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  linkToken_ (consumes<reco::MuonTrackLinksCollection>(iConfig.getParameter<edm::InputTag>("InputLinks")))
40 {
41  //register products
42  produces<ScoutingMuonCollection>();
43  produces<ScoutingVertexCollection>("displacedVtx");
44 }
45 
47 
48 // ------------ method called to produce the data ------------
50  edm::EventSetup const & setup) const
51 {
52  using namespace edm;
53 
54  std::unique_ptr<ScoutingMuonCollection> outMuons(new ScoutingMuonCollection());
55  std::unique_ptr<ScoutingVertexCollection> dispVertices(new ScoutingVertexCollection());
56 
57  // Get RecoChargedCandidate
58  Handle<reco::RecoChargedCandidateCollection> ChargedCandidateCollection;
59  if(!iEvent.getByToken(ChargedCandidateCollection_, ChargedCandidateCollection)){
60  iEvent.put(std::move(outMuons));
61  return;
62  }
63 
64  // Get Track
66  if(!iEvent.getByToken(TrackCollection_, TrackCollection)){
67  iEvent.put(std::move(outMuons));
68  return;
69  }
70 
71  // Get EcalPFClusterIsoMap
72  Handle<RecoChargedCandMap> EcalPFClusterIsoMap;
73  iEvent.getByToken(EcalPFClusterIsoMap_, EcalPFClusterIsoMap);
74 
75  // Get HcalPFClusterIsoMap
76  Handle<RecoChargedCandMap> HcalPFClusterIsoMap;
77  iEvent.getByToken(HcalPFClusterIsoMap_, HcalPFClusterIsoMap);
78 
79  // Get TrackIsoMap
80  Handle<ValueMap<double>> TrackIsoMap;
81  if(!iEvent.getByToken(TrackIsoMap_, TrackIsoMap)){
82  iEvent.put(std::move(outMuons));
83  return;
84  }
85 
86  std::pair<reco::RecoChargedCandidate,reco::RecoChargedCandidate> ivtxMuPair;
87  std::vector<std::pair<reco::RecoChargedCandidate,reco::RecoChargedCandidate> > vtxMuPair;
88 
89  //get displaced vertices
90  Handle<reco::VertexCollection> displacedvertexCollection;
91  if(iEvent.getByToken(displacedvertexCollection_, displacedvertexCollection)){
92 
93  for(auto &dispvtx : *displacedvertexCollection){
94  if ( !dispvtx.isValid() ) continue ;
95  float vtxProb = 0.0;
96  if( (dispvtx.chi2()>=0.0) && (dispvtx.ndof()>0) ) vtxProb = TMath::Prob(dispvtx.chi2(), dispvtx.ndof() );
97  if (vtxProb < minVtxProbCut) continue;
98 
99  // Get the 2 tracks associated to displaced vertex
100  auto trackIt = dispvtx.tracks_begin();
101  reco::TrackRef vertextkRef1 = (*trackIt).castTo<reco::TrackRef>() ;
102  trackIt++;
103  reco::TrackRef vertextkRef2 = (*trackIt).castTo<reco::TrackRef>();
104 
105  // Get the muons associated with the tracks
106  int iFoundRefs = 0;
107  for (auto const & cand : *ChargedCandidateCollection) {
108  reco::TrackRef tkRef = cand.get<reco::TrackRef>();
109  if(tkRef == vertextkRef1) {ivtxMuPair.first= cand; iFoundRefs++ ;}
110  if(tkRef == vertextkRef2) {ivtxMuPair.second= cand; iFoundRefs++ ;}
111  }
112  if (iFoundRefs<2) continue;
113  vtxMuPair.push_back(ivtxMuPair);
114 
115  dispVertices->emplace_back(
116  dispvtx.x(), dispvtx.y(), dispvtx.z(),
117  dispvtx.zError(), dispvtx.xError(),
118  dispvtx.yError(), dispvtx.tracksSize(),
119  dispvtx.chi2(), dispvtx.ndof(), dispvtx.isValid()
120  );
121 
122  }
123  }
124 
125  // Produce muons
126  std::vector<int> vtxInd;
127  float minDR2=1e-06;
128  int index = 0;
129 
130  // Read Links collection:
132  iEvent.getByToken(linkToken_, links);
133 
134 
135  for (auto &muon : *ChargedCandidateCollection) {
136  reco::RecoChargedCandidateRef muonRef = getRef(ChargedCandidateCollection, index);
137  ++index;
138  if (muonRef.isNull() || !muonRef.isAvailable())
139  continue;
140 
141  reco::TrackRef track = muon.track();
142  if (track.isNull() || !track.isAvailable())
143  continue;
144 
145  int validmuhit=0;
146  int matchedsta=0;
147  for(auto const & link : *links){
148  const reco::Track& trackerTrack = *link.trackerTrack();
149  float dR2 = deltaR2(track->eta(),track->phi(),trackerTrack.eta(),trackerTrack.phi());
150  float dPt = std::abs(track->pt() - trackerTrack.pt());
151  if (track->pt() != 0) dPt = dPt/track->pt();
152 
153  if (dR2 < 0.02*0.02 and dPt < 0.001) {
154  const reco::TrackRef staTrack = link.standAloneTrack();
155  validmuhit=staTrack->hitPattern().numberOfValidMuonHits() ;
156  matchedsta=staTrack->hitPattern().muonStationsWithValidHits();
157  }
158  }
159 
160  if (muon.pt() < muonPtCut)
161  continue;
162  if (fabs(muon.eta()) > muonEtaCut)
163  continue;
164 
165  double ecalisopf=-1.0;
166  if ( EcalPFClusterIsoMap.isValid()) { ecalisopf = (*EcalPFClusterIsoMap)[muonRef]; }
167 
168  double hcalisopf=-1.0;
169  if ( HcalPFClusterIsoMap.isValid()) { hcalisopf = (*HcalPFClusterIsoMap)[muonRef]; }
170 
171  vtxInd.reserve(vtxMuPair.size());
172  for (unsigned int i=0; i<vtxMuPair.size(); i++) {
173  float dr2_1 = reco::deltaR2( ((vtxMuPair[i]).first),muon );
174  float dr2_2 = reco::deltaR2( ((vtxMuPair[i]).second),muon );
175  if ( (dr2_1<minDR2) || (dr2_2<minDR2) ) vtxInd.push_back(i) ;
176  }
177 
178  outMuons->emplace_back(muon.pt(), muon.eta(), muon.phi(), muon.mass(),
179  ecalisopf, hcalisopf,
180  (*TrackIsoMap)[muonRef], track->chi2(), track->ndof(),
181  track->charge(), track->dxy(), track->dz(),
182  validmuhit,
183  track->hitPattern().numberOfValidPixelHits(),
184  matchedsta,
185  track->hitPattern().trackerLayersWithMeasurement(),
186  2, // Global muon
187  track->hitPattern().numberOfValidStripHits(),
188  track->qoverp(),
189  track->lambda(),
190  track->pt(),
191  track->phi(),
192  track->eta(),
193  track->dxyError(),
194  track->dzError(),
195  track->qoverpError(),
196  track->lambdaError(),
197  track->phiError(),
198  track->dsz(),
199  track->dszError(),
200  vtxInd
201  );
202  vtxInd.clear();
203  }
204 
205  // Put output
206  iEvent.put(std::move(outMuons));
207  iEvent.put(std::move(dispVertices), "displacedVtx");
208 }
209 
210 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
213  desc.add<edm::InputTag>("ChargedCandidates", edm::InputTag("hltL3MuonCandidates"));
214  desc.add<edm::InputTag>("Tracks", edm::InputTag("hltL3Muons"));
215  desc.add<edm::InputTag>("EcalPFClusterIsoMap", edm::InputTag("hltMuonEcalPFClusterIsoForMuons"));
216  desc.add<edm::InputTag>("HcalPFClusterIsoMap", edm::InputTag("hltMuonHcalPFClusterIsoForMuons"));
217  desc.add<edm::InputTag>("TrackIsoMap", edm::InputTag(
218  "hltMuonTkRelIsolationCut0p09Map:combinedRelativeIsoDeposits"));
219  desc.add<edm::InputTag>("displacedvertexCollection", edm::InputTag("hltDisplacedmumuVtxProducerDoubleMu3NoVtx"));
220  desc.add<double>("muonPtCut", 4.0);
221  desc.add<double>("muonEtaCut", 2.4);
222  desc.add<double>("minVtxProbCut", 0.001);
223  desc.add<edm::InputTag>("InputLinks",edm::InputTag("hltL3MuonsIterL3LinksNoVtx"));
224 
225  descriptions.add("hltScoutingMuonProducer", desc);
226 }
227 
228 // declare this class as a framework plugin
helper::MatcherGetRef< C >::ref_type getRef(const Handle< C > &c, size_t k)
Definition: getRef.h:28
bool isAvailable() const
Definition: Ref.h:575
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
void produce(edm::StreamID sid, edm::Event &iEvent, edm::EventSetup const &setup) const final
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:15
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:2
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:684
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
std::vector< MuonTrackLinks > MuonTrackLinksCollection
collection of MuonTrackLinks
Definition: MuonFwd.h:22
U second(std::pair< T, U > const &p)
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< ScoutingVertex > ScoutingVertexCollection
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:690
const edm::EDGetTokenT< edm::ValueMap< double > > TrackIsoMap_
double pt() const
track transverse momentum
Definition: TrackBase.h:660
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
~HLTScoutingMuonProducer() override
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:248
std::vector< RecoChargedCandidate > RecoChargedCandidateCollection
collectin of RecoChargedCandidate objects
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
const edm::EDGetTokenT< reco::RecoChargedCandidateCollection > ChargedCandidateCollection_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
const edm::EDGetTokenT< reco::MuonTrackLinksCollection > linkToken_
fixed size matrix
HLT enums.
HLTScoutingMuonProducer(const edm::ParameterSet &)
def move(src, dest)
Definition: eostools.py:511