00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include <iostream>
00017 #include <sstream>
00018 #include <stdexcept>
00019
00020 #include "RecoTracker/RingRecord/interface/Rings.h"
00021
00022 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00023
00024 #include "DataFormats/DetId/interface/DetId.h"
00025 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
00026 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
00027
00028 #include "DataFormats/SiStripDetId/interface/TIBDetId.h"
00029 #include "DataFormats/SiStripDetId/interface/TOBDetId.h"
00030 #include "DataFormats/SiStripDetId/interface/TIDDetId.h"
00031 #include "DataFormats/SiStripDetId/interface/TECDetId.h"
00032 #include "DataFormats/SiPixelDetId/interface/PXBDetId.h"
00033 #include "DataFormats/SiPixelDetId/interface/PXFDetId.h"
00034
00035
00036 Rings::Rings() {
00037
00038
00039
00040 }
00041
00042 Rings::Rings(std::string ascii_filename) {
00043
00044
00045
00046
00047 readInFromAsciiFile(ascii_filename);
00048
00049 }
00050
00051 Rings::~Rings() {
00052
00053
00054
00055 }
00056
00057 void Rings::readInFromAsciiFile(std::string ascii_filename) {
00058
00059
00060
00061
00062 std::ifstream input(ascii_filename.c_str());
00063 std::istringstream stream;
00064 std::string line;
00065 unsigned int index, type;
00066 float rmin,rmax,zmin,zmax;
00067 unsigned int ndetid = 0;
00068 double phi;
00069 unsigned int detid;
00070
00071 while ( std::getline(input,line) ) {
00072 if ( !std::isspace(line[0]) && !(line[0] == 35) ) {
00073
00074
00075 stream.str(line);
00076 stream.clear();
00077 stream >> index >> rmin >> rmax >> zmin >> zmax >> type;
00078 Ring ring(index,rmin,rmax,zmin,zmax,type);
00079 std::getline(input,line);
00080 while (std::isspace(line[0]) || (line[0] == 35) ) {
00081 std::getline(input,line);
00082 }
00083 stream.str(line);
00084 stream.clear();
00085 stream >> ndetid;
00086 for (unsigned int i = 0; i < ndetid; ++i ) {
00087 std::getline(input,line);
00088 while (std::isspace(line[0]) || (line[0] == 35) ) {
00089 std::getline(input,line);
00090 }
00091 stream.str(line);
00092 stream.clear();
00093 stream >> phi >> detid;
00094 ring.addId(phi,DetId(detid));
00095 }
00096 double center_z = zmin + ((zmax-zmin)/2);
00097 ringMap_.insert(std::make_pair(center_z,ring));
00098 }
00099 }
00100
00101 edm::LogInfo("RoadSearch") << "Read in: " << ringMap_.size() << " Rings from file: " << ascii_filename;
00102
00103 }
00104
00105 void Rings::dump(std::string ascii_filename) const {
00106
00107
00108
00109
00110 std::ofstream stream(ascii_filename.c_str());
00111
00112 dumpHeader(stream);
00113
00114 for ( const_iterator ring = ringMap_.begin(); ring != ringMap_.end(); ++ring ) {
00115
00116 stream << ring->second.dump();
00117
00118 }
00119
00120 }
00121
00122 void Rings::dumpHeader(std::ofstream &stream) const {
00123
00124
00125
00126
00127 stream << "#" << std::endl;
00128 stream << "# Rings for the RoadSearch tracking algorithm" << std::endl;
00129 stream << "# Ascii Dump" << std::endl;
00130 stream << "# " << std::endl;
00131 stream << "# Content:" << std::endl;
00132 stream << "# " << std::endl;
00133 stream << "# a dump of all Rings:" << std::endl;
00134 stream << "#" << std::endl;
00135 stream << "# Ring : index, rmin, rmax, zmin, zmax, std::multimap<phi,DetId>: Ring of DetUnits mapped in phi" << std::endl;
00136 stream << "# " << std::endl;
00137 stream << "# Ascii-Format:" << std::endl;
00138 stream << "# " << std::endl;
00139 stream << "# Ring:" << std::endl;
00140 stream << "#" << std::endl;
00141 stream << "# ### Ring: <index> ###" << std::endl;
00142 stream << "# <index> <rmin> <rmax> <zmin> <zmax>" << std::endl;
00143 stream << "# <number of DetId's in std::vector<DetId> >" << std::endl;
00144 stream << "# <phi of DetUnit described by DetId> <DetId::rawId()>" << std::endl;
00145 stream << "# <phi of DetUnit described by DetId> <DetId::rawId()>" << std::endl;
00146 stream << "# ..." << std::endl;
00147 stream << "#" << std::endl;
00148 stream << "#" << std::endl;
00149
00150 }
00151
00152 const Ring* Rings::getRing(DetId id, double phi,double z) const {
00153
00154
00155
00156
00157
00158
00159 double z_min = -999999.;
00160 double z_max = 999999.;
00161 double delta_z = 1.5 * 20.;
00162 if ( z != 999999. ) {
00163 z_min = z - delta_z;
00164 z_max = z + delta_z;
00165 }
00166
00167
00168 for ( const_iterator ring = ringMap_.lower_bound(z_min); ring != ringMap_.upper_bound(z_max); ++ring ) {
00169 if ( ring->second.containsDetId(id,phi) ) {
00170 return &(ring->second);
00171 }
00172 }
00173
00174 return 0;
00175 }
00176
00177 const Ring* Rings::getRing(unsigned int ringIndex, double z) const {
00178
00179
00180
00181
00182
00183
00184 double z_min = -999999.;
00185 double z_max = 999999.;
00186 double delta_z = 1.5 * 20.;
00187 if ( z != 999999. ) {
00188 z_min = z - delta_z;
00189 z_max = z + delta_z;
00190 }
00191
00192 for ( const_iterator ring = ringMap_.lower_bound(z_min); ring != ringMap_.upper_bound(z_max); ++ring ) {
00193 if ( ring->second.getindex() == ringIndex ) {
00194 return &(ring->second);
00195 }
00196 }
00197
00198 return 0;
00199 }
00200
00201 const Ring* Rings::getTIBRing(unsigned int layer,
00202 unsigned int fw_bw,
00203 unsigned int ext_int,
00204 unsigned int detector) const {
00205
00206
00207
00208 const Ring* ring = 0;
00209
00210
00211 TIBDetId id(layer,fw_bw,ext_int,1,detector,0);
00212 ring = getRing(DetId(id.rawId()));
00213 if ( ring == 0 ) {
00214 TIBDetId id(layer,fw_bw,ext_int,1,detector,2);
00215 ring = getRing(DetId(id.rawId()));
00216 }
00217
00218 if ( ring == 0 ) {
00219 edm::LogError("RoadSearch") << "TIB Ring for layer: " << layer
00220 << " fw_bw: " << fw_bw
00221 << " ext_int: " << ext_int
00222 << " detector: " << detector
00223 << " with rawId: " << id.rawId()
00224 << " could not be found.";
00225 }
00226
00227 return ring;
00228 }
00229
00230 const Ring* Rings::getTIDRing(unsigned int fw_bw,
00231 unsigned int wheel,
00232 unsigned int ring) const {
00233
00234
00235
00236 const Ring* int_ring = 0;
00237
00238
00239 TIDDetId id(fw_bw,wheel,ring,1,1,0);
00240 int_ring = getRing(DetId(id.rawId()));
00241 if ( int_ring == 0 ) {
00242 TIDDetId id(fw_bw,wheel,ring,1,1,2);
00243 int_ring = getRing(DetId(id.rawId()));
00244 }
00245
00246 if ( int_ring == 0 ) {
00247 edm::LogError("RoadSearch") << "TID Ring for fw_bw: " << fw_bw
00248 << " wheel: " << wheel
00249 << " ring: " << ring
00250 << " with rawId: " << id.rawId()
00251 << " could not be found.";
00252 }
00253
00254 return int_ring;
00255 }
00256
00257 const Ring* Rings::getTECRing(unsigned int fw_bw,
00258 unsigned int wheel,
00259 unsigned int ring) const {
00260
00261
00262
00263
00264
00265
00266 int petal_fw_bw = 1;
00267 int petal = 1;
00268 int module = 1;
00269
00270 const Ring* int_ring = 0;
00271
00272
00273 TECDetId id(fw_bw,wheel,petal_fw_bw,petal,ring,module,0);
00274 int_ring = getRing(DetId(id.rawId()));
00275 if ( int_ring == 0 ) {
00276 TECDetId id(fw_bw,wheel,petal_fw_bw,petal,ring,module,2);
00277 int_ring = getRing(DetId(id.rawId()));
00278 }
00279
00280 if ( int_ring == 0 ) {
00281 edm::LogError("RoadSearch") << "TEC Ring for fw_bw: " << fw_bw
00282 << " wheel: " << wheel
00283 << " ring: " << ring
00284 << " with rawId: " << id.rawId()
00285 << " could not be found.";
00286 }
00287
00288 return int_ring;
00289 }
00290
00291 const Ring* Rings::getTOBRing(unsigned int layer,
00292 unsigned int rod_fw_bw,
00293 unsigned int detector) const {
00294
00295
00296 const Ring* ring = 0;
00297
00298
00299 TOBDetId id(layer,rod_fw_bw,1,detector,0);
00300 ring = getRing(DetId(id.rawId()));
00301 if ( ring == 0 ) {
00302 TOBDetId id(layer,rod_fw_bw,1,detector,2);
00303 ring = getRing(DetId(id.rawId()));
00304 }
00305
00306 if ( ring == 0 ) {
00307 edm::LogError("RoadSearch") << "TOB Ring for layer: " << layer
00308 << " rod_fw_bw: " << rod_fw_bw
00309 << " detector: " << detector
00310 << " with rawId: " << id.rawId()
00311 << " could not be found.";
00312 }
00313
00314 return ring;
00315 }
00316
00317 const Ring* Rings::getPXBRing(unsigned int layer,
00318 unsigned int detector) const {
00319
00320
00321 unsigned int ladder = 0;
00322
00323 PXBDetId id(layer,ladder,detector);
00324
00325 return getRing(DetId(id.rawId()));
00326 }
00327
00328
00329 const Ring* Rings::getPXFRing(unsigned int fw_bw,
00330 unsigned int disk,
00331 unsigned int panel,
00332 unsigned int module) const {
00333
00334
00335 unsigned int detector = 0;
00336
00337 PXFDetId id(fw_bw+1,disk+1,detector+1,panel+1,module+1);
00338
00339 return getRing(DetId(id.rawId()));
00340 }
00341