2 // Main authors: Matevz Tadel & Alja Mrak-Tadel & Bogdan Vulpescu: 2006, 2007
4 /**************************************************************************
5 * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. *
6 * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for *
7 * full copyright notice. *
8 **************************************************************************/
12 #include "AliEveMUONData.h"
14 #include <EveDet/AliEveMUONChamberData.h>
15 #include <EveBase/AliEveEventManager.h>
17 #include <AliRawReader.h>
18 #include <AliRawReaderFile.h>
19 #include <AliRawReaderDate.h>
20 #include <AliRawReaderRoot.h>
22 #include <AliMUONDigitMaker.h>
23 #include <AliMUONHit.h>
24 #include <AliMUONVCluster.h>
25 #include "AliMUONVClusterStore.h"
26 #include <AliMUONVDigit.h>
27 #include "AliMUONDigitStoreV1.h"
28 #include "AliMUONVDigitStore.h"
29 #include "AliMUONTrackParam.h"
30 #include "AliMUONTrack.h"
31 #include "AliMUONESDInterface.h"
32 #include "AliESDMuonTrack.h"
33 #include "AliESDEvent.h"
36 #include "TClonesArray.h"
40 //______________________________________________________________________________
46 ClassImp(AliEveMUONData)
48 AliRawReader* AliEveMUONData::fgRawReader = 0;
50 //______________________________________________________________________________
51 AliEveMUONData::AliEveMUONData() :
59 for (Int_t i = 0; i < 256; i++) {
67 //______________________________________________________________________________
68 AliEveMUONData::~AliEveMUONData()
78 //______________________________________________________________________________
79 void AliEveMUONData::Reset()
88 for (Int_t i = 0; i < 256; i++) {
94 //______________________________________________________________________________
95 AliEveMUONData::AliEveMUONData(const AliEveMUONData &mdata) :
104 memset(fTrackList,0,256*sizeof(Int_t));
107 //______________________________________________________________________________
108 AliEveMUONData& AliEveMUONData::operator=(const AliEveMUONData &mdata)
111 // Assignment operator
114 if (this != &mdata) {
122 //______________________________________________________________________________
123 void AliEveMUONData::CreateChamber(Int_t chamber)
126 // create data for the chamber with id=chamber (0 to 13)
129 if (fChambers[chamber] == 0)
130 fChambers[chamber] = new AliEveMUONChamberData(chamber);
134 //______________________________________________________________________________
135 void AliEveMUONData::CreateAllChambers()
138 // create all 14 chambers data
141 for (Int_t c = 0; c < 14; ++c)
146 //______________________________________________________________________________
147 void AliEveMUONData::DropAllChambers()
150 // release data from all chambers
153 for (Int_t c = 0; c < 14; ++c) {
155 if (fChambers[c] != 0)
156 fChambers[c]->DropData();
162 //______________________________________________________________________________
163 void AliEveMUONData::DeleteAllChambers()
166 // delete all chambers data
169 for (Int_t c = 0; c < 14; ++c) {
178 //______________________________________________________________________________
179 void AliEveMUONData::RegisterTrack(Int_t track)
182 // register (in a list) a track with hits in the chambers
185 if (fNTrackList == (256-1)) {
186 cout << "Maximum of registered tracks reached..." << endl;
190 Bool_t inList = kFALSE;
191 for (Int_t i = 0; i < fNTrackList; i++) {
192 if (track == fTrackList[i]) {
198 fTrackList[fNTrackList] = track;
204 //______________________________________________________________________________
205 void AliEveMUONData::LoadRecPoints(TTree* tree)
208 // load reconstructed points from the TreeR
209 // load local trigger information
212 AliMUONVClusterStore *clusterStore = AliMUONVClusterStore::Create(*tree);
213 clusterStore->Clear();
214 clusterStore->Connect(*tree,kFALSE);
218 AliMUONVCluster *cluster;
220 Double_t clsX, clsY, clsZ, charge;
222 for (Int_t ch = 0; ch < 10; ++ch) {
224 if (fChambers[ch] == 0) continue;
226 TIter next(clusterStore->CreateChamberIterator(ch,ch));
228 while ( ( cluster = static_cast<AliMUONVCluster*>(next()) ) ) {
230 detElemId = cluster->GetDetElemId();
232 clsX = cluster->GetX();
233 clsY = cluster->GetY();
234 clsZ = cluster->GetZ();
235 charge = cluster->GetCharge();
237 fChambers[ch]->RegisterCluster(detElemId,0,clsX,clsY,clsZ,charge);
238 fChambers[ch]->RegisterCluster(detElemId,1,clsX,clsY,clsZ,charge);
248 //______________________________________________________________________________
249 void AliEveMUONData::LoadRecPointsFromESD(const Char_t *fileName)
252 // load reconstructed points stored in AliESDs.root
253 // load local trigger information
256 TFile* esdFile = TFile::Open(fileName);
257 if (!esdFile || !esdFile->IsOpen()) {
258 cout << "opening ESD file " << fileName << "failed" << endl;
261 TTree* esdTree = (TTree*) esdFile->Get("esdTree");
263 cout << "no ESD tree found" << endl;
267 AliESDEvent* esdEvent = new AliESDEvent();
268 esdEvent->ReadFromTree(esdTree);
270 AliMUONVCluster *cluster;
271 AliMUONTrackParam *trackParam;
272 AliESDMuonTrack *esdTrack;
273 AliMUONTrack muonTrack;
274 Int_t detElemId, chamber, nTrackParam;
275 Double_t clsX, clsY, clsZ, charge;
277 if (esdTree->GetEvent(AliEveEventManager::GetMaster()->GetEventId()) <= 0) {
278 cout << "fails to read ESD object for event " << AliEveEventManager::GetMaster()->GetEventId() << endl;
282 Int_t nTracks = Int_t(esdEvent->GetNumberOfMuonTracks());
283 for (Int_t iTrack = 0; iTrack < nTracks; iTrack++) {
284 esdTrack = esdEvent->GetMuonTrack(iTrack);
285 if (!esdTrack->ContainTrackerData()) continue;
286 AliMUONESDInterface::ESDToMUON(*esdTrack,muonTrack);
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();
298 fChambers[chamber]->RegisterCluster(detElemId,0,clsX,clsY,clsZ,charge);
299 fChambers[chamber]->RegisterCluster(detElemId,1,clsX,clsY,clsZ,charge);
310 //______________________________________________________________________________
311 void AliEveMUONData::LoadHits(TTree* tree)
314 // load simulation hits from the TreeH
317 TClonesArray *hits = 0;
319 Int_t cha, detElemId, nhits, ntracks;
320 Float_t hitX, hitY, hitZ;
322 ntracks = tree->GetEntries();
323 tree->SetBranchAddress("MUONHits",&hits);
325 for (Int_t it = 0; it < ntracks; it++) {
328 nhits = hits->GetEntriesFast();
330 for (Int_t ih = 0; ih < nhits; ih++) {
332 mhit = (AliMUONHit*)hits->UncheckedAt(ih);
336 detElemId = mhit->DetElemId();
337 cha = mhit->Chamber();
339 RegisterTrack(mhit->GetTrack());
341 fChambers[cha-1]->RegisterHit(detElemId,hitX,hitY,hitZ);
348 //______________________________________________________________________________
349 void AliEveMUONData::LoadDigits(TTree* tree)
352 // load digits from the TreeD
355 AliMUONVDigitStore *digitStore = AliMUONVDigitStore::Create(*tree);
357 digitStore->Connect(*tree,0);
361 AliMUONVDigit* digit;
362 TIter next(digitStore->CreateIterator());
364 Int_t cathode, detElemId, ix, iy, charge, chamber, adc;
366 while ( ( digit = static_cast<AliMUONVDigit*>(next() ) ) )
368 cathode = digit->Cathode();
371 detElemId = digit->DetElemId();
372 charge = (Int_t)digit->Charge();
374 chamber = detElemId/100 - 1;
376 fChambers[chamber]->RegisterDigit(detElemId,cathode,ix,iy,charge);
378 fChambers[chamber]->RegisterDigit(detElemId,cathode,ix,iy,adc);
386 //______________________________________________________________________________
387 void AliEveMUONData::LoadRaw(TString fileName)
390 // load raw data from fileName; tracker and trigger data
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
404 fgRawReader->RewindEvents();
405 fgRawReader->Reset();
408 while (fgRawReader->NextEvent())
410 if (iEvent != AliEveEventManager::GetMaster()->GetEventId())
418 AliMUONDigitMaker digitMaker;
420 digitMaker.SetMakeTriggerDigits(kTRUE);
422 AliMUONDigitStoreV1 digitStore;
424 digitMaker.Raw2Digits(fgRawReader,&digitStore);
426 AliMUONVDigit* digit;
427 TIter next(digitStore.CreateIterator());
429 Int_t cathode, detElemId, ix, iy, charge, chamber, adc;
431 while ( ( digit = static_cast<AliMUONVDigit*>(next() ) ) )
433 cathode = digit->Cathode();
436 detElemId = digit->DetElemId();
437 charge = (Int_t)digit->Charge();
439 chamber = detElemId/100 - 1;
441 fChambers[chamber]->RegisterDigit(detElemId,cathode,ix,iy,charge);
443 fChambers[chamber]->RegisterDigit(detElemId,cathode,ix,iy,adc);
448 //______________________________________________________________________________
449 Int_t AliEveMUONData::GetTrack(Int_t index) const
452 // return track stack number for "index"-th track with hits in the chambers
456 return fTrackList[index];
462 //______________________________________________________________________________
463 AliEveMUONChamberData* AliEveMUONData::GetChamberData(Int_t chamber)
466 // return chamber data
469 if (chamber < 0 || chamber > 13) return 0;
471 //if (fChambers[chamber] == 0) CreateChamber(chamber);
473 return fChambers[chamber];