CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GenMuonRadCorrAnalyzer.cc
Go to the documentation of this file.
2 
5 
12 
14 
15 #include <TMath.h>
16 
18  : beamEnergy_(cfg.getParameter<double>("beamEnergy")),
19  muonRadiationAlgo_(0),
20  numWarnings_(0)
21 {
22  srcSelectedMuons_ = cfg.getParameter<edm::InputTag>("srcSelectedMuons");
23  srcGenParticles_ = cfg.getParameter<edm::InputTag>("srcGenParticles");
24 
25  srcWeights_ = cfg.getParameter<vInputTag>("srcWeights");
26 
27  directory_ = cfg.getParameter<std::string>("directory");
28 
29  verbosity_ = ( cfg.exists("verbosity") ) ?
30  cfg.getParameter<int>("verbosity") : 0;
31 
32  typedef std::vector<double> vdouble;
33  vdouble binningMuonEn = cfg.getParameter<vdouble>("binningMuonEn");
34  int numBinsMuonEn = binningMuonEn.size() - 1;
35  if ( !(numBinsMuonEn >= 1) ) throw cms::Exception("Configuration")
36  << " Invalid Configuration Parameter 'binningMuonEn', must define at least one bin !!\n";
37 
38  unsigned numBinsRadDivMuonEn = cfg.getParameter<unsigned>("numBinsRadDivMuonEn");
39  double minRadDivMuonEn = cfg.getParameter<double>("minRadDivMuonEn");
40  double maxRadDivMuonEn = cfg.getParameter<double>("maxRadDivMuonEn");
41 
42  for ( int iBinMuPlusEn = 0; iBinMuPlusEn < numBinsMuonEn; ++iBinMuPlusEn ) {
43  double minMuPlusEn = binningMuonEn[iBinMuPlusEn];
44  double maxMuPlusEn = binningMuonEn[iBinMuPlusEn + 1];
45  for ( int iBinMuMinusEn = 0; iBinMuMinusEn < numBinsMuonEn; ++iBinMuMinusEn ) {
46  double minMuMinusEn = binningMuonEn[iBinMuMinusEn];
47  double maxMuMinusEn = binningMuonEn[iBinMuMinusEn + 1];
48  plotEntryType* plotEntry =
49  new plotEntryType(minMuPlusEn, maxMuPlusEn, minMuMinusEn, maxMuMinusEn,
50  numBinsRadDivMuonEn, minRadDivMuonEn, maxRadDivMuonEn);
51  plotEntries_.push_back(plotEntry);
52  }
53  }
54 
55  std::string muonRadiationAlgo_string = cfg.getParameter<std::string>("muonRadiationAlgo");
56  if ( muonRadiationAlgo_string == "" ) {
58  } else if ( muonRadiationAlgo_string == "pythia" ) {
59  edm::ParameterSet cfgMuonRadiationAlgo_pythia(cfg);
60  cfgMuonRadiationAlgo_pythia.addParameter<std::string>("mode", "pythia");
61  cfgMuonRadiationAlgo_pythia.addParameter<int>("verbosity", verbosity_);
62  muonRadiationAlgo_ = new GenMuonRadiationAlgorithm(cfgMuonRadiationAlgo_pythia);
63  } else if ( muonRadiationAlgo_string == "photos" ) {
64  edm::ParameterSet cfgMuonRadiationAlgo_photos(cfg);
65  cfgMuonRadiationAlgo_photos.addParameter<std::string>("mode", "photos");
66  cfgMuonRadiationAlgo_photos.addParameter<int>("verbosity", verbosity_);
67  muonRadiationAlgo_ = new GenMuonRadiationAlgorithm(cfgMuonRadiationAlgo_photos);
68  } else throw cms::Exception("Configuration")
69  << " Invalid Configuration Parameter 'muonRadiationAlgo' = " << muonRadiationAlgo_string << " !!\n";
70 }
71 
73 {
74  for ( std::vector<plotEntryType*>::iterator it = plotEntries_.begin();
75  it != plotEntries_.end(); ++it ) {
76  delete (*it);
77  }
78 
79  delete muonRadiationAlgo_;
80 }
81 
83 {
85 
86  TFileDirectory dir = ( directory_ != "" ) ? fs->mkdir(directory_) : (fs->tFileDirectory());
87  for ( std::vector<plotEntryType*>::iterator plotEntry = plotEntries_.begin();
88  plotEntry != plotEntries_.end(); ++plotEntry ) {
89  (*plotEntry)->bookHistograms(dir);
90  }
91 }
92 
94 {
95  double evtWeight = 1.0;
96  for ( vInputTag::const_iterator srcWeight = srcWeights_.begin();
97  srcWeight != srcWeights_.end(); ++srcWeight ) {
99  evt.getByLabel(*srcWeight, weight);
100  evtWeight *= (*weight);
101  }
102 
103  if ( evtWeight < 1.e-3 || evtWeight > 1.e+3 || TMath::IsNaN(evtWeight) ) return;
104 
105  std::vector<reco::CandidateBaseRef> selectedMuons = getSelMuons(evt, srcSelectedMuons_);
106 
108  evt.getByLabel(srcGenParticles_, genParticles);
109 
110  reco::Candidate::LorentzVector genMuonPlusP4_beforeRad;
111  reco::Candidate::LorentzVector genMuonPlusP4_afterRad;
112  bool genMuonPlus_found = false;
113  reco::Candidate::LorentzVector genMuonMinusP4_beforeRad;
114  reco::Candidate::LorentzVector genMuonMinusP4_afterRad;
115  bool genMuonMinus_found = false;
116 
117  std::vector<int> muonPdgIds;
118  muonPdgIds.push_back(-13);
119  muonPdgIds.push_back(+13);
120 
121  for ( std::vector<reco::CandidateBaseRef>::const_iterator selectedMuon = selectedMuons.begin();
122  selectedMuon != selectedMuons.end(); ++selectedMuon ) {
123  const reco::GenParticle* genMuon_matched = findGenParticleForMCEmbedding((*selectedMuon)->p4(), *genParticles, 0.3, -1, &muonPdgIds, true);
124  if ( genMuon_matched && genMuon_matched->charge() > +0.5 ) {
125  genMuonPlusP4_beforeRad = genMuon_matched->p4();
126  genMuonPlusP4_afterRad = genMuonPlusP4_beforeRad;
127  compGenMuonP4afterRad(genMuon_matched, genMuonPlusP4_afterRad);
128  genMuonPlus_found = true;
129  }
130  if ( genMuon_matched && genMuon_matched->charge() < -0.5 ) {
131  genMuonMinusP4_beforeRad = genMuon_matched->p4();
132  genMuonMinusP4_afterRad = genMuonMinusP4_beforeRad;
133  compGenMuonP4afterRad(genMuon_matched, genMuonMinusP4_afterRad);
134  genMuonMinus_found = true;
135  }
136  }
137 
138  if ( !(genMuonPlus_found && genMuonMinus_found) ) return;
139 
140  double muonPlusRad = 0.;
141  int muonPlusRad_error = 0;
142  double muonMinusRad = 0.;
143  int muonMinusRad_error = 0;
144  if ( muonRadiationAlgo_ ) {
145  muonPlusRad = muonRadiationAlgo_->compFSR(evt.streamID(), genMuonPlusP4_beforeRad, +1, genMuonMinusP4_beforeRad, muonPlusRad_error).E();
146  muonMinusRad = muonRadiationAlgo_->compFSR(evt.streamID(), genMuonMinusP4_beforeRad, -1, genMuonPlusP4_beforeRad, muonMinusRad_error).E();
147  } else {
148  muonPlusRad = genMuonPlusP4_beforeRad.E() - genMuonPlusP4_afterRad.E();
149  muonMinusRad = genMuonMinusP4_beforeRad.E() - genMuonMinusP4_afterRad.E();
150  }
151 
152  if ( muonPlusRad_error || muonMinusRad_error ) return;
153 
154  for ( std::vector<plotEntryType*>::iterator plotEntry = plotEntries_.begin();
155  plotEntry != plotEntries_.end(); ++plotEntry ) {
156  (*plotEntry)->fillHistograms(genMuonPlusP4_afterRad.E(), muonPlusRad, genMuonMinusP4_afterRad.E(), muonMinusRad, evtWeight);
157  }
158 }
159 
161 
T getParameter(std::string const &) const
tuple cfg
Definition: looper.py:293
GenMuonRadiationAlgorithm * muonRadiationAlgo_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
bool exists(std::string const &parameterName) const
checks if a parameter exists
void analyze(const edm::Event &, const edm::EventSetup &)
TFileDirectory & tFileDirectory()
Definition: TFileService.h:42
GenMuonRadCorrAnalyzer(const edm::ParameterSet &)
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:144
virtual int charge() const
electric charge
Definition: LeafCandidate.h:91
const reco::GenParticle * findGenParticleForMCEmbedding(const reco::Candidate::LorentzVector &, const reco::GenParticleCollection &, double, int, const std::vector< int > *, bool)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:420
void compGenMuonP4afterRad(const reco::GenParticle *, reco::Candidate::LorentzVector &)
reco::Candidate::LorentzVector compFSR(const edm::StreamID &streamID, const reco::Candidate::LorentzVector &, int, const reco::Candidate::LorentzVector &, int &)
std::vector< edm::InputTag > vInputTag
TFileDirectory mkdir(const std::string &dir, const std::string &descr="")
create a new subdirectory
Definition: TFileService.h:69
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:37
StreamID streamID() const
Definition: Event.h:79
std::vector< reco::CandidateBaseRef > getSelMuons(const edm::Event &, const edm::InputTag &)
dbl *** dir
Definition: mlp_gen.cc:35
virtual const LorentzVector & p4() const
four-momentum Lorentz vector
Definition: LeafCandidate.h:99
std::vector< plotEntryType * > plotEntries_