38 #include <ext/algorithm>
87 std::vector<int> &genBarcodes,
88 bool &barcodesAreSorted)
const;
107 setStatus_(
cfg.getParameter<int32_t>(
"setStatus")),
114 if (
cfg.exists(
"particleTypes")) {
115 pdts_ =
cfg.getParameter<vector<PdtEntry>>(
"particleTypes");
116 if (!
pdts_.empty()) {
122 if (
cfg.existsAs<
string>(
"filter")) {
123 string filter =
cfg.getParameter<
string>(
"filter");
128 produces<GenParticleCollection>();
129 produces<vector<int>>();
139 std::vector<int> &genBarcodes,
140 bool &barcodesAreSorted)
const {
151 if (
filter_.get() !=
nullptr) {
157 genp.addMother(parentRef);
158 mergedGens.push_back(
genp);
160 unsigned int dauidx = mergedGens.size() - 1;
168 for (SimTrackContainer::const_iterator isimtrk = simtracksSorted.begin(); isimtrk != simtracksSorted.end();
170 if (!isimtrk->noVertex()) {
172 const SimVertex &
vtx = simvertices[isimtrk->vertIndex()];
175 if (!
vtx.noParent()) {
177 unsigned int idx =
vtx.parentIndex();
178 SimTrackContainer::const_iterator it =
180 if ((it != simtracksSorted.end()) && (it->trackId() ==
idx)) {
181 if (it->trackId() == stDau.
trackId()) {
184 stDau, *isimtrk, dauidx, simtracksSorted, simvertices, mergedGens, ref, genBarcodes, barcodesAreSorted);
194 if (!
pdts_.empty()) {
197 for (vector<PdtEntry>::iterator itp =
pdts_.begin(), edp =
pdts_.end(); itp != edp; ++itp) {
211 std::unique_ptr<SimTrackContainer> simtracksTmp;
213 if (!__gnu_cxx::is_sorted(simtracks->begin(), simtracks->end(),
LessById())) {
214 simtracksTmp = std::make_unique<SimTrackContainer>(*simtracks);
216 simtracksSorted = &*simtracksTmp;
226 bool barcodesAreSorted =
true;
229 if (gens->size() != genBarcodes->size())
230 throw cms::Exception(
"Corrupt data") <<
"Barcodes not of the same size as GenParticles!\n";
233 auto candsPtr = std::make_unique<GenParticleCollection>();
239 for (
size_t i = 0;
i < gens->size(); ++
i) {
245 auto newGenBarcodes = std::make_unique<vector<int>>();
246 for (
unsigned int i = 0;
i < genBarcodes->size(); ++
i) {
247 newGenBarcodes->push_back((*genBarcodes)[
i]);
249 barcodesAreSorted = __gnu_cxx::is_sorted(newGenBarcodes->begin(), newGenBarcodes->end());
251 for (
size_t i = 0;
i <
cands.size(); ++
i) {
253 size_t nDaus =
cand.numberOfDaughters();
255 cand.resetDaughters(ref.
id());
256 for (
size_t d = 0;
d < nDaus; ++
d) {
260 size_t nMoms =
cand.numberOfMothers();
262 cand.resetMothers(ref.
id());
263 for (
size_t m = 0;
m < nMoms; ++
m) {
268 for (SimTrackContainer::const_iterator isimtrk = simtracks->begin(); isimtrk != simtracks->end(); ++isimtrk) {
270 if (isimtrk->genpartIndex() != -1)
281 if (!isimtrk->noVertex()) {
283 const SimVertex &
vtx = (*simvertices)[isimtrk->vertIndex()];
286 if (!
vtx.noParent()) {
288 unsigned int idx =
vtx.parentIndex();
289 SimTrackContainer::const_iterator it =
291 if ((it != simtracksSorted->end()) && (it->trackId() ==
idx)) {
292 if (it->genpartIndex() != -1) {
293 std::vector<int>::const_iterator itIndex;
294 if (barcodesAreSorted) {
295 itIndex =
std::lower_bound(genBarcodes->begin(), genBarcodes->end(), it->genpartIndex());
297 itIndex =
std::find(genBarcodes->begin(), genBarcodes->end(), it->genpartIndex());
302 if ((itIndex != genBarcodes->end()) && (*itIndex == it->genpartIndex())) {
305 unsigned int momidx = itIndex - genBarcodes->begin();