All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
include/N3AnaBase/event/track.h
00001 #ifndef __N3AnaBase__track_h
00002 #define __N3AnaBase__track_h 1
00003 
00004 #include <stdexcept>
00005 #include <iostream>
00006 #include <sstream>
00007 #include <string>
00008 #include <list>
00009 #include <cmath>
00010 #include <limits>
00011 #include <algorithm>
00012 
00013 #include <datatools/serialization/serialization.h>
00014 #include <datatools/utils/i_tree_dump.h>
00015 #include <datatools/utils/i_clear.h>
00016 #include <datatools/utils/i_propinit.h>
00017 #include <datatools/utils/properties.h>
00018 
00019 #include <geomtools/utils.h>
00020 
00021 #include <N3AnaBase/utils/geom_utils.h>
00022 #include <N3AnaBase/event/event_utils.h>
00023 #include <N3AnaBase/event/hit_info.h>
00024 
00025 namespace nemo3 {
00026   
00041 
00042   class track : 
00043     public datatools::utils::i_tree_dumpable,
00044     public datatools::utils::i_clear,
00045     public datatools::serialization::i_serializable  
00046   {
00047    
00048   public:
00049 
00051     class i_measurement : public datatools::utils::i_propinit
00052     {
00053     public:
00054 
00055       virtual void do_measurement (track &) = 0;
00056       
00057       track & operator () (track &);
00058 
00059     };
00060     
00062     class i_predicate : public datatools::utils::i_propinit
00063     {
00064     public:
00065       
00066       virtual bool do_test (track &) = 0;
00067       
00068       bool operator () (track &);
00069 
00070     };
00071     
00072   public:
00073 
00074     static const int INVALID_NUMBER = -1;
00075     static const std::string BAD_QUALITY_FLAG;
00076     static const double NO_LENGTH;
00077 
00078   public:
00079 
00081     typedef std::list<gg_hit>        gg_hit_col;
00082 
00083     void measure (i_measurement & measurement_);
00084 
00086     track (int32_t number_ = INVALID_NUMBER);
00087 
00089     virtual ~track ();
00090   
00091   private:
00092 
00093     int32_t                      __number;
00094     datatools::utils::properties __properties;
00095     bool                         __delayed;
00096     gg_hit_info_col              __gg_hits;
00097     gg_hit_col                   __missing_gg_hits;
00098     int                          __curve_type;
00099     geomtools::line_3d           __line_data;
00100     geomtools::helix_3d          __helix_data;
00101     double                       __length;
00102     geomtools::vector_3d         __vertex;
00103     geomtools::vector_3d         __scin_impact;
00104     scin_hit_info                __associated_scin;
00105 
00106   public: 
00107 
00109     const datatools::utils::properties & properties () const;
00110 
00112     const datatools::utils::properties & get_properties_const () const
00113     {
00114       return properties ();
00115     }
00116 
00118     const datatools::utils::properties & get_properties_ro () const
00119     {
00120       return properties ();
00121     }
00122 
00124     datatools::utils::properties & properties ();
00125 
00127     datatools::utils::properties & get_properties ()
00128     {
00129       return properties ();
00130     }
00131 
00133     datatools::utils::properties & get_properties_rw ()
00134     {
00135       return properties ();
00136     }
00137 
00139     int32_t get_number () const;
00140 
00142     void set_number (int32_t = INVALID_NUMBER);
00143 
00145     bool has_curve () const;
00146 
00148     int32_t get_curve_type () const;
00149 
00151     bool is_line () const;
00152 
00154     bool is_helix () const;
00155 
00157     void set_curve_type (int32_t = geom_utils::CURVE_INVALID);
00158 
00160     bool is_delayed () const;
00161 
00163     void set_delayed (bool = true);
00164 
00166     bool is_prompt () const;
00167 
00169     double get_length () const;
00170 
00172     void set_length (double length_);
00173 
00175     void reset_length ();
00176 
00178     bool has_length () const;
00179     
00181     bool has_vertex () const;
00182 
00184     bool has_impact_on_scin () const;
00185 
00187     bool has_scin_impact () const;
00188 
00190     const geomtools::vector_3d & vertex () const;
00191 
00193     const geomtools::vector_3d & get_vertex () const;
00194 
00196     void set_vertex (const geomtools::vector_3d &);
00197 
00199     void reset_vertex ();
00200 
00202     const geomtools::vector_3d & scin_impact () const;
00203 
00205     const geomtools::vector_3d & get_scin_impact () const;
00206     
00208     void set_scin_impact (const geomtools::vector_3d &);
00209 
00211     void reset_scin_impact ();
00212 
00214     const scin_hit_info & associated_scin () const;
00215 
00217     const scin_hit_info & get_associated_scin () const;
00218 
00220     void set_associated_scin (const scin_hit_info &);
00221 
00223     bool has_associated_scin () const;
00224 
00226     void reset_associated_scin ();
00227 
00229     void set_line_data (const geomtools::line_3d &);
00230 
00232     const geomtools::line_3d & get_line_data () const;
00233 
00235     geomtools::line_3d & get_line_data ();
00236 
00238     void set_helix_data (const geomtools::helix_3d &);
00239 
00241     const geomtools::helix_3d & get_helix_data () const;
00242 
00244     geomtools::helix_3d & get_helix_data ();
00245 
00247     geomtools::vector_3d get_first_point () const;
00248 
00250     geomtools::vector_3d get_last_point () const;
00251 
00253     const gg_hit_col & missing_gg_hits () const;
00254 
00256     gg_hit_col & missing_gg_hits ();
00257 
00259     const gg_hit_info_col & gg_hits () const;
00260     
00262     gg_hit_info_col & gg_hits ();
00263 
00265     int get_number_of_gg_hits () const
00266     {
00267       return __gg_hits.size ();
00268     }
00269 
00271     int get_number_of_missing_gg_hits () const
00272     {
00273       return __missing_gg_hits.size ();
00274     }
00275 
00277     gg_hit_info_col::iterator gg_hits_begin ()
00278     {
00279       return __gg_hits.begin ();
00280     }
00281 
00283     gg_hit_info_col::iterator gg_hits_end ()
00284     {
00285       return __gg_hits.end ();
00286     }
00287 
00289     void add_gg_hit (const gg_hit & hit_, bool close_to_track_ = false);
00290 
00292     void add_missing_gg_hit (const gg_hit & hit_);
00293 
00295     const gg_hit & get_gg_hit (int i_) const;
00296     
00298     gg_hit & get_gg_hit_no_const (int i_);
00299 
00301     const gg_hit & get_missing_gg_hit (int i_) const;
00302 
00304     void clear_missing_gg_hits ();
00305 
00307     void clear_gg_hits ();
00308 
00310     void clear_curve ();
00311 
00313     void clear_fit ();
00314 
00315   public: 
00316 
00318     virtual void clear ();
00319 
00321     virtual void tree_dump (std::ostream & out_         = std::clog, 
00322                             const std::string & title_  = "",
00323                             const std::string & indent_ = "",
00324                             bool inherit_               = false) const;
00325     
00327     void dump () const
00328     {
00329       tree_dump ();
00330     }
00331     
00333     static const std::string SERIAL_TAG;
00334     
00336     virtual const std::string & get_serial_tag () const;
00337     
00338   private:
00339 
00341     friend class boost::serialization::access; 
00342 
00344     template<class Archive>
00345     void serialize (Archive            & ar_, 
00346                     const unsigned int version_) 
00347     {
00348       ar_ & boost::serialization::make_nvp ("number",      __number);
00349       ar_ & boost::serialization::make_nvp ("properties",  __properties);
00350       ar_ & boost::serialization::make_nvp ("delayed",     __delayed);
00351       ar_ & boost::serialization::make_nvp ("gg_hits",     __gg_hits);
00352       ar_ & boost::serialization::make_nvp ("missing_gg_hits",    __missing_gg_hits);
00353       ar_ & boost::serialization::make_nvp ("length",      __length);
00354       ar_ & boost::serialization::make_nvp ("vertex",      __vertex);
00355       ar_ & boost::serialization::make_nvp ("scin_impact", __scin_impact);
00356       ar_ & boost::serialization::make_nvp ("associated_scin", __associated_scin);
00357       ar_ & boost::serialization::make_nvp ("curve_type", __curve_type);
00358       if (__curve_type == geom_utils::CURVE_HELIX)
00359         {
00360           ar_ & boost::serialization::make_nvp ("helix_data", __helix_data);
00361         }
00362       if (__curve_type == geom_utils::CURVE_LINE)
00363         {
00364           ar_ & boost::serialization::make_nvp ("line_data", __line_data);
00365         }
00366     }
00367 
00368   public:
00369 
00371     void set_helix_t1_t2 ();
00372 
00374     bool validate_gg_hit (const gg_hit & hit_, bool delayed_ = false) const;
00375 
00377     int compute_helix_chi_square_z (const geomtools::helix_3d & hd_, 
00378                                     double & chi2_, 
00379                                     unsigned int & n_) const;
00380   };
00381 
00383   class track_has_number 
00384     : public std::unary_function<track, bool>
00385   {
00386   private:
00387     int __number;
00388   public:
00389     explicit track_has_number (int n_)
00390     {
00391       __number = n_;
00392     }
00393 
00394     bool operator () (const track & track_) const
00395     {
00396       return (track_.get_number () == __number);
00397     }
00398   };
00399 
00401   class track_is_prompt 
00402     : public std::unary_function<track, bool>
00403   {
00404   public:
00405     explicit track_is_prompt () {} 
00406     bool operator () (const track & track_) const
00407     {
00408       return (track_.is_prompt ());
00409     }
00410   };
00411 
00413   class track_is_delayed 
00414     : public std::unary_function<track, bool>
00415   {
00416   public:
00417     explicit track_is_delayed () {} 
00418     bool operator () (const track & track_) const
00419     {
00420       return (track_.is_delayed ());
00421     }
00422   };
00423 
00425   class track_has_flag 
00426     : public std::unary_function<track, bool>
00427   {
00428   private:
00429     std::string __flag_name;
00430   public:
00431     explicit track_has_flag (const std::string & flag_name_)
00432     {
00433       __flag_name = flag_name_;
00434     }
00435 
00436     bool operator () (const track & track_) const
00437     {
00438       return (track_.properties ().has_flag (__flag_name));
00439     }
00440   };
00441 
00442 } // end of namespace nemo3
00443 
00444 #endif // __N3AnaBase__track_h
00445 
00446 // end of track.h