Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:45:14

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;
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 ZMuMuMassConstraintParameterFinder ::~ZMuMuMassConstraintParameterFinder() {}
0121 
0122 //
0123 // member functions
0124 //
0125 
0126 // ------------ method called for each event  ------------
0127 void ZMuMuMassConstraintParameterFinder ::analyze(const edm::Event& iEvent, const edm::EventSetup&) {
0128   edm::Handle<reco::GenParticleCollection> genParticles;
0129   iEvent.getByToken(genParticlesToken_, genParticles);
0130 
0131   for (const auto& particle : *(genParticles.product())) {
0132     if (std::abs(particle.pdgId()) != muonPdg_ || particle.status() != 1)
0133       continue;
0134     if (particle.p() < pMin_)
0135       continue;
0136     if (particle.pt() < ptMin_)
0137       continue;
0138     if (particle.eta() < etaMin_ || particle.eta() > etaMax_)
0139       continue;
0140     if (particle.phi() < phiMin_ || particle.phi() > phiMax_)
0141       continue;
0142 
0143     muonInfo_.muons().push_back(particle);
0144     if (particle.mother()->pdgId() == zBosonPdg_) {
0145       muonInfoFromZ_.muons().push_back(particle);
0146     }
0147   }
0148 
0149   muonInfo_.fill();
0150   muonInfoFromZ_.fill();
0151 }
0152 
0153 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0154 void ZMuMuMassConstraintParameterFinder ::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0155   edm::ParameterSetDescription desc;
0156   desc.setComment("Extract information on 'Z -> mu mu' decays.");
0157   desc.add<double>("pMin", 3.0);
0158   desc.add<double>("ptMin", 15.0);
0159   desc.add<double>("etaMin", -3.0);
0160   desc.add<double>("etaMax", 3.0);
0161   desc.add<double>("phiMin", -3.1416);
0162   desc.add<double>("phiMax", 3.1416);
0163   desc.add<double>("minMassPair", 85.8);
0164   desc.add<double>("maxMassPair", 95.8);
0165   descriptions.add("zMuMuMassConstraintParameterFinder", desc);
0166 }
0167 
0168 // ------------ helper class definition ------------
0169 ZMuMuMassConstraintParameterFinder ::DiMuonInfo ::DiMuonInfo(double minMass, double maxMass)
0170     : minMassPair_{minMass}, maxMassPair_{maxMass} {}
0171 
0172 void ZMuMuMassConstraintParameterFinder ::DiMuonInfo ::setupTree(const std::string& name,
0173                                                                  edm::Service<TFileService>& fs) {
0174   tree_ = fs->make<TTree>(name.c_str(), name.c_str());
0175   tree_->Branch("muons", &muons_);
0176   tree_->Branch("di_muon_mass", &diMuonMass_);
0177   tree_->Branch("pdg_mother", &pdgMother_);
0178   tree_->Branch("in_mass_window", &passed_);
0179 }
0180 
0181 void ZMuMuMassConstraintParameterFinder ::DiMuonInfo ::fill() {
0182   if (muons_.size() == 2) {
0183     diMuonMass_ = (muons_[0].p4() + muons_[1].p4()).M();
0184     pdgMother_ = muons_[0].mother()->pdgId();
0185     if (diMuonMass_ > minMassPair_ && diMuonMass_ < maxMassPair_)
0186       passed_ = true;
0187     tree_->Fill();
0188   }
0189   muons_.clear();
0190   diMuonMass_ = -1.0;
0191   pdgMother_ = 0;
0192   passed_ = false;
0193 }
0194 
0195 //define this as a plug-in
0196 DEFINE_FWK_MODULE(ZMuMuMassConstraintParameterFinder);