Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/tools/sg/h2plot is written in an unsupported language. File is not indexed.

0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003 
0004 #ifndef tools_sg_h2plot
0005 #define tools_sg_h2plot
0006 
0007 // Connexion tools/histo to sg/plotter.
0008 
0009 // Inheritance :
0010 #include "plottables"
0011 
0012 #include "../histo/h1d"
0013 #include "../histo/h2d"
0014 #include "../histo/p1d"
0015 #include "../histo/p2d"
0016 
0017 #include "../tokenize"
0018 #include "../num2s"
0019 
0020 namespace tools {
0021 namespace sg {
0022 
0023 class h1d2plot : public virtual bins1D {
0024 public:
0025   TOOLS_SCLASS(tools::sg::h1d2plot)
0026 public:
0027   virtual void* cast(const std::string& a_class) const {
0028     if(void* p = cmp_cast<h1d2plot>(this,a_class)) {return p;}
0029     return bins1D::cast(a_class);
0030   }
0031 public: //plottable
0032   virtual plottable* copy() const {return new h1d2plot(*this);}
0033   virtual bool is_valid() const {return true;}
0034   virtual const std::string& name() const {return m_name;}
0035   virtual void set_name(const std::string& a_s) {m_name = a_s;}
0036 
0037   virtual const std::string& title() const {return m_data.title();}
0038   virtual const std::string& legend() const {return m_legend;}
0039   virtual void set_legend(const std::string& a_s) {m_legend = a_s;}
0040 
0041   virtual void infos(const std::string& a_opts,std::string& a_sinfos) const {
0042     a_sinfos.clear();
0043     std::string f_lf("\n");
0044     std::vector<std::string> ws;
0045     words(a_opts," ",false,ws);
0046     std::vector<std::string>::const_iterator it;
0047 
0048     for(it=ws.begin();it!=ws.end();++it) {
0049       if(((*it)=="name") && m_name.size()) {
0050         if(a_sinfos.size()) a_sinfos += f_lf;
0051         a_sinfos += "Name";
0052         a_sinfos += f_lf;
0053         a_sinfos += m_name;
0054 
0055       } else if((*it)=="entries") {
0056         if(a_sinfos.size()) a_sinfos += f_lf;
0057         a_sinfos += "Entries";
0058         a_sinfos += f_lf;
0059         if(!numas<unsigned int>(m_data.all_entries(),a_sinfos)){}
0060 
0061       } else if((*it)=="mean") {
0062         if(a_sinfos.size()) a_sinfos += f_lf;
0063         a_sinfos += "Mean";
0064         a_sinfos += f_lf;
0065         if(!numas<double>(m_data.mean(),a_sinfos)) {}
0066 
0067       } else if((*it)=="rms") {
0068         if(a_sinfos.size()) a_sinfos += f_lf;
0069         a_sinfos += "RMS";
0070         a_sinfos += f_lf;
0071         if(!numas<double>(m_data.rms(),a_sinfos)) {}
0072 
0073       } else if((*it)=="underflow") {
0074         if(a_sinfos.size()) a_sinfos += f_lf;
0075         a_sinfos += "UDFLW";
0076         a_sinfos += f_lf;
0077         if(!numas<double>(m_data.bin_height(histo::axis_UNDERFLOW_BIN),a_sinfos)){}
0078 
0079       } else if((*it)=="overflow") {
0080         if(a_sinfos.size()) a_sinfos += f_lf;
0081         a_sinfos += "OVFLW";
0082         a_sinfos += f_lf;
0083         if(!numas<double>(m_data.bin_height(histo::axis_OVERFLOW_BIN),a_sinfos)){}
0084       }
0085     }
0086   }
0087 public: //bins1D
0088   virtual void bins_Sw_range(float& a_mn,float& a_mx,bool a_with_entries) const {
0089     if(a_with_entries && m_data.has_entries_per_bin()) {
0090       double mn,mx;
0091       m_data.min_bin_height_with_entries(mn);
0092       m_data.max_bin_height_with_entries(mx);
0093       a_mn = float(mn);
0094       a_mx = float(mx);
0095     } else {
0096       a_mn = (float)m_data.min_bin_height();
0097       a_mx = (float)m_data.max_bin_height();
0098     }
0099   }
0100   virtual unsigned int bins() const {return m_data.axis().bins();}
0101   virtual float axis_min() const {return (float)m_data.axis().lower_edge();}
0102   virtual float axis_max() const {return (float)m_data.axis().upper_edge();}
0103   virtual float bin_lower_edge(int aI) const {return (float)m_data.axis().bin_lower_edge(aI);}
0104   virtual float bin_upper_edge(int aI) const {return (float)m_data.axis().bin_upper_edge(aI);}
0105 
0106   virtual bool has_entries_per_bin() const {return m_data.has_entries_per_bin();}
0107   virtual unsigned int bin_entries(int aI) const {return m_data.bin_entries(aI);}
0108 
0109   virtual float bin_Sw(int aI) const {return (float)m_data.bin_height(aI);}
0110 
0111   virtual float bin_error(int aI) const {return (float)m_data.bin_error(aI);}
0112   virtual bool is_profile() const {return false;}
0113 public:
0114   h1d2plot(const histo::h1d& a_data):m_data(a_data) {
0115   }
0116   virtual ~h1d2plot(){
0117   }
0118 public:
0119   h1d2plot(const h1d2plot& a_from)
0120   :plottable(a_from),bins1D(a_from)
0121   ,m_data(a_from.m_data)
0122   ,m_name(a_from.m_name)
0123   ,m_legend(a_from.m_legend)
0124   {
0125   }
0126   h1d2plot& operator=(const h1d2plot& a_from){
0127     m_name = a_from.m_name;
0128     m_legend = a_from.m_legend;
0129     return *this;
0130   }
0131 public:
0132   const histo::h1d& data() const {return m_data;}
0133 protected:
0134   const histo::h1d& m_data;
0135   std::string m_name;
0136   std::string m_legend;
0137 };
0138 
0139 class h2d2plot : public virtual bins2D {
0140 public:
0141   TOOLS_SCLASS(tools::sg::h2d2plot)
0142 public:
0143   virtual void* cast(const std::string& a_class) const {
0144     if(void* p = cmp_cast<h2d2plot>(this,a_class)) {return p;}
0145     return bins2D::cast(a_class);
0146   }
0147 public: //plottable
0148   virtual plottable* copy() const {return new h2d2plot(*this);}
0149   virtual bool is_valid() const {return true;}
0150   virtual const std::string& name() const {return m_name;}
0151   virtual void set_name(const std::string& a_s) {m_name = a_s;}
0152   virtual const std::string& title() const {return m_data.title();}
0153   virtual const std::string& legend() const {return m_legend;}
0154   virtual void set_legend(const std::string& a_s) {m_legend = a_s;}
0155 
0156   virtual void infos(const std::string& a_opts,std::string& a_sinfos) const {
0157     a_sinfos.clear();
0158     std::string f_lf("\n");
0159     std::vector<std::string> ws;
0160     words(a_opts," ",false,ws);
0161     std::vector<std::string>::const_iterator it;
0162     for(it=ws.begin();it!=ws.end();++it) {
0163       if(((*it)=="name") && m_name.size()) {
0164         if(a_sinfos.size()) a_sinfos += f_lf;
0165         a_sinfos += "Name\n";
0166         a_sinfos += m_name;
0167 
0168       } else if((*it)=="entries") {
0169         if(a_sinfos.size()) a_sinfos += f_lf;
0170         a_sinfos += "Entries\n";
0171         if(!numas<unsigned int>(m_data.all_entries(),a_sinfos)) {}
0172 
0173       } else if((*it)=="mean") {
0174         if(a_sinfos.size()) a_sinfos += f_lf;
0175         a_sinfos += "MeanX\n";
0176         if(!numas<double>(m_data.mean_x(),a_sinfos)) {}
0177         a_sinfos += f_lf;
0178         a_sinfos += "MeanY\n";
0179         if(!numas<double>(m_data.mean_y(),a_sinfos)) {}
0180 
0181       } else if((*it)=="rms") {
0182         if(a_sinfos.size()) a_sinfos += f_lf;
0183         a_sinfos += "RMS X\n";
0184         if(!numas<double>(m_data.rms_x(),a_sinfos)) {}
0185         a_sinfos += f_lf;
0186         a_sinfos += "RMS Y\n";
0187         if(!numas<double>(m_data.rms_y(),a_sinfos)) {}
0188 
0189       }
0190     }
0191   }
0192 public: //bins2D
0193   virtual void bins_Sw_range(float& a_mn,float& a_mx,bool a_with_entries) const {
0194     if(a_with_entries && m_data.has_entries_per_bin()) {
0195       double mn,mx;
0196       m_data.min_bin_height_with_entries(mn);
0197       m_data.max_bin_height_with_entries(mx);
0198       a_mn = float(mn);
0199       a_mx = float(mx);
0200     } else {
0201       a_mn = (float)m_data.min_bin_height();
0202       a_mx = (float)m_data.max_bin_height();
0203     }
0204   }
0205   virtual unsigned int x_bins() const {return m_data.axis_x().bins();}
0206   virtual unsigned int y_bins() const {return m_data.axis_y().bins();}
0207   virtual float x_axis_min() const {return (float)m_data.axis_x().lower_edge();}
0208   virtual float x_axis_max() const {return (float)m_data.axis_x().upper_edge();}
0209   virtual float y_axis_min() const {return (float)m_data.axis_y().lower_edge();}
0210   virtual float y_axis_max() const {return (float)m_data.axis_y().upper_edge();}
0211 
0212   virtual float bin_lower_edge_x(int aI) const {return (float)m_data.axis_x().bin_lower_edge(aI);}
0213   virtual float bin_upper_edge_x(int aI) const {return (float)m_data.axis_x().bin_upper_edge(aI);}
0214   virtual float bin_lower_edge_y(int aI) const {return (float)m_data.axis_y().bin_lower_edge(aI);}
0215   virtual float bin_upper_edge_y(int aI) const {return (float)m_data.axis_y().bin_upper_edge(aI);}
0216 
0217   virtual bool has_entries_per_bin() const {return m_data.has_entries_per_bin();}
0218   virtual unsigned int bin_entries(int aI,int aJ) const {return m_data.bin_entries(aI,aJ);}
0219 
0220   virtual float bin_Sw(int aI,int aJ) const {return (float)m_data.bin_height(aI,aJ);}
0221 
0222   virtual float bin_error(int aI,int aJ) const {return (float)m_data.bin_error(aI,aJ);}
0223 public:
0224   h2d2plot(const histo::h2d& a_data)
0225   :m_data(a_data)
0226   {
0227   }
0228   virtual ~h2d2plot(){
0229   }
0230 public:
0231   h2d2plot(const h2d2plot& a_from)
0232   :plottable(a_from),bins2D(a_from)
0233   ,m_data(a_from.m_data)
0234   ,m_name(a_from.m_name)
0235   ,m_legend(a_from.m_legend)
0236   {
0237   }
0238   h2d2plot& operator=(const h2d2plot& a_from){
0239     m_name = a_from.m_name;
0240     m_legend = a_from.m_legend;
0241     return *this;
0242   }
0243 protected:
0244   const histo::h2d& m_data;
0245   std::string m_name;
0246   std::string m_legend;
0247 };
0248 
0249 //NOTE : for the moment, same code as h1d2plot !
0250 class p1d2plot : public virtual bins1D {
0251 public:
0252   TOOLS_SCLASS(tools::sg::p1d2plot)
0253 public:
0254   virtual void* cast(const std::string& a_class) const {
0255     if(void* p = cmp_cast<p1d2plot>(this,a_class)) {return p;}
0256     return bins1D::cast(a_class);
0257   }
0258 public:
0259   virtual plottable* copy() const {return new p1d2plot(*this);}
0260   virtual bool is_valid() const {return true;}
0261   virtual const std::string& name() const {return m_name;}
0262   virtual void set_name(const std::string& a_s) {m_name = a_s;}
0263   virtual const std::string& title() const {return m_data.title();}
0264   virtual const std::string& legend() const {return m_legend;}
0265   virtual void set_legend(const std::string& a_s) {m_legend = a_s;}
0266 
0267   virtual void infos(const std::string& a_opts,std::string& a_sinfos) const {
0268     a_sinfos.clear();
0269     std::string f_lf("\n");
0270     std::vector<std::string> ws;
0271     words(a_opts," ",false,ws);
0272     std::vector<std::string>::const_iterator it;
0273     for(it=ws.begin();it!=ws.end();++it) {
0274       if(((*it)=="name") && m_name.size()) {
0275         if(a_sinfos.size()) a_sinfos += f_lf;
0276         a_sinfos += "Name\n";
0277         a_sinfos += m_name;
0278 
0279       } else if((*it)=="entries") {
0280         if(a_sinfos.size()) a_sinfos += f_lf;
0281         a_sinfos += "Entries\n";
0282         if(!numas<unsigned int>(m_data.all_entries(),a_sinfos)) {}
0283       } else if((*it)=="mean") {
0284         if(a_sinfos.size()) a_sinfos += f_lf;
0285         a_sinfos += "Mean\n";
0286         if(!numas<double>(m_data.mean(),a_sinfos)) {}
0287       } else if((*it)=="rms") {
0288         if(a_sinfos.size()) a_sinfos += f_lf;
0289         a_sinfos += "RMS\n";
0290         if(!numas<double>(m_data.rms(),a_sinfos)) {}
0291 
0292       }
0293     }
0294   }
0295 public:
0296   virtual unsigned int bins() const {return m_data.axis().bins();}
0297 
0298   virtual void bins_Sw_range(float& a_mn,float& a_mx,bool a_with_entries) const {
0299     if(a_with_entries && m_data.has_entries_per_bin()) {
0300       double mn,mx;
0301       m_data.min_bin_height_with_entries(mn);
0302       m_data.max_bin_height_with_entries(mx);
0303       a_mn = float(mn);
0304       a_mx = float(mx);
0305     } else {
0306       a_mn = (float)m_data.min_bin_height();
0307       a_mx = (float)m_data.max_bin_height();
0308     }
0309   }
0310 
0311   virtual float axis_min() const {return (float)m_data.axis().lower_edge();}
0312   virtual float axis_max() const {return (float)m_data.axis().upper_edge();}
0313   virtual float bin_lower_edge(int aI) const {return (float)m_data.axis().bin_lower_edge(aI);}
0314   virtual float bin_upper_edge(int aI) const {return (float)m_data.axis().bin_upper_edge(aI);}
0315 
0316   virtual bool has_entries_per_bin() const {return m_data.has_entries_per_bin();}
0317   virtual unsigned int bin_entries(int aI) const {return m_data.bin_entries(aI);}
0318 
0319   virtual float bin_Sw(int aI) const {return (float)m_data.bin_height(aI);}
0320 
0321   virtual float bin_error(int aI) const {return (float)m_data.bin_error(aI);}
0322 
0323   virtual bool is_profile() const {return true;}
0324 public:
0325   p1d2plot(const histo::p1d& a_data):m_data(a_data){}
0326   virtual ~p1d2plot(){}
0327 public:
0328   p1d2plot(const p1d2plot& a_from)
0329   :plottable(a_from),bins1D(a_from)
0330   ,m_data(a_from.m_data)
0331   ,m_name(a_from.m_name)
0332   ,m_legend(a_from.m_legend)
0333   {}
0334   p1d2plot& operator=(const p1d2plot& a_from){
0335     m_name = a_from.m_name;
0336     m_legend = a_from.m_legend;
0337     return *this;
0338   }
0339 protected:
0340   const histo::p1d& m_data;
0341   std::string m_name;
0342   std::string m_legend;
0343 };
0344 
0345 }}
0346 
0347 #endif