File indexing completed on 2022-09-02 08:36:15
0001 #include <iostream>
0002
0003 #include "TTree.h"
0004
0005 #include "DataFormats/Common/interface/Handle.h"
0006 #include "FWCore/Framework/interface/Frameworkfwd.h"
0007 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0008 #include "FWCore/Framework/interface/Event.h"
0009 #include "FWCore/Framework/interface/EventSetup.h"
0010 #include "FWCore/Framework/interface/MakerMacros.h"
0011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0013 #include "FWCore/ServiceRegistry/interface/Service.h"
0014 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0015 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
0016
0017 class BoostTester : public edm::one::EDAnalyzer<edm::one::SharedResources> {
0018 public:
0019 explicit BoostTester(const edm::ParameterSet&);
0020 ~BoostTester() override = default;
0021
0022 void analyze(const edm::Event&, const edm::EventSetup&) override;
0023 void beginJob() override {}
0024 void endJob() override {}
0025
0026 private:
0027 TTree* ftreevtx;
0028 TTree* ftreep;
0029
0030 double fvx, fvy, fvz;
0031 double fpx, fpy, fpz, fpt, fp, fe, feta, fphi;
0032 };
0033
0034 BoostTester::BoostTester(const edm::ParameterSet&) {
0035 usesResource(TFileService::kSharedResource);
0036
0037 edm::Service<TFileService> tfile;
0038 ftreevtx = tfile->make<TTree>("vtxtree", "vtxtree");
0039 ftreevtx->Branch("vx", &fvx, "fvx/D");
0040 ftreevtx->Branch("vy", &fvy, "fvy/D");
0041 ftreevtx->Branch("vz", &fvz, "fvz/D");
0042
0043 ftreep = tfile->make<TTree>("ptree", "ptree");
0044 ftreep->Branch("px", &fpx, "fpx/D");
0045 ftreep->Branch("py", &fpy, "fpy/D");
0046 ftreep->Branch("pz", &fpz, "fpz/D");
0047 }
0048
0049 void BoostTester::analyze(const edm::Event& e, const edm::EventSetup&) {
0050 ftreevtx->SetBranchAddress("vx", &fvx);
0051 ftreevtx->SetBranchAddress("vy", &fvy);
0052 ftreevtx->SetBranchAddress("vz", &fvz);
0053
0054 ftreep->SetBranchAddress("px", &fpx);
0055 ftreep->SetBranchAddress("py", &fpy);
0056 ftreep->SetBranchAddress("pz", &fpz);
0057
0058 fpx = 0.;
0059 fpy = 0.;
0060 fpz = 0.;
0061
0062 std::vector<edm::Handle<edm::HepMCProduct> > EvtHandles;
0063 e.getManyByType(EvtHandles);
0064
0065 edm::LogVerbatim("BoostTest") << "evthandles= " << EvtHandles.size();
0066
0067 for (unsigned int i = 0; i < EvtHandles.size(); i++) {
0068 edm::LogVerbatim("BoostTest") << " i=" << i << " name: " << EvtHandles[i].provenance()->moduleLabel();
0069
0070 if (EvtHandles[i].isValid()) {
0071 const HepMC::GenEvent* Evt = EvtHandles[i]->GetEvent();
0072
0073
0074
0075
0076 for (auto Vtx = Evt->vertices_begin(); Vtx != Evt->vertices_end(); ++Vtx) {
0077 fvx = (*Vtx)->position().x();
0078 fvy = (*Vtx)->position().y();
0079 fvz = (*Vtx)->position().z();
0080
0081 ftreevtx->Fill();
0082
0083 edm::LogVerbatim("BoostTest") << " vertex (x,y,z)= " << (*Vtx)->position().x() << " " << (*Vtx)->position().y()
0084 << " " << (*Vtx)->position().z();
0085 }
0086
0087 for (HepMC::GenEvent::particle_const_iterator Part = Evt->particles_begin(); Part != Evt->particles_end();
0088 ++Part) {
0089 if ((*Part)->status() != 1)
0090 continue;
0091
0092 HepMC::FourVector Mon = (*Part)->momentum();
0093
0094 fpx += Mon.px();
0095 fpy += Mon.py();
0096 fpz += Mon.pz();
0097
0098 edm::LogVerbatim("BoostTest") << "particle: p=(" << Mon.px() << ", " << Mon.py() << ", " << Mon.pz()
0099 << ") status=" << (*Part)->status() << " pdgid=" << (*Part)->pdg_id();
0100 }
0101 }
0102 }
0103 edm::LogVerbatim("BoostTest") << " total px= " << fpx << " py= " << fpy << " pz= " << fpz;
0104
0105 ftreep->Fill();
0106 return;
0107 }
0108
0109 DEFINE_FWK_MODULE(BoostTester);