CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
McSelector.cc
Go to the documentation of this file.
1 /* \class McSelector
2  *
3  * Class to apply analysis cuts in the TriggerValidation Code
4  *
5  * Author: Massimiliano Chiorboli Date: August 2007
6  // Maurizio Pierini
7  // Maria Spiropulu
8  // Philip Hebda, July 2009
9 *
10  */
11 
13 
15 
16 using namespace edm;
17 using namespace reco;
18 using namespace std;
19 
21 {
22  //******************** PLEASE PAY ATTENTION: number of electron and muons is strictly equal, for jets, taus and photons the requirement is >= ********************
23  name = userCut_params.getParameter<string>("name");
24  m_genSrc = iC.consumes<reco::GenParticleCollection>(userCut_params.getParameter<string>("mcparticles"));
25  m_genJetSrc = iC.consumes<reco::GenJetCollection>(userCut_params.getParameter<string>("genJets"));
26  m_genMetSrc = iC.consumes<reco::GenMETCollection>(userCut_params.getParameter<string>("genMet"));
27  mc_ptElecMin = userCut_params.getParameter<double>("mc_ptElecMin" );
28  mc_ptMuonMin = userCut_params.getParameter<double>("mc_ptMuonMin" );
29  mc_ptTauMin = userCut_params.getParameter<double>("mc_ptTauMin" );
30  mc_ptPhotMin = userCut_params.getParameter<double>("mc_ptPhotMin" );
31  mc_ptJetMin = userCut_params.getParameter<double>("mc_ptJetMin" );
32  mc_ptJetForHtMin = userCut_params.getParameter<double>("mc_ptJetForHtMin" );
33  mc_metMin = userCut_params.getParameter<double>("mc_metMin" );
34  mc_htMin = userCut_params.getParameter<double>("mc_htMin" );
35  mc_nElec = userCut_params.getParameter<int>("mc_nElec");
36  mc_nElecRule = userCut_params.getParameter<string>("mc_nElecRule");
37  mc_nMuon = userCut_params.getParameter<int>("mc_nMuon");
38  mc_nMuonRule = userCut_params.getParameter<string>("mc_nMuonRule");
39  mc_nTau = userCut_params.getParameter<int>("mc_nTau");
40  mc_nPhot = userCut_params.getParameter<int>("mc_nPhot");
41  mc_nJet = userCut_params.getParameter<int>("mc_nJet" );
42 
43 
44  edm::LogInfo("HLTriggerOfflineSUSYBSM") << "UserAnalysis parameters, MC for " << name << " selection:" ;
45  edm::LogInfo("HLTriggerOfflineSUSYBSM") << " mc_ptElecMin = " << mc_ptElecMin ;
46  edm::LogInfo("HLTriggerOfflineSUSYBSM") << " mc_ptMuonMin = " << mc_ptMuonMin ;
47  edm::LogInfo("HLTriggerOfflineSUSYBSM") << " mc_ptTauMin = " << mc_ptTauMin ;
48  edm::LogInfo("HLTriggerOfflineSUSYBSM") << " mc_ptPhotMin = " << mc_ptPhotMin ;
49  edm::LogInfo("HLTriggerOfflineSUSYBSM") << " mc_ptJetMin = " << mc_ptJetMin ;
50  edm::LogInfo("HLTriggerOfflineSUSYBSM") << " mc_ptJetForHtMin = " << mc_ptJetForHtMin ;
51  edm::LogInfo("HLTriggerOfflineSUSYBSM") << " mc_metMin = " << mc_metMin ;
52  edm::LogInfo("HLTriggerOfflineSUSYBSM") << " mc_htMin = " << mc_htMin ;
53 
54  edm::LogInfo("HLTriggerOfflineSUSYBSM") << " mc_nElec = " << mc_nElec ;
55  edm::LogInfo("HLTriggerOfflineSUSYBSM") << " mc_nElecRule = " << mc_nElecRule ;
56  edm::LogInfo("HLTriggerOfflineSUSYBSM") << " mc_nMuon = " << mc_nMuon ;
57  edm::LogInfo("HLTriggerOfflineSUSYBSM") << " mc_nMuonRule = " << mc_nMuonRule ;
58  edm::LogInfo("HLTriggerOfflineSUSYBSM") << " mc_nTau = " << mc_nTau ;
59  edm::LogInfo("HLTriggerOfflineSUSYBSM") << " mc_nPhot = " << mc_nPhot ;
60  edm::LogInfo("HLTriggerOfflineSUSYBSM") << " mc_nJet = " << mc_nJet ;
61 
62 
63 }
64 
65 string McSelector::GetName(){return name;}
66 
68 {
69 
70 
71  this->handleObjects(iEvent);
72 
73 
74  bool TotalCutPassed = false;
75 
76 
77  bool ElectronCutPassed = false;
78  bool MuonCutPassed = false;
79  bool TauCutPassed = false;
80  bool PhotonCutPassed = false;
81  bool JetCutPassed = false;
82  bool MetCutPassed = false;
83  bool HtCutPassed = false;
84 
85  int nMcElectrons = 0;
86  int nMcMuons = 0;
87  int nMcTaus = 0;
88  int nMcPhotons = 0;
89  int nMcJets = 0;
90 
91  // cout <<"----------------------------------------------------------------------------" << endl;
92 
93  for(unsigned int i=0; i<theGenParticleCollection->size(); i++) {
94  const GenParticle* genParticle = (&(*theGenParticleCollection)[i]);
95  if(genParticle->status() == 2) {
96  //taus
97  if(fabs(genParticle->pdgId()) == 15) {
98  // cout << "Tau Mother = " << genParticle->mother()->pdgId() << endl;
99  // if(fabs(genParticle->mother()->pdgId()) == 15) cout << "Tau GrandMother = " << genParticle->mother()->mother()->pdgId() << endl;
100  if(genParticle->pt() > mc_ptTauMin && fabs(genParticle->eta())<2.5) {
101  nMcTaus++;
102  }
103  }
104  }
105  if(genParticle->status() == 1) {
106  // cout << "genParticle->status() = " << genParticle->status() << " genParticle->pdgId() = " << genParticle->pdgId() << " genParticle->pt() = " << genParticle->pt() << endl;
107  //electrons
108  if(fabs(genParticle->pdgId()) == 11 && genParticle->numberOfMothers()) {
109  // cout << "Mc Electron, pt = " << genParticle->pt() << endl;
110  // cout << "Electron Mother = " << genParticle->mother()->pdgId() << endl;
111 // if(fabs(genParticle->mother()->pdgId()) == 11 || fabs(genParticle->mother()->pdgId()) == 15)
112 // cout << "Electron GrandMother = " << genParticle->mother()->mother()->pdgId() << endl;
113 // if(fabs(genParticle->mother()->mother()->pdgId()) == 11 || fabs(genParticle->mother()->mother()->pdgId()) == 15)
114 // cout << "Electron GrandGrandMother = " << genParticle->mother()->mother()->mother()->pdgId() << endl;
115  int motherCode = genParticle->mother()->pdgId();
116  if(fabs(motherCode) == fabs(genParticle->pdgId()) || fabs(motherCode) == 15) {
117  motherCode = genParticle->mother()->mother()->pdgId();
118  if(fabs(motherCode) == fabs(genParticle->pdgId()) || fabs(motherCode) == 15) motherCode = genParticle->mother()->mother()->mother()->pdgId();
119  }
120  if(fabs(motherCode) == 23 || fabs(motherCode) == 24 || fabs(motherCode) > 999999) {
121  if(genParticle->pt() > mc_ptElecMin && fabs(genParticle->eta())<2.5) {
122  nMcElectrons++;
123  // cout << "Mc Electron, pt = " << genParticle->pt() << endl;
124  }
125  }
126  }
127  //muons
128  if(fabs(genParticle->pdgId()) == 13 && genParticle->numberOfMothers()) {
129  // cout << "Mc Muon, pt = " << genParticle->pt() << endl;
130  // cout << "Muon Mother = " << genParticle->mother()->pdgId() << endl;
131 // if(fabs(genParticle->mother()->pdgId()) == 13 || fabs(genParticle->mother()->pdgId()) == 15)
132 // cout << "Muon GrandMother = " << genParticle->mother()->mother()->pdgId() << endl;
133 // if(fabs(genParticle->mother()->mother()->pdgId()) == 13 || fabs(genParticle->mother()->mother()->pdgId()) == 15)
134 // cout << "Muon GrandGrandMother = " << genParticle->mother()->mother()->mother()->pdgId() << endl;
135  int motherCode = genParticle->mother()->pdgId();
136  if(fabs(motherCode) == fabs(genParticle->pdgId()) || fabs(motherCode) == 15) {
137  motherCode = genParticle->mother()->mother()->pdgId();
138  if(fabs(motherCode) == fabs(genParticle->pdgId()) || fabs(motherCode) == 15) motherCode = genParticle->mother()->mother()->mother()->pdgId();
139  }
140  if(fabs(motherCode) == 23 || fabs(motherCode) == 24 || fabs(motherCode) > 999999) {
141  if(genParticle->pt() > mc_ptMuonMin && fabs(genParticle->eta())<2.5) {
142  nMcMuons++;
143  // cout << "Mc Muon, pt = " << genParticle->pt() << endl;
144  }
145  }
146  }
147  //photons
148  if(fabs(genParticle->pdgId()) == 22 && fabs(genParticle->eta())<2.5) {
149  // cout << "Mc Photon, pt = " << genParticle->pt() << endl;
150  if(genParticle->pt() > mc_ptPhotMin) {
151  // cout << "Photon Mother = " << genParticle->mother()->pdgId() << endl;
152  nMcPhotons++;
153  // cout << "Mc Photon, pt = " << genParticle->pt() << endl;
154  }
155  }
156  }
157  }
158 
159  ht = 0;
160  for(unsigned int i=0; i<theGenJetCollection->size();i++) {
161  GenJet genjet = (*theGenJetCollection)[i];
162  // cout << "Mc Jet, pt = " << genjet.pt() << endl;
163  if(genjet.pt() > mc_ptJetMin && fabs(genjet.eta())<3) {
164  nMcJets++;
165  // cout << "Mc Jet, pt = " << genjet.pt() << endl;
166  }
167  if(genjet.pt() > mc_ptJetForHtMin) ht =+ genjet.pt();
168  }
169  if(ht>mc_htMin) HtCutPassed = true;
170 
171 
172  const GenMET theGenMET = theGenMETCollection->front();
173  // cout << "GenMET = " << theGenMET.pt() << endl;
174  if(theGenMET.pt() > mc_metMin) MetCutPassed = true;
175 
176  // cout <<"----------------------------------------------------------------------------" << endl;
177 
178 
179 // cout << "nMcElectrons = " << nMcElectrons << endl;
180 // cout << "nMcMuons = " << nMcMuons << endl;
181 // cout << "nMcTaus = " << nMcTaus << endl;
182 // cout << "nMcPhotons = " << nMcPhotons << endl;
183 // cout << "nMcJets = " << nMcJets << endl;
184 
185  if(mc_nElecRule == "strictEqual") {
186  if(nMcElectrons == mc_nElec) ElectronCutPassed = true;
187  }
188  else if (mc_nElecRule == "greaterEqual") {
189  if(nMcElectrons >= mc_nElec) ElectronCutPassed = true;
190  }
191  else cout << "WARNING: not a correct definition of cuts at gen level for electrons! " << endl;
192 
193 
194  if(mc_nMuonRule == "strictEqual") {
195  if(nMcMuons == mc_nMuon) MuonCutPassed = true;
196  }
197  else if (mc_nMuonRule == "greaterEqual") {
198  if(nMcMuons >= mc_nMuon) MuonCutPassed = true;
199  }
200  else cout << "WARNING: not a correct definition of cuts at gen level for muons! " << endl;
201  if(nMcTaus >= mc_nTau) TauCutPassed = true;
202  if(nMcPhotons >= mc_nPhot) PhotonCutPassed = true;
203  if(nMcJets >= mc_nJet ) JetCutPassed = true;
204 
205 
206 // cout << "ElectronCutPassed = " << (int)ElectronCutPassed << endl;
207 // cout << "MuonCutPassed = " << (int)MuonCutPassed << endl;
208 // cout << "PhotonCutPassed = " << (int)PhotonCutPassed << endl;
209 // cout << "JetCutPassed = " << (int)JetCutPassed << endl;
210 // cout << "MetCutPassed = " << (int)MetCutPassed << endl;
211 
212 
213 // if(
214 // (ElectronCutPassed || MuonCutPassed) &&
215 // PhotonCutPassed &&
216 // JetCutPassed &&
217 // MetCutPassed ) TotalCutPassed = true;
218 
219 
220  if(
221  ElectronCutPassed &&
222  MuonCutPassed &&
223  TauCutPassed &&
224  PhotonCutPassed &&
225  JetCutPassed &&
226  MetCutPassed &&
227  HtCutPassed ) TotalCutPassed = true;
228 
229 
230  // Apply a veto: removed because we require the exact number of leptons
231  // and not >=
232  // the veto is hence equivalent to request 0 leptons
233 
234 // if(TotalCutPassed) {
235 // if(mc_ElecVeto) {
236 // if(nMcElectrons>0) TotalCutPassed = false;
237 // }
238 // if(mc_MuonVeto) {
239 // if(nMcMuons>0) TotalCutPassed = false;
240 // }
241 // }
242 
243 
244 // cout << "TotalCutPassed = " << TotalCutPassed << endl;
245 
246  return TotalCutPassed;
247 }
248 
250 {
251 
252  //Get the GenParticleCandidates
253  Handle< reco::GenParticleCollection > theCandidateCollectionHandle;
254  iEvent.getByToken(m_genSrc, theCandidateCollectionHandle);
255  theGenParticleCollection = theCandidateCollectionHandle.product();
256 
257 
258  //Get the GenJets
259  Handle< GenJetCollection > theGenJetCollectionHandle ;
260  iEvent.getByToken( m_genJetSrc, theGenJetCollectionHandle);
261  theGenJetCollection = theGenJetCollectionHandle.product();
262 
263 
264  //Get the GenMET
265  Handle< GenMETCollection > theGenMETCollectionHandle;
266  iEvent.getByToken( m_genMetSrc, theGenMETCollectionHandle);
267  theGenMETCollection = theGenMETCollectionHandle.product();
268 
269 
270 }
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
tuple mc_nElecRule
virtual const Candidate * mother(size_type i=0) const =0
return pointer to mother
tuple mc_ptPhotMin
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
std::vector< reco::GenMET > GenMETCollection
collection of GenMET objects
virtual int pdgId() const GCC11_FINAL
PDG identifier.
std::vector< GenJet > GenJetCollection
collection of GenJet objects
tuple mc_ptJetMin
Definition: mcSel_RA1_cff.py:9
void handleObjects(const edm::Event &)
Definition: McSelector.cc:249
tuple mc_ptMuonMin
bool isSelected(const edm::Event &)
Definition: McSelector.cc:67
int iEvent
Definition: GenABIO.cc:230
virtual int status() const GCC11_FINAL
status word
virtual size_t numberOfMothers() const
number of mothers
McSelector(const edm::ParameterSet &userCut_params, edm::ConsumesCollector &&iC)
Definition: McSelector.cc:20
tuple mc_ptElecMin
tuple mc_ptJetForHtMin
Definition: mcSel_RA1_cff.py:5
Jets made from MC generator particles.
Definition: GenJet.h:24
virtual float eta() const GCC11_FINAL
momentum pseudorapidity
virtual int pdgId() const =0
PDG identifier.
tuple mc_nMuonRule
std::string GetName()
Definition: McSelector.cc:65
T const * product() const
Definition: Handle.h:81
tuple cout
Definition: gather_cfg.py:121
virtual float pt() const GCC11_FINAL
transverse momentum
virtual const Candidate * mother(size_type=0) const
return mother at a given position, i = 0, ... numberOfMothers() - 1 (read only mode) ...