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