ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/src/FillerVertexes.cc
Revision: 1.9
Committed: Thu Mar 18 20:21:01 2010 UTC (15 years, 1 month ago) by bendavid
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_015, Mit_014e, Mit_014d, Mit_014c, Mit_014b, Mit_014a, Mit_014, Mit_014pre3, Mit_014pre2, Mit_014pre1, Mit_013d, Mit_013c, Mit_013b, Mit_013a, Mit_013
Changes since 1.8: +2 -2 lines
Log Message:
Fix beginrun,beginjob mess

File Contents

# Content
1 // $Id: FillerVertexes.cc,v 1.8 2009/12/11 17:45:38 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(static_cast<Int_t>(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)));
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 }