CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HSCParticleProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: HSCParticleProducer
4 // Class: HSCParticleProducer
5 //
13 //
14 // Original Author: Rizzi Andrea
15 // Reworked and Ported to CMSSW_3_0_0 by Christophe Delaere
16 // Created: Wed Oct 10 12:01:28 CEST 2007
17 //
18 //
19 
20 // user include files
22 
23 using namespace susybsm;
24 using namespace reco;
25 
27  using namespace edm;
28  using namespace std;
29 
30  // the Act as Event filter
31  Filter_ = iConfig.getParameter<bool> ("filter");
32 
33  // the input collections
34  m_trackTag = iConfig.getParameter<edm::InputTag>("tracks");
35  m_muonsTag = iConfig.getParameter<edm::InputTag>("muons");
36  m_trackIsoTag = 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  maxInvPtDiff = iConfig.getParameter<double> ("maxInvPtDiff"); // 0.005
50 
51  if(useBetaFromTk )beta_calculator_TK = new BetaCalculatorTK (iConfig);
52  if(useBetaFromMuon)beta_calculator_MUON = new BetaCalculatorMUON(iConfig);
53  if(useBetaFromRpc )beta_calculator_RPC = new BetaCalculatorRPC (iConfig);
54  if(useBetaFromEcal)beta_calculator_ECAL = new BetaCalculatorECAL(iConfig);
55 
56  // Load all the selections
57  std::vector<edm::ParameterSet> SelectionParameters = iConfig.getParameter<std::vector<edm::ParameterSet> >("SelectionParameters");
58  for(unsigned int i=0;i<SelectionParameters.size();i++){
59  Selectors.push_back(new CandidateSelector(SelectionParameters[i]) );
60  }
61 
62  // what I produce
63  produces<susybsm::HSCParticleCollection >();
64  if(useBetaFromEcal)produces<susybsm::HSCPCaloInfoCollection >();
65 
66 }
67 
69  // do anything here that needs to be done at desctruction time
70  // (e.g. close files, deallocate resources etc.)
71 }
72 
73 //
74 // member functions
75 //
76 
77 // ------------ method called to produce the data ------------
78 bool
80 
81  using namespace edm;
82  using namespace reco;
83  using namespace std;
84  using namespace susybsm;
85 
86  // information from the muons
87  edm::Handle<reco::MuonCollection> muonCollectionHandle;
88  iEvent.getByLabel(m_muonsTag,muonCollectionHandle);
89 
90  // information from the tracks
91  edm::Handle<reco::TrackCollection> trackCollectionHandle;
92  iEvent.getByLabel(m_trackTag,trackCollectionHandle);
93 
94  // information from the tracks iso
95  edm::Handle<reco::TrackCollection> trackIsoCollectionHandle;
96  iEvent.getByLabel(m_trackIsoTag,trackIsoCollectionHandle);
97 
98 
99  // creates the output collection
101  std::auto_ptr<susybsm::HSCParticleCollection> result(hscp);
102 
104  std::auto_ptr<susybsm::HSCPCaloInfoCollection> caloInfoCollaptr(caloInfoColl);
105 
106 
107  // Fill the output collection with HSCP Candidate (the candiate only contains ref to muon AND/OR track object)
108  *hscp = getHSCPSeedCollection(trackCollectionHandle, muonCollectionHandle);
109 
110  // find the track ref for isolation purposed (main track is supposed to be the Iso track after refitting)
111  for(susybsm::HSCParticleCollection::iterator hscpcandidate = hscp->begin(); hscpcandidate != hscp->end(); ++hscpcandidate) {
112  // Matching is needed because input track collection and muon inner track may lightly differs due to track refit
113  reco::TrackRef track = hscpcandidate->trackRef();
114  if(track.isNull())continue;
115  float dRMin=1000; int found = -1;
116  for(unsigned int t=0; t<trackIsoCollectionHandle->size();t++) {
117  reco::TrackRef Isotrack = reco::TrackRef( trackIsoCollectionHandle, t );
118  if( fabs( (1.0/track->pt())-(1.0/Isotrack->pt())) > maxInvPtDiff) continue;
119  float dR = deltaR(track->momentum(), Isotrack->momentum());
120  if(dR <= minDR && dR < dRMin){ dRMin=dR; found = t;}
121  }
122  if(found>=0)hscpcandidate->setTrackIso(reco::TrackRef( trackIsoCollectionHandle, found ));
123  }
124 
125  // compute the TRACKER contribution
126  if(useBetaFromTk){
127  for(susybsm::HSCParticleCollection::iterator hscpcandidate = hscp->begin(); hscpcandidate != hscp->end(); ++hscpcandidate) {
128  beta_calculator_TK->addInfoToCandidate(*hscpcandidate, iEvent,iSetup);
129  }}
130 
131  // compute the MUON contribution
132  if(useBetaFromMuon){
133  for(susybsm::HSCParticleCollection::iterator hscpcandidate = hscp->begin(); hscpcandidate != hscp->end(); ++hscpcandidate) {
134  beta_calculator_MUON->addInfoToCandidate(*hscpcandidate, iEvent,iSetup);
135  }}
136 
137  // compute the RPC contribution
138  if(useBetaFromRpc){
139  for(susybsm::HSCParticleCollection::iterator hscpcandidate = hscp->begin(); hscpcandidate != hscp->end(); ++hscpcandidate) {
140  beta_calculator_RPC->addInfoToCandidate(*hscpcandidate, iEvent, iSetup);
141  }}
142 
143  // compute the ECAL contribution
144 // auto_ptr<ValueMap<HSCPCaloInfo> > CaloInfoMap(new ValueMap<HSCPCaloInfo> );
145 // ValueMap<HSCPCaloInfo>::Filler filler(*CaloInfoMap);
146 // std::vector<HSCPCaloInfo> CaloInfoColl(hscp->size());
147  if(useBetaFromEcal){
148  int Index=0;
149  caloInfoColl->resize(hscp->size());
150  for(susybsm::HSCParticleCollection::iterator hscpcandidate = hscp->begin(); hscpcandidate != hscp->end(); ++hscpcandidate, Index++) {
151  beta_calculator_ECAL->addInfoToCandidate(*hscpcandidate,trackCollectionHandle,iEvent,iSetup, (*caloInfoColl)[Index]);
152  }}
153 
154  // cleanup the collection based on the input selection
155  for(int i=0;i<(int)hscp->size();i++) {
156  susybsm::HSCParticleCollection::iterator hscpcandidate = hscp->begin() + i;
157  bool decision = false;
158  for(unsigned int s=0;s<Selectors.size();s++){decision |= Selectors[s]->isSelected(*hscpcandidate);}
159  if(!decision){
160  hscp->erase(hscpcandidate);
161  if(useBetaFromEcal)caloInfoColl->erase(caloInfoColl->begin() + i);
162  i--;
163  }
164  }
165  bool filterResult = !Filter_ || (Filter_ && hscp->size()>=1);
166 
167 
168 
169 
170  // output result
171  if(useBetaFromEcal){
172  edm::OrphanHandle<susybsm::HSCPCaloInfoCollection> caloInfoHandle= iEvent.put(caloInfoCollaptr);
173  // adding the reftoCaloInfoObject to the HSCP Object
174  for(int i=0;i<(int)hscp->size();i++) {
175  susybsm::HSCParticleCollection::iterator hscpcandidate = hscp->begin() + i;
176  hscpcandidate->setCaloInfo(HSCPCaloInfoRef(caloInfoHandle,i));
177  }
178  }
179 
180 
181  // output result
182 
183 
184  edm::OrphanHandle<susybsm::HSCParticleCollection> putHandle = iEvent.put(result);
185 // if(useBetaFromEcal){
186 // edm::RefProd<susybsm::HSCParticleCollection> hscpCollectionHandle = iEvent.getRefBeforePut<susybsm::HSCParticleCollection>();
187 // filler.insert(putHandle, CaloInfoColl.begin(), CaloInfoColl.end());
188 // filler.fill();
189 // iEvent.put(CaloInfoMap);
190 // }
191 
192  return filterResult;
193 }
194 
195 // ------------ method called once each job just before starting event loop ------------
196 void
198 }
199 
200 // ------------ method called once each job just after ending the event loop ------------
201 void
203 }
204 
205 std::vector<HSCParticle> HSCParticleProducer::getHSCPSeedCollection(edm::Handle<reco::TrackCollection>& trackCollectionHandle, edm::Handle<reco::MuonCollection>& muonCollectionHandle)
206 {
207  std::vector<HSCParticle> HSCPCollection;
208 
209  // Store a local vector of track ref (that can be modified if matching)
210  std::vector<reco::TrackRef> tracks;
211  for(unsigned int i=0; i<trackCollectionHandle->size(); i++){
212  TrackRef track = reco::TrackRef( trackCollectionHandle, i );
213  if(track->p()<minTkP || (track->chi2()/track->ndof())>maxTkChi2 || track->found()<minTkHits)continue;
214  tracks.push_back( track );
215  }
216 
217  // Loop on muons with inner track ref and create Muon HSCP Candidate
218  for(unsigned int m=0; m<muonCollectionHandle->size(); m++){
219  reco::MuonRef muon = reco::MuonRef( muonCollectionHandle, m );
220  if(muon->p()<minMuP )continue;
221  TrackRef innertrack = muon->innerTrack();
222  if(innertrack.isNull())continue;
223 
224  // Check if the inner track match any track in order to create a Muon+Track HSCP Candidate
225  // Matching is needed because input track collection and muon inner track may lightly differs due to track refit
226  float dRMin=1000; int found = -1;
227  for(unsigned int t=0; t<tracks.size();t++) {
228  reco::TrackRef track = tracks[t];
229  if( fabs( (1.0/innertrack->pt())-(1.0/track->pt())) > maxInvPtDiff) continue;
230  float dR = deltaR(innertrack->momentum(), track->momentum());
231  if(dR <= minDR && dR < dRMin){ dRMin=dR; found = t;}
232  }
233 
234  HSCParticle candidate;
235  candidate.setMuon(muon);
236  if(found>=0){
237 // 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() );
238  candidate.setTrack(tracks[found]);
239  tracks.erase(tracks.begin()+found);
240  }
241  HSCPCollection.push_back(candidate);
242  }
243 
244  // Loop on muons without inner tracks and create Muon HSCP Candidate
245  for(unsigned int m=0; m<muonCollectionHandle->size(); m++){
246  reco::MuonRef muon = reco::MuonRef( muonCollectionHandle, m );
247  if(muon->p()<minMuP)continue;
248  TrackRef innertrack = muon->innerTrack();
249  if(innertrack.isNonnull())continue;
250 
251  // Check if the muon match any track in order to create a Muon+Track HSCP Candidate
252  float dRMin=1000; int found = -1;
253  for(unsigned int t=0; t<tracks.size();t++) {
254  reco::TrackRef track = tracks[t];
255  if( fabs( (1.0/muon->pt())-(1.0/track->pt())) > maxInvPtDiff) continue;
256  float dR = deltaR(muon->momentum(), track->momentum());
257  if(dR <= minDR && dR < dRMin){ dRMin=dR; found = t;}
258  }
259 
260  HSCParticle candidate;
261  candidate.setMuon(muon);
262  if(found>=0){
263 // 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() );
264  candidate.setTrack(tracks[found]);
265  tracks.erase(tracks.begin()+found);
266  }
267  HSCPCollection.push_back(candidate);
268  }
269 
270  // Loop on tracks not matching muon and create Track HSCP Candidate
271  for(unsigned int i=0; i<tracks.size(); i++){
272  HSCParticle candidate;
273  candidate.setTrack(tracks[i]);
274  HSCPCollection.push_back(candidate);
275  }
276 
277  return HSCPCollection;
278 }
279 
280 //define this as a plug-in
282 
283 
284 
285 
286 
287 
288 
289 
290 
291 
292 
293 
294 
295 
296 
297 
298 
299 
300 
void setMuon(const reco::MuonRef &data)
Definition: HSCParticle.h:63
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
std::vector< susybsm::HSCParticle > getHSCPSeedCollection(edm::Handle< reco::TrackCollection > &trackCollectionHandle, edm::Handle< reco::MuonCollection > &muonCollectionHandle)
std::vector< HSCPCaloInfo > HSCPCaloInfoCollection
Definition: HSCPCaloInfo.h:58
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:250
edm::Ref< HSCPCaloInfoCollection > HSCPCaloInfoRef
Definition: HSCPCaloInfo.h:60
std::vector< HSCParticle > HSCParticleCollection
Definition: HSCParticle.h:94
int iEvent
Definition: GenABIO.cc:243
bool isNull() const
Checks for null.
Definition: Ref.h:247
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
tuple result
Definition: query.py:137
edm::Ref< MuonCollection > MuonRef
presistent reference to a Muon
Definition: MuonFwd.h:13
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
tuple tracks
Definition: testEve_cfg.py:39
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:14
HSCParticleProducer(const edm::ParameterSet &)
virtual bool filter(edm::Event &, const edm::EventSetup &)
void setTrack(const reco::TrackRef &data)
Definition: HSCParticle.h:65