CMS 3D CMS Logo

HLTScoutingMuonProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: HLTrigger/Muon
4 // Class: HLTScoutingMuonProducer
5 //
11 //
12 // Original Author: David G. Sheffield (Rutgers)
13 // Created: Fri, 31 Jul 2015
14 //
15 //
16 
19 #include "TMath.h"
20 
21 //
22 // constructors and destructor
23 //
25  ChargedCandidateCollection_(consumes<reco::RecoChargedCandidateCollection>
26  (iConfig.getParameter<edm::InputTag>("ChargedCandidates"))),
27  TrackCollection_(consumes<reco::TrackCollection>
28  (iConfig.getParameter<edm::InputTag>("Tracks"))),
29  EcalPFClusterIsoMap_(consumes<RecoChargedCandMap>(iConfig.getParameter<edm::InputTag>(
30  "EcalPFClusterIsoMap"))),
31  HcalPFClusterIsoMap_(consumes<RecoChargedCandMap>(iConfig.getParameter<edm::InputTag>(
32  "HcalPFClusterIsoMap"))),
33  TrackIsoMap_(consumes<edm::ValueMap<double>>(iConfig.getParameter<edm::InputTag>(
34  "TrackIsoMap"))),
35  displacedvertexCollection_(consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("displacedvertexCollection"))),
36  muonPtCut(iConfig.getParameter<double>("muonPtCut")),
37  muonEtaCut(iConfig.getParameter<double>("muonEtaCut")),
38  minVtxProbCut(iConfig.getParameter<double>("minVtxProbCut"))
39 {
40  //register products
41  produces<ScoutingMuonCollection>();
42  produces<ScoutingVertexCollection>("displacedVtx");
43 }
44 
46 
47 // ------------ method called to produce the data ------------
49  edm::EventSetup const & setup) const
50 {
51  using namespace edm;
52 
53  std::unique_ptr<ScoutingMuonCollection> outMuons(new ScoutingMuonCollection());
54  std::unique_ptr<ScoutingVertexCollection> dispVertices(new ScoutingVertexCollection());
55 
56  // Get RecoChargedCandidate
57  Handle<reco::RecoChargedCandidateCollection> ChargedCandidateCollection;
58  if(!iEvent.getByToken(ChargedCandidateCollection_, ChargedCandidateCollection)){
59  iEvent.put(std::move(outMuons));
60  return;
61  }
62 
63  // Get Track
65  if(!iEvent.getByToken(TrackCollection_, TrackCollection)){
66  iEvent.put(std::move(outMuons));
67  return;
68  }
69 
70  // Get EcalPFClusterIsoMap
71  Handle<RecoChargedCandMap> EcalPFClusterIsoMap;
72  iEvent.getByToken(EcalPFClusterIsoMap_, EcalPFClusterIsoMap);
73 
74  // Get HcalPFClusterIsoMap
75  Handle<RecoChargedCandMap> HcalPFClusterIsoMap;
76  iEvent.getByToken(HcalPFClusterIsoMap_, HcalPFClusterIsoMap);
77 
78  // Get TrackIsoMap
79  Handle<ValueMap<double>> TrackIsoMap;
80  if(!iEvent.getByToken(TrackIsoMap_, TrackIsoMap)){
81  iEvent.put(std::move(outMuons));
82  return;
83  }
84 
85  std::pair<reco::RecoChargedCandidate,reco::RecoChargedCandidate> ivtxMuPair;
86  std::vector<std::pair<reco::RecoChargedCandidate,reco::RecoChargedCandidate> > vtxMuPair;
87 
88  //get displaced vertices
89  Handle<reco::VertexCollection> displacedvertexCollection;
90  if(iEvent.getByToken(displacedvertexCollection_, displacedvertexCollection)){
91 
92  for(auto &dispvtx : *displacedvertexCollection){
93  if ( !dispvtx.isValid() ) continue ;
94  float vtxProb = 0.0;
95  if( (dispvtx.chi2()>=0.0) && (dispvtx.ndof()>0) ) vtxProb = TMath::Prob(dispvtx.chi2(), dispvtx.ndof() );
96  if (vtxProb < minVtxProbCut) continue;
97 
98  // Get the 2 tracks associated to displaced vertex
99  auto trackIt = dispvtx.tracks_begin();
100  reco::TrackRef vertextkRef1 = (*trackIt).castTo<reco::TrackRef>() ;
101  trackIt++;
102  reco::TrackRef vertextkRef2 = (*trackIt).castTo<reco::TrackRef>();
103 
104  // Get the muons associated with the tracks
105  int iFoundRefs = 0;
106  for (auto const & cand : *ChargedCandidateCollection) {
107  reco::TrackRef tkRef = cand.get<reco::TrackRef>();
108  if(tkRef == vertextkRef1) {ivtxMuPair.first= cand; iFoundRefs++ ;}
109  if(tkRef == vertextkRef2) {ivtxMuPair.second= cand; iFoundRefs++ ;}
110  }
111  if (iFoundRefs<2) continue;
112  vtxMuPair.push_back(ivtxMuPair);
113 
114  dispVertices->emplace_back(
115  dispvtx.x(), dispvtx.y(), dispvtx.z(),
116  dispvtx.zError(), dispvtx.xError(),
117  dispvtx.yError(), dispvtx.tracksSize(),
118  dispvtx.chi2(), dispvtx.ndof(), dispvtx.isValid()
119  );
120 
121  }
122  }
123 
124  // Produce muons
125  std::vector<int> vtxInd;
126  float minDR2=1e-06;
127  int index = 0;
128  for (auto &muon : *ChargedCandidateCollection) {
129  reco::RecoChargedCandidateRef muonRef = getRef(ChargedCandidateCollection, index);
130  ++index;
131  if (muonRef.isNull() || !muonRef.isAvailable())
132  continue;
133 
134  reco::TrackRef track = muon.track();
135  if (track.isNull() || !track.isAvailable())
136  continue;
137 
138  if (muon.pt() < muonPtCut)
139  continue;
140  if (fabs(muon.eta()) > muonEtaCut)
141  continue;
142 
143  double ecalisopf=-1.0;
144  if ( EcalPFClusterIsoMap.isValid()) { ecalisopf = (*EcalPFClusterIsoMap)[muonRef]; }
145 
146  double hcalisopf=-1.0;
147  if ( HcalPFClusterIsoMap.isValid()) { hcalisopf = (*HcalPFClusterIsoMap)[muonRef]; }
148 
149  for (unsigned int i=0; i<vtxMuPair.size(); i++) {
150  float dr2_1 = reco::deltaR2( ((vtxMuPair[i]).first),muon );
151  float dr2_2 = reco::deltaR2( ((vtxMuPair[i]).second),muon );
152  if ( (dr2_1<minDR2) || (dr2_2<minDR2) ) vtxInd.push_back(i) ;
153  }
154 
155  outMuons->emplace_back(muon.pt(), muon.eta(), muon.phi(), muon.mass(),
156  ecalisopf, hcalisopf,
157  (*TrackIsoMap)[muonRef], track->chi2(), track->ndof(),
158  track->charge(), track->dxy(), track->dz(),
159  track->hitPattern().numberOfValidMuonHits(),
160  track->hitPattern().numberOfValidPixelHits(),
161  0, // nMatchedStations
162  track->hitPattern().trackerLayersWithMeasurement(),
163  2, // Global muon
164  track->hitPattern().numberOfValidStripHits(),
165  track->qoverp(),
166  track->lambda(),
167  track->pt(),
168  track->phi(),
169  track->eta(),
170  track->dxyError(),
171  track->dzError(),
172  track->qoverpError(),
173  track->lambdaError(),
174  track->phiError(),
175  track->dsz(),
176  track->dszError(),
177  vtxInd
178  );
179  }
180 
181  // Put output
182  iEvent.put(std::move(outMuons));
183  iEvent.put(std::move(dispVertices), "displacedVtx");
184 }
185 
186 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
189  desc.add<edm::InputTag>("ChargedCandidates", edm::InputTag("hltL3MuonCandidates"));
190  desc.add<edm::InputTag>("Tracks", edm::InputTag("hltL3Muons"));
191  desc.add<edm::InputTag>("EcalPFClusterIsoMap", edm::InputTag("hltMuonEcalPFClusterIsoForMuons"));
192  desc.add<edm::InputTag>("HcalPFClusterIsoMap", edm::InputTag("hltMuonHcalPFClusterIsoForMuons"));
193  desc.add<edm::InputTag>("TrackIsoMap", edm::InputTag(
194  "hltMuonTkRelIsolationCut0p09Map:combinedRelativeIsoDeposits"));
195  desc.add<edm::InputTag>("displacedvertexCollection", edm::InputTag("hltDisplacedmumuVtxProducerDoubleMu3NoVtx"));
196  desc.add<double>("muonPtCut", 4.0);
197  desc.add<double>("muonEtaCut", 2.4);
198  desc.add<double>("minVtxProbCut", 0.001);
199  descriptions.add("hltScoutingMuonProducer", desc);
200 }
helper::MatcherGetRef< C >::ref_type getRef(const Handle< C > &c, size_t k)
Definition: getRef.h:28
bool isAvailable() const
Definition: Ref.h:576
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
const edm::EDGetTokenT< RecoChargedCandMap > EcalPFClusterIsoMap_
const edm::EDGetTokenT< reco::TrackCollection > TrackCollection_
const edm::EDGetTokenT< RecoChargedCandMap > HcalPFClusterIsoMap_
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:1
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
U second(std::pair< T, U > const &p)
int iEvent
Definition: GenABIO.cc:230
std::vector< ScoutingVertex > ScoutingVertexCollection
const edm::EDGetTokenT< edm::ValueMap< double > > TrackIsoMap_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::vector< ScoutingMuon > ScoutingMuonCollection
Definition: ScoutingMuon.h:106
const edm::EDGetTokenT< reco::VertexCollection > displacedvertexCollection_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isValid() const
Definition: HandleBase.h:74
bool isNull() const
Checks for null.
Definition: Ref.h:249
std::vector< RecoChargedCandidate > RecoChargedCandidateCollection
collectin of RecoChargedCandidate objects
const edm::EDGetTokenT< reco::RecoChargedCandidateCollection > ChargedCandidateCollection_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
virtual void produce(edm::StreamID sid, edm::Event &iEvent, edm::EventSetup const &setup) const override final
T1 deltaR2(T1 eta1, T2 phi1, T3 eta2, T4 phi2)
Definition: deltaR.h:36
fixed size matrix
HLT enums.
HLTScoutingMuonProducer(const edm::ParameterSet &)
def move(src, dest)
Definition: eostools.py:510