Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:57:08

0001 // -*- C++ -*-
0002 //
0003 // Package:    Alignment/OfflineValidation
0004 // Class:      TkAlV0sAnalyzer
0005 //
0006 /*
0007  *\class TkAlV0sAnalyzer TkAlV0sAnalyzer.cc Alignment/TkAlV0sAnalyzer/plugins/TkAlV0sAnalyzer.cc
0008 
0009  Description: [one line class summary]
0010 
0011  Implementation:
0012      [Notes on implementation]
0013 */
0014 //
0015 // Original Author:  Marco Musich
0016 //         Created:  Thu, 14 Dec 2023 15:10:34 GMT
0017 //
0018 //
0019 
0020 // system include files
0021 #include <memory>
0022 
0023 // user include files
0024 #include "FWCore/Framework/interface/Frameworkfwd.h"
0025 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0026 
0027 #include "FWCore/Framework/interface/Event.h"
0028 #include "FWCore/Framework/interface/MakerMacros.h"
0029 
0030 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0031 #include "FWCore/Utilities/interface/InputTag.h"
0032 #include "DataFormats/TrackReco/interface/Track.h"
0033 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0034 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0035 #include "FWCore/ServiceRegistry/interface/Service.h"
0036 #include "DataFormats/Candidate/interface/VertexCompositeCandidate.h"
0037 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidate.h"
0038 
0039 #include "TLorentzVector.h"
0040 
0041 //
0042 // class declaration
0043 //
0044 
0045 // If the analyzer does not use TFileService, please remove
0046 // the template argument to the base class so the class inherits
0047 // from  edm::one::EDAnalyzer<>
0048 // This will improve performance in multithreaded jobs.
0049 
0050 using reco::TrackCollection;
0051 
0052 class TkAlV0sAnalyzer : public edm::one::EDAnalyzer<edm::one::SharedResources> {
0053 public:
0054   explicit TkAlV0sAnalyzer(const edm::ParameterSet&);
0055   ~TkAlV0sAnalyzer() override = default;
0056 
0057   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0058 
0059 private:
0060   template <typename T, typename... Args>
0061   T* book(const Args&... args) const;
0062   void beginJob() override;
0063   void analyze(const edm::Event&, const edm::EventSetup&) override;
0064 
0065   // ----------member data ---------------------------
0066   const edm::EDGetTokenT<TrackCollection> tracksToken_;  //used to select what tracks to read from configuration file
0067   const edm::EDGetTokenT<reco::VertexCompositeCandidateCollection> vccToken_;
0068   edm::Service<TFileService> fs_;
0069 
0070   TH1F* h_diTrackMass;
0071   TH1F* h_V0Mass;
0072 };
0073 
0074 static constexpr double piMass2 = 0.13957018 * 0.13957018;
0075 
0076 //
0077 // constructors and destructor
0078 //
0079 TkAlV0sAnalyzer::TkAlV0sAnalyzer(const edm::ParameterSet& iConfig)
0080     : tracksToken_(consumes<TrackCollection>(iConfig.getUntrackedParameter<edm::InputTag>("tracks"))),
0081       vccToken_(consumes<reco::VertexCompositeCandidateCollection>(
0082           iConfig.getParameter<edm::InputTag>("vertexCompositeCandidates"))) {
0083   usesResource(TFileService::kSharedResource);
0084 }
0085 
0086 template <typename T, typename... Args>
0087 T* TkAlV0sAnalyzer::book(const Args&... args) const {
0088   T* t = fs_->make<T>(args...);
0089   return t;
0090 }
0091 
0092 //
0093 // member functions
0094 //
0095 // ------------ method called for each event  ------------
0096 void TkAlV0sAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0097   using namespace edm;
0098 
0099   std::vector<const reco::Track*> myTracks;
0100 
0101   edm::Handle<reco::VertexCompositeCandidateCollection> vccHandle;
0102   iEvent.getByToken(vccToken_, vccHandle);
0103 
0104   if (vccHandle->empty())
0105     return;
0106 
0107   reco::VertexCompositeCandidateCollection v0s = *vccHandle.product();
0108 
0109   for (const auto& track : iEvent.get(tracksToken_)) {
0110     myTracks.emplace_back(&track);
0111   }
0112 
0113   // exclude multiple candidates
0114   if (myTracks.size() != 2)
0115     return;
0116 
0117   for (const auto& v0 : v0s) {
0118     float mass = v0.mass();
0119     h_V0Mass->Fill(mass);
0120 
0121     for (size_t i = 0; i < v0.numberOfDaughters(); ++i) {
0122       //LogPrint("AlignmentTrackFromVertexCompositeCandidateSelector") << "daughter: " << i << std::endl;
0123       const reco::Candidate* daughter = v0.daughter(i);
0124       const reco::RecoChargedCandidate* chargedDaughter = dynamic_cast<const reco::RecoChargedCandidate*>(daughter);
0125       if (chargedDaughter) {
0126         //LogPrint("AlignmentTrackFromVertexCompositeCandidateSelector") << "charged daughter: " << i << std::endl;
0127         const reco::TrackRef trackRef = chargedDaughter->track();
0128         if (trackRef.isNonnull()) {
0129           // LogPrint("AlignmentTrackFromVertexCompositeCandidateSelector")
0130           // << "charged daughter has non-null trackref: " << i << std::endl;
0131         }
0132       }
0133     }
0134   }
0135 
0136   const auto& tplus = myTracks[0]->charge() > 0 ? myTracks[0] : myTracks[1];
0137   const auto& tminus = myTracks[0]->charge() < 0 ? myTracks[0] : myTracks[1];
0138 
0139   TLorentzVector p4_tplus(tplus->px(), tplus->py(), tplus->pz(), sqrt((tplus->p() * tplus->p()) + piMass2));
0140   TLorentzVector p4_tminus(tminus->px(), tminus->py(), tminus->pz(), sqrt((tminus->p() * tminus->p()) + piMass2));
0141 
0142   const auto& V0p4 = p4_tplus + p4_tminus;
0143   float track_invMass = V0p4.M();
0144   h_diTrackMass->Fill(track_invMass);
0145 }
0146 
0147 void TkAlV0sAnalyzer::beginJob() {
0148   h_diTrackMass = book<TH1F>("diTrackMass", "V0 mass from tracks in Event", 100, 0.400, 0.600);
0149   h_V0Mass = book<TH1F>("V0kMass", "Reconstructed V0 mass in Event", 100, 0.400, 0.600);
0150 }
0151 
0152 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0153 void TkAlV0sAnalyzer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0154   edm::ParameterSetDescription desc;
0155   desc.add<edm::InputTag>("vertexCompositeCandidates", edm::InputTag("generalV0Candidates:Kshort"));
0156   desc.addUntracked<edm::InputTag>("tracks", edm::InputTag("ALCARECOTkAlKShortTracks"));
0157   descriptions.addWithDefaultLabel(desc);
0158 }
0159 
0160 //define this as a plug-in
0161 DEFINE_FWK_MODULE(TkAlV0sAnalyzer);