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

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