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