Decoupled ITS/UPGRADE cmake stuff from ITS
authorshahoian <shahoian@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 1 Aug 2012 16:29:34 +0000 (16:29 +0000)
committershahoian <shahoian@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 1 Aug 2012 16:29:34 +0000 (16:29 +0000)
19 files changed:
ITS/UPGRADE/AliITSCalibrationPixUpg.cxx [new file with mode: 0644]
ITS/UPGRADE/AliITSCalibrationPixUpg.h [new file with mode: 0644]
ITS/UPGRADE/AliITSDetTypeSimUpg.cxx [new file with mode: 0644]
ITS/UPGRADE/AliITSDetTypeSimUpg.h [new file with mode: 0644]
ITS/UPGRADE/AliITSUpg.h
ITS/UPGRADE/AliITSdigitPixUpg.cxx [new file with mode: 0644]
ITS/UPGRADE/AliITSdigitPixUpg.h [new file with mode: 0644]
ITS/UPGRADE/AliITSresponsePixUpg.cxx [new file with mode: 0644]
ITS/UPGRADE/AliITSresponsePixUpg.h [new file with mode: 0644]
ITS/UPGRADE/AliITSsegmentationPixUpg.cxx
ITS/UPGRADE/AliITSsegmentationPixUpg.h
ITS/UPGRADE/AliITSsimulationPixUpg.cxx [new file with mode: 0644]
ITS/UPGRADE/AliITSsimulationPixUpg.h [new file with mode: 0644]
ITS/UPGRADE/CMakelibITSUpgradeBase.pkg [moved from ITS/CMakelibITSUpgradeBase.pkg with 91% similarity]
ITS/UPGRADE/CMakelibITSUpgradeRec.pkg [moved from ITS/CMakelibITSUpgradeRec.pkg with 86% similarity]
ITS/UPGRADE/CMakelibITSUpgradeSim.pkg [moved from ITS/CMakelibITSUpgradeSim.pkg with 92% similarity]
ITS/UPGRADE/ITSUpgradeBaseLinkDef.h [moved from ITS/ITSUpgradeBaseLinkDef.h with 82% similarity]
ITS/UPGRADE/ITSUpgradeRecLinkDef.h [moved from ITS/ITSUpgradeRecLinkDef.h with 100% similarity]
ITS/UPGRADE/ITSUpgradeSimLinkDef.h [moved from ITS/ITSUpgradeSimLinkDef.h with 94% similarity]

diff --git a/ITS/UPGRADE/AliITSCalibrationPixUpg.cxx b/ITS/UPGRADE/AliITSCalibrationPixUpg.cxx
new file mode 100644 (file)
index 0000000..7ce9319
--- /dev/null
@@ -0,0 +1,289 @@
+/**************************************************************************
+ * 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.                  *
+ **************************************************************************/
+#include "TArrayI.h"
+#include "AliITSCalibrationPixUpg.h"
+
+///////////////////////////////////////////////////////////////////////////
+//
+//  Calibration class for set:ITS                   
+//  Specific subdetector implementation for         
+//  Silicon pixels                                  
+//
+//  Modified by D. Elia, G.E. Bruno, H. Tydesjo
+//  Adapted for upgrade ruben.shahoyan@cern.ch
+//
+///////////////////////////////////////////////////////////////////////////
+
+ClassImp(AliITSCalibrationPixUpg)
+
+//______________________________________________________________________
+AliITSCalibrationPixUpg::AliITSCalibrationPixUpg() 
+: fNChips(0)
+  ,fNColPerChip(0)
+  ,fNCol(0)
+  ,fNRow(0)
+  ,fNrBad(0)
+  ,fBadChips(0)
+  ,fBadChannels(0)
+{
+  // constructor
+   SetDataType("simulated");
+   ClearBad();
+}
+
+//______________________________________________________________________
+AliITSCalibrationPixUpg::AliITSCalibrationPixUpg(Short_t nChips,Short_t nColPerChip,Short_t nRow) 
+: fNChips(0)
+  ,fNColPerChip(0)
+  ,fNCol(0)
+  ,fNRow(0)
+  ,fNrBad(0)
+  ,fBadChips(0)
+  ,fBadChannels(0)
+{
+  // constructor
+   SetDataType("simulated");
+   SetColRowData(nChips,nColPerChip,nRow);
+   ClearBad();
+}
+
+//______________________________________________________________________
+AliITSCalibrationPixUpg::AliITSCalibrationPixUpg(const AliITSCalibrationPixUpg &src) : 
+  AliITSCalibration(src)
+  ,fNChips(src.fNChips)
+  ,fNColPerChip(src.fNColPerChip)
+  ,fNCol(src.fNCol)
+  ,fNRow(src.fNRow)
+  ,fNrBad(src.fNrBad)
+  ,fBadChips(src.fBadChips)
+  ,fBadChannels(src.fBadChannels)
+{
+}
+
+//____________________________________________________________________________
+void AliITSCalibrationPixUpg::ClearBad() 
+{
+  // clear all bad pixels (single+chips)
+  fBadChannels.Reset();
+  fNrBad=0;
+  fBadChips = 0;
+  //
+}
+
+//____________________________________________________________________________
+void AliITSCalibrationPixUpg::AddBad(Int_t col, Int_t row) 
+{
+  // add single bad pixel 
+  fBadChannels.Set(fNrBad*2+2);
+  fBadChannels.AddAt(col,fNrBad*2);
+  fBadChannels.AddAt(row,fNrBad*2+1);
+  fNrBad++;
+}
+
+//____________________________________________________________________________
+void AliITSCalibrationPixUpg::SetChipBad(Int_t chip) 
+{
+  // set full chip bad
+  if ((int)chip>=fNChips) {AliError(Form("chip number %d exceeds allowed limit %d",chip,fNChips)); return;}
+  fBadChips |= 0x1<<chip;
+  //
+}
+
+//____________________________________________________________________________
+void AliITSCalibrationPixUpg::UnSetChipBad(Int_t chip) 
+{
+  // unset full chip bad
+  if (chip>=fNChips) {AliError(Form("chip number %d exceeds allowed limit %d",chip,fNChips)); return;}
+  fBadChips &= ~(0x1<<chip);
+  //
+}
+
+//____________________________________________________________________________
+Int_t AliITSCalibrationPixUpg::GetBadColAt(Int_t index) const 
+{
+  // Get column of index-th bad pixel
+  int nrc = fNColPerChip*fNRow;
+  if (nrc<1) AliFatal("Number of colums and rows is not set");
+  //
+  if ((Int_t)index<GetNrBadSingle()) return fBadChannels.At(index*2);
+  else {
+    Int_t badChipIndex=(index-GetNrBadSingle())/nrc;
+    Int_t badChipsFound =0;
+    for (int chip=fNChips; chip--;) {
+      if (IsChipMarkedBad(chip)) badChipsFound++;
+      if (badChipIndex==badChipsFound-1) {
+       Int_t badPixelIndex=(index-GetNrBadSingle())%(nrc);
+       return chip*fNColPerChip + badPixelIndex/fNRow;
+      }
+    }
+  }
+  AliError(Form("Index %d is out of bounds - returning -1",index));
+  return -1;
+}
+
+//____________________________________________________________________________
+Int_t AliITSCalibrationPixUpg::GetBadRowAt(Int_t index) const 
+{
+  // Get row of index-th bad pixel
+  int nrc = fNColPerChip*fNRow;
+  if (nrc<1) AliFatal("Number of colums and rows is not set");
+  //
+  if ((Int_t)index<GetNrBadSingle()) return fBadChannels.At(index*2+1);
+  else {
+    Int_t badChipIndex=(index-GetNrBadSingle())/nrc;
+    Int_t badChipsFound =0;
+    for (int chip=fNChips; chip--;) {
+      if (IsChipMarkedBad(chip)) badChipsFound++;
+      if (badChipIndex==badChipsFound-1) {
+       Int_t badPixelIndex=(index-GetNrBadSingle())%nrc;
+       return badPixelIndex%fNRow;
+      }
+    }
+  }
+  AliError(Form("Index %d is out of bounds - returning -1",index));
+  return -1;
+}
+
+//____________________________________________________________________________
+void AliITSCalibrationPixUpg::GetBadPixel(Int_t index, Int_t &row, Int_t &col) const 
+{
+  // i: is the i-th bad pixel in single bad pixel list
+  // row: is the corresponding row (-1 if i is out of range)
+  // col: is the corresponding column (-1 if i is out of range)
+  row = -1;
+  col = -1;
+  if(index>=0 && index<GetNrBadSingle()){
+    col = GetBadColAt(index);
+    row = GetBadRowAt(index);
+    return;
+  }
+  else {
+    if (index>=0) {
+      int nrc = fNColPerChip*fNRow;
+      if (nrc<1) AliFatal("Number of colums and rows is not set");
+      Int_t badChipIndex=(index-GetNrBadSingle())/nrc;
+      Int_t badChipsFound =0;
+      for (int chip=fNChips; chip--;) {
+       if (IsChipMarkedBad(chip)) badChipsFound++;
+       if (badChipIndex==badChipsFound-1) {
+         Int_t badPixelIndex=(index-GetNrBadSingle())%nrc;
+         col = chip*fNColPerChip + badPixelIndex/fNRow;
+         row = badPixelIndex%fNRow;
+         return;
+       }
+      }
+    }
+  }
+  AliError(Form("Index %d is out of bounds - nothing done",index));
+}
+
+//___________________________________________________________________________
+Int_t  AliITSCalibrationPixUpg::GetNrBad() const 
+{
+  // Total number of bad pixels (including bad chips) in a given module
+  Int_t bad=0;
+  // single pixels:
+  bad += fNrBad;
+  // whole chips:
+  for (int chip=fNChips; chip--;) if (IsChipMarkedBad(chip)) bad += fNColPerChip*fNRow;
+  return bad;
+}
+
+//___________________________________________________________________________
+Int_t  AliITSCalibrationPixUpg::GetNrBadInChip(Int_t chip) const 
+{
+  // Total number of bad pixels (including bad chips) in a given chip
+  if(chip<0 || chip>=fNChips) {AliError("Wrong chip number"); return -1;}
+  if (IsChipMarkedBad(chip)) return fNColPerChip*fNRow;
+  else {
+    Int_t bad=0;
+    for (int i=fNrBad; i--;) {
+      Int_t col = GetBadColAt(i);
+      if (col!=-1) if (GetChipIndexFromCol(col)==chip) bad++;
+    }
+    return bad;
+  }
+}
+
+//___________________________________________________________________________
+Int_t  AliITSCalibrationPixUpg::GetNrBadInColumn(Int_t col) const 
+{
+  // Total number of bad pixels (including bad chips) in a given column: col. range
+  if(col<0 || col>=fNCol) {AliError("Wrong column number"); return -1;}
+  if (IsChipMarkedBad(GetChipIndexFromCol(col))) return fNRow;
+  else {
+    Int_t bad=0;
+    for (int i=fNrBad; i--;) if (GetBadColAt(i)==col) bad++;
+    return bad;
+  }
+}
+
+//______________________________________________________________________
+Bool_t AliITSCalibrationPixUpg::IsBad() const 
+{
+  // Are all chips of this module bad?
+  for (Int_t chip=fNChips; chip--;) if (!IsChipMarkedBad(chip)) return kFALSE;
+  return kTRUE;
+}
+
+//______________________________________________________________________
+Bool_t AliITSCalibrationPixUpg::IsChipBad(Int_t chip) const 
+{
+  // Is the full chip bad?
+  return (GetNrBadInChip(chip)==fNColPerChip*fNRow);
+}
+
+//______________________________________________________________________
+Bool_t AliITSCalibrationPixUpg::IsColumnBad(Int_t col) const 
+{
+  // Is the full column bad?
+  return (GetNrBadInColumn(col)==fNRow);
+}
+
+//____________________________________________________________________________
+Bool_t AliITSCalibrationPixUpg::IsPixelBad(Int_t col, Int_t row) const 
+{
+  // Is this pixel bad?
+  if(col<0 || col>=fNCol) {AliError("Wrong column number"); return kFALSE;}
+  Int_t chip = GetChipIndexFromCol(col);
+  if (IsChipMarkedBad(chip)) return kTRUE;
+  for (Int_t i=fNrBad; i--;) if (GetBadColAt(i)==col && GetBadRowAt(i)==row) return kTRUE;
+  return kFALSE;
+}
+
+//______________________________________________________________________
+Int_t AliITSCalibrationPixUpg::GetChipIndexFromCol(Int_t col) const 
+{
+  // returns chip index for specific column
+  if(col>=fNCol) {AliWarning("Wrong column number"); return -1;}
+  return col/fNColPerChip;
+}
+
+//______________________________________________________________________
+void AliITSCalibrationPixUpg::SetNrBad(Int_t /*nr*/) 
+{
+  // should not be used anymore !!!
+  AliError("This method should not be used anymore. Use SetNrBadSingle instead!!!");
+}
+
+//____________________________________________________________________________
+void  AliITSCalibrationPixUpg::SetColRowData(Short_t nchip, Short_t ncolperchip, Short_t nrow) 
+{
+  // set segmentation data
+  fNChips = nchip; 
+  fNCol   = nchip*ncolperchip; 
+  fNRow   = nrow; 
+  fNColPerChip = ncolperchip;
+}
diff --git a/ITS/UPGRADE/AliITSCalibrationPixUpg.h b/ITS/UPGRADE/AliITSCalibrationPixUpg.h
new file mode 100644 (file)
index 0000000..8da3efe
--- /dev/null
@@ -0,0 +1,81 @@
+#ifndef ALIITSCALIBRATIONPIXUPG_H
+#define ALIITSCALIBRATIONPIXUPG_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* $Id: AliITSCalibrationPixUpg.h 53595 2011-12-14 16:13:16Z masera $ */
+//#include "TRandom.h"
+#include "AliITSCalibration.h"
+#include "TArrayS.h"
+
+////////////////////////////////////////////////////
+//                                                //
+// ITS response class for pixels                  //
+////////////////////////////////////////////////////
+
+class AliITSCalibrationPixUpg :  public AliITSCalibration {
+ public:
+    AliITSCalibrationPixUpg(); // default constructor
+    AliITSCalibrationPixUpg(Short_t nChips,Short_t nColPerChip,Short_t nRow); // default constructor
+    AliITSCalibrationPixUpg(const AliITSCalibrationPixUpg &src);
+    //    
+    virtual ~AliITSCalibrationPixUpg() {;} // destructror
+
+    virtual void   ClearBad();
+
+    virtual Int_t  GetNrBad() const;
+    virtual Int_t  GetNrBadInChip(Int_t chip) const;
+    virtual Int_t  GetNrBadInColumn(Int_t col) const;
+
+    virtual Int_t  GetBadColAt(Int_t index) const;
+    virtual Int_t  GetBadRowAt(Int_t index) const;
+    virtual void   GetBadPixel(Int_t index, Int_t &row, Int_t &col) const;
+
+    virtual Int_t  GetNrBadSingle() const {return fNrBad;}
+    virtual void   SetNrBadSingle(Int_t nr) {fNrBad=nr;} // used to be called SetNrBad, but misleading
+    virtual void   SetBadList(TArrayS badlist) {fBadChannels=badlist;}
+    virtual void   SetNrBad(Int_t /*nr*/); // Use SetNrBadSingle!!!
+
+    virtual Bool_t IsBad() const;
+    virtual Bool_t IsChipBad(Int_t chip) const;
+    virtual Bool_t IsColumnBad(Int_t col) const;
+    virtual Bool_t IsPixelBad(Int_t col, Int_t row) const;
+
+    virtual void   SetChipBad(Int_t chip);
+    virtual void   UnSetChipBad(Int_t chip);
+    Bool_t         IsChipMarkedBad(Int_t c) const {return (fBadChips&(0x1<<c))!=0;}
+
+    virtual void   AddBad(Int_t col, Int_t row);
+
+    virtual Int_t  GetChipIndexFromCol(Int_t col) const;
+    //    virtual Int_t  GetChipFromChipIndex(Int_t index) const;
+
+    virtual void   GiveCompressParam(Int_t *)   const {NotImplemented("GiveCompressParam");}
+    virtual void   SetDetParam(Double_t *)            {NotImplemented("SetDetParam");}
+    virtual void   GetDetParam(Double_t *)      const {NotImplemented("GetDetParam");}
+    virtual void   SetNDetParam(Int_t /*n*/)          {NotImplemented("SetNDetParam");}
+    virtual Int_t  NDetParam()                  const {NotImplemented("NDetParam"); return 0;}
+    virtual void   SetSigmaSpread(Double_t, Double_t) {NotImplemented("SetSigmaSpread");}
+    virtual void   SigmaSpread(Double_t & /* p1 */,Double_t & /* p2 */) const {NotImplemented("SigmaSpread");}
+    //
+    void    SetColRowData(Short_t nchip, Short_t ncolperchip, Short_t nrow);
+    Int_t   GetNCol()         const {return fNCol;}
+    Int_t   GetNRow()         const {return fNRow;}
+    Int_t   GetNColPerChip()  const {return fNColPerChip;}
+    Int_t   GetNChips()       const {return fNChips;}
+    //
+ protected:
+    Short_t  fNChips;          // n of chips
+    Short_t  fNColPerChip;     // n of columns per chip
+    Short_t  fNCol;            // number of columns
+    Short_t  fNRow;            // number of rows
+    Int_t    fNrBad;           // Nr of SINGLE bad pixels
+    UInt_t   fBadChips;        // bit pattern of completely dead chips?
+    TArrayS  fBadChannels;     // Array with bad channels info (col0,row0,col1...rowN) N = fNrBad
+    //
+    AliITSCalibrationPixUpg& operator=(const AliITSCalibrationPixUpg& source);
+    //
+    ClassDef(AliITSCalibrationPixUpg,1) // pixels response
+};
+
+#endif
diff --git a/ITS/UPGRADE/AliITSDetTypeSimUpg.cxx b/ITS/UPGRADE/AliITSDetTypeSimUpg.cxx
new file mode 100644 (file)
index 0000000..f7f21ef
--- /dev/null
@@ -0,0 +1,578 @@
+/***************************************************************************
+ * 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: AliITSDetTypeSimUpg.cxx 56993 2012-06-08 08:24:17Z fca $
+*/
+
+
+/////////////////////////////////////////////////////////////////////
+// Base simulation functions for ITS upgrade                       //
+//                                                                 //
+//                                                                 //
+/////////////////////////////////////////////////////////////////////          
+#include "TBranch.h"
+#include "TClonesArray.h"
+#include "TObjArray.h"
+#include "TTree.h"
+
+#include "AliRun.h"
+
+#include "AliCDBManager.h"
+#include "AliCDBId.h"
+#include "AliCDBStorage.h"
+#include "AliCDBEntry.h"
+#include "AliCDBMetaData.h"
+#include "AliITSdigit.h"
+#include "AliITSdigitPixUpg.h"
+#include "AliITSgeom.h"
+#include "AliITSDetTypeSimUpg.h"
+#include "AliITSpListItem.h"
+#include "AliITSCalibration.h"
+#include "AliITSsimulation.h"
+#include "AliITSTriggerConditions.h"
+#include "AliITSsegmentation.h"
+#include "AliITSsegmentationPixUpg.h"
+#include "AliBaseLoader.h"
+
+using std::endl;
+using std::cout;
+ClassImp(AliITSDetTypeSimUpg)
+
+const char* AliITSDetTypeSimUpg::fgkDetTypeName[AliITSDetTypeSimUpg::kNDetTypes] = {"PixUpg"};
+
+
+//----------------------------------------------------------------------
+AliITSDetTypeSimUpg::AliITSDetTypeSimUpg():
+TObject(),
+fSimulation(),   // [NDet]
+fSegmentation(), // [NDet]
+fCalibration(),     // [NMod]
+fNSDigits(0),    //! number of SDigits
+fSDigits("AliITSpListItem",1000),   
+fNDigits(0),     //! number of Digits
+fRunNumber(0),   //! Run number (to access DB)
+fDigits(),       //! [NMod][NDigits]
+fSimuPar(0),
+fkDigClassName(), // String with digit class name.
+fLoader(0),      // local pointer to loader
+fFirstcall(kTRUE),
+fTriggerConditions(NULL)
+{ 
+  // Default Constructor
+  // Inputs:
+  //    none.
+  // Outputs:
+  //    none.
+  // Return:
+  //    A properly zero-ed AliITSDetTypeSimUpg class.
+  for (int i=kNDetTypes;i--;) fDetNModules[i] = 0;
+  fSimulation   = new TObjArray(kNDetTypes);
+  fSegmentation = new TObjArray(kNDetTypes);
+  fSegmentation->SetOwner(kTRUE);
+  fDigits = new TObjArray(kNDetTypes);
+  fNDigits = new Int_t[kNDetTypes];
+  fSimuPar= new AliITSSimuParam();
+  SetRunNumber();
+}
+
+//----------------------------------------------------------------------
+AliITSDetTypeSimUpg::~AliITSDetTypeSimUpg()
+{
+  // Destructor
+  // Inputs:
+  //    none.
+  // Outputs:
+  //    none.
+  // Return:
+  //    Nothing.
+  
+  if(fSimulation){
+    fSimulation->Delete();
+    delete fSimulation;
+  }
+  //
+  if(fSegmentation){
+    fSegmentation->Delete();
+    delete fSegmentation;
+  }
+  //
+  if(fCalibration && fRunNumber<0){
+    fCalibration->Delete();
+    delete fCalibration;
+  }
+  //
+  delete fSimuPar;
+  delete[] fNDigits;
+  //
+  if (fLoader)fLoader->GetModulesFolder()->Remove(this); // Not deleting it.
+  fSDigits.Delete();
+  if (fDigits) {
+    fDigits->Delete();
+    delete fDigits;
+  }
+  //
+}
+
+//______________________________________________________________________
+void AliITSDetTypeSimUpg::SetITSgeom(AliITSgeom *geom)
+{
+  // Sets/replaces the existing AliITSgeom object kept in AliITSLoader
+    // 
+    // Inputs:
+    //   AliITSgoem   *geom  The AliITSgeom object to be used.
+    // Output:
+    //   none.
+    // Return:
+    //   none.
+  if(!fLoader){
+    Error("SetITSgeom","No pointer to loader - nothing done");
+    return;
+  }
+  else {
+    fLoader->SetITSgeom(geom);  // protections in AliITSLoader::SetITSgeom
+  }
+}
+
+//______________________________________________________________________
+void AliITSDetTypeSimUpg::SetLoader(AliITSLoader *loader)
+{
+  // Sets the local copy of the AliITSLoader, and passes on the
+  // AliITSgeom object as needed.
+  // Inputs
+  //   AliITSLoader  *loader pointer to AliITSLoader for local use
+  // Outputs:
+  //   none.
+  // Return:
+  //  none.
+  
+  if(fLoader==loader) return; // Same do nothing
+  if(fLoader){ // alread have an existing loader
+    Error("SetLoader","Already have an exisiting loader ptr=%p Nothing done",fLoader);
+  } // end if
+  fLoader = loader;
+}
+
+//______________________________________________________________________
+void AliITSDetTypeSimUpg::SetSimulationModel(Int_t dettype,AliITSsimulation *sim)
+{
+  //Set simulation model for detector type
+  if(fSimulation==0) fSimulation = new TObjArray(kNDetTypes);
+  fSimulation->AddAt(sim,dettype);
+}
+
+//______________________________________________________________________
+AliITSsimulation* AliITSDetTypeSimUpg::GetSimulationModel(Int_t dettype) const 
+{ 
+  //Get simulation model for detector type
+  if(fSimulation==0)  {
+    Warning("GetSimulationModel","fSimulation is 0!");
+    return 0;     
+  }
+  return (AliITSsimulation*)(fSimulation->At(dettype));
+}
+
+//______________________________________________________________________
+AliITSsimulation* AliITSDetTypeSimUpg::GetSimulationModelByModule(Int_t module) const 
+{
+  //Get simulation model by module number
+  if(GetITSgeom()==0) {
+    Warning("GetSimulationModelByModule","GetITSgeom() is 0!");
+    return 0;
+  }
+  
+  return GetSimulationModel(GetITSgeom()->GetModuleType(module));
+}
+
+//_______________________________________________________________________
+void AliITSDetTypeSimUpg::SetDefaultSegmentation(Int_t idet)
+{
+  // Set default segmentation model objects
+  AliITSsegmentation *seg;
+  //  
+  if(fSegmentation==0x0){
+    fSegmentation = new TObjArray(kNDetTypes);
+    fSegmentation->SetOwner(kTRUE);
+  }
+  if (GetSegmentationModel(idet)) delete (AliITSsegmentation*)fSegmentation->RemoveAt(idet);
+  //
+  switch (idet) 
+    {
+    case kDetPixUpg: seg = new AliITSsegmentationPixUpg(); break;
+    default        : AliFatal(Form("Uknown detector type %d",idet));
+  };
+  SetSegmentationModel(idet,seg);
+  //
+}
+
+//______________________________________________________________________
+void AliITSDetTypeSimUpg::SetSegmentationModel(Int_t dettype, AliITSsegmentation *seg)
+{
+  // Set segmentation model for detector type
+  if(fSegmentation==0x0){
+    fSegmentation = new TObjArray(kNDetTypes);
+    fSegmentation->SetOwner(kTRUE);
+  }
+  fSegmentation->AddAt(seg,dettype);
+}
+
+//______________________________________________________________________
+AliITSsegmentation* AliITSDetTypeSimUpg::GetSegmentationModel(Int_t dettype) const
+{
+  //Get segmentation model for detector type
+  
+  if(fSegmentation==0) {
+    Warning("GetSegmentationModel","fSegmentation is 0!");
+    return 0; 
+  } 
+  return (AliITSsegmentation*)(fSegmentation->At(dettype));
+}
+
+//_______________________________________________________________________
+AliITSsegmentation* AliITSDetTypeSimUpg::GetSegmentationModelByModule(Int_t module) const
+{
+  //Get segmentation model by module number
+  if(GetITSgeom()==0) {
+    Warning("GetSegmentationModelByModule","GetITSgeom() is 0!");
+    return 0;
+  }     
+  return GetSegmentationModel(GetITSgeom()->GetModuleType(module));
+  //
+}
+
+//_______________________________________________________________________
+void AliITSDetTypeSimUpg::CreateCalibrationArray() 
+{
+  //Create the container of calibration functions with correct size
+  if (fCalibration) {
+    Warning("CreateCalibration","pointer to calibration object exists\n");
+    fCalibration->Delete();
+    delete fCalibration;
+  }
+  //
+  Int_t nModTot = GetITSgeom()->GetIndexMax();
+  fCalibration = new TObjArray(nModTot);
+  fCalibration->SetOwner(kTRUE);
+  fCalibration->Clear();
+}
+
+//_______________________________________________________________________
+void AliITSDetTypeSimUpg::SetCalibrationModel(Int_t iMod, AliITSCalibration *resp)
+{
+  //Set response model for modules
+  
+  if (fCalibration==0) CreateCalibrationArray();
+  
+  if (fCalibration->At(iMod)!=0) delete (AliITSCalibration*) fCalibration->At(iMod);
+  fCalibration->AddAt(resp, iMod);
+}
+
+//______________________________________________________________________
+void AliITSDetTypeSimUpg::ResetCalibrationArray() 
+{
+  //resets response array
+  fCalibration->Clear();
+}
+
+//______________________________________________________________________
+void AliITSDetTypeSimUpg::ResetSegmentation()
+{
+  //Resets segmentation array
+  if(fSegmentation) fSegmentation->Clear();
+}
+
+//_______________________________________________________________________
+AliITSCalibration* AliITSDetTypeSimUpg::GetCalibrationModel(Int_t iMod) const 
+{
+  //Get response model for module number iMod 
+  //
+  if(fCalibration==0) {
+    AliError("fCalibration is 0!");
+    return 0; 
+  }
+  return (AliITSCalibration*)fCalibration->At(iMod);
+}
+
+//_______________________________________________________________________
+void AliITSDetTypeSimUpg::SetDefaults()
+{
+  //Set defaults for segmentation and response
+  
+  if(GetITSgeom()==0){
+    Warning("SetDefaults","GetITSgeom() is 0!");
+    return;
+  } // end if
+  if (fCalibration==0) {
+    CreateCalibrationArray();
+  } // end if
+  
+  ResetSegmentation();
+  if(!GetCalibration()){AliFatal("Exit"); exit(0);}
+  
+  SetDigitClassName(0,"AliITSdigitPixUpg");
+  //  
+  for(Int_t idet=0;idet<kNDetTypes;idet++){
+    if(!GetSegmentationModel(idet)) SetDefaultSegmentation(idet);
+  }
+  //
+}
+
+//______________________________________________________________________
+Bool_t AliITSDetTypeSimUpg::GetCalibration() {
+  // Get Default calibration if a storage is not defined.
+
+  if(!fFirstcall){
+    AliITSCalibration* cal = GetCalibrationModel(0);
+    if(cal)return kTRUE;
+  }
+  else {
+    fFirstcall = kFALSE;
+  }
+  
+  SetRunNumber((Int_t)AliCDBManager::Instance()->GetRun());
+  Int_t run=GetRunNumber();
+  
+  Bool_t isCacheActive = kTRUE;
+  if (run) {
+    isCacheActive=kFALSE;
+    fCalibration->SetOwner(kTRUE);
+  }
+  else{
+    fCalibration->SetOwner(kFALSE);
+  }
+  
+  AliCDBManager::Instance()->SetCacheFlag(isCacheActive);
+  //
+  // TO DO, RS
+  return kTRUE;
+}
+
+//_______________________________________________________________________
+void AliITSDetTypeSimUpg::SetDefaultSimulation()
+{
+  //Set default simulation for detector type
+  //
+  if (GetITSgeom()==0) {
+    Warning("SetDefaultSimulation","GetITSgeom() is 0!");
+    return;
+  }
+  if (fCalibration==0) {
+    Warning("SetDefaultSimulation","fCalibration is 0!");
+    return;
+  }
+  if (fSegmentation==0) {
+    Warning("SetDefaultSimulation","fSegmentation is 0!");
+    for (Int_t i=0;i<kNDetTypes;i++) SetDefaultSegmentation(i);
+  } else for(Int_t i=0;i<kNDetTypes;i++) if(!GetSegmentationModel(i)){
+       Warning("SetDefaultSimulation",
+               "Segmentation not defined for det %d - Default taken\n!",i);
+       SetDefaultSegmentation(i);
+      }
+  //
+  AliITSsimulation* sim;
+  //
+  for (Int_t idet=0;idet<kNDetTypes;idet++) {
+    //OixUpg
+    if(idet==0){
+      sim = GetSimulationModel(idet); 
+      if(!sim){
+       sim = new AliITSsimulationPixUpg(this);
+       SetSimulationModel(idet,sim);
+      }
+    }
+  }
+}
+
+//___________________________________________________________________
+void AliITSDetTypeSimUpg::SetTreeAddressS(TTree* treeS, const Char_t* name)
+{
+  // Set branch address for the ITS summable digits Trees.  
+
+  if(!treeS) return;
+  TBranch *branch;
+  branch = treeS->GetBranch(name);
+  TClonesArray *sdigi = &fSDigits;
+  if (branch) branch->SetAddress(&sdigi);
+
+}
+
+//___________________________________________________________________
+void AliITSDetTypeSimUpg::SetTreeAddressD(TTree* treeD, const Char_t* name)
+{
+  // Set branch address for the digit Trees.
+  TBranch *branch; 
+  TString branchname;
+  //
+  if(!treeD) return;
+  //
+  if(!fDigits) fDigits = new TObjArray(kNDetTypes); 
+  //
+  for(Int_t i=0;i<kNDetTypes;i++){
+    const Char_t* digclass = GetDigitClassName(i);
+    if(digclass==0x0){
+      if(i==0) SetDigitClassName(i,Form("AliITSdigit%s",fgkDetTypeName[i]));
+      digclass = GetDigitClassName(i);
+    }
+    TString classn = digclass;
+    if(!(fDigits->At(i))){
+      fDigits->AddAt(new TClonesArray(classn.Data(),1000),i);
+    }else{
+      ResetDigits(i);
+    }
+    //
+    if(kNDetTypes==3) branchname.Form("%sDigits%s",name,fgkDetTypeName[i]);
+    branch = treeD->GetBranch(branchname.Data());
+    if(branch) branch->SetAddress(&((*fDigits)[i]));    
+  }
+}
+
+//___________________________________________________________________
+void AliITSDetTypeSimUpg::ResetDigits()
+{
+  // Reset number of digits and the digits array for the ITS detector.  
+  //
+  if(!fDigits){
+    Error("ResetDigits","fDigits is null!");
+    return;
+  }
+  for(Int_t i=0;i<kNDetTypes;i++) ResetDigits(i);
+  //
+}
+
+//___________________________________________________________________
+void AliITSDetTypeSimUpg::ResetDigits(Int_t branch)
+{
+  // Reset number of digits and the digits array for this branch.
+  //
+  if (fDigits->At(branch)) ((TClonesArray*)fDigits->At(branch))->Clear();
+  if(fNDigits) fNDigits[branch]=0;
+}
+
+//_______________________________________________________________________
+void AliITSDetTypeSimUpg::SDigitsToDigits(Option_t* opt, Char_t* name)
+{
+  // Standard Summable digits to Digits function.
+  if(!GetITSgeom()){
+    Warning("SDigitsToDigits","GetITSgeom() is null!!");
+    return;
+  }
+  //
+  static Bool_t setDef = kTRUE;
+  if(setDef) SetDefaultSimulation();
+  setDef = kFALSE;
+  //
+  AliITSsimulation *sim =0;
+  TTree* trees = fLoader->TreeS();
+  if( !(trees && GetSDigits()) ){
+    Error("SDigits2Digits","Error: No trees or SDigits. Returning.");
+    return;
+  } 
+  //
+  TBranch* brchSDigits = trees->GetBranch(name);
+  //
+  Int_t id;
+  for(Int_t module=0;module<GetITSgeom()->GetIndexMax();module++) {
+    //
+    id = GetITSgeom()->GetModuleType(module);
+    sim = (AliITSsimulation*)GetSimulationModel(id);
+    if(!sim){
+      AliFatal(Form("The simulation class was not instanciated for module %d type %s!",
+                   module,GetITSgeom()->GetModuleTypeName(module)));
+    }
+    sim->InitSimulationModule(module,gAlice->GetEvNumber());
+    //
+    fSDigits.Clear();
+    brchSDigits->GetEvent(module);
+    sim->AddSDigitsToModule(&fSDigits,0);
+    sim->FinishSDigitiseModule();
+    fLoader->TreeD()->Fill();
+    ResetDigits();
+  }
+  //
+  //  WriteFOSignals(); 
+  fLoader->TreeD()->GetEntries();
+  fLoader->TreeD()->AutoSave();
+  fLoader->TreeD()->Reset();
+}
+
+//_________________________________________________________
+void AliITSDetTypeSimUpg::AddSumDigit(AliITSpListItem &sdig)
+{  
+  //Adds the module full of summable digits to the summable digits tree.
+  new(fSDigits[fNSDigits++]) AliITSpListItem(sdig);
+}
+
+//__________________________________________________________
+void AliITSDetTypeSimUpg::AddSimDigit(Int_t branch, const AliITSdigit* d)
+{  
+  // Add a simulated digit.
+  TClonesArray &ldigits = *((TClonesArray*)fDigits->At(branch));
+  switch(branch){
+  case kDetPixUpg:
+    new(ldigits[fNDigits[branch]++]) AliITSdigitPixUpg(*((AliITSdigitPixUpg*)d));
+    break;
+  default:
+    AliFatal(Form("Digit for unknown detector type %d",branch));
+  }  
+}
+
+//______________________________________________________________________
+void AliITSDetTypeSimUpg::AddSimDigit(Int_t branch,Float_t phys,Int_t *digits,
+                                     Int_t *tracks,Int_t *hits,Float_t *charges, 
+                                     Int_t sigexpanded)
+{
+  //   Add a simulated digit to the list.
+
+  TClonesArray &ldigits = *((TClonesArray*)fDigits->At(branch));
+  switch(branch){
+  case kDetPixUpg:
+    new(ldigits[fNDigits[branch]++]) AliITSdigitPixUpg(digits,tracks,hits);
+    break;
+  default:
+    AliFatal(Form("Digit for unknown detector type %d",branch));
+  } 
+}
+
+//_______________________________________________________________________
+AliITSTriggerConditions* AliITSDetTypeSimUpg::GetTriggerConditions() 
+{
+  // Get Pixel Trigger Conditions (separate method since it is used only when simulating trigger)
+  if (fTriggerConditions==NULL) { // read from db
+    fRunNumber = ((Int_t)AliCDBManager::Instance()->GetRun());
+    Bool_t origCacheStatus = AliCDBManager::Instance()->GetCacheFlag();
+    Bool_t isCacheActive;
+    if (fRunNumber<0) isCacheActive=kFALSE;
+    else              isCacheActive=kTRUE;
+    AliCDBManager::Instance()->SetCacheFlag(isCacheActive);
+    AliCDBEntry *pitCond = AliCDBManager::Instance()->Get("TRIGGER/SPD/PITConditions", fRunNumber);
+    if (!pitCond) {
+      AliError("Trigger conditions retrieval failed! ");
+      return NULL;
+    }
+    fTriggerConditions = (AliITSTriggerConditions*) pitCond->GetObject();
+    if (!isCacheActive) pitCond->SetObject(NULL);
+    pitCond->SetOwner(kTRUE);
+    if (!isCacheActive) {
+      delete pitCond;
+    }
+    AliCDBManager::Instance()->SetCacheFlag(origCacheStatus);
+    if (fTriggerConditions==NULL) {
+      AliWarning("fTriggerConditions is NULL!");
+    }
+  }
+  return fTriggerConditions;
+}
+
diff --git a/ITS/UPGRADE/AliITSDetTypeSimUpg.h b/ITS/UPGRADE/AliITSDetTypeSimUpg.h
new file mode 100644 (file)
index 0000000..5445062
--- /dev/null
@@ -0,0 +1,130 @@
+#ifndef ALIITSDETTYPESIMUPG_H
+#define ALIITSDETTYPESIMUPG_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/*
+  $Id: AliITSDetTypeSimUpg.h 53025 2011-11-19 22:50:51Z masera $ 
+*/
+
+/////////////////////////////////////////////////////////////////////////
+// * This class contains all of the "external" information needed to do//
+// * detector specific simulations for the ITS.                        //
+/////////////////////////////////////////////////////////////////////////
+
+#include <TObject.h>
+#include "AliITSLoader.h"
+#include "AliITSSimuParam.h"
+
+class TObjArray;
+class TClonesArray;
+class TTree;
+class AliCDBMetaData;
+class AliITSdigit;
+class AliITSdigitPixUpg;
+class AliITSmodule;
+class AliITSpListItem;
+class AliITSsimulation;
+class AliITSsegmentation;
+class AliITSresponse;
+class AliITSCalibration;
+class AliITSgeom;
+class AliITSTriggerConditions;
+
+class AliITSDetTypeSimUpg : public TObject {
+ public:
+  //
+  enum {kDetPixUpg, kNDetTypes};
+  //  
+  AliITSDetTypeSimUpg();
+  virtual ~AliITSDetTypeSimUpg(); 
+  AliITSgeom *GetITSgeom() const {if(fLoader)return ((AliITSLoader*)fLoader)->GetITSgeom(); else return 0;}
+  void SetITSgeom(AliITSgeom *geom);
+  
+  virtual void SetSimulationModel(Int_t dettype,AliITSsimulation *sim);
+  virtual AliITSsimulation* GetSimulationModel(Int_t dettype) const;        
+  virtual AliITSsimulation* GetSimulationModelByModule(Int_t module) const;
+  
+  virtual void SetSegmentationModel(Int_t dettype,AliITSsegmentation *seg);
+  virtual AliITSsegmentation* GetSegmentationModel(Int_t dettype) const;
+  virtual AliITSsegmentation* GetSegmentationModelByModule(Int_t module) const;
+  
+  virtual void SetCalibrationModel(Int_t iMod,AliITSCalibration *resp);
+  
+  virtual AliITSCalibration* GetCalibrationModel(Int_t iMod) const;
+  virtual AliITSTriggerConditions* GetTriggerConditions();
+  
+  virtual void SetSimuParam(const AliITSSimuParam* spar){
+    if(fSimuPar) delete fSimuPar;
+    fSimuPar = new AliITSSimuParam(*spar);
+  }
+  virtual AliITSSimuParam* GetSimuParam() const {return fSimuPar;}
+  
+  TObjArray* GetCalibrationArray() const {return fCalibration;}
+  TObjArray* GetSegmentation() const {return fSegmentation;}
+  void ResetCalibrationArray();
+  void ResetSegmentation();
+  
+  virtual void SetLoader(AliITSLoader* loader);
+  AliITSLoader* GetLoader() const {return fLoader;}
+  
+  virtual void SetDefaults();
+  virtual void SetDefaultSimulation();
+  virtual void SetRunNumber(Int_t rn=0){fRunNumber = rn;}
+  virtual Int_t GetRunNumber() const {return fRunNumber;}
+  virtual void SetTreeAddressS(TTree* treeS, const Char_t* name);
+  virtual void SetTreeAddressD(TTree* treeD, const Char_t* name);
+  
+  virtual void SetDigits(TObjArray* digits) {fDigits=digits;}
+  const TClonesArray* GetSDigits() const { return &fSDigits;}
+  TObjArray*    GetDigits() const {return fDigits;}
+  Int_t* GetNDigitArray() const {return fNDigits;}
+  TClonesArray *DigitsAddress(Int_t id) const { return ((TClonesArray*)(*fDigits)[id]);}
+  virtual void ResetSDigits(){fNSDigits=0; fSDigits.Clear();}
+  virtual void ResetDigits();
+  virtual void ResetDigits(Int_t branch);
+  virtual void SDigitsToDigits(Option_t *opt, Char_t* name);
+
+  virtual void AddSumDigit(AliITSpListItem &sdig);
+  virtual void AddSimDigit(Int_t branch, const AliITSdigit *d);
+  virtual void AddSimDigit(Int_t branch,Float_t phys,Int_t* digits,
+                          Int_t* tracks,Int_t *hits,Float_t* trkcharges,
+                          Int_t sigexpanded=-1000);
+  virtual void SetDigitClassName(Int_t i, const Char_t* name) {fkDigClassName[i]=name;}
+  const Char_t* GetDigitClassName(Int_t i) const {return fkDigClassName[i];}
+
+
+
+ protected:
+  virtual void CreateCalibrationArray(); 
+  virtual Bool_t GetCalibration();
+    
+ private:
+  AliITSDetTypeSimUpg(const AliITSDetTypeSimUpg &source);
+  AliITSDetTypeSimUpg& operator=(const AliITSDetTypeSimUpg &source);
+  void SetDefaultSegmentation(Int_t idet);  // creates def segm.
+
+  //
+  Int_t              fDetNModules[kNDetTypes]; // Total numbers of modules of each type, RS
+  //
+  TObjArray    *fSimulation;   //! [NDet]
+  TObjArray    *fSegmentation; //! [NDet]
+  TObjArray    *fCalibration;  //! [NMod]
+  Int_t         fNSDigits;     //! number of SDigits
+  TClonesArray  fSDigits;      //! Summable digits
+  Int_t*        fNDigits;      //! [NDet] number of Digits for det.
+  Int_t         fRunNumber;    //! run number (to access DB)
+  TObjArray     *fDigits;      //! [NMod][NDigits]
+  AliITSSimuParam *fSimuPar;   //! detector simulation parameters
+  const Char_t*    fkDigClassName[kNDetTypes]; //! String with digit class name.
+  AliITSLoader* fLoader;          //! loader  
+  Bool_t        fFirstcall;       //! flag
+  AliITSTriggerConditions* fTriggerConditions; //! Trigger conditions 
+  //
+  static const char* fgkDetTypeName[kNDetTypes];  // detector type names
+  //       
+  ClassDef(AliITSDetTypeSimUpg,1) // ITS Upg Simulation structure
+};
+
+#endif
index 3e6dd39..464b14e 100644 (file)
@@ -38,7 +38,7 @@ class AliITSUpg : public AliDetector {
     AliITSUpg(const Char_t *title); // standard Creator
     AliITSUpg(const char *name, const char *title); // extended standard Creator
     virtual ~AliITSUpg(); // destructor
-    virtual Int_t IsVersion() const {return 1;}
+    virtual Int_t IsVersion() const {return 11;}
 
     //===================== Simulation Geometry ========================
     // get geometry version - detailed (major) or coarse (minor)
diff --git a/ITS/UPGRADE/AliITSdigitPixUpg.cxx b/ITS/UPGRADE/AliITSdigitPixUpg.cxx
new file mode 100644 (file)
index 0000000..a99141d
--- /dev/null
@@ -0,0 +1,144 @@
+/**************************************************************************
+ * Copyright(c) 2004-2006, 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.                  *
+ **************************************************************************/
+
+#include <AliITSdigitPixUpg.h>
+#include <TArrayI.h>
+
+///////////////////////////////////////////////////////////////////
+//                                                               //
+// Class defining the digit object
+// for pixel
+// Inherits from AliITSdigit
+//                                                               //
+///////////////////////////////////////////////////////////////////
+
+ClassImp(AliITSdigitPixUpg)
+
+//______________________________________________________________________
+AliITSdigitPixUpg::AliITSdigitPixUpg():AliITSdigit(),
+fSignalPix(0){
+    // default constructor, zero coordinates and set array
+    // elements to clearly unphysical values. A value of 0 may
+    // be a valide track of hit number.
+    Int_t i;
+
+    for(i=0;i<fgkSize;i++) fTracks[i]  = -3;
+    for(i=0;i<fgkSize;i++) fHits[i]    = -1;
+}
+
+//______________________________________________________________________
+AliITSdigitPixUpg::AliITSdigitPixUpg(const Int_t *digits):
+  fSignalPix(digits[2])
+{
+    // Creates a pixel digit object
+    Int_t i;
+
+    for(i=0;i<fgkSize;i++) fTracks[i]  = -3;
+    for(i=0;i<fgkSize;i++) fHits[i]    = -1;
+    fCoord1       = digits[0];
+    fCoord2       = digits[1];
+    fSignal       = 1;
+}
+
+//______________________________________________________________________
+AliITSdigitPixUpg::AliITSdigitPixUpg(const Int_t *digits,const Int_t *tracks,
+                              const Int_t *hits):
+fSignalPix(digits[2])
+{
+    // Creates a simulated pixel digit object
+
+    for(Int_t i=0; i<fgkSize; i++) {
+       fTracks[i] = tracks[i];
+       fHits[i]   = hits[i];
+    } // end for i
+    fCoord1       = digits[0];
+    fCoord2       = digits[1];
+    fSignal       = 1;
+}
+
+//______________________________________________________________________
+Int_t AliITSdigitPixUpg::GetListOfTracks(TArrayI &t)
+{
+    // Fills the TArrayI t with the tracks found in fTracks removing
+    // duplicated tracks, but otherwise in the same order. It will return
+    // the number of tracks and fill the remaining elements to the array
+    // t with -1.
+    // Inputs:
+    //   TArrayI  &t Reference to a TArrayI to contain the list of
+    //               nonduplicated track numbers.
+    // Output:
+    //   TArrayI  &t The input array filled with the nonduplicated track
+    //               numbers.
+    // Return:
+    //   Int_t The number of none -1 entries in the TArrayI t.
+    Int_t nt = t.GetSize();
+    Int_t nth = this->GetNTracks();
+    Int_t n = 0,i,j;
+    Bool_t inlist = kFALSE;
+
+    t.Reset(-1); // -1 array.
+    for(i=0;i<nth;i++) {
+       if(this->GetTrack(i) == -1) continue;
+       inlist = kFALSE;
+       for(j=0;j<n;j++)if(this->GetTrack(i) == t.At(j)) inlist = kTRUE;
+       if(!inlist){ // add to end of list
+           t.AddAt(this->GetTrack(i),n);
+           if(n<nt) n++;
+       } // end if
+    } // end for i
+    return n;
+}
+
+//______________________________________________________________________
+void AliITSdigitPixUpg::Print(ostream *os)
+{
+    //Standard output format for this class
+    Int_t i;
+
+    AliITSdigit::Print(os);
+    for(i=0;i<fgkSize;i++) *os <<","<< fTracks[i];
+    for(i=0;i<fgkSize;i++) *os <<","<< fHits[i];
+    *os << "," << fSignalPix;
+}
+
+//______________________________________________________________________
+void AliITSdigitPixUpg::Read(istream *os)
+{
+    //Standard input for this class
+    Int_t i;
+
+    AliITSdigit::Read(os);
+    for(i=0;i<fgkSize;i++) *os >> fTracks[i];
+    for(i=0;i<fgkSize;i++) *os >> fHits[i];
+    *os >> fSignalPix;
+}
+
+//______________________________________________________________________
+ostream &operator<<(ostream &os,AliITSdigitPixUpg &source)
+{
+    // Standard output streaming function.
+
+    source.Print(&os);
+    return os;
+}
+
+//______________________________________________________________________
+istream &operator>>(istream &os,AliITSdigitPixUpg &source)
+{
+    // Standard output streaming function.
+
+    source.Read(&os);
+    return os;
+}
diff --git a/ITS/UPGRADE/AliITSdigitPixUpg.h b/ITS/UPGRADE/AliITSdigitPixUpg.h
new file mode 100644 (file)
index 0000000..9c38c11
--- /dev/null
@@ -0,0 +1,40 @@
+#ifndef ALIITSDIGITSPD_H
+#define ALIITSDIGITSPD_H
+/* Copyright(c) 2004-2006, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice     */
+/////////////////////////////////////////////////////////////
+// Digit class for SPD                                     //
+/////////////////////////////////////////////////////////////
+#include <AliITSdigit.h>
+
+//______________________________________________________________________
+class AliITSdigitPixUpg: public AliITSdigit {
+
+ public:
+    AliITSdigitPixUpg(); //default creator
+    AliITSdigitPixUpg(const Int_t *digits);//standard creator digits only
+    //standard creator with digits, tracks, and hits
+    AliITSdigitPixUpg(const Int_t *digits,const Int_t *tracks,const Int_t *hits);
+    virtual ~AliITSdigitPixUpg(){/*destructor*/}
+    // returns the signal in electrons
+    Int_t GetSignalPix() const {return fSignalPix;}
+    virtual Int_t GetListOfTracks(TArrayI &t);
+    // set signal in electrons
+    void SetSignalPix(Int_t sig) {fSignalPix = sig;}
+    virtual void Print(ostream *os); // Class ascii print function
+    virtual void Print(Option_t *option="") const {TObject::Print(option);}
+    virtual void Read(istream *os);  // Class ascii read function
+    virtual Int_t Read(const char *name) {return TObject::Read(name);}
+
+ protected:
+    
+    Int_t fSignalPix;   // Signal in electrons
+
+    ClassDef(AliITSdigitPixUpg,1)   // Simulated digit object for Pixels
+
+};
+// Input and output functions for standard C++ input/output.
+ostream &operator<<(ostream &os,AliITSdigitPixUpg &source);
+istream &operator>>(istream &os,AliITSdigitPixUpg &source);
+
+#endif
diff --git a/ITS/UPGRADE/AliITSresponsePixUpg.cxx b/ITS/UPGRADE/AliITSresponsePixUpg.cxx
new file mode 100644 (file)
index 0000000..f8e02de
--- /dev/null
@@ -0,0 +1,46 @@
+/**************************************************************************
+ * 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.                  *
+ **************************************************************************/
+///////////////////////////////////////////////////////////////////////////
+//  Base Response for pixels                      
+//  It is used to set static data members           
+//  connected to parameters equal for all           
+//  the SPD modules                                 
+//
+//  Modified by D. Elia, G.E. Bruno
+//  March-April 2006
+//  September   2007: Coupling params taken out
+//                    left in AliITSCalibrationSPD only
+//
+///////////////////////////////////////////////////////////////////////////
+
+#include "AliITSresponsePixUpg.h"
+
+const Float_t AliITSresponsePixUpg::fgkDiffCoeffDefault = 0.; //change this
+const TString AliITSresponsePixUpg::fgkCouplingOptDefault = "old";
+const Float_t AliITSresponsePixUpg::fgkEccentricityDiffDefault = 0.85;
+
+ClassImp(AliITSresponsePixUpg) 
+//______________________________________________________________________
+AliITSresponsePixUpg::AliITSresponsePixUpg():
+  AliITSresponse(),
+fCouplOpt(0),
+fEccDiff(0){
+
+  // constructor
+  SetCouplingOption(fgkCouplingOptDefault);
+  SetDiffCoeff(fgkDiffCoeffDefault,0.);
+  SetSigmaDiffusionAsymmetry(fgkEccentricityDiffDefault);
+
+}
diff --git a/ITS/UPGRADE/AliITSresponsePixUpg.h b/ITS/UPGRADE/AliITSresponsePixUpg.h
new file mode 100644 (file)
index 0000000..dcfdc2b
--- /dev/null
@@ -0,0 +1,34 @@
+#ifndef ALIITSRESPONSESPD_H
+#define ALIITSRESPONSESPD_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+
+#include "AliITSresponse.h"
+///////////////////////////////////////////
+//                                       //
+// ITS response class for Pixels         //
+///////////////////////////////////////////
+  
+class AliITSresponsePixUpg :  public AliITSresponse {
+ public:
+  AliITSresponsePixUpg(); // default constructor
+  virtual ~AliITSresponsePixUpg() {;} // destructror
+  //
+  virtual  void   SetSigmaDiffusionAsymmetry(Double_t ecc)        {fEccDiff=ecc;}   
+  virtual  void   GetSigmaDiffusionAsymmetry(Double_t &ecc) const {ecc=fEccDiff;}
+  //
+ protected:
+  //
+  static const Float_t fgkDiffCoeffDefault;  //default for fDiffCoeff
+  static const TString fgkCouplingOptDefault;  // type of pixel Coupling (old or new)
+  static const Float_t fgkEccentricityDiffDefault;//default for fCouplRow 
+  
+    TString fCouplOpt;        // Coupling Option
+    Float_t fEccDiff;         // Eccentricity (i.e. asymmetry parameter) in the Gaussian Diffusion
+
+
+    ClassDef(AliITSresponsePixUpg,1) // pixel upgrade base response class
+};
+
+#endif
index 8a2775e..71f2265 100644 (file)
@@ -364,3 +364,9 @@ Int_t AliITSsegmentationPixUpg::GetChipsInLocalWindow(Int_t* array, Float_t zmin
   //
   return nChipInW;
 }
+
+//______________________________________________________________________
+void AliITSsegmentationPixUpg::Init()
+{
+  // init settings
+}
index 1dfa10c..36451a4 100644 (file)
@@ -17,11 +17,13 @@ public AliITSsegmentation {
                           double thickness=0,
                           double edgL=0,double edgR=0,double edgT=0,double edgB=0);
   
-  AliITSsegmentationPixUpg(Option_t *opt="" );
+  //  AliITSsegmentationPixUpg(Option_t *opt="" );
   AliITSsegmentationPixUpg(const AliITSsegmentationPixUpg &source);
   virtual ~AliITSsegmentationPixUpg() {}
   AliITSsegmentationPixUpg& operator=(const AliITSsegmentationPixUpg &source);
-  
+  //
+  virtual void    Init();
+  //  
   virtual void    SetNPads(Int_t, Int_t) {MayNotUse("SetPadSize");}
   virtual Int_t   GetNPads() const {return fNCol*fNRow;}
   //
diff --git a/ITS/UPGRADE/AliITSsimulationPixUpg.cxx b/ITS/UPGRADE/AliITSsimulationPixUpg.cxx
new file mode 100644 (file)
index 0000000..d6c94c2
--- /dev/null
@@ -0,0 +1,1020 @@
+/**************************************************************************
+* 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.                  *
+**************************************************************************/
+
+#include <Riostream.h>
+#include <TGeoGlobalMagField.h>
+#include <TH1.h>
+#include <TString.h>
+#include "AliITS.h"
+#include "AliITSdigitPixUpg.h"
+#include "AliITShit.h"
+#include "AliITSmodule.h"
+#include "AliITSpList.h"
+#include "AliITSCalibrationPixUpg.h"
+#include "AliITSsegmentationPixUpg.h"
+#include "AliITSsimulationPixUpg.h"
+#include "AliLog.h"
+#include "AliRun.h"
+#include "AliMagF.h"
+#include "AliMathBase.h"
+
+//#define DEBUG
+
+using std::endl;
+using std::cout;
+ClassImp(AliITSsimulationPixUpg)
+////////////////////////////////////////////////////////////////////////
+//  Version: 1
+//  Modified by D. Elia, G.E. Bruno, H. Tydesjo 
+//  Fast diffusion code by Bjorn S. Nilsen
+//  March-April 2006
+//  October     2007: GetCalibrationObjects() removed
+//
+//  Version: 0
+//  Written by Boris Batyunya
+//  December 20 1999
+//
+//  Adapted for pixels of ITS upgrade July 2012, ruben.shahoyan@cern.ch
+//
+// AliITSsimulationPixUpg is to do the simulation of pixels
+//
+////////////////////////////////////////////////////////////////////////
+
+//______________________________________________________________________
+AliITSsimulationPixUpg::AliITSsimulationPixUpg():
+AliITSsimulation(),
+fHistos(0),
+fHistName(),
+fCoupling(),
+fLorentz(kFALSE),
+fTanLorAng(0),
+fStrobe(kTRUE),
+fStrobeLenght(4),
+fStrobePhase(-12.5e-9)
+{
+   // Default constructor.
+   // Inputs:
+   //    none.
+   // Outputs:
+   //    none.
+   // Return:
+   //    A default constructed AliITSsimulationPixUpg class.
+
+   AliDebug(1,Form("Calling default constructor"));
+//    Init();
+}
+
+//______________________________________________________________________
+AliITSsimulationPixUpg::AliITSsimulationPixUpg(AliITSDetTypeSim *dettyp):
+AliITSsimulation(dettyp),
+fHistos(0),
+fHistName(),
+fCoupling(),
+fLorentz(kFALSE),
+fTanLorAng(0),
+fStrobe(kTRUE),
+fStrobeLenght(4),
+fStrobePhase(-12.5e-9)
+{
+   // standard constructor
+   // Inputs:
+   //    AliITSsegmentation *seg  A pointer to the segmentation class
+   //                             to be used for this simulation
+   //    AliITSCalibration     *resp A pointer to the responce class to
+   //                             be used for this simulation
+   // Outputs:
+   //    none.
+   // Return:
+   //    A default constructed AliITSsimulationPixUpg class.
+
+   AliDebug(1,Form("Calling standard constructor "));
+   Init();
+}
+
+//______________________________________________________________________
+void AliITSsimulationPixUpg::Init()
+{
+  // Initilization
+  // Inputs:
+  //    none.
+  // Outputs:
+  //    none.
+  // Return:
+  //    none.
+  const Double_t kmictocm = 1.0e-4; // convert microns to cm.
+  
+  SetModuleNumber(0);
+  SetEventNumber(0);
+  SetMap(new AliITSpList(GetNPixelsZ(),GetNPixelsX()));
+  AliITSSimuParam* simpar = fDetType->GetSimuParam();
+  AliITSsegmentationPixUpg* seg = (AliITSsegmentationPixUpg*)GetSegmentationModel(-1);
+  Double_t bias = simpar->GetPixBiasVoltage();
+//    cout << "Bias Voltage --> " << bias << endl; // dom    
+   simpar->SetDistanceOverVoltage(kmictocm*seg->Dy(),bias);
+// set kind of coupling ("old" or "new")
+   char opt[20];
+   simpar->GetPixCouplingOption(opt);
+   char *old = strstr(opt,"old");
+   if (old) {
+     fCoupling=2;
+   } else {
+     fCoupling=1;
+   } // end if
+   SetLorentzDrift(simpar->GetSPDLorentzDrift());
+   if (fLorentz) SetTanLorAngle(simpar->GetSPDLorentzHoleWeight());
+   //SetStrobeGeneration(kFALSE);
+   if (fStrobe) GenerateStrobePhase();
+}
+
+//______________________________________________________________________
+Bool_t AliITSsimulationPixUpg::SetTanLorAngle(Double_t weightHole) 
+{
+    // This function set the Tangent of the Lorentz angle. 
+    // A weighted average is used for electrons and holes 
+    // Input: Double_t weightHole: wheight for hole: it should be in the range [0,1]
+    // output: Bool_t : kTRUE in case of success
+    //
+    if (!fDetType) {
+      AliError("AliITSsimulationPixUpg::SetTanLorAngle: AliITSDetTypeSim* fDetType not set ");
+      return kFALSE;}
+    if (weightHole<0) {
+       weightHole=0.;
+       AliWarning("AliITSsimulationPixUpg::SetTanLorAngle: You have asked for negative Hole weight");
+       AliWarning("AliITSsimulationPixUpg::SetTanLorAngle: I'm going to use only electrons");
+    }
+    if (weightHole>1) {
+       weightHole=1.;
+       AliWarning("AliITSsimulationPixUpg::SetTanLorAngle: You have asked for weight > 1");
+       AliWarning("AliITSsimulationPixUpg::SetTanLorAngle: I'm going to use only holes");
+    }
+    Double_t weightEle=1.-weightHole;
+    AliITSSimuParam* simpar = fDetType->GetSimuParam();
+    AliMagF* fld = (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
+    if (!fld) AliFatal("The field is not initialized");
+    Double_t bz = fld->SolenoidField();
+    fTanLorAng = TMath::Tan(weightHole*simpar->LorentzAngleHole(bz) +
+                             weightEle*simpar->LorentzAngleElectron(bz));
+    return kTRUE;
+}
+
+//______________________________________________________________________
+AliITSsimulationPixUpg::~AliITSsimulationPixUpg()
+{
+   // destructor
+   // Inputs:
+   //    none.
+   // Outputs:
+   //    none.
+   // Return:
+   //     none.
+
+   if (fHistos) {
+       fHistos->Delete(); 
+       delete fHistos;     
+   } // end if fHistos
+}
+
+//______________________________________________________________________
+AliITSsimulationPixUpg::AliITSsimulationPixUpg(const AliITSsimulationPixUpg &s) : 
+  AliITSsimulation(s),
+  fHistos(s.fHistos),
+  fHistName(s.fHistName),
+  fCoupling(s.fCoupling),
+  fLorentz(s.fLorentz),
+  fTanLorAng(s.fTanLorAng),
+  fStrobe(s.fStrobe),
+  fStrobeLenght(s.fStrobeLenght),
+  fStrobePhase(s.fStrobePhase)
+{
+  //     Copy Constructor
+   // Inputs:
+   //    AliITSsimulationPixUpg &s The original class for which
+   //                                this class is a copy of
+   // Outputs:
+   //    none.
+   // Return:
+
+}
+
+//______________________________________________________________________
+AliITSsimulationPixUpg&  AliITSsimulationPixUpg::operator=(const AliITSsimulationPixUpg &s)
+{
+   //    Assignment operator
+   // Inputs:
+   //    AliITSsimulationPixUpg &s The original class for which
+   //                                this class is a copy of
+   // Outputs:
+   //    none.
+   // Return:
+
+   if (&s == this) return *this;
+   this->fHistos = s.fHistos;
+   fCoupling  = s.fCoupling;
+   fHistName   = s.fHistName;
+   fLorentz   = s.fLorentz;
+   fTanLorAng = s.fTanLorAng;
+   fStrobe       = s.fStrobe;
+   fStrobeLenght = s.fStrobeLenght;
+   fStrobePhase  = s.fStrobePhase;
+   return *this;
+}
+
+//______________________________________________________________________
+void AliITSsimulationPixUpg::InitSimulationModule(Int_t module, Int_t event)
+{
+   //  This function creates maps to build the list of tracks for each
+   //  summable digit. Inputs defined by base class.
+   //  Inputs:
+   //    Int_t module   // Module number to be simulated
+   //    Int_t event    // Event number to be simulated
+   //  Outputs:
+   //    none
+   //  Returns:
+   //    none
+
+   AliDebug(1,Form("(module=%d,event=%d)",module,event));
+   const Double_t kmictocm = 1.0e-4; // convert microns to cm.
+   AliITSSimuParam* simpar = fDetType->GetSimuParam();
+   AliITSsegmentationPixUpg* seg = (AliITSsegmentationPixUpg*)GetSegmentationModel(-1);
+   SetModuleNumber(module);
+   SetEventNumber(event);
+   simpar->SetDistanceOverVoltage(kmictocm*seg->Dy(),simpar->GetSPDBiasVoltage(module)); 
+   ClearMap();
+}
+
+//_____________________________________________________________________
+void AliITSsimulationPixUpg::SDigitiseModule(AliITSmodule *mod,Int_t, Int_t event)
+{
+  //  This function begins the work of creating S-Digits.  Inputs defined
+  //  by base class.
+  //  Inputs:
+  //    AliITSmodule *mod  //  module
+  //    Int_t              //  not used
+  //    Int_t event        //  Event number
+  //  Outputs:
+  //    none
+  //  Return:
+  //    test              //  test returns kTRUE if the module contained hits
+  //                      //  test returns kFALSE if it did not contain hits
+  
+  AliDebug(1,Form("(mod=%p, ,event=%d)",mod,event));
+  if (!(mod->GetNhits())) {
+    AliDebug(1,Form("In event %d module %d there are %d hits returning.",
+                   event, mod->GetIndex(),mod->GetNhits()));
+    return;// if module has no hits don't create Sdigits
+  } // end if
+  SetModuleNumber(mod->GetIndex());
+  if (fStrobe) if (event != GetEventNumber()) GenerateStrobePhase(); 
+  SetEventNumber(event);
+  InitSimulationModule( GetModuleNumber() , event );
+  // HitToSDigit(mod);
+  HitToSDigitFast(mod);
+  if (fDetType->GetSimuParam()->GetSPDAddNoisyFlag())   AddNoisyPixels();
+  if (fDetType->GetSimuParam()->GetSPDRemoveDeadFlag()) RemoveDeadPixels();
+  
+  //    cout << "After Remove in SDigitiseModule !!!!!" << endl; // dom
+  //    cout << "Module " << mod->GetIndex() << " Event " << event << endl; // dom
+  WriteSDigits();
+  ClearMap();
+}
+
+//______________________________________________________________________
+void AliITSsimulationPixUpg::WriteSDigits()
+{
+   //  This function adds each S-Digit to pList
+   //  Inputs:
+   //    none.
+   //  Outputs:
+   //    none.
+   //  Return:
+   //    none
+   Int_t ix, nix, iz, niz;
+   static AliITS *aliITS = (AliITS*)gAlice->GetModule("ITS");
+
+   AliDebug(1,Form("Writing SDigits for module %d",GetModuleNumber()));
+//    cout << "WriteSDigits for module " << GetModuleNumber() << endl; // dom
+   GetMap()->GetMaxMapIndex(niz, nix);
+   for (iz=0; iz<niz; iz++)for (ix=0; ix<nix; ix++) {
+       if (GetMap()->GetSignalOnly(iz,ix)>0.0) {
+        //            cout << " Signal gt 0  iz ix " << iz << ix << " Module " << GetModuleNumber() << endl; // dom
+        aliITS->AddSumDigit(*(GetMap()->GetpListItem(iz,ix)));
+        if (AliDebugLevel()>0) {
+          AliDebug(1,Form("%d, %d",iz,ix));
+          cout << *(GetMap()->GetpListItem(iz,ix)) << endl;
+        } // end if GetDebug
+       } // end if GetMap()->GetSignalOnly(iz,ix)>0.0
+     } // end for iz,ix
+   return; 
+}
+
+//______________________________________________________________________
+void AliITSsimulationPixUpg::FinishSDigitiseModule()
+{
+   //  This function calls SDigitsToDigits which creates Digits from SDigits
+   //  Inputs:
+   //    none
+   //  Outputs:
+   //    none
+   //  Return
+   //    none
+
+   AliDebug(1,"()");
+//    cout << "FinishSDigitiseModule for module " << GetModuleNumber() << endl; // dom
+   FrompListToDigits(); // Charge To Signal both adds noise and
+   ClearMap();
+   return;
+}
+
+//______________________________________________________________________
+void AliITSsimulationPixUpg::DigitiseModule(AliITSmodule *mod,Int_t, Int_t event)
+{
+   //  This function creates Digits straight from the hits and then adds
+   //  electronic noise to the digits before adding them to pList
+   //  Each of the input variables is passed along to HitToSDigit
+   //  Inputs:
+   //    AliITSmodule *mod     module
+   //    Int_t                 Dummy.
+   //    Int_t                 Dummy
+   //  Outputs:
+   //     none.
+   //  Return:
+   //    none.
+
+  if (fStrobe) if (event != GetEventNumber()) GenerateStrobePhase();
+  AliDebug(1,Form("(mod=%p,,0)",mod));
+  // HitToSDigit(mod);
+  InitSimulationModule( mod->GetIndex(), event );
+  HitToSDigitFast(mod);
+  
+  if (fDetType->GetSimuParam()->GetSPDAddNoisyFlag())   AddNoisyPixels();
+  if (fDetType->GetSimuParam()->GetSPDRemoveDeadFlag()) RemoveDeadPixels();
+  //    cout << "After Remove in DigitiseModule in module " << mod->GetIndex() << endl; // dom
+  FrompListToDigits();
+  ClearMap();
+}
+
+//______________________________________________________________________
+void AliITSsimulationPixUpg::HitToSDigit(AliITSmodule *mod)
+{
+   // Does the charge distributions using Gaussian diffusion charge charing.
+   // Inputs:
+   //    AliITSmodule *mod  Pointer to this module
+   // Output:
+   //    none.
+   // Return:
+   //    none.
+   const Double_t kmictocm = 1.0e-4; // convert microns to cm.
+   const Double_t kBunchLenght = 25e-9; // LHC clock
+   TObjArray *hits = mod->GetHits();
+   Int_t nhits = hits->GetEntriesFast();
+   Int_t h,ix,iz,i;
+   Int_t idtrack;
+   Double_t x0=0.0,x1=0.0,y0=0.0,y1=0.0,z0=0.0,z1=0.0,de=0.0,ld=0.0;
+   Double_t x,y,z,t,tp,st,dt=0.2,el,sig,sigx,sigz,fda;
+   AliITSsegmentationPixUpg* seg = (AliITSsegmentationPixUpg*)GetSegmentationModel(-1);
+   AliITSSimuParam *simpar = fDetType->GetSimuParam();
+   Double_t thick = 0.5*kmictocm*seg->Dy();  // Half Thickness
+   simpar->GetSPDSigmaDiffusionAsymmetry(fda);  //
+
+   AliDebug(1,Form("(mod=%p) fCoupling=%d",mod,fCoupling));
+   if (nhits<=0) return;
+   for (h=0;h<nhits;h++) {
+     if (AliDebugLevel()>0) {
+       AliDebug(1,Form("Hits, %d", h));
+       cout << *(mod->GetHit(h)) << endl;
+     } // end if GetDebug
+     // Check if the hit is inside readout window
+     if (fStrobe)
+       if ((mod->GetHit(h)->GetTOF() < fStrobePhase) ||
+          (mod->GetHit(h)->GetTOF() > (fStrobePhase+(Double_t)fStrobeLenght*kBunchLenght))) continue;
+     if (!mod->LineSegmentL(h,x0,x1,y0,y1,z0,z1,de,idtrack)) continue;
+     st = TMath::Sqrt(x1*x1+y1*y1+z1*z1);
+     if (st>0.0) {
+       st = (Double_t)((Int_t)(st/kmictocm)); // number of microns
+       if (st<=1.0) st = 1.0;
+       dt = 1.0/st;
+       for (t=0.0;t<1.0;t+=dt) { // Integrate over t
+        tp  = t+0.5*dt;
+        x   = x0+x1*tp;
+        y   = y0+y1*tp;
+        z   = z0+z1*tp;
+        if (!(seg->LocalToDet(x,z,ix,iz))) continue; // outside
+        //el  = res->GeVToCharge((Double_t)(dt*de));
+        el  = dt * de / simpar->GetGeVToCharge();
+        //
+        if (GetDebug(1)) if (el<=0.0) cout<<"el="<<el<<" dt="<<dt<<" de="<<de<<endl; // end if GetDebug
+        //
+        sig = simpar->SigmaDiffusion1D(TMath::Abs(thick + y)); 
+        sigx=sig;
+        sigz=sig*fda;
+        if (fLorentz) ld=(y+thick)*fTanLorAng;
+        SpreadChargeAsym(x,z,ix,iz,el,sigx,sigz,ld,idtrack,h);
+       } // end for t
+     } else { // st == 0.0 deposit it at this point
+       x   = x0;
+       y   = y0;
+       z   = z0;
+       if (!(seg->LocalToDet(x,z,ix,iz))) continue; // outside
+       //el  = res->GeVToCharge((Double_t)de);
+       el  = de / simpar->GetGeVToCharge();
+       sig = simpar->SigmaDiffusion1D(TMath::Abs(thick + y));
+       sigx=sig;
+       sigz=sig*fda;
+       if (fLorentz) ld=(y+thick)*fTanLorAng;
+       SpreadChargeAsym(x,z,ix,iz,el,sigx,sigz,ld,idtrack,h);
+     } // end if st>0.0
+     
+   } // Loop over all hits h
+   
+   // Coupling
+   switch (fCoupling) {
+   default:
+     break;
+   case 1: //case 3:
+     for (i=0;i<GetMap()->GetEntries();i++) 
+       if (GetMap()->GetpListItem(i)==0) continue;
+       else{
+        GetMap()->GetMapIndex(GetMap()->GetpListItem(i)->GetIndex(),iz,ix);
+        SetCoupling(iz,ix,idtrack,h);
+       } // end for i
+     break;
+   case 2: // case 4:
+     for (i=0;i<GetMap()->GetEntries();i++) 
+       if (GetMap()->GetpListItem(i)==0) continue;
+       else{
+        GetMap()->GetMapIndex(GetMap()->GetpListItem(i)->GetIndex(),iz,ix);
+        SetCouplingOld(iz,ix,idtrack,h);
+       } // end for i
+     break;
+   } // end switch
+   if (GetDebug(2)) Info("HitToSDigit","Finished fCoupling=%d",fCoupling);
+}
+
+//______________________________________________________________________
+void AliITSsimulationPixUpg::HitToSDigitFast(AliITSmodule *mod)
+{
+  // Does the charge distributions using Gaussian diffusion charge charing.    // Inputs:
+  //    AliITSmodule *mod  Pointer to this module
+  // Output:
+  //    none.
+  // Return:
+  //    none.
+  const Double_t kmictocm = 1.0e-4; // convert microns to cm.
+  const Int_t kn10=10;
+  const Double_t kti[kn10]={7.443716945e-3,2.166976971e-1,3.397047841e-1,
+                           4.325316833e-1,4.869532643e-1,5.130467358e-1,
+                           5.674683167e-1,6.602952159e-1,7.833023029e-1,
+                           9.255628306e-1};
+  const Double_t kwi[kn10]={1.477621124e-1,1.346333597e-1,1.095431813e-1,
+                           7.472567455e-2,3.333567215e-2,3.333567215e-2,
+                           7.472567455e-2,1.095431813e-1,1.346333597e-1,
+                           1.477621124e-1};
+  const Double_t kBunchLenght = 25e-9; // LHC clock
+  TObjArray *hits = mod->GetHits();
+  Int_t nhits = hits->GetEntriesFast();
+  Int_t h,ix,iz,i;
+  Int_t idtrack;
+  Double_t x0=0.0,x1=0.0,y0=0.0,y1=0.0,z0=0.0,z1=0.0,de=0.0,ld=0.0;
+  Double_t x,y,z,t,st,el,sig,sigx,sigz,fda;
+  AliITSsegmentationPixUpg* seg = (AliITSsegmentationPixUpg*)GetSegmentationModel(-1);
+  AliITSSimuParam* simpar = fDetType->GetSimuParam();
+  Double_t thick = 0.5*kmictocm*seg->Dy();  // Half thickness
+  simpar->GetSPDSigmaDiffusionAsymmetry(fda);
+  //    cout << "Half Thickness " << thick << endl;  // dom
+  //    cout << "Diffusion asymm " << fda << endl;  // dom
+  
+  AliDebug(1,Form("(mod=%p) fCoupling=%d",mod,fCoupling));
+  if (nhits<=0) return;
+  for (h=0;h<nhits;h++) {
+    if (AliDebugLevel()>0) {
+      AliDebug(1,Form("Hits, %d", h));
+      cout << *(mod->GetHit(h)) << endl;
+    } // end if GetDebug
+    // Check if the hit is inside readout window
+    if (fStrobe)
+      if ((mod->GetHit(h)->GetTOF() < fStrobePhase) ||
+         (mod->GetHit(h)->GetTOF() > (fStrobePhase+(Double_t)fStrobeLenght*kBunchLenght))) continue;
+    if (!mod->LineSegmentL(h,x0,x1,y0,y1,z0,z1,de,idtrack)) continue;
+    st = TMath::Sqrt(x1*x1+y1*y1+z1*z1);
+    if (st>0.0) for (i=0;i<kn10;i++) { // Integrate over t
+       t   = kti[i];
+       x   = x0+x1*t;
+       y   = y0+y1*t;
+       z   = z0+z1*t;
+       if (!(seg->LocalToDet(x,z,ix,iz))) continue; // outside
+       el  = kwi[i]*de/simpar->GetGeVToCharge();
+       if (GetDebug(1)) {
+         if (el<=0.0) cout<<"el="<<el<<" kwi["<<i<<"]="<<kwi[i]
+                         <<" de="<<de<<endl;
+       } // end if GetDebug
+       sig = simpar->SigmaDiffusion1D(TMath::Abs(thick + y));
+       sigx=sig;
+       sigz=sig*fda;
+       if (fLorentz) ld=(y+thick)*fTanLorAng;
+       SpreadChargeAsym(x,z,ix,iz,el,sigx,sigz,ld,idtrack,h);
+       //                cout << "sigx sigz " << sigx << " " << sigz << endl; // dom
+      } // end for i // End Integrate over t
+    else { // st == 0.0 deposit it at this point
+      x   = x0;
+      y   = y0;
+      z   = z0;
+      if (!(seg->LocalToDet(x,z,ix,iz))) continue; // outside
+      el  = de / simpar->GetGeVToCharge();
+      sig = simpar->SigmaDiffusion1D(TMath::Abs(thick + y));
+      sigx=sig;
+      sigz=sig*fda;
+      if (fLorentz) ld=(y+thick)*fTanLorAng;
+      SpreadChargeAsym(x,z,ix,iz,el,sigx,sigz,ld,idtrack,h);
+    } // end if st>0.0
+    
+  } // Loop over all hits h
+  
+  // Coupling
+  switch (fCoupling) {
+  default:
+    break;
+  case 1: // case 3:
+    for (i=0;i<GetMap()->GetEntries();i++)
+      if (GetMap()->GetpListItem(i)==0) continue;
+      else{
+       GetMap()->GetMapIndex(GetMap()->GetpListItem(i)->GetIndex(),iz,ix);
+       SetCoupling(iz,ix,idtrack,h);
+      } // end for i
+    break;
+  case 2: // case 4:
+    for (i=0;i<GetMap()->GetEntries();i++)
+      if (GetMap()->GetpListItem(i)==0) continue;
+      else {
+       GetMap()->GetMapIndex(GetMap()->GetpListItem(i)->GetIndex(),iz,ix);  
+       SetCouplingOld(iz,ix,idtrack,h);
+      } // end for i
+    break;
+  } // end switch
+  if (GetDebug(2))Info("HitToSDigit","Finished fCoupling=%d",fCoupling);
+}
+
+//______________________________________________________________________
+void AliITSsimulationPixUpg::SpreadCharge(Double_t x0,Double_t z0,
+                                         Int_t ix0,Int_t iz0,
+                                         Double_t el,Double_t sig,Double_t ld,
+                                         Int_t t,Int_t hi)
+{
+   // Spreads the charge over neighboring cells. Assume charge is distributed
+   // as charge(x,z) = (el/2*pi*sig*sig)*exp(-arg)
+   // arg=((x-x0)*(x-x0)/2*sig*sig)+((z-z0*z-z0)/2*sig*sig)
+   // if fLorentz=kTRUE, then x0=x0+ld (Lorentz drift taken into account)
+   // Defined this way, the integral over all x and z is el.
+   // Inputs:
+   //    Double_t x0   x position of point where charge is liberated
+   //    Double_t z0   z position of point where charge is liberated
+   //    Int_t    ix0  row of cell corresponding to point x0
+   //    Int_t    iz0  columb of cell corresponding to point z0
+   //    Double_t el   number of electrons liberated in this step
+   //    Double_t sig  Sigma difusion for this step (y0 dependent)
+   //    Double_t ld   lorentz drift in x for this step (y0 dependent)
+   //    Int_t    t    track number
+   //    Int_t    ti   hit track index number
+   //    Int_t    hi   hit "hit" index number
+   // Outputs:
+   //     none.
+   // Return:
+   //     none.
+   const Int_t knx = 3,knz = 2;
+   const Double_t kRoot2 = 1.414213562; // Sqrt(2).
+   const Double_t kmictocm = 1.0e-4; // convert microns to cm.
+   Int_t ix,iz,ixs,ixe,izs,ize;
+   Float_t x,z;
+   Double_t x1,x2,z1,z2,s,sp;
+   AliITSsegmentationSPD* seg = (AliITSsegmentationSPD*)GetSegmentationModel(-1);
+   //
+   if (GetDebug(4)) Info("SpreadCharge","(x0=%e,z0=%e,ix0=%d,iz0=%d,el=%e,sig=%e,t=%d,i=%d)",x0,z0,ix0,iz0,el,sig,t,hi);
+   if (sig<=0.0) { // if sig<=0 No diffusion to simulate.
+     GetMap()->AddSignal(iz0,ix0,t,hi,GetModuleNumber(),el);
+     if (GetDebug(2)) cout << "sig<=0.0=" << sig << endl; // end if GetDebug
+     return;
+   } // end if
+   sp = 1.0/(sig*kRoot2);
+   if (GetDebug(2)) cout << "sig=" << sig << " sp=" << sp << endl; // end if GetDebug
+   ixs = TMath::Max(-knx+ix0,0);
+   ixe = TMath::Min(knx+ix0,seg->Npx()-1);
+   izs = TMath::Max(-knz+iz0,0);
+   ize = TMath::Min(knz+iz0,seg->Npz()-1);
+   for (ix=ixs;ix<=ixe;ix++) for (iz=izs;iz<=ize;iz++) {
+       seg->DetToLocal(ix,iz,x,z); // pixel center
+       x1  = x;
+       z1  = z;
+       x2  = x1 + 0.5*kmictocm*seg->Dpx(ix); // Upper
+       x1 -= 0.5*kmictocm*seg->Dpx(ix);  // Lower
+       z2  = z1 + 0.5*kmictocm*seg->Dpz(iz); // Upper
+       z1 -= 0.5*kmictocm*seg->Dpz(iz);  // Lower
+       x1 -= x0+ld; // Distance from where track traveled (taking into account the Lorentz drift)
+       x2 -= x0+ld; // Distance from where track traveled (taking into account the Lorentz drift)
+       z1 -= z0; // Distance from where track traveled
+       z2 -= z0; // Distance from where track traveled
+       s   = 0.25; // Correction based on definision of Erfc
+       s  *= AliMathBase::ErfcFast(sp*x1) - AliMathBase::ErfcFast(sp*x2);
+       if (GetDebug(3)) {
+        cout <<"el="<<el<<" ix0="<<ix0<<" ix="<<ix<<" x0="<<x<<
+          " iz0="<<iz0<<" iz="<<iz<<" z0="<<z<< 
+          " sp*x1="<<sp*x1<<" sp*x2="<<sp*x2<<" s="<<s;
+       } // end if GetDebug
+       s  *= AliMathBase::ErfcFast(sp*z1) - AliMathBase::ErfcFast(sp*z2);
+       if (GetDebug(3)) cout<<" sp*z1="<<sp*z1<<" sp*z2="<<sp*z2<<" s="<<s<< endl; // end if GetDebug
+       GetMap()->AddSignal(iz,ix,t,hi,GetModuleNumber(),s*el);
+     } // end for ix, iz
+}
+
+//______________________________________________________________________
+void AliITSsimulationPixUpg::SpreadChargeAsym(Double_t x0,Double_t z0,
+                                           Int_t ix0,Int_t iz0,
+                                           Double_t el,Double_t sigx,Double_t sigz,
+                                           Double_t ld,Int_t t,Int_t hi)
+{
+   // Spreads the charge over neighboring cells. Assume charge is distributed
+   // as charge(x,z) = (el/2*pi*sigx*sigz)*exp(-arg)
+   // arg=((x-x0)*(x-x0)/2*sigx*sigx)+((z-z0*z-z0)/2*sigz*sigz)
+   // if fLorentz=kTRUE, then x0=x0+ld (Lorentz drift taken into account)
+   // Defined this way, the integral over all x and z is el.
+   // Inputs:
+   //    Double_t x0   x position of point where charge is liberated
+   //    Double_t z0   z position of point where charge is liberated
+   //    Int_t    ix0  row of cell corresponding to point x0
+   //    Int_t    iz0  columb of cell corresponding to point z0
+   //    Double_t el   number of electrons liberated in this step
+   //    Double_t sigx Sigma difusion along x for this step (y0 dependent)
+   //    Double_t sigz Sigma difusion along z for this step (y0 dependent)
+   //    Double_t ld   lorentz drift in x for this stip (y0 dependent)
+   //    Int_t    t    track number
+   //    Int_t    ti   hit track index number
+   //    Int_t    hi   hit "hit" index number
+   // Outputs:
+   //     none.
+   // Return:
+   //     none.
+   const Int_t knx = 3,knz = 2;
+   const Double_t kRoot2 = 1.414213562; // Sqrt(2).
+   const Double_t kmictocm = 1.0e-4; // convert microns to cm.
+   Int_t ix,iz,ixs,ixe,izs,ize;
+   Float_t x,z;
+   Double_t x1,x2,z1,z2,s,spx,spz;
+   AliITSsegmentationSPD* seg = (AliITSsegmentationSPD*)GetSegmentationModel(-1);
+   //
+   if (GetDebug(4)) Info("SpreadChargeAsym","(x0=%e,z0=%e,ix0=%d,iz0=%d,el=%e,sigx=%e, sigz=%e, t=%d,i=%d)",x0,z0,ix0,iz0,el,sigx,sigz,t,hi);
+   if (sigx<=0.0 || sigz<=0.0) { // if sig<=0 No diffusion to simulate.
+     GetMap()->AddSignal(iz0,ix0,t,hi,GetModuleNumber(),el);
+     if (GetDebug(2)) {
+       cout << "sigx<=0.0=" << sigx << endl;
+       cout << "sigz<=0.0=" << sigz << endl;
+     } // end if GetDebug
+     return;
+   } // end if
+   spx = 1.0/(sigx*kRoot2);     spz = 1.0/(sigz*kRoot2);
+   if (GetDebug(2)) {
+     cout << "sigx=" << sigx << " spx=" << spx << endl;
+     cout << "sigz=" << sigz << " spz=" << spz << endl;
+   } // end if GetDebug
+   ixs = TMath::Max(-knx+ix0,0);
+   ixe = TMath::Min(knx+ix0,seg->Npx()-1);
+   izs = TMath::Max(-knz+iz0,0);
+   ize = TMath::Min(knz+iz0,seg->Npz()-1);
+   for (ix=ixs;ix<=ixe;ix++) for (iz=izs;iz<=ize;iz++) {
+       seg->DetToLocal(ix,iz,x,z); // pixel center
+       x1  = x;
+       z1  = z;
+       x2  = x1 + 0.5*kmictocm*seg->Dpx(ix); // Upper
+       x1 -= 0.5*kmictocm*seg->Dpx(ix);  // Lower
+       z2  = z1 + 0.5*kmictocm*seg->Dpz(iz); // Upper
+       z1 -= 0.5*kmictocm*seg->Dpz(iz);  // Lower
+       x1 -= x0+ld; // Distance from where track traveled (taking into account the Lorentz drift)
+       x2 -= x0+ld; // Distance from where track traveled (taking into account the Lorentz drift)
+       z1 -= z0; // Distance from where track traveled
+       z2 -= z0; // Distance from where track traveled
+       s   = 0.25; // Correction based on definision of Erfc
+       s  *= AliMathBase::ErfcFast(spx*x1) - AliMathBase::ErfcFast(spx*x2);
+       if (GetDebug(3)) cout <<"el="<<el<<" ix0="<<ix0<<" ix="<<ix<<" x0="<<x<<" iz0="<<iz0<<" iz="<<iz<<" z0="<<z<<" spx*x1="<<spx*x1<<" spx*x2="<<spx*x2<<" s="<<s; // end if GetDebug
+       s  *= AliMathBase::ErfcFast(spz*z1) - AliMathBase::ErfcFast(spz*z2);
+       if (GetDebug(3)) cout<<" spz*z1="<<spz*z1<<" spz*z2="<<spz*z2<<" s="<<s<< endl; // end if GetDebug
+       GetMap()->AddSignal(iz,ix,t,hi,GetModuleNumber(),s*el);
+     } // end for ix, iz
+}
+
+//______________________________________________________________________
+void AliITSsimulationPixUpg::RemoveDeadPixels() 
+{
+  // Removes dead pixels on each module (ladder)
+  // This should be called before going from sdigits to digits (FrompListToDigits)
+  Int_t mod = GetModuleNumber();
+  AliITSCalibrationPixUpg* calObj = (AliITSCalibrationPixUpg*) fDetType->GetCalibrationModel(mod);
+
+  Int_t nrDead = calObj->GetNrBad();
+  for (Int_t i=0; i<nrDead; i++) GetMap()->DeleteHit(calObj->GetBadColAt(i), calObj->GetBadRowAt(i));
+  //
+}
+
+//______________________________________________________________________
+void AliITSsimulationPixUpg::AddNoisyPixels() 
+{
+  // Adds noisy pixels on each module (ladder)
+  // This should be called before going from sdigits to digits (FrompListToDigits)
+  Int_t mod = GetModuleNumber();
+  AliITSCalibrationPixUpg* calObj = (AliITSCalibrationPixUpg*) fDetType->GetPixNoisyModel(mod);
+  //
+  Int_t nrNoisy = calObj->GetNrBad();
+  for (Int_t i=0; i<nrNoisy; i++) {
+    // adding 10 times the threshold will for sure make this pixel fire...
+    GetMap()->AddNoise(calObj->GetBadColAt(i), calObj->GetBadRowAt(i), mod, 10*GetThreshold());
+  }
+}
+
+//______________________________________________________________________
+void AliITSsimulationPixUpg::FrompListToDigits() 
+{
+  // add noise and electronics, perform the zero suppression and add the
+  // digit to the list
+  // Inputs:
+  //    none.
+  // Outputs:
+  //    none.
+  // Return:
+  //    none.
+  static AliITS *aliITS = (AliITS*)gAlice->GetModule("ITS");
+  Int_t j,ix,iz;
+  Double_t  electronics;
+  Double_t sig;
+  const Int_t    knmaxtrk=AliITSdigit::GetNTracks();
+  static AliITSdigitSPD dig;
+  AliITSSimuParam *simpar = fDetType->GetSimuParam();
+  if (GetDebug(1)) Info("FrompListToDigits","()");
+  for (iz=0; iz<GetNPixelsZ(); iz++) 
+    for (ix=0; ix<GetNPixelsX(); ix++) {
+      electronics = simpar->ApplySPDBaselineAndNoise();
+      UpdateMapNoise(ix,iz,electronics);
+      //
+      // Apply Threshold and write Digits.
+      sig = GetMap()->GetSignalOnly(iz,ix);
+      FillHistograms(ix,iz,sig+electronics);
+      if (GetDebug(3)) {
+       cout<<sig<<"+"<<electronics<<">threshold("<<ix<<","<<iz
+               <<")="<<GetThreshold() <<endl;
+      } // end if GetDebug
+      // if (sig+electronics <= GetThreshold()) continue;
+      if (GetMap()->GetSignal(iz,ix) <= GetThreshold()) continue;
+      dig.SetCoord1(iz);
+      dig.SetCoord2(ix);
+      dig.SetSignal(1);
+      
+      //        dig.SetSignalSPD((Int_t) GetMap()->GetSignal(iz,ix));
+      Double_t aSignal =  GetMap()->GetSignal(iz,ix);
+      if (TMath::Abs(aSignal)>2147483647.0) {
+       //PH 2147483647 is the max. integer
+       //PH This apparently is a problem which needs investigation
+       AliWarning(Form("Too big or too small signal value %f",aSignal));
+       aSignal = TMath::Sign((Double_t)2147483647,aSignal);
+      }
+      dig.SetSignalSPD((Int_t)aSignal);
+      
+      for (j=0;j<knmaxtrk;j++) {
+       if (j<GetMap()->GetNEntries()) {
+         dig.SetTrack(j,GetMap()->GetTrack(iz,ix,j));
+         dig.SetHit(j,GetMap()->GetHit(iz,ix,j));
+       }else { // Default values
+         dig.SetTrack(j,-3);
+         dig.SetHit(j,-1);
+       } // end if GetMap()
+      } // end for j
+      if (GetDebug(3)) {
+       cout<<iz<<","<<ix<<","<<*(GetMap()->GetpListItem(iz,ix))<<endl;
+      } // end if GetDebug
+      aliITS->AddSimDigit(0,&dig);
+      // simulate fo signal response for this pixel hit:
+      //RS      fDetType->ProcessSPDDigitForFastOr(fModule, dig.GetCoord1(), dig.GetCoord2());
+    } //  for ix/iz
+}
+
+//______________________________________________________________________
+void AliITSsimulationPixUpg::CreateHistograms() 
+{
+   // create 1D histograms for tests
+   // Inputs:
+   //    none.
+   // Outputs:
+   //    none.
+   // Return:
+   //     none.
+
+   if (GetDebug(1)) Info("CreateHistograms","create histograms");
+
+   fHistos = new TObjArray(GetNPixelsZ());
+   fHistName="pix_";
+   for (Int_t i=0;i<GetNPixelsZ();i++) {
+     Char_t pixelz[4];
+     snprintf(pixelz,3,"%d",i);
+     fHistName.Append(pixelz);
+     fHistos->AddAt(new TH1F(fHistName.Data(),"pixel maps",
+                            GetNPixelsX(),0.,(Double_t)GetNPixelsX()),i);
+   } // end for i
+}
+
+//______________________________________________________________________
+void AliITSsimulationPixUpg::FillHistograms(Int_t ix,Int_t iz,Double_t v) 
+{
+   // Fill the histogram
+   // Inputs:
+   //    none.
+   // Outputs:
+   //    none.
+   // Return:
+   //     none.
+  
+  if (!GetHistArray()) return; // Only fill if setup.
+  if (GetDebug(2)) Info("FillHistograms","fill histograms");
+  GetHistogram(iz)->Fill(ix,v);
+}
+
+//______________________________________________________________________
+void AliITSsimulationPixUpg::ResetHistograms() 
+{
+  // Reset histograms for this detector
+  // Inputs:
+  //    none.
+  // Outputs:
+  //    none.
+  // Return:
+  //     none.
+  
+  if (!GetHistArray()) return; // Only fill if setup.
+  if (GetDebug(2)) Info("FillHistograms","fill histograms");
+  for ( int i=0;i<GetNPixelsZ();i++ ) if (fHistos->At(i))    ((TH1F*)fHistos->At(i))->Reset();
+  //
+}
+
+//______________________________________________________________________
+void AliITSsimulationPixUpg::SetCoupling(Int_t col, Int_t row, Int_t ntrack, Int_t idhit) {
+  //  Take into account the coupling between adiacent pixels.
+  //  The parameters probcol and probrow are the probability of the
+  //  signal in one pixel shared in the two adjacent pixels along
+  //  the column and row direction, respectively.
+  //  Note pList is goten via GetMap() and module is not need any more.
+  //  Otherwise it is identical to that coded by Tiziano Virgili (BSN).
+  //Begin_Html
+  /*
+    <img src="picts/ITS/barimodel_3.gif">
+     </pre>
+     <br clear=left>
+     <font size=+2 color=red>
+     <a href="mailto:tiziano.virgili@cern.ch"></a>.
+     </font>
+     <pre>
+   */
+   //End_Html
+   // Inputs:
+   //    Int_t col            z cell index
+   //    Int_t row            x cell index
+   //    Int_t ntrack         track incex number
+   //    Int_t idhit          hit index number
+   // Outputs:
+   //    none.
+   // Return:
+   //     none.
+   Int_t j1,j2,flag=0;
+   Double_t pulse1,pulse2;
+   Double_t couplR=0.0,couplC=0.0;
+   Double_t xr=0.;
+
+   GetCouplings(couplC,couplR);
+   if (GetDebug(3)) Info("SetCoupling","(col=%d,row=%d,ntrack=%d,idhit=%d) "
+                        "Calling SetCoupling couplC=%e couplR=%e",
+                        col,row,ntrack,idhit,couplC,couplR);
+   j1 = col;
+   j2 = row;
+   pulse1 = GetMap()->GetSignalOnly(col,row);
+   pulse2 = pulse1;
+   for (Int_t isign=-1;isign<=1;isign+=2) {// loop in col direction
+     do {
+       j1 += isign;
+       xr = gRandom->Rndm();
+       if ((j1<0) || (j1>GetNPixelsZ()-1) || (xr>couplC)) {
+        j1 = col;
+        flag = 1;
+       } else {
+        UpdateMapSignal(row,j1,ntrack,idhit,pulse1);
+        //  flag = 0;
+        flag = 1; // only first next!!
+       } // end if
+     } while (flag == 0);
+     // loop in row direction
+     do {
+       j2 += isign;
+       xr = gRandom->Rndm();
+       if ((j2<0) || (j2>GetNPixelsX()-1) || (xr>couplR)) {
+        j2 = row;
+        flag = 1;
+       } else {
+        UpdateMapSignal(j2,col,ntrack,idhit,pulse2);
+        //  flag = 0;
+        flag = 1; // only first next!!
+       } // end if
+     } while(flag == 0);
+   } // for isign
+}
+
+//______________________________________________________________________
+void AliITSsimulationPixUpg::SetCouplingOld(Int_t col, Int_t row,Int_t ntrack,Int_t idhit) 
+{
+  //  Take into account the coupling between adiacent pixels.
+  //  The parameters probcol and probrow are the fractions of the
+  //  signal in one pixel shared in the two adjacent pixels along
+  //  the column and row direction, respectively.
+  //Begin_Html
+  /*
+    <img src="picts/ITS/barimodel_3.gif">
+    </pre>
+    <br clear=left>
+    <font size=+2 color=red>
+    <a href="mailto:Rocco.Caliandro@ba.infn.it"></a>.
+    </font>
+    <pre>
+  */
+  //End_Html
+  // Inputs:
+  //    Int_t col            z cell index
+  //    Int_t row            x cell index
+  //    Int_t ntrack         track incex number
+  //    Int_t idhit          hit index number
+  //    Int_t module         module number
+  // Outputs:
+  //    none.
+  // Return:
+  //     none.
+  Int_t j1,j2,flag=0;
+  Double_t pulse1,pulse2;
+  Double_t couplR=0.0,couplC=0.0;
+  
+  GetCouplings(couplC,couplR);
+  
+  //  Debugging ...
+  //    cout << "Threshold --> " << GetThreshold() << endl;  // dom
+  //    cout << "Couplings --> " << couplC << " " << couplR << endl;  // dom
+  
+  if (GetDebug(3)) Info("SetCouplingOld","(col=%d,row=%d,ntrack=%d,idhit=%d) "
+                        "Calling SetCoupling couplC=%e couplR=%e",
+                        col,row,ntrack,idhit,couplC,couplR);
+  for (Int_t isign=-1;isign<=1;isign+=2) {// loop in col direction
+    pulse1 = GetMap()->GetSignalOnly(col,row);
+    pulse2 = pulse1;
+    j1 = col;
+    j2 = row;
+    do{
+      j1 += isign;
+      pulse1 *= couplC;
+      if ((j1<0)||(j1>GetNPixelsZ()-1)||(pulse1<GetThreshold())) {
+       pulse1 = GetMap()->GetSignalOnly(col,row);
+       j1 = col;
+       flag = 1;
+      }else{
+       UpdateMapSignal(row,j1,ntrack,idhit,pulse1);
+       // flag = 0;
+       flag = 1;  // only first next !!
+      } // end if
+    } while(flag == 0);
+    // loop in row direction
+    do{
+      j2 += isign;
+      pulse2 *= couplR;
+      if ((j2<0)||(j2>(GetNPixelsX()-1))||(pulse2<GetThreshold())) {
+       pulse2 = GetMap()->GetSignalOnly(col,row);
+       j2 = row;
+       flag = 1;
+      }else{
+       UpdateMapSignal(j2,col,ntrack,idhit,pulse2);
+       // flag = 0;
+       flag = 1; // only first next!!
+      } // end if
+    } while(flag == 0);
+  } // for isign
+}
+
+//______________________________________________________________________
+void AliITSsimulationPixUpg::GenerateStrobePhase()
+{
+  // Generate randomly the strobe
+  // phase w.r.t to the LHC clock
+  // Done once per event
+  const Double_t kBunchLenght = 25e-9; // LHC clock
+  fStrobePhase = ((Double_t)gRandom->Integer(fStrobeLenght))*kBunchLenght-
+    (Double_t)fStrobeLenght*kBunchLenght+
+    kBunchLenght/2;
+}
+
diff --git a/ITS/UPGRADE/AliITSsimulationPixUpg.h b/ITS/UPGRADE/AliITSsimulationPixUpg.h
new file mode 100644 (file)
index 0000000..9afa6f5
--- /dev/null
@@ -0,0 +1,126 @@
+#ifndef ALIITSSIMULATIONPIXUPG_H
+#define ALIITSSIMULATIONPIXUPG_H
+
+/* Copyright(c) 2007-2009, ALICE Experiment at CERN, All rights reserved. *
+* See cxx source for full Copyright notice                               */
+
+////////////////////////////////////////////////////////////
+// Simulation class for upgrade pixels                    //
+////////////////////////////////////////////////////////////
+
+#include "TObjArray.h"
+#include "AliITSsimulation.h"
+#include "AliITSsegmentationPixUpg.h"
+#include "AliITSDetTypeSimUpg.h"
+
+class TH1F;
+class AliITSmodule;
+
+//-------------------------------------------------------------------
+
+class AliITSsimulationPixUpg : public AliITSsimulation {
+public:
+  AliITSsimulationPixUpg();
+  AliITSsimulationPixUpg(AliITSDetTypeSimUpg *dettyp);
+  virtual ~AliITSsimulationPixUpg();
+  AliITSsimulationPixUpg(const AliITSsimulationPixUpg &source); 
+  AliITSsimulationPixUpg& operator=(const AliITSsimulationPixUpg &s);
+  void Init();
+  //
+  // General User calling routines
+  // Initilize simulation for a specific event and module
+  void InitSimulationModule(Int_t module, Int_t event);
+  // Finish and write S Digitization
+  void FinishSDigitiseModule();
+  // From hits to Digits, without creating SDigits
+  void DigitiseModule(AliITSmodule *mod,Int_t,Int_t);
+  //
+   // More or less Internal Routines
+   // Create S Digits from specific module
+   void SDigitiseModule(AliITSmodule *mod, Int_t mask, Int_t event);
+   // Write S Digits to the tree of SDigits.
+   void WriteSDigits();
+   // fill pList from hits, charge sharing, diffusion, coupling
+   void HitToSDigit(AliITSmodule *mod);
+   // fill pList from hits, charge sharing, diffusion, coupling  (faster method optimized by Bjorne)
+   void HitToSDigitFast(AliITSmodule *mod);
+   // Adds noisy pixels to pList
+   void AddNoisyPixels();   
+   // Removes dead pixels from pList
+   void RemoveDeadPixels();
+   // Take pList of signals and apply noise... create Digits
+   void FrompListToDigits();
+   // This set the Lorentz drift of Electrons and Holes: by deafult equal weights to Electrons and Holes
+   void SetLorentzDrift(Bool_t b=kFALSE)
+   {fLorentz=b; if(fLorentz) SetTanLorAngle();};
+   // This function set the relative contribution between holes and electrons: use  0<=WeightHole<=1
+   Bool_t SetTanLorAngle(Double_t WeightHole=1.0);
+   // Getter for the Lorentz angle
+   Double_t GetTanLorAngle() const {return fTanLorAng;};
+   //
+   void CreateHistograms();
+   void FillHistograms(Int_t ix,Int_t iz,Double_t v=1.0);
+   void ResetHistograms();
+   TH1F* GetHistogram(Int_t i){return (TH1F*)(fHistos->At(i));}// get histogram
+   TObjArray*  GetHistArray() {return fHistos;}// get hist array
+   TString& GetHistName(){return fHistName;}
+   void SetHistName(TString &n){fHistName = n;}
+   //
+   // For backwards compatibility
+   void SDigitsToDigits(){ FinishSDigitiseModule();};
+   void HitToDigit(AliITSmodule *mod){
+     // Standard interface to DigitiseModule  Inputs: AliITSmodule *mod  Pointer to this module
+     DigitiseModule(mod,GetModuleNumber(),0);};
+   
+   // This sets fStrobe flag and allows generating the strobe and applying it to select hits 
+   void SetStrobeGeneration(Bool_t b=kFALSE) {fStrobe=b;};
+   void GenerateStrobePhase();
+   
+ private:
+   void SpreadCharge(Double_t x0,Double_t z0,Int_t ix0,Int_t iz0,
+                    Double_t el,Double_t sig,Double_t ld,Int_t t,Int_t hi);
+   void SpreadChargeAsym(Double_t x0,Double_t z0,Int_t ix0,Int_t iz0,
+                        Double_t el,Double_t sigx,Double_t sigz,Double_t ld,Int_t t,Int_t hi);
+   void UpdateMapSignal(Int_t ix,Int_t iz,Int_t trk,Int_t ht,Double_t signal){
+     //  This function adds a signal to the pList from the pList class
+     //  Inputs: iz column number  ix row number  trk track number  ht hit number  signal signal strength
+     GetMap()->AddSignal(iz,ix,trk,ht,GetModuleNumber(),signal);};
+   void UpdateMapNoise(Int_t ix,Int_t iz,Float_t noise){
+     //  This function adds noise to data in the MapA2 as well as the pList
+     //  Inputs:  iz column number  ix row number  noise electronic noise generated by FrompListToDigits
+     GetMap()->AddNoise(iz,ix,GetModuleNumber(),noise);}
+   // Get a pointer to the segmentation object
+   virtual AliITSsegmentation* GetSegmentationModel(Int_t /*dt*/){return fDetType->GetSegmentationModel(AliITSDetTypeSimUpg::kDetPixUpg);}
+   // set pointer to segmentation objec
+   virtual void SetSegmentationModel(Int_t /*dt*/, AliITSsegmentation *seg){fDetType->SetSegmentationModel(AliITSDetTypeSimUpg::kDetPixUpg,seg);}
+   // Bari-Salerno Coupling parameters
+   // "New" coupling routine  Tiziano Virgili
+   void SetCoupling(Int_t col,Int_t row,Int_t ntrack,Int_t idhit);
+   // "Old" coupling routine  Rocco Caliandro
+   void SetCouplingOld(Int_t col, Int_t row,Int_t ntrack,Int_t idhit);
+   // Getters for data kept in fSegmentation and fResponse.
+   // Returns the Threshold in electrons
+   Double_t GetThreshold(){
+     Double_t th,sig;AliITSSimuParam* simpar = fDetType->GetSimuParam(); 
+     simpar->SPDThresholds(GetModuleNumber(),th,sig);return th;}; 
+   // Returns the couplings Columb and Row.
+   void GetCouplings(Double_t &cc,Double_t &cr){
+     AliITSSimuParam* simpar = fDetType->GetSimuParam();
+     simpar->GetSPDCouplingParam(cc,cr);};
+   // Returns the number of pixels in x
+   Int_t GetNPixelsX(){return GetSegmentationModel(-1)->Npx();};
+   // Returns the number of pixels in z
+   Int_t GetNPixelsZ(){return GetSegmentationModel(-1)->Npz();};
+   
+   TObjArray    *fHistos;         //! just in case for histogramming
+   TString       fHistName;      //! Histogram name
+   Int_t         fCoupling;     // Sets the coupling to be used.
+                                // ==1 use SetCoupling, ==2 use SetCouplingOld
+   Bool_t        fLorentz;      // kTRUE if Lorentz drift has been allowed 
+   Double_t      fTanLorAng;    //! Tangent of the Lorentz Angle (weighted average for hole and electrons)
+   Bool_t        fStrobe;       // kTRUE if readout strobe with proper phase applied to select hits
+   Int_t         fStrobeLenght; // Strobe signal lenght in units of 25 ns
+   Double_t      fStrobePhase;  // The phase of the strobe signal with respect to the trigger
+   ClassDef(AliITSsimulationPixUpg,1)  // Simulation of pixel clusters
+ };
+#endif 
similarity index 91%
rename from ITS/CMakelibITSUpgradeBase.pkg
rename to ITS/UPGRADE/CMakelibITSUpgradeBase.pkg
index bc2f200..97b7286 100644 (file)
 # SHLIBS - Shared Libraries and objects for linking (Executables only)           #
 #--------------------------------------------------------------------------------#
 
-set ( SRCS     UPGRADE/v0/AliITSDigitUpgrade.cxx UPGRADE/v0/AliITSsegmentationUpgrade.cxx UPGRADE/v0/AliITSRecPointU.cxx UPGRADE/AliITSInitGeometryUpg.cxx UPGRADE/AliITSLoaderUpg.cxx UPGRADE/AliITSgeomTGeoUpg.cxx)
+set ( SRCS 
+v0/AliITSDigitUpgrade.cxx 
+v0/AliITSsegmentationUpgrade.cxx 
+v0/AliITSRecPointU.cxx 
+#
+AliITSInitGeometryUpg.cxx 
+AliITSLoaderUpg.cxx 
+AliITSgeomTGeoUpg.cxx
+AliITSCalibrationPixUpg.cxx
+AliITSsegmentationPixUpg.cxx
+)
 
 string ( REPLACE ".cxx" ".h" HDRS "${SRCS}" )
 
similarity index 86%
rename from ITS/CMakelibITSUpgradeRec.pkg
rename to ITS/UPGRADE/CMakelibITSUpgradeRec.pkg
index ae159f4..7846260 100644 (file)
 #--------------------------------------------------------------------------------#
 
 set ( SRCS  
-    UPGRADE/v0/AliITSlayerUpgrade.cxx 
-    UPGRADE/v0/AliITStrackerUpgrade.cxx 
-    UPGRADE/v0/AliITStrackU.cxx 
-    UPGRADE/AliITStrackerU.cxx 
-    UPGRADE/v0/AliITSUpgradeReconstructor.cxx 
-    UPGRADE/v0/AliITSUpgradeClusterList.cxx 
-    UPGRADE/v0/AliITSUpgradeClusterListNode.cxx 
-    UPGRADE/v0/AliITSUPixelModule.cxx 
-    UPGRADE/v0/AliITSUpgradeClusterFinder.cxx 
+    v0/AliITSlayerUpgrade.cxx 
+    v0/AliITStrackerUpgrade.cxx 
+    v0/AliITStrackU.cxx 
+    AliITStrackerU.cxx 
+    v0/AliITSUpgradeReconstructor.cxx 
+    v0/AliITSUpgradeClusterList.cxx 
+    v0/AliITSUpgradeClusterListNode.cxx 
+    v0/AliITSUPixelModule.cxx 
+    v0/AliITSUpgradeClusterFinder.cxx 
     )
 
 string ( REPLACE ".cxx" ".h" HDRS "${SRCS}" )
similarity index 92%
rename from ITS/CMakelibITSUpgradeSim.pkg
rename to ITS/UPGRADE/CMakelibITSUpgradeSim.pkg
index f486e3e..5789465 100644 (file)
 # SHLIBS - Shared Libraries and objects for linking (Executables only)           #
 #--------------------------------------------------------------------------------#
 
-set ( SRCS     UPGRADE/v0/AliITSupgrade.cxx UPGRADE/v0/AliITSupgradeDigitizer.cxx UPGRADE/AliITSUpg.cxx UPGRADE/AliITSvUpgrade.cxx UPGRADE/AliITSv11GeometryUpgrade.cxx UPGRADE/AliITSv11GeomBeamPipe.cxx)
+set ( SRCS     
+v0/AliITSupgrade.cxx 
+v0/AliITSupgradeDigitizer.cxx 
+#
+AliITSUpg.cxx 
+AliITSvUpgrade.cxx 
+AliITSv11GeometryUpgrade.cxx 
+AliITSv11GeomBeamPipe.cxx
+)
 
 string ( REPLACE ".cxx" ".h" HDRS "${SRCS}" )
 
similarity index 82%
rename from ITS/ITSUpgradeBaseLinkDef.h
rename to ITS/UPGRADE/ITSUpgradeBaseLinkDef.h
index a80634f..aa21225 100644 (file)
@@ -9,11 +9,16 @@
 #pragma link off all functions;
 
 // ITS upgrade classes 
+// v0 part >>>
 #pragma link C++ class  AliITSDigitUpgrade+;
 #pragma link C++ class  AliITSsegmentationUpgrade+;
 #pragma link C++ class  AliITSRecPointU+;
+// v0 part <<<
+//
 #pragma link C++ class  AliITSInitGeometryUpg+;
 #pragma link C++ class  AliITSLoaderUpg+;
 #pragma link C++ class  AliITSgeomTGeoUpg+;
+#pragma link C++ class  AliITSCalibrationPixUpg+;
+#pragma link C++ class  AliITSsegmentationPixUpg+;
 
 #endif
similarity index 94%
rename from ITS/ITSUpgradeSimLinkDef.h
rename to ITS/UPGRADE/ITSUpgradeSimLinkDef.h
index 2cbd9ba..40a185b 100644 (file)
 //#pragma link C++ global gITSdisplay;  // global used by AliITSdisplay
 
 // ITS upgrade classes
+//v0 part >>>. obsolete?
 #pragma link C++ class  AliITSupgrade+;
 #pragma link C++ class  AliITSupgradeDigitizer+;
+//v0 part <<<
+// 
 #pragma link C++ class  AliITSUpg+;
 #pragma link C++ class  AliITSvUpgrade+;
 #pragma link C++ class  AliITSv11GeometryUpgrade+;
 #pragma link C++ class  AliITSv11GeomBeamPipe+;
 
+
 #endif