+Int_t AliEMCALGeometry::GetSuperModuleNumber(Int_t absId) const
+{
+ // Return the number of the supermodule given the absolute
+ // ALICE numbering id
+
+ static Int_t nSupMod, nModule, nIphi, nIeta;
+ GetCellIndex(absId, nSupMod, nModule, nIphi, nIeta);
+ return nSupMod;
+}
+
+void AliEMCALGeometry::GetModuleIndexesFromCellIndexesInSModule(Int_t nSupMod, Int_t iphi, Int_t ieta,
+ Int_t &iphim, Int_t &ietam, Int_t &nModule) const
+{
+ // Transition from cell indexes (ieta,iphi) to module indexes (ietam,iphim, nModule)
+ static Int_t nphi;
+ nphi = GetNumberOfModuleInPhiDirection(nSupMod);
+
+ ietam = ieta/fNETAdiv;
+ iphim = iphi/fNPHIdiv;
+ nModule = ietam * nphi + iphim;
+}
+
+Int_t AliEMCALGeometry::GetAbsCellIdFromCellIndexes(Int_t nSupMod, Int_t iphi, Int_t ieta) const
+{
+ // Transition from super module number(nSupMod) and cell indexes (ieta,iphi) to absId
+ static Int_t ietam, iphim, nModule;
+ static Int_t nIeta, nIphi; // cell indexes in module
+
+ GetModuleIndexesFromCellIndexesInSModule(nSupMod, iphi, ieta, ietam, iphim, nModule);
+
+ nIeta = ieta%fNETAdiv;
+ nIeta = fNETAdiv - 1 - nIeta;
+ nIphi = iphi%fNPHIdiv;
+
+ return GetAbsCellId(nSupMod, nModule, nIphi, nIeta);
+}
+
+
+// Methods for AliEMCALRecPoint - Feb 19, 2006
+Bool_t AliEMCALGeometry::RelPosCellInSModule(Int_t absId, Double_t &xr, Double_t &yr, Double_t &zr) const
+{
+ // Look to see what the relative
+ // position inside a given cell is
+ // for a recpoint.
+ // Alice numbering scheme - Jun 08, 2006
+ // In:
+ // absId - cell is as in Geant, 0<= absId < fNCells;
+ // OUT:
+ // xr,yr,zr - x,y,z coordinates of cell with absId inside SM
+
+ // Shift index taking into account the difference between standard SM
+ // and SM of half size in phi direction
+ const Int_t phiIndexShift = fCentersOfCellsPhiDir.GetSize()/4; // Nov 22, 2006; was 6 for cas 2X2
+ static Int_t nSupMod, nModule, nIphi, nIeta, iphi, ieta;
+ if(!CheckAbsCellId(absId)) return kFALSE;
+
+ GetCellIndex(absId, nSupMod, nModule, nIphi, nIeta);
+ GetCellPhiEtaIndexInSModule(nSupMod,nModule,nIphi,nIeta, iphi, ieta);
+
+ xr = fCentersOfCellsXDir.At(ieta);
+ zr = fCentersOfCellsEtaDir.At(ieta);
+
+ if(nSupMod<10) {
+ yr = fCentersOfCellsPhiDir.At(iphi);
+ } else {
+ yr = fCentersOfCellsPhiDir.At(iphi + phiIndexShift);
+ }
+ AliDebug(1,Form("absId %i nSupMod %i iphi %i ieta %i xr %f yr %f zr %f ",absId,nSupMod,iphi,ieta,xr,yr,zr));
+
+ return kTRUE;
+}
+
+Bool_t AliEMCALGeometry::RelPosCellInSModule(Int_t absId, Double_t loc[3]) const
+{
+ // Alice numbering scheme - Jun 03, 2006
+ loc[0] = loc[1] = loc[2]=0.0;
+ if(RelPosCellInSModule(absId, loc[0],loc[1],loc[2])) {
+ return kTRUE;
+ }
+ return kFALSE;
+}
+
+Bool_t AliEMCALGeometry::RelPosCellInSModule(Int_t absId, TVector3 &vloc) const
+{
+ static Double_t loc[3];
+ if(RelPosCellInSModule(absId,loc)) {
+ vloc.SetXYZ(loc[0], loc[1], loc[2]);
+ return kTRUE;
+ } else {
+ vloc.SetXYZ(0,0,0);
+ return kFALSE;
+ }
+ // Alice numbering scheme - Jun 03, 2006
+}
+
+void AliEMCALGeometry::CreateListOfTrd1Modules()
+{
+ // Generate the list of Trd1 modules
+ // which will make up the EMCAL
+ // geometry
+
+ AliDebug(2,Form(" AliEMCALGeometry::CreateListOfTrd1Modules() started "));
+
+ AliEMCALShishKebabTrd1Module *mod=0, *mTmp=0; // current module
+ if(fShishKebabTrd1Modules == 0) {
+ fShishKebabTrd1Modules = new TList;
+ fShishKebabTrd1Modules->SetName("ListOfTRD1");
+ for(int iz=0; iz< GetNZ(); iz++) {
+ if(iz==0) {
+ mod = new AliEMCALShishKebabTrd1Module(TMath::Pi()/2.,this);
+ } else {
+ mTmp = new AliEMCALShishKebabTrd1Module(*mod);
+ mod = mTmp;
+ }
+ fShishKebabTrd1Modules->Add(mod);
+ }
+ } else {
+ AliDebug(2,Form(" Already exits : "));
+ }
+ mod = (AliEMCALShishKebabTrd1Module*)fShishKebabTrd1Modules->At(fShishKebabTrd1Modules->GetSize()-1);
+ fEtaMaxOfTRD1 = mod->GetMaxEtaOfModule(0);
+
+ AliDebug(2,Form(" fShishKebabTrd1Modules has %i modules : max eta %5.4f \n",
+ fShishKebabTrd1Modules->GetSize(),fEtaMaxOfTRD1));
+ // Feb 20,2006;
+ // Jun 01, 2006 - ALICE numbering scheme
+ // define grid for cells in eta(z) and x directions in local coordinates system of SM
+ // Works just for 2x2 case only -- ?? start here
+ //
+ //
+ // Define grid for cells in phi(y) direction in local coordinates system of SM
+ // as for 2X2 as for 3X3 - Nov 8,2006
+ //
+ AliDebug(2,Form(" Cells grid in phi directions : size %i\n", fCentersOfCellsPhiDir.GetSize()));
+ Int_t ind=0; // this is phi index
+ Int_t iphi=0, ieta=0, nModule=0, iphiTemp;
+ Double_t xr, zr, theta, phi, eta, r, x,y;
+ TVector3 vglob;
+ Double_t ytCenterModule, ytCenterCell;
+
+ fCentersOfCellsPhiDir.Set(fNPhi*fNPHIdiv);
+ fPhiCentersOfCells.Set(fNPhi*fNPHIdiv);
+
+ Double_t R0 = GetIPDistance() + GetLongModuleSize()/2.;
+ for(Int_t it=0; it<fNPhi; it++) { // cycle on modules
+ ytCenterModule = -fParSM[1] + fPhiModuleSize*(2*it+1)/2; // center of module
+ for(Int_t ic=0; ic<fNPHIdiv; ic++) { // cycle on cells in module
+ if(fNPHIdiv==2) {
+ ytCenterCell = ytCenterModule + fPhiTileSize *(2*ic-1)/2.;
+ } else if(fNPHIdiv==3){
+ ytCenterCell = ytCenterModule + fPhiTileSize *(ic-1);
+ } else if(fNPHIdiv==1){
+ ytCenterCell = ytCenterModule;
+ }
+ fCentersOfCellsPhiDir.AddAt(ytCenterCell,ind);
+ // Define grid on phi direction
+ // Grid is not the same for different eta bin;
+ // Effect is small but is still here
+ phi = TMath::ATan2(ytCenterCell, R0);
+ fPhiCentersOfCells.AddAt(phi, ind);
+
+ AliDebug(2,Form(" ind %2.2i : y %8.3f ", ind, fCentersOfCellsPhiDir.At(ind)));
+ ind++;
+ }
+ }
+
+ fCentersOfCellsEtaDir.Set(fNZ *fNETAdiv);
+ fCentersOfCellsXDir.Set(fNZ *fNETAdiv);
+ fEtaCentersOfCells.Set(fNZ *fNETAdiv * fNPhi*fNPHIdiv);
+ AliDebug(2,Form(" Cells grid in eta directions : size %i\n", fCentersOfCellsEtaDir.GetSize()));
+ for(Int_t it=0; it<fNZ; it++) {
+ AliEMCALShishKebabTrd1Module *trd1 = GetShishKebabModule(it);
+ nModule = fNPhi*it;
+ for(Int_t ic=0; ic<fNETAdiv; ic++) {
+ if(fNPHIdiv==2) {
+ trd1->GetCenterOfCellInLocalCoordinateofSM(ic, xr, zr); // case of 2X2
+ GetCellPhiEtaIndexInSModule(0, nModule, 0, ic, iphiTemp, ieta);
+ } if(fNPHIdiv==3) {
+ trd1->GetCenterOfCellInLocalCoordinateofSM_3X3(ic, xr, zr); // case of 3X3
+ GetCellPhiEtaIndexInSModule(0, nModule, 0, ic, iphiTemp, ieta);
+ } if(fNPHIdiv==1) {
+ trd1->GetCenterOfCellInLocalCoordinateofSM_1X1(xr, zr); // case of 1X1
+ GetCellPhiEtaIndexInSModule(0, nModule, 0, ic, iphiTemp, ieta);
+ }
+ fCentersOfCellsXDir.AddAt(float(xr) - fParSM[0],ieta);
+ fCentersOfCellsEtaDir.AddAt(float(zr) - fParSM[2],ieta);
+ // Define grid on eta direction for each bin in phi
+ for(int iphi=0; iphi<fCentersOfCellsPhiDir.GetSize(); iphi++) {
+ x = xr + trd1->GetRadius();
+ y = fCentersOfCellsPhiDir[iphi];
+ r = TMath::Sqrt(x*x + y*y + zr*zr);
+ theta = TMath::ACos(zr/r);
+ eta = AliEMCALShishKebabTrd1Module::ThetaToEta(theta);
+ // ind = ieta*fCentersOfCellsPhiDir.GetSize() + iphi;
+ ind = iphi*fCentersOfCellsEtaDir.GetSize() + ieta;
+ fEtaCentersOfCells.AddAt(eta, ind);
+ }
+ //printf(" ieta %i : xr + trd1->GetRadius() %f : zr %f : eta %f \n", ieta, xr + trd1->GetRadius(), zr, eta);
+ }
+ }
+ for(Int_t i=0; i<fCentersOfCellsEtaDir.GetSize(); i++) {
+ AliDebug(2,Form(" ind %2.2i : z %8.3f : x %8.3f", i+1,
+ fCentersOfCellsEtaDir.At(i),fCentersOfCellsXDir.At(i)));
+ }
+
+}
+
+void AliEMCALGeometry::GetTransformationForSM()
+{
+ //Uses the geometry manager to
+ //load the transformation matrix
+ //for the supermodules
+ // Unused after 19 Jan, 2007 - keep for compatibility;
+
+ return;
+ static Bool_t transInit=kFALSE;
+ if(transInit) return;
+
+ int i=0;
+ if(gGeoManager == 0) {
+ Info("CreateTransformationForSM() "," Load geometry : TGeoManager::Import()");
+ assert(0);
+ }
+ TGeoNode *tn = gGeoManager->GetTopNode();
+ TGeoNode *node=0, *xen1 = 0;
+ for(i=0; i<tn->GetNdaughters(); i++) {
+ node = tn->GetDaughter(i);
+ TString ns(node->GetName());
+ if(ns.Contains(GetNameOfEMCALEnvelope())) {
+ xen1 = node;
+ break;
+ }
+ }
+ if(!xen1) {
+ Info("CreateTransformationForSM() "," geometry has not EMCAL envelope with name %s",
+ GetNameOfEMCALEnvelope());
+ assert(0);
+ }
+ printf(" i %i : EMCAL Envelope is %s : #SM %i \n", i, xen1->GetName(), xen1->GetNdaughters());
+ for(i=0; i<xen1->GetNdaughters(); i++) {
+ TGeoNodeMatrix *sm = (TGeoNodeMatrix*)xen1->GetDaughter(i);
+ fMatrixOfSM[i] = sm->GetMatrix();
+ //Compiler doesn't like this syntax...
+ // printf(" %i : matrix %x \n", i, fMatrixOfSM[i]);
+ }
+ transInit = kTRUE;
+}
+
+void AliEMCALGeometry::GetGlobal(const Double_t *loc, Double_t *glob, int ind) const
+{
+ // Figure out the global numbering
+ // of a given supermodule from the
+ // local numbering
+ // Alice numbering - Jun 03,2006
+ // if(fMatrixOfSM[0] == 0) GetTransformationForSM();
+
+ if(ind>=0 && ind < GetNumberOfSuperModules()) {
+ fMatrixOfSM[ind]->LocalToMaster(loc, glob);
+ }
+}
+
+void AliEMCALGeometry::GetGlobal(const TVector3 &vloc, TVector3 &vglob, int ind) const
+{
+ //Figure out the global numbering
+ //of a given supermodule from the
+ //local numbering given a 3-vector location
+
+ static Double_t tglob[3], tloc[3];
+ vloc.GetXYZ(tloc);
+ GetGlobal(tloc, tglob, ind);
+ vglob.SetXYZ(tglob[0], tglob[1], tglob[2]);
+}
+
+void AliEMCALGeometry::GetGlobal(Int_t absId , double glob[3]) const
+{
+ // Alice numbering scheme - Jun 03, 2006
+ static Int_t nSupMod, nModule, nIphi, nIeta;
+ static double loc[3];
+
+ glob[0]=glob[1]=glob[2]=0.0; // bad case
+ if(RelPosCellInSModule(absId, loc)) {
+ GetCellIndex(absId, nSupMod, nModule, nIphi, nIeta);
+ fMatrixOfSM[nSupMod]->LocalToMaster(loc, glob);
+ }
+}
+
+void AliEMCALGeometry::GetGlobal(Int_t absId , TVector3 &vglob) const
+{
+ // Alice numbering scheme - Jun 03, 2006
+ static Double_t glob[3];
+
+ GetGlobal(absId, glob);
+ vglob.SetXYZ(glob[0], glob[1], glob[2]);
+
+}
+
+void AliEMCALGeometry::GetGlobal(const AliRecPoint *rp, TVector3 &vglob) const
+{
+ // Figure out the global numbering
+ // of a given supermodule from the
+ // local numbering for RecPoints
+
+ static TVector3 vloc;
+ static Int_t nSupMod, nModule, nIphi, nIeta;
+
+ AliRecPoint *rpTmp = (AliRecPoint*)rp; // const_cast ??
+ if(!rpTmp) return;
+ AliEMCALRecPoint *rpEmc = (AliEMCALRecPoint*)rpTmp;
+
+ GetCellIndex(rpEmc->GetAbsId(0), nSupMod, nModule, nIphi, nIeta);
+ rpTmp->GetLocalPosition(vloc);
+ GetGlobal(vloc, vglob, nSupMod);
+}
+
+void AliEMCALGeometry::EtaPhiFromIndex(Int_t absId,Double_t &eta,Double_t &phi) const
+{
+ // Nov 16, 2006- float to double
+ // version for TRD1 only
+ static TVector3 vglob;
+ GetGlobal(absId, vglob);
+ eta = vglob.Eta();
+ phi = vglob.Phi();
+}
+
+void AliEMCALGeometry::EtaPhiFromIndex(Int_t absId,Float_t &eta,Float_t &phi) const
+{
+ // Nov 16,2006 - should be discard in future
+ static TVector3 vglob;
+ GetGlobal(absId, vglob);
+ eta = float(vglob.Eta());
+ phi = float(vglob.Phi());
+}
+
+Bool_t AliEMCALGeometry::GetPhiBoundariesOfSM(Int_t nSupMod, Double_t &phiMin, Double_t &phiMax) const
+{
+ // 0<= nSupMod <=11; phi in rad
+ static int i;
+ if(nSupMod<0 || nSupMod >11) return kFALSE;
+ i = nSupMod/2;
+ phiMin = fPhiBoundariesOfSM[2*i];
+ phiMax = fPhiBoundariesOfSM[2*i+1];
+ return kTRUE;
+}
+
+Bool_t AliEMCALGeometry::GetPhiBoundariesOfSMGap(Int_t nPhiSec, Double_t &phiMin, Double_t &phiMax) const
+{
+ // 0<= nPhiSec <=4; phi in rad
+ // 0; gap boundaries between 0th&2th | 1th&3th SM
+ // 1; gap boundaries between 2th&4th | 3th&5th SM
+ // 2; gap boundaries between 4th&6th | 5th&7th SM
+ // 3; gap boundaries between 6th&8th | 7th&9th SM
+ // 4; gap boundaries between 8th&10th | 9th&11th SM
+ if(nPhiSec<0 || nPhiSec >4) return kFALSE;
+ phiMin = fPhiBoundariesOfSM[2*nPhiSec+1];
+ phiMax = fPhiBoundariesOfSM[2*nPhiSec+2];
+ return kTRUE;
+}
+
+Bool_t AliEMCALGeometry::SuperModuleNumberFromEtaPhi(Double_t eta, Double_t phi, Int_t &nSupMod) const
+{
+ // Return false if phi belongs a phi cracks between SM
+
+ static Int_t i;
+
+ if(TMath::Abs(eta) > fEtaMaxOfTRD1) return kFALSE;
+
+ phi = TVector2::Phi_0_2pi(phi); // move phi to (0,2pi) boundaries
+ for(i=0; i<6; i++) {
+ if(phi>=fPhiBoundariesOfSM[2*i] && phi<=fPhiBoundariesOfSM[2*i+1]) {
+ nSupMod = 2*i;
+ if(eta < 0.0) nSupMod++;
+ AliDebug(1,Form("eta %f phi %f(%5.2f) : nSupMod %i : #bound %i", eta,phi,phi*TMath::RadToDeg(), nSupMod,i));
+ return kTRUE;
+ }
+ }
+ return kFALSE;
+}
+
+Bool_t AliEMCALGeometry::GetAbsCellIdFromEtaPhi(Double_t eta, Double_t phi, Int_t &absId) const
+{
+ // Nov 17,2006
+ // stay here - phi problem as usual
+ static Int_t nSupMod, i, ieta, iphi, etaShift, nphi;
+ static Double_t absEta=0.0, d=0.0, dmin=0.0, phiLoc;
+ absId = nSupMod = - 1;
+ if(SuperModuleNumberFromEtaPhi(eta, phi, nSupMod)) {
+ // phi index first
+ phi = TVector2::Phi_0_2pi(phi);
+ phiLoc = phi - fPhiCentersOfSM[nSupMod/2];
+ nphi = fPhiCentersOfCells.GetSize();
+ if(nSupMod>=10) {
+ phiLoc = phi - 190.*TMath::DegToRad();
+ nphi /= 2;
+ }
+
+ dmin = TMath::Abs(fPhiCentersOfCells[0]-phiLoc);
+ iphi = 0;
+ for(i=1; i<nphi; i++) {
+ d = TMath::Abs(fPhiCentersOfCells[i] - phiLoc);
+ if(d < dmin) {
+ dmin = d;
+ iphi = i;
+ }
+ // printf(" i %i : d %f : dmin %f : fPhiCentersOfCells[i] %f \n", i, d, dmin, fPhiCentersOfCells[i]);
+ }
+ // odd SM are turned with respect of even SM - reverse indexes
+ AliDebug(2,Form(" iphi %i : dmin %f (phi %f, phiLoc %f ) ", iphi, dmin, phi, phiLoc));
+ // eta index
+ absEta = TMath::Abs(eta);
+ etaShift = iphi*fCentersOfCellsEtaDir.GetSize();
+ dmin = TMath::Abs(fEtaCentersOfCells[etaShift]-absEta);
+ ieta = 0;
+ for(i=1; i<fCentersOfCellsEtaDir.GetSize(); i++) {
+ d = TMath::Abs(fEtaCentersOfCells[i+etaShift] - absEta);
+ if(d < dmin) {
+ dmin = d;
+ ieta = i;
+ }
+ }
+ AliDebug(2,Form(" ieta %i : dmin %f (eta=%f) : nSupMod %i ", ieta, dmin, eta, nSupMod));
+
+ if(eta<0) iphi = (nphi-1) - iphi;
+ absId = GetAbsCellIdFromCellIndexes(nSupMod, iphi, ieta);
+
+ return kTRUE;
+ }
+ return kFALSE;
+}
+
+AliEMCALShishKebabTrd1Module* AliEMCALGeometry::GetShishKebabModule(Int_t neta)
+{
+ //This method was too long to be
+ //included in the header file - the
+ //rule checker complained about it's
+ //length, so we move it here. It returns the
+ //shishkebabmodule at a given eta index point.
+
+ static AliEMCALShishKebabTrd1Module* trd1=0;
+ if(fShishKebabTrd1Modules && neta>=0 && neta<fShishKebabTrd1Modules->GetSize()) {
+ trd1 = (AliEMCALShishKebabTrd1Module*)fShishKebabTrd1Modules->At(neta);
+ } else trd1 = 0;
+ return trd1;
+}
+
+void AliEMCALGeometry::Browse(TBrowser* b)
+{
+ if(fShishKebabTrd1Modules) b->Add(fShishKebabTrd1Modules);
+ for(int i=0; i<fNumberOfSuperModules; i++) {
+ if(fMatrixOfSM[i]) b->Add(fMatrixOfSM[i]);
+ }
+}
+
+Bool_t AliEMCALGeometry::IsFolder() const
+{
+ if(fShishKebabTrd1Modules) return kTRUE;
+ else return kFALSE;