tests/src/RealignCosmics.cpp

Go to the documentation of this file.
00001 #include "MapsTrackManager.hh"
00002 #include "MapsTrack.hh"
00003 #include "MapsSensor.hh"
00004 #include "MapsException.hh"
00005 #include <cmath>
00006 #include <vector>
00007 #include "TRandom2.h"
00008 #include "TFile.h"
00009 #include "TH1F.h"
00010 #include "TH2F.h"
00011 int main(int argc, const char **argv) {
00012 
00013         for (int d(0); d < argc; d++) {
00014                 std::cout << argv[d] << "\n";
00015         }
00016         if (argc != 3) {
00017                 std::cout << "Usage: Rewriter <input file> <outputfile>\n";
00018                 return 0;
00019         }
00020 
00021         MapsTrackManager mtm2;
00022         std::cout << "Recreating from root file...\n";
00023         char input[100];
00024         strcpy(input, argv[1]);
00025 
00026         mtm2.recreateFromRootFile(input);
00027         std::cout << "Rewriting to new root file...\n";
00028         std::vector<MapsSensor*> s(mtm2.getSensors());
00029         MapsSensor* left = 0;
00030         MapsSensor* right = 0;
00031         MapsSensor* m1 = 0;
00032         MapsSensor* m2 = 0;
00033         for (std::vector<MapsSensor*>::iterator it = s.begin(); it != s.end(); ++it) {
00034                 MapsSensor* sensor = *it;
00035                 if (sensor->id() == 2) {
00036                         left = sensor;
00037 
00038                 }
00039                 if (sensor->id() == 7) {
00040                         right = sensor;
00041                         //sensor->setPhi(1.5 * 3.14159265358979323846);
00042                 }
00043                 if (sensor->id() == 6) {
00044                         m1 = sensor;
00045                         //sensor->setPhi(0.5 * 3.14159265358979323846);
00046                 }
00047                 if (sensor->id() == 8) {
00048                         m2 = sensor;
00049                 }
00050 
00051         }
00052 
00053         mtm2.setRequiredLeftSensor(left);
00054         mtm2.setRequiredRightSensor(right);
00055         MapsTrackManager mtm3;
00056         mtm3.setSensors(s);
00057 
00058         std::vector<MapsTrack*>& tracks = mtm2.getTracks();
00059         for (std::vector<MapsTrack*>::iterator it = tracks.begin(); it
00060                         != tracks.end(); it++) {
00061                 MapsTrack* t = *it;
00062                 t->eraseGlobalHits();
00063                 std::pair<double, double> error(0.25, 0.25);
00064                 t->setTrackError(error);
00065                 MapsTrack threeHit;
00066                 t->make3HitTrack(threeHit);
00067                 if (threeHit.chiSqProb(0) > 0.05 && threeHit.chiSqProb(1) > 0.05) {
00068                         diagnose(std::cout, *t);
00069 
00070                         if (t->fourthSensor()->isDeadArea(t->findXYPrediction(t->fourthSensor()->zPosition())) && t->getHits().size() == 3) {
00071                                 std::cout << "Three hit prediction falls in dead area.\n";
00072                         } else {
00073                                 mtm3.addTrack(t);
00074                         }
00075                 }
00076                 t->tellSensorsOfResiduals(left, right);
00077         }
00078 
00079         TH2F s1, s2;
00080         TFile* f = new TFile("CosmicAlignment.root", "recreate");
00081         m1->getResidualXYPlot(s1);
00082         m2->getResidualXYPlot(s2);
00083         s1.Write();
00084         s2.Write();
00085         f->Write();
00086         f->Close();
00087         char output[100];
00088         strcpy(output, argv[2]);
00089         //mtm2.exportToRootFile(output);
00090         mtm3.exportToRootFile("GoodCosmicTracks.root");
00091         std::cout << "Done.\n";
00092         return 0;
00093 }
00094 

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