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 **************************************************************************/
10 #include "AliEveMUONData.h"
12 #include <EveDet/AliEveMUONChamberData.h>
13 #include <EveBase/AliEveEventManager.h>
15 #include <AliRawReader.h>
16 #include <AliRawReaderFile.h>
17 #include <AliRawReaderDate.h>
18 #include <AliRawReaderRoot.h>
20 #include <AliMUONDigitMaker.h>
21 #include <AliMUONHit.h>
22 #include <AliMUONVCluster.h>
23 #include "AliMUONVClusterStore.h"
24 #include <AliMUONVDigit.h>
25 #include "AliMUONDigitStoreV1.h"
26 #include "AliMUONVDigitStore.h"
27 #include "AliMUONTrackParam.h"
28 #include "AliMUONTrack.h"
29 #include "AliMUONESDInterface.h"
30 #include "AliESDMuonTrack.h"
31 #include "AliESDEvent.h"
34 #include "TClonesArray.h"
38 //______________________________________________________________________________
42 ClassImp(AliEveMUONData)
44 AliRawReader* AliEveMUONData::fgRawReader = 0;
46 //______________________________________________________________________________
47 AliEveMUONData::AliEveMUONData() :
55 for (Int_t i = 0; i < 256; i++) {
63 //______________________________________________________________________________
64 AliEveMUONData::~AliEveMUONData()
74 //______________________________________________________________________________
75 void AliEveMUONData::Reset()
84 for (Int_t i = 0; i < 256; i++) {
90 //______________________________________________________________________________
91 AliEveMUONData::AliEveMUONData(const AliEveMUONData &mdata) :
103 //______________________________________________________________________________
104 AliEveMUONData& AliEveMUONData::operator=(const AliEveMUONData &mdata)
107 // Assignment operator
110 if (this != &mdata) {
118 //______________________________________________________________________________
119 void AliEveMUONData::CreateChamber(Int_t chamber)
122 // create data for the chamber with id=chamber (0 to 13)
125 if (fChambers[chamber] == 0)
126 fChambers[chamber] = new AliEveMUONChamberData(chamber);
130 //______________________________________________________________________________
131 void AliEveMUONData::CreateAllChambers()
134 // create all 14 chambers data
137 for (Int_t c = 0; c < 14; ++c)
142 //______________________________________________________________________________
143 void AliEveMUONData::DropAllChambers()
146 // release data from all chambers
149 for (Int_t c = 0; c < 14; ++c) {
151 if (fChambers[c] != 0)
152 fChambers[c]->DropData();
158 //______________________________________________________________________________
159 void AliEveMUONData::DeleteAllChambers()
162 // delete all chambers data
165 for (Int_t c = 0; c < 14; ++c) {
174 //______________________________________________________________________________
175 void AliEveMUONData::RegisterTrack(Int_t track)
178 // register (in a list) a track with hits in the chambers
181 if (fNTrackList == (256-1)) {
182 cout << "Maximum of registered tracks reached..." << endl;
186 Bool_t inList = kFALSE;
187 for (Int_t i = 0; i < fNTrackList; i++) {
188 if (track == fTrackList[i]) {
194 fTrackList[fNTrackList] = track;
200 //______________________________________________________________________________
201 void AliEveMUONData::LoadRecPoints(TTree* tree)
204 // load reconstructed points from the TreeR
205 // load local trigger information
208 AliMUONVClusterStore *clusterStore = AliMUONVClusterStore::Create(*tree);
209 clusterStore->Clear();
210 clusterStore->Connect(*tree,kFALSE);
214 AliMUONVCluster *cluster;
216 Double_t clsX, clsY, clsZ, charge;
218 for (Int_t ch = 0; ch < 10; ++ch) {
220 if (fChambers[ch] == 0) continue;
222 TIter next(clusterStore->CreateChamberIterator(ch,ch));
224 while ( ( cluster = static_cast<AliMUONVCluster*>(next()) ) ) {
226 detElemId = cluster->GetDetElemId();
228 clsX = cluster->GetX();
229 clsY = cluster->GetY();
230 clsZ = cluster->GetZ();
231 charge = cluster->GetCharge();
233 fChambers[ch]->RegisterCluster(detElemId,0,clsX,clsY,clsZ,charge);
234 fChambers[ch]->RegisterCluster(detElemId,1,clsX,clsY,clsZ,charge);
244 //______________________________________________________________________________
245 void AliEveMUONData::LoadRecPointsFromESD(Char_t *fileName)
248 // load reconstructed points stored in AliESDs.root
249 // load local trigger information
252 TFile* esdFile = TFile::Open(fileName);
253 if (!esdFile || !esdFile->IsOpen()) {
254 cout << "opening ESD file " << fileName << "failed" << endl;
257 TTree* esdTree = (TTree*) esdFile->Get("esdTree");
259 cout << "no ESD tree found" << endl;
263 AliESDEvent* esdEvent = new AliESDEvent();
264 esdEvent->ReadFromTree(esdTree);
266 AliMUONVCluster *cluster;
267 AliMUONTrackParam *trackParam;
268 AliESDMuonTrack *esdTrack;
269 AliMUONTrack muonTrack;
270 Int_t detElemId, chamber, nTrackParam;
271 Double_t clsX, clsY, clsZ, charge;
273 if (esdTree->GetEvent(AliEveEventManager::GetMaster()->GetEventId()) <= 0) {
274 cout << "fails to read ESD object for event " << AliEveEventManager::GetMaster()->GetEventId() << endl;
278 Int_t nTracks = Int_t(esdEvent->GetNumberOfMuonTracks());
279 for (Int_t iTrack = 0; iTrack < nTracks; iTrack++) {
280 esdTrack = esdEvent->GetMuonTrack(iTrack);
281 if (!esdTrack->ClustersStored()) continue;
282 AliMUONESDInterface::ESDToMUON(*esdTrack,muonTrack);
283 nTrackParam = muonTrack.GetTrackParamAtCluster()->GetEntries();
284 for(Int_t iCluster = 0; iCluster < nTrackParam; iCluster++) {
285 trackParam = (AliMUONTrackParam *) muonTrack.GetTrackParamAtCluster()->At(iCluster);
286 cluster = trackParam->GetClusterPtr();
287 chamber = cluster->GetChamberId();
288 detElemId = cluster->GetDetElemId();
289 charge = cluster->GetCharge();
290 clsX = cluster->GetX();
291 clsY = cluster->GetY();
292 clsZ = cluster->GetZ();
294 fChambers[chamber]->RegisterCluster(detElemId,0,clsX,clsY,clsZ,charge);
295 fChambers[chamber]->RegisterCluster(detElemId,1,clsX,clsY,clsZ,charge);
306 //______________________________________________________________________________
307 void AliEveMUONData::LoadHits(TTree* tree)
310 // load simulation hits from the TreeH
313 TClonesArray *hits = 0;
315 Int_t cha, detElemId, nhits, ntracks;
316 Float_t hitX, hitY, hitZ;
318 ntracks = tree->GetEntries();
319 tree->SetBranchAddress("MUONHits",&hits);
321 for (Int_t it = 0; it < ntracks; it++) {
324 nhits = hits->GetEntriesFast();
326 for (Int_t ih = 0; ih < nhits; ih++) {
328 mhit = (AliMUONHit*)hits->UncheckedAt(ih);
332 detElemId = mhit->DetElemId();
333 cha = mhit->Chamber();
335 RegisterTrack(mhit->GetTrack());
337 fChambers[cha-1]->RegisterHit(detElemId,hitX,hitY,hitZ);
344 //______________________________________________________________________________
345 void AliEveMUONData::LoadDigits(TTree* tree)
348 // load digits from the TreeD
351 AliMUONVDigitStore *digitStore = AliMUONVDigitStore::Create(*tree);
353 digitStore->Connect(*tree,0);
357 AliMUONVDigit* digit;
358 TIter next(digitStore->CreateIterator());
360 Int_t cathode, detElemId, ix, iy, charge, chamber, adc;
362 while ( ( digit = static_cast<AliMUONVDigit*>(next() ) ) )
364 cathode = digit->Cathode();
367 detElemId = digit->DetElemId();
368 charge = (Int_t)digit->Charge();
370 chamber = detElemId/100 - 1;
372 fChambers[chamber]->RegisterDigit(detElemId,cathode,ix,iy,charge);
374 fChambers[chamber]->RegisterDigit(detElemId,cathode,ix,iy,adc);
382 //______________________________________________________________________________
383 void AliEveMUONData::LoadRaw(TString fileName)
386 // load raw data from fileName; tracker and trigger data
389 if (fgRawReader == 0) {
390 // check extention to choose the rawdata file format
391 if (fileName.EndsWith("/")) {
392 fgRawReader = new AliRawReaderFile(fileName); // DDL files
393 } else if (fileName.EndsWith(".root")) {
394 fgRawReader = new AliRawReaderRoot(fileName); // ROOT file
395 } else if (!fileName.IsNull()) {
396 fgRawReader = new AliRawReaderDate(fileName); // DATE file
400 fgRawReader->RewindEvents();
401 fgRawReader->Reset();
404 while (fgRawReader->NextEvent())
406 if (iEvent != AliEveEventManager::GetMaster()->GetEventId())
414 AliMUONDigitMaker digitMaker;
416 digitMaker.SetMakeTriggerDigits(kTRUE);
418 AliMUONDigitStoreV1 digitStore;
420 digitMaker.Raw2Digits(fgRawReader,&digitStore);
422 AliMUONVDigit* digit;
423 TIter next(digitStore.CreateIterator());
425 Int_t cathode, detElemId, ix, iy, charge, chamber, adc;
427 while ( ( digit = static_cast<AliMUONVDigit*>(next() ) ) )
429 cathode = digit->Cathode();
432 detElemId = digit->DetElemId();
433 charge = (Int_t)digit->Charge();
435 chamber = detElemId/100 - 1;
437 fChambers[chamber]->RegisterDigit(detElemId,cathode,ix,iy,charge);
439 fChambers[chamber]->RegisterDigit(detElemId,cathode,ix,iy,adc);
444 //______________________________________________________________________________
445 Int_t AliEveMUONData::GetTrack(Int_t index) const
448 // return track stack number for "index"-th track with hits in the chambers
452 return fTrackList[index];
458 //______________________________________________________________________________
459 AliEveMUONChamberData* AliEveMUONData::GetChamberData(Int_t chamber)
462 // return chamber data
465 if (chamber < 0 || chamber > 13) return 0;
467 //if (fChambers[chamber] == 0) CreateChamber(chamber);
469 return fChambers[chamber];