ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/src/FillTracks.cc
Revision: 1.8
Committed: Fri Jun 20 17:52:57 2008 UTC (16 years, 10 months ago) by loizides
Content type: text/plain
Branch: MAIN
Changes since 1.7: +3 -1 lines
Log Message:
First proof-of-principle implementation of MetaInfo.

File Contents

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