Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:23:22

0001 // -*- C++ -*-
0002 
0003 // CMS includes
0004 #include "FWCore/Utilities/interface/InputTag.h"
0005 #include "DataFormats/Common/interface/Handle.h"
0006 #include "DataFormats/PatCandidates/interface/Jet.h"
0007 #include "DataFormats/PatCandidates/interface/MET.h"
0008 #include "DataFormats/PatCandidates/interface/Photon.h"
0009 #include "DataFormats/PatCandidates/interface/Electron.h"
0010 #include "DataFormats/PatCandidates/interface/Tau.h"
0011 #include "DataFormats/TrackReco/interface/Track.h"
0012 
0013 #include "PhysicsTools/FWLite/interface/EventContainer.h"
0014 #include "PhysicsTools/FWLite/interface/CommandLineParser.h" 
0015 
0016 // Root includes
0017 #include "TROOT.h"
0018 
0019 using namespace std;
0020 
0021 
0022 ///////////////////////////
0023 // ///////////////////// //
0024 // // Main Subroutine // //
0025 // ///////////////////// //
0026 ///////////////////////////
0027 
0028 int main (int argc, char* argv[]) 
0029 {
0030    ////////////////////////////////
0031    // ////////////////////////// //
0032    // // Command Line Options // //
0033    // ////////////////////////// //
0034    ////////////////////////////////
0035 
0036    // Tell people what this analysis code does and setup default options.
0037    optutl::CommandLineParser parser ("Accessing many different PAT objects");
0038 
0039    ////////////////////////////////////////////////
0040    // Change any defaults or add any new command //
0041    //      line options you would like here.     //
0042    ////////////////////////////////////////////////
0043    parser.stringValue ("outputFile") = "mostPat"; // .root added automatically
0044 
0045    // Parse the command line arguments
0046    parser.parseArguments (argc, argv);
0047 
0048    //////////////////////////////////
0049    // //////////////////////////// //
0050    // // Create Event Container // //
0051    // //////////////////////////// //
0052    //////////////////////////////////
0053 
0054    // This object 'event' is used both to get all information from the
0055    // event as well as to store histograms, etc.
0056    fwlite::EventContainer eventCont (parser);
0057 
0058    ////////////////////////////////////////
0059    // ////////////////////////////////// //
0060    // //         Begin Run            // //
0061    // // (e.g., book histograms, etc) // //
0062    // ////////////////////////////////// //
0063    ////////////////////////////////////////
0064 
0065    // Setup a style
0066    gROOT->SetStyle ("Plain");
0067 
0068    // Book those histograms!
0069    eventCont.add( new TH1F( "jetpt",      "Jet Pt",      100, 0, 200) );
0070    eventCont.add( new TH1F( "jetnum",     "Jet Size",    100, 0, 50)  );
0071    eventCont.add( new TH1F( "metpt",      "MET Pt",      100, 0, 200) );
0072    eventCont.add( new TH1F( "photonpt",   "Photon Pt",   100, 0, 200) );
0073    eventCont.add( new TH1F( "trackpt",    "Track Pt",    100, 0, 200) );
0074    eventCont.add( new TH1F( "electronpt", "Electron Pt", 100, 0, 200) );
0075    eventCont.add( new TH1F( "taupt",      "Tau Pt",      100, 0, 200) );   
0076 
0077    //////////////////////
0078    // //////////////// //
0079    // // Event Loop // //
0080    // //////////////// //
0081    //////////////////////
0082    edm::InputTag jetLabel      ("selectedLayer1Jets");
0083    edm::InputTag metLabel      ("selectedLayer1METs");
0084    edm::InputTag photonLabel   ("selectedLayer1Photons");
0085    edm::InputTag trackLabel    ("generalTracks");
0086    edm::InputTag electronLabel ("selectedLayer1Electrons");
0087    edm::InputTag tauLabel      ("selectedLayer1Taus");
0088 
0089    for (eventCont.toBegin(); ! eventCont.atEnd(); ++eventCont) 
0090    {
0091       //////////////////////////////////
0092       // Take What We Need From Event //
0093       //////////////////////////////////
0094 
0095       // Get jets, METs, photons, tracks, electrons, and taus
0096       edm::Handle< vector<pat::Jet> > h_jet;
0097       eventCont.getByLabel (jetLabel, h_jet);
0098       assert( h_jet.isValid() );
0099 
0100       edm::Handle< vector<pat::MET> > h_met;
0101       eventCont.getByLabel (metLabel, h_met);
0102       assert( h_met.isValid() );
0103 
0104       edm::Handle< vector<pat::Photon> > h_photon;
0105       eventCont.getByLabel (photonLabel, h_photon);
0106       assert( h_photon.isValid() );
0107 
0108       edm::Handle< vector<reco::Track> > h_track;
0109       eventCont.getByLabel (trackLabel, h_track);
0110       assert( h_track.isValid() );
0111 
0112       edm::Handle< vector<pat::Electron> > h_electron;
0113       eventCont.getByLabel (electronLabel, h_electron);
0114       assert( h_electron.isValid() );
0115 
0116       edm::Handle< vector<pat::Tau> > h_tau;
0117       eventCont.getByLabel (tauLabel, h_tau);
0118       assert( h_tau.isValid() );
0119 
0120       // Fill, baby, fill!
0121  
0122       eventCont.hist("jetnum")->Fill( h_jet->size() );    
0123      
0124       const vector< pat::Jet >::const_iterator kJetEnd = h_jet->end();
0125       for (vector< pat::Jet >::const_iterator jetIter = h_jet->begin();
0126            jetIter != kJetEnd;
0127            ++jetIter) 
0128       {
0129          eventCont.hist("jetpt")->Fill( jetIter->pt() );  
0130       }
0131 
0132       const vector< pat::MET >::const_iterator kMetEnd = h_met->end();
0133       for (vector< pat::MET >::const_iterator metIter = h_met->begin();
0134            metIter != kMetEnd;
0135            ++metIter) 
0136       {
0137          eventCont.hist("metpt")->Fill( metIter->pt() );
0138       }
0139 
0140       const vector< pat::Photon >::const_iterator kPhotonEnd = h_photon->end();
0141       for (vector< pat::Photon >::const_iterator photonIter = h_photon->begin();
0142            photonIter != kPhotonEnd;
0143            ++photonIter) 
0144       {
0145          eventCont.hist("photonpt")->Fill( photonIter->pt() );
0146       }
0147 
0148       const vector< reco::Track >::const_iterator kTrackEnd = h_track->end();
0149       for (vector< reco::Track >::const_iterator trackIter = h_track->begin();
0150            trackIter != kTrackEnd;
0151            ++trackIter) 
0152       {
0153          eventCont.hist("trackpt")->Fill( trackIter->pt() );
0154       }
0155 
0156       const vector< pat::Electron >::const_iterator kElectronEnd = h_electron->end();
0157       for (vector< pat::Electron >::const_iterator electronIter = h_electron->begin();
0158            electronIter != kElectronEnd;
0159            ++electronIter) 
0160       {
0161          eventCont.hist("electronpt")->Fill( electronIter->pt() );
0162       }
0163 
0164       const vector< pat::Tau >::const_iterator kTauEnd = h_tau->end();
0165       for (vector< pat::Tau >::const_iterator tauIter = h_tau->begin();
0166            tauIter != kTauEnd;
0167            ++tauIter) 
0168       {
0169          eventCont.hist ("taupt")->Fill (tauIter->pt() );
0170       }
0171    } // for eventCont
0172 
0173       
0174    ////////////////////////
0175    // ////////////////// //
0176    // // Clean Up Job // //
0177    // ////////////////// //
0178    ////////////////////////
0179 
0180    // Histograms will be automatically written to the root file
0181    // specificed by command line options.
0182 
0183    // All done!  Bye bye.
0184    return 0;
0185 }