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