ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/src/FillerVertexes.cc
Revision: 1.11
Committed: Fri Sep 23 15:53:30 2011 UTC (13 years, 7 months ago) by mhchan
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_032, Mit_031, Mit_025c_branch2, Mit_025c_branch1, Mit_030, Mit_029c, Mit_029b, Mit_030_pre1, Mit_029a, Mit_029, Mit_029_pre1, Mit_028a, Mit_025c_branch0, Mit_028, Mit_027a, Mit_027, Mit_026, Mit_025e, Mit_025d, Mit_025c, Mit_025b, Mit_025a, Mit_025, Mit_025pre2, HEAD
Branch point for: Mit_025c_branch
Changes since 1.10: +2 -2 lines
Log Message:
Added track weights

File Contents

# Content
1 // $Id: FillerVertexes.cc,v 1.10 2010/10/20 20:34:27 bendavid Exp $
2
3 #include "MitProd/TreeFiller/interface/FillerVertexes.h"
4 #include "DataFormats/VertexReco/interface/Vertex.h"
5 #include "DataFormats/VertexReco/interface/VertexFwd.h"
6 #include "MitAna/DataTree/interface/Names.h"
7 #include "MitAna/DataTree/interface/VertexCol.h"
8 #include "MitProd/ObjectService/interface/ObjectService.h"
9 #include "MitEdm/DataFormats/interface/RefToBaseToPtr.h"
10
11 using namespace std;
12 using namespace edm;
13 using namespace mithep;
14
15 //--------------------------------------------------------------------------------------------------
16 FillerVertexes::FillerVertexes(const ParameterSet &cfg, const char *name, bool active) :
17 BaseFiller(cfg,name,active),
18 edmName_(Conf().getUntrackedParameter<string>("edmName","offlinePrimaryVertices")),
19 mitName_(Conf().getUntrackedParameter<string>("mitName","PrimaryVertexes")),
20 trackMapName_(Conf().getUntrackedParameter<string>("trackMapName","")),
21 vertexMapName_(Conf().getUntrackedParameter<string>("vertexMapName","VertexMap")),
22 vertexes_(new mithep::VertexArr(100)),
23 vertexMap_(new mithep::VertexMap),
24 trackMap_(0)
25 {
26 // Constructor.
27 }
28
29 //--------------------------------------------------------------------------------------------------
30 FillerVertexes::~FillerVertexes()
31 {
32 // Destructor.
33
34 delete vertexes_;
35 delete vertexMap_;
36 }
37
38 //--------------------------------------------------------------------------------------------------
39 void FillerVertexes::BookDataBlock(TreeWriter &tws)
40 {
41 // Add Vertex branch and the VertexMap to tree.
42
43 tws.AddBranch(mitName_,&vertexes_);
44 OS()->add<VertexArr>(vertexes_,mitName_);
45
46 if (!vertexMapName_.empty()) {
47 vertexMap_->SetBrName(mitName_);
48 OS()->add<VertexMap>(vertexMap_,vertexMapName_);
49 }
50 if (!trackMapName_.empty()) {
51 trackMap_ = OS()->get<TrackMap>(trackMapName_);
52 if (trackMap_)
53 AddBranchDep(mitName_,trackMap_->GetBrName());
54 }
55 }
56
57 //--------------------------------------------------------------------------------------------------
58 void FillerVertexes::FillDataBlock(const edm::Event &event,
59 const edm::EventSetup &setup)
60 {
61 // Fill the Vertex branch.
62
63 vertexes_->Delete();
64 vertexMap_->Reset();
65
66 Handle<reco::VertexCollection> hVertexProduct;
67 GetProduct(edmName_, hVertexProduct, event);
68 vertexMap_->SetEdmProductId(hVertexProduct.id().id());
69 const reco::VertexCollection inVertexes = *(hVertexProduct.product());
70
71 // loop through all vertexes
72 for (reco::VertexCollection::const_iterator inV = inVertexes.begin();
73 inV != inVertexes.end(); ++inV) {
74
75 mithep::Vertex *outVertex = vertexes_->Allocate();
76 new (outVertex) mithep::Vertex(inV->x(), inV->y(), inV->z(),
77 inV->xError(), inV->yError(), inV->zError());
78 outVertex->SetChi2(inV->chi2());
79 outVertex->SetIsValid(inV->isValid());
80 outVertex->SetNdof(inV->ndof());
81 outVertex->SetNTracksFit(inV->tracksSize());
82
83 //fill tracks associated to the vertex
84 if (trackMap_) {
85 for (reco::Vertex::trackRef_iterator iTrack = inV->tracks_begin(); iTrack!=inV->tracks_end(); ++iTrack) {
86 outVertex->AddTrack(trackMap_->GetMit(mitedm::refToBaseToPtr(*iTrack)), inV->trackWeight(*iTrack));
87 }
88 }
89
90 //add vertex to the map
91 mitedm::VertexPtr thePtr(hVertexProduct, inV-inVertexes.begin());
92 vertexMap_->Add(thePtr, outVertex);
93
94 }
95 vertexes_->Trim();
96 }