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

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