Thanks a lot for sharing that.
I am sharing the cc file, just in case.
(base) rathodswasti@Swastis-Laptop14:~/cms_open_data_work/CMSSW_10_6_30/src/Test/MiniAnalyzer/plugins$ cat MiniAnalyzer.cc
// -*- 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: Swasti
// 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;
std::vector<float> svPt;
std::vector<float> svX;
std::vector<float> svY;
std::vector<float> svZ;
std::vector<float> svNormalizedChi2;
std::vector<float> svChi2;
std::vector<float> svEta;
std::vector<float> svMass;
std::vector<int> svNumDaughters;
std::vector<float> svDxyError; // New parameter
// std::vector<float> svDxy;
// std::vector<float> svDxySig;
std::vector<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);
tree->Branch("svX", &svX);
tree->Branch("svY", &svY);
tree->Branch("svZ", &svZ);
tree->Branch("svNormalizedChi2", &svNormalizedChi2);
tree->Branch("svChi2", &svChi2);
tree->Branch("svEta", &svEta);
tree->Branch("svMass", &svMass);
tree->Branch("svNumDaughters", &svNumDaughters);
tree->Branch("svDxyError", &svDxyError);
//tree->Branch("svDxy", &svDxy);
//tree->Branch("svDxySig", &svDxySig);
tree->Branch("svNdf", &svNdf);
}
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);
svPt.clear();
svX.clear();
svY.clear();
svZ.clear();
svNormalizedChi2.clear();
svChi2.clear();
svEta.clear();
svMass.clear();
svNumDaughters.clear();
svDxyError.clear();
// svDxy.clear();
// svDxySig.clear();
svNdf.clear();
for (const auto& sv : *secondaryVertices) {
svPt.push_back(sv.pt());
svX.push_back(sv.vertex().x());
svY.push_back(sv.vertex().y());
svZ.push_back(sv.vertex().z());
svNormalizedChi2.push_back(sv.vertexNormalizedChi2());
svChi2.push_back(sv.vertexChi2());
svEta.push_back(sv.eta());
svMass.push_back(sv.mass());
svNumDaughters.push_back(sv.numberOfDaughters());
svDxyError.push_back(sv.dxyError());
svNdf.push_back(sv.vertexNdof());
// svDxy.push_back(dxy);
// svDxySig.push_back(dxySignificance);
}
npv = vertices->size();
nsv = vertices->size();
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);
(base) rathodswasti@Swastis-Laptop14:~/cms_open_data_work/CMSSW_10_6_30/src/Test/MiniAnalyzer/plugins$
this one got compiled successfully, Ndof works. However, I am more interested in getting dxy, so I am trying to calculate it using the x and y positions.
I am also extracting the same information from the Bulk Graviton simulation file - /BulkGravTohhTohbbhbb_narrow_M-600_13TeV-madgraph/RunIISummer16MiniAODv2-PUMoriond17_80X_mcRun2_asymptotic_2016_TrancheIV_v6_ext1-v1/MINIAODSIM | CERN Open Data Portal
Should I use that one?
Thanks for the reply again!