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