1 |
loizides |
1.8 |
// $Id: FillerTracks.cc,v 1.7 2008/07/13 08:46:04 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 |
|
|
#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 |
|
|
// Constructor.
|
29 |
|
|
}
|
30 |
|
|
|
31 |
loizides |
1.4 |
//--------------------------------------------------------------------------------------------------
|
32 |
loizides |
1.1 |
FillerTracks::~FillerTracks()
|
33 |
|
|
{
|
34 |
|
|
// Destructor.
|
35 |
|
|
|
36 |
loizides |
1.5 |
delete tracks_;
|
37 |
loizides |
1.1 |
delete trackMap_;
|
38 |
|
|
}
|
39 |
|
|
|
40 |
loizides |
1.4 |
//--------------------------------------------------------------------------------------------------
|
41 |
loizides |
1.1 |
void FillerTracks::BookDataBlock(TreeWriter &tws)
|
42 |
|
|
{
|
43 |
|
|
// Add tracks branch to tree.
|
44 |
|
|
|
45 |
|
|
tws.AddBranch(mitName_.c_str(),&tracks_);
|
46 |
|
|
}
|
47 |
|
|
|
48 |
loizides |
1.4 |
//--------------------------------------------------------------------------------------------------
|
49 |
loizides |
1.1 |
void FillerTracks::FillDataBlock(const edm::Event &event,
|
50 |
|
|
const edm::EventSetup &setup)
|
51 |
|
|
{
|
52 |
|
|
// Fill tracks from edm collection into our collection.
|
53 |
|
|
|
54 |
|
|
tracks_->Reset();
|
55 |
|
|
trackMap_->Reset();
|
56 |
loizides |
1.6 |
|
57 |
|
|
Handle<reco::TrackCollection> hTrackProduct;
|
58 |
|
|
GetProduct(edmName_, hTrackProduct, event);
|
59 |
loizides |
1.1 |
|
60 |
loizides |
1.6 |
trackMap_->SetEdmProductId(hTrackProduct.id().id());
|
61 |
|
|
const reco::TrackCollection inTracks = *(hTrackProduct.product());
|
62 |
loizides |
1.1 |
|
63 |
|
|
// if we have a Sim Particle association (for monte carlo), initialize the reco->sim mappings
|
64 |
|
|
reco::RecoToSimCollection simAssociation;
|
65 |
|
|
if (simMap_ && !edmSimAssociationName_.empty()) {
|
66 |
|
|
Handle<reco::RecoToSimCollection> simAssociationProduct;
|
67 |
loizides |
1.6 |
GetProduct(edmSimAssociationName_, simAssociationProduct, event);
|
68 |
loizides |
1.1 |
simAssociation = *(simAssociationProduct.product());
|
69 |
|
|
}
|
70 |
|
|
|
71 |
|
|
// loop through all tracks
|
72 |
|
|
for (reco::TrackCollection::const_iterator inTrack = inTracks.begin();
|
73 |
|
|
inTrack != inTracks.end(); ++inTrack) {
|
74 |
|
|
|
75 |
loizides |
1.5 |
mithep::Track *outTrack = tracks_->Allocate();
|
76 |
loizides |
1.4 |
new (outTrack) mithep::Track(inTrack->phi(),
|
77 |
|
|
inTrack->d0(),
|
78 |
|
|
inTrack->pt(),
|
79 |
|
|
inTrack->dz(),
|
80 |
|
|
inTrack->theta());
|
81 |
loizides |
1.1 |
|
82 |
|
|
outTrack->SetErrors(inTrack->phiError(),
|
83 |
|
|
inTrack->d0Error(),
|
84 |
|
|
inTrack->ptError(),
|
85 |
|
|
inTrack->dzError(),
|
86 |
|
|
inTrack->thetaError());
|
87 |
|
|
|
88 |
|
|
outTrack->SetCharge(inTrack->charge());
|
89 |
|
|
|
90 |
|
|
// add reference between mithep and edm object
|
91 |
loizides |
1.6 |
reco::TrackRef theRef(hTrackProduct, inTrack-inTracks.begin());
|
92 |
loizides |
1.1 |
trackMap_->Add(theRef, outTrack);
|
93 |
|
|
|
94 |
|
|
if (simMap_ && !edmSimAssociationName_.empty()) {
|
95 |
|
|
reco::TrackBaseRef theBaseRef(theRef);
|
96 |
|
|
vector<pair<TrackingParticleRef, double> > simRefs;
|
97 |
|
|
Bool_t noSimParticle=0;
|
98 |
|
|
try {
|
99 |
|
|
simRefs = simAssociation[theBaseRef]; //try to get the sim references if existing
|
100 |
|
|
}
|
101 |
loizides |
1.5 |
catch (edm::Exception &ex) {
|
102 |
loizides |
1.1 |
noSimParticle=1;
|
103 |
|
|
}
|
104 |
|
|
if (!noSimParticle) { //loop through sim match candidates
|
105 |
|
|
for (vector<pair<TrackingParticleRef, double> >::const_iterator simRefPair=simRefs.begin();
|
106 |
|
|
simRefPair != simRefs.end(); ++simRefPair)
|
107 |
|
|
|
108 |
|
|
if ( simRefPair->second > 0.5 ) // require more than 50% shared hits between reco and sim
|
109 |
loizides |
1.8 |
outTrack->SetSimPart(simMap_->GetMit(simRefPair->first)); //add reco->sim reference
|
110 |
loizides |
1.1 |
}
|
111 |
|
|
}
|
112 |
|
|
}
|
113 |
|
|
|
114 |
|
|
tracks_->Trim();
|
115 |
|
|
}
|