test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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:
72 
73 
74  virtual void produce(edm::Event&, const edm::EventSetup&) override;
75  private:
76  std::auto_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 
126  const CaloSubdetectorGeometry* EB = geometry->getSubdetectorGeometry(DetId::Ecal,EcalBarrel);
127  const CaloSubdetectorGeometry* EE = geometry->getSubdetectorGeometry(DetId::Ecal,EcalEndcap);
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  std::auto_ptr<EMLorentzVectorCollection> jetRecHits( new 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  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  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(jetRecHits);
205 
206  std::auto_ptr<JetCrystalsAssociationCollection> jetCrystals = associate(jets,myRecHits);
207  iEvent.put( jetCrystals );
208 }
209 
210 std::auto_ptr<JetCrystalsAssociationCollection> JetCrystalsAssociator::associate(
212  const edm::OrphanHandle<EMLorentzVectorCollection> & myLorentzRecHits) const
213 {
214  // we know we will save an element per input jet
215  std::auto_ptr<JetCrystalsAssociationCollection> outputCollection( new JetCrystalsAssociationCollection( jets->size() ) );
216 
217  //loop on jets and associate
218  for (size_t j = 0; j < jets->size(); j++) {
219  (*outputCollection)[j].first = edm::RefToBase<Jet>(CaloJetRef(jets, j));
220  for (size_t t = 0; t < myLorentzRecHits->size(); t++) {
221  double delta = ROOT::Math::VectorUtil::DeltaR((*jets)[j].p4().Vect(), (*myLorentzRecHits)[t]);
222  if (delta < m_deltaRCut)
223  (*outputCollection)[j].second.push_back( EMLorentzVectorRef(myLorentzRecHits, t) );
224  }
225  }
226  return outputCollection;
227 }
228 
229 //define this as a plug-in
dbl * delta
Definition: mlp_gen.cc:36
T getParameter(std::string const &) const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
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
virtual void produce(edm::Event &, const edm::EventSetup &) override
Geom::Theta< T > theta() const
Definition: PV3DBase.h:75
int iEvent
Definition: GenABIO.cc:230
math::PtEtaPhiELorentzVectorCollection EMLorentzVectorCollection
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
double p4[4]
Definition: TauolaWrapper.h:92
vector< PseudoJet > jets
math::PtEtaPhiELorentzVectorRef EMLorentzVectorRef
int j
Definition: DBlmapReader.cc:9
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:418
std::auto_ptr< JetCrystalsAssociationCollection > associate(const edm::Handle< CaloJetCollection > &jets, const edm::OrphanHandle< EMLorentzVectorCollection > &myLorentzRecHits) const
#define M_PI
edm::Ref< CaloJetCollection > CaloJetRef
edm references
Definition: DetId.h:18
Detector
Definition: DetId.h:24
const T & get() const
Definition: EventSetup.h:56
math::PtEtaPhiELorentzVector EMLorentzVector
Geom::Phi< T > phi() const
T eta() const
Definition: PV3DBase.h:76
ESHandle< TrackerGeometry > geometry
std::vector< JetCrystalsAssociation > JetCrystalsAssociationCollection
Detector det() const
get the detector field from this detid
Definition: DetId.h:35
const GlobalPoint & getPosition() const
Returns the position of reference for this cell.
JetCrystalsAssociator(const edm::ParameterSet &)