227 string fileDescriptor;
229 JFileRecorder <JTYPELIST<JAAnetTypes_t, JMetaTypes_t, JRootTypes_t>::typelist>
outputFile;
230 JLimit_t& numberOfEvents = inputFile.getLimit();
232 JCalibration_t calibrationFile;
257 JParser<> zap(
"Main program to simulate detector response to muons and showers.");
260 zap[
'F'] =
make_field(fileDescriptor,
"file name descriptor for CDF tables");
266 zap[
'T'] =
make_field(Tmax_s,
"dynamical update time [s]") = 100.0;
267 zap[
's'] =
make_field(writeEMShowers,
"store generated EM showers in event");
268 zap[
'N'] =
make_field(numberOfHits,
"minimum number of hits to output event") = 1;
269 zap[
'U'] =
make_field(factor,
"scaling factor applied to light yields") = 1.0;
275 catch(
const exception &error) {
276 FATAL(error.what() << endl);
283 const JMeta meta(argc, argv);
285 const double Zbed = 0.0;
290 if (fileDescriptor !=
"") {
291 CDF.push_back(JCDF_t(fileDescriptor, DIRECT_LIGHT_FROM_MUON));
292 CDF.push_back(JCDF_t(fileDescriptor, SCATTERED_LIGHT_FROM_MUON));
293 CDF.push_back(JCDF_t(fileDescriptor, DIRECT_LIGHT_FROM_DELTARAYS));
294 CDF.push_back(JCDF_t(fileDescriptor, SCATTERED_LIGHT_FROM_DELTARAYS));
296 CDG.push_back(JCDG_t(fileDescriptor, DIRECT_LIGHT_FROM_EMSHOWER));
297 CDG.push_back(JCDG_t(fileDescriptor, SCATTERED_LIGHT_FROM_EMSHOWER));
300 double maximal_road_width = 0.0;
301 double maximal_distance = 0.0;
303 for (
size_t i = 0; i != CDF.size(); ++i) {
305 DEBUG(
"Range CDF["<< CDF[i].type <<
"] " << CDF[i].function.intensity.getXmax() <<
" m" << endl);
307 maximal_road_width = max(maximal_road_width, CDF[i].function.intensity.getXmax());
310 for (
size_t i = 0; i != CDG.size(); ++i) {
312 DEBUG(
"Range CDG["<< CDG[i].type <<
"] " << CDG[i].function.intensity.getXmax() <<
" m" << endl);
315 maximal_road_width = max(maximal_road_width, CDG[i].function.intensity.getXmax());
318 maximal_distance = max(maximal_distance, CDG[i].function.intensity.getXmax());
321 NOTICE(
"Maximal road width [m] " << maximal_road_width << endl);
322 NOTICE(
"Maximal distance [m] " << maximal_distance << endl);
325 if (detectorFile ==
"" || inputFile.empty()) {
326 STATUS(
"Nothing to be done." << endl);
336 STATUS(
"Load detector... " << flush);
338 load(detectorFile, master.detector);
346 unique_ptr<JDynamics> dynamics;
348 if (!calibrationFile.empty()) {
352 dynamics.reset(
new JDynamics(master.detector, Tmax_s));
354 dynamics->load(calibrationFile);
356 catch(
const exception& error) {
361 const JDetector&
detector = (dynamics ? dynamics->getDetector() : master.detector);
368 STATUS(
"Setting up radiation tables... " << flush);
375 const JRadiation calcium (JSeaWater::Ca.Z, JSeaWater::Ca.A, 40, 0.01, 0.1, 0.1);
376 const JRadiation magnesium(JSeaWater::Mg.Z, JSeaWater::Mg.A, 40, 0.01, 0.1, 0.1);
377 const JRadiation potassium(JSeaWater::K .Z, JSeaWater::K .A, 40, 0.01, 0.1, 0.1);
378 const JRadiation sulphur (JSeaWater::S .Z, JSeaWater::S .A, 40, 0.01, 0.1, 0.1);
381 shared_ptr<JRadiation> Hydrogen (make_shared<JRadiationFunction>(hydrogen, 300, 0.2, 1.0e11));
382 shared_ptr<JRadiation> Oxygen (make_shared<JRadiationFunction>(oxygen, 300, 0.2, 1.0e11));
383 shared_ptr<JRadiation> Chlorine (make_shared<JRadiationFunction>(chlorine, 300, 0.2, 1.0e11));
384 shared_ptr<JRadiation> Sodium (make_shared<JRadiationFunction>(sodium, 300, 0.2, 1.0e11));
386 shared_ptr<JRadiation> Calcium (make_shared<JRadiationFunction>(calcium, 300, 0.2, 1.0e11));
387 shared_ptr<JRadiation> Magnesium(make_shared<JRadiationFunction>(magnesium,300, 0.2, 1.0e11));
388 shared_ptr<JRadiation> Potassium(make_shared<JRadiationFunction>(potassium,300, 0.2, 1.0e11));
389 shared_ptr<JRadiation> Sulphur (make_shared<JRadiationFunction>(sulphur, 300, 0.2, 1.0e11));
427 radiation.push_back(make_shared<JDeltaRaysSource>(200,
DENSITY_SEA_WATER, parameters.Tmin_GeV));
434 ionization.push_back(make_shared<JACoeffSource>(Calcium,
DENSITY_SEA_WATER * JSeaWater::Ca()));
435 ionization.push_back(make_shared<JACoeffSource>(Magnesium,
DENSITY_SEA_WATER * JSeaWater::Mg()));
436 ionization.push_back(make_shared<JACoeffSource>(Potassium,
DENSITY_SEA_WATER * JSeaWater::K()));
437 ionization.push_back(make_shared<JACoeffSource>(Sulphur,
DENSITY_SEA_WATER * JSeaWater::S()));
448 if (cylinder.
getZmin() < Zbed) {
452 NOTICE(
"Light generation volume: " << cylinder << endl);
460 header = inputFile.getHeader();
476 buffer.
detector.rbegin()->filename = detectorFile;
480 offset +=
Vec(cylinder.
getX(), cylinder.
getY(), 0.0);
517 copy(buffer, header);
523 NOTICE(
"Offset applied to true tracks is: " << offset << endl);
525 TH1D job(
"job", NULL, 400, 0.5, 400.5);
526 TProfile cpu(
"cpu", NULL, 16, 0.0, 8.0);
527 TProfile2D rms(
"rms", NULL, 16, 0.0, 8.0, 251, -0.5, 250.5);
528 TProfile2D rad(
"rad", NULL, 16, 0.0, 8.0, 251, -0.5, 250.5);
541 const double epsilon = 1.0e-6;
548 STATUS(
"event: " << setw(10) << in.getCounter() <<
'\r');
DEBUG(endl);
552 Evt* evt = in.next();
555 track->pos += offset;
560 event.mc_hits.clear();
565 FATAL(
"Monte Carlo event time undefined." << endl);
577 for (vector<Trk>::const_iterator track = evt->
mc_trks.begin(); track != evt->
mc_trks.end(); ++track) {
579 if (!track->is_finalstate()) {
595 double Zmin = intersection.first;
596 double Zmax = intersection.second;
598 if (Zmax - Zmin <= parameters.Dmin_m) {
602 JVertex vertex(0.0, track->t, track->E);
604 if (track->pos.z < Zbed) {
606 if (track->dir.z > 0.0)
607 vertex.
step(
gRock, (Zbed - track->pos.z) / track->dir.z);
612 if (vertex.
getZ() < Zmin) {
613 vertex.
step(gWater, Zmin - vertex.
getZ());
616 if (vertex.
getRange() <= parameters.Dmin_m) {
624 if (subdetector.empty()) {
632 while (vertex.
getE() >= parameters.Emin_GeV && vertex.
getZ() < Zmax) {
634 const int N = radiation.size();
639 for (
int i = 0; i != N; ++i) {
640 ls += li[i] = radiation[i]->getInverseInteractionLength(vertex.
getE());
647 for (
size_t i = 0; i != ionization.size(); ++i) {
648 As += ionization[i]->getA(vertex.
getE());
651 double step = gRandom->Exp(1.0) /
ls;
654 if (vertex.
getE() < parameters.Emax_GeV) {
655 if (parameters.Dmax_m < range) {
656 range = parameters.Dmax_m;
663 rms.Fill(log10(vertex.
getE()), (Double_t) 0, ts*ts);
667 vertex.
step(As, min(step,range));
673 if (vertex.
getE() >= parameters.Emin_GeV) {
675 double y = gRandom->Uniform(
ls);
677 for (
int i = 0; i != N; ++i) {
683 Es = radiation[i]->getEnergyOfShower(vertex.
getE());
684 ts = radiation[i]->getThetaRMS(vertex.
getE(), Es);
688 rms.Fill(log10(vertex.
getE()), (Double_t) radiation[i]->getID(), ts*ts);
689 rad.Fill(log10(vertex.
getE()), (Double_t) radiation[i]->getID(), Es);
697 vertex.
applyEloss(getRandomDirection(T2), Es);
699 muon.push_back(vertex);
710 muon.push_back(vertex);
717 make_predicate(&
Trk::id, track->id));
719 if (trk != event.
mc_trks.end()) {
720 trk->len = (muon.rbegin()->getZ() < Zmax ? +1 : -1) * (muon.rbegin()->getZ() - muon.begin()->getZ());
724 for (JDetector::const_iterator module = subdetector.begin(); module != subdetector.end(); ++module) {
726 if (module->empty()) {
730 const double z0 = muon.begin()->getZ();
731 const double t0 = muon.begin()->getT();
732 const double Z =
module->getZ() - module->getX() / getTanThetaC();
734 if (Z >= muon.begin()->getZ() && Z <= muon.rbegin()->getZ()) {
736 const JVector2D pos = muon.getPosition(Z);
737 const double R = hypot(module->getX() - pos.
getX(),
738 module->getY() - pos.
getY());
740 for (
size_t i = 0; i != CDF.size(); ++i) {
742 if (R < CDF[i].integral.getXmax()) {
752 const double NPE = CDF[i].integral.getNPE(R) *
module->size() * factor * W;
753 const size_t N = getPoisson(NPE);
759 for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) {
761 const double R = hypot(pmt->getX() - pos.
getX(),
762 pmt->getY() - pos.
getY());
763 const double theta = pi.
constrain(pmt->getTheta());
764 const double phi = pi.
constrain(fabs(pmt->getPhi()));
766 npe.push_back(CDF[i].function.getNPE(R, theta, phi) * factor * W);
771 for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) {
773 const double R = hypot(pmt->getX() - pos.
getX(),
774 pmt->getY() - pos.
getY());
775 const double Z = pmt->getZ() - z0;
776 const double theta = pi.
constrain(pmt->getTheta());
777 const double phi = pi.
constrain(fabs(pmt->getPhi()));
779 size_t n0 = min(ns[
distance(module->begin(),pmt)], parameters.Nmax_PMT);
781 job.Fill((
double) (100 + CDF[i].type), (
double) n0);
785 const double t1 = CDF[i].function.getTime(R, theta, phi, gRandom->Rndm());
788 mc_hits.push_back(
JHit_t(mc_hits.size() + 1,
792 t0 + (R * getTanThetaC() + Z) / C + t1,
799 if (std::accumulate(npe.begin(), npe.end(), 0.0) > NPE) {
800 job.Fill((
double) (300 + CDF[i].type));
804 catch(
const exception& error) {
805 job.Fill((
double) (200 + CDF[i].type));
812 for (JTrack::const_iterator vertex = muon.begin(); vertex != muon.end(); ++vertex) {
814 const double Es = vertex->
getEs();
816 if (Es >= parameters.Ecut_GeV) {
818 const double z0 = vertex->
getZ();
819 const double t0 = vertex->
getT();
822 int origin = track->id;
824 if (writeEMShowers) {
825 origin =
event.mc_trks.size() + 1;
828 int number_of_hits = 0;
830 JDetectorSubset_t::range_type range = subdetector.getRange(z0 - maximal_distance,
831 z0 + maximal_distance);
833 for (JDetector::const_iterator module = range.begin(); module != range.end(); ++module) {
835 if (module->empty()) {
839 const double R = hypot(module->getX() - vertex->
getX(),
840 module->getY() - vertex->
getY());
841 const double Z =
module->getZ() - z0 - DZ;
842 const double D = sqrt(R*R + Z*Z);
843 const double cd = Z / D;
845 for (
size_t i = 0; i != CDG.size(); ++i) {
847 if (D < CDG[i].integral.getXmax()) {
851 const double NPE = CDG[i].integral.getNPE(D, cd) * Es * module->size() * factor;
852 const size_t N = getPoisson(NPE);
858 for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) {
860 const double R = hypot(pmt->getX() - vertex->
getX(),
861 pmt->getY() - vertex->
getY());
862 const double Z = pmt->getZ() - z0 - DZ;
863 const double D = sqrt(R*R + Z*Z);
864 const double cd = Z / D;
865 const double theta = pi.
constrain(pmt->getTheta());
866 const double phi = pi.
constrain(fabs(pmt->getPhi()));
868 npe.push_back(CDG[i].function.getNPE(D, cd, theta, phi) * Es * factor);
873 for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) {
875 const double R = hypot(pmt->getX() - vertex->
getX(),
876 pmt->getY() - vertex->
getY());
877 const double theta = pi.
constrain(pmt->getTheta());
878 const double phi = pi.
constrain(fabs(pmt->getPhi()));
880 size_t n0 = min(ns[
distance(module->begin(),pmt)], parameters.Nmax_PMT);
882 job.Fill((
double) (100 + CDG[i].type), (
double) n0);
887 const double Z = pmt->getZ() - z0 - dz;
888 const double D = sqrt(R*R + Z*Z);
889 const double cd = Z / D;
891 const double t1 = CDG[i].function.getTime(D, cd, theta, phi, gRandom->Rndm());
894 mc_hits.push_back(
JHit_t(mc_hits.size() + 1,
903 number_of_hits += n1;
907 if (std::accumulate(npe.begin(), npe.end(), 0.0) > NPE) {
908 job.Fill((
double) (300 + CDG[i].type));
912 catch(
const exception& error) {
913 job.Fill((
double) (200 + CDG[i].type));
919 if (writeEMShowers && number_of_hits != 0) {
921 event.mc_trks.push_back(
JTrk_t(origin,
924 track->pos + track->dir * vertex->
getZ(),
932 }
else if (track->len > 0.0) {
940 const double z0 = 0.0;
941 const double z1 = z0 + track->len;
942 const double t0 = track->t;
943 const double E = track->E;
949 for (JDetector::const_iterator module =
detector.begin(); module !=
detector.end(); ++module) {
951 if (module->empty()) {
957 const double R = pos.
getX();
962 R > maximal_road_width) {
966 for (
size_t i = 0; i != CDF.size(); ++i) {
978 if (R < CDF[i].integral.getXmax()) {
982 const double NPE = CDF[i].integral.getNPE(R) *
module->size() * factor * W;
983 const size_t N = getPoisson(NPE);
993 for (JModule::const_iterator pmt = buffer.begin(); pmt != buffer.end(); ++pmt) {
995 const double R = pmt->getX();
996 const double theta = pi.
constrain(pmt->getTheta());
997 const double phi = pi.
constrain(fabs(pmt->getPhi()));
999 npe.push_back(CDF[i].function.getNPE(R, theta, phi) * factor * W);
1004 for (JModule::const_iterator pmt = buffer.begin(); pmt != buffer.end(); ++pmt) {
1006 const double R = pmt->getX();
1007 const double Z = pmt->getZ() - z0;
1008 const double theta = pi.
constrain(pmt->getTheta());
1009 const double phi = pi.
constrain(fabs(pmt->getPhi()));
1011 size_t n0 = min(ns[
distance(buffer.cbegin(),pmt)], parameters.Nmax_PMT);
1013 job.Fill((
double) (120 + CDF[i].type), (
double) n0);
1017 const double t1 = CDF[i].function.getTime(R, theta, phi, gRandom->Rndm());
1020 mc_hits.push_back(
JHit_t(mc_hits.size() + 1,
1024 t0 + (R * getTanThetaC() + Z) / C + t1,
1031 if (std::accumulate(npe.begin(), npe.end(), 0.0) > NPE) {
1032 job.Fill((
double) (320 + CDF[i].type));
1036 catch(
const exception& error) {
1037 job.Fill((
double) (220 + CDF[i].type));
1043 if (!buffer.empty()) {
1057 double E = track->E;
1062 catch(
const exception& error) {
1063 ERROR(error.what() << endl);
1066 E =
pythia(track->type, E);
1070 const double z0 = 0.0;
1071 const double t0 = track->t;
1078 for (JDetector::const_iterator module =
detector.begin(); module !=
detector.end(); ++module) {
1080 if (module->empty()) {
1086 const double R = pos.
getX();
1087 const double Z = pos.
getZ() - z0 - DZ;
1088 const double D = sqrt(R*R + Z*Z);
1089 const double cd = Z / D;
1091 for (
size_t i = 0; i != CDG.size(); ++i) {
1093 if (D < CDG[i].integral.getXmax()) {
1097 const double NPE = CDG[i].integral.getNPE(D, cd) * E * module->size() * factor;
1098 const size_t N = getPoisson(NPE);
1108 for (JModule::const_iterator pmt = buffer.begin(); pmt != buffer.end(); ++pmt) {
1110 const double R = pmt->getX();
1111 const double Z = pmt->getZ() - z0 - DZ;
1112 const double D = sqrt(R*R + Z*Z);
1113 const double cd = Z / D;
1114 const double theta = pi.
constrain(pmt->getTheta());
1115 const double phi = pi.
constrain(fabs(pmt->getPhi()));
1117 npe.push_back(CDG[i].function.getNPE(D, cd, theta, phi) * E * factor);
1122 for (JModule::const_iterator pmt = buffer.begin(); pmt != buffer.end(); ++pmt) {
1124 const double theta = pi.
constrain(pmt->getTheta());
1125 const double phi = pi.
constrain(fabs(pmt->getPhi()));
1127 size_t n0 = min(ns[
distance(buffer.cbegin(),pmt)], parameters.Nmax_PMT);
1129 job.Fill((
double) (140 + CDG[i].type), (
double) n0);
1134 const double Z = pmt->getZ() - z0 - dz;
1135 const double D = sqrt(R*R + Z*Z);
1136 const double cd = Z / D;
1138 const double t1 = CDG[i].function.getTime(D, cd, theta, phi, gRandom->Rndm());
1141 mc_hits.push_back(
JHit_t(mc_hits.size() + 1,
1145 t0 + (dz + D * getIndexOfRefraction()) / C + t1,
1152 if (std::accumulate(npe.begin(), npe.end(), 0.0) > NPE) {
1153 job.Fill((
double) (340 + CDG[i].type));
1157 catch(
const exception& error) {
1158 job.Fill((
double) (240 + CDG[i].type));
1164 if (!buffer.empty()) {
1175 if (!mc_hits.empty()) {
1177 mc_hits.
merge(parameters.Tmax_ns);
1179 event.mc_hits.resize(mc_hits.size());
1181 copy(mc_hits.begin(), mc_hits.end(), event.
mc_hits.begin());
1190 if (event.
mc_hits.size() >= numberOfHits) {