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