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 // system include files
20 #include <memory>
21 #include <string>
22 #include <iostream>
23 
24 // user include files
28 
31 
34 
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&);
51  ~GenHIEventProducer() override;
52 
53 private:
54  void produce(edm::Event&, const edm::EventSetup&) override;
57 
58  double ptCut_;
60 };
61 
62 //
63 // constants, enums and typedefs
64 //
65 
66 //
67 // static data member definitions
68 //
69 
70 //
71 // constructors and destructor
72 //
74  produces<edm::GenHIEvent>();
75  hepmcSrc_ = consumes<CrossingFrame<edm::HepMCProduct> >(iConfig.getParameter<edm::InputTag>("src"));
76  doParticleInfo_ = iConfig.getUntrackedParameter<bool>("doParticleInfo", false);
77  if (doParticleInfo_) {
78  ptCut_ = iConfig.getParameter<double>("ptCut");
79  }
80 }
81 
83  // do anything here that needs to be done at desctruction time
84  // (e.g. close files, deallocate resources etc.)
85 }
86 
87 //
88 // member functions
89 //
90 
91 // ------------ method called to produce the data ------------
93  using namespace edm;
94 
95  if (!(pdt.isValid()))
96  iSetup.getData(pdt);
97 
98  double b = -1;
99  int npart = -1;
100  int ncoll = 0;
101  int nhard = 0;
102  double phi = 0;
103  double ecc = -1;
104 
105  int nCharged = 0;
106  int nChargedMR = 0;
107  int nChargedPtCut = 0; // NchargedPtCut bym
108  int nChargedPtCutMR = 0; // NchargedPtCutMR bym
109 
110  double meanPt = 0;
111  double meanPtMR = 0;
112  double EtMR = 0; // Normalized of total energy bym
113  double TotEnergy = 0; // Total energy bym
114 
116  iEvent.getByToken(hepmcSrc_, hepmc);
118 
119  if (mix.size() < 1) {
120  throw cms::Exception("MatchVtx") << "Mixing has " << mix.size() << " sub-events, should have been at least 1"
121  << endl;
122  }
123 
124  const HepMCProduct& hievt = mix.getObject(mix.size() - 1);
125  const HepMC::GenEvent* evt = hievt.GetEvent();
126  if (doParticleInfo_) {
127  HepMC::GenEvent::particle_const_iterator begin = evt->particles_begin();
128  HepMC::GenEvent::particle_const_iterator end = evt->particles_end();
129  for (HepMC::GenEvent::particle_const_iterator it = begin; it != end; ++it) {
130  if ((*it)->status() != 1)
131  continue;
132  int pdg_id = (*it)->pdg_id();
133  const ParticleData* part = pdt->particle(pdg_id);
134  int charge = static_cast<int>(part->charge());
135 
136  if (charge == 0)
137  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)
157  continue;
158  nChargedMR++;
159  meanPtMR += pt;
160  }
161  }
162  const HepMC::HeavyIon* hi = evt->heavy_ion();
163 
164  if (hi) {
165  ncoll = ncoll + hi->Ncoll();
166  nhard = nhard + hi->Ncoll_hard();
167  int np = hi->Npart_proj() + hi->Npart_targ();
168  if (np >= 0) {
169  npart = np;
170  b = hi->impact_parameter();
171  phi = hi->event_plane_angle();
172  ecc = hi->eccentricity();
173  }
174  }
175 
176  // Get the normalized total energy bym
177  if (TotEnergy != 0) {
178  EtMR = TotEnergy / 2;
179  }
180 
181  if (nChargedMR != 0) {
182  meanPtMR /= nChargedMR;
183  }
184  if (nCharged != 0) {
185  meanPt /= nCharged;
186  }
187 
188  std::unique_ptr<edm::GenHIEvent> pGenHI(new edm::GenHIEvent(
189  b, npart, ncoll, nhard, phi, ecc, nCharged, nChargedMR, meanPt, meanPtMR, EtMR, nChargedPtCut, nChargedPtCutMR));
190 
191  iEvent.put(std::move(pGenHI));
192 }
193 
194 //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:131
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
edm::EDGetTokenT< CrossingFrame< edm::HepMCProduct > > hepmcSrc_
double npart
Definition: HydjetWrapper.h:46
bool getData(T &iHolder) const
Definition: EventSetup.h:113
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
int np
Definition: AMPTWrapper.h:43
void produce(edm::Event &, const edm::EventSetup &) override
#define end
Definition: vmac.h:39
HepPDT::ParticleData ParticleData
edm::ESHandle< ParticleDataTable > pdt
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:34
T const * product() const
Definition: Handle.h:69
part
Definition: HCALResponse.h:20
double b
Definition: hdecay.h:118
#define begin
Definition: vmac.h:32
HLT enums.
~GenHIEventProducer() override
def move(src, dest)
Definition: eostools.py:511
GenHIEventProducer(const edm::ParameterSet &)