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