CMS 3D CMS Logo

MuScleFit.cc
Go to the documentation of this file.
1 
5 // \class MuScleFit
6 // Fitter of momentum scale and resolution from resonance decays to muon track pairs
7 //
8 // \author R. Bellan, C.Mariotti, S.Bolognesi - INFN Torino / T.Dorigo, M.De Mattia - INFN Padova
9 // revised S. Casasso, E. Migliore - UniTo & INFN Torino
10 //
11 // Recent additions:
12 // - several parameters allow a more flexible use, tests, and control handles
13 // for the likelihood. In particular, a set of integers controls the order
14 // with which parameters are released; another controls which parameters are
15 // fixed. A function allows to smear momenta and angles of muons from the
16 // resonance before any correction, using a set of random numbers generated
17 // once and for all in the constructor (this way the smearing remains the same
18 // for any given muon no matter how many times one loops and what corrections
19 // one applies).
20 // For a correct use of these flags, please see the function minimizeLikelihood() in
21 // MuScleFitUtils.cc
22 // - the fit now allows to extract resolution functions simultaneously with the
23 // momentum scale. So far a simple parametrization
24 // of muon momentum resolution and angle resolution has been implemented, but
25 // extensions are straightforward.
26 // - It is however advisable to fit separately resolution and scale. The suggested
27 // course of action is:
28 // 1) fit the scale with a simple parametrization
29 // 2) check results, fit with more complicated forms
30 // 3) verify which is a sufficiently accurate description of the data
31 // 4) fix scale parameters and fit for the resolution
32 // 5) go back to fitting the scale with resolution parameters fixed to fitted values
33 // - Also note that resolution fits may fail to converge due to instability of the
34 // probability distribution to the limit of large widths. Improvements here are
35 // advisable.
36 // - The treatment of signal windows in the Y region
37 // has to be refined because of overlaps. More work is needed here, assigning a different
38 // weight to different hypothesis of the resonance producing a given mass, if there are
39 // multiple candidates.
40 // - Also, larger windows are to be allowed for fits to SA muons.
41 // - File Probs_1000.root contains the probability distribution of lorentzians convoluted
42 // with gaussian smearing functions, for the six resonances. A 1000x1000 grid
43 // in mass,sigma has been computed (using root macro Probs.C).
44 // A wider interval of masses for each resonance should be computed, to be used for standalone muons
45 //
46 //
47 // Notes on additions, TD 31/3/08
48 //
49 // - background model: at least a couple of different models, with two parameters,
50 // should be included in the fitting procedure such that the function massprob(),
51 // which produces the probability in the likelihood computation, incorporates the
52 // probability that the event is from background. That is, if the fitting function
53 // knows the shape of the mass spectrum ( say, a falling exponential plus a gaussian
54 // signal) it becomes possible to fit the scale together with the background shape
55 // and normalization parameters. Of course, one should do one thing at a time: first
56 // a scale fit, then a shape fit with scale parameters fixed, and then a combined
57 // fit. Convergence issues should be handled case by case.
58 // - The correct implementation of the above idea requires a reorganization of pass
59 // parameters (in the cfg) and fit parameters. The user has to be able to smear,
60 // bias, fix parameters, choose scale fitting functions, resolution fitting functions,
61 // and background functions. It should be possible to separate the fit functions from
62 // the biasing ones, which would allow a more thorough testing.
63 // - all the above can be obtained by making the .cfg instructions heavier. Since this
64 // is a routine operated by experts only, it is a sensible choice.
65 // - One should thus envision the following:
66 // 1) a set of parameters controlling the biasing function: parBias()
67 // 2) a set of parameters controlling the smearing function: parSmear()
68 // 3) a set of parameters to define resolution modeling and initial values: parResol()
69 // 3b) parResol() gets fix and order bits by parResolFix() and parResolOrder()
70 // 4) a set of parameters to define scale modeling and initial values: parScale()
71 // 4b) parScale() gets fix and order bits by parScaleFix() and parScaleOrder()
72 // 5) a set of parameters controlling the background shape and normalization: parNorm()
73 // 5b) parNorm() gets fix and order bits by parNormFix() and parNormOrder()
74 // The likelihood parameters then become a vector which is dynamically composed of
75 // sets 3), 4), and 5): parval() = parResol()+parScale()+parNorm()
76 // - In order to study better the likelihood behavior it would be advisable to introduce
77 // some histogram filling on the last iteration of the likelihood. It is not clear
78 // how best to achieve that: probably the simplest way is to make a histogram filling
79 // function run just after the likelihood computation, such that the best value of the
80 // fit parameters is used.
81 // - The muon pair which we call our resonance must be chosen in a way which does not
82 // bias our likelihood: we cannot just choose the pair closest to a resonance.
83 //
84 //
85 // Notes on additions, T.Dorigo 22/12/2008
86 // ---------------------------------------
87 //
88 // - File Probs_new_1000_CTEQ.root now contains a set of 24 additional two-dim histograms,
89 // defining the probability distribution of Z boson decays as a function of measured mass
90 // and expected sigma in 24 different bins of Z rapidity, extracted from CTEQ 6 PDF (at
91 // Leading Order) from the convolution in the factorization integral. See programs CTEQ.cpp
92 // and Fits.C.
93 // - The probability for Z boson events now thus depends on the measured rapidity of the dimuon
94 // system. All functions in file MuScleFitUtils.cc have been suitably changed.
95 //
96 // ----------------------------------------------------------------------------------
97 // Modifications by M. De Mattia 13/3/2009
98 // ---------------------------------------
99 // - The histograms map was moved to a base class (MuScleFitBase) from which this one inherits.
100 //
101 // Modifications by M. De Mattia 20/7/2009
102 // ---------------------------------------
103 // - Reworked background fit based on ranges. See comments in the code for more details.
104 // ---------------------------------------------------------------------------------------------
105 // Base Class Headers
106 // ------------------
113 
114 #include <CLHEP/Vector/LorentzVector.h>
115 #include <memory>
116 
117 #include <vector>
118 
122 
123 #include "MuScleFitBase.h"
124 #include "Histograms.h"
125 #include "MuScleFitPlotter.h"
130 #include "MuScleFitMuonSelector.h"
131 
136 
139 
145 
147 
148 #include "HepPDT/defs.h"
149 #include "HepPDT/TableBuilder.hh"
150 #include "HepPDT/ParticleDataTable.hh"
151 
152 #include "HepMC/GenParticle.h"
153 #include "HepMC/GenEvent.h"
154 
159 
163 
164 #include "TFile.h"
165 #include "TTree.h"
166 #include "TMinuit.h"
167 
168 // To use callgrind for code profiling uncomment also the following define.
169 // #define USE_CALLGRIND
170 
171 #ifdef USE_CALLGRIND
172 #include "valgrind/callgrind.h"
173 #endif
174 
175 // To read likelihood distributions from the database.
176 //#include "CondFormats/RecoMuonObjects/interface/MuScleFitLikelihoodPdf.h"
177 //#include "CondFormats/DataRecord/interface/MuScleFitLikelihoodPdfRcd.h"
178 
179 namespace edm {
180  class ParameterSet;
181  class Event;
182  class EventSetup;
183 } // namespace edm
184 
186 public:
187  // Constructor
188  // -----------
190 
191  // Destructor
192  // ----------
193  ~MuScleFit() override;
194 
195  // Operations
196  // ----------
198  // void beginOfJob( const edm::EventSetup& eventSetup );
199  // virtual void beginOfJob();
200  void endOfJob() override;
201 
202  void startingNewLoop(unsigned int iLoop) override;
203 
204  edm::EDLooper::Status endOfLoop(const edm::EventSetup& eventSetup, unsigned int iLoop) override;
205  virtual void endOfFastLoop(const unsigned int iLoop);
206 
212  virtual void duringFastLoop();
213 
214  template <typename T>
215  std::vector<MuScleFitMuon> fillMuonCollection(const std::vector<T>& tracks);
216 
217 private:
218 protected:
223  void selectMuons(const edm::Event& event);
229  void selectMuons(const int maxEvents, const TString& treeFileName);
230 
232  template <typename T>
233  void takeSelectedMuonType(const T& muon, std::vector<reco::Track>& tracks);
235  bool selGlobalMuon(const pat::Muon* aMuon);
236  bool selTrackerMuon(const pat::Muon* aMuon);
237 
242  const reco::Particle::LorentzVector& recoMu,
243  const std::string& inputName,
244  const int charge);
245 
250 
255  void checkParameters();
256 
258 
259  // Counters
260  // --------
265 
266  bool ifHepMC;
267  bool ifGenPart;
268 
269  // Constants
270  // ---------
273 
274  // Total number of loops
275  // ---------------------
276  unsigned int maxLoopNumber;
277  unsigned int loopCounter;
278 
279  bool fastLoop;
280 
282 
283  // The reconstructed muon 4-momenta to be put in the tree
284  // ------------------------------------------------------
287  int iev;
289 
292  bool PATmuons_;
294 
295  // Input Root Tree file name. If empty events are read from the edm root file.
297  // Output Root Tree file name. If not empty events are dumped to this file at the end of the last iteration.
299  // Maximum number of events from root tree. It works in the same way as the maxEvents to configure a input source.
301 
306 
309  std::vector<std::string> triggerPath_;
312 
313  // input collections for PU related infos
316 
317  std::unique_ptr<MuScleFitMuonSelector> muonSelector_;
318 };
319 
320 template <typename T>
321 std::vector<MuScleFitMuon> MuScleFit::fillMuonCollection(const std::vector<T>& tracks) {
322  std::vector<MuScleFitMuon> muons;
323  typename std::vector<T>::const_iterator track;
324  for (track = tracks.begin(); track != tracks.end(); ++track) {
327  track->px(), track->py(), track->pz(), sqrt(track->p() * track->p() + MuScleFitUtils::mMu2));
328  // Apply smearing if needed, and then bias
329  // ---------------------------------------
331  if (debug_ > 0)
332  std::cout << std::setprecision(9) << "Muon #" << MuScleFitUtils::goodmuon << ": initial value Pt = " << mu.Pt()
333  << std::endl;
334 
335  applySmearing(mu);
336  applyBias(mu, track->charge());
337  if (debug_ > 0)
338  std::cout << "track charge: " << track->charge() << std::endl;
339 
340  Double_t hitsTk = track->innerTrack()->hitPattern().numberOfValidTrackerHits();
341  Double_t hitsMuon = track->innerTrack()->hitPattern().numberOfValidMuonHits();
342  Double_t ptError = track->innerTrack()->ptError();
343  MuScleFitMuon muon(mu, track->charge(), ptError, hitsTk, hitsMuon, false);
344  if (debug_ > 0) {
345  std::cout << "[MuScleFit::fillMuonCollection]" << std::endl;
346  std::cout << " muon = " << muon << std::endl;
347  }
348 
349  // Store modified muon
350  // -------------------
351  muons.push_back(muon);
352  }
353  return muons;
354 }
355 
356 template <typename T>
357 void MuScleFit::takeSelectedMuonType(const T& muon, std::vector<reco::Track>& tracks) {
358  // std::cout<<"muon "<<muon->isGlobalMuon()<<muon->isStandAloneMuon()<<muon->isTrackerMuon()<<std::endl;
359  //NNBB: one muon can be of many kinds at once but with the theMuonType_ we are sure
360  // to avoid double counting of the same muon
361  if (muon->isGlobalMuon() && theMuonType_ == 1)
362  tracks.push_back(*(muon->globalTrack()));
363  else if (muon->isStandAloneMuon() && theMuonType_ == 2)
364  tracks.push_back(*(muon->outerTrack()));
365  else if (muon->isTrackerMuon() && theMuonType_ == 3)
366  tracks.push_back(*(muon->innerTrack()));
367 
368  else if (theMuonType_ == 10 && !(muon->isStandAloneMuon())) //particular case!!
369  tracks.push_back(*(muon->innerTrack()));
370  else if (theMuonType_ == 11 && muon->isGlobalMuon())
371  tracks.push_back(*(muon->innerTrack()));
372  else if (theMuonType_ == 13 && muon->isTrackerMuon())
373  tracks.push_back(*(muon->innerTrack()));
374 }
375 
376 // Constructor
377 // -----------
380  if (debug_ > 0)
381  std::cout << "[MuScleFit]: Constructor" << std::endl;
382 
383  if ((theMuonType_ < -4 || theMuonType_ > 5) && theMuonType_ < 10) {
384  std::cout << "[MuScleFit]: Unknown muon type! Aborting." << std::endl;
385  abort();
386  }
387 
388  loopCounter = 0;
389 
390  // Boundaries for h-function computation (to be improved!)
391  // -------------------------------------------------------
392  minResMass_hwindow[0] = 71.1876; // 76.;
393  maxResMass_hwindow[0] = 111.188; // 106.;
394  minResMass_hwindow[1] = 10.15;
395  maxResMass_hwindow[1] = 10.55;
396  minResMass_hwindow[2] = 9.8;
397  maxResMass_hwindow[2] = 10.2;
398  minResMass_hwindow[3] = 9.25;
399  maxResMass_hwindow[3] = 9.65;
400  minResMass_hwindow[4] = 3.58;
401  maxResMass_hwindow[4] = 3.78;
402  minResMass_hwindow[5] = 3.0;
403  maxResMass_hwindow[5] = 3.2;
404 
405  // Max number of loops (if > 2 then try to minimize likelihood more than once)
406  // ---------------------------------------------------------------------------
407  maxLoopNumber = pset.getUntrackedParameter<int>("maxLoopNumber", 2);
408  fastLoop = pset.getUntrackedParameter<bool>("FastLoop", true);
409 
410  // Selection of fits according to loop
411  MuScleFitUtils::doResolFit = pset.getParameter<std::vector<int> >("doResolFit");
412  MuScleFitUtils::doScaleFit = pset.getParameter<std::vector<int> >("doScaleFit");
413  MuScleFitUtils::doCrossSectionFit = pset.getParameter<std::vector<int> >("doCrossSectionFit");
414  MuScleFitUtils::doBackgroundFit = pset.getParameter<std::vector<int> >("doBackgroundFit");
415 
416  // Bias and smear types
417  // --------------------
418  int biasType = pset.getParameter<int>("BiasType");
419  MuScleFitUtils::BiasType = biasType;
420  // No error, the scale functions are used also for the bias
422  int smearType = pset.getParameter<int>("SmearType");
423  MuScleFitUtils::SmearType = smearType;
425 
426  // Fit types
427  // ---------
428  int resolFitType = pset.getParameter<int>("ResolFitType");
429  MuScleFitUtils::ResolFitType = resolFitType;
432  int scaleType = pset.getParameter<int>("ScaleFitType");
433  MuScleFitUtils::ScaleFitType = scaleType;
436 
437  // Initial parameters values
438  // -------------------------
439  MuScleFitUtils::parBias = pset.getParameter<std::vector<double> >("parBias");
440  MuScleFitUtils::parSmear = pset.getParameter<std::vector<double> >("parSmear");
441  MuScleFitUtils::parResol = pset.getParameter<std::vector<double> >("parResol");
443  pset.getUntrackedParameter<std::vector<double> >("parResolStep", std::vector<double>());
444  MuScleFitUtils::parResolMin = pset.getUntrackedParameter<std::vector<double> >("parResolMin", std::vector<double>());
445  MuScleFitUtils::parResolMax = pset.getUntrackedParameter<std::vector<double> >("parResolMax", std::vector<double>());
446  MuScleFitUtils::parScale = pset.getParameter<std::vector<double> >("parScale");
448  pset.getUntrackedParameter<std::vector<double> >("parScaleStep", std::vector<double>());
449  MuScleFitUtils::parScaleMin = pset.getUntrackedParameter<std::vector<double> >("parScaleMin", std::vector<double>());
450  MuScleFitUtils::parScaleMax = pset.getUntrackedParameter<std::vector<double> >("parScaleMax", std::vector<double>());
451  MuScleFitUtils::parCrossSection = pset.getParameter<std::vector<double> >("parCrossSection");
452  MuScleFitUtils::parBgr = pset.getParameter<std::vector<double> >("parBgr");
453  MuScleFitUtils::parResolFix = pset.getParameter<std::vector<int> >("parResolFix");
454  MuScleFitUtils::parScaleFix = pset.getParameter<std::vector<int> >("parScaleFix");
455  MuScleFitUtils::parCrossSectionFix = pset.getParameter<std::vector<int> >("parCrossSectionFix");
456  MuScleFitUtils::parBgrFix = pset.getParameter<std::vector<int> >("parBgrFix");
457  MuScleFitUtils::parResolOrder = pset.getParameter<std::vector<int> >("parResolOrder");
458  MuScleFitUtils::parScaleOrder = pset.getParameter<std::vector<int> >("parScaleOrder");
459  MuScleFitUtils::parCrossSectionOrder = pset.getParameter<std::vector<int> >("parCrossSectionOrder");
460  MuScleFitUtils::parBgrOrder = pset.getParameter<std::vector<int> >("parBgrOrder");
461 
462  MuScleFitUtils::resfind = pset.getParameter<std::vector<int> >("resfind");
463  MuScleFitUtils::FitStrategy = pset.getParameter<int>("FitStrategy");
464 
465  // Option to skip unnecessary stuff
466  // --------------------------------
467  MuScleFitUtils::speedup = pset.getParameter<bool>("speedup");
468 
469  // Option to skip simTracks comparison
470  compareToSimTracks_ = pset.getParameter<bool>("compareToSimTracks");
471  simTracksCollection_ = pset.getUntrackedParameter<edm::InputTag>("SimTracksCollection", edm::InputTag("g4SimHits"));
472 
473  triggerResultsLabel_ = pset.getUntrackedParameter<std::string>("TriggerResultsLabel");
474  triggerResultsProcess_ = pset.getUntrackedParameter<std::string>("TriggerResultsProcess");
475 
477  consumes<edm::TriggerResults>(edm::InputTag(triggerResultsLabel_.c_str(), "", triggerResultsProcess_.c_str()));
478 
479  triggerPath_ = pset.getUntrackedParameter<std::vector<std::string> >("TriggerPath");
480  negateTrigger_ = pset.getUntrackedParameter<bool>("NegateTrigger", false);
481  saveAllToTree_ = pset.getUntrackedParameter<bool>("SaveAllToTree", false);
482 
483  // input collections for PU related infos
484  puInfoSrc_ = pset.getUntrackedParameter<edm::InputTag>("PileUpSummaryInfo");
485  puInfoToken_ = consumes<std::vector<PileupSummaryInfo> >(puInfoSrc_);
486 
487  vertexSrc_ = pset.getUntrackedParameter<edm::InputTag>("PrimaryVertexCollection");
488  vertexToken_ = consumes<reco::VertexCollection>(vertexSrc_);
489 
490  genEvtInfoToken_ = consumes<GenEventInfoProduct>(edm::InputTag("generator"));
491 
492  PATmuons_ = pset.getUntrackedParameter<bool>("PATmuons", false);
493  genParticlesName_ = pset.getUntrackedParameter<std::string>("GenParticlesName", "genParticles");
494 
495  // Use the probability file or not. If not it will perform a simpler selection taking the muon pair with
496  // invariant mass closer to the pdf value and will crash if some fit is attempted.
497  MuScleFitUtils::useProbsFile_ = pset.getUntrackedParameter<bool>("UseProbsFile", true);
498 
499  // This must be set to true if using events generated with Sherpa
500  MuScleFitUtils::sherpa_ = pset.getUntrackedParameter<bool>("Sherpa", false);
501 
502  MuScleFitUtils::rapidityBinsForZ_ = pset.getUntrackedParameter<bool>("RapidityBinsForZ", true);
503 
504  // Set the cuts on muons to be used in the fit
505  MuScleFitUtils::separateRanges_ = pset.getUntrackedParameter<bool>("SeparateRanges", true);
506  MuScleFitUtils::maxMuonPt_ = pset.getUntrackedParameter<double>("MaxMuonPt", 100000000.);
507  MuScleFitUtils::minMuonPt_ = pset.getUntrackedParameter<double>("MinMuonPt", 0.);
508  MuScleFitUtils::minMuonEtaFirstRange_ = pset.getUntrackedParameter<double>("MinMuonEtaFirstRange", -6.);
509  MuScleFitUtils::maxMuonEtaFirstRange_ = pset.getUntrackedParameter<double>("MaxMuonEtaFirstRange", 6.);
510  MuScleFitUtils::minMuonEtaSecondRange_ = pset.getUntrackedParameter<double>("MinMuonEtaSecondRange", -100.);
511  MuScleFitUtils::maxMuonEtaSecondRange_ = pset.getUntrackedParameter<double>("MaxMuonEtaSecondRange", 100.);
512  MuScleFitUtils::deltaPhiMinCut_ = pset.getUntrackedParameter<double>("DeltaPhiMinCut", -100.);
513  MuScleFitUtils::deltaPhiMaxCut_ = pset.getUntrackedParameter<double>("DeltaPhiMaxCut", 100.);
514 
515  MuScleFitUtils::debugMassResol_ = pset.getUntrackedParameter<bool>("DebugMassResol", false);
516  // MuScleFitUtils::massResolComponentsStruct MuScleFitUtils::massResolComponents;
517 
518  // Check for parameters consistency
519  // it will abort in case of errors.
520  checkParameters();
521 
522  // Generate array of gaussian-distributed numbers for smearing
523  // -----------------------------------------------------------
524  if (MuScleFitUtils::SmearType > 0) {
525  std::cout << "[MuScleFit-Constructor]: Generating random values for smearing" << std::endl;
526  TF1 G("G", "[0]*exp(-0.5*pow(x,2))", -5., 5.);
527  double norm = 1 / sqrt(2 * TMath::Pi());
528  G.SetParameter(0, norm);
529  for (int i = 0; i < 10000; i++) {
530  for (int j = 0; j < 7; j++) {
531  MuScleFitUtils::x[j][i] = G.GetRandom();
532  }
533  }
534  }
536 
537  if (theMuonType_ > 0 && theMuonType_ < 4) {
540  } else if (theMuonType_ == 0 || theMuonType_ == 4 || theMuonType_ == 5 || theMuonType_ >= 10 || theMuonType_ == -1 ||
541  theMuonType_ == -2 || theMuonType_ == -3 || theMuonType_ == -4) {
544  } else {
545  std::cout << "Wrong muon type " << theMuonType_ << std::endl;
546  exit(1);
547  }
548 
549  // When using standalone muons switch to the single Z pdf
550  if (theMuonType_ == 2) {
552  }
553 
554  // Initialize ResMaxSigma And ResHalfWidth - 0 = global, 1 = SM, 2 = tracker
555  // -------------------------------------------------------------------------
574 
576  muonSelector_ = std::make_unique<MuScleFitMuonSelector>(iC,
578  theMuonType_,
579  PATmuons_,
586  debug_);
587 
589  new BackgroundHandler(pset.getParameter<std::vector<int> >("BgrFitType"),
590  pset.getParameter<std::vector<double> >("LeftWindowBorder"),
591  pset.getParameter<std::vector<double> >("RightWindowBorder"),
594 
597 
598  // Build cross section scale factors
599  // MuScleFitUtils::resfind
600 
602  pset.getUntrackedParameter<bool>("NormalizeLikelihoodByEventNumber", true);
603  if (debug_ > 0)
604  std::cout << "End of MuScleFit constructor" << std::endl;
605 
606  inputRootTreeFileName_ = pset.getParameter<std::string>("InputRootTreeFileName");
607  outputRootTreeFileName_ = pset.getParameter<std::string>("OutputRootTreeFileName");
608  maxEventsFromRootTree_ = pset.getParameter<int>("MaxEventsFromRootTree");
609 
610  MuScleFitUtils::startWithSimplex_ = pset.getParameter<bool>("StartWithSimplex");
611  MuScleFitUtils::computeMinosErrors_ = pset.getParameter<bool>("ComputeMinosErrors");
612  MuScleFitUtils::minimumShapePlots_ = pset.getParameter<bool>("MinimumShapePlots");
613 
615 }
616 
617 // Destructor
618 // ----------
620  if (debug_ > 0)
621  std::cout << "[MuScleFit]: Destructor" << std::endl;
622  std::cout << "Total number of analyzed events = " << totalEvents_ << std::endl;
623 
624  if (!(outputRootTreeFileName_.empty())) {
625  // Save the events to a root tree unless we are reading from the edm root file and the SavedPair size is different from the totalEvents_
627  std::cout << "Saving muon pairs to root tree" << std::endl;
628  RootTreeHandler rootTreeHandler;
630  // rootTreeHandler.writeTree(outputRootTreeFileName_, &(MuScleFitUtils::SavedPair), theMuonType_, 0, saveAllToTree_);
631  if (debug_ > 0) {
632  std::vector<MuonPair>::const_iterator it = muonPairs_.begin();
633  std::cout << "[MuScleFit::~MuScleFit] (Destructor)" << std::endl;
634  for (; it < muonPairs_.end(); ++it) {
635  std::cout << " Debugging pairs that are going to be written to file" << std::endl;
636  std::cout << " muon1 = " << it->mu1 << std::endl;
637  std::cout << " muon2 = " << it->mu2 << std::endl;
638  }
639  }
641  } else {
642  // rootTreeHandler.writeTree(outputRootTreeFileName_, &(MuScleFitUtils::SavedPair), theMuonType_, &(MuScleFitUtils::genPair), saveAllToTree_ );
643  rootTreeHandler.writeTree(
645  }
646  } else {
647  std::cout << "ERROR: events in the vector = " << MuScleFitUtils::SavedPair.size()
648  << " != totalEvents = " << totalEvents_ << std::endl;
649  }
650  }
651 }
652 
653 // Begin job
654 // ---------
656 // void MuScleFit::beginOfJob ()
657 // void MuScleFit::beginOfJob( const edm::EventSetup& eventSetup )
658 {
659  if (debug_ > 0)
660  std::cout << "[MuScleFit]: beginOfJob" << std::endl;
661  //if(maxLoopNumber>1)
664  }
665 
666  if (debug_ > 0)
667  std::cout << "[MuScleFit]: beginOfJob" << std::endl;
668 
669  // Create the root file
670  // --------------------
671  for (unsigned int i = 0; i < (maxLoopNumber); i++) {
672  std::stringstream ss;
673  ss << i;
675  if (theCompressionSettings_ > -1) {
676  theFiles_.push_back(new TFile(rootFileName.c_str(), "RECREATE", "", theCompressionSettings_));
677  } else {
678  theFiles_.push_back(new TFile(rootFileName.c_str(), "RECREATE"));
679  }
680  }
681  if (debug_ > 0)
682  std::cout << "[MuScleFit]: Root file created" << std::endl;
683 
684  std::cout << "creating plotter" << std::endl;
686  plotter->debug = debug_;
687 }
688 
689 // End of job method
690 // -----------------
692  if (debug_ > 0)
693  std::cout << "[MuScleFit]: endOfJob" << std::endl;
694 }
695 
696 // New loop
697 // --------
698 void MuScleFit::startingNewLoop(unsigned int iLoop) {
699  if (debug_ > 0)
700  std::cout << "[MuScleFit]: Starting loop # " << iLoop << std::endl;
701 
702  // Number of muons used
703  // --------------------
705 
706  // Counters for problem std::cout-ing
707  // -----------------------------
709 
710  // Create the root file
711  // --------------------
712  fillHistoMap(theFiles_[iLoop], iLoop);
713 
714  loopCounter = iLoop;
716 
717  iev = 0;
719 
721 }
722 
723 // End of loop routine
724 // -------------------
726  unsigned int iFastLoop = 1;
727 
728  // Read the events from the root tree if requested
729  if (!(inputRootTreeFileName_.empty())) {
731  // When reading from local file all the loops are done here
733  iFastLoop = 0;
734  } else {
735  endOfFastLoop(iLoop);
736  }
737 
738  // If a fastLoop is required we do all the remaining iterations here
739  if (fastLoop == true) {
740  for (; iFastLoop < maxLoopNumber; ++iFastLoop) {
741  std::cout << "Starting fast loop number " << iFastLoop << std::endl;
742 
743  // In the first loop is called by the framework
744  // if( iFastLoop > 0 ) {
745  startingNewLoop(iFastLoop);
746  // }
747 
748  // std::vector<std::pair<lorentzVector,lorentzVector> >::const_iterator it = MuScleFitUtils::SavedPair.begin();
749  // for( ; it != SavedPair.end(); ++it ) {
750  while (iev < totalEvents_) {
751  if (iev % 50000 == 0) {
752  std::cout << "Fast looping on event number " << iev << std::endl;
753  }
754  // This reads muons from SavedPair using iev to keep track of the event
755  duringFastLoop();
756  }
757  std::cout << "End of fast loop number " << iFastLoop << ". Ran on " << iev << " events" << std::endl;
758  endOfFastLoop(iFastLoop);
759  }
760  }
761 
762  if (iFastLoop >= maxLoopNumber - 1) {
763  return kStop;
764  } else {
765  return kContinue;
766  }
767 }
768 
769 void MuScleFit::endOfFastLoop(const unsigned int iLoop) {
770  // std::cout<< "Inside endOfFastLoop, iLoop = " << iLoop << " and loopCounter = " << loopCounter << std::endl;
771 
772  if (loopCounter == 0) {
773  // plotter->writeHistoMap();
774  // The destructor will call the writeHistoMap after the cd to the output file
775  delete plotter;
776  }
777 
778  std::cout << "Ending loop # " << iLoop << std::endl;
779 
780  // Write the histos to file
781  // ------------------------
782  // theFiles_[iLoop]->cd();
783  writeHistoMap(iLoop);
784 
785  // Likelihood minimization to compute corrections
786  // ----------------------------------------------
787  // theFiles_[iLoop]->cd();
788  TDirectory* likelihoodDir = theFiles_[iLoop]->mkdir("likelihood");
789  likelihoodDir->cd();
791 
792  // ATTENTION, this was put BEFORE the minimizeLikelihood. Check for problems.
793  theFiles_[iLoop]->Close();
794  // ATTENTION: Check that this delete does not give any problem
795  delete theFiles_[iLoop];
796 
797  // Clear the histos
798  // ----------------
799  clearHistoMap();
800 }
801 
802 // Stuff to do during loop
803 // -----------------------
806  bool isFired = false;
807 
808  if (triggerPath_[0].empty())
809  isFired = true;
810  else if (triggerPath_[0] == "All") {
811  isFired = triggerResults->accept();
812  if (debug_ > 0)
813  std::cout << "Trigger " << isFired << std::endl;
814  } else {
815  bool changed;
817  hltConfig.init(event.getRun(), eventSetup, triggerResultsProcess_, changed);
818 
819  const edm::TriggerNames& triggerNames = event.triggerNames(*triggerResults);
820 
821  for (unsigned i = 0; i < triggerNames.size(); i++) {
822  const std::string& hltName = triggerNames.triggerName(i);
823 
824  // match the path in the pset with the true name of the trigger
825  for (unsigned int ipath = 0; ipath < triggerPath_.size(); ipath++) {
826  if (hltName.find(triggerPath_[ipath]) != std::string::npos) {
827  unsigned int triggerIndex(hltConfig.triggerIndex(hltName));
828 
829  // triggerIndex must be less than the size of HLTR or you get a CMSException: _M_range_check
830  if (triggerIndex < triggerResults->size()) {
831  isFired = triggerResults->accept(triggerIndex);
832  if (debug_ > 0)
833  std::cout << triggerPath_[ipath] << " " << hltName << " " << isFired << std::endl;
834  }
835  } // end if (matching the path in the pset with the true trigger name
836  }
837  }
838  }
839 
840  if (negateTrigger_ && isFired)
841  return kContinue;
842  else if (!(negateTrigger_) && !isFired)
843  return kContinue;
844 
845 #ifdef USE_CALLGRIND
846  CALLGRIND_START_INSTRUMENTATION;
847 #endif
848 
849  if (debug_ > 0) {
850  std::cout << "[MuScleFit-duringLoop]: loopCounter = " << loopCounter << " Run: " << event.id().run()
851  << " Event: " << event.id().event() << std::endl;
852  }
853 
854  // On the first iteration we read the bank, otherwise we fetch the information from the muon tree
855  // ------------------------------------ Important Note --------------------------------------- //
856  // The fillMuonCollection method applies any smearing or bias to the muons, so we NEVER use
857  // unbiased muons.
858  // ----------------------------------------------------------------------------------------------
859  if (loopCounter == 0) {
860  if (!fastLoop || inputRootTreeFileName_.empty()) {
861  if (debug_ > 0)
862  std::cout << "Reading from edm event" << std::endl;
864  duringFastLoop();
865  ++totalEvents_;
866  }
867  }
868 
869  return kContinue;
870 
871 #ifdef USE_CALLGRIND
872  CALLGRIND_STOP_INSTRUMENTATION;
873  CALLGRIND_DUMP_STATS;
874 #endif
875 }
876 
880 
881  std::vector<MuScleFitMuon> muons;
883  // plotter->fillRec(muons); // @EM method already invoked inside MuScleFitMuonSelector::selectMuons()
884 
885  if (debug_ > 0) {
886  std::cout << "[MuScleFit::selectMuons] Debugging muons collections after call to muonSelector_->selectMuons"
887  << std::endl;
888  int iMu = 0;
889  for (std::vector<MuScleFitMuon>::const_iterator it = muons.begin(); it < muons.end(); ++it) {
890  std::cout << " - muon n. " << iMu << " = " << (*it) << std::endl;
891  ++iMu;
892  }
893  }
894 
895  // Find the two muons from the resonance, and set ResFound bool
896  // ------------------------------------------------------------
897  std::pair<MuScleFitMuon, MuScleFitMuon> recMuFromBestRes = MuScleFitUtils::findBestRecoRes(muons);
898 
900  if (debug_ > 0) {
901  std::cout << std::setprecision(9) << "Pt after findbestrecores: " << (recMuFromBestRes.first).Pt() << " "
902  << (recMuFromBestRes.second).Pt() << std::endl;
903  std::cout << "recMu1 = " << recMu1 << std::endl;
904  std::cout << "recMu2 = " << recMu2 << std::endl;
905  }
906  recMu1 = recMuFromBestRes.first.p4();
907  recMu2 = recMuFromBestRes.second.p4();
908  recMuScleMu1 = recMuFromBestRes.first;
909  recMuScleMu2 = recMuFromBestRes.second;
910 
911  if (debug_ > 0) {
912  std::cout << "after recMu1 = " << recMu1 << std::endl;
913  std::cout << "after recMu2 = " << recMu2 << std::endl;
914  std::cout << "mu1.pt = " << recMu1.Pt() << std::endl;
915  std::cout << "mu2.pt = " << recMu2.Pt() << std::endl;
916  std::cout << "after recMuScleMu1 = " << recMuScleMu1 << std::endl;
917  std::cout << "after recMuScleMu2 = " << recMuScleMu2 << std::endl;
918  }
919  MuScleFitUtils::SavedPair.push_back(std::make_pair(recMu1, recMu2));
921  } else {
922  MuScleFitUtils::SavedPair.push_back(std::make_pair(lorentzVector(0., 0., 0., 0.), lorentzVector(0., 0., 0., 0.)));
924  }
925  // Save the events also in the external tree so that it can be saved late
926 
927  // Fetch extra information (per event)
928  UInt_t the_NVtx(0);
929  Int_t the_numPUvtx(0);
930  Float_t the_TrueNumInteractions(0);
931 
932  // Fill pile-up related informations
933  // --------------------------------
934  edm::Handle<std::vector<PileupSummaryInfo> > puInfo = event.getHandle(puInfoToken_);
935  if (puInfo.isValid()) {
936  std::vector<PileupSummaryInfo>::const_iterator PVI;
937  for (PVI = puInfo->begin(); PVI != puInfo->end(); ++PVI) {
938  int BX = PVI->getBunchCrossing();
939  if (BX == 0) { // "0" is the in-time crossing, negative values are the early crossings, positive are late
940  the_TrueNumInteractions = PVI->getTrueNumInteractions();
941  the_numPUvtx = PVI->getPU_NumInteractions();
942  }
943  }
944  }
945 
947  if (vertices.isValid()) {
948  std::vector<reco::Vertex>::const_iterator itv;
949  // now, count vertices
950  for (itv = vertices->begin(); itv != vertices->end(); ++itv) {
951  // require that the vertex meets certain criteria
952  if (itv->ndof() < 5)
953  continue;
954  if (fabs(itv->z()) > 50.0)
955  continue;
956  if (fabs(itv->position().rho()) > 2.0)
957  continue;
958  ++the_NVtx;
959  }
960  }
961 
962  // get the MC event weight
963  edm::Handle<GenEventInfoProduct> genEvtInfo = event.getHandle(genEvtInfoToken_);
964  double the_genEvtweight = 1.;
965  if (genEvtInfo.isValid()) {
966  the_genEvtweight = genEvtInfo->weight();
967  }
968 
969  muonPairs_.push_back(MuonPair(
973  event.run(), event.id().event(), the_genEvtweight, the_numPUvtx, the_TrueNumInteractions, the_NVtx)));
974  // Fill the internal genPair tree from the external one
975  if (MuScleFitUtils::speedup == false) {
976  MuScleFitUtils::genPair.push_back(std::make_pair(genMuonPairs_.back().mu1.p4(), genMuonPairs_.back().mu2.p4()));
977  }
978 }
979 
980 void MuScleFit::selectMuons(const int maxEvents, const TString& treeFileName) {
981  std::cout << "Reading muon pairs from Root Tree in " << treeFileName << std::endl;
982  RootTreeHandler rootTreeHandler;
983  std::vector<std::pair<unsigned int, unsigned long long> > evtRun;
985  rootTreeHandler.readTree(
987  } else {
988  rootTreeHandler.readTree(maxEvents,
991  theMuonType_,
992  &evtRun,
994  }
995  // Now loop on all the pairs and apply any smearing and bias if needed
996  std::vector<std::pair<unsigned int, unsigned long long> >::iterator evtRunIt = evtRun.begin();
997  std::vector<std::pair<MuScleFitMuon, MuScleFitMuon> >::iterator it = MuScleFitUtils::SavedPairMuScleFitMuons.begin();
998  std::vector<std::pair<MuScleFitMuon, MuScleFitMuon> >::iterator genIt;
999  if (MuScleFitUtils::speedup == false)
1000  genIt = MuScleFitUtils::genMuscleFitPair.begin();
1001  for (; it != MuScleFitUtils::SavedPairMuScleFitMuons.end(); ++it, ++evtRunIt) {
1002  // Apply any cut if requested
1003  // Note that cuts here are only applied to already selected muons. They should not be used unless
1004  // you are sure that the difference is negligible (e.g. the number of events with > 2 muons is negligible).
1005  double pt1 = it->first.pt();
1006  //std::cout << "pt1 = " << pt1 << std::endl;
1007  double pt2 = it->second.pt();
1008  //std::cout << "pt2 = " << pt2 << std::endl;
1009  double eta1 = it->first.eta();
1010  //std::cout << "eta1 = " << eta1 << std::endl;
1011  double eta2 = it->second.eta();
1012  //std::cout << "eta2 = " << eta2 << std::endl;
1013  // If they don't pass the cuts set to null vectors
1014  bool dontPass = false;
1015  bool eta1InFirstRange;
1016  bool eta2InFirstRange;
1017  bool eta1InSecondRange;
1018  bool eta2InSecondRange;
1019 
1020  int ch1 = it->first.charge();
1021  int ch2 = it->second.charge();
1022 
1026  eta1InSecondRange =
1028  eta2InSecondRange =
1030 
1031  // This is my logic, which should be erroneous, but certainly simpler...
1034  ((eta1InFirstRange && eta2InSecondRange && ch1 >= ch2) ||
1035  (eta1InSecondRange && eta2InFirstRange && ch1 < ch2))))
1036  dontPass = true;
1037  } else {
1040  eta1InSecondRange =
1042  eta2InSecondRange =
1046  (((eta1InFirstRange && !eta2InFirstRange) && (eta2InSecondRange && !eta1InSecondRange) && ch1 >= ch2) ||
1047  ((eta2InFirstRange && !eta1InFirstRange) && (eta1InSecondRange && !eta2InSecondRange) && ch1 < ch2))))
1048  dontPass = true;
1049  }
1050 
1051  // Additional check on deltaPhi
1052  double deltaPhi = MuScleFitUtils::deltaPhi(it->first.phi(), it->second.phi());
1054  dontPass = true;
1055 
1056  lorentzVector vec1 = it->first.p4();
1057  lorentzVector vec2 = it->second.p4();
1058  if (ch1 >= ch2) {
1059  lorentzVector vectemp = vec1;
1060  vec1 = vec2;
1061  vec2 = vectemp;
1062  }
1063 
1064  if (!dontPass) {
1065  // First is always mu-, second mu+
1066  if ((MuScleFitUtils::SmearType != 0) || (MuScleFitUtils::BiasType != 0)) {
1068  applyBias(vec1, -1);
1070  applyBias(vec2, 1);
1071  }
1072 
1073  MuScleFitUtils::SavedPair.push_back(std::make_pair(vec1, vec2));
1074  }
1075 
1076  //FIXME: we loose the additional information besides the 4-momenta
1077  muonPairs_.push_back(MuonPair(
1078  MuScleFitMuon(vec1, -1),
1079  MuScleFitMuon(vec2, +1),
1081  (*evtRunIt).first, (*evtRunIt).second, 0, 0, 0, 0)) // FIXME: order of event and run number mixed up!
1082  );
1083 
1084  // Fill the internal genPair tree from the external one
1085  if (!MuScleFitUtils::speedup) {
1086  MuScleFitUtils::genPair.push_back(std::make_pair(genIt->first.p4(), genIt->second.p4()));
1087  genMuonPairs_.push_back(GenMuonPair(genIt->first.p4(), genIt->second.p4(), 0));
1088  ++genIt;
1089  }
1090  }
1092  if (!(MuScleFitUtils::speedup)) {
1094  }
1095 }
1096 
1098  // On loops>0 the two muons are directly obtained from the SavedMuon array
1099  // -----------------------------------------------------------------------
1100  MuScleFitUtils::ResFound = false;
1102  recMu2 = (MuScleFitUtils::SavedPair[iev].second);
1103 
1104  //std::cout << "iev = " << iev << ", recMu1 pt = " << recMu1.Pt() << ", recMu2 pt = " << recMu2.Pt() << std::endl;
1105 
1106  if (recMu1.Pt() > 0 && recMu2.Pt() > 0) {
1107  MuScleFitUtils::ResFound = true;
1108  if (debug_ > 0)
1109  std::cout << "Ev = " << iev << ": found muons in tree with Pt = " << recMu1.Pt() << " " << recMu2.Pt()
1110  << std::endl;
1111  }
1112 
1113  if (debug_ > 0)
1114  std::cout << "About to start lik par correction and histo filling; ResFound is " << MuScleFitUtils::ResFound
1115  << std::endl;
1116  // If resonance found, do the hard work
1117  // ------------------------------------
1119  // Find weight and reference mass for this muon pair
1120  // -------------------------------------------------
1121  // The last parameter = true means that we want to use always the background window to compute the weight,
1122  // otherwise the probability will be filled only for the resonance region.
1123  double weight = MuScleFitUtils::computeWeight((recMu1 + recMu2).mass(), iev, true);
1124  if (debug_ > 0) {
1125  std::cout << "Loop #" << loopCounter << "Event #" << iev << ": before correction Pt1 = " << recMu1.Pt()
1126  << " Pt2 = " << recMu2.Pt() << std::endl;
1127  }
1128  // For successive iterations, correct the muons only if the previous iteration was a scale fit.
1129  // --------------------------------------------------------------------------------------------
1130  if (loopCounter > 0) {
1134  }
1135  }
1136  if (debug_ > 0) {
1137  std::cout << "Loop #" << loopCounter << "Event #" << iev << ": after correction Pt1 = " << recMu1.Pt()
1138  << " Pt2 = " << recMu2.Pt() << std::endl;
1139  }
1140 
1142 
1143  //Fill histograms
1144  //------------------
1145 
1146  mapHisto_["hRecBestMu"]->Fill(recMu1, -1, weight);
1147  mapHisto_["hRecBestMuVSEta"]->Fill(recMu1);
1148  mapHisto_["hRecBestMu"]->Fill(recMu2, +1, weight);
1149  mapHisto_["hRecBestMuVSEta"]->Fill(recMu2);
1150  mapHisto_["hDeltaRecBestMu"]->Fill(recMu1, recMu2);
1151  // Reconstructed resonance
1152  mapHisto_["hRecBestRes"]->Fill(bestRecRes, +1, weight);
1153  mapHisto_["hRecBestResAllEvents"]->Fill(bestRecRes, +1, 1.);
1154  // // Fill histogram of Res mass vs muon variables
1155  // mapHisto_["hRecBestResVSMu"]->Fill (recMu1, bestRecRes, -1);
1156  // mapHisto_["hRecBestResVSMu"]->Fill (recMu2, bestRecRes, +1);
1157  // // Fill also the mass mu+/mu- comparisons
1158  // mapHisto_["hRecBestResVSMu"]->Fill(recMu1, recMu2, bestRecRes);
1159 
1160  mapHisto_["hRecBestResVSMu"]->Fill(recMu1, bestRecRes, -1, weight);
1161  mapHisto_["hRecBestResVSMu"]->Fill(recMu2, bestRecRes, +1, weight);
1162  // Fill also the mass mu+/mu- comparisons
1163  mapHisto_["hRecBestResVSMu"]->Fill(recMu1, recMu2, bestRecRes, weight);
1164 
1165  //-- rc 2010 filling histograms for mu+ /mu- ------
1166  // mapHisto_["hRecBestResVSMuMinus"]->Fill (recMu1, bestRecRes, -1);
1167  // mapHisto_["hRecBestResVSMuPlus"]->Fill (recMu2, bestRecRes, +1);
1168 
1169  //-- rc 2010 filling histograms MassVsMuEtaPhi------
1170  // mapHisto_["hRecBestResVSMuEtaPhi"]->Fill (recMu1, bestRecRes,-1);
1171  // mapHisto_["hRecBestResVSMuEtaPhi"]->Fill (recMu2, bestRecRes,+1);
1172 
1173  // Fill histogram of Res mass vs Res variables
1174  // mapHisto_["hRecBestResVSRes"]->Fill (bestRecRes, bestRecRes, +1);
1175  mapHisto_["hRecBestResVSRes"]->Fill(bestRecRes, bestRecRes, +1, weight);
1176 
1177  std::vector<double>* parval;
1178  std::vector<double> initpar;
1179  // Store a pointer to the vector of parameters of the last iteration, or the initial
1180  // parameters if this is the first iteration
1181  if (loopCounter == 0) {
1182  initpar = MuScleFitUtils::parResol;
1183  initpar.insert(initpar.end(), MuScleFitUtils::parScale.begin(), MuScleFitUtils::parScale.end());
1184  initpar.insert(initpar.end(), MuScleFitUtils::parCrossSection.begin(), MuScleFitUtils::parCrossSection.end());
1185  initpar.insert(initpar.end(), MuScleFitUtils::parBgr.begin(), MuScleFitUtils::parBgr.end());
1186  parval = &initpar;
1187  } else {
1188  parval = &(MuScleFitUtils::parvalue[loopCounter - 1]);
1189  }
1190 
1191  //Compute pt resolution w.r.t generated and simulated muons
1192  //--------------------------------------------------------
1193  if (!MuScleFitUtils::speedup) {
1194  //first is always mu-, second is always mu+
1197  }
1200  }
1201  if (compareToSimTracks_) {
1202  //first is always mu-, second is always mu+
1205  }
1208  }
1209  }
1210  }
1211 
1212  // ATTENTION: this was done only when a matching was found. Moved it outside because, genInfo or not, we still want to see the resolution function
1213  // Fill also the resolution histogramsm using the resolution functions:
1214  // the parameters are those from the last iteration, as the muons up to this point have also the corrections from the same iteration.
1215  // Need to use a different array (ForVec), containing functors able to operate on std::vector<double>
1216  mapHisto_["hFunctionResolPt"]->Fill(
1217  recMu1, MuScleFitUtils::resolutionFunctionForVec->sigmaPt(recMu1.Pt(), recMu1.Eta(), *parval), -1);
1218  mapHisto_["hFunctionResolCotgTheta"]->Fill(
1219  recMu1, MuScleFitUtils::resolutionFunctionForVec->sigmaCotgTh(recMu1.Pt(), recMu1.Eta(), *parval), -1);
1220  mapHisto_["hFunctionResolPhi"]->Fill(
1221  recMu1, MuScleFitUtils::resolutionFunctionForVec->sigmaPhi(recMu1.Pt(), recMu1.Eta(), *parval), -1);
1222  mapHisto_["hFunctionResolPt"]->Fill(
1223  recMu2, MuScleFitUtils::resolutionFunctionForVec->sigmaPt(recMu2.Pt(), recMu2.Eta(), *parval), +1);
1224  mapHisto_["hFunctionResolCotgTheta"]->Fill(
1225  recMu2, MuScleFitUtils::resolutionFunctionForVec->sigmaCotgTh(recMu2.Pt(), recMu2.Eta(), *parval), +1);
1226  mapHisto_["hFunctionResolPhi"]->Fill(
1227  recMu2, MuScleFitUtils::resolutionFunctionForVec->sigmaPhi(recMu2.Pt(), recMu2.Eta(), *parval), +1);
1228 
1229  // Compute likelihood histograms
1230  // -----------------------------
1231  if (debug_ > 0)
1232  std::cout << "mass = " << bestRecRes.mass() << std::endl;
1233  if (weight != 0.) {
1234  double massResol;
1235  double prob;
1236  double deltalike;
1237  if (loopCounter == 0) {
1238  std::vector<double> initpar;
1239  initpar.reserve((int)(MuScleFitUtils::parResol.size()));
1240  for (int i = 0; i < (int)(MuScleFitUtils::parResol.size()); i++) {
1241  initpar.push_back(MuScleFitUtils::parResol[i]);
1242  }
1243  for (int i = 0; i < (int)(MuScleFitUtils::parScale.size()); i++) {
1244  initpar.push_back(MuScleFitUtils::parScale[i]);
1245  }
1246  // for (int i=0; i<(int)(MuScleFitUtils::parCrossSection.size()); i++) {
1247  // initpar.push_back(MuScleFitUtils::parCrossSection[i]);
1248  // }
1250 
1251  for (int i = 0; i < (int)(MuScleFitUtils::parBgr.size()); i++) {
1252  initpar.push_back(MuScleFitUtils::parBgr[i]);
1253  }
1254  massResol = MuScleFitUtils::massResolution(recMu1, recMu2, initpar);
1255  // prob = MuScleFitUtils::massProb( bestRecRes.mass(), bestRecRes.Eta(), bestRecRes.Rapidity(), massResol, initpar, true );
1256  prob = MuScleFitUtils::massProb(bestRecRes.mass(),
1257  bestRecRes.Eta(),
1258  bestRecRes.Rapidity(),
1259  massResol,
1260  initpar,
1261  true,
1262  recMu1.eta(),
1263  recMu2.eta());
1264  } else {
1266  // prob = MuScleFitUtils::massProb( bestRecRes.mass(), bestRecRes.Eta(), bestRecRes.Rapidity(),
1267  // massResol, MuScleFitUtils::parvalue[loopCounter-1], true );
1268  prob = MuScleFitUtils::massProb(bestRecRes.mass(),
1269  bestRecRes.Eta(),
1270  bestRecRes.Rapidity(),
1271  massResol,
1273  true,
1274  recMu1.eta(),
1275  recMu2.eta());
1276  }
1277  if (debug_ > 0)
1278  std::cout << "inside weight: mass = " << bestRecRes.mass() << ", prob = " << prob << std::endl;
1279  if (prob > 0) {
1280  if (debug_ > 0)
1281  std::cout << "inside prob: mass = " << bestRecRes.mass() << ", prob = " << prob << std::endl;
1282 
1283  deltalike = log(prob) * weight; // NB maximum likelihood --> deltalike is maximized
1284  mapHisto_["hLikeVSMu"]->Fill(recMu1, deltalike);
1285  mapHisto_["hLikeVSMu"]->Fill(recMu2, deltalike);
1286  mapHisto_["hLikeVSMuMinus"]->Fill(recMu1, deltalike);
1287  mapHisto_["hLikeVSMuPlus"]->Fill(recMu2, deltalike);
1288 
1289  double recoMass = (recMu1 + recMu2).mass();
1290  if (recoMass != 0) {
1291  // IMPORTANT: massResol is not a relative resolution
1292  mapHisto_["hResolMassVSMu"]->Fill(recMu1, massResol, -1);
1293  mapHisto_["hResolMassVSMu"]->Fill(recMu2, massResol, +1);
1294  mapHisto_["hFunctionResolMassVSMu"]->Fill(recMu1, massResol / recoMass, -1);
1295  mapHisto_["hFunctionResolMassVSMu"]->Fill(recMu2, massResol / recoMass, +1);
1296  }
1297 
1299  mapHisto_["hdMdPt1"]->Fill(recMu1, MuScleFitUtils::massResolComponents.dmdpt1, -1);
1300  mapHisto_["hdMdPt2"]->Fill(recMu2, MuScleFitUtils::massResolComponents.dmdpt2, +1);
1301  mapHisto_["hdMdPhi1"]->Fill(recMu1, MuScleFitUtils::massResolComponents.dmdphi1, -1);
1302  mapHisto_["hdMdPhi2"]->Fill(recMu2, MuScleFitUtils::massResolComponents.dmdphi2, +1);
1303  mapHisto_["hdMdCotgTh1"]->Fill(recMu1, MuScleFitUtils::massResolComponents.dmdcotgth1, -1);
1304  mapHisto_["hdMdCotgTh2"]->Fill(recMu2, MuScleFitUtils::massResolComponents.dmdcotgth2, +1);
1305  }
1306 
1307  if (!MuScleFitUtils::speedup) {
1308  double genMass = (MuScleFitUtils::genPair[iev].first + MuScleFitUtils::genPair[iev].second).mass();
1309  // Fill the mass resolution (computed from MC), we use the covariance class to compute the variance
1310  if (genMass != 0) {
1311  mapHisto_["hGenResVSMu"]->Fill((MuScleFitUtils::genPair[iev].first),
1313  -1);
1314  mapHisto_["hGenResVSMu"]->Fill((MuScleFitUtils::genPair[iev].second),
1316  +1);
1317  double diffMass = (recoMass - genMass) / genMass;
1318  // double diffMass = recoMass - genMass;
1319  // Fill if for both muons
1320  double pt1 = recMu1.pt();
1321  double eta1 = recMu1.eta();
1322  double pt2 = recMu2.pt();
1323  double eta2 = recMu2.eta();
1324  // This is to avoid nan
1325  if (diffMass == diffMass) {
1326  // Mass relative difference vs Pt and Eta. To be used to extract the true mass resolution
1327  mapHisto_["hDeltaMassOverGenMassVsPt"]->Fill(pt1, diffMass);
1328  mapHisto_["hDeltaMassOverGenMassVsPt"]->Fill(pt2, diffMass);
1329  mapHisto_["hDeltaMassOverGenMassVsEta"]->Fill(eta1, diffMass);
1330  mapHisto_["hDeltaMassOverGenMassVsEta"]->Fill(eta2, diffMass);
1331  // This is used for the covariance comparison
1332  mapHisto_["hMassResolutionVsPtEta"]->Fill(pt1, eta1, diffMass, diffMass);
1333  mapHisto_["hMassResolutionVsPtEta"]->Fill(pt2, eta2, diffMass, diffMass);
1334  } else {
1335  std::cout << "Error, there is a nan: recoMass = " << recoMass << ", genMass = " << genMass << std::endl;
1336  }
1337  }
1338  // Fill with mass resolution from resolution function
1340  mapHisto_["hFunctionResolMass"]->Fill(recMu1, std::pow(massRes, 2), -1);
1341  mapHisto_["hFunctionResolMass"]->Fill(recMu2, std::pow(massRes, 2), +1);
1342  }
1343 
1344  mapHisto_["hMass_P"]->Fill(bestRecRes.mass(), prob);
1345  if (debug_ > 0)
1346  std::cout << "mass = " << bestRecRes.mass() << ", prob = " << prob << std::endl;
1347  mapHisto_["hMass_fine_P"]->Fill(bestRecRes.mass(), prob);
1348 
1349  mapHisto_["hMassProbVsRes"]->Fill(bestRecRes, bestRecRes, +1, prob);
1350  mapHisto_["hMassProbVsMu"]->Fill(recMu1, bestRecRes, -1, prob);
1351  mapHisto_["hMassProbVsMu"]->Fill(recMu2, bestRecRes, +1, prob);
1352  mapHisto_["hMassProbVsRes_fine"]->Fill(bestRecRes, bestRecRes, +1, prob);
1353  mapHisto_["hMassProbVsMu_fine"]->Fill(recMu1, bestRecRes, -1, prob);
1354  mapHisto_["hMassProbVsMu_fine"]->Fill(recMu2, bestRecRes, +1, prob);
1355  }
1356  }
1357  } // end if ResFound
1358 
1359  // Fill the pair
1360  // -------------
1361  if (loopCounter > 0) {
1362  if (debug_ > 0)
1363  std::cout << "[MuScleFit]: filling the pair" << std::endl;
1364  MuScleFitUtils::SavedPair[iev] = std::make_pair(recMu1, recMu2);
1365  }
1366 
1367  iev++;
1369 
1370  // return kContinue;
1371 }
1372 
1374  //first is always mu-, second is always mu+
1375  double deltaR =
1376  sqrt(MuScleFitUtils::deltaPhi(recMu.Phi(), genMu.Phi()) * MuScleFitUtils::deltaPhi(recMu.Phi(), genMu.Phi()) +
1377  ((recMu.Eta() - genMu.Eta()) * (recMu.Eta() - genMu.Eta())));
1378  if (deltaR < 0.01)
1379  return true;
1380  else if (debug_ > 0) {
1381  std::cout << "Reco muon " << recMu << " with eta " << recMu.Eta() << " and phi " << recMu.Phi() << std::endl
1382  << " DOES NOT MATCH with generated muon from resonance: " << std::endl
1383  << genMu << " with eta " << genMu.Eta() << " and phi " << genMu.Phi() << std::endl;
1384  }
1385  return false;
1386 }
1387 
1389  const reco::Particle::LorentzVector& recMu,
1390  const std::string& inputName,
1391  const int charge) {
1392  std::string name(inputName + "VSMu");
1393  mapHisto_["hResolPt" + name]->Fill(recMu, (-genMu.Pt() + recMu.Pt()) / genMu.Pt(), charge);
1394  mapHisto_["hResolTheta" + name]->Fill(recMu, (-genMu.Theta() + recMu.Theta()), charge);
1395  mapHisto_["hResolCotgTheta" + name]->Fill(
1396  recMu, (-cos(genMu.Theta()) / sin(genMu.Theta()) + cos(recMu.Theta()) / sin(recMu.Theta())), charge);
1397  mapHisto_["hResolEta" + name]->Fill(recMu, (-genMu.Eta() + recMu.Eta()), charge);
1398  mapHisto_["hResolPhi" + name]->Fill(recMu, MuScleFitUtils::deltaPhiNoFabs(recMu.Phi(), genMu.Phi()), charge);
1399 
1400  // Fill only if it was matched to a genMu and this muon is valid
1401  if ((genMu.Pt() != 0) && (recMu.Pt() != 0)) {
1402  mapHisto_["hPtRecoVsPt" + inputName]->Fill(genMu.Pt(), recMu.Pt());
1403  }
1404 }
1405 
1407  if (MuScleFitUtils::SmearType > 0) {
1409  if (debug_ > 0)
1410  std::cout << "Muon #" << MuScleFitUtils::goodmuon << ": after smearing Pt = " << mu.Pt() << std::endl;
1411  }
1412 }
1413 
1415  if (MuScleFitUtils::BiasType > 0) {
1417  if (debug_ > 0)
1418  std::cout << "Muon #" << MuScleFitUtils::goodmuon << ": after bias Pt = " << mu.Pt() << std::endl;
1419  }
1420 }
1421 
1422 // Simple method to check parameters consistency. It aborts the job if the parameters
1423 // are not consistent.
1425  // Fits selection dimension check
1427  std::cout << "[MuScleFit-Constructor]: wrong size of resolution fits selector = "
1428  << MuScleFitUtils::doResolFit.size() << std::endl;
1429  std::cout << "it must have as many values as the number of loops, which is = " << maxLoopNumber << std::endl;
1430  abort();
1431  }
1433  std::cout << "[MuScleFit-Constructor]: wrong size of scale fits selector = " << MuScleFitUtils::doScaleFit.size()
1434  << std::endl;
1435  std::cout << "it must have as many values as the number of loops, which is = " << maxLoopNumber << std::endl;
1436  abort();
1437  }
1439  std::cout << "[MuScleFit-Constructor]: wrong size of cross section fits selector = "
1440  << MuScleFitUtils::doCrossSectionFit.size() << std::endl;
1441  std::cout << "it must have as many values as the number of loops, which is = " << maxLoopNumber << std::endl;
1442  abort();
1443  }
1445  std::cout << "[MuScleFit-Constructor]: wrong size of background fits selector = "
1446  << MuScleFitUtils::doBackgroundFit.size() << std::endl;
1447  std::cout << "it must have as many values as the number of loops, which is = " << maxLoopNumber << std::endl;
1448  abort();
1449  }
1450 
1451  // Bias parameters: dimension check
1452  // --------------------------------
1453  if ((MuScleFitUtils::BiasType == 1 && MuScleFitUtils::parBias.size() != 2) || // linear in pt
1454  (MuScleFitUtils::BiasType == 2 && MuScleFitUtils::parBias.size() != 2) || // linear in |eta|
1455  (MuScleFitUtils::BiasType == 3 && MuScleFitUtils::parBias.size() != 4) || // sinusoidal in phi
1456  (MuScleFitUtils::BiasType == 4 && MuScleFitUtils::parBias.size() != 3) || // linear in pt and |eta|
1457  (MuScleFitUtils::BiasType == 5 && MuScleFitUtils::parBias.size() != 3) || // linear in pt and sinusoidal in phi
1458  (MuScleFitUtils::BiasType == 6 &&
1459  MuScleFitUtils::parBias.size() != 3) || // linear in |eta| and sinusoidal in phi
1460  (MuScleFitUtils::BiasType == 7 &&
1461  MuScleFitUtils::parBias.size() != 4) || // linear in pt and |eta| and sinusoidal in phi
1462  (MuScleFitUtils::BiasType == 8 && MuScleFitUtils::parBias.size() != 4) || // linear in pt and parabolic in |eta|
1463  (MuScleFitUtils::BiasType == 9 && MuScleFitUtils::parBias.size() != 2) || // exponential in pt
1464  (MuScleFitUtils::BiasType == 10 && MuScleFitUtils::parBias.size() != 3) || // parabolic in pt
1465  (MuScleFitUtils::BiasType == 11 &&
1466  MuScleFitUtils::parBias.size() != 4) || // linear in pt and sin in phi with chg
1467  (MuScleFitUtils::BiasType == 12 &&
1468  MuScleFitUtils::parBias.size() != 6) || // linear in pt and para in plus sin in phi with chg
1469  (MuScleFitUtils::BiasType == 13 &&
1470  MuScleFitUtils::parBias.size() != 8) || // linear in pt and para in plus sin in phi with chg
1472  MuScleFitUtils::BiasType > 13) {
1473  std::cout << "[MuScleFit-Constructor]: Wrong bias type or number of parameters: aborting!" << std::endl;
1474  abort();
1475  }
1476  // Smear parameters: dimension check
1477  // ---------------------------------
1486  std::cout << "[MuScleFit-Constructor]: Wrong smear type or number of parameters: aborting!" << std::endl;
1487  abort();
1488  }
1489  // Protect against bad size of parameters
1490  // --------------------------------------
1493  std::cout << "[MuScleFit-Constructor]: Mismatch in number of parameters for Resol: aborting!" << std::endl;
1494  abort();
1495  }
1498  std::cout << "[MuScleFit-Constructor]: Mismatch in number of parameters for Scale: aborting!" << std::endl;
1499  abort();
1500  }
1503  std::cout << "[MuScleFit-Constructor]: Mismatch in number of parameters for Bgr: aborting!" << std::endl;
1504  abort();
1505  }
1508  std::cout << "[MuScleFit-Constructor]: Mismatch in number of parameters for Bgr: aborting!" << std::endl;
1509  abort();
1510  }
1511 
1512  // Protect against an incorrect number of resonances
1513  // -------------------------------------------------
1514  if (MuScleFitUtils::resfind.size() != 6) {
1515  std::cout << "[MuScleFit-Constructor]: resfind must have 6 elements (1 Z, 3 Y, 2 Psi): aborting!" << std::endl;
1516  abort();
1517  }
1518 }
1519 
1521  reco::TrackRef iTrack = aMuon->innerTrack();
1522  const reco::HitPattern& p = iTrack->hitPattern();
1523 
1524  reco::TrackRef gTrack = aMuon->globalTrack();
1525  const reco::HitPattern& q = gTrack->hitPattern();
1526 
1527  return ( //isMuonInAccept(aMuon) &&// no acceptance cuts!
1528  iTrack->found() > 11 && gTrack->chi2() / gTrack->ndof() < 20.0 && q.numberOfValidMuonHits() > 0 &&
1529  iTrack->chi2() / iTrack->ndof() < 4.0 && aMuon->muonID("TrackerMuonArbitrated") &&
1530  aMuon->muonID("TMLastStationAngTight") && p.pixelLayersWithMeasurement() > 1 &&
1531  fabs(iTrack->dxy()) < 3.0 && //should be done w.r.t. PV!
1532  fabs(iTrack->dz()) < 15.0); //should be done w.r.t. PV!
1533 }
1534 
1536  reco::TrackRef iTrack = aMuon->innerTrack();
1537  const reco::HitPattern& p = iTrack->hitPattern();
1538 
1539  return ( //isMuonInAccept(aMuon) // no acceptance cuts!
1540  iTrack->found() > 11 && iTrack->chi2() / iTrack->ndof() < 4.0 && aMuon->muonID("TrackerMuonArbitrated") &&
1541  aMuon->muonID("TMLastStationAngTight") && p.pixelLayersWithMeasurement() > 1 &&
1542  fabs(iTrack->dxy()) < 3.0 && //should be done w.r.t. PV!
1543  fabs(iTrack->dz()) < 15.0); //should be done w.r.t. PV!
1544 }
1545 
static double deltaPhiNoFabs(const double &phi1, const double &phi2)
Without fabs at the end, used to have a symmetric distribution for the resolution fits and variance c...
size
Write out results.
static std::vector< std::pair< lorentzVector, lorentzVector > > simPair
const double Pi
static std::vector< int > doScaleFit
static std::vector< int > doResolFit
static std::vector< double > parBias
void selectMuons(const edm::Event &event)
Definition: MuScleFit.cc:877
static std::vector< int > parCrossSectionOrder
std::vector< GenMuonPair > genMuonPairs_
Stores the genMuon pairs and the motherId prior to the creation of the internal tree.
Definition: MuScleFitBase.h:84
static smearFunctionBase * smearFunction
static std::vector< int > parScaleOrder
edm::InputTag theMuonLabel_
Definition: MuScleFitBase.h:48
static std::vector< int > doCrossSectionFit
static void minimizeLikelihood()
static double maxMuonEtaSecondRange_
std::vector< MuScleFitMuon > fillMuonCollection(const std::vector< T > &tracks)
Definition: MuScleFit.cc:321
static std::vector< int > parBgrOrder
bool selGlobalMuon(const pat::Muon *aMuon)
Function for onia selections.
Definition: MuScleFit.cc:1520
static unsigned int loopCounter
static double deltaPhiMaxCut_
static std::vector< double > parResolMax
static std::vector< std::pair< MuScleFitMuon, MuScleFitMuon > > SavedPairMuScleFitMuons
unsigned int loopCounter
Definition: MuScleFit.cc:277
static std::vector< std::pair< MuScleFitMuon, MuScleFitMuon > > genMuscleFitPair
int totalEvents_
Definition: MuScleFit.cc:288
~MuScleFit() override
Definition: MuScleFit.cc:619
static bool startWithSimplex_
std::string triggerResultsProcess_
Definition: MuScleFit.cc:308
static std::vector< int > doBackgroundFit
static std::vector< double > parResol
static bool debugMassResol_
bool saveAllToTree_
Definition: MuScleFit.cc:311
virtual void duringFastLoop()
Definition: MuScleFit.cc:1097
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
void checkParameters()
Definition: MuScleFit.cc:1424
static BackgroundHandler * backgroundHandler
static double x[7][10000]
static int debug
static double ResMass[6]
edm::InputTag vertexSrc_
Definition: MuScleFit.cc:315
static double massWindowHalfWidth[3][6]
static bool speedup
#define DEFINE_FWK_LOOPER(type)
Definition: weight.py:1
constexpr int pow(int x)
Definition: conifer.h:24
std::map< std::string, Histograms * > mapHisto_
The map of histograms.
Definition: MuScleFitBase.h:79
static bool ResFound
void readTree(const int maxEvents, const TString &fileName, MuonPairVector *savedPair, const int muonType, std::vector< std::pair< unsigned int, unsigned long long > > *evtRun, MuonPairVector *genPair=nullptr)
void fillTreeRec(const std::vector< std::pair< reco::Particle::LorentzVector, reco::Particle::LorentzVector > > &savedPairs)
Used when running on the root tree containing preselected muon pairs.
static scaleFunctionBase< std::vector< double > > * biasFunction
bool selTrackerMuon(const pat::Muon *aMuon)
Definition: MuScleFit.cc:1535
bool ifHepMC
Definition: MuScleFit.cc:266
void startingNewLoop(unsigned int iLoop) override
Definition: MuScleFit.cc:698
static std::vector< int > parBgrFix
static std::vector< double > parResolMin
static bool minimumShapePlots_
edm::InputTag simTracksCollection_
Definition: MuScleFit.cc:291
static int MuonTypeForCheckMassWindow
static double minMuonEtaFirstRange_
static double massProb(const double &mass, const double &rapidity, const int ires, const double &massResol)
void fillComparisonHistograms(const reco::Particle::LorentzVector &genMu, const reco::Particle::LorentzVector &recoMu, const std::string &inputName, const int charge)
Fill the reco vs gen and reco vs sim comparison histograms.
Definition: MuScleFit.cc:1388
static struct MuScleFitUtils::massResolComponentsStruct massResolComponents
edm::EDGetTokenT< reco::VertexCollection > vertexToken_
Definition: MuScleFit.cc:303
static int BiasType
std::vector< std::string > triggerPath_
Definition: MuScleFit.cc:309
static std::vector< int > parScaleFix
static bool computeMinosErrors_
MuScleFitMuon recMuScleMu1
Definition: MuScleFit.cc:286
reco::Particle::LorentzVector lorentzVector
Definition: GenMuonPair.h:9
static scaleFunctionBase< std::vector< double > > * scaleFunctionForVec
static std::vector< std::vector< double > > parvalue
resolutionFunctionBase< double * > * resolutionFunctionService(const int identifier)
Service to build the resolution functor corresponding to the passed identifier.
Definition: Functions.cc:70
U second(std::pair< T, U > const &p)
void writeTree(const TString &fileName, const std::vector< MuonPair > *savedPair, const int muonType=0, const std::vector< GenMuonPair > *genPair=nullptr, const bool saveAll=false)
int theCompressionSettings_
Definition: MuScleFitBase.h:49
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
std::string outputRootTreeFileName_
Definition: MuScleFit.cc:298
std::string theGenInfoRootFileName_
Definition: MuScleFitBase.h:51
int numberOfSimVertices
Definition: MuScleFit.cc:263
resolutionFunctionBase< std::vector< double > > * resolutionFunctionVecService(const int identifier)
Service to build the resolution functor corresponding to the passed identifier when receiving a std::...
Definition: Functions.cc:92
static double massResolution(const lorentzVector &mu1, const lorentzVector &mu2)
reco::Particle::LorentzVector recMu2
Definition: MuScleFit.cc:285
bool PATmuons_
Definition: MuScleFit.cc:292
static std::vector< double > parScaleMin
std::vector< double > vec1
Definition: HCALResponse.h:15
reco::Particle::LorentzVector recMu1
Definition: MuScleFit.cc:285
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
static lorentzVector applyBias(const lorentzVector &muon, const int charge)
T sqrt(T t)
Definition: SSEVec.h:19
static std::vector< double > parBgr
unsigned int maxLoopNumber
Definition: MuScleFit.cc:276
static int SmearType
MuonServiceProxy * theService
Definition: MuScleFit.cc:257
std::string genParticlesName_
Definition: MuScleFit.cc:293
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
edm::EDGetTokenT< std::vector< PileupSummaryInfo > > puInfoToken_
Definition: MuScleFit.cc:304
scaleFunctionBase< double * > * scaleFunctionService(const int identifier)
Service to build the scale functor corresponding to the passed identifier.
Definition: Functions.cc:3
void clearHistoMap()
Clean the histograms map.
MuScleFitMuon recMuScleMu2
Definition: MuScleFit.cc:286
bool compareToSimTracks_
Definition: MuScleFit.cc:290
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
MuScleFit(const edm::ParameterSet &pset)
Definition: MuScleFit.cc:378
static std::string const triggerResults
Definition: EdmProvDump.cc:47
static lorentzVector applyScale(const lorentzVector &muon, const std::vector< double > &parval, const int charge)
static std::vector< int > parResolFix
static std::vector< double > parSmear
void beginOfJobInConstructor()
Definition: MuScleFit.cc:655
smearFunctionBase * smearFunctionService(const int identifier)
Service to build the smearing functor corresponding to the passed identifier.
Definition: Functions.cc:37
edm::EDGetTokenT< GenEventInfoProduct > genEvtInfoToken_
Definition: MuScleFit.cc:305
static std::vector< int > parResolOrder
static bool sherpa_
void endOfJob() override
Definition: MuScleFit.cc:691
bool fastLoop
Definition: MuScleFit.cc:279
edm::EDLooper::Status duringLoop(const edm::Event &event, const edm::EventSetup &eventSetup) override
Definition: MuScleFit.cc:804
int numberOfSimMuons
Definition: MuScleFit.cc:262
static std::vector< double > parScaleMax
scaleFunctionBase< std::vector< double > > * scaleFunctionVecService(const int identifier)
Service to build the scale functor corresponding to the passed identifier when receiving a std::vecto...
Definition: Functions.cc:20
void writeHistoMap(const unsigned int iLoop)
Save the histograms map to file.
static std::vector< double > parScale
static double oldNormalization_
void applySmearing(reco::Particle::LorentzVector &mu)
Apply the smearing if needed using the function in MuScleFitUtils.
Definition: MuScleFit.cc:1406
int numberOfSimTracks
Definition: MuScleFit.cc:261
std::string theRootFileName_
Definition: MuScleFitBase.h:50
void fillTreeGen(const std::vector< std::pair< reco::Particle::LorentzVector, reco::Particle::LorentzVector > > &genPairs)
edm::InputTag puInfoSrc_
Definition: MuScleFit.cc:314
static double deltaPhiMinCut_
std::string triggerResultsLabel_
Definition: MuScleFit.cc:307
static bool rapidityBinsForZ_
MuScleFitPlotter * plotter
Definition: MuScleFit.cc:281
void fillHistoMap(TFile *outputFile, unsigned int iLoop)
Create the histograms map.
Definition: MuScleFitBase.cc:9
std::vector< TFile * > theFiles_
The files were the histograms are saved.
Definition: MuScleFitBase.h:76
double minResMass_hwindow[6]
Definition: MuScleFit.cc:271
static int ResolFitType
static int goodmuon
reco::TrackRef globalTrack() const override
reference to Track reconstructed in both tracked and muon detector (reimplemented from reco::Muon) ...
Definition: Muon.h:80
static bool separateRanges_
bool isValid() const
Definition: HandleBase.h:70
static double minMuonEtaSecondRange_
reco::TrackRef innerTrack() const override
reference to Track reconstructed in the tracker only (reimplemented from reco::Muon) ...
Definition: Muon.h:72
static int iev_
static std::vector< double > parCrossSection
static const double mMu2
HLT enums.
static lorentzVector applySmearing(const lorentzVector &muon)
static bool normalizeLikelihoodByEventNumber_
std::string inputRootTreeFileName_
Definition: MuScleFit.cc:296
bool checkDeltaR(reco::Particle::LorentzVector &genMu, reco::Particle::LorentzVector &recMu)
Check if two lorentzVector are near in deltaR.
Definition: MuScleFit.cc:1373
int maxEventsFromRootTree_
Definition: MuScleFit.cc:300
double maxResMass_hwindow[6]
Definition: MuScleFit.cc:272
static int MuonType
std::vector< MuonPair > muonPairs_
Used to store the muon pairs plus run and event number prior to the creation of the internal tree...
Definition: MuScleFitBase.h:82
static double deltaPhi(const double &phi1, const double &phi2)
static double minMuonPt_
edm::EDGetTokenT< edm::TriggerResults > triggerResultsToken_
Definition: MuScleFit.cc:302
static scaleFunctionBase< double * > * scaleFunction
static bool useProbsFile_
static std::vector< int > resfind
void readProbabilityDistributionsFromFile()
Read probability distributions from a local root file.
void takeSelectedMuonType(const T &muon, std::vector< reco::Track > &tracks)
Template method used to fill the track collection starting from reco::muons or pat::muons.
Definition: MuScleFit.cc:357
std::vector< vec1 > vec2
Definition: HCALResponse.h:16
long double T
static int counter_resprob
static resolutionFunctionBase< std::vector< double > > * resolutionFunctionForVec
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:21
static int FitStrategy
Analysis-level muon class.
Definition: Muon.h:51
static double maxMuonEtaFirstRange_
std::unique_ptr< MuScleFitMuonSelector > muonSelector_
Definition: MuScleFit.cc:317
void applyBias(reco::Particle::LorentzVector &mu, const int charge)
Apply the bias if needed using the function in MuScleFitUtils.
Definition: MuScleFit.cc:1414
bool negateTrigger_
Definition: MuScleFit.cc:310
bool ifGenPart
Definition: MuScleFit.cc:267
static CrossSectionHandler * crossSectionHandler
edm::EDLooper::Status endOfLoop(const edm::EventSetup &eventSetup, unsigned int iLoop) override
Definition: MuScleFit.cc:725
static std::vector< double > parResolStep
Definition: event.py:1
static std::vector< int > parCrossSectionFix
static resolutionFunctionBase< double * > * resolutionFunction
void addParameters(std::vector< double > &initpar)
Inputs the vars in a vector.
bool muonID(const std::string &name) const
def exit(msg="")
virtual void endOfFastLoop(const unsigned int iLoop)
Definition: MuScleFit.cc:769
int numberOfEwkZ
Definition: MuScleFit.cc:264