23 hDebugFile =
new TFile(
"DTMeanTimerFitter.root",
"RECREATE");
31 vector<float> vDriftAndReso;
49 vector<Double_t> factor;
51 factor.push_back(
sqrt(2. / 3.));
52 factor.push_back(
sqrt(2. / 7.));
53 factor.push_back(
sqrt(8. / 7.));
54 factor.push_back(
sqrt(2. / 7.));
55 factor.push_back(
sqrt(8. / 7.));
56 factor.push_back(
sqrt(2. / 3.));
59 vector<Double_t>
mean;
60 vector<Double_t> sigma;
61 vector<Double_t>
count;
63 for (vector<TH1F *>::const_iterator ith = hTMax.begin(); ith != hTMax.end(); ++ith) {
66 edm::LogError(
"DTMeanTimerFitter") <<
"Error when fitting TMax..histogram name" << (*ith)->GetName();
68 vector<float> defvec(6, -1);
75 mean.push_back(funct->GetParameter(1));
76 sigma.push_back(funct->GetParameter(2));
77 count.push_back((*ith)->GetEntries());
80 Double_t tMaxMean = 0.;
81 Double_t wTMaxSum = 0.;
83 Double_t wSigmaSum = 0.;
86 for (
int i = 0;
i <= 5;
i++) {
89 tMaxMean += mean[
i] * (count[
i] / (sigma[
i] * sigma[
i]));
90 wTMaxSum += count[
i] / (sigma[
i] * sigma[
i]);
91 sigmaT += count[
i] * factor[
i] * sigma[
i];
92 wSigmaSum += count[
i];
97 if ((!wTMaxSum) || (!wSigmaSum)) {
98 edm::LogError(
"DTMeanTimerFitter") <<
"Error zero sum of weights..returning default";
99 vector<float> defvec(6, -1);
103 tMaxMean /= wTMaxSum;
107 Double_t vDrift = 2.1 / tMaxMean;
108 Double_t reso = vDrift * sigmaT;
109 vDriftAndReso.push_back(vDrift);
110 vDriftAndReso.push_back(reso);
113 <<
" final TMaxMean=" << tMaxMean <<
" sigma= " << sigmaT <<
" v_d and reso: " << vDrift <<
" " << reso << endl;
116 map<Double_t, TH1F *> hEntries;
117 for (vector<TH1F *>::const_iterator ith = hT0.begin(); ith != hT0.end(); ++ith) {
118 hEntries[(*ith)->GetEntries()] = (*ith);
123 for (map<Double_t, TH1F *>::reverse_iterator iter = hEntries.rbegin(); iter != hEntries.rend(); ++iter) {
126 hT0.push_back(iter->second);
127 else if (counter == 2) {
128 hT0.push_back(iter->second);
134 vector<Double_t> meanT0;
135 vector<Double_t> sigmaT0;
136 vector<Double_t> countT0;
138 for (vector<TH1F *>::const_iterator ith = hT0.begin(); ith != hT0.end(); ++ith) {
142 edm::LogError(
"DTMeanTimerFitter") <<
"Exception when fitting T0..histogram " << (*ith)->GetName();
144 vector<float> defvec(6, -1);
147 TF1 *
f1 = (*ith)->GetFunction(
"gaus");
149 meanT0.push_back(f1->GetParameter(1));
150 sigmaT0.push_back(f1->GetParameter(2));
151 countT0.push_back((*ith)->GetEntries());
154 if (hT0.size() != 6) {
156 for (
int i = 1;
i <= 4;
i++) {
157 vDriftAndReso.push_back(-1);
159 return vDriftAndReso;
162 for (
int it0 = 0; it0 <= 2; it0++) {
163 if ((countT0[it0] > 200) && (countT0[it0 + 1] > 200)) {
164 Double_t deltaT0 = meanT0[it0] - meanT0[it0 + 1];
165 vDriftAndReso.push_back(deltaT0);
167 vDriftAndReso.push_back(999.);
170 if ((countT0[4] > 200) && (countT0[5] > 200)) {
172 Double_t deltaT0MaxEntries = (meanT0[4] - meanT0[5]) / t0Diff;
173 vDriftAndReso.push_back(deltaT0MaxEntries);
175 vDriftAndReso.push_back(999.);
177 for (
int i = 1;
i <= 6;
i++) {
180 vDriftAndReso.push_back(-1);
183 return vDriftAndReso;
188 Double_t peak = (((((histo->GetXaxis())->GetXmax()) - ((histo->GetXaxis())->GetXmin())) / histo->GetNbinsX()) *
189 (histo->GetMaximumBin())) +
190 ((histo->GetXaxis())->GetXmin());
192 LogDebug(
"DTMeanTimerFitter") <<
"Peak " << peak <<
" : "
193 <<
"xmax " << ((histo->GetXaxis())->GetXmax()) <<
" xmin "
194 << ((histo->GetXaxis())->GetXmin()) <<
" nbin " << histo->GetNbinsX()
195 <<
" bin with max " << (histo->GetMaximumBin());
196 Double_t
range = 2. * histo->GetRMS();
199 TF1 *rGaus =
new TF1(
"rGaus",
"gaus", peak - range, peak + range);
200 rGaus->SetMarkerSize();
202 histo->Fit(
"rGaus",
"R");
204 edm::LogError(
"DTMeanTimerFitter") <<
"Exception when fitting TMax..histogram " << histo->GetName()
205 <<
" setting return function pointer to zero";
208 TF1 *
f1 = histo->GetFunction(
"rGaus");
Log< level::Info, true > LogVerbatim
virtual ~DTMeanTimerFitter()
Destructor.
DTMeanTimerFitter(TFile *file)
Constructor.
int GetT0Factor(TH1F *hist)
Log< level::Error, false > LogError
const uint16_t range(const Frame &aFrame)
TF1 * fitTMax(TH1F *histo)
Really do the fit.
static std::atomic< unsigned int > counter
std::vector< float > evaluateVDriftAndReso(const TString &N)
Fit the TMax histos and evaluate VDrift and resolution.