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 <TClonesArray.h>
30 #include <TGeometry.h>
37 // --- AliRoot header files
38 #include "AliDetector.h"
39 #include "AliRawDataHeader.h"
40 #include "AliRawReader.h"
41 #include "AliLoader.h"
47 #include "AliZDCHit.h"
48 #include "AliZDCSDigit.h"
49 #include "AliZDCDigit.h"
50 #include "AliZDCDigitizer.h"
51 #include "AliZDCRawStream.h"
52 #include "AliZDCCalibData.h"
53 #include "AliFstream.h"
58 //_____________________________________________________________________________
66 // Default constructor for the Zero Degree Calorimeter base class
77 //_____________________________________________________________________________
78 AliZDC::AliZDC(const char *name, const char *title) :
79 AliDetector(name,title),
85 // Standard constructor for the Zero Degree Calorimeter base class
93 fHits = new TClonesArray("AliZDCHit",1000);
94 gAlice->GetMCApp()->AddHitList(fHits);
96 char sensname[5],senstitle[25];
97 sprintf(sensname,"ZDC");
98 sprintf(senstitle,"ZDC dummy");
99 SetName(sensname); SetTitle(senstitle);
103 //____________________________________________________________________________
115 //_____________________________________________________________________________
116 AliZDC::AliZDC(const AliZDC& ZDC) :
117 AliDetector("ZDC","ZDC")
120 fNoShower = ZDC.fNoShower;
121 fCalibData = ZDC.fCalibData;
122 fZDCCalibFName = ZDC.fZDCCalibFName;
125 //_____________________________________________________________________________
126 AliZDC& AliZDC::operator=(const AliZDC& ZDC)
128 // assignement operator
130 fNoShower = ZDC.fNoShower;
131 fCalibData = ZDC.fCalibData;
132 fZDCCalibFName = ZDC.fZDCCalibFName;
136 //_____________________________________________________________________________
137 void AliZDC::AddHit(Int_t track, Int_t *vol, Float_t *hits)
140 // Add a ZDC hit to the hit list.
141 // -> We make use of 2 array of hits:
142 // [1] fHits (the usual one) that contains hits for each PRIMARY
143 // [2] fStHits that contains hits for each EVENT and is used to
144 // obtain digits at the end of each event
147 static Float_t primKinEn, xImpact, yImpact, sFlag;
149 AliZDCHit *newquad, *curprimquad;
150 newquad = new AliZDCHit(fIshunt, track, vol, hits);
151 TClonesArray &lhits = *fHits;
154 // First hit -> setting flag for primary or secondary particle
155 Int_t primary = gAlice->GetMCApp()->GetPrimary(track);
156 if(track != primary){
157 newquad->SetSFlag(1); // SECONDARY particle entering the ZDC
159 else if(track == primary){
160 newquad->SetSFlag(0); // PRIMARY particle entering the ZDC
162 sFlag = newquad->GetSFlag();
163 primKinEn = newquad->GetPrimKinEn();
164 xImpact = newquad->GetXImpact();
165 yImpact = newquad->GetYImpact();
168 newquad->SetPrimKinEn(primKinEn);
169 newquad->SetXImpact(xImpact);
170 newquad->SetYImpact(yImpact);
171 newquad->SetSFlag(sFlag);
175 for(j=0; j<fNhits; j++){
176 // If hits are equal (same track, same volume), sum them.
177 curprimquad = (AliZDCHit*) lhits[j];
178 if(*curprimquad == *newquad){
179 *curprimquad = *curprimquad+*newquad;
181 /*if(newquad->GetEnergy() != 0. || newquad->GetLightPMC() != 0. ||
182 newquad->GetLightPMQ() != 0.){
183 printf("\n\t --- Equal hits found\n");
184 curprimquad->Print("");
186 printf("\t --- Det. %d, Quad. %d: X = %f, E = %f, LightPMC = %f, LightPMQ = %f\n",
187 curprimquad->GetVolume(0),curprimquad->GetVolume(1),curprimquad->GetXImpact(),
188 curprimquad->GetEnergy(), curprimquad->GetLightPMC(), curprimquad->GetLightPMQ());
196 //Otherwise create a new hit
197 new(lhits[fNhits]) AliZDCHit(*newquad);
200 /*printf("\n\t New ZDC hit added! fNhits = %d\n", fNhits);
201 printf("\t Det. %d, Quad.t %d: X = %f, E = %f, LightPMC = %f, LightPMQ = %f\n",
202 newquad->GetVolume(0),newquad->GetVolume(1),newquad->GetXImpact(),
203 newquad->GetEnergy(), newquad->GetLightPMC(), newquad->GetLightPMQ());
208 //_____________________________________________________________________________
209 void AliZDC::BuildGeometry()
212 // Build the ROOT TNode geometry for event display
213 // in the Zero Degree Calorimeter
214 // This routine is dummy for the moment
219 const int kColorZDC = kBlue;
222 top=gAlice->GetGeometry()->GetNode("alice");
225 brik = new TBRIK("S_ZDC","ZDC box","void",300,300,5);
227 node = new TNode("ZDC","ZDC","S_ZDC",0,0,600,"");
228 node->SetLineColor(kColorZDC);
232 //____________________________________________________________________________
233 Float_t AliZDC::ZMin(void) const
235 // Minimum dimension of the ZDC module in z
239 //____________________________________________________________________________
240 Float_t AliZDC::ZMax(void) const
242 // Maximum dimension of the ZDC module in z
247 //_____________________________________________________________________________
248 void AliZDC::MakeBranch(Option_t *opt)
251 // Create Tree branches for the ZDC
255 sprintf(branchname,"%s",GetName());
257 const char *cH = strstr(opt,"H");
259 if(cH && fLoader->TreeH())
260 fHits = new TClonesArray("AliZDCHit",1000);
262 AliDetector::MakeBranch(opt);
265 //_____________________________________________________________________________
266 void AliZDC::Hits2SDigits()
268 // Create summable digits from hits
270 AliDebug(1,"\n Entering AliZDC::Hits2Digits() ");
272 fLoader->LoadHits("read");
273 fLoader->LoadSDigits("recreate");
274 AliRunLoader* runLoader = fLoader->GetRunLoader();
276 AliZDCSDigit* psdigit = &sdigit;
279 for(Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
280 Float_t pmCZN = 0, pmCZP = 0, pmQZN[4], pmQZP[4], pmZEM1 = 0, pmZEM2 = 0;
281 for(Int_t i = 0; i < 4; i++) pmQZN[i] = pmQZP[i] = 0;
283 runLoader->GetEvent(iEvent);
284 TTree* treeH = fLoader->TreeH();
285 Int_t ntracks = (Int_t) treeH->GetEntries();
290 for(Int_t itrack = 0; itrack < ntracks; itrack++) {
291 treeH->GetEntry(itrack);
292 for(AliZDCHit* zdcHit = (AliZDCHit*)FirstHit(-1); zdcHit;
293 zdcHit = (AliZDCHit*)NextHit()) {
295 sector[0] = zdcHit->GetVolume(0);
296 sector[1] = zdcHit->GetVolume(1);
297 if((sector[1] < 1) || (sector[1] > 4)) {
298 Error("Hits2SDigits", "sector[0] = %d, sector[1] = %d",
299 sector[0], sector[1]);
302 Float_t lightQ = zdcHit->GetLightPMQ();
303 Float_t lightC = zdcHit->GetLightPMC();
305 if(sector[0] == 1) { //ZN
307 pmQZN[sector[1]-1] += lightQ;
308 } else if(sector[0] == 2) { //ZP
310 pmQZP[sector[1]-1] += lightQ;
311 } else if(sector[0] == 3) { //ZEM
312 if(sector[1] == 1) pmZEM1 += lightC;
313 else pmZEM2 += lightQ;
318 // create the output tree
319 fLoader->MakeTree("S");
320 TTree* treeS = fLoader->TreeS();
321 const Int_t kBufferSize = 4000;
322 treeS->Branch(GetName(), "AliZDCSDigit", &psdigit, kBufferSize);
324 // Create sdigits for ZN1
325 sector[0] = 1; // Detector = ZN1
326 sector[1] = 0; // Common PM ADC
327 new(psdigit) AliZDCSDigit(sector, pmCZN);
328 if(pmCZN > 0) treeS->Fill();
329 for(Int_t j = 0; j < 4; j++) {
330 sector[1] = j+1; // Towers PM ADCs
331 new(psdigit) AliZDCSDigit(sector, pmQZN[j]);
332 if(pmQZN[j] > 0) treeS->Fill();
335 // Create sdigits for ZP1
336 sector[0] = 2; // Detector = ZP1
337 sector[1] = 0; // Common PM ADC
338 new(psdigit) AliZDCSDigit(sector, pmCZP);
339 if(pmCZP > 0) treeS->Fill();
340 for(Int_t j = 0; j < 4; j++) {
341 sector[1] = j+1; // Towers PM ADCs
342 new(psdigit) AliZDCSDigit(sector, pmQZP[j]);
343 if(pmQZP[j] > 0) treeS->Fill();
346 // Create sdigits for ZEM
348 sector[1] = 1; // Detector = ZEM1
349 new(psdigit) AliZDCSDigit(sector, pmZEM1);
350 if(pmZEM1 > 0) treeS->Fill();
351 sector[1] = 2; // Detector = ZEM2
352 new(psdigit) AliZDCSDigit(sector, pmZEM2);
353 if(pmZEM2 > 0) treeS->Fill();
355 // write the output tree
356 fLoader->WriteSDigits("OVERWRITE");
359 fLoader->UnloadHits();
360 fLoader->UnloadSDigits();
363 //_____________________________________________________________________________
364 AliDigitizer* AliZDC::CreateDigitizer(AliRunDigitizer* manager) const
366 // Create the digitizer for ZDC
368 return new AliZDCDigitizer(manager);
371 //_____________________________________________________________________________
372 void AliZDC::Digits2Raw()
374 // Convert ZDC digits to raw data
376 // Format: 24 int values -> ZN1(C+Q1-4), ZP1(C+Q1-4), ZEM1, ZEM2, ZN(C+Q1-4), ZP2(C+Q1-4), 2 Ref PMs
377 // + 24 int values for the corresponding out of time channels
378 // For the CAEN module V965 we have an Header, the Data Words and an End Of Block
379 // 12 channels x 2 gain chains read from 1st ADC module
380 // 12 channels x 2 gain chains read from 2nd ADC module
381 // 12 channels x 2 gain chains read from 3rd ADC module (o.o.t.)
382 // 12 channels x 2 gain chains read from 4rth ADC module (o.o.t.)
384 const int knADCData1=24, knADCData2=24; // In principle the 2 numbers can be different!
387 UInt_t lADCData1[knADCData1];
388 UInt_t lADCData2[knADCData2];
389 UInt_t lADCData3[knADCData1];
390 UInt_t lADCData4[knADCData2];
395 fLoader->LoadDigits("read");
397 AliZDCDigit* pdigit = &digit;
398 TTree* treeD = fLoader->TreeD();
400 treeD->SetBranchAddress("ZDC", &pdigit);
401 //printf("\t AliZDC::Digits2Raw -> TreeD has %d entries\n",(Int_t) treeD->GetEntries());
405 UInt_t lADCHeaderGEO = 0;
406 UInt_t lADCHeaderCRATE = 0;
407 UInt_t lADCHeaderCNT1 = knADCData1;
408 UInt_t lADCHeaderCNT2 = knADCData2;
410 lADCHeader1 = lADCHeaderGEO << 27 | 0x1 << 25 | lADCHeaderCRATE << 16 |
411 lADCHeaderCNT1 << 8 ;
412 lADCHeader2 = lADCHeaderGEO << 27 | 0x1 << 25 | lADCHeaderCRATE << 16 |
413 lADCHeaderCNT2 << 8 ;
416 UInt_t lADCDataGEO = lADCHeaderGEO;
418 UInt_t lADCDataValue1[knADCData1];
419 UInt_t lADCDataValue2[knADCData2];
420 UInt_t lADCDataValue3[knADCData1];
421 UInt_t lADCDataValue4[knADCData2];
423 UInt_t lADCDataOvFlw1[knADCData1];
424 UInt_t lADCDataOvFlw2[knADCData2];
425 UInt_t lADCDataOvFlw3[knADCData1];
426 UInt_t lADCDataOvFlw4[knADCData2];
428 for(Int_t i=0; i<knADCData1 ; i++){
429 lADCDataValue1[i] = 0;
430 lADCDataOvFlw1[i] = 0;
431 lADCDataValue3[i] = 0;
432 lADCDataOvFlw3[i] = 0;
434 for(Int_t i=0; i<knADCData2 ; i++){
435 lADCDataValue2[i] = 0;
436 lADCDataOvFlw2[i] = 0;
437 lADCDataValue4[i] = 0;
438 lADCDataOvFlw4[i] = 0;
441 UInt_t lADCDataChannel = 0;
444 for(Int_t iDigit=0; iDigit<treeD->GetEntries(); iDigit++){
445 treeD->GetEntry(iDigit);
446 if(!pdigit) continue;
451 if(digit.GetSector(1)!=5){ // ZDC signal channels
452 // *** ADC1 (ZN1, ZP1, ZEM1,2) or ADC3 (ZN1, ZP1, ZEM1,2 o.o.t.)
453 if(digit.GetSector(0)==1 || digit.GetSector(0)==2 || digit.GetSector(0)==3){
454 if(digit.GetSector(0)==1 || digit.GetSector(0)==2){
455 index = (digit.GetSector(0)-1) + 4*digit.GetSector(1); // ZN1 or ZP1
456 lADCDataChannel = 8*(digit.GetSector(0)-1) + digit.GetSector(1);
458 else if(digit.GetSector(0)==3){ // ZEM 1,2
459 index = 20 + (digit.GetSector(1)-1);
460 lADCDataChannel = 5 + 8*(digit.GetSector(1)-1);
463 /*printf("\t AliZDC::Digits2Raw -> idig%d det %d quad %d index %d, ADCch %d ADCVal[%d, %d]\n",
464 iDigit,digit.GetSector(0),digit.GetSector(1),index,lADCDataChannel,
465 digit.GetADCValue(0),digit.GetADCValue(1));// Ch. debug
468 if(iDigit<knADCData1){ // *** In-time signals
469 lADCDataValue1[index] = digit.GetADCValue(0); // High gain ADC ch.
470 if(lADCDataValue1[index] > 2047) lADCDataOvFlw1[index] = 1;
471 lADCDataValue1[index+2] = digit.GetADCValue(1); // Low gain ADC ch.
472 if(lADCDataValue1[index+2] > 2047) lADCDataOvFlw1[index+2] = 1;
474 lADCData1[index] = lADCDataGEO << 27 | 0x1 << 24 | lADCDataChannel << 17 |
475 lADCDataOvFlw1[index] << 12 | (lADCDataValue1[index] & 0xfff);
476 lADCData1[index+2] = lADCDataGEO << 27 | 0x1 << 24 | lADCDataChannel << 17 | 0x1 << 16 |
477 lADCDataOvFlw1[index+2] << 12 | (lADCDataValue1[index+2] & 0xfff);
479 else{ // *** Out-of-time signals
480 lADCDataValue3[index] = digit.GetADCValue(0); // High gain ADC ch.
481 if(lADCDataValue3[index] > 2047) lADCDataOvFlw3[index] = 1;
482 lADCDataValue3[index+2] = digit.GetADCValue(1); // Low gain ADC ch.
483 if(lADCDataValue3[index+2] > 2047) lADCDataOvFlw3[index+2] = 1;
485 lADCData3[index] = lADCDataGEO << 27 | lADCDataChannel << 17 |
486 lADCDataOvFlw3[index] << 12 | (lADCDataValue3[index] & 0xfff);
487 lADCData3[index+2] = lADCDataGEO << 27 | lADCDataChannel << 17 | 0x1 << 16 |
488 lADCDataOvFlw3[index+2] << 12 | (lADCDataValue3[index+2] & 0xfff);
491 // *** ADC2 (ZN2, ZP2) or ADC4 (ZN2, ZP2 o.o.t.)
492 else if(digit.GetSector(0)==4 || digit.GetSector(0)==5){
493 index = (digit.GetSector(0)-4) + 4*digit.GetSector(1); // ZN2 or ZP2
494 lADCDataChannel = 8*(digit.GetSector(0)-4) + digit.GetSector(1);
496 /*printf("\t AliZDC::Digits2Raw -> idig%d det %d quad %d index %d, ADCch %d ADCVal[%d, %d]\n",
497 iDigit,digit.GetSector(0),digit.GetSector(1),index,lADCDataChannel,
498 digit.GetADCValue(0),digit.GetADCValue(1));// Ch. debug
501 if(iDigit<knADCData2){ // *** In-time signals
502 lADCDataValue2[index] = digit.GetADCValue(0);
503 if(lADCDataValue2[index] > 2047) lADCDataOvFlw2[index] = 1;
504 lADCDataValue2[index+2] = digit.GetADCValue(1);
505 if(lADCDataValue2[index+2] > 2047) lADCDataOvFlw2[index+2] = 1;
507 lADCData2[index] = lADCDataGEO << 27 | lADCDataChannel << 17 |
508 lADCDataOvFlw2[index] << 12 | (lADCDataValue2[index] & 0xfff);
509 lADCData2[index+2] = lADCDataGEO << 27 | lADCDataChannel << 17 | 0x1 << 16 |
510 lADCDataOvFlw2[index+2] << 12 | (lADCDataValue2[index+2] & 0xfff);
512 else{ // *** Out-of-time signals
513 lADCDataValue4[index] = digit.GetADCValue(0);
514 if(lADCDataValue4[index] > 2047) lADCDataOvFlw4[index] = 1;
515 lADCDataValue4[index+2] = digit.GetADCValue(1);
516 if(lADCDataValue4[index+2] > 2047) lADCDataOvFlw4[index+2] = 1;
518 lADCData4[index] = lADCDataGEO << 27 | lADCDataChannel << 17 |
519 lADCDataOvFlw4[index] << 12 | (lADCDataValue4[index] & 0xfff);
520 lADCData4[index+2] = lADCDataGEO << 27 | lADCDataChannel << 17 | 0x1 << 16 |
521 lADCDataOvFlw4[index+2] << 12 | (lADCDataValue4[index+2] & 0xfff);
525 // *** ADC2 (Reference PTMs) or ADC4 (Reference PTMs o.o.t.)
526 else if(digit.GetSector(1)==5){
527 index = 20 + (digit.GetSector(0)-1)*1/3;
528 lADCDataChannel = 5 + (digit.GetSector(0)-1)*8/3;
530 /*printf("\t AliZDC::Digits2Raw -> idig%d det %d quad %d index %d, ADCch %d ADCVal[%d, %d]\n",
531 iDigit,digit.GetSector(0),digit.GetSector(1),index,lADCDataChannel,
532 digit.GetADCValue(0),digit.GetADCValue(1));// Ch. debug
535 if(iDigit<knADCData2){ // *** In-time signals
536 lADCDataValue2[index] = digit.GetADCValue(0);
537 if(lADCDataValue2[index] > 2047) lADCDataOvFlw2[index] = 1;
538 lADCDataValue2[index+2] = digit.GetADCValue(1);
539 if(lADCDataValue2[index+2] > 2047) lADCDataOvFlw2[index+2] = 1;
541 lADCData2[index] = lADCDataGEO << 27 | lADCDataChannel << 17 |
542 lADCDataOvFlw2[index] << 12 | (lADCDataValue2[index] & 0xfff);
543 lADCData2[index+2] = lADCDataGEO << 27 | lADCDataChannel << 17 | 0x1 << 16 |
544 lADCDataOvFlw2[index+2] << 12 | (lADCDataValue2[index+2] & 0xfff);
546 else{ // *** Out-of-time signals
547 lADCDataValue4[index] = digit.GetADCValue(0);
548 if(lADCDataValue4[index] > 2047) lADCDataOvFlw4[index] = 1;
549 lADCDataValue4[index+2] = digit.GetADCValue(1);
550 if(lADCDataValue4[index+2] > 2047) lADCDataOvFlw4[index+2] = 1;
552 lADCData4[index] = lADCDataGEO << 27 | lADCDataChannel << 17 |
553 lADCDataOvFlw4[index] << 12 | (lADCDataValue4[index] & 0xfff);
554 lADCData4[index+2] = lADCDataGEO << 27 | lADCDataChannel << 17 | 0x1 << 16 |
555 lADCDataOvFlw4[index+2] << 12 | (lADCDataValue4[index+2] & 0xfff);
559 if((index<0) || (index>23)) {
560 Error("Digits2Raw", "sector[0] = %d, sector[1] = %d",
561 digit.GetSector(0), digit.GetSector(1));
569 for(Int_t i=0;i<24;i++) printf("\t ADCData1[%d] = %x\n",i,lADCData1[i]);
570 for(Int_t i=0;i<20;i++) printf("\t ADCData2[%d] = %x\n",i,lADCData2[i]);
571 for(Int_t i=0;i<24;i++) printf("\t ADCData3[%d] = %x\n",i,lADCData3[i]);
572 for(Int_t i=0;i<20;i++) printf("\t ADCData4[%d] = %x\n",i,lADCData4[i]);
576 UInt_t lADCEndBlockGEO = lADCHeaderGEO;
577 UInt_t lADCEndBlockEvCount = gAlice->GetEventNrInRun();
579 lADCEndBlock = lADCEndBlockGEO << 27 | 0x1 << 26 | lADCEndBlockEvCount;
580 //printf("\t AliZDC::Digits2Raw -> ADCEndBlock = %d\n",lADCEndBlock);
583 // open the output file
585 strcpy(fileName,AliDAQ::DdlFileName("ZDC",0));
587 AliFstream* file = new AliFstream(fileName);
589 // write the DDL data header
590 AliRawDataHeader header;
591 header.fSize = sizeof(header) +
592 sizeof(lADCHeader1) + sizeof(lADCData1) + sizeof(lADCEndBlock) +
593 sizeof(lADCHeader2) + sizeof(lADCData2) + sizeof(lADCEndBlock) +
594 sizeof(lADCHeader1) + sizeof(lADCData3) + sizeof(lADCEndBlock) +
595 sizeof(lADCHeader2) + sizeof(lADCData4) + sizeof(lADCEndBlock);
597 /*printf("sizeof header = %d, ADCHeader1 = %d, ADCData1 = %d, ADCEndBlock = %d\n",
598 sizeof(header),sizeof(lADCHeader1),sizeof(lADCData1),sizeof(lADCEndBlock));
599 printf("sizeof header = %d, ADCHeader2 = %d, ADCData2 = %d, ADCEndBlock = %d\n",
600 sizeof(header),sizeof(lADCHeader2),sizeof(lADCData2),sizeof(lADCEndBlock));
603 header.SetAttribute(0); // valid data
604 file->WriteBuffer((char*)(&header), sizeof(header));
606 // write the raw data and close the file
607 file->WriteBuffer((char*) &lADCHeader1, sizeof (lADCHeader1));
608 file->WriteBuffer((char*)(lADCData1), sizeof(lADCData1));
609 file->WriteBuffer((char*) &lADCEndBlock, sizeof(lADCEndBlock));
610 file->WriteBuffer((char*) &lADCHeader2, sizeof (lADCHeader2));
611 file->WriteBuffer((char*)(lADCData2), sizeof(lADCData2));
612 file->WriteBuffer((char*) &lADCEndBlock, sizeof(lADCEndBlock));
613 file->WriteBuffer((char*) &lADCHeader1, sizeof (lADCHeader1));
614 file->WriteBuffer((char*)(lADCData3), sizeof(lADCData3));
615 file->WriteBuffer((char*) &lADCEndBlock, sizeof(lADCEndBlock));
616 file->WriteBuffer((char*) &lADCHeader2, sizeof (lADCHeader2));
617 file->WriteBuffer((char*)(lADCData4), sizeof(lADCData4));
618 file->WriteBuffer((char*) &lADCEndBlock, sizeof(lADCEndBlock));
622 fLoader->UnloadDigits();
625 //_____________________________________________________________________________
626 Bool_t AliZDC::Raw2SDigits(AliRawReader* rawReader)
628 // Convert ZDC raw data to Sdigits
630 AliLoader* loader = (gAlice->GetRunLoader())->GetLoader("ZDCLoader");
632 AliError("no ZDC loader found");
638 while(rawReader->NextEvent()){
639 (gAlice->GetRunLoader())->GetEvent(iEvent++);
640 // Create the output digit tree
641 TTree* treeS = loader->TreeS();
643 loader->MakeTree("S");
644 treeS = loader->TreeS();
648 AliZDCSDigit* psdigit = &sdigit;
649 const Int_t kBufferSize = 4000;
650 treeS->Branch("ZDC", "AliZDCSDigit", &psdigit, kBufferSize);
652 AliZDCRawStream rawStream(rawReader);
653 Int_t sector[2], resADC, rawADC, corrADC, nPheVal;
655 while(rawStream.Next()){
656 if(rawStream.IsADCDataWord()){
657 //For the moment only in-time SDigits are foreseen (1st 48 raw values)
659 for(Int_t j=0; j<2; j++) sector[j] = rawStream.GetSector(j);
660 rawADC = rawStream.GetADCValue();
661 resADC = rawStream.GetADCGain();
662 //printf("\t RAw2SDigits raw%d -> RawADC[%d, %d, %d] read\n",
663 // jcount, sector[0], sector[1], rawADC);
665 corrADC = rawADC - Pedestal(sector[0], sector[1], resADC);
666 if(corrADC<0) corrADC=0;
667 nPheVal = ADCch2Phe(sector[0], sector[1], corrADC, resADC);
669 //printf("\t \t -> SDigit[%d, %d, %d] created\n",
670 // sector[0], sector[1], nPheVal);
672 new(psdigit) AliZDCSDigit(sector, (Float_t) nPheVal);
678 // write the output tree
679 fLoader->WriteSDigits("OVERWRITE");
680 fLoader->UnloadSDigits();
686 //_____________________________________________________________________________
687 Int_t AliZDC::Pedestal(Int_t Det, Int_t Quad, Int_t Res) const
689 // Returns a pedestal for detector det, PM quad, channel with res.
691 // Getting calibration object for ZDC set
692 AliCDBManager *man = AliCDBManager::Instance();
693 AliCDBEntry *entry = man->Get("ZDC/Calib/Data");
694 AliZDCCalibData *calibData = (AliZDCCalibData*) entry->GetObject();
697 printf("\t No calibration object found for ZDC!");
702 Float_t meanPed, pedWidth;
705 if(Det==1 || Det==2) index = 10*(Det-1)+Quad+5*Res; // ZN1, ZP1
706 else if(Det==3) index = 10*(Det-1)+(Quad-1)+Res; // ZEM
707 else if(Det==4 || Det==5) index = 10*(Det-2)+Quad+5*Res+4; // ZN2, ZP2
709 else index = 10*(Quad-1)+(Det-1)*1/3+2*Res+4; // Reference PMs
712 meanPed = calibData->GetMeanPed(index);
713 pedWidth = calibData->GetMeanPedWidth(index);
714 pedValue = gRandom->Gaus(meanPed,pedWidth);
716 //printf("\t AliZDC::Pedestal - det(%d, %d) - Ped[%d] = %d\n",Det, Quad, index,(Int_t) pedValue); // Chiara debugging!
720 return (Int_t) pedValue;
724 //_____________________________________________________________________________
725 Int_t AliZDC::ADCch2Phe(Int_t Det, Int_t Quad, Int_t ADCVal, Int_t Res) const
727 // Evaluation of the no. of phe produced
728 Float_t pmGain[6][5];
730 for(Int_t j = 0; j < 5; j++){
731 pmGain[0][j] = 50000.;
732 pmGain[1][j] = 100000.;
733 pmGain[2][j] = 100000.;
734 pmGain[3][j] = 50000.;
735 pmGain[4][j] = 100000.;
736 pmGain[5][j] = 100000.;
739 resADC[0] = 0.0000008; // ADC Resolution high gain: 200 fC/adcCh
740 resADC[1] = 0.0000064; // ADC Resolution low gain: 25 fC/adcCh
742 Int_t nPhe = (Int_t) (ADCVal * pmGain[Det-1][Quad] * resADC[Res]);
744 //printf("\t AliZDC::ADCch2Phe -> det(%d, %d) - ADC %d phe %d\n",Det,Quad,ADCVal,nPhe);
749 //______________________________________________________________________
750 void AliZDC::SetTreeAddress(){
752 // Set branch address for the Trees.
753 if(fLoader->TreeH() && (fHits == 0x0))
754 fHits = new TClonesArray("AliZDCHit",1000);
756 AliDetector::SetTreeAddress();
759 //________________________________________________________________
760 void AliZDC::CreateCalibData()
763 //if(fCalibData) delete fCalibData; // delete previous version
764 fCalibData = new AliZDCCalibData(GetName());
766 //________________________________________________________________
767 void AliZDC::WriteCalibData(Int_t option)
770 const int kCompressLevel = 9;
771 char* fnam = GetZDCCalibFName();
772 if(!fnam || fnam[0]=='\0') {
773 fnam = gSystem->ExpandPathName("$(ALICE_ROOT)/data/AliZDCCalib.root");
774 Warning("WriteCalibData","No File Name is provided, using default %s",fnam);
776 TFile* cdfile = TFile::Open(fnam,"UPDATE","",kCompressLevel);
778 // Writes Calibration Data to current directory.
779 // User MUST take care of corresponding file opening and ->cd()... !!!
780 // By default, the object is overwritten. Use 0 option for opposite.
781 if(option) option = TObject::kOverwrite;
782 if(fCalibData) fCalibData->Write(0,option);
783 else if(fCalibData) fCalibData->Write(0,option);
789 //________________________________________________________________
790 void AliZDC::LoadCalibData()
793 char* fnam = GetZDCCalibFName();
794 if(!fnam || fnam[0]=='\0') return;
795 if(!gAlice->IsFileAccessible(fnam)) {
796 Error("LoadCalibData","ZDC Calibration Data file is not accessible, %s",fnam);
799 TFile* cdfile = TFile::Open(fnam);
801 // Loads Calibration Data from current directory.
802 // User MUST take care of corresponding file opening and ->cd()...!!!
804 if(fCalibData) delete fCalibData; // delete previous version
805 TString dtname = "Calib_";
807 fCalibData = (AliZDCCalibData*) gDirectory->Get(dtname.Data());
809 Error("LoadCalibData","No Calibration data found for %s",GetName());