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