CMS 3D CMS Logo

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