CMS 3D CMS Logo

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 
39 
40 #include "HepMC/HeavyIon.h"
43 using namespace std;
44 
45 //
46 // class decleration
47 //
48 
50  public:
51  explicit GenHIEventProducer(const edm::ParameterSet&);
52  ~GenHIEventProducer() override;
53 
54  private:
55  void produce(edm::Event&, const edm::EventSetup&) override;
58 
59  double ptCut_;
61 };
62 
63 //
64 // constants, enums and typedefs
65 //
66 
67 
68 //
69 // static data member definitions
70 //
71 
72 //
73 // constructors and destructor
74 //
76 {
77  produces<edm::GenHIEvent>();
78  hepmcSrc_ = consumes<CrossingFrame<edm::HepMCProduct> >(iConfig.getParameter<edm::InputTag>("src"));
79  doParticleInfo_ = iConfig.getUntrackedParameter<bool>("doParticleInfo",false);
80  if(doParticleInfo_){
81  ptCut_ = iConfig.getParameter<double> ("ptCut");
82  }
83 }
84 
85 
87 {
88 
89  // do anything here that needs to be done at desctruction time
90  // (e.g. close files, deallocate resources etc.)
91 
92 }
93 
94 
95 //
96 // member functions
97 //
98 
99 // ------------ method called to produce the data ------------
100  void
102 {
103  using namespace edm;
104 
105  if(!(pdt.isValid())) iSetup.getData(pdt);
106 
107  double b = -1;
108  int npart = -1;
109  int ncoll = 0;
110  int nhard = 0;
111  double phi = 0;
112  double ecc = -1;
113 
114  int nCharged = 0;
115  int nChargedMR = 0;
116  int nChargedPtCut = 0; // NchargedPtCut bym
117  int nChargedPtCutMR = 0; // NchargedPtCutMR bym
118 
119  double meanPt = 0;
120  double meanPtMR = 0;
121  double EtMR = 0; // Normalized of total energy bym
122  double TotEnergy = 0; // Total energy bym
123 
125  iEvent.getByToken(hepmcSrc_,hepmc);
127 
128  if(mix.size() < 1){
129  throw cms::Exception("MatchVtx")
130  <<"Mixing has "<<mix.size()<<" sub-events, should have been at least 1"
131  <<endl;
132  }
133 
134  const HepMCProduct& hievt = mix.getObject(mix.size()-1);
135  const HepMC::GenEvent* evt = hievt.GetEvent();
136  if(doParticleInfo_){
137  HepMC::GenEvent::particle_const_iterator begin = evt->particles_begin();
138  HepMC::GenEvent::particle_const_iterator end = evt->particles_end();
139  for(HepMC::GenEvent::particle_const_iterator it = begin; it != end; ++it){
140  if((*it)->status() != 1) continue;
141  int pdg_id = (*it)->pdg_id();
142  const ParticleData * part = pdt->particle(pdg_id );
143  int charge = static_cast<int>(part->charge());
144 
145  if(charge == 0) continue;
146  float pt = (*it)->momentum().perp();
147  float eta = (*it)->momentum().eta();
148  float energy = (*it)->momentum().e(); // energy bym
149  //float energy = (*it)->momentum().energy(); // energy bym
150  nCharged++;
151  meanPt += pt;
152  // Get the total energy bym
153  if(fabs(eta)<1.0){
154  TotEnergy += energy;
155  }
156  if(pt>ptCut_){
157  nChargedPtCut++;
158  if(fabs(eta)<0.5){
159  nChargedPtCutMR++;
160  }
161  }
162  // end bym
163 
164  if(fabs(eta) > 0.5) continue;
165  nChargedMR++;
166  meanPtMR += pt;
167  }
168  }
169  const HepMC::HeavyIon* hi = evt->heavy_ion();
170 
171  if(hi){
172  ncoll = ncoll + hi->Ncoll();
173  nhard = nhard + hi->Ncoll_hard();
174  int np = hi->Npart_proj() + hi->Npart_targ();
175  if(np >= 0){
176  npart = np;
177  b = hi->impact_parameter();
178  phi = hi->event_plane_angle();
179  ecc = hi->eccentricity();
180  }
181  }
182 
183  // Get the normalized total energy bym
184  if(TotEnergy != 0){
185  EtMR = TotEnergy/2;
186  }
187 
188  if(nChargedMR != 0){
189  meanPtMR /= nChargedMR;
190  }
191  if(nCharged != 0){
192  meanPt /= nCharged;
193  }
194 
195  std::unique_ptr<edm::GenHIEvent> pGenHI(new edm::GenHIEvent(b,
196  npart,
197  ncoll,
198  nhard,
199  phi,
200  ecc,
201  nCharged,
202  nChargedMR,
203  meanPt,
204  meanPtMR,
205  EtMR,
206  nChargedPtCut,
207  nChargedPtCutMR
208  ));
209 
210  iEvent.put(std::move(pGenHI));
211 
212 }
213 
214 //define this as a plug-in
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
edm::EDGetTokenT< CrossingFrame< edm::HepMCProduct > > hepmcSrc_
edm::ESHandle< ParticleDataTable > pdt
double npart
Definition: HydjetWrapper.h:49
bool getData(T &iHolder) const
Definition: EventSetup.h:111
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
int np
Definition: AMPTWrapper.h:33
void produce(edm::Event &, const edm::EventSetup &) override
#define end
Definition: vmac.h:39
HepPDT::ParticleData ParticleData
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:38
T const * product() const
Definition: Handle.h:74
part
Definition: HCALResponse.h:20
double b
Definition: hdecay.h:120
#define begin
Definition: vmac.h:32
HLT enums.
~GenHIEventProducer() override
def move(src, dest)
Definition: eostools.py:511
GenHIEventProducer(const edm::ParameterSet &)