CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CosmicMuonSeedGenerator.cc
Go to the documentation of this file.
15 
17 
22 
28 
31 
35 
37 
38 #include <vector>
39 
42 
43 using namespace edm;
44 using namespace std;
45 
46 // Constructor
48  produces<TrajectorySeedCollection>();
49 
50  // enable the DT chamber
51  theEnableDTFlag = pset.getParameter<bool>("EnableDTMeasurement");
52  // enable the CSC chamber
53  theEnableCSCFlag = pset.getParameter<bool>("EnableCSCMeasurement");
54 
55  theDTRecSegmentLabel = pset.getParameter<InputTag>("DTRecSegmentLabel");
56 
57  theCSCRecSegmentLabel = pset.getParameter<InputTag>("CSCRecSegmentLabel");
58 
59  // the maximum number of TrajectorySeed
60  theMaxSeeds = pset.getParameter<int>("MaxSeeds");
61 
62  theMaxDTChi2 = pset.getParameter<double>("MaxDTChi2");
63  theMaxCSCChi2 = pset.getParameter<double>("MaxCSCChi2");
64 
65  // pre-determined parameters for seed pt calculation ( pt * dphi )
66  theParameters["topmb41"] = 0.87;
67  theParameters["bottommb41"] = 1.2;
68  theParameters["topmb42"] = 0.67;
69  theParameters["bottommb42"] = 0.98;
70  theParameters["topmb43"] = 0.34;
71  theParameters["bottommb43"] = 0.58;
72  theParameters["topmb31"] = 0.54;
73  theParameters["bottommb31"] = 0.77;
74  theParameters["topmb32"] = 0.35;
75  theParameters["bottommb32"] = 0.55;
76  theParameters["topmb21"] = 0.21;
77  theParameters["bottommb21"] = 0.31;
78 
79 }
80 
81 // Destructor
83 }
84 
85 
86 // reconstruct muon's seeds
88 
89  eSetup.get<IdealMagneticFieldRecord>().get(theField);
90 
91  auto_ptr<TrajectorySeedCollection> output(new TrajectorySeedCollection());
92 
94 
95  std::string category = "Muon|RecoMuon|CosmicMuonSeedGenerator";
96 
97  // Muon Geometry - DT, CSC and RPC
98  eSetup.get<MuonRecoGeometryRecord>().get(theMuonLayers);
99 
100  // get the DT layers
101  vector<DetLayer*> dtLayers = theMuonLayers->allDTLayers();
102 
103  // get the CSC layers
104  vector<DetLayer*> cscForwardLayers = theMuonLayers->forwardCSCLayers();
105  vector<DetLayer*> cscBackwardLayers = theMuonLayers->backwardCSCLayers();
106 
107  MuonDetLayerMeasurements muonMeasurements(theDTRecSegmentLabel,theCSCRecSegmentLabel,
108  InputTag(),
109  theEnableDTFlag,theEnableCSCFlag,false);
110 
111  muonMeasurements.setEvent(event);
112 
113  MuonRecHitContainer allHits;
114 
115  vector<MuonRecHitContainer> RHMBs;
116  vector<MuonRecHitContainer> RHMEFs;
117  vector<MuonRecHitContainer> RHMEBs;
118 
119  stable_sort(allHits.begin(),allHits.end(),DecreasingGlobalY());
120 
121  for (vector<DetLayer*>::reverse_iterator icsclayer = cscForwardLayers.rbegin();
122  icsclayer != cscForwardLayers.rend() - 1; ++icsclayer) {
123 
124  MuonRecHitContainer RHMF = muonMeasurements.recHits(*icsclayer);
125  allHits.insert(allHits.end(),RHMF.begin(),RHMF.end());
126 
127  }
128 
129  for (vector<DetLayer*>::reverse_iterator icsclayer = cscBackwardLayers.rbegin();
130  icsclayer != cscBackwardLayers.rend() - 1; ++icsclayer) {
131 
132  MuonRecHitContainer RHMF = muonMeasurements.recHits(*icsclayer);
133  allHits.insert(allHits.end(),RHMF.begin(),RHMF.end());
134 
135  }
136 
137  for (vector<DetLayer*>::reverse_iterator idtlayer = dtLayers.rbegin();
138  idtlayer != dtLayers.rend(); ++idtlayer) {
139 
140  MuonRecHitContainer RHMB = muonMeasurements.recHits(*idtlayer);
141  RHMBs.push_back(RHMB);
142 
143  if ( idtlayer != dtLayers.rbegin() ) allHits.insert(allHits.end(),RHMB.begin(),RHMB.end());
144 
145  }
146 
147 // stable_sort(allHits.begin(),allHits.end(),DecreasingGlobalY());
148 
149  LogTrace(category)<<"all RecHits: "<<allHits.size();
150 
151 // CosmicMuonSeedGenerator::MuonRecHitPairVector mb41 = makeSegPairs(RHMBs[0], RHMBs[3], "mb41");
152 // createSeeds(seeds, mb41, eSetup);
153 
154 // CosmicMuonSeedGenerator::MuonRecHitPairVector mb43 = makeSegPairs(RHMBs[0],RHMBs[1], "mb43");
155 // createSeeds(seeds, mb43, eSetup);
156 
157  CosmicMuonSeedGenerator::MuonRecHitPairVector mb42 = makeSegPairs(RHMBs[0],RHMBs[2], "mb42");
158  createSeeds(seeds, mb42, eSetup);
159 
160 // CosmicMuonSeedGenerator::MuonRecHitPairVector mb32 = makeSegPairs(RHMBs[1], RHMBs[2], "mb32");
161 // createSeeds(seeds, mb32, eSetup);
162 
163  CosmicMuonSeedGenerator::MuonRecHitPairVector mb31 = makeSegPairs(RHMBs[1], RHMBs[3], "mb31");
164  createSeeds(seeds, mb31, eSetup);
165 
166 // CosmicMuonSeedGenerator::MuonRecHitPairVector mb21 = makeSegPairs(RHMBs[2], RHMBs[3], "mb21");
167 // createSeeds(seeds, mb21, eSetup);
168 
169  if ( !allHits.empty() ) {
170 
171  MuonRecHitContainer goodhits = selectSegments(allHits);
172  LogTrace(category)<<"good RecHits: "<<goodhits.size();
173 
174  if ( goodhits.empty() ) {
175  LogTrace(category)<<"No qualified Segments in Event! ";
176  LogTrace(category)<<"Use 2D RecHit";
177 
178  createSeeds(seeds,allHits,eSetup);
179 
180  }
181  else {
182  createSeeds(seeds,goodhits,eSetup);
183  }
184  }
185 
186  LogTrace(category)<<"Seeds built: "<<seeds.size();
187 
188  for(std::vector<TrajectorySeed>::iterator seed = seeds.begin();
189  seed != seeds.end(); ++seed) {
190  output->push_back(*seed);
191  }
192 
193  event.put(output);
194  seeds.clear();
195 
196 }
197 
198 
200 
201  const std::string category = "Muon|RecoMuon|CosmicMuonSeedGenerator";
202 
203  // only use 4D segments
204  if ( !hit->isValid() ) return false;
205 
206  if (hit->dimension() < 4) {
207  LogTrace(category)<<"dim < 4";
208  return false;
209  }
210 
211  if (hit->isDT() && ( hit->chi2()> theMaxDTChi2 )) {
212  LogTrace(category)<<"DT chi2 too large";
213  return false;
214  }
215  else if (hit->isCSC() &&( hit->chi2()> theMaxCSCChi2 ) ) {
216  LogTrace(category)<<"CSC chi2 too large";
217  return false;
218  }
219  return true;
220 
221 }
222 
224 
226  const std::string category = "Muon|RecoMuon|CosmicMuonSeedGenerator";
227 
228  //Only select good quality Segments
229  for (MuonRecHitContainer::const_iterator hit = hits.begin(); hit != hits.end(); hit++) {
230  if ( checkQuality(*hit) ) result.push_back(*hit);
231  }
232 
233  if ( result.size() < 2 ) return result;
234 
235  MuonRecHitContainer result2;
236 
237  //avoid selecting Segments with similar direction
238  for (MuonRecHitContainer::iterator hit = result.begin(); hit != result.end(); hit++) {
239  if (*hit == 0) continue;
240  if ( !(*hit)->isValid() ) continue;
241  bool good = true;
242  //UNUSED: GlobalVector dir1 = (*hit)->globalDirection();
243  //UNUSED: GlobalPoint pos1 = (*hit)->globalPosition();
244  for (MuonRecHitContainer::iterator hit2 = hit + 1; hit2 != result.end(); hit2++) {
245  if (*hit2 == 0) continue;
246  if ( !(*hit2)->isValid() ) continue;
247 
248  //compare direction and position
249  //UNUSED: GlobalVector dir2 = (*hit2)->globalDirection();
250  //UNUSED: GlobalPoint pos2 = (*hit2)->globalPosition();
251  if ( !areCorrelated((*hit),(*hit2)) ) continue;
252 
253  if ( !leftIsBetter((*hit),(*hit2)) ) {
254  good = false;
255  } else (*hit2) = 0;
256  }
257 
258  if ( good ) result2.push_back(*hit);
259  }
260 
261  result.clear();
262 
263  return result2;
264 
265 }
266 
268  const MuonRecHitContainer& hits,
269  const edm::EventSetup& eSetup) const {
270 
271  const std::string category = "Muon|RecoMuon|CosmicMuonSeedGenerator";
272 
273  if (hits.size() == 0 || results.size() >= theMaxSeeds ) return;
274  for (MuonRecHitContainer::const_iterator ihit = hits.begin(); ihit != hits.end(); ihit++) {
275  const std::vector<TrajectorySeed>& sds = createSeed((*ihit),eSetup);
276  LogTrace(category)<<"created seeds from rechit "<<sds.size();
277  results.insert(results.end(),sds.begin(),sds.end());
278  if ( results.size() >= theMaxSeeds ) break;
279  }
280  return;
281 }
282 
285  const edm::EventSetup& eSetup) const {
286 
287  const std::string category = "Muon|RecoMuon|CosmicMuonSeedGenerator";
288 
289  if (hitpairs.size() == 0 || results.size() >= theMaxSeeds ) return;
290  for (CosmicMuonSeedGenerator::MuonRecHitPairVector::const_iterator ihitpair = hitpairs.begin(); ihitpair != hitpairs.end(); ihitpair++) {
291  const std::vector<TrajectorySeed>& sds = createSeed((*ihitpair),eSetup);
292  LogTrace(category)<<"created seeds from rechit "<<sds.size();
293  results.insert(results.end(),sds.begin(),sds.end());
294  if ( results.size() >= theMaxSeeds ) break;
295  }
296  return;
297 }
298 
299 
300 std::vector<TrajectorySeed> CosmicMuonSeedGenerator::createSeed(const MuonRecHitPointer& hit, const edm::EventSetup& eSetup) const {
301 
302  std::vector<TrajectorySeed> result;
303 
304  const std::string category = "Muon|RecoMuon|CosmicMuonSeedGenerator";
305 
306  MuonPatternRecoDumper dumper;
307 
308  // set the pt by hand
309  double pt = 10.0;
310 
311  // AlgebraicVector4 t;
312  AlgebraicSymMatrix mat(5,0);
313 
314  // Fill the LocalTrajectoryParameters
315  LocalPoint segPos=hit->localPosition();
316 
317  GlobalVector polar(GlobalVector::Spherical(hit->globalDirection().theta(),
318  hit->globalDirection().phi(),
319  1.));
320  // Force all track downward for cosmic, not beam-halo
321  if (hit->geographicalId().subdetId() == MuonSubdetId::DT && fabs(hit->globalDirection().eta()) < 4.0 && hit->globalDirection().phi() > 0 )
322  polar = - polar;
323 
324  if (hit->geographicalId().subdetId() == MuonSubdetId::CSC && fabs(hit->globalDirection().eta()) > 2.3 ) {
325  polar = - polar;
326  }
327 
328  polar *=fabs(pt)/polar.perp();
329 
330  LocalVector segDir =hit->det()->toLocal(polar);
331 
332  int charge= 1;
333  LocalTrajectoryParameters param(segPos,segDir, charge);
334 
335  charge= -1;
336  LocalTrajectoryParameters param2(segPos,segDir, charge);
337 
338  mat = hit->parametersError().similarityT( hit->projectionMatrix() );
339 
340  float p_err = 0.2;
341  mat[0][0]= p_err;
342 
343  LocalTrajectoryError error(asSMatrix<5>(mat));
344 
345  // Create the TrajectoryStateOnSurface
346  TrajectoryStateOnSurface tsos(param, error, hit->det()->surface(), &*theField);
347  TrajectoryStateOnSurface tsos2(param2, error, hit->det()->surface(), &*theField);
348 
349  LogTrace(category)<<"Trajectory State on Surface of Seed";
350  LogTrace(category)<<"mom: "<<tsos.globalMomentum()<<" phi: "<<tsos.globalMomentum().phi();
351  LogTrace(category)<<"pos: " << tsos.globalPosition();
352  LogTrace(category) << "The RecSegment relies on: ";
353  LogTrace(category) << dumper.dumpMuonId(hit->geographicalId());
354 
355  result.push_back( tsosToSeed(tsos, hit->geographicalId().rawId()) );
356  result.push_back( tsosToSeed(tsos2, hit->geographicalId().rawId()) );
357 
358  return result;
359 }
360 
362  bool result = false;
363 
364  GlobalVector dir1 = lhs->globalDirection();
365  GlobalPoint pos1 = lhs->globalPosition();
366  GlobalVector dir2 = rhs->globalDirection();
367  GlobalPoint pos2 = rhs->globalPosition();
368 
369  GlobalVector dis = pos2 - pos1;
370 
371  if ( (deltaR<double>(dir1.eta(), dir1.phi(), dir2.eta(), dir2.phi()) < 0.1 || deltaR<double>(dir1.eta(), dir1.phi(), -dir2.eta(), -dir2.phi()) < 0.1 )
372  && dis.mag() < 5.0 )
373  result = true;
374 
375  if ( (deltaR<double>(dir1.eta(), dir1.phi(), dir2.eta(), dir2.phi()) < 0.1 || deltaR<double>(dir1.eta(), dir1.phi(), -dir2.eta(), -dir2.phi()) < 0.1 ) &&
376  (deltaR<double>(dir1.eta(), dir1.phi(), dis.eta(), dis.phi()) < 0.1 || deltaR<double>(dir2.eta(), dir2.phi(), dis.eta(), dis.phi()) < 0.1 ) )
377  result = true;
378 
379  if ( fabs(dir1.eta()) > 4.0 || fabs(dir2.eta()) > 4.0 ) {
380  if ( (fabs(dir1.theta() - dir2.theta()) < 0.07 ||
381  fabs(dir1.theta() + dir2.theta()) > 3.07 ) &&
382  (fabs(dir1.theta() - dis.theta()) < 0.07 ||
383  fabs(dir1.theta() - dis.theta()) < 0.07 ||
384  fabs(dir1.theta() + dis.theta()) > 3.07 ||
385  fabs(dir1.theta() + dis.theta()) > 3.07 ) )
386 
387  result = true;
388  }
389 
390  return result;
391 }
392 
395 
396  if ( (lhs->degreesOfFreedom() > rhs->degreesOfFreedom() ) ||
397  ( (lhs->degreesOfFreedom() == rhs->degreesOfFreedom() ) &&
398  (lhs)->chi2() < (rhs)->chi2() ) ) return true;
399  else return false;
400 
401 }
402 
403 
406 
408  const std::string category = "Muon|RecoMuon|CosmicMuonSeedGenerator";
409 
410  if (hits1.empty() || hits2.empty() ) return result;
411 
412  for (MuonRecHitContainer::const_iterator ihit1 = hits1.begin(); ihit1 != hits1.end(); ihit1++) {
413  if ( !checkQuality(*ihit1) ) continue;
414 
415  for (MuonRecHitContainer::const_iterator ihit2 = hits2.begin(); ihit2 != hits2.end(); ihit2++) {
416  if ( !checkQuality(*ihit2) ) continue;
417 
418  float dphi = deltaPhi((*ihit1)->globalPosition().phi(), (*ihit2)->globalPosition().phi());
419  if ( dphi < 0.5 ) {
420  if ((*ihit1)->globalPosition().y() > 0.0 && ( (*ihit1)->globalPosition().y() > (*ihit2)->globalPosition().y() ) ) {
421  std::string tag2 = "top"+tag;
422 
423  result.push_back(MuonRecHitPair(*ihit1, *ihit2, tag2));
424  } else if ((*ihit1)->globalPosition().y() < 0.0 && ( (*ihit1)->globalPosition().y() < (*ihit2)->globalPosition().y() ) ) {
425  std::string tag2 = "bottom"+tag;
426  result.push_back(MuonRecHitPair(*ihit2, *ihit1, tag2));
427 
428  }
429  }
430  }
431  }
432 
433  return result;
434 }
435 
437  const edm::EventSetup& eSetup) const {
438  std::vector<TrajectorySeed> result;
439 
440  const std::string category = "Muon|RecoMuon|CosmicMuonSeedGenerator";
441 
442  MuonPatternRecoDumper dumper;
443 
444  float dphi = deltaPhi((hitpair.first)->globalDirection().phi(), (hitpair.second)->globalDirection().phi());
445 
446  LogTrace(category)<<"hitpair.type "<<hitpair.type;
447 
448  map<string, float>::const_iterator iterPar = theParameters.find(hitpair.type);
449  if ( iterPar == theParameters.end() ) {
450  return result;
451  }
452 
453  // set the pt and charge by dphi
454  int charge = (dphi > 0) ? -1 : 1;
455 
456  double pt = 999.0;
457  float paraC = (iterPar->second);
458 
459  if (fabs(dphi) > 1e-5) {
460  pt = paraC/fabs(dphi);
461  }
462 
463  if (pt < 10.0 ) { return result; } //still use the old strategy for low pt
464 
465  AlgebraicVector t(4);
466  AlgebraicSymMatrix mat(5,0) ;
467 
469  if ( hit->dimension() < (hitpair.second)->dimension() ) hit = hitpair.second;
470 
471  // Fill the LocalTrajectoryParameters
472  LocalPoint segPos=hit->localPosition();
473 
474  GlobalVector polar(GlobalVector::Spherical(hit->globalDirection().theta(),
475  hit->globalDirection().phi(),
476  1.));
477  // Force all track downward for cosmic, not beam-halo
478  if (hit->geographicalId().subdetId() == MuonSubdetId::DT && fabs(hit->globalDirection().eta()) < 4.0 && hit->globalDirection().phi() > 0 )
479  polar = - polar;
480 
481  if (hit->geographicalId().subdetId() == MuonSubdetId::CSC && fabs(hit->globalDirection().eta()) > 2.3 ) {
482  polar = - polar;
483  }
484 
485  polar *=fabs(pt)/polar.perp();
486 
487  LocalVector segDir =hit->det()->toLocal(polar);
488 
489  LocalTrajectoryParameters param(segPos,segDir, charge);
490 
491  mat = hit->parametersError().similarityT( hit->projectionMatrix() );
492 
493  float p_err = 0.004/paraC;
494  if (pt < 10.01) p_err = 0.1;
495  mat[0][0]= p_err;
496 
497  LocalTrajectoryError error(asSMatrix<5>(mat));
498 
499  // Create the TrajectoryStateOnSurface
500  TrajectoryStateOnSurface tsos(param, error, hit->det()->surface(), &*theField);
501 
502  LogTrace(category)<<"Trajectory State on Surface of Seed";
503  LogTrace(category)<<"mom: "<<tsos.globalMomentum()<<" phi: "<<tsos.globalMomentum().phi();
504  LogTrace(category)<<"pos: " << tsos.globalPosition();
505  LogTrace(category) << "The RecSegment relies on: ";
506  LogTrace(category) << dumper.dumpMuonId(hit->geographicalId());
507 
508  result.push_back( tsosToSeed(tsos, hit->geographicalId().rawId()) );
509 
510  return result;
511 }
512 
514 
516 
518  TrajectorySeed seed(seedTSOS,container,alongMomentum);
519  return seed;
520 }
521 
T getParameter(std::string const &) const
virtual void produce(edm::Event &, const edm::EventSetup &)
reconstruct muon&#39;s seeds
T perp() const
Definition: PV3DBase.h:72
MuonTransientTrackingRecHit::MuonRecHitContainer selectSegments(const MuonTransientTrackingRecHit::MuonRecHitContainer &) const
select seed candidates from Segments in Event
MuonTransientTrackingRecHit::MuonRecHitPointer MuonRecHitPointer
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
PTrajectoryStateOnDet persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid)
MuonTransientTrackingRecHit::MuonRecHitPointer first
double charge(const std::vector< uint8_t > &Ampls)
std::string dumpMuonId(const DetId &id) const
Geom::Theta< T > theta() const
Definition: PV3DBase.h:75
bool areCorrelated(const MuonTransientTrackingRecHit::MuonRecHitPointer &, const MuonTransientTrackingRecHit::MuonRecHitPointer &) const
check if two rechits are correlated
static const int CSC
Definition: MuonSubdetId.h:15
T mag() const
Definition: PV3DBase.h:67
std::vector< TrajectorySeed > TrajectorySeedCollection
MuonRecHitContainer recHits(const DetLayer *layer, const edm::Event &iEvent)
returns the rechits which are on the layer
tuple result
Definition: query.py:137
bool leftIsBetter(const MuonTransientTrackingRecHit::MuonRecHitPointer &, const MuonTransientTrackingRecHit::MuonRecHitPointer &) const
compare quality of two rechits
std::vector< TrajectorySeed > createSeed(const MuonTransientTrackingRecHit::MuonRecHitPointer &, const edm::EventSetup &) const
create TrajectorySeed from MuonTransientTrackingRecHit
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
#define LogTrace(id)
std::vector< MuonRecHitPair > MuonRecHitPairVector
CLHEP::HepVector AlgebraicVector
bool checkQuality(const MuonTransientTrackingRecHit::MuonRecHitPointer &) const
determine if a MuonTransientTrackingRecHit is qualified to build seed
const T & get() const
Definition: EventSetup.h:55
MuonTransientTrackingRecHit::MuonRecHitPointer second
T eta() const
Definition: PV3DBase.h:76
void setEvent(const edm::Event &)
set event
CLHEP::HepSymMatrix AlgebraicSymMatrix
MuonTransientTrackingRecHit::MuonRecHitContainer MuonRecHitContainer
static const int DT
Definition: MuonSubdetId.h:14
std::vector< MuonRecHitPair > makeSegPairs(const MuonTransientTrackingRecHit::MuonRecHitContainer &, const MuonTransientTrackingRecHit::MuonRecHitContainer &, std::string) const
TrajectorySeed tsosToSeed(const TrajectoryStateOnSurface &, uint32_t) const
uint32_t dimension(pat::CandKinResolution::Parametrization parametrization)
Returns the number of free parameters in a parametrization (3 or 4)
void createSeeds(TrajectorySeedCollection &results, const MuonTransientTrackingRecHit::MuonRecHitContainer &hits, const edm::EventSetup &eSetup) const
generate TrajectorySeeds and put them into results
std::vector< MuonRecHitPointer > MuonRecHitContainer
CosmicMuonSeedGenerator(const edm::ParameterSet &)
Constructor.
virtual ~CosmicMuonSeedGenerator()
Destructor.