#include #include #include "TH1.h" #include "eff_utils/BinnedEfficiency.hpp" #include "eff_utils/EffWriteManager.hpp" #include "eff_utils/EffInfo.hpp" #include #include using namespace eff_utils; // in this example we create 2 histograms and save them to one file int main() { // make a histogram containing the information TH1F * h = new TH1F("test","test", 21, -2.1, 2.1); h->FillRandom("gaus"); // make an efficiency BinnedEfficiency * beff = new BinnedEfficiency(h); // create its descriptive data EffInfo * info = new EffInfo(); info->EffType("Binned"); info->EffVersion(0); info->EffName("gaus"); std::vector< std::string > vars; vars.push_back( "eta"); info->EffVarNames( vars ); info->ObjType( "EM"); info->ObjQuality("Tight"); info->ObjVersion(8); info->D0NoteID(0); // set the info in the efficiency beff->Info( *info ); // Efficiency makes a copy of the info so we can clear it now and reuse it one more time info->Clear() ; // creatin another efficiency object with a EffInfo slightly different TH1F * h1 = new TH1F("test1","test1", 21, -2.1, 2.1); h->FillRandom("gaus"); // make an efficiency BinnedEfficiency * beff1 = new BinnedEfficiency(h1); // reuse previously created object (must be cleaned before) info->EffType("Binned"); info->EffVersion(1); info->EffName("gaus"); vars.clear() ; vars.push_back( "eta"); info->EffVarNames( vars ); info->ObjType( "EM"); info->ObjQuality("Tight"); info->ObjVersion(8); info->Comments("Second efficiency has only the EffVersion different"); beff1->Info( *info ); // Efficiency makes a copy of the info so we can kill the pointer now delete info; // now here is how to write the efficiency to a file // 1) create a WriteManager and specify the directory path EffWriteManager manager("./") ; // 2) stream it out to the file manager.Save(*beff) ; // 3) Save second histogram to file. The manager will decide if this efficiency should be // placed in the same file or not. It will verify if there is an efficiency // with exactly the same meta data and if it find any, it will not save current histogram. manager.Save(*beff1) ; // done return 0; }