1 |
bendavid |
1.16 |
// $Id: FillerGsfTracks.cc,v 1.15 2008/09/17 04:28:12 loizides Exp $
|
2 |
loizides |
1.1 |
|
3 |
|
|
#include "MitProd/TreeFiller/interface/FillerGsfTracks.h"
|
4 |
|
|
#include "FWCore/MessageLogger/interface/MessageLogger.h"
|
5 |
|
|
#include "DataFormats/Common/interface/Handle.h"
|
6 |
|
|
#include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
|
7 |
|
|
#include "DataFormats/GsfTrackReco/interface/GsfTrackFwd.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.13 |
FillerGsfTracks::FillerGsfTracks(const ParameterSet &cfg, const char *name, bool active) :
|
19 |
|
|
FillerTracks(cfg,name,active,"pixelMatchGsfFit","GsfTracks"),
|
20 |
loizides |
1.4 |
trackMap_(new mithep::GsfTrackMap)
|
21 |
loizides |
1.1 |
{
|
22 |
loizides |
1.10 |
// Constructor.
|
23 |
loizides |
1.1 |
}
|
24 |
|
|
|
25 |
loizides |
1.4 |
//--------------------------------------------------------------------------------------------------
|
26 |
loizides |
1.1 |
FillerGsfTracks::~FillerGsfTracks()
|
27 |
|
|
{
|
28 |
|
|
// Destructor.
|
29 |
|
|
|
30 |
|
|
delete trackMap_;
|
31 |
|
|
}
|
32 |
|
|
|
33 |
loizides |
1.4 |
//--------------------------------------------------------------------------------------------------
|
34 |
loizides |
1.1 |
void FillerGsfTracks::BookDataBlock(TreeWriter &tws)
|
35 |
|
|
{
|
36 |
loizides |
1.10 |
// Add tracks branch to tree, publish and get our objects.
|
37 |
loizides |
1.1 |
|
38 |
|
|
tws.AddBranch(mitName_.c_str(),&tracks_);
|
39 |
loizides |
1.10 |
|
40 |
bendavid |
1.14 |
trackingMap_ = OS()->get<TrackingParticleMap>(trackingMapName_.c_str());
|
41 |
loizides |
1.10 |
OS()->add<GsfTrackMap>(trackMap_,trackMapName_.c_str());
|
42 |
|
|
OS()->add<TrackArr>(tracks_,mitName_.c_str());
|
43 |
loizides |
1.1 |
}
|
44 |
|
|
|
45 |
loizides |
1.4 |
//--------------------------------------------------------------------------------------------------
|
46 |
loizides |
1.1 |
void FillerGsfTracks::FillDataBlock(const edm::Event &event,
|
47 |
|
|
const edm::EventSetup &setup)
|
48 |
|
|
{
|
49 |
|
|
// Fill tracks from edm collection into our collection.
|
50 |
|
|
|
51 |
|
|
tracks_->Reset();
|
52 |
|
|
trackMap_->Reset();
|
53 |
|
|
|
54 |
loizides |
1.6 |
Handle<reco::GsfTrackCollection> hTrackProduct;
|
55 |
|
|
GetProduct(edmName_, hTrackProduct, event);
|
56 |
|
|
|
57 |
|
|
const reco::GsfTrackCollection inTracks = *(hTrackProduct.product());
|
58 |
loizides |
1.1 |
|
59 |
|
|
// if we have a Sim Particle association (for monte carlo), initialize the reco->sim mappings
|
60 |
|
|
reco::RecoToSimCollection simAssociation;
|
61 |
loizides |
1.15 |
if (trackingMap_ && !edmSimAssocName_.empty()) {
|
62 |
loizides |
1.6 |
Handle<reco::RecoToSimCollection> hSimAssociationProduct;
|
63 |
loizides |
1.15 |
GetProduct(edmSimAssocName_, hSimAssociationProduct, event);
|
64 |
loizides |
1.6 |
simAssociation = *(hSimAssociationProduct.product());
|
65 |
loizides |
1.1 |
}
|
66 |
|
|
|
67 |
|
|
// loop through all tracks
|
68 |
bendavid |
1.11 |
for (reco::GsfTrackCollection::const_iterator it = inTracks.begin();
|
69 |
|
|
it != inTracks.end(); ++it) {
|
70 |
loizides |
1.5 |
mithep::Track *outTrack = tracks_->Allocate();
|
71 |
bendavid |
1.11 |
// create track and set the core parameters
|
72 |
|
|
new (outTrack) mithep::Track(it->qoverp(),it->lambda(),it->phi(),it->dxy(),it->dsz());
|
73 |
|
|
outTrack->SetErrors(it->qoverpError(),it->lambdaError(),it->phiError(),it->dxyError(),it->dszError());
|
74 |
loizides |
1.1 |
|
75 |
bendavid |
1.11 |
//Fill track quality information
|
76 |
|
|
outTrack->SetChi2(it->chi2());
|
77 |
loizides |
1.13 |
outTrack->SetNdof(static_cast<Int_t>(it->ndof()));
|
78 |
bendavid |
1.11 |
|
79 |
|
|
//Fill hit layer map
|
80 |
|
|
const reco::HitPattern &hits = it->hitPattern();
|
81 |
|
|
for (Int_t i=0; i<hits.numberOfHits(); i++) {
|
82 |
|
|
uint32_t hit = hits.getHitPattern(i);
|
83 |
|
|
if ( hits.validHitFilter(hit) )
|
84 |
|
|
if ( hits.trackerHitFilter(hit) )
|
85 |
bendavid |
1.16 |
outTrack->SetHit(hitReader_.Layer(hit));
|
86 |
bendavid |
1.11 |
}
|
87 |
|
|
|
88 |
|
|
|
89 |
|
|
// add reference between mithep and edm object
|
90 |
|
|
reco::GsfTrackRef theRef(hTrackProduct, it - inTracks.begin());
|
91 |
loizides |
1.1 |
trackMap_->Add(theRef, outTrack);
|
92 |
|
|
|
93 |
loizides |
1.15 |
if (trackingMap_ && !edmSimAssocName_.empty()) {
|
94 |
loizides |
1.1 |
reco::TrackBaseRef theBaseRef(theRef);
|
95 |
bendavid |
1.11 |
vector<pair<TrackingParticleRef, double> > simRefs;
|
96 |
|
|
Bool_t noSimParticle = 0;
|
97 |
loizides |
1.1 |
try {
|
98 |
|
|
simRefs = simAssociation[theBaseRef]; //try to get the sim references if existing
|
99 |
|
|
}
|
100 |
loizides |
1.5 |
catch (edm::Exception &ex) {
|
101 |
bendavid |
1.11 |
noSimParticle = 1;
|
102 |
loizides |
1.1 |
}
|
103 |
bendavid |
1.11 |
|
104 |
loizides |
1.1 |
if (!noSimParticle) { //loop through sim match candidates
|
105 |
|
|
for (vector<pair<TrackingParticleRef, double> >::const_iterator simRefPair=simRefs.begin();
|
106 |
|
|
simRefPair != simRefs.end(); ++simRefPair)
|
107 |
bendavid |
1.11 |
|
108 |
|
|
if (simRefPair->second > 0.5) // require more than 50% shared hits between reco and sim
|
109 |
bendavid |
1.14 |
outTrack->SetMCPart(trackingMap_->GetMit(simRefPair->first)); //add reco->sim reference
|
110 |
loizides |
1.1 |
}
|
111 |
|
|
}
|
112 |
|
|
}
|
113 |
|
|
tracks_->Trim();
|
114 |
|
|
}
|