00001 #include "ObjyHistogramConverter.h" 00002 #include "HTL/PHistograms.h" 00003 #include "AIDA/IHistogram1D.h" 00004 #include "AIDA/IHistogram2D.h" 00005 #include "AIDA/IHistogram3D.h" 00006 #include "AIDA/IProfile1D.h" 00007 #include "AIDA/IAxis.h" 00008 00009 #include "AIDA_Dev/IDevHistogramFactory.h" 00010 #include "AIDA_Dev/IDevHistogram1D.h" 00011 #include "AIDA_Dev/IDevHistogram2D.h" 00012 #include "AIDA_Dev/IDevHistogram3D.h" 00013 #include "AIDA_Dev/IDevProfile1D.h" 00014 00015 #include "HTL/Gravity_Bin_1D.h" 00016 #include "HTL/Profile_Bin.h" 00017 00018 static const std::string emptyString = ""; 00019 00020 ooHandle(ooObj) 00021 Anaphe::AIDA_ObjectivityStore::ObjyHistogramConverter::convertToObjy( ooHandle(ooContObj)& containerHandle, 00022 const AIDA::IHistogram1D& h ) 00023 { 00024 ooHandle(P_I_Histo_1D) handle; 00025 if ( h.axis().isFixedBinning() ) { 00026 handle = new( containerHandle ) PHisto1D( h.title().c_str(), 00027 h.axis().bins(), 00028 h.axis().lowerEdge(), 00029 h.axis().upperEdge() ); 00030 } 00031 else { 00032 std::vector< double > edges( h.axis().bins() + 1 ); 00033 for ( int i = 0; i < h.axis().bins(); ++i ) edges[ i ] = h.axis().binLowerEdge( i ); 00034 edges.back() = h.axis().upperEdge(); 00035 handle = new( containerHandle ) PHisto1DVar( h.title().c_str(), edges ); 00036 } 00037 00038 std::vector<long int> v( 1 ); 00039 for ( int i = -2; i < h.axis().bins(); ++i ) { 00040 int ia = i; 00041 int ib = i; 00042 if ( i == -2 ) { 00043 ia = static_cast<int>( AIDA::IAxis::OVERFLOW_BIN ); 00044 ib = static_cast<int>( I_Histo::OVERFLOW_BIN ); 00045 } 00046 else if ( i == -1 ) { 00047 ia = static_cast<int>( AIDA::IAxis::UNDERFLOW_BIN ); 00048 ib = static_cast<int>( I_Histo::UNDERFLOW_BIN ); 00049 } 00050 v[0] = ib; 00051 if ( h.binEntries( ia ) == 0 ) continue; 00052 Gravity_Bin_1D& pBin = dynamic_cast<Gravity_Bin_1D&>( handle->i_any_bin( v ) ); 00053 pBin.set_count( h.binEntries( ia ) ); 00054 pBin.set_value( h.binHeight( ia ) ); 00055 pBin.set_error( h.binError( ia ) ); 00056 pBin.set_center( h.binMean( ia ) ); 00057 } 00058 00059 return handle; 00060 } 00061 00062 00063 AIDA::Dev::IDevHistogram1D* 00064 Anaphe::AIDA_ObjectivityStore::ObjyHistogramConverter::convertFromObjy( AIDA::Dev::IDevHistogramFactory& factory, 00065 const ooHandle(PHisto1D)& h ) 00066 { 00067 AIDA::Dev::IDevHistogram1D* histo = factory.createHistogram1D( std::string( h->name() ), 00068 h->i_partition().bin_count(), 00069 h->i_partition().i_lower_point(), 00070 h->i_partition().i_upper_point() ); 00071 00072 std::vector<long int> v( 1 ); 00073 for ( int i = -2; i < histo->axis().bins(); ++i ) { 00074 int ia = i; 00075 int ib = i; 00076 if ( i == -2 ) { 00077 ia = static_cast<int>( AIDA::IAxis::OVERFLOW_BIN ); 00078 ib = static_cast<int>( I_Histo::OVERFLOW_BIN ); 00079 } 00080 else if ( i == -1 ) { 00081 ia = static_cast<int>( AIDA::IAxis::UNDERFLOW_BIN ); 00082 ib = static_cast<int>( I_Histo::UNDERFLOW_BIN ); 00083 } 00084 v[0] = ib; 00085 if ( h->i_any_bin( v ).count() == 0 ) continue; 00086 Gravity_Bin_1D& pBin = dynamic_cast<Gravity_Bin_1D&>( h->i_any_bin( v ) ); 00087 histo->setBinContents( ia, 00088 pBin.count(), 00089 pBin.value(), 00090 pBin.error(), 00091 pBin.center() ); 00092 } 00093 histo->setRms( h->rms() ); 00094 return histo; 00095 } 00096 00097 00098 AIDA::Dev::IDevHistogram1D* 00099 Anaphe::AIDA_ObjectivityStore::ObjyHistogramConverter::convertFromObjy( AIDA::Dev::IDevHistogramFactory& factory, 00100 const ooHandle(PHisto1DVar)& h ) 00101 { 00102 std::vector<double> edges( h->i_partition().bin_count() + 1 ); 00103 for ( int i = 0; i < h->i_partition().bin_count(); ++i ) edges[i] = h->i_partition().i_lower_point( i ); 00104 edges.back() = h->i_partition().i_upper_point(); 00105 00106 AIDA::Dev::IDevHistogram1D* histo = factory.createHistogram1D( std::string( h->name() ), edges, emptyString ); 00107 00108 std::vector<long int> v( 1 ); 00109 for ( int i = -2; i < histo->axis().bins(); ++i ) { 00110 int ia = i; 00111 int ib = i; 00112 if ( i == -2 ) { 00113 ia = static_cast<int>( AIDA::IAxis::OVERFLOW_BIN ); 00114 ib = static_cast<int>( I_Histo::OVERFLOW_BIN ); 00115 } 00116 else if ( i == -1 ) { 00117 ia = static_cast<int>( AIDA::IAxis::UNDERFLOW_BIN ); 00118 ib = static_cast<int>( I_Histo::UNDERFLOW_BIN ); 00119 } 00120 v[0] = ib; 00121 if ( h->i_any_bin( v ).count() == 0 ) continue; 00122 Gravity_Bin_1D& pBin = dynamic_cast<Gravity_Bin_1D&>( h->i_any_bin( v ) ); 00123 histo->setBinContents( ia, 00124 pBin.count(), 00125 pBin.value(), 00126 pBin.error(), 00127 pBin.center() ); 00128 } 00129 histo->setRms( h->rms() ); 00130 return histo; 00131 } 00132 00133 00134 ooHandle(ooObj) 00135 Anaphe::AIDA_ObjectivityStore::ObjyHistogramConverter::convertToObjy( ooHandle(ooContObj)& containerHandle, 00136 const AIDA::IHistogram2D& h ) 00137 { 00138 ooHandle(P_I_Histo_2D) handle; 00139 if ( h.xAxis().isFixedBinning() ) { 00140 handle = new( containerHandle ) PHisto2D( h.title().c_str(), 00141 h.xAxis().bins(), 00142 h.xAxis().lowerEdge(), 00143 h.xAxis().upperEdge(), 00144 h.yAxis().bins(), 00145 h.yAxis().lowerEdge(), 00146 h.yAxis().upperEdge() ); 00147 } 00148 else { 00149 std::vector< double > edgesX( h.xAxis().bins() + 1 ); 00150 for ( int i = 0; i < h.xAxis().bins(); ++i ) edgesX[ i ] = h.xAxis().binLowerEdge( i ); 00151 edgesX.back() = h.xAxis().upperEdge(); 00152 std::vector< double > edgesY( h.yAxis().bins() + 1 ); 00153 for ( int i = 0; i < h.yAxis().bins(); ++i ) edgesY[ i ] = h.yAxis().binLowerEdge( i ); 00154 edgesY.back() = h.yAxis().upperEdge(); 00155 handle = new( containerHandle ) PHisto2DVar( h.title().c_str(), edgesX, edgesY ); 00156 } 00157 00158 std::vector<long int> v( 2 ); 00159 for ( int i = -2; i < h.xAxis().bins(); ++i ) { 00160 int ia = i; 00161 int ib = i; 00162 if ( i == -2 ) { 00163 ia = static_cast<int>( AIDA::IAxis::OVERFLOW_BIN ); 00164 ib = static_cast<int>( I_Histo::OVERFLOW_BIN ); 00165 } 00166 else if ( i == -1 ) { 00167 ia = static_cast<int>( AIDA::IAxis::UNDERFLOW_BIN ); 00168 ib = static_cast<int>( I_Histo::UNDERFLOW_BIN ); 00169 } 00170 v[0] = ib; 00171 for ( int j = -2; j < h.yAxis().bins(); ++j ) { 00172 int ja = j; 00173 int jb = j; 00174 if ( j == -2 ) { 00175 ja = static_cast<int>( AIDA::IAxis::OVERFLOW_BIN ); 00176 jb = static_cast<int>( I_Histo::OVERFLOW_BIN ); 00177 } 00178 else if ( j == -1 ) { 00179 ja = static_cast<int>( AIDA::IAxis::UNDERFLOW_BIN ); 00180 jb = static_cast<int>( I_Histo::UNDERFLOW_BIN ); 00181 } 00182 v[1] = jb; 00183 if ( h.binEntries( ia, ja ) == 0 ) continue; 00184 I_Bin& pBin = handle->i_any_bin( v ) ; 00185 pBin.set_count( h.binEntries( ia, ja ) ); 00186 pBin.set_value( h.binHeight( ia, ja ) ); 00187 pBin.set_error( h.binError( ia, ja ) ); 00188 } 00189 } 00190 00191 return handle; 00192 } 00193 00194 00195 AIDA::Dev::IDevHistogram2D* 00196 Anaphe::AIDA_ObjectivityStore::ObjyHistogramConverter::convertFromObjy( AIDA::Dev::IDevHistogramFactory& factory, 00197 const ooHandle(PHisto2D)& h ) 00198 { 00199 AIDA::Dev::IDevHistogram2D* histo = factory.createHistogram2D( std::string( h->name() ), 00200 h->i_partition(0).bin_count(), 00201 h->i_partition(0).i_lower_point(), 00202 h->i_partition(0).i_upper_point(), 00203 h->i_partition(1).bin_count(), 00204 h->i_partition(1).i_lower_point(), 00205 h->i_partition(1).i_upper_point() ); 00206 00207 std::vector<long int> v( 2 ); 00208 for ( int i = -2; i < histo->xAxis().bins(); ++i ) { 00209 int ia = i; 00210 int ib = i; 00211 if ( i == -2 ) { 00212 ia = static_cast<int>( AIDA::IAxis::OVERFLOW_BIN ); 00213 ib = static_cast<int>( I_Histo::OVERFLOW_BIN ); 00214 } 00215 else if ( i == -1 ) { 00216 ia = static_cast<int>( AIDA::IAxis::UNDERFLOW_BIN ); 00217 ib = static_cast<int>( I_Histo::UNDERFLOW_BIN ); 00218 } 00219 v[0] = ib; 00220 00221 for ( int j = -2; j < histo->yAxis().bins(); ++j ) { 00222 int ja = j; 00223 int jb = j; 00224 if ( j == -2 ) { 00225 ja = static_cast<int>( AIDA::IAxis::OVERFLOW_BIN ); 00226 jb = static_cast<int>( I_Histo::OVERFLOW_BIN ); 00227 } 00228 else if ( j == -1 ) { 00229 ja = static_cast<int>( AIDA::IAxis::UNDERFLOW_BIN ); 00230 jb = static_cast<int>( I_Histo::UNDERFLOW_BIN ); 00231 } 00232 v[1] = jb; 00233 if ( h->i_any_bin( v ).count() == 0 ) continue; 00234 double centreX, centreY; 00235 if ( i >= 0 ) centreX = 0.5 * ( h->i_partition(0).i_lower_point(i) + h->i_partition(0).i_upper_point(i) ); 00236 else if ( i == -2 ) centreX = h->i_partition(0).i_upper_point() + 1; 00237 else if ( i == -1 ) centreX = h->i_partition(0).i_lower_point() - 1; 00238 if ( j >= 0 ) centreY = 0.5 * ( h->i_partition(1).i_lower_point(j) + h->i_partition(1).i_upper_point(j) ); 00239 else if ( j == -2 ) centreY = h->i_partition(1).i_upper_point() + 1; 00240 else if ( j == -1 ) centreY = h->i_partition(1).i_lower_point() - 1; 00241 I_Bin& pBin = h->i_any_bin( v ); 00242 histo->setBinContents( ia, ja, 00243 pBin.count(), 00244 pBin.value(), 00245 pBin.error(), 00246 centreX, centreY ); 00247 } 00248 } 00249 histo->setRms( h->rms( 0 ), h->rms( 1 ) ); 00250 return histo; 00251 } 00252 00253 00254 AIDA::Dev::IDevHistogram2D* 00255 Anaphe::AIDA_ObjectivityStore::ObjyHistogramConverter::convertFromObjy( AIDA::Dev::IDevHistogramFactory& factory, 00256 const ooHandle(PHisto2DVar)& h ) 00257 { 00258 std::vector<double> edgesX( h->i_partition(0).bin_count() + 1 ); 00259 for ( int i = 0; i < h->i_partition(0).bin_count(); ++i ) edgesX[i] = h->i_partition(0).i_lower_point( i ); 00260 edgesX.back() = h->i_partition(0).i_upper_point(); 00261 00262 std::vector<double> edgesY( h->i_partition(1).bin_count() + 1 ); 00263 for ( int i = 0; i < h->i_partition(1).bin_count(); ++i ) edgesY[i] = h->i_partition(1).i_lower_point( i ); 00264 edgesY.back() = h->i_partition(1).i_upper_point(); 00265 00266 AIDA::Dev::IDevHistogram2D* histo = factory.createHistogram2D( std::string( h->name() ), edgesX, edgesY, emptyString ); 00267 00268 std::vector<long int> v( 2 ); 00269 for ( int i = -2; i < histo->xAxis().bins(); ++i ) { 00270 int ia = i; 00271 int ib = i; 00272 if ( i == -2 ) { 00273 ia = static_cast<int>( AIDA::IAxis::OVERFLOW_BIN ); 00274 ib = static_cast<int>( I_Histo::OVERFLOW_BIN ); 00275 } 00276 else if ( i == -1 ) { 00277 ia = static_cast<int>( AIDA::IAxis::UNDERFLOW_BIN ); 00278 ib = static_cast<int>( I_Histo::UNDERFLOW_BIN ); 00279 } 00280 v[0] = ib; 00281 00282 for ( int j = -2; j < histo->yAxis().bins(); ++j ) { 00283 int ja = j; 00284 int jb = j; 00285 if ( j == -2 ) { 00286 ja = static_cast<int>( AIDA::IAxis::OVERFLOW_BIN ); 00287 jb = static_cast<int>( I_Histo::OVERFLOW_BIN ); 00288 } 00289 else if ( j == -1 ) { 00290 ja = static_cast<int>( AIDA::IAxis::UNDERFLOW_BIN ); 00291 jb = static_cast<int>( I_Histo::UNDERFLOW_BIN ); 00292 } 00293 v[1] = jb; 00294 if ( h->i_any_bin( v ).count() == 0 ) continue; 00295 double centreX, centreY; 00296 if ( i >= 0 ) centreX = 0.5 * ( h->i_partition(0).i_lower_point(i) + h->i_partition(0).i_upper_point(i) ); 00297 else if ( i == -2 ) centreX = h->i_partition(0).i_upper_point() + 1; 00298 else if ( i == -1 ) centreX = h->i_partition(0).i_lower_point() - 1; 00299 if ( j >= 0 ) centreY = 0.5 * ( h->i_partition(1).i_lower_point(j) + h->i_partition(1).i_upper_point(j) ); 00300 else if ( j == -2 ) centreY = h->i_partition(1).i_upper_point() + 1; 00301 else if ( j == -1 ) centreY = h->i_partition(1).i_lower_point() - 1; 00302 I_Bin& pBin = h->i_any_bin( v ); 00303 histo->setBinContents( ia, ja, 00304 pBin.count(), 00305 pBin.value(), 00306 pBin.error(), 00307 centreX, centreY ); 00308 } 00309 } 00310 histo->setRms( h->rms( 0 ), h->rms( 1 ) ); 00311 return histo; 00312 } 00313 00314 00315 ooHandle(ooObj) 00316 Anaphe::AIDA_ObjectivityStore::ObjyHistogramConverter::convertToObjy( ooHandle(ooContObj)& containerHandle, 00317 const AIDA::IHistogram3D& h ) 00318 { 00319 ooHandle(P_I_Histo_3D) handle; 00320 if ( h.xAxis().isFixedBinning() ) { 00321 handle = new( containerHandle ) PHisto3D( h.title().c_str(), 00322 h.xAxis().bins(), 00323 h.xAxis().lowerEdge(), 00324 h.xAxis().upperEdge(), 00325 h.yAxis().bins(), 00326 h.yAxis().lowerEdge(), 00327 h.yAxis().upperEdge(), 00328 h.zAxis().bins(), 00329 h.zAxis().lowerEdge(), 00330 h.zAxis().upperEdge() ); 00331 } 00332 else { 00333 std::vector< double > edgesX( h.xAxis().bins() + 1 ); 00334 for ( int i = 0; i < h.xAxis().bins(); ++i ) edgesX[ i ] = h.xAxis().binLowerEdge( i ); 00335 edgesX.back() = h.xAxis().upperEdge(); 00336 std::vector< double > edgesY( h.yAxis().bins() + 1 ); 00337 for ( int i = 0; i < h.yAxis().bins(); ++i ) edgesY[ i ] = h.yAxis().binLowerEdge( i ); 00338 edgesY.back() = h.yAxis().upperEdge(); 00339 std::vector< double > edgesZ( h.zAxis().bins() + 1 ); 00340 for ( int i = 0; i < h.zAxis().bins(); ++i ) edgesZ[ i ] = h.zAxis().binLowerEdge( i ); 00341 edgesZ.back() = h.zAxis().upperEdge(); 00342 handle = new( containerHandle ) PHisto3DVar( h.title().c_str(), edgesX, edgesY, edgesZ ); 00343 } 00344 00345 std::vector<long int> v( 3 ); 00346 for ( int i = -2; i < h.xAxis().bins(); ++i ) { 00347 int ia = i; 00348 int ib = i; 00349 if ( i == -2 ) { 00350 ia = static_cast<int>( AIDA::IAxis::OVERFLOW_BIN ); 00351 ib = static_cast<int>( I_Histo::OVERFLOW_BIN ); 00352 } 00353 else if ( i == -1 ) { 00354 ia = static_cast<int>( AIDA::IAxis::UNDERFLOW_BIN ); 00355 ib = static_cast<int>( I_Histo::UNDERFLOW_BIN ); 00356 } 00357 v[0] = ib; 00358 for ( int j = -2; j < h.yAxis().bins(); ++j ) { 00359 int ja = j; 00360 int jb = j; 00361 if ( j == -2 ) { 00362 ja = static_cast<int>( AIDA::IAxis::OVERFLOW_BIN ); 00363 jb = static_cast<int>( I_Histo::OVERFLOW_BIN ); 00364 } 00365 else if ( j == -1 ) { 00366 ja = static_cast<int>( AIDA::IAxis::UNDERFLOW_BIN ); 00367 jb = static_cast<int>( I_Histo::UNDERFLOW_BIN ); 00368 } 00369 v[1] = jb; 00370 for ( int k = -2; k < h.zAxis().bins(); ++k ) { 00371 int ka = k; 00372 int kb = k; 00373 if ( k == -2 ) { 00374 ka = static_cast<int>( AIDA::IAxis::OVERFLOW_BIN ); 00375 kb = static_cast<int>( I_Histo::OVERFLOW_BIN ); 00376 } 00377 else if ( k == -1 ) { 00378 ka = static_cast<int>( AIDA::IAxis::UNDERFLOW_BIN ); 00379 kb = static_cast<int>( I_Histo::UNDERFLOW_BIN ); 00380 } 00381 v[2] = kb; 00382 if ( h.binEntries( ia, ja, ka ) == 0 ) continue; 00383 I_Bin& pBin = handle->i_any_bin( v ) ; 00384 pBin.set_count( h.binEntries( ia, ja, ka ) ); 00385 pBin.set_value( h.binHeight( ia, ja, ka ) ); 00386 pBin.set_error( h.binError( ia, ja, ka ) ); 00387 } 00388 } 00389 } 00390 00391 return handle; 00392 } 00393 00394 00395 AIDA::Dev::IDevHistogram3D* 00396 Anaphe::AIDA_ObjectivityStore::ObjyHistogramConverter::convertFromObjy( AIDA::Dev::IDevHistogramFactory& factory, 00397 const ooHandle(PHisto3D)& h ) 00398 { 00399 AIDA::Dev::IDevHistogram3D* histo = factory.createHistogram3D( std::string( h->name() ), 00400 h->i_partition(0).bin_count(), 00401 h->i_partition(0).i_lower_point(), 00402 h->i_partition(0).i_upper_point(), 00403 h->i_partition(1).bin_count(), 00404 h->i_partition(1).i_lower_point(), 00405 h->i_partition(1).i_upper_point(), 00406 h->i_partition(2).bin_count(), 00407 h->i_partition(2).i_lower_point(), 00408 h->i_partition(2).i_upper_point() ); 00409 00410 std::vector<long int> v( 3 ); 00411 for ( int i = -2; i < histo->xAxis().bins(); ++i ) { 00412 int ia = i; 00413 int ib = i; 00414 if ( i == -2 ) { 00415 ia = static_cast<int>( AIDA::IAxis::OVERFLOW_BIN ); 00416 ib = static_cast<int>( I_Histo::OVERFLOW_BIN ); 00417 } 00418 else if ( i == -1 ) { 00419 ia = static_cast<int>( AIDA::IAxis::UNDERFLOW_BIN ); 00420 ib = static_cast<int>( I_Histo::UNDERFLOW_BIN ); 00421 } 00422 v[0] = ib; 00423 00424 for ( int j = -2; j < histo->yAxis().bins(); ++j ) { 00425 int ja = j; 00426 int jb = j; 00427 if ( j == -2 ) { 00428 ja = static_cast<int>( AIDA::IAxis::OVERFLOW_BIN ); 00429 jb = static_cast<int>( I_Histo::OVERFLOW_BIN ); 00430 } 00431 else if ( j == -1 ) { 00432 ja = static_cast<int>( AIDA::IAxis::UNDERFLOW_BIN ); 00433 jb = static_cast<int>( I_Histo::UNDERFLOW_BIN ); 00434 } 00435 v[1] = jb; 00436 00437 for ( int k = -2; k < histo->zAxis().bins(); ++k ) { 00438 int ka = k; 00439 int kb = k; 00440 if ( k == -2 ) { 00441 ka = static_cast<int>( AIDA::IAxis::OVERFLOW_BIN ); 00442 kb = static_cast<int>( I_Histo::OVERFLOW_BIN ); 00443 } 00444 else if ( k == -1 ) { 00445 ka = static_cast<int>( AIDA::IAxis::UNDERFLOW_BIN ); 00446 kb = static_cast<int>( I_Histo::UNDERFLOW_BIN ); 00447 } 00448 v[2] = kb; 00449 00450 if ( h->i_any_bin( v ).count() == 0 ) continue; 00451 double centreX, centreY, centreZ; 00452 if ( i >= 0 ) centreX = 0.5 * ( h->i_partition(0).i_lower_point(i) + h->i_partition(0).i_upper_point(i) ); 00453 else if ( i == -2 ) centreX = h->i_partition(0).i_upper_point() + 1; 00454 else if ( i == -1 ) centreX = h->i_partition(0).i_lower_point() - 1; 00455 if ( j >= 0 ) centreY = 0.5 * ( h->i_partition(1).i_lower_point(j) + h->i_partition(1).i_upper_point(j) ); 00456 else if ( j == -2 ) centreY = h->i_partition(1).i_upper_point() + 1; 00457 else if ( j == -1 ) centreY = h->i_partition(1).i_lower_point() - 1; 00458 if ( k >= 0 ) centreZ = 0.5 * ( h->i_partition(2).i_lower_point(k) + h->i_partition(2).i_upper_point(k) ); 00459 else if ( k == -2 ) centreZ = h->i_partition(2).i_upper_point() + 1; 00460 else if ( k == -1 ) centreZ = h->i_partition(2).i_lower_point() - 1; 00461 I_Bin& pBin = h->i_any_bin( v ); 00462 histo->setBinContents( ia, ja, ka, 00463 pBin.count(), 00464 pBin.value(), 00465 pBin.error(), 00466 centreX, centreY, centreY ); 00467 } 00468 } 00469 } 00470 return histo; 00471 } 00472 00473 00474 AIDA::Dev::IDevHistogram3D* 00475 Anaphe::AIDA_ObjectivityStore::ObjyHistogramConverter::convertFromObjy( AIDA::Dev::IDevHistogramFactory& factory, 00476 const ooHandle(PHisto3DVar)& h ) 00477 { 00478 std::vector<double> edgesX( h->i_partition(0).bin_count() + 1 ); 00479 for ( int i = 0; i < h->i_partition(0).bin_count(); ++i ) edgesX[i] = h->i_partition(0).i_lower_point( i ); 00480 edgesX.back() = h->i_partition(0).i_upper_point(); 00481 00482 std::vector<double> edgesY( h->i_partition(1).bin_count() + 1 ); 00483 for ( int i = 0; i < h->i_partition(1).bin_count(); ++i ) edgesY[i] = h->i_partition(1).i_lower_point( i ); 00484 edgesY.back() = h->i_partition(1).i_upper_point(); 00485 00486 std::vector<double> edgesZ( h->i_partition(2).bin_count() + 1 ); 00487 for ( int i = 0; i < h->i_partition(2).bin_count(); ++i ) edgesZ[i] = h->i_partition(2).i_lower_point( i ); 00488 edgesZ.back() = h->i_partition(2).i_upper_point(); 00489 00490 AIDA::Dev::IDevHistogram3D* histo = factory.createHistogram3D( std::string( h->name() ), edgesX, edgesY, edgesZ, emptyString ); 00491 00492 std::vector<long int> v( 3 ); 00493 for ( int i = -2; i < histo->xAxis().bins(); ++i ) { 00494 int ia = i; 00495 int ib = i; 00496 if ( i == -2 ) { 00497 ia = static_cast<int>( AIDA::IAxis::OVERFLOW_BIN ); 00498 ib = static_cast<int>( I_Histo::OVERFLOW_BIN ); 00499 } 00500 else if ( i == -1 ) { 00501 ia = static_cast<int>( AIDA::IAxis::UNDERFLOW_BIN ); 00502 ib = static_cast<int>( I_Histo::UNDERFLOW_BIN ); 00503 } 00504 v[0] = ib; 00505 00506 for ( int j = -2; j < histo->yAxis().bins(); ++j ) { 00507 int ja = j; 00508 int jb = j; 00509 if ( j == -2 ) { 00510 ja = static_cast<int>( AIDA::IAxis::OVERFLOW_BIN ); 00511 jb = static_cast<int>( I_Histo::OVERFLOW_BIN ); 00512 } 00513 else if ( j == -1 ) { 00514 ja = static_cast<int>( AIDA::IAxis::UNDERFLOW_BIN ); 00515 jb = static_cast<int>( I_Histo::UNDERFLOW_BIN ); 00516 } 00517 v[1] = jb; 00518 00519 for ( int k = -2; k < histo->zAxis().bins(); ++k ) { 00520 int ka = k; 00521 int kb = k; 00522 if ( k == -2 ) { 00523 ka = static_cast<int>( AIDA::IAxis::OVERFLOW_BIN ); 00524 kb = static_cast<int>( I_Histo::OVERFLOW_BIN ); 00525 } 00526 else if ( k == -1 ) { 00527 ka = static_cast<int>( AIDA::IAxis::UNDERFLOW_BIN ); 00528 kb = static_cast<int>( I_Histo::UNDERFLOW_BIN ); 00529 } 00530 v[2] = kb; 00531 00532 if ( h->i_any_bin( v ).count() == 0 ) continue; 00533 double centreX, centreY, centreZ; 00534 if ( i >= 0 ) centreX = 0.5 * ( h->i_partition(0).i_lower_point(i) + h->i_partition(0).i_upper_point(i) ); 00535 else if ( i == -2 ) centreX = h->i_partition(0).i_upper_point() + 1; 00536 else if ( i == -1 ) centreX = h->i_partition(0).i_lower_point() - 1; 00537 if ( j >= 0 ) centreY = 0.5 * ( h->i_partition(1).i_lower_point(j) + h->i_partition(1).i_upper_point(j) ); 00538 else if ( j == -2 ) centreY = h->i_partition(1).i_upper_point() + 1; 00539 else if ( j == -1 ) centreY = h->i_partition(1).i_lower_point() - 1; 00540 if ( k >= 0 ) centreZ = 0.5 * ( h->i_partition(2).i_lower_point(k) + h->i_partition(2).i_upper_point(k) ); 00541 else if ( k == -2 ) centreZ = h->i_partition(2).i_upper_point() + 1; 00542 else if ( k == -1 ) centreZ = h->i_partition(2).i_lower_point() - 1; 00543 I_Bin& pBin = h->i_any_bin( v ); 00544 histo->setBinContents( ia, ja, ka, 00545 pBin.count(), 00546 pBin.value(), 00547 pBin.error(), 00548 centreX, centreY, centreY ); 00549 } 00550 } 00551 } 00552 return histo; 00553 } 00554 00555 00556 ooHandle(ooObj) 00557 Anaphe::AIDA_ObjectivityStore::ObjyHistogramConverter::convertToObjy( ooHandle(ooContObj)& containerHandle, 00558 const AIDA::IProfile1D& h ) 00559 { 00560 ooHandle(P_I_Histo_1D) handle; 00561 if ( h.axis().isFixedBinning() ) { 00562 handle = new( containerHandle ) PProfileHisto( h.title().c_str(), 00563 h.axis().bins(), 00564 h.axis().lowerEdge(), 00565 h.axis().upperEdge() ); 00566 } 00567 else { 00568 std::vector< double > edges( h.axis().bins() + 1 ); 00569 for ( int i = 0; i < h.axis().bins(); ++i ) edges[ i ] = h.axis().binLowerEdge( i ); 00570 edges.back() = h.axis().upperEdge(); 00571 handle = new( containerHandle ) PProfileHistoVar( h.title().c_str(), edges ); 00572 } 00573 00574 std::vector<long int> v( 1 ); 00575 for ( int i = -2; i < h.axis().bins(); ++i ) { 00576 int ia = i; 00577 int ib = i; 00578 if ( i == -2 ) { 00579 ia = static_cast<int>( AIDA::IAxis::OVERFLOW_BIN ); 00580 ib = static_cast<int>( I_Histo::OVERFLOW_BIN ); 00581 } 00582 else if ( i == -1 ) { 00583 ia = static_cast<int>( AIDA::IAxis::UNDERFLOW_BIN ); 00584 ib = static_cast<int>( I_Histo::UNDERFLOW_BIN ); 00585 } 00586 v[0] = ib; 00587 if ( h.binEntries( ia ) == 0 ) continue; 00588 Profile_Bin& pBin = dynamic_cast<Profile_Bin&>( handle->i_any_bin( v ) ); 00589 00590 const double newValue = h.binHeight( ia ); 00591 const double newError = h.binError( ia ); 00592 const double newSpread = h.binRms( ia ); 00593 double sumOfWeights = newSpread / newError; 00594 sumOfWeights *= sumOfWeights; 00595 const double sumOfWeightTimesExtraCoordinate = newValue * sumOfWeights; 00596 double sumOfWeightTimesSquaredExtraCoordinate = sumOfWeightTimesExtraCoordinate / sumOfWeights; 00597 sumOfWeightTimesSquaredExtraCoordinate *= sumOfWeightTimesSquaredExtraCoordinate; 00598 sumOfWeightTimesSquaredExtraCoordinate += newSpread * newSpread; 00599 sumOfWeightTimesSquaredExtraCoordinate *= sumOfWeights; 00600 pBin.set_count( h.binEntries( ia ) ); 00601 pBin.set_value( sumOfWeights, 1 ); 00602 pBin.set_value( sumOfWeightTimesExtraCoordinate, 2 ); 00603 pBin.set_value( sumOfWeightTimesSquaredExtraCoordinate, 3 ); 00604 } 00605 00606 return handle; 00607 } 00608 00609 00610 AIDA::Dev::IDevProfile1D* 00611 Anaphe::AIDA_ObjectivityStore::ObjyHistogramConverter::convertFromObjy( AIDA::Dev::IDevHistogramFactory& factory, 00612 const ooHandle(PProfileHisto)& h ) 00613 { 00614 AIDA::Dev::IDevProfile1D* histo = factory.createProfile1D( std::string( h->name() ), 00615 h->i_partition().bin_count(), 00616 h->i_partition().i_lower_point(), 00617 h->i_partition().i_upper_point() ); 00618 00619 std::vector<long int> v( 1 ); 00620 for ( int i = -2; i < histo->axis().bins(); ++i ) { 00621 int ia = i; 00622 int ib = i; 00623 if ( i == -2 ) { 00624 ia = static_cast<int>( AIDA::IAxis::OVERFLOW_BIN ); 00625 ib = static_cast<int>( I_Histo::OVERFLOW_BIN ); 00626 } 00627 else if ( i == -1 ) { 00628 ia = static_cast<int>( AIDA::IAxis::UNDERFLOW_BIN ); 00629 ib = static_cast<int>( I_Histo::UNDERFLOW_BIN ); 00630 } 00631 v[0] = ib; 00632 if ( h->i_any_bin( v ).count() == 0 ) continue; 00633 Profile_Bin& pBin = dynamic_cast<Profile_Bin&>( h->i_any_bin( v ) ); 00634 double centreX; 00635 if ( i >= 0 ) centreX = 0.5 * ( h->i_partition(0).i_lower_point(i) + h->i_partition(0).i_upper_point(i) ); 00636 else if ( i == -2 ) centreX = h->i_partition(0).i_upper_point() + 1; 00637 else if ( i == -1 ) centreX = h->i_partition(0).i_lower_point() - 1; 00638 histo->setBinContents( ia, 00639 pBin.count(), 00640 pBin.value(), 00641 pBin.error(), 00642 pBin.error(1), 00643 centreX ); 00644 } 00645 return histo; 00646 } 00647 00648 00649 AIDA::Dev::IDevProfile1D* 00650 Anaphe::AIDA_ObjectivityStore::ObjyHistogramConverter::convertFromObjy( AIDA::Dev::IDevHistogramFactory& factory, 00651 const ooHandle(PProfileHistoVar)& h ) 00652 { 00653 std::vector<double> edges( h->i_partition().bin_count() + 1 ); 00654 for ( int i = 0; i < h->i_partition().bin_count(); ++i ) edges[i] = h->i_partition().i_lower_point( i ); 00655 edges.back() = h->i_partition().i_upper_point(); 00656 00657 AIDA::Dev::IDevProfile1D* histo = factory.createProfile1D( std::string( h->name() ), edges, emptyString ); 00658 00659 std::vector<long int> v( 1 ); 00660 for ( int i = -2; i < histo->axis().bins(); ++i ) { 00661 int ia = i; 00662 int ib = i; 00663 if ( i == -2 ) { 00664 ia = static_cast<int>( AIDA::IAxis::OVERFLOW_BIN ); 00665 ib = static_cast<int>( I_Histo::OVERFLOW_BIN ); 00666 } 00667 else if ( i == -1 ) { 00668 ia = static_cast<int>( AIDA::IAxis::UNDERFLOW_BIN ); 00669 ib = static_cast<int>( I_Histo::UNDERFLOW_BIN ); 00670 } 00671 v[0] = ib; 00672 if ( h->i_any_bin( v ).count() == 0 ) continue; 00673 Profile_Bin& pBin = dynamic_cast<Profile_Bin&>( h->i_any_bin( v ) ); 00674 double centreX; 00675 if ( i >= 0 ) centreX = 0.5 * ( h->i_partition(0).i_lower_point(i) + h->i_partition(0).i_upper_point(i) ); 00676 else if ( i == -2 ) centreX = h->i_partition(0).i_upper_point() + 1; 00677 else if ( i == -1 ) centreX = h->i_partition(0).i_lower_point() - 1; 00678 histo->setBinContents( ia, 00679 pBin.count(), 00680 pBin.value(), 00681 pBin.error(), 00682 pBin.error(1), 00683 centreX ); 00684 } 00685 return histo; 00686 }