#include "eff_utils/Efficiency.hpp" #include "eff_utils/EffTool.hpp" #include "eff_utils/EffInfo.hpp" #include #include #include #include #include using namespace std; using namespace eff_utils; int main() { // Define the user interface object EffInfo mySpec; mySpec.EffName("Test"); mySpec.EffType("Binned"); mySpec.EffVersion(4); mySpec.ObjType("Electron"); mySpec.ObjQuality("loose_trk"); std::vector< std::string > vars; vars.push_back("DetEta"); mySpec.EffVarNames( vars ); mySpec.ObjVersion(2); std::cout << " going to try using filename : " << mySpec.MakeFileName() << std::endl; EffTool tryme(mySpec); if( tryme.isValid() ) std::cout << " Succeeded in loading efficiency! " << std::endl; else { std::cout << " Failed to load efficiency " << std::endl; return 1; } // Get the Efficiency Object const Efficiency * ptr = &tryme.EffObj(); if ( !ptr ) { std::cout << " For some reason the efficiency pointer is zero! " << std::endl; return 1; } // Access the Efficiency object cout << "EffType: " << ptr->Info().EffType() << endl; cout << "EffName: " << ptr->Info().EffName() << endl; cout << "EffDimension " << ptr->Info().EffNVars() << endl; cout << "EffVersion: " << ptr->Info().EffVersion() << endl; cout << "ObjType: " << ptr->Info().ObjType() << endl; cout << "ObjQuality: " << ptr->Info().ObjQuality() << endl; cout << "ObjVersionL " << ptr->Info().ObjVersion() << endl; cout << "D0NoteID: " << ptr->Info().D0NoteID() << endl; cout << "RunRange: " << ptr->Info().RunRangeLow() << " " << ptr->Info().RunRangeHigh() << endl; // Now test reading in one where there is more than one match! std::cout << " Test 2 " << std::endl; mySpec.EffName("Test-2"); mySpec.EffType("Binned"); mySpec.EffVersion(4); mySpec.ObjType("Electron"); mySpec.ObjQuality("loose_trk"); std::vector< std::string > vars2; vars2.push_back("DetEta"); mySpec.EffVarNames( vars2 ); mySpec.ObjVersion(2); std::cout << " going to try using filename : " << mySpec.MakeFileName() << std::endl; EffTool * toolptr; try { toolptr = new EffTool(mySpec); } catch( const eff_utils::EffDuplicateMatchesToRequest & e) { std::cout << e._message << std::endl; } catch(...) { std::cout << "shouldn't get here! " << std::endl; return 1; } if( toolptr && toolptr->isValid() ) { std::cout << " Succeeded in loading efficiency! " << std::endl; std::cout << " Which is a bad thing since it should have failed! " << std::endl; std::cout << " But up to now it is autorized to use the efficiency if you want"<< std::endl; } else { std::cout << " Failed to load efficiency " << std::endl; std::cout << " Which is a good thing since it should have failed! " << std::endl; } // Get the Efficiency Object /* ptr = &tryme2.EffObj(); if ( !ptr ) { std::cout << " For some reason the efficiency pointer is zero! " << std::endl; return 1; } // Access the Efficiency object cout << "EffType: " << ptr->Info().EffType() << endl; cout << "EffName: " << ptr->Info().EffName() << endl; cout << "EffDimension " << ptr->Info().EffNVars() << endl; cout << "EffVersion: " << ptr->Info().EffVersion() << endl; cout << "ObjType: " << ptr->Info().ObjType() << endl; cout << "ObjQuality: " << ptr->Info().ObjQuality() << endl; cout << "ObjVersionL " << ptr->Info().ObjVersion() << endl; cout << "D0NoteID: " << ptr->Info().D0NoteID() << endl; cout << "RunRange: " << ptr->Info().RunRangeLow() << " " << ptr->Info().RunRangeHigh() << endl; */ // now try next test. std::cout << " Test 3 ! " << std::endl; EffInfo mySpec2; mySpec2.EffName("Test-3"); mySpec2.EffType("Binned"); //mySpec.EffVersion(4); don't specify version! mySpec2.ObjType("Electron"); mySpec2.ObjQuality("loose_trk"); vars2.clear(); vars2.push_back("DetEta"); mySpec2.EffVarNames( vars2 ); mySpec2.ObjVersion(2); std::cout << " going to try using filename : " << mySpec2.MakeFileName() << std::endl; bool thrown = false; EffTool * tryme3; try { tryme3 = new EffTool(mySpec2); } catch(const EffDuplicateMatchesToRequest & e) { std::cout << "Duplicates found!" << std::endl; thrown = true; } catch(...) { std::cout << "Shouldn't get here either!" << std::endl; return 1; } if( !thrown ) { std::cout << "Expected exception did not get thrown!" << std::endl; return 1; } if( tryme3 && tryme3->isValid() ) { std::cout << " Succeeded in loading efficiency! " << std::endl; } else { std::cout << " Failed to load efficiency " << std::endl; std::cout << " Which is good, Because we prefer to throw an exeption if there is an ambiguity what kind of efficiency should be loaded" << std::endl; } // Get the Efficiency Object // now try again but this tim ebeing more specific std::cout << "Test 4" << std::endl; mySpec2.EffVersion(5); EffTool tryme4(mySpec2); if( tryme4.isValid() ) { std::cout << " Succeeded in loading efficiency! " << std::endl; } else { std::cout << " Failed to load efficiency " << std::endl; return 1; } std::ofstream of("test.spc"); of << tryme4.EffObj(); of.close(); // TriggerVersion test { EffInfo mySpec; mySpec.EffName("Test"); mySpec.EffType("Binned"); mySpec.EffVersion(4); mySpec.ObjType("Muon"); mySpec.ObjQuality("l3trk8h10"); mySpec.ObjRelativeTo("trackloose") ; std::vector< std::string > vars; vars.push_back("z"); vars.push_back("cfteta"); mySpec.EffVarNames( vars ); mySpec.ObjVersion(1); // version should be in the range 8 - 13.99 mySpec.TriggerVersion("v12") ; { EffTool tryme(mySpec); if( tryme.isValid() ) std::cout << " Succeeded in loading efficiency! " << std::endl; else { std::cout << " Failed to load efficiency " << std::endl; return 1; } // Get the Efficiency Object const Efficiency * ptr = &tryme.EffObj(); if ( !ptr ) { std::cout << " For some reason the efficiency pointer is zero! " << std::endl; return 1; } // Access the Trigger versions cout << "ObjType: " << ptr->Info().ObjType() << endl; cout << "ObjQuality: " << ptr->Info().ObjQuality() << endl; cout << "TriggerVersion: " << ptr->Info().TriggerVersion() << endl ; cout << "TriggerVersion low - high " << ptr->Info().TriggerVersionLow() << " " << ptr->Info().TriggerVersionHigh() << endl; } { // version should be in the range 8 - 13.99 // trying to load efficiency with wrong trigger version mySpec.TriggerVersion("14") ; EffTool tryme(mySpec); if( tryme.isValid() ){ std::cout << " Succeeded in loading efficiency! This is wrong, because trigger version outside specified range!" << std::endl; return 1 ; } else std::cout << " Failed to load efficiency. This is right! " << std::endl; } } // TriggerVersion Low - High test { EffInfo mySpec; mySpec.EffName("Test"); mySpec.EffType("Binned"); mySpec.EffVersion(4); mySpec.ObjType("Muon"); mySpec.ObjQuality("l3trk8h10"); mySpec.ObjRelativeTo("trackloose") ; std::vector< std::string > vars; vars.push_back("z"); vars.push_back("cfteta"); mySpec.EffVarNames( vars ); mySpec.ObjVersion(1); // version should be in the range 8 - 13.99 mySpec.TriggerVersionLow("v11.11") ; mySpec.TriggerVersionHigh("v12.11") ; { EffTool tryme(mySpec); if( tryme.isValid() ) std::cout << " Succeeded in loading efficiency! " << std::endl; else { std::cout << " Failed to load efficiency " << std::endl; return 1; } // Get the Efficiency Object const Efficiency * ptr = &tryme.EffObj(); if ( !ptr ) { std::cout << " For some reason the efficiency pointer is zero! " << std::endl; return 1; } // Access the Trigger versions cout << "ObjType: " << ptr->Info().ObjType() << endl; cout << "ObjQuality: " << ptr->Info().ObjQuality() << endl; cout << "TriggerVersion: " << ptr->Info().TriggerVersion() << endl ; cout << "TriggerVersion low - high " << ptr->Info().TriggerVersionLow() << " " << ptr->Info().TriggerVersionHigh() << endl; } { // version should be in the range 8 - 13.99 // trying to load efficiency with wrong trigger version mySpec.TriggerVersionLow("13.0") ; mySpec.TriggerVersionHigh("14.01") ; EffTool tryme(mySpec); if( tryme.isValid() ) { std::cout << " Succeeded in loading efficiency! This is wrong, because trigger version outside specified range!" << std::endl; return 1 ; } else std::cout << " Failed to load efficiency. This is right! " << std::endl; } } return 0; }