+//_____________________________________________________________________________
+Int_t
+AliMUONSimpleClusterServer::FindMCLabel(const AliMUONCluster& cluster, Int_t detElemId, const AliMpVSegmentation* seg[2]) const
+{
+ /// Find the label of the most contributing MC track (-1 in case of failure)
+ /// The data member fDigitStore must be set
+
+ // --- get the digit (if any) located at the cluster position on both cathods ---
+ Int_t nTracks[2] = {0, 0};
+ AliMUONVDigit* digit[2] = {0x0, 0x0};
+ for (Int_t iCath = 0; iCath < 2; iCath++) {
+ AliMpPad pad
+ = seg[AliMp::GetCathodType(iCath)]->PadByPosition(cluster.Position().X(), cluster.Position().Y(),kFALSE);
+ if (pad.IsValid()) {
+ digit[iCath] = fDigitStore->FindObject(detElemId, pad.GetManuId(), pad.GetManuChannel(), iCath);
+ if (digit[iCath]) nTracks[iCath] = digit[iCath]->Ntracks();
+ }
+ }
+
+ if (nTracks[0] + nTracks[1] == 0) return -1;
+
+ // --- build the list of contributing tracks and of the associated charge ---
+ Int_t* trackId = new Int_t[nTracks[0] + nTracks[1]];
+ Float_t* trackCharge = new Float_t[nTracks[0] + nTracks[1]];
+ Int_t nTracksTot = 0;
+
+ // fill with contributing tracks on first cathod
+ for (Int_t iTrack1 = 0; iTrack1 < nTracks[0]; iTrack1++) {
+ trackId[iTrack1] = digit[0]->Track(iTrack1);
+ trackCharge[iTrack1] = digit[0]->TrackCharge(iTrack1);
+ }
+ nTracksTot = nTracks[0];
+
+ // complement with contributing tracks on second cathod
+ for (Int_t iTrack2 = 0; iTrack2 < nTracks[1]; iTrack2++) {
+ Int_t trackId2 = digit[1]->Track(iTrack2);
+ // check if track exist
+ Bool_t trackExist = kFALSE;
+ for (Int_t iTrack1 = 0; iTrack1 < nTracks[0]; iTrack1++) {
+ if (trackId2 == trackId[iTrack1]) {
+ // complement existing track
+ trackCharge[iTrack1] += digit[1]->TrackCharge(iTrack2);
+ trackExist = kTRUE;
+ break;
+ }
+ }
+ // add the new track
+ if (!trackExist) {
+ trackId[nTracksTot] = trackId2;
+ trackCharge[nTracksTot] = digit[1]->TrackCharge(iTrack2);
+ nTracksTot++;
+ }
+ }
+
+ // --- Find the most contributing track ---
+ Int_t mainTrackId = -1;
+ Float_t maxCharge = 0.;
+ for (Int_t iTrack = 0; iTrack < nTracksTot; iTrack++) {
+ if (trackCharge[iTrack] > maxCharge) {
+ mainTrackId = trackId[iTrack];
+ maxCharge = trackCharge[iTrack];
+ }
+ }
+
+ delete[] trackId;
+ delete[] trackCharge;
+
+ return mainTrackId;
+}
+