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 
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 = default;
53 
54 private:
55  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
59 
60  double ptCut_;
61  const bool doParticleInfo_;
62 };
63 
64 //
65 // constructors and destructor
66 //
68  : hepmcSrc_(consumes<CrossingFrame<edm::HepMCProduct> >(iConfig.getParameter<edm::InputTag>("src"))),
69  pdtToken_(esConsumes<ParticleDataTable, edm::DefaultRecord>()),
70  putToken_(produces<edm::GenHIEvent>()),
71  doParticleInfo_(iConfig.getUntrackedParameter<bool>("doParticleInfo", false)) {
72  if (doParticleInfo_) {
73  ptCut_ = iConfig.getParameter<double>("ptCut");
74  }
75 }
76 
77 //
78 // member functions
79 //
80 
81 // ------------ method called to produce the data ------------
83  using namespace edm;
84 
85  const auto& pdt = iSetup.getData(pdtToken_);
86 
87  double b = -1;
88  int npart = -1;
89  int ncoll = 0;
90  int nhard = 0;
91  double phi = 0;
92  double ecc = -1;
93 
94  int nCharged = 0;
95  int nChargedMR = 0;
96  int nChargedPtCut = 0; // NchargedPtCut bym
97  int nChargedPtCutMR = 0; // NchargedPtCutMR bym
98 
99  double meanPt = 0;
100  double meanPtMR = 0;
101  double EtMR = 0; // Normalized of total energy bym
102  double TotEnergy = 0; // Total energy bym
103 
104  const auto& hepmc = iEvent.get(hepmcSrc_);
106 
107  if (mix.size() < 1) {
108  throw cms::Exception("MatchVtx") << "Mixing has " << mix.size() << " sub-events, should have been at least 1"
109  << endl;
110  }
111 
112  const HepMCProduct& hievt = mix.getObject(mix.size() - 1);
113  const HepMC::GenEvent* evt = hievt.GetEvent();
114  if (doParticleInfo_) {
115  HepMC::GenEvent::particle_const_iterator begin = evt->particles_begin();
116  HepMC::GenEvent::particle_const_iterator end = evt->particles_end();
117  for (HepMC::GenEvent::particle_const_iterator it = begin; it != end; ++it) {
118  if ((*it)->status() != 1)
119  continue;
120  int pdg_id = (*it)->pdg_id();
121  const ParticleData* part = pdt.particle(pdg_id);
122  int charge = static_cast<int>(part->charge());
123 
124  if (charge == 0)
125  continue;
126  float pt = (*it)->momentum().perp();
127  float eta = (*it)->momentum().eta();
128  float energy = (*it)->momentum().e(); // energy bym
129  //float energy = (*it)->momentum().energy(); // energy bym
130  nCharged++;
131  meanPt += pt;
132  // Get the total energy bym
133  if (fabs(eta) < 1.0) {
134  TotEnergy += energy;
135  }
136  if (pt > ptCut_) {
137  nChargedPtCut++;
138  if (fabs(eta) < 0.5) {
139  nChargedPtCutMR++;
140  }
141  }
142  // end bym
143 
144  if (fabs(eta) > 0.5)
145  continue;
146  nChargedMR++;
147  meanPtMR += pt;
148  }
149  }
150  const HepMC::HeavyIon* hi = evt->heavy_ion();
151 
152  if (hi) {
153  ncoll = ncoll + hi->Ncoll();
154  nhard = nhard + hi->Ncoll_hard();
155  int np = hi->Npart_proj() + hi->Npart_targ();
156  if (np >= 0) {
157  npart = np;
158  b = hi->impact_parameter();
159  phi = hi->event_plane_angle();
160  ecc = hi->eccentricity();
161  }
162  }
163 
164  // Get the normalized total energy bym
165  if (TotEnergy != 0) {
166  EtMR = TotEnergy / 2;
167  }
168 
169  if (nChargedMR != 0) {
170  meanPtMR /= nChargedMR;
171  }
172  if (nCharged != 0) {
173  meanPt /= nCharged;
174  }
175 
176  iEvent.emplace(putToken_,
177  b,
178  npart,
179  ncoll,
180  nhard,
181  phi,
182  ecc,
183  nCharged,
184  nChargedMR,
185  meanPt,
186  meanPtMR,
187  EtMR,
188  nChargedPtCut,
189  nChargedPtCutMR);
190 }
191 
192 //define this as a plug-in
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
HepPDT::ParticleDataTable ParticleDataTable
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
double npart
Definition: HydjetWrapper.h:46
const edm::ESGetToken< ParticleDataTable, edm::DefaultRecord > pdtToken_
const edm::EDPutTokenT< edm::GenHIEvent > putToken_
const edm::EDGetTokenT< CrossingFrame< edm::HepMCProduct > > hepmcSrc_
int iEvent
Definition: GenABIO.cc:224
int np
Definition: AMPTWrapper.h:43
Definition: EPCuts.h:4
bool getData(T &iHolder) const
Definition: EventSetup.h:122
HepPDT::ParticleData ParticleData
part
Definition: HCALResponse.h:20
double b
Definition: hdecay.h:118
HLT enums.
GenHIEventProducer(const edm::ParameterSet &)