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

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