CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TauGenJetProducer.cc
Go to the documentation of this file.
2 
4 
8 
12 
14 
15 using namespace std;
16 using namespace edm;
17 using namespace reco;
18 
20 {
21  inputTagGenParticles_
22  = iConfig.getParameter<InputTag>("GenParticles");
23  tokenGenParticles_
24  = consumes<GenParticleCollection>(inputTagGenParticles_);
25 
26  includeNeutrinos_
27  = iConfig.getParameter<bool>("includeNeutrinos");
28 
29  verbose_ =
30  iConfig.getUntrackedParameter<bool>("verbose",false);
31 
32  produces<GenJetCollection>();
33 }
34 
36 
38  const EventSetup& iSetup) {
39 
41 
42  bool found = iEvent.getByToken( tokenGenParticles_, genParticles);
43 
44  if ( !found ) {
45  std::ostringstream err;
46  err<<" cannot get collection: "
47  <<inputTagGenParticles_<<std::endl;
48  edm::LogError("TauGenJetProducer")<<err.str();
49  throw cms::Exception( "MissingProduct", err.str());
50  }
51 
52  std::auto_ptr<GenJetCollection>
53  pOutVisTaus(new GenJetCollection());
54 
55  using namespace GenParticlesHelper;
56 
57  GenParticleRefVector allStatus2Taus;
58  findParticles( *genParticles,
59  allStatus2Taus, 15, 2);
60 
61  for ( IGR iTau=allStatus2Taus.begin(); iTau!=allStatus2Taus.end(); ++iTau ) {
62 
63  // look for all status 1 (stable) descendents
64  GenParticleRefVector descendents;
65  findDescendents( *iTau, descendents, 1);
66 
67  // CV: skip status 2 taus that radiate-off a photon
68  // --> have a status 2 tau lepton in the list of descendents
69  GenParticleRefVector status2TauDaughters;
70  findDescendents( *iTau, status2TauDaughters, 2, 15 );
71  if ( status2TauDaughters.size() > 0 ) continue;
72 
73  // loop on descendents, and take all except neutrinos
74  math::XYZTLorentzVector sumVisMom;
75  Particle::Charge charge = 0;
76  Jet::Constituents constituents;
77 
78  if(verbose_)
79  cout<<"tau "<<(*iTau)<<endl;
80 
81  for(IGR igr = descendents.begin();
82  igr!= descendents.end(); ++igr ) {
83 
84  int absPdgId = abs((*igr)->pdgId());
85 
86  // neutrinos
87  if(!includeNeutrinos_ ) {
88  if( absPdgId == 12 ||
89  absPdgId == 14 ||
90  absPdgId == 16 )
91  continue;
92  }
93 
94  if(verbose_)
95  cout<<"\t"<<(*igr)<<endl;
96 
97  charge += (*igr)->charge();
98  sumVisMom += (*igr)->p4();
99 
100  // need to convert the vector of reference to the constituents
101  // to a vector of pointers to build the genjet
102  constituents.push_back( refToPtr( *igr) );
103  }
104 
105  math::XYZPoint vertex;
107 
108  GenJet jet( sumVisMom, vertex, specific, constituents);
109 
110  if (charge != (*iTau)->charge() )
111  std::cout<<" charge of Tau: " << (*iTau) << " not equal to charge of sum of charge of all descendents. " << std::cout;
112 
113  jet.setCharge(charge);
114  pOutVisTaus->push_back( jet );
115 
116  }
117  iEvent.put( pOutVisTaus );
118 }
119 
120 
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
dictionary specific
Ptr< typename C::value_type > refToPtr(Ref< C, typename C::value_type, refhelper::FindUsingAdvance< C, typename C::value_type > > const &ref)
Definition: RefToPtr.h:18
void findParticles(const reco::GenParticleCollection &sourceParticles, reco::GenParticleRefVector &particleRefs, int pdgId, int status)
find all particles of a given pdgId and status
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:446
virtual void setCharge(Charge q)
set electric charge
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< GenJet > GenJetCollection
collection of GenJet objects
const_iterator end() const
Termination of iteration.
Definition: RefVector.h:249
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:244
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
virtual void produce(edm::Event &, const edm::EventSetup &) override
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Jets made from MC generator particles.
Definition: GenJet.h:24
builds a GenJet from the visible daughters of each status 2 tau in the event.
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
size_type size() const
Size of the RefVector.
Definition: RefVector.h:89
TauGenJetProducer(const edm::ParameterSet &)
tuple cout
Definition: gather_cfg.py:121
void findDescendents(const reco::GenParticleRef &base, reco::GenParticleRefVector &descendents, int status, int pdgId=0)
find all descendents of a given status and pdgId (recursive)