1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
20 /// \brief Macro for refitting ESD tracks from ESD pads
22 /// \author Philippe Pillot, SUBATECH
24 #if !defined(__CINT__) || defined(__MAKECINT__)
25 #include <TStopwatch.h>
29 #include <Riostream.h>
30 #include <TGeoManager.h>
35 #include "AliESDEvent.h"
36 #include "AliESDMuonTrack.h"
37 #include "AliCDBManager.h"
38 #include "AliGeomManager.h"
41 #include "AliMUONCDB.h"
42 #include "AliMUONRecoParam.h"
43 #include "AliMUONESDInterface.h"
44 #include "AliMUONRefitter.h"
45 #include "AliMUONVDigit.h"
46 #include "AliMUONTrack.h"
47 #include "AliMUONVTrackStore.h"
48 #include "AliMUONTrackParam.h"
51 const Int_t printLevel = 1;
53 TTree* GetESDTree(TFile *esdFile);
55 //-----------------------------------------------------------------------
56 void MUONRefit(Int_t nevents = -1, const char* esdFileNameIn = "AliESDs.root", const char* esdFileNameOut = "AliESDs_New.root",
57 const char* geoFilename = "geometry.root", const char* ocdbPath = "local://$ALICE_ROOT/OCDB")
59 /// Example of muon refitting:
60 /// refit ESD tracks from ESD pads (i.e. re-clusterized the attached ESD clusters);
61 /// reset the charge of the digit using their raw charge before refitting;
62 /// compare results with original ESD tracks;
63 /// write results in a new ESD file
65 // open the ESD file and tree
66 TFile* esdFile = TFile::Open(esdFileNameIn);
67 TTree* esdTree = GetESDTree(esdFile);
69 // create the ESD output file and tree
70 TFile* newESDFile = TFile::Open(esdFileNameOut, "RECREATE");
71 newESDFile->SetCompressionLevel(2);
72 TTree* newESDTree = esdTree->CloneTree(0);
74 // connect ESD event to the ESD tree
75 AliESDEvent* esd = new AliESDEvent();
76 esd->ReadFromTree(esdTree);
79 if (esdTree->GetEvent(0) <= 0) {
80 Error("MUONRefit", "no ESD object found for event 0");
83 Int_t runNumber = esd->GetRunNumber();
85 // Import TGeo geometry
87 AliGeomManager::LoadGeometry(geoFilename);
89 Error("MUONRefit", "getting geometry from file %s failed", "generated/galice.root");
94 // load necessary data from OCDB
95 AliCDBManager::Instance()->SetDefaultStorage(ocdbPath);
96 AliCDBManager::Instance()->SetRun(runNumber);
97 if (!AliMUONCDB::LoadField()) return;
98 if (!AliMUONCDB::LoadMapping(kTRUE)) return;
100 // reconstruction parameters for the refitting
101 AliMUONRecoParam* recoParam = AliMUONRecoParam::GetLowFluxParam();
102 Info("MUONRefit", "\n Reconstruction parameters for refitting:");
103 recoParam->Print("FULL");
105 AliMUONESDInterface esdInterface;
106 AliMUONRefitter refitter(recoParam);
107 refitter.Connect(&esdInterface);
113 // Loop over ESD events
114 if (nevents > 0) nevents = TMath::Min(nevents,(Int_t)esdTree->GetEntries());
115 else nevents = (Int_t)esdTree->GetEntries();
116 for (Int_t iEvent = 0; iEvent < nevents; iEvent++) {
117 if (printLevel>0) cout<<endl<<" ****************event #"<<iEvent+1<<"****************"<<endl;
119 //----------------------------------------------//
120 // -------------- process event --------------- //
121 //----------------------------------------------//
122 // get the ESD of current event
123 esdTree->GetEvent(iEvent);
125 Error("MUONRefit", "no ESD object found for event %d", iEvent);
128 Int_t nTracks = (Int_t)esd->GetNumberOfMuonTracks();
129 if (nTracks < 1) continue;
131 // load the current event
132 esdInterface.LoadEvent(*esd, kFALSE);
134 // loop over digit to modify their charge
135 AliMUONVDigit *digit;
136 TIter next(esdInterface.CreateDigitIterator());
137 while ((digit = static_cast<AliMUONVDigit*>(next()))) {
138 digit->SetCharge(digit->ADC());
139 digit->Calibrated(kFALSE);
142 // refit the tracks from digits
143 AliMUONVTrackStore* newTrackStore = refitter.ReconstructFromDigits();
145 //----------------------------------------------//
146 // ------ fill new ESD and print results ------ //
147 //----------------------------------------------//
148 // loop over the list of ESD tracks
149 TClonesArray *esdTracks = (TClonesArray*) esd->FindListObject("MuonTracks");
150 for (Int_t iTrack = 0; iTrack < nTracks; iTrack++) {
153 AliESDMuonTrack* esdTrack = (AliESDMuonTrack*) esdTracks->UncheckedAt(iTrack);
155 // skip ghost tracks (leave them unchanged in the new ESD file)
156 if (!esdTrack->ContainTrackerData()) continue;
158 // get the corresponding MUON track
159 AliMUONTrack* track = esdInterface.FindTrack(esdTrack->GetUniqueID());
161 // Find the corresponding re-fitted MUON track
162 AliMUONTrack* newTrack = (AliMUONTrack*) newTrackStore->FindObject(esdTrack->GetUniqueID());
164 // replace the content of the current ESD track or remove it if the refitting has failed
166 Double_t vertex[3] = {esdTrack->GetNonBendingCoor(), esdTrack->GetBendingCoor(), esdTrack->GetZ()};
167 AliMUONESDInterface::MUONToESD(*newTrack, *esdTrack, vertex, esdInterface.GetDigits());
169 esdTracks->Remove(esdTrack);
172 // print initial and re-fitted track parameters at first cluster if any
174 cout<<" ----------------track #"<<iTrack+1<<"----------------"<<endl;
175 cout<<"before refit:"<<endl;
176 AliMUONTrackParam *param = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->First();
177 param->Print("FULL");
178 if (printLevel>1) param->GetCovariances().Print();
179 if (!newTrack) continue;
180 cout<<"after refit:"<<endl;
181 param = (AliMUONTrackParam*) newTrack->GetTrackParamAtCluster()->First();
182 param->Print("FULL");
183 if (printLevel>1) param->GetCovariances().Print();
184 cout<<" ----------------------------------------"<<endl;
190 delete newTrackStore;
192 // fill new ESD tree with new tracks
193 esdTracks->Compress();
196 if (printLevel>0) cout<<" ****************************************"<<endl;
202 // write output ESD tree
213 cout<<endl<<"time to refit: R:"<<timer.RealTime()<<" C:"<<timer.CpuTime()<<endl<<endl;
216 //-----------------------------------------------------------------------
217 TTree* GetESDTree(TFile *esdFile)
219 /// Check that the file is properly open
220 /// Return pointer to the ESD Tree
222 if (!esdFile || !esdFile->IsOpen()) {
223 Error("GetESDTree", "opening ESD file failed");
227 TTree* tree = (TTree*) esdFile->Get("esdTree");
229 Error("GetESDTree", "no ESD tree found");