]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ZDC/AliZDC.cxx
Updated to display cosmic runs (L. Molnar)
[u/mrichter/AliRoot.git] / ZDC / AliZDC.cxx
CommitLineData
4c039060 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
88cb7938 16/* $Id$ */
4c039060 17
fe4da5cc 18///////////////////////////////////////////////////////////////////////////////
19// //
359cdddc 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 //
fe4da5cc 24// //
fe4da5cc 25///////////////////////////////////////////////////////////////////////////////
26
f901045b 27// --- ROOT system
fe4da5cc 28#include <TBRIK.h>
7ca4655f 29#include <TClonesArray.h>
88cb7938 30#include <TGeometry.h>
31#include <TNode.h>
32#include <TTree.h>
232b622f 33#include <TFile.h>
8af17dba 34#include <TSystem.h>
90001c80 35#include <TRandom.h>
fe4da5cc 36
f901045b 37// --- AliRoot header files
88cb7938 38#include "AliDetector.h"
90001c80 39#include "AliRawDataHeader.h"
40#include "AliRawReader.h"
41#include "AliLoader.h"
42#include "AliRun.h"
43#include "AliMC.h"
44#include "AliLog.h"
45#include "AliDAQ.h"
fe4da5cc 46#include "AliZDC.h"
f901045b 47#include "AliZDCHit.h"
6de91202 48#include "AliZDCSDigit.h"
49#include "AliZDCDigit.h"
50#include "AliZDCDigitizer.h"
51#include "AliZDCRawStream.h"
8af17dba 52#include "AliZDCCalibData.h"
88cb7938 53
fe4da5cc 54
55ClassImp(AliZDC)
8af17dba 56
8a2624cc 57AliZDC *gAliZDC;
fe4da5cc 58
59//_____________________________________________________________________________
cc2abffd 60AliZDC::AliZDC() :
61 AliDetector(),
62 fNoShower (0),
63 fCalibData (0)
64
fe4da5cc 65{
66 //
67 // Default constructor for the Zero Degree Calorimeter base class
68 //
2e6fc82a 69
cc2abffd 70 fIshunt = 1;
71 fNhits = 0;
72 fHits = 0;
73 fDigits = 0;
74 fNdigits = 0;
d16dd065 75
fe4da5cc 76}
77
78//_____________________________________________________________________________
cc2abffd 79AliZDC::AliZDC(const char *name, const char *title) :
80 AliDetector(name,title),
81 fNoShower (0),
82 fCalibData (0)
83
fe4da5cc 84{
85 //
86 // Standard constructor for the Zero Degree Calorimeter base class
87 //
cc2abffd 88
89 fIshunt = 1;
90 fNhits = 0;
91 fDigits = 0;
92 fNdigits = 0;
93
94 fHits = new TClonesArray("AliZDCHit",1000);
5d12ce38 95 gAlice->GetMCApp()->AddHitList(fHits);
8af17dba 96
97 char sensname[5],senstitle[25];
98 sprintf(sensname,"ZDC");
99 sprintf(senstitle,"ZDC dummy");
100 SetName(sensname); SetTitle(senstitle);
f901045b 101
cc2abffd 102 gAliZDC = this;
866ab5a2 103
104}
cc2abffd 105
866ab5a2 106//____________________________________________________________________________
107AliZDC::~AliZDC()
108{
109 //
110 // ZDC destructor
111 //
112
cc2abffd 113 fIshunt = 0;
114 gAliZDC = 0;
2e6fc82a 115
d16dd065 116 delete fCalibData;
117
fe4da5cc 118}
cc2abffd 119
120//_____________________________________________________________________________
121AliZDC::AliZDC(const AliZDC& ZDC) :
122 AliDetector("ZDC","ZDC")
123{
124 // copy constructor
125 fNoShower = ZDC.fNoShower;
126 fCalibData = ZDC.fCalibData;
127 fZDCCalibFName = ZDC.fZDCCalibFName;
128}
129
130//_____________________________________________________________________________
131AliZDC& AliZDC::operator=(const AliZDC& ZDC)
132{
133 // assignement operator
134 if(this!=&ZDC){
135 fNoShower = ZDC.fNoShower;
136 fCalibData = ZDC.fCalibData;
137 fZDCCalibFName = ZDC.fZDCCalibFName;
138 } return *this;
139}
140
fe4da5cc 141//_____________________________________________________________________________
142void AliZDC::AddHit(Int_t track, Int_t *vol, Float_t *hits)
143{
144 //
f901045b 145 // Add a ZDC hit to the hit list.
146 // -> We make use of 2 array of hits:
147 // [1] fHits (the usual one) that contains hits for each PRIMARY
148 // [2] fStHits that contains hits for each EVENT and is used to
149 // obtain digits at the end of each event
fe4da5cc 150 //
f901045b 151
68ca986e 152 static Float_t primKinEn, xImpact, yImpact, sFlag;
153
43f34e8b 154 AliZDCHit *newquad, *curprimquad;
f901045b 155 newquad = new AliZDCHit(fIshunt, track, vol, hits);
65d4f2be 156 TClonesArray &lhits = *fHits;
cefa66cb 157
158 if(fNhits==0){
159 // First hit -> setting flag for primary or secondary particle
5d12ce38 160 Int_t primary = gAlice->GetMCApp()->GetPrimary(track);
cefa66cb 161 if(track != primary){
3ff116f2 162 newquad->SetSFlag(1); // SECONDARY particle entering the ZDC
cefa66cb 163 }
164 else if(track == primary){
3ff116f2 165 newquad->SetSFlag(0); // PRIMARY particle entering the ZDC
cefa66cb 166 }
3ff116f2 167 sFlag = newquad->GetSFlag();
168 primKinEn = newquad->GetPrimKinEn();
169 xImpact = newquad->GetXImpact();
170 yImpact = newquad->GetYImpact();
cefa66cb 171 }
172 else{
3ff116f2 173 newquad->SetPrimKinEn(primKinEn);
174 newquad->SetXImpact(xImpact);
175 newquad->SetYImpact(yImpact);
176 newquad->SetSFlag(sFlag);
cefa66cb 177 }
178
43f34e8b 179 Int_t j;
f901045b 180 for(j=0; j<fNhits; j++){
2e6fc82a 181 // If hits are equal (same track, same volume), sum them.
f901045b 182 curprimquad = (AliZDCHit*) lhits[j];
183 if(*curprimquad == *newquad){
184 *curprimquad = *curprimquad+*newquad;
cc2abffd 185 // CH. debug
186 /*if(newquad->GetEnergy() != 0. || newquad->GetLightPMC() != 0. ||
187 newquad->GetLightPMQ() != 0.){
188 printf("\n\t --- Equal hits found\n");
189 curprimquad->Print("");
190 newquad->Print("");
191 printf("\t --- Det. %d, Quad. %d: X = %f, E = %f, LightPMC = %f, LightPMQ = %f\n",
192 curprimquad->GetVolume(0),curprimquad->GetVolume(1),curprimquad->GetXImpact(),
193 curprimquad->GetEnergy(), curprimquad->GetLightPMC(), curprimquad->GetLightPMQ());
194 }*/
195 //
f901045b 196 delete newquad;
68ca986e 197 return;
f901045b 198 }
199 }
f901045b 200
201 //Otherwise create a new hit
cc2abffd 202 new(lhits[fNhits]) AliZDCHit(*newquad);
f901045b 203 fNhits++;
cc2abffd 204 // CH. debug
205 /*printf("\n\t New ZDC hit added! fNhits = %d\n", fNhits);
206 printf("\t Det. %d, Quad.t %d: X = %f, E = %f, LightPMC = %f, LightPMQ = %f\n",
207 newquad->GetVolume(0),newquad->GetVolume(1),newquad->GetXImpact(),
208 newquad->GetEnergy(), newquad->GetLightPMC(), newquad->GetLightPMQ());
209 */
866ab5a2 210 delete newquad;
cefa66cb 211}
212
fe4da5cc 213//_____________________________________________________________________________
214void AliZDC::BuildGeometry()
215{
216 //
217 // Build the ROOT TNode geometry for event display
218 // in the Zero Degree Calorimeter
219 // This routine is dummy for the moment
220 //
221
68ca986e 222 TNode *node, *top;
223 TBRIK *brik;
359cdddc 224 const int kColorZDC = kBlue;
fe4da5cc 225
226 //
68ca986e 227 top=gAlice->GetGeometry()->GetNode("alice");
fe4da5cc 228
229 // ZDC
fe4da5cc 230 brik = new TBRIK("S_ZDC","ZDC box","void",300,300,5);
68ca986e 231 top->cd();
232 node = new TNode("ZDC","ZDC","S_ZDC",0,0,600,"");
233 node->SetLineColor(kColorZDC);
234 fNodes->Add(node);
fe4da5cc 235}
236
359cdddc 237//____________________________________________________________________________
238Float_t AliZDC::ZMin(void) const
239{
240 // Minimum dimension of the ZDC module in z
6de91202 241 return -11600.;
359cdddc 242}
243
244//____________________________________________________________________________
245Float_t AliZDC::ZMax(void) const
246{
247 // Maximum dimension of the ZDC module in z
6de91202 248 return -11750.;
359cdddc 249}
250
251
fe4da5cc 252//_____________________________________________________________________________
5bc762ca 253void AliZDC::MakeBranch(Option_t *opt)
fe4da5cc 254{
255 //
359cdddc 256 // Create Tree branches for the ZDC
fe4da5cc 257 //
359cdddc 258
259 char branchname[10];
260 sprintf(branchname,"%s",GetName());
88cb7938 261
262 const char *cH = strstr(opt,"H");
263
90001c80 264 if(cH && fLoader->TreeH())
88cb7938 265 fHits = new TClonesArray("AliZDCHit",1000);
359cdddc 266
267 AliDetector::MakeBranch(opt);
1450a7cd 268}
1450a7cd 269
b6d27557 270//_____________________________________________________________________________
271void AliZDC::Hits2SDigits()
272{
6de91202 273 // Create summable digits from hits
274
99a553ce 275 AliDebug(1,"\n Entering AliZDC::Hits2Digits() ");
b6d27557 276
85a5290f 277 fLoader->LoadHits("read");
278 fLoader->LoadSDigits("recreate");
6de91202 279 AliRunLoader* runLoader = fLoader->GetRunLoader();
280 AliZDCSDigit sdigit;
281 AliZDCSDigit* psdigit = &sdigit;
85a5290f 282
6de91202 283 // Event loop
90001c80 284 for(Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
6de91202 285 Float_t pmCZN = 0, pmCZP = 0, pmQZN[4], pmQZP[4], pmZEM1 = 0, pmZEM2 = 0;
90001c80 286 for(Int_t i = 0; i < 4; i++) pmQZN[i] = pmQZP[i] = 0;
85a5290f 287
6de91202 288 runLoader->GetEvent(iEvent);
289 TTree* treeH = fLoader->TreeH();
359cdddc 290 Int_t ntracks = (Int_t) treeH->GetEntries();
6de91202 291 ResetHits();
292
359cdddc 293 // Tracks loop
6de91202 294 Int_t sector[2];
90001c80 295 for(Int_t itrack = 0; itrack < ntracks; itrack++) {
6de91202 296 treeH->GetEntry(itrack);
90001c80 297 for(AliZDCHit* zdcHit = (AliZDCHit*)FirstHit(-1); zdcHit;
6de91202 298 zdcHit = (AliZDCHit*)NextHit()) {
b6d27557 299
6de91202 300 sector[0] = zdcHit->GetVolume(0);
301 sector[1] = zdcHit->GetVolume(1);
90001c80 302 if((sector[1] < 1) || (sector[1] > 4)) {
6de91202 303 Error("Hits2SDigits", "sector[0] = %d, sector[1] = %d",
304 sector[0], sector[1]);
305 continue;
306 }
307 Float_t lightQ = zdcHit->GetLightPMQ();
308 Float_t lightC = zdcHit->GetLightPMC();
309
90001c80 310 if(sector[0] == 1) { //ZN
6de91202 311 pmCZN += lightC;
312 pmQZN[sector[1]-1] += lightQ;
90001c80 313 } else if(sector[0] == 2) { //ZP
6de91202 314 pmCZP += lightC;
315 pmQZP[sector[1]-1] += lightQ;
90001c80 316 } else if(sector[0] == 3) { //ZEM
317 if(sector[1] == 1) pmZEM1 += lightC;
6de91202 318 else pmZEM2 += lightQ;
319 }
320 }//Hits loop
359cdddc 321 }
6de91202 322
323 // create the output tree
324 fLoader->MakeTree("S");
325 TTree* treeS = fLoader->TreeS();
326 const Int_t kBufferSize = 4000;
327 treeS->Branch(GetName(), "AliZDCSDigit", &psdigit, kBufferSize);
328
90001c80 329 // Create sdigits for ZN1
330 sector[0] = 1; // Detector = ZN1
6de91202 331 sector[1] = 0; // Common PM ADC
332 new(psdigit) AliZDCSDigit(sector, pmCZN);
90001c80 333 if(pmCZN > 0) treeS->Fill();
334 for(Int_t j = 0; j < 4; j++) {
6de91202 335 sector[1] = j+1; // Towers PM ADCs
336 new(psdigit) AliZDCSDigit(sector, pmQZN[j]);
90001c80 337 if(pmQZN[j] > 0) treeS->Fill();
b6d27557 338 }
359cdddc 339
90001c80 340 // Create sdigits for ZP1
341 sector[0] = 2; // Detector = ZP1
6de91202 342 sector[1] = 0; // Common PM ADC
343 new(psdigit) AliZDCSDigit(sector, pmCZP);
90001c80 344 if(pmCZP > 0) treeS->Fill();
345 for(Int_t j = 0; j < 4; j++) {
6de91202 346 sector[1] = j+1; // Towers PM ADCs
347 new(psdigit) AliZDCSDigit(sector, pmQZP[j]);
90001c80 348 if(pmQZP[j] > 0) treeS->Fill();
6de91202 349 }
350
351 // Create sdigits for ZEM
352 sector[0] = 3;
353 sector[1] = 1; // Detector = ZEM1
354 new(psdigit) AliZDCSDigit(sector, pmZEM1);
90001c80 355 if(pmZEM1 > 0) treeS->Fill();
6de91202 356 sector[1] = 2; // Detector = ZEM2
357 new(psdigit) AliZDCSDigit(sector, pmZEM2);
90001c80 358 if(pmZEM2 > 0) treeS->Fill();
6de91202 359
360 // write the output tree
361 fLoader->WriteSDigits("OVERWRITE");
85a5290f 362 }
363
364 fLoader->UnloadHits();
365 fLoader->UnloadSDigits();
359cdddc 366}
367
368//_____________________________________________________________________________
6de91202 369AliDigitizer* AliZDC::CreateDigitizer(AliRunDigitizer* manager) const
359cdddc 370{
6de91202 371 // Create the digitizer for ZDC
372
373 return new AliZDCDigitizer(manager);
359cdddc 374}
375
376//_____________________________________________________________________________
6de91202 377void AliZDC::Digits2Raw()
359cdddc 378{
6de91202 379 // Convert ZDC digits to raw data
380
abf60186 381 // Format: 22 interger values -> ZN1 (C+Q1-4), ZP1 (C+Q1-4), ZEM1, 2, ZN (C+Q1-4), ZP2 (C+Q1-4))
d79f8d50 382 // + 22 interger values for the out of time channels
383 // For the CAEN module V965 we have an Header, the Data Words and an End Of Block
384 // 12 channels x 2 gain chains read from 1st ADC module
385 // 10 channels x 2 gain chains read from 2nd ADC module
386 // 12 channels x 2 gain chains read from 3rd ADC module (o.o.t.)
387 // 10 channels x 2 gain chains read from 4rth ADC module (o.o.t.)
388 //
abf60186 389 const int knADCData1=24, knADCData2=20;
7f73eb6b 390 UInt_t lADCHeader1;
8a2624cc 391 UInt_t lADCData1[knADCData1];
7f73eb6b 392 //
393 UInt_t lADCHeader2;
8a2624cc 394 UInt_t lADCData2[knADCData2];
7f73eb6b 395 //
d79f8d50 396 UInt_t lADCHeader3;
397 UInt_t lADCData3[knADCData1];
398 //
399 UInt_t lADCHeader4;
400 UInt_t lADCData4[knADCData2];
401 //
232b622f 402 UInt_t lADCEndBlock;
6de91202 403
404 // load the digits
405 fLoader->LoadDigits("read");
406 AliZDCDigit digit;
407 AliZDCDigit* pdigit = &digit;
408 TTree* treeD = fLoader->TreeD();
90001c80 409 if(!treeD) return;
6de91202 410 treeD->SetBranchAddress("ZDC", &pdigit);
c7426372 411 //printf("\t AliZDC::Digits2raw -> TreeD has %d entries\n",(Int_t) treeD->GetEntries());
6de91202 412
413 // Fill data array
414 // ADC header
232b622f 415 UInt_t lADCHeaderGEO = 0;
416 UInt_t lADCHeaderCRATE = 0;
8a2624cc 417 UInt_t lADCHeaderCNT1 = knADCData1;
418 UInt_t lADCHeaderCNT2 = knADCData2;
1450a7cd 419
7f73eb6b 420 lADCHeader1 = lADCHeaderGEO << 27 | 0x1 << 25 | lADCHeaderCRATE << 16 |
421 lADCHeaderCNT1 << 8 ;
abf60186 422 //
7f73eb6b 423 lADCHeader2 = lADCHeaderGEO << 27 | 0x1 << 25 | lADCHeaderCRATE << 16 |
424 lADCHeaderCNT2 << 8 ;
d79f8d50 425 //
426 lADCHeader3 = lADCHeaderGEO << 27 | 0x1 << 25 | lADCHeaderCRATE << 16 |
427 lADCHeaderCNT1 << 8 ;
428 //
429 lADCHeader4 = lADCHeaderGEO << 27 | 0x1 << 25 | lADCHeaderCRATE << 16 |
430 lADCHeaderCNT2 << 8 ;
abf60186 431 //printf("\t lADCHeader1 = %x, lADCHeader2 = %x\n",lADCHeader1, lADCHeader2);
6de91202 432
433 // ADC data word
232b622f 434 UInt_t lADCDataGEO = lADCHeaderGEO;
8a2624cc 435 UInt_t lADCDataValue1[knADCData1];
436 UInt_t lADCDataValue2[knADCData2];
d79f8d50 437 UInt_t lADCDataValue3[knADCData1];
438 UInt_t lADCDataValue4[knADCData2];
8a2624cc 439 UInt_t lADCDataOvFlw1[knADCData1];
440 UInt_t lADCDataOvFlw2[knADCData2];
d79f8d50 441 UInt_t lADCDataOvFlw3[knADCData1];
442 UInt_t lADCDataOvFlw4[knADCData2];
443 for(Int_t i=0; i<knADCData1 ; i++){
7f73eb6b 444 lADCDataValue1[i] = 0;
445 lADCDataOvFlw1[i] = 0;
d79f8d50 446 lADCDataValue3[i] = 0;
447 lADCDataOvFlw3[i] = 0;
7f73eb6b 448 }
d79f8d50 449 for(Int_t i=0; i<knADCData2 ; i++){
7f73eb6b 450 lADCDataValue2[i] = 0;
451 lADCDataOvFlw2[i] = 0;
d79f8d50 452 lADCDataValue4[i] = 0;
453 lADCDataOvFlw4[i] = 0;
6de91202 454 }
232b622f 455 UInt_t lADCDataChannel = 0;
6de91202 456
457 // loop over digits
d79f8d50 458 for(Int_t iDigit=0; iDigit<treeD->GetEntries(); iDigit++){
6de91202 459 treeD->GetEntry(iDigit);
d79f8d50 460 if(!pdigit) continue;
a5d5ab4c 461 //digit.Print("");
abf60186 462
d79f8d50 463 // *** ADC data
464 Int_t index1=0, index2=0;
465 // *** ADC1 (ZN1, ZP1, ZEM1,2) o ADC3 (ZN1, ZP1, ZEM1,2 o.o.t.)
7f73eb6b 466 if(digit.GetSector(0)==1 || digit.GetSector(0)==2 || digit.GetSector(0)==3){
467 if(digit.GetSector(0)==1 || digit.GetSector(0)==2){
abf60186 468 index1 = (digit.GetSector(0)-1) + digit.GetSector(1)*4; // ZN1 or ZP1
7f73eb6b 469 lADCDataChannel = (digit.GetSector(0)-1)*8 + digit.GetSector(1);
470 }
abf60186 471 else if(digit.GetSector(0)==3){ // ZEM 1,2
472 index1 = 20 + (digit.GetSector(1)-1);
473 lADCDataChannel = 5 + (digit.GetSector(1)-1)*8;
7f73eb6b 474 }
abf60186 475 //
c7426372 476 /*printf("\t AliZDC::Digits2raw -> det %d, quad %d, index = %d, ADCch = %d\n",
abf60186 477 digit.GetSector(0),digit.GetSector(1),index1,lADCDataChannel);// Ch. debug
c7426372 478 */
abf60186 479 //
d79f8d50 480 if(iDigit<22){
481 lADCDataValue1[index1] = digit.GetADCValue(0); // High gain ADC ch.
482 if(lADCDataValue1[index1] > 2047) lADCDataOvFlw1[index1] = 1;
483 lADCDataValue1[index1+2] = digit.GetADCValue(1); // Low gain ADC ch.
484 if(lADCDataValue1[index1+2] > 2047) lADCDataOvFlw1[index1+2] = 1;
7f73eb6b 485
d79f8d50 486 lADCData1[index1] = lADCDataGEO << 27 | lADCDataChannel << 17 |
7f73eb6b 487 lADCDataOvFlw1[index1] << 12 | (lADCDataValue1[index1] & 0xfff);
d79f8d50 488 lADCData1[index1+2] = lADCDataGEO << 27 | lADCDataChannel << 17 | 0x1 << 16 |
489 lADCDataOvFlw1[index1+2] << 12 | (lADCDataValue1[index1+2] & 0xfff);
490 }
491 else{
492 lADCDataValue3[index1] = digit.GetADCValue(0); // High gain ADC ch.
493 if(lADCDataValue3[index1] > 2047) lADCDataOvFlw3[index1] = 1;
494 lADCDataValue3[index1+2] = digit.GetADCValue(1); // Low gain ADC ch.
495 if(lADCDataValue3[index1+2] > 2047) lADCDataOvFlw3[index1+2] = 1;
496
497 lADCData3[index1] = lADCDataGEO << 27 | lADCDataChannel << 17 |
498 lADCDataOvFlw3[index1] << 12 | (lADCDataValue3[index1] & 0xfff);
499 lADCData3[index1+2] = lADCDataGEO << 27 | lADCDataChannel << 17 | 0x1 << 16 |
500 lADCDataOvFlw3[index1+2] << 12 | (lADCDataValue3[index1+2] & 0xfff);
501 }
6de91202 502 }
d79f8d50 503 // *** ADC2 (ZN2, ZP2) o ADC4 (ZN2, ZP2 o.o.t.)
7f73eb6b 504 else if(digit.GetSector(0)==4 || digit.GetSector(0)==5){
abf60186 505 index2 = (digit.GetSector(0)-4) + digit.GetSector(1)*4; // ZN2 or ZP2
7f73eb6b 506 lADCDataChannel = (digit.GetSector(0)-4)*8 + digit.GetSector(1);
abf60186 507 //
c7426372 508 /*printf("\t AliZDC::Digits2raw -> det %d, quad %d, index = %d, ADCch = %d\n",
abf60186 509 digit.GetSector(0),digit.GetSector(1),index1,lADCDataChannel); // Ch. debug
c7426372 510 */
7f73eb6b 511 //
d79f8d50 512 if(iDigit<22){
513 lADCDataValue2[index2] = digit.GetADCValue(0);
90001c80 514 if(lADCDataValue2[index2] > 2047) lADCDataOvFlw2[index2] = 1;
d79f8d50 515 lADCDataValue2[index2+2] = digit.GetADCValue(1);
90001c80 516 if(lADCDataValue2[index2+2] > 2047) lADCDataOvFlw2[index2+2] = 1;
d79f8d50 517 //
518 lADCData2[index2] = lADCDataGEO << 27 | lADCDataChannel << 17 |
7f73eb6b 519 lADCDataOvFlw2[index2] << 12 | (lADCDataValue2[index2] & 0xfff);
d79f8d50 520 lADCData2[index2+2] = lADCDataGEO << 27 | lADCDataChannel << 17 | 0x1 << 16 |
521 lADCDataOvFlw2[index2+2] << 12 | (lADCDataValue2[index2+2] & 0xfff);
522 }
523 else{
524 lADCDataValue4[index2] = digit.GetADCValue(0);
90001c80 525 if(lADCDataValue4[index2] > 2047) lADCDataOvFlw4[index2] = 1;
d79f8d50 526 lADCDataValue4[index2+2] = digit.GetADCValue(1);
90001c80 527 if(lADCDataValue4[index2+2] > 2047) lADCDataOvFlw4[index2+2] = 1;
d79f8d50 528 //
529 lADCData4[index2] = lADCDataGEO << 27 | lADCDataChannel << 17 |
530 lADCDataOvFlw4[index2] << 12 | (lADCDataValue4[index2] & 0xfff);
531 lADCData4[index2+2] = lADCDataGEO << 27 | lADCDataChannel << 17 | 0x1 << 16 |
532 lADCDataOvFlw4[index2+2] << 12 | (lADCDataValue4[index2+2] & 0xfff);
533 }
7f73eb6b 534 }
abf60186 535 if((index1<0) || (index1>23)) {
7f73eb6b 536 Error("Digits2Raw", "sector[0] = %d, sector[1] = %d",
537 digit.GetSector(0), digit.GetSector(1));
538 continue;
6de91202 539 }
abf60186 540 if((index2<0) || (index2>19)) {
6de91202 541 Error("Digits2Raw", "sector[0] = %d, sector[1] = %d",
542 digit.GetSector(0), digit.GetSector(1));
543 continue;
1450a7cd 544 }
1450a7cd 545
1450a7cd 546
1450a7cd 547 }
c7426372 548 /* for(Int_t i=0;i<24;i++) printf("\t ADCData1[%d] = %x\n",i,lADCData1[i]);
d79f8d50 549 for(Int_t i=0;i<20;i++) printf("\t ADCData2[%d] = %x\n",i,lADCData2[i]);
550 for(Int_t i=0;i<24;i++) printf("\t ADCData3[%d] = %x\n",i,lADCData3[i]);
551 for(Int_t i=0;i<20;i++) printf("\t ADCData4[%d] = %x\n",i,lADCData4[i]);
c7426372 552 */
7f73eb6b 553
6de91202 554 // End of Block
232b622f 555 UInt_t lADCEndBlockGEO = lADCHeaderGEO;
556 UInt_t lADCEndBlockEvCount = gAlice->GetEventNrInRun();
1450a7cd 557
232b622f 558 lADCEndBlock = lADCEndBlockGEO << 27 | 0x1 << 26 | lADCEndBlockEvCount;
1450a7cd 559
c7426372 560 //printf("\t ADCEndBlock = %d\n",lADCEndBlock);
6de91202 561
562
563 // open the output file
564 char fileName[30];
362c9d61 565 strcpy(fileName,AliDAQ::DdlFileName("ZDC",0));
6de91202 566#ifndef __DECCXX
567 ofstream file(fileName, ios::binary);
568#else
569 ofstream file(fileName);
570#endif
571
572 // write the DDL data header
573 AliRawDataHeader header;
d79f8d50 574 header.fSize = sizeof(header) +
575 sizeof(lADCHeader1) + sizeof(lADCData1) + sizeof(lADCEndBlock) +
576 sizeof(lADCHeader2) + sizeof(lADCData2) + sizeof(lADCEndBlock) +
577 sizeof(lADCHeader3) + sizeof(lADCData3) + sizeof(lADCEndBlock) +
578 sizeof(lADCHeader4) + sizeof(lADCData4) + sizeof(lADCEndBlock);
abf60186 579 /*printf("sizeof header = %d, ADCHeader1 = %d, ADCData1 = %d, ADCEndBlock = %d\n",
580 sizeof(header),sizeof(lADCHeader1),sizeof(lADCData1),sizeof(lADCEndBlock));
581 printf("sizeof header = %d, ADCHeader2 = %d, ADCData2 = %d, ADCEndBlock = %d\n",
582 sizeof(header),sizeof(lADCHeader2),sizeof(lADCData2),sizeof(lADCEndBlock));*/
6de91202 583 header.SetAttribute(0); // valid data
584 file.write((char*)(&header), sizeof(header));
585
586 // write the raw data and close the file
7f73eb6b 587 file.write((char*) &lADCHeader1, sizeof (lADCHeader1));
588 file.write((char*)(lADCData1), sizeof(lADCData1));
589 file.write((char*) &lADCEndBlock, sizeof(lADCEndBlock));
590 file.write((char*) &lADCHeader2, sizeof (lADCHeader2));
591 file.write((char*)(lADCData2), sizeof(lADCData2));
232b622f 592 file.write((char*) &lADCEndBlock, sizeof(lADCEndBlock));
d79f8d50 593 file.write((char*) &lADCHeader3, sizeof (lADCHeader3));
594 file.write((char*)(lADCData3), sizeof(lADCData3));
595 file.write((char*) &lADCEndBlock, sizeof(lADCEndBlock));
596 file.write((char*) &lADCHeader4, sizeof (lADCHeader4));
597 file.write((char*)(lADCData4), sizeof(lADCData4));
598 file.write((char*) &lADCEndBlock, sizeof(lADCEndBlock));
6de91202 599 file.close();
600
601 // unload the digits
602 fLoader->UnloadDigits();
359cdddc 603}
604
90001c80 605//_____________________________________________________________________________
606Bool_t AliZDC::Raw2SDigits(AliRawReader* rawReader)
607{
608 // Convert ZDC raw data to Sdigits
609
36f43fdf 610 AliLoader* loader = (gAlice->GetRunLoader())->GetLoader("ZDCLoader");
611 if(!loader) {
612 AliError("no ZDC loader found");
613 return kFALSE;
614 }
615
616// // Event loop
617 Int_t iEvent = 0;
90001c80 618 while(rawReader->NextEvent()){
36f43fdf 619 (gAlice->GetRunLoader())->GetEvent(iEvent++);
90001c80 620 // Create the output digit tree
36f43fdf 621 TTree* treeS = loader->TreeS();
622 if(!treeS){
623 loader->MakeTree("S");
624 treeS = loader->TreeS();
90001c80 625 }
626 //
627 AliZDCSDigit sdigit;
628 AliZDCSDigit* psdigit = &sdigit;
629 const Int_t kBufferSize = 4000;
630 treeS->Branch("ZDC", "AliZDCSDigit", &psdigit, kBufferSize);
631 //
632 AliZDCRawStream rawStream(rawReader);
633 Int_t sector[2], ADCRes, ADCRaw, ADCPedSub, nPheVal;
634 Int_t jcount = 0;
635 while(rawStream.Next()){
636 if(rawStream.IsADCDataWord()){
637 //For the moment only in-time SDigits are foreseen (1st 44 raw values)
36f43fdf 638 if(jcount < 44){
90001c80 639 for(Int_t j=0; j<2; j++) sector[j] = rawStream.GetSector(j);
640 ADCRaw = rawStream.GetADCValue();
641 ADCRes = rawStream.GetADCGain();
36f43fdf 642 //printf("\t RAw2SDigits raw%d -> RawADC[%d, %d, %d] read\n",
643 // jcount, sector[0], sector[1], ADCRaw);
90001c80 644 //
645 ADCPedSub = ADCRaw - Pedestal(sector[0], sector[1], ADCRes);
36f43fdf 646 if(ADCPedSub<0) ADCPedSub=0;
90001c80 647 nPheVal = ADCch2Phe(sector[0], sector[1], ADCPedSub, ADCRes);
36f43fdf 648 //
649 //printf("\t \t -> SDigit[%d, %d, %d] created\n",
650 // sector[0], sector[1], nPheVal);
651 //
90001c80 652 new(psdigit) AliZDCSDigit(sector, (Float_t) nPheVal);
653 treeS->Fill();
36f43fdf 654 jcount++;
90001c80 655 }
90001c80 656 }//IsADCDataWord
657 }//rawStream.Next
658 // write the output tree
659 fLoader->WriteSDigits("OVERWRITE");
660 fLoader->UnloadSDigits();
661 }//Event loop
662
663 return kTRUE;
664}
665
666//_____________________________________________________________________________
667Int_t AliZDC::Pedestal(Int_t Det, Int_t Quad, Int_t Res) const
668{
669 // Returns a pedestal for detector det, PM quad, channel with res.
670 //
36f43fdf 671 // Getting calibration object for ZDC set
672 AliCDBManager *man = AliCDBManager::Instance();
673 man->SetDefaultStorage("local://$ALICE_ROOT");
674 man->SetRun(0);
675 AliCDBEntry *entry = man->Get("ZDC/Calib/Data");
676 AliZDCCalibData *CalibData = (AliZDCCalibData*) entry->GetObject();
677 //
678 if(!CalibData){
679 printf("\t No calibration object found for ZDC!");
680 return -1;
681 }
682 //
90001c80 683 Float_t PedValue;
90001c80 684 Float_t meanPed, Pedwidth;
685 Int_t index=0;
686 if(Det==1|| Det==2) index = 10*(Det-1)+Quad+5*Res; // ZN1, ZP1
687 else if(Det==3) index = 10*(Det-1)+(Quad-1)+Res; // ZEM
688 else if(Det==4|| Det==5) index = 10*(Det-2)+Quad+5*Res+4; // ZN2, ZP2
36f43fdf 689 //
690 //
691 meanPed = CalibData->GetMeanPed(index);
692 Pedwidth = CalibData->GetMeanPedWidth(index);
90001c80 693 PedValue = gRandom->Gaus(meanPed,Pedwidth);
694 //
36f43fdf 695 //printf("\t AliZDC::Pedestal - det(%d, %d) - Ped[%d] = %d\n",Det, Quad, index,(Int_t) PedValue); // Chiara debugging!
696
90001c80 697
698
699 return (Int_t) PedValue;
700}
701
702
703//_____________________________________________________________________________
36f43fdf 704Int_t AliZDC::ADCch2Phe(Int_t Det, Int_t Quad, Int_t ADCVal, Int_t Res) const
90001c80 705{
706 // Evaluation of the no. of phe produced
707 Float_t PMGain[6][5];
708 Float_t ADCRes[2];
709 for(Int_t j = 0; j < 5; j++){
710 PMGain[0][j] = 50000.;
711 PMGain[1][j] = 100000.;
712 PMGain[2][j] = 100000.;
713 PMGain[3][j] = 50000.;
714 PMGain[4][j] = 100000.;
715 PMGain[5][j] = 100000.;
716 }
717 // ADC Caen V965
718 ADCRes[0] = 0.0000008; // ADC Resolution high gain: 200 fC/adcCh
719 ADCRes[1] = 0.0000064; // ADC Resolution low gain: 25 fC/adcCh
720 //
721 Int_t nPhe = (Int_t) (ADCVal * PMGain[Det-1][Quad] * ADCRes[Res]);
36f43fdf 722 //
723 //printf("\t AliZDC::ADCch2Phe -> det(%d, %d) - ADC %d phe %d\n",Det,Quad,ADCVal,nPhe);
90001c80 724
725 return nPhe;
726}
727
b81c9821 728//______________________________________________________________________
729void AliZDC::SetTreeAddress(){
90001c80 730
b81c9821 731 // Set branch address for the Trees.
90001c80 732 if(fLoader->TreeH() && (fHits == 0x0))
b81c9821 733 fHits = new TClonesArray("AliZDCHit",1000);
734
b81c9821 735 AliDetector::SetTreeAddress();
736}
359cdddc 737
8af17dba 738//________________________________________________________________
739void AliZDC::CreateCalibData()
740{
741 //
90001c80 742 //if(fCalibData) delete fCalibData; // delete previous version
8af17dba 743 fCalibData = new AliZDCCalibData(GetName());
744}
745//________________________________________________________________
746void AliZDC::WriteCalibData(Int_t option)
747{
748 //
749 const int kCompressLevel = 9;
4d81e5e7 750 char* fnam = GetZDCCalibFName();
90001c80 751 if(!fnam || fnam[0]=='\0') {
e689b8ea 752 fnam = gSystem->ExpandPathName("$(ALICE_ROOT)/data/AliZDCCalib.root");
8af17dba 753 Warning("WriteCalibData","No File Name is provided, using default %s",fnam);
754 }
755 TFile* cdfile = TFile::Open(fnam,"UPDATE","",kCompressLevel);
756
757 // Writes Calibration Data to current directory.
758 // User MUST take care of corresponding file opening and ->cd()... !!!
759 // By default, the object is overwritten. Use 0 option for opposite.
90001c80 760 if(option) option = TObject::kOverwrite;
761 if(fCalibData) fCalibData->Write(0,option);
762 else if(fCalibData) fCalibData->Write(0,option);
8af17dba 763
764 cdfile->Close();
765 delete cdfile;
766}
767
768//________________________________________________________________
769void AliZDC::LoadCalibData()
770{
771 //
4d81e5e7 772 char* fnam = GetZDCCalibFName();
90001c80 773 if(!fnam || fnam[0]=='\0') return;
774 if(!gAlice->IsFileAccessible(fnam)) {
8af17dba 775 Error("LoadCalibData","ZDC Calibration Data file is not accessible, %s",fnam);
776 exit(1);
777 }
778 TFile* cdfile = TFile::Open(fnam);
779
780 // Loads Calibration Data from current directory.
781 // User MUST take care of corresponding file opening and ->cd()...!!!
782 //
90001c80 783 if(fCalibData) delete fCalibData; // delete previous version
8af17dba 784 TString dtname = "Calib_";
785 dtname += GetName();
786 fCalibData = (AliZDCCalibData*) gDirectory->Get(dtname.Data());
90001c80 787 if(!fCalibData) {
8af17dba 788 Error("LoadCalibData","No Calibration data found for %s",GetName());
789 exit(1);
790 }
791
792 cdfile->Close();
793 delete cdfile;
794}
795