CMS 3D CMS Logo

JetCrystalsAssociator.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: JetCrystalsAssociator
4 // Class: JetCrystalsAssociator
5 //
13 //
14 // Original Author: Simone Gennai
15 // Created: Wed Apr 12 11:12:49 CEST 2006
16 //
17 //
18 
19 
20 // system include files
21 #include <memory>
22 #include <string>
23 #include <iostream>
25 
26 // user include files
35 
36 
40 
41 //Calorimeter stuff
46 
51 
57 
58 // Math
59 #include "Math/GenVector/VectorUtil.h"
60 #include "Math/GenVector/PxPyPzE4D.h"
61 using namespace reco;
62 
63 //
64 // class decleration
65 //
66 
68 
69  public:
71  ~JetCrystalsAssociator() override;
72 
73 
74  void produce(edm::Event&, const edm::EventSetup&) override;
75  private:
76  std::unique_ptr<JetCrystalsAssociationCollection> associate(
78  const edm::OrphanHandle<EMLorentzVectorCollection> & myLorentzRecHits) const;
79 
80 
81  // ----------member data ---------------------------
85 
86  double m_deltaRCut;
87 };
88 
90 {
91  produces<reco::JetCrystalsAssociationCollection>();
92  produces<reco::EMLorentzVectorCollection>();
93 
94  m_EBRecHits = iConfig.getParameter<edm::InputTag>("EBRecHits");
95  m_EERecHits = iConfig.getParameter<edm::InputTag>("EERecHits");
96  m_jetsSrc = iConfig.getParameter<edm::InputTag>("jets");
97  m_deltaRCut = iConfig.getParameter<double>("coneSize");
98 }
99 
100 
102 {
103 
104  // do anything here that needs to be done at desctruction time
105  // (e.g. close files, deallocate resources etc.)
106 
107 }
108 
109 
110 //
111 // member functions
112 //
113 
114 // ------------ method called to produce the data ------------
115 void
117 {
118  using namespace edm;
119  using namespace reco;
120  using namespace std;
121 
122  // geometry initialization
124  iSetup.get<CaloGeometryRecord>().get(geometry);
125 
128  // end
129 
131  iEvent.getByLabel(m_jetsSrc, jets);
132 
133  // get calo towers collection
134  // Handle<CaloTowerCollection> caloTowers;
135  // iEvent.getByLabel(m_towersSrc, caloTowers);
136 
137  // calculation of ECAL isolation
140  iEvent.getByLabel( m_EBRecHits, EBRecHits );
141  iEvent.getByLabel( m_EERecHits, EERecHits );
142 
143  auto jetRecHits = std::make_unique<EMLorentzVectorCollection>();
144  //loop on jets and associate
145  for (size_t t = 0; t < jets->size(); t++)
146  {
147  const std::vector<CaloTowerPtr> myTowers=(*jets)[t].getCaloConstituents();
148  // cout <<"Jet id "<<t<<endl;
149  // cout <<"Tower size "<<myTowers.size()<<endl;
150  for (unsigned int iTower = 0; iTower < myTowers.size(); iTower++)
151  {
152  CaloTowerPtr theTower = myTowers[iTower];
153  size_t numRecHits = theTower->constituentsSize();
154  // access CaloRecHits
155  for (size_t j = 0; j < numRecHits; j++) {
156  DetId RecHitDetID=theTower->constituent(j);
157  DetId::Detector DetNum=RecHitDetID.det();
158  if( DetNum == DetId::Ecal ){
159  int EcalNum = RecHitDetID.subdetId();
160  if( EcalNum == 1 ){
161  EBDetId EcalID = RecHitDetID;
162  EBRecHitCollection::const_iterator theRecHit=EBRecHits->find(EcalID);
163  if(theRecHit != EBRecHits->end()){
164  DetId id = theRecHit->detid();
165  const CaloCellGeometry* this_cell = EB->getGeometry(id);
166  if (this_cell) {
167  const GlobalPoint& posi = this_cell->getPosition();
168  double energy = theRecHit->energy();
169  double eta = posi.eta();
170  double phi = posi.phi();
171  double theta = posi.theta();
172  if(theta > M_PI) theta = 2 * M_PI- theta;
173  double et = energy * sin(theta);
174  // cout <<"Et "<<et<<endl;
175  EMLorentzVector p(et, eta, phi, energy);
176  jetRecHits->push_back(p);
177  }
178  }
179  } else if ( EcalNum == 2 ) {
180  EEDetId EcalID = RecHitDetID;
181  EERecHitCollection::const_iterator theRecHit=EERecHits->find(EcalID);
182  if(theRecHit != EBRecHits->end()){
183  DetId id = theRecHit->detid();
184  const CaloCellGeometry* this_cell = EE->getGeometry(id);
185  if (this_cell) {
186  const GlobalPoint& posi = this_cell->getPosition();
187  double energy = theRecHit->energy();
188  double eta = posi.eta();
189  double phi = posi.phi();
190  double theta = posi.theta();
191  if (theta > M_PI) theta = 2 * M_PI - theta;
192  double et = energy * sin(theta);
193  // cout <<"Et "<<et<<endl;
194  EMLorentzVector p(et, eta, phi, energy);
195  jetRecHits->push_back(p);
196  }
197  }
198  }
199  }
200  }
201  }
202  }
203 
204  edm::OrphanHandle <reco::EMLorentzVectorCollection> myRecHits = iEvent.put(std::move(jetRecHits));
205 
206  iEvent.put(associate(jets,myRecHits));
207 }
208 
209 std::unique_ptr<JetCrystalsAssociationCollection> JetCrystalsAssociator::associate(
211  const edm::OrphanHandle<EMLorentzVectorCollection> & myLorentzRecHits) const
212 {
213  // we know we will save an element per input jet
214  auto outputCollection = std::make_unique<JetCrystalsAssociationCollection>(jets->size());
215 
216  //loop on jets and associate
217  for (size_t j = 0; j < jets->size(); j++) {
218  (*outputCollection)[j].first = edm::RefToBase<Jet>(CaloJetRef(jets, j));
219  for (size_t t = 0; t < myLorentzRecHits->size(); t++) {
220  double delta = ROOT::Math::VectorUtil::DeltaR((*jets)[j].p4().Vect(), (*myLorentzRecHits)[t]);
221  if (delta < m_deltaRCut)
222  (*outputCollection)[j].second.push_back( EMLorentzVectorRef(myLorentzRecHits, t) );
223  }
224  }
225  return outputCollection;
226 }
227 
228 //define this as a plug-in
dbl * delta
Definition: mlp_gen.cc:36
T getParameter(std::string const &) const
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:45
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:127
size_t constituentsSize() const
Definition: CaloTower.h:105
std::unique_ptr< JetCrystalsAssociationCollection > associate(const edm::Handle< CaloJetCollection > &jets, const edm::OrphanHandle< EMLorentzVectorCollection > &myLorentzRecHits) const
DetId constituent(size_t i) const
Definition: CaloTower.h:106
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual const GlobalPoint & getPosition() const
Returns the position of reference for this cell.
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
std::vector< EcalRecHit >::const_iterator const_iterator
Geom::Theta< T > theta() const
void produce(edm::Event &, const edm::EventSetup &) override
virtual const CaloCellGeometry * getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
Geom::Theta< T > theta() const
Definition: PV3DBase.h:75
int iEvent
Definition: GenABIO.cc:230
double p4[4]
Definition: TauolaWrapper.h:92
vector< PseudoJet > jets
math::PtEtaPhiELorentzVectorRef EMLorentzVectorRef
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:464
#define M_PI
edm::Ref< CaloJetCollection > CaloJetRef
edm references
const_iterator end() const
Definition: DetId.h:18
Detector
Definition: DetId.h:24
const T & get() const
Definition: EventSetup.h:55
math::PtEtaPhiELorentzVector EMLorentzVector
et
define resolution functions of each parameter
T eta() const
Definition: PV3DBase.h:76
ESHandle< TrackerGeometry > geometry
iterator find(key_type k)
fixed size matrix
HLT enums.
Detector det() const
get the detector field from this detid
Definition: DetId.h:35
def move(src, dest)
Definition: eostools.py:510
JetCrystalsAssociator(const edm::ParameterSet &)