#ifndef ROOTNTUPLEPDFTESTER_H #define ROOTNTUPLEPDFTESTER_H #include "TTree.h" #include "TFile.h" #include #include "StatTools/Pdf/RandomGenerator.h" #include "StatTools/Pdf/Tuples.h" namespace Pdf { template void addBranchSuffix( std::string& s ); template<> inline void addBranchSuffix( std::string& s ) { s+="/I"; } template<> inline void addBranchSuffix( std::string& s ) { s+="/I"; } template<> inline void addBranchSuffix( std::string& s ) { s+="/F"; } template<> inline void addBranchSuffix( std::string& s ) { s+="/D"; } template inline void addBranchN( TTree& tree, T& x, int n, const std::string& name ) { std::string s( name ); s +=( '0' + n ); std::string sX( s ); addBranchSuffix( sX ); tree.Branch( s.c_str(), & x, sX.c_str() ); } template struct iterate { template static void addBranch( TTree& tree, ntuple& x, const std::string& name ) { iterate< n - 1 >::addBranch( tree, x, name ); addBranchN( tree, boost::get< n - 1 >( x ), n - 1, name ); } }; template<> struct iterate< 1 > { template static void addBranch( TTree& tree, ntuple& x, const std::string& name ) { addBranchN( tree, boost::get< 0 >( x ), 0, name ); } }; class RootNtuplePdfTester { public: RootNtuplePdfTester( const char * fileName ) : _file( fileName, "RECREATE" ) {} ~RootNtuplePdfTester() { _file.Close(); } template void test( const Pdf& pdf, const char * treeName, const char * treeDescr, int n = 10000 ) { RandomGenerator generator( pdf ); TTree tree( treeName, treeDescr ); typedef typename tuple_from_typelist< typename Types::type >::type ntuple; ntuple x; iterate::addBranch( tree, x, "x" ); for( int i = 0; i < n; i ++ ) { tuple_adapter::generate( generator, x ); tree.Fill(); } tree.Write(); } private: TFile _file; }; } #endif