source: fact/tools/rootmacros/slicecalculation.C@ 13436

Last change on this file since 13436 was 13427, checked in by Jens Buss, 13 years ago
add fit function
File size: 3.5 KB
Line 
1#include "slicecalculation.h"
2#include <TROOT.h>
3#include <TH1F.h>
4#include <TH2F.h>
5#include <TMath.h>
6
7//compute the median for 1-d histogram h1
8Double_t
9MedianOfH1(
10 TH1* h1,
11 int verbosityLevel
12 )
13{
14 if (verbosityLevel > 4) cout << endl
15 << "...calculating median of given TH1"
16 << endl;
17 Int_t nbins = h1->GetXaxis()->GetNbins();
18 Double_t *x = new Double_t[nbins];
19 Double_t *y = new Double_t[nbins];
20
21 for (Int_t i=0;i<nbins;i++)
22 {
23 x[i] = h1->GetXaxis()->GetBinCenter(i+1);
24 y[i] = h1->GetBinContent(i+1);
25 }
26 Double_t median = TMath::Median(nbins,x,y);
27
28 delete [] x;
29 delete [] y;
30
31 if (verbosityLevel > 4) cout << "...done" << endl;
32 return median;
33}
34
35//compute the median for each slice of a given TH2 histogram
36void
37PlotMedianEachSliceOfPulse(
38 TH2* phInputHistogram,
39 TH1* phOutputHistogram,
40 int fitdata,
41 int verbosityLevel
42 )
43{
44 if (verbosityLevel > 2) cout << endl
45 << "...calculating pulse shape of slice's Median"
46 << endl;
47
48 Int_t nbins = phInputHistogram->GetXaxis()->GetNbins();
49
50 for (Int_t TimeSlice=1;TimeSlice<=nbins;TimeSlice++)
51 {
52 TH1 *hProjection = phInputHistogram->ProjectionY("",TimeSlice,TimeSlice);
53 double median = MedianOfH1(hProjection);
54
55 if (verbosityLevel > 4)
56 printf("Median of Slice %d, Median=%g\n",TimeSlice,median);
57
58 delete hProjection;
59
60 phOutputHistogram->SetBinContent(TimeSlice, median );
61// hAllPixelMedian[pulse_order]->SetBinContent(TimeSlice, median );
62 }
63
64 if (verbosityLevel > 2) cout << "\t...done" << endl;
65
66 if (fitdata)
67 {
68 FitMaxPropabilityPuls(
69 phOutputHistogram,
70 verbosityLevel
71 );
72 }
73}
74
75//compute the mean for each slice of a given TH2 histogram
76void
77PlotMeanEachSliceOfPulse(
78 TH2* phInputHistogram,
79 TH1* phOutputHistogram,
80 int fitdata,
81 int verbosityLevel
82 )
83{
84 if (verbosityLevel > 2) cout << endl
85 << "...calculating pulse shape of slice's mean"
86 << endl;
87
88 Int_t nbins = phInputHistogram->GetXaxis()->GetNbins();
89
90 for (Int_t TimeSlice=1;TimeSlice<=nbins;TimeSlice++)
91 {
92 TH1 *hProjection = phInputHistogram->ProjectionY("",TimeSlice,TimeSlice);
93 double mean = hProjection->GetMean();
94
95 if (verbosityLevel > 4)
96 printf("Mean of Slice %d, mean=%g\n",TimeSlice,median);
97
98 delete hProjection;
99
100 phOutputHistogram->SetBinContent(TimeSlice, mean );
101// hAllPixelMean[pulse_order]->SetBinContent(TimeSlice, mean );
102 }
103
104 if (verbosityLevel > 2) cout << "\t...done" << endl;
105
106 if (fitdata)
107 {
108 FitMaxPropabilityPuls(
109 phOutputHistogram,
110 verbosityLevel
111 );
112 }
113}
114
115//fit a function to the given histogram
116void
117FitMaxPropabilityPuls(
118 TH1* phInputHistogram,
119 float left_border,
120 float right_border,
121 int verbosityLevel
122 )
123 {
124 if (verbosityLevel > 2) cout << "...fit Landau in histograms" ;
125 if (verbosityLevel > 2) cout << "\t...calculating Landaufit" ;
126 phInputHistogram->Fit("landau", "", "", left_border, right_border);
127 if (verbosityLevel > 2) cout << "...done" << endl;
128 }
Note: See TracBrowser for help on using the repository browser.