CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EvtPlaneProducer.cc
Go to the documentation of this file.
1 //
2 // Original Author: Sergey Petrushanko
3 // Created: Fri Jul 11 10:05:00 2008
4 //
5 //
6 
7 
8 // system include files
9 #include <memory>
10 #include <iostream>
11 #include <time.h>
12 #include "TMath.h"
13 
14 // user include files
19 
23 
28 
31 
34 
41 
42 #include <cstdlib>
44 
45 using namespace std;
46 using namespace hi;
47 
48 //
49 // class decleration
50 //
51 
53 public:
54  explicit EvtPlaneProducer(const edm::ParameterSet&);
56 
57 private:
58  //edm::Service<TFileService> fs;
59  class GenPlane {
60  public:
61  GenPlane(string name,double etaminval1,double etamaxval1,double etaminval2,double etamaxval2,int orderval){
62  epname=name;
63  etamin1=etaminval1;
64  etamax1=etamaxval1;
65  etamin2=etaminval2;
66  etamax2=etamaxval2;
67  sumsin=0;
68  sumcos=0;
69  order = (double) orderval;
70  }
71  ~GenPlane(){;}
72  void addParticle(double w, double s, double c, double eta) {
73  if(w < 0.001) return;
74  if((eta>=etamin1 && eta<etamax1) ||
75  (etamin2!= etamax2 && eta>=etamin2 && eta<etamax2 )) {
76  sumsin+=w*s;
77  sumcos+=w*c;
78  //For tracking, w=1 and mult is the track multiplicity.
79  //For calorimetors, w is an energy that needs to be subsequently
80  //converted if an multiplicity if needed
81  mult+=w;
82  }
83  }
84 
85  double getAngle(double &ang, double &sv, double &cv){
86  ang = -10;
87  sv = 0;
88  cv = 0;
89  sv = sumsin;
90  cv = sumcos;
91  double q = sv*sv+cv*cv;
92  if(q>0) ang = atan2(sv,cv)/order;
93  return ang;
94  }
95  void reset() {
96  sumsin=0;
97  sumcos=0;
98  mult = 0;
99  }
100  private:
101  string epname;
102  double etamin1;
103  double etamax1;
104 
105  double etamin2;
106  double etamax2;
107  double sumsin;
108  double sumcos;
109  int mult;
110  double order;
111  };
112 
113 
115 
116  virtual void beginJob() ;
117  virtual void produce(edm::Event&, const edm::EventSetup&);
118  virtual void endJob() ;
119 
120  // ----------member data ---------------------------
124  bool useECAL_;
125  bool useHCAL_;
126  bool useTrack_;
128  double minet_;
129  double maxet_;
130  double minpt_;
131  double maxpt_;
132  double minvtx_;
133  double maxvtx_;
134  double dzerr_;
135  double chi2_;
136 
138 };
139 
140 //
141 // constants, enums and typedefs
142 //
143 
144 
145 //
146 // static data member definitions
147 //
148 
149 //
150 // constructors and destructor
151 //
153 {
154 
155 
156  //register your products
157  vtxCollection_ = consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("vtxCollection_"));
158  caloCollection_ = consumes<CaloTowerCollection>(iConfig.getParameter<edm::InputTag>("caloCollection_"));
159  trackCollection_ = consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("trackCollection_"));
160  useECAL_ = iConfig.getUntrackedParameter<bool>("useECAL_",true);
161  useHCAL_ = iConfig.getUntrackedParameter<bool>("useHCAL_",true);
162  useTrack_ = iConfig.getUntrackedParameter<bool>("useTrack",true);
163  useTrackPtWeight_ = iConfig.getUntrackedParameter<bool>("useTrackPtWeight_",true);
164  minet_ = iConfig.getUntrackedParameter<double>("minet_",0.2);
165  maxet_ = iConfig.getUntrackedParameter<double>("maxet_",500.);
166  minpt_ = iConfig.getUntrackedParameter<double>("minpt_",0.3);
167  maxpt_ = iConfig.getUntrackedParameter<double>("maxpt_",2.5);
168  minvtx_ = iConfig.getUntrackedParameter<double>("minvtx_",-50.);
169  maxvtx_ = iConfig.getUntrackedParameter<double>("maxvtx_",50.);
170  dzerr_ = iConfig.getUntrackedParameter<double>("dzerr_",10.);
171  chi2_ = iConfig.getUntrackedParameter<double>("chi2_",40.);
172 
173  storeNames_ = 1;
174  produces<reco::EvtPlaneCollection>("recoLevel");
175  for(int i = 0; i<NumEPNames; i++ ) {
176  rp[i] = new GenPlane(EPNames[i].data(),EPEtaMin1[i],EPEtaMax1[i],EPEtaMin2[i],EPEtaMax2[i],EPOrder[i]);
177  }
178 }
179 
180 
182 {
183 
184  // do anything here that needs to be done at desctruction time
185  // (e.g. close files, deallocate resources etc.)
186 
187 }
188 
189 
190 //
191 // member functions
192 //
193 
194 // ------------ method called to produce the data ------------
195 void
197 {
198  using namespace edm;
199  using namespace reco;
200 
201  int vs_sell;
202  float vzr_sell;
203  //
204  //Get Vertex
205  //
206  edm::Handle<reco::VertexCollection> vertexCollection3;
207  iEvent.getByToken(vtxCollection_,vertexCollection3);
208  const reco::VertexCollection * vertices3 = vertexCollection3.product();
209  vs_sell = vertices3->size();
210  if(vs_sell>0) {
211  vzr_sell = vertices3->begin()->z();
212  } else
213  vzr_sell = -999.9;
214  //
215  for(int i = 0; i<NumEPNames; i++) rp[i]->reset();
216  if(vzr_sell>minvtx_ && vzr_sell<maxvtx_) {
217  //calorimetry part
218 
219  double tower_eta, tower_phi;
220  double tower_energyet, tower_energyet_e, tower_energyet_h;
221  double s1, s2, s13,s23,s14,s24,s15,s25,s16,s26;
222  Handle<CaloTowerCollection> calotower;
223  iEvent.getByToken(caloCollection_,calotower);
224 
225  if(calotower.isValid()){
226 
227  for (CaloTowerCollection::const_iterator j = calotower->begin();j !=calotower->end(); j++) {
228  tower_eta = j->eta();
229  tower_phi = j->phi();
230  tower_energyet_e = j->emEt();
231  tower_energyet_h = j->hadEt();
232  tower_energyet = tower_energyet_e + tower_energyet_h;
233 
234  s1 = sin(2.*tower_phi);
235  s2 = cos(2.*tower_phi);
236  s13 = sin(3.*tower_phi);
237  s23 = cos(3.*tower_phi);
238  s14 = sin(4.*tower_phi);
239  s24 = cos(4.*tower_phi);
240  s15 = sin(5.*tower_phi);
241  s25 = cos(5.*tower_phi);
242  s16 = sin(6.*tower_phi);
243  s26 = cos(6.*tower_phi);
244 
245  if(tower_energyet<minet_) continue;
246  if(tower_energyet>maxet_) continue;;
247 
248  rp[etEcal ]->addParticle (tower_energyet_e, s1, s2, tower_eta);
249  rp[etEcalP ]->addParticle (tower_energyet_e, s1, s2, tower_eta);
250  rp[etEcalM ]->addParticle (tower_energyet_e, s1, s2, tower_eta);
251  rp[etHcal ]->addParticle (tower_energyet_h, s1, s2, tower_eta);
252  rp[etHcalP ]->addParticle (tower_energyet_h, s1, s2, tower_eta);
253  rp[etHcalM ]->addParticle (tower_energyet_h, s1, s2, tower_eta);
254  rp[etHF ]->addParticle (tower_energyet, s1, s2, tower_eta);
255  rp[etHFp ]->addParticle (tower_energyet, s1, s2, tower_eta);
256  rp[etHFm ]->addParticle (tower_energyet, s1, s2, tower_eta);
257  rp[etCaloHFP ]->addParticle (tower_energyet, s1, s2, tower_eta);
258  rp[etCaloHFM ]->addParticle (tower_energyet, s1, s2, tower_eta);
259 
260  rp[etHF3 ]->addParticle (tower_energyet, s13, s23, tower_eta);
261  rp[etHFp3 ]->addParticle (tower_energyet, s13, s23, tower_eta);
262  rp[etHFm3 ]->addParticle (tower_energyet, s13, s23, tower_eta);
263 
264  rp[etHF4 ]->addParticle (tower_energyet, s14, s24, tower_eta);
265  rp[etHFp4 ]->addParticle (tower_energyet, s14, s24, tower_eta);
266  rp[etHFm4 ]->addParticle (tower_energyet, s14, s24, tower_eta);
267 
268  rp[etHF5 ]->addParticle (tower_energyet, s15, s25, tower_eta);
269  rp[etHFp5 ]->addParticle (tower_energyet, s15, s25, tower_eta);
270  rp[etHFm5 ]->addParticle (tower_energyet, s15, s25, tower_eta);
271 
272  rp[etHF6 ]->addParticle (tower_energyet, s16, s26, tower_eta);
273  rp[etHFp6 ]->addParticle (tower_energyet, s16, s26, tower_eta);
274  rp[etHFm6 ]->addParticle (tower_energyet, s16, s26, tower_eta);
275  }
276  }
277  //Tracking part
278 
279  double track_eta;
280  double track_phi;
281  double track_pt;
282 
284  iEvent.getByToken(trackCollection_, tracks);
285 
286  if(tracks.isValid()){
287  for(reco::TrackCollection::const_iterator j = tracks->begin(); j != tracks->end(); j++){
288 
289  //Find possible collections with command line: edmDumpEventContent *.root
290 
292  iEvent.getByToken(vtxCollection_, vertex);
293 
294  // find the vertex point and error
295 
296  math::XYZPoint vtxPoint(0.0,0.0,0.0);
297  double vzErr =0.0, vxErr=0.0, vyErr=0.0;
298  if(vertex->size()>0) {
299  vtxPoint=vertex->begin()->position();
300  vzErr=vertex->begin()->zError();
301  vxErr=vertex->begin()->xError();
302  vyErr=vertex->begin()->yError();
303  }
304  bool accepted = true;
305  bool isPixel = false;
306  // determine if the track is a pixel track
307  if ( j->numberOfValidHits() < 7 ) isPixel = true;
308 
309  // determine the vertex significance
310  double d0=0.0, dz=0.0, d0sigma=0.0, dzsigma=0.0;
311  d0 = -1.*j->dxy(vtxPoint);
312  dz = j->dz(vtxPoint);
313  d0sigma = sqrt(j->d0Error()*j->d0Error()+vxErr*vyErr);
314  dzsigma = sqrt(j->dzError()*j->dzError()+vzErr*vzErr);
315 
316  // cuts for pixel tracks
317  if( isPixel )
318  {
319  // dz significance cut
320  if ( fabs(dz/dzsigma) > dzerr_ ) accepted = false;
321 
322  // chi2/ndof cut
323  if ( j->normalizedChi2() > chi2_ ) accepted = false;
324  }
325 
326  // cuts for full tracks
327  if ( ! isPixel)
328  {
329  // dz and d0 significance cuts
330  if ( fabs(dz/dzsigma) > 3 ) accepted = false;
331  if ( fabs(d0/d0sigma) > 3 ) accepted = false;
332 
333  // pt resolution cut
334  if ( j->ptError()/j->pt() > 0.05 ) accepted = false;
335 
336  // number of valid hits cut
337  if ( j->numberOfValidHits() < 12 ) accepted = false;
338  }
339  if( accepted ) {
340  track_eta = j->eta();
341  track_phi = j->phi();
342  track_pt = j->pt();
343  double s =sin(2*track_phi);
344  double c =cos(2*track_phi);
345  double s3 =sin(3*track_phi);
346  double c3 =cos(3*track_phi);
347  double s4 =sin(4*track_phi);
348  double c4 =cos(4*track_phi);
349  double s5 =sin(5*track_phi);
350  double c5 =cos(5*track_phi);
351  double s6 =sin(6*track_phi);
352  double c6 =cos(6*track_phi);
353  double w = 1;
354  if(useTrackPtWeight_) {
355  w = track_pt;
356  if(w>2.5) w=2.0; //v2 starts decreasing above ~2.5 GeV/c
357  }
358  if(track_pt<minpt_) continue;
359  if(track_pt>maxpt_) continue;
360  rp[EvtPlaneFromTracksMidEta]->addParticle(w,s,c,track_eta);
361  rp[EvtPTracksPosEtaGap]->addParticle(w,s,c,track_eta);
362  rp[EvtPTracksNegEtaGap]->addParticle(w,s,c,track_eta);
363  rp[EPTracksMid3]->addParticle(w,s3,c3,track_eta);
364  rp[EPTracksPos3]->addParticle(w,s3,c3,track_eta);
365  rp[EPTracksNeg3]->addParticle(w,s3,c3,track_eta);
366  rp[EPTracksMid4]->addParticle(w,s4,c4,track_eta);
367  rp[EPTracksPos4]->addParticle(w,s4,c4,track_eta);
368  rp[EPTracksNeg4]->addParticle(w,s4,c4,track_eta);
369  rp[EPTracksMid5]->addParticle(w,s5,c5,track_eta);
370  rp[EPTracksPos5]->addParticle(w,s5,c5,track_eta);
371  rp[EPTracksNeg5]->addParticle(w,s5,c5,track_eta);
372  rp[EPTracksMid6]->addParticle(w,s6,c6,track_eta);
373  rp[EPTracksPos6]->addParticle(w,s6,c6,track_eta);
374  rp[EPTracksNeg6]->addParticle(w,s6,c6,track_eta);
375 
376  }
377 
378  }
379  }
380  }
381  std::auto_ptr<EvtPlaneCollection> evtplaneOutput(new EvtPlaneCollection);
382 
383  EvtPlane *ep[NumEPNames];
384 
385  double ang=-10;
386  double sv = 0;
387  double cv = 0;
388 
389  for(int i = 0; i<NumEPNames; i++) {
390  rp[i]->getAngle(ang,sv,cv);
391  if(storeNames_) ep[i] = new EvtPlane(ang,sv,cv,EPNames[i]);
392  else ep[i] = new EvtPlane(ang,sv,cv,"");
393  }
394  if(useTrack_) {
395  for(int i = 0; i<9; i++) {
396  evtplaneOutput->push_back(*ep[i]);
397  }
398  }
399  for(int i = 9; i<NumEPNames; i++) {
400  if(useECAL_ && !useHCAL_) {
401  if(EPNames[i].rfind("Ecal")!=string::npos) {
402  evtplaneOutput->push_back(*ep[i]);
403  }
404  } else if (useHCAL_ && !useECAL_) {
405  if(EPNames[i].rfind("Hcal")!=string::npos) {
406  evtplaneOutput->push_back(*ep[i]);
407  }
408  }else if (useECAL_ && useHCAL_) {
409  evtplaneOutput->push_back(*ep[i]);
410  }
411  }
412 
413  iEvent.put(evtplaneOutput, "recoLevel");
414  // storeNames_ = 0;
415 }
416 
417  // ------------ method called once each job just before starting event loop ------------
418 void
420 {
421 }
422 
423 // ------------ method called once each job just after ending the event loop ------------
424 void
426 }
427 
428 //define this as a plug-in
double getAngle(double &ang, double &sv, double &cv)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
const int EPOrder[]
int i
Definition: DBlmapReader.cc:9
const double EPEtaMin2[]
GenPlane(string name, double etaminval1, double etamaxval1, double etaminval2, double etamaxval2, int orderval)
edm::EDGetTokenT< reco::VertexCollection > vtxCollection_
const double w
Definition: UKUtility.cc:23
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:446
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
std::vector< CaloTower >::const_iterator const_iterator
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
T eta() const
const std::string EPNames[]
void beginJob()
Definition: Breakpoints.cc:15
tuple s2
Definition: indexGen.py:106
const double EPEtaMin1[]
virtual void endJob()
int iEvent
Definition: GenABIO.cc:230
virtual void beginJob()
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
T sqrt(T t)
Definition: SSEVec.h:48
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
std::vector< EvtPlane > EvtPlaneCollection
Definition: EvtPlane.h:33
virtual void produce(edm::Event &, const edm::EventSetup &)
int j
Definition: DBlmapReader.cc:9
edm::EDGetTokenT< CaloTowerCollection > caloCollection_
EvtPlaneProducer(const edm::ParameterSet &)
bool isValid() const
Definition: HandleBase.h:76
dictionary cv
Definition: cuy.py:362
edm::EDGetTokenT< reco::TrackCollection > trackCollection_
void addParticle(double w, double s, double c, double eta)
tuple tracks
Definition: testEve_cfg.py:39
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
const double EPEtaMax2[]
static const int NumEPNames
void reset(double vett[256])
Definition: TPedValues.cc:11
const double EPEtaMax1[]