38 #include <ext/algorithm>
85 std::vector<int> &genBarcodes,
86 bool &barcodesAreSorted)
const;
105 setStatus_(cfg.getParameter<int32_t>(
"setStatus")),
107 cfg.getParameter<
InputTag>(
"genParticles"))),
108 genBarcodesToken_(consumes<std::
vector<int>>(
109 cfg.getParameter<
InputTag>(
"genParticles")))
112 if (cfg.
exists(
"particleTypes")) {
114 if (!
pdts_.empty()) {
120 if (cfg.
existsAs<
string>(
"filter")) {
122 if (!filter.empty()) {
126 produces<GenParticleCollection>();
127 produces<vector<int>>();
137 std::vector<int> &genBarcodes,
138 bool &barcodesAreSorted)
const {
145 vtx = simvertices[stDau.
vertIndex()].position();
149 if (
filter_.get() !=
nullptr) {
155 genp.addMother(parentRef);
156 mergedGens.push_back(
genp);
158 unsigned int dauidx = mergedGens.size() - 1;
166 for (SimTrackContainer::const_iterator isimtrk = simtracksSorted.begin(); isimtrk != simtracksSorted.end();
168 if (!isimtrk->noVertex()) {
170 const SimVertex &vtx = simvertices[isimtrk->vertIndex()];
176 SimTrackContainer::const_iterator it =
178 if ((it != simtracksSorted.end()) && (it->trackId() == idx)) {
179 if (it->trackId() == stDau.
trackId()) {
182 stDau, *isimtrk, dauidx, simtracksSorted, simvertices, mergedGens, ref, genBarcodes, barcodesAreSorted);
192 if (!
pdts_.empty()) {
195 for (vector<PdtEntry>::iterator itp =
pdts_.begin(), edp =
pdts_.end(); itp != edp; ++itp) {
209 std::unique_ptr<SimTrackContainer> simtracksTmp;
211 if (!__gnu_cxx::is_sorted(simtracks->begin(), simtracks->end(),
LessById())) {
212 simtracksTmp = std::make_unique<SimTrackContainer>(*simtracks);
213 std::sort(simtracksTmp->begin(), simtracksTmp->end(),
LessById());
214 simtracksSorted = &*simtracksTmp;
224 bool barcodesAreSorted =
true;
227 if (gens->size() != genBarcodes->size())
228 throw cms::Exception(
"Corrupt data") <<
"Barcodes not of the same size as GenParticles!\n";
231 auto candsPtr = std::make_unique<GenParticleCollection>();
237 for (
size_t i = 0;
i < gens->size(); ++
i) {
239 cands.push_back(cand);
243 auto newGenBarcodes = std::make_unique<vector<int>>();
244 for (
unsigned int i = 0;
i < genBarcodes->size(); ++
i) {
245 newGenBarcodes->push_back((*genBarcodes)[
i]);
247 barcodesAreSorted = __gnu_cxx::is_sorted(newGenBarcodes->begin(), newGenBarcodes->end());
249 for (
size_t i = 0;
i < cands.size(); ++
i) {
254 for (
size_t d = 0;
d < nDaus; ++
d) {
261 for (
size_t m = 0;
m < nMoms; ++
m) {
266 for (SimTrackContainer::const_iterator isimtrk = simtracks->begin(); isimtrk != simtracks->end(); ++isimtrk) {
268 if (isimtrk->genpartIndex() != -1)
279 if (!isimtrk->noVertex()) {
281 const SimVertex &vtx = (*simvertices)[isimtrk->vertIndex()];
287 SimTrackContainer::const_iterator it =
289 if ((it != simtracksSorted->end()) && (it->trackId() == idx)) {
290 if (it->genpartIndex() != -1) {
291 std::vector<int>::const_iterator itIndex;
292 if (barcodesAreSorted) {
293 itIndex =
std::lower_bound(genBarcodes->begin(), genBarcodes->end(), it->genpartIndex());
295 itIndex =
std::find(genBarcodes->begin(), genBarcodes->end(), it->genpartIndex());
300 if ((itIndex != genBarcodes->end()) && (*itIndex == it->genpartIndex())) {
303 unsigned int momidx = itIndex - genBarcodes->begin();
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
bool operator()(const SimTrack &tk1, const SimTrack &tk2) const
bool existsAs(std::string const ¶meterName, bool trackiness=true) const
checks if a parameter exists as a given type
edm::EDGetTokenT< edm::SimVertexContainer > simverticesToken_
uint16_t *__restrict__ id
#define DEFINE_FWK_MODULE(type)
std::vector< PdtEntry > pdts_
edm::EDGetTokenT< std::vector< int > > genBarcodesToken_
size_t numberOfDaughters() const override
number of daughters
edm::ESGetToken< HepPDT::ParticleDataTable, edm::DefaultRecord > tableToken_
bool exists(std::string const ¶meterName) const
checks if a parameter exists
const daughters & daughterRefVector() const
references to daughtes
std::unique_ptr< StrFilter > filter_
size_t numberOfMothers() const override
number of mothers
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
float charge() const
charge
void addDaughter(const typename daughters::value_type &)
add a daughter via a reference
bool getData(T &iHolder) const
void resetDaughters(const edm::ProductID &id)
set daughters product ID
StringCutObjectSelector< reco::GenParticle > StrFilter
const mothers & motherRefVector() const
references to mothers
tuple key
prepare the HTCondor submission files and eventually submit them
Abs< T >::type abs(const T &t)
bool operator()(unsigned int id, const SimTrack &tk2) const
GenPlusSimParticleProducer(const edm::ParameterSet &)
Produces reco::GenParticle from SimTracks.
tuple genp
produce generated paricles in acceptance #
void addMother(const typename mothers::value_type &)
add a daughter via a reference
int vertIndex() const
index of the vertex in the Event container (-1 if no vertex)
bool operator()(const SimTrack &tk1, unsigned int id) const
unsigned int trackId() const
edm::Ref< edm::HepMCProduct, HepMC::GenParticle > GenParticleRef
edm::EDGetTokenT< reco::GenParticleCollection > gensToken_
Collection of GenParticles I need to make refs to. It must also have its associated vector<int> of ba...
std::vector< SimVertex > SimVertexContainer
T getParameter(std::string const &) const
math::XYZTLorentzVector LorentzVector
Lorentz vector.
void produce(edm::Event &, const edm::EventSetup &) override
int type() const
particle type (HEP PDT convension)
__host__ __device__ constexpr RandomIt lower_bound(RandomIt first, RandomIt last, const T &value, Compare comp={})
const math::XYZTLorentzVectorD & momentum() const
ProductID id() const
Accessor for product ID.
void addGenParticle(const SimTrack &stMom, const SimTrack &stDau, unsigned int momidx, const edm::SimTrackContainer &simtks, const edm::SimVertexContainer &simvtxs, reco::GenParticleCollection &mergedGens, const reco::GenParticleRefProd ref, std::vector< int > &genBarcodes, bool &barcodesAreSorted) const
Try to link the GEANT particle to the generator particle it came from.
math::XYZPoint Point
point in the space
void resetMothers(const edm::ProductID &id)
set mother product ID
std::vector< SimTrack > SimTrackContainer
edm::EDGetTokenT< edm::SimTrackContainer > simtracksToken_