ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/src/FillerTracks.cc
Revision: 1.26
Committed: Tue Nov 4 19:24:48 2008 UTC (16 years, 6 months ago) by bendavid
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_006b, Mit_006a, Mit_006
Changes since 1.25: +3 -2 lines
Log Message:
use typedefs for TrackPtr

File Contents

# Content
1 // $Id: FillerTracks.cc,v 1.25 2008/11/03 18:16:23 bendavid Exp $
2
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/HitPattern.h"
7 #include "DataFormats/TrackReco/interface/Track.h"
8 #include "DataFormats/TrackReco/interface/TrackFwd.h"
9 #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h"
10 #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticleFwd.h"
11 #include "DataFormats/RecoCandidate/interface/TrackAssociation.h"
12 #include "TrackingTools/TrackAssociator/interface/TrackDetectorAssociator.h"
13 #include "MitEdm/DataFormats/interface/Types.h"
14
15 using namespace std;
16 using namespace edm;
17 using namespace mithep;
18
19 //--------------------------------------------------------------------------------------------------
20 FillerTracks::FillerTracks(const ParameterSet &cfg, const char *name, bool active, bool ecalActive,
21 const char *edmName, const char *mitName) :
22 BaseFiller(cfg,name,active),
23 ecalAssocActive_(Conf().getUntrackedParameter<bool>("ecalAssocActive",ecalActive)),
24 edmName_(Conf().getUntrackedParameter<string>("edmName",edmName)),
25 mitName_(Conf().getUntrackedParameter<string>("mitName",mitName)),
26 edmSimAssocName_(Conf().getUntrackedParameter<string>("edmSimAssociationName","")),
27 trackingMapName_(Conf().getUntrackedParameter<string>("trackingMapName","TrackingMap")),
28 barrelSuperClusterIdMapName_(Conf().getUntrackedParameter<string>("superClusterIdMapName","barrelSuperClusterIdMap")),
29 endcapSuperClusterIdMapName_(Conf().getUntrackedParameter<string>("endcapClusterIdMapName","endcapSuperClusterIdMap")),
30 trackMapName_(Conf().getUntrackedParameter<string>("trackMapName",
31 Form("%sMapName",mitName_.c_str()))),
32 trackingMap_(0),
33 tracks_(new mithep::TrackArr(250)),
34 trackMap_(new mithep::TrackMap)
35 {
36 // Constructor.
37
38 //initialize track associator configuration if needed
39 if (ecalAssocActive_)
40 assocParams_.loadParameters(cfg.getUntrackedParameter<ParameterSet>("TrackAssociatorParameters"));
41
42 }
43
44 //--------------------------------------------------------------------------------------------------
45 FillerTracks::~FillerTracks()
46 {
47 // Destructor.
48
49 delete tracks_;
50 delete trackMap_;
51 }
52
53 //--------------------------------------------------------------------------------------------------
54 void FillerTracks::BookDataBlock(TreeWriter &tws)
55 {
56 // Add tracks branch to tree, publish and get our objects.
57
58 tws.AddBranch(mitName_.c_str(),&tracks_);
59
60 trackingMap_ = OS()->get<TrackingParticleMap>(trackingMapName_.c_str());
61 barrelSuperClusterIdMap_ = OS()->get<SuperClusterIdMap>(barrelSuperClusterIdMapName_.c_str());
62 endcapSuperClusterIdMap_ = OS()->get<SuperClusterIdMap>(endcapSuperClusterIdMapName_.c_str());
63 OS()->add<TrackMap>(trackMap_,trackMapName_.c_str());
64 OS()->add<TrackArr>(tracks_,mitName_.c_str());
65 }
66
67 //--------------------------------------------------------------------------------------------------
68 void FillerTracks::FillDataBlock(const edm::Event &event,
69 const edm::EventSetup &setup)
70 {
71 // Fill tracks from edm collection into our collection.
72
73 tracks_ ->Reset();
74 trackMap_->Reset();
75
76 //initialize Handle and get product, this usage allows also to get collections of classes which
77 //inherit from reco::Track
78 Handle<View<reco::Track> > hTrackProduct;
79 GetProduct(edmName_, hTrackProduct, event);
80
81 trackMap_->SetEdmProductId(hTrackProduct.id().id());
82 const View<reco::Track> inTracks = *(hTrackProduct.product());
83
84 // for MC SimParticle association (reco->sim mappings)
85 reco::RecoToSimCollection simAssociation;
86 if (trackingMap_ && !edmSimAssocName_.empty()) {
87 Handle<reco::RecoToSimCollection> simAssociationProduct;
88 GetProduct(edmSimAssocName_, simAssociationProduct, event);
89 simAssociation = *(simAssociationProduct.product());
90 //printf("SimAssociation Map Size = %i\n",simAssociation.size());
91 }
92
93 //set up associator for Track-Ecal associations
94 TrackDetectorAssociator trackAssociator;
95 trackAssociator.useDefaultPropagator();
96
97 // loop through all tracks and fill the information
98 for (View<reco::Track>::const_iterator it = inTracks.begin();
99 it != inTracks.end(); ++it) {
100
101 mithep::Track *outTrack = tracks_->Allocate();
102 // create track and set the core parameters
103 new (outTrack) mithep::Track(it->qoverp(),it->lambda(),
104 it->phi(),it->dxy(),it->dsz());
105 outTrack->SetErrors(it->qoverpError(),it->lambdaError(),
106 it->phiError(),it->dxyError(),it->dszError());
107
108 // fill track quality information
109 outTrack->SetChi2(it->chi2());
110 outTrack->SetNdof(static_cast<Int_t>(it->ndof()));
111
112 //fill hit layer map
113 const reco::HitPattern &hits = it->hitPattern();
114 for (Int_t i=0; i<hits.numberOfHits(); i++) {
115 uint32_t hit = hits.getHitPattern(i);
116 if (hits.validHitFilter(hit))
117 if (hits.trackerHitFilter(hit))
118 outTrack->SetHit(hitReader_.Layer(hit));
119
120 if (0) {
121 if (hits.muonDTHitFilter(hit))
122 printf("Muon DT Layer = %i\n", hits.getLayer(hit));
123 if (hits.muonCSCHitFilter(hit))
124 printf("Muon CSC Layer = %i\n", hits.getLayer(hit));
125 if (hits.muonRPCHitFilter(hit))
126 printf("Muon RPC Layer = %i\n", hits.getLayer(hit));
127 }
128 }
129
130 //make ecal associations
131 if (ecalAssocActive_) {
132 TrackDetMatchInfo matchInfo = trackAssociator.associate(event,setup,
133 *it,
134 assocParams_);
135 outTrack->SetEtaEcal(matchInfo.trkGlobPosAtEcal.eta());
136 outTrack->SetPhiEcal(matchInfo.trkGlobPosAtEcal.phi());
137
138 //fill supercluster link
139 if (barrelSuperClusterIdMap_ || endcapSuperClusterIdMap_) {
140 mithep::SuperCluster *cluster = 0;
141 for (std::vector<const ::CaloTower*>::const_iterator iTower = matchInfo.crossedTowers.begin();
142 iTower<matchInfo.crossedTowers.end() && !cluster; iTower++) {
143
144 for (uint ihit=0; ihit<(*iTower)->constituentsSize() && !cluster; ihit++) {
145 DetId hit = (*iTower)->constituent(ihit);
146 if (barrelSuperClusterIdMap_ && barrelSuperClusterIdMap_->HasMit(hit))
147 cluster = barrelSuperClusterIdMap_->GetMit(hit);
148 else if (endcapSuperClusterIdMap_ && endcapSuperClusterIdMap_->HasMit(hit))
149 cluster = endcapSuperClusterIdMap_->GetMit(hit);
150 }
151 }
152 if (cluster)
153 outTrack->SetSCluster(cluster);
154
155 }
156 }
157
158 // add reference between mithep and edm object
159 mitedm::TrackPtr thePtr = inTracks.ptrAt(it - inTracks.begin());
160 trackMap_->Add(thePtr, outTrack);
161
162 //do dim associations
163 if (trackingMap_ && !edmSimAssocName_.empty()) {
164 //printf("Trying Track-Sim association\n");
165 reco::TrackBaseRef theBaseRef = inTracks.refAt(it - inTracks.begin());
166 vector<pair<TrackingParticleRef, double> > simRefs;
167 Bool_t noSimParticle = 0;
168 try {
169 simRefs = simAssociation[theBaseRef]; //try to get the sim references if existing
170 }
171 catch (edm::Exception &ex) {
172 noSimParticle = 1;
173 }
174
175 if (!noSimParticle) { //loop through sim match candidates
176 //printf("Applying track-sim association\n");
177 for (vector<pair<TrackingParticleRef, double> >::const_iterator simRefPair=simRefs.begin();
178 simRefPair != simRefs.end(); ++simRefPair)
179
180 if (simRefPair->second > 0.5) // require more than 50% shared hits between reco and sim
181 outTrack->SetMCPart(trackingMap_->GetMit(simRefPair->first)); //add reco->sim reference
182 }
183 }
184 }
185 tracks_->Trim();
186 }
187