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 "AliMUONRecoParam.h"
32 #include "AliESDEvent.h"
35 #include "TClonesArray.h"
39 //______________________________________________________________________________
43 ClassImp(AliEveMUONData)
45 AliRawReader* AliEveMUONData::fgRawReader = 0;
47 //______________________________________________________________________________
48 AliEveMUONData::AliEveMUONData() :
56 for (Int_t i = 0; i < 256; i++) {
64 //______________________________________________________________________________
65 AliEveMUONData::~AliEveMUONData()
75 //______________________________________________________________________________
76 void AliEveMUONData::Reset()
85 for (Int_t i = 0; i < 256; i++) {
91 //______________________________________________________________________________
92 AliEveMUONData::AliEveMUONData(const AliEveMUONData &mdata) :
104 //______________________________________________________________________________
105 AliEveMUONData& AliEveMUONData::operator=(const AliEveMUONData &mdata)
108 // Assignment operator
111 if (this != &mdata) {
119 //______________________________________________________________________________
120 void AliEveMUONData::CreateChamber(Int_t chamber)
123 // create data for the chamber with id=chamber (0 to 13)
126 if (fChambers[chamber] == 0)
127 fChambers[chamber] = new AliEveMUONChamberData(chamber);
131 //______________________________________________________________________________
132 void AliEveMUONData::CreateAllChambers()
135 // create all 14 chambers data
138 for (Int_t c = 0; c < 14; ++c)
143 //______________________________________________________________________________
144 void AliEveMUONData::DropAllChambers()
147 // release data from all chambers
150 for (Int_t c = 0; c < 14; ++c) {
152 if (fChambers[c] != 0)
153 fChambers[c]->DropData();
159 //______________________________________________________________________________
160 void AliEveMUONData::DeleteAllChambers()
163 // delete all chambers data
166 for (Int_t c = 0; c < 14; ++c) {
175 //______________________________________________________________________________
176 void AliEveMUONData::RegisterTrack(Int_t track)
179 // register (in a list) a track with hits in the chambers
182 if (fNTrackList == (256-1)) {
183 cout << "Maximum of registered tracks reached..." << endl;
187 Bool_t inList = kFALSE;
188 for (Int_t i = 0; i < fNTrackList; i++) {
189 if (track == fTrackList[i]) {
195 fTrackList[fNTrackList] = track;
201 //______________________________________________________________________________
202 void AliEveMUONData::LoadRecPoints(TTree* tree)
205 // load reconstructed points from the TreeR
206 // load local trigger information
209 AliMUONVClusterStore *clusterStore = AliMUONVClusterStore::Create(*tree);
210 clusterStore->Clear();
211 clusterStore->Connect(*tree,kFALSE);
215 AliMUONVCluster *cluster;
217 Double_t clsX, clsY, clsZ, charge;
219 for (Int_t ch = 0; ch < 10; ++ch) {
221 if (fChambers[ch] == 0) continue;
223 TIter next(clusterStore->CreateChamberIterator(ch,ch));
225 while ( ( cluster = static_cast<AliMUONVCluster*>(next()) ) ) {
227 detElemId = cluster->GetDetElemId();
229 clsX = cluster->GetX();
230 clsY = cluster->GetY();
231 clsZ = cluster->GetZ();
232 charge = cluster->GetCharge();
234 fChambers[ch]->RegisterCluster(detElemId,0,clsX,clsY,clsZ,charge);
235 fChambers[ch]->RegisterCluster(detElemId,1,clsX,clsY,clsZ,charge);
245 //______________________________________________________________________________
246 void AliEveMUONData::LoadRecPointsFromESD(Char_t *fileName)
249 // load reconstructed points stored in AliESDs.root
250 // load local trigger information
253 TFile* esdFile = TFile::Open(fileName);
254 if (!esdFile || !esdFile->IsOpen()) {
255 cout << "opening ESD file " << fileName << "failed" << endl;
258 TTree* esdTree = (TTree*) esdFile->Get("esdTree");
260 cout << "no ESD tree found" << endl;
264 AliESDEvent* esdEvent = new AliESDEvent();
265 esdEvent->ReadFromTree(esdTree);
267 AliMUONVCluster *cluster;
268 AliMUONTrackParam *trackParam;
269 AliESDMuonTrack *esdTrack;
270 AliMUONTrack muonTrack;
271 Int_t detElemId, chamber, nTrackParam;
272 Double_t clsX, clsY, clsZ, charge;
274 if (esdTree->GetEvent(gAliEveEvent->GetEventId()) <= 0) {
275 cout << "fails to read ESD object for event " << gAliEveEvent->GetEventId() << endl;
279 AliMUONRecoParam* recoParam = AliMUONRecoParam::GetCosmicParam();
281 cout << "FIXME: I should get the RecoParams from the OCDB at this point !" << endl;
283 Int_t nTracks = Int_t(esdEvent->GetNumberOfMuonTracks());
284 for (Int_t iTrack = 0; iTrack < nTracks; iTrack++) {
285 esdTrack = esdEvent->GetMuonTrack(iTrack);
286 if (!esdTrack->ClustersStored()) continue;
287 AliMUONESDInterface::ESDToMUON(recoParam,*esdTrack,muonTrack);
288 nTrackParam = muonTrack.GetTrackParamAtCluster()->GetEntries();
289 for(Int_t iCluster = 0; iCluster < nTrackParam; iCluster++) {
290 trackParam = (AliMUONTrackParam *) muonTrack.GetTrackParamAtCluster()->At(iCluster);
291 cluster = trackParam->GetClusterPtr();
292 chamber = cluster->GetChamberId();
293 detElemId = cluster->GetDetElemId();
294 charge = cluster->GetCharge();
295 clsX = cluster->GetX();
296 clsY = cluster->GetY();
297 clsZ = cluster->GetZ();
299 fChambers[chamber]->RegisterCluster(detElemId,0,clsX,clsY,clsZ,charge);
300 fChambers[chamber]->RegisterCluster(detElemId,1,clsX,clsY,clsZ,charge);
313 //______________________________________________________________________________
314 void AliEveMUONData::LoadHits(TTree* tree)
317 // load simulation hits from the TreeH
320 TClonesArray *hits = 0;
322 Int_t cha, detElemId, nhits, ntracks;
323 Float_t hitX, hitY, hitZ;
325 ntracks = tree->GetEntries();
326 tree->SetBranchAddress("MUONHits",&hits);
328 for (Int_t it = 0; it < ntracks; it++) {
331 nhits = hits->GetEntriesFast();
333 for (Int_t ih = 0; ih < nhits; ih++) {
335 mhit = (AliMUONHit*)hits->UncheckedAt(ih);
339 detElemId = mhit->DetElemId();
340 cha = mhit->Chamber();
342 RegisterTrack(mhit->GetTrack());
344 fChambers[cha-1]->RegisterHit(detElemId,hitX,hitY,hitZ);
351 //______________________________________________________________________________
352 void AliEveMUONData::LoadDigits(TTree* tree)
355 // load digits from the TreeD
358 AliMUONVDigitStore *digitStore = AliMUONVDigitStore::Create(*tree);
360 digitStore->Connect(*tree,0);
364 AliMUONVDigit* digit;
365 TIter next(digitStore->CreateIterator());
367 Int_t cathode, detElemId, ix, iy, charge, chamber, adc;
369 while ( ( digit = static_cast<AliMUONVDigit*>(next() ) ) )
371 cathode = digit->Cathode();
374 detElemId = digit->DetElemId();
375 charge = (Int_t)digit->Charge();
377 chamber = detElemId/100 - 1;
379 fChambers[chamber]->RegisterDigit(detElemId,cathode,ix,iy,charge);
381 fChambers[chamber]->RegisterDigit(detElemId,cathode,ix,iy,adc);
389 //______________________________________________________________________________
390 void AliEveMUONData::LoadRaw(TString fileName)
393 // load raw data from fileName; tracker and trigger data
396 if (fgRawReader == 0) {
397 // check extention to choose the rawdata file format
398 if (fileName.EndsWith("/")) {
399 fgRawReader = new AliRawReaderFile(fileName); // DDL files
400 } else if (fileName.EndsWith(".root")) {
401 fgRawReader = new AliRawReaderRoot(fileName); // ROOT file
402 } else if (!fileName.IsNull()) {
403 fgRawReader = new AliRawReaderDate(fileName); // DATE file
407 fgRawReader->RewindEvents();
408 fgRawReader->Reset();
411 while (fgRawReader->NextEvent())
413 if (iEvent != gAliEveEvent->GetEventId())
421 AliMUONDigitMaker digitMaker;
423 digitMaker.SetMakeTriggerDigits(kTRUE);
425 AliMUONDigitStoreV1 digitStore;
427 digitMaker.Raw2Digits(fgRawReader,&digitStore);
429 AliMUONVDigit* digit;
430 TIter next(digitStore.CreateIterator());
432 Int_t cathode, detElemId, ix, iy, charge, chamber, adc;
434 while ( ( digit = static_cast<AliMUONVDigit*>(next() ) ) )
436 cathode = digit->Cathode();
439 detElemId = digit->DetElemId();
440 charge = (Int_t)digit->Charge();
442 chamber = detElemId/100 - 1;
444 fChambers[chamber]->RegisterDigit(detElemId,cathode,ix,iy,charge);
446 fChambers[chamber]->RegisterDigit(detElemId,cathode,ix,iy,adc);
451 //______________________________________________________________________________
452 Int_t AliEveMUONData::GetTrack(Int_t index) const
455 // return track stack number for "index"-th track with hits in the chambers
459 return fTrackList[index];
465 //______________________________________________________________________________
466 AliEveMUONChamberData* AliEveMUONData::GetChamberData(Int_t chamber)
469 // return chamber data
472 if (chamber < 0 || chamber > 13) return 0;
474 //if (fChambers[chamber] == 0) CreateChamber(chamber);
476 return fChambers[chamber];