42 G4String pType=
"custom";
53 std::string::size_type beg_idx,end_idx;
57 beg_idx =
line.find_first_not_of(
"\t #");
58 if(beg_idx > 0 &&
line[beg_idx-1] ==
'#')
continue;
59 end_idx =
line.find_first_of(
"\t ", beg_idx);
60 if (end_idx == std::string::npos)
continue;
62 pdgCode = strtol(
line.substr( beg_idx, end_idx - beg_idx ).c_str(), &endptr, 0);
63 if (endptr[0] !=
'\0') {
64 throw std::invalid_argument(
"CustomMonopoleFactory::loadCustomMonopoles: Could not convert string to int: " +
line.substr( beg_idx, end_idx - beg_idx ));
67 G4cout <<
"CustomMonopoleFactory: pdgCode = " << pdgCode << G4endl;
69 beg_idx =
line.find_first_not_of(
"\t ",end_idx);
70 end_idx =
line.find_first_of(
"\t #", beg_idx);
71 if (end_idx == std::string::npos)
continue;
73 mass =
atof(
line.substr( beg_idx, end_idx - beg_idx ).c_str());
75 beg_idx =
line.find_first_not_of(
"\t ",end_idx);
76 end_idx =
line.find_first_of(
"\t #", beg_idx);
77 if (end_idx == std::string::npos)
continue;
79 elCharge =
atof(
line.substr( beg_idx, end_idx - beg_idx ).c_str());
81 beg_idx =
line.find_first_not_of(
"\t ",end_idx);
82 end_idx =
line.find_first_of(
"\t #", beg_idx);
84 if (end_idx == std::string::npos)
continue;
85 magCharge =
atof(
line.substr( beg_idx, end_idx - beg_idx ).c_str());
87 beg_idx =
line.find_first_not_of(
"\t# ",end_idx);
88 end_idx =
line.length();
89 name =
line.substr( beg_idx, end_idx - beg_idx );
90 while(
name.c_str()[0] ==
' ')
name.erase(0,1);
92 std::string lowerCaseName(
name);
93 for(
unsigned int il=0;
il < lowerCaseName.length(); ++
il) lowerCaseName[
il] =
std::tolower(lowerCaseName[
il]);
94 isQball = (lowerCaseName.find(
"qball") != std::string::npos) ?
true :
false;
96 isFCP = (lowerCaseName.find(
"fcp") != std::string::npos) ?
true :
false;
98 G4cout <<
"CustomMonopoleFactory: name = " <<
name << G4endl;
100 if(abs(pdgCode) / 1000000 == 0)
102 G4cout <<
"CustomMonopoleFactory: pdgCode too low: " << pdgCode <<
" " << abs(pdgCode) / 1000000 << G4endl;
108 double elChargeFromPDGcode = (isQball) ? (pdgCode/10)%10000/10. : (pdgCode/10)%1000/1. ;
114 XX = (abs(pdgCode)/1000)%100;
115 YY = (abs(pdgCode)/10)%100;
116 G4cout <<
"CustomMonopoleFactory: XX = " << XX <<
", YY = " << YY << G4endl;
118 elChargeFromPDGcode = (pdgCode>0) ?
round(100.*XX/YY)/100. : -
round(100.*XX/YY)/100.;
119 G4cout <<
"CustomMonopoleFactory: elChargeFromPDGcode = " << elChargeFromPDGcode << G4endl;
122 if (!isQball && !isFCP && abs((
int)(pdgCode/10000)) == 412) elChargeFromPDGcode = -elChargeFromPDGcode;
125 if (elChargeFromPDGcode != elCharge) {
126 G4cout <<
"CustomMonopoleFactory: El. charges for "<<
name <<
" from PDGcode and 3d col. of particles.txt file do not agree: " << elChargeFromPDGcode <<
" / " << elCharge << G4endl;
127 G4Exception(
"CustomMonopoleFactory::loadCustomMonopoles",
"WrongElCharges",FatalException,
"El charge from PDGcode and 3d col. of particles.txt file do not agree");
129 if (elCharge == 0.0 && magCharge == 0.0) {
130 G4cout <<
"CustomMonopoleFactory: Both electric and magnetic charges are ZEROs. Skip the particle. " << G4endl;
136 G4cout <<
"CustomMonopoleFactory: pType is " << pType << G4endl;
137 G4cout <<
"CustomMonopoleFactory: PDGcode of " <<
name <<
" is " << pdgCode << G4endl;
138 G4cout <<
"CustomMonopoleFactory: Mass of " <<
name <<
" is " <<
mass << G4endl;
139 G4cout <<
"CustomMonopoleFactory: Electrical Charge of " <<
name <<
" is "<< elCharge << G4endl;
140 G4cout <<
"CustomMonopoleFactory: Magnetic Charge of " <<
name <<
" is "<< magCharge << G4endl;
147 pType, 0, +1, pdgCode,
151 particle->SetMagneticCharge(magCharge);
159 G4cout <<
"CustomMonopoleFactory: No particles have been loaded." << G4endl;
160 G4Exception(
"CustomMonopoleFactory::loadCustomMonopoles",
"NoParticlesLoaded",FatalException,
"No particles have been loaded");