00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 #ifndef STAR_StEmcGeom
00102 #define STAR_StEmcGeom
00103
00105
00106
00107
00109 #include <Stiostream.h>
00110 #include "math_constants.h"
00111 #include <math.h>
00112 #include <TArrayF.h>
00113 #include <TString.h>
00114 #include "tables/St_calb_calg_Table.h"
00115 #include "tables/St_calb_calr_Table.h"
00116 #include "StMessMgr.h"
00117
00118 class StMaker;
00119 class TDataSet;
00120
00121 class StEmcGeom {
00122 private:
00123 static StEmcGeom *mGeom[8];
00124
00125 StMaker* mChain;
00126 TDataSet* mGeantGeom;
00127 St_calb_calg* mCalg;
00128 calb_calg_st* mCalg_st;
00129 St_calb_calr* mCalr;
00130 calb_calr_st* mCalr_st;
00131
00132 void defineDefaultCommonConstants();
00133 void defineCommonConstants();
00134 void defineModuleGridOnPhi();
00135 Float_t relativeError(Float_t, Float_t) const;
00136
00137 Int_t getIndex(const Float_t &x, const TArrayF &arr) const;
00138
00139
00140 protected:
00141 TString mMode;
00142 Int_t mDetector;
00143 Int_t mNModule;
00144 Int_t mNEta;
00145 Int_t mNSub;
00146 Int_t mNes;
00147 Int_t mNRaw;
00148 Float_t mRadius;
00149 Float_t mYWidth;
00150 Float_t mEtaMax;
00151 Float_t mEtaMin;
00152 TArrayF mPhiOffset;
00153 TArrayF mPhiStep;
00154 TArrayF mPhiBound;
00155 Float_t mPhiStepHalf;
00156
00157 TArrayF mZlocal;
00158 TArrayF mYlocal;
00159 TArrayF mEta;
00160 TArrayF mEtaB;
00161 TArrayF mPhi;
00162 TArrayF mPhiModule;
00163 TArrayF mYB;
00164 TArrayF mPhiB;
00165
00166 Int_t mMaxAdc;
00167
00168 public:
00169 StEmcGeom(const Int_t );
00170 StEmcGeom(const Char_t*);
00171 StEmcGeom(const Int_t ,const Char_t*);
00172
00173 static StEmcGeom *instance(const Int_t det);
00174 static StEmcGeom *getEmcGeom(const Int_t det);
00175 static StEmcGeom *instance(const Char_t* cdet);
00176 static StEmcGeom *getEmcGeom(const Char_t* cdet);
00177 static StEmcGeom *instance(const Int_t det, const Char_t* mode);
00178 static StEmcGeom *getEmcGeom(const Int_t det, const Char_t* mode);
00179
00180 static Int_t getDetNumFromName(const Char_t *cdet);
00181
00182 virtual ~StEmcGeom();
00183
00184 const TString* Mode() const;
00185 Int_t Detector() const;
00186 Int_t NModule() const;
00187 Int_t NEta() const;
00188 Int_t NSub() const;
00189 Int_t Nes() const;
00190 Int_t NRaw() const;
00191 Float_t Radius() const;
00192 Float_t YWidth() const;
00193 Float_t EtaMax() const;
00194 Float_t EtaMin() const;
00195 const Float_t* PhiModule() const;
00196 const Float_t* PhiOffset() const;
00197 const Float_t* PhiStep() const;
00198 const Float_t* PhiBound() const;
00199 const Float_t* Zlocal() const;
00200 const Float_t* Eta() const;
00201 const Float_t* Ylocal() const;
00202 const Float_t* Phi() const;
00203
00204 const Float_t* EtaB() const;
00205 const Float_t* PhiB() const;
00206
00207 void setDetector(const Int_t val);
00208 void setRadius(const Float_t val);
00209 void setYWidth(const Float_t val);
00210
00211
00212 Int_t checkModule(const Int_t m) const;
00213 Int_t checkEta(const Int_t e) const;
00214 Int_t checkSub(const Int_t s) const;
00215 Int_t checkId(const Int_t softId) const;
00216
00217
00218 Int_t getBin(const Float_t phi, const Float_t eta, Int_t &m, Int_t &e, Int_t &s) const;
00219 Int_t getId(const Float_t phi, const Float_t eta, Int_t &softId) const;
00220
00221
00222 Int_t getBin(const Int_t softId, Int_t &m, Int_t &e, Int_t &s) const;
00223 Int_t getId(const Int_t m, const Int_t e, const Int_t s, Int_t &softId) const;
00224
00225 Int_t getVolIdBemc(const Int_t ivid, Int_t &module, Int_t &eta, Int_t &sub, Int_t &detector);
00226 Int_t getVolIdBsmd(const Int_t ivid, Int_t &module, Int_t &eta, Int_t &sub, Int_t &detector);
00227 Int_t getVolId(const Int_t ivid, Int_t &module, Int_t &eta, Int_t &sub, Int_t &det);
00228
00229 Int_t getZlYl(const Int_t softId, Float_t &zl, Float_t &yl) const;
00230 void getXYZ(const Int_t m, const Int_t e, const Int_t s, Float_t &x, Float_t &y, Float_t &z) const;
00231 Int_t getXYZ(const Int_t softId, Float_t &x, Float_t &y, Float_t &z) const;
00232 Int_t getXYZfromGeant(const Int_t ivid, Float_t &x, Float_t &y, Float_t &z);
00233
00234 Int_t getEta(const Int_t m, const Int_t e, Float_t &eta) const;
00235 Int_t getEta(const Int_t softId, Float_t &eta) const;
00236
00237 Int_t getTheta(const Int_t m, const Int_t e, Float_t &theta) const;
00238 Int_t getTheta(const Int_t softId, Float_t &theta) const;
00239
00240 Int_t getPhi(const Int_t m, const Int_t s, Float_t &phi) const;
00241 Int_t getPhi(const Int_t softId, Float_t &phi) const;
00242
00243 Int_t getEtaPhi(const Int_t softId, Float_t &eta, Float_t &phi) const;
00244
00245 Int_t getPhiModule(const Int_t m, Float_t &phi) const;
00246
00247 Int_t getMaxAdc() const {return mMaxAdc;}
00248
00249 void initGeom(const Int_t);
00250 void initBEMCorBPRS();
00251 void initBSMDE();
00252 void initBSMDP();
00253 void initEEMCorEPRS();
00254 void initESMDE();
00255 void initESMDP();
00256 void printGeom() const;
00257 void print() const {printGeom();}
00258 void compare(const StEmcGeom &, Bool_t) const;
00259 void compare(const StEmcGeom * const g, Bool_t key) const {compare(*g,key);};
00260 void printError(Float_t) const;
00261
00262 Float_t toDeg(const Float_t angR) const {return C_DEG_PER_RAD*angR;}
00263 Float_t toRad(const Float_t angD) const {return angD/C_DEG_PER_RAD;}
00264 void getGeantGeometryTable();
00265
00266 ClassDef(StEmcGeom,1)
00267 };
00268
00269 inline const TString* StEmcGeom::Mode() const {return &mMode;}
00270 inline Int_t StEmcGeom::Detector() const {return mDetector;}
00271 inline Int_t StEmcGeom::NModule() const {return mNModule;}
00272 inline Int_t StEmcGeom::NEta() const {return mNEta;}
00273 inline Int_t StEmcGeom::NSub() const {return mNSub;}
00274 inline Int_t StEmcGeom::Nes() const {return mNes;}
00275 inline Int_t StEmcGeom::NRaw() const {return mNRaw;}
00276 inline Float_t StEmcGeom::Radius() const {return mRadius;}
00277 inline Float_t StEmcGeom::YWidth() const {return mYWidth;}
00278 inline Float_t StEmcGeom::EtaMax() const {return mEtaMax;}
00279 inline Float_t StEmcGeom::EtaMin() const {return mEtaMin;}
00280 inline const Float_t* StEmcGeom::PhiModule() const {return mPhiModule.GetArray();}
00281 inline const Float_t* StEmcGeom::PhiOffset() const {return mPhiOffset.GetArray();}
00282 inline const Float_t* StEmcGeom::PhiStep() const {return mPhiStep.GetArray();}
00283 inline const Float_t* StEmcGeom::PhiBound() const {return mPhiBound.GetArray();}
00284 inline const Float_t* StEmcGeom::Zlocal() const {return mZlocal.GetArray();}
00285 inline const Float_t* StEmcGeom::Eta() const {return mEta.GetArray();}
00286 inline const Float_t* StEmcGeom::Ylocal() const {return mYlocal.GetArray();}
00287 inline const Float_t* StEmcGeom::Phi() const {return mPhi.GetArray();}
00288
00289 inline const Float_t* StEmcGeom::EtaB() const {return mEtaB.GetArray();}
00290 inline const Float_t* StEmcGeom::PhiB() const {return mPhiB.GetArray();}
00291
00292 inline void StEmcGeom::setDetector(const Int_t val) { mDetector = val;}
00293 inline void StEmcGeom::setRadius(const Float_t val) { mRadius = val;}
00294 inline void StEmcGeom::setYWidth(const Float_t val) { mYWidth = val;}
00295
00296
00297 inline Int_t StEmcGeom::checkModule(const Int_t m) const
00298 {
00299 if(m>=1 && m<=mNModule) return 0;
00300 else {LOG_ERROR<<" Bad module# "<<m<<"/"<<mNModule<<" in Detector "<<mDetector<<endm; return 1;}
00301 }
00302
00303 inline Int_t StEmcGeom::checkEta(const Int_t e) const
00304 {
00305 if(e>=1 && e<=mNEta) return 0;
00306 else {LOG_ERROR<<" Bad eta# "<<e<<endm; return 1;}
00307 }
00308
00309 inline Int_t StEmcGeom::checkSub(const Int_t s) const
00310 {
00311 if(s>=1 && s<=mNSub) return 0;
00312 else {LOG_ERROR<<" Bad sub# "<<s<<endm; return 1;}
00313 }
00314
00315 inline Int_t StEmcGeom::checkId(const Int_t softId) const
00316 {
00317 if(softId>=1 && softId<=mNRaw) return 0;
00318 else {LOG_ERROR<<" Bad raw# "<<softId<<endm; return 1;}
00319 }
00320
00321 inline Int_t StEmcGeom::getBin(const Float_t phi, const Float_t eta, Int_t &m, Int_t &e, Int_t &s) const
00322 {
00323
00325
00326
00327
00328
00329 Float_t phiw, sw;
00330 if(mEtaMin<eta && eta<=mEtaMax) {
00331 e = getIndex(eta, mEtaB);
00332 phiw = mPhiBound[0] - phi;
00333 if(phiw<0.0) phiw = phiw + C_2PI;
00334 if(phiw<0.0 || phiw>C_2PI) printf(" phi %f eta %f \n",phi,eta);
00335 m = int(-phiw/mPhiStep[0]) + 1;
00336
00337 sw = fmod(phiw, fabs(mPhiStep[0]));
00338 sw = sw - mPhiStepHalf;
00339 s = getIndex(sw, mPhiB);
00340
00341 return 0;
00342
00343 } else if(-mEtaMax<=eta && eta<-mEtaMin) {
00344 e = getIndex(fabs(eta), mEtaB);
00345 phiw = mPhiBound[1] - phi;
00346 if(phiw<0.0) phiw = phiw + C_2PI;
00347 if(phiw<0.0 || phiw>C_2PI) printf(" phi %f eta %f \n",phi,eta);
00348 m = 120 - int(phiw/fabs(mPhiStep[1]));
00349
00350 sw = fmod(phiw, fabs(mPhiStep[0]));
00351 sw = -(sw - mPhiStepHalf);
00352 s = getIndex(sw, mPhiB);
00353
00354 return 0;
00355
00356 } else return 1;
00357 }
00358
00359 inline Int_t StEmcGeom::getId(const Float_t phi, const Float_t eta, Int_t &softId) const
00360 {
00361 Int_t m,e,s;
00362 if(getBin(phi,eta,m,e,s) == 0 && s != -1) {
00363 return getId(m,e,s,softId);
00364 }
00365 return 1;
00366 }
00367
00368 inline Int_t StEmcGeom::getZlYl(const Int_t softId, Float_t &zl, Float_t &yl) const
00369 {
00370 Int_t m, e, s;
00371 if(!getBin(softId, m, e, s)){
00372 zl = mZlocal[e-1];
00373 yl = mYlocal[s-1];
00374 return 0;
00375 }
00376 else return 1;
00377 }
00378
00379 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
00380 {
00381 Float_t phi;
00382 if(m<=60) z = mZlocal[e-1];
00383 else z =-mZlocal[e-1];
00384 getPhi(m,s,phi);
00385 x = mRadius*cos(phi);
00386 y = mRadius*sin(phi);
00387 }
00388
00389 inline Int_t StEmcGeom::getXYZ(const Int_t softId, Float_t &x,Float_t &y,Float_t &z) const
00390 {
00391 Int_t m, e, s;
00392 if(!getBin(softId, m, e, s)){
00393 getXYZ(m,e,s, x,y,z);
00394 return 0;
00395 }
00396 else return 1;
00397 }
00398
00399 inline Int_t StEmcGeom::getXYZfromGeant(const Int_t ivid,Float_t &x,Float_t &y,Float_t &z)
00400 {
00401 Int_t m, e, s, det;
00402 if(getVolId(ivid, m,e,s,det) == 0){
00403 getXYZ(m,e,s, x,y,z);
00404 return 0;
00405 }
00406 else return 1;
00407 }
00408
00409 inline Int_t StEmcGeom::getEta(const Int_t m, const Int_t e, Float_t &eta) const
00410 {
00411 if(!checkModule(m) && !checkEta(e)){
00412 if(m <= mNModule/2) eta = mEta[e-1];
00413 else eta = -mEta[e-1];
00414 return 0;
00415 }
00416 else return 1;
00417 }
00418
00419 inline Int_t StEmcGeom::getEta(const Int_t softId, Float_t &eta) const
00420 {
00421 Int_t m,e,s;
00422 if(getBin(softId,m,e,s) == 0) {
00423 return getEta(m,e,eta);
00424 }
00425 return 1;
00426 }
00427
00428 inline Int_t StEmcGeom::getTheta(const Int_t m, const Int_t e, Float_t &theta) const
00429 {
00430 Float_t etaw;
00431 if(!getEta(m,e, etaw)) { theta = 2.*atan(exp(-etaw)); return 0;}
00432 else return 1;
00433 }
00434
00435 inline Int_t StEmcGeom::getTheta(const Int_t softId, Float_t &theta) const
00436 {
00437 Int_t m,e,s;
00438 if(getBin(softId,m,e,s) == 0) {
00439 return getTheta(m,e,theta);
00440 }
00441 return 1;
00442 }
00443
00444 inline Int_t StEmcGeom::getPhi(const Int_t m, const Int_t s, Float_t &phi) const
00445 {
00446
00447
00448
00449 Int_t iphi, im;
00450 if(!checkModule(m) && !checkSub(s)){
00451 Double_t phiW;
00452
00453
00454 if(m <= mNModule/2) {phiW = -mPhi[s-1]; im = 0; iphi=m-1;}
00455 else {phiW = mPhi[s-1]; im = 1; iphi=m-mNModule/2-1;}
00456
00457 phiW += mPhiOffset[im] + mPhiStep[im]*iphi;
00458
00459 while(phiW >= C_PI) phiW -= C_2PI;
00460 while(phiW < -C_PI) phiW += C_2PI;
00461 if(phiW > (C_PI-0.0001)) phiW = -C_PI;
00462
00463 phi = phiW;
00464 return 0;
00465 }
00466 else return 1;
00467 }
00468
00469 inline Int_t StEmcGeom::getPhi(const Int_t softId, Float_t &phi) const
00470 {
00471 Int_t m,e,s;
00472 if(getBin(softId,m,e,s) == 0) {
00473 return getPhi(m,s,phi);
00474 }
00475 return 1;
00476 }
00477
00478 inline Int_t StEmcGeom::getEtaPhi(const Int_t softId, Float_t &eta, Float_t &phi) const
00479 {
00480 Int_t m=0, e=0, s=0;
00481 if(!getBin(softId, m, e, s)) {
00482 getEta(m, e, eta);
00483 getPhi(m, s, phi);
00484 return 0;
00485 }
00486 else return 1;
00487 }
00488
00489 inline Int_t StEmcGeom::getPhiModule(const Int_t m, Float_t &phi) const
00490 {
00491 if(!checkModule(m)) { phi=mPhiModule[m-1]; return 0;}
00492 else return 1;
00493 }
00494
00495 inline Int_t StEmcGeom::getIndex(const Float_t &x, const TArrayF &arr) const
00496 {
00497
00498 for(Int_t i=1; i<arr.GetSize(); i++){
00499 if(x>=arr[i-1] && x<arr[i]) return i;
00500 }
00501 return -1;
00502 }
00503
00504 #ifndef WSUJoseMarch
00505 inline Int_t StEmcGeom::getId(const Int_t m, const Int_t e, const Int_t s, Int_t &softId) const
00506 {
00507 if(!checkModule(m) && !checkEta(e) && !checkSub(s)) {
00508 softId = mNes*(m-1) + mNEta*(s-1) + e;
00509 return 0;
00510 }
00511 else {
00512 LOG_WARN << Form("<W> getId(2001 Aug Scheme) | Det %i bad index m %i e %i s %i ",mDetector,m,e,s) << endm;
00513 return 1;
00514 }
00515 }
00516
00517 inline Int_t
00518 StEmcGeom::getBin(const Int_t softId, Int_t &m, Int_t &e, Int_t &s) const
00519 {
00520 static Int_t j, wid;
00521 if(!checkId(softId)) {
00522 wid = softId - 1;
00523 m = wid/mNes + 1;
00524 j = wid - mNes*(m-1);
00525 s = j/mNEta + 1;
00526 e = j%mNEta + 1;
00527 return 0;
00528 }
00529 else return 1;
00530 }
00531 #endif
00532
00533 #ifdef WSUJoseMarch
00534
00535
00536
00537 inline Int_t
00538 StEmcGeom::getId(const Int_t m, const Int_t e, const Int_t s,Int_t &rid)
00539 {
00540 if(!checkModule(m) && !checkEta(e) && !checkSub(s)){
00541 if(mDetector==1 || mDetector==2) {
00542 rid = 40*(m-1) + 20*(s-1) + (21-e);
00543 }
00544 if(mDetector==3 || mDetector==4) {
00545 rid = mNes*(m-1) + mNEta*(s-1) + (mNEta - e) + 1;
00546 }
00547 return 0;
00548 }
00549 else {
00550 printf("<W> Det %i bad index m %i e %i s %i \n", mDetector, m, e, s);
00551 return 1;
00552 }
00553 }
00554
00555 inline Int_t
00556 StEmcGeom::getBin(const Int_t rid,Int_t &m,Int_t &e,Int_t &s)
00557 {
00558
00559
00560
00561
00562
00563
00564
00565 Int_t idw;
00566 if(mDetector==1 || mDetector==2) {
00567 if(checkId(rid) == 1) return 1;
00568 m = (rid - 1) / 40 + 1;
00569 idw = (rid - 1) % 40;
00570 s = idw/20 + 1;
00571 e = 20 - idw%20;
00572 return 0;
00573 }
00574 else if(mDetector==3 || mDetector==4) {
00575 if(checkId(rid) == 1) return 1;
00576 m = (rid - 1) / mNes + 1;
00577 idw = (rid - 1) % mNes;
00578 s = idw/mNEta + 1;
00579 e = mNEta - idw%mNEta;
00580 return 0;
00581 }
00582 else {
00583 cout<<" Wrong number of detector "<<mDetector<<endl;
00584 return 1;
00585 }
00586 }
00587
00588 #endif
00589
00590 #endif