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

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