]>
Commit | Line | Data |
---|---|---|
1 | /************************************************************************** | |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
7 | * Permission to use, copy, modify and distribute this software and its * | |
8 | * documentation strictly for non-commercial purposes is hereby granted * | |
9 | * without fee, provided that the above copyright notice appears in all * | |
10 | * copies and that both the copyright notice and this permission notice * | |
11 | * appear in the supporting documentation. The authors make no claims * | |
12 | * about the suitability of this software for any purpose. It is * | |
13 | * provided "as is" without express or implied warranty. * | |
14 | **************************************************************************/ | |
15 | ||
16 | /* $Id$ */ | |
17 | ||
18 | /////////////////////////////////////////////////////////////////////////////// | |
19 | // // | |
20 | // Zero Degree Calorimeter // | |
21 | // This class contains the basic functions for the ZDCs; // | |
22 | // functions specific to one particular geometry are // | |
23 | // contained in the derived classes // | |
24 | // // | |
25 | /////////////////////////////////////////////////////////////////////////////// | |
26 | ||
27 | // --- ROOT system | |
28 | #include <TBRIK.h> | |
29 | #include <TGeometry.h> | |
30 | #include <TNode.h> | |
31 | #include <TTree.h> | |
32 | #include <TSystem.h> | |
33 | ||
34 | // --- AliRoot header files | |
35 | #include "AliDetector.h" | |
36 | #include "AliZDC.h" | |
37 | #include "AliZDCHit.h" | |
38 | #include "AliZDCSDigit.h" | |
39 | #include "AliZDCDigit.h" | |
40 | #include "AliZDCDigitizer.h" | |
41 | #include "AliZDCRawStream.h" | |
42 | #include "AliZDCCalibData.h" | |
43 | ||
44 | #include "AliRawDataHeader.h" | |
45 | #include "AliLoader.h" | |
46 | #include "AliRun.h" | |
47 | #include "AliMC.h" | |
48 | ||
49 | ||
50 | ClassImp(AliZDC) | |
51 | ||
52 | AliZDC *gZDC; | |
53 | ||
54 | //_____________________________________________________________________________ | |
55 | AliZDC::AliZDC() | |
56 | { | |
57 | // | |
58 | // Default constructor for the Zero Degree Calorimeter base class | |
59 | // | |
60 | ||
61 | fIshunt = 1; | |
62 | fNoShower = 0; | |
63 | ||
64 | fHits = 0; | |
65 | fNhits = 0; | |
66 | ||
67 | fDigits = 0; | |
68 | fNdigits = 0; | |
69 | ||
70 | fCalibData = 0; | |
71 | ||
72 | } | |
73 | ||
74 | //_____________________________________________________________________________ | |
75 | AliZDC::AliZDC(const char *name, const char *title) | |
76 | : AliDetector(name,title) | |
77 | { | |
78 | // | |
79 | // Standard constructor for the Zero Degree Calorimeter base class | |
80 | // | |
81 | ||
82 | fIshunt = 1; | |
83 | fNoShower = 0; | |
84 | ||
85 | // Allocate the hits array | |
86 | fHits = new TClonesArray("AliZDCHit",1000); | |
87 | gAlice->GetMCApp()->AddHitList(fHits); | |
88 | ||
89 | char sensname[5],senstitle[25]; | |
90 | sprintf(sensname,"ZDC"); | |
91 | sprintf(senstitle,"ZDC dummy"); | |
92 | SetName(sensname); SetTitle(senstitle); | |
93 | ||
94 | fDigits = 0; | |
95 | fNdigits = 0; | |
96 | ||
97 | fCalibData = 0; | |
98 | ||
99 | gZDC=this; | |
100 | ||
101 | } | |
102 | //____________________________________________________________________________ | |
103 | AliZDC::~AliZDC() | |
104 | { | |
105 | // | |
106 | // ZDC destructor | |
107 | // | |
108 | ||
109 | fIshunt = 0; | |
110 | gZDC=0; | |
111 | ||
112 | delete fCalibData; | |
113 | ||
114 | } | |
115 | //_____________________________________________________________________________ | |
116 | void AliZDC::AddHit(Int_t track, Int_t *vol, Float_t *hits) | |
117 | { | |
118 | // | |
119 | // Add a ZDC hit to the hit list. | |
120 | // -> We make use of 2 array of hits: | |
121 | // [1] fHits (the usual one) that contains hits for each PRIMARY | |
122 | // [2] fStHits that contains hits for each EVENT and is used to | |
123 | // obtain digits at the end of each event | |
124 | // | |
125 | ||
126 | static Float_t primKinEn, xImpact, yImpact, sFlag; | |
127 | ||
128 | AliZDCHit *newquad, *curprimquad; | |
129 | newquad = new AliZDCHit(fIshunt, track, vol, hits); | |
130 | TClonesArray &lhits = *fHits; | |
131 | ||
132 | if(fNhits==0){ | |
133 | // First hit -> setting flag for primary or secondary particle | |
134 | Int_t primary = gAlice->GetMCApp()->GetPrimary(track); | |
135 | if(track != primary){ | |
136 | newquad->SetSFlag(1); // SECONDARY particle entering the ZDC | |
137 | } | |
138 | else if(track == primary){ | |
139 | newquad->SetSFlag(0); // PRIMARY particle entering the ZDC | |
140 | } | |
141 | sFlag = newquad->GetSFlag(); | |
142 | primKinEn = newquad->GetPrimKinEn(); | |
143 | xImpact = newquad->GetXImpact(); | |
144 | yImpact = newquad->GetYImpact(); | |
145 | } | |
146 | else{ | |
147 | newquad->SetPrimKinEn(primKinEn); | |
148 | newquad->SetXImpact(xImpact); | |
149 | newquad->SetYImpact(yImpact); | |
150 | newquad->SetSFlag(sFlag); | |
151 | } | |
152 | ||
153 | Int_t j; | |
154 | for(j=0; j<fNhits; j++){ | |
155 | // If hits are equal (same track, same volume), sum them. | |
156 | curprimquad = (AliZDCHit*) lhits[j]; | |
157 | if(*curprimquad == *newquad){ | |
158 | *curprimquad = *curprimquad+*newquad; | |
159 | delete newquad; | |
160 | return; | |
161 | } | |
162 | } | |
163 | ||
164 | //Otherwise create a new hit | |
165 | new(lhits[fNhits]) AliZDCHit(newquad); | |
166 | fNhits++; | |
167 | ||
168 | delete newquad; | |
169 | } | |
170 | ||
171 | //_____________________________________________________________________________ | |
172 | void AliZDC::BuildGeometry() | |
173 | { | |
174 | // | |
175 | // Build the ROOT TNode geometry for event display | |
176 | // in the Zero Degree Calorimeter | |
177 | // This routine is dummy for the moment | |
178 | // | |
179 | ||
180 | TNode *node, *top; | |
181 | TBRIK *brik; | |
182 | const int kColorZDC = kBlue; | |
183 | ||
184 | // | |
185 | top=gAlice->GetGeometry()->GetNode("alice"); | |
186 | ||
187 | // ZDC | |
188 | brik = new TBRIK("S_ZDC","ZDC box","void",300,300,5); | |
189 | top->cd(); | |
190 | node = new TNode("ZDC","ZDC","S_ZDC",0,0,600,""); | |
191 | node->SetLineColor(kColorZDC); | |
192 | fNodes->Add(node); | |
193 | } | |
194 | ||
195 | //_____________________________________________________________________________ | |
196 | Int_t AliZDC::DistancetoPrimitive(Int_t , Int_t ) | |
197 | { | |
198 | // | |
199 | // Distance from the mouse to the Zero Degree Calorimeter | |
200 | // Dummy routine | |
201 | // | |
202 | return 9999; | |
203 | } | |
204 | ||
205 | //____________________________________________________________________________ | |
206 | Float_t AliZDC::ZMin(void) const | |
207 | { | |
208 | // Minimum dimension of the ZDC module in z | |
209 | return -11600.; | |
210 | } | |
211 | ||
212 | //____________________________________________________________________________ | |
213 | Float_t AliZDC::ZMax(void) const | |
214 | { | |
215 | // Maximum dimension of the ZDC module in z | |
216 | return -11750.; | |
217 | } | |
218 | ||
219 | ||
220 | //_____________________________________________________________________________ | |
221 | void AliZDC::MakeBranch(Option_t *opt, const char * /*file*/) | |
222 | { | |
223 | // | |
224 | // Create Tree branches for the ZDC | |
225 | // | |
226 | ||
227 | char branchname[10]; | |
228 | sprintf(branchname,"%s",GetName()); | |
229 | ||
230 | const char *cH = strstr(opt,"H"); | |
231 | ||
232 | if (cH && fLoader->TreeH()) | |
233 | fHits = new TClonesArray("AliZDCHit",1000); | |
234 | ||
235 | AliDetector::MakeBranch(opt); | |
236 | } | |
237 | ||
238 | //_____________________________________________________________________________ | |
239 | void AliZDC::Hits2SDigits() | |
240 | { | |
241 | // Create summable digits from hits | |
242 | ||
243 | if (GetDebug()) printf("\n Entering AliZDC::Hits2Digits() "); | |
244 | ||
245 | fLoader->LoadHits("read"); | |
246 | fLoader->LoadSDigits("recreate"); | |
247 | AliRunLoader* runLoader = fLoader->GetRunLoader(); | |
248 | AliZDCSDigit sdigit; | |
249 | AliZDCSDigit* psdigit = &sdigit; | |
250 | ||
251 | // Event loop | |
252 | for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) { | |
253 | Float_t pmCZN = 0, pmCZP = 0, pmQZN[4], pmQZP[4], pmZEM1 = 0, pmZEM2 = 0; | |
254 | for (Int_t i = 0; i < 4; i++) pmQZN[i] = pmQZP[i] = 0; | |
255 | ||
256 | runLoader->GetEvent(iEvent); | |
257 | TTree* treeH = fLoader->TreeH(); | |
258 | Int_t ntracks = (Int_t) treeH->GetEntries(); | |
259 | ResetHits(); | |
260 | ||
261 | // Tracks loop | |
262 | Int_t sector[2]; | |
263 | for (Int_t itrack = 0; itrack < ntracks; itrack++) { | |
264 | treeH->GetEntry(itrack); | |
265 | for (AliZDCHit* zdcHit = (AliZDCHit*)FirstHit(-1); zdcHit; | |
266 | zdcHit = (AliZDCHit*)NextHit()) { | |
267 | ||
268 | sector[0] = zdcHit->GetVolume(0); | |
269 | sector[1] = zdcHit->GetVolume(1); | |
270 | if ((sector[1] < 1) || (sector[1] > 4)) { | |
271 | Error("Hits2SDigits", "sector[0] = %d, sector[1] = %d", | |
272 | sector[0], sector[1]); | |
273 | continue; | |
274 | } | |
275 | Float_t lightQ = zdcHit->GetLightPMQ(); | |
276 | Float_t lightC = zdcHit->GetLightPMC(); | |
277 | ||
278 | if (sector[0] == 1) { //ZN | |
279 | pmCZN += lightC; | |
280 | pmQZN[sector[1]-1] += lightQ; | |
281 | } else if (sector[0] == 2) { //ZP | |
282 | pmCZP += lightC; | |
283 | pmQZP[sector[1]-1] += lightQ; | |
284 | } else if (sector[0] == 3) { //ZEM | |
285 | if (sector[1] == 1) pmZEM1 += lightC; | |
286 | else pmZEM2 += lightQ; | |
287 | } | |
288 | }//Hits loop | |
289 | } | |
290 | ||
291 | // create the output tree | |
292 | fLoader->MakeTree("S"); | |
293 | TTree* treeS = fLoader->TreeS(); | |
294 | const Int_t kBufferSize = 4000; | |
295 | treeS->Branch(GetName(), "AliZDCSDigit", &psdigit, kBufferSize); | |
296 | ||
297 | // Create sdigits for ZN | |
298 | sector[0] = 1; // Detector = ZN | |
299 | sector[1] = 0; // Common PM ADC | |
300 | new(psdigit) AliZDCSDigit(sector, pmCZN); | |
301 | if (pmCZN > 0) treeS->Fill(); | |
302 | for (Int_t j = 0; j < 4; j++) { | |
303 | sector[1] = j+1; // Towers PM ADCs | |
304 | new(psdigit) AliZDCSDigit(sector, pmQZN[j]); | |
305 | if (pmQZN[j] > 0) treeS->Fill(); | |
306 | } | |
307 | ||
308 | // Create sdigits for ZP | |
309 | sector[0] = 2; // Detector = ZP | |
310 | sector[1] = 0; // Common PM ADC | |
311 | new(psdigit) AliZDCSDigit(sector, pmCZP); | |
312 | if (pmCZP > 0) treeS->Fill(); | |
313 | for (Int_t j = 0; j < 4; j++) { | |
314 | sector[1] = j+1; // Towers PM ADCs | |
315 | new(psdigit) AliZDCSDigit(sector, pmQZP[j]); | |
316 | if (pmQZP[j] > 0) treeS->Fill(); | |
317 | } | |
318 | ||
319 | // Create sdigits for ZEM | |
320 | sector[0] = 3; | |
321 | sector[1] = 1; // Detector = ZEM1 | |
322 | new(psdigit) AliZDCSDigit(sector, pmZEM1); | |
323 | if (pmZEM1 > 0) treeS->Fill(); | |
324 | sector[1] = 2; // Detector = ZEM2 | |
325 | new(psdigit) AliZDCSDigit(sector, pmZEM2); | |
326 | if (pmZEM2 > 0) treeS->Fill(); | |
327 | ||
328 | // write the output tree | |
329 | fLoader->WriteSDigits("OVERWRITE"); | |
330 | } | |
331 | ||
332 | fLoader->UnloadHits(); | |
333 | fLoader->UnloadSDigits(); | |
334 | } | |
335 | ||
336 | //_____________________________________________________________________________ | |
337 | AliDigitizer* AliZDC::CreateDigitizer(AliRunDigitizer* manager) const | |
338 | { | |
339 | // Create the digitizer for ZDC | |
340 | ||
341 | return new AliZDCDigitizer(manager); | |
342 | } | |
343 | ||
344 | //_____________________________________________________________________________ | |
345 | void AliZDC::Digits2Raw() | |
346 | { | |
347 | // Convert ZDC digits to raw data | |
348 | ||
349 | // preliminary format: 12 interger values (ZNC, ZNQ1-4, ZPC, ZPQ1-4, ZEM1,2) | |
350 | // For the CAEN module V965 we have an header, the Data Words and an End Of Block | |
351 | UInt_t ADCHeader; | |
352 | UInt_t ADCData[24]; | |
353 | UInt_t ADCEndBlock; | |
354 | ||
355 | // load the digits | |
356 | fLoader->LoadDigits("read"); | |
357 | AliZDCDigit digit; | |
358 | AliZDCDigit* pdigit = &digit; | |
359 | TTree* treeD = fLoader->TreeD(); | |
360 | if (!treeD) return; | |
361 | treeD->SetBranchAddress("ZDC", &pdigit); | |
362 | ||
363 | // Fill data array | |
364 | // ADC header | |
365 | UInt_t ADCHeaderGEO = 0; | |
366 | UInt_t ADCHeaderCRATE = 0; | |
367 | UInt_t ADCHeaderCNT = (UInt_t) treeD->GetEntries(); | |
368 | ||
369 | ADCHeader = ADCHeaderGEO << 27 | 0x1 << 25 | ADCHeaderCRATE << 16 | | |
370 | ADCHeaderCNT << 8 ; | |
371 | ||
372 | //printf("ADCHeader = %d\n",ADCHeader); | |
373 | ||
374 | // ADC data word | |
375 | UInt_t ADCDataGEO = ADCHeaderGEO; | |
376 | UInt_t ADCDataValue[24]; | |
377 | UInt_t ADCDataOvFlw[24]; | |
378 | for(Int_t i = 0; i < 24; i++){ | |
379 | ADCDataValue[i] = 0; | |
380 | ADCDataOvFlw[i] = 0; | |
381 | } | |
382 | UInt_t ADCDataChannel = 0; | |
383 | ||
384 | // loop over digits | |
385 | for (Int_t iDigit = 0; iDigit < treeD->GetEntries(); iDigit++) { | |
386 | treeD->GetEntry(iDigit); | |
387 | if (!pdigit) continue; | |
388 | ||
389 | //ADC data | |
390 | Int_t index = 0; | |
391 | if(digit.GetSector(0)!=3){ | |
392 | index = (digit.GetSector(0)-1) + digit.GetSector(1)*4; | |
393 | ADCDataChannel = (digit.GetSector(0)-1)*8 + digit.GetSector(1); | |
394 | } | |
395 | else { | |
396 | index = 19 + digit.GetSector(1); | |
397 | ADCDataChannel = 5 + digit.GetSector(1)*8; | |
398 | } | |
399 | ||
400 | if ((index < 0) || (index >= 22)) { | |
401 | Error("Digits2Raw", "sector[0] = %d, sector[1] = %d", | |
402 | digit.GetSector(0), digit.GetSector(1)); | |
403 | continue; | |
404 | } | |
405 | ||
406 | ADCDataValue[index] = digit.GetADCValue(0); | |
407 | if (ADCDataValue[index] > 2047) ADCDataOvFlw[index] = 1; | |
408 | ADCDataValue[index+2] = digit.GetADCValue(1); | |
409 | if (ADCDataValue[index+2] > 2047) ADCDataOvFlw[index+2] = 1; | |
410 | ||
411 | ADCData[index] = ADCDataGEO << 27 | ADCDataChannel << 17 | | |
412 | ADCDataOvFlw[index] << 12 | (ADCDataValue[index] & 0xfff); | |
413 | ADCData[index+2] = ADCDataGEO << 27 | ADCDataChannel << 17 | 0x1 << 16 | | |
414 | ADCDataOvFlw[index+2] << 12 | (ADCDataValue[index+2] & 0xfff); | |
415 | } | |
416 | //for (Int_t i=0;i<24;i++)printf("ADCData[%d] = %d\n",i,ADCData[i]); | |
417 | ||
418 | // End of Block | |
419 | UInt_t ADCEndBlockGEO = ADCHeaderGEO; | |
420 | UInt_t ADCEndBlockEvCount = gAlice->GetEventNrInRun(); | |
421 | ||
422 | ADCEndBlock = ADCEndBlockGEO << 27 | 0x1 << 26 | ADCEndBlockEvCount; | |
423 | ||
424 | //printf("ADCEndBlock = %d\n",ADCEndBlock); | |
425 | ||
426 | ||
427 | // open the output file | |
428 | char fileName[30]; | |
429 | sprintf(fileName, "ZDC_%d.ddl", AliZDCRawStream::kDDLOffset); | |
430 | #ifndef __DECCXX | |
431 | ofstream file(fileName, ios::binary); | |
432 | #else | |
433 | ofstream file(fileName); | |
434 | #endif | |
435 | ||
436 | // write the DDL data header | |
437 | AliRawDataHeader header; | |
438 | header.fSize = sizeof(header) + sizeof(ADCHeader) + | |
439 | sizeof(ADCData) + sizeof(ADCEndBlock); | |
440 | //printf("sizeof header = %d, ADCHeader = %d, ADCData = %d, ADCEndBlock = %d\n", | |
441 | // sizeof(header),sizeof(ADCHeader),sizeof(ADCData),sizeof(ADCEndBlock)); | |
442 | header.SetAttribute(0); // valid data | |
443 | file.write((char*)(&header), sizeof(header)); | |
444 | ||
445 | // write the raw data and close the file | |
446 | file.write((char*) &ADCHeader, sizeof (ADCHeader)); | |
447 | file.write((char*)(ADCData), sizeof(ADCData)); | |
448 | file.write((char*) &ADCEndBlock, sizeof(ADCEndBlock)); | |
449 | file.close(); | |
450 | ||
451 | // unload the digits | |
452 | fLoader->UnloadDigits(); | |
453 | } | |
454 | ||
455 | //______________________________________________________________________ | |
456 | void AliZDC::SetTreeAddress(){ | |
457 | // Set branch address for the Trees. | |
458 | // Inputs: | |
459 | // none. | |
460 | // Outputs: | |
461 | // none. | |
462 | // Return: | |
463 | // none. | |
464 | if (fLoader->TreeH() && (fHits == 0x0)) | |
465 | fHits = new TClonesArray("AliZDCHit",1000); | |
466 | ||
467 | AliDetector::SetTreeAddress(); | |
468 | } | |
469 | ||
470 | ||
471 | //Calibration methods (by Alberto Colla) | |
472 | ||
473 | ||
474 | //________________________________________________________________ | |
475 | void AliZDC::CreateCalibData() | |
476 | { | |
477 | // | |
478 | //if (fCalibData) delete fCalibData; // delete previous version | |
479 | fCalibData = new AliZDCCalibData(GetName()); | |
480 | } | |
481 | //________________________________________________________________ | |
482 | void AliZDC::WriteCalibData(Int_t option) | |
483 | { | |
484 | // | |
485 | const int kCompressLevel = 9; | |
486 | const char defname[] = "$(ALICE)/AliRoot/data/AliZDCCalib.root"; | |
487 | char* fnam = GetZDCCalibFName(); | |
488 | if (!fnam || fnam[0]=='\0') { | |
489 | fnam = gSystem->ExpandPathName(defname); | |
490 | Warning("WriteCalibData","No File Name is provided, using default %s",fnam); | |
491 | } | |
492 | TFile* cdfile = TFile::Open(fnam,"UPDATE","",kCompressLevel); | |
493 | ||
494 | // Writes Calibration Data to current directory. | |
495 | // User MUST take care of corresponding file opening and ->cd()... !!! | |
496 | // By default, the object is overwritten. Use 0 option for opposite. | |
497 | if (option) option = TObject::kOverwrite; | |
498 | if (fCalibData) fCalibData->Write(0,option); | |
499 | else if (fCalibData) fCalibData->Write(0,option); | |
500 | ||
501 | cdfile->Close(); | |
502 | delete cdfile; | |
503 | } | |
504 | ||
505 | //________________________________________________________________ | |
506 | void AliZDC::LoadCalibData() | |
507 | { | |
508 | // | |
509 | char* fnam = GetZDCCalibFName(); | |
510 | if (!fnam || fnam[0]=='\0') return; | |
511 | if (!gAlice->IsFileAccessible(fnam)) { | |
512 | Error("LoadCalibData","ZDC Calibration Data file is not accessible, %s",fnam); | |
513 | exit(1); | |
514 | } | |
515 | TFile* cdfile = TFile::Open(fnam); | |
516 | ||
517 | // Loads Calibration Data from current directory. | |
518 | // User MUST take care of corresponding file opening and ->cd()...!!! | |
519 | // | |
520 | if (fCalibData) delete fCalibData; // delete previous version | |
521 | TString dtname = "Calib_"; | |
522 | dtname += GetName(); | |
523 | fCalibData = (AliZDCCalibData*) gDirectory->Get(dtname.Data()); | |
524 | if (!fCalibData) { | |
525 | Error("LoadCalibData","No Calibration data found for %s",GetName()); | |
526 | exit(1); | |
527 | } | |
528 | ||
529 | cdfile->Close(); | |
530 | delete cdfile; | |
531 | } | |
532 | ||
533 | ||
534 | //Calibration methods (by Alberto Colla) |