source: fact/tools/rootmacros/PulseTemplates/pixel.C@ 13591

Last change on this file since 13591 was 13590, checked in by Jens Buss, 12 years ago
new Method for computing histogram names
File size: 18.8 KB
Line 
1#include <iostream>
2#include "TObjArray.h"
3#include "TCanvas.h"
4
5#include "rootfilehandler.h"
6#include "pixel.h" // class implemented
7using namespace std;
8
9/////////////////////////////// PUBLIC ///////////////////////////////////////
10
11//============================= LIFECYCLE ====================================
12
13//Pixel::Pixel(int pixelID)
14//{
15// Chid = pixelID;
16// max_puslse_order = 1;
17// hMaxOverlay = NULL;
18// hEdgeOverlay = NULL;
19// hMaxProfile = NULL;
20// hEdgeProfile = NULL;
21// hList = NULL;
22
23//}
24//Pixel::Pixel(
25// int pixelID,
26// int maxPulsorder,
27// int verbosityLevel,
28// bool stats,
29// TFile* filename
30// )
31//{
32// mChid = pixelID;
33// mStats = stats;
34// mMaxPulseOrder = maxPulsorder;
35// mVerbosityLevel = verbosityLevel;
36
37// hMaxOverlay = new TH2F*[mMaxPulseOrder];
38// hEdgeOverlay = new TH2F*[mMaxPulseOrder];
39// hMaxProfile = new TProfile*[mMaxPulseOrder];
40// hEdgeProfile = new TProfile*[mMaxPulseOrder];
41
42// hList = new TObjArray;
43
44// LoadPulseHistos( filename );
45//}
46
47Pixel::Pixel(
48 int pixelID,
49 int maxPulsorder,
50 int verbosityLevel,
51 bool stats,
52// TFile* filename,
53 int pixelOverlayXaxisLeft,
54 int pixelOverlayXaxisRight,
55 int bSLMean,
56 int gainMean,
57 TString options
58 )
59{
60 mChid = pixelID;
61 mStats = stats; ///TODO: HANDOVER THE VALUE
62 mMaxPulseOrder = maxPulsorder;
63 mVerbosityLevel = verbosityLevel;
64 mOptions = options;
65 mPixelOverlayXaxisLeft = pixelOverlayXaxisLeft;
66 mPixelOverlayXaxisRight = pixelOverlayXaxisRight;
67 mBSLMean = bSLMean;
68 mGainMean = gainMean;
69
70 hMaxOverlay = new TH2F*[mMaxPulseOrder];
71 hEdgeOverlay = new TH2F*[mMaxPulseOrder];
72 hMaxProfile = new TProfile*[mMaxPulseOrder];
73 hEdgeProfile = new TProfile*[mMaxPulseOrder];
74
75 if (mOptions.Contains("S") )
76 {
77 hSlopeRisingEdge = new TH1F*[mMaxPulseOrder];
78 }
79
80 if (mOptions.Contains("R") )
81 {
82 hRisingEdgeToMax = new TH1I*[mMaxPulseOrder];
83 }
84
85 if (mOptions.Contains("M") )
86 {
87 hPosOfMax = new TH1I*[mMaxPulseOrder];
88 }
89
90 hList = new TObjArray;
91
92 BookPixelHistos();
93 BookDistributionHistos();
94}
95
96Pixel::~Pixel()
97{
98 if (mVerbosityLevel > 1) cout << endl << "...delete histograms of pixel " << mChid ;
99
100 DeletePixelHistos();
101 DeleteDistributionHistos();
102
103 delete hList;
104 hList = NULL;
105
106}// ~Pixel
107
108
109//============================= OPERATORS ====================================
110
111//XX&
112//XX::operator=(const XX&);
113//{
114// return *this;
115
116//}// =
117
118//============================= OPERATIONS ===================================
119void
120Pixel::BookPixelHistos()
121{
122 if (mVerbosityLevel > 2) cout << endl << "...book pixel histograms" << endl;
123 for (int order = 0; order < mMaxPulseOrder; order++)
124 {
125 if (mVerbosityLevel > 3) cout << "\t...booking " << HistoName("hMaxOverlay", order) << endl;
126 hMaxOverlay[order]=new TH2F(
127 HistoName("hMaxOverlay", order),
128 HistoTitle("Overlay of detected pulses of", order),
129 mPixelOverlayXaxisLeft + mPixelOverlayXaxisRight ,
130 (-1*mPixelOverlayXaxisLeft)-0.5,
131 mPixelOverlayXaxisRight-0.5 ,
132 512,
133 -55.5,
134 200.5
135 );
136
137 hMaxOverlay[order]->SetAxisRange(
138 mBSLMean - 5,
139 (mGainMean*(order+1)) + 10,
140 "Y");
141 hMaxOverlay[order]->GetXaxis()->SetTitle( "Timeslices [a.u.]" );
142 hMaxOverlay[order]->GetYaxis()->SetTitle( "Amplitude [mV]" );
143 //hMaxProfile->SetBit(TH2F::kCanRebin);
144 hMaxOverlay[order]->SetStats(mStats);
145 hList->Add( hMaxOverlay[order] );
146
147//------------------------------------------------------------------------
148
149 if (mVerbosityLevel > 3) cout << "\t...booking " << HistoName("hEdgeOverlay", order) << endl;
150 hEdgeOverlay[order] = new TH2F(
151 HistoName("hEdgeOverlay", order),
152 HistoTitle("Overlay at rising edge of detected pulses of", order),
153 mPixelOverlayXaxisLeft + mPixelOverlayXaxisRight ,
154 (-1*mPixelOverlayXaxisLeft)-0.5,
155 mPixelOverlayXaxisRight-0.5 ,
156 512,
157 -55.5,
158 200.5
159 );
160
161 hEdgeOverlay[order]->SetAxisRange(
162 mBSLMean - 5,
163 (mGainMean*(order+1)) + 10,
164 "Y");
165 hEdgeOverlay[order]->GetXaxis()->SetTitle( "Timeslices [a.u.]" );
166 hEdgeOverlay[order]->GetYaxis()->SetTitle( "Amplitude [mV]" );
167 hEdgeOverlay[order]->SetStats(mStats);
168 hList->Add( hEdgeOverlay[order] );
169
170 //------------------------------------------------------------------------
171
172 if (mVerbosityLevel > 3) cout << "\t...booking " << HistoName("hMaxProfile", order) << endl;
173 hMaxProfile[order] = new TProfile(
174 HistoName("hMaxProfile", order),
175 HistoTitle("Mean value of each slice in overlay plot (Tprofile)", order),
176 mPixelOverlayXaxisLeft + mPixelOverlayXaxisRight ,//nbinsx
177 (-1*mPixelOverlayXaxisLeft)-0.5, //xlow
178 mPixelOverlayXaxisRight-0.5 , //xup
179 // 512, //nbinsy
180 -55.5, //ylow
181 300.5, //yup
182 "s"); //option
183 hMaxProfile[order]->SetAxisRange(
184 mBSLMean - 5,
185 (mGainMean*(order+1)) + 10,
186 "Y");
187 hMaxProfile[order]->GetXaxis()->SetTitle( "Timeslices [a.u.]" );
188 hMaxProfile[order]->GetYaxis()->SetTitle( "Amplitude [mV]" );
189 //hMaxProfile->SetBit(TH2F::kCanRebin);
190 hMaxProfile[order]->SetStats(mStats);
191 hList->Add( hMaxProfile[order] );
192
193
194 //------------------------------------------------------------------------
195
196 if (mVerbosityLevel > 3) cout << "\t...booking " << HistoName("hEdgeProfile", order) << endl;
197 hEdgeProfile[order] = new TProfile(
198 HistoName("hEdgeProfile", order),
199 HistoTitle("Mean value of each slice in overlay plot (Tprofile)", order),
200 mPixelOverlayXaxisLeft + mPixelOverlayXaxisRight ,//nbinsx
201 (-1*mPixelOverlayXaxisLeft)-0.5, //xlow
202 mPixelOverlayXaxisRight-0.5 , //xup
203 // 512, //nbinsy
204 -55.5, //ylow
205 300.5, //yup
206 "s"); //option
207 hEdgeProfile[order]->SetLineColor(kRed);
208 hEdgeProfile[order]->SetAxisRange(
209 mBSLMean - 5,
210 (mGainMean*(order+1)) + 10,
211 "Y");
212 hEdgeProfile[order]->GetXaxis()->SetTitle( "Timeslices [a.u.]" );
213 hEdgeProfile[order]->GetYaxis()->SetTitle( "Amplitude [mV]" );
214 //hMaxProfile->SetBit(TH2F::kCanRebin);
215 hEdgeProfile[order]->SetStats(mStats);
216 hList->Add( hEdgeProfile[order] );
217
218 }
219 if (mVerbosityLevel > 2) cout << "...done" << endl;
220}
221//end of BookPixelHistos
222//----------------------------------------------------------------------------
223
224
225void
226Pixel::DrawHistograms(
227 TCanvas** pixelCanvas,
228 int* histoFrameNr
229 )
230{
231 if (mVerbosityLevel > 2) cout << endl << "...drawing pulse histograms" ;
232 for (int pulse_order = 0; pulse_order < mMaxPulseOrder; pulse_order++)
233 {
234 pixelCanvas[pulse_order]->cd( histoFrameNr[0] );
235 hMaxOverlay[pulse_order]->Draw("COLZ");
236 pixelCanvas[pulse_order]->cd( histoFrameNr[2] );
237 hMaxProfile[pulse_order]->Draw();
238 hEdgeProfile[pulse_order]->Draw("SAME");
239
240 pixelCanvas[pulse_order]->cd( histoFrameNr[1] );
241 hEdgeOverlay[pulse_order]->Draw("COLZ");
242 }
243}
244// end of DrawPulseHistograms
245//----------------------------------------------------------------------------
246
247
248void
249Pixel::BookDistributionHistos( )
250{
251 if (!mOptions.IsNull() )
252 {
253 int x_min = 0;
254 int x_max = 0;
255
256 for (int order =0; order < mMaxPulseOrder; order++)
257 {
258 if (mVerbosityLevel > 2) cout << endl
259 << "...book distribution histograms"
260 << endl;
261
262 if (mOptions.Contains("S"))
263 {
264 if (mVerbosityLevel > 3) cout << "\t...booking " << HistoName("hSlopeRisingEdge", order) << endl;
265 hSlopeRisingEdge[order] = new TH1F (
266 HistoName("hSlopeRisingEdge", order),
267 HistoTitle("Distribution of rising edge's slope", order),
268 600,
269 -10.1,
270 10.1
271 );
272 hSlopeRisingEdge[order]->SetAxisRange(
273 -1,
274 7,
275 "X");
276 hSlopeRisingEdge[order]->GetXaxis()->SetTitle( "Slope Amplitude/time [mV/timeslices]" );
277 hSlopeRisingEdge[order]->GetYaxis()->SetTitle( "counts" );
278 hSlopeRisingEdge[order]->SetStats(mStats);
279 hList->Add( hSlopeRisingEdge[order] );
280 }
281
282 if (mOptions.Contains("R"))
283 {
284 x_min = -15;
285 x_max = 35;
286
287 if (mVerbosityLevel > 3) cout << "\t...booking " << HistoName("hRisingEdgeToMax", order) << endl;
288 hRisingEdgeToMax[order] = new TH1I (
289 HistoName("hRisingEdgeToMax", order),
290 HistoTitle("Distance from rising edge to pulse's maximum", order),
291 x_max -x_min,
292 x_min,
293 x_max
294 );
295 hSlopeRisingEdge[order]->SetAxisRange(
296 -5,
297 25,
298 "X");
299 hRisingEdgeToMax[order]->GetXaxis()->SetTitle( "Timeslices [a.u.]" );
300 hRisingEdgeToMax[order]->GetYaxis()->SetTitle( "counts" );
301 hRisingEdgeToMax[order]->SetStats(mStats);
302 hList->Add( hRisingEdgeToMax[order] );
303 }
304
305 if (mOptions.Contains("M"))
306 {
307 x_min = 10;
308 x_max = 290;
309 if (mVerbosityLevel > 3) cout << "\t...booking " << HistoName("hPosOfMax", order) << endl;
310 hPosOfMax[order] = new TH1I (
311 HistoName("hPosOfMax", order),
312 HistoTitle("Distribution of pulse's maximum's positon", order),
313 x_max - x_min,
314 x_min,
315 x_max
316 );
317 hPosOfMax[order]->GetXaxis()->SetTitle( "Timeslices [a.u.]" );
318 hPosOfMax[order]->GetYaxis()->SetTitle( "counts" );
319 hRisingEdgeToMax[order]->SetStats(mStats);
320 hList->Add( hPosOfMax[order] );
321 }
322
323 if (mVerbosityLevel > 2) cout << "...done" << endl;
324 }
325 }
326}
327
328void
329Pixel::DrawDistributionHistograms(
330 TCanvas** pixelCanvas,
331 int* histoFrameNr
332 )
333{
334 if (mVerbosityLevel > 2) cout << endl << "...drawing distribution histograms" ;
335 bool nothing_to_fill = true;
336 for (int pulse_order = 0; pulse_order < mMaxPulseOrder; pulse_order++)
337 {
338 if (mOptions.Contains("S") )
339 {
340 pixelCanvas[pulse_order]->cd( histoFrameNr[0] );
341 hSlopeRisingEdge[pulse_order]->Draw();
342 nothing_to_fill = false;
343 }
344
345 if (mOptions.Contains("R") )
346 {
347 pixelCanvas[pulse_order]->cd( histoFrameNr[1] );
348 hRisingEdgeToMax[pulse_order]->Draw();
349 nothing_to_fill = false;
350 }
351
352 if (mOptions.Contains("M") )
353 {
354 pixelCanvas[pulse_order]->cd( histoFrameNr[2] );
355 hPosOfMax[pulse_order]->Draw();
356 nothing_to_fill = false;
357 }
358
359 }
360 if (nothing_to_fill)
361 {
362 cout << endl << "there were NO DISTRIBUTION HISTOGRAMS to fill" << endl;
363 }
364}
365// end of DrawDistributionHistograms
366//----------------------------------------------------------------------------
367
368void
369Pixel::SavePixelHistograms(
370 const char* outRootFileName,
371 bool saveResults
372 )
373{
374 if (mVerbosityLevel > 2) cout << endl << "Saving histograms of Pixel# " << mChid;
375 if (!saveResults) return;
376 SaveHistograms(
377 outRootFileName,
378 CreateSubDirName( mChid ),
379 hList,
380 saveResults,
381 mVerbosityLevel
382 );
383}
384// end of SavePixelHistograms
385//----------------------------------------------------------------------------
386
387void
388Pixel::DeletePixelHistos()
389{
390 if (mVerbosityLevel > 2)
391 {
392 cout << endl
393 << "\t...delete current overlay histograms of Pixel# " << mChid;
394 }
395 for (int order = 0;
396 order < mMaxPulseOrder;
397 order ++)
398 {
399 if (mVerbosityLevel > 3)
400 cout << endl << "\t\t...deleting hMaxOverlay"
401 << mChid << "_" << order
402 << " hMaxOverlay[order] adr " << hMaxOverlay[order]
403 << " hMaxOverlay adr " << hMaxOverlay
404 ;
405
406 delete hMaxOverlay[order];
407 hMaxOverlay[order] = NULL;
408
409 if (mVerbosityLevel > 3) cout << endl << "\t\t...deleting hEdgeOverlay"
410 << mChid << "_" << order ;
411 delete hEdgeOverlay[order];
412 hEdgeOverlay[order] = NULL;
413
414 if (mVerbosityLevel > 3) cout << endl << "\t\t...deleting hMaxProfile"
415 << mChid << "_" << order ;
416 delete hMaxProfile[order];
417 hMaxProfile[order] = NULL;
418
419 if (mVerbosityLevel > 3) cout << endl << "\t\t...deleting hMaxProfile2"
420 << mChid << "_" << order ;
421 delete hEdgeProfile[order];
422 hEdgeProfile[order] = NULL;
423 }
424 if (mVerbosityLevel > 3) cout << endl << "\t...deleting histogram Arrays";
425
426 if (mVerbosityLevel > 3) cout << endl << "\t\t...deleting hMaxOverlay";
427 delete[] hMaxOverlay;
428 hMaxOverlay = NULL;
429
430 if (mVerbosityLevel > 3) cout << endl << "\t\t...deleting hEdgeOverlay";
431 delete[] hEdgeOverlay;
432 hEdgeOverlay = NULL;
433
434 if (mVerbosityLevel > 3) cout << endl << "\t\t...deleting hMaxProfile";
435 delete[] hMaxProfile;
436 hMaxProfile = NULL;
437
438 if (mVerbosityLevel > 3) cout << endl << "\t\t...deleting hEdgeProfile";
439 delete[] hEdgeProfile;
440 hEdgeProfile = NULL;
441}
442// end of DeletePixelHistos
443//----------------------------------------------------------------------------
444
445void
446Pixel::DeleteDistributionHistos()
447{
448 if (mVerbosityLevel > 2)
449 {
450 cout << endl
451 << "\t...delete current distribution histograms" ;
452 }
453
454 for (int order = 0;
455 order < mMaxPulseOrder;
456 order ++)
457 {
458 if (mOptions.Contains("S"))
459 {
460 if (mVerbosityLevel > 3) cout << endl
461 << "\t\t...deleting hSlopeRisingEdge"
462 << mChid << "_" << order ;
463 delete hSlopeRisingEdge[order];
464 }
465
466 if (mOptions.Contains("R"))
467 {
468 if (mVerbosityLevel > 3) cout << endl
469 << "\t\t...deleting hRisingEdgeToMax"
470 << mChid << "_" << order ;
471// delete hRisingEdgeToMax[order];
472 }
473
474 if (mOptions.Contains("M"))
475 {
476 if (mVerbosityLevel > 3) cout << endl
477 << "\t\t...deleting hPosOfMax"
478 << mChid << "_" << order ;
479
480// delete hPosOfMax[order];
481 }
482
483 }
484 if (mVerbosityLevel > 3) cout << endl << "\t...deleting histogram Arrays";
485
486 if (mOptions.Contains("S"))
487 {
488 if (mVerbosityLevel > 3) cout << endl << "\t\t...deleting hSlopeRisingEdge";
489 delete[] hSlopeRisingEdge;
490 hSlopeRisingEdge = NULL;
491 }
492
493 if (mOptions.Contains("R"))
494 {
495 if (mVerbosityLevel > 3) cout << endl << "\t\t...deleting hRisingEdgeToMax";
496 delete[] hRisingEdgeToMax;
497 hRisingEdgeToMax = NULL;
498 }
499
500 if (mOptions.Contains("M"))
501 {
502 if (mVerbosityLevel > 3) cout << endl << "\t\t...deleting hPosOfMax";
503 delete[] hPosOfMax;
504 hPosOfMax = NULL;
505 }
506}
507// end of DeletePixelHistos
508//----------------------------------------------------------------------------
509
510void
511Pixel::LoadPulseHistos(
512 TFile* filename
513 )
514{
515 filename->cd();
516 filename->cd(CreateSubDirName( mChid ));
517 for (int order = 0; order < mMaxPulseOrder; order++)
518 {
519 hMaxOverlay[order] = (TH2F*)filename->Get( HistoName("hMaxOverlay", order) );
520 hEdgeOverlay[order] = (TH2F*)filename->Get( HistoName("hEdgeOverlay", order) );
521 hMaxProfile[order] = (TProfile*)filename->Get( HistoName("hMaxProfile", order) );
522 hEdgeProfile[order] = (TProfile*)filename->Get( HistoName("hEdgeProfile", order) );
523 }
524}
525
526TString
527Pixel::HistoName(
528 TString histoname,
529 int order
530 )
531{
532 histoname += mChid;
533 histoname += "_";
534 histoname += order;
535 return histoname;
536}
537
538TString
539Pixel::HistoTitle(
540 TString histo_title,
541 int order
542 )
543{
544 histo_title += " [Pixel_Order] ";
545 histo_title += mChid;
546 histo_title += "_";
547 histo_title += order;
548 return histo_title;
549}
550
551
552//============================= ACESS ===================================
553//============================= INQUIRY ===================================
554/////////////////////////////// PROTECTED ///////////////////////////////////
555
556/////////////////////////////// PRIVATE ///////////////////////////////////
557
558
559
560
561
562
563
564
Note: See TracBrowser for help on using the repository browser.