CMS 3D CMS Logo

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