+// #include "AliFMDGeometryBuilder.h"
+#include "AliFMDGeometry.h"
+#include "AliFMDDetector.h"
+#include "AliFMDRing.h"
+#include <TParticlePDG.h>
+#include <TDatabasePDG.h>
+#include "AliFMDHit.h"
+
+//____________________________________________________________________
+ClassImp(AliFMDv1)
+#if 0
+ ; // This is here to keep Emacs for indenting the next line
+#endif
+
+
+//____________________________________________________________________
+Bool_t
+AliFMDv1::VMC2FMD(TLorentzVector& v, UShort_t& detector,
+ Char_t& ring, UShort_t& sector, UShort_t& strip) const
+{
+ // Convert VMC coordinates to detector coordinates
+ TVirtualMC* mc = TVirtualMC::GetMC();
+ AliFMDGeometry* fmd = AliFMDGeometry::Instance();
+
+ // Get track position
+ mc->TrackPosition(v);
+ Int_t moduleno; mc->CurrentVolOffID(fmd->GetModuleOff(), moduleno);
+ Int_t iring; mc->CurrentVolOffID(fmd->GetRingOff(), iring);
+ ring = Char_t(iring);
+ Int_t det; mc->CurrentVolOffID(fmd->GetDetectorOff(), det);
+ detector = det;
+
+
+ // Get the ring geometry
+ //Int_t nsec = fmd->GetDetector(detector)->GetRing(ring)->GetNSectors();
+ Int_t nstr = fmd->GetDetector(detector)->GetRing(ring)->GetNStrips();
+ Double_t lowr = fmd->GetDetector(detector)->GetRing(ring)->GetMinR();
+ Double_t theta = fmd->GetDetector(detector)->GetRing(ring)->GetTheta();
+ Double_t pitch = fmd->GetDetector(detector)->GetRing(ring)->GetPitch();
+
+ // Figure out the strip number
+ Double_t r = TMath::Sqrt(v.X() * v.X() + v.Y() * v.Y());
+ Int_t str = Int_t((r - lowr) / pitch);
+ if (str < 0 || str >= nstr) return kFALSE;
+ strip = str;
+
+ // Figure out the sector number
+ Double_t phi = TMath::ATan2(v.Y(), v.X()) * 180. / TMath::Pi();
+ if (phi < 0) phi = 360. + phi;
+ Double_t t = phi - 2 * moduleno * theta;
+ sector = 2 * moduleno;
+ if (t < 0 || t > 2 * theta) return kFALSE;
+ else if (t > theta) sector += 1;
+
+ AliDebug(40, Form("<1> Inside an active FMD volume FMD%d%c[%2d,%3d] %s",
+ detector, ring, sector, strip, mc->CurrentVolPath()));
+ return kTRUE;
+}
+
+//____________________________________________________________________
+Bool_t
+AliFMDv1::VMC2FMD(Int_t copy, TLorentzVector& v,
+ UShort_t& detector, Char_t& ring,
+ UShort_t& sector, UShort_t& strip) const
+{
+ // Convert VMC coordinates to detector coordinates
+ TVirtualMC* mc = TVirtualMC::GetMC();
+ AliFMDGeometry* fmd = AliFMDGeometry::Instance();
+
+ strip = copy - 1;
+ Int_t sectordiv; mc->CurrentVolOffID(fmd->GetSectorOff(), sectordiv);
+ if (fmd->GetModuleOff() >= 0) {
+ Int_t module; mc->CurrentVolOffID(fmd->GetModuleOff(), module);
+ sector = 2 * module + sectordiv;
+ }
+ else
+ sector = sectordiv;
+ AliDebug(30, Form("Getting ring volume with offset %d -> %s",
+ fmd->GetRingOff(),
+ mc->CurrentVolOffName(fmd->GetRingOff())));
+ Int_t iring; mc->CurrentVolOffID(fmd->GetRingOff(), iring);
+ ring = Char_t(iring);
+ Int_t det; mc->CurrentVolOffID(fmd->GetDetectorOff(), det);
+ detector = det;
+
+ //Double_t rz = fmd->GetDetector(detector)->GetRingZ(ring);
+ AliFMDDetector* gdet = fmd->GetDetector(detector);
+ AliFMDRing* gring = gdet->GetRing(ring);
+ if (!gring) {
+ AliFatal(Form("Ring %c not found (volume was %s at offset %d in path %s)",
+ ring, fmd->GetRingOff(),
+ mc->CurrentVolOffName(fmd->GetRingOff()),
+ mc->CurrentVolPath()));
+ }
+ Int_t n = gring->GetNSectors();
+#if 0
+ if (rz < 0) {
+ Int_t s = ((n - sector + n / 2) % n) + 1;
+ AliDebug(1, Form("Recalculating sector to %d (=%d-%d+%d/2%%%d+1 z=%f)",
+ s, n, sector, n, n, rz));
+ sector = s;
+ }
+#endif
+ if (sector < 1 || sector > n) {
+ AliWarning(Form("sector # %d out of range (0-%d)", sector-1, n-1));
+ return kFALSE;
+ }
+ sector--;
+ // Get track position
+ mc->TrackPosition(v);
+ AliDebug(15, Form("<2> Inside an active FMD volume FMD%d%c[%2d,%3d] %s",
+ detector, ring, sector, strip, mc->CurrentVolPath()));
+
+ return kTRUE;
+}
+