Jpp
Control_utils.hh
Go to the documentation of this file.
1 #ifndef __CONTROL_UTILS__
2 #define __CONTROL_UTILS__
3 
4 
5 #include <string>
6 #include <iostream>
7 #include <sstream>
8 #include <iomanip>
9 
10 #include "TCanvas.h"
11 #include "RooPlot.h"
12 #include "RooDerivative.h"
13 #include "TLine.h"
14 #include "TF1.h"
15 
16 #include "NBRun.hh"
17 #include "Detector.hh"
18 
19 
20 
21 /**
22  * Produces a TH2 to be read as a table that summarizes which pmts were used as references for each module.
23  *
24  * \param Run a pointer to a nanobeacon run
25  * \return A TH2
26  */
27 inline TH2D* refs_th2(NBRun* Run){
28 
29  int run_number = Run->getRunNumber() ;
30 
31  double voltage = Run->getVoltage() ;
32 
33  vector <SuperModule*> SuperMods = Run->getSuperModules() ;
34 
35  char name[100] ;
36 
37  sprintf(name , "refs_Run_%d_%2.1fV", run_number , voltage) ;
38 
39  char title[100] ;
40 
41  sprintf(title , "Used reference PMTs") ;
42 
43  TH2D* refs = new TH2D(name , title , 18 , 0.5 , 18.5 , 12 , -0.5 , 11.5) ;
44 
45  for (auto & sm : SuperMods) {
46 
47  if (sm->get_ref_pmts().size()>0) {
48 
49  for (auto & ref : sm->get_ref_pmts()) {
50 
51  refs->Fill(sm->getFloor() , ref->getChannel()) ;
52 
53  }
54 
55  }
56 
57  }
58 
59  refs->GetXaxis()->SetTitle("Nanobeacon Floor") ;
60 
61  refs->GetYaxis()->SetTitle("PMT Channel (FPGA)") ;
62 
63  refs->SetOption("colz") ;
64 
65  refs->SetStats(0) ;
66 
67  return refs ;
68 
69 }
70 
71 
72 
73 /**
74  * Produces a TH2 to be read as a table that summarizes which pmts were used as good references for each module.
75  *
76  * \param Run a pointer to a nanobeacon run
77  * \return A TH2
78  */
79 inline TH2D* good_refs_th2(NBRun* Run){
80 
81  int run_number = Run->getRunNumber() ;
82 
83  double voltage = Run->getVoltage() ;
84 
85  vector <SuperModule*> SuperMods = Run->getSuperModules() ;
86 
87  char name[100] ;
88 
89  sprintf(name , "refs_Run_%d_%2.1fV", run_number , voltage) ;
90 
91  char title[100] ;
92 
93  sprintf(title , "Used reference PMTs") ;
94 
95  TH2D* refs = new TH2D(name , title , 18 , 0.5 , 18.5 , 12 , -0.5 , 11.5) ;
96 
97  for (auto & sm : SuperMods) {
98 
99  if (sm->get_ref_pmts().size()>0) {
100 
101  for (auto & ref : sm->get_ref_pmts()) {
102 
103  refs->Fill(sm->getFloor() , ref->getChannel()) ;
104 
105  if (ref->getNBPulse()->IsGood()==true){
106 
107  refs->Fill(sm->getFloor() , ref->getChannel()) ;
108 
109  }
110 
111  }
112 
113  }
114 
115  }
116 
117  refs->GetXaxis()->SetTitle("Nanobeacon Floor") ;
118 
119  refs->GetYaxis()->SetTitle("PMT Channel (FPGA)") ;
120 
121  refs->SetOption("colz") ;
122 
123  refs->SetStats(0) ;
124 
125  return refs ;
126 
127 }
128 
129 
130 /**
131  * Produces a TH2 to be read as a table that summarizes which pmts were used as good references for each module.
132  *
133  * \param Run a pointer to a nanobeacon run
134  * \return A TH2
135  */
136 inline TH2D* good_tgt_pmts_th2(NBRun* Run){
137 
138  int run_number = Run->getRunNumber() ;
139 
140  double voltage = Run->getVoltage() ;
141 
142  vector <SuperModule*> SuperMods = Run->getSuperModules() ;
143 
144  char name[100] ;
145 
146  sprintf(name , "tgt_pmts_Run_%d_%2.1fV", run_number , voltage) ;
147 
148  char title[100] ;
149 
150  sprintf(title , "Target PMTs used for the closest good source.") ;
151 
152  TH2D* tgts = new TH2D(name , title , 18 , 0.5 , 18.5 , 19 , 11.5 , 30.5) ;
153 
154  for (auto & sm : SuperMods) {
155 
156  if(sm->has_good_sources()==true){
157 
158  for (auto & spm : sm->get_closest_good_source().second){
159 
160  tgts->Fill(sm->getFloor() , spm->getChannel());
161 
162  if (spm->getNBPulse()->IsGood()==true){
163 
164  tgts->Fill(sm->getFloor() , spm->getChannel());
165 
166  }
167 
168  }
169 
170  }
171 
172  }
173 
174  tgts->GetXaxis()->SetTitle("Nanobeacon Floor") ;
175 
176  tgts->GetYaxis()->SetTitle("PMT Channel (FPGA)") ;
177 
178  tgts->SetOption("colz") ;
179 
180  tgts->SetStats(0) ;
181 
182  return tgts ;
183 
184 }
185 
186 
187 
188 /**
189  * Produces a TH2 to be read as a table that summarizes which modules were used as good sources for each target module.
190  *
191  * \param Run a pointer to a nanobeacon run
192  * \return A TH2
193  */
194 inline TH2D* srcs_th2(NBRun* Run){
195 
196  int run_number = Run->getRunNumber() ;
197 
198  double voltage = Run->getVoltage() ;
199 
200  vector <SuperModule*> SuperMods = Run->getSuperModules() ;
201 
202  char name[100] ;
203 
204  sprintf(name , "srcs_Run_%d_%2.1fV", run_number , voltage) ;
205 
206  char title[100] ;
207 
208  sprintf(title , "Sources for each target module.") ;
209 
210  TH2D* srcs = new TH2D(name , title , 18 , 0.5 , 18.5 , 18 , 0.5 , 18.5);
211 
212  for(auto & sm : SuperMods){
213 
214  int thisfloor = sm->getFloor() ;
215 
216  if(sm->get_sources().size()>0){
217 
218  for (auto & src : sm->get_sources()){
219 
220  int thatfloor = src.first->getFloor();
221 
222  srcs->Fill(thisfloor , thatfloor ) ;
223 
224  }
225  }
226 
227  if(sm->get_good_sources().size()>0){
228 
229  for (auto & src : sm->get_good_sources()){
230 
231  int thatfloor = src.first->getFloor();
232 
233  srcs->Fill(thisfloor , thatfloor) ;
234  }
235 
236  int thatfloor = sm->get_closest_good_source().first->getFloor();
237 
238  srcs->Fill(thisfloor , thatfloor) ;
239  }
240 
241  }
242 
243  srcs->GetXaxis()->SetTitle("Target Floor") ;
244 
245  srcs->GetYaxis()->SetTitle("Source Floor") ;
246 
247  srcs->SetOption("colz") ;
248 
249  srcs->SetStats(0) ;
250 
251  return srcs;
252 }
253 
254 
255 
256 /**
257  * Produces a TH2 to be interpreted as a table that summarizes which modules were targets for each source module.
258  *
259  * \param Run a pointer to a nanobeacon run
260  * \return A TH2
261  */
262 inline TH2D* tgts_th2(NBRun* Run){
263 
264  int run_number = Run->getRunNumber() ;
265 
266  double voltage = Run->getVoltage() ;
267 
268  vector <SuperModule*> SuperMods = Run->getSuperModules() ;
269 
270  char name[100] ;
271 
272  sprintf(name , "tgts_Run_%d_%2.1fV", run_number , voltage) ;
273 
274  char title[100] ;
275 
276  sprintf(title , "Targets for each source module.") ;
277 
278  TH2D* tgts = new TH2D(name , title , 18 , 0.5 , 18.5 , 18 , 0.5 , 18.5) ;
279 
280  for(auto & sm : SuperMods){
281 
282  int thisfloor = sm->getFloor() ;
283 
284  if(sm->get_targets().size()>0){
285 
286  for (auto & tgt : sm->get_targets()){
287 
288  int thatfloor = tgt.first->getFloor() ;
289 
290  tgts->Fill(thisfloor , thatfloor ) ;
291 
292  }
293  }
294 
295  if(sm->get_good_targets().size()>0){
296 
297  for (auto & tgt : sm->get_good_targets()){
298 
299  int thatfloor = tgt.first->getFloor() ;
300 
301  tgts->Fill(thisfloor , thatfloor) ;
302 
303  }
304 
305  int thatfloor = sm->get_closest_good_target().first->getFloor() ;
306 
307  tgts->Fill(thisfloor , thatfloor) ;
308  }
309 
310  }
311 
312  tgts->SetOption("colz") ;
313 
314  tgts->GetXaxis()->SetTitle("Source Floor") ;
315 
316  tgts->GetYaxis()->SetTitle("Target Floor") ;
317 
318  tgts->SetOption("colz") ;
319 
320  tgts->SetStats(0) ;
321 
322  return tgts ;
323 
324 }
325 
326 
327 /**
328  * Produces a TCanvas with the nanobeacon peak and the fit performed with Roofit.
329  *
330  * \param w A Rooworkspace that contains all the information relative to the fit.
331  * \param h The histogram with the nanobeacon peak.
332  * \return A TCanvas
333  */
334 inline TCanvas* RooCanvas(RooWorkspace w , TH1D* h){
335 
336  TCanvas * c = new TCanvas( (std::string("canvas_")+h->GetName()).c_str() , (std::string("canvas_")+h->GetName()).c_str() );
337 
338  c->cd() ;
339 
340  RooPlot* frame = w.var("time")->frame() ;
341 
342  RooDataHist Data ("data" , "data" , *w.var("time") , Import(*h)) ;
343 
344  Data.plotOn(frame) ;
345 
346  w.function("Model")->plotOn(frame) ;
347 
348  w.function("L1")->plotOn(frame , LineStyle(kDashed)) ;
349 
350  w.function("G1")->plotOn(frame , LineStyle(kDashed) , LineColor(kRed)) ;
351 
352  frame->Draw() ;
353 
354  TLine* line = new TLine ( w.var("mpv")->getVal() , 1 , w.var("mpv")->getVal() , 1e5) ;
355 
356  line->SetLineColor(kBlue) ;
357 
358  TLine* line2 = new TLine ( w.var("tpeak")->getVal() , 1 , w.var("tpeak")->getVal() , 1e5) ;
359 
360  line2->SetLineColor(kBlack) ;
361 
362  line->Draw("same") ;
363 
364  line2->Draw("same") ;
365 
366  return c ;
367 }
368 
369 #endif
srcs_th2
TH2D * srcs_th2(NBRun *Run)
Produces a TH2 to be read as a table that summarizes which modules were used as good sources for each...
Definition: Control_utils.hh:194
JTOOLS::w
data_type w[N+1][M+1]
Definition: JPolint.hh:708
NBRun
Class dedicated to the nanobeacon analyses, where the Modules in the detector are not regarded as sin...
Definition: NBRun.hh:24
good_tgt_pmts_th2
TH2D * good_tgt_pmts_th2(NBRun *Run)
Produces a TH2 to be read as a table that summarizes which pmts were used as good references for each...
Definition: Control_utils.hh:136
std::vector< SuperModule * >
NBRun::getVoltage
double getVoltage()
Get nanobeacon voltage.
Definition: NBRun.hh:439
NBRun::getRunNumber
int getRunNumber()
Get run number.
Definition: NBRun.hh:427
good_refs_th2
TH2D * good_refs_th2(NBRun *Run)
Produces a TH2 to be read as a table that summarizes which pmts were used as good references for each...
Definition: Control_utils.hh:79
refs_th2
TH2D * refs_th2(NBRun *Run)
Produces a TH2 to be read as a table that summarizes which pmts were used as references for each modu...
Definition: Control_utils.hh:27
RooCanvas
TCanvas * RooCanvas(RooWorkspace w, TH1D *h)
Produces a TCanvas with the nanobeacon peak and the fit performed with Roofit.
Definition: Control_utils.hh:334
Detector.hh
tgts_th2
TH2D * tgts_th2(NBRun *Run)
Produces a TH2 to be interpreted as a table that summarizes which modules were targets for each sourc...
Definition: Control_utils.hh:262
NBRun.hh
NBRun::getSuperModules
vector< SuperModule * > getSuperModules()
Get the SuperModules in the DU.
Definition: NBRun.hh:323