1 |
loizides |
1.13 |
// $Id: FillerTracks.cc,v 1.12 2008/07/30 16:39:58 loizides 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.13 |
FillerTracks::FillerTracks(const ParameterSet &cfg, const char *name, bool active) :
|
19 |
loizides |
1.7 |
BaseFiller(cfg,name,active),
|
20 |
loizides |
1.13 |
edmName_(Conf().getUntrackedParameter<string>("edmName","generalTracks")),
|
21 |
|
|
mitName_(Conf().getUntrackedParameter<string>("mitName",Names::gkTrackBrn)),
|
22 |
loizides |
1.1 |
edmSimAssociationName_(Conf().getUntrackedParameter<string>("edmSimAssociationName","")),
|
23 |
loizides |
1.13 |
simMapName_(Conf().getUntrackedParameter<string>("simMapName","SimMap")),
|
24 |
|
|
trackMapName_(Conf().getUntrackedParameter<string>("trackMapName",
|
25 |
|
|
Form("%sMapName",mitName_.c_str()))),
|
26 |
|
|
simMap_(0),
|
27 |
loizides |
1.7 |
tracks_(new mithep::TrackArr(250)),
|
28 |
loizides |
1.1 |
trackMap_(new mithep::TrackMap)
|
29 |
|
|
{
|
30 |
loizides |
1.13 |
// Constructor.
|
31 |
loizides |
1.1 |
}
|
32 |
|
|
|
33 |
loizides |
1.4 |
//--------------------------------------------------------------------------------------------------
|
34 |
loizides |
1.1 |
FillerTracks::~FillerTracks()
|
35 |
|
|
{
|
36 |
loizides |
1.13 |
// Destructor.
|
37 |
|
|
|
38 |
loizides |
1.5 |
delete tracks_;
|
39 |
loizides |
1.1 |
delete trackMap_;
|
40 |
|
|
}
|
41 |
|
|
|
42 |
loizides |
1.4 |
//--------------------------------------------------------------------------------------------------
|
43 |
loizides |
1.1 |
void FillerTracks::BookDataBlock(TreeWriter &tws)
|
44 |
|
|
{
|
45 |
loizides |
1.13 |
// Add tracks branch to tree, publish and get our objects.
|
46 |
|
|
|
47 |
loizides |
1.1 |
tws.AddBranch(mitName_.c_str(),&tracks_);
|
48 |
loizides |
1.12 |
|
49 |
loizides |
1.13 |
simMap_ = OS()->get<SimParticleMap>(simMapName_.c_str());
|
50 |
|
|
OS()->add<TrackMap>(trackMap_,trackMapName_.c_str());
|
51 |
|
|
OS()->add<TrackArr>(tracks_,mitName_.c_str());
|
52 |
loizides |
1.1 |
}
|
53 |
|
|
|
54 |
loizides |
1.4 |
//--------------------------------------------------------------------------------------------------
|
55 |
loizides |
1.1 |
void FillerTracks::FillDataBlock(const edm::Event &event,
|
56 |
|
|
const edm::EventSetup &setup)
|
57 |
|
|
{
|
58 |
loizides |
1.13 |
// Fill tracks from edm collection into our collection.
|
59 |
|
|
|
60 |
paus |
1.10 |
tracks_ ->Reset();
|
61 |
loizides |
1.1 |
trackMap_->Reset();
|
62 |
loizides |
1.6 |
|
63 |
|
|
Handle<reco::TrackCollection> hTrackProduct;
|
64 |
|
|
GetProduct(edmName_, hTrackProduct, event);
|
65 |
loizides |
1.1 |
|
66 |
loizides |
1.6 |
trackMap_->SetEdmProductId(hTrackProduct.id().id());
|
67 |
|
|
const reco::TrackCollection inTracks = *(hTrackProduct.product());
|
68 |
loizides |
1.1 |
|
69 |
paus |
1.10 |
// for MC SimParticle association (reco->sim mappings)
|
70 |
loizides |
1.1 |
reco::RecoToSimCollection simAssociation;
|
71 |
|
|
if (simMap_ && !edmSimAssociationName_.empty()) {
|
72 |
|
|
Handle<reco::RecoToSimCollection> simAssociationProduct;
|
73 |
loizides |
1.6 |
GetProduct(edmSimAssociationName_, simAssociationProduct, event);
|
74 |
loizides |
1.1 |
simAssociation = *(simAssociationProduct.product());
|
75 |
|
|
}
|
76 |
|
|
|
77 |
paus |
1.10 |
// loop through all tracks and fill the information
|
78 |
|
|
for (reco::TrackCollection::const_iterator it = inTracks.begin();
|
79 |
|
|
it != inTracks.end(); ++it) {
|
80 |
loizides |
1.5 |
mithep::Track *outTrack = tracks_->Allocate();
|
81 |
paus |
1.10 |
// create track and set the core parameters
|
82 |
|
|
new (outTrack) mithep::Track(it->phi(),it->d0(),it->pt(),it->dz(),it->theta());
|
83 |
|
|
outTrack->SetErrors(it->phiError(),it->d0Error(),it->ptError(),it->dzError(),it->thetaError());
|
84 |
|
|
outTrack->SetCharge(it->charge());
|
85 |
loizides |
1.1 |
|
86 |
|
|
// add reference between mithep and edm object
|
87 |
paus |
1.10 |
reco::TrackRef theRef(hTrackProduct, it - inTracks.begin());
|
88 |
loizides |
1.1 |
trackMap_->Add(theRef, outTrack);
|
89 |
|
|
|
90 |
|
|
if (simMap_ && !edmSimAssociationName_.empty()) {
|
91 |
|
|
reco::TrackBaseRef theBaseRef(theRef);
|
92 |
|
|
vector<pair<TrackingParticleRef, double> > simRefs;
|
93 |
paus |
1.10 |
Bool_t noSimParticle = 0;
|
94 |
loizides |
1.1 |
try {
|
95 |
|
|
simRefs = simAssociation[theBaseRef]; //try to get the sim references if existing
|
96 |
|
|
}
|
97 |
loizides |
1.5 |
catch (edm::Exception &ex) {
|
98 |
paus |
1.10 |
noSimParticle = 1;
|
99 |
loizides |
1.1 |
}
|
100 |
paus |
1.10 |
|
101 |
loizides |
1.1 |
if (!noSimParticle) { //loop through sim match candidates
|
102 |
|
|
for (vector<pair<TrackingParticleRef, double> >::const_iterator simRefPair=simRefs.begin();
|
103 |
|
|
simRefPair != simRefs.end(); ++simRefPair)
|
104 |
|
|
|
105 |
paus |
1.10 |
if (simRefPair->second > 0.5) // require more than 50% shared hits between reco and sim
|
106 |
bendavid |
1.9 |
outTrack->SetMCPart(simMap_->GetMit(simRefPair->first)); //add reco->sim reference
|
107 |
loizides |
1.1 |
}
|
108 |
|
|
}
|
109 |
|
|
}
|
110 |
|
|
tracks_->Trim();
|
111 |
|
|
}
|