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 )beta_calculator_TK = new BetaCalculatorTK (iConfig, consumesCollector());
55  if(useBetaFromMuon)beta_calculator_MUON = new BetaCalculatorMUON(iConfig, consumesCollector());
56  if(useBetaFromRpc )beta_calculator_RPC = new BetaCalculatorRPC (iConfig, consumesCollector());
57  if(useBetaFromEcal)beta_calculator_ECAL = new BetaCalculatorECAL(iConfig, consumesCollector());
58 
59  // Load all the selections
60  std::vector<edm::ParameterSet> SelectionParameters = iConfig.getParameter<std::vector<edm::ParameterSet> >("SelectionParameters");
61  for(unsigned int i=0;i<SelectionParameters.size();i++){
62  Selectors.push_back(new CandidateSelector(SelectionParameters[i]) );
63  }
64 
65  // what I produce
66  produces<susybsm::HSCParticleCollection >();
67  if(useBetaFromEcal)produces<susybsm::HSCPCaloInfoCollection >();
68 
69 }
70 
72  // do anything here that needs to be done at desctruction time
73  // (e.g. close files, deallocate resources etc.)
74 }
75 
76 //
77 // member functions
78 //
79 
80 // ------------ method called to produce the data ------------
81 bool
83 
84  using namespace edm;
85  using namespace reco;
86  using namespace std;
87  using namespace susybsm;
88 
89  // information from the muons
90  edm::Handle<reco::MuonCollection> muonCollectionHandle;
91  iEvent.getByToken(m_muonsToken,muonCollectionHandle);
92 
93  //information from the mean timer muons
94  edm::Handle<reco::MuonCollection> MTmuonCollectionHandle;
95  iEvent.getByToken(m_MTmuonsToken,MTmuonCollectionHandle);
96 
97  // information from the tracks
98  edm::Handle<reco::TrackCollection> trackCollectionHandle;
99  iEvent.getByToken(m_trackToken,trackCollectionHandle);
100 
101  // information from the tracks iso
102  edm::Handle<reco::TrackCollection> trackIsoCollectionHandle;
103  iEvent.getByToken(m_trackIsoToken,trackIsoCollectionHandle);
104 
105 
106  // creates the output collection
108  std::unique_ptr<susybsm::HSCParticleCollection> result(hscp);
109 
111  std::unique_ptr<susybsm::HSCPCaloInfoCollection> caloInfoCollaptr(caloInfoColl);
112 
113 
114  // Fill the output collection with HSCP Candidate (the candiate only contains ref to muon AND/OR track object)
115  *hscp = getHSCPSeedCollection(trackCollectionHandle, muonCollectionHandle, MTmuonCollectionHandle);
116 
117  // find the track ref for isolation purposed (main track is supposed to be the Iso track after refitting)
118  for(susybsm::HSCParticleCollection::iterator hscpcandidate = hscp->begin(); hscpcandidate != hscp->end(); ++hscpcandidate) {
119  // Matching is needed because input track collection and muon inner track may lightly differs due to track refit
120  reco::TrackRef track = hscpcandidate->trackRef();
121  if(track.isNull())continue;
122  float dRMin=1000; int found = -1;
123  for(unsigned int t=0; t<trackIsoCollectionHandle->size();t++) {
124  reco::TrackRef Isotrack = reco::TrackRef( trackIsoCollectionHandle, t );
125  if( fabs( (1.0/track->pt())-(1.0/Isotrack->pt())) > maxInvPtDiff) continue;
126  float dR = deltaR(track->momentum(), Isotrack->momentum());
127  if(dR <= minDR && dR < dRMin){ dRMin=dR; found = t;}
128  }
129  if(found>=0)hscpcandidate->setTrackIso(reco::TrackRef( trackIsoCollectionHandle, found ));
130  }
131 
132  // compute the TRACKER contribution
133  if(useBetaFromTk){
134  for(susybsm::HSCParticleCollection::iterator hscpcandidate = hscp->begin(); hscpcandidate != hscp->end(); ++hscpcandidate) {
135  beta_calculator_TK->addInfoToCandidate(*hscpcandidate, iEvent,iSetup);
136  }}
137 
138  // compute the MUON contribution
139  if(useBetaFromMuon){
140  for(susybsm::HSCParticleCollection::iterator hscpcandidate = hscp->begin(); hscpcandidate != hscp->end(); ++hscpcandidate) {
141  beta_calculator_MUON->addInfoToCandidate(*hscpcandidate, iEvent,iSetup);
142  }}
143 
144  // compute the RPC contribution
145  if(useBetaFromRpc){
146  for(susybsm::HSCParticleCollection::iterator hscpcandidate = hscp->begin(); hscpcandidate != hscp->end(); ++hscpcandidate) {
147  beta_calculator_RPC->addInfoToCandidate(*hscpcandidate, iEvent, iSetup);
148  }}
149 
150  // compute the ECAL contribution
151  if(useBetaFromEcal){
152  int Index=0;
153  caloInfoColl->resize(hscp->size());
154  for(susybsm::HSCParticleCollection::iterator hscpcandidate = hscp->begin(); hscpcandidate != hscp->end(); ++hscpcandidate, Index++) {
155  beta_calculator_ECAL->addInfoToCandidate(*hscpcandidate,trackCollectionHandle,iEvent,iSetup, (*caloInfoColl)[Index]);
156  }}
157 
158  // cleanup the collection based on the input selection
159  for(int i=0;i<(int)hscp->size();i++) {
160  susybsm::HSCParticleCollection::iterator hscpcandidate = hscp->begin() + i;
161  bool decision = false;
162  for(unsigned int s=0;s<Selectors.size();s++){decision |= Selectors[s]->isSelected(*hscpcandidate);}
163  if(!decision){
164  hscp->erase(hscpcandidate);
165  if(useBetaFromEcal)caloInfoColl->erase(caloInfoColl->begin() + i);
166  i--;
167  }
168  }
169  bool filterResult = !Filter_ || (Filter_ && !hscp->empty());
170 
171 
172 
173 
174  // output result
175  if(useBetaFromEcal){
176  edm::OrphanHandle<susybsm::HSCPCaloInfoCollection> caloInfoHandle= iEvent.put(std::move(caloInfoCollaptr));
177  // adding the reftoCaloInfoObject to the HSCP Object
178  for(int i=0;i<(int)hscp->size();i++) {
179  susybsm::HSCParticleCollection::iterator hscpcandidate = hscp->begin() + i;
180  hscpcandidate->setCaloInfo(HSCPCaloInfoRef(caloInfoHandle,i));
181  }
182  }
183 
184 
185  // output result
186 
187 
189 // if(useBetaFromEcal){
190 // edm::RefProd<susybsm::HSCParticleCollection> hscpCollectionHandle = iEvent.getRefBeforePut<susybsm::HSCParticleCollection>();
191 // filler.insert(putHandle, CaloInfoColl.begin(), CaloInfoColl.end());
192 // filler.fill();
193 // iEvent.put(std::move(CaloInfoMap));
194 // }
195 
196  return filterResult;
197 }
198 
199 // ------------ method called once each job just before starting event loop ------------
200 void
202 }
203 
204 // ------------ method called once each job just after ending the event loop ------------
205 void
207 }
208 
209 std::vector<HSCParticle> HSCParticleProducer::getHSCPSeedCollection(edm::Handle<reco::TrackCollection>& trackCollectionHandle, edm::Handle<reco::MuonCollection>& muonCollectionHandle, edm::Handle<reco::MuonCollection>& MTmuonCollectionHandle)
210 {
211  std::vector<HSCParticle> HSCPCollection;
212 
213  // Store a local vector of track ref (that can be modified if matching)
214  std::vector<reco::TrackRef> tracks;
215  for(unsigned int i=0; i<trackCollectionHandle->size(); i++){
216  TrackRef track = reco::TrackRef( trackCollectionHandle, i );
217 
218  //If track is from muon always keep it
219  bool isMuon=false;
220  for(unsigned int m=0; m<muonCollectionHandle->size(); m++){
221  reco::MuonRef muon = reco::MuonRef( muonCollectionHandle, m );
222  TrackRef innertrack = muon->innerTrack();
223  if(innertrack.isNull())continue;
224  if( fabs( (1.0/innertrack->pt())-(1.0/track->pt())) > maxInvPtDiff) continue;
225  float dR = deltaR(innertrack->momentum(), track->momentum());
226  if(dR <= minDR) isMuon=true;
227  }
228 
229  if((track->p()<minTkP || (track->chi2()/track->ndof())>maxTkChi2 || track->found()<minTkHits) && !isMuon)continue;
230  tracks.push_back( track );
231  }
232 
233  // Loop on muons with inner track ref and create Muon HSCP Candidate
234  for(unsigned int m=0; m<muonCollectionHandle->size(); m++){
235  reco::MuonRef muon = reco::MuonRef( muonCollectionHandle, m );
236  double SApt=-1;
237  if(muon->isStandAloneMuon()) SApt=muon->standAloneMuon()->pt();
238  if(muon->p()<minMuP && SApt<minSAMuPt)continue;
239  TrackRef innertrack = muon->innerTrack();
240  if(innertrack.isNull())continue;
241 
242  // Check if the inner track match any track in order to create a Muon+Track HSCP Candidate
243  // Matching is needed because input track collection and muon inner track may lightly differs due to track refit
244  float dRMin=1000; int found = -1;
245  for(unsigned int t=0; t<tracks.size();t++) {
246  reco::TrackRef track = tracks[t];
247  if( fabs( (1.0/innertrack->pt())-(1.0/track->pt())) > maxInvPtDiff) continue;
248  float dR = deltaR(innertrack->momentum(), track->momentum());
249  if(dR <= minDR && dR < dRMin){ dRMin=dR; found = t;}
250  }
251 
252  HSCParticle candidate;
253  candidate.setMuon(muon);
254  if(found>=0){
255 // 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() );
256  candidate.setTrack(tracks[found]);
257  tracks.erase(tracks.begin()+found);
258  }
259  HSCPCollection.push_back(candidate);
260  }
261 
262  // Loop on muons without inner tracks and create Muon HSCP Candidate
263  for(unsigned int m=0; m<muonCollectionHandle->size(); m++){
264  reco::MuonRef muon = reco::MuonRef( muonCollectionHandle, m );
265  double SApt=-1;
266  if(muon->isStandAloneMuon()) SApt=muon->standAloneMuon()->pt();
267  if(muon->p()<minMuP && SApt<minSAMuPt)continue;
268  TrackRef innertrack = muon->innerTrack();
269  if(innertrack.isNonnull())continue;
270 
271  // Check if the muon match any track in order to create a Muon+Track HSCP Candidate
272  float dRMin=1000; int found = -1;
273  for(unsigned int t=0; t<tracks.size();t++) {
274  reco::TrackRef track = tracks[t];
275  if( fabs( (1.0/muon->pt())-(1.0/track->pt())) > maxInvPtDiff) continue;
276  float dR = deltaR(muon->momentum(), track->momentum());
277  if(dR <= minDR && dR < dRMin){ dRMin=dR; found = t;}
278  }
279 
280  HSCParticle candidate;
281  candidate.setMuon(muon);
282  if(found>=0){
283 // 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() );
284  candidate.setTrack(tracks[found]);
285  tracks.erase(tracks.begin()+found);
286  }
287  HSCPCollection.push_back(candidate);
288  }
289 
290 
291  //Loop on MT muons and add to collection
292  for(unsigned int m=0; m<MTmuonCollectionHandle->size(); m++){
293  reco::MuonRef MTmuon = reco::MuonRef( MTmuonCollectionHandle, m );
294  if(MTmuon->pt()<minMTMuPt )continue;
295 
296  //Check if matches muon HSCP candidate and add reference
297  float dRMin=1000; int found = -1;
298  for(unsigned int i=0; i<HSCPCollection.size(); i++) {
299  if(!HSCPCollection[i].hasMuonRef()) continue;
300  reco::MuonRef muon = HSCPCollection[i].muonRef();
301  float dR = deltaR(muon->momentum(), MTmuon->momentum());
302  if(dR <= minMTDR && dR < dRMin){ dRMin=dR; found = i;}
303  }
304  if(found>-1) HSCPCollection[found].setMTMuon(MTmuon);
305  else {
306  HSCParticle candidate;
307  candidate.setMTMuon(MTmuon);
308  HSCPCollection.push_back(candidate);
309  }
310  }
311 
312 
313  // Loop on tracks not matching muon and create Track HSCP Candidate
314  for(unsigned int i=0; i<tracks.size(); i++){
315  HSCParticle candidate;
316  candidate.setTrack(tracks[i]);
317  HSCPCollection.push_back(candidate);
318  }
319 
320  return HSCPCollection;
321 }
322 
323 //define this as a plug-in
325 
326 
327 
328 
329 
330 
331 
332 
333 
334 
335 
336 
337 
338 
339 
340 
341 
342 
343 
void setMuon(const reco::MuonRef &data)
Definition: HSCParticle.h:63
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:253
bool isMuon(const Candidate &part)
Definition: pdgIdUtils.h:11
std::vector< HSCPCaloInfo > HSCPCaloInfoCollection
Definition: HSCPCaloInfo.h:58
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void setMTMuon(const reco::MuonRef &data)
Definition: HSCParticle.h:64
edm::Ref< HSCPCaloInfoCollection > HSCPCaloInfoRef
Definition: HSCPCaloInfo.h:60
std::vector< HSCParticle > HSCParticleCollection
Definition: HSCParticle.h:94
int iEvent
Definition: GenABIO.cc:230
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:250
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
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:65