source: fact/tools/rootmacros/PulseTemplates/FPulseOverlay.C@ 13480

Last change on this file since 13480 was 13472, checked in by Jens Buss, 13 years ago
Bugfixes after first compilation
File size: 32.2 KB
Line 
1/********************** FPulseOverlay ***********************
2* read FACT raw data
3* remove spikes
4* calculate baseline
5* find peaks (CFD and normal discriminator)
6+ search for Peaks in data
7+ put peaks into different histos depending on Amplitude
8+ draw histos for single, double, tripple, ....Photonpulses
9+ draw Parameterdevelopment
10 so it can be used for detection of other peaks
11*************************************************************/
12//----------------------------------------------------------------------------
13// root libraries
14//----------------------------------------------------------------------------
15
16#include <TROOT.h>
17#include <TCanvas.h>
18#include <TProfile.h>
19#include <TTimer.h>
20#include <TH1F.h>
21#include <TH2F.h>
22#include <Getline.h>
23#include <TLine.h>
24#include <TBox.h>
25#include <TMath.h>
26#include <TFile.h>
27#include <TStyle.h>
28#include <TString.h>
29
30#include <stdio.h>
31#include <stdint.h>
32#include <cstdio>
33#include <iostream>
34#include <fstream>
35using namespace std;
36
37#define NPIX 1440
38#define NCELL 1024
39#define FAD_MAX_SAMPLES 1024
40#define HAVE_ZLIB
41
42//----------------------------------------------------------------------------
43// rootmacros
44//----------------------------------------------------------------------------
45
46#include "../fits.h"
47
48#include "../openFits.h"
49#include "../openFits.c"
50
51#include "../discriminator.h"
52#include "../discriminator.C"
53#include "../zerosearch.h"
54#include "../zerosearch.C"
55#include "../factfir.C"
56
57#include "../DrsCalibration.C"
58#include "../DrsCalibration.h"
59
60#include "../SpikeRemoval.h"
61#include "../SpikeRemoval.C"
62
63#include "rootfilehandler.h"
64#include "rootfilehandler.C"
65
66#include "pixel.h"
67#include "pixel.C"
68
69//----------------------------------------------------------------------------
70// Decleration of global variables
71//----------------------------------------------------------------------------
72
73bool breakout=false;
74
75vector<int16_t> AllPixelDataVector;
76vector<int16_t> StartCellVector;
77unsigned int CurrentEventID;
78size_t PXLxROI;
79UInt_t gRegionOfInterest;
80UInt_t NumberOfPixels;
81TString histotitle;
82
83size_t TriggerOffsetROI, RC;
84size_t drs_n;
85vector<float> drs_basemean;
86vector<float> drs_gainmean;
87vector<float> drs_triggeroffsetmean;
88
89vector<float> Ameas(FAD_MAX_SAMPLES); // copy of the data (measured amplitude
90vector<float> Vcorr(FAD_MAX_SAMPLES); // corrected Values
91vector<float> Vslide(FAD_MAX_SAMPLES); // sliding average result
92vector<float> Vcfd(FAD_MAX_SAMPLES); // CDF result
93vector<float> Vcfd2(FAD_MAX_SAMPLES); // CDF result + 2nd sliding average
94
95int gNEvents=0;
96float gGainMean = 9;
97float gBSLMean = 0;
98
99//typedef struct{
100// double maxAmpl;
101// int countOfMax;
102// } OverlayMaximum;
103
104//typedef struct{
105// TString name;
106// TString title;
107// TString xTitle;
108// TString yTitle;
109// float yMax;
110// float yMin;
111//} histAttrib_t;
112
113//histAttrib_t* gHistoAttrib[maxPulseOrder];
114//histAttrib_t* gProfileAttrib[maxPulseOrder];
115
116
117// histograms
118const int Number_Of_Debug_Histo_Types = 7;
119
120const unsigned int
121 Ameas_ = 0,
122 N1mean_ = 1,
123 Vcorr_ = 2,
124 Vtest_ = 3,
125 Vslide_ = 4,
126 Vcfd_ = 5,
127 Vcfd2_ = 6;
128
129//const char* gHistoTypes[8] = {
130// "hMaxOverlay",
131// "hPixelMax",
132// "hEdgeOverlay",
133// "hMaxProfile",
134// "hAllPixelOverlay",
135// "hAllPixelMax",
136// "hAllPixelMaxGaus",
137// "hAllPixelProfile"
138//};
139
140//----------------------------------------------------------------------------
141// Initialisation of histograms
142//----------------------------------------------------------------------------
143
144 // Temporary Objects
145 TH1F* debugHistos = NULL;
146 //TH2F* hOverlayTemp = NULL;
147 //TH1D* hProjPeak = NULL;
148 TH1F* hTesthisto = NULL;
149 TH2F* hTesthisto2 = NULL;
150
151 //Histogram Parameters
152 Int_t gPixelOverlayXaxisLeft = 0;
153 Int_t gPixelOverlayXaxisRight = 0;
154
155 //Root-File Objects
156// TObjArray* hList[sampleSetSize] = {NULL};
157 TObjArray* hRootList = NULL;
158
159 TCanvas** cgpPixelPulses = NULL;
160 TCanvas * cFiltered = NULL;
161
162//----------------------------------------------------------------------------
163// Functions
164//----------------------------------------------------------------------------
165
166void BookDebugHistos(int );
167//void BookPixelHistos(int, int, int, int );
168void BookTestHistos( int );
169
170//void DeletePixelHistos(int );
171//void SaveHistograms( const char*, const char*, TObjArray*, int );
172
173void FillHistograms(Pixel*, vector<Region>*, int, int, int, int);
174//void DrawPulseHistograms(int);
175void DrawTestHistograms( int);
176
177void UpdateCanvases( int, int);
178void DeletePixelCanvases( int, int );
179
180//----------------------------------------------------------------------------
181//----------------------------------------------------------------------------
182// MAIN - Funtion
183//----------------------------------------------------------------------------
184//----------------------------------------------------------------------------
185int FPulseOverlay(
186 char* datafilename = "../data/2011/11/09/20111109_006.fits.gz",
187 const char* drsfilename = "../data/2011/11/09/20111109_003.drs.fits.gz",
188 const char* OutRootFileName = "../analysis/FPulseTemplate/20111109_006/20111109_006.pulses.root",
189 bool ProduceGraphic = false,
190 bool spikeDebug = false,
191 bool debugPixel = false,
192 int verbosityLevel = 0, // different verbosity levels can be implemented here
193 int firstevent = 0,
194 int nevents = -1,
195 int firstpixel = 0,
196 int npixel = -1,
197 int sampleSetSize = 36,
198 int maxPulseOrder = 1,
199 int AmplWindowWidth = 14, //Width of Window for selection of pulses to histograms
200 const char* histoOptions = "S",
201 float GainMean = 8,
202 float BSLMean = -1, //4 Histogramms will be drawn, decide how far pulsehights differ from eachother
203 int avg1 = 8,
204 int avg2 = 8,
205 int OverlayWindowLeft = 70,
206 int OverlayWindowRight = 230,
207 int refresh_rate = 500 //refresh rate for canvases
208 )
209{
210//----------------------------------------------------------------------------
211// set global variables
212//----------------------------------------------------------------------------
213
214 gGainMean = GainMean;
215 gBSLMean = BSLMean;
216
217//----------------------------------------------------------------------------
218// Initialize Pixel
219//----------------------------------------------------------------------------
220 Pixel** pPixelSet = new Pixel*[sampleSetSize];
221
222//----------------------------------------------------------------------------
223// Save-Root-File Settings
224//----------------------------------------------------------------------------
225 CreateRootFile( OutRootFileName, verbosityLevel );
226
227
228//----------------------------------------------------------------------------
229// root global Settings
230//----------------------------------------------------------------------------
231
232 gPixelOverlayXaxisLeft = OverlayWindowLeft;
233 gPixelOverlayXaxisRight = OverlayWindowRight;
234
235 gStyle->SetPalette(1,0);
236 gROOT->SetStyle("Plain");
237// gPad->SetGrid();
238
239 int pulsesCanvasFrameNrs[4] = {
240 1, // Top left
241 2, // Top right
242 3, // bottom left
243 4 // bootom right
244 };
245
246 //Canvases
247 cgpPixelPulses = new TCanvas*[maxPulseOrder];
248 TCanvas* cgpTestHistos = NULL;
249
250 if (ProduceGraphic)
251 {
252 //TCanvas* gpcDevelopment = NULL;
253 TString cName = "";
254 TString cTitle = "";
255
256 for (
257 int pulse_order = maxPulseOrder - 1;
258 pulse_order >= 0 ;
259 pulse_order--
260 )
261 {
262 cName ="cgpPixelPulses";
263 cName += pulse_order;
264 cTitle ="Pulses of Order: ";
265 cTitle += pulse_order;
266 cgpPixelPulses[pulse_order] = new TCanvas(cName,cTitle, 0,pulse_order*20,800,800);
267 cgpPixelPulses[pulse_order]->Divide(2, 2);
268 }
269
270 // Create (pointer to) Canvases, which are used in every run,
271 // also in 'non-debug' runs
272 // Canvases only need if spike Debug, but I want to deklare
273 // the pointers anyway ...
274
275 if (spikeDebug)
276 {
277 cFiltered = new TCanvas("cFiltered","filtered DRS Waveforms", 1,310,400,300);
278 cFiltered->Divide(1, 3);
279 }
280
281 cgpTestHistos = new TCanvas( "cgpTestHistos", "Test Histograms", 801, 0, 800, 800 );
282 cgpTestHistos->Divide(2,0);
283 }
284//-----------------------------------------------------------------------------
285// Filter-Settings
286//-----------------------------------------------------------------------------
287// CFD filter settings
288 int k_cfd = 10;
289 vector<double> a_cfd(k_cfd, 0);
290 double b_cfd = 1.;
291 a_cfd[0]=-0.75;
292 a_cfd[k_cfd-1]=1.;
293
294//-----------------------------------------------------------------------------
295// prepare datafile
296//-----------------------------------------------------------------------------
297
298// Open the data file
299
300 fits * datafile;
301 // Opens the raw data file and 'binds' the variables given as
302 // Parameters to the data file. So they are filled with
303 // raw data as soon as datafile->GetRow(int) is called.
304 gNEvents = openDataFits(
305 datafilename,
306 &datafile,
307 AllPixelDataVector,
308 StartCellVector,
309 CurrentEventID,
310 gRegionOfInterest,
311 NumberOfPixels,
312 PXLxROI,
313 verbosityLevel
314 );
315
316 if (gNEvents == 0)
317 {
318 cout << "return code of OpenDataFile:" << datafilename<< endl;
319 cout << "is zero -> aborting." << endl;
320 return 1;
321 }
322
323 if (verbosityLevel > 0)
324 {
325 cout << endl <<"number of events in file: "<< gNEvents << "\t";
326 }
327
328 if ( nevents == -1 || nevents > gNEvents ) nevents = gNEvents; // -1 means all!
329
330 if (verbosityLevel > 0)
331 {
332 cout <<"of, which "<< nevents << " will be processed"<< endl;
333 cout <<"Total # of Pixel: "<< NumberOfPixels << "\t";
334 }
335
336 if ( npixel == -1 || npixel > (int)NumberOfPixels ) npixel = (int)NumberOfPixels; // -1 means all!
337
338 if (verbosityLevel > 0)
339 {
340 cout <<"of, which "<< npixel << " will be processed"<< endl;
341 }
342
343 //Get the DRS calibration
344 RC = openCalibFits(
345 drsfilename,
346 drs_basemean,
347 drs_gainmean,
348 drs_triggeroffsetmean,
349 TriggerOffsetROI
350 );
351
352 if (RC == 0)
353 {
354 cout << "return code of openCalibFits:" << drsfilename << endl;
355 cout << "is zero -> aborting." << endl;
356 return 1;
357 }
358
359 // Book the histograms
360 BookDebugHistos(verbosityLevel );
361 BookTestHistos( verbosityLevel );
362//-------------------------------------
363// Loop over Pixel Sets
364//-------------------------------------
365 for ( int firstPixelOfSample = firstpixel;
366 firstPixelOfSample < firstpixel + npixel;
367 firstPixelOfSample += sampleSetSize )
368 {
369
370 if (verbosityLevel >= 0)
371 {
372 cout << "------------------------------------------------" << endl
373 << "...processing Sample from Pixel: "
374 << firstPixelOfSample
375 << "to Pixel: "
376 << firstPixelOfSample+sampleSetSize-1 << endl;
377 }
378// BookPixelHistos(
379// sampleSetSize,
380// firstPixelOfSample,
381// maxPulseOrder,
382// verbosityLevel
383// );
384
385//--------------------------------------------------------------------
386// Loops over Every Event of Pixel
387//--------------------------------------------------------------------
388 for ( int ev = firstevent; ev < firstevent + nevents; ev++)
389 {
390 // Get an Event --> consists of 1440 Pixel ...erm....data
391 datafile->GetRow( ev );
392
393 if (verbosityLevel > 0)
394 {
395 cout << "-------------------------------------" << endl
396 << "...processing Event: " << CurrentEventID
397 << "/" << nevents << endl;
398 }
399
400//--------------------------------------------------------------------
401// Loops over every Pixel of a Set of Pixels
402//--------------------------------------------------------------------
403 for ( int pixel = firstPixelOfSample;
404 pixel < sampleSetSize || pixel < firstpixel + npixel;
405 pixel++ )
406 {
407 if (verbosityLevel > 0)
408 {
409 cout << "-------------------------------------" << endl
410 << "...processing Pixel: " << pixel
411 << "/" << firstpixel + npixel << endl;
412 }
413
414 pPixelSet[pixel] = new Pixel(
415 pixel,
416 maxPulseOrder,
417 verbosityLevel,
418 gPixelOverlayXaxisLeft,
419 gPixelOverlayXaxisRight,
420 gBSLMean,
421 gGainMean,
422 histoOptions
423 );
424
425//-------------------------------------
426// Apply Calibration
427//-------------------------------------
428 if (verbosityLevel > 2) cout << "...applying DrsCalibration";
429 applyDrsCalibration(
430 Ameas,
431 pixel,
432 12,
433 12,
434 drs_basemean,
435 drs_gainmean,
436 drs_triggeroffsetmean,
437 gRegionOfInterest,
438 AllPixelDataVector,
439 StartCellVector
440 );
441 if (verbosityLevel > 2) cout << "...done " << endl;
442
443//-------------------------------------
444// Apply Filters
445//-------------------------------------
446 // finds spikes in the raw data, and interpolates the value
447 // spikes are: 1 or 2 slice wide, positive non physical artifacts
448 if (verbosityLevel > 2) cout << "...removeing Spikes";
449 removeSpikes (Ameas, Vcorr);
450 if (verbosityLevel > 2) cout << "...done " << endl;
451
452 // filter Vcorr with sliding average using FIR filter function
453 if (verbosityLevel > 2) cout << "...applying sliding average filter";
454 sliding_avg(Vcorr, Vslide, avg1);
455 if (verbosityLevel > 2) cout << "...done " << endl;
456
457 // filter Vslide with CFD using FIR filter function
458 if (verbosityLevel > 2) cout << "...apllying factfir filter";
459 factfir(b_cfd , a_cfd, k_cfd, Vslide, Vcfd);
460 if (verbosityLevel > 2) cout << "...done " << endl;
461
462 // filter Vcfd with sliding average using FIR filter function
463 if (verbosityLevel > 2) cout << "...applying 2nd sliding average filter";
464 sliding_avg(Vcfd, Vcfd2, avg2);
465 if (verbosityLevel > 2) cout << "...done " << endl;
466
467//-------------------------------------
468// Search vor Zero crossings
469//-------------------------------------
470 if (verbosityLevel > 2) cout << endl << "...searching zero crossings" ;
471 // peaks in Ameas[] are found by searching for zero crossings
472 // in Vcfd2
473 // first Argument 1 means ... *rising* edge
474 // second Argument 1 means ... search with stepsize 1 ... 10 is okay as well
475 vector<Region>* pZXings = zerosearch( Vcfd2 , 1 , 8);
476 // pZXings means "zero cross ings"
477 EnlargeRegion(*pZXings, 10, 10);
478 findAbsMaxInRegions(*pZXings, Vslide);
479 removeMaximaBelow( *pZXings, 3.0);
480 removeRegionWithMaxOnEdge( *pZXings, 2);
481 removeRegionOnFallingEdge( *pZXings, 100);
482 findTimeOfHalfMaxLeft(*pZXings, Vcorr, gBSLMean, 5, 10, verbosityLevel );
483 if (verbosityLevel > 2) cout << "...done" << endl;
484
485//-----------------------------------------------------------------------------
486// Fill Overlay Histos
487//-----------------------------------------------------------------------------
488 FillHistograms(
489 pPixelSet[pixel],
490 pZXings,
491 AmplWindowWidth,
492 ev,
493 maxPulseOrder,
494 verbosityLevel
495 );
496
497//-----------------------------------------------------------------------------
498// Spike Debug
499//-----------------------------------------------------------------------------
500 if ( spikeDebug )
501 {
502 // TODO do this correct. The vectors should be the rigt ones... this is just luck
503 debugHistos[Ameas_].GetXaxis()->Set(Ameas.size() , -0.5 , Ameas.size()-0.5);
504 debugHistos[Vcorr_].GetXaxis()->Set(Ameas.size() , -0.5 , Ameas.size()-0.5);
505 debugHistos[Vslide_].GetXaxis()->Set(Ameas.size() , -0.5 , Ameas.size()-0.5);
506 debugHistos[Vcfd_].GetXaxis()->Set(Ameas.size() , -0.5 , Ameas.size()-0.5);
507 debugHistos[Vcfd2_].GetXaxis()->Set(Ameas.size() , -0.5 , Ameas.size()-0.5);
508
509 for ( unsigned int sl = 0; sl < gRegionOfInterest; sl++)
510 {
511 debugHistos[Ameas_].SetBinContent(sl, Ameas[sl]);
512 debugHistos[Vcorr_].SetBinContent(sl, Vcorr[sl]);
513 debugHistos[Vslide_].SetBinContent( sl, Vslide[sl] );
514 debugHistos[Vcfd_].SetBinContent( sl, Vcfd[sl] );
515 debugHistos[Vcfd2_].SetBinContent( sl, Vcfd2[sl] );
516 }
517
518
519 cFiltered->cd(1);
520 gPad->SetGrid();
521 debugHistos[Ameas_].Draw();
522
523 cFiltered->cd(2);
524 gPad->SetGrid();
525 debugHistos[Vcorr_].Draw();
526
527 cFiltered->cd(3);
528 gPad->SetGrid();
529 debugHistos[Vslide_].Draw();
530
531 TBox *OneBox;
532 vector<TBox*> MyBoxes;
533 for (unsigned int i=0; i<pZXings->size(); i++){
534 OneBox = new TBox(
535 pZXings->at(i).maxPos -10 ,
536 pZXings->at(i).maxVal -0.5,
537 pZXings->at(i).maxPos +10 ,
538 pZXings->at(i).maxVal +0.5);
539 OneBox->SetLineColor(kBlue);
540 OneBox->SetLineWidth(1);
541 OneBox->SetFillStyle(0);
542 OneBox->SetFillColor(kRed);
543 MyBoxes.push_back(OneBox);
544 OneBox->Draw();
545 }
546
547 // cFiltered->cd(3);
548 // gPad->SetGrid();
549 // debugHistos[Vcfd2_].Draw();
550 // TLine *zeroline = new TLine(0, 0, 1024, 0);
551 // zeroline->SetLineColor(kBlue);
552 // zeroline->Draw();
553
554 cFiltered->Update();
555
556
557 //Process gui events asynchronously during input
558 TTimer timer("gSystem->ProcessEvents();", 50, kFALSE);
559 timer.TurnOn();
560 TString input = Getline("Type 'q' to exit, <return> to go on: ");
561 timer.TurnOff();
562 if (input=="q\n") {
563 breakout=true;
564 }
565
566 //TODO!!!!!!!!!
567 // do some Garbage collection ...
568 // all the Objects on the heap should be deleted here.
569
570 }// end of if(spikeDebug)
571
572 delete pZXings;
573 if (breakout) break;
574//-------------------------------------
575// Draw 1. Set of Pixel Histograms
576//-------------------------------------
577 if ((ev % refresh_rate) == 0)
578 {
579 if (ProduceGraphic)
580 {
581 if (debugPixel)
582 {
583 for ( int order = 0;
584 order < maxPulseOrder;
585 order++
586 )
587 {
588 pPixelSet[pixel]->DrawHistograms(
589 cgpPixelPulses[order],
590 pulsesCanvasFrameNrs
591 );
592 }
593 DrawTestHistograms(
594 verbosityLevel
595 );
596
597 UpdateCanvases(
598 verbosityLevel,
599 maxPulseOrder
600 );
601 }
602 }
603 }
604
605 if (breakout) break;
606
607 if (verbosityLevel > 2)
608 {
609 cout << endl << "...End of Pixel"
610 << endl << "-------------------------------------"<< endl;
611 }
612 }//End of Loop over Sample
613//-------------------------------------
614// end of Loops over Sample
615//-------------------------------------
616
617 }//End of Loop over Events
618//-------------------------------------
619// end of Loops over Events
620//-------------------------------------
621
622
623
624//-------------------------------------
625// Draw Pixel Histogramms of Overlay Spectra
626//-------------------------------------
627
628 for ( int pixel = firstPixelOfSample;
629 pixel < sampleSetSize || pixel < firstpixel + npixel;
630 pixel++ )
631 {
632 //here is what happends at the end of each loop over all Events
633// pPixelSet[pixel]->DrawHistograms(
634// cgpPixelPulses,
635// pulsesCanvasFrameNrs
636// );
637
638 SaveHistograms( //save histograms of generell results into output root file
639 OutRootFileName,
640 CreateSubDirName(pPixelSet[pixel]->mChid),
641 pPixelSet[pixel]->hList,
642 verbosityLevel
643 );
644
645 if (ProduceGraphic)
646 {
647 UpdateCanvases(
648 verbosityLevel,
649 maxPulseOrder
650 );
651 }
652
653 //Save Histograms of Pixels into Output rootfile
654 pPixelSet[pixel]->SavePixelHistograms( OutRootFileName );
655
656
657 if (debugPixel)
658 {
659 //Process gui events asynchronously during input
660 cout << endl;
661 TTimer timer("gSystem->ProcessEvents();", 50, kFALSE);
662 timer.TurnOn();
663 TString input = Getline("Type 'q' to exit, <return> to go on: ");
664 timer.TurnOff();
665 if (input=="q\n") {
666 break;
667 }
668 }
669
670 delete pPixelSet[pixel];
671
672 if (verbosityLevel > 2)
673 {
674 cout << endl << "...End of Pixel-Set"
675 << endl << "------------------------------------------------"
676 << endl;
677 }
678 }
679 }
680 // End of Loop over all Pixels
681
682//-------------------------------------
683// Draw Histograms
684//-------------------------------------
685
686 SaveHistograms( //save histograms of generell results into output root file
687 OutRootFileName,
688 "root",
689 hRootList,
690 verbosityLevel
691 );
692
693 if (ProduceGraphic)
694 {
695 UpdateCanvases(
696 verbosityLevel,
697 maxPulseOrder
698 );
699 }
700
701 DeletePixelCanvases(
702 maxPulseOrder,
703 verbosityLevel
704 );
705 return( 0 );
706}
707//----------------------------------------------------------------------------
708// end of main function
709//-----------------------------------------------------------------------------
710
711
712
713
714//-----------------------------------------------------------------------------
715// Funktions
716//-----------------------------------------------------------------------------
717
718/*
719ich erzeuge sowas wie 36 pixel mit ca 20 Histogrammen pro pixel
720wie viel speicher braucht das?
721Ich brauche eine möglichkeit jedes dieser histogramme zu identifizieren
722am besten ein array oder eine liste oder einen abstracten datentyp mit den histogrammen als attribute.
723ne klasse wäre super
724
725*/
726
727void BookTestHistos( int verbosityLevel )
728{
729 if (verbosityLevel > 2) cout << endl << "...book pixel histograms" << endl;
730
731 hTesthisto = new TH1F (
732 "hTesthisto",
733 "Deviation of rising edge and maximum",
734 600,
735 -10.1,
736 10.1
737 );
738 hTesthisto->GetXaxis()->SetTitle( "Timeslices [a.u.]" );
739 hTesthisto->GetYaxis()->SetTitle( "counts" );
740
741 hTesthisto2 = new TH2F (
742 "hTesthisto2",
743 "Deviation of rising edge and maximum by event #",
744 gNEvents,
745 250,
746 800,
747 600,
748 -10.1,
749 10.1
750 );
751// hTesthisto2->GetXaxis()->SetTitle( "Timeslices [a.u.]" );
752// hTesthisto2->GetYaxis()->SetTitle( "counts" );
753// hTesthisto2->SetMarkerStyle( 2 );
754
755 if (verbosityLevel > 2) cout << "...done" << endl;
756}
757//end of BookTestHistos
758//----------------------------------------------------------------------------
759
760
761void BookDebugHistos( int verbosityLevel )
762{
763 if (verbosityLevel > 2) cout << endl << "...book histograms" << endl;
764 hRootList = new TObjArray;
765 debugHistos = new TH1F[ Number_Of_Debug_Histo_Types ];
766 for ( int type = 0; type < Number_Of_Debug_Histo_Types; type++){
767 debugHistos[ type ].SetBins(1024, 0, 1024);
768 debugHistos[ type ].SetLineColor(1);
769 debugHistos[ type ].SetLineWidth(2);
770 debugHistos[ type ].SetStats(false);
771
772 // set X axis paras
773 debugHistos[ type ].GetXaxis()->SetLabelSize(0.08);
774 debugHistos[ type ].GetXaxis()->SetTitleSize(0.08);
775 debugHistos[ type ].GetXaxis()->SetTitleOffset(1.0);
776 debugHistos[ type ].GetXaxis()->SetTitle(Form("Time slice [%.1f ns/slice]", 1./2.));
777
778 // set Y axis paras
779 debugHistos[ type ].GetYaxis()->SetLabelSize(0.08);
780 debugHistos[ type ].GetYaxis()->SetTitleSize(0.08);
781 debugHistos[ type ].GetYaxis()->SetTitleOffset(0.3);
782 debugHistos[ type ].GetYaxis()->SetTitle("Amplitude [mV]");
783 }
784 if (verbosityLevel > 2) cout << "...done" << endl;
785}
786// end of BookDebugHistos
787//----------------------------------------------------------------------------
788
789
790void FillHistograms(
791 Pixel* CurrentPixel,
792 vector<Region>* pZXings,
793 int AmplWindowWidth,
794 int eventNumber,
795 int maxPulseOrder,
796 int verbosityLevel
797 )
798{
799 if (verbosityLevel > 2) cout << endl << "...filling pulse histograms" ;
800 bool use_this_peak=false;
801 int order_of_pulse=0;
802 vector<Region>::iterator reg;
803
804 //Loop over all found zerocrossings in Region
805 for (reg = pZXings->begin() ; reg < pZXings->end() ; reg++)
806 {
807 //skip those who are at the Rim of the ROI
808 if (reg->maxPos < 12 || (unsigned int) reg->maxPos > gRegionOfInterest-12)
809 {
810 if (verbosityLevel > 2) cout << endl << "\t...out of range" << endl;
811 continue;
812 }
813 //domstest->Fill(reg->maxPos);
814
815 // Define axis range of Histogram
816 int Left = reg->maxPos - gPixelOverlayXaxisLeft;
817 int Right = reg->maxPos + gPixelOverlayXaxisRight;
818 int EdgeLeft = reg->halfRisingEdgePos - gPixelOverlayXaxisLeft;
819 int EdgeRight = reg->halfRisingEdgePos + gPixelOverlayXaxisRight;
820
821 if (Left < 0) Left =0;
822 if (Right > (int)Ameas.size() ) Right=Ameas.size() ;
823 if (EdgeLeft < 0) EdgeLeft =0;
824 if (EdgeRight > (int)Ameas.size() ) EdgeRight=Ameas.size() ;
825
826
827 hTesthisto2->Fill( eventNumber, reg->slopeOfRisingEdge ) ;
828
829 if (verbosityLevel > 2) cout << endl << "\t...choosing Histogram" ;
830
831 //determine order of pulse and which histogram shall be filled
832 if (verbosityLevel > 2) cout << endl << "\t...choosing Histogram" ;
833 for(int order = 0; order < maxPulseOrder; order++)
834 {
835 if (Ameas[reg->maxPos] >= ((gGainMean*(order+1)) - (AmplWindowWidth/2))
836 && Ameas[reg->maxPos] < ((gGainMean*(order+1)) + AmplWindowWidth/2))
837 {
838 //hOverlayTemp = hMaxOverlay[order];
839 if (verbosityLevel > 2) cout << "...#" << order ;
840 order_of_pulse = order;
841 use_this_peak = true;
842 break;
843 }
844 else if (order >= (maxPulseOrder - 1)){
845 use_this_peak = false;
846 if (verbosityLevel > 2) cout << "...NONE" << endl ;
847 }
848 if (use_this_peak)
849 {
850 CurrentPixel->hSlopeRisingEdge[order_of_pulse]->Fill( reg->slopeOfRisingEdge ) ;
851 }
852 }
853
854 //Fill overlay und profile histograms
855 if (use_this_peak){
856 if (verbosityLevel > 2) cout << "...filling" ;
857 for ( int pos = Left; pos < Right; pos++){
858// if ();
859 CurrentPixel->hMaxOverlay[order_of_pulse]->Fill( pos - (reg->maxPos), Ameas[pos]) ;
860 CurrentPixel->hMaxProfile[order_of_pulse]->Fill( pos - (reg->maxPos), Ameas[pos]) ;
861 }
862 for ( int pos = EdgeLeft; pos < EdgeRight; pos++){
863// cout << endl << "###filling edge histo###" << endl;
864 CurrentPixel->hEdgeOverlay[order_of_pulse]->Fill( pos - (reg->halfRisingEdgePos), Ameas[pos]) ;
865 CurrentPixel->hEdgeProfile[order_of_pulse]->Fill( pos - (reg->halfRisingEdgePos), Ameas[pos]) ;
866// cout << endl << "######" << endl;
867 }
868 if (verbosityLevel > 2) cout << "...done" << endl;
869 }
870 //Breakout option
871 if (breakout)
872 break;
873 }
874 if (verbosityLevel > 2) cout << "...done" << endl;
875}
876// end of FillHistograms
877//----------------------------------------------------------------------------
878
879void DrawTestHistograms(
880 int verbosityLevel
881 )
882{
883 if (verbosityLevel > 2) cout << endl << "...drawing pulse histograms TODO CANVAS" ;
884
885// cgpTestHistos->cd(1);
886// hTesthisto->Draw();
887// cgpTestHistos->cd(2);
888// hTesthisto2->Draw("BOX");
889}
890// end of DrawTestHistograms
891//----------------------------------------------------------------------------
892
893void UpdateCanvases(
894 int verbosityLevel,
895 int max_pulse_order
896 )
897{
898 if (verbosityLevel > 3) cout << endl << "...updating canvases TODO CANVAS" ;
899 for (int pulse_order = 0; pulse_order < max_pulse_order; pulse_order++)
900 {
901// cgpPixelPulses[pulse_order]->Modified();
902// cgpPixelPulses[pulse_order]->Update();
903// cgpTestHistos->Modified();
904// cgpTestHistos->Update();
905 }
906}
907// end of UpdateCanvases
908//----------------------------------------------------------------------------
909
910void
911DeletePixelCanvases(
912 int maxPulseOrder,
913 int verbosityLevel
914 )
915{
916 if (verbosityLevel > 2) cout << endl << "...delete pixel Canvas TODO CANVAS" ;
917// for (int pulse_order = 0; pulse_order < maxPulseOrder; pulse_order ++)
918// {
919// delete cgpPixelPulses[pulse_order];
920// }
921}
922
923//----------------------------------------------------------------------------
924//----------------------------------------------------------------------------
925
926
Note: See TracBrowser for help on using the repository browser.