Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights reserved. 2 // See the file tools.license for terms. 3 4 #ifndef tools_waxml_histos 5 #define tools_waxml_histos 6 7 #include "../histo/h1d" 8 #include "../histo/h2d" 9 #include "../histo/h3d" 10 #include "../histo/p1d" 11 #include "../histo/p2d" 12 13 #include "../sout" 14 #include "../num2s" 15 #include "../srep" 16 17 #include <sstream> 18 19 namespace tools { 20 namespace waxml { 21 22 inline std::string soutd(std::ostringstream& a_oss,double a_value) { 23 a_oss.str(""); 24 a_oss << a_value; 25 std::string _s("\""); 26 _s += a_oss.str(); 27 _s += "\""; 28 return _s; 29 } 30 31 inline std::string bin_to_string(std::ostringstream& a_oss,int a_index) { 32 if(a_index==histo::axis_UNDERFLOW_BIN) { 33 return "UNDERFLOW"; 34 } else if(a_index==histo::axis_OVERFLOW_BIN) { 35 return "OVERFLOW"; 36 } else { 37 a_oss.str(""); 38 a_oss << a_index; 39 return a_oss.str(); 40 } 41 } 42 43 typedef std::map<std::string,std::string> annotations_t; 44 45 inline void write_annotations( 46 const annotations_t& a_annotations 47 ,std::ostream& a_writer 48 ,int aShift 49 ){ 50 if(a_annotations.empty()) return; 51 52 std::string spaces; 53 for(int i=0;i<aShift;i++) spaces += " "; 54 55 a_writer << spaces << " <annotation>" << std::endl; 56 57 annotations_t::const_iterator it; 58 for(it=a_annotations.begin();it!=a_annotations.end();++it){ 59 a_writer << spaces << " <item" 60 << " key=" << sout(to_xml((*it).first)) 61 << " value=" << sout(to_xml((*it).second)) 62 << "/>" << std::endl; 63 } 64 a_writer << spaces << " </annotation>" << std::endl; 65 } 66 67 inline void write_axis( 68 const histo::axis<double,unsigned int>& aAxis 69 ,const std::string& aDirection 70 ,std::ostream& a_writer 71 ,std::ostringstream& a_oss 72 ,int aShift 73 ){ 74 typedef histo::axis<double,unsigned int>::bn_t bn_t; 75 76 std::string spaces; 77 for(int i=0;i<aShift;i++) spaces += " "; 78 79 if(aAxis.is_fixed_binning()) { 80 a_writer << spaces << " <axis" 81 << " direction=" << sout(aDirection) 82 << " numberOfBins=" << num_out<bn_t>(aAxis.bins()) 83 << " min=" << soutd(a_oss,aAxis.lower_edge()) 84 << " max=" << soutd(a_oss,aAxis.upper_edge()) 85 << "/>" << std::endl; 86 } else { 87 a_writer << spaces << " <axis" 88 << " direction=" << sout(aDirection) 89 << " numberOfBins=" << num_out<bn_t>(aAxis.bins()) 90 << " min=" << soutd(a_oss,aAxis.lower_edge()) 91 << " max=" << soutd(a_oss,aAxis.upper_edge()) 92 << ">" << std::endl; 93 bn_t number = aAxis.bins()-1; 94 for(bn_t index=0;index<number;index++) { 95 a_writer << spaces << " <binBorder" 96 << " value=" << soutd(a_oss,aAxis.bin_upper_edge(index)) 97 << "/>" << std::endl; 98 } 99 a_writer << spaces << " </axis>" << std::endl; 100 } 101 } 102 103 inline void write_bin( 104 std::ostream& a_writer 105 ,std::ostringstream& a_oss 106 ,const histo::h1d& aObject 107 ,const std::string& aSpaces 108 ,int aIndex 109 ){ 110 unsigned int entries = aObject.bin_entries(aIndex); 111 if(entries) { 112 a_writer << aSpaces << " <bin1d" 113 << " binNum=" << sout(bin_to_string(a_oss,aIndex)) 114 << " entries=" << num_out<unsigned int>(entries) 115 << " height=" << soutd(a_oss,aObject.bin_height(aIndex)) 116 << " error=" << soutd(a_oss,aObject.bin_error(aIndex)); 117 118 double mean = aObject.bin_mean(aIndex); 119 if(mean!=0) { 120 a_writer << " weightedMean=" << soutd(a_oss,mean); 121 } 122 123 double stddev = aObject.bin_rms(aIndex); 124 if(stddev!=0) { 125 a_writer << " weightedRms=" << soutd(a_oss,stddev); 126 } 127 128 a_writer << "/>" << std::endl; 129 } 130 } 131 132 inline void write_bin( 133 std::ostream& a_writer 134 ,std::ostringstream& a_oss 135 ,const histo::h2d& aObject 136 ,const std::string& aSpaces 137 ,int aIndexX 138 ,int aIndexY 139 ){ 140 unsigned int entries = aObject.bin_entries(aIndexX,aIndexY); 141 if(entries) { 142 a_writer << aSpaces << " <bin2d" 143 << " binNumX=" << sout(bin_to_string(a_oss,aIndexX)) 144 << " binNumY=" << sout(bin_to_string(a_oss,aIndexY)) 145 << " entries=" << num_out<unsigned int>(entries) 146 << " height=" << soutd(a_oss,aObject.bin_height(aIndexX,aIndexY)) 147 << " error=" << soutd(a_oss,aObject.bin_error(aIndexX,aIndexY)); 148 149 double mean_x = aObject.bin_mean_x(aIndexX,aIndexY); 150 if(mean_x!=0) { 151 a_writer << " weightedMeanX=" << soutd(a_oss,mean_x); 152 } 153 double mean_y = aObject.bin_mean_y(aIndexX,aIndexY); 154 if(mean_y!=0) { 155 a_writer << " weightedMeanY=" << soutd(a_oss,mean_y); 156 } 157 158 double stddevX = aObject.bin_rms_x(aIndexX,aIndexY); 159 if(stddevX!=0) { 160 a_writer << " weightedRmsX=" << soutd(a_oss,stddevX); 161 } 162 double stddevY = aObject.bin_rms_y(aIndexX,aIndexY); 163 if(stddevY!=0) { 164 a_writer << " weightedRmsY=" << soutd(a_oss,stddevY); 165 } 166 167 a_writer << "/>" << std::endl; 168 } 169 } 170 171 inline void write_bin( 172 std::ostream& a_writer 173 ,std::ostringstream& a_oss 174 ,const histo::h3d& aObject 175 ,const std::string& aSpaces 176 ,int aIndexX 177 ,int aIndexY 178 ,int aIndexZ 179 ){ 180 unsigned int entries = aObject.bin_entries(aIndexX,aIndexY,aIndexZ); 181 if(entries) { 182 a_writer << aSpaces << " <bin3d" 183 << " binNumX=" << sout(bin_to_string(a_oss,aIndexX)) 184 << " binNumY=" << sout(bin_to_string(a_oss,aIndexY)) 185 << " binNumZ=" << sout(bin_to_string(a_oss,aIndexZ)) 186 << " entries=" << num_out<unsigned int>(entries) 187 << " height=" << soutd(a_oss,aObject.bin_height(aIndexX,aIndexY,aIndexZ)) 188 << " error=" << soutd(a_oss,aObject.bin_error(aIndexX,aIndexY,aIndexZ)); 189 190 191 double mean_x = aObject.bin_mean_x(aIndexX,aIndexY,aIndexZ); 192 if(mean_x!=0) { 193 a_writer << " weightedMeanX=" << soutd(a_oss,mean_x); 194 } 195 double mean_y = aObject.bin_mean_y(aIndexX,aIndexY,aIndexZ); 196 if(mean_y!=0) { 197 a_writer << " weightedMeanY=" << soutd(a_oss,mean_y); 198 } 199 double mean_z = aObject.bin_mean_z(aIndexX,aIndexY,aIndexZ); 200 if(mean_y!=0) { 201 a_writer << " weightedMeanZ=" << soutd(a_oss,mean_z); 202 } 203 204 double stddevX = aObject.bin_rms_x(aIndexX,aIndexY,aIndexZ); 205 if(stddevX!=0) { 206 a_writer << " weightedRmsX=" << soutd(a_oss,stddevX); 207 } 208 double stddevY = aObject.bin_rms_y(aIndexX,aIndexY,aIndexZ); 209 if(stddevY!=0) { 210 a_writer << " weightedRmsY=" << soutd(a_oss,stddevY); 211 } 212 double stddevZ = aObject.bin_rms_z(aIndexX,aIndexY,aIndexZ); 213 if(stddevZ!=0) { 214 a_writer << " weightedRmsZ=" << soutd(a_oss,stddevZ); 215 } 216 217 a_writer << "/>" << std::endl; 218 } 219 } 220 221 inline void write_bin( 222 std::ostream& a_writer 223 ,std::ostringstream& a_oss 224 ,const histo::p1d& aObject 225 ,const std::string& aSpaces 226 ,int aIndex 227 ){ 228 if(aObject.bin_entries(aIndex)) { 229 a_writer << aSpaces << " <bin1d" 230 << " binNum=" << sout(bin_to_string(a_oss,aIndex)) 231 << " entries=" << num_out<unsigned int>(aObject.bin_entries(aIndex)) 232 << " height=" << soutd(a_oss,aObject.bin_height(aIndex)) 233 << " error=" << soutd(a_oss,aObject.bin_error(aIndex)) 234 << " weightedMean=" << soutd(a_oss,aObject.bin_mean(aIndex)); 235 236 double stddev = aObject.bin_rms(aIndex); 237 if(stddev!=0) { 238 a_writer << " weightedRms=" << soutd(a_oss,stddev); 239 } 240 241 a_writer << " rms=" << soutd(a_oss,aObject.bin_rms_value(aIndex)); 242 a_writer << "/>" << std::endl; 243 } 244 } 245 246 inline void write_bin( 247 std::ostream& a_writer 248 ,std::ostringstream& a_oss 249 ,const histo::p2d& aObject 250 ,const std::string& aSpaces 251 ,int aIndexX 252 ,int aIndexY 253 ){ 254 if(aObject.bin_entries(aIndexX,aIndexY)) { 255 a_writer << aSpaces << " <bin2d" 256 << " binNumX=" << sout(bin_to_string(a_oss,aIndexX)) 257 << " binNumY=" << sout(bin_to_string(a_oss,aIndexY)) 258 << " entries=" << num_out<unsigned int>(aObject.bin_entries(aIndexX,aIndexY)) 259 << " height=" << soutd(a_oss,aObject.bin_height(aIndexX,aIndexY)) 260 << " error=" << soutd(a_oss,aObject.bin_error(aIndexX,aIndexY)) 261 << " weightedMeanX=" << soutd(a_oss,aObject.bin_mean_x(aIndexX,aIndexY)) 262 << " weightedMeanY=" << soutd(a_oss,aObject.bin_mean_y(aIndexX,aIndexY)); 263 264 double stddevX = aObject.bin_rms_x(aIndexX,aIndexY); 265 if(stddevX!=0) { 266 a_writer << " weightedRmsX=" << soutd(a_oss,stddevX); 267 } 268 double stddevY = aObject.bin_rms_y(aIndexX,aIndexY); 269 if(stddevY!=0) { 270 a_writer << " weightedRmsY=" << soutd(a_oss,stddevY); 271 } 272 273 a_writer << " rms=" << soutd(a_oss,aObject.bin_rms_value(aIndexX,aIndexY)); 274 a_writer << "/>" << std::endl; 275 } 276 } 277 278 inline bool write( 279 std::ostream& a_writer 280 ,const histo::h1d& aObject 281 ,const std::string& aPath 282 ,const std::string& aName 283 ,int aShift = 0 284 ){ 285 std::ostringstream ossd; 286 ossd.precision(25); 287 288 typedef histo::axis<double,unsigned int>::bn_t bn_t; 289 290 std::ostream& writer = a_writer; 291 292 std::string spaces; 293 for(int i=0;i<aShift;i++) spaces += " "; 294 295 // <histogram1d> : 296 writer << spaces << " <histogram1d" 297 << " path=" << sout(to_xml(aPath)) 298 << " name=" << sout(to_xml(aName)) 299 << " title=" << sout(to_xml(aObject.title())) 300 << ">" << std::endl; 301 302 // <annotations> : 303 write_annotations(aObject.annotations(),writer,aShift); 304 305 // <axis> : 306 write_axis(aObject.axis(),"x",writer,ossd,aShift); 307 308 // <statistics> : 309 writer << spaces << " <statistics" 310 << " entries=" << num_out<unsigned int>(aObject.entries()) 311 << ">" << std::endl; 312 writer << spaces << " <statistic" 313 << " direction=" << sout("x") 314 << " mean=" << soutd(ossd,aObject.mean()) 315 << " rms=" << soutd(ossd,aObject.rms()) 316 << "/>" << std::endl; 317 writer << spaces << " </statistics>" << std::endl; 318 319 // bins : 320 writer << spaces << " <data1d>" << std::endl; 321 322 bn_t xbins = aObject.axis().bins(); 323 for(bn_t index=0;index<xbins;index++) 324 write_bin(writer,ossd,aObject,spaces,index); 325 326 write_bin(writer,ossd,aObject,spaces,histo::axis_UNDERFLOW_BIN); 327 write_bin(writer,ossd,aObject,spaces,histo::axis_OVERFLOW_BIN); 328 329 writer << spaces << " </data1d>" << std::endl; 330 writer << spaces << " </histogram1d>" << std::endl; 331 332 return true; 333 } 334 335 inline bool write( 336 std::ostream& a_writer 337 ,const histo::h2d& aObject 338 ,const std::string& aPath 339 ,const std::string& aName 340 ,int aShift = 0 341 ){ 342 std::ostringstream ossd; 343 ossd.precision(25); 344 345 typedef histo::axis<double,unsigned int>::bn_t bn_t; 346 347 std::ostream& writer = a_writer; 348 349 std::string spaces; 350 for(int i=0;i<aShift;i++) spaces += " "; 351 352 // <histogram2d> : 353 writer << spaces << " <histogram2d" 354 << " path=" << sout(to_xml(aPath)) 355 << " name=" << sout(to_xml(aName)) 356 << " title=" << sout(to_xml(aObject.title())) 357 << ">" << std::endl; 358 359 // <annotations> : 360 write_annotations(aObject.annotations(),writer,aShift); 361 362 // <axis> : 363 write_axis(aObject.axis_x(),"x",writer,ossd,aShift); 364 write_axis(aObject.axis_y(),"y",writer,ossd,aShift); 365 366 // <statistics> : 367 writer << spaces << " <statistics" 368 << " entries=" << num_out<unsigned int>(aObject.entries()) 369 << ">" << std::endl; 370 writer << spaces << " <statistic" 371 << " direction=" << sout("x") 372 << " mean=" << soutd(ossd,aObject.mean_x()) 373 << " rms=" << soutd(ossd,aObject.rms_x()) 374 << "/>" << std::endl; 375 writer << spaces << " <statistic" 376 << " direction=" << sout("y") 377 << " mean=" << soutd(ossd,aObject.mean_y()) 378 << " rms=" << soutd(ossd,aObject.rms_y()) 379 << "/>" << std::endl; 380 writer << spaces << " </statistics>" << std::endl; 381 382 // bins : 383 writer << spaces << " <data2d>" << std::endl; 384 385 bn_t xbins = aObject.axis_x().bins(); 386 bn_t ybins = aObject.axis_y().bins(); 387 bn_t indexX,indexY; 388 for(indexX=0;indexX<xbins;indexX++) { 389 for(indexY=0;indexY<ybins;indexY++) { 390 write_bin(writer,ossd,aObject,spaces,indexX,indexY); 391 } 392 } 393 394 write_bin(writer,ossd,aObject,spaces,histo::axis_UNDERFLOW_BIN,histo::axis_UNDERFLOW_BIN); 395 write_bin(writer,ossd,aObject,spaces,histo::axis_OVERFLOW_BIN,histo::axis_UNDERFLOW_BIN); 396 write_bin(writer,ossd,aObject,spaces,histo::axis_UNDERFLOW_BIN,histo::axis_OVERFLOW_BIN); 397 write_bin(writer,ossd,aObject,spaces,histo::axis_OVERFLOW_BIN,histo::axis_OVERFLOW_BIN); 398 399 for(indexX=0;indexX<xbins;indexX++){ 400 write_bin(writer,ossd,aObject,spaces,indexX,histo::axis_UNDERFLOW_BIN); 401 write_bin(writer,ossd,aObject,spaces,indexX,histo::axis_OVERFLOW_BIN); 402 } 403 404 for(indexY=0;indexY<ybins;indexY++){ 405 write_bin(writer,ossd,aObject,spaces,histo::axis_UNDERFLOW_BIN,indexY); 406 write_bin(writer,ossd,aObject,spaces,histo::axis_OVERFLOW_BIN,indexY); 407 } 408 409 writer << spaces << " </data2d>" << std::endl; 410 writer << spaces << " </histogram2d>" << std::endl; 411 412 return true; 413 } 414 415 inline bool write( 416 std::ostream& a_writer 417 ,const histo::h3d& aObject 418 ,const std::string& aPath 419 ,const std::string& aName 420 ,int aShift = 0 421 ){ 422 std::ostringstream ossd; 423 ossd.precision(25); 424 425 typedef histo::axis<double,unsigned int>::bn_t bn_t; 426 std::ostream& writer = a_writer; 427 428 std::string spaces; 429 for(int i=0;i<aShift;i++) spaces += " "; 430 431 // <histogram3d> : 432 writer << spaces << " <histogram3d" 433 << " path=" << sout(to_xml(aPath)) 434 << " name=" << sout(to_xml(aName)) 435 << " title=" << sout(to_xml(aObject.title())) 436 << ">" << std::endl; 437 438 // <annotations> : 439 write_annotations(aObject.annotations(),writer,aShift); 440 441 // <axis> : 442 write_axis(aObject.axis_x(),"x",writer,ossd,aShift); 443 write_axis(aObject.axis_y(),"y",writer,ossd,aShift); 444 write_axis(aObject.axis_z(),"z",writer,ossd,aShift); 445 446 // <statistics> : 447 writer << spaces << " <statistics" 448 << " entries=" << num_out<unsigned int>(aObject.entries()) 449 << ">" << std::endl; 450 writer << spaces << " <statistic" 451 << " direction=" << sout("x") 452 << " mean=" << soutd(ossd,aObject.mean_x()) 453 << " rms=" << soutd(ossd,aObject.rms_x()) 454 << "/>" << std::endl; 455 writer << spaces << " <statistic" 456 << " direction=" << sout("y") 457 << " mean=" << soutd(ossd,aObject.mean_y()) 458 << " rms=" << soutd(ossd,aObject.rms_y()) 459 << "/>" << std::endl; 460 writer << spaces << " <statistic" 461 << " direction=" << sout("z") 462 << " mean=" << soutd(ossd,aObject.mean_z()) 463 << " rms=" << soutd(ossd,aObject.rms_z()) 464 << "/>" << std::endl; 465 writer << spaces << " </statistics>" << std::endl; 466 467 // bins : 468 writer << spaces << " <data3d>" << std::endl; 469 bn_t xbins = aObject.axis_x().bins(); 470 bn_t ybins = aObject.axis_y().bins(); 471 bn_t zbins = aObject.axis_z().bins(); 472 bn_t indexX,indexY,indexZ; 473 for(indexX=0;indexX<xbins;indexX++) { 474 for(indexY=0;indexY<ybins;indexY++) { 475 for(indexZ=0;indexZ<zbins;indexZ++) { 476 write_bin(writer,ossd,aObject,spaces,indexX,indexY,indexZ); 477 } 478 } 479 } 480 481 // Corners : 482 write_bin(writer,ossd,aObject,spaces, 483 histo::axis_UNDERFLOW_BIN, 484 histo::axis_UNDERFLOW_BIN, 485 histo::axis_UNDERFLOW_BIN); 486 write_bin(writer,ossd,aObject,spaces, 487 histo::axis_OVERFLOW_BIN, 488 histo::axis_UNDERFLOW_BIN, 489 histo::axis_UNDERFLOW_BIN); 490 write_bin(writer,ossd,aObject,spaces, 491 histo::axis_UNDERFLOW_BIN, 492 histo::axis_OVERFLOW_BIN, 493 histo::axis_UNDERFLOW_BIN); 494 write_bin(writer,ossd,aObject,spaces, 495 histo::axis_OVERFLOW_BIN, 496 histo::axis_OVERFLOW_BIN, 497 histo::axis_UNDERFLOW_BIN); 498 499 write_bin(writer,ossd,aObject,spaces, 500 histo::axis_UNDERFLOW_BIN, 501 histo::axis_UNDERFLOW_BIN, 502 histo::axis_OVERFLOW_BIN); 503 write_bin(writer,ossd,aObject,spaces, 504 histo::axis_OVERFLOW_BIN, 505 histo::axis_UNDERFLOW_BIN, 506 histo::axis_OVERFLOW_BIN); 507 write_bin(writer,ossd,aObject,spaces, 508 histo::axis_UNDERFLOW_BIN, 509 histo::axis_OVERFLOW_BIN, 510 histo::axis_OVERFLOW_BIN); 511 write_bin(writer,ossd,aObject,spaces, 512 histo::axis_OVERFLOW_BIN, 513 histo::axis_OVERFLOW_BIN, 514 histo::axis_OVERFLOW_BIN); 515 516 517 // Edges : 518 for(indexX=0;indexX<xbins;indexX++){ 519 write_bin(writer,ossd,aObject,spaces, 520 indexX, 521 histo::axis_UNDERFLOW_BIN, 522 histo::axis_UNDERFLOW_BIN); 523 write_bin(writer,ossd,aObject,spaces, 524 indexX, 525 histo::axis_OVERFLOW_BIN, 526 histo::axis_UNDERFLOW_BIN); 527 write_bin(writer,ossd,aObject,spaces, 528 indexX, 529 histo::axis_UNDERFLOW_BIN, 530 histo::axis_OVERFLOW_BIN); 531 write_bin(writer,ossd,aObject,spaces, 532 indexX, 533 histo::axis_OVERFLOW_BIN, 534 histo::axis_OVERFLOW_BIN); 535 } 536 537 for(indexY=0;indexY<ybins;indexY++){ 538 write_bin(writer,ossd,aObject,spaces, 539 histo::axis_UNDERFLOW_BIN, 540 indexY, 541 histo::axis_UNDERFLOW_BIN); 542 write_bin(writer,ossd,aObject,spaces, 543 histo::axis_OVERFLOW_BIN, 544 indexY, 545 histo::axis_UNDERFLOW_BIN); 546 write_bin(writer,ossd,aObject,spaces, 547 histo::axis_UNDERFLOW_BIN, 548 indexY, 549 histo::axis_OVERFLOW_BIN); 550 write_bin(writer,ossd,aObject,spaces, 551 histo::axis_OVERFLOW_BIN, 552 indexY, 553 histo::axis_OVERFLOW_BIN); 554 } 555 556 for(indexZ=0;indexZ<zbins;indexZ++){ 557 write_bin(writer,ossd,aObject,spaces, 558 histo::axis_UNDERFLOW_BIN, 559 histo::axis_UNDERFLOW_BIN, 560 indexZ); 561 write_bin(writer,ossd,aObject,spaces, 562 histo::axis_OVERFLOW_BIN, 563 histo::axis_UNDERFLOW_BIN, 564 indexZ); 565 write_bin(writer,ossd,aObject,spaces, 566 histo::axis_UNDERFLOW_BIN, 567 histo::axis_OVERFLOW_BIN, 568 indexZ); 569 write_bin(writer,ossd,aObject,spaces, 570 histo::axis_OVERFLOW_BIN, 571 histo::axis_OVERFLOW_BIN, 572 indexZ); 573 } 574 575 576 // Faces : 577 for(indexX=0;indexX<xbins;indexX++) { 578 for(indexY=0;indexY<ybins;indexY++) { 579 write_bin(writer,ossd,aObject,spaces, 580 indexX,indexY,histo::axis_UNDERFLOW_BIN); 581 write_bin(writer,ossd,aObject,spaces, 582 indexX,indexY,histo::axis_OVERFLOW_BIN); 583 } 584 } 585 for(indexY=0;indexY<ybins;indexY++) { 586 for(indexZ=0;indexZ<zbins;indexZ++) { 587 write_bin(writer,ossd,aObject,spaces, 588 histo::axis_UNDERFLOW_BIN,indexY,indexZ); 589 write_bin(writer,ossd,aObject,spaces, 590 histo::axis_OVERFLOW_BIN,indexY,indexZ); 591 } 592 } 593 for(indexX=0;indexX<xbins;indexX++) { 594 for(indexZ=0;indexZ<zbins;indexZ++) { 595 write_bin(writer,ossd,aObject,spaces, 596 indexX,histo::axis_UNDERFLOW_BIN,indexZ); 597 write_bin(writer,ossd,aObject,spaces, 598 indexX,histo::axis_OVERFLOW_BIN,indexZ); 599 } 600 } 601 602 writer << spaces << " </data3d>" << std::endl; 603 writer << spaces << " </histogram3d>" << std::endl; 604 605 return true; 606 } 607 608 inline bool write( 609 std::ostream& a_writer 610 ,const histo::p1d& aObject 611 ,const std::string& aPath 612 ,const std::string& aName 613 ,int aShift = 0 614 ){ 615 std::ostringstream ossd; 616 ossd.precision(25); 617 618 typedef histo::axis<double,unsigned int>::bn_t bn_t; 619 std::ostream& writer = a_writer; 620 621 std::string spaces; 622 for(int i=0;i<aShift;i++) spaces += " "; 623 624 // <profile1d> : 625 writer << spaces << " <profile1d" 626 << " path=" << sout(to_xml(aPath)) 627 << " name=" << sout(to_xml(aName)) 628 << " title=" << sout(to_xml(aObject.title())) 629 << ">" << std::endl; 630 631 // <annotations> : 632 write_annotations(aObject.annotations(),writer,aShift); 633 634 // <axis> : 635 write_axis(aObject.axis(),"x",writer,ossd,aShift); 636 637 // <statistics> : 638 writer << spaces << " <statistics" 639 << " entries=" << num_out<unsigned int>(aObject.entries()) 640 << ">" << std::endl; 641 writer << spaces << " <statistic" 642 << " direction=" << sout("x") 643 << " mean=" << soutd(ossd,aObject.mean()) 644 << " rms=" << soutd(ossd,aObject.rms()) 645 << "/>" << std::endl; 646 writer << spaces << " </statistics>" << std::endl; 647 648 // bins : 649 writer << spaces << " <data1d>" << std::endl; 650 bn_t xbins = aObject.axis().bins(); 651 for(bn_t index=0;index<xbins;index++) { 652 write_bin(writer,ossd,aObject,spaces,index); 653 } 654 655 write_bin(writer,ossd,aObject,spaces,histo::axis_UNDERFLOW_BIN); 656 write_bin(writer,ossd,aObject,spaces,histo::axis_OVERFLOW_BIN); 657 658 writer << spaces << " </data1d>" << std::endl; 659 writer << spaces << " </profile1d>" << std::endl; 660 661 return true; 662 } 663 664 inline bool write( 665 std::ostream& a_writer 666 ,const histo::p2d& aObject 667 ,const std::string& aPath 668 ,const std::string& aName 669 ,int aShift = 0 670 ){ 671 std::ostringstream ossd; 672 ossd.precision(25); 673 674 typedef histo::axis<double,unsigned int>::bn_t bn_t; 675 std::ostream& writer = a_writer; 676 677 std::string spaces; 678 for(int i=0;i<aShift;i++) spaces += " "; 679 680 // <profile2d> : 681 writer << spaces << " <profile2d" 682 << " path=" << sout(to_xml(aPath)) 683 << " name=" << sout(to_xml(aName)) 684 << " title=" << sout(to_xml(aObject.title())) 685 << ">" << std::endl; 686 687 // <annotations> : 688 write_annotations(aObject.annotations(),writer,aShift); 689 690 // <axis> : 691 write_axis(aObject.axis_x(),"x",writer,ossd,aShift); 692 write_axis(aObject.axis_y(),"y",writer,ossd,aShift); 693 694 // <statistics> : 695 writer << spaces << " <statistics" 696 << " entries=" << num_out<unsigned int>(aObject.entries()) 697 << ">" << std::endl; 698 writer << spaces << " <statistic" 699 << " direction=" << sout("x") 700 << " mean=" << soutd(ossd,aObject.mean_x()) 701 << " rms=" << soutd(ossd,aObject.rms_x()) 702 << "/>" << std::endl; 703 writer << spaces << " <statistic" 704 << " direction=" << sout("y") 705 << " mean=" << soutd(ossd,aObject.mean_y()) 706 << " rms=" << soutd(ossd,aObject.rms_y()) 707 << "/>" << std::endl; 708 writer << spaces << " </statistics>" << std::endl; 709 710 // bins : 711 writer << spaces << " <data2d>" << std::endl; 712 {bn_t xbins = aObject.axis_x().bins(); 713 bn_t ybins = aObject.axis_y().bins(); 714 for(bn_t indexX=0;indexX<xbins;indexX++) { 715 for(bn_t indexY=0;indexY<ybins;indexY++) { 716 write_bin(writer,ossd,aObject,spaces,indexX,indexY); 717 } 718 }} 719 720 write_bin(writer,ossd,aObject,spaces, 721 histo::axis_UNDERFLOW_BIN,histo::axis_UNDERFLOW_BIN); 722 write_bin(writer,ossd,aObject,spaces, 723 histo::axis_OVERFLOW_BIN,histo::axis_UNDERFLOW_BIN); 724 write_bin(writer,ossd,aObject,spaces, 725 histo::axis_UNDERFLOW_BIN,histo::axis_OVERFLOW_BIN); 726 write_bin(writer,ossd,aObject,spaces, 727 histo::axis_OVERFLOW_BIN,histo::axis_OVERFLOW_BIN); 728 729 for(bn_t indexX=0;indexX<aObject.axis_x().bins();indexX++){ 730 write_bin(writer,ossd,aObject,spaces,indexX,histo::axis_UNDERFLOW_BIN); 731 write_bin(writer,ossd,aObject,spaces,indexX,histo::axis_OVERFLOW_BIN); 732 } 733 734 for(bn_t indexY=0;indexY<aObject.axis_y().bins();indexY++){ 735 write_bin(writer,ossd,aObject,spaces,histo::axis_UNDERFLOW_BIN,indexY); 736 write_bin(writer,ossd,aObject,spaces,histo::axis_OVERFLOW_BIN,indexY); 737 } 738 739 writer << spaces << " </data2d>" << std::endl; 740 writer << spaces << " </profile2d>" << std::endl; 741 742 return true; 743 } 744 745 }} 746 747 #endif