CMS 3D CMS Logo

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