]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/Alieve/MUONData.cxx
Add the det.element id for each local board
[u/mrichter/AliRoot.git] / EVE / Alieve / MUONData.cxx
1 //
2 // Sources:
3 //
4 // GetTrackerMapping = AliMUONDigitMaker::GetMapping
5 // GetTriggerMapping = AliMUONDigitMaker::TriggerDigits
6 // GetTriggerChamber = AliMUONDigitMaker::GetTriggerChamber
7 // LoadRawTracker    = MUONRawStreamTracker.C
8 // LoadRawTrigger    = MUONRawStreamTrigger.C
9 //
10
11 #include "MUONData.h"
12
13 #include <Alieve/MUONChamberData.h>
14 #include <Alieve/EventAlieve.h>
15
16 #include <AliRawReader.h>
17 #include <AliRawReaderFile.h>
18 #include <AliRawReaderDate.h>
19 #include <AliRawReaderRoot.h>
20
21 #include <AliLog.h>
22
23 #include <AliMUONDigitMaker.h>
24 #include <AliMUONHit.h>
25 #include <AliMUONRawCluster.h>
26 #include <AliMUONDigit.h>
27 #include <AliMUONTriggerCrateStore.h>
28 #include <AliMUONData.h>
29
30 #include "TTree.h"
31 #include "TString.h"
32 #include "TClonesArray.h"
33 #include "TList.h"
34
35 using namespace Reve;
36 using namespace Alieve;
37
38 //______________________________________________________________________
39 // MUONData
40 //
41
42 ClassImp(MUONData)
43
44 AliRawReader*            MUONData::fgRawReader        = 0;
45
46 //______________________________________________________________________
47 MUONData::MUONData() :
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 MUONData::~MUONData()
65 {
66   //
67   // Destructor
68   //
69
70   DeleteAllChambers();
71
72 }
73
74 //______________________________________________________________________
75 void MUONData::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 MUONData::MUONData(const MUONData &mdata) :
92   TObject(mdata),
93   Reve::ReferenceCount()
94 {
95   //
96   // Copy constructor
97   //
98
99 }
100
101 //______________________________________________________________________
102 MUONData& MUONData::operator=(const MUONData &mdata)
103 {
104   //
105   // Assignment operator
106   //
107
108   if (this != &mdata) {
109
110   }
111
112   return *this;
113
114 }
115
116 //______________________________________________________________________
117 void MUONData::CreateChamber(Int_t chamber)
118 {
119   // 
120   // create data for the chamber with id=chamber (0 to 13)
121   //
122
123   if (fChambers[chamber] == 0)
124     fChambers[chamber] = new MUONChamberData(chamber);
125
126 }
127
128 //______________________________________________________________________
129 void MUONData::CreateAllChambers()
130 {
131   //
132   // create all 14 chambers data
133   //
134
135   for (Int_t c = 0; c < 14; ++c)
136     CreateChamber(c);
137
138 }
139
140 //______________________________________________________________________
141 void MUONData::DropAllChambers()
142 {
143   // 
144   // release data from all chambers 
145   //
146
147   for (Int_t c = 0; c < 14; ++c) {
148
149     if (fChambers[c] != 0)
150       fChambers[c]->DropData();
151
152   }
153
154 }
155
156 //______________________________________________________________________
157 void MUONData::DeleteAllChambers()
158 {
159   //
160   // delete all chambers data
161   //
162
163   for (Int_t c = 0; c < 14; ++c) {
164
165     delete fChambers[c];
166     fChambers[c] = 0;
167
168   }
169
170 }
171
172 //______________________________________________________________________
173 void MUONData::RegisterTrack(Int_t track)
174 {
175   //
176   // register (in a list) a track with hits in the chambers
177   //
178
179   if (fNTrackList == (256-1)) {
180     cout << "Maximum of registered tracks reached..." << endl;
181     return;
182   }
183
184   Bool_t inList = kFALSE;
185   for (Int_t i = 0; i < fNTrackList; i++) {
186     if (track == fTrackList[i]) {
187       inList = kTRUE;
188       break;
189     }
190   }
191   if (!inList) {
192     fTrackList[fNTrackList] = track;
193     fNTrackList++;
194   }
195
196 }
197
198 //______________________________________________________________________
199 void MUONData::LoadDigits(TTree* tree)
200 {
201   // 
202   // load digits from the TreeD
203   //
204
205   Char_t branchname[30];
206   TClonesArray *digits = 0;
207   Int_t ndigits;
208   AliMUONDigit  *mdig;
209   Int_t cathode, detElemId, ix, iy, charge;
210
211   for (Int_t c = 0; c < 14; ++c) {
212
213     if (fChambers[c] == 0) continue;
214     sprintf(branchname,"MUONDigits%d",c+1);
215     tree->SetBranchAddress(branchname,&digits);
216     tree->GetEntry(0);
217
218     ndigits = digits->GetEntriesFast(); 
219
220     for (Int_t id = 0; id < ndigits; id++) {
221       mdig  = (AliMUONDigit*)digits->UncheckedAt(id);
222
223       cathode   = mdig->Cathode();
224       ix        = mdig->PadX();
225       iy        = mdig->PadY();
226       detElemId = mdig->DetElemId();      
227       charge    = (Int_t)mdig->Signal();
228
229       fChambers[c]->RegisterDigit(detElemId,cathode,ix,iy,charge);
230       
231     } // end digits loop
232
233   }
234
235 }
236
237 //______________________________________________________________________
238 void MUONData::LoadRecPoints(TTree* tree)
239 {
240   //
241   // load reconstructed points from the TreeR
242   // load local trigger information
243   //
244
245   Char_t branchname[30];
246   TClonesArray *clusters = 0;
247   Int_t nclusters;
248   AliMUONRawCluster  *mcls;
249   Int_t detElemId;
250   Float_t clsX, clsY, clsZ, charge;
251
252   for (Int_t c = 0; c < 10; ++c) {
253
254     if (fChambers[c] == 0) continue;
255     sprintf(branchname,"MUONRawClusters%d",c+1);
256     tree->SetBranchAddress(branchname,&clusters);
257     tree->GetEntry(0);
258
259     nclusters = clusters->GetEntriesFast(); 
260
261     for (Int_t ic = 0; ic < nclusters; ic++) {
262       mcls  = (AliMUONRawCluster*)clusters->UncheckedAt(ic);
263
264       detElemId = mcls->GetDetElemId();
265       for (Int_t icath = 0; icath < 2; icath++) {
266         clsX   = mcls->GetX(icath);
267         clsY   = mcls->GetY(icath);
268         clsZ   = mcls->GetZ(icath);
269         charge = mcls->GetCharge(icath);
270
271         fChambers[c]->RegisterCluster(detElemId,icath,clsX,clsY,clsZ,charge);
272       }
273
274     }
275
276   }
277
278 }
279
280 //______________________________________________________________________
281 void MUONData::LoadHits(TTree* tree)
282 {
283   //
284   // load simulation hits from the TreeH
285   //
286
287   TClonesArray *hits = 0;
288   AliMUONHit  *mhit;
289   Int_t cha, detElemId, nhits, ntracks;
290   Float_t hitX, hitY, hitZ;
291
292   ntracks = tree->GetEntries();
293   tree->SetBranchAddress("MUONHits",&hits);
294
295   for (Int_t it = 0; it < ntracks; it++) {
296
297     tree->GetEvent(it);
298     nhits = hits->GetEntriesFast();
299
300     for (Int_t ih = 0; ih < nhits; ih++) {
301
302       mhit = (AliMUONHit*)hits->UncheckedAt(ih);
303       hitX = mhit->X();
304       hitY = mhit->Y();
305       hitZ = mhit->Z();
306       detElemId = mhit->DetElemId();
307       cha = mhit->Chamber();
308
309       RegisterTrack(mhit->GetTrack());
310
311       fChambers[cha-1]->RegisterHit(detElemId,hitX,hitY,hitZ);
312
313     }
314   }
315
316 }
317
318 //______________________________________________________________________
319 void MUONData::LoadRaw(TString fileName)
320 {
321   //
322   // load raw data from fileName; tracker and trigger data
323   //
324
325   if (fgRawReader == 0) {
326     // check extention to choose the rawdata file format
327     if (fileName.EndsWith("/")) {
328       fgRawReader = new AliRawReaderFile(fileName); // DDL files
329     } else if (fileName.EndsWith(".root")) {
330       fgRawReader = new AliRawReaderRoot(fileName); // ROOT file
331     } else if (!fileName.IsNull()) {
332       fgRawReader = new AliRawReaderDate(fileName); // DATE file
333     }
334   }
335   
336   fgRawReader->RewindEvents();
337   fgRawReader->Reset();
338
339   Int_t iEvent = 0;
340   while (fgRawReader->NextEvent()) {
341     if (iEvent != Alieve::gEvent->GetEventId()) {
342       iEvent++;
343       continue;
344     }
345     break;
346   }
347
348   AliMUONDigitMaker *digitMaker = new AliMUONDigitMaker();
349
350   AliMUONTriggerCrateStore *crateManager = new AliMUONTriggerCrateStore();
351   crateManager->ReadFromFile();
352
353   AliMUONData *muonData = new AliMUONData(0x0,"MUON","MUON");
354
355   digitMaker->SetDisplayFlag();
356   digitMaker->SetCrateManager(crateManager);
357   digitMaker->SetMUONData(muonData);
358   muonData->SetDataContainer("D, GLT");
359
360   digitMaker->Raw2Digits(fgRawReader);
361
362   AliMUONDigit *digit;
363   Int_t cathode, detElemId, ix, iy, charge, chamber, ndigits;
364   for (chamber = 0; chamber < 14; chamber++) {
365     ndigits = (Int_t)muonData->Digits(chamber)->GetEntriesFast();
366     for (Int_t id = 0; id < ndigits; id++) {
367       digit = static_cast<AliMUONDigit*>(muonData->Digits(chamber)->At(id));
368       cathode   = digit->Cathode();
369       ix        = digit->PadX();
370       iy        = digit->PadY();
371       detElemId = digit->DetElemId();      
372       charge    = (Int_t)digit->Signal();
373       chamber   = detElemId/100 - 1;
374       fChambers[chamber]->RegisterDigit(detElemId,cathode,ix,iy,charge);
375     }
376   }
377
378   delete muonData;
379   delete crateManager;
380   delete digitMaker;
381
382 }
383
384 //______________________________________________________________________
385 Int_t MUONData::GetTrack(Int_t index)
386 {
387   //
388   // return track stack number for "index"-th track with hits in the chambers
389   //
390
391   if (index < 256) {
392     return fTrackList[index];
393   } else {
394     return -1;
395   }
396
397 }
398
399 //______________________________________________________________________
400 MUONChamberData* MUONData::GetChamberData(Int_t chamber)
401 {
402   //
403   // return chamber data
404   //
405
406   if (chamber < 0 || chamber > 13) return 0;
407
408   //if (fChambers[chamber] == 0) CreateChamber(chamber);
409
410   return fChambers[chamber];
411
412 }