ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/src/FillerTracks.cc
Revision: 1.4
Committed: Thu Jul 3 07:56:14 2008 UTC (16 years, 10 months ago) by loizides
Content type: text/plain
Branch: MAIN
Changes since 1.3: +10 -9 lines
Log Message:
Coding Conventions

File Contents

# User Rev Content
1 loizides 1.4 // $Id: FillerTracks.cc,v 1.3 2008/07/02 13:30:09 bendavid Exp $
2 loizides 1.1
3     #include "MitProd/TreeFiller/interface/FillerTracks.h"
4     #include "FWCore/MessageLogger/interface/MessageLogger.h"
5     #include "DataFormats/Common/interface/Handle.h"
6     #include "DataFormats/TrackReco/interface/Track.h"
7     #include "DataFormats/TrackReco/interface/TrackFwd.h"
8     #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h"
9     #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticleFwd.h"
10     #include "DataFormats/RecoCandidate/interface/TrackAssociation.h"
11     #include "MitAna/DataTree/interface/Names.h"
12    
13     using namespace std;
14     using namespace edm;
15     using namespace mithep;
16    
17 loizides 1.4 //--------------------------------------------------------------------------------------------------
18 loizides 1.2 FillerTracks::FillerTracks(const ParameterSet &cfg, const char *name,
19     bool active, const SimParticleMap *sm) :
20     BaseFiller(cfg, name, active),
21 loizides 1.1 edmName_(Conf().getUntrackedParameter<string>("edmName","")),
22     mitName_(Conf().getUntrackedParameter<string>("mitName","")),
23     edmSimAssociationName_(Conf().getUntrackedParameter<string>("edmSimAssociationName","")),
24     simMap_(sm),
25     tracks_(new mithep::TrackArr),
26     trackMap_(new mithep::TrackMap)
27     {
28     // Constructor.
29     }
30    
31 loizides 1.4 //--------------------------------------------------------------------------------------------------
32 loizides 1.1 FillerTracks::~FillerTracks()
33     {
34     // Destructor.
35    
36     delete trackMap_;
37     }
38    
39 loizides 1.4 //--------------------------------------------------------------------------------------------------
40 loizides 1.1 void FillerTracks::BookDataBlock(TreeWriter &tws)
41     {
42     // Add tracks branch to tree.
43    
44     tws.AddBranch(mitName_.c_str(),&tracks_);
45     }
46    
47 loizides 1.4 //--------------------------------------------------------------------------------------------------
48 loizides 1.1 void FillerTracks::FillDataBlock(const edm::Event &event,
49     const edm::EventSetup &setup)
50     {
51     // Fill tracks from edm collection into our collection.
52    
53     tracks_->Reset();
54     trackMap_->Reset();
55    
56     // get the tracks collection
57     try {
58 bendavid 1.3 event.getByLabel(edm::InputTag(edmName_),trackProduct_);
59 loizides 1.1 } catch (cms::Exception& ex) {
60     edm::LogError("FillerTracks") << "Error! Cannot get collection with label "
61     << edmName_ << endl;
62     throw edm::Exception(edm::errors::Configuration, "FillerTracks:FillDataBlock()\n")
63     << "Error! Cannot get collection with label " << edmName_ << endl;
64     }
65    
66     trackMap_->SetEdmProductId(trackProduct_.id().id());
67     const reco::TrackCollection inTracks = *(trackProduct_.product());
68    
69     // if we have a Sim Particle association (for monte carlo), initialize the reco->sim mappings
70     reco::RecoToSimCollection simAssociation;
71     if (simMap_ && !edmSimAssociationName_.empty()) {
72     Handle<reco::RecoToSimCollection> simAssociationProduct;
73     try {
74 bendavid 1.3 event.getByLabel(edm::InputTag(edmSimAssociationName_), simAssociationProduct);
75 loizides 1.1 }
76     catch (cms::Exception& ex) {
77     edm::LogError("FillerTracks") << "Error! Cannot get collection with label "
78     << edmSimAssociationName_ << endl;
79     throw edm::Exception(edm::errors::Configuration, "FillerTracks:FillDataBlock()\n")
80     << "Error! Cannot get collection with label " << edmSimAssociationName_ << endl;
81     }
82     simAssociation = *(simAssociationProduct.product());
83     }
84    
85     // loop through all tracks
86     for (reco::TrackCollection::const_iterator inTrack = inTracks.begin();
87     inTrack != inTracks.end(); ++inTrack) {
88    
89     mithep::Track* outTrack = tracks_->Allocate();
90 loizides 1.4 new (outTrack) mithep::Track(inTrack->phi(),
91     inTrack->d0(),
92     inTrack->pt(),
93     inTrack->dz(),
94     inTrack->theta());
95 loizides 1.1
96     outTrack->SetErrors(inTrack->phiError(),
97     inTrack->d0Error(),
98     inTrack->ptError(),
99     inTrack->dzError(),
100     inTrack->thetaError());
101    
102     outTrack->SetCharge(inTrack->charge());
103    
104     // add reference between mithep and edm object
105     reco::TrackRef theRef(trackProduct_, inTrack-inTracks.begin());
106     trackMap_->Add(theRef, outTrack);
107    
108     if (simMap_ && !edmSimAssociationName_.empty()) {
109     reco::TrackBaseRef theBaseRef(theRef);
110     vector<pair<TrackingParticleRef, double> > simRefs;
111     Bool_t noSimParticle=0;
112     try {
113     simRefs = simAssociation[theBaseRef]; //try to get the sim references if existing
114     }
115     catch (edm::Exception& ex) {
116     noSimParticle=1;
117     }
118     if (!noSimParticle) { //loop through sim match candidates
119     for (vector<pair<TrackingParticleRef, double> >::const_iterator simRefPair=simRefs.begin();
120     simRefPair != simRefs.end(); ++simRefPair)
121    
122     if ( simRefPair->second > 0.5 ) // require more than 50% shared hits between reco and sim
123     outTrack->SetSimParticle(simMap_->GetMit(simRefPair->first)); //add reco->sim reference
124     }
125     }
126     }
127    
128     tracks_->Trim();
129     }