ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/src/FillerTracks.cc
Revision: 1.3
Committed: Wed Jul 2 13:30:09 2008 UTC (16 years, 10 months ago) by bendavid
Content type: text/plain
Branch: MAIN
Changes since 1.2: +3 -7 lines
Log Message:
cleaned up scheme for specifying edm names

File Contents

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