Committ for the simulation a more detailed description of the ITS upgrade (Mario...
authoramastros <amastros@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 28 Jul 2011 14:56:30 +0000 (14:56 +0000)
committeramastros <amastros@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 28 Jul 2011 14:56:30 +0000 (14:56 +0000)
It contains :
- classes which simulate the geometry up to the volume hits.
- demo macros for the detector configuration

Note : CMake files to be committed soon.

12 files changed:
ITS/UPGRADE/AliITSInitGeometryUpg.cxx [new file with mode: 0644]
ITS/UPGRADE/AliITSInitGeometryUpg.h [new file with mode: 0644]
ITS/UPGRADE/AliITSLoaderUpg.cxx [new file with mode: 0644]
ITS/UPGRADE/AliITSLoaderUpg.h [new file with mode: 0644]
ITS/UPGRADE/AliITSUpg.cxx [new file with mode: 0644]
ITS/UPGRADE/AliITSUpg.h [new file with mode: 0644]
ITS/UPGRADE/AliITSv11GeometryUpgrade.cxx [new file with mode: 0644]
ITS/UPGRADE/AliITSv11GeometryUpgrade.h [new file with mode: 0644]
ITS/UPGRADE/AliITSvUpgrade.cxx [new file with mode: 0644]
ITS/UPGRADE/AliITSvUpgrade.h [new file with mode: 0644]
ITS/UPGRADE/ConfigTGeoUpgrade.C [new file with mode: 0644]
ITS/UPGRADE/simTGeoUpgrade.C [new file with mode: 0644]

diff --git a/ITS/UPGRADE/AliITSInitGeometryUpg.cxx b/ITS/UPGRADE/AliITSInitGeometryUpg.cxx
new file mode 100644 (file)
index 0000000..b86ab8e
--- /dev/null
@@ -0,0 +1,1303 @@
+/**************************************************************************
+ * 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: AliITSInitGeometryUpg.cxx $
+*/
+////////////////////////////////////////////////////////////////
+//  This class initializes the class AliITSgeom
+//  The initialization is done starting from 
+//  a geometry coded by means of the ROOT geometrical modeler
+//  This initialization can be used both for simulation and reconstruction
+///////////////////////////////////////////////////////////////
+
+#include <TArrayD.h>
+#include <TArrayF.h>
+#include <TStopwatch.h>
+#include <TGeoManager.h>
+#include <TGeoMatrix.h>
+#include <TGeoVolume.h>
+#include <TGeoShape.h>
+#include <TGeoBBox.h>
+#include <TGeoTrd1.h>
+#include <TGeoTrd2.h>
+#include <TGeoArb8.h>
+#include <TGeoTube.h>
+#include <TGeoCone.h>
+#include <TGeoSphere.h>
+#include <TGeoPara.h>
+#include <TGeoPgon.h>
+#include <TGeoPcon.h>
+#include <TGeoEltu.h>
+#include <TGeoHype.h>
+#include <TMath.h>
+
+#include "AliLog.h"
+#include "AliITSInitGeometryUpg.h"
+#include <TDatime.h>
+
+ClassImp(AliITSInitGeometryUpg)
+
+//______________________________________________________________________
+AliITSInitGeometryUpg::AliITSInitGeometryUpg():
+TObject(),                   // Base Class
+fName(0),                    // Geometry name
+fMinorVersion(-1),           // Minor version number/type
+fMajorVersion(kvDefault),    // Major versin number
+fTiming(kFALSE),             // Flag to start inilization timing
+fSegGeom(kFALSE),            // Flag to switch between the old use of
+                             // AliITSgeomS?D class, or AliITSsegmentation
+                             // class in fShape of AliITSgeom class.
+fDecode(kFALSE),             // Flag for new/old decoding
+fDebug(0){                   // Debug flag
+    // Default Creator
+    // Inputs:
+    //   none.
+    // Outputs:
+    //   none.
+    // Return:
+    //   A default inilized AliITSInitGeometryUpg object
+
+    fName = "Undefined";
+}
+//______________________________________________________________________
+AliITSInitGeometryUpg::AliITSInitGeometryUpg(AliITSVersion_t version,
+                                            Int_t minorversion):
+TObject(),                   // Base Class
+fName(0),                    // Geometry name
+fMinorVersion(minorversion), // Minor version number/type
+fMajorVersion(version),      // Major versin number
+fTiming(kFALSE),             // Flag to start inilization timing
+fSegGeom(kFALSE),            // Flag to switch between the old use of
+                             // AliITSgeomS?D class, or AliITSsegmentation
+                             // class in fShape of AliITSgeom class.
+fDecode(kFALSE),             // Flag for new/old decoding
+fDebug(0){                   // Debug flag
+    // Default Creator
+    // Inputs:
+    //   none.
+    // Outputs:
+    //   none.
+    // Return:
+    //   A default inilized AliITSInitGeometryUpg object
+
+  switch (version) {
+    case kv11:
+        fName="AliITSv11";
+       break;
+    case kvUpgrade:
+        fName="AliITSvUpgrade";
+       break;
+    case kvDefault:
+    default:
+        AliFatal(Form("Undefined geometry: fMajorVersion=%d, "
+                      "fMinorVersion= %d",(Int_t)fMajorVersion,fMinorVersion));
+        fName = "Undefined";
+       break;
+    } // switch
+}
+//______________________________________________________________________
+AliITSgeom* AliITSInitGeometryUpg::CreateAliITSgeom(){
+    // Creates and Initilizes the geometry transformation class AliITSgeom
+    // to values appropreate to this specific geometry. Now that
+    // the segmentation is part of AliITSgeom, the detector
+    // segmentations are also defined here.
+    // Inputs:
+    //   none.
+    // Outputs:
+    //   none.
+    // Return:
+    //   A pointer to a new properly inilized AliITSgeom class. If
+    //   pointer = 0 then failed to init.
+
+
+  AliITSVersion_t version = kvDefault;
+  Int_t minor = 0;
+  TDatime datetime;
+  TGeoVolume *itsV = gGeoManager->GetVolume("ITSV");
+  if(!itsV){
+    Error("CreateAliITSgeom","Can't find ITS volume ITSV, aborting");
+    return 0;
+  }// end if
+  const Char_t *title = itsV->GetTitle();
+  if(!ReadVersionString(title,(Int_t)strlen(title),version,minor,
+                       datetime))
+    Warning("UpdateInternalGeometry","Can't read title=%s\n",title);
+  SetTiming(kFALSE);
+  SetSegGeom(kFALSE);
+  SetDecoding(kFALSE);
+  AliITSgeom *geom = CreateAliITSgeom(version,minor);
+  AliDebug(1,"AliITSgeom object has been initialized from TGeo\n");
+  return geom;
+}
+//______________________________________________________________________
+AliITSgeom* AliITSInitGeometryUpg::CreateAliITSgeom(Int_t major,Int_t minor){
+    // Creates and Initilizes the geometry transformation class AliITSgeom
+    // to values appropreate to this specific geometry. Now that
+    // the segmentation is part of AliITSgeom, the detector
+    // segmentations are also defined here.
+    // Inputs:
+    //   Int_t major   major version, see AliITSVersion_t
+    //   Int_t minor   minor version
+    // Outputs:
+    //   none.
+    // Return:
+    //   A pointer to a new properly inilized AliITSgeom class. If
+    //   pointer = 0 then failed to init.
+
+    switch(major){
+    case kv11:
+        SetGeometryName("AliITSv11");
+        SetVersion(kv11,minor);
+        break;
+    case kvUpgrade:
+        SetGeometryName("AliITSvUpgrade");
+        SetVersion(kvUpgrade,minor);
+        break;
+    case kvDefault:
+    default:
+        SetGeometryName("Undefined");
+        SetVersion(kvDefault,minor);
+        break;
+    } // end switch
+    AliITSgeom *geom = new AliITSgeom();
+    if(!InitAliITSgeom(geom)){ // Error initilization failed
+       delete geom;
+       geom = 0;
+    } // end if
+    return geom;
+}
+//______________________________________________________________________
+Bool_t AliITSInitGeometryUpg::InitAliITSgeom(AliITSgeom *geom){
+  // Initilizes the geometry transformation class AliITSgeom
+  // to values appropreate to this specific geometry. Now that
+  // the segmentation is part of AliITSgeom, the detector
+  // segmentations are also defined here.
+  // Inputs:
+  //   AliITSgeom *geom  A pointer to the AliITSgeom class
+  // Outputs:
+  //   AliITSgeom *geom  This pointer recreated and properly inilized.
+  // Return:
+  //   none.
+
+    if(!gGeoManager){
+        AliFatal("The geometry manager has not been initialized (e.g. "
+                 "TGeoManager::Import(\"geometry.root\")should be "
+                 "called in advance) - exit forced");
+        return kFALSE;
+    } // end if
+    switch(fMajorVersion) {
+    case kv11: {
+        return InitAliITSgeomV11(geom);
+    } break; // end case
+    case kvUpgrade: {
+        return InitAliITSgeomVUpgrade(geom);
+    } break; // end case
+    case kvDefault: default: {
+        AliFatal("Undefined geometry");
+        return kFALSE;
+    } break; // end case
+    } // end switch
+    return kFALSE;
+}
+//______________________________________________________________________
+void AliITSInitGeometryUpg::TransposeTGeoHMatrix(TGeoHMatrix *m)const{
+    // Transpose the rotation matrix part of a TGeoHMatrix. This
+    // is needed because TGeo stores the transpose of the rotation
+    // matrix as compared to what AliITSgeomMatrix uses (and Geant3).
+    // Inputs:
+    //    TGeoHMatrix *m  The matrix to be transposed
+    // Outputs:
+    //    TGEoHMatrix *m  The transposed matrix
+    // Return:
+    //    none.
+    Int_t i;
+    Double_t r[9];
+
+    if(m==0) return; // no matrix to transpose.
+    for(i=0;i<9;i += 4) r[i] = m->GetRotationMatrix()[i]; // diagonals
+    r[1] = m->GetRotationMatrix()[3];
+    r[2] = m->GetRotationMatrix()[6];
+    r[3] = m->GetRotationMatrix()[1];
+    r[5] = m->GetRotationMatrix()[7];
+    r[6] = m->GetRotationMatrix()[2];
+    r[7] = m->GetRotationMatrix()[5];
+    m->SetRotation(r);
+    return;
+}
+
+
+//______________________________________________________________________
+Bool_t AliITSInitGeometryUpg::InitAliITSgeomV11(AliITSgeom *geom){
+  // Initilizes the geometry transformation class AliITSgeom
+  // Now that the segmentation is part of AliITSgeom, the detector
+  // segmentations are also defined here.
+  //
+  // Inputs:
+  //   AliITSgeom *geom  A pointer to the AliITSgeom class
+  // Outputs:
+  //   AliITSgeom *geom  This pointer recreated and properly inilized.
+  // LG
+
+  const Int_t kItype  = 0; // Type of transformation defined 0=> Geant
+  const Int_t klayers = 6; // number of layers in the ITS
+  const Int_t kladders[klayers]   = {20,40,14,22,34,38}; // Number of ladders
+  const Int_t kdetectors[klayers] = {4,4,6,8,22,25};// number of detector/lad
+  const AliITSDetector kIdet[6]   = {kSPD,kSPD,kSDD,kSDD,kSSD,kSSD};
+  const TString kPathbase = "/ALIC_1/ITSV_1/";
+
+  const char *pathSPDsens1, *pathSPDsens2;
+  pathSPDsens1="%sITSSPD_1/ITSSPDCarbonFiberSectorV_%d/ITSSPDSensitiveVirtualvolumeM0_1/ITSSPDlay1-Stave_%d/ITSSPDhalf-Stave%d_1/ITSSPDlay1-Ladder_%d/ITSSPDlay1-sensor_1";
+  pathSPDsens2="%sITSSPD_1/ITSSPDCarbonFiberSectorV_%d/ITSSPDSensitiveVirtualvolumeM0_1/ITSSPDlay2-Stave_%d/ITSSPDhalf-Stave%d_1/ITSSPDlay2-Ladder_%d/ITSSPDlay2-sensor_1";
+
+  const char *pathSDDsens1, *pathSDDsens2;
+  pathSDDsens1 = "%sITSsddLayer3_1/ITSsddLadd_%d/ITSsddSensor3_%d/ITSsddWafer3_%d/ITSsddSensitivL3_1";
+  pathSDDsens2 = "%sITSsddLayer4_1/ITSsddLadd_%d/ITSsddSensor4_%d/ITSsddWafer4_%d/ITSsddSensitivL4_1";
+
+  const char *pathSSDsens1, *pathSSDsens2;
+  pathSSDsens1 = "%sITSssdLayer5_1/ITSssdLay5Ladd_%d/ITSssdSensor5_%d/ITSssdSensitivL5_1";
+  pathSSDsens2 = "%sITSssdLayer6_1/ITSssdLay6Ladd_%d/ITSssdSensor6_%d/ITSssdSensitivL6_1";
+
+  const TString kNames[klayers] = {
+    pathSPDsens1, // lay=1
+    pathSPDsens2, // lay=2
+    pathSDDsens1, // lay=3
+    pathSDDsens2, // lay=4
+    pathSSDsens1, // lay=5
+    pathSSDsens2};// Lay=6
+  
+  Int_t mod,nmods=0, lay, lad, det, cpn0, cpn1, cpn2, cpnHS=1;
+  Double_t tran[3]={0.,0.,0.}, rot[10]={9*0.0,1.0};
+  TArrayD shapePar;
+  TString path, shapeName;
+  TGeoHMatrix matrix;
+  Bool_t initSeg[3]={kFALSE, kFALSE, kFALSE};
+  TStopwatch *time = 0x0;
+  if(fTiming) time = new TStopwatch();
+
+  if(fTiming) time->Start();
+  for(mod=0;mod<klayers;mod++) nmods += kladders[mod]*kdetectors[mod];
+  geom->Init(kItype,klayers,kladders,kdetectors,nmods);
+
+  for(mod=0; mod<nmods; mod++) {
+
+    DecodeDetectorLayers(mod,lay,lad,det);
+    geom->CreateMatrix(mod,lay,lad,det,kIdet[lay-1],tran,rot);
+    RecodeDetector(mod,cpn0,cpn1,cpn2);
+
+    if (kIdet[lay-1]==kSPD) { // we need 1 more copy number because of the half-stave
+      if (det<3) cpnHS = 0; else cpnHS = 1;
+      path.Form(kNames[lay-1].Data(),kPathbase.Data(),cpn0,cpn1,cpnHS,cpn2);
+    } else {
+      path.Form(kNames[lay-1].Data(),kPathbase.Data(),cpn0,cpn1,cpn2);
+    };
+
+    geom->GetGeomMatrix(mod)->SetPath(path);
+    GetTransformation(path.Data(),matrix);
+    geom->SetTrans(mod,matrix.GetTranslation());
+    TransposeTGeoHMatrix(&matrix); //Transpose TGeo's rotation matrixes
+    geom->SetRotMatrix(mod,matrix.GetRotationMatrix());
+    if(initSeg[kIdet[lay-1]]) continue;
+    GetShape(path,shapeName,shapePar);
+    if(shapeName.CompareTo("BOX")){
+      Error("InitITSgeom","Geometry changed without proper code update"
+           "or error in reading geometry. Shape is not BOX.");
+      return kFALSE;
+    } // end if
+  } // end for module
+
+  if(fTiming){
+    time->Stop();
+    time->Print();
+    delete time;
+  } // end if
+  return kTRUE;
+}
+//______________________________________________________________________
+Bool_t AliITSInitGeometryUpg::InitAliITSgeomVUpgrade(AliITSgeom *geom){
+  // Initilizes the geometry transformation class AliITSgeom
+  // Now that the segmentation is part of AliITSgeom, the detector
+  // segmentations are also defined here.
+  //
+  // Inputs:
+  //   AliITSgeom *geom  A pointer to the AliITSgeom class
+  // Outputs:
+  //   AliITSgeom *geom  This pointer recreated and properly inilized.
+  // LG
+
+  const Int_t kItype  = 0; // Type of transformation defined 0=> Geant
+  const Int_t klayers = GetNumberOfLayers(); // Number of layers in the ITS
+  const AliITSDetector kIdet = kUPG;
+  const TString kPathbase = "/ALIC_1/ITSV_2/"; // We have 2 to cheat AliGeoManager::CheckSymNamesLUT
+
+  if (klayers <= 0) {
+    AliError("No layers found in ITSV");
+    return kFALSE;
+  }
+
+  Int_t *kladders = new Int_t[klayers];      // Number of ladders
+  Int_t *kdetectors = new Int_t[klayers];    // Number of detectors/ladder
+
+  for (Int_t j=0; j<klayers; j++) {
+    kladders[j] = GetNumberOfLadders(j);
+    kdetectors[j] = GetNumberOfModules(j);
+  }
+
+  const char *pathsens;
+  pathsens="%sITSupgLayer%d_1/ITSupgLadder%d_%d/ITSupgModule%d_%d/ITSupgSensor%d_%d";
+
+  const TString kNames = pathsens;
+  
+  Int_t mod,nmods=0, lay, lad, det, cpn0, cpn1, cpn2;
+  Double_t tran[3]={0.,0.,0.}, rot[10]={9*0.0,1.0};
+  TArrayD shapePar;
+  TString path, shapeName;
+  TGeoHMatrix matrix;
+  Bool_t initSeg=kFALSE ;
+  TStopwatch *time = 0x0;
+  if(fTiming) time = new TStopwatch();
+
+  if(fTiming) time->Start();
+  for(mod=0;mod<klayers;mod++) nmods += kladders[mod]*kdetectors[mod];
+  geom->Init(kItype,klayers,kladders,kdetectors,nmods);
+
+  for(mod=0; mod<nmods; mod++) {
+
+    DecodeDetectorLayers(mod,lay,lad,det);
+    geom->CreateMatrix(mod,lay,lad,det,kIdet,tran,rot);
+    RecodeDetector(mod,cpn0,cpn1,cpn2);
+
+    path.Form(kNames.Data(),kPathbase.Data(),lay,lay,cpn0,lay,cpn1,lay,cpn2);
+
+    geom->GetGeomMatrix(mod)->SetPath(path);
+    GetTransformation(path.Data(),matrix);
+    geom->SetTrans(mod,matrix.GetTranslation());
+    TransposeTGeoHMatrix(&matrix); //Transpose TGeo's rotation matrixes
+    geom->SetRotMatrix(mod,matrix.GetRotationMatrix());
+//    if(initSeg[kIdet[lay-1]]) continue;
+    if(initSeg) continue;
+    GetShape(path,shapeName,shapePar);
+    if(shapeName.CompareTo("BOX")){
+      Error("InitITSgeom","Geometry changed without proper code update"
+           "or error in reading geometry. Shape is not BOX.");
+      return kFALSE;
+    } // end if
+  } // end for module
+
+  if(fTiming){
+    time->Stop();
+    time->Print();
+    delete time;
+  } // end if
+  return kTRUE;
+}
+
+//_______________________________________________________________________
+Bool_t AliITSInitGeometryUpg::GetTransformation(const TString &volumePath,
+                                            TGeoHMatrix &mat){
+    // Returns the Transformation matrix between the volume specified
+    // by the path volumePath and the Top or mater volume. The format
+    // of the path volumePath is as follows (assuming ALIC is the Top volume)
+    // "/ALIC_1/DDIP_1/S05I_2/S05H_1/S05G_3". Here ALIC is the top most
+    // or master volume which has only 1 instance of. Of all of the daughter
+    // volumes of ALICE, DDIP volume copy #1 is indicated. Similarly for
+    // the daughter volume of DDIP is S05I copy #2 and so on.
+    // Inputs:
+    //   TString& volumePath  The volume path to the specific volume
+    //                        for which you want the matrix. Volume name
+    //                        hierarchy is separated by "/" while the
+    //                        copy number is appended using a "_".
+    // Outputs:
+    //  TGeoHMatrix &mat      A matrix with its values set to those
+    //                        appropriate to the Local to Master transformation
+    // Return:
+    //   A logical value if kFALSE then an error occurred and no change to
+    //   mat was made.
+
+    // We have to preserve the modeler state
+
+    // Preserve the modeler state.
+    gGeoManager->PushPath();
+    if (!gGeoManager->cd(volumePath.Data())) {
+      gGeoManager->PopPath();
+      Error("GetTransformation","Error in cd-ing to %s",volumePath.Data());
+      return kFALSE;
+    } // end if !gGeoManager
+    mat = *gGeoManager->GetCurrentMatrix();
+    // Retstore the modeler state.
+    gGeoManager->PopPath();
+    return kTRUE;
+}
+//______________________________________________________________________
+Bool_t AliITSInitGeometryUpg::GetShape(const TString &volumePath,
+                                   TString &shapeType,TArrayD &par){
+    // Returns the shape and its parameters for the volume specified
+    // by volumeName.
+    // Inputs:
+    //   TString& volumeName  The volume name
+    // Outputs:
+    //   TString &shapeType   Shape type
+    //   TArrayD &par         A TArrayD of parameters with all of the
+    //                        parameters of the specified shape.
+    // Return:
+    //   A logical indicating whether there was an error in getting this
+    //   information
+    Int_t npar;
+    gGeoManager->PushPath();
+    if (!gGeoManager->cd(volumePath.Data())) {
+       gGeoManager->PopPath();
+       return kFALSE;
+    }
+    TGeoVolume * vol = gGeoManager->GetCurrentVolume();
+    gGeoManager->PopPath();
+    if (!vol) return kFALSE;
+    TGeoShape *shape = vol->GetShape();
+    TClass *classType = shape->IsA();
+    if (classType==TGeoBBox::Class()) {
+       shapeType = "BOX";
+       npar = 3;
+       par.Set(npar);
+       TGeoBBox *box = (TGeoBBox*)shape;
+       par.AddAt(box->GetDX(),0);
+       par.AddAt(box->GetDY(),1);
+       par.AddAt(box->GetDZ(),2);
+       return kTRUE;
+    } // end if
+    if (classType==TGeoTrd1::Class()) {
+       shapeType = "TRD1";
+       npar = 4;
+       par.Set(npar);
+       TGeoTrd1 *trd1 = (TGeoTrd1*)shape;
+       par.AddAt(trd1->GetDx1(),0);
+       par.AddAt(trd1->GetDx2(),1);
+       par.AddAt(trd1->GetDy(), 2);
+       par.AddAt(trd1->GetDz(), 3);
+       return kTRUE;
+    } // end if
+    if (classType==TGeoTrd2::Class()) {
+       shapeType = "TRD2";
+       npar = 5;
+       par.Set(npar);
+       TGeoTrd2 *trd2 = (TGeoTrd2*)shape;
+       par.AddAt(trd2->GetDx1(),0);
+       par.AddAt(trd2->GetDx2(),1);
+       par.AddAt(trd2->GetDy1(),2);
+       par.AddAt(trd2->GetDy2(),3);
+       par.AddAt(trd2->GetDz(), 4);
+       return kTRUE;
+    } // end if
+    if (classType==TGeoTrap::Class()) {
+       shapeType = "TRAP";
+       npar = 11;
+       par.Set(npar);
+       TGeoTrap *trap = (TGeoTrap*)shape;
+       Double_t tth = TMath::Tan(trap->GetTheta()*TMath::DegToRad());
+       par.AddAt(trap->GetDz(),0);
+       par.AddAt(tth*TMath::Cos(trap->GetPhi()*TMath::DegToRad()),1);
+       par.AddAt(tth*TMath::Sin(trap->GetPhi()*TMath::DegToRad()),2);
+       par.AddAt(trap->GetH1(),3);
+       par.AddAt(trap->GetBl1(),4);
+       par.AddAt(trap->GetTl1(),5);
+       par.AddAt(TMath::Tan(trap->GetAlpha1()*TMath::DegToRad()),6);
+       par.AddAt(trap->GetH2(),7);
+       par.AddAt(trap->GetBl2(),8);
+       par.AddAt(trap->GetTl2(),9);
+       par.AddAt(TMath::Tan(trap->GetAlpha2()*TMath::DegToRad()),10);
+       return kTRUE;
+    } // end if
+    if (classType==TGeoTube::Class()) {
+       shapeType = "TUBE";
+       npar = 3;
+       par.Set(npar);
+       TGeoTube *tube = (TGeoTube*)shape;
+       par.AddAt(tube->GetRmin(),0);
+       par.AddAt(tube->GetRmax(),1);
+       par.AddAt(tube->GetDz(),2);
+       return kTRUE;
+    } // end if
+    if (classType==TGeoTubeSeg::Class()) {
+       shapeType = "TUBS";
+       npar = 5;
+       par.Set(npar);
+       TGeoTubeSeg *tubs = (TGeoTubeSeg*)shape;
+       par.AddAt(tubs->GetRmin(),0);
+       par.AddAt(tubs->GetRmax(),1);
+       par.AddAt(tubs->GetDz(),2);
+       par.AddAt(tubs->GetPhi1(),3);
+       par.AddAt(tubs->GetPhi2(),4);
+       return kTRUE;
+    } // end if
+    if (classType==TGeoCone::Class()) {
+       shapeType = "CONE";
+       npar = 5;
+       par.Set(npar);
+       TGeoCone *cone = (TGeoCone*)shape;
+       par.AddAt(cone->GetDz(),0);
+       par.AddAt(cone->GetRmin1(),1);
+       par.AddAt(cone->GetRmax1(),2);
+       par.AddAt(cone->GetRmin2(),3);
+       par.AddAt(cone->GetRmax2(),4);
+       return kTRUE;
+    } // end if
+    if (classType==TGeoConeSeg::Class()) {
+       shapeType = "CONS";
+       npar = 7;
+       par.Set(npar);
+       TGeoConeSeg *cons = (TGeoConeSeg*)shape;
+       par.AddAt(cons->GetDz(),0);
+       par.AddAt(cons->GetRmin1(),1);
+       par.AddAt(cons->GetRmax1(),2);
+       par.AddAt(cons->GetRmin2(),3);
+       par.AddAt(cons->GetRmax2(),4);
+       par.AddAt(cons->GetPhi1(),5);
+       par.AddAt(cons->GetPhi2(),6);
+       return kTRUE;
+    } // end if
+    if (classType==TGeoSphere::Class()) {
+       shapeType = "SPHE";
+       npar = 6;
+       par.Set(npar);
+       
+       TGeoSphere *sphe = (TGeoSphere*)shape;
+       par.AddAt(sphe->GetRmin(),0);
+       par.AddAt(sphe->GetRmax(),1);
+       par.AddAt(sphe->GetTheta1(),2);
+       par.AddAt(sphe->GetTheta2(),3);
+       par.AddAt(sphe->GetPhi1(),4);
+       par.AddAt(sphe->GetPhi2(),5);
+       return kTRUE;
+    } // end if
+    if (classType==TGeoPara::Class()) {
+       shapeType = "PARA";
+       npar = 6;
+       par.Set(npar);
+       TGeoPara *para = (TGeoPara*)shape;
+       par.AddAt(para->GetX(),0);
+       par.AddAt(para->GetY(),1);
+       par.AddAt(para->GetZ(),2);
+       par.AddAt(para->GetTxy(),3);
+       par.AddAt(para->GetTxz(),4);
+       par.AddAt(para->GetTyz(),5);
+       return kTRUE;
+    } // end if
+    if (classType==TGeoPgon::Class()) {
+       shapeType = "PGON";
+       TGeoPgon *pgon = (TGeoPgon*)shape;
+       Int_t nz = pgon->GetNz();
+       const Double_t *rmin = pgon->GetRmin();
+       const Double_t *rmax = pgon->GetRmax();
+       const Double_t *z = pgon->GetZ();
+       npar = 4 + 3*nz;
+       par.Set(npar);
+       par.AddAt(pgon->GetPhi1(),0);
+       par.AddAt(pgon->GetDphi(),1);
+       par.AddAt(pgon->GetNedges(),2);
+       par.AddAt(pgon->GetNz(),3);
+       for (Int_t i=0; i<nz; i++) {
+           par.AddAt(z[i], 4+3*i);
+           par.AddAt(rmin[i], 4+3*i+1);
+           par.AddAt(rmax[i], 4+3*i+2);
+       }
+       return kTRUE;
+    } // end if
+    if (classType==TGeoPcon::Class()) {
+       shapeType = "PCON";
+       TGeoPcon *pcon = (TGeoPcon*)shape;
+       Int_t nz = pcon->GetNz();
+       const Double_t *rmin = pcon->GetRmin();
+       const Double_t *rmax = pcon->GetRmax();
+       const Double_t *z = pcon->GetZ();
+       npar = 3 + 3*nz;
+       par.Set(npar);
+       par.AddAt(pcon->GetPhi1(),0);
+       par.AddAt(pcon->GetDphi(),1);
+       par.AddAt(pcon->GetNz(),2);
+       for (Int_t i=0; i<nz; i++) {
+           par.AddAt(z[i], 3+3*i);
+           
+           par.AddAt(rmin[i], 3+3*i+1);
+           par.AddAt(rmax[i], 3+3*i+2);
+       }
+       return kTRUE;
+    } // end if
+    if (classType==TGeoEltu::Class()) {
+       shapeType = "ELTU";
+       npar = 3;
+       par.Set(npar);
+       TGeoEltu *eltu = (TGeoEltu*)shape;
+       par.AddAt(eltu->GetA(),0);
+       par.AddAt(eltu->GetB(),1);
+       par.AddAt(eltu->GetDz(),2);
+       return kTRUE;
+    } // end if
+    if (classType==TGeoHype::Class()) {
+       shapeType = "HYPE";
+       npar = 5;
+       par.Set(npar);
+       TGeoHype *hype = (TGeoHype*)shape;
+       par.AddAt(TMath::Sqrt(hype->RadiusHypeSq(0.,kTRUE)),0);
+       par.AddAt(TMath::Sqrt(hype->RadiusHypeSq(0.,kFALSE)),1);
+       par.AddAt(hype->GetDZ(),2);
+       par.AddAt(hype->GetStIn(),3);
+       par.AddAt(hype->GetStOut(),4);
+       return kTRUE;
+    } // end if
+    if (classType==TGeoGtra::Class()) {
+       shapeType = "GTRA";
+       npar = 12;
+       par.Set(npar);
+       TGeoGtra *trap = (TGeoGtra*)shape;
+       Double_t tth = TMath::Tan(trap->GetTheta()*TMath::DegToRad());
+       par.AddAt(trap->GetDz(),0);
+       par.AddAt(tth*TMath::Cos(trap->GetPhi()*TMath::DegToRad()),1);
+       par.AddAt(tth*TMath::Sin(trap->GetPhi()*TMath::DegToRad()),2);
+       par.AddAt(trap->GetH1(),3);
+       par.AddAt(trap->GetBl1(),4);
+       par.AddAt(trap->GetTl1(),5);
+       par.AddAt(TMath::Tan(trap->GetAlpha1()*TMath::DegToRad()),6);
+       par.AddAt(trap->GetH2(),7);
+       par.AddAt(trap->GetBl2(),8);
+       par.AddAt(trap->GetTl2(),9);
+       par.AddAt(TMath::Tan(trap->GetAlpha2()*TMath::DegToRad()),10);
+       par.AddAt(trap->GetTwistAngle(),11);
+       return kTRUE;
+    } // end if
+    if (classType==TGeoCtub::Class()) {
+       shapeType = "CTUB";
+       npar = 11;
+       par.Set(npar);
+       TGeoCtub *ctub = (TGeoCtub*)shape;
+       const Double_t *lx = ctub->GetNlow();
+       const Double_t *tx = ctub->GetNhigh();
+       par.AddAt(ctub->GetRmin(),0);
+       par.AddAt(ctub->GetRmax(),1);
+       par.AddAt(ctub->GetDz(),2);
+       par.AddAt(ctub->GetPhi1(),3);
+       par.AddAt(ctub->GetPhi2(),4);
+       par.AddAt(lx[0],5);
+       par.AddAt(lx[1],6);
+       par.AddAt(lx[2],7);
+       par.AddAt(tx[0],8);
+       par.AddAt(tx[1],9);
+       par.AddAt(tx[2],10);
+       return kTRUE;
+    } // end if
+    Error("GetShape","Getting shape parameters for shape %s not implemented",
+         shape->ClassName());
+    shapeType = "Unknown";
+    return kFALSE;
+}
+//______________________________________________________________________
+void AliITSInitGeometryUpg::DecodeDetector(
+    Int_t &mod,Int_t layer,Int_t cpn0,Int_t cpn1,Int_t cpn2) const {
+    // decode geometry into detector module number. There are two decoding
+    // Scheams. Old which does not follow the ALICE coordinate system
+    // requirements, and New which dose.
+    // Inputs:
+    //    Int_t layer    The ITS layer
+    //    Int_t cpn0     The lowest copy number
+    //    Int_t cpn1     The middle copy number
+    //    Int_t cpn2     the highest copy number
+    // Output:
+    //    Int_t &mod     The module number assoicated with this set
+    //                   of copy numbers.
+    // Return:
+    //    none.
+
+    // This is a FIXED switch yard function. I (Bjorn Nilsen) Don't 
+    // like them but I see not better way for the moment.
+    switch (fMajorVersion){
+    case kvDefault:{
+        Error("DecodeDetector","Major version = kvDefault, not supported");
+    }break;
+    case kv11:{
+        return DecodeDetectorv11(mod,layer,cpn0,cpn1,cpn2);
+    }break;
+    case kvUpgrade:{
+        return DecodeDetectorvUpgrade(mod,layer,cpn0,cpn1,cpn2);
+    }break;
+    default:{
+        Error("DecodeDetector","Major version = %d, not supported",
+              (Int_t)fMajorVersion);
+        return;
+    }break;
+    } // end switch
+    return;
+}
+//______________________________________________________________________
+void AliITSInitGeometryUpg::RecodeDetector(Int_t mod,Int_t &cpn0,
+                                        Int_t &cpn1,Int_t &cpn2){
+    // decode geometry into detector module number. There are two decoding
+    // Scheams. Old which does not follow the ALICE coordinate system
+    // requirements, and New which dose.
+    // Inputs:
+    //    Int_t mod      The module number assoicated with this set
+    //                   of copy numbers.
+    // Output:
+    //    Int_t cpn0     The lowest copy number
+    //    Int_t cpn1     The middle copy number
+    //    Int_t cpn2     the highest copy number
+    // Return:
+    //    none.
+
+    // This is a FIXED switch yard function. I (Bjorn Nilsen) Don't 
+    // like them but I see not better way for the moment.
+    switch (fMajorVersion){
+    case kvDefault:{
+        Error("RecodeDetector","Major version = kvDefault, not supported");
+        return;
+    }
+    case kv11:{
+        return RecodeDetectorv11(mod,cpn0,cpn1,cpn2);
+    }break;
+    case kvUpgrade:{
+        return RecodeDetectorvUpgrade(mod,cpn0,cpn1,cpn2);
+    }break;
+    default:{
+        Error("RecodeDetector","Major version = %d, not supported",
+              (Int_t)fMajorVersion);
+        return;
+    }break;
+    } // end switch
+    return;
+}
+//______________________________________________________________________
+void AliITSInitGeometryUpg::DecodeDetectorLayers(Int_t mod,Int_t &layer,
+                                              Int_t &lad,Int_t &det){
+    // decode geometry into detector module number. There are two decoding
+    // Scheams. Old which does not follow the ALICE coordinate system
+    // requirements, and New which dose. Note, this use of layer ladder
+    // and detector numbers are strictly for internal use of this
+    // specific code. They do not represent the "standard" layer ladder
+    // or detector numbering except in a very old and obsoleate sence.
+    // Inputs:
+    //    Int_t mod      The module number assoicated with this set
+    //                   of copy numbers.
+    // Output:
+    //    Int_t lay     The layer number
+    //    Int_t lad     The ladder number
+    //    Int_t det     the dettector number
+    // Return:
+    //    none.
+
+    // This is a FIXED switch yard function. I (Bjorn Nilsen) Don't 
+    // like them but I see not better way for the moment.
+    switch (fMajorVersion) {
+    case kvDefault:{
+        Error("DecodeDetectorLayers",
+              "Major version = kvDefault, not supported");
+        return;
+    }break;
+    case kv11:{
+        return DecodeDetectorLayersv11(mod,layer,lad,det);
+    }break;
+    case kvUpgrade:{
+        return DecodeDetectorLayersvUpgrade(mod,layer,lad,det);
+    }break;
+    default:{
+        Error("DecodeDetectorLayers","Major version = %d, not supported",
+              (Int_t)fMajorVersion);
+        return;
+    }break;
+    } // end switch
+    return;
+}
+
+//______________________________________________________________________
+void AliITSInitGeometryUpg::DecodeDetectorv11(Int_t &mod,Int_t layer,
+                                 Int_t cpn0,Int_t cpn1,Int_t cpn2) const {
+    // decode geometry into detector module number
+    // Inputs:
+    //    Int_t layer    The ITS layer
+    //    Int_t cpn0     The lowest copy number
+    //    Int_t cpn1     The middle copy number
+    //    Int_t cpn2     the highest copy number
+    // Output:
+    //    Int_t &mod     The module number assoicated with this set
+    //                   of copy numbers.
+    // Return:
+    //    none.
+  const Int_t kDetPerLadderSPD[2]={2,4};
+  const Int_t kDetPerLadder[6]={4,4,6,8,22,25};
+  const Int_t kLadPerLayer[6]={20,40,14,22,34,38};
+  Int_t lad=-1,det=-1;
+  
+  switch(layer) {
+  case 1: case 2:{
+    lad = cpn1+kDetPerLadderSPD[layer-1]*(cpn0-1);
+    det = cpn2;
+  } break;
+  case 3: case 4:{
+    lad = cpn0+1;
+    det = cpn1+1;
+  } break;
+  case 5: case 6:{
+    lad = cpn0+1;
+    det = cpn1+1;
+  } break;
+  default:{
+  } break;
+  } // end switch
+  mod = 0;
+  for(Int_t i=0;i<layer-1;i++) mod += kLadPerLayer[i]*kDetPerLadder[i];
+  mod += kDetPerLadder[layer-1]*(lad-1)+det-1;// module start at zero.
+  return;
+}
+
+//______________________________________________________________________
+void AliITSInitGeometryUpg::DecodeDetectorvUpgrade(Int_t &mod,Int_t layer,
+                                 Int_t cpn0,Int_t cpn1,Int_t cpn2) const {
+    // decode geometry into detector module number
+    // Inputs:
+    //    Int_t layer    The ITS layer
+    //    Int_t cpn0     The lowest copy number
+    //    Int_t cpn1     The middle copy number
+    //    Int_t cpn2     the highest copy number
+    // Output:
+    //    Int_t &mod     The module number assoicated with this set
+    //                   of copy numbers.
+    // Return:
+    //    none.
+    // MS 23jun11
+  Int_t lad=-1,det=-1;
+
+  lad = cpn0;
+  det = cpn1;
+  mod = 0;
+  for(Int_t i=0;i<layer;i++) mod += GetNumberOfLadders(i)*GetNumberOfModules(i);
+  mod += GetNumberOfModules(layer)*(lad-1)+det-1;// module start at zero.
+  return;
+}
+
+//______________________________________________________________________
+void AliITSInitGeometryUpg::RecodeDetectorv11(Int_t mod,Int_t &cpn0,
+                                          Int_t &cpn1,Int_t &cpn2) {
+    // decode geometry into detector module number using the new decoding
+    // Scheme.
+    // Inputs:
+    //    Int_t mod      The module number assoicated with this set
+    //                   of copy numbers.
+    // Output:
+    //    Int_t cpn0     The lowest copy number  (SPD sector or SDD/SSD ladder)
+    //    Int_t cpn1     The middle copy number  (SPD stave or SDD/SSD module)
+    //    Int_t cpn2     the highest copy number (SPD ladder or 1 for SDD/SSD)
+    // Return:
+    //    none.
+    const Int_t kDetPerLadderSPD[2]={2,4};
+    Int_t lay,lad,det;
+
+    DecodeDetectorLayersv11(mod,lay,lad,det);
+    if (lay<3) { // SPD
+        cpn2 = det;     // Detector 1-4
+        cpn0 = (lad+kDetPerLadderSPD[lay-1]-1)/kDetPerLadderSPD[lay-1];
+        cpn1 = (lad+kDetPerLadderSPD[lay-1]-1)%kDetPerLadderSPD[lay-1] + 1;
+    } else { // SDD and SSD
+        cpn2 = 1;
+        cpn1 = det;
+        cpn0 = lad;
+        if (lay<5) { // SDD
+         cpn1--;
+         cpn0--;
+        } else { //SSD
+         cpn1--;
+         cpn0--;
+        } // end if Lay<5/else
+    } // end if lay<3/else
+    /*printf("AliITSInitGeometryUpg::RecodeDetectorv11:"
+           "mod=%d lay=%d lad=%d det=%d cpn0=%d cpn1=%d cpn2=%d\n",
+           mod,lay,lad,det,cpn0,cpn1,cpn2);*/
+}
+
+//______________________________________________________________________
+void AliITSInitGeometryUpg::RecodeDetectorvUpgrade(Int_t mod,Int_t &cpn0,
+                                               Int_t &cpn1,Int_t &cpn2) {
+    // decode geometry into detector module number using the new decoding
+    // Scheme.
+    // Inputs:
+    //    Int_t mod      The module number assoicated with this set
+    //                   of copy numbers.
+    // Output:
+    //    Int_t cpn0     The lowest copy number  (ladder)
+    //    Int_t cpn1     The middle copy number  (module)
+    //    Int_t cpn2     the highest copy number (sensor - always 1 for now)
+    // Return:
+    //    none.
+    // MS - 23jun11 - cross your fingers and hope for the best
+    Int_t lay,lad,det;
+
+    DecodeDetectorLayersvUpgrade(mod,lay,lad,det);
+    cpn2 = 1;
+    cpn1 = det;
+    cpn0 = lad;
+//    cpn1--;
+//    cpn0--;
+    /*printf("AliITSInitGeometryUpg::RecodeDetectorv11:"
+           "mod=%d lay=%d lad=%d det=%d cpn0=%d cpn1=%d cpn2=%d\n",
+           mod,lay,lad,det,cpn0,cpn1,cpn2);*/
+}
+
+//______________________________________________________________________
+void AliITSInitGeometryUpg::DecodeDetectorLayersv11(Int_t mod,Int_t &lay,
+                                                Int_t &lad,Int_t &det) {
+
+  // decode module number into detector indices for v11
+  // mod starts from 0
+  // lay, lad, det start from 1
+
+  // Inputs:
+  //    Int_t mod      The module number associated with this set
+  //                   of copy numbers.
+  // Output:
+  //    Int_t lay     The layer number
+  //    Int_t lad     The ladder number
+  //    Int_t det     the dettector number
+
+  const Int_t kDetPerLadder[6] = {4,4,6,8,22,25};
+  const Int_t kLadPerLayer[6]  = {20,40,14,22,34,38};
+  
+  Int_t mod2 = 0;
+  lay  = 0;
+  
+  do {
+    mod2 += kLadPerLayer[lay]*kDetPerLadder[lay];
+    lay++;
+  } while(mod2<=mod); // end while
+  if(lay>6) Error("DecodeDetectorLayers","lay=%d>6",lay);
+
+  mod2 = kLadPerLayer[lay-1]*kDetPerLadder[lay-1] - mod2+mod;
+  lad = mod2/kDetPerLadder[lay-1];
+
+  if(lad>=kLadPerLayer[lay-1]||lad<0) Error("DecodeDetectorLayers",
+                                     "lad=%d not in the correct range",lad);
+  det = (mod2 - lad*kDetPerLadder[lay-1])+1;
+  if(det>kDetPerLadder[lay-1]||det<1) Error("DecodeDetectorLayers",
+                                     "det=%d not in the correct range",det);
+  lad++;
+}
+
+//______________________________________________________________________
+void AliITSInitGeometryUpg::DecodeDetectorLayersvUpgrade(Int_t  mod,Int_t &lay,
+                                                     Int_t &lad,Int_t &det){
+
+  // decode module number into detector indices for vUpgrade
+  // mod starts from 0
+  // lay, lad, det start from 1
+
+  // Inputs:
+  //    Int_t mod      The module number associated with this set
+  //                   of copy numbers.
+  // Output:
+  //    Int_t lay     The layer number
+  //    Int_t lad     The ladder number
+  //    Int_t det     the dettector number
+  // MS - 22jun11
+
+  const Int_t kLayers = GetNumberOfLayers();
+  
+  Int_t mod2 = 0;
+  lay  = 0;
+  
+  do {
+    mod2 += GetNumberOfLadders(lay)*GetNumberOfModules(lay);
+    lay++;
+  } while(mod2<=mod); // end while
+  if(lay>kLayers) Error("DecodeDetectorLayers","lay=%d>%d",lay,kLayers);
+
+  mod2 = GetNumberOfLadders(lay-1)*GetNumberOfModules(lay-1) - mod2+mod;
+  lad = mod2/GetNumberOfModules(lay-1);
+
+  if(lad>=GetNumberOfLadders(lay-1)||lad<0) Error("DecodeDetectorLayers",
+                                     "lad=%d not in the correct range",lad);
+  det = (mod2 - lad*GetNumberOfModules(lay-1))+1;
+  if(det>GetNumberOfModules(lay-1)||det<1) Error("DecodeDetectorLayers",
+
+                                     "det=%d not in the correct range",det);
+  lay--;
+  lad++;
+}
+
+//______________________________________________________________________
+Bool_t AliITSInitGeometryUpg::WriteVersionString(Char_t *str,Int_t length,
+                        AliITSVersion_t maj,Int_t min,
+                        const Char_t *cvsDate,const Char_t *cvsRevision)const{
+    // fills the string str with the major and minor version number
+    // Inputs:
+    //   Char_t *str          The character string to hold the major 
+    //                        and minor version numbers in
+    //   Int_t  length        The maximum number of characters which 
+    //                        can be accomidated by this string. 
+    //                        str[length-1] must exist and will be set to zero
+    //   AliITSVersion_t maj  The major number
+    //   Int_t           min  The minor number
+    //   Char_t *cvsDate      The date string from cvs
+    //   Char_t *cvsRevision  The Revision string from cvs
+    // Outputs:
+    //   Char_t *str          The character string holding the major and minor
+    //                        version numbers. str[length-1] must exist
+    //                        and will be set to zero
+    // Return:
+    //   kTRUE if no errors
+    Char_t cvslikedate[30];
+    Int_t i,n,cvsDateLength,cvsRevisionLength;
+
+    cvsDateLength = (Int_t)strlen(cvsDate);
+    if(cvsDateLength>30){ // svn string, make a cvs like string
+        i=0;n=0;
+        do{
+            cvslikedate[i] = cvsDate[i];
+            if(cvsDate[i]=='+' || cvsDate[i++]=='-'){
+                n++; // count number of -
+                cvslikedate[i-1] = '/'; // replace -'s by /'s.
+            } // end if
+        } while(n<3&&i<30); // once additonal - of time zone reach exit
+        cvslikedate[i-1] = '$'; // put $ at end then zero.
+        for(;i<30;i++) cvslikedate[i]=0;// i starts wher do loop left off.
+    }else{
+        for(i=0;i<cvsDateLength&&i<30;i++) cvslikedate[i]=cvsDate[i];
+    }// end if
+    cvsDateLength = (Int_t)strlen(cvslikedate);
+    cvsRevisionLength = (Int_t)strlen(cvsRevision);
+    i = (Int_t)maj;
+    n = 50+(Int_t)(TMath::Log10(TMath::Abs((Double_t)i)))+1+
+        (Int_t)(TMath::Log10(TMath::Abs((Double_t)min)))+1
+        +cvsDateLength-6+cvsRevisionLength-10;
+    if(GetDebug()>1) printf("AliITSInitGeometryUpg::WriteVersionString:"
+                        "length=%d major=%d minor=%d cvsDate=%s[%d] "
+                        "cvsRevision=%s[%d] n=%d\n",length,i,min,cvslikedate,
+                        cvsDateLength,cvsRevision,cvsRevisionLength,n);
+    if(i<0) n++;
+    if(min<0) n++;
+    if(length<n){// not enough space to write in output string.
+        Warning("WriteVersionString","Output string not long enough "
+                "lenght=%d must be at least %d long\n",length,n);
+        return kFALSE;
+    } // end if length<n
+    char *cvsrevision = new char[cvsRevisionLength-10];
+    char *cvsdate = new char[cvsDateLength-6];
+    for(i=0;i<cvsRevisionLength-10;i++)
+        if(10+i<cvsRevisionLength-1)
+            cvsrevision[i] = cvsRevision[10+i]; else cvsrevision[i] = 0;
+    for(i=0;i<cvsDateLength-6;i++) if(6+i<cvsDateLength-1)
+        cvsdate[i] = cvslikedate[6+i]; else cvsdate[i] = 0;
+    for(i=0;i<length;i++) str[i] = 0; // zero it out for now.
+    i = (Int_t)maj;
+    snprintf(str,length-1,"Major Version= %d Minor Version= %d Revision: %s Date: %s",i,min,cvsrevision,cvsdate);
+    /* this gives compilation warnings on some compilers: descriptor zu
+    if(GetDebug()>1)printf("AliITSInitGeometryUpg::WriteVersionString: "
+                       "n=%d str=%s revision[%zu] date[%zu]\n",
+                       n,str,strlen(cvsrevision),strlen(cvsdate));
+    */
+    delete[] cvsrevision;
+    delete[] cvsdate;
+    return kTRUE;
+}
+//______________________________________________________________________
+Bool_t AliITSInitGeometryUpg::ReadVersionString(const Char_t *str,Int_t length,
+                                             AliITSVersion_t &maj,Int_t &min,
+                                             TDatime &dt)const{
+    // fills the string str with the major and minor version number
+    // Inputs:
+    //   Char_t *str   The character string to holding the major and minor
+    //                 version numbers in
+    //   Int_t  length The maximum number of characters which can be
+    //                 accomidated by this string. str[length-1] must exist
+    // Outputs:
+    //   Char_t *str   The character string holding the major and minor
+    //                 version numbers unchanged. str[length-1] must exist.
+    //   AliITSVersion_t maj  The major number
+    //   Int_t           min  The minor number
+    //   TDatime         dt   The date and time of the cvs commit
+    // Return:
+    //   kTRUE if no errors
+    Bool_t ok;
+    Char_t cvsRevision[10],cvsDate[11],cvsTime[9];
+    Int_t i,m,n=strlen(str),year,month,day,hours,minuits,seconds;
+    memset(cvsRevision,0,10*sizeof(Char_t));
+    memset(cvsDate,0,11*sizeof(Char_t));    
+    memset(cvsTime,0,9*sizeof(Char_t));
+
+    if(GetDebug()>1)printf("AliITSInitGeometryUpg::ReadVersionString:"
+                       "str=%s length=%d\n",
+                       str,length);
+    if(n<35) return kFALSE; // not enough space for numbers
+    m = sscanf(str,"Major Version= %d  Minor Version= %d Revision: %9s "
+               "Date: %10s %8s",&i,&min,cvsRevision,cvsDate,cvsTime);
+    ok = m==5;
+    if(!ok) return !ok;
+    m = sscanf(cvsDate,"%d/%d/%d",&year,&month,&day);
+    ok = m==3;
+    if(!ok) return !ok;
+    m = sscanf(cvsTime,"%d:%d:%d",&hours,&minuits,&seconds);
+    ok = m==3;
+    if(!ok) return !ok;
+    dt.Set(year,month,day,hours,minuits,seconds);
+    if(GetDebug()>1)printf("AliITSInitGeometryUpg::ReadVersionString: i=%d "
+                     "min=%d cvsRevision=%s cvsDate=%s cvsTime=%s m=%d\n",
+                       i,min,cvsRevision,cvsDate,cvsTime,m);
+    if(GetDebug()>1)printf("AliITSInitGeometryUpg::ReadVersionString: year=%d"
+                       " month=%d day=%d hours=%d minuits=%d seconds=%d\n",
+                       year,month,day,hours,minuits,seconds);
+    switch (i){
+    case kv11:{
+        maj = kv11;
+    } break;
+    case kvUpgrade:{
+        maj = kvUpgrade;
+    } break;
+    default:{
+        maj = kvDefault;
+    } break;
+    } // end switch
+    return ok;
+}
+//______________________________________________________________________
+Int_t AliITSInitGeometryUpg::GetNumberOfLayers(){
+  // Determines the number of layers in the Upgrade Geometry
+  //
+  // Inputs:
+  //   none
+  // Outputs:
+  //   none
+  // Return:
+  //   the number of layers in the current geometry
+  //   -1 if not Upgrade Geometry
+  // MS
+
+    Int_t numberOfLayers = 0;
+
+    if (fMajorVersion != kvUpgrade) {
+      AliError("Not Upgrade Geometry!");
+      return -1;
+    }
+
+    // This checks should be redundant, but let's do things neatly
+    if (!gGeoManager) {
+      AliError("gGeoManager is null");
+      return 0;
+    }
+
+    if (!gGeoManager->GetVolume("ITSV")) {
+      AliError("can't find ITSV volume");
+      return 0;
+    }
+
+    // Loop on all ITSV nodes, count Layer volumes by checking names
+    Int_t nNodes = gGeoManager->GetVolume("ITSV")->GetNodes()->GetEntries();
+
+    if (nNodes == 0)
+      return 0;
+
+    for (Int_t j=0; j<nNodes; j++)
+      if (strstr(gGeoManager->GetVolume("ITSV")->GetNodes()->At(j)->GetName(),
+                "ITSupgLayer"))
+       numberOfLayers++;
+
+
+    return numberOfLayers;
+}
+//______________________________________________________________________
+Int_t AliITSInitGeometryUpg::GetNumberOfLadders(const Int_t lay) const {
+  // Determines the number of layers in the Upgrade Geometry
+  //
+  // Inputs:
+  //   lay: layer number
+  // Outputs:
+  //   none
+  // Return:
+  //   the number of ladders in layer lay
+  //   -1 if not Upgrade Geometry
+  // MS
+
+    Int_t numberOfLadders = 0;
+
+    if (fMajorVersion != kvUpgrade) {
+      AliError("Not Upgrade Geometry!");
+      return -1;
+    }
+
+    // This checks should be redundant, but let's do things neatly
+    if (!gGeoManager) {
+      AliError("gGeoManager is null");
+      return 0;
+    }
+
+    char laynam[15];
+    snprintf(laynam, 15, "ITSupgLayer%d", lay);
+    if (!gGeoManager->GetVolume(laynam)) {
+      AliError(Form("can't find %s volume",laynam));
+      return 0;
+    }
+
+    // Loop on all layer nodes, count Ladder volumes by checking names
+    Int_t nNodes = gGeoManager->GetVolume(laynam)->GetNodes()->GetEntries();
+
+    if (nNodes == 0)
+      return 0;
+
+    for (Int_t j=0; j<nNodes; j++)
+      if (strstr(gGeoManager->GetVolume(laynam)->GetNodes()->At(j)->GetName(),
+                "ITSupgLadder"))
+       numberOfLadders++;
+
+
+    return numberOfLadders;
+}
+//______________________________________________________________________
+Int_t AliITSInitGeometryUpg::GetNumberOfModules(const Int_t lay) const {
+  // Determines the number of layers in the Upgrade Geometry
+  //
+  // Inputs:
+  //   lay: layer number
+  // Outputs:
+  //   none
+  // Return:
+  //   the number of modules per ladder in layer lay
+  //   -1 if not Upgrade Geometry
+  // MS
+
+    Int_t numberOfModules = 0;
+
+    if (fMajorVersion != kvUpgrade) {
+      AliError("Not Upgrade Geometry!");
+      return -1;
+    }
+
+    // This checks should be redundant, but let's do things neatly
+    if (!gGeoManager) {
+      AliError("gGeoManager is null");
+      return 0;
+    }
+
+    char laddnam[15];
+    snprintf(laddnam, 15, "ITSupgLadder%d", lay);
+    if (!gGeoManager->GetVolume(laddnam)) {
+      AliError(Form("can't find %s volume",laddnam));
+      return 0;
+    }
+
+    // Loop on all ladder nodes, count Module volumes by checking names
+    Int_t nNodes = gGeoManager->GetVolume(laddnam)->GetNodes()->GetEntries();
+
+    if (nNodes == 0)
+      return 0;
+
+    for (Int_t j=0; j<nNodes; j++)
+      if (strstr(gGeoManager->GetVolume(laddnam)->GetNodes()->At(j)->GetName(),
+                "ITSupgModule"))
+       numberOfModules++;
+
+
+    return numberOfModules;
+}
diff --git a/ITS/UPGRADE/AliITSInitGeometryUpg.h b/ITS/UPGRADE/AliITSInitGeometryUpg.h
new file mode 100644 (file)
index 0000000..8b50c95
--- /dev/null
@@ -0,0 +1,118 @@
+#ifndef ALIITSINITGEOMETRYUPG_H
+#define ALIITSINITGEOMETRYUPG_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/*
+$Id: AliITSInitGeometryUpg.h $
+*/
+
+/////////////////////////////////////////////////////////////////////
+// Class to inilize AliITSgeom and the like for both simulation
+//  and reconstruction.
+/////////////////////////////////////////////////////////////////////
+
+#include <TObject.h>
+#include <TString.h>
+#include "AliITSgeom.h"
+
+typedef enum {
+  kvDefault=0,kv11=11,kvUpgrade=20
+} AliITSVersion_t;
+
+class TArrayD;
+class TGeoHMatrix;
+class TDatime;
+
+class AliITSInitGeometryUpg : public TObject{
+ public:
+
+    AliITSInitGeometryUpg();//Default Constructor
+    AliITSInitGeometryUpg(AliITSVersion_t version,
+                      Int_t minorversion=2);//Standard Constructor
+    //virtual ~AliITSInitGeometryUpg(); // Destructor
+    //
+    // Create and initialize geometry from TGeo
+    AliITSgeom* CreateAliITSgeom();
+    AliITSgeom* CreateAliITSgeom(Int_t major,Int_t minor); 
+    Bool_t InitAliITSgeom(AliITSgeom *geom);//Initilize geometry from gGeoManager
+    // Getters and Setters
+    // Getters and Setters
+    void    SetVersion(AliITSVersion_t maj,Int_t min) {// Set Major and Minor versions
+        fMajorVersion=maj;fMinorVersion=min;}
+    TString GetGeometryName()const {return fName;}// Return geometry name
+    void    SetGeometryName(const Char_t *name){fName = name;}// Set Geometry name
+    Int_t   GetMajorVersion()const {return (Int_t)fMajorVersion;} // Return geometry major version
+    Int_t   GetMinorVersion()const{return fMinorVersion;}// Return geometry minor version
+    Bool_t  GetTiming()const{return fTiming;} // return routine timing flag
+    void    SetTiming(Bool_t time=kTRUE){fTiming=time;}// Set routine timing (on)
+    Bool_t  GetSegGeom()const{return fSegGeom;} // return flag indecating the use of AliITSsegmentation or AliITSgeomS?D class in fShape.
+    void    SetSegGeom(Bool_t seg=kTRUE){fSegGeom = seg;}// Set the use of AliITSsegmentation class' instead of AliITSgeomS?D class in fShape
+    Bool_t  GetDecoding()const{return fDecode;}// Return flag indecating wether to use new/old decoding
+    void    SetDecoding(Bool_t newdec=kFALSE){fDecode = newdec;}// Set flag to use new/old decoding
+     // Set debug level. debug=0 no debug info outputted.
+    void    SetDebug(Int_t debug=0){fDebug=debug;};
+    // Retrun debug value
+    Int_t   GetDebug()const{return fDebug;};
+    // Decode module number into old layer, ladder, and detector numbers
+    void DecodeDetectorLayers(Int_t mod,Int_t &lay,Int_t &lad,Int_t &det);
+    // find module number by layer, and copy numbers
+    void DecodeDetector(Int_t &mod,Int_t lay,Int_t cpn0,
+                        Int_t cpn1,Int_t cpn2) const;
+    // Given module number, find copy numbers.
+    void RecodeDetector(Int_t mod,Int_t &cpn0,Int_t &cpn1,Int_t &cpn2);
+   // fills the string str with the major and minor version number
+    Bool_t WriteVersionString(Char_t *str,Int_t length,
+                              AliITSVersion_t maj,Int_t min,
+                              const Char_t *cvsDate,const Char_t *cvsRev)const;
+    // decodes the string str with the major and minor version number
+    Bool_t ReadVersionString(const Char_t *str,Int_t length,
+                             AliITSVersion_t &maj,Int_t &min,TDatime &dt)const;
+
+    Int_t GetNumberOfLayers();
+    Int_t GetNumberOfLadders(const Int_t lay)const;
+    Int_t GetNumberOfModules(const Int_t lay)const;
+
+ private:
+    // Decode module number into old layer, ladder, and detector numbers
+    void DecodeDetectorLayersv11(Int_t mod,Int_t &lay,
+                                Int_t &lad,Int_t &det);
+    // find module number by layer, and copy numbers
+    void DecodeDetectorv11(Int_t &mod,Int_t lay,Int_t cpn0,Int_t cpn1,
+                          Int_t cpn2)const;
+    // Given module number, find copy numbers.
+    void RecodeDetectorv11(Int_t mod,Int_t &cpn0,Int_t &cpn1,
+                          Int_t &cpn2);
+    // Decode module number into old layer, ladder, and detector numbers
+    void DecodeDetectorvUpgrade(Int_t &mod,Int_t lay,Int_t cpn0,Int_t cpn1,
+                                    Int_t cpn2)const;
+    // find module number by layer, and copy numbers
+    void RecodeDetectorvUpgrade(Int_t mod,Int_t &cpn0,Int_t &cpn1,
+                                    Int_t &cpn2);
+    // Given module number, find copy numbers.
+    void DecodeDetectorLayersvUpgrade(Int_t mod,Int_t &lay,Int_t &lad,
+                                    Int_t &det);
+                  
+    // Virtual MC code 
+    Bool_t InitAliITSgeomV11(AliITSgeom *geom);
+    Bool_t InitAliITSgeomVUpgrade(AliITSgeom *geom);
+    Bool_t GetTransformation(const TString &volumePath,TGeoHMatrix &mat);
+    Bool_t GetShape(const TString &volumePath,TString &shapeType,TArrayD &par);
+    void TransposeTGeoHMatrix(TGeoHMatrix *m) const;
+
+    TString         fName;         // Geometry name
+    Int_t           fMinorVersion; // Geometry minor version
+    AliITSVersion_t fMajorVersion; // Geometry swich value
+    Bool_t          fTiming;       // Flag to start inilization timing
+    Bool_t          fSegGeom;      // Flag to switch between the old use of
+                                   // AliITSgeomS?D class, or AliITSsegmentation
+                                   // class in fShape of AliITSgeom class.
+    Bool_t          fDecode;       // Flag for new/old decoding
+    Int_t           fDebug;        // Debug flag
+
+    ClassDef(AliITSInitGeometryUpg,0) // create/Init AliITSgeom
+    // 0 in ClassDef indicates that this class will not be "saved" in a file.
+};
+
+#endif
+
diff --git a/ITS/UPGRADE/AliITSLoaderUpg.cxx b/ITS/UPGRADE/AliITSLoaderUpg.cxx
new file mode 100644 (file)
index 0000000..496a478
--- /dev/null
@@ -0,0 +1,360 @@
+/**************************************************************************
+ * 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: AliITSLoaderUpg.cxx $ */
+
+#include <TClonesArray.h>
+#include <TClass.h>
+#include <TGeoManager.h>
+#include <TTree.h>
+
+#include "AliITSdigit.h"
+#include "AliITSLoaderUpg.h"
+#include "AliRunLoader.h"
+#include "AliObjectLoader.h"
+#include "AliITSInitGeometryUpg.h"
+#include "AliLog.h"
+
+///////////////////////////////////////////////////////////////////////////
+// Loader for ITS Upgrade
+// it manages the I/O for:
+// raw clusters, primary vertices
+// V0 and cascade
+// and tracks propagated to the origin
+//////////////////////////////////////////////////////////////////////////
+const TString AliITSLoaderUpg::fgkDefaultRawClustersContainerName = "TreeC";
+const TString AliITSLoaderUpg::fgkDefaultBackTracksContainerName = "TreeB";
+const TString AliITSLoaderUpg::fgkDefaultVerticesContainerName = "Vertex";
+const TString AliITSLoaderUpg::fgkDefaultV0ContainerName = "V0";
+const TString AliITSLoaderUpg::fgkDefaultCascadeContainerName = "Cascade";
+ClassImp(AliITSLoaderUpg)
+
+/**********************************************************************/
+  AliITSLoaderUpg::AliITSLoaderUpg():AliLoader(),
+fGeom(0){
+  // Default constructor
+}
+/*********************************************************************/
+AliITSLoaderUpg::AliITSLoaderUpg(const Char_t *name,const Char_t *topfoldername):
+AliLoader(name,topfoldername),
+fGeom(0){
+  //Constructor   
+    AliDataLoader* rawClustersDataLoader = new AliDataLoader(
+        fDetectorName + ".RawCl.root",fgkDefaultRawClustersContainerName,
+        "Raw Clusters");
+    fDataLoaders->Add(rawClustersDataLoader);
+    rawClustersDataLoader->SetEventFolder(fEventFolder);
+    rawClustersDataLoader->SetFolder(GetDetectorDataFolder());
+
+    AliDataLoader* backTracksDataLoader =  new AliDataLoader(
+        fDetectorName + ".BackTracks.root",fgkDefaultBackTracksContainerName,
+        "Back Propagated Tracks");
+    fDataLoaders->Add(backTracksDataLoader);
+    backTracksDataLoader->SetEventFolder(fEventFolder);
+    backTracksDataLoader->SetFolder(GetDetectorDataFolder());
+
+    AliDataLoader* vertexDataLoader = new AliDataLoader(
+        fDetectorName + ".Vertex.root",fgkDefaultVerticesContainerName,
+        "Primary Vertices","O");
+    fDataLoaders->Add(vertexDataLoader);
+    vertexDataLoader->SetEventFolder(fEventFolder);
+    vertexDataLoader->SetFolder(GetDetectorDataFolder());
+
+    AliDataLoader* v0DataLoader = new AliDataLoader(
+        fDetectorName + ".V0s.root",fgkDefaultV0ContainerName,"V0 Vertices");
+    fDataLoaders->Add(v0DataLoader);
+    v0DataLoader->SetEventFolder(fEventFolder);
+    v0DataLoader->SetFolder(GetDetectorDataFolder());
+
+    AliDataLoader* cascadeDataLoader = new AliDataLoader(
+        fDetectorName + ".Cascades.root",fgkDefaultCascadeContainerName,
+        "Cascades");
+    fDataLoaders->Add(cascadeDataLoader);
+    cascadeDataLoader->SetEventFolder(fEventFolder);
+    cascadeDataLoader->SetFolder(GetDetectorDataFolder());
+}
+/**********************************************************************/
+AliITSLoaderUpg::AliITSLoaderUpg(const Char_t *name,TFolder *topfolder): 
+  AliLoader(name,topfolder),
+fGeom(0){
+  //ctor  
+    AliDataLoader*  rawClustersDataLoader = new AliDataLoader(
+        fDetectorName + ".RawCl.root",fgkDefaultRawClustersContainerName,
+        "Raw Clusters"); 
+    fDataLoaders->Add(rawClustersDataLoader);
+    rawClustersDataLoader->SetEventFolder(fEventFolder);
+    rawClustersDataLoader->SetFolder(GetDetectorDataFolder());
+
+    AliDataLoader*  backTracksDataLoader =  new AliDataLoader(
+        fDetectorName + ".BackTracks.root",fgkDefaultBackTracksContainerName,
+        "Back Propagated Tracks");
+    fDataLoaders->Add(backTracksDataLoader);
+    backTracksDataLoader->SetEventFolder(fEventFolder);
+    backTracksDataLoader->SetFolder(GetDetectorDataFolder());
+
+    AliDataLoader* vertexDataLoader = new AliDataLoader(
+        fDetectorName + ".Vertex.root",fgkDefaultVerticesContainerName,
+        "Primary Vertices","O");
+    fDataLoaders->Add(vertexDataLoader);
+    vertexDataLoader->SetEventFolder(fEventFolder);
+    vertexDataLoader->SetFolder(GetDetectorDataFolder());
+
+    AliDataLoader* v0DataLoader = new AliDataLoader(
+        fDetectorName + ".V0.root",fgkDefaultV0ContainerName,"V0 Vertices");
+    fDataLoaders->Add(v0DataLoader);
+    v0DataLoader->SetEventFolder(fEventFolder);
+    v0DataLoader->SetFolder(GetDetectorDataFolder());
+
+    AliDataLoader* cascadeDataLoader = new AliDataLoader(
+        fDetectorName + ".Cascade.root",fgkDefaultCascadeContainerName,
+        "Cascades");
+    fDataLoaders->Add(cascadeDataLoader);
+    cascadeDataLoader->SetEventFolder(fEventFolder);
+    cascadeDataLoader->SetFolder(GetDetectorDataFolder());
+}
+
+
+/**********************************************************************/
+AliITSLoaderUpg::~AliITSLoaderUpg(){
+    //destructor
+    AliDataLoader* dl = 0;
+    UnloadRawClusters();
+    dl = GetRawClLoader();
+    fDataLoaders->Remove(dl);
+
+    UnloadBackTracks();
+    dl = GetBackTracksDataLoader();
+    fDataLoaders->Remove(dl);
+
+    UnloadVertices();
+    dl = GetVertexDataLoader();
+    fDataLoaders->Remove(dl);
+
+    UnloadV0s();
+    dl = GetV0DataLoader();
+    fDataLoaders->Remove(dl);
+
+    UnloadCascades();
+    dl = GetCascadeDataLoader();
+    fDataLoaders->Remove(dl);
+  
+    if(fGeom)delete fGeom;
+    fGeom = 0;
+}
+/*
+//----------------------------------------------------------------------
+AliITS* AliITSLoaderUpg::GetITS(){
+    // Returns the pointer to the ITS, kept on the file. A short cut metthod
+    // Inputs:
+    //    none.
+    // Outputs:
+    //    none.
+    // Returns:
+    //    Returns a pointer to the ITS, if not found returns 0.
+    AliITS *its;
+
+    if(gAlice){
+        its = dynamic_cast<AliITS*> (gAlice->GetDetector(
+            GetDetectorName().Data()));
+        if(its) return its;
+    } // end if gAlice
+    AliRunLoader *rl=0;
+    rl = GetRunLoader();
+    if(!rl) return 0;
+    AliRun *ar=0;
+    ar = rl->GetAliRun();
+    if(!ar) return 0;
+    its = dynamic_cast<AliITS*> (ar->GetDetector(GetDetectorName().Data()));
+    return its;
+}
+//----------------------------------------------------------------------
+void AliITSLoaderUpg::SetupDigits(AliITS *its){
+    // Sets up to store ITS Digits in side AliITS::fDtype TObjArray
+    // Inputs:
+    //    AliITS *its  Pointer to the ITS
+    // Outputs:
+    //    none.
+    // Return:
+    //    none.
+
+    its->SetTreeAddressD(TreeD());
+}
+*/
+//----------------------------------------------------------------------
+void AliITSLoaderUpg::SetupDigits(TObjArray *digPerDet,Int_t n,
+                                 const Char_t **digclass){
+    // Sets up digPerDet to store ITS Digits.
+    // Inputs:
+    //    TObjArray *digPerDet   A pointer to a TObject Array size>=3.
+    //    Int_t      n           The size of the TObjArray and digclass array
+    //    Char_t     **digclass  Array of digit class names
+    // Outputs:
+    //    TObjArray *digPerDet   Setup and linked to the tree of digits
+    // Return:
+    //    none.
+    Int_t i,m;
+    TClonesArray *cl = 0;
+    TTree *td = 0;
+    TBranch *br = 0;
+    Char_t branch[14];
+    const Char_t *det[3] = {"SPD","SDD","SSD"};
+
+    if(!digPerDet){
+        Error("SetUpDigits","TObject Array digPerDet does not exist");
+        return;
+    } // end if
+    m = digPerDet->GetSize();
+    if(m<n){
+        Error("SetUpDigits","TObject Array digPerDet=%p must have a size"
+              " at least that of n=%d",digPerDet,n);
+    } // end if
+    if(m<3){
+        Error("SetUpDigits","TObject Array digPerDet=%p must have a size >2",
+              digPerDet);
+        return;
+    } // end if
+    td = TreeD();
+    for(i=0;i<n;i++){
+        if(digPerDet->At(i)==0){ // set up TClones Array
+            digPerDet->AddAt(new TClonesArray(digclass[i],1000),i);
+            if(n==3) snprintf(branch,13,"ITSDigits%s",det[i]);
+            else     snprintf(branch,13,"ITSDigits%d",i+1);
+            br = td->GetBranch(branch);
+            br->SetAddress(&((*digPerDet)[i]));
+            continue; // do next one.
+        } // end if
+        cl =  dynamic_cast<TClonesArray*> (digPerDet->At(i));
+        if(!cl && digPerDet->At(i)!=0){  // not a TClonesArray
+            Error("SetUpDigits","TObject Array digPerDet-At(%d)=%p must be "
+                  "zeroed or filled with TClonesArrays",i,digPerDet);
+            return;
+        } // end if
+        if(!(cl->GetClass()->GetBaseClass(AliITSdigit::Class()))){
+            Error("SetUPDigits","TClones array at digPerDet[%d}=%p must be"
+                  "derived from AliITSdigit",i,digPerDet->At(i));
+        } // end if
+        cl->Clear();
+        if(n==3) snprintf(branch,13,"ITSDigits%s",det[i]);
+        else     snprintf(branch,13,"ITSDigits%d",i+1);
+        br = td->GetBranch(branch);
+        br->SetAddress(&((*digPerDet)[i]));
+        continue;
+    } // end for i
+}
+//---------------------------------------------------------------------
+AliITSdigit * AliITSLoaderUpg::GetDigit(TObjArray *digPerDet,Int_t module,
+                                       Int_t digit){
+    // Gets the digit for for a specific detector type and module.
+    // To be used in conjustion with Setupdigits(AliITS *its).
+    // Inputs:
+    //   TObjArray *digPereDet    Pointer to the Array of digits
+    //   Int_t      module        Module number
+    //   Int_t      digit         Digit number
+    // Outputs:
+    //   none.
+    // Return:
+    //   returns the pointer to the digit. if zero then last digit for that
+    //   module.
+
+    if(digPerDet==0){
+        Error("GetDigit","digPerDet=%p, module=%d, digit=%d",
+              digPerDet,module,digit);
+        return 0;
+    } // end if
+    return 0;
+}
+/*
+//---------------------------------------------------------------------
+AliITSdigit * AliITSLoaderUpg::GetDigit(AliITS *its,Int_t module,Int_t digit){
+    // Gets the digit for for a specific detector type and module.
+    // To be used in conjustion with Setupdigits(AliITS *its).
+    // Inputs:
+    //   AliITS *its    Pointer to the ITS
+    //   Int_t  module  Module number
+    //   Int_t digit    Digit number
+    // Outputs:
+    //   none.
+    // Return:
+    //   returns the pointer to the digit. if zero then last digit for that
+    //   module.
+    //AliITSDetType *idtype;
+    AliITSgeom *geom = its->GetITSgeom();
+    Int_t idet = geom->GetModuleType(module);
+    TClonesArray *digits;
+    its->ResetDigits();
+    TreeD()->GetEvent(module);
+    digits = its->DigitsAddress(idet);
+    if(digit>-1 && digit<digits->GetEntriesFast()){ // if in range.
+        return (AliITSdigit*) digits->At(digit);
+    } // end if
+    return 0;
+}
+*/
+//----------------------------------------------------------------------
+void AliITSLoaderUpg::MakeTree(Option_t *opt){
+    // invokes AliLoader::MakeTree + specific ITS tree(s)
+    // Valid options: H,S,D,R,T and C (C=raw clusters)
+    AliLoader::MakeTree(opt);
+    const char *oC = strstr(opt,"C");
+    if (oC) MakeRawClustersContainer();
+
+    const char *oB = strstr(opt,"B");
+    if (oB) MakeBackTracksContainer();
+
+    const char *oV0 = strstr(opt,"V0");
+    if (oV0) MakeV0Container();
+
+    const char *oX = strstr(opt,"X");
+    if (oX) MakeCascadeContainer();
+}
+
+//----------------------------------------------------------------------
+AliITSgeom* AliITSLoaderUpg::GetITSgeom(Bool_t force) {
+  // retrieves the ITS geometry from file
+  if(fGeom && !force)return fGeom;
+  if(fGeom && force){
+    delete fGeom;
+    fGeom = 0;
+  }
+  if(!gGeoManager){
+    AliError("gGeoManager is a null pointer - ITS geometry not built");
+    return fGeom;
+  }
+  AliITSInitGeometryUpg initgeom;
+  fGeom = initgeom.CreateAliITSgeom();
+  AliDebug(1,"AliITSgeom object has been initialized from TGeo\n");
+  AliDebug(1,Form("Geometry name: %s",(initgeom.GetGeometryName()).Data()));
+  return fGeom;
+}
+//______________________________________________________________________
+void AliITSLoaderUpg::SetITSgeom(AliITSgeom *geom){
+    // Replaces the AliITSgeom object read from file with the one
+    // given.
+    // Inputs:
+    //   AliITSgeom *geom   The AliITSgeom object to replace the one
+    //                      read from the file
+    // Outputs:
+    //   none.
+    // Return:
+    //   none.
+
+    if(fGeom==geom) return; // Same do nothing
+    if(fGeom) {
+       delete fGeom;
+       fGeom=0;
+    }// end if
+    fGeom=geom;
+}
diff --git a/ITS/UPGRADE/AliITSLoaderUpg.h b/ITS/UPGRADE/AliITSLoaderUpg.h
new file mode 100644 (file)
index 0000000..b3bf762
--- /dev/null
@@ -0,0 +1,147 @@
+#ifndef ALIITSLOADERUPG_H
+#define ALIITSLOADERUPG_H
+//////////////////////////////////////////////////////////
+// Loader class for ITS Upgrade                         //
+//////////////////////////////////////////////////////////
+#include <AliLoader.h>
+#include <AliESDVertex.h>
+#include <AliITSgeom.h>
+class AliITSpidESD;
+class AliITSdigit;
+class TObjArray;
+
+class AliITSLoaderUpg: public AliLoader{
+  public:
+    AliITSLoaderUpg();
+    AliITSLoaderUpg(const Char_t *name,const Char_t *topfoldername);
+    AliITSLoaderUpg(const Char_t *name,TFolder *topfolder);
+
+    virtual ~AliITSLoaderUpg();
+
+    void           MakeTree(Option_t* opt);
+    virtual void   SetupDigits(TObjArray *digPerDet,Int_t n,
+                                const Char_t **digclass); // Sets up digits
+    // Gets the AliITSdigit for a given module and a specific digit in that
+    // module. Array of digits stored in AliITS (must use 
+    // SetupDigits(AliITS *its)).
+    // virtual AliITSdigit* GetDigit(AliITS *its,Int_t module,Int_t digit);
+    // Gets the AliITSdigit for a given module and a specific digit in that
+    // module. Array of digits stored in a user defined TObjArray digPerDet
+    virtual AliITSdigit* GetDigit(TObjArray *digPerDet,Int_t module,Int_t digit);
+
+    //Raw Clusters
+    AliDataLoader* GetRawClLoader() {return GetDataLoader("Raw Clusters");}
+    virtual void   CleanRawClusters() {
+        GetRawClLoader()->GetBaseLoader(0)->Clean();}
+    Int_t          LoadRawClusters(Option_t* opt=""){
+        return GetRawClLoader()->GetBaseLoader(0)->Load(opt);}
+    void           SetRawClustersFileName(const TString& fname){
+        GetRawClLoader()->SetFileName(fname);}
+    // returns a pointer to the tree of  RawClusters
+    TTree*         TreeC(){ return GetRawClLoader()->Tree();} 
+    void           UnloadRawClusters(){
+        GetRawClLoader()->GetBaseLoader(0)->Unload();}
+    virtual Int_t  WriteRawClusters(Option_t* opt=""){
+        return GetRawClLoader()->GetBaseLoader(0)->WriteData(opt);}
+
+    //Vertices
+    AliDataLoader* GetVertexDataLoader() {
+        return GetDataLoader("Primary Vertices");}
+    virtual void   CleanVertices() {
+        GetVertexDataLoader()->GetBaseLoader(0)->Clean();}
+    Int_t          LoadVertices(Option_t* opt=""){
+        return GetVertexDataLoader()->GetBaseLoader(0)->Load(opt);}
+    void           SetVerticesFileName(const TString& fname){
+        GetVertexDataLoader()->SetFileName(fname);}
+    void           UnloadVertices(){
+        GetVertexDataLoader()->GetBaseLoader(0)->Unload();}
+    virtual Int_t  WriteVertices(Option_t* opt=""){
+        return GetVertexDataLoader()->GetBaseLoader(0)->WriteData(opt);}
+    virtual Int_t PostVertex(AliESDVertex *ptr){
+        return GetVertexDataLoader()->GetBaseLoader(0)->Post(ptr);}
+    //    virtual void SetVerticesContName(const char *name){
+    //       GetVertexDataLoader()->GetBaseLoader(0)->SetName(name);}
+    AliESDVertex *GetVertex(){
+        return static_cast <AliESDVertex*>(GetVertexDataLoader()->
+                                           GetBaseLoader(0)->Get());}
+    //V0s
+    AliDataLoader* GetV0DataLoader() {return GetDataLoader("V0 Vertices");}
+    virtual void   CleanV0s() {GetV0DataLoader()->GetBaseLoader(0)->Clean();}
+    Int_t          LoadV0s(Option_t* opt=""){
+        return GetV0DataLoader()->GetBaseLoader(0)->Load(opt);}
+    void           SetV0FileName(const TString& fname){
+        GetV0DataLoader()->SetFileName(fname);}
+    void           UnloadV0s(){GetV0DataLoader()->GetBaseLoader(0)->Unload();}
+    virtual Int_t  WriteV0s(Option_t* opt=""){
+        return GetV0DataLoader()->GetBaseLoader(0)->WriteData(opt);}
+    TTree*         TreeV0(){ return GetV0DataLoader()->Tree();}
+
+    //Cascades
+    AliDataLoader* GetCascadeDataLoader() {return GetDataLoader("Cascades");}
+    virtual void   CleanCascades() {
+        GetCascadeDataLoader()->GetBaseLoader(0)->Clean();}
+    Int_t          LoadCascades(Option_t* opt=""){
+        return GetCascadeDataLoader()->GetBaseLoader(0)->Load(opt);}
+    void           SetCascadeFileName(const TString& fname){
+        GetCascadeDataLoader()->SetFileName(fname);}
+    void           UnloadCascades(){
+        GetCascadeDataLoader()->GetBaseLoader(0)->Unload();}
+    virtual Int_t  WriteCascades(Option_t* opt=""){
+        return GetCascadeDataLoader()->GetBaseLoader(0)->WriteData(opt);}
+    TTree*         TreeX(){ return GetCascadeDataLoader()->Tree();}
+
+    //Back Propagated Tracks
+    AliDataLoader* GetBackTracksDataLoader() {
+        return GetDataLoader("Back Propagated Tracks");}
+    virtual void   CleanBackTracks() {
+        GetBackTracksDataLoader()->GetBaseLoader(0)->Clean();}
+    Int_t          LoadBackTracks(Option_t* opt=""){
+        return GetBackTracksDataLoader()->GetBaseLoader(0)->Load(opt);}
+    void           SetBackTracksFileName(const TString& fname){
+        GetBackTracksDataLoader()->SetFileName(fname);}
+     // returns a pointer to the tree of  BackTracks
+    TTree*         TreeB(){ return GetBackTracksDataLoader()->Tree();}
+    void           UnloadBackTracks(){
+        GetBackTracksDataLoader()->GetBaseLoader(0)->Unload();}
+    virtual Int_t  WriteBackTracks(Option_t* opt=""){
+        return GetBackTracksDataLoader()->GetBaseLoader(0)->WriteData(opt);}
+
+    // Geometry. Geom is read from file, unless already loaded
+    // readout from file can be forced if force=kTRUE
+    AliITSgeom* GetITSgeom(Bool_t force=kFALSE); 
+    void SetITSgeom(AliITSgeom* g);
+  protected:
+
+    AliITSLoaderUpg(const AliITSLoaderUpg &ob); // copy constructor
+    AliITSLoaderUpg& operator=(const AliITSLoaderUpg & /* source */); // ass.
+
+    // METHODS
+    virtual void   MakeRawClustersContainer() {GetRawClLoader()->MakeTree();}
+    Int_t          PostRawClusters(){
+        return GetRawClLoader()->GetBaseLoader(0)->Post();}
+
+    virtual void   MakeBackTracksContainer() {
+        GetBackTracksDataLoader()->MakeTree();}
+    Int_t          PostBackTracks(){
+        return GetBackTracksDataLoader()->GetBaseLoader(0)->Post();}
+    virtual void   MakeV0Container() {GetV0DataLoader()->MakeTree();}
+    Int_t          PostV0s(){
+        return GetV0DataLoader()->GetBaseLoader(0)->Post();}
+
+    virtual void   MakeCascadeContainer() {GetCascadeDataLoader()->MakeTree();}
+    Int_t          PostCascades(){
+        return GetCascadeDataLoader()->GetBaseLoader(0)->Post();}
+
+    // DATA
+    static const TString fgkDefaultRawClustersContainerName;  //default for Raw Clusters container name
+    static const TString fgkDefaultBackTracksContainerName;   //default for Back propag. tracks container name
+    static const TString fgkDefaultVerticesContainerName;     //default for primary vertices container name
+    static const TString fgkDefaultV0ContainerName;           //default for V0 container name
+    static const TString fgkDefaultCascadeContainerName;      //default fo cascade container name
+    AliITSgeom *fGeom;     //! pointer to the ITS geometry class
+
+
+    ClassDef(AliITSLoaderUpg,1) // Loader for additional ITS specific trees.
+};
+#endif
diff --git a/ITS/UPGRADE/AliITSUpg.cxx b/ITS/UPGRADE/AliITSUpg.cxx
new file mode 100644 (file)
index 0000000..98a3394
--- /dev/null
@@ -0,0 +1,1393 @@
+/**************************************************************************
+ * 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: AliITSUpg.cxx $ */
+
+
+///////////////////////////////////////////////////////////////////////////////
+//                                                                           //
+//      An overview of the basic philosophy of the ITS code development      //
+// and analysis is show in the figure below.                                 //
+//Begin_Html                                                                 //
+/*                                               
+<img src="picts/ITS/ITS_Analysis_schema.gif">
+</pre>
+<br clear=left>
+<font size=+2 color=red>
+<p>Roberto Barbera is in charge of the ITS Offline code (1999).
+<a href="mailto:roberto.barbera@ct.infn.it">Roberto Barbera</a>.
+</font>
+<pre>
+*/
+//End_Html
+//
+//  AliITSUpg. Inner Traking System base class.
+//  This class contains the base procedures for the Inner Tracking System
+//
+//Begin_Html
+/*
+<img src="picts/ITS/AliITS_Class_Diagram.gif">
+</pre>
+<br clear=left>
+<font size=+2 color=red>
+<p>This show the class diagram of the different elements that are part of
+the AliITS class.
+</font>
+<pre>
+*/
+//End_Html
+//
+// Version: 0
+// Written by Rene Brun, Federico Carminati, and Roberto Barbera
+//
+// Version: 1
+// Modified and documented by Bjorn S. Nilsen
+// July 11 1999
+//
+// Version: 2
+// Modified and documented by A. Bologna
+// October 18 1999
+//
+// AliITSUpg is the general base class for the ITS. Also see AliDetector for
+// futher information.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include <stdlib.h>
+#include <TClonesArray.h>
+#include <TFile.h>
+#include <TParticle.h>
+#include <TString.h>
+#include <TTree.h>
+#include <TVirtualMC.h>
+#include "AliDetector.h"
+#include "AliITSUpg.h"
+#include "AliITSDetTypeSim.h"
+#include "AliITSDDLRawData.h"
+#include "AliITSLoader.h"
+#include "AliITSLoaderUpg.h"
+#include "AliITShit.h"
+#include "AliITSmodule.h"
+#include "AliITSpListItem.h"
+#include "AliITSsimulation.h"
+#include "AliITSsimulationFastPoints.h"
+#include "AliMC.h"
+#include "AliITSDigitizer.h"
+#include "AliITSRecPoint.h"
+#include "AliITSsegmentationSPD.h"
+#include "AliITSsegmentationSDD.h"
+#include "AliITSsimulationSDD.h"
+#include "AliITSCalibrationSDD.h"
+#include "AliITSCalibrationSSD.h"
+#include "AliITSsegmentationSSD.h"
+#include "AliITSRawStreamSPD.h"
+#include "AliITSRawStreamSSD.h"
+#include "AliITSRawStreamSDD.h"
+#include "AliRawReader.h"
+#include "AliRun.h"
+#include "AliLog.h"
+#include "AliITSInitGeometryUpg.h"
+#include "AliITSFOSignalsSPD.h"
+
+ClassImp(AliITSUpg)
+
+//______________________________________________________________________
+AliITSUpg::AliITSUpg() : AliDetector(),
+fDetTypeSim(0),
+fEuclidOut(0),
+fOpt("All"),
+fIdN(0),
+fIdSens(0),
+fIdName(0),
+fITSmodules(0),
+fTiming(kFALSE),
+fSimuParam(0),
+fModA(0),
+fpSDigits(0)
+{
+  // Default initializer for ITS
+  //      The default constructor of the AliITS class. In addition to
+  // creating the AliITS class it zeros the variables fIshunt (a member
+  // of AliDetector class), fEuclidOut, and fIdN, and zeros the pointers
+  // fIdSens, and fIdName. The AliDetector default constructor
+  // is also called.
+  
+//    SetDetectors(); // default to fOpt="All". This variable not written out.
+//PH    SetMarkerColor(kRed);
+}
+//______________________________________________________________________
+AliITSUpg::AliITSUpg(const Char_t *title):
+  AliDetector("ITS",title),
+  fDetTypeSim(0),
+  fEuclidOut(0),
+  fOpt("All"),
+  fIdN(0),
+  fIdSens(0),
+  fIdName(0),
+  fITSmodules(0),
+  fTiming(kFALSE),
+  fSimuParam(0),
+  fModA(0),
+  fpSDigits(0)
+{
+    //     The standard Constructor for the ITS class. 
+    // It also zeros the variables
+    // fIshunt (a member of AliDetector class), fEuclidOut, and zeros
+    // the pointers fIdSens and fIdName. To help in displaying hits via the
+    // ROOT macro display.C AliITS also sets the marker color to red. The
+    // variables passes with this constructor, const char *name and *title,
+    // are used by the constructor of AliDetector class. See AliDetector
+    // class for a description of these parameters and its constructor
+    // functions.
+    // Inputs:
+    //   Char_t *title  Simulation title for the ITS
+    // Outputs:
+    //   none.
+    // Return:
+    //   none.
+  
+    fHits = new TClonesArray("AliITShit",1560); // from AliDetector
+    if(gAlice->GetMCApp()) gAlice->GetMCApp()->AddHitList(fHits);
+    //fNhits=0;  //done in AliDetector(name,title)
+    SetDetectors(); // default to fOpt="All". This variable not written out.
+    fDetTypeSim   = new AliITSDetTypeSim();
+    //PH  SetMarkerColor(kRed);
+    if(!fLoader) MakeLoader(AliConfig::GetDefaultEventFolderName());
+    fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
+}
+//______________________________________________________________________
+AliITSUpg::AliITSUpg(const char *name, const char *title):
+  AliDetector(name,title),
+  fDetTypeSim(0),
+  fEuclidOut(0),
+  fOpt("All"),
+  fIdN(0),
+  fIdSens(0),
+  fIdName(0),
+  fITSmodules(0),
+  fTiming(kFALSE),
+  fSimuParam(0),
+  fModA(0),
+  fpSDigits(0)
+{
+  //     The standard Constructor for the ITS class. 
+  // It also zeros the variables
+  // fIshunt (a member of AliDetector class), fEuclidOut, and zeros
+  // the pointers fIdSens and fIdName. To help in displaying hits via the
+  // ROOT macro display.C AliITS also sets the marker color to red. The
+  // variables passes with this constructor, const char *name and *title,
+  // are used by the constructor of AliDetector class. See AliDetector
+  // class for a description of these parameters and its constructor
+  // functions.
+  
+  fHits = new TClonesArray("AliITShit",1560);
+  if(gAlice->GetMCApp()) gAlice->GetMCApp()->AddHitList(fHits);
+  //fNhits=0;  //done in AliDetector(name,title)
+
+  SetDetectors(); // default to fOpt="All". This variable not written out.
+    
+  fDetTypeSim   = new AliITSDetTypeSim();
+  //PH  SetMarkerColor(kRed);
+  if(!fLoader) MakeLoader(AliConfig::GetDefaultEventFolderName());
+  fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
+
+}
+//______________________________________________________________________
+AliITSUpg::~AliITSUpg(){
+    // Default destructor for ITS.
+    //     The default destructor of the AliITS class. In addition to deleting
+    // the AliITS class it deletes the memory pointed to by 
+    // fIdSens, fIdName, fDetTypeSim and it's contents.
+    // Inputs:
+    //      none.
+    // Outputs:
+    //      none.
+    // Return:
+    //      none.
+
+    if (fHits) {
+      fHits->Delete();
+      delete fHits;
+      fHits=0;
+    }
+    if(fITSmodules) {
+        this->ClearModules();
+        delete fITSmodules;
+       fITSmodules = 0;
+    }// end if fITSmodules!=0
+
+    delete[] fIdName;  // Array of TStrings
+    delete[] fIdSens;
+    Int_t size   = AliITSgeomTGeo::GetNModules();
+    if (fDetTypeSim){
+      delete fDetTypeSim;
+      fDetTypeSim = 0;
+    }
+    if(fSimuParam){
+      delete fSimuParam;
+      fSimuParam=0;
+    }
+    if(fModA){
+      if(size>0){
+       for(Int_t j=0; j<size; j++){
+         fModA[j]->Delete();
+         delete fModA[j];
+       }
+      }
+      delete []fModA;
+    }
+    if(fpSDigits){
+      fpSDigits->Delete();
+      delete fpSDigits;
+    }
+}
+
+//______________________________________________________________________
+AliDigitizer* AliITSUpg::CreateDigitizer(AliRunDigitizer* manager)const{
+    // Creates the AliITSDigitizer in a standard way for use via AliModule.
+    // This function can not be included in the .h file because of problems
+    // with the order of inclusion (recursive).
+    // Inputs:
+    //    AliRunDigitizer *manager  The Manger class for Digitization
+    // Output:
+    //    none.
+    // Return:
+    //    A new AliITSRunDigitizer (cast as a AliDigitizer).
+
+     return new AliITSDigitizer(manager);
+}
+//______________________________________________________________________
+void AliITSUpg::Init(){
+    // Initializer ITS after it has been built
+    //     This routine initializes the AliITS class. It is intended to be
+    // called from the Init function in AliITSv?. Besides displaying a banner
+    // indicating that it has been called it initializes the array fIdSens
+    // and sets the default segmentation, response, digit and raw cluster
+    // classes therefore it should be called after a call to CreateGeometry.
+    // Inputs:
+    //      none.
+    // Outputs:
+    //      none.
+    // Return:
+    //      none.
+    Int_t i;
+    // Array of TStrings
+    if(gMC) for(i=0;i<fIdN;i++) fIdSens[i] = gMC->VolId(fIdName[i]);
+}
+//______________________________________________________________________
+void AliITSUpg::SetDefaults(){
+    // sets the default segmentation, response, digit and raw cluster classes.
+    // Inputs:
+    //      none.
+    // Outputs:
+    //      none.
+    // Return:
+    //      none.
+    AliInfoClass("AliITSUpg::Setting Defaults");
+    if(!fDetTypeSim) { 
+     Error("SetDefaults()","fDetTypeSim is 0!"); 
+     return;
+    }
+
+    fDetTypeSim->SetDefaults();
+    if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
+
+}
+//______________________________________________________________________
+void AliITSUpg::SetDefaultSimulation(){
+    // sets the default simulation.
+    // Inputs:
+    //      none.
+    // Outputs:
+    //      none.
+    // Return:
+    //      none.
+    if(!fDetTypeSim) { 
+     Error("SetDefaultSimulation()","fDetTypeSim is 0!"); 
+     return;
+    }
+
+    fDetTypeSim->SetDefaultSimulation();
+    if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
+
+}
+
+
+//______________________________________________________________________
+void AliITSUpg::MakeBranch(Option_t* option){
+    // Creates Tree branches for the ITS.
+    // Inputs:
+    //      Option_t *option    String of Tree types S,D, and/or R.
+    //      const char *file    String of the file name where these branches
+    //                          are to be stored. If blank then these branches
+    //                          are written to the same tree as the Hits were
+    //                          read from.
+    // Outputs:
+    //      none.
+    // Return:
+    //      none.
+  if(!fDetTypeSim) {
+    Error("MakeBranch","fDetTypeSim is 0!");
+    return;
+  }
+
+  Bool_t cH = (strstr(option,"H")!=0);
+  Bool_t cS = (strstr(option,"S")!=0);
+  Bool_t cD = (strstr(option,"D")!=0);
+  
+  if(cH && (fHits == 0x0)) fHits = new TClonesArray("AliITShit", 1560);
+  AliDetector::MakeBranch(option);
+  
+  if(cS) MakeBranchS(0);
+  if(cD) MakeBranchD(0);
+
+
+}
+//___________________________________________________________________
+void AliITSUpg::MakeBranchS(const char* fl){
+
+  // Creates Tree Branch for the ITS summable digits.
+  // Inputs:
+  //      cont char *fl  File name where SDigits branch is to be written
+  //                     to. If blank it write the SDigits to the same
+  //                     file in which the Hits were found.
+
+  
+  if(!fDetTypeSim){
+    Error("MakeBranchS","fDetTypeSim is 0!");
+  }
+  Int_t buffersize = 4000;
+  char branchname[31];
+
+  // only one branch for SDigits.
+  snprintf(branchname,30,"%s",GetName());
+
+  if(fLoader->TreeS()){
+    TClonesArray* sdig = (TClonesArray*)fDetTypeSim->GetSDigits();
+    MakeBranchInTree(fLoader->TreeS(),branchname,&sdig,buffersize,fl);
+  } 
+}
+//______________________________________________________________________
+void AliITSUpg::MakeBranchD(const char* file){
+
+  //Make branch for digits
+  if(!fDetTypeSim) {
+    Warning("MakeBranchD","fDetTypeSim is 0!");
+    return;
+  }
+  fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
+  if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
+  MakeBranchInTreeD(fLoader->TreeD(),file);
+}
+
+//___________________________________________________________________
+void AliITSUpg:: MakeBranchInTreeD(TTree* treeD, const char* file){
+  // Creates Tree branches for the ITS.
+
+  if(!fDetTypeSim){
+    Error("MakeBranchS","fDetTypeSim is 0!");
+  }
+  fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
+  if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
+
+  const Char_t *det[3] = {"SPD","SDD","SSD"};
+  const Char_t* digclass;
+  Int_t buffersize = 4000;
+  Char_t branchname[31];
+  
+  if(!fDetTypeSim->GetDigits()){
+    fDetTypeSim->SetDigits(new TObjArray(fgkNTYPES));
+  }
+  for(Int_t i=0;i<fgkNTYPES;i++){
+    digclass = fDetTypeSim->GetDigitClassName(i);
+    TString classn = digclass;
+    if(!((fDetTypeSim->GetDigits())->At(i))){
+      (fDetTypeSim->GetDigits())->AddAt(new TClonesArray(classn.Data(),1000),i);
+    }
+    else ResetDigits(i);  
+    if(fgkNTYPES==3) snprintf(branchname,30,"%sDigits%s",GetName(),det[i]);
+    else sprintf(branchname,"%sDigits%d",GetName(),i+1);
+    TObjArray* dig = DigitsAddress(i);
+    if(GetDigits() && treeD) AliDetector::MakeBranchInTree(treeD,branchname, &dig,buffersize,file);
+  }
+
+}
+//______________________________________________________________________
+void AliITSUpg::SetTreeAddress(){
+    // Set branch address for the Trees.
+    // Inputs:
+    //      none.
+    // Outputs:
+    //      none.
+    // Return:
+    //      none.
+    
+  if(!fDetTypeSim) {
+    Error("SetTreeAddress","fDetTypeSim is 0!");
+    return;
+  }
+
+  fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
+  if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
+
+  TTree *treeS = fLoader->TreeS();
+  TTree *treeD = fLoader->TreeD();
+  if (fLoader->TreeH() && (fHits == 0x0)) {
+      fHits = new TClonesArray("AliITShit", 1560);
+  }
+  AliDetector::SetTreeAddress();
+
+  fDetTypeSim->SetTreeAddressS(treeS, (Char_t*)GetName());
+  fDetTypeSim->SetTreeAddressD(treeD, (Char_t*)GetName());
+}
+//______________________________________________________________________
+void AliITSUpg::AddHit(Int_t track, Int_t *vol, Float_t *hits){
+    // Add an ITS hit
+    //     The function to add information to the AliITShit class. See the
+    // AliITShit class for a full description. This function allocates the
+    // necessary new space for the hit information and passes the variable
+    // track, and the pointers *vol and *hits to the AliITShit constructor
+    // function.
+    // Inputs:
+    //      Int_t   track   Track number which produced this hit.
+    //      Int_t   *vol    Array of Integer Hit information. See AliITShit.h
+    //      Float_t *hits   Array of Floating Hit information.  see AliITShit.h
+    // Outputs:
+    //      none.
+    // Return:
+    //      none.
+  TClonesArray &lhits = *fHits;
+  new(lhits[fNhits++]) AliITShit(fIshunt,track,vol,hits);
+}
+
+//______________________________________________________________________
+void AliITSUpg::FillModules(Int_t /* evnt */,Int_t bgrev,Int_t /* nmodules */,
+                         Option_t *option, const char *filename){
+  // fill the modules with the sorted by module hits; add hits from
+  // background if option=Add.
+
+  static TTree *trH1;                 //Tree with background hits
+  static Bool_t first=kTRUE;
+  static TFile *file;
+  const char *addBgr = strstr(option,"Add");
+  
+  if (addBgr ) {
+    if(first) {
+      file=new TFile(filename);
+    } // end if first
+    first=kFALSE;
+    file->cd();
+    file->ls();
+    // Get Hits Tree header from file
+    if(trH1) delete trH1;
+    trH1=0;
+    
+    char treeName[21];
+    snprintf(treeName,20,"TreeH%d",bgrev);
+    trH1 = (TTree*)gDirectory->Get(treeName);
+    if (!trH1) {
+      Error("FillModules","cannot find Hits Tree for event:%d",bgrev);
+    } // end if !trH1
+    // Set branch addresses
+  } // end if addBgr
+  
+  FillModules(fLoader->TreeH(),0); // fill from this file's tree.
+    
+  if (addBgr ) {
+    FillModules(trH1,10000000); // Default mask 10M.
+    TTree *fAli=fLoader->GetRunLoader()->TreeK();
+    TFile *fileAli=0;
+    if (fAli) {
+      fileAli =fAli->GetCurrentFile();
+      fileAli->cd();
+    }
+  } // end if add
+  
+  
+}
+//______________________________________________________________________
+void AliITSUpg::FillModules(TTree *treeH, Int_t mask) {
+    // fill the modules with the sorted by module hits; 
+    // can be called many times to do a merging
+    // Inputs:
+    //      TTree *treeH  The tree containing the hits to be copied into
+    //                    the modules.
+    //      Int_t mask    The track number mask to indecate which file
+    //                    this hits came from.
+    // Outputs:
+    //      none.
+    // Return:
+    //      none.
+
+    if (treeH == 0x0)
+     {
+       AliError("Tree H  is NULL");
+       return;
+     }
+    Int_t lay,lad,det,index;
+    AliITShit *itsHit=0;
+    AliITSmodule *mod=0;
+    char branchname[21];
+    snprintf(branchname,20,"%s",GetName());
+    TBranch *branch = treeH->GetBranch(branchname);
+    if (!branch) {
+        Error("FillModules","%s branch in TreeH not found",branchname);
+        return;
+    } // end if !branch
+    branch->SetAddress(&fHits);
+    Int_t nTracks =(Int_t) treeH->GetEntries();
+    Int_t iPrimTrack,h;
+    for(iPrimTrack=0; iPrimTrack<nTracks; iPrimTrack++){
+        ResetHits();
+        Int_t nBytes = treeH->GetEvent(iPrimTrack);
+        if (nBytes <= 0) continue;
+        Int_t nHits = fHits->GetEntriesFast();
+        for(h=0; h<nHits; h++){
+            itsHit = (AliITShit *)fHits->UncheckedAt(h);
+            itsHit->GetDetectorID(lay,lad,det);
+            if (GetITSgeom()) {
+                index = GetITSgeom()->GetModuleIndex(lay,lad,det);
+            } else {
+                index=det-1; // This should not be used.
+            } // end if [You must have fITSgeom for this to work!]
+            mod = GetModule(index);
+            itsHit->SetTrack(itsHit->GetTrack()+mask); // Set track mask.
+            mod->AddHit(itsHit,iPrimTrack,h);
+        } // end loop over hits 
+    } // end loop over tracks
+}
+
+//______________________________________________________________________
+Bool_t AliITSUpg::InitModules(Int_t size,Int_t &nmodules){
+    // Initialize the modules array.
+    // Inputs:
+    //      Int_t size  Size of array of the number of modules to be
+    //                  created. If size <=0 then the number of modules
+    //                  is gotten from AliITSgeom class kept in fITSgeom.
+    // Outputs:
+    //      Int_t &nmodules The number of modules existing.
+    // Return:
+    //      none.
+
+    if(fITSmodules){ 
+        fITSmodules->Delete();
+        delete fITSmodules;
+    } // end fir fITSmoudles
+
+    if(!fDetTypeSim) {
+      Error("InitModules","fDetTypeSim is null!");
+      return kFALSE;
+    }
+    if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
+
+    Int_t nl,indexMAX,index;
+
+    if(size<=0){ // default to using data stored in AliITSgeom
+        if(fDetTypeSim->GetITSgeom()==0) {
+            Error("InitModules","fITSgeom not defined");
+            return kFALSE;
+        } // end if fITSgeom==0
+        nl = fDetTypeSim->GetITSgeom()->GetNlayers();
+        indexMAX = fDetTypeSim->GetITSgeom()->GetIndexMax();
+        nmodules = indexMAX;
+        fITSmodules = new TObjArray(indexMAX);
+        for(index=0;index<indexMAX;index++){
+            fITSmodules->AddAt( new AliITSmodule(index),index);
+        } // end for index
+    }else{
+        fITSmodules = new TObjArray(size);
+        for(index=0;index<size;index++) {
+            fITSmodules->AddAt( new AliITSmodule(index),index);
+        } // end for index
+
+        nmodules = size;
+    } // end i size<=0
+    return kTRUE;
+}
+//______________________________________________________________________
+void AliITSUpg::Hits2SDigits(){
+    // Standard Hits to summable Digits function.
+    // Inputs:
+    //      none.
+    // Outputs:
+    //      none.
+  
+
+   if(!fDetTypeSim) {
+     Error("Hits2SDigits","fDetTypeSim is null!");
+     return; 
+  } 
+     
+  SetDefaults();
+  fLoader->LoadHits("read");
+  fLoader->LoadSDigits("recreate");
+  AliRunLoader* rl = fLoader->GetRunLoader(); 
+  fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
+  if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
+
+  for (Int_t iEvent = 0; iEvent < rl->GetNumberOfEvents(); iEvent++) {
+        // Do the Hits to Digits operation. Use Standard input values.
+        // Event number from file, no background hit merging , use size from
+        // AliITSgeom class, option="All", input from this file only.
+    rl->GetEvent(iEvent);
+    if (!fLoader->TreeS()) fLoader->MakeTree("S");
+    MakeBranch("S");
+    SetTreeAddress();
+    HitsToPreDigits(iEvent,0,-1," ",fOpt," ");
+  } // end for iEvent
+    
+  fLoader->UnloadHits();
+  fLoader->UnloadSDigits();
+  
+}
+//______________________________________________________________________
+void AliITSUpg::Hits2Digits(){
+
+  //Conversion from hits to digits
+  if(!fDetTypeSim) {
+    Error("Hits2SDigits","fDetTypeSim is 0!");
+    return;
+  }
+   
+  fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
+  if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
+  SetDefaults();
+
+  fLoader->LoadHits("read");
+  fLoader->LoadDigits("recreate");
+  AliRunLoader* rl = fLoader->GetRunLoader(); 
+  for (Int_t iEvent = 0; iEvent < rl->GetNumberOfEvents(); iEvent++) {
+    rl->GetEvent(iEvent);
+    if (!fLoader->TreeD()) fLoader->MakeTree("D");
+    MakeBranch("D");
+    SetTreeAddress();   
+    HitsToDigits(iEvent,0,-1," ",fOpt," ");
+  } 
+  
+  fLoader->UnloadHits();
+  fLoader->UnloadDigits();
+  
+}
+
+//______________________________________________________________________
+void AliITSUpg::HitsToDigits(Int_t evNumber,Int_t bgrev,Int_t size,
+                          Option_t *option,Option_t *opt,
+                          const char *filename){
+    //   Keep galice.root for signal and name differently the file for 
+    // background when add! otherwise the track info for signal will be lost !
+    // the condition below will disappear when the geom class will be
+    // initialized for all versions - for the moment it is only for v5 !
+    // 7 is the SDD beam test version.
+    // Inputs:
+    //      Int_t evnt       Event to be processed.
+    //      Int_t bgrev      Background Hit tree number.
+    //      Int_t nmodules   Not used.
+    //      Option_t *option String indicating if merging hits or not. To
+    //                       merge hits set equal to "Add". Otherwise no
+    //                       background hits are considered.
+    //      Test_t *filename File name containing the background hits..
+    // Outputs:
+    //      none.
+    // Return:
+    //      none.
+
+  if(!fDetTypeSim) {
+    Error("HitsToDigits","fDetTypeSim is null!");
+    return;
+  }
+  fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
+  if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
+  if(!GetITSgeom()) return; // need transformations to do digitization.
+  AliITSgeom *geom = GetITSgeom();
+
+  const char *all = strstr(opt,"All");
+  const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
+                       strstr(opt,"SSD")};
+  static Bool_t setDef=kTRUE;
+  if (setDef) SetDefaultSimulation();
+  setDef=kFALSE;
+  
+  Int_t nmodules;
+  InitModules(size,nmodules);
+  FillModules(evNumber,bgrev,nmodules,option,filename);
+  // Reset Fast-OR signals for this event
+//  fDetTypeSim->ResetFOSignals();
+
+  AliITSsimulation *sim      = 0;
+  AliITSmodule     *mod      = 0;
+  Int_t id;
+  for(Int_t module=0;module<geom->GetIndexMax();module++){
+    id       = geom->GetModuleType(module);
+    if (!all && !det[id]) continue;
+    sim      = (AliITSsimulation*)fDetTypeSim->GetSimulationModel(id);
+    if (!sim) {
+      Error("HitsToDigits","The simulation class was not "
+           "instanciated for module %d type %s!",module,
+           geom->GetModuleTypeName(module));
+      exit(1);
+    } // end if !sim
+    mod      = (AliITSmodule *)fITSmodules->At(module);
+    sim->DigitiseModule(mod,module,evNumber);
+    // fills all branches - wasted disk space
+    fLoader->TreeD()->Fill(); 
+    ResetDigits();
+  } // end for module
+  
+  ClearModules();
+  // Add Fast-OR signals to event (only one object per event)
+  if (all || det[0]) { // SPD present
+    WriteFOSignals();
+  }
+  
+  fLoader->TreeD()->GetEntries();
+  fLoader->TreeD()->AutoSave();
+  // reset tree
+  fLoader->TreeD()->Reset();
+}
+//_____________________________________________________________________
+void AliITSUpg::Hits2PreDigits(){ 
+  // Turn hits into SDigits
+
+  if(!fDetTypeSim) {
+    Error("Hits2SDigits","fDetTypeSim is 0!");
+    return;
+  }
+   
+  fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
+  if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
+  SetDefaults();
+  
+  HitsToPreDigits(fLoader->GetRunLoader()->GetEventNumber(),
+                 0,-1," ",fOpt," ");
+}
+
+//______________________________________________________________________
+void AliITSUpg::HitsToPreDigits(Int_t evNumber,Int_t bgrev,Int_t size,
+                             Option_t *option,Option_t *opt,
+                             const char *filename){
+    //   Keep galice.root for signal and name differently the file for 
+    // background when add! otherwise the track info for signal will be lost !
+    // the condition below will disappear when the geom class will be
+    // initialized for all versions - for the moment it is only for v5 !
+    // 7 is the SDD beam test version.
+    // Inputs:
+    //      Int_t evnt       Event to be processed.
+    //      Int_t bgrev      Background Hit tree number.
+    //      Int_t nmodules   Not used.
+    //      Option_t *option String indicating if merging hits or not. To
+    //                       merge hits set equal to "Add". Otherwise no
+    //                       background hits are considered.
+    //      Test_t *filename File name containing the background hits..
+    // Outputs:
+    //      none.
+    // Return:
+    //      none.
+
+  if(!fDetTypeSim) {
+    Error("HitsToPreDigits","fDetTypeSim is null!");
+    return;
+  }
+  fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
+  if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
+
+  if(!GetITSgeom()){
+    Error("HitsToPreDigits","fGeom is null!");
+    return; // need transformations to do digitization.
+  }
+  AliITSgeom *geom = GetITSgeom();
+
+  const char *all = strstr(opt,"All");
+  const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
+                       strstr(opt,"SSD")};
+  static Bool_t setDef=kTRUE;
+  if (setDef) SetDefaultSimulation();
+  setDef=kFALSE;
+  
+  Int_t nmodules;
+  InitModules(size,nmodules);
+  FillModules(evNumber,bgrev,nmodules,option,filename);
+  
+
+  AliITSsimulation *sim      = 0;
+  AliITSmodule     *mod      = 0;
+  Int_t id,module;
+  for(module=0;module<geom->GetIndexMax();module++){
+    id       = geom->GetModuleType(module);
+    if (!all && !det[id]) continue;
+    sim      = (AliITSsimulation*)GetSimulationModel(id);
+    if (!sim) {
+      Error("HitsToPreDigits","The simulation class was not "
+           "instanciated for module %d type %s!",module,
+           geom->GetModuleTypeName(module));
+      exit(1);
+    } // end if !sim
+    mod      = (AliITSmodule *)fITSmodules->At(module);
+    sim->SDigitiseModule(mod,module,evNumber);
+    // fills all branches - wasted disk space
+    fLoader->TreeS()->Fill(); 
+    fDetTypeSim->ResetSDigits();
+  } // end for module
+
+  ClearModules();
+
+  
+  fLoader->TreeS()->GetEntries();
+  fLoader->TreeS()->AutoSave();
+  fLoader->WriteSDigits("OVERWRITE");
+  // reset tree
+  fLoader->TreeS()->Reset();
+}
+
+//_____________________________________________________________________
+void AliITSUpg::HitsToFastRecPoints(Int_t evNumber,Int_t bgrev,Int_t size,
+                                  Option_t *opt0,Option_t *opt1,
+                                 const char *flnm){
+    // keep galice.root for signal and name differently the file for 
+    // background when add! otherwise the track info for signal will be lost !
+    // the condition below will disappear when the geom class will be
+    // initialized for all versions - for the moment it is only for v5 !
+    // Inputs:
+    //      Int_t evnt       Event to be processed.
+    //      Int_t bgrev      Background Hit tree number.
+    //      Int_t size       Size used by InitModules. See InitModules.
+    //      Option_t *opt0   Option passed to FillModules. See FillModules.
+    //      Option_t *opt1   String indicating if merging hits or not. To
+    //                       merge hits set equal to "Add". Otherwise no
+    //                       background hits are considered.
+    //      Test_t *flnm     File name containing the background hits..
+    // Outputs:
+    //      none.
+    // Return:
+    //      none.
+
+
+
+  if(!GetITSgeom()){
+    Error("HitsToPreDigits","fGeom is null!");
+    return; // need transformations to do digitization.
+  }
+  AliITSgeom *geom = GetITSgeom();
+
+  AliITSLoaderUpg *pITSloader = (AliITSLoaderUpg*)fLoader;
+
+  const char *all = strstr(opt1,"All");
+  const char *det[3] ={strstr(opt1,"SPD"),strstr(opt1,"SDD"),
+                      strstr(opt1,"SSD")};
+  Int_t nmodules;
+  InitModules(size,nmodules);
+  FillModules(evNumber,bgrev,nmodules,opt0,flnm);
+
+  AliITSsimulation *sim      = 0;
+  AliITSmodule     *mod      = 0;
+  Int_t id,module;
+
+  TTree *lTR = pITSloader->TreeR();
+  if(!lTR) {
+    pITSloader->MakeTree("R");
+    lTR = pITSloader->TreeR();
+  }
+  
+  TClonesArray* ptarray = new TClonesArray("AliITSRecPoint",1000);
+  TBranch* branch = (TBranch*)lTR->Branch("ITSRecPointsF",&ptarray);
+  branch->SetAddress(&ptarray);
+  //m.b. : this change is nothing but a nice way to make sure
+  //the CPU goes up !    
+  for(module=0;module<geom->GetIndexMax();module++){
+    id       = geom->GetModuleType(module);
+    if (!all && !det[id]) continue;
+    sim      = (AliITSsimulation*)GetSimulationModel(id);
+    if (!sim) {
+      Error("HitsToFastPoints","The simulation class was not "
+           "instantiated for module %d type %s!",module,
+           geom->GetModuleTypeName(module));
+      exit(1);
+    } // end if !sim
+    mod      = (AliITSmodule *)fITSmodules->At(module);
+    sim->CreateFastRecPoints(mod,module,gRandom,ptarray);
+    lTR->Fill();
+    ptarray->Clear();
+  } // end for module
+
+  ClearModules();
+  fLoader->WriteRecPoints("OVERWRITE");
+  delete ptarray;
+}
+//_____________________________________________________________________
+Int_t AliITSUpg::Hits2Clusters(TTree *hTree, TTree *cTree) {
+  //------------------------------------------------------------
+  // This function creates ITS clusters
+  //------------------------------------------------------------
+  if(!GetITSgeom()){
+    Error("HitsToPreDigits","fGeom is null!");
+    return 1; // need transformations to do digitization.
+  }
+  AliITSgeom *geom=GetITSgeom();
+  Int_t mmax=geom->GetIndexMax();
+
+  InitModules(-1,mmax);
+  FillModules(hTree,0);
+
+  TClonesArray *points = new TClonesArray("AliITSRecPoint",1000);
+  TBranch *branch=cTree->GetBranch("ITSRecPoints");
+  if (!branch) cTree->Branch("ITSRecPoints",&points);
+  else branch->SetAddress(&points);
+
+  AliITSsimulationFastPoints sim;
+  Int_t ncl=0;
+  for (Int_t m=0; m<mmax; m++) {
+    AliITSmodule *mod=GetModule(m);      
+    sim.CreateFastRecPoints(mod,m,gRandom,points);      
+    ncl+=points->GetEntriesFast();
+    cTree->Fill();
+    points->Clear();
+  }
+
+  AliDebug(1,Form("Number of found fast clusters : %d",ncl));
+
+  //cTree->Write();
+
+  delete points;
+  return 0;
+}
+
+//_____________________________________________________________________
+void AliITSUpg::CheckLabels(Int_t lab[3]) const {
+  //------------------------------------------------------------
+  // Tries to find mother's labels
+  //------------------------------------------------------------
+
+  if(lab[0]<0 && lab[1]<0 && lab[2]<0) return; // In case of no labels just exit
+
+  Int_t ntracks = gAlice->GetMCApp()->GetNtrack();
+  for (Int_t i=0;i<3;i++){
+    Int_t label = lab[i];
+    if (label>=0 && label<ntracks) {
+      TParticle *part=(TParticle*)gAlice->GetMCApp()->Particle(label);
+      if (part->P() < 0.005) {
+       Int_t m=part->GetFirstMother();
+       if (m<0) {      
+         continue;
+       }
+       if (part->GetStatusCode()>0) {
+         continue;
+       }
+       lab[i]=m;       
+      }
+    }    
+  }
+  
+}
+
+//______________________________________________________________________
+void AliITSUpg::SDigitsToDigits(Option_t *opt){
+  // Standard Summable digits to Digits function.
+  // Inputs:
+  //      none.
+  // Outputs:
+  //      none.
+  if (!fDetTypeSim) {
+    AliError("fDetTypeSim is 0!");
+    return;
+  }
+  const char *all = strstr(opt,"All");
+  const char *det[3] ={strstr(opt,"SPD"),strstr(opt,"SDD"),
+                      strstr(opt,"SSD")};
+
+  // Reset Fast-OR signals for this event
+//  fDetTypeSim->ResetFOSignals();
+
+  fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
+  SetDefaults();
+  if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
+  fDetTypeSim->SDigitsToDigits(opt,(Char_t*)GetName());
+
+  // Add Fast-OR signals to event (only one object per event)
+  if (all || det[0]) { // SPD present
+   WriteFOSignals();
+  }
+}
+
+//______________________________________________________________________
+void AliITSUpg::ResetDigits(){
+    // Reset number of digits and the digits array for the ITS detector.
+    // Inputs:
+    //      none.
+    // Outputs:
+    //      none.
+    if(!fDetTypeSim) {
+      Error("ResetDigits","fDetTypeSim is 0!");
+      return;
+    }
+   
+    fDetTypeSim->ResetDigits();
+
+
+}
+//______________________________________________________________________
+void AliITSUpg::ResetDigits(Int_t branch){
+    // Reset number of digits and the digits array for this branch.
+    // Inputs:
+    //      none.
+    // Outputs:
+    //      none.
+
+    if(!fDetTypeSim) {
+      Error("ResetDigits","fDetTypeSim is 0!");
+      return;
+    }
+   
+    fDetTypeSim->ResetDigits(branch);
+
+}
+//______________________________________________________________________
+void AliITSUpg::AddSumDigit(AliITSpListItem &sdig){
+    // Adds the a module full of summable digits to the summable digits tree.
+    // Inputs:
+    //      AliITSpListItem &sdig   SDigit to be added to SDigits tree.
+    // Outputs:
+    //      none.
+    // Return:
+    //      none.
+
+    if(!fDetTypeSim) {
+      Error("AddSumDigit","fDetTypeSim is 0!");
+      return;
+    }
+    fDetTypeSim->AddSumDigit(sdig);
+    
+}
+//______________________________________________________________________
+void AliITSUpg::AddSimDigit(Int_t branch, AliITSdigit *d){
+    //    Add a simulated digit.
+    // Inputs:
+    //      Int_t id        Detector type number.
+    //      AliITSdigit *d  Digit to be added to the Digits Tree. See 
+    //                      AliITSdigit.h
+    // Outputs:
+    //      none.
+    // Return:
+    //      none.
+
+    if(!fDetTypeSim) {
+      Error("AddSimDigit","fDetTypeSim is 0!");
+      return;
+    }
+    fDetTypeSim->AddSimDigit(branch,d);
+
+}
+//______________________________________________________________________
+void AliITSUpg::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.
+  // Inputs:
+  //      Int_t id        Detector type number.
+  //      Float_t phys    Physics indicator. See AliITSdigits.h
+  //      Int_t *digits   Integer array containing the digits info. See 
+  //                      AliITSdigit.h
+  //      Int_t *tracks   Integer array [AliITSdigitS?D::GetNTracks()] 
+  //                      containing the track numbers that contributed to
+  //                      this digit.
+  //      Int_t *hits     Integer array [AliITSdigitS?D::GetNTracks()]
+  //                      containing the hit numbers, from AliITSmodule, that
+  //                      contributed to this digit.
+  //      Float_t *charge Floating point array of the signals contributed
+  //                      to this digit by each track.
+  // Outputs:
+  //      none.
+  // Return:
+  //      none.
+
+    if(!fDetTypeSim) {
+      Error("AddSimDigit","fDetTypeSim is 0!");
+      return;
+    }
+    fDetTypeSim->AddSimDigit(branch,phys,digits,tracks,hits,charges,sigexpanded);
+
+}
+//______________________________________________________________________
+void AliITSUpg::Digits2Raw(){
+    // convert digits of the current event to raw data
+
+  if(!fDetTypeSim) {
+    Error("Digits2Raw","fDetTypeSim is 0!");
+    return;
+  }
+  fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
+  SetDefaults();
+  if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
+  fDetTypeSim->GetLoader()->LoadDigits();
+  TTree* digits = fDetTypeSim->GetLoader()->TreeD();
+  if (!digits) {
+      Error("Digits2Raw", "no digits tree");
+      return;
+  }
+  fDetTypeSim->SetTreeAddressD(digits,(Char_t*)GetName());
+  
+   // Get the FO signals for this event
+  AliITSFOSignalsSPD* foSignals = NULL;
+  AliRunLoader* runLoader = AliRunLoader::Instance();
+  AliITSLoaderUpg* itsLoader = (AliITSLoaderUpg*) runLoader->GetLoader("ITSLoader");
+  if (!itsLoader) {
+    AliError("ITS loader is NULL.");
+  }
+   else {
+      if(!itsLoader->TreeD()) AliError("   !!! No TreeD available !!!");
+      foSignals = (AliITSFOSignalsSPD*)itsLoader->TreeD()->GetUserInfo()->FindObject("AliITSFOSignalsSPD");
+      if(!foSignals) AliError("FO signals not retrieved");
+     }
+  Bool_t deleteFOsignalsLater = kFALSE;
+  if (!foSignals) {
+    AliError("FO signals not available. No FO bits will be written.");
+    foSignals = new AliITSFOSignalsSPD(); // make a temporary dummy signals object
+    deleteFOsignalsLater = kTRUE;
+  }
+  
+  
+//  AliITSDDLModuleMapSDD* ddlsdd=fDetTypeSim->GetDDLModuleMapSDD();
+  Char_t rawSDD=fDetTypeSim->GetSimuParam()->GetSDDRawDataFormat();
+  AliITSDDLRawData rawWriter;
+  
+  rawWriter.SetSDDRawFormat(rawSDD);
+  //Verbose level
+  // 0: Silent
+  // 1: cout messages
+  // 2: txt files with digits 
+  //BE CAREFUL, verbose level 2 MUST be used only for debugging and
+  //it is highly suggested to use this mode only for debugging digits files
+  //reasonably small, because otherwise the size of the txt files can reach
+  //quickly several MB wasting time and disk space.
+  rawWriter.SetVerbose(0);
+    
+  //SILICON PIXEL DETECTOR
+  AliDebug(1,"Formatting raw data for SPD");
+  rawWriter.RawDataSPD(digits->GetBranch("ITSDigitsSPD"),foSignals);
+  if(deleteFOsignalsLater) delete foSignals;
+    
+  //SILICON DRIFT DETECTOR
+  AliDebug(1,Form("Formatting raw data for SDD - Format code =%d",rawSDD));
+//  rawWriter.RawDataSDD(digits->GetBranch("ITSDigitsSDD"),ddlsdd);
+    
+  //SILICON STRIP DETECTOR
+  AliDebug(1,"Formatting raw data for SSD");
+  rawWriter.RawDataSSD(digits->GetBranch("ITSDigitsSSD"));
+
+  fLoader->UnloadDigits();
+}
+//______________________________________________________________________
+AliLoader* AliITSUpg::MakeLoader(const char* topfoldername){ 
+    //builds ITSgetter (AliLoader type)
+    //if detector wants to use castomized getter, it must overload this method
+
+    AliDebug(1,Form("Creating AliITSLoaderUpg. Top folder is %s.",
+         topfoldername));
+    fLoader = new AliITSLoaderUpg(GetName(),topfoldername);
+    return fLoader;
+}
+//______________________________________________________________________
+Bool_t AliITSUpg::Raw2SDigits(AliRawReader* rawReader)
+{
+  //
+  // Converts RAW data to SDigits
+  //
+  // Get TreeS
+  //
+  Int_t last   = -1;
+  Int_t size   = AliITSgeomTGeo::GetNModules();
+  if(!fModA) {
+    fModA = new TClonesArray*[size];
+    for (Int_t mod = 0; mod < size; mod++) fModA[mod] = new TClonesArray("AliITSpListItem", 10000);
+  }
+  AliLoader* loader =  (AliRunLoader::Instance())->GetLoader("ITSLoader");
+  if (!loader){
+    Error("Open","Can not get ITS loader from Run Loader");
+    return kFALSE;
+  }
+
+  TTree* tree = 0;
+  tree = loader->TreeS();
+  if (!tree){
+    loader->MakeTree("S");
+    tree = loader->TreeS();
+  }
+  //
+  // Array for SDigits
+  // 
+  if(!fpSDigits){
+    fpSDigits = new TClonesArray("AliITSpListItem",10000);
+  }
+  TClonesArray& aSDigits = *fpSDigits;
+  Int_t bufsize = 32000;
+  tree->Branch("ITS", &fpSDigits, bufsize);
+  Int_t npx = 0;
+  //
+  // SPD
+  //
+  AliITSsegmentationSPD* segSPD = (AliITSsegmentationSPD*) fDetTypeSim->GetSegmentationModel(0);
+  if(!segSPD){
+    AliWarning("Set AliITS defaults");
+    SetDefaults();
+    segSPD = (AliITSsegmentationSPD*) fDetTypeSim->GetSegmentationModel(0);
+  }
+  npx = segSPD->Npx();
+  Double_t thr, sigma; 
+    
+  AliITSRawStreamSPD inputSPD(rawReader);
+  while(1){
+    Bool_t next  = inputSPD.Next();
+    if (!next) break;
+
+    Int_t module = inputSPD.GetModuleID();
+    Int_t column = inputSPD.GetColumn();
+    Int_t row    = inputSPD.GetRow();
+    Int_t index  = npx * column + row;
+
+    if (module >= size) continue;
+    last = (fModA[module])->GetEntries();
+    TClonesArray& dum = *fModA[module];
+    fDetTypeSim->GetSimuParam()->SPDThresholds(module,thr,sigma);
+    thr += 1.;
+    new (dum[last]) AliITSpListItem(-1, -1, module, index, thr);
+  }
+  rawReader->Reset();
+
+  //
+  // SDD
+  // 
+  AliITSsegmentationSDD* segSDD = (AliITSsegmentationSDD*) fDetTypeSim->GetSegmentationModel(1);
+  npx = segSDD->Npx();
+  Int_t scalef=AliITSsimulationSDD::ScaleFourier(segSDD);
+  Int_t firstSDD=AliITSgeomTGeo::GetModuleIndex(3,1,1);
+  Int_t firstSSD=AliITSgeomTGeo::GetModuleIndex(5,1,1);
+
+  AliITSRawStream* inputSDD=AliITSRawStreamSDD::CreateRawStreamSDD(rawReader);
+  for(Int_t iMod=firstSDD; iMod<firstSSD; iMod++){
+    AliITSCalibrationSDD* cal = (AliITSCalibrationSDD*)fDetTypeSim->GetCalibrationModel(iMod);
+    Bool_t isZeroSupp=cal->GetZeroSupp();
+    if(isZeroSupp){ 
+      for(Int_t iSid=0; iSid<2; iSid++) inputSDD->SetZeroSuppLowThreshold(iMod-firstSDD,iSid,cal->GetZSLowThreshold(iSid));
+    }else{
+      for(Int_t iSid=0; iSid<2; iSid++) inputSDD->SetZeroSuppLowThreshold(iMod-firstSDD,iSid,0);
+    }
+  }
+
+//  AliITSDDLModuleMapSDD* ddlmap=fDetTypeSim->GetDDLModuleMapSDD();
+//  inputSDD->SetDDLModuleMap(ddlmap);
+  while(inputSDD->Next()){
+    if(inputSDD->IsCompletedModule()==kFALSE && 
+       inputSDD->IsCompletedDDL()==kFALSE){
+
+      Int_t module = inputSDD->GetModuleID();
+      Int_t anode  = inputSDD->GetCoord1()+segSDD->NpzHalf()*inputSDD->GetChannel();
+      Int_t time   = inputSDD->GetCoord2();
+      Int_t signal10 = inputSDD->GetSignal();
+      Int_t index = AliITSpList::GetIndex(anode,time,scalef*npx);
+
+      if (module >= size) continue;
+      last = fModA[module]->GetEntries();
+      TClonesArray& dum = *fModA[module];
+      new (dum[last]) AliITSpListItem(-1, -1, module, index, Double_t(signal10));
+      ((AliITSpListItem*) dum.At(last))->AddSignalAfterElect(module, index, Double_t(signal10));
+    }
+  }
+  delete inputSDD;
+  rawReader->Reset();
+    
+  //
+  // SSD
+  // 
+  AliITSsegmentationSSD* segSSD = (AliITSsegmentationSSD*) fDetTypeSim->GetSegmentationModel(2);
+  npx = segSSD->Npx();
+  AliITSRawStreamSSD inputSSD(rawReader);
+  while(1){
+    Bool_t next  = inputSSD.Next();
+    if (!next) break;
+
+    Int_t module  = inputSSD.GetModuleID();
+    if(module<0)AliError(Form("Invalid SSD  module %d \n",module));
+    if(module<0)continue;
+    Int_t side    = inputSSD.GetSideFlag();
+    Int_t strip   = inputSSD.GetStrip();
+    Int_t signal  = inputSSD.GetSignal();
+    Int_t index  = npx * side + strip;
+
+    if (module >= size) continue;
+       
+    last = fModA[module]->GetEntries();
+    TClonesArray& dum = *fModA[module];
+    new (dum[last]) AliITSpListItem(-1, -1, module, index, Double_t(signal));
+  }
+  rawReader->Reset();
+  AliITSpListItem* sdig = 0;
+    
+  Int_t firstssd = GetITSgeom()->GetStartDet(kSSD);
+  Double_t adcToEv = 1.;
+  for (Int_t mod = 0; mod < size; mod++)
+    {
+      if(mod>=firstssd) {
+       AliITSCalibrationSSD* calssd = (AliITSCalibrationSSD*)fDetTypeSim->GetCalibrationModel(mod);
+       adcToEv = 1./calssd->GetSSDDEvToADC(1.);
+      }
+      Int_t nsdig =  fModA[mod]->GetEntries();
+      for (Int_t ie = 0; ie < nsdig; ie++) {
+       sdig = (AliITSpListItem*) (fModA[mod]->At(ie));
+       Double_t digsig = sdig->GetSignal();
+       if(mod>=firstssd) digsig*=adcToEv; // for SSD: convert back charge from ADC to electron
+       new (aSDigits[ie]) AliITSpListItem(-1, -1, mod, sdig->GetIndex(), digsig);
+       Float_t sig = sdig->GetSignalAfterElect();
+       if(mod>=firstssd) sig*=adcToEv;
+       if (sig > 0.) {
+         sdig = (AliITSpListItem*)aSDigits[ie];
+         sdig->AddSignalAfterElect(mod, sdig->GetIndex(), Double_t(sig));
+       }
+      }
+       
+      tree->Fill();
+      aSDigits.Clear();
+      fModA[mod]->Clear();
+    }
+  loader->WriteSDigits("OVERWRITE");    
+  return kTRUE;
+}
+
+//______________________________________________________________________
+void AliITSUpg::UpdateInternalGeometry(){
+  //reads new geometry from TGeo 
+//   AliDebug(1,"Delete ITSgeom and create a new one reading TGeo");
+
+  AliITSVersion_t version = (AliITSVersion_t)IsVersion();
+  Int_t minor = 0;
+  AliITSInitGeometryUpg initgeom;
+  AliITSgeom* geom = initgeom.CreateAliITSgeom(version,minor);
+  SetITSgeom(geom);
+}
+//______________________________________________________________________
+AliTriggerDetector* AliITSUpg::CreateTriggerDetector() const {
+  // create an AliITSTrigger object (and set trigger conditions as input)
+  return new AliITSTrigger(fDetTypeSim->GetTriggerConditions());
+}
+//______________________________________________________________________
+void AliITSUpg::WriteFOSignals(){
+// This method write FO signals in Digits tree both in Hits2Digits
+// or SDigits2Digits
+
+//  fDetTypeSim->ProcessNoiseForFastOr();
+  fDetTypeSim->WriteFOSignals();
+}
diff --git a/ITS/UPGRADE/AliITSUpg.h b/ITS/UPGRADE/AliITSUpg.h
new file mode 100644 (file)
index 0000000..aed02f1
--- /dev/null
@@ -0,0 +1,175 @@
+#ifndef ALIITSUPG_H
+#define ALIITSUPG_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* $Id: AliITSUpg.h */
+
+////////////////////////////////////////////////////////////////////////
+//           Manager class for set: ITS Upgrade                       //
+////////////////////////////////////////////////////////////////////////
+
+
+#include <TObjArray.h> // used in inline function GetModule.
+#include "AliDetector.h"
+#include "AliITSTrigger.h"
+#include "AliITSDetTypeSim.h"
+
+
+class TString;
+class TTree;
+class AliITSpListItem;
+class AliITSsimulation;
+class AliITSsegmentation;
+
+class AliITSCalibration;
+class AliITShit;
+class AliITSgeom;
+class AliITSdigit;
+class AliITSmodule;
+class AliRunDigitizer;
+
+
+class AliITSUpg : public AliDetector {
+
+ public:
+    //================= Standard Classes ===============================
+    AliITSUpg();  // Default creator.
+    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;}
+
+    //===================== Simulation Geometry ========================
+    // get geometry version - detailed (major) or coarse (minor)
+    virtual Int_t GetMajorVersion() const {return -1;}
+    virtual Int_t GetMinorVersion() const {return -1;}
+    virtual void  GetGeometryVersion(Int_t &a,Int_t &b) const
+                          {a = GetMajorVersion();b=GetMinorVersion();return;}
+    virtual void  SetEUCLID(Bool_t euclid=kTRUE) {fEuclidOut = euclid;}
+    virtual Bool_t GetEUCLID()const {return fEuclidOut;}
+    //-------------------- Geometry Transformations --------------------
+
+    // ITS geometry functions From Simulation
+    AliITSgeom* GetITSgeom() const {return fDetTypeSim->GetITSgeom();}
+    void   SetITSgeom(AliITSgeom *geom) {fDetTypeSim->SetITSgeom(geom);}
+    // return pointer to the array of modules
+    TObjArray *GetModules(){return fITSmodules;}
+
+    AliITSmodule *GetModule(Int_t index){
+        return (AliITSmodule*)(fITSmodules->At(index));}
+    virtual void SetSimuParam(AliITSSimuParam *sp){
+      fSimuParam=sp;
+      fDetTypeSim->SetSimuParam(sp);
+    }
+    AliITSSimuParam* GetSimuParam() const {return fSimuParam;}
+
+    virtual void SetDetTypeSim(AliITSDetTypeSim* dts) {fDetTypeSim=dts;}
+    AliITSDetTypeSim* GetDetTypeSim() const {return fDetTypeSim;}
+    //================ Necessary general Classes =======================
+    virtual void Init();
+    virtual AliLoader* MakeLoader(const char* topfoldername);
+    virtual void SetDefaults();
+    virtual void SetDefaultSimulation();
+    virtual void MakeBranch(Option_t *opt=" ");
+    virtual void MakeBranchS(const char* fl);
+    virtual void MakeBranchD(const char* file);
+    virtual void MakeBranchInTreeD(TTree* treeD, const char* file=0);
+    virtual void SetTreeAddress();
+     //---------- Configuration Methods (per detector type) -------------
+    // Determines which ITS subdetectors will be processed. Effects
+    // digitization, and Reconstruction only.
+    void SetDetectors(Option_t *opt="All"){fOpt = opt;}
+    // Returns the list of ITS subdetectors that will be processed.
+    Option_t* GetDetectors(){return fOpt;}
+
+    // Set calibration
+    virtual void SetCalibrationModel(Int_t dettype, AliITSCalibration *cal){
+        fDetTypeSim->SetCalibrationModel(dettype,cal);}
+    // Set segmentation for Simulation
+    virtual void SetSegmentationModel(Int_t id, AliITSsegmentation *seg){
+        fDetTypeSim->SetSegmentationModel(id,seg);}
+    // Set simulation 
+    virtual void SetSimulationModel(Int_t id, AliITSsimulation *sim){
+        fDetTypeSim->SetSimulationModel(id,sim);}
+    // Set simulation 
+    virtual AliITSsimulation* GetSimulationModel(Int_t id){
+       return fDetTypeSim->GetSimulationModel(id);}
+    //=================== Hits =========================================
+    virtual void StepManager() {} // See Step Manager for specific geometry.
+    //------------ sort hits by module for Digitisation ----------------
+    virtual void FillModules(Int_t /* evnt */,Int_t bgrev,Int_t /* nmodules */,
+                            Option_t *opt, const char *filename); 
+    virtual Bool_t InitModules(Int_t size,Int_t &nmodules);  
+    virtual void FillModules(TTree *treeH, Int_t mask = 0);
+    virtual void ClearModules(){if(fITSmodules) fITSmodules->Delete();}
+    virtual void AddHit(Int_t track, Int_t *vol, Float_t *hits);
+   // Trigger
+    virtual AliTriggerDetector* CreateTriggerDetector() const;
+
+    AliDigitizer* CreateDigitizer(AliRunDigitizer* manager) const;
+    virtual void UpdateInternalGeometry();
+    virtual void SDigitsToDigits(Option_t *opt="All");
+    virtual void SDigits2Digits(){SDigitsToDigits("All");}
+    virtual void Hits2Digits(); 
+    virtual void Hits2SDigits();
+    virtual void Hits2PreDigits();
+    virtual void HitsToDigits(Int_t evNumber,Int_t bgrev,Int_t size,
+                          Option_t *option,Option_t *opt,
+                          const char *filename);
+    virtual void HitsToPreDigits(Int_t evNumber,Int_t bgrev,Int_t size,
+                             Option_t *option,Option_t *opt,
+                             const char *filename);
+    void HitsToSDigits(Int_t evNumber,Int_t bgrev,Int_t size,
+                       Option_t *add, Option_t *det, const char *filename)
+      {HitsToPreDigits(evNumber,bgrev,size,add,det,filename);}
+    
+    virtual void ResetDigits();
+    virtual void ResetDigits(Int_t branch);
+    virtual void AddSumDigit(AliITSpListItem &sdig);
+    virtual void AddSimDigit(Int_t branch, 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);
+    TObjArray* GetDigits()  const {return fDetTypeSim->GetDigits();}
+    Int_t* GetNDigitArray() const {return fDetTypeSim->GetNDigitArray();}
+    TClonesArray *DigitsAddress(Int_t id) {
+       return fDetTypeSim->DigitsAddress(id);}
+    //Fast simulation
+    virtual void HitsToFastRecPoints(Int_t evNumber,Int_t bgrev,Int_t size,
+                 Option_t *add, Option_t *det, const char *filename);
+    virtual Int_t Hits2Clusters(TTree *in, TTree *out);
+    virtual void CheckLabels(Int_t lab[3]) const;
+
+    //===================== Raw Data IO ================================
+    // Write digits into raw data format
+    virtual void   Digits2Raw();
+    virtual Bool_t Raw2SDigits(AliRawReader*);
+    
+    //===================== FO signals ================================
+    // Write FO signals in UserInfo of SDigits/Digits tree
+    void WriteFOSignals();
+
+ protected:
+    static const Int_t fgkNTYPES=3; //number of detector types
+    //================== Data Members ==================================
+    AliITSDetTypeSim *fDetTypeSim; //detector type for simulation
+    Bool_t        fEuclidOut;  // Flag to write geometry in euclid format
+    Option_t     *fOpt;        //! Detector option ="All" unless changed.
+    Int_t         fIdN;        // the number of layers
+    Int_t        *fIdSens;     //[fIdN] layer identifier
+    TString      *fIdName;     //[fIdN] layer identifier
+    TObjArray    *fITSmodules; //! Pointer to ITS modules
+    Bool_t        fTiming;     // flag to turn on/off timers.
+    AliITSSimuParam* fSimuParam; //simulation parameters
+    TClonesArray** fModA;      //! Used by Raw2SDigits (one TC per module)
+    TClonesArray* fpSDigits;   //! Branch address to build SD from raw data 
+
+ private:
+    AliITSUpg(const AliITSUpg &source); // copy constructor. Not to be used!
+    AliITSUpg& operator=(const AliITSUpg &source); // = operator. Not to be used!
+    ClassDef(AliITSUpg,1) // Base class for ITS
+
+};
+
+#endif
diff --git a/ITS/UPGRADE/AliITSv11GeometryUpgrade.cxx b/ITS/UPGRADE/AliITSv11GeometryUpgrade.cxx
new file mode 100644 (file)
index 0000000..6e547e7
--- /dev/null
@@ -0,0 +1,531 @@
+/**************************************************************************
+ * 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.                  *
+ **************************************************************************/
+
+//*************************************************************************
+// This class Defines the Geometry for the ITS Upgrade using TGeo
+// This is a work class used to study different configurations
+// during the development of the new ITS structure.
+//
+//  Mario Sitta <sitta@to.infn.it>
+//*************************************************************************
+
+
+/* $Id: AliITSv11GeometryUpgrade.cxx  */
+// General Root includes
+#include <TMath.h>
+// Root Geometry includes
+//#include <AliLog.h>
+#include <TGeoManager.h>
+#include <TGeoVolume.h>
+#include <TGeoPcon.h>
+#include <TGeoCone.h>
+#include <TGeoTube.h> // contaings TGeoTubeSeg
+#include <TGeoArb8.h>
+#include <TGeoXtru.h>
+#include <TGeoCompositeShape.h>
+#include <TGeoMatrix.h>
+#include "AliITSv11GeometryUpgrade.h"
+
+const Double_t AliITSv11GeometryUpgrade::fgkDefaultSensorThick = 300*fgkmicron;
+const Double_t AliITSv11GeometryUpgrade::fgkDefaultLadderThick =   1*fgkcm;
+
+ClassImp(AliITSv11GeometryUpgrade)
+
+#define SQ(A) (A)*(A)
+
+//________________________________________________________________________
+AliITSv11GeometryUpgrade::AliITSv11GeometryUpgrade(): 
+  AliITSv11Geometry(),
+  fLayerNumber(0),
+  fLayRadius(0),
+  fZLength(0),
+  fSensorThick(0),
+  fLadderThick(0),
+  fLadderWidth(0),
+  fLadderTilt(0),
+  fNLadders(0),
+  fNModules(0),
+  fIsTurbo(0)
+{
+  //
+  // Standard constructor
+  //
+}
+
+//________________________________________________________________________
+AliITSv11GeometryUpgrade::AliITSv11GeometryUpgrade(Int_t debug): 
+  AliITSv11Geometry(debug),
+  fLayerNumber(0),
+  fLayRadius(0),
+  fZLength(0),
+  fSensorThick(0),
+  fLadderThick(0),
+  fLadderWidth(0),
+  fLadderTilt(0),
+  fNLadders(0),
+  fNModules(0),
+  fIsTurbo(0)
+{
+  //
+  // Constructor setting debugging level
+  //
+}
+
+//________________________________________________________________________
+AliITSv11GeometryUpgrade::AliITSv11GeometryUpgrade(Int_t lay, Int_t debug): 
+  AliITSv11Geometry(debug),
+  fLayerNumber(lay),
+  fLayRadius(0),
+  fZLength(0),
+  fSensorThick(0),
+  fLadderThick(0),
+  fLadderWidth(0),
+  fLadderTilt(0),
+  fNLadders(0),
+  fNModules(0),
+  fIsTurbo(0)
+{
+  //
+  // Constructor setting layer number and debugging level
+  //
+}
+
+//________________________________________________________________________
+AliITSv11GeometryUpgrade::AliITSv11GeometryUpgrade(Int_t lay, Bool_t turbo, Int_t debug): 
+  AliITSv11Geometry(debug),
+  fLayerNumber(lay),
+  fLayRadius(0),
+  fZLength(0),
+  fSensorThick(0),
+  fLadderThick(0),
+  fLadderWidth(0),
+  fLadderTilt(0),
+  fNLadders(0),
+  fNModules(0),
+  fIsTurbo(turbo)
+{
+  //
+  // Constructor setting layer number and debugging level
+  // for a "turbo" layer (i.e. where ladders overlap in phi)
+  //
+}
+
+//________________________________________________________________________
+AliITSv11GeometryUpgrade::AliITSv11GeometryUpgrade(const AliITSv11GeometryUpgrade &s):
+  AliITSv11Geometry(s.GetDebug()),
+  fLayerNumber(s.fLayerNumber),
+  fLayRadius(s.fLayRadius),
+  fZLength(s.fZLength),
+  fSensorThick(s.fSensorThick),
+  fLadderThick(s.fLadderThick),
+  fLadderWidth(s.fLadderWidth),
+  fLadderTilt(s.fLadderTilt),
+  fNLadders(s.fNLadders),
+  fNModules(s.fNModules),
+  fIsTurbo(s.fIsTurbo)
+{
+  //
+  // Copy constructor
+  //
+}
+
+//________________________________________________________________________
+AliITSv11GeometryUpgrade& AliITSv11GeometryUpgrade::operator=(const AliITSv11GeometryUpgrade &s)
+{
+  //
+  // Assignment operator 
+  //
+  if(&s == this) return *this;
+
+  fLayerNumber = s.fLayerNumber;
+  fLayRadius   = s.fLayRadius;
+  fZLength     = s.fZLength;
+  fSensorThick = s.fSensorThick;
+  fLadderThick = s.fLadderThick;
+  fLadderWidth = s.fLadderWidth;
+  fLadderTilt  = s.fLadderTilt;
+  fNLadders    = s.fNLadders;
+  fNModules    = s.fNModules;
+  fIsTurbo     = s.fIsTurbo;
+
+  return *this;
+}
+
+//________________________________________________________________________
+AliITSv11GeometryUpgrade::~AliITSv11GeometryUpgrade() {
+  //
+  // Destructor
+  //
+}
+
+//________________________________________________________________________
+void AliITSv11GeometryUpgrade::CreateLayer(TGeoVolume *moth,
+                                    const TGeoManager *mgr){
+//
+// Creates the actual Layer and places inside its mother volume
+//
+// Input:
+//         moth : the TGeoVolume owing the volume structure
+//         mgr  : the GeoManager (used only to get the proper material)
+//
+// Output:
+//
+// Return:
+//
+// Created:      17 Jun 2011  Mario Sitta
+// Updated:      08 Jul 2011  Mario Sitta
+//
+
+
+  // Local variables
+  char volname[30];
+  Double_t rmin, rmax;
+  Double_t xpos, ypos, zpos;
+  Double_t alpha;
+
+
+  // Check if the user set the proper parameters
+  if (fLayRadius <= 0) AliFatal(Form("Wrong layer radius (%f)",fLayRadius));
+  if (fZLength   <= 0) AliFatal(Form("Wrong layer length (%f)",fZLength));
+  if (fNLadders  <= 0) AliFatal(Form("Wrong number of ladders (%d)",fNLadders));
+  if (fNModules  <= 0) AliFatal(Form("Wrong number of modules (%d)",fNModules));
+
+  if (fLadderThick <= 0) {
+    AliInfo(Form("Ladder thickness wrong or not set (%f), using default (%f)",
+                fLadderThick,fgkDefaultLadderThick));
+    fLadderThick = fgkDefaultLadderThick;
+  }
+
+  if (fSensorThick <= 0) {
+    AliInfo(Form("Sensor thickness wrong or not set (%f), using default (%f)",
+                fSensorThick,fgkDefaultSensorThick));
+    fSensorThick = fgkDefaultSensorThick;
+  }
+
+  if (fSensorThick > fLadderThick) {
+    AliWarning(Form("Sensor thickness (%f) is greater than ladder thickness (%f), fixing",
+                fSensorThick,fLadderThick));
+    fSensorThick = fLadderThick;
+  }
+
+
+  // If a Turbo layer is requested, do it and exit
+  if (fIsTurbo) {
+    CreateLayerTurbo(moth, mgr);
+    return;
+  }
+
+
+  // First create the ladder container
+  alpha = (360./(2*fNLadders))*TMath::DegToRad();
+  fLadderWidth = fLayRadius*TMath::Tan(alpha);
+
+  rmin = 0.98*fLayRadius;
+  rmax = 1.02*TMath::Sqrt( fLadderWidth*fLadderWidth +
+                         (rmin+fLadderThick)*(rmin+fLadderThick) );
+
+  TGeoTube *layer = new TGeoTube(rmin, rmax, 0.5*fZLength);
+
+
+  // We have all shapes: now create the real volumes
+  TGeoMedium *medAir = mgr->GetMedium("ITS_AIR$");
+
+  snprintf(volname, 30, "ITSupgLayer%d", fLayerNumber);
+  TGeoVolume *layVol = new TGeoVolume(volname, layer, medAir);
+
+//  layVol->SetVisibility(kFALSE);
+  layVol->SetVisibility(kTRUE);
+  layVol->SetLineColor(1);
+
+  TGeoVolume *laddVol = CreateLadder();
+
+
+  // Now build up the layer
+  alpha = 360./fNLadders;
+  Double_t r = fLayRadius + ((TGeoBBox*)laddVol->GetShape())->GetDY();
+  for (Int_t j=0; j<fNLadders; j++) {
+    Double_t theta = j*alpha;
+    xpos = r*SinD(theta);
+    ypos = r*CosD(theta);
+    zpos = 0.;
+    layVol->AddNode(laddVol, j+1, new TGeoCombiTrans( xpos, ypos, zpos,
+                                 new TGeoRotation("",-theta,0,0)));
+  }
+
+
+  // Finally put everything in the mother volume
+  moth->AddNode(layVol, 1, 0);
+
+
+  // Upgrade geometry is served
+  return;
+}
+
+//________________________________________________________________________
+void AliITSv11GeometryUpgrade::CreateLayerTurbo(TGeoVolume *moth,
+                                         const TGeoManager *mgr){
+//
+// Creates the actual Layer and places inside its mother volume
+// A so-called "turbo" layer is a layer where ladders overlap in phi
+// User can set width and tilt angle, no check is performed here
+// to avoid volume overlaps
+//
+// Input:
+//         moth : the TGeoVolume owing the volume structure
+//         mgr  : the GeoManager (used only to get the proper material)
+//
+// Output:
+//
+// Return:
+//
+// Created:      08 Jul 2011  Mario Sitta
+//
+
+
+  // Local variables
+  char volname[30];
+  Double_t rmin, rmax, rladd, d;
+  Double_t xpos, ypos, zpos;
+  Double_t alpha, gamma;
+
+
+  // Check if the user set the proper (remaining) parameters
+  if (fLadderWidth <= 0)
+    AliFatal(Form("Wrong ladder width (%f)",fLadderWidth));
+  if (TMath::Abs(fLadderTilt) > 45)
+    AliWarning(Form("Ladder tilt angle (%f) greater than 45deg",fLadderTilt));
+
+
+  // First create the ladder container
+  // d is half the diagonal of the ladder section
+  // rladd is the radius at the ladder's center-of-gravity
+  // alpha here is the angle between the diagonal and the ladder basis
+  d = 0.5*TMath::Sqrt(fLadderThick*fLadderThick + fLadderWidth*fLadderWidth);
+  alpha = TMath::ACos(0.5*fLadderThick/d)*TMath::RadToDeg();
+  gamma = 90. - alpha - fLadderTilt;
+  rladd = fLayRadius + 0.5*fLadderThick;
+
+  rmin = 0.98*TMath::Sqrt( rladd*rladd + d*d - 2*rladd*d*CosD(gamma) );
+  rmax = 1.02*TMath::Sqrt( rladd*rladd + d*d + 2*rladd*d*CosD(gamma) );
+
+  TGeoTube *layer = new TGeoTube(rmin, rmax, 0.5*fZLength);
+
+
+  // We have all shapes: now create the real volumes
+  TGeoMedium *medAir = mgr->GetMedium("ITS_AIR$");
+
+  snprintf(volname, 30, "ITSupgLayer%d", fLayerNumber);
+  TGeoVolume *layVol = new TGeoVolume(volname, layer, medAir);
+
+//  layVol->SetVisibility(kFALSE);
+  layVol->SetVisibility(kTRUE);
+  layVol->SetLineColor(1);
+
+  TGeoVolume *laddVol = CreateLadder();
+
+
+  // Now build up the layer
+
+
+  // Now build up the layer
+  alpha = 360./fNLadders;
+  Double_t r = fLayRadius + ((TGeoBBox*)laddVol->GetShape())->GetDY();
+  for (Int_t j=0; j<fNLadders; j++) {
+    Double_t theta = j*alpha;
+    xpos = r*SinD(theta);
+    ypos = r*CosD(theta);
+    zpos = 0.;
+    layVol->AddNode(laddVol, j+1, new TGeoCombiTrans( xpos, ypos, zpos,
+                                new TGeoRotation("",-theta+fLadderTilt,0,0)));
+  }
+
+
+  // Finally put everything in the mother volume
+  moth->AddNode(layVol, 1, 0);
+
+  return;
+}
+
+//________________________________________________________________________
+TGeoVolume* AliITSv11GeometryUpgrade::CreateLadder(const TGeoManager *mgr){
+//
+// Creates the actual Ladder
+//
+// Input:
+//         mgr  : the GeoManager (used only to get the proper material)
+//
+// Output:
+//
+// Return:
+//
+// Created:      22 Jun 2011  Mario Sitta
+//
+
+  char volname[30];
+  Double_t xlen, ylen, zlen;
+  Double_t xpos, ypos, zpos, zmod;
+  Double_t alpha;
+
+
+  // First create all needed shapes
+  alpha = (360./(2*fNLadders))*TMath::DegToRad();
+
+  // The ladder
+  xlen = fLayRadius*TMath::Tan(alpha);
+  ylen = 0.5*fLadderThick;
+  zlen = 0.5*fZLength;
+
+  TGeoBBox *ladder = new TGeoBBox(xlen, ylen, zlen);
+
+
+  // We have all shapes: now create the real volumes
+  TGeoMedium *medAir = mgr->GetMedium("ITS_AIR$");
+
+  snprintf(volname, 30, "ITSupgLadder%d", fLayerNumber);
+  TGeoVolume *laddVol = new TGeoVolume(volname, ladder, medAir);
+
+//  laddVol->SetVisibility(kFALSE);
+  laddVol->SetVisibility(kTRUE);
+  laddVol->SetLineColor(2);
+
+  TGeoVolume *modVol = CreateModule(ladder->GetDX(), ladder->GetDY(),
+                                   ladder->GetDZ());
+
+
+  // Now build up the ladder
+  zmod = ((TGeoBBox*)modVol->GetShape())->GetDZ();
+  for (Int_t j=0; j<fNModules; j++) {
+    xpos = 0.;
+    ypos = 0.;
+    zpos = -ladder->GetDZ() + j*2*zmod + zmod;
+    laddVol->AddNode(modVol, j+1, new TGeoTranslation(xpos, ypos, zpos));
+  }
+
+
+  // Done, return the ladder
+  return laddVol;
+}
+
+//________________________________________________________________________
+TGeoVolume* AliITSv11GeometryUpgrade::CreateModule(const Double_t xlad,
+                                                  const Double_t ylad,
+                                                  const Double_t zlad,
+                                                  const TGeoManager *mgr){
+//
+// Creates the actual Module
+//
+// Input:
+//         xlad,ylad,zlad : the ladder dimensions
+//         mgr  : the GeoManager (used only to get the proper material)
+//
+// Output:
+//
+// Return:
+//
+// Created:      22 Jun 2011  Mario Sitta
+//
+
+  char volname[30];
+  Double_t xlen, ylen, zlen;
+  Double_t xpos, ypos, zpos;
+
+
+  // First create all needed shapes
+
+  // The module
+  TGeoBBox *module = new TGeoBBox(xlad, ylad, zlad/fNModules);
+
+  // The sensor
+  xlen = module->GetDX();
+  ylen = 0.5*fSensorThick;
+  zlen = module->GetDZ();
+  TGeoBBox *sensor = new TGeoBBox(xlen, ylen, zlen);
+
+
+  // We have all shapes: now create the real volumes
+  TGeoMedium *medAir = mgr->GetMedium("ITS_AIR$");
+  TGeoMedium *medSi  = mgr->GetMedium("ITS_SI$");
+
+  snprintf(volname, 30, "ITSupgModule%d", fLayerNumber);
+  TGeoVolume *modVol = new TGeoVolume(volname, module, medAir);
+
+  modVol->SetVisibility(kFALSE);
+  modVol->SetLineColor(1);
+
+  snprintf(volname, 30, "ITSupgSensor%d", fLayerNumber);
+  TGeoVolume *sensVol = new TGeoVolume(volname, sensor, medSi);
+
+  sensVol->SetVisibility(kTRUE);
+  sensVol->SetLineColor(8);
+  sensVol->SetLineWidth(1);
+  sensVol->SetFillColor(sensVol->GetLineColor());
+  sensVol->SetFillStyle(4000); // 0% transparent
+
+
+  // Now build up the module
+  xpos = 0.;
+  ypos = -module->GetDY() + sensor->GetDY();
+  zpos = 0.;
+
+  modVol->AddNode(sensVol, 1, new TGeoTranslation(xpos, ypos, zpos));
+
+
+  // Done, return the module
+  return modVol;
+}
+
+//________________________________________________________________________
+void AliITSv11GeometryUpgrade::SetLadderTilt(const Double_t t){
+//
+// Sets the Ladder tilt angle (for turbo layers only)
+//
+// Input:
+//         t :  the ladder tilt angle
+//
+// Output:
+//
+// Return:
+//
+// Created:      08 Jul 2011  Mario Sitta
+//
+
+  if (fIsTurbo)
+    fLadderTilt = t;
+  else
+    AliError("Not a Turbo layer");
+
+}
+
+//________________________________________________________________________
+void AliITSv11GeometryUpgrade::SetLadderWidth(const Double_t w){
+//
+// Sets the Ladder width (for turbo layers only)
+//
+// Input:
+//         w :  the ladder width
+//
+// Output:
+//
+// Return:
+//
+// Created:      08 Jul 2011  Mario Sitta
+//
+
+  if (fIsTurbo)
+    fLadderWidth = w;
+  else
+    AliError("Not a Turbo layer");
+
+}
diff --git a/ITS/UPGRADE/AliITSv11GeometryUpgrade.h b/ITS/UPGRADE/AliITSv11GeometryUpgrade.h
new file mode 100644 (file)
index 0000000..90fd248
--- /dev/null
@@ -0,0 +1,88 @@
+#ifndef ALIITSV11GEOMETRYUPGRADE_H
+#define ALIITSV11GEOMETRYUPGRADE_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+
+//*************************************************************************
+// This class Defines the Geometry for the ITS Upgrade using TGeo
+// This is a work class used to study different configurations
+// during the development of the new ITS structure.
+//
+//  Mario Sitta <sitta@to.infn.it>
+//*************************************************************************
+
+
+/*
+  $Id: AliITSv11GeometryUpgrade.h
+ */
+
+#include "AliITSv11Geometry.h"
+#include <TGeoManager.h>
+#include <TGeoCompositeShape.h>
+#include <TGeoXtru.h>
+
+class TGeoVolume;
+
+class AliITSv11GeometryUpgrade : public AliITSv11Geometry {
+  public:
+    AliITSv11GeometryUpgrade();
+    AliITSv11GeometryUpgrade(Int_t debug);
+    AliITSv11GeometryUpgrade(Int_t lay, Int_t debug);
+    AliITSv11GeometryUpgrade(Int_t lay, Bool_t turbo, Int_t debug);
+    AliITSv11GeometryUpgrade(const AliITSv11GeometryUpgrade &source);
+    AliITSv11GeometryUpgrade& operator=(const AliITSv11GeometryUpgrade &source);
+    virtual ~AliITSv11GeometryUpgrade();
+    //
+    Bool_t    IsTurbo() {return fIsTurbo;};
+
+    Double_t  GetLadderThick() {return fLadderThick;};
+    Double_t  GetLadderTilt()  {return fLadderTilt;};
+    Double_t  GetLadderWidth() {return fLadderWidth;};
+    Double_t  GetSensorThick() {return fSensorThick;};
+    Double_t  GetNLadders()    {return fNLadders;};
+    Double_t  GetNModules()    {return fNModules;};
+    Double_t  GetRadius()      {return fLayRadius;};
+    Double_t  GetZLength()     {return fZLength;};
+
+    void      SetLadderThick(const Double_t t) {fLadderThick = t;};
+    void      SetLadderTilt(const Double_t t);
+    void      SetLadderWidth(const Double_t w);
+    void      SetSensorThick(const Double_t t) {fSensorThick = t;};
+    void      SetNLadders(const Int_t n) {fNLadders = n;};
+    void      SetNModules(const Int_t m) {fNModules = m;};
+    void      SetRadius(const Double_t r) {fLayRadius = r;};
+    void      SetZLength(const Double_t z) {fZLength   = z;};
+
+    virtual void CreateLayer(TGeoVolume *moth,
+                      const TGeoManager *mgr=gGeoManager);
+
+  private:
+    void CreateLayerTurbo(TGeoVolume *moth,
+                   const TGeoManager *mgr=gGeoManager);
+
+    TGeoVolume* CreateLadder(const TGeoManager *mgr=gGeoManager);
+    TGeoVolume* CreateModule(const Double_t x, const Double_t y,
+                            const Double_t z,
+                            const TGeoManager *mgr=gGeoManager);
+
+    Int_t     fLayerNumber; // Current layer number
+    Double_t  fLayRadius;   // Inner radius of this layer
+    Double_t  fZLength;     // Z length of this layer
+    Double_t  fSensorThick; // Sensor thickness
+    Double_t  fLadderThick; // Ladder thickness
+    Double_t  fLadderWidth; // Ladder width (for turbo layers only)
+    Double_t  fLadderTilt;  // Ladder tilt angle (for turbo layers only)
+    Int_t     fNLadders;    // Number of ladders in this layer
+    Int_t     fNModules;    // Number of modules per ladder in this layer
+    Bool_t    fIsTurbo;     // True if this layer is a "turbo" layer
+
+  // Parameters for the Upgrade geometry
+
+    static const Double_t fgkDefaultSensorThick; // Default sensor thickness
+    static const Double_t fgkDefaultLadderThick; // Default ladder thickness
+
+  ClassDef(AliITSv11GeometryUpgrade,0) // ITS v11 Upgrade geometry
+};
+
+#endif
diff --git a/ITS/UPGRADE/AliITSvUpgrade.cxx b/ITS/UPGRADE/AliITSvUpgrade.cxx
new file mode 100644 (file)
index 0000000..652b8b2
--- /dev/null
@@ -0,0 +1,1551 @@
+/**************************************************************************
+ * Copyright(c) 2007-2009, 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: AliITSvUpgrade.cxx */
+
+
+//========================================================================
+//
+//        Geometry for the Upgrade of the Inner Tracking System
+//
+// Mario Sitta (sitta@to.infn.it)
+//
+//========================================================================
+
+
+
+// $Log: AliITSvUpgrade.cxx,v $
+
+#include <TClonesArray.h>
+#include <TGeoGlobalMagField.h>
+#include <TGeoManager.h>
+#include <TGeoMatrix.h>
+#include <TGeoPhysicalNode.h>
+#include <TGeoVolume.h>
+#include <TGeoXtru.h>
+#include <TLorentzVector.h>
+#include <TString.h>
+#include <TVirtualMC.h>
+
+#include "AliITSUpg.h"
+#include "AliITSDetTypeSim.h"
+#include "AliITShit.h"
+#include "AliLog.h"
+#include "AliMC.h"
+#include "AliMagF.h"
+#include "AliRun.h"
+#include "AliTrackReference.h"
+#include "AliITSInitGeometryUpg.h"
+#include "AliITSv11Geometry.h"
+#include "AliITSv11GeometryUpgrade.h"
+#include "AliITSvUpgrade.h"
+#include "AliGeomManager.h"
+
+ClassImp(AliITSvUpgrade)
+
+//______________________________________________________________________
+AliITSvUpgrade::AliITSvUpgrade():
+  fMajorVersion(IsVersion()),
+  fMinorVersion(-1),
+  fNumberOfLayers(0),
+  fLayTurbo(0),
+  fLayRadii(0),
+  fLayZLength(0),
+  fLaddPerLay(0),
+  fModPerLadd(0),
+  fLadThick(0),
+  fLadWidth(0),
+  fLadTilt(0),
+  fDetThick(0),
+  fInitGeom((AliITSVersion_t)fMajorVersion,fMinorVersion),
+  fUpGeom(0)
+ {
+    //    Standard default constructor
+    // Inputs:
+    //   none.
+    // Outputs:
+    //   none.
+    // Return:
+    //   none.
+}
+
+//______________________________________________________________________
+AliITSvUpgrade::AliITSvUpgrade(const char *title):
+  AliITSUpg("ITS", title),
+  fMajorVersion(IsVersion()),
+  fMinorVersion(-1),
+  fNumberOfLayers(0),
+  fLayTurbo(0),
+  fLayRadii(0),
+  fLayZLength(0),
+  fLaddPerLay(0),
+  fModPerLadd(0),
+  fLadThick(0),
+  fLadWidth(0),
+  fLadTilt(0),
+  fDetThick(0),
+  fInitGeom((AliITSVersion_t)fMajorVersion,fMinorVersion),
+  fUpGeom(0)
+{
+    //    Standard constructor for the Upgrade geometry.
+    // Inputs:
+    //   const char * title  Arbitrary title
+    // Outputs:
+    //   none.
+    // Return:
+    //   none.
+
+  fIdN = 6;
+  fIdName = new TString[fIdN];
+
+  fIdName[0] = "ITS1";
+  fIdName[1] = "ITS2";
+  fIdName[2] = "ITS3";
+  fIdName[3] = "ITS4";
+  fIdName[4] = "ITS5";
+  fIdName[5] = "ITS6";
+
+  fIdSens    = new Int_t[fIdN];
+  for(Int_t i=0; i<fIdN; i++) fIdSens[i] = 0;
+
+  fLayTurbo   = new Bool_t[fIdN];
+  fLayRadii   = new Double_t[fIdN];
+  fLayZLength = new Double_t[fIdN];
+  fLaddPerLay = new Int_t[fIdN];
+  fModPerLadd = new Int_t[fIdN];
+  fLadThick   = new Double_t[fIdN];
+  fLadWidth   = new Double_t[fIdN];
+  fLadTilt    = new Double_t[fIdN];
+  fDetThick   = new Double_t[fIdN];
+
+  fUpGeom = new AliITSv11GeometryUpgrade*[fIdN];
+
+  if (fNumberOfLayers > 0)  // if not, we'll Fatal-ize in CreateGeometry
+    for (Int_t j=0; j<fNumberOfLayers; j++) {
+      fLayRadii[j] = 0.;
+      fLayZLength[j] = 0.;
+      fLaddPerLay[j] = 0;
+      fModPerLadd[j] = 0;
+      fLadWidth[j] = 0.;
+      fDetThick[j] = 0.;
+      fUpGeom[j] = 0;
+    }
+    
+}
+
+//______________________________________________________________________
+AliITSvUpgrade::AliITSvUpgrade(const char *name, const char *title,
+                              const Int_t nlay):
+  AliITSUpg("ITS", title),
+  fMajorVersion(IsVersion()),
+  fMinorVersion(1),
+  fNumberOfLayers(nlay),
+  fLayTurbo(0),
+  fLayRadii(0),
+  fLayZLength(0),
+  fLaddPerLay(0),
+  fModPerLadd(0),
+  fLadThick(0),
+  fLadWidth(0),
+  fLadTilt(0),
+  fDetThick(0),
+  fInitGeom((AliITSVersion_t)fMajorVersion,fMinorVersion),
+  fUpGeom(0)
+{
+    //    Standard constructor for the Upgrade geometry.
+    // Inputs:
+    //   const char * name   Ignored, set to "ITS"
+    //   const char * title  Arbitrary title
+    //   const Int_t nlay    Number of layers
+    // Outputs:
+    //   none.
+    // Return:
+    //   none.
+  
+  fIdN = nlay;
+  fIdName = new TString[fIdN];
+
+  for (Int_t j=0; j<fIdN; j++)
+    fIdName[j].Form("ITSupgSensor%d",j); // See AliITSv11GeometryUpgrade
+
+  (void) name; // removes warning message
+
+  fIdSens    = new Int_t[fIdN];
+  for(Int_t i=0; i<fIdN; i++) fIdSens[i] = 0;
+
+  fLayTurbo   = new Bool_t[fIdN];
+  fLayRadii   = new Double_t[fIdN];
+  fLayZLength = new Double_t[fIdN];
+  fLaddPerLay = new Int_t[fIdN];
+  fModPerLadd = new Int_t[fIdN];
+  fLadThick   = new Double_t[fIdN];
+  fLadWidth   = new Double_t[fIdN];
+  fLadTilt    = new Double_t[fIdN];
+  fDetThick   = new Double_t[fIdN];
+
+  fUpGeom = new AliITSv11GeometryUpgrade*[fIdN];
+  
+  if (fNumberOfLayers > 0)  // if not, we'll Fatal-ize in CreateGeometry
+    for (Int_t j=0; j<fNumberOfLayers; j++) {
+      fLayRadii[j] = 0.;
+      fLayZLength[j] = 0.;
+      fLaddPerLay[j] = 0;
+      fModPerLadd[j] = 0;
+      fLadWidth[j] = 0.;
+      fDetThick[j] = 0.;
+      fUpGeom[j] = 0;
+    }
+    
+}
+
+//______________________________________________________________________
+AliITSvUpgrade::~AliITSvUpgrade() {
+    //    Standard destructor
+    // Inputs:
+    //   none.
+    // Outputs:
+    //   none.
+    // Return:
+    //   none.
+  delete [] fLayTurbo;
+  delete [] fLayRadii;
+  delete [] fLayZLength;
+  delete [] fLaddPerLay;
+  delete [] fModPerLadd;
+  delete [] fLadThick;
+  delete [] fLadWidth;
+  delete [] fLadTilt;
+  delete [] fDetThick;
+  delete [] fUpGeom;
+
+}
+
+//______________________________________________________________________
+void AliITSvUpgrade::SetT2Lmatrix(Int_t uid, Double_t yShift, 
+                                 Bool_t yFlip, Bool_t yRot180) const {
+
+  //
+  // Creates the TGeo Local to Tracking transformation matrix
+  // and sends it to the corresponding TGeoPNEntry 
+  //
+  // This function is used in AddAlignableVolumes()
+
+  TGeoPNEntry *alignableEntry = gGeoManager->GetAlignableEntryByUID(uid);
+  TGeoHMatrix* globMatrix = alignableEntry->GetGlobalOrig();
+
+  Double_t *gtrans = globMatrix->GetTranslation(), rotMatrix[9];
+  memcpy(&rotMatrix[0], globMatrix->GetRotationMatrix(), 9*sizeof(Double_t));
+  Double_t al = TMath::ATan2(rotMatrix[1],rotMatrix[0]);
+  if (yRot180) {
+    al = TMath::ATan2(rotMatrix[1],-rotMatrix[0]);
+  }
+  Double_t xShift = gtrans[0]*TMath::Cos(al)+gtrans[1]*TMath::Sin(al);
+  Double_t zShift = -gtrans[2];
+
+  TGeoHMatrix *matLtoT = new TGeoHMatrix;
+  matLtoT->SetDx( xShift ); // translation
+  matLtoT->SetDy( yShift );
+  matLtoT->SetDz( zShift );
+  rotMatrix[0]= 0;  rotMatrix[1]= 1;  rotMatrix[2]= 0; // + rotation
+  rotMatrix[3]= 1;  rotMatrix[4]= 0;  rotMatrix[5]= 0;
+  rotMatrix[6]= 0;  rotMatrix[7]= 0;  rotMatrix[8]=-1;
+  if (yFlip) rotMatrix[3] = -1;  // flipping in y  (for SPD1)
+  if (yFlip) rotMatrix[1] = -1;  // flipping in y  (for SPD1)
+
+  if (yRot180) { // rotation of pi around the axis perpendicular to the wafer
+    if (yFlip) matLtoT->SetDx( -xShift ); // flipping in y  (for SPD1)
+    matLtoT->SetDy( -yShift );
+    matLtoT->SetDz( -zShift );
+    rotMatrix[8]=1;
+    rotMatrix[3] = -1;
+    if (yFlip) rotMatrix[3] = 1;  // flipping in y  (for SPD1)
+  }
+
+  TGeoRotation rot;
+  rot.SetMatrix(rotMatrix);
+  matLtoT->MultiplyLeft(&rot);
+  TGeoHMatrix *matTtoL = new TGeoHMatrix(matLtoT->Inverse());
+  delete matLtoT;
+  alignableEntry->SetMatrix(matTtoL);
+}
+
+//______________________________________________________________________
+void AliITSvUpgrade::AddAlignableVolumes() const{
+  // Creates entries for alignable volumes associating the symbolic volume
+  // name with the corresponding volume path.
+  // 
+  // Records in the alignable entries the transformation matrices converting
+  // TGeo local coordinates (in the RS of alignable volumes) to the tracking
+  // system
+  // For this, this function has to run before the misalignment because we
+  // are using the ideal positions in the AliITSgeom object.
+  // Inputs:
+  //   none.
+  // Outputs:
+  //   none.
+  // Return:
+  //   none.
+
+  AliInfo("Add ITS alignable volumes");
+
+  if (!gGeoManager) {
+    AliFatal("TGeoManager doesn't exist !");
+    return;
+  }
+  // To be done - dummy for the time being
+}
+
+//______________________________________________________________________
+void AliITSvUpgrade::CreateGeometry() {
+
+  // Create the geometry and insert it in the mother volume ITSV
+
+
+  TGeoManager *geoManager = gGeoManager;
+
+  TGeoVolume *vALIC = geoManager->GetVolume("ALIC");
+
+  new TGeoVolumeAssembly("ITSV");
+  TGeoVolume *vITSV = geoManager->GetVolume("ITSV");
+  vALIC->AddNode(vITSV, 2, 0);  // Copy number is 2 to cheat AliGeoManager::CheckSymNamesLUT
+
+  //
+  const Char_t *cvsDate="$Date: 2011-03-11 18:17:13 +0100 (Fri, 11 Mar 2011) $";
+  const Char_t *cvsRevision="$Revision: 48336 $";
+  const Int_t kLength=100;
+  Char_t vstrng[kLength];
+  if(fInitGeom.WriteVersionString(vstrng,kLength,(AliITSVersion_t)IsVersion(),
+                            fMinorVersion,cvsDate,cvsRevision)) {
+    vITSV->SetTitle(vstrng);
+  }
+
+  // Check that we have all needed parameters
+  if (fNumberOfLayers <= 0)
+    AliFatal(Form("Wrong number of layers (%d)",fNumberOfLayers));
+
+  for (Int_t j=0; j<fNumberOfLayers; j++) {
+    if (fLayRadii[j] <= 0)
+      AliFatal(Form("Wrong layer radius for layer %d (%f)",j,fLayRadii[j]));
+    if (fLayZLength[j] <= 0)
+      AliFatal(Form("Wrong layer length for layer %d (%f)",j,fLayZLength[j]));
+    if (fLaddPerLay[j] <= 0)
+      AliFatal(Form("Wrong number of ladders for layer %d (%d)",j,
+                   fLaddPerLay[j]));
+    if (fModPerLadd[j] <= 0)
+      AliFatal(Form("Wrong number of modules for layer %d (%d)",j,
+                   fModPerLadd[j]));
+    if (fLadThick[j] < 0)
+      AliFatal(Form("Wrong ladder thickness for layer %d (%f)",j,
+                   fLadThick[j]));
+    if (fLayTurbo[j] && fLadWidth[j] <= 0)
+      AliFatal(Form("Wrong ladder width for layer %d (%f)",j,
+                   fLadWidth[j]));
+    if (fDetThick[j] < 0)
+      AliFatal(Form("Wrong module thickness for layer %d (%f)",j,
+                   fDetThick[j]));
+
+    if (j > 0) {
+      if (fLayRadii[j] <= fLayRadii[j-1])
+       AliError(Form("Layer %d radius (%f) is smaller than layer %d radius (%f)",
+                     j,fLayRadii[j],j-1,fLayRadii[j-1]));
+      if (fLayZLength[j] <= fLayZLength[j-1])
+       AliWarning(Form("Layer %d length (%f) is smaller than layer %d length (%f)",
+                     j,fLayZLength[j],j-1,fLayZLength[j-1]));
+    } // if (j > 0)
+
+    if (fLadThick[j] == 0)
+      AliInfo(Form("Ladder thickness for layer %d not set, using default",j));
+
+    if (fDetThick[j] == 0)
+      AliInfo(Form("Module thickness for layer %d not set, using default",j));
+
+  } // for (Int_t j=0; j<fNumberOfLayers; j++)
+
+  // Now create the actual geometry
+  for (Int_t j=0; j<fNumberOfLayers; j++) {
+    if (fLayTurbo[j]) {
+      fUpGeom[j] = new AliITSv11GeometryUpgrade(j,kTRUE,kFALSE);
+      fUpGeom[j]->SetLadderWidth(fLadWidth[j]);
+      fUpGeom[j]->SetLadderTilt(fLadTilt[j]);
+    }
+    else
+      fUpGeom[j] = new AliITSv11GeometryUpgrade(j,kFALSE);
+    fUpGeom[j]->SetRadius(fLayRadii[j]);
+    fUpGeom[j]->SetZLength(fLayZLength[j]);
+    fUpGeom[j]->SetNLadders(fLaddPerLay[j]);
+    fUpGeom[j]->SetNModules(fModPerLadd[j]);
+    if (fLadThick[j] != 0) fUpGeom[j]->SetLadderThick(fLadThick[j]);
+    if (fDetThick[j] != 0) fUpGeom[j]->SetSensorThick(fDetThick[j]);
+    fUpGeom[j]->CreateLayer(vITSV);
+  }
+
+}
+
+//______________________________________________________________________
+void AliITSvUpgrade::CreateMaterials(){
+    // Create ITS materials
+    //     This function defines the default materials used in the Geant
+    // Monte Carlo simulations for the geometries AliITSv1, AliITSv3,
+    // AliITSv11Hybrid.
+    // In general it is automatically replaced by
+    // the CreateMaterials routine defined in AliITSv?. Should the function
+    // CreateMaterials not exist for the geometry version you are using this
+    // one is used. See the definition found in AliITSv5 or the other routine
+    // for a complete definition.
+    // Inputs:
+    //   none.
+    // Outputs:
+    //   none.
+    // Return:
+    //   none.
+
+    Int_t   ifield = ((AliMagF*)TGeoGlobalMagField::Instance()->GetField())->Integ();
+    Float_t fieldm = ((AliMagF*)TGeoGlobalMagField::Instance()->GetField())->Max();
+
+    Float_t tmaxfd = 0.1; // 1.0; // Degree
+    Float_t stemax = 1.0; // cm
+    Float_t deemax = 0.1; // 30.0; // Fraction of particle's energy 0<deemax<=1
+    Float_t epsil  = 1.0E-4; // 1.0; // cm
+    Float_t stmin  = 0.0; // cm "Default value used"
+
+    Float_t tmaxfdSi = 0.1; // .10000E+01; // Degree
+    Float_t stemaxSi = 0.0075; //  .10000E+01; // cm
+    Float_t deemaxSi = 0.1; // 0.30000E-02; // Fraction of particle's energy 0<deemax<=1
+    Float_t epsilSi  = 1.0E-4;// .10000E+01;
+    Float_t stminSi  = 0.0; // cm "Default value used"
+
+    Float_t tmaxfdAir = 0.1; // .10000E+01; // Degree
+    Float_t stemaxAir = .10000E+01; // cm
+    Float_t deemaxAir = 0.1; // 0.30000E-02; // Fraction of particle's energy 0<deemax<=1
+    Float_t epsilAir  = 1.0E-4;// .10000E+01;
+    Float_t stminAir  = 0.0; // cm "Default value used"
+
+    Float_t tmaxfdServ = 1.0; // 10.0; // Degree
+    Float_t stemaxServ = 1.0; // 0.01; // cm
+    Float_t deemaxServ = 0.5; // 0.1; // Fraction of particle's energy 0<deemax<=1
+    Float_t epsilServ  = 1.0E-3; // 0.003; // cm
+    Float_t stminServ  = 0.0; //0.003; // cm "Default value used"
+
+    // Freon PerFluorobuthane C4F10 see 
+    // http://st-support-cooling-electronics.web.cern.ch/
+    //        st-support-cooling-electronics/default.htm
+    Float_t afre[2]  = { 12.011,18.9984032 };
+    Float_t zfre[2]  = { 6., 9. };
+    Float_t wfre[2]  = { 4.,10. };
+    Float_t densfre  = 1.52;
+
+
+    //CM55J
+
+    Float_t aCM55J[4]={12.0107,14.0067,15.9994,1.00794};
+    Float_t zCM55J[4]={6.,7.,8.,1.};
+    Float_t wCM55J[4]={0.908508078,0.010387573,0.055957585,0.025146765};
+    Float_t dCM55J = 1.8;
+
+    //ALCM55J
+
+    Float_t aALCM55J[5]={12.0107,14.0067,15.9994,1.00794,26.981538};
+    Float_t zALCM55J[5]={6.,7.,8.,1.,13.};
+    Float_t wALCM55J[5]={0.817657902,0.0093488157,0.0503618265,0.0226320885,0.1};
+    Float_t dALCM55J = 1.9866;
+
+    //Si Chips
+
+    Float_t aSICHIP[6]={12.0107,14.0067,15.9994,1.00794,28.0855,107.8682};
+    Float_t zSICHIP[6]={6.,7.,8.,1.,14., 47.};
+    Float_t wSICHIP[6]={0.039730642,0.001396798,0.01169634,0.004367771,0.844665,0.09814344903};
+    Float_t dSICHIP = 2.36436;
+
+    //Inox
+    
+    Float_t aINOX[9]={12.0107,54.9380, 28.0855,30.9738,32.066,58.6928,51.9961,95.94,55.845};
+    Float_t zINOX[9]={6.,25.,14.,15.,16., 28.,24.,42.,26.};
+    Float_t wINOX[9]={0.0003,0.02,0.01,0.00045,0.0003,0.12,0.17,0.025,0.654};
+    Float_t dINOX = 8.03;
+
+    //AISI 304 L (from F.Tosello's web page - M.S. 18 Oct 10)
+    
+    Float_t a304L[8]={12.0107,54.9380, 28.0855,30.9738,32.066,58.6928,51.9961,55.845};
+    Float_t z304L[8]={6.,25.,14.,15.,16., 28.,24.,26.};
+    Float_t w304L[8]={0.0003,0.02,0.01,0.00045,0.003,0.0925,0.19,0.6865};
+    Float_t d304L = 8.03;
+
+    //SDD HV microcable
+
+    Float_t aHVm[5]={12.0107,1.00794,14.0067,15.9994,26.981538};
+    Float_t zHVm[5]={6.,1.,7.,8.,13.};
+    Float_t wHVm[5]={0.520088819984,0.01983871336,0.0551367996,0.157399667056, 0.247536};
+    Float_t dHVm = 1.6087;
+
+    //SDD LV+signal cable
+
+    Float_t aLVm[5]={12.0107,1.00794,14.0067,15.9994,26.981538};
+    Float_t zLVm[5]={6.,1.,7.,8.,13.};
+    Float_t wLVm[5]={0.21722436468,0.0082859922,0.023028867,0.06574077612, 0.68572};
+    Float_t dLVm = 2.1035;
+
+    //SDD hybrid microcab
+
+    Float_t aHLVm[5]={12.0107,1.00794,14.0067,15.9994,26.981538};
+    Float_t zHLVm[5]={6.,1.,7.,8.,13.};
+    Float_t wHLVm[5]={0.24281879711,0.00926228815,0.02574224025,0.07348667449, 0.64869};
+    Float_t dHLVm = 2.0502;
+
+    //SDD anode microcab
+
+    Float_t aALVm[5]={12.0107,1.00794,14.0067,15.9994,26.981538};
+    Float_t zALVm[5]={6.,1.,7.,8.,13.};
+    Float_t wALVm[5]={0.392653705471,0.0128595919215,0.041626868025,0.118832707289, 0.431909};
+    Float_t dALVm = 2.0502;
+
+    //X7R capacitors - updated from F.Tosello's web page - M.S. 18 Oct 10
+
+    Float_t aX7R[6]={137.327,47.867,15.9994,58.6928,63.5460,118.710};
+    Float_t zX7R[6]={56.,22.,8.,28.,29.,50.};
+    Float_t wX7R[6]={0.524732,0.176736,0.179282,0.079750,0.019750,0.019750};
+    Float_t dX7R = 6.07914;
+
+    //X7R weld, i.e. Sn 60% Pb 40% (from F.Tosello's web page - M.S. 15 Oct 10)
+
+    Float_t aX7Rweld[2]={118.71 , 207.20};
+    Float_t zX7Rweld[2]={ 50.   ,  82.  };
+    Float_t wX7Rweld[2]={  0.60 ,   0.40};
+    Float_t dX7Rweld   = 8.52358;
+
+    // AIR
+
+    Float_t aAir[4]={12.0107,14.0067,15.9994,39.948};
+    Float_t zAir[4]={6.,7.,8.,18.};
+    Float_t wAir[4]={0.000124,0.755267,0.231781,0.012827};
+    Float_t dAir = 1.20479E-3;
+
+    // Water
+
+    Float_t aWater[2]={1.00794,15.9994};
+    Float_t zWater[2]={1.,8.};
+    Float_t wWater[2]={0.111894,0.888106};
+    Float_t dWater   = 1.0;
+
+    // CERAMICS
+  //     94.4% Al2O3 , 2.8% SiO2 , 2.3% MnO , 0.5% Cr2O3
+    Float_t acer[5]  = { 26.981539,15.9994,28.0855,54.93805,51.9961 };
+    Float_t zcer[5]  = {       13.,     8.,    14.,     25.,    24. };
+    Float_t wcer[5]  = {.4443408,.5213375,.0130872,.0178135,.003421};
+    Float_t denscer  = 3.6;
+
+    //G10FR4
+
+    Float_t zG10FR4[14] = {14.00,      20.00,  13.00,  12.00,  5.00,   22.00,  11.00,  19.00,  26.00,  9.00,   8.00,   6.00,   7.00,   1.00};
+    Float_t aG10FR4[14] = {28.0855000,40.0780000,26.9815380,24.3050000,10.8110000,47.8670000,22.9897700,39.0983000,55.8450000,18.9984000,15.9994000,12.0107000,14.0067000,1.0079400};
+    Float_t wG10FR4[14] = {0.15144894,0.08147477,0.04128158,0.00904554,0.01397570,0.00287685,0.00445114,0.00498089,0.00209828,0.00420000,0.36043788,0.27529426,0.01415852,0.03427566};
+    Float_t densG10FR4= 1.8;
+    
+     //--- EPOXY  --- C18 H19 O3
+      Float_t aEpoxy[3] = {15.9994, 1.00794, 12.0107} ; 
+      Float_t zEpoxy[3] = {     8.,      1.,      6.} ; 
+      Float_t wEpoxy[3] = {     3.,     19.,     18.} ; 
+      Float_t dEpoxy = 1.8 ;
+
+      // rohacell: C9 H13 N1 O2
+    Float_t arohac[4] = {12.01,  1.01, 14.010, 16.};
+    Float_t zrohac[4] = { 6.,    1.,    7.,     8.};
+    Float_t wrohac[4] = { 14.,   10.,    2.,     6.};
+    Float_t drohac    = 0.052;
+
+    // If he/she means stainless steel (inox) + Aluminium and Zeff=15.3383 then
+//
+// %Al=81.6164 %inox=100-%Al
+
+    Float_t aInAl[5] = {27., 55.847,51.9961,58.6934,28.0855 };
+    Float_t zInAl[5] = {13., 26.,24.,28.,14. };
+    Float_t wInAl[5] = {.816164, .131443,.0330906,.0183836,.000919182};
+    Float_t dInAl    = 3.075;
+
+    // Aluminum alloy with 12% Copper - 21 Oct 10
+
+    Float_t aAlCu12[2] = {26.9815, 63.546};
+    Float_t zAlCu12[2] = {13.    , 29.   };
+    Float_t wAlCu12[2] = { 0.88  ,  0.12 };
+    Float_t dAlCu12    = 2.96;
+
+    // Kapton
+
+    Float_t aKapton[4]={1.00794,12.0107, 14.010,15.9994};
+    Float_t zKapton[4]={1.,6.,7.,8.};
+    Float_t wKapton[4]={0.026362,0.69113,0.07327,0.209235};
+    Float_t dKapton   = 1.42;
+    
+    // Kapton + Cu (for Pixel Bus)
+
+    Float_t aKaptonCu[5]={1.00794, 12.0107, 14.010, 15.9994, 63.5460};
+    Float_t zKaptonCu[5]={1., 6., 7., 8., 29.};
+    Float_t wKaptonCuBus[5];
+    
+    // Kapton + Cu (for Pixel MCM)
+
+    Float_t wKaptonCuMCM[5];
+    
+    // Kapton + Cu (mix of two above)
+
+    Float_t wKaptonCuMix[5];
+
+    //SDD ruby sph.
+    Float_t aAlOxide[2]  = { 26.981539,15.9994};
+    Float_t zAlOxide[2]  = {       13.,     8.};
+    Float_t wAlOxide[2]  = {0.4707, 0.5293};
+    Float_t dAlOxide     = 3.97;
+
+    // Silica for optical fibers: Si O2
+    Float_t aoptfib[2] = { 28.0855, 15.9994};
+    Float_t zoptfib[2] = { 14.,      8.    };
+    Float_t woptfib[2] = {  1.,      2.    };
+    Float_t doptfib    = 2.55;
+
+    // Tetrafluorethylene-Perfluorpropylene (FEP) - 08 Mar 10
+    Float_t aFEP[2] = { 12.0107, 18.9984};
+    Float_t zFEP[2] = {  6.    ,  9.    };
+    Float_t wFEP[2] = {  1.    ,  2.    };
+    Float_t dFEP    = 2.15;
+
+    // PVC (C2H3Cl)n - 08 Jul 10
+    Float_t aPVC[3] = { 12.0107, 1.00794, 35.4527};
+    Float_t zPVC[3] = {  6.    , 1.     , 35.   };
+    Float_t wPVC[3] = {  2.    , 3.     ,  1.   };
+    Float_t dPVC    = 1.3;
+
+    // PBT (Polybutylene terephthalate = C12-H12-O4) - 01 Sep 10
+    Float_t aPBT[3] = { 12.0107, 1.00794, 15.9994};
+    Float_t zPBT[3] = {  6.    , 1.     ,  8.   };
+    Float_t wPBT[3] = { 12.    ,12.     ,  4.   };
+    Float_t dPBT    = 1.31;
+
+    // POLYAX (POLYAX = C37-H24-O6-N2) - 03 Sep 10
+    Float_t aPOLYAX[4] = { 12.0107, 1.00794, 15.9994, 14.00674};
+    Float_t zPOLYAX[4] = {  6.    , 1.     ,  8.    ,  7.     };
+    Float_t wPOLYAX[4] = { 37.    ,24.     ,  6.    ,  2.     };
+    Float_t dPOLYAX    = 1.27;
+
+    // PPS (PPS = C6-H4-S) - 05 Sep 10
+    Float_t aPPS[3] = { 12.0107, 1.00794, 32.066};
+    Float_t zPPS[3] = {  6.    , 1.     , 16.   };
+    Float_t wPPS[3] = {  6.    , 4.     ,  1.   };
+    Float_t dPPS    = 1.35;
+
+    // Megolon (Polyolefin = (C-H2)n) - 20 Oct 10
+    Float_t aMegolon[2] = { 12.0107, 1.00794};
+    Float_t zMegolon[2] = {  6.    , 1.     };
+    Float_t wMegolon[2] = {  1.    , 2.     };
+    Float_t dMegolon    = 1.51; // Mean of various types
+
+    // Standard glass (from glassproperties.com/glasses - M.S. 21 Oct 10)
+    Float_t aStdGlass[7] = {15.9994  ,28.0855  ,22.98977 ,40.078   ,
+                           24.305   ,26.981539,39.0983  };
+    Float_t zStdGlass[7] = { 8.      ,14.      ,11.      ,20.      ,
+                           12.      ,13.      ,19.      };
+    Float_t wStdGlass[7] = { 0.468377, 0.348239, 0.096441, 0.071469,
+                            0.006030, 0.005293, 0.004151};
+    Float_t dStdGlass    = 2.53;
+
+    // Glass Fiber (from F.Tosello's web page - M.S. 15 Oct 10)
+    Float_t aGlass[11] = {15.9994  ,28.0855  ,40.078   ,26.981539,10.811   ,
+               24.305   ,39.0983  ,22.98977 ,18.9984  ,47.867   ,55.845};
+    Float_t zGlass[11] = { 8.      ,14.      ,20       ,13       , 5       ,
+               12.      ,19       ,11       , 9       ,22       ,26    };
+    Float_t wGlass[11] = { 0.473610, 0.252415, 0.135791, 0.068803, 0.023293,
+                0.015076, 0.008301, 0.007419, 0.007000, 0.004795, 0.003497};
+    Float_t dGlass = 2.61;
+
+    // Ryton R-4 04 (from F.Tosello's web page - M.S. 15 Oct 10)
+    Float_t aRyton[14] = {15.9994  ,28.0855  ,40.078   ,26.981539,10.811   ,
+                         24.305   ,39.0983  ,22.98977 ,18.9984  ,47.867   ,
+                         55.845   ,12.0107  , 1.00794 ,32.066   };
+    Float_t zRyton[14] = { 8.      ,14.      ,20.      ,13.      , 5.      ,
+                         12.      ,19.      ,11.      , 9.      ,22.      ,
+                         26.      , 6.      , 1.      ,16.      };
+    Float_t wRyton[14] = { 0.189445, 0.100966, 0.054316, 0.027521, 0.009317,
+                          0.006030, 0.003320, 0.002968, 0.002800, 0.001918,
+                          0.001399, 0.399760, 0.022365, 0.177875};
+    Float_t dRyton = 1.65;
+
+    // Plexiglas (Poly(methyl methacrylate) (C5O2H8)n - M.S. 05 nov 10)
+    Float_t aPlexy[3] = { 12.0107, 15.9994,  1.00794};
+    Float_t zPlexy[3] = {  6.    , 8.     ,  1.   };
+    Float_t wPlexy[3] = {  5.    , 2.     ,  8.   };
+    Float_t dPlexy    = 1.18;
+
+    //SSD NiSn capacitor ends
+    Float_t aNiSn[2]  = { 56.6934,118.710};
+    Float_t zNiSn[2]  = {     28.,     50.};
+    Float_t wNiSn[2]  = {0.33, 0.67};
+    Float_t dNiSn     = wNiSn[0]*8.908 + wNiSn[1]*7.310;
+
+    AliMaterial(1,"SI$",0.28086E+02,0.14000E+02,0.23300E+01,0.93600E+01,0.99900E+03);
+    AliMedium(1,"SI$",1,0,ifield,fieldm,tmaxfdSi,stemaxSi,deemaxSi,epsilSi,stminSi);
+
+    AliMaterial(2,"SPD SI CHIP$",0.28086E+02,0.14000E+02,0.23300E+01,0.93600E+01,0.99900E+03);
+    AliMedium(2,"SPD SI CHIP$",2,0,ifield,fieldm,tmaxfdSi,stemaxSi,deemaxSi,epsilSi,stminSi);
+
+    AliMaterial(3,"SPD SI BUS$",0.28086E+02,0.14000E+02,0.23300E+01,0.93600E+01,0.99900E+03);
+    AliMedium(3,"SPD SI BUS$",3,0,ifield,fieldm,tmaxfdSi,stemaxSi,deemaxSi,epsilSi,stminSi);
+
+    AliMixture(4,"C (M55J)$",aCM55J,zCM55J,dCM55J,4,wCM55J);
+    AliMedium(4,"C (M55J)$",4,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+    AliMixture(5,"AIR$",aAir,zAir,dAir,4,wAir);
+    AliMedium(5,"AIR$",5,0,ifield,fieldm,tmaxfdAir,stemaxAir,deemaxAir,epsilAir,stminAir);
+
+    AliMixture(6,"GEN AIR$",aAir,zAir,dAir,4,wAir);
+    AliMedium(6,"GEN AIR$",6,0,ifield,fieldm,tmaxfdAir,stemaxAir,deemaxAir,epsilAir,stminAir);
+
+    AliMixture(7,"SDD SI CHIP$",aSICHIP,zSICHIP,dSICHIP,6,wSICHIP);
+    AliMedium(7,"SDD SI CHIP$",7,0,ifield,fieldm,tmaxfdSi,stemaxSi,deemaxSi,epsilSi,stminSi);
+
+    AliMixture(9,"SDD C (M55J)$",aCM55J,zCM55J,dCM55J,4,wCM55J);
+    AliMedium(9,"SDD C (M55J)$",9,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+    AliMixture(10,"SDD AIR$",aAir,zAir,dAir,4,wAir);
+    AliMedium(10,"SDD AIR$",10,0,ifield,fieldm,tmaxfdAir,stemaxAir,deemaxAir,epsilAir,stminAir);
+
+    AliMaterial(11,"AL$",0.26982E+02,0.13000E+02,0.26989E+01,0.89000E+01,0.99900E+03);
+    AliMedium(11,"AL$",11,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+    AliMixture(12, "Water$",aWater,zWater,dWater,2,wWater);
+    AliMedium(12,"WATER$",12,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+    AliMixture(13,"Freon$",afre,zfre,densfre,-2,wfre);
+    AliMedium(13,"Freon$",13,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+    AliMaterial(14,"COPPER$",0.63546E+02,0.29000E+02,0.89600E+01,0.14300E+01,0.99900E+03);
+    AliMedium(14,"COPPER$",14,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+    AliMixture(15,"CERAMICS$",acer,zcer,denscer,5,wcer);
+    AliMedium(15,"CERAMICS$",15,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+    AliMixture(20,"SSD C (M55J)$",aCM55J,zCM55J,dCM55J,4,wCM55J);
+    AliMedium(20,"SSD C (M55J)$",20,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+    AliMixture(21,"SSD AIR$",aAir,zAir,dAir,4,wAir);
+    AliMedium(21,"SSD AIR$",21,0,ifield,fieldm,tmaxfdAir,stemaxAir,deemaxAir,epsilAir,stminAir);
+
+    AliMixture(25,"G10FR4$",aG10FR4,zG10FR4,densG10FR4,14,wG10FR4);
+    AliMedium(25,"G10FR4$",25,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+     AliMixture(26,"GEN C (M55J)$",aCM55J,zCM55J,dCM55J,4,wCM55J);
+    AliMedium(26,"GEN C (M55J)$",26,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+    AliMixture(27,"GEN Air$",aAir,zAir,dAir,4,wAir);
+    AliMedium(27,"GEN Air$",27,0,ifield,fieldm,tmaxfdAir,stemaxAir,deemaxAir,epsilAir,stminAir);
+
+    AliMixture(35,"PLEXYGLAS$",aPlexy,zPlexy,dPlexy,-3,wPlexy);
+    AliMedium(35,"PLEXYGLAS$",35,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+    AliMixture(36,"STDGLASS$",aStdGlass,zStdGlass,dStdGlass,7,wStdGlass);
+    AliMedium(36,"STDGLASS$",36,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+    AliMixture(37,"ALCU12$",aAlCu12,zAlCu12,dAlCu12,2,wAlCu12);
+    AliMedium(37,"ALCU12$",37,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+    AliMixture(38,"MEGOLON$",aMegolon,zMegolon,dMegolon,-2,wMegolon);
+    AliMedium(38,"MEGOLON$",38,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+    AliMixture(39,"RYTON$",aRyton,zRyton,dRyton,14,wRyton);
+    AliMedium(39,"RYTON$",39,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+    AliMixture(40,"GLASS FIBER$",aGlass,zGlass,dGlass,11,wGlass);
+    AliMedium(40,"GLASS FIBER$",40,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+    AliMixture(41,"AISI304L$",a304L,z304L,d304L,8,w304L);
+    AliMedium(41,"AISI304L$",41,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+    AliMaterial(42,"NICKEL$",0.58693E+02,0.28000E+02,0.89080E+01,0.14200E+01,0.99900E+03);
+    AliMedium(42,"NICKEL$",42,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+               
+    AliMixture(43,"SDD X7R weld$",aX7Rweld,zX7Rweld,dX7Rweld,2,wX7Rweld);
+    AliMedium(43,"SDD X7R weld$",43,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+    AliMixture(44,"PPS$",aPPS,zPPS,dPPS,-3,wPPS);
+    AliMedium(44,"PPS$",44,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+    AliMixture(45,"POLYAX$",aPOLYAX,zPOLYAX,dPOLYAX,-4,wPOLYAX);
+    AliMedium(45,"POLYAX$",45,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+    AliMixture(46,"PBT$",aPBT,zPBT,dPBT,-3,wPBT);
+    AliMedium(46,"PBT$",46,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+    AliMixture(47,"PVC$",aPVC,zPVC,dPVC,-3,wPVC);
+    AliMedium(47,"PVC$",47,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+    Double_t cuFrac = 0.56;
+    Double_t kFrac  = 1.0 - cuFrac;
+    Double_t cuDens = 8.96;
+    Float_t dKaptonCuBus   = cuFrac * cuDens + kFrac * dKapton;
+    for (Int_t j=0; j<4; j++)
+      wKaptonCuBus[j] = wKapton[j]*kFrac;
+    wKaptonCuBus[4] = cuFrac;
+    AliMixture(48, "SPD-BUS CU KAPTON", aKaptonCu, zKaptonCu, dKaptonCuBus, 5, wKaptonCuBus);
+    AliMedium(48,"SPD-BUS CU KAPTON$",48,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+    
+    cuFrac = 0.5;
+    kFrac  = 1.0 - cuFrac;
+    Float_t dKaptonCuMCM   = cuFrac * cuDens + kFrac * dKapton;
+    for (Int_t j=0; j<4; j++)
+      wKaptonCuMCM[j] = wKapton[j]*kFrac;
+    wKaptonCuMCM[4] = cuFrac;
+    AliMixture(49, "SPD-MCM CU KAPTON", aKaptonCu, zKaptonCu, dKaptonCuMCM, 5, wKaptonCuMCM);
+    AliMedium(49,"SPD-MCM CU KAPTON$",49,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+    
+    cuFrac = (0.56 + 0.5) / 2.0;
+    kFrac  = 1.0 - cuFrac;
+    Float_t dKaptonCuMix   = cuFrac * cuDens + kFrac * dKapton;
+    for (Int_t j=0; j<4; j++)
+      wKaptonCuMix[j] = wKapton[j]*kFrac;
+    wKaptonCuMix[4] = cuFrac;
+    AliMixture(50, "SPD-MIX CU KAPTON", aKaptonCu, zKaptonCu, dKaptonCuMix, 5, wKaptonCuMix);
+    AliMedium(50,"SPD-MIX CU KAPTON$",50,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+    AliMaterial(51,"SPD SI$",0.28086E+02,0.14000E+02,0.23300E+01,0.93600E+01,0.99900E+03);
+    AliMedium(51,"SPD SI$",51,0,ifield,fieldm,tmaxfdSi,stemaxSi,deemaxSi,epsilSi,stminSi);
+
+    AliMaterial(52,"SPD SI CHIP$",0.28086E+02,0.14000E+02,0.23300E+01,0.93600E+01,0.99900E+03);
+    AliMedium(52,"SPD SI CHIP$",52,0,ifield,fieldm,tmaxfdSi,stemaxSi,deemaxSi,epsilSi,stminSi);
+
+    AliMaterial(53,"SPD SI BUS$",0.28086E+02,0.14000E+02,0.23300E+01,0.93600E+01,0.99900E+03);
+    AliMedium(53,"SPD SI BUS$",53,0,ifield,fieldm,tmaxfdSi,stemaxSi,deemaxSi,epsilSi,stminSi);
+
+    AliMixture(54,"SPD C (M55J)$",aCM55J,zCM55J,dCM55J,4,wCM55J);
+    AliMedium(54,"SPD C (M55J)$",54,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+    AliMixture(55,"SPD AIR$",aAir,zAir,dAir,4,wAir);
+    AliMedium(55,"SPD AIR$",55,0,ifield,fieldm,tmaxfdAir,stemaxAir,deemaxAir,epsilAir,stminAir);
+
+    AliMixture(56, "SPD KAPTON(POLYCH2)", aKapton, zKapton, dKapton, 4, wKapton);
+    AliMedium(56,"SPD KAPTON(POLYCH2)$",56,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+    // Gaseous Freon has same chemical composition but air density at 1.7 atm
+    AliMixture(59,"GASEOUS FREON$",afre,zfre,1.7*dAir,-2,wfre);
+    AliMedium(59,"GASEOUS FREON$",59,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+    AliMixture(61,"EPOXY$",aEpoxy,zEpoxy,dEpoxy,-3,wEpoxy);
+    AliMedium(61,"EPOXY$",61,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+    AliMaterial(62,"SILICON$",0.28086E+02,0.14000E+02,0.23300E+01,0.93600E+01,0.99900E+03);
+    AliMedium(62,"SILICON$",62,0,ifield,fieldm,tmaxfdSi,stemaxSi,deemaxSi,epsilSi,stminSi);
+
+    AliMixture(63, "KAPTONH(POLYCH2)", aKapton, zKapton, dKapton, 4, wKapton);
+    AliMedium(63,"KAPTONH(POLYCH2)$",63,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+    AliMaterial(64,"ALUMINUM$",0.26982E+02,0.13000E+02,0.26989E+01,0.89000E+01,0.99900E+03);
+    AliMedium(64,"ALUMINUM$",64,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+    AliMixture(65,"INOX$",aINOX,zINOX,dINOX,9,wINOX);
+    AliMedium(65,"INOX$",65,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+    AliMixture(66,"NiSn$",aNiSn,zNiSn,dNiSn,2,wNiSn);
+    AliMedium(66,"NiSn$",66,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+    AliMaterial(67,"Sn$", 118.710, 50., 7.310, 1.206, 999.);
+    AliMedium(67,"Sn$",67,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+    AliMixture(68,"ROHACELL$",arohac,zrohac,drohac,-4,wrohac);
+    AliMedium(68,"ROHACELL$",68,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+     AliMixture(69,"SDD C AL (M55J)$",aALCM55J,zALCM55J,dALCM55J,5,wALCM55J);
+    AliMedium(69,"SDD C AL (M55J)$",69,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+  
+    AliMixture(70, "SDDKAPTON (POLYCH2)", aKapton, zKapton, dKapton, 4, wKapton);
+    AliMedium(70,"SDDKAPTON (POLYCH2)$",70,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+     AliMaterial(71,"ITS SANDW A$",0.12011E+02,0.60000E+01,0.2115E+00,0.17479E+03,0.99900E+03);
+    AliMedium(71,"ITS SANDW A$",71,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+    AliMaterial(72,"ITS SANDW B$",0.12011E+02,0.60000E+01,0.27000E+00,0.18956E+03,0.99900E+03);
+    AliMedium(72,"ITS SANDW B$",72,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+    AliMaterial(73,"ITS SANDW C$",0.12011E+02,0.60000E+01,0.41000E+00,0.90868E+02,0.99900E+03);
+    AliMedium(73,"ITS SANDW C$",73,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+    AliMaterial(74,"HEAT COND GLUE$",0.12011E+02,0.60000E+01,0.1930E+01,0.22100E+02,0.99900E+03);
+    AliMedium(74,"HEAT COND GLUE$",74,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+    AliMaterial(75,"ELASTO SIL$",0.28086E+02,0.14000E+02,0.23300E+01,0.93600E+01,0.99900E+03);
+    AliMedium(75,"ELASTO SIL$",75,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+    // SPD bus (data from Petra Riedler)
+    Float_t aSPDbus[5] = {1.00794,12.0107,14.01,15.9994,26.982 };
+    Float_t zSPDbus[5] = {1.,6.,7.,8.,13.};
+    Float_t wSPDbus[5] = {0.023523,0.318053,0.009776,0.078057,0.570591};
+    Float_t dSPDbus    = 2.128505;
+
+    //   AliMaterial(76,"SPDBUS(AL+KPT+EPOX)$",0.19509E+02,0.96502E+01,0.19060E+01,0.15413E+02,0.99900E+03);
+    AliMixture(76,"SPDBUS(AL+KPT+EPOX)$",aSPDbus,zSPDbus,dSPDbus,5,wSPDbus);
+    AliMedium(76,"SPDBUS(AL+KPT+EPOX)$",76,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+               
+    AliMixture(77,"SDD X7R capacitors$",aX7R,zX7R,dX7R,6,wX7R);
+    AliMedium(77,"SDD X7R capacitors$",77,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+    AliMixture(78,"SDD ruby sph. Al2O3$",aAlOxide,zAlOxide,dAlOxide,2,wAlOxide);
+    AliMedium(78,"SDD ruby sph. Al2O3$",78,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+    AliMaterial(79,"SDD SI insensitive$",0.28086E+02,0.14000E+02,0.23300E+01,0.93600E+01,0.99900E+03);
+    AliMedium(79,"SDD SI insensitive$",79,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+    AliMixture(80,"SDD HV microcable$",aHVm,zHVm,dHVm,5,wHVm);
+    AliMedium(80,"SDD HV microcable$",80,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+    AliMixture(81,"SDD LV+signal cable$",aLVm,zLVm,dLVm,5,wLVm);
+    AliMedium(81,"SDD LV+signal cable$",81,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+    AliMixture(82,"SDD hybrid microcab$",aHLVm, zHLVm,dHLVm,5,wHLVm);
+    AliMedium(82,"SDD hybrid microcab$",82,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+    AliMixture(83,"SDD anode microcab$",aALVm,zALVm,dALVm,5,wALVm);
+    AliMedium(83,"SDD anode microcab$",83,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+    Float_t aDSring[4]={12.0107,      1.00794,     14.0067,      15.9994};
+    Float_t zDSring[4]={ 6.,          1.,           7.,           8.};
+    Float_t wDSring[4]={ 0.854323888, 0.026408778,  0.023050265,  0.096217069};
+    Float_t dDSring = 0.2875;
+    AliMixture(84,"SDD/SSD rings$",aDSring,zDSring,dDSring,4,wDSring);
+    AliMedium(84,"SDD/SSD rings$",84,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+    AliMixture(85,"inox/alum$",aInAl,zInAl,dInAl,5,wInAl);
+    AliMedium(85,"inox/alum$",85,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+    // special media to take into account services in the SDD and SSD 
+    // cones for the FMD
+    //Begin_Html
+    /*
+      <A HREF="http://www.Physics.ohio-state.edu/~nilsen/ITS/ITS_MatBudget_4B.xls">
+      </pre>
+      <br clear=left>
+      <font size=+2 color=blue>
+      <p> The Exel spread sheet from which these density number come from.
+      </font></A>
+    */
+    //End_Html
+
+    Bool_t fByThick = kTRUE;
+    //  AliMaterial(86,"AIRFMDSDD$",0.14610E+02,0.73000E+01,0.12050E-02,0.30423E+05,0.99900E+03);
+    Float_t aA[13],zZ[13],wW[13],den;
+    // From Pierluigi Barberis calculations of 2SPD+1SDD October 2 2002.
+    zZ[0] = 1.0; aA[0] = 1.00794; // Hydrogen
+    zZ[1] = 6.0; aA[1] = 12.011; // Carbon
+    zZ[2] = 7.0; aA[2] = 14.00674; // Nitrogen
+    zZ[3] = 8.0; aA[3] = 15.9994; // Oxigen
+    zZ[4] = 14.0; aA[4] = 28.0855; // Silicon
+    zZ[5] = 24.0; aA[5] = 51.9961; //Cromium
+    zZ[6] = 25.0; aA[6] = 54.938049; // Manganese
+    zZ[7] = 26.0; aA[7] = 55.845; // Iron
+    zZ[8] = 28.0; aA[8] = 58.6934; // Nickle
+    zZ[9] = 29.0; aA[9] = 63.546; // Copper
+    zZ[10] = 13.0; aA[10] = 26.981539; // Alulminum
+    zZ[11] = 47.0; aA[11] = 107.8682; // Silver
+    zZ[12] = 27.0; aA[12] = 58.9332; // Cobolt
+    wW[0] = 0.019965;
+    wW[1] = 0.340961;
+    wW[2] = 0.041225;
+    wW[3] = 0.200352;
+    wW[4] = 0.000386;
+    wW[5] = 0.001467;
+    wW[6] = 0.000155;
+    wW[7] = 0.005113;
+    wW[8] = 0.000993;
+    wW[9] = 0.381262;
+    wW[10] = 0.008121;
+    wW[11] = 0.000000;
+    wW[12] = 0.000000;
+    if(fByThick){// New values seeITS_MatBudget_4B.xls
+       den = 1.5253276; // g/cm^3  Cell O370
+    }else{
+       den = 2.58423412; // g/cm^3 Cell L370
+    } // end if fByThick
+    //den = 6161.7/(3671.58978);//g/cm^3 Volume does not exclude holes
+    AliMixture(86,"AIRFMDSDD$",aA,zZ,den,+11,wW);
+    AliMedium(86,"AIRFMDSDD$",86,0,ifield,fieldm,tmaxfdAir,stemaxAir,
+             deemaxAir,epsilAir,stminAir);
+
+    //AliMaterial(87,"AIRFMDSSD$",0.14610E+02,0.73000E+01,0.12050E-02,0.30423E+05,0.99900E+03);
+    // From Pierluigi Barberis calculations of SSD October 2 2002.
+    wW[0] = 0.019777;
+    wW[1] = 0.325901;
+    wW[2] = 0.031848;
+    wW[3] = 0.147668;
+    wW[4] = 0.030609;
+    wW[5] = 0.013993;
+    wW[6] = 0.001479;
+    wW[7] = 0.048792;
+    wW[8] = 0.009477;
+    wW[9] = 0.350697;
+    wW[10] = 0.014546;
+    wW[11] = 0.005213;
+    wW[12] = 0.000000;
+    if(fByThick){// New values seeITS_MatBudget_4B.xls
+       den = 1.2464275; // g/cm^3   Cell O403
+    }else{
+       den = 1.28134409; // g/cm^3  Cell L403
+    } // end if fByThick
+    //den = 7666.3/(9753.553259); // volume does not exclude holes
+    AliMixture(87,"AIRFMDSSD$",aA,zZ,den,+12,wW); 
+    AliMedium(87,"AIRFMDSSD$",87,0,ifield,fieldm,tmaxfdAir,stemaxAir,
+             deemaxAir,epsilAir,stminAir);
+
+    //AliMaterial(88,"ITS SANDW CFMDSDD$",0.12011E+02,0.60000E+01,0.41000E+00,0.90868E+02,0.99900E+03);
+    // From Pierluigi Barberis calculations of 1SDD+Carbon fiber October 2 2002
+    wW[0] = 0.016302;
+    wW[1] = 0.461870;
+    wW[2] = 0.033662;
+    wW[3] = 0.163595;
+    wW[4] = 0.000315;
+    wW[5] = 0.001197;
+    wW[6] = 0.000127;
+    wW[7] = 0.004175;
+    wW[8] = 0.000811;
+    wW[9] = 0.311315;
+    wW[10] = 0.006631;
+    wW[11] = 0.000000;
+    wW[12] = 0.000000;
+    if(fByThick){// New values seeITS_MatBudget_4B.xls
+       den = 1.9353276; // g/cm^3  Cell N370
+    }else{
+       den = 3.2788626; // g/cm^3 Cell F370
+    } // end if fByThick
+    //den = 7667.1/(3671.58978); // Volume does not excludeholes
+    AliMixture(88,"ITS SANDW CFMDSDD$",aA,zZ,den,+11,wW); 
+    AliMedium(88,"ITS SANDW CFMDSDD$",88,0,ifield,fieldm,tmaxfd,stemax,
+             deemax,epsil,stmin);
+
+    //AliMaterial(89,"ITS SANDW CFMDSSD$",0.12011E+02,0.60000E+01,0.41000E+00,0.90868E+02,0.99900E+03);
+    // From Pierluigi Barberis calculations of SSD+Carbon fiber October 2 2002.
+    wW[0] = 0.014065;
+    wW[1] = 0.520598;
+    wW[2] = 0.022650;
+    wW[3] = 0.105018;
+    wW[4] = 0.021768;
+    wW[5] = 0.009952;
+    wW[6] = 0.001051;
+    wW[7] = 0.034700;
+    wW[8] = 0.006740;
+    wW[9] = 0.249406;
+    wW[10] = 0.010345;
+    wW[11] = 0.0003707;
+    wW[12] = 0.000000;
+    if(fByThick){// New values seeITS_MatBudget_4B.xls
+       den = 1.6564275; // g/cm^3  Cell N304
+    }else{
+       den = 1.7028296; // g/cm^3  Cell F304
+    } // end if fByThick
+    //den = 1166.5/(3671.58978); // Volume does not exclude holes
+    AliMixture(89,"ITS SANDW CFMDSSD$",aA,zZ,den,+12,wW); 
+    AliMedium(89,"ITS SANDW CFMDSSD$",89,0,ifield,fieldm,tmaxfd,stemax,
+             deemax,epsil,stmin);
+
+    //AliMaterial(97,"SPD SERVICES$",0.12011E+02,0.60000E+01,0.41000E+00,0.90868E+02,0.99900E+03);
+    // From Pierluigi Barberis calculations of 1SPD October 2 2002.
+    wW[0] = 0.005970;
+    wW[1] = 0.304704;
+    wW[2] = 0.042510;
+    wW[3] = 0.121715;
+    wW[4] = 0.001118;
+    wW[5] = 0.030948;
+    wW[6] = 0.003270;
+    wW[7] = 0.107910;
+    wW[8] = 0.020960;
+    wW[9] = 0.360895;
+    wW[10] = 0.000000;
+    wW[11] = 0.000000;
+    wW[12] = 0.000000;
+    if(fByThick){// New values seeITS_MatBudget_4B.xls
+       den = 80.31136576; // g/cm^3 Cell H329
+    }else{
+       den = 87.13062; // g/cm^3  Cell G329
+    } // end if fByThick
+    //den = 1251.3/(0.05*2.0*TMath::Pi()*(7.75*7.75 - 3.7*3.7)); // g/cm^3
+    AliMixture(97,"SPD SERVICES$",aA,zZ,den,+10,wW); 
+    AliMedium(97,"SPD SERVICES$",97,0,ifield,fieldm,tmaxfd,stemax,
+             deemax,epsil,stmin);
+
+
+    // Special media
+
+    AliMaterial(90,"SPD shield$", 12.011, 6., 1.93 , 22.36, 999);
+    AliMedium(90,"SPD shield$",90,0,ifield,fieldm,tmaxfdServ,stemaxServ,deemaxServ,epsilServ,stminServ);
+
+    // SPD End Ladder (data from Petra Riedler)
+    Float_t aSPDel[5] = {1.00794,12.0107,14.01,15.9994,63.54 };
+    Float_t zSPDel[5] = {1.,6.,7.,8.,29.};
+    Float_t wSPDel[5] = {0.004092,0.107274,0.011438,0.032476,0.844719};
+    Float_t dSPDel    = 3.903403;
+
+    //   AliMaterial(91, "SPD End ladder$", 47.0447, 21.7963, 3.6374, 4.4711, 999); 
+    AliMixture(91,"SPD End ladder$",aSPDel,zSPDel,dSPDel,5,wSPDel);
+    AliMedium(91,"SPD End ladder$",91,0,ifield,fieldm,tmaxfdServ,stemaxServ,deemaxServ,epsilServ,stminServ);
+
+    AliMaterial(92, "SPD cone$",28.0855, 14., 2.33, 9.36, 999);    
+    AliMedium(92,"SPD cone$",92,0,ifield,fieldm,tmaxfdServ,stemaxServ,deemaxServ,epsilServ,stminServ);
+    /*  Material with fractional Z not actually used
+    AliMaterial(93, "SDD End ladder$", 69.9298, 29.8246, 0.3824, 36.5103, 999);
+    AliMedium(93,"SDD End ladder$",93,0,ifield,fieldm,tmaxfdServ,stemaxServ,deemaxServ,epsilServ,stminServ);
+    */
+    AliMaterial(94, "SDD cone$",63.546, 29., 1.15, 1.265, 999);
+    AliMedium(94,"SDD cone$",94,0,ifield,fieldm,tmaxfdServ,stemaxServ,deemaxServ,epsilServ,stminServ);
+    /* Material with fractional Z not actually used
+    AliMaterial(95, "SSD End ladder$", 32.0988, 15.4021, 0.68, 35.3238, 999); 
+    AliMedium(95,"SSD End ladder$",95,0,ifield,fieldm,tmaxfdServ,stemaxServ,deemaxServ,epsilServ,stminServ);
+    */
+    AliMaterial(96, "SSD cone$",63.546, 29., 1.15, 1.265, 999);
+    AliMedium(96,"SSD cone$",96,0,ifield,fieldm,tmaxfdServ,stemaxServ,deemaxServ,epsilServ,stminServ);
+
+    AliMixture(98,"SDD OPTICFIB$",aoptfib,zoptfib,doptfib,-2,woptfib);
+    AliMedium(98,"SDD OPTICFIB$",98,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+    AliMixture(95,"SSD FEP$",aFEP,zFEP,dFEP,-2,wFEP);
+    AliMedium(95,"SSD FEP$",95,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+    // Mean material for low-voltage cables on SPD trays Side A
+    // (Copper + PolyEthylene (C2-H4)) (D.Elia for cable number and
+    // cross-section area, M.Sitta for elemental computation) - 26 Feb 10
+    wW[0] = 0.323024;//H
+    wW[2] = 0.515464;//Cu
+    wW[1] = 0.161512;//C
+    wW[3] = 0.000000;//O
+    wW[4] = 0.000000;//S
+    wW[5] = 0.000000;//F
+    wW[6] = 0.000000;//Sn
+    wW[7] = 0.000000;//Pb
+    wW[8] = 0.000000;//Cr
+    wW[9] = 0.000000;//Si
+    wW[10] = 0.000000;//Ni
+    wW[11] = 0.000000;//Ca
+
+    den = 5.078866;
+    AliMixture(60,"SPD_LOWCABLES$",aA,zZ,den,+3,wW);
+    AliMedium(60,"SPD_LOWCABLES$",60,0,ifield,fieldm,tmaxfd,stemax,
+             deemax,epsil,stmin);
+
+    // Mean material for high-voltage cables on SPD trays Side A & C
+    // (Copper + HD PolyEthylene (C2-H2)) (D.Elia for cable number and
+    // cross-section area, M.Sitta for elemental computation) - 10 Jun 10
+    wW[0] = 0.083766;//H
+    wW[2] = 0.417136;//Cu
+    wW[1] = 0.499098;//C
+    wW[3] = 0.000000;//O
+    wW[4] = 0.000000;//S
+    wW[5] = 0.000000;//F
+    wW[6] = 0.000000;//Sn
+    wW[7] = 0.000000;//Pb
+    wW[8] = 0.000000;//Cr
+    wW[9] = 0.000000;//Si
+    wW[10] = 0.000000;//Ni
+    wW[11] = 0.000000;//Ca
+
+    den = 1.514930;
+    AliMixture(58,"SPD_HICABLES$",aA,zZ,den,+3,wW);
+    AliMedium(58,"SPD_HICABLES$",58,0,ifield,fieldm,tmaxfd,stemax,
+             deemax,epsil,stmin);
+
+    // PolyUrethane [C25-H42-N2-O6] - 07 Mar 10
+    zZ[2] =  7.0; aA[2] =  14.0067; // Nitrogen - From Root TGeoElementTable
+
+    wW[0] = 0.090724;//H
+    wW[2] = 0.060035;//N
+    wW[1] = 0.643513;//C
+    wW[3] = 0.205728;//O
+    wW[4] = 0.000000;//S
+    wW[5] = 0.000000;//F
+    wW[6] = 0.000000;//Sn
+    wW[7] = 0.000000;//Pb
+    wW[8] = 0.000000;//Cr
+    wW[9] = 0.000000;//Si
+    wW[10] = 0.000000;//Ni
+    wW[11] = 0.000000;//Ca
+
+    den = 1.158910;
+    AliMixture(67,"POLYURETHANE$",aA,zZ,den,+4,wW);
+    AliMedium(67,"POLYURETHANE$",67,0,ifield,fieldm,tmaxfd,stemax,
+             deemax,epsil,stmin);
+
+    //  POM (Polyoxymethylene = (CH2O)n ) - 02 May 10
+    zZ[2] =  8.0; aA[2] =  15.9994; // Oxigen
+
+    wW[0] = 0.067137;//H
+    wW[1] = 0.400016;//C
+    wW[2] = 0.532847;//O
+    wW[3] = 0.000000;//O
+    wW[4] = 0.000000;//S
+    wW[5] = 0.000000;//F
+    wW[6] = 0.000000;//Sn
+    wW[7] = 0.000000;//Pb
+    wW[8] = 0.000000;//Cr
+    wW[9] = 0.000000;//Si
+    wW[10] = 0.000000;//Ni
+    wW[11] = 0.000000;//Ca
+
+    den = 1.4200;
+    AliMixture(57,"POLYOXYMETHYLENE$",aA,zZ,den,+3,wW);
+    AliMedium(57,"POLYOXYMETHYLENE$",57,0,ifield,fieldm,tmaxfd,stemax,
+             deemax,epsil,stmin);
+
+
+    // Anticorodal (Aliminum alloy) - 08 nov 10
+    // A,Z from Root TGeoElementTable, W from Web sites
+    zZ[0] = 13.0; aA[0] =  26.9815; // Aluminium
+    zZ[1] = 29.0; aA[1] =  63.546 ; // Copper
+    zZ[2] = 26.0; aA[2] =  55.845 ; // Iron
+    zZ[3] = 25.0; aA[3] =  54.938 ; // Manganese
+    zZ[4] = 12.0; aA[4] =  24.305 ; // Magnesium
+    zZ[5] = 14.0; aA[5] =  28.0855; // Silicon
+    zZ[6] = 30.0; aA[6] =  65.39  ; // Zinc
+    zZ[7] = 24.0; aA[7] =  51.9961; // Chromium
+    zZ[8] = 22.0; aA[8] =  47.867 ; // Titanium
+
+    wW[1] = 0.001000;//Cu
+    wW[2] = 0.005000;//Fe
+    wW[3] = 0.007000;//Mn - mean value
+    wW[4] = 0.009000;//Mg - mean value
+    wW[5] = 0.001000;//Si - mean value
+    wW[6] = 0.002000;//Zn
+    wW[7] = 0.002500;//Cr
+    wW[8] = 0.001000;//Ti
+
+    Double_t totFrac = 0;
+    for (Int_t j=1; j<9; j++)
+      totFrac += wW[j];
+    wW[0] = 1. - totFrac;//Al - the remainder
+
+    den = 2.69;
+    AliMixture(93,"ANTICORODAL$",aA,zZ,den,+9,wW);
+    AliMedium(93,"ANTICORODAL$",93,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+    // Hokotol (another Aluminium alloy) - 08 nov 10
+    // A,Z from Root TGeoElementTable, W from Web sites
+    zZ[0] = 13.0; aA[0] =  26.9815; // Aluminium
+    zZ[1] = 29.0; aA[1] =  63.546 ; // Copper
+    zZ[2] = 26.0; aA[2] =  55.845 ; // Iron
+    zZ[3] = 25.0; aA[3] =  54.938 ; // Manganese
+    zZ[4] = 12.0; aA[4] =  24.305 ; // Magnesium
+    zZ[5] = 14.0; aA[5] =  28.0855; // Silicon
+    zZ[6] = 30.0; aA[6] =  65.39  ; // Zinc
+    zZ[7] = 24.0; aA[7] =  51.9961; // Chromium
+    zZ[8] = 22.0; aA[8] =  47.867 ; // Titanium
+    zZ[9] = 40.0; aA[9] =  91.224 ; // Zirconium
+
+    wW[1] = 0.020500;//Cu - mean value
+    wW[2] = 0.000300;//Fe
+    wW[3] = 0.022000;//Mn - mean value
+    wW[4] = 0.001000;//Mg - mean value
+    wW[5] = 0.002000;//Si - mean value
+    wW[6] = 0.066500;//Zn
+    wW[7] = 0.005000;//Cr
+    wW[8] = 0.000600;//Ti
+    wW[9] = 0.001650;//Zr - mean value
+
+    totFrac = 0;
+    for (Int_t j=1; j<10; j++)
+      totFrac += wW[j];
+    wW[0] = 1. - totFrac;//Al - the remainder
+
+    den = 2.69;
+    AliMixture(34,"HOKOTOL$",aA,zZ,den,+10,wW);
+    AliMedium(34,"HOKOTOL$",34,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+    // Ergal (7075) (yet another Aluminium alloy) - 09 nov 10
+    // A,Z from Root TGeoElementTable, W from Web sites
+    zZ[0] = 13.0; aA[0] =  26.9815; // Aluminium
+    zZ[1] = 29.0; aA[1] =  63.546 ; // Copper
+    zZ[2] = 26.0; aA[2] =  55.845 ; // Iron
+    zZ[3] = 25.0; aA[3] =  54.938 ; // Manganese
+    zZ[4] = 12.0; aA[4] =  24.305 ; // Magnesium
+    zZ[5] = 14.0; aA[5] =  28.0855; // Silicon
+    zZ[6] = 30.0; aA[6] =  65.39  ; // Zinc
+    zZ[7] = 24.0; aA[7] =  51.9961; // Chromium
+    zZ[8] = 22.0; aA[8] =  47.867 ; // Titanium
+
+    wW[1] = 0.016000;//Cu - mean value
+    wW[2] = 0.005000;//Fe
+    wW[3] = 0.003000;//Mn
+    wW[4] = 0.025000;//Mg - mean value
+    wW[5] = 0.004000;//Si
+    wW[6] = 0.056000;//Zn - mean value
+    wW[7] = 0.002300;//Cr - mean value
+    wW[8] = 0.002000;//Ti
+
+    totFrac = 0;
+    for (Int_t j=1; j<9; j++)
+      totFrac += wW[j];
+    wW[0] = 1. - totFrac;//Al - the remainder
+
+    den = 2.69;
+    AliMixture(33,"ERGAL$",aA,zZ,den,+9,wW);
+    AliMedium(33,"ERGAL$",33,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+    
+}
+
+//______________________________________________________________________
+void AliITSvUpgrade::DefineLayer(const Int_t nlay, const Double_t r,
+                                const Double_t zlen, const Int_t nladd,
+                                const Int_t nmod, const Double_t lthick,
+                                const Double_t dthick){
+    //     Sets the layer parameters
+    // Inputs:
+    //          nlay    layer number
+    //          r       layer radius
+    //          zlen    layer length
+    //          nladd   number of ladders
+    //          nmod    number of modules per ladder
+    //          lthick  ladder thickness (if omitted, defaults to 0)
+    //          dthick  detector thickness (if omitted, defaults to 0)
+    // Outputs:
+    //   none.
+    // Return:
+    //   none.
+
+    if (nlay >= fNumberOfLayers || nlay < 0) {
+      AliError(Form("Wrong layer number (%d)",nlay));
+      return;
+    }
+
+    fLayTurbo[nlay] = kFALSE;
+    fLayRadii[nlay] = r;
+    fLayZLength[nlay] = zlen;
+    fLaddPerLay[nlay] = nladd;
+    fModPerLadd[nlay] = nmod;
+    fLadThick[nlay] = lthick;
+    fDetThick[nlay] = dthick;
+}
+
+//______________________________________________________________________
+void AliITSvUpgrade::DefineLayerTurbo(const Int_t nlay, const Double_t r,
+                                     const Double_t zlen, const Int_t nladd,
+                                     const Int_t nmod, const Double_t width,
+                                     const Double_t tilt,
+                                     const Double_t lthick,
+                                     const Double_t dthick){
+    //     Sets the layer parameters for a "turbo" layer
+    //     (i.e. a layer whose ladders overlap in phi)
+    // Inputs:
+    //          nlay    layer number
+    //          r       layer radius
+    //          zlen    layer length
+    //          nladd   number of ladders
+    //          nmod    number of modules per ladder
+    //          width   layer width
+    //          tilt    layer tilt angle (degrees)
+    //          lthick  ladder thickness (if omitted, defaults to 0)
+    //          dthick  detector thickness (if omitted, defaults to 0)
+    // Outputs:
+    //   none.
+    // Return:
+    //   none.
+
+    if (nlay >= fNumberOfLayers || nlay < 0) {
+      AliError(Form("Wrong layer number (%d)",nlay));
+      return;
+    }
+
+    fLayTurbo[nlay] = kTRUE;
+    fLayRadii[nlay] = r;
+    fLayZLength[nlay] = zlen;
+    fLaddPerLay[nlay] = nladd;
+    fModPerLadd[nlay] = nmod;
+    fLadThick[nlay] = lthick;
+    fLadWidth[nlay] = width;
+    fLadTilt[nlay] = tilt;
+    fDetThick[nlay] = dthick;
+}
+
+//______________________________________________________________________
+void AliITSvUpgrade::GetLayerParameters(const Int_t nlay,
+                                       Double_t &r, Double_t &zlen,
+                                       Int_t &nladd, Int_t &nmod,
+                                       Double_t &width, Double_t &tilt,
+                                       Double_t &lthick, Double_t &dthick){
+    //     Gets the layer parameters
+    // Inputs:
+    //          nlay    layer number
+    // Outputs:
+    //          r       layer radius
+    //          zlen    layer length
+    //          nladd   number of ladders
+    //          nmod    number of modules per ladder
+    //          width   ladder width
+    //          tilt    ladder tilt angle
+    //          lthick  ladder thickness
+    //          dthick  detector thickness
+    // Return:
+    //   none.
+
+    if (nlay >= fNumberOfLayers || nlay < 0) {
+      AliError(Form("Wrong layer number (%d)",nlay));
+      return;
+    }
+
+    r = fLayRadii[nlay];
+    zlen = fLayZLength[nlay];
+    nladd = fLaddPerLay[nlay];
+    nmod = fModPerLadd[nlay];
+    width = fLadWidth[nlay];
+    tilt = fLadTilt[nlay];
+    lthick = fLadThick[nlay];
+    dthick = fDetThick[nlay];
+}
+
+//______________________________________________________________________
+void AliITSvUpgrade::Init(){
+    //     Initialise the ITS after it has been created.
+    // Inputs:
+    //   none.
+    // Outputs:
+    //   none.
+    // Return:
+    //   none.
+
+    AliDebug(1,Form("Init: Major version %d Minor version %d",fMajorVersion,
+                fMinorVersion));
+    UpdateInternalGeometry();
+    AliITSUpg::Init();
+
+}
+
+//______________________________________________________________________
+Bool_t AliITSvUpgrade::IsLayerTurbo(const Int_t nlay){
+    //     Returns true if the layer is a "turbo" layer
+    // Inputs:
+    //          nlay    layer number
+    // Outputs:
+    //   none.
+    // Return:
+    //          kTRUE if the layer is a turbo layer
+
+    if ( nlay < 0 || nlay > fNumberOfLayers ) {
+      AliError(Form("Wrong layer number %d",nlay));
+      return kFALSE;
+    } else
+      return fUpGeom[nlay]->IsTurbo();
+
+}
+
+//______________________________________________________________________
+void AliITSvUpgrade::SetDefaults(){
+    // sets the default segmentation, response, digit and raw cluster classes
+    // Inputs:
+    //   none.
+    // Outputs:
+    //   none.
+    // Return:
+    //   none.
+
+    if(!fDetTypeSim){
+       Warning("SetDefaults","Error fDetTypeSim not defined");
+       return;
+    }
+
+    fDetTypeSim->SetDefaults();
+
+    return;
+}
+
+//______________________________________________________________________
+void AliITSvUpgrade::StepManager(){
+    //    Called for every step in the ITS, then calles the AliITShit class
+    // creator with the information to be recoreded about that hit.
+    //     The value of the macro ALIITSPRINTGEOM if set to 1 will allow the
+    // printing of information to a file which can be used to create a .det
+    // file read in by the routine CreateGeometry(). If set to 0 or any other
+    // value except 1, the default behavior, then no such file is created nor
+    // it the extra variables and the like used in the printing allocated.
+    // Inputs:
+    //   none.
+    // Outputs:
+    //   none.
+    // Return:
+    //   none.
+
+    if(!(this->IsActive())) return;
+    if(!(gMC->TrackCharge())) return;
+
+    Int_t copy, lay = 0;
+    Int_t id = gMC->CurrentVolID(copy);
+
+    Bool_t notSens = kFALSE;
+    while ((lay<fIdN)  && (notSens = id != fIdSens[lay])) ++lay;
+    if (notSens) return;
+
+    if(gMC->IsTrackExiting()) {
+       AddTrackReference(gAlice->GetMCApp()->GetCurrentTrackNumber(), AliTrackReference::kITS);
+    } // if Outer ITS mother Volume
+
+    static TLorentzVector position, momentum; // Saves on calls to construtors
+    static AliITShit hit;// Saves on calls to constructors
+
+    TClonesArray &lhits = *(Hits());
+    Int_t   cpn0, cpn1, mod, status = 0;
+    //
+    // Track status
+    if(gMC->IsTrackInside())      status +=  1;
+    if(gMC->IsTrackEntering())    status +=  2;
+    if(gMC->IsTrackExiting())     status +=  4;
+    if(gMC->IsTrackOut())         status +=  8;
+    if(gMC->IsTrackDisappeared()) status += 16;
+    if(gMC->IsTrackStop())        status += 32;
+    if(gMC->IsTrackAlive())       status += 64;
+
+    //
+    // retrieve the indices with the volume path
+    //
+    if (lay < 0 || lay > fIdN) {
+      AliError(Form("Invalid value: lay=%d. Not an ITS sensitive volume",lay));
+      return; // not an ITS sensitive volume.
+    } else {
+      copy = 1;
+      gMC->CurrentVolOffID(1,cpn1);
+      gMC->CurrentVolOffID(2,cpn0);
+    } //
+
+    fInitGeom.DecodeDetector(mod,lay,cpn0,cpn1,copy);
+    // We should not need to pass by the switch !
+    // This is time consuming...
+    // therefore DecodeDetectorv11Upgrade(...) shouldn't be private !
+    // and we should be able to use instead :
+    //fInitGeom.DecodeDetectorv11Upgrade(mod,lay+1,cpn0,cpn1,copy);
+
+    //
+    // Fill hit structure.
+    //
+    hit.SetModule(mod);
+    hit.SetTrack(gAlice->GetMCApp()->GetCurrentTrackNumber());
+    gMC->TrackPosition(position);
+    gMC->TrackMomentum(momentum);
+    hit.SetPosition(position);
+    hit.SetTime(gMC->TrackTime());
+    hit.SetMomentum(momentum);
+    hit.SetStatus(status);
+    hit.SetEdep(gMC->Edep());
+    hit.SetShunt(GetIshunt());
+    if(gMC->IsTrackEntering()){
+        hit.SetStartPosition(position);
+        hit.SetStartTime(gMC->TrackTime());
+        hit.SetStartStatus(status);
+        return; // don't save entering hit.
+    } // end if IsEntering
+    // Fill hit structure with this new hit.
+    //Info("StepManager","Calling Copy Constructor");
+    new(lhits[fNhits++]) AliITShit(hit); // Use Copy Construtor.
+    // Save old position... for next hit.
+    hit.SetStartPosition(position);
+    hit.SetStartTime(gMC->TrackTime());
+    hit.SetStartStatus(status);
+
+    return;
+}
+
diff --git a/ITS/UPGRADE/AliITSvUpgrade.h b/ITS/UPGRADE/AliITSvUpgrade.h
new file mode 100644 (file)
index 0000000..0d553a6
--- /dev/null
@@ -0,0 +1,93 @@
+#ifndef ALIITSVUPGRADE_H
+#define ALIITSVUPGRADE_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+//========================================================================
+//
+//        Geometry for the Upgrade of the Inner Tracking System
+//
+// Mario Sitta (sitta@to.infn.it)
+//
+//========================================================================
+
+
+// $Id: AliITSvUpgrade.h 
+
+#include "AliITSUpg.h"
+#include "AliITSInitGeometryUpg.h"
+
+class  AliITSv11GeometryUpgrade;
+class  TGeoVolume;
+class  TGeoVolumeAssembly;
+
+class AliITSvUpgrade : public AliITSUpg {
+
+ public:
+    AliITSvUpgrade();
+    AliITSvUpgrade(const char *title);
+    AliITSvUpgrade(const char *name, const char *title, const Int_t nlay);
+    virtual       ~AliITSvUpgrade() ;
+
+    virtual void   AddAlignableVolumes() const;
+    virtual void   CreateGeometry();
+    virtual void   CreateMaterials();
+    virtual void   DefineLayer(const Int_t nlay, const Double_t r,
+                              const Double_t zlen, const Int_t nladd,
+                              const Int_t nmod, const Double_t lthick = 0.,
+                              const Double_t dthick = 0.);
+    virtual void   DefineLayerTurbo(const Int_t nlay, const Double_t r,
+                                   const Double_t zlen, const Int_t nladd,
+                                   const Int_t nmod, const Double_t width,
+                                   const Double_t tilt,
+                                   const Double_t lthick = 0.,
+                                   const Double_t dthick = 0.);
+    virtual void   GetLayerParameters(const Int_t nlay,
+                                     Double_t &r, Double_t &zlen,
+                                     Int_t &nladd, Int_t &nmod,
+                                     Double_t &width, Double_t &tilt,
+                                     Double_t &lthick, Double_t &mthick);
+    virtual Int_t  GetMajorVersion() const {return fMajorVersion;}
+    virtual Int_t  GetMinorVersion() const {return fMinorVersion;}
+    virtual Int_t  GetNumberOfLayers() const {return fNumberOfLayers;}
+    virtual void   Init(); 
+    virtual Bool_t IsLayerTurbo(const Int_t nlay);
+    virtual Int_t  IsVersion() const {// returns the ITS version number 
+                                      return 20;}  // vUpgrade
+    virtual void   SetDefaults();
+    virtual void   SetMinorVersion(Int_t v=2) {fMinorVersion = v;}
+    virtual void   SetNumberOfLayers(Int_t n) {fNumberOfLayers = n;}
+    virtual void   StepManager();
+
+ protected:
+    void SetT2Lmatrix(Int_t uid, Double_t yShift,
+                     Bool_t yFlip, Bool_t yRot180=kFALSE) const; // Set T2L matrix in TGeoPNEntries
+
+ private:
+    AliITSvUpgrade(const AliITSvUpgrade &source); // copy constructor
+    AliITSvUpgrade& operator=(const AliITSvUpgrade &source); // assignment operator
+
+    Int_t   fMajorVersion;     // Major version number == IsVersion
+    Int_t   fMinorVersion;     // Minor version number
+
+    Int_t   fNumberOfLayers;   // Number of layers
+    Bool_t   *fLayTurbo;       // True for "turbo" layers
+    Double_t *fLayRadii;       // Vector of layer radii
+    Double_t *fLayZLength;     // Vector of layer length along Z
+    Int_t    *fLaddPerLay;     // Vector of number of ladders per layer
+    Int_t    *fModPerLadd;     // Vector of number of modules per ladder
+    Double_t *fLadThick;       // Vector of ladder thicknesses
+    Double_t *fLadWidth;       // Vector of ladder width (only used for turbo)
+    Double_t *fLadTilt;        // Vector of ladder tilt (only used for turbo)
+    Double_t *fDetThick;       // Vector of detector thicknesses
+
+    AliITSInitGeometryUpg fInitGeom;   //! Get access to decoding and AliITSgeom init functins
+
+    AliITSv11GeometryUpgrade **fUpGeom; //! Geometry
+
+  // Parameters for the Upgrade geometry
+
+    ClassDef(AliITSvUpgrade,0)                          
+};
+#endif
diff --git a/ITS/UPGRADE/ConfigTGeoUpgrade.C b/ITS/UPGRADE/ConfigTGeoUpgrade.C
new file mode 100644 (file)
index 0000000..e4f543e
--- /dev/null
@@ -0,0 +1,385 @@
+/// One can use the configuration macro in compiled mode by
+// root [0] gSystem->Load("libgeant321");
+// root [0] gSystem->SetIncludePath("-I$ROOTSYS/include -I$ALICE_ROOT/include\
+//                   -I$ALICE_ROOT -I$ALICE/geant3/TGeant3");
+// root [0] .x grun.C(1,"Config.C++"
+
+#if !defined(__CINT__) || defined(__MAKECINT__)
+#include <Riostream.h>
+#include <TPDGCode.h>
+#include <TRandom.h>
+#include <TSystem.h>
+#include <TVirtualMC.h>
+#include <TGeant3TGeo.h>
+#include "STEER/AliRunLoader.h"
+#include "STEER/AliRun.h"
+#include "STEER/AliConfig.h"
+#include "PYTHIA6/AliDecayerPythia.h"
+#include "EVGEN/AliGenCocktail.h"
+#include "EVGEN/AliGenHIJINGpara.h"
+#include "EVGEN/AliGenFixed.h"
+#include "EVGEN/AliGenBox.h"
+#include "STEER/AliMagWrapCheb.h"
+#include "STRUCT/AliBODY.h"
+#include "STRUCT/AliMAG.h"
+#include "STRUCT/AliABSOv3.h"
+#include "STRUCT/AliDIPOv3.h"
+#include "STRUCT/AliHALLv3.h"
+#include "STRUCT/AliFRAMEv2.h"
+#include "STRUCT/AliSHILv3.h"
+#include "STRUCT/AliPIPEv3.h"
+#include "ITS/AliITSv11Hybrid.h"
+#include "ITS/UPGRADE/AliITSvUpgrade.h"
+#include "TPC/AliTPCv2.h"
+#include "TOF/AliTOFv6T0.h"
+#include "HMPID/AliHMPIDv3.h"
+#include "ZDC/AliZDCv3.h"
+#include "TRD/AliTRDv1.h"
+#include "TRD/AliTRDgeometry.h"
+#include "FMD/AliFMDv1.h"
+#include "MUON/AliMUONv1.h"
+#include "PHOS/AliPHOSv1.h"
+#include "PMD/AliPMDv1.h"
+#include "T0/AliT0v1.h"
+#include "EMCAL/AliEMCALv2.h"
+#include "ACORDE/AliACORDEv1.h"
+#include "VZERO/AliVZEROv7.h"
+#include <TVirtualMagField.h>
+#endif
+
+/* $Id: Config.C 47147 2011-02-07 11:46:44Z amastros $ */
+enum PprTrigConf_t
+{
+  kDefaultPPTrig, kDefaultPbPbTrig
+};
+
+const char * pprTrigConfName[] = {
+  "p-p","Pb-Pb"
+};
+
+Float_t EtaToTheta(Float_t arg);
+
+static PprTrigConf_t strig = kDefaultPPTrig;// default PP trigger configuration
+
+void Config()
+{
+  // ThetaRange is (0., 180.). It was (0.28,179.72) 7/12/00 09:00
+  // Theta range given through pseudorapidity limits 22/6/2001
+
+  // Set Random Number seed
+  gRandom->SetSeed(0); // Set 0 to use the currecnt time
+
+
+  // libraries required by geant321
+#if defined(__CINT__)
+  gSystem->Load("liblhapdf");
+  gSystem->Load("libEGPythia6");
+  gSystem->Load("libpythia6");
+  gSystem->Load("libAliPythia6");
+  gSystem->Load("libgeant321");
+#endif
+
+  new     TGeant3TGeo("C++ Interface to Geant3");
+
+  AliRunLoader* rl=0x0;
+
+
+  rl = AliRunLoader::Open("galice.root",
+                         AliConfig::GetDefaultEventFolderName(),
+                         "recreate");
+  if (rl == 0x0)
+    {
+      gAlice->Fatal("Config.C","Can not instatiate the Run Loader");
+      return;
+    }
+  rl->SetCompressionLevel(2);
+  rl->SetNumberOfEventsPerFile(2000);
+  gAlice->SetRunLoader(rl);
+
+  // Set the trigger configuration
+  // gAlice->SetTriggerDescriptor(pprTrigConfName[strig]);
+  //cout<<"Trigger configuration is set to  "<<pprTrigConfName[strig]<<endl;
+  AliSimulation::Instance()->SetTriggerConfig(pprTrigConfName[strig]);
+  cout<<"Trigger configuration is set to  pprTrigConfName[strig] "<<endl;
+
+  //
+  // Set External decayer
+  TVirtualMCDecayer *decayer = new AliDecayerPythia();
+
+  decayer->SetForceDecay(kAll);
+  decayer->Init();
+  gMC->SetExternalDecayer(decayer);
+  //=======================================================================
+  // ************* STEERING parameters FOR ALICE SIMULATION **************
+  // --- Specify event type to be tracked through the ALICE setup
+  // --- All positions are in cm, angles in degrees, and P and E in GeV
+
+
+  gMC->SetProcess("DCAY",1);
+  gMC->SetProcess("PAIR",1);
+  gMC->SetProcess("COMP",1);
+  gMC->SetProcess("PHOT",1);
+  gMC->SetProcess("PFIS",0);
+  gMC->SetProcess("DRAY",0);
+  gMC->SetProcess("ANNI",1);
+  gMC->SetProcess("BREM",1);
+  gMC->SetProcess("MUNU",1);
+  gMC->SetProcess("CKOV",1);
+  gMC->SetProcess("HADR",0);
+  gMC->SetProcess("LOSS",2);
+  gMC->SetProcess("MULS",1);
+  gMC->SetProcess("RAYL",1);
+
+  Float_t cut = 1.e-3;        // 1MeV cut by default
+  Float_t tofmax = 1.e10;
+
+  gMC->SetCut("CUTGAM", cut);
+  gMC->SetCut("CUTELE", cut);
+  gMC->SetCut("CUTNEU", cut);
+  gMC->SetCut("CUTHAD", cut);
+  gMC->SetCut("CUTMUO", cut);
+  gMC->SetCut("BCUTE",  cut); 
+  gMC->SetCut("BCUTM",  cut); 
+  gMC->SetCut("DCUTE",  cut); 
+  gMC->SetCut("DCUTM",  cut); 
+  gMC->SetCut("PPCUTM", cut);
+  gMC->SetCut("TOFMAX", tofmax); 
+
+  // Special generation for Valgrind tests
+  // Each detector is fired by few particles selected 
+  // to cover specific cases
+
+
+  // The cocktail itself
+
+  AliGenCocktail *gener = new AliGenCocktail();
+  gener->SetPhiRange(0, 360);
+  // Set pseudorapidity range from -8 to 8.
+  Float_t thmin = EtaToTheta(8);   // theta min. <---> eta max
+  Float_t thmax = EtaToTheta(-8);  // theta max. <---> eta min 
+  gener->SetThetaRange(thmin,thmax);
+  gener->SetOrigin(0., 0., 0);  //vertex position
+  gener->SetSigma(0., 0., 0);   //Sigma in (X,Y,Z) (cm) on IP position
+
+  AliGenBox *gbox2 = new AliGenBox(1);
+  gbox2->SetPtRange(0.99,1.0001);  //
+  gbox2->SetPhiRange(0,360.);
+  gbox2->SetThetaRange(40.,140.);
+  gbox2->SetPart(kPiMinus);
+  gener->AddGenerator(gbox2,"GENBOX PIONS for ITS",1);
+
+    
+    
+  gener->Init();
+
+
+  // 
+  // Activate this line if you want the vertex smearing to happen
+  // track by track
+  //
+  //VertexSmear_t perTrack;
+  //gener->SetVertexSmear(perTrack); 
+  // Field (L3 0.5 T)
+  //AliMagF* field = new AliMagF("map","map",2, -1.,1., 15, AliMagF::k5kGUniform);
+  //TGeoGlobalMagField::Instance()->SetField(field);
+  TGeoGlobalMagField::Instance()->SetField(new AliMagF("Maps","Maps", -1., -1., AliMagF::k5kG));
+
+  Int_t   iABSO  =  0;
+  Int_t   iDIPO  =  0;
+  Int_t   iFMD   =  0;
+  Int_t   iFRAME =  0;
+  Int_t   iHALL  =  0;
+  Int_t   iITS   =  1;
+  Int_t   iMAG   =  0;
+  Int_t   iMUON  =  0;
+  Int_t   iPHOS  =  0;
+  Int_t   iPIPE  =  0;
+  Int_t   iPMD   =  0;
+  Int_t   iHMPID  =  0;
+  Int_t   iSHIL  =  0;
+  Int_t   iT0 =  0;
+  Int_t   iTOF   =  0;
+  Int_t   iTPC   =  0;
+  Int_t   iTRD   =  0;
+  Int_t   iZDC   =  0;
+  Int_t   iEMCAL =  0;
+  Int_t   iACORDE   =  0;
+  Int_t   iVZERO =  0;
+  rl->CdGAFile();
+  //=================== Alice BODY parameters =============================
+  AliBODY *BODY = new AliBODY("BODY", "Alice envelop");
+
+  if (iMAG)
+    {
+      //=================== MAG parameters ============================
+      // --- Start with Magnet since detector layouts may be depending ---
+      // --- on the selected Magnet dimensions ---
+      AliMAG *MAG = new AliMAG("MAG", "Magnet");
+    }
+
+
+  if (iABSO)
+    {
+      //=================== ABSO parameters ============================
+      AliABSO *ABSO = new AliABSOv3("ABSO", "Muon Absorber");
+    }
+
+  if (iDIPO)
+    {
+      //=================== DIPO parameters ============================
+
+      AliDIPO *DIPO = new AliDIPOv3("DIPO", "Dipole version 3");
+    }
+
+  if (iHALL)
+    {
+      //=================== HALL parameters ============================
+
+      AliHALL *HALL = new AliHALLv3("HALL", "Alice Hall");
+    }
+
+
+  if (iFRAME)
+    {
+      //=================== FRAME parameters ============================
+
+      AliFRAMEv2 *FRAME = new AliFRAMEv2("FRAME", "Space Frame");
+      FRAME->SetHoles(1);
+    }
+
+  if (iSHIL)
+    {
+      //=================== SHIL parameters ============================
+
+      AliSHIL *SHIL = new AliSHILv3("SHIL", "Shielding Version 3");
+    }
+
+
+  if (iPIPE)
+    {
+      //=================== PIPE parameters ============================
+
+      AliPIPE *PIPE = new AliPIPEv3("PIPE", "Beam Pipe");
+    }
+  if (iITS)
+    {
+      //=================== ITS parameters ============================
+      Bool_t isUpgrade = kTRUE;
+//      AliITS *ITS = 0x0;
+      if(isUpgrade) {
+       AliITSvUpgrade *ITS  = new AliITSvUpgrade("ITS","ITS Upgrade",4);
+       ITS->DefineLayer(0, 4.0, 14.1, 10, 6);
+       ITS->DefineLayer(1, 7.6, 14.1, 10, 6);
+       ITS->DefineLayerTurbo(2,14.9, 22.2, 12, 8, 4.8, 10);
+       ITS->DefineLayer(3,23.8, 29.7, 16, 8);
+      }
+      else AliITS *ITS = new AliITSv11Hybrid("ITS","ITS v11Hybrid");
+    
+    }
+
+
+  if (iTPC)
+    {
+      //============================ TPC parameters ===================
+      AliTPC *TPC = new AliTPCv2("TPC", "Default");
+    }
+
+
+  if (iTOF) {
+    //=================== TOF parameters ============================
+    AliTOF *TOF = new AliTOFv6T0("TOF", "normal TOF");
+  }
+
+
+  if (iHMPID)
+    {
+      //=================== HMPID parameters ===========================
+      AliHMPID *HMPID = new AliHMPIDv3("HMPID", "normal HMPID");
+
+    }
+
+
+  if (iZDC)
+    {
+      //=================== ZDC parameters ============================
+
+      AliZDC *ZDC = new AliZDCv3("ZDC", "normal ZDC");
+    }
+
+  if (iTRD)
+    {
+      //=================== TRD parameters ============================
+
+      AliTRD *TRD = new AliTRDv1("TRD", "TRD slow simulator");
+      AliTRDgeometry *geoTRD = TRD->GetGeometry();
+      // Partial geometry: modules at 2,3,4,6,11,12,14,15
+      // starting at 6h in positive direction
+      geoTRD->SetSMstatus(0,0);
+      geoTRD->SetSMstatus(1,0);
+      geoTRD->SetSMstatus(5,0);
+      geoTRD->SetSMstatus(7,0);
+      geoTRD->SetSMstatus(8,0);
+      geoTRD->SetSMstatus(9,0);
+      geoTRD->SetSMstatus(10,0);
+      geoTRD->SetSMstatus(13,0);
+      geoTRD->SetSMstatus(16,0);
+      geoTRD->SetSMstatus(17,0);
+    }
+
+  if (iFMD)
+    {
+      //=================== FMD parameters ============================
+      AliFMD *FMD = new AliFMDv1("FMD", "normal FMD");
+    }
+
+  if (iMUON)
+    {
+      //=================== MUON parameters ===========================
+      // New MUONv1 version (geometry defined via builders)
+      AliMUON *MUON = new AliMUONv1("MUON","default");
+    }
+  //=================== PHOS parameters ===========================
+
+  if (iPHOS)
+    {
+      AliPHOS *PHOS = new AliPHOSv1("PHOS", "IHEP");
+    }
+
+
+  if (iPMD)
+    {
+      //=================== PMD parameters ============================
+      AliPMD *PMD = new AliPMDv1("PMD", "normal PMD");
+    }
+
+  if (iT0)
+    {
+      //=================== T0 parameters ============================
+      AliT0 *T0 = new AliT0v1("T0", "T0 Detector");
+    }
+
+  if (iEMCAL)
+    {
+      //=================== EMCAL parameters ============================
+      AliEMCAL *EMCAL = new AliEMCALv2("EMCAL", "EMCAL_COMPLETEV1");
+    }
+
+  if (iACORDE)
+    {
+      //=================== ACORDE parameters ============================
+      AliACORDE *ACORDE = new AliACORDEv1("ACORDE", "normal ACORDE");
+    }
+
+  if (iVZERO)
+    {
+      //=================== VZERO parameters ============================
+      AliVZERO *VZERO = new AliVZEROv7("VZERO", "normal VZERO");
+    }
+
+
+}
+
+Float_t EtaToTheta(Float_t arg){
+  return (180./TMath::Pi())*2.*atan(exp(-arg));
+}
diff --git a/ITS/UPGRADE/simTGeoUpgrade.C b/ITS/UPGRADE/simTGeoUpgrade.C
new file mode 100644 (file)
index 0000000..66e086f
--- /dev/null
@@ -0,0 +1,22 @@
+void simTGeoUpgrade(Int_t nev=10) {
+
+  gSystem->Exec(" rm *.root ");
+  gSystem->Load("libITSUpgradeBase.so");
+  gSystem->Load("libITSUpgradeSim.so");
+  AliSimulation simulator("ConfigTgeoUpgrade.C");
+  simulator.SetMakeSDigits("");
+
+  simulator.SetMakeDigits("");
+
+  simulator.SetDefaultStorage("local://$ALICE_ROOT/OCDB");
+  simulator.SetSpecificStorage("GRP/GRP/Data",
+                              Form("local://%s",gSystem->pwd()));
+  simulator.SetRunHLT("");
+  simulator.SetRunQA(":");
+
+  TStopwatch timer;
+  timer.Start();
+  simulator.Run(nev);
+  timer.Stop();
+  timer.Print();
+}