CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions
FWLiteWithPythonConfig.cc File Reference
#include <TH1F.h>
#include <TROOT.h>
#include <TFile.h>
#include <TSystem.h>
#include "DataFormats/FWLite/interface/Event.h"
#include "DataFormats/Common/interface/Handle.h"
#include "FWCore/FWLite/interface/AutoLibraryLoader.h"
#include "DataFormats/FWLite/interface/InputSource.h"
#include "DataFormats/FWLite/interface/OutputFiles.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/PythonParameterSet/interface/MakeParameterSets.h"
#include "DataFormats/MuonReco/interface/Muon.h"
#include "DataFormats/PatCandidates/interface/Muon.h"
#include "PhysicsTools/FWLite/interface/TFileService.h"

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 20 of file FWLiteWithPythonConfig.cc.

References fwlite::Event::atEnd(), gather_cfg::cout, dir, AutoLibraryLoader::enable(), cmsRelvalreport::exit, fwlite::OutputFiles::file(), edm::ParameterSet::getParameter(), TFileDirectory::make(), scaleCards::mass, TFileDirectory::mkdir(), patZpeak::muons, LaserDQM_cfg::process, edm::readPSetsFrom(), TrackerOfflineValidation_Standalone_cff::TFileService, and fwlite::Event::toBegin().

21 {
22  // define what muon you are using; this is necessary as FWLite is not
23  // capable of reading edm::Views
24  using reco::Muon;
25 
26  // ----------------------------------------------------------------------
27  // First Part:
28  //
29  // * enable the AutoLibraryLoader
30  // * book the histograms of interest
31  // * open the input file
32  // ----------------------------------------------------------------------
33 
34  // load framework libraries
35  gSystem->Load( "libFWCoreFWLite" );
37 
38  // parse arguments
39  if ( argc < 2 ) {
40  std::cout << "Usage : " << argv[0] << " [parameters.py]" << std::endl;
41  return 0;
42  }
43 
44  if( !edm::readPSetsFrom(argv[1])->existsAs<edm::ParameterSet>("process") ){
45  std::cout << " ERROR: ParametersSet 'process' is missing in your configuration file" << std::endl; exit(0);
46  }
47  // get the python configuration
48  const edm::ParameterSet& process = edm::readPSetsFrom(argv[1])->getParameter<edm::ParameterSet>("process");
49  fwlite::InputSource inputHandler_(process); fwlite::OutputFiles outputHandler_(process);
50 
51 
52  // now get each parameter
53  const edm::ParameterSet& ana = process.getParameter<edm::ParameterSet>("muonAnalyzer");
54  edm::InputTag muons_( ana.getParameter<edm::InputTag>("muons") );
55 
56  // book a set of histograms
57  fwlite::TFileService fs = fwlite::TFileService(outputHandler_.file().c_str());
58  TFileDirectory dir = fs.mkdir("analyzeBasicPat");
59  TH1F* muonPt_ = dir.make<TH1F>("muonPt" , "pt" , 100, 0., 300.);
60  TH1F* muonEta_ = dir.make<TH1F>("muonEta" , "eta" , 100, -3., 3.);
61  TH1F* muonPhi_ = dir.make<TH1F>("muonPhi" , "phi" , 100, -5., 5.);
62  TH1F* mumuMass_= dir.make<TH1F>("mumuMass", "mass", 90, 30., 120.);
63 
64  // loop the events
65  int ievt=0;
66  int maxEvents_( inputHandler_.maxEvents() );
67  for(unsigned int iFile=0; iFile<inputHandler_.files().size(); ++iFile){
68  // open input file (can be located on castor)
69  TFile* inFile = TFile::Open(inputHandler_.files()[iFile].c_str());
70  if( inFile ){
71  // ----------------------------------------------------------------------
72  // Second Part:
73  //
74  // * loop the events in the input file
75  // * receive the collections of interest via fwlite::Handle
76  // * fill the histograms
77  // * after the loop close the input file
78  // ----------------------------------------------------------------------
79  fwlite::Event ev(inFile);
80  for(ev.toBegin(); !ev.atEnd(); ++ev, ++ievt){
81  edm::EventBase const & event = ev;
82  // break loop if maximal number of events is reached
83  if(maxEvents_>0 ? ievt+1>maxEvents_ : false) break;
84  // simple event counter
85  if(inputHandler_.reportAfter()!=0 ? (ievt>0 && ievt%inputHandler_.reportAfter()==0) : false)
86  std::cout << " processing event: " << ievt << std::endl;
87 
88  // Handle to the muon collection
90  event.getByLabel(muons_, muons);
91 
92  // loop muon collection and fill histograms
93  for(std::vector<Muon>::const_iterator mu1=muons->begin(); mu1!=muons->end(); ++mu1){
94  muonPt_ ->Fill( mu1->pt () );
95  muonEta_->Fill( mu1->eta() );
96  muonPhi_->Fill( mu1->phi() );
97  if( mu1->pt()>20 && fabs(mu1->eta())<2.1 ){
98  for(std::vector<Muon>::const_iterator mu2=muons->begin(); mu2!=muons->end(); ++mu2){
99  if(mu2>mu1){ // prevent double conting
100  if( mu1->charge()*mu2->charge()<0 ){ // check only muon pairs of unequal charge
101  if( mu2->pt()>20 && fabs(mu2->eta())<2.1 ){
102  mumuMass_->Fill( (mu1->p4()+mu2->p4()).mass() );
103  }
104  }
105  }
106  }
107  }
108  }
109  }
110  // close input file
111  inFile->Close();
112  }
113  // break loop if maximal number of events is reached:
114  // this has to be done twice to stop the file loop as well
115  if(maxEvents_>0 ? ievt+1>maxEvents_ : false) break;
116  }
117  return 0;
118 }
T getParameter(std::string const &) const
boost::shared_ptr< ParameterSet > readPSetsFrom(std::string const &fileOrString)
TFileDirectory mkdir(const std::string &dir, const std::string &descr="")
create a new subdirectory
tuple argc
Definition: dir2webdir.py:41
tuple muons
Definition: patZpeak.py:38
tuple mass
Definition: scaleCards.py:27
T * make() const
make new ROOT object
static void enable()
enable automatic library loading
tuple cout
Definition: gather_cfg.py:121
dbl *** dir
Definition: mlp_gen.cc:35
tuple process
Definition: LaserDQM_cfg.py:3