CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MuScleFitUtils.cc
Go to the documentation of this file.
1 
5 // Some notes:
6 // - M(Z) after simulation needs to be extracted as a function of |y_Z| in order to be
7 // a better reference point for calibration. In fact, the variation of PDF with y_Z
8 // in production is sizable <---- need to check though.
9 // - ResHalfWidth needs to be optimized - this depends on the level of background.
10 // - Background parametrization still to be worked on, so far only a constant (type=1, and
11 // parameter 2 fixed to 0) works.
12 // - weights have to be assigned to dimuon mass values in regions where different resonances
13 // overlap, and one has to decide which resonance mass to assign the event to - this until
14 // we implement in the fitter a sum of probabilities of an event to belong to different
15 // resonances. The weight has to depend on the mass and has relative cross sections of
16 // Y(1S), 2S, 3S as parameters. Some overlap is also expected in the J/psi-Psi(2S) region
17 // when reconstructing masses with Standalone muons.
18 //
19 // MODS 7/7/08 TD:
20 // - changed parametrization of resolution in Pt: from sigma_pt = a*Pt + b*|eta| to
21 // sigma_pt = (a*Pt + b*|eta|)*Pt
22 // which is more correct (I hope)
23 // - changed parametrization of resolution in cotgth: from sigma_cotgth = f(eta) to f(cotgth)
24 // --------------------------------------------------------------------------------------------
25 
26 #include "MuScleFitUtils.h"
31 #include "TString.h"
32 #include "TFile.h"
33 #include "TTree.h"
34 #include "TCanvas.h"
35 #include "TH2F.h"
36 #include "TF1.h"
37 #include "TF2.h"
38 #include <iostream>
39 #include <fstream>
40 #include <memory> // to use the auto_ptr
41 
42 // Includes the definitions of all the bias and scale functions
43 // These functions are selected in the constructor according
44 // to the input parameters.
46 
47 // To use callgrind for code profiling uncomment also the following define.
48 //#define USE_CALLGRIND
49 #ifdef USE_CALLGRIND
50 #include "valgrind/callgrind.h"
51 #endif
52 
53 // Lorenzian Peak function
54 // -----------------------
55 Double_t lorentzianPeak (Double_t *x, Double_t *par) {
56  return (0.5*par[0]*par[1]/TMath::Pi()) /
57  TMath::Max(1.e-10,(x[0]-par[2])*(x[0]-par[2]) + .25*par[1]*par[1]);
58 }
59 
60 // Gaussian function
61 // -----------------
62 Double_t Gaussian (Double_t *x, Double_t *par) {
63  return par[0]*exp(-0.5*((x[0]-par[1])/par[2])*((x[0]-par[1])/par[2]));
64 }
65 
66 // Array with number of parameters in the fitting functions
67 // (not currently in use)
68 // --------------------------------------------------------
69 //const int nparsResol[2] = {6, 4};
70 //const int nparsScale[13] = {2, 2, 2, 3, 3, 3, 4, 4, 2, 3, 4, 6, 8};
71 //const int nparsBgr[3] = {1, 2, 3};
72 
73 // Quantities used for h-value computation
74 // ---------------------------------------
75 double mzsum;
76 double isum;
77 double f[11][100];
78 double g[11][100];
79 
80 // Lorentzian convoluted with a gaussian:
81 // --------------------------------------
82 TF1 * GL = new TF1 ("GL",
83  "0.5/3.1415926*[0]/(pow(x-[1],2)+pow(0.5*[0],2))*exp(-0.5*pow((x-[2])/[3],2))/([3]*sqrt(6.283185))",
84  0, 1000);
85 
86 TF2 * GL2= new TF2 ("GL2",
87  "0.5/3.1415926*[0]/(pow(x-[1],2)+pow(0.5*[0],2))*exp(-0.5*pow((x-y)/[2],2))/([2]*sqrt(6.283185))",
88  0, 200, 0, 200);
89 
90 // // Lorentzian convoluted with a gaussian over a linear background:
91 // // ---------------------------------------------------------------
92 // TF1 * GLBL = new TF1 ("GLBL",
93 // "0.5/3.1415926*[0]/(pow(x-[1],2)+pow(0.5*[0],2))*exp(-0.5*pow((x-[2])/[3],2))/([3]*sqrt(6.283185))+[4]+[5]*x",
94 // 0, 1000);
95 
96 // // Lorentzian convoluted with a gaussian over an exponential background:
97 // // ---------------------------------------------------------------
98 // TF1 * GLBE = new TF1 ("GLBE",
99 // "0.5/3.1415926*[0]/(pow(x-[1],2)+pow(0.5*[0],2))*exp(-0.5*pow((x-[2])/[3],2))/([3]*sqrt(6.283185))+exp([4]+[5]*x)",
100 // 0, 1000);
101 
102 std::vector<int> MuScleFitUtils::doResolFit;
103 std::vector<int> MuScleFitUtils::doScaleFit;
104 std::vector<int> MuScleFitUtils::doCrossSectionFit;
105 std::vector<int> MuScleFitUtils::doBackgroundFit;
106 
111 
112 bool MuScleFitUtils::duringMinos_ = false;
113 
114 const int MuScleFitUtils::totalResNum = 6;
115 
119 // No error, we take functions from the same group for bias and scale.
128 
130 // const int MuScleFitUtils::backgroundFunctionsRegions = 3;
131 // backgroundFunctionBase * MuScleFitUtils::backgroundFunctionForRegion[MuScleFitUtils::backgroundFunctionsRegions];
132 // backgroundFunctionBase * MuScleFitUtils::backgroundFunction[MuScleFitUtils::totalResNum];
134 std::vector<double> MuScleFitUtils::parBias;
135 std::vector<double> MuScleFitUtils::parSmear;
136 std::vector<double> MuScleFitUtils::parResol;
137 std::vector<double> MuScleFitUtils::parResolStep;
138 std::vector<double> MuScleFitUtils::parResolMin;
139 std::vector<double> MuScleFitUtils::parResolMax;
140 std::vector<double> MuScleFitUtils::parScale;
141 std::vector<double> MuScleFitUtils::parScaleStep;
142 std::vector<double> MuScleFitUtils::parScaleMin;
143 std::vector<double> MuScleFitUtils::parScaleMax;
144 std::vector<double> MuScleFitUtils::parCrossSection;
145 std::vector<double> MuScleFitUtils::parBgr;
146 std::vector<int> MuScleFitUtils::parResolFix;
147 std::vector<int> MuScleFitUtils::parScaleFix;
148 std::vector<int> MuScleFitUtils::parCrossSectionFix;
149 std::vector<int> MuScleFitUtils::parBgrFix;
150 std::vector<int> MuScleFitUtils::parResolOrder;
151 std::vector<int> MuScleFitUtils::parScaleOrder;
152 std::vector<int> MuScleFitUtils::parCrossSectionOrder;
153 std::vector<int> MuScleFitUtils::parBgrOrder;
154 
155 std::vector<int> MuScleFitUtils::resfind;
156 int MuScleFitUtils::debug = 0;
157 
158 bool MuScleFitUtils::ResFound = false;
161 
162 std::vector<std::vector<double> > MuScleFitUtils::parvalue;
163 
164 int MuScleFitUtils::FitStrategy = 1; // Strategy in likelihood fit (1 or 2)
165 bool MuScleFitUtils::speedup = false; // Whether to cut corners (no sim study, fewer histos)
166 
167 std::vector<std::pair<lorentzVector,lorentzVector> > MuScleFitUtils::SavedPair; // Pairs of reconstructed muons making resonances
168 std::vector<std::pair<lorentzVector,lorentzVector> > MuScleFitUtils::ReducedSavedPair; // Pairs of reconstructed muons making resonances inside smaller windows
169 std::vector<std::pair<lorentzVector,lorentzVector> > MuScleFitUtils::genPair; // Pairs of generated muons making resonances
170 std::vector<std::pair<lorentzVector,lorentzVector> > MuScleFitUtils::simPair; // Pairs of simulated muons making resonances
171 
172 // Smearing parameters
173 // -------------------
174 double MuScleFitUtils::x[][10000];
175 
176 // Probability matrices and normalization values
177 // ---------------------------------------------
178 int MuScleFitUtils::nbins = 1000;
179 double MuScleFitUtils::GLZValue[][1001][1001];
180 double MuScleFitUtils::GLZNorm[][1001];
181 double MuScleFitUtils::GLValue[][1001][1001];
182 double MuScleFitUtils::GLNorm[][1001];
184 
185 // Masses and widths from PDG 2006, half widths to be revised
186 // NB in particular, halfwidths have to be made a function of muonType
187 // -------------------------------------------------------------------
188 const double MuScleFitUtils::mMu2 = 0.011163612;
189 const double MuScleFitUtils::muMass = 0.105658;
194 
195 double MuScleFitUtils::ResGamma[] = {2.4952, 0.000020, 0.000032, 0.000054, 0.000317, 0.0000932 };
196 // ATTENTION:
197 // This is left because the values are used by the BackgroundHandler to define the center of the regions windows,
198 // but the values used in the code are read computed using the probability histograms ranges.
199 // The histograms are read after the initialization of the BackgroundHandler (this can be improved so that
200 // the background handler too could use the new values).
201 // At this time the values are consistent.
202 double MuScleFitUtils::ResMinMass[] = {-99, -99, -99, -99, -99, -99};
203 double MuScleFitUtils::ResMass[] = {91.1876, 10.3552, 10.0233, 9.4603, 3.68609, 3.0969};
204 // From Summer08 generator production TWiki: https://twiki.cern.ch/twiki/bin/view/CMS/ProductionSummer2008
205 // - Z->mumu 1.233 nb
206 // - Upsilon3S->mumu 0.82 nb
207 // - Upsilon2S->mumu 6.33 nb
208 // - Upsilon1S->mumu 13.9 nb
209 // - Prompt Psi2S->mumu 2.169 nb
210 // - Prompt J/Psi->mumu 127.2 nb
211 // double MuScleFitUtils::crossSection[] = {1.233, 0.82, 6.33, 13.9, 2.169, 127.2};
212 // double MuScleFitUtils::crossSection[] = {1.233, 2.07, 6.33, 13.9, 2.169, 127.2};
213 
214 unsigned int MuScleFitUtils::loopCounter = 5;
215 
216 // According to the pythia manual, there is only a code for the Upsilon and Upsilon'. It does not distinguish
217 // between Upsilon(2S) and Upsilon(3S)
218 const unsigned int MuScleFitUtils::motherPdgIdArray[] = {23, 100553, 100553, 553, 100443, 443};
219 
220 // double MuScleFitUtils::leftWindowFactor = 1.;
221 // double MuScleFitUtils::rightWindowFactor = 1.;
222 
223 // double MuScleFitUtils::internalLeftWindowFactor = 1.;
224 // double MuScleFitUtils::internalRightWindowFactor = 1.;
225 
226 // int MuScleFitUtils::backgroundWindowEvents_ = 0;
227 // int MuScleFitUtils::resonanceWindowEvents_ = 0;
228 
229 // double MuScleFitUtils::oldEventsOutInRatio_ = 0.;
230 
232 
233 bool MuScleFitUtils::sherpa_ = false;
234 
236 
238 
240 double MuScleFitUtils::minMuonPt_ = 0.;
241 double MuScleFitUtils::maxMuonPt_ = 100000000.;
246 double MuScleFitUtils::deltaPhiMinCut_ = -100.;
247 double MuScleFitUtils::deltaPhiMaxCut_ = 100.;
248 
251 
253 TMinuit * MuScleFitUtils::rminPtr_ = 0;
256 
260 
261 int MuScleFitUtils::iev_ = 0;
263 
264 // Find the best simulated resonance from a vector of simulated muons (SimTracks)
265 // and return its decay muons
266 // ------------------------------------------------------------------------------
267 std::pair<SimTrack,SimTrack> MuScleFitUtils::findBestSimuRes (const std::vector<SimTrack>& simMuons) {
268 
269  std::pair<SimTrack, SimTrack> simMuFromBestRes;
270  double maxprob = -0.1;
271 
272  // Double loop on muons
273  // --------------------
274  for (std::vector<SimTrack>::const_iterator simMu1=simMuons.begin(); simMu1!=simMuons.end(); simMu1++) {
275  for (std::vector<SimTrack>::const_iterator simMu2=simMu1+1; simMu2!=simMuons.end(); simMu2++) {
276  if (((*simMu1).charge()*(*simMu2).charge())>0) {
277  continue; // this also gets rid of simMu1==simMu2...
278  }
279  // Choose the best resonance using its mass. Check Z, Y(3S,2S,1S), Psi(2S), J/Psi in order
280  // ---------------------------------------------------------------------------------------
281  double mcomb = ((*simMu1).momentum()+(*simMu2).momentum()).mass();
282  double Y = ((*simMu1).momentum()+(*simMu2).momentum()).Rapidity();
283  for (int ires=0; ires<6; ires++) {
284  if (resfind[ires]>0) {
285  double prob = massProb( mcomb, Y, ires, 0. );
286  if (prob>maxprob) {
287  simMuFromBestRes.first = (*simMu1);
288  simMuFromBestRes.second = (*simMu2);
289  maxprob = prob;
290  }
291  }
292  }
293  }
294  }
295 
296  // Return most likely combination of muons making a resonance
297  // ----------------------------------------------------------
298  return simMuFromBestRes;
299 }
300 
301 // Find the best reconstructed resonance from a collection of reconstructed muons
302 // (MuonCollection) and return its decay muons
303 // ------------------------------------------------------------------------------
304 std::pair<lorentzVector,lorentzVector> MuScleFitUtils::findBestRecoRes( const std::vector<reco::LeafCandidate>& muons ){
305  // NB this routine returns the resonance, but it also sets the ResFound flag, which
306  // is used in MuScleFit to decide whether to use the event or not.
307  // --------------------------------------------------------------------------------
308  if (debug>0) std::cout << "In findBestRecoRes" << std::endl;
309  ResFound = false;
310  std::pair<lorentzVector, lorentzVector> recMuFromBestRes;
311 
312  // Choose the best resonance using its mass probability
313  // ----------------------------------------------------
314  double maxprob = -0.1;
315  double minDeltaMass = 999999;
316  std::pair<reco::LeafCandidate,reco::LeafCandidate> bestMassMuons;
317  for (std::vector<reco::LeafCandidate>::const_iterator Muon1=muons.begin(); Muon1!=muons.end(); ++Muon1) {
318  //rc2010
319  if (debug>0) std::cout << "muon_1_charge:"<<(*Muon1).charge() << std::endl;
320  for (std::vector<reco::LeafCandidate>::const_iterator Muon2=Muon1+1; Muon2!=muons.end(); ++Muon2) {
321  //rc2010
322  if (debug>0) std::cout << "after_2" << std::endl;
323  if (((*Muon1).charge()*(*Muon2).charge())>0) {
324  continue; // This also gets rid of Muon1==Muon2...
325  }
326  // To allow the selection of ranges at negative and positive eta independently we define two
327  // ranges of eta: (minMuonEtaFirstRange_, maxMuonEtaFirstRange_) and (minMuonEtaSecondRange_, maxMuonEtaSecondRange_).
328  // If the interval selected is simmetric, one only needs to specify the first range. The second has
329  // default values that accept all muons (minMuonEtaSecondRange_ = -100., maxMuonEtaSecondRange_ = 100.).
330  double pt1 = (*Muon1).p4().Pt();
331  double pt2 = (*Muon2).p4().Pt();
332  double eta1 = (*Muon1).p4().Eta();
333  double eta2 = (*Muon2).p4().Eta();
334  if( pt1 >= minMuonPt_ && pt1 < maxMuonPt_ &&
335  pt2 >= minMuonPt_ && pt2 < maxMuonPt_ &&
336  ( (eta1 >= minMuonEtaFirstRange_ && eta1 < maxMuonEtaFirstRange_ &&
337  eta2 >= minMuonEtaFirstRange_ && eta2 < maxMuonEtaFirstRange_) ||
338  (eta1 >= minMuonEtaSecondRange_ && eta1 < maxMuonEtaSecondRange_ &&
339  eta2 >= minMuonEtaSecondRange_ && eta2 < maxMuonEtaSecondRange_) ) ) {
340  double mcomb = ((*Muon1).p4()+(*Muon2).p4()).mass();
341  double Y = ((*Muon1).p4()+(*Muon2).p4()).Rapidity();
342  if (debug>1) {
343  std::cout<<"muon1 "<<(*Muon1).p4().Px()<<", "<<(*Muon1).p4().Py()<<", "<<(*Muon1).p4().Pz()<<", "<<(*Muon1).p4().E()<<std::endl;
344  std::cout<<"muon2 "<<(*Muon2).p4().Px()<<", "<<(*Muon2).p4().Py()<<", "<<(*Muon2).p4().Pz()<<", "<<(*Muon2).p4().E()<<std::endl;
345  std::cout<<"mcomb "<<mcomb<<std::endl;}
346  double massResol = 0.;
347  if( useProbsFile_ ) {
348  massResol = massResolution ((*Muon1).p4(), (*Muon2).p4(), parResol);
349  }
350  double prob = 0;
351  for( int ires=0; ires<6; ires++ ) {
352  if( resfind[ires]>0 ) {
353  if( useProbsFile_ ) {
354  prob = massProb( mcomb, Y, ires, massResol );
355  }
356  if( prob>maxprob ) {
357  if( (*Muon1).charge()<0 ) { // store first the mu minus and then the mu plus
358  recMuFromBestRes.first = (*Muon1).p4();
359  recMuFromBestRes.second = (*Muon2).p4();
360  } else {
361  recMuFromBestRes.first = (*Muon2).p4();
362  recMuFromBestRes.second = (*Muon1).p4();
363  }
364  ResFound = true; // NNBB we accept "resonances" even outside mass bounds
365  maxprob = prob;
366  }
367  // if( ResMass[ires] == 0 ) {
368  // std::cout << "Error: ResMass["<<ires<<"] = " << ResMass[ires] << std::endl;
369  // exit(1);
370  // }
371  double deltaMass = fabs(mcomb-ResMass[ires])/ResMass[ires];
372  if( deltaMass<minDeltaMass ){
373  bestMassMuons = std::make_pair((*Muon1),(*Muon2));
374  minDeltaMass = deltaMass;
375  }
376  }
377  }
378  }
379  }
380  }
381  //If outside mass window (maxprob==0) then take the two muons with best invariant mass
382  //(anyway they will not be used in the likelihood calculation, only to fill plots)
383  if(!maxprob){
384  if(bestMassMuons.first.charge()<0){
385  recMuFromBestRes.first = bestMassMuons.first.p4();
386  recMuFromBestRes.second = bestMassMuons.second.p4();
387  }
388  else{
389  recMuFromBestRes.second = bestMassMuons.first.p4();
390  recMuFromBestRes.first = bestMassMuons.second.p4();
391  }
392  }
393  return recMuFromBestRes;
394 }
395 
396 // Resolution smearing function called to worsen muon Pt resolution at start
397 // -------------------------------------------------------------------------
399 {
400  double pt = muon.Pt();
401  double eta = muon.Eta();
402  double phi = muon.Phi();
403  double E = muon.E();
404 
405  double y[7];
406  for (int i=0; i<SmearType+3; i++) {
407  y[i] = x[i][goodmuon%10000];
408  }
409 
410  // Use the smear function selected in the constructor
411  smearFunction->smear( pt, eta, phi, y, parSmear );
412 
413  if (debug>9) {
414  std::cout << "Smearing Pt,eta,phi = " << pt << " " << eta << " "
415  << phi << "; x = ";
416  for (int i=0; i<SmearType+3; i++) {
417  std::cout << y[i];
418  }
419  std::cout << std::endl;
420  }
421 
422  double ptEtaPhiE[4] = {pt, eta, phi, E};
423  return( fromPtEtaPhiToPxPyPz(ptEtaPhiE) );
424 }
425 
426 // Biasing function called to modify muon Pt scale at the start.
427 // -------------------------------------------------------------
429 {
430  double ptEtaPhiE[4] = {muon.Pt(),muon.Eta(),muon.Phi(),muon.E()};
431 
432  if (MuScleFitUtils::debug>1) std::cout << "pt before bias = " << ptEtaPhiE[0] << std::endl;
433 
434  // Use functors (although not with the () operator)
435  // Note that we always pass pt, eta and phi, but internally only the needed
436  // values are used.
437  // The functors used are takend from the same group used for the scaling
438  // thus the name of the method used is "scale".
439  ptEtaPhiE[0] = biasFunction->scale(ptEtaPhiE[0], ptEtaPhiE[1], ptEtaPhiE[2], chg, MuScleFitUtils::parBias);
440 
441  if (MuScleFitUtils::debug>1) std::cout << "pt after bias = " << ptEtaPhiE[0] << std::endl;
442 
443  return( fromPtEtaPhiToPxPyPz(ptEtaPhiE) );
444 }
445 
446 // Version of applyScale accepting a std::vector<double> of parameters
447 // --------------------------------------------------------------
449  const std::vector<double> & parval, const int chg)
450 {
451  double * p = new double[(int)(parval.size())];
452  // Replaced by auto_ptr, which handles delete at the end
453  // std::auto_ptr<double> p(new double[(int)(parval.size())]);
454  // Removed auto_ptr, check massResolution for an explanation.
455  int id = 0;
456  for (std::vector<double>::const_iterator it=parval.begin(); it!=parval.end(); ++it, ++id) {
457  //(&*p)[id] = *it;
458  // Also ok would be (p.get())[id] = *it;
459  p[id] = *it;
460  }
461  lorentzVector tempScaleVec( applyScale (muon, p, chg) );
462  delete[] p;
463  return tempScaleVec;
464 }
465 
466 // This is called by the likelihood to "taste" different values for additional corrections
467 // ---------------------------------------------------------------------------------------
469  double* parval, const int chg)
470 {
471  double ptEtaPhiE[4] = {muon.Pt(),muon.Eta(),muon.Phi(),muon.E()};
472  int shift = parResol.size();
473 
474  if (MuScleFitUtils::debug>1) std::cout << "pt before scale = " << ptEtaPhiE[0] << std::endl;
475 
476  // the address of parval[shift] is passed as pointer to double. Internally it is used as a normal array, thus:
477  // array[0] = parval[shift], array[1] = parval[shift+1], ...
478  ptEtaPhiE[0] = scaleFunction->scale(ptEtaPhiE[0], ptEtaPhiE[1], ptEtaPhiE[2], chg, &(parval[shift]));
479 
480  if (MuScleFitUtils::debug>1) std::cout << "pt after scale = " << ptEtaPhiE[0] << std::endl;
481 
482  return( fromPtEtaPhiToPxPyPz(ptEtaPhiE) );
483 }
484 
485 // Useful function to convert 4-vector coordinates
486 // -----------------------------------------------
488 {
489  double px = ptEtaPhiE[0]*cos(ptEtaPhiE[2]);
490  double py = ptEtaPhiE[0]*sin(ptEtaPhiE[2]);
491  double tmp = 2*atan(exp(-ptEtaPhiE[1]));
492  double pz = ptEtaPhiE[0]*cos(tmp)/sin(tmp);
493  double E = sqrt(px*px+py*py+pz*pz+muMass*muMass);
494 
495  // lorentzVector corrMu(px,py,pz,E);
496  // To fix memory leaks, this is to be substituted with
497  // std::auto_ptr<lorentzVector> corrMu(new lorentzVector(px, py, pz, E));
498 
499  return lorentzVector(px,py,pz,E);
500 }
501 
502 // Dimuon mass
503 // -----------
505  const lorentzVector& mu2 )
506 {
507  return (mu1+mu2).mass();
508 }
509 
510 // Mass resolution - version accepting a std::vector<double> parval
511 // -----------------------------------------------------------
513  const lorentzVector& mu2,
514  const std::vector<double> & parval )
515 {
516  // double * p = new double[(int)(parval.size())];
517  // Replaced by auto_ptr, which handles delete at the end
518  // --------- //
519  // ATTENTION //
520  // --------- //
521  // auto_ptr calls delete, not delete[] and thus it must
522  // not be used with arrays. There are alternatives see
523  // e.g.: http://www.gotw.ca/gotw/042.htm. The best
524  // alternative seems to be to switch to vector though.
525  // std::auto_ptr<double> p(new double[(int)(parval.size())]);
526 
527  double * p = new double[(int)(parval.size())];
528  std::vector<double>::const_iterator it = parval.begin();
529  int id = 0;
530  for ( ; it!=parval.end(); ++it, ++id) {
531  // (&*p)[id] = *it;
532  p[id] = *it;
533  }
534  double massRes = massResolution (mu1, mu2, p);
535  delete[] p;
536  return massRes;
537 }
538 
557  const lorentzVector& mu2,
558  double* parval )
559 {
560  double mass = (mu1+mu2).mass();
561  double pt1 = mu1.Pt();
562  double phi1 = mu1.Phi();
563  double eta1 = mu1.Eta();
564  double theta1 = 2*atan(exp(-eta1));
565  double pt2 = mu2.Pt();
566  double phi2 = mu2.Phi();
567  double eta2 = mu2.Eta();
568  double theta2 = 2*atan(exp(-eta2));
569 
570  double dmdpt1 = (pt1/std::pow(sin(theta1),2)*sqrt((std::pow(pt2/sin(theta2),2)+mMu2)/(std::pow(pt1/sin(theta1),2)+mMu2))-
571  pt2*(cos(phi1-phi2)+cos(theta1)*cos(theta2)/(sin(theta1)*sin(theta2))))/mass;
572  double dmdpt2 = (pt2/std::pow(sin(theta2),2)*sqrt((std::pow(pt1/sin(theta1),2)+mMu2)/(std::pow(pt2/sin(theta2),2)+mMu2))-
573  pt1*(cos(phi2-phi1)+cos(theta2)*cos(theta1)/(sin(theta2)*sin(theta1))))/mass;
574  double dmdphi1 = pt1*pt2/mass*sin(phi1-phi2);
575  double dmdphi2 = pt2*pt1/mass*sin(phi2-phi1);
576  double dmdcotgth1 = (pt1*pt1*cos(theta1)/sin(theta1)*
577  sqrt((std::pow(pt2/sin(theta2),2)+mMu2)/(std::pow(pt1/sin(theta1),2)+mMu2)) -
578  pt1*pt2*cos(theta2)/sin(theta2))/mass;
579  double dmdcotgth2 = (pt2*pt2*cos(theta2)/sin(theta2)*
580  sqrt((std::pow(pt1/sin(theta1),2)+mMu2)/(std::pow(pt2/sin(theta2),2)+mMu2)) -
581  pt2*pt1*cos(theta1)/sin(theta1))/mass;
582 
583  if( debugMassResol_ ) {
584  massResolComponents.dmdpt1 = dmdpt1;
585  massResolComponents.dmdpt2 = dmdpt2;
586  massResolComponents.dmdphi1 = dmdphi1;
587  massResolComponents.dmdphi2 = dmdphi2;
588  massResolComponents.dmdcotgth1 = dmdcotgth1;
589  massResolComponents.dmdcotgth2 = dmdcotgth2;
590  }
591 
592  // Resolution parameters:
593  // ----------------------
594  double sigma_pt1 = resolutionFunction->sigmaPt( pt1,eta1,parval );
595  double sigma_pt2 = resolutionFunction->sigmaPt( pt2,eta2,parval );
596  double sigma_phi1 = resolutionFunction->sigmaPhi( pt1,eta1,parval );
597  double sigma_phi2 = resolutionFunction->sigmaPhi( pt2,eta2,parval );
598  double sigma_cotgth1 = resolutionFunction->sigmaCotgTh( pt1,eta1,parval );
599  double sigma_cotgth2 = resolutionFunction->sigmaCotgTh( pt2,eta2,parval );
600  double cov_pt1pt2 = resolutionFunction->covPt1Pt2( pt1, eta1, pt2, eta2, parval );
601 
602  // Sigma_Pt is defined as a relative sigmaPt/Pt for this reason we need to
603  // multiply it by pt.
604  double mass_res = sqrt(std::pow(dmdpt1*sigma_pt1*pt1,2)+std::pow(dmdpt2*sigma_pt2*pt2,2)+
605  std::pow(dmdphi1*sigma_phi1,2)+std::pow(dmdphi2*sigma_phi2,2)+
606  std::pow(dmdcotgth1*sigma_cotgth1,2)+std::pow(dmdcotgth2*sigma_cotgth2,2)+
607  2*dmdpt1*dmdpt2*cov_pt1pt2*sigma_pt1*sigma_pt2);
608 
609  if (debug>19) {
610  std::cout << " Pt1=" << pt1 << " phi1=" << phi1 << " cotgth1=" << cos(theta1)/sin(theta1) << " - Pt2=" << pt2
611  << " phi2=" << phi2 << " cotgth2=" << cos(theta2)/sin(theta2) << std::endl;
612  std::cout << " P[0]="
613  << parval[0] << " P[1]=" << parval[1] << "P[2]=" << parval[2] << " P[3]=" << parval[3] << std::endl;
614  std::cout << " Dmdpt1= " << dmdpt1 << " dmdpt2= " << dmdpt2 << " sigma_pt1="
615  << sigma_pt1 << " sigma_pt2=" << sigma_pt2 << std::endl;
616  std::cout << " Dmdphi1= " << dmdphi1 << " dmdphi2= " << dmdphi2 << " sigma_phi1="
617  << sigma_phi1 << " sigma_phi2=" << sigma_phi2 << std::endl;
618  std::cout << " Dmdcotgth1= " << dmdcotgth1 << " dmdcotgth2= " << dmdcotgth2
619  << " sigma_cotgth1="
620  << sigma_cotgth1 << " sigma_cotgth2=" << sigma_cotgth2 << std::endl;
621  std::cout << " Mass resolution (pval) for muons of Pt = " << pt1 << " " << pt2
622  << " : " << mass << " +- " << mass_res << std::endl;
623  }
624 
625  // Debug std::cout
626  // ----------
627  bool didit = false;
628  for (int ires=0; ires<6; ires++) {
629  if (!didit && resfind[ires]>0 && fabs(mass-ResMass[ires])<ResHalfWidth[ires]) {
630  if (mass_res>ResMaxSigma[ires] && counter_resprob<100) {
631  counter_resprob++;
632  LogDebug("MuScleFitUtils") << "RESOLUTION PROBLEM: ires=" << ires << std::endl;
633  didit = true;
634  }
635  }
636  }
637 
638  return mass_res;
639 }
640 
646  const lorentzVector& mu2,
647  const ResolutionFunction & resolFunc )
648 {
649  double mass = (mu1+mu2).mass();
650  double pt1 = mu1.Pt();
651  double phi1 = mu1.Phi();
652  double eta1 = mu1.Eta();
653  double theta1 = 2*atan(exp(-eta1));
654  double pt2 = mu2.Pt();
655  double phi2 = mu2.Phi();
656  double eta2 = mu2.Eta();
657  double theta2 = 2*atan(exp(-eta2));
658 
659  double dmdpt1 = (pt1/std::pow(sin(theta1),2)*sqrt((std::pow(pt2/sin(theta2),2)+mMu2)/(std::pow(pt1/sin(theta1),2)+mMu2))-
660  pt2*(cos(phi1-phi2)+cos(theta1)*cos(theta2)/(sin(theta1)*sin(theta2))))/mass;
661  double dmdpt2 = (pt2/std::pow(sin(theta2),2)*sqrt((std::pow(pt1/sin(theta1),2)+mMu2)/(std::pow(pt2/sin(theta2),2)+mMu2))-
662  pt1*(cos(phi2-phi1)+cos(theta2)*cos(theta1)/(sin(theta2)*sin(theta1))))/mass;
663  double dmdphi1 = pt1*pt2/mass*sin(phi1-phi2);
664  double dmdphi2 = pt2*pt1/mass*sin(phi2-phi1);
665  double dmdcotgth1 = (pt1*pt1*cos(theta1)/sin(theta1)*
666  sqrt((std::pow(pt2/sin(theta2),2)+mMu2)/(std::pow(pt1/sin(theta1),2)+mMu2)) -
667  pt1*pt2*cos(theta2)/sin(theta2))/mass;
668  double dmdcotgth2 = (pt2*pt2*cos(theta2)/sin(theta2)*
669  sqrt((std::pow(pt1/sin(theta1),2)+mMu2)/(std::pow(pt2/sin(theta2),2)+mMu2)) -
670  pt2*pt1*cos(theta1)/sin(theta1))/mass;
671 
672  // Resolution parameters:
673  // ----------------------
674  double sigma_pt1 = resolFunc.sigmaPt( mu1 );
675  double sigma_pt2 = resolFunc.sigmaPt( mu2 );
676  double sigma_phi1 = resolFunc.sigmaPhi( mu1 );
677  double sigma_phi2 = resolFunc.sigmaPhi( mu2 );
678  double sigma_cotgth1 = resolFunc.sigmaCotgTh( mu1 );
679  double sigma_cotgth2 = resolFunc.sigmaCotgTh( mu2 );
680 
681  // Sigma_Pt is defined as a relative sigmaPt/Pt for this reason we need to
682  // multiply it by pt.
683  double mass_res = sqrt(std::pow(dmdpt1*sigma_pt1*pt1,2)+std::pow(dmdpt2*sigma_pt2*pt2,2)+
684  std::pow(dmdphi1*sigma_phi1,2)+std::pow(dmdphi2*sigma_phi2,2)+
685  std::pow(dmdcotgth1*sigma_cotgth1,2)+std::pow(dmdcotgth2*sigma_cotgth2,2));
686 
687  return mass_res;
688 }
689 
690 
691 // Mass probability - version with linear background included, accepts std::vector<double> parval
692 // -----------------------------------------------------------------------------------------
693 double MuScleFitUtils::massProb( const double & mass, const double & resEta, const double & rapidity, const double & massResol, const std::vector<double> & parval, const bool doUseBkgrWindow, const double & eta1, const double & eta2 )
694 {
695 #ifdef USE_CALLGRIND
696  CALLGRIND_START_INSTRUMENTATION;
697 #endif
698 
699  double * p = new double[(int)(parval.size())];
700  // Replaced by auto_ptr, which handles delete at the end
701  // Removed auto_ptr, check massResolution for an explanation.
702  // std::auto_ptr<double> p(new double[(int)(parval.size())]);
703 
704  std::vector<double>::const_iterator it = parval.begin();
705  int id = 0;
706  for ( ; it!=parval.end(); ++it, ++id) {
707  // (&*p)[id] = *it;
708  p[id] = *it;
709  }
710  // p must be passed by value as below:
711  double massProbability = massProb( mass, resEta, rapidity, massResol, p, doUseBkgrWindow, eta1, eta2 );
712  delete[] p;
713 
714 #ifdef USE_CALLGRIND
715  CALLGRIND_STOP_INSTRUMENTATION;
716  CALLGRIND_DUMP_STATS;
717 #endif
718 
719  return massProbability;
720 }
721 
727 double MuScleFitUtils::probability( const double & mass, const double & massResol,
728  const double GLvalue[][1001][1001], const double GLnorm[][1001],
729  const int iRes, const int iY )
730 {
731  if( iRes == 0 && iY > 23 ) {
732  std::cout << "WARNING: rapidity bin selected = " << iY << " but there are only histograms for the first 24 bins" << std::endl;
733  }
734 
735  double PS = 0.;
736  bool insideProbMassWindow = true;
737  // Interpolate the four values of GLZValue[] in the
738  // grid square within which the (mass,sigma) values lay
739  // ----------------------------------------------------
740  // This must be done with respect to the width used in the computation of the probability distribution,
741  // so that the bin 0 really matches the bin 0 of that distribution.
742  // double fracMass = (mass-(ResMass[iRes]-ResHalfWidth[iRes]))/(2*ResHalfWidth[iRes]);
743  double fracMass = (mass - ResMinMass[iRes])/(2*ResHalfWidth[iRes]);
744  if (debug>1) std::cout << std::setprecision(9)<<"mass ResMinMass[iRes] ResHalfWidth[iRes] ResHalfWidth[iRes]"
745  << mass << " "<<ResMinMass[iRes]<<" "<<ResHalfWidth[iRes]<<" "<<ResHalfWidth[iRes]<<std::endl;
746  int iMassLeft = (int)(fracMass*(double)nbins);
747  int iMassRight = iMassLeft+1;
748  double fracMassStep = (double)nbins*(fracMass - (double)iMassLeft/(double)nbins);
749  if (debug>1) std::cout<<"nbins iMassLeft fracMass "<<nbins<<" "<<iMassLeft<<" "<<fracMass<<std::endl;
750 
751  // Simple protections for the time being: the region where we fit should not include
752  // values outside the boundaries set by ResMass-ResHalfWidth : ResMass+ResHalfWidth
753  // ---------------------------------------------------------------------------------
754  if (iMassLeft<0) {
755  edm::LogInfo("probability") << "WARNING: fracMass=" << fracMass << ", iMassLeft="
756  << iMassLeft << "; mass = " << mass << " and bounds are " << ResMinMass[iRes]
757  << ":" << ResMinMass[iRes]+2*ResHalfWidth[iRes] << " - iMassLeft set to 0" << std::endl;
758  iMassLeft = 0;
759  iMassRight = 1;
760  insideProbMassWindow = false;
761  }
762  if (iMassRight>nbins) {
763  edm::LogInfo("probability") << "WARNING: fracMass=" << fracMass << ", iMassRight="
764  << iMassRight << "; mass = " << mass << " and bounds are " << ResMinMass[iRes]
765  << ":" << ResMass[iRes]+2*ResHalfWidth[iRes] << " - iMassRight set to " << nbins-1 << std::endl;
766  iMassLeft = nbins-1;
767  iMassRight = nbins;
768  insideProbMassWindow = false;
769  }
770  double fracSigma = (massResol/ResMaxSigma[iRes]);
771  int iSigmaLeft = (int)(fracSigma*(double)nbins);
772  int iSigmaRight = iSigmaLeft+1;
773  double fracSigmaStep = (double)nbins * (fracSigma - (double)iSigmaLeft/(double)nbins);
774  // std::cout << "massResol = " << massResol << std::endl;
775  // std::cout << "ResMaxSigma["<<iRes<<"] = " << ResMaxSigma[iRes] << std::endl;
776  // std::cout << "fracSigma = " << fracSigma << std::endl;
777  // std::cout << "nbins = " << nbins << std::endl;
778  // std::cout << "ISIGMALEFT = " << iSigmaLeft << std::endl;
779  // std::cout << "ISIGMARIGHT = " << iSigmaRight << std::endl;
780  // std::cout << "fracSigmaStep = " << fracSigmaStep << std::endl;
781 
782  // Simple protections for the time being: they should not affect convergence, since
783  // ResMaxSigma is set to very large values, and if massResol exceeds them the fit
784  // should not get any prize for that (for large sigma, the prob. distr. becomes flat)
785  // ----------------------------------------------------------------------------------
786  if (iSigmaLeft<0) {
787  edm::LogInfo("probability") << "WARNING: fracSigma = " << fracSigma << ", iSigmaLeft="
788  << iSigmaLeft << ", with massResol = " << massResol << " and ResMaxSigma[iRes] = "
789  << ResMaxSigma[iRes] << " - iSigmaLeft set to 0" << std::endl;
790  iSigmaLeft = 0;
791  iSigmaRight = 1;
792  }
793  if (iSigmaRight>nbins ) {
794  if (counter_resprob<100)
795  edm::LogInfo("probability") << "WARNING: fracSigma = " << fracSigma << ", iSigmaRight="
796  << iSigmaRight << ", with massResol = " << massResol << " and ResMaxSigma[iRes] = "
797  << ResMaxSigma[iRes] << " - iSigmaRight set to " << nbins-1 << std::endl;
798  iSigmaLeft = nbins-1;
799  iSigmaRight = nbins;
800  }
801 
802  // If f11,f12,f21,f22 are the values at the four corners, one finds by linear interpolation the
803  // formula below for PS
804  // --------------------------------------------------------------------------------------------
805  if( insideProbMassWindow ) {
806  double f11 = 0.;
807  if (GLnorm[iY][iSigmaLeft]>0)
808  f11 = GLvalue[iY][iMassLeft][iSigmaLeft] / GLnorm[iY][iSigmaLeft];
809  double f12 = 0.;
810  if (GLnorm[iY][iSigmaRight]>0)
811  f12 = GLvalue[iY][iMassLeft][iSigmaRight] / GLnorm[iY][iSigmaRight];
812  double f21 = 0.;
813  if (GLnorm[iY][iSigmaLeft]>0)
814  f21 = GLvalue[iY][iMassRight][iSigmaLeft] / GLnorm[iY][iSigmaLeft];
815  double f22 = 0.;
816  if (GLnorm[iY][iSigmaRight]>0)
817  f22 = GLvalue[iY][iMassRight][iSigmaRight] / GLnorm[iY][iSigmaRight];
818  PS = f11 + (f12-f11)*fracSigmaStep + (f21-f11)*fracMassStep +
819  (f22-f21-f12+f11)*fracMassStep*fracSigmaStep;
820  if (PS>0.1 || debug>1) LogDebug("MuScleFitUtils") << "iRes = " << iRes << " PS=" << PS << " f11,f12,f21,f22="
821  << f11 << " " << f12 << " " << f21 << " " << f22 << " "
822  << " fSS=" << fracSigmaStep << " fMS=" << fracMassStep << " iSL, iSR="
823  << iSigmaLeft << " " << iSigmaRight
824  << " GLvalue["<<iY<<"]["<<iMassLeft<<"] = " << GLvalue[iY][iMassLeft][iSigmaLeft]
825  << " GLnorm["<<iY<<"]["<<iSigmaLeft<<"] = " << GLnorm[iY][iSigmaLeft] << std::endl;
826 
827 // if (PS>0.1) std::cout << "iRes = " << iRes << " PS=" << PS << " f11,f12,f21,f22="
828 // << f11 << " " << f12 << " " << f21 << " " << f22 << " "
829 // << " fSS=" << fracSigmaStep << " fMS=" << fracMassStep << " iSL, iSR="
830 // << iSigmaLeft << " " << iSigmaRight << " GLV,GLN="
831 // << GLvalue[iY][iMassLeft][iSigmaLeft]
832 // << " " << GLnorm[iY][iSigmaLeft] << std::endl;
833 
834  }
835  else {
836  edm::LogInfo("probability") << "outside mass probability window. Setting PS["<<iRes<<"] = 0" << std::endl;
837  }
838 
839 // if( PS != PS ) {
840 // std::cout << "ERROR: PS = " << PS << " for iRes = " << iRes << std::endl;
841 
842 // std::cout << "mass = " << mass << ", massResol = " << massResol << std::endl;
843 // std::cout << "fracMass = " << fracMass << ", iMassLeft = " << iMassLeft
844 // << ", iMassRight = " << iMassRight << ", fracMassStep = " << fracMassStep << std::endl;
845 // std::cout << "fracSigma = " << fracSigma << ", iSigmaLeft = " << iSigmaLeft
846 // << ", iSigmaRight = " << iSigmaRight << ", fracSigmaStep = " << fracSigmaStep << std::endl;
847 // std::cout << "ResMaxSigma["<<iRes<<"] = " << ResMaxSigma[iRes] << std::endl;
848 
849 // std::cout << "GLvalue["<<iY<<"]["<<iMassLeft<<"] = " << GLvalue[iY][iMassLeft][iSigmaLeft]
850 // << " GLnorm["<<iY<<"]["<<iSigmaLeft<<"] = " << GLnorm[iY][iSigmaLeft] << std::endl;
851 // }
852 
853  return PS;
854 }
855 
856 // Mass probability - version with linear background included
857 // ----------------------------------------------------------
858 double MuScleFitUtils::massProb( const double & mass, const double & resEta, const double & rapidity, const double & massResol, double * parval, const bool doUseBkgrWindow, const double & eta1, const double & eta2 ) {
859 
860  // This routine computes the likelihood that a given measured mass "measMass" is
861  // the result of a reference mass ResMass[] if the resolution
862  // expected for the two muons is massResol.
863  // This version includes two parameters (the last two in parval, by default)
864  // to size up the background fraction and its relative normalization with respect
865  // to the signal shape.
866  //
867  // We model the signal probability with a Lorentz L(M,H) of resonance mass M and natural width H
868  // convoluted with a gaussian G(m,s) of measured mass m and expected mass resolution s,
869  // by integrating over the intersection of the supports of L and G (which can be made to coincide with
870  // the region where L is non-zero, given that H<<s in most cases) the product L(M,H)*G(m,s) dx as follows:
871  //
872  // GL(m,s) = Int(M-10H,M+10H) [ L(x-M,H) * G(x-m,s) ] dx
873  //
874  // The above convolution is computed numerically by an independent root macro, Probs.C, which outputs
875  // the values in six 1001x1001 grids, one per resonance.
876  //
877  // NB THe following block of explanations for background models is outdated, see detailed
878  // explanations where the code computes PB.
879  // +++++++++++++++++++++++
880  // For the background, instead, we have two choices: a linear and an exponential model.
881  // * For the linear model, we choose a one-parameter form whereby the line is automatically normalized
882  // in the support [x1,x2] where we defined our "signal region", as follows:
883  //
884  // B(x;b) = 1/(x2-x1) + {x - (x2+x1)/2} * b
885  //
886  // Defined as above, B(x) is a line passing for the point of coordinates (x1+x2)/2, 1/(x2-x1),
887  // whose slope b has as support the interval ( -2/[(x1-x2)*(x1+x2)], 2/[(x1-x2)*(x1+x2)] )
888  // so that B(x) is always positive-definite in [x1,x2].
889  //
890  // * For the exponential model, we define B(x;b) as
891  //
892  // B(x;b) = b * { exp(-b*x) / [exp(-b*x1)-exp(-b*x2)] }
893  //
894  // This one-parameter definition is automatically normalized to unity in [x1,x2], with a parameter
895  // b which has to be positive in order for the slope to be negative.
896  // Please note that this model is not useful in most circumstances; a more useful form would be one
897  // which included a linear component.
898  // ++++++++++++++++++++++
899  //
900  // Once GL(m,s) and B(x;b) are defined, we introduce a further parameter a, such that we can have the
901  // likelihood control the relative fraction of signal and background. We first normalize GL(m,s) for
902  // any given s by taking the integral
903  //
904  // Int(x1,x2) GL(m,s) dm = K_s
905  //
906  // We then define the probability as
907  //
908  // P(m,s,a,b) = GL(m,s)/K_s * a + B(x,b) * (1-a)
909  //
910  // with a taking on values in the interval [0,1].
911  // Defined as above, the probability is well-behaved, in the sense that it has a value between 0 and 1,
912  // and the four parameters m,s,a,b fully control its shape.
913  //
914  // It is to be noted that the formulation above requires the computation of two rather time-consuming
915  // integrals. The one defining GL(m,s) can be stored in a TH2D and loaded by the constructor from a
916  // file suitably prepared, and this will save loads of computing time.
917  // ----------------------------------------------------------------------------------------------------
918 
919  double P = 0.;
920  int crossSectionParShift = parResol.size() + parScale.size();
921  // Take the relative cross sections
922  std::vector<double> relativeCrossSections = crossSectionHandler->relativeCrossSections(&(parval[crossSectionParShift]), resfind);
923  // for( unsigned int i=0; i<relativeCrossSections.size(); ++i ) {
924  // std::cout << "relativeCrossSections["<<i<<"] = " << relativeCrossSections[i] << std::endl;
925  // std::cout << "parval["<<crossSectionParShift+i<<"] = " << parval[crossSectionParShift+i] << std::endl;
926  // }
927 
928  // int bgrParShift = crossSectionParShift + parCrossSection.size();
929  int bgrParShift = crossSectionParShift + crossSectionHandler->parNum();
930  double Bgrp1 = 0.;
931  // double Bgrp2 = 0.;
932  // double Bgrp3 = 0.;
933 
934  // NB defined as below, P is a non-rigorous "probability" that we observe
935  // a dimuon mass "mass", given ResMass[], gamma, and massResol. It is what we need for the
936  // fit which finds the best resolution parameters, though. A definition which is
937  // more properly a probability is given below (in massProb2()), where the result
938  // cannot be used to fit resolution parameters because the fit would always prefer
939  // to set the res parameters to the minimum possible value (best resolution),
940  // to have a probability close to one of observing any mass.
941  // -------------------------------------------------------------------------------
942 
943  // Determine what resonance(s) we have to deal with
944  // NB for now we assume equal xs for each resonance
945  // so we do not assign them different weights
946  // ------------------------------------------------
947  double PS[6] = {0.};
948  double PB = 0.;
949  double PStot[6] = {0.};
950 
951  // Should be removed because it is not used
952  bool resConsidered[6] = {false};
953 
954  bool useBackgroundWindow = (doBackgroundFit[loopCounter] || doUseBkgrWindow);
955  // bool useBackgroundWindow = (doBackgroundFit[loopCounter]);
956 
957  // First check the Z, which is divided in 24 rapidity bins
958  // NB max value of Z rapidity to be considered is 2.4 here
959  // -------------------------------------------------------
960 
961  // Do this only if we want to use the rapidity bins for the Z
963  // ATTENTION: cut on Z rapidity at 2.4 since we only have histograms up to that value
964  // std::pair<double, double> windowFactors = backgroundHandler->windowFactors( useBackgroundWindow, 0 );
965  std::pair<double, double> windowBorders = backgroundHandler->windowBorders( useBackgroundWindow, 0 );
966  if( resfind[0]>0
967  // && checkMassWindow( mass, 0,
968  // backgroundHandler->resMass( useBackgroundWindow, 0 ),
969  // windowFactors.first, windowFactors.second )
970  && checkMassWindow( mass, windowBorders.first, windowBorders.second )
971  // && fabs(rapidity)<2.4
972  ) {
973 
974  int iY = (int)(fabs(rapidity)*10.);
975  if( iY > 23 ) iY = 23;
976 
977  if (MuScleFitUtils::debug>1) std::cout << "massProb:resFound = 0, rapidity bin =" << iY << std::endl;
978 
979  // In this case the last value is the rapidity bin
980  PS[0] = probability(mass, massResol, GLZValue, GLZNorm, 0, iY);
981 
982  if( PS[0] != PS[0] ) {
983  std::cout << "ERROR: PS[0] = nan, setting it to 0" << std::endl;
984  PS[0] = 0;
985  }
986 
987  // std::pair<double, double> bgrResult = backgroundHandler->backgroundFunction( doBackgroundFit[loopCounter],
988  // &(parval[bgrParShift]), MuScleFitUtils::totalResNum, 0,
989  // resConsidered, ResMass, ResHalfWidth, MuonType, mass, resEta );
990 
991  std::pair<double, double> bgrResult = backgroundHandler->backgroundFunction( doBackgroundFit[loopCounter],
992  &(parval[bgrParShift]), MuScleFitUtils::totalResNum, 0,
993  resConsidered, ResMass, ResHalfWidth, MuonType, mass, eta1, eta2 );
994 
995  Bgrp1 = bgrResult.first;
996  // When fitting the background we have only one Bgrp1
997  // When not fitting the background we have many only in a superposition region and this case is treated
998  // separately after this loop
999  PB = bgrResult.second;
1000  if( PB != PB ) PB = 0;
1001  PStot[0] = (1-Bgrp1)*PS[0] + Bgrp1*PB;
1002 
1003  // PStot[0] *= crossSectionHandler->crossSection(0);
1004  // PStot[0] *= parval[crossSectionParShift];
1005  PStot[0] *= relativeCrossSections[0];
1006  // std::cout << "PStot["<<0<<"] = " << "(1-"<<Bgrp1<<")*"<<PS[0]<<" + "<<Bgrp1<<"*"<<PB<<" = " << PStot[0] << std::endl;
1007  }
1008  else {
1009  if( debug > 0 ) {
1010  std::cout << "Mass = " << mass << " outside range with rapidity = " << rapidity << std::endl;
1011  std::cout << "with resMass = " << backgroundHandler->resMass( useBackgroundWindow, 0 ) << " and left border = " << windowBorders.first << " right border = " << windowBorders.second << std::endl;
1012  }
1013  }
1014  }
1015  // Next check the other resonances
1016  // -------------------------------
1017  int firstRes = 1;
1018  if( !MuScleFitUtils::rapidityBinsForZ_ ) firstRes = 0;
1019  for( int ires=firstRes; ires<6; ++ires ) {
1020  if( resfind[ires] > 0 ) {
1021  // First is left, second is right (returns (1,1) in the case of resonances, it could be improved avoiding the call in this case)
1022  // std::pair<double, double> windowFactor = backgroundHandler->windowFactors( useBackgroundWindow, ires );
1023  std::pair<double, double> windowBorder = backgroundHandler->windowBorders( useBackgroundWindow, ires );
1024  if( checkMassWindow(mass, windowBorder.first, windowBorder.second) ) {
1025  if (MuScleFitUtils::debug>1) std::cout << "massProb:resFound = " << ires << std::endl;
1026 
1027  // In this case the rapidity value is instead the resonance index again.
1028  PS[ires] = probability(mass, massResol, GLValue, GLNorm, ires, ires);
1029 
1030  std::pair<double, double> bgrResult = backgroundHandler->backgroundFunction( doBackgroundFit[loopCounter],
1031  &(parval[bgrParShift]), MuScleFitUtils::totalResNum, ires,
1032  // resConsidered, ResMass, ResHalfWidth, MuonType, mass, resEta );
1033  resConsidered, ResMass, ResHalfWidth, MuonType, mass, eta1, eta2 );
1034  Bgrp1 = bgrResult.first;
1035  PB = bgrResult.second;
1036 
1037  if( PB != PB ) PB = 0;
1038  PStot[ires] = (1-Bgrp1)*PS[ires] + Bgrp1*PB;
1039  if( MuScleFitUtils::debug>0 ) std::cout << "PStot["<<ires<<"] = " << "(1-"<<Bgrp1<<")*"<<PS[ires]<<" + "<<Bgrp1<<"*"<<PB<<" = " << PStot[ires] << std::endl;
1040 
1041  PStot[ires] *= relativeCrossSections[ires];
1042  }
1043  }
1044  }
1045 
1046  for( int i=0; i<6; ++i ) {
1047  P += PStot[i];
1048  }
1049 
1051  double PStotTemp = 0.;
1052  for( int i=0; i<6; ++i ) {
1053  PStotTemp += PS[i]*relativeCrossSections[i];
1054  }
1055  if( PStotTemp != PStotTemp ) {
1056  std::cout << "ERROR: PStotTemp = nan!!!!!!!!!" << std::endl;
1057  int parnumber = (int)(parResol.size()+parScale.size()+crossSectionHandler->parNum()+parBgr.size());
1058  for( int i=0; i<6; ++i ) {
1059  std::cout << "PS[i] = " << PS[i] << std::endl;
1060  if( PS[i] != PS[i] ) {
1061  std::cout << "mass = " << mass << std::endl;
1062  std::cout << "massResol = " << massResol << std::endl;
1063  for( int j=0; j<parnumber; ++j ) {
1064  std::cout << "parval["<<j<<"] = " << parval[j] << std::endl;
1065  }
1066  }
1067  }
1068  }
1069  if( PStotTemp == PStotTemp ) {
1071  }
1072  if (debug>0) std::cout << "mass = " << mass << ", P = " << P << ", PStot = " << PStotTemp << ", PB = " << PB << ", bgrp1 = " << Bgrp1 << std::endl;
1073 
1075  }
1076  return P;
1077 }
1078 
1079 // Method to check if the mass value is within the mass window of the i-th resonance.
1080 // inline bool MuScleFitUtils::checkMassWindow( const double & mass, const int ires, const double & resMass, const double & leftFactor, const double & rightFactor )
1081 // {
1082 // return( mass-resMass > -leftFactor*massWindowHalfWidth[MuonTypeForCheckMassWindow][ires]
1083 // && mass-resMass < rightFactor*massWindowHalfWidth[MuonTypeForCheckMassWindow][ires] );
1084 // }
1085 inline bool MuScleFitUtils::checkMassWindow( const double & mass, const double & leftBorder, const double & rightBorder )
1086 {
1087  return( (mass > leftBorder) && (mass < rightBorder) );
1088 }
1089 
1090 // Function that returns the weight for a muon pair
1091 // ------------------------------------------------
1092 double MuScleFitUtils::computeWeight( const double & mass, const int iev, const bool doUseBkgrWindow )
1093 {
1094  // Compute weight for this event
1095  // -----------------------------
1096  double weight = 0.;
1097 
1098  // Take the highest-mass resonance within bounds
1099  // NB this must be revised once credible estimates of the relative xs of Y(1S), (2S), and (3S)
1100  // are made. Those are priors in the decision of which resonance to assign to an in-between event.
1101  // -----------------------------------------------------------------------------------------------
1102 
1103  if( doUseBkgrWindow && (debug > 0) ) std::cout << "using backgrond window for mass = " << mass << std::endl;
1104  // bool useBackgroundWindow = (doBackgroundFit[loopCounter] || doUseBkgrWindow);
1105  bool useBackgroundWindow = (doBackgroundFit[loopCounter]);
1106 
1107  for (int ires=0; ires<6; ires++) {
1108  if (resfind[ires]>0 && weight==0.) {
1109  // std::pair<double, double> windowFactor = backgroundHandler->windowFactors( useBackgroundWindow, ires );
1110  std::pair<double, double> windowBorder = backgroundHandler->windowBorders( useBackgroundWindow, ires );
1111  // if( checkMassWindow(mass, ires, backgroundHandler->resMass( useBackgroundWindow, ires ),
1112  // windowFactor.first, windowFactor.second) ) {
1113  if( checkMassWindow(mass, windowBorder.first, windowBorder.second) ) {
1114  weight = 1.0;
1115  if( doUseBkgrWindow && (debug > 0) ) std::cout << "setting weight to = " << weight << std::endl;
1116  }
1117  }
1118  }
1119 
1120  return weight;
1121 }
1122 
1123 // Likelihood minimization routine
1124 // -------------------------------
1126 {
1127  // Output file with fit parameters resulting from minimization
1128  // -----------------------------------------------------------
1129  std::ofstream FitParametersFile;
1130  FitParametersFile.open ("FitParameters.txt", std::ios::app);
1131  FitParametersFile << "Fitting with resolution, scale, bgr function # "
1132  << ResolFitType << " " << ScaleFitType << " " << BgrFitType
1133  << " - Iteration " << loopCounter << std::endl;
1134 
1135  // Fill parvalue and other vectors needed for the fitting
1136  // ------------------------------------------------------
1137 
1138 
1139 
1140 
1141 
1142  // ----- //
1143  // FIXME //
1144  // ----- //
1145  // this was changed to verify the possibility that fixed parameters influence the errors.
1146  // It must be 0 otherwise the parameters for resonances will not be passed by minuit (will be always 0).
1147  // Should be removed.
1148  int parForResonanceWindows = 0;
1149  // int parnumber = (int)(parResol.size()+parScale.size()+parCrossSection.size()+parBgr.size() - parForResonanceWindows);
1150  int parnumber = (int)(parResol.size()+parScale.size()+crossSectionHandler->parNum()+parBgr.size() - parForResonanceWindows);
1151 
1152 
1153 
1154 
1155 
1156 
1157  int parnumberAll = (int)(parResol.size()+parScale.size()+crossSectionHandler->parNum()+parBgr.size());
1158 
1159  // parvalue is a std::vector<std::vector<double> > storing all the parameters from all the loops
1160  parvalue.push_back(parResol);
1161  std::vector<double> *tmpVec = &(parvalue.back());
1162 
1163  // If this is not the first loop we want to start from neutral values
1164  // Otherwise the scale will start with values correcting again a bias
1165  // that is already corrected.
1166  if( scaleFitNotDone_ ) {
1167  tmpVec->insert( tmpVec->end(), parScale.begin(), parScale.end() );
1168  std::cout << "scaleFitNotDone: tmpVec->size() = " << tmpVec->size() << std::endl;
1169  }
1170  else {
1171  scaleFunction->resetParameters(tmpVec);
1172  std::cout << "scaleFitDone: tmpVec->size() = " << tmpVec->size() << std::endl;
1173  }
1174  tmpVec->insert( tmpVec->end(), parCrossSection.begin(), parCrossSection.end() );
1175  tmpVec->insert( tmpVec->end(), parBgr.begin(), parBgr.end() );
1176  int i = 0;
1177  std::vector<double>::const_iterator it = tmpVec->begin();
1178  for( ; it != tmpVec->end(); ++it, ++i ) {
1179  std::cout << "tmpVec["<<i<<"] = " << *it << std::endl;
1180  }
1181 
1182  // Empty vector of size = number of cross section fitted parameters. Note that the cross section
1183  // fit works in a different way than the others and it uses ratios of the paramters passed via cfg.
1184  // We use this empty vector for compatibility with the rest of the structure.
1185  std::vector<int> crossSectionParNumSizeVec( MuScleFitUtils::crossSectionHandler->parNum(), 0 );
1186 
1187  std::vector<int> parfix(parResolFix);
1188  parfix.insert( parfix.end(), parScaleFix.begin(), parScaleFix.end() );
1189  parfix.insert( parfix.end(), crossSectionParNumSizeVec.begin(), crossSectionParNumSizeVec.end() );
1190  parfix.insert( parfix.end(), parBgrFix.begin(), parBgrFix.end() );
1191 
1192  std::vector<int> parorder(parResolOrder);
1193  parorder.insert( parorder.end(), parScaleOrder.begin(), parScaleOrder.end() );
1194  parorder.insert( parorder.end(), crossSectionParNumSizeVec.begin(), crossSectionParNumSizeVec.end() );
1195  parorder.insert( parorder.end(), parBgrOrder.begin(), parBgrOrder.end() );
1196 
1197  // This is filled later
1198  std::vector<double> parerr(3*parnumberAll,0.);
1199 
1200  if (debug>19) {
1201  std::cout << "[MuScleFitUtils-minimizeLikelihood]: Parameters before likelihood " << std::endl;
1202  for (unsigned int i=0; i<(unsigned int)parnumberAll; i++) {
1203  std::cout << " Par # " << i << " = " << parvalue[loopCounter][i] << " : free = " << parfix[i] << "; order = "
1204  << parorder[i] << std::endl;
1205  }
1206  }
1207 
1208 // // Background rescaling from regions to resonances
1209 // // -----------------------------------------------
1210 // // If we are in a loop > 0 and we are not fitting the background, but we have fitted it in the previous iteration
1211 // if( loopCounter > 0 && !(doBackgroundFit[loopCounter]) && doBackgroundFit[loopCounter-1] ) {
1212 // // This rescales from regions to resonances
1213 // int localMuonType = MuonType;
1214 // if( MuonType > 2 ) localMuonType = 2;
1215 // backgroundHandler->rescale( parBgr, ResMass, massWindowHalfWidth[localMuonType],
1216 // MuScleFitUtils::SavedPair);
1217 // }
1218 
1219  // Init Minuit
1220  // -----------
1221  TMinuit rmin (parnumber);
1222  rminPtr_ = &rmin;
1223  rmin.SetFCN (likelihood); // Unbinned likelihood
1224  // Standard initialization of minuit parameters:
1225  // sets input to be $stdin, output to be $stdout
1226  // and saving to a file.
1227  rmin.mninit (5, 6, 7);
1228  int ierror = 0;
1229  int istat;
1230  double arglis[4];
1231  arglis[0] = FitStrategy; // Strategy 1 or 2
1232  // 1 standard
1233  // 2 try to improve minimum (slower)
1234  rmin.mnexcm ("SET STR", arglis, 1, ierror);
1235 
1236  arglis[0] = 10001;
1237  // Set the random seed for the generator used in SEEk to a fixed value for reproducibility
1238  rmin.mnexcm("SET RAN", arglis, 1, ierror);
1239 
1240  // Set fit parameters
1241  // ------------------
1242  double * Start = new double[parnumberAll];
1243  double * Step = new double[parnumberAll];
1244  double * Mini = new double[parnumberAll];
1245  double * Maxi = new double[parnumberAll];
1246  int * ind = new int[parnumberAll]; // Order of release of parameters
1247  TString * parname = new TString[parnumberAll];
1248 
1249  if( !parResolStep.empty() && !parResolMin.empty() && !parResolMax.empty() ) {
1250  MuScleFitUtils::resolutionFunctionForVec->setParameters( Start, Step, Mini, Maxi, ind, parname, parResol, parResolOrder, parResolStep, parResolMin, parResolMax, MuonType );
1251  }
1252  else {
1253  MuScleFitUtils::resolutionFunctionForVec->setParameters( Start, Step, Mini, Maxi, ind, parname, parResol, parResolOrder, MuonType );
1254  }
1255 
1256  // Take the number of parameters in the resolutionFunction and displace the arrays passed to the scaleFunction
1257  int resParNum = MuScleFitUtils::resolutionFunctionForVec->parNum();
1258 
1259  if( !parScaleStep.empty() && !parScaleMin.empty() && !parScaleMax.empty() ) {
1260  MuScleFitUtils::scaleFunctionForVec->setParameters( &(Start[resParNum]), &(Step[resParNum]),
1261  &(Mini[resParNum]), &(Maxi[resParNum]),
1262  &(ind[resParNum]), &(parname[resParNum]),
1265  }
1266  else {
1267  MuScleFitUtils::scaleFunctionForVec->setParameters( &(Start[resParNum]), &(Step[resParNum]),
1268  &(Mini[resParNum]), &(Maxi[resParNum]),
1269  &(ind[resParNum]), &(parname[resParNum]),
1271  }
1272 
1273  // Initialize cross section parameters
1274  int crossSectionParShift = resParNum + MuScleFitUtils::scaleFunctionForVec->parNum();
1275  MuScleFitUtils::crossSectionHandler->setParameters( &(Start[crossSectionParShift]), &(Step[crossSectionParShift]), &(Mini[crossSectionParShift]),
1276  &(Maxi[crossSectionParShift]), &(ind[crossSectionParShift]), &(parname[crossSectionParShift]),
1278 
1279  // Initialize background parameters
1280  int bgrParShift = crossSectionParShift + crossSectionHandler->parNum();
1281  MuScleFitUtils::backgroundHandler->setParameters( &(Start[bgrParShift]), &(Step[bgrParShift]), &(Mini[bgrParShift]), &(Maxi[bgrParShift]),
1282  &(ind[bgrParShift]), &(parname[bgrParShift]), parBgr, parBgrOrder, MuonType );
1283 
1284  for( int ipar=0; ipar<parnumber; ++ipar ) {
1285  std::cout << "parname["<<ipar<<"] = " << parname[ipar] << std::endl;
1286  std::cout << "Start["<<ipar<<"] = " << Start[ipar] << std::endl;
1287  std::cout << "Step["<<ipar<<"] = " << Step[ipar] << std::endl;
1288  std::cout << "Mini["<<ipar<<"] = " << Mini[ipar] << std::endl;
1289  std::cout << "Maxi["<<ipar<<"] = " << Maxi[ipar] << std::endl;
1290 
1291 
1292  rmin.mnparm( ipar, parname[ipar], Start[ipar], Step[ipar], Mini[ipar], Maxi[ipar], ierror );
1293 
1294 
1295  // Testing without limits
1296  // rmin.mnparm( ipar, parname[ipar], Start[ipar], Step[ipar], 0, 0, ierror );
1297 
1298 
1299  }
1300 
1301  // Do minimization
1302  // ---------------
1303  if (debug>19)
1304  std::cout << "[MuScleFitUtils-minimizeLikelihood]: Starting minimization" << std::endl;
1305  double fmin;
1306  double fdem;
1307  double errdef;
1308  int npari;
1309  int nparx;
1310  rmin.mnexcm ("CALL FCN", arglis, 1, ierror);
1311 
1312  // First, fix all parameters
1313  // -------------------------
1314  if (debug>19)
1315  std::cout << "[MuScleFitUtils-minimizeLikelihood]: First fix all parameters ...";
1316  for (int ipar=0; ipar<parnumber; ipar++) {
1317  rmin.FixParameter (ipar);
1318  }
1319 
1320  // Then release them in the specified order and refit
1321  // --------------------------------------------------
1322  if (debug>19) std::cout << " Then release them in order..." << std::endl;
1323 
1324  TString name;
1325  double pval;
1326  double pmin;
1327  double pmax;
1328  double errp;
1329  double errl;
1330  double errh;
1331  int ivar;
1332  double erro;
1333  double cglo;
1334  int n_times = 0;
1335  // n_times = number of loops required to unlock all parameters.
1336 
1337  if (debug>19) std::cout << "Before scale parNum" << std::endl;
1338  int scaleParNum = scaleFunction->parNum();
1339  if (debug>19) std::cout << "After scale parNum" << std::endl;
1340  // edm::LogInfo("minimizeLikelihood") << "number of parameters for scaleFunction = " << scaleParNum << std::endl;
1341  // edm::LogInfo("minimizeLikelihood") << "number of parameters for resolutionFunction = " << resParNum << std::endl;
1342  // edm::LogInfo("minimizeLikelihood") << "number of parameters for cross section = " << crossSectionHandler->parNum() << std::endl;
1343  // edm::LogInfo("minimizeLikelihood") << "number of parameters for backgroundFunction = " << parBgr.size() << std::endl;
1344  std::cout << "number of parameters for scaleFunction = " << scaleParNum << std::endl;
1345  std::cout << "number of parameters for resolutionFunction = " << resParNum << std::endl;
1346  std::cout << "number of parameters for cross section = " << crossSectionHandler->parNum() << std::endl;
1347  std::cout << "number of parameters for backgroundFunction = " << parBgr.size() << std::endl;
1348  // edm::LogInfo("minimizeLikelihood") << "number of parameters for backgroundFunction = " << backgroundFunction->parNum() << std::endl;
1349 
1350  for (int i=0; i<parnumber; i++) {
1351  // NB ind[] has been set as parorder[] previously
1352  if (n_times<ind[i]) {
1353  edm::LogInfo("minimizeLikelihood") << "n_times = " << n_times << ", ind["<<i<<"] = " << ind[i] << ", scaleParNum = " << scaleParNum << ", doScaleFit["<<loopCounter<<"] = " << doScaleFit[loopCounter] << std::endl;
1354  // Set the n_times only if we will do the fit
1355  if ( i<resParNum ) {
1356  if( doResolFit[loopCounter] ) n_times = ind[i];
1357  }
1358  else if( i<resParNum+scaleParNum ) {
1359  if( doScaleFit[loopCounter] ) n_times = ind[i];
1360  }
1361  else if( doBackgroundFit[loopCounter] ) n_times = ind[i];
1362  }
1363  }
1364  for (int iorder=0; iorder<n_times+1; iorder++) { // Repeat fit n_times times
1365  std::cout << "Starting minimization " << iorder << " of " << n_times << std::endl;
1366 
1367  bool somethingtodo = false;
1368 
1369  // Use parameters from cfg to select which fit to do
1370  // -------------------------------------------------
1371  if( doResolFit[loopCounter] ) {
1372  // Release resolution parameters and fit them
1373  // ------------------------------------------
1374  for( unsigned int ipar=0; ipar<parResol.size(); ++ipar ) {
1375  if( parfix[ipar]==0 && ind[ipar]==iorder ) {
1376  rmin.Release( ipar );
1377  somethingtodo = true;
1378  }
1379  }
1380  }
1381  if( doScaleFit[loopCounter] ) {
1382  // Release scale parameters and fit them
1383  // -------------------------------------
1384  for( unsigned int ipar=parResol.size(); ipar<parResol.size()+parScale.size(); ++ipar ) {
1385  if( parfix[ipar]==0 && ind[ipar]==iorder ) { // parfix=0 means parameter is free
1386  rmin.Release( ipar );
1387  somethingtodo = true;
1388  }
1389  }
1390  scaleFitNotDone_ = false;
1391  }
1392  unsigned int crossSectionParShift = parResol.size()+parScale.size();
1393  if( doCrossSectionFit[loopCounter] ) {
1394  // Release cross section parameters and fit them
1395  // ---------------------------------------------
1396  // Note that only cross sections of resonances that are being fitted are released
1397  bool doCrossSection = crossSectionHandler->releaseParameters( rmin, resfind, parfix, ind, iorder, crossSectionParShift );
1398  if( doCrossSection ) somethingtodo = true;
1399  }
1400  if( doBackgroundFit[loopCounter] ) {
1401  // Release background parameters and fit them
1402  // ------------------------------------------
1403  // for( int ipar=parResol.size()+parScale.size(); ipar<parnumber; ++ipar ) {
1404  // Free only the parameters for the regions, as the resonances intervals are never used to fit the background
1405  unsigned int bgrParShift = crossSectionParShift+crossSectionHandler->parNum();
1406  for( unsigned int ipar = bgrParShift; ipar < bgrParShift+backgroundHandler->regionsParNum(); ++ipar ) {
1407  // Release only those parameters for the resonances we are fitting
1408  if( parfix[ipar]==0 && ind[ipar]==iorder && backgroundHandler->unlockParameter(resfind, ipar - bgrParShift) ) {
1409  rmin.Release( ipar );
1410  somethingtodo = true;
1411  }
1412  }
1413  }
1414 
1415  // OK, now do minimization if some parameter has been released
1416  // -----------------------------------------------------------
1417  if( somethingtodo ) {
1418 // #ifdef DEBUG
1419 
1420  std::stringstream fileNum;
1421  fileNum << loopCounter;
1422 
1423  minuitLoop_ = 0;
1424  char name[50];
1425  sprintf(name, "likelihoodInLoop_%d_%d", loopCounter, iorder);
1426  TH1D * tempLikelihoodInLoop = new TH1D(name, "likelihood value in minuit loop", 10000, 0, 10000);
1427  likelihoodInLoop_ = tempLikelihoodInLoop;
1428  char signalProbName[50];
1429  sprintf(signalProbName, "signalProb_%d_%d", loopCounter, iorder);
1430  TH1D * tempSignalProb = new TH1D(signalProbName, "signal probability", 10000, 0, 10000);
1431  signalProb_ = tempSignalProb;
1432  char backgroundProbName[50];
1433  sprintf(backgroundProbName, "backgroundProb_%d_%d", loopCounter, iorder);
1434  TH1D * tempBackgroundProb = new TH1D(backgroundProbName, "background probability", 10000, 0, 10000);
1435  backgroundProb_ = tempBackgroundProb;
1436 // #endif
1437 
1438 
1439 
1440  // Before we start the minimization we create a list of events with only the events inside a smaller
1441  // window than the one in which the probability is != 0. We will compute the probability for all those
1442  // events and hopefully the margin will avoid them to get a probability = 0 (which causes a discontinuity
1443  // in the likelihood function). The width of this smaller window must be optimized, but we can start using
1444  // an 90% of the normalization window.
1445  double protectionFactor = 0.9;
1446 
1448  for( unsigned int nev=0; nev<MuScleFitUtils::SavedPair.size(); ++nev ) {
1449  const lorentzVector * recMu1 = &(MuScleFitUtils::SavedPair[nev].first);
1450  const lorentzVector * recMu2 = &(MuScleFitUtils::SavedPair[nev].second);
1451  double mass = MuScleFitUtils::invDimuonMass( *recMu1, *recMu2 );
1452  // Test all resonances to see if the mass is inside at least one of the windows
1453  bool check = false;
1454  for( int ires = 0; ires < 6; ++ires ) {
1455  // std::pair<double, double> windowFactor = backgroundHandler->windowFactors( doBackgroundFit[loopCounter], ires );
1456  std::pair<double, double> windowBorder = backgroundHandler->windowBorders( doBackgroundFit[loopCounter], ires );
1457  // if( resfind[ires] && checkMassWindow( mass, ires, backgroundHandler->resMass( doBackgroundFit[loopCounter], ires ),
1458  // 0.9*windowFactor.first, 0.9*windowFactor.second ) ) {
1459  // double resMassValue = backgroundHandler->resMass( doBackgroundFit[loopCounter], ires );
1460  // double windowBorderLeft = resMassValue - protectionFactor*(resMassValue - windowBorder.first);
1461  // double windowBorderRight = resMassValue + protectionFactor*(windowBorder.second - resMassValue);
1462  double windowBorderShift = (windowBorder.second - windowBorder.first)*(1-protectionFactor)/2.;
1463  double windowBorderLeft = windowBorder.first + windowBorderShift;
1464  double windowBorderRight = windowBorder.second - windowBorderShift;
1465  if( resfind[ires] && checkMassWindow( mass, windowBorderLeft, windowBorderRight ) ) {
1466  check = true;
1467  }
1468  }
1469  if( check ) {
1470  MuScleFitUtils::ReducedSavedPair.push_back(std::make_pair(*recMu1, *recMu2));
1471  }
1472  }
1473  std::cout << "Fitting with " << MuScleFitUtils::ReducedSavedPair.size() << " events" << std::endl;
1474 
1475 
1476  // rmin.SetMaxIterations(500*parnumber);
1477 
1478  //Print some informations
1479  std::cout<<"MINUIT is starting the minimization for the iteration number "<<loopCounter<<std::endl;
1480 
1481  //Try to set iterations
1482  // rmin.SetMaxIterations(100000);
1483 
1484  std::cout<<"maxNumberOfIterations (just set) = "<<rmin.GetMaxIterations()<<std::endl;
1485 
1487 
1488  // Maximum number of iterations
1489  arglis[0] = 100000;
1490  // tolerance
1491  arglis[1] = 0.1;
1492 
1493  // Run simplex first to get an initial estimate of the minimum
1494  if( startWithSimplex_ ) {
1495  rmin.mnexcm( "SIMPLEX", arglis, 0, ierror );
1496  }
1497 
1498  rmin.mnexcm( "MIGRAD", arglis, 2, ierror );
1499 
1500 
1501 
1502 
1503 // #ifdef DEBUG
1504  likelihoodInLoop_->Write();
1505  signalProb_->Write();
1506  backgroundProb_->Write();
1507  delete tempLikelihoodInLoop;
1508  delete tempSignalProb;
1509  delete tempBackgroundProb;
1510  likelihoodInLoop_ = 0;
1511  signalProb_ = 0;
1512  backgroundProb_ = 0;
1513 // #endif
1514 
1515 
1516  // Compute again the error matrix
1517  rmin.mnexcm( "HESSE", arglis, 0, ierror );
1518 
1519  // Peform minos error analysis.
1520  if( computeMinosErrors_ ) {
1521  duringMinos_ = true;
1522  rmin.mnexcm( "MINOS", arglis, 0, ierror );
1523  duringMinos_ = false;
1524  }
1525 
1526  if( normalizationChanged_ > 1 ) {
1527  std::cout << "WARNING: normalization changed during fit meaning that events exited from the mass window. This causes a discontinuity in the likelihood function. Please check the scan of the likelihood as a function of the parameters to see if there are discontinuities around the minimum." << std::endl;
1528  }
1529  }
1530 
1531  // bool notWritten = true;
1532  for (int ipar=0; ipar<parnumber; ipar++) {
1533 
1534  rmin.mnpout (ipar, name, pval, erro, pmin, pmax, ivar);
1535  // Save parameters in parvalue[] vector
1536  // ------------------------------------
1537  if (ierror!=0 && debug>0) {
1538  std::cout << "[MuScleFitUtils-minimizeLikelihood]: ierror!=0, bogus pars" << std::endl;
1539  }
1540  // for (int ipar=0; ipar<parnumber; ipar++) {
1541  // rmin.mnpout (ipar, name, pval, erro, pmin, pmax, ivar);
1542  parvalue[loopCounter][ipar] = pval;
1543  // }
1544 
1545 
1546  // int ilax2 = 0;
1547  // Double_t val2pl, val2mi;
1548  // rmin.mnmnot (ipar+1, ilax2, val2pl, val2mi);
1549  rmin.mnerrs (ipar, errh, errl, errp, cglo);
1550 
1551 
1552  // Set error on params
1553  // -------------------
1554  if (errp!=0) {
1555  parerr[3*ipar] = errp;
1556  } else {
1557  parerr[3*ipar] = (((errh)>(fabs(errl)))?(errh):(fabs(errl)));
1558  }
1559  parerr[3*ipar+1] = errl;
1560  parerr[3*ipar+2] = errh;
1561 
1562  if( ipar == 0 ) {
1563  FitParametersFile << " Resolution fit parameters:" << std::endl;
1564  }
1565  if( ipar == int(parResol.size()) ) {
1566  FitParametersFile << " Scale fit parameters:" << std::endl;
1567  }
1568  if( ipar == int(parResol.size()+parScale.size()) ) {
1569  FitParametersFile << " Cross section fit parameters:" << std::endl;
1570  }
1571  if( ipar == int(parResol.size()+parScale.size()+crossSectionHandler->parNum()) ) {
1572  FitParametersFile << " Background fit parameters:" << std::endl;
1573  }
1574 // if( ipar >= int(parResol.size()+parScale.size()) && ipar < int(parResol.size()+parScale.size()+crossSectionHandler->parNum()) && notWritted ) {
1575 
1576 // std::vector<double> relativeCrossSections = crossSectionHandler->relativeCrossSections(&(parvalue[loopCounter][parResol.size()+parScale.size()]));
1577 // std::vector<double>::const_iterator it = relativeCrossSections.begin();
1578 // for( ; it != relativeCrossSections.end(); ++it ) {
1579 // FitParametersFile << " Results of the fit: parameter " << ipar << " has value "
1580 // << *it << "+-" << 0
1581 // << " + " << 0 << " - " << 0
1582 // << " /t/t (" << 0 << ")" << std::endl;
1583 // }
1584 
1585 // notWritten = false;
1586 // }
1587 // else {
1588  FitParametersFile << " Results of the fit: parameter " << ipar << " has value "
1589  << pval << "+-" << parerr[3*ipar]
1590  << " + " << parerr[3*ipar+1] << " - " << parerr[3*ipar+2]
1591  // << " \t\t (" << parname[ipar] << ")"
1592  << std::endl;
1593 
1594 
1595 
1596  }
1597  rmin.mnstat (fmin, fdem, errdef, npari, nparx, istat); // NNBB Commented for a check!
1598  FitParametersFile << std::endl;
1599 
1600  if( minimumShapePlots_ ) {
1601  // Create plots of the minimum vs parameters
1602  // -----------------------------------------
1603  // Keep this after the parameters filling because it recomputes the values and it can compromise the fit results.
1604  if( somethingtodo ) {
1605  std::stringstream iorderString;
1606  iorderString << iorder;
1607  std::stringstream iLoopString;
1608  iLoopString << loopCounter;
1609 
1610  for (int ipar=0; ipar<parnumber; ipar++) {
1611  if( parfix[ipar] == 1 ) continue;
1612  std::cout << "plotting parameter = " << ipar+1 << std::endl;
1613  std::stringstream iparString;
1614  iparString << ipar+1;
1615  std::stringstream iparStringName;
1616  iparStringName << ipar;
1617  rmin.mncomd( ("scan "+iparString.str()).c_str(), ierror );
1618  if( ierror == 0 ) {
1619  TCanvas * canvas = new TCanvas(("likelihoodCanvas_loop_"+iLoopString.str()+"_oder_"+iorderString.str()+"_par_"+iparStringName.str()).c_str(), ("likelihood_"+iparStringName.str()).c_str(), 1000, 800);
1620  canvas->cd();
1621  // arglis[0] = ipar;
1622  // rmin.mnexcm( "SCA", arglis, 0, ierror );
1623  TGraph * graph = (TGraph*)rmin.GetPlot();
1624  graph->Draw("AP");
1625  // graph->SetTitle(("parvalue["+iparStringName.str()+"]").c_str());
1626  graph->SetTitle(parname[ipar]);
1627  // graph->Write();
1628 
1629  canvas->Write();
1630  }
1631  }
1632 
1633  // // Draw contours of the fit
1634  // TCanvas * canvas = new TCanvas(("contourCanvas_oder_"+iorderString.str()).c_str(), "contour", 1000, 800);
1635  // canvas->cd();
1636  // TGraph * contourGraph = (TGraph*)rmin.Contour(4, 2, 4);
1637  // if( (rmin.GetStatus() == 0) || (rmin.GetStatus() >= 3) ) {
1638  // contourGraph->Draw("AP");
1639  // }
1640  // else {
1641  // std::cout << "Contour graph error: status = " << rmin.GetStatus() << std::endl;
1642  // }
1643  // canvas->Write();
1644  }
1645  }
1646 
1647  } // end loop on iorder
1648  FitParametersFile.close();
1649 
1650  std::cout << "[MuScleFitUtils-minimizeLikelihood]: Parameters after likelihood " << std::endl;
1651  for (unsigned int ipar=0; ipar<(unsigned int)parnumber; ipar++) {
1652  std::cout << ipar << " " << parvalue[loopCounter][ipar] << " : free = "
1653  << parfix[ipar] << "; order = " << parorder[ipar] << std::endl;
1654  }
1655 
1656  // Put back parvalue into parResol, parScale, parCrossSection, parBgr
1657  // ------------------------------------------------------------------
1658  for( int i=0; i<(int)(parResol.size()); ++i ) {
1660  }
1661  for( int i=0; i<(int)(parScale.size()); ++i ) {
1662  parScale[i] = parvalue[loopCounter][i+parResol.size()];
1663  }
1665  for( unsigned int i=0; i<parCrossSection.size(); ++i ) {
1666  // parCrossSection[i] = parvalue[loopCounter][i+parResol.size()+parScale.size()];
1667  std::cout << "relative cross section["<<i<<"] = " << parCrossSection[i] << std::endl;
1668  }
1669  // Save only the fitted background parameters
1670  for( unsigned int i = 0; i<(parBgr.size() - parForResonanceWindows); ++i ) {
1672  }
1673 
1674  // Background rescaling from regions to resonances
1675  // -----------------------------------------------
1676  // Only if we fitted the background
1677  if( doBackgroundFit[loopCounter] ) {
1678  // This rescales from regions to resonances
1679  int localMuonType = MuonType;
1680  if( MuonType > 2 ) localMuonType = 2;
1683  }
1684 
1685  // Delete the arrays used to set some parameters
1686  delete[] Start;
1687  delete[] Step;
1688  delete[] Mini;
1689  delete[] Maxi;
1690  delete[] ind;
1691  delete[] parname;
1692 }
1693 
1694 // Likelihood function
1695 // -------------------
1696 extern "C" void likelihood( int& npar, double* grad, double& fval, double* xval, int flag ) {
1697 
1698  if (MuScleFitUtils::debug>19) std::cout << "[MuScleFitUtils-likelihood]: In likelihood function" << std::endl;
1699 
1700  const lorentzVector * recMu1;
1701  const lorentzVector * recMu2;
1702  lorentzVector corrMu1;
1703  lorentzVector corrMu2;
1704 
1705  // if (MuScleFitUtils::debug>19) {
1706  // int parnumber = (int)(MuScleFitUtils::parResol.size()+MuScleFitUtils::parScale.size()+
1707  // MuScleFitUtils::parCrossSection.size()+MuScleFitUtils::parBgr.size());
1708  // std::cout << "[MuScleFitUtils-likelihood]: Looping on tree with ";
1709  // for (int ipar=0; ipar<parnumber; ipar++) {
1710  // std::cout << "Parameter #" << ipar << " with value " << xval[ipar] << " ";
1711  // }
1712  // std::cout << std::endl;
1713  // }
1714 
1715  // Loop on the tree
1716  // ----------------
1717  double flike = 0;
1718  int evtsinlik = 0;
1719  int evtsoutlik = 0;
1720  // std::cout << "SavedPair.size() = " << MuScleFitUtils::SavedPair.size() << std::endl;
1721  if( MuScleFitUtils::debug>0 ) {
1722  std::cout << "SavedPair.size() = " << MuScleFitUtils::SavedPair.size() << std::endl;
1723  std::cout << "ReducedSavedPair.size() = " << MuScleFitUtils::ReducedSavedPair.size() << std::endl;
1724  }
1725  // for( unsigned int nev=0; nev<MuScleFitUtils::SavedPair.size(); ++nev ) {
1726  for( unsigned int nev=0; nev<MuScleFitUtils::ReducedSavedPair.size(); ++nev ) {
1727 
1728  // recMu1 = &(MuScleFitUtils::SavedPair[nev].first);
1729  // recMu2 = &(MuScleFitUtils::SavedPair[nev].second);
1730  recMu1 = &(MuScleFitUtils::ReducedSavedPair[nev].first);
1731  recMu2 = &(MuScleFitUtils::ReducedSavedPair[nev].second);
1732 
1733  // Compute original mass
1734  // ---------------------
1735  double mass = MuScleFitUtils::invDimuonMass( *recMu1, *recMu2 );
1736 
1737  // Compute weight and reference mass (from original mass)
1738  // ------------------------------------------------------
1740  if( weight!=0. ) {
1741  // Compute corrected mass (from previous biases) only if we are currently fitting the scale
1742  // ----------------------------------------------------------------------------------------
1744 // std::cout << "Original pt1 = " << corrMu1.Pt() << std::endl;
1745 // std::cout << "Original pt2 = " << corrMu2.Pt() << std::endl;
1746  corrMu1 = MuScleFitUtils::applyScale(*recMu1, xval, -1);
1747  corrMu2 = MuScleFitUtils::applyScale(*recMu2, xval, 1);
1748 
1749 // if( (corrMu1.Pt() != corrMu1.Pt()) || (corrMu2.Pt() != corrMu2.Pt()) ) {
1750 // std::cout << "Rescaled pt1 = " << corrMu1.Pt() << std::endl;
1751 // std::cout << "Rescaled pt2 = " << corrMu2.Pt() << std::endl;
1752 // }
1753 // std::cout << "Rescaled pt1 = " << corrMu1.Pt() << std::endl;
1754 // std::cout << "Rescaled pt2 = " << corrMu2.Pt() << std::endl;
1755  }
1756  else {
1757  corrMu1 = *recMu1;
1758  corrMu2 = *recMu2;
1759 
1760 // if( (corrMu1.Pt() != corrMu1.Pt()) || (corrMu2.Pt() != corrMu2.Pt()) ) {
1761 // std::cout << "Not rescaled pt1 = " << corrMu1.Pt() << std::endl;
1762 // std::cout << "Not rescaled pt2 = " << corrMu2.Pt() << std::endl;
1763 // }
1764  }
1765  double corrMass = MuScleFitUtils::invDimuonMass(corrMu1, corrMu2);
1766  double Y = (corrMu1+corrMu2).Rapidity();
1767  double resEta = (corrMu1+corrMu2).Eta();
1768  if( MuScleFitUtils::debug>19 ) {
1769  std::cout << "[MuScleFitUtils-likelihood]: Original/Corrected resonance mass = " << mass
1770  << " / " << corrMass << std::endl;
1771  }
1772 
1773  // Compute mass resolution
1774  // -----------------------
1775  double massResol = MuScleFitUtils::massResolution(corrMu1, corrMu2, xval);
1776  if (MuScleFitUtils::debug>19)
1777  std::cout << "[MuScleFitUtils-likelihood]: Resolution is " << massResol << std::endl;
1778 
1779  // Compute probability of this mass value including background modeling
1780  // --------------------------------------------------------------------
1781  if (MuScleFitUtils::debug>1) std::cout << "calling massProb inside likelihood function" << std::endl;
1782 
1783  // double prob = MuScleFitUtils::massProb( corrMass, resEta, Y, massResol, xval );
1784  double prob = MuScleFitUtils::massProb( corrMass, resEta, Y, massResol, xval, false, corrMu1.eta(), corrMu2.eta() );
1785  if (MuScleFitUtils::debug>1) std::cout << "likelihood:massProb = " << prob << std::endl;
1786 
1787  // Compute likelihood
1788  // ------------------
1789  if( prob>0 ) {
1790  // flike += log(prob*10000)*weight; // NNBB! x10000 to see if we can recover the problem of boundary
1791  flike += log(prob)*weight;
1792  evtsinlik += 1; // NNBB test: see if likelihood per event is smarter (boundary problem)
1793  } else {
1794  if( MuScleFitUtils::debug > 0 ) {
1795  std::cout << "WARNING: corrMass = " << corrMass << " outside window, this will cause a discontinuity in the likelihood. Consider increasing the safety bands which are now set to 90% of the normalization window to avoid this problem" << std::endl;
1796  std::cout << "Original mass was = " << mass << std::endl;
1797  std::cout << "WARNING: massResol = " << massResol << " outside window" << std::endl;
1798  }
1799  evtsoutlik += 1;
1800  }
1801  if (MuScleFitUtils::debug>19)
1802  std::cout << "[MuScleFitUtils-likelihood]: Mass probability = " << prob << std::endl;
1803  } // weight!=0
1804 
1805  } // End of loop on tree events
1806 
1807 // // Protection for low statistic. If the likelihood manages to throw out all the signal
1808 // // events and stays with ~ 10 events in the resonance window it could have a better likelihood
1809 // // because of ~ uniformly distributed events (a random combination could be good and spoil the fit).
1810 // // We require that the number of events included in the fit does not change more than 5% in each minuit loop.
1811 // bool lowStatPenalty = false;
1812 // if( MuScleFitUtils::minuitLoop_ > 0 ) {
1813 // double newEventsOutInRatio = double(evtsinlik);
1814 // // double newEventsOutInRatio = double(evtsoutlik)/double(evtsinlik);
1815 // double ratio = newEventsOutInRatio/MuScleFitUtils::oldEventsOutInRatio_;
1816 // MuScleFitUtils::oldEventsOutInRatio_ = newEventsOutInRatio;
1817 // if( ratio < 0.8 || ratio > 1.2 ) {
1818 // std::cout << "Warning: too much change from oldEventsInLikelihood to newEventsInLikelihood, ratio is = " << ratio << std::endl;
1819 // std::cout << "oldEventsInLikelihood = " << MuScleFitUtils::oldEventsOutInRatio_ << ", newEventsInLikelihood = " << newEventsOutInRatio << std::endl;
1820 // lowStatPenalty = true;
1821 // }
1822 // }
1823 
1824  // It is a product of probabilities, we compare the sqrt_N of them. Thus N becomes a denominator of the logarithm.
1825  if( evtsinlik != 0 ) {
1826 
1828  // && !(MuScleFitUtils::duringMinos_) ) {
1829  if( MuScleFitUtils::rminPtr_ == 0 ) {
1830  std::cout << "ERROR: rminPtr_ = " << MuScleFitUtils::rminPtr_ << ", code will crash" << std::endl;
1831  }
1832  double normalizationArg[] = {1/double(evtsinlik)};
1833  // Reset the normalizationArg only if it changed
1834  if( MuScleFitUtils::oldNormalization_ != normalizationArg[0] ) {
1835  int ierror = 0;
1836 // if( MuScleFitUtils::likelihoodInLoop_ != 0 ) {
1837 // // This condition is set only when minimizing. Later calls of hesse and minos will not change the value
1838 // // This is done to avoid minos being confused by changing the UP parameter during its computation.
1839 // MuScleFitUtils::rminPtr_->mnexcm("SET ERR", normalizationArg, 1, ierror);
1840 // }
1841  MuScleFitUtils::rminPtr_->mnexcm("SET ERR", normalizationArg, 1, ierror);
1842  std::cout << "oldNormalization = " << MuScleFitUtils::oldNormalization_ << " new = " << normalizationArg[0] << std::endl;
1843  MuScleFitUtils::oldNormalization_ = normalizationArg[0];
1845  }
1846  fval = -2.*flike/double(evtsinlik);
1847  // fval = -2.*flike;
1848  // if( lowStatPenalty ) {
1849  // fval *= 100;
1850  // }
1851  }
1852  else {
1853  fval = -2.*flike;
1854  }
1855  }
1856  else {
1857  std::cout << "Problem: Events in likelihood = " << evtsinlik << std::endl;
1858  fval = 999999999.;
1859  }
1860  // fval = -2.*flike;
1861  if (MuScleFitUtils::debug>19)
1862  std::cout << "[MuScleFitUtils-likelihood]: End tree loop with likelihood value = " << fval << std::endl;
1863 
1864 // #ifdef DEBUG
1865 
1866 // if( MuScleFitUtils::minuitLoop_ < 10000 ) {
1870  }
1871  // }
1872  // else std::cout << "minuitLoop over 10000. Not filling histogram" << std::endl;
1873 
1874  std::cout<<"MINUIT loop number "<<MuScleFitUtils::minuitLoop_<<", likelihood = "<<fval<<std::endl;
1875 
1876  if( MuScleFitUtils::debug > 0 ) {
1877  // if( MuScleFitUtils::duringMinos_ ) {
1878  // int parnumber = (int)(MuScleFitUtils::parResol.size()+MuScleFitUtils::parScale.size()+
1879  // MuScleFitUtils::parCrossSection.size()+MuScleFitUtils::parBgr.size());
1880  // std::cout << "[MuScleFitUtils-likelihood]: Looping on tree with ";
1881  // for (int ipar=0; ipar<parnumber; ipar++) {
1882  // std::cout << "Parameter #" << ipar << " with value " << xval[ipar] << " ";
1883  // }
1884  // std::cout << std::endl;
1885  // std::cout << "[MuScleFitUtils-likelihood]: likelihood value = " << fval << std::endl;
1886  // }
1887  std::cout << "Events in likelihood = " << evtsinlik << std::endl;
1888  std::cout << "Events out likelihood = " << evtsoutlik << std::endl;
1889  }
1890 
1891 // #endif
1892 }
1893 
1894 // Mass fitting routine
1895 // --------------------
1896 std::vector<TGraphErrors*> MuScleFitUtils::fitMass (TH2F* histo) {
1897 
1898  if (MuScleFitUtils::debug>0) std::cout << "Fitting " << histo->GetName() << std::endl;
1899 
1900  std::vector<TGraphErrors *> results;
1901 
1902  // Results of the fit
1903  // ------------------
1904  std::vector<double> Ftop;
1905  std::vector<double> Fwidth;
1906  std::vector<double> Fmass;
1907  std::vector<double> Etop;
1908  std::vector<double> Ewidth;
1909  std::vector<double> Emass;
1910  std::vector<double> Fchi2;
1911  // X bin center and width
1912  // ----------------------
1913  std::vector<double> Xcenter;
1914  std::vector<double> Ex;
1915 
1916  // Fit with lorentzian peak
1917  // ------------------------
1918  TF1 *fitFcn = new TF1 ("fitFcn", lorentzianPeak, 70, 110, 3);
1919  fitFcn->SetParameters (100, 3, 91);
1920  fitFcn->SetParNames ("Ftop", "Fwidth", "Fmass");
1921  fitFcn->SetLineWidth (2);
1922 
1923  // Fit slices projected along Y from bins in X
1924  // -------------------------------------------
1925  double cont_min = 20; // Minimum number of entries
1926  Int_t binx = histo->GetXaxis()->GetNbins();
1927  // TFile *f= new TFile("prova.root", "recreate");
1928  // histo->Write();
1929  for (int i=1; i<=binx; i++) {
1930  TH1 * histoY = histo->ProjectionY ("", i, i);
1931  // histoY->Write();
1932  double cont = histoY->GetEntries();
1933  if (cont>cont_min) {
1934  histoY->Fit ("fitFcn", "0", "", 70, 110);
1935  double *par = fitFcn->GetParameters();
1936  double *err = fitFcn->GetParErrors();
1937 
1938  Ftop.push_back(par[0]);
1939  Fwidth.push_back(par[1]);
1940  Fmass.push_back(par[2]);
1941  Etop.push_back(err[0]);
1942  Ewidth.push_back(err[1]);
1943  Emass.push_back(err[2]);
1944 
1945  double chi2 = fitFcn->GetChisquare();
1946  Fchi2.push_back(chi2);
1947 
1948  double xx = histo->GetXaxis()->GetBinCenter(i);
1949  Xcenter.push_back(xx);
1950  double ex = 0; // FIXME: you can use the bin width
1951  Ex.push_back(ex);
1952  }
1953  }
1954  // f->Close();
1955 
1956  // Put the fit results in arrays for TGraphErrors
1957  // ----------------------------------------------
1958  const int nn = Fmass.size();
1959  double *x = new double[nn];
1960  double *ym = new double[nn];
1961  double *e = new double[nn];
1962  double *eym = new double[nn];
1963  double *yw = new double[nn];
1964  double *eyw = new double[nn];
1965  double *yc = new double[nn];
1966 
1967  for (int j=0; j<nn; j++) {
1968  x[j] = Xcenter[j];
1969  ym[j] = Fmass[j];
1970  eym[j] = Emass[j];
1971  yw[j] = Fwidth[j];
1972  eyw[j] = Ewidth[j];
1973  yc[j] = Fchi2[j];
1974  e[j] = Ex[j];
1975  }
1976 
1977  // Create TGraphErrors
1978  // -------------------
1979  TString name = histo->GetName();
1980  TGraphErrors *grM = new TGraphErrors (nn, x, ym, e, eym);
1981  grM->SetTitle (name+"_M");
1982  grM->SetName (name+"_M");
1983  TGraphErrors *grW = new TGraphErrors (nn, x, yw, e, eyw);
1984  grW->SetTitle (name+"_W");
1985  grW->SetName (name+"_W");
1986  TGraphErrors *grC = new TGraphErrors (nn, x, yc, e, e);
1987  grC->SetTitle (name+"_chi2");
1988  grC->SetName (name+"_chi2");
1989 
1990  // Cleanup
1991  // -------
1992  delete[] x;
1993  delete[] ym;
1994  delete[] eym;
1995  delete[] yw;
1996  delete[] eyw;
1997  delete[] yc;
1998  delete[] e;
1999  delete fitFcn;
2000 
2001  results.push_back(grM);
2002  results.push_back(grW);
2003  results.push_back(grC);
2004  return results;
2005 }
2006 
2007 // Resolution fitting routine
2008 // --------------------------
2009 std::vector<TGraphErrors*> MuScleFitUtils::fitReso (TH2F* histo) {
2010  std::cout << "Fitting " << histo->GetName() << std::endl;
2011  std::vector<TGraphErrors *> results;
2012 
2013  // Results from fit
2014  // ----------------
2015  std::vector<double> maxs;
2016  std::vector<double> means;
2017  std::vector<double> sigmas;
2018  std::vector<double> chi2s;
2019  std::vector<double> Emaxs;
2020  std::vector<double> Emeans;
2021  std::vector<double> Esigmas;
2022 
2023  // X bin center and width
2024  // ----------------------
2025  std::vector<double> Xcenter;
2026  std::vector<double> Ex;
2027 
2028  // Fit with a gaussian
2029  // -------------------
2030  TF1 *fitFcn = new TF1 ("fitFunc", Gaussian, -0.2, 0.2, 3);
2031  fitFcn->SetParameters (100, 0, 0.02);
2032  fitFcn->SetParNames ("max", "mean", "sigma");
2033  fitFcn->SetLineWidth (2);
2034 
2035  // Fit slices projected along Y from bins in X
2036  // -------------------------------------------
2037  double cont_min = 20; // Minimum number of entries
2038  Int_t binx = histo->GetXaxis()->GetNbins();
2039  for (int i=1; i<=binx; i++) {
2040  TH1 * histoY = histo->ProjectionY ("", i, i);
2041  double cont = histoY->GetEntries();
2042  if (cont>cont_min) {
2043  histoY->Fit ("fitFunc", "0", "", -0.2, 0.2);
2044  double *par = fitFcn->GetParameters();
2045  double *err = fitFcn->GetParErrors();
2046 
2047  maxs.push_back (par[0]);
2048  means.push_back (par[1]);
2049  sigmas.push_back (par[2]);
2050  Emaxs.push_back (err[0]);
2051  Emeans.push_back (err[1]);
2052  Esigmas.push_back (err[2]);
2053 
2054  double chi2 = fitFcn->GetChisquare();
2055  chi2s.push_back (chi2);
2056 
2057  double xx = histo->GetXaxis()->GetBinCenter(i);
2058  Xcenter.push_back (xx);
2059  double ex = 0; // FIXME: you can use the bin width
2060  Ex.push_back (ex);
2061  }
2062  }
2063 
2064  // Put the fit results in arrays for TGraphErrors
2065  // ----------------------------------------------
2066  const int nn = means.size();
2067  double *x = new double[nn];
2068  double *ym = new double[nn];
2069  double *e = new double[nn];
2070  double *eym = new double[nn];
2071  double *yw = new double[nn];
2072  double *eyw = new double[nn];
2073  double *yc = new double[nn];
2074 
2075  for (int j=0; j<nn; j++) {
2076  x[j] = Xcenter[j];
2077  ym[j] = means[j];
2078  eym[j] = Emeans[j];
2079  // yw[j] = maxs[j];
2080  // eyw[j] = Emaxs[j];
2081  yw[j] = sigmas[j];
2082  eyw[j] = Esigmas[j];
2083  yc[j] = chi2s[j];
2084  e[j] = Ex[j];
2085  }
2086 
2087  // Create TGraphErrors
2088  // -------------------
2089  TString name = histo->GetName();
2090  TGraphErrors *grM = new TGraphErrors (nn, x, ym, e, eym);
2091  grM->SetTitle (name+"_mean");
2092  grM->SetName (name+"_mean");
2093  TGraphErrors *grW = new TGraphErrors (nn, x, yw, e, eyw);
2094  grW->SetTitle (name+"_sigma");
2095  grW->SetName (name+"_sigma");
2096  TGraphErrors *grC = new TGraphErrors (nn, x, yc, e, e);
2097  grC->SetTitle (name+"_chi2");
2098  grC->SetName (name+"_chi2");
2099 
2100  // Cleanup
2101  // -------
2102  delete[] x;
2103  delete[] ym;
2104  delete[] eym;
2105  delete[] yw;
2106  delete[] eyw;
2107  delete[] yc;
2108  delete[] e;
2109  delete fitFcn;
2110 
2111  results.push_back (grM);
2112  results.push_back (grW);
2113  results.push_back (grC);
2114  return results;
2115 }
2116 
2117 // Mass probability for likelihood computation - no-background version (not used anymore)
2118 // --------------------------------------------------------------------------------------
2119 double MuScleFitUtils::massProb( const double & mass, const double & rapidity, const int ires, const double & massResol )
2120 {
2121  // This routine computes the likelihood that a given measured mass "measMass" is
2122  // the result of resonance #ires if the resolution expected for the two muons is massResol
2123  // ---------------------------------------------------------------------------------------
2124 
2125  double P = 0.;
2126 
2127  // Return Lorentz value for zero resolution cases (like MC)
2128  // --------------------------------------------------------
2129  if (massResol==0.) {
2130  if (debug>9) std::cout << "Mass, gamma , mref, width, P: " << mass
2131  << " " << ResGamma[ires] << " " << ResMass[ires]<< " " << massResol
2132  << " : used Lorentz P-value" << std::endl;
2133  return (0.5*ResGamma[ires]/TMath::Pi())/((mass-ResMass[ires])*(mass-ResMass[ires])+
2134  .25*ResGamma[ires]*ResGamma[ires]);
2135  }
2136 
2137  // NB defined as below, P is not a "probability" but a likelihood that we observe
2138  // a dimuon mass "mass", given mRef, gamma, and massResol. It is what we need for the
2139  // fit which finds the best resolution parameters, though. A definition which is
2140  // more properly a probability is given below (in massProb2()), where the result
2141  // cannot be used to fit resolution parameters because the fit would always prefer
2142  // to set the res parameters to the minimum possible value (best resolution),
2143  // to have a probability close to one of observing any mass.
2144  // -------------------------------------------------------------------------------
2145  // NNBB the following two lines have been replaced with the six following them,
2146  // which provide an improvement of a factor 9 in speed of execution at a
2147  // negligible price in precision.
2148  // ----------------------------------------------------------------------------
2149  // GL->SetParameters(gamma,mRef,mass,massResol);
2150  // P = GL->Integral(mass-5*massResol, mass+5*massResol);
2151 
2152  Int_t np = 100;
2153  double * x = new double[np];
2154  double * w = new double[np];
2155  GL->SetParameters (ResGamma[ires], ResMass[ires], mass, massResol);
2156  GL->CalcGaussLegendreSamplingPoints (np, x, w, 0.1e-15);
2157  P = GL->IntegralFast (np, x, w, ResMass[ires]-10*ResGamma[ires], ResMass[ires]+10*ResGamma[ires]);
2158  delete[] x;
2159  delete[] w;
2160 
2161  // If we are too far away we set P to epsilon and forget about this event
2162  // ----------------------------------------------------------------------
2163  if (P<1.0e-12) {
2164  P = 1.0e-12;
2165  if (debug>9) std::cout << "Mass, gamma , mref, width, P: " << mass
2166  << " " << ResGamma[ires] << " " << ResMass[ires] << " " << massResol
2167  << ": used epsilon" << std::endl;
2168  return P;
2169  }
2170 
2171  if (debug>9) std::cout << "Mass, gamma , mref, width, P: " << mass
2172  << " " << ResGamma[ires] << " " << ResMass[ires] << " " << massResol
2173  << " " << P << std::endl;
2174  return P;
2175 }
2176 
2177 std::pair<lorentzVector, lorentzVector> MuScleFitUtils::findSimMuFromRes( const edm::Handle<edm::HepMCProduct> & evtMC,
2178  const edm::Handle<edm::SimTrackContainer> & simTracks )
2179 {
2180  //Loop on simulated tracks
2181  std::pair<lorentzVector, lorentzVector> simMuFromRes;
2182  for( edm::SimTrackContainer::const_iterator simTrack=simTracks->begin(); simTrack!=simTracks->end(); ++simTrack ) {
2183  //Chose muons
2184  if (fabs((*simTrack).type())==13) {
2185  //If tracks from IP than find mother
2186  if ((*simTrack).genpartIndex()>0) {
2187  HepMC::GenParticle* gp = evtMC->GetEvent()->barcode_to_particle ((*simTrack).genpartIndex());
2188  if( gp != 0 ) {
2189 
2190  for (HepMC::GenVertex::particle_iterator mother = gp->production_vertex()->particles_begin(HepMC::ancestors);
2191  mother!=gp->production_vertex()->particles_end(HepMC::ancestors); ++mother) {
2192 
2193  bool fromRes = false;
2194  unsigned int motherPdgId = (*mother)->pdg_id();
2195  for( int ires = 0; ires < 6; ++ires ) {
2196  if( motherPdgId == motherPdgIdArray[ires] && resfind[ires] ) fromRes = true;
2197  }
2198  if( fromRes ) {
2199  if(gp->pdg_id() == 13)
2200  simMuFromRes.first = lorentzVector(simTrack->momentum().px(),simTrack->momentum().py(),
2201  simTrack->momentum().pz(),simTrack->momentum().e());
2202  else
2203  simMuFromRes.second = lorentzVector(simTrack->momentum().px(),simTrack->momentum().py(),
2204  simTrack->momentum().pz(),simTrack->momentum().e());
2205  }
2206  }
2207  }
2208  // else LogDebug("MuScleFitUtils") << "WARNING: no matching genParticle found for simTrack" << std::endl;
2209  }
2210  }
2211  }
2212  return simMuFromRes;
2213 }
2214 
2215 std::pair<lorentzVector, lorentzVector> MuScleFitUtils::findGenMuFromRes( const edm::HepMCProduct* evtMC )
2216 {
2217  const HepMC::GenEvent* Evt = evtMC->GetEvent();
2218  std::pair<lorentzVector,lorentzVector> muFromRes;
2219  //Loop on generated particles
2220  for (HepMC::GenEvent::particle_const_iterator part=Evt->particles_begin();
2221  part!=Evt->particles_end(); part++) {
2222  if (fabs((*part)->pdg_id())==13 && (*part)->status()==1) {
2223  bool fromRes = false;
2224  for (HepMC::GenVertex::particle_iterator mother = (*part)->production_vertex()->particles_begin(HepMC::ancestors);
2225  mother != (*part)->production_vertex()->particles_end(HepMC::ancestors); ++mother) {
2226  unsigned int motherPdgId = (*mother)->pdg_id();
2227 
2228  // For sherpa the resonance is not saved. The muons from the resonance can be identified
2229  // by having as mother a muon of status 3.
2230  if( sherpa_ ) {
2231  if( motherPdgId == 13 && (*mother)->status() == 3 ) fromRes = true;
2232  }
2233  else {
2234  for( int ires = 0; ires < 6; ++ires ) {
2235  if( motherPdgId == motherPdgIdArray[ires] && resfind[ires] ) fromRes = true;
2236  }
2237  }
2238  }
2239  if(fromRes){
2240  if((*part)->pdg_id()==13)
2241  // muFromRes.first = (*part)->momentum();
2242  muFromRes.first = (lorentzVector((*part)->momentum().px(),(*part)->momentum().py(),
2243  (*part)->momentum().pz(),(*part)->momentum().e()));
2244  else
2245  muFromRes.second = (lorentzVector((*part)->momentum().px(),(*part)->momentum().py(),
2246  (*part)->momentum().pz(),(*part)->momentum().e()));
2247  }
2248  }
2249  }
2250  return muFromRes;
2251 }
2252 
2253 std::pair<lorentzVector, lorentzVector> MuScleFitUtils::findGenMuFromRes( const reco::GenParticleCollection* genParticles)
2254 {
2255  std::pair<lorentzVector,lorentzVector> muFromRes;
2256 
2257  //Loop on generated particles
2258  if( debug>0 ) std::cout << "Starting loop on " << genParticles->size() << " genParticles" << std::endl;
2259  for( reco::GenParticleCollection::const_iterator part=genParticles->begin(); part!=genParticles->end(); ++part ) {
2260  if (fabs(part->pdgId())==13 && part->status()==1) {
2261  bool fromRes = false;
2262  unsigned int motherPdgId = part->mother()->pdgId();
2263  if( debug>0 ) {
2264  std::cout << "Found a muon with mother: " << motherPdgId << std::endl;
2265  }
2266  for( int ires = 0; ires < 6; ++ires ) {
2267  if( motherPdgId == motherPdgIdArray[ires] && resfind[ires] ) fromRes = true;
2268  }
2269  if(fromRes){
2270  if(part->pdgId()==13) {
2271  muFromRes.first = part->p4();
2272  if( debug>0 ) std::cout << "Found a genMuon + : " << muFromRes.first << std::endl;
2273  // muFromRes.first = (lorentzVector(part->p4().px(),part->p4().py(),
2274  // part->p4().pz(),part->p4().e()));
2275  }
2276  else {
2277  muFromRes.second = part->p4();
2278  if( debug>0 ) std::cout << "Found a genMuon - : " << muFromRes.second << std::endl;
2279  // muFromRes.second = (lorentzVector(part->p4().px(),part->p4().py(),
2280  // part->p4().pz(),part->p4().e()));
2281  }
2282  }
2283  }
2284  }
2285  return muFromRes;
2286 }
#define LogDebug(id)
static std::vector< std::pair< lorentzVector, lorentzVector > > simPair
const double Pi
static std::vector< int > doScaleFit
TF2 * GL2
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
static std::vector< int > doResolFit
static std::pair< lorentzVector, lorentzVector > findGenMuFromRes(const reco::GenParticleCollection *genParticles)
double sigmaPt(const U &track, const int i=0) const
The second, optional, parameter is the iteration number.
static double GLValue[6][1001][1001]
int i
Definition: DBlmapReader.cc:9
static std::vector< double > parBias
static std::vector< int > parCrossSectionOrder
static smearFunctionBase * smearFunction
static std::vector< int > parScaleOrder
static std::vector< int > doCrossSectionFit
static void minimizeLikelihood()
static double maxMuonEtaSecondRange_
Double_t Gaussian(Double_t *x, Double_t *par)
int regionsParNum()
Returns the total number of parameters used for the regions.
static std::vector< int > parBgrOrder
static std::vector< int > parfix
static double deltaPhiMaxCut_
static unsigned int loopCounter
double sigmaCotgTh(const U &track, const int i=0) const
The second, optional, parameter is the iteration number.
static std::vector< double > parResolMax
static std::pair< lorentzVector, lorentzVector > findSimMuFromRes(const edm::Handle< edm::HepMCProduct > &evtMC, const edm::Handle< edm::SimTrackContainer > &simTracks)
static int nbins
void likelihood(int &npar, double *grad, double &fval, double *xval, int flag)
static bool startWithSimplex_
static std::vector< int > doBackgroundFit
static std::vector< double > parResol
static bool debugMassResol_
void setParameters(double *Start, double *Step, double *Mini, double *Maxi, int *ind, TString *parname, const std::vector< double > &parCrossSection, const std::vector< int > &parCrossSectionOrder, const std::vector< int > &resfind)
Initializes the arrays needed by Minuit.
int ires[2]
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
static double ResMinMass[6]
static TH1D * backgroundProb_
virtual void smear(double &pt, double &eta, double &phi, const double *y, const std::vector< double > &parSmear)=0
static BackgroundHandler * backgroundHandler
static double x[7][10000]
std::pair< double, double > backgroundFunction(const bool doBackgroundFit, const double *parval, const int resTotNum, const int ires, const bool *resConsidered, const double *ResMass, const double ResHalfWidth[], const int MuonType, const double &mass, const double &eta1, const double &eta2)
static int debug
static std::vector< TGraphErrors * > fitMass(TH2F *histo)
static double ResMass[6]
static double massWindowHalfWidth[3][6]
TF1 * GL
static bool speedup
static bool scaleFitNotDone_
static unsigned int normalizationChanged_
#define P
static bool ResFound
static scaleFunctionBase< std::vector< double > > * biasFunction
double isum
static bool checkMassWindow(const double &mass, const double &leftBorder, const double &rightBorder)
Method to check if the mass value is within the mass window of the i-th resonance.
static std::vector< int > parBgrFix
static std::vector< double > parResolMin
static bool minimumShapePlots_
T eta() const
static int MuonTypeForCheckMassWindow
static double minMuonEtaFirstRange_
static double massProb(const double &mass, const double &rapidity, const int ires, const double &massResol)
static struct MuScleFitUtils::massResolComponentsStruct massResolComponents
static int BiasType
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
static std::vector< int > parScaleFix
static bool computeMinosErrors_
reco::Particle::LorentzVector lorentzVector
Definition: GenMuonPair.h:8
static scaleFunctionBase< std::vector< double > > * scaleFunctionForVec
def canvas
Definition: svgfig.py:481
static std::pair< SimTrack, SimTrack > findBestSimuRes(const std::vector< SimTrack > &simMuons)
static std::vector< std::vector< double > > parvalue
virtual double sigmaPt(const double &pt, const double &eta, const T &parval)=0
static double maxMuonPt_
static int ScaleFitType
static std::vector< std::pair< lorentzVector, lorentzVector > > genPair
static std::vector< std::pair< lorentzVector, lorentzVector > > ReducedSavedPair
static const int totalResNum
static const double muMass
static double massResolution(const lorentzVector &mu1, const lorentzVector &mu2)
int np
Definition: AMPTWrapper.h:33
static const unsigned int motherPdgIdArray[6]
static int minuitLoop_
virtual int parNum() const
Definition: Functions.h:3050
static std::vector< double > parScaleMin
static lorentzVector applyBias(const lorentzVector &muon, const int charge)
void rescale(std::vector< double > &parBgr, const double *ResMass, const double *massWindowHalfWidth, const std::vector< std::pair< reco::Particle::LorentzVector, reco::Particle::LorentzVector > > &muonPairs, const double &weight=1.)
T sqrt(T t)
Definition: SSEVec.h:48
static double GLZNorm[40][1001]
static std::vector< double > parBgr
bool check(const DataFrame &df, bool capcheck, bool dvercheck)
static int SmearType
virtual void setParameters(double *Start, double *Step, double *Mini, double *Maxi, int *ind, TString *parname, const T &parScale, const std::vector< int > &parScaleOrder, const int muonType)=0
This method is used to differentiate parameters among the different functions.
static lorentzVector fromPtEtaPhiToPxPyPz(const double *ptEtaPhiE)
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
virtual double covPt1Pt2(const double &pt1, const double &eta1, const double &pt2, const double &eta2, const T &parval)
Definition: Functions.h:3031
int j
Definition: DBlmapReader.cc:9
bool releaseParameters(TMinuit &rmin, const std::vector< int > &resfind, const std::vector< int > &parfix, const int *ind, const int iorder, const unsigned int shift)
Use the information in resfind, parorder and parfix to release the N-1 variables. ...
static double ResMaxSigma[6]
double f[11][100]
static double computeWeight(const double &mass, const int iev, const bool doUseBkgrWindow=false)
static std::vector< double > parScaleStep
static std::vector< std::pair< lorentzVector, lorentzVector > > SavedPair
static double invDimuonMass(const lorentzVector &mu1, const lorentzVector &mu2)
static lorentzVector applyScale(const lorentzVector &muon, const std::vector< double > &parval, const int charge)
static TH1D * signalProb_
static std::vector< int > parResolFix
static double GLZValue[40][1001][1001]
static TMinuit * rminPtr_
static std::vector< double > parSmear
virtual double scale(const double &pt, const double &eta, const double &phi, const int chg, const T &parScale) const =0
static std::vector< int > parResolOrder
double resMass(const bool doBackgroundFit, const int ires)
static bool sherpa_
static int BgrFitType
static TH1D * likelihoodInLoop_
static std::vector< double > parScaleMax
Definition: adjgraph.h:12
double sigmaPhi(const U &track, const int i=0) const
The second, optional, parameter is the iteration number.
static std::vector< double > parScale
static double oldNormalization_
virtual double sigmaCotgTh(const double &pt, const double &eta, const T &parval)=0
std::vector< double > relativeCrossSections(const double *variables, const std::vector< int > &resfind)
Perform a variable transformation from N-1 to relative cross sections.
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:35
void setParameters(double *Start, double *Step, double *Mini, double *Maxi, int *ind, TString *parname, const std::vector< double > &parBgr, const std::vector< int > &parBgrOrder, const int muonType)
Sets initial parameters for all the functions.
static bool duringMinos_
part
Definition: HCALResponse.h:20
static double ResGamma[6]
static double deltaPhiMinCut_
Double_t lorentzianPeak(Double_t *x, Double_t *par)
int iorder
static bool rapidityBinsForZ_
double mzsum
static int ResolFitType
int cont
static int goodmuon
static bool separateRanges_
static double minMuonEtaSecondRange_
static int iev_
static std::vector< double > parCrossSection
static const double mMu2
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
static double GLNorm[6][1001]
static std::vector< TGraphErrors * > fitReso(TH2F *histo)
tuple muons
Definition: patZpeak.py:38
static lorentzVector applySmearing(const lorentzVector &muon)
std::pair< double, double > windowBorders(const bool doBackgroundFit, const int ires)
Returns the appropriate window borders depending on whether the background is being fitted and on the...
static bool normalizeLikelihoodByEventNumber_
bool unlockParameter(const std::vector< int > &resfind, const unsigned int ipar)
returns true if the parameter is to be unlocked
static unsigned int const shift
virtual void setParameters(double *Start, double *Step, double *Mini, double *Maxi, int *ind, TString *parname, const T &parResol, const std::vector< int > &parResolOrder, const int muonType)
This method is used to differentiate parameters among the different functions.
Definition: Functions.h:3038
static int MuonType
tuple cout
Definition: gather_cfg.py:121
static double probability(const double &mass, const double &massResol, const double GLvalue[][1001][1001], const double GLnorm[][1001], const int iRes, const int iY)
Computes the probability given the mass, mass resolution and the arrays with the probabilities and th...
static double minMuonPt_
virtual double sigmaPhi(const double &pt, const double &eta, const T &parval)=0
T w() const
Definition: DDAxes.h:10
static scaleFunctionBase< double * > * scaleFunction
static bool useProbsFile_
int weight
Definition: histoStyle.py:50
static std::vector< int > resfind
virtual void resetParameters(std::vector< double > *scaleVec) const
This method is used to reset the scale parameters to neutral values (useful for iterations &gt; 0) ...
Definition: Functions.h:49
static double ResHalfWidth[6]
static int counter_resprob
static resolutionFunctionBase< std::vector< double > > * resolutionFunctionForVec
static std::vector< int > parorder
virtual int parNum() const
Definition: Functions.h:66
static int FitStrategy
static double maxMuonEtaFirstRange_
static std::pair< lorentzVector, lorentzVector > findBestRecoRes(const std::vector< reco::LeafCandidate > &muons)
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
static CrossSectionHandler * crossSectionHandler
static std::vector< double > parResolStep
static std::vector< int > parCrossSectionFix
static resolutionFunctionBase< double * > * resolutionFunction
Definition: DDAxes.h:10