9#include "FairPrimaryGenerator.h"
12#include "TGeoCompositeShape.h"
14#include "TGeoManager.h"
16#include "TGeoVolume.h"
39 LOG(info) <<
"Opening input file " << fileName;
41 LOG(fatal) <<
"Error opening input file.";
47 fTree->SetBranchAddress(
"Ev", &
Ev);
48 fTree->SetBranchAddress(
"pxv", &
pxv);
49 fTree->SetBranchAddress(
"pyv", &
pyv);
50 fTree->SetBranchAddress(
"pzv", &
pzv);
51 fTree->SetBranchAddress(
"neu", &
neu);
52 fTree->SetBranchAddress(
"cc", &
cc);
58 fTree->SetBranchAddress(
"El", &
El);
59 fTree->SetBranchAddress(
"pxl", &
pxl);
60 fTree->SetBranchAddress(
"pyl", &
pyl);
61 fTree->SetBranchAddress(
"pzl", &
pzl);
62 fTree->SetBranchAddress(
"Ef", &
Ef);
63 fTree->SetBranchAddress(
"pxf", &
pxf);
64 fTree->SetBranchAddress(
"pyf", &
pyf);
65 fTree->SetBranchAddress(
"pzf", &
pzf);
66 fTree->SetBranchAddress(
"nf", &
nf);
73 Double_t px, Double_t py,
76 Double_t theta = atan(sqrt(x * x + y * y) / z);
77 Double_t c = cos(theta);
78 Double_t s = sin(theta);
80 Double_t px1 = c * px + s * pz;
81 Double_t pzr = -s * px + c * pz;
82 Double_t phi = atan2(y, x);
86 Double_t pxr = c * px1 - s * py;
87 Double_t pyr = s * px1 + c * py;
90 return {pxr, pyr, pzr};
101 dVecs.push_back(dVec);
103 cout <<
"Debug GenieGenerator: " << dVec.X() <<
" " << box.Z() << endl;
108 TGeoVolume* top = gGeoManager->GetTopVolume();
109 TGeoNode* linner = top->FindNode(
"lidT1I_1");
110 TGeoNode* scint = top->FindNode(
"lidT1lisci_1");
111 TGeoNode* louter = top->FindNode(
"lidT1O_1");
112 TGeoNode* lidT6I = top->FindNode(
"lidT6I_1");
113 TGeoNode* t2I = top->FindNode(
"T2I_1");
114 TGeoNode* t1I = top->FindNode(
"T1I_1");
115 TGeoEltu* temp =
dynamic_cast<TGeoEltu*
>(linner->GetVolume()->GetShape());
117 temp =
dynamic_cast<TGeoEltu*
>(louter->GetVolume()->GetShape());
121 fEntrZ_inner = linner->GetMatrix()->GetTranslation()[2];
122 fEntrZ_outer = louter->GetMatrix()->GetTranslation()[2];
125 TGeoCompositeShape* tempC =
126 dynamic_cast<TGeoCompositeShape*
>(t2I->GetVolume()->GetShape());
129 tempC =
dynamic_cast<TGeoCompositeShape*
>(t1I->GetVolume()->GetShape());
130 fL1z = tempC->GetDZ() * 2;
131 temp =
dynamic_cast<TGeoEltu*
>(scint->GetVolume()->GetShape());
133 cout <<
"Info GenieGenerator: geo inner " <<
fEntrDz_inner <<
" "
135 cout <<
"Info GenieGenerator: geo outer " <<
fEntrDz_outer <<
" "
137 cout <<
"Info GenieGenerator: A and B " <<
fEntrA <<
" " <<
fEntrB << endl;
138 cout <<
"Info GenieGenerator: vessel length heig<ht width " <<
Lvessel
140 cout <<
"Info GenieGenerator: scint thickness " <<
fScintDz << endl;
143 for (
size_t j = 0; j <
m_boxes.size(); j++) {
144 cout <<
"Info GenieGenerator: nuMu X" << j <<
" - "
147 cout <<
"Info GenieGenerator: nuMu Y" << j <<
" - "
150 cout <<
"Info GenieGenerator: nuMu Z" << j <<
" - "
157 LOG(warning) <<
"End of input file. Rewind.";
161 if (
fn % 1000 == 0) {
162 cout <<
"Info GenieGenerator: neutrino event-nr " <<
fn << endl;
174 Double_t where = gRandom->Uniform(0., 1.);
183 if (gRandom->Uniform(0., 1.) < 0.5) {
188 }
else if (where < 0.64) {
192 Double_t zrand = gRandom->Uniform(0,
Lvessel);
197 Double_t theta = gRandom->Uniform(0., TMath::Pi());
199 if (gRandom->Uniform(0., 1.) > 0.5) {
207 x = (ea + rextra) * cos(theta);
208 y = sqrt(1. - (x * x) / ((ea + rextra) * (ea + rextra))) * (eb + rextra);
209 if (gRandom->Uniform(-1., 1.) > 0.) y = -y;
212 int j =
static_cast<int>(gRandom->Uniform(0.,
m_boxes.size() + 0.5));
222 Double_t zrelative = z -
ztarget;
230 cpg->AddTrack(
neu, pout[0], pout[1], pout[2], x, y, z, -1,
false);
234 Int_t oLPdgCode =
neu;
236 oLPdgCode = copysign(TMath::Abs(
neu) - 1,
neu);
241 cpg->AddTrack(oLPdgCode, pout[0], pout[1], pout[2], x, y, z, 0,
true);
243 for (
int i = 0; i <
nf; i++) {
245 cpg->AddTrack(
pdgf[i], pout[0], pout[1], pout[2], x, y, z, 0,
true);
255 Double_t start[3] = {0., 0.,
startZ};
256 Double_t end[3] = {0., 0.,
endZ};
262 Double_t bparam = 0.;
265 cout <<
"Info GenieGenerator: MaterialBudget " << start[2] <<
" - "
267 cout <<
"Info GenieGenerator: MaterialBudget " << bparam << endl;
268 cout <<
"Info GenieGenerator: MaterialBudget 0 " << mparam[0] << endl;
269 cout <<
"Info GenieGenerator: MaterialBudget 1 " << mparam[1] << endl;
270 cout <<
"Info GenieGenerator: MaterialBudget 2 " << mparam[2] << endl;
271 cout <<
"Info GenieGenerator: MaterialBudget 3 " << mparam[3] << endl;
272 cout <<
"Info GenieGenerator: MaterialBudget 4 " << mparam[4] << endl;
273 cout <<
"Info GenieGenerator: MaterialBudget 5 " << mparam[5] << endl;
274 cout <<
"Info GenieGenerator: MaterialBudget 6 " << mparam[6] << endl;
275 cout <<
"Info GenieGenerator: MaterialBudget " << mparam[0] * mparam[4]
279 printf(
"Reading (log10(p),log10(pt)) Hists from file: %s\n",
281 for (Int_t idnu = 12; idnu < 17; idnu += 2) {
282 for (Int_t idadd = -1; idadd < 2; idadd += 2) {
283 Int_t idhnu =
static_cast<int>(idbase + idnu);
284 if (idadd < 0) idhnu += 1000;
285 sprintf(ts,
"%d", idhnu);
288 TH2* h2tmp =
dynamic_cast<TH2*
>(
fInputFile->Get(ts));
289 printf(
"HISTID=%d, Title:%s\n", idhnu, h2tmp->GetTitle());
290 sprintf(ts,
"px_%d", idhnu);
293 pxhist[idhnu] = h2tmp->ProjectionX(ts, 1, -1);
294 Int_t nbinx = h2tmp->GetNbinsX();
297 for (Int_t k = 1; k < nbinx + 1; k += 1) {
298 sprintf(ts,
"h%d%d", idhnu, k);
300 pyslice[idhnu][k] = h2tmp->ProjectionY(ts, k, k);
309 LOG(warning) <<
"End of input file. Rewind.";
314 cout <<
"Info GenieGenerator: neutrino event-nr " <<
fn << endl;
321 Double_t pout[3] = {0., 0., -1.};
326 while (pout[2] < 0.) {
334 Int_t idhnu = TMath::Abs(
neu) + idbase;
335 if (
neu < 0) idhnu += 1000;
336 Int_t nbinmx =
pxhist[idhnu]->GetNbinsX();
337 Double_t pl10 = log10(
pzv);
338 Int_t nbx =
pxhist[idhnu]->FindBin(pl10);
341 if (nbx < 1) nbx = 1;
342 if (nbx > nbinmx) nbx = nbinmx;
343 Double_t ptlog10 =
pyslice[idhnu][nbx]->GetRandom();
345 Double_t pt = pow(10., ptlog10) - 0.01;
347 Double_t phi = gRandom->Uniform(0., 2 * TMath::Pi());
348 pout[0] = cos(phi) * pt;
349 pout[1] = sin(phi) * pt;
350 pout[2] =
pzv *
pzv - pt * pt;
355 pout[2] = TMath::Sqrt(pout[2]);
356 if (gRandom->Uniform(-1., 1.) < 0.) pout[0] = -pout[0];
357 if (gRandom->Uniform(-1., 1.) < 0.) pout[1] = -pout[1];
361 start[0] = (pout[0] / pout[2]) * (start[2] -
ztarget);
362 start[1] = (pout[1] / pout[2]) * (start[2] -
ztarget);
365 txnu = pout[0] / pout[2];
366 tynu = pout[1] / pout[2];
367 end[0] = txnu * (end[2] -
ztarget);
368 end[1] = tynu * (end[2] -
ztarget);
377 Double_t prob2int = -1.;
381 while (prob2int < gRandom->Uniform(0., 1.)) {
383 z = gRandom->Uniform(start[2], end[2]);
386 if (mparam[6] < 0.5) {
393 TGeoNode* node = gGeoManager->FindNode(x, y, z);
394 TGeoMaterial* mat =
nullptr;
395 if (node && !gGeoManager->IsOutside()) {
396 mat = node->GetVolume()->GetMaterial();
400 prob2int = mat->GetDensity() / mparam[7];
402 cout <<
"***WARNING*** GenieGenerator: prob2int > Maximum density????"
403 << prob2int <<
" maxrho:" << mparam[7]
404 <<
" material: " << mat->GetName() << endl;
413 Double_t zrelative = z -
ztarget;
414 Double_t tof = TMath::Sqrt(x * x + y * y + zrelative * zrelative) /
417 neu, pout[0], pout[1], pout[2], x, y, z, -1,
false,
418 TMath::Sqrt(pout[0] * pout[0] + pout[1] * pout[1] + pout[2] * pout[2]),
419 tof, mparam[0] * mparam[4]);
423 Int_t oLPdgCode =
neu;
425 oLPdgCode = copysign(TMath::Abs(
neu) - 1,
neu);
430 cpg->AddTrack(oLPdgCode, pp[0], pp[1], pp[2], x, y, z, 0,
true,
El, tof,
431 mparam[0] * mparam[4]);
433 for (
int i = 0; i <
nf; i++) {
435 cpg->AddTrack(
pdgf[i], pp[0], pp[1], pp[2], x, y, z, 0,
true,
Ef[i], tof,
436 mparam[0] * mparam[4]);
std::vector< TVector3 > m_boxes
std::vector< double > Rotate(Double_t x, Double_t y, Double_t z, Double_t px, Double_t py, Double_t pz)
~GenieGenerator() override
Bool_t ReadEvent(FairPrimaryGenerator *) override
std::vector< TVector3 > dVecs
Bool_t OldReadEvent(FairPrimaryGenerator *)
Bool_t Init(const char *, int) override
void AddBox(TVector3 dVec, TVector3 box)
TFile * fInputFile
don't make it persistent, magic ROOT command
TH1D * pyslice[3000][100]
double MeanMaterialBudget(std::span< const double, 3 > start, std::span< const double, 3 > end, std::span< double, 10 > mparam)