25 hDebugFile =
new TFile(
"DTMeanTimerFitter.root",
"RECREATE");
36 vector<float> vDriftAndReso;
54 vector<Double_t> factor;
56 factor.push_back(
sqrt(2./3.));
57 factor.push_back(
sqrt(2./7.));
58 factor.push_back(
sqrt(8./7.));
59 factor.push_back(
sqrt(2./7.));
60 factor.push_back(
sqrt(8./7.));
61 factor.push_back(
sqrt(2./3.));
65 vector<Double_t>
mean;
66 vector<Double_t> sigma;
67 vector<Double_t>
count;
69 for(vector<TH1F*>::const_iterator ith = hTMax.begin();
70 ith != hTMax.end(); ith++) {
73 edm::LogError(
"DTMeanTimerFitter") <<
"Error when fitting TMax..histogram name" << (*ith)->GetName();
75 vector<float> defvec(6,-1);
82 mean.push_back(funct->GetParameter(1));
83 sigma.push_back(funct->GetParameter(2));
84 count.push_back((*ith)->GetEntries());
90 Double_t wSigmaSum = 0.;
93 for(
int i=0;
i<=5;
i++) {
94 if(count[
i]<200)
continue;
95 tMaxMean += mean[
i]*(count[
i]/(sigma[
i]*sigma[
i]));
96 wTMaxSum += count[
i]/(sigma[
i]*sigma[
i]);
97 sigmaT += count[
i]*factor[
i]*sigma[
i];
98 wSigmaSum += count[
i];
103 if((!wTMaxSum)||(!wSigmaSum)){
104 edm::LogError(
"DTMeanTimerFitter") <<
"Error zero sum of weights..returning default";
105 vector<float> defvec(6,-1);
109 tMaxMean /= wTMaxSum;
113 Double_t vDrift = 2.1 / tMaxMean;
114 Double_t reso = vDrift * sigmaT;
115 vDriftAndReso.push_back(vDrift);
116 vDriftAndReso.push_back(reso);
118 edm::LogVerbatim(
"DTMeanTimerFitter") <<
" final TMaxMean=" << tMaxMean <<
" sigma= " << sigmaT
119 <<
" v_d and reso: " << vDrift <<
" " << reso << endl;
122 map<Double_t,TH1F*> hEntries;
123 for(vector<TH1F*>::const_iterator ith = hT0.begin();
124 ith != hT0.end(); ith++) {
125 hEntries[(*ith)->GetEntries()] = (*ith);
130 for(map<Double_t,TH1F*>::reverse_iterator iter = hEntries.rbegin();
131 iter != hEntries.rend(); iter++) {
133 if (counter==1) hT0.push_back(iter->second);
134 else if (counter==2) {hT0.push_back(iter->second);
break;}
138 vector<Double_t> meanT0;
139 vector<Double_t> sigmaT0;
140 vector<Double_t> countT0;
142 for(vector<TH1F*>::const_iterator ith = hT0.begin();
143 ith != hT0.end(); ith++) {
147 edm::LogError(
"DTMeanTimerFitter") <<
"Exception when fitting T0..histogram " << (*ith)->GetName();
149 vector<float> defvec(6,-1);
152 TF1 *
f1 = (*ith)->GetFunction(
"gaus");
154 meanT0.push_back(f1->GetParameter(1));
155 sigmaT0.push_back(f1->GetParameter(2));
156 countT0.push_back((*ith)->GetEntries());
159 if(hT0.size() != 6) {
161 for(
int i=1;
i<=4;
i++) {
162 vDriftAndReso.push_back(-1);
164 return vDriftAndReso;
167 for(
int it0=0; it0<=2; it0++) {
168 if((countT0[it0] > 200) && (countT0[it0+1] > 200)) {
169 Double_t deltaT0 = meanT0[it0] - meanT0[it0+1];
170 vDriftAndReso.push_back(deltaT0);
173 vDriftAndReso.push_back(999.);
176 if((countT0[4] > 200) && (countT0[5] > 200)) {
178 Double_t deltaT0MaxEntries = (meanT0[4] - meanT0[5])/ t0Diff;
179 vDriftAndReso.push_back(deltaT0MaxEntries);
182 vDriftAndReso.push_back(999.);
185 for(
int i=1;
i<=6;
i++) {
188 vDriftAndReso.push_back(-1);
191 return vDriftAndReso;
198 Double_t peak = (((((histo->GetXaxis())->GetXmax())-((histo->GetXaxis())->GetXmin()))/histo->GetNbinsX())*
199 (histo->GetMaximumBin()))+((histo->GetXaxis())->GetXmin());
201 LogDebug(
"DTMeanTimerFitter") <<
"Peak "<<peak<<
" : "<<
"xmax "<<((histo->GetXaxis())->GetXmax())
202 <<
" xmin "<<((histo->GetXaxis())->GetXmin())
203 <<
" nbin "<<histo->GetNbinsX()
204 <<
" bin with max "<<(histo->GetMaximumBin());
205 Double_t range = 2.*histo->GetRMS();
208 TF1 *rGaus =
new TF1(
"rGaus",
"gaus",peak-range,peak+range);
209 rGaus->SetMarkerSize();
211 histo->Fit(
"rGaus",
"R");
213 edm::LogError(
"DTMeanTimerFitter") <<
"Exception when fitting TMax..histogram " << histo->GetName()
214 <<
" setting return function pointer to zero";
217 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(TString N)
Fit the TMax histos and evaluate VDrift and resolution.