CMS 3D CMS Logo

L1RecoTreeProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: L1Trigger/L1TNtuples
4 // Class: L1RecoTreeProducer
5 //
11 // system include files
12 #include <memory>
13 
14 // framework
23 
24 // ROOT output stuff
27 #include "TH1.h"
28 #include "TTree.h"
29 #include "TF1.h"
30 
31 // EDM formats
34 
35 //local data formats
37 
38 
39 //
40 // class declaration
41 //
42 
44 public:
45  explicit L1RecoTreeProducer(const edm::ParameterSet&);
47 
48 
49 private:
50  virtual void beginJob(void) ;
51  virtual void analyze(const edm::Event&, const edm::EventSetup&);
52  virtual void endJob();
53 
54 public:
56 
57 private:
58 
59  // output file
61 
62  // tree
63  TTree * tree_;
64 
65  // EDM input tags
67 
68  unsigned int maxVtx_;
69 
70 };
71 
72 
73 
75 {
76 
77  vtxToken_ = consumes<reco::VertexCollection>(iConfig.getUntrackedParameter("vtxToken",edm::InputTag("offlinePrimaryVertices")));
78 
79  maxVtx_ = iConfig.getParameter<unsigned int>("maxVtx");
80 
82 
83  // set up output
84  tree_=fs_->make<TTree>("RecoTree", "RecoTree");
85  tree_->Branch("Vertex", "L1Analysis::L1AnalysisRecoVertexDataFormat", &vtxData_, 32000, 3);
86 
87 }
88 
89 
91 {
92 
93  // do anything here that needs to be done at desctruction time
94  // (e.g. close files, deallocate resources etc.)
95 
96 }
97 
98 
99 //
100 // member functions
101 //
102 
103 // ------------ method called to for each event ------------
105 {
106 
107  vtxData_->Reset();
108 
109  // get vertices
111  iEvent.getByToken(vtxToken_, vertices);
112 
113  if (vertices.isValid()) {
114 
115  for(reco::VertexCollection::const_iterator it=vertices->begin();
116  it!=vertices->end() && vtxData_->nVtx < maxVtx_;
117  ++it) {
118 
119  if (!it->isFake()) {
120  vtxData_->NDoF.push_back(it->ndof());
121  vtxData_->Z.push_back(it->z());
122  vtxData_->Rho.push_back(it->position().rho());
123  vtxData_->nVtx++;
124  }
125 
126  }
127  tree_->Fill();
128  }
129 
130 }
131 
132 
133 // ------------ method called once each job just before starting event loop ------------
134 void
136 {
137 }
138 
139 // ------------ method called once each job just after ending the event loop ------------
140 void
142 }
143 
144 //define this as a plug-in
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
L1Analysis::L1AnalysisRecoVertexDataFormat * vtxData_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
L1RecoTreeProducer(const edm::ParameterSet &)
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
int iEvent
Definition: GenABIO.cc:230
virtual void beginJob(void)
bool isValid() const
Definition: HandleBase.h:74
edm::EDGetTokenT< reco::VertexCollection > vtxToken_
edm::Service< TFileService > fs_
virtual void analyze(const edm::Event &, const edm::EventSetup &)