+ TLorentzVector v;
+ UShort_t detector;
+ Char_t ring;
+ UShort_t sector;
+ UShort_t strip;
+
+ if (fmd->IsDetailed()) {
+ if (!VMC2FMD(copy, v, detector, ring, sector, strip)) return;
+ } else {
+ if (!VMC2FMD(v, detector, ring, sector, strip)) return;
+ }
+ TLorentzVector p;
+ mc->TrackMomentum(p);
+ Int_t trackno = gAlice->GetMCApp()->GetCurrentTrackNumber();
+ Int_t pdg = mc->TrackPid();
+ Double_t edep = mc->Edep() * 1000; // keV
+ Bool_t isBad = CheckHit(trackno, pdg, absQ, p, edep);
+
+ // Check that the track is actually within the active area
+ Bool_t entering = mc->IsTrackEntering();
+ Bool_t inside = mc->IsTrackInside();
+ Bool_t out = (mc->IsTrackExiting()|| mc->IsTrackDisappeared()||
+ mc->IsTrackStop());
+ // Reset the energy deposition for this track, and update some of
+ // our parameters.
+ if (entering) {
+ AliFMDDebug(15, ("Track # %8d entering active FMD volume %s: "
+ "Edep=%f (%f,%f,%f)", trackno, mc->CurrentVolPath(),
+ edep, v.X(), v.Y(), v.Z()));
+ fCurrentP = p;
+ fCurrentV = v;
+ fCurrentDeltaE = edep;
+ fCurrentPdg = pdg; // mc->IdFromPDG(pdg);
+ }
+ // If the track is inside, then update the energy deposition
+ if (inside && fCurrentDeltaE >= 0) {
+ fCurrentDeltaE += edep;
+ AliFMDDebug(15, ("Track # %8d inside active FMD volume %s: Edep=%f, "
+ "Accumulated Edep=%f (%f,%f,%f)", trackno,
+ mc->CurrentVolPath(), edep, fCurrentDeltaE,
+ v.X(), v.Y(), v.Z()));
+ }
+ // The track exits the volume, or it disappeared in the volume, or
+ // the track is stopped because it no longer fulfills the cuts
+ // defined, then we create a hit.
+ if (out) {
+ if (fCurrentDeltaE >= 0) {
+ fCurrentDeltaE += edep;
+ AliFMDDebug(15, ("Track # %8d exiting active FMD volume %s: Edep=%g, "
+ "Accumulated Edep=%g (%f,%f,%f)", trackno,
+ mc->CurrentVolPath(), edep, fCurrentDeltaE,
+ v.X(), v.Y(), v.Z()));
+ TVector3 cur(v.Vect());
+ cur -= fCurrentV.Vect();
+ Double_t len = cur.Mag();
+ AliFMDHit* h =
+ AddHitByFields(trackno, detector, ring, sector, strip,
+ fCurrentV.X(), fCurrentV.Y(), fCurrentV.Z(),
+ fCurrentP.X(), fCurrentP.Y(), fCurrentP.Z(),
+ fCurrentDeltaE, fCurrentPdg, fCurrentV.T(),
+ len, mc->IsTrackDisappeared()||mc->IsTrackStop());
+ // Add a copy
+ if (isBad && fBad) {
+ new ((*fBad)[fBad->GetEntries()]) AliFMDHit(*h);
+ }
+ // Check the geometry that we can get back the coordinates.
+#ifdef CHECK_TRANS
+ Double_t x, y, z;
+ fmd->Detector2XYZ(detector, ring, sector, strip, x, y ,z);
+ AliFMDDebug(1, ("Hit at (%f,%f,%f), geometry says (%f,%f,%f)",
+ fCurrentV.X(), fCurrentV.Y(), fCurrentV.Z(), x, y, z));
+#endif
+ }
+ fCurrentDeltaE = -1;
+ }
+}
+//___________________________________________________________________
+//
+// EOF
+//