tests/src/RotationTest.cpp

Go to the documentation of this file.
00001 #include "MapsSensor.hh"
00002 #include <iostream>
00003 #include <cmath>
00004 #include <vector>
00005 #include <algorithm>
00006 #include <ostream>
00007 #include <iterator>
00008 #include <functional>
00009 #include "TFile.h"
00010 #include "TH2F.h"
00011 #include "TRandom2.h"
00012 
00013 void printSensor(MapsSensor* s) {
00014         std::cout << *s << "\n";
00015 }
00016 
00017 void isDead(MapsSensor* s, std::pair<double, double> input) {
00018         if (s->isDeadArea(input))
00019                 std::cout << "Sensor " << s->id() << " reports area dead.\n";
00020         else
00021                 std::cout << "Sensor " << s->id() << " reports area alive.\n";
00022 }
00023 
00024 struct testArea :
00025         public std::binary_function<MapsSensor*, std::pair<double, double>, bool> {
00026         bool operator()(MapsSensor* s, std::pair<double, double> p) const {
00027                 //std::cout << *s << ":\t dead at " << p << "?\t";
00028                 if (s->isDeadArea(p)) {
00029                         //std::cout << "Yes.\n";
00030                         s->registerTrackMiss(0, p, 0);
00031                 }
00032                 //else
00033                 //std::cout << "No.\n";
00034                 return s->isDeadArea(p);
00035         }
00036 };
00037 
00038 int main() {
00039         std::cout << "Wilkommen to ze RotationTest\n";
00040         double pi = 3.14159265358979323846;
00041         std::vector<MapsSensor*> sensors;
00042         MapsSensor* s0 = new MapsSensor(0, 0, 0);
00043         MapsSensor* s90 = new MapsSensor(1, 10, pi/2.0);
00044         MapsSensor* s180 = new MapsSensor(2, 20, pi);
00045         MapsSensor* s270 = new MapsSensor(3, 30, 1.5*pi);
00046         sensors.push_back(s0);
00047         sensors.push_back(s90);
00048         sensors.push_back(s180);
00049         sensors.push_back(s270);
00050         
00051         std::pair<int, int> testC1(167, 0);
00052         std::cout << "Each sensor takes " << testC1 << " to...\n";
00053         
00054         for(std::vector<MapsSensor*>::iterator it = sensors.begin(); it != sensors.end(); ++it) {
00055                 std::pair<double, double> transform;
00056                 MapsSensor* s = *it;
00057                 s->convertHitToPhysical(testC1, transform);
00058                 std::cout << *s << "\t ---> " << transform << "\n";
00059         }
00060 
00061         //test zero degree case first
00062 
00063         std::cout << "Testing zero degree case...\n";
00064         std::pair<double, double> input(2.40, 3.0);
00065         bool isDead0 = s0->isDeadArea(input);
00066         std::cout << *s0 << " reports " << input<< " is dead?\t" << isDead0 << "\n";
00067 
00068         std::for_each(sensors.begin(), sensors.end(), printSensor);
00069         std::for_each(sensors.begin(), sensors.end(), std::mem_fun(&MapsSensor::id));
00070 
00071         int howMany = std::count_if(sensors.begin(), sensors.end(), std::bind2nd(
00072                         testArea(), input));
00073 
00074         std::cout << "Hoy many have sensors report dead areas for that hit?:\t"
00075                         << howMany << "\n";
00076 
00077         TFile* f = new TFile("RotationTest.root", "recreate");
00078         TH2F hExclusion("hExclusion", "Mutual exclusion areas", 1000, -5.0, 5.0,
00079                         1000, -5.0, 5.0);
00080         TRandom2 rand;
00081         std::pair<double, double> place;
00082         for (unsigned u(0); u < 100000; ++u) {
00083                 place.first = rand.Uniform(10.0) - 5.0;
00084                 place.second = rand.Uniform(10.0) - 5.0;
00085                 int deathCount = std::count_if(sensors.begin(), sensors.end(),
00086                                 std::bind2nd(testArea(), place));
00087                 if (deathCount > 0)
00088                         hExclusion.Fill(place.first, place.second);
00089 
00090         }
00091         TH2F s0x("hS0XMapping", "hS0XMapping", 168, 0, 168, 1000, -5.0, 5.0);
00092         TH2F s90x("hS90XMapping", "hS90XMapping", 168, 0, 168, 1000, -5.0, 5.0);
00093         TH2F s0y("hS0YMapping", "hS0YMapping", 168, 0, 168, 1000, -5.0, 5.0);
00094         TH2F s90y("hS90YMapping", "hS90YMapping", 168, 0, 168, 1000, -5.0, 5.0);
00095         for (unsigned k(0); k < 168; ++k) {
00096                 std::pair<int, int> h(k, k);
00097                 std::pair<double, double> p;
00098                 s0->convertHitToPhysical(h, p);
00099                 s0x.Fill(h.first, p.first);
00100                 s0y.Fill(h.second, p.second);
00101                 s90->convertHitToPhysical(h, p);
00102                 s90x.Fill(h.first, p.first);
00103                 s90y.Fill(h.second, p.second);
00104         }
00105         s0y.Write();
00106         s90y.Write();
00107         s0x.Write();
00108         s90x.Write();
00109 
00110         TH2F a, b, c, d;
00111         s0->getInefficiencyXYPlot(a, true);
00112         s90->getInefficiencyXYPlot(b, true);
00113         s180->getInefficiencyXYPlot(c, true);
00114         s270->getInefficiencyXYPlot(d, true);
00115         a.Write();
00116         b.Write();
00117         c.Write();
00118         d.Write();
00119         hExclusion.Write();
00120         f->Write();
00121         f->Close();
00122 
00123 }
00124 

Generated on Wed Mar 19 17:47:58 2008 for MapsTracks by  doxygen 1.5.2