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 
207  edm::EDLooper::Status duringLoop(const edm::Event& event, const edm::EventSetup& eventSetup) override;
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 
304  std::vector<std::string> triggerPath_;
307 
308  // input collections for PU related infos
311 
312  std::unique_ptr<MuScleFitMuonSelector> muonSelector_;
313 };
314 
315 template <typename T>
316 std::vector<MuScleFitMuon> MuScleFit::fillMuonCollection(const std::vector<T>& tracks) {
317  std::vector<MuScleFitMuon> muons;
318  typename std::vector<T>::const_iterator track;
319  for (track = tracks.begin(); track != tracks.end(); ++track) {
322  track->px(), track->py(), track->pz(), sqrt(track->p() * track->p() + MuScleFitUtils::mMu2));
323  // Apply smearing if needed, and then bias
324  // ---------------------------------------
326  if (debug_ > 0)
327  std::cout << std::setprecision(9) << "Muon #" << MuScleFitUtils::goodmuon << ": initial value Pt = " << mu.Pt()
328  << std::endl;
329 
330  applySmearing(mu);
331  applyBias(mu, track->charge());
332  if (debug_ > 0)
333  std::cout << "track charge: " << track->charge() << std::endl;
334 
335  Double_t hitsTk = track->innerTrack()->hitPattern().numberOfValidTrackerHits();
336  Double_t hitsMuon = track->innerTrack()->hitPattern().numberOfValidMuonHits();
337  Double_t ptError = track->innerTrack()->ptError();
338  MuScleFitMuon muon(mu, track->charge(), ptError, hitsTk, hitsMuon, false);
339  if (debug_ > 0) {
340  std::cout << "[MuScleFit::fillMuonCollection]" << std::endl;
341  std::cout << " muon = " << muon << std::endl;
342  }
343 
344  // Store modified muon
345  // -------------------
346  muons.push_back(muon);
347  }
348  return muons;
349 }
350 
351 template <typename T>
352 void MuScleFit::takeSelectedMuonType(const T& muon, std::vector<reco::Track>& tracks) {
353  // std::cout<<"muon "<<muon->isGlobalMuon()<<muon->isStandAloneMuon()<<muon->isTrackerMuon()<<std::endl;
354  //NNBB: one muon can be of many kinds at once but with the theMuonType_ we are sure
355  // to avoid double counting of the same muon
356  if (muon->isGlobalMuon() && theMuonType_ == 1)
357  tracks.push_back(*(muon->globalTrack()));
358  else if (muon->isStandAloneMuon() && theMuonType_ == 2)
359  tracks.push_back(*(muon->outerTrack()));
360  else if (muon->isTrackerMuon() && theMuonType_ == 3)
361  tracks.push_back(*(muon->innerTrack()));
362 
363  else if (theMuonType_ == 10 && !(muon->isStandAloneMuon())) //particular case!!
364  tracks.push_back(*(muon->innerTrack()));
365  else if (theMuonType_ == 11 && muon->isGlobalMuon())
366  tracks.push_back(*(muon->innerTrack()));
367  else if (theMuonType_ == 13 && muon->isTrackerMuon())
368  tracks.push_back(*(muon->innerTrack()));
369 }
370 
371 // Constructor
372 // -----------
375  if (debug_ > 0)
376  std::cout << "[MuScleFit]: Constructor" << std::endl;
377 
378  if ((theMuonType_ < -4 || theMuonType_ > 5) && theMuonType_ < 10) {
379  std::cout << "[MuScleFit]: Unknown muon type! Aborting." << std::endl;
380  abort();
381  }
382 
383  loopCounter = 0;
384 
385  // Boundaries for h-function computation (to be improved!)
386  // -------------------------------------------------------
387  minResMass_hwindow[0] = 71.1876; // 76.;
388  maxResMass_hwindow[0] = 111.188; // 106.;
389  minResMass_hwindow[1] = 10.15;
390  maxResMass_hwindow[1] = 10.55;
391  minResMass_hwindow[2] = 9.8;
392  maxResMass_hwindow[2] = 10.2;
393  minResMass_hwindow[3] = 9.25;
394  maxResMass_hwindow[3] = 9.65;
395  minResMass_hwindow[4] = 3.58;
396  maxResMass_hwindow[4] = 3.78;
397  minResMass_hwindow[5] = 3.0;
398  maxResMass_hwindow[5] = 3.2;
399 
400  // Max number of loops (if > 2 then try to minimize likelihood more than once)
401  // ---------------------------------------------------------------------------
402  maxLoopNumber = pset.getUntrackedParameter<int>("maxLoopNumber", 2);
403  fastLoop = pset.getUntrackedParameter<bool>("FastLoop", true);
404 
405  // Selection of fits according to loop
406  MuScleFitUtils::doResolFit = pset.getParameter<std::vector<int> >("doResolFit");
407  MuScleFitUtils::doScaleFit = pset.getParameter<std::vector<int> >("doScaleFit");
408  MuScleFitUtils::doCrossSectionFit = pset.getParameter<std::vector<int> >("doCrossSectionFit");
409  MuScleFitUtils::doBackgroundFit = pset.getParameter<std::vector<int> >("doBackgroundFit");
410 
411  // Bias and smear types
412  // --------------------
413  int biasType = pset.getParameter<int>("BiasType");
414  MuScleFitUtils::BiasType = biasType;
415  // No error, the scale functions are used also for the bias
417  int smearType = pset.getParameter<int>("SmearType");
418  MuScleFitUtils::SmearType = smearType;
420 
421  // Fit types
422  // ---------
423  int resolFitType = pset.getParameter<int>("ResolFitType");
424  MuScleFitUtils::ResolFitType = resolFitType;
427  int scaleType = pset.getParameter<int>("ScaleFitType");
428  MuScleFitUtils::ScaleFitType = scaleType;
431 
432  // Initial parameters values
433  // -------------------------
434  MuScleFitUtils::parBias = pset.getParameter<std::vector<double> >("parBias");
435  MuScleFitUtils::parSmear = pset.getParameter<std::vector<double> >("parSmear");
436  MuScleFitUtils::parResol = pset.getParameter<std::vector<double> >("parResol");
438  pset.getUntrackedParameter<std::vector<double> >("parResolStep", std::vector<double>());
439  MuScleFitUtils::parResolMin = pset.getUntrackedParameter<std::vector<double> >("parResolMin", std::vector<double>());
440  MuScleFitUtils::parResolMax = pset.getUntrackedParameter<std::vector<double> >("parResolMax", std::vector<double>());
441  MuScleFitUtils::parScale = pset.getParameter<std::vector<double> >("parScale");
443  pset.getUntrackedParameter<std::vector<double> >("parScaleStep", std::vector<double>());
444  MuScleFitUtils::parScaleMin = pset.getUntrackedParameter<std::vector<double> >("parScaleMin", std::vector<double>());
445  MuScleFitUtils::parScaleMax = pset.getUntrackedParameter<std::vector<double> >("parScaleMax", std::vector<double>());
446  MuScleFitUtils::parCrossSection = pset.getParameter<std::vector<double> >("parCrossSection");
447  MuScleFitUtils::parBgr = pset.getParameter<std::vector<double> >("parBgr");
448  MuScleFitUtils::parResolFix = pset.getParameter<std::vector<int> >("parResolFix");
449  MuScleFitUtils::parScaleFix = pset.getParameter<std::vector<int> >("parScaleFix");
450  MuScleFitUtils::parCrossSectionFix = pset.getParameter<std::vector<int> >("parCrossSectionFix");
451  MuScleFitUtils::parBgrFix = pset.getParameter<std::vector<int> >("parBgrFix");
452  MuScleFitUtils::parResolOrder = pset.getParameter<std::vector<int> >("parResolOrder");
453  MuScleFitUtils::parScaleOrder = pset.getParameter<std::vector<int> >("parScaleOrder");
454  MuScleFitUtils::parCrossSectionOrder = pset.getParameter<std::vector<int> >("parCrossSectionOrder");
455  MuScleFitUtils::parBgrOrder = pset.getParameter<std::vector<int> >("parBgrOrder");
456 
457  MuScleFitUtils::resfind = pset.getParameter<std::vector<int> >("resfind");
458  MuScleFitUtils::FitStrategy = pset.getParameter<int>("FitStrategy");
459 
460  // Option to skip unnecessary stuff
461  // --------------------------------
462  MuScleFitUtils::speedup = pset.getParameter<bool>("speedup");
463 
464  // Option to skip simTracks comparison
465  compareToSimTracks_ = pset.getParameter<bool>("compareToSimTracks");
466  simTracksCollection_ = pset.getUntrackedParameter<edm::InputTag>("SimTracksCollection", edm::InputTag("g4SimHits"));
467 
468  triggerResultsLabel_ = pset.getUntrackedParameter<std::string>("TriggerResultsLabel");
469  triggerResultsProcess_ = pset.getUntrackedParameter<std::string>("TriggerResultsProcess");
470  triggerPath_ = pset.getUntrackedParameter<std::vector<std::string> >("TriggerPath");
471  negateTrigger_ = pset.getUntrackedParameter<bool>("NegateTrigger", false);
472  saveAllToTree_ = pset.getUntrackedParameter<bool>("SaveAllToTree", false);
473 
474  // input collections for PU related infos
475  puInfoSrc_ = pset.getUntrackedParameter<edm::InputTag>("PileUpSummaryInfo");
476  vertexSrc_ = pset.getUntrackedParameter<edm::InputTag>("PrimaryVertexCollection");
477 
478  PATmuons_ = pset.getUntrackedParameter<bool>("PATmuons", false);
479  genParticlesName_ = pset.getUntrackedParameter<std::string>("GenParticlesName", "genParticles");
480 
481  // Use the probability file or not. If not it will perform a simpler selection taking the muon pair with
482  // invariant mass closer to the pdf value and will crash if some fit is attempted.
483  MuScleFitUtils::useProbsFile_ = pset.getUntrackedParameter<bool>("UseProbsFile", true);
484 
485  // This must be set to true if using events generated with Sherpa
486  MuScleFitUtils::sherpa_ = pset.getUntrackedParameter<bool>("Sherpa", false);
487 
488  MuScleFitUtils::rapidityBinsForZ_ = pset.getUntrackedParameter<bool>("RapidityBinsForZ", true);
489 
490  // Set the cuts on muons to be used in the fit
491  MuScleFitUtils::separateRanges_ = pset.getUntrackedParameter<bool>("SeparateRanges", true);
492  MuScleFitUtils::maxMuonPt_ = pset.getUntrackedParameter<double>("MaxMuonPt", 100000000.);
493  MuScleFitUtils::minMuonPt_ = pset.getUntrackedParameter<double>("MinMuonPt", 0.);
494  MuScleFitUtils::minMuonEtaFirstRange_ = pset.getUntrackedParameter<double>("MinMuonEtaFirstRange", -6.);
495  MuScleFitUtils::maxMuonEtaFirstRange_ = pset.getUntrackedParameter<double>("MaxMuonEtaFirstRange", 6.);
496  MuScleFitUtils::minMuonEtaSecondRange_ = pset.getUntrackedParameter<double>("MinMuonEtaSecondRange", -100.);
497  MuScleFitUtils::maxMuonEtaSecondRange_ = pset.getUntrackedParameter<double>("MaxMuonEtaSecondRange", 100.);
498  MuScleFitUtils::deltaPhiMinCut_ = pset.getUntrackedParameter<double>("DeltaPhiMinCut", -100.);
499  MuScleFitUtils::deltaPhiMaxCut_ = pset.getUntrackedParameter<double>("DeltaPhiMaxCut", 100.);
500 
501  MuScleFitUtils::debugMassResol_ = pset.getUntrackedParameter<bool>("DebugMassResol", false);
502  // MuScleFitUtils::massResolComponentsStruct MuScleFitUtils::massResolComponents;
503 
504  // Check for parameters consistency
505  // it will abort in case of errors.
506  checkParameters();
507 
508  // Generate array of gaussian-distributed numbers for smearing
509  // -----------------------------------------------------------
510  if (MuScleFitUtils::SmearType > 0) {
511  std::cout << "[MuScleFit-Constructor]: Generating random values for smearing" << std::endl;
512  TF1 G("G", "[0]*exp(-0.5*pow(x,2))", -5., 5.);
513  double norm = 1 / sqrt(2 * TMath::Pi());
514  G.SetParameter(0, norm);
515  for (int i = 0; i < 10000; i++) {
516  for (int j = 0; j < 7; j++) {
517  MuScleFitUtils::x[j][i] = G.GetRandom();
518  }
519  }
520  }
522 
523  if (theMuonType_ > 0 && theMuonType_ < 4) {
526  } else if (theMuonType_ == 0 || theMuonType_ == 4 || theMuonType_ == 5 || theMuonType_ >= 10 || theMuonType_ == -1 ||
527  theMuonType_ == -2 || theMuonType_ == -3 || theMuonType_ == -4) {
530  } else {
531  std::cout << "Wrong muon type " << theMuonType_ << std::endl;
532  exit(1);
533  }
534 
535  // When using standalone muons switch to the single Z pdf
536  if (theMuonType_ == 2) {
538  }
539 
540  // Initialize ResMaxSigma And ResHalfWidth - 0 = global, 1 = SM, 2 = tracker
541  // -------------------------------------------------------------------------
560 
561  muonSelector_ = std::make_unique<MuScleFitMuonSelector>(theMuonLabel_,
562  theMuonType_,
563  PATmuons_,
570  debug_);
571 
573  new BackgroundHandler(pset.getParameter<std::vector<int> >("BgrFitType"),
574  pset.getParameter<std::vector<double> >("LeftWindowBorder"),
575  pset.getParameter<std::vector<double> >("RightWindowBorder"),
578 
581 
582  // Build cross section scale factors
583  // MuScleFitUtils::resfind
584 
586  pset.getUntrackedParameter<bool>("NormalizeLikelihoodByEventNumber", true);
587  if (debug_ > 0)
588  std::cout << "End of MuScleFit constructor" << std::endl;
589 
590  inputRootTreeFileName_ = pset.getParameter<std::string>("InputRootTreeFileName");
591  outputRootTreeFileName_ = pset.getParameter<std::string>("OutputRootTreeFileName");
592  maxEventsFromRootTree_ = pset.getParameter<int>("MaxEventsFromRootTree");
593 
594  MuScleFitUtils::startWithSimplex_ = pset.getParameter<bool>("StartWithSimplex");
595  MuScleFitUtils::computeMinosErrors_ = pset.getParameter<bool>("ComputeMinosErrors");
596  MuScleFitUtils::minimumShapePlots_ = pset.getParameter<bool>("MinimumShapePlots");
597 
599 }
600 
601 // Destructor
602 // ----------
604  if (debug_ > 0)
605  std::cout << "[MuScleFit]: Destructor" << std::endl;
606  std::cout << "Total number of analyzed events = " << totalEvents_ << std::endl;
607 
608  if (!(outputRootTreeFileName_.empty())) {
609  // 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_
611  std::cout << "Saving muon pairs to root tree" << std::endl;
612  RootTreeHandler rootTreeHandler;
614  // rootTreeHandler.writeTree(outputRootTreeFileName_, &(MuScleFitUtils::SavedPair), theMuonType_, 0, saveAllToTree_);
615  if (debug_ > 0) {
616  std::vector<MuonPair>::const_iterator it = muonPairs_.begin();
617  std::cout << "[MuScleFit::~MuScleFit] (Destructor)" << std::endl;
618  for (; it < muonPairs_.end(); ++it) {
619  std::cout << " Debugging pairs that are going to be written to file" << std::endl;
620  std::cout << " muon1 = " << it->mu1 << std::endl;
621  std::cout << " muon2 = " << it->mu2 << std::endl;
622  }
623  }
625  } else {
626  // rootTreeHandler.writeTree(outputRootTreeFileName_, &(MuScleFitUtils::SavedPair), theMuonType_, &(MuScleFitUtils::genPair), saveAllToTree_ );
627  rootTreeHandler.writeTree(
629  }
630  } else {
631  std::cout << "ERROR: events in the vector = " << MuScleFitUtils::SavedPair.size()
632  << " != totalEvents = " << totalEvents_ << std::endl;
633  }
634  }
635 }
636 
637 // Begin job
638 // ---------
640 // void MuScleFit::beginOfJob ()
641 // void MuScleFit::beginOfJob( const edm::EventSetup& eventSetup )
642 {
643  if (debug_ > 0)
644  std::cout << "[MuScleFit]: beginOfJob" << std::endl;
645  //if(maxLoopNumber>1)
648  }
649 
650  if (debug_ > 0)
651  std::cout << "[MuScleFit]: beginOfJob" << std::endl;
652 
653  // Create the root file
654  // --------------------
655  for (unsigned int i = 0; i < (maxLoopNumber); i++) {
656  std::stringstream ss;
657  ss << i;
659  if (theCompressionSettings_ > -1) {
660  theFiles_.push_back(new TFile(rootFileName.c_str(), "RECREATE", "", theCompressionSettings_));
661  } else {
662  theFiles_.push_back(new TFile(rootFileName.c_str(), "RECREATE"));
663  }
664  }
665  if (debug_ > 0)
666  std::cout << "[MuScleFit]: Root file created" << std::endl;
667 
668  std::cout << "creating plotter" << std::endl;
670  plotter->debug = debug_;
671 }
672 
673 // End of job method
674 // -----------------
676  if (debug_ > 0)
677  std::cout << "[MuScleFit]: endOfJob" << std::endl;
678 }
679 
680 // New loop
681 // --------
682 void MuScleFit::startingNewLoop(unsigned int iLoop) {
683  if (debug_ > 0)
684  std::cout << "[MuScleFit]: Starting loop # " << iLoop << std::endl;
685 
686  // Number of muons used
687  // --------------------
689 
690  // Counters for problem std::cout-ing
691  // -----------------------------
693 
694  // Create the root file
695  // --------------------
696  fillHistoMap(theFiles_[iLoop], iLoop);
697 
698  loopCounter = iLoop;
700 
701  iev = 0;
703 
705 }
706 
707 // End of loop routine
708 // -------------------
709 edm::EDLooper::Status MuScleFit::endOfLoop(const edm::EventSetup& eventSetup, unsigned int iLoop) {
710  unsigned int iFastLoop = 1;
711 
712  // Read the events from the root tree if requested
713  if (!(inputRootTreeFileName_.empty())) {
715  // When reading from local file all the loops are done here
717  iFastLoop = 0;
718  } else {
719  endOfFastLoop(iLoop);
720  }
721 
722  // If a fastLoop is required we do all the remaining iterations here
723  if (fastLoop == true) {
724  for (; iFastLoop < maxLoopNumber; ++iFastLoop) {
725  std::cout << "Starting fast loop number " << iFastLoop << std::endl;
726 
727  // In the first loop is called by the framework
728  // if( iFastLoop > 0 ) {
729  startingNewLoop(iFastLoop);
730  // }
731 
732  // std::vector<std::pair<lorentzVector,lorentzVector> >::const_iterator it = MuScleFitUtils::SavedPair.begin();
733  // for( ; it != SavedPair.end(); ++it ) {
734  while (iev < totalEvents_) {
735  if (iev % 50000 == 0) {
736  std::cout << "Fast looping on event number " << iev << std::endl;
737  }
738  // This reads muons from SavedPair using iev to keep track of the event
739  duringFastLoop();
740  }
741  std::cout << "End of fast loop number " << iFastLoop << ". Ran on " << iev << " events" << std::endl;
742  endOfFastLoop(iFastLoop);
743  }
744  }
745 
746  if (iFastLoop >= maxLoopNumber - 1) {
747  return kStop;
748  } else {
749  return kContinue;
750  }
751 }
752 
753 void MuScleFit::endOfFastLoop(const unsigned int iLoop) {
754  // std::cout<< "Inside endOfFastLoop, iLoop = " << iLoop << " and loopCounter = " << loopCounter << std::endl;
755 
756  if (loopCounter == 0) {
757  // plotter->writeHistoMap();
758  // The destructor will call the writeHistoMap after the cd to the output file
759  delete plotter;
760  }
761 
762  std::cout << "Ending loop # " << iLoop << std::endl;
763 
764  // Write the histos to file
765  // ------------------------
766  // theFiles_[iLoop]->cd();
767  writeHistoMap(iLoop);
768 
769  // Likelihood minimization to compute corrections
770  // ----------------------------------------------
771  // theFiles_[iLoop]->cd();
772  TDirectory* likelihoodDir = theFiles_[iLoop]->mkdir("likelihood");
773  likelihoodDir->cd();
775 
776  // ATTENTION, this was put BEFORE the minimizeLikelihood. Check for problems.
777  theFiles_[iLoop]->Close();
778  // ATTENTION: Check that this delete does not give any problem
779  delete theFiles_[iLoop];
780 
781  // Clear the histos
782  // ----------------
783  clearHistoMap();
784 }
785 
786 // Stuff to do during loop
787 // -----------------------
790  event.getByLabel(edm::InputTag(triggerResultsLabel_.c_str(), "", triggerResultsProcess_.c_str()), triggerResults);
791  //event.getByLabel(InputTag(triggerResultsLabel_),triggerResults);
792  bool isFired = false;
793 
794  if (triggerPath_[0].empty())
795  isFired = true;
796  else if (triggerPath_[0] == "All") {
797  isFired = triggerResults->accept();
798  if (debug_ > 0)
799  std::cout << "Trigger " << isFired << std::endl;
800  } else {
801  bool changed;
803  hltConfig.init(event.getRun(), eventSetup, triggerResultsProcess_, changed);
804 
805  const edm::TriggerNames& triggerNames = event.triggerNames(*triggerResults);
806 
807  for (unsigned i = 0; i < triggerNames.size(); i++) {
808  const std::string& hltName = triggerNames.triggerName(i);
809 
810  // match the path in the pset with the true name of the trigger
811  for (unsigned int ipath = 0; ipath < triggerPath_.size(); ipath++) {
812  if (hltName.find(triggerPath_[ipath]) != std::string::npos) {
813  unsigned int triggerIndex(hltConfig.triggerIndex(hltName));
814 
815  // triggerIndex must be less than the size of HLTR or you get a CMSException: _M_range_check
816  if (triggerIndex < triggerResults->size()) {
817  isFired = triggerResults->accept(triggerIndex);
818  if (debug_ > 0)
819  std::cout << triggerPath_[ipath] << " " << hltName << " " << isFired << std::endl;
820  }
821  } // end if (matching the path in the pset with the true trigger name
822  }
823  }
824  }
825 
826  if (negateTrigger_ && isFired)
827  return kContinue;
828  else if (!(negateTrigger_) && !isFired)
829  return kContinue;
830 
831 #ifdef USE_CALLGRIND
832  CALLGRIND_START_INSTRUMENTATION;
833 #endif
834 
835  if (debug_ > 0) {
836  std::cout << "[MuScleFit-duringLoop]: loopCounter = " << loopCounter << " Run: " << event.id().run()
837  << " Event: " << event.id().event() << std::endl;
838  }
839 
840  // On the first iteration we read the bank, otherwise we fetch the information from the muon tree
841  // ------------------------------------ Important Note --------------------------------------- //
842  // The fillMuonCollection method applies any smearing or bias to the muons, so we NEVER use
843  // unbiased muons.
844  // ----------------------------------------------------------------------------------------------
845  if (loopCounter == 0) {
846  if (!fastLoop || inputRootTreeFileName_.empty()) {
847  if (debug_ > 0)
848  std::cout << "Reading from edm event" << std::endl;
850  duringFastLoop();
851  ++totalEvents_;
852  }
853  }
854 
855  return kContinue;
856 
857 #ifdef USE_CALLGRIND
858  CALLGRIND_STOP_INSTRUMENTATION;
859  CALLGRIND_DUMP_STATS;
860 #endif
861 }
862 
866 
867  std::vector<MuScleFitMuon> muons;
869  // plotter->fillRec(muons); // @EM method already invoked inside MuScleFitMuonSelector::selectMuons()
870 
871  if (debug_ > 0) {
872  std::cout << "[MuScleFit::selectMuons] Debugging muons collections after call to muonSelector_->selectMuons"
873  << std::endl;
874  int iMu = 0;
875  for (std::vector<MuScleFitMuon>::const_iterator it = muons.begin(); it < muons.end(); ++it) {
876  std::cout << " - muon n. " << iMu << " = " << (*it) << std::endl;
877  ++iMu;
878  }
879  }
880 
881  // Find the two muons from the resonance, and set ResFound bool
882  // ------------------------------------------------------------
883  std::pair<MuScleFitMuon, MuScleFitMuon> recMuFromBestRes = MuScleFitUtils::findBestRecoRes(muons);
884 
886  if (debug_ > 0) {
887  std::cout << std::setprecision(9) << "Pt after findbestrecores: " << (recMuFromBestRes.first).Pt() << " "
888  << (recMuFromBestRes.second).Pt() << std::endl;
889  std::cout << "recMu1 = " << recMu1 << std::endl;
890  std::cout << "recMu2 = " << recMu2 << std::endl;
891  }
892  recMu1 = recMuFromBestRes.first.p4();
893  recMu2 = recMuFromBestRes.second.p4();
894  recMuScleMu1 = recMuFromBestRes.first;
895  recMuScleMu2 = recMuFromBestRes.second;
896 
897  if (debug_ > 0) {
898  std::cout << "after recMu1 = " << recMu1 << std::endl;
899  std::cout << "after recMu2 = " << recMu2 << std::endl;
900  std::cout << "mu1.pt = " << recMu1.Pt() << std::endl;
901  std::cout << "mu2.pt = " << recMu2.Pt() << std::endl;
902  std::cout << "after recMuScleMu1 = " << recMuScleMu1 << std::endl;
903  std::cout << "after recMuScleMu2 = " << recMuScleMu2 << std::endl;
904  }
905  MuScleFitUtils::SavedPair.push_back(std::make_pair(recMu1, recMu2));
907  } else {
908  MuScleFitUtils::SavedPair.push_back(std::make_pair(lorentzVector(0., 0., 0., 0.), lorentzVector(0., 0., 0., 0.)));
910  }
911  // Save the events also in the external tree so that it can be saved late
912 
913  // Fetch extra information (per event)
914  UInt_t the_NVtx(0);
915  Int_t the_numPUvtx(0);
916  Float_t the_TrueNumInteractions(0);
917 
918  // Fill pile-up related informations
919  // --------------------------------
921  event.getByLabel(puInfoSrc_, puInfo);
922  if (puInfo.isValid()) {
923  std::vector<PileupSummaryInfo>::const_iterator PVI;
924  for (PVI = puInfo->begin(); PVI != puInfo->end(); ++PVI) {
925  int BX = PVI->getBunchCrossing();
926  if (BX == 0) { // "0" is the in-time crossing, negative values are the early crossings, positive are late
927  the_TrueNumInteractions = PVI->getTrueNumInteractions();
928  the_numPUvtx = PVI->getPU_NumInteractions();
929  }
930  }
931  }
932 
934  event.getByLabel(vertexSrc_, vertices);
935  if (vertices.isValid()) {
936  std::vector<reco::Vertex>::const_iterator itv;
937  // now, count vertices
938  for (itv = vertices->begin(); itv != vertices->end(); ++itv) {
939  // require that the vertex meets certain criteria
940  if (itv->ndof() < 5)
941  continue;
942  if (fabs(itv->z()) > 50.0)
943  continue;
944  if (fabs(itv->position().rho()) > 2.0)
945  continue;
946  ++the_NVtx;
947  }
948  }
949 
950  // get the MC event weight
952  event.getByLabel("generator", genEvtInfo);
953  double the_genEvtweight = 1.;
954  if (genEvtInfo.isValid()) {
955  the_genEvtweight = genEvtInfo->weight();
956  }
957 
958  muonPairs_.push_back(MuonPair(
962  event.run(), event.id().event(), the_genEvtweight, the_numPUvtx, the_TrueNumInteractions, the_NVtx)));
963  // Fill the internal genPair tree from the external one
964  if (MuScleFitUtils::speedup == false) {
965  MuScleFitUtils::genPair.push_back(std::make_pair(genMuonPairs_.back().mu1.p4(), genMuonPairs_.back().mu2.p4()));
966  }
967 }
968 
969 void MuScleFit::selectMuons(const int maxEvents, const TString& treeFileName) {
970  std::cout << "Reading muon pairs from Root Tree in " << treeFileName << std::endl;
971  RootTreeHandler rootTreeHandler;
972  std::vector<std::pair<unsigned int, unsigned long long> > evtRun;
974  rootTreeHandler.readTree(
976  } else {
977  rootTreeHandler.readTree(maxEvents,
980  theMuonType_,
981  &evtRun,
983  }
984  // Now loop on all the pairs and apply any smearing and bias if needed
985  std::vector<std::pair<unsigned int, unsigned long long> >::iterator evtRunIt = evtRun.begin();
986  std::vector<std::pair<MuScleFitMuon, MuScleFitMuon> >::iterator it = MuScleFitUtils::SavedPairMuScleFitMuons.begin();
987  std::vector<std::pair<MuScleFitMuon, MuScleFitMuon> >::iterator genIt;
988  if (MuScleFitUtils::speedup == false)
989  genIt = MuScleFitUtils::genMuscleFitPair.begin();
990  for (; it != MuScleFitUtils::SavedPairMuScleFitMuons.end(); ++it, ++evtRunIt) {
991  // Apply any cut if requested
992  // Note that cuts here are only applied to already selected muons. They should not be used unless
993  // you are sure that the difference is negligible (e.g. the number of events with > 2 muons is negligible).
994  double pt1 = it->first.pt();
995  //std::cout << "pt1 = " << pt1 << std::endl;
996  double pt2 = it->second.pt();
997  //std::cout << "pt2 = " << pt2 << std::endl;
998  double eta1 = it->first.eta();
999  //std::cout << "eta1 = " << eta1 << std::endl;
1000  double eta2 = it->second.eta();
1001  //std::cout << "eta2 = " << eta2 << std::endl;
1002  // If they don't pass the cuts set to null vectors
1003  bool dontPass = false;
1004  bool eta1InFirstRange;
1005  bool eta2InFirstRange;
1006  bool eta1InSecondRange;
1007  bool eta2InSecondRange;
1008 
1009  int ch1 = it->first.charge();
1010  int ch2 = it->second.charge();
1011 
1015  eta1InSecondRange =
1017  eta2InSecondRange =
1019 
1020  // This is my logic, which should be erroneous, but certainly simpler...
1023  ((eta1InFirstRange && eta2InSecondRange && ch1 >= ch2) ||
1024  (eta1InSecondRange && eta2InFirstRange && ch1 < ch2))))
1025  dontPass = true;
1026  } else {
1029  eta1InSecondRange =
1031  eta2InSecondRange =
1035  (((eta1InFirstRange && !eta2InFirstRange) && (eta2InSecondRange && !eta1InSecondRange) && ch1 >= ch2) ||
1036  ((eta2InFirstRange && !eta1InFirstRange) && (eta1InSecondRange && !eta2InSecondRange) && ch1 < ch2))))
1037  dontPass = true;
1038  }
1039 
1040  // Additional check on deltaPhi
1041  double deltaPhi = MuScleFitUtils::deltaPhi(it->first.phi(), it->second.phi());
1043  dontPass = true;
1044 
1045  lorentzVector vec1 = it->first.p4();
1046  lorentzVector vec2 = it->second.p4();
1047  if (ch1 >= ch2) {
1048  lorentzVector vectemp = vec1;
1049  vec1 = vec2;
1050  vec2 = vectemp;
1051  }
1052 
1053  if (!dontPass) {
1054  // First is always mu-, second mu+
1055  if ((MuScleFitUtils::SmearType != 0) || (MuScleFitUtils::BiasType != 0)) {
1057  applyBias(vec1, -1);
1059  applyBias(vec2, 1);
1060  }
1061 
1062  MuScleFitUtils::SavedPair.push_back(std::make_pair(vec1, vec2));
1063  }
1064 
1065  //FIXME: we loose the additional information besides the 4-momenta
1066  muonPairs_.push_back(MuonPair(
1067  MuScleFitMuon(vec1, -1),
1068  MuScleFitMuon(vec2, +1),
1070  (*evtRunIt).first, (*evtRunIt).second, 0, 0, 0, 0)) // FIXME: order of event and run number mixed up!
1071  );
1072 
1073  // Fill the internal genPair tree from the external one
1074  if (!MuScleFitUtils::speedup) {
1075  MuScleFitUtils::genPair.push_back(std::make_pair(genIt->first.p4(), genIt->second.p4()));
1076  genMuonPairs_.push_back(GenMuonPair(genIt->first.p4(), genIt->second.p4(), 0));
1077  ++genIt;
1078  }
1079  }
1081  if (!(MuScleFitUtils::speedup)) {
1083  }
1084 }
1085 
1087  // On loops>0 the two muons are directly obtained from the SavedMuon array
1088  // -----------------------------------------------------------------------
1089  MuScleFitUtils::ResFound = false;
1091  recMu2 = (MuScleFitUtils::SavedPair[iev].second);
1092 
1093  //std::cout << "iev = " << iev << ", recMu1 pt = " << recMu1.Pt() << ", recMu2 pt = " << recMu2.Pt() << std::endl;
1094 
1095  if (recMu1.Pt() > 0 && recMu2.Pt() > 0) {
1096  MuScleFitUtils::ResFound = true;
1097  if (debug_ > 0)
1098  std::cout << "Ev = " << iev << ": found muons in tree with Pt = " << recMu1.Pt() << " " << recMu2.Pt()
1099  << std::endl;
1100  }
1101 
1102  if (debug_ > 0)
1103  std::cout << "About to start lik par correction and histo filling; ResFound is " << MuScleFitUtils::ResFound
1104  << std::endl;
1105  // If resonance found, do the hard work
1106  // ------------------------------------
1108  // Find weight and reference mass for this muon pair
1109  // -------------------------------------------------
1110  // The last parameter = true means that we want to use always the background window to compute the weight,
1111  // otherwise the probability will be filled only for the resonance region.
1112  double weight = MuScleFitUtils::computeWeight((recMu1 + recMu2).mass(), iev, true);
1113  if (debug_ > 0) {
1114  std::cout << "Loop #" << loopCounter << "Event #" << iev << ": before correction Pt1 = " << recMu1.Pt()
1115  << " Pt2 = " << recMu2.Pt() << std::endl;
1116  }
1117  // For successive iterations, correct the muons only if the previous iteration was a scale fit.
1118  // --------------------------------------------------------------------------------------------
1119  if (loopCounter > 0) {
1123  }
1124  }
1125  if (debug_ > 0) {
1126  std::cout << "Loop #" << loopCounter << "Event #" << iev << ": after correction Pt1 = " << recMu1.Pt()
1127  << " Pt2 = " << recMu2.Pt() << std::endl;
1128  }
1129 
1131 
1132  //Fill histograms
1133  //------------------
1134 
1135  mapHisto_["hRecBestMu"]->Fill(recMu1, -1, weight);
1136  mapHisto_["hRecBestMuVSEta"]->Fill(recMu1);
1137  mapHisto_["hRecBestMu"]->Fill(recMu2, +1, weight);
1138  mapHisto_["hRecBestMuVSEta"]->Fill(recMu2);
1139  mapHisto_["hDeltaRecBestMu"]->Fill(recMu1, recMu2);
1140  // Reconstructed resonance
1141  mapHisto_["hRecBestRes"]->Fill(bestRecRes, +1, weight);
1142  mapHisto_["hRecBestResAllEvents"]->Fill(bestRecRes, +1, 1.);
1143  // // Fill histogram of Res mass vs muon variables
1144  // mapHisto_["hRecBestResVSMu"]->Fill (recMu1, bestRecRes, -1);
1145  // mapHisto_["hRecBestResVSMu"]->Fill (recMu2, bestRecRes, +1);
1146  // // Fill also the mass mu+/mu- comparisons
1147  // mapHisto_["hRecBestResVSMu"]->Fill(recMu1, recMu2, bestRecRes);
1148 
1149  mapHisto_["hRecBestResVSMu"]->Fill(recMu1, bestRecRes, -1, weight);
1150  mapHisto_["hRecBestResVSMu"]->Fill(recMu2, bestRecRes, +1, weight);
1151  // Fill also the mass mu+/mu- comparisons
1152  mapHisto_["hRecBestResVSMu"]->Fill(recMu1, recMu2, bestRecRes, weight);
1153 
1154  //-- rc 2010 filling histograms for mu+ /mu- ------
1155  // mapHisto_["hRecBestResVSMuMinus"]->Fill (recMu1, bestRecRes, -1);
1156  // mapHisto_["hRecBestResVSMuPlus"]->Fill (recMu2, bestRecRes, +1);
1157 
1158  //-- rc 2010 filling histograms MassVsMuEtaPhi------
1159  // mapHisto_["hRecBestResVSMuEtaPhi"]->Fill (recMu1, bestRecRes,-1);
1160  // mapHisto_["hRecBestResVSMuEtaPhi"]->Fill (recMu2, bestRecRes,+1);
1161 
1162  // Fill histogram of Res mass vs Res variables
1163  // mapHisto_["hRecBestResVSRes"]->Fill (bestRecRes, bestRecRes, +1);
1164  mapHisto_["hRecBestResVSRes"]->Fill(bestRecRes, bestRecRes, +1, weight);
1165 
1166  std::vector<double>* parval;
1167  std::vector<double> initpar;
1168  // Store a pointer to the vector of parameters of the last iteration, or the initial
1169  // parameters if this is the first iteration
1170  if (loopCounter == 0) {
1171  initpar = MuScleFitUtils::parResol;
1172  initpar.insert(initpar.end(), MuScleFitUtils::parScale.begin(), MuScleFitUtils::parScale.end());
1173  initpar.insert(initpar.end(), MuScleFitUtils::parCrossSection.begin(), MuScleFitUtils::parCrossSection.end());
1174  initpar.insert(initpar.end(), MuScleFitUtils::parBgr.begin(), MuScleFitUtils::parBgr.end());
1175  parval = &initpar;
1176  } else {
1177  parval = &(MuScleFitUtils::parvalue[loopCounter - 1]);
1178  }
1179 
1180  //Compute pt resolution w.r.t generated and simulated muons
1181  //--------------------------------------------------------
1182  if (!MuScleFitUtils::speedup) {
1183  //first is always mu-, second is always mu+
1186  }
1189  }
1190  if (compareToSimTracks_) {
1191  //first is always mu-, second is always mu+
1194  }
1197  }
1198  }
1199  }
1200 
1201  // 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
1202  // Fill also the resolution histogramsm using the resolution functions:
1203  // the parameters are those from the last iteration, as the muons up to this point have also the corrections from the same iteration.
1204  // Need to use a different array (ForVec), containing functors able to operate on std::vector<double>
1205  mapHisto_["hFunctionResolPt"]->Fill(
1206  recMu1, MuScleFitUtils::resolutionFunctionForVec->sigmaPt(recMu1.Pt(), recMu1.Eta(), *parval), -1);
1207  mapHisto_["hFunctionResolCotgTheta"]->Fill(
1208  recMu1, MuScleFitUtils::resolutionFunctionForVec->sigmaCotgTh(recMu1.Pt(), recMu1.Eta(), *parval), -1);
1209  mapHisto_["hFunctionResolPhi"]->Fill(
1210  recMu1, MuScleFitUtils::resolutionFunctionForVec->sigmaPhi(recMu1.Pt(), recMu1.Eta(), *parval), -1);
1211  mapHisto_["hFunctionResolPt"]->Fill(
1212  recMu2, MuScleFitUtils::resolutionFunctionForVec->sigmaPt(recMu2.Pt(), recMu2.Eta(), *parval), +1);
1213  mapHisto_["hFunctionResolCotgTheta"]->Fill(
1214  recMu2, MuScleFitUtils::resolutionFunctionForVec->sigmaCotgTh(recMu2.Pt(), recMu2.Eta(), *parval), +1);
1215  mapHisto_["hFunctionResolPhi"]->Fill(
1216  recMu2, MuScleFitUtils::resolutionFunctionForVec->sigmaPhi(recMu2.Pt(), recMu2.Eta(), *parval), +1);
1217 
1218  // Compute likelihood histograms
1219  // -----------------------------
1220  if (debug_ > 0)
1221  std::cout << "mass = " << bestRecRes.mass() << std::endl;
1222  if (weight != 0.) {
1223  double massResol;
1224  double prob;
1225  double deltalike;
1226  if (loopCounter == 0) {
1227  std::vector<double> initpar;
1228  initpar.reserve((int)(MuScleFitUtils::parResol.size()));
1229  for (int i = 0; i < (int)(MuScleFitUtils::parResol.size()); i++) {
1230  initpar.push_back(MuScleFitUtils::parResol[i]);
1231  }
1232  for (int i = 0; i < (int)(MuScleFitUtils::parScale.size()); i++) {
1233  initpar.push_back(MuScleFitUtils::parScale[i]);
1234  }
1235  // for (int i=0; i<(int)(MuScleFitUtils::parCrossSection.size()); i++) {
1236  // initpar.push_back(MuScleFitUtils::parCrossSection[i]);
1237  // }
1239 
1240  for (int i = 0; i < (int)(MuScleFitUtils::parBgr.size()); i++) {
1241  initpar.push_back(MuScleFitUtils::parBgr[i]);
1242  }
1243  massResol = MuScleFitUtils::massResolution(recMu1, recMu2, initpar);
1244  // prob = MuScleFitUtils::massProb( bestRecRes.mass(), bestRecRes.Eta(), bestRecRes.Rapidity(), massResol, initpar, true );
1245  prob = MuScleFitUtils::massProb(bestRecRes.mass(),
1246  bestRecRes.Eta(),
1247  bestRecRes.Rapidity(),
1248  massResol,
1249  initpar,
1250  true,
1251  recMu1.eta(),
1252  recMu2.eta());
1253  } else {
1255  // prob = MuScleFitUtils::massProb( bestRecRes.mass(), bestRecRes.Eta(), bestRecRes.Rapidity(),
1256  // massResol, MuScleFitUtils::parvalue[loopCounter-1], true );
1257  prob = MuScleFitUtils::massProb(bestRecRes.mass(),
1258  bestRecRes.Eta(),
1259  bestRecRes.Rapidity(),
1260  massResol,
1262  true,
1263  recMu1.eta(),
1264  recMu2.eta());
1265  }
1266  if (debug_ > 0)
1267  std::cout << "inside weight: mass = " << bestRecRes.mass() << ", prob = " << prob << std::endl;
1268  if (prob > 0) {
1269  if (debug_ > 0)
1270  std::cout << "inside prob: mass = " << bestRecRes.mass() << ", prob = " << prob << std::endl;
1271 
1272  deltalike = log(prob) * weight; // NB maximum likelihood --> deltalike is maximized
1273  mapHisto_["hLikeVSMu"]->Fill(recMu1, deltalike);
1274  mapHisto_["hLikeVSMu"]->Fill(recMu2, deltalike);
1275  mapHisto_["hLikeVSMuMinus"]->Fill(recMu1, deltalike);
1276  mapHisto_["hLikeVSMuPlus"]->Fill(recMu2, deltalike);
1277 
1278  double recoMass = (recMu1 + recMu2).mass();
1279  if (recoMass != 0) {
1280  // IMPORTANT: massResol is not a relative resolution
1281  mapHisto_["hResolMassVSMu"]->Fill(recMu1, massResol, -1);
1282  mapHisto_["hResolMassVSMu"]->Fill(recMu2, massResol, +1);
1283  mapHisto_["hFunctionResolMassVSMu"]->Fill(recMu1, massResol / recoMass, -1);
1284  mapHisto_["hFunctionResolMassVSMu"]->Fill(recMu2, massResol / recoMass, +1);
1285  }
1286 
1288  mapHisto_["hdMdPt1"]->Fill(recMu1, MuScleFitUtils::massResolComponents.dmdpt1, -1);
1289  mapHisto_["hdMdPt2"]->Fill(recMu2, MuScleFitUtils::massResolComponents.dmdpt2, +1);
1290  mapHisto_["hdMdPhi1"]->Fill(recMu1, MuScleFitUtils::massResolComponents.dmdphi1, -1);
1291  mapHisto_["hdMdPhi2"]->Fill(recMu2, MuScleFitUtils::massResolComponents.dmdphi2, +1);
1292  mapHisto_["hdMdCotgTh1"]->Fill(recMu1, MuScleFitUtils::massResolComponents.dmdcotgth1, -1);
1293  mapHisto_["hdMdCotgTh2"]->Fill(recMu2, MuScleFitUtils::massResolComponents.dmdcotgth2, +1);
1294  }
1295 
1296  if (!MuScleFitUtils::speedup) {
1297  double genMass = (MuScleFitUtils::genPair[iev].first + MuScleFitUtils::genPair[iev].second).mass();
1298  // Fill the mass resolution (computed from MC), we use the covariance class to compute the variance
1299  if (genMass != 0) {
1300  mapHisto_["hGenResVSMu"]->Fill((MuScleFitUtils::genPair[iev].first),
1302  -1);
1303  mapHisto_["hGenResVSMu"]->Fill((MuScleFitUtils::genPair[iev].second),
1305  +1);
1306  double diffMass = (recoMass - genMass) / genMass;
1307  // double diffMass = recoMass - genMass;
1308  // Fill if for both muons
1309  double pt1 = recMu1.pt();
1310  double eta1 = recMu1.eta();
1311  double pt2 = recMu2.pt();
1312  double eta2 = recMu2.eta();
1313  // This is to avoid nan
1314  if (diffMass == diffMass) {
1315  // Mass relative difference vs Pt and Eta. To be used to extract the true mass resolution
1316  mapHisto_["hDeltaMassOverGenMassVsPt"]->Fill(pt1, diffMass);
1317  mapHisto_["hDeltaMassOverGenMassVsPt"]->Fill(pt2, diffMass);
1318  mapHisto_["hDeltaMassOverGenMassVsEta"]->Fill(eta1, diffMass);
1319  mapHisto_["hDeltaMassOverGenMassVsEta"]->Fill(eta2, diffMass);
1320  // This is used for the covariance comparison
1321  mapHisto_["hMassResolutionVsPtEta"]->Fill(pt1, eta1, diffMass, diffMass);
1322  mapHisto_["hMassResolutionVsPtEta"]->Fill(pt2, eta2, diffMass, diffMass);
1323  } else {
1324  std::cout << "Error, there is a nan: recoMass = " << recoMass << ", genMass = " << genMass << std::endl;
1325  }
1326  }
1327  // Fill with mass resolution from resolution function
1329  mapHisto_["hFunctionResolMass"]->Fill(recMu1, std::pow(massRes, 2), -1);
1330  mapHisto_["hFunctionResolMass"]->Fill(recMu2, std::pow(massRes, 2), +1);
1331  }
1332 
1333  mapHisto_["hMass_P"]->Fill(bestRecRes.mass(), prob);
1334  if (debug_ > 0)
1335  std::cout << "mass = " << bestRecRes.mass() << ", prob = " << prob << std::endl;
1336  mapHisto_["hMass_fine_P"]->Fill(bestRecRes.mass(), prob);
1337 
1338  mapHisto_["hMassProbVsRes"]->Fill(bestRecRes, bestRecRes, +1, prob);
1339  mapHisto_["hMassProbVsMu"]->Fill(recMu1, bestRecRes, -1, prob);
1340  mapHisto_["hMassProbVsMu"]->Fill(recMu2, bestRecRes, +1, prob);
1341  mapHisto_["hMassProbVsRes_fine"]->Fill(bestRecRes, bestRecRes, +1, prob);
1342  mapHisto_["hMassProbVsMu_fine"]->Fill(recMu1, bestRecRes, -1, prob);
1343  mapHisto_["hMassProbVsMu_fine"]->Fill(recMu2, bestRecRes, +1, prob);
1344  }
1345  }
1346  } // end if ResFound
1347 
1348  // Fill the pair
1349  // -------------
1350  if (loopCounter > 0) {
1351  if (debug_ > 0)
1352  std::cout << "[MuScleFit]: filling the pair" << std::endl;
1353  MuScleFitUtils::SavedPair[iev] = std::make_pair(recMu1, recMu2);
1354  }
1355 
1356  iev++;
1358 
1359  // return kContinue;
1360 }
1361 
1363  //first is always mu-, second is always mu+
1364  double deltaR =
1365  sqrt(MuScleFitUtils::deltaPhi(recMu.Phi(), genMu.Phi()) * MuScleFitUtils::deltaPhi(recMu.Phi(), genMu.Phi()) +
1366  ((recMu.Eta() - genMu.Eta()) * (recMu.Eta() - genMu.Eta())));
1367  if (deltaR < 0.01)
1368  return true;
1369  else if (debug_ > 0) {
1370  std::cout << "Reco muon " << recMu << " with eta " << recMu.Eta() << " and phi " << recMu.Phi() << std::endl
1371  << " DOES NOT MATCH with generated muon from resonance: " << std::endl
1372  << genMu << " with eta " << genMu.Eta() << " and phi " << genMu.Phi() << std::endl;
1373  }
1374  return false;
1375 }
1376 
1378  const reco::Particle::LorentzVector& recMu,
1379  const std::string& inputName,
1380  const int charge) {
1381  std::string name(inputName + "VSMu");
1382  mapHisto_["hResolPt" + name]->Fill(recMu, (-genMu.Pt() + recMu.Pt()) / genMu.Pt(), charge);
1383  mapHisto_["hResolTheta" + name]->Fill(recMu, (-genMu.Theta() + recMu.Theta()), charge);
1384  mapHisto_["hResolCotgTheta" + name]->Fill(
1385  recMu, (-cos(genMu.Theta()) / sin(genMu.Theta()) + cos(recMu.Theta()) / sin(recMu.Theta())), charge);
1386  mapHisto_["hResolEta" + name]->Fill(recMu, (-genMu.Eta() + recMu.Eta()), charge);
1387  mapHisto_["hResolPhi" + name]->Fill(recMu, MuScleFitUtils::deltaPhiNoFabs(recMu.Phi(), genMu.Phi()), charge);
1388 
1389  // Fill only if it was matched to a genMu and this muon is valid
1390  if ((genMu.Pt() != 0) && (recMu.Pt() != 0)) {
1391  mapHisto_["hPtRecoVsPt" + inputName]->Fill(genMu.Pt(), recMu.Pt());
1392  }
1393 }
1394 
1396  if (MuScleFitUtils::SmearType > 0) {
1398  if (debug_ > 0)
1399  std::cout << "Muon #" << MuScleFitUtils::goodmuon << ": after smearing Pt = " << mu.Pt() << std::endl;
1400  }
1401 }
1402 
1404  if (MuScleFitUtils::BiasType > 0) {
1406  if (debug_ > 0)
1407  std::cout << "Muon #" << MuScleFitUtils::goodmuon << ": after bias Pt = " << mu.Pt() << std::endl;
1408  }
1409 }
1410 
1411 // Simple method to check parameters consistency. It aborts the job if the parameters
1412 // are not consistent.
1414  // Fits selection dimension check
1416  std::cout << "[MuScleFit-Constructor]: wrong size of resolution fits selector = "
1417  << MuScleFitUtils::doResolFit.size() << std::endl;
1418  std::cout << "it must have as many values as the number of loops, which is = " << maxLoopNumber << std::endl;
1419  abort();
1420  }
1422  std::cout << "[MuScleFit-Constructor]: wrong size of scale fits selector = " << MuScleFitUtils::doScaleFit.size()
1423  << std::endl;
1424  std::cout << "it must have as many values as the number of loops, which is = " << maxLoopNumber << std::endl;
1425  abort();
1426  }
1428  std::cout << "[MuScleFit-Constructor]: wrong size of cross section fits selector = "
1429  << MuScleFitUtils::doCrossSectionFit.size() << std::endl;
1430  std::cout << "it must have as many values as the number of loops, which is = " << maxLoopNumber << std::endl;
1431  abort();
1432  }
1434  std::cout << "[MuScleFit-Constructor]: wrong size of background fits selector = "
1435  << MuScleFitUtils::doBackgroundFit.size() << std::endl;
1436  std::cout << "it must have as many values as the number of loops, which is = " << maxLoopNumber << std::endl;
1437  abort();
1438  }
1439 
1440  // Bias parameters: dimension check
1441  // --------------------------------
1442  if ((MuScleFitUtils::BiasType == 1 && MuScleFitUtils::parBias.size() != 2) || // linear in pt
1443  (MuScleFitUtils::BiasType == 2 && MuScleFitUtils::parBias.size() != 2) || // linear in |eta|
1444  (MuScleFitUtils::BiasType == 3 && MuScleFitUtils::parBias.size() != 4) || // sinusoidal in phi
1445  (MuScleFitUtils::BiasType == 4 && MuScleFitUtils::parBias.size() != 3) || // linear in pt and |eta|
1446  (MuScleFitUtils::BiasType == 5 && MuScleFitUtils::parBias.size() != 3) || // linear in pt and sinusoidal in phi
1447  (MuScleFitUtils::BiasType == 6 &&
1448  MuScleFitUtils::parBias.size() != 3) || // linear in |eta| and sinusoidal in phi
1449  (MuScleFitUtils::BiasType == 7 &&
1450  MuScleFitUtils::parBias.size() != 4) || // linear in pt and |eta| and sinusoidal in phi
1451  (MuScleFitUtils::BiasType == 8 && MuScleFitUtils::parBias.size() != 4) || // linear in pt and parabolic in |eta|
1452  (MuScleFitUtils::BiasType == 9 && MuScleFitUtils::parBias.size() != 2) || // exponential in pt
1453  (MuScleFitUtils::BiasType == 10 && MuScleFitUtils::parBias.size() != 3) || // parabolic in pt
1454  (MuScleFitUtils::BiasType == 11 &&
1455  MuScleFitUtils::parBias.size() != 4) || // linear in pt and sin in phi with chg
1456  (MuScleFitUtils::BiasType == 12 &&
1457  MuScleFitUtils::parBias.size() != 6) || // linear in pt and para in plus sin in phi with chg
1458  (MuScleFitUtils::BiasType == 13 &&
1459  MuScleFitUtils::parBias.size() != 8) || // linear in pt and para in plus sin in phi with chg
1461  MuScleFitUtils::BiasType > 13) {
1462  std::cout << "[MuScleFit-Constructor]: Wrong bias type or number of parameters: aborting!" << std::endl;
1463  abort();
1464  }
1465  // Smear parameters: dimension check
1466  // ---------------------------------
1475  std::cout << "[MuScleFit-Constructor]: Wrong smear type or number of parameters: aborting!" << std::endl;
1476  abort();
1477  }
1478  // Protect against bad size of parameters
1479  // --------------------------------------
1482  std::cout << "[MuScleFit-Constructor]: Mismatch in number of parameters for Resol: aborting!" << std::endl;
1483  abort();
1484  }
1487  std::cout << "[MuScleFit-Constructor]: Mismatch in number of parameters for Scale: aborting!" << std::endl;
1488  abort();
1489  }
1492  std::cout << "[MuScleFit-Constructor]: Mismatch in number of parameters for Bgr: aborting!" << std::endl;
1493  abort();
1494  }
1497  std::cout << "[MuScleFit-Constructor]: Mismatch in number of parameters for Bgr: aborting!" << std::endl;
1498  abort();
1499  }
1500 
1501  // Protect against an incorrect number of resonances
1502  // -------------------------------------------------
1503  if (MuScleFitUtils::resfind.size() != 6) {
1504  std::cout << "[MuScleFit-Constructor]: resfind must have 6 elements (1 Z, 3 Y, 2 Psi): aborting!" << std::endl;
1505  abort();
1506  }
1507 }
1508 
1510  reco::TrackRef iTrack = aMuon->innerTrack();
1511  const reco::HitPattern& p = iTrack->hitPattern();
1512 
1513  reco::TrackRef gTrack = aMuon->globalTrack();
1514  const reco::HitPattern& q = gTrack->hitPattern();
1515 
1516  return ( //isMuonInAccept(aMuon) &&// no acceptance cuts!
1517  iTrack->found() > 11 && gTrack->chi2() / gTrack->ndof() < 20.0 && q.numberOfValidMuonHits() > 0 &&
1518  iTrack->chi2() / iTrack->ndof() < 4.0 && aMuon->muonID("TrackerMuonArbitrated") &&
1519  aMuon->muonID("TMLastStationAngTight") && p.pixelLayersWithMeasurement() > 1 &&
1520  fabs(iTrack->dxy()) < 3.0 && //should be done w.r.t. PV!
1521  fabs(iTrack->dz()) < 15.0); //should be done w.r.t. PV!
1522 }
1523 
1525  reco::TrackRef iTrack = aMuon->innerTrack();
1526  const reco::HitPattern& p = iTrack->hitPattern();
1527 
1528  return ( //isMuonInAccept(aMuon) // no acceptance cuts!
1529  iTrack->found() > 11 && 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 
MuScleFit::takeSelectedMuonType
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:352
MuScleFitUtils::x
static double x[7][10000]
Definition: MuScleFitUtils.h:213
PDWG_BPHSkim_cff.muons
muons
Definition: PDWG_BPHSkim_cff.py:47
MuScleFitUtils::parSmear
static std::vector< double > parSmear
Definition: MuScleFitUtils.h:190
MuScleFitUtils::parScaleFix
static std::vector< int > parScaleFix
Definition: MuScleFitUtils.h:203
MuScleFitBase.h
edm::EDLooperBase::Status
Status
Definition: EDLooperBase.h:79
MuScleFit::ifHepMC
bool ifHepMC
Definition: MuScleFit.cc:266
MuScleFitBase::muonPairs_
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
MuScleFit::selTrackerMuon
bool selTrackerMuon(const pat::Muon *aMuon)
Definition: MuScleFit.cc:1524
PDWG_EXOHSCP_cff.tracks
tracks
Definition: PDWG_EXOHSCP_cff.py:28
MuScleFitUtils::BiasType
static int BiasType
Definition: MuScleFitUtils.h:149
PileupSummaryInfo.h
MuScleFitUtils::minMuonPt_
static double minMuonPt_
Definition: MuScleFitUtils.h:259
CompositeCandidate.h
MuScleFitUtils::deltaPhiNoFabs
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...
Definition: MuScleFitUtils.h:118
MuScleFit::saveAllToTree_
bool saveAllToTree_
Definition: MuScleFit.cc:306
MuScleFitUtils::findBestRecoRes
static std::pair< MuScleFitMuon, MuScleFitMuon > findBestRecoRes(const std::vector< MuScleFitMuon > &muons)
Definition: MuScleFitUtils.cc:315
mps_fire.i
i
Definition: mps_fire.py:428
MuScleFitUtils::smearFunction
static smearFunctionBase * smearFunction
Definition: MuScleFitUtils.h:148
MuScleFitBase
Definition: MuScleFitBase.h:18
MuScleFitUtils::parResolMin
static std::vector< double > parResolMin
Definition: MuScleFitUtils.h:194
RootTreeHandler
Definition: RootTreeHandler.h:24
HLT_FULL_cff.track
track
Definition: HLT_FULL_cff.py:11713
Muon.h
MuonPatternRecoDumper.h
MuScleFit::fillComparisonHistograms
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:1377
MuScleFitUtils::parvalue
static std::vector< std::vector< double > > parvalue
Definition: MuScleFitUtils.h:226
MuScleFitUtils::separateRanges_
static bool separateRanges_
Definition: MuScleFitUtils.h:258
MuScleFit::numberOfSimMuons
int numberOfSimMuons
Definition: MuScleFit.cc:262
MuScleFitBase::genMuonPairs_
std::vector< GenMuonPair > genMuonPairs_
Stores the genMuon pairs and the motherId prior to the creation of the internal tree.
Definition: MuScleFitBase.h:84
MuScleFitUtils::parScaleOrder
static std::vector< int > parScaleOrder
Definition: MuScleFitUtils.h:207
MuScleFitUtils::ResMass
static double ResMass[6]
Definition: MuScleFitUtils.h:136
ESHandle.h
TriggerResults.h
vec1
std::vector< double > vec1
Definition: HCALResponse.h:15
Event.h
BackgroundHandler
Definition: BackgroundHandler.h:32
muon
Definition: MuonCocktails.h:17
MuScleFitUtils::maxMuonEtaFirstRange_
static double maxMuonEtaFirstRange_
Definition: MuScleFitUtils.h:262
MuScleFitUtils::computeWeight
static double computeWeight(const double &mass, const int iev, const bool doUseBkgrWindow=false)
Definition: MuScleFitUtils.cc:1163
amptDefaultParameters_cff.mu
mu
Definition: amptDefaultParameters_cff.py:16
MuScleFitUtils::deltaPhi
static double deltaPhi(const double &phi1, const double &phi2)
Definition: MuScleFitUtils.h:109
GenMuonPair
Definition: GenMuonPair.h:19
MuScleFit::duringLoop
edm::EDLooper::Status duringLoop(const edm::Event &event, const edm::EventSetup &eventSetup) override
Definition: MuScleFit.cc:788
edm
HLT enums.
Definition: AlignableModifier.h:19
MuScleFit::totalEvents_
int totalEvents_
Definition: MuScleFit.cc:288
Muon.h
mps_merge.weight
weight
Definition: mps_merge.py:88
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
MuScleFitPlotter::fillTreeRec
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.
Definition: MuScleFitPlotter.cc:334
MuScleFitUtils::parBgrFix
static std::vector< int > parBgrFix
Definition: MuScleFitUtils.h:205
MuScleFitUtils::deltaPhiMaxCut_
static double deltaPhiMaxCut_
Definition: MuScleFitUtils.h:266
gather_cfg.cout
cout
Definition: gather_cfg.py:144
MuScleFitUtils::computeMinosErrors_
static bool computeMinosErrors_
Definition: MuScleFitUtils.h:280
MuScleFitUtils::mMu2
static const double mMu2
Definition: MuScleFitUtils.h:139
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89287
MuScleFitUtils::crossSectionHandler
static CrossSectionHandler * crossSectionHandler
Definition: MuScleFitUtils.h:171
triggerResults
static const std::string triggerResults
Definition: EdmProvDump.cc:45
MuScleFitUtils::MuonTypeForCheckMassWindow
static int MuonTypeForCheckMassWindow
Definition: MuScleFitUtils.h:224
MuScleFit::negateTrigger_
bool negateTrigger_
Definition: MuScleFit.cc:305
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:222
callgraph.G
G
Definition: callgraph.py:13
MuScleFitMuon
Definition: Muon.h:14
resolutionFunctionService
resolutionFunctionBase< double * > * resolutionFunctionService(const int identifier)
Service to build the resolution functor corresponding to the passed identifier.
Definition: Functions.cc:70
MuScleFitUtils::parResolOrder
static std::vector< int > parResolOrder
Definition: MuScleFitUtils.h:206
MuScleFitUtils::parCrossSectionOrder
static std::vector< int > parCrossSectionOrder
Definition: MuScleFitUtils.h:208
MuScleFitUtils::speedup
static bool speedup
Definition: MuScleFitUtils.h:212
MuScleFitUtils::applyScale
static lorentzVector applyScale(const lorentzVector &muon, const std::vector< double > &parval, const int charge)
Definition: MuScleFitUtils.cc:465
pat::Muon
Analysis-level muon class.
Definition: Muon.h:51
MuScleFit
Definition: MuScleFit.cc:185
vec2
std::vector< vec1 > vec2
Definition: HCALResponse.h:16
tools.TF1
TF1
Definition: tools.py:23
MuScleFitUtils::FitStrategy
static int FitStrategy
Definition: MuScleFitUtils.h:211
MuScleFitUtils::massResolComponents
static struct MuScleFitUtils::massResolComponentsStruct massResolComponents
Definition: MuScleFitUtils.cc:262
edm::Handle< edm::TriggerResults >
DEFINE_FWK_LOOPER
#define DEFINE_FWK_LOOPER(type)
Definition: LooperFactory.h:107
MuScleFit::endOfJob
void endOfJob() override
Definition: MuScleFit.cc:675
MuScleFit::selectMuons
void selectMuons(const edm::Event &event)
Definition: MuScleFit.cc:863
MuScleFit::ifGenPart
bool ifGenPart
Definition: MuScleFit.cc:267
dqmdumpme.first
first
Definition: dqmdumpme.py:55
MuScleFitUtils::useProbsFile_
static bool useProbsFile_
Definition: MuScleFitUtils.h:255
MuScleFitBase::readProbabilityDistributionsFromFile
void readProbabilityDistributionsFromFile()
Read probability distributions from a local root file.
Definition: MuScleFitBase.cc:159
MuScleFitUtils::resfind
static std::vector< int > resfind
Definition: MuScleFitUtils.h:210
edm::EDLooper
Definition: EDLooper.h:27
MuScleFit::maxEventsFromRootTree_
int maxEventsFromRootTree_
Definition: MuScleFit.cc:300
MuScleFit::numberOfSimVertices
int numberOfSimVertices
Definition: MuScleFit.cc:263
MuScleFitUtils::genPair
static std::vector< std::pair< lorentzVector, lorentzVector > > genPair
Definition: MuScleFitUtils.h:233
reco::Particle::LorentzVector
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:21
MuScleFit::recMu2
reco::Particle::LorentzVector recMu2
Definition: MuScleFit.cc:285
edm::Ref< TrackCollection >
MuScleFitUtils::rapidityBinsForZ_
static bool rapidityBinsForZ_
Definition: MuScleFitUtils.h:251
MuScleFit::endOfLoop
edm::EDLooper::Status endOfLoop(const edm::EventSetup &eventSetup, unsigned int iLoop) override
Definition: MuScleFit.cc:709
MuonPair
Definition: MuonPair.h:13
MuScleFitUtils::applySmearing
static lorentzVector applySmearing(const lorentzVector &muon)
Definition: MuScleFitUtils.cc:416
funct::sin
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
resolutionFunctionVecService
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
CrossSectionHandler::addParameters
void addParameters(std::vector< double > &initpar)
Inputs the vars in a vector.
Definition: CrossSectionHandler.h:50
MuScleFitUtils::minimumShapePlots_
static bool minimumShapePlots_
Definition: MuScleFitUtils.h:281
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
MuScleFitUtils::doCrossSectionFit
static std::vector< int > doCrossSectionFit
Definition: MuScleFitUtils.h:180
MakerMacros.h
MuScleFit::recMuScleMu1
MuScleFitMuon recMuScleMu1
Definition: MuScleFit.cc:286
reco::HitPattern
Definition: HitPattern.h:147
MuScleFitBase::theFiles_
std::vector< TFile * > theFiles_
The files were the histograms are saved.
Definition: MuScleFitBase.h:76
funct::cos
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Track.h
MuScleFit::simTracksCollection_
edm::InputTag simTracksCollection_
Definition: MuScleFit.cc:291
MuScleFitMuonSelector.h
MuScleFitUtils::parResol
static std::vector< double > parResol
Definition: MuScleFitUtils.h:192
MuScleFitUtils::normalizeLikelihoodByEventNumber_
static bool normalizeLikelihoodByEventNumber_
Definition: MuScleFitUtils.h:240
MuScleFitUtils::parCrossSection
static std::vector< double > parCrossSection
Definition: MuScleFitUtils.h:200
MuScleFitUtils::debugMassResol_
static bool debugMassResol_
Definition: MuScleFitUtils.h:268
edm::EDLooperBase::kStop
Definition: EDLooperBase.h:79
SiPixelRawToDigiRegional_cfi.deltaPhi
deltaPhi
Definition: SiPixelRawToDigiRegional_cfi.py:9
HLT_FULL_cff.muon
muon
Definition: HLT_FULL_cff.py:11710
L1TEGammaOffline_cfi.triggerNames
triggerNames
Definition: L1TEGammaOffline_cfi.py:40
Service.h
MuScleFitUtils::parResolMax
static std::vector< double > parResolMax
Definition: MuScleFitUtils.h:195
MuonFwd.h
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
HLT_FULL_cff.eta2
eta2
Definition: HLT_FULL_cff.py:9542
MuScleFitPlotter.h
MuScleFitUtils::ResFound
static bool ResFound
Definition: MuScleFitUtils.h:131
MuScleFitPlotter::fillTreeGen
void fillTreeGen(const std::vector< std::pair< reco::Particle::LorentzVector, reco::Particle::LorentzVector > > &genPairs)
Definition: MuScleFitPlotter.cc:354
MuScleFit::recMu1
reco::Particle::LorentzVector recMu1
Definition: MuScleFit.cc:285
MuScleFitUtils::deltaPhiMinCut_
static double deltaPhiMinCut_
Definition: MuScleFitUtils.h:265
LeafCandidate.h
MuScleFit::numberOfSimTracks
int numberOfSimTracks
Definition: MuScleFit.cc:261
Event
HLT_FULL_cff.pt1
pt1
Definition: HLT_FULL_cff.py:9870
RootTreeHandler.h
MuScleFitUtils::scaleFunction
static scaleFunctionBase< double * > * scaleFunction
Definition: MuScleFitUtils.h:156
MuScleFitUtils::massResolution
static double massResolution(const lorentzVector &mu1, const lorentzVector &mu2)
MuScleFitUtils::startWithSimplex_
static bool startWithSimplex_
Definition: MuScleFitUtils.h:279
MuScleFit::startingNewLoop
void startingNewLoop(unsigned int iLoop) override
Definition: MuScleFit.cc:682
MuScleFitUtils::minMuonEtaSecondRange_
static double minMuonEtaSecondRange_
Definition: MuScleFitUtils.h:263
MuScleFit::applySmearing
void applySmearing(reco::Particle::LorentzVector &mu)
Apply the smearing if needed using the function in MuScleFitUtils.
Definition: MuScleFit.cc:1395
MuScleFitUtils::ResolFitType
static int ResolFitType
Definition: MuScleFitUtils.h:152
MuScleFitBase::theMuonLabel_
edm::InputTag theMuonLabel_
Definition: MuScleFitBase.h:48
MuScleFit::maxLoopNumber
unsigned int maxLoopNumber
Definition: MuScleFit.cc:276
MuScleFit::maxResMass_hwindow
double maxResMass_hwindow[6]
Definition: MuScleFit.cc:272
MuScleFitUtils::parScale
static std::vector< double > parScale
Definition: MuScleFitUtils.h:196
MuScleFitUtils::resolutionFunctionForVec
static resolutionFunctionBase< std::vector< double > > * resolutionFunctionForVec
Definition: MuScleFitUtils.h:154
MuScleFitBase::theRootFileName_
std::string theRootFileName_
Definition: MuScleFitBase.h:50
PbPb_ZMuSkimMuonDPG_cff.deltaR
deltaR
Definition: PbPb_ZMuSkimMuonDPG_cff.py:63
RootTreeHandler::writeTree
void writeTree(const TString &fileName, const std::vector< MuonPair > *savedPair, const int muonType=0, const std::vector< GenMuonPair > *genPair=nullptr, const bool saveAll=false)
Definition: RootTreeHandler.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
Vertex.h
scaleFunctionVecService
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
MuScleFitUtils::minMuonEtaFirstRange_
static double minMuonEtaFirstRange_
Definition: MuScleFitUtils.h:261
MuScleFit::beginOfJobInConstructor
void beginOfJobInConstructor()
Definition: MuScleFit.cc:639
LooperFactory.h
MuScleFit::triggerResultsLabel_
std::string triggerResultsLabel_
Definition: MuScleFit.cc:302
HLT_FULL_cff.eta1
eta1
Definition: HLT_FULL_cff.py:9541
MuScleFitUtils::SavedPairMuScleFitMuons
static std::vector< std::pair< MuScleFitMuon, MuScleFitMuon > > SavedPairMuScleFitMuons
Definition: MuScleFitUtils.h:234
MuScleFitUtils::massWindowHalfWidth
static double massWindowHalfWidth[3][6]
Definition: MuScleFitUtils.h:134
MuScleFit::theService
MuonServiceProxy * theService
Definition: MuScleFit.cc:257
ALCARECOTkAlJpsiMuMu_cff.charge
charge
Definition: ALCARECOTkAlJpsiMuMu_cff.py:47
MuScleFit::PATmuons_
bool PATmuons_
Definition: MuScleFit.cc:292
CaloMuon.h
MuScleFitBase::theMuonType_
int theMuonType_
Definition: MuScleFitBase.h:47
MuScleFitUtils::debug
static int debug
Definition: MuScleFitUtils.h:130
edm::ParameterSet
Definition: ParameterSet.h:47
MuScleFitUtils::parScaleMax
static std::vector< double > parScaleMax
Definition: MuScleFitUtils.h:199
MuScleFit::minResMass_hwindow
double minResMass_hwindow[6]
Definition: MuScleFit.cc:271
lorentzVector
reco::Particle::LorentzVector lorentzVector
Definition: GenMuonPair.h:9
MuScleFitUtils::iev_
static int iev_
Definition: MuScleFitUtils.h:253
GenEventInfoProduct.h
Event.h
ParticleDataTable.h
Histograms.h
ParameterSet
Definition: Functions.h:16
MuScleFitBase::fillHistoMap
void fillHistoMap(TFile *outputFile, unsigned int iLoop)
Create the histograms map.
Definition: MuScleFitBase.cc:9
MuScleFitUtils::SavedPair
static std::vector< std::pair< lorentzVector, lorentzVector > > SavedPair
Definition: MuScleFitUtils.h:231
createfilelist.int
int
Definition: createfilelist.py:10
TriggerNames.h
MuScleFit::muonSelector_
std::unique_ptr< MuScleFitMuonSelector > muonSelector_
Definition: MuScleFit.cc:312
MuScleFit::outputRootTreeFileName_
std::string outputRootTreeFileName_
Definition: MuScleFit.cc:298
MuScleFit::fillMuonCollection
std::vector< MuScleFitMuon > fillMuonCollection(const std::vector< T > &tracks)
Definition: MuScleFit.cc:316
MuScleFit::numberOfEwkZ
int numberOfEwkZ
Definition: MuScleFit.cc:264
MuScleFitUtils::biasFunction
static scaleFunctionBase< std::vector< double > > * biasFunction
Definition: MuScleFitUtils.h:151
submitPVResolutionJobs.q
q
Definition: submitPVResolutionJobs.py:84
edm::EventSetup
Definition: EventSetup.h:57
MuScleFitBase::debug_
int debug_
Definition: MuScleFitBase.h:53
MuScleFit::recMuScleMu2
MuScleFitMuon recMuScleMu2
Definition: MuScleFit.cc:286
edm::EDLooperBase::kContinue
Definition: EDLooperBase.h:79
HLT_FULL_cff.pt2
pt2
Definition: HLT_FULL_cff.py:9872
MuScleFitUtils::parResolFix
static std::vector< int > parResolFix
Definition: MuScleFitUtils.h:202
MuScleFit::selGlobalMuon
bool selGlobalMuon(const pat::Muon *aMuon)
Function for onia selections.
Definition: MuScleFit.cc:1509
HLTConfigProvider.h
MuScleFitBase::theGenInfoRootFileName_
std::string theGenInfoRootFileName_
Definition: MuScleFitBase.h:51
MuScleFitUtils::parBgr
static std::vector< double > parBgr
Definition: MuScleFitUtils.h:201
MuScleFit::triggerResultsProcess_
std::string triggerResultsProcess_
Definition: MuScleFit.cc:303
MuScleFitEvent
Definition: Event.h:6
MuScleFitUtils::maxMuonPt_
static double maxMuonPt_
Definition: MuScleFitUtils.h:260
MuScleFitBase::clearHistoMap
void clearHistoMap()
Clean the histograms map.
Definition: MuScleFitBase.cc:143
MuScleFitUtils::parBgrOrder
static std::vector< int > parBgrOrder
Definition: MuScleFitUtils.h:209
MuScleFitUtils::genMuscleFitPair
static std::vector< std::pair< MuScleFitMuon, MuScleFitMuon > > genMuscleFitPair
Definition: MuScleFitUtils.h:235
InputTag.h
pat::Muon::globalTrack
reco::TrackRef globalTrack() const override
reference to Track reconstructed in both tracked and muon detector (reimplemented from reco::Muon)
Definition: Muon.h:80
MuScleFit::puInfoSrc_
edm::InputTag puInfoSrc_
Definition: MuScleFit.cc:309
MuScleFitBase::theCompressionSettings_
int theCompressionSettings_
Definition: MuScleFitBase.h:49
MuScleFit::genParticlesName_
std::string genParticlesName_
Definition: MuScleFit.cc:293
MuScleFitUtils::oldNormalization_
static double oldNormalization_
Definition: MuScleFitUtils.h:244
MuScleFitUtils::parBias
static std::vector< double > parBias
Definition: MuScleFitUtils.h:191
MuScleFitUtils::scaleFunctionForVec
static scaleFunctionBase< std::vector< double > > * scaleFunctionForVec
Definition: MuScleFitUtils.h:157
MuScleFitUtils::applyBias
static lorentzVector applyBias(const lorentzVector &muon, const int charge)
Definition: MuScleFitUtils.cc:444
HLTConfigProvider
Definition: HLTConfigProvider.h:29
smearFunctionService
smearFunctionBase * smearFunctionService(const int identifier)
Service to build the smearing functor corresponding to the passed identifier.
Definition: Functions.cc:37
MuScleFit::applyBias
void applyBias(reco::Particle::LorentzVector &mu, const int charge)
Apply the bias if needed using the function in MuScleFitUtils.
Definition: MuScleFit.cc:1403
MuScleFitUtils::parCrossSectionFix
static std::vector< int > parCrossSectionFix
Definition: MuScleFitUtils.h:204
MuScleFitUtils::doBackgroundFit
static std::vector< int > doBackgroundFit
Definition: MuScleFitUtils.h:181
MuScleFitPlotter::debug
bool debug
Definition: MuScleFitPlotter.h:55
MuScleFitUtils::ScaleFitType
static int ScaleFitType
Definition: MuScleFitUtils.h:155
Frameworkfwd.h
T
long double T
Definition: Basic3DVectorLD.h:48
relativeConstraints.empty
bool empty
Definition: relativeConstraints.py:46
CrossSectionHandler
Definition: CrossSectionHandler.h:27
MuonServiceProxy.h
edm::TriggerNames
Definition: TriggerNames.h:55
MuScleFitUtils::SmearType
static int SmearType
Definition: MuScleFitUtils.h:147
EgHLTOffHistBins_cfi.mass
mass
Definition: EgHLTOffHistBins_cfi.py:34
MuScleFitUtils::counter_resprob
static int counter_resprob
Definition: MuScleFitUtils.h:215
MuScleFit::~MuScleFit
~MuScleFit() override
Definition: MuScleFit.cc:603
Data_TkAlMinBias_Run2018C_PromptReco_v3_cff.maxEvents
maxEvents
Definition: Data_TkAlMinBias_Run2018C_PromptReco_v3_cff.py:3
MuScleFitPlotter
Definition: MuScleFitPlotter.h:27
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
EventSetup.h
MuScleFitUtils::parScaleMin
static std::vector< double > parScaleMin
Definition: MuScleFitUtils.h:198
pat::Muon::muonID
bool muonID(const std::string &name) const
scaleFunctionService
scaleFunctionBase< double * > * scaleFunctionService(const int identifier)
Service to build the scale functor corresponding to the passed identifier.
Definition: Functions.cc:3
HltComparatorCreateWorkflow.hltConfig
hltConfig
Definition: HltComparatorCreateWorkflow.py:161
MuScleFitUtils::doScaleFit
static std::vector< int > doScaleFit
Definition: MuScleFitUtils.h:179
CSCSkim_cfi.rootFileName
rootFileName
Definition: CSCSkim_cfi.py:9
L1TStage2uGTEmulatorClient_cff.BX
BX
Definition: L1TStage2uGTEmulatorClient_cff.py:9
dqm-mbProfile.log
log
Definition: dqm-mbProfile.py:17
RootTreeHandler::readTree
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)
Definition: RootTreeHandler.h:86
Pi
const double Pi
Definition: CosmicMuonParameters.h:18
MuScleFitUtils::parScaleStep
static std::vector< double > parScaleStep
Definition: MuScleFitUtils.h:197
MuScleFit::checkParameters
void checkParameters()
Definition: MuScleFit.cc:1413
MuScleFit::endOfFastLoop
virtual void endOfFastLoop(const unsigned int iLoop)
Definition: MuScleFit.cc:753
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
MuScleFit::plotter
MuScleFitPlotter * plotter
Definition: MuScleFit.cc:281
MuScleFit::fastLoop
bool fastLoop
Definition: MuScleFit.cc:279
Functions.h
MuScleFitUtils::loopCounter
static unsigned int loopCounter
Definition: MuScleFitUtils.h:145
MuScleFitBase::mapHisto_
std::map< std::string, Histograms * > mapHisto_
The map of histograms.
Definition: MuScleFitBase.h:79
EventSetup
beamvalidation.exit
def exit(msg="")
Definition: beamvalidation.py:53
MuScleFit::compareToSimTracks_
bool compareToSimTracks_
Definition: MuScleFit.cc:290
ParameterSet.h
MuonServiceProxy
Definition: MuonServiceProxy.h:38
MuScleFit::vertexSrc_
edm::InputTag vertexSrc_
Definition: MuScleFit.cc:310
HepMCProduct.h
MuScleFit::inputRootTreeFileName_
std::string inputRootTreeFileName_
Definition: MuScleFit.cc:296
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
EDLooper.h
pat::Muon::innerTrack
reco::TrackRef innerTrack() const override
reference to Track reconstructed in the tracker only (reimplemented from reco::Muon)
Definition: Muon.h:72
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
event
Definition: event.py:1
MuScleFitUtils::sherpa_
static bool sherpa_
Definition: MuScleFitUtils.h:248
edm::Event
Definition: Event.h:73
MuScleFit::checkDeltaR
bool checkDeltaR(reco::Particle::LorentzVector &genMu, reco::Particle::LorentzVector &recMu)
Check if two lorentzVector are near in deltaR.
Definition: MuScleFit.cc:1362
MuScleFitUtils::parResolStep
static std::vector< double > parResolStep
Definition: MuScleFitUtils.h:193
MuScleFitUtils::resolutionFunction
static resolutionFunctionBase< double * > * resolutionFunction
Definition: MuScleFitUtils.h:153
MuScleFitUtils::MuonType
static int MuonType
Definition: MuScleFitUtils.h:223
TtFullHadEvtBuilder_cfi.prob
prob
Definition: TtFullHadEvtBuilder_cfi.py:33
SimTrackContainer.h
edm::InputTag
Definition: InputTag.h:15
MuScleFit::duringFastLoop
virtual void duringFastLoop()
Definition: MuScleFit.cc:1086
MuScleFitUtils::simPair
static std::vector< std::pair< lorentzVector, lorentzVector > > simPair
Definition: MuScleFitUtils.h:236
SimVertexContainer.h
weight
Definition: weight.py:1
MuScleFitUtils::goodmuon
static int goodmuon
Definition: MuScleFitUtils.h:214
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
MuScleFitUtils::backgroundHandler
static BackgroundHandler * backgroundHandler
Definition: MuScleFitUtils.h:175
MuScleFitUtils::minimizeLikelihood
static void minimizeLikelihood()
Definition: MuScleFitUtils.cc:1197
MuScleFit::iev
int iev
Definition: MuScleFit.cc:287
MuScleFitUtils::maxMuonEtaSecondRange_
static double maxMuonEtaSecondRange_
Definition: MuScleFitUtils.h:264
MuScleFit::MuScleFit
MuScleFit(const edm::ParameterSet &pset)
Definition: MuScleFit.cc:373
MuScleFitUtils::doResolFit
static std::vector< int > doResolFit
Definition: MuScleFitUtils.h:178
Muon.h
MuScleFitBase::writeHistoMap
void writeHistoMap(const unsigned int iLoop)
Save the histograms map to file.
Definition: MuScleFitBase.cc:150
GenEventInfoProduct::weight
double weight() const
Definition: GenEventInfoProduct.h:35
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
pwdgSkimBPark_cfi.vertices
vertices
Definition: pwdgSkimBPark_cfi.py:7
MuScleFit::triggerPath_
std::vector< std::string > triggerPath_
Definition: MuScleFit.cc:304
MuScleFitUtils::massProb
static double massProb(const double &mass, const double &rapidity, const int ires, const double &massResol)
Definition: MuScleFitUtils.cc:2208
MuScleFit::loopCounter
unsigned int loopCounter
Definition: MuScleFit.cc:277