CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TagProbeMassProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: TagProbeMassProducer
4 // Class: TagProbeMassProducer
5 //
13 //
14 // Original Author: Nadia Adam
15 // Created: Wed Apr 16 09:46:30 CDT 2008
16 // $Id: TagProbeMassProducer.cc,v 1.1 2010/05/04 09:42:40 azzi Exp $
17 //
18 //
19 
20 
21 // User includes
23 //#include "PhysicsTools/TagAndProbe/interface/CandidateAssociation.h"
27 
29 //#include "DataFormats/MuonReco/interface/Muon.h"
30 //#include "DataFormats/MuonReco/interface/MuonFwd.h"
31 
34 
35 #include "Math/GenVector/VectorUtil.h"
36 
38 {
39  tagCollection_ = iConfig.getParameter<edm::InputTag>("TagCollection");
40  probeCollection_ = iConfig.getParameter<edm::InputTag>("ProbeCollection");
41  passingProbeCollection_ = iConfig.getParameter<edm::InputTag>("PassingProbeCollection");
42 
43  massMinCut_ = iConfig.getUntrackedParameter<double>("MassMinCut",50.0);
44  massMaxCut_ = iConfig.getUntrackedParameter<double>("MassMaxCut",120.0);
45  delRMinCut_ = iConfig.getUntrackedParameter<double>("DelRMinCut",0.0);
46  delRMaxCut_ = iConfig.getUntrackedParameter<double>("DelRMaxCut",10000.0);
47 
48  requireOS_ = iConfig.getUntrackedParameter<bool>("RequireOS",true);
49 
50  produces<std::vector<float> >("TPmass");
51 }
52 
53 
55 {
56 
57 }
58 
59 
60 //
61 // member functions
62 //
63 
64 // ------------ method called to produce the data ------------
65 void
67 {
68 
69  // We need the output Muon association collection to fill
70  std::auto_ptr<std::vector<float> > TPmass( new std::vector<float>);
71 
72  if ( !iEvent.getByLabel( tagCollection_, tags ) ) {
73  edm::LogWarning("TagProbe") << "Could not extract tag muons with input tag "
74  << tagCollection_;
75  }
76 
77  if ( !iEvent.getByLabel( probeCollection_, probes ) ) {
78  edm::LogWarning("TagProbe") << "Could not extract probe muons with input tag "
80  }
81 
83  edm::LogWarning("TagProbe") << "Could not extract passing probe muons with input tag "
85  }
86 
87  // Loop over Tag and associate with Probes
88  if( tags.isValid() && probes.isValid() )
89  {
91  for (size_t i = 0; i < tags->size(); ++i) {
92  vtags.push_back(tags->refAt(i));
93  }
95  for (size_t i = 0; i < probes->size(); ++i) {
96  vprobes.push_back(probes->refAt(i));
97  }
98 
99  int itag = 0;
101  for( ; tag != vtags.end(); ++tag, ++itag )
102  {
103  int iprobe = 0;
105  for( ; probe != vprobes.end(); ++probe, ++iprobe )
106  {
107  // Tag-Probe invariant mass cut
108  double invMass = ROOT::Math::VectorUtil::InvariantMass((*tag)->p4(), (*probe)->p4());
109  if( invMass < massMinCut_ ) continue;
110  if( invMass > massMaxCut_ ) continue;
111 
112  // Tag-Probe deltaR cut
113  double delR = reco::deltaR<double>((*tag)->eta(),(*tag)->phi(),(*probe)->eta(),(*probe)->phi());
114  if( delR < delRMinCut_ ) continue;
115  if( delR > delRMaxCut_ ) continue;
116 
117  // Tag-Probe opposite sign
118  int sign = (*tag)->charge() * (*probe)->charge();
119  if( requireOS_ && sign > 0 ) continue;
120 
121  bool isPassing = isPassingProbe (iprobe);
122 
123  if (isPassing) TPmass->push_back(invMass);
124  }
125  }
126  }
127 
128  // Finally put the tag probe collection in the event
129  iEvent.put( TPmass,"TPmass" );
130 }
131 
132 // ------------ method called once each job just before starting event loop ------------
133 void
135 {
136 }
137 
138 // ------------ method called once each job just after ending the event loop ------------
139 void
141 }
142 
143 
144 bool TagProbeMassProducer::isPassingProbe (const unsigned int iProbe) const {
145 
146  if (iProbe > probes->size()) return false;
147 
148  edm::RefToBase<reco::Candidate> probeRef = probes->refAt(iProbe);
149  edm::RefToBase<reco::Candidate> passingProbeRef;
150 
151  unsigned int numPassingProbes = passingProbes->size();
152 
153  for (unsigned int iPassProbe = 0; iPassProbe < numPassingProbes; ++iPassProbe) {
154  passingProbeRef = passingProbes->refAt(iPassProbe);
155  if (passingProbeRef == probeRef) {
156  return true;
157  }
158  }
159  return false;
160 }
161 
162 //define this as a plug-in
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
edm::Handle< reco::CandidateView > probes
edm::InputTag passingProbeCollection_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
double sign(double x)
const_iterator end() const
edm::InputTag probeCollection_
edm::Handle< reco::CandidateView > tags
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:120
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:420
TagProbeMassProducer(const edm::ParameterSet &)
bool isPassingProbe(const unsigned int iprobe) const
const_iterator begin() const
edm::Handle< reco::CandidateView > passingProbes
void push_back(const RefToBase< T > &)
virtual void produce(edm::Event &, const edm::EventSetup &) override