ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitEdm/Producers/src/TrackToTrackAssociator.cc
Revision: 1.1
Committed: Tue Nov 4 19:25:56 2008 UTC (16 years, 6 months ago) by bendavid
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_008pre2, Mit_008pre1, Mit_006b, Mit_006a, Mit_006
Log Message:
Added TrackToTrackAssociator tool

File Contents

# User Rev Content
1 bendavid 1.1 // $Id: TrackToTrackAssociator.cc,v 1.1 2008/09/27 05:48:25 loizides Exp $
2    
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     produces<mitedm::TrackAssociation>();
22     }
23    
24     //--------------------------------------------------------------------------------------------------
25     void TrackToTrackAssociator::PrintErrorAndExit(const char *msg) const
26     {
27     // Print error message and then exit.
28    
29     Error("PrintErrorAndExit", msg);
30     gSystem->Exit(1);
31     }
32    
33     //--------------------------------------------------------------------------------------------------
34     void TrackToTrackAssociator::produce(Event &evt, const EventSetup &setup)
35     {
36    
37     Handle<View<reco::Track> > hFromTrackProduct;
38     GetProduct(fromTracksName_, hFromTrackProduct, evt);
39     const View<reco::Track> fromTracks = *(hFromTrackProduct.product());
40    
41     Handle<View<reco::Track> > hToTrackProduct;
42     GetProduct(toTracksName_, hToTrackProduct, evt);
43     const View<reco::Track> toTracks = *(hToTrackProduct.product());
44    
45     auto_ptr<mitedm::TrackAssociation> association(new mitedm::TrackAssociation());
46    
47     //fill all for each fromTrack, fill an association for all toTracks which share some hits, using as
48     //the association quality the ratio number of matched hits/number of valid hits on toTrack
49     for (View<reco::Track>::const_iterator tFrom = fromTracks.begin();
50     tFrom != fromTracks.end(); ++tFrom) {
51    
52     reco::TrackBaseRef refFrom = fromTracks.refAt(tFrom-fromTracks.begin());
53    
54     for (View<reco::Track>::const_iterator tTo = toTracks.begin();
55     tTo != toTracks.end(); ++tTo) {
56    
57     uint nShared = 0;
58     for (uint i=0; i<tTo->recHitsSize(); ++i) {
59     if (tTo->recHit(i)->isValid()) {
60     bool matchedHit = false;
61     for (uint j=0; j<tFrom->recHitsSize() && !matchedHit; ++j) {
62     if ( tTo->recHit(i)->sharesInput(tFrom->recHit(j).get(), TrackingRecHit::some) ) {
63     nShared++;
64     matchedHit=true;
65     }
66     }
67     }
68     }
69    
70     if (nShared>0) {
71     double rShared = (double)nShared/(double)(tTo->numberOfValidHits());
72     reco::TrackBaseRef refTo = toTracks.refAt(tTo-toTracks.begin());
73     std::pair<TrackBaseRef, double> assocWQuality(refTo,rShared);
74     association->insert(refFrom, assocWQuality);
75     }
76     }
77     }
78    
79     evt.put(association);
80    
81     }
82    
83     // Define this as a plug-in
84     DEFINE_FWK_MODULE(TrackToTrackAssociator);