Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:56:34

0001 // -*- C++ -*-
0002 //
0003 // Package:    Alignment/MillePedeAlignmentAlgorithm
0004 // Class:      ZMuMuMassConstraintParameterFinder
0005 //
0006 /**\class ZMuMuMassConstraintParameterFinder ZMuMuMassConstraintParameterFinder.cc Alignment/MillePedeAlignmentAlgorithm/plugins/ZMuMuMassConstraintParameterFinder.cc
0007 
0008    Description: Determines the generator di-muon invariant-mass distribution
0009 
0010    Implementation:
0011 
0012    Generator muons are extracted from the genParticles collection and matched to
0013    Z-boson decays. The configured selection should match the selection applied
0014    on muon tracks in real data to obtain a "true" invariant mass distribution
0015    within the selection.
0016 
0017 */
0018 //
0019 // Original Author:  Gregor Mittag
0020 //         Created:  Fri, 17 Jun 2016 09:42:56 GMT
0021 //
0022 //
0023 
0024 // system include files
0025 #include <cmath>
0026 #include <cstdlib>
0027 #include <vector>
0028 
0029 // ROOT include files
0030 #include "TTree.h"
0031 
0032 // user include files
0033 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0034 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
0035 #include "DataFormats/HepMCCandidate/interface/GenParticleFwd.h"
0036 #include "FWCore/Framework/interface/Frameworkfwd.h"
0037 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0038 #include "FWCore/Framework/interface/Event.h"
0039 #include "FWCore/Framework/interface/MakerMacros.h"
0040 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0041 #include "FWCore/ServiceRegistry/interface/Service.h"
0042 
0043 //
0044 // class declaration
0045 //
0046 
0047 class ZMuMuMassConstraintParameterFinder : public edm::one::EDAnalyzer<edm::one::SharedResources> {
0048 public:
0049   explicit ZMuMuMassConstraintParameterFinder(const edm::ParameterSet&);
0050   ~ZMuMuMassConstraintParameterFinder() override = default;
0051 
0052   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0053 
0054 private:
0055   /// helper class containing information about a di-muon system
0056   class DiMuonInfo {
0057   public:
0058     DiMuonInfo(double, double);
0059     void setupTree(const std::string&, edm::Service<TFileService>&);
0060     void fill();
0061     std::vector<reco::GenParticle>& muons() { return muons_; }
0062 
0063   private:
0064     TTree* tree_{nullptr};
0065     std::vector<reco::GenParticle> muons_;
0066     double diMuonMass_{-1.0};
0067     int pdgMother_{0};
0068     bool passed_{false};
0069 
0070     const double minMassPair_;
0071     const double maxMassPair_;
0072   };
0073 
0074   void analyze(const edm::Event&, const edm::EventSetup&) override;
0075 
0076   // ----------member data ---------------------------
0077   edm::EDGetTokenT<reco::GenParticleCollection> genParticlesToken_;
0078 
0079   // particle IDs
0080   const int muonPdg_{13};
0081   const int zBosonPdg_{23};
0082 
0083   // muon cuts
0084   const double pMin_;
0085   const double ptMin_;
0086   const double etaMin_;
0087   const double etaMax_;
0088   const double phiMin_;
0089   const double phiMax_;
0090 
0091   // di-muon cuts
0092   const double minMassPair_;
0093   const double maxMassPair_;
0094 
0095   DiMuonInfo muonInfo_;
0096   DiMuonInfo muonInfoFromZ_;
0097 };
0098 
0099 //
0100 // constructors and destructor
0101 //
0102 ZMuMuMassConstraintParameterFinder ::ZMuMuMassConstraintParameterFinder(const edm::ParameterSet& iConfig)
0103     : genParticlesToken_(consumes<reco::GenParticleCollection>(edm::InputTag{"genParticles"})),
0104       pMin_(iConfig.getParameter<double>("pMin")),
0105       ptMin_(iConfig.getParameter<double>("ptMin")),
0106       etaMin_(iConfig.getParameter<double>("etaMin")),
0107       etaMax_(iConfig.getParameter<double>("etaMax")),
0108       phiMin_(iConfig.getParameter<double>("phiMin")),
0109       phiMax_(iConfig.getParameter<double>("phiMax")),
0110       minMassPair_(iConfig.getParameter<double>("minMassPair")),
0111       maxMassPair_(iConfig.getParameter<double>("maxMassPair")),
0112       muonInfo_(minMassPair_, maxMassPair_),
0113       muonInfoFromZ_(minMassPair_, maxMassPair_) {
0114   usesResource(TFileService::kSharedResource);
0115   edm::Service<TFileService> fs;
0116   muonInfo_.setupTree("di_muon", fs);
0117   muonInfoFromZ_.setupTree("di_muon_from_Z", fs);
0118 }
0119 
0120 //
0121 // member functions
0122 //
0123 
0124 // ------------ method called for each event  ------------
0125 void ZMuMuMassConstraintParameterFinder ::analyze(const edm::Event& iEvent, const edm::EventSetup&) {
0126   edm::Handle<reco::GenParticleCollection> genParticles;
0127   iEvent.getByToken(genParticlesToken_, genParticles);
0128 
0129   for (const auto& particle : *(genParticles.product())) {
0130     if (std::abs(particle.pdgId()) != muonPdg_ || particle.status() != 1)
0131       continue;
0132     if (particle.p() < pMin_)
0133       continue;
0134     if (particle.pt() < ptMin_)
0135       continue;
0136     if (particle.eta() < etaMin_ || particle.eta() > etaMax_)
0137       continue;
0138     if (particle.phi() < phiMin_ || particle.phi() > phiMax_)
0139       continue;
0140 
0141     muonInfo_.muons().push_back(particle);
0142     if (particle.mother()->pdgId() == zBosonPdg_) {
0143       muonInfoFromZ_.muons().push_back(particle);
0144     }
0145   }
0146 
0147   muonInfo_.fill();
0148   muonInfoFromZ_.fill();
0149 }
0150 
0151 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0152 void ZMuMuMassConstraintParameterFinder ::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0153   edm::ParameterSetDescription desc;
0154   desc.setComment("Extract information on 'Z -> mu mu' decays.");
0155   desc.add<double>("pMin", 3.0);
0156   desc.add<double>("ptMin", 15.0);
0157   desc.add<double>("etaMin", -3.0);
0158   desc.add<double>("etaMax", 3.0);
0159   desc.add<double>("phiMin", -M_PI);
0160   desc.add<double>("phiMax", M_PI);
0161   desc.add<double>("minMassPair", 85.8);
0162   desc.add<double>("maxMassPair", 95.8);
0163   descriptions.add("zMuMuMassConstraintParameterFinder", desc);
0164 }
0165 
0166 // ------------ helper class definition ------------
0167 ZMuMuMassConstraintParameterFinder ::DiMuonInfo ::DiMuonInfo(double minMass, double maxMass)
0168     : minMassPair_{minMass}, maxMassPair_{maxMass} {}
0169 
0170 void ZMuMuMassConstraintParameterFinder ::DiMuonInfo ::setupTree(const std::string& name,
0171                                                                  edm::Service<TFileService>& fs) {
0172   tree_ = fs->make<TTree>(name.c_str(), name.c_str());
0173   tree_->Branch("muons", &muons_);
0174   tree_->Branch("di_muon_mass", &diMuonMass_);
0175   tree_->Branch("pdg_mother", &pdgMother_);
0176   tree_->Branch("in_mass_window", &passed_);
0177 }
0178 
0179 void ZMuMuMassConstraintParameterFinder ::DiMuonInfo ::fill() {
0180   if (muons_.size() == 2) {
0181     diMuonMass_ = (muons_[0].p4() + muons_[1].p4()).M();
0182     pdgMother_ = muons_[0].mother()->pdgId();
0183     if (diMuonMass_ > minMassPair_ && diMuonMass_ < maxMassPair_)
0184       passed_ = true;
0185     tree_->Fill();
0186   }
0187   muons_.clear();
0188   diMuonMass_ = -1.0;
0189   pdgMother_ = 0;
0190   passed_ = false;
0191 }
0192 
0193 //define this as a plug-in
0194 DEFINE_FWK_MODULE(ZMuMuMassConstraintParameterFinder);