test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
playingWithJets.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 
3 // CMS includes
8 
11 
12 // Root includes
13 #include "TROOT.h"
14 
15 using namespace std;
16 
17 
19 // ///////////////////// //
20 // // Main Subroutine // //
21 // ///////////////////// //
23 
24 int main (int argc, char* argv[])
25 {
27  // ////////////////////////// //
28  // // Command Line Options // //
29  // ////////////////////////// //
31 
32  // Tell people what this analysis code does and setup default options.
33  optutl::CommandLineParser parser ("Playing with jets");
34 
36  // Change any defaults or add any new command //
37  // line options you would like here. //
39  // change default output filename
40  parser.stringValue ("outputFile") = "jetInfo.root";
41 
42  // Parse the command line arguments
43  parser.parseArguments (argc, argv);
44 
46  // //////////////////////////// //
47  // // Create Event Container // //
48  // //////////////////////////// //
50 
51  // This object 'event' is used both to get all information from the
52  // event as well as to store histograms, etc.
53  fwlite::EventContainer eventCont (parser);
54 
56  // ////////////////////////////////// //
57  // // Begin Run // //
58  // // (e.g., book histograms, etc) // //
59  // ////////////////////////////////// //
61 
62  // Setup a style
63  gROOT->SetStyle ("Plain");
64 
65  // Book those histograms!
66  eventCont.add( new TH1F( "jetpt", "Jet p_{T} using standard absolute p_{T} calibration", 100, 0, 60) );
67  eventCont.add( new TH1F( "jeteta", "Jet eta using standard absolute p_{T} calibration", 100, 0, 10) );
68  eventCont.add( new TH1F( "reljetpt", "Jet p_{T} using relative inter eta calibration", 100, 0, 60) );
69  eventCont.add( new TH1F( "reljeteta", "Jet eta using relative inter eta calibration", 100, 0, 10) );
70  eventCont.add( new TH1F( "phijet1jet2", "Phi between Jet 1 and Jet 2", 100, 0, 3.5) );
71  eventCont.add( new TH1F( "invarMass", "Invariant Mass of the 4-vector sum of Two Jets", 100, 0, 200) );
72 
74  // //////////////// //
75  // // Event Loop // //
76  // //////////////// //
78 
79  // create labels
80  edm::InputTag jetLabel ("selectedLayer1Jets");
81 
82  for (eventCont.toBegin(); ! eventCont.atEnd(); ++eventCont)
83  {
85  // Take What We Need From Event //
87 
88  // Get jets
90  eventCont.getByLabel (jetLabel, jetHandle);
91  assert ( jetHandle.isValid() );
92 
93  const vector< pat::Jet >::const_iterator kJetEnd = jetHandle->end();
94  for (vector< pat::Jet >::const_iterator jetIter = jetHandle->begin();
95  jetIter != kJetEnd;
96  ++jetIter)
97  {
98  // A few correctedJet options:
99  // ABS - absolute pt calibration (automatic)
100  // REL - relative inter eta calibration
101  // EMF - calibration as a function of the jet EMF
102  eventCont.hist("reljetpt") ->Fill( jetIter->correctedJet("REL").pt() );
103  eventCont.hist("reljeteta")->Fill( jetIter->correctedJet("REL").eta() );
104  eventCont.hist("jetpt") ->Fill( jetIter->correctedJet("ABS").pt() );
105  // Automatically ABS
106  eventCont.hist("jeteta") ->Fill( jetIter->eta() );
107  } // for jetIter
108 
109  // Do we have at least two jets?
110  if (jetHandle->size() < 2)
111  {
112  // Nothing to do here
113  continue;
114  }
115 
116  // Store invariant mass and delta phi between two leading jets.
117  eventCont.hist("invarMass")->Fill( (jetHandle->at(0).p4() + jetHandle->at(1).p4()).M() );
118  eventCont.hist("phijet1jet2")->Fill( deltaPhi( jetHandle->at(0).phi(), jetHandle->at(1).phi() ) );
119  } // for eventCont
120 
121 
123  // ////////////////// //
124  // // Clean Up Job // //
125  // ////////////////// //
127 
128  // Histograms will be automatically written to the root file
129  // specificed by command line options.
130 
131  // All done! Bye bye.
132  return 0;
133 }
std::string & stringValue(std::string key)
void parseArguments(int argc, char **argv, bool allowArgs=false)
int main(int argc, char **argv)
bool getByLabel(const std::type_info &iInfo, const char *iModuleLabel, const char *iProductInstanceLabel, const char *iProcessLabel, void *oData) const
void add(TH1 *histPtr, const std::string &directory="")
bool isValid() const
Definition: HandleBase.h:76
tuple argc
Definition: dir2webdir.py:38
const EventContainer & toBegin()
TH1 * hist(const std::string &name)