27 string database = gemcOpt.
args[
"DATABASE"].args;
28 string dbtable = gemcOpt.
args[
"GT"].args;
29 string dbhost = gemcOpt.
args[
"DBHOST"].args;
31 string dbUser = gemcOpt.
args[
"DBUSER"].args;
32 string dbPswd = gemcOpt.
args[
"DBPSWD"].args;
34 string hd_msg = gemcOpt.
args[
"LOG_MSG"].args +
" MySQL: >> ";
35 double GEO_VERBOSITY = gemcOpt.
args[
"GEO_VERBOSITY"].arg;
36 string catch_v = gemcOpt.
args[
"CATCH"].args;
37 string hall_field = gemcOpt.
args[
"HALL_FIELD"].args;
40 map<string, detector> CLAS;
46 vector<identifier> identity;
50 cout << endl << hd_msg <<
" Connecting to database \"" << database <<
"\" as \"" 51 << dbUser <<
"\". " << endl;
54 QSqlDatabase db = QSqlDatabase::addDatabase(
"QMYSQL");
55 db.setHostName(dbhost.c_str());
56 db.setDatabaseName(database.c_str());
57 db.setUserName( dbUser.c_str() );
58 db.setPassword( dbPswd.c_str() );
63 cout << hd_msg <<
" Cannot connect to database " << database <<
". Exiting." << endl;
70 if(RunConditions.
gTab_Vec.size() == 0 && dbtable ==
"no")
72 RunConditions.
gTab_Vec.push_back(
"BST");
73 RunConditions.
gTab_Vec.push_back(
"CTOF");
74 RunConditions.
gTab_Vec.push_back(
"HTCC");
75 RunConditions.
gTab_Vec.push_back(
"SECTOR");
76 RunConditions.
gTab_Vec.push_back(
"FTOF");
77 RunConditions.
gTab_Vec.push_back(
"EC");
78 RunConditions.
gTab_Vec.push_back(
"DC12");
79 RunConditions.
gTab_Vec.push_back(
"solenoid");
80 RunConditions.
gTab_Vec.push_back(
"torus");
82 if(RunConditions.
gTab_Vec.size() == 0 && dbtable !=
"no")
83 RunConditions.
gTab_Vec.push_back(dbtable);
85 for(
unsigned int sql_t=0; sql_t< RunConditions.
gTab_Vec.size(); sql_t++)
87 if(GEO_VERBOSITY > 3) cout << hd_msg <<
" Importing table: " << RunConditions.
gTab_Vec[sql_t] << endl;;
89 string dbexecute =
"select name, mother, description, pos, rot, col, type,";
90 dbexecute +=
"dimensions, material, magfield, ncopy, pmany, exist, ";
91 dbexecute +=
"visible, style, sensitivity, hitType, identity from " + RunConditions.
gTab_Vec[sql_t];
94 bool SUCCESS = q.exec(dbexecute.c_str());
97 cout << hd_msg <<
" Failed to access DB for table: " << RunConditions.
gTab_Vec[sql_t] <<
". Maybe the table doesn't exist? Exiting." << endl;
113 Detector.
pos = G4ThreeVector(0, 0, 0);
115 G4ThreeVector nompos(0, 0, 0);
116 G4ThreeVector shiftp(0, 0, 0);
117 G4ThreeVector more_rot(0, 0, 0);
127 shiftp = RunConditions.
gDet_Map[Detector.
name].get_position();
128 if(GEO_VERBOSITY > 3 || Detector.
name.find(catch_v))
129 cout << hd_msg <<
" Detector " << Detector.
name <<
" is displaced by: " << shiftp/cm <<
" cm" << endl;
132 Detector.
pos = nompos + shiftp;
136 Detector.
rot = G4RotationMatrix(G4ThreeVector(1, 0, 0),
137 G4ThreeVector(0, 1, 0),
138 G4ThreeVector(0, 0, 1));
142 if(var !=
"ordered:")
158 else if(order ==
"yxz")
164 else if(order ==
"yzx")
170 else if(order ==
"zxy")
176 else if(order ==
"zyx")
184 cout << hd_msg <<
" Ordered rotation <" << order <<
"> for " << Detector.
name <<
" is wrong, it's none of the following:" 185 <<
" xzy, yxz, yzx, zxy or zyx. Exiting." << endl;
192 more_rot = RunConditions.
gDet_Map[Detector.
name].get_vrotation();
193 if(GEO_VERBOSITY > 3 || Detector.
name.find(catch_v))
194 cout << hd_msg <<
" Detector " << Detector.
name <<
" is rotated by: " << more_rot/deg <<
" deg" << endl;
196 Detector.
rot.rotateX(more_rot.x());
197 Detector.
rot.rotateY(more_rot.y());
198 Detector.
rot.rotateZ(more_rot.z());
206 if(var.size() != 6 && var.size() != 7)
208 cout << hd_msg <<
" Color for " << Detector.
name <<
"<" << var <<
"> has wrong size: " << var.size()
209 <<
". It should be 6 or 7 hexadecimal numbers." << endl;
212 thisCol = G4Colour(strtol(var.substr(0, 2).c_str(), NULL, 16)/255.0,
213 strtol(var.substr(2, 2).c_str(), NULL, 16)/255.0,
214 strtol(var.substr(4, 2).c_str(), NULL, 16)/255.0,
215 1.0 - atof(var.substr(6, 1).c_str())/5.0);
237 Detector.
ncopy = q.value(10).toInt();
240 Detector.
pMany = q.value(11).toInt();
243 Detector.
exist = q.value(12).toInt();
248 if(GEO_VERBOSITY > 3 || Detector.
name.find(catch_v))
249 cout << hd_msg <<
" Detector " << Detector.
name <<
" has existance set to: " << Detector.
exist << endl;
255 Detector.
visible = q.value(13).toInt();
258 Detector.
style = q.value(14).toInt();
274 if(iden.
rule.find(
"ncopy") != string::npos) iden.
id = Detector.
ncopy;
275 identity.push_back(iden);
289 Detector.
VAtts = G4VisAttributes(thisCol);
290 if(Detector.
visible) Detector.
style ? Detector.
VAtts.SetForceSolid(
true) : Detector.
VAtts.SetForceWireframe(
true);
291 Detector.
visible ? Detector.
VAtts.SetVisibility(
true) : Detector.
VAtts.SetVisibility(
false);
295 CLAS[Detector.
name] = Detector;
304 db.removeDatabase(
"qt_sql_default_connection");
307 string hall_mat = gemcOpt.
args[
"HALL_MATERIAL"].args;
312 queen.
pos = G4ThreeVector(0, 0, 0);
313 queen.
rot = G4RotationMatrix(G4ThreeVector(1, 0, 0),
314 G4ThreeVector(0, 1, 0),
315 G4ThreeVector(0, 0, 1));
326 CLAS[
"root"] = queen;
334 string field = gemcOpt.
args[
"NO_FIELD"].args;
336 for( map<string, detector>::iterator it = CLAS.begin() ; it!=CLAS.end() && field !=
"all" ; it++)
339 if(it->first == field)
342 if(it->second.magfield ==
"no")
345 string mother = it->second.mother;
346 string firstAncestorFieldFound =
"no";
347 while(mother !=
"akasha" && firstAncestorFieldFound ==
"no")
349 if(CLAS[mother].magfield !=
"no")
351 firstAncestorFieldFound = CLAS[mother].magfield;
352 it->second.magfield = CLAS[mother].magfield;
355 mother = CLAS[mother].mother;
359 if(GEO_VERBOSITY > 3 || it->first.find(catch_v) != string::npos) cout << hd_msg <<
" " << it->second ;
370 string hd_msg = gemcOpt.
args[
"LOG_MSG"].args +
" MySQL: >> ";
371 string database = gemcOpt.
args[
"BANK_DATABASE"].args;
372 string dbhost = gemcOpt.
args[
"DBHOST"].args;
374 string dbUser = gemcOpt.
args[
"DBUSER"].args;
375 string dbPswd = gemcOpt.
args[
"DBPSWD"].args;
377 double HIT_VERBOSITY = gemcOpt.
args[
"HIT_VERBOSITY"].arg;
383 QSqlDatabase db = QSqlDatabase::addDatabase(
"QMYSQL");
384 db.setHostName(dbhost.c_str());
385 db.setDatabaseName(database.c_str());
386 db.setUserName( dbUser.c_str() );
387 db.setPassword( dbPswd.c_str() );
392 cout << hd_msg <<
" Database not connected. Exiting." << endl;
398 if(HIT_VERBOSITY>1) cout << hd_msg <<
" Loading definitions table for <" << SD <<
">..." ;
400 string command =
"select id, identifiers, minEnergy, TimeWindow, ProdThreshold, MaxStep from SDId where name = \"" + SD +
"\"" ;
401 q.exec(command.c_str());
409 SDID.
id = q.value(0).toInt();
435 cout <<
"found: bank " << SD <<
", id=" << SDID.
id <<
"." << endl << endl ;
436 for(
unsigned int i=0; i<SDID.
IDnames.size(); i++)
438 cout <<
" element name: " << SDID.
IDnames[i] << endl;
440 cout << endl << hd_msg <<
" Minimum Energy Cut for processing the <" << SD <<
"> hit: " << SDID.
minEnergy/MeV <<
" MeV." << endl ;
441 cout << hd_msg <<
" Time Window for <" << SD <<
">: " << SDID.
TimeWindow/ns <<
" ns." << endl ;
442 cout << hd_msg <<
" Production Threshold for <" << SD <<
">: " << SDID.
ProdThreshold/mm <<
" mm." << endl ;
443 cout << hd_msg <<
" Maximum Acceptable Step for <" << SD <<
">: " << SDID.
MaxStep/mm <<
" mm." << endl ;
453 db.removeDatabase(
"qt_sql_default_connection");
SDId get_SDId(string SD, gemc_opts gemcOpt)
Connects to DB and retrieve SDId.
map< string, detector > read_detector(gemc_opts gemcOpt, run_conditions RunConditions)
Reads detector map from database.
vector< string > gTab_Vec
Vector of SQL tables names.
int id
Sensitive Detector identifier. This is also the bank ID.
string sensitivity
Defines the Sensitive Detector. possible choices: "no" "hits collection name".
string mother
Mother Volume name.
double ProdThreshold
Production Threshold in the detector.
G4ThreeVector pos
Position relative to the mother volume, as G4ThreeVector.
double TimeWindow
If two steps happens withing the same TimeWindow, they belong to the same Hit.
string gemc_tostring(QString input)
int id
manually assing ID. 0 if "ncopy" (will be set at hit processing time)
string name
Name of the detector.
G4VisAttributes VAtts
Visual Attributes: color, transparency, style (wireframe, solid), visibility.
vector< string > IDnames
Identifier names as they should be in identifier.
bool pMany
Needed by geant4 at G4PVPlacement time.
map< string, gcard_detector > gDet_Map
Map of gcard_detector. Map Key = detector name.
string name
Name of the volume. Since this is the key of the STL map, it has to be unique.
string material
Volume Material name.
double minEnergy
Minimum energy of the hit to be recorded in the output stream.
int visible
visibility of the detector: 0=invisible 1=visible
int style
Visual style: 0=wireframe 1=solid.
double MaxStep
Maximum Acceptable Step in the detector.
string hitType
Hit Process routine name. A Hit Process MPHBaseClass derived class must exists with this name...
vector< identifier > identity
Vector of identifiers. Example: superlayer manual 1 type manual 2 segment manual 3 strip manual 4...
string magfield
Magnetic Field. The string "no" means that the field is inherited from the mother volume...
map< string, opts > args
Options map.
G4RotationMatrix rot
Rotation Matrix, defined by rotations along x,y,z axis relative to the mother volume.
int exist
detector ON/OFF switch
string type
solid type. This follows the GEANT4 definitions
vector< double > dimensions
vector of dimensions. Size, units depends on solid type
string TrimSpaces(string in)
Removes leading and trailing spaces.
double get_number(string)
Returns dimension from string, i.e. 100*cm.
int scanned
for use during construction
string rule
"manual" or "ncopy"
string description
Volume Description for documentation.