Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:54:53

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