1 |
loizides |
1.1 |
// $Id: FillerGlobalMuons.cc,v 1.3 2008/06/18 19:17:21 loizides 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/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 |
|
|
|
12 |
|
|
#include "MitAna/DataTree/interface/Track.h"
|
13 |
|
|
#include "MitAna/DataTree/interface/Names.h"
|
14 |
|
|
|
15 |
|
|
using namespace std;
|
16 |
|
|
using namespace edm;
|
17 |
|
|
using namespace mithep;
|
18 |
|
|
|
19 |
|
|
//-------------------------------------------------------------------------------------------------
|
20 |
|
|
FillerTracks::FillerTracks(const ParameterSet &cfg,
|
21 |
|
|
const char *name="Tracks", const SimParticleMap *sm) :
|
22 |
|
|
BaseFiller(cfg, name),
|
23 |
|
|
edmName_(Conf().getUntrackedParameter<string>("edmName","")),
|
24 |
|
|
edmDataName_(Conf().getUntrackedParameter<string>("edmDataName","")),
|
25 |
|
|
mitName_(Conf().getUntrackedParameter<string>("mitName","")),
|
26 |
|
|
edmSimAssociationName_(Conf().getUntrackedParameter<string>("edmSimAssociationName","")),
|
27 |
|
|
simMap_(sm),
|
28 |
|
|
tracks_(new mithep::TrackArr),
|
29 |
|
|
trackMap_(new mithep::TrackMap)
|
30 |
|
|
{
|
31 |
|
|
// Constructor.
|
32 |
|
|
}
|
33 |
|
|
|
34 |
|
|
//-------------------------------------------------------------------------------------------------
|
35 |
|
|
FillerTracks::~FillerTracks()
|
36 |
|
|
{
|
37 |
|
|
// Destructor.
|
38 |
|
|
|
39 |
|
|
delete trackMap_;
|
40 |
|
|
}
|
41 |
|
|
|
42 |
|
|
//-------------------------------------------------------------------------------------------------
|
43 |
|
|
void FillerTracks::BookDataBlock(TreeWriter &tws)
|
44 |
|
|
{
|
45 |
|
|
// Add tracks branch to tree.
|
46 |
|
|
|
47 |
|
|
tws.AddBranch(mitName_.c_str(),&tracks_);
|
48 |
|
|
}
|
49 |
|
|
|
50 |
|
|
//-------------------------------------------------------------------------------------------------
|
51 |
|
|
void FillerTracks::FillDataBlock(const edm::Event &event,
|
52 |
|
|
const edm::EventSetup &setup)
|
53 |
|
|
{
|
54 |
|
|
// Fill tracks from edm collection into our collection.
|
55 |
|
|
|
56 |
|
|
tracks_->Reset();
|
57 |
|
|
trackMap_->Reset();
|
58 |
|
|
|
59 |
|
|
// get the tracks collection
|
60 |
|
|
try {
|
61 |
|
|
if (edmDataName_ == "")
|
62 |
|
|
event.getByLabel(edmName_,trackProduct_);
|
63 |
|
|
else
|
64 |
|
|
event.getByLabel(edmName_,edmDataName_,trackProduct_);
|
65 |
|
|
} catch (cms::Exception& ex) {
|
66 |
|
|
edm::LogError("FillerTracks") << "Error! Cannot get collection with label "
|
67 |
|
|
<< edmName_ << endl;
|
68 |
|
|
throw edm::Exception(edm::errors::Configuration, "FillerTracks:FillDataBlock()\n")
|
69 |
|
|
<< "Error! Cannot get collection with label " << edmName_ << endl;
|
70 |
|
|
}
|
71 |
|
|
|
72 |
|
|
trackMap_->SetEdmProductId(trackProduct_.id().id());
|
73 |
|
|
const reco::TrackCollection inTracks = *(trackProduct_.product());
|
74 |
|
|
|
75 |
|
|
// if we have a Sim Particle association (for monte carlo), initialize the reco->sim mappings
|
76 |
|
|
reco::RecoToSimCollection simAssociation;
|
77 |
|
|
if (simMap_ && !edmSimAssociationName_.empty()) {
|
78 |
|
|
Handle<reco::RecoToSimCollection> simAssociationProduct;
|
79 |
|
|
try {
|
80 |
|
|
event.getByLabel(edmSimAssociationName_, simAssociationProduct);
|
81 |
|
|
}
|
82 |
|
|
catch (cms::Exception& ex) {
|
83 |
|
|
edm::LogError("FillerTracks") << "Error! Cannot get collection with label "
|
84 |
|
|
<< edmSimAssociationName_ << endl;
|
85 |
|
|
throw edm::Exception(edm::errors::Configuration, "FillerTracks:FillDataBlock()\n")
|
86 |
|
|
<< "Error! Cannot get collection with label " << edmSimAssociationName_ << endl;
|
87 |
|
|
}
|
88 |
|
|
simAssociation = *(simAssociationProduct.product());
|
89 |
|
|
}
|
90 |
|
|
|
91 |
|
|
// loop through all tracks
|
92 |
|
|
for (reco::TrackCollection::const_iterator inTrack = inTracks.begin();
|
93 |
|
|
inTrack != inTracks.end(); ++inTrack) {
|
94 |
|
|
|
95 |
|
|
mithep::Track* outTrack = tracks_->Allocate();
|
96 |
|
|
new (outTrack) mithep::Track(inTrack->phi(),inTrack->d0(),inTrack->pt(),inTrack->dz(),inTrack->theta());
|
97 |
|
|
|
98 |
|
|
|
99 |
|
|
outTrack->SetErrors(inTrack->phiError(),
|
100 |
|
|
inTrack->d0Error(),
|
101 |
|
|
inTrack->ptError(),
|
102 |
|
|
inTrack->dzError(),
|
103 |
|
|
inTrack->thetaError());
|
104 |
|
|
|
105 |
|
|
outTrack->SetCharge(inTrack->charge());
|
106 |
|
|
|
107 |
|
|
// add reference between mithep and edm object
|
108 |
|
|
reco::TrackRef theRef(trackProduct_, inTrack-inTracks.begin());
|
109 |
|
|
trackMap_->Add(theRef, outTrack);
|
110 |
|
|
|
111 |
|
|
if (simMap_ && !edmSimAssociationName_.empty()) {
|
112 |
|
|
reco::TrackBaseRef theBaseRef(theRef);
|
113 |
|
|
vector<pair<TrackingParticleRef, double> > simRefs;
|
114 |
|
|
Bool_t noSimParticle=0;
|
115 |
|
|
try {
|
116 |
|
|
simRefs = simAssociation[theBaseRef]; //try to get the sim references if existing
|
117 |
|
|
}
|
118 |
|
|
catch (edm::Exception& ex) {
|
119 |
|
|
noSimParticle=1;
|
120 |
|
|
}
|
121 |
|
|
if (!noSimParticle) { //loop through sim match candidates
|
122 |
|
|
for (vector<pair<TrackingParticleRef, double> >::const_iterator simRefPair=simRefs.begin();
|
123 |
|
|
simRefPair != simRefs.end(); ++simRefPair)
|
124 |
|
|
|
125 |
|
|
if ( simRefPair->second > 0.5 ) // require more than 50% shared hits between reco and sim
|
126 |
|
|
outTrack->SetSimParticle(simMap_->GetMit(simRefPair->first)); //add reco->sim reference
|
127 |
|
|
}
|
128 |
|
|
}
|
129 |
|
|
}
|
130 |
|
|
|
131 |
|
|
tracks_->Trim();
|
132 |
|
|
}
|