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

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