Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-04-07 05:50:33

0001 #ifndef HeavyFlavorAnalysis_SpecificDecay_BPHWriteSpecificDecay_h
0002 #define HeavyFlavorAnalysis_SpecificDecay_BPHWriteSpecificDecay_h
0003 
0004 #include "DataFormats/Candidate/interface/VertexCompositeCandidate.h"
0005 #include "DataFormats/Common/interface/Ref.h"
0006 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
0007 #include "DataFormats/PatCandidates/interface/CompositeCandidate.h"
0008 #include "DataFormats/PatCandidates/interface/GenericParticle.h"
0009 #include "DataFormats/PatCandidates/interface/Muon.h"
0010 #include "DataFormats/TrackReco/interface/Track.h"
0011 #include "FWCore/Framework/interface/Event.h"
0012 #include "FWCore/Framework/interface/EventSetup.h"
0013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0014 #include "HeavyFlavorAnalysis/RecoDecay/interface/BPHAnalyzerTokenWrapper.h"
0015 #include "HeavyFlavorAnalysis/RecoDecay/interface/BPHPlusMinusCandidate.h"
0016 #include "HeavyFlavorAnalysis/RecoDecay/interface/BPHRecoCandidate.h"
0017 #include "HeavyFlavorAnalysis/RecoDecay/interface/BPHTrackReference.h"
0018 #include "HeavyFlavorAnalysis/RecoDecay/interface/BPHVertexCompositePtrCandidate.h"
0019 #include "MagneticField/Engine/interface/MagneticField.h"
0020 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
0021 #include "RecoVertex/KinematicFitPrimitives/interface/RefCountedKinematicParticle.h"
0022 #include "RecoVertex/KinematicFitPrimitives/interface/RefCountedKinematicVertex.h"
0023 
0024 #include <string>
0025 #include <vector>
0026 #include <map>
0027 
0028 class TH1F;
0029 class BPHRecoCandidate;
0030 
0031 class BPHWriteSpecificDecay : public BPHAnalyzerWrapper<BPHModuleWrapper::one_producer> {
0032 public:
0033   explicit BPHWriteSpecificDecay(const edm::ParameterSet& ps);
0034   ~BPHWriteSpecificDecay() override = default;
0035 
0036   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0037 
0038   void beginJob() override;
0039   void produce(edm::Event& ev, const edm::EventSetup& es) override;
0040   virtual void fill(edm::Event& ev, const edm::EventSetup& es);
0041   void endJob() override;
0042 
0043 private:
0044   const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> bFieldToken;
0045   std::string pVertexLabel;
0046   std::string patMuonLabel;
0047   std::string ccCandsLabel;
0048   std::string pfCandsLabel;
0049   std::string pcCandsLabel;
0050   std::string gpCandsLabel;
0051   std::string k0CandsLabel;
0052   std::string l0CandsLabel;
0053   std::string kSCandsLabel;
0054   std::string lSCandsLabel;
0055 
0056   // token wrappers to allow running both on "old" and "new" CMSSW versions
0057   BPHTokenWrapper<std::vector<reco::Vertex>> pVertexToken;
0058   BPHTokenWrapper<pat::MuonCollection> patMuonToken;
0059   BPHTokenWrapper<std::vector<pat::CompositeCandidate>> ccCandsToken;
0060   BPHTokenWrapper<std::vector<reco::PFCandidate>> pfCandsToken;
0061   BPHTokenWrapper<std::vector<BPHTrackReference::candidate>> pcCandsToken;
0062   BPHTokenWrapper<std::vector<pat::GenericParticle>> gpCandsToken;
0063   BPHTokenWrapper<std::vector<reco::VertexCompositeCandidate>> k0CandsToken;
0064   BPHTokenWrapper<std::vector<reco::VertexCompositeCandidate>> l0CandsToken;
0065   BPHTokenWrapper<std::vector<reco::VertexCompositePtrCandidate>> kSCandsToken;
0066   BPHTokenWrapper<std::vector<reco::VertexCompositePtrCandidate>> lSCandsToken;
0067 
0068   bool usePV;
0069   bool usePM;
0070   bool useCC;
0071   bool usePF;
0072   bool usePC;
0073   bool useGP;
0074   bool useK0;
0075   bool useL0;
0076   bool useKS;
0077   bool useLS;
0078 
0079   std::string oniaName;
0080   std::string sdName;
0081   std::string ssName;
0082   std::string buName;
0083   std::string bdName;
0084   std::string bsName;
0085   std::string k0Name;
0086   std::string l0Name;
0087   std::string b0Name;
0088   std::string lbName;
0089   std::string bcName;
0090   std::string x3872Name;
0091 
0092   enum recoType {
0093     Onia,
0094     Pmm,
0095     Psi1,
0096     Psi2,
0097     Ups,
0098     Ups1,
0099     Ups2,
0100     Ups3,
0101     Kx0,
0102     Pkk,
0103     Bu,
0104     Bd,
0105     Bs,
0106     K0s,
0107     Lambda0,
0108     B0,
0109     Lambdab,
0110     Bc,
0111     X3872
0112   };
0113   enum parType {
0114     ptMin,
0115     etaMax,
0116     mPsiMin,
0117     mPsiMax,
0118     mKx0Min,
0119     mKx0Max,
0120     mPhiMin,
0121     mPhiMax,
0122     mK0sMin,
0123     mK0sMax,
0124     mLambda0Min,
0125     mLambda0Max,
0126     massMin,
0127     massMax,
0128     probMin,
0129     mFitMin,
0130     mFitMax,
0131     constrMass,
0132     constrSigma,
0133     constrMJPsi,
0134     writeCandidate
0135   };
0136   std::map<std::string, recoType> rMap;
0137   std::map<std::string, parType> pMap;
0138   std::map<std::string, parType> fMap;
0139   std::map<recoType, std::map<parType, double>> parMap;
0140 
0141   bool recoOnia;
0142   bool recoKx0;
0143   bool recoPkk;
0144   bool recoBu;
0145   bool recoBd;
0146   bool recoBs;
0147   bool recoK0s;
0148   bool recoLambda0;
0149   bool recoB0;
0150   bool recoLambdab;
0151   bool recoBc;
0152   bool recoX3872;
0153 
0154   bool writeOnia;
0155   bool writeKx0;
0156   bool writePkk;
0157   bool writeBu;
0158   bool writeBd;
0159   bool writeBs;
0160   bool writeK0s;
0161   bool writeLambda0;
0162   bool writeB0;
0163   bool writeLambdab;
0164   bool writeBc;
0165   bool writeX3872;
0166 
0167   bool writeVertex;
0168   bool writeMomentum;
0169 
0170   std::vector<BPHPlusMinusConstCandPtr> lFull;
0171   std::vector<BPHPlusMinusConstCandPtr> lJPsi;
0172   std::vector<BPHRecoConstCandPtr> lSd;
0173   std::vector<BPHRecoConstCandPtr> lSs;
0174   std::vector<BPHRecoConstCandPtr> lBu;
0175   std::vector<BPHRecoConstCandPtr> lBd;
0176   std::vector<BPHRecoConstCandPtr> lBs;
0177   std::vector<BPHPlusMinusConstCandPtr> lK0;
0178   std::vector<BPHPlusMinusConstCandPtr> lL0;
0179   std::vector<BPHRecoConstCandPtr> lB0;
0180   std::vector<BPHRecoConstCandPtr> lLb;
0181   std::vector<BPHRecoConstCandPtr> lBc;
0182   std::vector<BPHRecoConstCandPtr> lX3872;
0183 
0184   std::map<const BPHRecoCandidate*, const BPHRecoCandidate*> jPsiOMap;
0185   std::map<const BPHRecoCandidate*, const BPHRecoCandidate*> daughMap;
0186   typedef edm::Ref<std::vector<reco::Vertex>> vertex_ref;
0187   std::map<const BPHRecoCandidate*, vertex_ref> pvRefMap;
0188   typedef edm::Ref<pat::CompositeCandidateCollection> compcc_ref;
0189   std::map<const BPHRecoCandidate*, compcc_ref> ccRefMap;
0190 
0191   void setRecoParameters(const edm::ParameterSet& ps);
0192 
0193   template <class T>
0194   edm::OrphanHandle<pat::CompositeCandidateCollection> write(edm::Event& ev,
0195                                                              const std::vector<T>& list,
0196                                                              const std::string& name) {
0197     pat::CompositeCandidateCollection* ccList = new pat::CompositeCandidateCollection;
0198     int i;
0199     int n = list.size();
0200     std::map<const BPHRecoCandidate*, const BPHRecoCandidate*>::const_iterator dauIter;
0201     std::map<const BPHRecoCandidate*, const BPHRecoCandidate*>::const_iterator dauIend = daughMap.end();
0202     std::map<const BPHRecoCandidate*, const BPHRecoCandidate*>::const_iterator jpoIter;
0203     std::map<const BPHRecoCandidate*, const BPHRecoCandidate*>::const_iterator jpoIend = jPsiOMap.end();
0204     std::map<const BPHRecoCandidate*, vertex_ref>::const_iterator pvrIter;
0205     std::map<const BPHRecoCandidate*, vertex_ref>::const_iterator pvrIend = pvRefMap.end();
0206     std::map<const BPHRecoCandidate*, compcc_ref>::const_iterator ccrIter;
0207     std::map<const BPHRecoCandidate*, compcc_ref>::const_iterator ccrIend = ccRefMap.end();
0208     for (i = 0; i < n; ++i) {
0209       const T& ptr = list[i];
0210       ccList->push_back(ptr->composite());
0211       pat::CompositeCandidate& cc = ccList->back();
0212       if ((pvrIter = pvRefMap.find(ptr.get())) != pvrIend)
0213         cc.addUserData("primaryVertex", pvrIter->second);
0214       const std::vector<std::string>& cNames = ptr->compNames();
0215       int j = 0;
0216       int m = cNames.size();
0217       while (j < m) {
0218         const std::string& compName = cNames[j++];
0219         const BPHRecoCandidate* cptr = ptr->getComp(compName).get();
0220         if ((ccrIter = ccRefMap.find(cptr)) == ccrIend) {
0221           if ((dauIter = daughMap.find(cptr)) != dauIend)
0222             cptr = dauIter->second;
0223           if ((jpoIter = jPsiOMap.find(cptr)) != jpoIend)
0224             cptr = jpoIter->second;
0225         }
0226         if ((ccrIter = ccRefMap.find(cptr)) != ccrIend) {
0227           compcc_ref cref = ccrIter->second;
0228           if (cref.isNonnull())
0229             cc.addUserData("refTo" + compName, cref);
0230         }
0231       }
0232       const BPHPlusMinusCandidate* pmp = dynamic_cast<const BPHPlusMinusCandidate*>(ptr.get());
0233       if (pmp != nullptr) {
0234         cc.addUserData("cowboy", pmp->isCowboy());
0235         //        cc.addUserFloat(    "dca", pmp->cAppInRPhi().distance() );
0236       }
0237       if (writeVertex)
0238         cc.addUserData("vertex", ptr->vertex());
0239       if (ptr->isEmpty())
0240         continue;
0241       if (writeVertex)
0242         cc.addUserData("fitVertex", reco::Vertex(*ptr->topDecayVertex()));
0243       if (ptr->isValidFit()) {
0244         const RefCountedKinematicParticle kinPart = ptr->topParticle();
0245         const KinematicState kinStat = kinPart->currentState();
0246         cc.addUserFloat("fitMass", kinStat.mass());
0247         if (writeMomentum)
0248           cc.addUserData("fitMomentum", kinStat.kinematicParameters().momentum());
0249       }
0250     }
0251     typedef std::unique_ptr<pat::CompositeCandidateCollection> ccc_pointer;
0252     edm::OrphanHandle<pat::CompositeCandidateCollection> ccHandle = ev.put(ccc_pointer(ccList), name);
0253     for (i = 0; i < n; ++i) {
0254       const BPHRecoCandidate* ptr = list[i].get();
0255       edm::Ref<pat::CompositeCandidateCollection> ccRef(ccHandle, i);
0256       ccRefMap[ptr] = ccRef;
0257     }
0258     return ccHandle;
0259   }
0260 };
0261 
0262 #endif