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>
33 // --- AliRoot header files
34 #include "AliDetector.h"
36 #include "AliZDCHit.h"
37 #include "AliZDCSDigit.h"
38 #include "AliZDCDigit.h"
39 #include "AliZDCDigitizer.h"
40 #include "AliZDCRawStream.h"
42 #include "AliRawDataHeader.h"
43 #include "AliLoader.h"
50 //_____________________________________________________________________________
54 // Default constructor for the Zero Degree Calorimeter base class
68 //_____________________________________________________________________________
69 AliZDC::AliZDC(const char *name, const char *title)
70 : AliDetector(name,title)
73 // Standard constructor for the Zero Degree Calorimeter base class
79 // Allocate the hits array
80 fHits = new TClonesArray("AliZDCHit",1000);
81 gAlice->GetMCApp()->AddHitList(fHits);
87 //____________________________________________________________________________
97 //_____________________________________________________________________________
98 void AliZDC::AddHit(Int_t track, Int_t *vol, Float_t *hits)
101 // Add a ZDC hit to the hit list.
102 // -> We make use of 2 array of hits:
103 // [1] fHits (the usual one) that contains hits for each PRIMARY
104 // [2] fStHits that contains hits for each EVENT and is used to
105 // obtain digits at the end of each event
108 static Float_t primKinEn, xImpact, yImpact, sFlag;
110 AliZDCHit *newquad, *curprimquad;
111 newquad = new AliZDCHit(fIshunt, track, vol, hits);
112 TClonesArray &lhits = *fHits;
115 // First hit -> setting flag for primary or secondary particle
116 Int_t primary = gAlice->GetMCApp()->GetPrimary(track);
117 if(track != primary){
118 newquad->SetSFlag(1); // SECONDARY particle entering the ZDC
120 else if(track == primary){
121 newquad->SetSFlag(0); // PRIMARY particle entering the ZDC
123 sFlag = newquad->GetSFlag();
124 primKinEn = newquad->GetPrimKinEn();
125 xImpact = newquad->GetXImpact();
126 yImpact = newquad->GetYImpact();
129 newquad->SetPrimKinEn(primKinEn);
130 newquad->SetXImpact(xImpact);
131 newquad->SetYImpact(yImpact);
132 newquad->SetSFlag(sFlag);
136 for(j=0; j<fNhits; j++){
137 // If hits are equal (same track, same volume), sum them.
138 curprimquad = (AliZDCHit*) lhits[j];
139 if(*curprimquad == *newquad){
140 *curprimquad = *curprimquad+*newquad;
146 //Otherwise create a new hit
147 new(lhits[fNhits]) AliZDCHit(newquad);
153 //_____________________________________________________________________________
154 void AliZDC::BuildGeometry()
157 // Build the ROOT TNode geometry for event display
158 // in the Zero Degree Calorimeter
159 // This routine is dummy for the moment
164 const int kColorZDC = kBlue;
167 top=gAlice->GetGeometry()->GetNode("alice");
170 brik = new TBRIK("S_ZDC","ZDC box","void",300,300,5);
172 node = new TNode("ZDC","ZDC","S_ZDC",0,0,600,"");
173 node->SetLineColor(kColorZDC);
177 //_____________________________________________________________________________
178 Int_t AliZDC::DistancetoPrimitive(Int_t , Int_t )
181 // Distance from the mouse to the Zero Degree Calorimeter
187 //____________________________________________________________________________
188 Float_t AliZDC::ZMin(void) const
190 // Minimum dimension of the ZDC module in z
194 //____________________________________________________________________________
195 Float_t AliZDC::ZMax(void) const
197 // Maximum dimension of the ZDC module in z
202 //_____________________________________________________________________________
203 void AliZDC::MakeBranch(Option_t *opt, const char * /*file*/)
206 // Create Tree branches for the ZDC
210 sprintf(branchname,"%s",GetName());
212 const char *cH = strstr(opt,"H");
214 if (cH && fLoader->TreeH())
215 fHits = new TClonesArray("AliZDCHit",1000);
217 AliDetector::MakeBranch(opt);
220 //_____________________________________________________________________________
221 void AliZDC::Hits2SDigits()
223 // Create summable digits from hits
225 if (GetDebug()) printf("\n Entering AliZDC::Hits2Digits() ");
227 fLoader->LoadHits("read");
228 fLoader->LoadSDigits("recreate");
229 AliRunLoader* runLoader = fLoader->GetRunLoader();
231 AliZDCSDigit* psdigit = &sdigit;
234 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
235 Float_t pmCZN = 0, pmCZP = 0, pmQZN[4], pmQZP[4], pmZEM1 = 0, pmZEM2 = 0;
236 for (Int_t i = 0; i < 4; i++) pmQZN[i] = pmQZP[i] = 0;
238 runLoader->GetEvent(iEvent);
239 TTree* treeH = fLoader->TreeH();
240 Int_t ntracks = (Int_t) treeH->GetEntries();
245 for (Int_t itrack = 0; itrack < ntracks; itrack++) {
246 treeH->GetEntry(itrack);
247 for (AliZDCHit* zdcHit = (AliZDCHit*)FirstHit(-1); zdcHit;
248 zdcHit = (AliZDCHit*)NextHit()) {
250 sector[0] = zdcHit->GetVolume(0);
251 sector[1] = zdcHit->GetVolume(1);
252 if ((sector[1] < 1) || (sector[1] > 4)) {
253 Error("Hits2SDigits", "sector[0] = %d, sector[1] = %d",
254 sector[0], sector[1]);
257 Float_t lightQ = zdcHit->GetLightPMQ();
258 Float_t lightC = zdcHit->GetLightPMC();
260 if (sector[0] == 1) { //ZN
262 pmQZN[sector[1]-1] += lightQ;
263 } else if (sector[0] == 2) { //ZP
265 pmQZP[sector[1]-1] += lightQ;
266 } else if (sector[0] == 3) { //ZEM
267 if (sector[1] == 1) pmZEM1 += lightC;
268 else pmZEM2 += lightQ;
273 // create the output tree
274 fLoader->MakeTree("S");
275 TTree* treeS = fLoader->TreeS();
276 const Int_t kBufferSize = 4000;
277 treeS->Branch(GetName(), "AliZDCSDigit", &psdigit, kBufferSize);
279 // Create sdigits for ZN
280 sector[0] = 1; // Detector = ZN
281 sector[1] = 0; // Common PM ADC
282 new(psdigit) AliZDCSDigit(sector, pmCZN);
283 if (pmCZN > 0) treeS->Fill();
284 for (Int_t j = 0; j < 4; j++) {
285 sector[1] = j+1; // Towers PM ADCs
286 new(psdigit) AliZDCSDigit(sector, pmQZN[j]);
287 if (pmQZN[j] > 0) treeS->Fill();
290 // Create sdigits for ZP
291 sector[0] = 2; // Detector = ZP
292 sector[1] = 0; // Common PM ADC
293 new(psdigit) AliZDCSDigit(sector, pmCZP);
294 if (pmCZP > 0) treeS->Fill();
295 for (Int_t j = 0; j < 4; j++) {
296 sector[1] = j+1; // Towers PM ADCs
297 new(psdigit) AliZDCSDigit(sector, pmQZP[j]);
298 if (pmQZP[j] > 0) treeS->Fill();
301 // Create sdigits for ZEM
303 sector[1] = 1; // Detector = ZEM1
304 new(psdigit) AliZDCSDigit(sector, pmZEM1);
305 if (pmZEM1 > 0) treeS->Fill();
306 sector[1] = 2; // Detector = ZEM2
307 new(psdigit) AliZDCSDigit(sector, pmZEM2);
308 if (pmZEM2 > 0) treeS->Fill();
310 // write the output tree
311 fLoader->WriteSDigits("OVERWRITE");
314 fLoader->UnloadHits();
315 fLoader->UnloadSDigits();
318 //_____________________________________________________________________________
319 AliDigitizer* AliZDC::CreateDigitizer(AliRunDigitizer* manager) const
321 // Create the digitizer for ZDC
323 return new AliZDCDigitizer(manager);
326 //_____________________________________________________________________________
327 void AliZDC::Digits2Raw()
329 // Convert ZDC digits to raw data
331 // preliminary format: 12 interger values (ZNC, ZNQ1-4, ZPC, ZPQ1-4, ZEM1,2)
332 // For the CAEN module V965 we have an header, the Data Words and an End Of Block
338 fLoader->LoadDigits("read");
340 AliZDCDigit* pdigit = &digit;
341 TTree* treeD = fLoader->TreeD();
343 treeD->SetBranchAddress("ZDC", &pdigit);
347 UInt_t ADCHeaderGEO = 0;
348 UInt_t ADCHeaderCRATE = 0;
349 UInt_t ADCHeaderCNT = (UInt_t) treeD->GetEntries();
351 ADCHeader = ADCHeaderGEO << 27 | 0x1 << 25 | ADCHeaderCRATE << 16 |
354 //printf("ADCHeader = %d\n",ADCHeader);
357 UInt_t ADCDataGEO = ADCHeaderGEO;
358 UInt_t ADCDataValue[24];
359 UInt_t ADCDataOvFlw[24];
360 for(Int_t i = 0; i < 24; i++){
364 UInt_t ADCDataChannel = 0;
367 for (Int_t iDigit = 0; iDigit < treeD->GetEntries(); iDigit++) {
368 treeD->GetEntry(iDigit);
369 if (!pdigit) continue;
373 if(digit.GetSector(0)!=3){
374 index = (digit.GetSector(0)-1) + digit.GetSector(1)*4;
375 ADCDataChannel = (digit.GetSector(0)-1)*8 + digit.GetSector(1);
378 index = 19 + digit.GetSector(1);
379 ADCDataChannel = 5 + digit.GetSector(1)*8;
382 if ((index < 0) || (index >= 22)) {
383 Error("Digits2Raw", "sector[0] = %d, sector[1] = %d",
384 digit.GetSector(0), digit.GetSector(1));
388 ADCDataValue[index] = digit.GetADCValue(0);
389 if (ADCDataValue[index] > 2047) ADCDataOvFlw[index] = 1;
390 ADCDataValue[index+2] = digit.GetADCValue(1);
391 if (ADCDataValue[index+2] > 2047) ADCDataOvFlw[index+2] = 1;
393 ADCData[index] = ADCDataGEO << 27 | ADCDataChannel << 17 |
394 ADCDataOvFlw[index] << 12 | (ADCDataValue[index] & 0xfff);
395 ADCData[index+2] = ADCDataGEO << 27 | ADCDataChannel << 17 | 0x1 << 16 |
396 ADCDataOvFlw[index+2] << 12 | (ADCDataValue[index+2] & 0xfff);
398 //for (Int_t i=0;i<24;i++)printf("ADCData[%d] = %d\n",i,ADCData[i]);
401 UInt_t ADCEndBlockGEO = ADCHeaderGEO;
402 UInt_t ADCEndBlockEvCount = gAlice->GetEventNrInRun();
404 ADCEndBlock = ADCEndBlockGEO << 27 | 0x1 << 26 | ADCEndBlockEvCount;
406 //printf("ADCEndBlock = %d\n",ADCEndBlock);
409 // open the output file
411 sprintf(fileName, "ZDC_%d.ddl", AliZDCRawStream::kDDLOffset);
413 ofstream file(fileName, ios::binary);
415 ofstream file(fileName);
418 // write the DDL data header
419 AliRawDataHeader header;
420 header.fSize = sizeof(header) + sizeof(ADCHeader) +
421 sizeof(ADCData) + sizeof(ADCEndBlock);
422 //printf("sizeof header = %d, ADCHeader = %d, ADCData = %d, ADCEndBlock = %d\n",
423 // sizeof(header),sizeof(ADCHeader),sizeof(ADCData),sizeof(ADCEndBlock));
424 header.SetAttribute(0); // valid data
425 file.write((char*)(&header), sizeof(header));
427 // write the raw data and close the file
428 file.write((char*) &ADCHeader, sizeof (ADCHeader));
429 file.write((char*)(ADCData), sizeof(ADCData));
430 file.write((char*) &ADCEndBlock, sizeof(ADCEndBlock));
434 fLoader->UnloadDigits();
437 //______________________________________________________________________
438 void AliZDC::SetTreeAddress(){
439 // Set branch address for the Trees.
446 if (fLoader->TreeH() && (fHits == 0x0))
447 fHits = new TClonesArray("AliZDCHit",1000);
449 AliDetector::SetTreeAddress();