ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/src/FillTracks.cc
Revision: 1.6
Committed: Wed Jun 18 14:10:45 2008 UTC (16 years, 10 months ago) by loizides
Content type: text/plain
Branch: MAIN
Changes since 1.5: +2 -3 lines
Log Message:
Use Array

File Contents

# User Rev Content
1 loizides 1.6 // $Id: FillTracks.cc,v 1.5 2008/06/18 13:23:22 paus Exp $
2 bendavid 1.1
3     #include "MitProd/TreeFiller/interface/FillTracks.h"
4     #include "FWCore/MessageLogger/interface/MessageLogger.h"
5     #include "FWCore/Framework/interface/ESHandle.h"
6     #include "DataFormats/Common/interface/Handle.h"
7     #include "FWCore/ServiceRegistry/interface/Service.h"
8     #include "DataFormats/TrackReco/interface/Track.h"
9     #include "DataFormats/TrackReco/interface/TrackFwd.h"
10     #include "MitAna/DataTree/interface/Names.h"
11    
12     using namespace std;
13     using namespace edm;
14     using namespace mithep;
15    
16     //-------------------------------------------------------------------------------------------------
17 loizides 1.3 FillTracks::FillTracks(const edm::ParameterSet &iConfig) :
18 loizides 1.6 tracks_(new mithep::Array<mithep::Track>()),
19 paus 1.5 trackSource_(iConfig.getUntrackedParameter<string>("trackSource", "generalTracks")),
20 loizides 1.3 trackBranch_(iConfig.getUntrackedParameter<string>("trackBrname", Names::gkTrackBrn))
21 bendavid 1.1 {
22     }
23    
24     //-------------------------------------------------------------------------------------------------
25     FillTracks::~FillTracks()
26     {
27     }
28    
29     //-------------------------------------------------------------------------------------------------
30     void FillTracks::analyze(const edm::Event &theEvent,
31 paus 1.2 const edm::EventSetup &iSetup)
32 bendavid 1.1 {
33     tracks_->Reset();
34    
35     Handle<reco::TrackCollection> theTrackProduct;
36     try {
37     theEvent.getByLabel(trackSource_, theTrackProduct);
38     } catch (cms::Exception& ex) {
39     edm::LogError("FillTracks") << "Error! Can not get collection with label "
40     << trackSource_ << endl;
41     throw edm::Exception(edm::errors::Configuration, "FillTracks:analyze()\n")
42     << "Error! Can not get collection with label " << trackSource_ << endl;
43     }
44    
45     const reco::TrackCollection Tracks = *(theTrackProduct.product());
46    
47     int nTracks = 0;
48 loizides 1.3 for (reco::TrackCollection::const_iterator inTrack = Tracks.begin();
49     inTrack != Tracks.end(); ++inTrack) {
50 bendavid 1.1
51 paus 1.2 mithep::Track* outTrack = new mithep::Track(inTrack->phi(),inTrack->d0(),inTrack->pt(),
52     inTrack->dz(),inTrack->theta());
53 bendavid 1.1
54 loizides 1.3 outTrack->SetErrors(inTrack->phiError(),
55     inTrack->d0Error(),
56     inTrack->ptError(),
57     inTrack->dzError(),
58     inTrack->thetaError());
59 bendavid 1.1 outTrack->SetCharge(inTrack->charge());
60    
61 loizides 1.4 tracks_->AddCopy(outTrack);
62 bendavid 1.1 nTracks++;
63     }
64 loizides 1.3 tracks_->Trim();
65 bendavid 1.1 }
66    
67     //-------------------------------------------------------------------------------------------------
68     void FillTracks::beginJob(edm::EventSetup const &iEvent)
69     {
70     Service<TreeService> ts;
71     TreeWriter *tws = ts->get();
72 paus 1.5 if (! tws) {
73 bendavid 1.1 throw edm::Exception(edm::errors::Configuration, "FillTracks::beginJob()\n")
74     << "Could not get pointer to Tree with name " << tws->GetName() << "\n";
75     return;
76     }
77    
78     tws->AddBranch(trackBranch_.c_str(),&tracks_);
79     }
80    
81     //-------------------------------------------------------------------------------------------------
82     void FillTracks::endJob()
83     {
84     edm::LogInfo("FillMuons::endJob") << "Ending Job" << endl;
85     }