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>
37 #include "AliTracker.h"
38 #include "AliESDEvent.h"
39 #include "AliRecoParam.h"
40 #include "AliCDBManager.h"
41 #include "AliRunLoader.h"
42 #include "AliLoader.h"
45 #include "AliMpConstants.h"
47 #include "AliMpSegmentation.h"
48 #include "AliMpVSegmentation.h"
50 #include "AliMUONCalibrationData.h"
51 #include "AliMUONVCalibParam.h"
52 #include "AliMUONPadInfo.h"
53 #include "AliMUONClusterInfo.h"
54 #include "AliMUONRecoParam.h"
55 #include "AliMUONESDInterface.h"
56 #include "AliMUONVDigit.h"
57 #include "AliMUONVDigitStore.h"
58 #include "AliMUONVCluster.h"
59 #include "AliMUONVClusterStore.h"
60 #include "AliMUONTrack.h"
61 #include "AliMUONTrackParam.h"
64 const Int_t printLevel = 1;
67 TTree* GetESDTree(TFile *esdFile);
68 UInt_t buildClusterMap(AliMUONTrack &track);
70 //-----------------------------------------------------------------------
71 void MUONClusterInfo(Int_t nevents = -1, const char* esdFileName = "AliESDs.root",
72 const char* inFileName = "galice.root", const char* outFileName = "clusterInfo.root")
74 /// 1) if (esdFileName != "")
75 /// loop over ESD event and fill AliMUONClusterInfo object with cluster + corresponding track parameters;
76 /// 2) if (inFileName != "")
77 /// loop over RecPoints and fill AliMUONClusterInfo object with cluster not attached to a track;
78 /// 3) write results in a new root file.
80 /// ******************************************* WARNING ******************************************* ///
81 /// track parameters at each cluster are recomputed by the interface using Kalman filter + Smoother ///
82 /// (It can be changed by resetting the tracker in the interface with a new recoParam object) ///
83 /// and the magnetic field set in the function prepare() ///
84 /// ******************************************* WARNING ******************************************* ///
86 Bool_t useESD = (strcmp(esdFileName,""));
87 Bool_t useRecPoints = (strcmp(inFileName,""));
88 if (!useESD && !useRecPoints) {
89 Error("MUONClusterInfo","you must provide ESD and/or galice root file(s)");
93 AliMUONClusterInfo* clusterInfo = new AliMUONClusterInfo();
94 AliMUONPadInfo padInfo;
95 AliMUONCalibrationData* calibData = 0x0;
96 AliMUONESDInterface esdInterface;
97 AliMUONVClusterStore* clusterStore = 0x0;
98 AliMUONVDigitStore* digitStore = 0x0;
100 // prepare the refitting during ESD->MUON conversion
103 // open the ESD file and tree and connect the ESD event
104 TFile* esdFile = 0x0;
105 TTree* esdTree = 0x0;
106 AliESDEvent* esd = 0x0;
108 esdFile = TFile::Open(esdFileName);
109 esdTree = GetESDTree(esdFile);
110 esd = new AliESDEvent();
111 esd->ReadFromTree(esdTree);
114 // get the cluster from RecPoints
115 AliRunLoader * rl = 0x0;
116 AliLoader* MUONLoader = 0x0;
118 rl = AliRunLoader::Open(inFileName,"MUONLoader");
119 MUONLoader = rl->GetDetectorLoader("MUON");
120 MUONLoader->LoadRecPoints("READ");
121 MUONLoader->LoadDigits("READ");
124 // prepare the output tree
126 TFile* clusterInfoFile = TFile::Open(outFileName, "RECREATE");
127 clusterInfoFile->SetCompressionLevel(1);
129 TTree* clusterInfoTree = new TTree("clusterInfoTree","clusterInfoTree");
130 clusterInfoTree->Branch("clusterInfo", &clusterInfo, 32000, 99);
137 if (nevents > 0) nevents = TMath::Min(nevents,(Int_t)esdTree->GetEntries());
138 else nevents = (Int_t)esdTree->GetEntries();
140 if (nevents > 0) nevents = TMath::Min(nevents,(Int_t)rl->GetNumberOfEvents());
141 else nevents = (Int_t)rl->GetNumberOfEvents();
143 for (Int_t iEvent = 0; iEvent < nevents; iEvent++) {
145 //----------------------------------------------//
146 // -------------- process event --------------- //
147 //----------------------------------------------//
148 // get the ESD of current event
150 esdTree->GetEvent(iEvent);
152 Error("MUONClusterInfo", "no ESD object found for event %d", iEvent);
155 // load the current esd event
156 esdInterface.LoadEvent(*esd);
158 if (!useRecPoints) digitStore = esdInterface.GetDigits();
162 if (!(rl->GetEvent(iEvent) == 0)) {
163 Error("MUONClusterInfo", "unable to load event %d", iEvent);
166 // get the clusters of current event
167 TTree* treeR = MUONLoader->TreeR();
168 clusterStore = AliMUONVClusterStore::Create(*treeR);
169 if ( clusterStore != 0x0 ) {
170 clusterStore->Clear();
171 clusterStore->Connect(*treeR);
174 // get the digits of current event
175 TTree* treeD = MUONLoader->TreeD();
176 digitStore = AliMUONVDigitStore::Create(*treeD);
177 if ( digitStore != 0x0 ) {
179 digitStore->Connect(*treeD);
184 // prepare access to calibration data
185 if (useESD && !calibData) calibData = new AliMUONCalibrationData(esd->GetESDRun()->GetRunNumber());
186 else if (!calibData) calibData = new AliMUONCalibrationData(rl->GetRunNumber());
188 //----------------------------------------------//
189 // ------------- fill cluster info ------------ //
190 //----------------------------------------------//
191 // --- loop over the refitted tracks ---
194 TIter nextTrack(esdInterface.CreateTrackIterator());
196 while ((track = static_cast<AliMUONTrack*>(nextTrack()))) {
198 UInt_t muonClusterMap = buildClusterMap(*track);
200 // loop over clusters
201 AliMUONTrackParam* trackParam = static_cast<AliMUONTrackParam*>(track->GetTrackParamAtCluster()->First());
203 clusterInfo->Clear("C");
206 AliMUONVCluster* cluster = trackParam->GetClusterPtr();
207 clusterInfo->SetRunId(esd->GetRunNumber());
208 clusterInfo->SetEventId(iEvent);
209 clusterInfo->SetZ(cluster->GetZ());
210 clusterInfo->SetClusterId(cluster->GetUniqueID());
211 clusterInfo->SetClusterXY(cluster->GetX(), cluster->GetY());
212 clusterInfo->SetClusterXYErr(cluster->GetErrX(), cluster->GetErrY());
213 clusterInfo->SetClusterChi2(cluster->GetChi2());
214 clusterInfo->SetClusterCharge(cluster->GetCharge());
217 clusterInfo->SetTrackId(track->GetUniqueID());
218 clusterInfo->SetTrackXY(trackParam->GetNonBendingCoor(), trackParam->GetBendingCoor());
219 clusterInfo->SetTrackThetaXY(TMath::ATan(trackParam->GetNonBendingSlope()), TMath::ATan(trackParam->GetBendingSlope()));
220 clusterInfo->SetTrackP(trackParam->P());
221 const TMatrixD paramCov = trackParam->GetCovariances();
222 clusterInfo->SetTrackXYErr(TMath::Sqrt(paramCov(0,0)), TMath::Sqrt(paramCov(2,2)));
223 clusterInfo->SetTrackChi2(track->GetNormalizedChi2());
224 clusterInfo->SetTrackCharge((Short_t)trackParam->GetCharge());
225 clusterInfo->SetTrackNHits(track->GetNClusters());
226 clusterInfo->SetTrackChamberHitMap(muonClusterMap);
228 // fill pad info if available
229 for (Int_t i=0; i<cluster->GetNDigits(); i++) {
230 AliMUONVDigit* digit = digitStore->FindObject(cluster->GetDigitId(i));
231 if (!digit) continue;
234 const AliMpVSegmentation* seg = AliMpSegmentation::Instance()->
235 GetMpSegmentation(digit->DetElemId(),AliMp::GetCathodType(digit->Cathode()));
236 AliMpPad pad = seg->PadByIndices(digit->PadX(), digit->PadY());
238 // calibration parameters
239 AliMUONVCalibParam* ped = calibData->Pedestals(digit->DetElemId(), digit->ManuId());
240 AliMUONVCalibParam* gain = calibData->Gains(digit->DetElemId(), digit->ManuId());
241 Int_t manuChannel = digit->ManuChannel();
243 if ( digit->ManuId() & AliMpConstants::ManuMask(AliMp::kNonBendingPlane)) {
248 padInfo.SetPadId(digit->GetUniqueID());
249 padInfo.SetPadPlaneType(planeType);
250 padInfo.SetPadXY(pad.GetPositionX(), pad.GetPositionY());
251 padInfo.SetPadDimXY(pad.GetDimensionX(), pad.GetDimensionY());
252 padInfo.SetPadCharge((Double_t)digit->Charge());
253 padInfo.SetPadADC(digit->ADC());
254 padInfo.SetSaturated(digit->IsSaturated());
255 padInfo.SetCalibrated(digit->IsCalibrated());
256 padInfo.SetPedestal(ped->ValueAsFloatFast(manuChannel,0), ped->ValueAsFloatFast(manuChannel,1));
257 padInfo.SetGain(gain->ValueAsFloatFast(manuChannel,0), gain->ValueAsFloatFast(manuChannel,1),
258 gain->ValueAsFloatFast(manuChannel,2), gain->ValueAsFloatFast(manuChannel,3));
260 clusterInfo->AddPad(padInfo);
263 // remove clusters attached to a track
265 AliMUONVCluster* cl = clusterStore->FindObject(cluster->GetUniqueID());
266 if (cl) clusterStore->Remove(*cl);
269 // fill cluster info tree
270 clusterInfoTree->Fill();
272 trackParam = static_cast<AliMUONTrackParam*>(track->GetTrackParamAtCluster()->After(trackParam));
279 // --- loop over clusters not attached to a track ---
282 TIter nextCluster(clusterStore->CreateIterator());
283 AliMUONVCluster *cluster;
284 while ( ( cluster = static_cast<AliMUONVCluster*>(nextCluster()) ) ) {
286 clusterInfo->Clear("C");
289 clusterInfo->SetRunId(rl->GetRunNumber());
290 clusterInfo->SetEventId(iEvent);
291 clusterInfo->SetZ(cluster->GetZ());
292 clusterInfo->SetClusterId(cluster->GetUniqueID());
293 clusterInfo->SetClusterXY(cluster->GetX(), cluster->GetY());
294 clusterInfo->SetClusterXYErr(cluster->GetErrX(), cluster->GetErrY());
295 clusterInfo->SetClusterChi2(cluster->GetChi2());
296 clusterInfo->SetClusterCharge(cluster->GetCharge());
298 // fill dummy track info
299 clusterInfo->SetTrackId(0);
300 clusterInfo->SetTrackXY(0.,0.);
301 clusterInfo->SetTrackThetaXY(0.,0.);
302 clusterInfo->SetTrackP(0.);
303 clusterInfo->SetTrackXYErr(0.,0.);
304 clusterInfo->SetTrackChi2(0.);
305 clusterInfo->SetTrackCharge(0);
306 clusterInfo->SetTrackNHits(0);
307 clusterInfo->SetTrackChamberHitMap(0);
309 // fill pad info if available
310 for (Int_t i=0; i<cluster->GetNDigits(); i++) {
311 AliMUONVDigit* digit = digitStore->FindObject(cluster->GetDigitId(i));
312 if (!digit) continue;
315 const AliMpVSegmentation* seg = AliMpSegmentation::Instance()->
316 GetMpSegmentation(digit->DetElemId(),AliMp::GetCathodType(digit->Cathode()));
317 AliMpPad pad = seg->PadByIndices(digit->PadX(), digit->PadY());
319 // calibration parameters
320 AliMUONVCalibParam* ped = calibData->Pedestals(digit->DetElemId(), digit->ManuId());
321 AliMUONVCalibParam* gain = calibData->Gains(digit->DetElemId(), digit->ManuId());
322 Int_t manuChannel = digit->ManuChannel();
324 if ( digit->ManuId() & AliMpConstants::ManuMask(AliMp::kNonBendingPlane)) {
329 padInfo.SetPadId(digit->GetUniqueID());
330 padInfo.SetPadPlaneType(planeType);
331 padInfo.SetPadXY(pad.GetPositionX(), pad.GetPositionY());
332 padInfo.SetPadDimXY(pad.GetDimensionX(), pad.GetDimensionY());
333 padInfo.SetPadCharge((Double_t)digit->Charge());
334 padInfo.SetPadADC(digit->ADC());
335 padInfo.SetSaturated(digit->IsSaturated());
336 padInfo.SetCalibrated(digit->IsCalibrated());
337 padInfo.SetPedestal(ped->ValueAsFloatFast(manuChannel,0), ped->ValueAsFloatFast(manuChannel,1));
338 padInfo.SetGain(gain->ValueAsFloatFast(manuChannel,0), gain->ValueAsFloatFast(manuChannel,1),
339 gain->ValueAsFloatFast(manuChannel,2), gain->ValueAsFloatFast(manuChannel,3));
341 clusterInfo->AddPad(padInfo);
344 // fill cluster info tree
345 clusterInfoTree->Fill();
358 printf("Writing Tree\n");
360 clusterInfoFile->cd();
361 clusterInfoTree->Write();
362 printf("Deleting Tree\n");
363 delete clusterInfoTree;
364 printf("Closing File\n");
365 clusterInfoFile->Close();
368 printf("Deleting calibData\n");
370 printf("Deleting clusterInfo\n");
373 MUONLoader->UnloadDigits();
374 MUONLoader->UnloadRecPoints();
381 cout<<endl<<"time to fill cluster/track info: R:"<<timer.RealTime()<<" C:"<<timer.CpuTime()<<endl<<endl;
384 //-----------------------------------------------------------------------
387 /// Set the magnetic field, the mapping and the reconstruction parameters
392 if (!TGeoGlobalMagField::Instance()->GetField()) {
393 printf("Loading field map...\n");
394 AliMagF* field = new AliMagF("Maps","Maps",2,1.,1., 10.,AliMagF::k5kG);
395 TGeoGlobalMagField::Instance()->SetField(field);
399 AliCDBManager* man = AliCDBManager::Instance();
400 man->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
402 if ( ! AliMpCDB::LoadDDLStore() ) {
403 Error("Prepare","Could not access mapping from OCDB !");
407 // Reset the reconstruction parameters for track refitting if needed
408 // (by default will use Kalman filter + Smoother)
409 // AliMUONRecoParam *muonRecoParam = AliMUONRecoParam::GetLowFluxParam();
410 // AliMUONESDInterface::ResetTracker(muonRecoParam);
414 //-----------------------------------------------------------------------
415 TTree* GetESDTree(TFile *esdFile)
417 /// Check that the file is properly open
418 /// Return pointer to the ESD Tree
420 if (!esdFile || !esdFile->IsOpen()) {
421 Error("GetESDTree", "opening ESD file failed");
425 TTree* tree = (TTree*) esdFile->Get("esdTree");
427 Error("GetESDTree", "no ESD tree found");
436 //-----------------------------------------------------------------------
437 UInt_t buildClusterMap(AliMUONTrack &track)
439 /// Build the map of clusters in tracking chambers
441 UInt_t muonClusterMap = 0;
443 AliMUONTrackParam* trackParam = static_cast<AliMUONTrackParam*>(track.GetTrackParamAtCluster()->First());
446 muonClusterMap |= BIT(trackParam->GetClusterPtr()->GetChamberId());
448 trackParam = static_cast<AliMUONTrackParam*>(track.GetTrackParamAtCluster()->After(trackParam));
451 return muonClusterMap;