ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/src/FillerTracks.cc
Revision: 1.5
Committed: Mon Jul 7 16:14:01 2008 UTC (16 years, 10 months ago) by loizides
Content type: text/plain
Branch: MAIN
Changes since 1.4: +6 -5 lines
Log Message:
coding conventions

File Contents

# User Rev Content
1 loizides 1.5 // $Id: FillerTracks.cc,v 1.4 2008/07/03 07:56:14 loizides 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 loizides 1.5 delete tracks_;
37 loizides 1.1 delete trackMap_;
38     }
39    
40 loizides 1.4 //--------------------------------------------------------------------------------------------------
41 loizides 1.1 void FillerTracks::BookDataBlock(TreeWriter &tws)
42     {
43     // Add tracks branch to tree.
44    
45     tws.AddBranch(mitName_.c_str(),&tracks_);
46     }
47    
48 loizides 1.4 //--------------------------------------------------------------------------------------------------
49 loizides 1.1 void FillerTracks::FillDataBlock(const edm::Event &event,
50     const edm::EventSetup &setup)
51     {
52     // Fill tracks from edm collection into our collection.
53    
54     tracks_->Reset();
55     trackMap_->Reset();
56    
57     // get the tracks collection
58     try {
59 bendavid 1.3 event.getByLabel(edm::InputTag(edmName_),trackProduct_);
60 loizides 1.5 } catch (cms::Exception &ex) {
61 loizides 1.1 edm::LogError("FillerTracks") << "Error! Cannot get collection with label "
62     << edmName_ << endl;
63     throw edm::Exception(edm::errors::Configuration, "FillerTracks:FillDataBlock()\n")
64     << "Error! Cannot get collection with label " << edmName_ << endl;
65     }
66    
67     trackMap_->SetEdmProductId(trackProduct_.id().id());
68     const reco::TrackCollection inTracks = *(trackProduct_.product());
69    
70     // if we have a Sim Particle association (for monte carlo), initialize the reco->sim mappings
71     reco::RecoToSimCollection simAssociation;
72     if (simMap_ && !edmSimAssociationName_.empty()) {
73     Handle<reco::RecoToSimCollection> simAssociationProduct;
74     try {
75 bendavid 1.3 event.getByLabel(edm::InputTag(edmSimAssociationName_), simAssociationProduct);
76 loizides 1.1 }
77 loizides 1.5 catch (cms::Exception &ex) {
78 loizides 1.1 edm::LogError("FillerTracks") << "Error! Cannot get collection with label "
79     << edmSimAssociationName_ << endl;
80     throw edm::Exception(edm::errors::Configuration, "FillerTracks:FillDataBlock()\n")
81     << "Error! Cannot get collection with label " << edmSimAssociationName_ << endl;
82     }
83     simAssociation = *(simAssociationProduct.product());
84     }
85    
86     // loop through all tracks
87     for (reco::TrackCollection::const_iterator inTrack = inTracks.begin();
88     inTrack != inTracks.end(); ++inTrack) {
89    
90 loizides 1.5 mithep::Track *outTrack = tracks_->Allocate();
91 loizides 1.4 new (outTrack) mithep::Track(inTrack->phi(),
92     inTrack->d0(),
93     inTrack->pt(),
94     inTrack->dz(),
95     inTrack->theta());
96 loizides 1.1
97     outTrack->SetErrors(inTrack->phiError(),
98     inTrack->d0Error(),
99     inTrack->ptError(),
100     inTrack->dzError(),
101     inTrack->thetaError());
102    
103     outTrack->SetCharge(inTrack->charge());
104    
105     // add reference between mithep and edm object
106     reco::TrackRef theRef(trackProduct_, inTrack-inTracks.begin());
107     trackMap_->Add(theRef, outTrack);
108    
109     if (simMap_ && !edmSimAssociationName_.empty()) {
110     reco::TrackBaseRef theBaseRef(theRef);
111     vector<pair<TrackingParticleRef, double> > simRefs;
112     Bool_t noSimParticle=0;
113     try {
114     simRefs = simAssociation[theBaseRef]; //try to get the sim references if existing
115     }
116 loizides 1.5 catch (edm::Exception &ex) {
117 loizides 1.1 noSimParticle=1;
118     }
119     if (!noSimParticle) { //loop through sim match candidates
120     for (vector<pair<TrackingParticleRef, double> >::const_iterator simRefPair=simRefs.begin();
121     simRefPair != simRefs.end(); ++simRefPair)
122    
123     if ( simRefPair->second > 0.5 ) // require more than 50% shared hits between reco and sim
124     outTrack->SetSimParticle(simMap_->GetMit(simRefPair->first)); //add reco->sim reference
125     }
126     }
127     }
128    
129     tracks_->Trim();
130     }