]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliITS.cxx
Getter and Setter for ESDpid
[u/mrichter/AliRoot.git] / ITS / AliITS.cxx
index 9f1bf6f7634a985393d256282aee1c761995d1fa..9a7b54119a9ea4ac0712de5c6be82a200433682c 100644 (file)
@@ -85,14 +85,32 @@ the AliITS class.
 #include "AliMC.h"
 #include "AliITSDigitizer.h"
 #include "AliITSRecPoint.h"
-#include "AliITSclusterV2.h"
+#include "AliITSsegmentationSPD.h"
+#include "AliITSsegmentationSDD.h"
+#include "AliITSsegmentationSSD.h"
+#include "AliITSRawStreamSPD.h"
+#include "AliITSRawStreamSSD.h"
+#include "AliITSRawStreamSDD.h"
+#include "AliRawReader.h"
 #include "AliRun.h"
 #include "AliLog.h"
+#include "AliITSInitGeometry.h"
+#include "AliITSFOSignalsSPD.h"
 
 ClassImp(AliITS)
 
 //______________________________________________________________________
-AliITS::AliITS() : AliDetector(){
+AliITS::AliITS() : AliDetector(),
+fDetTypeSim(0),
+fEuclidOut(0),
+fOpt("All"),
+fIdN(0),
+fIdSens(0),
+fIdName(0),
+fITSmodules(0),
+fTiming(kFALSE),
+fSimuParam(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
@@ -100,21 +118,60 @@ AliITS::AliITS() : AliDetector(){
   // fIdSens, and fIdName. The AliDetector default constructor
   // is also called.
   
-  fEuclidOut=0;
-  fOpt="All";
-  fIdSens=0;
-  fIdName=0;
-  fDetTypeSim=0;
-  fIshunt     = 0;   // not zeroed in AliDetector.
-  fHits =0;
-  fNhits=0;
-  fITSmodules=0;
 //    SetDetectors(); // default to fOpt="All". This variable not written out.
-    SetMarkerColor(kRed);
+//PH    SetMarkerColor(kRed);
+}
+//______________________________________________________________________
+AliITS::AliITS(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)
+{
+    //     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);
 }
 //______________________________________________________________________
-AliITS::AliITS(const char *name, const char *title):AliDetector(name,title){
+AliITS::AliITS(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)
+{
   //     The standard Constructor for the ITS class. 
   // It also zeros the variables
   // fIshunt (a member of AliDetector class), fEuclidOut, and zeros
@@ -125,28 +182,16 @@ AliITS::AliITS(const char *name, const char *title):AliDetector(name,title){
   // class for a description of these parameters and its constructor
   // functions.
   
-  fEuclidOut=0;
-  fOpt="All";
-  fIdSens=0;
-  fIdName=0;
-  fDetTypeSim=0;
   fHits = new TClonesArray("AliITShit",1560);
   if(gAlice->GetMCApp()) gAlice->GetMCApp()->AddHitList(fHits);
-  fNhits=0;
-  fITSmodules = 0;
-
-  fIshunt     = 0;  // not zeroed in AliDetector
-  // Not done in AliDetector.
+  //fNhits=0;  //done in AliDetector(name,title)
 
-  fEuclidOut  = 0;
   SetDetectors(); // default to fOpt="All". This variable not written out.
-  
-  fIdName     = 0;
-  fIdSens     = 0;
-  
+    
   fDetTypeSim   = new AliITSDetTypeSim();
-  
-  SetMarkerColor(kRed);
+  //PH  SetMarkerColor(kRed);
+  if(!fLoader) MakeLoader(AliConfig::GetDefaultEventFolderName());
+  fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
 
 }
 //______________________________________________________________________
@@ -161,6 +206,7 @@ AliITS::~AliITS(){
     //      none.
     // Return:
     //      none.
+
     if (fHits) {
       fHits->Delete();
       delete fHits;
@@ -179,38 +225,10 @@ AliITS::~AliITS(){
       delete fDetTypeSim;
       fDetTypeSim = 0;
     }
-}
-//______________________________________________________________________
-AliITS::AliITS(const AliITS &source) : AliDetector(source){
-    // Copy constructor. This is a function which is not allowed to be
-    // done to the ITS. It exits with an error.
-    // Inputs:
-    //      AliITS &source  An AliITS class.
-    // Outputs:
-    //      none.
-    // Return:
-    //      none.
-
-    if(this==&source) return;
-    Error("Copy constructor",
-          "You are not allowed to make a copy of the AliITS");
-    exit(1);
-}
-//______________________________________________________________________
-AliITS& AliITS::operator=(const AliITS &source){
-    // Assignment operator. This is a function which is not allowed to be
-    // done to the ITS. It exits with an error.
-    // Inputs:
-    //      AliITS &source  An AliITS class.
-    // Outputs:
-    //      none.
-    // Return:
-    //      none.
-
-    if(this==&source) return *this;
-    Error("operator=","You are not allowed to make a copy of the AliITS");
-    exit(1);
-    return *this; //fake return
+    if(fSimuParam){
+      delete fSimuParam;
+      fSimuParam=0;
+    }
 }
 //______________________________________________________________________
 AliDigitizer* AliITS::CreateDigitizer(AliRunDigitizer* manager)const{
@@ -241,27 +259,10 @@ void AliITS::Init(){
     // Return:
     //      none.
     Int_t i;
-
-    SetDefaults();
     // Array of TStrings
     if(gMC) for(i=0;i<fIdN;i++) fIdSens[i] = gMC->VolId(fIdName[i]);
  
-    WriteGeometry();
-}
-
-//______________________________________________________________________
-void AliITS::WriteGeometry(){
-  
-  //Writes ITS geomtry on gAlice
-
-  if(!fLoader) MakeLoader(AliConfig::GetDefaultEventFolderName());
-  AliRunLoader* rl  = fLoader->GetRunLoader();
-  rl->CdGAFile();
-  AliITSgeom* geom = GetITSgeom();
-  geom->Write();
-
 }
-
 //______________________________________________________________________
 void AliITS::SetDefaults(){
     // sets the default segmentation, response, digit and raw cluster classes.
@@ -271,15 +272,14 @@ void AliITS::SetDefaults(){
     //      none.
     // Return:
     //      none.
-  AliInfoClass("Setting Defaults");
-
+    AliInfoClass("AliITS::Setting Defaults");
     if(!fDetTypeSim) { 
      Error("SetDefaults()","fDetTypeSim is 0!"); 
      return;
     }
 
     fDetTypeSim->SetDefaults();
-
+    if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
 
 }
 //______________________________________________________________________
@@ -291,13 +291,13 @@ void AliITS::SetDefaultSimulation(){
     //      none.
     // Return:
     //      none.
-
     if(!fDetTypeSim) { 
      Error("SetDefaultSimulation()","fDetTypeSim is 0!"); 
      return;
     }
 
     fDetTypeSim->SetDefaultSimulation();
+    if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
 
 }
 
@@ -352,7 +352,6 @@ void AliITS::MakeBranchS(const char* fl){
   sprintf(branchname,"%s",GetName());
 
   if(fLoader->TreeS()){
-    if(fDetTypeSim->GetSDigits()==0x0) fDetTypeSim->SetSDigits(new TClonesArray("AliITSpListItem",1000));
     TClonesArray* sdig = (TClonesArray*)fDetTypeSim->GetSDigits();
     MakeBranchInTree(fLoader->TreeS(),branchname,&sdig,buffersize,fl);
   } 
@@ -365,7 +364,8 @@ void AliITS::MakeBranchD(const char* file){
     Warning("MakeBranchD","fDetTypeSim is 0!");
     return;
   }
-  fDetTypeSim->SetLoader(fLoader);
+  fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
+  if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
   MakeBranchInTreeD(fLoader->TreeD(),file);
 }
 
@@ -376,10 +376,11 @@ void AliITS:: MakeBranchInTreeD(TTree* treeD, const char* file){
   if(!fDetTypeSim){
     Error("MakeBranchS","fDetTypeSim is 0!");
   }
-  fDetTypeSim->SetLoader(fLoader);
+  fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
+  if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
 
   const Char_t *det[3] = {"SPD","SDD","SSD"};
-  Char_t* digclass;
+  const Char_t* digclass;
   Int_t buffersize = 4000;
   Char_t branchname[30];
   
@@ -409,13 +410,14 @@ void AliITS::SetTreeAddress(){
     //      none.
     // Return:
     //      none.
-
+    
   if(!fDetTypeSim) {
     Error("SetTreeAddress","fDetTypeSim is 0!");
     return;
   }
 
-  fDetTypeSim->SetLoader(fLoader);
+  fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
+  if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
 
   TTree *treeS = fLoader->TreeS();
   TTree *treeD = fLoader->TreeD();
@@ -426,8 +428,6 @@ void AliITS::SetTreeAddress(){
 
   fDetTypeSim->SetTreeAddressS(treeS, (Char_t*)GetName());
   fDetTypeSim->SetTreeAddressD(treeD, (Char_t*)GetName());
-
-
 }
 //______________________________________________________________________
 void AliITS::AddHit(Int_t track, Int_t *vol, Float_t *hits){
@@ -447,7 +447,6 @@ void AliITS::AddHit(Int_t track, Int_t *vol, Float_t *hits){
     //      none.
   TClonesArray &lhits = *fHits;
   new(lhits[fNhits++]) AliITShit(fIshunt,track,vol,hits);
-
 }
 
 //______________________________________________________________________
@@ -494,8 +493,6 @@ void AliITS::FillModules(Int_t evnt,Int_t bgrev,Int_t nmodules,
   
   
 }
-
-
 //______________________________________________________________________
 void AliITS::FillModules(TTree *treeH, Int_t mask) {
     // fill the modules with the sorted by module hits; 
@@ -548,7 +545,7 @@ void AliITS::FillModules(TTree *treeH, Int_t mask) {
 }
 
 //______________________________________________________________________
-void AliITS::InitModules(Int_t size,Int_t &nmodules){
+Bool_t AliITS::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
@@ -566,15 +563,16 @@ void AliITS::InitModules(Int_t size,Int_t &nmodules){
 
     if(!fDetTypeSim) {
       Error("InitModules","fDetTypeSim is null!");
-      return;
+      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;
+            return kFALSE;
         } // end if fITSgeom==0
         nl = fDetTypeSim->GetITSgeom()->GetNlayers();
         indexMAX = fDetTypeSim->GetITSgeom()->GetIndexMax();
@@ -591,6 +589,7 @@ void AliITS::InitModules(Int_t size,Int_t &nmodules){
 
         nmodules = size;
     } // end i size<=0
+    return kTRUE;
 }
 //______________________________________________________________________
 void AliITS::Hits2SDigits(){
@@ -603,15 +602,16 @@ void AliITS::Hits2SDigits(){
 
    if(!fDetTypeSim) {
      Error("Hits2SDigits","fDetTypeSim is null!");
-     return;
-    
+     return; 
   } 
      
   SetDefaults();
   fLoader->LoadHits("read");
   fLoader->LoadSDigits("recreate");
   AliRunLoader* rl = fLoader->GetRunLoader(); 
-  fDetTypeSim->SetLoader(fLoader);
+  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
@@ -636,7 +636,8 @@ void AliITS::Hits2Digits(){
     return;
   }
    
-  fDetTypeSim->SetLoader(fLoader);
+  fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
+  if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
   SetDefaults();
 
   fLoader->LoadHits("read");
@@ -681,7 +682,8 @@ void AliITS::HitsToDigits(Int_t evNumber,Int_t bgrev,Int_t size,
     Error("HitsToDigits","fDetTypeSim is null!");
     return;
   }
-  fDetTypeSim->SetLoader(fLoader);
+  fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
+  if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
   if(!GetITSgeom()) return; // need transformations to do digitization.
   AliITSgeom *geom = GetITSgeom();
 
@@ -695,6 +697,9 @@ void AliITS::HitsToDigits(Int_t evNumber,Int_t bgrev,Int_t size,
   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;
@@ -717,6 +722,17 @@ void AliITS::HitsToDigits(Int_t evNumber,Int_t bgrev,Int_t size,
   } // end for module
   
   ClearModules();
+  // Add random noise to FO signals
+  if (all || det[0]) { // SPD present
+    fDetTypeSim->ProcessNoiseForFastOr();
+  }
+
+  // Add Fast-OR signals to event (only one object per event)
+  if (all || det[0]) { // SPD present
+    fDetTypeSim->WriteFOSignals();
+  }
+
   
   fLoader->TreeD()->GetEntries();
   fLoader->TreeD()->AutoSave();
@@ -732,7 +748,8 @@ void AliITS::Hits2PreDigits(){
     return;
   }
    
-  fDetTypeSim->SetLoader(fLoader);
+  fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
+  if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
   SetDefaults();
   
   HitsToPreDigits(fLoader->GetRunLoader()->GetEventNumber(),
@@ -766,7 +783,8 @@ void AliITS::HitsToPreDigits(Int_t evNumber,Int_t bgrev,Int_t size,
     Error("HitsToPreDigits","fDetTypeSim is null!");
     return;
   }
-  fDetTypeSim->SetLoader(fLoader);
+  fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
+  if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
 
   if(!GetITSgeom()){
     Error("HitsToPreDigits","fGeom is null!");
@@ -839,6 +857,7 @@ void AliITS::HitsToFastRecPoints(Int_t evNumber,Int_t bgrev,Int_t size,
     //      none.
 
 
+
   if(!GetITSgeom()){
     Error("HitsToPreDigits","fGeom is null!");
     return; // need transformations to do digitization.
@@ -859,15 +878,16 @@ void AliITS::HitsToFastRecPoints(Int_t evNumber,Int_t bgrev,Int_t size,
   Int_t id,module;
 
   TTree *lTR = pITSloader->TreeR();
-  TBranch* branch = lTR->GetBranch("ITSRecPointsF");
+  if(!lTR) {
+    pITSloader->MakeTree("R");
+    lTR = pITSloader->TreeR();
+  }
+  
   TClonesArray* ptarray = new TClonesArray("AliITSRecPoint",1000);
-  if(branch)  branch->SetAddress(ptarray);
-  else lTR->Branch("ITSRecPointsF",&ptarray);
-
+  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 !
-  AliDebug(1,Form("N mod = %d",geom->GetIndexMax()));    
+  //the CPU goes up !    
   for(module=0;module<geom->GetIndexMax();module++){
     id       = geom->GetModuleType(module);
     if (!all && !det[id]) continue;
@@ -881,6 +901,7 @@ void AliITS::HitsToFastRecPoints(Int_t evNumber,Int_t bgrev,Int_t size,
     mod      = (AliITSmodule *)fITSmodules->At(module);
     sim->CreateFastRecPoints(mod,module,gRandom,ptarray);
     lTR->Fill();
+    ptarray->Clear();
   } // end for module
 
   ClearModules();
@@ -902,82 +923,29 @@ Int_t AliITS::Hits2Clusters(TTree *hTree, TTree *cTree) {
   InitModules(-1,mmax);
   FillModules(hTree,0);
 
-  TClonesArray *clusters=new TClonesArray("AliITSclusterV2",1000);
-  TBranch *branch=cTree->GetBranch("Clusters");
-  if (!branch) cTree->Branch("Clusters",&clusters);
-  else branch->SetAddress(&clusters);
-
   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);      
-    RecPoints2Clusters(points, m, clusters);
-    ncl+=clusters->GetEntriesFast();
+    ncl+=points->GetEntriesFast();
     cTree->Fill();
-    clusters->Clear();
     points->Clear();
   }
 
-  Info("Hits2Clusters","Number of found fast clusters : %d",ncl);
+  AliDebug(1,Form("Number of found fast clusters : %d",ncl));
 
   //cTree->Write();
 
-  delete clusters;
   delete points;
   return 0;
 }
-//_____________________________________________________________________
-void AliITS::RecPoints2Clusters
-(const TClonesArray *points, Int_t idx, TClonesArray *clusters) {
-  //------------------------------------------------------------
-  // Conversion AliITSRecPoint -> AliITSclusterV2 for the ITS 
-  // subdetector indexed by idx 
-  //------------------------------------------------------------
 
-  if(!GetITSgeom()){
-    Error("HitsToPreDigits","fGeom is null!");
-    return; // need transformations to do digitization.
-  }
-  AliITSgeom *g=GetITSgeom();
-  Int_t mmax = g->GetIndexMax();
-  Float_t yshift[2200];
-  Float_t zshift[2200];
-  Int_t ndet[2200];
-  for (Int_t m=0; m<mmax; m++) {
-    Int_t lay,lad,det; g->GetModuleId(m,lay,lad,det);
-    Float_t x,y,z;     g->GetTrans(lay,lad,det,x,y,z); 
-    Double_t rot[9];   g->GetRotMatrix(lay,lad,det,rot);
-    Double_t alpha=TMath::ATan2(rot[1],rot[0])+TMath::Pi();
-    Double_t ca=TMath::Cos(alpha), sa=TMath::Sin(alpha);
-    yshift[m] = x*ca + y*sa;
-    zshift[m] = (Double_t)z;
-    ndet[m] = (lad-1)*g->GetNdetectors(lay) + (det-1);
-  }
-
-  //SPD geometry  
-  Float_t lastSPD1=g->GetModuleIndex(2,1,1)-1;
-
-  TClonesArray &cl=*clusters;
-  Int_t ncl=points->GetEntriesFast();
-  for (Int_t i=0; i<ncl; i++) {
-    AliITSRecPoint *p = (AliITSRecPoint *)points->UncheckedAt(i);
-    Float_t lp[5];
-    lp[0]=-(-p->GetX()+yshift[idx]); if (idx<=lastSPD1) lp[0]*=-1; //SPD1
-    lp[1]=  -p->GetZ()+zshift[idx];
-    lp[2]=p->GetSigmaX2();
-    lp[3]=p->GetSigmaZ2();
-    lp[4]=p->GetQ()*36./23333.;  //electrons -> ADC
-    Int_t lab[4]; 
-    lab[0]=p->GetLabel(0); lab[1]=p->GetLabel(1); lab[2]=p->GetLabel(2);
-    lab[3]=ndet[idx];
-    CheckLabels(lab);
-    Int_t dummy[3]={0,0,0};
-    new (cl[i]) AliITSclusterV2(lab,lp, dummy);
-  }  
-} 
 //_____________________________________________________________________
 void AliITS::CheckLabels(Int_t lab[3]) const {
   //------------------------------------------------------------
@@ -1008,20 +976,36 @@ void AliITS::CheckLabels(Int_t lab[3]) const {
 
 //______________________________________________________________________
 void AliITS::SDigitsToDigits(Option_t *opt){
-    // Standard Summable digits to Digits function.
-    // Inputs:
-    //      none.
-    // Outputs:
-    //      none.
-    if(!fDetTypeSim) {
-      Error("SDigitsToSDigits","fDetTypeSim is 0!");
-      return;
-    }
-   
-    fDetTypeSim->SetLoader(fLoader);
-    SetDefaults();
-    fDetTypeSim->SDigitsToDigits(opt,(Char_t*)GetName());
+  // 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 random noise to FO signals
+  if (all || det[0]) { // SPD present
+    fDetTypeSim->ProcessNoiseForFastOr();
+  }
+  // Add Fast-OR signals to event (only one object per event)
+  if (all || det[0]) { // SPD present
+    fDetTypeSim->WriteFOSignals();
+  }
 }
 
 //______________________________________________________________________
@@ -1072,25 +1056,6 @@ void AliITS::AddSumDigit(AliITSpListItem &sdig){
     }
     fDetTypeSim->AddSumDigit(sdig);
     
-}
-//______________________________________________________________________
-void AliITS::AddRealDigit(Int_t branch, Int_t *digits){
-    //   Add a real digit - as coming from data.
-    // Inputs:
-    //      Int_t id        Detector type number.
-    //      Int_t *digits   Integer array containing the digits info. See 
-    //                      AliITSdigit.h
-    // Outputs:
-    //      none.
-    // Return:
-    //      none.
-
-    if(!fDetTypeSim) {
-      Error("AddRealDigit","fDetTypeSim is 0!");
-      return;
-    }
-    fDetTypeSim->AddRealDigit(branch,digits);
-
 }
 //______________________________________________________________________
 void AliITS::AddSimDigit(Int_t branch, AliITSdigit *d){
@@ -1113,7 +1078,7 @@ void AliITS::AddSimDigit(Int_t branch, AliITSdigit *d){
 }
 //______________________________________________________________________
 void AliITS::AddSimDigit(Int_t branch,Float_t phys,Int_t *digits,Int_t *tracks,
-                         Int_t *hits,Float_t *charges){
+                         Int_t *hits,Float_t *charges, Int_t sigexpanded){
   //   Add a simulated digit to the list.
   // Inputs:
   //      Int_t id        Detector type number.
@@ -1137,7 +1102,7 @@ void AliITS::AddSimDigit(Int_t branch,Float_t phys,Int_t *digits,Int_t *tracks,
       Error("AddSimDigit","fDetTypeSim is 0!");
       return;
     }
-    fDetTypeSim->AddSimDigit(branch,phys,digits,tracks,hits,charges);
+    fDetTypeSim->AddSimDigit(branch,phys,digits,tracks,hits,charges,sigexpanded);
 
 }
 //______________________________________________________________________
@@ -1148,8 +1113,9 @@ void AliITS::Digits2Raw(){
     Error("Digits2Raw","fDetTypeSim is 0!");
     return;
   }
-  fDetTypeSim->SetLoader(fLoader);
+  fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
   SetDefaults();
+  if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
   fDetTypeSim->GetLoader()->LoadDigits();
   TTree* digits = fDetTypeSim->GetLoader()->TreeD();
   if (!digits) {
@@ -1157,8 +1123,33 @@ void AliITS::Digits2Raw(){
       return;
   }
   fDetTypeSim->SetTreeAddressD(digits,(Char_t*)GetName());
-
+  
+   // Get the FO signals for this event
+  AliITSFOSignalsSPD* foSignals = NULL;
+  AliRunLoader* runLoader = AliRunLoader::Instance();
+  AliITSLoader* itsLoader = (AliITSLoader*) 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
@@ -1170,34 +1161,189 @@ void AliITS::Digits2Raw(){
   rawWriter.SetVerbose(0);
     
   //SILICON PIXEL DETECTOR
-  Info("Digits2Raw", "Formatting raw data for SPD");
-  rawWriter.RawDataSPD(digits->GetBranch("ITSDigitsSPD"));
+  AliDebug(1,"Formatting raw data for SPD");
+  rawWriter.RawDataSPD(digits->GetBranch("ITSDigitsSPD"),foSignals);
+  if(deleteFOsignalsLater) delete foSignals;
     
   //SILICON DRIFT DETECTOR
-  Info("Digits2Raw", "Formatting raw data for SDD");
-  rawWriter.RawDataSDD(digits->GetBranch("ITSDigitsSDD"));
+  AliDebug(1,Form("Formatting raw data for SDD - Format code =%d",rawSDD));
+  rawWriter.RawDataSDD(digits->GetBranch("ITSDigitsSDD"),ddlsdd);
     
   //SILICON STRIP DETECTOR
-  Info("Digits2Raw", "Formatting raw data for SSD");
+  AliDebug(1,"Formatting raw data for SSD");
   rawWriter.RawDataSSD(digits->GetBranch("ITSDigitsSSD"));
 
   fLoader->UnloadDigits();
-  
-
-
-  
 }
-
-
-
-
 //______________________________________________________________________
 AliLoader* AliITS::MakeLoader(const char* topfoldername){ 
     //builds ITSgetter (AliLoader type)
     //if detector wants to use castomized getter, it must overload this method
 
-    Info("MakeLoader","Creating AliITSLoader. Top folder is %s.",
-         topfoldername);
+    AliDebug(1,Form("Creating AliITSLoader. Top folder is %s.",
+         topfoldername));
     fLoader = new AliITSLoader(GetName(),topfoldername);
     return fLoader;
 }
+//______________________________________________________________________
+Bool_t AliITS::Raw2SDigits(AliRawReader* rawReader)
+{
+  //
+  // Converts RAW data to SDigits
+  //
+  // Get TreeS
+  //
+    Int_t last   = -1;
+    Int_t size   = GetITSgeom()->GetIndexMax();
+    TClonesArray** modA = new TClonesArray*[size];
+    for (Int_t mod = 0; mod < size; mod++) modA[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
+    // 
+    TClonesArray aSDigits("AliITSpListItem",10000), *itsSDigits=&aSDigits;
+    Int_t bufsize = 32000;
+    tree->Branch("ITS", &itsSDigits, 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 = (modA[module])->GetEntries();
+       TClonesArray& dum = *modA[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();
+    AliITSRawStream* inputSDD=AliITSRawStreamSDD::CreateRawStreamSDD(rawReader);
+    AliITSDDLModuleMapSDD* ddlmap=fDetTypeSim->GetDDLModuleMapSDD();
+    inputSDD->SetDDLModuleMap(ddlmap);
+    while(1){
+       Bool_t next  = inputSDD->Next();
+       if (!next) break;
+
+       if(inputSDD->IsCompletedModule()==kFALSE && 
+          inputSDD->IsCompletedDDL()==kFALSE){
+
+         Int_t module = inputSDD->GetModuleID();
+         Int_t anode  = inputSDD->GetCoord1();
+         Int_t time   = inputSDD->GetCoord2();
+         Int_t signal10 = inputSDD->GetSignal();
+         Int_t index  = npx * anode + time;
+
+         if (module >= size) continue;
+         last = modA[module]->GetEntries();
+         TClonesArray& dum = *modA[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();
+       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 = modA[module]->GetEntries();
+       TClonesArray& dum = *modA[module];
+       new (dum[last]) AliITSpListItem(-1, -1, module, index, Double_t(signal));
+    }
+    rawReader->Reset();
+     AliITSpListItem* sdig = 0;
+    
+    for (Int_t mod = 0; mod < size; mod++)
+    {
+       Int_t nsdig =  modA[mod]->GetEntries();
+       for (Int_t ie = 0; ie < nsdig; ie++) {
+           sdig = (AliITSpListItem*) (modA[mod]->At(ie));
+           new (aSDigits[ie]) AliITSpListItem(-1, -1, mod, sdig->GetIndex(), sdig->GetSignal());
+           Float_t sig = sdig->GetSignalAfterElect();
+           if (sig > 0.) {
+               sdig = (AliITSpListItem*)aSDigits[ie];
+               sdig->AddSignalAfterElect(mod, sdig->GetIndex(), Double_t(sig));
+           }
+       }
+       
+       tree->Fill();
+       aSDigits.Clear();
+       modA[mod]->Clear();
+    }
+    loader->WriteSDigits("OVERWRITE");    
+    delete modA;
+    return kTRUE;
+}
+
+
+//______________________________________________________________________
+void AliITS::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;
+  if(version==kvPPRasymmFMD) minor=2;  // default minor version for this geom.
+  AliITSInitGeometry initgeom;
+  AliITSgeom* geom = initgeom.CreateAliITSgeom(version,minor);
+  SetITSgeom(geom);
+}
+//______________________________________________________________________
+AliTriggerDetector* AliITS::CreateTriggerDetector() const {
+  // create an AliITSTrigger object (and set trigger conditions as input)
+  return new AliITSTrigger(fDetTypeSim->GetTriggerConditions());
+}
+