]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ZDC/AliZDC.cxx
#95494: Change AliLog message in AliAltroRawStreamV3.cxx (additional reduction of...
[u/mrichter/AliRoot.git] / ZDC / AliZDC.cxx
index 9e25074c6b60f0127f8110a34035f11c744fa712..73e2c4a5dc5203c42608e662d733bcc7822bc90f 100644 (file)
@@ -63,7 +63,10 @@ AliZDC::AliZDC() :
   fEnCalibData(0),
   fTowCalibData(0),
   fZDCCalibFName(""),
-  fSpectatorTracked(1)
+  fSpectatorTracked(1),
+  fBeamEnergy(0.),
+  fIspASystem(kFALSE),
+  fIsRELDISgen(kFALSE)
 {
   //
   // Default constructor for the Zero Degree Calorimeter base class
@@ -85,7 +88,10 @@ AliZDC::AliZDC(const char *name, const char *title) :
   fEnCalibData(0),
   fTowCalibData(0),
   fZDCCalibFName(""),
-  fSpectatorTracked(1)
+  fSpectatorTracked(1),
+  fBeamEnergy(0.),
+  fIspASystem(kFALSE),
+  fIsRELDISgen(kFALSE)
 {
   //
   // Standard constructor for the Zero Degree Calorimeter base class
@@ -99,10 +105,7 @@ AliZDC::AliZDC(const char *name, const char *title) :
   fHits = new TClonesArray("AliZDCHit",1000);
   gAlice->GetMCApp()->AddHitList(fHits);
   
-  char sensname[5],senstitle[25];
-  sprintf(sensname,"ZDC");
-  sprintf(senstitle,"ZDC dummy");
-  SetName(sensname); SetTitle(senstitle);
+  SetName("ZDC"); SetTitle("ZDC");
 
 }
 
@@ -128,7 +131,10 @@ fPedCalib(ZDC.fPedCalib),
 fEnCalibData(ZDC.fEnCalibData),
 fTowCalibData(ZDC.fTowCalibData),
 fZDCCalibFName(ZDC.fZDCCalibFName),
-fSpectatorTracked(ZDC.fSpectatorTracked)
+fSpectatorTracked(ZDC.fSpectatorTracked),
+fBeamEnergy(ZDC.fBeamEnergy),
+fIspASystem(ZDC.fIspASystem),
+fIsRELDISgen(ZDC.fIsRELDISgen)
 {
   // copy constructor
 }
@@ -143,6 +149,8 @@ AliZDC& AliZDC::operator=(const AliZDC& ZDC)
     fEnCalibData = ZDC.fEnCalibData;
     fTowCalibData = ZDC.fTowCalibData;
     fZDCCalibFName = ZDC.fZDCCalibFName;
+    fBeamEnergy = ZDC.fBeamEnergy;
+    fIspASystem = ZDC.fIspASystem;
   } return *this;
 }
 
@@ -237,7 +245,7 @@ void AliZDC::MakeBranch(Option_t *opt)
   //
 
   char branchname[10];
-  sprintf(branchname,"%s",GetName());
+  snprintf(branchname, 10, "%s", GetName());
 
   const char *cH = strstr(opt,"H");
   
@@ -411,12 +419,14 @@ void AliZDC::Hits2SDigits()
 }
 
 //_____________________________________________________________________________
-AliDigitizer* AliZDC::CreateDigitizer(AliRunDigitizer* manager) const
-{
+AliDigitizer* AliZDC::CreateDigitizer(AliDigitizationInput* digInput) const{
   // Create the digitizer for ZDC
-  AliZDCDigitizer *zdcDigitizer = new AliZDCDigitizer(manager);
+  AliZDCDigitizer *zdcDigitizer = new AliZDCDigitizer(digInput);
   if(fSpectatorTracked==0) zdcDigitizer->SetSpectators2Track();
-  //printf("\n**************************ZDC digitizer created with Spectators2Track = %d\n\n", fSpectatorTracked);
+  if(fBeamEnergy>0.01) zdcDigitizer->SetBeamEnergy(fBeamEnergy);
+  if(fIspASystem==kTRUE) zdcDigitizer->SetpAsystem();
+  if(fIsRELDISgen==kTRUE) zdcDigitizer->SetRELDISGenerator();
+  //if(fIspASystem==kTRUE) printf("\n **** ZDC digitizer initialized for p-A collisions\n\n");
   return zdcDigitizer;
 }
 
@@ -435,10 +445,12 @@ void AliZDC::Digits2Raw()
   //
   const int knADCData1=12, knADCData2=12; 
   const int knADCData3=12, knADCData4=12; 
+  //
   UInt_t lADCHeader1; 
   UInt_t lADCHeader2; 
   UInt_t lADCHeader3; 
   UInt_t lADCHeader4; 
+  //
   UInt_t lADCData1[2*knADCData1];
   UInt_t lADCData2[2*knADCData2];
   UInt_t lADCData3[2*knADCData3];
@@ -456,7 +468,7 @@ void AliZDC::Digits2Raw()
   //printf("\t AliZDC::Digits2Raw -> TreeD has %d entries\n",(Int_t) treeD->GetEntries());
 
   // Reading channel map
-  printf("\n\t Reading ADC mapping from OCDB\n");
+  //printf("\n\t Reading ADC mapping from OCDB\n");
   AliZDCChMap * chMap = GetChMap();
   const int nCh = knADCData1+knADCData2+knADCData3+knADCData4;
   Int_t  mapADC[nCh][4]; 
@@ -465,6 +477,9 @@ void AliZDC::Digits2Raw()
     mapADC[i][1] = chMap->GetADCChannel(i);
     mapADC[i][2] = chMap->GetDetector(i);
     mapADC[i][3] = chMap->GetSector(i);
+    // Ch. debug
+    //printf("  mapADC[%d] = (%d %d %d %d)\n", i,
+    // mapADC[i][0],mapADC[i][1],mapADC[i][2],mapADC[i][3]);
   }
 
   // *** Fill data array
@@ -499,96 +514,141 @@ void AliZDC::Digits2Raw()
   UInt_t lADCDataOvFlwHG = 0;
   UInt_t lADCDataOvFlwLG = 0;
   //
-  for(Int_t i=0; i<knADCData1 ; i++){
-    lADCDataValue1[i] = 0;
-  }
-  for(Int_t i=0; i<knADCData2 ; i++){
-    lADCDataValue2[i] = 0;
-  }
-  for(Int_t i=0; i<knADCData3 ; i++){
-    lADCDataValue3[i] = 0;
-  }
-  for(Int_t i=0; i<knADCData4 ; i++){
-    lADCDataValue4[i] = 0;
-  }
+  for(Int_t i=0; i<2*knADCData1 ; i++) lADCDataValue1[i] = 0;
+  for(Int_t i=0; i<2*knADCData2 ; i++) lADCDataValue2[i] = 0;
+  for(Int_t i=0; i<2*knADCData3 ; i++) lADCDataValue3[i] = 0;
+  for(Int_t i=0; i<2*knADCData4 ; i++) lADCDataValue4[i] = 0;
   //
   UInt_t lADCDataChannel = 0;
   
+  Int_t indADC0=0, indADC1=0, indADC2=0, indADC3=0;
+  
   // loop over digits
-  for(Int_t iDigit=0; iDigit<treeD->GetEntries(); iDigit++){
+  for(Int_t iDigit=0; iDigit<(Int_t) (treeD->GetEntries()); iDigit++){
     treeD->GetEntry(iDigit);
     if(!pdigit) continue;
     //digit.Print("");
-    
+   
     // *** ADC data
     // Scan of the map to assign the correct ADC module-channel
     for(Int_t k=0; k<nCh; k++){
+      if(iDigit<knADCData1+knADCData2){ 
        if(digit.GetSector(0)==mapADC[k][2] && digit.GetSector(1)==mapADC[k][3]){
-        lADCDataGEO = mapADC[k][0];
-        lADCDataChannel = mapADC[k][1];
+        lADCDataGEO = (UInt_t) mapADC[k][0];
+        lADCDataChannel = (UInt_t) mapADC[k][1];
         break;
        } 
+      }
+      else{
+       if(digit.GetSector(0)==mapADC[k][2] && digit.GetSector(1)==mapADC[k][3]){
+        lADCDataGEO = (UInt_t) mapADC[k][0];
+        lADCDataChannel = (UInt_t) mapADC[k][1];
+        if(k>knADCData1+knADCData2) break;
+       } 
+      }
     }
-    
-    if(lADCDataGEO==0){ // *** In-time signals - 1st ADC module
-      // High gain ADC ch.       
+    // Ch. debug
+    //printf("iDigit %d det %d sec %d -> lADCDataGEO %d  lADCDataChannel %d\n",
+    // iDigit,digit.GetSector(0),digit.GetSector(1),lADCDataGEO,lADCDataChannel);
+     
+    if(lADCDataGEO==0){ 
+      if(indADC0>=knADCData1){
+        AliWarning(" Problem with digit index 4 ADC0\n");
+       return;
+      }
+      Int_t indLG = indADC0+knADCData1;
+      // High gain ADC ch.      
       if(digit.GetADCValue(0) > 2047) lADCDataOvFlwHG = 1; 
-      lADCDataValue1[iDigit] = digit.GetADCValue(0);    
-      lADCData1[iDigit] = lADCDataGEO << 27 | lADCDataChannel << 17 | 
-                     lADCDataOvFlwHG << 12 | (lADCDataValue1[iDigit] & 0xfff); 
+      lADCDataValue1[indADC0] = digit.GetADCValue(0);    
+      lADCData1[indADC0] = lADCDataGEO << 27 |  lADCDataChannel << 17 | 
+                   lADCDataOvFlwHG << 12 | (lADCDataValue1[indADC0] & 0xfff); 
       // Low gain ADC ch.
       if(digit.GetADCValue(1) > 2047) lADCDataOvFlwLG = 1; 
-      lADCDataValue1[iDigit+knADCData1] = digit.GetADCValue(1); 
-      lADCData1[iDigit+knADCData1] = lADCDataGEO << 27 |  lADCDataChannel << 17 | 0x1 << 16 |
-                     lADCDataOvFlwLG << 12 | (lADCDataValue1[iDigit+knADCData1] & 0xfff);  
+      lADCDataValue1[indLG] = digit.GetADCValue(1); 
+      lADCData1[indLG] = lADCDataGEO << 27 |  lADCDataChannel << 17 | 0x1 << 16 |
+                   lADCDataOvFlwLG << 12 | (lADCDataValue1[indLG] & 0xfff);  
+      // Ch. debug
+      //printf(" lADCDataGEO %d  ADCdataHG[%d] %d  ADCdataLG[%d] %d\n", 
+      //  lADCDataGEO,indADC0,lADCDataValue1[indADC0],indLG,lADCDataValue1[indLG]);
+                   
+      indADC0++;
     }
-    else if(lADCDataGEO==1){ // *** In-time signals - 2nd ADC module
-      // High gain ADC ch.       
+    else if(lADCDataGEO==1){ 
+      if(indADC1>=knADCData2){
+         AliWarning(" Problem with digit index 4 ADC1\n");
+        return;
+      }
+      Int_t indLG = indADC1+knADCData2;
+      // High gain ADC ch.      
       if(digit.GetADCValue(0) > 2047) lADCDataOvFlwHG = 1; 
-      lADCDataValue2[iDigit] = digit.GetADCValue(0);    
-      lADCData2[iDigit] = lADCDataGEO << 27 | lADCDataChannel << 17 | 
-                     lADCDataOvFlwHG << 12 | (lADCDataValue2[iDigit] & 0xfff); 
+      lADCDataValue2[indADC1] = digit.GetADCValue(0);   
+      lADCData2[indADC1] = lADCDataGEO << 27 | lADCDataChannel << 17 | 
+                   lADCDataOvFlwHG << 12 | (lADCDataValue2[indADC1] & 0xfff); 
       // Low gain ADC ch.
       if(digit.GetADCValue(1) > 2047) lADCDataOvFlwLG = 1; 
-      lADCDataValue2[iDigit+knADCData1] = digit.GetADCValue(1); 
-      lADCData2[iDigit+knADCData1] = lADCDataGEO << 27 |  lADCDataChannel << 17 | 0x1 << 16 |
-                     lADCDataOvFlwLG << 12 | (lADCDataValue2[iDigit+knADCData2] & 0xfff);  
-    }            
-    else if(lADCDataGEO==2){ // *** Out-of-time signals - 3rd ADC module
-      // High gain ADC ch.       
+      lADCDataValue2[indLG] = digit.GetADCValue(1); 
+      lADCData2[indLG] = lADCDataGEO << 27 |  lADCDataChannel << 17 | 0x1 << 16 |
+                   lADCDataOvFlwLG << 12 | (lADCDataValue2[indLG] & 0xfff);  
+      // Ch. debug
+      //printf(" lADCDataGEO %d  ADCdataHG[%d] %d  ADCdataLG[%d] %d\n", 
+      //  lADCDataGEO,indADC1,lADCDataValue2[indADC1],indLG,lADCDataValue2[indLG]);
+                 
+      indADC1++;
+    }
+    else if(lADCDataGEO==2){ 
+      if(indADC2>=knADCData3){
+        AliWarning(" Problem with digit index 4 ADC2\n");
+       return;
+      }
+      Int_t indLG = indADC2+knADCData3;
+      // High gain ADC ch.      
       if(digit.GetADCValue(0) > 2047) lADCDataOvFlwHG = 1; 
-      lADCDataValue3[iDigit] = digit.GetADCValue(0);    
-      lADCData3[iDigit] = lADCDataGEO << 27 | lADCDataChannel << 17 | 
-                     lADCDataOvFlwHG << 12 | (lADCDataValue3[iDigit] & 0xfff); 
+      lADCDataValue3[indADC1] = digit.GetADCValue(0);    
+      lADCData3[indADC1] = lADCDataGEO << 27 | lADCDataChannel << 17 | 
+                   lADCDataOvFlwHG << 12 | (lADCDataValue3[indADC2] & 0xfff); 
       // Low gain ADC ch.
       if(digit.GetADCValue(1) > 2047) lADCDataOvFlwLG = 1; 
-      lADCDataValue3[iDigit+knADCData1] = digit.GetADCValue(1); 
-      lADCData3[iDigit+knADCData3] = lADCDataGEO << 27 |  lADCDataChannel << 17 | 0x1 << 16 |
-                     lADCDataOvFlwLG << 12 | (lADCDataValue3[iDigit+knADCData3] & 0xfff);  
+      lADCDataValue3[indLG] = digit.GetADCValue(1); 
+      lADCData3[indLG] = lADCDataGEO << 27 |  lADCDataChannel << 17 | 0x1 << 16 |
+                   lADCDataOvFlwLG << 12 | (lADCDataValue3[indLG] & 0xfff);  
+      // Ch. debug
+      //printf(" lADCDataGEO %d  ADCdataHG[%d] %d  ADCdataLG[%d] %d\n", 
+      //  lADCDataGEO,indADC2,lADCDataValue3[indADC2],indLG,lADCDataValue3[indLG]);
+                 
+      indADC2++;
     }
-    else if(lADCDataGEO==3){ // *** Out-of-time signals - 4rth ADC
-      // High gain ADC ch.       
+    else if(lADCDataGEO==3){ 
+      if(indADC3>=knADCData4){
+         AliWarning(" Problem with digit index 4 ADC2\n");
+        return;
+      }
+      Int_t indLG = indADC3+knADCData4;
+      // High gain ADC ch.      
       if(digit.GetADCValue(0) > 2047) lADCDataOvFlwHG = 1; 
-      lADCDataValue4[iDigit] = digit.GetADCValue(0);    
-      lADCData4[iDigit] = lADCDataGEO << 27 | lADCDataChannel << 17 | 
-                     lADCDataOvFlwHG << 12 | (lADCDataValue4[iDigit] & 0xfff); 
+      lADCDataValue4[indADC3] = digit.GetADCValue(0);    
+      lADCData4[indADC3] = lADCDataGEO << 27 | lADCDataChannel << 17 | 
+                   lADCDataOvFlwHG << 12 | (lADCDataValue4[indADC3] & 0xfff); 
       // Low gain ADC ch.
       if(digit.GetADCValue(1) > 2047) lADCDataOvFlwLG = 1; 
-      lADCDataValue4[iDigit+knADCData1] = digit.GetADCValue(1); 
-      lADCData4[iDigit+knADCData4] = lADCDataGEO << 27 |  lADCDataChannel << 17 | 0x1 << 16 |
-                     lADCDataOvFlwLG << 12 | (lADCDataValue4[iDigit+knADCData4] & 0xfff);  
-    }                 
+      lADCDataValue4[indLG] = digit.GetADCValue(1); 
+      lADCData4[indLG] = lADCDataGEO << 27 |  lADCDataChannel << 17 | 0x1 << 16 |
+                   lADCDataOvFlwLG << 12 | (lADCDataValue4[indLG] & 0xfff);  
+      // Ch. debug
+      //printf(" lADCDataGEO %d  ADCdataHG[%d] %d  ADCdataLG[%d] %d\n", 
+      //  lADCDataGEO,indADC3,lADCDataValue4[indADC3],indLG,lADCDataValue4[indLG]);
+                 
+      indADC3++;
+    }            
+
   }
   //
-  /*
-  for(Int_t i=0;i<knADCData1;i++) printf("\t ADCData1[%d] = %x\n",i,lADCData1[i]);
-  for(Int_t i=0;i<knADCData2;i++) printf("\t ADCData2[%d] = %x\n",i,lADCData2[i]);
-  for(Int_t i=0;i<knADCData1;i++) printf("\t ADCData3[%d] = %x\n",i,lADCData3[i]);
-  for(Int_t i=0;i<knADCData2;i++) printf("\t ADCData4[%d] = %x\n",i,lADCData4[i]);
-  */
+  /*for(Int_t i=0;i<2*knADCData1;i++) printf("\t ADCData1[%d] = %x\n",i,lADCData1[i]);
+  for(Int_t i=0;i<2*knADCData2;i++) printf("\t ADCData2[%d] = %x\n",i,lADCData2[i]);
+  for(Int_t i=0;i<2*knADCData3;i++) printf("\t ADCData3[%d] = %x\n",i,lADCData3[i]);
+  for(Int_t i=0;i<2*knADCData4;i++) printf("\t ADCData4[%d] = %x\n",i,lADCData4[i]);*/
+   
   // End of Block
-  UInt_t lADCEndBlockGEO = lADCHeaderGEO1;
+  UInt_t lADCEndBlockGEO = 0;
   // Event counter in ADC EOB -> getting no. of events in run from AliRunLoader
   // get run loader
   AliRunLoader* runLoader = fLoader->GetRunLoader(); 
@@ -598,10 +658,10 @@ void AliZDC::Digits2Raw()
   //printf("\t AliZDC::Digits2Raw -> ADCEndBlock = %d\n",lADCEndBlock);
 
   // open the output file
-  char fileName[30];
-  strcpy(fileName,AliDAQ::DdlFileName("ZDC",0));
+  TString fileName;
+  fileName.Form("%s",AliDAQ::DdlFileName("ZDC",0)); 
 
-  AliFstream* file = new AliFstream(fileName);
+  AliFstream* file = new AliFstream(fileName.Data());
 
   // write the DDL data header
   AliRawDataHeaderSim header;
@@ -615,23 +675,25 @@ void AliZDC::Digits2Raw()
           sizeof(header),sizeof(lADCHeader1),sizeof(lADCData1),sizeof(lADCEndBlock));
   printf("sizeof header = %d, ADCHeader2 = %d, ADCData2 = %d, ADCEndBlock = %d\n",
           sizeof(header),sizeof(lADCHeader2),sizeof(lADCData2),sizeof(lADCEndBlock));
-  */
-  //    
+  printf("sizeof header = %d, ADCHeader3 = %d, ADCData3 = %d, ADCEndBlock = %d\n",
+          sizeof(header),sizeof(lADCHeader1),sizeof(lADCData1),sizeof(lADCEndBlock));
+  printf("sizeof header = %d, ADCHeader4 = %d, ADCData4 = %d, ADCEndBlock = %d\n",
+          sizeof(header),sizeof(lADCHeader2),sizeof(lADCData2),sizeof(lADCEndBlock));*/
+  
   header.SetAttribute(0);  // valid data
   file->WriteBuffer((char*)(&header), sizeof(header));
-
   // write the raw data and close the file
-  file->WriteBuffer((char*) &lADCHeader1, sizeof (lADCHeader1));
-  file->WriteBuffer((char*)(lADCData1), sizeof(lADCData1));
+  file->WriteBuffer((char*) &lADCHeader1,  sizeof (lADCHeader1));
+  file->WriteBuffer((char*) &lADCData1,   sizeof(lADCData1));
   file->WriteBuffer((char*) &lADCEndBlock, sizeof(lADCEndBlock));
-  file->WriteBuffer((char*) &lADCHeader2, sizeof (lADCHeader2));
-  file->WriteBuffer((char*)(lADCData2), sizeof(lADCData2));
+  file->WriteBuffer((char*) &lADCHeader2,  sizeof (lADCHeader2));
+  file->WriteBuffer((char*) (lADCData2),   sizeof(lADCData2));
   file->WriteBuffer((char*) &lADCEndBlock, sizeof(lADCEndBlock));
-  file->WriteBuffer((char*) &lADCHeader3, sizeof (lADCHeader3));
-  file->WriteBuffer((char*)(lADCData3), sizeof(lADCData3));
+  file->WriteBuffer((char*) &lADCHeader3,  sizeof (lADCHeader3));
+  file->WriteBuffer((char*) (lADCData3),   sizeof(lADCData3));
   file->WriteBuffer((char*) &lADCEndBlock, sizeof(lADCEndBlock));
-  file->WriteBuffer((char*) &lADCHeader4, sizeof (lADCHeader4));
-  file->WriteBuffer((char*)(lADCData4), sizeof(lADCData4));
+  file->WriteBuffer((char*) &lADCHeader4,  sizeof (lADCHeader4));
+  file->WriteBuffer((char*) (lADCData4),   sizeof(lADCData4));
   file->WriteBuffer((char*) &lADCEndBlock, sizeof(lADCEndBlock));
   delete file;
 
@@ -643,59 +705,54 @@ void AliZDC::Digits2Raw()
 Bool_t AliZDC::Raw2SDigits(AliRawReader* rawReader)
 {
   // Convert ZDC raw data to Sdigits
-  
+  const int kNch = 48;
   AliLoader* loader = (AliRunLoader::Instance())->GetLoader("ZDCLoader");
   if(!loader) {
     AliError("no ZDC loader found");
     return kFALSE;
   }
 
-//  // Event loop
-  Int_t iEvent = 0;
-  while(rawReader->NextEvent()){
-    (AliRunLoader::Instance())->GetEvent(iEvent++);
-    // Create the output digit tree
-    TTree* treeS = loader->TreeS();
-    if(!treeS){
-      loader->MakeTree("S");
-      treeS = loader->TreeS();
-    }
-    //
-    AliZDCSDigit sdigit;
-    AliZDCSDigit* psdigit = &sdigit;
-    const Int_t kBufferSize = 4000;
-    treeS->Branch("ZDC", "AliZDCSDigit",  &psdigit, kBufferSize);
-    //
-    AliZDCRawStream rawStream(rawReader);
-    Int_t sector[2], resADC, rawADC, corrADC, nPheVal;
-    Int_t jcount = 0;
-    while(rawStream.Next()){
-      if(rawStream.IsADCDataWord()){
-        //For the moment only in-time SDigits are foreseen (1st 48 raw values)
-        if(jcount < 48){ 
-          for(Int_t j=0; j<2; j++) sector[j] = rawStream.GetSector(j);
-         rawADC = rawStream.GetADCValue();
-         resADC = rawStream.GetADCGain();
-         //printf("\t RAw2SDigits raw%d ->  RawADC[%d, %d, %d] read\n",
-         //    jcount, sector[0], sector[1], rawADC);
-         //
-         corrADC = rawADC - Pedestal(sector[0], sector[1], resADC);
-         if(corrADC<0) corrADC=0;
-         nPheVal = ADCch2Phe(sector[0], sector[1], corrADC, resADC);
-          //
-         //printf("\t \t ->  SDigit[%d, %d, %d] created\n",
-         //    sector[0], sector[1], nPheVal);
-         //
-          new(psdigit) AliZDCSDigit(sector, (Float_t) nPheVal, 0.);
-          treeS->Fill();
-          jcount++;
-        }
-      }//IsADCDataWord
-    }//rawStream.Next
-    // write the output tree
-    fLoader->WriteSDigits("OVERWRITE");
-    fLoader->UnloadSDigits();
-  }//Event loop 
+  // Create the output digit tree
+  TTree* treeS = loader->TreeS();
+  if(!treeS){
+    loader->MakeTree("S");
+    treeS = loader->TreeS();
+  }
+  //
+  AliZDCSDigit sdigit;
+  AliZDCSDigit* psdigit = &sdigit;
+  const Int_t kBufferSize = 4000;
+  treeS->Branch("ZDC", "AliZDCSDigit",  &psdigit, kBufferSize);
+  //
+  AliZDCRawStream rawStream(rawReader);
+  Int_t sector[2], resADC, rawADC, corrADC, nPheVal;
+  Int_t jcount = 0;
+  while(rawStream.Next()){
+    if(rawStream.IsADCDataWord()){
+      //For the moment only in-time SDigits are foreseen (1st 48 raw values)
+      if(jcount < kNch){ 
+       for(Int_t j=0; j<2; j++) sector[j] = rawStream.GetSector(j);
+        rawADC = rawStream.GetADCValue();
+        resADC = rawStream.GetADCGain();
+        //printf("\t RAw2SDigits raw%d ->  RawADC[%d, %d, %d] read\n",
+        //    jcount, sector[0], sector[1], rawADC);
+        //
+        corrADC = rawADC - Pedestal(sector[0], sector[1], resADC);
+        if(corrADC<0) corrADC=0;
+        nPheVal = ADCch2Phe(sector[0], sector[1], corrADC, resADC);
+       //
+        //printf("\t \t ->  SDigit[%d, %d, %d] created\n",
+        //    sector[0], sector[1], nPheVal);
+        //
+       new(psdigit) AliZDCSDigit(sector, (Float_t) nPheVal, 0.);
+       treeS->Fill();
+       jcount++;
+      }
+    }//IsADCDataWord
+  }//rawStream.Next
+  // write the output tree
+  fLoader->WriteSDigits("OVERWRITE");
+  fLoader->UnloadSDigits();
    
   return kTRUE;
 }
@@ -708,6 +765,7 @@ Int_t AliZDC::Pedestal(Int_t Det, Int_t Quad, Int_t Res) const
   // Getting calibration object for ZDC set
   AliCDBManager *man = AliCDBManager::Instance();
   AliCDBEntry  *entry = man->Get("ZDC/Calib/Pedestals");
+  if(!entry) AliFatal("No calibration data loaded!");  
   AliZDCPedestals *calibPed = (AliZDCPedestals*) entry->GetObject();
   //
   if(!calibPed){
@@ -756,7 +814,7 @@ Int_t AliZDC::ADCch2Phe(Int_t Det, Int_t Quad, Int_t ADCVal, Int_t Res) const
   resADC[0] = 0.0000008; // ADC Resolution high gain: 200 fC/adcCh
   resADC[1] = 0.0000064; // ADC Resolution low gain:  25  fC/adcCh
   //
-  Int_t nPhe = (Int_t) (ADCVal * pmGain[Det-1][Quad] * resADC[Res]);
+  Int_t nPhe = (Int_t) (ADCVal / (pmGain[Det-1][Quad] * resADC[Res]));
   //
   //printf("\t AliZDC::ADCch2Phe -> det(%d, %d) - ADC %d  phe %d\n",Det,Quad,ADCVal,nPhe);
 
@@ -774,7 +832,7 @@ void AliZDC::SetTreeAddress(){
 }
 
 //_____________________________________________________________________________
-AliZDCChMap* AliZDCRawStream::GetChMap() const
+AliZDCChMap* AliZDC::GetChMap() const
 {
 
   // Getting calibration object for ZDC