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

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