CMS 3D CMS Logo

EvtPlaneProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: EvtPlaneProducer
4 // Class: EvtPlaneProducer
5 //
13 //
14 // Original Author: Sergey Petrushanko
15 // Created: Fri Jul 11 10:05:00 2008
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 #include <iostream>
22 #include <ctime>
23 #include <cmath>
24 
25 // user include files
30 
35 
40 
41 
44 
48 
54 #include <cstdlib>
60 
65 
68 
69 using namespace std;
70 using namespace hi;
71 
72 //
73 // class decleration
74 //
75 
76 namespace hi {
77  class GenPlane {
78  public:
79  GenPlane(string name,double etaminval1,double etamaxval1,double etaminval2,double etamaxval2,int orderval){
80  epname=name;
81  etamin1=etaminval1;
82  etamax1=etamaxval1;
83  etamin2=etaminval2;
84  etamax2=etamaxval2;
85  sumsin=0;
86  sumcos=0;
87  sumsinNoWgt=0;
88  sumcosNoWgt=0;
89 
90  mult = 0;
91  order = (double) orderval;
92  }
93  ~GenPlane(){;}
94  void addParticle(double w, double PtOrEt, double s, double c, double eta) {
95  if((eta>=etamin1 && eta<etamax1) ||
96  (etamin2!= etamax2 && eta>=etamin2 && eta<etamax2 )) {
97  sumsin+=w*s;
98  sumcos+=w*c;
99  sumsinNoWgt+=s;
100  sumcosNoWgt+=c;
101 
102  sumw+=fabs(w);
103  sumw2+=w*w;
104  sumPtOrEt+=PtOrEt;
105  sumPtOrEt2+=PtOrEt*PtOrEt;
106  ++mult;
107  }
108  }
109 
110  double getAngle(double &ang, double &sv, double &cv, double &svNoWgt, double &cvNoWgt, double &w, double &w2, double &PtOrEt, double &PtOrEt2, uint &epmult){
111  ang = -10;
112  sv = 0;
113  cv = 0;
114  sv = sumsin;
115  cv = sumcos;
116  svNoWgt = sumsinNoWgt;
117  cvNoWgt = sumcosNoWgt;
118  w = sumw;
119  w2 = sumw2;
120  PtOrEt = sumPtOrEt;
121  PtOrEt2 = sumPtOrEt2;
122  epmult = mult;
123  double q = sv*sv+cv*cv;
124  if(q>0) ang = atan2(sv,cv)/order;
125  return ang;
126  }
127  void reset() {
128  sumsin=0;
129  sumcos=0;
130  sumsinNoWgt = 0;
131  sumcosNoWgt = 0;
132  sumw = 0;
133  sumw2 = 0;
134  mult = 0;
135  sumPtOrEt = 0;
136  sumPtOrEt2 = 0;
137  }
138  private:
139  string epname;
140  double etamin1;
141  double etamax1;
142 
143  double etamin2;
144  double etamax2;
145  double sumsin;
146  double sumcos;
147  double sumsinNoWgt;
148  double sumcosNoWgt;
150  double sumw;
151  double sumw2;
152  double sumPtOrEt;
153  double sumPtOrEt2;
154  double order;
155  };
156 }
157 
159 public:
160  explicit EvtPlaneProducer(const edm::ParameterSet&);
161  ~EvtPlaneProducer() override;
162 
163 private:
165 
166  void produce(edm::Event&, const edm::EventSetup&) override;
167 
168  // ----------member data ---------------------------
169 
173 
176 
177 
181 
185 
189 
193 
196 
197  bool loadDB_;
198  double minet_;
199  double maxet_;
200  double minpt_;
201  double maxpt_;
202  double minvtx_;
203  double maxvtx_;
204  double dzerr_;
205  double chi2_;
208  double nCentBins_;
209  double caloCentRef_;
213 };
214 
216  centralityVariable_ ( iConfig.getParameter<std::string>("centralityVariable") ),
217  centralityBinTag_ ( iConfig.getParameter<edm::InputTag>("centralityBinTag") ),
218  vertexTag_ ( iConfig.getParameter<edm::InputTag>("vertexTag") ),
219  caloTag_ ( iConfig.getParameter<edm::InputTag>("caloTag") ),
220  castorTag_ ( iConfig.getParameter<edm::InputTag>("castorTag") ),
221  trackTag_ ( iConfig.getParameter<edm::InputTag>("trackTag") ),
222  loadDB_ ( iConfig.getParameter<bool>("loadDB") ),
223  minet_ ( iConfig.getParameter<double>("minet") ),
224  maxet_ ( iConfig.getParameter<double>("maxet") ),
225  minpt_ ( iConfig.getParameter<double>("minpt") ),
226  maxpt_ ( iConfig.getParameter<double>("maxpt") ),
227  minvtx_ ( iConfig.getParameter<double>("minvtx") ),
228  maxvtx_ ( iConfig.getParameter<double>("maxvtx") ),
229  dzerr_ ( iConfig.getParameter<double>("dzerr") ),
230  chi2_ ( iConfig.getParameter<double>("chi2") ),
231  FlatOrder_ ( iConfig.getParameter<int>("FlatOrder") ),
232  NumFlatBins_ ( iConfig.getParameter<int>("NumFlatBins") ),
233  caloCentRef_ ( iConfig.getParameter<double>("caloCentRef") ),
234  caloCentRefWidth_ ( iConfig.getParameter<double>("caloCentRefWidth") ),
235  CentBinCompression_ ( iConfig.getParameter<int>("CentBinCompression") )
236 {
237 
238  nCentBins_ = 200.;
239 
240  if(iConfig.exists("nonDefaultGlauberModel")){
241  centralityMC_ = iConfig.getParameter<std::string>("nonDefaultGlauberModel");
242  }
244 
245  centralityBinToken = consumes<int>(centralityBinTag_);
246 
247  vertexToken = consumes<std::vector<reco::Vertex>>(vertexTag_);
248 
249  caloToken = consumes<CaloTowerCollection>(caloTag_);
250 
251  castorToken = consumes<std::vector<reco::CastorTower>>(castorTag_);
252 
253  trackToken = consumes<reco::TrackCollection>(trackTag_);
254 
255  produces<reco::EvtPlaneCollection>();
256  for(int i = 0; i<NumEPNames; i++ ) {
258  }
259  for(int i = 0; i<NumEPNames; i++) {
260  flat[i] = new HiEvtPlaneFlatten();
262  }
263 
264 }
265 
266 
268 {
269 
270  // do anything here that needs to be done at desctruction time
271  // (e.g. close files, deallocate resources etc.)
272  for(int i = 0; i<NumEPNames; i++) {
273  delete flat[i];
274  }
275 
276 }
277 
278 
279 //
280 // member functions
281 //
282 
283 // ------------ method called to produce the data ------------
284 void
286 {
287  using namespace edm;
288  using namespace std;
289  using namespace reco;
290 
291  if( loadDB_ && (hiWatcher.check(iSetup) || hirpWatcher.check(iSetup)) ) {
292  //
293  //Get Size of Centrality Table
294  //
296  iSetup.get<HeavyIonRcd>().get(centralityLabel_,centDB_);
297  nCentBins_ = centDB_->m_table.size();
298  for(int i = 0; i<NumEPNames; i++) {
299  if(caloCentRef_>0) {
300  int minbin = (caloCentRef_-caloCentRefWidth_/2.)*nCentBins_/100.;
301  int maxbin = (caloCentRef_+caloCentRefWidth_/2.)*nCentBins_/100.;
302  minbin/=CentBinCompression_;
303  maxbin/=CentBinCompression_;
304  if(minbin>0 && maxbin>=minbin) {
305  if(EPDet[i]==HF || EPDet[i]==Castor) flat[i]->setCaloCentRefBins(minbin,maxbin);
306  }
307  }
308  }
309 
310  //
311  //Get flattening parameter file.
312  //
313  if ( loadDB_ ) {
314  edm::ESHandle<RPFlatParams> flatparmsDB_;
315  iSetup.get<HeavyIonRPRcd>().get(flatparmsDB_);
316  LoadEPDB db(flatparmsDB_,flat);
317  if(!db.IsSuccess()) {
318  loadDB_ = kFALSE;
319  }
320  }
321 
322  } //rp record change
323 
324  //
325  //Get Centrality
326  //
327  int bin = 0;
328  if(loadDB_) {
329  edm::Handle<int> cbin_;
330  iEvent.getByToken(centralityBinToken, cbin_);
331  int cbin = *cbin_;
332  bin = cbin/CentBinCompression_;
333  }
334  //
335  //Get Vertex
336  //
337  int vs_sell = 0.;
338  float vzr_sell;
340  const reco::VertexCollection * vertices3 = nullptr;
341  if ( vertex_.isValid() ) {
342  vertices3 = vertex_.product();
343  vs_sell = vertices3->size();
344  }
345  if(vs_sell>0) {
346  vzr_sell = vertices3->begin()->z();
347  } else
348  vzr_sell = -999.9;
349  //
350  for(int i = 0; i<NumEPNames; i++) rp[i]->reset();
351  if(vzr_sell<minvtx_ or vzr_sell>maxvtx_) return;
352 
353  //calorimetry part
354 
355  double tower_eta, tower_phi;
356  double tower_energyet, tower_energyet_e, tower_energyet_h;
357 
359 
360  if(caloCollection_.isValid()){
361  for (CaloTowerCollection::const_iterator j = caloCollection_->begin();j !=caloCollection_->end(); j++) {
362  tower_eta = j->eta();
363  tower_phi = j->phi();
364  tower_energyet_e = j->emEt();
365  tower_energyet_h = j->hadEt();
366  tower_energyet = tower_energyet_e + tower_energyet_h;
367  double minet = minet_;
368  double maxet = maxet_;
369  for(int i = 0; i<NumEPNames; i++) {
370  if(minet_<0) minet = minTransverse[i];
371  if(maxet_<0) maxet = maxTransverse[i];
372  if(tower_energyet<minet) continue;
373  if(tower_energyet>maxet) continue;
374  if(EPDet[i]==HF) {
375  double w = tower_energyet;
376  if(loadDB_) w = tower_energyet*flat[i]->getEtScale(vzr_sell,bin);
377  if(EPOrder[i]==1 ) {
378  if(MomConsWeight[i][0]=='y' && loadDB_ ) {
379  w = flat[i]->getW(tower_energyet, vzr_sell, bin);
380  }
381  if(tower_eta<0 ) w=-w;
382  }
383  rp[i]->addParticle(w,tower_energyet,sin(EPOrder[i]*tower_phi),cos(EPOrder[i]*tower_phi),tower_eta);
384  }
385  }
386  }
387  }
388 
389  //Castor part
390 
391 
393 
395  for (std::vector<reco::CastorTower>::const_iterator j = castorCollection_->begin();j !=castorCollection_->end(); j++) {
396  tower_eta = j->eta();
397  tower_phi = j->phi();
398  tower_energyet = j->et();
399  double minet = minet_;
400  double maxet = maxet_;
401  for(int i = 0; i<NumEPNames; i++) {
402  if(EPDet[i]==Castor) {
403  if(minet_<0) minet = minTransverse[i];
404  if(maxet_<0) maxet = maxTransverse[i];
405  if(tower_energyet<minet) continue;
406  if(tower_energyet>maxet) continue;
407  double w = tower_energyet;
408  if(EPOrder[i]==1 ) {
409  if(MomConsWeight[i][0]=='y' && loadDB_ ) {
410  w = flat[i]->getW(tower_energyet, vzr_sell, bin);
411  }
412  if(tower_eta<0 ) w=-w;
413  }
414  rp[i]->addParticle(w,tower_energyet,sin(EPOrder[i]*tower_phi),cos(EPOrder[i]*tower_phi),tower_eta);
415  }
416  }
417  }
418  }
419 
420  //Tracking part
421 
422  double track_eta;
423  double track_phi;
424  double track_pt;
425 
426  double vzErr2 =0.0, vxyErr=0.0;
427  math::XYZPoint vtxPoint(0.0,0.0,0.0);
428  if(vertex_.isValid() && !vertex_->empty()) {
429  vtxPoint=vertex_->begin()->position();
430  vzErr2= (vertex_->begin()->zError())*(vertex_->begin()->zError());
431  vxyErr=vertex_->begin()->xError() * vertex_->begin()->yError();
432  }
433 
436  for(reco::TrackCollection::const_iterator j = trackCollection_->begin(); j != trackCollection_->end(); j++){
437  bool accepted = true;
438  bool isPixel = false;
439  // determine if the track is a pixel track
440  if ( j->numberOfValidHits() < 7 ) isPixel = true;
441 
442  // determine the vertex significance
443  double d0=0.0, dz=0.0, d0sigma=0.0, dzsigma=0.0;
444  d0 = -1.*j->dxy(vtxPoint);
445  dz = j->dz(vtxPoint);
446  d0sigma = sqrt(j->d0Error()*j->d0Error()+vxyErr);
447  dzsigma = sqrt(j->dzError()*j->dzError()+vzErr2);
448 
449  // cuts for pixel tracks
450  if( isPixel ){
451  // dz significance cut
452  if ( fabs(dz/dzsigma) > dzerr_ ) accepted = false;
453  // chi2/ndof cut
454  if ( j->normalizedChi2() > chi2_ ) accepted = false;
455  }
456  // cuts for full tracks
457  if ( ! isPixel) {
458  // dz and d0 significance cuts
459  if ( fabs(dz/dzsigma) > 3 ) accepted = false;
460  if ( fabs(d0/d0sigma) > 3 ) accepted = false;
461  // pt resolution cut
462  if ( j->ptError()/j->pt() > 0.1 ) accepted = false;
463  // number of valid hits cut
464  if ( j->numberOfValidHits() < 12 ) accepted = false;
465  }
466  if( accepted ) {
467  track_eta = j->eta();
468  track_phi = j->phi();
469  track_pt = j->pt();
470  double minpt = minpt_;
471  double maxpt = maxpt_;
472  for(int i = 0; i<NumEPNames; i++) {
473  if(minpt_<0) minpt = minTransverse[i];
474  if(maxpt_<0) maxpt = maxTransverse[i];
475  if(track_pt<minpt) continue;
476  if(track_pt>maxpt) continue;
477  if(EPDet[i]==Tracker) {
478  double w = track_pt;
479  if(w>2.5) w=2.0; //v2 starts decreasing above ~2.5 GeV/c
480  if(EPOrder[i]==1) {
481  if(MomConsWeight[i][0]=='y' && loadDB_) {
482  w = flat[i]->getW(track_pt, vzr_sell, bin);
483  }
484  if(track_eta<0) w=-w;
485  }
486  rp[i]->addParticle(w,track_pt,sin(EPOrder[i]*track_phi),cos(EPOrder[i]*track_phi),track_eta);
487  }
488  }
489  }
490  } //end for
491  }
492 
493  auto evtplaneOutput = std::make_unique<EvtPlaneCollection>();
494 
495  double ang=-10;
496  double sv = 0;
497  double cv = 0;
498  double svNoWgt = 0;
499  double cvNoWgt = 0;
500 
501  double wv = 0;
502  double wv2 = 0;
503  double pe = 0;
504  double pe2 = 0;
505  uint epmult = 0;
506 
507  for(int i = 0; i<NumEPNames; i++) {
508  rp[i]->getAngle(ang,sv,cv,svNoWgt, cvNoWgt, wv,wv2,pe,pe2,epmult);
509  evtplaneOutput->push_back( EvtPlane(i,0,ang,sv,cv,wv,wv2,pe,pe2,epmult) );
510  evtplaneOutput->back().addLevel(3, 0., svNoWgt, cvNoWgt);
511  }
512 
513  iEvent.put(std::move(evtplaneOutput));
514 }
515 
516 //define this as a plug-in
void init(int order, int nbins, std::string tag, int vord)
edm::InputTag centralityBinTag_
std::string centralityLabel_
T getParameter(std::string const &) const
const int EPOrder[]
const double EPEtaMin2[]
edm::Handle< CaloTowerCollection > caloCollection_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
std::vector< CBin > m_table
const int EPDet[]
common ppss p3p6s2 common epss epspn46 common const1 w2
Definition: inclppp.h:1
edm::Handle< reco::TrackCollection > trackCollection_
edm::InputTag caloTag_
const double w
Definition: UKUtility.cc:23
std::string centralityMC_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
bool IsSuccess()
Definition: LoadEPDB.h:109
edm::ESWatcher< HeavyIonRcd > hiWatcher
#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
bool exists(std::string const &parameterName) const
checks if a parameter exists
void setCaloCentRefBins(const int caloCentRefMinBin, const int caloCentRefMaxBin)
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
cv
Definition: cuy.py:364
edm::EDGetTokenT< int > centralityBinToken
edm::EDGetTokenT< std::vector< reco::CastorTower > > castorToken
const std::string EPNames[]
const double maxTransverse[]
void produce(edm::Event &, const edm::EventSetup &) override
double getEtScale(double vtx, int centbin) const
const double EPEtaMin1[]
edm::ESWatcher< HeavyIonRPRcd > hirpWatcher
int iEvent
Definition: GenABIO.cc:230
const std::string MomConsWeight[]
GenPlane * rp[NumEPNames]
T sqrt(T t)
Definition: SSEVec.h:18
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
HiEvtPlaneFlatten * flat[NumEPNames]
void addParticle(double w, double PtOrEt, double s, double c, double eta)
edm::EDGetTokenT< std::vector< reco::Vertex > > vertexToken
GenPlane(string name, double etaminval1, double etamaxval1, double etaminval2, double etamaxval2, int orderval)
edm::InputTag vertexTag_
EvtPlaneProducer(const edm::ParameterSet &)
bool isValid() const
Definition: HandleBase.h:74
edm::EDGetTokenT< reco::TrackCollection > trackToken
edm::Handle< std::vector< reco::CastorTower > > castorCollection_
bin
set the eta bin as selection string.
std::string centralityVariable_
double getW(double pt, double vtx, int centbin) const
T const * product() const
Definition: Handle.h:81
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
def uint(string)
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
~EvtPlaneProducer() override
fixed size matrix
HLT enums.
T get() const
Definition: EventSetup.h:62
bool isPixel(HitType hitType)
const double EPEtaMax2[]
static const int NumEPNames
edm::EDGetTokenT< CaloTowerCollection > caloToken
double getAngle(double &ang, double &sv, double &cv, double &svNoWgt, double &cvNoWgt, double &w, double &w2, double &PtOrEt, double &PtOrEt2, uint &epmult)
void reset(double vett[256])
Definition: TPedValues.cc:11
edm::InputTag castorTag_
const double EPEtaMax1[]
def move(src, dest)
Definition: eostools.py:511
edm::Handle< std::vector< reco::Vertex > > vertex_
const double minTransverse[]
edm::InputTag trackTag_