CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Roads.cc
Go to the documentation of this file.
1 //
2 // Package: RecoTracker/RoadMapRecord
3 // Class: Roads
4 //
5 // Description: The Roads object holds the RoadSeeds
6 // and the RoadSets of all Roads through
7 // the detector. A RoadSeed consists
8 // of the inner and outer SeedRing,
9 // a RoadSet consists of all Rings in
10 // in the Road.
11 //
12 // Original Author: Oliver Gutsche, gutsche@fnal.gov
13 // Created: Thu Jan 12 21:00:00 UTC 2006
14 //
15 // $Author: gutsche $
16 // $Date: 2007/02/05 19:22:46 $
17 // $Revision: 1.6 $
18 //
19 
20 #include <iostream>
21 #include <sstream>
22 
24 
26 
30 
32 
34 
35 }
36 
37 Roads::Roads(std::string ascii_filename, const Rings *rings) : rings_(rings) {
38 
39  readInFromAsciiFile(ascii_filename);
40 
41 }
42 
44 
45 }
46 
47 void Roads::readInFromAsciiFile(std::string ascii_filename) {
48 
49  // input file
50  std::ifstream input(ascii_filename.c_str());
51 
52  // variable declaration
53  unsigned int counter = 0;
54  std::istringstream stream;
55  std::string line;
56  unsigned int nroads = 0;
57  unsigned int nrings = 0;
58  unsigned int nlayers = 0;
59  unsigned int index = 0;
60 
61  // read in number of roads
62  std::getline(input,line);
63  while (std::isspace(line[0]) || (line[0] == 35) ) {
64  std::getline(input,line);
65  }
66  stream.str(line);
67  stream.clear();
68  stream >> nroads;
69 
70  for (unsigned int road = 0;
71  road < nroads;
72  ++road ) {
73  // read in number of inner seed rings
74  std::getline(input,line);
75  while (std::isspace(line[0]) || (line[0] == 35) ) {
76  std::getline(input,line);
77  }
78  std::vector<const Ring*> innerSeedRings;
79  stream.str(line);
80  stream.clear();
81  stream >> nrings;
82  for ( unsigned int i = 0;
83  i < nrings;
84  ++i ) {
85 
86  // read in ring indices for inner seed rings
87  std::getline(input,line);
88  while (std::isspace(line[0]) || (line[0] == 35) ) {
89  std::getline(input,line);
90  }
91  stream.str(line);
92  stream.clear();
93  stream >> index;
94  innerSeedRings.push_back(rings_->getRing(index));
95  }
96 
97  // read in number of outer seed rings
98  std::getline(input,line);
99  while (std::isspace(line[0]) || (line[0] == 35) ) {
100  std::getline(input,line);
101  }
102  std::vector<const Ring*> outerSeedRings;
103  stream.str(line);
104  stream.clear();
105  stream >> nrings;
106  for ( unsigned int i = 0;
107  i < nrings;
108  ++i ) {
109 
110  // read in ring indices for outer seed rings
111  std::getline(input,line);
112  while (std::isspace(line[0]) || (line[0] == 35) ) {
113  std::getline(input,line);
114  }
115  stream.str(line);
116  stream.clear();
117  stream >> index;
118  outerSeedRings.push_back(rings_->getRing(index));
119  }
120 
121  // RoadSeed
122  RoadSeed seed(innerSeedRings,outerSeedRings);
123 
124  // RoadSet
125  RoadSet set;
126 
127  // number of layers in road set
128  std::getline(input,line);
129  while (std::isspace(line[0]) || (line[0] == 35) ) {
130  std::getline(input,line);
131  }
132  stream.str(line);
133  stream.clear();
134  stream >> nlayers;
135 
136  for ( unsigned int i = 0;
137  i < nlayers;
138  ++i ) {
139 
140  std::vector<const Ring*> layer;
141 
142  // number of rings in layer
143  std::getline(input,line);
144  while (std::isspace(line[0]) || (line[0] == 35) ) {
145  std::getline(input,line);
146  }
147  stream.str(line);
148  stream.clear();
149  stream >> nrings;
150  for ( unsigned int j = 0; j < nrings; ++j ) {
151  std::getline(input,line);
152  while (std::isspace(line[0]) || (line[0] == 35) ) {
153  std::getline(input,line);
154  }
155  stream.str(line);
156  stream.clear();
157  stream >> index;
158  layer.push_back(rings_->getRing(index));
159  }
160  set.push_back(layer);
161  }
162 
163 
164  // add seed and set to map
165  roadMap_.insert(make_pair(seed,set));
166  ++counter;
167  }
168 
169  edm::LogInfo("RoadSearch") << "Read in: " << counter << " RoadSets from file: " << ascii_filename;
170 
171 }
172 
173 void Roads::dump(std::string ascii_filename) const {
174 
175  std::ofstream stream(ascii_filename.c_str());
176 
177  dumpHeader(stream);
178 
179  stream << "### Road information ###" << std::endl;
180  stream << roadMap_.size() << std::endl;
181 
182  unsigned int counter = 0;
183 
184  for ( const_iterator roaditerator = roadMap_.begin();
185  roaditerator != roadMap_.end();
186  ++roaditerator ) {
187 
188  ++counter;
189 
190  stream << "### RoadMap Entry " << counter << " ###" << std::endl;
191 
192  RoadSeed seed = (*roaditerator).first;
193  RoadSet set = (*roaditerator).second;
194 
195  stream << "### RoadSeed First Ring ###" << std::endl;
196  stream << seed.first.size() << std::endl;
197  for (std::vector<const Ring*>::const_iterator ring = seed.first.begin();
198  ring != seed.first.end();
199  ++ring ) {
200  stream << (*ring)->getindex() << std::endl;
201  }
202  stream << "### RoadSeed Second Ring ###" << std::endl;
203  stream << seed.second.size() << std::endl;
204  for (std::vector<const Ring*>::const_iterator ring = seed.second.begin();
205  ring != seed.second.end();
206  ++ring ) {
207  stream << (*ring)->getindex() << std::endl;
208  }
209 
210  stream << "### RoadSet ###" << std::endl;
211  stream << set.size() << std::endl;
212  for ( RoadSet::const_iterator layer = set.begin(); layer != set.end(); ++layer ) {
213  stream << "### Layer ###" << std::endl;
214  stream << layer->size() << std::endl;
215  for ( std::vector<const Ring*>::const_iterator ring = layer->begin();
216  ring != layer->end();
217  ++ring ) {
218  stream << (*ring)->getindex() << std::endl;
219  }
220  }
221  }
222 }
223 
224 void Roads::dumpHeader(std::ofstream &stream) const {
225 
226  stream << "#" << std::endl;
227  stream << "# Roads for the RoadSearch tracking algorithm" << std::endl;
228  stream << "# Ascii Dump" << std::endl;
229  stream << "# " << std::endl;
230  stream << "# Content:" << std::endl;
231  stream << "# " << std::endl;
232  stream << "# a dump of the RoadMap structure:" << std::endl;
233  stream << "#" << std::endl;
234  stream << "# Road Information: <number of roads>" << std::endl;
235  stream << "# Ring: index, rmin, rmax, zmin, zmax, std::vector<DetId>: Ring of DetUnits in phi taken from ring service" << std::endl;
236  stream << "# RoadSeed: std::pair<std::vector<const Ring*>,std::vector<const Ring*> >: inner and outer Ring Seed for the Road" << std::endl;
237  stream << "# RoadSet : std::vector<std::vectro<const Ring*> >: all Rings belonging to a road structured in layers" << std::endl;
238  stream << "# RoadMap: std::multimap<RoadSeed,RoadSet>: main container for the Roads" << std::endl;
239  stream << "# " << std::endl;
240  stream << "# Ascii-Format:" << std::endl;
241  stream << "# " << std::endl;
242  stream << "# Road Information:" << std::endl;
243  stream << "# <number of roads>" << std::endl;
244  stream << "#" << std::endl;
245  stream << "# RoadMap for each road:" << std::endl;
246  stream << "#" << std::endl;
247  stream << "# ### RoadMap Entry ###" << std::endl;
248  stream << "# ### RoadSeed First Ring ###" << std::endl;
249  stream << "# <number of inner seed rings>" << std::endl;
250  stream << "# <index>" << std::endl;
251  stream << "# <index>" << std::endl;
252  stream << "# ..." << std::endl;
253  stream << "# ### RoadSeed Second Ring ###" << std::endl;
254  stream << "# <number of outer seed rings>" << std::endl;
255  stream << "# <index>" << std::endl;
256  stream << "# <index>" << std::endl;
257  stream << "# ..." << std::endl;
258  stream << "# ### RoadSet ###" << std::endl;
259  stream << "# <number of Layers in RoadSet>" << std::endl;
260  stream << "# ### Layer ###" << std::endl;
261  stream << "# <number of rings in layer>" << std::endl;
262  stream << "# <index>" << std::endl;
263  stream << "# <index>" << std::endl;
264  stream << "# ..." << std::endl;
265  stream << "# ### Layer ###" << std::endl;
266  stream << "# ..." << std::endl;
267  stream << "#" << std::endl;
268  stream << "#" << std::endl;
269 
270 }
271 
273  DetId OuterSeedRing,
274  double InnerSeedRingPhi,
275  double OuterSeedRingPhi,
276  double dphi_scalefactor) const {
277 
278  // loop over seed Ring pairs
279 
280  // determine ringtype for inner seed ring detid
281  Ring::type innerSeedRingType = getRingType(InnerSeedRing);
282  Ring::type outerSeedRingType = getRingType(OuterSeedRing);
283 
284  for ( const_iterator road = roadMap_.begin(); road != roadMap_.end(); ++road ) {
285  for ( std::vector<const Ring*>::const_iterator innerRing = road->first.first.begin();
286  innerRing != road->first.first.end();
287  ++innerRing ) {
288  if ( (*innerRing)->getType() == innerSeedRingType ) {
289  for ( std::vector<const Ring*>::const_iterator outerRing = road->first.second.begin();
290  outerRing != road->first.second.end();
291  ++outerRing ) {
292  if ( (*outerRing)->getType() == outerSeedRingType ) {
293  if ( (*innerRing)->containsDetId(InnerSeedRing,InnerSeedRingPhi,dphi_scalefactor) &&
294  (*outerRing)->containsDetId(OuterSeedRing,OuterSeedRingPhi,dphi_scalefactor) ) {
295  return &(road->first);
296  }
297  }
298  }
299  }
300  }
301  }
302 
303  edm::LogError("RoadSearch") << "RoadSeed could not be found for inner SeedRing type: " << innerSeedRingType << " DetId: " << InnerSeedRing.rawId()
304  << " at " << InnerSeedRingPhi
305  << " and outer SeedRing type : " << outerSeedRingType << " DetID: " << OuterSeedRing.rawId()
306  << " at " << OuterSeedRingPhi;
307  return 0;
308 }
309 
310 const Roads::RoadSeed* Roads::getRoadSeed(std::vector<DetId> seedRingDetIds,
311  std::vector<double> seedRingHitsPhi,
312  double dphi_scalefactor) const {
313  //
314  // loop over roads and return first road which contains all seedRingDetIds
315  //
316 
317  for ( const_iterator road = roadMap_.begin(); road != roadMap_.end(); ++road ) {
318  unsigned int found = 0;
319  for ( unsigned int detIdCounter = 0;
320  detIdCounter < seedRingDetIds.size();
321  ++detIdCounter ) {
322  DetId id = RoadSearchDetIdHelper::ReturnRPhiId(seedRingDetIds[detIdCounter]);
323  double phi = seedRingHitsPhi[detIdCounter];
325 
326  bool foundInInnerRing = false;
327  for ( std::vector<const Ring*>::const_iterator innerRing = road->first.first.begin();
328  innerRing != road->first.first.end();
329  ++innerRing ) {
330  if ( (*innerRing)->getType() == type ) {
331  if ( (*innerRing)->containsDetId(id,phi,dphi_scalefactor) ) {
332  ++found;
333  foundInInnerRing = true;
334  }
335  }
336  }
337 
338  if ( !foundInInnerRing ) {
339  for ( std::vector<const Ring*>::const_iterator outerRing = road->first.second.begin();
340  outerRing != road->first.second.end();
341  ++outerRing ) {
342  if ( (*outerRing)->getType() == type ) {
343  if ( (*outerRing)->containsDetId(id,phi,dphi_scalefactor) ) {
344  ++found;
345  }
346  }
347  }
348  }
349 
350  if ( found == seedRingDetIds.size() ) {
351  return &(road->first);
352  }
353  }
354  }
355 
356  std::ostringstream ost;
357 
358  ost << "RoadSeed could not be found for following hits:\n";
359  for ( unsigned int detIdCounter = 0;
360  detIdCounter < seedRingDetIds.size();
361  ++detIdCounter ) {
362  ost << "Hit DetId: " << seedRingDetIds[detIdCounter].rawId() << " phi: " << seedRingHitsPhi[detIdCounter] << "\n";
363  }
364 
365  edm::LogError("RoadSearch") << ost.str();
366 
367  return 0;
368 }
369 
370 const Roads::type Roads::getRoadType(const RoadSeed *const seed) const {
371  //
372  // check if one of the outer rings is in TOB, then mark as RPhi
373  // problematic for transition region
374  bool TOBRing = false;
375  for ( std::vector<const Ring*>::const_iterator ring = seed->second.begin();
376  ring != seed->second.end();
377  ++ring) {
378  if ( (*ring)->getType() == Ring::TOBRing) {
379  TOBRing = true;
380  }
381  }
382  if ( TOBRing ) {
383  return Roads::RPhi;
384  } else {
385  return Roads::ZPhi;
386  }
387 }
388 
389 
391 
393 
394  if ( (unsigned int)id.subdetId() == StripSubdetector::TIB ) {
395  type = Ring::TIBRing;
396  } else if ( (unsigned int)id.subdetId() == StripSubdetector::TOB ) {
397  type = Ring::TOBRing;
398  } else if ( (unsigned int)id.subdetId() == StripSubdetector::TID ) {
399  type = Ring::TIDRing;
400  } else if ( (unsigned int)id.subdetId() == StripSubdetector::TEC ) {
401  type = Ring::TECRing;
402  } else if ( (unsigned int)id.subdetId() == PixelSubdetector::PixelBarrel ) {
403  type = Ring::PXBRing;
404  } else if ( (unsigned int)id.subdetId() == PixelSubdetector::PixelEndcap ) {
405  type = Ring::PXFRing;
406  }
407 
408  return type;
409 
410 }
const Rings * rings_
Definition: Roads.h:96
const Ring * getRing(DetId id, double phi=999999., double z=999999.) const
Definition: Rings.cc:152
int i
Definition: DBlmapReader.cc:9
static DetId ReturnRPhiId(const DetId id)
void dumpHeader(std::ofstream &stream) const
Definition: Roads.cc:224
RoadMap roadMap_
Definition: Roads.h:97
void readInFromAsciiFile(std::string ascii_file)
Definition: Roads.cc:47
std::vector< std::vector< const Ring * > > RoadSet
Definition: Roads.h:39
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
Roads()
Definition: Roads.cc:33
int j
Definition: DBlmapReader.cc:9
Definition: Rings.h:27
std::pair< std::vector< const Ring * >, std::vector< const Ring * > > RoadSeed
Definition: Roads.h:38
Definition: DetId.h:20
RoadMap::const_iterator const_iterator
Definition: Roads.h:43
const Ring::type getRingType(DetId id) const
Definition: Roads.cc:390
type
Definition: Roads.h:45
const type getRoadType(const RoadSeed *const seed) const
Definition: Roads.cc:370
void dump(std::string ascii_filename="roads.dat") const
Definition: Roads.cc:173
type
Definition: Ring.h:41
const RoadSeed * getRoadSeed(DetId InnerSeedRing, DetId OuterSeedRing, double InnerSeedRingPhi=999999., double OuterSeedRingPhi=999999., double dphi_scalefactor=1.5) const
Definition: Roads.cc:272
~Roads()
Definition: Roads.cc:43
void set(const std::string &name, int value)
set the flag, with a run-time name
Definition: DDAxes.h:10