StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFgtDb.cxx
1 #include "StMessMgr.h"
2 #include "StFgtDb.h"
3 #include <TVector3.h>
4 #include <TRotation.h>
5 #include <fstream>
6 using namespace std;
7 
8 void
9 StFgtDb::printFgtDumpCSV1(TString fname, int myDate, int myTime) {
10 
11  ofstream fd;
12  fd.open(fname.Data());
13 
14  if (fd.is_open())
15  {
16 
17  cout<<"Saving FGT output in "<<fname.Data()<<endl;
18 
19  fd<<"# FGT mapping, timeStamp "<< myDate<<" "<<myTime<<"\n";
20  fd<<"# electId,geoID, RDO(1;2),ARM(0-4),APV(0-9;12-21),chan(0-127), disk(1-6),quad(A-D),layer(P;R),strip(P:0-719;R0-279+400-679), ordinate(rad;cm),lowSpan(cm;rad),upSpan(cm;rad), geoName, stat,ped(ADC),sigPed(ADC)\n";
21 
22 
23  StFgtDb *fgtDb=this;
24 
25  int nTry=0, nMap=0;
26  for (int rdo=1;rdo<=2;rdo++){// 2 RDOs numbered 1,2
27  for (int arm=0;arm<6;arm++){//6 arms numbered from 0
28  for (int apv=0;apv<=21;apv++){//24 APVs numbered 0-23 but in real life APV# 10,11,22,23 are unused so 0-19 in determining electronic Id
29  if ((apv==10)||(apv==11)) continue;
30 
31  for (int channel=0;channel<128;channel++){//128 channels numbered from 0
32 
33  nTry++;
34  int geoId=fgtDb->getGeoIdFromElecCoord(rdo, arm, apv, channel);
35  if (geoId<0) continue;
36  nMap++;
37  Short_t disk,quad,quad2,strip; Char_t layer;
38  Double_t ordinate, lowerSpan, upperSpan;
39  StFgtGeom::decodeGeoId(geoId,disk,quad,layer,strip);
40  quad2= quad;
41  StFgtGeom::getPhysicalCoordinate(geoId,disk,quad2,layer,ordinate,lowerSpan,upperSpan);
42 
43  double ped=fgtDb->getPedestalFromElecCoord(rdo,arm,apv,channel);
44  double pedSig=fgtDb->getPedestalSigmaFromElecCoord(rdo,arm,apv,channel);
45  Short_t stat=fgtDb->getStatusFromElecCoord(rdo,arm,apv,channel);
46  int electId = StFgtGeom::getElectIdFromElecCoord(rdo,arm,apv,channel);
47  std::string geoName=fgtDb->getGeoNameFromElecCoord(rdo,arm,apv,channel);
48 
49 
50  fd<<electId<<", "<<geoId<<", "<<rdo<<", "<<arm<<", "<<apv<<", "<<channel<<", "<<disk+1<<", "<<quad<<", "<<layer<<", "<<strip<<", "<<ordinate<<", "<<lowerSpan<<", "<<upperSpan<<", "<<geoName.data()<<", "<<stat<<", "<<ped<<", "<<pedSig<<"\n";
51 
52  }
53  }
54  }
55  }
56 
57 
58  fd<<"# FGT mapping end, nTry= "<<nTry<<" nMap="<< nMap<<" from StFgtDb\n";
59  fd.close();
60 
61  }
62  else
63  {
64  cout << "Error opening file";
65  }
66 
67 }
68 
69 
70 
71 
72 Int_t StFgtDb::getElecCoordFromGeoId(
73  Int_t geoId, Int_t& rdo, Int_t& arm, Int_t& apv, Int_t& channel
74 )
75 {
76  if ( geoId < 0 || geoId >= kFgtNumGeoIds )
77  {
78  LOG_DEBUG << "GeoId " << geoId << " out of range in StFgtDb::getElecCoordFromGeoId." << endm;
79  rdo = kFgtError;
80  arm = kFgtError;
81  apv = kFgtError;
82  channel = kFgtError;
83 
84  return kFgtError;
85  }
86 
87  Int_t elecId = m_rmap->Mapping[ geoId ];
88 
89  StFgtGeom::decodeElectronicId( elecId, rdo, arm, apv, channel );
90 
91  return 0;
92 }
93 
94 Int_t StFgtDb::getElecCoordFromGeoName(
95  const std::string & geoName,
96  Int_t& rdo, Int_t& arm, Int_t& apv, Int_t& channel
97 )
98 {
99  Int_t geoId =
100  StFgtGeom::translateGeoNameToGeoId( geoName );
101 
102  if ( geoId < 0 )
103  {
104  rdo = kFgtError;
105  arm = kFgtError;
106  apv = kFgtError;
107  channel = kFgtError;
108 
109  return kFgtError;
110  }
111 
112  getElecCoordFromGeoId( geoId, rdo, arm, apv, channel );
113 
114  return 0;
115 }
116 
117 Double_t StFgtDb::getPedestalFromGeoId( Int_t geoId )
118 {
119  if ( geoId < 0 || geoId >= kFgtNumGeoIds )
120  {
121  LOG_DEBUG << "GeoId " << geoId << " out of range in StFgtDb::getPedestalFromGeoId." << endm;
122  return kFgtError;
123  }
124 
125  Int_t elecId = m_rmap->Mapping[ geoId ];
126  return m_pedestal->AdcPedestal[ elecId ];
127 }
128 
129 Double_t StFgtDb::getPedestalFromElecId( Int_t elecId)
130 {
131  if ( elecId < 0 || elecId >= kFgtNumElecIds )
132  {
133  LOG_DEBUG << "Electronic ID " << elecId << " out of range in StFgtDb::getPedestalFromElecId." << endm;
134  return kFgtError;
135  }
136 
137  return m_pedestal->AdcPedestal[ elecId ];
138 }
139 
140 Double_t StFgtDb::getPedestalSigmaFromGeoId( Int_t geoId )
141 {
142  if ( geoId < 0 || geoId >= kFgtNumGeoIds )
143  {
144  LOG_DEBUG << "GeoId " << geoId << " out of range in StFgtDb::getPedestalSigmaFromGeoId." << endm;
145  return kFgtError;
146  }
147 
148  Int_t elecId = m_rmap->Mapping[ geoId ];
149  return m_pedestal->AdcPedestalRMS[ elecId ];
150 }
151 
152 Double_t StFgtDb::getPedestalSigmaFromElecId( Int_t elecId )
153 {
154  if ( elecId < 0 || elecId >= kFgtNumElecIds )
155  {
156  LOG_DEBUG << "Electronic ID " << elecId << " out of range in StFgtDb::getPedestalSigmaFromElecId." << endm;
157  return kFgtError;
158  }
159 
160  return m_pedestal->AdcPedestalRMS[ elecId ];
161 }
162 
163 Char_t StFgtDb::getPedestalStatusFromGeoId( Int_t geoId )
164 {
165  if ( geoId < 0 || geoId >= kFgtNumGeoIds )
166  {
167  LOG_DEBUG << "GeoId " << geoId << " out of range in StFgtDb::getPedestalStatusFromGeoId." << endm;
168  return kFgtErrorChar;
169  }
170 
171  Int_t elecId = m_rmap->Mapping[ geoId ];
172  return m_pedestal->Status[ elecId ];
173 }
174 
175 Char_t StFgtDb::getPedestalStatusFromElecId( Int_t elecId )
176 {
177  if ( elecId < 0 || elecId >= kFgtNumElecIds )
178  {
179  LOG_DEBUG << "Electronic ID " << elecId << " out of range in StFgtDb::getPedestalStatusFromElecId." << endm;
180  return kFgtErrorChar;
181  }
182 
183  return m_pedestal->Status[ elecId ];
184 }
185 
186 Char_t StFgtDb::getStatusFromGeoId( Int_t geoId )
187 {
188  if ( geoId < 0 || geoId >= kFgtNumGeoIds )
189  {
190  LOG_DEBUG << "GeoId " << geoId << " out of range in StFgtDb::getStatusFromGeoId." << endm;
191  return kFgtErrorChar;
192  }
193 
194  Int_t elecId = m_rmap->Mapping[ geoId ];
195  return m_status->Status[ elecId ];
196 }
197 
198 Char_t StFgtDb::getStatusFromElecId( Int_t elecId )
199 {
200  if ( elecId < 0 || elecId >= kFgtNumElecIds )
201  {
202  LOG_DEBUG << "Electronic ID " << elecId << " out of range in StFgtDb::getStatusFromElecId." << endm;
203  return kFgtErrorChar;
204  }
205 
206  return m_status->Status[ elecId ];
207 }
208 
209 Double_t StFgtDb::getGainFromGeoId( Int_t geoId )
210 {
211  if ( geoId < 0 || geoId >= kFgtNumGeoIds )
212  {
213  LOG_DEBUG << "GeoId " << geoId << " out of range in StFgtDb::getGainFromGeoId." << endm;
214  return kFgtError;
215  }
216 
217  Int_t elecId = m_rmap->Mapping[ geoId ];
218  return m_gain->Gain[ elecId ];
219 }
220 
221 Double_t StFgtDb::getGainFromElecId( Int_t elecId )
222 {
223  if ( elecId < 0 || elecId >= kFgtNumElecIds )
224  {
225  LOG_DEBUG << "Electronic ID " << elecId << " out of range in StFgtDb::getGainFromElecId." << endm;
226  return kFgtError;
227  }
228 
229  return m_gain->Gain[ elecId ];
230 }
231 
232 Char_t StFgtDb::getGainStatusFromGeoId( Int_t geoId )
233 {
234  if ( geoId < 0 || geoId >= kFgtNumGeoIds )
235  {
236  LOG_DEBUG << "GeoId " << geoId << " out of range in StFgtDb::getGainStatusFromGeoId." << endm;
237  return kFgtErrorChar;
238  }
239 
240  Int_t elecId = m_rmap->Mapping[ geoId ];
241  return m_gain->Status[ elecId ];
242 }
243 
244 Char_t StFgtDb::getGainStatusFromElecId( Int_t elecId )
245 {
246  if ( elecId < 0 || elecId >= kFgtNumElecIds )
247  {
248  LOG_DEBUG << "Electronic ID " << elecId << " out of range in StFgtDb::getGainStatusFromElecId." << endm;
249  return kFgtErrorChar;
250  }
251 
252  return m_gain->Status[ elecId ];
253 }
254 
255 Double_t StFgtDb::getMapping(
256  Int_t rdo, Int_t arm, Int_t apv, Int_t channel
257 )
258 {
259  Short_t disc, quadrant;
260  Char_t layer;
261  Double_t ordinate, lowerSpan, upperSpan;
262 
263  if ( getPhysCoordFromElecCoord(
264  rdo, arm, apv, channel,
265  disc, quadrant, layer,
266  ordinate, lowerSpan, upperSpan
267  ) < 0
268  )
269  return kFgtError;
270 
271  return ordinate;
272 }
273 
274 // This, similarly, seems needlessly complicated.
275 bool StFgtDb::isR(
276  Int_t rdo, Int_t arm, Int_t apv, Int_t channel
277 )
278 {
279  Short_t disc, quadrant;
280  Char_t layer;
281  Double_t ordinate, lowerSpan, upperSpan;
282 
283  // Can't do any boundry checking return value thing here. Going to
284  // have to let the call here handle the warning message.
285  getPhysCoordFromElecCoord(
286  rdo, arm, apv, channel,
287  disc, quadrant, layer,
288  ordinate, lowerSpan, upperSpan
289  );
290 
291  return (layer == 'R');
292 }
293 
294 // This gives XYZ from R and PHI obtained by StFgtGeom::getPhysicalCoordinate(STAR coordinate)
295 // If option=0, no alighment parameter is considered and gives ideal position
296 // If option=1 (default), then alignment parameter is taken from DB, and it will apply offsets and rotation around StFgtGeom::getQuadCenterXYZ()
297 // If option=2, then alignment parameter is taken from last argument, and it will apply offsets and rotation around StFgtGeom::getQuadCenterXYZ()
298 void StFgtDb::getStarXYZ(Short_t disc, Short_t quad, Double_t r, Double_t phi, TVector3 &xyz, Int_t opt, fgtAlignment_st* par){
299  xyz.SetXYZ(0,0,0); //initialize to zero
300  if(disc<0 || disc>=kFgtNumDiscs) return;
301  if(quad<0 || quad>=kFgtNumQuads) return;
302  TVector3 org(r*cos(phi),r*sin(phi),StFgtGeom::getDiscZ(disc)); //Get STAR xyz (ideal position w/o alignment)
303  if(opt==0) {xyz=org; return;} //opt=0 return ideal position
304  fgtAlignment_st* alg;
305  if(opt==1) { alg = m_alignment;} //use DB
306  else { alg = par; } //use user input instead of DB
307  int i=disc*4+quad;
308  //printf("i=%d\n",i);
309  TVector3 center; StFgtGeom::getQuadCenterXYZ(disc,quad,center); //get xyz of center of quadrant
310  TVector3 local=org-center; //move to center of quadrant
311  //printf("center x=%8.3f y=%8.3f z=%8.3f\n",center.X(),center.Y(),center.Z());
312  //printf("org x=%8.3f y=%8.3f z=%8.3f\n",org.X(),org.Y(),org.Z());
313  //printf("local x=%8.3f y=%8.3f z=%8.3f\n",local.X(),local.Y(),local.Z());
314  TRotation rot;
315  rot.SetXEulerAngles(alg->phi[i], alg->theta[i], alg->psi[i]); //set up Euler angles
316  TVector3 rotated = local.Transform(rot); //rotate
317  //printf("rot x=%8.3f y=%8.3f z=%8.3f\n",rotated.X(),rotated.Y(),rotated.Z());
318  TVector3 global=rotated+center; //move back to STAR coordinate
319  //printf("global x=%8.3f y=%8.3f z=%8.3f\n",global.X(),global.Y(),global.Z());
320  TVector3 offset(alg->xoff[i],alg->yoff[i],alg->zoff[i]); //offsets
321  //printf("offset x=%8.3f y=%8.3f z=%8.3f\n",offset.X(),offset.Y(),offset.Z());
322  xyz = global + offset; //add offsets
323  //printf("xyz x=%8.3f y=%8.3f z=%8.3f\n",xyz.X(),xyz.Y(),xyz.Z());
324 }