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

Last change on this file since 14811 was 14811, checked in by Jens Buss, 12 years ago
whitespace
File size: 40.7 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 <TGraph.h>
22#include <TGraphErrors.h>
23#include <TStyle.h>
24#include <TString.h>
25#include <TF1.h>
26
27#include <stdio.h>
28#include <stdint.h>
29#include <cstdio>
30#include <iostream>
31#include <fstream>
32
33#include <vector>
34#include <utility>
35
36using namespace std;
37
38#define NPIX 1440
39#define NCELL 1024
40#define FAD_MAX_SAMPLES 1024
41#define MAX_PULS_ORDER 1
42#define HAVE_ZLIB
43
44//----------------------------------------------------------------------------
45// Classes
46//----------------------------------------------------------------------------
47#include "rootfilehandler.h"
48#include "pixel.h"
49#include "pixelsum.h"
50#include "pulse.h"
51#include "templateextractors.h"
52#include "configfile.h"
53#include "csv.h"
54
55//----------------------------------------------------------------------------
56// Decleration of global variables
57//----------------------------------------------------------------------------
58bool breakout=false;
59
60//----------------------------------------------------------------------------
61// Initialisation of Root Objects
62//----------------------------------------------------------------------------
63
64// Temporary Objects
65
66//Pixelwise Histograms
67
68//All Pixel Histograms
69
70//Root-File Objects
71TObjArray* hAllPixelList = NULL;
72TObjArray* hRootList = NULL;
73
74//Canvases
75TCanvas** cgpPixelPulses = NULL;
76TCanvas** cgpAllPixelPulses = NULL;
77TCanvas** cgpDistributions = NULL;
78TCanvas* cgpGraphs = NULL;
79//TCanvas* cgpTestHistos = NULL;
80
81//----------------------------------------------------------------------------
82// Functions
83//----------------------------------------------------------------------------
84void DeletePixelCanvases( int, int );
85void
86UpdateCanvases(
87 int verbosityLevel,
88 int max_pulse_order,
89 bool testmode
90 );
91
92//----------------------------------------------------------------------------
93//----------------------------------------------------------------------------
94// MAIN - Funtion
95//----------------------------------------------------------------------------
96//----------------------------------------------------------------------------
97int FCalcPulseTemplate(
98 TString InRootFileName = "20120802templ_0mV_entries.root",
99// TString InRootFileName = "20120309_032.root",
100// TString InputPath = "analysis/analysis/FPulseTemplate/20120309_017/Overlay/",
101 TString InputPath = "",
102// TString InputPath = "analysis/analysis/FPulseTemplate/20120309_032/Overlay/",
103 TString OutputRootFileName = "test.root",
104 TString OutPutPath = "",
105 int firstpixel = 0,
106 int npixel = 1,
107 int pixelSetSize = 200,
108 int maxPulseOrder = 1,
109// TString histoOptions = "SRM",
110 bool ProduceGraphic = true,
111 bool stats = true,
112 bool saveResults = false,
113// bool fitdata = false,
114 bool debugPixel = true,
115// int refresh_rate = 500, //refresh rate for canvases
116 int verbosityLevel = 1 // different verbosity levels can be implemented here
117 )
118{
119
120 InputPath = SetHostsPaths(true, InputPath );
121 OutPutPath = SetHostsPaths(true, OutPutPath );
122
123 TString outFile = OutPutPath;
124 outFile += OutputRootFileName;
125
126//----------------------------------------------------------------------------
127// Open-Root-File Settings
128//----------------------------------------------------------------------------
129 if (verbosityLevel > 0)
130 {
131 cout << endl << "...load root file" << endl;
132 }
133
134 TFile * inputRootFile
135 = LoadRootFile( InputPath, InRootFileName, verbosityLevel );
136
137 if (inputRootFile == NULL)
138 {
139 cerr << "input file not readable, check file path!!!" << endl;
140 return(0);
141 }
142 if (saveResults)
143 {
144 CreateRootFile( outFile, true, verbosityLevel );
145 }
146
147 TFile * outputRootFile
148 = OpenRootFile( OutPutPath, OutputRootFileName, verbosityLevel );
149//----------------------------------------------------------------------------
150// Define operation range
151//----------------------------------------------------------------------------
152 if ( npixel == -1 )
153 {
154 npixel = NPIX - firstpixel;
155 }
156
157
158 if ( pixelSetSize == -1 )
159 {
160 pixelSetSize = firstpixel +npixel;
161 }
162
163// float GainMean = GainMean; // this has to be extracted from root files
164// float BSLMean = BSLMean; // this has to be extracted from root files
165
166//----------------------------------------------------------------------------
167// root global Settings
168//----------------------------------------------------------------------------
169 if (verbosityLevel > 0)
170 {
171 cout << endl << "...setting up root environment" ;
172 }
173
174 gStyle->SetPalette(1,0);
175 gROOT->SetStyle("Plain");
176// gPad->SetGrid();
177
178
179
180//----------------------------------------------------------------------------
181// root Canvas Settings
182//----------------------------------------------------------------------------
183 if (verbosityLevel > 0)
184 {
185 cout << endl << "...preparing canvases" << endl;
186 }
187
188 //Canvas Pad numbering
189 int PixelCanvasFrameNrs[8] =
190 {
191 1, // Top left
192 2, // Top mid left
193 3, // Top mid right
194 4, // Top right
195 5, // bootom left
196 6, // bootom mid left
197 7, // bottom mid right
198 8 // bootom right
199 };
200
201// //Canvas Pad numbering
202// int DistributionCanvasFrameNrs[4] = {
203// 1, // Top left
204// 2, // Top right
205// 3, // bottom left
206// 4 // bootom right
207// };
208
209 if (ProduceGraphic)
210 {
211
212 //Canvases
213 cgpPixelPulses = new TCanvas*[maxPulseOrder];
214 cgpDistributions = new TCanvas*[maxPulseOrder];
215 cgpGraphs = new TCanvas("graphs", "Dependences to pe" );
216
217 //TCanvas* gpcDevelopment = NULL;
218 TString cName = "";
219 TString cTitle = "";
220
221 //naming of pulse canvases
222 for (
223 int pulse_order = maxPulseOrder - 1;
224 pulse_order >= 0 ;
225 pulse_order--
226 )
227 {
228 cName ="cgpDistributions";
229 cName += pulse_order;
230
231 cTitle ="Distributions of Pulses with Order of: ";
232 cTitle += pulse_order;
233
234 cgpDistributions[pulse_order]
235 = new TCanvas(cName,cTitle, 720,pulse_order*20,720,720);
236// cgpDistributions[pulse_order]->Divide(2, 2);
237
238 cName ="cgpPixelPulses";
239 cName += pulse_order;
240
241 cTitle ="Overlays of Pulses with Order of: ";
242 cTitle += pulse_order;
243
244 cgpPixelPulses[pulse_order]
245 = new TCanvas(cName,cTitle, 0,pulse_order*20,800,800);
246 cgpPixelPulses[pulse_order]->Divide(4, 2);
247 }
248
249 cgpGraphs->Divide(1,3);
250 }
251
252//-----------------------------------------------------------------------------
253// Filter-Settings
254//-----------------------------------------------------------------------------
255
256//-----------------------------------------------------------------------------
257// Distrribution Histograms
258//-----------------------------------------------------------------------------
259 TH1D hBsl[maxPulseOrder];
260 TH1D hAsymptote[maxPulseOrder];
261 TH1D hT0[maxPulseOrder];
262 TH1D hTau1[maxPulseOrder];
263 TH1D hTau2[maxPulseOrder];
264 TH1D hIntegral[maxPulseOrder];
265 TH1D hAmplitude[maxPulseOrder];
266 TH1D hRiseTime[maxPulseOrder];
267
268 //Lopp over pulse order configure distribution histograms
269 for (int i = 0; i<maxPulseOrder; i++)
270 {
271 //BSL
272 TString title;
273 title = "hBSL";
274 title.Append(i);
275 hBsl[i].SetNameTitle(title, title);
276 hBsl[i].SetBins(400, -2-0.005, 2-0.005);
277
278 //Asymptote
279 title = "hAsymptote";
280 title.Append(i);
281 hAsymptote[i].SetNameTitle(title, title);
282 hAsymptote[i].SetBins(60, -10.5, 49.5);
283
284 //T0
285 title = "hT0";
286 title.Append(i);
287 hT0[i].SetNameTitle(title, title);
288 hT0[i].SetBins(80, 39.5, 119.5);
289
290 //Tau1
291 title = "hTau1";
292 title.Append(i);
293 hTau1[i].SetNameTitle(title, title);
294 hTau1[i].SetBins(10, -10.5, 9.5);
295
296 //Tau2
297 title = "hTau2";
298 title.Append(i);
299 hTau2[i].SetNameTitle(title, title);
300 hTau2[i].SetBins(40, 19.5, 59.5);
301
302 //Integral
303 title = "hIntegral";
304 title.Append(i);
305 hIntegral[i].SetNameTitle(title, title);
306 hIntegral[i].SetBins(500, (i+1)*-0.5, (i+1)*499.5);
307
308 //Amplitude
309 title = "hAmplitude";
310 title.Append(i);
311 hAmplitude[i].SetNameTitle(title, title);
312 hAmplitude[i].SetBins(400, (i+1)*4.95, (i+1)*24.95);
313
314 //hRiseTime
315 title = "hRiseTime";
316 title.Append(i);
317 hRiseTime[i].SetNameTitle(title, title);
318 hRiseTime[i].SetBins(20, -0, 10);
319 }
320
321 // Error Histograms
322
323 TH1D hMedianErrors[maxPulseOrder];
324 TH1D hMeanErrors[maxPulseOrder];
325 TH1D hMaxErrors[maxPulseOrder];
326
327 //Lopp over pulse order configure distribution histograms
328 for (int i = 0; i<maxPulseOrder; i++)
329 {
330 //hMedianErrors
331 TString title;
332 title = "hMedianErrors";
333 title.Append(i);
334 hMedianErrors[i].SetNameTitle(title, title);
335 hMedianErrors[i].SetBins(300, -0.5, 300.5);
336
337 //hMeanErrors
338 title = "hMeanErrors";
339 title.Append(i);
340 hMeanErrors[i].SetNameTitle(title, title);
341 hMeanErrors[i].SetBins(300, -0.5, 300.5);
342
343 //hMaxErrors
344 title = "hMaxErrors";
345 title.Append(i);
346 hMaxErrors[i].SetNameTitle(title, title);
347 hMaxErrors[i].SetBins(300, -0.5, 300.5);
348 }
349
350
351//-----------------------------------------------------------------------------
352// Graphs
353//-----------------------------------------------------------------------------
354 TGraphErrors grPheVsAmpl;
355 grPheVsAmpl.SetNameTitle("grPheVsAmpl", "Distribution of Pulse Amplitude vs. Photon equivalent");
356 grPheVsAmpl.SetMarkerStyle(21);
357
358 TGraphErrors grPheVsIntegral;
359 grPheVsIntegral.SetNameTitle("grPheVsIntegral", "Distribution of Pulse Integral vs. Photon equivalent");
360 grPheVsIntegral.SetMarkerStyle(21);
361
362 TGraphErrors grPheVsTau2;
363 grPheVsTau2.SetNameTitle("grPheVsTau2", "Distribution of Tau2 vs. Photon equivalent");
364 grPheVsTau2.SetMarkerStyle(21);
365//-----------------------------------------------------------------------------
366// Variables
367//-----------------------------------------------------------------------------
368
369
370//----------------------------------------------------------------------------
371// Initialize Pixels
372//----------------------------------------------------------------------------
373 if (verbosityLevel > 0)
374 {
375 cout << endl << "...preparing pixels" << endl;
376 }
377
378 Pixel** pixel = new Pixel*[NPIX];
379
380 for (int i = 0 ; i < NPIX; i++)
381 {
382 pixel[i] = NULL;
383 }
384
385 PixelSum* wholeCamera = NULL;
386
387 bool first_pass = true;
388
389//----------------------------------------------------------------------------
390// Initialize Outputfiles
391//----------------------------------------------------------------------------
392
393 Csv PixelCsv(OutPutPath, InRootFileName.Remove(12, 5), "points", verbosityLevel);
394 PixelCsv.WritePointSetHeader();
395 Csv PixelModelCsv(OutPutPath, InRootFileName.Remove(12, 5), "fitResults", verbosityLevel);
396 PixelModelCsv.WritePulseAttributesHeader();
397// Csv AllPixelCsv(OutPutPath, InRootFileName.Remove(12, 5), -1, verbosityLevel);
398// Csv AllPixelModelCsv(OutPutPath, InRootFileName.Remove(12, 5), "AllPixelModel", verbosityLevel);
399
400 TCanvas pulses("Templates","Templates", 0,0,1200,600);
401 pulses.Divide(3,1);
402//-------------------------------------
403// Loop over Pixel Sets
404//-------------------------------------
405 for ( int firstPixelOfSet = firstpixel;
406 firstPixelOfSet < firstpixel + npixel;
407 firstPixelOfSet += pixelSetSize )
408 {
409 if (verbosityLevel >= 0)
410 {
411 cout << "------------------------------------------------"
412 << endl
413 << "...processing Pixel: "
414 << firstPixelOfSet
415 << " to Pixel: "
416 << firstPixelOfSet+pixelSetSize-1
417 << endl;
418 }
419
420 //--------------------------------------------------------------------
421 // Loop over every Pixel of a Set of Pixels
422 //--------------------------------------------------------------------
423 for ( int pixelID = firstPixelOfSet;
424 pixelID < firstPixelOfSet + pixelSetSize
425 && pixelID < firstpixel + npixel;
426 pixelID++ )
427 {
428 if (verbosityLevel >= 0)
429 {
430 cout << "------------------------------------------------"
431 << endl
432 << "...processing Pixel: "
433 << pixelID << "/"
434 << firstPixelOfSet + pixelSetSize - 1
435 << endl;
436 }
437 if (verbosityLevel > 1)
438 {
439 cout << "-------------------------------------"
440 << endl
441 << "...processing Set from Pixel "
442 << firstPixelOfSet
443 << " to Pixel "
444 << firstPixelOfSet+pixelSetSize-1
445 << " Pixel: " << pixelID
446 << "/" << firstpixel + npixel -1
447 << endl;
448 }
449
450 //-------------------------------------
451 // Create individual Pixel
452 //-------------------------------------
453 if (verbosityLevel > 3)
454 {
455 cout << "...creating pixel: " << pixelID << endl;
456 }
457
458 pixel[pixelID] = new Pixel(
459 pixelID,
460 maxPulseOrder, ///One should get this from the file
461 verbosityLevel,
462 stats,
463 "L",
464 70, //pixelOverlayXaxisLeft /TODO: get it from the root file
465 230, //pixelOverlayXaxisRight /TODO: get it from the root file
466 -1, //bslMean /TODO: get it from the root file
467 9, //gain mean /TODO: get it from the root file
468 inputRootFile,
469 outputRootFile
470 );
471
472 if (breakout) break;
473
474 //Preparing Camera
475 if (first_pass)
476 {
477 if (verbosityLevel > 0)
478 {
479 cout << endl << "...preparing camera" << endl;
480 }
481
482 wholeCamera = new PixelSum(
483 "AllPixel",
484 1440,
485 maxPulseOrder,
486 verbosityLevel,
487 stats,
488 "C",
489 pixel[pixelID]->mPixelOverlayXaxisLeft,
490 pixel[pixelID]->mPixelOverlayXaxisRight ,
491 pixel[pixelID]->mBSLMean ,
492 pixel[pixelID]->mGainMean ,
493 outputRootFile
494 );
495
496 first_pass = false;
497 }
498 //-------------------------------------
499 // Histogramms of Maximas in Overlay Spectra
500 //-------------------------------------
501
502 for ( int pulse_order = 0 ;
503 pulse_order < pixel[pixelID]->mMaxPulseOrder ;
504 pulse_order ++)
505 {
506 if (verbosityLevel > 2)
507 {
508 cout << "-------------------------------------"
509 << endl
510 << "...processing Set from Pixel "
511 << firstPixelOfSet
512 << " to Pixel "
513 << firstPixelOfSet+pixelSetSize-1
514 << " Pixel: " << pixelID
515 << "/" << firstpixel + npixel -1
516 << " Pulse-Order: " << pulse_order
517 << endl;
518 }
519
520 // Calculate Max Prop. Value of each slice
521 //-------------------------------------
522
523 //from Maximum Overlay
524 if (verbosityLevel > 2)
525 {
526 cout << "...extracting templates from Maximum Overlay "
527 << endl;
528 }
529
530 ExtractPulseTemplate(
531 pixel[pixelID],
532 "Maximum",
533 pulse_order,
534 10,
535 verbosityLevel
536 );
537
538 //from Edge Overlay
539 if (verbosityLevel > 2)
540 {
541 cout << "...extracting templates from Edge Overlay "
542 << endl;
543 }
544 ExtractPulseTemplate(
545 pixel[pixelID],
546 "Edge",
547 pulse_order,
548 10,
549 verbosityLevel
550 );
551
552 PixelCsv.WritePointSet(
553 pixel[pixelID],
554 "Maximum",
555 pulse_order
556 );
557
558 PixelCsv.WritePointSet(
559 pixel[pixelID],
560 "Edge",
561 pulse_order
562 );
563
564 if ( saveResults )
565 {
566 WritePixelTemplateToCsv(
567 pixel[pixelID],
568 OutPutPath,
569 "Maximum",
570 pulse_order,
571 verbosityLevel
572 );
573
574 WritePixelTemplateToCsv(
575 pixel[pixelID],
576 OutPutPath,
577 "Edge",
578 pulse_order,
579 verbosityLevel
580 );
581 }
582
583 if (ProduceGraphic && debugPixel)
584 {
585
586 pixel[pixelID]->DrawTemplateHistograms(
587 cgpPixelPulses,
588 PixelCanvasFrameNrs
589 );
590
591 pixel[pixelID]->DrawEdgeTemplateHistograms(
592 cgpPixelPulses,
593 PixelCanvasFrameNrs
594 );
595
596// cgpPixelPulses[pulse_order]->cd(6);
597
598
599 //-------------------------------------
600 //-------------------------------------
601 // Test Area
602 //-------------------------------------
603 //-------------------------------------
604
605 cgpPixelPulses[pulse_order]->cd(8);
606
607 //-------------------------------------
608 //-------------------------------------
609 // EOF Test Area
610 //-------------------------------------
611 //-------------------------------------
612 }
613
614 // =======================================================
615 // Fit of pulse function to template
616
617 Pulse* pulseFits[6];
618
619// pulses.cd(1);
620 Pulse maxMaxPulse("maxMaxPulse", pixel[pixelID]->hPixelMax[pulse_order], "Q", 1,pulse_order);
621 pulseFits[0] = &maxMaxPulse;
622
623// pulses.cd(2);
624 Pulse maxMedianPulse("maxMedianPulse", pixel[pixelID]->hPixelMedian[pulse_order], "Q",1,pulse_order);
625 pulseFits[1] = &maxMedianPulse;
626
627// pulses.cd(3);
628 Pulse maxMeanPulse("maxMeanPulse", pixel[pixelID]->hPixelMean[pulse_order], "Q",1,pulse_order);
629 pulseFits[2] = &maxMeanPulse;
630
631 Pulse edgeMaxPulse("edgeMaxPulse", pixel[pixelID]->hPixelEdgeMax[pulse_order], "Q",1,pulse_order);
632 pulseFits[3] = &edgeMaxPulse;
633
634 Pulse edgeMedianPulse("edgeMedianPulse", pixel[pixelID]->hPixelEdgeMedian[pulse_order], "Q",1,pulse_order);
635 pulseFits[4] = &edgeMedianPulse;
636
637 Pulse edgeMeanPulse("edgeMeanPulse", pixel[pixelID]->hPixelEdgeMean[pulse_order], "Q",1,pulse_order);
638 pulseFits[5] = &edgeMeanPulse;
639
640
641 //--------------------------------------------------------
642 //Write parameters from pulse fit to CSV
643
644 for (int i = 0; i < 6; i++)
645 {
646 PixelModelCsv.WritePulseAttributes(
647 pixel[pixelID],
648 pulseFits[i],
649 "Edge_pix",
650 pulse_order
651 );
652 }
653 //-------------------------------------
654 // Fill Error Histogramms
655 //-------------------------------------
656
657 for (int i = pixel[pixelID]->hPixelEdgeMedian[pulse_order]->GetXaxis()->GetFirst();
658 i <= pixel[pixelID]->hPixelEdgeMedian[pulse_order]->GetXaxis()->GetLast();
659 i++)
660 {
661
662 hMedianErrors[pulse_order].SetBinContent(
663 i,
664 pixel[pixelID]->hPixelEdgeMedian[pulse_order]->GetBinError(i)
665 );
666
667 hMeanErrors[pulse_order].SetBinContent(
668 i,
669 pixel[pixelID]->hPixelEdgeMean[pulse_order]->GetBinError(i)
670 );
671
672 hMaxErrors[pulse_order].SetBinContent(
673 i,
674 pixel[pixelID]->hPixelEdgeMax[pulse_order]->GetBinError(i)
675 );
676 }
677
678 if (ProduceGraphic && debugPixel)
679 {
680 int current_order = 0;
681 pulses.cd(1);
682 hMaxErrors[current_order].Draw();
683
684 pulses.cd(2);
685 hMedianErrors[current_order].Draw();
686
687 pulses.cd(3);
688 hMeanErrors[current_order].Draw();
689 pulses.Update();
690 }
691
692 //-------------------------------------
693 // Fill Distribution Histogramms
694 //-------------------------------------
695
696 hBsl[pulse_order].Fill( edgeMedianPulse.GetBsl() );
697 hAsymptote[pulse_order].Fill( edgeMedianPulse.GetHeight() );
698 hT0[pulse_order].Fill( edgeMedianPulse.GetT0() );
699 hTau1[pulse_order].Fill( edgeMedianPulse.GetTau1() );
700 hTau2[pulse_order].Fill( edgeMedianPulse.GetTau2() );
701 hIntegral[pulse_order].Fill( edgeMedianPulse.GetIntegral());
702 hAmplitude[pulse_order].Fill( edgeMedianPulse.GetAmplitude());
703 hRiseTime[pulse_order].Fill( edgeMedianPulse.GetRiseTime());
704
705 //-------------------------------------
706 // Fill Distribution Graphs
707 //-------------------------------------
708
709 grPheVsAmpl.Set(grPheVsAmpl.GetN()+1);
710 grPheVsIntegral.Set(grPheVsIntegral.GetN()+1);
711
712
713 grPheVsAmpl.SetPoint(
714 grPheVsAmpl.GetN()-1,
715 edgeMedianPulse.GetPhE(),
716 edgeMedianPulse.GetAmplitude()
717 );
718
719 grPheVsAmpl.SetPointError(
720 grPheVsAmpl.GetN()-1,
721 edgeMedianPulse.GetPhEErr(),
722 edgeMedianPulse.GetAmplitudeErr()
723 );
724
725 grPheVsIntegral.SetPoint(
726 grPheVsIntegral.GetN()-1,
727 edgeMedianPulse.GetPhE(),
728 edgeMedianPulse.GetIntegral()
729 );
730
731 grPheVsAmpl.SetPointError(
732 grPheVsIntegral.GetN()-1,
733 edgeMedianPulse.GetPhEErr(),
734 edgeMedianPulse.GetIntegralErr()
735 );
736
737 grPheVsTau2.SetPoint(
738 grPheVsIntegral.GetN()-1,
739 edgeMedianPulse.GetPhE(),
740 edgeMedianPulse.GetTau2()
741 );
742
743 grPheVsTau2.SetPointError(
744 grPheVsIntegral.GetN()-1,
745 edgeMedianPulse.GetPhE(),
746 edgeMedianPulse.GetTau2Err()
747 );
748
749// cgpDistributions[pulse_order].cd(1);
750
751
752// FitMaxPropabilityPuls(
753// pixel[pixelID]->hPixelEdgeMean[pulse_order],
754// verbosityLevel
755// );
756 //-------------------------------------
757 // Fill Histogramms of Camera
758 //-------------------------------------
759
760 wholeCamera->hMaxOverlay[pulse_order]->Add(
761 pixel[pixelID]->hMaxOverlay[pulse_order]
762 );
763
764 wholeCamera->hMaxProfile[pulse_order]->Add(
765 pixel[pixelID]->hMaxProfile[pulse_order]
766 );
767
768 wholeCamera->hEdgeOverlay[pulse_order]->Add(
769 pixel[pixelID]->hEdgeOverlay[pulse_order]
770 );
771
772 wholeCamera->hEdgeProfile[pulse_order]->Add(
773 pixel[pixelID]->hEdgeProfile[pulse_order]
774 );
775
776 //-------------------------------------
777 // Comparisons
778 //-------------------------------------
779
780 //chi2 test
781// float chi2 =
782// pixel[pixelID]->hPixelEdgeMean[pulse_order]->Chi2Test(
783// pixel[pixelID]->hPixelMean[pulse_order],
784// "UUPCHI2"
785// );
786// cout << "p-Value :" << chi2 << endl;
787// wholeCamera->hChi2EdgetoMax[pulse_order]->Fill(chi2);
788// cgpDistributions[pulse_order]->cd();
789// wholeCamera->hChi2EdgetoMax[pulse_order]->Draw();
790
791 if (verbosityLevel > 2)
792 {
793 cout << endl
794 << "...End of pulseorder "
795 << pulse_order
796 << endl;
797 }
798
799 }
800 // End of Loop over pulsorder of current Pixel
801
802 if (ProduceGraphic && debugPixel)
803 {
804 UpdateCanvases(
805 verbosityLevel,
806 MAX_PULS_ORDER,
807 false
808 );
809 }
810
811 if (debugPixel)
812 {
813 //Process gui events asynchronously during input
814 cout << endl;
815 TTimer timer("gSystem->ProcessEvents();", 50, kFALSE);
816 timer.TurnOn();
817 TString input = Getline("Type 'q' to exit, Type 's' to exit set, <return> to go on: ");
818 timer.TurnOff();
819 if (input=="q\n")
820 {
821 return(0);
822 }
823 if (input=="s\n")
824 {
825 break;
826 }
827 }
828
829 if ( saveResults )
830 {
831 pixel[pixelID]->SavePixelHistograms(
832 outFile,
833 saveResults
834 );
835 }
836
837 //deleteCurrent Pixel from Heap
838 delete pixel[pixelID];
839 pixel[pixelID] = NULL;
840
841 if (verbosityLevel > 2)
842 {
843 cout << endl
844 << "...End of Pixel"
845 << endl
846 << "------------------------------------------------"
847 << endl;
848 }
849 }
850 // End of Loop over all Pixels of set
851
852 if (verbosityLevel > 1)
853 {
854 cout << endl
855 << "...End of Loop over all Pixels of set"
856 << endl
857 << "------------------------------------------------"
858 << endl;
859 }
860 }
861 // End of Loop over all Pixelsets
862
863 if (verbosityLevel > 0)
864 {
865 cout << endl
866 << "...End of Loop over all Pixelsets"
867 << endl
868 << "------------------------------------------------"
869 << endl;
870 }
871
872 delete[] pixel;
873 pixel = NULL;
874
875//-------------------------------------
876// Draw All Pixel Histograms
877//-------------------------------------
878
879 for ( int pulse_order = 0 ;
880 pulse_order < wholeCamera->mMaxPulseOrder ;
881 pulse_order ++)
882 {
883 if (verbosityLevel > 2)
884 {
885 cout << "-------------------------------------"
886 << endl
887 << "...processing Pulse-Order: "
888 << pulse_order;
889 }
890
891// Calculate Max Prop. Value of each slice
892//-------------------------------------
893
894 //from Maximum Overlay
895 ExtractPulseTemplate(
896 wholeCamera,
897 "Maximum",
898 pulse_order,
899 10,
900 verbosityLevel
901 );
902 if ( saveResults )
903 {
904 WritePixelTemplateToCsv(
905 wholeCamera,
906 OutPutPath,
907 "Maximum",
908 pulse_order,
909 verbosityLevel
910 );
911 }
912
913 //from Edge Overlay
914 ExtractPulseTemplate(
915 wholeCamera,
916 "Edge",
917 pulse_order,
918 10,
919 verbosityLevel
920 );
921 if ( saveResults )
922 {
923 WritePixelTemplateToCsv(
924 wholeCamera,
925 OutPutPath,
926 "Edge",
927 pulse_order,
928 verbosityLevel
929 );
930 }
931
932 if (ProduceGraphic)
933 {
934 wholeCamera->DrawTemplateHistograms(
935 cgpPixelPulses,
936 PixelCanvasFrameNrs
937 );
938
939 wholeCamera->DrawEdgeTemplateHistograms(
940 cgpPixelPulses,
941 PixelCanvasFrameNrs
942 );
943 }
944
945 ShiftStartOfHistoInXTo(
946 wholeCamera->hEdgeOverlay[0],
947 0
948 );
949
950 ShiftStartOfHistoInXTo(
951 wholeCamera->hMaxOverlay[0],
952 0
953 );
954
955 // =======================================================
956 // Fit of pulse function to template
957
958 Pulse* allPulseFits[6];
959
960 pulses.cd(1);
961 Pulse maxCamMaxPulse("maxMaxPulse", wholeCamera->hPixelMax[pulse_order], "Q", 1);
962 allPulseFits[0] = &maxCamMaxPulse;
963
964 pulses.cd(2);
965 Pulse maxCamMedianPulse("maxMedianPulse", wholeCamera->hPixelMedian[pulse_order], "Q", 1);
966 allPulseFits[1] = &maxCamMedianPulse;
967
968 pulses.cd(3);
969 Pulse maxCamMeanPulse("maxMeanPulse", wholeCamera->hPixelMean[pulse_order],"Q", 1);
970 allPulseFits[2] = &maxCamMeanPulse;
971
972 Pulse edgeCamMaxPulse("edgeMaxPulse", wholeCamera->hPixelEdgeMax[pulse_order], "Q", 1);
973 allPulseFits[3] = &edgeCamMaxPulse;
974
975 Pulse edgeCamMedianPulse("edgeMedianPulse", wholeCamera->hPixelEdgeMedian[pulse_order],"Q", 1);
976 allPulseFits[4] = &edgeCamMedianPulse;
977
978 Pulse edgeCamMeanPulse("edgeMeanPulse", wholeCamera->hPixelEdgeMean[pulse_order], "Q", 1);
979 allPulseFits[5] = &edgeCamMeanPulse;
980
981
982 //--------------------------------------------------------
983 //Write parameters from pulse fit to CSV
984
985 for (int i = 0; i < 6; i++)
986 {
987 PixelModelCsv.WritePulseAttributes(
988 wholeCamera,
989 allPulseFits[i],
990 "Edge",
991 pulse_order
992 );
993 }
994 } //EOF: Draw All Pixel Histograms
995
996
997 //-------------------------------------
998 // Draw Parameter Distributions
999 //-------------------------------------
1000
1001 if (ProduceGraphic)
1002 {
1003 cgpGraphs->cd(1);
1004
1005 if (verbosityLevel > 0) cout << "...drawing grPheVsAmpl" << endl;
1006 grPheVsAmpl.Draw("AP");
1007
1008 cgpGraphs->cd(2);
1009 if (verbosityLevel > 0) cout << "...drawing grPheVsIntegral" << endl;
1010 grPheVsIntegral.Draw("AP");
1011
1012 cgpGraphs->cd(3);
1013 if (verbosityLevel > 0) cout << "...drawing grPheVsTau2" << endl;
1014 grPheVsTau2.Draw("AP");
1015
1016 cgpGraphs->Update();
1017
1018 for (int i = 0; i < maxPulseOrder; i++){
1019 cgpDistributions[i]->Divide(4,2);
1020
1021 cgpDistributions[i]->cd(1);
1022 hBsl[i].Draw();
1023 cgpDistributions[i]->cd(2);
1024 hAsymptote[i].Draw();
1025 cgpDistributions[i]->cd(3);
1026 hT0[i].Draw();
1027 cgpDistributions[i]->cd(4);
1028 hTau1[i].Draw();
1029 cgpDistributions[i]->cd(5);
1030 hTau2[i].Draw();
1031 cgpDistributions[i]->cd(6);
1032 hIntegral[i].Draw();
1033 cgpDistributions[i]->cd(7);
1034 hAmplitude[i].Draw();
1035 cgpDistributions[i]->cd(8);
1036 hRiseTime[i].Draw();
1037
1038
1039
1040 }
1041
1042
1043
1044
1045
1046 }
1047
1048
1049
1050
1051
1052
1053
1054//-------------------------------------
1055// Save All Pixel Histograms
1056//-------------------------------------
1057 if ( saveResults )
1058 {
1059 wholeCamera->SavePixelHistograms(
1060 outFile,
1061 saveResults
1062 );
1063 }
1064
1065 if (ProduceGraphic)
1066 {
1067 UpdateCanvases(
1068 verbosityLevel,
1069 MAX_PULS_ORDER,
1070 false
1071 );
1072
1073 //Process gui events asynchronously during input
1074 cout << endl;
1075 TTimer timer("gSystem->ProcessEvents();", 50, kFALSE);
1076 timer.TurnOn();
1077 TString input = Getline("press <return> to exit: ");
1078 timer.TurnOff();
1079 cout << input ;
1080 }
1081
1082//-------------------------------------
1083// Delete Objects on Heap
1084//-------------------------------------
1085 delete wholeCamera;
1086 if (ProduceGraphic)
1087 {
1088 DeletePixelCanvases( maxPulseOrder ,verbosityLevel );
1089 }
1090 delete inputRootFile;
1091 delete outputRootFile;
1092
1093 return( 0 );
1094}
1095//----------------------------------------------------------------------------
1096// end of main function
1097//-----------------------------------------------------------------------------
1098
1099
1100
1101
1102//-----------------------------------------------------------------------------
1103// Funktions
1104//-----------------------------------------------------------------------------
1105void
1106DeletePixelCanvases(
1107 int maxPulseOrder,
1108 int verbosityLevel
1109 )
1110{
1111 if (verbosityLevel > 2)
1112 {
1113 cout << endl
1114 << "...delete pixel Canvases"
1115 << endl;
1116 }
1117
1118 for ( int pulse_order = 0; pulse_order < maxPulseOrder; pulse_order++ )
1119 {
1120 delete cgpPixelPulses[pulse_order];
1121 cgpPixelPulses[pulse_order] = NULL;
1122
1123 delete cgpDistributions[pulse_order];
1124 cgpDistributions[pulse_order] = NULL;
1125 }
1126
1127 delete[] cgpPixelPulses;
1128 cgpPixelPulses = NULL;
1129
1130 delete[] cgpDistributions;
1131 cgpDistributions = NULL;
1132}
1133
1134void
1135UpdateCanvases(
1136 int verbosityLevel,
1137 int max_pulse_order,
1138 bool testmode
1139 )
1140{
1141 if (verbosityLevel > 3)
1142 {
1143 cout << endl << "...updating canvases" << endl;
1144 }
1145 for (int pulse_order = 0; pulse_order < max_pulse_order; pulse_order++)
1146 {
1147 cgpPixelPulses[pulse_order]->Modified();
1148 cgpPixelPulses[pulse_order]->Update();
1149
1150 cgpDistributions[pulse_order]->Modified();
1151 cgpDistributions[pulse_order]->Update();
1152// if ( testmode )
1153// {
1154// cgpTestHistos->Modified();
1155// cgpTestHistos->Update();
1156// }
1157 }
1158}
1159//-----------------------------------------------------------------------------
1160// MAIN Funktion for C compilation
1161//-----------------------------------------------------------------------------
1162
1163int main(int argc,char *argv[])
1164{
1165// Int_t index;
1166 TString test;
1167 TString rcFileName;
1168 TString processType = "template";
1169 bool rcFileNameCmdSet = false;
1170 int verbLevel = 0; // different verbosity levels can be implemented here
1171 bool verbLevelCmdSet = false;
1172 bool save = false;
1173 bool produceGraphic = false;
1174
1175// TString inputRootFile = "test.root";
1176// TString inputPath = "";
1177// TString outputRootFile = "test.root";
1178// TString outPutPath = "";
1179// int firstPixel = 0;
1180// int nPixel = -1;
1181// int pixelSetSize = 40;
1182// int maxOrder = 3;
1183// bool dbgPixel = false;
1184// bool fitdata = false;
1185// bool printStats = false;
1186
1187 // decode arguments
1188 if(argc < 2)
1189 {
1190 printf("no arguements given, using standard arguments\n");
1191 }
1192
1193 // set conditions for functions arguments
1194 for (int i=1;i<argc;i++)
1195 {
1196 test = argv[i];
1197
1198 if (test.Contains("--config-file") || test.Contains("-c"))
1199 {
1200 cout << "RC-File: \"" << argv[i + 1] << "\"" << endl;
1201 rcFileName = argv[i + 1];
1202 rcFileNameCmdSet = true;
1203 continue;
1204 }
1205
1206 if (test.Contains("--verbosity") || test.Contains("-v"))
1207 {
1208 cout << "Verbosity Level: \"" << argv[i + 1] << "\"" << endl;
1209 verbLevel = atoi(argv[i + 1]);
1210 continue;
1211 }
1212
1213 if (test.Contains("--save") || test.Contains("-s"))
1214 {
1215 cout << "will save results" << endl;
1216 save = true;
1217 continue;
1218 }
1219
1220 if (test.Contains("--graphics") || test.Contains("-g"))
1221 {
1222 cout << "will produce graphics" << endl;
1223 produceGraphic = true;
1224 continue;
1225 }
1226 }
1227
1228 // reading rc-File:
1229 if (rcFileNameCmdSet)
1230 {
1231 configfile rcfile( rcFileName, processType );
1232
1233 if (save)
1234 {
1235 rcfile.mSave = save;
1236 }
1237
1238 if (verbLevelCmdSet)
1239 {
1240 rcfile.mVerbLevel = verbLevel;
1241 }
1242
1243 if (produceGraphic)
1244 {
1245 rcfile.mProduceGraphic = produceGraphic;
1246 }
1247
1248 //
1249 FCalcPulseTemplate(
1250 rcfile.mInputFile,
1251 rcfile.mInputPath,
1252 rcfile.mOutputFile,
1253 rcfile.mOutputPath,
1254 rcfile.mFirstPixel,
1255 rcfile.mNumPixel,
1256 rcfile.mPixelSetSize,
1257 rcfile.mMaxOrder,
1258// rcfile.mHistoOptions,
1259 rcfile.mProduceGraphic,
1260 rcfile.mPrintStats,
1261 rcfile.mSave,
1262 rcfile.mDbgPixel,
1263 rcfile.mVerbLevel
1264 );
1265 }
1266 else
1267 {
1268 cout << "user: check if configfile is set correctly in cmd" << endl;
1269 }
1270
1271 return 0;
1272}
1273
1274
Note: See TracBrowser for help on using the repository browser.