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"
55 //_____________________________________________________________________________
59 // Default constructor for the Zero Degree Calorimeter base class
73 //_____________________________________________________________________________
74 AliZDC::AliZDC(const char *name, const char *title)
75 : AliDetector(name,title)
78 // Standard constructor for the Zero Degree Calorimeter base class
84 // Allocate the hits array
85 fHits = new TClonesArray("AliZDCHit",1000);
86 gAlice->GetMCApp()->AddHitList(fHits);
88 char sensname[5],senstitle[25];
89 sprintf(sensname,"ZDC");
90 sprintf(senstitle,"ZDC dummy");
91 SetName(sensname); SetTitle(senstitle);
99 //____________________________________________________________________________
110 //_____________________________________________________________________________
111 void AliZDC::AddHit(Int_t track, Int_t *vol, Float_t *hits)
114 // Add a ZDC hit to the hit list.
115 // -> We make use of 2 array of hits:
116 // [1] fHits (the usual one) that contains hits for each PRIMARY
117 // [2] fStHits that contains hits for each EVENT and is used to
118 // obtain digits at the end of each event
121 static Float_t primKinEn, xImpact, yImpact, sFlag;
123 AliZDCHit *newquad, *curprimquad;
124 newquad = new AliZDCHit(fIshunt, track, vol, hits);
125 TClonesArray &lhits = *fHits;
128 // First hit -> setting flag for primary or secondary particle
129 Int_t primary = gAlice->GetMCApp()->GetPrimary(track);
130 if(track != primary){
131 newquad->SetSFlag(1); // SECONDARY particle entering the ZDC
133 else if(track == primary){
134 newquad->SetSFlag(0); // PRIMARY particle entering the ZDC
136 sFlag = newquad->GetSFlag();
137 primKinEn = newquad->GetPrimKinEn();
138 xImpact = newquad->GetXImpact();
139 yImpact = newquad->GetYImpact();
142 newquad->SetPrimKinEn(primKinEn);
143 newquad->SetXImpact(xImpact);
144 newquad->SetYImpact(yImpact);
145 newquad->SetSFlag(sFlag);
149 for(j=0; j<fNhits; j++){
150 // If hits are equal (same track, same volume), sum them.
151 curprimquad = (AliZDCHit*) lhits[j];
152 if(*curprimquad == *newquad){
153 *curprimquad = *curprimquad+*newquad;
159 //Otherwise create a new hit
160 new(lhits[fNhits]) AliZDCHit(newquad);
166 //_____________________________________________________________________________
167 void AliZDC::BuildGeometry()
170 // Build the ROOT TNode geometry for event display
171 // in the Zero Degree Calorimeter
172 // This routine is dummy for the moment
177 const int kColorZDC = kBlue;
180 top=gAlice->GetGeometry()->GetNode("alice");
183 brik = new TBRIK("S_ZDC","ZDC box","void",300,300,5);
185 node = new TNode("ZDC","ZDC","S_ZDC",0,0,600,"");
186 node->SetLineColor(kColorZDC);
190 //_____________________________________________________________________________
191 Int_t AliZDC::DistancetoPrimitive(Int_t , Int_t )
194 // Distance from the mouse to the Zero Degree Calorimeter
200 //____________________________________________________________________________
201 Float_t AliZDC::ZMin(void) const
203 // Minimum dimension of the ZDC module in z
207 //____________________________________________________________________________
208 Float_t AliZDC::ZMax(void) const
210 // Maximum dimension of the ZDC module in z
215 //_____________________________________________________________________________
216 void AliZDC::MakeBranch(Option_t *opt, const char * /*file*/)
219 // Create Tree branches for the ZDC
223 sprintf(branchname,"%s",GetName());
225 const char *cH = strstr(opt,"H");
227 if (cH && fLoader->TreeH())
228 fHits = new TClonesArray("AliZDCHit",1000);
230 AliDetector::MakeBranch(opt);
233 //_____________________________________________________________________________
234 void AliZDC::Hits2SDigits()
236 // Create summable digits from hits
238 if (GetDebug()) printf("\n Entering AliZDC::Hits2Digits() ");
240 fLoader->LoadHits("read");
241 fLoader->LoadSDigits("recreate");
242 AliRunLoader* runLoader = fLoader->GetRunLoader();
244 AliZDCSDigit* psdigit = &sdigit;
247 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
248 Float_t pmCZN = 0, pmCZP = 0, pmQZN[4], pmQZP[4], pmZEM1 = 0, pmZEM2 = 0;
249 for (Int_t i = 0; i < 4; i++) pmQZN[i] = pmQZP[i] = 0;
251 runLoader->GetEvent(iEvent);
252 TTree* treeH = fLoader->TreeH();
253 Int_t ntracks = (Int_t) treeH->GetEntries();
258 for (Int_t itrack = 0; itrack < ntracks; itrack++) {
259 treeH->GetEntry(itrack);
260 for (AliZDCHit* zdcHit = (AliZDCHit*)FirstHit(-1); zdcHit;
261 zdcHit = (AliZDCHit*)NextHit()) {
263 sector[0] = zdcHit->GetVolume(0);
264 sector[1] = zdcHit->GetVolume(1);
265 if ((sector[1] < 1) || (sector[1] > 4)) {
266 Error("Hits2SDigits", "sector[0] = %d, sector[1] = %d",
267 sector[0], sector[1]);
270 Float_t lightQ = zdcHit->GetLightPMQ();
271 Float_t lightC = zdcHit->GetLightPMC();
273 if (sector[0] == 1) { //ZN
275 pmQZN[sector[1]-1] += lightQ;
276 } else if (sector[0] == 2) { //ZP
278 pmQZP[sector[1]-1] += lightQ;
279 } else if (sector[0] == 3) { //ZEM
280 if (sector[1] == 1) pmZEM1 += lightC;
281 else pmZEM2 += lightQ;
286 // create the output tree
287 fLoader->MakeTree("S");
288 TTree* treeS = fLoader->TreeS();
289 const Int_t kBufferSize = 4000;
290 treeS->Branch(GetName(), "AliZDCSDigit", &psdigit, kBufferSize);
292 // Create sdigits for ZN
293 sector[0] = 1; // Detector = ZN
294 sector[1] = 0; // Common PM ADC
295 new(psdigit) AliZDCSDigit(sector, pmCZN);
296 if (pmCZN > 0) treeS->Fill();
297 for (Int_t j = 0; j < 4; j++) {
298 sector[1] = j+1; // Towers PM ADCs
299 new(psdigit) AliZDCSDigit(sector, pmQZN[j]);
300 if (pmQZN[j] > 0) treeS->Fill();
303 // Create sdigits for ZP
304 sector[0] = 2; // Detector = ZP
305 sector[1] = 0; // Common PM ADC
306 new(psdigit) AliZDCSDigit(sector, pmCZP);
307 if (pmCZP > 0) treeS->Fill();
308 for (Int_t j = 0; j < 4; j++) {
309 sector[1] = j+1; // Towers PM ADCs
310 new(psdigit) AliZDCSDigit(sector, pmQZP[j]);
311 if (pmQZP[j] > 0) treeS->Fill();
314 // Create sdigits for ZEM
316 sector[1] = 1; // Detector = ZEM1
317 new(psdigit) AliZDCSDigit(sector, pmZEM1);
318 if (pmZEM1 > 0) treeS->Fill();
319 sector[1] = 2; // Detector = ZEM2
320 new(psdigit) AliZDCSDigit(sector, pmZEM2);
321 if (pmZEM2 > 0) treeS->Fill();
323 // write the output tree
324 fLoader->WriteSDigits("OVERWRITE");
327 fLoader->UnloadHits();
328 fLoader->UnloadSDigits();
331 //_____________________________________________________________________________
332 AliDigitizer* AliZDC::CreateDigitizer(AliRunDigitizer* manager) const
334 // Create the digitizer for ZDC
336 return new AliZDCDigitizer(manager);
339 //_____________________________________________________________________________
340 void AliZDC::Digits2Raw()
342 // Convert ZDC digits to raw data
344 // preliminary format: 12 interger values (ZNC, ZNQ1-4, ZPC, ZPQ1-4, ZEM1,2)
345 // For the CAEN module V965 we have an header, the Data Words and an End Of Block
351 fLoader->LoadDigits("read");
353 AliZDCDigit* pdigit = &digit;
354 TTree* treeD = fLoader->TreeD();
356 treeD->SetBranchAddress("ZDC", &pdigit);
360 UInt_t ADCHeaderGEO = 0;
361 UInt_t ADCHeaderCRATE = 0;
362 UInt_t ADCHeaderCNT = (UInt_t) treeD->GetEntries();
364 ADCHeader = ADCHeaderGEO << 27 | 0x1 << 25 | ADCHeaderCRATE << 16 |
367 //printf("ADCHeader = %d\n",ADCHeader);
370 UInt_t ADCDataGEO = ADCHeaderGEO;
371 UInt_t ADCDataValue[24];
372 UInt_t ADCDataOvFlw[24];
373 for(Int_t i = 0; i < 24; i++){
377 UInt_t ADCDataChannel = 0;
380 for (Int_t iDigit = 0; iDigit < treeD->GetEntries(); iDigit++) {
381 treeD->GetEntry(iDigit);
382 if (!pdigit) continue;
386 if(digit.GetSector(0)!=3){
387 index = (digit.GetSector(0)-1) + digit.GetSector(1)*4;
388 ADCDataChannel = (digit.GetSector(0)-1)*8 + digit.GetSector(1);
391 index = 19 + digit.GetSector(1);
392 ADCDataChannel = 5 + digit.GetSector(1)*8;
395 if ((index < 0) || (index >= 22)) {
396 Error("Digits2Raw", "sector[0] = %d, sector[1] = %d",
397 digit.GetSector(0), digit.GetSector(1));
401 ADCDataValue[index] = digit.GetADCValue(0);
402 if (ADCDataValue[index] > 2047) ADCDataOvFlw[index] = 1;
403 ADCDataValue[index+2] = digit.GetADCValue(1);
404 if (ADCDataValue[index+2] > 2047) ADCDataOvFlw[index+2] = 1;
406 ADCData[index] = ADCDataGEO << 27 | ADCDataChannel << 17 |
407 ADCDataOvFlw[index] << 12 | (ADCDataValue[index] & 0xfff);
408 ADCData[index+2] = ADCDataGEO << 27 | ADCDataChannel << 17 | 0x1 << 16 |
409 ADCDataOvFlw[index+2] << 12 | (ADCDataValue[index+2] & 0xfff);
411 //for (Int_t i=0;i<24;i++)printf("ADCData[%d] = %d\n",i,ADCData[i]);
414 UInt_t ADCEndBlockGEO = ADCHeaderGEO;
415 UInt_t ADCEndBlockEvCount = gAlice->GetEventNrInRun();
417 ADCEndBlock = ADCEndBlockGEO << 27 | 0x1 << 26 | ADCEndBlockEvCount;
419 //printf("ADCEndBlock = %d\n",ADCEndBlock);
422 // open the output file
424 sprintf(fileName, "ZDC_%d.ddl", AliZDCRawStream::kDDLOffset);
426 ofstream file(fileName, ios::binary);
428 ofstream file(fileName);
431 // write the DDL data header
432 AliRawDataHeader header;
433 header.fSize = sizeof(header) + sizeof(ADCHeader) +
434 sizeof(ADCData) + sizeof(ADCEndBlock);
435 //printf("sizeof header = %d, ADCHeader = %d, ADCData = %d, ADCEndBlock = %d\n",
436 // sizeof(header),sizeof(ADCHeader),sizeof(ADCData),sizeof(ADCEndBlock));
437 header.SetAttribute(0); // valid data
438 file.write((char*)(&header), sizeof(header));
440 // write the raw data and close the file
441 file.write((char*) &ADCHeader, sizeof (ADCHeader));
442 file.write((char*)(ADCData), sizeof(ADCData));
443 file.write((char*) &ADCEndBlock, sizeof(ADCEndBlock));
447 fLoader->UnloadDigits();
450 //______________________________________________________________________
451 void AliZDC::SetTreeAddress(){
452 // Set branch address for the Trees.
459 if (fLoader->TreeH() && (fHits == 0x0))
460 fHits = new TClonesArray("AliZDCHit",1000);
462 AliDetector::SetTreeAddress();
466 //Calibration methods (by Alberto Colla)
469 //________________________________________________________________
470 void AliZDC::CreateCalibData()
473 //if (fCalibData) delete fCalibData; // delete previous version
474 fCalibData = new AliZDCCalibData(GetName());
476 //________________________________________________________________
477 void AliZDC::WriteCalibData(Int_t option)
480 const int kCompressLevel = 9;
481 const char defname[] = "$(ALICE)/AliRoot/data/AliZDCCalib.root";
482 char* fnam = gAlice->GetZDCCalibFName();
483 if (!fnam || fnam[0]=='\0') {
484 fnam = gSystem->ExpandPathName(defname);
485 Warning("WriteCalibData","No File Name is provided, using default %s",fnam);
487 TFile* cdfile = TFile::Open(fnam,"UPDATE","",kCompressLevel);
489 // Writes Calibration Data to current directory.
490 // User MUST take care of corresponding file opening and ->cd()... !!!
491 // By default, the object is overwritten. Use 0 option for opposite.
492 if (option) option = TObject::kOverwrite;
493 if (fCalibData) fCalibData->Write(0,option);
494 else if (fCalibData) fCalibData->Write(0,option);
500 //________________________________________________________________
501 void AliZDC::LoadCalibData()
504 char* fnam = gAlice->GetZDCCalibFName();
505 if (!fnam || fnam[0]=='\0') return;
506 if (!gAlice->IsFileAccessible(fnam)) {
507 Error("LoadCalibData","ZDC Calibration Data file is not accessible, %s",fnam);
510 TFile* cdfile = TFile::Open(fnam);
512 // Loads Calibration Data from current directory.
513 // User MUST take care of corresponding file opening and ->cd()...!!!
515 if (fCalibData) delete fCalibData; // delete previous version
516 TString dtname = "Calib_";
518 fCalibData = (AliZDCCalibData*) gDirectory->Get(dtname.Data());
520 Error("LoadCalibData","No Calibration data found for %s",GetName());
529 //Calibration methods (by Alberto Colla)