CMS 3D CMS Logo

MuonCSCSeedFromRecHits.cc
Go to the documentation of this file.
13 #include <iomanip>
14 
15 
18 {
19 }
20 
21 
23 {
25  if(theRhits.size() == 1)
26  {
27  //return createSeed(100., 100., theRhits[0]);
28  makeDefaultSeed(result);
29  return result;
30  }
31  //@@ doesn't handle overlap between ME11 and ME12 correctly
32  // sort by station
33  MuonRecHitContainer station1Hits, station2Hits, station3Hits, station4Hits;
34  for ( MuonRecHitContainer::const_iterator iter = theRhits.begin(), end = theRhits.end();
35  iter != end; ++iter)
36  {
37  int station = CSCDetId((*iter)->geographicalId().rawId()).station();
38  if ((*iter)->isME0()) {
39  station=1;//ME0DetId((*iter)->geographicalId().rawId()).station();
40  }
41 
42  if(station == 1)
43  {
44  station1Hits.push_back(*iter);
45  }
46  else if(station == 2)
47  {
48  station2Hits.push_back(*iter);
49  }
50  else if(station == 3)
51  {
52  station3Hits.push_back(*iter);
53  }
54  else if(station == 4)
55  {
56  station4Hits.push_back(*iter);
57  }
58  }
59 
60  //std::cout << "Station hits " << station1Hits.size() << " "
61  // << station2Hits.size() << " "
62  // << station3Hits.size() << std::endl;
63 
64  // see whether station 2 or station 3 is better
65  MuonRecHitContainer * betterSecondHits = &station2Hits;
66  MuonRecHitContainer * notAsGoodSecondHits = &station3Hits;
67  if(!station2Hits.empty() && !station3Hits.empty())
68  {
69  // swap if station 3 has better quailty
70  if(segmentQuality(station3Hits[0]) < segmentQuality(station2Hits[0]))
71  {
72  betterSecondHits = &station3Hits;
73  notAsGoodSecondHits = &station2Hits;
74  }
75  }
76 
77  // now try to make pairs
78  if(makeSeed(station1Hits, *betterSecondHits, result))
79  {
80  return result;
81  }
82  if(makeSeed(station1Hits, *notAsGoodSecondHits, result))
83  {
84  return result;
85  }
86  if(makeSeed(station2Hits, station3Hits, result))
87  {
88  return result;
89  }
90  if(makeSeed(station1Hits, station4Hits, result))
91  {
92  return result;
93  }
94 
95 
96 
97  // no luck
98  makeDefaultSeed(result);
99  return result;
100 }
101 
102 
104  TrajectorySeed & seed) const
105 {
106  for ( MuonRecHitContainer::const_iterator itr1 = hits1.begin(), end1 = hits1.end();
107  itr1 != end1; ++itr1)
108  {
109  CSCDetId cscId1((*itr1)->geographicalId().rawId());
110  //int type1 = CSCChamberSpecs::whatChamberType(cscId1.station(), cscId1.ring());
111 
112  for ( MuonRecHitContainer::const_iterator itr2 = hits2.begin(), end2 = hits2.end();
113  itr2 != end2; ++itr2)
114  {
115 
116  CSCDetId cscId2((*itr2)->geographicalId().rawId());
117  //int type2 = CSCChamberSpecs::whatChamberType(cscId2.station(), cscId2.ring());
118 
119  // take the first pair that comes along. Probably want to rank them later
120  std::vector<double> pts = thePtExtractor->pT_extract(*itr1, *itr2);
121 
122  double pt = pts[0];
123  double sigmapt = pts[1];
124  double minpt = 3.;
125 
126  // if too small, probably an error. Keep trying.
127  if(fabs(pt) > minpt)
128  {
129  double maxpt = 2000.;
130  if(pt > maxpt) {
131  pt = maxpt;
132  sigmapt = maxpt;
133  }
134  if(pt < -maxpt) {
135  pt = -maxpt;
136  sigmapt = maxpt;
137  }
138 
139  // get the position and direction from the higher-quality segment
141  seed = createSeed(pt, sigmapt, bestSeg);
142 
143  //std::cout << "FITTED TIMESPT " << pt << " dphi " << dphi << " eta " << eta << std::endl;
144  return true;
145  }
146 
147  }
148  }
149 
150  // guess it didn't find one
151 //std::cout << "NOTHING FOUND ! " << std::endl;
152  return false;
153 }
154 
155 
156 //typedef MuonTransientTrackingRecHit::MuonRecHitContainer MuonRecHitContainer;
158 {
159  int Nchi2 = 0;
160  int quality = 0;
161  int nhits = segment->recHits().size();
162  if ( segment->chi2()/(nhits*2.-4.) > 3. ) Nchi2 = 1;
163  if ( segment->chi2()/(nhits*2.-4.) > 9. ) Nchi2 = 2;
164 
165  if ( nhits > 4 ) quality = 1 + Nchi2;
166  if ( nhits == 4 ) quality = 3 + Nchi2;
167  if ( nhits == 3 ) quality = 5 + Nchi2;
168 
169  float dPhiGloDir = fabs ( deltaPhi(segment->globalPosition().barePhi(), segment->globalDirection().barePhi()) );
170 
171  if ( dPhiGloDir > .2 ) ++quality;
172  // add a penalty for being ME1A if the chamber is ganged
173  if ( segment->isCSC() and CSCDetId(segment->geographicalId()).ring() == 4 )
174  {
175  const auto chamber = dynamic_cast<const CSCChamber*>(segment->det());
176  if ( chamber->specs()->gangedStrips() ) ++quality;
177  }
178 
179  return quality;
180 }
181 
182 
183 
186 {
187  MuonRecHitPointer me1=nullptr, meit=nullptr;
188  float dPhiGloDir = .0; // +v
189  float bestdPhiGloDir = M_PI; // +v
190  int quality1 = 0, quality = 0; // +v I= 5,6-p. / II= 4p. / III= 3p.
191 
192  for ( MuonRecHitContainer::const_iterator iter = endcapHits.begin(); iter!= endcapHits.end(); iter++ ){
193  if ( !(*iter)->isCSC() && !(*iter)->isME0() ) continue;
194 
195  // tmp compar. Glob-Dir for the same tr-segm:
196 
197  meit = *iter;
198 
199  quality = segmentQuality(meit);
200 
201  dPhiGloDir = fabs ( deltaPhi(meit->globalPosition().barePhi(), meit->globalDirection().barePhi()) );
202 
203  if(!me1){
204  me1 = meit;
205  quality1 = quality;
206  bestdPhiGloDir = dPhiGloDir;
207  }
208 
209  if(me1) {
210 
211  if ( !me1->isValid() ) {
212  me1 = meit;
213  quality1 = quality;
214  bestdPhiGloDir = dPhiGloDir;
215  }
216 
217  if ( me1->isValid() && quality < quality1 ) {
218  me1 = meit;
219  quality1 = quality;
220  bestdPhiGloDir = dPhiGloDir;
221  }
222 
223  if ( me1->isValid() && bestdPhiGloDir > .03 ) {
224  if ( dPhiGloDir < bestdPhiGloDir - .01 && quality == quality1 ) {
225  me1 = meit;
226  quality1 = quality;
227  bestdPhiGloDir = dPhiGloDir;
228  }
229  }
230  }
231 
232  } // iter
233 
234  return me1;
235 }
236 
237 
239 {
240  //Search ME1 ...
242  // bool good=false;
243 
244  if(me1 && me1->isValid() )
245  {
246  //revert if a LogTrace or smth is necessary good =
247  createDefaultEndcapSeed(me1, seed);
248  }
249 }
250 
251 
252 
253 
254 
255 bool
257  TrajectorySeed & seed) const {
258  //float momentum = computeDefaultPt(last);
259  std::vector<double> momentum = thePtExtractor->pT_extract(last, last);
260  seed = createSeed(momentum[0],momentum[1],last);
261  return true;
262 }
263 
264 
265 
267 {
268  for ( MuonRecHitContainer::const_iterator iter = theRhits.begin(); iter!= theRhits.end(); iter++ ){
269  if ( !(*iter)->isCSC() ) continue;
270  for ( MuonRecHitContainer::const_iterator iter2 = iter + 1; iter2 != theRhits.end(); ++iter2)
271  {
272  if( !(*iter2)->isCSC() ) continue;
273 
274  CSCDetId cscId1((*iter)->geographicalId().rawId());
275  CSCDetId cscId2((*iter2)->geographicalId().rawId());
276  double dphi = deltaPhi((**iter).globalPosition().barePhi(), (**iter2).globalPosition().barePhi());
277 
278  int type1 = cscId1.iChamberType();
279  int type2 = cscId2.iChamberType();
280 
281  // say the lower station first
282  if(type1 < type2)
283  {
284  std::cout << "HITPAIRA," << type1 << type2 << "," <<
285  dphi << "," << (**iter).globalPosition().eta() << std::endl;
286  }
287  if(type2 < type1)
288  {
289  std::cout << "HITPAIRB," << type2 << type1 << "," <<
290  -dphi << "," << (**iter2).globalPosition().eta() << std::endl;
291  }
292  if(type1 == type2)
293  {
294  std::cout << "HITPAIRSAMESTATION," << type1 << cscId1.ring() << cscId2.ring()
295  << "," << dphi << "," << (**iter).globalPosition().eta() << std::endl;
296  }
297 
298  }
299  }
300 }
MuonTransientTrackingRecHit::MuonRecHitPointer MuonRecHitPointer
virtual TrajectorySeed seed() const
MuonTransientTrackingRecHit::MuonRecHitContainer theRhits
MuonTransientTrackingRecHit::MuonRecHitContainer MuonRecHitContainer
MuonTransientTrackingRecHit::ConstMuonRecHitPointer ConstMuonRecHitPointer
const MuonSeedPtExtractor * thePtExtractor
static const double pts[33]
Definition: Constants.h:30
ConstMuonRecHitPointer bestEndcapHit(const MuonRecHitContainer &endcapHits) const
bool createDefaultEndcapSeed(ConstMuonRecHitPointer last, TrajectorySeed &seed) const
int segmentQuality(ConstMuonRecHitPointer muon) const
#define end
Definition: vmac.h:37
#define M_PI
void makeDefaultSeed(TrajectorySeed &seed) const
TrajectorySeed createSeed(float ptmean, float sptmean, MuonTransientTrackingRecHit::ConstMuonRecHitPointer last) const
virtual std::vector< double > pT_extract(MuonTransientTrackingRecHit::ConstMuonRecHitPointer firstHit, MuonTransientTrackingRecHit::ConstMuonRecHitPointer secondHit) const
bool makeSeed(const MuonRecHitContainer &hits1, const MuonRecHitContainer &hits2, TrajectorySeed &seed) const