1 | /********************** FPulseTemplate ***********************
|
---|
2 | * open a root-file with pulse overlay histograms
|
---|
3 | * calculate most propable Pulse-Shape
|
---|
4 | * compute pulse height and pulse integral spektrum of the peaks
|
---|
5 | + draw histos for single, double, tripple, ....above 100mV Photonpulses
|
---|
6 | + draw Parameterdevelopment depending on photon quantity
|
---|
7 | + form a template (shape depending on number of photons)
|
---|
8 | so it can be used for detection of other peaks
|
---|
9 | *************************************************************/
|
---|
10 |
|
---|
11 | //----------------------------------------------------------------------------
|
---|
12 | // root libraries
|
---|
13 | //----------------------------------------------------------------------------
|
---|
14 |
|
---|
15 | #include <TROOT.h>
|
---|
16 | #include <TCanvas.h>
|
---|
17 | #include <TTimer.h>
|
---|
18 | #include <Getline.h>
|
---|
19 | #include <TMath.h>
|
---|
20 | #include <TFile.h>
|
---|
21 | #include <TStyle.h>
|
---|
22 | #include <TString.h>
|
---|
23 |
|
---|
24 | #include <stdio.h>
|
---|
25 | #include <stdint.h>
|
---|
26 | #include <cstdio>
|
---|
27 | #include <iostream>
|
---|
28 | #include <fstream>
|
---|
29 | using namespace std;
|
---|
30 |
|
---|
31 | #define NPIX 1440
|
---|
32 | #define NCELL 1024
|
---|
33 | #define FAD_MAX_SAMPLES 1024
|
---|
34 | #define MAX_PULS_ORDER 1
|
---|
35 | #define HAVE_ZLIB
|
---|
36 |
|
---|
37 | //----------------------------------------------------------------------------
|
---|
38 | // rootmacros
|
---|
39 | //----------------------------------------------------------------------------
|
---|
40 | #include "rootfilehandler.h"
|
---|
41 | #include "pixel.h"
|
---|
42 | #include "templateextractors.h"
|
---|
43 |
|
---|
44 | //----------------------------------------------------------------------------
|
---|
45 | // Decleration of global variables
|
---|
46 | //----------------------------------------------------------------------------
|
---|
47 | bool breakout=false;
|
---|
48 |
|
---|
49 | //----------------------------------------------------------------------------
|
---|
50 | // Initialisation of Root Objects
|
---|
51 | //----------------------------------------------------------------------------
|
---|
52 |
|
---|
53 | // Temporary Objects
|
---|
54 |
|
---|
55 | //Pixelwise Histograms
|
---|
56 |
|
---|
57 | //All Pixel Histograms
|
---|
58 |
|
---|
59 | //Root-File Objects
|
---|
60 | TObjArray* hAllPixelList = NULL;
|
---|
61 | TObjArray* hRootList = NULL;
|
---|
62 |
|
---|
63 | //Canvases
|
---|
64 | TCanvas** cgpPixelPulses = NULL;
|
---|
65 | TCanvas** cgpAllPixelPulses = NULL;
|
---|
66 | TCanvas** cgpDistributions = NULL;
|
---|
67 | //TCanvas* cgpTestHistos = NULL;
|
---|
68 |
|
---|
69 | //----------------------------------------------------------------------------
|
---|
70 | // Functions
|
---|
71 | //----------------------------------------------------------------------------
|
---|
72 | void DeletePixelCanvases( int, int );
|
---|
73 | void
|
---|
74 | UpdateCanvases(
|
---|
75 | int verbosityLevel,
|
---|
76 | int max_pulse_order,
|
---|
77 | bool testmode
|
---|
78 | );
|
---|
79 | //----------------------------------------------------------------------------
|
---|
80 | //----------------------------------------------------------------------------
|
---|
81 | // MAIN - Funtion
|
---|
82 | //----------------------------------------------------------------------------
|
---|
83 | //----------------------------------------------------------------------------
|
---|
84 | int FCalcPulseTemplate(
|
---|
85 | TString InRootFileName = "20111109_006.pulses.root",
|
---|
86 | TString InputPath = "../analysis/FPulseTemplate/20111109_006/",
|
---|
87 | TString OutputRootFileName = "20111109_006.pulses.root",
|
---|
88 | TString OutPutPath = "../analysis/FPulseTemplate/20111109_006/Templates/",
|
---|
89 | bool ProduceGraphic = false,
|
---|
90 | bool fitdata = false,
|
---|
91 | bool stats = false,
|
---|
92 | bool debugPixel = false,
|
---|
93 | int pixelSetSize = 40,
|
---|
94 | int maxPulseOrder = 3,
|
---|
95 | int refresh_rate = 500, //refresh rate for canvases
|
---|
96 | int verbosityLevel = 0, // different verbosity levels can be implemented here
|
---|
97 | int firstpixel = 0,
|
---|
98 | int npixel = -1
|
---|
99 | )
|
---|
100 | {
|
---|
101 |
|
---|
102 | //----------------------------------------------------------------------------
|
---|
103 | // Open-Root-File Settings
|
---|
104 | //----------------------------------------------------------------------------
|
---|
105 | TFile * inputRootFile = OpenRootFile( InputPath, InRootFileName, verbosityLevel );
|
---|
106 |
|
---|
107 | //----------------------------------------------------------------------------
|
---|
108 | // global variable Settings
|
---|
109 | //----------------------------------------------------------------------------
|
---|
110 | if ( npixel == -1 )
|
---|
111 | {
|
---|
112 | npixel = NPIX - firstpixel;
|
---|
113 | }
|
---|
114 |
|
---|
115 |
|
---|
116 | if ( pixelSetSize == -1 )
|
---|
117 | {
|
---|
118 | pixelSetSize = firstpixel +npixel;
|
---|
119 | }
|
---|
120 | // float GainMean = GainMean; // this has to be extracted from root files
|
---|
121 | // float BSLMean = BSLMean; // this has to be extracted from root files
|
---|
122 |
|
---|
123 | //----------------------------------------------------------------------------
|
---|
124 | // root global Settings
|
---|
125 | //----------------------------------------------------------------------------
|
---|
126 | gStyle->SetPalette(1,0);
|
---|
127 | gROOT->SetStyle("Plain");
|
---|
128 | gPad->SetGrid();
|
---|
129 |
|
---|
130 |
|
---|
131 |
|
---|
132 | //----------------------------------------------------------------------------
|
---|
133 | // root Canvas Settings
|
---|
134 | //----------------------------------------------------------------------------
|
---|
135 |
|
---|
136 | //Canvas Pad numbering
|
---|
137 | int pulsesCanvasFrameNrs[4] = {
|
---|
138 | 1, // Top left
|
---|
139 | 2, // Top right
|
---|
140 | 3, // bottom left
|
---|
141 | 4 // bootom right
|
---|
142 | };
|
---|
143 |
|
---|
144 | //Canvas Pad numbering
|
---|
145 | int distributionCanvasFrameNrs[4] = {
|
---|
146 | 1, // Top left
|
---|
147 | 2, // Top right
|
---|
148 | 3, // bottom left
|
---|
149 | 4 // bootom right
|
---|
150 | };
|
---|
151 |
|
---|
152 | if (ProduceGraphic)
|
---|
153 | {
|
---|
154 |
|
---|
155 | //Canvases
|
---|
156 | cgpPixelPulses = new TCanvas*[maxPulseOrder];
|
---|
157 | cgpDistributions = new TCanvas*[maxPulseOrder];
|
---|
158 |
|
---|
159 | //TCanvas* gpcDevelopment = NULL;
|
---|
160 | TString cName = "";
|
---|
161 | TString cTitle = "";
|
---|
162 |
|
---|
163 | //naming of pulse canvases
|
---|
164 | for (
|
---|
165 | int pulse_order = maxPulseOrder - 1;
|
---|
166 | pulse_order >= 0 ;
|
---|
167 | pulse_order--
|
---|
168 | )
|
---|
169 | {
|
---|
170 | cName ="cgpDistributions";
|
---|
171 | cName += pulse_order;
|
---|
172 | cTitle ="Distributions of Pulses with Order of: ";
|
---|
173 | cTitle += pulse_order;
|
---|
174 | cgpDistributions[pulse_order] = new TCanvas(cName,cTitle, 720,pulse_order*20,720,720);
|
---|
175 | cgpDistributions[pulse_order]->Divide(2, 2);
|
---|
176 | cName ="cgpPixelPulses";
|
---|
177 | cName += pulse_order;
|
---|
178 | cTitle ="Overlays of Pulses with Order of: ";
|
---|
179 | cTitle += pulse_order;
|
---|
180 | cgpPixelPulses[pulse_order] = new TCanvas(cName,cTitle, 0,pulse_order*20,720,720);
|
---|
181 | cgpPixelPulses[pulse_order]->Divide(2, 2);
|
---|
182 | }
|
---|
183 |
|
---|
184 |
|
---|
185 | // Create (pointer to) Canvases, which are used in every run,
|
---|
186 | // also in 'non-debug' runs
|
---|
187 | // Canvases only need if spike Debug, but I want to deklare
|
---|
188 | // the pointers anyway ...
|
---|
189 |
|
---|
190 | // if (testmode)
|
---|
191 | // {
|
---|
192 | // //additional Test histograms
|
---|
193 | // cgpTestHistos = new TCanvas( "cgpTestHistos", "Test Histograms", 360, 420, 360, 360 );
|
---|
194 | // cgpTestHistos->Divide(2,0);
|
---|
195 | // }
|
---|
196 | }
|
---|
197 |
|
---|
198 | //-----------------------------------------------------------------------------
|
---|
199 | // Filter-Settings
|
---|
200 | //-----------------------------------------------------------------------------
|
---|
201 |
|
---|
202 |
|
---|
203 | //-----------------------------------------------------------------------------
|
---|
204 | // prepare datafile
|
---|
205 | //-----------------------------------------------------------------------------
|
---|
206 |
|
---|
207 | //----------------------------------------------------------------------------
|
---|
208 | // Initialize Pixel
|
---|
209 | //----------------------------------------------------------------------------
|
---|
210 | Pixel** pixel = new Pixel*[NPIX];
|
---|
211 |
|
---|
212 | for (int i = 0 ; i < NPIX; i++)
|
---|
213 | {
|
---|
214 | pixel[i] = NULL;
|
---|
215 | }
|
---|
216 |
|
---|
217 | //-------------------------------------
|
---|
218 | // Loop over Pixel Sets
|
---|
219 | //-------------------------------------
|
---|
220 | for ( int firstPixelOfSet = firstpixel;
|
---|
221 | firstPixelOfSet < firstpixel + npixel;
|
---|
222 | firstPixelOfSet += pixelSetSize )
|
---|
223 | {
|
---|
224 | if (verbosityLevel >= 0)
|
---|
225 | {
|
---|
226 | cout << "------------------------------------------------" << endl
|
---|
227 | << "...processing Pixel: "
|
---|
228 | << firstPixelOfSet
|
---|
229 | << "to Pixel: "
|
---|
230 | << firstPixelOfSet+pixelSetSize-1 << endl;
|
---|
231 | }
|
---|
232 |
|
---|
233 | //--------------------------------------------------------------------
|
---|
234 | // Loops over every Pixel of a Set of Pixels
|
---|
235 | //--------------------------------------------------------------------
|
---|
236 | for ( int pixelID = firstPixelOfSet;
|
---|
237 | pixelID < firstPixelOfSet + pixelSetSize
|
---|
238 | && pixelID < firstpixel + npixel;
|
---|
239 | pixelID++ )
|
---|
240 | {
|
---|
241 |
|
---|
242 | if (verbosityLevel > 1)
|
---|
243 | {
|
---|
244 | cout << "-------------------------------------" << endl
|
---|
245 | << "...processing Set from Pixel "
|
---|
246 | << firstPixelOfSet
|
---|
247 | << " to Pixel "
|
---|
248 | << firstPixelOfSet+pixelSetSize-1
|
---|
249 | << " Pixel: " << pixelID
|
---|
250 | << "/" << firstpixel + npixel -1 << endl;
|
---|
251 | }
|
---|
252 |
|
---|
253 | //-------------------------------------
|
---|
254 | // Create individual Pixel
|
---|
255 | //-------------------------------------
|
---|
256 | pixel[pixelID] = new Pixel(
|
---|
257 | pixelID,
|
---|
258 | maxPulseOrder, ///One should get this from the file
|
---|
259 | verbosityLevel,
|
---|
260 | stats,
|
---|
261 | inputRootFile
|
---|
262 | );
|
---|
263 |
|
---|
264 | if (breakout) break;
|
---|
265 |
|
---|
266 | //-------------------------------------
|
---|
267 | // Histogramms of Maximas in Overlay Spectra
|
---|
268 | //-------------------------------------
|
---|
269 |
|
---|
270 | for ( int pulse_order = 0 ;
|
---|
271 | pulse_order < pixel[pixelID]->mMaxPulseOrder ;
|
---|
272 | pulse_order ++)
|
---|
273 | {
|
---|
274 | if (verbosityLevel > 2)
|
---|
275 | {
|
---|
276 | cout << "-------------------------------------" << endl
|
---|
277 | << "...processing Set from Pixel "
|
---|
278 | << firstPixelOfSet
|
---|
279 | << " to Pixel "
|
---|
280 | << firstPixelOfSet+pixelSetSize-1
|
---|
281 | << " Pixel: " << pixelID
|
---|
282 | << "/" << firstpixel + npixel -1 << endl
|
---|
283 | << " Pulse-Order: " << pulse_order;
|
---|
284 | }
|
---|
285 |
|
---|
286 | // Calculate Max Prop. Value of each slice
|
---|
287 | //-------------------------------------
|
---|
288 |
|
---|
289 | //from Maximum Overlay
|
---|
290 | ExtractPulseTemplate(
|
---|
291 | pixel[pixelID],
|
---|
292 | "Maximum",
|
---|
293 | pulse_order,
|
---|
294 | verbosityLevel
|
---|
295 | );
|
---|
296 |
|
---|
297 | //from Edge Overlay
|
---|
298 | ExtractPulseTemplate(
|
---|
299 | pixel[pixelID],
|
---|
300 | "Edge",
|
---|
301 | pulse_order,
|
---|
302 | verbosityLevel
|
---|
303 | );
|
---|
304 |
|
---|
305 | WritePixelTemplateToCsv(
|
---|
306 | pixel[pixelID],
|
---|
307 | OutPutPath,
|
---|
308 | "Maximum",
|
---|
309 | pulse_order,
|
---|
310 | verbosityLevel
|
---|
311 | );
|
---|
312 |
|
---|
313 | WritePixelTemplateToCsv(
|
---|
314 | pixel[pixelID],
|
---|
315 | OutPutPath,
|
---|
316 | "Edge",
|
---|
317 | pulse_order,
|
---|
318 | verbosityLevel
|
---|
319 | );
|
---|
320 |
|
---|
321 | pixel[pixelID]->DrawTemplateHistograms(
|
---|
322 | cgpPixelPulses,
|
---|
323 | pulsesCanvasFrameNrs
|
---|
324 | );
|
---|
325 |
|
---|
326 | pixel[pixelID]->DrawEdgeTemplateHistograms(
|
---|
327 | cgpPixelPulses,
|
---|
328 | pulsesCanvasFrameNrs
|
---|
329 | );
|
---|
330 |
|
---|
331 |
|
---|
332 |
|
---|
333 | }
|
---|
334 | // End of Loop over pulsorder of current Pixel
|
---|
335 |
|
---|
336 | if (ProduceGraphic)
|
---|
337 | {
|
---|
338 | UpdateCanvases(
|
---|
339 | verbosityLevel,
|
---|
340 | MAX_PULS_ORDER,
|
---|
341 | false
|
---|
342 | );
|
---|
343 | }
|
---|
344 |
|
---|
345 | if (debugPixel)
|
---|
346 | {
|
---|
347 | //Process gui events asynchronously during input
|
---|
348 | cout << endl;
|
---|
349 | TTimer timer("gSystem->ProcessEvents();", 50, kFALSE);
|
---|
350 | timer.TurnOn();
|
---|
351 | TString input = Getline("Type 'q' to exit, <return> to go on: ");
|
---|
352 | timer.TurnOff();
|
---|
353 | if (input=="q\n")
|
---|
354 | {
|
---|
355 | break;
|
---|
356 | }
|
---|
357 | }
|
---|
358 |
|
---|
359 | if (verbosityLevel > 2)
|
---|
360 | {
|
---|
361 | cout << endl << "...End of Pixel"
|
---|
362 | << endl << "------------------------------------------------"
|
---|
363 | << endl;
|
---|
364 | }
|
---|
365 | }
|
---|
366 | // End of Loop over all Pixels of set
|
---|
367 |
|
---|
368 | if (verbosityLevel > 1)
|
---|
369 | {
|
---|
370 | cout << endl << "...End of Loop over all Pixels of set"
|
---|
371 | << endl << "------------------------------------------------"
|
---|
372 | << endl;
|
---|
373 | }
|
---|
374 | }
|
---|
375 | // End of Loop over all Pixelsets
|
---|
376 |
|
---|
377 | if (verbosityLevel > 0)
|
---|
378 | {
|
---|
379 | cout << endl << "...End of Loop over all Pixelsets"
|
---|
380 | << endl << "------------------------------------------------"
|
---|
381 | << endl;
|
---|
382 | }
|
---|
383 |
|
---|
384 | //-------------------------------------
|
---|
385 | // Draw All Pixel Histograms
|
---|
386 | //-------------------------------------
|
---|
387 |
|
---|
388 | // SaveHistograms( //save histograms of all pixel into output root file
|
---|
389 | // OutInRootFileName,
|
---|
390 | // CreateSubDirName("All"),
|
---|
391 | // hAllPixelList,
|
---|
392 | // verbosityLevel
|
---|
393 | // );
|
---|
394 |
|
---|
395 | // SaveHistograms( //save histograms of generell results into output root file
|
---|
396 | // OutInRootFileName,
|
---|
397 | // "root",
|
---|
398 | // hRootList,
|
---|
399 | // verbosityLevel
|
---|
400 | // );
|
---|
401 |
|
---|
402 |
|
---|
403 |
|
---|
404 | // if (ProduceGraphic)
|
---|
405 | // {
|
---|
406 | // UpdateCanvases(
|
---|
407 | // verbosityLevel,
|
---|
408 | // MAX_PULS_ORDER
|
---|
409 | // );
|
---|
410 | // }
|
---|
411 |
|
---|
412 | // WriteAllPixelTemplateToCsv(
|
---|
413 | // OutPutPath,
|
---|
414 | // "PulseTemplate_PointSet",
|
---|
415 | // "Maximum",
|
---|
416 | // verbosityLevel
|
---|
417 | // );
|
---|
418 |
|
---|
419 | DeletePixelCanvases( maxPulseOrder ,verbosityLevel );
|
---|
420 | return( 0 );
|
---|
421 | }
|
---|
422 | //----------------------------------------------------------------------------
|
---|
423 | // end of main function
|
---|
424 | //-----------------------------------------------------------------------------
|
---|
425 |
|
---|
426 |
|
---|
427 |
|
---|
428 |
|
---|
429 | //-----------------------------------------------------------------------------
|
---|
430 | // Funktions
|
---|
431 | //-----------------------------------------------------------------------------
|
---|
432 | void
|
---|
433 | DeletePixelCanvases(
|
---|
434 | int maxPulseOrder,
|
---|
435 | int verbosityLevel
|
---|
436 | )
|
---|
437 | {
|
---|
438 | if (verbosityLevel > 2) cout << endl << "...delete pixel Canvases" ;
|
---|
439 | for (int pulse_order = 0; pulse_order < maxPulseOrder; pulse_order++ )
|
---|
440 | {
|
---|
441 | delete cgpPixelPulses[pulse_order];
|
---|
442 | delete cgpDistributions[pulse_order];
|
---|
443 | }
|
---|
444 | delete[] cgpPixelPulses;
|
---|
445 | delete[] cgpDistributions;
|
---|
446 | }
|
---|
447 |
|
---|
448 | void
|
---|
449 | UpdateCanvases(
|
---|
450 | int verbosityLevel,
|
---|
451 | int max_pulse_order,
|
---|
452 | bool testmode
|
---|
453 | )
|
---|
454 | {
|
---|
455 | if (verbosityLevel > 3) cout << endl << "...updating canvases" ;
|
---|
456 | for (int pulse_order = 0; pulse_order < max_pulse_order; pulse_order++)
|
---|
457 | {
|
---|
458 | cgpPixelPulses[pulse_order]->Modified();
|
---|
459 | cgpPixelPulses[pulse_order]->Update();
|
---|
460 | cgpDistributions[pulse_order]->Modified();
|
---|
461 | cgpDistributions[pulse_order]->Update();
|
---|
462 | // if ( testmode )
|
---|
463 | // {
|
---|
464 | // cgpTestHistos->Modified();
|
---|
465 | // cgpTestHistos->Update();
|
---|
466 | // }
|
---|
467 | }
|
---|
468 | }
|
---|
469 | //-----------------------------------------------------------------------------
|
---|
470 | // MAIN Funktion for C compilation
|
---|
471 | //-----------------------------------------------------------------------------
|
---|
472 |
|
---|
473 | int main()
|
---|
474 | {
|
---|
475 |
|
---|
476 | FCalcPulseTemplate();
|
---|
477 | return 0;
|
---|
478 |
|
---|
479 | }
|
---|