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(gAliEveEvent->GetEventId()) <= 0) {
274 cout << "fails to read ESD object for event " << gAliEveEvent->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);
305 //______________________________________________________________________________
306 void AliEveMUONData::LoadHits(TTree* tree)
309 // load simulation hits from the TreeH
312 TClonesArray *hits = 0;
314 Int_t cha, detElemId, nhits, ntracks;
315 Float_t hitX, hitY, hitZ;
317 ntracks = tree->GetEntries();
318 tree->SetBranchAddress("MUONHits",&hits);
320 for (Int_t it = 0; it < ntracks; it++) {
323 nhits = hits->GetEntriesFast();
325 for (Int_t ih = 0; ih < nhits; ih++) {
327 mhit = (AliMUONHit*)hits->UncheckedAt(ih);
331 detElemId = mhit->DetElemId();
332 cha = mhit->Chamber();
334 RegisterTrack(mhit->GetTrack());
336 fChambers[cha-1]->RegisterHit(detElemId,hitX,hitY,hitZ);
343 //______________________________________________________________________________
344 void AliEveMUONData::LoadDigits(TTree* tree)
347 // load digits from the TreeD
350 AliMUONVDigitStore *digitStore = AliMUONVDigitStore::Create(*tree);
352 digitStore->Connect(*tree,0);
356 AliMUONVDigit* digit;
357 TIter next(digitStore->CreateIterator());
359 Int_t cathode, detElemId, ix, iy, charge, chamber, adc;
361 while ( ( digit = static_cast<AliMUONVDigit*>(next() ) ) )
363 cathode = digit->Cathode();
366 detElemId = digit->DetElemId();
367 charge = (Int_t)digit->Charge();
369 chamber = detElemId/100 - 1;
371 fChambers[chamber]->RegisterDigit(detElemId,cathode,ix,iy,charge);
373 fChambers[chamber]->RegisterDigit(detElemId,cathode,ix,iy,adc);
381 //______________________________________________________________________________
382 void AliEveMUONData::LoadRaw(TString fileName)
385 // load raw data from fileName; tracker and trigger data
388 if (fgRawReader == 0) {
389 // check extention to choose the rawdata file format
390 if (fileName.EndsWith("/")) {
391 fgRawReader = new AliRawReaderFile(fileName); // DDL files
392 } else if (fileName.EndsWith(".root")) {
393 fgRawReader = new AliRawReaderRoot(fileName); // ROOT file
394 } else if (!fileName.IsNull()) {
395 fgRawReader = new AliRawReaderDate(fileName); // DATE file
399 fgRawReader->RewindEvents();
400 fgRawReader->Reset();
403 while (fgRawReader->NextEvent())
405 if (iEvent != gAliEveEvent->GetEventId())
413 AliMUONDigitMaker digitMaker;
415 digitMaker.SetMakeTriggerDigits(kTRUE);
417 AliMUONDigitStoreV1 digitStore;
419 digitMaker.Raw2Digits(fgRawReader,&digitStore);
421 AliMUONVDigit* digit;
422 TIter next(digitStore.CreateIterator());
424 Int_t cathode, detElemId, ix, iy, charge, chamber, adc;
426 while ( ( digit = static_cast<AliMUONVDigit*>(next() ) ) )
428 cathode = digit->Cathode();
431 detElemId = digit->DetElemId();
432 charge = (Int_t)digit->Charge();
434 chamber = detElemId/100 - 1;
436 fChambers[chamber]->RegisterDigit(detElemId,cathode,ix,iy,charge);
438 fChambers[chamber]->RegisterDigit(detElemId,cathode,ix,iy,adc);
443 //______________________________________________________________________________
444 Int_t AliEveMUONData::GetTrack(Int_t index) const
447 // return track stack number for "index"-th track with hits in the chambers
451 return fTrackList[index];
457 //______________________________________________________________________________
458 AliEveMUONChamberData* AliEveMUONData::GetChamberData(Int_t chamber)
461 // return chamber data
464 if (chamber < 0 || chamber > 13) return 0;
466 //if (fChambers[chamber] == 0) CreateChamber(chamber);
468 return fChambers[chamber];