tests/src/ExtractEfficienciesCosmics.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 <algorithm>
00007 #include <iostream>
00008 #include "TRandom2.h"
00009 #include "TFile.h"
00010 #include "TH1F.h"
00011 #include "Operators.h"
00012 
00013 int main(int argc, const char **argv) {
00014 
00015         if (argc != 3) {
00016                 std::cout << "Usage: ExtractEfficiencies <input file> <outputfile>\n";
00017                 return 0;
00018         }
00019         std::cout << "Welcome to ExtractEfficiencies...\n";
00020         
00021         //Define chi squared probability cuts
00022         double cut(0.05);
00023         //Define errors for chi squared calculation
00024         std::pair<double, double> error(0.1, 0.1);
00025         //std::pair<double, double> error(0.026, 0.02);
00026         std::cout << "\tUsing cuts for probability of: \t" << cut << "\n";
00027         std::cout << "\tError parameters: \t" << error << "\n";
00028         
00029         std::cout << "\tRecreating from root file...\n";
00030         char input[100];
00031         strcpy(input, argv[1]);
00032         
00033         //Create a maps track manager to recreate the tracks
00034         MapsTrackManager mtm2;
00035         //Reinitialise all the tracks and sensors in mtm2
00036         mtm2.recreateFromRootFile(input);
00037 
00038         std::vector<MapsTrack*>& tracks = mtm2.getTracks();
00039 
00040         //count efficient and inefficient frequency
00041         unsigned ineff(0), eff(0), deadArs(0);
00042         unsigned candidateTracks(0);
00043 
00044         for (std::vector<MapsTrack*>::iterator it = tracks.begin(); it
00045                         != tracks.end(); it++) {
00046                 MapsTrack* t = *it;
00047 
00048                 //this is not obligatory, but highly advised!
00049                 t->setTrackError(error);
00050                 
00051                 //see if we have a good three hit track first: for tracks which are just three hits anyway
00052                 //t3 will be a copy of t
00053                 MapsTrack t3;
00054                 t->make3HitTrack(t3);
00055                 t3.setTrackError(error);
00056 
00057                 //evaluate quality of the 3 hit track
00058                 if (t3.chiSqProb(0) > cut && t3.chiSqProb(1) > cut) {
00059                         //it's a real track then
00060                         candidateTracks++;
00061 
00062                         //get the original track's fourth sensor
00063                         MapsSensor* s4 = t->fourthSensor();
00064 
00065                         //pose the ultimate question...
00066                         std::pair<double, double> resid;
00067                         unsigned fourthConfirm = t->getFourthHitResidual(t3, resid);
00068 
00069                         if (fourthConfirm == 0 && t->chiSqProb(0) > cut && t->chiSqProb(1)
00070                                         > cut) {
00071                                 //fourth sensor was efficient
00072                                 //one could also cut on the residual value, if you wanted
00073                                 s4->registerTrackConfirm(t->fourthSensorThresh(), t->getHits().at(s4), t->timeStamp(), resid);
00074                                 eff++;
00075                         } else {
00076                                 //fourth sensor wasn't efficien!
00077                                 //but only if it could have been
00078                                 if(!s4->isDeadArea(t->findXYPrediction(s4->zPosition()))) {
00079                                         s4->registerTrackMiss(t->fourthSensorThresh(), t->findXYPrediction(s4->zPosition()), t->timeStamp());
00080                                         ineff++;
00081                                 } else {
00082                                         ++deadArs;
00083                                 }
00084                         }
00085 
00086                 }
00087         }
00088         
00089         //All that follows is housekeeping and plot extraction...
00090         
00091         char output[100];
00092         strcpy(output, argv[2]);
00093         TFile f(output, "recreate");
00094 
00095         //iterate over sensors to extract efficiency plots      
00096         std::vector<MapsSensor*>& sensors = mtm2.getSensors();
00097         for (std::vector<MapsSensor*>::iterator it = sensors.begin(); it
00098                         != sensors.end(); it++) {
00099                 MapsSensor* s = *it;
00100                 TH1F h;
00101                 TH1F g, k;
00102                 TH2F j, l, m, n;
00103                 s->getEfficiencyCurve(h, 20, 0, 200);
00104                 s->getEfficiencyTimestamps(g);
00105                 s->getEfficiencyXYPlot(j);
00106                 s->getInefficiencyXYPlot(m, true);
00107                 s->getInefficiencyTimestamps(k);
00108                 s->getFourthHitResidualPlot(l);
00109                 s->getEfficiencyByGroup(n);
00110                 h.Write();
00111                 g.Write();
00112                 j.Write();
00113                 k.Write();
00114                 l.Write();
00115                 m.Write();
00116                 n.Write();
00117                 std::cout.precision(4);
00118                 std::cout << "\n" << *s << ": Efficiency: \n";
00119                 for (unsigned tMult(7); tMult < 20; tMult++) {
00120                         double efficiency = s->getEfficiency(tMult*10);
00121                         if (efficiency > -0.9)
00122                                 std::cout << "\t Thresh: " << tMult*10 << "\t: " << efficiency
00123                                                 * 100 << "\n";
00124                 }
00125         }
00126 
00127         //save plots to disk
00128         std::cout << "\tWriting root file: " << output << "\n";
00129         f.Write();
00130         f.Close();
00131 
00132         //close up shop
00133         std::cout << "ExtractEfficiencies: summary:\n";
00134         std::cout << "\tTotal candidate tracks:\t" << candidateTracks << "\n";
00135         std::cout << "\tEfficient hits:\t" << eff << "\n";
00136         std::cout << "\tInefficient hits:\t" << ineff << "\n";
00137         std::cout << "\tDead area intersections:\t" << deadArs << "\n";
00138 
00139         std::cout << "Have a nice day.\n";
00140 
00141 }
00142 

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