ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/src/FillTracks.cc
Revision: 1.5
Committed: Wed Jun 18 13:23:22 2008 UTC (16 years, 10 months ago) by paus
Content type: text/plain
Branch: MAIN
Changes since 1.4: +5 -4 lines
Log Message:
Basic structure of Filling framework.

File Contents

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