]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVE/EveDet/AliEveMUONData.cxx
- new interface beween MUON objects (track/cluster/digit) and ESD objects (track...
[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
361fa326 20#include <AliLog.h>
3626c858 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"
cef26510 37#include "TList.h"
fafff680 38#include "TFile.h"
d810d0de 39
3626c858 40
57ffa5fb 41//______________________________________________________________________________
d810d0de 42// AliEveMUONData
3626c858 43//
44
d810d0de 45ClassImp(AliEveMUONData)
3626c858 46
d810d0de 47AliRawReader* AliEveMUONData::fgRawReader = 0;
3626c858 48
57ffa5fb 49//______________________________________________________________________________
d810d0de 50AliEveMUONData::AliEveMUONData() :
eadce74d 51 fChambers(14),
52 fNTrackList(0)
3626c858 53{
54 //
55 // Constructor
56 //
51346b82 57
cef26510 58 for (Int_t i = 0; i < 256; i++) {
eadce74d 59 fTrackList[i] = -1;
60 }
61
3626c858 62 CreateAllChambers();
63
64}
65
57ffa5fb 66//______________________________________________________________________________
d810d0de 67AliEveMUONData::~AliEveMUONData()
3626c858 68{
69 //
70 // Destructor
71 //
72
73 DeleteAllChambers();
74
3626c858 75}
76
57ffa5fb 77//______________________________________________________________________________
d810d0de 78void AliEveMUONData::Reset()
eadce74d 79{
80 //
81 // Reset data
82 //
83
84 //DropAllChambers();
85
86 fNTrackList = 0;
cef26510 87 for (Int_t i = 0; i < 256; i++) {
eadce74d 88 fTrackList[i] = -1;
89 }
90
91}
92
57ffa5fb 93//______________________________________________________________________________
d810d0de 94AliEveMUONData::AliEveMUONData(const AliEveMUONData &mdata) :
e4204218 95 TObject(mdata),
84aff7a4 96 TEveRefCnt(),
8d33d1c2 97 fChambers(14),
98 fNTrackList(0)
3626c858 99{
100 //
101 // Copy constructor
102 //
103
104}
105
57ffa5fb 106//______________________________________________________________________________
d810d0de 107AliEveMUONData& AliEveMUONData::operator=(const AliEveMUONData &mdata)
3626c858 108{
109 //
110 // Assignment operator
111 //
112
113 if (this != &mdata) {
114
115 }
116
117 return *this;
118
119}
120
57ffa5fb 121//______________________________________________________________________________
d810d0de 122void AliEveMUONData::CreateChamber(Int_t chamber)
3626c858 123{
51346b82 124 //
3626c858 125 // create data for the chamber with id=chamber (0 to 13)
126 //
127
128 if (fChambers[chamber] == 0)
d810d0de 129 fChambers[chamber] = new AliEveMUONChamberData(chamber);
3626c858 130
131}
132
57ffa5fb 133//______________________________________________________________________________
d810d0de 134void AliEveMUONData::CreateAllChambers()
3626c858 135{
136 //
137 // create all 14 chambers data
138 //
139
140 for (Int_t c = 0; c < 14; ++c)
141 CreateChamber(c);
142
143}
144
57ffa5fb 145//______________________________________________________________________________
d810d0de 146void AliEveMUONData::DropAllChambers()
3626c858 147{
51346b82 148 //
149 // release data from all chambers
3626c858 150 //
151
152 for (Int_t c = 0; c < 14; ++c) {
153
154 if (fChambers[c] != 0)
155 fChambers[c]->DropData();
156
157 }
158
159}
160
57ffa5fb 161//______________________________________________________________________________
d810d0de 162void AliEveMUONData::DeleteAllChambers()
3626c858 163{
164 //
165 // delete all chambers data
166 //
167
168 for (Int_t c = 0; c < 14; ++c) {
169
170 delete fChambers[c];
171 fChambers[c] = 0;
172
173 }
174
175}
176
57ffa5fb 177//______________________________________________________________________________
d810d0de 178void AliEveMUONData::RegisterTrack(Int_t track)
eadce74d 179{
180 //
181 // register (in a list) a track with hits in the chambers
182 //
183
cef26510 184 if (fNTrackList == (256-1)) {
eadce74d 185 cout << "Maximum of registered tracks reached..." << endl;
186 return;
187 }
188
189 Bool_t inList = kFALSE;
190 for (Int_t i = 0; i < fNTrackList; i++) {
191 if (track == fTrackList[i]) {
192 inList = kTRUE;
193 break;
194 }
195 }
196 if (!inList) {
197 fTrackList[fNTrackList] = track;
198 fNTrackList++;
199 }
200
201}
202
57ffa5fb 203//______________________________________________________________________________
d810d0de 204void AliEveMUONData::LoadRecPoints(TTree* tree)
2674c15a 205{
206 //
207 // load reconstructed points from the TreeR
208 // load local trigger information
209 //
210
8c58b039 211 AliMUONVClusterStore *clusterStore = AliMUONVClusterStore::Create(*tree);
212 clusterStore->Clear();
213 clusterStore->Connect(*tree,kFALSE);
51346b82 214
8c58b039 215 tree->GetEvent(0);
51346b82 216
8c58b039 217 AliMUONVCluster *cluster;
eadce74d 218 Int_t detElemId;
8c58b039 219 Double_t clsX, clsY, clsZ, charge;
eadce74d 220
8c58b039 221 for (Int_t ch = 0; ch < 10; ++ch) {
eadce74d 222
8c58b039 223 if (fChambers[ch] == 0) continue;
51346b82 224
8c58b039 225 TIter next(clusterStore->CreateChamberIterator(ch,ch));
51346b82 226
8c58b039 227 while ( ( cluster = static_cast<AliMUONVCluster*>(next()) ) ) {
eadce74d 228
8c58b039 229 detElemId = cluster->GetDetElemId();
51346b82 230
8c58b039 231 clsX = cluster->GetX();
232 clsY = cluster->GetY();
233 clsZ = cluster->GetZ();
234 charge = cluster->GetCharge();
eadce74d 235
8c58b039 236 fChambers[ch]->RegisterCluster(detElemId,0,clsX,clsY,clsZ,charge);
237 fChambers[ch]->RegisterCluster(detElemId,1,clsX,clsY,clsZ,charge);
eadce74d 238
239 }
240
241 }
242
8c58b039 243 delete clusterStore;
51346b82 244
eadce74d 245}
246
fafff680 247//______________________________________________________________________________
248void AliEveMUONData::LoadRecPointsFromESD(Char_t *fileName)
249{
250 //
251 // load reconstructed points stored in AliESDs.root
252 // load local trigger information
253 //
254
255 TFile* esdFile = TFile::Open(fileName);
256 if (!esdFile || !esdFile->IsOpen()) {
257 cout << "opening ESD file " << fileName << "failed" << endl;
258 return;
259 }
260 TTree* esdTree = (TTree*) esdFile->Get("esdTree");
261 if (!esdTree) {
262 cout << "no ESD tree found" << endl;
263 esdFile->Close();
264 return;
265 }
266 AliESDEvent* esdEvent = new AliESDEvent();
267 esdEvent->ReadFromTree(esdTree);
268
269 AliMUONVCluster *cluster;
270 AliMUONTrackParam *trackParam;
271 AliESDMuonTrack *esdTrack;
103e6575 272 AliMUONTrack muonTrack;
fafff680 273 Int_t detElemId, chamber, nTrackParam;
274 Double_t clsX, clsY, clsZ, charge;
275
276 if (esdTree->GetEvent(gEvent->GetEventId()) <= 0) {
277 cout << "fails to read ESD object for event " << gEvent->GetEventId() << endl;
278 return;
279 }
280
281 Int_t nTracks = Int_t(esdEvent->GetNumberOfMuonTracks());
282 for (Int_t iTrack = 0; iTrack < nTracks; iTrack++) {
283 esdTrack = esdEvent->GetMuonTrack(iTrack);
284 if (!esdTrack->ClustersStored()) continue;
103e6575 285 AliMUONESDInterface::ESDToMUON(*esdTrack,muonTrack);
fafff680 286 nTrackParam = muonTrack.GetTrackParamAtCluster()->GetEntries();
287 for(Int_t iCluster = 0; iCluster < nTrackParam; iCluster++) {
288 trackParam = (AliMUONTrackParam *) muonTrack.GetTrackParamAtCluster()->At(iCluster);
289 cluster = trackParam->GetClusterPtr();
290 chamber = cluster->GetChamberId();
291 detElemId = cluster->GetDetElemId();
292 charge = cluster->GetCharge();
293 clsX = cluster->GetX();
294 clsY = cluster->GetY();
295 clsZ = cluster->GetZ();
296
297 fChambers[chamber]->RegisterCluster(detElemId,0,clsX,clsY,clsZ,charge);
298 fChambers[chamber]->RegisterCluster(detElemId,1,clsX,clsY,clsZ,charge);
299
300 }
301 }
302
303 delete esdEvent;
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 {
51346b82 408 if (iEvent != gEvent->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 }
832dd5c9 444
3626c858 445}
446
57ffa5fb 447//______________________________________________________________________________
d810d0de 448Int_t AliEveMUONData::GetTrack(Int_t index)
eadce74d 449{
450 //
451 // return track stack number for "index"-th track with hits in the chambers
452 //
453
cef26510 454 if (index < 256) {
eadce74d 455 return fTrackList[index];
456 } else {
457 return -1;
458 }
459
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];
474
475}