#include "MapsSensor.hh" #include "TH2F.h" #include "TFile.h" #include "TRandom2.h" #include #include #include #include "ToString.h" #include "Operators.h" #include int main() { std::cout << "Welcome to the TestDeadAreas tool\n"; MapsSensor* s0 = new MapsSensor(0, 0); std::cout << "Making DeadAreas.root\n"; TFile* f = new TFile("DeadAreas.root", "recreate"); TH2F hits("hDeadAreaHits", "DeadAreaHits", 1000, -5.0, 5.0, 1000, -5.0, 5.0); TRandom2 rand; TH2F recoX("recoX", "recoX", 1000, -5.0, 5.0, 1000, -5.0, 5.0); TH2F recoY("recoY", "recoY", 1000, -5.0, 5.0, 1000, -5.0, 5.0); std::pair xy; std::pair g; std::pair reco; std::pair k; for (unsigned u(0); u < 10000000; u++) { xy.first = rand.Uniform(10.0) - 5.0; xy.second = rand.Uniform(10.0) - 5.0; if (!s0->isDeadArea(xy)) { hits.Fill(xy.first, xy.second); s0->convertPhysicalToHit(xy, g); s0->convertHitToPhysical(g, reco); s0->convertPhysicalToHit(reco, k); assert(k.first == g.first); assert(k.second == g.second); recoX.Fill(reco.first, xy.first); recoY.Fill(reco.second, xy.second); } } std::cout << "Testing standard dead areas...\n"; xy.second = 0.1; xy.first = -4.425; assert(!s0->isDeadArea(xy)); xy.first = -4.451; assert(s0->isDeadArea(xy)); xy.first = -2.11; assert(s0->isDeadArea(xy)); xy.first = 0.2; assert(s0->isDeadArea(xy)); xy.first = 0.249; assert(s0->isDeadArea(xy)); xy.first = 2.5; assert(s0->isDeadArea(xy)); xy.first = 4.69; assert(!s0->isDeadArea(xy)); xy.first = 4.71; assert(s0->isDeadArea(xy)); xy.second = 0.024; assert(s0->isDeadArea(xy)); xy.first = 3.0; assert(s0->isDeadArea(xy)); std::cout << "Testing hit to xy conversion method...\n"; std::pair h(0, 0); std::pair p(0, 0); std::cout.precision(4); s0->convertHitToPhysical(h, xy); std::cout << h << ":\t" << xy << "\n"; s0->convertPhysicalToHit(xy, p); std::cout << "\t\t: reconv:\t" << p << "\n"; h.first = 41; h.second = 84; s0->convertHitToPhysical(h, xy); std::cout << h << ":\t" << xy << "\n"; s0->convertPhysicalToHit(xy, p); std::cout << "\t\t: reconv:\t" << p << "\n"; h.first = 42; h.second = 84; s0->convertHitToPhysical(h, xy); std::cout << h << ":\t" << xy << "\n"; s0->convertPhysicalToHit(xy, p); std::cout << "\t\t: reconv:\t" << p << "\n"; h.first = 43; h.second = 85; s0->convertHitToPhysical(h, xy); std::cout << h << ":\t" << xy << "\n"; s0->convertPhysicalToHit(xy, p); std::cout << "\t\t: reconv:\t" << p << "\n"; h.first = 126; h.second = 85; s0->convertHitToPhysical(h, xy); std::cout << h << ":\t" << xy << "\n"; h.second = 167; s0->convertHitToPhysical(h, xy); std::cout << h << ":\t" << xy << "\n"; s0->convertPhysicalToHit(xy, p); std::cout << "\t\t: reconv:\t" << p << "\n"; std::cout << "Testing xy to xy loop...\n"; h.first = 41; h.second = 35; s0->convertHitToPhysical(h, xy); std::cout << "Pre:\t" << h << ",:\t" << xy << "\n"; s0->convertPhysicalToHit(xy, h); std::cout << "Post:\t" << h << ",:\t" << xy << "\n"; std::cout << "Region:\t" << floor(xy.first/2.35) + 2<< "\n"; xy.first = 0.25; s0->convertPhysicalToHit(xy, h); std::cout << "Post2:\t" << h << ",:\t" << xy << "\n"; std::cout << "Region:\t" << floor(xy.first/2.35) + 2<< "\n"; hits.Write(); recoX.Write(); recoY.Write(); f->Write(); f->Close(); std::cout << "Tests pass. Done.\n"; }