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 //______________________________________________________________________________
44 ClassImp(AliEveMUONData)
46 AliRawReader* AliEveMUONData::fgRawReader = 0;
48 //______________________________________________________________________________
49 AliEveMUONData::AliEveMUONData() :
57 for (Int_t i = 0; i < 256; i++) {
65 //______________________________________________________________________________
66 AliEveMUONData::~AliEveMUONData()
76 //______________________________________________________________________________
77 void AliEveMUONData::Reset()
86 for (Int_t i = 0; i < 256; i++) {
92 //______________________________________________________________________________
93 AliEveMUONData::AliEveMUONData(const AliEveMUONData &mdata) :
102 memset(fTrackList,0,256*sizeof(Int_t));
105 //______________________________________________________________________________
106 AliEveMUONData& AliEveMUONData::operator=(const AliEveMUONData &mdata)
109 // Assignment operator
112 if (this != &mdata) {
120 //______________________________________________________________________________
121 void AliEveMUONData::CreateChamber(Int_t chamber)
124 // create data for the chamber with id=chamber (0 to 13)
127 if (fChambers[chamber] == 0)
128 fChambers[chamber] = new AliEveMUONChamberData(chamber);
132 //______________________________________________________________________________
133 void AliEveMUONData::CreateAllChambers()
136 // create all 14 chambers data
139 for (Int_t c = 0; c < 14; ++c)
144 //______________________________________________________________________________
145 void AliEveMUONData::DropAllChambers()
148 // release data from all chambers
151 for (Int_t c = 0; c < 14; ++c) {
153 if (fChambers[c] != 0)
154 fChambers[c]->DropData();
160 //______________________________________________________________________________
161 void AliEveMUONData::DeleteAllChambers()
164 // delete all chambers data
167 for (Int_t c = 0; c < 14; ++c) {
176 //______________________________________________________________________________
177 void AliEveMUONData::RegisterTrack(Int_t track)
180 // register (in a list) a track with hits in the chambers
183 if (fNTrackList == (256-1)) {
184 cout << "Maximum of registered tracks reached..." << endl;
188 Bool_t inList = kFALSE;
189 for (Int_t i = 0; i < fNTrackList; i++) {
190 if (track == fTrackList[i]) {
196 fTrackList[fNTrackList] = track;
202 //______________________________________________________________________________
203 void AliEveMUONData::LoadRecPoints(TTree* tree)
206 // load reconstructed points from the TreeR
207 // load local trigger information
210 AliMUONVClusterStore *clusterStore = AliMUONVClusterStore::Create(*tree);
211 clusterStore->Clear();
212 clusterStore->Connect(*tree,kFALSE);
216 AliMUONVCluster *cluster;
218 Double_t clsX, clsY, clsZ, charge;
220 for (Int_t ch = 0; ch < 10; ++ch) {
222 if (fChambers[ch] == 0) continue;
224 TIter next(clusterStore->CreateChamberIterator(ch,ch));
226 while ( ( cluster = static_cast<AliMUONVCluster*>(next()) ) ) {
228 detElemId = cluster->GetDetElemId();
230 clsX = cluster->GetX();
231 clsY = cluster->GetY();
232 clsZ = cluster->GetZ();
233 charge = cluster->GetCharge();
235 fChambers[ch]->RegisterCluster(detElemId,0,clsX,clsY,clsZ,charge);
236 fChambers[ch]->RegisterCluster(detElemId,1,clsX,clsY,clsZ,charge);
246 //______________________________________________________________________________
247 void AliEveMUONData::LoadRecPointsFromESD(Char_t *fileName)
250 // load reconstructed points stored in AliESDs.root
251 // load local trigger information
254 TFile* esdFile = TFile::Open(fileName);
255 if (!esdFile || !esdFile->IsOpen()) {
256 cout << "opening ESD file " << fileName << "failed" << endl;
259 TTree* esdTree = (TTree*) esdFile->Get("esdTree");
261 cout << "no ESD tree found" << endl;
265 AliESDEvent* esdEvent = new AliESDEvent();
266 esdEvent->ReadFromTree(esdTree);
268 AliMUONVCluster *cluster;
269 AliMUONTrackParam *trackParam;
270 AliESDMuonTrack *esdTrack;
271 AliMUONTrack muonTrack;
272 Int_t detElemId, chamber, nTrackParam;
273 Double_t clsX, clsY, clsZ, charge;
275 if (esdTree->GetEvent(AliEveEventManager::GetMaster()->GetEventId()) <= 0) {
276 cout << "fails to read ESD object for event " << AliEveEventManager::GetMaster()->GetEventId() << endl;
280 Int_t nTracks = Int_t(esdEvent->GetNumberOfMuonTracks());
281 for (Int_t iTrack = 0; iTrack < nTracks; iTrack++) {
282 esdTrack = esdEvent->GetMuonTrack(iTrack);
283 if (!esdTrack->ClustersStored()) continue;
284 AliMUONESDInterface::ESDToMUON(*esdTrack,muonTrack);
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();
296 fChambers[chamber]->RegisterCluster(detElemId,0,clsX,clsY,clsZ,charge);
297 fChambers[chamber]->RegisterCluster(detElemId,1,clsX,clsY,clsZ,charge);
308 //______________________________________________________________________________
309 void AliEveMUONData::LoadHits(TTree* tree)
312 // load simulation hits from the TreeH
315 TClonesArray *hits = 0;
317 Int_t cha, detElemId, nhits, ntracks;
318 Float_t hitX, hitY, hitZ;
320 ntracks = tree->GetEntries();
321 tree->SetBranchAddress("MUONHits",&hits);
323 for (Int_t it = 0; it < ntracks; it++) {
326 nhits = hits->GetEntriesFast();
328 for (Int_t ih = 0; ih < nhits; ih++) {
330 mhit = (AliMUONHit*)hits->UncheckedAt(ih);
334 detElemId = mhit->DetElemId();
335 cha = mhit->Chamber();
337 RegisterTrack(mhit->GetTrack());
339 fChambers[cha-1]->RegisterHit(detElemId,hitX,hitY,hitZ);
346 //______________________________________________________________________________
347 void AliEveMUONData::LoadDigits(TTree* tree)
350 // load digits from the TreeD
353 AliMUONVDigitStore *digitStore = AliMUONVDigitStore::Create(*tree);
355 digitStore->Connect(*tree,0);
359 AliMUONVDigit* digit;
360 TIter next(digitStore->CreateIterator());
362 Int_t cathode, detElemId, ix, iy, charge, chamber, adc;
364 while ( ( digit = static_cast<AliMUONVDigit*>(next() ) ) )
366 cathode = digit->Cathode();
369 detElemId = digit->DetElemId();
370 charge = (Int_t)digit->Charge();
372 chamber = detElemId/100 - 1;
374 fChambers[chamber]->RegisterDigit(detElemId,cathode,ix,iy,charge);
376 fChambers[chamber]->RegisterDigit(detElemId,cathode,ix,iy,adc);
384 //______________________________________________________________________________
385 void AliEveMUONData::LoadRaw(TString fileName)
388 // load raw data from fileName; tracker and trigger data
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
402 fgRawReader->RewindEvents();
403 fgRawReader->Reset();
406 while (fgRawReader->NextEvent())
408 if (iEvent != AliEveEventManager::GetMaster()->GetEventId())
416 AliMUONDigitMaker digitMaker;
418 digitMaker.SetMakeTriggerDigits(kTRUE);
420 AliMUONDigitStoreV1 digitStore;
422 digitMaker.Raw2Digits(fgRawReader,&digitStore);
424 AliMUONVDigit* digit;
425 TIter next(digitStore.CreateIterator());
427 Int_t cathode, detElemId, ix, iy, charge, chamber, adc;
429 while ( ( digit = static_cast<AliMUONVDigit*>(next() ) ) )
431 cathode = digit->Cathode();
434 detElemId = digit->DetElemId();
435 charge = (Int_t)digit->Charge();
437 chamber = detElemId/100 - 1;
439 fChambers[chamber]->RegisterDigit(detElemId,cathode,ix,iy,charge);
441 fChambers[chamber]->RegisterDigit(detElemId,cathode,ix,iy,adc);
446 //______________________________________________________________________________
447 Int_t AliEveMUONData::GetTrack(Int_t index) const
450 // return track stack number for "index"-th track with hits in the chambers
454 return fTrackList[index];
460 //______________________________________________________________________________
461 AliEveMUONChamberData* AliEveMUONData::GetChamberData(Int_t chamber)
464 // return chamber data
467 if (chamber < 0 || chamber > 13) return 0;
469 //if (fChambers[chamber] == 0) CreateChamber(chamber);
471 return fChambers[chamber];