23 hDebugFile =
new TFile(
"DTMeanTimerFitter.root",
"RECREATE");
34 vector<float> vDriftAndReso;
52 vector<Double_t> factor;
54 factor.push_back(
sqrt(2./3.));
55 factor.push_back(
sqrt(2./7.));
56 factor.push_back(
sqrt(8./7.));
57 factor.push_back(
sqrt(2./7.));
58 factor.push_back(
sqrt(8./7.));
59 factor.push_back(
sqrt(2./3.));
63 vector<Double_t>
mean;
64 vector<Double_t> sigma;
65 vector<Double_t>
count;
67 for(vector<TH1F*>::const_iterator ith = hTMax.begin();
68 ith != hTMax.end(); ++ith) {
71 edm::LogError(
"DTMeanTimerFitter") <<
"Error when fitting TMax..histogram name" << (*ith)->GetName();
73 vector<float> defvec(6,-1);
80 mean.push_back(funct->GetParameter(1));
81 sigma.push_back(funct->GetParameter(2));
82 count.push_back((*ith)->GetEntries());
88 Double_t wSigmaSum = 0.;
91 for(
int i=0;
i<=5;
i++) {
92 if(count[
i]<200)
continue;
93 tMaxMean += mean[
i]*(count[
i]/(sigma[
i]*sigma[
i]));
94 wTMaxSum += count[
i]/(sigma[
i]*sigma[
i]);
95 sigmaT += count[
i]*factor[
i]*sigma[
i];
96 wSigmaSum += count[
i];
101 if((!wTMaxSum)||(!wSigmaSum)){
102 edm::LogError(
"DTMeanTimerFitter") <<
"Error zero sum of weights..returning default";
103 vector<float> defvec(6,-1);
107 tMaxMean /= wTMaxSum;
111 Double_t vDrift = 2.1 / tMaxMean;
112 Double_t reso = vDrift * sigmaT;
113 vDriftAndReso.push_back(vDrift);
114 vDriftAndReso.push_back(reso);
116 edm::LogVerbatim(
"DTMeanTimerFitter") <<
" final TMaxMean=" << tMaxMean <<
" sigma= " << sigmaT
117 <<
" v_d and reso: " << vDrift <<
" " << reso << endl;
120 map<Double_t,TH1F*> hEntries;
121 for(vector<TH1F*>::const_iterator ith = hT0.begin();
122 ith != hT0.end(); ++ith) {
123 hEntries[(*ith)->GetEntries()] = (*ith);
128 for(map<Double_t,TH1F*>::reverse_iterator iter = hEntries.rbegin();
129 iter != hEntries.rend(); ++iter) {
131 if (counter==1) hT0.push_back(iter->second);
132 else if (counter==2) {hT0.push_back(iter->second);
break;}
136 vector<Double_t> meanT0;
137 vector<Double_t> sigmaT0;
138 vector<Double_t> countT0;
140 for(vector<TH1F*>::const_iterator ith = hT0.begin();
141 ith != hT0.end(); ++ith) {
145 edm::LogError(
"DTMeanTimerFitter") <<
"Exception when fitting T0..histogram " << (*ith)->GetName();
147 vector<float> defvec(6,-1);
150 TF1 *
f1 = (*ith)->GetFunction(
"gaus");
152 meanT0.push_back(f1->GetParameter(1));
153 sigmaT0.push_back(f1->GetParameter(2));
154 countT0.push_back((*ith)->GetEntries());
157 if(hT0.size() != 6) {
159 for(
int i=1;
i<=4;
i++) {
160 vDriftAndReso.push_back(-1);
162 return vDriftAndReso;
165 for(
int it0=0; it0<=2; it0++) {
166 if((countT0[it0] > 200) && (countT0[it0+1] > 200)) {
167 Double_t deltaT0 = meanT0[it0] - meanT0[it0+1];
168 vDriftAndReso.push_back(deltaT0);
171 vDriftAndReso.push_back(999.);
174 if((countT0[4] > 200) && (countT0[5] > 200)) {
176 Double_t deltaT0MaxEntries = (meanT0[4] - meanT0[5])/ t0Diff;
177 vDriftAndReso.push_back(deltaT0MaxEntries);
180 vDriftAndReso.push_back(999.);
183 for(
int i=1;
i<=6;
i++) {
186 vDriftAndReso.push_back(-1);
189 return vDriftAndReso;
196 Double_t peak = (((((histo->GetXaxis())->GetXmax())-((histo->GetXaxis())->GetXmin()))/histo->GetNbinsX())*
197 (histo->GetMaximumBin()))+((histo->GetXaxis())->GetXmin());
199 LogDebug(
"DTMeanTimerFitter") <<
"Peak "<<peak<<
" : "<<
"xmax "<<((histo->GetXaxis())->GetXmax())
200 <<
" xmin "<<((histo->GetXaxis())->GetXmin())
201 <<
" nbin "<<histo->GetNbinsX()
202 <<
" bin with max "<<(histo->GetMaximumBin());
203 Double_t range = 2.*histo->GetRMS();
206 TF1 *rGaus =
new TF1(
"rGaus",
"gaus",peak-range,peak+range);
207 rGaus->SetMarkerSize();
209 histo->Fit(
"rGaus",
"R");
211 edm::LogError(
"DTMeanTimerFitter") <<
"Exception when fitting TMax..histogram " << histo->GetName()
212 <<
" setting return function pointer to zero";
215 TF1 *
f1 = histo->GetFunction(
"rGaus");
virtual ~DTMeanTimerFitter()
Destructor.
DTMeanTimerFitter(TFile *file)
Constructor.
int GetT0Factor(TH1F *hist)
TF1 * fitTMax(TH1F *histo)
Really do the fit.
std::vector< float > evaluateVDriftAndReso(const TString &N)
Fit the TMax histos and evaluate VDrift and resolution.