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

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