1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
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 //
25 ///////////////////////////////////////////////////////////////////////////////
29 #include <TGeometry.h>
35 // --- AliRoot header files
36 #include "AliDetector.h"
38 #include "AliZDCHit.h"
39 #include "AliZDCSDigit.h"
40 #include "AliZDCDigit.h"
41 #include "AliZDCDigitizer.h"
42 #include "AliZDCRawStream.h"
43 #include "AliZDCCalibData.h"
45 #include "AliRawDataHeader.h"
46 #include "AliLoader.h"
56 //_____________________________________________________________________________
60 // Default constructor for the Zero Degree Calorimeter base class
76 //_____________________________________________________________________________
77 AliZDC::AliZDC(const char *name, const char *title)
78 : AliDetector(name,title)
81 // Standard constructor for the Zero Degree Calorimeter base class
87 // Allocate the hits array
88 fHits = new TClonesArray("AliZDCHit",1000);
89 gAlice->GetMCApp()->AddHitList(fHits);
91 char sensname[5],senstitle[25];
92 sprintf(sensname,"ZDC");
93 sprintf(senstitle,"ZDC dummy");
94 SetName(sensname); SetTitle(senstitle);
104 //____________________________________________________________________________
117 //_____________________________________________________________________________
118 void AliZDC::AddHit(Int_t track, Int_t *vol, Float_t *hits)
121 // Add a ZDC hit to the hit list.
122 // -> We make use of 2 array of hits:
123 // [1] fHits (the usual one) that contains hits for each PRIMARY
124 // [2] fStHits that contains hits for each EVENT and is used to
125 // obtain digits at the end of each event
128 static Float_t primKinEn, xImpact, yImpact, sFlag;
130 AliZDCHit *newquad, *curprimquad;
131 newquad = new AliZDCHit(fIshunt, track, vol, hits);
132 TClonesArray &lhits = *fHits;
135 // First hit -> setting flag for primary or secondary particle
136 Int_t primary = gAlice->GetMCApp()->GetPrimary(track);
137 if(track != primary){
138 newquad->SetSFlag(1); // SECONDARY particle entering the ZDC
140 else if(track == primary){
141 newquad->SetSFlag(0); // PRIMARY particle entering the ZDC
143 sFlag = newquad->GetSFlag();
144 primKinEn = newquad->GetPrimKinEn();
145 xImpact = newquad->GetXImpact();
146 yImpact = newquad->GetYImpact();
149 newquad->SetPrimKinEn(primKinEn);
150 newquad->SetXImpact(xImpact);
151 newquad->SetYImpact(yImpact);
152 newquad->SetSFlag(sFlag);
156 for(j=0; j<fNhits; j++){
157 // If hits are equal (same track, same volume), sum them.
158 curprimquad = (AliZDCHit*) lhits[j];
159 if(*curprimquad == *newquad){
160 *curprimquad = *curprimquad+*newquad;
166 //Otherwise create a new hit
167 new(lhits[fNhits]) AliZDCHit(newquad);
173 //_____________________________________________________________________________
174 void AliZDC::BuildGeometry()
177 // Build the ROOT TNode geometry for event display
178 // in the Zero Degree Calorimeter
179 // This routine is dummy for the moment
184 const int kColorZDC = kBlue;
187 top=gAlice->GetGeometry()->GetNode("alice");
190 brik = new TBRIK("S_ZDC","ZDC box","void",300,300,5);
192 node = new TNode("ZDC","ZDC","S_ZDC",0,0,600,"");
193 node->SetLineColor(kColorZDC);
197 //____________________________________________________________________________
198 Float_t AliZDC::ZMin(void) const
200 // Minimum dimension of the ZDC module in z
204 //____________________________________________________________________________
205 Float_t AliZDC::ZMax(void) const
207 // Maximum dimension of the ZDC module in z
212 //_____________________________________________________________________________
213 void AliZDC::MakeBranch(Option_t *opt)
216 // Create Tree branches for the ZDC
220 sprintf(branchname,"%s",GetName());
222 const char *cH = strstr(opt,"H");
224 if (cH && fLoader->TreeH())
225 fHits = new TClonesArray("AliZDCHit",1000);
227 AliDetector::MakeBranch(opt);
230 //_____________________________________________________________________________
231 void AliZDC::Hits2SDigits()
233 // Create summable digits from hits
235 AliDebug(1,"\n Entering AliZDC::Hits2Digits() ");
237 fLoader->LoadHits("read");
238 fLoader->LoadSDigits("recreate");
239 AliRunLoader* runLoader = fLoader->GetRunLoader();
241 AliZDCSDigit* psdigit = &sdigit;
244 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
245 Float_t pmCZN = 0, pmCZP = 0, pmQZN[4], pmQZP[4], pmZEM1 = 0, pmZEM2 = 0;
246 for (Int_t i = 0; i < 4; i++) pmQZN[i] = pmQZP[i] = 0;
248 runLoader->GetEvent(iEvent);
249 TTree* treeH = fLoader->TreeH();
250 Int_t ntracks = (Int_t) treeH->GetEntries();
255 for (Int_t itrack = 0; itrack < ntracks; itrack++) {
256 treeH->GetEntry(itrack);
257 for (AliZDCHit* zdcHit = (AliZDCHit*)FirstHit(-1); zdcHit;
258 zdcHit = (AliZDCHit*)NextHit()) {
260 sector[0] = zdcHit->GetVolume(0);
261 sector[1] = zdcHit->GetVolume(1);
262 if ((sector[1] < 1) || (sector[1] > 4)) {
263 Error("Hits2SDigits", "sector[0] = %d, sector[1] = %d",
264 sector[0], sector[1]);
267 Float_t lightQ = zdcHit->GetLightPMQ();
268 Float_t lightC = zdcHit->GetLightPMC();
270 if (sector[0] == 1) { //ZN
272 pmQZN[sector[1]-1] += lightQ;
273 } else if (sector[0] == 2) { //ZP
275 pmQZP[sector[1]-1] += lightQ;
276 } else if (sector[0] == 3) { //ZEM
277 if (sector[1] == 1) pmZEM1 += lightC;
278 else pmZEM2 += lightQ;
283 // create the output tree
284 fLoader->MakeTree("S");
285 TTree* treeS = fLoader->TreeS();
286 const Int_t kBufferSize = 4000;
287 treeS->Branch(GetName(), "AliZDCSDigit", &psdigit, kBufferSize);
289 // Create sdigits for ZN
290 sector[0] = 1; // Detector = ZN
291 sector[1] = 0; // Common PM ADC
292 new(psdigit) AliZDCSDigit(sector, pmCZN);
293 if (pmCZN > 0) treeS->Fill();
294 for (Int_t j = 0; j < 4; j++) {
295 sector[1] = j+1; // Towers PM ADCs
296 new(psdigit) AliZDCSDigit(sector, pmQZN[j]);
297 if (pmQZN[j] > 0) treeS->Fill();
300 // Create sdigits for ZP
301 sector[0] = 2; // Detector = ZP
302 sector[1] = 0; // Common PM ADC
303 new(psdigit) AliZDCSDigit(sector, pmCZP);
304 if (pmCZP > 0) treeS->Fill();
305 for (Int_t j = 0; j < 4; j++) {
306 sector[1] = j+1; // Towers PM ADCs
307 new(psdigit) AliZDCSDigit(sector, pmQZP[j]);
308 if (pmQZP[j] > 0) treeS->Fill();
311 // Create sdigits for ZEM
313 sector[1] = 1; // Detector = ZEM1
314 new(psdigit) AliZDCSDigit(sector, pmZEM1);
315 if (pmZEM1 > 0) treeS->Fill();
316 sector[1] = 2; // Detector = ZEM2
317 new(psdigit) AliZDCSDigit(sector, pmZEM2);
318 if (pmZEM2 > 0) treeS->Fill();
320 // write the output tree
321 fLoader->WriteSDigits("OVERWRITE");
324 fLoader->UnloadHits();
325 fLoader->UnloadSDigits();
328 //_____________________________________________________________________________
329 AliDigitizer* AliZDC::CreateDigitizer(AliRunDigitizer* manager) const
331 // Create the digitizer for ZDC
333 return new AliZDCDigitizer(manager);
336 //_____________________________________________________________________________
337 void AliZDC::Digits2Raw()
339 // Convert ZDC digits to raw data
341 // Format: 22 interger values -> ZN1 (C+Q1-4), ZP1 (C+Q1-4), ZEM1, 2, ZN (C+Q1-4), ZP2 (C+Q1-4))
342 // For the CAEN module V965 we have an header, the Data Words and an End Of Block
343 // 24 channels read on 1st ADC module, 20 channels read on 2nd ADC module
344 const int knADCData1=24, knADCData2=20;
346 UInt_t lADCData1[knADCData1];
349 UInt_t lADCData2[knADCData2];
354 fLoader->LoadDigits("read");
356 AliZDCDigit* pdigit = &digit;
357 TTree* treeD = fLoader->TreeD();
359 treeD->SetBranchAddress("ZDC", &pdigit);
360 //printf("\t AliZDC::Digits2raw -> TreeD has %d entries\n",(Int_t) treeD->GetEntries());
361 //digit.Print(""); // Ch. debug
366 UInt_t lADCHeaderGEO = 0;
367 UInt_t lADCHeaderCRATE = 0;
368 UInt_t lADCHeaderCNT1 = knADCData1;
369 UInt_t lADCHeaderCNT2 = knADCData2;
371 lADCHeader1 = lADCHeaderGEO << 27 | 0x1 << 25 | lADCHeaderCRATE << 16 |
372 lADCHeaderCNT1 << 8 ;
374 lADCHeader2 = lADCHeaderGEO << 27 | 0x1 << 25 | lADCHeaderCRATE << 16 |
375 lADCHeaderCNT2 << 8 ;
377 //printf("\t lADCHeader1 = %x, lADCHeader2 = %x\n",lADCHeader1, lADCHeader2);
380 UInt_t lADCDataGEO = lADCHeaderGEO;
381 UInt_t lADCDataValue1[knADCData1];
382 UInt_t lADCDataValue2[knADCData2];
383 UInt_t lADCDataOvFlw1[knADCData1];
384 UInt_t lADCDataOvFlw2[knADCData2];
385 for(Int_t i = 0; i<knADCData1 ; i++){
386 lADCDataValue1[i] = 0;
387 lADCDataOvFlw1[i] = 0;
389 for(Int_t i = 0; i<knADCData2 ; i++){
390 lADCDataValue2[i] = 0;
391 lADCDataOvFlw2[i] = 0;
393 UInt_t lADCDataChannel = 0;
396 for (Int_t iDigit = 0; iDigit<treeD->GetEntries(); iDigit++) {
397 treeD->GetEntry(iDigit);
398 if (!pdigit) continue;
401 Int_t index1 = 0, index2 = 0;
402 // ADC #1 (ZN1, ZP1, ZEM1,2)
403 if(digit.GetSector(0)==1 || digit.GetSector(0)==2 || digit.GetSector(0)==3){
404 if(digit.GetSector(0)==1 || digit.GetSector(0)==2){
405 index1 = (digit.GetSector(0)-1) + digit.GetSector(1)*4; // ZN1 or ZP1
406 lADCDataChannel = (digit.GetSector(0)-1)*8 + digit.GetSector(1);
408 else if(digit.GetSector(0)==3){ // ZEM 1,2
409 index1 = 20 + (digit.GetSector(1)-1);
410 lADCDataChannel = 5 + (digit.GetSector(1)-1)*8;
413 /*printf("\t AliZDC::Digits2raw -> det %d, quad %d, index = %d, ADCch = %d\n",
414 digit.GetSector(0),digit.GetSector(1),index1,lADCDataChannel);// Ch. debug
417 lADCDataValue1[index1] = digit.GetADCValue(0); // High gain ADC ch.
418 if(lADCDataValue1[index1] > 2047) lADCDataOvFlw1[index1] = 1;
419 lADCDataValue1[index1+2] = digit.GetADCValue(1); // Low gain ADC ch.
420 if(lADCDataValue1[index1+2] > 2047) lADCDataOvFlw1[index1+2] = 1;
422 lADCData1[index1] = lADCDataGEO << 27 | lADCDataChannel << 17 |
423 lADCDataOvFlw1[index1] << 12 | (lADCDataValue1[index1] & 0xfff);
424 lADCData1[index1+2] = lADCDataGEO << 27 | lADCDataChannel << 17 | 0x1 << 16 |
425 lADCDataOvFlw1[index1+2] << 12 | (lADCDataValue1[index1+2] & 0xfff);
428 else if(digit.GetSector(0)==4 || digit.GetSector(0)==5){
429 index2 = (digit.GetSector(0)-4) + digit.GetSector(1)*4; // ZN2 or ZP2
430 lADCDataChannel = (digit.GetSector(0)-4)*8 + digit.GetSector(1);
432 /*printf("\t AliZDC::Digits2raw -> det %d, quad %d, index = %d, ADCch = %d\n",
433 digit.GetSector(0),digit.GetSector(1),index1,lADCDataChannel); // Ch. debug
436 lADCDataValue2[index2] = digit.GetADCValue(0);
437 if (lADCDataValue2[index2] > 2047) lADCDataOvFlw2[index2] = 1;
438 lADCDataValue2[index2+2] = digit.GetADCValue(1);
439 if (lADCDataValue2[index2+2] > 2047) lADCDataOvFlw2[index2+2] = 1;
441 lADCData2[index2] = lADCDataGEO << 27 | lADCDataChannel << 17 |
442 lADCDataOvFlw2[index2] << 12 | (lADCDataValue2[index2] & 0xfff);
443 lADCData2[index2+2] = lADCDataGEO << 27 | lADCDataChannel << 17 | 0x1 << 16 |
444 lADCDataOvFlw2[index2+2] << 12 | (lADCDataValue2[index2+2] & 0xfff);
446 if((index1<0) || (index1>23)) {
447 Error("Digits2Raw", "sector[0] = %d, sector[1] = %d",
448 digit.GetSector(0), digit.GetSector(1));
451 if((index2<0) || (index2>19)) {
452 Error("Digits2Raw", "sector[0] = %d, sector[1] = %d",
453 digit.GetSector(0), digit.GetSector(1));
459 //for(Int_t i=0;i<24;i++) printf("\t ADCData1[%d] = %x\n",i,lADCData1[i]);
460 //for(Int_t i=0;i<20;i++) printf("\t ADCData2[%d] = %x\n",i,lADCData2[i]);
463 UInt_t lADCEndBlockGEO = lADCHeaderGEO;
464 UInt_t lADCEndBlockEvCount = gAlice->GetEventNrInRun();
466 lADCEndBlock = lADCEndBlockGEO << 27 | 0x1 << 26 | lADCEndBlockEvCount;
468 //printf("\t ADCEndBlock = %d\n",lADCEndBlock);
471 // open the output file
473 strcpy(fileName,AliDAQ::DdlFileName("ZDC",0));
475 ofstream file(fileName, ios::binary);
477 ofstream file(fileName);
480 // write the DDL data header
481 AliRawDataHeader header;
482 header.fSize = sizeof(header) + sizeof(lADCHeader1) + sizeof(lADCData1) +
483 sizeof(lADCEndBlock)+ sizeof(lADCHeader2) + sizeof(lADCData2) + sizeof(lADCEndBlock);
484 /*printf("sizeof header = %d, ADCHeader1 = %d, ADCData1 = %d, ADCEndBlock = %d\n",
485 sizeof(header),sizeof(lADCHeader1),sizeof(lADCData1),sizeof(lADCEndBlock));
486 printf("sizeof header = %d, ADCHeader2 = %d, ADCData2 = %d, ADCEndBlock = %d\n",
487 sizeof(header),sizeof(lADCHeader2),sizeof(lADCData2),sizeof(lADCEndBlock));*/
488 header.SetAttribute(0); // valid data
489 file.write((char*)(&header), sizeof(header));
491 // write the raw data and close the file
492 file.write((char*) &lADCHeader1, sizeof (lADCHeader1));
493 file.write((char*)(lADCData1), sizeof(lADCData1));
494 file.write((char*) &lADCEndBlock, sizeof(lADCEndBlock));
495 file.write((char*) &lADCHeader2, sizeof (lADCHeader2));
496 file.write((char*)(lADCData2), sizeof(lADCData2));
497 file.write((char*) &lADCEndBlock, sizeof(lADCEndBlock));
501 fLoader->UnloadDigits();
504 //______________________________________________________________________
505 void AliZDC::SetTreeAddress(){
506 // Set branch address for the Trees.
513 if (fLoader->TreeH() && (fHits == 0x0))
514 fHits = new TClonesArray("AliZDCHit",1000);
516 AliDetector::SetTreeAddress();
520 //Calibration methods (by Alberto Colla)
523 //________________________________________________________________
524 void AliZDC::CreateCalibData()
527 //if (fCalibData) delete fCalibData; // delete previous version
528 fCalibData = new AliZDCCalibData(GetName());
530 //________________________________________________________________
531 void AliZDC::WriteCalibData(Int_t option)
534 const int kCompressLevel = 9;
535 char* fnam = GetZDCCalibFName();
536 if (!fnam || fnam[0]=='\0') {
537 fnam = gSystem->ExpandPathName("$(ALICE)/$(ALICE_LEVEL)/data/AliZDCCalib.root");
538 Warning("WriteCalibData","No File Name is provided, using default %s",fnam);
540 TFile* cdfile = TFile::Open(fnam,"UPDATE","",kCompressLevel);
542 // Writes Calibration Data to current directory.
543 // User MUST take care of corresponding file opening and ->cd()... !!!
544 // By default, the object is overwritten. Use 0 option for opposite.
545 if (option) option = TObject::kOverwrite;
546 if (fCalibData) fCalibData->Write(0,option);
547 else if (fCalibData) fCalibData->Write(0,option);
553 //________________________________________________________________
554 void AliZDC::LoadCalibData()
557 char* fnam = GetZDCCalibFName();
558 if (!fnam || fnam[0]=='\0') return;
559 if (!gAlice->IsFileAccessible(fnam)) {
560 Error("LoadCalibData","ZDC Calibration Data file is not accessible, %s",fnam);
563 TFile* cdfile = TFile::Open(fnam);
565 // Loads Calibration Data from current directory.
566 // User MUST take care of corresponding file opening and ->cd()...!!!
568 if (fCalibData) delete fCalibData; // delete previous version
569 TString dtname = "Calib_";
571 fCalibData = (AliZDCCalibData*) gDirectory->Get(dtname.Data());
573 Error("LoadCalibData","No Calibration data found for %s",GetName());
582 //Calibration methods (by Alberto Colla)