source: fact/tools/rootmacros/PulseTemplates/templateextractors.C@ 14809

Last change on this file since 14809 was 14760, checked in by Jens Buss, 12 years ago
add number of bootstrapp iterations
  • Property svn:executable set to *
File size: 28.8 KB
Line 
1#include <iostream>
2#include <fstream>
3#include <stdlib.h>
4#include <iostream>
5
6#include <TCanvas.h>
7#include <TTimer.h>
8#include <Getline.h>
9
10#include "templateextractors.h"
11
12using namespace std;
13using namespace TMath;
14
15
16void
17CalcMaxPropabilityOfSlice(
18 TH2* inputHisto,
19 TH1* outputHisto,
20 int verbosityLevel
21 )
22{
23 if (verbosityLevel > 2)
24 cout << endl
25 << "...calculating slieces value of max. propability"
26 << endl;
27
28 float sliceMax = 0;
29 TH1D* hTemp = NULL;
30 int nbins = inputHisto->GetXaxis()->GetNbins();
31
32 if (verbosityLevel > 2)
33 cout << "...generating projections" << endl;
34
35 for (Int_t slice = 1; slice <= nbins; slice++)
36 {
37 if (verbosityLevel > 2)
38 cout << "...slice: " << slice;
39
40 //put maximumvalue of every Y-projection of every slice into vector
41 hTemp = inputHisto->ProjectionY( "", slice,slice);
42 sliceMax = hTemp->GetBinCenter( hTemp->GetMaximumBin() );
43
44 if (verbosityLevel > 2)
45 cout << " with max value "
46 << sliceMax << endl;
47
48 outputHisto->SetBinContent(slice, sliceMax );
49 }
50
51 if (verbosityLevel > 2)
52 cout << "\t...done" << endl;
53}
54// end of CalcMaxPropabilityOfSlice
55//----------------------------------------------------------------------------
56
57
58void
59PlotMaxPropabilityPulse(
60 Pixel* CurrentPixel,
61 TString overlayType,
62 int verbosityLevel
63 )
64{
65 if (verbosityLevel > 2) cout << endl
66 << "...calculating pulse shape of max. propability"
67 << endl;
68 TH2F** hInputHistoArray = NULL;
69 TH1F** hOutputHistoArray = NULL;
70
71 if (overlayType.Contains("Edge"))
72 {
73 hInputHistoArray = CurrentPixel->hEdgeOverlay;
74 hOutputHistoArray = CurrentPixel->hPixelEdgeMax;
75
76 }
77 else if (overlayType.Contains("Maximum"))
78 {
79 hInputHistoArray = CurrentPixel->hMaxOverlay;
80 hOutputHistoArray = CurrentPixel->hPixelMax;
81 }
82 else
83 {
84 cout << endl << "Unknown Overlay Method-->aborting" << endl;
85 return;
86 }
87
88 for ( int pulse_order = 0 ;
89 pulse_order < CurrentPixel->mMaxPulseOrder ;
90 pulse_order ++)
91 {
92 if (verbosityLevel > 2) cout << "\t...calculation of "
93 << "pulse order " << pulse_order;
94 // vector max_value_of to number of slices in Overlay Spectra
95 CalcMaxPropabilityOfSlice(
96 hInputHistoArray[pulse_order],
97 hOutputHistoArray[pulse_order],
98 verbosityLevel);
99
100 CalcMaxPropabilityOfSlice(
101 hInputHistoArray[pulse_order],
102 hOutputHistoArray[pulse_order],
103 verbosityLevel);
104 }
105}
106// end of PlotMaxPropabilityPulse
107//----------------------------------------------------------------------------
108
109void
110FitMaxPropabilityPulse(
111 TH1F* inputHisto,
112 int verbosityLevel
113 )
114{
115 if (verbosityLevel > 2) cout << "...fit Landau in histograms" ;
116 if (verbosityLevel > 2) cout << "\t...calculating Landaufit" ;
117 inputHisto->Fit("landau", "", "", -50, 250);
118 if (verbosityLevel > 2) cout << "...done" << endl;
119}
120// end of FitMaxPropabilityPuls
121//----------------------------------------------------------------------------
122
123Double_t MedianOfH1 (
124 TH1* inputHisto
125 )
126{
127 //compute the median for 1-d histogram h1
128 Int_t nbins = inputHisto->GetXaxis()->GetNbins();
129 Double_t *x = new Double_t[nbins];
130 Double_t *y = new Double_t[nbins];
131 for (Int_t i=0;i<nbins;i++) {
132 x[i] = inputHisto->GetXaxis()->GetBinCenter(i+1);
133 y[i] = inputHisto->GetBinContent(i+1);
134 }
135 Double_t median = TMath::Median(nbins,x,y);
136 delete [] x;
137 delete [] y;
138 return median;
139}
140// end of PlotMedianEachSliceOfPulse
141//----------------------------------------------------------------------------
142
143Double_t MedianOfH1withRndSlices (
144 TH1* inputHisto, //histogram from which median will be calculated
145 vector<int>* position //array with random slice numbers
146 )
147{
148 //compute the median for 1-d histogram h1
149 Int_t nbins = inputHisto->GetXaxis()->GetNbins();
150 Double_t *x = new Double_t[nbins];
151 Double_t *y = new Double_t[nbins];
152
153 for (Int_t i=0;i<nbins;i++) {
154 x[i] = inputHisto->GetXaxis()->GetBinCenter(position->at(i) );
155 y[i] = inputHisto->GetBinContent(position->at(i) );
156 }
157 Double_t median = TMath::Median(nbins,x,y);
158 delete [] x;
159 delete [] y;
160 return median;
161}
162// end of PlotMedianEachSliceOfPulse
163//----------------------------------------------------------------------------
164
165int ExtractTH1EnriesToVector (
166 TH1* inputHisto, //histogram from which median will be calculated
167 vector<int>* entries //array with random slice numbers
168 )
169{
170 //compute number of bins in imput histo
171 Int_t nbins = inputHisto->GetXaxis()->GetNbins();
172 int quantity;
173 for (Int_t i=0;i<nbins;i++) {
174 quantity = inputHisto->GetBinContent(i);
175 for (int j = 0; j < quantity; j++){
176 entries->push_back(inputHisto->GetXaxis()->GetBinCenter(i));
177 }
178 }
179 return entries->size();
180}
181// end of PlotMedianEachSliceOfPulse
182//----------------------------------------------------------------------------
183
184void CalculateErrorsWithBootstrapping(TH1* inputHisto, int numIt, double* par, double* parErr)
185{
186// cout << "...calculating errors of " << inputHisto->GetName() << endl;
187 Sample sample;
188 double Mean[numIt];
189 double Median[numIt];
190 double Max[numIt];
191 double parameter[3];
192 double parameterErr[3];
193
194// TCanvas test_canvas;
195// test_canvas.Divide(2,1);
196// test_canvas.cd(1);
197// inputHisto->Draw();
198 for (int i = 0; i < numIt; i++)
199 {
200// test_canvas.cd(2);
201 TH1* tempHisto = (TH1*)inputHisto->Clone("tempHisto");
202// "",
203// "",
204// inputHisto->GetNbinsX(),
205// inputHisto->GetXaxis()->GetBinLowEdge( inputHisto->GetXaxis()->GetFirst() ),
206// inputHisto->GetXaxis()->GetBinUpEdge( inputHisto->GetXaxis()->GetLast() )
207// );
208 tempHisto->Reset();
209 sample.BootstrapTH1(inputHisto, tempHisto);
210
211 Mean[i] = tempHisto->GetMean();
212 Median[i] = MedianOfH1 ( tempHisto );
213
214 Max[i] = tempHisto->GetBinCenter( tempHisto->GetMaximumBin() );
215
216 //improved determination of maximum
217// TF1 gaus("fgaus", "gaus", Max[i]-10, Max[i]+10);
218// tempHisto->Fit("fgaus", "WWQRN0");
219// Max[i] = gaus.GetParameter(1);
220
221
222// sample.SetSeed(sample.GetSeed() + 1);
223
224 /*
225 //Process gui events asynchronously during input
226 tempHisto->Draw();
227 test_canvas.Modified();
228 test_canvas.Update();
229 cout << endl;
230 TTimer timer("gSystem->ProcessEvents();", 50, kFALSE);
231 timer.TurnOn();
232 TString input = Getline("Type 'q' to exit, <return> to go on: ");
233 timer.TurnOff();
234 if (input=="q\n")
235 {
236 return;
237 }
238 */
239
240
241
242 delete tempHisto;
243 }
244
245 parameter[0] = TMath::Mean( numIt, Max);
246 parameterErr[0] = TMath::RMS( numIt, Max);
247 parameter[1] = TMath::Mean( numIt, Median);
248 parameterErr[1] = TMath::RMS( numIt, Median);
249 parameter[2] = TMath::Mean( numIt, Mean);
250 parameterErr[2] = TMath::RMS( numIt, Mean);
251
252 for (int i = 0; i < 3; i++)
253 {
254 if (&par[i] != NULL)
255 {
256 par[i] = parameter[i];
257 }
258 else cout << "par[" << i << "] array to small" << endl;
259 if (&par[i] != NULL)
260 {
261 parErr[i] = parameterErr[i];
262 }
263 else cout << "parErr[" << i << "] array to small" << endl;
264 }
265
266 return;
267}
268
269void
270PlotMedianOfSlice(
271 Pixel* CurrentPixel,
272 TString overlayType,
273 int verbosityLevel
274 )
275{
276 if (verbosityLevel > 2) cout << endl
277 << "...calculating pulse shape of slice's Median"
278 << endl;
279
280 TH2F** hInputHistoArray = NULL;
281 TH1F** hOutputHistoArray = NULL;
282// TH1* hTempHisto = NULL;
283// float median = 0;
284
285 if (overlayType.Contains("Edge"))
286 {
287 hInputHistoArray = CurrentPixel->hEdgeOverlay;
288 hOutputHistoArray = CurrentPixel->hPixelEdgeMean;
289
290 }
291 else if (overlayType.Contains("Maximum"))
292 {
293 hInputHistoArray = CurrentPixel->hMaxOverlay;
294 hOutputHistoArray = CurrentPixel->hPixelMedian;
295 }
296 else
297 {
298 cout << endl << "Unknown Overlay Method-->aborting" << endl;
299 return;
300 }
301
302 for (int pulse_order = 0 ;
303 pulse_order < CurrentPixel->mMaxPulseOrder ;
304 pulse_order ++)
305 {
306 if (verbosityLevel > 2) cout << "\t...calculation of "
307 << "pulse order " << pulse_order;
308
309 MedianOfTH2Slices(
310 hInputHistoArray[pulse_order],
311 hOutputHistoArray[pulse_order],
312 verbosityLevel
313 );
314
315 ErrorMedianOfTH2Slices(
316 hInputHistoArray[pulse_order],
317 hOutputHistoArray[pulse_order],
318 5, //numIterations
319 verbosityLevel
320 );
321
322// Int_t nbins = hInputHistoArray[pulse_order]->GetXaxis()->GetNbins();
323
324// for (Int_t slice=1;slice<=nbins;slice++) {
325
326// hTempHisto = hInputHistoArray[pulse_order]->ProjectionY("",slice,slice);
327// median = MedianOfH1(hTempHisto);
328
329// if (verbosityLevel > 2) printf("Median of Slice %d, Median=%g\n",slice,median);
330
331// hOutputHistoArray[pulse_order]->SetBinContent(slice, median );
332//// delete h1;
333// }
334
335 if (verbosityLevel > 2) cout << "\t...done" << endl;
336 }
337}
338// end of PlotMedianEachSliceOfPulse
339//----------------------------------------------------------------------------
340
341void
342MedianOfTH2Slices(
343 TH2* inputHisto,
344 TH1* outputHisto,
345 int verbosityLevel
346 )
347{
348 Int_t nbins = inputHisto->GetXaxis()->GetNbins();
349 float median = 0;
350
351 for (Int_t slice=1;slice<=nbins;slice++) {
352
353 median = MedianOfH1( inputHisto->ProjectionY("",slice,slice) );
354
355 if (verbosityLevel > 2) printf("Median of Slice %d, Median=%g\n",slice,median);
356
357 outputHisto->SetBinContent(slice, median );
358// delete h1;
359 }
360 return;
361}
362// end of MedianOfTH2Slices
363//----------------------------------------------------------------------------
364
365double
366ErrorMedianOfH1(
367 TH1* inputHisto,
368 int numIterations,
369 int verbosityLevel
370 )
371{
372 if (verbosityLevel > 5) cout << "...calculating errors of median" << endl;
373// float MedianOfSliceMean;
374 double medianRMS = 0;
375
376 int sample_min = inputHisto->GetXaxis()->GetFirst();
377 int sample_max = inputHisto->GetXaxis()->GetLast();
378 int sample_size = inputHisto->GetXaxis()->GetNbins();
379// int sample_size = sample_max - sample_min;
380// cout << "sample_min " << sample_min
381// << ", sample_max " << sample_max
382// << ", sample_size " << sample_size
383// << endl;
384 double median[numIterations];
385 vector<int> rndList;
386 Sample sample(sample_size);
387
388 for (int i = 0; i < numIterations; i++)
389 {
390 sample.SetSeed(sample.GetSeed() + 1);
391 sample.BootstrapSample(&rndList, sample_min, sample_max, sample_size);
392 median[i] = MedianOfH1withRndSlices(
393 inputHisto,
394 &rndList
395 );
396 }
397
398// MedianOfSliceMean = TMath::Mean(numIterations, median);
399 medianRMS = RMS(numIterations, median);
400// if (verbosityLevel > 2) printf("Mean Median=%g\n",MedianOfSliceMean);
401 if (verbosityLevel > 5) printf("medianRMS=%g\n",medianRMS);
402
403 return medianRMS;
404}
405
406void
407ErrorMedianOfTH2Slices(
408 TH2* inputHisto,
409 TH1* outputHisto,
410 int numIterations,
411 int verbosityLevel
412 )
413{
414 if (verbosityLevel > 2) cout << "...calculating errors of median" << endl;
415 Int_t nbins = inputHisto->GetXaxis()->GetNbins();
416 cout << "nbins " << nbins << endl;
417 float MedianOfSliceMean[nbins];
418 float MedianOfSliceRMS[nbins];
419 float median[numIterations];
420 vector<int> rndList;
421// rndList->clear();
422
423 TH1 *htemp = NULL;
424
425 for (Int_t slice=1;slice<=nbins;slice++) {
426 htemp = inputHisto->ProjectionY("",slice,slice);
427
428
429 int sample_min = htemp->GetXaxis()->GetFirst();
430 int sample_max = htemp->GetXaxis()->GetLast();
431 int sample_size = htemp->GetXaxis()->GetNbins();
432
433// cout << "sample_min " << sample_min
434// << ", sample_max " << sample_max
435// << ", sample_size " << sample_size
436// << endl;
437
438 Sample sample(sample_size);
439 for (int i = 0; i < numIterations; i++)
440 {
441 sample.SetSeed(sample.GetSeed() + 1);
442 sample.BootstrapSample(&rndList, sample_min, sample_max, sample_size);
443 median[i] = MedianOfH1withRndSlices(
444 htemp,
445 &rndList
446 );
447
448 }
449 MedianOfSliceMean[slice] = TMath::Mean(numIterations, median);
450 MedianOfSliceRMS[slice] = TMath::RMS(numIterations, median);
451 outputHisto->SetBinError(slice, MedianOfSliceRMS[slice]);
452// outputHisto->SetBinError(slice, RMS(numIterations, median) );
453 if (verbosityLevel > 2) printf("Mean Median of Slice %d, Mean Median=%g\n",slice,MedianOfSliceMean[slice]);
454 if (verbosityLevel > 2) printf("RMS of Median of Slice %d, MedianRMS=%g\n",slice,MedianOfSliceRMS[slice]);
455// outputHisto->SetBinContent(slice, median );
456// delete h1;
457 }
458 return;
459}
460// end of ErrorMedianOfTH2Slices
461//----------------------------------------------------------------------------
462
463void
464PlotMeanOfSlice(
465 Pixel* CurrentPixel,
466 TString overlayType,
467 int verbosityLevel
468 )
469{
470 if (verbosityLevel > 2) cout << endl
471 << "...calculating pulse shape of slice's Mean"
472 << endl;
473
474 TH2F** hInputHistoArray = NULL;
475 TH1F** hOutputHistoArray = NULL;
476 TH1* hTempHisto = NULL;
477 float mean = 0;
478
479 if (overlayType.Contains("Edge"))
480 {
481 hInputHistoArray = CurrentPixel->hEdgeOverlay;
482 hOutputHistoArray = CurrentPixel->hPixelEdgeMean;
483
484 }
485 else if (overlayType.Contains("Maximum"))
486 {
487 hInputHistoArray = CurrentPixel->hMaxOverlay;
488 hOutputHistoArray = CurrentPixel->hPixelMean;
489 }
490 else
491 {
492 cout << endl << "Unknown Overlay Method-->aborting" << endl;
493 return;
494 }
495
496 for (int pulse_order = 0 ;
497 pulse_order < CurrentPixel->mMaxPulseOrder ;
498 pulse_order ++)
499 {
500 if (verbosityLevel > 2) cout << "\t...calculation of "
501 << "pulse order " << pulse_order;
502
503 Int_t nbins = hInputHistoArray[pulse_order]->GetXaxis()->GetNbins();
504
505 for (Int_t slice=1;slice<=nbins;slice++) {
506
507 hTempHisto = hInputHistoArray[pulse_order]->ProjectionY("",slice,slice);
508 mean = hTempHisto->GetMean();
509
510 if (verbosityLevel > 2) printf("Mean of Slice %d, Mean=%g\n",slice,mean);
511
512 hOutputHistoArray[pulse_order]->SetBinContent(slice, mean );
513// delete h1;
514 }
515
516 if (verbosityLevel > 2) cout << "\t...done" << endl;
517 }
518}
519// end of CalcMeanOfSlice
520//----------------------------------------------------------------------------
521
522void
523ExtractPulseTemplate(
524 Pixel* CurrentPixel,
525 TString overlayType,
526 int pulse_order,
527 int numBootstrapIt,// = 10, //number of iterations for bootstrapping
528 int verbosityLevel
529 )
530{
531 if (verbosityLevel > 2) cout << endl
532 << "...calculating pulse shape"
533 << " of max. propability"
534 << " of "
535 << overlayType
536 << " Overlay"
537 << endl;
538 TH2F* hInputHisto = NULL;
539 TH1F* hOutputMaxHisto = NULL;
540 TH1F* hOutputMeanHisto = NULL;
541 TH1F* hOutputMedianHisto = NULL;
542 TH1* hTempHisto = NULL;
543 float max_prop = 0;
544 float median = 0;
545 float mean = 0;
546 float max_prop_err = 0;
547 float median_err = 0;
548 float mean_err = 0;
549
550 if (verbosityLevel > 3)
551 {
552 cout << "...setting pointers to histogramm arrays ";
553 cout << " for " << overlayType << "Overlay" << endl;
554 }
555 if (overlayType.Contains("Edge"))
556 {
557 hInputHisto = (CurrentPixel->hEdgeOverlay[pulse_order]);
558
559 //Maximum Propability of Slices
560 hOutputMaxHisto = (CurrentPixel->hPixelEdgeMax[pulse_order]);
561
562 //Mean of Slices
563 hOutputMeanHisto = (CurrentPixel->hPixelEdgeMean[pulse_order]);
564
565 //Median of Slices
566 hOutputMedianHisto = (CurrentPixel->hPixelEdgeMedian[pulse_order]);
567 }
568 else if (overlayType.Contains("Maximum"))
569 {
570 hInputHisto = (CurrentPixel->hMaxOverlay[pulse_order]);
571
572 //Maximum Propability of Slices
573 hOutputMaxHisto = (CurrentPixel->hPixelMax[pulse_order]);
574
575 //Mean of Slices
576 hOutputMeanHisto = (CurrentPixel->hPixelMean[pulse_order]);
577
578 //Median of Slices
579 hOutputMedianHisto = (CurrentPixel->hPixelMedian[pulse_order]);
580 }
581 else
582 {
583 cout << endl << overlayType << "Unknown Overlay Method-->aborting" << endl;
584 return;
585 }
586 if (verbosityLevel > 3)
587 {
588 cout << "...done " << endl;
589 }
590
591 if (verbosityLevel > 2)
592 {
593 cout << "\t...calculation of "
594 << "pulse order " << pulse_order << endl;
595 }
596
597// if (verbosityLevel > 2) cout << "\t...# slices processed " << nbins << endl;
598
599 int slice_min = hInputHisto->GetXaxis()->GetFirst();
600 int slice_max = hInputHisto->GetXaxis()->GetLast();
601
602 for (Int_t slice=slice_min;slice<=slice_max;slice++)
603 {
604
605 hTempHisto = hInputHisto->ProjectionY("",slice,slice);
606
607 //containers for errors
608 double slMean[3];
609 double slError[3];
610
611 //calculate Errors with bootstrapping
612 CalculateErrorsWithBootstrapping(hTempHisto, numBootstrapIt, slMean, slError);
613
614 if (verbosityLevel > 3)
615 {
616 cout << "\t\t...calculating maxProb of slice " << slice << endl;
617 }
618
619 //Get maximum of slice's distribution
620// max_prop = hTempHisto->GetBinCenter( hTempHisto->GetMaximumBin() );
621 max_prop = slMean[0];
622
623 //improve result by< fitting gaussian to slices distribution
624// TF1 gaus("fgaus", "gaus", max_prop-30, max_prop+30);
625// hTempHisto->Fit("fgaus", "QRN0");
626// max_prop = gaus.GetParameter(1);
627
628 //calculate error of max prop
629// max_prop_err = gaus.GetParameter(2); //RMS of gaus fit of slices distribution
630 max_prop_err = slError[0]; //error calculated with bootstrapping
631// max_prop_err = hTempHisto->GetRMS(); //RMS of slice
632
633 if (verbosityLevel > 3)
634 {
635 cout << "\t\t...calculating Median of slice " << slice << endl;
636 }
637// median = MedianOfH1(hTempHisto);
638 median = slMean[1];
639 median_err = slError[1]; //error from bootstraping
640
641 if (verbosityLevel > 3) cout << "\t\t...calculating Mean of slice " << slice << endl;
642
643
644// mean = hTempHisto->GetMean();
645 mean = slMean[2];
646// mean_err = hTempHisto->GetRMS()/hTempHisto->GetEntries(); //RMS of slice
647 mean_err = slError[2]; //error from bootstraping
648
649 if (verbosityLevel > 4) cout << "\t\t\t\t MaxProb of Slice " << slice << ": " << max_prop << endl;
650 hOutputMaxHisto->SetBinContent(slice, max_prop );
651 hOutputMaxHisto->SetBinError( slice, max_prop_err);
652
653 if (verbosityLevel > 4) cout << "\t\t\t\t Mean of Slice " << slice << ": " << mean << endl;
654 hOutputMeanHisto->SetBinContent(slice, mean );
655 hOutputMeanHisto->SetBinError( slice, mean_err);
656
657 if (verbosityLevel > 4) cout << "\t\t\t\t Median of Slice " << slice << ": " << median << endl;
658 hOutputMedianHisto->SetBinContent( slice, median );
659 hOutputMedianHisto->SetBinError( slice, median_err);
660 delete hTempHisto;
661
662 }//Loop over slices
663
664// ErrorMedianOfTH2Slices(
665// hInputHisto,
666// hOutputMedianHisto,
667// 100, //numIterations
668// verbosityLevel
669// );
670// hOutputMaxHisto->GetXaxis()->SetLimits(
671// 0,
672// 300
673// );
674
675// hOutputMeanHisto->GetXaxis()->SetLimits(
676// 0,
677// 300
678// );
679
680// hOutputMedianHisto->GetXaxis()->SetLimits(
681// 0,
682// 300
683// );
684
685 ShiftStartOfHistoInXTo(
686 hOutputMaxHisto,
687 0
688 );
689
690 ShiftStartOfHistoInXTo(
691 hOutputMeanHisto,
692 0
693 );
694
695 ShiftStartOfHistoInXTo(
696 hOutputMedianHisto,
697 0
698 );
699
700}
701// end of PlotMaxPropabilityPulse
702//----------------------------------------------------------------------------
703
704bool
705WritePixelTemplateToCsv(
706 Pixel* CurrentPixel,
707 TString path,
708 TString overlayMethod,
709 int order,
710 int verbosityLevel
711 )
712{
713// TSystem this_system();
714// this_system.cd(path);
715// cout << this_system.pwd();
716// this_system.mkdir("CSV");
717 path = CurrentPixel->CsvFileName( path, overlayMethod, order);
718
719 TH1F* Max_histo = NULL;
720 TH1F* Median_histo = NULL;
721 TH1F* Mean_histo = NULL;
722
723 if (overlayMethod.Contains("Maximum"))
724 {
725 Max_histo = CurrentPixel->hPixelMax[order];
726 Median_histo = CurrentPixel->hPixelMedian[order];
727 Mean_histo = CurrentPixel->hPixelMean[order];
728 }
729 else if (overlayMethod.Contains("Edge"))
730 {
731 Max_histo = CurrentPixel->hPixelMax[order];
732 Median_histo = CurrentPixel->hPixelMedian[order];
733 Mean_histo = CurrentPixel->hPixelMean[order];
734 }
735 else
736 {
737 cout << endl << "Unknown Overlay Method-->aborting" << endl;
738 return 1;
739 }
740
741
742 Int_t nbins = Max_histo->GetXaxis()->GetNbins();
743
744 if (verbosityLevel > 2)
745 {
746 cout << "writing point-set to csv file: " ;
747 cout << path << endl;
748 cout << "...opening file" << endl;
749 }
750 if (verbosityLevel > 2) cout << "...number of bins " << nbins << endl;
751 ofstream out;
752 out.open( path );
753 out << "### point-set of a single photon pulse template" << endl;
754 out << "### template determined with pulse overlay at: "
755 << overlayMethod << endl;
756 out << "### Slice's Amplitude determined by calculating the " << endl
757 << "### value of maximum propability of slice -> AmplitudeMax " << endl
758 << "### mean of slice -> AmplitudeMean " << endl
759 << "### median of slice -> AmplitudeMedian " << endl
760 << "### for each slice" << endl;
761 out << "### Pixel number (CHid): " << CurrentPixel->mChid << endl
762 << endl;
763
764 out << "time [slices],AmplitudeMax [mV],AmplitudeMean [mV],AmplitudeMedian [mV]" << endl;
765
766 for (int slice=1;slice<=nbins;slice++)
767 {
768 out << slice << "," ;
769 out << Max_histo->GetBinContent(slice) << ",";
770 out << Mean_histo->GetBinContent(slice) << ",";
771 out << Median_histo->GetBinContent(slice) << endl;
772 }
773 out.close();
774 if (verbosityLevel > 2) cout << "...csv file closed" << endl;
775 return 0;
776}
777
778void
779FitMaxPropabilityPuls(
780 TH1F* hMaximumTemp,
781 int verbosityLevel
782 )
783 {
784 if (verbosityLevel > 2) cout << "...fit Landau in histograms" ;
785 if (verbosityLevel > 2) cout << "\t...calculating Landaufit" ;
786 hMaximumTemp->Fit("landau", "", "", -50, 250);
787 if (verbosityLevel > 2) cout << "...done" << endl;
788 }
789
790//void
791//FitFallingEdge(
792// TString name,
793// TH1F* histo,
794// double xMin,
795// double xMax,
796// double* parameters
797// )
798//{
799// TF1* polExpFit = new TF1(name, PolExp, xMin, xMax, 3 );
800// polExpFit->SetParNames("Pol0", "Slope", "Shift");
801// polExpFit->SetLineColor(kGreen);
802// histo->Fit(polExpFit, "+RWM");
803// polExpFit->GetParameters(parameters);
804//}
805
806//void
807//FitRisingEdge(
808// TString name,
809// TH1F* histo,
810// double xMin,
811// double xMax,
812// double* parameters
813// )
814//{
815// TF1* polExpFit = new TF1(name, NegPolExp, xMin, xMax, 3 );
816// polExpFit->SetParNames("Pol0", "Slope", "Shift");
817// polExpFit->SetLineColor(kRed);
818// histo->Fit(polExpFit, "+RWWM");
819// polExpFit->GetParameters(parameters);
820//}
821
822//double
823//NegPolExp(
824// double* x,
825// double* par
826// )
827//{
828// return par[0]+(-1)*TMath::Exp(par[1]+par[2]*x[0]);
829//}
830
831//double
832//PolExp(
833// double* x,
834// double* par
835// )
836//{
837// return
838//// par[0]+
839// TMath::Exp(par[1]+par[2]*x[0]);
840//}
841
842//double
843//ChargeDiode(
844// double time,
845// double chargeVoltage,
846// double impedance,
847// double capacity
848// )
849//{
850// return chargeVoltage*(1 - TMath::Exp(time/(impedance*capacity)));
851//}
852
853//double
854//UnChargeDiode(
855// double* time,
856// double* chargeVoltage,
857// double* timeConstant
858// )
859//{
860// return chargeVoltage[0]+TMath::Exp(chargeVoltage[1]+timeConstant[2]*time[0]);
861//// return chargeVoltage[0] * (TMath::Exp(time[0]/timeConstant[0]));
862//}
863
864//double
865//template_function(
866// double* input_x,
867// double* par)
868//{
869// double returnval = 0.0;
870
871// // I introduce a few names
872// // double shift = par[0];
873// double bsl = par[0];
874// double beginOfRisingEdge = par[1];
875// double p0RisingEdge = par[6];
876// double p1RisingEdge = par[7];
877// double p2RisingEdge = par[8];
878// double p3RisingEdge = par[9];
879// double endOfRisingEdge = par[2];
880//// double pOFallingEdge = par[3];
881//// double expPar1FallingEdge = par[4];
882//// double expPar1FallingEdge = par[5];
883// /*
884// bool couted_once = false;
885// if not couted_once
886// {
887// couted_once = true;
888// cout << "shift:" << shift << endl;
889// cout << "bsl:" << bsl << endl;
890// cout << "expars:" << endl;
891// cout << "\t factor:" << exppar[0] << endl;
892// cout << "\t tau:" << exppar[1] << endl;
893// cout << "\t t0:" << exppar[2] << endl;
894// cout << "pol3pars:" << endl;
895// cout << "p[0] + x p[1] + x^2 p[2] + x^3 p[3]" << endl;
896// cout << pol3par[0] << "\t" << pol3par[1] << "\t" << pol3par[2] << "\t" << pol3par[3] << endl;
897// cout << "ranges:" << endl;
898// cout << "begin of pol3: " << range[0] << endl;
899// cout << "begin of exp: " << range[1] << endl;
900// }
901// */
902// double x = input_x[0];
903
904// // the baseline is added everywhere.
905// returnval += bsl;
906
907// if ( (x > beginOfRisingEdge) && (x <= endOfRisingEdge) )
908// {
909// // from this point on the pol3 is added
910// returnval += p0RisingEdge;
911// returnval += p1RisingEdge * x;
912// returnval += p2RisingEdge * x*x;
913// returnval += p3RisingEdge * x*x*x;
914// }
915// else if ( x > endOfRisingEdge )
916// {
917// // from this point on the exp-func is added
918//// returnval += exppar[0] * TMath::Exp( exppar[1] * ( x - exppar[2] ) );
919// returnval += PolExp(input_x, par+3);
920// }
921
922// return returnval;
923//}
924
925
926void
927ShiftHistoInX(
928 TH1* histo,
929 float shift
930 )
931{
932 histo->GetXaxis()->SetLimits(
933 histo->GetXaxis()->GetBinLowEdge( histo->GetXaxis()->GetFirst() ) + shift,
934 histo->GetXaxis()->GetBinUpEdge( histo->GetXaxis()->GetLast() ) + shift
935 );
936}
937
938void
939ShiftStartOfHistoInXTo(
940 TH1* histo,
941 float value
942 )
943{
944 float min = histo->GetXaxis()->GetBinLowEdge( histo->GetXaxis()->GetFirst() );
945 float shift = value - min;
946
947 ShiftHistoInX( histo, shift);
948}
Note: See TracBrowser for help on using the repository browser.