CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DeltaRNearestObjectComputer.cc
Go to the documentation of this file.
1 /*****************************************************************************
2  * Project: CMS detector at the CERN
3  *
4  * Package: PhysicsTools/TagAndProbe
5  *
6  *
7  * Authors:
8  * Giovanni Petrucciani, UCSD - Giovanni.Petrucciani@cern.ch
9  *
10  * Description:
11  * - Matches a given object with other objects using deltaR-matching.
12  * - For example: can match a photon with track within a given deltaR.
13  * - Saves collection of the reference vectors of matched objects.
14  * History:
15  *
16  * Kalanand Mishra, Fermilab - kalanand@fnal.gov
17  * Extended the class to compute deltaR with respect to any object
18  * (i.e., Candidate, Jet, Muon, Electron, or Photon). The previous
19  * version of this class could deltaR only with respect to reco::Candidates.
20  * This didn't work if one wanted to apply selection cuts on the Candidate's
21  * RefToBase object.
22  *****************************************************************************/
23 
28 
32 
40 
42 
43 template<typename T>
45  public:
46  explicit DeltaRNearestObjectComputer(const edm::ParameterSet & iConfig);
48 
49  virtual void produce(edm::Event & iEvent, const edm::EventSetup & iSetup);
50 
51  private:
54  StringCutObjectSelector<T,true> objCut_; // lazy parsing, to allow cutting on variables not in reco::Candidate class
55 };
56 
57 template<typename T>
59  probes_(iConfig.getParameter<edm::InputTag>("probes")),
60  objects_(iConfig.getParameter<edm::InputTag>("objects")),
61  objCut_(iConfig.existsAs<std::string>("objectSelection") ? iConfig.getParameter<std::string>("objectSelection") : "", true)
62 {
63  produces<edm::ValueMap<float> >();
64 }
65 
66 
67 template<typename T>
69 {
70 }
71 
72 template<typename T>
73 void
75  using namespace edm;
76 
77  // read input
79  iEvent.getByLabel(probes_, probes);
80 
81  Handle<View<T> > objects;
82  iEvent.getByLabel(objects_, objects);
83 
84  // prepare vector for output
85  std::vector<float> values;
86 
87  // fill
88  View<reco::Candidate>::const_iterator probe, endprobes = probes->end();
89  for (probe = probes->begin(); probe != endprobes; ++probe) {
90  double dr2min = 10000;
91  for (unsigned int iObj=0; iObj<objects->size(); iObj++) {
92  const T& obj = objects->at(iObj);
93  if (!objCut_(obj)) continue;
94  double dr2 = deltaR2(*probe, obj);
95  if (dr2 < dr2min) { dr2min = dr2; }
96  }
97  values.push_back(sqrt(dr2min));
98  }
99 
100  // convert into ValueMap and store
101  std::auto_ptr<ValueMap<float> > valMap(new ValueMap<float>());
102  ValueMap<float>::Filler filler(*valMap);
103  filler.insert(probes, values.begin(), values.end());
104  filler.fill();
105  iEvent.put(valMap);
106 }
107 
108 
110 // plugin definition
112 
119 
DeltaRNearestObjectComputer< reco::GsfElectron > DeltaRNearestGsfElectronComputer
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
StringCutObjectSelector< T, true > objCut_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
DeltaRNearestObjectComputer< reco::Muon > DeltaRNearestMuonComputer
int iEvent
Definition: GenABIO.cc:243
tuple obj
Example code starts here #.
Definition: VarParsing.py:655
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:84
T sqrt(T t)
Definition: SSEVec.h:28
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:359
double deltaR2(const Vector1 &v1, const Vector2 &v2)
Definition: VectorUtil.h:78
DeltaRNearestObjectComputer< reco::Candidate > DeltaRNearestCandidateComputer
DeltaRNearestObjectComputer< reco::Electron > DeltaRNearestElectronComputer
DeltaRNearestObjectComputer< reco::Jet > DeltaRNearestJetComputer
DeltaRNearestObjectComputer(const edm::ParameterSet &iConfig)
DeltaRNearestObjectComputer< reco::Photon > DeltaRNearestPhotonComputer
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup)