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