Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:05:22

0001 #include "DataFormats/TrackReco/interface/HitPattern.h"
0002 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0003 
0004 #include <random>
0005 #include <algorithm>
0006 #include <cstdio>
0007 #include <iostream>
0008 
0009 namespace test {
0010   namespace TestHitPattern {
0011     using namespace reco;
0012 
0013     int test() {
0014       {
0015         // Phase0, only for testing
0016         TrackerTopology::PixelBarrelValues ttopo_pxb{
0017             16,
0018             8,
0019             2,
0020             0,
0021             0xF,
0022             0xFF,
0023             0x3F,
0024             0x0};  //DoubleMask is not used in Phase0, so initializing the corresponding starting bit and mask to 0
0025         TrackerTopology::PixelEndcapValues ttopo_pxf{23, 16, 10, 8, 2, 0x3, 0xF, 0x3F, 0x3, 0x3F};
0026         TrackerTopology::TECValues ttopo_tec{18, 14, 12, 8, 5, 2, 0, 0x3, 0xF, 0x3, 0xF, 0x7, 0x7, 0x3};
0027         TrackerTopology::TIBValues ttopo_tib{14, 12, 10, 4, 2, 0, 0x7, 0x3, 0x3, 0x7F, 0x3, 0x3};
0028         TrackerTopology::TIDValues ttopo_tid{13, 11, 9, 7, 2, 0, 0x3, 0x3, 0x3, 0x3, 0x1f, 0x3};
0029         TrackerTopology::TOBValues ttopo_tob{14, 12, 5, 2, 0, 0x7, 0x3, 0x7f, 0x7, 0x3};
0030         TrackerTopology ttopo{ttopo_pxb, ttopo_pxf, ttopo_tec, ttopo_tib, ttopo_tid, ttopo_tob};
0031 
0032         const uint32_t radial_detids[] = {
0033             402666125,  //TID r1
0034             402668833,  //TID r2
0035             402673476,  //TID r3
0036             470066725,  //TEC r1
0037             470390853,  //TEC r2
0038             470114664,  //TEC r3
0039             470131344,  //TEC r4
0040             470079661,  //TEC r5
0041             470049476,  //TEC r6
0042             470045428,  //TEC r7
0043             0x628f3a3c  // MTD BTL
0044         };
0045 
0046         HitPattern hp;
0047         auto i = 0;
0048         for (auto id : radial_detids) {
0049           hp.appendHit(id, (i++ == 1) ? TrackingRecHit::missing : TrackingRecHit::valid, ttopo);
0050         }
0051         hp.appendHit(radial_detids[2], TrackingRecHit::missing, ttopo);
0052         hp.appendHit(radial_detids[8], TrackingRecHit::missing, ttopo);
0053 
0054         std::cout << hp.numberOfValidTrackerHits() << ' ' << hp.numberOfValidPixelHits() << ' '
0055                   << hp.numberOfValidStripHits() << ' ' << hp.numberOfValidTimingHits() << std::endl;
0056         std::cout << hp.pixelLayersWithMeasurement() << ' ' << hp.stripLayersWithMeasurement() << std::endl;
0057         std::cout << hp.numberOfValidStripLayersWithMonoAndStereo() << std::endl;
0058         std::cout << hp.pixelLayersWithoutMeasurement(HitPattern::TRACK_HITS) << ' '
0059                   << hp.stripLayersWithoutMeasurement(HitPattern::TRACK_HITS) << std::endl;
0060 
0061         assert(hp.numberOfValidTrackerHits() == 9);
0062         assert(hp.numberOfValidPixelHits() == 0);
0063         assert(hp.numberOfValidStripHits() == 9);
0064         assert(hp.pixelLayersWithMeasurement() == 0);
0065         assert(hp.stripLayersWithMeasurement() == 7);
0066         assert(hp.numberOfValidStripLayersWithMonoAndStereo() == 1);
0067         assert(hp.pixelLayersWithoutMeasurement(HitPattern::TRACK_HITS) == 0);
0068         assert(hp.stripLayersWithoutMeasurement(HitPattern::TRACK_HITS) == 1);
0069         assert(hp.numberOfValidTimingHits() == 1);
0070       }
0071 
0072       {
0073         uint16_t oldHitPattern[50] = {20113, 44149, 2321, 19529, 37506, 34993, 11429, 12644, 23051, 13124, 26, 0};
0074 
0075         uint8_t hitCount = 15;
0076         uint8_t beginTrackHits = 3;
0077         uint8_t endTrackHits = 15;
0078         uint8_t beginInner = 0;
0079         uint8_t endInner = 0;
0080         uint8_t beginOuter = 0;
0081         uint8_t endOuter = 3;
0082 
0083         HitPattern hp;
0084         HitPattern::fillNewHitPatternWithOldHitPattern_v12(
0085             oldHitPattern, hitCount, beginTrackHits, endTrackHits, beginInner, endInner, beginOuter, endOuter, &hp);
0086 
0087         assert(hp.numberOfValidTrackerHits() == 12);
0088         assert(hp.numberOfValidPixelHits() == 4);
0089         assert(hp.numberOfValidPixelBarrelHits() == 4);
0090         assert(hp.numberOfValidPixelEndcapHits() == 0);
0091         assert(hp.numberOfValidStripHits() == 8);
0092         assert(hp.numberOfValidStripTIBHits() == 6);
0093         assert(hp.numberOfValidStripTIDHits() == 0);
0094         assert(hp.numberOfValidStripTOBHits() == 2);
0095         assert(hp.numberOfValidStripTECHits() == 0);
0096 
0097         assert(hp.numberOfTimingHits() == 0);
0098         assert(hp.numberOfValidTimingHits() == 0);
0099         assert(hp.numberOfValidTimingBTLHits() == 0);
0100         assert(hp.numberOfValidTimingETLHits() == 0);
0101 
0102         assert(hp.numberOfLostTimingHits() == 0);
0103         assert(hp.numberOfLostTimingBTLHits() == 0);
0104         assert(hp.numberOfLostTimingETLHits() == 0);
0105 
0106         assert(hp.numberOfMuonHits() == 0);
0107         assert(hp.numberOfValidMuonHits() == 0);
0108         assert(hp.numberOfValidMuonDTHits() == 0);
0109         assert(hp.numberOfValidMuonCSCHits() == 0);  //20
0110         assert(hp.numberOfValidMuonRPCHits() == 0);
0111         assert(hp.numberOfValidMuonGEMHits() == 0);
0112         assert(hp.numberOfValidMuonME0Hits() == 0);
0113 
0114         assert(hp.numberOfLostMuonHits() == 0);
0115         assert(hp.numberOfLostMuonDTHits() == 0);
0116         assert(hp.numberOfLostMuonCSCHits() == 0);
0117         assert(hp.numberOfLostMuonRPCHits() == 0);
0118         assert(hp.numberOfLostMuonGEMHits() == 0);
0119         assert(hp.numberOfLostMuonME0Hits() == 0);
0120 
0121         assert(hp.numberOfBadHits() == 0);  // 30
0122         assert(hp.numberOfBadMuonHits() == 0);
0123         assert(hp.numberOfBadMuonDTHits() == 0);
0124         assert(hp.numberOfBadMuonCSCHits() == 0);
0125         assert(hp.numberOfBadMuonRPCHits() == 0);
0126         assert(hp.numberOfBadMuonGEMHits() == 0);
0127         assert(hp.numberOfBadMuonME0Hits() == 0);
0128 
0129         assert(hp.numberOfInactiveHits() == 0);
0130         assert(hp.numberOfInactiveTrackerHits() == 0);
0131         //assert(hp.numberOfInactiveTimingHits() );
0132 
0133         assert(hp.numberOfValidStripLayersWithMonoAndStereo() == 3);
0134 
0135         assert(hp.trackerLayersWithMeasurementOld() == 9);  //40
0136         assert(hp.trackerLayersWithMeasurement() == 9);
0137         assert(hp.pixelLayersWithMeasurementOld() == 4);
0138         assert(hp.pixelLayersWithMeasurement() == 4);
0139         assert(hp.stripLayersWithMeasurement() == 5);
0140         assert(hp.pixelBarrelLayersWithMeasurement() == 4);
0141         assert(hp.pixelEndcapLayersWithMeasurement() == 0);
0142         assert(hp.stripTIBLayersWithMeasurement() == 4);
0143         assert(hp.stripTIDLayersWithMeasurement() == 0);
0144         assert(hp.stripTOBLayersWithMeasurement() == 1);
0145         assert(hp.stripTECLayersWithMeasurement() == 0);  //50
0146 
0147         assert(hp.trackerLayersNull() == 20);
0148         assert(hp.pixelLayersNull() == 3);
0149         assert(hp.stripLayersNull() == 17);
0150         assert(hp.pixelBarrelLayersNull() == 0);
0151         assert(hp.pixelEndcapLayersNull() == 3);
0152         assert(hp.stripTIBLayersNull() == 0);
0153         assert(hp.stripTIDLayersNull() == 3);
0154         assert(hp.stripTOBLayersNull() == 5);
0155         assert(hp.stripTECLayersNull() == 9);
0156       }
0157 
0158       HitPattern hp1;
0159       HitPattern hp2;
0160       std::mt19937 eng;
0161       std::uniform_int_distribution<int> ugen(1, 255);
0162 
0163       hp1.insertTrackHit(121 << 3);
0164       hp2.insertTrackHit(121 << 3);
0165       hp1.insertTrackHit(121 << 3);
0166       hp2.insertTrackHit(125 << 3);
0167       hp1.insertTrackHit(121 << 3);
0168       hp2.insertTrackHit(121 << 3);
0169 
0170       for (int i = 3; i != 20; ++i) {
0171         if (i % 7 == 1) {
0172           hp1.insertTrackHit((123 << 3) + 1);  // invalid
0173         }
0174         if (i % 3 == 1) {
0175           int p = ugen(eng);
0176           hp1.insertTrackHit(p << 3);
0177           hp2.insertTrackHit(p << 3);
0178         } else {
0179           hp1.insertTrackHit(ugen(eng) << 3);
0180           hp2.insertTrackHit(ugen(eng) << 3);
0181         }
0182       }
0183 
0184       for (int i = 0; i != 15; ++i) {
0185         printf("%d,%d ",
0186                hp1.getHitPattern(HitPattern::TRACK_HITS, i) >> 3,
0187                hp2.getHitPattern(HitPattern::TRACK_HITS, i) >> 3);
0188       }
0189       printf("\n");
0190 
0191       PatternSet<15> p1(HitPattern::TRACK_HITS, hp1), p2(HitPattern::TRACK_HITS, hp2);
0192 
0193       PatternSet<15> comm = commonHits(p1, p2);
0194       std::cout << "common " << comm.size() << std::endl;
0195       for (auto p : comm) {
0196         printf("%d ", int(p));
0197       }
0198       printf("\n");
0199 
0200       assert(p1.size() == 15);
0201       assert(p2.size() == 15);
0202       for (int i = 0; i != 14; ++i) {
0203         printf("%d,%d ", int(p1[i]), int(p2[i]));
0204         assert(p1[i] != 0);
0205         assert(p2[i] != 0);
0206         assert(p1[i] <= p1[i + 1]);
0207         assert(p2[i] <= p2[i + 1]);
0208       }
0209       printf("\n");
0210       return 0;
0211     }
0212   }  // namespace TestHitPattern
0213 }  // namespace test
0214 
0215 int main() { return test::TestHitPattern::test(); }