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