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.3 by bendavid, Wed Jul 2 13:30:09 2008 UTC vs.
Revision 1.22 by bendavid, Thu Oct 16 16:17:17 2008 UTC

# Line 3 | Line 3
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/HitPattern.h"
7   #include "DataFormats/TrackReco/interface/Track.h"
8   #include "DataFormats/TrackReco/interface/TrackFwd.h"
9   #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h"
10   #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticleFwd.h"
11   #include "DataFormats/RecoCandidate/interface/TrackAssociation.h"
12  
12 #include "MitAna/DataTree/interface/Track.h"
13 #include "MitAna/DataTree/interface/Names.h"
14
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","")),
22 <  mitName_(Conf().getUntrackedParameter<string>("mitName","")),
23 <  edmSimAssociationName_(Conf().getUntrackedParameter<string>("edmSimAssociationName","")),
24 <  simMap_(sm),
25 <  tracks_(new mithep::TrackArr),
17 > //--------------------------------------------------------------------------------------------------
18 > FillerTracks::FillerTracks(const ParameterSet &cfg, const char *name, bool active,
19 >                           const char *edmName, const char *mitName) :
20 >  BaseFiller(cfg,name,active),
21 >  edmName_(Conf().getUntrackedParameter<string>("edmName",edmName)),
22 >  mitName_(Conf().getUntrackedParameter<string>("mitName",mitName)),
23 >  edmSimAssocName_(Conf().getUntrackedParameter<string>("edmSimAssociationName","")),
24 >  trackingMapName_(Conf().getUntrackedParameter<string>("trackingMapName","TrackingMap")),
25 >  trackMapName_(Conf().getUntrackedParameter<string>("trackMapName",
26 >                                                     Form("%sMapName",mitName_.c_str()))),
27 >  trackingMap_(0),
28 >  tracks_(new mithep::TrackArr(250)),
29    trackMap_(new mithep::TrackMap)
30   {
31    // Constructor.
32   }
33  
34 < //-------------------------------------------------------------------------------------------------
34 > //--------------------------------------------------------------------------------------------------
35   FillerTracks::~FillerTracks()
36   {
37    // Destructor.
38  
39 +  delete tracks_;
40    delete trackMap_;
41   }
42  
43 < //-------------------------------------------------------------------------------------------------
43 > //--------------------------------------------------------------------------------------------------
44   void FillerTracks::BookDataBlock(TreeWriter &tws)
45   {
46 <  // Add tracks branch to tree.
46 >  // Add tracks branch to tree, publish and get our objects.
47  
48    tws.AddBranch(mitName_.c_str(),&tracks_);
49 +
50 +  trackingMap_ = OS()->get<TrackingParticleMap>(trackingMapName_.c_str());
51 +  OS()->add<TrackMap>(trackMap_,trackMapName_.c_str());
52 +  OS()->add<TrackArr>(tracks_,mitName_.c_str());
53   }
54  
55 < //-------------------------------------------------------------------------------------------------
55 > //--------------------------------------------------------------------------------------------------
56   void FillerTracks::FillDataBlock(const edm::Event      &event,
57                                   const edm::EventSetup &setup)
58   {
59    // Fill tracks from edm collection into our collection.
60  
61 <  tracks_->Reset();
61 >  tracks_  ->Reset();
62    trackMap_->Reset();
63 <  
64 <  // get the tracks collection
65 <  try {
60 <    event.getByLabel(edm::InputTag(edmName_),trackProduct_);
61 <  } catch (cms::Exception& ex) {
62 <    edm::LogError("FillerTracks") << "Error! Cannot get collection with label "
63 <                                  << edmName_ << endl;
64 <    throw edm::Exception(edm::errors::Configuration, "FillerTracks:FillDataBlock()\n")
65 <      << "Error! Cannot get collection with label " << edmName_ << endl;
66 <  }
63 >
64 >  Handle<reco::TrackCollection> hTrackProduct;
65 >  GetProduct(edmName_, hTrackProduct, event);  
66          
67 <  trackMap_->SetEdmProductId(trackProduct_.id().id());
68 <  const reco::TrackCollection inTracks = *(trackProduct_.product());  
67 >  trackMap_->SetEdmProductId(hTrackProduct.id().id());
68 >  const reco::TrackCollection inTracks = *(hTrackProduct.product());  
69    
70 <  // if we have a Sim Particle association (for monte carlo), initialize the reco->sim mappings
70 >  // for MC SimParticle association (reco->sim mappings)
71    reco::RecoToSimCollection simAssociation;
72 <  if (simMap_ && !edmSimAssociationName_.empty()) {
72 >  if (trackingMap_ && !edmSimAssocName_.empty()) {
73      Handle<reco::RecoToSimCollection> simAssociationProduct;
74 <    try {
76 <      event.getByLabel(edm::InputTag(edmSimAssociationName_), simAssociationProduct);
77 <    }
78 <    catch (cms::Exception& ex) {
79 <      edm::LogError("FillerTracks") << "Error! Cannot get collection with label "
80 <                                    << edmSimAssociationName_ << endl;
81 <      throw edm::Exception(edm::errors::Configuration, "FillerTracks:FillDataBlock()\n")
82 <        << "Error! Cannot get collection with label " << edmSimAssociationName_ << endl;
83 <    }
74 >    GetProduct(edmSimAssocName_, simAssociationProduct, event);  
75      simAssociation = *(simAssociationProduct.product());
76 +    //printf("SimAssociation Map Size = %i\n",simAssociation.size());
77    }
78    
79 <  // loop through all tracks
80 <  for (reco::TrackCollection::const_iterator inTrack = inTracks.begin();
81 <       inTrack != inTracks.end(); ++inTrack) {
82 <    
83 <    mithep::Track* outTrack = tracks_->Allocate();
84 <    new (outTrack) mithep::Track(inTrack->phi(),inTrack->d0(),inTrack->pt(),inTrack->dz(),inTrack->theta());
85 <        
86 <        
87 <    outTrack->SetErrors(inTrack->phiError(),
96 <                        inTrack->d0Error(),
97 <                        inTrack->ptError(),
98 <                        inTrack->dzError(),
99 <                        inTrack->thetaError());
100 <
101 <    outTrack->SetCharge(inTrack->charge());
79 >  // loop through all tracks and fill the information
80 >  for (reco::TrackCollection::const_iterator it = inTracks.begin();
81 >       it != inTracks.end(); ++it) {
82 >    mithep::Track *outTrack = tracks_->Allocate();
83 >    // create track and set the core parameters
84 >    new (outTrack) mithep::Track(it->qoverp(),it->lambda(),
85 >                                 it->phi(),it->dxy(),it->dsz());
86 >    outTrack->SetErrors(it->qoverpError(),it->lambdaError(),
87 >                        it->phiError(),it->dxyError(),it->dszError());
88          
89 +    // fill track quality information
90 +    outTrack->SetChi2(it->chi2());
91 +    outTrack->SetNdof(static_cast<Int_t>(it->ndof()));
92 +    
93 +    //fill hit layer map
94 +    const reco::HitPattern &hits = it->hitPattern();
95 +    for (Int_t i=0; i<hits.numberOfHits(); i++) {
96 +      uint32_t hit = hits.getHitPattern(i);
97 +      if (hits.validHitFilter(hit))
98 +        if (hits.trackerHitFilter(hit))
99 +          outTrack->SetHit(hitReader_.Layer(hit));
100 +                
101 +      if (0) {
102 +        if (hits.muonDTHitFilter(hit))
103 +          printf("Muon DT Layer = %i\n", hits.getLayer(hit));
104 +        if (hits.muonCSCHitFilter(hit))
105 +          printf("Muon CSC Layer = %i\n", hits.getLayer(hit));        
106 +        if (hits.muonRPCHitFilter(hit))
107 +          printf("Muon RPC Layer = %i\n", hits.getLayer(hit));
108 +      }
109 +    }
110 +    
111      // add reference between mithep and edm object
112 <    reco::TrackRef theRef(trackProduct_, inTrack-inTracks.begin());
112 >    reco::TrackRef theRef(hTrackProduct, it - inTracks.begin());
113      trackMap_->Add(theRef, outTrack);
114          
115 <    if (simMap_ && !edmSimAssociationName_.empty()) {
115 >    if (trackingMap_ && !edmSimAssocName_.empty()) {
116 >      //printf("Trying Track-Sim association\n");
117        reco::TrackBaseRef theBaseRef(theRef);
118        vector<pair<TrackingParticleRef, double> > simRefs;
119 <      Bool_t noSimParticle=0;
119 >      Bool_t noSimParticle = 0;
120        try {
121          simRefs = simAssociation[theBaseRef]; //try to get the sim references if existing
122        }
123 <      catch (edm::Exception& ex) {
124 <        noSimParticle=1;
123 >      catch (edm::Exception &ex) {
124 >        noSimParticle = 1;
125        }
126 +
127        if (!noSimParticle) { //loop through sim match candidates
128 +        //printf("Applying track-sim association\n");
129          for (vector<pair<TrackingParticleRef, double> >::const_iterator simRefPair=simRefs.begin();
130               simRefPair != simRefs.end(); ++simRefPair)
131  
132 <          if ( simRefPair->second > 0.5 ) // require more than 50% shared hits between reco and sim
133 <            outTrack->SetSimParticle(simMap_->GetMit(simRefPair->first)); //add reco->sim reference
132 >          if (simRefPair->second > 0.5) // require more than 50% shared hits between reco and sim
133 >            outTrack->SetMCPart(trackingMap_->GetMit(simRefPair->first)); //add reco->sim reference
134        }
135      }
136    }
126
137    tracks_->Trim();
138   }
139 +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines