]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PMD/AliPMDRawToSDigits.cxx
solution of the problem: the BC id of the event header does not match the one from...
[u/mrichter/AliRoot.git] / PMD / AliPMDRawToSDigits.cxx
index a8661562a5fe80fcd315073d73bdd35e97fb9076..3dd99bce2d1ee38ec32fa4f9e47b416a367d33c5 100644 (file)
@@ -95,7 +95,7 @@ AliPMDRawToSDigits::~AliPMDRawToSDigits()
 
 void AliPMDRawToSDigits::Raw2SDigits(AliRunLoader *runLoader, AliRawReader *rawReader)
 {
-  // Converts RAW data to digits
+  // Converts RAW data to sdigits
   //
   TObjArray pmdddlcont;
   AliLoader *pmdLoader = runLoader->GetLoader("PMDLoader");
@@ -110,49 +110,37 @@ void AliPMDRawToSDigits::Raw2SDigits(AliRunLoader *runLoader, AliRawReader *rawR
   if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
   treeS->Branch("PMDSDigit", &fSDigits, bufsize); 
 
-  const Int_t kDDL = AliDAQ::NumberOfDdls("PMD");
+//  const Int_t kDDL = AliDAQ::NumberOfDdls("PMD");
   const Int_t kRow = 48;
   const Int_t kCol = 96;
+  const Int_t kSMN = 48;
 
   Int_t idet = 0;
-  Int_t iSMN = 0;
   Int_t indexsmn = 0;
-
-  for (Int_t indexDDL = 0; indexDDL < kDDL; indexDDL++)
+  Int_t ismn = 0;
+  
+  Int_t ***precpvADC;
+  precpvADC = new int **[kSMN];
+  for (Int_t i=0; i<kSMN; i++) precpvADC[i] = new int *[kRow];
+  for (Int_t i=0; i<kSMN;i++)
     {
-
-      if (indexDDL < 4)
-       {
-         iSMN = 6;
-       }
-      else if (indexDDL >= 4)
-       {
-         iSMN = 12;
-       }
-      Int_t ***precpvADC;
-      precpvADC = new int **[iSMN];
-      for (Int_t i=0; i<iSMN; i++) precpvADC[i] = new int *[kRow];
-      for (Int_t i=0; i<iSMN;i++)
-       {
-         for (Int_t j=0; j<kRow; j++) precpvADC[i][j] = new int [kCol];
-       }
-      for (Int_t i = 0; i < iSMN; i++)
+      for (Int_t j=0; j<kRow; j++) precpvADC[i][j] = new int [kCol];
+    }
+  for (Int_t i = 0; i < kSMN; i++)
+    {
+      for (Int_t j = 0; j < kRow; j++)
        {
-         for (Int_t j = 0; j < kRow; j++)
+         for (Int_t k = 0; k < kCol; k++)
            {
-             for (Int_t k = 0; k < kCol; k++)
-               {
-                 precpvADC[i][j][k] = 0;
-               }
+             precpvADC[i][j][k] = 0;
            }
        }
-      
-      rawReader->Reset();
-      AliPMDRawStream pmdinput(rawReader);
-      rawReader->Select("PMD", indexDDL, indexDDL);
-      
-      pmdinput.DdlData(indexDDL,&pmdddlcont);
-      
+    }
+  
+  AliPMDRawStream pmdinput(rawReader);
+  Int_t indexDDL = -1;
+  while ((indexDDL = pmdinput.DdlData(&pmdddlcont)) >=0)
+  {
       Int_t ientries = pmdddlcont.GetEntries();
       for (Int_t ient = 0; ient < ientries; ient++)
        {
@@ -166,106 +154,82 @@ void AliPMDRawToSDigits::Raw2SDigits(AliRunLoader *runLoader, AliRawReader *rawR
          Int_t col = pmdddl->GetColumn();
          Int_t sig = pmdddl->GetSignal();
          
-         
          if (indexDDL < 4)
            {
              if (det != 0)
                AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
                              indexDDL, det));
-             indexsmn = smn - indexDDL * 6;
+             indexsmn = smn;
            }
-         else if (indexDDL == 4)
+         else if (indexDDL == 4 || indexDDL == 5)
            {
              if (det != 1)
                AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
                              indexDDL, det));
-             if (smn < 6)
-               {
-                 indexsmn = smn;
-               }
-             else if (smn >= 18 && smn < 24)
-               {
-                 indexsmn = smn - 12;
-               }
+             indexsmn = smn + 24;
            }
-         else if (indexDDL == 5)
-           {
-             if (det != 1)
-               AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
-                             indexDDL, det));
-             if (smn >= 6 && smn < 12)
-               {
-                 indexsmn = smn - 6;
-               }
-             else if (smn >= 12 && smn < 18)
-               {
-                 indexsmn = smn - 6;
-               }
-           }         
+
          precpvADC[indexsmn][row][col] = sig;
        }
       
       pmdddlcont.Clear();
       
-      // Add the sdigits here
+    } // DDL Loop
+      
+  // Add the sdigits here
+  
+  for ( indexsmn = 0; indexsmn < kSMN; indexsmn++)
+    {
 
-      Int_t ismn = 0;
-      for (Int_t indexsmn = 0; indexsmn < iSMN; indexsmn++)
+      if (indexsmn < 23)
        {
-         if (indexDDL < 4)
-           {
-             ismn = indexsmn + indexDDL * 6;
-             idet = 0;
-           }
-         else if (indexDDL == 4)
-           {
-             if (indexsmn < 6)
-               {
-                 ismn = indexsmn;
-               }
-             else if (indexsmn >= 6 && indexsmn < 12)
-               {
-                 ismn = indexsmn + 12;
-               }
-             idet = 1;
-           }
-         else if (indexDDL == 5)
+         idet = 0;
+         ismn = indexsmn;
+       }
+      else if (indexsmn > 23)
+       {
+         idet = 0;
+         ismn = indexsmn - 24;
+       }
+      for (Int_t irow = 0; irow < kRow; irow++)
+       {
+         for (Int_t icol = 0; icol < kCol; icol++)
            {
-             if (indexsmn < 6)
-               {
-                 ismn = indexsmn + 6;
-               }
-             else if (indexsmn >= 6 && indexsmn < 12)
-               {
-                 ismn = indexsmn + 6;
-               }
-             idet = 1;
-           }
 
-         for (Int_t irow = 0; irow < kRow; irow++)
-           {
-             for (Int_t icol = 0; icol < kCol; icol++)
+             Int_t trno  = -99999;   // when extracted from raw data
+             Int_t trpid = -99999;   // when extracted from raw data
+             Int_t sig1  = precpvADC[indexsmn][irow][icol];
+             
+             // plug in a function to convert to adc to MeV
+             Float_t edep = 0.;
+             if (sig1 > 0)
                {
-
-                 Int_t trno = -99999;
-                 Int_t sig1 = precpvADC[indexsmn][irow][icol];
-                 
-                 // plug in a function to convert to adc to MeV
-                 Float_t edep = 0.;
-                 if (sig1 > 0)
-                   {
-                     AdcToMeV(sig1,edep);
-                     AddSDigit(trno,idet,ismn,irow,icol,edep);
-                   }
-               } // row
-           }     // col
-
-         treeS->Fill();
-         ResetSDigit();
-       }         
-    } // DDL Loop
+                 AdcToMeV(sig1,edep);
+                 AddSDigit(trno,trpid,idet,ismn,irow,icol,edep);
+               }
+           } // row
+       }     // col
+      
+      treeS->Fill();
+      ResetSDigit();
+    }
 
   pmdLoader->WriteSDigits("OVERWRITE");
+
+  // Delete all the pointers
+  
+  for (Int_t i = 0; i < kSMN; i++)
+    {
+      for (Int_t j = 0; j < kRow; j++)
+       {
+         delete [] precpvADC[i][j];
+       }
+    }
+  for (Int_t j = 0; j < kSMN; j++)
+    {
+      delete [] precpvADC[j];
+    }
+  delete [] precpvADC;
   
 }
 // ------------------------------------------------------------------------- //
@@ -274,7 +238,7 @@ void AliPMDRawToSDigits::Raw2Digits(AliRunLoader *runLoader, AliRawReader *rawRe
   // Converts RAW data to digits
   //
   TObjArray pmdddlcont;
-
+  
   AliLoader *pmdLoader = runLoader->GetLoader("PMDLoader");
   
   TTree* treeD = pmdLoader->TreeD();
@@ -286,52 +250,38 @@ void AliPMDRawToSDigits::Raw2Digits(AliRunLoader *runLoader, AliRawReader *rawRe
   Int_t bufsize = 16000;
   if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
   treeD->Branch("PMDDigit", &fDigits, bufsize); 
-
-  const Int_t kDDL = AliDAQ::NumberOfDdls("PMD");
+  
+//  const Int_t kDDL = AliDAQ::NumberOfDdls("PMD");
   const Int_t kRow = 48;
   const Int_t kCol = 96;
-
+  const Int_t kSMN = 48;
+  
   Int_t idet = 0;
-  Int_t iSMN = 0;
+  Int_t ismn = 0;
   Int_t indexsmn = 0;
-
-  for (Int_t indexDDL = 0; indexDDL < kDDL; indexDDL++)
+  
+  Int_t ***precpvADC;
+  precpvADC = new int **[kSMN];
+  for (Int_t i=0; i<kSMN; i++) precpvADC[i] = new int *[kRow];
+  for (Int_t i=0; i<kSMN;i++)
     {
-
-      if (indexDDL < 4)
-       {
-         iSMN = 6;
-       }
-      else if (indexDDL >= 4)
-       {
-         iSMN = 12;
-       }
-      Int_t ***precpvADC;
-      precpvADC = new int **[iSMN];
-      for (Int_t i=0; i<iSMN; i++) precpvADC[i] = new int *[kRow];
-      for (Int_t i=0; i<iSMN;i++)
-       {
-         for (Int_t j=0; j<kRow; j++) precpvADC[i][j] = new int [kCol];
-       }
-      for (Int_t i = 0; i < iSMN; i++)
+      for (Int_t j=0; j<kRow; j++) precpvADC[i][j] = new int [kCol];
+    }
+  for (Int_t i = 0; i < kSMN; i++)
+    {
+      for (Int_t j = 0; j < kRow; j++)
        {
-         for (Int_t j = 0; j < kRow; j++)
+         for (Int_t k = 0; k < kCol; k++)
            {
-             for (Int_t k = 0; k < kCol; k++)
-               {
-                 precpvADC[i][j][k] = 0;
-               }
+             precpvADC[i][j][k] = 0;
            }
        }
-      
-      rawReader->Reset();
-      AliPMDRawStream pmdinput(rawReader);
-      rawReader->Select("PMD", indexDDL, indexDDL);
-      
-      //pmdinput.DdlData(&pmdddlcont);
-      pmdinput.DdlData(indexDDL,&pmdddlcont);
-      
-      
+    }
+
+  AliPMDRawStream pmdinput(rawReader);
+  Int_t indexDDL = -1;
+  while ((indexDDL = pmdinput.DdlData(&pmdddlcont)) >=0)
+  {
       Int_t ientries = pmdddlcont.GetEntries();
       for (Int_t ient = 0; ient < ientries; ient++)
        {
@@ -351,137 +301,105 @@ void AliPMDRawToSDigits::Raw2Digits(AliRunLoader *runLoader, AliRawReader *rawRe
              if (det != 0)
                AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
                              indexDDL, det));
-             indexsmn = smn - indexDDL * 6;
+             indexsmn = smn ;
            }
-         else if (indexDDL == 4)
+         else if (indexDDL == 4 || indexDDL == 5)
            {
              if (det != 1)
                AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
                              indexDDL, det));
-             if (smn < 6)
-               {
-                 indexsmn = smn;
-               }
-             else if (smn >= 18 && smn < 24)
-               {
-                 indexsmn = smn - 12;
-               }
-           }
-         else if (indexDDL == 5)
-           {
-             if (det != 1)
-               AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
-                             indexDDL, det));
-             if (smn >= 6 && smn < 12)
-               {
-                 indexsmn = smn - 6;
-               }
-             else if (smn >= 12 && smn < 18)
-               {
-                 indexsmn = smn - 6;
-               }
+             indexsmn = smn + 24;
            }         
          precpvADC[indexsmn][row][col] = sig;
        }
       
       pmdddlcont.Clear();
+    } // DDL Loop  
       
-      // Add the digits here
-      
-      Int_t ismn = 0;
-      for (Int_t indexsmn = 0; indexsmn < iSMN; indexsmn++)
+  // Add the digits here
+  for (indexsmn = 0; indexsmn < kSMN; indexsmn++)
+    {
+      if (indexsmn < 23)
        {
-         if (indexDDL < 4)
-           {
-             ismn = indexsmn + indexDDL * 6;
-             idet = 0;
-           }
-         else if (indexDDL == 4)
-           {
-             if (indexsmn < 6)
-               {
-                 ismn = indexsmn;
-               }
-             else if (indexsmn >= 6 && indexsmn < 12)
-               {
-                 ismn = indexsmn + 12;
-               }
-             idet = 1;
-           }
-         else if (indexDDL == 5)
+         ismn = indexsmn;
+         idet = 0;
+       }
+      else if (indexsmn > 23)
+       {
+         ismn = indexsmn -24;
+         idet = 1;
+       }
+      for (Int_t irow = 0; irow < kRow; irow++)
+       {
+         for (Int_t icol = 0; icol < kCol; icol++)
            {
-             if (indexsmn < 6)
+             Int_t trno  = -99999;    // when extracted from raw
+             Int_t trpid = -99999;    // when extracted from raw
+             Int_t sig1  = precpvADC[indexsmn][irow][icol];
+             
+             // plug in a function to convert to adc to MeV
+             if (sig1 > 0)
                {
-                 ismn = indexsmn + 6;
+                 AddDigit(trno,trpid,idet,ismn,irow,icol,sig1);
                }
-             else if (indexsmn >= 6 && indexsmn < 12)
-               {
-                 ismn = indexsmn + 6;
-               }
-             idet = 1;
-           }
-
-         for (Int_t irow = 0; irow < kRow; irow++)
-           {
-             for (Int_t icol = 0; icol < kCol; icol++)
-               {
-                 Int_t trno = -99999;
-                 Int_t sig1 = precpvADC[indexsmn][irow][icol];
-                 
-                 // plug in a function to convert to adc to MeV
-                 if (sig1 > 0)
-                   {
-                     AddDigit(trno,idet,ismn,irow,icol,sig1);
-                   }
-               } // row
-           }     // col
-         treeD->Fill();
-         ResetDigit();
-       }         
-         
-    } // DDL Loop
+           } // row
+       }     // col
+      treeD->Fill();
+      ResetDigit();
+    }    
   
   pmdLoader->WriteDigits("OVERWRITE");
 
+  // Delete all the pointers
+
+  for (Int_t i = 0; i < kSMN; i++)
+    {
+      for (Int_t j = 0; j < kRow; j++)
+       {
+         delete [] precpvADC[i][j];
+       }
+    }
+  for (Int_t j = 0; j < kSMN; j++)
+    {
+      delete [] precpvADC[j];
+    }
+  delete [] precpvADC;
 }
 // ------------------------------------------------------------------------- //
 
 void AliPMDRawToSDigits::AdcToMeV(Int_t adc, Float_t &edep)
 {
-  // To be implemented, this is just for the test
-
-  const Float_t kConstant   = 7.181;
-  //  const Float_t kErConstant = 0.6899;
-  const Float_t kSlope      = 35.93;
-  //  const Float_t kErSlope    = 0.306;
-
+  // These constants are from Test Beam 2010
 
+  const Float_t kConstant   = 0.612796;
+  const Float_t kSlope      = 130.158;
 
-  Float_t adc10bit = (Float_t) adc/4;
-  edep     = (1000.0/kSlope)*(adc10bit - kConstant);
+  edep     = (1000.0/kSlope)*(adc - kConstant);
 }
 
 // ------------------------------------------------------------------------- //
 
-void AliPMDRawToSDigits::AddSDigit(Int_t trnumber, Int_t det, Int_t smnumber, 
+void AliPMDRawToSDigits::AddSDigit(Int_t trnumber, Int_t trpid, Int_t det,
+                                  Int_t smnumber, 
                                   Int_t irow, Int_t icol, Float_t adc)
 {
   // Add SDigit
   //
   if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
   TClonesArray &lsdigits = *fSDigits;
-  new(lsdigits[fNsdigit++]) AliPMDsdigit(trnumber,det,smnumber,irow,icol,adc);
+  new(lsdigits[fNsdigit++]) AliPMDsdigit(trnumber,trpid,det,smnumber,irow,icol,adc);
 }
 
 // ------------------------------------------------------------------------- //
-void AliPMDRawToSDigits::AddDigit(Int_t trnumber, Int_t det, Int_t smnumber, 
+void AliPMDRawToSDigits::AddDigit(Int_t trnumber, Int_t trpid, Int_t det,
+                                 Int_t smnumber, 
                                  Int_t irow, Int_t icol, Float_t adc)
 {
   // Add Digit
   //
   if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
   TClonesArray &ldigits = *fDigits;
-  new(ldigits[fNdigit++]) AliPMDdigit(trnumber,det,smnumber,irow,icol,adc);
+  new(ldigits[fNdigit++]) AliPMDdigit(trnumber,trpid,det,smnumber,irow,icol,adc);
 }
 
 // ------------------------------------------------------------------------- //