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>
|
---|
38 | using 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 |
|
---|
79 | bool gBreakout=false;
|
---|
80 |
|
---|
81 | vector<int16_t> gAllPixelDataVector;
|
---|
82 | vector<int16_t> gStartCellVector;
|
---|
83 | unsigned int gCurrentEventID;
|
---|
84 | size_t gPXLxROI;
|
---|
85 | UInt_t gRegionOfInterest;
|
---|
86 | UInt_t gNumberOfPixels;
|
---|
87 | TString ghistotitle;
|
---|
88 |
|
---|
89 | size_t gTriggerOffsetROI;
|
---|
90 | size_t gRC;
|
---|
91 | size_t gDrs_n;
|
---|
92 | vector<float> gDrsBaseMean;
|
---|
93 | vector<float> gDrsGainMean;
|
---|
94 | vector<float> gDrsTriggeroffsetMean;
|
---|
95 |
|
---|
96 | vector<float> gAmeas(FAD_MAX_SAMPLES); // copy of the data (measured amplitude
|
---|
97 | vector<float> gVcorr(FAD_MAX_SAMPLES); // corrected Values
|
---|
98 | vector<float> gVslide(FAD_MAX_SAMPLES); // sliding average result
|
---|
99 | vector<float> gVcfd(FAD_MAX_SAMPLES); // CDF result
|
---|
100 | vector<float> gVcfd2(FAD_MAX_SAMPLES); // CDF result + 2nd sliding average
|
---|
101 |
|
---|
102 | int gNEvents=0;
|
---|
103 | float gGainMean = 9;
|
---|
104 | float 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
|
---|
125 | const int Number_Of_Debug_Histo_Types = 7;
|
---|
126 |
|
---|
127 | const 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 |
|
---|
175 | void BookDebugHistos(int );
|
---|
176 | void BookTestHistos( int );
|
---|
177 |
|
---|
178 | //void DeletePixelHistos(int );
|
---|
179 | //void SaveHistograms( const char*, const char*, TObjArray*, int );
|
---|
180 |
|
---|
181 | void FillHistograms(Pixel*, vector<Region>*, int, int, int , int );
|
---|
182 | void DrawTestHistograms( int);
|
---|
183 | bool ProduceDebugHistos( vector<Region> *pZXings);
|
---|
184 | bool UseThisPulse( int, int, int, float, int, int);
|
---|
185 | void UpdateCanvases( int, int, bool);
|
---|
186 | void DeletePixelCanvases( int, int );
|
---|
187 |
|
---|
188 | int HandleFitsFile(
|
---|
189 | fits * datafile,
|
---|
190 | TString datafilename,
|
---|
191 | TString drsfilename,
|
---|
192 | int nevents,
|
---|
193 | int npixel,
|
---|
194 | int verbosityLevel
|
---|
195 | );
|
---|
196 |
|
---|
197 | TString gDataDirectory;
|
---|
198 | TString gHomeDirectory;
|
---|
199 | TString ghostname;
|
---|
200 |
|
---|
201 | //----------------------------------------------------------------------------
|
---|
202 | //----------------------------------------------------------------------------
|
---|
203 | // MAIN - Funtion
|
---|
204 | //----------------------------------------------------------------------------
|
---|
205 | //----------------------------------------------------------------------------
|
---|
206 | int FPulseOverlay_multifile(
|
---|
207 | TString inputPath = "raw/2012/03/09/",
|
---|
208 | TString dataFileIdBase = "20120309",
|
---|
209 | TString dataFileSuffix = ".fits.gz",
|
---|
210 | int firstRunId = 18,
|
---|
211 | int nRuns = 50,
|
---|
212 | TString drsfilename = "20120309_012.drs.fits.gz",
|
---|
213 | TString OutputPath = "analysis/FPulseTemplate/20120309_018/Overlay/",
|
---|
214 | TString OutRootFileName = "20120309_018.root",
|
---|
215 | int firstevent = 1, // Hast to be between 1 and infinity NOT 0!!!!
|
---|
216 | int nevents = 100,
|
---|
217 | int firstpixel = 0,
|
---|
218 | int npixel = 2,
|
---|
219 | int pixelSetSize = 150,
|
---|
220 | int maxPulseOrder = 1,
|
---|
221 | int verbosityLevel = 6, // different verbosity levels can be implemented here
|
---|
222 | TString histoOptions = "SRM",
|
---|
223 | int AmplWindowWidth = 14, //Width of Window for selection of pulses to histograms
|
---|
224 | float GainMean = 9,
|
---|
225 | float BSLMean = -1, //4 Histogramms will be drawn, decide how far pulsehights differ from eachother
|
---|
226 | int avg1 = 8,
|
---|
227 | int avg2 = 8,
|
---|
228 | int OverlayWindowLeft = 70,
|
---|
229 | int OverlayWindowRight = 230,
|
---|
230 | bool ProduceGraphic = false,
|
---|
231 | bool spikeDebug = false,
|
---|
232 | bool debugPixel = false,
|
---|
233 | bool stats = false,
|
---|
234 | bool saveResults = false,
|
---|
235 | bool testmode = false,
|
---|
236 | int refresh_rate = 500 //refresh rate for canvases
|
---|
237 | )
|
---|
238 | {
|
---|
239 | //-----------------------------------------------------------------------------
|
---|
240 | // prepare datafiles
|
---|
241 | //-----------------------------------------------------------------------------
|
---|
242 |
|
---|
243 | // declare the data file
|
---|
244 | fits * datafile = NULL;
|
---|
245 |
|
---|
246 | // Opens the raw data file and 'binds' the variables given as
|
---|
247 | // Parameters to the data file. So they are filled with
|
---|
248 | // raw data as soon as datafile->GetRow(int) is called.
|
---|
249 |
|
---|
250 | //vector of fits files to read
|
---|
251 | vector<TString> datafiles;
|
---|
252 |
|
---|
253 | inputPath = SetHostsPaths(false, inputPath );
|
---|
254 | drsfilename.Prepend(inputPath);
|
---|
255 |
|
---|
256 | //fill vector of fits files to read
|
---|
257 | cout << "generating file list:" << endl;
|
---|
258 | for (int RunId = firstRunId; RunId < firstRunId + nRuns; RunId++)
|
---|
259 | {
|
---|
260 | TString run_id;
|
---|
261 |
|
---|
262 | run_id = "";
|
---|
263 | run_id += RunId;
|
---|
264 | while (run_id.Length() <3)
|
---|
265 | run_id.Prepend("0");
|
---|
266 |
|
---|
267 | //filename/path construction
|
---|
268 | TString temp_filename = inputPath;
|
---|
269 | temp_filename.Append(dataFileIdBase);
|
---|
270 | temp_filename.Append("_");
|
---|
271 | temp_filename.Append(run_id);
|
---|
272 | temp_filename.Append(dataFileSuffix);
|
---|
273 |
|
---|
274 | cout << "\t checking" << temp_filename;
|
---|
275 |
|
---|
276 | //check if file is readable
|
---|
277 | ifstream fits_file(temp_filename);
|
---|
278 | if (fits_file.good())
|
---|
279 | {
|
---|
280 | //fill vector
|
---|
281 | cout << "\t...added" << endl;
|
---|
282 | datafiles.push_back(temp_filename);
|
---|
283 | }
|
---|
284 | else {
|
---|
285 | cout << "\t...failed" << endl;
|
---|
286 | }
|
---|
287 |
|
---|
288 | }
|
---|
289 |
|
---|
290 | //----------------------------------------------------------------------------
|
---|
291 | // Save-Root-File Settings
|
---|
292 | //----------------------------------------------------------------------------
|
---|
293 |
|
---|
294 | OutputPath = SetHostsPaths(true, OutputPath );
|
---|
295 | OutRootFileName.Prepend(OutputPath);
|
---|
296 | // drsfilename = SetHostsPaths(false, drsfilename );
|
---|
297 | // OutRootFileName = SetHostsPaths(true, OutRootFileName );
|
---|
298 | cout << endl;
|
---|
299 | cout << "drs filename:\t" << drsfilename << endl;
|
---|
300 | // cout << "data filename:\t" << datafilename << endl;
|
---|
301 | cout << "out filename:\t" << OutRootFileName << endl;
|
---|
302 |
|
---|
303 |
|
---|
304 | if (saveResults)
|
---|
305 | {
|
---|
306 | CreateRootFile( OutRootFileName, true, verbosityLevel );
|
---|
307 | }
|
---|
308 |
|
---|
309 |
|
---|
310 |
|
---|
311 |
|
---|
312 |
|
---|
313 | //----------------------------------------------------------------------------
|
---|
314 | // root global Settings
|
---|
315 | //----------------------------------------------------------------------------
|
---|
316 |
|
---|
317 | gGainMean = GainMean;
|
---|
318 | gBSLMean = BSLMean;
|
---|
319 | gPixelOverlayXaxisLeft = OverlayWindowLeft;
|
---|
320 | gPixelOverlayXaxisRight = OverlayWindowRight;
|
---|
321 |
|
---|
322 | gStyle->SetPalette(1,0);
|
---|
323 | gROOT->SetStyle("Plain");
|
---|
324 | // gPad->SetGrid();
|
---|
325 |
|
---|
326 | //----------------------------------------------------------------------------
|
---|
327 | // root Canvas Settings
|
---|
328 | //----------------------------------------------------------------------------
|
---|
329 | //Canvas Pad numbering
|
---|
330 | int pulsesCanvasFrameNrs[4] = {
|
---|
331 | 1, // Top left
|
---|
332 | 2, // Top right
|
---|
333 | 3, // bottom left
|
---|
334 | 4 // bootom right
|
---|
335 | };
|
---|
336 |
|
---|
337 | //Canvas Pad numbering
|
---|
338 | int distributionCanvasFrameNrs[4] = {
|
---|
339 | 1, // Top left
|
---|
340 | 2, // Top right
|
---|
341 | 3, // bottom left
|
---|
342 | 4 // bootom right
|
---|
343 | };
|
---|
344 |
|
---|
345 | if (ProduceGraphic)
|
---|
346 | {
|
---|
347 |
|
---|
348 | //Canvases
|
---|
349 | cgpPixelPulses = new TCanvas*[maxPulseOrder];
|
---|
350 | cgpDistributions = new TCanvas*[maxPulseOrder];
|
---|
351 |
|
---|
352 | //TCanvas* gpcDevelopment = NULL;
|
---|
353 | TString cName = "";
|
---|
354 | TString cTitle = "";
|
---|
355 |
|
---|
356 | //naming of pulse canvases
|
---|
357 | for (
|
---|
358 | int pulse_order = maxPulseOrder - 1;
|
---|
359 | pulse_order >= 0 ;
|
---|
360 | pulse_order--
|
---|
361 | )
|
---|
362 | {
|
---|
363 | cName ="cgpDistributions";
|
---|
364 | cName += pulse_order;
|
---|
365 | cTitle ="Distributions of Pulses with Order of: ";
|
---|
366 | cTitle += pulse_order;
|
---|
367 | cgpDistributions[pulse_order] = new TCanvas(cName,cTitle, 720,pulse_order*20,720,720);
|
---|
368 | cgpDistributions[pulse_order]->Divide(2, 2);
|
---|
369 | cName ="cgpPixelPulses";
|
---|
370 | cName += pulse_order;
|
---|
371 | cTitle ="Overlays of Pulses with Order of: ";
|
---|
372 | cTitle += pulse_order;
|
---|
373 | cgpPixelPulses[pulse_order] = new TCanvas(cName,cTitle, 0,pulse_order*20,720,720);
|
---|
374 | cgpPixelPulses[pulse_order]->Divide(2, 2);
|
---|
375 | }
|
---|
376 |
|
---|
377 |
|
---|
378 | // Create (pointer to) Canvases, which are used in every run,
|
---|
379 | // also in 'non-debug' runs
|
---|
380 | // Canvases only need if spike Debug, but I want to deklare
|
---|
381 | // the pointers anyway ...
|
---|
382 | if (spikeDebug)
|
---|
383 | {
|
---|
384 | cFiltered = new TCanvas("cFiltered","filtered DRS Waveforms", 1080,420,360,360);
|
---|
385 | cFiltered->Divide(1, 3);
|
---|
386 | }
|
---|
387 |
|
---|
388 | if (testmode)
|
---|
389 | {
|
---|
390 | //additional Test histograms
|
---|
391 | cgpTestHistos = new TCanvas( "cgpTestHistos", "Test Histograms", 360, 420, 360, 360 );
|
---|
392 | cgpTestHistos->Divide(2,0);
|
---|
393 | }
|
---|
394 | }
|
---|
395 |
|
---|
396 | //-----------------------------------------------------------------------------
|
---|
397 | // Filter-Settings
|
---|
398 | //-----------------------------------------------------------------------------
|
---|
399 | // CFD filter settings
|
---|
400 | int k_cfd = 10;
|
---|
401 | vector<double> a_cfd(k_cfd, 0);
|
---|
402 | double b_cfd = 1.;
|
---|
403 | a_cfd[0]=-0.75;
|
---|
404 | a_cfd[k_cfd-1]=1.;
|
---|
405 |
|
---|
406 | //-----------------------------------------------------------------------------
|
---|
407 | // Book the histograms
|
---|
408 | //-----------------------------------------------------------------------------
|
---|
409 |
|
---|
410 |
|
---|
411 |
|
---|
412 | if (testmode)
|
---|
413 | {
|
---|
414 | BookTestHistos( verbosityLevel );
|
---|
415 | }
|
---|
416 | //----------------------------------------------------------------------------
|
---|
417 | // Initialize Pixel
|
---|
418 | //----------------------------------------------------------------------------
|
---|
419 | Pixel** pixel = new Pixel*[NPIX];
|
---|
420 |
|
---|
421 | for (int i = 0 ; i < NPIX; i++)
|
---|
422 | {
|
---|
423 | pixel[i] = NULL;
|
---|
424 | }
|
---|
425 |
|
---|
426 |
|
---|
427 | //-----------------------------------------------------------------------------
|
---|
428 | // Main Cycle
|
---|
429 | //-----------------------------------------------------------------------------
|
---|
430 |
|
---|
431 | if ( pixelSetSize == -1 )
|
---|
432 | {
|
---|
433 | pixelSetSize = firstpixel +npixel;
|
---|
434 | }
|
---|
435 | int lastPixelOfSet = 0;
|
---|
436 | //-------------------------------------
|
---|
437 | // Loop over Pixel Sets
|
---|
438 | //-------------------------------------
|
---|
439 | for ( int firstPixelOfSet = firstpixel;
|
---|
440 | firstPixelOfSet < firstpixel + npixel;
|
---|
441 | firstPixelOfSet += pixelSetSize )
|
---|
442 | {
|
---|
443 | lastPixelOfSet = firstPixelOfSet + pixelSetSize-1;
|
---|
444 | if (lastPixelOfSet > firstpixel + npixel)
|
---|
445 | {
|
---|
446 | lastPixelOfSet = firstpixel + npixel;
|
---|
447 | }
|
---|
448 | if (lastPixelOfSet > 1439)
|
---|
449 | {
|
---|
450 | lastPixelOfSet = 1439;
|
---|
451 | }
|
---|
452 | if (verbosityLevel == 0)
|
---|
453 | {
|
---|
454 | cout << "------------------------------------------------" << endl
|
---|
455 | << "...processing Set from Pixel "
|
---|
456 | << firstPixelOfSet
|
---|
457 | << " to Pixel "
|
---|
458 | << lastPixelOfSet << endl;
|
---|
459 | }
|
---|
460 |
|
---|
461 | //-------------------------------------
|
---|
462 | // Loop over Fits Files
|
---|
463 | //-------------------------------------
|
---|
464 |
|
---|
465 | for( unsigned int fileId = 0; fileId < datafiles.size(); fileId++ )
|
---|
466 | {
|
---|
467 | datafile = NULL;
|
---|
468 | // int return_val = 0;
|
---|
469 | // return_val = HandleFitsFile(
|
---|
470 | // datafile,
|
---|
471 | // datafiles.at(fileId),
|
---|
472 | // drsfilename,
|
---|
473 | // nevents,
|
---|
474 | // npixel,
|
---|
475 | // verbosityLevel
|
---|
476 | // );
|
---|
477 | // if (return_val)
|
---|
478 | // {
|
---|
479 | // cerr << "ERROR" << endl;
|
---|
480 | // return return_val;
|
---|
481 | // }
|
---|
482 | //==================================================
|
---|
483 |
|
---|
484 | // Opens the raw data file and 'binds' the variables given as
|
---|
485 | // Parameters to the data file. So they are filled with
|
---|
486 | // raw data as soon as datafile->GetRow(int) is called.
|
---|
487 | cout << "\nopening " << datafiles.at(fileId) << endl;
|
---|
488 |
|
---|
489 | gNEvents = openDataFits(
|
---|
490 | datafiles.at(fileId),
|
---|
491 | &datafile,
|
---|
492 | gAllPixelDataVector,
|
---|
493 | gStartCellVector,
|
---|
494 | gCurrentEventID,
|
---|
495 | gRegionOfInterest,
|
---|
496 | gNumberOfPixels,
|
---|
497 | gPXLxROI,
|
---|
498 | verbosityLevel
|
---|
499 | );
|
---|
500 |
|
---|
501 | if (gNEvents == 0)
|
---|
502 | {
|
---|
503 | cout << "return code of OpenDataFile:" << datafiles.at(fileId)<< endl;
|
---|
504 | cout << "is zero -> aborting." << endl;
|
---|
505 | return 1;
|
---|
506 | }
|
---|
507 |
|
---|
508 | if (verbosityLevel > 0)
|
---|
509 | {
|
---|
510 | cout << endl <<"number of events in file: "<< gNEvents << "\t";
|
---|
511 | }
|
---|
512 |
|
---|
513 | if ( nevents == -1 || nevents > gNEvents ) nevents = gNEvents; // -1 means all!
|
---|
514 |
|
---|
515 | if (verbosityLevel > 0)
|
---|
516 | {
|
---|
517 | cout <<"of, which "<< nevents << " will be processed"<< endl;
|
---|
518 | cout <<"Total # of Pixel: "<< gNumberOfPixels << "\t";
|
---|
519 | }
|
---|
520 |
|
---|
521 | if ( npixel == -1 || npixel > (int)gNumberOfPixels ) npixel = (int)gNumberOfPixels; // -1 means all!
|
---|
522 |
|
---|
523 | if (verbosityLevel > 0)
|
---|
524 | {
|
---|
525 | cout <<"of, which "<< npixel << " will be processed"<< endl;
|
---|
526 | }
|
---|
527 |
|
---|
528 | //Get the DRS calibration
|
---|
529 | gRC = openCalibFits(
|
---|
530 | drsfilename,
|
---|
531 | gDrsBaseMean,
|
---|
532 | gDrsGainMean,
|
---|
533 | gDrsTriggeroffsetMean,
|
---|
534 | gTriggerOffsetROI
|
---|
535 | );
|
---|
536 |
|
---|
537 | if (gRC == 0)
|
---|
538 | {
|
---|
539 | cout << "return code of openCalibFits:" << drsfilename << endl;
|
---|
540 | cout << "is zero -> aborting." << endl;
|
---|
541 | return 1;
|
---|
542 | }
|
---|
543 |
|
---|
544 | //==================================================================
|
---|
545 |
|
---|
546 | //--------------------------------------------------------------------
|
---|
547 | // Loop over every Event of Pixel Set
|
---|
548 | //--------------------------------------------------------------------
|
---|
549 | for ( int ev = firstevent ; ev < firstevent + nevents; ev++)
|
---|
550 | {
|
---|
551 | // Get an Event --> consists of 1440 Pixel ...erm....data
|
---|
552 | datafile->GetRow( ev - 1 );
|
---|
553 |
|
---|
554 | if (verbosityLevel == 1)
|
---|
555 | {
|
---|
556 | cout << "-------------------------------------" << endl
|
---|
557 | << "...processing Set from Pixel "
|
---|
558 | << firstPixelOfSet
|
---|
559 | << " to Pixel "
|
---|
560 | << lastPixelOfSet
|
---|
561 | << "... Event: " << gCurrentEventID
|
---|
562 | << "/" << nevents << endl;
|
---|
563 | }
|
---|
564 |
|
---|
565 | cout << "\t\t success!" << endl;
|
---|
566 | //--------------------------------------------------------------------
|
---|
567 | // Loops over every Pixel of a Set of Pixels
|
---|
568 | //--------------------------------------------------------------------
|
---|
569 | for ( int pixelID = firstPixelOfSet;
|
---|
570 | pixelID < lastPixelOfSet + 1
|
---|
571 | && pixelID < firstpixel + npixel;
|
---|
572 | pixelID++ )
|
---|
573 | {
|
---|
574 | if (verbosityLevel > 1)
|
---|
575 | {
|
---|
576 | cout << "-------------------------------------" << endl
|
---|
577 | << "...processing Set from Pixel "
|
---|
578 | << firstPixelOfSet
|
---|
579 | << " to Pixel "
|
---|
580 | << lastPixelOfSet
|
---|
581 | << "... Event: " << gCurrentEventID
|
---|
582 | << "/" << nevents << endl
|
---|
583 | << " Pixel: " << pixelID
|
---|
584 | << "/" << firstpixel + npixel -1 << endl;
|
---|
585 | }
|
---|
586 |
|
---|
587 | //-------------------------------------
|
---|
588 | // Create individual Pixel
|
---|
589 | //-------------------------------------
|
---|
590 | if (ev == firstevent)
|
---|
591 | {
|
---|
592 | pixel[pixelID] = new Pixel(
|
---|
593 | pixelID,
|
---|
594 | maxPulseOrder,
|
---|
595 | verbosityLevel,
|
---|
596 | stats,
|
---|
597 | histoOptions,
|
---|
598 | gPixelOverlayXaxisLeft,
|
---|
599 | gPixelOverlayXaxisRight,
|
---|
600 | gBSLMean,
|
---|
601 | gGainMean
|
---|
602 | );
|
---|
603 | }
|
---|
604 |
|
---|
605 | //-------------------------------------
|
---|
606 | // Apply Calibration
|
---|
607 | //-------------------------------------
|
---|
608 | if (verbosityLevel > 2) cout << "...applying DrsCalibration";
|
---|
609 | applyDrsCalibration(
|
---|
610 | gAmeas,
|
---|
611 | pixelID,
|
---|
612 | 12,
|
---|
613 | 12,
|
---|
614 | gDrsBaseMean,
|
---|
615 | gDrsGainMean,
|
---|
616 | gDrsTriggeroffsetMean,
|
---|
617 | gRegionOfInterest,
|
---|
618 | gAllPixelDataVector,
|
---|
619 | gStartCellVector
|
---|
620 | );
|
---|
621 | if (verbosityLevel > 2) cout << "...done " << endl;
|
---|
622 |
|
---|
623 | //-------------------------------------
|
---|
624 | // Apply Filters
|
---|
625 | //-------------------------------------
|
---|
626 | // finds spikes in the raw data, and interpolates the value
|
---|
627 | // spikes are: 1 or 2 slice wide, positive non physical artifacts
|
---|
628 | if (verbosityLevel > 2) cout << "...removeing Spikes";
|
---|
629 | removeSpikes (gAmeas, gVcorr);
|
---|
630 | if (verbosityLevel > 2) cout << "...done " << endl;
|
---|
631 |
|
---|
632 | // filter gVcorr with sliding average using FIR filter function
|
---|
633 | if (verbosityLevel > 2) cout << "...applying sliding average filter";
|
---|
634 | sliding_avg(gVcorr, gVslide, avg1);
|
---|
635 | if (verbosityLevel > 2) cout << "...done " << endl;
|
---|
636 |
|
---|
637 | // filter gVslide with CFD using FIR filter function
|
---|
638 | if (verbosityLevel > 2) cout << "...apllying factfir filter";
|
---|
639 | factfir(b_cfd , a_cfd, k_cfd, gVslide, gVcfd);
|
---|
640 | if (verbosityLevel > 2) cout << "...done " << endl;
|
---|
641 |
|
---|
642 | // filter gVcfd with sliding average using FIR filter function
|
---|
643 | if (verbosityLevel > 2) cout << "...applying 2nd sliding average filter";
|
---|
644 | sliding_avg(gVcfd, gVcfd2, avg2);
|
---|
645 | if (verbosityLevel > 2) cout << "...done " << endl;
|
---|
646 |
|
---|
647 | //-------------------------------------
|
---|
648 | // SeagRCh vor Zero crossings
|
---|
649 | //-------------------------------------
|
---|
650 | if (verbosityLevel > 2) cout << endl << "...seagRChing zero crossings" ;
|
---|
651 | // peaks in gAmeas[] are found by seagRChing for zero crossings
|
---|
652 | // in gVcfd2
|
---|
653 | // first Argument 1 means ... *rising* edge
|
---|
654 | // second Argument 1 means ... seagRCh with stepsize 1 ... 10 is okay as well
|
---|
655 | vector<Region>* pZXings = zerosearch( gVcfd2 , 1 , 8);
|
---|
656 | // pZXings means "zero cross ings"
|
---|
657 | EnlargeRegion(*pZXings, 10, 10);
|
---|
658 | findAbsMaxInRegions(*pZXings, gVslide);
|
---|
659 | removeMaximaBelow( *pZXings, 3.0);
|
---|
660 | removeRegionWithMaxOnEdge( *pZXings, 2);
|
---|
661 | removeRegionOnFallingEdge( *pZXings, 100);
|
---|
662 | findTimeOfHalfMaxLeft(*pZXings, gVslide, gBSLMean, 5, 10, verbosityLevel );
|
---|
663 | removeRegionWithToFlatSlope(*pZXings, 0.5);
|
---|
664 | if (verbosityLevel > 2) cout << "...done" << endl;
|
---|
665 |
|
---|
666 | //-----------------------------------------------------------------------------
|
---|
667 | // Fill Overlay Histos
|
---|
668 | //-----------------------------------------------------------------------------
|
---|
669 | if (verbosityLevel > 2)
|
---|
670 | {
|
---|
671 | cout << endl << "Filling Histograms of Pixel# [Set] " << pixelID
|
---|
672 | << " Pixel# [Got] " << pixel[pixelID]->mChid;
|
---|
673 | }
|
---|
674 | FillHistograms(
|
---|
675 | pixel[pixelID],
|
---|
676 | pZXings,
|
---|
677 | AmplWindowWidth,
|
---|
678 | ev,
|
---|
679 | // histoOptions,
|
---|
680 | maxPulseOrder,
|
---|
681 | verbosityLevel
|
---|
682 | );
|
---|
683 | //-----------------------------------------------------------------------------
|
---|
684 | // Spike Debug
|
---|
685 | //-----------------------------------------------------------------------------
|
---|
686 | if ( spikeDebug )
|
---|
687 | {
|
---|
688 | BookDebugHistos(verbosityLevel );
|
---|
689 | gBreakout = ProduceDebugHistos( pZXings );
|
---|
690 | }// end of if(spikeDebug)
|
---|
691 |
|
---|
692 | delete pZXings;
|
---|
693 | if (gBreakout) break;
|
---|
694 | //-------------------------------------
|
---|
695 | // Draw 1. Set of Pixel Histograms
|
---|
696 | //-------------------------------------
|
---|
697 | if ((ev % refresh_rate) == 0)
|
---|
698 | {
|
---|
699 | if (ProduceGraphic)
|
---|
700 | {
|
---|
701 | if (debugPixel)
|
---|
702 | {
|
---|
703 | // for ( int order = 0;
|
---|
704 | // order < maxPulseOrder;
|
---|
705 | // order++
|
---|
706 | // )
|
---|
707 | // {
|
---|
708 | pixel[firstPixelOfSet]->DrawOverlayHistograms(
|
---|
709 | cgpPixelPulses,
|
---|
710 | pulsesCanvasFrameNrs
|
---|
711 | );
|
---|
712 |
|
---|
713 | pixel[firstPixelOfSet]->DrawDistributionHistograms(
|
---|
714 | cgpDistributions,
|
---|
715 | distributionCanvasFrameNrs
|
---|
716 | );
|
---|
717 | // }
|
---|
718 | if (testmode)
|
---|
719 | {
|
---|
720 | DrawTestHistograms(
|
---|
721 | verbosityLevel
|
---|
722 | );
|
---|
723 | }
|
---|
724 |
|
---|
725 | UpdateCanvases(
|
---|
726 | verbosityLevel,
|
---|
727 | maxPulseOrder,
|
---|
728 | testmode
|
---|
729 | );
|
---|
730 | }
|
---|
731 | }
|
---|
732 | }
|
---|
733 |
|
---|
734 | if (gBreakout) break;
|
---|
735 |
|
---|
736 | if (verbosityLevel > 1)
|
---|
737 | {
|
---|
738 | cout << endl << "...End of Pixel"
|
---|
739 | << endl << "-------------------------------------"<< endl;
|
---|
740 | }
|
---|
741 | }//End of Loop over Set
|
---|
742 | //-------------------------------------
|
---|
743 | // end of Loops over Set
|
---|
744 | //-------------------------------------
|
---|
745 |
|
---|
746 | }//End of Loop over Events
|
---|
747 | //-------------------------------------
|
---|
748 | // end of Loops over Events
|
---|
749 | //-------------------------------------
|
---|
750 |
|
---|
751 | }//End of Loop over Files
|
---|
752 | //-------------------------------------
|
---|
753 | // end of Loops over Files
|
---|
754 | //-------------------------------------
|
---|
755 |
|
---|
756 |
|
---|
757 | //-------------------------------------
|
---|
758 | // Draw Pixel Histogramms of Overlay Spectra
|
---|
759 | //-------------------------------------
|
---|
760 |
|
---|
761 | for ( int pixelID = firstPixelOfSet;
|
---|
762 | pixelID < firstPixelOfSet + pixelSetSize
|
---|
763 | && pixelID < firstpixel + npixel;
|
---|
764 | pixelID++ )
|
---|
765 | {
|
---|
766 | //here is what happends at the end of each loop over all Events
|
---|
767 |
|
---|
768 | if (ProduceGraphic)
|
---|
769 | {
|
---|
770 | pixel[pixelID]->DrawOverlayHistograms(
|
---|
771 | cgpPixelPulses,
|
---|
772 | pulsesCanvasFrameNrs
|
---|
773 | );
|
---|
774 |
|
---|
775 | pixel[pixelID]->DrawDistributionHistograms(
|
---|
776 | cgpDistributions,
|
---|
777 | distributionCanvasFrameNrs
|
---|
778 | );
|
---|
779 |
|
---|
780 | UpdateCanvases(
|
---|
781 | verbosityLevel,
|
---|
782 | maxPulseOrder,
|
---|
783 | testmode
|
---|
784 | );
|
---|
785 | }
|
---|
786 |
|
---|
787 | //Save Histograms of Pixels into Output rootfile
|
---|
788 | if (verbosityLevel > 2)
|
---|
789 | {
|
---|
790 | cout << endl << "Saving Pixel# [Set] " << pixelID
|
---|
791 | << " Pixel# [Got] " << pixel[pixelID]->mChid;
|
---|
792 | }
|
---|
793 | pixel[pixelID]->SavePixelHistograms( OutRootFileName, saveResults );
|
---|
794 |
|
---|
795 |
|
---|
796 | if (debugPixel)
|
---|
797 | {
|
---|
798 | //Process gui events asynchronously during input
|
---|
799 | cout << endl;
|
---|
800 | TTimer timer("gSystem->ProcessEvents();", 50, kFALSE);
|
---|
801 | timer.TurnOn();
|
---|
802 | TString input = Getline("Type 'q' to exit, <return> to go on: ");
|
---|
803 | timer.TurnOff();
|
---|
804 | if (input=="q\n") {
|
---|
805 | break;
|
---|
806 | }
|
---|
807 | }
|
---|
808 |
|
---|
809 | if (verbosityLevel > 2)
|
---|
810 | {
|
---|
811 | cout << endl << "Deleting Pixel# [Set] " << pixelID
|
---|
812 | << " Pixel# [Got] " << pixel[pixelID]->mChid;
|
---|
813 | }
|
---|
814 | delete pixel[pixelID];
|
---|
815 |
|
---|
816 | if (verbosityLevel > 2)
|
---|
817 | {
|
---|
818 | cout << endl << "...End of Pixel-Set"
|
---|
819 | << endl << "------------------------------------------------"
|
---|
820 | << endl;
|
---|
821 | }
|
---|
822 | }
|
---|
823 | }
|
---|
824 | // End of Loop over all Pixels
|
---|
825 |
|
---|
826 | //-------------------------------------
|
---|
827 | // Draw Histograms
|
---|
828 | //-------------------------------------
|
---|
829 | TString test = "root";
|
---|
830 | SaveHistograms( //save histograms of generell results into output root file
|
---|
831 | OutRootFileName,
|
---|
832 | test,
|
---|
833 | hRootList,
|
---|
834 | saveResults,
|
---|
835 | verbosityLevel
|
---|
836 | );
|
---|
837 |
|
---|
838 | if (ProduceGraphic)
|
---|
839 | {
|
---|
840 | UpdateCanvases(
|
---|
841 | verbosityLevel,
|
---|
842 | maxPulseOrder,
|
---|
843 | testmode
|
---|
844 | );
|
---|
845 |
|
---|
846 | //Process gui events asynchronously during input
|
---|
847 | cout << endl;
|
---|
848 | TTimer timer("gSystem->ProcessEvents();", 50, kFALSE);
|
---|
849 | timer.TurnOn();
|
---|
850 | Getline("Press <return> to go on");
|
---|
851 | timer.TurnOff();
|
---|
852 |
|
---|
853 | DeletePixelCanvases(
|
---|
854 | maxPulseOrder,
|
---|
855 | verbosityLevel
|
---|
856 | );
|
---|
857 |
|
---|
858 | if (testmode)
|
---|
859 | delete cgpTestHistos;
|
---|
860 |
|
---|
861 | if (spikeDebug)
|
---|
862 | delete cFiltered;
|
---|
863 | }
|
---|
864 |
|
---|
865 | delete datafile;
|
---|
866 | delete[] pixel;
|
---|
867 |
|
---|
868 | return( 0 );
|
---|
869 | }
|
---|
870 | //----------------------------------------------------------------------------
|
---|
871 | // end of main function
|
---|
872 | //-----------------------------------------------------------------------------
|
---|
873 |
|
---|
874 |
|
---|
875 |
|
---|
876 |
|
---|
877 | //-----------------------------------------------------------------------------
|
---|
878 | // Funktions
|
---|
879 | //-----------------------------------------------------------------------------
|
---|
880 |
|
---|
881 | /*
|
---|
882 | ich erzeuge sowas wie 36 pixel mit ca 20 Histogrammen pro pixel
|
---|
883 | wie viel speicher braucht das?
|
---|
884 | Ich brauche eine möglichkeit jedes dieser histogramme zu identifizieren
|
---|
885 | am besten ein array oder eine liste oder einen abstracten datentyp mit den histogrammen als attribute.
|
---|
886 | ne klasse wäre super
|
---|
887 |
|
---|
888 | */
|
---|
889 |
|
---|
890 | void BookTestHistos( int verbosityLevel )
|
---|
891 | {
|
---|
892 | if (verbosityLevel > 2) cout << endl << "...book pixel histograms" << endl;
|
---|
893 |
|
---|
894 | hTesthisto = new TH1F (
|
---|
895 | "hTesthisto",
|
---|
896 | "Deviation of rising edge and maximum",
|
---|
897 | 600,
|
---|
898 | -10.1,
|
---|
899 | 10.1
|
---|
900 | );
|
---|
901 | hTesthisto->GetXaxis()->SetTitle( "Timeslices [a.u.]" );
|
---|
902 | hTesthisto->GetYaxis()->SetTitle( "counts" );
|
---|
903 |
|
---|
904 | hTesthisto2 = new TH2F (
|
---|
905 | "hTesthisto2",
|
---|
906 | "Deviation of rising edge and maximum by event #",
|
---|
907 | gNEvents,
|
---|
908 | 250,
|
---|
909 | 800,
|
---|
910 | 600,
|
---|
911 | -10.1,
|
---|
912 | 10.1
|
---|
913 | );
|
---|
914 | // hTesthisto2->GetXaxis()->SetTitle( "Timeslices [a.u.]" );
|
---|
915 | // hTesthisto2->GetYaxis()->SetTitle( "counts" );
|
---|
916 | // hTesthisto2->SetMarkerStyle( 2 );
|
---|
917 |
|
---|
918 | if (verbosityLevel > 2) cout << "...done" << endl;
|
---|
919 | }
|
---|
920 | //end of BookTestHistos
|
---|
921 | //----------------------------------------------------------------------------
|
---|
922 |
|
---|
923 |
|
---|
924 | void
|
---|
925 | BookDebugHistos( int verbosityLevel )
|
---|
926 | {
|
---|
927 | if (verbosityLevel > 2) cout << endl << "...book histograms" << endl;
|
---|
928 | hRootList = new TList();
|
---|
929 | debugHistos = new TH1F[ Number_Of_Debug_Histo_Types ];
|
---|
930 | for ( int type = 0; type < Number_Of_Debug_Histo_Types; type++){
|
---|
931 | debugHistos[ type ].SetBins(1024, 0, 1024);
|
---|
932 | debugHistos[ type ].SetLineColor(1);
|
---|
933 | debugHistos[ type ].SetLineWidth(2);
|
---|
934 | debugHistos[ type ].SetStats(false);
|
---|
935 |
|
---|
936 | // set X axis paras
|
---|
937 | debugHistos[ type ].GetXaxis()->SetLabelSize(0.08);
|
---|
938 | debugHistos[ type ].GetXaxis()->SetTitleSize(0.08);
|
---|
939 | debugHistos[ type ].GetXaxis()->SetTitleOffset(1.0);
|
---|
940 | debugHistos[ type ].GetXaxis()->SetTitle(Form("Time slice [%.1f ns/slice]", 1./2.));
|
---|
941 |
|
---|
942 | // set Y axis paras
|
---|
943 | debugHistos[ type ].GetYaxis()->SetLabelSize(0.08);
|
---|
944 | debugHistos[ type ].GetYaxis()->SetTitleSize(0.08);
|
---|
945 | debugHistos[ type ].GetYaxis()->SetTitleOffset(0.3);
|
---|
946 | debugHistos[ type ].GetYaxis()->SetTitle("Amplitude [mV]");
|
---|
947 | // hRootList->Add( &debugHistos[ type ] );
|
---|
948 | }
|
---|
949 | if (verbosityLevel > 2) cout << "...done" << endl;
|
---|
950 | }
|
---|
951 | // end of BookDebugHistos
|
---|
952 | //----------------------------------------------------------------------------
|
---|
953 |
|
---|
954 |
|
---|
955 | void
|
---|
956 | FillHistograms(
|
---|
957 | Pixel* CurrentPixel,
|
---|
958 | vector<Region>* pZXings,
|
---|
959 | int AmplWindowWidth,
|
---|
960 | int eventNumber,
|
---|
961 | int maxPulseOrder,
|
---|
962 | int verbosityLevel
|
---|
963 | )
|
---|
964 | {
|
---|
965 | if (verbosityLevel > 2) cout << endl << "...filling pulse histograms" ;
|
---|
966 | if (verbosityLevel > 3) cout << endl << "...EventNR " << eventNumber ;
|
---|
967 | bool use_this_peak=false;
|
---|
968 | int order_of_pulse=0;
|
---|
969 | vector<Region>::iterator reg;
|
---|
970 | //Loop over all found zerocrossings in Region
|
---|
971 | for (reg = pZXings->begin() ; reg < pZXings->end() ; reg++)
|
---|
972 | {
|
---|
973 | //skip those who are at the Rim of the ROI
|
---|
974 | if (reg->maxPos < 12 || (unsigned int) reg->maxPos > gRegionOfInterest-12)
|
---|
975 | {
|
---|
976 | if (verbosityLevel > 2) cout << endl << "\t...out of range" << endl;
|
---|
977 | continue;
|
---|
978 | }
|
---|
979 |
|
---|
980 | // Define axis range of Histogram
|
---|
981 | int Left = reg->maxPos - gPixelOverlayXaxisLeft;
|
---|
982 | int Right = reg->maxPos + gPixelOverlayXaxisRight;
|
---|
983 | int EdgeLeft = reg->halfRisingEdgePos - gPixelOverlayXaxisLeft;
|
---|
984 | int EdgeRight = reg->halfRisingEdgePos + gPixelOverlayXaxisRight;
|
---|
985 |
|
---|
986 | if (Left < 0) Left = 0;
|
---|
987 | if (EdgeLeft < 0) EdgeLeft = 0;
|
---|
988 | if (Right > (int)gAmeas.size() ) Right = gAmeas.size();
|
---|
989 | if (EdgeRight > (int)gAmeas.size() ) EdgeRight = gAmeas.size();
|
---|
990 |
|
---|
991 |
|
---|
992 | if (verbosityLevel > 2) cout << endl << "\t...choosing Histogram" ;
|
---|
993 | //determine order of pulse and which histogram shall be filled
|
---|
994 | for ( int order = 0; order < maxPulseOrder; order++)
|
---|
995 | {
|
---|
996 | use_this_peak = UseThisPulse(
|
---|
997 | reg->maxPos,
|
---|
998 | order,
|
---|
999 | AmplWindowWidth,
|
---|
1000 | gGainMean,
|
---|
1001 | maxPulseOrder,
|
---|
1002 | verbosityLevel
|
---|
1003 | );
|
---|
1004 | if ( use_this_peak)
|
---|
1005 | {
|
---|
1006 | order_of_pulse = order;
|
---|
1007 | break;
|
---|
1008 | }
|
---|
1009 | }
|
---|
1010 | //Fill histograms
|
---|
1011 | if (use_this_peak)
|
---|
1012 | {
|
---|
1013 | //Histograms for Distributions
|
---|
1014 | if (CurrentPixel->mOptions.Contains("S") )
|
---|
1015 | {
|
---|
1016 | if (verbosityLevel > 2)
|
---|
1017 | cout << endl << "\t...filling Edge Histogram" ;
|
---|
1018 | CurrentPixel->hSlopeRisingEdge[order_of_pulse]->Fill( reg->slopeOfRisingEdge ) ;
|
---|
1019 | }
|
---|
1020 |
|
---|
1021 | if (CurrentPixel->mOptions.Contains("R") )
|
---|
1022 | {
|
---|
1023 | if (verbosityLevel > 2)
|
---|
1024 | cout << endl << "\t...filling RisingEdgeToMax Histogram" ;
|
---|
1025 | CurrentPixel->hRisingEdgeToMax[order_of_pulse]->Fill( reg->distanceEdgeToMax ) ;
|
---|
1026 | }
|
---|
1027 |
|
---|
1028 | if (CurrentPixel->mOptions.Contains("M") )
|
---|
1029 | {
|
---|
1030 | if (verbosityLevel > 2)
|
---|
1031 | cout << endl << "\t...filling PosOfMax Histogram" ;
|
---|
1032 | CurrentPixel->hPosOfMax[order_of_pulse]->Fill( reg->maxPos ) ;
|
---|
1033 | }
|
---|
1034 |
|
---|
1035 | //Histograms for Maximum Overlay
|
---|
1036 | for ( int pos = Left; pos < Right; pos++)
|
---|
1037 | {
|
---|
1038 | CurrentPixel->hMaxOverlay[order_of_pulse]->Fill( pos - (reg->maxPos), gAmeas[pos]) ;
|
---|
1039 | CurrentPixel->hMaxProfile[order_of_pulse]->Fill( pos - (reg->maxPos), gAmeas[pos]) ;
|
---|
1040 | }
|
---|
1041 | //Histograms for Edge Overlay
|
---|
1042 | for ( int pos = EdgeLeft; pos < EdgeRight; pos++)
|
---|
1043 | {
|
---|
1044 | CurrentPixel->hEdgeOverlay[order_of_pulse]->Fill( pos - (reg->halfRisingEdgePos), gAmeas[pos]) ;
|
---|
1045 | CurrentPixel->hEdgeProfile[order_of_pulse]->Fill( pos - (reg->halfRisingEdgePos), gAmeas[pos]) ;
|
---|
1046 | }
|
---|
1047 |
|
---|
1048 | if (verbosityLevel > 2) cout << "...done" << endl;
|
---|
1049 | }
|
---|
1050 |
|
---|
1051 | //gBreakout option
|
---|
1052 | if (gBreakout)
|
---|
1053 | {
|
---|
1054 | break;
|
---|
1055 | }
|
---|
1056 | }
|
---|
1057 | if (verbosityLevel > 2) cout << "...done" << endl;
|
---|
1058 | }
|
---|
1059 | // end of FillHistograms
|
---|
1060 | //----------------------------------------------------------------------------
|
---|
1061 |
|
---|
1062 | bool UseThisPulse(
|
---|
1063 | int maxPos,
|
---|
1064 | int order,
|
---|
1065 | int AmplWindowWidth,
|
---|
1066 | float gainMean,
|
---|
1067 | int maxPulseOrder,
|
---|
1068 | int verbosityLevel
|
---|
1069 | )
|
---|
1070 | {
|
---|
1071 | //determine if pulse is of given order
|
---|
1072 | bool use_this_peak = false;
|
---|
1073 | if (gAmeas[maxPos] >= ((gainMean*(order+1)) - (AmplWindowWidth/2))
|
---|
1074 | && gAmeas[maxPos] < ((gainMean*(order+1)) + AmplWindowWidth/2))
|
---|
1075 | {
|
---|
1076 | if (verbosityLevel > 3) cout << "...#" << order ;
|
---|
1077 | use_this_peak = true;
|
---|
1078 | }
|
---|
1079 | else
|
---|
1080 | {
|
---|
1081 | if (verbosityLevel > 3)
|
---|
1082 | {
|
---|
1083 | if (order >= (maxPulseOrder - 1))
|
---|
1084 | {
|
---|
1085 | cout << "...NONE" << endl ;
|
---|
1086 | }
|
---|
1087 | }
|
---|
1088 | use_this_peak = false;
|
---|
1089 | }
|
---|
1090 |
|
---|
1091 | return use_this_peak;
|
---|
1092 | }
|
---|
1093 |
|
---|
1094 |
|
---|
1095 | void
|
---|
1096 | DrawTestHistograms(
|
---|
1097 | int verbosityLevel
|
---|
1098 | )
|
---|
1099 | {
|
---|
1100 | if (verbosityLevel > 2) cout << endl << "...drawing pulse histograms TODO CANVAS" ;
|
---|
1101 |
|
---|
1102 | // cgpTestHistos->cd(1);
|
---|
1103 | // hTesthisto->Draw();
|
---|
1104 | // cgpTestHistos->cd(2);
|
---|
1105 | // hTesthisto2->Draw("BOX");
|
---|
1106 | }
|
---|
1107 | // end of DrawTestHistograms
|
---|
1108 | //----------------------------------------------------------------------------
|
---|
1109 |
|
---|
1110 | void
|
---|
1111 | UpdateCanvases(
|
---|
1112 | int verbosityLevel,
|
---|
1113 | int max_pulse_order,
|
---|
1114 | bool testmode
|
---|
1115 | )
|
---|
1116 | {
|
---|
1117 | if (verbosityLevel > 3) cout << endl << "...updating canvases" ;
|
---|
1118 | for (int pulse_order = 0; pulse_order < max_pulse_order; pulse_order++)
|
---|
1119 | {
|
---|
1120 | cgpPixelPulses[pulse_order]->Modified();
|
---|
1121 | cgpPixelPulses[pulse_order]->Update();
|
---|
1122 | cgpDistributions[pulse_order]->Modified();
|
---|
1123 | cgpDistributions[pulse_order]->Update();
|
---|
1124 | if ( testmode )
|
---|
1125 | {
|
---|
1126 | cgpTestHistos->Modified();
|
---|
1127 | cgpTestHistos->Update();
|
---|
1128 | }
|
---|
1129 | }
|
---|
1130 | }
|
---|
1131 | // end of UpdateCanvases
|
---|
1132 | //----------------------------------------------------------------------------
|
---|
1133 |
|
---|
1134 | void
|
---|
1135 | DeletePixelCanvases(
|
---|
1136 | int maxPulseOrder,
|
---|
1137 | int verbosityLevel
|
---|
1138 | )
|
---|
1139 | {
|
---|
1140 | if (verbosityLevel > 2) cout << endl << "...delete pixel Canvases" ;
|
---|
1141 | for (int pulse_order = 0; pulse_order < maxPulseOrder; pulse_order++ )
|
---|
1142 | {
|
---|
1143 | delete cgpPixelPulses[pulse_order];
|
---|
1144 | delete cgpDistributions[pulse_order];
|
---|
1145 | }
|
---|
1146 | delete[] cgpPixelPulses;
|
---|
1147 | delete[] cgpDistributions;
|
---|
1148 | }
|
---|
1149 |
|
---|
1150 | //----------------------------------------------------------------------------
|
---|
1151 | //----------------------------------------------------------------------------
|
---|
1152 |
|
---|
1153 | bool
|
---|
1154 | ProduceDebugHistos(
|
---|
1155 | vector<Region>* pZXings
|
---|
1156 | )
|
---|
1157 | {
|
---|
1158 | // TODO do this correct. The vectors should be the rigt ones... this is just luck
|
---|
1159 | debugHistos[gAmeas_].GetXaxis()->Set(gAmeas.size() , -0.5 , gAmeas.size()-0.5);
|
---|
1160 | debugHistos[gVcorr_].GetXaxis()->Set(gAmeas.size() , -0.5 , gAmeas.size()-0.5);
|
---|
1161 | debugHistos[gVslide_].GetXaxis()->Set(gAmeas.size() , -0.5 , gAmeas.size()-0.5);
|
---|
1162 | debugHistos[gVcfd_].GetXaxis()->Set(gAmeas.size() , -0.5 , gAmeas.size()-0.5);
|
---|
1163 | debugHistos[gVcfd2_].GetXaxis()->Set(gAmeas.size() , -0.5 , gAmeas.size()-0.5);
|
---|
1164 |
|
---|
1165 | for ( unsigned int sl = 0; sl < gRegionOfInterest; sl++)
|
---|
1166 | {
|
---|
1167 | debugHistos[gAmeas_].SetBinContent(sl, gAmeas[sl]);
|
---|
1168 | debugHistos[gVcorr_].SetBinContent(sl, gVcorr[sl]);
|
---|
1169 | debugHistos[gVslide_].SetBinContent( sl, gVslide[sl] );
|
---|
1170 | debugHistos[gVcfd_].SetBinContent( sl, gVcfd[sl] );
|
---|
1171 | debugHistos[gVcfd2_].SetBinContent( sl, gVcfd2[sl] );
|
---|
1172 | }
|
---|
1173 |
|
---|
1174 | bool has_negative_slope = false;
|
---|
1175 | cFiltered->cd(1);
|
---|
1176 | gPad->SetGrid();
|
---|
1177 | debugHistos[gAmeas_].Draw();
|
---|
1178 |
|
---|
1179 | TF1 *OneEdge;
|
---|
1180 | TLine *OneLine;
|
---|
1181 | TBox *OneBox;
|
---|
1182 | vector<TF1*> MyEdges;
|
---|
1183 | vector<TBox*> MyBoxes;
|
---|
1184 | vector<TBox*> MyLines;
|
---|
1185 |
|
---|
1186 | int left = debugHistos[gAmeas_].GetXaxis()->GetFirst();
|
---|
1187 | int right = debugHistos[gAmeas_].GetXaxis()->GetLast();
|
---|
1188 | vector<Region>::iterator region;
|
---|
1189 | for (region = pZXings->begin() ; region < pZXings->end() ; region++)
|
---|
1190 | {
|
---|
1191 | if (region->slopeOfRisingEdge < 0)
|
---|
1192 | {
|
---|
1193 | has_negative_slope = true;
|
---|
1194 | }
|
---|
1195 | }
|
---|
1196 |
|
---|
1197 | if (has_negative_slope)
|
---|
1198 | {
|
---|
1199 | for (unsigned int i=0; i<pZXings->size(); i++){
|
---|
1200 | Region* reg = &pZXings->at(i);
|
---|
1201 | cout << "Slope is: " << reg->slopeOfRisingEdge << endl;
|
---|
1202 |
|
---|
1203 | // xBegin = (reg->halfRisingEdgePos - reg->distanceEdgeToMax);
|
---|
1204 | // yBegin = reg->integRCeptRisingEdge + reg->slopeOfRisingEdge * (xBegin)
|
---|
1205 |
|
---|
1206 | OneEdge = new TF1(
|
---|
1207 | "OneEdge",
|
---|
1208 | "[0]*x+[1]",
|
---|
1209 | left,
|
---|
1210 | right
|
---|
1211 | );
|
---|
1212 |
|
---|
1213 | OneEdge->SetParameters(
|
---|
1214 | reg->slopeOfRisingEdge,
|
---|
1215 | reg->interceptRisingEdge
|
---|
1216 | );
|
---|
1217 |
|
---|
1218 | OneEdge->SetLineColor(kRed);
|
---|
1219 | OneEdge->SetLineWidth(1);
|
---|
1220 | MyEdges.push_back(OneEdge);
|
---|
1221 |
|
---|
1222 | OneEdge->Draw("SAME");
|
---|
1223 | // delete OneEdge;
|
---|
1224 |
|
---|
1225 | OneBox = new TBox(
|
---|
1226 | pZXings->at(i).maxPos -10 ,
|
---|
1227 | pZXings->at(i).maxVal -0.5,
|
---|
1228 | pZXings->at(i).maxPos +10 ,
|
---|
1229 | pZXings->at(i).maxVal +0.5);
|
---|
1230 | OneBox->SetLineColor(kBlue);
|
---|
1231 | OneBox->SetLineWidth(1);
|
---|
1232 | OneBox->SetFillStyle(0);
|
---|
1233 | OneBox->SetFillColor(kRed);
|
---|
1234 | MyBoxes.push_back(OneBox);
|
---|
1235 | OneBox->Draw();
|
---|
1236 |
|
---|
1237 | OneLine = new TLine(
|
---|
1238 | pZXings->at(i).halfRisingEdgePos,
|
---|
1239 | gAmeas[pZXings->at(i).halfRisingEdgePos],
|
---|
1240 | pZXings->at(i).halfRisingEdgePos,
|
---|
1241 | pZXings->at(i).halfRisingEdgePos * pZXings->at(i).slopeOfRisingEdge + pZXings->at(i).interceptRisingEdge
|
---|
1242 | );
|
---|
1243 | OneLine->SetLineColor(kBlue);
|
---|
1244 | OneLine->SetLineWidth(3);
|
---|
1245 | MyLines.push_back(OneBox);
|
---|
1246 | OneLine->Draw();
|
---|
1247 | }
|
---|
1248 |
|
---|
1249 | cFiltered->cd(2);
|
---|
1250 | gPad->SetGrid();
|
---|
1251 | debugHistos[gVslide_].Draw();
|
---|
1252 | debugHistos[gVcorr_].Draw("SAME");
|
---|
1253 |
|
---|
1254 | for (unsigned int i=0; i<MyEdges.size(); i++){
|
---|
1255 | MyEdges.at(i)->Draw("SAME");
|
---|
1256 | }
|
---|
1257 | for (unsigned int i=0; i<MyBoxes.size(); i++){
|
---|
1258 | MyBoxes.at(i)->Draw();
|
---|
1259 | }
|
---|
1260 | for (unsigned int i=0; i<MyLines.size(); i++){
|
---|
1261 | MyLines.at(i)->Draw();
|
---|
1262 | }
|
---|
1263 |
|
---|
1264 | cFiltered->cd(3);
|
---|
1265 | gPad->SetGrid();
|
---|
1266 | debugHistos[gVcorr_].SetLineColor(kBlue);
|
---|
1267 | debugHistos[gVcorr_].Draw();
|
---|
1268 | debugHistos[gAmeas_].Draw("SAME");
|
---|
1269 | debugHistos[gVslide_].SetLineColor(kRed);
|
---|
1270 | debugHistos[gVslide_].Draw("SAME");
|
---|
1271 | debugHistos[gVcfd_].SetLineColor(kGreen);
|
---|
1272 | debugHistos[gVcfd_].Draw("SAME");
|
---|
1273 | debugHistos[gVcfd2_].SetLineColor(kViolet);
|
---|
1274 | debugHistos[gVcfd2_].Draw("SAME");
|
---|
1275 | for (unsigned int i=0; i<MyEdges.size(); i++){
|
---|
1276 | MyEdges.at(i)->Draw("SAME");
|
---|
1277 | }
|
---|
1278 | for (unsigned int i=0; i<MyBoxes.size(); i++){
|
---|
1279 | MyBoxes.at(i)->Draw();
|
---|
1280 | }
|
---|
1281 | for (unsigned int i=0; i<MyLines.size(); i++){
|
---|
1282 | MyLines.at(i)->Draw();
|
---|
1283 | }
|
---|
1284 |
|
---|
1285 |
|
---|
1286 | // cFiltered->cd(3);
|
---|
1287 | // gPad->SetGrid();
|
---|
1288 | // debugHistos[gVcfd2_].Draw();
|
---|
1289 | // TLine *zeroline = new TLine(0, 0, 1024, 0);
|
---|
1290 | // zeroline->SetLineColor(kBlue);
|
---|
1291 | // zeroline->Draw();
|
---|
1292 |
|
---|
1293 | cFiltered->Update();
|
---|
1294 |
|
---|
1295 |
|
---|
1296 | //Process gui events asynchronously during input
|
---|
1297 | TTimer timer("gSystem->ProcessEvents();", 50, kFALSE);
|
---|
1298 | timer.TurnOn();
|
---|
1299 | TString input = Getline("Type 'q' to exit, <return> to go on: ");
|
---|
1300 | timer.TurnOff();
|
---|
1301 | if (input=="q\n") {
|
---|
1302 | return true;
|
---|
1303 | }
|
---|
1304 |
|
---|
1305 | MyLines.clear();
|
---|
1306 | MyBoxes.clear();
|
---|
1307 | MyEdges.clear();
|
---|
1308 |
|
---|
1309 | // for (unsigned int i=0; i<pZXings->size(); i++)
|
---|
1310 | // {
|
---|
1311 | // delete MyEdges.at(i)
|
---|
1312 | // delete MyBoxes.at(i);
|
---|
1313 | // }
|
---|
1314 | // delete OneBox;
|
---|
1315 | // delete OneEdge;
|
---|
1316 | // delete OneLine;
|
---|
1317 |
|
---|
1318 | // MyEdges.erase();
|
---|
1319 | // MyBoxes.erase();
|
---|
1320 | }
|
---|
1321 |
|
---|
1322 | //TODO!!!!!!!!!
|
---|
1323 | // do some Garbage collection ...
|
---|
1324 | // all the Objects on the heap should be deleted here.
|
---|
1325 | return false;
|
---|
1326 | }// end of if(spikeDebug)
|
---|
1327 |
|
---|
1328 | int HandleFitsFile(
|
---|
1329 | fits * datafile,
|
---|
1330 | TString datafilename,
|
---|
1331 | TString drsfilename,
|
---|
1332 | int nevents,
|
---|
1333 | int npixel,
|
---|
1334 | int verbosityLevel
|
---|
1335 | )
|
---|
1336 | {
|
---|
1337 | // Opens the raw data file and 'binds' the variables given as
|
---|
1338 | // Parameters to the data file. So they are filled with
|
---|
1339 | // raw data as soon as datafile->GetRow(int) is called.
|
---|
1340 | cout << "\nopening " << datafilename << endl;
|
---|
1341 |
|
---|
1342 | gNEvents = openDataFits(
|
---|
1343 | datafilename,
|
---|
1344 | &datafile,
|
---|
1345 | gAllPixelDataVector,
|
---|
1346 | gStartCellVector,
|
---|
1347 | gCurrentEventID,
|
---|
1348 | gRegionOfInterest,
|
---|
1349 | gNumberOfPixels,
|
---|
1350 | gPXLxROI,
|
---|
1351 | verbosityLevel
|
---|
1352 | );
|
---|
1353 |
|
---|
1354 | if (gNEvents == 0)
|
---|
1355 | {
|
---|
1356 | cout << "return code of OpenDataFile:" << datafilename<< endl;
|
---|
1357 | cout << "is zero -> aborting." << endl;
|
---|
1358 | return 1;
|
---|
1359 | }
|
---|
1360 |
|
---|
1361 | if (verbosityLevel > 0)
|
---|
1362 | {
|
---|
1363 | cout << endl <<"number of events in file: "<< gNEvents << "\t";
|
---|
1364 | }
|
---|
1365 |
|
---|
1366 | if ( nevents == -1 || nevents > gNEvents ) nevents = gNEvents; // -1 means all!
|
---|
1367 |
|
---|
1368 | if (verbosityLevel > 0)
|
---|
1369 | {
|
---|
1370 | cout <<"of, which "<< nevents << " will be processed"<< endl;
|
---|
1371 | cout <<"Total # of Pixel: "<< gNumberOfPixels << "\t";
|
---|
1372 | }
|
---|
1373 |
|
---|
1374 | if ( npixel == -1 || npixel > (int)gNumberOfPixels ) npixel = (int)gNumberOfPixels; // -1 means all!
|
---|
1375 |
|
---|
1376 | if (verbosityLevel > 0)
|
---|
1377 | {
|
---|
1378 | cout <<"of, which "<< npixel << " will be processed"<< endl;
|
---|
1379 | }
|
---|
1380 |
|
---|
1381 | //Get the DRS calibration
|
---|
1382 | gRC = openCalibFits(
|
---|
1383 | drsfilename,
|
---|
1384 | gDrsBaseMean,
|
---|
1385 | gDrsGainMean,
|
---|
1386 | gDrsTriggeroffsetMean,
|
---|
1387 | gTriggerOffsetROI
|
---|
1388 | );
|
---|
1389 |
|
---|
1390 | if (gRC == 0)
|
---|
1391 | {
|
---|
1392 | cout << "return code of openCalibFits:" << drsfilename << endl;
|
---|
1393 | cout << "is zero -> aborting." << endl;
|
---|
1394 | return 1;
|
---|
1395 | }
|
---|
1396 | return 0;
|
---|
1397 | }
|
---|
1398 |
|
---|
1399 | //int main(int argc,char *argv[])
|
---|
1400 | //{
|
---|
1401 |
|
---|
1402 | // TString test;
|
---|
1403 | // TString gRCFileName;
|
---|
1404 | // TString processType = "overlay";
|
---|
1405 | // bool gRCFileNameCmdSet = false;
|
---|
1406 | // int verbLevel = 0; // different verbosity levels can be implemented here
|
---|
1407 | // bool verbLevelCmdSet = false;
|
---|
1408 | // bool save = false;
|
---|
1409 | // bool produceGraphic = false;
|
---|
1410 |
|
---|
1411 | // // decode arguments
|
---|
1412 | // if(argc < 2)
|
---|
1413 | // {
|
---|
1414 | // printf("no arguements given, using standard arguments\n");
|
---|
1415 | // }
|
---|
1416 |
|
---|
1417 | // // set conditions for functions arguments
|
---|
1418 | // for (int i=1;i<argc;i++)
|
---|
1419 | // {
|
---|
1420 | // test = argv[i];
|
---|
1421 |
|
---|
1422 | // if (test.Contains("--config_file") || test.Contains("-c"))
|
---|
1423 | // {
|
---|
1424 | // cout << "gRC-File: \"" << argv[i + 1] << "\"" << endl;
|
---|
1425 | // gRCFileName = argv[i + 1];
|
---|
1426 | // gRCFileNameCmdSet = true;
|
---|
1427 | // continue;
|
---|
1428 | // }
|
---|
1429 |
|
---|
1430 | // if (test.Contains("--verbosity") || test.Contains("-v"))
|
---|
1431 | // {
|
---|
1432 | // cout << "Verbosity Level: \"" << argv[i + 1] << "\"" << endl;
|
---|
1433 | // verbLevel = atoi(argv[i + 1]);
|
---|
1434 | // continue;
|
---|
1435 | // }
|
---|
1436 |
|
---|
1437 | // if (test.Contains("--save") || test.Contains("-s"))
|
---|
1438 | // {
|
---|
1439 | // cout << "will save results" << endl;
|
---|
1440 | // save = true;
|
---|
1441 | // continue;
|
---|
1442 | // }
|
---|
1443 |
|
---|
1444 | // if (test.Contains("--graphics") || test.Contains("-g"))
|
---|
1445 | // {
|
---|
1446 | // cout << "will produce graphics" << endl;
|
---|
1447 | // produceGraphic = true;
|
---|
1448 | // continue;
|
---|
1449 | // }
|
---|
1450 | // }
|
---|
1451 |
|
---|
1452 | // // reading gRC-File:
|
---|
1453 | // configfile gRCfile( gRCFileName, processType );
|
---|
1454 |
|
---|
1455 | // if (save)
|
---|
1456 | // {
|
---|
1457 | // gRCfile.mSave = save;
|
---|
1458 | // }
|
---|
1459 |
|
---|
1460 | // if (verbLevelCmdSet)
|
---|
1461 | // {
|
---|
1462 | // gRCfile.mVerbLevel = verbLevel;
|
---|
1463 | // }
|
---|
1464 |
|
---|
1465 | // if (produceGraphic)
|
---|
1466 | // {
|
---|
1467 | // gRCfile.mProduceGraphic = produceGraphic;
|
---|
1468 | // }
|
---|
1469 |
|
---|
1470 | // FPulseOverlay(
|
---|
1471 | // gRCfile.mInputPath,
|
---|
1472 | // gRCfile.mDataFileName,
|
---|
1473 | // gRCfile.mDrsFileName,
|
---|
1474 | // gRCfile.mOutputPath,
|
---|
1475 | // gRCfile.mOutputFile,
|
---|
1476 | // gRCfile.mFirstEvent,
|
---|
1477 | // gRCfile.mNumEvents,
|
---|
1478 | // gRCfile.mFirstPixel,
|
---|
1479 | // gRCfile.mNumPixel,
|
---|
1480 | // gRCfile.mPixelSetSize,
|
---|
1481 | // gRCfile.mMaxOrder,
|
---|
1482 | // gRCfile.mVerbLevel,
|
---|
1483 | // gRCfile.mHistoOptions,
|
---|
1484 | // gRCfile.mAmplWindowWidth,
|
---|
1485 | // gRCfile.mGainMean,
|
---|
1486 | // gRCfile.mBSLMean,
|
---|
1487 | // gRCfile.mAvg1,
|
---|
1488 | // gRCfile.mAvg2,
|
---|
1489 | // gRCfile.mOverlayWindowLeft,
|
---|
1490 | // gRCfile.mOverlayWindowRight,
|
---|
1491 | // gRCfile.mProduceGraphic,
|
---|
1492 | // gRCfile.mSpikeDebug,
|
---|
1493 | // gRCfile.mDbgPixel,
|
---|
1494 | // gRCfile.mPrintStats,
|
---|
1495 | // gRCfile.mSave,
|
---|
1496 | // gRCfile.mTestMode,
|
---|
1497 | // gRCfile.mRefreshRate
|
---|
1498 | // );
|
---|
1499 | // return 0;
|
---|
1500 |
|
---|
1501 | //}
|
---|