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_xi_, h_th_x_, h_th_y_;
41 };
42 
43 //----------------------------------------------------------------------------------------------------
44 
45 using namespace std;
46 using namespace edm;
47 using namespace HepMC;
48 
49 //----------------------------------------------------------------------------------------------------
50 
52  : tokenHepMC_(consumes<edm::HepMCProduct>(iConfig.getParameter<edm::InputTag>("tagHepMC"))),
53  lhcInfoLabel_(iConfig.getParameter<std::string>("lhcInfoLabel")),
54  outputFile_(iConfig.getParameter<string>("outputFile")),
55  h_xi_(new TH1D("h_xi", ";#xi", 100, 0., 0.30)),
56  h_th_x_(new TH1D("h_th_x", ";#theta^{*}_{x}", 100, -300E-6, +300E-6)),
57  h_th_y_(new TH1D("h_th_y", ";#theta^{*}_{y}", 100, -300E-6, +300E-6)) {}
58 
59 //----------------------------------------------------------------------------------------------------
60 
62  // get conditions
63  edm::ESHandle<LHCInfo> hLHCInfo;
64  iSetup.get<LHCInfoRcd>().get(lhcInfoLabel_, hLHCInfo);
65 
66  // get input
68  iEvent.getByToken(tokenHepMC_, hHepMC);
69  HepMC::GenEvent *hepMCEvent = (HepMC::GenEvent *)hHepMC->GetEvent();
70 
71  // extract protons
72  for (auto it = hepMCEvent->particles_begin(); it != hepMCEvent->particles_end(); ++it) {
73  const auto &part = *it;
74 
75  // accept only stable non-beam protons
76  if (part->pdg_id() != 2212)
77  continue;
78 
79  if (part->status() != 1)
80  continue;
81 
82  if (part->is_beam())
83  continue;
84 
85  const auto &mom = part->momentum();
86  const double p_nom = hLHCInfo->energy();
87 
88  if (mom.rho() / p_nom < 0.7)
89  continue;
90 
91  const double xi_simu = (p_nom - mom.e()) / p_nom;
92  const double th_x_simu = mom.x() / mom.rho();
93  const double th_y_simu = mom.y() / mom.rho();
94 
95  h_xi_->Fill(xi_simu);
96  h_th_x_->Fill(th_x_simu);
97  h_th_y_->Fill(th_y_simu);
98  }
99 }
100 
101 //----------------------------------------------------------------------------------------------------
102 
104  auto f_out = std::make_unique<TFile>(outputFile_.c_str(), "recreate");
105 
106  h_xi_->Write();
107  h_th_x_->Write();
108  h_th_y_->Write();
109 }
110 
111 //----------------------------------------------------------------------------------------------------
112 
edm::EDGetTokenT< edm::HepMCProduct > tokenHepMC_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
CTPPSHepMCDistributionPlotter(const edm::ParameterSet &)
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:34
part
Definition: HCALResponse.h:20
void analyze(const edm::Event &, const edm::EventSetup &) override
HLT enums.
T get() const
Definition: EventSetup.h:73
float const energy() const
Definition: LHCInfo.cc:190