CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_2_9_HLT1_bphpatch4/src/PhysicsTools/FWLite/bin/FWLiteLumiAccess.cc

Go to the documentation of this file.
00001 #include <TFile.h>
00002 #include <TSystem.h>
00003 
00004 #include "DataFormats/FWLite/interface/Event.h"
00005 #include "DataFormats/FWLite/interface/Handle.h"
00006 #include "FWCore/FWLite/interface/AutoLibraryLoader.h"
00007 
00008 #include "DataFormats/FWLite/interface/Run.h"
00009 #include "DataFormats/FWLite/interface/LuminosityBlock.h"
00010 #include "DataFormats/Luminosity/interface/LumiSummary.h"
00011 #include "PhysicsTools/FWLite/interface/CommandLineParser.h"
00012 
00013 
00014 int main(int argc, char ** argv){
00015   // load framework libraries
00016   gSystem->Load( "libFWCoreFWLite" );
00017   AutoLibraryLoader::enable();
00018 
00019   // initialize command line parser
00020   optutl::CommandLineParser parser ("Analyze FWLite Histograms");
00021 
00022   // parse arguments
00023   parser.parseArguments (argc, argv);
00024   std::vector<std::string> inputFiles_ = parser.stringVector("inputFiles");
00025   
00026   for(unsigned int iFile=0; iFile<inputFiles_.size(); ++iFile){
00027     // open input file (can be located on castor)
00028     TFile* inFile = TFile::Open(inputFiles_[iFile].c_str());
00029     if( inFile ){
00030       fwlite::Event ev(inFile);
00031       fwlite::Handle<LumiSummary> summary;
00032       
00033       std::cout << "----------- Accessing by event ----------------" << std::endl;
00034       
00035       // get run and luminosity blocks from events as well as associated 
00036       // products. (This works for both ChainEvent and MultiChainEvent.)
00037       for(ev.toBegin(); !ev.atEnd(); ++ev){
00038         // get the Luminosity block ID from the event
00039         std::cout << " Luminosity ID " << ev.getLuminosityBlock().id() << std::endl;
00040         // get the Run ID from the event
00041         std::cout <<" Run ID " << ev.getRun().id()<< std::endl;
00042         // get the Run ID from the luminosity block you got from the event
00043         std::cout << "Run via lumi " << ev.getLuminosityBlock().getRun().id() << std::endl;
00044         // get the integrated luminosity (or any luminosity product) from 
00045         // the event
00046         summary.getByLabel(ev.getLuminosityBlock(),"lumiProducer");
00047       }
00048       
00049       std::cout << "----------- Accessing by lumi block ----------------" << std::endl;
00050       
00051       double lumi_tot = 0.0;
00052       // loop over luminosity blocks (in analogy to looping over events)
00053       fwlite::LuminosityBlock ls(inFile);
00054       for(ls.toBegin(); !ls.atEnd(); ++ls){
00055         summary.getByLabel(ls,"lumiProducer");
00056         std::cout  << ls.id() << " Inst.  Luminosity = " << summary->avgInsRecLumi() << std::endl;
00057         // get the associated run from this lumi
00058         std::cout << "Run from lumi " << ls.getRun().id() << std::endl;
00059         // add up the luminosity by lumi block
00060         lumi_tot += summary->avgInsRecLumi();
00061       }
00062       // print the result
00063       std::cout << "----------------------------------------------------" << std::endl;
00064       std::cout << "Total luminosity from lumi sections = " << lumi_tot   << std::endl;
00065       std::cout << "----------------------------------------------------" << std::endl;
00066       
00067       std::cout << "----------- Accessing by run ----------------" << std::endl;
00068       
00069       // do the same for runs
00070       fwlite::Run r(inFile);
00071       for(r.toBegin(); !r.atEnd(); ++r) {
00072         std::cout << "Run " << r.id() << std::endl;
00073       }
00074       // close input file
00075       inFile->Close();
00076     }
00077   }
00078   return 0;
00079 }