- AliMUONRecoParam.cxx:
[u/mrichter/AliRoot.git] / EVE / EveDet / AliEveMUONData.cxx
CommitLineData
d810d0de 1// $Id$
fafff680 2// Main authors: Matevz Tadel & Alja Mrak-Tadel & Bogdan Vulpescu: 2006, 2007
d810d0de 3
4/**************************************************************************
5 * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. *
6 * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for *
51346b82 7 * full copyright notice. *
d810d0de 8 **************************************************************************/
16718cdc 9
d810d0de 10#include "AliEveMUONData.h"
3626c858 11
cb4245bb 12#include <EveDet/AliEveMUONChamberData.h>
707b281a 13#include <EveBase/AliEveEventManager.h>
3626c858 14
15#include <AliRawReader.h>
16#include <AliRawReaderFile.h>
17#include <AliRawReaderDate.h>
18#include <AliRawReaderRoot.h>
19
cef26510 20#include <AliMUONDigitMaker.h>
eadce74d 21#include <AliMUONHit.h>
8c58b039 22#include <AliMUONVCluster.h>
23#include "AliMUONVClusterStore.h"
8d33d1c2 24#include <AliMUONVDigit.h>
8d33d1c2 25#include "AliMUONDigitStoreV1.h"
832dd5c9 26#include "AliMUONVDigitStore.h"
fafff680 27#include "AliMUONTrackParam.h"
28#include "AliMUONTrack.h"
103e6575 29#include "AliMUONESDInterface.h"
fafff680 30#include "AliESDMuonTrack.h"
31#include "AliESDEvent.h"
3626c858 32#include "TTree.h"
33#include "TString.h"
3626c858 34#include "TClonesArray.h"
fafff680 35#include "TFile.h"
d810d0de 36
3626c858 37
57ffa5fb 38//______________________________________________________________________________
d810d0de 39// AliEveMUONData
3626c858 40//
41
d810d0de 42ClassImp(AliEveMUONData)
3626c858 43
d810d0de 44AliRawReader* AliEveMUONData::fgRawReader = 0;
3626c858 45
57ffa5fb 46//______________________________________________________________________________
d810d0de 47AliEveMUONData::AliEveMUONData() :
eadce74d 48 fChambers(14),
49 fNTrackList(0)
3626c858 50{
51 //
52 // Constructor
53 //
51346b82 54
cef26510 55 for (Int_t i = 0; i < 256; i++) {
eadce74d 56 fTrackList[i] = -1;
57 }
58
3626c858 59 CreateAllChambers();
60
61}
62
57ffa5fb 63//______________________________________________________________________________
d810d0de 64AliEveMUONData::~AliEveMUONData()
3626c858 65{
66 //
67 // Destructor
68 //
69
70 DeleteAllChambers();
71
3626c858 72}
73
57ffa5fb 74//______________________________________________________________________________
d810d0de 75void AliEveMUONData::Reset()
eadce74d 76{
77 //
78 // Reset data
79 //
80
81 //DropAllChambers();
82
83 fNTrackList = 0;
cef26510 84 for (Int_t i = 0; i < 256; i++) {
eadce74d 85 fTrackList[i] = -1;
86 }
87
88}
89
57ffa5fb 90//______________________________________________________________________________
d810d0de 91AliEveMUONData::AliEveMUONData(const AliEveMUONData &mdata) :
e4204218 92 TObject(mdata),
84aff7a4 93 TEveRefCnt(),
8d33d1c2 94 fChambers(14),
95 fNTrackList(0)
3626c858 96{
97 //
98 // Copy constructor
99 //
100
101}
102
57ffa5fb 103//______________________________________________________________________________
d810d0de 104AliEveMUONData& AliEveMUONData::operator=(const AliEveMUONData &mdata)
3626c858 105{
106 //
107 // Assignment operator
108 //
109
110 if (this != &mdata) {
111
112 }
113
114 return *this;
115
116}
117
57ffa5fb 118//______________________________________________________________________________
d810d0de 119void AliEveMUONData::CreateChamber(Int_t chamber)
3626c858 120{
51346b82 121 //
3626c858 122 // create data for the chamber with id=chamber (0 to 13)
123 //
124
125 if (fChambers[chamber] == 0)
d810d0de 126 fChambers[chamber] = new AliEveMUONChamberData(chamber);
3626c858 127
128}
129
57ffa5fb 130//______________________________________________________________________________
d810d0de 131void AliEveMUONData::CreateAllChambers()
3626c858 132{
133 //
134 // create all 14 chambers data
135 //
136
137 for (Int_t c = 0; c < 14; ++c)
138 CreateChamber(c);
139
140}
141
57ffa5fb 142//______________________________________________________________________________
d810d0de 143void AliEveMUONData::DropAllChambers()
3626c858 144{
51346b82 145 //
146 // release data from all chambers
3626c858 147 //
148
149 for (Int_t c = 0; c < 14; ++c) {
150
151 if (fChambers[c] != 0)
152 fChambers[c]->DropData();
153
154 }
155
156}
157
57ffa5fb 158//______________________________________________________________________________
d810d0de 159void AliEveMUONData::DeleteAllChambers()
3626c858 160{
161 //
162 // delete all chambers data
163 //
164
165 for (Int_t c = 0; c < 14; ++c) {
166
167 delete fChambers[c];
168 fChambers[c] = 0;
169
170 }
171
172}
173
57ffa5fb 174//______________________________________________________________________________
d810d0de 175void AliEveMUONData::RegisterTrack(Int_t track)
eadce74d 176{
177 //
178 // register (in a list) a track with hits in the chambers
179 //
180
cef26510 181 if (fNTrackList == (256-1)) {
eadce74d 182 cout << "Maximum of registered tracks reached..." << endl;
183 return;
184 }
185
186 Bool_t inList = kFALSE;
187 for (Int_t i = 0; i < fNTrackList; i++) {
188 if (track == fTrackList[i]) {
189 inList = kTRUE;
190 break;
191 }
192 }
193 if (!inList) {
194 fTrackList[fNTrackList] = track;
195 fNTrackList++;
196 }
197
198}
199
57ffa5fb 200//______________________________________________________________________________
d810d0de 201void AliEveMUONData::LoadRecPoints(TTree* tree)
2674c15a 202{
203 //
204 // load reconstructed points from the TreeR
205 // load local trigger information
206 //
207
8c58b039 208 AliMUONVClusterStore *clusterStore = AliMUONVClusterStore::Create(*tree);
209 clusterStore->Clear();
210 clusterStore->Connect(*tree,kFALSE);
51346b82 211
8c58b039 212 tree->GetEvent(0);
51346b82 213
8c58b039 214 AliMUONVCluster *cluster;
eadce74d 215 Int_t detElemId;
8c58b039 216 Double_t clsX, clsY, clsZ, charge;
eadce74d 217
8c58b039 218 for (Int_t ch = 0; ch < 10; ++ch) {
eadce74d 219
8c58b039 220 if (fChambers[ch] == 0) continue;
51346b82 221
8c58b039 222 TIter next(clusterStore->CreateChamberIterator(ch,ch));
51346b82 223
8c58b039 224 while ( ( cluster = static_cast<AliMUONVCluster*>(next()) ) ) {
eadce74d 225
8c58b039 226 detElemId = cluster->GetDetElemId();
51346b82 227
8c58b039 228 clsX = cluster->GetX();
229 clsY = cluster->GetY();
230 clsZ = cluster->GetZ();
231 charge = cluster->GetCharge();
eadce74d 232
8c58b039 233 fChambers[ch]->RegisterCluster(detElemId,0,clsX,clsY,clsZ,charge);
234 fChambers[ch]->RegisterCluster(detElemId,1,clsX,clsY,clsZ,charge);
eadce74d 235
236 }
237
238 }
239
8c58b039 240 delete clusterStore;
51346b82 241
eadce74d 242}
243
fafff680 244//______________________________________________________________________________
245void AliEveMUONData::LoadRecPointsFromESD(Char_t *fileName)
246{
247 //
248 // load reconstructed points stored in AliESDs.root
249 // load local trigger information
250 //
251
252 TFile* esdFile = TFile::Open(fileName);
253 if (!esdFile || !esdFile->IsOpen()) {
254 cout << "opening ESD file " << fileName << "failed" << endl;
255 return;
256 }
257 TTree* esdTree = (TTree*) esdFile->Get("esdTree");
258 if (!esdTree) {
259 cout << "no ESD tree found" << endl;
260 esdFile->Close();
261 return;
262 }
263 AliESDEvent* esdEvent = new AliESDEvent();
264 esdEvent->ReadFromTree(esdTree);
265
266 AliMUONVCluster *cluster;
267 AliMUONTrackParam *trackParam;
268 AliESDMuonTrack *esdTrack;
103e6575 269 AliMUONTrack muonTrack;
fafff680 270 Int_t detElemId, chamber, nTrackParam;
271 Double_t clsX, clsY, clsZ, charge;
272
a15e6d7d 273 if (esdTree->GetEvent(gAliEveEvent->GetEventId()) <= 0) {
274 cout << "fails to read ESD object for event " << gAliEveEvent->GetEventId() << endl;
fafff680 275 return;
276 }
277
278 Int_t nTracks = Int_t(esdEvent->GetNumberOfMuonTracks());
279 for (Int_t iTrack = 0; iTrack < nTracks; iTrack++) {
280 esdTrack = esdEvent->GetMuonTrack(iTrack);
281 if (!esdTrack->ClustersStored()) continue;
ad3c6eda 282 AliMUONESDInterface::ESDToMUON(*esdTrack,muonTrack);
fafff680 283 nTrackParam = muonTrack.GetTrackParamAtCluster()->GetEntries();
284 for(Int_t iCluster = 0; iCluster < nTrackParam; iCluster++) {
285 trackParam = (AliMUONTrackParam *) muonTrack.GetTrackParamAtCluster()->At(iCluster);
286 cluster = trackParam->GetClusterPtr();
287 chamber = cluster->GetChamberId();
288 detElemId = cluster->GetDetElemId();
289 charge = cluster->GetCharge();
290 clsX = cluster->GetX();
291 clsY = cluster->GetY();
292 clsZ = cluster->GetZ();
293
294 fChambers[chamber]->RegisterCluster(detElemId,0,clsX,clsY,clsZ,charge);
295 fChambers[chamber]->RegisterCluster(detElemId,1,clsX,clsY,clsZ,charge);
296
297 }
298 }
299
300 delete esdEvent;
19e6c9f1 301
fafff680 302 esdFile->Close();
303
304}
305
57ffa5fb 306//______________________________________________________________________________
d810d0de 307void AliEveMUONData::LoadHits(TTree* tree)
eadce74d 308{
309 //
310 // load simulation hits from the TreeH
311 //
312
313 TClonesArray *hits = 0;
314 AliMUONHit *mhit;
315 Int_t cha, detElemId, nhits, ntracks;
316 Float_t hitX, hitY, hitZ;
317
318 ntracks = tree->GetEntries();
319 tree->SetBranchAddress("MUONHits",&hits);
320
321 for (Int_t it = 0; it < ntracks; it++) {
322
323 tree->GetEvent(it);
324 nhits = hits->GetEntriesFast();
325
326 for (Int_t ih = 0; ih < nhits; ih++) {
327
328 mhit = (AliMUONHit*)hits->UncheckedAt(ih);
329 hitX = mhit->X();
330 hitY = mhit->Y();
331 hitZ = mhit->Z();
332 detElemId = mhit->DetElemId();
333 cha = mhit->Chamber();
334
335 RegisterTrack(mhit->GetTrack());
336
337 fChambers[cha-1]->RegisterHit(detElemId,hitX,hitY,hitZ);
338
339 }
340 }
341
2674c15a 342}
343
57ffa5fb 344//______________________________________________________________________________
d810d0de 345void AliEveMUONData::LoadDigits(TTree* tree)
832dd5c9 346{
51346b82 347 //
832dd5c9 348 // load digits from the TreeD
349 //
350
351 AliMUONVDigitStore *digitStore = AliMUONVDigitStore::Create(*tree);
352 digitStore->Clear();
353 digitStore->Connect(*tree,0);
354
355 tree->GetEvent(0);
356
357 AliMUONVDigit* digit;
358 TIter next(digitStore->CreateIterator());
51346b82 359
832dd5c9 360 Int_t cathode, detElemId, ix, iy, charge, chamber, adc;
51346b82 361
832dd5c9 362 while ( ( digit = static_cast<AliMUONVDigit*>(next() ) ) )
363 {
364 cathode = digit->Cathode();
365 ix = digit->PadX();
366 iy = digit->PadY();
51346b82 367 detElemId = digit->DetElemId();
832dd5c9 368 charge = (Int_t)digit->Charge();
369 adc = digit->ADC();
370 chamber = detElemId/100 - 1;
371 if (chamber > 9) {
372 fChambers[chamber]->RegisterDigit(detElemId,cathode,ix,iy,charge);
373 } else {
374 fChambers[chamber]->RegisterDigit(detElemId,cathode,ix,iy,adc);
375 }
376 }
51346b82 377
832dd5c9 378 delete digitStore;
379
380}
381
57ffa5fb 382//______________________________________________________________________________
d810d0de 383void AliEveMUONData::LoadRaw(TString fileName)
3626c858 384{
385 //
386 // load raw data from fileName; tracker and trigger data
387 //
388
389 if (fgRawReader == 0) {
390 // check extention to choose the rawdata file format
391 if (fileName.EndsWith("/")) {
392 fgRawReader = new AliRawReaderFile(fileName); // DDL files
393 } else if (fileName.EndsWith(".root")) {
394 fgRawReader = new AliRawReaderRoot(fileName); // ROOT file
395 } else if (!fileName.IsNull()) {
396 fgRawReader = new AliRawReaderDate(fileName); // DATE file
397 }
3626c858 398 }
51346b82 399
3626c858 400 fgRawReader->RewindEvents();
cef26510 401 fgRawReader->Reset();
3626c858 402
403 Int_t iEvent = 0;
51346b82 404 while (fgRawReader->NextEvent())
8d33d1c2 405 {
a15e6d7d 406 if (iEvent != gAliEveEvent->GetEventId())
8d33d1c2 407 {
3626c858 408 iEvent++;
409 continue;
410 }
3626c858 411 break;
cef26510 412 }
3626c858 413
8d33d1c2 414 AliMUONDigitMaker digitMaker;
3626c858 415
8d33d1c2 416 digitMaker.SetMakeTriggerDigits(kTRUE);
3626c858 417
8d33d1c2 418 AliMUONDigitStoreV1 digitStore;
51346b82 419
8d33d1c2 420 digitMaker.Raw2Digits(fgRawReader,&digitStore);
3626c858 421
8d33d1c2 422 AliMUONVDigit* digit;
423 TIter next(digitStore.CreateIterator());
51346b82 424
832dd5c9 425 Int_t cathode, detElemId, ix, iy, charge, chamber, adc;
51346b82 426
8d33d1c2 427 while ( ( digit = static_cast<AliMUONVDigit*>(next() ) ) )
428 {
cef26510 429 cathode = digit->Cathode();
430 ix = digit->PadX();
431 iy = digit->PadY();
51346b82 432 detElemId = digit->DetElemId();
8d33d1c2 433 charge = (Int_t)digit->Charge();
832dd5c9 434 adc = digit->ADC();
cef26510 435 chamber = detElemId/100 - 1;
832dd5c9 436 if (chamber > 9) {
437 fChambers[chamber]->RegisterDigit(detElemId,cathode,ix,iy,charge);
438 } else {
439 fChambers[chamber]->RegisterDigit(detElemId,cathode,ix,iy,adc);
440 }
cef26510 441 }
3626c858 442}
443
57ffa5fb 444//______________________________________________________________________________
a15e6d7d 445Int_t AliEveMUONData::GetTrack(Int_t index) const
eadce74d 446{
447 //
448 // return track stack number for "index"-th track with hits in the chambers
449 //
450
cef26510 451 if (index < 256) {
eadce74d 452 return fTrackList[index];
453 } else {
454 return -1;
455 }
eadce74d 456}
457
57ffa5fb 458//______________________________________________________________________________
d810d0de 459AliEveMUONChamberData* AliEveMUONData::GetChamberData(Int_t chamber)
3626c858 460{
461 //
462 // return chamber data
463 //
464
465 if (chamber < 0 || chamber > 13) return 0;
466
467 //if (fChambers[chamber] == 0) CreateChamber(chamber);
468
469 return fChambers[chamber];
3626c858 470}