/*
$Log$
+Revision 1.31 2002/10/23 07:24:56 alibrary
+Introducing Riostream.h
+
Revision 1.30 2002/10/14 14:57:29 hristov
Merging the VirtualMC branch to the main development branch (HEAD)
#include "AliMUONTrackHit.h"
#include "AliMagF.h"
#include "AliRun.h" // for gAlice
+#include "AliMUONTrackK.h" //AZ
+#include <TMatrixD.h> //AZ
//************* Defaults parameters for reconstruction
static const Double_t kDefaultMinBendingMomentum = 3.0;
{
// Constructor for class AliMUONEventReconstructor
SetReconstructionParametersToDefaults();
+ fTrackMethod = 1; //AZ - tracking method (1-default, 2-Kalman)
// Memory allocation for the TClonesArray of hits for reconstruction
// Is 10000 the right size ????
fHitsForRecPtr = new TClonesArray("AliMUONHitForRec", 10000);
{
// To add to the list of hits for reconstruction
// the GEANT signal hits from a hit tree TH.
+ Int_t hitBits, chamBits; //AZ
if (fPrintLevel >= 2)
cout << "enter AddHitsForRecFromGEANT with TH: " << TH << endl;
if (TH == NULL) return;
Int_t ntracks = (Int_t) TH->GetEntries();
if (fPrintLevel >= 2)
cout << "ntracks: " << ntracks << endl;
+ fMuons = 0; //AZ
for (Int_t track = 0; track < ntracks; track++) {
gAlice->ResetHits();
TH->GetEvent(track);
// Loop over hits
Int_t hit = 0;
+ hitBits = 0; // AZ
+ chamBits = 0; // AZ
+ Int_t itrack = track; //AZ
for (AliMUONHit* mHit = (AliMUONHit*) pMUON->FirstHit(-1);
mHit;
mHit = (AliMUONHit*) pMUON->NextHit(), hit++) {
- NewHitForRecFromGEANT(mHit,track, hit, 1);
+ Int_t ipart = TMath::Abs ((Int_t) mHit->Particle()); //AZ
+ //itrack = mHit->Track(); //AZ
+ //AZNewHitForRecFromGEANT(mHit,track, hit, 1);
+ if (NewHitForRecFromGEANT(mHit,track, hit, 1) && ipart == 13
+ //if (NewHitForRecFromGEANT(mHit,itrack-1, hit, 1) && ipart == 13
+ && itrack <= 2) chamBits |= BIT(mHit->Chamber()-1); //AZ - set bit
} // end of hit loop
+ if (chamBits&3 && chamBits>>2&3 && chamBits>>4&3 && chamBits>>6&3 &&
+ chamBits>>8&3 && ((chamBits>>6&3)==3 || (chamBits>>8&3)==3))
+ fMuons += 1; //AZ
+ //if (chamBits&3 && chamBits>>2&3 && chamBits>>4&3 && chamBits>>6&3 &&
+ // chamBits>>8&3 && ((chamBits>>6&3)==3 || (chamBits>>8&3)==3) &&
+ // ((chamBits&3)==3 || (chamBits>>2&3)==3)) fMuons += 1;
} // end of track loop
return;
}
hitForRec->Dump();}
} // end of cluster loop
} // end of chamber loop
+ SortHitsForRecWithIncreasingChamber(); //AZ
return;
}
if (fPrintLevel >= 1) cout << "enter MakeSegments" << endl;
ResetSegments();
// Loop over stations
- for (Int_t st = 0; st < kMaxMuonTrackingStations; st++)
+ Int_t nb = (fTrackMethod == 2) ? 3 : 0; //AZ
+ //AZ for (Int_t st = 0; st < kMaxMuonTrackingStations; st++)
+ for (Int_t st = nb; st < kMaxMuonTrackingStations; st++) //AZ
MakeSegmentsPerStation(st);
if (fPrintLevel >= 10) {
cout << "end of MakeSegments" << endl;
// The order may be important for the following Reset's
ResetTracks();
ResetTrackHits();
- // Look for candidates from at least 3 aligned points in stations(1..) 4 and 5
- MakeTrackCandidates();
- // Follow tracks in stations(1..) 3, 2 and 1
- FollowTracks();
- // Remove double tracks
- RemoveDoubleTracks();
+ if (fTrackMethod == 2) { //AZ - Kalman filter
+ MakeTrackCandidatesK();
+ // Follow tracks in stations(1..) 3, 2 and 1
+ FollowTracksK();
+ // Remove double tracks
+ RemoveDoubleTracksK();
+ // Propagate tracks to the vertex thru absorber
+ GoToVertex();
+ } else { //AZ
+ // Look for candidates from at least 3 aligned points in stations(1..) 4 and 5
+ MakeTrackCandidates();
+ // Follow tracks in stations(1..) 3, 2 and 1
+ FollowTracks();
+ // Remove double tracks
+ RemoveDoubleTracks();
+ }
return;
}
fRecTracksPtr->Compress(); // for simple loop without "Next" since no hole
// Loop over reconstructed tracks
for (trackIndex = 0; trackIndex < fNRecTracks; trackIndex++) {
+ if (fTrackMethod != 1) continue; //AZ - skip the rest for now
if (fPrintLevel >= 1)
cout << " track number: " << trackIndex << endl;
// function for each track for modularity ????
TDirectory *current = gDirectory;
if (!fTreeFile) fTreeFile = new TFile("tree_reco.root", "RECREATE");
if (!fEventTree) fEventTree = new TTree("TreeRecoEvent", "MUON reconstructed events");
- if (fRecoEvent->MakeDumpTracks(fRecTracksPtr)) {
+ //AZif (fRecoEvent->MakeDumpTracks(fRecTracksPtr)) {
+ if (fRecoEvent->MakeDumpTracks(fMuons, fRecTracksPtr, this)) { //AZ
if (fPrintLevel > 1) fRecoEvent->EventInfo();
TBranch *branch = fEventTree->GetBranch("Event");
if (!branch) branch = fEventTree->Branch("Event", "AliMUONRecoEvent", &fRecoEvent, 64000);
// restore directory
current->cd();
}
+
+//__________________________________________________________________________
+void AliMUONEventReconstructor::MakeTrackCandidatesK(void)
+{
+ // To make initial tracks for Kalman filter from the list of segments
+ Int_t istat, iseg;
+ AliMUONSegment *segment;
+ AliMUONTrackK *trackK;
+
+ if (fPrintLevel >= 1) cout << "enter MakeTrackCandidatesK" << endl;
+ // Reset the TClonesArray of reconstructed tracks
+ if (fRecTracksPtr) fRecTracksPtr->Delete();
+ // Delete in order that the Track destructors are called,
+ // hence the space for the TClonesArray of pointers to TrackHit's is freed
+ fNRecTracks = 0;
+
+ AliMUONTrackK a(this, fHitsForRecPtr); // bad idea ???
+ // Loop over stations(1...) 5 and 4
+ for (istat=4; istat>=3; istat--) {
+ // Loop over segments in the station
+ for (iseg=0; iseg<fNSegments[istat]; iseg++) {
+ // Transform segments to tracks and evaluate covariance matrix
+ segment = (AliMUONSegment*) ((*fSegmentsPtr[istat])[iseg]);
+ trackK = new ((*fRecTracksPtr)[fNRecTracks]) AliMUONTrackK(segment);
+ fNRecTracks++;
+ } // for (iseg=0;...)
+ } // for (istat=4;...)
+ return;
+}
+
+//__________________________________________________________________________
+void AliMUONEventReconstructor::FollowTracksK(void)
+{
+ // Follow tracks using Kalman filter
+ Bool_t Ok;
+ Int_t icand, ichamBeg, ichamEnd, chamBits;
+ Double_t zDipole1, zDipole2;
+ AliMUONTrackK *trackK;
+ AliMUONHitForRec *hit;
+ AliMUONRawCluster *clus;
+ TClonesArray *rawclusters;
+ AliMUON *pMUON;
+ clus = 0; rawclusters = 0;
+
+ zDipole1 = GetSimpleBPosition() - GetSimpleBLength()/2;
+ zDipole2 = zDipole1 + GetSimpleBLength();
+
+ // Print hits
+ pMUON = (AliMUON*) gAlice->GetModule("MUON");
+ for (Int_t i1=0; i1<fNHitsForRec; i1++) {
+ hit = (AliMUONHitForRec*) ((*fHitsForRecPtr)[i1]);
+ //if (hit->GetTHTrack() > 1 || hit->GetGeantSignal() == 0) continue;
+ /*
+ cout << " Hit #" << hit->GetChamberNumber() << " ";
+ cout << hit->GetBendingCoor() << " ";
+ cout << hit->GetNonBendingCoor() << " ";
+ cout << hit->GetZ() << " ";
+ cout << hit->GetGeantSignal() << " ";
+ cout << hit->GetTHTrack() << endl;
+ */
+ /*
+ printf(" Hit # %d %10.4f %10.4f %10.4f",
+ hit->GetChamberNumber(), hit->GetBendingCoor(),
+ hit->GetNonBendingCoor(), hit->GetZ());
+ if (fRecGeantHits) {
+ // from GEANT hits
+ printf(" %3d %3d \n", hit->GetGeantSignal(), hit->GetTHTrack());
+ } else {
+ // from raw clusters
+ rawclusters = pMUON->RawClustAddress(hit->GetChamberNumber());
+ clus = (AliMUONRawCluster*) rawclusters->UncheckedAt(hit->
+ GetHitNumber());
+ printf("%3d", clus->fTracks[1]-1);
+ if (clus->fTracks[2] != 0) printf("%3d \n", clus->fTracks[2]-1);
+ else printf("\n");
+ }
+ */
+ }
+
+ icand = -1;
+ Int_t nSeeds = fNRecTracks; // starting number of seeds
+ // Loop over track candidates
+ while (icand < fNRecTracks-1) {
+ icand ++;
+ trackK = (AliMUONTrackK*) ((*fRecTracksPtr)[icand]);
+
+ // Discard candidate which will produce the double track
+ if (icand > 0) {
+ Ok = CheckCandidateK(icand,nSeeds);
+ if (!Ok) {
+ //trackK->SetRecover(-1); // mark candidate to be removed
+ //continue;
+ }
+ }
+
+ Ok = kTRUE;
+ if (trackK->GetRecover() == 0) hit = (AliMUONHitForRec*)
+ trackK->GetHitOnTrack()->Last(); // last hit
+ else hit = (AliMUONHitForRec*) (*trackK->GetHitOnTrack())[1]; // 2'nd hit
+ ichamBeg = hit->GetChamberNumber();
+ ichamEnd = 0;
+ // Check propagation direction
+ if (trackK->GetTrackDir() > 0) {
+ ichamEnd = 9; // forward propagation
+ Ok = trackK->KalmanFilter(ichamBeg,ichamEnd,kFALSE,zDipole1,zDipole2);
+ if (Ok) {
+ ichamBeg = ichamEnd;
+ ichamEnd = 6; // backward propagation
+ // Change weight matrix and zero fChi2 for backpropagation
+ trackK->StartBack();
+ Ok = trackK->KalmanFilter(ichamBeg,ichamEnd,kTRUE,zDipole1,zDipole2);
+ ichamBeg = ichamEnd;
+ ichamEnd = 0;
+ }
+ } else {
+ if (trackK->GetBPFlag()) {
+ // backpropagation
+ ichamEnd = 6; // backward propagation
+ // Change weight matrix and zero fChi2 for backpropagation
+ trackK->StartBack();
+ Ok = trackK->KalmanFilter(ichamBeg,ichamEnd,kTRUE,zDipole1,zDipole2);
+ ichamBeg = ichamEnd;
+ ichamEnd = 0;
+ }
+ }
+
+ if (Ok) {
+ trackK->SetTrackDir(-1);
+ trackK->SetBPFlag(kFALSE);
+ Ok = trackK->KalmanFilter(ichamBeg,ichamEnd,kFALSE,zDipole1,zDipole2);
+ }
+ if (Ok) trackK->SetTrackQuality(0); // compute "track quality"
+ else trackK->SetRecover(-1); // mark candidate to be removed
+
+ // Majority 3 of 4 in first 2 stations
+ chamBits = 0;
+ for (Int_t i=0; i<trackK->GetNTrackHits(); i++) {
+ hit = (AliMUONHitForRec*) (*trackK->GetHitOnTrack())[i];
+ chamBits |= BIT(hit->GetChamberNumber()-1);
+ }
+ //if (!((chamBits&3)==3 || (chamBits>>2&3)==3)) trackK->SetRecover(-1);
+ //mark candidate to be removed
+ } // while
+
+ for (Int_t i=0; i<fNRecTracks; i++) {
+ trackK = (AliMUONTrackK*) ((*fRecTracksPtr)[i]);
+ if (trackK->GetRecover() < 0) fRecTracksPtr->RemoveAt(i);
+ }
+
+ // Compress TClonesArray
+ fRecTracksPtr->Compress();
+ fNRecTracks = fRecTracksPtr->GetEntriesFast();
+ return;
+}
+
+//__________________________________________________________________________
+Bool_t AliMUONEventReconstructor::CheckCandidateK(Int_t icand, Int_t nSeeds)
+{
+ // Discards track candidate if it will produce the double track (having
+ // the same seed segment hits as hits of a good track found before)
+ AliMUONTrackK *track1, *track2;
+ AliMUONHitForRec *hit1, *hit2, *hit;
+
+ track1 = (AliMUONTrackK*) ((*fRecTracksPtr)[icand]);
+ hit1 = (AliMUONHitForRec*) (*track1->GetHitOnTrack())[0]; // 1'st hit
+ hit2 = (AliMUONHitForRec*) (*track1->GetHitOnTrack())[1]; // 2'nd hit
+
+ for (Int_t i=0; i<icand; i++) {
+ track2 = (AliMUONTrackK*) ((*fRecTracksPtr)[i]);
+ //if (track2->GetRecover() < 0) continue;
+ if (track2->GetRecover() < 0 && icand >= nSeeds) continue;
+
+ if (track1->GetStartSegment() == track2->GetStartSegment()) {
+ return kFALSE;
+ } else {
+ Int_t nSame = 0;
+ for (Int_t j=0; j<track2->GetNTrackHits(); j++) {
+ hit = (AliMUONHitForRec*) (*track2->GetHitOnTrack())[j];
+ if (hit == hit1 || hit == hit2) {
+ nSame++;
+ if (nSame == 2) return kFALSE;
+ }
+ } // for (Int_t j=0;
+ }
+ } // for (Int_t i=0;
+ return kTRUE;
+}
+
+//__________________________________________________________________________
+void AliMUONEventReconstructor::RemoveDoubleTracksK(void)
+{
+ // Removes double tracks (sharing more than half of their hits). Keeps
+ // the track with higher quality
+ AliMUONTrackK *track1, *track2, *trackToKill;
+
+ // Sort tracks according to their quality
+ fRecTracksPtr->Sort();
+
+ // Loop over first track of the pair
+ track1 = (AliMUONTrackK*) fRecTracksPtr->First();
+ while (track1) {
+ // Loop over second track of the pair
+ track2 = (AliMUONTrackK*) fRecTracksPtr->After(track1);
+ while (track2) {
+ // Check whether or not to keep track2
+ if (!track2->KeepTrack(track1)) {
+ cout << " Killed track: " << 1/(*track2->GetTrackParameters())(4,0) <<
+ " " << track2->GetTrackQuality() << endl;
+ trackToKill = track2;
+ track2 = (AliMUONTrackK*) fRecTracksPtr->After(track2);
+ trackToKill->Kill();
+ fRecTracksPtr->Compress();
+ } else track2 = (AliMUONTrackK*) fRecTracksPtr->After(track2);
+ } // track2
+ track1 = (AliMUONTrackK*) fRecTracksPtr->After(track1);
+ } // track1
+
+ fNRecTracks = fRecTracksPtr->GetEntriesFast();
+ cout << " Number of Kalman tracks: " << fNRecTracks << endl;
+}
+
+//__________________________________________________________________________
+void AliMUONEventReconstructor::GoToVertex(void)
+{
+ // Propagates track to the vertex thru absorber
+ // (using Branson correction for now)
+
+ Double_t zVertex;
+ zVertex = 0;
+ for (Int_t i=0; i<fNRecTracks; i++) {
+ //((AliMUONTrackK*)(*fRecTracksPtr)[i])->Branson();
+ //((AliMUONTrackK*)(*fRecTracksPtr)[i])->GoToZ(zVertex); // w/out absorber
+ ((AliMUONTrackK*)(*fRecTracksPtr)[i])->SetTrackQuality(1); // compute Chi2
+ ((AliMUONTrackK*)(*fRecTracksPtr)[i])->GoToVertex(); // with absorber
+ }
+}
--- /dev/null
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * *
+ * Author: The ALICE Off-line Project. *
+ * Contributors are mentioned in the code where appropriate. *
+ * *
+ * Permission to use, copy, modify and distribute this software and its *
+ * documentation strictly for non-commercial purposes is hereby granted *
+ * without fee, provided that the above copyright notice appears in all *
+ * copies and that both the copyright notice and this permission notice *
+ * appear in the supporting documentation. The authors make no claims *
+ * about the suitability of this software for any purpose. It is *
+ * provided "as is" without express or implied warranty. *
+ **************************************************************************/
+
+#include "AliMUONTrackK.h"
+
+#include <Riostream.h>
+#include <TClonesArray.h>
+#include <TArrayD.h>
+#include <TMatrixD.h>
+#include <stdlib.h> // for exit()
+
+#include "AliCallf77.h"
+#include "AliMUON.h"
+#include "AliMUONChamber.h"
+#include "AliMUONEventReconstructor.h"
+#include "AliMUONSegment.h"
+#include "AliMUONHitForRec.h"
+#include "AliMUONRawCluster.h"
+#include "AliMUONTrackParam.h"
+#include "AliRun.h"
+#include "AliMagF.h"
+
+void mnvertLocalK(Double_t* a, Int_t l, Int_t m, Int_t n, Int_t& ifail);
+
+ClassImp(AliMUONTrackK) // Class implementation in ROOT context
+
+ // A few calls in Fortran or from Fortran (extrap.F).
+#ifndef WIN32
+# define extrap_onestep_helix extrap_onestep_helix_
+# define extrap_onestep_helix3 extrap_onestep_helix3_
+# define extrap_onestep_rungekutta extrap_onestep_rungekutta_
+# define gufld_double gufld_double_
+#else
+# define extrap_onestep_helix EXTRAP_ONESTEP_HELIX
+# define extrap_onestep_helix3 EXTRAP_ONESTEP_HELIX3
+# define extrap_onestep_rungekutta EXTRAP_ONESTEP_RUNGEKUTTA
+# define gufld_double GUFLD_DOUBLE
+#endif
+
+extern "C" {
+ void type_of_call extrap_onestep_helix
+ (Double_t &Charge, Double_t &StepLength, Double_t *VGeant3, Double_t *VGeant3New);
+
+ void type_of_call extrap_onestep_helix3
+ (Double_t &Field, Double_t &StepLength, Double_t *VGeant3, Double_t *VGeant3New);
+
+ void type_of_call extrap_onestep_rungekutta
+ (Double_t &Charge, Double_t &StepLength, Double_t *VGeant3, Double_t *VGeant3New);
+
+ void type_of_call gufld_double(Double_t *Position, Double_t *Field);
+ /* void type_of_call gufld_double(Double_t *Position, Double_t *Field) {
+ // interface to "gAlice->Field()->Field" for arguments in double precision
+ Float_t x[3], b[3];
+ x[0] = Position[0]; x[1] = Position[1]; x[2] = Position[2];
+ gAlice->Field()->Field(x, b);
+ Field[0] = b[0]; Field[1] = b[1]; Field[2] = b[2];
+ }
+ */
+}
+
+Int_t AliMUONTrackK::fgNOfPoints = 0;
+AliMUON* AliMUONTrackK::fgMUON = NULL;
+AliMUONEventReconstructor* AliMUONTrackK::fgEventReconstructor = NULL;
+TClonesArray* AliMUONTrackK::fgHitForRec = NULL;
+
+ //__________________________________________________________________________
+AliMUONTrackK::AliMUONTrackK()
+{
+ // Default constructor
+
+ fgEventReconstructor = NULL; // pointer to event reconstructor
+ fgMUON = NULL; // pointer to Muon module
+ fgHitForRec = NULL; // pointer to points
+ fgNOfPoints = 0; // number of points
+
+ fStartSegment = NULL;
+ fTrackHitsPtr = NULL;
+ fNTrackHits = 0;
+ fTrackPar = NULL;
+ fTrackParNew = NULL;
+ fCovariance = NULL;
+ fWeight = NULL;
+ fSkipHit = NULL;
+
+ return;
+}
+
+ //__________________________________________________________________________
+AliMUONTrackK::AliMUONTrackK(AliMUONEventReconstructor *EventReconstructor, TClonesArray *hitForRec)
+{
+ // Constructor
+
+ fgEventReconstructor = EventReconstructor; // pointer to event reconstructor
+ fgMUON = (AliMUON*) gAlice->GetModule("MUON"); // pointer to Muon module
+ fgHitForRec = hitForRec; // pointer to points
+ fgNOfPoints = fgHitForRec->GetEntriesFast(); // number of points
+
+ fStartSegment = NULL;
+ fTrackHitsPtr = NULL;
+ fNTrackHits = 0;
+ fChi2 = 0;
+ fTrackPar = NULL;
+ fTrackParNew = NULL;
+ fCovariance = NULL;
+ fWeight = NULL;
+ fSkipHit = NULL;
+
+ return;
+}
+
+ //__________________________________________________________________________
+AliMUONTrackK::AliMUONTrackK(AliMUONSegment *segment)
+{
+ // Constructor from a segment
+ Double_t dX, dY, dZ;
+ AliMUONHitForRec *hit1, *hit2;
+ AliMUONRawCluster *clus;
+ TClonesArray *rawclusters;
+
+ fStartSegment = segment;
+ fRecover = 0;
+ // Pointers to hits from the segment
+ hit1 = segment->GetHitForRec1();
+ hit2 = segment->GetHitForRec2();
+ hit1->SetNTrackHits(hit1->GetNTrackHits()+1); // mark hit as being on track
+ hit2->SetNTrackHits(hit2->GetNTrackHits()+1); // mark hit as being on track
+ // check sorting in Z
+ if (hit1->GetZ() > hit2->GetZ()) {
+ hit1 = hit2;
+ hit2 = segment->GetHitForRec1();
+ }
+ // memory allocation for the TObjArray of pointers to reconstructed TrackHit's
+ fTrackHitsPtr = new TObjArray(10);
+ fNTrackHits = 2;
+ fChi2 = 0;
+ fBPFlag = kFALSE;
+ fTrackPar = new TMatrixD(kSize,1); // track parameters
+ fTrackParNew = new TMatrixD(kSize,1); // track parameters
+ fCovariance = new TMatrixD(kSize,kSize); // covariance matrix
+ fWeight = new TMatrixD(kSize,kSize); // weight matrix (inverse of covariance)
+
+ // Fill array of track parameters
+ if (hit1->GetChamberNumber() > 7) {
+ // last tracking station
+ (*fTrackPar)(0,0) = hit1->GetBendingCoor(); // y
+ (*fTrackPar)(1,0) = hit1->GetNonBendingCoor(); // x
+ fPosition = hit1->GetZ(); // z
+ fTrackHitsPtr->Add((TObjArray*)hit2); // add hit 2
+ fTrackHitsPtr->Add((TObjArray*)hit1); // add hit 1
+ fTrackDir = -1;
+ } else {
+ // last but one tracking station
+ (*fTrackPar)(0,0) = hit2->GetBendingCoor(); // y
+ (*fTrackPar)(1,0) = hit2->GetNonBendingCoor(); // x
+ fPosition = hit2->GetZ(); // z
+ fTrackHitsPtr->Add((TObjArray*)hit1); // add hit 1
+ fTrackHitsPtr->Add((TObjArray*)hit2); // add hit 2
+ fTrackDir = 1;
+ }
+ dZ = hit2->GetZ() - hit1->GetZ();
+ dY = hit2->GetBendingCoor() - hit1->GetBendingCoor();
+ dX = hit2->GetNonBendingCoor() - hit1->GetNonBendingCoor();
+ (*fTrackPar)(2,0) = TMath::ATan2(dY,dZ); // alpha
+ (*fTrackPar)(3,0) = TMath::ATan2(dX,dZ/TMath::Cos((*fTrackPar)(2,0))); // beta
+ (*fTrackPar)(4,0) = 1/fgEventReconstructor->GetBendingMomentumFromImpactParam(segment->GetBendingImpact()); // 1/Pt
+ (*fTrackPar)(4,0) *= TMath::Cos((*fTrackPar)(3,0)); // 1/p
+ cout << fgEventReconstructor->GetBendingMomentumFromImpactParam(segment->GetBendingImpact()) << " " << 1/(*fTrackPar)(4,0) << " ";
+ if (fgEventReconstructor->GetRecGeantHits()) {
+ // from GEANT hits
+ cout << ((AliMUONHitForRec*)((*fTrackHitsPtr)[0]))->GetTHTrack() << "<-->" << ((AliMUONHitForRec*)((*fTrackHitsPtr)[1]))->GetTHTrack() << endl;
+ } else {
+ // from raw clusters
+ for (Int_t i=0; i<2; i++) {
+ hit1 = (AliMUONHitForRec*) ((*fTrackHitsPtr)[i]);
+ rawclusters = fgMUON->RawClustAddress(hit1->GetChamberNumber());
+ clus = (AliMUONRawCluster*) rawclusters->UncheckedAt(hit1->GetHitNumber());
+ cout << clus->fTracks[1]-1;
+ if (clus->fTracks[2] != 0) cout << " " << clus->fTracks[2]-1;
+ if (i == 0) cout << " <--> ";
+ }
+ cout << endl;
+ }
+ // Evaluate covariance (and weight) matrix
+ EvalCovariance(dZ);
+
+ return;
+}
+
+ //__________________________________________________________________________
+AliMUONTrackK::~AliMUONTrackK()
+{
+ // Destructor
+
+ if (fTrackHitsPtr) {
+ delete fTrackHitsPtr; // delete the TObjArray of pointers to TrackHit's
+ fTrackHitsPtr = NULL;
+ }
+ delete fTrackPar; delete fTrackParNew; delete fCovariance;
+ delete fWeight;
+}
+
+ //__________________________________________________________________________
+AliMUONTrackK::AliMUONTrackK (const AliMUONTrackK& source)
+{
+// Dummy copy constructor
+}
+
+ //__________________________________________________________________________
+AliMUONTrackK & AliMUONTrackK::operator=(const AliMUONTrackK& source)
+{
+ // Assignment operator
+ // Members
+ if(&source == this) return *this;
+ fStartSegment = source.fStartSegment;
+ fNTrackHits = source.fNTrackHits;
+ fChi2 = source.fChi2;
+ fPosition = source.fPosition;
+ fPositionNew = source.fPositionNew;
+ fTrackDir = source.fTrackDir;
+ fBPFlag = source.fBPFlag;
+ fRecover = source.fRecover;
+ fSkipHit = source.fSkipHit;
+
+ // Pointers
+ fTrackHitsPtr = new TObjArray(*source.fTrackHitsPtr);
+ //source.fTrackHitsPtr->Dump();
+ //fTrackHitsPtr->Dump();
+
+ fTrackPar = new TMatrixD(*source.fTrackPar); // track parameters
+ fTrackParNew = new TMatrixD(*source.fTrackParNew); // track parameters
+ fCovariance = new TMatrixD(*source.fCovariance); // covariance matrix
+ fWeight = new TMatrixD(*source.fWeight); // weight matrix (inverse of covariance)
+
+ return *this;
+}
+
+ //__________________________________________________________________________
+void AliMUONTrackK::EvalCovariance(Double_t dZ)
+{
+ // Evaluate covariance (and weight) matrix for track candidate
+ Double_t sigmaB, sigmaNonB, tanA, tanB, dAdY, rad, dBdX, dBdY;
+
+ sigmaB = fgEventReconstructor->GetBendingResolution(); // bending resolution
+ sigmaNonB = fgEventReconstructor->GetNonBendingResolution(); // non-bending resolution
+
+ (*fWeight)(0,0) = sigmaB*sigmaB; // <yy>
+
+ (*fWeight)(1,1) = sigmaNonB*sigmaNonB; // <xx>
+
+ tanA = TMath::Tan((*fTrackPar)(2,0));
+ dAdY = 1/(1+tanA*tanA)/dZ;
+ (*fWeight)(2,2) = dAdY*dAdY*(*fWeight)(0,0)*2; // <aa>
+ (*fWeight)(0,2) = dAdY*(*fWeight)(0,0); // <ya>
+ (*fWeight)(2,0) = (*fWeight)(0,2);
+
+ rad = dZ/TMath::Cos((*fTrackPar)(2,0));
+ tanB = TMath::Tan((*fTrackPar)(3,0));
+ dBdX = 1/(1+tanB*tanB)/rad;
+ dBdY = 0; // neglect
+ (*fWeight)(3,3) = dBdX*dBdX*(*fWeight)(1,1)*2; // <bb>
+ (*fWeight)(1,3) = dBdX*(*fWeight)(1,1); // <xb>
+ (*fWeight)(3,1) = (*fWeight)(1,3);
+
+ //(*fWeight)(4,4) = ((*fTrackPar)(4,0)*0.2)*((*fTrackPar)(4,0)*0.2); // error 20%
+ (*fWeight)(4,4) = ((*fTrackPar)(4,0)*0.5)*((*fTrackPar)(4,0)*0.5); // error 50%
+
+ // check whether the Invert method returns flag if matrix cannot be inverted,
+ // and do not calculate the Determinant in that case !!!!
+ if (fWeight->Determinant() != 0) {
+
+ // fWeight->Invert();
+
+ Int_t ifailWeight;
+ mnvertLocalK(&((*fWeight)(0,0)), kSize,kSize,kSize,ifailWeight);
+ } else {
+ cout << " ***** Warning in EvalCovariance: Determinant fWeight=0:" << endl;
+ }
+ return;
+}
+
+ //__________________________________________________________________________
+Bool_t AliMUONTrackK::KalmanFilter(Int_t ichamBeg, Int_t ichamEnd, Bool_t Back, Double_t zDipole1, Double_t zDipole2)
+{
+ // Follows track through detector stations
+ Bool_t miss, success;
+ Int_t ichamb, iFB, iMin, iMax, dChamb, ichambOK, i;
+ Int_t ihit, firstIndx, lastIndx, currIndx, dChambMiss, iDindx=0;
+ Double_t zEnd, dChi2;
+ AliMUONHitForRec *hitAdd, *firstHit, *lastHit, *hit;
+ AliMUONRawCluster *clus;
+ TClonesArray *rawclusters;
+ hit = 0; clus = 0; rawclusters = 0;
+
+ miss = kTRUE;
+ success = kTRUE;
+ Int_t endOfProp = 0;
+ iFB = TMath::Sign(1,ichamEnd-ichamBeg);
+ iMin = TMath::Min(ichamEnd,ichamBeg);
+ iMax = TMath::Max(ichamEnd,ichamBeg);
+ ichamb = ichamBeg;
+ ichambOK = ichamb;
+
+ // Get indices of the 1'st and last hits on the track candidate
+ firstHit = (AliMUONHitForRec*) fTrackHitsPtr->First();
+ lastHit = (AliMUONHitForRec*) fTrackHitsPtr->Last();
+ firstIndx = fgHitForRec->IndexOf(firstHit);
+ lastIndx = fgHitForRec->IndexOf(lastHit);
+ currIndx = TMath::Abs (TMath::Max(firstIndx*iFB,lastIndx*iFB));
+ if (Back) {
+ // backpropagation
+ currIndx = 2;
+ iDindx = 1;
+ if (fRecover != 0) {
+ // find hit with the highest Z
+ Double_t zbeg = 0;
+ for (i=0; i<fNTrackHits; i++) {
+ hitAdd = (AliMUONHitForRec*) ((*fTrackHitsPtr)[i]);
+ zEnd = hitAdd->GetZ();
+ if (zEnd > zbeg) zbeg = zEnd;
+ else {
+ currIndx = fNTrackHits - i + 2; //???
+ break;
+ }
+ } //for (Int_t i=0;
+ }
+ } else if (fRecover != 0) {
+ Back = kTRUE; // dirty trick
+ iDindx = -1;
+ if (ichamBeg == 7 || ichamBeg == 8) currIndx = fNTrackHits - 2;
+ else {
+ Double_t zbeg = ((AliMUONHitForRec*)((*fTrackHitsPtr)[0]))->GetZ();
+ for (i=1; i<fNTrackHits; i++) {
+ hitAdd = (AliMUONHitForRec*) ((*fTrackHitsPtr)[i]);
+ zEnd = hitAdd->GetZ();
+ if (zEnd < zbeg) break;
+ } //for (Int_t i=1;
+ currIndx = fNTrackHits - i; //???
+ }
+ }
+
+ while (ichamb>=iMin && ichamb<=iMax) {
+ // Find the closest hit in Z, not belonging to the current plane
+ if (Back) {
+ // backpropagation
+ hitAdd = (AliMUONHitForRec*) ((*fTrackHitsPtr)[fNTrackHits-currIndx]);
+ zEnd = hitAdd->GetZ();
+ } else {
+ zEnd = -9999;
+ for (ihit=currIndx+iFB; ihit>=0 && ihit<fgNOfPoints; ihit+=iFB) {
+ hitAdd = (AliMUONHitForRec*) ((*fgHitForRec)[ihit]);
+ //if (TMath::Abs(hitAdd->GetZ()-fPosition) > 0.1) {
+ if (TMath::Abs(hitAdd->GetZ()-fPosition) > 0.5) {
+ zEnd = hitAdd->GetZ();
+ currIndx = ihit;
+ break;
+ }
+ }
+ }
+ if (zEnd<-999 && ichamb==ichamEnd) endOfProp = 1; // end-of-propagation
+ else {
+ // Check if there is a missing chamber
+ if (zEnd<-999 || TMath::Abs(hitAdd->GetChamberNumber()-ichamb) > 1) {
+ if (!Back && zEnd>-999) currIndx -= iFB;
+ ichamb += iFB;
+ zEnd = (&(fgMUON->Chamber(ichamb)))->Z();
+ miss = kTRUE;
+ } else {
+ ichamb = hitAdd->GetChamberNumber();
+ miss = kFALSE;
+ }
+ }
+ if (ichamb<iMin || ichamb>iMax) break;
+ // Check for missing station
+ if (!Back) {
+ dChamb = TMath::Abs(ichamb-ichambOK);
+ if (dChamb > 1) {
+ dChambMiss = endOfProp;
+ //Check if (iFB > 0) dChambMiss++;
+ if (iFB > 0) {
+ if (TMath::Odd(ichambOK)) dChambMiss++;
+ else dChambMiss--;
+ }
+ //cout << dChamb << " " << ichambOK << " " << fgNOfPoints << endl;
+ if (TMath::Odd(ichambOK) && dChamb > 3-dChambMiss) {
+ // missing station - abandon track
+ //cout << dChamb << " " << ichambOK << " " << fgNOfPoints << " " << 1/(*fTrackPar)(4,0) << endl;
+ /*
+ for (Int_t i1=0; i1<fgNOfPoints; i1++) {
+ cout << " Hit #" << ((AliMUONHitForRec*)((*fgHitForRec)[i1]))->GetChamberNumber() << " ";
+ cout << ((AliMUONHitForRec*)((*fgHitForRec)[i1]))->GetBendingCoor() << " ";
+ cout << ((AliMUONHitForRec*)((*fgHitForRec)[i1]))->GetNonBendingCoor() << " ";
+ cout << ((AliMUONHitForRec*)((*fgHitForRec)[i1]))->GetZ() << " " << " ";
+ cout << ((AliMUONHitForRec*)((*fgHitForRec)[i1]))->GetTHTrack() << endl;
+ }
+ //cout << endl;
+ */
+ /*
+ cout << fNTrackHits << endl;
+ for (Int_t i1=0; i1<fNTrackHits; i1++) {
+ hit = (AliMUONHitForRec*) ((*fTrackHitsPtr)[i1]);
+ printf(" * %d %10.4f %10.4f %10.4f",
+ hit->GetChamberNumber(), hit->GetBendingCoor(),
+ hit->GetNonBendingCoor(), hit->GetZ());
+ if (fgEventReconstructor->GetRecGeantHits()) {
+ // from GEANT hits
+ printf(" %3d %3d \n", hit->GetGeantSignal(), hit->GetTHTrack());
+ } else {
+ // from raw clusters
+ rawclusters = fgMUON->RawClustAddress(hit->GetChamberNumber());
+ clus = (AliMUONRawCluster*) rawclusters->UncheckedAt(hit->GetHitNumber());
+ printf("%3d", clus->fTracks[1]-1);
+ if (clus->fTracks[2] != 0) printf("%3d \n", clus->fTracks[2]-1);
+ else printf("\n");
+ }
+ }
+ */
+ if (fNTrackHits>2 && fRecover==0 && !(ichambOK==((AliMUONHitForRec*)((*fTrackHitsPtr)[0]))->GetChamberNumber())) {
+ // try to recover track later
+ Recover();
+ }
+ return kFALSE;
+ }
+ //Check else if (TMath::Even(ichambOK) && dChamb > 2-endOfProp) {
+ else if (TMath::Even(ichambOK) && dChamb > 2-dChambMiss) {
+ // missing station - abandon track
+ //cout << dChamb << " " << ichambOK << " " << fgNOfPoints << " " << 1/(*fTrackPar)(4,0) << endl;
+ /*
+ for (Int_t i1=0; i1<fgNOfPoints; i1++) {
+ cout << " Hit #" << ((AliMUONHitForRec*)((*fgHitForRec)[i1]))->GetChamberNumber() << " ";
+ cout << ((AliMUONHitForRec*)((*fgHitForRec)[i1]))->GetBendingCoor() << " ";
+ cout << ((AliMUONHitForRec*)((*fgHitForRec)[i1]))->GetNonBendingCoor() << " ";
+ cout << ((AliMUONHitForRec*)((*fgHitForRec)[i1]))->GetZ() << " " << " ";
+ cout << ((AliMUONHitForRec*)((*fgHitForRec)[i1]))->GetTHTrack() << endl;
+ }
+ //cout << endl;
+ */
+ /*
+ cout << fNTrackHits << endl;
+ for (Int_t i1=0; i1<fNTrackHits; i1++) {
+ hit = (AliMUONHitForRec*) ((*fTrackHitsPtr)[i1]);
+ printf(" * %d %10.4f %10.4f %10.4f",
+ hit->GetChamberNumber(), hit->GetBendingCoor(),
+ hit->GetNonBendingCoor(), hit->GetZ());
+ if (fgEventReconstructor->GetRecGeantHits()) {
+ // from GEANT hits
+ printf(" %3d %3d \n", hit->GetGeantSignal(), hit->GetTHTrack());
+ } else {
+ // from raw clusters
+ rawclusters = fgMUON->RawClustAddress(hit->GetChamberNumber());
+ clus = (AliMUONRawCluster*) rawclusters->UncheckedAt(hit->GetHitNumber());
+ printf("%3d", clus->fTracks[1]-1);
+ if (clus->fTracks[2] != 0) printf("%3d \n", clus->fTracks[2]-1);
+ else printf("\n");
+ }
+ }
+ */
+ if (fNTrackHits>2 && fRecover==0 && !(ichambOK==((AliMUONHitForRec*)((*fTrackHitsPtr)[0]))->GetChamberNumber())) {
+ // try to recover track later
+ Recover();
+ }
+ return kFALSE;
+ }
+ }
+ }
+ if (endOfProp != 0) break;
+
+ // propagate to the found Z
+
+ // Check if track steps into dipole
+ if (fPosition>zDipole2 && zEnd<zDipole2) {
+ //LinearPropagation(zDipole2-zBeg);
+ ParPropagation(zDipole2);
+ MSThin(1); // multiple scattering in the chamber
+ WeightPropagation(zDipole2); // propagate weight matrix
+ fPosition = fPositionNew;
+ *fTrackPar = *fTrackParNew;
+ //MagnetPropagation(zEnd);
+ ParPropagation(zEnd);
+ WeightPropagation(zEnd);
+ fPosition = fPositionNew;
+ }
+ // Check if track steps out of dipole
+ else if (fPosition>zDipole1 && zEnd<zDipole1) {
+ //MagnetPropagation(zDipole1-zBeg);
+ ParPropagation(zDipole1);
+ MSThin(1); // multiple scattering in the chamber
+ WeightPropagation(zDipole1);
+ fPosition = fPositionNew;
+ *fTrackPar = *fTrackParNew;
+ //LinearPropagation(zEnd-zDipole1);
+ ParPropagation(zEnd);
+ WeightPropagation(zEnd);
+ fPosition = fPositionNew;
+ } else {
+ ParPropagation(zEnd);
+ //MSThin(1); // multiple scattering in the chamber
+ if (TMath::Abs(zEnd-fPosition) > 5) MSThin(1); // multiple scattering in the chamber
+ WeightPropagation(zEnd);
+ fPosition = fPositionNew;
+ }
+
+ // Add measurement
+ if (fRecover != 0 && hitAdd == fSkipHit && !miss) {
+ // recovered track - remove the hit
+ miss = kTRUE;
+ ichamb = hitAdd->GetChamberNumber();
+ if (fRecover == 1) {
+ // remove the last hit
+ fTrackHitsPtr->Remove((TObjArray*)hitAdd); // remove hit
+ fNTrackHits --;
+ hitAdd->SetNTrackHits(hitAdd->GetNTrackHits()-1); // unmark hit
+ } else {
+ // remove the hits
+ for (i=fNTrackHits-1; i>1; i--) {
+ hitAdd = (AliMUONHitForRec*)((*fTrackHitsPtr)[i]);
+ fTrackHitsPtr->Remove((TObjArray*)hitAdd); // remove hit
+ hitAdd->SetNTrackHits(hitAdd->GetNTrackHits()-1); // unmark hit
+ fNTrackHits --;
+ if (hitAdd == fSkipHit) break;
+ } // for (i=fNTrackHits-1;
+ }
+ Back = kFALSE;
+ fRecover =0; // ????????? Dec-17-2001
+ ichambOK = ((AliMUONHitForRec*)((*fTrackHitsPtr)[fNTrackHits-1]))->GetChamberNumber();
+ currIndx = fgHitForRec->IndexOf(fSkipHit);
+ }
+
+ if (Back && !miss) {
+ // backward propagator
+ TMatrixD pointWeight(kSize,kSize);
+ TMatrixD point(kSize,1);
+ TMatrixD trackParTmp = point;
+ point(0,0) = hitAdd->GetBendingCoor();
+ point(1,0) = hitAdd->GetNonBendingCoor();
+ pointWeight(0,0) = 1/hitAdd->GetBendingReso2();
+ pointWeight(1,1) = 1/hitAdd->GetNonBendingReso2();
+ TryPoint(point,pointWeight,trackParTmp,dChi2);
+ *fTrackPar = trackParTmp;
+ *fWeight += pointWeight;
+ fChi2 += dChi2; // Chi2
+ if (ichamb==ichamEnd) break;
+ currIndx += iDindx;
+ } else {
+ // forward propagator
+ if (miss || !FindPoint(ichamb,zEnd,currIndx,iFB,hitAdd)) {
+ // missing point
+ *fTrackPar = *fTrackParNew;
+ } else {
+ //add point
+ fTrackHitsPtr->Add((TObjArray*)hitAdd); // add hit
+ fNTrackHits ++;
+ hitAdd->SetNTrackHits(hitAdd->GetNTrackHits()+1); // mark hit as being on track
+ ichambOK = ichamb;
+ currIndx = fgHitForRec->IndexOf(hitAdd); // Check
+ }
+ }
+ } // while
+ cout << fNTrackHits << " " << fChi2 << " " << 1/(*fTrackPar)(4,0) << " " << fPosition << endl;
+ return success;
+}
+
+ //__________________________________________________________________________
+void AliMUONTrackK::ParPropagation(Double_t zEnd)
+{
+ // Propagation of track parameters to zEnd
+ Int_t iFB, nTries;
+ Double_t dZ, step, distance, charge;
+ Double_t vGeant3[7], vGeant3New[7];
+
+ nTries = 0;
+ // First step using linear extrapolation
+ dZ = zEnd - fPosition;
+ iFB = (Int_t)TMath::Sign(Double_t(1.0),dZ);
+ step = dZ/TMath::Cos((*fTrackPar)(2,0))/TMath::Cos((*fTrackPar)(3,0)); // linear estimate
+ charge = iFB*TMath::Sign(Double_t(1.0),(*fTrackPar)(4,0));
+ fPositionNew = fPosition;
+ *fTrackParNew = *fTrackPar;
+ SetGeantParam(vGeant3,iFB);
+
+ // Check if overstep
+ do {
+ step = TMath::Abs(step);
+ // Propagate parameters
+ extrap_onestep_rungekutta(charge,step,vGeant3,vGeant3New);
+ distance = zEnd - vGeant3New[2];
+ step *= dZ/(vGeant3New[2]-fPositionNew);
+ nTries ++;
+ } while (distance*iFB < 0 && TMath::Abs(distance) > kEpsilon);
+
+ GetFromGeantParam(vGeant3New,iFB);
+
+ // Position ajustment (until within tolerance)
+ while (TMath::Abs(distance) > kEpsilon) {
+ dZ = zEnd - fPositionNew;
+ iFB = (Int_t)TMath::Sign(Double_t(1.0),dZ);
+ step = dZ/TMath::Cos((*fTrackParNew)(2,0))/TMath::Cos((*fTrackParNew)(3,0));
+ step = TMath::Abs(step);
+ SetGeantParam(vGeant3,iFB);
+ do {
+ // binary search
+ // Propagate parameters
+ extrap_onestep_rungekutta(charge,step,vGeant3,vGeant3New);
+ distance = zEnd - vGeant3New[2];
+ step /= 2;
+ nTries ++;
+ if (nTries > kTriesMax) {
+ cout << " ***** ParPropagation: too many tries " << nTries << endl;
+ exit(0);
+ }
+ } while (distance*iFB < 0);
+
+ GetFromGeantParam(vGeant3New,iFB);
+ }
+ //cout << nTries << endl;
+ return;
+}
+/*
+ //__________________________________________________________________________
+void AliMUONTrackK::WeightPropagation(void)
+{
+ // Propagation of the weight matrix
+ // W = DtWD, where D is Jacobian
+
+ // !!! not implemented TMatrixD weight1(*fJacob,TMatrixD::kAtBA,*fWeight); // DtWD
+ TMatrixD weight1(*fWeight,TMatrixD::kMult,*fJacob); // WD
+ *fWeight = TMatrixD(*fJacob,TMatrixD::kTransposeMult,weight1); // DtWD
+ return;
+}
+*/
+ //__________________________________________________________________________
+void AliMUONTrackK::WeightPropagation(Double_t zEnd)
+{
+ // Propagation of the weight matrix
+ // W = DtWD, where D is Jacobian
+ Int_t i, j;
+ Double_t dPar;
+
+ TMatrixD Jacob(kSize,kSize);
+ Jacob = 0;
+
+ // Save initial and propagated parameters
+ TMatrixD trackPar0 = *fTrackPar;
+ TMatrixD trackParNew0 = *fTrackParNew;
+ Double_t savePosition = fPositionNew;
+
+ // Get covariance matrix
+ *fCovariance = *fWeight;
+ // check whether the Invert method returns flag if matrix cannot be inverted,
+ // and do not calculate the Determinant in that case !!!!
+ if (fCovariance->Determinant() != 0) {
+ // fCovariance->Invert();
+ Int_t ifailCov;
+ mnvertLocalK(&((*fCovariance)(0,0)), kSize,kSize,kSize,ifailCov);
+ } else {
+ cout << " ***** Warning in WeightPropagation: Determinant fCovariance=0:" << endl;
+ }
+
+ // Loop over parameters to find change of the initial vs propagated ones
+ zEnd = fPosition;
+ fPosition = fPositionNew;
+ for (i=0; i<kSize; i++) {
+ dPar = TMath::Sqrt((*fCovariance)(i,i));
+ *fTrackPar = trackParNew0;
+ (*fTrackPar)(i,0) += dPar;
+ ParPropagation(zEnd);
+ for (j=0; j<kSize; j++) {
+ Jacob(j,i) = ((*fTrackParNew)(j,0)-trackPar0(j,0))/dPar;
+ }
+ }
+
+ //Jacob->Print();
+ //trackParNew0.Print();
+ //TMatrixD par1(Jacob,TMatrixD::kMult,trackPar0); //
+ //par1.Print();
+ /*
+ if (Jacob.Determinant() != 0) {
+ // Jacob.Invert();
+ } else {
+ cout << " ***** Warning in WeightPropagation: Determinant Jacob=0:" << endl;
+ }
+ */
+ TMatrixD weight1(*fWeight,TMatrixD::kMult,Jacob); // WD
+ *fWeight = TMatrixD(Jacob,TMatrixD::kTransposeMult,weight1); // DtWD
+ //fWeight->Print();
+
+ // Restore initial and propagated parameters
+ *fTrackPar = trackPar0;
+ *fTrackParNew = trackParNew0;
+ fPosition = zEnd;
+ fPositionNew = savePosition;
+ return;
+}
+
+ //__________________________________________________________________________
+Bool_t AliMUONTrackK::FindPoint(Int_t ichamb, Double_t zEnd, Int_t currIndx, Int_t iFB, AliMUONHitForRec *&hitAdd)
+{
+ // Picks up point within a window for the chamber No ichamb
+ // Split the track if there are more than 1 hit
+ Int_t ihit, nRecTracks;
+ Double_t WindowB, WindowNonB, dChi2Tmp=0, dChi2, y, x, savePosition=0;
+ TClonesArray *trackPtr;
+ AliMUONHitForRec *hit, *hitLoop;
+ AliMUONTrackK *trackK;
+
+ Bool_t Ok = kFALSE;
+ //sigmaB = fgEventReconstructor->GetBendingResolution(); // bending resolution
+ //sigmaNonB = fgEventReconstructor->GetNonBendingResolution(); // non-bending resolution
+ *fCovariance = *fWeight;
+ // check whether the Invert method returns flag if matrix cannot be inverted,
+ // and do not calculate the Determinant in that case !!!!
+ if (fCovariance->Determinant() != 0) {
+ // fCovariance->Invert();
+
+ Int_t ifailCov;
+ mnvertLocalK(&((*fCovariance)(0,0)), kSize,kSize,kSize,ifailCov);
+ } else {
+ cout << " ***** Warning in FindPoint: Determinant fCovariance=0:" << endl;
+ }
+ //WindowB = kNSigma*TMath::Sqrt((*fCovariance)(0,0)+sigmaB*sigmaB);
+ //WindowNonB = kNSigma*TMath::Sqrt((*fCovariance)(1,1)+sigmaNonB*sigmaNonB);
+ // Loop over all hits and take hits from the chamber
+ TMatrixD pointWeight(kSize,kSize);
+ TMatrixD saveWeight = pointWeight;
+ TMatrixD pointWeightTmp = pointWeight;
+ TMatrixD point(kSize,1);
+ TMatrixD trackPar = point;
+ TMatrixD trackParTmp = point;
+ Int_t nHitsOK = 0;
+
+ for (ihit=currIndx; ihit>=0 && ihit<fgNOfPoints; ihit+=iFB) {
+ hit = (AliMUONHitForRec*) ((*fgHitForRec)[ihit]);
+ if (hit->GetChamberNumber() == ichamb) {
+ //if (TMath::Abs(hit->GetZ()-zEnd) < 0.1) {
+ if (TMath::Abs(hit->GetZ()-zEnd) < 0.5) {
+ if (TMath::Abs(hit->GetZ()-zEnd) > 0.1) {
+ // adjust position: for multiple hits in the chamber
+ // (mostly (only?) for GEANT hits)
+ zEnd = hit->GetZ();
+ *fTrackPar = *fTrackParNew;
+ ParPropagation(zEnd);
+ WeightPropagation(zEnd);
+ fPosition = fPositionNew;
+ *fTrackPar = *fTrackParNew;
+ // Get covariance
+ *fCovariance = *fWeight;
+ if (fCovariance->Determinant() != 0) {
+ //fCovariance->Invert();
+ Int_t ifailCov;
+ mnvertLocalK(&((*fCovariance)(0,0)), kSize,kSize,kSize,ifailCov);
+ } else {
+ cout << " ***** Warning in FindPoint: Determinant fCovariance=0:" << endl;
+ }
+ }
+ y = hit->GetBendingCoor();
+ x = hit->GetNonBendingCoor();
+ WindowB = kNSigma*TMath::Sqrt((*fCovariance)(0,0)+hit->GetBendingReso2());
+ WindowNonB = kNSigma*TMath::Sqrt((*fCovariance)(1,1)+hit->GetNonBendingReso2());
+ if (TMath::Abs((*fTrackParNew)(0,0)-y) <= WindowB &&
+ TMath::Abs((*fTrackParNew)(1,0)-x) <= WindowNonB) {
+ // Vector of measurements and covariance matrix
+ point.Zero();
+ point(0,0) = y;
+ point(1,0) = x;
+ pointWeight(0,0) = 1/hit->GetBendingReso2();
+ pointWeight(1,1) = 1/hit->GetNonBendingReso2();
+ TryPoint(point,pointWeight,trackPar,dChi2);
+ if (TMath::Abs(1./(trackPar)(4,0)) < fgEventReconstructor->GetMinBendingMomentum()) continue; // p < p_min - next hit
+ Ok = kTRUE;
+ nHitsOK++;
+ //if (nHitsOK > -1) {
+ if (nHitsOK == 1) {
+ // Save current members
+ saveWeight = *fWeight;
+ savePosition = fPosition;
+ // temporary storage for the current track
+ dChi2Tmp = dChi2;
+ trackParTmp = trackPar;
+ pointWeightTmp = pointWeight;
+ hitAdd = hit;
+ } else {
+ // branching: create a new track
+ trackPtr = fgEventReconstructor->GetRecTracksPtr();
+ nRecTracks = fgEventReconstructor->GetNRecTracks();
+ trackK = new ((*trackPtr)[nRecTracks])
+ AliMUONTrackK(*this); // dummy copy constructor
+ *trackK = *this;
+ fgEventReconstructor->SetNRecTracks(nRecTracks+1);
+ //cout << " ******** New track: " << ichamb << " " << hit->GetTHTrack() << " " << 1/(trackPar)(4,0) << " " << hit->GetBendingCoor() << " " << fNTrackHits << " " << nRecTracks << endl;
+ trackK->fRecover = 0;
+ *(trackK->fTrackPar) = trackPar;
+ *(trackK->fWeight) += pointWeight;
+ trackK->fChi2 += dChi2;
+ // Mark hits as being on 2 tracks
+ for (Int_t i=0; i<fNTrackHits; i++) {
+ hitLoop = (AliMUONHitForRec*) ((*fTrackHitsPtr)[i]);
+ hitLoop->SetNTrackHits(hitLoop->GetNTrackHits()+1);
+ /*
+ cout << " ** ";
+ cout << hitLoop->GetChamberNumber() << " ";
+ cout << hitLoop->GetBendingCoor() << " ";
+ cout << hitLoop->GetNonBendingCoor() << " ";
+ cout << hitLoop->GetZ() << " " << " ";
+ cout << hitLoop->GetGeantSignal() << " " << " ";
+ cout << hitLoop->GetTHTrack() << endl;
+ printf(" ** %d %10.4f %10.4f %10.4f %d %d \n",
+ hitLoop->GetChamberNumber(), hitLoop->GetBendingCoor(),
+ hitLoop->GetNonBendingCoor(), hitLoop->GetZ(),
+ hitLoop->GetGeantSignal(), hitLoop->GetTHTrack());
+ */
+ }
+ //add point
+ trackK->fTrackHitsPtr->Add((TObjArray*)hit); // add hit
+ trackK->fNTrackHits ++;
+ hit->SetNTrackHits(hit->GetNTrackHits()+1); // mark hit as being on track
+ if (ichamb == 9) {
+ // the last chamber
+ trackK->fTrackDir = -1;
+ trackK->fBPFlag = kTRUE;
+ }
+ }
+ }
+ }
+ } else break; // different chamber
+ } // for (ihit=currIndx;
+ if (Ok) {
+ *fTrackPar = trackParTmp;
+ *fWeight = saveWeight;
+ *fWeight += pointWeightTmp;
+ fChi2 += dChi2Tmp; // Chi2
+ // Restore members
+ fPosition = savePosition;
+ }
+ return Ok;
+}
+
+ //__________________________________________________________________________
+void AliMUONTrackK::TryPoint(TMatrixD &point, const TMatrixD &pointWeight, TMatrixD &trackParTmp, Double_t &dChi2)
+{
+ // Adds a measurement point (modifies track parameters and computes
+ // change of Chi2)
+
+ // Solving linear system (W+U)p' = U(m-p) + (W+U)p
+ TMatrixD wu = *fWeight;
+ wu += pointWeight; // W+U
+ trackParTmp = point;
+ trackParTmp -= *fTrackParNew; // m-p
+ TMatrixD right(pointWeight,TMatrixD::kMult,trackParTmp); // U(m-p)
+ TMatrixD right1(wu,TMatrixD::kMult,*fTrackParNew); // (W+U)p
+ right += right1; // U(m-p) + (W+U)p
+
+ // check whether the Invert method returns flag if matrix cannot be inverted,
+ // and do not calculate the Determinant in that case !!!!
+ if (wu.Determinant() != 0) {
+
+ // wu.Invert();
+ Int_t ifailWU;
+ mnvertLocalK(&((wu)(0,0)), kSize,kSize,kSize,ifailWU);
+ } else {
+ cout << " ***** Warning in TryPoint: Determinant wu=0:" << endl;
+ }
+ trackParTmp = TMatrixD(wu,TMatrixD::kMult,right);
+
+ right1 = trackParTmp;
+ right1 -= point; // p'-m
+ point = trackParTmp;
+ point -= *fTrackParNew; // p'-p
+ right = TMatrixD(*fWeight,TMatrixD::kMult,point); // W(p'-p)
+ TMatrixD value(point,TMatrixD::kTransposeMult,right); // (p'-p)'W(p'-p)
+ dChi2 = value(0,0);
+ right = TMatrixD(pointWeight,TMatrixD::kMult,right1); // U(p'-m)
+ value = TMatrixD(right1,TMatrixD::kTransposeMult,right); // (p'-m)'U(p'-m)
+ dChi2 += value(0,0);
+ return;
+}
+
+ //__________________________________________________________________________
+void AliMUONTrackK::MSThin(Int_t sign)
+{
+ // Adds multiple scattering in a thin layer (only angles are affected)
+ Double_t cosAlph, cosBeta, momentum, velo, path, theta0;
+
+ // check whether the Invert method returns flag if matrix cannot be inverted,
+ // and do not calculate the Determinant in that case !!!!
+ if (fWeight->Determinant() != 0) {
+ //fWeight->Invert(); // covariance
+
+ Int_t ifailWeight;
+ mnvertLocalK(&((*fWeight)(0,0)), kSize,kSize,kSize,ifailWeight);
+ } else {
+ cout << " ***** Warning in MSThin: Determinant fWeight=0:" << endl;
+ }
+
+ cosAlph = TMath::Cos((*fTrackParNew)(2,0));
+ cosBeta = TMath::Cos((*fTrackParNew)(3,0));
+ momentum = 1/(*fTrackParNew)(4,0); // particle momentum
+ //velo = momentum/TMath::Sqrt(momentum*momentum+muonMass*muonMass); // velocity/c for muon hypothesis
+ velo = 1; // relativistic
+ path = fgEventReconstructor->GetChamberThicknessInX0()/cosAlph/cosBeta; // path length
+ theta0 = 0.0136/velo/momentum*TMath::Sqrt(path)*(1+0.038*TMath::Log(path)); // projected scattering angle
+
+ (*fWeight)(2,2) += sign*theta0/cosBeta*theta0/cosBeta; // alpha
+ (*fWeight)(3,3) += sign*theta0*theta0; // beta
+ //fWeight->Invert(); // weight
+
+ Int_t ifailWeight;
+ mnvertLocalK(&((*fWeight)(0,0)), kSize,kSize,kSize,ifailWeight);
+ return;
+}
+ //__________________________________________________________________________
+void AliMUONTrackK::StartBack(void)
+{
+ // Starts backpropagator
+
+ fBPFlag = kTRUE;
+ fChi2 = 0;
+ for (Int_t i=0; i<kSize; i++) {
+ for (Int_t j=0; j<kSize; j++) {
+ if (j==i) (*fWeight)(i,i) /= 100;
+ //if (j==i) (*fWeight)(i,i) /= fNTrackHits*fNTrackHits;
+ else (*fWeight)(j,i) = 0;
+ }
+ }
+}
+
+ //__________________________________________________________________________
+void AliMUONTrackK::SetGeantParam(Double_t *VGeant3, Int_t iFB)
+{
+ // Set vector of Geant3 parameters pointed to by "VGeant3"
+ // from track parameters
+
+ VGeant3[0] = (*fTrackParNew)(1,0); // X
+ VGeant3[1] = (*fTrackParNew)(0,0); // Y
+ VGeant3[2] = fPositionNew; // Z
+ VGeant3[3] = iFB*TMath::Sin((*fTrackParNew)(3,0)); // Px/Ptot
+ VGeant3[4] = iFB*TMath::Cos((*fTrackParNew)(3,0))*TMath::Sin((*fTrackParNew)(2,0)); // Py/Ptot
+ VGeant3[5] = iFB*TMath::Sqrt(1.0-VGeant3[3]*VGeant3[3]-VGeant3[4]*VGeant3[4]); // Pz/Ptot
+ VGeant3[6] = 1/TMath::Abs((*fTrackParNew)(4,0)); // Ptot
+}
+
+ //__________________________________________________________________________
+void AliMUONTrackK::GetFromGeantParam(Double_t *VGeant3, Int_t iFB)
+{
+ // Get track parameters from vector of Geant3 parameters pointed
+ // to by "VGeant3"
+
+ fPositionNew = VGeant3[2]; // Z
+ (*fTrackParNew)(0,0) = VGeant3[1]; // Y
+ (*fTrackParNew)(1,0) = VGeant3[0]; // X
+ (*fTrackParNew)(3,0) = TMath::ASin(iFB*VGeant3[3]); // beta
+ (*fTrackParNew)(2,0) = TMath::ASin(iFB*VGeant3[4]/TMath::Cos((*fTrackParNew)(3,0))); // alpha
+ (*fTrackParNew)(4,0) = 1/VGeant3[6]*TMath::Sign(Double_t(1.0),(*fTrackPar)(4,0)); // 1/Ptot
+}
+
+ //__________________________________________________________________________
+void AliMUONTrackK::SetTrackQuality(Int_t iChi2)
+{
+ // Computes "track quality" from Chi2 (if iChi2==0) or vice versa
+
+ if (fChi2 > 250) {
+ cout << " ***** Too high Chi2: " << fChi2 << endl;
+ fChi2 = 250;
+ // exit(0);
+ }
+ if (iChi2 == 0) fChi2 = fNTrackHits + (250.-fChi2)/251;
+ else fChi2 = 250 - (fChi2-fNTrackHits)*251;
+}
+
+ //__________________________________________________________________________
+Int_t AliMUONTrackK::Compare(const TObject* trackK) const
+{
+ // "Compare" function to sort with decreasing "track quality".
+ // Returns +1 (0, -1) if quality of current track
+ // is smaller than (equal to, larger than) quality of trackK
+
+ if (fChi2 < ((AliMUONTrackK*)trackK)->fChi2) return(+1);
+ else if (fChi2 == ((AliMUONTrackK*)trackK)->fChi2) return(0);
+ else return(-1);
+}
+
+ //__________________________________________________________________________
+Bool_t AliMUONTrackK::KeepTrack(AliMUONTrackK* track0)
+{
+ // Check whether or not to keep current track
+ // (keep, if it has less than half of common hits with track0)
+ Int_t hitsInCommon, nHits0, i, j, nTrackHits2;
+ AliMUONHitForRec *hit0, *hit1;
+
+ hitsInCommon = 0;
+ nHits0 = track0->fNTrackHits;
+ nTrackHits2 = fNTrackHits/2;
+
+ for (i=0; i<nHits0; i++) {
+ // Check if hit belongs to several tracks
+ hit0 = (AliMUONHitForRec*) (*track0->fTrackHitsPtr)[i];
+ if (hit0->GetNTrackHits() == 1) continue;
+ for (j=0; j<fNTrackHits; j++) {
+ hit1 = (AliMUONHitForRec*) (*fTrackHitsPtr)[j];
+ if (hit1->GetNTrackHits() == 1) continue;
+ if (hit0 == hit1) {
+ hitsInCommon++;
+ if (hitsInCommon >= nTrackHits2) return kFALSE;
+ break;
+ }
+ } // for (j=0;
+ } // for (i=0;
+ return kTRUE;
+}
+
+ //__________________________________________________________________________
+void AliMUONTrackK::Kill(void)
+{
+ // Kill track candidate
+ Int_t i;
+ AliMUONHitForRec *hit;
+
+ if (fTrackHitsPtr) {
+ // Remove track mark from hits
+ for (i=0; i<fNTrackHits; i++) {
+ hit = (AliMUONHitForRec*) (*fTrackHitsPtr)[i];
+ hit->SetNTrackHits(hit->GetNTrackHits()-1);
+ }
+ }
+ fgEventReconstructor->GetRecTracksPtr()->Remove(this);
+}
+
+ //__________________________________________________________________________
+void AliMUONTrackK::Branson(void)
+{
+ // Propagates track to the vertex thru absorber using Branson correction
+ // (makes use of the AliMUONTrackParam class)
+
+ AliMUONTrackParam *trackParam = new AliMUONTrackParam();
+ trackParam->SetBendingCoor((*fTrackPar)(0,0));
+ trackParam->SetNonBendingCoor((*fTrackPar)(1,0));
+ trackParam->SetBendingSlope(TMath::Tan((*fTrackPar)(2,0)));
+ trackParam->SetNonBendingSlope(TMath::Tan((*fTrackPar)(3,0))/TMath::Cos((*fTrackPar)(2,0)));
+ trackParam->SetInverseBendingMomentum((*fTrackPar)(4,0)/TMath::Cos((*fTrackPar)(3,0)));
+ trackParam->SetZ(fPosition);
+
+ trackParam->ExtrapToVertex();
+
+ (*fTrackPar)(0,0) = trackParam->GetBendingCoor();
+ (*fTrackPar)(1,0) = trackParam->GetNonBendingCoor();
+ (*fTrackPar)(2,0) = TMath::ATan(trackParam->GetBendingSlope());
+ (*fTrackPar)(3,0) = TMath::ATan(TMath::Cos((*fTrackPar)(2,0))*trackParam->GetNonBendingSlope());
+ (*fTrackPar)(4,0) = TMath::Cos((*fTrackPar)(3,0))*trackParam->GetInverseBendingMomentum();
+ fPosition = trackParam->GetZ();
+ delete trackParam;
+ cout << 1/(*fTrackPar)(4,0) << " " << fPosition << " " << (*fTrackPar)(0,0) << endl;
+
+ // Get covariance matrix
+ *fCovariance = *fWeight;
+ if (fCovariance->Determinant() != 0) {
+ // fCovariance->Invert();
+
+ Int_t ifailCov;
+ mnvertLocalK(&((*fCovariance)(0,0)), kSize,kSize,kSize,ifailCov);
+ } else {
+ cout << " ***** Warning in Branson: Determinant fCovariance=0:" << endl;
+ }
+}
+
+ //__________________________________________________________________________
+void AliMUONTrackK::GoToZ(Double_t zEnd)
+{
+ // Propagates track to given Z
+
+ ParPropagation(zEnd);
+ MSThin(1); // multiple scattering in the chamber
+ WeightPropagation(zEnd);
+ fPosition = fPositionNew;
+ *fTrackPar = *fTrackParNew;
+}
+
+ //__________________________________________________________________________
+void AliMUONTrackK::GoToVertex(void)
+{
+ // Version 3.08
+ // Propagates track to the vertex
+ // All material constants are taken from AliRoot
+
+ static Double_t x01[5] = { 24.282, // C
+ 24.282, // C
+ 11.274, // Concrete
+ 1.758, // Fe
+ 1.758}; // Fe (cm)
+ // inner part theta < 3 degrees
+ static Double_t x02[5] = { 30413, // Air
+ 24.282, // C
+ 11.274, // Concrete
+ 1.758, // Fe
+ 0.369}; // W (cm)
+ // z positions of the materials inside the absober outer part theta > 3 degres
+ static Double_t zPos[10] = {90, 105, 315, 443, 468};
+ // R > 1
+ // R < 1
+
+ Double_t dZ, r0Norm, X0, deltaP, dChi2, pTotal, pOld;
+ AliMUONHitForRec *hit;
+ AliMUONRawCluster *clus;
+ TClonesArray *rawclusters;
+
+ // First step to the rear end of the absorber
+ Double_t zRear = 503;
+ GoToZ(zRear);
+ Double_t tan3 = TMath::Tan(3./180*TMath::Pi());
+
+ // Go through absorber
+ pOld = 1/(*fTrackPar)(4,0);
+ Double_t r0Rear = (*fTrackPar)(0,0)*(*fTrackPar)(0,0) +
+ (*fTrackPar)(1,0)*(*fTrackPar)(1,0);
+ r0Rear = TMath::Sqrt(r0Rear)/fPosition/tan3;
+ r0Norm = r0Rear;
+ for (Int_t i=4; i>=0; i--) {
+ ParPropagation(zPos[i]);
+ WeightPropagation(zPos[i]);
+ dZ = TMath::Abs (fPositionNew-fPosition);
+ if (r0Norm > 1) X0 = x01[i];
+ else X0 = x02[i];
+ MSLine(dZ,X0); // multiple scattering in the medium (linear approximation)
+ fPosition = fPositionNew;
+ *fTrackPar = *fTrackParNew;
+ r0Norm = (*fTrackPar)(0,0)*(*fTrackPar)(0,0) +
+ (*fTrackPar)(1,0)*(*fTrackPar)(1,0);
+ r0Norm = TMath::Sqrt(r0Norm)/fPosition/tan3;
+ }
+ // Correct momentum for energy losses
+ pTotal = 1/TMath::Abs((*fTrackPar)(4,0));
+ Double_t p0 = pTotal;
+ for (Int_t j=0; j<2; j++) {
+ /*
+ if (r0Rear > 1) {
+ if (p0 < 20) {
+ deltaP = 2.164 + 0.145e-1*p0 - 0.417e-3*p0*p0;
+ } else {
+ deltaP = 2.275 + 0.102e-2*p0 - 0.674e-6*p0*p0;
+ }
+ } else {
+ if (p0 < 20) {
+ deltaP = 2.581 + 0.188e-1*p0 - 0.398e-3*p0*p0;
+ } else {
+ deltaP = 2.727 + 0.356e-2*p0 + 0.242e-5*p0*p0;
+ }
+ }
+ */
+ if (r0Rear < 1) {
+ //W
+ if (p0<15) {
+ deltaP = 2.737 + 0.0494*p0 - 0.001123*p0*p0;
+ } else {
+ deltaP = 3.0643 + 0.01346*p0;
+ }
+ } else {
+ //Pb
+ if (p0<15) {
+ deltaP = 2.1380 + 0.0351*p0 - 0.000853*p0*p0;
+ } else {
+ deltaP = 2.407 + 0.00702*p0;
+ }
+ }
+
+ p0 = pTotal + deltaP/TMath::Cos((*fTrackPar)(2,0))/TMath::Cos((*fTrackPar)(3,0));
+ }
+ (*fTrackPar)(4,0) = 1/p0*TMath::Sign((Double_t)1.,(*fTrackPar)(4,0));
+
+ // Go to the vertex
+ ParPropagation((Double_t)0.);
+ WeightPropagation((Double_t)0.);
+ fPosition = fPositionNew;
+ //*fTrackPar = *fTrackParNew;
+ // Add vertex as a hit
+ TMatrixD pointWeight(kSize,kSize);
+ TMatrixD point(kSize,1);
+ TMatrixD trackParTmp = point;
+ point(0,0) = 0; // vertex coordinate - should be taken somewhere
+ point(1,0) = 0; // vertex coordinate - should be taken somewhere
+ pointWeight(0,0) = 1/1.e-3/1.e-3; // 10 um error
+ pointWeight(1,1) = 1/1.e-3/1.e-3; // 10 um error
+ TryPoint(point,pointWeight,trackParTmp,dChi2);
+ *fTrackPar = trackParTmp;
+ *fWeight += pointWeight;
+ fChi2 += dChi2; // Chi2
+ cout << pOld << " " << 1/(*fTrackPar)(4,0) << " " << dChi2 << " " << fChi2 << " " << fNTrackHits << endl;
+ for (Int_t i1=0; i1<fNTrackHits; i1++) {
+ hit = (AliMUONHitForRec*) ((*fTrackHitsPtr)[i1]);
+ printf ("%4d", hit->GetChamberNumber());
+ //cout << ((AliMUONHitForRec*)((*fTrackHitsPtr)[i1]))->GetChamberNumber() << " ";
+ }
+ cout << endl;
+ for (Int_t i1=0; i1<fNTrackHits; i1++) {
+ hit = (AliMUONHitForRec*) ((*fTrackHitsPtr)[i1]);
+ //cout << ((AliMUONHitForRec*)((*fTrackHitsPtr)[i1]))->GetHitNumber() << " ";
+ //cout << ((AliMUONHitForRec*)((*fTrackHitsPtr)[i1]))->GetZ() << " ";
+ printf ("%4d", fgHitForRec->IndexOf(hit));
+ //cout << fgHitForRec->IndexOf(((AliMUONHitForRec*)((*fTrackHitsPtr)[i1]))) << " ";
+ }
+ cout << endl;
+ if (fgEventReconstructor->GetRecGeantHits()) {
+ // from GEANT hits
+ for (Int_t i1=0; i1<fNTrackHits; i1++) {
+ hit = (AliMUONHitForRec*) ((*fTrackHitsPtr)[i1]);
+ cout << hit->GetTHTrack() + hit->GetGeantSignal()*10000 << " ";
+ }
+ } else {
+ // from raw clusters
+ for (Int_t i1=0; i1<fNTrackHits; i1++) {
+ hit = (AliMUONHitForRec*) ((*fTrackHitsPtr)[i1]);
+ rawclusters = fgMUON->RawClustAddress(hit->GetChamberNumber());
+ clus = (AliMUONRawCluster*) rawclusters->UncheckedAt(hit->GetHitNumber());
+ printf ("%4d", clus->fTracks[1] - 1);
+ //cout << clus->fTracks[1] - 1 << " ";
+ }
+ cout << endl;
+ for (Int_t i1=0; i1<fNTrackHits; i1++) {
+ hit = (AliMUONHitForRec*) ((*fTrackHitsPtr)[i1]);
+ rawclusters = fgMUON->RawClustAddress(hit->GetChamberNumber());
+ clus = (AliMUONRawCluster*) rawclusters->UncheckedAt(hit->GetHitNumber());
+ if (clus->fTracks[2] != 0) printf ("%4d", clus->fTracks[2] - 1);
+ else printf ("%4s", " ");
+ //if (clus->fTracks[2] != 0) cout << clus->fTracks[2] - 1 << " ";
+ }
+ }
+ cout << endl;
+ for (Int_t i1=0; i1<fNTrackHits; i1++) {
+ //cout << ((AliMUONHitForRec*)((*fTrackHitsPtr)[i1]))->GetHitNumber() << " ";
+ cout << ((AliMUONHitForRec*)((*fTrackHitsPtr)[i1]))->GetZ() << " ";
+ //cout << fgHitForRec->IndexOf(((AliMUONHitForRec*)((*fTrackHitsPtr)[i1]))) << " ";
+ }
+ cout << endl;
+ cout << "---------------------------------------------------" << endl;
+
+ // Get covariance matrix
+ *fCovariance = *fWeight;
+ if (fCovariance->Determinant() != 0) {
+ // fCovariance->Invert();
+
+ Int_t ifailCov;
+ mnvertLocalK(&((*fCovariance)(0,0)), kSize,kSize,kSize,ifailCov);
+ } else {
+ cout << " ***** Warning in GoToVertex: Determinant fCovariance=0:" << endl;
+ }
+}
+
+ //__________________________________________________________________________
+void AliMUONTrackK::MSLine(Double_t dZ, Double_t X0)
+{
+ // Adds multiple scattering in a thick layer for linear propagation
+
+ Double_t cosAlph = TMath::Cos((*fTrackPar)(2,0));
+ Double_t tanAlph = TMath::Tan((*fTrackPar)(2,0));
+ Double_t cosBeta = TMath::Cos((*fTrackPar)(3,0));
+ Double_t sinBeta;
+ sinBeta = TMath::Sin((*fTrackPar)(3,0));
+ Double_t tanBeta = TMath::Tan((*fTrackPar)(3,0));
+ Double_t momentum = 1/(*fTrackPar)(4,0);
+ Double_t velo = 1; // relativistic velocity
+ Double_t step = TMath::Abs(dZ)/cosAlph/cosBeta; // step length
+
+ // Projected scattering angle
+ Double_t theta0 = 0.0136/velo/momentum/TMath::Sqrt(X0)*(1+0.038*TMath::Log(step/X0));
+ Double_t theta02 = theta0*theta0;
+ Double_t dl2 = step*step/2*theta02;
+ Double_t dl3 = dl2*step*2/3;
+
+ //Derivatives
+ Double_t dYdT = 1/cosAlph;
+ Double_t dYdB = 0; //(*fTrackPar)(2,0)*sinBeta/cosAlph;
+ Double_t dXdT = tanAlph*tanBeta;
+ //Double_t dXdB = (1+(*fTrackPar)(2,0)*tanAlph*sinBeta*sinBeta)/cosBeta;
+ Double_t dXdB = 1/cosBeta;
+ Double_t dAdT = 1/cosBeta;
+ Double_t dAdB = 0; //(*fTrackPar)(2,0)*tanBeta;
+
+ // Get covariance matrix
+ *fCovariance = *fWeight;
+ if (fCovariance->Determinant() != 0) {
+ // fCovariance->Invert();
+
+ Int_t ifailCov;
+ mnvertLocalK(&((*fCovariance)(0,0)), kSize,kSize,kSize,ifailCov);
+ } else {
+ cout << " ***** Warning in MSLine: Determinant fCovariance=0:" << endl;
+ }
+
+ (*fCovariance)(0,0) += dl3*(dYdT*dYdT+dYdB*dYdB); // <yy>
+ (*fCovariance)(1,1) += dl3*(dXdT*dXdT+dXdB*dXdB); // <xx>
+ (*fCovariance)(2,2) += theta02*step*(dAdT*dAdT+dAdB*dAdB); // <aa>
+ (*fCovariance)(3,3) += theta02*step; // <bb>
+
+ (*fCovariance)(0,1) += dl3*(dYdT*dXdT+dYdB*dXdB); // <yx>
+ (*fCovariance)(1,0) = (*fCovariance)(0,1);
+
+ (*fCovariance)(0,2) += dl2*(dYdT*dAdT+dYdB*dAdB); // <ya>
+ (*fCovariance)(2,0) = (*fCovariance)(0,2);
+
+ (*fCovariance)(0,3) += dl2*dYdB; // <yb>
+ (*fCovariance)(3,0) = (*fCovariance)(0,3);
+
+ (*fCovariance)(1,2) += dl2*(dXdT*dAdT+dXdB*dAdB); // <xa>
+ (*fCovariance)(2,1) = (*fCovariance)(1,2);
+
+ (*fCovariance)(1,3) += dl2*dXdB; // <xb>
+ (*fCovariance)(3,1) = (*fCovariance)(1,3);
+
+ (*fCovariance)(2,3) += theta02*step*dAdB; // <ab>
+ (*fCovariance)(3,2) = (*fCovariance)(2,3);
+
+ // Get weight matrix
+ *fWeight = *fCovariance;
+ if (fWeight->Determinant() != 0) {
+ // fWeight->Invert();
+
+ Int_t ifailWeight;
+ mnvertLocalK(&((*fWeight)(0,0)), kSize,kSize,kSize,ifailWeight);
+ } else {
+ cout << " ***** Warning in MSLine: Determinant fWeight=0:" << endl;
+ }
+}
+
+ //__________________________________________________________________________
+void AliMUONTrackK::Recover(void)
+{
+ // Adds new failed track(s) which can be tried to be recovered
+ Int_t nRecTracks, ichamb;
+ TClonesArray *trackPtr;
+ AliMUONTrackK *trackK;
+
+ //cout << " ******** Enter Recover " << endl;
+ //return;
+ trackPtr = fgEventReconstructor->GetRecTracksPtr();
+
+ // The last hit will be removed
+ nRecTracks = fgEventReconstructor->GetNRecTracks();
+
+ // Check if the track candidate doesn't exist yet
+ for (Int_t i=0; i<nRecTracks; i++) {
+ trackK = (AliMUONTrackK*) ((*trackPtr)[i]);
+ if (trackK->fNTrackHits == 2 && trackK->GetRecover() == 0) continue;
+ if (trackK == this) continue;
+ //if (trackK->GetRecover() != 1) continue;
+ if (trackK->fNTrackHits >= fNTrackHits-1) {
+ for (Int_t j=0; j<fNTrackHits-1; j++) {
+ if ((*trackK->fTrackHitsPtr)[j] != ((*fTrackHitsPtr)[j])) break;
+ return;
+ } // for (Int_t j=0;
+ }
+ } // for (Int_t i=0;
+
+ cout << " ******** Enter Recover " << endl;
+ trackK = new ((*trackPtr)[nRecTracks]) AliMUONTrackK(fStartSegment);
+ fgEventReconstructor->SetNRecTracks(nRecTracks+1);
+ trackK->fRecover = 1;
+ trackK->fSkipHit = (AliMUONHitForRec*) ((*fTrackHitsPtr)[fNTrackHits-1]);
+ trackK->fNTrackHits = fNTrackHits;
+ delete trackK->fTrackHitsPtr; // not efficient ?
+ trackK->fTrackHitsPtr = new TObjArray(*fTrackHitsPtr);
+ cout << nRecTracks << " " << trackK->fRecover << endl;
+
+ // The hit before missing chamber will be removed
+ Int_t ichamBeg = ((AliMUONHitForRec*)((*fTrackHitsPtr)[0]))->GetChamberNumber();
+ Int_t indxSkip = -1;
+ if (ichamBeg == 9) {
+ // segment in the last station
+ // look for the missing chamber
+ for (Int_t i=1; i<fNTrackHits; i++) {
+ ichamb = ((AliMUONHitForRec*)((*fTrackHitsPtr)[i]))->GetChamberNumber();
+ if (TMath::Abs(ichamBeg-ichamb)>1 && i>2) {
+ indxSkip = i;
+ break;
+ }
+ ichamBeg = ichamb;
+ } // for (Int_t i=1;
+ } else {
+ // in the last but one station
+ for (Int_t i=1; i<fNTrackHits; i++) {
+ ichamb = ((AliMUONHitForRec*)((*fTrackHitsPtr)[i]))->GetChamberNumber();
+ if (TMath::Abs(ichamBeg-ichamb)>1 && ichamb<4) {
+ indxSkip = i;
+ break;
+ }
+ ichamBeg = ichamb;
+ } // for (Int_t i=1;
+ }
+ if (indxSkip < 0) return;
+
+ // Check if the track candidate doesn't exist yet
+ for (Int_t i=0; i<nRecTracks; i++) {
+ trackK = (AliMUONTrackK*) ((*trackPtr)[i]);
+ if (trackK->fNTrackHits == 2 && trackK->GetRecover() == 0) continue;
+ if (trackK == this) continue;
+ //if (trackK->GetRecover() != 1) continue;
+ if (trackK->fNTrackHits >= indxSkip-1) {
+ for (Int_t j=0; j<indxSkip-1; j++) {
+ if ((*trackK->fTrackHitsPtr)[j] != ((*fTrackHitsPtr)[j])) break;
+ return;
+ } // for (Int_t j=0;
+ }
+ } // for (Int_t i=0;
+
+ nRecTracks = fgEventReconstructor->GetNRecTracks();
+ trackK = new ((*trackPtr)[nRecTracks]) AliMUONTrackK(fStartSegment);
+ fgEventReconstructor->SetNRecTracks(nRecTracks+1);
+ trackK->fRecover = 2;
+ trackK->fSkipHit = (AliMUONHitForRec*) ((*fTrackHitsPtr)[indxSkip-1]);
+ trackK->fNTrackHits = fNTrackHits;
+ delete trackK->fTrackHitsPtr; // not efficient ?
+ trackK->fTrackHitsPtr = new TObjArray(*fTrackHitsPtr);
+ cout << nRecTracks << " " << trackK->fRecover << endl;
+}
+
+//______________________________________________________________________________
+ void mnvertLocalK(Double_t *a, Int_t l, Int_t, Int_t n, Int_t &ifail)
+{
+//*-*-*-*-*-*-*-*-*-*-*-*Inverts a symmetric matrix*-*-*-*-*-*-*-*-*-*-*-*-*
+//*-* ==========================
+//*-* inverts a symmetric matrix. matrix is first scaled to
+//*-* have all ones on the diagonal (equivalent to change of units)
+//*-* but no pivoting is done since matrix is positive-definite.
+//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
+
+ // taken from TMinuit package of Root (l>=n)
+ // fVERTs, fVERTq and fVERTpp changed to localVERTs, localVERTq and localVERTpp
+ // Double_t localVERTs[n], localVERTq[n], localVERTpp[n];
+ Double_t * localVERTs = new Double_t[n];
+ Double_t * localVERTq = new Double_t[n];
+ Double_t * localVERTpp = new Double_t[n];
+ // fMaxint changed to localMaxint
+ Int_t localMaxint = n;
+
+ /* System generated locals */
+ Int_t aOffset;
+
+ /* Local variables */
+ Double_t si;
+ Int_t i, j, k, kp1, km1;
+
+ /* Parameter adjustments */
+ aOffset = l + 1;
+ a -= aOffset;
+
+ /* Function Body */
+ ifail = 0;
+ if (n < 1) goto L100;
+ if (n > localMaxint) goto L100;
+//*-*- scale matrix by sqrt of diag elements
+ for (i = 1; i <= n; ++i) {
+ si = a[i + i*l];
+ if (si <= 0) goto L100;
+ localVERTs[i-1] = 1 / TMath::Sqrt(si);
+ }
+ for (i = 1; i <= n; ++i) {
+ for (j = 1; j <= n; ++j) {
+ a[i + j*l] = a[i + j*l]*localVERTs[i-1]*localVERTs[j-1];
+ }
+ }
+//*-*- . . . start main loop . . . .
+ for (i = 1; i <= n; ++i) {
+ k = i;
+//*-*- preparation for elimination step1
+ if (a[k + k*l] != 0) localVERTq[k-1] = 1 / a[k + k*l];
+ else goto L100;
+ localVERTpp[k-1] = 1;
+ a[k + k*l] = 0;
+ kp1 = k + 1;
+ km1 = k - 1;
+ if (km1 < 0) goto L100;
+ else if (km1 == 0) goto L50;
+ else goto L40;
+L40:
+ for (j = 1; j <= km1; ++j) {
+ localVERTpp[j-1] = a[j + k*l];
+ localVERTq[j-1] = a[j + k*l]*localVERTq[k-1];
+ a[j + k*l] = 0;
+ }
+L50:
+ if (k - n < 0) goto L51;
+ else if (k - n == 0) goto L60;
+ else goto L100;
+L51:
+ for (j = kp1; j <= n; ++j) {
+ localVERTpp[j-1] = a[k + j*l];
+ localVERTq[j-1] = -a[k + j*l]*localVERTq[k-1];
+ a[k + j*l] = 0;
+ }
+//*-*- elimination proper
+L60:
+ for (j = 1; j <= n; ++j) {
+ for (k = j; k <= n; ++k) { a[j + k*l] += localVERTpp[j-1]*localVERTq[k-1]; }
+ }
+ }
+//*-*- elements of left diagonal and unscaling
+ for (j = 1; j <= n; ++j) {
+ for (k = 1; k <= j; ++k) {
+ a[k + j*l] = a[k + j*l]*localVERTs[k-1]*localVERTs[j-1];
+ a[j + k*l] = a[k + j*l];
+ }
+ }
+ delete localVERTs;
+ delete localVERTq;
+ delete localVERTpp;
+ return;
+//*-*- failure return
+L100:
+ delete localVERTs;
+ delete localVERTq;
+ delete localVERTpp;
+ ifail = 1;
+} /* mnvertLocal */