Back to home page

Project CMSSW displayed by LXR

 
 

    


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   // load framework libraries
0016   gSystem->Load("libFWCoreFWLite");
0017   FWLiteEnabler::enable();
0018 
0019   // initialize command line parser
0020   optutl::CommandLineParser parser("Analyze FWLite Histograms");
0021 
0022   // parse arguments
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     // open input file (can be located on castor)
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       // get run and luminosity blocks from events as well as associated
0036       // products. (This works for both ChainEvent and MultiChainEvent.)
0037       for (ev.toBegin(); !ev.atEnd(); ++ev) {
0038         // get the Luminosity block ID from the event
0039         std::cout << " Luminosity ID " << ev.getLuminosityBlock().id() << std::endl;
0040         // get the Run ID from the event
0041         std::cout << " Run ID " << ev.getRun().id() << std::endl;
0042         // get the Run ID from the luminosity block you got from the event
0043         std::cout << "Run via lumi " << ev.getLuminosityBlock().getRun().id() << std::endl;
0044         // get the integrated luminosity (or any luminosity product) from
0045         // the event
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       // loop over luminosity blocks (in analogy to looping over events)
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         // get the associated run from this lumi
0058         std::cout << "Run from lumi " << ls.getRun().id() << std::endl;
0059         // add up the luminosity by lumi block
0060         lumi_tot += summary->avgInsRecLumi();
0061       }
0062       // print the result
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       // do the same for runs
0070       fwlite::Run r(inFile);
0071       for (r.toBegin(); !r.atEnd(); ++r) {
0072         std::cout << "Run " << r.id() << std::endl;
0073       }
0074       // close input file
0075       inFile->Close();
0076     }
0077   }
0078   return 0;
0079 }