CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HLTL1MuonMatcher.cc
Go to the documentation of this file.
1 //
2 // $Id: HLTL1MuonMatcher.cc,v 1.3 2010/07/12 20:56:11 gpetrucc Exp $
3 //
4 
17 
20 
25 
28 
30 
32 
33 namespace pat {
34 
36  public:
37  explicit HLTL1MuonMatcher(const edm::ParameterSet & iConfig);
38  virtual ~HLTL1MuonMatcher() { }
39 
40  virtual void produce(edm::Event & iEvent, const edm::EventSetup & iSetup);
41 
42  virtual void beginRun(edm::Run & iRun, const edm::EventSetup & iSetup);
43 
44 
46  bool operator()(const pat::TriggerObjectStandAlone &l1) const {
47  if (resolveAmbiguities_ && (std::find(lockedItems_.begin(), lockedItems_.end(), &l1) != lockedItems_.end())) return false;
48  return selector_(0,l1);
49  }
50  private:
54 
56 
59 
64 
66  std::string labelProp_;
67 
70 
72  template<typename Hand, typename T>
74  const Hand & handle,
75  const std::vector<T> & values,
76  const std::string & label) const ;
77 
78  // for ambiguity resolution
79  std::vector<const pat::TriggerObjectStandAlone *> lockedItems_;
80  };
81 
82 } // namespace
83 
85  matcher_(iConfig),
86  reco_(iConfig.getParameter<edm::InputTag>("src")),
87  l1_(iConfig.getParameter<edm::InputTag>("matched")),
88  selector_(iConfig),
89  resolveAmbiguities_(iConfig.getParameter<bool>("resolveAmbiguities")),
90  labelProp_(iConfig.getParameter<std::string>("setPropLabel")),
91  writeExtraInfo_(iConfig.existsAs<bool>("writeExtraInfo") ? iConfig.getParameter<bool>("writeExtraInfo") : false)
92 {
93  produces<PATPrimitiveCollection>("propagatedReco"); // reco to muon station 2
94  produces<PATTriggerAssociation>("propagatedReco"); // asso reco to propagated reco
95  produces<PATTriggerAssociation>(); // asso reco to l1
96  if (writeExtraInfo_) {
97  produces<edm::ValueMap<float> >("deltaR");
98  produces<edm::ValueMap<float> >("deltaPhi");
99  }
100 }
101 
102 void
104  using namespace edm;
105  using namespace std;
106 
109 
110  iEvent.getByLabel(reco_, reco);
111  iEvent.getByLabel(l1_, l1s);
112 
113  auto_ptr<PATPrimitiveCollection> propOut(new PATPrimitiveCollection());
114  vector<int> propMatches(reco->size(), -1);
115  vector<int> fullMatches(reco->size(), -1);
116  vector<float> deltaRs(reco->size(), 999), deltaPhis(reco->size(), 999);
117  lockedItems_.clear();
118  for (int i = 0, n = reco->size(); i < n; ++i) {
119  TrajectoryStateOnSurface propagated;
120  const reco::Candidate &mu = (*reco)[i];
121  int match = matcher_.matchGeneric(mu, *l1s, *this, deltaRs[i], deltaPhis[i], propagated);
122  if (propagated.isValid()) {
123  GlobalPoint pos = propagated.globalPosition();
124  propMatches[i] = propOut->size();
125  propOut->push_back(PATPrimitive(math::PtEtaPhiMLorentzVector(mu.pt(), pos.eta(), pos.phi(), mu.mass())));
126  propOut->back().addFilterLabel(labelProp_);
127  propOut->back().setCharge(mu.charge());
128  }
129  fullMatches[i] = match;
130  if (match != -1) {
131  lockedItems_.push_back(&(*l1s)[match]);
132  }
133  }
134  lockedItems_.clear();
135 
136  OrphanHandle<PATPrimitiveCollection> propDone = iEvent.put(propOut, "propagatedReco");
137 
138  auto_ptr<PATTriggerAssociation> propAss(new PATTriggerAssociation(propDone));
139  PATTriggerAssociation::Filler propFiller(*propAss);
140  propFiller.insert(reco, propMatches.begin(), propMatches.end());
141  propFiller.fill();
142  iEvent.put(propAss, "propagatedReco");
143 
144  auto_ptr<PATTriggerAssociation> fullAss(new PATTriggerAssociation(l1s));
145  PATTriggerAssociation::Filler fullFiller(*fullAss);
146  fullFiller.insert(reco, fullMatches.begin(), fullMatches.end());
147  fullFiller.fill();
148  iEvent.put(fullAss);
149 
150  if (writeExtraInfo_) {
151  storeExtraInfo(iEvent, reco, deltaRs, "deltaR");
152  storeExtraInfo(iEvent, reco, deltaPhis, "deltaPhi");
153  }
154 }
155 
156 template<typename Hand, typename T>
157 void
159  const Hand & handle,
160  const std::vector<T> & values,
161  const std::string & label) const {
162  using namespace edm; using namespace std;
163  auto_ptr<ValueMap<T> > valMap(new ValueMap<T>());
164  typename edm::ValueMap<T>::Filler filler(*valMap);
165  filler.insert(handle, values.begin(), values.end());
166  filler.fill();
167  iEvent.put(valMap, label);
168 }
169 
170 
171 void
173  matcher_.init(iSetup);
174 }
175 
176 
178 using namespace pat;
int i
Definition: DBlmapReader.cc:9
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup)
virtual double pt() const =0
transverse momentum
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual double mass() const =0
mass
Geom::Phi< T > phi() const
Definition: PV3DBase.h:68
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
GlobalPoint globalPosition() const
L1MuonMatcherAlgo matcher_
std::vector< TriggerObjectStandAlone > TriggerObjectStandAloneCollection
Collection of TriggerObjectStandAlone.
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
std::vector< const pat::TriggerObjectStandAlone * > lockedItems_
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
Definition: LorentzVector.h:26
int iEvent
Definition: GenABIO.cc:243
pat::TriggerObjectStandAlone PATPrimitive
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
pat::TriggerObjectStandAloneCollection PATPrimitiveCollection
tuple handle
Definition: patZpeak.py:22
virtual int charge() const =0
electric charge
const int mu
Definition: Constants.h:23
bool writeExtraInfo_
Write out additional info as ValueMaps.
virtual void beginRun(edm::Run &iRun, const edm::EventSetup &iSetup)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
void storeExtraInfo(edm::Event &iEvent, const Hand &handle, const std::vector< T > &values, const std::string &label) const
Store extra information in a ValueMap.
edm::InputTag reco_
Labels for input collections.
pat::PATTriggerMatchSelector< bool, PATPrimitive > selector_
T eta() const
Definition: PV3DBase.h:75
HLTL1MuonMatcher(const edm::ParameterSet &iConfig)
Matcher of reconstructed objects to L1 Muons.
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:6
std::string labelProp_
Labels to set as filter names in the output.
bool operator()(const pat::TriggerObjectStandAlone &l1) const
select L1s with patName_ and filterLabel_ (public, so it can be used by L1MuonMatcherAlgo) ...
pat::TriggerObjectStandAloneMatch PATTriggerAssociation
Definition: Run.h:33
Analysis-level trigger object class (stand-alone)