CMS 3D CMS Logo

CTPPSBeamSmearingValidator.cc
Go to the documentation of this file.
1 /****************************************************************************
2  * Authors:
3  * Jan Kašpar
4  ****************************************************************************/
5 
8 
11 
13 
14 #include "TFile.h"
15 #include "TH1D.h"
16 
17 #include <map>
18 
19 //----------------------------------------------------------------------------------------------------
20 
22 public:
24 
25  ~CTPPSBeamSmearingValidator() override {}
26 
27 private:
28  void analyze(const edm::Event &, const edm::EventSetup &) override;
29 
30  void endJob() override;
31 
34 
36 
37  std::unique_ptr<TH1D> h_de_vtx_x_, h_de_vtx_y_, h_de_vtx_z_, h_de_vtx_t_;
38 
39  struct SectorPlots {
40  std::unique_ptr<TH1D> h_de_th_x, h_de_th_y, h_de_p;
41 
42  SectorPlots()
43  : h_de_th_x(new TH1D("", ";#Delta#theta_{x} (rad)", 100, 0., 0.)),
44  h_de_th_y(new TH1D("", ";#Delta#theta_{y} (rad)", 100, 0., 0.)),
45  h_de_p(new TH1D("", ";#Deltap (GeV)", 100, 0., 0.)) {}
46 
47  void write() const {
48  h_de_th_x->Write("h_de_th_x");
49  h_de_th_y->Write("h_de_th_y");
50  h_de_p->Write("h_de_p");
51  }
52  };
53 
54  std::map<unsigned int, SectorPlots> sectorPlots_;
55 };
56 
57 //----------------------------------------------------------------------------------------------------
58 
59 using namespace std;
60 using namespace edm;
61 using namespace HepMC;
62 
63 //----------------------------------------------------------------------------------------------------
64 
66  : tokenBeforeSmearing_(consumes<edm::HepMCProduct>(iConfig.getParameter<edm::InputTag>("tagBeforeSmearing"))),
67  tokenAfterSmearing_(consumes<edm::HepMCProduct>(iConfig.getParameter<edm::InputTag>("tagAfterSmearing"))),
68  outputFile_(iConfig.getParameter<string>("outputFile")),
69  h_de_vtx_x_(new TH1D("h_de_vtx_x", ";#Delta vtx_{x} (mm)", 100, 0., 0.)),
70  h_de_vtx_y_(new TH1D("h_de_vtx_y", ";#Delta vtx_{y} (mm)", 100, 0., 0.)),
71  h_de_vtx_z_(new TH1D("h_de_vtx_z", ";#Delta vtx_{z} (mm)", 100, 0., 0.)),
72  h_de_vtx_t_(new TH1D("h_de_vtx_t", ";#Delta vtx_{t} (mm)", 100, 0., 0.)) {}
73 
74 //----------------------------------------------------------------------------------------------------
75 
77  // get input
78  edm::Handle<edm::HepMCProduct> hBeforeSmearing;
79  iEvent.getByToken(tokenBeforeSmearing_, hBeforeSmearing);
80  HepMC::GenEvent *orig = (HepMC::GenEvent *)hBeforeSmearing->GetEvent();
81 
82  edm::Handle<edm::HepMCProduct> hAfterSmearing;
83  iEvent.getByToken(tokenAfterSmearing_, hAfterSmearing);
84  HepMC::GenEvent *smear = (HepMC::GenEvent *)hAfterSmearing->GetEvent();
85 
86  // vertices
87  GenEvent::vertex_const_iterator vold, vnew;
88  for (vold = orig->vertices_begin(), vnew = smear->vertices_begin();
89  vold != orig->vertices_end() && vnew != smear->vertices_end();
90  ++vold, ++vnew) {
91  const FourVector &vo = (*vold)->position();
92  const FourVector &vn = (*vnew)->position();
93 
94  // HepMC gives vertex in mm
95  h_de_vtx_x_->Fill(vn.x() - vo.x());
96  h_de_vtx_y_->Fill(vn.y() - vo.y());
97  h_de_vtx_z_->Fill(vn.z() - vo.z());
98  h_de_vtx_t_->Fill(vn.t() - vo.t());
99  }
100 
101  // particles
102  GenEvent::particle_const_iterator pold, pnew;
103  for (pold = orig->particles_begin(), pnew = smear->particles_begin();
104  pold != orig->particles_end() && pnew != smear->particles_end();
105  ++pold, ++pnew) {
106  FourVector o = (*pold)->momentum(), n = (*pnew)->momentum();
107 
108  // determine direction region
109  signed int idx = -1;
110  const double thetaLim = 0.01; // rad
111  double th = o.theta();
112 
113  if (th < thetaLim)
114  idx = 0;
115  if (th > (M_PI - thetaLim))
116  idx = 1;
117 
118  if (idx < 0)
119  continue;
120 
121  /*
122  cout << "particle\n\told: [" << o.x() << ", " << o.y() << ", " << o.z() << ", " << o.t()
123  << "]\n\tnew: [" << n.x() << ", " << n.y() << ", " << n.z() << ", " << n.t()
124  << "]\n\tregion: " << idx << endl;
125  */
126 
127  // fill histograms
128  auto &sp = sectorPlots_[idx];
129 
130  double othx = o.x() / o.rho(), othy = o.y() / o.rho();
131  double nthx = n.x() / n.rho(), nthy = n.y() / n.rho();
132 
133  sp.h_de_p->Fill(n.rho() - o.rho());
134 
135  sp.h_de_th_x->Fill(nthx - othx);
136  sp.h_de_th_y->Fill(nthy - othy);
137  }
138 }
139 
140 //----------------------------------------------------------------------------------------------------
141 
143  auto f_out = std::make_unique<TFile>(outputFile_.c_str(), "recreate");
144 
145  h_de_vtx_x_->Write();
146  h_de_vtx_y_->Write();
147  h_de_vtx_z_->Write();
148  h_de_vtx_t_->Write();
149 
150  gDirectory = f_out->mkdir("sector 45");
151  sectorPlots_[0].write();
152 
153  gDirectory = f_out->mkdir("sector 56");
154  sectorPlots_[1].write();
155 }
156 
157 //----------------------------------------------------------------------------------------------------
158 
CTPPSBeamSmearingValidator::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: CTPPSBeamSmearingValidator.cc:75
EDAnalyzer.h
CTPPSBeamSmearingValidator::SectorPlots
Definition: CTPPSBeamSmearingValidator.cc:40
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
edm::EDGetTokenT< edm::HepMCProduct >
edm
HLT enums.
Definition: AlignableModifier.h:19
CTPPSBeamSmearingValidator::SectorPlots::h_de_th_x
std::unique_ptr< TH1D > h_de_th_x
Definition: CTPPSBeamSmearingValidator.cc:41
edm::one::EDAnalyzer
Definition: EDAnalyzer.h:30
CTPPSBeamSmearingValidator::h_de_vtx_z_
std::unique_ptr< TH1D > h_de_vtx_z_
Definition: CTPPSBeamSmearingValidator.cc:38
edm::Handle< edm::HepMCProduct >
CTPPSBeamSmearingValidator::h_de_vtx_x_
std::unique_ptr< TH1D > h_de_vtx_x_
Definition: CTPPSBeamSmearingValidator.cc:38
CTPPSBeamSmearingValidator::SectorPlots::write
void write() const
Definition: CTPPSBeamSmearingValidator.cc:48
EcalTangentSkim_cfg.o
o
Definition: EcalTangentSkim_cfg.py:42
HepMC::GenEvent
Definition: hepmc_rootio.cc:9
heavyIonCSV_trainingSettings.idx
idx
Definition: heavyIonCSV_trainingSettings.py:5
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
CTPPSBeamSmearingValidator::tokenAfterSmearing_
edm::EDGetTokenT< edm::HepMCProduct > tokenAfterSmearing_
Definition: CTPPSBeamSmearingValidator.cc:34
CTPPSBeamSmearingValidator::h_de_vtx_t_
std::unique_ptr< TH1D > h_de_vtx_t_
Definition: CTPPSBeamSmearingValidator.cc:38
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
CTPPSBeamSmearingValidator::SectorPlots::h_de_th_y
std::unique_ptr< TH1D > h_de_th_y
Definition: CTPPSBeamSmearingValidator.cc:41
CTPPSBeamSmearingValidator::endJob
void endJob() override
Definition: CTPPSBeamSmearingValidator.cc:141
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
CTPPSBeamSmearingValidator::SectorPlots::h_de_p
std::unique_ptr< TH1D > h_de_p
Definition: CTPPSBeamSmearingValidator.cc:41
CTPPSBeamSmearingValidator::outputFile_
std::string outputFile_
Definition: CTPPSBeamSmearingValidator.cc:36
iEvent
int iEvent
Definition: GenABIO.cc:224
M_PI
#define M_PI
Definition: BXVectorInputProducer.cc:49
edm::EventSetup
Definition: EventSetup.h:58
edm::HepMCProduct::GetEvent
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:37
CTPPSBeamSmearingValidator::h_de_vtx_y_
std::unique_ptr< TH1D > h_de_vtx_y_
Definition: CTPPSBeamSmearingValidator.cc:38
std
Definition: JetResolutionObject.h:76
CTPPSBeamSmearingValidator
Definition: CTPPSBeamSmearingValidator.cc:20
Frameworkfwd.h
HepMC
Definition: GenParticle.h:15
CTPPSBeamSmearingValidator::~CTPPSBeamSmearingValidator
~CTPPSBeamSmearingValidator() override
Definition: CTPPSBeamSmearingValidator.cc:26
CTPPSBeamSmearingValidator::CTPPSBeamSmearingValidator
CTPPSBeamSmearingValidator(const edm::ParameterSet &)
Definition: CTPPSBeamSmearingValidator.cc:64
CTPPSBeamSmearingValidator::sectorPlots_
std::map< unsigned int, SectorPlots > sectorPlots_
Definition: CTPPSBeamSmearingValidator.cc:55
edm::HepMCProduct
Definition: HepMCProduct.h:21
HepMCProduct.h
edm::Event
Definition: Event.h:73
CTPPSBeamSmearingValidator::tokenBeforeSmearing_
edm::EDGetTokenT< edm::HepMCProduct > tokenBeforeSmearing_
Definition: CTPPSBeamSmearingValidator.cc:33
CTPPSBeamSmearingValidator::SectorPlots::SectorPlots
SectorPlots()
Definition: CTPPSBeamSmearingValidator.cc:43
edm::InputTag
Definition: InputTag.h:15