CMS 3D CMS Logo

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