CMS 3D CMS Logo

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