Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-04-22 06:27:47

0001 #ifndef SimDataFormats_SimTauCPLink_h
0002 #define SimDataFormats_SimTauCPLink_h
0003 
0004 #include "DataFormats/HGCalReco/interface/TICLCandidate.h"
0005 #include "SimDataFormats/CaloAnalysis/interface/CaloParticleFwd.h"
0006 #include "SimDataFormats/CaloAnalysis/interface/CaloParticle.h"
0007 #include "SimDataFormats/CaloAnalysis/interface/SimCluster.h"
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 
0010 class SimTauCPLink {
0011 public:
0012   SimTauCPLink() {}
0013   ~SimTauCPLink() {}
0014   struct DecayNav {
0015     int pdgId_;
0016     int resonance_idx_;
0017     int calo_particle_idx_;
0018     int gen_particle_idx_;
0019     int pdgId() const { return pdgId_; }
0020     int resonance_idx() const { return resonance_idx_; }
0021     int calo_particle_idx() const { return calo_particle_idx_; }
0022     int gen_particle_idx() const { return gen_particle_idx_; }
0023 
0024   private:
0025   };
0026 
0027   std::vector<std::pair<int, int>> resonances;
0028   std::vector<DecayNav> leaves;
0029   CaloParticleRefVector calo_particle_leaves;
0030   int decayMode;
0031 
0032   enum decayModes {
0033     kNull = -1,
0034     kOneProng0PiZero,    // 0
0035     kOneProng1PiZero,    // 1
0036     kOneProng2PiZero,    // 2
0037     kOneProng3PiZero,    // 3
0038     kOneProngNPiZero,    // 4
0039     kTwoProng0PiZero,    // 5
0040     kTwoProng1PiZero,    // 6
0041     kTwoProng2PiZero,    // 7
0042     kTwoProng3PiZero,    // 8
0043     kTwoProngNPiZero,    // 9
0044     kThreeProng0PiZero,  // 10
0045     kThreeProng1PiZero,  // 11
0046     kThreeProng2PiZero,  // 12
0047     kThreeProng3PiZero,  // 13
0048     kThreeProngNPiZero,  // 14
0049     kRareDecayMode,      // 15
0050     kElectron,           // 16
0051     kMuon                // 17
0052   };
0053 
0054   void dump(void) const {
0055     LogDebug("SimTauProducer")
0056         .format("Decay mode: {} ", buildDecayModes())
0057         .format("Leaves: {} ", leaves.size())
0058         .format("Resonances: {}", resonances.size());
0059     for (auto const &l : leaves) {
0060       LogDebug("SimTauProducer")
0061           .format("L {} {} CP: {} GenP idx: {}",
0062                   l.pdgId(),
0063                   l.resonance_idx(),
0064                   (int)((l.calo_particle_idx() == -1) ? -1 : calo_particle_leaves[l.calo_particle_idx()].key()),
0065                   l.gen_particle_idx());
0066     }
0067     for (auto const &r : resonances) {
0068       LogDebug("SimTauProducer").format("R {} {}", r.first, r.second);
0069     }
0070   }
0071 
0072   void dumpDecay(const std::pair<int, int> &entry) const {
0073     if (entry.second == -1) {  // No intermediate mother.
0074       LogDebug("SimTauProducer").format("{} {}", entry.first, entry.second);
0075     } else {
0076       LogDebug("SimTauProducer").format("{} {} coming from: ", entry.first, entry.second);
0077       auto const &mother = resonances[entry.second];
0078       dumpDecay(mother);
0079     }
0080   }
0081 
0082   void dumpFullDecay(void) const {
0083     for (auto const &leaf : leaves) {
0084       dumpDecay({leaf.pdgId(), leaf.resonance_idx()});
0085     }
0086   }
0087 
0088   int buildDecayModes() const {
0089     int numElectrons = 0;
0090     int numMuons = 0;
0091     int numHadrons = 0;
0092     int numPhotons = 0;
0093     for (auto leaf : leaves) {
0094       int pdg_id = abs(leaf.pdgId());
0095       switch (pdg_id) {
0096         case 22:
0097           numPhotons++;
0098           break;
0099         case 11:
0100           numElectrons++;
0101           break;
0102         case 13:
0103           numMuons++;
0104           break;
0105         case 16:
0106           break;
0107         default:
0108           numHadrons++;
0109       }
0110     }
0111 
0112     if (numElectrons == 1)
0113       return kElectron;
0114     else if (numMuons == 1)
0115       return kMuon;
0116     switch (numHadrons) {
0117       case 1:
0118         switch (numPhotons) {
0119           case 0:
0120             return kOneProng0PiZero;
0121           case 2:
0122             return kOneProng1PiZero;
0123           case 4:
0124             return kOneProng2PiZero;
0125           case 6:
0126             return kOneProng3PiZero;
0127           default:
0128             return kOneProngNPiZero;
0129         }
0130       case 2:
0131         switch (numPhotons) {
0132           case 0:
0133             return kTwoProng0PiZero;
0134           case 2:
0135             return kTwoProng1PiZero;
0136           case 4:
0137             return kTwoProng2PiZero;
0138           case 6:
0139             return kTwoProng3PiZero;
0140           default:
0141             return kTwoProngNPiZero;
0142         }
0143       case 3:
0144         switch (numPhotons) {
0145           case 0:
0146             return kThreeProng0PiZero;
0147           case 2:
0148             return kThreeProng1PiZero;
0149           case 4:
0150             return kThreeProng2PiZero;
0151           case 6:
0152             return kThreeProng3PiZero;
0153           default:
0154             return kThreeProngNPiZero;
0155         }
0156       default:
0157         return kRareDecayMode;
0158     }
0159   }
0160 
0161 private:
0162 };
0163 
0164 #endif  //SimTauCPLink