12 #include <top/modules/TOPBackground/TOPBackgroundModule.h>
14 #include <top/dataobjects/TOPBarHit.h>
15 #include <top/dataobjects/TOPDigit.h>
16 #include <top/dataobjects/TOPSimHit.h>
17 #include <top/geometry/TOPGeometryPar.h>
19 #include <mdst/dataobjects/MCParticle.h>
20 #include <simulation/dataobjects/BeamBackHit.h>
23 #include <framework/datastore/DataStore.h>
24 #include <framework/datastore/StoreArray.h>
27 #include <framework/logging/Logger.h>
36 #include <geometry/Materials.h>
37 #include <G4Material.hh>
40 using namespace boost;
99 setDescription(
"A module to analyze beam background simulations regarding TOP");
102 addParam(
"Type", m_BkgType,
"Backgound type" ,
string(
"Backgound"));
103 addParam(
"Output", m_OutputFileName,
"Name of the output file",
104 string(
"Backgound.root"));
105 addParam(
"TimeOfSimulation", m_TimeOfSimulation,
106 "Real time in micro seconds that corresponds to simulated data", 5.);
109 TOPBackgroundModule::~TOPBackgroundModule()
114 void TOPBackgroundModule::initialize()
120 m_rootFile = TFile::Open(m_OutputFileName.c_str(),
"RECREATE");
121 origingamma =
new TTree(
"origingamma",
"tree");
122 originpe =
new TTree(
"originpe",
"tree2");
124 origingamma->Branch(
"x", &origingamma_x);
125 origingamma->Branch(
"y", &origingamma_y);
126 origingamma->Branch(
"z", &origingamma_z);
127 originpe->Branch(
"x", &originpe_x);
128 originpe->Branch(
"y", &originpe_y);
129 originpe->Branch(
"z", &originpe_z);
131 peflux =
new TH1F(
"Photoelectron flux",
"Photoelectron flux", 33, -11.25, 360);
132 nflux =
new TH1F(
"Neutron flux",
"Neutron flux", 33, -11.25, 360);
133 rdose =
new TH1F(
"Radiation dose",
"Radiation dose", 33, -11.25, 360);
134 zdist =
new TH1F(
"Photoelectron origin",
"Photoelectron origin", 200, -400, 400);
135 genergy =
new TH1F(
"Energy distribution of photons",
"Energy distribution of photons", 150, 0, 5);
136 genergy2 =
new TH1F(
"Energy distribution of gammas",
"Energy distribution of gammas", 500, 0, 5);
138 zdistg =
new TH1F(
"Photoelectron flux z",
"Photoelectron flux Z projection", 800, -400, 400);
139 originpt =
new TH1F(
"P_t of origin electron",
"P_t of origin electron", 300, 0.06, 0.14);
141 nflux_bar =
new TH2F(
"Neutron flux on bar",
"Neutron flux on bar", 32, -114.8, 211.5, 16, -0, 360);
142 gflux_bar =
new TH2F(
"Gamma flux on bar",
"Gamma flux on bar MHz/cm^{2}", 32, -114.8, 211.5, 16, -0, 360);
143 cflux_bar =
new TH2F(
"Charged flux on bar",
"Charged flux on bar MHz/cm^{2}", 32, -114.8, 211.5, 16, -0, 360);
145 norigin =
new TH1F(
"neutron(BAR) origin",
"neutron(BAR) origin", 200, -400, 400);
146 gorigin =
new TH1F(
"gamma(BAR) origin",
"gamma(BAR) origin", 200, -400, 400);
147 corigin =
new TH1F(
"charged(BAR) origin",
"charged(BAR) origin", 200, -400, 400);
149 nprim =
new TH1F(
"neutron(BAR) primary",
"neutron(BAR) primary", 200, -400, 400);
150 gprim =
new TH1F(
"gamma(BAR) primary",
"gamma(BAR) primary", 200, -400, 400);
151 cprim =
new TH1F(
"charged(BAR) primary",
"charged(BAR) primary", 200, -400, 400);
153 origin_zx =
new TGraph();
154 origin_zy =
new TGraph();
156 prim_zx =
new TGraph();
157 prim_zy =
new TGraph();
158 module_occupancy =
new TGraph();
160 origin_zy->SetName(
"originZY");
161 origin_zx->SetName(
"originZX");
162 module_occupancy->SetName(
"occupancy");
164 const auto& geo = TOP::TOPGeometryPar::Instance()->getGeometry()->getFrontEnd();
165 double S1 = geo.getFrontBoardWidth() * geo.getFrontBoardHeight();
166 double S2 = geo.getHVBoardWidth() * geo.getHVBoardLength();
167 double V1 = S1 * geo.getFrontBoardThickness();
168 double V2 = S2 * geo.getHVBoardThickness();
169 G4Material* material1 = geometry::Materials::get(geo.getFrontBoardMaterial());
170 if (!material1) B2FATAL(
"Material '" << geo.getFrontBoardMaterial() <<
"' not found");
171 G4Material* material2 = geometry::Materials::get(geo.getHVBoardMaterial());
172 if (!material2) B2FATAL(
"Material '" << geo.getHVBoardMaterial() <<
"' not found");
173 double density1 = material1->GetDensity() / CLHEP::kg * CLHEP::cm * CLHEP::cm * CLHEP::cm;
174 double density2 = material2->GetDensity() / CLHEP::kg * CLHEP::cm * CLHEP::cm * CLHEP::cm;
177 PCBmass = V1 * density1 + V2 * density2;
180 evtoJ = 1.60217653 * 1e-10;
181 mtoc = 1.97530864197531;
193 void TOPBackgroundModule::beginRun()
196 B2INFO(
"TOPBackground: Processing:");
200 void TOPBackgroundModule::event()
208 for (
int i = 0; i < nHits; i++) {
212 peflux->AddBinContent(barID * 2, 1. / m_TimeOfSimulation / 32.0);
214 const TOPSimHit* simHit = DataStore::getRelated<TOPSimHit>(aDigit);
215 if (!simHit)
continue;
218 module_occupancy->SetPoint(count_occ, PMTID , barID);
223 const MCParticle* particle = DataStore::getRelated<MCParticle>(simHit);
232 const MCParticle* pommother = mother->getMother();
235 zdist->Fill(mother->getVertex().Z());
236 zdistg->Fill(mother->getVertex().Z(), 1. / m_TimeOfSimulation / 32.0 / 16.0);
237 originpe_x = mother->getVertex().X();
238 originpe_y = mother->getVertex().Y();
239 originpe_z = mother->getVertex().Z();
241 TVector3 momentum = mother->getMomentum();
242 if (m_BkgType.at(m_BkgType.size() - 3) ==
'L') momentum.RotateY(0.0415);
243 else if (m_BkgType.at(m_BkgType.size() - 3) ==
'H') momentum.RotateY(-0.0415);
244 double px = momentum.X();
245 double py = momentum.Y();
246 double pt = sqrt(px * px + py * py);
259 for (
int iHit = 0; iHit < nHits; ++iHit) {
262 if (subdet != 5)
continue;
265 double phi = pos.XYvector().Phi_0_2pi(pos.XYvector().Phi()) / 3.14159265358979 * 180.;
266 int barID = int (phi / 22.5 + 0.5);
273 if (tophit->
getPDG() == 2112) {
277 nflux->AddBinContent(barID * 2, w / m_TimeOfSimulation / PCBarea * yearns * tlen / 0.2);
281 rdose->AddBinContent(barID * 2, edep / m_TimeOfSimulation * yearns / PCBmass * evtoJ);
286 for (
int iHit = 0; iHit < nHits; ++iHit) {
289 int PDG = toptrk->
getPDG();
293 nflux_bar->Fill(toptrk->
getPosition().Z(), (barID - 1) * 22.5,
294 1. / 917.65 / m_TimeOfSimulation * yearns * 2.);
298 gflux_bar->Fill(toptrk->
getPosition().Z(), (barID - 1) * 22.5,
299 1. / 917.65 / m_TimeOfSimulation * 2.);
301 genergy2->Fill(toptrk->
getMomentum().Mag() * 1000);
313 cflux_bar->Fill(toptrk->
getPosition().Z(), (barID - 1) * 22.5,
314 1. / 917.65 / m_TimeOfSimulation * 2.);
323 void TOPBackgroundModule::myprint(TH1F* histo,
const char* path,
const char* xtit =
"",
const char* ytit =
"",
double tresh = 0)
327 gStyle->SetOptStat(
"");
328 gStyle->SetOptFit(1111);
330 gStyle->SetCanvasColor(-1);
331 gStyle->SetPadColor(-1);
332 gStyle->SetFrameFillColor(-1);
333 gStyle->SetHistFillColor(-1);
334 gStyle->SetTitleFillColor(-1);
335 gStyle->SetFillColor(-1);
336 gStyle->SetFillStyle(4000);
337 gStyle->SetStatStyle(0);
338 gStyle->SetTitleStyle(0);
339 gStyle->SetCanvasBorderSize(0);
340 gStyle->SetCanvasBorderMode(0);
341 gStyle->SetPadBorderMode(0);
343 gStyle->SetFrameBorderSize(0);
344 gStyle->SetLegendBorderSize(0);
345 gStyle->SetStatBorderSize(0);
346 gStyle->SetTitleBorderSize(0);
351 TCanvas* c1 =
new TCanvas(
"c1",
"", 1920, 1200);
353 double x1 = histo->GetBinLowEdge(1);
354 double nb = histo->GetNbinsX();
355 double bin = histo->GetBinWidth(1);
356 double x2 = x1 + bin * nb;
358 double max = histo->GetBinContent(histo->GetMaximumBin());
361 histo->GetYaxis()->SetRangeUser(0, tresh * 1.1);
364 TLine* line =
new TLine(x1, tresh, x2, tresh);
365 line->SetLineColor(1);
366 line->SetLineWidth(3);
367 line->SetLineStyle(2);
370 histo->SetFillColor(2);
371 histo->SetLineColor(1);
373 gPad->SetTopMargin(0.08);
374 gPad->SetBottomMargin(0.15);
377 histo->GetXaxis()->SetLabelSize(0.06);
378 histo->GetYaxis()->SetLabelSize(0.06);
379 histo->GetXaxis()->SetTitleSize(0.06);
380 histo->GetYaxis()->SetTitleSize(0.06);
381 histo->GetXaxis()->SetTitle(xtit);
382 histo->GetYaxis()->SetTitle(ytit);
383 histo->GetXaxis()->SetTitleOffset(0.9);
384 histo->GetYaxis()->SetTitleOffset(0.7);
388 TLegend* leg =
new TLegend(0.75, 0.95, 0.90, 1.00);
389 leg->AddEntry(histo, m_BkgType.c_str(),
"pf");
400 void TOPBackgroundModule::endRun()
402 B2INFO(
"TOPBackground: Finished:");
405 void TOPBackgroundModule::terminate()
415 origingamma->Write();
427 module_occupancy->Write();
435 B2INFO(
"TOPBackground finished");
440 void TOPBackgroundModule::printModuleParams()
const