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