Changing RunMuonTracking (Laurent)
[u/mrichter/AliRoot.git] / EVE / Alieve / MUONData.cxx
CommitLineData
3626c858 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
361fa326 21#include <AliLog.h>
3626c858 22
cef26510 23#include <AliMUONDigitMaker.h>
eadce74d 24#include <AliMUONHit.h>
25#include <AliMUONRawCluster.h>
3626c858 26#include <AliMUONDigit.h>
3626c858 27#include <AliMUONTriggerCrateStore.h>
cef26510 28#include <AliMUONData.h>
3626c858 29
30#include "TTree.h"
31#include "TString.h"
3626c858 32#include "TClonesArray.h"
cef26510 33#include "TList.h"
3626c858 34
35using namespace Reve;
36using namespace Alieve;
37
38//______________________________________________________________________
39// MUONData
40//
41
42ClassImp(MUONData)
43
44AliRawReader* MUONData::fgRawReader = 0;
3626c858 45
46//______________________________________________________________________
47MUONData::MUONData() :
eadce74d 48 fChambers(14),
49 fNTrackList(0)
3626c858 50{
51 //
52 // Constructor
53 //
54
cef26510 55 for (Int_t i = 0; i < 256; i++) {
eadce74d 56 fTrackList[i] = -1;
57 }
58
3626c858 59 CreateAllChambers();
60
61}
62
63//______________________________________________________________________
64MUONData::~MUONData()
65{
66 //
67 // Destructor
68 //
69
70 DeleteAllChambers();
71
3626c858 72}
73
eadce74d 74//______________________________________________________________________
75void MUONData::Reset()
76{
77 //
78 // Reset data
79 //
80
81 //DropAllChambers();
82
83 fNTrackList = 0;
cef26510 84 for (Int_t i = 0; i < 256; i++) {
eadce74d 85 fTrackList[i] = -1;
86 }
87
88}
89
3626c858 90//______________________________________________________________________
91MUONData::MUONData(const MUONData &mdata) :
e4204218 92 TObject(mdata),
93 Reve::ReferenceCount()
3626c858 94{
95 //
96 // Copy constructor
97 //
98
99}
100
101//______________________________________________________________________
102MUONData& 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//______________________________________________________________________
117void 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//______________________________________________________________________
129void 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//______________________________________________________________________
141void 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//______________________________________________________________________
157void 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
eadce74d 172//______________________________________________________________________
173void MUONData::RegisterTrack(Int_t track)
174{
175 //
176 // register (in a list) a track with hits in the chambers
177 //
178
cef26510 179 if (fNTrackList == (256-1)) {
eadce74d 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
3626c858 198//______________________________________________________________________
199void 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
3626c858 229 fChambers[c]->RegisterDigit(detElemId,cathode,ix,iy,charge);
eadce74d 230
3626c858 231 } // end digits loop
232
233 }
234
235}
236
2674c15a 237//______________________________________________________________________
eadce74d 238void MUONData::LoadRecPoints(TTree* tree)
2674c15a 239{
240 //
241 // load reconstructed points from the TreeR
242 // load local trigger information
243 //
244
eadce74d 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//______________________________________________________________________
281void 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
2674c15a 316}
317
3626c858 318//______________________________________________________________________
319void 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 }
3626c858 334 }
335
3626c858 336 fgRawReader->RewindEvents();
cef26510 337 fgRawReader->Reset();
3626c858 338
339 Int_t iEvent = 0;
3626c858 340 while (fgRawReader->NextEvent()) {
cef26510 341 if (iEvent != Alieve::gEvent->GetEventId()) {
3626c858 342 iEvent++;
343 continue;
344 }
3626c858 345 break;
cef26510 346 }
3626c858 347
cef26510 348 AliMUONDigitMaker *digitMaker = new AliMUONDigitMaker();
3626c858 349
cef26510 350 AliMUONTriggerCrateStore *crateManager = new AliMUONTriggerCrateStore();
351 crateManager->ReadFromFile();
3626c858 352
cef26510 353 AliMUONData *muonData = new AliMUONData(0x0,"MUON","MUON");
3626c858 354
cef26510 355 digitMaker->SetDisplayFlag();
356 digitMaker->SetCrateManager(crateManager);
357 digitMaker->SetMUONData(muonData);
358 muonData->SetDataContainer("D, GLT");
3626c858 359
cef26510 360 digitMaker->Raw2Digits(fgRawReader);
3626c858 361
cef26510 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);
3626c858 375 }
cef26510 376 }
3626c858 377
cef26510 378 delete muonData;
3626c858 379 delete crateManager;
cef26510 380 delete digitMaker;
3626c858 381
382}
383
eadce74d 384//______________________________________________________________________
385Int_t MUONData::GetTrack(Int_t index)
386{
387 //
388 // return track stack number for "index"-th track with hits in the chambers
389 //
390
cef26510 391 if (index < 256) {
eadce74d 392 return fTrackList[index];
393 } else {
394 return -1;
395 }
396
397}
398
3626c858 399//______________________________________________________________________
400MUONChamberData* 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}