ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/src/FillerTracks.cc
Revision: 1.11
Committed: Tue Jul 29 22:54:37 2008 UTC (16 years, 9 months ago) by bendavid
Content type: text/plain
Branch: MAIN
Changes since 1.10: +2 -5 lines
Log Message:
Added full TRef based linking to Decay and Stable Particle Fillers

File Contents

# User Rev Content
1 bendavid 1.11 // $Id: FillerTracks.cc,v 1.10 2008/07/28 23:13:44 paus Exp $
2 loizides 1.1
3 bendavid 1.11 #include "MitProd/TreeFiller/interface/FillerTracks.h"
4 loizides 1.1 #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 loizides 1.7 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 loizides 1.7 tracks_(new mithep::TrackArr(250)),
26 loizides 1.1 trackMap_(new mithep::TrackMap)
27     {
28 paus 1.10 // Constructor
29 loizides 1.1 }
30    
31 loizides 1.4 //--------------------------------------------------------------------------------------------------
32 loizides 1.1 FillerTracks::~FillerTracks()
33     {
34 paus 1.10 // Destructor
35 loizides 1.5 delete tracks_;
36 loizides 1.1 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     tws.AddBranch(mitName_.c_str(),&tracks_);
44     }
45    
46 loizides 1.4 //--------------------------------------------------------------------------------------------------
47 loizides 1.1 void FillerTracks::FillDataBlock(const edm::Event &event,
48     const edm::EventSetup &setup)
49     {
50 paus 1.10 // -----------------------------------------------------------------------------------------------
51     // Fill tracks from edm collection into our collection
52     // -----------------------------------------------------------------------------------------------
53     tracks_ ->Reset();
54 loizides 1.1 trackMap_->Reset();
55 loizides 1.6
56     Handle<reco::TrackCollection> hTrackProduct;
57     GetProduct(edmName_, hTrackProduct, event);
58 loizides 1.1
59 loizides 1.6 trackMap_->SetEdmProductId(hTrackProduct.id().id());
60     const reco::TrackCollection inTracks = *(hTrackProduct.product());
61 loizides 1.1
62 paus 1.10 // -----------------------------------------------------------------------------------------------
63     // for MC SimParticle association (reco->sim mappings)
64     // -----------------------------------------------------------------------------------------------
65 loizides 1.1 reco::RecoToSimCollection simAssociation;
66     if (simMap_ && !edmSimAssociationName_.empty()) {
67     Handle<reco::RecoToSimCollection> simAssociationProduct;
68 loizides 1.6 GetProduct(edmSimAssociationName_, simAssociationProduct, event);
69 loizides 1.1 simAssociation = *(simAssociationProduct.product());
70     }
71    
72 paus 1.10 // -----------------------------------------------------------------------------------------------
73     // loop through all tracks and fill the information
74     // -----------------------------------------------------------------------------------------------
75     for (reco::TrackCollection::const_iterator it = inTracks.begin();
76     it != inTracks.end(); ++it) {
77 loizides 1.5 mithep::Track *outTrack = tracks_->Allocate();
78 paus 1.10 // create track and set the core parameters
79     new (outTrack) mithep::Track(it->phi(),it->d0(),it->pt(),it->dz(),it->theta());
80     outTrack->SetErrors(it->phiError(),it->d0Error(),it->ptError(),it->dzError(),it->thetaError());
81     outTrack->SetCharge(it->charge());
82 loizides 1.1
83     // add reference between mithep and edm object
84 paus 1.10 reco::TrackRef theRef(hTrackProduct, it - inTracks.begin());
85 loizides 1.1 trackMap_->Add(theRef, outTrack);
86    
87     if (simMap_ && !edmSimAssociationName_.empty()) {
88     reco::TrackBaseRef theBaseRef(theRef);
89     vector<pair<TrackingParticleRef, double> > simRefs;
90 paus 1.10 Bool_t noSimParticle = 0;
91 loizides 1.1 try {
92     simRefs = simAssociation[theBaseRef]; //try to get the sim references if existing
93     }
94 loizides 1.5 catch (edm::Exception &ex) {
95 paus 1.10 noSimParticle = 1;
96 loizides 1.1 }
97 paus 1.10
98 loizides 1.1 if (!noSimParticle) { //loop through sim match candidates
99     for (vector<pair<TrackingParticleRef, double> >::const_iterator simRefPair=simRefs.begin();
100     simRefPair != simRefs.end(); ++simRefPair)
101    
102 paus 1.10 if (simRefPair->second > 0.5) // require more than 50% shared hits between reco and sim
103 bendavid 1.9 outTrack->SetMCPart(simMap_->GetMit(simRefPair->first)); //add reco->sim reference
104 loizides 1.1 }
105     }
106     }
107     tracks_->Trim();
108     }