-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMiniAnalyzer.cc
More file actions
201 lines (159 loc) · 5.79 KB
/
MiniAnalyzer.cc
File metadata and controls
201 lines (159 loc) · 5.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
// -*- C++ -*-
//
// Package: Test/MiniAnalyzer
// Class: MiniAnalyzer
//
/**\class MiniAnalyzer MiniAnalyzer.cc Test/MiniAnalyzer/plugins/MiniAnalyzer.cc
Description: [one line class summary]
Implementation:
[Notes on implementation]
*/
//
// Original Author:
// Created: Thu, 01 Feb 2024 02:16:09 GMT
//
//
// system include files
#include <memory>
// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "CommonTools/UtilAlgos/interface/TFileService.h"
#include "TH1.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "DataFormats/PatCandidates/interface/Jet.h"
#include "DataFormats/Candidate/interface/VertexCompositePtrCandidate.h"
#include "DataFormats/Candidate/interface/LeafCandidate.h"
#include "DataFormats/Math/interface/LorentzVector.h"
#include "DataFormats/VertexReco/interface/VertexFwd.h"
#include "DataFormats/VertexReco/interface/Vertex.h"
#include "DataFormats/GeometryVector/interface/GlobalPoint.h"
#include "DataFormats/BeamSpot/interface/BeamSpot.h"
// ROOT includes
#include "TTree.h"
#include <TFile.h>
#include <TROOT.h>
#include "TBranch.h"
#include <string>
#include <vector>
#include "TSystem.h"
#include "TVector3.h"
#include "TLorentzVector.h"
//
// class declaration
//
class MiniAnalyzer : public edm::one::EDAnalyzer<edm::one::SharedResources> {
public:
explicit MiniAnalyzer(const edm::ParameterSet&);
~MiniAnalyzer();
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
private:
virtual void beginJob() override;
virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
virtual void endJob() override;
// ----------member data ---------------------------
edm::EDGetTokenT<reco::VertexCollection> vtxToken_;
edm::EDGetTokenT<std::vector<reco::VertexCompositePtrCandidate>> secondaryVertexToken_;
TTree *tree;
edm::RunNumber_t irun;
edm::EventNumber_t ievent;
edm::LuminosityBlockNumber_t ilumiblock;
edm::Timestamp itime;
size_t run, event, lumi, time;
unsigned int npv;
unsigned int nsv;
float svPt;
float svX;
float svY;
float svZ;
float svNormalizedChi2;
float svChi2;
float svEta;
float svMass;
int svNumDaughters;
float svDxyError;
float svDxy;
float svNdf;
};
//
// constructors and destructor
//
MiniAnalyzer::MiniAnalyzer(const edm::ParameterSet& iConfig)
: vtxToken_(consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("vertices"))),
secondaryVertexToken_(consumes<std::vector<reco::VertexCompositePtrCandidate>>(iConfig.getParameter<edm::InputTag>("secondaryVertices")))
{
usesResource("TFileService");
edm::Service<TFileService> file;
tree = file->make<TTree>("tree","For QCD File");
tree->Branch("npv", &npv, "npv/i");
tree->Branch("nsv", &nsv, "nsv/i");
tree->Branch("svPt", &svPt, "svPt/F");
tree->Branch("svX", &svX, "svX/F");
tree->Branch("svY", &svY, "svY/F");
tree->Branch("svZ", &svZ, "svZ/F");
tree->Branch("svNormalizedChi2", &svNormalizedChi2, "svNormalizedChi2/F");
tree->Branch("svChi2", &svChi2, "svChi2/F");
tree->Branch("svEta", &svEta, "svEta/F");
tree->Branch("svMass", &svMass, "svMass/F");
tree->Branch("svNumDaughters", &svNumDaughters, "svNumDaughters/I");
tree->Branch("svDxyError", &svDxyError, "svDxyError/F");
tree->Branch("svDxy", &svDxy, "svDxy/F");
tree->Branch("svNdf", &svNdf, "svNdf/F");
}
MiniAnalyzer::~MiniAnalyzer() {}
//
// member functions
//
void MiniAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
{
using namespace edm;
edm::Handle<reco::VertexCollection> vertices;
iEvent.getByToken(vtxToken_, vertices);
if (vertices->empty()) return;
edm::Handle<std::vector<reco::VertexCompositePtrCandidate>> secondaryVertices;
iEvent.getByToken(secondaryVertexToken_, secondaryVertices);
irun = iEvent.id().run();
ievent = iEvent.id().event();
ilumiblock = iEvent.id().luminosityBlock();
itime = iEvent.time();
run = static_cast<size_t>(irun);
event = static_cast<size_t>(ievent);
lumi = static_cast<size_t>(ilumiblock);
time = static_cast<size_t>((iEvent.time().value()) >> 32);
npv = vertices->size();
nsv = secondaryVertices->size();
if (nsv == 0) return;
const reco::Vertex& primaryVertex = vertices->front(); //to get only the frst vertex
const auto& sv = secondaryVertices->front();
svPt = sv.pt();
svX = sv.vertex().x();
svY = sv.vertex().y();
svZ = sv.vertex().z();
svNormalizedChi2 = sv.vertexNormalizedChi2();
svChi2 = sv.vertexChi2();
svEta = sv.eta();
svMass = sv.mass();
svNumDaughters = sv.numberOfDaughters();
svDxyError = sv.dxyError();
svNdf = sv.vertexNdof();
// Calculating dxy
GlobalPoint svPosition(sv.vertex().x(), sv.vertex().y(), sv.vertex().z());
GlobalPoint pvPosition(primaryVertex.position().x(), primaryVertex.position().y(), primaryVertex.position().z());
double dx = svPosition.x() - pvPosition.x();
double dy = svPosition.y() - pvPosition.y();
svDxy = std::sqrt(dx * dx + dy * dy);
tree->Fill();
}
void MiniAnalyzer::beginJob() {}
void MiniAnalyzer::endJob() {}
void MiniAnalyzer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.add<edm::InputTag>("vertices", edm::InputTag("offlinePrimaryVertices"));
desc.add<edm::InputTag>("secondaryVertices", edm::InputTag("inclusiveSecondaryVertices"));
descriptions.add("miniAnalyzer", desc);
}
DEFINE_FWK_MODULE(MiniAnalyzer);