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++) {
268  reco::TrackRef track = tracks[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++) {
304  reco::TrackRef track = tracks[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
void setMuon(const reco::MuonRef &data)
Definition: HSCParticle.h:56
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
bool isMuon(const Candidate &part)
Definition: pdgIdUtils.h:9
std::vector< HSCPCaloInfo > HSCPCaloInfoCollection
Definition: HSCPCaloInfo.h:55
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
void setMTMuon(const reco::MuonRef &data)
Definition: HSCParticle.h:57
edm::Ref< HSCPCaloInfoCollection > HSCPCaloInfoRef
Definition: HSCPCaloInfo.h:57
std::vector< HSCParticle > HSCParticleCollection
Definition: HSCParticle.h:86
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::Ref< MuonCollection > MuonRef
presistent reference to a Muon
Definition: MuonFwd.h:13
bool filter(edm::Event &, const edm::EventSetup &) override
bool isNull() const
Checks for null.
Definition: Ref.h:235
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:20
std::vector< susybsm::HSCParticle > getHSCPSeedCollection(edm::Handle< reco::TrackCollection > &trackCollectionHandle, edm::Handle< reco::MuonCollection > &muonCollectionHandle, edm::Handle< reco::MuonCollection > &MTmuonCollectionHandle)
fixed size matrix
HLT enums.
HSCParticleProducer(const edm::ParameterSet &)
def move(src, dest)
Definition: eostools.py:511
void setTrack(const reco::TrackRef &data)
Definition: HSCParticle.h:58