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