24 #include <unordered_map>
28 class ConvertParticle {
31 static constexpr
double mmToCm = 0.1;
36 ConvertParticle(
bool abortOnUnknownPDGCode)
37 : abortOnUnknownPDGCode_(abortOnUnknownPDGCode),
44 bool initialized()
const {
return initialized_; }
48 for (HepPDT::ParticleDataTable::const_iterator
p = pdt.begin();
p != pdt.end(); ++
p) {
49 HepPDT::ParticleID
const&
id =
p->first;
50 int pdgId =
id.pid(), apdgId =
std::abs(pdgId);
51 int q3 =
id.threeCharge();
52 if (apdgId < PDGCacheMax && pdgId > 0) {
53 chargeP_[apdgId] = q3;
54 chargeM_[apdgId] = -q3;
56 chargeP_[apdgId] = -q3;
57 chargeM_[apdgId] = q3;
59 chargeMap_.emplace(pdgId, q3);
60 chargeMap_.emplace(-pdgId, -q3);
69 int pdgId = part->pdg_id();
75 HepMC::GenVertex
const*
v = part->production_vertex();
77 HepMC::ThreeVector vtx = v->point3d();
87 bool abortOnUnknownPDGCode_;
89 std::vector<int> chargeP_, chargeM_;
90 std::unordered_map<int, int> chargeMap_;
92 int chargeTimesThree(
int id)
const {
94 return id > 0 ? chargeP_[
id] : chargeM_[-
id];
96 auto f = chargeMap_.find(
id);
97 if (
f == chargeMap_.end()) {
98 if (abortOnUnknownPDGCode_)
101 return HepPDT::ParticleID(
id).threeCharge();
110 bool selection = ((!part->end_vertex() && part->status() == 1) && (part->pdg_id() == 2212) &&
111 (
TMath::Abs(part->momentum().pz()) >= minPz));
166 using namespace reco;
168 using namespace HepMC;
171 : abortOnUnknownPDGCode_(cfg.getUntrackedParameter<bool>(
"abortOnUnknownPDGCode",
true)),
172 bunchList_(cfg.getParameter<
vector<int> >(
"bunchCrossingList")),
173 minPz_(cfg.getParameter<double>(
"minPz")) {
174 produces<GenParticleCollection>();
177 pdtToken_ = esConsumes<HepPDT::ParticleDataTable, edm::DefaultRecord, edm::Transition::BeginRun>();
185 if (!convert_ptr->initialized())
186 convert_ptr->init(*pdt);
192 size_t totalSize = 0;
198 npiles = cfhepmcprod->size();
200 LogDebug(
"GenPUProtonProducer") <<
" Number of pile-up events : " << npiles << endl;
202 for (
size_t icf = 0; icf < npiles; ++icf) {
203 LogDebug(
"GenPUProtonProducer") <<
"CF " << icf
204 <<
" size : " << cfhepmcprod->getObject(icf).GetEvent()->particles_size() << endl;
205 totalSize += cfhepmcprod->getObject(icf).GetEvent()->particles_size();
207 LogDebug(
"GenPUProtonProducer") <<
"Total size : " << totalSize << endl;
210 auto candsPtr = std::make_unique<GenParticleCollection>();
214 ConvertParticle
const& convertParticle_ = *runCache(evt.
getRun().
index());
217 unsigned int total_number_of_protons = 0;
220 for (mixHepMC_itr = cfhepmcprod->begin(); mixHepMC_itr != cfhepmcprod->end(); ++mixHepMC_itr, ++idx_mix) {
221 int bunch = mixHepMC_itr.
bunch();
224 auto event = (*mixHepMC_itr).GetEvent();
226 size_t num_particles =
event->particles_size();
229 unsigned int number_of_protons = 0;
230 for (
auto p =
event->particles_begin();
p !=
event->particles_end(); ++
p) {
234 convertParticle_(cand, part);
236 cands.push_back(cand);
239 LogDebug(
"GenPUProtonProducer") <<
"Idx : " << idx_mix <<
" Bunch : " << bunch
240 <<
" Number of particles : " << num_particles
241 <<
" Number of protons : " << number_of_protons << endl;
243 total_number_of_protons += number_of_protons;
246 LogDebug(
"GenPUProtonProducer") <<
"Total number of protons : " << total_number_of_protons << endl;
247 LogDebug(
"GenPUProtonProducer") <<
"Output collection size : " << cands.size() << endl;
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
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)
uint16_t *__restrict__ id
HepPDT::ParticleDataTable ParticleDataTable
bool getByToken(EDGetToken token, Handle< PROD > &result) const
#define DEFINE_FWK_MODULE(type)
Run const & getRun() const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
std::shared_ptr< ConvertParticle > globalBeginRun(const edm::Run &, const edm::EventSetup &) const override
void setVertex(const Point &vertex) override
set vertex
edm::ESGetToken< HepPDT::ParticleDataTable, edm::DefaultRecord > pdtToken_
~GenPUProtonProducer() override
bool abortOnUnknownPDGCode_
Abs< T >::type abs(const T &t)
GenPUProtonProducer(const edm::ParameterSet &)
static constexpr int PDGCacheMax
T const * product() const
void setThreeCharge(Charge qx3) final
set electric charge
static const double mmToCm
T getParameter(std::string const &) const
math::XYZTLorentzVector LorentzVector
Lorentz vector.
math::XYZPoint Point
point in the space
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
void setStatus(int status) final
set status word
void produce(edm::StreamID, edm::Event &e, const edm::EventSetup &) const override
void setPdgId(int pdgId) final
void setP4(const LorentzVector &p4) final
set 4-momentum
void globalEndRun(edm::Run const &, edm::EventSetup const &) const override