+ // PDG code electron
+ const Int_t kPdgElectron = 11;
+
+ Int_t layer = 0;
+ Int_t stack = 0;
+ Int_t sector = 0;
+ Int_t det = 0;
+ Int_t qTot;
+
+ Float_t hits[3];
+ Double_t eDep;
+
+ Bool_t drRegion = kFALSE;
+ Bool_t amRegion = kFALSE;
+
+ TString cIdPath;
+ Char_t cIdSector[3];
+ cIdSector[2] = 0;
+
+ TString cIdCurrent;
+ TString cIdSensDr = "J";
+ TString cIdSensAm = "K";
+ Char_t cIdChamber[3];
+ cIdChamber[2] = 0;
+
+ TLorentzVector pos;
+ TLorentzVector mom;
+
+ const Int_t kNlayer = AliTRDgeometry::Nlayer();
+ const Int_t kNstack = AliTRDgeometry::Nstack();
+ const Int_t kNdetsec = kNlayer * kNstack;
+
+ const Double_t kBig = 1.0e+12;
+ const Float_t kEkinMinStep = 1.0e-5; // Minimum energy for the step size adjustment
+
+ // Set the maximum step size to a very large number for all
+ // neutral particles and those outside the driftvolume
+ if (!fPrimaryIonisation) gMC->SetMaxStep(kBig);
+
+ // If not charged track or already stopped or disappeared, just return.
+ if ((!gMC->TrackCharge()) ||
+ gMC->IsTrackDisappeared()) {
+ return;
+ }
+
+ // Inside a sensitive volume?
+ cIdCurrent = gMC->CurrentVolName();
+
+ if (cIdSensDr == cIdCurrent[1]) {
+ drRegion = kTRUE;
+ }
+ if (cIdSensAm == cIdCurrent[1]) {
+ amRegion = kTRUE;
+ }
+
+ if ((!drRegion) &&
+ (!amRegion)) {
+ return;
+ }
+
+ // The hit coordinates and charge
+ gMC->TrackPosition(pos);
+ hits[0] = pos[0];
+ hits[1] = pos[1];
+ hits[2] = pos[2];
+
+ // The sector number (0 - 17), according to standard coordinate system
+ cIdPath = gGeoManager->GetPath();
+ cIdSector[0] = cIdPath[21];
+ cIdSector[1] = cIdPath[22];
+ sector = atoi(cIdSector);
+
+ // The plane and chamber number
+ cIdChamber[0] = cIdCurrent[2];
+ cIdChamber[1] = cIdCurrent[3];
+ Int_t idChamber = (atoi(cIdChamber) % kNdetsec);
+ stack = ((Int_t) idChamber / kNlayer);
+ layer = ((Int_t) idChamber % kNlayer);
+
+ // The detector number
+ det = fGeometry->GetDetector(layer,stack,sector);
+
+ // 0: InFlight 1:Entering 2:Exiting
+ Int_t trkStat = 0;
+
+ // Special hits only in the drift region
+ if ((drRegion) &&
+ (gMC->IsTrackEntering())) {
+
+ // Create a track reference at the entrance of each
+ // chamber that contains the momentum components of the particle
+ gMC->TrackMomentum(mom);
+ AddTrackReference(gAlice->GetMCApp()->GetCurrentTrackNumber(), AliTrackReference::kTRD);
+ trkStat = 1;
+
+ // Create the hits from TR photons if electron/positron is
+ // entering the drift volume
+ if ((fTR) &&
+ (fTRon) &&
+ (TMath::Abs(gMC->TrackPid()) == kPdgElectron)) {
+ CreateTRhit(det);