Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-09-07 22:41:51

0001 // -*- C++ -*-
0002 //
0003 // Package:    TagProbeMassProducer
0004 // Class:      TagProbeMassProducer
0005 //
0006 /**\class TagProbeMassProducer TagProbeMassProducer.cc PhysicsTools/TagProbeMassProducer/src/TagProbeMassProducer.cc
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Nadia Adam
0015 //         Created:  Wed Apr 16 09:46:30 CDT 2008
0016 // $Id: TagProbeMassProducer.cc,v 1.1 2010/05/04 09:42:40 azzi Exp $
0017 //
0018 //
0019 
0020 // User includes
0021 #include "DPGAnalysis/Skims/interface/TagProbeMassProducer.h"
0022 //#include "PhysicsTools/TagAndProbe/interface/CandidateAssociation.h"
0023 #include "DataFormats/Candidate/interface/Candidate.h"
0024 #include "DataFormats/Candidate/interface/CandidateFwd.h"
0025 #include "DataFormats/Common/interface/AssociationMap.h"
0026 
0027 #include "DataFormats/Math/interface/deltaR.h"
0028 //#include "DataFormats/MuonReco/interface/Muon.h"
0029 //#include "DataFormats/MuonReco/interface/MuonFwd.h"
0030 
0031 #include "FWCore/Framework/interface/MakerMacros.h"
0032 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0033 
0034 #include "Math/GenVector/VectorUtil.h"
0035 
0036 TagProbeMassProducer::TagProbeMassProducer(const edm::ParameterSet& iConfig) {
0037   tagCollection_ = iConfig.getParameter<edm::InputTag>("TagCollection");
0038   probeCollection_ = iConfig.getParameter<edm::InputTag>("ProbeCollection");
0039   passingProbeCollection_ = iConfig.getParameter<edm::InputTag>("PassingProbeCollection");
0040 
0041   massMinCut_ = iConfig.getUntrackedParameter<double>("MassMinCut", 50.0);
0042   massMaxCut_ = iConfig.getUntrackedParameter<double>("MassMaxCut", 120.0);
0043   delRMinCut_ = iConfig.getUntrackedParameter<double>("DelRMinCut", 0.0);
0044   delRMaxCut_ = iConfig.getUntrackedParameter<double>("DelRMaxCut", 10000.0);
0045 
0046   requireOS_ = iConfig.getUntrackedParameter<bool>("RequireOS", true);
0047 
0048   produces<std::vector<float> >("TPmass");
0049 }
0050 
0051 TagProbeMassProducer::~TagProbeMassProducer() {}
0052 
0053 //
0054 // member functions
0055 //
0056 
0057 // ------------ method called to produce the data  ------------
0058 void TagProbeMassProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0059   // We need the output Muon association collection to fill
0060   std::unique_ptr<std::vector<float> > TPmass(new std::vector<float>);
0061 
0062   if (!iEvent.getByLabel(tagCollection_, tags)) {
0063     edm::LogWarning("TagProbe") << "Could not extract tag muons with input tag " << tagCollection_;
0064   }
0065 
0066   if (!iEvent.getByLabel(probeCollection_, probes)) {
0067     edm::LogWarning("TagProbe") << "Could not extract probe muons with input tag " << probeCollection_;
0068   }
0069 
0070   if (!iEvent.getByLabel(passingProbeCollection_, passingProbes)) {
0071     edm::LogWarning("TagProbe") << "Could not extract passing probe muons with input tag " << passingProbeCollection_;
0072   }
0073 
0074   // Loop over Tag and associate with Probes
0075   if (tags.isValid() && probes.isValid()) {
0076     edm::RefToBaseVector<reco::Candidate> vtags;
0077     for (size_t i = 0; i < tags->size(); ++i) {
0078       vtags.push_back(tags->refAt(i));
0079     }
0080     edm::RefToBaseVector<reco::Candidate> vprobes;
0081     for (size_t i = 0; i < probes->size(); ++i) {
0082       vprobes.push_back(probes->refAt(i));
0083     }
0084 
0085     int itag = 0;
0086     edm::RefToBaseVector<reco::Candidate>::const_iterator tag = vtags.begin();
0087     for (; tag != vtags.end(); ++tag, ++itag) {
0088       int iprobe = 0;
0089       edm::RefToBaseVector<reco::Candidate>::const_iterator probe = vprobes.begin();
0090       for (; probe != vprobes.end(); ++probe, ++iprobe) {
0091         // Tag-Probe invariant mass cut
0092         double invMass = ROOT::Math::VectorUtil::InvariantMass((*tag)->p4(), (*probe)->p4());
0093         if (invMass < massMinCut_)
0094           continue;
0095         if (invMass > massMaxCut_)
0096           continue;
0097 
0098         // Tag-Probe deltaR cut
0099         double delR = reco::deltaR<double>((*tag)->eta(), (*tag)->phi(), (*probe)->eta(), (*probe)->phi());
0100         if (delR < delRMinCut_)
0101           continue;
0102         if (delR > delRMaxCut_)
0103           continue;
0104 
0105         // Tag-Probe opposite sign
0106         int sign = (*tag)->charge() * (*probe)->charge();
0107         if (requireOS_ && sign > 0)
0108           continue;
0109 
0110         bool isPassing = isPassingProbe(iprobe);
0111 
0112         if (isPassing)
0113           TPmass->push_back(invMass);
0114       }
0115     }
0116   }
0117 
0118   // Finally put the tag probe collection in the event
0119   iEvent.put(std::move(TPmass), "TPmass");
0120 }
0121 
0122 bool TagProbeMassProducer::isPassingProbe(const unsigned int iProbe) const {
0123   if (iProbe > probes->size())
0124     return false;
0125 
0126   edm::RefToBase<reco::Candidate> probeRef = probes->refAt(iProbe);
0127   edm::RefToBase<reco::Candidate> passingProbeRef;
0128 
0129   unsigned int numPassingProbes = passingProbes->size();
0130 
0131   for (unsigned int iPassProbe = 0; iPassProbe < numPassingProbes; ++iPassProbe) {
0132     passingProbeRef = passingProbes->refAt(iPassProbe);
0133     if (passingProbeRef == probeRef) {
0134       return true;
0135     }
0136   }
0137   return false;
0138 }
0139 
0140 //define this as a plug-in
0141 DEFINE_FWK_MODULE(TagProbeMassProducer);