CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Ring.h
Go to the documentation of this file.
1 #ifndef RECOTRACKER_RING_H
2 #define RECOTRACKER_RING_H
3 
4 //
5 // Package: RecoTracker/RingRecord
6 // Class: Ring
7 //
8 // Description: A Ring represents all DetId's
9 // at a given radius and z
10 // summed over phi
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/03/07 21:46:48 $
17 // $Revision: 1.2 $
18 //
19 
20 #include <iostream>
21 #include <map>
22 #include <sstream>
23 #include <fstream>
24 #include <utility>
25 
27 
30 
31 class Ring {
32 
33  public:
34 
35  typedef std::multimap<double,DetId> DetIdMap;
36  typedef DetIdMap::iterator iterator;
37  typedef DetIdMap::const_iterator const_iterator;
38  typedef std::pair<iterator,iterator> IteratorRange;
39  typedef std::pair<const_iterator,const_iterator> ConstIteratorRange;
40 
41  enum type {
49  };
50 
52  rmin_(0.),
53  rmax_(0.),
54  zmin_(0.),
55  zmax_(0.),
57  index_(0) {}
58 
60  rmin_(0.),
61  rmax_(0.),
62  zmin_(0.),
63  zmax_(0.),
64  type_(input),
65  index_(0) {}
66 
67  Ring(unsigned int index,
68  float rmin,
69  float rmax,
70  float zmin,
71  float zmax,
72  unsigned int type) : initialized_(true),
73  rmin_(rmin),
74  rmax_(rmax),
75  zmin_(zmin),
76  zmax_(zmax),
77  index_(index) {
78  if ( type == 0 ) {
79  type_ = TIBRing;
80  } else if ( type == 1 ) {
81  type_ = TOBRing;
82  } else if ( type == 2 ) {
83  type_ = TIDRing;
84  } else if ( type == 3 ) {
85  type_ = TECRing;
86  } else if ( type == 4 ) {
87  type_ = PXBRing;
88  } else if ( type == 5 ) {
89  type_ = PXFRing;
90  } else {
92  }
93  }
94 
95  Ring(Ring* input) : detids_(input->getDetIdMap()),
96  initialized_(input->isInitialized()),
97  rmin_(input->getrmin()),
98  rmax_(input->getrmax()),
99  zmin_(input->getzmin()),
100  zmax_(input->getzmax()),
101  type_(input->getType()),
102  index_(input->getindex()) {}
103 
104  ~Ring() {}
105 
106  inline void addId(double phi, DetId id) { detids_.insert(std::make_pair(phi,id)); }
107 
108  inline int getNumDetIds() const { return detids_.size(); }
109 
110  inline bool containsDetId(DetId id, double phi = 999999.,
111  double dphi_scalefactor = 1.5) const {
112  // calculate window around given phi (if phi == 999999. set window to [-pi,pi])
113  // determine phi segmentation from number of detids in ring
114  // window is += 1.5 times the phi segmentation
115  double phi_inner = -Geom::pi();
116  double phi_outer = Geom::pi();
117  double delta_phi = Geom::twoPi() / detids_.size();
118  if ( phi != 999999. ) {
119  phi_inner = map_phi(phi - dphi_scalefactor*delta_phi);
120  phi_outer = map_phi(phi + dphi_scalefactor*delta_phi);
121  }
122 
123  // check for out of bounds of [0,2pi]
124  if ( phi_inner > phi_outer ) {
125  // double loop
126  for ( const_iterator ring = detids_.lower_bound(phi_inner); ring != detids_.end(); ++ring ) {
127  if ( id == ring->second ) {
128  return true;
129  }
130  }
131  for ( const_iterator ring = detids_.begin(); ring != detids_.upper_bound(phi_outer); ++ring ) {
132  if ( id == ring->second ) {
133  return true;
134  }
135  }
136  } else {
137  for ( const_iterator ring = detids_.lower_bound(phi_inner); ring != detids_.upper_bound(phi_outer); ++ring ) {
138  if ( id == ring->second ) {
139  return true;
140  }
141  }
142  }
143 
144  return false;
145  }
146 
147  inline const_iterator begin() const { return detids_.begin(); }
148  inline const_iterator end() const { return detids_.end(); }
149 
150  inline iterator begin() { return detids_.begin(); }
151  inline iterator end() { return detids_.end(); }
152 
153  inline bool isInitialized() const { return initialized_; }
154 
155  inline float getrmin() const { if ( !isInitialized() ) notInitializedMsg(); return rmin_; }
156  inline float getrmax() const { if ( !isInitialized() ) notInitializedMsg(); return rmax_; }
157  inline float getzmin() const { if ( !isInitialized() ) notInitializedMsg(); return zmin_; }
158  inline float getzmax() const { if ( !isInitialized() ) notInitializedMsg(); return zmax_; }
159 
160  inline void setrmin(float input) { rmin_ = input; }
161  inline void setrmax(float input) { rmax_ = input; }
162  inline void setzmin(float input) { zmin_ = input; }
163  inline void setzmax(float input) { zmax_ = input; }
164 
165  inline void setInitialized(bool input) { initialized_ = input; }
166 
167  inline void initialize(float rmin, float rmax, float zmin, float zmax) {
168  rmin_ = rmin;
169  rmax_ = rmax;
170  zmin_ = zmin;
171  zmax_ = zmax;
172  initialized_ = true; }
173 
174  inline void notInitializedMsg() const {
175  edm::LogWarning("RoadSearch") << "Ring " << index_ << " does not have initialized values for r_min, r_max, z_min, z_max! Using default value of 0. !"; }
176 
177  inline void setType(type input) { type_ = input; }
178 
179  inline type getType() const { return type_; }
180 
181  inline DetId getFirst() const { return detids_.begin()->second; }
182 
183  inline void setindex(unsigned int input) { index_ = input; }
184 
185  inline unsigned int getindex() const { return index_; }
186 
187  inline DetIdMap getDetIdMap() const { return detids_; }
188 
190  int operator==(const Ring& ring) const { return index_==ring.getindex(); }
192  int operator!=(const Ring& ring) const { return index_!=ring.getindex(); }
194  int operator<(const Ring& ring) const { return index_<ring.getindex(); }
195 
196  inline std::string print() const {
197  std::ostringstream stream;
198  stream << "Ring: " << index_
199  << " rmin: " << rmin_
200  << " rmax: " << rmax_
201  << " zmin: " << zmin_
202  << " zmax: " << zmax_
203  << " number of DetUnits: " << detids_.size();
204  return stream.str();
205  }
206 
207  inline std::string dump() const {
208  std::ostringstream stream;
209  stream << "### Ring with index: " << index_ << " ###" << std::endl;
210  stream << index_
211  << " " << rmin_
212  << " " << rmax_
213  << " " << zmin_
214  << " " << zmax_
215  << " " << type_ << std::endl;
216  stream << detids_.size() << std::endl;
217  for ( const_iterator entry = detids_.begin(); entry != detids_.end(); ++entry ) {
218  stream << entry->first << " " << entry->second.rawId() << std::endl;
219  }
220  return stream.str();
221  }
222 
223  inline const_iterator lower_bound(double phi) const { return detids_.lower_bound(phi); }
224  inline const_iterator upper_bound(double phi) const { return detids_.upper_bound(phi); }
225 
226  inline double map_phi(double phi) const {
227  // map phi to [-pi,pi]
228  double result = phi;
229  if ( result < -Geom::pi()) result += Geom::twoPi();
230  if ( result > Geom::pi()) result -= Geom::twoPi();
231  return result;
232  }
233 
234  private:
235 
237 
239 
240  float rmin_;
241  float rmax_;
242  float zmin_;
243  float zmax_;
244 
246 
247  unsigned int index_;
248 
249 };
250 
251 #endif
Ring()
Definition: Ring.h:51
std::pair< const_iterator, const_iterator > ConstIteratorRange
Definition: Ring.h:39
iterator end()
Definition: Ring.h:151
type type_
Definition: Ring.h:245
float zmin_
Definition: Ring.h:242
DetId getFirst() const
Definition: Ring.h:181
unsigned int getindex() const
Definition: Ring.h:185
const_iterator upper_bound(double phi) const
Definition: Ring.h:224
bool isInitialized() const
Definition: Ring.h:153
std::pair< iterator, iterator > IteratorRange
Definition: Ring.h:38
bool containsDetId(DetId id, double phi=999999., double dphi_scalefactor=1.5) const
Definition: Ring.h:110
Ring(type input)
Definition: Ring.h:59
void setzmax(float input)
Definition: Ring.h:163
void setType(type input)
Definition: Ring.h:177
type getType() const
Definition: Ring.h:179
Ring(Ring *input)
Definition: Ring.h:95
int operator!=(const Ring &ring) const
inequality
Definition: Ring.h:192
DetIdMap getDetIdMap() const
Definition: Ring.h:187
void setindex(unsigned int input)
Definition: Ring.h:183
unsigned int index_
Definition: Ring.h:247
void setrmin(float input)
Definition: Ring.h:160
Ring(unsigned int index, float rmin, float rmax, float zmin, float zmax, unsigned int type)
Definition: Ring.h:67
const_iterator lower_bound(double phi) const
Definition: Ring.h:223
float getzmax() const
Definition: Ring.h:158
const_iterator begin() const
Definition: Ring.h:147
int operator==(const Ring &ring) const
equality
Definition: Ring.h:190
std::string dump() const
Definition: Ring.h:207
Definition: Ring.h:31
std::string print() const
Definition: Ring.h:196
std::pair< std::string, MonitorElement * > entry
Definition: ME_MAP.h:8
tuple result
Definition: query.py:137
void setrmax(float input)
Definition: Ring.h:161
float getrmin() const
Definition: Ring.h:155
void notInitializedMsg() const
Definition: Ring.h:174
void setzmin(float input)
Definition: Ring.h:162
DetIdMap detids_
Definition: Ring.h:236
float rmin_
Definition: Ring.h:240
double delta_phi(double ph11, double phi2)
Definition: AnglesUtil.h:91
~Ring()
Definition: Ring.h:104
int operator<(const Ring &ring) const
comparison
Definition: Ring.h:194
float getzmin() const
Definition: Ring.h:157
Definition: DetId.h:20
float zmax_
Definition: Ring.h:243
void initialize(float rmin, float rmax, float zmin, float zmax)
Definition: Ring.h:167
std::multimap< double, DetId > DetIdMap
Definition: Ring.h:35
int getNumDetIds() const
Definition: Ring.h:108
const_iterator end() const
Definition: Ring.h:148
double map_phi(double phi) const
Definition: Ring.h:226
double pi()
Definition: Pi.h:31
double twoPi()
Definition: Pi.h:32
float getrmax() const
Definition: Ring.h:156
DetIdMap::const_iterator const_iterator
Definition: Ring.h:37
float rmax_
Definition: Ring.h:241
DetIdMap::iterator iterator
Definition: Ring.h:36
type
Definition: Ring.h:41
iterator begin()
Definition: Ring.h:150
void setInitialized(bool input)
Definition: Ring.h:165
void addId(double phi, DetId id)
Definition: Ring.h:106
bool initialized_
Definition: Ring.h:238
Definition: DDAxes.h:10