CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/TrackingTools/RoadSearchHitAccess/src/RoadSearchDetIdHelper.cc

Go to the documentation of this file.
00001 //
00002 // Package:         TrackingTools/RoadSearchDetIdHelper
00003 // Class:           RoadSearchDetIdHelper
00004 // 
00005 // Description:     helper functions concerning DetIds
00006 //
00007 // Original Author: Oliver Gutsche, gutsche@fnal.gov
00008 // Created:         Sun Jan 28 19:06:20 UTC 2007
00009 //
00010 // $Author: gutsche $
00011 // $Date: 2007/02/16 00:48:21 $
00012 // $Revision: 1.2 $
00013 //
00014 
00015 #include "TrackingTools/RoadSearchHitAccess/interface/RoadSearchDetIdHelper.h"
00016 
00017 #include <sstream>
00018 
00019 RoadSearchDetIdHelper::RoadSearchDetIdHelper() {
00020 }
00021 
00022 RoadSearchDetIdHelper::~RoadSearchDetIdHelper() {
00023 }
00024 
00025 std::string RoadSearchDetIdHelper::Print(const DetId id) {
00026   //
00027   // print DetId composition according to the type
00028   //
00029 
00030   std::ostringstream output;
00031 
00032   if ( (unsigned int)id.subdetId() == StripSubdetector::TIB ) {
00033     TIBDetId tibid(id.rawId()); 
00034     output << "TIB ring Detid: " << id.rawId() 
00035            << " layer: " << tibid.layer() 
00036            << " fw(0)/bw(1): " << tibid.string()[0]
00037            << " int(0)/ext(1): " << tibid.string()[1] 
00038            << " string: " << tibid.string()[2] 
00039            << " module: " << tibid.module();
00040     if ( IsMatched(tibid) ) {
00041       output << " corresponding to matched detunit of glued sensor";
00042     } else if ( IsGluedRPhi(tibid) ) {
00043       output << " corresponding to rphi detunit of glued sensor";
00044     } else if ( IsStereo(tibid) ) {
00045       output << " corresponding to stereo detunit of glued sensor";
00046     } else if ( IsSingleRPhi(tibid) ) {
00047       output << " corresponding to rphi detunit of single sensor";
00048     }
00049     output << std::endl; 
00050   } else if ( (unsigned int)id.subdetId() == StripSubdetector::TOB ) {
00051     TOBDetId tobid(id.rawId()); 
00052     output << "TOB ring Detid: " << id.rawId() 
00053            << " layer: " << tobid.layer() 
00054            << " fw(0)/bw(1): " << tobid.rod()[0]
00055            << " rod: " << tobid.rod()[1] 
00056            << " detector: " << tobid.module();
00057     if ( IsMatched(tobid) ) {
00058       output << " corresponding to matched detunit of glued sensor";
00059     } else if ( IsGluedRPhi(tobid) ) {
00060       output << " corresponding to rphi detunit of glued sensor";
00061     } else if ( IsStereo(tobid) ) {
00062       output << " corresponding to stereo detunit of glued sensor";
00063     } else if ( IsSingleRPhi(tobid) ) {
00064       output << " corresponding to rphi detunit of single sensor";
00065     }
00066     output << std::endl; 
00067   } else if ( (unsigned int)id.subdetId() == StripSubdetector::TID ) {
00068     TIDDetId tidid(id.rawId()); 
00069     output << "TID ring Detid: " << id.rawId() 
00070            << " side neg(1)/pos(2): " << tidid.side() 
00071            << " wheel: " << tidid.wheel()
00072            << " ring: " << tidid.ring()
00073            << " detector fw(0)/bw(1): " << tidid.module()[0]
00074            << " detector: " << tidid.module()[1];
00075     if ( IsMatched(tidid) ) {
00076       output << " corresponding to matched detunit of glued sensor";
00077     } else if ( IsGluedRPhi(tidid) ) {
00078       output << " corresponding to rphi detunit of glued sensor";
00079     } else if ( IsStereo(tidid) ) {
00080       output << " corresponding to stereo detunit of glued sensor";
00081     } else if ( IsSingleRPhi(tidid) ) {
00082       output << " corresponding to rphi detunit of single sensor";
00083     }
00084     output << std::endl; 
00085   } else if ( (unsigned int)id.subdetId() == StripSubdetector::TEC ) {
00086     TECDetId tecid(id.rawId()); 
00087     output << "TEC ring DetId: " << id.rawId() 
00088            << " side neg(1)/pos(2): " << tecid.side() 
00089            << " wheel: " << tecid.wheel()
00090            << " petal fw(0)/bw(1): " << tecid.petal()[0]
00091            << " petal: " << tecid.petal()[1] 
00092            << " ring: " << tecid.ring()
00093            << " module: " << tecid.module();
00094     if ( IsMatched(tecid) ) {
00095       output << " corresponding to matched detunit of glued sensor";
00096     } else if ( IsGluedRPhi(tecid) ) {
00097       output << " corresponding to rphi detunit of glued sensor";
00098     } else if ( IsStereo(tecid) ) {
00099       output << " corresponding to stereo detunit of glued sensor";
00100     } else if ( IsSingleRPhi(tecid) ) {
00101       output << " corresponding to rphi detunit of single sensor";
00102     }
00103     output << std::endl; 
00104   } else if ( (unsigned int)id.subdetId() == PixelSubdetector::PixelBarrel ) {
00105     PXBDetId pxbid(id.rawId()); 
00106     output << "PXB ring DetId: " << id.rawId() 
00107            << " layer: " << pxbid.layer()
00108            << " ladder: " << pxbid.ladder()
00109            << " detector: " << pxbid.module()
00110            << std::endl; 
00111   } else if ( (unsigned int)id.subdetId() == PixelSubdetector::PixelEndcap ) {
00112     PXFDetId pxfid(id.rawId()); 
00113     output << "PXF ring DetId: " << id.rawId() 
00114            << " side: " << pxfid.side()
00115            << " disk: " << pxfid.disk()
00116            << " blade: " << pxfid.blade()
00117            << " detector: " << pxfid.module()
00118            << std::endl; 
00119   }
00120 
00121 
00122   return output.str();
00123 }
00124 
00125 bool RoadSearchDetIdHelper::IsMatched(const DetId id) {
00126 
00127   // return value
00128   bool result = false;
00129 
00130   if ( (unsigned int)id.subdetId() == StripSubdetector::TIB ) {
00131     TIBDetId tibid(id.rawId()); 
00132     if ( !tibid.glued() ) {
00133       if ( tibid.layer() == 1 ||
00134            tibid.layer() == 2 ) {
00135         result = true;
00136       }
00137     }
00138   } else if ( (unsigned int)id.subdetId() == StripSubdetector::TOB ) {
00139     TOBDetId tobid(id.rawId()); 
00140     if ( !tobid.glued() ) {
00141       if ( tobid.layer() == 1 ||
00142            tobid.layer() == 2 ) {
00143         result = true;
00144       }
00145     }
00146   } else if ( (unsigned int)id.subdetId() == StripSubdetector::TID ) {
00147     TIDDetId tidid(id.rawId()); 
00148     if ( !tidid.glued() ) {
00149       if ( tidid.ring() == 1 ||
00150            tidid.ring() == 2 ) {
00151         result = true;
00152       }
00153     }
00154   } else if ( (unsigned int)id.subdetId() == StripSubdetector::TEC ) {
00155     TECDetId tecid(id.rawId()); 
00156     if ( !tecid.glued() ) {
00157       if ( tecid.ring() == 1 ||
00158            tecid.ring() == 2 ||
00159            tecid.ring() == 5 ) {
00160         result = true;
00161       }
00162     }
00163   }
00164 
00165   return result;
00166 }
00167 
00168 bool RoadSearchDetIdHelper::IsSingleRPhi(const DetId id) {
00169 
00170   // return value
00171   bool result = true;
00172 
00173   if ( (unsigned int)id.subdetId() == StripSubdetector::TIB ) {
00174     TIBDetId tibid(id.rawId()); 
00175     if ( !tibid.glued() ) {
00176       if ( tibid.layer() == 1 ||
00177            tibid.layer() == 2 ) {
00178         result = false;
00179       }
00180     } else {
00181       result = false;
00182     }
00183   } else if ( (unsigned int)id.subdetId() == StripSubdetector::TOB ) {
00184     TOBDetId tobid(id.rawId()); 
00185     if ( !tobid.glued() ) {
00186       if ( tobid.layer() == 1 ||
00187            tobid.layer() == 2 ) {
00188         result = false;
00189       }
00190     } else {
00191       if ( (tobid.rawId()-2) != tobid.glued() ) {
00192         result = false;
00193       }
00194     }
00195   } else if ( (unsigned int)id.subdetId() == StripSubdetector::TID ) {
00196     TIDDetId tidid(id.rawId()); 
00197     if ( !tidid.glued() ) {
00198       if ( tidid.ring() == 1 ||
00199            tidid.ring() == 2 ) {
00200         result = false;
00201       } 
00202     } else {
00203       if ( (tidid.rawId()-2) != tidid.glued() ) {
00204         result = false;
00205       }
00206     }
00207   } else if ( (unsigned int)id.subdetId() == StripSubdetector::TEC ) {
00208     TECDetId tecid(id.rawId()); 
00209     if ( !tecid.glued() ) {
00210       if ( tecid.ring() == 1 ||
00211            tecid.ring() == 2 ||
00212            tecid.ring() == 5 ) {
00213         result = false;
00214       } 
00215     } else {
00216       if ( (tecid.rawId()-2) != tecid.glued() ) {
00217         result = false;
00218       }
00219     }
00220   }
00221 
00222   return result;
00223 }
00224 
00225 bool RoadSearchDetIdHelper::IsGluedRPhi(const DetId id) {
00226 
00227   // return value
00228   bool result = true;
00229 
00230   if ( (unsigned int)id.subdetId() == StripSubdetector::TIB ) {
00231     TIBDetId tibid(id.rawId()); 
00232     if ( !tibid.glued() ) {
00233       result = false;
00234     } else {
00235       if ( (tibid.rawId()-2) != tibid.glued() ) {
00236         result = false;
00237       }
00238     }
00239   } else if ( (unsigned int)id.subdetId() == StripSubdetector::TOB ) {
00240     TOBDetId tobid(id.rawId()); 
00241     if ( !tobid.glued() ) {
00242       result = false;
00243     } else {
00244       if ( (tobid.rawId()-2) != tobid.glued() ) {
00245         result = false;
00246       }
00247     }
00248   } else if ( (unsigned int)id.subdetId() == StripSubdetector::TID ) {
00249     TIDDetId tidid(id.rawId()); 
00250     if ( !tidid.glued() ) {
00251       result = false;
00252     } else {
00253       if ( (tidid.rawId()-2) != tidid.glued() ) {
00254         result = false;
00255       }
00256     }
00257   } else if ( (unsigned int)id.subdetId() == StripSubdetector::TEC ) {
00258     TECDetId tecid(id.rawId()); 
00259     if ( !tecid.glued() ) {
00260       result = false;
00261     } else {
00262       if ( (tecid.rawId()-2) != tecid.glued() ) {
00263         result = false;
00264       }
00265     }
00266   } else if ( (unsigned int)id.subdetId() == PixelSubdetector::PixelBarrel ) {
00267     result = false;
00268   } else if ( (unsigned int)id.subdetId() == PixelSubdetector::PixelEndcap ) {
00269     result = false;
00270   } 
00271 
00272   return result;
00273 }
00274 
00275 bool RoadSearchDetIdHelper::IsStereo(const DetId id) {
00276 
00277   // return value
00278   bool result = true;
00279 
00280   if ( (unsigned int)id.subdetId() == StripSubdetector::TIB ) {
00281     TIBDetId tibid(id.rawId()); 
00282     if ( !tibid.glued() ) {
00283       result = false;
00284     } else {
00285       if ( (tibid.rawId()-1) != tibid.glued() ) {
00286         result = false;
00287       }
00288     }
00289   } else if ( (unsigned int)id.subdetId() == StripSubdetector::TOB ) {
00290     TOBDetId tobid(id.rawId()); 
00291     if ( !tobid.glued() ) {
00292       result = false;
00293     } else {
00294       if ( (tobid.rawId()-1) != tobid.glued() ) {
00295         result = false;
00296       }
00297     }
00298   } else if ( (unsigned int)id.subdetId() == StripSubdetector::TID ) {
00299     TIDDetId tidid(id.rawId()); 
00300     if ( !tidid.glued() ) {
00301       result = false;
00302     } else {
00303       if ( (tidid.rawId()-1) != tidid.glued() ) {
00304         result = false;
00305       }
00306     }
00307   } else if ( (unsigned int)id.subdetId() == StripSubdetector::TEC ) {
00308     TECDetId tecid(id.rawId()); 
00309     if ( !tecid.glued() ) {
00310       result = false;
00311     } else {
00312       if ( (tecid.rawId()-1) != tecid.glued() ) {
00313         result = false;
00314       }
00315     }
00316   } else if ( (unsigned int)id.subdetId() == PixelSubdetector::PixelBarrel ) {
00317     result = false;
00318   } else if ( (unsigned int)id.subdetId() == PixelSubdetector::PixelEndcap ) {
00319     result = false;
00320   }
00321 
00322   return result;
00323 }
00324 
00325 DetId RoadSearchDetIdHelper::ReturnRPhiId(const DetId id) {
00326   //
00327   // return corresponding rphi id
00328   //
00329 
00330   if ( IsMatched(id) ) {
00331     return DetId(id.rawId()+2);
00332   } else if ( IsStereo(id) ) {
00333     return DetId(id.rawId()+1);
00334   } else {
00335     return id;
00336   }
00337 
00338   return id;
00339 }
00340 
00341 
00342 bool RoadSearchDetIdHelper::detIdsOnSameLayer(DetId id1, DetId id2) {
00343   //
00344   // check whether two detids are on the same layer
00345   //
00346 
00347   // return value
00348   bool result = false;
00349 
00350   // check if both rings belong to same subdetector
00351   if ( (unsigned int)id1.subdetId() == StripSubdetector::TIB && 
00352        (unsigned int)id2.subdetId() == StripSubdetector::TIB ) {
00353     // make TIBDetId instance
00354     TIBDetId id1TIB(id1.rawId());
00355     TIBDetId id2TIB(id2.rawId());
00356     // check whether both rings are on the same TIB layer
00357     if ( id1TIB.layer() == id2TIB.layer() ) {
00358       result = true;
00359     }
00360   } else if ( (unsigned int)id1.subdetId() == StripSubdetector::TOB &&
00361               (unsigned int)id2.subdetId() == StripSubdetector::TOB ) {
00362     // make TOBDetId instance
00363     TOBDetId id1TOB(id1.rawId());
00364     TOBDetId id2TOB(id2.rawId());
00365     // check whether both rings are on the same TOB layer
00366     if ( id1TOB.layer() == id2TOB.layer() ) {
00367       result = true;
00368     }
00369   } else if ( (unsigned int)id1.subdetId() == StripSubdetector::TID && 
00370               (unsigned int)id2.subdetId() == StripSubdetector::TID) {
00371     // make TIDDetId instance
00372     TIDDetId id1TID(id1.rawId());
00373     TIDDetId id2TID(id2.rawId());
00374     // check whether both rings are on the same TID wheel
00375     if ( id1TID.wheel() == id2TID.wheel() ) {
00376       result = true;
00377     }
00378   } else if ( (unsigned int)id1.subdetId() == StripSubdetector::TEC &&
00379               (unsigned int)id2.subdetId() == StripSubdetector::TEC ) {
00380     // make TECDetId instance
00381     TECDetId id1TEC(id1.rawId());
00382     TECDetId id2TEC(id2.rawId());
00383     // check whether both rings are on the same TEC wheel
00384     if ( id1TEC.wheel() == id2TEC.wheel() ) {
00385       result = true;
00386     }
00387   } else if ( (unsigned int)id1.subdetId() == PixelSubdetector::PixelBarrel && 
00388               (unsigned int)id2.subdetId() == PixelSubdetector::PixelBarrel) {
00389     // make PXBDetId instance
00390     PXBDetId id1PXB(id1.rawId());
00391     PXBDetId id2PXB(id2.rawId());
00392     // check whether both rings are on the same PXB layer
00393     if ( id1PXB.layer() == id2PXB.layer() ) {
00394       result = true;
00395     }
00396   } else if ( (unsigned int)id1.subdetId() == PixelSubdetector::PixelEndcap &&
00397               (unsigned int)id2.subdetId() == PixelSubdetector::PixelEndcap) {
00398     // make PXFDetId instance
00399     PXFDetId id1PXF(id1.rawId());
00400     PXFDetId id2PXF(id2.rawId());
00401     // check whether both rings are on the same PXF disk
00402     if ( id1PXF.disk() == id2PXF.disk() ) {
00403       result = true;
00404     }
00405   }
00406   
00407   return result;
00408 }