CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EopTreeWriter.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: EopTreeWriter
4 // Class: EopTreeWriter
5 //
13 //
14 // Original Author: Holger Enderle
15 // Created: Thu Dec 4 11:22:48 CET 2008
16 // $Id: EopTreeWriter.cc,v 1.3 2012/03/02 07:46:48 mussgill Exp $
17 //
18 //
19 
20 // framework include files
29 
31 
32 // user include files
35 #include <TMath.h>
36 #include <TH1.h>
37 #include "TTree.h"
38 
41 
46 
51 
54 
61 
63 
64 //
65 // class decleration
66 //
67 
69  public:
70  explicit EopTreeWriter(const edm::ParameterSet&);
72 
73 
74  private:
75  virtual void beginJob() ;
76  virtual void analyze(const edm::Event&, const edm::EventSetup&);
77  virtual void endJob() ;
78 
79  double getDistInCM(double eta1, double phi1, double eta2, double phi2);
80 
81  // ----------member data ---------------------------
83 
85  TTree *tree_;
89 };
90 
91 //
92 // constants, enums and typedefs
93 //
94 
95 //
96 // static data member definitions
97 //
98 
99 //
100 // constructors and destructor
101 //
103  src_(iConfig.getParameter<edm::InputTag>("src"))
104 {
105  //now do what ever initialization is needed
106 
107  // TrackAssociator parameters
108  edm::ParameterSet parameters = iConfig.getParameter<edm::ParameterSet>("TrackAssociatorParameters");
109  parameters_.loadParameters( parameters );
110 
111  tree_ = fs_->make<TTree>("EopTree","EopTree");
113  tree_->Branch("EopVariables", &treeMemPtr_); // address of pointer!
114 }
115 
116 
118 {
119 
120  // do anything here that needs to be done at destruction time
121  // (e.g. close files, deallocate resources etc.)
122 
123 }
124 
125 
126 //
127 // member functions
128 //
129 
130 // ------------ method called to for each event ------------
131 void
133 {
134  using namespace edm;
135 
136  // get geometry
138  iSetup.get<CaloGeometryRecord>().get(geometry);
139  const CaloGeometry* geo = geometry.product();
140 // const CaloSubdetectorGeometry* towerGeometry =
141 // geo->getSubdetectorGeometry(DetId::Calo, CaloTowerDetId::SubdetId);
142 
143  // temporary collection of EB+EE recHits
144  std::auto_ptr<EcalRecHitCollection> tmpEcalRecHitCollection(new EcalRecHitCollection);
145  std::vector<edm::InputTag> ecalLabels_;
146 
148  bool ecalInAlca = iEvent.getByLabel(edm::InputTag("IsoProd","IsoTrackEcalRecHitCollection"),tmpEc);
149  bool ecalInReco = iEvent.getByLabel(edm::InputTag("ecalRecHit","EcalRecHitsEB"),tmpEc)&&
150  iEvent.getByLabel(edm::InputTag("ecalRecHit","EcalRecHitsEE"),tmpEc);
151  if(ecalInAlca)ecalLabels_.push_back(edm::InputTag("IsoProd","IsoTrackEcalRecHitCollection"));
152  else if(ecalInReco){
153  ecalLabels_.push_back(edm::InputTag("ecalRecHit","EcalRecHitsEB"));
154  ecalLabels_.push_back(edm::InputTag("ecalRecHit","EcalRecHitsEE"));
155  }
156  else throw cms::Exception("MissingProduct","can not find EcalRecHits");
157 
158  std::vector<edm::InputTag>::const_iterator i;
159  for (i=ecalLabels_.begin(); i!=ecalLabels_.end(); i++)
160  {
162  iEvent.getByLabel(*i,ec);
163  for(EcalRecHitCollection::const_iterator recHit = (*ec).begin(); recHit != (*ec).end(); ++recHit)
164  {
165  tmpEcalRecHitCollection->push_back(*recHit);
166  }
167  }
168 
170  iEvent.getByLabel(src_, tracks);
171 
174  bool pixelInAlca = iEvent.getByLabel(edm::InputTag("IsoProd","HcalIsolatedTrackCollection"),tmpPix);
175  if(pixelInAlca)iEvent.getByLabel(edm::InputTag("IsoProd","HcalIsolatedTrackCollection"),isoPixelTracks);
176 
177  Double_t trackemc1;
178  Double_t trackemc3;
179  Double_t trackemc5;
180  Double_t trackhac1;
181  Double_t trackhac3;
182  Double_t trackhac5;
183  Double_t maxPNearby;
184  Double_t dist;
185  Double_t EnergyIn;
186  Double_t EnergyOut;
187 
188  parameters_.useMuon = false;
189 
190  if(pixelInAlca)
191  if(isoPixelTracks->size()==0) return;
192 
193  for(reco::TrackCollection::const_iterator track = tracks->begin();track!=tracks->end();++track){
194 
195  bool noChargedTracks = true;
196 
197  if(track->p()<9.) continue;
198 
201 
202  trackemc1 = 0;
203  trackemc3 = 0;
204  trackemc5 = 0;
205  trackhac1 = 0;
206  trackhac3 = 0;
207  trackhac5 = 0;
208 
209  trackemc1 = info.nXnEnergy(TrackDetMatchInfo::EcalRecHits, 0);
210  trackemc3 = info.nXnEnergy(TrackDetMatchInfo::EcalRecHits, 1);
211  trackemc5 = info.nXnEnergy(TrackDetMatchInfo::EcalRecHits, 2);
212  trackhac1 = info.nXnEnergy(TrackDetMatchInfo::HcalRecHits, 0);
213  trackhac3 = info.nXnEnergy(TrackDetMatchInfo::HcalRecHits, 1);
214  trackhac5 = info.nXnEnergy(TrackDetMatchInfo::HcalRecHits, 2);
215 
216  if(trackhac3<5.) continue;
217 
218  double etaecal=info.trkGlobPosAtEcal.eta();
219  double phiecal=info.trkGlobPosAtEcal.phi();
220 
221  maxPNearby=-10;
222  dist=50;
223  for (reco::TrackCollection::const_iterator track1 = tracks->begin(); track1!=tracks->end(); track1++)
224  {
225  if (track == track1) continue;
226  TrackDetMatchInfo info1 = trackAssociator_.associate(iEvent, iSetup, *track1, parameters_);
227  double etaecal1=info1.trkGlobPosAtEcal.eta();
228  double phiecal1=info1.trkGlobPosAtEcal.phi();
229 
230  if (etaecal1==0&&phiecal1==0) continue;
231 
232  double ecDist=getDistInCM(etaecal,phiecal,etaecal1,phiecal1);
233 
234  if( ecDist < 40. )
235  {
236  //calculate maximum P and sum P near seed track
237  if (track1->p()>maxPNearby)
238  {
239  maxPNearby=track1->p();
240  dist = ecDist;
241  }
242 
243  //apply loose isolation criteria
244  if (track1->p()>5.)
245  {
246  noChargedTracks = false;
247  break;
248  }
249  }
250  }
251  EnergyIn=0;
252  EnergyOut=0;
253  if(noChargedTracks){
254  for (std::vector<EcalRecHit>::const_iterator ehit=tmpEcalRecHitCollection->begin(); ehit!=tmpEcalRecHitCollection->end(); ehit++)
255  {
257  // R-scheme of ECAL CLUSTERIZATION
258  GlobalPoint posH = geo->getPosition((*ehit).detid());
259  double phihit = posH.phi();
260  double etahit = posH.eta();
261 
262  double dHitCM=getDistInCM(etaecal,phiecal,etahit,phihit);
263 
264  if (dHitCM<9.0)
265  {
266  EnergyIn+=ehit->energy();
267  }
268  if (dHitCM>15.0&&dHitCM<35.0)
269  {
270  EnergyOut+=ehit->energy();
271  }
272 
273  }
274 
275  treeMemPtr_->fillVariables(track->charge(), track->innerOk(), track->outerRadius(),
276  track->numberOfValidHits(), track->numberOfLostHits(),
277  track->chi2(), track->normalizedChi2(),
278  track->p(), track->pt(), track->ptError(),
279  track->theta(), track->eta(), track->phi(),
280  trackemc1, trackemc3, trackemc5,
281  trackhac1, trackhac3, trackhac5,
282  maxPNearby, dist, EnergyIn, EnergyOut);
283 
284  tree_->Fill();
285  }
286  }
287 }
288 
289 
290 // ------------ method called once each job just before starting event loop ------------
291 void
293 {
294 }
295 
296 // ------------ method called once each job just after ending the event loop ------------
297 void
299 
300  delete treeMemPtr_; treeMemPtr_ = 0;
301 
302 }
303 
304 double
305 EopTreeWriter::getDistInCM(double eta1, double phi1, double eta2, double phi2)
306 {
307  double deltaPhi=phi1-phi2;
308  while(deltaPhi > TMath::Pi())deltaPhi-=2*TMath::Pi();
309  while(deltaPhi <= -TMath::Pi())deltaPhi+=2*TMath::Pi();
310  double dR;
311  // double Rec;
312  double theta1=2*atan(exp(-eta1));
313  double theta2=2*atan(exp(-eta2));
314  double cotantheta1;
315  if(cos(theta1)==0)cotantheta1=0;
316  else cotantheta1=1/tan(theta1);
317  double cotantheta2;
318  if(cos(theta2)==0)cotantheta2=0;
319  else cotantheta2=1/tan(theta2);
320  // if (fabs(eta1)<1.479) Rec=129; //radius of ECAL barrel
321  // else Rec=317; //distance from IP to ECAL endcap
322  //|vect| times tg of acos(scalar product)
323  // dR=fabs((Rec/sin(theta1))*tan(acos(sin(theta1)*sin(theta2)*(sin(phi1)*sin(phi2)+cos(phi1)*cos(phi2))+cos(theta1)*cos(theta2))));
324  if(fabs(eta1)<1.479)dR=129*sqrt((cotantheta1-cotantheta2)*(cotantheta1-cotantheta2)+deltaPhi*deltaPhi);
325  else dR=317*sqrt(tan(theta1)*tan(theta1)+tan(theta2)*tan(theta2)-2*tan(theta1)*tan(theta2)*cos(deltaPhi));
326  return dR;
327 }
328 
329 //define this as a plug-in
const double Pi
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
dictionary parameters
Definition: Parameters.py:2
container to hold data to be written into TTree
Definition: EopVariables.h:8
virtual void analyze(const edm::Event &, const edm::EventSetup &)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
static FreeTrajectoryState getFreeTrajectoryState(const edm::EventSetup &, const reco::Track &)
get FreeTrajectoryState from different track representations
void useDefaultPropagator()
use the default propagator
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
std::vector< EcalRecHit >::const_iterator const_iterator
edm::InputTag src_
double nXnEnergy(const DetId &, EnergyType, int gridSize=1)
get energy of the NxN shape (N = 2*gridSize + 1) around given detector element
int iEvent
Definition: GenABIO.cc:243
T sqrt(T t)
Definition: SSEVec.h:48
virtual void endJob()
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
TrackAssociatorParameters parameters_
edm::Service< TFileService > fs_
void fillVariables(Int_t charge, Int_t innerOk, Double_t outerRadius, Int_t numberOfValidHits, Int_t numberOfLostHits, Double_t chi2, Double_t normalizedChi2, Double_t p, Double_t pt, Double_t ptError, Double_t theta, Double_t eta, Double_t phi, Double_t emc1, Double_t emc3, Double_t emc5, Double_t hac1, Double_t hac3, Double_t hac5, Double_t maxPNearby, Double_t dist, Double_t EnergyIn, Double_t EnergyOut)
fill variables into tree
Definition: EopVariables.h:25
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
TrackDetectorAssociator trackAssociator_
tuple tracks
Definition: testEve_cfg.py:39
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
virtual void beginJob()
T eta() const
Definition: PV3DBase.h:76
ESHandle< TrackerGeometry > geometry
double getDistInCM(double eta1, double phi1, double eta2, double phi2)
TrackDetMatchInfo associate(const edm::Event &, const edm::EventSetup &, const FreeTrajectoryState &, const AssociatorParameters &)
T * make() const
make new ROOT object
math::XYZPoint trkGlobPosAtEcal
Track position at different parts of the calorimeter.
void loadParameters(const edm::ParameterSet &)
EopVariables * treeMemPtr_
EopTreeWriter(const edm::ParameterSet &)