CMS 3D CMS Logo

RPCSeedOverlapper.cc
Go to the documentation of this file.
1 
9 
10 using namespace std;
11 using namespace edm;
12 
14  isConfigured = false;
15  isIOset = false;
16  isEventSetupset = false;
17 }
18 
20 
22  isCheckgoodOverlap = iConfig.getParameter<bool>("isCheckgoodOverlap");
23  isCheckcandidateOverlap = iConfig.getParameter<bool>("isCheckcandidateOverlap");
24  ShareRecHitsNumberThreshold = iConfig.getParameter<unsigned int>("ShareRecHitsNumberThreshold");
25  isConfigured = true;
26 }
27 
28 void RPCSeedOverlapper::setIO(std::vector<weightedTrajectorySeed> *goodweightedRef,
29  std::vector<weightedTrajectorySeed> *candidateweightedRef) {
30  goodweightedSeedsRef = goodweightedRef;
31  candidateweightedSeedsRef = candidateweightedRef;
32  isIOset = true;
33 }
34 
35 void RPCSeedOverlapper::unsetIO() { isIOset = false; }
36 
38  eSetup = &iSetup;
39  isEventSetupset = true;
40 }
41 
43  if (isConfigured == false || isIOset == false || isEventSetupset == false) {
44  cout << "Configuration or IO is not set yet" << endl;
45  return;
46  }
47  if (isCheckgoodOverlap == true)
48  CheckOverlap(*eSetup, goodweightedSeedsRef);
49  if (isCheckcandidateOverlap == true)
50  CheckOverlap(*eSetup, candidateweightedSeedsRef);
51 }
52 
54  std::vector<weightedTrajectorySeed> *weightedSeedsRef) {
55  std::vector<weightedTrajectorySeed> sortweightedSeeds;
56  std::vector<weightedTrajectorySeed> tempweightedSeeds;
58 
59  edm::ESHandle<RPCGeometry> rpcGeometry;
60  iSetup.get<MuonGeometryRecord>().get(rpcGeometry);
61 
62  while (!weightedSeedsRef->empty()) {
63  cout << "Finding the weighted seeds group from " << weightedSeedsRef->size() << " seeds which share some recHits"
64  << endl;
65  // Take 1st seed in SeedsRef as referrence and find a collection which always share some recHits with some other
66  tempRecHits.clear();
67  tempweightedSeeds.clear();
68  int N = 0;
69  for (vector<weightedTrajectorySeed>::iterator itweightedseed = weightedSeedsRef->begin();
70  itweightedseed != weightedSeedsRef->end();
71  N++) {
72  TrajectorySeed::range RecHitsRange = itweightedseed->first.recHits();
73  if (N == 0) {
74  cout << "Always take the 1st weighted seed to be the referrence." << endl;
75  for (TrajectorySeed::const_iterator it = RecHitsRange.first; it != RecHitsRange.second; it++) {
76  cout << "Put its recHits to tempRecHits" << endl;
77  tempRecHits.push_back(it->clone());
78  }
79  cout << "Put it to tempweightedSeeds" << endl;
80  tempweightedSeeds.push_back(*itweightedseed);
81  cout << "Then erase from weightedSeedsRef->" << endl;
82  itweightedseed = weightedSeedsRef->erase(itweightedseed);
83  } else {
84  cout << "Come to other weighted seed for checking " << itweightedseed->first.nHits() << " recHits from "
85  << tempRecHits.size() << " temp recHits" << endl;
86  unsigned int ShareRecHitsNumber = 0;
87  for (TrajectorySeed::const_iterator it = RecHitsRange.first; it != RecHitsRange.second; it++) {
88  if (isShareHit(tempRecHits, *it, rpcGeometry))
89  ShareRecHitsNumber++;
90  }
91  if (ShareRecHitsNumber >= ShareRecHitsNumberThreshold) {
92  cout << "This seed is found to belong to current share group" << endl;
93  for (TrajectorySeed::const_iterator it = RecHitsRange.first; it != RecHitsRange.second; it++) {
94  if (!isShareHit(tempRecHits, *it, rpcGeometry)) {
95  cout << "Put its extra recHits to tempRecHits" << endl;
96  tempRecHits.push_back(it->clone());
97  }
98  }
99  cout << "Put it to tempSeeds" << endl;
100  tempweightedSeeds.push_back(*itweightedseed);
101  cout << "Then erase from SeedsRef" << endl;
102  itweightedseed = weightedSeedsRef->erase(itweightedseed);
103  } else
104  itweightedseed++;
105  }
106  }
107  // Find the best weighted seed and kick out those share recHits with it
108  // The best weighted seed save in sortweightedSeeds, those don't share recHits with it will be push back to weightedSeedsRef for next while loop
109  weightedTrajectorySeed bestweightedSeed;
110  vector<weightedTrajectorySeed>::iterator bestweightediter;
111  // Find the min Spt wrt Pt as the best Seed
112  double Quality = 1000000;
113  unsigned NumberofHits = 0;
114  cout << "Find " << tempweightedSeeds.size() << " seeds into one trajectory group" << endl;
115  for (vector<weightedTrajectorySeed>::iterator itweightedseed = tempweightedSeeds.begin();
116  itweightedseed != tempweightedSeeds.end();
117  itweightedseed++) {
118  unsigned int nHits = itweightedseed->first.nHits();
119  //std::vector<float> seed_error = itweightedseed->first.startingState().errorMatrix();
120  //double Spt = seed_error[1];
121  double weightedQuality = itweightedseed->second;
122  cout << "Find a weighted seed with quality " << weightedQuality << endl;
123  if ((NumberofHits < nHits) || (NumberofHits == nHits && weightedQuality < Quality)) {
124  NumberofHits = nHits;
125  Quality = weightedQuality;
126  bestweightedSeed = *itweightedseed;
127  bestweightediter = itweightedseed;
128  }
129  }
130  cout << "Best good temp seed's quality is " << Quality << endl;
131  sortweightedSeeds.push_back(bestweightedSeed);
132  tempweightedSeeds.erase(bestweightediter);
133  tempRecHits.clear();
134 
135  for (TrajectorySeed::const_iterator it = bestweightedSeed.first.recHits().first;
136  it != bestweightedSeed.first.recHits().second;
137  it++)
138  tempRecHits.push_back(it->clone());
139 
140  for (vector<weightedTrajectorySeed>::iterator itweightedseed = tempweightedSeeds.begin();
141  itweightedseed != tempweightedSeeds.end();) {
142  cout << "Checking the temp weighted seed's " << itweightedseed->first.nHits() << " hits to " << tempRecHits.size()
143  << " temp recHits" << endl;
144  TrajectorySeed::range RecHitsRange = itweightedseed->first.recHits();
145  bool isShare = false;
146  for (TrajectorySeed::const_iterator it = RecHitsRange.first; it != RecHitsRange.second; it++)
147  if (isShareHit(tempRecHits, *it, rpcGeometry))
148  isShare = true;
149 
150  if (isShare == true) {
151  cout << "Find one temp seed share some recHits with best weighted seed" << endl;
152  itweightedseed = tempweightedSeeds.erase(itweightedseed);
153  } else {
154  cout << "This seed has no relation with best weighted seed" << endl;
155  weightedSeedsRef->push_back(*itweightedseed);
156  itweightedseed = tempweightedSeeds.erase(itweightedseed);
157  }
158  }
159  }
160  // At the end exchange SeedsRef with sortSeeds
161  weightedSeedsRef->clear();
162  *weightedSeedsRef = sortweightedSeeds;
163 }
164 
166  const TrackingRecHit &hit,
167  edm::ESHandle<RPCGeometry> rpcGeometry) {
168  bool istheSame = false;
169  unsigned int n = 1;
170  cout << "Checking from " << RecHits.size() << " temp recHits" << endl;
171 
172  LocalPoint lpos1 = hit.localPosition();
173  DetId RPCId1 = hit.geographicalId();
174  const GeomDetUnit *rpcroll1 = rpcGeometry->idToDetUnit(RPCId1);
175  GlobalPoint gpos1 = rpcroll1->toGlobal(lpos1);
176  cout << "The hit's position: " << gpos1.x() << ", " << gpos1.y() << ", " << gpos1.z() << endl;
177  for (edm::OwnVector<TrackingRecHit>::const_iterator it = RecHits.begin(); it != RecHits.end(); it++, n++) {
178  cout << "Checking the " << n << " th recHit from tempRecHits" << endl;
179  LocalPoint lpos2 = it->localPosition();
180  DetId RPCId2 = it->geographicalId();
181  const GeomDetUnit *rpcroll2 = rpcGeometry->idToDetUnit(RPCId2);
182  GlobalPoint gpos2 = rpcroll2->toGlobal(lpos2);
183  cout << "The temp hit's position: " << gpos2.x() << ", " << gpos2.y() << ", " << gpos2.z() << endl;
184 
185  if ((gpos1.x() == gpos2.x()) && (gpos1.y() == gpos2.y()) && (gpos1.z() == gpos2.z())) {
186  cout << "This hit is found to be the same" << endl;
187  istheSame = true;
188  }
189  }
190  return istheSame;
191 }
T getParameter(std::string const &) const
std::pair< const_iterator, const_iterator > range
const GeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
Definition: RPCGeometry.cc:30
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:49
size_type size() const
Definition: OwnVector.h:300
T y() const
Definition: PV3DBase.h:60
RPCSeedPattern::weightedTrajectorySeed weightedTrajectorySeed
iterator begin()
Definition: OwnVector.h:280
void push_back(D *&d)
Definition: OwnVector.h:326
bool isShareHit(const edm::OwnVector< TrackingRecHit > &RecHits, const TrackingRecHit &hit, edm::ESHandle< RPCGeometry > rpcGeometry)
recHitContainer::const_iterator const_iterator
T z() const
Definition: PV3DBase.h:61
void clear()
Definition: OwnVector.h:481
virtual LocalPoint localPosition() const =0
Definition: DetId.h:17
iterator end()
Definition: OwnVector.h:285
#define N
Definition: blowfish.cc:9
void configure(const edm::ParameterSet &iConfig)
void setEventSetup(const edm::EventSetup &iSetup)
HLT enums.
T get() const
Definition: EventSetup.h:73
DetId geographicalId() const
void CheckOverlap(const edm::EventSetup &iSetup, std::vector< weightedTrajectorySeed > *SeedsRef)
T x() const
Definition: PV3DBase.h:59
void setIO(std::vector< weightedTrajectorySeed > *goodweightedRef, std::vector< weightedTrajectorySeed > *candidateweightedRef)