CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GenHIEventProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: GenHIEventProducer
4 // Class: GenHIEventProducer
5 //
13 //
14 // Original Author: Yetkin Yilmaz
15 // Created: Thu Aug 13 08:39:51 EDT 2009
16 //
17 //
18 
19 
20 // system include files
21 #include <memory>
22 #include <string>
23 #include <iostream>
24 
25 // user include files
29 
32 
35 
38 
39 #include "HepMC/HeavyIon.h"
42 using namespace std;
43 
44 //
45 // class decleration
46 //
47 
49  public:
50  explicit GenHIEventProducer(const edm::ParameterSet&);
52 
53  private:
54  virtual void produce(edm::Event&, const edm::EventSetup&) override;
55  std::vector<std::string> hepmcSrc_;
57 
58  double ptCut_;
60 };
61 
62 //
63 // constants, enums and typedefs
64 //
65 
66 
67 //
68 // static data member definitions
69 //
70 
71 //
72 // constructors and destructor
73 //
75 {
76  produces<edm::GenHIEvent>();
77  hepmcSrc_ = iConfig.getParameter<std::vector<std::string> >("generators");
78  doParticleInfo_ = iConfig.getUntrackedParameter<bool>("doParticleInfo",false);
79  if(doParticleInfo_){
80  ptCut_ = iConfig.getUntrackedParameter<double> ("ptCut",1.);
81  }
82 }
83 
84 
86 {
87 
88  // do anything here that needs to be done at desctruction time
89  // (e.g. close files, deallocate resources etc.)
90 
91 }
92 
93 
94 //
95 // member functions
96 //
97 
98 // ------------ method called to produce the data ------------
99  void
101 {
102  using namespace edm;
103 
104  if(!(pdt.isValid())) iSetup.getData(pdt);
105 
106  double b = -1;
107  int npart = -1;
108  int ncoll = 0;
109  int nhard = 0;
110  double phi = 0;
111  double ecc = -1;
112 
113  int nCharged = 0;
114  int nChargedMR = 0;
115  int nChargedPtCut = 0; // NchargedPtCut bym
116  int nChargedPtCutMR = 0; // NchargedPtCutMR bym
117 
118  double meanPt = 0;
119  double meanPtMR = 0;
120  double EtMR = 0; // Normalized of total energy bym
121  double TotEnergy = 0; // Total energy bym
122 
123  for(size_t ihep = 0; ihep < hepmcSrc_.size(); ++ihep){
125  iEvent.getByLabel(hepmcSrc_[ihep],hepmc);
126 
127  const HepMC::GenEvent* evt = hepmc->GetEvent();
128  if(doParticleInfo_){
129  HepMC::GenEvent::particle_const_iterator begin = evt->particles_begin();
130  HepMC::GenEvent::particle_const_iterator end = evt->particles_end();
131  for(HepMC::GenEvent::particle_const_iterator it = begin; it != end; ++it){
132  if((*it)->status() != 1) continue;
133  int pdg_id = (*it)->pdg_id();
134  const ParticleData * part = pdt->particle(pdg_id );
135  int charge = static_cast<int>(part->charge());
136 
137  if(charge == 0) continue;
138  float pt = (*it)->momentum().perp();
139  float eta = (*it)->momentum().eta();
140  float energy = (*it)->momentum().e(); // energy bym
141  //float energy = (*it)->momentum().energy(); // energy bym
142  nCharged++;
143  meanPt += pt;
144  // Get the total energy bym
145  if(fabs(eta)<1.0){
146  TotEnergy += energy;
147  }
148  if(pt>ptCut_){
149  nChargedPtCut++;
150  if(fabs(eta)<0.5){
151  nChargedPtCutMR++;
152  }
153  }
154  // end bym
155 
156  if(fabs(eta) > 0.5) continue;
157  nChargedMR++;
158  meanPtMR += pt;
159  }
160  }
161  const HepMC::HeavyIon* hi = evt->heavy_ion();
162 
163  if(hi){
164  ncoll = ncoll + hi->Ncoll();
165  nhard = nhard + hi->Ncoll_hard();
166  int np = hi->Npart_proj() + hi->Npart_targ();
167  if(np >= 0){
168  npart = np;
169  b = hi->impact_parameter();
170  phi = hi->event_plane_angle();
171  ecc = hi->eccentricity();
172  }
173  }
174  }
175  // Get the normalized total energy bym
176  if(TotEnergy != 0){
177  EtMR = TotEnergy/2;
178  }
179 
180  if(nChargedMR != 0){
181  meanPtMR /= nChargedMR;
182  }
183  if(nCharged != 0){
184  meanPt /= nCharged;
185  }
186 
187  std::auto_ptr<edm::GenHIEvent> pGenHI(new edm::GenHIEvent(b,
188  npart,
189  ncoll,
190  nhard,
191  phi,
192  ecc,
193  nCharged,
194  nChargedMR,
195  meanPt,
196  meanPtMR,
197  EtMR,
198  nChargedPtCut,
199  nChargedPtCutMR
200  ));
201 
202  iEvent.put(pGenHI);
203 
204 }
205 
206 //define this as a plug-in
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
edm::ESHandle< ParticleDataTable > pdt
double npart
Definition: HydjetWrapper.h:49
void getData(T &iHolder) const
Definition: EventSetup.h:79
int iEvent
Definition: GenABIO.cc:230
int np
Definition: AMPTWrapper.h:33
virtual void produce(edm::Event &, const edm::EventSetup &) override
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
std::vector< std::string > hepmcSrc_
#define end
Definition: vmac.h:37
HepPDT::ParticleData ParticleData
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:418
unsigned int nCharged(const GenJet &jet)
part
Definition: HCALResponse.h:20
double b
Definition: hdecay.h:120
Geom::Phi< T > phi() const
#define begin
Definition: vmac.h:30
GenHIEventProducer(const edm::ParameterSet &)