]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/EveDet/AliEveMUONData.cxx
- synchronized the overlay macro to the changes of the drawing one
[u/mrichter/AliRoot.git] / EVE / EveDet / AliEveMUONData.cxx
1 // $Id$
2 // Main authors: Matevz Tadel & Alja Mrak-Tadel & Bogdan Vulpescu: 2006, 2007
3
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  **************************************************************************/
9
10 #include <string.h>
11
12 #include "AliEveMUONData.h"
13
14 #include <EveDet/AliEveMUONChamberData.h>
15 #include <EveBase/AliEveEventManager.h>
16
17 #include <AliRawReader.h>
18 #include <AliRawReaderFile.h>
19 #include <AliRawReaderDate.h>
20 #include <AliRawReaderRoot.h>
21
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"
34 #include "TTree.h"
35 #include "TString.h"
36 #include "TClonesArray.h"
37 #include "TFile.h"
38
39
40 //______________________________________________________________________________
41 // AliEveMUONData
42 //
43
44 ClassImp(AliEveMUONData)
45
46 AliRawReader*            AliEveMUONData::fgRawReader        = 0;
47
48 //______________________________________________________________________________
49 AliEveMUONData::AliEveMUONData() :
50   fChambers(14),
51   fNTrackList(0)
52 {
53   //
54   // Constructor
55   //
56
57   for (Int_t i = 0; i < 256; i++) {
58     fTrackList[i] = -1;
59   }
60
61   CreateAllChambers();
62
63 }
64
65 //______________________________________________________________________________
66 AliEveMUONData::~AliEveMUONData()
67 {
68   //
69   // Destructor
70   //
71
72   DeleteAllChambers();
73
74 }
75
76 //______________________________________________________________________________
77 void AliEveMUONData::Reset()
78 {
79   //
80   // Reset data
81   //
82
83   //DropAllChambers();
84
85   fNTrackList = 0;
86   for (Int_t i = 0; i < 256; i++) {
87     fTrackList[i] = -1;
88   }
89
90 }
91
92 //______________________________________________________________________________
93 AliEveMUONData::AliEveMUONData(const AliEveMUONData &mdata) :
94   TObject(mdata),
95   TEveRefCnt(),
96   fChambers(14),
97   fNTrackList(0)
98 {
99   //
100   // Copy constructor
101   //
102   memset(fTrackList,0,256*sizeof(Int_t));
103 }
104
105 //______________________________________________________________________________
106 AliEveMUONData& AliEveMUONData::operator=(const AliEveMUONData &mdata)
107 {
108   //
109   // Assignment operator
110   //
111
112   if (this != &mdata) {
113
114   }
115
116   return *this;
117
118 }
119
120 //______________________________________________________________________________
121 void AliEveMUONData::CreateChamber(Int_t chamber)
122 {
123   //
124   // create data for the chamber with id=chamber (0 to 13)
125   //
126
127   if (fChambers[chamber] == 0)
128     fChambers[chamber] = new AliEveMUONChamberData(chamber);
129
130 }
131
132 //______________________________________________________________________________
133 void AliEveMUONData::CreateAllChambers()
134 {
135   //
136   // create all 14 chambers data
137   //
138
139   for (Int_t c = 0; c < 14; ++c)
140     CreateChamber(c);
141
142 }
143
144 //______________________________________________________________________________
145 void AliEveMUONData::DropAllChambers()
146 {
147   //
148   // release data from all chambers
149   //
150
151   for (Int_t c = 0; c < 14; ++c) {
152
153     if (fChambers[c] != 0)
154       fChambers[c]->DropData();
155
156   }
157
158 }
159
160 //______________________________________________________________________________
161 void AliEveMUONData::DeleteAllChambers()
162 {
163   //
164   // delete all chambers data
165   //
166
167   for (Int_t c = 0; c < 14; ++c) {
168
169     delete fChambers[c];
170     fChambers[c] = 0;
171
172   }
173
174 }
175
176 //______________________________________________________________________________
177 void AliEveMUONData::RegisterTrack(Int_t track)
178 {
179   //
180   // register (in a list) a track with hits in the chambers
181   //
182
183   if (fNTrackList == (256-1)) {
184     cout << "Maximum of registered tracks reached..." << endl;
185     return;
186   }
187
188   Bool_t inList = kFALSE;
189   for (Int_t i = 0; i < fNTrackList; i++) {
190     if (track == fTrackList[i]) {
191       inList = kTRUE;
192       break;
193     }
194   }
195   if (!inList) {
196     fTrackList[fNTrackList] = track;
197     fNTrackList++;
198   }
199
200 }
201
202 //______________________________________________________________________________
203 void AliEveMUONData::LoadRecPoints(TTree* tree)
204 {
205   //
206   // load reconstructed points from the TreeR
207   // load local trigger information
208   //
209
210   AliMUONVClusterStore *clusterStore = AliMUONVClusterStore::Create(*tree);
211   clusterStore->Clear();
212   clusterStore->Connect(*tree,kFALSE);
213
214   tree->GetEvent(0);
215
216   AliMUONVCluster *cluster;
217   Int_t detElemId;
218   Double_t clsX, clsY, clsZ, charge;
219
220   for (Int_t ch = 0; ch < 10; ++ch) {
221
222     if (fChambers[ch] == 0) continue;
223
224     TIter next(clusterStore->CreateChamberIterator(ch,ch));
225
226     while ( ( cluster = static_cast<AliMUONVCluster*>(next()) ) ) {
227
228       detElemId = cluster->GetDetElemId();
229
230       clsX   = cluster->GetX();
231       clsY   = cluster->GetY();
232       clsZ   = cluster->GetZ();
233       charge = cluster->GetCharge();
234
235       fChambers[ch]->RegisterCluster(detElemId,0,clsX,clsY,clsZ,charge);
236       fChambers[ch]->RegisterCluster(detElemId,1,clsX,clsY,clsZ,charge);
237
238     }
239
240   }
241
242   delete clusterStore;
243
244 }
245
246 //______________________________________________________________________________
247 void AliEveMUONData::LoadRecPointsFromESD(Char_t *fileName)
248 {
249   //
250   // load reconstructed points stored in AliESDs.root
251   // load local trigger information
252   //
253
254   TFile* esdFile = TFile::Open(fileName);
255   if (!esdFile || !esdFile->IsOpen()) {
256     cout << "opening ESD file " << fileName << "failed" << endl;
257     return;
258   }
259   TTree* esdTree = (TTree*) esdFile->Get("esdTree");
260   if (!esdTree) {
261     cout << "no ESD tree found" << endl;
262     esdFile->Close();
263     return;
264   }
265   AliESDEvent* esdEvent = new AliESDEvent();
266   esdEvent->ReadFromTree(esdTree);
267
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;
274   
275   if (esdTree->GetEvent(AliEveEventManager::GetMaster()->GetEventId()) <= 0) {
276     cout << "fails to read ESD object for event " << AliEveEventManager::GetMaster()->GetEventId() << endl;
277     return;
278   }
279     
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();
295       
296       fChambers[chamber]->RegisterCluster(detElemId,0,clsX,clsY,clsZ,charge);
297       fChambers[chamber]->RegisterCluster(detElemId,1,clsX,clsY,clsZ,charge);
298       
299     }
300   }
301
302   delete esdEvent;
303   
304   esdFile->Close();
305
306 }
307
308 //______________________________________________________________________________
309 void AliEveMUONData::LoadHits(TTree* tree)
310 {
311   //
312   // load simulation hits from the TreeH
313   //
314
315   TClonesArray *hits = 0;
316   AliMUONHit  *mhit;
317   Int_t cha, detElemId, nhits, ntracks;
318   Float_t hitX, hitY, hitZ;
319
320   ntracks = tree->GetEntries();
321   tree->SetBranchAddress("MUONHits",&hits);
322
323   for (Int_t it = 0; it < ntracks; it++) {
324
325     tree->GetEvent(it);
326     nhits = hits->GetEntriesFast();
327
328     for (Int_t ih = 0; ih < nhits; ih++) {
329
330       mhit = (AliMUONHit*)hits->UncheckedAt(ih);
331       hitX = mhit->X();
332       hitY = mhit->Y();
333       hitZ = mhit->Z();
334       detElemId = mhit->DetElemId();
335       cha = mhit->Chamber();
336
337       RegisterTrack(mhit->GetTrack());
338
339       fChambers[cha-1]->RegisterHit(detElemId,hitX,hitY,hitZ);
340
341     }
342   }
343
344 }
345
346 //______________________________________________________________________________
347 void AliEveMUONData::LoadDigits(TTree* tree)
348 {
349   //
350   // load digits from the TreeD
351   //
352
353   AliMUONVDigitStore *digitStore = AliMUONVDigitStore::Create(*tree);
354   digitStore->Clear();
355   digitStore->Connect(*tree,0);
356
357   tree->GetEvent(0);
358
359   AliMUONVDigit* digit;
360   TIter next(digitStore->CreateIterator());
361
362   Int_t cathode, detElemId, ix, iy, charge, chamber, adc;
363
364   while ( ( digit = static_cast<AliMUONVDigit*>(next() ) ) )
365     {
366       cathode   = digit->Cathode();
367       ix        = digit->PadX();
368       iy        = digit->PadY();
369       detElemId = digit->DetElemId();
370       charge    = (Int_t)digit->Charge();
371       adc       = digit->ADC();
372       chamber   = detElemId/100 - 1;
373       if (chamber > 9) {
374         fChambers[chamber]->RegisterDigit(detElemId,cathode,ix,iy,charge);
375       } else {
376         fChambers[chamber]->RegisterDigit(detElemId,cathode,ix,iy,adc);
377       }
378     }
379
380   delete digitStore;
381
382 }
383
384 //______________________________________________________________________________
385 void AliEveMUONData::LoadRaw(TString fileName)
386 {
387   //
388   // load raw data from fileName; tracker and trigger data
389   //
390
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
399     }
400   }
401
402   fgRawReader->RewindEvents();
403   fgRawReader->Reset();
404
405   Int_t iEvent = 0;
406   while (fgRawReader->NextEvent())
407   {
408     if (iEvent != AliEveEventManager::GetMaster()->GetEventId())
409     {
410       iEvent++;
411       continue;
412     }
413     break;
414   }
415
416   AliMUONDigitMaker digitMaker;
417
418   digitMaker.SetMakeTriggerDigits(kTRUE);
419
420   AliMUONDigitStoreV1 digitStore;
421
422   digitMaker.Raw2Digits(fgRawReader,&digitStore);
423
424   AliMUONVDigit* digit;
425   TIter next(digitStore.CreateIterator());
426
427   Int_t cathode, detElemId, ix, iy, charge, chamber, adc;
428
429   while ( ( digit = static_cast<AliMUONVDigit*>(next() ) ) )
430   {
431       cathode   = digit->Cathode();
432       ix        = digit->PadX();
433       iy        = digit->PadY();
434       detElemId = digit->DetElemId();
435       charge    = (Int_t)digit->Charge();
436       adc       = digit->ADC();
437       chamber   = detElemId/100 - 1;
438       if (chamber > 9) {
439         fChambers[chamber]->RegisterDigit(detElemId,cathode,ix,iy,charge);
440       } else {
441         fChambers[chamber]->RegisterDigit(detElemId,cathode,ix,iy,adc);
442       }
443   }
444 }
445
446 //______________________________________________________________________________
447 Int_t AliEveMUONData::GetTrack(Int_t index) const
448 {
449   //
450   // return track stack number for "index"-th track with hits in the chambers
451   //
452
453   if (index < 256) {
454     return fTrackList[index];
455   } else {
456     return -1;
457   }
458 }
459
460 //______________________________________________________________________________
461 AliEveMUONChamberData* AliEveMUONData::GetChamberData(Int_t chamber)
462 {
463   //
464   // return chamber data
465   //
466
467   if (chamber < 0 || chamber > 13) return 0;
468
469   //if (fChambers[chamber] == 0) CreateChamber(chamber);
470
471   return fChambers[chamber];
472 }