223 string fileDescriptor;
225 JFileRecorder <JTYPELIST<JAAnetTypes_t, JMetaTypes_t, JRootTypes_t>::typelist>
outputFile;
226 JLimit_t& numberOfEvents = inputFile.getLimit();
251 JParser<> zap(
"Main program to simulate detector response to muons and showers.");
254 zap[
'F'] =
make_field(fileDescriptor,
"file name descriptor for CDF tables");
259 zap[
's'] =
make_field(writeEMShowers,
"store generated EM showers in event");
260 zap[
'N'] =
make_field(numberOfHits,
"minimum number of hits to output event") = 1;
261 zap[
'U'] =
make_field(factor,
"scaling factor applied to light yields") = 1.0;
267 catch(
const exception &error) {
268 FATAL(error.what() << endl);
275 const JMeta meta(argc, argv);
277 const double Zbed = 0.0;
282 if (fileDescriptor !=
"") {
283 CDF.push_back(JCDF_t(fileDescriptor, DIRECT_LIGHT_FROM_MUON));
284 CDF.push_back(JCDF_t(fileDescriptor, SCATTERED_LIGHT_FROM_MUON));
285 CDF.push_back(JCDF_t(fileDescriptor, DIRECT_LIGHT_FROM_DELTARAYS));
286 CDF.push_back(JCDF_t(fileDescriptor, SCATTERED_LIGHT_FROM_DELTARAYS));
288 CDG.push_back(JCDG_t(fileDescriptor, DIRECT_LIGHT_FROM_EMSHOWER));
289 CDG.push_back(JCDG_t(fileDescriptor, SCATTERED_LIGHT_FROM_EMSHOWER));
292 double maximal_road_width = 0.0;
293 double maximal_distance = 0.0;
295 for (
size_t i = 0; i != CDF.size(); ++i) {
297 DEBUG(
"Range CDF["<< CDF[i].type <<
"] " << CDF[i].function.intensity.getXmax() <<
" m" << endl);
299 maximal_road_width = max(maximal_road_width, CDF[i].function.intensity.getXmax());
302 for (
size_t i = 0; i != CDG.size(); ++i) {
304 DEBUG(
"Range CDG["<< CDG[i].type <<
"] " << CDG[i].function.intensity.getXmax() <<
" m" << endl);
307 maximal_road_width = max(maximal_road_width, CDG[i].function.intensity.getXmax());
310 maximal_distance = max(maximal_distance, CDG[i].function.intensity.getXmax());
313 NOTICE(
"Maximal road width [m] " << maximal_road_width << endl);
314 NOTICE(
"Maximal distance [m] " << maximal_distance << endl);
317 if (detectorFile ==
"" || inputFile.empty()) {
318 STATUS(
"Nothing to be done." << endl);
326 STATUS(
"Load detector... " << flush);
338 for (JDetector::iterator module =
detector.begin(); module !=
detector.end(); ) {
339 if (!module->empty())
342 module = detector.erase(module);
350 STATUS(
"Setting up radiation tables... " << flush);
357 const JRadiation calcium (JSeaWater::Ca.Z, JSeaWater::Ca.A, 40, 0.01, 0.1, 0.1);
358 const JRadiation magnesium(JSeaWater::Mg.Z, JSeaWater::Mg.A, 40, 0.01, 0.1, 0.1);
359 const JRadiation potassium(JSeaWater::K .Z, JSeaWater::K .A, 40, 0.01, 0.1, 0.1);
360 const JRadiation sulphur (JSeaWater::S .Z, JSeaWater::S .A, 40, 0.01, 0.1, 0.1);
363 shared_ptr<JRadiation> Hydrogen (make_shared<JRadiationFunction>(hydrogen, 300, 0.2, 1.0e11));
364 shared_ptr<JRadiation> Oxygen (make_shared<JRadiationFunction>(oxygen, 300, 0.2, 1.0e11));
365 shared_ptr<JRadiation> Chlorine (make_shared<JRadiationFunction>(chlorine, 300, 0.2, 1.0e11));
366 shared_ptr<JRadiation> Sodium (make_shared<JRadiationFunction>(sodium, 300, 0.2, 1.0e11));
368 shared_ptr<JRadiation> Calcium (make_shared<JRadiationFunction>(calcium, 300, 0.2, 1.0e11));
369 shared_ptr<JRadiation> Magnesium(make_shared<JRadiationFunction>(magnesium,300, 0.2, 1.0e11));
370 shared_ptr<JRadiation> Potassium(make_shared<JRadiationFunction>(potassium,300, 0.2, 1.0e11));
371 shared_ptr<JRadiation> Sulphur (make_shared<JRadiationFunction>(sulphur, 300, 0.2, 1.0e11));
409 radiation.push_back(make_shared<JDeltaRaysSource>(200,
DENSITY_SEA_WATER, parameters.Tmin_GeV));
416 ionization.push_back(make_shared<JACoeffSource>(Calcium,
DENSITY_SEA_WATER * JSeaWater::Ca()));
417 ionization.push_back(make_shared<JACoeffSource>(Magnesium,
DENSITY_SEA_WATER * JSeaWater::Mg()));
418 ionization.push_back(make_shared<JACoeffSource>(Potassium,
DENSITY_SEA_WATER * JSeaWater::K()));
419 ionization.push_back(make_shared<JACoeffSource>(Sulphur,
DENSITY_SEA_WATER * JSeaWater::S()));
430 if (cylinder.
getZmin() < Zbed) {
434 NOTICE(
"Light generation volume: " << cylinder << endl);
442 header = inputFile.getHeader();
444 JHead buffer(header);
458 buffer.
detector.rbegin()->filename = detectorFile;
462 offset +=
Vec(cylinder.
getX(), cylinder.
getY(), 0.0);
499 copy(buffer, header);
505 NOTICE(
"Offset applied to true tracks is: " << offset << endl);
507 TH1D job(
"job", NULL, 400, 0.5, 400.5);
508 TProfile cpu(
"cpu", NULL, 16, 0.0, 8.0);
509 TProfile2D rms(
"rms", NULL, 16, 0.0, 8.0, 251, -0.5, 250.5);
510 TProfile2D rad(
"rad", NULL, 16, 0.0, 8.0, 251, -0.5, 250.5);
523 const double epsilon = 1.0e-6;
530 STATUS(
"event: " << setw(10) << in.getCounter() <<
'\r');
DEBUG(endl);
534 Evt* evt = in.next();
537 track->pos += offset;
542 event.mc_hits.clear();
549 for (vector<Trk>::const_iterator track = evt->
mc_trks.begin(); track != evt->
mc_trks.end(); ++track) {
551 if (!track->is_finalstate()) {
567 double Zmin = intersection.first;
568 double Zmax = intersection.second;
570 if (Zmax - Zmin <= parameters.Dmin_m) {
574 JVertex vertex(0.0, track->t, track->E);
576 if (track->pos.z < Zbed) {
578 if (track->dir.z > 0.0)
579 vertex.
step(
gRock, (Zbed - track->pos.z) / track->dir.z);
584 if (vertex.
getZ() < Zmin) {
585 vertex.
step(gWater, Zmin - vertex.
getZ());
588 if (vertex.
getRange() <= parameters.Dmin_m) {
596 if (subdetector.empty()) {
604 while (vertex.
getE() >= parameters.Emin_GeV && vertex.
getZ() < Zmax) {
606 const int N = radiation.size();
611 for (
int i = 0; i != N; ++i) {
612 ls += li[i] = radiation[i]->getInverseInteractionLength(vertex.
getE());
617 for (
size_t i = 0; i != ionization.size(); ++i) {
618 As += ionization[i]->getA(vertex.
getE());
621 double step = gRandom->Exp(1.0) /
ls;
624 if (vertex.
getE() < parameters.Emax_GeV) {
625 if (parameters.Dmax_m < range) {
626 range = parameters.Dmax_m;
633 rms.Fill(log10(vertex.
getE()), (Double_t) 0, ts*ts);
637 vertex.
step(As, min(step,range));
643 if (vertex.
getE() >= parameters.Emin_GeV) {
645 double y = gRandom->Uniform(
ls);
647 for (
int i = 0; i != N; ++i) {
653 Es = radiation[i]->getEnergyOfShower(vertex.
getE());
654 ts = radiation[i]->getThetaRMS(vertex.
getE(), Es);
658 rms.Fill(log10(vertex.
getE()), (Double_t) radiation[i]->getID(), ts*ts);
659 rad.Fill(log10(vertex.
getE()), (Double_t) radiation[i]->getID(), Es);
667 vertex.
applyEloss(getRandomDirection(T2), Es);
669 muon.push_back(vertex);
680 muon.push_back(vertex);
687 make_predicate(&
Trk::id, track->id));
689 if (trk != event.
mc_trks.end()) {
690 trk->len = (muon.rbegin()->getZ() < Zmax ? +1 : -1) * (muon.rbegin()->getZ() - muon.begin()->getZ());
694 for (JDetector::const_iterator module = subdetector.begin(); module != subdetector.end(); ++module) {
696 const double z0 = muon.begin()->getZ();
697 const double t0 = muon.begin()->getT();
698 const double Z =
module->getZ() - module->getX() / getTanThetaC();
700 if (Z >= muon.begin()->getZ() && Z <= muon.rbegin()->getZ()) {
702 const JVector2D pos = muon.getPosition(Z);
703 const double R = hypot(module->getX() - pos.
getX(),
704 module->getY() - pos.
getY());
706 for (
size_t i = 0; i != CDF.size(); ++i) {
708 if (R < CDF[i].integral.getXmax()) {
719 const double NPE = CDF[i].integral.getNPE(R) *
module->size() * factor * W;
720 const size_t N = getPoisson(NPE);
726 for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) {
728 const double R = hypot(pmt->getX() - pos.
getX(),
729 pmt->getY() - pos.
getY());
730 const double theta = pi.
constrain(pmt->getTheta());
731 const double phi = pi.
constrain(fabs(pmt->getPhi()));
733 npe.push_back(CDF[i].function.getNPE(R, theta, phi) * factor * W);
738 for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) {
740 const double R = hypot(pmt->getX() - pos.
getX(),
741 pmt->getY() - pos.
getY());
742 const double Z = pmt->getZ() - z0;
743 const double theta = pi.
constrain(pmt->getTheta());
744 const double phi = pi.
constrain(fabs(pmt->getPhi()));
746 size_t n0 = min(ns[
distance(module->begin(),pmt)], parameters.Nmax_PMT);
748 job.Fill((
double) (100 + CDF[i].type), (
double) n0);
752 const double t1 = CDF[i].function.getTime(R, theta, phi, gRandom->Rndm());
755 mc_hits.push_back(
JHit_t(mc_hits.size() + 1,
759 t0 + (R * getTanThetaC() + Z) / C + t1,
766 if (std::accumulate(npe.begin(), npe.end(), 0.0) > NPE) {
767 job.Fill((
double) (300 + CDF[i].type));
771 catch(
const exception& error) {
772 job.Fill((
double) (200 + CDF[i].type));
779 for (JTrack::const_iterator vertex = muon.begin(); vertex != muon.end(); ++vertex) {
781 const double Es = vertex->
getEs();
783 if (Es >= parameters.Ecut_GeV) {
785 const double z0 = vertex->
getZ();
786 const double t0 = vertex->
getT();
789 int origin = track->id;
791 if (writeEMShowers) {
792 origin =
event.mc_trks.size() + 1;
795 int number_of_hits = 0;
797 JDetectorSubset_t::range_type range = subdetector.getRange(z0 - maximal_distance,
798 z0 + maximal_distance);
800 for (JDetector::const_iterator module = range.begin(); module != range.end(); ++module) {
802 const double R = hypot(module->getX() - vertex->
getX(),
803 module->getY() - vertex->
getY());
804 const double Z =
module->getZ() - z0 - DZ;
805 const double D = sqrt(R*R + Z*Z);
806 const double cd = Z / D;
808 for (
size_t i = 0; i != CDG.size(); ++i) {
810 if (D < CDG[i].integral.getXmax()) {
814 const double NPE = CDG[i].integral.getNPE(D, cd) * Es * module->size() * factor;
815 const size_t N = getPoisson(NPE);
821 for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) {
823 const double R = hypot(pmt->getX() - vertex->
getX(),
824 pmt->getY() - vertex->
getY());
825 const double Z = pmt->getZ() - z0 - DZ;
826 const double D = sqrt(R*R + Z*Z);
827 const double cd = Z / D;
828 const double theta = pi.
constrain(pmt->getTheta());
829 const double phi = pi.
constrain(fabs(pmt->getPhi()));
831 npe.push_back(CDG[i].function.getNPE(D, cd, theta, phi) * Es * factor);
836 for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) {
838 const double R = hypot(pmt->getX() - vertex->
getX(),
839 pmt->getY() - vertex->
getY());
840 const double theta = pi.
constrain(pmt->getTheta());
841 const double phi = pi.
constrain(fabs(pmt->getPhi()));
843 size_t n0 = min(ns[
distance(module->begin(),pmt)], parameters.Nmax_PMT);
845 job.Fill((
double) (100 + CDG[i].type), (
double) n0);
850 const double Z = pmt->getZ() - z0 - dz;
851 const double D = sqrt(R*R + Z*Z);
852 const double cd = Z / D;
854 const double t1 = CDG[i].function.getTime(D, cd, theta, phi, gRandom->Rndm());
857 mc_hits.push_back(
JHit_t(mc_hits.size() + 1,
866 number_of_hits += n1;
870 if (std::accumulate(npe.begin(), npe.end(), 0.0) > NPE) {
871 job.Fill((
double) (300 + CDG[i].type));
875 catch(
const exception& error) {
876 job.Fill((
double) (200 + CDG[i].type));
882 if (writeEMShowers && number_of_hits != 0) {
884 event.mc_trks.push_back(
JTrk_t(origin,
887 track->pos + track->dir * vertex->
getZ(),
895 }
else if (track->len > 0.0) {
903 const double z0 = 0.0;
904 const double z1 = z0 + track->len;
905 const double t0 = track->t;
906 const double E = track->E;
912 for (JDetector::const_iterator module =
detector.begin(); module !=
detector.end(); ++module) {
916 const double R = pos.
getX();
921 R > maximal_road_width) {
925 for (
size_t i = 0; i != CDF.size(); ++i) {
937 if (R < CDF[i].integral.getXmax()) {
941 const double NPE = CDF[i].integral.getNPE(R) *
module->size() * factor * W;
942 const size_t N = getPoisson(NPE);
952 for (JModule::const_iterator pmt = buffer.begin(); pmt != buffer.end(); ++pmt) {
954 const double R = pmt->getX();
955 const double theta = pi.
constrain(pmt->getTheta());
956 const double phi = pi.
constrain(fabs(pmt->getPhi()));
958 npe.push_back(CDF[i].function.getNPE(R, theta, phi) * factor * W);
963 for (JModule::const_iterator pmt = buffer.begin(); pmt != buffer.end(); ++pmt) {
965 const double R = pmt->getX();
966 const double Z = pmt->getZ() - z0;
967 const double theta = pi.
constrain(pmt->getTheta());
968 const double phi = pi.
constrain(fabs(pmt->getPhi()));
970 size_t n0 = min(ns[
distance(buffer.cbegin(),pmt)], parameters.Nmax_PMT);
972 job.Fill((
double) (120 + CDF[i].type), (
double) n0);
976 const double t1 = CDF[i].function.getTime(R, theta, phi, gRandom->Rndm());
979 mc_hits.push_back(
JHit_t(mc_hits.size() + 1,
983 t0 + (R * getTanThetaC() + Z) / C + t1,
990 if (std::accumulate(npe.begin(), npe.end(), 0.0) > NPE) {
991 job.Fill((
double) (320 + CDF[i].type));
995 catch(
const exception& error) {
996 job.Fill((
double) (220 + CDF[i].type));
1002 if (!buffer.empty()) {
1016 double E = track->E;
1021 catch(
const exception& error) {
1022 ERROR(error.what() << endl);
1025 E =
pythia(track->type, E);
1029 const double z0 = 0.0;
1030 const double t0 = track->t;
1037 for (JDetector::const_iterator module =
detector.begin(); module !=
detector.end(); ++module) {
1041 const double R = pos.
getX();
1042 const double Z = pos.
getZ() - z0 - DZ;
1043 const double D = sqrt(R*R + Z*Z);
1044 const double cd = Z / D;
1046 for (
size_t i = 0; i != CDG.size(); ++i) {
1048 if (D < CDG[i].integral.getXmax()) {
1052 const double NPE = CDG[i].integral.getNPE(D, cd) * E * module->size() * factor;
1053 const size_t N = getPoisson(NPE);
1063 for (JModule::const_iterator pmt = buffer.begin(); pmt != buffer.end(); ++pmt) {
1065 const double R = pmt->getX();
1066 const double Z = pmt->getZ() - z0 - DZ;
1067 const double D = sqrt(R*R + Z*Z);
1068 const double cd = Z / D;
1069 const double theta = pi.
constrain(pmt->getTheta());
1070 const double phi = pi.
constrain(fabs(pmt->getPhi()));
1072 npe.push_back(CDG[i].function.getNPE(D, cd, theta, phi) * E * factor);
1077 for (JModule::const_iterator pmt = buffer.begin(); pmt != buffer.end(); ++pmt) {
1079 const double theta = pi.
constrain(pmt->getTheta());
1080 const double phi = pi.
constrain(fabs(pmt->getPhi()));
1082 size_t n0 = min(ns[
distance(buffer.cbegin(),pmt)], parameters.Nmax_PMT);
1084 job.Fill((
double) (140 + CDG[i].type), (
double) n0);
1089 const double Z = pmt->getZ() - z0 - dz;
1090 const double D = sqrt(R*R + Z*Z);
1091 const double cd = Z / D;
1093 const double t1 = CDG[i].function.getTime(D, cd, theta, phi, gRandom->Rndm());
1096 mc_hits.push_back(
JHit_t(mc_hits.size() + 1,
1100 t0 + (dz + D * getIndexOfRefraction()) / C + t1,
1107 if (std::accumulate(npe.begin(), npe.end(), 0.0) > NPE) {
1108 job.Fill((
double) (340 + CDG[i].type));
1112 catch(
const exception& error) {
1113 job.Fill((
double) (240 + CDG[i].type));
1119 if (!buffer.empty()) {
1130 if (!mc_hits.empty()) {
1132 mc_hits.
merge(parameters.Tmax_ns);
1134 event.mc_hits.resize(mc_hits.size());
1136 copy(mc_hits.begin(), mc_hits.end(), event.
mc_hits.begin());
1145 if (event.
mc_hits.size() >= numberOfHits) {