36 #include <ext/algorithm>
84 std::vector<int> &genBarcodes,
85 bool &barcodesAreSorted)
const;
104 setStatus_(
cfg.getParameter<int32_t>(
"setStatus")),
111 if (
cfg.exists(
"particleTypes")) {
112 pdts_ =
cfg.getParameter<vector<PdtEntry>>(
"particleTypes");
116 if (
cfg.existsAs<
string>(
"filter")) {
117 string filter =
cfg.getParameter<
string>(
"filter");
122 produces<GenParticleCollection>();
123 produces<vector<int>>();
133 std::vector<int> &genBarcodes,
134 bool &barcodesAreSorted)
const {
145 if (
filter_.get() !=
nullptr) {
151 genp.addMother(parentRef);
152 mergedGens.push_back(
genp);
154 unsigned int dauidx = mergedGens.size() - 1;
162 for (SimTrackContainer::const_iterator isimtrk = simtracksSorted.begin(); isimtrk != simtracksSorted.end();
164 if (!isimtrk->noVertex()) {
166 const SimVertex &
vtx = simvertices[isimtrk->vertIndex()];
169 if (!
vtx.noParent()) {
171 unsigned int idx =
vtx.parentIndex();
172 SimTrackContainer::const_iterator it =
174 if ((it != simtracksSorted.end()) && (it->trackId() ==
idx)) {
175 if (it->trackId() == stDau.
trackId()) {
178 stDau, *isimtrk, dauidx, simtracksSorted, simvertices, mergedGens, ref, genBarcodes, barcodesAreSorted);
188 if (!
pdts_.empty()) {
190 for (vector<PdtEntry>::iterator itp =
pdts_.begin(), edp =
pdts_.end(); itp != edp; ++itp) {
204 std::unique_ptr<SimTrackContainer> simtracksTmp;
206 if (!__gnu_cxx::is_sorted(simtracks->begin(), simtracks->end(),
LessById())) {
207 simtracksTmp = std::make_unique<SimTrackContainer>(*simtracks);
208 std::sort(simtracksTmp->begin(), simtracksTmp->end(),
LessById());
209 simtracksSorted = &*simtracksTmp;
219 bool barcodesAreSorted =
true;
222 if (gens->size() != genBarcodes->size())
223 throw cms::Exception(
"Corrupt data") <<
"Barcodes not of the same size as GenParticles!\n";
226 auto candsPtr = std::make_unique<GenParticleCollection>();
232 for (
size_t i = 0;
i < gens->size(); ++
i) {
238 auto newGenBarcodes = std::make_unique<vector<int>>();
239 for (
unsigned int i = 0;
i < genBarcodes->size(); ++
i) {
240 newGenBarcodes->push_back((*genBarcodes)[
i]);
242 barcodesAreSorted = __gnu_cxx::is_sorted(newGenBarcodes->begin(), newGenBarcodes->end());
244 for (
size_t i = 0;
i <
cands.size(); ++
i) {
246 size_t nDaus =
cand.numberOfDaughters();
248 cand.resetDaughters(ref.
id());
249 for (
size_t d = 0;
d < nDaus; ++
d) {
253 size_t nMoms =
cand.numberOfMothers();
255 cand.resetMothers(ref.
id());
256 for (
size_t m = 0;
m < nMoms; ++
m) {
261 for (SimTrackContainer::const_iterator isimtrk = simtracks->begin(); isimtrk != simtracks->end(); ++isimtrk) {
263 if (isimtrk->genpartIndex() != -1)
274 if (!isimtrk->noVertex()) {
276 const SimVertex &
vtx = (*simvertices)[isimtrk->vertIndex()];
279 if (!
vtx.noParent()) {
281 unsigned int idx =
vtx.parentIndex();
282 SimTrackContainer::const_iterator it =
284 if ((it != simtracksSorted->end()) && (it->trackId() ==
idx)) {
285 if (it->genpartIndex() != -1) {
286 std::vector<int>::const_iterator itIndex;
287 if (barcodesAreSorted) {
288 itIndex =
std::lower_bound(genBarcodes->begin(), genBarcodes->end(), it->genpartIndex());
290 itIndex =
std::find(genBarcodes->begin(), genBarcodes->end(), it->genpartIndex());
295 if ((itIndex != genBarcodes->end()) && (*itIndex == it->genpartIndex())) {
298 unsigned int momidx = itIndex - genBarcodes->begin();