File indexing completed on 2024-04-06 12:23:22
0001 #include <iostream>
0002 #include "TFile.h"
0003 #include "TSystem.h"
0004
0005 #include "DataFormats/FWLite/interface/Event.h"
0006 #include "DataFormats/FWLite/interface/Handle.h"
0007 #include "FWCore/FWLite/interface/FWLiteEnabler.h"
0008
0009 #include "DataFormats/FWLite/interface/Run.h"
0010 #include "DataFormats/FWLite/interface/LuminosityBlock.h"
0011 #include "DataFormats/Luminosity/interface/LumiSummary.h"
0012 #include "PhysicsTools/FWLite/interface/CommandLineParser.h"
0013
0014 int main(int argc, char** argv) {
0015
0016 gSystem->Load("libFWCoreFWLite");
0017 FWLiteEnabler::enable();
0018
0019
0020 optutl::CommandLineParser parser("Analyze FWLite Histograms");
0021
0022
0023 parser.parseArguments(argc, argv);
0024 std::vector<std::string> inputFiles_ = parser.stringVector("inputFiles");
0025
0026 for (unsigned int iFile = 0; iFile < inputFiles_.size(); ++iFile) {
0027
0028 TFile* inFile = TFile::Open(inputFiles_[iFile].c_str());
0029 if (inFile) {
0030 fwlite::Event ev(inFile);
0031 fwlite::Handle<LumiSummary> summary;
0032
0033 std::cout << "----------- Accessing by event ----------------" << std::endl;
0034
0035
0036
0037 for (ev.toBegin(); !ev.atEnd(); ++ev) {
0038
0039 std::cout << " Luminosity ID " << ev.getLuminosityBlock().id() << std::endl;
0040
0041 std::cout << " Run ID " << ev.getRun().id() << std::endl;
0042
0043 std::cout << "Run via lumi " << ev.getLuminosityBlock().getRun().id() << std::endl;
0044
0045
0046 summary.getByLabel(ev.getLuminosityBlock(), "lumiProducer");
0047 }
0048
0049 std::cout << "----------- Accessing by lumi block ----------------" << std::endl;
0050
0051 double lumi_tot = 0.0;
0052
0053 fwlite::LuminosityBlock ls(inFile);
0054 for (ls.toBegin(); !ls.atEnd(); ++ls) {
0055 summary.getByLabel(ls, "lumiProducer");
0056 std::cout << ls.id() << " Inst. Luminosity = " << summary->avgInsRecLumi() << std::endl;
0057
0058 std::cout << "Run from lumi " << ls.getRun().id() << std::endl;
0059
0060 lumi_tot += summary->avgInsRecLumi();
0061 }
0062
0063 std::cout << "----------------------------------------------------" << std::endl;
0064 std::cout << "Total luminosity from lumi sections = " << lumi_tot << std::endl;
0065 std::cout << "----------------------------------------------------" << std::endl;
0066
0067 std::cout << "----------- Accessing by run ----------------" << std::endl;
0068
0069
0070 fwlite::Run r(inFile);
0071 for (r.toBegin(); !r.atEnd(); ++r) {
0072 std::cout << "Run " << r.id() << std::endl;
0073 }
0074
0075 inFile->Close();
0076 }
0077 }
0078 return 0;
0079 }