File indexing completed on 2024-04-06 12:21:14
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include <memory>
0012
0013
0014 #include "FWCore/Framework/interface/Frameworkfwd.h"
0015 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0016 #include "FWCore/Framework/interface/Event.h"
0017 #include "FWCore/Framework/interface/EventSetup.h"
0018 #include "FWCore/Framework/interface/MakerMacros.h"
0019 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0020 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0021 #include "FWCore/Framework/interface/ESHandle.h"
0022
0023
0024 #include "FWCore/ServiceRegistry/interface/Service.h"
0025 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0026 #include "TH1.h"
0027 #include "TTree.h"
0028 #include "TF1.h"
0029
0030
0031 #include "DataFormats/VertexReco/interface/Vertex.h"
0032 #include "DataFormats/VertexReco/interface/VertexFwd.h"
0033
0034
0035 #include "L1Trigger/L1TNtuples/interface/L1AnalysisRecoVertexDataFormat.h"
0036
0037
0038
0039
0040
0041 class L1RecoTreeProducer : public edm::one::EDAnalyzer<edm::one::SharedResources> {
0042 public:
0043 explicit L1RecoTreeProducer(const edm::ParameterSet&);
0044 ~L1RecoTreeProducer() override;
0045
0046 private:
0047 void beginJob(void) override;
0048 void analyze(const edm::Event&, const edm::EventSetup&) override;
0049 void endJob() override;
0050
0051 public:
0052 L1Analysis::L1AnalysisRecoVertexDataFormat* vtxData_;
0053
0054 private:
0055
0056 edm::Service<TFileService> fs_;
0057
0058
0059 TTree* tree_;
0060
0061
0062 edm::EDGetTokenT<reco::VertexCollection> vtxToken_;
0063
0064 unsigned int maxVtx_;
0065 };
0066
0067 L1RecoTreeProducer::L1RecoTreeProducer(const edm::ParameterSet& iConfig) {
0068 vtxToken_ = consumes<reco::VertexCollection>(
0069 iConfig.getUntrackedParameter("vtxToken", edm::InputTag("offlinePrimaryVertices")));
0070
0071 maxVtx_ = iConfig.getParameter<unsigned int>("maxVtx");
0072
0073 vtxData_ = new L1Analysis::L1AnalysisRecoVertexDataFormat();
0074
0075 usesResource(TFileService::kSharedResource);
0076
0077 tree_ = fs_->make<TTree>("RecoTree", "RecoTree");
0078 tree_->Branch("Vertex", "L1Analysis::L1AnalysisRecoVertexDataFormat", &vtxData_, 32000, 3);
0079 }
0080
0081 L1RecoTreeProducer::~L1RecoTreeProducer() {
0082
0083
0084 }
0085
0086
0087
0088
0089
0090
0091 void L1RecoTreeProducer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0092 vtxData_->Reset();
0093
0094
0095 edm::Handle<reco::VertexCollection> vertices;
0096 iEvent.getByToken(vtxToken_, vertices);
0097
0098 if (vertices.isValid()) {
0099 for (reco::VertexCollection::const_iterator it = vertices->begin();
0100 it != vertices->end() && vtxData_->nVtx < maxVtx_;
0101 ++it) {
0102 if (!it->isFake()) {
0103 vtxData_->NDoF.push_back(it->ndof());
0104 vtxData_->Z.push_back(it->z());
0105 vtxData_->Rho.push_back(it->position().rho());
0106 vtxData_->nVtx++;
0107 }
0108 }
0109 tree_->Fill();
0110 }
0111 }
0112
0113
0114 void L1RecoTreeProducer::beginJob(void) {}
0115
0116
0117 void L1RecoTreeProducer::endJob() {}
0118
0119
0120 DEFINE_FWK_MODULE(L1RecoTreeProducer);