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 **************************************************************************/
19 /// \file MUONClusterInfo.C
20 /// \brief Macro to fill AliMUONClusterInfo objects
22 /// \author Philippe Pillot, SUBATECH
24 #if !defined(__CINT__) || defined(__MAKECINT__)
25 #include <TStopwatch.h>
27 #include <TClonesArray.h>
30 #include <Riostream.h>
31 #include <TGeoManager.h>
36 #include "AliMagFMaps.h"
37 #include "AliTracker.h"
38 #include "AliESDEvent.h"
39 #include "AliESDMuonTrack.h"
40 #include "AliRecoParam.h"
41 #include "AliCDBManager.h"
42 #include "AliGeomManager.h"
46 #include "AliMpSegmentation.h"
47 #include "AliMpVSegmentation.h"
49 #include "AliMUONCalibrationData.h"
50 #include "AliMUONVCalibParam.h"
51 #include "AliMUONPadInfo.h"
52 #include "AliMUONClusterInfo.h"
53 #include "AliMUONRecoParam.h"
54 #include "AliMUONESDInterface.h"
55 #include "AliMUONRefitter.h"
56 #include "AliMUONVDigit.h"
57 #include "AliMUONVDigitStore.h"
58 #include "AliMUONVCluster.h"
59 #include "AliMUONVClusterStore.h"
60 #include "AliMUONTrack.h"
61 #include "AliMUONVTrackStore.h"
62 #include "AliMUONTrackParam.h"
63 #include "AliMUONTrackExtrap.h"
66 const Int_t printLevel = 1;
69 TTree* GetESDTree(TFile *esdFile);
71 //-----------------------------------------------------------------------
72 void MUONClusterInfo(Int_t nevents = -1, const char* esdFileName = "AliESDs.root", const char* outFileName = "clusterInfo.root")
74 /// refit ESD tracks from ESD clusters to get track parameters at each attached cluster;
75 /// fill AliMUONESDClusterInfo object with ESD cluster + corresponding track parameters;
76 /// write results in a new root file.
78 AliMUONClusterInfo* clusterInfo = new AliMUONClusterInfo();
79 AliMUONPadInfo padInfo;
80 AliMUONCalibrationData* calibData = 0x0;
82 // prepare the refitting
85 AliMUONESDInterface esdInterface;
86 AliMUONRefitter refitter;
87 refitter.Connect(&esdInterface);
89 // open the ESD file and tree and connect the ESD event
90 TFile* esdFile = TFile::Open(esdFileName);
91 TTree* esdTree = GetESDTree(esdFile);
92 AliESDEvent* esd = new AliESDEvent();
93 esd->ReadFromTree(esdTree);
95 // prepare the output tree
97 TFile* clusterInfoFile = TFile::Open(outFileName, "RECREATE");
98 clusterInfoFile->SetCompressionLevel(1);
100 TTree* clusterInfoTree = new TTree("clusterInfoTree","clusterInfoTree");
101 clusterInfoTree->Branch("clusterInfo", &clusterInfo, 32000, 99);
106 // Loop over ESD events
107 if (nevents > 0) nevents = TMath::Min(nevents,(Int_t)esdTree->GetEntries());
108 else nevents = (Int_t)esdTree->GetEntries();
109 for (Int_t iEvent = 0; iEvent < nevents; iEvent++) {
111 //----------------------------------------------//
112 // -------------- process event --------------- //
113 //----------------------------------------------//
114 // get the ESD of current event
115 esdTree->GetEvent(iEvent);
117 Error("CheckESD", "no ESD object found for event %d", iEvent);
120 Int_t nTracks = (Int_t)esd->GetNumberOfMuonTracks();
121 if (nTracks < 1) continue;
123 // prepare access to calibration data
124 if (!calibData) calibData = new AliMUONCalibrationData(esd->GetESDRun()->GetRunNumber());
126 // load the current event
127 esdInterface.LoadEvent(*esd);
130 AliMUONVDigitStore* digitStore = esdInterface.GetDigits();
132 // refit the tracks from clusters
133 AliMUONVTrackStore* newTrackStore = refitter.ReconstructFromClusters();
135 //----------------------------------------------//
136 // ------------- fill cluster info ------------ //
137 //----------------------------------------------//
138 // loop over the refitted tracks
139 TIter nextTrack(newTrackStore->CreateIterator());
140 AliMUONTrack* newTrack;
141 while ((newTrack = static_cast<AliMUONTrack*>(nextTrack()))) {
143 // loop over clusters
144 AliMUONTrackParam* trackParam = static_cast<AliMUONTrackParam*>(newTrack->GetTrackParamAtCluster()->First());
146 clusterInfo->Clear("C");
149 AliMUONVCluster* cluster = trackParam->GetClusterPtr();
150 clusterInfo->SetEventId(iEvent);
151 clusterInfo->SetZ(cluster->GetZ());
152 clusterInfo->SetClusterId(cluster->GetUniqueID());
153 clusterInfo->SetClusterXY(cluster->GetX(), cluster->GetY());
154 clusterInfo->SetClusterXYErr(cluster->GetErrX(), cluster->GetErrY());
155 clusterInfo->SetClusterChi2(cluster->GetChi2());
156 clusterInfo->SetClusterCharge(cluster->GetCharge());
159 clusterInfo->SetTrackId(newTrack->GetUniqueID());
160 clusterInfo->SetTrackXY(trackParam->GetNonBendingCoor(), trackParam->GetBendingCoor());
161 clusterInfo->SetTrackThetaXY(TMath::ATan(trackParam->GetBendingSlope()), TMath::ATan(trackParam->GetNonBendingSlope()));
162 clusterInfo->SetTrackP(trackParam->P());
163 const TMatrixD paramCov = trackParam->GetCovariances();
164 clusterInfo->SetTrackXYErr(TMath::Sqrt(paramCov(0,0)), TMath::Sqrt(paramCov(2,2)));
165 clusterInfo->SetTrackChi2(newTrack->GetNormalizedChi2());
166 clusterInfo->SetTrackCharge((Short_t)trackParam->GetCharge());
168 // fill pad info if available
169 for (Int_t i=0; i<cluster->GetNDigits(); i++) {
170 AliMUONVDigit* digit = digitStore->FindObject(cluster->GetDigitId(i));
171 if (!digit) continue;
174 const AliMpVSegmentation* seg = AliMpSegmentation::Instance()->
175 GetMpSegmentation(digit->DetElemId(),AliMp::GetCathodType(digit->Cathode()));
176 AliMpPad pad = seg->PadByIndices(AliMpIntPair(digit->PadX(), digit->PadY()));
178 // calibration parameters
179 AliMUONVCalibParam* ped = calibData->Pedestals(digit->DetElemId(), digit->ManuId());
180 AliMUONVCalibParam* gain = calibData->Gains(digit->DetElemId(), digit->ManuId());
181 Int_t manuChannel = digit->ManuChannel();
184 padInfo.SetPadId(digit->GetUniqueID());
185 padInfo.SetPadXY(pad.Position().X(), pad.Position().Y());
186 padInfo.SetPadDimXY(pad.Dimensions().X(), pad.Dimensions().Y());
187 padInfo.SetPadCharge((Double_t)digit->Charge());
188 padInfo.SetPadADC(digit->ADC());
189 padInfo.SetSaturated(digit->IsSaturated());
190 padInfo.SetCalibrated(digit->IsCalibrated());
191 padInfo.SetPedestal(ped->ValueAsFloatFast(manuChannel,0), ped->ValueAsFloatFast(manuChannel,1));
192 padInfo.SetGain(gain->ValueAsFloatFast(manuChannel,0), gain->ValueAsFloatFast(manuChannel,1),
193 gain->ValueAsFloatFast(manuChannel,2), gain->ValueAsFloatFast(manuChannel,3));
195 clusterInfo->AddPad(padInfo);
198 // fill cluster info tree
199 clusterInfoTree->Fill();
201 trackParam = static_cast<AliMUONTrackParam*>(newTrack->GetTrackParamAtCluster()->After(trackParam));
207 delete newTrackStore;
212 printf("Writing Tree\n");
214 clusterInfoFile->cd();
215 clusterInfoTree->Write();
216 printf("Deleting Tree\n");
217 delete clusterInfoTree;
218 printf("Closing File\n");
219 clusterInfoFile->Close();
222 printf("Deleting calibData\n");
224 printf("Deleting clusterInfo\n");
226 printf("Closing esdFile\n");
228 printf("Deleting esd\n");
231 cout<<endl<<"time to fill cluster/track info: R:"<<timer.RealTime()<<" C:"<<timer.CpuTime()<<endl<<endl;
234 //-----------------------------------------------------------------------
237 /// Set the geometry, the magnetic field, the mapping and the reconstruction parameters
239 // Import TGeo geometry (needed by AliMUONTrackExtrap::ExtrapToVertex)
241 AliGeomManager::LoadGeometry("geometry.root");
243 Error("MUONRefit", "getting geometry from file %s failed", "generated/galice.root");
249 printf("Loading field map...\n");
250 AliMagFMaps* field = new AliMagFMaps("Maps","Maps", 1, 1., 10., AliMagFMaps::k5kG);
251 AliTracker::SetFieldMap(field, kFALSE);
252 AliMUONTrackExtrap::SetField(AliTracker::GetFieldMap());
255 AliCDBManager* man = AliCDBManager::Instance();
256 man->SetDefaultStorage("local://$ALICE_ROOT");
258 if ( ! AliMpCDB::LoadDDLStore() ) {
259 Error("MUONRefit","Could not access mapping from OCDB !");
263 // set reconstruction parameters
264 AliMUONRecoParam *muonRecoParam = AliMUONRecoParam::GetLowFluxParam();
265 muonRecoParam->Print("FULL");
266 AliRecoParam::Instance()->RegisterRecoParam(muonRecoParam);
270 //-----------------------------------------------------------------------
271 TTree* GetESDTree(TFile *esdFile)
273 /// Check that the file is properly open
274 /// Return pointer to the ESD Tree
276 if (!esdFile || !esdFile->IsOpen()) {
277 Error("GetESDTree", "opening ESD file failed");
281 TTree* tree = (TTree*) esdFile->Get("esdTree");
283 Error("GetESDTree", "no ESD tree found");