inc/MapsTrack.hh

Go to the documentation of this file.
00001 #ifndef MAPSTRACK_HH_
00002 #define MAPSTRACK_HH_
00003 #include <map>
00004 #include <iostream>
00005 #include <vector>
00006 #include "ToString.h"
00007 #include "MapsSensor.hh"
00008 #include "MapsException.hh"
00009 #include "Operators.h"
00010 
00011 /** MapsTrack.hh
00012  * 
00013  * Jamie Ballin, Imperial College London
00014  *              February 2008
00015  * 
00016  * 
00017  * A track is defined by at least 3 hits in 3 sensors. Only one hit per sensor
00018  * is allowed. At most it is defined by 4 hits in 4 sensors (though only slight
00019  * revisions would be required to change this).
00020  * 
00021  * Note that MapsTracks are lazy: they do not tell each of the assosicated MapsSensors of
00022  * their residuals unless you explicitly tell them to do so. Telling sensors whether they
00023  * have been efficient or not is entirely up to the user; see examples in tests/, especially
00024  * ExtractEfficiencies.cpp code.
00025  * 
00026  */
00027 class MapsTrack {
00028 public:
00029         typedef std::pair<int, int> coord;
00030         typedef std::pair<double, double> physXY;
00031 
00032         MapsTrack() :
00033                 myT(0), myFourthThresh(0) {
00034         }
00035         ;
00036 
00037         /** Constructor */
00038         MapsTrack(unsigned bx, std::map<MapsSensor*, MapsTrack::coord> hits,
00039                         MapsSensor* fourthSensor = 0, unsigned fourthThreshold = 0) :
00040                 myT(bx), myFourthThresh(fourthThreshold),
00041                                 myFourthSensor(fourthSensor), myHits(hits), myTrackError(std::pair<double, double>(0.1, 0.1)), myPixelPitch(0.05) {
00042         }
00043         ;
00044 
00045         virtual ~MapsTrack();
00046 
00047         /** the timestamp of this track */
00048         inline unsigned timeStamp() const {
00049                 return myT;
00050         }
00051         ;
00052         /** returns a map of hits making the track */
00053         const std::map<MapsSensor*, coord>& getHits();
00054 
00055         /** The standard deviation of the hits in x */
00056         double sigmaX() const;
00057 
00058         /** The standard deviation of the hits in y */
00059         double sigmaY() const;
00060 
00061         /** Returns the arithmetic mean of the x hits */
00062         double meanX() const;
00063 
00064         /** Returns the arithmetic mean of the y hits */
00065         double meanY() const;
00066 
00067         inline double pixelPitch() const {
00068                 return myPixelPitch;
00069         }
00070         ;
00071 
00072         inline std::pair<double, double> trackError() const {
00073                 return myTrackError;
00074         }
00075         ;
00076 
00077         /**
00078          * Use this to set the size of the pixel to anything other than 0.05 mm.
00079          */
00080         void setPixelPitch(const double& pitch);
00081 
00082         /**
00083          * Use this to set the sigma parameter used in the chi squared computations.
00084          */
00085         void setTrackError(const std::pair<double, double>& error);
00086 
00087         /** 
00088          * Getter to tell you the fourth sensor for this track 
00089          */
00090         MapsSensor* fourthSensor() const;
00091 
00092         /**
00093          * Getter for the fourth sensor threshold.
00094          */
00095         inline unsigned fourthSensorThresh() const {
00096                 return myFourthThresh;
00097         }
00098         ;
00099         /**
00100          * Sets/overwrites the fourth sensor's threshold.
00101          */
00102         void setFourthSensorThresh(const unsigned& threshold);
00103 
00104         /**
00105          * A track is defined by at least 3 hits; this returns the first sensor 
00106          * not found in the supplied list, and zero if all were found.
00107          */
00108         MapsSensor* missingSensor(std::vector<MapsSensor*> sensors) const;
00109 
00110         /**
00111          * Determines the residual i.t.o. the difference between the real hit in sensor s 
00112          * and the track defined by its left and right extrapolation points
00113          * 
00114          * Throws an exception if the track doesn't have a hit for the supplied sensor.
00115          */
00116         std::pair<double, double> simpleResidual(MapsSensor* s) const
00117                         throw(MapsException);
00118 
00119         /**
00120          * Convenience method for calling simpleResidual() for all sensors :-| 
00121          */
00122         std::map<MapsSensor*, std::pair<double, double> > allResiduals();
00123 
00124         /**
00125          * Sets each sensor's residuals based on this track.
00126          */
00127         void tellSensorsOfResiduals();
00128 
00129         /**
00130          * Sets sensor residuals conditionally: this allows you to define a fixed coordinate
00131          * system. Usually the left most and right most sensors are set as the fixed references.
00132          */
00133         void tellSensorsOfResiduals(const MapsSensor* const requiredLeft,
00134                         const MapsSensor* const requiredRight);
00135 
00136         /**
00137          * Sets each sensor's efficiency hits etc. based on this track.
00138          */
00139         void tellSensorsOfHits();
00140 
00141         /** 
00142          * Define the theta to be the angle in radians relative to a 
00143          * straight (non-skew) line through the sensors. This uses the complete track fit.
00144          */
00145         double theta() const;
00146 
00147         /**
00148          * Uses the Root API to evaluate whether the observed chi2 for a 
00149          * "correct model" is more than the chi2 of the track
00150          */
00151         double chiSqProb(const unsigned& dimension) const;
00152 
00153         /**
00154          * Overwrites/sets this track's hits with those supplied.
00155          */
00156         void setHits(std::map<MapsSensor*, coord> hits);
00157 
00158         /**
00159          * One line description of the track.
00160          */
00161         friend std::ostream& operator<<(std::ostream& s, const MapsTrack& mt);
00162 
00163         /**
00164          * Prints a complete description of this track to the specfified output stream
00165          */
00166         friend std::ostream& diagnose(std::ostream& s, const MapsTrack& mt);
00167 
00168         /**
00169          * Prints the hits sensor by sensor.
00170          */
00171         std::ostream& printCoords(std::ostream& s) const;
00172         
00173 
00174         /**
00175          * Returns the sensor that should be used as the left sensor in a 
00176          * track extrapolation to the supplied sensor
00177          */
00178         MapsSensor* leftExtrapPoint(MapsSensor*) const;
00179 
00180         /**
00181          * Returns the sensor that should be used as the right sensor in a 
00182          * track extrapolation to the supplied sensor
00183          */
00184         MapsSensor* rightExtrapPoint(MapsSensor*) const;
00185 
00186         /**
00187          * Determines the 'p' coefficients for this track, as defined by
00188          *      chi^2 = sum_i [x_i - (p_0 +z_i*p_1)]^2/sigma_i^2
00189          * where i is the layer index and the assumption
00190          *      sigma_i -> sigma
00191          * is applied.
00192          * 
00193          * Dimension:   = 0 for x
00194          *                              = 1 for y
00195          */
00196         std::pair<double, double> fitParameters(const unsigned& dimension) const;
00197 
00198         /**
00199          * Evaluates the chi squared based on the full track fit.
00200          * 
00201          * Dimension:   = 0 for x
00202          *                              = 1 for y
00203          */
00204         double chiSq(const unsigned& dimension) const;
00205 
00206         /**
00207          * Makes a three hit track from tracks with four hits, ignoring the ''fourth sensor''.
00208          * Makes a copy of this track if we only have 3 hits anyway.
00209          */
00210         void make3HitTrack(MapsTrack& mt);
00211 
00212         /**
00213          * Evaluates the difference in pixel coordinates between the extrapolated three hit track 
00214          * and the fourth sensor's hit. You supply the answer :-) Returns something other than zero 
00215          * if there was no fourth hit for comparison.
00216          */
00217         unsigned getFourthHitResidual(const MapsTrack& threeHitTrack,
00218                         std::pair<double, double>& answer);
00219 
00220         /**
00221          * Uses the supplied track's fit to extrapolate to the supplied z position.
00222          */
00223         std::pair<double, double> findXYPrediction(const double& zpos) const;
00224         
00225         const std::map<MapsSensor*, physXY >& getGlobalHits() const;
00226         
00227         void eraseGlobalHits();
00228 
00229 protected:
00230 
00231         MapsTrack& operator=(MapsTrack& mt) {
00232                 return *this;
00233         }
00234         
00235 
00236 private:
00237 
00238         //returns the sensor with a hit that is more "left" than any other
00239         MapsSensor* leftSensor() const;
00240         //and more "right" than any other
00241         MapsSensor* rightSensor() const;
00242 
00243         MapsTrack(MapsTrack& mt);
00244         
00245         unsigned myT;
00246         unsigned myFourthThresh;
00247         MapsSensor* myFourthSensor;
00248         std::map<MapsSensor*, coord> myHits;
00249         
00250         //this is the same as myHits, but with each coord converted to the global system
00251         //access it with getPhysicalHits()
00252         mutable std::map<MapsSensor*, physXY > myGlobalHits;
00253 
00254         std::pair<double, double> myTrackError;
00255         double myPixelPitch;
00256 
00257         //we don't want to tell the sensors twice of these things despite what application code may do
00258         bool myToldSensorsResids;
00259         bool myToldSensorsHits;
00260 
00261 };
00262 
00263 //std::ostream& operator<<(std::ostream& s, const MapsTrack::coord& c);
00264 
00265 //std::ostream& operator<<(std::ostream& s, const std::pair<double, double>& p);
00266 
00267 std::ostream& operator<<(std::ostream& s, const MapsTrack& mt);
00268 
00269 std::ostream& diagnose(std::ostream& s, const MapsTrack& mt);
00270 
00271 //#include "MapsTrack.cc"
00272 #endif /**MAPSTRACK_HH_*/
00273 

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