]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliITSDetTypeRec.cxx
Add to repository the macro to plot the output of SDD calibration runs from LDCs
[u/mrichter/AliRoot.git] / ITS / AliITSDetTypeRec.cxx
index 34b511e8319f67e97d13e9a9e07326c6bdb53f75..d691f2a89e8342e018f335686413fbcf7579817c 100644 (file)
 #include "TTree.h"
 
 #include "AliCDBManager.h"
-#include "AliCDBStorage.h"
 #include "AliCDBEntry.h"
 #include "AliITSClusterFinder.h"
-#include "AliITSClusterFinderV2.h"
 #include "AliITSClusterFinderV2SPD.h"
 #include "AliITSClusterFinderV2SDD.h"
 #include "AliITSClusterFinderV2SSD.h"
-#include "AliITSClusterFinderSPD.h"
-#include "AliITSClusterFinderSDD.h"
-#include "AliITSClusterFinderSSD.h"
 #include "AliITSDetTypeRec.h"
-#include "AliITSgeom.h"
-#include "AliITSRawCluster.h"
-#include "AliITSRawClusterSPD.h"
-#include "AliITSRawClusterSDD.h"
-#include "AliITSRawClusterSSD.h"
+#include "AliITSDDLModuleMapSDD.h"
 #include "AliITSRecPoint.h"
-#include "AliITSReconstructor.h"
-#include "AliITSRecoParam.h"
+#include "AliITSRecPointContainer.h"
 #include "AliITSCalibrationSDD.h"
 #include "AliITSMapSDD.h"
-#include "AliITSDriftSpeedArraySDD.h"
-#include "AliITSDriftSpeedSDD.h"
 #include "AliITSCalibrationSSD.h"
 #include "AliITSNoiseSSDv2.h"
 #include "AliITSGainSSDv2.h"
 #include "AliITSNoiseSSD.h"
 #include "AliITSGainSSD.h"
 #include "AliITSBadChannelsSSD.h"
+#include "AliITSresponseSDD.h"
 #include "AliITSsegmentationSPD.h"
 #include "AliITSsegmentationSDD.h"
 #include "AliITSsegmentationSSD.h"
 #include "AliLog.h"
+#include "AliITSRawStreamSPD.h"
+#include "AliITSTriggerConditions.h"
+#include "AliITSFOSignalsSPD.h"
+#include "AliRunLoader.h"
+#include "AliDataLoader.h"
+#include "AliITSLoader.h"
 
+class AliITSDriftSpeedArraySDD;
+class AliITSCorrMapSDD;
+class AliITSRecoParam;
 
 const Int_t AliITSDetTypeRec::fgkNdettypes = 3;
 const Int_t AliITSDetTypeRec::fgkDefaultNModulesSPD =  240;
@@ -78,18 +76,17 @@ fSegmentation(0),
 fCalibration(0),
 fSSDCalibration(0),
 fSPDDead(0),
-fPreProcess(0),
-fPostProcess(0),
+fTriggerConditions(0),
 fDigits(0),
+fFOSignals(0),
 fDDLMapSDD(0),
 fRespSDD(0),
-fNdtype(0),
-fCtype(0),
-fNctype(0),
+fAveGainSDD(0),
 fRecPoints(0),
 fNRecPoints(0),
-fSelectedVertexer(),
-fFirstcall(kTRUE){
+fFirstcall(kTRUE),
+fLoadOnlySPDCalib(0),
+fFastOrFiredMap(1200){
     // Standard Constructor
     // Inputs:
     //    none.
@@ -101,14 +98,9 @@ fFirstcall(kTRUE){
   fReconstruction = new TObjArray(fgkNdettypes);
   fDigits = new TObjArray(fgkNdettypes);
   for(Int_t i=0; i<3; i++){
-    fClusterClassName[i]=0;
-    fDigClassName[i]=0;
-    fRecPointClassName[i]=0;
+    fkDigClassName[i]=0;
   }
   fSSDCalibration=new AliITSCalibrationSSD();
-  fNdtype = new Int_t[fgkNdettypes];
-  fCtype = new TObjArray(fgkNdettypes);
-  fNctype = new Int_t[fgkNdettypes];
   fNMod = new Int_t [fgkNdettypes];
   fNMod[0] = fgkDefaultNModulesSPD;
   fNMod[1] = fgkDefaultNModulesSDD;
@@ -116,12 +108,7 @@ fFirstcall(kTRUE){
   fRecPoints = new TClonesArray("AliITSRecPoint",3000);
   fNRecPoints = 0;
   
-  for(Int_t i=0;i<fgkNdettypes;i++){
-    fNdtype[i]=0;
-    fNctype[i]=0;
-  }
   
-  SelectVertexer(" "); 
 }
 
 //______________________________________________________________________
@@ -133,19 +120,17 @@ fSegmentation(rec.fSegmentation),
 fCalibration(rec.fCalibration),
 fSSDCalibration(rec.fSSDCalibration),
 fSPDDead(rec.fSPDDead),
-fPreProcess(rec.fPreProcess),
-fPostProcess(rec.fPostProcess),
+fTriggerConditions(rec.fTriggerConditions),
 fDigits(rec.fDigits),
+fFOSignals(rec.fFOSignals),
 fDDLMapSDD(rec.fDDLMapSDD),
 fRespSDD(rec.fRespSDD),
-fNdtype(rec.fNdtype),
-fCtype(rec.fCtype),
-fNctype(rec.fNctype),
+fAveGainSDD(rec.fAveGainSDD),
 fRecPoints(rec.fRecPoints),
 fNRecPoints(rec.fNRecPoints),
-fSelectedVertexer(rec.fSelectedVertexer),
-fFirstcall(rec.fFirstcall)
-{
+fFirstcall(rec.fFirstcall),
+fLoadOnlySPDCalib(rec.fLoadOnlySPDCalib),
+fFastOrFiredMap(rec.fFastOrFiredMap){
 
   // Copy constructor. 
 
@@ -182,16 +167,26 @@ AliITSDetTypeRec::~AliITSDetTypeRec(){
       if(fDDLMapSDD) delete fDDLMapSDD;
    }
   }
-  if(fSSDCalibration) delete fSSDCalibration;
+  if(fSSDCalibration){
+    if(!(AliCDBManager::Instance()->GetCacheFlag())) {
+      delete fSSDCalibration;
+      fSSDCalibration = NULL;
+    }
+  }
    if(fSPDDead){
     if(!(AliCDBManager::Instance()->GetCacheFlag())) {
       fSPDDead->Delete();
       delete fSPDDead;
       fSPDDead = 0;
     }
-  }  
-  if(fPreProcess) delete fPreProcess;
-  if(fPostProcess) delete fPostProcess;
+  } 
+  if(fTriggerConditions){
+    if(!(AliCDBManager::Instance()->GetCacheFlag())) {
+      fTriggerConditions->Delete();
+      delete fTriggerConditions;
+      fTriggerConditions = 0;
+    }
+  } 
   if(fDigits){
     fDigits->Delete();
     delete fDigits;
@@ -202,13 +197,6 @@ AliITSDetTypeRec::~AliITSDetTypeRec(){
     delete fRecPoints;
     fRecPoints=0;
   }
-  if(fCtype) {
-    fCtype->Delete();
-    delete fCtype;
-    fCtype = 0;
-  }
-  delete [] fNctype;
-  delete [] fNdtype;
   delete [] fNMod;
   
   if (fITSgeom) delete fITSgeom;
@@ -225,7 +213,7 @@ void AliITSDetTypeRec::SetReconstructionModel(Int_t dettype,AliITSClusterFinder
   fReconstruction->AddAt(clf,dettype);
 }
 //______________________________________________________________________
-AliITSClusterFinder* AliITSDetTypeRec::GetReconstructionModel(Int_t dettype){
+AliITSClusterFinder* AliITSDetTypeRec::GetReconstructionModel(Int_t dettype) const{
 
   //Get reconstruction model for detector type
   if(fReconstruction==0)  {
@@ -246,7 +234,7 @@ void AliITSDetTypeRec::SetSegmentationModel(Int_t dettype,AliITSsegmentation *se
 
 }
 //______________________________________________________________________
-AliITSsegmentation* AliITSDetTypeRec::GetSegmentationModel(Int_t dettype){
+AliITSsegmentation* AliITSDetTypeRec::GetSegmentationModel(Int_t dettype) const {
 
   //Get segmentation model for detector type
    
@@ -287,7 +275,7 @@ void AliITSDetTypeRec::SetSPDDeadModel(Int_t iMod, AliITSCalibration *cal){
   fSPDDead->AddAt(cal,iMod);
 }
 //_______________________________________________________________________
-AliITSCalibration* AliITSDetTypeRec::GetCalibrationModel(Int_t iMod){
+AliITSCalibration* AliITSDetTypeRec::GetCalibrationModel(Int_t iMod) const {
   
   //Get calibration model for module type
   
@@ -306,7 +294,7 @@ AliITSCalibration* AliITSDetTypeRec::GetCalibrationModel(Int_t iMod){
 
 }
 //_______________________________________________________________________
-AliITSCalibration* AliITSDetTypeRec::GetSPDDeadModel(Int_t iMod){
+AliITSCalibration* AliITSDetTypeRec::GetSPDDeadModel(Int_t iMod) const {
   
   //Get SPD dead for module iMod
   
@@ -314,43 +302,50 @@ AliITSCalibration* AliITSDetTypeRec::GetSPDDeadModel(Int_t iMod){
     AliWarning("fSPDDead is 0!");
     return 0; 
   }  
-
   return (AliITSCalibration*)fSPDDead->At(iMod);
 }
-
+//_______________________________________________________________________
+AliITSTriggerConditions* AliITSDetTypeRec::GetTriggerConditions() const {
+  //Get Pixel Trigger Conditions
+  if (fTriggerConditions==0) {
+    AliWarning("fTriggerConditions is 0!");
+  }
+  return fTriggerConditions;
+}
 //______________________________________________________________________
-void AliITSDetTypeRec::SetTreeAddressD(TTree *treeD){
+void AliITSDetTypeRec::SetTreeAddressD(TTree* const treeD){
     // Set branch address for the tree of digits.
 
-    const char *det[4] = {"SPD","SDD","SSD","ITS"};
-    TBranch *branch;
-    Char_t* digclass;
-    Int_t i;
-    char branchname[30];
-
-    if(!treeD) return;
-    if (fDigits == 0x0) fDigits = new TObjArray(fgkNdettypes);
-    for (i=0; i<fgkNdettypes; i++) {
-        digclass = GetDigitClassName(i);
-       if(!(fDigits->At(i))) {
-            fDigits->AddAt(new TClonesArray(digclass,1000),i);
-        }else{
-            ResetDigits(i);
-        } 
-        if (fgkNdettypes==3) sprintf(branchname,"%sDigits%s",det[3],det[i]);
-        else  sprintf(branchname,"%sDigits%d",det[3],i+1);
-        if (fDigits) {
-            branch = treeD->GetBranch(branchname);
-            if (branch) branch->SetAddress(&((*fDigits)[i]));
-        } 
+  const char *det[4] = {"SPD","SDD","SSD","ITS"};
+  TBranch *branch;
+  const Char_t* digclass;
+  Int_t i;
+  char branchname[30];
+
+  if(!treeD) return;
+  if (fDigits == 0x0) fDigits = new TObjArray(fgkNdettypes);
+  for (i=0; i<fgkNdettypes; i++) {
+    digclass = GetDigitClassName(i);
+    if(!(fDigits->At(i))) {
+      fDigits->AddAt(new TClonesArray(digclass,1000),i);
+    }
+    else{
+      ResetDigits(i);
     } 
+    if (fgkNdettypes==3) sprintf(branchname,"%sDigits%s",det[3],det[i]);
+    else  sprintf(branchname,"%sDigits%d",det[3],i+1);
+    if (fDigits) {
+      branch = treeD->GetBranch(branchname);
+      if (branch) branch->SetAddress(&((*fDigits)[i]));
+    }
+  } 
+
 }
 
 //_______________________________________________________________________
-TBranch* AliITSDetTypeRec::MakeBranchInTree(TTree *tree, const char* name, 
-                                       const char *classname, 
-                                       void* address,Int_t size, 
-                                       Int_t splitlevel)
+TBranch* AliITSDetTypeRec::MakeBranchInTree(TTree* const tree, 
+                           const char* name, const char *classname, 
+                           void* address,Int_t size,Int_t splitlevel)
 { 
 //
 // Makes branch in given tree and diverts them to a separate file
@@ -394,28 +389,25 @@ void AliITSDetTypeRec::SetDefaults(){
       seg = new AliITSsegmentationSPD();
       SetSegmentationModel(dettype,seg);
       SetDigitClassName(dettype,"AliITSdigitSPD");
-      SetClusterClassName(dettype,"AliITSRawClusterSPD");
-
     }
     if(dettype==1){
       seg = new AliITSsegmentationSDD();
-      AliITSCalibrationSDD* cal=(AliITSCalibrationSDD*)GetCalibrationModel(fgkDefaultNModulesSPD+1);
-      if(cal->IsAMAt20MHz()){ 
-       seg->SetPadSize(seg->Dpz(0),20.);
-       seg->SetNPads(seg->Npz()/2,128);
+      if(fLoadOnlySPDCalib==kFALSE){
+       AliITSCalibrationSDD* cal=(AliITSCalibrationSDD*)GetCalibrationModel(fgkDefaultNModulesSPD+1);
+       if(cal->IsAMAt20MHz()){ 
+         seg->SetPadSize(seg->Dpz(0),20.);
+         seg->SetNPads(seg->Npz()/2,128);
+       }
       }
       SetSegmentationModel(dettype,seg);
       SetDigitClassName(dettype,"AliITSdigitSDD");
-      SetClusterClassName(dettype,"AliITSRawClusterSDD");
     }
     if(dettype==2){
       AliITSsegmentationSSD* seg2 = new AliITSsegmentationSSD();
       SetSegmentationModel(dettype,seg2);
       SetDigitClassName(dettype,"AliITSdigitSSD");
-      SetClusterClassName(dettype,"AliITSRawClusterSSD");
     }
   }
-  
 }
 //______________________________________________________________________
 Bool_t AliITSDetTypeRec::GetCalibration() {
@@ -424,8 +416,7 @@ Bool_t AliITSDetTypeRec::GetCalibration() {
   if(!fFirstcall){
     AliITSCalibration* cal = GetCalibrationModel(0);
     if(cal)return kTRUE;
-  }
-  else {
+  }else {
     fFirstcall = kFALSE;
   }
 
@@ -438,36 +429,87 @@ Bool_t AliITSDetTypeRec::GetCalibration() {
     fCalibration->SetOwner(!cacheStatus);
     fCalibration->Clear();
   }
+    
+  Bool_t retCode=GetCalibrationSPD(cacheStatus);
+  if(retCode==kFALSE) return kFALSE;
+
+  if(fLoadOnlySPDCalib==kFALSE){
+    retCode=GetCalibrationSDD(cacheStatus);
+    if(retCode==kFALSE) return kFALSE;
+    retCode=GetCalibrationSSD(cacheStatus);
+    if(retCode==kFALSE) return kFALSE;
+  }
 
+  AliInfo(Form("%i SPD, %i SDD and %i SSD in calibration database",
+              fNMod[0], fNMod[1], fNMod[2]));
+  return kTRUE;
+}
+//______________________________________________________________________
+Bool_t AliITSDetTypeRec::GetCalibrationSPD(Bool_t cacheStatus) {
+  // Get SPD calibration objects from OCDB
   // dead pixel are not used for local reconstruction
-  AliCDBEntry *entrySPD = AliCDBManager::Instance()->Get("ITS/Calib/SPDNoisy");
+
+  AliCDBEntry *noisySPD = AliCDBManager::Instance()->Get("ITS/Calib/SPDNoisy");
   AliCDBEntry *deadSPD = AliCDBManager::Instance()->Get("ITS/Calib/SPDDead");
-  AliCDBEntry *entrySDD = AliCDBManager::Instance()->Get("ITS/Calib/CalibSDD");
+  AliCDBEntry *pitCond = AliCDBManager::Instance()->Get("TRIGGER/SPD/PITConditions");
+  if(!noisySPD || !deadSPD || !pitCond ){
+    AliFatal("SPD Calibration object retrieval failed! ");
+    return kFALSE;
+  }
+
+  TObjArray *calNoisySPD = (TObjArray*) noisySPD->GetObject();
+  if (!cacheStatus) noisySPD->SetObject(NULL);
+  noisySPD->SetOwner(kTRUE);
  
- //  AliCDBEntry *entrySSD = AliCDBManager::Instance()->Get("ITS/Calib/CalibSSD");
-  AliCDBEntry *entryNoiseSSD = AliCDBManager::Instance()->Get("ITS/Calib/NoiseSSD");
-  AliCDBEntry *entryGainSSD = AliCDBManager::Instance()->Get("ITS/Calib/GainSSD");
-  AliCDBEntry *entryBadChannelsSSD = AliCDBManager::Instance()->Get("ITS/Calib/BadChannelsSSD");
+  TObjArray *calDeadSPD = (TObjArray*) deadSPD->GetObject();
+  if (!cacheStatus) deadSPD->SetObject(NULL);
+  deadSPD->SetOwner(kTRUE);
+
+  AliITSTriggerConditions *calPitCond = (AliITSTriggerConditions*) pitCond->GetObject();
+  if (!cacheStatus) pitCond->SetObject(NULL);
+  pitCond->SetOwner(kTRUE);
+
+  if(!cacheStatus){
+    delete noisySPD;
+    delete deadSPD;
+    delete pitCond;
+  }
+  if ((!calNoisySPD) || (!calDeadSPD) || (!calPitCond)){ 
+    AliWarning("Can not get SPD calibration from calibration database !");
+    return kFALSE;
+  }
+
+  fNMod[0] = calNoisySPD->GetEntries();
+
+  AliITSCalibration* cal;
+  for (Int_t i=0; i<fNMod[0]; i++) {
+    cal = (AliITSCalibration*) calNoisySPD->At(i);
+    SetCalibrationModel(i, cal);
+    cal = (AliITSCalibration*) calDeadSPD->At(i);
+    SetSPDDeadModel(i, cal);
+  }
+  fTriggerConditions = calPitCond;
+
+  return kTRUE;
+}
+
+//______________________________________________________________________
+Bool_t AliITSDetTypeRec::GetCalibrationSDD(Bool_t cacheStatus) {
+  // Get SDD calibration objects from OCDB
+
+  AliCDBEntry *entrySDD = AliCDBManager::Instance()->Get("ITS/Calib/CalibSDD");
   AliCDBEntry *entry2SDD = AliCDBManager::Instance()->Get("ITS/Calib/RespSDD");
   AliCDBEntry *drSpSDD = AliCDBManager::Instance()->Get("ITS/Calib/DriftSpeedSDD");
   AliCDBEntry *ddlMapSDD = AliCDBManager::Instance()->Get("ITS/Calib/DDLMapSDD");
-//   AliCDBEntry *mapASDD = AliCDBManager::Instance()->Get("ITS/Calib/MapsAnodeSDD");
+  //   AliCDBEntry *mapASDD = AliCDBManager::Instance()->Get("ITS/Calib/MapsAnodeSDD");
   AliCDBEntry *mapTSDD = AliCDBManager::Instance()->Get("ITS/Calib/MapsTimeSDD");
 
-  if(!entrySPD || !deadSPD || !entrySDD || !entryNoiseSSD || !entryGainSSD || 
-     !entryBadChannelsSSD || 
-     !entry2SDD || !drSpSDD || !ddlMapSDD || !mapTSDD ){
-    AliFatal("Calibration object retrieval failed! ");
+  if(!entrySDD || !entry2SDD || !drSpSDD || !ddlMapSDD || !mapTSDD ){
+    AliFatal("SDD Calibration object retrieval failed! ");
     return kFALSE;
   }    
 
-  TObjArray *calSPD = (TObjArray *)entrySPD->GetObject();
-  if(!cacheStatus)entrySPD->SetObject(NULL);
-  entrySPD->SetOwner(kTRUE);
-  TObjArray *caldeadSPD = (TObjArray *)deadSPD->GetObject();
-  if(!cacheStatus)deadSPD->SetObject(NULL);
-  deadSPD->SetOwner(kTRUE);
 
     
   TObjArray *calSDD = (TObjArray *)entrySDD->GetObject();
@@ -494,12 +536,96 @@ Bool_t AliITSDetTypeRec::GetCalibration() {
   if(!cacheStatus)mapTSDD->SetObject(NULL);
   mapTSDD->SetOwner(kTRUE);
 
-  TObject *emptyssd = 0; TString ssdobjectname = 0;
-  AliITSNoiseSSDv2 *noiseSSD = new AliITSNoiseSSDv2();  
+
+  // DB entries are deleted. In this way metadeta objects are deleted as well
+  if(!cacheStatus){
+    delete entrySDD;
+    delete entry2SDD;
+    //delete mapASDD;
+    delete mapTSDD;
+    delete drSpSDD;
+    delete ddlMapSDD;
+  }
+
+  if ((!pSDD)||(!calSDD) || (!drSp) || (!ddlsdd) || (!mapT) ){
+    AliWarning("Can not get SDD calibration from calibration database !");
+    return kFALSE;
+  }
+
+  fNMod[1] = calSDD->GetEntries();
+
+  fDDLMapSDD=ddlsdd;
+  fRespSDD=pSDD;
+  AliITSCalibration* cal;
+  Float_t avegain=0.;
+  Float_t nGdAnodes=0;
+  Bool_t oldMapFormat=kFALSE;
+  TObject* objmap=(TObject*)mapT->At(0);
+  TString cname(objmap->ClassName());
+  if(cname.CompareTo("AliITSMapSDD")==0){ 
+    oldMapFormat=kTRUE;
+    AliInfo("SDD Maps converted to new format");
+  }
+  for(Int_t iddl=0; iddl<AliITSDDLModuleMapSDD::GetNDDLs(); iddl++){
+    for(Int_t icar=0; icar<AliITSDDLModuleMapSDD::GetNModPerDDL();icar++){
+      Int_t iMod=fDDLMapSDD->GetModuleNumber(iddl,icar);
+      if(iMod==-1) continue;
+      Int_t i=iMod - fgkDefaultNModulesSPD;
+      cal = (AliITSCalibration*) calSDD->At(i);
+      Int_t i0=2*i;
+      Int_t i1=1+2*i;
+      for(Int_t iAnode=0;iAnode< ((AliITSCalibrationSDD*)cal)->NOfAnodes(); iAnode++){
+       if(((AliITSCalibrationSDD*)cal)->IsBadChannel(iAnode)) continue;
+       avegain+= ((AliITSCalibrationSDD*)cal)->GetChannelGain(iAnode);
+       nGdAnodes++;
+      }
+      AliITSDriftSpeedArraySDD* arr0 = (AliITSDriftSpeedArraySDD*) drSp->At(i0);
+      AliITSDriftSpeedArraySDD* arr1 = (AliITSDriftSpeedArraySDD*) drSp->At(i1);
+
+      AliITSCorrMapSDD* mt0 = 0;
+      AliITSCorrMapSDD* mt1 = 0;
+      if(oldMapFormat){ 
+       AliITSMapSDD* oldmap0=(AliITSMapSDD*)mapT->At(i0);
+       AliITSMapSDD* oldmap1=(AliITSMapSDD*)mapT->At(i1);
+       mt0=oldmap0->ConvertToNewFormat();
+       mt1=oldmap1->ConvertToNewFormat();
+      }else{
+       mt0=(AliITSCorrMapSDD*)mapT->At(i0);
+       mt1=(AliITSCorrMapSDD*)mapT->At(i1);
+      }
+      cal->SetDriftSpeed(0,arr0);
+      cal->SetDriftSpeed(1,arr1);
+      cal->SetMapT(0,mt0);
+      cal->SetMapT(1,mt1);
+      SetCalibrationModel(iMod, cal);
+    }
+  }
+  if(nGdAnodes) fAveGainSDD=avegain/nGdAnodes;
+  return kTRUE;
+}
+
+
+//______________________________________________________________________
+Bool_t AliITSDetTypeRec::GetCalibrationSSD(Bool_t cacheStatus) {
+  // Get SSD calibration objects from OCDB
+  //  AliCDBEntry *entrySSD = AliCDBManager::Instance()->Get("ITS/Calib/CalibSSD");
+
+  AliCDBEntry *entryNoiseSSD = AliCDBManager::Instance()->Get("ITS/Calib/NoiseSSD");
+  AliCDBEntry *entryGainSSD = AliCDBManager::Instance()->Get("ITS/Calib/GainSSD");
+  AliCDBEntry *entryBadChannelsSSD = AliCDBManager::Instance()->Get("ITS/Calib/BadChannelsSSD");
+
+  if(!entryNoiseSSD || !entryGainSSD || !entryBadChannelsSSD){
+    AliFatal("SSD Calibration object retrieval failed! ");
+    return kFALSE;
+  }    
+
+  TObject *emptyssd = 0; TString ssdobjectname;
+  AliITSNoiseSSDv2 *noiseSSD = NULL; 
   emptyssd = (TObject *)entryNoiseSSD->GetObject();
   ssdobjectname = emptyssd->GetName();
   if(ssdobjectname=="TObjArray") {
     TObjArray *noiseSSDOld = (TObjArray *)entryNoiseSSD->GetObject();
+    noiseSSD = new AliITSNoiseSSDv2(); 
     ReadOldSSDNoise(noiseSSDOld, noiseSSD);
   }
   else if(ssdobjectname=="AliITSNoiseSSDv2")
@@ -507,11 +633,12 @@ Bool_t AliITSDetTypeRec::GetCalibration() {
   if(!cacheStatus)entryNoiseSSD->SetObject(NULL);
   entryNoiseSSD->SetOwner(kTRUE);
 
-  AliITSGainSSDv2 *gainSSD = new AliITSGainSSDv2();
+  AliITSGainSSDv2 *gainSSD = NULL;;
   emptyssd = (TObject *)entryGainSSD->GetObject();
   ssdobjectname = emptyssd->GetName();
   if(ssdobjectname=="Gain") {
     TObjArray *gainSSDOld = (TObjArray *)entryGainSSD->GetObject();
+    gainSSD = new AliITSGainSSDv2();
     ReadOldSSDGain(gainSSDOld, gainSSD);
   }
   else if(ssdobjectname=="AliITSGainSSDv2")
@@ -519,11 +646,12 @@ Bool_t AliITSDetTypeRec::GetCalibration() {
   if(!cacheStatus)entryGainSSD->SetObject(NULL);
   entryGainSSD->SetOwner(kTRUE);
 
-  AliITSBadChannelsSSDv2 *badChannelsSSD = new AliITSBadChannelsSSDv2();
+  AliITSBadChannelsSSDv2 *badChannelsSSD = NULL;
   emptyssd = (TObject *)entryBadChannelsSSD->GetObject();
   ssdobjectname = emptyssd->GetName();
   if(ssdobjectname=="TObjArray") {
     TObjArray *badChannelsSSDOld = (TObjArray *)entryBadChannelsSSD->GetObject();
+    badChannelsSSD = new AliITSBadChannelsSSDv2();
     ReadOldSSDBadChannels(badChannelsSSDOld, badChannelsSSD);
   }
   else if(ssdobjectname=="AliITSBadChannelsSSDv2")
@@ -533,122 +661,24 @@ Bool_t AliITSDetTypeRec::GetCalibration() {
 
   // DB entries are deleted. In this way metadeta objects are deleted as well
   if(!cacheStatus){
-    delete entrySPD;
-    delete deadSPD;
-    delete entrySDD;
     delete entryNoiseSSD;
     delete entryGainSSD;
     delete entryBadChannelsSSD;
-    delete entry2SDD;
-    //delete mapASDD;
-    delete mapTSDD;
-    delete drSpSDD;
-    delete ddlMapSDD;
   }
 
-  if ((!pSDD)|| (!calSPD) || (!caldeadSPD) ||(!calSDD) || (!drSp) || (!ddlsdd)
-      || (!mapT) || (!noiseSSD)|| (!gainSSD)|| (!badChannelsSSD)) {
-    AliWarning("Can not get calibration from calibration database !");
+  if ((!noiseSSD)|| (!gainSSD)|| (!badChannelsSSD)) {
+    AliWarning("Can not get SSD calibration from calibration database !");
     return kFALSE;
   }
 
-  fNMod[0] = calSPD->GetEntries();
-  fNMod[1] = calSDD->GetEntries();
-  AliInfo(Form("%i SPD, %i SDD and %i SSD in calibration database",
-              fNMod[0], fNMod[1], fNMod[2]));
-  AliITSCalibration* cal;
-  for (Int_t i=0; i<fNMod[0]; i++) {
-    cal = (AliITSCalibration*) calSPD->At(i);
-    SetCalibrationModel(i, cal);
-    cal = (AliITSCalibration*) caldeadSPD->At(i);
-    SetSPDDeadModel(i, cal);
-  }
-
-  fDDLMapSDD=ddlsdd;
-  fRespSDD=pSDD;
-  for(Int_t iddl=0; iddl<AliITSDDLModuleMapSDD::GetNDDLs(); iddl++){
-    for(Int_t icar=0; icar<AliITSDDLModuleMapSDD::GetNModPerDDL();icar++){
-      Int_t iMod=fDDLMapSDD->GetModuleNumber(iddl,icar);
-      if(iMod==-1) continue;
-      Int_t i=iMod - fgkDefaultNModulesSPD;
-      cal = (AliITSCalibration*) calSDD->At(i);
-      Int_t i0=2*i;
-      Int_t i1=1+2*i;
-      AliITSDriftSpeedArraySDD* arr0 = (AliITSDriftSpeedArraySDD*) drSp->At(i0);
-      //      AliITSMapSDD* ma0 = (AliITSMapSDD*)mapAn->At(i0);
-      AliITSMapSDD* mt0 = (AliITSMapSDD*)mapT->At(i0);
-      AliITSDriftSpeedArraySDD* arr1 = (AliITSDriftSpeedArraySDD*) drSp->At(i1);
-      //      AliITSMapSDD* ma1 = (AliITSMapSDD*)mapAn->At(i1);
-      AliITSMapSDD* mt1 = (AliITSMapSDD*)mapT->At(i1);
-      cal->SetDriftSpeed(0,arr0);
-      cal->SetDriftSpeed(1,arr1);
-//       cal->SetMapA(0,ma0);
-//       cal->SetMapA(1,ma1);
-      cal->SetMapT(0,mt0);
-      cal->SetMapT(1,mt1);
-      SetCalibrationModel(iMod, cal);
-    }
-  }
-
   fSSDCalibration->SetNoise(noiseSSD);
   fSSDCalibration->SetGain(gainSSD);
   fSSDCalibration->SetBadChannels(badChannelsSSD);
   //fSSDCalibration->FillBadChipMap();
 
-
-
   return kTRUE;
 }
 
-
-//________________________________________________________________
-void AliITSDetTypeRec::SetDefaultClusterFinders(){
-  
-  //set defaults for standard cluster finder
-
-  if(!GetITSgeom()){
-    Warning("SetDefaults","null pointer to AliITSgeom!");
-    return;
-  }
-
-  AliITSClusterFinder *clf; 
-
-  for(Int_t dettype=0;dettype<fgkNdettypes;dettype++){
-    //SPD
-    if(dettype==0){
-      if(!GetReconstructionModel(dettype)){
-       TClonesArray *dig0 = DigitsAddress(0);
-       TClonesArray *rec0 = ClustersAddress(0);
-       clf = new AliITSClusterFinderSPD(this,dig0,rec0);
-       SetReconstructionModel(dettype,clf);
-
-      }
-    }
-   
-    //SDD
-    if(dettype==1){
-      if(!GetReconstructionModel(dettype)){
-       TClonesArray *dig1 = DigitsAddress(1);
-       TClonesArray *rec1 = ClustersAddress(1);
-       clf = new AliITSClusterFinderSDD(this,dig1,rec1);
-       SetReconstructionModel(dettype,clf);
-      }
-
-    }
-    //SSD
-    if(dettype==2){
-      if(!GetReconstructionModel(dettype)){
-       TClonesArray* dig2 = DigitsAddress(2);
-       clf = new AliITSClusterFinderSSD(this,dig2);
-       SetReconstructionModel(dettype,clf);
-      }
-    }
-
- }
-  
-}
-
 //________________________________________________________________
 void AliITSDetTypeRec::SetDefaultClusterFindersV2(Bool_t rawdata){
 
@@ -710,23 +740,6 @@ void AliITSDetTypeRec::MakeBranch(TTree* tree, Option_t* option){
 
 }
 
-//___________________________________________________________________
-void AliITSDetTypeRec::AddCluster(Int_t id, AliITSRawCluster *c){
-
-  // Adds a raw cluster to the list
-  TClonesArray &lc = *((TClonesArray*)fCtype->At(id));  
-  switch(id){
-  case 0:
-    new(lc[fNctype[id]++]) AliITSRawClusterSPD(*((AliITSRawClusterSPD*)c));
-    break;
-  case 1:
-    new(lc[fNctype[id]++]) AliITSRawClusterSDD(*((AliITSRawClusterSDD*)c));
-    break;
-  case 2:
-    new(lc[fNctype[id]++]) AliITSRawClusterSSD(*((AliITSRawClusterSSD*)c));
-    break;
-  } 
-}
 //___________________________________________________________________
 void AliITSDetTypeRec::ResetDigits(){
   // Reset number of digits and the digits array for the ITS detector.
@@ -741,26 +754,7 @@ void AliITSDetTypeRec::ResetDigits(Int_t branch){
   // Reset number of digits and the digits array for this branch.
   
   if(fDigits->At(branch)) ((TClonesArray*)fDigits->At(branch))->Clear();
-  if(fNdtype) fNdtype[branch]=0;
-
-}
-
-//__________________________________________________________________
-void AliITSDetTypeRec::ResetClusters(){
-
-  //Resets number of clusters and the cluster array 
-  for(Int_t i=0;i<fgkNdettypes;i++){
-    ResetClusters(i);
-  }
-}
-
-//__________________________________________________________________
-void AliITSDetTypeRec::ResetClusters(Int_t i){
-
-  //Resets number of clusters and the cluster array for this branch
 
-  if (fCtype->At(i))    ((TClonesArray*)fCtype->At(i))->Clear();
-  if (fNctype)  fNctype[i]=0;
 }
 //__________________________________________________________________
 void AliITSDetTypeRec::MakeBranchR(TTree *treeR, Option_t *opt){
@@ -791,7 +785,7 @@ void AliITSDetTypeRec::MakeBranchR(TTree *treeR, Option_t *opt){
     MakeBranchInTree(treeR,branchname,0,&fRecPoints,buffsz,99);
 }
 //______________________________________________________________________
-void AliITSDetTypeRec::SetTreeAddressR(TTree *treeR){
+void AliITSDetTypeRec::SetTreeAddressR(TTree* const treeR){
     // Set branch address for the Reconstructed points Trees.
     // Inputs:
     //      TTree *treeR   Tree containing the RecPoints.
@@ -799,24 +793,24 @@ void AliITSDetTypeRec::SetTreeAddressR(TTree *treeR){
     //      none.
     // Return:
 
-    char branchname[30];
-    Char_t namedet[10]="ITS";
+   char branchname[30];
+   Char_t namedet[10]="ITS";
 
-    if(!treeR) return;
-    if(fRecPoints==0x0) fRecPoints = new TClonesArray("AliITSRecPoint",1000);
-    TBranch *branch;
-    sprintf(branchname,"%sRecPoints",namedet);
-    branch = treeR->GetBranch(branchname);
-    if (branch) {
+   if(!treeR) return;
+   if(fRecPoints==0x0) fRecPoints = new TClonesArray("AliITSRecPoint",1000);
+   TBranch *branch;
+   sprintf(branchname,"%sRecPoints",namedet);
+   branch = treeR->GetBranch(branchname);
+   if (branch) {
       branch->SetAddress(&fRecPoints);
-    }else {
+    } 
+    else {
       sprintf(branchname,"%sRecPointsF",namedet);
       branch = treeR->GetBranch(branchname);
       if (branch) {
        branch->SetAddress(&fRecPoints);
       }
-
-    }
+   }
 }
 //____________________________________________________________________
 void AliITSDetTypeRec::AddRecPoint(const AliITSRecPoint &r){
@@ -834,7 +828,7 @@ void AliITSDetTypeRec::AddRecPoint(const AliITSRecPoint &r){
 }
 
 //______________________________________________________________________
-void AliITSDetTypeRec::DigitsToRecPoints(TTree *treeD,TTree *treeR,Int_t lastentry,Option_t *opt, Bool_t v2){
+void AliITSDetTypeRec::DigitsToRecPoints(TTree *treeD,TTree *treeR,Int_t lastentry,Option_t *opt, Int_t optCluFind){
   // cluster finding and reconstruction of space points
   // the condition below will disappear when the geom class will be
   // initialized for all versions - for the moment it is only for v5 !
@@ -851,15 +845,33 @@ void AliITSDetTypeRec::DigitsToRecPoints(TTree *treeD,TTree *treeR,Int_t lastent
   const char *all = strstr(opt,"All");
   const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
                         strstr(opt,"SSD")};
-  if(!v2) {
-    SetDefaultClusterFinders();
-    AliInfo("Original cluster finder has been selected\n");
-  }
-  else   { 
+  if(optCluFind==0){
     SetDefaultClusterFindersV2();
-    AliInfo("V2 cluster finder has been selected \n");
+    AliDebug(1,"V2 cluster finder has been selected \n");
+  }else{
+    SetDefaultClusterFindersV2();
+    AliInfo("Cluster Finder Option not implemented, V2 cluster finder will be used \n");    
+  }
+
+  
+  // Reset Fast-OR fired map
+  ResetFastOrFiredMap();
+
+  if (all || det[0]) { // SPD present
+    // Get the FO signals for this event
+    AliRunLoader* runLoader = AliRunLoader::Instance();
+    AliITSLoader* itsLoader = (AliITSLoader*) runLoader->GetLoader("ITSLoader");
+    if (!itsLoader) {
+      AliError("ITS loader is NULL.");
+    }
+   else {
+      fFOSignals = (AliITSFOSignalsSPD*)itsLoader->TreeD()->GetUserInfo()->FindObject("AliITSFOSignalsSPD");
+      if(!fFOSignals) AliError("FO signals not retrieved");
+     }
+
   }
 
+  
   AliITSClusterFinder *rec     = 0;
   Int_t id,module,first=0;
   for(module=0;module<GetITSgeom()->GetIndexMax();module++){
@@ -873,20 +885,34 @@ void AliITSDetTypeRec::DigitsToRecPoints(TTree *treeD,TTree *treeR,Int_t lastent
       ResetDigits();  // MvL: Not sure we neeed this when rereading anyways
       if (all) {
           treeD->GetEvent(lastentry+module);
-      }else {
-          treeD->GetEvent(lastentry+(module-first));
-      }
-      Int_t ndigits = itsDigits->GetEntriesFast();
-      if(ndigits>0){
-       rec->SetDetTypeRec(this);
-       rec->SetDigits(DigitsAddress(id));
-       //      rec->SetClusters(ClustersAddress(id));
-       rec->FindRawClusters(module);
-      } // end if
-      treeR->Fill();
-      ResetRecPoints();
-      ResetClusters();
-  } 
+        }
+    else {
+      treeD->GetEvent(lastentry+(module-first));
+    }
+    Int_t ndigits = itsDigits->GetEntriesFast();
+    if (ndigits>0 || id==0) { // for SPD we always want to call FindRawClusters (to process FO signals)
+      rec->SetDetTypeRec(this);
+      rec->SetDigits(DigitsAddress(id));
+      //       rec->SetClusters(ClustersAddress(id));
+      rec->FindRawClusters(module);
+    } // end if
+    treeR->Fill();
+    ResetRecPoints();
+  }
+  
+   // Remove PIT in-active chips from Fast-OR fired map
+  if (all || det[0]) { // SPD present
+    RemoveFastOrFiredInActive();
+    // here removing bits which have no associated clusters 
+    RemoveFastOrFiredFromDead(GetFiredChipMap(treeR));  
+  }
+
+  AliITSRecPointContainer* rpcont = AliITSRecPointContainer::Instance();
+  Int_t nClu[6];
+  nClu[0]=rpcont->GetNClustersInLayer(1,treeR);
+  for(Int_t iLay=2; iLay<=6; iLay++) nClu[iLay-1]=rpcont->GetNClustersInLayerFast(iLay);
+  AliInfo(Form("Number of RecPoints in ITS Layers = %d %d %d %d %d %d",
+              nClu[0],nClu[1],nClu[2],nClu[3],nClu[4],nClu[5]));
 }
 //______________________________________________________________________
 void AliITSDetTypeRec::DigitsToRecPoints(AliRawReader* rawReader,TTree *treeR,Option_t *opt){
@@ -904,65 +930,88 @@ void AliITSDetTypeRec::DigitsToRecPoints(AliRawReader* rawReader,TTree *treeR,Op
   const char *all = strstr(opt,"All");
   const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
                         strstr(opt,"SSD")};
-  AliITSClusterFinderV2 *rec     = 0;
+  
   Int_t id=0;
-
-  TClonesArray *array=new TClonesArray("AliITSRecPoint",1000);
+  AliITSRecPointContainer* rpc = AliITSRecPointContainer::Instance();
+  rpc->FullReset();
+  TClonesArray* array = rpc->UncheckedGetClusters(0);
   TBranch *branch = treeR->Branch("ITSRecPoints",&array);
-  delete array;
-  TClonesArray** clusters = new TClonesArray*[GetITSgeom()->GetIndexMax()]; 
-  for (Int_t iModule = 0; iModule < GetITSgeom()->GetIndexMax(); iModule++) {
-    clusters[iModule] = NULL;
-  }
-  for(id=0;id<3;id++){
-    if (!all && !det[id]) continue;
-    rec = (AliITSClusterFinderV2*)GetReconstructionModel(id);
-    if (!rec)
-      AliFatal("The reconstruction class was not instanciated");
-    rec->SetDetTypeRec(this);
-    rec->RawdataToClusters(rawReader,clusters);    
-  } 
+  DigitsToRecPoints(rawReader,opt); 
+
   Int_t nClusters =0;
-  TClonesArray *emptyArray=new TClonesArray("AliITSRecPoint");
   for(Int_t iModule=0;iModule<GetITSgeom()->GetIndexMax();iModule++){
     id = GetITSgeom()->GetModuleType(iModule);
     if (!all && !det[id]) continue;
-    array = clusters[iModule];
+    array = rpc->UncheckedGetClusters(iModule);
     if(!array){
       AliDebug(1,Form("data for module %d missing!",iModule));
-      array = emptyArray;
     }
     branch->SetAddress(&array);
     treeR->Fill();
     nClusters+=array->GetEntriesFast();
-
-    if (array != emptyArray) {
-      array->Delete();
-      delete array;
-    }
   }
-  delete emptyArray;
 
-  delete[] clusters;
-  Info("DigitsToRecPoints", "total number of found recpoints in ITS: %d\n", 
-       nClusters);
-  
+  rpc->FullReset();
+
+  AliITSRecPointContainer* rpcont = AliITSRecPointContainer::Instance();
+  Int_t nClu[6];
+  nClu[0]=rpcont->GetNClustersInLayer(1,treeR);
+  for(Int_t iLay=2; iLay<=6; iLay++) nClu[iLay-1]=rpcont->GetNClustersInLayerFast(iLay);
+  AliInfo(Form("Number of RecPoints in ITS Layers = %d %d %d %d %d %d, Total = %d",
+              nClu[0],nClu[1],nClu[2],nClu[3],nClu[4],nClu[5],nClusters));
 }
+//______________________________________________________________________
+void AliITSDetTypeRec::DigitsToRecPoints(AliRawReader* rawReader,Option_t *opt){
+  // cluster finding and reconstruction of space points
+  // 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:
+  //      AliRawReader *rawReader  Pointer to the raw-data reader
+  // Outputs:
+  //      none.
+  // Return:
+  //      none.
+  const char *all = strstr(opt,"All");
+  const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
+                        strstr(opt,"SSD")};
+  
+  // Reset Fast-OR fired map
+  ResetFastOrFiredMap();
+  
+  AliITSClusterFinder *rec     = 0;
+  Int_t id=0;
 
+  for(id=0;id<3;id++){
+    if (!all && !det[id]) continue;
+    rec = (AliITSClusterFinder*)GetReconstructionModel(id);
+    if (!rec)
+      AliFatal("The reconstruction class was not instantiated");
+    rec->SetDetTypeRec(this);
+    rec->RawdataToClusters(rawReader);    
+  } 
+   
+  // Remove PIT in-active chips from Fast-OR fired map
+  if (all || det[0]) { // SPD present
+    RemoveFastOrFiredInActive();
+    // here removing bits which have no associated clusters 
+    RemoveFastOrFiredFromDead(GetFiredChipMap());
+   
+  }  
+}
 //______________________________________________________________________
-void AliITSDetTypeRec::ReadOldSSDNoise(TObjArray *array, 
+void AliITSDetTypeRec::ReadOldSSDNoise(const TObjArray *array, 
                                       AliITSNoiseSSDv2 *noiseSSD) {
   //Reads the old SSD calibration object and converts it to the new format
   const Int_t fgkSSDSTRIPSPERMODULE = 1536;
   const Int_t fgkSSDPSIDESTRIPSPERMODULE = 768;
 
-  Int_t fNMod = array->GetEntries();
+  Int_t gNMod = array->GetEntries();
   cout<<"Converting old calibration object for noise..."<<endl;
 
   //NOISE
   Double_t noise = 0.0;
-  for (Int_t iModule = 0; iModule < fNMod; iModule++) {
+  for (Int_t iModule = 0; iModule < gNMod; iModule++) {
     AliITSNoiseSSD *noiseModule = (AliITSNoiseSSD*) (array->At(iModule));
     for(Int_t iStrip = 0; iStrip < fgkSSDSTRIPSPERMODULE; iStrip++) {
       noise = (iStrip < fgkSSDPSIDESTRIPSPERMODULE) ? noiseModule->GetNoiseP(iStrip) : noiseModule->GetNoiseN(1535 - iStrip);
@@ -975,12 +1024,12 @@ void AliITSDetTypeRec::ReadOldSSDNoise(TObjArray *array,
 }
 
 //______________________________________________________________________
-void AliITSDetTypeRec::ReadOldSSDBadChannels(TObjArray *array, 
+void AliITSDetTypeRec::ReadOldSSDBadChannels(const TObjArray *array, 
                                             AliITSBadChannelsSSDv2 *badChannelsSSD) {
   //Reads the old SSD calibration object and converts it to the new format
-  Int_t fNMod = array->GetEntries();
+  Int_t gNMod = array->GetEntries();
   cout<<"Converting old calibration object for bad channels..."<<endl;
-  for (Int_t iModule = 0; iModule < fNMod; iModule++) {
+  for (Int_t iModule = 0; iModule < gNMod; iModule++) {
     //for (Int_t iModule = 0; iModule < 1; iModule++) {
     AliITSBadChannelsSSD *bad = (AliITSBadChannelsSSD*) (array->At(iModule));
     TArrayI arrayPSide = bad->GetBadPChannelsList();
@@ -999,15 +1048,15 @@ void AliITSDetTypeRec::ReadOldSSDBadChannels(TObjArray *array,
 }
 
 //______________________________________________________________________
-void AliITSDetTypeRec::ReadOldSSDGain(TObjArray *array, 
+void AliITSDetTypeRec::ReadOldSSDGain(const TObjArray *array, 
                                      AliITSGainSSDv2 *gainSSD) {
   //Reads the old SSD calibration object and converts it to the new format
 
-  Int_t fNMod = array->GetEntries();
+  Int_t gNMod = array->GetEntries();
   cout<<"Converting old calibration object for gain..."<<endl;
 
   //GAIN
-  for (Int_t iModule = 0; iModule < fNMod; iModule++) {
+  for (Int_t iModule = 0; iModule < gNMod; iModule++) {
     AliITSGainSSD *gainModule = (AliITSGainSSD*) (array->At(iModule));
     TArrayF arrayPSide = gainModule->GetGainP();
     for(Int_t iPCounter = 0; iPCounter < arrayPSide.GetSize(); iPCounter++)
@@ -1021,5 +1070,132 @@ void AliITSDetTypeRec::ReadOldSSDGain(TObjArray *array,
                        arrayNSide.At(iNCounter));
   }//loop over modules 
 }
+//______________________________________________________________________
+void AliITSDetTypeRec::RemoveFastOrFiredInActive() {
+  // Removes the chips that were in-active in the pixel trigger (from fast-or fired map)
 
+  if (fTriggerConditions==NULL) {
+    AliError("Pixel trigger conditions are missing.");
+    return;
+  }
+  Int_t eq   = -1;
+  Int_t hs   = -1;
+  Int_t chip = -1;
+  while (fTriggerConditions->GetNextInActiveChip(eq,hs,chip)) {
+    UInt_t chipKey = AliITSRawStreamSPD::GetOfflineChipKeyFromOnline(eq,hs,chip);
+    fFastOrFiredMap.SetBitNumber(chipKey,kFALSE);
+  }
+}
+//______________________________________________________________________
+TBits AliITSDetTypeRec::GetFiredChipMap() const {
+  
+  //
+  // TBits of the fired chips  
+  //
+  AliITSRecPointContainer* rpc = AliITSRecPointContainer::Instance();
+
+  TBits isfiredchip(1200);
+  
+   AliITSsegmentationSPD *segSPD = (AliITSsegmentationSPD*)GetSegmentationModel(0);
+   if(!segSPD) {
+    AliError("no segmentation model for SPD available, the fired chip map is empty. Exiting"); 
+    return isfiredchip;
+   }
+   
+  
+  for(Int_t imod =0; imod < fgkDefaultNModulesSPD; imod++){
+    TClonesArray *array = rpc->UncheckedGetClusters(imod);
+    if(!array) continue;
+    Int_t nCluster = array->GetEntriesFast();
+    while(nCluster--) {
+      AliITSRecPoint* cluster = (AliITSRecPoint*)array->UncheckedAt(nCluster);
+     if (cluster->GetLayer()>1)continue;
+     Float_t local[3]={-1,-1};
+     local[1]=cluster->GetDetLocalX();
+     local[0]=cluster->GetDetLocalZ();
+     
+     Int_t eq = AliITSRawStreamSPD::GetOnlineEqIdFromOffline(imod);
+     Int_t hs = AliITSRawStreamSPD::GetOnlineHSFromOffline(imod);
+     Int_t row, col;
+     segSPD->LocalToDet(0.5,local[0],row,col);
+     Int_t chip = AliITSRawStreamSPD::GetOnlineChipFromOffline(imod,col);
+     Int_t chipkey = AliITSRawStreamSPD::GetOfflineChipKeyFromOnline(eq,hs,chip);
+     isfiredchip.SetBitNumber(chipkey,kTRUE);
+    }
+    
+  } 
+  return isfiredchip;
+  
+}
+//______________________________________________________________________
+TBits AliITSDetTypeRec::GetFiredChipMap(TTree *treeR) const{
+  //
+  // TBits of the fired chips  
+  //
+  TBits isfiredchip(1200);
+  
+  if(!treeR) {
+     AliError("no treeR. fired chip map stays empty. Exiting.");
+     return isfiredchip;
+   }
+   
+  AliITSRecPointContainer* rpcont=AliITSRecPointContainer::Instance();
+  TClonesArray *recpoints = rpcont->FetchClusters(0,treeR);
+  if(!rpcont->GetStatusOK() || !rpcont->IsSPDActive()){
+    AliError("no clusters. fired chip map stays empty. Exiting.");
+     return isfiredchip;
+  }
+  
+   AliITSsegmentationSPD *segSPD = (AliITSsegmentationSPD*)GetSegmentationModel(0);
+      
+   for(Int_t imod =0; imod < fgkDefaultNModulesSPD; imod++){
+    recpoints = rpcont->UncheckedGetClusters(imod);
+    Int_t nCluster = recpoints->GetEntriesFast();
+    
+    // loop over clusters
+    while(nCluster--) {
+      AliITSRecPoint* cluster = (AliITSRecPoint*)recpoints->UncheckedAt(nCluster);
+      if (cluster->GetLayer()>1)continue;
+      Float_t local[3]={-1,-1};
+      local[1]=cluster->GetDetLocalX();
+      local[0]=cluster->GetDetLocalZ();
+      
+      Int_t eq = AliITSRawStreamSPD::GetOnlineEqIdFromOffline(imod);
+      Int_t hs = AliITSRawStreamSPD::GetOnlineHSFromOffline(imod);
+      Int_t row, col;
+      segSPD->LocalToDet(0.5,local[0],row,col);
+      Int_t chip = AliITSRawStreamSPD::GetOnlineChipFromOffline(imod,col);
+      Int_t chipkey = AliITSRawStreamSPD::GetOfflineChipKeyFromOnline(eq,hs,chip);
+      isfiredchip.SetBitNumber(chipkey,kTRUE);
+    }
+  }
+  return isfiredchip;
+}
+//______________________________________________________________________
+void  AliITSDetTypeRec::RemoveFastOrFiredFromDead(TBits firedchipmap){
+  //
+  // resetting of the fast-or bit on cluster basis. 
+  // fast-or bits can be remnant from SPD ideal simulation (no dead channels)
+  //
+  
+  for(Int_t chipKey=0; chipKey<1200; chipKey++){
+    // FO masked chips have been previously removed  
+   if(!fFastOrFiredMap.TestBitNumber(chipKey)) continue; 
+   if(!firedchipmap.TestBitNumber(chipKey))  {
+    fFastOrFiredMap.SetBitNumber(chipKey,kFALSE);
+    AliDebug(2,Form("removing bit in key %i \n ",chipKey));
+  }
+ }
+   
+}
+//______________________________________________________________________
+void AliITSDetTypeRec::SetFastOrFiredMapOnline(UInt_t eq, UInt_t hs, UInt_t chip) {
+  // Set fast-or fired map for this chip
+  Int_t chipKey = AliITSRawStreamSPD::GetOfflineChipKeyFromOnline(eq,hs,chip);
+  return SetFastOrFiredMap(chipKey);
+}