Belle II Software development
TOPBackgroundModule.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9// Own header.
10#include <top/modules/TOPBackground/TOPBackgroundModule.h>
11
12// TOP headers.
13#include <top/dataobjects/TOPBarHit.h>
14#include <top/dataobjects/TOPDigit.h>
15#include <top/dataobjects/TOPSimHit.h>
16#include <top/geometry/TOPGeometryPar.h>
17
18#include <mdst/dataobjects/MCParticle.h>
19#include <simulation/dataobjects/BeamBackHit.h>
20
21// framework - DataStore
22#include <framework/datastore/DataStore.h>
23#include <framework/datastore/StoreArray.h>
24
25// framework aux
26#include <framework/logging/Logger.h>
27#include <framework/gearbox/Const.h>
28
29#include <TCanvas.h>
30#include <TLegend.h>
31#include <TLine.h>
32#include <TPad.h>
33#include <TROOT.h>
34#include <TStyle.h>
35#include <Math/VectorUtil.h>
36#include <TMath.h>
37
38#include <geometry/Materials.h>
39#include <G4Material.hh>
40
41using namespace std;
42
43namespace Belle2 {
48 //-----------------------------------------------------------------
50 //-----------------------------------------------------------------
51
52 REG_MODULE(TOPBackground);
53
54
55 //-----------------------------------------------------------------
56 // Implementation
57 //-----------------------------------------------------------------
58
60 m_rootFile(0),
61 origingamma(0),
62 originpe(0),
63 peflux(0),
64 nflux(0),
65 rdose(0),
66 zdist(0),
67 genergy(0),
68 genergy2(0),
69 zdistg(0),
70 originpt(0),
71 nflux_bar(0),
72 gflux_bar(0),
73 cflux_bar(0),
74 norigin(0),
75 gorigin(0),
76 corigin(0),
77 nprim(0),
78 gprim(0),
79 cprim(0),
80 origin_zx(0),
81 origin_zy(0),
82 prim_zx(0),
83 prim_zy(0),
85 PCBmass(0),
86 PCBarea(0),
87 yearns(0),
88 evtoJ(0),
89 mtoc(0),
90 count(0),
91 count_occ(0),
95 originpe_x(0),
96 originpe_y(0),
97 originpe_z(0)
98 {
99 // Set description()
100 setDescription("A module to analyze beam background simulations regarding TOP");
101
102 // Add parameters
103 addParam("Type", m_BkgType, "Background type", string("Background"));
104 addParam("Output", m_OutputFileName, "Name of the output file",
105 string("Background.root"));
106 addParam("TimeOfSimulation", m_TimeOfSimulation,
107 "Real time in micro seconds that corresponds to simulated data", 5.);
108 }
109
111 {
112
113 // CPU time start
114
115 // Initializing the output root file
116 m_rootFile = TFile::Open(m_OutputFileName.c_str(), "RECREATE");
117 origingamma = new TTree("origingamma", "tree");
118 originpe = new TTree("originpe", "tree2");
119
120 origingamma->Branch("x", &origingamma_x);
121 origingamma->Branch("y", &origingamma_y);
122 origingamma->Branch("z", &origingamma_z);
123 originpe->Branch("x", &originpe_x);
124 originpe->Branch("y", &originpe_y);
125 originpe->Branch("z", &originpe_z);
126
127 peflux = new TH1F("Photoelectron flux", "Photoelectron flux", 33, -11.25, 360);
128 nflux = new TH1F("Neutron flux", "Neutron flux", 33, -11.25, 360);
129 rdose = new TH1F("Radiation dose", "Radiation dose", 33, -11.25, 360);
130 zdist = new TH1F("Photoelectron origin", "Photoelectron origin", 200, -400, 400);
131 genergy = new TH1F("Energy distribution of photons", "Energy distribution of photons", 150, 0, 5);
132 genergy2 = new TH1F("Energy distribution of gammas", "Energy distribution of gammas", 500, 0, 5);
133
134 zdistg = new TH1F("Photoelectron flux z", "Photoelectron flux Z projection", 800, -400, 400);
135 originpt = new TH1F("P_t of origin electron", "P_t of origin electron", 300, 0.06, 0.14);
136
137 nflux_bar = new TH2F("Neutron flux on bar", "Neutron flux on bar", 32, -114.8, 211.5, 16, -0, 360);
138 gflux_bar = new TH2F("Gamma flux on bar", "Gamma flux on bar MHz/cm^{2}", 32, -114.8, 211.5, 16, -0, 360);
139 cflux_bar = new TH2F("Charged flux on bar", "Charged flux on bar MHz/cm^{2}", 32, -114.8, 211.5, 16, -0, 360);
140
141 norigin = new TH1F("neutron(BAR) origin", "neutron(BAR) origin", 200, -400, 400);
142 gorigin = new TH1F("gamma(BAR) origin", "gamma(BAR) origin", 200, -400, 400);
143 corigin = new TH1F("charged(BAR) origin", "charged(BAR) origin", 200, -400, 400);
144
145 nprim = new TH1F("neutron(BAR) primary", "neutron(BAR) primary", 200, -400, 400);
146 gprim = new TH1F("gamma(BAR) primary", "gamma(BAR) primary", 200, -400, 400);
147 cprim = new TH1F("charged(BAR) primary", "charged(BAR) primary", 200, -400, 400);
148
149 origin_zx = new TGraph();
150 origin_zy = new TGraph();
151
152 prim_zx = new TGraph();
153 prim_zy = new TGraph();
154 module_occupancy = new TGraph();
155
156 origin_zy->SetName("originZY");
157 origin_zx->SetName("originZX");
158 module_occupancy->SetName("occupancy");
159
160 const auto& geo = TOP::TOPGeometryPar::Instance()->getGeometry()->getFrontEnd();
161 double S1 = geo.getFrontBoardWidth() * geo.getFrontBoardHeight();
162 double S2 = geo.getHVBoardWidth() * geo.getHVBoardLength();
163 double V1 = S1 * geo.getFrontBoardThickness();
164 double V2 = S2 * geo.getHVBoardThickness();
165 G4Material* material1 = geometry::Materials::get(geo.getFrontBoardMaterial());
166 if (!material1) B2FATAL("Material '" << geo.getFrontBoardMaterial() << "' not found");
167 G4Material* material2 = geometry::Materials::get(geo.getHVBoardMaterial());
168 if (!material2) B2FATAL("Material '" << geo.getHVBoardMaterial() << "' not found");
169 double density1 = material1->GetDensity() / CLHEP::kg * CLHEP::cm * CLHEP::cm * CLHEP::cm;
170 double density2 = material2->GetDensity() / CLHEP::kg * CLHEP::cm * CLHEP::cm * CLHEP::cm;
171
172 PCBarea = S1 + S2; // [cm^2], old value was: 496.725
173 PCBmass = V1 * density1 + V2 * density2; // [kg], old value was: 0.417249
174
175 yearns = 1.e13;
176 evtoJ = 1.60217653 * 1e-10;
177 mtoc = 1.97530864197531;
178 count = 0;
179 count_occ = 0;
180
181 origingamma_x = 0;
182 origingamma_y = 0;
183 origingamma_z = 0;
184 originpe_x = 0;
185 originpe_y = 0;
186 originpe_z = 0;
187 }
188
190 {
191 // Print run number
192 B2INFO("TOPBackground: Processing:");
193
194 }
195
197 {
198 StoreArray<TOPSimHit> topSimhits;
199 StoreArray<MCParticle> mcParticles;
200 StoreArray<TOPDigit> topDigits;
201 StoreArray<TOPBarHit> topTracks;
202
203 int nHits = topDigits.getEntries();
204 for (int i = 0; i < nHits; i++) {
205 const TOPDigit* aDigit = topDigits[i];
206 int barID = aDigit->getModuleID();
207
208 peflux->AddBinContent(barID * 2, 1. / m_TimeOfSimulation / 32.0);
209
210 const TOPSimHit* simHit = DataStore::getRelated<TOPSimHit>(aDigit);
211 if (!simHit) continue;
212 int PMTID = simHit->getPmtID();
213
214 module_occupancy->SetPoint(count_occ, PMTID, barID);
215 count_occ++;
216
217 genergy->Fill(simHit->getEnergy());
218
219 const MCParticle* particle = DataStore::getRelated<MCParticle>(simHit);
220
221 if (particle) {
222 const MCParticle* currParticle = particle;
223
224 const MCParticle* mother = currParticle->getMother();
225
226 while (mother) {
227 const MCParticle* pommother = mother->getMother();
228 if (!pommother) {
229
230 zdist->Fill(mother->getVertex().Z());
231 zdistg->Fill(mother->getVertex().Z(), 1. / m_TimeOfSimulation / 32.0 / 16.0);
232 originpe_x = mother->getVertex().X();
233 originpe_y = mother->getVertex().Y();
234 originpe_z = mother->getVertex().Z();
235 originpe->Fill();
236 ROOT::Math::XYZVector momentum = mother->getMomentum();
237 if (m_BkgType.at(m_BkgType.size() - 3) == 'L') ROOT::Math::VectorUtil::RotateY(momentum, 0.0415);
238 else if (m_BkgType.at(m_BkgType.size() - 3) == 'H') ROOT::Math::VectorUtil::RotateY(momentum, -0.0415);
239 double px = momentum.X();
240 double py = momentum.Y();
241 double pt = sqrt(px * px + py * py);
242 originpt->Fill(pt);
243 }
244 mother = pommother;
245 }
246 }
247 }
248
249
250 StoreArray<BeamBackHit> beamBackHits;
251 nHits = beamBackHits.getEntries();
252
253 for (int iHit = 0; iHit < nHits; ++iHit) {
254 const BeamBackHit* tophit = beamBackHits[iHit];
255 int subdet = tophit->getSubDet();
256 if (subdet != 5) continue;
257
258 auto pos = tophit->getPosition();
259 double phi = ROOT::Math::VectorUtil::Phi_0_2pi(pos.Phi()) * TMath::RadToDeg();
260 int barID = int (phi / 22.5 + 0.5);
261 if (barID == 16) {
262 barID = 0;
263 }
264 barID++;
265
266
267 if (tophit->getPDG() == Const::neutron.getPDGCode()) {
268 double w = tophit->getNeutronWeight();
269 double tlen = tophit->getTrackLength();
270
271 nflux->AddBinContent(barID * 2, w / m_TimeOfSimulation / PCBarea * yearns * tlen / 0.2);
272
273 } else {
274 double edep = tophit->getEnergyDeposit();
275 rdose->AddBinContent(barID * 2, edep / m_TimeOfSimulation * yearns / PCBmass * evtoJ);
276 }
277 }
278
279 nHits = topTracks.getEntries();
280 for (int iHit = 0; iHit < nHits; ++iHit) {
281 const TOPBarHit* toptrk = topTracks[iHit];
282
283 int PDG = toptrk->getPDG();
284 int barID = toptrk->getModuleID();
285
286 if (PDG == Const::neutron.getPDGCode()) {
287 nflux_bar->Fill(toptrk->getPosition().Z(), (barID - 1) * 22.5,
288 1. / 917.65 / m_TimeOfSimulation * yearns * 2.);
289 norigin->Fill(toptrk->getProductionPoint().Z());
290 } else {
291 if (PDG == Const::photon.getPDGCode()) {
292 gflux_bar->Fill(toptrk->getPosition().Z(), (barID - 1) * 22.5,
293 1. / 917.65 / m_TimeOfSimulation * 2.);
294 gorigin->Fill(toptrk->getProductionPoint().Z());
295 genergy2->Fill(toptrk->getMomentum().R() * 1000);
296 origin_zx->SetPoint(count, toptrk->getProductionPoint().Z(),
297 toptrk->getProductionPoint().X());
298 origin_zy->SetPoint(count, toptrk->getProductionPoint().Z() / 0.999143,
299 toptrk->getProductionPoint().Y());
300 origingamma_x = toptrk->getProductionPoint().X();
301 origingamma_y = toptrk->getProductionPoint().Y();
302 origingamma_z = toptrk->getProductionPoint().Z();
303 origingamma->Fill();
304 count++;
305
306 } else {
307 cflux_bar->Fill(toptrk->getPosition().Z(), (barID - 1) * 22.5,
308 1. / 917.65 / m_TimeOfSimulation * 2.);
309 corigin->Fill(toptrk->getProductionPoint().Z());
310 }
311 }
312
313 }
314 }
315
316
317 void TOPBackgroundModule::myprint(TH1F* histo, const char* path, const char* xtit = "", const char* ytit = "", double tresh = 0)
318 {
319
320 gROOT->Reset();
321 gStyle->SetOptStat("");
322 gStyle->SetOptFit(1111);
323
324 gStyle->SetCanvasColor(-1);
325 gStyle->SetPadColor(-1);
326 gStyle->SetFrameFillColor(-1);
327 gStyle->SetHistFillColor(-1);
328 gStyle->SetTitleFillColor(-1);
329 gStyle->SetFillColor(-1);
330 gStyle->SetFillStyle(4000);
331 gStyle->SetStatStyle(0);
332 gStyle->SetTitleStyle(0);
333 gStyle->SetCanvasBorderSize(0);
334 gStyle->SetCanvasBorderMode(0);
335 gStyle->SetPadBorderMode(0);
336 // gStyle->SetTitleMode(0);
337 gStyle->SetFrameBorderSize(0);
338 gStyle->SetLegendBorderSize(0);
339 gStyle->SetStatBorderSize(0);
340 gStyle->SetTitleBorderSize(0);
341 //gROOT->ForceStyle();*/
342
343
344
345 TCanvas* c1 = new TCanvas("c1", "", 1920, 1200);
346
347 double x1 = histo->GetBinLowEdge(1);
348 double nb = histo->GetNbinsX();
349 double bin = histo->GetBinWidth(1);
350 double x2 = x1 + bin * nb;
351
352 double max = histo->GetBinContent(histo->GetMaximumBin());
353
354 if (max < tresh) {
355 histo->GetYaxis()->SetRangeUser(0, tresh * 1.1);
356 }
357
358 TLine* line = new TLine(x1, tresh, x2, tresh);
359 line->SetLineColor(1);
360 line->SetLineWidth(3);
361 line->SetLineStyle(2);
362
363
364 histo->SetFillColor(2);
365 histo->SetLineColor(1);
366
367 gPad->SetTopMargin(0.08);
368 gPad->SetBottomMargin(0.15);
369 gPad->SetGridy();
370
371 histo->GetXaxis()->SetLabelSize(0.06);
372 histo->GetYaxis()->SetLabelSize(0.06);
373 histo->GetXaxis()->SetTitleSize(0.06);
374 histo->GetYaxis()->SetTitleSize(0.06);
375 histo->GetXaxis()->SetTitle(xtit);
376 histo->GetYaxis()->SetTitle(ytit);
377 histo->GetXaxis()->SetTitleOffset(0.9);
378 histo->GetYaxis()->SetTitleOffset(0.7);
379
380 histo->Draw();
381
382 TLegend* leg = new TLegend(0.75, 0.95, 0.90, 1.00);
383 leg->AddEntry(histo, m_BkgType.c_str(), "pf");
384 leg->Draw("SAME");
385 if (tresh > 0.01) {
386 line->Draw("SAME");
387 }
388
389 c1->Print(path);
390 }
391
392
393
395 {
396 B2INFO("TOPBackground: Finished:");
397 }
398
400 {
401 /*
402 myprint(peflux, ("peflux_" + m_BkgType + ".pdf").c_str(), "#phi", "MHz / PMT", 1.);
403 myprint(zdist, ("zdist_" + m_BkgType + ".pdf").c_str(), "z[cm]", "", 0.0);
404 myprint(nflux, ("nflux_" + m_BkgType + ".pdf").c_str(), "#phi", "neutrons / cm^{2} / year", 0.0);
405 myprint(rdose, ("rdose_" + m_BkgType + ".pdf").c_str(), "#phi", "Gy/year", 0.0);
406 */
407
408 m_rootFile->cd();
409 origingamma->Write();
410 originpe->Write();
411 peflux->Write();
412 zdist->Write();
413 nflux->Write();
414 rdose->Write();
415 genergy->Write();
416 genergy2->Write();
417 nflux_bar->Write();
418 gflux_bar->Write();
419 origin_zx->Write();
420 origin_zy->Write();
421 module_occupancy->Write();
422 gorigin->Write();
423 norigin->Write();
424 zdistg->Write();
425 originpt->Write();
426 m_rootFile->Close();
427
428 // Announce
429 B2INFO("TOPBackground finished");
430
431
432 }
433
435} // end Belle2 namespace
Class BeamBackHit - Stores hits from beam background simulation.
Definition BeamBackHit.h:28
double getNeutronWeight() const
get the effective neutron weight
double getEnergyDeposit() const
Get particle energy deposit in sensitive volume.
int getPDG() const
Get the lund code of the particle that hit the sensitive area.
Definition BeamBackHit.h:89
double getTrackLength() const
the length of the track in the volume
ROOT::Math::XYZVector getPosition() const
Get global position of the particle hit.
Definition BeamBackHit.h:95
int getSubDet() const
Det the index of subdetector in which hit occurred.
Definition BeamBackHit.h:86
static const ParticleType neutron
neutron particle
Definition Const.h:675
static const ParticleType photon
photon particle
Definition Const.h:673
static T * getRelated(const TObject *object, const std::string &name="", const std::string &namedRelation="")
Get the object to or from which another object has a relation.
Definition DataStore.h:432
A Class to store the Monte Carlo particle information.
Definition MCParticle.h:32
ROOT::Math::XYZVector getVertex() const
Return production vertex position, shorthand for getProductionVertex().
Definition MCParticle.h:172
ROOT::Math::XYZVector getMomentum() const
Return momentum.
Definition MCParticle.h:187
void setDescription(const std::string &description)
Sets the description of the module.
Definition Module.cc:214
Module()
Constructor.
Definition Module.cc:30
Accessor to arrays stored in the data store.
Definition StoreArray.h:113
int getEntries() const
Get the number of objects in the array.
Definition StoreArray.h:216
double origingamma_z
points from origin_zx and _zy graphs: z
TTree * originpe
tree for saving originpe points
TH1F * originpt
pt of electrons
TFile * m_rootFile
root file for saving histograms
TH2F * cflux_bar
charged flux on bar
double origingamma_y
points from origin_zx and _zy graphs: y
double originpe_x
points for origin of mother of photoelectrons: x
TH1F * zdistg
z distribution of the photoelectron flux
TH2F * gflux_bar
gamma flux on bar
TH1F * genergy2
energy of gamma that hits the bar
TH2F * nflux_bar
neutron flux on bar
double origingamma_x
points from origin_zx and _zy graphs: x
double originpe_z
points for origin of mother of photoelectrons: z (=zdist)
std::string m_BkgType
Type of background.
std::string m_OutputFileName
Output filename.
double originpe_y
points for origin of mother of photoelectrons: y
TTree * origingamma
tree for saving origingamma points
double m_TimeOfSimulation
Time of the simulation of the input file.
TH1F * zdist
z distribution of primaries
TH1F * genergy
energy of gamma that hits the bar
Class to store track parameters of incoming MC particles relation to MCParticle filled in top/simulat...
Definition TOPBarHit.h:27
ROOT::Math::XYZPoint getPosition() const
Returns impact point.
Definition TOPBarHit.h:104
int getModuleID() const
Returns module ID.
Definition TOPBarHit.h:86
ROOT::Math::XYZPoint getProductionPoint() const
Returns production point.
Definition TOPBarHit.h:98
int getPDG() const
Returns PDG code of particle.
Definition TOPBarHit.h:92
ROOT::Math::XYZVector getMomentum() const
Returns impact momentum.
Definition TOPBarHit.h:116
Class to store TOP digitized hits (output of TOPDigitizer or raw data unpacker) relations to TOPSimHi...
Definition TOPDigit.h:24
int getModuleID() const
Returns module ID.
Definition TOPDigit.h:270
double getFrontBoardWidth() const
Returns front board width.
const TOPGeoFrontEnd & getFrontEnd() const
Returns front-end.
Class to store simulated hits of Cherenkov photons on PMT's input for digitization module (TOPDigitiz...
Definition TOPSimHit.h:27
double getEnergy() const
Returns photon energy.
Definition TOPSimHit.h:108
int getPmtID() const
Returns PMT ID.
Definition TOPSimHit.h:72
const TOPGeometry * getGeometry() const
Returns pointer to geometry object using basf2 units.
static TOPGeometryPar * Instance()
Static method to obtain the pointer to its instance.
static G4Material * get(const std::string &name)
Find given material.
Definition Materials.h:63
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition Module.h:559
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition Module.h:649
double sqrt(double a)
sqrt for double
Definition beamHelpers.h:28
MCParticle * getMother() const
Returns a pointer to the mother particle.
Definition MCParticle.h:590
virtual void initialize() override
Initialize the Module.
virtual void event() override
Event processor.
void myprint(TH1F *histo, const char *path, const char *xtit, const char *ytit, double tresh)
Print histogram 1D, helper function.
virtual void endRun() override
End-of-run action.
virtual void terminate() override
Termination action.
virtual void beginRun() override
Called when entering a new run.
Abstract base class for different kinds of events.
STL namespace.