]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ZDC/AliZDCDigitizer.cxx
For each bin change wait for buffer to be refilled with fresh events from the new...
[u/mrichter/AliRoot.git] / ZDC / AliZDCDigitizer.cxx
index 474a2a936f69cf5e318a726e81c91d0e2535b652..6adb203edb78f38598d104ed70919ae7c660c776 100644 (file)
 #include "AliZDCDigitizer.h"
 
 class AliCDBStorage;
-class AliZDCCalibData;
+class AliZDCPedestals;
+class AliZDCCalib;
 
 ClassImp(AliZDCDigitizer)
 
 
 //____________________________________________________________________________
-AliZDCDigitizer::AliZDCDigitizer()
+AliZDCDigitizer::AliZDCDigitizer() :
+  fIsCalibration(0), 
+  fPedData(0), 
+  fCalibData(0)
 {
 // Default constructor    
 
@@ -58,12 +62,13 @@ AliZDCDigitizer::AliZDCDigitizer()
 
 //____________________________________________________________________________
 AliZDCDigitizer::AliZDCDigitizer(AliRunDigitizer* manager):
-  AliDigitizer(manager)
+  AliDigitizer(manager),
+  fIsCalibration(0), //By default the simulation doesn't create calib. data
+  fPedData(GetPedData()), 
+  fCalibData(GetCalibData())
 {
-  fIsCalibration=0; //By default the simulation doesn't create calib. data
   // Get calibration data
-  fCalibData = GetCalibData(); 
-  if(fIsCalibration!=0) printf("\t **** AliZDCDigitizer -> Creating calibration data (pedestals)\n");
+  if(fIsCalibration!=0) printf("\n\t AliZDCDigitizer -> Creating calibration data (pedestals)\n");
 
 }
 
@@ -71,13 +76,16 @@ AliZDCDigitizer::AliZDCDigitizer(AliRunDigitizer* manager):
 AliZDCDigitizer::~AliZDCDigitizer()
 {
 // Destructor
-
+// Not implemented
 }
 
 
 //____________________________________________________________________________
 AliZDCDigitizer::AliZDCDigitizer(const AliZDCDigitizer &digitizer):
-  AliDigitizer()
+  AliDigitizer(),
+  fIsCalibration(digitizer.fIsCalibration),
+  fPedData(digitizer.fPedData),
+  fCalibData(digitizer.fCalibData)
 {
   // Copy constructor
 
@@ -87,8 +95,6 @@ AliZDCDigitizer::AliZDCDigitizer(const AliZDCDigitizer &digitizer):
      }
   }
   for(Int_t i=0; i<2; i++) fADCRes[i] = digitizer.fADCRes[i];
-  fIsCalibration = digitizer.fIsCalibration;
-  fCalibData = digitizer.fCalibData;
 
 }
 
@@ -118,7 +124,7 @@ void AliZDCDigitizer::Exec(Option_t* /*option*/)
   // Execute digitization
 
   // ------------------------------------------------------------
-  // !!! 2nd ZDC set added (needed for trigger purposes!)
+  // !!! 2nd ZDC set added 
   // *** 1st 3 arrays are digits from REAL (simulated) hits
   // *** last 2 are copied from simulated digits
   // --- pm[0][...] = light in ZN right  [C, Q1, Q2, Q3, Q4]
@@ -198,16 +204,17 @@ void AliZDCDigitizer::Exec(Option_t* /*option*/)
     specP = ((AliGenHijingEventHeader*) genHeader)->ProjSpectatorsp();
     AliDebug(2, Form("\n AliZDCDigitizer -> b = %f fm, Nspecn = %d, Nspecp = %d\n",
                      impPar, specN, specP));
-    printf("\n\t AliZDCDigitizer -> b = %f fm, NSpecn = %d, NSpecp = %d\n", impPar, specN, specP);
+    printf("\n\t AliZDCDigitizer -> b = %f fm, # generated spectator n = %d," 
+    " # generated spectator p = %d\n", impPar, specN, specP);
   }
 
   // add spectators
   if(impPar >= 0) {
     Int_t freeSpecN, freeSpecP;
     Fragmentation(impPar, specN, specP, freeSpecN, freeSpecP);
-    printf("\n\t AliZDCDigitizer ---- Adding signal for %d free spectator n\n",freeSpecN);
+    printf("\n\t AliZDCDigitizer -> Adding signal for %d free spectator n\n",freeSpecN);
     SpectatorSignal(1, freeSpecN, pm);
-    printf("\t AliZDCDigitizer ---- Adding signal for %d free spectator p\n\n",freeSpecP);
+    printf("\t AliZDCDigitizer -> Adding signal for %d free spectator p\n\n",freeSpecP);
     SpectatorSignal(2, freeSpecP, pm);
   }
 
@@ -233,45 +240,46 @@ void AliZDCDigitizer::Exec(Option_t* /*option*/)
   treeD->Branch("ZDC", "AliZDCDigit", &pdigit, kBufferSize);
 
   // Create digits
-  Int_t sector[2], sectorL[2];
-  Int_t digi[2], digiL[2], digioot[2];
-  for(sector[0]=1; sector[0]<=3; sector[0]++){
+  Int_t sector[2];
+  Int_t digi[2], digioot[2];
+  for(sector[0]=1; sector[0]<6; sector[0]++){
     for(sector[1]=0; sector[1]<5; sector[1]++){
         if((sector[0]==3) && ((sector[1]<1) || (sector[1]>2))) continue;
         for(Int_t res=0; res<2; res++){
            digi[res] = Phe2ADCch(sector[0], sector[1], pm[sector[0]-1][sector[1]], res) 
                    + Pedestal(sector[0], sector[1], res);
        }
-       /*printf("\t DIGIT added -> det = %d, quad = %d - digi[0,1] = [%d, %d]\n",
+       /*printf("\t DIGIT added -> det %d quad %d - digi[0,1] = [%d, %d]\n",
             sector[0], sector[1], digi[0], digi[1]); // Chiara debugging!
        */
        //
        new(pdigit) AliZDCDigit(sector, digi);
         treeD->Fill();
-       //
-       // --- Adding digits for 2nd ZDC set (left side w.r.t. IP) ---
-       // --- they are copied from right ZDC digits
-       if(sector[0]==1 || sector[0]==2){
-          sectorL[0] = sector[0]+3;
-          sectorL[1] = sector[1];
-           for(Int_t res=0; res<2; res++){
-             digiL[res] = Phe2ADCch(sectorL[0], sectorL[1], pm[sector[0]-1][sector[1]], res) 
-                   + Pedestal(sectorL[0], sectorL[1], res);
-          }
-          /*printf("\t DIGIT added -> det = %d, quad = %d - digi[0,1] = [%d, %d]\n",
-                sectorL[0], sectorL[1], digiL[0], digiL[1]); // Chiara debugging!
-          */
-          //
-          new(pdigit) AliZDCDigit(sectorL, digiL);
-           treeD->Fill();
-       }
-       //
-        //printf("\t AliZDCDigitizer -> TreeD has %d entries\n",(Int_t) treeD->GetEntries());
     }
+  } // Loop over detector
+  // Adding in-time digits for 2 reference PTM signals (after signal ch.)
+  // (for the moment the ref. signal is completely invented assuming a PMgain of 5*10^4!)
+  Int_t sectorRef[2];
+  sectorRef[1] = 5;
+  Int_t sigRef[2];
+  // Reference signal are set to 100 (high gain chain) and 800 (low gain chain)
+  if(fIsCalibration==0) {sigRef[0]=100;  sigRef[1]=800;}
+  else {sigRef[0]=0;  sigRef[1]=0;} // calibration -> simulation of pedestal values
+  //
+  for(Int_t iref=0; iref<2; iref++){
+     sectorRef[0] = 3*iref+1;
+     for(Int_t res=0; res<2; res++){
+       sigRef[res] += Pedestal(sectorRef[0], sectorRef[1], res);
+     }
+     /*printf("\t RefDigit added -> det = %d, quad = %d - digi[0,1] = [%d, %d]\n",
+         sectorRef[0], sectorRef[1], sigRef[0], sigRef[1]); // Chiara debugging!
+     */
+     new(pdigit) AliZDCDigit(sectorRef, sigRef);
+     treeD->Fill();     
   }
   //
   // --- Adding digits for out-of-time channels after signal digits
-  for(sector[0]=1; sector[0]<=3; sector[0]++){
+  for(sector[0]=1; sector[0]<6; sector[0]++){
     for(sector[1]=0; sector[1]<5; sector[1]++){
         if((sector[0]==3) && ((sector[1]<1) || (sector[1]>2))) continue;
         for(Int_t res=0; res<2; res++){
@@ -283,24 +291,23 @@ void AliZDCDigitizer::Exec(Option_t* /*option*/)
        //
        new(pdigit) AliZDCDigit(sector, digioot);
         treeD->Fill();
-       //
-       if(sector[0]==1 || sector[0]==2){
-          sectorL[0] = sector[0]+3;
-          sectorL[1] = sector[1];
-           for(Int_t res=0; res<2; res++){
-             digioot[res] = Pedestal(sectorL[0], sectorL[1], res); // out-of-time ADCs
-          }
-          /*printf("\t DIGIToot added -> det = %d, quad = %d - digi[0,1] = [%d, %d]\n",
-                sectorL[0], sectorL[1], digioot[0], digioot[1]); // Chiara debugging!
-          */
-          //
-          new(pdigit) AliZDCDigit(sectorL, digioot);
-           treeD->Fill();
-       }
-       //
-        //printf("\t AliZDCDigitizer -> TreeD has %d entries\n",(Int_t) treeD->GetEntries());
     }
   }
+  // Adding out-of-time digits for 2 reference PTM signals (after out-of-time ch.)
+  Int_t sigRefoot[2];
+  for(Int_t iref=0; iref<2; iref++){
+     sectorRef[0] = 3*iref+1;
+     for(Int_t res=0; res<2; res++){
+       sigRefoot[res] = Pedestal(sectorRef[0], sectorRef[1], res);
+     }
+     /*printf("\t RefDigitoot added -> det = %d, quad = %d - digi[0,1] = [%d, %d]\n",
+         sectorRef[0], sectorRef[1], sigRefoot[0], sigRefoot[1]); // Chiara debugging!
+     */
+     new(pdigit) AliZDCDigit(sectorRef, sigRefoot);
+     treeD->Fill();
+  }
+  //printf("\t AliZDCDigitizer -> TreeD has %d entries\n",(Int_t) treeD->GetEntries());
+
   // write the output tree
   loader->WriteDigits("OVERWRITE");
   loader->UnloadDigits();
@@ -313,23 +320,22 @@ void AliZDCDigitizer::Fragmentation(Float_t impPar, Int_t specN, Int_t specP,
 {
 // simulate fragmentation of spectators
 
-  Int_t zz[100], nn[100];
   AliZDCFragment frag(impPar);
-  for(Int_t j=0; j<=99; j++){
-     zz[j] =0;
-     nn[j] =0;
-  }
 
   // Fragments generation
-  Int_t nAlpha;
-  frag.GenerateIMF(zz, nAlpha);
+  frag.GenerateIMF();
+  Int_t nAlpha = frag.GetNalpha();
 
   // Attach neutrons
-  Int_t ztot=0;
-  Int_t ntot=0;
-  frag.AttachNeutrons(zz, nn, ztot, ntot);
+  Int_t ztot = frag.GetZtot();
+  Int_t ntot = frag.GetNtot();
+  frag.AttachNeutrons();
   freeSpecN = specN-ntot-2*nAlpha;
   freeSpecP = specP-ztot-2*nAlpha;
+  // Removing deuterons
+  Int_t ndeu = (Int_t) (freeSpecN*frag.DeuteronNumber());
+  freeSpecN -= ndeu;
+  //
   if(freeSpecN<0) freeSpecN=0;
   if(freeSpecP<0) freeSpecP=0;
   AliDebug(2, Form("FreeSpn = %d, FreeSpp = %d", freeSpecN, freeSpecP));
@@ -383,7 +389,7 @@ void AliZDCDigitizer::SpectatorSignal(Int_t SpecType, Int_t numEvents,
                            volume[0], volume[1], lightQ, lightC));
          //printf("\n   Volume = (%d, %d), lightQ = %.0f, lightC = %.0f",
           //                 volume[0], volume[1], lightQ, lightC);
-         if(volume[0] < 3) {  // ZN or ZP
+         if(volume[0] != 3) {  // ZN or ZP
             pm[volume[0]-1][0] += lightC;
             pm[volume[0]-1][volume[1]] += lightQ;
            //printf("\n   pm[%d][0] = %.0f, pm[%d][%d] = %.0f\n",(volume[0]-1),pm[volume[0]-1][0],
@@ -391,7 +397,7 @@ void AliZDCDigitizer::SpectatorSignal(Int_t SpecType, Int_t numEvents,
          } 
          else { 
             if(volume[1] == 1) pm[2][1] += lightC; // ZEM 1
-            else                pm[2][2] += lightQ; // ZEM 2
+            else               pm[2][2] += lightQ; // ZEM 2
            //printf("\n   pm[2][1] = %.0f, pm[2][2] = %.0f\n",pm[2][1],pm[2][2]);
          }
        }
@@ -413,7 +419,7 @@ Int_t AliZDCDigitizer::Phe2ADCch(Int_t Det, Int_t Quad, Float_t Light,
 {
   // Evaluation of the ADC channel corresponding to the light yield Light
   Int_t vADCch = (Int_t) (Light * fPMGain[Det-1][Quad] * fADCRes[Res]);
-  //printf("\t Phe2ADCch -> det %d quad %d - phe %.0f  ADC %d\n", Det,Quad,Light,ADCch);
+  //printf("\t Phe2ADCch -> det %d quad %d - phe %.0f  ADC %d\n", Det,Quad,Light,vADCch);
 
   return vADCch;
 }
@@ -423,29 +429,34 @@ Int_t AliZDCDigitizer::Pedestal(Int_t Det, Int_t Quad, Int_t Res) const
 {
   // Returns a pedestal for detector det, PM quad, channel with res.
   //
-  Float_t PedValue;
-  
+  Float_t pedValue;
   // Normal run
   if(fIsCalibration == 0){
-    Float_t meanPed, Pedwidth;
-    Int_t index=0;
-    if(Det==1|| Det==2)                index = 10*(Det-1)+Quad+5*Res;   // ZN1, ZP1
-    else if(Det==3)            index = 10*(Det-1)+(Quad-1)+Res; // ZEM
-    else if(Det==4|| Det==5)   index = 10*(Det-2)+Quad+5*Res+4; // ZN2, ZP2
-    meanPed = fCalibData->GetMeanPed(index);
-    Pedwidth = fCalibData->GetMeanPedWidth(index);
-    PedValue = gRandom->Gaus(meanPed,Pedwidth);
+    Int_t index=0, kNch=24;
+    if(Quad!=5){
+      if(Det==1)       index = Quad+kNch*Res;    // ZNC
+      else if(Det==2)  index = (Quad+5)+kNch*Res;  // ZPC
+      else if(Det==3)  index = (Quad+9)+kNch*Res;  // ZEM
+      else if(Det==4)  index = (Quad+12)+kNch*Res; // ZNA
+      else if(Det==5)  index = (Quad+17)+kNch*Res; // ZPA
+    }
+    else index = (Det-1)/3+22+kNch*Res; // Reference PMs
     //
-    /*printf("\t Pedestal -> det = %d, quad = %d, res = %d - Ped[%d] = %d\n",
-       Det, Quad, index,(Int_t) PedValue); // Chiara debugging!
+    Float_t meanPed = fPedData->GetMeanPed(index);
+    Float_t pedWidth = fPedData->GetMeanPedWidth(index);
+    pedValue = gRandom->Gaus(meanPed,pedWidth);
+    //
+    /*printf("\t  AliZDCDigitizer::Pedestal -> det %d quad %d res %d - Ped[%d] = %d\n",
+       Det, Quad, Res, index,(Int_t) pedValue); // Chiara debugging!
     */
   }
-  
   // To create calibration object
-  else PedValue = gRandom->Gaus((40.+10.*gRandom->Rndm()),5.);
-  
+  else{
+    if(Res == 0) pedValue = gRandom->Gaus((35.+10.*gRandom->Rndm()),(0.5+0.2*gRandom->Rndm())); //High gain
+    else  pedValue = gRandom->Gaus((250.+100.*gRandom->Rndm()),(3.5+2.*gRandom->Rndm())); //Low gain
+  }
 
-  return (Int_t) PedValue;
+  return (Int_t) pedValue;
 }
 
 //_____________________________________________________________________________
@@ -474,17 +485,31 @@ AliCDBStorage* AliZDCDigitizer::SetStorage(const char *uri)
 }
 
 //_____________________________________________________________________________
-AliZDCCalibData* AliZDCDigitizer::GetCalibData() const
+AliZDCPedestals* AliZDCDigitizer::GetPedData() const
 {
 
-  // Getting calibration object for ZDC set
+  // Getting pedestal calibration object for ZDC set
 
-  AliCDBEntry  *entry = AliCDBManager::Instance()->Get("ZDC/Calib/Data");
-  if(!entry) AliFatal("No ZDC calibration found in OCDB!");
-  //
-  AliZDCCalibData *calibdata = (AliZDCCalibData*) entry->GetObject();
-  if(!calibdata)  AliWarning("No calibration data from calibration database !");
+  AliCDBEntry  *entry = AliCDBManager::Instance()->Get("ZDC/Calib/Pedestals");
+  if(!entry) AliFatal("No calibration data loaded!");  
+
+  AliZDCPedestals *calibdata = dynamic_cast<AliZDCPedestals*>  (entry->GetObject());
+  if(!calibdata)  AliFatal("Wrong calibration object in calibration  file!");
 
   return calibdata;
 }
 
+//_____________________________________________________________________________
+AliZDCCalib* AliZDCDigitizer::GetCalibData() const
+{
+
+  // Getting calibration object for ZDC set
+
+  AliCDBEntry  *entry = AliCDBManager::Instance()->Get("ZDC/Calib/EMDCalib");
+  if(!entry) AliFatal("No calibration data loaded!");  
+
+  AliZDCCalib *calibdata = dynamic_cast<AliZDCCalib*>  (entry->GetObject());
+  if(!calibdata)  AliFatal("Wrong calibration object in calibration  file!");
+
+  return calibdata;
+}