159 #include "art_root_io/TFileService.h" 160 #include "cetlib_except/exception.h" 175 #include "TDatabasePDG.h" 178 #include "CLHEP/Random/RandFlat.h" 179 #include "CLHEP/Random/RandGaussQ.h" 203 void SampleOne(
unsigned int i,
simb::MCTruth& mct, CLHEP::HepRandomEngine& engine);
205 void initialization(
double theta1,
215 void sampling(
double&
E,
219 CLHEP::HepRandomEngine& engine);
221 static const int kGAUS = 1;
287 double Energy, phi, theta, dep,
Time;
288 double Momentum, px0, py0,
pz0;
289 double x0, y0,
z0, cx, cy, cz;
297 double spmu[121][62][51];
299 double depth[360][91];
309 unsigned int NEvents = 0;
333 :
art::EDProducer{pset}
339 ,
fPDG{pset.get<
int>(
"PDG")}
341 ,
fInputDir{pset.get<std::string>(
"InputDir")}
347 ,
fEmin{pset.get<
double>(
"Emin")}
348 ,
fEmax{pset.get<
double>(
"Emax")}
349 ,
fThetamin{pset.get<
double>(
"Thetamin")}
350 ,
fThetamax{pset.get<
double>(
"Thetamax")}
351 ,
fPhimin{pset.get<
double>(
"Phimin")}
352 ,
fPhimax{pset.get<
double>(
"Phimax")}
353 ,
figflag{pset.get<
int>(
"igflag")}
354 ,
fXmin{pset.get<
double>(
"Xmin")}
355 ,
fYmin{pset.get<
double>(
"Ymin")}
356 ,
fZmin{pset.get<
double>(
"Zmin")}
357 ,
fXmax{pset.get<
double>(
"Xmax")}
358 ,
fYmax{pset.get<
double>(
"Ymax")}
359 ,
fZmax{pset.get<
double>(
"Zmax")}
360 ,
fDetRotX{pset.get<
double>(
"DetRotX")}
361 ,
fDetRotY{pset.get<
double>(
"DetRotY")}
362 ,
fDetRotZ{pset.get<
double>(
"DetRotZ")}
363 ,
fT0{pset.get<
double>(
"T0")}
364 ,
fSigmaT{pset.get<
double>(
"SigmaT")}
365 ,
fTDist{pset.get<
int>(
"TDist")}
367 produces<std::vector<simb::MCTruth>>();
368 produces<sumdata::RunData, art::InRun>();
382 <<
", Z = " <<
fDetRotZ << std::endl;
405 fTree = tfs->make<TTree>(
"Generator",
"analysis tree");
409 fTree->Branch(
"posX", &
x0,
"posX/D");
410 fTree->Branch(
"posY", &
y0,
"posY/D");
411 fTree->Branch(
"posZ", &
z0,
"posZ/D");
412 fTree->Branch(
"cosX", &
cx,
"cosX/D");
413 fTree->Branch(
"cosY", &
cy,
"cosY/D");
414 fTree->Branch(
"cosZ", &
cz,
"cosZ/D");
416 fTree->Branch(
"phi", &
phi,
"phi/D");
417 fTree->Branch(
"depth", &
dep,
"dep/D");
440 <<
"\nThetamax has to be less than " << M_PI / 2 <<
", but was entered as " <<
fThetamax 441 <<
", this causes an error so leaving program now...\n\n";
444 <<
"\nThetamin has to be more than 0, but was entered as " <<
fThetamin 445 <<
", this causes an error so leaving program now...\n\n";
447 throw cet::exception(
"MUSUNGen") <<
"\nMinimum angle is bigger than maximum angle....causes " 448 "an error so leaving program now....\n\n";
451 <<
"\nPhimax has to be less than " << 2 * M_PI <<
", but was entered as " <<
fPhimax 452 <<
", this cause an error so leaving program now...\n\n";
455 <<
"\nPhimin has to be more than 0, but was entered as " <<
fPhimin 456 <<
", this causes an error so leaving program now...\n\n";
458 throw cet::exception(
"MUSUNGen") <<
"\nMinimum angle is bigger than maximum angle....causes " 459 "an error so leaving program now....\n\n";
462 <<
"\nMinimum energy is bigger than maximum energy....causes an error so leaving program " 480 std::cout <<
"Material - SURF rock" << std::endl;
481 std::cout <<
"Density = " <<
fRockDensity <<
" g/cm^3" << std::endl;
482 std::cout <<
"Parameters for muon spectrum are from LVD best fit" << std::endl;
483 std::cout <<
"Muon energy range = " <<
fEmin <<
" - " <<
fEmax <<
" GeV" << std::endl;
486 std::cout <<
"Azimuthal angle range = " <<
fPhimin <<
" - " << fPhimax <<
" degrees" 488 std::cout <<
"Global intensity = " <<
FI 489 <<
" (cm^2 s)^(-1) or s^(-1) (for muons on the surface)" << std::endl;
522 std::cout <<
"\n\nNumber of muons = " <<
NEvents << std::endl;
523 std::cout <<
"Mean muon energy = " <<
se /
NEvents <<
" GeV" << std::endl;
524 std::cout <<
"Mean zenith angle (theta) = " <<
st /
NEvents <<
" degrees" << std::endl;
525 std::cout <<
"Mean azimuthal angle (phi)= " <<
sp /
NEvents <<
" degrees" << std::endl;
526 std::cout <<
"Mean slant depth = " <<
sd /
NEvents <<
" m w.e." << std::endl;
534 std::unique_ptr<std::vector<simb::MCTruth>> truthcol(
new std::vector<simb::MCTruth>);
545 truthcol->push_back(truth);
547 evt.
put(std::move(truthcol));
556 CLHEP::RandFlat flat(engine);
557 CLHEP::RandGaussQ gauss(engine);
574 if (
phi >= 360.)
phi -= 360.;
579 int trackid = -1 * (i + 1);
580 std::string primary(
"primary");
586 double pdgfire = flat.fire();
589 static TDatabasePDG pdgt;
590 TParticlePDG* pdgp = pdgt.GetParticle(
PdgCode);
591 if (pdgp) m = pdgp->Mass();
621 double ss = sh1 + sv1 + sv2;
622 double xfl1 = flat.fire();
623 if (xfl1 <= sh1 / ss) {
628 else if (xfl1 <= (sh1 + sv1) / ss) {
721 int lineNumber = 0, index = 0;
722 char inputLine[10000];
723 std::string fROOTfile;
725 for (
int a = 0; a < 121; ++a)
726 for (
int b = 0; b < 62; ++b)
727 for (
int c = 0; c < 50; ++c)
729 for (
int a = 0; a < 23401; ++a)
731 for (
int a = 0; a < 360; ++a)
732 for (
int b = 0; b < 91; ++b)
734 for (
int a = 0; a < 360; ++a)
735 for (
int b = 0; b < 91; ++b)
738 std::ostringstream File1LocStream;
740 std::string File1Loc = File1LocStream.str();
741 cet::search_path sp1(
"FW_SEARCH_PATH");
742 if (sp1.find_file(fInputFile1, fROOTfile)) File1Loc = fROOTfile;
746 <<
"\nFile1 " << fInputFile1 <<
" not found in FW_SEARCH_PATH or at " <<
fInputDir 749 while (file1.good()) {
751 file1.getline(inputLine, 9999);
753 token = strtok(inputLine,
" ");
754 while (token != NULL) {
756 fmu[index][lineNumber] = atof(token);
757 token = strtok(NULL,
" ");
768 std::ostringstream File2LocStream;
770 std::string File2Loc = File2LocStream.str();
771 cet::search_path sp2(
"FW_SEARCH_PATH");
772 if (sp2.find_file(fInputFile2, fROOTfile)) File2Loc = fROOTfile;
773 std::ifstream file2(File2Loc.c_str(), std::ios::binary |
std::ios::in);
776 <<
"\nFile2 " << fInputFile2 <<
" not found in FW_SEARCH_PATH or at " << fInputDir
779 int i1 = 0, i2 = 0, i3 = 0;
781 while (file2.good()) {
783 file2.read((
char*)(&readVal),
sizeof(
float));
784 spmu[i1][i2][i3] = readVal;
798 for (
int i = 0; i < 120; i++)
799 for (
int j = 0; j < 62; j++)
800 for (
int k = 0; k < 51; k++)
802 spmu[1][1][0] = 0.000853544;
805 std::ostringstream File3LocStream;
807 std::string File3Loc = File3LocStream.str();
808 cet::search_path sp3(
"FW_SEARCH_PATH");
809 if (sp3.find_file(fInputFile3, fROOTfile)) File3Loc = fROOTfile;
813 <<
"\nFile3 " << fInputFile3 <<
" not found in FW_SEARCH_PATH or at " << fInputDir
816 lineNumber = index = 0;
817 while (file3.good()) {
819 file3.getline(inputLine, 9999);
821 token = strtok(inputLine,
" ");
822 while (token != NULL) {
824 depth[index][lineNumber] = atof(token);
825 token = strtok(NULL,
" ");
845 ph1 = M_PI / 180. * phi1;
846 ph2 = M_PI / 180. * phi2;
851 double theta = theta1;
855 while (theta < theta2 - dc / 2.) {
857 double theta0 = M_PI / 180. *
theta;
858 double cc = cos(theta0);
859 double ash = s_hor * cc;
860 double asv01 = s_ver1 * sqrt(1. - cc * cc);
861 double asv02 = s_ver2 * sqrt(1. - cc * cc);
862 int ic1 = (theta + 0.999);
864 if (ic2 > 91) ic2 = 91;
865 if (ic1 < 1) ic1 = 1;
869 while (phi < phi2 - dp / 2.) {
877 double asv1 = asv01 * fabs(cos(phi0));
878 double asv2 = asv02 * fabs(sin(phi0));
879 double asv0 = ash + asv1 + asv2;
881 if (figflag == 1) fl = asv0;
882 int ip1 = (phi + 0.999);
884 if (ip2 > 360) ip2 = 1;
885 if (ip1 < 1) ip1 = 360;
888 for (
int ii = 0; ii < 4; ii++) {
891 if (ip1 == 360 && (ii == 1 || ii == 3)) iip = -359;
892 if (
fmu[ip1 + iip - 1][ic1 + iic - 1] < 0) {
893 if (pow(10.,
fmu[ip1 + iip - 1][ic1 + iic - 1]) / 4 > 1
e-6) {
894 std::cout <<
"Looking at fmu [ " << ip1 <<
" + " << iip <<
" - 1 (" << ip1 + iip - 1
895 <<
") ] [ " << ic1 <<
" + " << iic <<
" - 1 (" << ic1 + iic - 1 <<
") ] ." 896 <<
"\nChanging sp1 from " << sp1 <<
" to " 897 << sp1 + pow(10.,
fmu[ip1 + iip - 1][ic1 + iic - 1]) / 4 <<
"..........." 898 << sp1 <<
" + 10 ^ (" <<
fmu[ip1 + iip - 1][ic1 + iic - 1] <<
") / 4 " 901 sp1 = sp1 + pow(10.,
fmu[ip1 + iip - 1][ic1 + iic - 1]) / 4;
908 sc = sc + sp1 * fl * dp * M_PI / 180. * sin(theta0) * dc * M_PI / 180.;
915 theta = theta + dc / 2.;
919 for (
int ipc1 = 0; ipc1 < ipc; ipc1++)
930 CLHEP::HepRandomEngine& engine)
932 CLHEP::RandFlat flat(engine);
933 CLHEP::RandGaussQ gauss(engine);
935 #if 0 // this code is disabled for good 936 double xfl = flat.fire();
937 int loIndex = 0, hiIndex = 32400;
938 int i = (loIndex+hiIndex)/2;
939 bool foundIndex =
false;
940 if( xfl <
fnmu[loIndex] ) {
943 }
else if ( xfl >
fnmu[hiIndex] ) {
946 }
else if ( xfl >
fnmu[i-1] && xfl <=
fnmu[i] )
948 while( !foundIndex ) {
953 i = (loIndex + hiIndex)/2;
955 if( xfl >
fnmu[i-1] && xfl <=
fnmu[i] )
959 double xfl = flat.fire();
961 while (xfl >
fnmu[i])
964 int ic = (i - 2) / 360;
965 int ip = i - 2 - ic * 360;
968 theta =
the1 + ((double)ic + xfl);
970 phi =
ph1 + ((double)ip + xfl);
971 if (phi > 360) phi = phi - 360;
974 int ic1 = cos(M_PI / 180. * theta) * 50.;
975 if (ic1 < 0) ic1 = 0;
976 if (ic1 > 50) ic1 = 50;
977 int ip1 = dep / 200. - 16;
978 if (ip1 < 0) ip1 = 0;
979 if (ip1 > 61) ip1 = 61;
983 loIndex = 0, hiIndex = 120;
984 int j = (loIndex+hiIndex)/2;
986 if( xfl <
spmu[loIndex][ip1][ic1] ) {
989 }
else if ( xfl >
spmu[hiIndex][ip1][ic1] ) {
992 }
else if ( xfl >
spmu[j-1][ip1][ic1] && xfl <=
spmu[j][ip1][ic1] )
994 while( !foundIndex ) {
995 if( xfl <
spmu[j][ip1][ic1] )
999 j = (loIndex + hiIndex)/2;
1001 if( xfl >
spmu[j-1][ip1][ic1] && xfl <=
spmu[j][ip1][ic1] )
1006 while (xfl >
spmu[j][ip1][ic1])
1010 double En1 = 0.05 * (j - 1);
1011 double En2 = 0.05 * (j);
1012 E = pow(10., En1 + (En2 - En1) * flat.fire());
base_engine_t & createEngine(seed_t seed)
double fEmax
Maximum Kinetic Energy (GeV)
void beginRun(art::Run &run)
double fZmax
Maximum Z position.
double fYmax
Maximum Y position.
double fDetRotZ
How much the detector should be rotated around Z axis (rotates the coordinate system clockwise)) ...
double fCavernAngle
Angle of the detector from the North to the East.
void AddTrajectoryPoint(TLorentzVector const &position, TLorentzVector const &momentum)
void SetOrigin(simb::Origin_t origin)
double fEmin
Minimum Kinetic Energy (GeV)
double fThetamin
Minimum theta.
std::string fInputDir
Input Directory.
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
double fDetRotY
How much the detector should be rotated around Y axis (rotates the coordinate system clockwise)) ...
double fT0
Central t position (ns) in world coordinates.
double fDetRotX
How much the detector should be rotated around X axis (rotates the coordinate system clockwise)) ...
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
int fTDist
How to distribute t (gaus, or uniform)
int fPDG
PDG code of particles to generate.
#define DEFINE_ART_MODULE(klass)
void endRun(art::Run &run)
double fPhimax
Maximum phi.
single particles thrown at the detector
std::string fInputFile3
Input File 3.
double fPhimin
Minimum phi.
double fChargeRatio
Charge ratio of particle / anti-particle.
std::string fInputFile2
Input File 2.
An art service to assist in the distribution of guaranteed unique seeds to all engines within an art ...
int figflag
If want sampled from sphere or parallelepiped.
module to produce single or multiple specified particles in the detector
void initialization(double theta1, double theta2, double phi1, double phi2, int figflag, double s_hor, double s_ver1, double s_ver2, double &FI)
void SampleOne(unsigned int i, simb::MCTruth &mct, CLHEP::HepRandomEngine &engine)
double fYmin
Minimum Y position.
void Add(simb::MCParticle const &part)
double fZmin
Minimum Z position.
double fSigmaT
Variation in t position (ns)
CLHEP::HepRandomEngine & fEngine
art-managed random-number engine
double fThetamax
Maximum theta.
double fXmin
Minimum X position.
std::string const & DetectorName() const
Returns a string with the name of the detector, as configured.
void produce(art::Event &evt)
Event generator information.
#define MF_LOG_WARNING(category)
Namespace collecting geometry-related classes utilities.
void sampling(double &E, double &theta, double &phi, double &dep, CLHEP::HepRandomEngine &engine)
Event Generation using GENIE, cosmics or single particles.
std::string fInputFile1
Input File 1.
art framework interface to geometry description
cet::coded_exception< error, detail::translate > exception
double fXmax
Maximum X position.