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