29 #include "AliGeomManager.h"
30 #include "AliESDEvent.h"
31 #include "AliESDMuonTrack.h"
32 #include "AliESDMuonGlobalTrack.h"
36 #include "AliRunLoader.h"
37 #include "AliHeader.h"
38 #include "AliGenEventHeader.h"
60 fNPlanesMFTAnalyzed(0),
62 fScaleSigmaClusterCut(1.),
63 fNMaxMissingMFTClusters(0),
64 fGlobalTrackingDiverged(kFALSE),
68 fFinalBestCandidate(0),
72 fXExtrapVertexError(0),
73 fYExtrapVertexError(0),
74 fBransonCorrection(kFALSE)
82 fSegmentation = fMFT->GetSegmentation();
86 AliInfo(Form(
"fMFT = %p, fSegmentation = %p", fMFT, fSegmentation));
88 for (Int_t iPlane=0; iPlane<fNPlanesMFT; iPlane++) {
89 fMFTClusterArray[iPlane] =
new TClonesArray(
"AliMFTCluster");
90 fMFTClusterArrayFront[iPlane] =
new TClonesArray(
"AliMFTCluster");
91 fMFTClusterArrayBack[iPlane] =
new TClonesArray(
"AliMFTCluster");
92 fMFTClusterArray[iPlane] -> SetOwner(kTRUE);
93 fMFTClusterArrayFront[iPlane] -> SetOwner(kTRUE);
94 fMFTClusterArrayBack[iPlane] -> SetOwner(kTRUE);
95 fMinResearchRadiusAtPlane[iPlane] = 0.;
98 fCandidateTracks =
new TClonesArray(
"AliMuonForwardTrack",50000);
108 for (Int_t iPlane=0; iPlane<
fNPlanesMFT; iPlane++) {
127 for (Int_t iPlane=0; iPlane<
fNPlanesMFT; iPlane++) {
128 AliDebug(1, Form(
"Setting Address for Branch Plane_%02d", iPlane));
129 cTree->SetBranchAddress(Form(
"Plane_%02d",iPlane), &
fMFTClusterArray[iPlane]);
132 if (!cTree->GetEvent())
return kFALSE;
133 for (Int_t iPlane=0; iPlane<
fNPlanesMFT; iPlane++) {
134 AliInfo(Form(
"plane %02d: nClusters = %d\n", iPlane,
fMFTClusterArray[iPlane]->GetEntries()));
154 for (Int_t iPlane=0; iPlane<
fNPlanesMFT; iPlane++) {
173 TFile *outputFileMuonGlobalTracks =
new TFile(
"MuonGlobalTracks.root",
"update");
174 TTree *outputTreeMuonGlobalTracks =
new TTree(
"AliMuonForwardTracks",
"Tree of AliMuonForwardTracks");
175 TClonesArray *muonForwardTracks =
new TClonesArray(
"AliMuonForwardTrack");
176 outputTreeMuonGlobalTracks -> Branch(
"tracks", &muonForwardTracks);
190 const AliESDVertex* esdVert = fESD->GetVertex();
191 if (esdVert->GetNContributors() > 0 || !strcmp(esdVert->GetTitle(),
"vertexer: smearMC")) {
192 fXExtrapVertex = esdVert->GetX();
193 fYExtrapVertex = esdVert->GetY();
194 fZExtrapVertex = esdVert->GetZ();
197 AliInfo(Form(
"Found ESD vertex from %d contributors (%f +/- %f, %f +/- %f, %f)",
204 Int_t nTracksMUON =
event->GetNumberOfMuonTracks();
206 AliInfo(Form(
"Number of ESD MUON tracks: %d\n", nTracksMUON));
209 while (iTrack<nTracksMUON) {
211 fNPlanesMFTAnalyzed = 0;
213 AliInfo(
"****************************************************************************************");
214 AliInfo(Form(
"*************************** MUON TRACK %3d/%d ***************************************", iTrack, nTracksMUON));
215 AliInfo(
"****************************************************************************************");
217 fCandidateTracks -> Delete();
219 fNPlanesMFTAnalyzed = 0;
221 const AliESDMuonTrack *esdTrack =
event->GetMuonTrack(iTrack);
227 if (!fMUONTrack->GetTrackParamAtCluster()->First()) {
228 AliInfo(
"Skipping track, no parameters available!!!");
236 track -> SetMCLabel(fMUONTrack->GetMCLabel());
237 track -> SetMatchTrigger(fMUONTrack->GetMatchTrigger());
242 Double_t xEndOfAbsorber = trackParamEndOfAbsorber.GetNonBendingCoor();
243 Double_t yEndOfAbsorber = trackParamEndOfAbsorber.GetBendingCoor();
244 Double_t rAbsorber = TMath::Sqrt(xEndOfAbsorber*xEndOfAbsorber + yEndOfAbsorber*yEndOfAbsorber);
245 track -> SetRAtAbsorberEnd(rAbsorber);
249 for (Int_t iPlane=fNPlanesMFT-1; iPlane>=0; iPlane--) {
255 fNPlanesMFTAnalyzed++;
257 Int_t nCandidates = fCandidateTracks->GetEntriesFast();
258 for (Int_t iCandidate=0; iCandidate<nCandidates; iCandidate++) {
260 if (!(fCandidateTracks->UncheckedAt(iCandidate)))
continue;
270 if ((fNPlanesMFTAnalyzed-fCurrentTrack->GetNMFTClusters())>fNMaxMissingMFTClusters ||
fIsPlaneMandatory[iPlane]) {
271 fCandidateTracks->Remove(fCurrentTrack);
275 if (fScaleSigmaClusterCut>0) fScaleSigmaClusterCut -= 0.1;
279 fCandidateTracks->Compress();
286 fScaleSigmaClusterCut = 1.0;
288 AliDebug(1,
"Finished cycle over planes");
294 Int_t nFinalTracks = fCandidateTracks->GetEntriesFast();
295 AliInfo(Form(
"nFinalTracks = %d", nFinalTracks));
297 Int_t nGoodClustersBestCandidate = 0;
298 Int_t idBestCandidate = 0;
299 Double_t bestChi2 = -1.;
301 for (Int_t iFinalCandidate=0; iFinalCandidate<nFinalTracks; iFinalCandidate++) {
303 if (!(fCandidateTracks->UncheckedAt(iFinalCandidate)))
continue;
305 Int_t nMFTClusters = finalTrack->GetNMFTClusters();
308 for (Int_t iCluster=0; iCluster<nMFTClusters; iCluster++) {
309 AliMFTCluster *localCluster = finalTrack->GetMFTCluster(iCluster);
312 chi2 /= nMFTClusters;
316 if (chi2<bestChi2 || bestChi2<0) {
318 idBestCandidate = iFinalCandidate;
326 newTrack -> SetNWrongClustersMC(newTrack->GetNMFTClusters() - nGoodClustersBestCandidate);
328 new ((*muonForwardTracks)[muonForwardTracks->GetEntries()])
AliMuonForwardTrack(*newTrack);
334 AliDebug(2,
"Creating a new Muon Global Track");
335 AliESDMuonGlobalTrack *myESDTrack =
event->NewMuonGlobalTrack();
336 myESDTrack -> SetPxPyPz(newTrack->Px(), newTrack->Py(), newTrack->Pz());
338 myESDTrack -> SetLabel(newTrack->
GetMCLabel());
339 myESDTrack -> SetChi2OverNdf(newTrack->GetChi2OverNdf());
340 myESDTrack -> SetCharge(newTrack->GetCharge());
342 myESDTrack -> SetNMFTClusters(newTrack->GetNMFTClusters());
343 myESDTrack -> SetNWrongMFTClustersMC(newTrack->GetNWrongClustersMC());
344 myESDTrack -> SetFirstTrackingPoint(newTrack->GetMFTCluster(0)->GetX(), newTrack->GetMFTCluster(0)->GetY(), newTrack->GetMFTCluster(0)->GetZ());
346 myESDTrack -> SetRAtAbsorberEnd(newTrack->GetRAtAbsorberEnd());
347 myESDTrack -> SetCovariances(newTrack->GetTrackParamAtMFTCluster(0)->GetCovariances());
348 myESDTrack -> SetChi2MatchTrigger(esdTrack->GetChi2MatchTrigger());
349 myESDTrack -> SetMuonClusterMap(esdTrack->GetMuonClusterMap());
350 myESDTrack -> SetHitsPatternInTrigCh(esdTrack->GetHitsPatternInTrigCh());
351 myESDTrack -> SetHitsPatternInTrigChTrk(esdTrack->GetHitsPatternInTrigChTrk());
352 myESDTrack -> Connected(esdTrack->IsConnected());
354 ULong_t mftClusterPattern = 0;
355 for (Int_t iCluster=0; iCluster<newTrack->GetNMFTClusters(); iCluster++) {
356 AliMFTCluster *localCluster = newTrack->GetMFTCluster(iCluster);
357 mftClusterPattern |= 1 << localCluster->
GetPlane();
360 myESDTrack -> SetMFTClusterPattern(mftClusterPattern);
366 fFinalBestCandidate = NULL;
370 outputTreeMuonGlobalTracks -> Fill();
373 while (outputFileMuonGlobalTracks->cd(Form(
"Event%d",myEventID))) myEventID++;
374 outputFileMuonGlobalTracks -> mkdir(Form(
"Event%d",myEventID));
375 outputFileMuonGlobalTracks -> cd(Form(
"Event%d",myEventID));
376 outputTreeMuonGlobalTracks -> Write();
377 outputFileMuonGlobalTracks -> Close();
379 muonForwardTracks -> Delete();
380 delete muonForwardTracks;
545 AliDebug(3,Form(
"dX = %f, dY = %f\n", dX, dY));
549 Double_t sigmaX2 = kParamCov(0,0) + cluster->
GetErrX2();
550 Double_t sigmaY2 = kParamCov(2,2) + cluster->
GetErrY2();
551 AliDebug(3, Form(
"dX2 = %f, dY2 = %f\n", sigmaX2, sigmaY2));
552 Double_t covXY = kParamCov(0,2);
553 Double_t det = sigmaX2 * sigmaY2 - covXY * covXY;
556 if (det==0.)
return 1.e10;
557 return (dX*dX*sigmaY2 + dY*dY*sigmaX2 - 2.*dX*dY*covXY) / det;
565 Bool_t result = kFALSE;
569 for (Int_t iTrack=0; iTrack<cluster->
GetNMCTracks(); iTrack++) {
586 AliError(
"no run loader found in file galice.root");
590 runLoader->CdGAFile();
591 runLoader->LoadgAlice();
592 runLoader->LoadHeader();
593 runLoader->GetEvent(
gAlice->GetEvNumber());
596 runLoader->GetHeader()->GenEventHeader()->PrimaryVertex(vtx);
597 AliInfo(Form(
"Primary vertex from MC found in (%f, %f, %f)\n",vtx[0], vtx[1], vtx[2]));
604 AliInfo(Form(
"Set ESD vertex from MC (%f +/- %f, %f +/- %f, %f)",
605 fXExtrapVertex,fXExtrapVertexError,fYExtrapVertex,fYExtrapVertexError,fZExtrapVertex));
613 AliInfo(
"Adding clusters from underlying event");
617 TGrid::Connect(
"alien://");
619 TFile* fileWithClustersToAdd =
TFile::Open(fMFT->GetFileNameForUnderlyingEvent());
620 if (!fileWithClustersToAdd)
return;
621 if (!(fileWithClustersToAdd->IsOpen()))
return;
622 if (!(fileWithClustersToAdd->cd(Form(
"Event%d",fMFT->GetUnderlyingEventID()))))
return;
629 treeIn = (TTree*) gDirectory->Get(
"TreeR");
631 for (Int_t iPlane=0; iPlane<
fNPlanesMFT; iPlane++) {
632 if (!(treeIn->GetBranch(Form(
"Plane_%02d",iPlane)))) {
636 else treeIn->SetBranchAddress(Form(
"Plane_%02d",iPlane), &(recPointsPerPlaneToAdd[iPlane]));
639 treeIn -> GetEntry(0);
641 for (Int_t iPlane=0; iPlane<
fNPlanesMFT; iPlane++) {
643 Int_t nClusters = recPointsPerPlaneToAdd[iPlane]->GetEntries();
644 for (Int_t iCluster=0; iCluster<nClusters; iCluster++) {
660 AliInfo(
"Adding clusters from pile-up event(s)");
664 TGrid::Connect(
"alien://");
666 TFile* fileWithClustersToAdd =
TFile::Open(fMFT->GetFileNameForPileUpEvents());
667 if (!fileWithClustersToAdd)
return;
668 if (!(fileWithClustersToAdd->IsOpen()))
return;
675 if (!(fileWithClustersToAdd->cd(Form(
"Event%d",fMFT->GetPileUpEventID(iPileUp)))))
continue;
679 treeIn = (TTree*) gDirectory->Get(
"TreeR");
681 for (Int_t iPlane=0; iPlane<
fNPlanesMFT; iPlane++) {
682 if (!(treeIn->GetBranch(Form(
"Plane_%02d",iPlane)))) {
686 else treeIn->SetBranchAddress(Form(
"Plane_%02d",iPlane), &(recPointsPerPlaneToAdd[iPlane]));
689 treeIn -> GetEntry(0);
691 for (Int_t iPlane=0; iPlane<
fNPlanesMFT; iPlane++) {
693 Int_t nClusters = recPointsPerPlaneToAdd[iPlane]->GetEntries();
694 for (Int_t iCluster=0; iCluster<nClusters; iCluster++) {
static const Double_t fYVertexTolerance
static Double_t AbsZEnd()
Return z-position of absorber end.
printf("Chi2/npoints = %f\n", TMath::Sqrt(chi2/npoints))
static void ESDToMUON(const AliESDMuonTrack &esdTrack, AliMUONTrack &track, Bool_t refit=kTRUE)
TFile * Open(const char *filename, Long64_t &nevents)
TClonesArray * fMFTClusterArray[fNMaxPlanes]
static const Double_t fPrimaryVertexResY
Int_t GetMatchTrigger(void) const
return 1,2,3 if track matches with trigger track, 0 if not
Double_t GetBendingCoor() const
return bending coordinate (cm)
Bool_t fIsPlaneMandatory[fNMaxPlanes]
void AddClustersFromUnderlyingEvent()
static const Double_t fPrimaryVertexResX
static const Int_t fNMaxPlanes
Track parameters in ALICE dimuon spectrometer.
static const Int_t fNMaxPlanes
Double_t GetErrX2() const
void SetMCLabel(Int_t track, Int_t labelMC)
Double_t TryOneCluster(const AliMUONTrackParam &trackParam, AliMFTCluster *cluster)
Int_t GetNMCTracks() const
void SeparateFrontBackClusters()
static const Int_t fLabelOffsetMC
TClonesArray * fMFTClusterArrayFront[fNMaxPlanes]
array of clusters for the planes of the MFT
static const Double_t fZEvalKinem
Int_t GetMCLabel() const
return the corresponding MC track number
Int_t LoadClusters(TTree *cf)
Double_t GetErrY2() const
static const Double_t fPrimaryVertexResZ
void AddClustersFromPileUpEvents()
Double_t fXExtrapVertexError
Constants for the Muon Forward Tracker.
static const Double_t fXVertexTolerance
static const Int_t fNMaxPileUpEvents
TClonesArray * fMFTClusterArrayBack[fNMaxPlanes]
array of front clusters for the planes of the MFT
Double_t fYExtrapVertexError
Double_t GetNonBendingCoor() const
return non bending coordinate (cm)
Bool_t IsCorrectMatch(AliMFTCluster *cluster, Int_t labelMC)
Bool_t fGlobalTrackingDiverged
Int_t FindClusterInPlane(Int_t planeId)
Reconstructed track in ALICE dimuon spectrometer.
TClonesArray * fCandidateTracks
array of back clusters for the planes of the MFT
static const Int_t kNDisks
Number of Disk.
AliMUONTrack * fMUONTrack
array of candidate global tracks
Int_t GetMCLabel(Int_t track) const
const TMatrixD & GetCovariances() const
Int_t Clusters2Tracks(AliESDEvent *event)
Double_t fXExtrapVertex
best final candidate (if any)
virtual ~AliMFTTrackerMU()
ALICE muon forward track, combining the information of the Muon Spectrometer and the Muon Forward Tra...