#include #include #include "TROOT.h" #include "TFile.h" #include "TH1D.h" #include "km3net-dataformat/offline/Evt.hh" #include "JDAQ/JDAQEventIO.hh" #include "JAAnet/JAAnetToolkit.hh" #include "JSupport/JTriggeredFileScanner.hh" #include "JSupport/JMonteCarloFileSupportkit.hh" #include "JSupport/JSupport.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" /** * \file * * Example program to histogram trigger efficiency. * \author mdejong */ int main(int argc, char **argv) { using namespace std; using namespace JPP; using namespace KM3NETDAQ; JTriggeredFileScanner<> inputFile; string outputFile; int debug; try { JParser<> zap("Example program to histogram trigger efficiency."); zap['f'] = make_field(inputFile); zap['o'] = make_field(outputFile) = "efficiency.root"; zap['d'] = make_field(debug) = 1; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } // output TFile out(outputFile.c_str(), "recreate"); TH1D h0("h0", NULL, 100, 0.5, 100.5); TH1D h1("h1", NULL, 100, 0.5, 100.5); TH1D h2("h2", NULL, 100, 0.5, 100.5); h2.Sumw2(); while (inputFile.hasNext()) { STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl); JTriggeredFileScanner<>::multi_pointer_type ps = inputFile.next(); const Evt* event = ps; const int n = event->mc_hits.size() - count_if(event->mc_hits.begin(), event->mc_hits.cend(), &is_noise); h1.Fill((Double_t) n, 1.0); } STATUS(endl); for (JMultipleFileScanner in(inputFile); in.hasNext(); ) { STATUS("event: " << setw(10) << in.getCounter() << '\r'); DEBUG(endl); const Evt* event = in.next(); const int n = event->mc_hits.size() - count_if(event->mc_hits.begin(), event->mc_hits.cend(), &is_noise); h0.Fill((Double_t) n, 1.0); } STATUS(endl); for (Int_t i = 1; i <= h1.GetNbinsX(); ++i) { const Double_t y1 = h1.GetBinContent(i); const Double_t y0 = h0.GetBinContent(i); if (y0 != 0.0) { const Double_t y3 = y1 / y0; const Double_t w3 = sqrt(y1 * (y0 - y1) / (y0*y0*y0)); h2.SetBinContent(i, y3); h2.SetBinError (i, w3); } else { ERROR("Bin " << h0.GetName() << "[" << i << "] empty." << endl); } } out.Write(); out.Close(); }