1 |
loizides |
1.2 |
// $Id: TrackToTrackAssociator.cc,v 1.1 2008/11/04 19:25:56 bendavid Exp $
|
2 |
bendavid |
1.1 |
|
3 |
|
|
#include "MitEdm/Producers/interface/TrackToTrackAssociator.h"
|
4 |
|
|
#include <TSystem.h>
|
5 |
|
|
#include <TError.h>
|
6 |
|
|
#include "DataFormats/TrackReco/interface/TrackFwd.h"
|
7 |
|
|
#include "MitEdm/DataFormats/interface/Types.h"
|
8 |
|
|
|
9 |
|
|
using namespace std;
|
10 |
|
|
using namespace edm;
|
11 |
|
|
using namespace reco;
|
12 |
|
|
using namespace mitedm;
|
13 |
|
|
using namespace mithep;
|
14 |
|
|
|
15 |
|
|
//--------------------------------------------------------------------------------------------------
|
16 |
|
|
TrackToTrackAssociator::TrackToTrackAssociator(const ParameterSet& cfg) :
|
17 |
|
|
fromTracksName_(cfg.getUntrackedParameter<string>("fromTracks")),
|
18 |
|
|
toTracksName_(cfg.getUntrackedParameter<string>("toTracks"))
|
19 |
|
|
{
|
20 |
|
|
// Constructor: Register your base product.
|
21 |
loizides |
1.2 |
|
22 |
bendavid |
1.1 |
produces<mitedm::TrackAssociation>();
|
23 |
|
|
}
|
24 |
|
|
|
25 |
|
|
//--------------------------------------------------------------------------------------------------
|
26 |
|
|
void TrackToTrackAssociator::PrintErrorAndExit(const char *msg) const
|
27 |
|
|
{
|
28 |
|
|
// Print error message and then exit.
|
29 |
|
|
|
30 |
|
|
Error("PrintErrorAndExit", msg);
|
31 |
|
|
gSystem->Exit(1);
|
32 |
|
|
}
|
33 |
|
|
|
34 |
|
|
//--------------------------------------------------------------------------------------------------
|
35 |
|
|
void TrackToTrackAssociator::produce(Event &evt, const EventSetup &setup)
|
36 |
|
|
{
|
37 |
loizides |
1.2 |
// Produce the track association.
|
38 |
bendavid |
1.1 |
|
39 |
|
|
Handle<View<reco::Track> > hFromTrackProduct;
|
40 |
|
|
GetProduct(fromTracksName_, hFromTrackProduct, evt);
|
41 |
|
|
const View<reco::Track> fromTracks = *(hFromTrackProduct.product());
|
42 |
|
|
|
43 |
|
|
Handle<View<reco::Track> > hToTrackProduct;
|
44 |
|
|
GetProduct(toTracksName_, hToTrackProduct, evt);
|
45 |
|
|
const View<reco::Track> toTracks = *(hToTrackProduct.product());
|
46 |
|
|
|
47 |
|
|
auto_ptr<mitedm::TrackAssociation> association(new mitedm::TrackAssociation());
|
48 |
|
|
|
49 |
loizides |
1.2 |
//fill all for each fromTrack, fill an association for all toTracks which share some hits,
|
50 |
|
|
//using as the association quality the ratio number of matched hits/number of valid hits
|
51 |
|
|
//on toTrack
|
52 |
bendavid |
1.1 |
for (View<reco::Track>::const_iterator tFrom = fromTracks.begin();
|
53 |
|
|
tFrom != fromTracks.end(); ++tFrom) {
|
54 |
|
|
|
55 |
|
|
reco::TrackBaseRef refFrom = fromTracks.refAt(tFrom-fromTracks.begin());
|
56 |
|
|
|
57 |
|
|
for (View<reco::Track>::const_iterator tTo = toTracks.begin();
|
58 |
|
|
tTo != toTracks.end(); ++tTo) {
|
59 |
|
|
|
60 |
loizides |
1.2 |
uint nShared = 0;
|
61 |
|
|
for (uint i=0; i<tTo->recHitsSize(); ++i) {
|
62 |
|
|
if (tTo->recHit(i)->isValid()) {
|
63 |
|
|
bool matchedHit = false;
|
64 |
|
|
for (uint j=0; j<tFrom->recHitsSize() && !matchedHit; ++j) {
|
65 |
|
|
if ( tTo->recHit(i)->sharesInput(tFrom->recHit(j).get(), TrackingRecHit::some) ) {
|
66 |
|
|
nShared++;
|
67 |
|
|
matchedHit=true;
|
68 |
bendavid |
1.1 |
}
|
69 |
loizides |
1.2 |
}
|
70 |
|
|
}
|
71 |
|
|
}
|
72 |
|
|
|
73 |
|
|
if (nShared>0) {
|
74 |
|
|
double rShared = (double)nShared/(double)(tTo->numberOfValidHits());
|
75 |
|
|
reco::TrackBaseRef refTo = toTracks.refAt(tTo-toTracks.begin());
|
76 |
|
|
std::pair<TrackBaseRef, double> assocWQuality(refTo,rShared);
|
77 |
|
|
association->insert(refFrom, assocWQuality);
|
78 |
|
|
}
|
79 |
bendavid |
1.1 |
}
|
80 |
|
|
}
|
81 |
|
|
evt.put(association);
|
82 |
|
|
}
|
83 |
|
|
|
84 |
loizides |
1.2 |
// define this as a plug-in
|
85 |
bendavid |
1.1 |
DEFINE_FWK_MODULE(TrackToTrackAssociator);
|