158 #include "art_root_io/TFileService.h" 159 #include "cetlib_except/exception.h" 164 #include "nurandom/RandomUtils/NuRandomService.h" 174 #include "TDatabasePDG.h" 177 #include "CLHEP/Random/RandFlat.h" 178 #include "CLHEP/Random/RandGaussQ.h" 202 void SampleOne(
unsigned int i,
simb::MCTruth& mct, CLHEP::HepRandomEngine& engine);
204 void initialization(
double theta1,
214 void sampling(
double&
E,
218 CLHEP::HepRandomEngine& engine);
220 static const int kGAUS = 1;
287 double spmu[121][62][51];
289 double depth[360][91];
299 unsigned int NEvents = 0;
323 :
art::EDProducer{pset}
327 ,
fPDG{pset.get<
int>(
"PDG")}
335 ,
fEmin{pset.get<
double>(
"Emin")}
336 ,
fEmax{pset.get<
double>(
"Emax")}
337 ,
fThetamin{pset.get<
double>(
"Thetamin")}
338 ,
fThetamax{pset.get<
double>(
"Thetamax")}
339 ,
fPhimin{pset.get<
double>(
"Phimin")}
340 ,
fPhimax{pset.get<
double>(
"Phimax")}
341 ,
figflag{pset.get<
int>(
"igflag")}
342 ,
fXmin{pset.get<
double>(
"Xmin")}
343 ,
fYmin{pset.get<
double>(
"Ymin")}
344 ,
fZmin{pset.get<
double>(
"Zmin")}
345 ,
fXmax{pset.get<
double>(
"Xmax")}
346 ,
fYmax{pset.get<
double>(
"Ymax")}
347 ,
fZmax{pset.get<
double>(
"Zmax")}
348 ,
fT0{pset.get<
double>(
"T0")}
349 ,
fSigmaT{pset.get<
double>(
"SigmaT")}
350 ,
fTDist{pset.get<
int>(
"TDist")}
352 produces<std::vector<simb::MCTruth>>();
353 produces<sumdata::RunData, art::InRun>();
383 fTree = tfs->make<TTree>(
"Generator",
"analysis tree");
387 fTree->Branch(
"posX", &
x0,
"posX/D");
388 fTree->Branch(
"posY", &
y0,
"posY/D");
389 fTree->Branch(
"posZ", &
z0,
"posZ/D");
390 fTree->Branch(
"cosX", &
cx,
"cosX/D");
391 fTree->Branch(
"cosY", &
cy,
"cosY/D");
392 fTree->Branch(
"cosZ", &
cz,
"cosZ/D");
394 fTree->Branch(
"phi", &
phi,
"phi/D");
395 fTree->Branch(
"depth", &
dep,
"dep/D");
419 <<
"\nThetamax has to be less than " <<
M_PI / 2 <<
", but was entered as " <<
fThetamax 420 <<
", this causes an error so leaving program now...\n\n";
423 <<
"\nThetamin has to be more than 0, but was entered as " <<
fThetamin 424 <<
", this causes an error so leaving program now...\n\n";
426 throw cet::exception(
"MUSUNGen") <<
"\nMinimum angle is bigger than maximum angle....causes " 427 "an error so leaving program now....\n\n";
430 <<
"\nPhimax has to be less than " << 2 *
M_PI <<
", but was entered as " <<
fPhimax 431 <<
", this cause an error so leaving program now...\n\n";
434 <<
"\nPhimin has to be more than 0, but was entered as " <<
fPhimin 435 <<
", this causes an error so leaving program now...\n\n";
437 throw cet::exception(
"MUSUNGen") <<
"\nMinimum angle is bigger than maximum angle....causes " 438 "an error so leaving program now....\n\n";
441 <<
"\nMinimum energy is bigger than maximum energy....causes an error so leaving program " 459 std::cout <<
"Material - SURF rock" <<
std::endl;
461 std::cout <<
"Parameters for muon spectrum are from LVD best fit" <<
std::endl;
465 std::cout <<
"Azimuthal angle range = " <<
fPhimin <<
" - " << fPhimax <<
" degrees" 467 std::cout <<
"Global intensity = " <<
FI 468 <<
" (cm^2 s)^(-1) or s^(-1) (for muons on the surface)" <<
std::endl;
504 std::cout <<
"Mean zenith angle (theta) = " <<
st /
NEvents <<
" degrees" <<
std::endl;
505 std::cout <<
"Mean azimuthal angle (phi)= " <<
sp /
NEvents <<
" degrees" <<
std::endl;
515 std::unique_ptr<std::vector<simb::MCTruth>> truthcol(
new std::vector<simb::MCTruth>);
526 truthcol->push_back(truth);
538 CLHEP::RandFlat
flat(engine);
539 CLHEP::RandGaussQ
gauss(engine);
556 if (
phi >= 360.)
phi -= 360.;
561 int trackid = -1 * (i + 1);
568 double pdgfire = flat.fire();
571 static TDatabasePDG pdgt;
572 TParticlePDG* pdgp = pdgt.GetParticle(
PdgCode);
573 if (pdgp) m = pdgp->Mass();
598 double ss = sh1 + sv1 + sv2;
599 double xfl1 = flat.fire();
600 if (xfl1 <= sh1 / ss) {
605 else if (xfl1 <= (sh1 + sv1) / ss) {
694 int lineNumber = 0,
index = 0;
695 char inputLine[10000];
698 for (
int a = 0;
a < 121; ++
a)
699 for (
int b = 0;
b < 62; ++
b)
700 for (
int c = 0;
c < 50; ++
c)
702 for (
int a = 0;
a < 23401; ++
a)
704 for (
int a = 0;
a < 360; ++
a)
705 for (
int b = 0;
b < 91; ++
b)
707 for (
int a = 0;
a < 360; ++
a)
708 for (
int b = 0;
b < 91; ++
b)
711 std::ostringstream File1LocStream;
715 if (sp1.
find_file(fInputFile1, fROOTfile)) File1Loc = fROOTfile;
716 std::ifstream file1(File1Loc.c_str(), std::ios::in);
719 <<
"\nFile1 " << fInputFile1 <<
" not found in FW_SEARCH_PATH or at " <<
fInputDir 722 while (file1.good()) {
724 file1.getline(inputLine, 9999);
726 token = strtok(inputLine,
" ");
727 while (token != NULL) {
729 fmu[
index][lineNumber] = atof(token);
730 token = strtok(NULL,
" ");
741 std::ostringstream File2LocStream;
745 if (sp2.
find_file(fInputFile2, fROOTfile)) File2Loc = fROOTfile;
746 std::ifstream file2(File2Loc.c_str(), std::ios::binary | std::ios::in);
749 <<
"\nFile2 " << fInputFile2 <<
" not found in FW_SEARCH_PATH or at " << fInputDir
752 int i1 = 0, i2 = 0, i3 = 0;
754 while (file2.good()) {
756 file2.read((
char*)(&readVal),
sizeof(
float));
757 spmu[i1][i2][i3] = readVal;
771 for (
int i = 0; i < 120; i++)
772 for (
int j = 0; j < 62; j++)
773 for (
int k = 0;
k < 51;
k++)
775 spmu[1][1][0] = 0.000853544;
778 std::ostringstream File3LocStream;
782 if (sp3.
find_file(fInputFile3, fROOTfile)) File3Loc = fROOTfile;
783 std::ifstream file3(File3Loc.c_str(), std::ios::in);
786 <<
"\nFile3 " << fInputFile3 <<
" not found in FW_SEARCH_PATH or at " << fInputDir
789 lineNumber =
index = 0;
790 while (file3.good()) {
792 file3.getline(inputLine, 9999);
794 token = strtok(inputLine,
" ");
795 while (token != NULL) {
798 token = strtok(NULL,
" ");
824 double theta = theta1;
828 while (theta < theta2 - dc / 2.) {
831 double cc = cos(theta0);
832 double ash = s_hor * cc;
833 double asv01 = s_ver1 * sqrt(1. - cc * cc);
834 double asv02 = s_ver2 * sqrt(1. - cc * cc);
835 int ic1 = (theta + 0.999);
837 if (ic2 > 91) ic2 = 91;
838 if (ic1 < 1) ic1 = 1;
842 while (phi < phi2 - dp / 2.) {
850 double asv1 = asv01 * fabs(cos(phi0));
851 double asv2 = asv02 * fabs(sin(phi0));
852 double asv0 = ash + asv1 + asv2;
854 if (figflag == 1) fl = asv0;
855 int ip1 = (phi + 0.999);
857 if (ip2 > 360) ip2 = 1;
858 if (ip1 < 1) ip1 = 360;
861 for (
int ii = 0; ii < 4; ii++) {
864 if (ip1 == 360 && (ii == 1 || ii == 3)) iip = -359;
865 if (
fmu[ip1 + iip - 1][ic1 + iic - 1] < 0) {
866 if (
pow(10.,
fmu[ip1 + iip - 1][ic1 + iic - 1]) / 4 > 1
e-6) {
867 std::cout <<
"Looking at fmu [ " << ip1 <<
" + " << iip <<
" - 1 (" << ip1 + iip - 1
868 <<
") ] [ " << ic1 <<
" + " << iic <<
" - 1 (" << ic1 + iic - 1 <<
") ] ." 869 <<
"\nChanging sp1 from " << sp1 <<
" to " 870 << sp1 +
pow(10.,
fmu[ip1 + iip - 1][ic1 + iic - 1]) / 4 <<
"..........." 871 << sp1 <<
" + 10 ^ (" <<
fmu[ip1 + iip - 1][ic1 + iic - 1] <<
") / 4 " 874 sp1 = sp1 +
pow(10.,
fmu[ip1 + iip - 1][ic1 + iic - 1]) / 4;
881 sc = sc + sp1 * fl * dp *
M_PI / 180. * sin(theta0) * dc *
M_PI / 180.;
888 theta = theta + dc / 2.;
892 for (
int ipc1 = 0; ipc1 < ipc; ipc1++)
904 CLHEP::HepRandomEngine& engine)
906 CLHEP::RandFlat
flat(engine);
907 CLHEP::RandGaussQ
gauss(engine);
909 #if 0 // this code is disabled for good 910 double xfl = flat.fire();
911 int loIndex = 0, hiIndex = 32400;
912 int i = (loIndex+hiIndex)/2;
913 bool foundIndex =
false;
914 if( xfl <
fnmu[loIndex] ) {
917 }
else if ( xfl >
fnmu[hiIndex] ) {
920 }
else if ( xfl >
fnmu[i-1] && xfl <=
fnmu[i] )
922 while( !foundIndex ) {
927 i = (loIndex + hiIndex)/2;
929 if( xfl >
fnmu[i-1] && xfl <=
fnmu[i] )
933 double xfl = flat.fire();
935 while (xfl >
fnmu[i])
938 int ic = (i - 2) / 360;
939 int ip = i - 2 - ic * 360;
942 theta =
the1 + ((double)ic + xfl);
944 phi =
ph1 + ((double)ip + xfl);
945 if (phi > 360) phi = phi - 360;
948 int ic1 = cos(
M_PI / 180. * theta) * 50.;
949 if (ic1 < 0) ic1 = 0;
950 if (ic1 > 50) ic1 = 50;
951 int ip1 = dep / 200. - 16;
952 if (ip1 < 0) ip1 = 0;
953 if (ip1 > 61) ip1 = 61;
957 loIndex = 0, hiIndex = 120;
958 int j = (loIndex+hiIndex)/2;
960 if( xfl <
spmu[loIndex][ip1][ic1] ) {
963 }
else if ( xfl >
spmu[hiIndex][ip1][ic1] ) {
966 }
else if ( xfl >
spmu[j-1][ip1][ic1] && xfl <=
spmu[j][ip1][ic1] )
968 while( !foundIndex ) {
969 if( xfl <
spmu[j][ip1][ic1] )
973 j = (loIndex + hiIndex)/2;
975 if( xfl >
spmu[j-1][ip1][ic1] && xfl <=
spmu[j][ip1][ic1] )
980 while (xfl >
spmu[j][ip1][ic1])
984 double En1 = 0.05 * (j - 1);
985 double En2 = 0.05 * (j);
986 E =
pow(10., En1 + (En2 - En1) * flat.fire());
double fEmax
Maximum Kinetic Energy (GeV)
void beginRun(art::Run &run)
double fZmax
Maximum Z position.
double fYmax
Maximum Y position.
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.
double fT0
Central t position (ns) in world coordinates.
art framework interface to geometry description
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)
std::string DetectorName() const
Returns a string with the name of the detector, as configured.
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.
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Base utilities and modules for event generation and detector simulation.
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)
std::string find_file(std::string const &filename) const
CLHEP::HepRandomEngine & fEngine
art-managed random-number engine
double fThetamax
Maximum theta.
double fXmin
Minimum X position.
void produce(art::Event &evt)
Event generator information.
LArSoft geometry interface.
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.
cet::coded_exception< error, detail::translate > exception
double fXmax
Maximum X position.
QTextStream & endl(QTextStream &s)