Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

AIDA_DevHistogramFactory.cpp

Go to the documentation of this file.
00001 #include "AIDA_DevHistogramFactory.h"
00002 
00003 #include "AIDA_Histogram1D.h"
00004 #include "AIDA_Histogram2D.h"
00005 #include "AIDA_Histogram3D.h"
00006 #include "AIDA_Profile1D.h"
00007 #include "AIDA_Profile2D.h"
00008 #include "AIDA_BoundedProfile1D.h"
00009 #include "AIDA_BoundedProfile2D.h"
00010 #include "AIDA_Cloud1D.h"
00011 #include "AIDA_Cloud2D.h"
00012 #include "AIDA_Cloud3D.h"
00013 
00014 #include "AIDA/IAxis.h"
00015 
00016 #include <typeinfo>
00017 #include <cmath>
00018 
00019 
00020 static const int numberOfExtraBins = 2;
00021 static const std::string emptyString = "";
00022 
00023 bool
00024 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::destroy( AIDA::IBaseHistogram * histo )
00025 {
00026   delete histo;
00027   return true;
00028 }
00029 
00030 
00031 AIDA::Dev::IDevCloud1D*
00032 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::createCloud1D( const std::string & title, int nMax, const std::string& )
00033 {
00034   AIDA::Dev::IDevCloud1D* p = new Anaphe::AIDA_Histogram_native::AIDA_Cloud1D( title );
00035   if ( nMax == -1 ) p->setCacheSize( static_cast<unsigned int>( -1 ) );
00036   else p->setCacheSize( nMax );
00037   return p;
00038 }
00039 
00040 
00041 AIDA::Dev::IDevCloud1D*
00042 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::createCloud1D()
00043 {
00044   return new Anaphe::AIDA_Histogram_native::AIDA_Cloud1D( emptyString );
00045 }
00046 
00047 
00048 AIDA::Dev::IDevCloud1D*
00049 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::createCopy( const AIDA::ICloud1D & original )
00050 {
00051   try {
00052     const Anaphe::AIDA_Histogram_native::AIDA_Cloud1D& h = dynamic_cast< const Anaphe::AIDA_Histogram_native::AIDA_Cloud1D& >( original );
00053     return new Anaphe::AIDA_Histogram_native::AIDA_Cloud1D( h );
00054   }
00055   catch( std::bad_cast ) {
00056     return new Anaphe::AIDA_Histogram_native::AIDA_Cloud1D( original );
00057   }
00058 }
00059 
00060 
00061 AIDA::Dev::IDevCloud2D*
00062 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::createCloud2D( const std::string & title, int nMax, const std::string& )
00063 {
00064   AIDA::Dev::IDevCloud2D* p = new Anaphe::AIDA_Histogram_native::AIDA_Cloud2D( title );
00065   if ( nMax == -1 ) p->setCacheSize( static_cast<unsigned int>( -1 ) );
00066   else p->setCacheSize( nMax );
00067   return p;
00068 }
00069 
00070 
00071 AIDA::Dev::IDevCloud2D*
00072 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::createCloud2D()
00073 {
00074   return new Anaphe::AIDA_Histogram_native::AIDA_Cloud2D( emptyString );
00075 }
00076 
00077 
00078 AIDA::Dev::IDevCloud2D*
00079 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::createCopy( const AIDA::ICloud2D & original )
00080 {
00081   try {
00082     const Anaphe::AIDA_Histogram_native::AIDA_Cloud2D& h = dynamic_cast< const Anaphe::AIDA_Histogram_native::AIDA_Cloud2D& >( original );
00083     return new Anaphe::AIDA_Histogram_native::AIDA_Cloud2D( h );
00084   }
00085   catch( std::bad_cast ) {
00086     return new Anaphe::AIDA_Histogram_native::AIDA_Cloud2D( original );
00087   }
00088 }
00089 
00090 
00091 AIDA::Dev::IDevCloud3D*
00092 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::createCloud3D( const std::string & title, int nMax, const std::string& )
00093 {
00094   AIDA::Dev::IDevCloud3D* p = new Anaphe::AIDA_Histogram_native::AIDA_Cloud3D( title );
00095   if ( nMax == -1 ) p->setCacheSize( static_cast<unsigned int>(-1) );
00096   else p->setCacheSize( nMax );
00097   return p;
00098 }
00099 
00100 
00101 AIDA::Dev::IDevCloud3D*
00102 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::createCloud3D()
00103 {
00104   return new Anaphe::AIDA_Histogram_native::AIDA_Cloud3D( emptyString );
00105 }
00106 
00107 
00108 AIDA::Dev::IDevCloud3D*
00109 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::createCopy( const AIDA::ICloud3D & original )
00110 {
00111   try {
00112     const Anaphe::AIDA_Histogram_native::AIDA_Cloud3D& h = dynamic_cast< const Anaphe::AIDA_Histogram_native::AIDA_Cloud3D& >( original );
00113     return new Anaphe::AIDA_Histogram_native::AIDA_Cloud3D( h );
00114   }
00115   catch( std::bad_cast ) {
00116     return new Anaphe::AIDA_Histogram_native::AIDA_Cloud3D( original );
00117   }
00118 }
00119 
00120 
00121 AIDA::Dev::IDevHistogram1D*
00122 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::createHistogram1D( const std::string & title, int nBins, double lowerEdge, double upperEdge, const std::string& )
00123 {
00124   return new Anaphe::AIDA_Histogram_native::AIDA_Histogram1D( title, nBins, lowerEdge, upperEdge );
00125 }
00126 
00127 
00128 AIDA::Dev::IDevHistogram1D*
00129 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::createHistogram1D( const std::string & title, const std::vector< double > & binEdge, const std::string& )
00130 {
00131   return new Anaphe::AIDA_Histogram_native::AIDA_Histogram1D( title, binEdge );
00132 }
00133 
00134 
00135 AIDA::Dev::IDevHistogram1D*
00136 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::createHistogram1D( int nBins, double lowerEdge, double upperEdge )
00137 {
00138   return new Anaphe::AIDA_Histogram_native::AIDA_Histogram1D( emptyString, nBins, lowerEdge, upperEdge );
00139 }
00140 
00141 
00142 AIDA::Dev::IDevHistogram1D*
00143 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::createCopy( const AIDA::IHistogram1D & original )
00144 {
00145   try {
00146     const Anaphe::AIDA_Histogram_native::AIDA_Histogram1D& h = dynamic_cast< const Anaphe::AIDA_Histogram_native::AIDA_Histogram1D& >( original );
00147     return new Anaphe::AIDA_Histogram_native::AIDA_Histogram1D( h );
00148   }
00149   catch( std::bad_cast ) {
00150     return new Anaphe::AIDA_Histogram_native::AIDA_Histogram1D( original );
00151   }
00152 }
00153 
00154 
00155 AIDA::Dev::IDevHistogram2D*
00156 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::createHistogram2D( const std::string & title, int nBinsX, double lowerEdgeX, double upperEdgeX, int nBinsY, double lowerEdgeY, double upperEdgeY, const std::string& )
00157 {
00158   return new Anaphe::AIDA_Histogram_native::AIDA_Histogram2D( title, nBinsX, lowerEdgeX, upperEdgeX, nBinsY, lowerEdgeY, upperEdgeY );
00159 }
00160 
00161 
00162 AIDA::Dev::IDevHistogram2D*
00163 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::createHistogram2D( const std::string & title, const std::vector< double > & binEdgeX, const std::vector< double > & binEdgeY, const std::string& )
00164 {
00165   return new Anaphe::AIDA_Histogram_native::AIDA_Histogram2D( title, binEdgeX, binEdgeY );
00166 }
00167 
00168 
00169 AIDA::Dev::IDevHistogram2D*
00170 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::createHistogram2D( int nBinsX, double lowerEdgeX, double upperEdgeX, int nBinsY, double lowerEdgeY, double upperEdgeY )
00171 {
00172   return new Anaphe::AIDA_Histogram_native::AIDA_Histogram2D( emptyString, nBinsX, lowerEdgeX, upperEdgeX, nBinsY, lowerEdgeY, upperEdgeY );
00173 }
00174 
00175 
00176 AIDA::Dev::IDevHistogram2D*
00177 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::createCopy( const AIDA::IHistogram2D & original )
00178 {
00179   try {
00180     const Anaphe::AIDA_Histogram_native::AIDA_Histogram2D& h = dynamic_cast< const Anaphe::AIDA_Histogram_native::AIDA_Histogram2D& >( original );
00181     return new Anaphe::AIDA_Histogram_native::AIDA_Histogram2D( h );
00182   }
00183   catch( std::bad_cast ) {
00184     return new Anaphe::AIDA_Histogram_native::AIDA_Histogram2D( original );
00185   }
00186 }
00187 
00188 
00189 AIDA::Dev::IDevHistogram3D*
00190 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::createHistogram3D( const std::string & title, int nBinsX, double lowerEdgeX, double upperEdgeX, int nBinsY, double lowerEdgeY, double upperEdgeY,
00191                                                 int nBinsZ, double lowerEdgeZ, double upperEdgeZ, const std::string& )
00192 {
00193   return new Anaphe::AIDA_Histogram_native::AIDA_Histogram3D( title, nBinsX, lowerEdgeX, upperEdgeX, nBinsY, lowerEdgeY, upperEdgeY, nBinsZ, lowerEdgeZ, upperEdgeZ );
00194 }
00195 
00196 
00197 AIDA::Dev::IDevHistogram3D*
00198 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::createHistogram3D( const std::string & title, const std::vector< double > & binEdgeX, const std::vector< double > & binEdgeY, const std::vector< double > & binEdgeZ, const std::string& )
00199 {
00200   return new Anaphe::AIDA_Histogram_native::AIDA_Histogram3D( title, binEdgeX, binEdgeY, binEdgeZ );
00201 }
00202 
00203 
00204 AIDA::Dev::IDevHistogram3D*
00205 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::createHistogram3D( int nBinsX, double lowerEdgeX, double upperEdgeX, int nBinsY, double lowerEdgeY, double upperEdgeY, int nBinsZ, double lowerEdgeZ, double upperEdgeZ )
00206 {
00207   return new Anaphe::AIDA_Histogram_native::AIDA_Histogram3D( emptyString, nBinsX, lowerEdgeX, upperEdgeX, nBinsY, lowerEdgeY, upperEdgeY, nBinsZ, lowerEdgeZ, upperEdgeZ );
00208 }
00209 
00210 
00211 AIDA::Dev::IDevHistogram3D*
00212 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::createCopy( const AIDA::IHistogram3D & original )
00213 {
00214   try {
00215     const Anaphe::AIDA_Histogram_native::AIDA_Histogram3D& h = dynamic_cast< const Anaphe::AIDA_Histogram_native::AIDA_Histogram3D& >( original );
00216     return new Anaphe::AIDA_Histogram_native::AIDA_Histogram3D( h );
00217   }
00218   catch( std::bad_cast ) {
00219     return new Anaphe::AIDA_Histogram_native::AIDA_Histogram3D( original );
00220   }
00221 }
00222 
00223 
00224 AIDA::Dev::IDevProfile1D*
00225 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::createProfile1D( const std::string & title, int nBins, double lowerEdge, double upperEdge, const std::string& )
00226 {
00227   return new Anaphe::AIDA_Histogram_native::AIDA_Profile1D( title, nBins, lowerEdge, upperEdge );
00228 }
00229 
00230 
00231 AIDA::Dev::IDevProfile1D*
00232 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::createProfile1D( const std::string & title, int nBins, double lowerEdge, double upperEdge, double lowerValue, double upperValue, const std::string& )
00233 {
00234   return new Anaphe::AIDA_Histogram_native::AIDA_BoundedProfile1D( title, nBins, lowerEdge, upperEdge, lowerValue, upperValue );
00235 }
00236 
00237 AIDA::Dev::IDevProfile1D*
00238 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::createProfile1D( const std::string & title, const std::vector< double > & binEdge, const std::string& )
00239 {
00240   return new Anaphe::AIDA_Histogram_native::AIDA_Profile1D( title, binEdge );
00241 }
00242 
00243 
00244 AIDA::Dev::IDevProfile1D*
00245 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::createProfile1D( const std::string & title, const std::vector< double > & binEdge, double lowerValue, double upperValue, const std::string& )
00246 {
00247   return new Anaphe::AIDA_Histogram_native::AIDA_BoundedProfile1D( title, binEdge, lowerValue, upperValue );
00248 }
00249 
00250 
00251 AIDA::Dev::IDevProfile1D*
00252 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::createProfile1D( int nBins, double lowerEdge, double upperEdge )
00253 {
00254   return new Anaphe::AIDA_Histogram_native::AIDA_Profile1D( emptyString, nBins, lowerEdge, upperEdge );
00255 }
00256 
00257 
00258 AIDA::Dev::IDevProfile1D*
00259 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::createProfile1D( int nBins, double lowerEdge, double upperEdge, double lowerValue, double upperValue )
00260 {
00261   return new Anaphe::AIDA_Histogram_native::AIDA_BoundedProfile1D( emptyString, nBins, lowerEdge, upperEdge, lowerValue, upperValue );
00262 }
00263 
00264 
00265 AIDA::Dev::IDevProfile1D*
00266 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::createCopy( const AIDA::IProfile1D & original )
00267 {
00268   try {
00269     const Anaphe::AIDA_Histogram_native::AIDA_Profile1D& h = dynamic_cast< const Anaphe::AIDA_Histogram_native::AIDA_Profile1D& >( original );
00270     try {
00271       const Anaphe::AIDA_Histogram_native::AIDA_BoundedProfile1D& b = dynamic_cast< const Anaphe::AIDA_Histogram_native::AIDA_BoundedProfile1D& >( h );
00272       return new Anaphe::AIDA_Histogram_native::AIDA_BoundedProfile1D( b );
00273     }
00274     catch( std::bad_cast ) {
00275       return new Anaphe::AIDA_Histogram_native::AIDA_Profile1D( h );
00276     }
00277   }
00278   catch( std::bad_cast ) {
00279     return new Anaphe::AIDA_Histogram_native::AIDA_Profile1D( original );
00280   }
00281 }
00282 
00283 
00284 AIDA::Dev::IDevProfile2D*
00285 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::createProfile2D( const std::string & title, int nBinsX, double lowerEdgeX, double upperEdgeX, int nBinsY, double lowerEdgeY, double upperEdgeY, const std::string& )
00286 {
00287   return new Anaphe::AIDA_Histogram_native::AIDA_Profile2D( title, nBinsX, lowerEdgeX, upperEdgeX, nBinsY, lowerEdgeY, upperEdgeY );
00288 }
00289 
00290 
00291 AIDA::Dev::IDevProfile2D*
00292 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::createProfile2D( const std::string & title, int nBinsX, double lowerEdgeX, double upperEdgeX, int nBinsY, double lowerEdgeY, double upperEdgeY, double lowerValue, double upperValue, const std::string& )
00293 {
00294   return new Anaphe::AIDA_Histogram_native::AIDA_BoundedProfile2D( title, nBinsX, lowerEdgeX, upperEdgeX, nBinsY, lowerEdgeY, upperEdgeY, lowerValue, upperValue );
00295 }
00296 
00297 
00298 AIDA::Dev::IDevProfile2D*
00299 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::createProfile2D( const std::string & title, const std::vector< double > & binEdgeX, const std::vector< double > & binEdgeY, const std::string& )
00300 {
00301   return new Anaphe::AIDA_Histogram_native::AIDA_Profile2D( title, binEdgeX, binEdgeY );
00302 }
00303 
00304 
00305 AIDA::Dev::IDevProfile2D*
00306 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::createProfile2D( const std::string & title, const std::vector< double > & binEdgeX, const std::vector< double > & binEdgeY, double lowerValue, double upperValue, const std::string& )
00307 {
00308   return new Anaphe::AIDA_Histogram_native::AIDA_BoundedProfile2D( title, binEdgeX, binEdgeY, lowerValue, upperValue );
00309 }
00310 
00311 
00312 AIDA::Dev::IDevProfile2D*
00313 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::createProfile2D( int nBinsX, double lowerEdgeX, double upperEdgeX, int nBinsY, double lowerEdgeY, double upperEdgeY )
00314 {
00315   return new Anaphe::AIDA_Histogram_native::AIDA_Profile2D( emptyString, nBinsX, lowerEdgeX, upperEdgeX, nBinsY, lowerEdgeY, upperEdgeY );
00316 }
00317 
00318 
00319 AIDA::Dev::IDevProfile2D*
00320 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::createProfile2D( int nBinsX, double lowerEdgeX, double upperEdgeX, int nBinsY, double lowerEdgeY, double upperEdgeY, double lowerValue, double upperValue )
00321 {
00322   return new Anaphe::AIDA_Histogram_native::AIDA_BoundedProfile2D( emptyString, nBinsX, lowerEdgeX, upperEdgeX, nBinsY, lowerEdgeY, upperEdgeY, lowerValue, upperValue );
00323 }
00324 
00325 
00326 AIDA::Dev::IDevProfile2D*
00327 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::createCopy( const AIDA::IProfile2D & original )
00328 {
00329   try {
00330     const Anaphe::AIDA_Histogram_native::AIDA_Profile2D& h = dynamic_cast< const Anaphe::AIDA_Histogram_native::AIDA_Profile2D& >( original );
00331     try {
00332       const Anaphe::AIDA_Histogram_native::AIDA_BoundedProfile2D& b = dynamic_cast< const Anaphe::AIDA_Histogram_native::AIDA_BoundedProfile2D& >( h );
00333       return new Anaphe::AIDA_Histogram_native::AIDA_BoundedProfile2D( b );
00334     }
00335     catch( std::bad_cast ) {
00336       return new Anaphe::AIDA_Histogram_native::AIDA_Profile2D( h );
00337     }
00338   }
00339   catch( std::bad_cast ) {
00340     return new Anaphe::AIDA_Histogram_native::AIDA_Profile2D( original );
00341   }
00342 }
00343 
00344 
00345 AIDA::Dev::IDevHistogram1D*
00346 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::add( const AIDA::IHistogram1D & a, const AIDA::IHistogram1D & b )
00347 {
00348   AIDA::Dev::IDevHistogram1D* p = createCopy( a );
00349   if ( ! ( p->add( b ) ) ) {
00350     delete p;
00351     p = 0;
00352   }
00353   return p;
00354 }
00355 
00356 
00357 AIDA::Dev::IDevHistogram2D*
00358 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::add( const AIDA::IHistogram2D & a, const AIDA::IHistogram2D & b )
00359 {
00360   AIDA::Dev::IDevHistogram2D* p = createCopy( a );
00361   if ( ! ( p->add( b ) ) ) {
00362     delete p;
00363     p = 0;
00364   }
00365   return p;
00366 }
00367 
00368 
00369 AIDA::Dev::IDevHistogram3D*
00370 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::add( const AIDA::IHistogram3D & a, const AIDA::IHistogram3D & b )
00371 {
00372   AIDA::Dev::IDevHistogram3D* p = createCopy( a );
00373   if ( ! ( p->add( b ) ) ) {
00374     delete p;
00375     p = 0;
00376   }
00377   return p;
00378 }
00379 
00380 
00381 AIDA::Dev::IDevHistogram1D*
00382 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::subtract( const AIDA::IHistogram1D & a, const AIDA::IHistogram1D & b )
00383 {
00384   AIDA::Dev::IDevHistogram1D* p = createCopy( b );
00385   p->scale( -1.0 );
00386   if ( ! ( p->add( a ) ) ) {
00387     delete p;
00388     p = 0;
00389   }
00390   return p;
00391 }
00392 
00393 
00394 AIDA::Dev::IDevHistogram2D*
00395 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::subtract( const AIDA::IHistogram2D & a, const AIDA::IHistogram2D & b )
00396 {
00397   AIDA::Dev::IDevHistogram2D* p = createCopy( b );
00398   p->scale( -1.0 );
00399   if ( ! ( p->add( a ) ) ) {
00400     delete p;
00401     p = 0;
00402   }
00403   return p;
00404 }
00405 
00406 
00407 AIDA::Dev::IDevHistogram3D*
00408 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::subtract( const AIDA::IHistogram3D & a, const AIDA::IHistogram3D & b )
00409 {
00410   AIDA::Dev::IDevHistogram3D* p = createCopy( b );
00411   p->scale( -1.0 );
00412   if ( ! ( p->add( a ) ) ) {
00413     delete p;
00414     p = 0;
00415   }
00416   return p;
00417 }
00418 
00419 
00420 AIDA::Dev::IDevHistogram1D*
00421 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::multiply( const AIDA::IHistogram1D & a, const AIDA::IHistogram1D & b )
00422 {
00423   const AIDA::IAxis& otherAxis = b.axis();
00424   const AIDA::IAxis& myAxis = a.axis();
00425   if ( otherAxis.bins() != myAxis.bins() ) return 0;
00426   for ( int iBin = 0; iBin < myAxis.bins(); ++iBin ) {
00427     const double otherLow = otherAxis.binLowerEdge( iBin );
00428     const double myLow = myAxis.binLowerEdge( iBin );
00429     if ( otherLow != myLow ) return 0;
00430   }
00431   if ( otherAxis.upperEdge() != myAxis.upperEdge() ) return 0;
00432 
00433   AIDA::Dev::IDevHistogram1D* p = createCopy( a );
00434   p->reset();
00435 
00436   for ( int i = -numberOfExtraBins; i < myAxis.bins(); ++i ) {
00437     const double heightA = a.binHeight(i);
00438     const double heightB = b.binHeight(i);
00439     const double height = heightA * heightB;
00440     const double errorA = a.binError(i);
00441     const double errorB = b.binError(i);
00442     const double error = std::sqrt( errorA*errorA + errorB*errorB);
00443     const double centreA = a.binMean(i);
00444     const double centreB = b.binMean(i);
00445     const double centre = ( ( height != 0 ) ? ( centreA*heightA + centreB*heightB ) / (heightA + heightB) : 0.5 * (centreA + centreB) );
00446     p->setBinContents( i, a.binEntries(i) + b.binEntries(i), height, error, centre );
00447   }
00448 
00449   return p;
00450 }
00451 
00452 
00453 AIDA::Dev::IDevHistogram2D*
00454 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::multiply( const AIDA::IHistogram2D & a, const AIDA::IHistogram2D & b )
00455 {
00456   const AIDA::IAxis& xAxisA = a.xAxis();
00457   const AIDA::IAxis& xAxisB = b.xAxis();
00458   if ( xAxisA.bins() != xAxisB.bins() ) return 0;
00459   for ( int iBin = 0; iBin < xAxisA.bins(); ++iBin ) {
00460     const double otherLow = xAxisA.binLowerEdge( iBin );
00461     const double myLow = xAxisB.binLowerEdge( iBin );
00462     if ( otherLow != myLow ) return 0;
00463   }
00464   if ( xAxisA.upperEdge() != xAxisB.upperEdge() ) return 0;
00465 
00466   const AIDA::IAxis& yAxisA = a.yAxis();
00467   const AIDA::IAxis& yAxisB = b.yAxis();
00468   if ( yAxisA.bins() != yAxisB.bins() ) return 0;
00469   for ( int iBin = 0; iBin < yAxisA.bins(); ++iBin ) {
00470     const double otherLow = yAxisA.binLowerEdge( iBin );
00471     const double myLow = yAxisB.binLowerEdge( iBin );
00472     if ( otherLow != myLow ) return 0;
00473   }
00474   if ( yAxisA.upperEdge() != yAxisB.upperEdge() ) return 0;
00475 
00476   AIDA::Dev::IDevHistogram2D* p = createCopy( a );
00477   p->reset();
00478 
00479   for ( int i = -numberOfExtraBins; i < xAxisA.bins(); ++i ) {
00480     for ( int j = -numberOfExtraBins; j < yAxisA.bins(); ++j ) {
00481       const double heightA = a.binHeight(i,j);
00482       const double heightB = b.binHeight(i,j);
00483       const double height = heightA * heightB;
00484       const double errorA = a.binError(i,j);
00485       const double errorB = b.binError(i,j);
00486       const double error = std::sqrt( errorA*errorA + errorB*errorB);
00487       const double centreXA = a.binMeanX(i,j);
00488       const double centreXB = b.binMeanX(i,j);
00489       const double centreX = ( ( height != 0 ) ? ( centreXA*heightA + centreXB*heightB ) / (heightA + heightB) : 0.5 * (centreXA + centreXB) );
00490       const double centreYA = a.binMeanY(i,j);
00491       const double centreYB = b.binMeanY(i,j);
00492       const double centreY = ( ( height != 0 ) ? ( centreYA*heightA + centreYB*heightB ) / (heightA + heightB) : 0.5 * (centreYA + centreYB) );
00493       p->setBinContents( i, j, a.binEntries(i,j) + b.binEntries(i,j), height, error, centreX, centreY );
00494     }
00495   }
00496 
00497   return p;
00498 }
00499 
00500 
00501 AIDA::Dev::IDevHistogram3D*
00502 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::multiply( const AIDA::IHistogram3D & a, const AIDA::IHistogram3D & b )
00503 {
00504   const AIDA::IAxis& xAxisA = a.xAxis();
00505   const AIDA::IAxis& xAxisB = b.xAxis();
00506   if ( xAxisA.bins() != xAxisB.bins() ) return 0;
00507   for ( int iBin = 0; iBin < xAxisA.bins(); ++iBin ) {
00508     const double otherLow = xAxisA.binLowerEdge( iBin );
00509     const double myLow = xAxisB.binLowerEdge( iBin );
00510     if ( otherLow != myLow ) return 0;
00511   }
00512   if ( xAxisA.upperEdge() != xAxisB.upperEdge() ) return 0;
00513 
00514   const AIDA::IAxis& yAxisA = a.yAxis();
00515   const AIDA::IAxis& yAxisB = b.yAxis();
00516   if ( yAxisA.bins() != yAxisB.bins() ) return 0;
00517   for ( int iBin = 0; iBin < yAxisA.bins(); ++iBin ) {
00518     const double otherLow = yAxisA.binLowerEdge( iBin );
00519     const double myLow = yAxisB.binLowerEdge( iBin );
00520     if ( otherLow != myLow ) return 0;
00521   }
00522   if ( yAxisA.upperEdge() != yAxisB.upperEdge() ) return 0;
00523 
00524   const AIDA::IAxis& zAxisA = a.zAxis();
00525   const AIDA::IAxis& zAxisB = b.zAxis();
00526   if ( zAxisA.bins() != zAxisB.bins() ) return 0;
00527   for ( int iBin = 0; iBin < zAxisA.bins(); ++iBin ) {
00528     const double otherLow = zAxisA.binLowerEdge( iBin );
00529     const double myLow = zAxisB.binLowerEdge( iBin );
00530     if ( otherLow != myLow ) return 0;
00531   }
00532   if ( zAxisA.upperEdge() != zAxisB.upperEdge() ) return 0;
00533 
00534   AIDA::Dev::IDevHistogram3D* p = createCopy( a );
00535   p->reset();
00536 
00537   for ( int i = -numberOfExtraBins; i < xAxisA.bins(); ++i ) {
00538     for ( int j = -numberOfExtraBins; j < yAxisA.bins(); ++j ) {
00539       for ( int k = -numberOfExtraBins; k < zAxisA.bins(); ++k ) {
00540         const double heightA = a.binHeight(i,j,k);
00541         const double heightB = b.binHeight(i,j,k);
00542         const double height = heightA * heightB;
00543         const double errorA = a.binError(i,j,k);
00544         const double errorB = b.binError(i,j,k);
00545         const double error = std::sqrt( errorA*errorA + errorB*errorB);
00546         const double centreXA = a.binMeanX(i,j,k);
00547         const double centreXB = b.binMeanX(i,j,k);
00548         const double centreX = ( ( height != 0 ) ? ( centreXA*heightA + centreXB*heightB ) / (heightA + heightB) : 0.5 * (centreXA + centreXB) );
00549         const double centreYA = a.binMeanY(i,j,k);
00550         const double centreYB = b.binMeanY(i,j,k);
00551         const double centreY = ( ( height != 0 ) ? ( centreYA*heightA + centreYB*heightB ) / (heightA + heightB) : 0.5 * (centreYA + centreYB) );
00552         const double centreZA = a.binMeanZ(i,j,k);
00553         const double centreZB = b.binMeanZ(i,j,k);
00554         const double centreZ = ( ( height != 0 ) ? ( centreZA*heightA + centreZB*heightB ) / (heightA + heightB) : 0.5 * (centreZA + centreZB) );
00555         p->setBinContents( i, j, k, a.binEntries(i,j,k) + b.binEntries(i,j,k), height, error, centreX, centreY, centreZ );
00556       }
00557     }
00558   }
00559 
00560   return p;
00561 }
00562 
00563 
00564 AIDA::Dev::IDevHistogram1D*
00565 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::divide( const AIDA::IHistogram1D & a, const AIDA::IHistogram1D & b )
00566 {
00567   const AIDA::IAxis& xAxisA = a.axis();
00568   const AIDA::IAxis& xAxisB = b.axis();
00569   if ( xAxisA.bins() != xAxisB.bins() ) return 0;
00570   for ( int iBin = 0; iBin < xAxisA.bins(); ++iBin ) {
00571     const double otherLow = xAxisA.binLowerEdge( iBin );
00572     const double myLow = xAxisB.binLowerEdge( iBin );
00573     if ( otherLow != myLow ) return 0;
00574   }
00575   if ( xAxisA.upperEdge() != xAxisB.upperEdge() ) return 0;
00576 
00577   AIDA::Dev::IDevHistogram1D* p = createCopy( a );
00578   p->reset();
00579 
00580   for ( int i = -numberOfExtraBins; i < xAxisA.bins(); ++i ) {
00581     const double heightA = a.binHeight(i);
00582     const double heightB = b.binHeight(i);
00583     const double height = ( ( heightB != 0 ) ? heightA / heightB : 0 ) ;
00584     double error = 0;
00585     if ( heightB != 0 ) {
00586       const double errorA = a.binError(i);
00587       const double errorB = b.binError(i);
00588       const double hb2 = heightB * heightB;
00589       error = ( std::sqrt( errorA * errorA * hb2 + errorB * errorB * heightA * heightA ) ) / hb2;
00590     }
00591     const double centreXA = a.binMean(i);
00592     const double centreXB = b.binMean(i);
00593     const double centreX = ( ( height != 0 ) ? ( centreXA*heightA + centreXB*heightB ) / (heightA+heightB) : 0.5 * (centreXA + centreXB) );
00594     p->setBinContents( i, a.binEntries(i) + b.binEntries(i), height, error, centreX );
00595   }
00596 
00597   return p;
00598 }
00599 
00600 
00601 AIDA::Dev::IDevHistogram2D*
00602 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::divide( const AIDA::IHistogram2D & a, const AIDA::IHistogram2D & b )
00603 {
00604   const AIDA::IAxis& xAxisA = a.xAxis();
00605   const AIDA::IAxis& xAxisB = b.xAxis();
00606   if ( xAxisA.bins() != xAxisB.bins() ) return 0;
00607   for ( int iBin = 0; iBin < xAxisA.bins(); ++iBin ) {
00608     const double otherLow = xAxisA.binLowerEdge( iBin );
00609     const double myLow = xAxisB.binLowerEdge( iBin );
00610     if ( otherLow != myLow ) return 0;
00611   }
00612   if ( xAxisA.upperEdge() != xAxisB.upperEdge() ) return 0;
00613 
00614   const AIDA::IAxis& yAxisA = a.yAxis();
00615   const AIDA::IAxis& yAxisB = b.yAxis();
00616   if ( yAxisA.bins() != yAxisB.bins() ) return 0;
00617   for ( int iBin = 0; iBin < yAxisA.bins(); ++iBin ) {
00618     const double otherLow = yAxisA.binLowerEdge( iBin );
00619     const double myLow = yAxisB.binLowerEdge( iBin );
00620     if ( otherLow != myLow ) return 0;
00621   }
00622   if ( yAxisA.upperEdge() != yAxisB.upperEdge() ) return 0;
00623 
00624   AIDA::Dev::IDevHistogram2D* p = createCopy( a );
00625   p->reset();
00626 
00627   for ( int i = -numberOfExtraBins; i < xAxisA.bins(); ++i ) {
00628     for ( int j = -numberOfExtraBins; j < yAxisA.bins(); ++j ) {
00629       const double heightA = a.binHeight(i,j);
00630       const double heightB = b.binHeight(i,j);
00631       const double height = ( ( heightB != 0 ) ? heightA / heightB : 0 ) ;
00632       double error = 0;
00633       if ( heightB != 0 ) {
00634         const double errorA = a.binError(i,j);
00635         const double errorB = b.binError(i,j);
00636         const double hb2 = heightB * heightB;
00637         error = ( std::sqrt( errorA * errorA * hb2 + errorB * errorB * heightA * heightA ) ) / hb2;
00638       }
00639       const double centreXA = a.binMeanX(i,j);
00640       const double centreXB = b.binMeanX(i,j);
00641       const double centreX = ( ( height != 0 ) ? ( centreXA*heightA + centreXB*heightB ) / (heightA+heightB) : 0.5 * (centreXA + centreXB) );
00642       const double centreYA = a.binMeanY(i,j);
00643       const double centreYB = b.binMeanY(i,j);
00644       const double centreY = ( ( height != 0 ) ? ( centreYA*heightA + centreYB*heightB ) / (heightA+heightB) : 0.5 * (centreYA + centreYB) );
00645       p->setBinContents( i, j, a.binEntries(i,j) + b.binEntries(i,j), height, error, centreX, centreY );
00646     }
00647   }
00648 
00649   return p;
00650 }
00651 
00652 
00653 AIDA::Dev::IDevHistogram3D*
00654 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::divide( const AIDA::IHistogram3D & a, const AIDA::IHistogram3D & b )
00655 {
00656   const AIDA::IAxis& xAxisA = a.xAxis();
00657   const AIDA::IAxis& xAxisB = b.xAxis();
00658   if ( xAxisA.bins() != xAxisB.bins() ) return 0;
00659   for ( int iBin = 0; iBin < xAxisA.bins(); ++iBin ) {
00660     const double otherLow = xAxisA.binLowerEdge( iBin );
00661     const double myLow = xAxisB.binLowerEdge( iBin );
00662     if ( otherLow != myLow ) return 0;
00663   }
00664   if ( xAxisA.upperEdge() != xAxisB.upperEdge() ) return 0;
00665 
00666   const AIDA::IAxis& yAxisA = a.yAxis();
00667   const AIDA::IAxis& yAxisB = b.yAxis();
00668   if ( yAxisA.bins() != yAxisB.bins() ) return 0;
00669   for ( int iBin = 0; iBin < yAxisA.bins(); ++iBin ) {
00670     const double otherLow = yAxisA.binLowerEdge( iBin );
00671     const double myLow = yAxisB.binLowerEdge( iBin );
00672     if ( otherLow != myLow ) return 0;
00673   }
00674   if ( yAxisA.upperEdge() != yAxisB.upperEdge() ) return 0;
00675 
00676   const AIDA::IAxis& zAxisA = a.zAxis();
00677   const AIDA::IAxis& zAxisB = b.zAxis();
00678   if ( zAxisA.bins() != zAxisB.bins() ) return 0;
00679   for ( int iBin = 0; iBin < zAxisA.bins(); ++iBin ) {
00680     const double otherLow = zAxisA.binLowerEdge( iBin );
00681     const double myLow = zAxisB.binLowerEdge( iBin );
00682     if ( otherLow != myLow ) return 0;
00683   }
00684   if ( zAxisA.upperEdge() != zAxisB.upperEdge() ) return 0;
00685 
00686   AIDA::Dev::IDevHistogram3D* p = createCopy( a );
00687   p->reset();
00688 
00689   for ( int i = -numberOfExtraBins; i < xAxisA.bins(); ++i ) {
00690     for ( int j = -numberOfExtraBins; j < yAxisA.bins(); ++j ) {
00691       for ( int k = -numberOfExtraBins; k < zAxisA.bins(); ++k ) {
00692         const double heightA = a.binHeight(i,j,k);
00693         const double heightB = b.binHeight(i,j,k);
00694         const double height = ( ( heightB != 0 ) ? heightA / heightB : 0 ) ;
00695         double error = 0;
00696         if ( heightB != 0 ) {
00697           const double errorA = a.binError(i,j,k);
00698           const double errorB = b.binError(i,j,k);
00699           const double hb2 = heightB * heightB;
00700           error = ( std::sqrt( errorA * errorA * hb2 + errorB * errorB * heightA * heightA ) ) / hb2;
00701         }
00702         const double centreXA = a.binMeanX(i,j,k);
00703         const double centreXB = b.binMeanX(i,j,k);
00704         const double centreX = ( ( height != 0 ) ? ( centreXA*heightA + centreXB*heightB ) / (heightA+heightB) : 0.5 * (centreXA + centreXB) );
00705         const double centreYA = a.binMeanY(i,j,k);
00706         const double centreYB = b.binMeanY(i,j,k);
00707         const double centreY = ( ( height != 0 ) ? ( centreYA*heightA + centreYB*heightB ) / (heightA+heightB) : 0.5 * (centreYA + centreYB) );
00708         const double centreZA = a.binMeanZ(i,j,k);
00709         const double centreZB = b.binMeanZ(i,j,k);
00710         const double centreZ = ( ( height != 0 ) ? ( centreZA*heightA + centreZB*heightB ) / (heightA+heightB) : 0.5 * (centreZA + centreZB) );
00711         p->setBinContents( i, j, k, a.binEntries(i,j,k) + b.binEntries(i,j,k), height, error, centreX, centreY, centreZ );
00712       }
00713     }
00714   }
00715 
00716   return p;
00717 }
00718 
00719 
00720 AIDA::Dev::IDevHistogram1D*
00721 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::projectionX( const AIDA::IHistogram2D & h )
00722 {
00723   AIDA::Dev::IDevHistogram1D* p = 0;
00724   const AIDA::IAxis& axis = h.xAxis();
00725   if ( axis.isFixedBinning() ) {
00726     p = new Anaphe::AIDA_Histogram_native::AIDA_Histogram1D( h.title(), axis.bins(), axis.lowerEdge(), axis.upperEdge() );
00727   }
00728   else {
00729     std::vector< double > edges( axis.bins() + 1 );
00730     for ( int i = 0; i < axis.bins(); ++i ) edges[i] = axis.binLowerEdge( i );
00731     edges[ axis.bins() ] = axis.upperEdge();
00732     p = new Anaphe::AIDA_Histogram_native::AIDA_Histogram1D( h.title(), edges );
00733   }
00734 
00735   for ( int i = -numberOfExtraBins; i < axis.bins(); ++i ) {
00736     double errorSquared = 0;
00737     double binMeanX = 0;
00738     double binHeight = 0;
00739     const AIDA::IAxis& axisY = h.yAxis();
00740     for ( int j = -numberOfExtraBins; j < axisY.bins(); ++j ) {
00741       const double be = h.binError( i, j );
00742       errorSquared += be * be;
00743       const double height = h.binHeight( i, j );
00744       binHeight += height;
00745       binMeanX += h.binMeanX( i, j ) * height;
00746     }
00747     if ( binHeight != 0 ) binMeanX /= binHeight;
00748     p->setBinContents( i,
00749                        h.binEntriesX(i),
00750                        binHeight,
00751                        std::sqrt( errorSquared ),
00752                        binMeanX );
00753   }
00754 
00755   return p;
00756 }
00757 
00758 
00759 AIDA::Dev::IDevHistogram1D*
00760 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::projectionY( const AIDA::IHistogram2D & h )
00761 {
00762   AIDA::Dev::IDevHistogram1D* p = 0;
00763   const AIDA::IAxis& axis = h.yAxis();
00764   if ( axis.isFixedBinning() ) {
00765     p = new Anaphe::AIDA_Histogram_native::AIDA_Histogram1D( h.title(), axis.bins(), axis.lowerEdge(), axis.upperEdge() );
00766   }
00767   else {
00768     std::vector< double > edges( axis.bins() + 1 );
00769     for ( int i = 0; i < axis.bins(); ++i ) edges[i] = axis.binLowerEdge( i );
00770     edges[ axis.bins() ] = axis.upperEdge();
00771     p = new Anaphe::AIDA_Histogram_native::AIDA_Histogram1D( h.title(), edges );
00772   }
00773 
00774   for ( int i = -numberOfExtraBins; i < axis.bins(); ++i ) {
00775     double errorSquared = 0;
00776     double binMeanY = 0;
00777     double binHeight = 0;
00778     const AIDA::IAxis& axisX = h.xAxis();
00779     for ( int j = -numberOfExtraBins; j < axisX.bins(); ++j ) {
00780       const double be = h.binError( j, i );
00781       errorSquared += be * be;
00782       const double height = h.binHeight( j, i );
00783       binHeight += height;
00784       binMeanY += h.binMeanY( j, i ) * height;
00785     }
00786     if ( binHeight != 0 ) binMeanY /= binHeight;
00787     p->setBinContents( i,
00788                        h.binEntriesY(i),
00789                        binHeight,
00790                        std::sqrt( errorSquared ),
00791                        binMeanY );
00792   }
00793 
00794   return p;
00795 }
00796 
00797 
00798 
00799 AIDA::Dev::IDevHistogram1D*
00800 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::sliceX( const AIDA::IHistogram2D & h, int indexY )
00801 {
00802   AIDA::Dev::IDevHistogram1D* p = 0;
00803   const AIDA::IAxis& axis = h.xAxis();
00804   if ( axis.isFixedBinning() ) {
00805     p = new Anaphe::AIDA_Histogram_native::AIDA_Histogram1D( h.title(), axis.bins(), axis.lowerEdge(), axis.upperEdge() );
00806   }
00807   else {
00808     std::vector< double > edges( axis.bins() + 1 );
00809     for ( int i = 0; i < axis.bins(); ++i ) edges[i] = axis.binLowerEdge( i );
00810     edges[ axis.bins() ] = axis.upperEdge();
00811     p = new Anaphe::AIDA_Histogram_native::AIDA_Histogram1D( h.title(), edges );
00812   }
00813 
00814   for ( int i = -numberOfExtraBins; i < axis.bins(); ++i ) {
00815     p->setBinContents( i,
00816                        h.binEntries(i, indexY),
00817                        h.binHeight(i, indexY),
00818                        h.binError(i, indexY ),
00819                        h.binMeanX(i, indexY) );
00820   }
00821 
00822   return p;
00823 }
00824 
00825 
00826 AIDA::Dev::IDevHistogram1D*
00827 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::sliceY( const AIDA::IHistogram2D & h, int indexX )
00828 {
00829   AIDA::Dev::IDevHistogram1D* p = 0;
00830   const AIDA::IAxis& axis = h.yAxis();
00831   if ( axis.isFixedBinning() ) {
00832     p = new Anaphe::AIDA_Histogram_native::AIDA_Histogram1D( h.title(), axis.bins(), axis.lowerEdge(), axis.upperEdge() );
00833   }
00834   else {
00835     std::vector< double > edges( axis.bins() + 1 );
00836     for ( int i = 0; i < axis.bins(); ++i ) edges[i] = axis.binLowerEdge( i );
00837     edges[ axis.bins() ] = axis.upperEdge();
00838     p = new Anaphe::AIDA_Histogram_native::AIDA_Histogram1D( h.title(), edges );
00839   }
00840 
00841   for ( int i = -numberOfExtraBins; i < axis.bins(); ++i ) {
00842     p->setBinContents( i,
00843                        h.binEntries(indexX, i),
00844                        h.binHeight(indexX, i),
00845                        h.binError(indexX, i ),
00846                        h.binMeanY(indexX, i) );
00847   }
00848 
00849   return p;
00850 }
00851 
00852 
00853 AIDA::Dev::IDevHistogram1D*
00854 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::sliceX( const AIDA::IHistogram2D & h, int indexY1, int indexY2 )
00855 {
00856   AIDA::Dev::IDevHistogram1D* p = 0;
00857   const AIDA::IAxis& axis = h.xAxis();
00858   if ( axis.isFixedBinning() ) {
00859     p = new Anaphe::AIDA_Histogram_native::AIDA_Histogram1D( h.title(), axis.bins(), axis.lowerEdge(), axis.upperEdge() );
00860   }
00861   else {
00862     std::vector< double > edges( axis.bins() + 1 );
00863     for ( int i = 0; i < axis.bins(); ++i ) edges[i] = axis.binLowerEdge( i );
00864     edges[ axis.bins() ] = axis.upperEdge();
00865     p = new Anaphe::AIDA_Histogram_native::AIDA_Histogram1D( h.title(), edges );
00866   }
00867 
00868   for ( int i = -numberOfExtraBins; i < axis.bins(); ++i ) {
00869     int entries = 0;
00870     double height = 0;
00871     double errorSquared = 0;
00872     double binMean = 0;
00873     for ( int j = indexY1; j <= indexY2; ++j ) {
00874       entries += h.binEntries(i, j );
00875       const double tempHeight = h.binHeight(i, j );
00876       height += tempHeight;
00877       binMean += h.binMeanX(i,j) * tempHeight;
00878       const double error = h.binError( i, j );
00879       errorSquared += error * error;
00880     };
00881     if ( height != 0 ) binMean /= height;
00882     p->setBinContents( i,
00883                        entries,
00884                        height,
00885                        std::sqrt( errorSquared ),
00886                        binMean );
00887   }
00888 
00889   return p;
00890 }
00891 
00892 
00893 AIDA::Dev::IDevHistogram1D*
00894 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::sliceY( const AIDA::IHistogram2D & h, int indexX1, int indexX2 )
00895 {
00896   AIDA::Dev::IDevHistogram1D* p = 0;
00897   const AIDA::IAxis& axis = h.yAxis();
00898   if ( axis.isFixedBinning() ) {
00899     p = new Anaphe::AIDA_Histogram_native::AIDA_Histogram1D( h.title(), axis.bins(), axis.lowerEdge(), axis.upperEdge() );
00900   }
00901   else {
00902     std::vector< double > edges( axis.bins() + 1 );
00903     for ( int i = 0; i < axis.bins(); ++i ) edges[i] = axis.binLowerEdge( i );
00904     edges[ axis.bins() ] = axis.upperEdge();
00905     p = new Anaphe::AIDA_Histogram_native::AIDA_Histogram1D( h.title(), edges );
00906   }
00907 
00908   for ( int i = -numberOfExtraBins; i < axis.bins(); ++i ) {
00909     int entries = 0;
00910     double height = 0;
00911     double errorSquared = 0;
00912     double binMean = 0;
00913     for ( int j = indexX1; j <= indexX2; ++j ) {
00914       entries += h.binEntries(j, i );
00915       const double tempHeight = h.binHeight(i, j );
00916       height += tempHeight;
00917       binMean += h.binMeanY(i,j) * tempHeight;
00918       const double error = h.binError( j, i );
00919       errorSquared += error * error;
00920     };
00921     if ( height != 0 ) binMean /= height;
00922     p->setBinContents( i,
00923                        entries,
00924                        height,
00925                        std::sqrt( errorSquared ),
00926                        binMean );
00927   }
00928 
00929   return p;
00930 }
00931 
00932 
00933 AIDA::Dev::IDevHistogram2D*
00934 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::projectionXY( const AIDA::IHistogram3D & h )
00935 {
00936   AIDA::Dev::IDevHistogram2D* p = 0;
00937   const AIDA::IAxis& xAxis = h.xAxis();
00938   const AIDA::IAxis& yAxis = h.yAxis();
00939   const AIDA::IAxis& zAxis = h.zAxis();
00940   if ( xAxis.isFixedBinning() ) {
00941     p = new Anaphe::AIDA_Histogram_native::AIDA_Histogram2D( h.title(), xAxis.bins(), xAxis.lowerEdge(), xAxis.upperEdge(), yAxis.bins(), yAxis.lowerEdge(), yAxis.upperEdge() );
00942   }
00943   else {
00944     std::vector< double > edgesX( xAxis.bins() + 1 );
00945     for ( int i = 0; i < xAxis.bins(); ++i ) edgesX[i] = xAxis.binLowerEdge( i );
00946     edgesX[ xAxis.bins() ] = xAxis.upperEdge();
00947     std::vector< double > edgesY( yAxis.bins() + 1 );
00948     for ( int i = 0; i < yAxis.bins(); ++i ) edgesY[i] = yAxis.binLowerEdge( i );
00949     edgesY[ yAxis.bins() ] = yAxis.upperEdge();
00950     p = new Anaphe::AIDA_Histogram_native::AIDA_Histogram2D( h.title(), edgesX, edgesY );
00951   }
00952 
00953   for ( int i = -numberOfExtraBins; i < xAxis.bins(); ++i ) {
00954     for ( int j = -numberOfExtraBins; j < yAxis.bins(); ++j ) {
00955       int entries = 0;
00956       double height = 0;
00957       double errorSquared = 0;
00958       double binMeanX = 0;
00959       double binMeanY = 0;
00960       for ( int k = -numberOfExtraBins; k < zAxis.bins(); ++k ) {
00961         entries += h.binEntries( i, j, k );
00962         const double tempHeight = h.binHeight( i, j, k );
00963         height += tempHeight;
00964         binMeanX += h.binMeanX( i, j, k ) * tempHeight;
00965         binMeanY += h.binMeanY( i, j, k ) * tempHeight;
00966         const double error = h.binError( i, j, k );
00967         errorSquared += error*error;
00968       }
00969       if ( height != 0 ) {
00970         binMeanX /= height;
00971         binMeanY /= height;
00972       }
00973       p->setBinContents( i, j, entries, height, std::sqrt( errorSquared ), binMeanX, binMeanY );
00974     }
00975   }
00976 
00977   return p;
00978 }
00979 
00980 
00981 AIDA::Dev::IDevHistogram2D*
00982 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::projectionXZ( const AIDA::IHistogram3D & h )
00983 {
00984   AIDA::Dev::IDevHistogram2D* p = 0;
00985   const AIDA::IAxis& xAxis = h.xAxis();
00986   const AIDA::IAxis& yAxis = h.yAxis();
00987   const AIDA::IAxis& zAxis = h.zAxis();
00988   if ( xAxis.isFixedBinning() ) {
00989     p = new Anaphe::AIDA_Histogram_native::AIDA_Histogram2D( h.title(), xAxis.bins(), xAxis.lowerEdge(), xAxis.upperEdge(), zAxis.bins(), zAxis.lowerEdge(), zAxis.upperEdge() );
00990   }
00991   else {
00992     std::vector< double > edgesX( xAxis.bins() + 1 );
00993     for ( int i = 0; i < xAxis.bins(); ++i ) edgesX[i] = xAxis.binLowerEdge( i );
00994     edgesX[ xAxis.bins() ] = xAxis.upperEdge();
00995     std::vector< double > edgesZ( zAxis.bins() + 1 );
00996     for ( int i = 0; i < zAxis.bins(); ++i ) edgesZ[i] = zAxis.binLowerEdge( i );
00997     edgesZ[ zAxis.bins() ] = zAxis.upperEdge();
00998     p = new Anaphe::AIDA_Histogram_native::AIDA_Histogram2D( h.title(), edgesX, edgesZ );
00999   }
01000 
01001   for ( int i = -numberOfExtraBins; i < xAxis.bins(); ++i ) {
01002     for ( int j = -numberOfExtraBins; j < zAxis.bins(); ++j ) {
01003       int entries = 0;
01004       double height = 0;
01005       double errorSquared = 0;
01006       double binMeanX = 0;
01007       double binMeanZ = 0;
01008       for ( int k = -numberOfExtraBins; k < yAxis.bins(); ++k ) {
01009         entries += h.binEntries( i, k, j );
01010         const double tempHeight = h.binHeight( i, k, j );
01011         height += tempHeight;
01012         binMeanX += h.binMeanX( i, k, j ) * tempHeight;
01013         binMeanZ += h.binMeanZ( i, k, j ) * tempHeight;
01014         const double error = h.binError( i, k, j );
01015         errorSquared += error*error;
01016       }
01017       if ( height != 0 ) {
01018         binMeanX /= height;
01019         binMeanZ /= height;
01020       }
01021       p->setBinContents( i, j, entries, height, std::sqrt( errorSquared ), binMeanX, binMeanZ );
01022     }
01023   }
01024 
01025   return p;
01026 }
01027 
01028 
01029 AIDA::Dev::IDevHistogram2D*
01030 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::projectionYZ( const AIDA::IHistogram3D & h )
01031 {
01032   AIDA::Dev::IDevHistogram2D* p = 0;
01033   const AIDA::IAxis& xAxis = h.xAxis();
01034   const AIDA::IAxis& yAxis = h.yAxis();
01035   const AIDA::IAxis& zAxis = h.zAxis();
01036   if ( yAxis.isFixedBinning() ) {
01037     p = new Anaphe::AIDA_Histogram_native::AIDA_Histogram2D( h.title(), yAxis.bins(), yAxis.lowerEdge(), yAxis.upperEdge(), zAxis.bins(), zAxis.lowerEdge(), zAxis.upperEdge() );
01038   }
01039   else {
01040     std::vector< double > edgesY( yAxis.bins() + 1 );
01041     for ( int i = 0; i < yAxis.bins(); ++i ) edgesY[i] = yAxis.binLowerEdge( i );
01042     edgesY[ yAxis.bins() ] = yAxis.upperEdge();
01043     std::vector< double > edgesZ( zAxis.bins() + 1 );
01044     for ( int i = 0; i < zAxis.bins(); ++i ) edgesZ[i] = zAxis.binLowerEdge( i );
01045     edgesZ[ zAxis.bins() ] = zAxis.upperEdge();
01046     p = new Anaphe::AIDA_Histogram_native::AIDA_Histogram2D( h.title(), edgesY, edgesZ );
01047   }
01048 
01049   for ( int i = -numberOfExtraBins; i < yAxis.bins(); ++i ) {
01050     for ( int j = -numberOfExtraBins; j < zAxis.bins(); ++j ) {
01051       int entries = 0;
01052       double height = 0;
01053       double errorSquared = 0;
01054       double binMeanY = 0;
01055       double binMeanZ = 0;
01056       for ( int k = -numberOfExtraBins; k < xAxis.bins(); ++k ) {
01057         entries += h.binEntries( k, i, j );
01058         const double tempHeight = h.binHeight( k, i, j );
01059         height += tempHeight;
01060         binMeanY += h.binMeanY( k, i, j ) * tempHeight;
01061         binMeanZ += h.binMeanZ( k, i, j ) * tempHeight;
01062         const double error = h.binError( k, i, j );
01063         errorSquared += error*error;
01064       }
01065       if ( height != 0 ) {
01066         binMeanY /= height;
01067         binMeanZ /= height;
01068       }
01069       p->setBinContents( i, j, entries, height, std::sqrt( errorSquared ), binMeanY, binMeanZ );
01070     }
01071   }
01072 
01073   return p;
01074 }
01075 
01076 
01077 AIDA::Dev::IDevHistogram2D*
01078 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::sliceXY( const AIDA::IHistogram3D & h, int indexZ1, int indexZ2 )
01079 {
01080   AIDA::Dev::IDevHistogram2D* p = 0;
01081   const AIDA::IAxis& xAxis = h.xAxis();
01082   const AIDA::IAxis& yAxis = h.yAxis();
01083   if ( xAxis.isFixedBinning() ) {
01084     p = new Anaphe::AIDA_Histogram_native::AIDA_Histogram2D( h.title(), xAxis.bins(), xAxis.lowerEdge(), xAxis.upperEdge(), yAxis.bins(), yAxis.lowerEdge(), yAxis.upperEdge() );
01085   }
01086   else {
01087     std::vector< double > edgesX( xAxis.bins() + 1 );
01088     for ( int i = 0; i < xAxis.bins(); ++i ) edgesX[i] = xAxis.binLowerEdge( i );
01089     edgesX[ xAxis.bins() ] = xAxis.upperEdge();
01090     std::vector< double > edgesY( yAxis.bins() + 1 );
01091     for ( int i = 0; i < yAxis.bins(); ++i ) edgesY[i] = yAxis.binLowerEdge( i );
01092     edgesY[ yAxis.bins() ] = yAxis.upperEdge();
01093     p = new Anaphe::AIDA_Histogram_native::AIDA_Histogram2D( h.title(), edgesX, edgesY );
01094   }
01095   for ( int i = -numberOfExtraBins; i < xAxis.bins(); ++i ) {
01096     for ( int j = -numberOfExtraBins; j < yAxis.bins(); ++j ) {
01097       int entries = 0;
01098       double height = 0;
01099       double errorSquared = 0;
01100       double binMeanX = 0;
01101       double binMeanY = 0;
01102       for ( int k = indexZ1; k <= indexZ2; ++k ) {
01103         entries += h.binEntries( i, j, k );
01104         const double tempHeight = h.binHeight( i, j, k );
01105         height += tempHeight;
01106         binMeanX += h.binMeanX( i, j, k ) * tempHeight;
01107         binMeanY += h.binMeanY( i, j, k ) * tempHeight;
01108         const double error = h.binError( i, j, k );
01109         errorSquared += error*error;
01110       }
01111       if ( height != 0 ) {
01112         binMeanX /= height;
01113         binMeanY /= height;
01114       }
01115       p->setBinContents( i, j, entries, height, std::sqrt( errorSquared ), binMeanX, binMeanY );
01116     }
01117   }
01118 
01119   return p;
01120 }
01121 
01122 
01123 AIDA::Dev::IDevHistogram2D*
01124 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::sliceXZ( const AIDA::IHistogram3D & h, int indexY1, int indexY2 )
01125 {
01126   AIDA::Dev::IDevHistogram2D* p = 0;
01127   const AIDA::IAxis& xAxis = h.xAxis();
01128   const AIDA::IAxis& zAxis = h.zAxis();
01129   if ( xAxis.isFixedBinning() ) {
01130     p = new Anaphe::AIDA_Histogram_native::AIDA_Histogram2D( h.title(), xAxis.bins(), xAxis.lowerEdge(), xAxis.upperEdge(), zAxis.bins(), zAxis.lowerEdge(), zAxis.upperEdge() );
01131   }
01132   else {
01133     std::vector< double > edgesX( xAxis.bins() + 1 );
01134     for ( int i = 0; i < xAxis.bins(); ++i ) edgesX[i] = xAxis.binLowerEdge( i );
01135     edgesX[ xAxis.bins() ] = xAxis.upperEdge();
01136     std::vector< double > edgesZ( zAxis.bins() + 1 );
01137     for ( int i = 0; i < zAxis.bins(); ++i ) edgesZ[i] = zAxis.binLowerEdge( i );
01138     edgesZ[ zAxis.bins() ] = zAxis.upperEdge();
01139     p = new Anaphe::AIDA_Histogram_native::AIDA_Histogram2D( h.title(), edgesX, edgesZ );
01140   }
01141 
01142   for ( int i = -numberOfExtraBins; i < xAxis.bins(); ++i ) {
01143     for ( int j = -numberOfExtraBins; j < zAxis.bins(); ++j ) {
01144       int entries = 0;
01145       double height = 0;
01146       double errorSquared = 0;
01147       double binMeanX = 0;
01148       double binMeanZ = 0;
01149       for ( int k = indexY1; k <= indexY2; ++k ) {
01150         entries += h.binEntries( i, k, j );
01151         const double tempHeight = h.binHeight( i, k, j );
01152         height += tempHeight;
01153         binMeanX += h.binMeanX( i, k, j ) * tempHeight;
01154         binMeanZ += h.binMeanZ( i, k, j ) * tempHeight;
01155         const double error = h.binError( i, k, j );
01156         errorSquared += error*error;
01157       }
01158       if ( height != 0 ) {
01159         binMeanX /= height;
01160         binMeanZ /= height;
01161       }
01162       p->setBinContents( i, j, entries, height, std::sqrt( errorSquared ), binMeanX, binMeanZ );
01163     }
01164   }
01165 
01166   return p;
01167 }
01168 
01169 
01170 AIDA::Dev::IDevHistogram2D*
01171 Anaphe::AIDA_Histogram_native::AIDA_DevHistogramFactory::sliceYZ( const AIDA::IHistogram3D & h, int indexX1, int indexX2 )
01172 {
01173   AIDA::Dev::IDevHistogram2D* p = 0;
01174   const AIDA::IAxis& yAxis = h.yAxis();
01175   const AIDA::IAxis& zAxis = h.zAxis();
01176   if ( yAxis.isFixedBinning() ) {
01177     p = new Anaphe::AIDA_Histogram_native::AIDA_Histogram2D( h.title(), yAxis.bins(), yAxis.lowerEdge(), yAxis.upperEdge(), zAxis.bins(), zAxis.lowerEdge(), zAxis.upperEdge() );
01178   }
01179   else {
01180     std::vector< double > edgesY( yAxis.bins() + 1 );
01181     for ( int i = 0; i < yAxis.bins(); ++i ) edgesY[i] = yAxis.binLowerEdge( i );
01182     edgesY[ yAxis.bins() ] = yAxis.upperEdge();
01183     std::vector< double > edgesZ( zAxis.bins() + 1 );
01184     for ( int i = 0; i < zAxis.bins(); ++i ) edgesZ[i] = zAxis.binLowerEdge( i );
01185     edgesZ[ zAxis.bins() ] = zAxis.upperEdge();
01186     p = new Anaphe::AIDA_Histogram_native::AIDA_Histogram2D( h.title(), edgesY, edgesZ );
01187   }
01188 
01189   for ( int i = -numberOfExtraBins; i < yAxis.bins(); ++i ) {
01190     for ( int j = -numberOfExtraBins; j < zAxis.bins(); ++j ) {
01191       int entries = 0;
01192       double height = 0;
01193       double errorSquared = 0;
01194       double binMeanY = 0;
01195       double binMeanZ = 0;
01196       for ( int k = indexX1; k <= indexX2; ++k ) {
01197         entries += h.binEntries( k, i, j );
01198         const double tempHeight = h.binHeight( k, i, j );
01199         height += tempHeight;
01200         binMeanY += h.binMeanY( k, i, j ) * tempHeight;
01201         binMeanZ += h.binMeanZ( k, i, j ) * tempHeight;
01202         const double error = h.binError( k, i, j );
01203         errorSquared += error*error;
01204       }
01205       if ( height != 0 ) {
01206         binMeanY /= height;
01207         binMeanZ /= height;
01208       }
01209       p->setBinContents( i, j, entries, height, std::sqrt( errorSquared ), binMeanY, binMeanZ );
01210     }
01211   }
01212 
01213   return p;
01214 }

Generated on Tue Nov 19 12:32:16 2002 for AIDA_Histogram_native by doxygen1.2.16