PMD calibration classes
authorbnandi <bnandi@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 14 Mar 2006 15:34:09 +0000 (15:34 +0000)
committerbnandi <bnandi@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 14 Mar 2006 15:34:09 +0000 (15:34 +0000)
PMD/AliPMDCalibData.cxx [new file with mode: 0644]
PMD/AliPMDCalibData.h [new file with mode: 0644]
PMD/AliPMDCalibrator.cxx [new file with mode: 0644]
PMD/AliPMDCalibrator.h [new file with mode: 0644]

diff --git a/PMD/AliPMDCalibData.cxx b/PMD/AliPMDCalibData.cxx
new file mode 100644 (file)
index 0000000..940a23d
--- /dev/null
@@ -0,0 +1,126 @@
+/***************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+//
+// Author : Z. Ahmed
+//
+#include "TNamed.h"
+#include "AliCDBEntry.h"
+#include "AliPMD.h"
+#include "AliPMDCalibData.h"
+
+
+ClassImp(AliPMDCalibData)
+
+AliPMDCalibData::AliPMDCalibData()
+{
+  // Default constructor
+  Reset();
+}
+// ----------------------------------------------------------------- //
+AliPMDCalibData::AliPMDCalibData(const char* name)
+{
+  //constructor
+  TString namst = "Calib_";
+  namst += name;
+  SetName(namst.Data());
+  SetTitle(namst.Data());
+  Reset();
+  
+}
+// ----------------------------------------------------------------- //
+AliPMDCalibData::AliPMDCalibData(const AliPMDCalibData& calibda) :
+  TNamed(calibda)
+{
+  // copy constructor
+  SetName(calibda.GetName());
+  SetTitle(calibda.GetName());
+  Reset();
+  for(Int_t det=0;det<2;det++){
+    for(Int_t smn=0;smn<24;smn++) {
+      for(Int_t row=0;row<96;row++) {
+       for(Int_t col=0;col<96;col++) {
+         fGainFact[det][smn][row][col]=calibda.GetGainFact(det,smn,row,col);
+       }
+      }
+    }
+  }
+}
+// ----------------------------------------------------------------- //
+AliPMDCalibData &AliPMDCalibData::operator =(const AliPMDCalibData& calibda)
+{
+  //asignment operator
+  SetName(calibda.GetName());
+  SetTitle(calibda.GetName());
+  Reset();
+  for(Int_t det=0;det<2;det++){
+    for(Int_t smn=0;smn<24;smn++) {
+      for(Int_t row=0;row<96;row++) {
+       for(Int_t col=0;col<96;col++) {
+         fGainFact[det][smn][row][col]=calibda.GetGainFact(det,smn,row,col);
+       }
+      }
+    }
+  }
+  return *this;
+}
+// ----------------------------------------------------------------- //
+AliPMDCalibData::~AliPMDCalibData()
+{
+  //destructor
+}
+// ----------------------------------------------------------------- //
+void AliPMDCalibData::Reset()
+{
+  //memset(fgainfact ,1,2*24*96*96*sizeof(Float_t));
+  for(Int_t det=0;det<2;det++){
+    for(Int_t smn=0;smn<24;smn++) {
+      for(Int_t row=0;row<96;row++) {
+       for(Int_t col=0;col<96;col++) {
+         fGainFact[det][smn][row][col]=1.0;
+       }
+      }
+    }
+  }
+}
+// ----------------------------------------------------------------- //
+Float_t AliPMDCalibData:: GetGainFact(Int_t det, Int_t smn, Int_t row, Int_t col) const
+{
+  return fGainFact[det][smn][row][col];
+}
+// ----------------------------------------------------------------- //
+void AliPMDCalibData::SetGainFact(Int_t det, Int_t smn, Int_t row, Int_t col, Float_t gain)
+{
+  fGainFact[det][smn][row][col]= gain;
+}
+
+// ----------------------------------------------------------------- //
+void AliPMDCalibData::Print(Option_t *) const
+{
+  printf("\n ######gain factors for each cells are ####\n");
+  for(Int_t det=0;det<2;det++)
+    {
+      for(Int_t smn=0;smn<24;smn++)
+       {
+         for(Int_t row=0;row<96;row++)
+           {
+             for(Int_t col=0;col<96; col++)
+               {
+                 printf("%4.1f",fGainFact[det][smn][row][col]);
+               }
+             printf("\n");
+           }
+       }
+    }
+}
diff --git a/PMD/AliPMDCalibData.h b/PMD/AliPMDCalibData.h
new file mode 100644 (file)
index 0000000..ebb47d2
--- /dev/null
@@ -0,0 +1,31 @@
+#ifndef ALIPMDCALIBDATA_H
+#define ALIPMDCALIBDATA_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+
+class TNamed;
+class AliCDBEntry;
+class AliPMD;
+
+class AliPMDCalibData: public TNamed
+{
+ public:
+  AliPMDCalibData();
+  AliPMDCalibData(const char* name);
+  AliPMDCalibData(const AliPMDCalibData &calibda);
+  AliPMDCalibData& operator= (const AliPMDCalibData &calibda);
+  virtual ~AliPMDCalibData();
+  void    Reset();
+  void    SetGainFact(Int_t det, Int_t smn, Int_t row, Int_t col,
+                     Float_t gain);
+  Float_t GetGainFact(Int_t det, Int_t smn, Int_t row, Int_t col) const;
+  virtual void Print(Option_t *) const;
+  
+ protected:
+  
+  Float_t fGainFact[2][24][96][96];
+
+  ClassDef(AliPMDCalibData,1) // calibration class for gainfactors
+};
+#endif
diff --git a/PMD/AliPMDCalibrator.cxx b/PMD/AliPMDCalibrator.cxx
new file mode 100644 (file)
index 0000000..1d3857c
--- /dev/null
@@ -0,0 +1,269 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+// *                                                                        *
+// * Author: The ALICE Off-line Project.                                    *
+// * Contributors are mentioned in the code where appropriate.             *
+// *                                                                       *
+// * Permission to use, copy, modify and distribute this software and its   *
+// * documentation strictly for non-commercial purposes is hereby granted   *
+// * without fee, provided that the above copyright notice appears in all   *
+// * copies and that both the copyright notice and this permission notice   *
+// * appear in the supporting documentation. The authors make no claims     *
+// * about the suitability of this software for any purpose. It is         *
+// * provided "as is" without express or implied warranty.                 *
+// **************************************************************************/
+//
+//////////////////////////////////////////////////////////////////////////////
+// Author : Z. Ahamed
+
+#include "TF1.h"
+#include "TFile.h"
+#include "TObjString.h"
+#include "TROOT.h"
+#include "TClonesArray.h"
+#include "TH1F.h"
+
+// --- Standard library ---
+
+// --- AliRoot header files ---
+#include "AliLog.h"
+#include "AliPMDCalibrator.h"
+#include "AliRawReaderDate.h"
+#include "AliPMDRawStream.h"
+#include "AliRawReaderFile.h"
+#include "AliPMDCalibData.h"
+#include "AliCDBManager.h"
+#include "AliCDBId.h"
+#include "AliCDBMetaData.h"
+
+ClassImp(AliPMDCalibrator)
+
+const Int_t kDet =2;
+const Int_t kMaxSMN = 24;
+const Int_t kMaxRow =96;
+const Int_t kMaxCol =96;
+
+AliPMDCalibrator::AliPMDCalibrator()
+{
+  // Standard Constructor
+
+  fCalibData = new AliPMDCalibData();
+  
+  for(Int_t d=0;d<2;d++)
+    {
+      for(Int_t i=0;i<24;i++)
+       {
+         fHsmIso[d][i] = NULL ;
+         for(Int_t j=0;j<96;j++)
+           {
+             for(Int_t k=0;k<96;k++)
+               {
+                 fGainFact[d][i][j][k] = 0.0;
+                 fHadcIso[d][i][j][k]  = NULL;
+               }
+           }
+       }
+    }
+}
+// ------------------------------------------------------------------------ //
+
+AliPMDCalibrator::~AliPMDCalibrator()
+{
+  // dtor
+  if(fHsmIso)  delete fHsmIso ;
+  if(fHadcIso) delete fHadcIso ;
+  delete fCalibData;
+}
+// ------------------------------------------------------------------------ //
+
+void AliPMDCalibrator::Exec()
+{
+  // reads parameters and does the calibration
+  CalculateIsoCell() ;
+
+}
+// ------------------------------------------------------------------------ //
+
+void AliPMDCalibrator::Init()
+{
+  // intializes everything
+  char hname[kMaxSMN];
+  char hname24[kMaxSMN];
+  char hnameiso[120];
+  char htitle1[120];
+
+  for(Int_t d=0;d<2;d++) {
+    for(Int_t i1=0; i1<kMaxSMN;i1++) {
+      sprintf(hname,"det_%d_iso_sm_%2d",d,i1);
+      sprintf(hname24,"det_%d_iso_sm_%2d",d,i1);
+      fHsmIso[d][i1]= new TH1F(hname,hname24,100,0,1000);
+      for(Int_t j1 = 0; j1 < kMaxRow; j1++) {
+       for(Int_t k1 = 0; k1 < kMaxCol; k1++) {
+         sprintf(hnameiso,"Isolated Cell ADC for det_%d_cell_sm%d_row%d_col%d"
+                 ,d,i1,j1,k1);
+         sprintf(htitle1,"Isolated Cell ADC for det_%d_cell_sm%d_row%d_col%d"
+                 ,d,i1,j1,k1);
+         
+         TObject *old=gDirectory->GetList()->FindObject(hnameiso);
+         if (old) gDirectory->GetList()->Remove(old);
+         fHadcIso[d][i1][j1][k1] = new TH1F(hnameiso,htitle1,100,0.,4000.);
+       }
+      }
+    }
+  }
+  
+}
+
+// ------------------------------------------------------------------------ //
+
+void AliPMDCalibrator::CalculateIsoCell()
+{
+  // Calculates the ADC of isolated cell
+
+  const Int_t kMaxHit        = 60000;
+  const Int_t kCellNeighbour = 6;
+
+  Int_t neibx[6] = {1,0,-1,-1,0,1};
+  Int_t neiby[6] = {0,1,1,0,-1,-1};
+  
+  Int_t id1,jd1; //neighbour row/col
+  Int_t countisocell = 0 ;//number of isilated cell
+  Int_t isocount; //number of neighbours with 0 signal
+  Int_t d1[kDet][kMaxSMN][kMaxRow][kMaxCol];
+  Int_t ch[kDet][kMaxSMN][kMaxRow][kMaxCol];
+  Int_t maxhit;
+  
+  
+  Int_t det[kMaxHit],smn[kMaxHit];
+  Int_t row[kMaxHit],col[kMaxHit],sig[kMaxHit],chno[kMaxHit];
+
+  for(Int_t idet = 0; idet < kDet; idet++)
+    {
+      for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
+        {
+          for(Int_t irow = 0; irow < kMaxRow; irow++)
+            {
+              for(Int_t icol = 0; icol < kMaxCol; icol++)
+                {
+                  d1[idet][ismn][irow][icol] = 0;
+                  ch[idet][ismn][irow][icol] = 0;
+                }
+           }
+       }
+    }
+  //accessing raw data
+  AliRawReaderFile reader(".");
+  AliPMDRawStream stream(&reader);
+  while(reader.NextEvent())
+    {
+      // printf("In CalculateIsoCell before while(stream.Next()), ...\n");
+      
+      while(stream.Next())
+       {
+         Int_t idet = stream.GetDetector();
+         Int_t ismn = stream.GetSMN();
+         Int_t ichno = stream.GetChannel();
+         Int_t irow = stream.GetRow();
+         Int_t icol = stream.GetColumn();
+         Int_t isig = stream.GetSignal();
+         
+         if (isig>0)
+           {
+             d1[idet][ismn][irow][icol] = isig;
+             ch[idet][ismn][irow][icol] = ichno;
+           }
+       }
+      
+      maxhit = 0;
+      
+      for(Int_t idet=0; idet < kDet; idet++)
+       {
+         for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
+           {
+             for(Int_t irow = 0; irow < kMaxRow; irow++)
+               {
+                 for(Int_t icol = 0; icol < kMaxCol; icol++)
+                   {
+                     
+                     //printf("d1[%d][%d][%d][%d]=%d\n",
+                     //det,ksmn,irow,jcol, d1[det][ksmn][irow][jcol] ); 
+                     //printf("ch[%d][%d][%d][%d]=%d\n",
+                     //det,ksmn,irow,jcol, ch[det][ksmn][irow][jcol] ); 
+                     
+                     if(d1[idet][ismn][irow][icol] > 0)
+                       {
+                         isocount = 0;
+                         for(Int_t ii = 0; ii < kCellNeighbour; ii++)
+                           {
+                             id1 = irow + neibx[ii];
+                             jd1 = icol + neiby[ii];
+                             if(d1[idet][ismn][id1][jd1] == 0)
+                               {
+                                 isocount++;
+                                 if(isocount == kCellNeighbour)
+                                   {
+                                     countisocell++;
+                                     det[maxhit]  = idet;
+                                     smn[maxhit]  = ismn;
+                                     row[maxhit]  = irow;
+                                     col[maxhit]  = icol;
+                                     sig[maxhit]  = d1[idet][ismn][irow][icol];
+                                     chno[maxhit] = ch[idet][ismn][irow][icol];
+                                     maxhit++;
+                                     fHsmIso[idet][ismn]->Fill(d1[idet][ismn][irow][icol]);
+                                     fHadcIso[idet][ismn][irow][icol]->Fill(d1[idet][ismn][irow][icol]);
+                                   }
+                               }
+                           }  // neigh cell cond.
+                       }     // d>0 cond.
+                   }
+               }
+           }
+       } //event loop
+    }
+  Double_t histMean[2][24];
+  Double_t isoMean[2][24][96][96];
+  for(Int_t d1=0;d1<2;d1++)
+    {
+      for(Int_t i1=0;i1<24;i1++)
+       {
+         histMean[d1][i1]= fHsmIso[d1][i1]->GetMean();
+         for(Int_t j1=0;j1<96;j1++)
+           {
+             for(Int_t k1=0;k1<96;k1++)
+               {
+                 isoMean[d1][i1][j1][k1]=fHadcIso[d1][i1][j1][k1]->GetMean();
+                 if(isoMean[d1][i1][j1][k1]>0.0 && histMean[d1][i1]>0.0)
+                   {
+                     fGainFact[d1][i1][j1][k1]=isoMean[d1][i1][k1][j1]/histMean[d1][i1];
+                     float_t gain=fGainFact[d1][i1][j1][k1];
+                     fCalibData->SetGainFact(d1,i1,j1,k1,gain);
+                   }                              
+               }
+           }
+       }
+    }
+  
+}
+// ------------------------------------------------------------------------ //
+Bool_t AliPMDCalibrator::Store()
+{
+  AliCDBManager *man = AliCDBManager::Instance();
+  man->SetDefaultStorage("local://$ALICE_ROOT");
+  AliCDBId id("PMD/Calib/Data",0,0);
+  AliCDBMetaData md;
+  md.SetResponsible("Zubayer");
+  md.SetBeamPeriod(0);
+  md.SetAliRootVersion("28.02.2006");
+  md.SetComment("Test");
+  
+  printf("\n\n\n fCalibData\n");
+  //fCalibData->Print(0);
+  //printf("\n\n\n fCalibData\n");
+  
+  Bool_t result = man->Put(fCalibData,id,&md);
+
+  return result;
+}
+
diff --git a/PMD/AliPMDCalibrator.h b/PMD/AliPMDCalibrator.h
new file mode 100644 (file)
index 0000000..81e0077
--- /dev/null
@@ -0,0 +1,30 @@
+#ifndef ALIPMDCALIBRATOR_H
+#define ALIPMDCALIBRATOR_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+class TTask;
+class TObjArray;
+class TH1F;  
+
+class AliPMDCalibData;
+
+class AliPMDCalibrator
+{
+ public:
+  AliPMDCalibrator() ;              // ctor
+  virtual ~AliPMDCalibrator() ;     // dtor
+  virtual void Exec();
+  void CalculateIsoCell();          //calculates gains
+  void Init();
+  Bool_t Store();
+  
+ private:
+  Float_t fGainFact[2][24][96][96];
+  TH1F *fHsmIso[2][24];             //histos of isolated cell modulewise
+  TH1F *fHadcIso[2][24][96][96];    // histos of isolated cells cellwise
+  AliPMDCalibData *fCalibData;
+
+ClassDef(AliPMDCalibrator,1)        // description 
+};
+#endif // AliPMDCALIBRATOR_H