Classes for ZDC calibration (by A. Colla)
authorcoppedis <coppedis@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 31 Mar 2005 07:35:47 +0000 (07:35 +0000)
committercoppedis <coppedis@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 31 Mar 2005 07:35:47 +0000 (07:35 +0000)
ZDC/AliZDC.cxx
ZDC/AliZDC.h
ZDC/AliZDCCalibData.cxx [new file with mode: 0644]
ZDC/AliZDCCalibData.h [new file with mode: 0644]

index aac2849..38c5c24 100644 (file)
@@ -29,6 +29,8 @@
 #include <TGeometry.h>
 #include <TNode.h>
 #include <TTree.h>
+#include <TFile.h>
+#include <TSystem.h>
 
 // --- AliRoot header files
 #include "AliDetector.h"
@@ -38,6 +40,7 @@
 #include "AliZDCDigit.h"
 #include "AliZDCDigitizer.h"
 #include "AliZDCRawStream.h"
+#include "AliZDCCalibData.h"
 
 #include "AliRawDataHeader.h"
 #include "AliLoader.h"
@@ -46,6 +49,8 @@
 
  
 ClassImp(AliZDC)
+
+AliZDC *gZDC;
  
 //_____________________________________________________________________________
 AliZDC::AliZDC()
@@ -79,9 +84,16 @@ AliZDC::AliZDC(const char *name, const char *title)
   // Allocate the hits array  
   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);
 
   fDigits     = 0;
   fNdigits    = 0;
+  
+  gZDC=this;
 
 }
 //____________________________________________________________________________ 
@@ -92,6 +104,7 @@ AliZDC::~AliZDC()
   //
 
   fIshunt   = 0;
+  gZDC=0;
 
 }
 //_____________________________________________________________________________
@@ -449,3 +462,68 @@ void AliZDC::SetTreeAddress(){
   AliDetector::SetTreeAddress();
 }
  
+//Calibration methods (by Alberto Colla)
+//________________________________________________________________
+void AliZDC::CreateCalibData()
+{
+  // 
+  //if (fCalibData) delete fCalibData; // delete previous version
+  fCalibData = new AliZDCCalibData(GetName());
+}
+//________________________________________________________________
+void AliZDC::WriteCalibData(Int_t option)
+{
+  //
+  const int kCompressLevel = 9;
+  const char defname[] = "$(ALICE)/AliRoot/data/AliZDCCalib.root";
+  char* fnam = gAlice->GetZDCCalibFName();
+  if (!fnam || fnam[0]=='\0') {
+    fnam = gSystem->ExpandPathName(defname);
+    Warning("WriteCalibData","No File Name is provided, using default %s",fnam);
+  }
+  TFile* cdfile = TFile::Open(fnam,"UPDATE","",kCompressLevel);
+
+  // Writes Calibration Data to current directory. 
+  // User MUST take care of corresponding file opening and ->cd()... !!!
+  // By default, the object is overwritten. Use 0 option for opposite.
+  if (option) option = TObject::kOverwrite;
+  if (fCalibData) fCalibData->Write(0,option);
+  else if (fCalibData) fCalibData->Write(0,option);
+
+  cdfile->Close();
+  delete cdfile;
+}
+
+//________________________________________________________________
+void AliZDC::LoadCalibData()
+{
+  //
+  char* fnam = gAlice->GetZDCCalibFName();
+  if (!fnam || fnam[0]=='\0') return; 
+  if (!gAlice->IsFileAccessible(fnam)) {
+    Error("LoadCalibData","ZDC Calibration Data file is not accessible, %s",fnam);
+    exit(1);
+  }
+  TFile* cdfile = TFile::Open(fnam);
+
+  // Loads Calibration Data from current directory. 
+  // User MUST take care of corresponding file opening and ->cd()...!!!
+  //
+  if (fCalibData) delete fCalibData; // delete previous version
+  TString dtname = "Calib_";
+  dtname += GetName();
+  fCalibData = (AliZDCCalibData*) gDirectory->Get(dtname.Data());
+  if (!fCalibData) { 
+    Error("LoadCalibData","No Calibration data found for %s",GetName());
+    exit(1);
+  }
+
+  cdfile->Close();
+  delete cdfile;
+}
+
+
+//Calibration methods (by Alberto Colla)
index 7174765..2f204e1 100644 (file)
@@ -10,6 +10,8 @@
 ////////////////////////////////////////////////
 
 #include "AliDetector.h"
+
+class AliZDCCalibData;
  
 class AliZDC : public AliDetector {
 
@@ -36,11 +38,27 @@ public:
   void  NoShower(){fNoShower=1;}
   void  Shower()  {fNoShower=0;}
 
+
+//Calibration methods (by Alberto Colla)
+  void          CreateCalibData();
+  void          WriteCalibData(Int_t option=TObject::kOverwrite);
+  void          LoadCalibData();
+  void          SetCalibData(AliZDCCalibData* data) {fCalibData = data;}
+  AliZDCCalibData* GetCalibData() const  {return fCalibData;}
+//Calibration methods (by Alberto Colla)
+
+
 protected:
 
   Int_t        fNoShower;      // Flag to switch off the shower        
+
+//Calibration methods (by Alberto Colla)
+  AliZDCCalibData* fCalibData; // Calibration data for ZDC
+//Calibration methods (by Alberto Colla)
   
   ClassDef(AliZDC,4)   // Zero Degree Calorimeter base class
 };
  
+R__EXTERN  AliZDC *gZDC;
+
 #endif
diff --git a/ZDC/AliZDCCalibData.cxx b/ZDC/AliZDCCalibData.cxx
new file mode 100644 (file)
index 0000000..daebcb1
--- /dev/null
@@ -0,0 +1,105 @@
+/**************************************************************************
+ * 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.                  *
+ **************************************************************************/
+
+/* $Id$ */
+
+///////////////////////////////////////////////////////////////////////////////
+//                                                                           //
+// class for ZDC calibration                                                 //
+//                                                                           //
+///////////////////////////////////////////////////////////////////////////////
+
+#include "AliZDCCalibData.h"
+
+ClassImp(AliZDCCalibData)
+
+//________________________________________________________________
+AliZDCCalibData::AliZDCCalibData()
+{
+  fHistMeanPed=0;
+  Reset();
+}
+
+//________________________________________________________________
+AliZDCCalibData::AliZDCCalibData(const char* name)
+{
+  TString namst = "Calib_";
+  namst += name;
+  SetName(namst.Data());
+  SetTitle(namst.Data());
+  fHistMeanPed=0;
+  Reset();
+}
+
+//________________________________________________________________
+AliZDCCalibData::~AliZDCCalibData()
+{
+  CleanHistos();
+}
+
+//________________________________________________________________
+void AliZDCCalibData::Reset()
+{
+  memset(fMeanPedestal,0,47*sizeof(Float_t));
+  memset(fEnCalibration,0,4*sizeof(Float_t));
+}                                                                                       
+
+//________________________________________________________________
+void AliZDCCalibData::CleanHistos()
+{
+  if (fHistMeanPed) delete fHistMeanPed; fHistMeanPed = 0;
+}
+
+//________________________________________________________________
+void AliZDCCalibData::PrepHistos()
+{
+  CleanHistos();
+  Int_t   kNChannels = 100;
+  Float_t kMaxPedVal = 400.;
+  TString hname = GetName();  hname += "_Pedestals";
+  fHistMeanPed   = new TH1F(hname.Data(),hname.Data(),kNChannels,0.,kMaxPedVal);
+  for (int i=0; i<64; i++) {
+    fHistMeanPed->SetBinContent(i+1,GetMeanPed(i));
+  }
+}
+
+//________________________________________________________________
+void  AliZDCCalibData::Print() const
+{
+   printf("\n  ----    Mean pedestal values    ----\n\n");
+   for(int t=0; t<47; t++){
+      printf(" MeanPed Value[ADC%d] = %f\n",t,fMeanPedestal[t]);
+   }
+   printf("\n  ----    Energy calibration coefficients         ----\n\n");
+   for(int t=0; t<4; t++){
+      printf(" En Calib Coeff. [ZDC%d] = %f\n",t,fEnCalibration[t]);
+   }
+} 
+
+//________________________________________________________________
+void AliZDCCalibData::SetMeanPed(Float_t* MeanPed)
+{
+  if(MeanPed) for(int t=0; t<47; t++) fMeanPedestal[t] = MeanPed[t];
+  else for(int t=0; t<43; t++) fMeanPedestal[t] = 0.;
+}
+
+//________________________________________________________________
+void AliZDCCalibData::SetEnCalib(Float_t* EnCalib) 
+{
+  if(EnCalib) for(int t=0; t<4; t++) fEnCalibration[t] = EnCalib[t];
+  else for(int t=0; t<4; t++) fEnCalibration[t] = 0.;
+}
+
diff --git a/ZDC/AliZDCCalibData.h b/ZDC/AliZDCCalibData.h
new file mode 100644 (file)
index 0000000..04f307f
--- /dev/null
@@ -0,0 +1,52 @@
+#ifndef ALIZDCCALIBDATA_H
+#define ALIZDCCALIBDATA_H
+
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+////////////////////////////////////////////////
+//  class for ZDC calibration                 //
+////////////////////////////////////////////////
+
+#include "TNamed.h"
+#include "TH1.h"
+#include "AliZDC.h"
+
+class AliZDCCalibData:
+public TNamed {
+ //
+ public:
+  AliZDCCalibData();
+  AliZDCCalibData(const char* name);
+  virtual ~AliZDCCalibData();
+  void Reset();
+  virtual void  Print() const; 
+  //
+  Float_t   GetMeanPed(Int_t channel)   const {return fMeanPedestal[channel];}
+  Float_t*  GetMeanPed()   const {return (float*)fMeanPedestal;}
+  
+  Float_t   GetEnCalib(Int_t channel)    const {return fEnCalibration[channel];}
+  Float_t*  GetEnCalib()   const {return (float*)fEnCalibration;}
+  
+  //
+  void     SetMeanPed(Float_t val, Int_t channel) {fMeanPedestal[channel]=val;}
+  void     SetMeanPed(Float_t* MeanPed);
+
+  void            SetEnCalib(Float_t val, Int_t channel) {fEnCalibration[channel]=val;}
+  void            SetEnCalib(Float_t* EnCalib);
+  
+  //
+  void     PrepHistos();
+  TH1F*    GetHistMeanPed() const {return fHistMeanPed;}
+  void     CleanHistos();
+ //
+ protected:
+  Float_t  fMeanPedestal[47];  // Mean pedestal values
+  Float_t  fEnCalibration[4];  // Coeff. for energy calibration (4 different ZDC's?)
+
+  TH1F*    fHistMeanPed;        //! histos for drawing mean pedestals
+  //
+  ClassDef(AliZDCCalibData,11)    // ZDC Sensor Calibration data
+};
+
+#endif