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