101 #ifndef STAR_StEmcGeom
102 #define STAR_StEmcGeom
110 #include "math_constants.h"
114 #include "tables/St_calb_calg_Table.h"
115 #include "tables/St_calb_calr_Table.h"
116 #include "StMessMgr.h"
128 calb_calg_st* mCalg_st;
130 calb_calr_st* mCalr_st;
132 void defineDefaultCommonConstants();
133 void defineCommonConstants();
134 void defineModuleGridOnPhi();
135 Float_t relativeError(Float_t, Float_t)
const;
137 Int_t getIndex(
const Float_t &x,
const TArrayF &arr)
const;
155 Float_t mPhiStepHalf;
173 static StEmcGeom *instance(
const Int_t det);
174 static StEmcGeom *getEmcGeom(
const Int_t det);
175 static StEmcGeom *instance(
const Char_t* cdet);
176 static StEmcGeom *getEmcGeom(
const Char_t* cdet);
177 static StEmcGeom *instance(
const Int_t det,
const Char_t* mode);
178 static StEmcGeom *getEmcGeom(
const Int_t det,
const Char_t* mode);
180 static Int_t getDetNumFromName(
const Char_t *cdet);
184 const TString* Mode()
const;
185 Int_t Detector()
const;
186 Int_t NModule()
const;
191 Float_t Radius()
const;
192 Float_t YWidth()
const;
193 Float_t EtaMax()
const;
194 Float_t EtaMin()
const;
195 const Float_t* PhiModule()
const;
196 const Float_t* PhiOffset()
const;
197 const Float_t* PhiStep()
const;
198 const Float_t* PhiBound()
const;
199 const Float_t* Zlocal()
const;
200 const Float_t* Eta()
const;
201 const Float_t* Ylocal()
const;
202 const Float_t* Phi()
const;
204 const Float_t* EtaB()
const;
205 const Float_t* PhiB()
const;
207 void setDetector(
const Int_t val);
208 void setRadius(
const Float_t val);
209 void setYWidth(
const Float_t val);
212 Int_t checkModule(
const Int_t m)
const;
213 Int_t checkEta(
const Int_t e)
const;
214 Int_t checkSub(
const Int_t s)
const;
215 Int_t checkId(
const Int_t softId)
const;
218 Int_t
getBin(
const Float_t phi,
const Float_t eta, Int_t &m, Int_t &e, Int_t &s)
const;
219 Int_t getId(
const Float_t phi,
const Float_t eta, Int_t &softId)
const;
222 Int_t
getBin(
const Int_t softId, Int_t &m, Int_t &e, Int_t &s)
const;
223 Int_t getId(
const Int_t m,
const Int_t e,
const Int_t s, Int_t &softId)
const;
225 Int_t getVolIdBemc(
const Int_t ivid, Int_t &module, Int_t &eta, Int_t &sub, Int_t &detector);
226 Int_t getVolIdBsmd(
const Int_t ivid, Int_t &module, Int_t &eta, Int_t &sub, Int_t &detector);
227 Int_t getVolId(
const Int_t ivid, Int_t &module, Int_t &eta, Int_t &sub, Int_t &det);
229 Int_t getZlYl(
const Int_t softId, Float_t &zl, Float_t &yl)
const;
230 void getXYZ(
const Int_t m,
const Int_t e,
const Int_t s, Float_t &x, Float_t &y, Float_t &z)
const;
231 Int_t getXYZ(
const Int_t softId, Float_t &x, Float_t &y, Float_t &z)
const;
232 Int_t getXYZfromGeant(
const Int_t ivid, Float_t &x, Float_t &y, Float_t &z);
234 Int_t getEta(
const Int_t m,
const Int_t e, Float_t &eta)
const;
235 Int_t getEta(
const Int_t softId, Float_t &eta)
const;
237 Int_t getTheta(
const Int_t m,
const Int_t e, Float_t &theta)
const;
238 Int_t getTheta(
const Int_t softId, Float_t &theta)
const;
240 Int_t getPhi(
const Int_t m,
const Int_t s, Float_t &phi)
const;
241 Int_t getPhi(
const Int_t softId, Float_t &phi)
const;
243 Int_t getEtaPhi(
const Int_t softId, Float_t &eta, Float_t &phi)
const;
245 Int_t getPhiModule(
const Int_t m, Float_t &phi)
const;
247 Int_t getMaxAdc()
const {
return mMaxAdc;}
249 void initGeom(
const Int_t);
250 void initBEMCorBPRS();
253 void initEEMCorEPRS();
256 void printGeom()
const;
257 void print()
const {printGeom();}
258 void compare(
const StEmcGeom &, Bool_t)
const;
259 void compare(
const StEmcGeom *
const g, Bool_t key)
const {compare(*g,key);};
260 void printError(Float_t)
const;
262 Float_t toDeg(
const Float_t angR)
const {
return C_DEG_PER_RAD*angR;}
263 Float_t toRad(
const Float_t angD)
const {
return angD/C_DEG_PER_RAD;}
264 void getGeantGeometryTable();
269 inline const TString* StEmcGeom::Mode()
const {
return &mMode;}
270 inline Int_t StEmcGeom::Detector()
const {
return mDetector;}
271 inline Int_t StEmcGeom::NModule()
const {
return mNModule;}
272 inline Int_t StEmcGeom::NEta()
const {
return mNEta;}
273 inline Int_t StEmcGeom::NSub()
const {
return mNSub;}
274 inline Int_t StEmcGeom::Nes()
const {
return mNes;}
275 inline Int_t StEmcGeom::NRaw()
const {
return mNRaw;}
276 inline Float_t StEmcGeom::Radius()
const {
return mRadius;}
277 inline Float_t StEmcGeom::YWidth()
const {
return mYWidth;}
278 inline Float_t StEmcGeom::EtaMax()
const {
return mEtaMax;}
279 inline Float_t StEmcGeom::EtaMin()
const {
return mEtaMin;}
280 inline const Float_t* StEmcGeom::PhiModule()
const {
return mPhiModule.GetArray();}
281 inline const Float_t* StEmcGeom::PhiOffset()
const {
return mPhiOffset.GetArray();}
282 inline const Float_t* StEmcGeom::PhiStep()
const {
return mPhiStep.GetArray();}
283 inline const Float_t* StEmcGeom::PhiBound()
const {
return mPhiBound.GetArray();}
284 inline const Float_t* StEmcGeom::Zlocal()
const {
return mZlocal.GetArray();}
285 inline const Float_t* StEmcGeom::Eta()
const {
return mEta.GetArray();}
286 inline const Float_t* StEmcGeom::Ylocal()
const {
return mYlocal.GetArray();}
287 inline const Float_t* StEmcGeom::Phi()
const {
return mPhi.GetArray();}
289 inline const Float_t* StEmcGeom::EtaB()
const {
return mEtaB.GetArray();}
290 inline const Float_t* StEmcGeom::PhiB()
const {
return mPhiB.GetArray();}
292 inline void StEmcGeom::setDetector(
const Int_t val) { mDetector = val;}
293 inline void StEmcGeom::setRadius(
const Float_t val) { mRadius = val;}
294 inline void StEmcGeom::setYWidth(
const Float_t val) { mYWidth = val;}
297 inline Int_t StEmcGeom::checkModule(
const Int_t m)
const
299 if(m>=1 && m<=mNModule)
return 0;
300 else {LOG_ERROR<<
" Bad module# "<<m<<
"/"<<mNModule<<
" in Detector "<<mDetector<<endm;
return 1;}
303 inline Int_t StEmcGeom::checkEta(
const Int_t e)
const
305 if(e>=1 && e<=mNEta)
return 0;
306 else {LOG_ERROR<<
" Bad eta# "<<e<<endm;
return 1;}
309 inline Int_t StEmcGeom::checkSub(
const Int_t s)
const
311 if(s>=1 && s<=mNSub)
return 0;
312 else {LOG_ERROR<<
" Bad sub# "<<s<<endm;
return 1;}
315 inline Int_t StEmcGeom::checkId(
const Int_t softId)
const
317 if(softId>=1 && softId<=mNRaw)
return 0;
318 else {LOG_ERROR<<
" Bad raw# "<<softId<<endm;
return 1;}
321 inline Int_t
StEmcGeom::getBin(
const Float_t phi,
const Float_t eta, Int_t &m, Int_t &e, Int_t &s)
const
330 if(mEtaMin<eta && eta<=mEtaMax) {
331 e = getIndex(eta, mEtaB);
332 phiw = mPhiBound[0] - phi;
333 if(phiw<0.0) phiw = phiw + C_2PI;
334 if(phiw<0.0 || phiw>C_2PI) printf(
" phi %f eta %f \n",phi,eta);
335 m = int(-phiw/mPhiStep[0]) + 1;
337 sw = fmod(phiw, fabs(mPhiStep[0]));
338 sw = sw - mPhiStepHalf;
339 s = getIndex(sw, mPhiB);
343 }
else if(-mEtaMax<=eta && eta<-mEtaMin) {
344 e = getIndex(fabs(eta), mEtaB);
345 phiw = mPhiBound[1] - phi;
346 if(phiw<0.0) phiw = phiw + C_2PI;
347 if(phiw<0.0 || phiw>C_2PI) printf(
" phi %f eta %f \n",phi,eta);
348 m = 120 - int(phiw/fabs(mPhiStep[1]));
350 sw = fmod(phiw, fabs(mPhiStep[0]));
351 sw = -(sw - mPhiStepHalf);
352 s = getIndex(sw, mPhiB);
359 inline Int_t StEmcGeom::getId(
const Float_t phi,
const Float_t eta, Int_t &softId)
const
362 if(
getBin(phi,eta,m,e,s) == 0 && s != -1) {
363 return getId(m,e,s,softId);
368 inline Int_t StEmcGeom::getZlYl(
const Int_t softId, Float_t &zl, Float_t &yl)
const
371 if(!
getBin(softId, m, e, s)){
379 inline void StEmcGeom::getXYZ(
const Int_t m,
const Int_t e,
const Int_t s, Float_t &x,Float_t &y,Float_t &z)
const
382 if(m<=60) z = mZlocal[e-1];
383 else z =-mZlocal[e-1];
385 x = mRadius*cos(phi);
386 y = mRadius*sin(phi);
389 inline Int_t StEmcGeom::getXYZ(
const Int_t softId, Float_t &x,Float_t &y,Float_t &z)
const
392 if(!
getBin(softId, m, e, s)){
393 getXYZ(m,e,s, x,y,z);
399 inline Int_t StEmcGeom::getXYZfromGeant(
const Int_t ivid,Float_t &x,Float_t &y,Float_t &z)
402 if(getVolId(ivid, m,e,s,det) == 0){
403 getXYZ(m,e,s, x,y,z);
409 inline Int_t StEmcGeom::getEta(
const Int_t m,
const Int_t e, Float_t &eta)
const
411 if(!checkModule(m) && !checkEta(e)){
412 if(m <= mNModule/2) eta = mEta[e-1];
413 else eta = -mEta[e-1];
419 inline Int_t StEmcGeom::getEta(
const Int_t softId, Float_t &eta)
const
422 if(
getBin(softId,m,e,s) == 0) {
423 return getEta(m,e,eta);
428 inline Int_t StEmcGeom::getTheta(
const Int_t m,
const Int_t e, Float_t &theta)
const
431 if(!getEta(m,e, etaw)) { theta = 2.*atan(exp(-etaw));
return 0;}
435 inline Int_t StEmcGeom::getTheta(
const Int_t softId, Float_t &theta)
const
438 if(
getBin(softId,m,e,s) == 0) {
439 return getTheta(m,e,theta);
444 inline Int_t StEmcGeom::getPhi(
const Int_t m,
const Int_t s, Float_t &phi)
const
450 if(!checkModule(m) && !checkSub(s)){
454 if(m <= mNModule/2) {phiW = -mPhi[s-1]; im = 0; iphi=m-1;}
455 else {phiW = mPhi[s-1]; im = 1; iphi=m-mNModule/2-1;}
457 phiW += mPhiOffset[im] + mPhiStep[im]*iphi;
459 while(phiW >= C_PI) phiW -= C_2PI;
460 while(phiW < -C_PI) phiW += C_2PI;
461 if(phiW > (C_PI-0.0001)) phiW = -C_PI;
469 inline Int_t StEmcGeom::getPhi(
const Int_t softId, Float_t &phi)
const
472 if(
getBin(softId,m,e,s) == 0) {
473 return getPhi(m,s,phi);
478 inline Int_t StEmcGeom::getEtaPhi(
const Int_t softId, Float_t &eta, Float_t &phi)
const
481 if(!
getBin(softId, m, e, s)) {
489 inline Int_t StEmcGeom::getPhiModule(
const Int_t m, Float_t &phi)
const
491 if(!checkModule(m)) { phi=mPhiModule[m-1];
return 0;}
495 inline Int_t StEmcGeom::getIndex(
const Float_t &x,
const TArrayF &arr)
const
498 for(Int_t i=1; i<arr.GetSize(); i++){
499 if(x>=arr[i-1] && x<arr[i])
return i;
505 inline Int_t StEmcGeom::getId(
const Int_t m,
const Int_t e,
const Int_t s, Int_t &softId)
const
507 if(!checkModule(m) && !checkEta(e) && !checkSub(s)) {
508 softId = mNes*(m-1) + mNEta*(s-1) + e;
512 LOG_WARN << Form(
"<W> getId(2001 Aug Scheme) | Det %i bad index m %i e %i s %i ",mDetector,m,e,s) << endm;
521 if(!checkId(softId)) {
524 j = wid - mNes*(m-1);
538 StEmcGeom::getId(
const Int_t m,
const Int_t e,
const Int_t s,Int_t &rid)
540 if(!checkModule(m) && !checkEta(e) && !checkSub(s)){
541 if(mDetector==1 || mDetector==2) {
542 rid = 40*(m-1) + 20*(s-1) + (21-e);
544 if(mDetector==3 || mDetector==4) {
545 rid = mNes*(m-1) + mNEta*(s-1) + (mNEta - e) + 1;
550 printf(
"<W> Det %i bad index m %i e %i s %i \n", mDetector, m, e, s);
566 if(mDetector==1 || mDetector==2) {
567 if(checkId(rid) == 1)
return 1;
568 m = (rid - 1) / 40 + 1;
569 idw = (rid - 1) % 40;
574 else if(mDetector==3 || mDetector==4) {
575 if(checkId(rid) == 1)
return 1;
576 m = (rid - 1) / mNes + 1;
577 idw = (rid - 1) % mNes;
579 e = mNEta - idw%mNEta;
583 cout<<
" Wrong number of detector "<<mDetector<<endl;
Int_t getBin(const Float_t phi, const Float_t eta, Int_t &m, Int_t &e, Int_t &s) const