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()))) {
117 digit->SetCharge(digit->ADC());
118 digit->Calibrated(kFALSE);
121 // refit the tracks from digits
122 AliMUONVTrackStore* newTrackStore = refitter.ReconstructFromDigits();
124 //----------------------------------------------//
125 // ------ fill new ESD and print results ------ //
126 //----------------------------------------------//
127 // loop over the list of ESD tracks
128 TClonesArray *esdTracks = (TClonesArray*) esd->FindListObject("MuonTracks");
129 for (Int_t iTrack = 0; iTrack < nTracks; iTrack++) {
132 AliESDMuonTrack* esdTrack = (AliESDMuonTrack*) esdTracks->UncheckedAt(iTrack);
134 // skip ghost tracks (leave them unchanged in the new ESD file)
135 if (!esdTrack->ContainTrackerData()) continue;
137 // get the corresponding MUON track
138 AliMUONTrack* track = esdInterface.FindTrack(esdTrack->GetUniqueID());
140 // Find the corresponding re-fitted MUON track
141 AliMUONTrack* newTrack = (AliMUONTrack*) newTrackStore->FindObject(esdTrack->GetUniqueID());
143 // replace the content of the current ESD track or remove it if the refitting has failed
145 Double_t vertex[3] = {esdTrack->GetNonBendingCoor(), esdTrack->GetBendingCoor(), esdTrack->GetZ()};
146 AliMUONESDInterface::MUONToESD(*newTrack, *esdTrack, vertex, esdInterface.GetDigits());
148 esdTracks->Remove(esdTrack);
151 // print initial and re-fitted track parameters at first cluster if any
153 cout<<" ----------------track #"<<iTrack+1<<"----------------"<<endl;
154 cout<<"before refit:"<<endl;
155 AliMUONTrackParam *param = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->First();
156 param->Print("FULL");
157 if (printLevel>1) param->GetCovariances().Print();
158 if (!newTrack) continue;
159 cout<<"after refit:"<<endl;
160 param = (AliMUONTrackParam*) newTrack->GetTrackParamAtCluster()->First();
161 param->Print("FULL");
162 if (printLevel>1) param->GetCovariances().Print();
163 cout<<" ----------------------------------------"<<endl;
169 delete newTrackStore;
171 // fill new ESD tree with new tracks
172 esdTracks->Compress();
175 if (printLevel>0) cout<<" ****************************************"<<endl;
181 // write output ESD tree
182 TFile* newESDFile = TFile::Open(esdFileNameOut, "RECREATE");
183 newESDFile->SetCompressionLevel(2);
192 cout<<endl<<"time to refit: R:"<<timer.RealTime()<<" C:"<<timer.CpuTime()<<endl<<endl;
195 //-----------------------------------------------------------------------
198 /// Set the geometry, the magnetic field, the mapping and the reconstruction parameters
200 // Import TGeo geometry (needed by AliMUONTrackExtrap::ExtrapToVertex)
202 AliGeomManager::LoadGeometry("geometry.root");
204 Error("MUONRefit", "getting geometry from file %s failed", "generated/galice.root");
210 printf("Loading field map...\n");
211 AliMagFMaps* field = new AliMagFMaps("Maps","Maps", 1, 1., 10., AliMagFMaps::k5kG);
212 AliTracker::SetFieldMap(field, kFALSE);
213 AliMUONTrackExtrap::SetField(AliTracker::GetFieldMap());
216 AliCDBManager* man = AliCDBManager::Instance();
217 man->SetDefaultStorage("local://$ALICE_ROOT");
219 if ( ! AliMpCDB::LoadDDLStore() ) {
220 Error("MUONRefit","Could not access mapping from OCDB !");
224 // set reconstruction parameters
225 AliMUONRecoParam *muonRecoParam = AliMUONRecoParam::GetLowFluxParam();
226 muonRecoParam->CombineClusterTrackReco(kFALSE);
227 muonRecoParam->Print("FULL");
228 AliRecoParam::Instance()->RegisterRecoParam(muonRecoParam);
232 //-----------------------------------------------------------------------
233 TTree* GetESDTree(TFile *esdFile)
235 /// Check that the file is properly open
236 /// Return pointer to the ESD Tree
238 if (!esdFile || !esdFile->IsOpen()) {
239 Error("GetESDTree", "opening ESD file failed");
243 TTree* tree = (TTree*) esdFile->Get("esdTree");
245 Error("GetESDTree", "no ESD tree found");