CMS 3D CMS Logo

SimTauCPLinkProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 //
4 // Authors: Marco Rovere, Andreas Gruber
5 // Created: Mon, 16 Oct 2023 14:24:35 GMT
6 //
7 //
8 
9 // system include files
10 #include <memory>
11 
12 // user include files
15 
18 
23 
29 
31 public:
32  explicit SimTauProducer(const edm::ParameterSet&);
33  ~SimTauProducer() override = default;
34 
35  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
36 
37 private:
38  void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const override;
39 
41  uint8_t,
42  int,
43  const reco::GenParticle&,
44  int,
45  edm::Handle<std::vector<CaloParticle>>,
46  const std::vector<int>&) const;
47  // ----------member data ---------------------------
51 };
52 
54  : caloParticles_token_(consumes<std::vector<CaloParticle>>(iConfig.getParameter<edm::InputTag>("caloParticles"))),
55  genParticles_token_(consumes<reco::GenParticleCollection>(iConfig.getParameter<edm::InputTag>("genParticles"))),
56  genBarcodes_token_(consumes<std::vector<int>>(iConfig.getParameter<edm::InputTag>("genBarcodes"))) {
57  produces<std::vector<SimTauCPLink>>();
58 }
59 
61  uint8_t generation,
62  int resonance_idx,
63  const reco::GenParticle& gen_particle,
64  int gen_particle_key,
65  edm::Handle<std::vector<CaloParticle>> calo_particle_h,
66  const std::vector<int>& gen_particle_barcodes) const {
67  const auto& caloPartVec = *calo_particle_h;
68  auto& daughters = gen_particle.daughterRefVector();
69  bool is_leaf = (daughters.empty());
70 
71  if (is_leaf) {
72  LogDebug("SimTauProducer").format(" TO BE SAVED {} ", resonance_idx);
73  auto const& gen_particle_barcode = gen_particle_barcodes[gen_particle_key];
74  auto const& found_in_caloparticles = std::find_if(caloPartVec.begin(), caloPartVec.end(), [&](const auto& p) {
75  return p.g4Tracks()[0].genpartIndex() == gen_particle_barcode;
76  });
77  if (found_in_caloparticles != caloPartVec.end()) {
78  auto calo_particle_idx = (found_in_caloparticles - caloPartVec.begin());
79  t.calo_particle_leaves.push_back(CaloParticleRef(calo_particle_h, calo_particle_idx));
80  t.leaves.push_back(
81  {gen_particle.pdgId(), resonance_idx, (int)t.calo_particle_leaves.size() - 1, gen_particle_key});
82  LogDebug("SimTauProducer").format(" CP {} {}", calo_particle_idx, caloPartVec[calo_particle_idx].pdgId());
83  } else {
84  t.leaves.push_back({gen_particle.pdgId(), resonance_idx, -1, gen_particle_key});
85  }
86  return;
87  } else if (generation != 0) {
88  t.resonances.push_back({gen_particle.pdgId(), resonance_idx});
89  resonance_idx = t.resonances.size() - 1;
90  LogDebug("SimTauProducer").format(" RESONANCE/INTERMEDIATE {} ", resonance_idx);
91  }
92 
93  ++generation;
94  for (auto daughter = daughters.begin(); daughter != daughters.end(); ++daughter) {
95  int gen_particle_key = (*daughter).key();
96  LogDebug("SimTauProducer").format(" gen {} {} {} ", generation, gen_particle_key, (*daughter)->pdgId());
97  buildSimTau(t, generation, resonance_idx, *(*daughter), gen_particle_key, calo_particle_h, gen_particle_barcodes);
98  }
99 }
100 
102  using namespace edm;
103 
104  auto caloParticles_h = iEvent.getHandle(caloParticles_token_);
105  const auto& genParticles = iEvent.get(genParticles_token_);
106  const auto& genBarcodes = iEvent.get(genBarcodes_token_);
107 
108  auto tauDecayVec = std::make_unique<std::vector<SimTauCPLink>>();
109  for (auto const& g : genParticles) {
110  auto const& flags = g.statusFlags();
111  if (std::abs(g.pdgId()) == 15 and flags.isPrompt() and flags.isDecayedLeptonHadron()) {
112  SimTauCPLink t;
113  buildSimTau(t, 0, -1, g, -1, caloParticles_h, genBarcodes);
114  t.decayMode = t.buildDecayModes();
115 #ifdef EDM_ML_DEBUG
116  t.dumpFullDecay();
117  t.dump();
118 #endif
119  (*tauDecayVec).push_back(t);
120  }
121  }
122  iEvent.put(std::move(tauDecayVec));
123 }
124 
127  desc.add<edm::InputTag>("caloParticles", edm::InputTag("mix", "MergedCaloTruth"));
128  desc.add<edm::InputTag>("genParticles", edm::InputTag("genParticles"));
129  desc.add<edm::InputTag>("genBarcodes", edm::InputTag("genParticles"));
130  descriptions.add("SimTauProducer", desc);
131 }
132 
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
void produce(edm::StreamID, edm::Event &, edm::EventSetup const &) const override
void buildSimTau(SimTauCPLink &, uint8_t, int, const reco::GenParticle &, int, edm::Handle< std::vector< CaloParticle >>, const std::vector< int > &) const
~SimTauProducer() override=default
const daughters & daughterRefVector() const
references to daughtes
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
int pdgId() const final
PDG identifier.
int iEvent
Definition: GenABIO.cc:224
edm::Ref< CaloParticleCollection > CaloParticleRef
const edm::EDGetTokenT< std::vector< int > > genBarcodes_token_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
SimTauProducer(const edm::ParameterSet &)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
const edm::EDGetTokenT< std::vector< reco::GenParticle > > genParticles_token_
fixed size matrix
HLT enums.
const edm::EDGetTokenT< std::vector< CaloParticle > > caloParticles_token_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
def move(src, dest)
Definition: eostools.py:511
#define LogDebug(id)