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