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 //
3 
16 
19 
24 
27 
29 
31 
32 namespace pat {
33 
35  public:
36  explicit HLTL1MuonMatcher(const edm::ParameterSet & iConfig);
37  virtual ~HLTL1MuonMatcher() { }
38 
39  virtual void produce(edm::Event & iEvent, const edm::EventSetup& iSetup) override;
40 
41  virtual void beginRun(const edm::Run & iRun, const edm::EventSetup& iSetup) override;
42 
43 
45  bool operator()(const pat::TriggerObjectStandAlone &l1) const {
46  if (resolveAmbiguities_ && (std::find(lockedItems_.begin(), lockedItems_.end(), &l1) != lockedItems_.end())) return false;
47  return selector_(0,l1);
48  }
49  private:
53 
55 
58 
63 
66 
69 
71  template<typename Hand, typename T>
73  const Hand & handle,
74  const std::vector<T> & values,
75  const std::string & label) const ;
76 
77  // for ambiguity resolution
78  std::vector<const pat::TriggerObjectStandAlone *> lockedItems_;
79  };
80 
81 } // namespace
82 
84  matcher_(iConfig),
85  reco_(iConfig.getParameter<edm::InputTag>("src")),
86  l1_(iConfig.getParameter<edm::InputTag>("matched")),
87  selector_(iConfig),
88  resolveAmbiguities_(iConfig.getParameter<bool>("resolveAmbiguities")),
89  labelProp_(iConfig.getParameter<std::string>("setPropLabel")),
90  writeExtraInfo_(iConfig.existsAs<bool>("writeExtraInfo") ? iConfig.getParameter<bool>("writeExtraInfo") : false)
91 {
92  produces<PATPrimitiveCollection>("propagatedReco"); // reco to muon station 2
93  produces<PATTriggerAssociation>("propagatedReco"); // asso reco to propagated reco
94  produces<PATTriggerAssociation>(); // asso reco to l1
95  if (writeExtraInfo_) {
96  produces<edm::ValueMap<float> >("deltaR");
97  produces<edm::ValueMap<float> >("deltaPhi");
98  }
99 }
100 
101 void
103  using namespace edm;
104  using namespace std;
105 
108 
109  iEvent.getByLabel(reco_, reco);
110  iEvent.getByLabel(l1_, l1s);
111 
112  auto_ptr<PATPrimitiveCollection> propOut(new PATPrimitiveCollection());
113  vector<int> propMatches(reco->size(), -1);
114  vector<int> fullMatches(reco->size(), -1);
115  vector<float> deltaRs(reco->size(), 999), deltaPhis(reco->size(), 999);
116  lockedItems_.clear();
117  for (int i = 0, n = reco->size(); i < n; ++i) {
118  TrajectoryStateOnSurface propagated;
119  const reco::Candidate &mu = (*reco)[i];
120  int match = matcher_.matchGeneric(mu, *l1s, *this, deltaRs[i], deltaPhis[i], propagated);
121  if (propagated.isValid()) {
122  GlobalPoint pos = propagated.globalPosition();
123  propMatches[i] = propOut->size();
124  propOut->push_back(PATPrimitive(math::PtEtaPhiMLorentzVector(mu.pt(), pos.eta(), pos.phi(), mu.mass())));
125  propOut->back().addFilterLabel(labelProp_);
126  propOut->back().setCharge(mu.charge());
127  }
128  fullMatches[i] = match;
129  if (match != -1) {
130  lockedItems_.push_back(&(*l1s)[match]);
131  }
132  }
133  lockedItems_.clear();
134 
135  OrphanHandle<PATPrimitiveCollection> propDone = iEvent.put(propOut, "propagatedReco");
136 
137  auto_ptr<PATTriggerAssociation> propAss(new PATTriggerAssociation(propDone));
138  PATTriggerAssociation::Filler propFiller(*propAss);
139  propFiller.insert(reco, propMatches.begin(), propMatches.end());
140  propFiller.fill();
141  iEvent.put(propAss, "propagatedReco");
142 
143  auto_ptr<PATTriggerAssociation> fullAss(new PATTriggerAssociation(l1s));
144  PATTriggerAssociation::Filler fullFiller(*fullAss);
145  fullFiller.insert(reco, fullMatches.begin(), fullMatches.end());
146  fullFiller.fill();
147  iEvent.put(fullAss);
148 
149  if (writeExtraInfo_) {
150  storeExtraInfo(iEvent, reco, deltaRs, "deltaR");
151  storeExtraInfo(iEvent, reco, deltaPhis, "deltaPhi");
152  }
153 }
154 
155 template<typename Hand, typename T>
156 void
158  const Hand & handle,
159  const std::vector<T> & values,
160  const std::string & label) const {
161  using namespace edm; using namespace std;
162  auto_ptr<ValueMap<T> > valMap(new ValueMap<T>());
163  typename edm::ValueMap<T>::Filler filler(*valMap);
164  filler.insert(handle, values.begin(), values.end());
165  filler.fill();
166  iEvent.put(valMap, label);
167 }
168 
169 
170 void
172  matcher_.init(iSetup);
173 }
174 
175 
177 using namespace pat;
int i
Definition: DBlmapReader.cc:9
virtual float mass() const =0
mass
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:52
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
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:25
virtual float pt() const =0
transverse momentum
int iEvent
Definition: GenABIO.cc:243
pat::TriggerObjectStandAlone PATPrimitive
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
pat::TriggerObjectStandAloneCollection PATPrimitiveCollection
tuple handle
Definition: patZpeak.py:22
virtual int charge() const =0
electric charge
const int mu
Definition: Constants.h:22
bool writeExtraInfo_
Write out additional info as ValueMaps.
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
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.
virtual void beginRun(const edm::Run &iRun, const edm::EventSetup &iSetup) override
pat::PATTriggerMatchSelector< bool, PATPrimitive > selector_
T eta() const
Definition: PV3DBase.h:76
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.
volatile std::atomic< bool > shutdown_flag false
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:41
Analysis-level trigger object class (stand-alone)