test
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 //
19 //
20 
21 
22 // system include files
23 #include <memory>
24 
25 // user include files
28 
38 
39 #include <vector>
40 
42 
44  public:
46  std::vector<const reco::Candidate*> chargedObjects;
47  std::vector<const reco::Candidate*> neutralObjects;
48  };
51 
52  private:
53  virtual void beginJob() override ;
54  virtual void produce(edm::Event&, const edm::EventSetup&) override;
55  virtual void endJob() override ;
56 
57  //for signal, the module takes input from a PdgIdAndStatusCandViewSelector
58  //for background, the module takes input from a collection of GenJets
59  bool iAmSignal_;
63  double totalPtCut_;
64  double totalEtaCut_;
66 };
67 
69 {
70  edm::LogInfo("TruthTauDecayModeProducer") << "Initializing ctor of TruthTauDecayModeProducer";
71  iAmSignal_ = iConfig.getParameter<bool>("iAmSignal");
72  inputTag_ = iConfig.getParameter<edm::InputTag>("inputTag");
73  leadTrackPtCut_ = iConfig.getParameter<double>("leadTrackPtCut");
74  leadTrackEtaCut_ = iConfig.getParameter<double>("leadTrackEtaCut");
75  totalPtCut_ = iConfig.getParameter<double>("totalPtCut");
76  totalEtaCut_ = iConfig.getParameter<double>("totalEtaCut");
77  //register your products
78  edm::LogInfo("TruthTauDecayModeProducer") << "Registering products";
79  produces<std::vector<reco::PFTauDecayMode> >();
80  edm::LogInfo("TruthTauDecayModeProducer") << "TruthTauDecayModeProducer initialized";
81 }
82 
83 
85 {
86 }
87 
88 void
90 {
91  using namespace edm;
92  using namespace std;
93  using namespace reco;
94 
95  std::vector<tauObjectsHolder> tausToAdd_;
96 
97  /* **********************************************
98  * ********** True Tau Case ***********
99  * ********************************************** */
100  if (iAmSignal_)
101  {
103  iEvent.getByLabel(inputTag_, decayedMCTaus);
104  for(edm::RefToBaseVector<reco::Candidate>::const_iterator iterGen = decayedMCTaus->begin();
105  iterGen != decayedMCTaus->end();
106  ++iterGen)
107  {
108  //copy into custom format (this casting is bullshit)
109  GeneratorTau tempTau = static_cast<const GenParticle&>(*(*iterGen));
110  //LogInfo("MCTauCandidateProducer") << "Generator tau produced, initializing.. ";
111  tempTau.init();
112  //LogInfo("MCTauCandidateProducer") << "GenTau initialization done";
113  if (tempTau.isFinalStateTau())
114  {
115  // Build a Tau Candidate from the information contained in the parsing class
116  tauObjectsHolder tempTauHolder;
117  tempTauHolder.chargedObjects = tempTau.getGenChargedPions();
118  tempTauHolder.neutralObjects = tempTau.getGenNeutralPions();
119  tausToAdd_.push_back(tempTauHolder);
120  }
121  }
122  } else
123  {
124  /* **********************************************
125  * ********** QCD Case ***********
126  * ********************************************** */
128  iEvent.getByLabel(inputTag_, genJets);
129  for(GenJetCollection::const_iterator aGenJet = genJets->begin(); aGenJet != genJets->end(); ++aGenJet)
130  {
131  // get all constituents
132  std::vector<const GenParticle*> theJetConstituents = aGenJet->getGenConstituents();
133 
134  tauObjectsHolder tempTauHolder;
135  // filter the constituents
136  for( std::vector<const GenParticle*>::const_iterator aCandidate = theJetConstituents.begin();
137  aCandidate != theJetConstituents.end();
138  ++aCandidate)
139  {
140  int pdgId = std::abs((*aCandidate)->pdgId());
141  const Candidate* theCandidate = static_cast<const Candidate*>(*aCandidate);
142  //filter nus
143  if (pdgId == 16 || pdgId == 12 || pdgId == 14)
144  {
145  //do nothing
146  } else
147  {
148  // call everything charged a pion
149  // call everything neutral a neutral pion
150  if (theCandidate->charge() != 0)
151  tempTauHolder.chargedObjects.push_back(theCandidate);
152  else
153  tempTauHolder.neutralObjects.push_back(theCandidate);
154  }
155  }
156  tausToAdd_.push_back(tempTauHolder);
157  }
158  }
159 
160  //output collection
161  std::auto_ptr<vector<PFTauDecayMode> > pOut( new std::vector<PFTauDecayMode> );
162  for(std::vector<tauObjectsHolder>::const_iterator iTempTau = tausToAdd_.begin();
163  iTempTau != tausToAdd_.end();
164  ++iTempTau)
165  {
166  double leadTrackPt = 0.;
167  double leadTrackEta = 0.;
168  VertexCompositeCandidate chargedObjectsToAdd;
169  const std::vector<const Candidate*>* chargedObjects = &(iTempTau->chargedObjects);
170  for(std::vector<const Candidate*>::const_iterator iCharged = chargedObjects->begin();
171  iCharged != chargedObjects->end();
172  ++iCharged)
173  {
174  chargedObjectsToAdd.addDaughter(**iCharged);
175  double trackPt = (*iCharged)->pt();
176  if (trackPt > leadTrackPt)
177  {
178  leadTrackPt = trackPt;
179  leadTrackEta = (*iCharged)->eta();
180  }
181  }
182  //update the composite four vector
183  addP4.set(chargedObjectsToAdd);
184 
185  CompositeCandidate neutralPionsToAdd;
186  const std::vector<const Candidate*>* neutralObjects = &(iTempTau->neutralObjects);
187  for(std::vector<const Candidate*>::const_iterator iNeutral = neutralObjects->begin();
188  iNeutral != neutralObjects->end();
189  ++iNeutral)
190  {
191  neutralPionsToAdd.addDaughter(**iNeutral);
192  }
193  addP4.set(neutralPionsToAdd);
194 
195  Particle::LorentzVector myFourVector = chargedObjectsToAdd.p4();
196  myFourVector += neutralPionsToAdd.p4();
197 
198  if(leadTrackPt > leadTrackPtCut_ && std::abs(leadTrackEta) < leadTrackEtaCut_ && myFourVector.pt() > totalPtCut_ && std::abs(myFourVector.eta()) < totalEtaCut_)
199  {
200  //TODO: add vertex fitting
201  CompositeCandidate theOutliers;
202  PFTauRef noPFTau; //empty REF to PFTau
203  PFTauDecayMode decayModeToAdd(chargedObjectsToAdd, neutralPionsToAdd, theOutliers);
204  decayModeToAdd.setPFTauRef(noPFTau);
205  pOut->push_back(decayModeToAdd);
206  }
207  }
208  iEvent.put(pOut);
209 }
210 
211 void
213 {
214 }
215 
216 // ------------ method called once each job just after ending the event loop ------------
217 void
219 }
220 
221 //define this as a plug-in
std::vector< const reco::Candidate * > neutralObjects
T getParameter(std::string const &) const
virtual void produce(edm::Event &, const edm::EventSetup &) override
tuple trackPt
Definition: listHistos.py:120
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 &)
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
std::vector< const reco::Candidate * > chargedObjects
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:418
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
virtual const LorentzVector & p4() const final
four-momentum Lorentz vector
Definition: LeafCandidate.h:99
math::PtEtaPhiELorentzVectorF LorentzVector