CMS 3D CMS Logo

CTPPSHepMCDistributionPlotter.cc
Go to the documentation of this file.
1 /****************************************************************************
2  * Authors:
3  * Jan Kašpar
4  ****************************************************************************/
5 
10 
13 
15 
17 
20 
21 #include "TFile.h"
22 #include "TH1D.h"
23 
24 #include <string>
25 
26 //----------------------------------------------------------------------------------------------------
27 
29 public:
31 
32 private:
33  void analyze(const edm::Event &, const edm::EventSetup &) override;
34  void endJob() override;
35 
39 
40  std::unique_ptr<TH1D> h_vtx_x_, h_vtx_y_, h_vtx_z_, h_vtx_t_;
41  std::unique_ptr<TH1D> h_xi_, h_th_x_, h_th_y_;
42 };
43 
44 //----------------------------------------------------------------------------------------------------
45 
46 using namespace std;
47 using namespace edm;
48 using namespace HepMC;
49 
50 //----------------------------------------------------------------------------------------------------
51 
53  : tokenHepMC_(consumes<edm::HepMCProduct>(iConfig.getParameter<edm::InputTag>("tagHepMC"))),
54  lhcInfoESToken_(esConsumes(ESInputTag("", iConfig.getParameter<std::string>("lhcInfoLabel")))),
55  outputFile_(iConfig.getParameter<string>("outputFile")),
56 
57  h_vtx_x_(new TH1D("h_vtx_x", ";vtx_x (mm)", 100, 0., 0.)),
58  h_vtx_y_(new TH1D("h_vtx_y", ";vtx_y (mm)", 100, 0., 0.)),
59  h_vtx_z_(new TH1D("h_vtx_z", ";vtx_z (mm)", 100, 0., 0.)),
60  h_vtx_t_(new TH1D("h_vtx_t", ";vtx_t (mm)", 100, 0., 0.)),
61 
62  h_xi_(new TH1D("h_xi", ";#xi", 100, 0., 0.30)),
63  h_th_x_(new TH1D("h_th_x", ";#theta^{*}_{x}", 100, -300E-6, +300E-6)),
64  h_th_y_(new TH1D("h_th_y", ";#theta^{*}_{y}", 100, -300E-6, +300E-6)) {}
65 
66 //----------------------------------------------------------------------------------------------------
67 
69  // get conditions
70  const auto &lhcInfo = iSetup.getData(lhcInfoESToken_);
71 
72  // get input
74  iEvent.getByToken(tokenHepMC_, hHepMC);
75  HepMC::GenEvent *hepMCEvent = (HepMC::GenEvent *)hHepMC->GetEvent();
76 
77  // plot vertices
78  for (HepMC::GenEvent::vertex_iterator vit = hepMCEvent->vertices_begin(); vit != hepMCEvent->vertices_end(); ++vit) {
79  const auto pos = (*vit)->position();
80  h_vtx_x_->Fill(pos.x());
81  h_vtx_y_->Fill(pos.y());
82  h_vtx_z_->Fill(pos.z());
83  h_vtx_t_->Fill(pos.t());
84  }
85 
86  // extract protons
87  for (auto it = hepMCEvent->particles_begin(); it != hepMCEvent->particles_end(); ++it) {
88  const auto &part = *it;
89 
90  // accept only stable non-beam protons
91  if (part->pdg_id() != 2212)
92  continue;
93 
94  if (part->status() != 1)
95  continue;
96 
97  if (part->is_beam())
98  continue;
99 
100  const auto &mom = part->momentum();
101  const double p_nom = lhcInfo.energy();
102 
103  if (mom.rho() / p_nom < 0.7)
104  continue;
105 
106  const double xi_simu = (p_nom - mom.e()) / p_nom;
107  const double th_x_simu = mom.x() / mom.rho();
108  const double th_y_simu = mom.y() / mom.rho();
109 
110  h_xi_->Fill(xi_simu);
111  h_th_x_->Fill(th_x_simu);
112  h_th_y_->Fill(th_y_simu);
113  }
114 }
115 
116 //----------------------------------------------------------------------------------------------------
117 
119  auto f_out = std::make_unique<TFile>(outputFile_.c_str(), "recreate");
120 
121  h_vtx_x_->Write();
122  h_vtx_y_->Write();
123  h_vtx_z_->Write();
124  h_vtx_t_->Write();
125 
126  h_xi_->Write();
127  h_th_x_->Write();
128  h_th_y_->Write();
129 }
130 
131 //----------------------------------------------------------------------------------------------------
132 
CTPPSHepMCDistributionPlotter::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: CTPPSHepMCDistributionPlotter.cc:67
EDAnalyzer.h
edm::ESInputTag
Definition: ESInputTag.h:87
ESHandle.h
edm::EDGetTokenT< edm::HepMCProduct >
edm
HLT enums.
Definition: AlignableModifier.h:19
pos
Definition: PixelAliasList.h:18
CTPPSHepMCDistributionPlotter::CTPPSHepMCDistributionPlotter
CTPPSHepMCDistributionPlotter(const edm::ParameterSet &)
Definition: CTPPSHepMCDistributionPlotter.cc:51
LHCInfo.h
edm::one::EDAnalyzer
Definition: EDAnalyzer.h:30
edm::Handle< edm::HepMCProduct >
HepMC::GenEvent
Definition: hepmc_rootio.cc:9
CTPPSHepMCDistributionPlotter
Definition: CTPPSHepMCDistributionPlotter.cc:27
CTPPSHepMCDistributionPlotter::h_th_x_
std::unique_ptr< TH1D > h_th_x_
Definition: CTPPSHepMCDistributionPlotter.cc:42
MakerMacros.h
part
part
Definition: HCALResponse.h:20
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
CTPPSHepMCDistributionPlotter::h_vtx_x_
std::unique_ptr< TH1D > h_vtx_x_
Definition: CTPPSHepMCDistributionPlotter.cc:41
CTPPSHepMCDistributionPlotter::lhcInfoESToken_
edm::ESGetToken< LHCInfo, LHCInfoRcd > lhcInfoESToken_
Definition: CTPPSHepMCDistributionPlotter.cc:38
CTPPSHepMCDistributionPlotter::h_vtx_y_
std::unique_ptr< TH1D > h_vtx_y_
Definition: CTPPSHepMCDistributionPlotter.cc:41
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
CTPPSHepMCDistributionPlotter::endJob
void endJob() override
Definition: CTPPSHepMCDistributionPlotter.cc:117
CTPPSHepMCDistributionPlotter::h_th_y_
std::unique_ptr< TH1D > h_th_y_
Definition: CTPPSHepMCDistributionPlotter.cc:42
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::EventSetup
Definition: EventSetup.h:58
edm::HepMCProduct::GetEvent
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:37
CTPPSHepMCDistributionPlotter::h_vtx_z_
std::unique_ptr< TH1D > h_vtx_z_
Definition: CTPPSHepMCDistributionPlotter.cc:41
edm::ESGetToken< LHCInfo, LHCInfoRcd >
edm::EventSetup::getData
bool getData(T &iHolder) const
Definition: EventSetup.h:127
std
Definition: JetResolutionObject.h:76
CTPPSHepMCDistributionPlotter::outputFile_
std::string outputFile_
Definition: CTPPSHepMCDistributionPlotter.cc:39
Frameworkfwd.h
CTPPSHepMCDistributionPlotter::h_xi_
std::unique_ptr< TH1D > h_xi_
Definition: CTPPSHepMCDistributionPlotter.cc:42
HepMC
Definition: GenParticle.h:15
CTPPSHepMCDistributionPlotter::h_vtx_t_
std::unique_ptr< TH1D > h_vtx_t_
Definition: CTPPSHepMCDistributionPlotter.cc:41
EventSetup.h
CTPPSDetId.h
edm::HepMCProduct
Definition: HepMCProduct.h:21
LHCInfoRcd.h
HepMCProduct.h
CTPPSHepMCDistributionPlotter::tokenHepMC_
edm::EDGetTokenT< edm::HepMCProduct > tokenHepMC_
Definition: CTPPSHepMCDistributionPlotter.cc:37
DeDxTools::esConsumes
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
reco::vertex_iterator
VertexRefVector::iterator vertex_iterator
iterator over a vector of references to Vertex objects in the same collection
Definition: VertexFwd.h:19