Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:33:05

0001 #include <memory>
0002 #include <string>
0003 #include <vector>
0004 #include <sstream>
0005 #include <fstream>
0006 #include <iostream>
0007 
0008 #include <TH1F.h>
0009 #include <TROOT.h>
0010 #include <TFile.h>
0011 #include <TSystem.h>
0012 
0013 #include "DataFormats/FWLite/interface/Handle.h"
0014 #include "DataFormats/PatCandidates/interface/Muon.h"
0015 #include "DataFormats/PatCandidates/interface/CompositeCandidate.h"
0016 #include "FWCore/FWLite/interface/FWLiteEnabler.h"
0017 
0018 using namespace std;
0019 
0020 int main(int argc, char* argv[]) 
0021 {
0022   // ----------------------------------------------------------------------
0023   // First Part: 
0024   //
0025   //  * enable FWLite 
0026   //  * book the histograms of interest 
0027   //  * open the input file
0028   // ----------------------------------------------------------------------
0029 
0030   // load framework libraries
0031   gSystem->Load( "libFWCoreFWLite" );
0032   FWLiteEnabler::enable();
0033     
0034   // open input file (can be located on castor)
0035   TFile* inFile = TFile::Open( "file:jpsi.root" );
0036 
0037   // ----------------------------------------------------------------------
0038   // Second Part: 
0039   //
0040   //  * loop the events in the input file 
0041   //  * receive the collections of interest via fwlite::Handle
0042   //  * fill the histograms
0043   //  * after the loop close the input file
0044   // ----------------------------------------------------------------------
0045 
0046   // loop the events
0047   unsigned int iEvent=0;
0048   fwlite::Event event(inFile);
0049   for(event.toBegin(); !event.atEnd(); ++event, ++iEvent){
0050     // break loop after end of file is reached 
0051     // or after 1000 events have been processed
0052     if( iEvent==1000 ) break;
0053     
0054     // simple event counter
0055     if(iEvent>0 && iEvent%1==0){
0056       std::cout << "  processing event: " << iEvent << std::endl;
0057     }
0058 
0059     // fwlite::Handle to to jpsi collection
0060     fwlite::Handle<std::vector<pat::CompositeCandidate> > jpsis;
0061     jpsis.getByLabel(event, "patJPsiCandidates");
0062     
0063     // loop jpsi collection and fill histograms
0064     for(unsigned i=0; i<jpsis->size(); ++i){
0065       cout << "jpsi " << i << ", mass = " << jpsis->at(i).mass() << ", dR = " << jpsis->at(i).userFloat("dR") << endl;
0066     }
0067   }  
0068   // close input file
0069   inFile->Close();
0070   
0071   // that's it!
0072   return 0;
0073 }