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);
678 muon.push_back(vertex);
685 make_predicate(&
Trk::id, track->id));
687 if (trk != event.
mc_trks.end()) {
688 trk->len = (muon.rbegin()->getZ() < Zmax ? +1 : -1) * (muon.rbegin()->getZ() - muon.begin()->getZ());
692 for (JDetector::const_iterator module = subdetector.begin(); module != subdetector.end(); ++module) {
694 const double z0 = muon.begin()->getZ();
695 const double t0 = muon.begin()->getT();
696 const double Z =
module->getZ() - module->getX() / getTanThetaC();
698 if (Z >= muon.begin()->getZ() && Z <= muon.rbegin()->getZ()) {
700 const JVector2D pos = muon.getPosition(Z);
701 const double R = hypot(module->getX() - pos.
getX(),
702 module->getY() - pos.
getY());
704 for (
size_t i = 0; i != CDF.size(); ++i) {
706 if (R < CDF[i].integral.getXmax()) {
717 const double NPE = CDF[i].integral.getNPE(R) *
module->size() * factor * W;
718 const size_t N = getPoisson(NPE);
724 for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) {
726 const double R = hypot(pmt->getX() - pos.
getX(),
727 pmt->getY() - pos.
getY());
728 const double theta = pi.
constrain(pmt->getTheta());
729 const double phi = pi.
constrain(fabs(pmt->getPhi()));
731 npe.push_back(CDF[i].function.getNPE(R, theta, phi) * factor * W);
736 for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) {
738 const double R = hypot(pmt->getX() - pos.
getX(),
739 pmt->getY() - pos.
getY());
740 const double Z = pmt->getZ() - z0;
741 const double theta = pi.
constrain(pmt->getTheta());
742 const double phi = pi.
constrain(fabs(pmt->getPhi()));
744 size_t n0 = min(ns[
distance(module->begin(),pmt)], parameters.Nmax_PMT);
746 job.Fill((
double) (100 + CDF[i].type), (
double) n0);
750 const double t1 = CDF[i].function.getTime(R, theta, phi, gRandom->Rndm());
753 mc_hits.push_back(
JHit_t(mc_hits.size() + 1,
757 t0 + (R * getTanThetaC() + Z) / C + t1,
764 if (std::accumulate(npe.begin(), npe.end(), 0.0) > NPE) {
765 job.Fill((
double) (300 + CDF[i].type));
769 catch(
const exception& error) {
770 job.Fill((
double) (200 + CDF[i].type));
777 for (JTrack::const_iterator vertex = muon.begin(); vertex != muon.end(); ++vertex) {
779 const double Es = vertex->
getEs();
781 if (Es >= parameters.Ecut_GeV) {
783 const double z0 = vertex->
getZ();
784 const double t0 = vertex->
getT();
787 int origin = track->id;
789 if (writeEMShowers) {
790 origin =
event.mc_trks.size() + 1;
793 int number_of_hits = 0;
795 JDetectorSubset_t::range_type range = subdetector.getRange(z0 - maximal_distance,
796 z0 + maximal_distance);
798 for (JDetector::const_iterator module = range.begin(); module != range.end(); ++module) {
800 const double R = hypot(module->getX() - vertex->
getX(),
801 module->getY() - vertex->
getY());
802 const double Z =
module->getZ() - z0 - DZ;
803 const double D = sqrt(R*R + Z*Z);
804 const double cd = Z / D;
806 for (
size_t i = 0; i != CDG.size(); ++i) {
808 if (D < CDG[i].integral.getXmax()) {
812 const double NPE = CDG[i].integral.getNPE(D, cd) * Es * module->size() * factor;
813 const size_t N = getPoisson(NPE);
819 for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) {
821 const double R = hypot(pmt->getX() - vertex->
getX(),
822 pmt->getY() - vertex->
getY());
823 const double Z = pmt->getZ() - z0 - DZ;
824 const double D = sqrt(R*R + Z*Z);
825 const double cd = Z / D;
826 const double theta = pi.
constrain(pmt->getTheta());
827 const double phi = pi.
constrain(fabs(pmt->getPhi()));
829 npe.push_back(CDG[i].function.getNPE(D, cd, theta, phi) * Es * factor);
834 for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) {
836 const double R = hypot(pmt->getX() - vertex->
getX(),
837 pmt->getY() - vertex->
getY());
838 const double theta = pi.
constrain(pmt->getTheta());
839 const double phi = pi.
constrain(fabs(pmt->getPhi()));
841 size_t n0 = min(ns[
distance(module->begin(),pmt)], parameters.Nmax_PMT);
843 job.Fill((
double) (100 + CDG[i].type), (
double) n0);
848 const double Z = pmt->getZ() - z0 - dz;
849 const double D = sqrt(R*R + Z*Z);
850 const double cd = Z / D;
852 const double t1 = CDG[i].function.getTime(D, cd, theta, phi, gRandom->Rndm());
855 mc_hits.push_back(
JHit_t(mc_hits.size() + 1,
864 number_of_hits += n1;
868 if (std::accumulate(npe.begin(), npe.end(), 0.0) > NPE) {
869 job.Fill((
double) (300 + CDG[i].type));
873 catch(
const exception& error) {
874 job.Fill((
double) (200 + CDG[i].type));
880 if (writeEMShowers && number_of_hits != 0) {
882 event.mc_trks.push_back(
JTrk_t(origin,
885 track->pos + track->dir * vertex->
getZ(),
893 }
else if (track->len > 0.0) {
901 const double z0 = 0.0;
902 const double z1 = z0 + track->len;
903 const double t0 = track->t;
904 const double E = track->E;
910 for (JDetector::const_iterator module =
detector.begin(); module !=
detector.end(); ++module) {
914 const double R = pos.
getX();
919 R > maximal_road_width) {
923 for (
size_t i = 0; i != CDF.size(); ++i) {
935 if (R < CDF[i].integral.getXmax()) {
939 const double NPE = CDF[i].integral.getNPE(R) *
module->size() * factor * W;
940 const size_t N = getPoisson(NPE);
950 for (JModule::const_iterator pmt = buffer.begin(); pmt != buffer.end(); ++pmt) {
952 const double R = pmt->getX();
953 const double theta = pi.
constrain(pmt->getTheta());
954 const double phi = pi.
constrain(fabs(pmt->getPhi()));
956 npe.push_back(CDF[i].function.getNPE(R, theta, phi) * factor * W);
961 for (JModule::const_iterator pmt = buffer.begin(); pmt != buffer.end(); ++pmt) {
963 const double R = pmt->getX();
964 const double Z = pmt->getZ() - z0;
965 const double theta = pi.
constrain(pmt->getTheta());
966 const double phi = pi.
constrain(fabs(pmt->getPhi()));
968 size_t n0 = min(ns[
distance(buffer.cbegin(),pmt)], parameters.Nmax_PMT);
970 job.Fill((
double) (120 + CDF[i].type), (
double) n0);
974 const double t1 = CDF[i].function.getTime(R, theta, phi, gRandom->Rndm());
977 mc_hits.push_back(
JHit_t(mc_hits.size() + 1,
981 t0 + (R * getTanThetaC() + Z) / C + t1,
988 if (std::accumulate(npe.begin(), npe.end(), 0.0) > NPE) {
989 job.Fill((
double) (320 + CDF[i].type));
993 catch(
const exception& error) {
994 job.Fill((
double) (220 + CDF[i].type));
1000 if (!buffer.empty()) {
1014 double E = track->E;
1019 catch(
const exception& error) {
1020 ERROR(error.what() << endl);
1023 E =
pythia(track->type, E);
1027 const double z0 = 0.0;
1028 const double t0 = track->t;
1035 for (JDetector::const_iterator module =
detector.begin(); module !=
detector.end(); ++module) {
1039 const double R = pos.
getX();
1040 const double Z = pos.
getZ() - z0 - DZ;
1041 const double D = sqrt(R*R + Z*Z);
1042 const double cd = Z / D;
1044 for (
size_t i = 0; i != CDG.size(); ++i) {
1046 if (D < CDG[i].integral.getXmax()) {
1050 const double NPE = CDG[i].integral.getNPE(D, cd) * E * module->size() * factor;
1051 const size_t N = getPoisson(NPE);
1061 for (JModule::const_iterator pmt = buffer.begin(); pmt != buffer.end(); ++pmt) {
1063 const double R = pmt->getX();
1064 const double Z = pmt->getZ() - z0 - DZ;
1065 const double D = sqrt(R*R + Z*Z);
1066 const double cd = Z / D;
1067 const double theta = pi.
constrain(pmt->getTheta());
1068 const double phi = pi.
constrain(fabs(pmt->getPhi()));
1070 npe.push_back(CDG[i].function.getNPE(D, cd, theta, phi) * E * factor);
1075 for (JModule::const_iterator pmt = buffer.begin(); pmt != buffer.end(); ++pmt) {
1077 const double theta = pi.
constrain(pmt->getTheta());
1078 const double phi = pi.
constrain(fabs(pmt->getPhi()));
1080 size_t n0 = min(ns[
distance(buffer.cbegin(),pmt)], parameters.Nmax_PMT);
1082 job.Fill((
double) (140 + CDG[i].type), (
double) n0);
1087 const double Z = pmt->getZ() - z0 - dz;
1088 const double D = sqrt(R*R + Z*Z);
1089 const double cd = Z / D;
1091 const double t1 = CDG[i].function.getTime(D, cd, theta, phi, gRandom->Rndm());
1094 mc_hits.push_back(
JHit_t(mc_hits.size() + 1,
1098 t0 + (dz + D * getIndexOfRefraction()) / C + t1,
1105 if (std::accumulate(npe.begin(), npe.end(), 0.0) > NPE) {
1106 job.Fill((
double) (340 + CDG[i].type));
1110 catch(
const exception& error) {
1111 job.Fill((
double) (240 + CDG[i].type));
1117 if (!buffer.empty()) {
1128 if (!mc_hits.empty()) {
1130 mc_hits.
merge(parameters.Tmax_ns);
1132 event.mc_hits.resize(mc_hits.size());
1134 copy(mc_hits.begin(), mc_hits.end(), event.
mc_hits.begin());
1143 if (event.
mc_hits.size() >= numberOfHits) {