ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/src/FillerTracks.cc
(Generate patch)

Comparing UserCode/MitProd/TreeFiller/src/FillerTracks.cc (file contents):
Revision 1.7 by loizides, Sun Jul 13 08:46:04 2008 UTC vs.
Revision 1.13 by loizides, Thu Jul 31 12:34:04 2008 UTC

# Line 15 | Line 15 | using namespace edm;
15   using namespace mithep;
16  
17   //--------------------------------------------------------------------------------------------------
18 < FillerTracks::FillerTracks(const ParameterSet &cfg, const char *name,
19 <                           bool active, const SimParticleMap *sm) :
18 > FillerTracks::FillerTracks(const ParameterSet &cfg, const char *name, bool active) :
19    BaseFiller(cfg,name,active),
20 <  edmName_(Conf().getUntrackedParameter<string>("edmName","")),
21 <  mitName_(Conf().getUntrackedParameter<string>("mitName","")),
20 >  edmName_(Conf().getUntrackedParameter<string>("edmName","generalTracks")),
21 >  mitName_(Conf().getUntrackedParameter<string>("mitName",Names::gkTrackBrn)),
22    edmSimAssociationName_(Conf().getUntrackedParameter<string>("edmSimAssociationName","")),
23 <  simMap_(sm),
23 >  simMapName_(Conf().getUntrackedParameter<string>("simMapName","SimMap")),
24 >  trackMapName_(Conf().getUntrackedParameter<string>("trackMapName",
25 >                                                     Form("%sMapName",mitName_.c_str()))),
26 >  simMap_(0),
27    tracks_(new mithep::TrackArr(250)),
28    trackMap_(new mithep::TrackMap)
29   {
# Line 40 | Line 42 | FillerTracks::~FillerTracks()
42   //--------------------------------------------------------------------------------------------------
43   void FillerTracks::BookDataBlock(TreeWriter &tws)
44   {
45 <  // Add tracks branch to tree.
45 >  // Add tracks branch to tree, publish and get our objects.
46  
47    tws.AddBranch(mitName_.c_str(),&tracks_);
48 +
49 +  simMap_ = OS()->get<SimParticleMap>(simMapName_.c_str());
50 +  OS()->add<TrackMap>(trackMap_,trackMapName_.c_str());
51 +  OS()->add<TrackArr>(tracks_,mitName_.c_str());
52   }
53  
54   //--------------------------------------------------------------------------------------------------
# Line 51 | Line 57 | void FillerTracks::FillDataBlock(const e
57   {
58    // Fill tracks from edm collection into our collection.
59  
60 <  tracks_->Reset();
60 >  tracks_  ->Reset();
61    trackMap_->Reset();
62  
63    Handle<reco::TrackCollection> hTrackProduct;
# Line 60 | Line 66 | void FillerTracks::FillDataBlock(const e
66    trackMap_->SetEdmProductId(hTrackProduct.id().id());
67    const reco::TrackCollection inTracks = *(hTrackProduct.product());  
68    
69 <  // if we have a Sim Particle association (for monte carlo), initialize the reco->sim mappings
69 >  // for MC SimParticle association (reco->sim mappings)
70    reco::RecoToSimCollection simAssociation;
71    if (simMap_ && !edmSimAssociationName_.empty()) {
72      Handle<reco::RecoToSimCollection> simAssociationProduct;
# Line 68 | Line 74 | void FillerTracks::FillDataBlock(const e
74      simAssociation = *(simAssociationProduct.product());
75    }
76    
77 <  // loop through all tracks
78 <  for (reco::TrackCollection::const_iterator inTrack = inTracks.begin();
79 <       inTrack != inTracks.end(); ++inTrack) {
74 <    
77 >  // loop through all tracks and fill the information
78 >  for (reco::TrackCollection::const_iterator it = inTracks.begin();
79 >       it != inTracks.end(); ++it) {
80      mithep::Track *outTrack = tracks_->Allocate();
81 <    new (outTrack) mithep::Track(inTrack->phi(),
82 <                                 inTrack->d0(),
83 <                                 inTrack->pt(),
84 <                                 inTrack->dz(),
80 <                                 inTrack->theta());
81 <        
82 <    outTrack->SetErrors(inTrack->phiError(),
83 <                        inTrack->d0Error(),
84 <                        inTrack->ptError(),
85 <                        inTrack->dzError(),
86 <                        inTrack->thetaError());
87 <
88 <    outTrack->SetCharge(inTrack->charge());
81 >    // 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          
86      // add reference between mithep and edm object
87 <    reco::TrackRef theRef(hTrackProduct, inTrack-inTracks.begin());
87 >    reco::TrackRef theRef(hTrackProduct, it - inTracks.begin());
88      trackMap_->Add(theRef, outTrack);
89          
90      if (simMap_ && !edmSimAssociationName_.empty()) {
91        reco::TrackBaseRef theBaseRef(theRef);
92        vector<pair<TrackingParticleRef, double> > simRefs;
93 <      Bool_t noSimParticle=0;
93 >      Bool_t noSimParticle = 0;
94        try {
95          simRefs = simAssociation[theBaseRef]; //try to get the sim references if existing
96        }
97        catch (edm::Exception &ex) {
98 <        noSimParticle=1;
98 >        noSimParticle = 1;
99        }
100 +
101        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 <          if ( simRefPair->second > 0.5 ) // require more than 50% shared hits between reco and sim
106 <            outTrack->SetSimParticle(simMap_->GetMit(simRefPair->first)); //add reco->sim reference
105 >          if (simRefPair->second > 0.5) // require more than 50% shared hits between reco and sim
106 >            outTrack->SetMCPart(simMap_->GetMit(simRefPair->first)); //add reco->sim reference
107        }
108      }
109    }
113
110    tracks_->Trim();
111   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines