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 "AliMagFMaps.h"
36 #include "AliTracker.h"
37 #include "AliESDEvent.h"
38 #include "AliESDMuonTrack.h"
39 #include "AliRecoParam.h"
40 #include "AliCDBManager.h"
41 #include "AliGeomManager.h"
45 #include "AliMUONRecoParam.h"
46 #include "AliMUONESDInterface.h"
47 #include "AliMUONRefitter.h"
48 #include "AliMUONVDigit.h"
49 #include "AliMUONVCluster.h"
50 #include "AliMUONVClusterStore.h"
51 #include "AliMUONTrack.h"
52 #include "AliMUONVTrackStore.h"
53 #include "AliMUONTrackParam.h"
54 #include "AliMUONTrackExtrap.h"
57 const Int_t printLevel = 1;
60 TTree* GetESDTree(TFile *esdFile);
62 //-----------------------------------------------------------------------
63 void MUONRefit(Int_t nevents = -1, const char* esdFileNameIn = "AliESDs.root", const char* esdFileNameOut = "AliESDs_New.root")
65 /// refit ESD tracks from ESD pads (i.e. re-clusterized the attached ESD clusters);
66 /// reset the charge of the digit using their raw charge before refitting;
67 /// compare results with original ESD tracks;
68 /// write results in a new ESD file
70 // prepare the refitting
73 AliMUONESDInterface esdInterface;
74 AliMUONRefitter refitter;
75 refitter.Connect(&esdInterface);
77 // open the ESD file and tree
78 TFile* esdFile = TFile::Open(esdFileNameIn);
79 TTree* esdTree = GetESDTree(esdFile);
81 // create the ESD output tree
83 TTree* newESDTree = esdTree->CloneTree(0);
85 // connect ESD event to the ESD tree
86 AliESDEvent* esd = new AliESDEvent();
87 esd->ReadFromTree(esdTree);
92 // Loop over ESD events
93 if (nevents > 0) nevents = TMath::Min(nevents,(Int_t)esdTree->GetEntries());
94 else nevents = (Int_t)esdTree->GetEntries();
95 for (Int_t iEvent = 0; iEvent < nevents; iEvent++) {
96 if (printLevel>0) cout<<endl<<" ****************event #"<<iEvent+1<<"****************"<<endl;
98 //----------------------------------------------//
99 // -------------- process event --------------- //
100 //----------------------------------------------//
101 // get the ESD of current event
102 esdTree->GetEvent(iEvent);
104 Error("CheckESD", "no ESD object found for event %d", iEvent);
107 Int_t nTracks = (Int_t)esd->GetNumberOfMuonTracks();
108 if (nTracks < 1) continue;
110 // load the current event
111 esdInterface.LoadEvent(*esd);
113 // loop over digit to modify their charge
114 AliMUONVDigit *digit;
115 TIter next(esdInterface.CreateDigitIterator());
116 while ((digit = static_cast<AliMUONVDigit*>(next()))) digit->SetCharge(digit->ADC());
118 // refit the tracks from digits
119 AliMUONVTrackStore* newTrackStore = refitter.ReconstructFromDigits();
121 //----------------------------------------------//
122 // ------ fill new ESD and print results ------ //
123 //----------------------------------------------//
124 // loop over the list of ESD tracks
125 TClonesArray *esdTracks = (TClonesArray*) esd->FindListObject("MuonTracks");
126 for (Int_t iTrack = 0; iTrack < nTracks; iTrack++) {
129 AliESDMuonTrack* esdTrack = (AliESDMuonTrack*) esdTracks->UncheckedAt(iTrack);
130 // get the corresponding MUON track
131 AliMUONTrack* track = esdInterface.FindTrack(esdTrack->GetUniqueID());
132 // Find the corresponding re-fitted MUON track
133 AliMUONTrack* newTrack = (AliMUONTrack*) newTrackStore->FindObject(esdTrack->GetUniqueID());
135 // replace the content of the current ESD track or remove it if the refitting has failed
137 Double_t vertex[3] = {esdTrack->GetNonBendingCoor(), esdTrack->GetBendingCoor(), esdTrack->GetZ()};
138 AliMUONESDInterface::MUONToESD(*newTrack, *esdTrack, vertex, esdInterface.GetDigits());
140 esdTracks->Remove(esdTrack);
143 // print initial and re-fitted track parameters at first cluster if any
145 cout<<" ----------------track #"<<iTrack+1<<"----------------"<<endl;
146 cout<<"before refit:"<<endl;
147 AliMUONTrackParam *param = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->First();
148 param->Print("FULL");
149 if (printLevel>1) param->GetCovariances().Print();
150 if (!newTrack) continue;
151 cout<<"after refit:"<<endl;
152 param = (AliMUONTrackParam*) newTrack->GetTrackParamAtCluster()->First();
153 param->Print("FULL");
154 if (printLevel>1) param->GetCovariances().Print();
155 cout<<" ----------------------------------------"<<endl;
161 delete newTrackStore;
163 // fill new ESD tree with new tracks
164 esdTracks->Compress();
167 if (printLevel>0) cout<<" ****************************************"<<endl;
173 // write output ESD tree
174 TFile* newESDFile = TFile::Open(esdFileNameOut, "RECREATE");
175 newESDFile->SetCompressionLevel(2);
184 cout<<endl<<"time to refit: R:"<<timer.RealTime()<<" C:"<<timer.CpuTime()<<endl<<endl;
187 //-----------------------------------------------------------------------
190 /// Set the geometry, the magnetic field, the mapping and the reconstruction parameters
192 // Import TGeo geometry (needed by AliMUONTrackExtrap::ExtrapToVertex)
194 AliGeomManager::LoadGeometry("geometry.root");
196 Error("MUONRefit", "getting geometry from file %s failed", "generated/galice.root");
202 printf("Loading field map...\n");
203 AliMagFMaps* field = new AliMagFMaps("Maps","Maps", 1, 1., 10., AliMagFMaps::k5kG);
204 AliTracker::SetFieldMap(field, kFALSE);
205 AliMUONTrackExtrap::SetField(AliTracker::GetFieldMap());
208 AliCDBManager* man = AliCDBManager::Instance();
209 man->SetDefaultStorage("local://$ALICE_ROOT");
211 if ( ! AliMpCDB::LoadDDLStore() ) {
212 Error("MUONRefit","Could not access mapping from OCDB !");
216 // set reconstruction parameters
217 AliMUONRecoParam *muonRecoParam = AliMUONRecoParam::GetLowFluxParam();
218 muonRecoParam->CombineClusterTrackReco(kFALSE);
219 muonRecoParam->Print("FULL");
220 AliRecoParam::Instance()->RegisterRecoParam(muonRecoParam);
224 //-----------------------------------------------------------------------
225 TTree* GetESDTree(TFile *esdFile)
227 /// Check that the file is properly open
228 /// Return pointer to the ESD Tree
230 if (!esdFile || !esdFile->IsOpen()) {
231 Error("GetESDTree", "opening ESD file failed");
235 TTree* tree = (TTree*) esdFile->Get("esdTree");
237 Error("GetESDTree", "no ESD tree found");