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

Last change on this file since 14942 was 14941, checked in by Jens Buss, 12 years ago
changed SaveHistograms to SaveFileList
File size: 56.9 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 if ( pos+5 >= Right )
1173 {
1174 break;
1175 }
1176 if (gVcorr[pos+1] > average_of_max)
1177 {
1178 break;
1179 }
1180 slope_of_follow = (gVcorr[pos+5] - gVcorr[pos+1])/5;
1181
1182 if (slope_of_follow > 1)
1183 {
1184 break;
1185 }
1186 }
1187// if (pos > reg->maxPos
1188// && gVcorr[pos] < average_of_max
1189// && gVcorr[pos+3] > average_of_max
1190// && gVcorr[pos+10] > average_of_max
1191// )
1192// {
1193// break;
1194// }
1195 CurrentPixel->hEdgeOverlay[order_of_pulse]->Fill( pos - (reg->halfRisingEdgePos), gVcorr[pos]) ;
1196 CurrentPixel->hEdgeProfile[order_of_pulse]->Fill( pos - (reg->halfRisingEdgePos), gVcorr[pos]) ;
1197 }
1198
1199 //set histogram entries
1200 CurrentPixel->hMaxOverlay[order_of_pulse]->SetEntries( maxOverlayEntries +1 );
1201 CurrentPixel->hEdgeOverlay[order_of_pulse]->SetEntries( edgeOverlayEntries +1 );
1202 CurrentPixel->hMaxProfile[order_of_pulse]->SetEntries( maxProfileEntries +1 );
1203 CurrentPixel->hEdgeProfile[order_of_pulse]->SetEntries( edgeProfileEntries +1 );
1204
1205 if (verbosityLevel > 2) cout << "...done" << endl;
1206 }
1207
1208 //gBreakout option
1209 if (gBreakout)
1210 {
1211 break;
1212 }
1213 }
1214 if (verbosityLevel > 2) cout << "...done" << endl;
1215}
1216// end of FillHistograms
1217//----------------------------------------------------------------------------
1218
1219bool UseThisPulse(
1220 int maxPos,
1221 int order,
1222 int AmplWindowWidth,
1223 float gainMean,
1224 float bslMean,
1225 int maxPulseOrder,
1226 int verbosityLevel
1227 )
1228{
1229 //determine if pulse is of given order
1230bool use_this_peak = false;
1231 if (gVcorr[maxPos] >= ((gainMean*(order+1)) - bslMean - (AmplWindowWidth/2))
1232 && gVcorr[maxPos] < ((gainMean*(order+1)) -bslMean + AmplWindowWidth/2))
1233 {
1234 if (verbosityLevel > 3) cout << "...#" << order ;
1235 use_this_peak = true;
1236 }
1237 else
1238 {
1239 if (verbosityLevel > 3)
1240 {
1241 if (order >= (maxPulseOrder - 1))
1242 {
1243 cout << "...NONE" << endl ;
1244 }
1245 }
1246 use_this_peak = false;
1247 }
1248
1249return use_this_peak;
1250}
1251
1252
1253void
1254DrawTestHistograms(
1255 int verbosityLevel
1256 )
1257{
1258 if (verbosityLevel > 2) cout << endl << "...drawing pulse histograms TODO CANVAS" ;
1259
1260// cgpTestHistos->cd(1);
1261// hTesthisto->Draw();
1262// cgpTestHistos->cd(2);
1263// hTesthisto2->Draw("BOX");
1264}
1265// end of DrawTestHistograms
1266//----------------------------------------------------------------------------
1267
1268void
1269UpdateCanvases(
1270 int verbosityLevel,
1271 int max_pulse_order,
1272 bool testmode
1273 )
1274{
1275 if (verbosityLevel > 3) cout << endl << "...updating canvases" ;
1276 for (int pulse_order = 0; pulse_order < max_pulse_order; pulse_order++)
1277 {
1278 cgpPixelPulses[pulse_order]->Modified();
1279 cgpPixelPulses[pulse_order]->Update();
1280 cgpDistributions[pulse_order]->Modified();
1281 cgpDistributions[pulse_order]->Update();
1282 if ( testmode )
1283 {
1284 cgpTestHistos->Modified();
1285 cgpTestHistos->Update();
1286 }
1287 }
1288}
1289// end of UpdateCanvases
1290//----------------------------------------------------------------------------
1291
1292void
1293DeletePixelCanvases(
1294 int maxPulseOrder,
1295 int verbosityLevel
1296 )
1297{
1298 if (verbosityLevel > 2) cout << endl << "...delete pixel Canvases" ;
1299 for (int pulse_order = 0; pulse_order < maxPulseOrder; pulse_order++ )
1300 {
1301 delete cgpPixelPulses[pulse_order];
1302 delete cgpDistributions[pulse_order];
1303 }
1304 delete[] cgpPixelPulses;
1305 delete[] cgpDistributions;
1306}
1307
1308//----------------------------------------------------------------------------
1309//----------------------------------------------------------------------------
1310
1311bool
1312ProduceDebugHistos(
1313 vector<Region>* pZXings
1314 )
1315{
1316 // TODO do this correct. The vectors should be the rigt ones... this is just luck
1317 debugHistos[gAmeas_].GetXaxis()->Set(gAmeas.size() , -0.5 , gAmeas.size()-0.5);
1318 debugHistos[gVcorr_].GetXaxis()->Set(gAmeas.size() , -0.5 , gAmeas.size()-0.5);
1319 debugHistos[gVslide_].GetXaxis()->Set(gAmeas.size() , -0.5 , gAmeas.size()-0.5);
1320 debugHistos[gVcfd_].GetXaxis()->Set(gAmeas.size() , -0.5 , gAmeas.size()-0.5);
1321 debugHistos[gVcfd2_].GetXaxis()->Set(gAmeas.size() , -0.5 , gAmeas.size()-0.5);
1322
1323 for ( unsigned int sl = 0; sl < gRegionOfInterest; sl++)
1324 {
1325 debugHistos[gAmeas_].SetBinContent(sl, gAmeas[sl]);
1326 debugHistos[gVcorr_].SetBinContent(sl, gVcorr[sl]);
1327 debugHistos[gVslide_].SetBinContent( sl, gVslide[sl] );
1328 debugHistos[gVcfd_].SetBinContent( sl, gVcfd[sl] );
1329 debugHistos[gVcfd2_].SetBinContent( sl, gVcfd2[sl] );
1330 }
1331
1332 bool has_negative_slope = false;
1333 cFiltered->cd(1);
1334 gPad->SetGrid();
1335 debugHistos[gAmeas_].Draw();
1336
1337 TF1 *OneEdge;
1338 TLine *OneLine;
1339 TBox *OneBox;
1340 vector<TF1*> MyEdges;
1341 vector<TBox*> MyBoxes;
1342 vector<TBox*> MyLines;
1343
1344 int left = debugHistos[gAmeas_].GetXaxis()->GetFirst();
1345 int right = debugHistos[gAmeas_].GetXaxis()->GetLast();
1346 vector<Region>::iterator region;
1347 for (region = pZXings->begin() ; region < pZXings->end() ; region++)
1348 {
1349 if (region->slopeOfRisingEdge < 0)
1350 {
1351 has_negative_slope = true;
1352 }
1353 }
1354
1355 if (has_negative_slope)
1356 {
1357 for (unsigned int i=0; i<pZXings->size(); i++){
1358 Region* reg = &pZXings->at(i);
1359 cout << "Slope is: " << reg->slopeOfRisingEdge << endl;
1360
1361// xBegin = (reg->halfRisingEdgePos - reg->distanceEdgeToMax);
1362// yBegin = reg->integRCeptRisingEdge + reg->slopeOfRisingEdge * (xBegin)
1363
1364 OneEdge = new TF1(
1365 "OneEdge",
1366 "[0]*x+[1]",
1367 left,
1368 right
1369 );
1370
1371 OneEdge->SetParameters(
1372 reg->slopeOfRisingEdge,
1373 reg->interceptRisingEdge
1374 );
1375
1376 OneEdge->SetLineColor(kRed);
1377 OneEdge->SetLineWidth(1);
1378 MyEdges.push_back(OneEdge);
1379
1380 OneEdge->Draw("SAME");
1381// delete OneEdge;
1382
1383 OneBox = new TBox(
1384 pZXings->at(i).maxPos -10 ,
1385 pZXings->at(i).maxVal -0.5,
1386 pZXings->at(i).maxPos +10 ,
1387 pZXings->at(i).maxVal +0.5);
1388 OneBox->SetLineColor(kBlue);
1389 OneBox->SetLineWidth(1);
1390 OneBox->SetFillStyle(0);
1391 OneBox->SetFillColor(kRed);
1392 MyBoxes.push_back(OneBox);
1393 OneBox->Draw();
1394
1395 OneLine = new TLine(
1396 pZXings->at(i).halfRisingEdgePos,
1397 gAmeas[pZXings->at(i).halfRisingEdgePos],
1398 pZXings->at(i).halfRisingEdgePos,
1399 pZXings->at(i).halfRisingEdgePos * pZXings->at(i).slopeOfRisingEdge + pZXings->at(i).interceptRisingEdge
1400 );
1401 OneLine->SetLineColor(kBlue);
1402 OneLine->SetLineWidth(3);
1403 MyLines.push_back(OneBox);
1404 OneLine->Draw();
1405 }
1406
1407 cFiltered->cd(2);
1408 gPad->SetGrid();
1409 debugHistos[gVslide_].Draw();
1410 debugHistos[gVcorr_].Draw("SAME");
1411
1412 for (unsigned int i=0; i<MyEdges.size(); i++){
1413 MyEdges.at(i)->Draw("SAME");
1414 }
1415 for (unsigned int i=0; i<MyBoxes.size(); i++){
1416 MyBoxes.at(i)->Draw();
1417 }
1418 for (unsigned int i=0; i<MyLines.size(); i++){
1419 MyLines.at(i)->Draw();
1420 }
1421
1422 cFiltered->cd(3);
1423 gPad->SetGrid();
1424 debugHistos[gVcorr_].SetLineColor(kBlue);
1425 debugHistos[gVcorr_].Draw();
1426 debugHistos[gAmeas_].Draw("SAME");
1427 debugHistos[gVslide_].SetLineColor(kRed);
1428 debugHistos[gVslide_].Draw("SAME");
1429 debugHistos[gVcfd_].SetLineColor(kGreen);
1430 debugHistos[gVcfd_].Draw("SAME");
1431 debugHistos[gVcfd2_].SetLineColor(kViolet);
1432 debugHistos[gVcfd2_].Draw("SAME");
1433 for (unsigned int i=0; i<MyEdges.size(); i++){
1434 MyEdges.at(i)->Draw("SAME");
1435 }
1436 for (unsigned int i=0; i<MyBoxes.size(); i++){
1437 MyBoxes.at(i)->Draw();
1438 }
1439 for (unsigned int i=0; i<MyLines.size(); i++){
1440 MyLines.at(i)->Draw();
1441 }
1442
1443
1444// cFiltered->cd(3);
1445// gPad->SetGrid();
1446// debugHistos[gVcfd2_].Draw();
1447// TLine *zeroline = new TLine(0, 0, 1024, 0);
1448// zeroline->SetLineColor(kBlue);
1449// zeroline->Draw();
1450
1451 cFiltered->Update();
1452
1453
1454 //Process gui events asynchronously during input
1455 TTimer timer("gSystem->ProcessEvents();", 50, kFALSE);
1456 timer.TurnOn();
1457 TString input = Getline("Type 'q' to exit, <return> to go on: ");
1458 timer.TurnOff();
1459 if (input=="q\n") {
1460 return true;
1461 }
1462
1463 MyLines.clear();
1464 MyBoxes.clear();
1465 MyEdges.clear();
1466
1467// for (unsigned int i=0; i<pZXings->size(); i++)
1468// {
1469// delete MyEdges.at(i)
1470// delete MyBoxes.at(i);
1471// }
1472// delete OneBox;
1473// delete OneEdge;
1474// delete OneLine;
1475
1476// MyEdges.erase();
1477// MyBoxes.erase();
1478 }
1479
1480 //TODO!!!!!!!!!
1481 // do some Garbage collection ...
1482 // all the Objects on the heap should be deleted here.
1483return false;
1484}// end of if(spikeDebug)
1485
1486int HandleFitsFile(
1487 fits * datafile,
1488 TString datafilename,
1489 TString drsfilename,
1490 int nevents,
1491 int npixel,
1492 int verbosityLevel
1493 )
1494{
1495 // Opens the raw data file and 'binds' the variables given as
1496 // Parameters to the data file. So they are filled with
1497 // raw data as soon as datafile->GetRow(int) is called.
1498 cout << "\nopening " << datafilename << endl;
1499
1500 gNEvents = openDataFits(
1501 datafilename,
1502 &datafile,
1503 gAllPixelDataVector,
1504 gStartCellVector,
1505 gCurrentEventID,
1506 gRegionOfInterest,
1507 gNumberOfPixels,
1508 gPXLxROI,
1509 verbosityLevel
1510 );
1511
1512 if (gNEvents == 0)
1513 {
1514 cout << "return code of OpenDataFile:" << datafilename<< endl;
1515 cout << "is zero -> aborting." << endl;
1516 return 1;
1517 }
1518
1519 if (verbosityLevel > 0)
1520 {
1521 cout << endl <<"number of events in file: "<< gNEvents << "\t";
1522 }
1523
1524 if ( nevents == -1 || nevents > gNEvents ) nevents = gNEvents; // -1 means all!
1525
1526 if (verbosityLevel > 0)
1527 {
1528 cout <<"of, which "<< nevents << " will be processed"<< endl;
1529 cout <<"Total # of Pixel: "<< gNumberOfPixels << "\t";
1530 }
1531
1532 if ( npixel == -1 || npixel > (int)gNumberOfPixels ) npixel = (int)gNumberOfPixels; // -1 means all!
1533
1534 if (verbosityLevel > 0)
1535 {
1536 cout <<"of, which "<< npixel << " will be processed"<< endl;
1537 }
1538
1539 //Get the DRS calibration
1540 gRC = openCalibFits(
1541 drsfilename,
1542 gDrsBaseMean,
1543 gDrsGainMean,
1544 gDrsTriggeroffsetMean,
1545 gTriggerOffsetROI
1546 );
1547
1548 if (gRC == 0)
1549 {
1550 cout << "return code of openCalibFits:" << drsfilename << endl;
1551 cout << "is zero -> aborting." << endl;
1552 return 1;
1553 }
1554 return 0;
1555}
1556
1557void ReadSequenzFile(TString fileName, vector<TString> *fitsFiles, vector<TString> *drsFiles)
1558{
1559 ifstream seqFile;
1560 seqFile.open(fileName,ios::in);
1561
1562 TString fitsName, drsName;
1563
1564 if(!seqFile)
1565 {
1566 cerr << "***** no config-file in the user defined directory.\n"
1567 << "Check the path .\n" << endl;
1568 return;
1569 }
1570
1571 if(!seqFile.good()) {
1572 cerr << "***** not able to read config-file." << endl;
1573 return;
1574 }
1575
1576 while(!seqFile.eof())
1577 {
1578 seqFile >> fitsName >> drsName;
1579
1580 if (!fitsName.IsWhitespace() && !fitsName.IsNull())
1581 {
1582 fitsFiles->push_back(fitsName);
1583
1584 if (!drsName.IsWhitespace() && !drsName.IsNull())
1585 {
1586 drsFiles->push_back(drsName);
1587 }
1588 else drsFiles->push_back("0");
1589 }
1590 }
1591
1592 seqFile.close();
1593
1594 return;
1595}
1596
1597
1598//int main(int argc,char *argv[])
1599//{
1600
1601// TString test;
1602// TString gRCFileName;
1603// TString processType = "overlay";
1604// bool gRCFileNameCmdSet = false;
1605// int verbLevel = 0; // different verbosity levels can be implemented here
1606// bool verbLevelCmdSet = false;
1607// bool save = false;
1608// bool produceGraphic = false;
1609
1610// // decode arguments
1611// if(argc < 2)
1612// {
1613// printf("no arguements given, using standard arguments\n");
1614// }
1615
1616// // set conditions for functions arguments
1617// for (int i=1;i<argc;i++)
1618// {
1619// test = argv[i];
1620
1621// if (test.Contains("--config_file") || test.Contains("-c"))
1622// {
1623// cout << "gRC-File: \"" << argv[i + 1] << "\"" << endl;
1624// gRCFileName = argv[i + 1];
1625// gRCFileNameCmdSet = true;
1626// continue;
1627// }
1628
1629// if (test.Contains("--verbosity") || test.Contains("-v"))
1630// {
1631// cout << "Verbosity Level: \"" << argv[i + 1] << "\"" << endl;
1632// verbLevel = atoi(argv[i + 1]);
1633// continue;
1634// }
1635
1636// if (test.Contains("--save") || test.Contains("-s"))
1637// {
1638// cout << "will save results" << endl;
1639// save = true;
1640// continue;
1641// }
1642
1643// if (test.Contains("--graphics") || test.Contains("-g"))
1644// {
1645// cout << "will produce graphics" << endl;
1646// produceGraphic = true;
1647// continue;
1648// }
1649// }
1650
1651// // reading gRC-File:
1652// configfile gRCfile( gRCFileName, processType );
1653
1654// if (save)
1655// {
1656// gRCfile.mSave = save;
1657// }
1658
1659// if (verbLevelCmdSet)
1660// {
1661// gRCfile.mVerbLevel = verbLevel;
1662// }
1663
1664// if (produceGraphic)
1665// {
1666// gRCfile.mProduceGraphic = produceGraphic;
1667// }
1668
1669// FPulseOverlay(
1670// gRCfile.mInputPath,
1671// gRCfile.mDataFileName,
1672// gRCfile.mDrsFileName,
1673// gRCfile.mOutputPath,
1674// gRCfile.mOutputFile,
1675// gRCfile.mFirstEvent,
1676// gRCfile.mNumEvents,
1677// gRCfile.mFirstPixel,
1678// gRCfile.mNumPixel,
1679// gRCfile.mPixelSetSize,
1680// gRCfile.mMaxOrder,
1681// gRCfile.mVerbLevel,
1682// gRCfile.mHistoOptions,
1683// gRCfile.mAmplWindowWidth,
1684// gRCfile.mGainMean,
1685// gRCfile.mBSLMean,
1686// gRCfile.mAvg1,
1687// gRCfile.mAvg2,
1688// gRCfile.mOverlayWindowLeft,
1689// gRCfile.mOverlayWindowRight,
1690// gRCfile.mProduceGraphic,
1691// gRCfile.mSpikeDebug,
1692// gRCfile.mDbgPixel,
1693// gRCfile.mPrintStats,
1694// gRCfile.mSave,
1695// gRCfile.mTestMode,
1696// gRCfile.mRefreshRate
1697// );
1698// return 0;
1699
1700//}
Note: See TracBrowser for help on using the repository browser.