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 "AliMUONVDigit.h"
56 #include "AliMUONVDigitStore.h"
57 #include "AliMUONVCluster.h"
58 #include "AliMUONTrack.h"
59 #include "AliMUONTrackParam.h"
62 const Int_t printLevel = 1;
65 TTree* GetESDTree(TFile *esdFile);
67 //-----------------------------------------------------------------------
68 void MUONClusterInfo(Int_t nevents = -1, const char* esdFileName = "AliESDs.root", const char* outFileName = "clusterInfo.root")
70 /// load ESD event in the ESDInterface to recover MUON objects;
71 /// track parameters at each cluster are recomputed by the interface using Kalman filter + Smoother
72 /// (It can be changed by resetting the tracker in the interface with a new recoParam object);
73 /// fill AliMUONESDClusterInfo object with ESD cluster + corresponding track parameters;
74 /// write results in a new root file.
76 AliMUONClusterInfo* clusterInfo = new AliMUONClusterInfo();
77 AliMUONPadInfo padInfo;
78 AliMUONCalibrationData* calibData = 0x0;
79 AliMUONESDInterface esdInterface;
81 // prepare the refitting during ESD->MUON conversion
84 // open the ESD file and tree and connect the ESD event
85 TFile* esdFile = TFile::Open(esdFileName);
86 TTree* esdTree = GetESDTree(esdFile);
87 AliESDEvent* esd = new AliESDEvent();
88 esd->ReadFromTree(esdTree);
90 // prepare the output tree
92 TFile* clusterInfoFile = TFile::Open(outFileName, "RECREATE");
93 clusterInfoFile->SetCompressionLevel(1);
95 TTree* clusterInfoTree = new TTree("clusterInfoTree","clusterInfoTree");
96 clusterInfoTree->Branch("clusterInfo", &clusterInfo, 32000, 99);
101 // Loop over ESD events
102 if (nevents > 0) nevents = TMath::Min(nevents,(Int_t)esdTree->GetEntries());
103 else nevents = (Int_t)esdTree->GetEntries();
104 for (Int_t iEvent = 0; iEvent < nevents; iEvent++) {
106 //----------------------------------------------//
107 // -------------- process event --------------- //
108 //----------------------------------------------//
109 // get the ESD of current event
110 esdTree->GetEvent(iEvent);
112 Error("CheckESD", "no ESD object found for event %d", iEvent);
115 if (esd->GetNumberOfMuonTracks() < 1) continue;
117 // prepare access to calibration data
118 if (!calibData) calibData = new AliMUONCalibrationData(esd->GetESDRun()->GetRunNumber());
120 // load the current event
121 esdInterface.LoadEvent(*esd);
124 AliMUONVDigitStore* digitStore = esdInterface.GetDigits();
126 //----------------------------------------------//
127 // ------------- fill cluster info ------------ //
128 //----------------------------------------------//
129 // loop over the refitted tracks
130 TIter nextTrack(esdInterface.CreateTrackIterator());
132 while ((track = static_cast<AliMUONTrack*>(nextTrack()))) {
134 // loop over clusters
135 AliMUONTrackParam* trackParam = static_cast<AliMUONTrackParam*>(track->GetTrackParamAtCluster()->First());
137 clusterInfo->Clear("C");
140 AliMUONVCluster* cluster = trackParam->GetClusterPtr();
141 clusterInfo->SetEventId(iEvent);
142 clusterInfo->SetZ(cluster->GetZ());
143 clusterInfo->SetClusterId(cluster->GetUniqueID());
144 clusterInfo->SetClusterXY(cluster->GetX(), cluster->GetY());
145 clusterInfo->SetClusterXYErr(cluster->GetErrX(), cluster->GetErrY());
146 clusterInfo->SetClusterChi2(cluster->GetChi2());
147 clusterInfo->SetClusterCharge(cluster->GetCharge());
150 clusterInfo->SetTrackId(track->GetUniqueID());
151 clusterInfo->SetTrackXY(trackParam->GetNonBendingCoor(), trackParam->GetBendingCoor());
152 clusterInfo->SetTrackThetaXY(TMath::ATan(trackParam->GetBendingSlope()), TMath::ATan(trackParam->GetNonBendingSlope()));
153 clusterInfo->SetTrackP(trackParam->P());
154 const TMatrixD paramCov = trackParam->GetCovariances();
155 clusterInfo->SetTrackXYErr(TMath::Sqrt(paramCov(0,0)), TMath::Sqrt(paramCov(2,2)));
156 clusterInfo->SetTrackChi2(track->GetNormalizedChi2());
157 clusterInfo->SetTrackCharge((Short_t)trackParam->GetCharge());
159 // fill pad info if available
160 for (Int_t i=0; i<cluster->GetNDigits(); i++) {
161 AliMUONVDigit* digit = digitStore->FindObject(cluster->GetDigitId(i));
162 if (!digit) continue;
165 const AliMpVSegmentation* seg = AliMpSegmentation::Instance()->
166 GetMpSegmentation(digit->DetElemId(),AliMp::GetCathodType(digit->Cathode()));
167 AliMpPad pad = seg->PadByIndices(AliMpIntPair(digit->PadX(), digit->PadY()));
169 // calibration parameters
170 AliMUONVCalibParam* ped = calibData->Pedestals(digit->DetElemId(), digit->ManuId());
171 AliMUONVCalibParam* gain = calibData->Gains(digit->DetElemId(), digit->ManuId());
172 Int_t manuChannel = digit->ManuChannel();
175 padInfo.SetPadId(digit->GetUniqueID());
176 padInfo.SetPadXY(pad.Position().X(), pad.Position().Y());
177 padInfo.SetPadDimXY(pad.Dimensions().X(), pad.Dimensions().Y());
178 padInfo.SetPadCharge((Double_t)digit->Charge());
179 padInfo.SetPadADC(digit->ADC());
180 padInfo.SetSaturated(digit->IsSaturated());
181 padInfo.SetCalibrated(digit->IsCalibrated());
182 padInfo.SetPedestal(ped->ValueAsFloatFast(manuChannel,0), ped->ValueAsFloatFast(manuChannel,1));
183 padInfo.SetGain(gain->ValueAsFloatFast(manuChannel,0), gain->ValueAsFloatFast(manuChannel,1),
184 gain->ValueAsFloatFast(manuChannel,2), gain->ValueAsFloatFast(manuChannel,3));
186 clusterInfo->AddPad(padInfo);
189 // fill cluster info tree
190 clusterInfoTree->Fill();
192 trackParam = static_cast<AliMUONTrackParam*>(track->GetTrackParamAtCluster()->After(trackParam));
201 printf("Writing Tree\n");
203 clusterInfoFile->cd();
204 clusterInfoTree->Write();
205 printf("Deleting Tree\n");
206 delete clusterInfoTree;
207 printf("Closing File\n");
208 clusterInfoFile->Close();
211 printf("Deleting calibData\n");
213 printf("Deleting clusterInfo\n");
215 printf("Closing esdFile\n");
217 printf("Deleting esd\n");
220 cout<<endl<<"time to fill cluster/track info: R:"<<timer.RealTime()<<" C:"<<timer.CpuTime()<<endl<<endl;
223 //-----------------------------------------------------------------------
226 /// Set the geometry, the magnetic field, the mapping and the reconstruction parameters
230 // Import TGeo geometry (needed for track extrapolation)
232 AliGeomManager::LoadGeometry("geometry.root");
234 Error("MUONRefit", "getting geometry from file %s failed", "generated/galice.root");
240 printf("Loading field map...\n");
241 AliMagFMaps* field = new AliMagFMaps("Maps","Maps", 1, 1., 10., AliMagFMaps::k5kG);
242 AliTracker::SetFieldMap(field, kFALSE);
245 AliCDBManager* man = AliCDBManager::Instance();
246 man->SetDefaultStorage("local://$ALICE_ROOT");
248 if ( ! AliMpCDB::LoadDDLStore() ) {
249 Error("MUONRefit","Could not access mapping from OCDB !");
253 // Reset the reconstruction parameters for track refitting if needed
254 // (by default will use Kalman filter + Smoother)
255 // AliMUONRecoParam *muonRecoParam = AliMUONRecoParam::GetLowFluxParam();
256 // AliMUONESDInterface::ResetTracker(muonRecoParam);
260 //-----------------------------------------------------------------------
261 TTree* GetESDTree(TFile *esdFile)
263 /// Check that the file is properly open
264 /// Return pointer to the ESD Tree
266 if (!esdFile || !esdFile->IsOpen()) {
267 Error("GetESDTree", "opening ESD file failed");
271 TTree* tree = (TTree*) esdFile->Get("esdTree");
273 Error("GetESDTree", "no ESD tree found");