23 #include <unordered_map>
27 class ConvertParticle {
30 static constexpr
double mmToCm = 0.1;
43 bool initialized()
const {
return initialized_; }
47 for (HepPDT::ParticleDataTable::const_iterator
p = pdt.begin();
p != pdt.end(); ++
p) {
50 int q3 =
id.threeCharge();
51 if (apdgId < PDGCacheMax && pdgId > 0) {
52 chargeP_[apdgId] = q3;
53 chargeM_[apdgId] = -q3;
55 chargeP_[apdgId] = -q3;
56 chargeM_[apdgId] = q3;
58 chargeMap_.emplace(
pdgId, q3);
59 chargeMap_.emplace(-
pdgId, -q3);
69 cand.setThreeCharge(chargeTimesThree(
pdgId));
73 cand.setCollisionId(0);
74 HepMC::GenVertex
const*
v =
part->production_vertex();
76 HepMC::ThreeVector
vtx =
v->point3d();
86 bool abortOnUnknownPDGCode_;
88 std::vector<int> chargeP_, chargeM_;
89 std::unordered_map<int, int> chargeMap_;
91 int chargeTimesThree(
int id)
const {
93 return id > 0 ? chargeP_[
id] : chargeM_[-
id];
95 auto f = chargeMap_.find(
id);
96 if (
f == chargeMap_.end()) {
97 if (abortOnUnknownPDGCode_)
164 using namespace reco;
166 using namespace HepMC;
169 : abortOnUnknownPDGCode_(
cfg.getUntrackedParameter<
bool>(
"abortOnUnknownPDGCode",
true)),
170 bunchList_(
cfg.getParameter<vector<
int> >(
"bunchCrossingList")),
171 minPz_(
cfg.getParameter<double>(
"minPz")) {
172 produces<GenParticleCollection>();
174 consumes<CrossingFrame<HepMCProduct> >(
InputTag(
cfg.getParameter<
std::string>(
"mix"),
"generatorSmeared"));
183 if (!convert_ptr->initialized())
184 convert_ptr->init(*pdt);
190 size_t totalSize = 0;
196 npiles = cfhepmcprod->size();
198 LogDebug(
"GenPUProtonProducer") <<
" Number of pile-up events : " << npiles << endl;
200 for (
size_t icf = 0; icf < npiles; ++icf) {
201 LogDebug(
"GenPUProtonProducer") <<
"CF " << icf
202 <<
" size : " << cfhepmcprod->getObject(icf).GetEvent()->particles_size() << endl;
203 totalSize += cfhepmcprod->getObject(icf).GetEvent()->particles_size();
205 LogDebug(
"GenPUProtonProducer") <<
"Total size : " << totalSize << endl;
208 auto candsPtr = std::make_unique<GenParticleCollection>();
212 ConvertParticle
const& convertParticle_ = *runCache(evt.
getRun().
index());
215 unsigned int total_number_of_protons = 0;
218 for (mixHepMC_itr = cfhepmcprod->begin(); mixHepMC_itr != cfhepmcprod->end(); ++mixHepMC_itr, ++idx_mix) {
219 int bunch = mixHepMC_itr.
bunch();
222 auto event = (*mixHepMC_itr).GetEvent();
224 size_t num_particles =
event->particles_size();
227 unsigned int number_of_protons = 0;
228 for (
auto p =
event->particles_begin();
p !=
event->particles_end(); ++
p) {
237 LogDebug(
"GenPUProtonProducer") <<
"Idx : " << idx_mix <<
" Bunch : " << bunch
238 <<
" Number of particles : " << num_particles
239 <<
" Number of protons : " << number_of_protons << endl;
241 total_number_of_protons += number_of_protons;
244 LogDebug(
"GenPUProtonProducer") <<
"Total number of protons : " << total_number_of_protons << endl;
245 LogDebug(
"GenPUProtonProducer") <<
"Output collection size : " <<
cands.size() << endl;