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 "../words"
0018 #include "../num2s"
0019 
0020 #ifdef TOOLS_MEM
0021 #include "../mem"
0022 #endif
0023 
0024 namespace tools {
0025 namespace sg {
0026 
0027 class h1d2plot : public virtual bins1D {
0028 public:
0029   TOOLS_SCLASS(tools::sg::h1d2plot)
0030 public:
0031   virtual void* cast(const std::string& a_class) const {
0032     if(void* p = cmp_cast<h1d2plot>(this,a_class)) {return p;}
0033     return bins1D::cast(a_class);
0034   }
0035 public: //plottable
0036   virtual plottable* copy() const {return new h1d2plot(*this);}
0037   virtual bool is_valid() const {return true;}
0038   virtual const std::string& name() const {return m_name;}
0039   virtual void set_name(const std::string& a_s) {m_name = a_s;}
0040 
0041   virtual const std::string& title() const {return m_data.title();}
0042   virtual const std::string& legend() const {return m_legend;}
0043   virtual void set_legend(const std::string& a_s) {m_legend = a_s;}
0044 
0045   virtual void infos(const std::string& a_opts,std::string& a_sinfos) const {
0046     a_sinfos.clear();
0047     std::string f_lf("\n");
0048     std::vector<std::string> ws;
0049     words(a_opts," ",false,ws);
0050     std::vector<std::string>::const_iterator it;
0051 
0052   /*bool show_fit_ndf = false;
0053    {for(it=ws.begin();it!=ws.end();++it) {
0054       if((*it)=="fit_ndf") {show_fit_ndf = true;break;}
0055     }}*/
0056 
0057     for(it=ws.begin();it!=ws.end();++it) {
0058       if(((*it)=="name") && m_name.size()) {
0059         if(a_sinfos.size()) a_sinfos += f_lf;
0060         a_sinfos += "Name";
0061         a_sinfos += f_lf;
0062         a_sinfos += m_name;
0063 
0064       } else if((*it)=="entries") {
0065         if(a_sinfos.size()) a_sinfos += f_lf;
0066         a_sinfos += "Entries";
0067         a_sinfos += f_lf;
0068         if(!numas<unsigned int>(m_data.all_entries(),a_sinfos)){}
0069 
0070       } else if((*it)=="mean") {
0071         if(a_sinfos.size()) a_sinfos += f_lf;
0072         a_sinfos += "Mean";
0073         a_sinfos += f_lf;
0074         if(!numas<double>(m_data.mean(),a_sinfos)) {}
0075 
0076       } else if((*it)=="rms") {
0077         if(a_sinfos.size()) a_sinfos += f_lf;
0078         a_sinfos += "RMS";
0079         a_sinfos += f_lf;
0080         if(!numas<double>(m_data.rms(),a_sinfos)) {}
0081 
0082       } else if((*it)=="underflow") {
0083         if(a_sinfos.size()) a_sinfos += f_lf;
0084         a_sinfos += "UDFLW";
0085         a_sinfos += f_lf;
0086         if(!numas<double>(m_data.bin_height(histo::axis_UNDERFLOW_BIN),a_sinfos)){}
0087 
0088       } else if((*it)=="overflow") {
0089         if(a_sinfos.size()) a_sinfos += f_lf;
0090         a_sinfos += "OVFLW";
0091         a_sinfos += f_lf;
0092         if(!numas<double>(m_data.bin_height(histo::axis_OVERFLOW_BIN),a_sinfos)){}
0093 
0094 /*
0095       } else if((*it)=="fit_quality") {
0096         //look in m_data annotations for "fit.chi2" and "fit.ndf" keys :
0097         if(show_fit_ndf) {
0098           std::string schi2;
0099           std::string sndf;
0100           if(m_data.annotation("fit.chi2",schi2) &&
0101              m_data.annotation("fit.ndf",sndf)   ){
0102             if(a_sinfos.size()) a_sinfos += f_lf;
0103             a_sinfos += "[h]^2! / ndf";
0104             a_sinfos += f_lf;
0105             a_sinfos += schi2;
0106             a_sinfos += " / ";
0107             a_sinfos += sndf;
0108           }
0109         } else { //show chi2 only.
0110           std::string schi2;
0111           if(m_data.annotation("fit.chi2",schi2)){
0112             if(a_sinfos.size()) a_sinfos += f_lf;
0113             a_sinfos += "[h]^2!";
0114             a_sinfos += f_lf;
0115             a_sinfos += schi2;
0116           }
0117         }
0118 
0119       } else if((*it)=="fit_parameters") {
0120         //look in m_data annotations for "fit.param.<name>" keys :
0121         typedef std::map<std::string,std::string> annots_t;
0122         const annots_t& annots = m_data.annotations();
0123         annots_t::const_iterator it;
0124         for(it=annots.begin();it!=annots.end();++it) {
0125           const std::string& key = (*it).first;
0126           if(key.substr(0,10)=="fit.param.") {
0127             //fit.param.mean 14
0128             //01234567890123
0129             std::string name = key.substr(10,key.size()-10);
0130             if(a_sinfos.size()) a_sinfos += f_lf;
0131             a_sinfos += name;
0132             a_sinfos += f_lf;
0133             a_sinfos += (*it).second;
0134           }
0135         }
0136 */
0137       }
0138     }
0139   }
0140 public: //bins1D
0141   virtual void bins_Sw_range(float& a_mn,float& a_mx,bool a_with_entries) const {
0142     if(a_with_entries && m_data.has_entries_per_bin()) {
0143       double mn,mx;
0144       m_data.min_bin_height_with_entries(mn);
0145       m_data.max_bin_height_with_entries(mx);
0146       a_mn = float(mn);
0147       a_mx = float(mx);
0148     } else {
0149       a_mn = (float)m_data.min_bin_height();
0150       a_mx = (float)m_data.max_bin_height();
0151     }
0152   }
0153   virtual unsigned int bins() const {return m_data.axis().bins();}
0154   virtual float axis_min() const {return (float)m_data.axis().lower_edge();}
0155   virtual float axis_max() const {return (float)m_data.axis().upper_edge();}
0156   virtual float bin_lower_edge(int aI) const {return (float)m_data.axis().bin_lower_edge(aI);}
0157   virtual float bin_upper_edge(int aI) const {return (float)m_data.axis().bin_upper_edge(aI);}
0158 
0159   virtual bool has_entries_per_bin() const {return m_data.has_entries_per_bin();}
0160   virtual unsigned int bin_entries(int aI) const {return m_data.bin_entries(aI);}
0161 
0162   virtual float bin_Sw(int aI) const {return (float)m_data.bin_height(aI);}
0163 
0164   virtual float bin_error(int aI) const {return (float)m_data.bin_error(aI);}
0165   virtual bool is_profile() const {return false;}
0166 public:
0167   h1d2plot(const histo::h1d& a_data):m_data(a_data) {
0168 #ifdef TOOLS_MEM
0169     mem::increment(s_class().c_str());
0170 #endif
0171   }
0172   virtual ~h1d2plot(){
0173 #ifdef TOOLS_MEM
0174     mem::decrement(s_class().c_str());
0175 #endif
0176   }
0177 public:
0178   h1d2plot(const h1d2plot& a_from)
0179   :plottable(a_from),bins1D(a_from)
0180   ,m_data(a_from.m_data)
0181   ,m_name(a_from.m_name)
0182   ,m_legend(a_from.m_legend)
0183   {
0184 #ifdef TOOLS_MEM
0185     mem::increment(s_class().c_str());
0186 #endif
0187   }
0188   h1d2plot& operator=(const h1d2plot& a_from){
0189     m_name = a_from.m_name;
0190     m_legend = a_from.m_legend;
0191     return *this;
0192   }
0193 public:
0194   const histo::h1d& data() const {return m_data;}
0195 protected:
0196   const histo::h1d& m_data;
0197   std::string m_name;
0198   std::string m_legend;
0199 };
0200 
0201 class h2d2plot : public virtual bins2D {
0202 public:
0203   TOOLS_SCLASS(tools::sg::h2d2plot)
0204 public:
0205   virtual void* cast(const std::string& a_class) const {
0206     if(void* p = cmp_cast<h2d2plot>(this,a_class)) {return p;}
0207     return bins2D::cast(a_class);
0208   }
0209 public: //plottable
0210   virtual plottable* copy() const {return new h2d2plot(*this);}
0211   virtual bool is_valid() const {return true;}
0212   virtual const std::string& name() const {return m_name;}
0213   virtual void set_name(const std::string& a_s) {m_name = a_s;}
0214   virtual const std::string& title() const {return m_data.title();}
0215   virtual const std::string& legend() const {return m_legend;}
0216   virtual void set_legend(const std::string& a_s) {m_legend = a_s;}
0217 
0218   virtual void infos(const std::string& a_opts,std::string& a_sinfos) const {
0219     a_sinfos.clear();
0220     std::string f_lf("\n");
0221     std::vector<std::string> ws;
0222     words(a_opts," ",false,ws);
0223     std::vector<std::string>::const_iterator it;
0224     for(it=ws.begin();it!=ws.end();++it) {
0225       if(((*it)=="name") && m_name.size()) {
0226         if(a_sinfos.size()) a_sinfos += f_lf;
0227         a_sinfos += "Name\n";
0228         a_sinfos += m_name;
0229 
0230       } else if((*it)=="entries") {
0231         if(a_sinfos.size()) a_sinfos += f_lf;
0232         a_sinfos += "Entries\n";
0233         if(!numas<unsigned int>(m_data.all_entries(),a_sinfos)) {}
0234 
0235       } else if((*it)=="mean") {
0236         if(a_sinfos.size()) a_sinfos += f_lf;
0237         a_sinfos += "MeanX\n";
0238         if(!numas<double>(m_data.mean_x(),a_sinfos)) {}
0239         a_sinfos += f_lf;
0240         a_sinfos += "MeanY\n";
0241         if(!numas<double>(m_data.mean_y(),a_sinfos)) {}
0242 
0243       } else if((*it)=="rms") {
0244         if(a_sinfos.size()) a_sinfos += f_lf;
0245         a_sinfos += "RMS X\n";
0246         if(!numas<double>(m_data.rms_x(),a_sinfos)) {}
0247         a_sinfos += f_lf;
0248         a_sinfos += "RMS Y\n";
0249         if(!numas<double>(m_data.rms_y(),a_sinfos)) {}
0250 
0251       }
0252     }
0253   }
0254 public: //bins2D
0255   virtual void bins_Sw_range(float& a_mn,float& a_mx,bool a_with_entries) const {
0256     if(a_with_entries && m_data.has_entries_per_bin()) {
0257       double mn,mx;
0258       m_data.min_bin_height_with_entries(mn);
0259       m_data.max_bin_height_with_entries(mx);
0260       a_mn = float(mn);
0261       a_mx = float(mx);
0262     } else {
0263       a_mn = (float)m_data.min_bin_height();
0264       a_mx = (float)m_data.max_bin_height();
0265     }
0266   }
0267   virtual unsigned int x_bins() const {return m_data.axis_x().bins();}
0268   virtual unsigned int y_bins() const {return m_data.axis_y().bins();}
0269   virtual float x_axis_min() const {return (float)m_data.axis_x().lower_edge();}
0270   virtual float x_axis_max() const {return (float)m_data.axis_x().upper_edge();}
0271   virtual float y_axis_min() const {return (float)m_data.axis_y().lower_edge();}
0272   virtual float y_axis_max() const {return (float)m_data.axis_y().upper_edge();}
0273 
0274   virtual float bin_lower_edge_x(int aI) const {return (float)m_data.axis_x().bin_lower_edge(aI);}
0275   virtual float bin_upper_edge_x(int aI) const {return (float)m_data.axis_x().bin_upper_edge(aI);}
0276   virtual float bin_lower_edge_y(int aI) const {return (float)m_data.axis_y().bin_lower_edge(aI);}
0277   virtual float bin_upper_edge_y(int aI) const {return (float)m_data.axis_y().bin_upper_edge(aI);}
0278 
0279   virtual bool has_entries_per_bin() const {return m_data.has_entries_per_bin();}
0280   virtual unsigned int bin_entries(int aI,int aJ) const {return m_data.bin_entries(aI,aJ);}
0281 
0282   virtual float bin_Sw(int aI,int aJ) const {return (float)m_data.bin_height(aI,aJ);}
0283 
0284   virtual float bin_error(int aI,int aJ) const {return (float)m_data.bin_error(aI,aJ);}
0285 public:
0286   h2d2plot(const histo::h2d& a_data)
0287   :m_data(a_data)
0288   {
0289 #ifdef TOOLS_MEM
0290     mem::increment(s_class().c_str());
0291 #endif
0292   }
0293   virtual ~h2d2plot(){
0294 #ifdef TOOLS_MEM
0295     mem::decrement(s_class().c_str());
0296 #endif
0297   }
0298 public:
0299   h2d2plot(const h2d2plot& a_from)
0300   :plottable(a_from),bins2D(a_from)
0301   ,m_data(a_from.m_data)
0302   ,m_name(a_from.m_name)
0303   ,m_legend(a_from.m_legend)
0304   {
0305 #ifdef TOOLS_MEM
0306     mem::increment(s_class().c_str());
0307 #endif
0308   }
0309   h2d2plot& operator=(const h2d2plot& a_from){
0310     m_name = a_from.m_name;
0311     m_legend = a_from.m_legend;
0312     return *this;
0313   }
0314 protected:
0315   const histo::h2d& m_data;
0316   std::string m_name;
0317   std::string m_legend;
0318 };
0319 
0320 //NOTE : for the moment, same code as h1d2plot !
0321 class p1d2plot : public virtual bins1D {
0322 public:
0323   TOOLS_SCLASS(tools::sg::p1d2plot)
0324 public:
0325   virtual void* cast(const std::string& a_class) const {
0326     if(void* p = cmp_cast<p1d2plot>(this,a_class)) {return p;}
0327     return bins1D::cast(a_class);
0328   }
0329 public:
0330   virtual plottable* copy() const {return new p1d2plot(*this);}
0331   virtual bool is_valid() const {return true;}
0332   virtual const std::string& name() const {return m_name;}
0333   virtual void set_name(const std::string& a_s) {m_name = a_s;}
0334   virtual const std::string& title() const {return m_data.title();}
0335   virtual const std::string& legend() const {return m_legend;}
0336   virtual void set_legend(const std::string& a_s) {m_legend = a_s;}
0337 
0338   virtual void infos(const std::string& a_opts,std::string& a_sinfos) const {
0339     a_sinfos.clear();
0340     std::string f_lf("\n");
0341     std::vector<std::string> ws;
0342     words(a_opts," ",false,ws);
0343     std::vector<std::string>::const_iterator it;
0344     for(it=ws.begin();it!=ws.end();++it) {
0345       if(((*it)=="name") && m_name.size()) {
0346         if(a_sinfos.size()) a_sinfos += f_lf;
0347         a_sinfos += "Name\n";
0348         a_sinfos += m_name;
0349 
0350       } else if((*it)=="entries") {
0351         if(a_sinfos.size()) a_sinfos += f_lf;
0352         a_sinfos += "Entries\n";
0353         if(!numas<unsigned int>(m_data.all_entries(),a_sinfos)) {}
0354       } else if((*it)=="mean") {
0355         if(a_sinfos.size()) a_sinfos += f_lf;
0356         a_sinfos += "Mean\n";
0357         if(!numas<double>(m_data.mean(),a_sinfos)) {}
0358       } else if((*it)=="rms") {
0359         if(a_sinfos.size()) a_sinfos += f_lf;
0360         a_sinfos += "RMS\n";
0361         if(!numas<double>(m_data.rms(),a_sinfos)) {}
0362 
0363       }
0364     }
0365   }
0366 public:
0367   virtual unsigned int bins() const {return m_data.axis().bins();}
0368 
0369   virtual void bins_Sw_range(float& a_mn,float& a_mx,bool a_with_entries) const {
0370     if(a_with_entries && m_data.has_entries_per_bin()) {
0371       double mn,mx;
0372       m_data.min_bin_height_with_entries(mn);
0373       m_data.max_bin_height_with_entries(mx);
0374       a_mn = float(mn);
0375       a_mx = float(mx);
0376     } else {
0377       a_mn = (float)m_data.min_bin_height();
0378       a_mx = (float)m_data.max_bin_height();
0379     }
0380   }
0381 
0382   virtual float axis_min() const {return (float)m_data.axis().lower_edge();}
0383   virtual float axis_max() const {return (float)m_data.axis().upper_edge();}
0384   virtual float bin_lower_edge(int aI) const {return (float)m_data.axis().bin_lower_edge(aI);}
0385   virtual float bin_upper_edge(int aI) const {return (float)m_data.axis().bin_upper_edge(aI);}
0386 
0387   virtual bool has_entries_per_bin() const {return m_data.has_entries_per_bin();}
0388   virtual unsigned int bin_entries(int aI) const {return m_data.bin_entries(aI);}
0389 
0390   virtual float bin_Sw(int aI) const {return (float)m_data.bin_height(aI);}
0391 
0392   virtual float bin_error(int aI) const {return (float)m_data.bin_error(aI);}
0393 
0394   virtual bool is_profile() const {return true;}
0395 public:
0396   p1d2plot(const histo::p1d& a_data):m_data(a_data){}
0397   virtual ~p1d2plot(){}
0398 public:
0399   p1d2plot(const p1d2plot& a_from)
0400   :plottable(a_from),bins1D(a_from)
0401   ,m_data(a_from.m_data)
0402   ,m_name(a_from.m_name)
0403   ,m_legend(a_from.m_legend)
0404   {}
0405   p1d2plot& operator=(const p1d2plot& a_from){
0406     m_name = a_from.m_name;
0407     m_legend = a_from.m_legend;
0408     return *this;
0409   }
0410 protected:
0411   const histo::p1d& m_data;
0412   std::string m_name;
0413   std::string m_legend;
0414 };
0415 
0416 /*
0417 class p2d2plot : public virtual SbPlottableBins2D {
0418 public:
0419   TOOLS_SCLASS(tools::sg::p2d2plot)
0420 public:
0421   virtual void* cast(const std::string& a_class) const {
0422     if(void* p = cmp_cast<p2d2plot>(this,a_class)) {return p;}
0423     return bins2D::cast(a_class);
0424   }
0425 public: //SbPlottableObject
0426   virtual bool is_valid() const {return true;}
0427   virtual const char* name(){return m_name;}
0428   virtual const char* legend(){return m_legend;}
0429 public:
0430   virtual int getDimension() const{return 2;}
0431   virtual const char* title(){return m_data.title();}
0432 public: //SbPlottableBins2D
0433   virtual void getBinsSumOfWeightsRange(float& a_mn,float& a_mx) const {
0434     a_mn = (float)m_data.min_bin_height();
0435     a_mx = (float)m_data.max_bin_height();
0436   }
0437   virtual int getAxisNumberOfBinsX() const {return m_data.axis_x().bins();}
0438   virtual int getAxisNumberOfBinsY() const {return m_data.axis_y().bins();}
0439   virtual float getAxisMinimumX() const {return (float)m_data.axis_x().lower_edge();}
0440   virtual float getAxisMaximumX() const {return (float)m_data.axis_x().upper_edge();}
0441   virtual float getAxisMinimumY() const {return (float)m_data.axis_y().lower_edge();}
0442   virtual float getAxisMaximumY() const {return (float)m_data.axis_y().upper_edge();}
0443   virtual float getBinLowerEdgeX(int aI) const {
0444     return (float)m_data.axis_x().bin_lower_edge(aI);
0445   }
0446   virtual float bin_upper_edgeX(int aI) const {
0447     return (float)m_data.axis_x().bin_upper_edge(aI);
0448   }
0449   virtual float getBinLowerEdgeY(int aI) const {
0450     return (float)m_data.axis_y().bin_lower_edge(aI);
0451   }
0452   virtual float bin_upper_edgeY(int aI) const {
0453     return (float)m_data.axis_y().bin_upper_edge(aI);
0454   }
0455   virtual int getBinNumberOfEntries(int aI,int aJ) const {
0456     return m_data.bin_entries(aI,aJ);
0457   }
0458   virtual float getBinSumOfWeights(int aI,int aJ) const {
0459     return (float)m_data.bin_height(aI,aJ);
0460   }
0461   virtual float getBinBar(int aI,int aJ) const {
0462     return (float)m_data.bin_error(aI,aJ);
0463   }
0464 
0465   virtual void infos(const std::string& a_opts,std::string& a_sinfos) const {
0466     a_sinfos.clear();
0467     std::string f_lf("\n");
0468     std::vector<std::string> ws;
0469     words(a_opts," ",false,ws);
0470     std::vector<std::string>::const_iterator it;
0471     for(it=ws.begin();it!=ws.end();++it) {
0472       if(((*it)=="name") && m_name.size()) {
0473         if(a_sinfos.size()) a_sinfos += f_lf;
0474         a_sinfos += "Name\n";
0475         a_sinfos += m_name;
0476 
0477       } else if((*it)=="entries") {
0478         if(a_sinfos.size()) a_sinfos += f_lf;
0479         a_sinfos += "Entries\n";
0480         if(!numasd int>(m_data.all_entries(),a_sinfos)) {}
0481       } else if((*it)=="mean") {
0482         if(a_sinfos.size()) a_sinfos += f_lf;
0483         a_sinfos += "MeanX\n";
0484         if(!numas<double>(m_data.mean_x(),a_sinfos)) {}
0485         a_sinfos += f_lf;
0486         a_sinfos += "MeanY\n";
0487         if(!numas<double>(m_data.mean_y(),a_sinfos)) {}
0488       } else if((*it)=="rms") {
0489         if(a_sinfos.size()) a_sinfos += f_lf;
0490         a_sinfos += "RMS X\n";
0491         if(!numas<double>(m_data.rms_x(),a_sinfos)) {}
0492         a_sinfos += f_lf;
0493         a_sinfos += "RMS Y\n";
0494         if(!numas<double>(m_data.rms_y(),a_sinfos)) {}
0495 
0496       }
0497     }
0498   }
0499 
0500 public:
0501   p2d2plot(const histo::p2d& a_data)
0502   :m_data(a_data)
0503   {
0504 #ifdef TOOLS_MEM
0505     mem::increment(s_class().c_str());
0506 #endif
0507   }
0508   virtual ~p2d2plot(){
0509 #ifdef TOOLS_MEM
0510     mem::decrement(s_class().c_str());
0511 #endif
0512   }
0513 public:
0514   p2d2plot(const p2d2plot& a_from)
0515   :m_data(a_from.m_data)
0516   ,m_name(a_from.m_name)
0517   ,m_legend(a_from.m_legend)
0518   {
0519 #ifdef TOOLS_MEM
0520     mem::increment(s_class().c_str());
0521 #endif
0522   }
0523   p2d2plot& operator=(const p2d2plot& a_from){
0524     m_name = a_from.m_name;
0525     m_legend = a_from.m_legend;
0526     return *this;
0527   }
0528 protected:
0529   const histo::p2d& m_data;
0530   std::string m_name;
0531   std::string m_legend;
0532 };
0533 */
0534 
0535 }}
0536 
0537 #endif