CMS 3D CMS Logo

HSCParticleProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: HSCParticleProducer
4 // Class: HSCParticleProducer
5 //
13 //
14 // Original Author: Loic Quertenmont
15 // Created: Wed Oct 10 12:01:28 CEST 2007
16 //
17 //
18 
19 // user include files
21 
22 using namespace susybsm;
23 using namespace reco;
24 
26  using namespace edm;
27  using namespace std;
28 
29  // the Act as Event filter
30  Filter_ = iConfig.getParameter<bool>("filter");
31 
32  // the input collections
33  m_trackToken = consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("tracks"));
34  m_muonsToken = consumes<reco::MuonCollection>(iConfig.getParameter<edm::InputTag>("muons"));
35  m_MTmuonsToken = consumes<reco::MuonCollection>(iConfig.getParameter<edm::InputTag>("MTmuons"));
36  m_trackIsoToken = consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("tracksIsolation"));
37 
38  useBetaFromTk = iConfig.getParameter<bool>("useBetaFromTk");
39  useBetaFromMuon = iConfig.getParameter<bool>("useBetaFromMuon");
40  useBetaFromRpc = iConfig.getParameter<bool>("useBetaFromRpc");
41  useBetaFromEcal = iConfig.getParameter<bool>("useBetaFromEcal");
42 
43  // the parameters
44  minTkP = iConfig.getParameter<double>("minTkP"); // 30
45  maxTkChi2 = iConfig.getParameter<double>("maxTkChi2"); // 5
46  minTkHits = iConfig.getParameter<uint32_t>("minTkHits"); // 9
47  minMuP = iConfig.getParameter<double>("minMuP"); // 30
48  minDR = iConfig.getParameter<double>("minDR"); // 0.1
49  minSAMuPt = iConfig.getParameter<double>("minSAMuPt"); // 70
50  minMTMuPt = iConfig.getParameter<double>("minMTMuPt"); // 70
51  minMTDR = iConfig.getParameter<double>("minMTDR"); // 0.3
52  maxInvPtDiff = iConfig.getParameter<double>("maxInvPtDiff"); // 0.005
53 
54  if (useBetaFromTk)
55  beta_calculator_TK = new BetaCalculatorTK(iConfig, consumesCollector());
56  if (useBetaFromMuon)
57  beta_calculator_MUON = new BetaCalculatorMUON(iConfig, consumesCollector());
58  if (useBetaFromRpc)
59  beta_calculator_RPC = new BetaCalculatorRPC(iConfig, consumesCollector());
60  if (useBetaFromEcal)
61  beta_calculator_ECAL = new BetaCalculatorECAL(iConfig, consumesCollector());
62 
63  // Load all the selections
64  std::vector<edm::ParameterSet> SelectionParameters =
65  iConfig.getParameter<std::vector<edm::ParameterSet> >("SelectionParameters");
66  for (unsigned int i = 0; i < SelectionParameters.size(); i++) {
67  Selectors.push_back(new CandidateSelector(SelectionParameters[i]));
68  }
69 
70  // what I produce
71  produces<susybsm::HSCParticleCollection>();
72  if (useBetaFromEcal)
73  produces<susybsm::HSCPCaloInfoCollection>();
74 }
75 
77  // do anything here that needs to be done at desctruction time
78  // (e.g. close files, deallocate resources etc.)
79 }
80 
81 //
82 // member functions
83 //
84 
85 // ------------ method called to produce the data ------------
87  using namespace edm;
88  using namespace reco;
89  using namespace std;
90  using namespace susybsm;
91 
92  // information from the muons
93  edm::Handle<reco::MuonCollection> muonCollectionHandle;
94  iEvent.getByToken(m_muonsToken, muonCollectionHandle);
95 
96  //information from the mean timer muons
97  edm::Handle<reco::MuonCollection> MTmuonCollectionHandle;
98  iEvent.getByToken(m_MTmuonsToken, MTmuonCollectionHandle);
99 
100  // information from the tracks
101  edm::Handle<reco::TrackCollection> trackCollectionHandle;
102  iEvent.getByToken(m_trackToken, trackCollectionHandle);
103 
104  // information from the tracks iso
105  edm::Handle<reco::TrackCollection> trackIsoCollectionHandle;
106  iEvent.getByToken(m_trackIsoToken, trackIsoCollectionHandle);
107 
108  // creates the output collection
110  std::unique_ptr<susybsm::HSCParticleCollection> result(hscp);
111 
113  std::unique_ptr<susybsm::HSCPCaloInfoCollection> caloInfoCollaptr(caloInfoColl);
114 
115  // Fill the output collection with HSCP Candidate (the candiate only contains ref to muon AND/OR track object)
116  *hscp = getHSCPSeedCollection(trackCollectionHandle, muonCollectionHandle, MTmuonCollectionHandle);
117 
118  // find the track ref for isolation purposed (main track is supposed to be the Iso track after refitting)
119  for (susybsm::HSCParticleCollection::iterator hscpcandidate = hscp->begin(); hscpcandidate != hscp->end();
120  ++hscpcandidate) {
121  // Matching is needed because input track collection and muon inner track may lightly differs due to track refit
122  reco::TrackRef track = hscpcandidate->trackRef();
123  if (track.isNull())
124  continue;
125  float dRMin = 1000;
126  int found = -1;
127  for (unsigned int t = 0; t < trackIsoCollectionHandle->size(); t++) {
128  reco::TrackRef Isotrack = reco::TrackRef(trackIsoCollectionHandle, t);
129  if (fabs((1.0 / track->pt()) - (1.0 / Isotrack->pt())) > maxInvPtDiff)
130  continue;
131  float dR = deltaR(track->momentum(), Isotrack->momentum());
132  if (dR <= minDR && dR < dRMin) {
133  dRMin = dR;
134  found = t;
135  }
136  }
137  if (found >= 0)
138  hscpcandidate->setTrackIso(reco::TrackRef(trackIsoCollectionHandle, found));
139  }
140 
141  // compute the TRACKER contribution
142  if (useBetaFromTk) {
143  for (susybsm::HSCParticleCollection::iterator hscpcandidate = hscp->begin(); hscpcandidate != hscp->end();
144  ++hscpcandidate) {
145  beta_calculator_TK->addInfoToCandidate(*hscpcandidate, iEvent, iSetup);
146  }
147  }
148 
149  // compute the MUON contribution
150  if (useBetaFromMuon) {
151  for (susybsm::HSCParticleCollection::iterator hscpcandidate = hscp->begin(); hscpcandidate != hscp->end();
152  ++hscpcandidate) {
153  beta_calculator_MUON->addInfoToCandidate(*hscpcandidate, iEvent, iSetup);
154  }
155  }
156 
157  // compute the RPC contribution
158  if (useBetaFromRpc) {
159  for (susybsm::HSCParticleCollection::iterator hscpcandidate = hscp->begin(); hscpcandidate != hscp->end();
160  ++hscpcandidate) {
161  beta_calculator_RPC->addInfoToCandidate(*hscpcandidate, iEvent, iSetup);
162  }
163  }
164 
165  // compute the ECAL contribution
166  if (useBetaFromEcal) {
167  int Index = 0;
168  caloInfoColl->resize(hscp->size());
169  for (susybsm::HSCParticleCollection::iterator hscpcandidate = hscp->begin(); hscpcandidate != hscp->end();
170  ++hscpcandidate, Index++) {
171  beta_calculator_ECAL->addInfoToCandidate(
172  *hscpcandidate, trackCollectionHandle, iEvent, iSetup, (*caloInfoColl)[Index]);
173  }
174  }
175 
176  // cleanup the collection based on the input selection
177  for (int i = 0; i < (int)hscp->size(); i++) {
178  susybsm::HSCParticleCollection::iterator hscpcandidate = hscp->begin() + i;
179  bool decision = false;
180  for (unsigned int s = 0; s < Selectors.size(); s++) {
181  decision |= Selectors[s]->isSelected(*hscpcandidate);
182  }
183  if (!decision) {
184  hscp->erase(hscpcandidate);
185  if (useBetaFromEcal)
186  caloInfoColl->erase(caloInfoColl->begin() + i);
187  i--;
188  }
189  }
190  bool filterResult = !Filter_ || (Filter_ && !hscp->empty());
191 
192  // output result
193  if (useBetaFromEcal) {
194  edm::OrphanHandle<susybsm::HSCPCaloInfoCollection> caloInfoHandle = iEvent.put(std::move(caloInfoCollaptr));
195  // adding the reftoCaloInfoObject to the HSCP Object
196  for (int i = 0; i < (int)hscp->size(); i++) {
197  susybsm::HSCParticleCollection::iterator hscpcandidate = hscp->begin() + i;
198  hscpcandidate->setCaloInfo(HSCPCaloInfoRef(caloInfoHandle, i));
199  }
200  }
201 
202  // output result
203 
205  // if(useBetaFromEcal){
206  // edm::RefProd<susybsm::HSCParticleCollection> hscpCollectionHandle = iEvent.getRefBeforePut<susybsm::HSCParticleCollection>();
207  // filler.insert(putHandle, CaloInfoColl.begin(), CaloInfoColl.end());
208  // filler.fill();
209  // iEvent.put(std::move(CaloInfoMap));
210  // }
211 
212  return filterResult;
213 }
214 
215 // ------------ method called once each job just before starting event loop ------------
217 
218 // ------------ method called once each job just after ending the event loop ------------
220 
222  edm::Handle<reco::TrackCollection>& trackCollectionHandle,
223  edm::Handle<reco::MuonCollection>& muonCollectionHandle,
224  edm::Handle<reco::MuonCollection>& MTmuonCollectionHandle) {
225  std::vector<HSCParticle> HSCPCollection;
226 
227  // Store a local vector of track ref (that can be modified if matching)
228  std::vector<reco::TrackRef> tracks;
229  for (unsigned int i = 0; i < trackCollectionHandle->size(); i++) {
230  TrackRef track = reco::TrackRef(trackCollectionHandle, i);
231 
232  //If track is from muon always keep it
233  bool isMuon = false;
234  for (unsigned int m = 0; m < muonCollectionHandle->size(); m++) {
235  reco::MuonRef muon = reco::MuonRef(muonCollectionHandle, m);
236  TrackRef innertrack = muon->innerTrack();
237  if (innertrack.isNull())
238  continue;
239  if (fabs((1.0 / innertrack->pt()) - (1.0 / track->pt())) > maxInvPtDiff)
240  continue;
241  float dR = deltaR(innertrack->momentum(), track->momentum());
242  if (dR <= minDR)
243  isMuon = true;
244  }
245 
246  if ((track->p() < minTkP || (track->chi2() / track->ndof()) > maxTkChi2 || track->found() < minTkHits) && !isMuon)
247  continue;
248  tracks.push_back(track);
249  }
250 
251  // Loop on muons with inner track ref and create Muon HSCP Candidate
252  for (unsigned int m = 0; m < muonCollectionHandle->size(); m++) {
253  reco::MuonRef muon = reco::MuonRef(muonCollectionHandle, m);
254  double SApt = -1;
255  if (muon->isStandAloneMuon())
256  SApt = muon->standAloneMuon()->pt();
257  if (muon->p() < minMuP && SApt < minSAMuPt)
258  continue;
259  TrackRef innertrack = muon->innerTrack();
260  if (innertrack.isNull())
261  continue;
262 
263  // Check if the inner track match any track in order to create a Muon+Track HSCP Candidate
264  // Matching is needed because input track collection and muon inner track may lightly differs due to track refit
265  float dRMin = 1000;
266  int found = -1;
267  for (unsigned int t = 0; t < tracks.size(); t++) {
269  if (fabs((1.0 / innertrack->pt()) - (1.0 / track->pt())) > maxInvPtDiff)
270  continue;
271  float dR = deltaR(innertrack->momentum(), track->momentum());
272  if (dR <= minDR && dR < dRMin) {
273  dRMin = dR;
274  found = t;
275  }
276  }
277 
278  HSCParticle candidate;
279  candidate.setMuon(muon);
280  if (found >= 0) {
281  // printf("MUON with Inner Track Matching --> DR = %6.2f (%6.2f %+6.2f %+6.2f):(%6.2f %+6.2f %+6.2f) vs (%6.2f %+6.2f %+6.2f)\n",dRMin,muon->pt(), muon->eta(), muon->phi(), innertrack->pt(), innertrack->eta(), innertrack->phi(), tracks[found]->pt(), tracks[found]->eta(), tracks[found]->phi() );
282  candidate.setTrack(tracks[found]);
283  tracks.erase(tracks.begin() + found);
284  }
285  HSCPCollection.push_back(candidate);
286  }
287 
288  // Loop on muons without inner tracks and create Muon HSCP Candidate
289  for (unsigned int m = 0; m < muonCollectionHandle->size(); m++) {
290  reco::MuonRef muon = reco::MuonRef(muonCollectionHandle, m);
291  double SApt = -1;
292  if (muon->isStandAloneMuon())
293  SApt = muon->standAloneMuon()->pt();
294  if (muon->p() < minMuP && SApt < minSAMuPt)
295  continue;
296  TrackRef innertrack = muon->innerTrack();
297  if (innertrack.isNonnull())
298  continue;
299 
300  // Check if the muon match any track in order to create a Muon+Track HSCP Candidate
301  float dRMin = 1000;
302  int found = -1;
303  for (unsigned int t = 0; t < tracks.size(); t++) {
305  if (fabs((1.0 / muon->pt()) - (1.0 / track->pt())) > maxInvPtDiff)
306  continue;
307  float dR = deltaR(muon->momentum(), track->momentum());
308  if (dR <= minDR && dR < dRMin) {
309  dRMin = dR;
310  found = t;
311  }
312  }
313 
314  HSCParticle candidate;
315  candidate.setMuon(muon);
316  if (found >= 0) {
317  // printf("MUON without Inner Track Matching --> DR = %6.2f (%6.2f %+6.2f %+6.2f) vs (%6.2f %+6.2f %+6.2f)\n",dRMin,muon->pt(), muon->eta(), muon->phi(), tracks[found]->pt(), tracks[found]->eta(), tracks[found]->phi() );
318  candidate.setTrack(tracks[found]);
319  tracks.erase(tracks.begin() + found);
320  }
321  HSCPCollection.push_back(candidate);
322  }
323 
324  //Loop on MT muons and add to collection
325  for (unsigned int m = 0; m < MTmuonCollectionHandle->size(); m++) {
326  reco::MuonRef MTmuon = reco::MuonRef(MTmuonCollectionHandle, m);
327  if (MTmuon->pt() < minMTMuPt)
328  continue;
329 
330  //Check if matches muon HSCP candidate and add reference
331  float dRMin = 1000;
332  int found = -1;
333  for (unsigned int i = 0; i < HSCPCollection.size(); i++) {
334  if (!HSCPCollection[i].hasMuonRef())
335  continue;
336  reco::MuonRef muon = HSCPCollection[i].muonRef();
337  float dR = deltaR(muon->momentum(), MTmuon->momentum());
338  if (dR <= minMTDR && dR < dRMin) {
339  dRMin = dR;
340  found = i;
341  }
342  }
343  if (found > -1)
344  HSCPCollection[found].setMTMuon(MTmuon);
345  else {
346  HSCParticle candidate;
347  candidate.setMTMuon(MTmuon);
348  HSCPCollection.push_back(candidate);
349  }
350  }
351 
352  // Loop on tracks not matching muon and create Track HSCP Candidate
353  for (unsigned int i = 0; i < tracks.size(); i++) {
354  HSCParticle candidate;
355  candidate.setTrack(tracks[i]);
356  HSCPCollection.push_back(candidate);
357  }
358 
359  return HSCPCollection;
360 }
361 
362 //define this as a plug-in
susybsm::HSCParticle::setTrack
void setTrack(const reco::TrackRef &data)
Definition: HSCParticle.h:58
susybsm::HSCParticle
Definition: HSCParticle.h:42
PDWG_EXOHSCP_cff.tracks
tracks
Definition: PDWG_EXOHSCP_cff.py:28
HSCParticleProducer_cff.minSAMuPt
minSAMuPt
Definition: HSCParticleProducer_cff.py:80
mps_fire.i
i
Definition: mps_fire.py:428
HLT_FULL_cff.track
track
Definition: HLT_FULL_cff.py:11776
HSCParticleProducer_cff.useBetaFromMuon
useBetaFromMuon
Definition: HSCParticleProducer_cff.py:62
muon
Definition: MuonCocktails.h:17
edm::Ref::isNull
bool isNull() const
Checks for null.
Definition: Ref.h:235
edm
HLT enums.
Definition: AlignableModifier.h:19
susybsm::HSCParticle::setMuon
void setMuon(const reco::MuonRef &data)
Definition: HSCParticle.h:56
susybsm
Definition: HSCParticle.h:16
HSCParticleProducer::~HSCParticleProducer
~HSCParticleProducer() override
Definition: HSCParticleProducer.cc:76
susybsm::HSCParticleCollection
std::vector< HSCParticle > HSCParticleCollection
Definition: HSCParticle.h:86
HLT_FULL_cff.dRMin
dRMin
Definition: HLT_FULL_cff.py:8727
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
HSCParticleProducer::HSCParticleProducer
HSCParticleProducer(const edm::ParameterSet &)
Definition: HSCParticleProducer.cc:25
newFWLiteAna.found
found
Definition: newFWLiteAna.py:118
edm::Handle< reco::MuonCollection >
edm::Ref< TrackCollection >
HSCParticleProducer_cff.minMTDR
minMTDR
Definition: HSCParticleProducer_cff.py:86
HSCParticleProducer::endJob
void endJob() override
Definition: HSCParticleProducer.cc:219
alignCSCRings.s
s
Definition: alignCSCRings.py:92
HSCParticleProducer_cff.useBetaFromRpc
useBetaFromRpc
Definition: HSCParticleProducer_cff.py:63
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
PDWG_EXOHSCP_cff.maxInvPtDiff
maxInvPtDiff
Definition: PDWG_EXOHSCP_cff.py:108
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:72
reco::MuonRef
edm::Ref< MuonCollection > MuonRef
presistent reference to a Muon
Definition: MuonFwd.h:13
susybsm::HSCPCaloInfoRef
edm::Ref< HSCPCaloInfoCollection > HSCPCaloInfoRef
Definition: HSCPCaloInfo.h:57
PDWG_EXOHSCP_cff.minDR
minDR
Definition: PDWG_EXOHSCP_cff.py:109
HSCParticleProducer_cff.minMuP
minMuP
Definition: HSCParticleProducer_cff.py:76
PbPb_ZMuSkimMuonDPG_cff.deltaR
deltaR
Definition: PbPb_ZMuSkimMuonDPG_cff.py:63
HSCParticleProducer_cff.SelectionParameters
SelectionParameters
Definition: HSCParticleProducer_cff.py:89
reco::TrackRef
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:20
HSCParticleProducer_cff.useBetaFromTk
useBetaFromTk
Definition: HSCParticleProducer_cff.py:61
edm::ParameterSet
Definition: ParameterSet.h:47
HSCParticleProducer::beginJob
void beginJob() override
Definition: HSCParticleProducer.cc:216
BetaCalculatorMUON
Definition: BetaCalculatorMUON.h:22
HSCParticleProducer_cff.minTkHits
minTkHits
Definition: HSCParticleProducer_cff.py:79
edm::Ref::isNonnull
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
HSCParticleProducer_cff.useBetaFromEcal
useBetaFromEcal
Definition: HSCParticleProducer_cff.py:64
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::EventSetup
Definition: EventSetup.h:57
CandidateSelector
Definition: CandidateSelector.h:18
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
edm::OrphanHandle
Definition: EDProductfwd.h:39
susybsm::HSCParticle::setMTMuon
void setMTMuon(const reco::MuonRef &data)
Definition: HSCParticle.h:57
HSCParticleProducer_cff.maxTkChi2
maxTkChi2
Definition: HSCParticleProducer_cff.py:78
HSCParticleProducer.h
BetaCalculatorTK
Definition: BetaCalculatorTK.h:21
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
HSCParticleProducer_cff.minTkP
minTkP
Definition: HSCParticleProducer_cff.py:77
HSCParticleProducer::filter
bool filter(edm::Event &, const edm::EventSetup &) override
Definition: HSCParticleProducer.cc:86
HSCParticleProducer
Definition: HSCParticleProducer.h:52
mps_fire.result
result
Definition: mps_fire.py:311
HGC3DClusterGenMatchSelector_cfi.dR
dR
Definition: HGC3DClusterGenMatchSelector_cfi.py:7
HSCParticleProducer_cff.minMTMuPt
minMTMuPt
Definition: HSCParticleProducer_cff.py:81
BetaCalculatorRPC
Definition: BetaCalculatorRPC.h:29
HSCParticleProducer::getHSCPSeedCollection
std::vector< susybsm::HSCParticle > getHSCPSeedCollection(edm::Handle< reco::TrackCollection > &trackCollectionHandle, edm::Handle< reco::MuonCollection > &muonCollectionHandle, edm::Handle< reco::MuonCollection > &MTmuonCollectionHandle)
Definition: HSCParticleProducer.cc:221
edm::Event
Definition: Event.h:73
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
edm::InputTag
Definition: InputTag.h:15
BetaCalculatorECAL
Definition: BetaCalculatorECAL.h:31
susybsm::HSCPCaloInfoCollection
std::vector< HSCPCaloInfo > HSCPCaloInfoCollection
Definition: HSCPCaloInfo.h:55
reco::isMuon
bool isMuon(const Candidate &part)
Definition: pdgIdUtils.h:9