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