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.2 2011/11/30 07:45:28 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() override ;
76  virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
77  virtual void endJob() override ;
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");
110  parameters_.loadParameters( parameters, iC );
111 
112  tree_ = fs_->make<TTree>("EopTree","EopTree");
114  tree_->Branch("EopVariables", &treeMemPtr_); // address of pointer!
115 }
116 
117 
119 {
120 
121  // do anything here that needs to be done at destruction time
122  // (e.g. close files, deallocate resources etc.)
123 
124 }
125 
126 
127 //
128 // member functions
129 //
130 
131 // ------------ method called to for each event ------------
132 void
134 {
135  using namespace edm;
136 
137  // get geometry
139  iSetup.get<CaloGeometryRecord>().get(geometry);
140  const CaloGeometry* geo = geometry.product();
141 // const CaloSubdetectorGeometry* towerGeometry =
142 // geo->getSubdetectorGeometry(DetId::Calo, CaloTowerDetId::SubdetId);
143 
144  // temporary collection of EB+EE recHits
145  std::auto_ptr<EcalRecHitCollection> tmpEcalRecHitCollection(new EcalRecHitCollection);
146  std::vector<edm::InputTag> ecalLabels_;
147 
149  bool ecalInAlca = iEvent.getByLabel(edm::InputTag("IsoProd","IsoTrackEcalRecHitCollection"),tmpEc);
150  bool ecalInReco = iEvent.getByLabel(edm::InputTag("ecalRecHit","EcalRecHitsEB"),tmpEc)&&
151  iEvent.getByLabel(edm::InputTag("ecalRecHit","EcalRecHitsEE"),tmpEc);
152  if(ecalInAlca)ecalLabels_.push_back(edm::InputTag("IsoProd","IsoTrackEcalRecHitCollection"));
153  else if(ecalInReco){
154  ecalLabels_.push_back(edm::InputTag("ecalRecHit","EcalRecHitsEB"));
155  ecalLabels_.push_back(edm::InputTag("ecalRecHit","EcalRecHitsEE"));
156  }
157  else throw cms::Exception("MissingProduct","can not find EcalRecHits");
158 
159  std::vector<edm::InputTag>::const_iterator i;
160  for (i=ecalLabels_.begin(); i!=ecalLabels_.end(); i++)
161  {
163  iEvent.getByLabel(*i,ec);
164  for(EcalRecHitCollection::const_iterator recHit = (*ec).begin(); recHit != (*ec).end(); ++recHit)
165  {
166  tmpEcalRecHitCollection->push_back(*recHit);
167  }
168  }
169 
171  iEvent.getByLabel(src_, tracks);
172 
175  bool pixelInAlca = iEvent.getByLabel(edm::InputTag("IsoProd","HcalIsolatedTrackCollection"),tmpPix);
176  if(pixelInAlca)iEvent.getByLabel(edm::InputTag("IsoProd","HcalIsolatedTrackCollection"),isoPixelTracks);
177 
178  Double_t trackemc1;
179  Double_t trackemc3;
180  Double_t trackemc5;
181  Double_t trackhac1;
182  Double_t trackhac3;
183  Double_t trackhac5;
184  Double_t maxPNearby;
185  Double_t dist;
186  Double_t EnergyIn;
187  Double_t EnergyOut;
188 
189  parameters_.useMuon = false;
190 
191  if(pixelInAlca)
192  if(isoPixelTracks->size()==0) return;
193 
194  for(reco::TrackCollection::const_iterator track = tracks->begin();track!=tracks->end();++track){
195 
196  bool noChargedTracks = true;
197 
198  if(track->p()<9.) continue;
199 
202 
203  trackemc1 = 0;
204  trackemc3 = 0;
205  trackemc5 = 0;
206  trackhac1 = 0;
207  trackhac3 = 0;
208  trackhac5 = 0;
209 
210  trackemc1 = info.nXnEnergy(TrackDetMatchInfo::EcalRecHits, 0);
211  trackemc3 = info.nXnEnergy(TrackDetMatchInfo::EcalRecHits, 1);
212  trackemc5 = info.nXnEnergy(TrackDetMatchInfo::EcalRecHits, 2);
213  trackhac1 = info.nXnEnergy(TrackDetMatchInfo::HcalRecHits, 0);
214  trackhac3 = info.nXnEnergy(TrackDetMatchInfo::HcalRecHits, 1);
215  trackhac5 = info.nXnEnergy(TrackDetMatchInfo::HcalRecHits, 2);
216 
217  if(trackhac3<5.) continue;
218 
219  double etaecal=info.trkGlobPosAtEcal.eta();
220  double phiecal=info.trkGlobPosAtEcal.phi();
221 
222  maxPNearby=-10;
223  dist=50;
224  for (reco::TrackCollection::const_iterator track1 = tracks->begin(); track1!=tracks->end(); track1++)
225  {
226  if (track == track1) continue;
227  TrackDetMatchInfo info1 = trackAssociator_.associate(iEvent, iSetup, *track1, parameters_);
228  double etaecal1=info1.trkGlobPosAtEcal.eta();
229  double phiecal1=info1.trkGlobPosAtEcal.phi();
230 
231  if (etaecal1==0&&phiecal1==0) continue;
232 
233  double ecDist=getDistInCM(etaecal,phiecal,etaecal1,phiecal1);
234 
235  if( ecDist < 40. )
236  {
237  //calculate maximum P and sum P near seed track
238  if (track1->p()>maxPNearby)
239  {
240  maxPNearby=track1->p();
241  dist = ecDist;
242  }
243 
244  //apply loose isolation criteria
245  if (track1->p()>5.)
246  {
247  noChargedTracks = false;
248  break;
249  }
250  }
251  }
252  EnergyIn=0;
253  EnergyOut=0;
254  if(noChargedTracks){
255  for (std::vector<EcalRecHit>::const_iterator ehit=tmpEcalRecHitCollection->begin(); ehit!=tmpEcalRecHitCollection->end(); ehit++)
256  {
258  // R-scheme of ECAL CLUSTERIZATION
259  GlobalPoint posH = geo->getPosition((*ehit).detid());
260  double phihit = posH.phi();
261  double etahit = posH.eta();
262 
263  double dHitCM=getDistInCM(etaecal,phiecal,etahit,phihit);
264 
265  if (dHitCM<9.0)
266  {
267  EnergyIn+=ehit->energy();
268  }
269  if (dHitCM>15.0&&dHitCM<35.0)
270  {
271  EnergyOut+=ehit->energy();
272  }
273 
274  }
275 
276  treeMemPtr_->fillVariables(track->charge(), track->innerOk(), track->outerRadius(),
277  track->numberOfValidHits(), track->numberOfLostHits(),
278  track->chi2(), track->normalizedChi2(),
279  track->p(), track->pt(), track->ptError(),
280  track->theta(), track->eta(), track->phi(),
281  trackemc1, trackemc3, trackemc5,
282  trackhac1, trackhac3, trackhac5,
283  maxPNearby, dist, EnergyIn, EnergyOut);
284 
285  tree_->Fill();
286  }
287  }
288 }
289 
290 
291 // ------------ method called once each job just before starting event loop ------------
292 void
294 {
295 }
296 
297 // ------------ method called once each job just after ending the event loop ------------
298 void
300 
301  delete treeMemPtr_; treeMemPtr_ = 0;
302 
303 }
304 
305 double
306 EopTreeWriter::getDistInCM(double eta1, double phi1, double eta2, double phi2)
307 {
308  double deltaPhi=phi1-phi2;
309  while(deltaPhi > TMath::Pi())deltaPhi-=2*TMath::Pi();
310  while(deltaPhi <= -TMath::Pi())deltaPhi+=2*TMath::Pi();
311  double dR;
312  // double Rec;
313  double theta1=2*atan(exp(-eta1));
314  double theta2=2*atan(exp(-eta2));
315  double cotantheta1;
316  if(cos(theta1)==0)cotantheta1=0;
317  else cotantheta1=1/tan(theta1);
318  double cotantheta2;
319  if(cos(theta2)==0)cotantheta2=0;
320  else cotantheta2=1/tan(theta2);
321  // if (fabs(eta1)<1.479) Rec=129; //radius of ECAL barrel
322  // else Rec=317; //distance from IP to ECAL endcap
323  //|vect| times tg of acos(scalar product)
324  // dR=fabs((Rec/sin(theta1))*tan(acos(sin(theta1)*sin(theta2)*(sin(phi1)*sin(phi2)+cos(phi1)*cos(phi2))+cos(theta1)*cos(theta2))));
325  if(fabs(eta1)<1.479)dR=129*sqrt((cotantheta1-cotantheta2)*(cotantheta1-cotantheta2)+deltaPhi*deltaPhi);
326  else dR=317*sqrt(tan(theta1)*tan(theta1)+tan(theta2)*tan(theta2)-2*tan(theta1)*tan(theta2)*cos(deltaPhi));
327  return dR;
328 }
329 
330 //define this as a plug-in
const double Pi
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
static const TGPicture * info(bool iBackgroundIsBlack)
container to hold data to be written into TTree
Definition: EopVariables.h:8
#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
virtual void analyze(const edm::Event &, const edm::EventSetup &) override
std::vector< EcalRecHit >::const_iterator const_iterator
void loadParameters(const edm::ParameterSet &, edm::ConsumesCollector &)
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
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:230
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
T sqrt(T t)
Definition: SSEVec.h:18
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
TrackAssociatorParameters parameters_
virtual void endJob() override
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:418
TrackDetectorAssociator trackAssociator_
tuple tracks
Definition: testEve_cfg.py:39
const T & get() const
Definition: EventSetup.h:56
T const * product() const
Definition: ESHandle.h:86
T eta() const
Definition: PV3DBase.h:76
virtual void beginJob() override
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 &)
math::XYZPoint trkGlobPosAtEcal
Track position at different parts of the calorimeter.
EopVariables * treeMemPtr_
EopTreeWriter(const edm::ParameterSet &)