CMS 3D CMS Logo

CosmicMuonSeedGenerator.cc
Go to the documentation of this file.
13 
15 
19 
25 
28 
32 
34 
35 #include <vector>
36 
39 
40 using namespace edm;
41 using namespace std;
42 
43 // Constructor
45  produces<TrajectorySeedCollection>();
46 
47  // enable the DT chamber
48  theEnableDTFlag = pset.getParameter<bool>("EnableDTMeasurement");
49  // enable the CSC chamber
50  theEnableCSCFlag = pset.getParameter<bool>("EnableCSCMeasurement");
51 
52  theDTRecSegmentLabel = pset.getParameter<InputTag>("DTRecSegmentLabel");
53 
54  theCSCRecSegmentLabel = pset.getParameter<InputTag>("CSCRecSegmentLabel");
55 
56  // the maximum number of TrajectorySeed
57  theMaxSeeds = pset.getParameter<int>("MaxSeeds");
58 
59  theMaxDTChi2 = pset.getParameter<double>("MaxDTChi2");
60  theMaxCSCChi2 = pset.getParameter<double>("MaxCSCChi2");
61 
62  theForcePointDownFlag = pset.existsAs<bool>("ForcePointDown") ? pset.getParameter<bool>("ForcePointDown") : true;
63 
64  // pre-determined parameters for seed pt calculation ( pt * dphi )
65  theParameters["topmb41"] = 0.87;
66  theParameters["bottommb41"] = 1.2;
67  theParameters["topmb42"] = 0.67;
68  theParameters["bottommb42"] = 0.98;
69  theParameters["topmb43"] = 0.34;
70  theParameters["bottommb43"] = 0.58;
71  theParameters["topmb31"] = 0.54;
72  theParameters["bottommb31"] = 0.77;
73  theParameters["topmb32"] = 0.35;
74  theParameters["bottommb32"] = 0.55;
75  theParameters["topmb21"] = 0.21;
76  theParameters["bottommb21"] = 0.31;
77 
78 
79  edm::ConsumesCollector iC = consumesCollector();
80  muonMeasurements = new MuonDetLayerMeasurements(theDTRecSegmentLabel,theCSCRecSegmentLabel,
81 
82  InputTag(),InputTag(),InputTag(),iC,
83  theEnableDTFlag,theEnableCSCFlag,false,false,false);
84 
85 
86 
87 }
88 
89 // Destructor
91  if (muonMeasurements)
92  delete muonMeasurements;
93 }
94 
95 
96 // reconstruct muon's seeds
98 
99  eSetup.get<IdealMagneticFieldRecord>().get(theField);
100 
101  auto output = std::make_unique<TrajectorySeedCollection>();
102 
104 
105  std::string category = "Muon|RecoMuon|CosmicMuonSeedGenerator";
106 
107  // Muon Geometry - DT, CSC and RPC
108  eSetup.get<MuonRecoGeometryRecord>().get(theMuonLayers);
109 
110  // get the DT layers
111  vector<const DetLayer*> dtLayers = theMuonLayers->allDTLayers();
112 
113  // get the CSC layers
114  vector<const DetLayer*> cscForwardLayers = theMuonLayers->forwardCSCLayers();
115  vector<const DetLayer*> cscBackwardLayers = theMuonLayers->backwardCSCLayers();
116 
117 
118 
119  muonMeasurements->setEvent(event);
120 
121  MuonRecHitContainer allHits;
122 
123  vector<MuonRecHitContainer> RHMBs;
124  vector<MuonRecHitContainer> RHMEFs;
125  vector<MuonRecHitContainer> RHMEBs;
126 
127  stable_sort(allHits.begin(),allHits.end(),DecreasingGlobalY());
128 
129  for (vector<const DetLayer*>::reverse_iterator icsclayer = cscForwardLayers.rbegin();
130  icsclayer != cscForwardLayers.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<const DetLayer*>::reverse_iterator icsclayer = cscBackwardLayers.rbegin();
138  icsclayer != cscBackwardLayers.rend() - 1; ++icsclayer) {
139 
140  MuonRecHitContainer RHMF = muonMeasurements->recHits(*icsclayer);
141  allHits.insert(allHits.end(),RHMF.begin(),RHMF.end());
142 
143  }
144 
145  for (vector<const DetLayer*>::reverse_iterator idtlayer = dtLayers.rbegin();
146  idtlayer != dtLayers.rend(); ++idtlayer) {
147 
148  MuonRecHitContainer RHMB = muonMeasurements->recHits(*idtlayer);
149  RHMBs.push_back(RHMB);
150 
151  if ( idtlayer != dtLayers.rbegin() ) allHits.insert(allHits.end(),RHMB.begin(),RHMB.end());
152 
153  }
154 
155 // stable_sort(allHits.begin(),allHits.end(),DecreasingGlobalY());
156 
157  LogTrace(category)<<"all RecHits: "<<allHits.size();
158 
159 // CosmicMuonSeedGenerator::MuonRecHitPairVector mb41 = makeSegPairs(RHMBs[0], RHMBs[3], "mb41");
160 // createSeeds(seeds, mb41, eSetup);
161 
162 // CosmicMuonSeedGenerator::MuonRecHitPairVector mb43 = makeSegPairs(RHMBs[0],RHMBs[1], "mb43");
163 // createSeeds(seeds, mb43, eSetup);
164 
165  CosmicMuonSeedGenerator::MuonRecHitPairVector mb42 = makeSegPairs(RHMBs[0],RHMBs[2], "mb42");
166  createSeeds(seeds, mb42, eSetup);
167 
168 // CosmicMuonSeedGenerator::MuonRecHitPairVector mb32 = makeSegPairs(RHMBs[1], RHMBs[2], "mb32");
169 // createSeeds(seeds, mb32, eSetup);
170 
171  CosmicMuonSeedGenerator::MuonRecHitPairVector mb31 = makeSegPairs(RHMBs[1], RHMBs[3], "mb31");
172  createSeeds(seeds, mb31, eSetup);
173 
174 // CosmicMuonSeedGenerator::MuonRecHitPairVector mb21 = makeSegPairs(RHMBs[2], RHMBs[3], "mb21");
175 // createSeeds(seeds, mb21, eSetup);
176 
177  if ( !allHits.empty() ) {
178 
179  MuonRecHitContainer goodhits = selectSegments(allHits);
180  LogTrace(category)<<"good RecHits: "<<goodhits.size();
181 
182  if ( goodhits.empty() ) {
183  LogTrace(category)<<"No qualified Segments in Event! ";
184  LogTrace(category)<<"Use 2D RecHit";
185 
186  createSeeds(seeds,allHits,eSetup);
187 
188  }
189  else {
190  createSeeds(seeds,goodhits,eSetup);
191  }
192  }
193 
194  LogTrace(category)<<"Seeds built: "<<seeds.size();
195 
196  for(std::vector<TrajectorySeed>::iterator seed = seeds.begin();
197  seed != seeds.end(); ++seed) {
198  output->push_back(*seed);
199  }
200 
201  event.put(std::move(output));
202  seeds.clear();
203 
204 }
205 
206 
208 
209  const std::string category = "Muon|RecoMuon|CosmicMuonSeedGenerator";
210 
211  // only use 4D segments
212  if ( !hit->isValid() ) return false;
213 
214  if (hit->dimension() < 4) {
215  LogTrace(category)<<"dim < 4";
216  return false;
217  }
218 
219  if (hit->isDT() && ( hit->chi2()> theMaxDTChi2 )) {
220  LogTrace(category)<<"DT chi2 too large";
221  return false;
222  }
223  else if (hit->isCSC() &&( hit->chi2()> theMaxCSCChi2 ) ) {
224  LogTrace(category)<<"CSC chi2 too large";
225  return false;
226  }
227  return true;
228 
229 }
230 
232 
234  const std::string category = "Muon|RecoMuon|CosmicMuonSeedGenerator";
235 
236  //Only select good quality Segments
237  for (MuonRecHitContainer::const_iterator hit = hits.begin(); hit != hits.end(); hit++) {
238  if ( checkQuality(*hit) ) result.push_back(*hit);
239  }
240 
241  if ( result.size() < 2 ) return result;
242 
243  MuonRecHitContainer result2;
244 
245  //avoid selecting Segments with similar direction
246  for (MuonRecHitContainer::iterator hit = result.begin(); hit != result.end(); hit++) {
247  if (*hit == 0) continue;
248  if ( !(*hit)->isValid() ) continue;
249  bool good = true;
250  //UNUSED: GlobalVector dir1 = (*hit)->globalDirection();
251  //UNUSED: GlobalPoint pos1 = (*hit)->globalPosition();
252  for (MuonRecHitContainer::iterator hit2 = hit + 1; hit2 != result.end(); hit2++) {
253  if (*hit2 == 0) continue;
254  if ( !(*hit2)->isValid() ) continue;
255 
256  //compare direction and position
257  //UNUSED: GlobalVector dir2 = (*hit2)->globalDirection();
258  //UNUSED: GlobalPoint pos2 = (*hit2)->globalPosition();
259  if ( !areCorrelated((*hit),(*hit2)) ) continue;
260 
261  if ( !leftIsBetter((*hit),(*hit2)) ) {
262  good = false;
263  } else (*hit2) = 0;
264  }
265 
266  if ( good ) result2.push_back(*hit);
267  }
268 
269  result.clear();
270 
271  return result2;
272 
273 }
274 
276  const MuonRecHitContainer& hits,
277  const edm::EventSetup& eSetup) const {
278 
279  const std::string category = "Muon|RecoMuon|CosmicMuonSeedGenerator";
280 
281  if (hits.size() == 0 || results.size() >= theMaxSeeds ) return;
282  for (MuonRecHitContainer::const_iterator ihit = hits.begin(); ihit != hits.end(); ihit++) {
283  const std::vector<TrajectorySeed>& sds = createSeed((*ihit),eSetup);
284  LogTrace(category)<<"created seeds from rechit "<<sds.size();
285  results.insert(results.end(),sds.begin(),sds.end());
286  if ( results.size() >= theMaxSeeds ) break;
287  }
288  return;
289 }
290 
293  const edm::EventSetup& eSetup) const {
294 
295  const std::string category = "Muon|RecoMuon|CosmicMuonSeedGenerator";
296 
297  if (hitpairs.size() == 0 || results.size() >= theMaxSeeds ) return;
298  for (CosmicMuonSeedGenerator::MuonRecHitPairVector::const_iterator ihitpair = hitpairs.begin(); ihitpair != hitpairs.end(); ihitpair++) {
299  const std::vector<TrajectorySeed>& sds = createSeed((*ihitpair),eSetup);
300  LogTrace(category)<<"created seeds from rechit "<<sds.size();
301  results.insert(results.end(),sds.begin(),sds.end());
302  if ( results.size() >= theMaxSeeds ) break;
303  }
304  return;
305 }
306 
307 
308 std::vector<TrajectorySeed> CosmicMuonSeedGenerator::createSeed(const MuonRecHitPointer& hit, const edm::EventSetup& eSetup) const {
309 
310  std::vector<TrajectorySeed> result;
311 
312  const std::string category = "Muon|RecoMuon|CosmicMuonSeedGenerator";
313 
314  MuonPatternRecoDumper dumper;
315 
316  // set the pt by hand
317  double pt = 10.0;
318 
319  // AlgebraicVector4 t;
320  AlgebraicSymMatrix mat(5,0);
321 
322  // Fill the LocalTrajectoryParameters
323  LocalPoint segPos=hit->localPosition();
324 
325  GlobalVector polar(GlobalVector::Spherical(hit->globalDirection().theta(),
326  hit->globalDirection().phi(),
327  1.));
328  // Force all track downward for cosmic, not beam-halo
329  if(theForcePointDownFlag){
330  if (hit->geographicalId().subdetId() == MuonSubdetId::DT && fabs(hit->globalDirection().eta()) < 4.0 && hit->globalDirection().phi() > 0 )
331  polar = - polar;
332 
333  if (hit->geographicalId().subdetId() == MuonSubdetId::CSC && fabs(hit->globalDirection().eta()) > 2.3 )
334  polar = - polar;
335  }
336 
337  polar *=fabs(pt)/polar.perp();
338 
339  LocalVector segDir =hit->det()->toLocal(polar);
340 
341  int charge= 1;
342  LocalTrajectoryParameters param(segPos,segDir, charge);
343 
344  charge= -1;
345  LocalTrajectoryParameters param2(segPos,segDir, charge);
346 
347  mat = hit->parametersError().similarityT( hit->projectionMatrix() );
348 
349  float p_err = 0.2;
350  mat[0][0]= p_err;
351 
352  LocalTrajectoryError error(asSMatrix<5>(mat));
353 
354  // Create the TrajectoryStateOnSurface
355  TrajectoryStateOnSurface tsos(param, error, hit->det()->surface(), &*theField);
356  TrajectoryStateOnSurface tsos2(param2, error, hit->det()->surface(), &*theField);
357 
358  LogTrace(category)<<"Trajectory State on Surface of Seed";
359  LogTrace(category)<<"mom: "<<tsos.globalMomentum()<<" phi: "<<tsos.globalMomentum().phi();
360  LogTrace(category)<<"pos: " << tsos.globalPosition();
361  LogTrace(category) << "The RecSegment relies on: ";
362  LogTrace(category) << dumper.dumpMuonId(hit->geographicalId());
363 
365  container.push_back(hit->hit()->clone());
366 
367  result.push_back( tsosToSeed(tsos, hit->geographicalId().rawId(), container) );
368  result.push_back( tsosToSeed(tsos2, hit->geographicalId().rawId(), container) );
369 
370  return result;
371 }
372 
374  bool result = false;
375 
376  GlobalVector dir1 = lhs->globalDirection();
377  GlobalPoint pos1 = lhs->globalPosition();
378  GlobalVector dir2 = rhs->globalDirection();
379  GlobalPoint pos2 = rhs->globalPosition();
380 
381  GlobalVector dis = pos2 - pos1;
382 
383  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 )
384  && dis.mag() < 5.0 )
385  result = true;
386 
387  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 ) &&
388  (deltaR<double>(dir1.eta(), dir1.phi(), dis.eta(), dis.phi()) < 0.1 || deltaR<double>(dir2.eta(), dir2.phi(), dis.eta(), dis.phi()) < 0.1 ) )
389  result = true;
390 
391  if ( fabs(dir1.eta()) > 4.0 || fabs(dir2.eta()) > 4.0 ) {
392  if ( (fabs(dir1.theta() - dir2.theta()) < 0.07 ||
393  fabs(dir1.theta() + dir2.theta()) > 3.07 ) &&
394  (fabs(dir1.theta() - dis.theta()) < 0.07 ||
395  fabs(dir1.theta() - dis.theta()) < 0.07 ||
396  fabs(dir1.theta() + dis.theta()) > 3.07 ||
397  fabs(dir1.theta() + dis.theta()) > 3.07 ) )
398 
399  result = true;
400  }
401 
402  return result;
403 }
404 
407 
408  if ( (lhs->degreesOfFreedom() > rhs->degreesOfFreedom() ) ||
409  ( (lhs->degreesOfFreedom() == rhs->degreesOfFreedom() ) &&
410  (lhs)->chi2() < (rhs)->chi2() ) ) return true;
411  else return false;
412 
413 }
414 
415 
418 
420  const std::string category = "Muon|RecoMuon|CosmicMuonSeedGenerator";
421 
422  if (hits1.empty() || hits2.empty() ) return result;
423 
424  for (MuonRecHitContainer::const_iterator ihit1 = hits1.begin(); ihit1 != hits1.end(); ihit1++) {
425  if ( !checkQuality(*ihit1) ) continue;
426 
427  for (MuonRecHitContainer::const_iterator ihit2 = hits2.begin(); ihit2 != hits2.end(); ihit2++) {
428  if ( !checkQuality(*ihit2) ) continue;
429 
430  float dphi = deltaPhi((*ihit1)->globalPosition().barePhi(), (*ihit2)->globalPosition().barePhi());
431  if ( dphi < 0.5 ) {
432  if ((*ihit1)->globalPosition().y() > 0.0 && ( (*ihit1)->globalPosition().y() > (*ihit2)->globalPosition().y() ) ) {
433  std::string tag2 = "top"+tag;
434 
435  result.push_back(MuonRecHitPair(*ihit1, *ihit2, tag2));
436  } else if ((*ihit1)->globalPosition().y() < 0.0 && ( (*ihit1)->globalPosition().y() < (*ihit2)->globalPosition().y() ) ) {
437  std::string tag2 = "bottom"+tag;
438  result.push_back(MuonRecHitPair(*ihit2, *ihit1, tag2));
439 
440  }
441  }
442  }
443  }
444 
445  return result;
446 }
447 
449  const edm::EventSetup& eSetup) const {
450  std::vector<TrajectorySeed> result;
451 
452  const std::string category = "Muon|RecoMuon|CosmicMuonSeedGenerator";
453 
454  MuonPatternRecoDumper dumper;
455 
456  float dphi = deltaPhi((hitpair.first)->globalDirection().barePhi(), (hitpair.second)->globalDirection().barePhi());
457 
458  LogTrace(category)<<"hitpair.type "<<hitpair.type;
459 
460  map<string, float>::const_iterator iterPar = theParameters.find(hitpair.type);
461  if ( iterPar == theParameters.end() ) {
462  return result;
463  }
464 
465  // set the pt and charge by dphi
466  int charge = (dphi > 0) ? -1 : 1;
467 
468  double pt = 999.0;
469  float paraC = (iterPar->second);
470 
471  if (fabs(dphi) > 1e-5) {
472  pt = paraC/fabs(dphi);
473  }
474 
475  if (pt < 10.0 ) { return result; } //still use the old strategy for low pt
476 
477  AlgebraicVector t(4);
478  AlgebraicSymMatrix mat(5,0) ;
479 
481  if ( hit->dimension() < (hitpair.second)->dimension() ) hit = hitpair.second;
482 
483  // Fill the LocalTrajectoryParameters
484  LocalPoint segPos=hit->localPosition();
485 
486  GlobalVector polar(GlobalVector::Spherical(hit->globalDirection().theta(),
487  hit->globalDirection().phi(),
488  1.));
489  // Force all track downward for cosmic, not beam-halo
490  if(theForcePointDownFlag){
491  if (hit->geographicalId().subdetId() == MuonSubdetId::DT && fabs(hit->globalDirection().eta()) < 4.0 && hit->globalDirection().phi() > 0 )
492  polar = - polar;
493 
494  if (hit->geographicalId().subdetId() == MuonSubdetId::CSC && fabs(hit->globalDirection().eta()) > 2.3 )
495  polar = - polar;
496  }
497 
498  polar *=fabs(pt)/polar.perp();
499 
500  LocalVector segDir =hit->det()->toLocal(polar);
501 
502  LocalTrajectoryParameters param(segPos,segDir, charge);
503 
504  mat = hit->parametersError().similarityT( hit->projectionMatrix() );
505 
506  float p_err = 0.004/paraC;
507  if (pt < 10.01) p_err = 0.1;
508  mat[0][0]= p_err;
509 
510  LocalTrajectoryError error(asSMatrix<5>(mat));
511 
512  // Create the TrajectoryStateOnSurface
513  TrajectoryStateOnSurface tsos(param, error, hit->det()->surface(), &*theField);
514 
515  LogTrace(category)<<"Trajectory State on Surface of Seed";
516  LogTrace(category)<<"mom: "<<tsos.globalMomentum()<<" phi: "<<tsos.globalMomentum().phi();
517  LogTrace(category)<<"pos: " << tsos.globalPosition();
518  LogTrace(category) << "The RecSegment relies on: ";
519  LogTrace(category) << dumper.dumpMuonId(hit->geographicalId());
520 
522  container.push_back(hitpair.first->hit()->clone());
523  container.push_back(hitpair.second->hit()->clone());
524 
525  result.push_back( tsosToSeed(tsos, hit->geographicalId().rawId(), container) );
526 
527  return result;
528 }
529 
531 
533  return tsosToSeed(tsos, id, container);
534 }
535 
537 
539  TrajectorySeed seed(seedTSOS,container,alongMomentum);
540  return seed;
541 }
T getParameter(std::string const &) const
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:186
T perp() const
Definition: PV3DBase.h:72
MuonTransientTrackingRecHit::MuonRecHitContainer MuonRecHitContainer
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
std::string dumpMuonId(const DetId &id) const
Geom::Theta< T > theta() const
Definition: PV3DBase.h:75
void push_back(D *&d)
Definition: OwnVector.h:290
bool areCorrelated(const MuonTransientTrackingRecHit::MuonRecHitPointer &, const MuonTransientTrackingRecHit::MuonRecHitPointer &) const
check if two rechits are correlated
static const int CSC
Definition: MuonSubdetId.h:13
T mag() const
Definition: PV3DBase.h:67
std::vector< TrajectorySeed > TrajectorySeedCollection
std::shared_ptr< MuonTransientTrackingRecHit > MuonRecHitPointer
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
#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
MuonTransientTrackingRecHit::MuonRecHitPointer MuonRecHitPointer
const T & get() const
Definition: EventSetup.h:55
MuonTransientTrackingRecHit::MuonRecHitPointer second
T eta() const
Definition: PV3DBase.h:76
HLT enums.
CLHEP::HepSymMatrix AlgebraicSymMatrix
MuonTransientTrackingRecHit::MuonRecHitContainer MuonRecHitContainer
static const int DT
Definition: MuonSubdetId.h:12
virtual void produce(edm::Event &, const edm::EventSetup &) override
reconstruct muon&#39;s seeds
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
def move(src, dest)
Definition: eostools.py:510
CosmicMuonSeedGenerator(const edm::ParameterSet &)
Constructor.
Definition: event.py:1
virtual ~CosmicMuonSeedGenerator()
Destructor.