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

Last change on this file since 14963 was 14942, checked in by Jens Buss, 12 years ago
stuff
File size: 41.9 KB
Line 
1#include <iostream>
2#include <TMath.h>
3#include <TF1.h>
4#include <TVectorF.h>
5
6#include "rootfilehandler.h"
7#include "pixel.h" // class implemented
8using namespace std;
9
10/////////////////////////////// PUBLIC ///////////////////////////////////////
11
12//============================= LIFECYCLE ====================================
13
14
15Pixel::Pixel(
16 int pixelID,
17 int maxPulsorder,
18 int verbosityLevel,
19 bool stats,
20 TString options,
21 int pixelOverlayXaxisLeft,
22 int pixelOverlayXaxisRight,
23 float bSLMean,
24 float gainMean,
25 TFile* filename,
26 TFile* outfilename
27 )
28{
29 mConstructorType = 1; //important for deletion 0 delete distribution 1 delete TemplateHistos
30
31 mChid = pixelID;
32 mMaxPulseOrder = maxPulsorder;
33 mVerbosityLevel = verbosityLevel;
34 mStats = stats;
35 mOptions = options;
36 mPixelOverlayXaxisLeft = pixelOverlayXaxisLeft;
37 mPixelOverlayXaxisRight = pixelOverlayXaxisRight;
38 mBSLMean = bSLMean;
39 mGainMean = gainMean;
40 mRootFile = filename;
41 mOutRootFile = outfilename;
42
43 hMaxOverlay = new TH2F*[mMaxPulseOrder];
44 hEdgeOverlay = new TH2F*[mMaxPulseOrder];
45 hMaxProfile = new TProfile*[mMaxPulseOrder];
46 hEdgeProfile = new TProfile*[mMaxPulseOrder];
47
48 hPixelMax = new TH1F*[mMaxPulseOrder];
49 hPixelMedian = new TH1F*[mMaxPulseOrder];
50 hPixelMean = new TH1F*[mMaxPulseOrder];
51
52 hPixelEdgeMax = new TH1F*[mMaxPulseOrder];
53 hPixelEdgeMedian = new TH1F*[mMaxPulseOrder];
54 hPixelEdgeMean = new TH1F*[mMaxPulseOrder];
55
56 hList = new TList();
57 hMemberlist = new TList();
58
59 if (mOptions.Contains("C") )
60 {
61 hChi2EdgetoMax = new TH1F*[mMaxPulseOrder];
62 }
63
64 if (options.Contains("L"))
65 {
66 LoadPulseHistos( );
67 }
68 else
69 {
70 BookPixelHistos();
71 }
72
73 if (mOptions.Contains("C"))
74 {
75 BookDistributionHistos();
76 }
77
78 BookTemplateHistos();
79 BookEdgeTemplateHistos();
80}
81
82Pixel::Pixel(
83 int pixelID,
84 int maxPulsorder,
85 int verbosityLevel,
86 bool stats,
87 TString options,
88 int pixelOverlayXaxisLeft,
89 int pixelOverlayXaxisRight,
90 float bSLMean,
91 float gainMean
92 )
93{
94 mConstructorType = 0;
95
96 mChid = pixelID;
97 mMaxPulseOrder = maxPulsorder;
98 mVerbosityLevel = verbosityLevel;
99 mStats = stats; ///TODO: HANDOVER THE VALUE
100 mOptions = options;
101 mPixelOverlayXaxisLeft = pixelOverlayXaxisLeft;
102 mPixelOverlayXaxisRight = pixelOverlayXaxisRight;
103 mBSLMean = bSLMean;
104 mGainMean = gainMean;
105
106 hMaxOverlay = new TH2F*[mMaxPulseOrder];
107 hEdgeOverlay = new TH2F*[mMaxPulseOrder];
108 hMaxProfile = new TProfile*[mMaxPulseOrder];
109 hEdgeProfile = new TProfile*[mMaxPulseOrder];
110
111 if (mOptions.Contains("S") )
112 {
113 hSlopeRisingEdge = new TH1F*[mMaxPulseOrder];
114 }
115
116 if (mOptions.Contains("R") )
117 {
118 hRisingEdgeToMax = new TH1I*[mMaxPulseOrder];
119 }
120
121 if (mOptions.Contains("M") )
122 {
123 hPosOfMax = new TH1I*[mMaxPulseOrder];
124 }
125
126 hList = new TList();
127 hMemberlist = new TList();
128
129 BookPixelHistos();
130 BookDistributionHistos();
131}
132
133Pixel::~Pixel()
134{
135 if (mVerbosityLevel > 1)
136 {
137 cout << endl << "...delete histograms of pixel " << mChid ;
138 cout << endl << "...mConstructorType = " << mConstructorType ;
139 }
140
141 if (mConstructorType == 0)
142 {
143 DeleteDistributionHistos();
144 }
145
146 if (mConstructorType == 1)
147 {
148 DeleteTemplateHistos();
149 DeleteEdgeTemplateHistos();
150 }
151
152 DeletePixelHistos();
153 delete hList;
154 delete hMemberlist;
155
156 hList = NULL;
157 hMemberlist = NULL;
158 if (mVerbosityLevel > 1)
159 {
160 cout << endl << "...histograms of pixel " << mChid ;
161 cout << "...deleted " << endl ;
162 }
163}// ~Pixel
164
165
166//============================= OPERATORS ====================================
167
168//XX&
169//XX::operator=(const XX&);
170//{
171// return *this;
172
173//}// =
174
175//============================= OPERATIONS ===================================
176void
177Pixel::DrawOverlayHistograms(
178 TCanvas** pixelCanvas,
179 int* histoFrameNr
180 )
181{
182 if (mVerbosityLevel > 2) cout << endl << "...drawing pulse histograms" ;
183 for (int pulse_order = 0; pulse_order < mMaxPulseOrder; pulse_order++)
184 {
185 pixelCanvas[pulse_order]->cd( histoFrameNr[0] );
186 hMaxOverlay[pulse_order]->Draw("COLZ");
187 pixelCanvas[pulse_order]->cd( histoFrameNr[2] );
188 hMaxProfile[pulse_order]->Draw();
189
190 pixelCanvas[pulse_order]->cd( histoFrameNr[1] );
191 hEdgeOverlay[pulse_order]->Draw("COLZ");
192 pixelCanvas[pulse_order]->cd( histoFrameNr[3] );
193 hEdgeProfile[pulse_order]->Draw();
194 }
195}
196// end of DrawOverlayHistograms
197//----------------------------------------------------------------------------
198
199void
200Pixel::DrawDistributionHistograms(
201 TCanvas** pixelCanvas,
202 int* histoFrameNr
203 )
204{
205 if (mVerbosityLevel > 2) cout << endl << "...drawing distribution histograms" ;
206 bool nothing_to_fill = true;
207 for (int pulse_order = 0; pulse_order < mMaxPulseOrder; pulse_order++)
208 {
209 if (mOptions.Contains("S") )
210 {
211 pixelCanvas[pulse_order]->cd( histoFrameNr[0] );
212 hSlopeRisingEdge[pulse_order]->Draw();
213 nothing_to_fill = false;
214 }
215
216 if (mOptions.Contains("R") )
217 {
218 pixelCanvas[pulse_order]->cd( histoFrameNr[1] );
219 hRisingEdgeToMax[pulse_order]->Draw();
220 nothing_to_fill = false;
221 }
222
223 if (mOptions.Contains("M") )
224 {
225 pixelCanvas[pulse_order]->cd( histoFrameNr[2] );
226 hPosOfMax[pulse_order]->Draw();
227 nothing_to_fill = false;
228 }
229
230 }
231 if (nothing_to_fill)
232 {
233 cout << endl << "there were NO DISTRIBUTION HISTOGRAMS to fill" << endl;
234 }
235}
236// end of DrawDistributionHistograms
237//----------------------------------------------------------------------------
238
239void
240Pixel::DrawTemplateHistograms(
241 TCanvas** pixelCanvas,
242 int* histoFrameNr
243 )
244{
245 int mrkStyle =1;
246 int mrkSize = 2;
247 if (mVerbosityLevel > 2) cout << "...drawing Template histograms" << endl ;
248 for (int pulse_order = 0; pulse_order < mMaxPulseOrder; pulse_order++)
249 {
250 pixelCanvas[pulse_order]->cd( histoFrameNr[0] );
251 hMaxOverlay[pulse_order]->Draw("COLZ");
252
253 pixelCanvas[pulse_order]->cd( histoFrameNr[1] );
254 hPixelMax[pulse_order]->Draw("E1");
255 hPixelMax[pulse_order]->SetMarkerColor(kBlue);
256 hPixelMax[pulse_order]->SetLineColor(kBlack);
257 hPixelMax[pulse_order]->SetMarkerStyle(mrkStyle);
258 hPixelMax[pulse_order]->SetMarkerSize(mrkSize);
259
260 pixelCanvas[pulse_order]->cd( histoFrameNr[2] );
261 hPixelMedian[pulse_order]->Draw("E1");
262 hPixelMedian[pulse_order]->SetMarkerColor(kBlue);
263 hPixelMedian[pulse_order]->SetLineColor(kBlack);
264 hPixelMedian[pulse_order]->SetMarkerStyle(mrkStyle);
265 hPixelMedian[pulse_order]->SetMarkerSize(mrkSize);
266
267 pixelCanvas[pulse_order]->cd( histoFrameNr[3] );
268 hPixelMean[pulse_order]->Draw("E1");
269 hPixelMean[pulse_order]->SetMarkerColor(kBlue);
270 hPixelMean[pulse_order]->SetLineColor(kBlack);
271 hPixelMean[pulse_order]->SetMarkerStyle(mrkStyle);
272 hPixelMean[pulse_order]->SetMarkerSize(mrkSize);
273// hPixelMax[pulse_order]->Draw("SAME");
274// hPixelMedian[pulse_order]->Draw("SAME");
275
276 }
277}
278// end of DrawTemplateHistograms
279//----------------------------------------------------------------------------
280
281void
282Pixel::DrawEdgeTemplateHistograms(
283 TCanvas** pixelCanvas,
284 int* histoFrameNr
285 )
286{
287 int mrkStyle = 1;
288 int mrkSize = 3;
289
290 if (mVerbosityLevel > 2) cout << endl << "...drawing Template histograms" ;
291 for (int pulse_order = 0; pulse_order < mMaxPulseOrder; pulse_order++)
292 {
293 pixelCanvas[pulse_order]->cd( histoFrameNr[4] );
294 hEdgeOverlay[pulse_order]->Draw("COLZ");
295
296 pixelCanvas[pulse_order]->cd( histoFrameNr[5] );
297 hPixelEdgeMax[pulse_order]->Draw("E1");
298 hPixelEdgeMax[pulse_order]->SetLineColor(kBlack);
299 hPixelEdgeMax[pulse_order]->SetMarkerColor(kBlue);
300 hPixelEdgeMax[pulse_order]->SetMarkerStyle(mrkStyle);
301 hPixelEdgeMax[pulse_order]->SetMarkerSize(mrkSize);
302
303 pixelCanvas[pulse_order]->cd( histoFrameNr[6] );
304 hPixelEdgeMedian[pulse_order]->Draw("E1");
305 hPixelEdgeMedian[pulse_order]->SetLineColor(kBlack);
306 hPixelEdgeMedian[pulse_order]->SetMarkerColor(kBlue);
307 hPixelEdgeMedian[pulse_order]->SetMarkerStyle(mrkStyle);
308 hPixelEdgeMedian[pulse_order]->SetMarkerSize(mrkSize);
309
310 pixelCanvas[pulse_order]->cd( histoFrameNr[7] );
311 hPixelEdgeMean[pulse_order]->Draw("E1");
312 hPixelEdgeMean[pulse_order]->SetLineColor(kBlack);
313 hPixelEdgeMean[pulse_order]->SetMarkerColor(kBlue);
314 hPixelEdgeMean[pulse_order]->SetMarkerStyle(mrkStyle);
315 hPixelEdgeMean[pulse_order]->SetMarkerSize(mrkSize);
316// hPixelEdgeMax[pulse_order]->Draw("SAME");
317// hPixelEdgeMedian[pulse_order]->Draw("SAME");
318
319 }
320}
321// end of DrawTemplateHistograms
322//----------------------------------------------------------------------------
323
324
325
326
327void
328Pixel::SavePixelHistograms(
329 TString outRootFileName,
330 bool saveResults
331 )
332{
333 if (mVerbosityLevel > 2) cout << endl << "Saving histograms of Pixel# " << mChid;
334 if (!saveResults) return;
335 SaveList(
336 outRootFileName,
337 CreateSubDirName( mChid ),
338 hList,
339 saveResults,
340 mVerbosityLevel
341 );
342 /*
343 we also need to save same values:
344
345 EXAMPLE
346 root > TFile f("v.root","recreate")
347 root > TVectorD v(1)
348 root > v[0] = 3.14
349 root > v.Write("v")
350 and to read the file do
351 CODE: SELECT ALL
352 root > TFile f("v.root")
353 root > TVectorD *v = (TVectorD*)f.get("v");
354 root > v->Print()
355
356 */
357}
358// end of SavePixelHistograms
359//----------------------------------------------------------------------------
360
361TString
362Pixel::HistoName(
363 TString histoname,
364 int order
365 )
366{
367 histoname += mChid;
368 histoname += "_";
369 histoname += order;
370 return histoname;
371}
372
373TString
374Pixel::ChooseCycleNumber(
375 TString histoname,
376 int cycleNumber
377 )
378{
379 histoname += ";";
380 histoname += cycleNumber;
381 return histoname;
382}
383
384TString
385Pixel::HistoTitle(
386 TString histo_title,
387 int order
388 )
389{
390 histo_title += " [Pixel_Order] ";
391 histo_title += mChid;
392 histo_title += "_";
393 histo_title += order;
394 return histo_title;
395}
396
397TString
398Pixel::CsvFileName(
399 TString path,
400 TString overlayMethod,
401 int order
402 )
403{
404 path += "CSV/";
405 path += overlayMethod;
406 path += "OverlayTemplate";
407 path += "_";
408 path += mChid;
409 path += "_";
410 path += order;
411 path += ".csv";
412 return path;
413}
414
415
416//============================= ACESS ===================================
417//============================= INQUIRY ===================================
418/////////////////////////////// PROTECTED ///////////////////////////////////
419
420/////////////////////////////// PRIVATE ///////////////////////////////////
421
422void
423Pixel::BookPixelHistos()
424{
425 if (mVerbosityLevel > 2) cout << endl << "...book pixel histograms" << endl;
426 for (int order = 0; order < mMaxPulseOrder; order++)
427 {
428 if (mVerbosityLevel > 3) cout << "\t...booking " << HistoName("hMaxOverlay", order) << endl;
429 hMaxOverlay[order]=new TH2F(
430 HistoName("hMaxOverlay", order),
431 HistoTitle("Overlay at peak maximum of detected pulses of", order),
432 mPixelOverlayXaxisLeft + mPixelOverlayXaxisRight ,
433 (-1*mPixelOverlayXaxisLeft)-0.5,
434 mPixelOverlayXaxisRight-0.5 ,
435 512,
436 -55.5,
437 200.5
438 );
439
440 hMaxOverlay[order]->SetAxisRange(
441 mBSLMean - 5,
442 (mGainMean*(order+1)) + 10,
443 "Y");
444 hMaxOverlay[order]->GetXaxis()->SetTitle( "Timeslices [a.u.]" );
445 hMaxOverlay[order]->GetYaxis()->SetTitle( "Amplitude [mV]" );
446 //hMaxProfile->SetBit(TH2F::kCanRebin);
447 hMaxOverlay[order]->SetStats(mStats);
448 hList->Add( hMaxOverlay[order] );
449
450//------------------------------------------------------------------------
451
452 if (mVerbosityLevel > 3) cout << "\t...booking " << HistoName("hEdgeOverlay", order) << endl;
453 hEdgeOverlay[order] = new TH2F(
454 HistoName("hEdgeOverlay", order),
455 HistoTitle("Overlay at rising edge of detected pulses of", order),
456 mPixelOverlayXaxisLeft + mPixelOverlayXaxisRight ,
457 (-1*mPixelOverlayXaxisLeft)-0.5,
458 mPixelOverlayXaxisRight-0.5 ,
459 512,
460 -55.5,
461 200.5
462 );
463
464 hEdgeOverlay[order]->SetAxisRange(
465 mBSLMean - 5,
466 (mGainMean*(order+1)) + 10,
467 "Y");
468 hEdgeOverlay[order]->GetXaxis()->SetTitle( "Timeslices [a.u.]" );
469 hEdgeOverlay[order]->GetYaxis()->SetTitle( "Amplitude [mV]" );
470 hEdgeOverlay[order]->SetStats(mStats);
471 hList->Add( hEdgeOverlay[order] );
472
473 //------------------------------------------------------------------------
474
475 if (mVerbosityLevel > 3) cout << "\t...booking " << HistoName("hMaxProfile", order) << endl;
476 hMaxProfile[order] = new TProfile(
477 HistoName("hMaxProfile", order),
478 HistoTitle("Mean value of each slice in overlay plot (Tprofile)", order),
479 mPixelOverlayXaxisLeft + mPixelOverlayXaxisRight ,//nbinsx
480 (-1*mPixelOverlayXaxisLeft)-0.5, //xlow
481 mPixelOverlayXaxisRight-0.5 , //xup
482 // 512, //nbinsy
483 -55.5, //ylow
484 300.5, //yup
485 "s"); //option
486 hMaxProfile[order]->SetAxisRange(
487 mBSLMean - 5,
488 (mGainMean*(order+1)) + 10,
489 "Y");
490 hMaxProfile[order]->GetXaxis()->SetTitle( "Timeslices [a.u.]" );
491 hMaxProfile[order]->GetYaxis()->SetTitle( "Amplitude [mV]" );
492 //hMaxProfile->SetBit(TH2F::kCanRebin);
493 hMaxProfile[order]->SetStats(mStats);
494 hList->Add( hMaxProfile[order] );
495
496
497 //------------------------------------------------------------------------
498
499 if (mVerbosityLevel > 3) cout << "\t...booking " << HistoName("hEdgeProfile", order) << endl;
500 hEdgeProfile[order] = new TProfile(
501 HistoName("hEdgeProfile", order),
502 HistoTitle("Mean value of each slice in overlay plot (Tprofile)", order),
503 mPixelOverlayXaxisLeft + mPixelOverlayXaxisRight ,//nbinsx
504 (-1*mPixelOverlayXaxisLeft)-0.5, //xlow
505 mPixelOverlayXaxisRight-0.5 , //xup
506 // 512, //nbinsy
507 -55.5, //ylow
508 300.5, //yup
509 "s"); //option
510 hEdgeProfile[order]->SetLineColor(kRed);
511 hEdgeProfile[order]->SetAxisRange(
512 mBSLMean - 5,
513 (mGainMean*(order+1)) + 10,
514 "Y");
515 hEdgeProfile[order]->GetXaxis()->SetTitle( "Timeslices [a.u.]" );
516 hEdgeProfile[order]->GetYaxis()->SetTitle( "Amplitude [mV]" );
517 //hMaxProfile->SetBit(TH2F::kCanRebin);
518 hEdgeProfile[order]->SetStats(mStats);
519 hList->Add( hEdgeProfile[order] );
520
521 }
522 if (mVerbosityLevel > 2) cout << "...done" << endl;
523}
524//end of BookPixelHistos
525//----------------------------------------------------------------------------
526
527void
528Pixel::BookDistributionHistos( )
529{
530 if (!mOptions.IsNull() )
531 {
532 int x_min = 0;
533 int x_max = 0;
534
535 for (int order =0; order < mMaxPulseOrder; order++)
536 {
537 if (mVerbosityLevel > 2) cout << endl
538 << "...book distribution histograms"
539 << endl;
540
541 if (mOptions.Contains("S"))
542 {
543 if (mVerbosityLevel > 3) cout << "\t...booking " << HistoName("hSlopeRisingEdge", order) << endl;
544 hSlopeRisingEdge[order] = new TH1F (
545 HistoName("hSlopeRisingEdge", order),
546 HistoTitle("Distribution of rising edge's slope", order),
547 600,
548 -10.1,
549 10.1
550 );
551 hSlopeRisingEdge[order]->SetAxisRange(
552 -1,
553 7,
554 "X");
555 hSlopeRisingEdge[order]->GetXaxis()->SetTitle( "Slope Amplitude/time [mV/timeslices]" );
556 hSlopeRisingEdge[order]->GetYaxis()->SetTitle( "counts" );
557 hSlopeRisingEdge[order]->SetStats(mStats);
558 hList->Add( hSlopeRisingEdge[order] );
559 }
560
561 if (mOptions.Contains("R"))
562 {
563 x_min = -15;
564 x_max = 35;
565
566 if (mVerbosityLevel > 3) cout << "\t...booking " << HistoName("hRisingEdgeToMax", order) << endl;
567 hRisingEdgeToMax[order] = new TH1I (
568 HistoName("hRisingEdgeToMax", order),
569 HistoTitle("Distribution of distance between rising edge and pulse's maximum", order),
570 x_max -x_min,
571 x_min,
572 x_max
573 );
574 hSlopeRisingEdge[order]->SetAxisRange(
575 -5,
576 25,
577 "X");
578 hRisingEdgeToMax[order]->GetXaxis()->SetTitle( "Timeslices [a.u.]" );
579 hRisingEdgeToMax[order]->GetYaxis()->SetTitle( "counts" );
580 hRisingEdgeToMax[order]->SetStats(mStats);
581 hList->Add( hRisingEdgeToMax[order] );
582 }
583
584 if (mOptions.Contains("M"))
585 {
586 x_min = 10;
587 x_max = 290;
588 if (mVerbosityLevel > 3) cout << "\t...booking " << HistoName("hPosOfMax", order) << endl;
589 hPosOfMax[order] = new TH1I (
590 HistoName("hPosOfMax", order),
591 HistoTitle("Distribution of pulse's maximum's positon", order),
592 x_max - x_min,
593 x_min,
594 x_max
595 );
596 hPosOfMax[order]->GetXaxis()->SetTitle( "Timeslices [a.u.]" );
597 hPosOfMax[order]->GetYaxis()->SetTitle( "counts" );
598 hRisingEdgeToMax[order]->SetStats(mStats);
599 hList->Add( hPosOfMax[order] );
600 }
601
602 if (mOptions.Contains("C"))
603 {
604 if (mVerbosityLevel > 3) cout << "\t...booking " << HistoName("hSlopeRisingEdge", order) << endl;
605 hChi2EdgetoMax[order] = new TH1F (
606 HistoName("hChi2EdgetoMax", order),
607 HistoTitle("Distribution of CHI2 comparison of Edge and Max", order),
608 600,
609 -299,
610 300
611 );
612 hChi2EdgetoMax[order]->SetAxisRange(
613 -1,
614 7,
615 "X");
616 hChi2EdgetoMax[order]->GetXaxis()->SetTitle( "p-Value" );
617 hChi2EdgetoMax[order]->GetYaxis()->SetTitle( "counts" );
618 hChi2EdgetoMax[order]->SetStats(mStats);
619// hList->Add( hChi2EdgetoMax[order] );
620 }
621
622 if (mVerbosityLevel > 2) cout << "...done" << endl;
623 }
624 }
625}
626//end of BookDistributionHistos
627//----------------------------------------------------------------------------
628
629void
630Pixel::BookTemplateHistos()
631{
632 if (mVerbosityLevel > 2) cout << endl << "...book pixel histograms" << endl;
633 for (int order = 0; order < mMaxPulseOrder; order++)
634 {
635 if (mVerbosityLevel > 3)
636 {
637 cout << "\t...booking " << HistoName("hPixelMax", order) << endl;
638 }
639
640 hPixelMax[order]=new TH1F(
641 HistoName("hPixelMax", order),
642 HistoTitle("Maximum value of each slice in overlay plot of", order),
643 mPixelOverlayXaxisLeft + mPixelOverlayXaxisRight ,
644 (-1*mPixelOverlayXaxisLeft)-0.5,
645 mPixelOverlayXaxisRight-0.5
646 );
647
648 hPixelMax[order]->SetAxisRange(
649 mBSLMean - 5,
650 (mGainMean*(order+1)) + 10,
651 "Y");
652 hPixelMax[order]->GetXaxis()->SetTitle( "Timeslices [a.u.]" );
653 hPixelMax[order]->GetYaxis()->SetTitle( "Amplitude [mV]" );
654 //hMaxProfile->SetBit(TH2F::kCanRebin);
655 hPixelMax[order]->SetStats(mStats);
656 hList->Add( hPixelMax[order] );
657
658//------------------------------------------------------------------------
659
660 if (mVerbosityLevel > 3) cout << "\t...booking " << HistoName("hPixelMean", order) << endl;
661 hPixelMean[order] = new TH1F(
662 HistoName("hPixelMean", order),
663 HistoTitle("Mean value of each slice in overlay plot of", order),
664 mPixelOverlayXaxisLeft + mPixelOverlayXaxisRight ,
665 (-1*mPixelOverlayXaxisLeft)-0.5,
666 mPixelOverlayXaxisRight-0.5
667 );
668 hPixelMean[order]->SetLineColor(kBlue);
669 hPixelMean[order]->SetAxisRange(
670 mBSLMean - 5,
671 (mGainMean*(order+1)) + 10,
672 "Y");
673 hPixelMean[order]->GetXaxis()->SetTitle( "Timeslices [a.u.]" );
674 hPixelMean[order]->GetYaxis()->SetTitle( "Amplitude [mV]" );
675 hPixelMean[order]->SetStats(mStats);
676 hList->Add( hPixelMean[order] );
677
678 //------------------------------------------------------------------------
679
680 if (mVerbosityLevel > 3) cout << "\t...booking " << HistoName("hPixelMedian", order) << endl;
681 hPixelMedian[order] = new TH1F(
682 HistoName("hPixelMedian", order),
683 HistoTitle("Median value of each slice in overlay plot of", order),
684 mPixelOverlayXaxisLeft + mPixelOverlayXaxisRight ,//nbinsx
685 (-1*mPixelOverlayXaxisLeft)-0.5, //xlow
686 mPixelOverlayXaxisRight-0.5 //xup
687 );
688 hPixelMedian[order]->SetLineColor(kRed);
689 hPixelMedian[order]->SetAxisRange(
690 mBSLMean - 5,
691 (mGainMean*(order+1)) + 10,
692 "Y");
693 hPixelMedian[order]->GetXaxis()->SetTitle( "Timeslices [a.u.]" );
694 hPixelMedian[order]->GetYaxis()->SetTitle( "Amplitude [mV]" );
695 //hMaxProfile->SetBit(TH2F::kCanRebin);
696 hPixelMedian[order]->SetStats(mStats);
697 hList->Add( hPixelMedian[order] );
698
699 }
700 if (mVerbosityLevel > 2) cout << "...done" << endl;
701}
702//end of BookTemplateHistos
703//----------------------------------------------------------------------------
704
705void
706Pixel::BookEdgeTemplateHistos()
707{
708 if (mVerbosityLevel > 2) cout << endl << "...book pixel histograms" << endl;
709 for (int order = 0; order < mMaxPulseOrder; order++)
710 {
711 if (mVerbosityLevel > 3) cout << "\t...booking " << HistoName("hPixelEdgeMax", order) << endl;
712 hPixelEdgeMax[order]=new TH1F(
713 HistoName("hPixelEdgeMax", order),
714 HistoTitle("Maximum value of each slice in overlay plot of", order),
715 mPixelOverlayXaxisLeft + mPixelOverlayXaxisRight ,
716 (-1*mPixelOverlayXaxisLeft)-0.5,
717 mPixelOverlayXaxisRight-0.5
718 );
719
720 hPixelEdgeMax[order]->SetAxisRange(
721 mBSLMean - 5,
722 (mGainMean*(order+1)) + 10,
723 "Y");
724 hPixelEdgeMax[order]->GetXaxis()->SetTitle( "Timeslices [a.u.]" );
725 hPixelEdgeMax[order]->GetYaxis()->SetTitle( "Amplitude [mV]" );
726 //hMaxProfile->SetBit(TH2F::kCanRebin);
727 hPixelEdgeMax[order]->SetStats(mStats);
728 hList->Add( hPixelEdgeMax[order] );
729
730//------------------------------------------------------------------------
731
732 if (mVerbosityLevel > 3) cout << "\t...booking " << HistoName("hPixelEdgeMean", order) << endl;
733 hPixelEdgeMean[order] = new TH1F(
734 HistoName("hPixelEdgeMean", order),
735 HistoTitle("Mean value of each slice in overlay plot of", order),
736 mPixelOverlayXaxisLeft + mPixelOverlayXaxisRight ,
737 (-1*mPixelOverlayXaxisLeft)-0.5,
738 mPixelOverlayXaxisRight-0.5
739 );
740 hPixelEdgeMean[order]->SetLineColor(kBlue);
741 hPixelEdgeMean[order]->SetAxisRange(
742 mBSLMean - 5,
743 (mGainMean*(order+1)) + 10,
744 "Y");
745 hPixelEdgeMean[order]->GetXaxis()->SetTitle( "Timeslices [a.u.]" );
746 hPixelEdgeMean[order]->GetYaxis()->SetTitle( "Amplitude [mV]" );
747 hPixelEdgeMean[order]->SetStats(mStats);
748 hList->Add( hPixelEdgeMean[order] );
749
750 //------------------------------------------------------------------------
751
752 if (mVerbosityLevel > 3) cout << "\t...booking " << HistoName("hPixelEdgeMedian", order) << endl;
753 hPixelEdgeMedian[order] = new TH1F(
754 HistoName("hPixelEdgeMedian", order),
755 HistoTitle("Median value of each slice in overlay plot of", order),
756 mPixelOverlayXaxisLeft + mPixelOverlayXaxisRight ,//nbinsx
757 (-1*mPixelOverlayXaxisLeft)-0.5, //xlow
758 mPixelOverlayXaxisRight-0.5 //xup
759 );
760 hPixelEdgeMedian[order]->SetLineColor(kRed);
761 hPixelEdgeMedian[order]->SetAxisRange(
762 mBSLMean - 5,
763 (mGainMean*(order+1)) + 10,
764 "Y");
765 hPixelEdgeMedian[order]->GetXaxis()->SetTitle( "Timeslices [a.u.]" );
766 hPixelEdgeMedian[order]->GetYaxis()->SetTitle( "Amplitude [mV]" );
767 //hMaxProfile->SetBit(TH2F::kCanRebin);
768 hPixelEdgeMedian[order]->SetStats(mStats);
769 hList->Add( hPixelEdgeMedian[order] );
770
771 }
772 if (mVerbosityLevel > 2) cout << "...done" << endl;
773}
774//end of BookEdgeTemplateHistos
775//----------------------------------------------------------------------------
776
777void
778Pixel::LoadPulseHistos()
779{
780 mRootFile->cd();
781
782 if (mVerbosityLevel > 2)
783 {
784 if (mVerbosityLevel > 3)
785 {
786 mRootFile->ls();
787 }
788 cout << "loading current File: " ;
789 gFile->pwd();
790 }
791
792 mRootFile->cd( CreateSubDirName( mChid ) ); //Go to pixel's subdirectory
793 mDirectory = gDirectory;
794
795 if (mVerbosityLevel > 2)
796 {
797 if (mVerbosityLevel > 3)
798 {
799 gDirectory->ls();
800 }
801 cout << "Current Directory: " ;
802 gDirectory->pwd();
803 }
804
805
806 if (mVerbosityLevel > 2) cout << endl << "...load pixel histograms" << endl;
807 for (int order = 0; order < mMaxPulseOrder; order++)
808 {
809
810 if (mVerbosityLevel > 3) cout << "\t...loading " << ChooseCycleNumber( HistoName("hMaxOverlay", order), 1) << endl;
811 hMaxOverlay[order] = (TH2F*)mDirectory->Get( ChooseCycleNumber( HistoName("hMaxOverlay", order), 1) );
812
813 if (mVerbosityLevel > 3) cout << "\t...loading " << HistoName("hEdgeOverlay", order) << endl;
814 hEdgeOverlay[order] = (TH2F*)mDirectory->Get( ChooseCycleNumber( HistoName("hEdgeOverlay", order), 1) );
815
816 if (mVerbosityLevel > 3) cout << "\t...loading " << HistoName("hMaxProfile", order) << endl;
817 hMaxProfile[order] = (TProfile*)mDirectory->Get( ChooseCycleNumber( HistoName("hMaxProfile", order), 1) );
818
819 if (mVerbosityLevel > 3) cout << "\t...loading " << HistoName("hEdgeProfile", order) << endl;
820 hEdgeProfile[order] = (TProfile*)mDirectory->Get( ChooseCycleNumber( HistoName("hEdgeProfile", order), 1) );
821
822
823 }
824 // mPixelOverlayXaxisRight =70; ///TODO: get it from the root file
825 // mPixelOverlayXaxisLeft =230; ///TODO: get it from the root file
826// mBSLMean =-2; ///TODO: get it from the root file
827// mGainMean =11; ///TODO: get it from the root file
828 // mOptions ="SRM"; ///TODO: get it from the root file
829
830// mPixelOverlayXaxisRight = hEdgeOverlay[0]->GetXaxis()->GetBinLowEdge(
831// hEdgeOverlay[0]->GetXaxis()->GetFirst()
832// );
833
834// mPixelOverlayXaxisLeft = hEdgeOverlay[0]->GetXaxis()->GetBinUpEdge(
835// hEdgeOverlay[0]->GetXaxis()->GetLast()
836// );
837
838 mPixelOverlayXaxisLeft = hEdgeOverlay[0]->GetBinCenter(
839 hEdgeOverlay[0]->GetXaxis()->GetFirst()
840 );
841
842 mPixelOverlayXaxisLeft *= -1;
843
844 mPixelOverlayXaxisRight = hEdgeOverlay[0]->GetBinCenter(
845 hEdgeOverlay[0]->GetXaxis()->GetLast()
846 );
847
848}
849// end of LoadPulseHistos
850//----------------------------------------------------------------------------
851
852void
853Pixel::DeletePixelHistos()
854{
855 if (mVerbosityLevel > 2)
856 {
857 cout << endl
858 << endl
859 << "\t...delete current overlay histograms of Pixel# " << mChid;
860 }
861 for (int order = 0;
862 order < mMaxPulseOrder;
863 order ++)
864 {
865 if (mVerbosityLevel > 3)
866 cout << endl << "\t\t...deleting hMaxOverlay"
867 << mChid << "_" << order;
868
869 delete hMaxOverlay[order];
870 hMaxOverlay[order] = NULL;
871
872 if (mVerbosityLevel > 3) cout << endl << "\t\t...deleting hEdgeOverlay"
873 << mChid << "_" << order ;
874 delete hEdgeOverlay[order];
875 hEdgeOverlay[order] = NULL;
876
877 if (mVerbosityLevel > 3) cout << endl << "\t\t...deleting hMaxProfile"
878 << mChid << "_" << order ;
879 delete hMaxProfile[order];
880 hMaxProfile[order] = NULL;
881
882 if (mVerbosityLevel > 3) cout << endl << "\t\t...deleting hMaxProfile2"
883 << mChid << "_" << order ;
884 delete hEdgeProfile[order];
885 hEdgeProfile[order] = NULL;
886 }
887 if (mVerbosityLevel > 3) cout << endl << "\t...deleting histogram Arrays";
888
889 if (mVerbosityLevel > 3) cout << endl << "\t\t...deleting hMaxOverlay";
890 delete[] hMaxOverlay;
891 hMaxOverlay = NULL;
892
893 if (mVerbosityLevel > 3) cout << endl << "\t\t...deleting hEdgeOverlay";
894 delete[] hEdgeOverlay;
895 hEdgeOverlay = NULL;
896
897 if (mVerbosityLevel > 3) cout << endl << "\t\t...deleting hMaxProfile";
898 delete[] hMaxProfile;
899 hMaxProfile = NULL;
900
901 if (mVerbosityLevel > 3) cout << endl << "\t\t...deleting hEdgeProfile";
902 delete[] hEdgeProfile;
903 hEdgeProfile = NULL;
904}
905// end of DeletePixelHistos
906//----------------------------------------------------------------------------
907
908void
909Pixel::DeleteDistributionHistos()
910{
911 if (mVerbosityLevel > 2)
912 {
913 cout << endl
914 << "\t...delete current distribution histograms" ;
915 }
916
917 for (int order = 0;
918 order < mMaxPulseOrder;
919 order ++)
920 {
921 if (mOptions.Contains("S"))
922 {
923 if (mVerbosityLevel > 3) cout << endl
924 << "\t\t...deleting hSlopeRisingEdge"
925 << mChid << "_" << order ;
926 delete hSlopeRisingEdge[order];
927 }
928
929 if (mOptions.Contains("R"))
930 {
931 if (mVerbosityLevel > 3) cout << endl
932 << "\t\t...deleting hRisingEdgeToMax"
933 << mChid << "_" << order ;
934 delete hRisingEdgeToMax[order];
935 }
936
937 if (mOptions.Contains("M"))
938 {
939 if (mVerbosityLevel > 3) cout << endl
940 << "\t\t...deleting hPosOfMax"
941 << mChid << "_" << order ;
942
943 delete hPosOfMax[order];
944 }
945
946 }
947 if (mVerbosityLevel > 3) cout << endl << "\t...deleting histogram Arrays";
948
949 if (mOptions.Contains("S"))
950 {
951 if (mVerbosityLevel > 3)
952 cout << endl << "\t\t...deleting hSlopeRisingEdge";
953 delete[] hSlopeRisingEdge;
954 hSlopeRisingEdge = NULL;
955 }
956
957 if (mOptions.Contains("R"))
958 {
959 if (mVerbosityLevel > 3)
960 cout << endl << "\t\t...deleting hRisingEdgeToMax";
961 delete[] hRisingEdgeToMax;
962 hRisingEdgeToMax = NULL;
963 }
964
965 if (mOptions.Contains("M"))
966 {
967 if (mVerbosityLevel > 3)
968 cout << endl << "\t\t...deleting hPosOfMax";
969 delete[] hPosOfMax;
970 hPosOfMax = NULL;
971 }
972}
973// end of DeletePixelHistos
974//----------------------------------------------------------------------------
975
976void
977Pixel::DeleteTemplateHistos()
978{
979 if (mVerbosityLevel > 2)
980 {
981 cout << endl
982 << "\t...delete current template histograms of Pixel# " << mChid;
983 }
984 for (int order = 0;
985 order < mMaxPulseOrder;
986 order ++)
987 {
988 if (mVerbosityLevel > 3) cout << endl << "\t\t...deleting hPixelMean"
989 << mChid << "_" << order ;
990 delete hPixelMean[order];
991 hPixelMean[order] = NULL;
992
993 if (mVerbosityLevel > 3) cout << endl << "\t\t...deleting hPixelMedian"
994 << mChid << "_" << order ;
995 delete hPixelMedian[order];
996 hPixelMedian[order] = NULL;
997
998 if (mVerbosityLevel > 3)
999 cout << endl << "\t\t...deleting hPixelMax"
1000 << mChid << "_" << order;
1001 delete hPixelMax[order];
1002 hPixelMax[order] = NULL;
1003
1004 }
1005 if (mVerbosityLevel > 3) cout << endl << "\t...deleting histogram Arrays";
1006
1007 if (mVerbosityLevel > 3) cout << endl << "\t\t...deleting hPixelMax";
1008 delete[] hPixelMax;
1009 hPixelMax = NULL;
1010
1011 if (mVerbosityLevel > 3) cout << endl << "\t\t...deleting hPixelMedian";
1012 delete[] hPixelMedian;
1013 hPixelMedian = NULL;
1014
1015 if (mVerbosityLevel > 3) cout << endl << "\t\t...deleting hPixelMean";
1016 delete[] hPixelMean;
1017 hPixelMean = NULL;
1018}
1019// end of DeleteTemplateHistos
1020//----------------------------------------------------------------------------
1021
1022void
1023Pixel::DeleteEdgeTemplateHistos()
1024{
1025 if (mVerbosityLevel > 2)
1026 {
1027 cout << endl
1028 << "\t...delete current Edge template histograms of Pixel# " << mChid;
1029 }
1030 for (int order = 0;
1031 order < mMaxPulseOrder;
1032 order ++)
1033 {
1034 if (mVerbosityLevel > 3)
1035 cout << endl << "\t\t...deleting hPixelEdgeMax"
1036 << mChid << "_" << order;
1037
1038 delete hPixelEdgeMax[order];
1039 hPixelEdgeMax[order] = NULL;
1040
1041 if (mVerbosityLevel > 3) cout << endl << "\t\t...deleting hPixelEdgeMedian"
1042 << mChid << "_" << order ;
1043 delete hPixelEdgeMedian[order];
1044 hPixelEdgeMedian[order] = NULL;
1045
1046 if (mVerbosityLevel > 3) cout << endl << "\t\t...deleting hPixelEdgeMean"
1047 << mChid << "_" << order ;
1048 delete hPixelEdgeMean[order];
1049 hPixelEdgeMean[order] = NULL;
1050
1051 }
1052 if (mVerbosityLevel > 3) cout << endl << "\t...deleting histogram Arrays";
1053
1054 if (mVerbosityLevel > 3) cout << endl << "\t\t...deleting hPixelEdgeMax";
1055 delete[] hPixelEdgeMax;
1056 hPixelEdgeMax = NULL;
1057
1058 if (mVerbosityLevel > 3) cout << endl << "\t\t...deleting hPixelEdgeMedian";
1059 delete[] hPixelEdgeMedian;
1060 hPixelEdgeMedian = NULL;
1061
1062 if (mVerbosityLevel > 3) cout << endl << "\t\t...deleting hPixelEdgeMean";
1063 delete[] hPixelEdgeMean;
1064 hPixelEdgeMean = NULL;
1065}
1066// end of DeleteTemplateHistos
1067//----------------------------------------------------------------------------
1068
1069void
1070Pixel::MakeTH1Pretty(
1071 TH1* histo,
1072 TString histName,
1073 TString histTitle,
1074 int order
1075 )
1076{
1077 if (mVerbosityLevel > 3) cout << "\t...booking " << HistoName(histName, order) << endl;
1078
1079 histo->SetNameTitle(
1080 HistoName(histName, order),
1081 HistoTitle(histTitle, order)
1082 );
1083
1084 histo->SetBins(
1085 mPixelOverlayXaxisLeft + mPixelOverlayXaxisRight ,
1086 (-1*mPixelOverlayXaxisLeft)-0.5,
1087 mPixelOverlayXaxisRight-0.5
1088 );
1089
1090 histo->SetAxisRange(
1091 mBSLMean - 5,
1092 (mGainMean*(order+1)) + 10,
1093 "Y");
1094 histo->GetXaxis()->SetTitle( "Timeslices [a.u.]" );
1095 histo->GetYaxis()->SetTitle( "Amplitude [mV]" );
1096 //histo->SetBit(TH2F::kCanRebin);
1097 histo->SetStats(mStats);
1098}
1099// end of MakeTH2Pretty
1100//----------------------------------------------------------------------------
1101
1102
1103void
1104Pixel::MakeTH2Pretty(
1105 TH2* histo,
1106 TString histName,
1107 TString histTitle,
1108 int order
1109 )
1110{
1111 if (mVerbosityLevel > 3) cout << "\t...designing " << HistoName(histName, order) << endl;
1112
1113 histo->SetNameTitle(
1114 HistoName(histName, order),
1115 HistoTitle(histTitle, order)
1116 );
1117
1118 histo->SetBins(
1119 mPixelOverlayXaxisLeft + mPixelOverlayXaxisRight ,
1120 (-1*mPixelOverlayXaxisLeft)-0.5,
1121 mPixelOverlayXaxisRight-0.5 ,
1122 512,
1123 -55.5,
1124 200.5
1125 );
1126
1127 histo->SetAxisRange(
1128 mBSLMean - 5,
1129 (mGainMean*(order+1)) + 10,
1130 "Y");
1131
1132 histo->GetXaxis()->SetTitle( "Timeslices [a.u.]" );
1133 histo->GetYaxis()->SetTitle( "Amplitude [mV]" );
1134 //histo->SetBit(TH2F::kCanRebin);
1135 histo->SetStats(mStats);
1136}
1137// end of MakeTH2Pretty
1138//----------------------------------------------------------------------------
1139
1140void
1141Pixel::MakeTProfilePretty(
1142 TProfile* histo,
1143 TString histName,
1144 TString histTitle,
1145 int order
1146 )
1147{
1148 if (mVerbosityLevel > 3) cout << "\t...booking " << HistoName(histName, order) << endl;
1149
1150 histo->SetNameTitle(
1151 HistoName(histName, order),
1152 HistoTitle(histTitle, order)
1153 );
1154
1155 histo->SetBins(
1156 mPixelOverlayXaxisLeft + mPixelOverlayXaxisRight ,
1157 (-1*mPixelOverlayXaxisLeft)-0.5,
1158 mPixelOverlayXaxisRight-0.5
1159 );
1160 histo->SetOption( "s" );
1161
1162 histo->SetAxisRange(
1163 mBSLMean - 5,
1164 (mGainMean*(order+1)) + 10,
1165 "Y");
1166
1167 histo->GetXaxis()->SetTitle( "Timeslices [a.u.]" );
1168 histo->GetYaxis()->SetTitle( "Amplitude [mV]" );
1169 //histo->SetBit(TH2F::kCanRebin);
1170 histo->SetStats(mStats);
1171}
1172// end of MakeTProfilePretty
1173//----------------------------------------------------------------------------
1174
1175
1176void
1177Pixel::ShiftHistoInY(
1178 TH1* histo,
1179 float shift
1180 )
1181{
1182 int min_bin = histo->GetXaxis()->GetFirst();
1183 int max_bin = histo->GetXaxis()->GetLast();
1184
1185 for (int bin = min_bin; bin <= max_bin; bin++)
1186 {
1187 histo->AddBinContent( bin, shift);
1188 }
1189
1190}
1191
1192void
1193Pixel::SetRangeUser(float xMin, float xMax, int order)
1194{
1195 hMaxOverlay[order]->GetXaxis()->SetRangeUser(xMin, xMax);
1196 hEdgeOverlay[order]->GetXaxis()->SetRangeUser(xMin, xMax);
1197
1198 hPixelMax[order]->GetXaxis()->SetRangeUser(xMin, xMax);
1199 hPixelMedian[order]->GetXaxis()->SetRangeUser(xMin, xMax);
1200 hPixelMean[order]->GetXaxis()->SetRangeUser(xMin, xMax);
1201
1202 hPixelEdgeMax[order]->GetXaxis()->SetRangeUser(xMin, xMax);
1203 hPixelEdgeMedian[order]->GetXaxis()->SetRangeUser(xMin, xMax);
1204 hPixelEdgeMean[order]->GetXaxis()->SetRangeUser(xMin, xMax);
1205
1206 return;
1207}
1208
1209void
1210Pixel::NormalizeSamplesTH2F(TH2F* histo)
1211{
1212
1213 int first = histo->GetXaxis()->GetFirst();
1214 int last = histo->GetXaxis()->GetLast();
1215
1216 TH2F *hTemp = new TH2F(*histo);
1217 hTemp->Reset();
1218
1219 for (int i = first; i < last; i++)
1220 {
1221 TH1* hTemp1D = histo->ProjectionY("_px1", i, i+1);
1222 double integral = hTemp1D->Integral();
1223 // double maximum = hTemp->GetBinContent(hTemp->GetMaximumBin());
1224 hTemp1D->Scale(1/integral);
1225 // hTemp->Scale(1/maximum);
1226 int first_sl = hTemp1D->GetXaxis()->GetFirst();
1227 int last_sl = hTemp1D->GetXaxis()->GetLast();
1228
1229 for (int j = first_sl; j < last_sl; j++)
1230 {
1231 hTemp->SetBinContent(i, j, hTemp->GetBinContent(j));
1232 }
1233 }
1234
1235 histo->Reset();
1236 histo->Add(hTemp);
1237
1238 delete hTemp;
1239 return;
1240}
1241
1242void
1243Pixel::Normalize2Dhistos(int order)
1244{
1245 NormalizeSamplesTH2F(hMaxOverlay[order]);
1246 NormalizeSamplesTH2F(hEdgeOverlay[order]);
1247 return;
1248}
1249
1250
Note: See TracBrowser for help on using the repository browser.