GEMC  2.3
Geant4 Monte-Carlo Framework
sensitiveID.cc
Go to the documentation of this file.
1 // Qt headers
2 #include <QtSql>
3 
4 // gemc headers
5 #include "sensitiveID.h"
6 #include "utils.h"
7 
8 // CLHEP units
9 #include "CLHEP/Units/PhysicalConstants.h"
10 using namespace CLHEP;
11 
12 
13 sensitiveID::sensitiveID(string SD, goptions gemcOpt, string factory, string variation, string s)
14 {
15  double verbosity = gemcOpt.optMap["HIT_VERBOSITY"].arg;
16  name = SD;
17  thisFactory = factory + " " + variation;
18  system = s;
19 
20  // iF SD is FLUX, returns special sensitiveID
21  if(SD == "flux")
22  {
23  description = "generic flux detector";
24  identifiers.push_back("id");
25  signalThreshold = 0;
26  timeWindow = 0;
27  prodThreshold = 1*mm; // standard 1 mm production threshold
28  maxStep = 1*mm;
29  return;
30  }
31 
32 
33  // MYSQL sensitivity infos
34  if(factory == "TEXT")
35  {
36  string fname = system + "__hit_" + variation + ".txt";
37  if(verbosity > 1) cout << " > Loading TEXT definitions for <" << SD << ">..." << endl;
38 
39  ifstream IN(fname.c_str());
40  if(!IN)
41  {
42  // if file is not found, maybe it's in the GEMC_DATA_DIR directory
43  if(getenv("GEMC_DATA_DIR") != NULL)
44  {
45  string maybeHere = (string) getenv("GEMC_DATA_DIR") + "/" + fname;
46 
47  IN.open(maybeHere.c_str());
48  if(!IN && verbosity > 2)
49  {
50  cout << " !!! Error: Failed to open hit file " << fname << " for sensitive detector: >"
51  << SD << "<. Maybe the filename doesn't exist? Exiting." << endl;
52  }
53  }
54  if(!IN && verbosity > 2)
55  {
56  cout << " !!! Error: Failed to open hit file " << fname << " for sensitive detector: >"
57  << SD << "<. Maybe the filename doesn't exist? Exiting." << endl;
58  }
59  }
60 
61  while(!IN.eof())
62  {
63  string dbline;
64  getline(IN, dbline);
65 
66  if(!dbline.size())
67  continue;
68 
69  gtable gt(get_strings(dbline, "|"));
70 
71  if(gt.data.size())
72  if(gt.data[0] == SD)
73  {
74  // Reading variables
75  // 0 is system name, by construction is SD
76 
77  // 1: description
78  description = gt.data[1];
79 
80  // 2: Identifiers
81  vector<string> ids = get_strings(gt.data[2]);
82  for(unsigned i=0; i<ids.size(); i++)
83  identifiers.push_back(ids[i]);
84 
85  // 3: Minimum Energy Cut for processing the hit
86  signalThreshold = get_number(gt.data[3], 1);
87 
88  // 4: Time Window
89  timeWindow = get_number(gt.data[4], 1);
90 
91  // 5: Production Threshold in the detector
92  prodThreshold = get_number(gt.data[5], 1);
93 
94  // 6: Maximum Acceptable Step in the detector
95  maxStep = get_number(gt.data[6], 1);
96 
97  // 7: rise time of the PMT signal
98  riseTime = get_number(gt.data[7], 1);
99 
100  // 8: fall time of the PMT signal
101  fallTime = get_number(gt.data[8], 1);
102 
103  // 9: from MeV to mV constant
104  mvToMeV = get_number(gt.data[9]);
105 
106  // 10: pedestal
107  pedestal = get_number(gt.data[10]);
108 
109  // 11: time from PMT face to signal
110  delay = get_number(gt.data[11]);
111 
112  }
113  }
114  IN.close();
115  if(verbosity > 3)
116  cout << *this << endl;;
117 
118  return;
119  }
120 
121 
122 
123  // MYSQL sensitivity infos
124  if(factory == "MYSQL")
125  {
126  // connection to the DB
127  QSqlDatabase db = openGdb(gemcOpt);
128  string tname = system + "__hit";
129 
130  if(verbosity > 1) cout << " > Loading MYSQL definitions for <" << SD << ">..." ;
131 
132  string dbexecute = "select name, description, identifiers, signalThreshold, timeWindow, prodThreshold, maxStep, riseTime, fallTime, mvToMeV, pedestal, delay from " + tname ;
133  dbexecute += " where variation ='" + variation + "'";
134  dbexecute += " and name = '" + SD + "'";
135 
136  QSqlQuery q;
137  if(!q.exec(dbexecute.c_str()))
138  {
139  cout << " !!! Failed to execute MYSQL query " << dbexecute << ". This is a fatal error. Exiting." << endl;
140  qDebug() << q.lastError();
141  exit(0);
142  }
143  // Warning if nothing is found
144  if(q.size() == 0 && verbosity)
145  {
146  cout << " ** WARNING: sensitive detector \"" << SD << "\" not found in factory " << factory
147  << " for variation " << variation << endl << endl;
148  }
149 
150  // else loading parameters from DB
151  while (q.next())
152  {
153  // Reading variables
154  // 0 is system name, by construction is SD
155 
156  // 1: description
157  description = qv_tostring(q.value(1));
158 
159  // 2: Identifiers
160  vector<string> ids = get_strings(qv_tostring(q.value(2)));
161  for(unsigned i=0; i<ids.size(); i++)
162  identifiers.push_back(ids[i]);
163 
164  // 3: Minimum Energy Cut for processing the hit
165  signalThreshold = get_number(qv_tostring(q.value(3)));
166 
167  // 4: Time Window
168  timeWindow = get_number(qv_tostring(q.value(4)));
169 
170  // 5: Production Threshold in the detector
171  prodThreshold = get_number(qv_tostring(q.value(5)));
172 
173  // 6: Maximum Acceptable Step in the detector
174  maxStep = get_number(qv_tostring(q.value(6)));
175 
176  // 7: rise time of the PMT signal
177  riseTime = get_number(qv_tostring(q.value(7)));
178 
179  // 8: fall time of the PMT signal
180  fallTime = get_number(qv_tostring(q.value(8)));
181 
182  // 9: from MeV to mV constant
183  mvToMeV = get_number(qv_tostring(q.value(9)));
184 
185  // 10: pedestal
186  pedestal = get_number(qv_tostring(q.value(10)));
187 
188  // 11: time from PMT face to signal
189  delay = get_number(qv_tostring(q.value(11)));
190 
191  }
192 
193  // closing DB connection
194  closeGdb(db);
195  if(verbosity > 3)
196  cout << *this << endl;
197 
198  return;
199  }
200 
201 }
202 
203 
204 ostream &operator<<(ostream &stream, sensitiveID SD)
205 {
206  cout << " > Sensitive detector " << SD.name << ": " << endl << endl ;
207  for(unsigned int i=0; i<SD.identifiers.size(); i++)
208  {
209  cout << " identifier element name: " << SD.identifiers[i] << endl;
210  }
211  cout << endl << " > Signal Threshold: " << SD.signalThreshold/MeV << " MeV." << endl ;
212  cout << " > Production Threshold: " << SD.prodThreshold/mm << " mm." << endl ;
213  cout << " > Time Window for: " << SD.timeWindow/ns << " ns." << endl ;
214  cout << " > Maximum Acceptable Step: " << SD.maxStep/mm << " mm." << endl ;
215  cout << " > Signal Rise Time: " << SD.riseTime/ns << " ns." << endl ;
216  cout << " > Signal Fall Time: " << SD.fallTime/ns << " ns." << endl ;
217  cout << " > Signal MeV to mV: " << SD.mvToMeV << " mV/MeV" << endl ;
218  cout << " > Signal Pedestal: " << SD.pedestal << " mV" << endl ;
219  cout << " > Signal Delay " << SD.delay/ns << " ns." << endl ;
220  cout << endl;
221 
222  return stream;
223 }
224 
225 
226 
227 
228 
229 
230 
231 
232 
233 
234 
235 
vector< string > get_strings(string input)
returns a vector of strings from a stringstream, space is delimiter
double delay
time from PMT face to signal
Definition: sensitiveID.h:38
void closeGdb(QSqlDatabase db)
Definition: utils.cc:252
QSqlDatabase openGdb(goptions gemcOpt)
Definition: utils.cc:218
vector< string > data
Definition: utils.h:76
Definition: utils.h:65
double verbosity
string qv_tostring(QVariant input)
double get_number(string v, int warn_no_unit)
Returns number with dimension from string, i.e. 100*cm.
ostream & operator<<(ostream &stream, sensitiveID SD)
Definition: sensitiveID.cc:204
string name
Sensitive Detector name. This has to match the bank name.
Definition: sensitiveID.h:27
double prodThreshold
Geant4 Production Threshold in the detector.
Definition: sensitiveID.h:32
map< string, aopt > optMap
Options map.
Definition: options.h:75
double mvToMeV
from MeV to mV constant
Definition: sensitiveID.h:36
double pedestal
pedestal
Definition: sensitiveID.h:37
double maxStep
Geant4 Maximum Acceptable Step in the detector.
Definition: sensitiveID.h:33
double timeWindow
If two steps happens within the same TimeWindow, they belong to the same Hit.
Definition: sensitiveID.h:31
double signalThreshold
Minimum energy of the hit to be recorded in the output stream.
Definition: sensitiveID.h:30
vector< string > identifiers
vector of strings that uniquely identify the detector element
Definition: sensitiveID.h:29
double fallTime
fall time of the PMT signal
Definition: sensitiveID.h:35
double riseTime
rise time of the PMT signal
Definition: sensitiveID.h:34