CMS 3D CMS Logo

CompoundJetProducer.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 CompoundJetProducer::CompoundJetProducer(edm::ParameterSet const& conf) : VirtualJetProducer(conf) {
15  produces<reco::BasicJetCollection>();
16  // the subjet collections are set through the config file in the "jetCollInstanceName" field.
17 }
18 
20  fjCompoundJets_.clear();
22 }
23 
25  // Write jets and constitutents. Will use fjJets_.
26  switch (jetTypeE) {
27  case JetType::CaloJet:
28  writeCompoundJets<reco::CaloJet>(iEvent, iSetup);
29  break;
30  case JetType::PFJet:
31  writeCompoundJets<reco::PFJet>(iEvent, iSetup);
32  break;
33  case JetType::GenJet:
34  writeCompoundJets<reco::GenJet>(iEvent, iSetup);
35  break;
36  case JetType::BasicJet:
37  writeCompoundJets<reco::BasicJet>(iEvent, iSetup);
38  break;
39  default:
40  throw cms::Exception("InvalidInput") << "invalid jet type in CompoundJetProducer\n";
41  break;
42  };
43 }
44 
46 template <class T>
48  // get a list of output jets
49  auto jetCollection = std::make_unique<reco::BasicJetCollection>();
50  // get a list of output subjets
51  auto subjetCollection = std::make_unique<std::vector<T>>();
52 
53  // This will store the handle for the subjets after we write them
54  edm::OrphanHandle<std::vector<T>> subjetHandleAfterPut;
55  // this is the mapping of subjet to hard jet
56  std::vector<std::vector<int>> indices;
57  // this is the list of hardjet 4-momenta
58  std::vector<math::XYZTLorentzVector> p4_hardJets;
59  // this is the hardjet areas
60  std::vector<double> area_hardJets;
61 
62  [[maybe_unused]] const CaloGeometry* pGeometry = nullptr;
63  [[maybe_unused]] const HcalTopology* pTopology = nullptr;
64  if constexpr (std::is_same_v<T, reco::CaloJet>) {
65  pGeometry = &getGeometry(iSetup);
66  pTopology = &getTopology(iSetup);
67  }
68 
69  // Loop over the hard jets
70  std::vector<CompoundPseudoJet>::const_iterator it = fjCompoundJets_.begin(), iEnd = fjCompoundJets_.end(),
71  iBegin = fjCompoundJets_.begin();
72  indices.resize(fjCompoundJets_.size());
73  for (; it != iEnd; ++it) {
74  int jetIndex = it - iBegin;
75  fastjet::PseudoJet localJet = it->hardJet();
76  // Get the 4-vector for the hard jet
77  p4_hardJets.push_back(math::XYZTLorentzVector(localJet.px(), localJet.py(), localJet.pz(), localJet.e()));
78  area_hardJets.push_back(it->hardJetArea());
79 
80  // create the subjet list
81  std::vector<CompoundPseudoSubJet>::const_iterator itSubJetBegin = it->subjets().begin(), itSubJet = itSubJetBegin,
82  itSubJetEnd = it->subjets().end();
83  for (; itSubJet != itSubJetEnd; ++itSubJet) {
84  fastjet::PseudoJet subjet = itSubJet->subjet();
85  math::XYZTLorentzVector p4Subjet(subjet.px(), subjet.py(), subjet.pz(), subjet.e());
87 
88  // This will hold ptr's to the subjets
89  std::vector<reco::CandidatePtr> subjetConstituents;
90 
91  // Get the transient subjet constituents from fastjet
92  std::vector<int> const& subjetFastjetConstituentIndices = itSubJet->constituents();
93  std::vector<int>::const_iterator fastSubIt = subjetFastjetConstituentIndices.begin(),
94  transConstEnd = subjetFastjetConstituentIndices.end();
95  for (; fastSubIt != transConstEnd; ++fastSubIt) {
96  // Add a ptr to this constituent
97  if (*fastSubIt < static_cast<int>(inputs_.size()))
98  subjetConstituents.push_back(inputs_[*fastSubIt]);
99  }
100 
101  // This holds the subjet-to-hardjet mapping
102  indices[jetIndex].push_back(subjetCollection->size());
103 
104  // Add the concrete subjet type to the subjet list to write to event record
105  T jet;
106  if constexpr (std::is_same_v<T, reco::CaloJet>) {
107  reco::writeSpecific(jet, p4Subjet, point, subjetConstituents, *pGeometry, *pTopology);
108  } else {
109  reco::writeSpecific(jet, p4Subjet, point, subjetConstituents);
110  }
111  jet.setJetArea(itSubJet->subjetArea());
112  subjetCollection->push_back(jet);
113  }
114  }
115  // put subjets into event record
116  subjetHandleAfterPut = iEvent.put(std::move(subjetCollection), jetCollInstanceName_);
117 
118  // Now create the hard jets with ptr's to the subjets as constituents
119  std::vector<math::XYZTLorentzVector>::const_iterator ip4 = p4_hardJets.begin(), ip4Begin = p4_hardJets.begin(),
120  ip4End = p4_hardJets.end();
121 
122  for (; ip4 != ip4End; ++ip4) {
123  int p4_index = ip4 - ip4Begin;
124  std::vector<int>& ind = indices[p4_index];
125  std::vector<reco::CandidatePtr> i_hardJetConstituents;
126  // Add the subjets to the hard jet
127  for (std::vector<int>::const_iterator isub = ind.begin(); isub != ind.end(); ++isub) {
128  reco::CandidatePtr candPtr(subjetHandleAfterPut, *isub, false);
129  i_hardJetConstituents.push_back(candPtr);
130  }
131  reco::Particle::Point point(0, 0, 0);
132  reco::BasicJet toput(*ip4, point, i_hardJetConstituents);
133  toput.setJetArea(area_hardJets[ip4 - ip4Begin]);
134  jetCollection->push_back(toput);
135  }
136 
137  // put hard jets into event record
139 }
JetType::Type jetTypeE
HcalTopology const & getTopology(edm::EventSetup const &) const
void writeCompoundJets(edm::Event &iEvent, edm::EventSetup const &iSetup)
function template to write out the outputs
virtual void inputTowers()
void output(edm::Event &iEvent, edm::EventSetup const &iSetup) override
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
Jets made from CaloTowers.
Definition: BasicJet.h:19
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
virtual void setJetArea(float fArea)
set jet area
Definition: Jet.h:101
int iEvent
Definition: GenABIO.cc:224
std::string jetCollInstanceName_
std::vector< edm::Ptr< reco::Candidate > > inputs_
void inputTowers() override
compound fastjet::PseudoJets
math::XYZPoint Point
point in the space
Definition: Particle.h:25
CaloGeometry const & getGeometry(edm::EventSetup const &) const
std::vector< CompoundPseudoJet > fjCompoundJets_
Namespace of DDCMS conversion namespace.
fixed size matrix
HLT enums.
long double T
def move(src, dest)
Definition: eostools.py:511
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5