CMS 3D CMS Logo

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