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