CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/PhysicsTools/ParallelAnalysis/src/TrackAnalysisAlgorithm.cc

Go to the documentation of this file.
00001 #include "PhysicsTools/ParallelAnalysis/interface/TrackAnalysisAlgorithm.h"
00002 #include "DataFormats/TrackReco/interface/Track.h"
00003 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00004 #include "DataFormats/Common/interface/Handle.h"
00005 #include "FWCore/Framework/interface/Event.h"
00006 #include <TCanvas.h>
00007 #include <TList.h>
00008 #include <TH1.h>
00009 #include <iostream>
00010 using namespace examples;
00011 using namespace std;
00012 using namespace edm;
00013 using namespace reco;
00014 
00015 const char * TrackAnalysisAlgorithm::kPt = "pt";
00016 const char * TrackAnalysisAlgorithm::kEta = "eta";
00017 
00018 TrackAnalysisAlgorithm::TrackAnalysisAlgorithm( const TList *, TList& out ) {
00019   cout << ">> booking histograms" << endl;
00020   out.Add( h_pt  = new TH1F( kPt , "pt"  , 100,  0, 20 ) );
00021   out.Add( h_eta = new TH1F( kEta, "#eta", 100, -3,    3 ) );
00022 }
00023 
00024 void TrackAnalysisAlgorithm::process( const Event & event ) {
00025   cout << ">> processing event " << endl;
00026   Handle<TrackCollection> tracks;
00027   event.getByLabel( "ctfWithMaterialTracks", tracks );
00028   
00029   cout << ">> tracks found:" << tracks->size() << endl;
00030   for ( size_t i = 0; i < tracks->size(); ++i ) {
00031     const Track & track = ( * tracks )[ i ];
00032     h_pt ->Fill( track.pt() );
00033     h_eta->Fill( track.eta() );
00034     cout << ">> pt, eta:  " << track.pt() << ", " << track.eta() << endl;
00035   }
00036 }
00037 
00038 void TrackAnalysisAlgorithm::postProcess( TList & ) {
00039   cout << ">> nothing to be done in post-processing" << endl;
00040 }
00041 
00042 void TrackAnalysisAlgorithm::terminate( TList & out ) {
00043   cout << ">> terminating" << endl;
00044   TCanvas canvas;
00045   draw( out, canvas,  kPt );
00046   draw( out, canvas, kEta );
00047 }
00048 
00049 void TrackAnalysisAlgorithm::draw( const TList & out, TCanvas & canvas, const char * k ) {
00050   TObject * hist = out.FindObject( k );
00051   if( 0 != hist ) {
00052     hist->Draw();
00053     canvas.SaveAs( ( string( k ) + ".jpg" ).c_str() );
00054   } else {
00055     cerr <<">> no '" << k << "' histogram" << endl;
00056   }
00057 }