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());
619 for (
size_t i = 0; i != ionization.size(); ++i) {
620 As += ionization[i]->getA(vertex.
getE());
623 double step = gRandom->Exp(1.0) /
ls;
626 if (vertex.
getE() < parameters.Emax_GeV) {
627 if (parameters.Dmax_m < range) {
628 range = parameters.Dmax_m;
635 rms.Fill(log10(vertex.
getE()), (Double_t) 0, ts*ts);
639 vertex.
step(As, min(step,range));
645 if (vertex.
getE() >= parameters.Emin_GeV) {
647 double y = gRandom->Uniform(
ls);
649 for (
int i = 0; i != N; ++i) {
655 Es = radiation[i]->getEnergyOfShower(vertex.
getE());
656 ts = radiation[i]->getThetaRMS(vertex.
getE(), Es);
660 rms.Fill(log10(vertex.
getE()), (Double_t) radiation[i]->getID(), ts*ts);
661 rad.Fill(log10(vertex.
getE()), (Double_t) radiation[i]->getID(), Es);
669 vertex.
applyEloss(getRandomDirection(T2), Es);
671 muon.push_back(vertex);
682 muon.push_back(vertex);
689 make_predicate(&
Trk::id, track->id));
691 if (trk != event.
mc_trks.end()) {
692 trk->len = (muon.rbegin()->getZ() < Zmax ? +1 : -1) * (muon.rbegin()->getZ() - muon.begin()->getZ());
696 for (JDetector::const_iterator module = subdetector.begin(); module != subdetector.end(); ++module) {
698 const double z0 = muon.begin()->getZ();
699 const double t0 = muon.begin()->getT();
700 const double Z =
module->getZ() - module->getX() / getTanThetaC();
702 if (Z >= muon.begin()->getZ() && Z <= muon.rbegin()->getZ()) {
704 const JVector2D pos = muon.getPosition(Z);
705 const double R = hypot(module->getX() - pos.
getX(),
706 module->getY() - pos.
getY());
708 for (
size_t i = 0; i != CDF.size(); ++i) {
710 if (R < CDF[i].integral.getXmax()) {
720 const double NPE = CDF[i].integral.getNPE(R) *
module->size() * factor * W;
721 const size_t N = getPoisson(NPE);
727 for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) {
729 const double R = hypot(pmt->getX() - pos.
getX(),
730 pmt->getY() - pos.
getY());
731 const double theta = pi.
constrain(pmt->getTheta());
732 const double phi = pi.
constrain(fabs(pmt->getPhi()));
734 npe.push_back(CDF[i].function.getNPE(R, theta, phi) * factor * W);
739 for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) {
741 const double R = hypot(pmt->getX() - pos.
getX(),
742 pmt->getY() - pos.
getY());
743 const double Z = pmt->getZ() - z0;
744 const double theta = pi.
constrain(pmt->getTheta());
745 const double phi = pi.
constrain(fabs(pmt->getPhi()));
747 size_t n0 = min(ns[
distance(module->begin(),pmt)], parameters.Nmax_PMT);
749 job.Fill((
double) (100 + CDF[i].type), (
double) n0);
753 const double t1 = CDF[i].function.getTime(R, theta, phi, gRandom->Rndm());
756 mc_hits.push_back(
JHit_t(mc_hits.size() + 1,
760 t0 + (R * getTanThetaC() + Z) / C + t1,
767 if (std::accumulate(npe.begin(), npe.end(), 0.0) > NPE) {
768 job.Fill((
double) (300 + CDF[i].type));
772 catch(
const exception& error) {
773 job.Fill((
double) (200 + CDF[i].type));
780 for (JTrack::const_iterator vertex = muon.begin(); vertex != muon.end(); ++vertex) {
782 const double Es = vertex->
getEs();
784 if (Es >= parameters.Ecut_GeV) {
786 const double z0 = vertex->
getZ();
787 const double t0 = vertex->
getT();
790 int origin = track->id;
792 if (writeEMShowers) {
793 origin =
event.mc_trks.size() + 1;
796 int number_of_hits = 0;
798 JDetectorSubset_t::range_type range = subdetector.getRange(z0 - maximal_distance,
799 z0 + maximal_distance);
801 for (JDetector::const_iterator module = range.begin(); module != range.end(); ++module) {
803 const double R = hypot(module->getX() - vertex->
getX(),
804 module->getY() - vertex->
getY());
805 const double Z =
module->getZ() - z0 - DZ;
806 const double D = sqrt(R*R + Z*Z);
807 const double cd = Z / D;
809 for (
size_t i = 0; i != CDG.size(); ++i) {
811 if (D < CDG[i].integral.getXmax()) {
815 const double NPE = CDG[i].integral.getNPE(D, cd) * Es * module->size() * factor;
816 const size_t N = getPoisson(NPE);
822 for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) {
824 const double R = hypot(pmt->getX() - vertex->
getX(),
825 pmt->getY() - vertex->
getY());
826 const double Z = pmt->getZ() - z0 - DZ;
827 const double D = sqrt(R*R + Z*Z);
828 const double cd = Z / D;
829 const double theta = pi.
constrain(pmt->getTheta());
830 const double phi = pi.
constrain(fabs(pmt->getPhi()));
832 npe.push_back(CDG[i].function.getNPE(D, cd, theta, phi) * Es * factor);
837 for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) {
839 const double R = hypot(pmt->getX() - vertex->
getX(),
840 pmt->getY() - vertex->
getY());
841 const double theta = pi.
constrain(pmt->getTheta());
842 const double phi = pi.
constrain(fabs(pmt->getPhi()));
844 size_t n0 = min(ns[
distance(module->begin(),pmt)], parameters.Nmax_PMT);
846 job.Fill((
double) (100 + CDG[i].type), (
double) n0);
851 const double Z = pmt->getZ() - z0 - dz;
852 const double D = sqrt(R*R + Z*Z);
853 const double cd = Z / D;
855 const double t1 = CDG[i].function.getTime(D, cd, theta, phi, gRandom->Rndm());
858 mc_hits.push_back(
JHit_t(mc_hits.size() + 1,
867 number_of_hits += n1;
871 if (std::accumulate(npe.begin(), npe.end(), 0.0) > NPE) {
872 job.Fill((
double) (300 + CDG[i].type));
876 catch(
const exception& error) {
877 job.Fill((
double) (200 + CDG[i].type));
883 if (writeEMShowers && number_of_hits != 0) {
885 event.mc_trks.push_back(
JTrk_t(origin,
888 track->pos + track->dir * vertex->
getZ(),
896 }
else if (track->len > 0.0) {
904 const double z0 = 0.0;
905 const double z1 = z0 + track->len;
906 const double t0 = track->t;
907 const double E = track->E;
913 for (JDetector::const_iterator module =
detector.begin(); module !=
detector.end(); ++module) {
917 const double R = pos.
getX();
922 R > maximal_road_width) {
926 for (
size_t i = 0; i != CDF.size(); ++i) {
938 if (R < CDF[i].integral.getXmax()) {
942 const double NPE = CDF[i].integral.getNPE(R) *
module->size() * factor * W;
943 const size_t N = getPoisson(NPE);
953 for (JModule::const_iterator pmt = buffer.begin(); pmt != buffer.end(); ++pmt) {
955 const double R = pmt->getX();
956 const double theta = pi.
constrain(pmt->getTheta());
957 const double phi = pi.
constrain(fabs(pmt->getPhi()));
959 npe.push_back(CDF[i].function.getNPE(R, theta, phi) * factor * W);
964 for (JModule::const_iterator pmt = buffer.begin(); pmt != buffer.end(); ++pmt) {
966 const double R = pmt->getX();
967 const double Z = pmt->getZ() - z0;
968 const double theta = pi.
constrain(pmt->getTheta());
969 const double phi = pi.
constrain(fabs(pmt->getPhi()));
971 size_t n0 = min(ns[
distance(buffer.cbegin(),pmt)], parameters.Nmax_PMT);
973 job.Fill((
double) (120 + CDF[i].type), (
double) n0);
977 const double t1 = CDF[i].function.getTime(R, theta, phi, gRandom->Rndm());
980 mc_hits.push_back(
JHit_t(mc_hits.size() + 1,
984 t0 + (R * getTanThetaC() + Z) / C + t1,
991 if (std::accumulate(npe.begin(), npe.end(), 0.0) > NPE) {
992 job.Fill((
double) (320 + CDF[i].type));
996 catch(
const exception& error) {
997 job.Fill((
double) (220 + CDF[i].type));
1003 if (!buffer.empty()) {
1017 double E = track->E;
1022 catch(
const exception& error) {
1023 ERROR(error.what() << endl);
1026 E =
pythia(track->type, E);
1030 const double z0 = 0.0;
1031 const double t0 = track->t;
1038 for (JDetector::const_iterator module =
detector.begin(); module !=
detector.end(); ++module) {
1042 const double R = pos.
getX();
1043 const double Z = pos.
getZ() - z0 - DZ;
1044 const double D = sqrt(R*R + Z*Z);
1045 const double cd = Z / D;
1047 for (
size_t i = 0; i != CDG.size(); ++i) {
1049 if (D < CDG[i].integral.getXmax()) {
1053 const double NPE = CDG[i].integral.getNPE(D, cd) * E * module->size() * factor;
1054 const size_t N = getPoisson(NPE);
1064 for (JModule::const_iterator pmt = buffer.begin(); pmt != buffer.end(); ++pmt) {
1066 const double R = pmt->getX();
1067 const double Z = pmt->getZ() - z0 - DZ;
1068 const double D = sqrt(R*R + Z*Z);
1069 const double cd = Z / D;
1070 const double theta = pi.
constrain(pmt->getTheta());
1071 const double phi = pi.
constrain(fabs(pmt->getPhi()));
1073 npe.push_back(CDG[i].function.getNPE(D, cd, theta, phi) * E * factor);
1078 for (JModule::const_iterator pmt = buffer.begin(); pmt != buffer.end(); ++pmt) {
1080 const double theta = pi.
constrain(pmt->getTheta());
1081 const double phi = pi.
constrain(fabs(pmt->getPhi()));
1083 size_t n0 = min(ns[
distance(buffer.cbegin(),pmt)], parameters.Nmax_PMT);
1085 job.Fill((
double) (140 + CDG[i].type), (
double) n0);
1090 const double Z = pmt->getZ() - z0 - dz;
1091 const double D = sqrt(R*R + Z*Z);
1092 const double cd = Z / D;
1094 const double t1 = CDG[i].function.getTime(D, cd, theta, phi, gRandom->Rndm());
1097 mc_hits.push_back(
JHit_t(mc_hits.size() + 1,
1101 t0 + (dz + D * getIndexOfRefraction()) / C + t1,
1108 if (std::accumulate(npe.begin(), npe.end(), 0.0) > NPE) {
1109 job.Fill((
double) (340 + CDG[i].type));
1113 catch(
const exception& error) {
1114 job.Fill((
double) (240 + CDG[i].type));
1120 if (!buffer.empty()) {
1131 if (!mc_hits.empty()) {
1133 mc_hits.
merge(parameters.Tmax_ns);
1135 event.mc_hits.resize(mc_hits.size());
1137 copy(mc_hits.begin(), mc_hits.end(), event.
mc_hits.begin());
1146 if (event.
mc_hits.size() >= numberOfHits) {