CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 namespace {
13  const bool debug = false;
14 
15 }
16 
17 
18 CompoundJetProducer::CompoundJetProducer(edm::ParameterSet const& conf):
19  VirtualJetProducer( conf )
20 {
21 
22  produces<reco::BasicJetCollection>();
23  // the subjet collections are set through the config file in the "jetCollInstanceName" field.
24 }
25 
26 
28 {
29  fjCompoundJets_.clear();
31 }
32 
34 {
35  // Write jets and constitutents. Will use fjJets_.
36  switch( jetTypeE ) {
37  case JetType::CaloJet :
38  writeCompoundJets<reco::CaloJet>( iEvent, iSetup );
39  break;
40  case JetType::PFJet :
41  writeCompoundJets<reco::PFJet>( iEvent, iSetup );
42  break;
43  case JetType::GenJet :
44  writeCompoundJets<reco::GenJet>( iEvent, iSetup );
45  break;
46  case JetType::BasicJet :
47  writeCompoundJets<reco::BasicJet>( iEvent, iSetup );
48  break;
49  default:
50  throw cms::Exception("InvalidInput") << "invalid jet type in CompoundJetProducer\n";
51  break;
52  };
53 
54 }
55 
57 template< class T>
59 {
60 
61  // get a list of output jets
62  std::auto_ptr<reco::BasicJetCollection> jetCollection( new reco::BasicJetCollection() );
63  // get a list of output subjets
64  std::auto_ptr<std::vector<T> > subjetCollection( new std::vector<T>() );
65 
66  // This will store the handle for the subjets after we write them
67  edm::OrphanHandle< std::vector<T> > subjetHandleAfterPut;
68  // this is the mapping of subjet to hard jet
69  std::vector< std::vector<int> > indices;
70  // this is the list of hardjet 4-momenta
71  std::vector<math::XYZTLorentzVector> p4_hardJets;
72  // this is the hardjet areas
73  std::vector<double> area_hardJets;
74 
75 
76  // Loop over the hard jets
77  std::vector<CompoundPseudoJet>::const_iterator it = fjCompoundJets_.begin(),
78  iEnd = fjCompoundJets_.end(),
79  iBegin = fjCompoundJets_.begin();
80  indices.resize( fjCompoundJets_.size() );
81  for ( ; it != iEnd; ++it ) {
82  int jetIndex = it - iBegin;
83  fastjet::PseudoJet localJet = it->hardJet();
84  // Get the 4-vector for the hard jet
85  p4_hardJets.push_back( math::XYZTLorentzVector(localJet.px(), localJet.py(), localJet.pz(), localJet.e() ));
86  area_hardJets.push_back( it->hardJetArea() );
87 
88  // create the subjet list
89  std::vector<CompoundPseudoSubJet>::const_iterator itSubJetBegin = it->subjets().begin(),
90  itSubJet = itSubJetBegin, itSubJetEnd = it->subjets().end();
91  for (; itSubJet != itSubJetEnd; ++itSubJet ){
92 
93  fastjet::PseudoJet subjet = itSubJet->subjet();
94  math::XYZTLorentzVector p4Subjet(subjet.px(), subjet.py(), subjet.pz(), subjet.e() );
96 
97  // This will hold ptr's to the subjets
98  std::vector<reco::CandidatePtr> subjetConstituents;
99 
100  // Get the transient subjet constituents from fastjet
101  std::vector<int> const & subjetFastjetConstituentIndices = itSubJet->constituents();
102  std::vector<int>::const_iterator fastSubIt = subjetFastjetConstituentIndices.begin(),
103  transConstBegin = subjetFastjetConstituentIndices.begin(),
104  transConstEnd = subjetFastjetConstituentIndices.end();
105  for ( ; fastSubIt != transConstEnd; ++fastSubIt ) {
106  // Add a ptr to this constituent
107  if ( *fastSubIt < static_cast<int>(inputs_.size()) )
108  subjetConstituents.push_back( inputs_[*fastSubIt] );
109  }
110 
111  // This holds the subjet-to-hardjet mapping
112  indices[jetIndex].push_back( subjetCollection->size() );
113 
114 
115  // Add the concrete subjet type to the subjet list to write to event record
116  T jet;
117  reco::writeSpecific( jet, p4Subjet, point, subjetConstituents, iSetup);
118  jet.setJetArea( itSubJet->subjetArea() );
119  subjetCollection->push_back( jet );
120 
121  }
122  }
123  // put subjets into event record
124  subjetHandleAfterPut = iEvent.put( subjetCollection, jetCollInstanceName_ );
125 
126 
127  // Now create the hard jets with ptr's to the subjets as constituents
128  std::vector<math::XYZTLorentzVector>::const_iterator ip4 = p4_hardJets.begin(),
129  ip4Begin = p4_hardJets.begin(),
130  ip4End = p4_hardJets.end();
131 
132  for ( ; ip4 != ip4End; ++ip4 ) {
133  int p4_index = ip4 - ip4Begin;
134  std::vector<int> & ind = indices[p4_index];
135  std::vector<reco::CandidatePtr> i_hardJetConstituents;
136  // Add the subjets to the hard jet
137  for( std::vector<int>::const_iterator isub = ind.begin();
138  isub != ind.end(); ++isub ) {
139  reco::CandidatePtr candPtr( subjetHandleAfterPut, *isub, false );
140  i_hardJetConstituents.push_back( candPtr );
141  }
143  reco::BasicJet toput( *ip4, point, i_hardJetConstituents);
144  toput.setJetArea( area_hardJets[ip4 - ip4Begin] );
145  jetCollection->push_back( toput );
146  }
147 
148  // put hard jets into event record
149  iEvent.put( jetCollection);
150 
151 }
JetType::Type jetTypeE
void writeCompoundJets(edm::Event &iEvent, edm::EventSetup const &iSetup)
function template to write out the outputs
virtual void inputTowers()
virtual void inputTowers()
compound fastjet::PseudoJets
Jets made from CaloTowers.
Definition: BasicJet.h:21
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:30
virtual void setJetArea(float fArea)
set jet area
Definition: Jet.h:91
int iEvent
Definition: GenABIO.cc:243
std::string jetCollInstanceName_
std::vector< edm::Ptr< reco::Candidate > > inputs_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:84
math::XYZPoint Point
point in the space
Definition: Particle.h:30
std::vector< CompoundPseudoJet > fjCompoundJets_
tuple conf
Definition: dbtoconf.py:185
#define debug
Definition: MEtoEDMFormat.h:34
long double T
virtual void output(edm::Event &iEvent, edm::EventSetup const &iSetup)
*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
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
std::vector< BasicJet > BasicJetCollection
collection of BasicJet objects