23 #include <unordered_map> 27 class ConvertParticle {
33 : abortOnUnknownPDGCode_(
true), initialized_(
false), chargeP_(PDGCacheMax, 0), chargeM_(PDGCacheMax, 0){};
35 ConvertParticle(
bool abortOnUnknownPDGCode)
36 : abortOnUnknownPDGCode_(abortOnUnknownPDGCode),
38 chargeP_(PDGCacheMax, 0),
39 chargeM_(PDGCacheMax, 0){};
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;
54 }
else if (apdgId < PDGCacheMax) {
55 chargeP_[apdgId] = -q3;
56 chargeM_[apdgId] = q3;
58 chargeMap_.emplace(pdgId, q3);
59 chargeMap_.emplace(-pdgId, -q3);
68 int pdgId = part->pdg_id();
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_)
109 bool selection = ((!part->end_vertex() && part->status() == 1) && (part->pdg_id() == 2212) &&
110 (
TMath::Abs(part->momentum().pz()) >= minPz));
165 using namespace reco;
167 using namespace HepMC;
170 : abortOnUnknownPDGCode_(cfg.getUntrackedParameter<
bool>(
"abortOnUnknownPDGCode",
true)),
171 bunchList_(cfg.getParameter<vector<
int> >(
"bunchCrossingList")),
172 minPz_(cfg.getParameter<double>(
"minPz")) {
173 produces<GenParticleCollection>();
184 if (!convert_ptr->initialized())
185 convert_ptr->init(*pdt);
191 size_t totalSize = 0;
197 npiles = cfhepmcprod->size();
199 LogDebug(
"GenPUProtonProducer") <<
" Number of pile-up events : " << npiles << endl;
201 for (
size_t icf = 0; icf < npiles; ++icf) {
202 LogDebug(
"GenPUProtonProducer") <<
"CF " << icf
203 <<
" size : " << cfhepmcprod->getObject(icf).GetEvent()->particles_size() << endl;
204 totalSize += cfhepmcprod->getObject(icf).GetEvent()->particles_size();
206 LogDebug(
"GenPUProtonProducer") <<
"Total size : " << totalSize << endl;
209 auto candsPtr = std::make_unique<GenParticleCollection>();
213 ConvertParticle
const& convertParticle_ = *runCache(evt.
getRun().
index());
216 unsigned int total_number_of_protons = 0;
219 for (mixHepMC_itr = cfhepmcprod->begin(); mixHepMC_itr != cfhepmcprod->end(); ++mixHepMC_itr, ++idx_mix) {
220 int bunch = mixHepMC_itr.
bunch();
223 auto event = (*mixHepMC_itr).GetEvent();
225 size_t num_particles =
event->particles_size();
228 unsigned int number_of_protons = 0;
229 for (
auto p =
event->particles_begin();
p !=
event->particles_end(); ++
p) {
233 convertParticle_(cand, part);
235 cands.push_back(cand);
238 LogDebug(
"GenPUProtonProducer") <<
"Idx : " << idx_mix <<
" Bunch : " << bunch
239 <<
" Number of particles : " << num_particles
240 <<
" Number of protons : " << number_of_protons << endl;
242 total_number_of_protons += number_of_protons;
245 LogDebug(
"GenPUProtonProducer") <<
"Total number of protons : " << total_number_of_protons << endl;
246 LogDebug(
"GenPUProtonProducer") <<
"Output collection size : " << cands.size() << endl;
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
T getParameter(std::string const &) const
std::shared_ptr< ConvertParticle > globalBeginRun(const edm::Run &, const edm::EventSetup &) const override
std::vector< int > bunchList_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
edm::EDGetTokenT< CrossingFrame< edm::HepMCProduct > > mixToken_
void setCollisionId(int s)
HepPDT::ParticleDataTable ParticleDataTable
bool getByToken(EDGetToken token, Handle< PROD > &result) const
void produce(edm::StreamID, edm::Event &e, const edm::EventSetup &) const override
Run const & getRun() const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
void setVertex(const Point &vertex) override
set vertex
bool getData(T &iHolder) const
#define DEFINE_FWK_MODULE(type)
~GenPUProtonProducer() override
bool abortOnUnknownPDGCode_
Abs< T >::type abs(const T &t)
GenPUProtonProducer(const edm::ParameterSet &)
T const * product() const
void setThreeCharge(Charge qx3) final
set electric charge
static const double mmToCm
math::XYZTLorentzVector LorentzVector
Lorentz vector.
math::XYZPoint Point
point in the space
void setStatus(int status) final
set status word
void setPdgId(int pdgId) final
void setP4(const LorentzVector &p4) final
set 4-momentum