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 <TObjArray.h>
30 #include <Riostream.h>
36 #include "AliESDEvent.h"
37 #include "AliRecoParam.h"
38 #include "AliCDBManager.h"
39 #include "AliRunLoader.h"
40 #include "AliLoader.h"
41 #include "AliHeader.h"
44 #include "AliMpConstants.h"
45 #include "AliMpSegmentation.h"
46 #include "AliMpVSegmentation.h"
48 #include "AliMUONCDB.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 "AliMUONVClusterStore.h"
59 #include "AliMUONTrack.h"
60 #include "AliMUONTrackParam.h"
63 const Int_t printLevel = 1;
65 TTree* GetESDTree(TFile *esdFile);
66 UInt_t buildClusterMap(AliMUONTrack &track);
68 //-----------------------------------------------------------------------
69 void MUONClusterInfo(Int_t nevents = -1, const char* esdFileName = "AliESDs.root", const char* inFileName = "galice.root",
70 const TString ocdbPath = "local://$ALICE_ROOT/OCDB", const char* outFileName = "clusterInfo.root")
72 /// 1) if (esdFileName != "")
73 /// loop over ESD event and fill AliMUONClusterInfo object with cluster + corresponding track parameters;
74 /// 2) if (inFileName != "")
75 /// loop over RecPoints and fill AliMUONClusterInfo object with cluster not attached to a track;
76 /// 3) write results in a new root file.
78 /// ******************************************* WARNING ******************************************* ///
79 /// track parameters at each cluster are recomputed by the interface using Kalman filter + Smoother ///
80 /// (It can be changed by resetting the tracker in the interface with a new recoParam object) ///
81 /// and the magnetic field set in the function prepare() ///
82 /// ******************************************* WARNING ******************************************* ///
84 Bool_t useESD = (strcmp(esdFileName,""));
85 Bool_t useRecPoints = (strcmp(inFileName,""));
86 if (!useESD && !useRecPoints) {
87 Error("MUONClusterInfo","you must provide ESD and/or galice root file(s)");
91 AliMUONClusterInfo* clusterInfo = new AliMUONClusterInfo();
92 AliMUONPadInfo padInfo;
93 AliMUONCalibrationData* calibData = 0x0;
94 AliMUONESDInterface esdInterface;
95 AliMUONVClusterStore* clusterStore = 0x0;
96 AliMUONVDigitStore* digitStore = 0x0;
98 // open the ESD file and tree and connect the ESD event
100 TTree* esdTree = 0x0;
101 AliESDEvent* esd = 0x0;
102 Int_t runNumber = -1;
104 esdFile = TFile::Open(esdFileName);
105 esdTree = GetESDTree(esdFile);
106 esd = new AliESDEvent();
107 esd->ReadFromTree(esdTree);
108 if (esdTree->GetEvent(0) <= 0) {
109 Error("MUONClusterInfo", "no ESD object found for event 0");
112 runNumber = esd->GetRunNumber();
115 // get the cluster from RecPoints
116 AliRunLoader * rl = 0x0;
117 AliLoader* MUONLoader = 0x0;
119 rl = AliRunLoader::Open(inFileName,"MUONLoader");
120 MUONLoader = rl->GetDetectorLoader("MUON");
121 MUONLoader->LoadRecPoints("READ");
122 MUONLoader->LoadDigits("READ");
124 if (runNumber < 0) runNumber = rl->GetHeader()->GetRun();
127 // load necessary data from OCDB
128 AliCDBManager::Instance()->SetDefaultStorage(ocdbPath);
129 AliCDBManager::Instance()->SetRun(runNumber);
130 if (!AliMUONCDB::LoadField()) return;
131 if (!AliMUONCDB::LoadMapping(kTRUE)) return;
132 AliMUONRecoParam* recoParam = AliMUONCDB::LoadRecoParam();
133 if (!recoParam) return;
135 // reset tracker for track restoring initial track parameters at cluster
136 AliMUONESDInterface::ResetTracker(recoParam);
138 // prepare access to calibration data
139 calibData = new AliMUONCalibrationData(runNumber);
141 // prepare the output tree
143 TFile* clusterInfoFile = TFile::Open(outFileName, "RECREATE");
144 clusterInfoFile->SetCompressionLevel(1);
146 TTree* clusterInfoTree = new TTree("clusterInfoTree","clusterInfoTree");
147 clusterInfoTree->Branch("clusterInfo", &clusterInfo, 32000, 99);
154 if (nevents > 0) nevents = TMath::Min(nevents,(Int_t)esdTree->GetEntries());
155 else nevents = (Int_t)esdTree->GetEntries();
157 if (nevents > 0) nevents = TMath::Min(nevents,(Int_t)rl->GetNumberOfEvents());
158 else nevents = (Int_t)rl->GetNumberOfEvents();
160 for (Int_t iEvent = 0; iEvent < nevents; iEvent++) {
162 //----------------------------------------------//
163 // -------------- process event --------------- //
164 //----------------------------------------------//
165 // get the ESD of current event
167 esdTree->GetEvent(iEvent);
169 Error("MUONClusterInfo", "no ESD object found for event %d", iEvent);
172 // load the current esd event
173 esdInterface.LoadEvent(*esd);
175 if (!useRecPoints) digitStore = esdInterface.GetDigits();
179 if (!(rl->GetEvent(iEvent) == 0)) {
180 Error("MUONClusterInfo", "unable to load event %d", iEvent);
183 // get the clusters of current event
184 TTree* treeR = MUONLoader->TreeR();
185 clusterStore = AliMUONVClusterStore::Create(*treeR);
186 if ( clusterStore != 0x0 ) {
187 clusterStore->Clear();
188 clusterStore->Connect(*treeR);
191 // get the digits of current event
192 TTree* treeD = MUONLoader->TreeD();
193 digitStore = AliMUONVDigitStore::Create(*treeD);
194 if ( digitStore != 0x0 ) {
196 digitStore->Connect(*treeD);
201 //----------------------------------------------//
202 // ------------- fill cluster info ------------ //
203 //----------------------------------------------//
204 // --- loop over the refitted tracks ---
207 TIter nextTrack(esdInterface.CreateTrackIterator());
209 while ((track = static_cast<AliMUONTrack*>(nextTrack()))) {
211 UInt_t muonClusterMap = buildClusterMap(*track);
213 // loop over clusters
214 AliMUONTrackParam* trackParam = static_cast<AliMUONTrackParam*>(track->GetTrackParamAtCluster()->First());
216 clusterInfo->Clear("C");
219 AliMUONVCluster* cluster = trackParam->GetClusterPtr();
220 clusterInfo->SetRunId(esd->GetRunNumber());
221 clusterInfo->SetEventId(iEvent);
222 clusterInfo->SetZ(cluster->GetZ());
223 clusterInfo->SetClusterId(cluster->GetUniqueID());
224 clusterInfo->SetClusterXY(cluster->GetX(), cluster->GetY());
225 clusterInfo->SetClusterXYErr(cluster->GetErrX(), cluster->GetErrY());
226 clusterInfo->SetClusterChi2(cluster->GetChi2());
227 clusterInfo->SetClusterCharge(cluster->GetCharge());
230 clusterInfo->SetTrackId(track->GetUniqueID());
231 clusterInfo->SetTrackXY(trackParam->GetNonBendingCoor(), trackParam->GetBendingCoor());
232 clusterInfo->SetTrackThetaXY(TMath::ATan(trackParam->GetNonBendingSlope()), TMath::ATan(trackParam->GetBendingSlope()));
233 clusterInfo->SetTrackP(trackParam->P());
234 const TMatrixD paramCov = trackParam->GetCovariances();
235 clusterInfo->SetTrackXYErr(TMath::Sqrt(paramCov(0,0)), TMath::Sqrt(paramCov(2,2)));
236 clusterInfo->SetTrackChi2(track->GetNormalizedChi2());
237 clusterInfo->SetTrackCharge((Short_t)trackParam->GetCharge());
238 clusterInfo->SetTrackNHits(track->GetNClusters());
239 clusterInfo->SetTrackChamberHitMap(muonClusterMap);
241 // fill pad info if available
242 for (Int_t i=0; i<cluster->GetNDigits(); i++) {
243 AliMUONVDigit* digit = digitStore->FindObject(cluster->GetDigitId(i));
244 if (!digit) continue;
247 const AliMpVSegmentation* seg = AliMpSegmentation::Instance()->
248 GetMpSegmentation(digit->DetElemId(),AliMp::GetCathodType(digit->Cathode()));
249 AliMpPad pad = seg->PadByIndices(digit->PadX(), digit->PadY());
251 // calibration parameters
252 AliMUONVCalibParam* ped = calibData->Pedestals(digit->DetElemId(), digit->ManuId());
253 AliMUONVCalibParam* gain = calibData->Gains(digit->DetElemId(), digit->ManuId());
254 Int_t manuChannel = digit->ManuChannel();
256 if ( digit->ManuId() & AliMpConstants::ManuMask(AliMp::kNonBendingPlane)) {
261 padInfo.SetPadId(digit->GetUniqueID());
262 padInfo.SetPadPlaneType(planeType);
263 padInfo.SetPadXY(pad.GetPositionX(), pad.GetPositionY());
264 padInfo.SetPadDimXY(pad.GetDimensionX(), pad.GetDimensionY());
265 padInfo.SetPadCharge((Double_t)digit->Charge());
266 padInfo.SetPadADC(digit->ADC());
267 padInfo.SetSaturated(digit->IsSaturated());
268 padInfo.SetCalibrated(digit->IsCalibrated());
269 padInfo.SetPedestal(ped->ValueAsFloatFast(manuChannel,0), ped->ValueAsFloatFast(manuChannel,1));
270 padInfo.SetGain(gain->ValueAsFloatFast(manuChannel,0), gain->ValueAsFloatFast(manuChannel,1),
271 gain->ValueAsFloatFast(manuChannel,2), gain->ValueAsFloatFast(manuChannel,3));
273 clusterInfo->AddPad(padInfo);
276 // remove clusters attached to a track
278 AliMUONVCluster* cl = clusterStore->FindObject(cluster->GetUniqueID());
279 if (cl) clusterStore->Remove(*cl);
282 // fill cluster info tree
283 clusterInfoTree->Fill();
285 trackParam = static_cast<AliMUONTrackParam*>(track->GetTrackParamAtCluster()->After(trackParam));
292 // --- loop over clusters not attached to a track ---
295 TIter nextCluster(clusterStore->CreateIterator());
296 AliMUONVCluster *cluster;
297 while ( ( cluster = static_cast<AliMUONVCluster*>(nextCluster()) ) ) {
299 clusterInfo->Clear("C");
302 clusterInfo->SetRunId(rl->GetRunNumber());
303 clusterInfo->SetEventId(iEvent);
304 clusterInfo->SetZ(cluster->GetZ());
305 clusterInfo->SetClusterId(cluster->GetUniqueID());
306 clusterInfo->SetClusterXY(cluster->GetX(), cluster->GetY());
307 clusterInfo->SetClusterXYErr(cluster->GetErrX(), cluster->GetErrY());
308 clusterInfo->SetClusterChi2(cluster->GetChi2());
309 clusterInfo->SetClusterCharge(cluster->GetCharge());
311 // fill dummy track info
312 clusterInfo->SetTrackId(0);
313 clusterInfo->SetTrackXY(0.,0.);
314 clusterInfo->SetTrackThetaXY(0.,0.);
315 clusterInfo->SetTrackP(0.);
316 clusterInfo->SetTrackXYErr(0.,0.);
317 clusterInfo->SetTrackChi2(0.);
318 clusterInfo->SetTrackCharge(0);
319 clusterInfo->SetTrackNHits(0);
320 clusterInfo->SetTrackChamberHitMap(0);
322 // fill pad info if available
323 for (Int_t i=0; i<cluster->GetNDigits(); i++) {
324 AliMUONVDigit* digit = digitStore->FindObject(cluster->GetDigitId(i));
325 if (!digit) continue;
328 const AliMpVSegmentation* seg = AliMpSegmentation::Instance()->
329 GetMpSegmentation(digit->DetElemId(),AliMp::GetCathodType(digit->Cathode()));
330 AliMpPad pad = seg->PadByIndices(digit->PadX(), digit->PadY());
332 // calibration parameters
333 AliMUONVCalibParam* ped = calibData->Pedestals(digit->DetElemId(), digit->ManuId());
334 AliMUONVCalibParam* gain = calibData->Gains(digit->DetElemId(), digit->ManuId());
335 Int_t manuChannel = digit->ManuChannel();
337 if ( digit->ManuId() & AliMpConstants::ManuMask(AliMp::kNonBendingPlane)) {
342 padInfo.SetPadId(digit->GetUniqueID());
343 padInfo.SetPadPlaneType(planeType);
344 padInfo.SetPadXY(pad.GetPositionX(), pad.GetPositionY());
345 padInfo.SetPadDimXY(pad.GetDimensionX(), pad.GetDimensionY());
346 padInfo.SetPadCharge((Double_t)digit->Charge());
347 padInfo.SetPadADC(digit->ADC());
348 padInfo.SetSaturated(digit->IsSaturated());
349 padInfo.SetCalibrated(digit->IsCalibrated());
350 padInfo.SetPedestal(ped->ValueAsFloatFast(manuChannel,0), ped->ValueAsFloatFast(manuChannel,1));
351 padInfo.SetGain(gain->ValueAsFloatFast(manuChannel,0), gain->ValueAsFloatFast(manuChannel,1),
352 gain->ValueAsFloatFast(manuChannel,2), gain->ValueAsFloatFast(manuChannel,3));
354 clusterInfo->AddPad(padInfo);
357 // fill cluster info tree
358 clusterInfoTree->Fill();
371 printf("Writing Tree\n");
373 clusterInfoFile->cd();
374 clusterInfoTree->Write();
375 printf("Deleting Tree\n");
376 delete clusterInfoTree;
377 printf("Closing File\n");
378 clusterInfoFile->Close();
381 printf("Deleting calibData\n");
383 printf("Deleting clusterInfo\n");
386 MUONLoader->UnloadDigits();
387 MUONLoader->UnloadRecPoints();
395 cout<<endl<<"time to fill cluster/track info: R:"<<timer.RealTime()<<" C:"<<timer.CpuTime()<<endl<<endl;
398 //-----------------------------------------------------------------------
399 TTree* GetESDTree(TFile *esdFile)
401 /// Check that the file is properly open
402 /// Return pointer to the ESD Tree
404 if (!esdFile || !esdFile->IsOpen()) {
405 Error("GetESDTree", "opening ESD file failed");
409 TTree* tree = (TTree*) esdFile->Get("esdTree");
411 Error("GetESDTree", "no ESD tree found");
420 //-----------------------------------------------------------------------
421 UInt_t buildClusterMap(AliMUONTrack &track)
423 /// Build the map of clusters in tracking chambers
425 UInt_t muonClusterMap = 0;
427 AliMUONTrackParam* trackParam = static_cast<AliMUONTrackParam*>(track.GetTrackParamAtCluster()->First());
430 muonClusterMap |= BIT(trackParam->GetClusterPtr()->GetChamberId());
432 trackParam = static_cast<AliMUONTrackParam*>(track.GetTrackParamAtCluster()->After(trackParam));
435 return muonClusterMap;