]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/EveDet/AliEveMUONData.cxx
Moving the QA for raw data inside the event loop (Yves). The list of the detectors...
[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   esdFile->Close();
302
303 }
304
305 //______________________________________________________________________________
306 void AliEveMUONData::LoadHits(TTree* tree)
307 {
308   //
309   // load simulation hits from the TreeH
310   //
311
312   TClonesArray *hits = 0;
313   AliMUONHit  *mhit;
314   Int_t cha, detElemId, nhits, ntracks;
315   Float_t hitX, hitY, hitZ;
316
317   ntracks = tree->GetEntries();
318   tree->SetBranchAddress("MUONHits",&hits);
319
320   for (Int_t it = 0; it < ntracks; it++) {
321
322     tree->GetEvent(it);
323     nhits = hits->GetEntriesFast();
324
325     for (Int_t ih = 0; ih < nhits; ih++) {
326
327       mhit = (AliMUONHit*)hits->UncheckedAt(ih);
328       hitX = mhit->X();
329       hitY = mhit->Y();
330       hitZ = mhit->Z();
331       detElemId = mhit->DetElemId();
332       cha = mhit->Chamber();
333
334       RegisterTrack(mhit->GetTrack());
335
336       fChambers[cha-1]->RegisterHit(detElemId,hitX,hitY,hitZ);
337
338     }
339   }
340
341 }
342
343 //______________________________________________________________________________
344 void AliEveMUONData::LoadDigits(TTree* tree)
345 {
346   //
347   // load digits from the TreeD
348   //
349
350   AliMUONVDigitStore *digitStore = AliMUONVDigitStore::Create(*tree);
351   digitStore->Clear();
352   digitStore->Connect(*tree,0);
353
354   tree->GetEvent(0);
355
356   AliMUONVDigit* digit;
357   TIter next(digitStore->CreateIterator());
358
359   Int_t cathode, detElemId, ix, iy, charge, chamber, adc;
360
361   while ( ( digit = static_cast<AliMUONVDigit*>(next() ) ) )
362     {
363       cathode   = digit->Cathode();
364       ix        = digit->PadX();
365       iy        = digit->PadY();
366       detElemId = digit->DetElemId();
367       charge    = (Int_t)digit->Charge();
368       adc       = digit->ADC();
369       chamber   = detElemId/100 - 1;
370       if (chamber > 9) {
371         fChambers[chamber]->RegisterDigit(detElemId,cathode,ix,iy,charge);
372       } else {
373         fChambers[chamber]->RegisterDigit(detElemId,cathode,ix,iy,adc);
374       }
375     }
376
377   delete digitStore;
378
379 }
380
381 //______________________________________________________________________________
382 void AliEveMUONData::LoadRaw(TString fileName)
383 {
384   //
385   // load raw data from fileName; tracker and trigger data
386   //
387
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
396     }
397   }
398
399   fgRawReader->RewindEvents();
400   fgRawReader->Reset();
401
402   Int_t iEvent = 0;
403   while (fgRawReader->NextEvent())
404   {
405     if (iEvent != gAliEveEvent->GetEventId())
406     {
407       iEvent++;
408       continue;
409     }
410     break;
411   }
412
413   AliMUONDigitMaker digitMaker;
414
415   digitMaker.SetMakeTriggerDigits(kTRUE);
416
417   AliMUONDigitStoreV1 digitStore;
418
419   digitMaker.Raw2Digits(fgRawReader,&digitStore);
420
421   AliMUONVDigit* digit;
422   TIter next(digitStore.CreateIterator());
423
424   Int_t cathode, detElemId, ix, iy, charge, chamber, adc;
425
426   while ( ( digit = static_cast<AliMUONVDigit*>(next() ) ) )
427   {
428       cathode   = digit->Cathode();
429       ix        = digit->PadX();
430       iy        = digit->PadY();
431       detElemId = digit->DetElemId();
432       charge    = (Int_t)digit->Charge();
433       adc       = digit->ADC();
434       chamber   = detElemId/100 - 1;
435       if (chamber > 9) {
436         fChambers[chamber]->RegisterDigit(detElemId,cathode,ix,iy,charge);
437       } else {
438         fChambers[chamber]->RegisterDigit(detElemId,cathode,ix,iy,adc);
439       }
440   }
441 }
442
443 //______________________________________________________________________________
444 Int_t AliEveMUONData::GetTrack(Int_t index) const
445 {
446   //
447   // return track stack number for "index"-th track with hits in the chambers
448   //
449
450   if (index < 256) {
451     return fTrackList[index];
452   } else {
453     return -1;
454   }
455 }
456
457 //______________________________________________________________________________
458 AliEveMUONChamberData* AliEveMUONData::GetChamberData(Int_t chamber)
459 {
460   //
461   // return chamber data
462   //
463
464   if (chamber < 0 || chamber > 13) return 0;
465
466   //if (fChambers[chamber] == 0) CreateChamber(chamber);
467
468   return fChambers[chamber];
469 }