source: fact/tools/rootmacros/PulseTemplates/FPulseOverlay_filelist.C@ 15118

Last change on this file since 15118 was 15118, checked in by Jens Buss, 12 years ago
add comments
File size: 57.3 KB
Line 
1/********************** FPulseOverlay ***********************
2* read FACT raw data
3* remove spikes
4* calculate baseline
5* find peaks (CFD and normal discriminator)
6+ seagRCh 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#include <TF1.h>
31#include<TSystem.h>
32
33#include <stdio.h>
34#include <stdint.h>
35#include <cstdio>
36#include <iostream>
37#include <fstream>
38using namespace std;
39
40#define NPIX 1440
41#define FAD_MAX_SAMPLES 1024
42#define HAVE_ZLIB
43
44//----------------------------------------------------------------------------
45// rootmacros
46//----------------------------------------------------------------------------
47
48//#include "../fits.h"
49
50#include "../openFits.h"
51//#include "../openFits.c"
52
53#include "../discriminator.h"
54//#include "../discriminator.C"
55#include "../zerosearch.h"
56//#include "../zerosearch.h"
57# include "../factfir.h"
58//#include "../factfir.C"
59
60//#include "../DrsCalibration.C"
61#include "../DrsCalibration.h"
62
63#include "../SpikeRemoval.h"
64//#include "../SpikeRemoval.C"
65
66#include "rootfilehandler.h"
67//#include "rootfilehandler.C"
68
69#include "pixel.h"
70//#include "pixel.C"
71
72#include "configfile.h"
73
74
75//----------------------------------------------------------------------------
76// Decleration of global variables
77//----------------------------------------------------------------------------
78
79bool gBreakout=false;
80
81vector<int16_t> gAllPixelDataVector;
82vector<int16_t> gStartCellVector;
83unsigned int gCurrentEventID;
84size_t gPXLxROI;
85UInt_t gRegionOfInterest;
86UInt_t gNumberOfPixels;
87TString ghistotitle;
88
89size_t gTriggerOffsetROI;
90size_t gRC;
91size_t gDrs_n;
92vector<float> gDrsBaseMean;
93vector<float> gDrsGainMean;
94vector<float> gDrsTriggeroffsetMean;
95
96vector<float> gAmeas(FAD_MAX_SAMPLES); // copy of the data (measured amplitude
97vector<float> gVcorr(FAD_MAX_SAMPLES); // corrected Values
98vector<float> gVslide(FAD_MAX_SAMPLES); // sliding average result
99vector<float> gVcfd(FAD_MAX_SAMPLES); // CDF result
100vector<float> gVcfd2(FAD_MAX_SAMPLES); // CDF result + 2nd sliding average
101
102int gNEvents=0;
103float gGainMean = 9;
104float gBSLMean = 0;
105
106//typedef struct{
107// double maxAmpl;
108// int countOfMax;
109// } OverlayMaximum;
110
111//typedef struct{
112// TString name;
113// TString title;
114// TString xTitle;
115// TString yTitle;
116// float yMax;
117// float yMin;
118//} histAttrib_t;
119
120//histAttrib_t* gHistoAttrib[maxPulseOrder];
121//histAttrib_t* gProfileAttrib[maxPulseOrder];
122
123
124// histograms
125const int Number_Of_Debug_Histo_Types = 7;
126
127const unsigned int
128 gAmeas_ = 0,
129 N1mean_ = 1,
130 gVcorr_ = 2,
131 Vtest_ = 3,
132 gVslide_ = 4,
133 gVcfd_ = 5,
134 gVcfd2_ = 6;
135
136//const char* gHistoTypes[8] = {
137// "hMaxOverlay",
138// "hPixelMax",
139// "hEdgeOverlay",
140// "hMaxProfile",
141// "hAllPixelOverlay",
142// "hAllPixelMax",
143// "hAllPixelMaxGaus",
144// "hAllPixelProfile"
145//};
146
147//----------------------------------------------------------------------------
148// Initialisation of histograms
149//----------------------------------------------------------------------------
150
151 // Temporary Objects
152 TH1F* debugHistos = NULL;
153 //TH2F* hOverlayTemp = NULL;
154 //TH1D* hProjPeak = NULL;
155 TH1F* hTesthisto = NULL;
156 TH2F* hTesthisto2 = NULL;
157
158 //Histogram Parameters
159 Int_t gPixelOverlayXaxisLeft = 0;
160 Int_t gPixelOverlayXaxisRight = 0;
161
162 //Root-File Objects
163// TObjArray* hList[pixelSetSize] = {NULL};
164 TList* hRootList = NULL;
165
166 TCanvas** cgpPixelPulses = NULL;
167 TCanvas** cgpDistributions = NULL;
168 TCanvas* cFiltered = NULL;
169 TCanvas* cgpTestHistos = NULL;
170
171//----------------------------------------------------------------------------
172// Functions
173//----------------------------------------------------------------------------
174
175void BookDebugHistos(int );
176void BookTestHistos( int );
177
178//void DeletePixelHistos(int );
179//void SaveHistograms( const char*, const char*, TObjArray*, int );
180
181void FillHistograms(Pixel*, vector<Region>*, int, int, int , bool , int verbosityLevel );
182void DrawTestHistograms( int);
183bool ProduceDebugHistos( vector<Region> *pZXings);
184bool UseThisPulse( int, int, int, float, float bslMean, int maxPulseOrder, int verbosityLevel);
185void UpdateCanvases( int, int, bool);
186void DeletePixelCanvases( int, int );
187
188int HandleFitsFile(
189 fits * datafile,
190 TString datafilename,
191 TString drsfilename,
192 int nevents,
193 int npixel,
194 int verbosityLevel
195 );
196
197void ReadSequenzFile(
198 TString fileName,
199 vector<TString> *fitsFiles,
200 vector<TString> *drsFiles
201 );
202
203TString gDataDirectory;
204TString gHomeDirectory;
205TString ghostname;
206
207//----------------------------------------------------------------------------
208//----------------------------------------------------------------------------
209// MAIN - Funtion
210//----------------------------------------------------------------------------
211//----------------------------------------------------------------------------
212int FPulseOverlay_filelist(
213 //---------------{Process Files}---------------
214 TString inputPath = "raw/2012/08/02/",
215 TString sequenzFileName = "/home_nfs/isdc/jbbuss/analysis/pulseShape/lists/20120802templ_vs_100mV.csv",
216 TString OutputPath = "analysis/PulsTemplateAnalysis/20120802/",
217 TString OutRootFileName = "20120802_100mV_Stacking_G12B-2AWW8.root",
218 //---------------{Process parameters}---------------
219 int nRuns = -1,
220 int firstevent = 1, // Hast to be between 1 and infinity NOT 0!!!!
221 int nevents = -1,
222 int firstpixel = 0,
223 int npixel = -1,
224 int pixelSetSize = 150,
225 int maxPulseOrder = 6,
226 //---------------{stacking parameters}---------------
227 TString histoOptions = "SRM",
228 int AmplWindowWidth = 8, //Width of Window for selection of pulses to histograms
229 float GainMean = 12,
230 float BSLMean = -2, //4 Histogramms will be drawn, decide how far pulsehights differ from eachother
231 int avg1 = 8,
232 int avg2 = 8,
233 int OverlayWindowLeft = 100,
234 int OverlayWindowRight = 1024,
235
236 // pulses within this distance behind pulse max will be discarted
237 int beginRisingEdge = 5,
238 int endRisingEdge = 10,
239
240 // pulses within this distance behind pulse max will be discarted
241 float risingEdgeMinSlope = 0.5,
242 //---------------{graphical options}---------------
243 bool select_pulses = false,
244 bool ProduceGraphic = false,
245 bool spikeDebug = false,
246 bool debugPixel = false,
247 bool stats = true,
248 bool saveResults = true,
249 bool testmode = false,
250 //---------------{verbosity}---------------
251 int refresh_rate = 500, //refresh rate for canvases
252 int verbosityLevel = 0 // different verbosity levels can be implemented here
253 )
254{
255//-----------------------------------------------------------------------------
256// configuration
257//-----------------------------------------------------------------------------
258
259 // Amplitude below which pulses will be discarted
260 float minPulseAmplitude = 0.3*(GainMean-BSLMean);
261 // Amplitude above which pulses will be discarted
262 float maxPulseAmplitude = 2*(GainMean-BSLMean)*maxPulseOrder;
263 // pulses within this distance to timeline edge be discarted
264 int timeLineEdgeWidth = 2;
265 // pulses within this distance behind pulse max will be discarted
266 int FallingEdgeWidth = 200;
267
268
269//-----------------------------------------------------------------------------
270// prepare datafiles
271//-----------------------------------------------------------------------------
272
273 inputPath = SetHostsPaths(false, inputPath );
274
275 TString fitsFileSuffix = ".fits.gz";
276 TString drsFileSuffix = ".drs.fits.gz";
277
278 // declare the data file
279 fits * datafile = NULL;
280
281 // Opens the raw data file and 'binds' the variables given as
282 // Parameters to the data file. So they are filled with
283 // raw data as soon as datafile->GetRow(int) is called.
284
285 //vector of fits files to read
286 vector<TString> fitsFileNames;
287 vector<TString> drsFileNames;
288
289 cout << "...reading sequnezfile" << endl;
290 ReadSequenzFile(
291 sequenzFileName,
292 &fitsFileNames,
293 &drsFileNames
294 );
295
296 cout << "filelist\n" ;
297
298 //fill vector of fits files to read
299 cout << "generating file list:" << endl;
300 if(nRuns < fitsFileNames.size() && nRuns != -1)
301 {
302 fitsFileNames.resize( nRuns);
303 drsFileNames.resize( nRuns);
304 }
305
306 for (unsigned int fileNr = 0; fileNr < fitsFileNames.size(); fileNr++)
307 {
308 if ( fileNr >= drsFileNames.size() )
309 {
310 cout << "too less drs-files in vector, skipping rest" << endl;
311 break;
312
313 drsFileNames.resize(fileNr);
314 fitsFileNames.resize(fileNr);
315 }
316
317 cout << "...checking raw files";
318// cout << "\t fits:\t" << fitsFileNames.at(fileNr);
319// cout << "\n\t\t drs:\t" << drsFileNames.at(fileNr) << endl;
320
321 //filename/path construction
322 TString fits_filename = inputPath;
323 fits_filename.Append(fitsFileNames.at(fileNr));
324 fits_filename.Append(fitsFileSuffix);
325 TString drs_filename = inputPath;
326 drs_filename.Append(drsFileNames.at(fileNr));
327 drs_filename.Append(drsFileSuffix);
328 cout << "\n\t fits:\t" << fits_filename;
329 cout << "\n\t drs:\t" << drs_filename << endl;
330
331 //check if files are readable
332 ifstream fitsFile(fits_filename);
333 ifstream drsFile(drs_filename);
334 if (fitsFile.good() && drsFile.good())
335 {
336 //fill vector
337 cout << "...added\n" << endl;
338 fitsFileNames.at(fileNr) = fits_filename;
339 drsFileNames.at(fileNr) = drs_filename;
340 }
341 else {
342 cout << "...FAILED:";
343 cout << "\t deleting line"
344// << fitsFileNames.at(fileNr)
345// << " and "
346// << drsFileNames.at(fileNr)
347 << " from list\n" << endl;
348
349 fitsFileNames.erase(fitsFileNames.begin()+fileNr);
350 drsFileNames.erase(drsFileNames.begin()+fileNr);
351 fileNr--;
352// continue;
353 }
354 }
355 cout << endl << "size of file vectors: fits: "
356 << fitsFileNames.size()
357 << " drs: "
358 << drsFileNames.size() << endl;
359
360 if (fitsFileNames.size() < 1) return 1;
361
362//----------------------------------------------------------------------------
363// Save-Root-File Settings
364//----------------------------------------------------------------------------
365
366 OutputPath = SetHostsPaths(true, OutputPath );
367 OutRootFileName.Prepend(OutputPath);
368// drsfilename = SetHostsPaths(false, drsfilename );
369// OutRootFileName = SetHostsPaths(true, OutRootFileName );
370 cout << endl;
371// cout << "drs filename:\t" << drsfilename << endl;
372// cout << "data filename:\t" << datafilename << endl;
373 cout << "out filename:\t" << OutRootFileName << endl;
374
375
376 if (saveResults)
377 {
378 CreateRootFile( OutRootFileName, true, verbosityLevel );
379 }
380
381
382
383
384
385//----------------------------------------------------------------------------
386// root global Settings
387//----------------------------------------------------------------------------
388
389 gGainMean = GainMean;
390 gBSLMean = BSLMean;
391 gPixelOverlayXaxisLeft = OverlayWindowLeft;
392 gPixelOverlayXaxisRight = OverlayWindowRight;
393
394 gStyle->SetPalette(1,0);
395 gROOT->SetStyle("Plain");
396// gPad->SetGrid();
397
398//----------------------------------------------------------------------------
399// root Canvas Settings
400//----------------------------------------------------------------------------
401 //Canvas Pad numbering
402 int pulsesCanvasFrameNrs[4] = {
403 1, // Top left
404 2, // Top right
405 3, // bottom left
406 4 // bootom right
407 };
408
409 //Canvas Pad numbering
410 int distributionCanvasFrameNrs[4] = {
411 1, // Top left
412 2, // Top right
413 3, // bottom left
414 4 // bootom right
415 };
416
417 if (ProduceGraphic)
418 {
419
420 //Canvases
421 cgpPixelPulses = new TCanvas*[maxPulseOrder];
422 cgpDistributions = new TCanvas*[maxPulseOrder];
423
424 //TCanvas* gpcDevelopment = NULL;
425 TString cName = "";
426 TString cTitle = "";
427
428 //naming of pulse canvases
429 for (
430 int pulse_order = maxPulseOrder - 1;
431 pulse_order >= 0 ;
432 pulse_order--
433 )
434 {
435 cName ="cgpDistributions";
436 cName += pulse_order;
437 cTitle ="Distributions of Pulses with Order of: ";
438 cTitle += pulse_order;
439 cgpDistributions[pulse_order] = new TCanvas(cName,cTitle, 720,pulse_order*20,720,720);
440 cgpDistributions[pulse_order]->Divide(2, 2);
441 cName ="cgpPixelPulses";
442 cName += pulse_order;
443 cTitle ="Overlays of Pulses with Order of: ";
444 cTitle += pulse_order;
445 cgpPixelPulses[pulse_order] = new TCanvas(cName,cTitle, 0,pulse_order*20,720,720);
446 cgpPixelPulses[pulse_order]->Divide(2, 2);
447 }
448
449
450 // Create (pointer to) Canvases, which are used in every run,
451 // also in 'non-debug' runs
452 // Canvases only need if spike Debug, but I want to deklare
453 // the pointers anyway ...
454 if (spikeDebug)
455 {
456 cFiltered = new TCanvas("cFiltered","filtered DRS Waveforms", 1080,420,360,360);
457 cFiltered->Divide(1, 3);
458 }
459
460 if (testmode)
461 {
462 //additional Test histograms
463 cgpTestHistos = new TCanvas( "cgpTestHistos", "Test Histograms", 360, 420, 360, 360 );
464 cgpTestHistos->Divide(2,0);
465 }
466 }
467
468//-----------------------------------------------------------------------------
469// Filter-Settings
470//-----------------------------------------------------------------------------
471// CFD filter settings
472 int k_cfd = 10;
473 vector<double> a_cfd(k_cfd, 0);
474 double b_cfd = 1.;
475 a_cfd[0]=-0.75;
476 a_cfd[k_cfd-1]=1.;
477
478//-----------------------------------------------------------------------------
479// Book the histograms
480//-----------------------------------------------------------------------------
481
482
483
484 if (testmode)
485 {
486 BookTestHistos( verbosityLevel );
487 }
488//----------------------------------------------------------------------------
489// Initialize Pixel
490//----------------------------------------------------------------------------
491 Pixel** pixel = new Pixel*[NPIX];
492
493 for (int i = 0 ; i < NPIX; i++)
494 {
495 pixel[i] = NULL;
496 }
497
498
499//-----------------------------------------------------------------------------
500// Main Cycle
501//-----------------------------------------------------------------------------
502 cout << "------------------Main cylcle------------------------------" << endl;
503
504 if(npixel == -1) npixel = 1439;
505
506 if ( pixelSetSize == -1 )
507 {
508 pixelSetSize = firstpixel +npixel;
509 }
510 int lastPixelOfSet = 0;
511 cout << "check " << npixel << endl;
512//-------------------------------------
513// Loop over Pixel Sets
514//-------------------------------------
515 for ( int firstPixelOfSet = firstpixel;
516 firstPixelOfSet < firstpixel + npixel;
517 firstPixelOfSet += pixelSetSize )
518 {
519 lastPixelOfSet = firstPixelOfSet + pixelSetSize-1;
520 if (lastPixelOfSet > firstpixel + npixel)
521 {
522 lastPixelOfSet = firstpixel + npixel;
523 }
524 if (lastPixelOfSet > 1439)
525 {
526 lastPixelOfSet = 1439;
527 }
528 if (verbosityLevel == 0)
529 {
530 cout << "------------------------------------------------" << endl
531 << "...processing Set from Pixel "
532 << firstPixelOfSet
533 << " to Pixel "
534 << lastPixelOfSet << endl;
535 }
536
537 //-------------------------------------
538 // Loop over Fits Files
539 //-------------------------------------
540
541 cout << "loop over files" << endl;
542 for( unsigned int fileId = 0; fileId < fitsFileNames.size(); fileId++ )
543 {
544 datafile = NULL;
545// int return_val = 0;
546// return_val = HandleFitsFile(
547// datafile,
548// datafiles.at(fileId),
549// drsfilename,
550// nevents,
551// npixel,
552// verbosityLevel
553// );
554// if (return_val)
555// {
556// cerr << "ERROR" << endl;
557// return return_val;
558// }
559//==================================================
560
561 // Opens the raw data file and 'binds' the variables given as
562 // Parameters to the data file. So they are filled with
563 // raw data as soon as datafile->GetRow(int) is called.
564 cout << "\nopening " << fitsFileNames.at(fileId) << endl;
565
566 gNEvents = openDataFits(
567 fitsFileNames.at(fileId),
568 &datafile,
569 gAllPixelDataVector,
570 gStartCellVector,
571 gCurrentEventID,
572 gRegionOfInterest,
573 gNumberOfPixels,
574 gPXLxROI,
575 verbosityLevel
576 );
577
578 if (gNEvents == 0)
579 {
580 cout << "return code of OpenDataFile:" << fitsFileNames.at(fileId)<< endl;
581 cout << "is zero -> aborting." << endl;
582 return 1;
583 }
584
585 if (verbosityLevel > 0)
586 {
587 cout << endl <<"number of events in file: "<< gNEvents << "\t";
588 }
589
590 if ( nevents == -1 || nevents > gNEvents ) nevents = gNEvents; // -1 means all!
591
592 if (verbosityLevel > 0)
593 {
594 cout <<"of, which "<< nevents << " will be processed"<< endl;
595 cout <<"Total # of Pixel: "<< gNumberOfPixels << "\t";
596 }
597
598 if ( npixel == -1 || npixel > (int)gNumberOfPixels ) npixel = (int)gNumberOfPixels; // -1 means all!
599
600 if (verbosityLevel > 0)
601 {
602 cout <<"of, which "<< npixel << " will be processed"<< endl;
603 }
604
605 //Get the DRS calibration
606 gRC = openCalibFits(
607 drsFileNames.at(fileId),
608 gDrsBaseMean,
609 gDrsGainMean,
610 gDrsTriggeroffsetMean,
611 gTriggerOffsetROI
612 );
613
614 if (gRC == 0)
615 {
616 cout << "return code of openCalibFits:" << drsFileNames.at(fileId) << endl;
617 cout << "is zero -> aborting." << endl;
618 return 1;
619 }
620
621 //==================================================================
622
623//--------------------------------------------------------------------
624// Loop over every Event of Pixel Set
625//--------------------------------------------------------------------
626 for ( int ev = firstevent ; ev < firstevent + nevents; ev++)
627 {
628 // Get an Event --> consists of 1440 Pixel ...erm....data
629 datafile->GetRow( ev - 1 );
630
631 if (verbosityLevel == 1)
632 {
633 cout << "-------------------------------------" << endl
634 << "...processing Set from Pixel "
635 << firstPixelOfSet
636 << " to Pixel "
637 << lastPixelOfSet
638 << "... Event: " << gCurrentEventID
639 << "/" << nevents << endl;
640 }
641
642 //--------------------------------------------------------------------
643 // Loops over every Pixel of a Set of Pixels
644 //--------------------------------------------------------------------
645 for ( int pixelID = firstPixelOfSet;
646 pixelID < lastPixelOfSet + 1
647 && pixelID < firstpixel + npixel;
648 pixelID++ )
649 {
650 if (verbosityLevel > 1)
651 {
652 cout << "-------------------------------------" << endl
653 << "...processing Set from Pixel "
654 << firstPixelOfSet
655 << " to Pixel "
656 << lastPixelOfSet
657 << "... Event: " << gCurrentEventID
658 << "/" << nevents << endl
659 << " Pixel: " << pixelID
660 << "/" << firstpixel + npixel -1 << endl;
661 }
662
663 //-------------------------------------
664 // Create individual Pixel
665 //-------------------------------------
666 if (ev == firstevent && fileId == 0)
667 {
668 pixel[pixelID] = new Pixel(
669 pixelID,
670 maxPulseOrder,
671 verbosityLevel,
672 stats,
673 histoOptions,
674 gPixelOverlayXaxisLeft,
675 gPixelOverlayXaxisRight,
676 gBSLMean,
677 gGainMean
678 );
679 }
680
681 //-------------------------------------
682 // Apply Calibration
683 //-------------------------------------
684 if (verbosityLevel > 2) cout << "...applying DrsCalibration";
685 applyDrsCalibration(
686 gAmeas,
687 pixelID,
688 12,
689 12,
690 gDrsBaseMean,
691 gDrsGainMean,
692 gDrsTriggeroffsetMean,
693 gRegionOfInterest,
694 gAllPixelDataVector,
695 gStartCellVector
696 );
697 if (verbosityLevel > 2) cout << "...done " << endl;
698
699 //-------------------------------------
700 // Apply Filters
701 //-------------------------------------
702 // finds spikes in the raw data, and interpolates the value
703 // spikes are: 1 or 2 slice wide, positive non physical artifacts
704 if (verbosityLevel > 2) cout << "...removeing Spikes";
705 removeSpikes (gAmeas, gVcorr);
706 if (verbosityLevel > 2) cout << "...done " << endl;
707
708 // filter gVcorr with sliding average using FIR filter function
709 if (verbosityLevel > 2) cout << "...applying sliding average filter";
710 sliding_avg(gVcorr, gVslide, avg1);
711 if (verbosityLevel > 2) cout << "...done " << endl;
712
713 // filter gVslide with CFD using FIR filter function
714 if (verbosityLevel > 2) cout << "...apllying factfir filter";
715 factfir(b_cfd , a_cfd, k_cfd, gVslide, gVcfd);
716 if (verbosityLevel > 2) cout << "...done " << endl;
717
718 // filter gVcfd with sliding average using FIR filter function
719 if (verbosityLevel > 2) cout << "...applying 2nd sliding average filter";
720 sliding_avg(gVcfd, gVcfd2, avg2);
721 if (verbosityLevel > 2) cout << "...done " << endl;
722
723 //-------------------------------------
724 // Search vor Zero crossings
725 //-------------------------------------
726 if (verbosityLevel > 2) cout << endl << "...seagRChing zero crossings" ;
727 // peaks in gAmeas[] are found by seagRChing for zero crossings
728 // in gVcfd2
729 // first Argument 1 means ... *rising* edge
730 // second Argument 1 means ... seagRCh with stepsize 1 ... 10 is okay as well
731 vector<Region>* pZXings = zerosearch( gVcfd2 , 1 , 8);
732 // pZXings means "zero cross ings"
733 EnlargeRegion(*pZXings, 10, 10);
734 findAbsMaxInRegions(*pZXings, gVslide);
735 removeMaximaBelow( *pZXings, minPulseAmplitude);
736 removeMaximaAbove( *pZXings, maxPulseAmplitude);
737 removeRegionWithMaxOnEdge( *pZXings, timeLineEdgeWidth);
738 removeRegionOnFallingEdge( *pZXings, FallingEdgeWidth);
739 // Calculate the position (sample) of a pulses half maximum
740 findTimeOfHalfMaxLeft(*pZXings, gVslide, gBSLMean, beginRisingEdge, endRisingEdge, verbosityLevel );
741 //sometimes pulses where found with a very flat slope, DISMISS them
742 removeRegionWithToFlatSlope(*pZXings, risingEdgeMinSlope);
743 if (verbosityLevel > 2) cout << "...done" << endl;
744
745 //-----------------------------------------------------------------------------
746 // Fill Overlay Histos
747 //-----------------------------------------------------------------------------
748 if (verbosityLevel > 2)
749 {
750 cout << endl << "Filling Histograms of Pixel# [Set] " << pixelID
751 << " Pixel# [Got] " << pixel[pixelID]->mChid;
752 }
753 FillHistograms(
754 pixel[pixelID],
755 pZXings,
756 AmplWindowWidth,
757 ev,
758 // histoOptions,
759 maxPulseOrder,
760 select_pulses,
761 verbosityLevel
762 );
763 //-----------------------------------------------------------------------------
764 // Spike Debug
765 //-----------------------------------------------------------------------------
766 if ( spikeDebug )
767 {
768 BookDebugHistos(verbosityLevel );
769 gBreakout = ProduceDebugHistos( pZXings );
770 }// end of if(spikeDebug)
771
772 delete pZXings;
773 if (gBreakout) break;
774 //-------------------------------------
775 // Draw 1. Set of Pixel Histograms
776 //-------------------------------------
777 if ((ev % refresh_rate) == 0)
778 {
779 if (ProduceGraphic)
780 {
781 if (debugPixel)
782 {
783 // for ( int order = 0;
784 // order < maxPulseOrder;
785 // order++
786 // )
787 // {
788 pixel[firstPixelOfSet]->DrawOverlayHistograms(
789 cgpPixelPulses,
790 pulsesCanvasFrameNrs
791 );
792
793 pixel[firstPixelOfSet]->DrawDistributionHistograms(
794 cgpDistributions,
795 distributionCanvasFrameNrs
796 );
797 // }
798 if (testmode)
799 {
800 DrawTestHistograms(
801 verbosityLevel
802 );
803 }
804
805 UpdateCanvases(
806 verbosityLevel,
807 maxPulseOrder,
808 testmode
809 );
810 }
811 }
812 }
813
814 if (gBreakout) break;
815
816 if (verbosityLevel > 1)
817 {
818 cout << endl << "...End of Pixel"
819 << endl << "-------------------------------------"<< endl;
820 }
821 }//End of Loop over Set
822 //-------------------------------------
823 // end of Loops over Set
824 //-------------------------------------
825
826 }//End of Loop over Events
827 //-------------------------------------
828 // end of Loops over Events
829 //-------------------------------------
830
831 }//End of Loop over Files
832 //-------------------------------------
833 // end of Loops over Files
834 //-------------------------------------
835
836
837//-------------------------------------
838// Draw Pixel Histogramms of Overlay Spectra
839//-------------------------------------
840
841 for ( int pixelID = firstPixelOfSet;
842 pixelID < firstPixelOfSet + pixelSetSize
843 && pixelID < firstpixel + npixel;
844 pixelID++ )
845 {
846 //here is what happends at the end of each loop over all Events
847
848 if (ProduceGraphic)
849 {
850 pixel[pixelID]->DrawOverlayHistograms(
851 cgpPixelPulses,
852 pulsesCanvasFrameNrs
853 );
854
855 pixel[pixelID]->DrawDistributionHistograms(
856 cgpDistributions,
857 distributionCanvasFrameNrs
858 );
859
860 UpdateCanvases(
861 verbosityLevel,
862 maxPulseOrder,
863 testmode
864 );
865 }
866
867 //Save Histograms of Pixels into Output rootfile
868 if (verbosityLevel > 2)
869 {
870 cout << endl << "Saving Pixel# [Set] " << pixelID
871 << " Pixel# [Got] " << pixel[pixelID]->mChid;
872 }
873 pixel[pixelID]->SavePixelHistograms( OutRootFileName, saveResults );
874
875
876 if (debugPixel)
877 {
878 //Process gui events asynchronously during input
879 cout << endl;
880 TTimer timer("gSystem->ProcessEvents();", 50, kFALSE);
881 timer.TurnOn();
882 TString input = Getline("Type 'q' to exit, <return> to go on: ");
883 timer.TurnOff();
884 if (input=="q\n") {
885 break;
886 }
887 }
888
889 if (verbosityLevel > 2)
890 {
891 cout << endl << "Deleting Pixel# [Set] " << pixelID
892 << " Pixel# [Got] " << pixel[pixelID]->mChid;
893 }
894 delete pixel[pixelID];
895
896 if (verbosityLevel > 2)
897 {
898 cout << endl << "...End of Pixel-Set"
899 << endl << "------------------------------------------------"
900 << endl;
901 }
902 }
903 }
904 // End of Loop over all Pixels
905
906//-------------------------------------
907// Draw Histograms
908//-------------------------------------
909 TString test = "root";
910 SaveList( //save histograms of generell results into output root file
911 OutRootFileName,
912 test,
913 hRootList,
914 saveResults,
915 verbosityLevel
916 );
917
918 if (ProduceGraphic)
919 {
920 UpdateCanvases(
921 verbosityLevel,
922 maxPulseOrder,
923 testmode
924 );
925
926 //Process gui events asynchronously during input
927 cout << endl;
928 TTimer timer("gSystem->ProcessEvents();", 50, kFALSE);
929 timer.TurnOn();
930 Getline("Press <return> to go on");
931 timer.TurnOff();
932
933 DeletePixelCanvases(
934 maxPulseOrder,
935 verbosityLevel
936 );
937
938 if (testmode)
939 delete cgpTestHistos;
940
941 if (spikeDebug)
942 delete cFiltered;
943 }
944
945 delete datafile;
946 delete[] pixel;
947
948 return( 0 );
949}
950//----------------------------------------------------------------------------
951// end of main function
952//-----------------------------------------------------------------------------
953
954
955
956
957//-----------------------------------------------------------------------------
958// Funktions
959//-----------------------------------------------------------------------------
960
961/*
962ich erzeuge sowas wie 36 pixel mit ca 20 Histogrammen pro pixel
963wie viel speicher braucht das?
964Ich brauche eine möglichkeit jedes dieser histogramme zu identifizieren
965am besten ein array oder eine liste oder einen abstracten datentyp mit den histogrammen als attribute.
966ne klasse wäre super
967
968*/
969
970void BookTestHistos( int verbosityLevel )
971{
972 if (verbosityLevel > 2) cout << endl << "...book pixel histograms" << endl;
973
974 hTesthisto = new TH1F (
975 "hTesthisto",
976 "Deviation of rising edge and maximum",
977 600,
978 -10.1,
979 10.1
980 );
981 hTesthisto->GetXaxis()->SetTitle( "Timeslices [a.u.]" );
982 hTesthisto->GetYaxis()->SetTitle( "counts" );
983
984 hTesthisto2 = new TH2F (
985 "hTesthisto2",
986 "Deviation of rising edge and maximum by event #",
987 gNEvents,
988 250,
989 800,
990 600,
991 -10.1,
992 10.1
993 );
994// hTesthisto2->GetXaxis()->SetTitle( "Timeslices [a.u.]" );
995// hTesthisto2->GetYaxis()->SetTitle( "counts" );
996// hTesthisto2->SetMarkerStyle( 2 );
997
998 if (verbosityLevel > 2) cout << "...done" << endl;
999}
1000//end of BookTestHistos
1001//----------------------------------------------------------------------------
1002
1003
1004void
1005BookDebugHistos( int verbosityLevel )
1006{
1007 if (verbosityLevel > 2) cout << endl << "...book histograms" << endl;
1008 hRootList = new TList();
1009 debugHistos = new TH1F[ Number_Of_Debug_Histo_Types ];
1010 for ( int type = 0; type < Number_Of_Debug_Histo_Types; type++){
1011 debugHistos[ type ].SetBins(1024, 0, 1024);
1012 debugHistos[ type ].SetLineColor(1);
1013 debugHistos[ type ].SetLineWidth(2);
1014 debugHistos[ type ].SetStats(false);
1015
1016 // set X axis paras
1017 debugHistos[ type ].GetXaxis()->SetLabelSize(0.08);
1018 debugHistos[ type ].GetXaxis()->SetTitleSize(0.08);
1019 debugHistos[ type ].GetXaxis()->SetTitleOffset(1.0);
1020 debugHistos[ type ].GetXaxis()->SetTitle(Form("Time slice [%.1f ns/slice]", 1./2.));
1021
1022 // set Y axis paras
1023 debugHistos[ type ].GetYaxis()->SetLabelSize(0.08);
1024 debugHistos[ type ].GetYaxis()->SetTitleSize(0.08);
1025 debugHistos[ type ].GetYaxis()->SetTitleOffset(0.3);
1026 debugHistos[ type ].GetYaxis()->SetTitle("Amplitude [mV]");
1027// hRootList->Add( &debugHistos[ type ] );
1028 }
1029 if (verbosityLevel > 2) cout << "...done" << endl;
1030}
1031// end of BookDebugHistos
1032//----------------------------------------------------------------------------
1033
1034
1035void
1036FillHistograms(
1037 Pixel* CurrentPixel,
1038 vector<Region>* pZXings,
1039 int AmplWindowWidth,
1040 int eventNumber,
1041 int maxPulseOrder,
1042 bool select_pulses,
1043 int verbosityLevel
1044 )
1045{
1046 //entry counters
1047 int maxOverlayEntries = 0;
1048 int edgeOverlayEntries = 0;
1049 int maxProfileEntries = 0;
1050 int edgeProfileEntries = 0;
1051
1052
1053
1054
1055 if (verbosityLevel > 2) cout << endl << "...filling pulse histograms" ;
1056 if (verbosityLevel > 3) cout << endl << "...EventNR " << eventNumber ;
1057 bool use_this_peak=false;
1058 int order_of_pulse=0;
1059 vector<Region>::iterator reg;
1060 //Loop over all found zerocrossings in Region
1061 for (reg = pZXings->begin() ; reg < pZXings->end() ; reg++)
1062 {
1063 //skip those who are at the Rim of the ROI
1064 if (reg->maxPos < 12 || (unsigned int) reg->maxPos > gRegionOfInterest-12)
1065 {
1066 if (verbosityLevel > 2) cout << endl << "\t...out of range" << endl;
1067 continue;
1068 }
1069
1070 // Define axis range of Histogram
1071 int Left = reg->maxPos - gPixelOverlayXaxisLeft;
1072 int Right = reg->maxPos + gPixelOverlayXaxisRight;
1073 int EdgeLeft = reg->halfRisingEdgePos - gPixelOverlayXaxisLeft;
1074 int EdgeRight = reg->halfRisingEdgePos + gPixelOverlayXaxisRight;
1075
1076 if (Left < 0) Left = 0;
1077 if (EdgeLeft < 0) EdgeLeft = 0;
1078 if (Right > (int)gVcorr.size() ) Right = gVcorr.size();
1079 if (EdgeRight > (int)gVcorr.size() ) EdgeRight = gVcorr.size();
1080
1081
1082 if (verbosityLevel > 2) cout << endl << "\t...choosing Histogram" ;
1083 //determine order of pulse and which histogram shall be filled
1084 for ( int order = 0; order < maxPulseOrder; order++)
1085 {
1086 use_this_peak = UseThisPulse(
1087 reg->maxPos,
1088 order,
1089 AmplWindowWidth,
1090 gGainMean,
1091 gBSLMean,
1092 maxPulseOrder,
1093 verbosityLevel
1094 );
1095 if ( use_this_peak)
1096 {
1097 order_of_pulse = order;
1098 break;
1099 }
1100 }
1101 if (select_pulses){
1102 order_of_pulse = 0;
1103 use_this_peak = true;
1104 }
1105 //Fill histograms
1106 if (use_this_peak)
1107 {
1108 //get number of entries of used histograms
1109 maxOverlayEntries = CurrentPixel->hMaxOverlay[order_of_pulse]->GetEntries();
1110 edgeOverlayEntries = CurrentPixel->hEdgeOverlay[order_of_pulse]->GetEntries();
1111 maxProfileEntries = CurrentPixel->hMaxProfile[order_of_pulse]->GetEntries();
1112 edgeProfileEntries = CurrentPixel->hEdgeProfile[order_of_pulse]->GetEntries();
1113
1114
1115 //Histograms for Distributions
1116 if (CurrentPixel->mOptions.Contains("S") )
1117 {
1118 if (verbosityLevel > 2)
1119 cout << endl << "\t...filling Edge Histogram" ;
1120 CurrentPixel->hSlopeRisingEdge[order_of_pulse]->Fill( reg->slopeOfRisingEdge ) ;
1121 }
1122
1123 if (CurrentPixel->mOptions.Contains("R") )
1124 {
1125 if (verbosityLevel > 2)
1126 cout << endl << "\t...filling RisingEdgeToMax Histogram" ;
1127 CurrentPixel->hRisingEdgeToMax[order_of_pulse]->Fill( reg->distanceEdgeToMax ) ;
1128 }
1129
1130 if (CurrentPixel->mOptions.Contains("M") )
1131 {
1132 if (verbosityLevel > 2)
1133 cout << endl << "\t...filling PosOfMax Histogram" ;
1134 CurrentPixel->hPosOfMax[order_of_pulse]->Fill( reg->maxPos ) ;
1135 }
1136
1137 float average_of_max = gVcorr[reg->maxPos];
1138 average_of_max += gVcorr[reg->maxPos + 1];
1139 average_of_max += gVcorr[reg->maxPos - 1];
1140 average_of_max /= 3;
1141
1142 float slope_of_follow = 0.0;
1143
1144 //Histograms for Maximum Overlay
1145 for ( int pos = Left; pos < Right; pos++)
1146 {
1147 if (pos > reg->maxPos + 2)
1148 {
1149 if ( pos+5 >= Right )
1150 {
1151 break;
1152 }
1153 if (gVcorr[pos+1] > average_of_max)
1154 {
1155 break;
1156 }
1157 slope_of_follow = (gVcorr[pos+5] - gVcorr[pos+1])/5;
1158
1159 if (slope_of_follow > 1)
1160 {
1161 break;
1162 }
1163 }
1164 CurrentPixel->hMaxOverlay[order_of_pulse]->Fill( pos - (reg->maxPos), gVcorr[pos]) ;
1165 CurrentPixel->hMaxProfile[order_of_pulse]->Fill( pos - (reg->maxPos), gVcorr[pos]) ;
1166 }
1167 //Histograms for Edge Overlay
1168 for ( int pos = EdgeLeft; pos < EdgeRight; pos++)
1169 {
1170 if (pos > reg->maxPos + 2)
1171 {
1172 // check if the current slice is close to the end of the overlay window
1173 if ( pos+5 >= Right )
1174 {
1175 break;
1176 }
1177 // check if the next slice is larger than the pulse maximum
1178 // i guess it makes more sense to compare the average amplitude of the slices before
1179 //to the following pulse
1180 if (gVcorr[pos+1] > average_of_max)
1181 {
1182 break;
1183 }
1184
1185 // check if the next 5 slices have a steep slope
1186 slope_of_follow = (gVcorr[pos+5] - gVcorr[pos+1])/5;
1187 if (slope_of_follow > 1)
1188 {
1189 break;
1190 }
1191 }
1192// if (pos > reg->maxPos
1193// && gVcorr[pos] < average_of_max
1194// && gVcorr[pos+3] > average_of_max
1195// && gVcorr[pos+10] > average_of_max
1196// )
1197// {
1198// break;
1199// }
1200 CurrentPixel->hEdgeOverlay[order_of_pulse]->Fill( pos - (reg->halfRisingEdgePos), gVcorr[pos]) ;
1201 CurrentPixel->hEdgeProfile[order_of_pulse]->Fill( pos - (reg->halfRisingEdgePos), gVcorr[pos]) ;
1202 }
1203
1204 //set histogram entries
1205 CurrentPixel->hMaxOverlay[order_of_pulse]->SetEntries( maxOverlayEntries +1 );
1206 CurrentPixel->hEdgeOverlay[order_of_pulse]->SetEntries( edgeOverlayEntries +1 );
1207 CurrentPixel->hMaxProfile[order_of_pulse]->SetEntries( maxProfileEntries +1 );
1208 CurrentPixel->hEdgeProfile[order_of_pulse]->SetEntries( edgeProfileEntries +1 );
1209
1210 if (verbosityLevel > 2) cout << "...done" << endl;
1211 }
1212
1213 //gBreakout option
1214 if (gBreakout)
1215 {
1216 break;
1217 }
1218 }
1219 if (verbosityLevel > 2) cout << "...done" << endl;
1220}
1221// end of FillHistograms
1222//----------------------------------------------------------------------------
1223
1224bool UseThisPulse(
1225 int maxPos,
1226 int order,
1227 int AmplWindowWidth,
1228 float gainMean,
1229 float bslMean,
1230 int maxPulseOrder,
1231 int verbosityLevel
1232 )
1233{
1234 //determine if pulse is of given order
1235bool use_this_peak = false;
1236 if (gVcorr[maxPos] >= ((gainMean*(order+1)) - bslMean - (AmplWindowWidth/2))
1237 && gVcorr[maxPos] < ((gainMean*(order+1)) -bslMean + AmplWindowWidth/2))
1238 {
1239 if (verbosityLevel > 3) cout << "...#" << order ;
1240 use_this_peak = true;
1241 }
1242 else
1243 {
1244 if (verbosityLevel > 3)
1245 {
1246 if (order >= (maxPulseOrder - 1))
1247 {
1248 cout << "...NONE" << endl ;
1249 }
1250 }
1251 use_this_peak = false;
1252 }
1253
1254return use_this_peak;
1255}
1256
1257
1258void
1259DrawTestHistograms(
1260 int verbosityLevel
1261 )
1262{
1263 if (verbosityLevel > 2) cout << endl << "...drawing pulse histograms TODO CANVAS" ;
1264
1265// cgpTestHistos->cd(1);
1266// hTesthisto->Draw();
1267// cgpTestHistos->cd(2);
1268// hTesthisto2->Draw("BOX");
1269}
1270// end of DrawTestHistograms
1271//----------------------------------------------------------------------------
1272
1273void
1274UpdateCanvases(
1275 int verbosityLevel,
1276 int max_pulse_order,
1277 bool testmode
1278 )
1279{
1280 if (verbosityLevel > 3) cout << endl << "...updating canvases" ;
1281 for (int pulse_order = 0; pulse_order < max_pulse_order; pulse_order++)
1282 {
1283 cgpPixelPulses[pulse_order]->Modified();
1284 cgpPixelPulses[pulse_order]->Update();
1285 cgpDistributions[pulse_order]->Modified();
1286 cgpDistributions[pulse_order]->Update();
1287 if ( testmode )
1288 {
1289 cgpTestHistos->Modified();
1290 cgpTestHistos->Update();
1291 }
1292 }
1293}
1294// end of UpdateCanvases
1295//----------------------------------------------------------------------------
1296
1297void
1298DeletePixelCanvases(
1299 int maxPulseOrder,
1300 int verbosityLevel
1301 )
1302{
1303 if (verbosityLevel > 2) cout << endl << "...delete pixel Canvases" ;
1304 for (int pulse_order = 0; pulse_order < maxPulseOrder; pulse_order++ )
1305 {
1306 delete cgpPixelPulses[pulse_order];
1307 delete cgpDistributions[pulse_order];
1308 }
1309 delete[] cgpPixelPulses;
1310 delete[] cgpDistributions;
1311}
1312
1313//----------------------------------------------------------------------------
1314//----------------------------------------------------------------------------
1315
1316bool
1317ProduceDebugHistos(
1318 vector<Region>* pZXings
1319 )
1320{
1321 // TODO do this correct. The vectors should be the rigt ones... this is just luck
1322 debugHistos[gAmeas_].GetXaxis()->Set(gAmeas.size() , -0.5 , gAmeas.size()-0.5);
1323 debugHistos[gVcorr_].GetXaxis()->Set(gAmeas.size() , -0.5 , gAmeas.size()-0.5);
1324 debugHistos[gVslide_].GetXaxis()->Set(gAmeas.size() , -0.5 , gAmeas.size()-0.5);
1325 debugHistos[gVcfd_].GetXaxis()->Set(gAmeas.size() , -0.5 , gAmeas.size()-0.5);
1326 debugHistos[gVcfd2_].GetXaxis()->Set(gAmeas.size() , -0.5 , gAmeas.size()-0.5);
1327
1328 for ( unsigned int sl = 0; sl < gRegionOfInterest; sl++)
1329 {
1330 debugHistos[gAmeas_].SetBinContent(sl, gAmeas[sl]);
1331 debugHistos[gVcorr_].SetBinContent(sl, gVcorr[sl]);
1332 debugHistos[gVslide_].SetBinContent( sl, gVslide[sl] );
1333 debugHistos[gVcfd_].SetBinContent( sl, gVcfd[sl] );
1334 debugHistos[gVcfd2_].SetBinContent( sl, gVcfd2[sl] );
1335 }
1336
1337 bool has_negative_slope = false;
1338 cFiltered->cd(1);
1339 gPad->SetGrid();
1340 debugHistos[gAmeas_].Draw();
1341
1342 TF1 *OneEdge;
1343 TLine *OneLine;
1344 TBox *OneBox;
1345 vector<TF1*> MyEdges;
1346 vector<TBox*> MyBoxes;
1347 vector<TBox*> MyLines;
1348
1349 int left = debugHistos[gAmeas_].GetXaxis()->GetFirst();
1350 int right = debugHistos[gAmeas_].GetXaxis()->GetLast();
1351 vector<Region>::iterator region;
1352 for (region = pZXings->begin() ; region < pZXings->end() ; region++)
1353 {
1354 if (region->slopeOfRisingEdge < 0)
1355 {
1356 has_negative_slope = true;
1357 }
1358 }
1359
1360 if (has_negative_slope)
1361 {
1362 for (unsigned int i=0; i<pZXings->size(); i++){
1363 Region* reg = &pZXings->at(i);
1364 cout << "Slope is: " << reg->slopeOfRisingEdge << endl;
1365
1366// xBegin = (reg->halfRisingEdgePos - reg->distanceEdgeToMax);
1367// yBegin = reg->integRCeptRisingEdge + reg->slopeOfRisingEdge * (xBegin)
1368
1369 OneEdge = new TF1(
1370 "OneEdge",
1371 "[0]*x+[1]",
1372 left,
1373 right
1374 );
1375
1376 OneEdge->SetParameters(
1377 reg->slopeOfRisingEdge,
1378 reg->interceptRisingEdge
1379 );
1380
1381 OneEdge->SetLineColor(kRed);
1382 OneEdge->SetLineWidth(1);
1383 MyEdges.push_back(OneEdge);
1384
1385 OneEdge->Draw("SAME");
1386// delete OneEdge;
1387
1388 OneBox = new TBox(
1389 pZXings->at(i).maxPos -10 ,
1390 pZXings->at(i).maxVal -0.5,
1391 pZXings->at(i).maxPos +10 ,
1392 pZXings->at(i).maxVal +0.5);
1393 OneBox->SetLineColor(kBlue);
1394 OneBox->SetLineWidth(1);
1395 OneBox->SetFillStyle(0);
1396 OneBox->SetFillColor(kRed);
1397 MyBoxes.push_back(OneBox);
1398 OneBox->Draw();
1399
1400 OneLine = new TLine(
1401 pZXings->at(i).halfRisingEdgePos,
1402 gAmeas[pZXings->at(i).halfRisingEdgePos],
1403 pZXings->at(i).halfRisingEdgePos,
1404 pZXings->at(i).halfRisingEdgePos * pZXings->at(i).slopeOfRisingEdge + pZXings->at(i).interceptRisingEdge
1405 );
1406 OneLine->SetLineColor(kBlue);
1407 OneLine->SetLineWidth(3);
1408 MyLines.push_back(OneBox);
1409 OneLine->Draw();
1410 }
1411
1412 cFiltered->cd(2);
1413 gPad->SetGrid();
1414 debugHistos[gVslide_].Draw();
1415 debugHistos[gVcorr_].Draw("SAME");
1416
1417 for (unsigned int i=0; i<MyEdges.size(); i++){
1418 MyEdges.at(i)->Draw("SAME");
1419 }
1420 for (unsigned int i=0; i<MyBoxes.size(); i++){
1421 MyBoxes.at(i)->Draw();
1422 }
1423 for (unsigned int i=0; i<MyLines.size(); i++){
1424 MyLines.at(i)->Draw();
1425 }
1426
1427 cFiltered->cd(3);
1428 gPad->SetGrid();
1429 debugHistos[gVcorr_].SetLineColor(kBlue);
1430 debugHistos[gVcorr_].Draw();
1431 debugHistos[gAmeas_].Draw("SAME");
1432 debugHistos[gVslide_].SetLineColor(kRed);
1433 debugHistos[gVslide_].Draw("SAME");
1434 debugHistos[gVcfd_].SetLineColor(kGreen);
1435 debugHistos[gVcfd_].Draw("SAME");
1436 debugHistos[gVcfd2_].SetLineColor(kViolet);
1437 debugHistos[gVcfd2_].Draw("SAME");
1438 for (unsigned int i=0; i<MyEdges.size(); i++){
1439 MyEdges.at(i)->Draw("SAME");
1440 }
1441 for (unsigned int i=0; i<MyBoxes.size(); i++){
1442 MyBoxes.at(i)->Draw();
1443 }
1444 for (unsigned int i=0; i<MyLines.size(); i++){
1445 MyLines.at(i)->Draw();
1446 }
1447
1448
1449// cFiltered->cd(3);
1450// gPad->SetGrid();
1451// debugHistos[gVcfd2_].Draw();
1452// TLine *zeroline = new TLine(0, 0, 1024, 0);
1453// zeroline->SetLineColor(kBlue);
1454// zeroline->Draw();
1455
1456 cFiltered->Update();
1457
1458
1459 //Process gui events asynchronously during input
1460 TTimer timer("gSystem->ProcessEvents();", 50, kFALSE);
1461 timer.TurnOn();
1462 TString input = Getline("Type 'q' to exit, <return> to go on: ");
1463 timer.TurnOff();
1464 if (input=="q\n") {
1465 return true;
1466 }
1467
1468 MyLines.clear();
1469 MyBoxes.clear();
1470 MyEdges.clear();
1471
1472// for (unsigned int i=0; i<pZXings->size(); i++)
1473// {
1474// delete MyEdges.at(i)
1475// delete MyBoxes.at(i);
1476// }
1477// delete OneBox;
1478// delete OneEdge;
1479// delete OneLine;
1480
1481// MyEdges.erase();
1482// MyBoxes.erase();
1483 }
1484
1485 //TODO!!!!!!!!!
1486 // do some Garbage collection ...
1487 // all the Objects on the heap should be deleted here.
1488return false;
1489}// end of if(spikeDebug)
1490
1491int HandleFitsFile(
1492 fits * datafile,
1493 TString datafilename,
1494 TString drsfilename,
1495 int nevents,
1496 int npixel,
1497 int verbosityLevel
1498 )
1499{
1500 // Opens the raw data file and 'binds' the variables given as
1501 // Parameters to the data file. So they are filled with
1502 // raw data as soon as datafile->GetRow(int) is called.
1503 cout << "\nopening " << datafilename << endl;
1504
1505 gNEvents = openDataFits(
1506 datafilename,
1507 &datafile,
1508 gAllPixelDataVector,
1509 gStartCellVector,
1510 gCurrentEventID,
1511 gRegionOfInterest,
1512 gNumberOfPixels,
1513 gPXLxROI,
1514 verbosityLevel
1515 );
1516
1517 if (gNEvents == 0)
1518 {
1519 cout << "return code of OpenDataFile:" << datafilename<< endl;
1520 cout << "is zero -> aborting." << endl;
1521 return 1;
1522 }
1523
1524 if (verbosityLevel > 0)
1525 {
1526 cout << endl <<"number of events in file: "<< gNEvents << "\t";
1527 }
1528
1529 if ( nevents == -1 || nevents > gNEvents ) nevents = gNEvents; // -1 means all!
1530
1531 if (verbosityLevel > 0)
1532 {
1533 cout <<"of, which "<< nevents << " will be processed"<< endl;
1534 cout <<"Total # of Pixel: "<< gNumberOfPixels << "\t";
1535 }
1536
1537 if ( npixel == -1 || npixel > (int)gNumberOfPixels ) npixel = (int)gNumberOfPixels; // -1 means all!
1538
1539 if (verbosityLevel > 0)
1540 {
1541 cout <<"of, which "<< npixel << " will be processed"<< endl;
1542 }
1543
1544 //Get the DRS calibration
1545 gRC = openCalibFits(
1546 drsfilename,
1547 gDrsBaseMean,
1548 gDrsGainMean,
1549 gDrsTriggeroffsetMean,
1550 gTriggerOffsetROI
1551 );
1552
1553 if (gRC == 0)
1554 {
1555 cout << "return code of openCalibFits:" << drsfilename << endl;
1556 cout << "is zero -> aborting." << endl;
1557 return 1;
1558 }
1559 return 0;
1560}
1561
1562void ReadSequenzFile(TString fileName, vector<TString> *fitsFiles, vector<TString> *drsFiles)
1563{
1564 ifstream seqFile;
1565 seqFile.open(fileName,ios::in);
1566
1567 TString fitsName, drsName;
1568
1569 if(!seqFile)
1570 {
1571 cerr << "***** no config-file in the user defined directory.\n"
1572 << "Check the path .\n" << endl;
1573 return;
1574 }
1575
1576 if(!seqFile.good()) {
1577 cerr << "***** not able to read config-file." << endl;
1578 return;
1579 }
1580
1581 while(!seqFile.eof())
1582 {
1583 seqFile >> fitsName >> drsName;
1584
1585 if (!fitsName.IsWhitespace() && !fitsName.IsNull())
1586 {
1587 fitsFiles->push_back(fitsName);
1588
1589 if (!drsName.IsWhitespace() && !drsName.IsNull())
1590 {
1591 drsFiles->push_back(drsName);
1592 }
1593 else drsFiles->push_back("0");
1594 }
1595 }
1596
1597 seqFile.close();
1598
1599 return;
1600}
1601
1602
1603//int main(int argc,char *argv[])
1604//{
1605
1606// TString test;
1607// TString gRCFileName;
1608// TString processType = "overlay";
1609// bool gRCFileNameCmdSet = false;
1610// int verbLevel = 0; // different verbosity levels can be implemented here
1611// bool verbLevelCmdSet = false;
1612// bool save = false;
1613// bool produceGraphic = false;
1614
1615// // decode arguments
1616// if(argc < 2)
1617// {
1618// printf("no arguements given, using standard arguments\n");
1619// }
1620
1621// // set conditions for functions arguments
1622// for (int i=1;i<argc;i++)
1623// {
1624// test = argv[i];
1625
1626// if (test.Contains("--config_file") || test.Contains("-c"))
1627// {
1628// cout << "gRC-File: \"" << argv[i + 1] << "\"" << endl;
1629// gRCFileName = argv[i + 1];
1630// gRCFileNameCmdSet = true;
1631// continue;
1632// }
1633
1634// if (test.Contains("--verbosity") || test.Contains("-v"))
1635// {
1636// cout << "Verbosity Level: \"" << argv[i + 1] << "\"" << endl;
1637// verbLevel = atoi(argv[i + 1]);
1638// continue;
1639// }
1640
1641// if (test.Contains("--save") || test.Contains("-s"))
1642// {
1643// cout << "will save results" << endl;
1644// save = true;
1645// continue;
1646// }
1647
1648// if (test.Contains("--graphics") || test.Contains("-g"))
1649// {
1650// cout << "will produce graphics" << endl;
1651// produceGraphic = true;
1652// continue;
1653// }
1654// }
1655
1656// // reading gRC-File:
1657// configfile gRCfile( gRCFileName, processType );
1658
1659// if (save)
1660// {
1661// gRCfile.mSave = save;
1662// }
1663
1664// if (verbLevelCmdSet)
1665// {
1666// gRCfile.mVerbLevel = verbLevel;
1667// }
1668
1669// if (produceGraphic)
1670// {
1671// gRCfile.mProduceGraphic = produceGraphic;
1672// }
1673
1674// FPulseOverlay(
1675// gRCfile.mInputPath,
1676// gRCfile.mDataFileName,
1677// gRCfile.mDrsFileName,
1678// gRCfile.mOutputPath,
1679// gRCfile.mOutputFile,
1680// gRCfile.mFirstEvent,
1681// gRCfile.mNumEvents,
1682// gRCfile.mFirstPixel,
1683// gRCfile.mNumPixel,
1684// gRCfile.mPixelSetSize,
1685// gRCfile.mMaxOrder,
1686// gRCfile.mVerbLevel,
1687// gRCfile.mHistoOptions,
1688// gRCfile.mAmplWindowWidth,
1689// gRCfile.mGainMean,
1690// gRCfile.mBSLMean,
1691// gRCfile.mAvg1,
1692// gRCfile.mAvg2,
1693// gRCfile.mOverlayWindowLeft,
1694// gRCfile.mOverlayWindowRight,
1695// gRCfile.mProduceGraphic,
1696// gRCfile.mSpikeDebug,
1697// gRCfile.mDbgPixel,
1698// gRCfile.mPrintStats,
1699// gRCfile.mSave,
1700// gRCfile.mTestMode,
1701// gRCfile.mRefreshRate
1702// );
1703// return 0;
1704
1705//}
Note: See TracBrowser for help on using the repository browser.