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.6 by loizides, Tue Jul 8 12:38:20 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 < //-------------------------------------------------------------------------------------------------
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","")),
22    mitName_(Conf().getUntrackedParameter<string>("mitName","")),
23    edmSimAssociationName_(Conf().getUntrackedParameter<string>("edmSimAssociationName","")),
24    simMap_(sm),
# Line 31 | Line 28 | FillerTracks::FillerTracks(const Paramet
28    // Constructor.
29   }
30  
31 < //-------------------------------------------------------------------------------------------------
31 > //--------------------------------------------------------------------------------------------------
32   FillerTracks::~FillerTracks()
33   {
34    // Destructor.
35  
36 +  delete tracks_;
37    delete trackMap_;
38   }
39  
40 < //-------------------------------------------------------------------------------------------------
40 > //--------------------------------------------------------------------------------------------------
41   void FillerTracks::BookDataBlock(TreeWriter &tws)
42   {
43    // Add tracks branch to tree.
# Line 47 | Line 45 | void FillerTracks::BookDataBlock(TreeWri
45    tws.AddBranch(mitName_.c_str(),&tracks_);
46   }
47  
48 < //-------------------------------------------------------------------------------------------------
48 > //--------------------------------------------------------------------------------------------------
49   void FillerTracks::FillDataBlock(const edm::Event      &event,
50                                   const edm::EventSetup &setup)
51   {
# Line 55 | Line 53 | void FillerTracks::FillDataBlock(const e
53  
54    tracks_->Reset();
55    trackMap_->Reset();
56 <  
57 <  // get the tracks collection
58 <  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 <  }
56 >
57 >  Handle<reco::TrackCollection> hTrackProduct;
58 >  GetProduct(edmName_, hTrackProduct, event);  
59          
60 <  trackMap_->SetEdmProductId(trackProduct_.id().id());
61 <  const reco::TrackCollection inTracks = *(trackProduct_.product());  
60 >  trackMap_->SetEdmProductId(hTrackProduct.id().id());
61 >  const reco::TrackCollection inTracks = *(hTrackProduct.product());  
62    
63    // if we have a Sim Particle association (for monte carlo), initialize the reco->sim mappings
64    reco::RecoToSimCollection simAssociation;
65    if (simMap_ && !edmSimAssociationName_.empty()) {
66      Handle<reco::RecoToSimCollection> simAssociationProduct;
67 <    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 <    }
67 >    GetProduct(edmSimAssociationName_, simAssociationProduct, event);  
68      simAssociation = *(simAssociationProduct.product());
69    }
70    
# Line 92 | Line 72 | void FillerTracks::FillDataBlock(const e
72    for (reco::TrackCollection::const_iterator inTrack = inTracks.begin();
73         inTrack != inTracks.end(); ++inTrack) {
74      
75 <    mithep::Track* outTrack = tracks_->Allocate();
76 <    new (outTrack) mithep::Track(inTrack->phi(),inTrack->d0(),inTrack->pt(),inTrack->dz(),inTrack->theta());
77 <        
75 >    mithep::Track *outTrack = tracks_->Allocate();
76 >    new (outTrack) mithep::Track(inTrack->phi(),
77 >                                 inTrack->d0(),
78 >                                 inTrack->pt(),
79 >                                 inTrack->dz(),
80 >                                 inTrack->theta());
81          
82      outTrack->SetErrors(inTrack->phiError(),
83                          inTrack->d0Error(),
# Line 105 | Line 88 | void FillerTracks::FillDataBlock(const e
88      outTrack->SetCharge(inTrack->charge());
89          
90      // add reference between mithep and edm object
91 <    reco::TrackRef theRef(trackProduct_, inTrack-inTracks.begin());
91 >    reco::TrackRef theRef(hTrackProduct, inTrack-inTracks.begin());
92      trackMap_->Add(theRef, outTrack);
93          
94      if (simMap_ && !edmSimAssociationName_.empty()) {
# Line 115 | Line 98 | void FillerTracks::FillDataBlock(const e
98        try {
99          simRefs = simAssociation[theBaseRef]; //try to get the sim references if existing
100        }
101 <      catch (edm::Exception& ex) {
101 >      catch (edm::Exception &ex) {
102          noSimParticle=1;
103        }
104        if (!noSimParticle) { //loop through sim match candidates

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines