source: fact/tools/rootmacros/PulseTemplates/FCalcPulseTemplate.C@ 13782

Last change on this file since 13782 was 13780, checked in by Jens Buss, 13 years ago
changed all savelists from objarray to list, extracted SetHostPath to rootfilehandler, drawing and filling whole camera histos added, working no seg fault
File size: 20.8 KB
Line 
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>
29using 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 "pixelsum.h"
43#include "templateextractors.h"
44
45//----------------------------------------------------------------------------
46// Decleration of global variables
47//----------------------------------------------------------------------------
48bool breakout=false;
49
50//----------------------------------------------------------------------------
51// Initialisation of Root Objects
52//----------------------------------------------------------------------------
53
54// Temporary Objects
55
56//Pixelwise Histograms
57
58//All Pixel Histograms
59
60//Root-File Objects
61TObjArray* hAllPixelList = NULL;
62TObjArray* hRootList = NULL;
63
64//Canvases
65TCanvas** cgpPixelPulses = NULL;
66TCanvas** cgpAllPixelPulses = NULL;
67TCanvas** cgpDistributions = NULL;
68//TCanvas* cgpTestHistos = NULL;
69
70//----------------------------------------------------------------------------
71// Functions
72//----------------------------------------------------------------------------
73void DeletePixelCanvases( int, int );
74void
75UpdateCanvases(
76 int verbosityLevel,
77 int max_pulse_order,
78 bool testmode
79 );
80//----------------------------------------------------------------------------
81//----------------------------------------------------------------------------
82// MAIN - Funtion
83//----------------------------------------------------------------------------
84//----------------------------------------------------------------------------
85int FCalcPulseTemplate(
86 TString InRootFileName = "20120309_018.root",
87 TString InputPath = "analysis/FPulseTemplate/20120309_018/Overlay/",
88 TString OutputRootFileName = "test.root",
89 TString OutPutPath = "analysis/FPulseTemplate/20120309_018/",
90 bool ProduceGraphic = true,
91// bool fitdata = false,
92 bool stats = false,
93 bool debugPixel = false,
94 int pixelSetSize = 40,
95 int maxPulseOrder = 3,
96// int refresh_rate = 500, //refresh rate for canvases
97 int verbosityLevel = 5, // different verbosity levels can be implemented here
98 int firstpixel = 0,
99 int npixel = 2
100 )
101{
102
103
104 InputPath = SetHostsPaths(true, InputPath );
105 OutPutPath = SetHostsPaths(true, OutPutPath );
106
107
108//----------------------------------------------------------------------------
109// Open-Root-File Settings
110//----------------------------------------------------------------------------
111 if (verbosityLevel > 0)
112 {
113 cout << endl << "...load root file" << endl;
114 }
115
116 TFile * inputRootFile = OpenRootFile( InputPath, InRootFileName, verbosityLevel );
117 TFile * outputRootFile = OpenRootFile( OutPutPath, OutputRootFileName, verbosityLevel );
118//----------------------------------------------------------------------------
119// global variable Settings
120//----------------------------------------------------------------------------
121 if ( npixel == -1 )
122 {
123 npixel = NPIX - firstpixel;
124 }
125
126
127 if ( pixelSetSize == -1 )
128 {
129 pixelSetSize = firstpixel +npixel;
130 }
131// float GainMean = GainMean; // this has to be extracted from root files
132// float BSLMean = BSLMean; // this has to be extracted from root files
133
134//----------------------------------------------------------------------------
135// root global Settings
136//----------------------------------------------------------------------------
137 if (verbosityLevel > 0)
138 {
139 cout << endl << "...setting up root environment" ;
140 }
141
142 gStyle->SetPalette(1,0);
143 gROOT->SetStyle("Plain");
144// gPad->SetGrid();
145
146
147
148//----------------------------------------------------------------------------
149// root Canvas Settings
150//----------------------------------------------------------------------------
151 if (verbosityLevel > 0)
152 {
153 cout << endl << "...preparing canvases" << endl;
154 }
155
156 //Canvas Pad numbering
157 int PixelCanvasFrameNrs[4] = {
158 1, // Top left
159 2, // Top right
160 3, // bottom left
161 4 // bootom right
162 };
163
164 //Canvas Pad numbering
165 int AllpixelCanvasFrameNrs[4] = {
166 1, // Top left
167 2, // Top right
168 3, // bottom left
169 4 // bootom right
170 };
171
172 if (ProduceGraphic)
173 {
174
175 //Canvases
176 cgpPixelPulses = new TCanvas*[maxPulseOrder];
177 cgpDistributions = new TCanvas*[maxPulseOrder];
178
179 //TCanvas* gpcDevelopment = NULL;
180 TString cName = "";
181 TString cTitle = "";
182
183 //naming of pulse canvases
184 for (
185 int pulse_order = maxPulseOrder - 1;
186 pulse_order >= 0 ;
187 pulse_order--
188 )
189 {
190 cName ="cgpDistributions";
191 cName += pulse_order;
192 cTitle ="Distributions of Pulses with Order of: ";
193 cTitle += pulse_order;
194 cgpDistributions[pulse_order] = new TCanvas(cName,cTitle, 720,pulse_order*20,720,720);
195 cgpDistributions[pulse_order]->Divide(2, 2);
196 cName ="cgpPixelPulses";
197 cName += pulse_order;
198 cTitle ="Overlays of Pulses with Order of: ";
199 cTitle += pulse_order;
200 cgpPixelPulses[pulse_order] = new TCanvas(cName,cTitle, 0,pulse_order*20,720,720);
201 cgpPixelPulses[pulse_order]->Divide(2, 2);
202 }
203
204
205 // Create (pointer to) Canvases, which are used in every run,
206 // also in 'non-debug' runs
207 // Canvases only need if spike Debug, but I want to deklare
208 // the pointers anyway ...
209
210// if (testmode)
211// {
212// //additional Test histograms
213// cgpTestHistos = new TCanvas( "cgpTestHistos", "Test Histograms", 360, 420, 360, 360 );
214// cgpTestHistos->Divide(2,0);
215// }
216 }
217
218//-----------------------------------------------------------------------------
219// Filter-Settings
220//-----------------------------------------------------------------------------
221
222
223//-----------------------------------------------------------------------------
224// prepare datafile
225//-----------------------------------------------------------------------------
226
227//----------------------------------------------------------------------------
228// Initialize Pixel
229//----------------------------------------------------------------------------
230 if (verbosityLevel > 0)
231 {
232 cout << endl << "...preparing pixels" << endl;
233 }
234
235 Pixel** pixel = new Pixel*[NPIX];
236
237 for (int i = 0 ; i < NPIX; i++)
238 {
239 pixel[i] = NULL;
240 }
241
242 PixelSum* wholeCamera = NULL;
243
244 bool first_pass = true;
245//-------------------------------------
246// Loop over Pixel Sets
247//-------------------------------------
248 for ( int firstPixelOfSet = firstpixel;
249 firstPixelOfSet < firstpixel + npixel;
250 firstPixelOfSet += pixelSetSize )
251 {
252 if (verbosityLevel >= 0)
253 {
254 cout << "------------------------------------------------" << endl
255 << "...processing Pixel: "
256 << firstPixelOfSet
257 << " to Pixel: "
258 << firstPixelOfSet+pixelSetSize-1 << endl;
259 }
260
261 //--------------------------------------------------------------------
262 // Loops over every Pixel of a Set of Pixels
263 //--------------------------------------------------------------------
264 for ( int pixelID = firstPixelOfSet;
265 pixelID < firstPixelOfSet + pixelSetSize
266 && pixelID < firstpixel + npixel;
267 pixelID++ )
268 {
269
270 if (verbosityLevel > 1)
271 {
272 cout << "-------------------------------------" << endl
273 << "...processing Set from Pixel "
274 << firstPixelOfSet
275 << " to Pixel "
276 << firstPixelOfSet+pixelSetSize-1
277 << " Pixel: " << pixelID
278 << "/" << firstpixel + npixel -1 << endl;
279 }
280
281 //-------------------------------------
282 // Create individual Pixel
283 //-------------------------------------
284 if (verbosityLevel > 3)
285 {
286 cout << "...creating pixel: " << pixelID << endl;
287 }
288 pixel[pixelID] = new Pixel(
289 pixelID,
290 maxPulseOrder, ///One should get this from the file
291 verbosityLevel,
292 stats,
293 "L",
294 70, ///TODO: get it from the root file
295 230, ///TODO: get it from the root file
296 -1, ///TODO: get it from the root file
297 9, ///TODO: get it from the root file
298 inputRootFile
299 );
300
301 if (breakout) break;
302
303 //Preparing Camera
304 if (first_pass)
305 {
306 if (verbosityLevel > 0)
307 {
308 cout << endl << "...preparing camera" << endl;
309 }
310 wholeCamera = new PixelSum(
311 "AllPixel",
312 1440,
313 maxPulseOrder,
314 verbosityLevel,
315 stats,
316 "",
317 pixel[pixelID]->mPixelOverlayXaxisLeft,
318 pixel[pixelID]->mPixelOverlayXaxisRight ,
319 pixel[pixelID]->mBSLMean ,
320 pixel[pixelID]->mGainMean ,
321 outputRootFile
322 );
323 first_pass = false;
324 }
325 //-------------------------------------
326 // Histogramms of Maximas in Overlay Spectra
327 //-------------------------------------
328
329 for ( int pulse_order = 0 ;
330 pulse_order < pixel[pixelID]->mMaxPulseOrder ;
331 pulse_order ++)
332 {
333 if (verbosityLevel > 2)
334 {
335 cout << "-------------------------------------" << endl
336 << "...processing Set from Pixel "
337 << firstPixelOfSet
338 << " to Pixel "
339 << firstPixelOfSet+pixelSetSize-1
340 << " Pixel: " << pixelID
341 << "/" << firstpixel + npixel -1
342 << " Pulse-Order: " << pulse_order << endl;
343 }
344
345 // Calculate Max Prop. Value of each slice
346 //-------------------------------------
347 if (verbosityLevel > 2)
348 {
349 cout << "...extracting templates from Maximum Overlay " << endl;
350 }
351 //from Maximum Overlay
352 ExtractPulseTemplate(
353 pixel[pixelID],
354 "Maximum",
355 pulse_order,
356 verbosityLevel
357 );
358
359 if (verbosityLevel > 2)
360 {
361 cout << "...extracting templates from Edge Overlay " << endl;
362 }
363 //from Edge Overlay
364 ExtractPulseTemplate(
365 pixel[pixelID],
366 "Edge",
367 pulse_order,
368 verbosityLevel
369 );
370
371 WritePixelTemplateToCsv(
372 pixel[pixelID],
373 OutPutPath,
374 "Maximum",
375 pulse_order,
376 verbosityLevel
377 );
378
379 WritePixelTemplateToCsv(
380 pixel[pixelID],
381 OutPutPath,
382 "Edge",
383 pulse_order,
384 verbosityLevel
385 );
386 if (ProduceGraphic)
387 {
388 pixel[pixelID]->DrawTemplateHistograms(
389 cgpPixelPulses,
390 PixelCanvasFrameNrs
391 );
392
393 pixel[pixelID]->DrawEdgeTemplateHistograms(
394 cgpPixelPulses,
395 PixelCanvasFrameNrs
396 );
397 }
398 //-------------------------------------
399 // Fill Histogramms of Camera
400 //-------------------------------------
401 cout << "1" << endl;
402 wholeCamera->hMaxOverlay[pulse_order]->Add(
403 pixel[pixelID]->hMaxOverlay[pulse_order]
404 );
405 cout << wholeCamera->hMaxOverlay[pulse_order]->GetName() << endl;
406cout << "2" << endl;
407 wholeCamera->hMaxProfile[pulse_order]->Add(
408 pixel[pixelID]->hMaxProfile[pulse_order]
409 );
410cout << "3" << endl;
411 wholeCamera->hEdgeOverlay[pulse_order]->Add(
412 pixel[pixelID]->hEdgeOverlay[pulse_order]
413 );
414cout << "4" << endl;
415 wholeCamera->hEdgeProfile[pulse_order]->Add(
416 pixel[pixelID]->hEdgeProfile[pulse_order]
417 );
418cout << "5" << endl;
419
420 if (verbosityLevel > 2)
421 {
422 cout << endl << "...End of pulseorder "
423 << pulse_order
424 << endl;
425 }
426
427 }
428 // End of Loop over pulsorder of current Pixel
429
430 if (ProduceGraphic)
431 {
432 UpdateCanvases(
433 verbosityLevel,
434 MAX_PULS_ORDER,
435 false
436 );
437 }
438
439 if (debugPixel)
440 {
441 //Process gui events asynchronously during input
442 cout << endl;
443 TTimer timer("gSystem->ProcessEvents();", 50, kFALSE);
444 timer.TurnOn();
445 TString input = Getline("Type 'q' to exit, <return> to go on: ");
446 timer.TurnOff();
447 if (input=="q\n")
448 {
449 break;
450 }
451 }
452
453
454
455 //deleteCurrent Pixel from Heap
456 delete pixel[pixelID];
457 pixel[pixelID] = NULL;
458 if (verbosityLevel > 2)
459 {
460 cout << endl << "...End of Pixel"
461 << endl << "------------------------------------------------"
462 << endl;
463 }
464 }
465 // End of Loop over all Pixels of set
466
467 if (verbosityLevel > 1)
468 {
469 cout << endl << "...End of Loop over all Pixels of set"
470 << endl << "------------------------------------------------"
471 << endl;
472 }
473 }
474 // End of Loop over all Pixelsets
475
476 if (verbosityLevel > 0)
477 {
478 cout << endl << "...End of Loop over all Pixelsets"
479 << endl << "------------------------------------------------"
480 << endl;
481 }
482
483 delete[] pixel;
484 pixel = NULL;
485//-------------------------------------
486// Draw All Pixel Histograms
487//-------------------------------------
488
489 for ( int pulse_order = 0 ;
490 pulse_order < wholeCamera->mMaxPulseOrder ;
491 pulse_order ++)
492 {
493 if (verbosityLevel > 2)
494 {
495 cout << "-------------------------------------" << endl
496 << "...processing Pulse-Order: " << pulse_order;
497 }
498
499// Calculate Max Prop. Value of each slice
500// -------------------------------------
501
502 //from Maximum Overlay
503 ExtractPulseTemplate(
504 wholeCamera,
505 "Maximum",
506 pulse_order,
507 verbosityLevel
508 );
509
510 //from Edge Overlay
511 ExtractPulseTemplate(
512 wholeCamera,
513 "Edge",
514 pulse_order,
515 verbosityLevel
516 );
517
518 WritePixelTemplateToCsv(
519 wholeCamera,
520 OutPutPath,
521 "Maximum",
522 pulse_order,
523 verbosityLevel
524 );
525
526 WritePixelTemplateToCsv(
527 wholeCamera,
528 OutPutPath,
529 "Edge",
530 pulse_order,
531 verbosityLevel
532 );
533
534// wholeCamera->DrawTemplateHistograms(
535// cgpPixelPulses,
536// PixelCanvasFrameNrs
537// );
538
539// wholeCamera->DrawEdgeTemplateHistograms(
540// cgpPixelPulses,
541// PixelCanvasFrameNrs
542// );
543 } //EOF: Draw All Pixel Histograms
544
545//-------------------------------------
546// Save All Pixel Histograms
547//-------------------------------------
548
549// SaveHistograms( //save histograms of all pixel into output root file
550// OutInRootFileName,
551// CreateSubDirName("All"),
552// hAllPixelList,
553// verbosityLevel
554// );
555
556// SaveHistograms( //save histograms of generell results into output root file
557// OutInRootFileName,
558// "root",
559// hRootList,
560// verbosityLevel
561// );
562
563
564
565// if (ProduceGraphic)
566// {
567// UpdateCanvases(
568// verbosityLevel,
569// MAX_PULS_ORDER,
570// false
571// );
572// }
573
574 delete wholeCamera;
575 if (ProduceGraphic)
576 {
577 DeletePixelCanvases( maxPulseOrder ,verbosityLevel );
578 }
579 delete inputRootFile;
580 delete outputRootFile;
581 return( 0 );
582}
583//----------------------------------------------------------------------------
584// end of main function
585//-----------------------------------------------------------------------------
586
587
588
589
590//-----------------------------------------------------------------------------
591// Funktions
592//-----------------------------------------------------------------------------
593void
594DeletePixelCanvases(
595 int maxPulseOrder,
596 int verbosityLevel
597 )
598{
599 if (verbosityLevel > 2)
600 {
601 cout << endl << "...delete pixel Canvases" << endl;
602 }
603 for (int pulse_order = 0; pulse_order < maxPulseOrder; pulse_order++ )
604 {
605 delete cgpPixelPulses[pulse_order];
606 cgpPixelPulses[pulse_order] = NULL;
607 delete cgpDistributions[pulse_order];
608 cgpDistributions[pulse_order] = NULL;
609 }
610 delete[] cgpPixelPulses;
611 cgpPixelPulses = NULL;
612 delete[] cgpDistributions;
613 cgpDistributions = NULL;
614}
615
616void
617UpdateCanvases(
618 int verbosityLevel,
619 int max_pulse_order,
620 bool testmode
621 )
622{
623 if (verbosityLevel > 3) cout << endl << "...updating canvases" ;
624 for (int pulse_order = 0; pulse_order < max_pulse_order; pulse_order++)
625 {
626 cgpPixelPulses[pulse_order]->Modified();
627 cgpPixelPulses[pulse_order]->Update();
628 cgpDistributions[pulse_order]->Modified();
629 cgpDistributions[pulse_order]->Update();
630// if ( testmode )
631// {
632// cgpTestHistos->Modified();
633// cgpTestHistos->Update();
634// }
635 }
636}
637//-----------------------------------------------------------------------------
638// MAIN Funktion for C compilation
639//-----------------------------------------------------------------------------
640
641int main()
642{
643
644FCalcPulseTemplate();
645return 0;
646
647}
Note: See TracBrowser for help on using the repository browser.