///////////////////////////////////////////////////////////// // //----------------------------------------------------------------------- // File and Version Information: // $Id:$ // // Description: // EMC Mapper class. Map crystal index (fDetectorId) to two coordinate index. // // This class uses the singleton pattern design // Author List: // Dima Melnychuk // 27/04/2007 Stefano Spataro (encoding for the Fwd Endcup) // /////////////////////////////////////////////////////////////// #include "EmcMapper.h" #include "TwoCoordIndex.h" #include #include using namespace std; EmcMapper* EmcMapper::_instance = 0; EmcMapper* EmcMapper::Instance (int MapVersion) { if (_instance == 0) { _instance = new EmcMapper(MapVersion); } return _instance; } // ----- Destructor ----------------------------------- EmcMapper::~EmcMapper() {} // -------------------------------------------------------- EmcMapper::EmcMapper(Int_t MapVersion):fMapVersion(MapVersion) { TwoCoordIndex _tci; Int_t iTheta, iPhi, detId, detId_tmp, iX, iY; if (fMapVersion==1) { // Crys 1-5000; copyNo 1-20; nRow 1-100, nMod 1-5 // 72(iTheta)x160(iPhi) for barrel part // index iTheta from 1 (backward part) till 72 (forward) for (Int_t module=1; module<=5; module++) { if (module ==2) { for (Int_t row=1; row<=29;row++) for (Int_t crystal=1; crystal<=10;crystal++) for (Int_t copy=1; copy<=16;copy++) { iPhi=crystal+(copy-1)*10; iTheta=row; detId = module*100000000 + row*1000000 + copy*10000 + crystal; TwoCoordIndex* _tci=new TwoCoordIndex(iTheta,iPhi,detId); fIntTwoCoordMap[detId]=_tci; } } else if (module ==1) { for (Int_t row=1; row<=43;row++) for (Int_t crystal=1; crystal<=10;crystal++) for (Int_t copy=1; copy<=16;copy++) { iPhi=crystal+(copy-1)*10; iTheta=row+29; detId = module*100000000 + row*1000000 + copy*10000 + crystal; TwoCoordIndex* _tci=new TwoCoordIndex(iTheta,iPhi,detId); fIntTwoCoordMap[detId]=_tci; } } if (module ==3) { for (Int_t row=1; row<=40;row++) for (Int_t crystal=1; crystal<=40;crystal++) for (Int_t copy=1; copy<=4;copy++) { if (copy==1) { iX = -row+1; iY = crystal; } if (copy==2) { iX = -row+1; iY = -crystal+1; } if (copy==3) { iX = row; iY = -crystal+1; } if (copy==4) { iX = row; iY = crystal; } detId = module*100000000 + row*1000000 + copy*10000 + crystal; TwoCoordIndex* _tci=new TwoCoordIndex(iX+250,iY+250,detId); fIntTwoCoordMap[detId]=_tci; } } if (module ==4) { for (Int_t row=1; row<=18;row++) for (Int_t crystal=1; crystal<=18;crystal++) for (Int_t copy=1; copy<=4;copy++) { if (copy==1) { iX = -row+1; iY = crystal; } if (copy==2) { iX = -row+1; iY = -crystal+1; } if (copy==3) { iX = row; iY = -crystal+1; } if (copy==4) { iX = row; iY = crystal; } detId = module*100000000 + row*1000000 + copy*10000 + crystal; TwoCoordIndex* _tci=new TwoCoordIndex(iX+350,iY+350,detId); fIntTwoCoordMap[detId]=_tci; } } if (module ==5) { for (Int_t row=1; row<=14;row++) for (Int_t crystal=1; crystal<=7;crystal++) for (Int_t copy=1; copy<=4;copy++) { if (copy==1) { iX = -row+1; iY = crystal; } if (copy==2) { iX = -row+1; iY = -crystal+1; } if (copy==3) { iX = row; iY = -crystal+1; } if (copy==4) { iX = row; iY = crystal; } detId = module*100000000 + row*1000000 + copy*10000 + crystal; TwoCoordIndex* _tci=new TwoCoordIndex(iX+450,iY+450,detId); fIntTwoCoordMap[detId]=_tci; } } } //fill neigbour list std::map ::const_iterator tciIter; for(tciIter=fIntTwoCoordMap.begin();tciIter!=fIntTwoCoordMap.end();++tciIter) { TwoCoordIndex* _tci=tciIter->second; detId=tciIter->first; iTheta=_tci->itsXCoord(); iPhi=_tci->itsYCoord(); for (Int_t i=iTheta-1;i<=iTheta+1;i++) for (Int_t j=iPhi-1;j<=iPhi+1;j++) { if ((i!= 0)&&(i!= 73)&&(j!= 0)&&(j!=161)&& // Boundaries of module 1&2 (i!=210)&&(i!=291)&&(j!=210)&&(j!=291)&& // Boundaries of module 3 (i!=332)&&(i!=369)&&(j!=332)&&(j!=369)&& // Boundaries of module 4 (i!=465)&&(i!=436)&&(j!=458)&&(j!=443)&& // Boundaries of module 5 ((i!=iTheta)||(j!=iPhi))) { detId_tmp=EmcMapper::GetDetId(i,j); TwoCoordIndex* tci_tmp=fIntTwoCoordMap[detId_tmp]; _tci->addToNeighbourList(tci_tmp); fIntTwoCoordMap[detId]=_tci; } else if ((i!=0)&&(i!=73)&&(j==0)) { detId_tmp=EmcMapper::GetDetId(i,160); TwoCoordIndex* tci_tmp=fIntTwoCoordMap[detId_tmp]; _tci->addToNeighbourList(tci_tmp); fIntTwoCoordMap[detId]=_tci; } else if ((i!=0)&&(i!=73)&&(j==161)) { detId_tmp=EmcMapper::GetDetId(i,1); TwoCoordIndex* tci_tmp=fIntTwoCoordMap[detId_tmp]; _tci->addToNeighbourList(tci_tmp); fIntTwoCoordMap[detId]=_tci; } } } } } TwoCoordIndex* EmcMapper::GetTCI(Int_t DetectorId) { TwoCoordIndex* tci= fIntTwoCoordMap[DetectorId]; return tci; }; const std::map& EmcMapper::GetTciMap() { return fIntTwoCoordMap; } Int_t EmcMapper::GetDetId(Int_t iTheta,Int_t iPhi) { Int_t module,row,copy,crystal,detId; if (iTheta<=29) { module=2; row=iTheta; copy=(iPhi-1)/10+1; crystal=(iPhi-1)%10+1; } else if ((iTheta>29)&&(iTheta<73)) { module=1; row=iTheta-29; copy=(iPhi-1)/10+1; crystal=(iPhi-1)%10+1; } if ((iTheta>200)&&(iTheta<300)) { module=3; if ((iTheta<=250)&& (iPhi>250)) { copy = 1; row = 1-(iTheta-250); crystal = iPhi-250; } if ((iTheta<=250)&& (iPhi<=250)) { copy = 2; row = 1-(iTheta-250); crystal = 1-(iPhi-250); } if ((iTheta>250)&& (iPhi<=250)) { copy = 3; row = (iTheta-250); crystal = 1-(iPhi-250); } if ((iTheta>250)&& (iPhi>250)) { copy = 4; row = iTheta-250; crystal = iPhi-250; } } if ((iTheta>300)&&(iTheta<400)) { module=4; if ((iTheta<=350)&& (iPhi>350)) { copy = 1; row = 1-(iTheta-350); crystal = iPhi-350; } if ((iTheta<=350)&& (iPhi<=350)) { copy = 2; row = 1-(iTheta-350); crystal = 1-(iPhi-350); } if ((iTheta>350)&& (iPhi<=350)) { copy = 3; row = (iTheta-350); crystal = 1-(iPhi-350); } if ((iTheta>350)&& (iPhi>350)) { copy = 4; row = (iTheta-350); crystal = iPhi-350; } } if ((iTheta>400)&&(iTheta<500)) { module=5; if ((iTheta<=450)&& (iPhi>450)) { copy = 1; row = 1-(iTheta-450); crystal = iPhi-450; } if ((iTheta<=450)&& (iPhi<=450)) { copy = 2; row = 1-(iTheta-450); crystal = 1-(iPhi-450); } if ((iTheta>450)&& (iPhi<=450)) { copy = 3; row = (iTheta-450); crystal = 1-(iPhi-450); } if ((iTheta>450)&& (iPhi>450)) { copy = 4; row = (iTheta-450); crystal = iPhi-450; } } detId = module*100000000 + row*1000000 + copy*10000 + crystal; return detId; } ClassImp(EmcMapper)