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