CMS 3D CMS Logo

TrackAnalysisAlgorithm.cc
Go to the documentation of this file.
6 #include <TCanvas.h>
7 #include <TList.h>
8 #include <TH1.h>
9 #include <iostream>
10 using namespace examples;
11 using namespace std;
12 using namespace edm;
13 using namespace reco;
14 
15 const char * TrackAnalysisAlgorithm::kPt = "pt";
16 const char * TrackAnalysisAlgorithm::kEta = "eta";
17 
19  cout << ">> booking histograms" << endl;
20  out.Add( h_pt = new TH1F( kPt , "pt" , 100, 0, 20 ) );
21  out.Add( h_eta = new TH1F( kEta, "#eta", 100, -3, 3 ) );
22 }
23 
25  cout << ">> processing event " << endl;
27  event.getByLabel( "ctfWithMaterialTracks", tracks );
28 
29  cout << ">> tracks found:" << tracks->size() << endl;
30  for ( size_t i = 0; i < tracks->size(); ++i ) {
31  const Track & track = ( * tracks )[ i ];
32  h_pt ->Fill( track.pt() );
33  h_eta->Fill( track.eta() );
34  cout << ">> pt, eta: " << track.pt() << ", " << track.eta() << endl;
35  }
36 }
37 
39  cout << ">> nothing to be done in post-processing" << endl;
40 }
41 
43  cout << ">> terminating" << endl;
44  TCanvas canvas;
45  draw( out, canvas, kPt );
46  draw( out, canvas, kEta );
47 }
48 
49 void TrackAnalysisAlgorithm::draw( const TList & out, TCanvas & canvas, const char * k ) {
50  TObject * hist = out.FindObject( k );
51  if( nullptr != hist ) {
52  hist->Draw();
53  canvas.SaveAs( ( string( k ) + ".jpg" ).c_str() );
54  } else {
55  cerr <<">> no '" << k << "' histogram" << endl;
56  }
57 }
example_track example_track const char *const kPt
Definition: TSelector.cc:34
def draw(name, histos, styles=_defaultStyles, legendLabels=[], kwargs)
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:684
void process(const edm::Event &)
process one event
static void draw(const TList &, TCanvas &, const char *)
draw an histogram
double pt() const
track transverse momentum
Definition: TrackBase.h:654
static void terminate(TList &)
terminate processing
int k[5][pyjets_maxn]
static const char * kPt
histogram names
TrackAnalysisAlgorithm(const TList *, TList &)
constructor
fixed size matrix
HLT enums.
void postProcess(TList &)
post process
def canvas(sub, attr)
Definition: svgfig.py:481
Definition: event.py:1