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