CMS 3D CMS Logo

HLTTauMCProducer.cc
Go to the documentation of this file.
2 
3 using namespace edm;
4 using namespace std;
5 using namespace reco;
6 
8  : MC_{consumes<GenParticleCollection>(mc.getUntrackedParameter<edm::InputTag>("GenParticles"))},
9  MCMET_{consumes<GenMETCollection>(mc.getUntrackedParameter<edm::InputTag>("GenMET"))},
10  ptMinMCTau_{mc.getUntrackedParameter<double>("ptMinTau", 5.)},
11  ptMinMCElectron_{mc.getUntrackedParameter<double>("ptMinElectron", 5.)},
12  ptMinMCMuon_{mc.getUntrackedParameter<double>("ptMinMuon", 2.)},
13  m_PDG_{mc.getUntrackedParameter<std::vector<int>>("BosonID")},
14  etaMin_{mc.getUntrackedParameter<double>("EtaMin", -2.5)},
15  etaMax_{mc.getUntrackedParameter<double>("EtaMax", 2.5)},
16  phiMin_{mc.getUntrackedParameter<double>("PhiMin", -3.15)},
17  phiMax_{mc.getUntrackedParameter<double>("PhiMax", 3.15)} {
18  // One Parameter Set per Collection
19 
20  produces<LorentzVectorCollection>("LeptonicTauLeptons");
21  produces<LorentzVectorCollection>("LeptonicTauElectrons");
22  produces<LorentzVectorCollection>("LeptonicTauMuons");
23  produces<LorentzVectorCollection>("HadronicTauOneProng");
24  produces<LorentzVectorCollection>("HadronicTauThreeProng");
25  produces<LorentzVectorCollection>("HadronicTauOneAndThreeProng");
26  produces<LorentzVectorCollection>("TauOther");
27  produces<LorentzVectorCollection>("Neutrina");
28  produces<LorentzVectorCollection>("MET");
29  produces<std::vector<int>>("Mothers");
30 }
31 
33  // All the code from HLTTauMCInfo is here :-)
34 
35  unique_ptr<LorentzVectorCollection> product_Electrons(new LorentzVectorCollection);
36  unique_ptr<LorentzVectorCollection> product_Muons(new LorentzVectorCollection);
37  unique_ptr<LorentzVectorCollection> product_Leptons(new LorentzVectorCollection);
38  unique_ptr<LorentzVectorCollection> product_OneProng(new LorentzVectorCollection);
39  unique_ptr<LorentzVectorCollection> product_ThreeProng(new LorentzVectorCollection);
40  unique_ptr<LorentzVectorCollection> product_OneAndThreeProng(new LorentzVectorCollection);
41  unique_ptr<LorentzVectorCollection> product_Other(new LorentzVectorCollection);
42  unique_ptr<LorentzVectorCollection> product_Neutrina(new LorentzVectorCollection);
43  unique_ptr<LorentzVectorCollection> product_MET(new LorentzVectorCollection);
44  unique_ptr<std::vector<int>> product_Mothers(new std::vector<int>);
45 
47  iEvent.getByToken(MC_, genParticles);
48 
49  if (!genParticles.isValid())
50  return;
51 
52  // Look for MET
54  iEvent.getByToken(MCMET_, genMet);
55  LorentzVector MET(0., 0., 0., 0.);
56  if (genMet.isValid()) {
57  MET = LorentzVector(genMet->front().px(), genMet->front().py(), 0, genMet->front().pt());
58  }
59  product_MET->push_back(MET);
60 
61  // Look for primary bosons
62  // It is not guaranteed that primary bosons are stored in event history.
63  // Is it really needed when check if taus from the boson is removed?
64  // Kept for backward compatibility
65  for (GenParticleCollection::const_iterator p = genParticles->begin(); p != genParticles->end(); ++p) {
66  // Check the PDG ID
67  bool pdg_ok = false;
68  for (size_t pi = 0; pi < m_PDG_.size(); ++pi) {
69  if (abs((*p).pdgId()) == m_PDG_[pi] && ((*p).isHardProcess() || (*p).status() == 3)) {
70  pdg_ok = true;
71  // cout<<" Bsoson particles: "<< (*p).pdgId()<< " " <<(*p).status() << "
72  // "<< pdg_ok<<endl;
73  break;
74  }
75  }
76 
77  // Check if the boson is one of interest and if there is a valid vertex
78  if (pdg_ok) {
79  product_Mothers->push_back((*p).pdgId());
80 
81  TLorentzVector Boson((*p).px(), (*p).py(), (*p).pz(), (*p).energy());
82  }
83  } // End of search for the bosons
84 
85  // Look for taus
86  GenParticleRefVector allTaus;
87  unsigned index = 0;
88  for (GenParticleCollection::const_iterator p = genParticles->begin(); p != genParticles->end(); ++p, ++index) {
89  const GenParticle &genP = *p;
90  // accept only isPromptDecayed() particles
91  if (!genP.isPromptDecayed())
92  continue;
93  // check if it is tau, i.e. if |pdgId|=15
94  if (std::abs(genP.pdgId()) == 15) {
96  // check if it is the last tau in decay/radiation chain
97  GenParticleRefVector daugTaus;
98  getGenDecayProducts(genRef, daugTaus, 0, 15);
99  if (daugTaus.empty())
100  allTaus.push_back(genRef);
101  }
102  }
103 
104  // Find stable tau decay products and build visible taus
105  for (GenParticleRefVector::const_iterator t = allTaus.begin(); t != allTaus.end(); ++t) {
106  // look for all stable (status=1) decay products
107  GenParticleRefVector decayProducts;
108  getGenDecayProducts(*t, decayProducts, 1);
109 
110  // build visible taus and recognize decay mode
111  if (!decayProducts.empty()) {
112  LorentzVector Visible_Taus(0., 0., 0., 0.);
113  LorentzVector TauDecayProduct(0., 0., 0., 0.);
114  LorentzVector Neutrino(0., 0., 0., 0.);
115 
116  int numElectrons = 0;
117  int numMuons = 0;
118  int numChargedPions = 0;
119  int numNeutralPions = 0;
120  int numPhotons = 0;
121  int numOtherParticles = 0;
122 
123  for (GenParticleRefVector::const_iterator pit = decayProducts.begin(); pit != decayProducts.end(); ++pit) {
124  int pdg_id = abs((*pit)->pdgId());
125  if (pdg_id == 11)
126  numElectrons++;
127  else if (pdg_id == 13)
128  numMuons++;
129  else if (pdg_id == 211 || pdg_id == 321)
130  numChargedPions++; // Count both pi+ and K+
131  else if (pdg_id == 111 || pdg_id == 130 || pdg_id == 310)
132  numNeutralPions++; // Count both pi0 and K0_L/S
133  else if (pdg_id == 12 || pdg_id == 14 || pdg_id == 16) {
134  if (pdg_id == 16) {
135  Neutrino.SetPxPyPzE((*pit)->px(), (*pit)->py(), (*pit)->pz(), (*pit)->energy());
136  }
137  } else if (pdg_id == 22)
138  numPhotons++;
139  else {
140  numOtherParticles++;
141  }
142 
143  if (pdg_id != 12 && pdg_id != 14 && pdg_id != 16) {
144  TauDecayProduct.SetPxPyPzE((*pit)->px(), (*pit)->py(), (*pit)->pz(), (*pit)->energy());
145  Visible_Taus += TauDecayProduct;
146  }
147  // cout<< "This has to be the same: " << (*pit)->pdgId()
148  //<< " "<< (*pit)->status()<< " mother: "<< (*pit)->mother()->pdgId() <<
149  // endl;
150  }
151 
152  int tauDecayMode = kOther;
153 
154  if (numOtherParticles == 0) {
155  if (numElectrons == 1) {
156  //--- tau decays into electrons
157  tauDecayMode = kElectron;
158  } else if (numMuons == 1) {
159  //--- tau decays into muons
160  tauDecayMode = kMuon;
161  } else {
162  //--- hadronic tau decays
163  switch (numChargedPions) {
164  case 1:
165  if (numNeutralPions != 0) {
166  tauDecayMode = kOther;
167  break;
168  }
169  switch (numPhotons) {
170  case 0:
171  tauDecayMode = kOneProng0pi0;
172  break;
173  case 2:
174  tauDecayMode = kOneProng1pi0;
175  break;
176  case 4:
177  tauDecayMode = kOneProng2pi0;
178  break;
179  default:
180  tauDecayMode = kOther;
181  break;
182  }
183  break;
184  case 3:
185  if (numNeutralPions != 0) {
186  tauDecayMode = kOther;
187  break;
188  }
189  switch (numPhotons) {
190  case 0:
191  tauDecayMode = kThreeProng0pi0;
192  break;
193  case 2:
194  tauDecayMode = kThreeProng1pi0;
195  break;
196  default:
197  tauDecayMode = kOther;
198  break;
199  }
200  break;
201  }
202  }
203  }
204 
205  // cout<< "So we have a: " << tauDecayMode <<endl;
206  if (tauDecayMode == kElectron) {
207  if ((Visible_Taus.eta() > etaMin_ && Visible_Taus.eta() < etaMax_ && Visible_Taus.phi() > phiMin_ &&
208  Visible_Taus.phi() < phiMax_) &&
209  (Visible_Taus.pt() > ptMinMCElectron_)) {
210  product_Electrons->push_back(Visible_Taus);
211  product_Leptons->push_back(Visible_Taus);
212  }
213  } else if (tauDecayMode == kMuon) {
214  if ((Visible_Taus.eta() > etaMin_ && Visible_Taus.eta() < etaMax_ && Visible_Taus.phi() > phiMin_ &&
215  Visible_Taus.phi() < phiMax_) &&
216  (Visible_Taus.pt() > ptMinMCMuon_)) {
217  product_Muons->push_back(Visible_Taus);
218  product_Leptons->push_back(Visible_Taus);
219  }
220  } else if (tauDecayMode == kOneProng0pi0 || tauDecayMode == kOneProng1pi0 || tauDecayMode == kOneProng2pi0) {
221  if ((Visible_Taus.eta() > etaMin_ && Visible_Taus.eta() < etaMax_ && Visible_Taus.phi() > phiMin_ &&
222  Visible_Taus.phi() < phiMax_) &&
223  (Visible_Taus.pt() > ptMinMCTau_)) {
224  product_OneProng->push_back(Visible_Taus);
225  product_OneAndThreeProng->push_back(Visible_Taus);
226  product_Neutrina->push_back(Neutrino);
227  }
228  } else if (tauDecayMode == kThreeProng0pi0 || tauDecayMode == kThreeProng1pi0) {
229  if ((Visible_Taus.eta() > etaMin_ && Visible_Taus.eta() < etaMax_ && Visible_Taus.phi() > phiMin_ &&
230  Visible_Taus.phi() < phiMax_) &&
231  (Visible_Taus.pt() > ptMinMCTau_)) {
232  product_ThreeProng->push_back(Visible_Taus);
233  product_OneAndThreeProng->push_back(Visible_Taus);
234  product_Neutrina->push_back(Neutrino);
235  }
236  } else if (tauDecayMode == kOther) {
237  if ((Visible_Taus.eta() > etaMin_ && Visible_Taus.eta() < etaMax_ && Visible_Taus.phi() > phiMin_ &&
238  Visible_Taus.phi() < phiMax_) &&
239  (Visible_Taus.pt() > ptMinMCTau_)) {
240  product_Other->push_back(Visible_Taus);
241  }
242  }
243  }
244  }
245 
246  iEvent.put(std::move(product_Leptons), "LeptonicTauLeptons");
247  iEvent.put(std::move(product_Electrons), "LeptonicTauElectrons");
248  iEvent.put(std::move(product_Muons), "LeptonicTauMuons");
249  iEvent.put(std::move(product_OneProng), "HadronicTauOneProng");
250  iEvent.put(std::move(product_ThreeProng), "HadronicTauThreeProng");
251  iEvent.put(std::move(product_OneAndThreeProng), "HadronicTauOneAndThreeProng");
252  iEvent.put(std::move(product_Other), "TauOther");
253  iEvent.put(std::move(product_Neutrina), "Neutrina");
254  iEvent.put(std::move(product_MET), "MET");
255  iEvent.put(std::move(product_Mothers), "Mothers");
256 }
257 
258 // Helper Function
259 
262  int status,
263  int pdgId) const {
264  const GenParticleRefVector &daughterRefs = mother->daughterRefVector();
265 
266  for (GenParticleRefVector::const_iterator d = daughterRefs.begin(); d != daughterRefs.end(); ++d) {
267  if ((status == 0 || (*d)->status() == status) && (pdgId == 0 || std::abs((*d)->pdgId()) == pdgId)) {
268  products.push_back(*d);
269  } else
271  }
272 }
const double ptMinMCTau_
bool empty() const
Is the RefVector empty.
Definition: RefVector.h:99
const edm::EDGetTokenT< reco::GenMETCollection > MCMET_
ESProducts< std::remove_reference_t< TArgs >... > products(TArgs &&... args)
Definition: ESProducts.h:128
bool isPromptDecayed() const
Definition: GenParticle.h:55
const double phiMin_
const double ptMinMCElectron_
const Double_t pi
int pdgId() const final
PDG identifier.
HLTTauMCProducer(const edm::ParameterSet &)
int iEvent
Definition: GenABIO.cc:224
Definition: MET.h:41
const double ptMinMCMuon_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
math::XYZTLorentzVector LorentzVector
const double etaMin_
void getGenDecayProducts(const reco::GenParticleRef &, reco::GenParticleRefVector &, int status=1, int pdgId=0) const
const double etaMax_
d
Definition: ztail.py:151
std::vector< LorentzVector > LorentzVectorCollection
const edm::EDGetTokenT< reco::GenParticleCollection > MC_
const double phiMax_
const_iterator end() const
Termination of iteration.
Definition: RefVector.h:228
TLorentzVector genMet(const HepMC::GenEvent *all, double etamin=-9999., double etamax=9999.)
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
fixed size matrix
HLT enums.
void push_back(value_type const &ref)
Add a Ref<C, T> to the RefVector.
Definition: RefVector.h:67
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:223
def move(src, dest)
Definition: eostools.py:511
math::PtEtaPhiELorentzVectorF LorentzVector
const std::vector< int > m_PDG_