CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/DataFormats/TrackReco/src/HitPattern.cc

Go to the documentation of this file.
00001 #include "DataFormats/TrackReco/interface/HitPattern.h"
00002 #include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
00003 #include "DataFormats/SiPixelDetId/interface/PXBDetId.h"
00004 #include "DataFormats/SiPixelDetId/interface/PXFDetId.h"
00005 #include "DataFormats/SiStripDetId/interface/TIBDetId.h"
00006 #include "DataFormats/SiStripDetId/interface/TIDDetId.h"
00007 #include "DataFormats/SiStripDetId/interface/TOBDetId.h"
00008 #include "DataFormats/SiStripDetId/interface/TECDetId.h"
00009 #include "DataFormats/MuonDetId/interface/DTLayerId.h"
00010 #include "DataFormats/MuonDetId/interface/CSCDetId.h"
00011 #include "DataFormats/MuonDetId/interface/RPCDetId.h"
00012 using namespace reco;
00013 
00014 
00015 uint32_t HitPattern::encode(const TrackingRecHit & hit, unsigned int i){
00016   
00017   // ignore the rec hit if the number of hit is larger than the max
00018   if (i >= 32 * PatternSize / HitSize) return 0;
00019 
00020   // get rec hit det id and rec hit type
00021   DetId id = hit.geographicalId();
00022   uint32_t detid = id.det();
00023   uint32_t hitType = (uint32_t) hit.getType();
00024 
00025   // init pattern of this hit to 0
00026   uint32_t pattern = 0;
00027 
00028   // adding tracker/muon detector bit
00029   pattern += ((detid)&SubDetectorMask)<<SubDetectorOffset;
00030   
00031   // adding substructure (PXB,PXF,TIB,TID,TOB,TEC, or DT,CSC,RPC) bits 
00032   uint32_t subdet = id.subdetId();
00033   pattern += ((subdet)&SubstrMask)<<SubstrOffset;
00034   
00035   // adding layer/disk/wheel bits
00036   uint32_t layer = 0;
00037   if (detid == DetId::Tracker) {
00038     if (subdet == PixelSubdetector::PixelBarrel) 
00039       layer = PXBDetId(id).layer();
00040     else if (subdet == PixelSubdetector::PixelEndcap)
00041       layer = PXFDetId(id).disk();
00042     else if (subdet == StripSubdetector::TIB)
00043       layer = TIBDetId(id).layer();
00044     else if (subdet == StripSubdetector::TID)
00045       layer = TIDDetId(id).wheel();
00046     else if (subdet == StripSubdetector::TOB)
00047       layer = TOBDetId(id).layer();
00048     else if (subdet == StripSubdetector::TEC)
00049       layer = TECDetId(id).wheel();
00050   } else if (detid == DetId::Muon) {
00051     if (subdet == (uint32_t) MuonSubdetId::DT) 
00052       layer = ((DTLayerId(id.rawId()).station()-1)<<2) + DTLayerId(id.rawId()).superLayer();
00053     else if (subdet == (uint32_t) MuonSubdetId::CSC)
00054       layer = ((CSCDetId(id.rawId()).station()-1)<<2) +  (CSCDetId(id.rawId()).ring()-1);
00055     else if (subdet == (uint32_t) MuonSubdetId::RPC) {
00056       RPCDetId rpcid(id.rawId());
00057       layer = ((rpcid.station()-1)<<2) + abs(rpcid.region());
00058       if (rpcid.station() <= 2) layer += 2*(rpcid.layer()-1);
00059     }
00060   }
00061   pattern += (layer&LayerMask)<<LayerOffset;
00062 
00063   // adding mono/stereo bit
00064   uint32_t side = 0;
00065   if (detid == DetId::Tracker) {
00066        side = isStereo(id);
00067   } else if (detid == DetId::Muon) {
00068        side = 0;
00069   }
00070   pattern += (side&SideMask)<<SideOffset;
00071 
00072   // adding hit type bits
00073   pattern += (hitType&HitTypeMask)<<HitTypeOffset;
00074 
00075   return pattern;
00076 }
00077 
00078 
00079 void HitPattern::setHitPattern(int position, uint32_t pattern) {
00080   int offset = position * HitSize;
00081   for (int i=0; i<HitSize; i++) {
00082     int pos = offset + i;
00083     uint32_t bit = (pattern >> i) & 0x1;
00084     hitPattern_[pos / 32] += bit << ((offset + i) % 32); 
00085   }
00086 }
00087 
00088 void HitPattern::appendHit(const TrackingRecHit & hit){
00089 
00090   // get rec hit det id and rec hit type
00091   DetId id = hit.geographicalId();
00092   uint32_t detid = id.det();
00093   uint32_t subdet = id.subdetId();
00094 
00095   std::vector<const TrackingRecHit*> hits;
00096 
00097 
00098   if (detid == DetId::Tracker)
00099     hits.push_back(&hit);
00100    
00101   if (detid == DetId::Muon) {
00102 
00103     if (subdet == (uint32_t) MuonSubdetId::DT){
00104 
00105       // DT rechit (granularity 2)
00106       if(hit.dimension() == 1)
00107         hits.push_back(&hit);
00108       
00109       // 4D segment (granularity 0) 
00110       else if(hit.dimension() > 1){ // Both 2 and 4 dim cases. MB4s have 2D, but formatted in 4D segments 
00111         std::vector<const TrackingRecHit*> seg2D = hit.recHits(); // 4D --> 2D
00112         // load 1D hits (2D --> 1D)
00113         for(std::vector<const TrackingRecHit*>::const_iterator it = seg2D.begin(); it != seg2D.end(); ++it){
00114           std::vector<const TrackingRecHit*> hits1D =  (*it)->recHits();
00115           copy(hits1D.begin(),hits1D.end(),back_inserter(hits));
00116         }
00117       }
00118     }
00119 
00120     else if (subdet == (uint32_t) MuonSubdetId::CSC){
00121       
00122       // CSC rechit (granularity 2)
00123       if(hit.dimension() == 2)
00124         hits.push_back(&hit);
00125 
00126       // 4D segment (granularity 0) 
00127       if(hit.dimension() == 4)
00128         hits = hit.recHits(); // load 2D hits (4D --> 1D)
00129     }
00130    
00131     else if (subdet == (uint32_t) MuonSubdetId::RPC) {
00132       hits.push_back(&hit);
00133     }
00134   }
00135 
00136   unsigned int i =  numberOfHits();
00137   for(std::vector<const TrackingRecHit*>::const_iterator it = hits.begin(); it != hits.end(); ++it)
00138     set(**it,i++);
00139 
00140 
00141 }
00142 
00143 
00144 uint32_t HitPattern::getHitPattern(int position) const {
00145 /* Note: you are not taking a consecutive sequence of HitSize bits starting from position*HitSize
00146          as the bit order in the words are reversed. 
00147          e.g. if position = 0 you take the lowest 10 bits of the first word.
00148     
00149          I hope this can clarify what is the memory layout of such thing
00150 
00151  straight 01234567890123456789012345678901 | 23456789012345678901234567890123 | 4567
00152  (global) 0         1         2         3  | 3       4         5         6    | 6  
00153  words    [--------------0---------------] | [--------------1---------------] | [---   
00154  word     01234567890123456789012345678901 | 01234567890123456789012345678901 | 0123
00155   (str)   0         1         2         3  | 0         1         2         3  | 0
00156           [--------------0---------------] | [--------------1---------------] | [---   
00157  word     10987654321098765432109876543210 | 10987654321098765432109876543210 | 1098
00158   (rev)   32         21        10        0 | 32         21        10        0 | 32  
00159  reverse  10987654321098765432109876543210 | 32109876543210987654321098765432 | 5432
00160           32         21        10        0 | 6  65        54        43      3   9
00161 
00162          ugly enough, but it's not my fault, I was not even in CMS at that time   [gpetrucc] */
00163   uint16_t bitEndOffset = (position+1) * HitSize;
00164   uint8_t secondWord   = (bitEndOffset >> 5);
00165   uint8_t secondWordBits = bitEndOffset & (32-1); // that is, bitEndOffset % 32
00166   if (secondWordBits >= HitSize) { // full block is in this word
00167       uint8_t lowBitsToTrash = secondWordBits - HitSize;
00168       uint32_t myResult = (hitPattern_[secondWord] >> lowBitsToTrash) & ((1 << HitSize)-1);
00169       return myResult;
00170   } else {
00171       uint8_t  firstWordBits   = HitSize - secondWordBits;
00172       uint32_t firstWordBlock  = hitPattern_[secondWord-1] >> (32-firstWordBits);
00173       uint32_t secondWordBlock = hitPattern_[secondWord] & ((1<<secondWordBits)-1);
00174       uint32_t myResult = firstWordBlock + (secondWordBlock << firstWordBits);
00175       return myResult;
00176   }
00177 }
00178 
00179 
00180 
00181 
00182 
00183 bool HitPattern::hasValidHitInFirstPixelBarrel() const {
00184   for (int i=0; i<(PatternSize * 32) / HitSize; i++) {
00185     uint32_t pattern = getHitPattern(i);
00186     if (pattern == 0) break;
00187     if (pixelBarrelHitFilter(pattern)) {
00188       if (getLayer(pattern) == 1) {
00189         if (validHitFilter(pattern)) {
00190           return true;
00191         }
00192       }
00193     }
00194   }
00195   return false;
00196 }
00197 
00198 bool HitPattern::hasValidHitInFirstPixelEndcap() const {
00199   for (int i=0; i<(PatternSize * 32) / HitSize; i++) {
00200     uint32_t pattern = getHitPattern(i);
00201     if (pattern == 0) break;
00202     if (pixelEndcapHitFilter(pattern)) {
00203       if (getLayer(pattern) == 1) {
00204         if (validHitFilter(pattern)) {
00205           return true;
00206         }
00207       }
00208     }
00209   }
00210   return false;
00211 }
00212 
00213 int HitPattern::numberOfHits() const {
00214   int count = 0;
00215   for (int i=0; i<(PatternSize * 32) / HitSize; i++) {
00216     uint32_t pattern = getHitPattern(i);
00217     if (pattern == 0) break;
00218     ++count;
00219   }
00220   return count;
00221 }
00222 
00223 
00224 int HitPattern::numberOfValidStripLayersWithMonoAndStereo () const {
00225   static const int nHits = (PatternSize * 32) / HitSize;
00226   bool hasMono[SubstrMask + 1][LayerMask + 1];
00227   //     printf("sizeof(hasMono) = %d\n", sizeof(hasMono));
00228   memset(hasMono, 0, sizeof(hasMono));
00229   bool hasStereo[SubstrMask + 1][LayerMask + 1];
00230   memset(hasStereo, 0, sizeof(hasStereo));
00231   // mark which layers have mono/stereo hits
00232   for (int i = 0; i < nHits; i++) {
00233     uint32_t pattern = getHitPattern(i);
00234     if (pattern == 0) break;
00235     if (validHitFilter(pattern) && stripHitFilter(pattern)) {
00236       switch (getSide(pattern)) {
00237       case 0: // mono
00238         hasMono[getSubStructure(pattern)][getLayer(pattern)] 
00239           = true;
00240         break;
00241       case 1: // stereo
00242         hasStereo[getSubStructure(pattern)][getLayer(pattern)]
00243           = true;
00244         break;
00245       default:
00246         break;
00247       }
00248     }
00249     
00250   }
00251   // count how many layers have mono and stereo hits
00252   int count = 0;
00253   for (int i = 0; i < SubstrMask + 1; ++i) 
00254     for (int j = 0; j < LayerMask + 1; ++j)
00255       if (hasMono[i][j] && hasStereo[i][j])
00256         count++;
00257   return count;
00258 }
00259 
00260 uint32_t HitPattern::getTrackerLayerCase(uint32_t substr, uint32_t layer) const {
00261   uint32_t tk_substr_layer = 
00262     (1 << SubDetectorOffset) +
00263     ((substr & SubstrMask) << SubstrOffset) +
00264     ((layer & LayerMask) << LayerOffset);
00265   
00266   uint32_t mask =
00267     (SubDetectorMask << SubDetectorOffset) +
00268     (SubstrMask << SubstrOffset) +
00269     (LayerMask << LayerOffset);
00270   
00271   // crossed
00272   //   layer case 0: valid + (missing, off, bad) ==> with measurement
00273   //   layer case 1: missing + (off, bad) ==> without measurement
00274   //   layer case 2: off, bad ==> totally off or bad, cannot say much
00275   // not crossed
00276   //   layer case 999999: track outside acceptance or in gap ==> null
00277 
00278   uint32_t layerCase = 999999;
00279   for (int i=0; i<(PatternSize * 32) / HitSize; i++)
00280   {
00281     uint32_t pattern = getHitPattern(i);
00282     if (pattern == 0) break;
00283     if ((pattern & mask) == tk_substr_layer) {
00284       uint32_t hitType = (pattern >> HitTypeOffset) & HitTypeMask; // 0,1,2,3
00285       if (hitType < layerCase) {
00286         layerCase = hitType;
00287         if (hitType == 3) layerCase = 2;
00288       }
00289     }
00290   }
00291   return layerCase;
00292 }
00293 
00294 uint32_t HitPattern::getTrackerMonoStereo (uint32_t substr, uint32_t layer) const
00295 {
00296   uint32_t tk_substr_layer = 
00297     (1 << SubDetectorOffset) +
00298     ((substr & SubstrMask) << SubstrOffset) +
00299     ((layer & LayerMask) << LayerOffset);
00300 
00301   uint32_t mask =
00302     (SubDetectorMask << SubDetectorOffset) +
00303     (SubstrMask << SubstrOffset) +
00304     (LayerMask << LayerOffset);
00305 
00306   //    0:              neither a valid mono nor a valid stereo hit
00307   //    MONO:           valid mono hit
00308   //    STEREO:         valid stereo hit
00309   //    MONO | STEREO:  both
00310   uint32_t monoStereo = 0;
00311   for (int i=0; i<(PatternSize * 32) / HitSize; i++)
00312   {
00313     uint32_t pattern = getHitPattern(i);
00314     if (pattern == 0) break;
00315     if ((pattern & mask) == tk_substr_layer)
00316     {
00317       uint32_t hitType = (pattern >> HitTypeOffset) & HitTypeMask; // 0,1,2,3
00318       if (hitType == 0) { // valid hit
00319            switch (getSide(pattern)) {
00320            case 0: // mono
00321                 monoStereo |= MONO;
00322                 break;
00323            case 1: // stereo
00324                 monoStereo |= STEREO;
00325                 break;
00326            default:
00327                 break;
00328            }
00329       }
00330     }
00331   }
00332   return monoStereo;
00333 }
00334 
00335 
00336 
00337 int HitPattern::pixelBarrelLayersWithMeasurement() const {
00338   int count = 0;
00339   uint32_t substr = PixelSubdetector::PixelBarrel;
00340   uint32_t NPixBarrel = 4;
00341   for (uint32_t layer=1; layer<=NPixBarrel; layer++) {
00342     if (getTrackerLayerCase(substr, layer) == 0) count++;
00343   }
00344   return count;
00345 }
00346 
00347 int HitPattern::pixelEndcapLayersWithMeasurement() const {
00348   int count = 0;
00349   uint32_t substr = PixelSubdetector::PixelEndcap;
00350   uint32_t NPixForward = 3;
00351   for (uint32_t layer=1; layer<=NPixForward; layer++) {
00352     if (getTrackerLayerCase(substr, layer) == 0) count++;
00353   }
00354   return count;
00355 }
00356 
00357 int HitPattern::stripTIBLayersWithMeasurement() const {
00358   int count = 0;
00359   uint32_t substr = StripSubdetector::TIB;
00360   for (uint32_t layer=1; layer<=4; layer++) {
00361     if (getTrackerLayerCase(substr, layer) == 0) count++;
00362   }
00363   return count;
00364 }
00365 
00366 int HitPattern::stripTIDLayersWithMeasurement() const {
00367   int count = 0;
00368   uint32_t substr = StripSubdetector::TID;
00369   for (uint32_t layer=1; layer<=3; layer++) {
00370     if (getTrackerLayerCase(substr, layer) == 0) count++;
00371   }
00372   return count;
00373 }
00374 
00375 int HitPattern::stripTOBLayersWithMeasurement() const {
00376   int count = 0;
00377   uint32_t substr = StripSubdetector::TOB;
00378   for (uint32_t layer=1; layer<=6; layer++) {
00379     if (getTrackerLayerCase(substr, layer) == 0) count++;
00380   }
00381   return count;
00382 }
00383 
00384 int HitPattern::stripTECLayersWithMeasurement() const {
00385   int count = 0;
00386   uint32_t substr = StripSubdetector::TEC;
00387   for (uint32_t layer=1; layer<=9; layer++) {
00388     if (getTrackerLayerCase(substr, layer) == 0) count++;
00389   }
00390   return count;
00391 }
00392 
00393 
00394 int HitPattern::pixelBarrelLayersWithoutMeasurement() const {
00395   int count = 0;
00396   uint32_t substr = PixelSubdetector::PixelBarrel;
00397   uint32_t NPixBarrel = 4;
00398   for (uint32_t layer=1; layer<=NPixBarrel; layer++) {
00399     if (getTrackerLayerCase(substr, layer) == 1) count++;
00400   }
00401   return count;
00402 }
00403 
00404 int HitPattern::pixelEndcapLayersWithoutMeasurement() const {
00405   int count = 0;
00406   uint32_t substr = PixelSubdetector::PixelEndcap;
00407   uint32_t NPixForward = 3;
00408   for (uint32_t layer=1; layer<=NPixForward; layer++) {
00409     if (getTrackerLayerCase(substr, layer) == 1) count++;
00410   }
00411   return count;
00412 }
00413 
00414 int HitPattern::stripTIBLayersWithoutMeasurement() const {
00415   int count = 0;
00416   uint32_t substr = StripSubdetector::TIB;
00417   for (uint32_t layer=1; layer<=4; layer++) {
00418     if (getTrackerLayerCase(substr, layer) == 1) count++;
00419   }
00420   return count;
00421 }
00422 
00423 int HitPattern::stripTIDLayersWithoutMeasurement() const {
00424   int count = 0;
00425   uint32_t substr = StripSubdetector::TID;
00426   for (uint32_t layer=1; layer<=3; layer++) {
00427     if (getTrackerLayerCase(substr, layer) == 1) count++;
00428   }
00429   return count;
00430 }
00431 
00432 int HitPattern::stripTOBLayersWithoutMeasurement() const {
00433   int count = 0;
00434   uint32_t substr = StripSubdetector::TOB;
00435   for (uint32_t layer=1; layer<=6; layer++) {
00436     if (getTrackerLayerCase(substr, layer) == 1) count++;
00437   }
00438   return count;
00439 }
00440 
00441 int HitPattern::stripTECLayersWithoutMeasurement() const {
00442   int count = 0;
00443   uint32_t substr = StripSubdetector::TEC;
00444   for (uint32_t layer=1; layer<=9; layer++) {
00445     if (getTrackerLayerCase(substr, layer) == 1) count++;
00446   }
00447   return count;
00448 }
00449 
00450 
00451 int HitPattern::pixelBarrelLayersTotallyOffOrBad() const {
00452   int count = 0;
00453   uint32_t substr = PixelSubdetector::PixelBarrel;
00454   uint32_t NPixBarrel = 4;
00455   for (uint32_t layer=1; layer<=NPixBarrel; layer++) {
00456     if (getTrackerLayerCase(substr, layer) == 2) count++;
00457   }
00458   return count;
00459 }
00460 
00461 int HitPattern::pixelEndcapLayersTotallyOffOrBad() const {
00462   int count = 0;
00463   uint32_t substr = PixelSubdetector::PixelEndcap;
00464   uint32_t NPixForward = 3;
00465   for (uint32_t layer=1; layer<=NPixForward; layer++) {
00466     if (getTrackerLayerCase(substr, layer) == 2) count++;
00467   }
00468   return count;
00469 }
00470 
00471 int HitPattern::stripTIBLayersTotallyOffOrBad() const {
00472   int count = 0;
00473   uint32_t substr = StripSubdetector::TIB;
00474   for (uint32_t layer=1; layer<=4; layer++) {
00475     if (getTrackerLayerCase(substr, layer) == 2) count++;
00476   }
00477   return count;
00478 }
00479 
00480 int HitPattern::stripTIDLayersTotallyOffOrBad() const {
00481   int count = 0;
00482   uint32_t substr = StripSubdetector::TID;
00483   for (uint32_t layer=1; layer<=3; layer++) {
00484     if (getTrackerLayerCase(substr, layer) == 2) count++;
00485   }
00486   return count;
00487 }
00488 
00489 int HitPattern::stripTOBLayersTotallyOffOrBad() const {
00490   int count = 0;
00491   uint32_t substr = StripSubdetector::TOB;
00492   for (uint32_t layer=1; layer<=6; layer++) {
00493     if (getTrackerLayerCase(substr, layer) == 2) count++;
00494   }
00495   return count;
00496 }
00497 
00498 int HitPattern::stripTECLayersTotallyOffOrBad() const {
00499   int count = 0;
00500   uint32_t substr = StripSubdetector::TEC;
00501   for (uint32_t layer=1; layer<=9; layer++) {
00502     if (getTrackerLayerCase(substr, layer) == 2) count++;
00503   }
00504   return count;
00505 }
00506 
00507 
00508 int HitPattern::pixelBarrelLayersNull() const {
00509   int count = 0;
00510   uint32_t substr = PixelSubdetector::PixelBarrel;
00511   uint32_t NPixBarrel = 4;
00512   for (uint32_t layer=1; layer<=NPixBarrel; layer++) {
00513     if (getTrackerLayerCase(substr, layer) == 999999) count++;
00514   }
00515   return count;
00516 }
00517 
00518 int HitPattern::pixelEndcapLayersNull() const {
00519   int count = 0;
00520   uint32_t substr = PixelSubdetector::PixelEndcap;
00521   uint32_t NPixForward = 3;
00522   for (uint32_t layer=1; layer<=NPixForward; layer++) {
00523     if (getTrackerLayerCase(substr, layer) == 999999) count++;
00524   }
00525   return count;
00526 }
00527 
00528 int HitPattern::stripTIBLayersNull() const {
00529   int count = 0;
00530   uint32_t substr = StripSubdetector::TIB;
00531   for (uint32_t layer=1; layer<=4; layer++) {
00532     if (getTrackerLayerCase(substr, layer) == 999999) count++;
00533   }
00534   return count;
00535 }
00536 
00537 int HitPattern::stripTIDLayersNull() const {
00538   int count = 0;
00539   uint32_t substr = StripSubdetector::TID;
00540   for (uint32_t layer=1; layer<=3; layer++) {
00541     if (getTrackerLayerCase(substr, layer) == 999999) count++;
00542   }
00543   return count;
00544 }
00545 
00546 int HitPattern::stripTOBLayersNull() const {
00547   int count = 0;
00548   uint32_t substr = StripSubdetector::TOB;
00549   for (uint32_t layer=1; layer<=6; layer++) {
00550     if (getTrackerLayerCase(substr, layer) == 999999) count++;
00551   }
00552   return count;
00553 }
00554 
00555 int HitPattern::stripTECLayersNull() const {
00556   int count = 0;
00557   uint32_t substr = StripSubdetector::TEC;
00558   for (uint32_t layer=1; layer<=9; layer++) {
00559     if (getTrackerLayerCase(substr, layer) == 999999) count++;
00560   }
00561   return count;
00562 }
00563 
00564 void HitPattern::printHitPattern (int position, std::ostream &stream) const
00565 {
00566      uint32_t pattern = getHitPattern(position);
00567      stream << "\t";
00568      if (muonHitFilter(pattern))
00569           stream << "muon";
00570      if (trackerHitFilter(pattern))
00571           stream << "tracker";
00572      stream << "\tsubstructure " << getSubStructure(pattern);
00573      if (muonHitFilter(pattern)) {
00574          stream << "\tstation " << getMuonStation(pattern);
00575          if (muonDTHitFilter(pattern)) { 
00576             stream << "\tdt superlayer " << getDTSuperLayer(pattern); 
00577          } else if (muonCSCHitFilter(pattern)) { 
00578             stream << "\tcsc ring " << getCSCRing(pattern); 
00579          } else if (muonRPCHitFilter(pattern)) {
00580             stream << "\trpc " << (getRPCregion(pattern) ? "endcaps" : "barrel") << ", layer " << getRPCLayer(pattern); 
00581          } else {
00582             stream << "(UNKNOWN Muon SubStructure!) \tsubsubstructure " << getSubStructure(pattern);
00583          }
00584      } else {
00585          stream << "\tlayer " << getLayer(pattern);
00586      }
00587      stream << "\thit type " << getHitType(pattern);
00588      stream << std::endl;
00589 }
00590 
00591 void HitPattern::print (std::ostream &stream) const
00592 {
00593      stream << "HitPattern" << std::endl;
00594      for (int i = 0; i < numberOfHits(); i++) 
00595           printHitPattern(i, stream);
00596      std::ios_base::fmtflags flags = stream.flags();
00597      stream.setf ( std::ios_base::hex, std::ios_base::basefield );  
00598      stream.setf ( std::ios_base::showbase );               
00599      for (int i = 0; i < numberOfHits(); i++) {
00600           uint32_t pattern = getHitPattern(i);
00601           stream << pattern << std::endl;
00602      }
00603      stream.flags(flags);
00604 }
00605 
00606 uint32_t HitPattern::isStereo (DetId i) 
00607 {
00608      switch (i.det()) {
00609      case DetId::Tracker:
00610           switch (i.subdetId()) {
00611           case PixelSubdetector::PixelBarrel:
00612           case PixelSubdetector::PixelEndcap:
00613                return 0;
00614           case StripSubdetector::TIB:
00615           {
00616                TIBDetId id = i;
00617                return id.isStereo();
00618           }
00619           case StripSubdetector::TID:
00620           {
00621                TIDDetId id = i;
00622                return id.isStereo();
00623           }
00624           case StripSubdetector::TOB:
00625           {
00626                TOBDetId id = i;
00627                return id.isStereo();
00628           }
00629           case StripSubdetector::TEC:
00630           {
00631                TECDetId id = i;
00632                return id.isStereo();
00633           }
00634           default:
00635                return 0;
00636           }
00637           break;
00638      default:
00639           return 0;
00640      }
00641 }
00642 
00643 int  HitPattern::muonStations(int subdet, int hitType) const {
00644   int stations[4] = { 0,0,0,0 };
00645   for (int i=0; i<(PatternSize * 32) / HitSize; i++) {
00646     uint32_t pattern = getHitPattern(i);
00647     if (pattern == 0) break;
00648     if (muonHitFilter(pattern) &&
00649         (subdet  == 0  || int(getSubStructure(pattern)) == subdet) &&
00650         (hitType == -1 || int(getHitType(pattern))      == hitType)) {
00651         stations[getMuonStation(pattern)-1] = 1;
00652     }
00653   }
00654   return stations[0]+stations[1]+stations[2]+stations[3];
00655 }
00656 
00657 
00658 int HitPattern::innermostMuonStationWithHits(int hitType) const {
00659   int ret = 0;
00660   for (int i=0; i<(PatternSize * 32) / HitSize; i++) {
00661     uint32_t pattern = getHitPattern(i);
00662     if (pattern == 0) break;
00663     if (muonHitFilter(pattern) &&
00664         (hitType == -1 || int(getHitType(pattern)) == hitType)) {
00665         int stat = getMuonStation(pattern);
00666         if (ret == 0 || stat < ret) ret = stat;
00667     }
00668   }
00669   return ret;
00670 }
00671 
00672 int HitPattern::outermostMuonStationWithHits(int hitType) const {
00673   int ret = 0;
00674   for (int i=0; i<(PatternSize * 32) / HitSize; i++) {
00675     uint32_t pattern = getHitPattern(i);
00676     if (pattern == 0) break;
00677     if (muonHitFilter(pattern) &&
00678         (hitType == -1 || int(getHitType(pattern)) == hitType)) {
00679         int stat = getMuonStation(pattern);
00680         if (ret == 0 || stat > ret) ret = stat;
00681     }
00682   }
00683   return ret;
00684 }
00685 
00686 
00687 int HitPattern::numberOfDTStationsWithRPhiView() const {
00688   int stations[4] = { 0,0,0,0 };
00689   for (int i=0; i<(PatternSize * 32) / HitSize; i++) {
00690     uint32_t pattern = getHitPattern(i);
00691     if (pattern == 0) break;
00692     if (muonDTHitFilter(pattern) && validHitFilter(pattern) && getDTSuperLayer(pattern) != 2) {
00693         stations[getMuonStation(pattern)-1] = 1;
00694     }
00695   }
00696   return stations[0]+stations[1]+stations[2]+stations[3];
00697 }
00698 
00699 int HitPattern::numberOfDTStationsWithRZView() const {
00700   int stations[4] = { 0,0,0,0 };
00701   for (int i=0; i<(PatternSize * 32) / HitSize; i++) {
00702     uint32_t pattern = getHitPattern(i);
00703     if (pattern == 0) break;
00704     if (muonDTHitFilter(pattern) && validHitFilter(pattern) && getDTSuperLayer(pattern) == 2) {
00705         stations[getMuonStation(pattern)-1] = 1;
00706     }
00707   }
00708   return stations[0]+stations[1]+stations[2]+stations[3];
00709 }
00710 
00711 int HitPattern::numberOfDTStationsWithBothViews() const {
00712   int stations[4][2] = { {0,0}, {0,0}, {0,0}, {0,0} };
00713   for (int i=0; i<(PatternSize * 32) / HitSize; i++) {
00714     uint32_t pattern = getHitPattern(i);
00715     if (pattern == 0) break;
00716     if (muonDTHitFilter(pattern) && validHitFilter(pattern)) {
00717         stations[getMuonStation(pattern)-1][getDTSuperLayer(pattern) == 2] = 1;
00718     }
00719   }
00720   return stations[0][0]*stations[0][1] + stations[1][0]*stations[1][1] + stations[2][0]*stations[2][1] + stations[3][0]*stations[3][1];
00721 }
00722 
00723 
00724