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