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.2 by loizides, Tue Jul 1 21:11:47 2008 UTC vs.
Revision 1.13 by loizides, Thu Jul 31 12:34:04 2008 UTC

# Line 8 | Line 8
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"
11   #include "MitAna/DataTree/interface/Names.h"
12  
13   using namespace std;
14   using namespace edm;
15   using namespace mithep;
16  
17 < //-------------------------------------------------------------------------------------------------
18 < FillerTracks::FillerTracks(const ParameterSet &cfg, const char *name,
19 <                           bool active, const SimParticleMap *sm) :
20 <  BaseFiller(cfg, name, active),
21 <  edmName_(Conf().getUntrackedParameter<string>("edmName","")),
24 <  edmDataName_(Conf().getUntrackedParameter<string>("edmDataName","")),
25 <  mitName_(Conf().getUntrackedParameter<string>("mitName","")),
17 > //--------------------------------------------------------------------------------------------------
18 > FillerTracks::FillerTracks(const ParameterSet &cfg, const char *name, bool active) :
19 >  BaseFiller(cfg,name,active),
20 >  edmName_(Conf().getUntrackedParameter<string>("edmName","generalTracks")),
21 >  mitName_(Conf().getUntrackedParameter<string>("mitName",Names::gkTrackBrn)),
22    edmSimAssociationName_(Conf().getUntrackedParameter<string>("edmSimAssociationName","")),
23 <  simMap_(sm),
24 <  tracks_(new mithep::TrackArr),
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   {
30    // Constructor.
31   }
32  
33 < //-------------------------------------------------------------------------------------------------
33 > //--------------------------------------------------------------------------------------------------
34   FillerTracks::~FillerTracks()
35   {
36    // Destructor.
37  
38 +  delete tracks_;
39    delete trackMap_;
40   }
41  
42 < //-------------------------------------------------------------------------------------------------
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 < //-------------------------------------------------------------------------------------------------
54 > //--------------------------------------------------------------------------------------------------
55   void FillerTracks::FillDataBlock(const edm::Event      &event,
56                                   const edm::EventSetup &setup)
57   {
58    // Fill tracks from edm collection into our collection.
59  
60 <  tracks_->Reset();
60 >  tracks_  ->Reset();
61    trackMap_->Reset();
62 <  
63 <  // get the tracks collection
64 <  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 <  }
62 >
63 >  Handle<reco::TrackCollection> hTrackProduct;
64 >  GetProduct(edmName_, hTrackProduct, event);  
65          
66 <  trackMap_->SetEdmProductId(trackProduct_.id().id());
67 <  const reco::TrackCollection inTracks = *(trackProduct_.product());  
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;
73 <    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 <    }
73 >    GetProduct(edmSimAssociationName_, simAssociationProduct, event);  
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) {
80 <    
81 <    mithep::Track* outTrack = tracks_->Allocate();
82 <    new (outTrack) mithep::Track(inTrack->phi(),inTrack->d0(),inTrack->pt(),inTrack->dz(),inTrack->theta());
83 <        
84 <        
99 <    outTrack->SetErrors(inTrack->phiError(),
100 <                        inTrack->d0Error(),
101 <                        inTrack->ptError(),
102 <                        inTrack->dzError(),
103 <                        inTrack->thetaError());
104 <
105 <    outTrack->SetCharge(inTrack->charge());
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 >    // 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(trackProduct_, 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;
97 >      catch (edm::Exception &ex) {
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    }
130
110    tracks_->Trim();
111   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines