ATLAS Offline Software
Loading...
Searching...
No Matches
CustomMonopoleFactory.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5// class header
7// package headers
8#include "CustomMonopole.h"
9// CLHEP headers
10#include "CLHEP/Units/PhysicalConstants.h"
11#include "CLHEP/Units/SystemOfUnits.h"
12// STL headers
13#include <fstream>
14#include <iomanip>
15#include <iostream>
16#include <stdexcept>
17#include <sstream>
18#include <iterator>
19#include <set>
20
21
23{
24 static const CustomMonopoleFactory factory;
25 return factory;
26}
27
29{
30 return (particle && m_particles.find(particle)!=m_particles.end());
31}
32
37
39{
40 std::ifstream configFile("particles.txt");
41 // std::ifstream configFile("stophadrons.txt");
42 G4String pType="custom";
43 G4String pSubType="";
44 // bool first = true;
45 int pdgCode;
46 double mass;
47 double elCharge;
48 double magCharge;
49 std::string name,line;
50 // This should be compatible IMO to SLHA
51 while(getline(configFile,line))
52 {
53 std::string::size_type beg_idx,end_idx;
54 bool isQball = false;
55 bool isFCP = false; // Wendy Taylor: fractionally charged particle
56 bool isDyon = false; // Ethan Brooks Dyons
57
58 beg_idx = line.find_first_not_of("\t #");
59 if(beg_idx > 0 && line[beg_idx-1] == '#') continue;
60 end_idx = line.find_first_of( "\t ", beg_idx);
61 if (end_idx == std::string::npos) continue;
62 char *endptr;
63 const std::string numberTxt = line.substr( beg_idx, end_idx - beg_idx );
64 pdgCode = strtol(numberTxt.c_str(), &endptr, 0);
65 if (endptr[0] != '\0') {
66 throw std::invalid_argument("CustomMonopoleFactory::loadCustomMonopoles: Could not convert string to int: " + numberTxt);
67 }
68
69 G4cout << "CustomMonopoleFactory: pdgCode = " << pdgCode << G4endl;
70
71 beg_idx = line.find_first_not_of("\t ",end_idx);
72 end_idx = line.find_first_of( "\t #", beg_idx);
73 if (end_idx == std::string::npos) continue;
74
75 mass = atof(line.substr( beg_idx, end_idx - beg_idx ).c_str());
76
77 beg_idx = line.find_first_not_of("\t ",end_idx);
78 end_idx = line.find_first_of( "\t #", beg_idx);
79 if (end_idx == std::string::npos) continue;
80
81 elCharge = atof(line.substr( beg_idx, end_idx - beg_idx ).c_str());
82
83 beg_idx = line.find_first_not_of("\t ",end_idx);
84 end_idx = line.find_first_of( "\t #", beg_idx);
85
86 if (end_idx == std::string::npos) continue;
87 magCharge = atof(line.substr( beg_idx, end_idx - beg_idx ).c_str());
88
89 beg_idx = line.find_first_not_of("\t# ",end_idx);
90 end_idx = line.length();
91 name = line.substr( beg_idx, end_idx - beg_idx );
92 while(name.c_str()[0] == ' ') name.erase(0,1);
93 while(name[name.size()-1] == ' ') name.erase(name.size()-1,1);
94 std::string lowerCaseName(name);
95 for(unsigned int il=0; il < lowerCaseName.length(); ++il) lowerCaseName[il] = std::tolower(lowerCaseName[il]);
96 isQball = (lowerCaseName.find("qball") != std::string::npos) ? true : false;
97
98 isFCP = (lowerCaseName.find("fcp") != std::string::npos) ? true : false;
99
100 isDyon = (lowerCaseName.find("dyonss") != std::string::npos || lowerCaseName.find("dyonos") != std::string::npos) ? true : false; // Set Dyon boolean True if dyon same sign or opposite sign is present
101 G4cout << "CustomMonopoleFactory: name = " << name << G4endl;
102
103 if(abs(pdgCode) / 1000000 == 0)
104 {
105 G4cout << "CustomMonopoleFactory: pdgCode too low: " << pdgCode << " " << abs(pdgCode) / 1000000 << G4endl;
106 continue;
107 }
108 else
109 {
110
111 double elChargeFromPDGcode = (isQball) ? (pdgCode/10)%10000/10. : (pdgCode/10)%1000/1. ;
112
113 if (isFCP)
114 {
115 // pdgCode charge encoding scheme developed by quanyin.li@cern.ch
116 float XX, YY; // XX = numerator, YY = denominator
117 XX = (abs(pdgCode)/1000)%100;
118 YY = (abs(pdgCode)/10)%100;
119 G4cout << "CustomMonopoleFactory: XX = " << XX << ", YY = " << YY << G4endl;
120
121 elChargeFromPDGcode = (pdgCode>0) ? round(100.*XX/YY)/100. : -round(100.*XX/YY)/100.;
122 G4cout << "CustomMonopoleFactory: elChargeFromPDGcode = " << elChargeFromPDGcode << G4endl;
123 }
124
125 if(isDyon) // Ethan Brooks Dyons
126 {
127 elChargeFromPDGcode = (abs((int)(pdgCode/10000)) == 412) ? -pdgCode%4120000/10 : pdgCode%4110000/10; // encoding of electric charge in the dyon PDGID
128 magCharge = (pdgCode>0) ? 1 : -1; // sign matches PDG sign, only allow for plus or minus one magnetic charge
129 G4cout << "Loading Dyons: " << magCharge << G4endl;
130 }
131
132 if (!isQball && !isFCP && !isDyon && abs((int)(pdgCode/10000)) == 412) elChargeFromPDGcode = -elChargeFromPDGcode;
133
134 if (elChargeFromPDGcode != elCharge) {
135 G4cout << "CustomMonopoleFactory: El. charges for "<< name <<" from PDGcode and 3d col. of particles.txt file do not agree: " << elChargeFromPDGcode << " / " << elCharge << G4endl;
136 G4Exception("CustomMonopoleFactory::loadCustomMonopoles","WrongElCharges",FatalException,"El charge from PDGcode and 3d col. of particles.txt file do not agree");
137 }
138 if (elCharge == 0.0 && magCharge == 0.0) {
139 G4cout << "CustomMonopoleFactory: Both electric and magnetic charges are ZEROs. Skip the particle. " << G4endl;
140 continue;
141 }
142
143 }
144
145 G4cout << "CustomMonopoleFactory: pType is " << pType << G4endl;
146 G4cout << "CustomMonopoleFactory: PDGcode of " << name << " is " << pdgCode << G4endl;
147 G4cout << "CustomMonopoleFactory: Mass of " << name << " is " << mass << G4endl;
148 G4cout << "CustomMonopoleFactory: Electrical Charge of " << name << " is "<< elCharge << G4endl;
149 G4cout << "CustomMonopoleFactory: Magnetic Charge of " << name << " is "<< magCharge << G4endl;
150
151 // CustomMonopole *particle = CustomMonopole::MonopoleDefinition(
152 CustomMonopole *particle = new CustomMonopole(
153 name, mass * CLHEP::GeV , 0.0*CLHEP::MeV, CLHEP::eplus*elCharge,
154 0, +1, 0,
155 0, 0, 0,
156 pType, 0, +1, pdgCode,
157 true, -1.0, NULL);
158 // magCharge);
159
160 particle->SetMagneticCharge(magCharge);
161 particle->PrintMonopoleInfo();
162 m_particles.insert(particle);
163 }
164
165 configFile.close();
166
167 if (m_particles.empty()) {
168 G4cout << "CustomMonopoleFactory: No particles have been loaded." << G4endl;
169 G4Exception("CustomMonopoleFactory::loadCustomMonopoles","NoParticlesLoaded",FatalException,"No particles have been loaded");
170 }
171 return;
172}
bool isCustomMonopole(CustomMonopole *particle) const
static const CustomMonopoleFactory & instance()
std::set< CustomMonopole * > m_particles