ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/src/FillerVertexes.cc
Revision: 1.6
Committed: Fri Sep 25 08:42:51 2009 UTC (15 years, 7 months ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_011a
Changes since 1.5: +2 -2 lines
Log Message:
Extended interface of BookDataBlock to contain event setup.

File Contents

# User Rev Content
1 loizides 1.6 // $Id: FillerVertexes.cc,v 1.5 2009/06/15 15:00:26 loizides Exp $
2 bendavid 1.1
3     #include "MitProd/TreeFiller/interface/FillerVertexes.h"
4     #include "DataFormats/VertexReco/interface/Vertex.h"
5     #include "DataFormats/VertexReco/interface/VertexFwd.h"
6 loizides 1.5 #include "MitAna/DataTree/interface/Names.h"
7     #include "MitAna/DataTree/interface/VertexCol.h"
8     #include "MitProd/ObjectService/interface/ObjectService.h"
9 bendavid 1.1
10     using namespace std;
11     using namespace edm;
12     using namespace mithep;
13    
14     //--------------------------------------------------------------------------------------------------
15     FillerVertexes::FillerVertexes(const ParameterSet &cfg, const char *name, bool active) :
16     BaseFiller(cfg,name,active),
17 loizides 1.2 edmName_(Conf().getUntrackedParameter<string>("edmName","PrimaryVertexes")),
18 bendavid 1.1 mitName_(Conf().getUntrackedParameter<string>("mitName","PrimaryVertexes")),
19 loizides 1.4 vertexMapName_(Conf().getUntrackedParameter<string>("vertexMapName","VertexMap")),
20 bendavid 1.1 vertexes_(new mithep::VertexArr(100)),
21     vertexMap_(new mithep::VertexMap)
22     {
23     // Constructor.
24     }
25    
26     //--------------------------------------------------------------------------------------------------
27     FillerVertexes::~FillerVertexes()
28     {
29     // Destructor.
30    
31     delete vertexes_;
32     delete vertexMap_;
33     }
34    
35     //--------------------------------------------------------------------------------------------------
36 loizides 1.6 void FillerVertexes::BookDataBlock(TreeWriter &tws, const edm::EventSetup &es)
37 bendavid 1.1 {
38     // Add Vertex branch and the VertexMap to tree.
39    
40 loizides 1.4 tws.AddBranch(mitName_,&vertexes_);
41     OS()->add<VertexArr>(vertexes_,mitName_);
42 bendavid 1.1
43 loizides 1.4 if (!vertexMapName_.empty()) {
44     vertexMap_->SetBrName(mitName_);
45     OS()->add<VertexMap>(vertexMap_,vertexMapName_);
46     }
47 bendavid 1.1 }
48    
49     //--------------------------------------------------------------------------------------------------
50     void FillerVertexes::FillDataBlock(const edm::Event &event,
51 loizides 1.2 const edm::EventSetup &setup)
52 bendavid 1.1 {
53 loizides 1.2 // Fill the Vertex branch.
54 bendavid 1.1
55 bendavid 1.3 vertexes_->Delete();
56 bendavid 1.1 vertexMap_->Reset();
57    
58     Handle<reco::VertexCollection> hVertexProduct;
59     GetProduct(edmName_, hVertexProduct, event);
60     vertexMap_->SetEdmProductId(hVertexProduct.id().id());
61     const reco::VertexCollection inVertexes = *(hVertexProduct.product());
62    
63     // loop through all vertexes
64     for (reco::VertexCollection::const_iterator inV = inVertexes.begin();
65     inV != inVertexes.end(); ++inV) {
66    
67     mithep::Vertex *outVertex = vertexes_->Allocate();
68     new (outVertex) mithep::Vertex(inV->x(), inV->y(), inV->z(),
69     inV->xError(), inV->yError(), inV->zError());
70     outVertex->SetChi2(inV->chi2());
71 loizides 1.2 outVertex->SetNdof(static_cast<Int_t>(inV->ndof()));
72 bendavid 1.1 outVertex->SetNTracks(inV->tracksSize());
73    
74     //add vertex to the map
75     mitedm::VertexPtr thePtr(hVertexProduct, inV-inVertexes.begin());
76     vertexMap_->Add(thePtr, outVertex);
77 loizides 1.4
78 bendavid 1.1 }
79     vertexes_->Trim();
80     }