CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SubEventGenJetProducer.cc
Go to the documentation of this file.
1 
8 
9 using namespace std;
10 using namespace reco;
11 using namespace edm;
12 using namespace cms;
13 
14 namespace {
15  const bool debug = false;
16 
17 }
18 
19 namespace {
20  bool checkHydro(const reco::GenParticle * p){
21  const Candidate* m1 = p->mother();
22  while(m1){
23  int pdg = abs(m1->pdgId());
24  int st = m1->status();
25  LogDebug("SubEventMothers")<<"Pdg ID : "<<pdg<<endl;
26  if(st == 3 || pdg < 9 || pdg == 21){
27  LogDebug("SubEventMothers")<<"Sub-Collision Found! Pdg ID : "<<pdg<<endl;
28  return false;
29  }
30  const Candidate* m = m1->mother();
31  m1 = m;
32  if(!m1) LogDebug("SubEventMothers")<<"No Mother, particle is : "<<pdg<<" with status "<<st<<endl;
33  }
34  // return true;
35  return true; // Debugging - to be changed
36  }
37 }
38 
39 SubEventGenJetProducer::SubEventGenJetProducer(edm::ParameterSet const& conf):
40  VirtualJetProducer( conf )
41 {
42  // mapSrc_ = conf.getParameter<edm::InputTag>( "srcMap");
43  ignoreHydro_ = conf.getUntrackedParameter<bool>("ignoreHydro", true);
44  produces<reco::BasicJetCollection>();
45  // the subjet collections are set through the config file in the "jetCollInstanceName" field.
46 }
47 
48 
50 {
51  std::vector<edm::Ptr<reco::Candidate> >::const_iterator inBegin = inputs_.begin(),
52  inEnd = inputs_.end(), i = inBegin;
53  for (; i != inEnd; ++i ) {
54  reco::CandidatePtr input = inputs_[i - inBegin];
55  if (edm::isNotFinite(input->pt())) continue;
56  if (input->et() <inputEtMin_) continue;
57  if (input->energy()<inputEMin_) continue;
58  if (isAnomalousTower(input)) continue;
59 
60  edm::Ptr<reco::Candidate> p = inputs_[i - inBegin];
61  const GenParticle * pref = dynamic_cast<const GenParticle *>(p.get());
62  int subevent = pref->collisionId();
63  LogDebug("SubEventContainers")<<"SubEvent is : "<<subevent<<endl;
64  LogDebug("SubEventContainers")<<"SubSize is : "<<subInputs_.size()<<endl;
65 
66  if(subevent >= (int)subInputs_.size()){
67  hydroTag_.resize(subevent+1, -1);
68  subInputs_.resize(subevent+1);
69  LogDebug("SubEventContainers")<<"SubSize is : "<<subInputs_.size()<<endl;
70  LogDebug("SubEventContainers")<<"HydroTagSize is : "<<hydroTag_.size()<<endl;
71  }
72 
73  LogDebug("SubEventContainers")<<"HydroTag is : "<<hydroTag_[subevent]<<endl;
74  if(hydroTag_[subevent] != 0) hydroTag_[subevent] = (int)checkHydro(pref);
75 
76  subInputs_[subevent].push_back(fastjet::PseudoJet(input->px(),input->py(),input->pz(),
77  input->energy()));
78 
79  subInputs_[subevent].back().set_user_index(i - inBegin);
80 
81  }
82 
83 }
84 
86  LogDebug("VirtualJetProducer") << "Entered produce\n";
87 
88  fjJets_.clear();
89  subInputs_.clear();
90  nSubParticles_.clear();
91  hydroTag_.clear();
92  inputs_.clear();
93 
94  // get inputs and convert them to the fastjet format (fastjet::PeudoJet)
96  iEvent.getByLabel(src_,inputsHandle);
97  for (size_t i = 0; i < inputsHandle->size(); ++i) {
98  inputs_.push_back(inputsHandle->ptrAt(i));
99  }
100  LogDebug("VirtualJetProducer") << "Got inputs\n";
101 
102  inputTowers();
103  // Convert candidates to fastjet::PseudoJets.
104  // Also correct to Primary Vertex. Will modify fjInputs_
105  // and use inputs_
106 
108 
109  std::auto_ptr<std::vector<GenJet> > jets(new std::vector<GenJet>() );
110  subJets_ = jets.get();
111 
112  LogDebug("VirtualJetProducer") << "Inputted towers\n";
113 
114  size_t nsub = subInputs_.size();
115 
116  for(size_t isub = 0; isub < nsub; ++isub){
117  if(ignoreHydro_ && hydroTag_[isub]) continue;
118  fjJets_.clear();
119  fjInputs_.clear();
120  fjInputs_ = subInputs_[isub];
121  runAlgorithm( iEvent, iSetup );
122  }
123 
124  //Finalize
125  LogDebug("SubEventJetProducer") << "Wrote jets\n";
126 
127  iEvent.put(jets);
128  return;
129 }
130 
132 {
133  // run algorithm
134  fjJets_.clear();
135 
136  fjClusterSeq_ = ClusterSequencePtr( new fastjet::ClusterSequence( fjInputs_, *fjJetDefinition_ ) );
137  fjJets_ = fastjet::sorted_by_pt(fjClusterSeq_->inclusive_jets(jetPtMin_));
138 
139  using namespace reco;
140 
141  for (unsigned int ijet=0;ijet<fjJets_.size();++ijet) {
142 
143  GenJet jet;
144  const fastjet::PseudoJet& fjJet = fjJets_[ijet];
145 
146  std::vector<fastjet::PseudoJet> fjConstituents =
147  sorted_by_pt(fjClusterSeq_->constituents(fjJet));
148 
149  std::vector<CandidatePtr> constituents =
150  getConstituents(fjConstituents);
151 
152  double px=fjJet.px();
153  double py=fjJet.py();
154  double pz=fjJet.pz();
155  double E=fjJet.E();
156  double jetArea=0.0;
157  double pu=0.;
158 
159  writeSpecific( jet,
160  Particle::LorentzVector(px, py, pz, E),
161  vertex_,
162  constituents, iSetup);
163 
164  jet.setJetArea (jetArea);
165  jet.setPileup (pu);
166 
167  subJets_->push_back(jet);
168  }
169 }
170 
172 
173 
#define LogDebug(id)
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
reco::Particle::Point vertex_
virtual const Candidate * mother(size_type i=0) const =0
return pointer to mother
virtual std::vector< reco::CandidatePtr > getConstituents(const std::vector< fastjet::PseudoJet > &fjConstituents)
std::vector< fastjet::PseudoJet > fjJets_
virtual void setPileup(float fEnergy)
Set pileup energy contribution as calculated by algorithm.
Definition: Jet.h:109
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual int status() const =0
status word
#define abs(x)
Definition: mlp_lapack.h:159
int collisionId() const
Definition: GenParticle.h:39
std::vector< reco::GenJet > * subJets_
virtual bool isAnomalousTower(reco::CandidatePtr input)
virtual void setJetArea(float fArea)
set jet area
Definition: Jet.h:104
std::vector< fastjet::PseudoJet > fjInputs_
int iEvent
Definition: GenABIO.cc:243
bool isNotFinite(T x)
Definition: isFinite.h:10
std::vector< edm::Ptr< reco::Candidate > > inputs_
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:143
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:94
ClusterSequencePtr fjClusterSeq_
vector< PseudoJet > jets
Jets made from MC generator particles.
Definition: GenJet.h:25
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
tuple conf
Definition: dbtoconf.py:185
virtual int pdgId() const =0
PDG identifier.
void produce(edm::Event &, const edm::EventSetup &)
std::vector< std::vector< fastjet::PseudoJet > > subInputs_
#define debug
Definition: MEtoEDMFormat.h:34
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:25
virtual const Candidate * mother(size_type=0) const
return mother at a given position, i = 0, ... numberOfMothers() - 1 (read only mode) ...
boost::shared_ptr< fastjet::ClusterSequence > ClusterSequencePtr
void runAlgorithm(edm::Event &, const edm::EventSetup &)
void writeSpecific(reco::CaloJet &jet, reco::Particle::LorentzVector const &p4, reco::Particle::Point const &point, std::vector< reco::CandidatePtr > const &constituents, edm::EventSetup const &c)
Definition: JetSpecific.cc:41