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