CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Rings.cc
Go to the documentation of this file.
1 //
2 // Package: RecoTracker/RingRecord
3 // Class: Rings
4 //
5 // Description: The Rings object holds all Rings of
6 // the tracker mapped in z of their centers
7 //
8 // Original Author: Oliver Gutsche, gutsche@fnal.gov
9 // Created: Tue Oct 3 22:14:25 UTC 2006
10 //
11 // $Author: gutsche $
12 // $Date: 2007/03/30 02:49:37 $
13 // $Revision: 1.2 $
14 //
15 
16 #include <iostream>
17 #include <sstream>
18 #include <stdexcept>
19 
21 
23 
27 
34 
35 
37  //
38  // default constructor
39  //
40 }
41 
42 Rings::Rings(std::string ascii_filename) {
43  //
44  // constructor reading in ascii file
45  //
46 
47  readInFromAsciiFile(ascii_filename);
48 
49 }
50 
52  //
53  // default destructor
54  //
55 }
56 
57 void Rings::readInFromAsciiFile(std::string ascii_filename) {
58  //
59  // read in all rings stored in ascii file
60  //
61 
62  std::ifstream input(ascii_filename.c_str());
63  std::istringstream stream;
64  std::string line;
65  unsigned int index, type;
66  float rmin,rmax,zmin,zmax;
67  unsigned int ndetid = 0;
68  double phi;
69  unsigned int detid;
70 
71  while ( std::getline(input,line) ) {
72  if ( !std::isspace(line[0]) && !(line[0] == 35) ) {
73 
74  // ring
75  stream.str(line);
76  stream.clear();
77  stream >> index >> rmin >> rmax >> zmin >> zmax >> type;
78  Ring ring(index,rmin,rmax,zmin,zmax,type);
79  std::getline(input,line);
80  while (std::isspace(line[0]) || (line[0] == 35) ) {
81  std::getline(input,line);
82  }
83  stream.str(line);
84  stream.clear();
85  stream >> ndetid;
86  for (unsigned int i = 0; i < ndetid; ++i ) {
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 >> phi >> detid;
94  ring.addId(phi,DetId(detid));
95  }
96  double center_z = zmin + ((zmax-zmin)/2);
97  ringMap_.insert(std::make_pair(center_z,ring));
98  }
99  }
100 
101  edm::LogInfo("RoadSearch") << "Read in: " << ringMap_.size() << " Rings from file: " << ascii_filename;
102 
103 }
104 
105 void Rings::dump(std::string ascii_filename) const {
106  //
107  // dump all rings in ascii file
108  //
109 
110  std::ofstream stream(ascii_filename.c_str());
111 
112  dumpHeader(stream);
113 
114  for ( const_iterator ring = ringMap_.begin(); ring != ringMap_.end(); ++ring ) {
115 
116  stream << ring->second.dump();
117 
118  }
119 
120 }
121 
122 void Rings::dumpHeader(std::ofstream &stream) const {
123  //
124  // header with general information about content of rings ascii file
125  //
126 
127  stream << "#" << std::endl;
128  stream << "# Rings for the RoadSearch tracking algorithm" << std::endl;
129  stream << "# Ascii Dump" << std::endl;
130  stream << "# " << std::endl;
131  stream << "# Content:" << std::endl;
132  stream << "# " << std::endl;
133  stream << "# a dump of all Rings:" << std::endl;
134  stream << "#" << std::endl;
135  stream << "# Ring : index, rmin, rmax, zmin, zmax, std::multimap<phi,DetId>: Ring of DetUnits mapped in phi" << std::endl;
136  stream << "# " << std::endl;
137  stream << "# Ascii-Format:" << std::endl;
138  stream << "# " << std::endl;
139  stream << "# Ring:" << std::endl;
140  stream << "#" << std::endl;
141  stream << "# ### Ring: <index> ###" << std::endl;
142  stream << "# <index> <rmin> <rmax> <zmin> <zmax>" << std::endl;
143  stream << "# <number of DetId's in std::vector<DetId> >" << std::endl;
144  stream << "# <phi of DetUnit described by DetId> <DetId::rawId()>" << std::endl;
145  stream << "# <phi of DetUnit described by DetId> <DetId::rawId()>" << std::endl;
146  stream << "# ..." << std::endl;
147  stream << "#" << std::endl;
148  stream << "#" << std::endl;
149 
150 }
151 
152 const Ring* Rings::getRing(DetId id, double phi,double z) const {
153  //
154  // loop over rings to discover ring which contains DetId id
155  // loop is restricted to window in z
156 
157  // calculate window around given z (if z == 999999. set window to maximum)
158  // window is += 1.5 times the longest sensor in z (TOB: ~20 cm)
159  double z_min = -999999.;
160  double z_max = 999999.;
161  double delta_z = 1.5 * 20.;
162  if ( z != 999999. ) {
163  z_min = z - delta_z;
164  z_max = z + delta_z;
165  }
166 
167  // loop over rings
168  for ( const_iterator ring = ringMap_.lower_bound(z_min); ring != ringMap_.upper_bound(z_max); ++ring ) {
169  if ( ring->second.containsDetId(id,phi) ) {
170  return &(ring->second);
171  }
172  }
173 
174  return 0;
175 }
176 
177 const Ring* Rings::getRing(unsigned int ringIndex, double z) const {
178  //
179  // loop over rings to discover ring which has RingIndex ringIndex
180  // loop is restricted to window in z
181 
182  // calculate window around given z (if z == 999999. set window to maximum)
183  // window is += 1.5 times the longest sensor in z (TOB: ~20 cm)
184  double z_min = -999999.;
185  double z_max = 999999.;
186  double delta_z = 1.5 * 20.;
187  if ( z != 999999. ) {
188  z_min = z - delta_z;
189  z_max = z + delta_z;
190  }
191 
192  for ( const_iterator ring = ringMap_.lower_bound(z_min); ring != ringMap_.upper_bound(z_max); ++ring ) {
193  if ( ring->second.getindex() == ringIndex ) {
194  return &(ring->second);
195  }
196  }
197 
198  return 0;
199 }
200 
201 const Ring* Rings::getTIBRing(unsigned int layer,
202  unsigned int fw_bw,
203  unsigned int ext_int,
204  unsigned int detector) const {
205 
206  // construct DetID from info using else the first of all entities and return Ring
207 
208  const Ring* ring = 0;
209 
210  // first try stereo = 0, then stereo = 2, then fail
211  TIBDetId id(layer,fw_bw,ext_int,1,detector,0);
212  ring = getRing(DetId(id.rawId()));
213  if ( ring == 0 ) {
214  TIBDetId id(layer,fw_bw,ext_int,1,detector,2);
215  ring = getRing(DetId(id.rawId()));
216  }
217 
218  if ( ring == 0 ) {
219  edm::LogError("RoadSearch") << "TIB Ring for layer: " << layer
220  << " fw_bw: " << fw_bw
221  << " ext_int: " << ext_int
222  << " detector: " << detector
223  << " with rawId: " << id.rawId()
224  << " could not be found.";
225  }
226 
227  return ring;
228 }
229 
230 const Ring* Rings::getTIDRing(unsigned int fw_bw,
231  unsigned int wheel,
232  unsigned int ring) const {
233 
234  // construct DetID from info using else the first of all entities and return Ring
235 
236  const Ring* int_ring = 0;
237 
238  // first try stereo = 0, then stereo = 2, then fail
239  TIDDetId id(fw_bw,wheel,ring,1,1,0);
240  int_ring = getRing(DetId(id.rawId()));
241  if ( int_ring == 0 ) {
242  TIDDetId id(fw_bw,wheel,ring,1,1,2);
243  int_ring = getRing(DetId(id.rawId()));
244  }
245 
246  if ( int_ring == 0 ) {
247  edm::LogError("RoadSearch") << "TID Ring for fw_bw: " << fw_bw
248  << " wheel: " << wheel
249  << " ring: " << ring
250  << " with rawId: " << id.rawId()
251  << " could not be found.";
252  }
253 
254  return int_ring;
255 }
256 
257 const Ring* Rings::getTECRing(unsigned int fw_bw,
258  unsigned int wheel,
259  unsigned int ring) const {
260 
261  // try to construct first detid from fw_bw, wheel, ring
262  // set petal and module to 1 (zero in c-array terms)
263  // check for combination if petal_fw_bw is valid, otherwise set to 0 is valid
264  // if not, increase them to get a valid id
265 
266  int petal_fw_bw = 1;
267  int petal = 1;
268  int module = 1;
269 
270  const Ring* int_ring = 0;
271 
272  // first try stereo = 0, then stereo = 2, then fail
273  TECDetId id(fw_bw,wheel,petal_fw_bw,petal,ring,module,0);
274  int_ring = getRing(DetId(id.rawId()));
275  if ( int_ring == 0 ) {
276  TECDetId id(fw_bw,wheel,petal_fw_bw,petal,ring,module,2);
277  int_ring = getRing(DetId(id.rawId()));
278  }
279 
280  if ( int_ring == 0 ) {
281  edm::LogError("RoadSearch") << "TEC Ring for fw_bw: " << fw_bw
282  << " wheel: " << wheel
283  << " ring: " << ring
284  << " with rawId: " << id.rawId()
285  << " could not be found.";
286  }
287 
288  return int_ring;
289 }
290 
291 const Ring* Rings::getTOBRing(unsigned int layer,
292  unsigned int rod_fw_bw,
293  unsigned int detector) const {
294 
295  // construct DetID from info using else the first of all entities and return Ring
296  const Ring* ring = 0;
297 
298  // first try stereo = 0, then stereo = 2, then fail
299  TOBDetId id(layer,rod_fw_bw,1,detector,0);
300  ring = getRing(DetId(id.rawId()));
301  if ( ring == 0 ) {
302  TOBDetId id(layer,rod_fw_bw,1,detector,2);
303  ring = getRing(DetId(id.rawId()));
304  }
305 
306  if ( ring == 0 ) {
307  edm::LogError("RoadSearch") << "TOB Ring for layer: " << layer
308  << " rod_fw_bw: " << rod_fw_bw
309  << " detector: " << detector
310  << " with rawId: " << id.rawId()
311  << " could not be found.";
312  }
313 
314  return ring;
315 }
316 
317 const Ring* Rings::getPXBRing(unsigned int layer,
318  unsigned int detector) const {
319 
320  // construct DetID from info using else the first of all entities and return Ring
321  unsigned int ladder = 0;
322 
323  PXBDetId id(layer,ladder,detector);
324 
325  return getRing(DetId(id.rawId()));
326 }
327 
328 
329 const Ring* Rings::getPXFRing(unsigned int fw_bw,
330  unsigned int disk,
331  unsigned int panel,
332  unsigned int module) const {
333 
334  // construct DetID from info using else the first of all entities and return Ring
335  unsigned int detector = 0;
336 
337  PXFDetId id(fw_bw+1,disk+1,detector+1,panel+1,module+1);
338 
339  return getRing(DetId(id.rawId()));
340 }
341 
const Ring * getTOBRing(unsigned int layer, unsigned int rod_fw_bw, unsigned int detector) const
Definition: Rings.cc:291
const Ring * getRing(DetId id, double phi=999999., double z=999999.) const
Definition: Rings.cc:152
type
Definition: HCALResponse.h:22
int i
Definition: DBlmapReader.cc:9
RingMap::const_iterator const_iterator
Definition: Rings.h:33
void dump(std::string ascii_filename="rings.dat") const
Definition: Rings.cc:105
void dumpHeader(std::ofstream &stream) const
Definition: Rings.cc:122
Rings()
Definition: Rings.cc:36
const Ring * getPXFRing(unsigned int fw_bw, unsigned int disk, unsigned int panel, unsigned int module) const
Definition: Rings.cc:329
double double double z
const Ring * getTIDRing(unsigned int fw_bw, unsigned int wheel, unsigned int ring) const
Definition: Rings.cc:230
const Ring * getTIBRing(unsigned int layer, unsigned int fw_bw, unsigned int ext_int, unsigned int detector) const
Definition: Rings.cc:201
RingMap ringMap_
Definition: Rings.h:80
Definition: Ring.h:31
Definition: DetId.h:20
const Ring * getPXBRing(unsigned int layer, unsigned int detector) const
Definition: Rings.cc:317
void readInFromAsciiFile(std::string ascii_file)
Definition: Rings.cc:57
~Rings()
Definition: Rings.cc:51
Definition: vlib.h:209
const Ring * getTECRing(unsigned int fw_bw, unsigned int wheel, unsigned int ring) const
Definition: Rings.cc:257
void addId(double phi, DetId id)
Definition: Ring.h:106
Definition: DDAxes.h:10