36 #include <ext/algorithm>
83 std::vector<int> &genBarcodes,
84 bool &barcodesAreSorted)
const;
103 setStatus_(
cfg.getParameter<int32_t>(
"setStatus")),
106 genBarcodesToken_(consumes<
std::vector<
int>>(
110 if (
cfg.exists(
"particleTypes")) {
111 pdts_ =
cfg.getParameter<vector<PdtEntry>>(
"particleTypes");
115 if (
cfg.existsAs<
string>(
"filter")) {
116 string filter =
cfg.getParameter<
string>(
"filter");
121 produces<GenParticleCollection>();
122 produces<vector<int>>();
132 std::vector<int> &genBarcodes,
133 bool &barcodesAreSorted)
const {
144 if (
filter_.get() !=
nullptr) {
150 genp.addMother(parentRef);
151 mergedGens.push_back(
genp);
153 unsigned int dauidx = mergedGens.size() - 1;
161 for (SimTrackContainer::const_iterator isimtrk = simtracksSorted.begin(); isimtrk != simtracksSorted.end();
163 if (!isimtrk->noVertex()) {
165 const SimVertex &
vtx = simvertices[isimtrk->vertIndex()];
168 if (!
vtx.noParent()) {
170 unsigned int idx =
vtx.parentIndex();
171 SimTrackContainer::const_iterator it =
173 if ((it != simtracksSorted.end()) && (it->trackId() ==
idx)) {
174 if (it->trackId() == stDau.
trackId()) {
177 stDau, *isimtrk, dauidx, simtracksSorted, simvertices, mergedGens, ref, genBarcodes, barcodesAreSorted);
187 if (!
pdts_.empty()) {
189 for (vector<PdtEntry>::iterator itp =
pdts_.begin(), edp =
pdts_.end(); itp != edp; ++itp) {
203 std::unique_ptr<SimTrackContainer> simtracksTmp;
205 if (!__gnu_cxx::is_sorted(simtracks->begin(), simtracks->end(),
LessById())) {
207 std::sort(simtracksTmp->begin(), simtracksTmp->end(),
LessById());
208 simtracksSorted = &*simtracksTmp;
218 bool barcodesAreSorted =
true;
221 if (gens->size() != genBarcodes->size())
222 throw cms::Exception(
"Corrupt data") <<
"Barcodes not of the same size as GenParticles!\n";
225 auto candsPtr = std::make_unique<GenParticleCollection>();
231 for (
size_t i = 0;
i < gens->size(); ++
i) {
237 auto newGenBarcodes = std::make_unique<vector<int>>();
238 for (
unsigned int i = 0;
i < genBarcodes->size(); ++
i) {
239 newGenBarcodes->push_back((*genBarcodes)[
i]);
241 barcodesAreSorted = __gnu_cxx::is_sorted(newGenBarcodes->begin(), newGenBarcodes->end());
243 for (
size_t i = 0;
i <
cands.size(); ++
i) {
245 size_t nDaus =
cand.numberOfDaughters();
247 cand.resetDaughters(ref.
id());
248 for (
size_t d = 0;
d < nDaus; ++
d) {
252 size_t nMoms =
cand.numberOfMothers();
254 cand.resetMothers(ref.
id());
255 for (
size_t m = 0;
m < nMoms; ++
m) {
260 for (SimTrackContainer::const_iterator isimtrk = simtracks->begin(); isimtrk != simtracks->end(); ++isimtrk) {
262 if (isimtrk->genpartIndex() != -1)
273 if (!isimtrk->noVertex()) {
275 const SimVertex &
vtx = (*simvertices)[isimtrk->vertIndex()];
278 if (!
vtx.noParent()) {
280 unsigned int idx =
vtx.parentIndex();
281 SimTrackContainer::const_iterator it =
283 if ((it != simtracksSorted->end()) && (it->trackId() ==
idx)) {
284 if (it->genpartIndex() != -1) {
285 std::vector<int>::const_iterator itIndex;
286 if (barcodesAreSorted) {
287 itIndex =
std::lower_bound(genBarcodes->begin(), genBarcodes->end(), it->genpartIndex());
289 itIndex =
std::find(genBarcodes->begin(), genBarcodes->end(), it->genpartIndex());
294 if ((itIndex != genBarcodes->end()) && (*itIndex == it->genpartIndex())) {
297 unsigned int momidx = itIndex - genBarcodes->begin();