]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
New classes for beam test analysis
authorschutz <schutz@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 21 Oct 2002 16:36:01 +0000 (16:36 +0000)
committerschutz <schutz@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 21 Oct 2002 16:36:01 +0000 (16:36 +0000)
12 files changed:
PHOS/AliPHOSBeamTestEvent.cxx [new file with mode: 0644]
PHOS/AliPHOSBeamTestEvent.h [new file with mode: 0644]
PHOS/AliPHOSCalibrationDB.cxx [new file with mode: 0644]
PHOS/AliPHOSCalibrationDB.h [new file with mode: 0644]
PHOS/AliPHOSConTableDB.cxx [new file with mode: 0644]
PHOS/AliPHOSConTableDB.h [new file with mode: 0644]
PHOS/AliPHOSRaw2Digits.cxx [new file with mode: 0644]
PHOS/AliPHOSRaw2Digits.cxx~ [new file with mode: 0644]
PHOS/AliPHOSRaw2Digits.h [new file with mode: 0644]
PHOS/AliPHOSRaw2Digits.h~ [new file with mode: 0644]
PHOS/PHOSLinkDef.h
PHOS/libPHOS.pkg

diff --git a/PHOS/AliPHOSBeamTestEvent.cxx b/PHOS/AliPHOSBeamTestEvent.cxx
new file mode 100644 (file)
index 0000000..d52e0c3
--- /dev/null
@@ -0,0 +1,45 @@
+/**************************************************************************
+ * 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$ */
+
+//_________________________________________________________________________
+// Short description  
+//
+//*-- Author : Maxim Volkov (RRC KI) & Dmitri Peressounko (RRC KI & SUBATECH) 
+//////////////////////////////////////////////////////////////////////////////
+
+// --- ROOT system ---
+
+// --- Standard library ---
+
+// --- AliRoot header files ---
+
+#include "AliPHOSBeamTestEvent.h"
+
+ClassImp(AliPHOSBeamTestEvent)
+
+
+//____________________________________________________________________________ 
+  AliPHOSBeamTestEvent::AliPHOSBeamTestEvent():TObject() 
+{
+
+}
+
+//____________________________________________________________________________ 
+  AliPHOSBeamTestEvent::~AliPHOSBeamTestEvent()
+{
+
+}
diff --git a/PHOS/AliPHOSBeamTestEvent.h b/PHOS/AliPHOSBeamTestEvent.h
new file mode 100644 (file)
index 0000000..c030fd9
--- /dev/null
@@ -0,0 +1,62 @@
+#ifndef ALIPHOSBEAMTESTEVENT_H
+#define ALIPHOSBEAMTESTEVENT_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* $Id$ */
+
+//_________________________________________________________________________
+//  Class for PHOS Beam Test event header. Contanes all information 
+//  about triggers, etc.    
+//                  
+//*-- Author: Maxim Volkov (RRC KI) & Dmitri Peressounko (RRC KI & SUBATECH)
+
+
+// --- ROOT system ---
+#include "TObject.h"
+// --- Standard library ---
+
+// --- AliRoot header files ---
+
+class AliPHOSBeamTestEvent:public TObject {
+
+public:
+  AliPHOSBeamTestEvent() ;          // ctor
+
+  virtual ~AliPHOSBeamTestEvent() ; // dtor
+  UInt_t *  GetUserVector(void){return fUserVector ;}
+  UInt_t *  GetHeader(void){return fHeader ;}
+  UShort_t  GetPattern(void){return fPattern ;}
+  UShort_t *GetScanning(void){return fScanning ;}
+  UShort_t *GetCharge(void){return fCharge ;}
+  UInt_t *  GetScaler(void){return fScaler ;}
+  UShort_t *GetTDC(void) {return fTDC2228 ;}
+
+  void SetUserVector(UInt_t * uv){
+         for(Int_t i=0;i<16;i++)fUserVector[i]=uv[i];}
+  void SetHeader(UInt_t * h){
+         for(Int_t i=0;i<12;i++)fHeader[i]=h[i];}
+  void SetPattern(UShort_t pat){fPattern=pat ;}
+  void SetScanning(UShort_t * scan){
+        for(Int_t i=0;i<32;i++) fScanning[i]=scan[i] ;}
+  void SetCharge(UShort_t *charg){
+         for(Int_t i=0;i<12;i++) fCharge[i]=charg[i] ;}
+  void SetScaler(UInt_t * sc){
+        for(Int_t i=0;i<12;i++) fScaler[i]=sc[i] ;}
+  void SetTDC(UShort_t * tdc) {
+         for(Int_t i=0;i<12;i++) fTDC2228[i]=tdc[i] ;}
+private:
+  UInt_t   fUserVector[16] ;     //ZEBRA Event user vector
+  UInt_t   fHeader[12] ;         //ZEBRA event header
+  UInt_t   fScaler[12] ;         //Scalers, 1 module X 12 (4 byte) ch.
+  UShort_t fPattern ;            //Trigger bit register
+  UShort_t fScanning[32] ;       //Scanning ADCs,4 modulesX8=32 channels
+  UShort_t fCharge[12] ;         //Charge ADCs, 1 module X 12 = 12 ch.
+  UShort_t fTDC2228[32] ;        //LeCroy TDC 2228A, 4 module X 8 =32 ch
+
+  ClassDef(AliPHOSBeamTestEvent,1)  // description 
+
+};
+
+#endif // ALIPHOSBEAMTESTEVENT_H
diff --git a/PHOS/AliPHOSCalibrationDB.cxx b/PHOS/AliPHOSCalibrationDB.cxx
new file mode 100644 (file)
index 0000000..7c766ee
--- /dev/null
@@ -0,0 +1,137 @@
+/**************************************************************************
+ * 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$ */
+
+//_________________________________________________________________________
+// Short description  
+//
+//*-- Author :  D.Peressounko (RRC KI & SUBATECH) 
+//////////////////////////////////////////////////////////////////////////////
+
+// --- ROOT system ---
+#include "TFile.h"
+// --- Standard library ---
+#include <iostream.h>
+#include <fstream>
+
+// --- AliRoot header files ---
+#include "AliPHOSConTableDB.h"
+#include "AliPHOSCalibrationDB.h"
+#include "AliPHOSGeometry.h"
+ClassImp(AliPHOSCalibrationDB)
+
+
+//____________________________________________________________________________ 
+  AliPHOSCalibrationDB::AliPHOSCalibrationDB():TNamed() 
+{
+  fPedestals = 0 ;
+  fSlopes = 0;
+  fNChannels = 0 ;
+  fctdb = 0 ;
+}
+//____________________________________________________________________________ 
+AliPHOSCalibrationDB::AliPHOSCalibrationDB(const char* filename ,const char * database):
+  TNamed("AliPHOSCalibrationDB",database){
+  //Creates the containers: we prepare places for all channels in PHOS
+
+  AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance("GPS2","") ;
+  fNChannels = geom->GetNModules()*geom->GetNPhi()*geom->GetNZ()+
+               geom->GetNumberOfCPVPadsZ()*geom->GetNumberOfCPVPadsPhi()*geom->GetNModules() ;
+  //Note, that to avoid shifting AbsId each time we access data, we do not use
+  //first slot and index runs from 1 to fNChannels inclusively
+  fPedestals = new TArrayF(fNChannels+1) ;
+  fSlopes =  new TArrayF(fNChannels+1) ;
+  fctdb = 0 ;
+} 
+//____________________________________________________________________________ 
+  AliPHOSCalibrationDB::~AliPHOSCalibrationDB()
+{
+  if(fPedestals)
+    delete fPedestals ;
+  if(fSlopes)
+    delete fSlopes ;
+}
+//____________________________________________________________________________ 
+Float_t AliPHOSCalibrationDB::Calibrate(Int_t amp, Int_t absId)const 
+{
+  //if absID is known, return calibrated energy, else - zero
+  if(absId <=0 || absId > fNChannels) 
+    return 0.0000001 ;
+
+  Float_t ret = (amp - fPedestals->At(absId))*fSlopes->At(absId); 
+  if(ret > 0)
+    return ret ;
+  else
+    return 0.0000001 ; //Should not be zero - to avoid FPE
+}
+//____________________________________________________________________________ 
+void  AliPHOSCalibrationDB::SetAll(Float_t pedestal, Float_t slope){
+  //Set all calibration parameters to the same value
+  if(fPedestals)
+    for(Int_t i=0;i<fNChannels;i++){
+      fPedestals->AddAt(pedestal,i) ;
+      fSlopes->AddAt(slope,i);
+    }
+  else
+    cout << "Please, create me with non-default constructor!" << endl;
+}
+//____________________________________________________________________________
+void AliPHOSCalibrationDB::ReadCalibrationParameters(const char * filename, Option_t* opt){
+  //reads calibration parameters from ascii file
+
+  if(strcmp(opt,"gains")==0){  //read gains
+    if(!fctdb){
+      cout << "Specify Connections Table Database first" << endl ;
+      return ;
+    }
+    ifstream gainfile(filename) ; 
+    for(Int_t i = 1; i<=64; i++){
+      Float_t slope ;
+      gainfile >> slope  ;      
+      fSlopes->AddAt(slope,fctdb->Raw2AbsId(i));
+    }
+    gainfile.close();   
+  }
+  else
+    if(strstr(opt,"pedest")){  //read pedestals
+      if(!fctdb){
+       cout << "Specify Connections Table Database first" << endl ;
+       return ;
+      }
+      ifstream pfile(filename) ; 
+      for(Int_t i = 1; i<=64; i++){
+       Float_t pedestal ;
+       pfile >> pedestal  ;      
+       fPedestals->AddAt(pedestal,fctdb->Raw2AbsId(i));
+      }
+      pfile.close();
+   }
+   else{
+     cout << "Available options are " << endl ;
+     cout << " `gains' : to read gains " << endl ;
+     cout << " `pedestals : to read pedestals " << endl ;
+   }
+}
+//____________________________________________________________________________
+AliPHOSCalibrationDB& AliPHOSCalibrationDB::operator=(AliPHOSCalibrationDB const & cdb)
+{
+  //
+  fNChannels = cdb.fNChannels;
+  fFileName = cdb.fFileName;
+  fPedestals=cdb.fPedestals ;
+  fSlopes = cdb.fSlopes;
+  return *this ;
+}
diff --git a/PHOS/AliPHOSCalibrationDB.h b/PHOS/AliPHOSCalibrationDB.h
new file mode 100644 (file)
index 0000000..a82d5a4
--- /dev/null
@@ -0,0 +1,62 @@
+#ifndef ALIPHOSCALIBRATIONDB_H
+#define ALIPHOSCALIBRATIONDB_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* $Id$ */
+
+//_________________________________________________________________________    
+//                  
+//*-- Author: D.Peressounko (RRC KI & SUBATECH)
+
+
+// --- ROOT system ---
+#include "TNamed.h"
+#include "TArrayF.h" 
+#include "TString.h" 
+
+// --- Standard library ---
+
+// --- AliRoot header files ---
+class AliPHOSConTableDB ;
+
+class AliPHOSCalibrationDB:public TNamed {
+
+public:
+  AliPHOSCalibrationDB() ;          // ctor
+  AliPHOSCalibrationDB(const char* filename ,const char * database = "Primordial") ;          
+  virtual ~AliPHOSCalibrationDB() ; // dtor
+
+  //Main method: calibrates if gains are known, otherwise - returns 0
+  Float_t Calibrate(Int_t amp, Int_t absId)const ;
+
+  //Read gains of pedestals from ascii file
+  void ReadCalibrationParameters(const char * filename = "gains.dat",Option_t* opt = "gains") ;
+
+  //Sets the same parameters for all channels  
+  void SetAll(Float_t pedestal = 0, Float_t slope = 0.01) ; 
+
+  //To know correspondance when reads list of gains from ascii file 
+  void SetConTableDB(AliPHOSConTableDB * ctdb){fctdb = ctdb; }
+
+  //Set parameters for particlular channel
+  void SetParameters(Int_t AbsId, Float_t pedestal = 0, Float_t slope = 0.01)
+    {if(fPedestals){fPedestals->AddAt(pedestal,AbsId-1) ; fSlopes->AddAt(slope,AbsId-1) ;} }
+
+  //To be replaced in real DB when updating will really be necessary
+  void Update(Int_t event,Int_t run){} 
+
+  AliPHOSCalibrationDB & operator = (const AliPHOSCalibrationDB & ) ;
+private:
+  Int_t     fCurentRun ;       //! 
+  Int_t     fNChannels ;
+  TString   fFileName ;
+  TArrayF * fPedestals ;
+  TArrayF * fSlopes ;
+  AliPHOSConTableDB * fctdb ;  //!
+
+  ClassDef(AliPHOSCalibrationDB,1)  // description 
+
+};
+
+#endif // AliPHOSCALIBRATIONDB_H
diff --git a/PHOS/AliPHOSConTableDB.cxx b/PHOS/AliPHOSConTableDB.cxx
new file mode 100644 (file)
index 0000000..c6dd74e
--- /dev/null
@@ -0,0 +1,164 @@
+/**************************************************************************
+ * 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$ */
+
+//_________________________________________________________________________
+// Short description  
+//
+//*-- Author :  (SUBATECH) 
+//////////////////////////////////////////////////////////////////////////////
+
+// --- ROOT system ---
+#include "TArrayS.h"
+#include "TH2S.h"
+
+// --- Standard library ---
+#include <iostream.h>
+// --- AliRoot header files ---
+#include "AliPHOSGeometry.h"
+#include "AliPHOSConTableDB.h"
+
+ClassImp(AliPHOSConTableDB)
+
+
+//____________________________________________________________________________ 
+  AliPHOSConTableDB::AliPHOSConTableDB():TNamed("AliPHOSConTableDB","Beamtest2002") 
+{
+  fNcrInProto = 0 ;
+  fProtoRaws = 0 ;
+  fProtoColumns = 0 ;
+  fRawOffset = 0 ;
+  fColOffset = 0 ;
+  fGeom = 0;
+  fAbsIdMap = 0 ;
+}
+
+//____________________________________________________________________________ 
+  AliPHOSConTableDB::AliPHOSConTableDB(const char * title):TNamed("AliPHOSConTableDB",title) 
+{
+  fNcrInProto = 0 ;
+  fProtoRaws = 0 ;
+  fProtoColumns = 0 ;
+  fRawOffset = 0 ;
+  fColOffset = 0 ;
+
+  fGeom = AliPHOSGeometry::GetInstance("GPS2","") ;
+
+}
+
+//____________________________________________________________________________ 
+  AliPHOSConTableDB::~AliPHOSConTableDB()
+{
+  if(fAbsIdMap)
+    delete [] fAbsIdMap ;
+}
+
+//____________________________________________________________________________ 
+void  AliPHOSConTableDB::BuildDB(void)
+{ 
+  //Make a map between Protopype cristalls and PHOS crystalls
+  //assuming, that prototype is centered in the third module of the PHOS
+  fNcrInProto =fProtoRaws*fProtoColumns ;
+  if(!fNcrInProto){
+    cout << "configuratio of prototype is not known!!!" << endl ;
+    cout << "specify number of raws and columns in prototype" << endl ;
+    return ;
+  }
+  fRawOffset = (fGeom->GetNPhi() - fProtoRaws)/2 ;
+  fColOffset = (fGeom->GetNZ() - fProtoColumns )/ 2 ;
+  fAbsIdMap = new TArrayS(fNcrInProto) ;
+  for(Int_t raw =0; raw < fProtoRaws; raw ++){
+    for(Int_t col = 0; col < fProtoColumns ; col ++){
+      Int_t rawId = col*fProtoRaws + raw ;
+      Int_t rel[4] = {3,0,0,0} ; //We assume, that we deal with third module
+      rel[2]=raw + fRawOffset ;
+      rel[3]=col + fColOffset ;
+      Int_t absId ;
+      fGeom->RelToAbsNumbering(rel,absId) ;
+      fAbsIdMap->AddAt(static_cast<UInt_t>(absId),rawId) ;
+    }
+  }
+
+}
+//____________________________________________________________________________ 
+void AliPHOSConTableDB::PlotProtoMap(Option_t * opt)
+{
+  //Visualyse connection table
+
+  TH2S * hMapProto = new TH2S("hMap","Map of Prototype ids",
+                             fGeom->GetNPhi(),0,fGeom->GetNPhi(),
+                             fGeom->GetNZ(),0,fGeom->GetNZ()) ;
+  TH2S * hMapPHOS = new TH2S("hMapPHOS","Map of PHOS ids",
+                            fGeom->GetNPhi(),0,fGeom->GetNPhi(),
+                            fGeom->GetNZ(),0,fGeom->GetNZ()) ;
+  TH2C * hMapBox = new TH2C("hMapBox","Map of Prototype ids",
+                             fGeom->GetNPhi(),0,fGeom->GetNPhi(),
+                             fGeom->GetNZ(),0,fGeom->GetNZ()) ; 
+  for(Int_t raw =0; raw <fGeom->GetNPhi() ; raw ++)
+    for(Int_t col = 0; col <fGeom->GetNZ() ; col ++)
+      hMapBox->SetBinContent(raw+1,col+1,1) ;
+  
+  for(Int_t raw =0; raw < fProtoRaws; raw ++){
+    for(Int_t col = 0; col < fProtoColumns ; col ++){
+      Int_t rawId = col*fProtoRaws + raw ;
+      Int_t rel[4] = {3,0,0,0} ; //We assume, that we deal with third module
+      rel[2]=raw + fRawOffset ;
+      rel[3]=col + fColOffset ;
+      hMapProto->SetBinContent(rel[2]+1,rel[3]+1,rawId);
+      Int_t absId ;
+      fGeom->RelToAbsNumbering(rel,absId) ;
+      hMapPHOS->SetBinContent(rel[2]+1,rel[3]+1,absId) ;
+    }
+  }
+
+
+  if(strstr(opt,"Zoom")||strstr(opt,"zoom")){
+    static_cast<TAxis *>(hMapBox->GetXaxis())->SetRange(fRawOffset+1,fGeom->GetNPhi()-fRawOffset) ;
+    static_cast<TAxis *>(hMapBox->GetYaxis())->SetRange(fColOffset+1,fGeom->GetNZ()-fColOffset) ;    
+  }
+   hMapBox->Draw("box") ;
+   if(strstr(opt,"PHOS"))
+     hMapPHOS->Draw("textsame") ;
+   else
+     hMapProto->Draw("textsame") ;
+
+} 
+//____________________________________________________________________________ 
+Int_t AliPHOSConTableDB::Raw2AbsId(Int_t rawId){
+  //converts numbering of modules in prototipe into
+  //numbering in PHOS
+  if(rawId >= 0 && rawId<fNcrInProto)
+    return fAbsIdMap->At(rawId) ;
+  else
+    return 0 ;
+}
+//____________________________________________________________________________ 
+void AliPHOSConTableDB::Print(Option_t * option)const {
+
+  cout << GetName() <<  " " << GetTitle() << endl ;
+  cout << "PHOS Geometry configured for " ; 
+  if(fGeom)
+    cout << fGeom->GetName() << " " << fGeom->GetTitle() <<  endl ;
+  else
+    cout << " null " << endl ;
+  cout << "-------Prototype parameters--------" << endl ;
+  cout << "    number of columns: " << fProtoColumns << endl ;
+  cout << "    number of raws:    " << fProtoRaws << endl ;
+  cout << "    centered in third PHOS module with offsets: " <<endl ;
+  cout << "    raw: " << fRawOffset << " of " << fGeom->GetNPhi() << endl ;
+  cout << "    col: " << fColOffset << " of " << fGeom->GetNZ() << endl ;
+  cout << "------------------------------------" << endl ;
+}
diff --git a/PHOS/AliPHOSConTableDB.h b/PHOS/AliPHOSConTableDB.h
new file mode 100644 (file)
index 0000000..cbc8092
--- /dev/null
@@ -0,0 +1,69 @@
+#ifndef ALIPHOSCONTABLEDB_H
+#define ALIPHOSCONTABLEDB_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* $Id$ */
+
+//_________________________________________________________________________
+//  Base Class for PHOS     
+//                  
+//*-- Author: (SUBATECH)
+
+
+// --- ROOT system ---
+#include "TNamed.h"
+class TArrayS ;
+
+// --- Standard library ---
+
+// --- AliRoot header files ---
+class AliPHOSGeometry ;
+
+class AliPHOSConTableDB: public TNamed {
+
+public:
+  AliPHOSConTableDB() ;          // ctor
+  AliPHOSConTableDB(const char * title) ;          // ctor
+  virtual ~AliPHOSConTableDB() ; // dtor
+
+  //Calculate table from known numbe of raws/columns 
+  //assuming that prototype is situated in the center of 3 PHOS mod.
+  void BuildDB(void) ;
+
+  //set the number of columns in prototype
+  void SetNCols(Int_t ncolumns){fProtoColumns = ncolumns ;}
+  //Set the number of raw in prototype
+  void SetNRaws(Int_t nraws){fProtoRaws = nraws ;}
+
+  //Plot correspondance between Prototype Id and PHOS
+  //Options are "Zoom" - only proto region is plotted
+  //            "PHOS" - presents both PHOS and Proto ids
+  void PlotProtoMap(Option_t * opt="Zoom") ; 
+
+  void Print(Option_t *option="") ;
+
+  //Transforms channel number in prototype into AbsId number in PHOS
+  Int_t Raw2AbsId(Int_t raw) ;
+
+  //Transforms AbsId number in PHOS into channel number in prototype 
+  Int_t AbsId2Raw(Int_t AbsId) ;
+
+  virtual void Print(Option_t * option="")const ;
+
+private:
+  AliPHOSGeometry * fGeom ;   //!
+
+  Int_t     fProtoRaws ;        //Parameters
+  Int_t     fProtoColumns ;     //used to calculate
+  Int_t     fRawOffset ;        //correspondance
+  Int_t     fColOffset ;        //map
+  Int_t     fNcrInProto ;    //Number of channels in prototype
+  TArrayS * fAbsIdMap ;      //Map of correspondance between Raw and PHOS ID
+
+  ClassDef(AliPHOSConTableDB,1)  // description 
+
+
+};
+
+#endif // AliPHOSCONTABLEDB_H
diff --git a/PHOS/AliPHOSRaw2Digits.cxx b/PHOS/AliPHOSRaw2Digits.cxx
new file mode 100644 (file)
index 0000000..675c2ec
--- /dev/null
@@ -0,0 +1,536 @@
+/**************************************************************************
+ * 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$ */
+
+//_________________________________________________________________________
+// Short description  
+//
+/*-- Author: Maxim Volkov (RRC KI)
+             Dmitri Peressounko (RRC KI & SUBATECH)
+             Yuri Kharlov (IHEP & SUBATECH)     */
+
+//////////////////////////////////////////////////////////////////////////////
+
+// --- ROOT system ---
+#include "TClonesArray.h"
+#include "TFile.h"
+#include "TTree.h"
+
+// --- Standard library ---
+#include <iostream.h>
+//#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <netinet/in.h>
+
+// --- AliRoot header files ---
+#include "AliPHOSDigit.h"
+#include "AliPHOSConTableDB.h"
+#include "AliPHOSBeamTestEvent.h"
+#include "AliPHOSRaw2Digits.h"
+#include "AliPHOSv1.h"
+#include "../EVGEN/AliGenBox.h"
+#include "AliRun.h"
+
+ClassImp(AliPHOSRaw2Digits)
+  
+  
+//____________________________________________________________________________ 
+  AliPHOSRaw2Digits::AliPHOSRaw2Digits():TTask() 
+{
+  fInName="";  
+  fMK1 = 0x0123CDEF ;
+  fMK2 = 0x80708070 ;
+  fMK3 = 0x4321ABCD ;
+  fMK4 = 0x80618061 ;
+  fCKW = 0x4640E400 ;
+  fDebug = kFALSE;             //  Debug flag
+  fIsInitialized = kFALSE ;
+  fTarget[0] = 0 ;
+  fTarget[1] = 0 ;
+  fTarget[2] = 0 ;
+  fDigits = 0 ;
+  fPHOSHeader =0 ;
+  fEvent = 0 ;
+  fctdb = 0;
+}
+//____________________________________________________________________________ 
+  AliPHOSRaw2Digits::AliPHOSRaw2Digits(const char * filename):TTask("Default","") 
+{
+  fInName=filename;
+  TString outname(fInName) ;
+  outname.ToLower() ;
+  outname.ReplaceAll(".fz",".root") ;
+  outname.ReplaceAll(".gz","") ;
+  SetTitle(outname) ;
+
+  fMK1 = 0x0123CDEF ;
+  fMK2 = 0x80708070 ;
+  fMK3 = 0x4321ABCD ;
+  fMK4 = 0x80618061 ;
+  fCKW = 0x4640E400 ;
+  fDebug = kFALSE;             //  Debug flag
+  fIsInitialized = kFALSE ;
+  fTarget[0] = 0 ;
+  fTarget[1] = 0 ;
+  fTarget[2] = 0 ;
+  fDigits = 0 ;
+  fPHOSHeader =0 ;
+  fEvent = 0 ;
+  fctdb = 0;
+}
+
+//____________________________________________________________________________ 
+AliPHOSRaw2Digits::~AliPHOSRaw2Digits()
+{
+  if(fPHOSHeader)
+    fPHOSHeader->Delete() ;
+  if(fDigits){
+    fDigits->Delete() ;
+    delete fDigits ;
+  }
+  
+}
+//____________________________________________________________________________ 
+void AliPHOSRaw2Digits::Exec(Option_t * option){
+  //This is steering method performing all the conversion
+
+  if(!fIsInitialized) //need initialization
+    if(!Init())       //failed to initialize
+      return ;
+
+  ProcessRawFile() ;
+
+  FinishRun() ;
+} 
+//____________________________________________________________________________ 
+Bool_t AliPHOSRaw2Digits::Init(void){
+  //Create PHOS geometry, sets magnetic field to zero, 
+  //create Generator - to store target position, 
+  //opens out file, creates TreeE and make initialization of contaniers
+
+
+  if(fIsInitialized)
+    return kTRUE;
+
+  //Create PHOS
+  new AliPHOSv1("PHOS","GPS2") ;
+
+  //Set Magnetic field
+  gAlice->SetField(0,2);  
+
+  //Set positin of the virtex
+  AliGenBox *gener = new AliGenBox(1);
+  Float_t ox = fTarget[1]; 
+  Float_t oy = fTarget[2]-460.; 
+  Float_t oz = fTarget[0];
+  gener->SetOrigin(ox, oy, oz);
+
+  //  Create the output file
+  TString outname("") ;
+  if(strstr(GetTitle(),"root")){
+    outname=GetTitle();
+  }
+  else{
+    outname = fInName ;
+    outname.ToLower() ;
+    outname.ReplaceAll(".fz",".root") ;
+  }
+  TFile *rootfile = new TFile(outname,"recreate");
+  rootfile->SetCompressionLevel(2);
+
+  // Create the Root Trees
+  gAlice->MakeTree("E") ;
+
+  //Make container for digits
+  fDigits = new TClonesArray("AliPHOSDigit",1000) ;
+
+  //Fill now TreeE
+  fPHOSHeader = new  AliPHOSBeamTestEvent() ;
+  Int_t splitlevel = 0 ;
+  Int_t bufferSize = 32000 ;    
+  TBranch * headerBranch = gAlice->TreeE()->Branch("AliPHOSBeamTestEvent", 
+                                                  "AliPHOSBeamTestEvent", 
+                                                  &fPHOSHeader,bufferSize,splitlevel);
+  headerBranch->SetName("AliPHOSBeamTestEvent") ;
+
+  fIsInitialized = kTRUE ;
+  return kTRUE ;
+}
+//____________________________________________________________________________ 
+Bool_t AliPHOSRaw2Digits::ProcessRawFile(){
+
+  //Method opens zebra file and reads successively bytes from it,
+  //filling corresponding fields in header and digits.
+
+
+  fStatus= -3 ;
+  //First of all, open file and check if it is a zebra file
+
+  char command[256];
+  sprintf(command,"zcat %s",fInName.Data());
+  FILE *dataFile = popen(command, "r");
+  if (dataFile == NULL) {
+    cout << " Can not open file " << fInName.Data() << endl ;
+    perror(fInName.Data()) ;
+    fStatus = -1 ;
+    return kFALSE ;
+  }
+  printf("Open pipe: %s\n",command);
+
+  // Check if byte ordering is little-endian 
+  UInt_t w = 0x12345678;
+  Int_t swapo = memcmp(&w, "\x78\x56\x34\x12", sizeof(UInt_t)) == 0;
+  if(fDebug)
+    cout << "swapo=" << swapo << endl;
+  
+  
+  UInt_t recBuf[300] ;
+
+  // Read physical record control words 
+  UInt_t nb = 8*sizeof(UInt_t);
+  Int_t n = fread(recBuf, nb, 1, dataFile);
+  if(static_cast<UInt_t>(n) != 1) {
+    if (n < 0 )
+      perror(fInName.Data());
+    else
+      cout << "Could not read physical record control words" << endl;
+    fStatus = -2 ;
+    return kFALSE;
+  }
+  
+  if(fDebug)
+    cout << "recbuf[0] = " << recBuf[0] << endl ;
+  
+  // Check if it is a ZEBRA file and if the words are swapped 
+  UInt_t swapi = 0 ;
+  if (recBuf[0] != fMK1) {
+    Swab4(recBuf, &w, 1);
+    if (w != fMK1) {
+      cout << "Does not look like a ZEBRA file\n";
+      pclose(dataFile) ;
+      fStatus = -2 ;
+      return kFALSE;
+    }
+    swapi=1 ;
+  }
+  
+  if(fDebug){
+    cout << "        w = " << w << endl ;;
+    cout << "    swapi = " << swapi << endl ;;
+  }
+  
+  // Get number of words in physical record 
+  UInt_t  nwphr ;
+  if (swapi)
+    Swab4(&recBuf[4],&nwphr,1);
+  else 
+    nwphr = recBuf[4];
+  nwphr*=2; // 1998 -- Now we have 2 records 150 words each 
+
+
+  //start loop over data  
+  // Read rest of record 
+  nb = (nwphr-8)*sizeof(UInt_t);
+  n = fread(&recBuf[8], nb, 1, dataFile) ;
+  if (static_cast<UInt_t>(n) != 1) {
+    if (n < 0 ){
+      perror(fInName.Data());
+      fStatus = -2 ;
+      return kFALSE;
+    }
+  }
+  nb = nwphr *sizeof(UInt_t);
+
+  UInt_t userVector[16] ;
+  UInt_t zheader[12];    
+  UShort_t pattern ;
+  UShort_t scanning[32] ;
+  UShort_t charge[12];
+  UInt_t scaler[12]; 
+  UShort_t tdc2228[32];
+  
+  //read untill the end of file
+  fEvent=0 ;
+  while(1){
+
+    //    StartNewEvent() ;
+    fDigits->Delete() ;
+    gAlice->SetEvent(fEvent) ;
+         
+    Int_t i ;
+    for(i=0;i<16;i++)
+      userVector[i]=*(recBuf+21+i);
+    if(!swapi)
+      Swab4(userVector, userVector, 16);     
+    fPHOSHeader->SetUserVector(userVector) ;
+    
+    
+    // ZEBRA event header
+    for(i=0;i<12;i++)
+      zheader[i]=*(recBuf+47+i);
+    if(swapi)
+      Swab4(zheader, zheader, 12);
+    fPHOSHeader->SetHeader(zheader) ;
+    
+    // Swap input 
+    if (swapi)
+      Swab4(recBuf, recBuf, nwphr);
+    
+    /* Physical record control words */
+    UInt_t * recptr = recBuf;  //Pointer to current position
+
+    if(recptr[7] != 1) {
+      cout << "Can not handle fast blocks" << endl;
+      fStatus = -2 ;
+      return kFALSE;
+    }    
+    recptr += 8;
+    
+    // Logical record control words   
+    UInt_t lrtyp = recptr[1];
+    if (lrtyp != 3) {
+      cout << "Can not handle logical record type " <<  lrtyp << endl ;
+      fStatus = -2 ;
+      return kFALSE;
+    }
+    
+    recptr += 2;
+    if (recptr[0] != fCKW) {
+      cout <<  "Bad check word" << endl;
+      fStatus = -2 ;
+      return kFALSE;
+    }
+    
+    UInt_t  nwuh = recptr[9];
+    recptr += 10+nwuh;
+    
+    // Bank system words 
+    UInt_t nd = recptr[8];           /* Number of data words */
+    recptr += 10;
+    
+    // Data words 
+    UInt_t evtno = recptr[2];                  /* Event number */
+    
+    if(fDebug)
+      cout << "evtno=" << evtno << endl;
+    
+    UInt_t nh = recptr[4];                  /* Number of header words in data bank */
+    recptr += nh;
+    
+    // Unswap data from VME 
+    if (swapi)
+      Swab4(recptr, recptr, nd-nh-3);
+    
+    // Give buffer to monitor program 
+    //  UInt_t esize = nd-nh-3;
+    //    if (swapo)
+    //       Swab2(recptr, recptr, esize); 
+    // Two byte data are correct after this operation. 
+    //But we're in trouble if the data array contains 4 byte data!
+    
+    // From now on deal with VME data (MSB first, or network byte order).
+    
+    
+    // Fill the event with data from ADCs
+    UChar_t *byteptr=(UChar_t*)recptr;
+    
+    // Trigger bit register  
+    pattern=ntohs(*(UShort_t*)byteptr);
+    fPHOSHeader->SetPattern(pattern) ;
+    byteptr+=sizeof(UShort_t);
+    
+    // Either peak ADCs, 10 modulesX8=80 channels, 
+    //or Kurchatov 64+2 channel ADC 
+    //(the rest of the channels padded with 0xffff) 
+    for(i=0;i<80;i++){
+      Int_t peak = static_cast<Int_t>(ntohs(*(UShort_t*)byteptr));
+      //make digit
+      Int_t absID = fctdb->Raw2AbsId(i) ;
+      if(absID > 0)
+       new((*fDigits)[i])AliPHOSDigit(-1,absID,peak,0.,i) ;
+      if(fDebug){
+       if(peak>(UShort_t)1000)
+         cout << "event=" << fEvent << " peak[" << i << "] = "<<peak << endl;
+      }
+      byteptr+=sizeof(UShort_t);
+    }
+    
+    // Scanning ADCs, 4 modulesX8=32 channels
+    for(i=0;i<32;i++){
+      scanning[i]=ntohs(*(UShort_t*)byteptr);
+      byteptr+=sizeof(UShort_t);
+    }
+    fPHOSHeader->SetScanning(scanning) ;
+    
+    // Charge ADCs, 1 moduleX12=12 channels
+    for(i=0;i<12;i++){
+      charge[i]=ntohs(*(UShort_t*)byteptr);
+      byteptr+=sizeof(UShort_t);
+    }
+    fPHOSHeader->SetCharge(charge) ;
+    
+    // Scalers, 1 moduleX12=12 (4 byte) channels
+    for(i=0;i<12;i++){
+      scaler[i]=ntohl(*(UInt_t*)byteptr);
+      byteptr+=sizeof(UInt_t);
+    }
+    fPHOSHeader->SetScaler(scaler) ;
+    
+    // LeCroy TDC 2228A, 4 moduleX8=32 channels
+    for(i=0;i<8;i++){
+      tdc2228[i]=ntohs(*(UShort_t*)byteptr);
+      byteptr+=sizeof(UShort_t);
+    }
+    fPHOSHeader->SetTDC(tdc2228) ;
+
+    WriteDigits() ;
+    if(fDebug)
+      cout << "event=" << fEvent << " written " << endl;
+    // Read next record 
+    UInt_t nb = nwphr *sizeof(UInt_t);
+    n = fread( recBuf, nb,1,dataFile);
+    if (n < 0 ){
+      perror(fInName);
+      fStatus = -2 ;
+      return kFALSE;
+    }
+    if (static_cast<UInt_t>(n) != 1) {
+      pclose(dataFile) ;
+      fStatus = 1 ;
+      return kTRUE ; //all read
+    }
+    fEvent++ ;
+  }
+  
+  fStatus = 1 ;  
+  return kTRUE ;  
+}
+//____________________________________________________________________________ 
+void AliPHOSRaw2Digits::Swab4(void *from, void *to, size_t nwords){
+  // The function swaps 4 bytes: byte#3<-->byte#0, byte#2<-->byte#1 
+  register char *pf=static_cast<char*>(from) ;
+  register char *pt=static_cast<char*>(to) ;
+  register char c;
+  while (nwords-- > 0 ) {
+    c = pf[0];
+    pt[0] = pf[3];
+    pt[3] = c;
+    c = pf[1];
+    pt[1] = pf[2];
+    pt[2] = c;
+    pf += 4;
+    pt += 4;
+  }
+}
+
+//____________________________________________________________________________ 
+void AliPHOSRaw2Digits::Swab2(void *from, void *to, size_t nwords)
+{ //The function swaps 2x2 bytes: byte#0<-->byte#1, byte#2<-->byte#3 
+  register char *pf=static_cast<char*>(from) ;
+  register char *pt=static_cast<char*>(to);
+  register char c;   
+  while (nwords-- > 0 ) {
+    c = pf[0];
+    pt[0] = pf[1];
+    pt[1] = c;
+    c = pf[2];
+    pt[2] = pf[3];
+    pt[3] = c;
+    pf += 4;
+    pt += 4;
+  }
+}
+
+//____________________________________________________________________________ 
+void AliPHOSRaw2Digits::FinishRun(){
+  //Write geometry and header tree
+  gAlice->Write(0,TObject::kOverwrite);
+  gAlice->TreeE()->Write(0,TObject::kOverwrite);
+  
+}
+//____________________________________________________________________________ 
+void AliPHOSRaw2Digits::WriteDigits(void){
+  //In this method we create TreeD, write digits and Raw2Digits to it
+  // and write Header to TreeE. Finally we write TreeD to root file 
+  
+  //Start from Digits
+  fDigits->Sort() ;
+  fDigits->Expand(fDigits->GetEntriesFast()) ;
+  for(Int_t i=0;i<fDigits->GetEntriesFast(); i++)
+    static_cast<AliPHOSDigit*>(fDigits->At(i))->SetIndexInList(i) ;
+
+  char hname[30];
+  sprintf(hname,"TreeD%d",fEvent);
+  TTree * treeD = new TTree(hname,"Digits");
+  //treeD->Write(0,TObject::kOverwrite);
+  
+  // -- create Digits branch
+  Int_t bufferSize = 32000 ;    
+  TBranch * digitsBranch = treeD->Branch("PHOS",&fDigits,bufferSize);
+  digitsBranch->SetTitle("Default");
+  
+  // -- Create Digitizer branch
+  Int_t splitlevel = 0 ;
+  const AliPHOSRaw2Digits * d = this ;
+  TBranch * digitizerBranch = treeD->Branch("AliPHOSRaw2Digits", 
+                                           "AliPHOSRaw2Digits", &d,bufferSize,splitlevel); 
+  digitizerBranch->SetTitle("Default");
+  
+  digitsBranch->Fill() ;
+  digitizerBranch->Fill() ; 
+  treeD->Write(0,TObject::kOverwrite);
+  delete treeD ;
+
+  //Write header
+  gAlice->TreeE()->Fill();
+}
+//____________________________________________________________________________ 
+void AliPHOSRaw2Digits::Print(Option_t * option)const{
+  
+  cout << "----------AliPHOSRaw2Digits----------" << endl ;
+  cout << "Input stream " << endl ;
+  cout << "Current input  File: " << fInName.Data() << endl ;
+  cout << "Current output File: " << GetTitle() << endl ;
+  cout << "Events processes in the last file " << fEvent << endl ;
+  cout << "Input file status " ;
+  switch (fStatus){
+  case 0: cout << "`Have not processed yet' " << endl ;
+    break ;
+  case 1: cout << "`Processed normally' " << endl ;
+    break ;
+  case -1: cout << "`File not found'" << endl ;
+    break ;
+  case -2: cout << "`Error in reading' " << endl ;
+    break ;
+  case -3: cout << "'Interupted'" << endl ;
+  default: ;
+  }
+  cout << "Connection table: " ;
+  if(fctdb)
+    cout << fctdb->GetName() << "  " << fctdb->GetTitle() << endl ;
+  else
+    cout << " no DB " << endl ;
+  
+}
diff --git a/PHOS/AliPHOSRaw2Digits.cxx~ b/PHOS/AliPHOSRaw2Digits.cxx~
new file mode 100644 (file)
index 0000000..708ce90
--- /dev/null
@@ -0,0 +1,548 @@
+/**************************************************************************
+ * 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$ */
+
+//_________________________________________________________________________
+// Short description  
+//
+/*-- Author: Maxim Volkov (RRC KI)
+             Dmitri Peressounko (RRC KI & SUBATECH)
+             Yuri Kharlov (IHEP & SUBATECH)     */
+
+//////////////////////////////////////////////////////////////////////////////
+
+// --- ROOT system ---
+#include "TClonesArray.h"
+#include "TFile.h"
+#include "TTree.h"
+
+// --- Standard library ---
+#include <iostream.h>
+//#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <netinet/in.h>
+
+// --- AliRoot header files ---
+#include "AliPHOSDigit.h"
+#include "AliPHOSConTableDB.h"
+#include "AliPHOSBeamTestEvent.h"
+#include "AliPHOSRaw2Digits.h"
+#include "AliPHOSv1.h"
+#include "../EVGEN/AliGenBox.h"
+#include "AliRun.h"
+
+ClassImp(AliPHOSRaw2Digits)
+  
+  
+//____________________________________________________________________________ 
+  AliPHOSRaw2Digits::AliPHOSRaw2Digits():TTask() 
+{
+  fInName="";  
+  fMK1 = 0x0123CDEF ;
+  fMK2 = 0x80708070 ;
+  fMK3 = 0x4321ABCD ;
+  fMK4 = 0x80618061 ;
+  fCKW = 0x4640E400 ;
+  fDebug = kFALSE;             //  Debug flag
+  fIsInitialized = kFALSE ;
+  fTarget[0] = 0 ;
+  fTarget[1] = 0 ;
+  fTarget[2] = 0 ;
+  fDigits = 0 ;
+  fPHOSHeader =0 ;
+  fEvent = 0 ;
+  fctdb = 0;
+}
+//____________________________________________________________________________ 
+  AliPHOSRaw2Digits::AliPHOSRaw2Digits(const char * filename):TTask("Default","") 
+{
+  fInName=filename;
+  TString outname(fInName) ;
+  outname.ToLower() ;
+  outname.ReplaceAll(".fz",".root") ;
+  SetTitle(outname) ;
+
+  fMK1 = 0x0123CDEF ;
+  fMK2 = 0x80708070 ;
+  fMK3 = 0x4321ABCD ;
+  fMK4 = 0x80618061 ;
+  fCKW = 0x4640E400 ;
+  fDebug = kFALSE;             //  Debug flag
+  fIsInitialized = kFALSE ;
+  fTarget[0] = 0 ;
+  fTarget[1] = 0 ;
+  fTarget[2] = 0 ;
+  fDigits = 0 ;
+  fPHOSHeader =0 ;
+  fEvent = 0 ;
+  fctdb = 0;
+}
+
+//____________________________________________________________________________ 
+AliPHOSRaw2Digits::~AliPHOSRaw2Digits()
+{
+  if(fPHOSHeader)
+    fPHOSHeader->Delete() ;
+  if(fDigits){
+    fDigits->Delete() ;
+    delete fDigits ;
+  }
+  
+}
+//____________________________________________________________________________ 
+void AliPHOSRaw2Digits::Exec(Option_t * option){
+  //This is steering method performing all the conversion
+
+  if(!fIsInitialized) //need initialization
+    if(!Init())       //failed to initialize
+      return ;
+
+  ProcessRawFile() ;
+
+  FinishRun() ;
+} 
+//____________________________________________________________________________ 
+Bool_t AliPHOSRaw2Digits::Init(void){
+  //Create PHOS geometry, sets magnetic field to zero, 
+  //create Generator - to store target position, 
+  //opens out file, creates TreeE and make initialization of contaniers
+
+
+  if(fIsInitialized)
+    return kTRUE;
+
+  //Create PHOS
+  new AliPHOSv1("PHOS","GPS2") ;
+
+  //Set Magnetic field
+  gAlice->SetField(0,2);  
+
+  //Set positin of the virtex
+  AliGenBox *gener = new AliGenBox(1);
+  Float_t ox = fTarget[1]; 
+  Float_t oy = fTarget[2]-460.; 
+  Float_t oz = fTarget[0];
+  gener->SetOrigin(ox, oy, oz);
+
+  //  Create the output file
+  TString outname("") ;
+  if(strstr(GetTitle(),"root")){
+    outname=GetTitle();
+  }
+  else{
+    outname = fInName ;
+    outname.ToLower() ;
+    outname.ReplaceAll(".fz",".root") ;
+  }
+  TFile *rootfile = new TFile(outname,"recreate");
+  rootfile->SetCompressionLevel(2);
+
+  // Create the Root Trees
+  gAlice->MakeTree("E") ;
+
+  //Make container for digits
+  fDigits = new TClonesArray("AliPHOSDigit",1000) ;
+
+  //Fill now TreeE
+  fPHOSHeader = new  AliPHOSBeamTestEvent() ;
+  Int_t splitlevel = 0 ;
+  Int_t bufferSize = 32000 ;    
+  TBranch * headerBranch = gAlice->TreeE()->Branch("AliPHOSBeamTestEvent", 
+                                                  "AliPHOSBeamTestEvent", 
+                                                  &fPHOSHeader,bufferSize,splitlevel);
+  headerBranch->SetName("AliPHOSBeamTestEvent") ;
+
+  fIsInitialized = kTRUE ;
+  return kTRUE ;
+}
+//____________________________________________________________________________ 
+Bool_t AliPHOSRaw2Digits::ProcessRawFile(){
+
+  //Method opens zebra file and reads successively bytes from it,
+  //filling corresponding fields in header and digits.
+
+
+  fStatus= -3 ;
+  //First of all, open file and check if it is a zebra file
+
+  char command[256];
+  sprintf(command,"zcat %s",fInName.Data());
+  FILE *dataFile = popen(command, "r");
+  if (dataFile == NULL) {
+    cout << " Can not open file " << fInName.Data() << endl ;
+    perror(fInName.Data()) ;
+    fStatus = -1 ;
+    return kFALSE ;
+  }
+  printf("Open pipe: %s\n",command);
+
+//   Int_t dataFile = open(fInName.Data(), O_RDONLY);
+//   if(dataFile == -1){
+//     cout << " Can not open file " << fInName.Data() << endl ;
+//     perror(fInName.Data()) ;
+//     fStatus = -1 ;
+//     return kFALSE ;
+//   }
+
+  // Check if byte ordering is little-endian 
+  UInt_t w = 0x12345678;
+  Int_t swapo = memcmp(&w, "\x78\x56\x34\x12", sizeof(UInt_t)) == 0;
+  if(fDebug)
+    cout << "swapo=" << swapo << endl;
+  
+  
+  UInt_t recBuf[300] ;
+
+  // Read physical record control words 
+  UInt_t nb = 8*sizeof(UInt_t);
+  Int_t n = fread(recBuf, nb, 1, dataFile);
+//   Int_t n = read(dataFile, recBuf, nb);
+  if(static_cast<UInt_t>(n) != 1) {
+//   if(static_cast<UInt_t>(n) != nb) {
+    if (n < 0 )
+      perror(fInName.Data());
+    else
+      cout << "Could not read physical record control words" << endl;
+    fStatus = -2 ;
+    return kFALSE;
+  }
+
+  
+  if(fDebug)
+    cout << "recbuf[0] = " << recBuf[0] << endl ;
+  
+  // Check if it is a ZEBRA file and if the words are swapped 
+  UInt_t swapi = 0 ;
+  if (recBuf[0] != fMK1) {
+    Swab4(recBuf, &w, 1);
+    if (w != fMK1) {
+      cout << "Does not look like a ZEBRA file\n";
+      pclose(dataFile) ;
+      fStatus = -2 ;
+      return kFALSE;
+    }
+    swapi=1 ;
+  }
+  
+  if(fDebug){
+    cout << "        w = " << w << endl ;;
+    cout << "    swapi = " << swapi << endl ;;
+  }
+  
+  // Get number of words in physical record 
+  UInt_t  nwphr ;
+  if (swapi)
+    Swab4(&recBuf[4],&nwphr,1);
+  else 
+    nwphr = recBuf[4];
+  nwphr*=2; // 1998 -- Now we have 2 records 150 words each 
+
+
+  //start loop over data  
+  // Read rest of record 
+  nb = (nwphr-8)*sizeof(UInt_t);
+  n = fread(&recBuf[8], nb, 1, dataFile) ;
+//   n = read(dataFile, &recBuf[8], nb) ;
+  if (static_cast<UInt_t>(n) != 1) {
+    if (n < 0 ){
+      perror(fInName.Data());
+      fStatus = -2 ;
+      return kFALSE;
+    }
+  }
+  nb = nwphr *sizeof(UInt_t);
+
+  UInt_t userVector[16] ;
+  UInt_t zheader[12];    
+  UShort_t pattern ;
+  UShort_t scanning[32] ;
+  UShort_t charge[12];
+  UInt_t scaler[12]; 
+  UShort_t tdc2228[32];
+  
+  //read untill the end of file
+  fEvent=0 ;
+  while(1){
+
+    //    StartNewEvent() ;
+    fDigits->Delete() ;
+    gAlice->SetEvent(fEvent) ;
+         
+    Int_t i ;
+    for(i=0;i<16;i++)
+      userVector[i]=*(recBuf+21+i);
+    if(!swapi)
+      Swab4(userVector, userVector, 16);     
+    fPHOSHeader->SetUserVector(userVector) ;
+    
+    
+    // ZEBRA event header
+    for(i=0;i<12;i++)
+      zheader[i]=*(recBuf+47+i);
+    if(swapi)
+      Swab4(zheader, zheader, 12);
+    fPHOSHeader->SetHeader(zheader) ;
+    
+    // Swap input 
+    if (swapi)
+      Swab4(recBuf, recBuf, nwphr);
+    
+    /* Physical record control words */
+    UInt_t * recptr = recBuf;  //Pointer to current position
+
+    if(recptr[7] != 1) {
+      cout << "Can not handle fast blocks" << endl;
+      fStatus = -2 ;
+      return kFALSE;
+    }    
+    recptr += 8;
+    
+    // Logical record control words   
+    UInt_t lrtyp = recptr[1];
+    if (lrtyp != 3) {
+      cout << "Can not handle logical record type " <<  lrtyp << endl ;
+      fStatus = -2 ;
+      return kFALSE;
+    }
+    
+    recptr += 2;
+    if (recptr[0] != fCKW) {
+      cout <<  "Bad check word" << endl;
+      fStatus = -2 ;
+      return kFALSE;
+    }
+    
+    UInt_t  nwuh = recptr[9];
+    recptr += 10+nwuh;
+    
+    // Bank system words 
+    UInt_t nd = recptr[8];           /* Number of data words */
+    recptr += 10;
+    
+    // Data words 
+    UInt_t evtno = recptr[2];                  /* Event number */
+    
+    if(fDebug)
+      cout << "evtno=" << evtno << endl;
+    
+    UInt_t nh = recptr[4];                  /* Number of header words in data bank */
+    recptr += nh;
+    
+    // Unswap data from VME 
+    if (swapi)
+      Swab4(recptr, recptr, nd-nh-3);
+    
+    // Give buffer to monitor program 
+    //  UInt_t esize = nd-nh-3;
+    //    if (swapo)
+    //       Swab2(recptr, recptr, esize); 
+    // Two byte data are correct after this operation. 
+    //But we're in trouble if the data array contains 4 byte data!
+    
+    // From now on deal with VME data (MSB first, or network byte order).
+    
+    
+    // Fill the event with data from ADCs
+    UChar_t *byteptr=(UChar_t*)recptr;
+    
+    // Trigger bit register  
+    pattern=ntohs(*(UShort_t*)byteptr);
+    fPHOSHeader->SetPattern(pattern) ;
+    byteptr+=sizeof(UShort_t);
+    
+    // Either peak ADCs, 10 modulesX8=80 channels, 
+    //or Kurchatov 64+2 channel ADC 
+    //(the rest of the channels padded with 0xffff) 
+    for(i=0;i<80;i++){
+      Int_t peak = static_cast<Int_t>(ntohs(*(UShort_t*)byteptr));
+      //make digit
+      Int_t absID = fctdb->Raw2AbsId(i) ;
+      if(absID > 0)
+       new((*fDigits)[i])AliPHOSDigit(-1,absID,peak,0.,i) ;
+      if(fDebug){
+       if(peak>(UShort_t)1000)
+         cout << "event=" << fEvent << " peak[" << i << "] = "<<peak << endl;
+      }
+      byteptr+=sizeof(UShort_t);
+    }
+    
+    // Scanning ADCs, 4 modulesX8=32 channels
+    for(i=0;i<32;i++){
+      scanning[i]=ntohs(*(UShort_t*)byteptr);
+      byteptr+=sizeof(UShort_t);
+    }
+    fPHOSHeader->SetScanning(scanning) ;
+    
+    // Charge ADCs, 1 moduleX12=12 channels
+    for(i=0;i<12;i++){
+      charge[i]=ntohs(*(UShort_t*)byteptr);
+      byteptr+=sizeof(UShort_t);
+    }
+    fPHOSHeader->SetCharge(charge) ;
+    
+    // Scalers, 1 moduleX12=12 (4 byte) channels
+    for(i=0;i<12;i++){
+      scaler[i]=ntohl(*(UInt_t*)byteptr);
+      byteptr+=sizeof(UInt_t);
+    }
+    fPHOSHeader->SetScaler(scaler) ;
+    
+    // LeCroy TDC 2228A, 4 moduleX8=32 channels
+    for(i=0;i<8;i++){
+      tdc2228[i]=ntohs(*(UShort_t*)byteptr);
+      byteptr+=sizeof(UShort_t);
+    }
+    fPHOSHeader->SetTDC(tdc2228) ;
+
+    WriteDigits() ;
+    if(fDebug)
+      cout << "event=" << fEvent << " written " << endl;
+    // Read next record 
+    UInt_t nb = nwphr *sizeof(UInt_t);
+    n = fread( recBuf, nb,1,dataFile);
+//    n = read(dataFile, recBuf, nb) ;
+    if (n < 0 ){
+      perror(fInName);
+      fStatus = -2 ;
+      return kFALSE;
+    }
+    if (static_cast<UInt_t>(n) != 1) {
+      pclose(dataFile) ;
+      fStatus = 1 ;
+      return kTRUE ; //all read
+    }
+    fEvent++ ;
+  }
+  
+  fStatus = 1 ;  
+  return kTRUE ;  
+}
+//____________________________________________________________________________ 
+void AliPHOSRaw2Digits::Swab4(void *from, void *to, size_t nwords){
+  // The function swaps 4 bytes: byte#3<-->byte#0, byte#2<-->byte#1 
+  register char *pf=static_cast<char*>(from) ;
+  register char *pt=static_cast<char*>(to) ;
+  register char c;
+  while (nwords-- > 0 ) {
+    c = pf[0];
+    pt[0] = pf[3];
+    pt[3] = c;
+    c = pf[1];
+    pt[1] = pf[2];
+    pt[2] = c;
+    pf += 4;
+    pt += 4;
+  }
+}
+
+//____________________________________________________________________________ 
+void AliPHOSRaw2Digits::Swab2(void *from, void *to, size_t nwords)
+{ //The function swaps 2x2 bytes: byte#0<-->byte#1, byte#2<-->byte#3 
+  register char *pf=static_cast<char*>(from) ;
+  register char *pt=static_cast<char*>(to);
+  register char c;   
+  while (nwords-- > 0 ) {
+    c = pf[0];
+    pt[0] = pf[1];
+    pt[1] = c;
+    c = pf[2];
+    pt[2] = pf[3];
+    pt[3] = c;
+    pf += 4;
+    pt += 4;
+  }
+}
+
+//____________________________________________________________________________ 
+void AliPHOSRaw2Digits::FinishRun(){
+  //Write geometry and header tree
+  gAlice->Write(0,TObject::kOverwrite);
+  gAlice->TreeE()->Write(0,TObject::kOverwrite);
+  
+}
+//____________________________________________________________________________ 
+void AliPHOSRaw2Digits::WriteDigits(void){
+  //In this method we create TreeD, write digits and Raw2Digits to it
+  // and write Header to TreeE. Finally we write TreeD to root file 
+  
+  //Start from Digits
+  fDigits->Sort() ;
+  fDigits->Expand(fDigits->GetEntriesFast()) ;
+  for(Int_t i=0;i<fDigits->GetEntriesFast(); i++)
+    static_cast<AliPHOSDigit*>(fDigits->At(i))->SetIndexInList(i) ;
+
+  char hname[30];
+  sprintf(hname,"TreeD%d",fEvent);
+  TTree * treeD = new TTree(hname,"Digits");
+  //treeD->Write(0,TObject::kOverwrite);
+  
+  // -- create Digits branch
+  Int_t bufferSize = 32000 ;    
+  TBranch * digitsBranch = treeD->Branch("PHOS",&fDigits,bufferSize);
+  digitsBranch->SetTitle("Default");
+  
+  // -- Create Digitizer branch
+  Int_t splitlevel = 0 ;
+  const AliPHOSRaw2Digits * d = this ;
+  TBranch * digitizerBranch = treeD->Branch("AliPHOSRaw2Digits", 
+                                           "AliPHOSRaw2Digits", &d,bufferSize,splitlevel); 
+  digitizerBranch->SetTitle("Default");
+  
+  digitsBranch->Fill() ;
+  digitizerBranch->Fill() ; 
+  treeD->Write(0,TObject::kOverwrite);
+  delete treeD ;
+
+  //Write header
+  gAlice->TreeE()->Fill();
+}
+//____________________________________________________________________________ 
+void AliPHOSRaw2Digits::Print(Option_t * option)const{
+  
+  cout << "----------AliPHOSRaw2Digits----------" << endl ;
+  cout << "Input stream " << endl ;
+  cout << "Current input  File: " << fInName.Data() << endl ;
+  cout << "Current output File: " << GetTitle() << endl ;
+  cout << "Events processes in the last file " << fEvent << endl ;
+  cout << "Input file status " ;
+  switch (fStatus){
+  case 0: cout << "`Have not processed yet' " << endl ;
+    break ;
+  case 1: cout << "`Processed normally' " << endl ;
+    break ;
+  case -1: cout << "`File not found'" << endl ;
+    break ;
+  case -2: cout << "`Error in reading' " << endl ;
+    break ;
+  case -3: cout << "'Interupted'" << endl ;
+  default: ;
+  }
+  cout << "Connection table: " ;
+  if(fctdb)
+    cout << fctdb->GetName() << "  " << fctdb->GetTitle() << endl ;
+  else
+    cout << " no DB " << endl ;
+  
+}
diff --git a/PHOS/AliPHOSRaw2Digits.h b/PHOS/AliPHOSRaw2Digits.h
new file mode 100644 (file)
index 0000000..4e7bf7a
--- /dev/null
@@ -0,0 +1,75 @@
+#ifndef ALIPHOSRAW2DIGITS_H
+#define ALIPHOSRAW2DIGITS_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* $id */
+
+//_________________________________________________________________________
+//  Base Class for PHOS     
+//                  
+/*-- Author: Maxim Volkov (RRC KI)
+              Dmitri Peressounko (RRC KI & SUBATECH)
+              Yuri Kharlov (IHEP & SUBATECH)     */
+
+// --- ROOT system ---
+#include "TTask.h"
+class TClonesArray ;
+
+// --- Standard library ---
+
+// --- AliRoot header files ---
+class AliPHOSGeometry ;
+class AliPHOSBeamTestEvent ;
+class AliPHOSConTableDB ;
+
+class AliPHOSRaw2Digits : public TTask {
+
+public:
+  AliPHOSRaw2Digits() ;          // ctor
+  AliPHOSRaw2Digits(const char * inputFileName) ;         
+  virtual ~AliPHOSRaw2Digits() ; // dtor
+
+  void Exec(Option_t *option) ;
+
+  void SetInputFile(TString inname="Run_1234.fz"){fInName=inname ; }
+  void SetDebugLevel(Int_t idebug=1){fDebug=idebug ;}
+
+  //Set position of the target in the given run.
+  //The reference system is following
+  //Z axis along beam direction, from target to prototype (0-surface of prototype)
+  //X axis along columns of prototype (0-center of prototype)
+  //Y axis along raws of prototype    (0-center of prototype)
+  void SetTargetPosition(Double_t * pos)
+    {for(Int_t i=0;i<3;i++)fTarget[i]=pos[i] ;}
+  void SetConTableDB(AliPHOSConTableDB * ctdb){fctdb = ctdb ;}
+  void Print(Option_t *option="")const ;
+
+private:
+  void FinishRun() ;
+  Bool_t ProcessRawFile() ;
+  void Swab4(void *from, void *to, size_t nwords)  ;
+  void Swab2(void *from, void *to, size_t nwords)  ;
+  Bool_t Init() ;
+  void WriteDigits(void) ;
+
+  TClonesArray * fDigits ;             //!list of final digits
+  AliPHOSBeamTestEvent * fPHOSHeader ; //!
+  AliPHOSConTableDB * fctdb ;          //!
+  Double_t fTarget[3] ;                //!Position of the target
+  Int_t   fEvent ;         //
+  Int_t   fStatus ;        //status of input file: OK, not found etc.
+  TString fInName ;        // FileName of the input file
+  Bool_t  fDebug ;         //!
+  Bool_t  fIsInitialized ; //!
+  UInt_t  fMK1 ;     //!ZEBRA markers
+  UInt_t  fMK2 ;     //!
+  UInt_t  fMK3 ;     //!
+  UInt_t  fMK4 ;     //!
+  UInt_t  fCKW ;     //!
+
+  ClassDef(AliPHOSRaw2Digits,1)  // description 
+
+};
+
+#endif // AliPHOSRAW2DIGITS_H
diff --git a/PHOS/AliPHOSRaw2Digits.h~ b/PHOS/AliPHOSRaw2Digits.h~
new file mode 100644 (file)
index 0000000..095e5b3
--- /dev/null
@@ -0,0 +1,70 @@
+#ifndef ALIPHOSRAW2DIGITS_H
+#define ALIPHOSRAW2DIGITS_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* $id */
+
+//_________________________________________________________________________
+//  Base Class for PHOS     
+//                  
+/*-- Author: Maxim Volkov (RRC KI)
+              Dmitri Peressounko (RRC KI & SUBATECH)
+              Yuri Kharlov (IHEP & SUBATECH)     */
+
+// --- ROOT system ---
+#include "TTask.h"
+class TClonesArray ;
+
+// --- Standard library ---
+
+// --- AliRoot header files ---
+class AliPHOSGeometry ;
+
+class AliPHOSRaw2Digits : public TTask {
+
+public:
+  AliPHOSRaw2Digits() ;          // ctor
+  virtual ~AliPHOSRaw2Digits() ; // dtor
+
+  void Exec(Option_t *option) ;
+  Bool_t OpenOutFile() ;
+
+  void SetInputFile(TString inname="Run2002.rz"){fInName=inname ; }
+  void SetDebugLevel(Int_t idebug=1){fDebug=idebug ;}
+  void SetNRaws(Int_t nraws){fProtoRaws = nraws ;}
+  void SetNcols(Int_t ncolumns){fProtoColumns = ncolumns ;}
+  void Print(Option_t *option) ;
+
+private:
+  Bool_t ProcessRawFile() ;
+  void Swab4(void *from, void *to, size_t nwords)  ;
+  void Swab2(void *from, void *to, size_t nwords)  ;
+  Int_t RawId2AbsId(Int_t raw) ;
+  Bool_t Init() ;
+
+
+  TClonesArray * fBTHeaders ; //!list of beam test headers
+  AliPHOSGeometry * fGeom ;  //!
+  Int_t   fEvent ;   //!
+  Int_t   fStatus ;  //! status of input file: OK, not found etc.
+  TString fInName ;  //!FileName of the input file
+  Bool_t  fDebug ;   //!
+  Bool_t  fIsInitialized ;
+  Int_t   fProtoRaws ;
+  Int_t   fProtoColumns ;
+  Int_t   fRawOffset ;
+  Int_t   fColOffset ;
+  Int_t   fNcrInProto ; //!Number of cristalls in prototype
+  UInt_t *fAbsIdMap ;//[fNcrInProto] Map of correspondance between Raw and PHOS ID
+  UInt_t  fMK1 ;     //!ZEBRA markers
+  UInt_t  fMK2 ;     //!
+  UInt_t  fMK3 ;     //!
+  UInt_t  fMK4 ;     //!
+  UInt_t  fCKW ;     //!
+
+  ClassDef(AliPHOSRaw2Digits,1)  // description 
+
+};
+
+#endif // AliPHOSRAW2DIGITS_H
index 9a5c15beb62d7817b95a2c363efe133c28a2a9ef..96f6def7e7789ab9886b054d4e2203515e4f0f7c 100644 (file)
@@ -53,4 +53,8 @@
 #pragma link C++ class AliPHOSEvalRecPoint+;
 #pragma link C++ class AliPHOSPIDv1+;
 #pragma link C++ class AliPHOSMemoryWatcher+;
+#pragma link C++ class AliPHOSRaw2Digits+;
+#pragma link C++ class AliPHOSBeamTestEvent+;
+#pragma link C++ class AliPHOSCalibrationDB+;
+#pragma link C++ class AliPHOSConTableDB+;
 #endif
index 092286cf376313b36572100a514d2793625c6f5f..cb1fc11753da4bb12cceb6ba5de6fe7a9367b9b1 100644 (file)
@@ -21,7 +21,9 @@ SRCS          =    AliPHOS.cxx AliPHOSv0.cxx AliPHOSv1.cxx AliPHOSv2.cxx \
                  AliPHOSQAObjectCheckable.cxx AliPHOSQAChecker.cxx AliPHOSQAMeanChecker.cxx AliPHOSQAAlarm.cxx \
                  AliPHOSIhepAnalyze.cxx AliPHOSEvalRecPoint.cxx \
                  AliPHOSRecManager.cxx AliPHOSRecCpvManager.cxx AliPHOSRecEmcManager.cxx \
-                 AliPHOSClusterizerv2.cxx AliPHOSPIDv1.cxx AliPHOSMemoryWatcher.cxx 
+                 AliPHOSClusterizerv2.cxx AliPHOSPIDv1.cxx AliPHOSMemoryWatcher.cxx \
+                AliPHOSRaw2Digits.cxx AliPHOSBeamTestEvent.cxx AliPHOSCalibrationDB.cxx \
+                AliPHOSConTableDB.cxx
 
 HDRS:= $(SRCS:.cxx=.h)