- return hitForRec;
-}
- //__________________________________________________________________________
-TClonesArray* AliMUONTrackReconstructor::CleanTrackRefs(TTree *treeTR)
-{
- // Make hits from track ref..
- // Re-calculate hits parameters because two AliTrackReferences are recorded for
- // each chamber (one when particle is entering + one when particle is leaving
- // the sensitive volume)
-
- AliTrackReference *trackReference;
- Float_t x1, y1, z1, pX1, pY1, pZ1;
- Float_t x2, y2, z2, pX2, pY2, pZ2;
- Int_t track1, track2;
- Int_t nRec = 0;
- Float_t maxGasGap = 1.; // cm
- Int_t iHit1 = 0;
- Int_t iHitMin = 0;
-
- AliTrackReference *trackReferenceNew = new AliTrackReference();
-
- TClonesArray* trackRefs = new TClonesArray("AliTrackReference", 10);
- TClonesArray* cleanTrackRefs = new TClonesArray("AliTrackReference", 10);
-
- if (treeTR == NULL) return NULL;
- TBranch* branch = treeTR->GetBranch("MUON");
- if (branch == NULL) return NULL;
- branch->SetAddress(&trackRefs);
-
- Int_t nTrack = (Int_t)treeTR->GetEntries();
- for (Int_t iTrack = 0; iTrack < nTrack; iTrack++) {
- treeTR->GetEntry(iTrack);
- iHitMin = 0;
- iHit1 = 0;
- while (iHit1 < trackRefs->GetEntries()) {
- trackReference = (AliTrackReference*)trackRefs->At(iHit1);
- x1 = trackReference->X();
- y1 = trackReference->Y();
- z1 = trackReference->Z();
- pX1 = trackReference->Px();
- pY1 = trackReference->Py();
- pZ1 = trackReference->Pz();
- track1 = trackReference->GetTrack();
- nRec = 1;
- iHitMin = iHit1+1;
- for (Int_t iHit2 = iHit1+1; iHit2 < trackRefs->GetEntries(); iHit2++) {
- trackReference = (AliTrackReference*)trackRefs->At(iHit2);
- x2 = trackReference->X();
- y2 = trackReference->Y();
- z2 = trackReference->Z();
- pX2 = trackReference->Px();
- pY2 = trackReference->Py();
- pZ2 = trackReference->Pz();
- track2 = trackReference->GetTrack();
- if (track2 == track1 && TMath::Abs(z2-z1) < maxGasGap ) {
- nRec++;
- x1 += x2;
- y1 += y2;
- z1 += z2;
- pX1 += pX2;
- pY1 += pY2;
- pZ1 += pZ2;
- iHitMin = iHit2+1;
+
+ Double_t chi2WithOneCluster = AliMUONTrack::MaxChi2();
+ Double_t chi2WithTwoClusters = AliMUONTrack::MaxChi2();
+ Double_t maxChi2WithOneCluster = 2. * GetRecoParam()->GetSigmaCutForTracking() *
+ GetRecoParam()->GetSigmaCutForTracking(); // 2 because 2 quantities in chi2
+ Double_t maxChi2WithTwoClusters = 4. * GetRecoParam()->GetSigmaCutForTracking() *
+ GetRecoParam()->GetSigmaCutForTracking(); // 4 because 4 quantities in chi2
+ Double_t bestChi2WithOneCluster = maxChi2WithOneCluster;
+ Double_t bestChi2WithTwoClusters = maxChi2WithTwoClusters;
+ Bool_t foundOneCluster = kFALSE;
+ Bool_t foundTwoClusters = kFALSE;
+ AliMUONTrack *newTrack = 0x0;
+ AliMUONVCluster *clusterCh1, *clusterCh2;
+ AliMUONTrackParam extrapTrackParam;
+ AliMUONTrackParam extrapTrackParamAtCh;
+ AliMUONTrackParam extrapTrackParamAtCluster1;
+ AliMUONTrackParam extrapTrackParamAtCluster2;
+ AliMUONTrackParam bestTrackParamAtCluster1;
+ AliMUONTrackParam bestTrackParamAtCluster2;
+
+ // Get track parameters according to the propagation direction
+ if (nextStation==4) extrapTrackParamAtCh = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->Last();
+ else extrapTrackParamAtCh = *(AliMUONTrackParam*)trackCandidate.GetTrackParamAtCluster()->First();
+
+ // Printout for debuging
+ if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
+ cout<<endl<<"Track parameters and covariances at first cluster:"<<endl;
+ extrapTrackParamAtCh.GetParameters().Print();
+ extrapTrackParamAtCh.GetCovariances().Print();
+ }
+
+ // Add MCS effect
+ Int_t currentChamber = extrapTrackParamAtCh.GetClusterPtr()->GetChamberId();
+ AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(currentChamber),-1.);
+
+ // Add MCS in the missing chamber(s) if any
+ while (ch1 < ch2 && currentChamber > ch2 + 1) {
+ // extrapolation to the missing chamber
+ currentChamber--;
+ if (!AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(currentChamber))) return kFALSE;
+ // add MCS effect
+ AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCh,AliMUONConstants::ChamberThicknessInX0(currentChamber),-1.);
+ }
+
+ //Extrapolate trackCandidate to chamber "ch2"
+ if (!AliMUONTrackExtrap::ExtrapToZCov(&extrapTrackParamAtCh, AliMUONConstants::DefaultChamberZ(ch2))) return kFALSE;
+
+ // Printout for debuging
+ if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 2) || (AliLog::GetGlobalDebugLevel() >= 2)) {
+ cout<<endl<<"Track parameters and covariances at first cluster extrapolated to z = "<<AliMUONConstants::DefaultChamberZ(ch2)<<":"<<endl;
+ extrapTrackParamAtCh.GetParameters().Print();
+ extrapTrackParamAtCh.GetCovariances().Print();
+ }
+
+ // Printout for debuging
+ if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
+ cout << "FollowTrackInStation: look for clusters in chamber(1..): " << ch2+1 << endl;
+ }
+
+ // Ask the clustering to reconstruct new clusters around the track position in the current station
+ // except for station 4 and 5 that are already entirely clusterized
+ if (GetRecoParam()->CombineClusterTrackReco()) {
+ if (nextStation < 3) AskForNewClustersInStation(extrapTrackParamAtCh, clusterStore, nextStation);
+ }
+
+ Int_t nClusters = clusterStore.GetSize();
+ Bool_t *clusterCh1Used = new Bool_t[nClusters];
+ for (Int_t i = 0; i < nClusters; i++) clusterCh1Used[i] = kFALSE;
+ Int_t iCluster1;
+
+ // Create iterators to loop over clusters in both chambers
+ TIter nextInCh1(clusterStore.CreateChamberIterator(ch1,ch1));
+ TIter nextInCh2(clusterStore.CreateChamberIterator(ch2,ch2));
+
+ // look for candidates in chamber 2
+ while ( ( clusterCh2 = static_cast<AliMUONVCluster*>(nextInCh2()) ) ) {
+
+ // try to add the current cluster fast
+ if (!TryOneClusterFast(extrapTrackParamAtCh, clusterCh2)) continue;
+
+ // try to add the current cluster accuratly
+ chi2WithOneCluster = TryOneCluster(extrapTrackParamAtCh, clusterCh2, extrapTrackParamAtCluster2);
+
+ // if good chi2 then try to attach a cluster in the other chamber too
+ if (chi2WithOneCluster < maxChi2WithOneCluster) {
+ Bool_t foundSecondCluster = kFALSE;
+
+ // Printout for debuging
+ if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
+ cout << "FollowTrackInStation: found one cluster in chamber(1..): " << ch2+1
+ << " (Chi2 = " << chi2WithOneCluster << ")" << endl;
+ clusterCh2->Print();
+ cout << " look for second clusters in chamber(1..): " << ch1+1 << " ..." << endl;
+ }
+
+ // add MCS effect for next step
+ AliMUONTrackExtrap::AddMCSEffect(&extrapTrackParamAtCluster2,AliMUONConstants::ChamberThicknessInX0(ch2),-1.);
+
+ // copy new track parameters for next step
+ extrapTrackParam = extrapTrackParamAtCluster2;
+
+ //Extrapolate track parameters to chamber "ch1"
+ Bool_t normalExtrap = AliMUONTrackExtrap::ExtrapToZ(&extrapTrackParam, AliMUONConstants::DefaultChamberZ(ch1));
+
+ // reset cluster iterator of chamber 1
+ nextInCh1.Reset();
+ iCluster1 = -1;
+
+ // look for second candidates in chamber 1
+ if (normalExtrap) while ( ( clusterCh1 = static_cast<AliMUONVCluster*>(nextInCh1()) ) ) {
+ iCluster1++;
+
+ // try to add the current cluster fast
+ if (!TryOneClusterFast(extrapTrackParam, clusterCh1)) continue;
+
+ // try to add the current cluster accurately
+ chi2WithTwoClusters = TryTwoClusters(extrapTrackParamAtCluster2, clusterCh1, extrapTrackParamAtCluster1);
+
+ // if good chi2 then create a new track by adding the 2 clusters to the "trackCandidate"
+ if (chi2WithTwoClusters < maxChi2WithTwoClusters) {
+ foundSecondCluster = kTRUE;
+ foundTwoClusters = kTRUE;
+
+ // Printout for debuging
+ if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
+ cout << "FollowTrackInStation: found second cluster in chamber(1..): " << ch1+1
+ << " (Global Chi2 = " << chi2WithTwoClusters << ")" << endl;
+ clusterCh1->Print();
+ }
+
+ if (GetRecoParam()->TrackAllTracks()) {
+ // copy trackCandidate into a new track put at the end of fRecTracksPtr and add the new clusters
+ newTrack = new ((*fRecTracksPtr)[fRecTracksPtr->GetLast()+1]) AliMUONTrack(trackCandidate);
+ UpdateTrack(*newTrack,extrapTrackParamAtCluster1,extrapTrackParamAtCluster2);
+ fNRecTracks++;
+
+ // Tag clusterCh1 as used
+ clusterCh1Used[iCluster1] = kTRUE;
+
+ // Printout for debuging
+ if ((AliLog::GetDebugLevel("MUON","AliMUONTrackReconstructor") >= 1) || (AliLog::GetGlobalDebugLevel() >= 1)) {
+ cout << "FollowTrackInStation: added two clusters in station(1..): " << nextStation+1 << endl;
+ if (AliLog::GetGlobalDebugLevel() >= 3) newTrack->RecursiveDump();
+ }
+
+ } else if (chi2WithTwoClusters < bestChi2WithTwoClusters) {
+ // keep track of the best couple of clusters
+ bestChi2WithTwoClusters = chi2WithTwoClusters;
+ bestTrackParamAtCluster1 = extrapTrackParamAtCluster1;
+ bestTrackParamAtCluster2 = extrapTrackParamAtCluster2;
+ }
+