+//-------------------------------------------------------------------------
+
+UShort_t AliTOFGeometry::GetAliSensVolIndex(Int_t isector, Int_t iplate, Int_t istrip)
+{
+ //
+ // Get the index of the TOF alignable volume in the AliGeomManager order.
+ //
+
+ Int_t index = GetStripNumber(isector, iplate, istrip);
+
+ UShort_t volIndex = AliGeomManager::LayerToVolUID(AliGeomManager::kTOF,index);
+
+ return volIndex;
+
+}
+//-------------------------------------------------------------------------
+
+Int_t AliTOFGeometry::GetStripNumber(Int_t isector, Int_t iplate, Int_t istrip)
+{
+ //
+ // Get the serial number of the TOF strip number istrip [0,14/18],
+ // in the module number iplate [0,4],
+ // in the TOF SM number isector [0,17].
+ // This number will range in [0,1637].
+ //
+
+ Bool_t check = (isector >= kNSectors);
+
+ if (check)
+ printf("E-AliTOFGeometry::GetStripNumber: Wrong sector number in TOF (%d)!\n",isector);
+
+ Int_t index = -1;
+ Int_t stripInSM = GetStripNumberPerSM(iplate, istrip);
+ if (!check && stripInSM!=-1)
+ index = (2*(kNStripC+kNStripB)+kNStripA)*isector + stripInSM;
+
+ return index;
+
+}
+//-------------------------------------------------------------------------
+
+void AliTOFGeometry::GetStripAndModule(Int_t iStripPerSM, Int_t &iplate, Int_t &istrip)
+{
+ //
+ // Convert the serial number of the TOF strip number iStripPerSM [0,90]
+ // in module number iplate [0,4] and strip number istrip [0,14/18].
+ //
+
+ if (iStripPerSM<0 || iStripPerSM>=kNStripC+kNStripB+kNStripA+kNStripB+kNStripC) {
+ iplate = -1;
+ istrip = -1;
+ }
+ else if (iStripPerSM<kNStripC) {
+ iplate = 0;
+ istrip = iStripPerSM;
+ }
+ else if (iStripPerSM>=kNStripC && iStripPerSM<kNStripC+kNStripB) {
+ iplate = 1;
+ istrip = iStripPerSM-kNStripC;
+ }
+ else if (iStripPerSM>=kNStripC+kNStripB && iStripPerSM<kNStripC+kNStripB+kNStripA) {
+ iplate = 2;
+ istrip = iStripPerSM-kNStripC-kNStripB;
+ }
+ else if (iStripPerSM>=kNStripC+kNStripB+kNStripA && iStripPerSM<kNStripC+kNStripB+kNStripA+kNStripB) {
+ iplate = 3;
+ istrip = iStripPerSM-kNStripC-kNStripB-kNStripA;
+ }
+ else if (iStripPerSM>=kNStripC+kNStripB+kNStripA+kNStripB && iStripPerSM<kNStripC+kNStripB+kNStripA+kNStripB+kNStripC) {
+ iplate = 4;
+ istrip = iStripPerSM-kNStripC-kNStripB-kNStripA-kNStripB;
+ }
+
+
+}
+//-------------------------------------------------------------------------
+
+Int_t AliTOFGeometry::GetStripNumberPerSM(Int_t iplate, Int_t istrip)
+{
+ //
+ // Get the serial number of the TOF strip number istrip [0,14/18],
+ // in the module number iplate [0,4].
+ // This number will range in [0,90].
+ //
+
+ Int_t index = -1;
+
+ Bool_t check = (
+ (iplate<0 || iplate>=kNPlates)
+ ||
+ (
+ (iplate==2 && (istrip<0 || istrip>=kNStripA))
+ ||
+ (iplate!=2 && (istrip<0 || istrip>=kNStripC))
+ )
+ );
+
+ if (iplate<0 || iplate>=kNPlates)
+ printf("E-AliTOFGeometry::GetStripNumberPerSM: Wrong plate number in TOF (%1d)!\n",iplate);
+
+ if (
+ (iplate==2 && (istrip<0 || istrip>=kNStripA))
+ ||
+ (iplate!=2 && (istrip<0 || istrip>=kNStripC))
+ )
+ printf("E-AliTOFGeometry::GetStripNumberPerSM: Wrong strip number in TOF "
+ "(strip=%2d in the plate=%1d)!\n",istrip,iplate);
+
+ Int_t stripOffset = 0;
+ switch (iplate) {
+ case 0:
+ stripOffset = 0;
+ break;
+ case 1:
+ stripOffset = kNStripC;
+ break;
+ case 2:
+ stripOffset = kNStripC+kNStripB;
+ break;
+ case 3:
+ stripOffset = kNStripC+kNStripB+kNStripA;
+ break;
+ case 4:
+ stripOffset = kNStripC+kNStripB+kNStripA+kNStripB;
+ break;
+ };
+
+ if (!check) index = stripOffset + istrip;
+
+ return index;
+
+}
+//-------------------------------------------------------------------------
+
+void AliTOFGeometry::PadRF2TrackingRF(Float_t *ctrackPos, Float_t *differenceT)
+{
+ //
+ // To convert the 3D distance ctrackPos, referred to the ALICE RF,
+ // into the 3D distance differenceT, referred to the tracking RF
+ // in case ctrakPos belongs to a TOF sensitive volume.
+ //
+
+ for (Int_t ii=0; ii<3; ii++) differenceT[ii] = 999.;
+
+ AliDebug(1,Form(" track position in ALICE global Ref. frame -> %f, %f, %f",
+ ctrackPos[0],ctrackPos[1],ctrackPos[2]));
+
+ Int_t detId[5] = {-1,-1,-1,-1,-1};
+
+ detId[0] = GetSector(ctrackPos);
+ if (detId[0]==-1) {
+ AliWarning(Form("This point does not belong to any TOF sector"));
+ return;
+ }
+
+ detId[1] = GetPlate(ctrackPos);
+ if (detId[1]==-1) {
+ AliWarning(Form("This point does not belong to any TOF module"));
+ return;
+ }
+
+ detId[2] = GetStrip(ctrackPos);
+ if (detId[2]==-1) {
+ AliWarning(Form("This point does not belong to any TOF strip"));
+ return;
+ }
+
+ detId[3] = GetPadZ(ctrackPos);
+ if (detId[3]==-1) {
+ AliWarning(Form("This point does not belong to any TOF pad-row"));
+ return;
+ }
+
+ detId[4] = GetPadX(ctrackPos);
+ if (detId[4]==-1) {
+ AliWarning(Form("This point does not belong to any TOF pad"));
+ return;
+ }
+
+
+ UShort_t alignableStripIndex =
+ GetAliSensVolIndex(detId[0],detId[1],detId[2]);
+ AliDebug(1,Form(" sector = %2d, plate = %1d, strip = %2d (padZ = %1d, padX = %2d) "
+ "---> stripIndex = %4d",
+ detId[0], detId[1], detId[2], detId[3], detId[4], alignableStripIndex));
+
+ // pad centre coordinates in the strip ref. frame
+ Double_t padCentreL[3] = {(detId[4]-AliTOFGeometry::NpadX()/2)*AliTOFGeometry::XPad()
+ +AliTOFGeometry::XPad()/2.,
+ 0.,
+ (detId[3]-AliTOFGeometry::NpadZ()/2)*AliTOFGeometry::XPad()
+ +AliTOFGeometry::XPad()/2.};
+ // pad centre coordinates in the strip tracking frame
+ Double_t padCentreT[3] = {0., 0., 0.};
+ TGeoHMatrix l2t = *AliGeomManager::GetTracking2LocalMatrix(alignableStripIndex);
+ l2t.MasterToLocal(padCentreL,padCentreT);
+
+
+ Char_t path[200];
+ // pad centre coordinates in its ref. frame
+ Double_t padCentreL2[3] = {0., 0., 0.};
+ // pad centre coordinates in the ALICE global ref. frame
+ Double_t padCentreG[3] = {0., 0., 0.};
+ GetVolumePath(detId,path);
+ gGeoManager->cd(path);
+ TGeoHMatrix g2l = *gGeoManager->GetCurrentMatrix();
+ TGeoHMatrix l2g = g2l.Inverse();
+ l2g.MasterToLocal(padCentreL2,padCentreG);
+
+
+ Char_t path2[200];
+ // strip centre coordinates in its ref. frame
+ Double_t stripCentreL[3] = {0., 0., 0.};
+ // strip centre coordinates in the ALICE global ref. frame
+ Double_t stripCentreG[3] = {0., 0., 0.};
+ GetVolumePath(detId[0],detId[1],detId[2],path2);
+ gGeoManager->cd(path2);
+ TGeoHMatrix g2lb = *gGeoManager->GetCurrentMatrix();
+ TGeoHMatrix l2gb = g2lb.Inverse();
+ l2gb.MasterToLocal(stripCentreL,stripCentreG);
+
+ TGeoHMatrix g2t = 0;
+ AliGeomManager::GetTrackingMatrix(alignableStripIndex, g2t);
+
+ // track position in the ALICE global ref. frame
+ Double_t posG[3];
+ for (Int_t ii=0; ii<3; ii++) posG[ii] = (Double_t)ctrackPos[ii];
+
+ // strip centre coordinates in the tracking ref. frame
+ Double_t stripCentreT[3] = {0., 0., 0.};
+ // track position in the tracking ref. frame
+ Double_t posT[3] = {0., 0., 0.};
+ g2t.MasterToLocal(posG,posT);
+ g2t.MasterToLocal(stripCentreG,stripCentreT);
+
+ for (Int_t ii=0; ii<3; ii++)
+ AliDebug(1,Form(" track position in ALICE global and tracking RFs -> posG[%d] = %f --- posT[%d] = %f",
+ ii, posG[ii], ii, posT[ii]));
+ for (Int_t ii=0; ii<3; ii++)
+ AliDebug(1,Form(" pad centre coordinates in its, the ALICE global and tracking RFs -> "
+ "padCentreL[%d] = %f --- padCentreG[%d] = %f --- padCentreT[%d] = %f",
+ ii, padCentreL[ii],
+ ii, padCentreG[ii],
+ ii, padCentreT[ii]));
+ for (Int_t ii=0; ii<3; ii++)
+ AliDebug(1,Form(" strip centre coordinates in its, the ALICE global and tracking RFs -> "
+ "stripCentreL[%d] = %f --- stripCentreG[%d] = %f --- stripCentreT[%d] = %f",
+ ii, stripCentreL[ii],
+ ii, stripCentreG[ii],
+ ii, stripCentreT[ii]));
+ for (Int_t ii=0; ii<3; ii++)
+ AliDebug(1,Form(" difference between the track position and the pad centre in the tracking RF "
+ "-> posT[%d]-padCentreT[%d] = %f",
+ ii,ii,
+ posT[ii]-padCentreT[ii]));
+
+ for (Int_t ii=0; ii<3; ii++) differenceT[ii] = (Float_t)(posT[ii]-padCentreT[ii]);
+
+}
+//-------------------------------------------------------------------------
+
+Int_t AliTOFGeometry::GetTOFsupermodule(Int_t index)
+{
+ // Return the TOF supermodule where TOF channel index is located
+
+ if (index<0 || index>=NPadXSector()*NSectors()) return -1;
+ else return index/NpadXStrip()/NStripXSector();
+
+}