CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TruthTauDecayModeProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: TruthTauDecayModeProducer
4 // Class: TruthTauDecayModeProducer
5 //
15 //
16 // Original Author: Evan K. Friis, UC Davis (friis@physics.ucdavis.edu)
17 // Created: Thu Sep 1 06:19:05 PST 2008
18 // $Id: TruthTauDecayModeProducer.cc,v 1.6 2010/10/19 20:22:27 wmtan Exp $
19 //
20 //
21 
22 
23 // system include files
24 #include <memory>
25 
26 // user include files
29 
39 
40 #include <vector>
41 
43 
45  public:
47  std::vector<const reco::Candidate*> chargedObjects;
48  std::vector<const reco::Candidate*> neutralObjects;
49  };
52 
53  private:
54  virtual void beginJob() ;
55  virtual void produce(edm::Event&, const edm::EventSetup&);
56  virtual void endJob() ;
57 
58  //for signal, the module takes input from a PdgIdAndStatusCandViewSelector
59  //for background, the module takes input from a collection of GenJets
60  bool iAmSignal_;
64  double totalPtCut_;
65  double totalEtaCut_;
67 };
68 
70 {
71  edm::LogInfo("TruthTauDecayModeProducer") << "Initializing ctor of TruthTauDecayModeProducer";
72  iAmSignal_ = iConfig.getParameter<bool>("iAmSignal");
73  inputTag_ = iConfig.getParameter<edm::InputTag>("inputTag");
74  leadTrackPtCut_ = iConfig.getParameter<double>("leadTrackPtCut");
75  leadTrackEtaCut_ = iConfig.getParameter<double>("leadTrackEtaCut");
76  totalPtCut_ = iConfig.getParameter<double>("totalPtCut");
77  totalEtaCut_ = iConfig.getParameter<double>("totalEtaCut");
78  //register your products
79  edm::LogInfo("TruthTauDecayModeProducer") << "Registering products";
80  produces<std::vector<reco::PFTauDecayMode> >();
81  edm::LogInfo("TruthTauDecayModeProducer") << "TruthTauDecayModeProducer initialized";
82 }
83 
84 
86 {
87 }
88 
89 void
91 {
92  using namespace edm;
93  using namespace std;
94  using namespace reco;
95 
96  std::vector<tauObjectsHolder> tausToAdd_;
97 
98  /* **********************************************
99  * ********** True Tau Case ***********
100  * ********************************************** */
101  if (iAmSignal_)
102  {
104  iEvent.getByLabel(inputTag_, decayedMCTaus);
105  for(edm::RefToBaseVector<reco::Candidate>::const_iterator iterGen = decayedMCTaus->begin();
106  iterGen != decayedMCTaus->end();
107  ++iterGen)
108  {
109  //copy into custom format (this casting is bullshit)
110  GeneratorTau tempTau = static_cast<const GenParticle&>(*(*iterGen));
111  //LogInfo("MCTauCandidateProducer") << "Generator tau produced, initializing.. ";
112  tempTau.init();
113  //LogInfo("MCTauCandidateProducer") << "GenTau initialization done";
114  if (tempTau.isFinalStateTau())
115  {
116  // Build a Tau Candidate from the information contained in the parsing class
117  tauObjectsHolder tempTauHolder;
118  tempTauHolder.chargedObjects = tempTau.getGenChargedPions();
119  tempTauHolder.neutralObjects = tempTau.getGenNeutralPions();
120  tausToAdd_.push_back(tempTauHolder);
121  }
122  }
123  } else
124  {
125  /* **********************************************
126  * ********** QCD Case ***********
127  * ********************************************** */
129  iEvent.getByLabel(inputTag_, genJets);
130  for(GenJetCollection::const_iterator aGenJet = genJets->begin(); aGenJet != genJets->end(); ++aGenJet)
131  {
132  // get all constituents
133  std::vector<const GenParticle*> theJetConstituents = aGenJet->getGenConstituents();
134 
135  tauObjectsHolder tempTauHolder;
136  // filter the constituents
137  for( std::vector<const GenParticle*>::const_iterator aCandidate = theJetConstituents.begin();
138  aCandidate != theJetConstituents.end();
139  ++aCandidate)
140  {
141  int pdgId = std::abs((*aCandidate)->pdgId());
142  const Candidate* theCandidate = static_cast<const Candidate*>(*aCandidate);
143  //filter nus
144  if (pdgId == 16 || pdgId == 12 || pdgId == 14)
145  {
146  //do nothing
147  } else
148  {
149  // call everything charged a pion
150  // call everything neutral a neutral pion
151  if (theCandidate->charge() != 0)
152  tempTauHolder.chargedObjects.push_back(theCandidate);
153  else
154  tempTauHolder.neutralObjects.push_back(theCandidate);
155  }
156  }
157  tausToAdd_.push_back(tempTauHolder);
158  }
159  }
160 
161  //output collection
162  std::auto_ptr<vector<PFTauDecayMode> > pOut( new std::vector<PFTauDecayMode> );
163  for(std::vector<tauObjectsHolder>::const_iterator iTempTau = tausToAdd_.begin();
164  iTempTau != tausToAdd_.end();
165  ++iTempTau)
166  {
167  double leadTrackPt = 0.;
168  double leadTrackEta = 0.;
169  VertexCompositeCandidate chargedObjectsToAdd;
170  const std::vector<const Candidate*>* chargedObjects = &(iTempTau->chargedObjects);
171  for(std::vector<const Candidate*>::const_iterator iCharged = chargedObjects->begin();
172  iCharged != chargedObjects->end();
173  ++iCharged)
174  {
175  chargedObjectsToAdd.addDaughter(**iCharged);
176  double trackPt = (*iCharged)->pt();
177  if (trackPt > leadTrackPt)
178  {
179  leadTrackPt = trackPt;
180  leadTrackEta = (*iCharged)->eta();
181  }
182  }
183  //update the composite four vector
184  addP4.set(chargedObjectsToAdd);
185 
186  CompositeCandidate neutralPionsToAdd;
187  const std::vector<const Candidate*>* neutralObjects = &(iTempTau->neutralObjects);
188  for(std::vector<const Candidate*>::const_iterator iNeutral = neutralObjects->begin();
189  iNeutral != neutralObjects->end();
190  ++iNeutral)
191  {
192  neutralPionsToAdd.addDaughter(**iNeutral);
193  }
194  addP4.set(neutralPionsToAdd);
195 
196  Particle::LorentzVector myFourVector = chargedObjectsToAdd.p4();
197  myFourVector += neutralPionsToAdd.p4();
198 
199  if(leadTrackPt > leadTrackPtCut_ && std::abs(leadTrackEta) < leadTrackEtaCut_ && myFourVector.pt() > totalPtCut_ && std::abs(myFourVector.eta()) < totalEtaCut_)
200  {
201  //TODO: add vertex fitting
202  CompositeCandidate theOutliers;
203  PFTauRef noPFTau; //empty REF to PFTau
204  PFTauDecayMode decayModeToAdd(chargedObjectsToAdd, neutralPionsToAdd, theOutliers);
205  decayModeToAdd.setPFTauRef(noPFTau);
206  pOut->push_back(decayModeToAdd);
207  }
208  }
209  iEvent.put(pOut);
210 }
211 
212 void
214 {
215 }
216 
217 // ------------ method called once each job just after ending the event loop ------------
218 void
220 }
221 
222 //define this as a plug-in
std::vector< const reco::Candidate * > neutralObjects
T getParameter(std::string const &) const
virtual const LorentzVector & p4() const GCC11_FINAL
four-momentum Lorentz vector
tuple trackPt
Definition: listHistos.py:120
virtual void produce(edm::Event &, const edm::EventSetup &)
void setPFTauRef(const PFTauRef &theTau)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
bool isFinalStateTau() const
Definition: GeneratorTau.h:51
TruthTauDecayModeProducer(const edm::ParameterSet &)
#define abs(x)
Definition: mlp_lapack.h:159
int iEvent
Definition: GenABIO.cc:243
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:94
std::vector< const reco::Candidate * > chargedObjects
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
void addDaughter(const Candidate &, const std::string &s="")
add a clone of the passed candidate as daughter
std::vector< const reco::Candidate * > getGenNeutralPions() const
std::vector< const reco::Candidate * > getGenChargedPions() const
void set(reco::Candidate &c) const
set up a candidate
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:25