00001 #include "MapsSensor.hh"
00002 #include "TH2F.h"
00003 #include "TFile.h"
00004 #include "TRandom2.h"
00005 #include <iostream>
00006 #include <vector>
00007 #include <cassert>
00008 #include "ToString.h"
00009 #include "Operators.h"
00010 #include <cmath>
00011
00012 int main() {
00013 std::cout << "Welcome to the TestDeadAreas tool\n";
00014
00015 MapsSensor* s0 = new MapsSensor(0, 0);
00016 std::cout << "Making DeadAreas.root\n";
00017 TFile* f = new TFile("DeadAreas.root", "recreate");
00018 TH2F
00019 hits("hDeadAreaHits", "DeadAreaHits", 1000, -5.0, 5.0, 1000, -5.0,
00020 5.0);
00021 TRandom2 rand;
00022
00023 TH2F recoX("recoX", "recoX", 1000, -5.0, 5.0, 1000, -5.0, 5.0);
00024 TH2F recoY("recoY", "recoY", 1000, -5.0, 5.0, 1000, -5.0, 5.0);
00025
00026 std::pair<double, double> xy;
00027 std::pair<int, int> g;
00028 std::pair<double, double> reco;
00029 std::pair<int, int> k;
00030 for (unsigned u(0); u < 10000000; u++) {
00031 xy.first = rand.Uniform(10.0) - 5.0;
00032 xy.second = rand.Uniform(10.0) - 5.0;
00033
00034 if (!s0->isDeadArea(xy)) {
00035 hits.Fill(xy.first, xy.second);
00036 s0->convertPhysicalToHit(xy, g);
00037 s0->convertHitToPhysical(g, reco);
00038 s0->convertPhysicalToHit(reco, k);
00039 assert(k.first == g.first);
00040 assert(k.second == g.second);
00041 recoX.Fill(reco.first, xy.first);
00042 recoY.Fill(reco.second, xy.second);
00043 }
00044 }
00045
00046 std::cout << "Testing standard dead areas...\n";
00047 xy.second = 0.1;
00048 xy.first = -4.425;
00049 assert(!s0->isDeadArea(xy));
00050
00051 xy.first = -4.451;
00052 assert(s0->isDeadArea(xy));
00053
00054 xy.first = -2.11;
00055 assert(s0->isDeadArea(xy));
00056
00057 xy.first = 0.2;
00058 assert(s0->isDeadArea(xy));
00059
00060 xy.first = 0.249;
00061 assert(s0->isDeadArea(xy));
00062
00063 xy.first = 2.5;
00064 assert(s0->isDeadArea(xy));
00065
00066 xy.first = 4.69;
00067 assert(!s0->isDeadArea(xy));
00068
00069 xy.first = 4.71;
00070 assert(s0->isDeadArea(xy));
00071
00072 xy.second = 0.024;
00073 assert(s0->isDeadArea(xy));
00074
00075 xy.first = 3.0;
00076 assert(s0->isDeadArea(xy));
00077
00078 std::cout << "Testing hit to xy conversion method...\n";
00079 std::pair<int, int> h(0, 0);
00080 std::pair<int, int> p(0, 0);
00081 std::cout.precision(4);
00082 s0->convertHitToPhysical(h, xy);
00083 std::cout << h << ":\t" << xy << "\n";
00084 s0->convertPhysicalToHit(xy, p);
00085 std::cout << "\t\t: reconv:\t" << p << "\n";
00086
00087 h.first = 41;
00088 h.second = 84;
00089 s0->convertHitToPhysical(h, xy);
00090 std::cout << h << ":\t" << xy << "\n";
00091 s0->convertPhysicalToHit(xy, p);
00092 std::cout << "\t\t: reconv:\t" << p << "\n";
00093
00094 h.first = 42;
00095 h.second = 84;
00096 s0->convertHitToPhysical(h, xy);
00097 std::cout << h << ":\t" << xy << "\n";
00098 s0->convertPhysicalToHit(xy, p);
00099 std::cout << "\t\t: reconv:\t" << p << "\n";
00100
00101 h.first = 43;
00102 h.second = 85;
00103 s0->convertHitToPhysical(h, xy);
00104 std::cout << h << ":\t" << xy << "\n";
00105 s0->convertPhysicalToHit(xy, p);
00106 std::cout << "\t\t: reconv:\t" << p << "\n";
00107
00108 h.first = 126;
00109 h.second = 85;
00110 s0->convertHitToPhysical(h, xy);
00111 std::cout << h << ":\t" << xy << "\n";
00112
00113 h.second = 167;
00114 s0->convertHitToPhysical(h, xy);
00115 std::cout << h << ":\t" << xy << "\n";
00116 s0->convertPhysicalToHit(xy, p);
00117 std::cout << "\t\t: reconv:\t" << p << "\n";
00118
00119 std::cout << "Testing xy to xy loop...\n";
00120 h.first = 41;
00121 h.second = 35;
00122 s0->convertHitToPhysical(h, xy);
00123 std::cout << "Pre:\t" << h << ",:\t" << xy << "\n";
00124 s0->convertPhysicalToHit(xy, h);
00125 std::cout << "Post:\t" << h << ",:\t" << xy << "\n";
00126 std::cout << "Region:\t" << floor(xy.first/2.35) + 2<< "\n";
00127 xy.first = 0.25;
00128 s0->convertPhysicalToHit(xy, h);
00129 std::cout << "Post2:\t" << h << ",:\t" << xy << "\n";
00130 std::cout << "Region:\t" << floor(xy.first/2.35) + 2<< "\n";
00131
00132 hits.Write();
00133 recoX.Write();
00134 recoY.Write();
00135 f->Write();
00136 f->Close();
00137 std::cout << "Tests pass. Done.\n";
00138 }