CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions
PatMuonEDMAnalyzer.cc File Reference
#include <memory>
#include <string>
#include <vector>
#include <sstream>
#include <fstream>
#include <iostream>
#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/FWLiteEnabler.h"
#include "DataFormats/MuonReco/interface/Muon.h"
#include "DataFormats/PatCandidates/interface/Muon.h"
#include "PhysicsTools/FWLite/interface/TFileService.h"
#include "PhysicsTools/FWLite/interface/CommandLineParser.h"

Go to the source code of this file.

Functions

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

Function Documentation

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

CALO JETS


PF JETS

Definition at line 22 of file PatMuonEDMAnalyzer.cc.

References fwlite::Event::atEnd(), gather_cfg::cout, dir, FWLiteEnabler::enable(), ev, optutl::VariableMapCont::integerValue(), TFileDirectory::make(), TFileDirectory::mkdir(), PatBasicFWLiteAnalyzer::muonEta, PatBasicFWLiteAnalyzer::muonPhi, PatBasicFWLiteAnalyzer::muonPt, optutl::CommandLineParser::parseArguments(), geometryXMLtoCSV::parser, AlCaHLTBitMon_QueryRunRegistry::string, optutl::VariableMapCont::stringValue(), optutl::VariableMapCont::stringVector(), TrackerOfflineValidation_Standalone_cff::TFileService, and fwlite::Event::toBegin().

23 {
24  // ----------------------------------------------------------------------
25  // First Part:
26  //
27  // * enable FWLite
28  // * book the histograms of interest
29  // * open the input file
30  // ----------------------------------------------------------------------
31 
32  // load framework libraries
33  gSystem->Load( "libFWCoreFWLite" );
35 
36  // initialize command line parser
37  optutl::CommandLineParser parser ("Analyze FWLite Histograms");
38 
39  // set defaults
40  parser.integerValue ("maxEvents" ) = 1000;
41  parser.integerValue ("outputEvery") = 10;
42  parser.stringValue ("outputFile" ) = "analyzeEdmTuple.root";
43 
44  // parse arguments
45  parser.parseArguments (argc, argv);
46  int maxEvents_ = parser.integerValue("maxEvents");
47  unsigned int outputEvery_ = parser.integerValue("outputEvery");
48  std::string outputFile_ = parser.stringValue("outputFile");
49  std::vector<std::string> inputFiles_ = parser.stringVector("inputFiles");
50 
51  // book a set of histograms
52  fwlite::TFileService fs = fwlite::TFileService(outputFile_.c_str());
53  TFileDirectory dir = fs.mkdir("analyzePatMuon");
54  TH1F* muonPt_ = dir.make<TH1F>("muonPt" , "pt" , 100, 0., 300.);
55  TH1F* muonEta_ = dir.make<TH1F>("muonEta" , "eta" , 100, -3., 3.);
56  TH1F* muonPhi_ = dir.make<TH1F>("muonPhi" , "phi" , 100, -5., 5.);
57 
58  // loop the events
59  int ievt=0;
60  for(unsigned int iFile=0; iFile<inputFiles_.size(); ++iFile){
61  // open input file (can be located on castor)
62  TFile* inFile = TFile::Open(inputFiles_[iFile].c_str());
63  if( inFile ){
64  // ----------------------------------------------------------------------
65  // Second Part:
66  //
67  // * loop the events in the input file
68  // * receive the collections of interest via fwlite::Handle
69  // * fill the histograms
70  // * after the loop close the input file
71  // ----------------------------------------------------------------------
72  fwlite::Event ev(inFile);
73  for(ev.toBegin(); !ev.atEnd(); ++ev, ++ievt){
74  edm::EventBase const & event = ev;
75  // break loop if maximal number of events is reached
76  if(maxEvents_>0 ? ievt+1>maxEvents_ : false) break;
77  // simple event counter
78  if(outputEvery_!=0 ? (ievt>0 && ievt%outputEvery_==0) : false)
79  std::cout << " processing event: " << ievt << std::endl;
80 
81  // Handle to the muon pt
83  event.getByLabel(std::string("patMuonAnalyzer:pt"), muonPt);
84  // loop muon collection and fill histograms
85  for(std::vector<float>::const_iterator mu1=muonPt->begin(); mu1!=muonPt->end(); ++mu1){
86  muonPt_ ->Fill( *mu1 );
87  }
88  // Handle to the muon eta
90  event.getByLabel(std::string("patMuonAnalyzer:eta"), muonEta);
91  for(std::vector<float>::const_iterator mu1=muonEta->begin(); mu1!=muonEta->end(); ++mu1){
92  muonEta_ ->Fill( *mu1 );
93  }
94  // Handle to the muon phi
96  event.getByLabel(std::string("patMuonAnalyzer:phi"), muonPhi);
97  for(std::vector<float>::const_iterator mu1=muonPhi->begin(); mu1!=muonPhi->end(); ++mu1){
98  muonPhi_ ->Fill( *mu1 );
99  }
100  }
101  // close input file
102  inFile->Close();
103  }
104  // break loop if maximal number of events is reached:
105  // this has to be done twice to stop the file loop as well
106  if(maxEvents_>0 ? ievt+1>maxEvents_ : false) break;
107  }
108  return 0;
109 }
bool ev
static void enable()
enable automatic library loading
T * make(const Args &...args) const
make new ROOT object
TFileDirectory mkdir(const std::string &dir, const std::string &descr="")
create a new subdirectory
tuple argc
Definition: dir2webdir.py:38
tuple cout
Definition: gather_cfg.py:121
dbl *** dir
Definition: mlp_gen.cc:35