LCOV - code coverage report
Current view: top level - ITS/ITSbase - AliITSDetTypeRec.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 471 678 69.5 %
Date: 2016-06-14 17:26:59 Functions: 37 45 82.2 %

          Line data    Source code
       1             : /***************************************************************************
       2             :  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
       3             :  *                                                                        *
       4             :  * Author: The ALICE Off-line Project.                                    *
       5             :  * Conributors are mentioned in the code where appropriate.              *
       6             :  *                                                                        *
       7             :  * Permission to use, copy, modify and distribute this software and its   *
       8             :  * documentation strictly for non-commercial purposes is hereby granted   *
       9             :  * without fee, provided that the above copyright notice appears in all   *
      10             :  * copies and that both the copyright notice and this permission notice   *
      11             :  * appear in the supporting documentation. The authors make no claims     *
      12             :  * about the suitability of this software for any purpose. It is          *
      13             :  * provided "as is" without express or implied warranty.                  *
      14             :  **************************************************************************/
      15             : 
      16             : 
      17             : 
      18             : ////////////////////////////////////////////////////////////////////////
      19             : // This class defines the "Standard" reconstruction for the ITS       // 
      20             : // detector.                                                          //
      21             : //                                                                    //
      22             : ////////////////////////////////////////////////////////////////////////
      23             : #include "TObjArray.h"
      24             : #include "TTree.h"
      25             : 
      26             : #include "AliCDBManager.h"
      27             : #include "AliCDBEntry.h"
      28             : #include "AliITSClusterFinder.h"
      29             : #include "AliITSClusterFinderV2SPD.h"
      30             : #include "AliITSClusterFinderV2SDD.h"
      31             : #include "AliITSClusterFinderSDDfast.h"
      32             : #include "AliITSClusterFinderV2SSD.h"
      33             : #include "AliITSDetTypeRec.h"
      34             : #include "AliITSDDLModuleMapSDD.h"
      35             : #include "AliITSRecPoint.h"
      36             : #include "AliITSRecPointContainer.h"
      37             : #include "AliITSCalibrationSDD.h"
      38             : #include "AliITSMapSDD.h"
      39             : #include "AliITSCalibrationSSD.h"
      40             : #include "AliITSNoiseSSDv2.h"
      41             : #include "AliITSGainSSDv2.h"
      42             : #include "AliITSBadChannelsSSDv2.h"
      43             : #include "AliITSNoiseSSD.h"
      44             : #include "AliITSGainSSD.h"
      45             : #include "AliITSBadChannelsSSD.h"
      46             : #include "AliITSresponseSDD.h"
      47             : #include "AliITSsegmentationSPD.h"
      48             : #include "AliITSsegmentationSDD.h"
      49             : #include "AliITSsegmentationSSD.h"
      50             : #include "AliLog.h"
      51             : #include "AliITSRawStreamSPD.h"
      52             : #include "AliITSTriggerConditions.h"
      53             : #include "AliITSFOSignalsSPD.h"
      54             : #include "AliRunLoader.h"
      55             : #include "AliDataLoader.h"
      56             : #include "AliITSLoader.h"
      57             : #include "AliITSReconstructor.h"
      58             : 
      59             : 
      60             : class AliITSDriftSpeedArraySDD;
      61             : class AliITSCorrMapSDD;
      62             : class AliITSRecoParam;
      63             : 
      64             : const Int_t AliITSDetTypeRec::fgkNdettypes = 3;
      65             : const Int_t AliITSDetTypeRec::fgkDefaultNModulesSPD =  240;
      66             : const Int_t AliITSDetTypeRec::fgkDefaultNModulesSDD =  260;
      67             : const Int_t AliITSDetTypeRec::fgkDefaultNModulesSSD = 1698;
      68             : 
      69         118 : ClassImp(AliITSDetTypeRec)
      70             : 
      71             : //________________________________________________________________
      72           2 : AliITSDetTypeRec::AliITSDetTypeRec(): TObject(),
      73           2 : fNMod(0),
      74           2 : fITSgeom(0),
      75           2 : fReconstruction(0),
      76           2 : fSegmentation(0),
      77           2 : fCalibration(0),
      78           2 : fSSDCalibration(0),
      79           2 : fSPDDead(0),
      80           2 : fSPDSparseDead(0),
      81           2 : fTriggerConditions(0),
      82           2 : fDigits(0),
      83           2 : fFOSignals(0),
      84           2 : fDDLMapSDD(0),
      85           2 : fRespSDD(0),
      86           2 : fAveGainSDD(0),
      87           2 : fRecPoints(0),
      88           2 : fNRecPoints(0),
      89           2 : fFirstcall(kTRUE),
      90           2 : fLoadOnlySPDCalib(0),
      91          12 : fFastOrFiredMap(1200){
      92             :     // Standard Constructor
      93             :     // Inputs:
      94             :     //    none.
      95             :     // Outputs:
      96             :     //    none.
      97             :     // Return:
      98             :     //   
      99             : 
     100           6 :   fReconstruction = new TObjArray(fgkNdettypes);
     101           6 :   fDigits = new TObjArray(fgkNdettypes);
     102          16 :   for(Int_t i=0; i<3; i++){
     103           6 :     fkDigClassName[i]=0;
     104             :   }
     105           6 :   fSSDCalibration=new AliITSCalibrationSSD();
     106           4 :   fNMod = new Int_t [fgkNdettypes];
     107           2 :   fNMod[0] = fgkDefaultNModulesSPD;
     108           2 :   fNMod[1] = fgkDefaultNModulesSDD;
     109           2 :   fNMod[2] = fgkDefaultNModulesSSD;
     110           2 :   fNRecPoints = 0;
     111             :   
     112             :   
     113           4 : }
     114             : 
     115             : //______________________________________________________________________
     116           0 : AliITSDetTypeRec::AliITSDetTypeRec(const AliITSDetTypeRec & rec):TObject(rec),
     117           0 : fNMod(rec.fNMod),
     118           0 : fITSgeom(rec.fITSgeom),
     119           0 : fReconstruction(rec.fReconstruction),
     120           0 : fSegmentation(rec.fSegmentation),
     121           0 : fCalibration(rec.fCalibration),
     122           0 : fSSDCalibration(rec.fSSDCalibration),
     123           0 : fSPDDead(rec.fSPDDead),
     124           0 : fSPDSparseDead(rec.fSPDSparseDead),
     125           0 : fTriggerConditions(rec.fTriggerConditions),
     126           0 : fDigits(rec.fDigits),
     127           0 : fFOSignals(rec.fFOSignals),
     128           0 : fDDLMapSDD(rec.fDDLMapSDD),
     129           0 : fRespSDD(rec.fRespSDD),
     130           0 : fAveGainSDD(rec.fAveGainSDD),
     131           0 : fRecPoints(rec.fRecPoints),
     132           0 : fNRecPoints(rec.fNRecPoints),
     133           0 : fFirstcall(rec.fFirstcall),
     134           0 : fLoadOnlySPDCalib(rec.fLoadOnlySPDCalib),
     135           0 : fFastOrFiredMap(rec.fFastOrFiredMap){
     136             : 
     137             :   // Copy constructor. 
     138           0 :   for(Int_t i=0; i<3; i++){    
     139           0 :     fkDigClassName[i]=rec.fkDigClassName[i];  // NB only copies Char_t*, so not so safe, but this code should never be reached anyways
     140             :   }
     141           0 : }
     142             : //______________________________________________________________________
     143             : AliITSDetTypeRec& AliITSDetTypeRec::operator=(const AliITSDetTypeRec& source){
     144             :     // Assignment operator. 
     145           0 :     this->~AliITSDetTypeRec();
     146           0 :     new(this) AliITSDetTypeRec(source);
     147           0 :     return *this;
     148             : 
     149           0 : }
     150             : 
     151             : //_____________________________________________________________________
     152          12 : AliITSDetTypeRec::~AliITSDetTypeRec(){
     153             :   //Destructor
     154             : 
     155           2 :   if(fReconstruction){
     156           2 :     fReconstruction->Delete();
     157           4 :     delete fReconstruction;
     158             :   }
     159           2 :   if(fSegmentation){
     160           2 :     fSegmentation->Delete();
     161           4 :     delete fSegmentation;
     162             :   }
     163           2 :   if(fCalibration){
     164           4 :     if(!(AliCDBManager::Instance()->GetCacheFlag())) {
     165           0 :       fCalibration->Delete();
     166           0 :       delete fCalibration;
     167           0 :       if(fRespSDD) delete fRespSDD;
     168           0 :       if(fDDLMapSDD) delete fDDLMapSDD;
     169             :    }
     170             :   }
     171           2 :   if(fSSDCalibration){
     172           4 :     if(!(AliCDBManager::Instance()->GetCacheFlag())) {
     173           0 :       delete fSSDCalibration;
     174             :     }
     175             :   }
     176           2 :    if(fSPDDead){
     177           4 :     if(!(AliCDBManager::Instance()->GetCacheFlag())) {
     178           0 :       fSPDDead->Delete();
     179           0 :       delete fSPDDead;
     180             :     }
     181             :   } 
     182           2 :      if(fSPDSparseDead){
     183           4 :     if(!(AliCDBManager::Instance()->GetCacheFlag())) {
     184           0 :       fSPDSparseDead->Delete();
     185           0 :       delete fSPDSparseDead;
     186             :     }
     187             :   } 
     188           2 :   if(fTriggerConditions){
     189           4 :     if(!(AliCDBManager::Instance()->GetCacheFlag())) {
     190           0 :       fTriggerConditions->Delete();
     191           0 :       delete fTriggerConditions;
     192             :     }
     193             :   } 
     194           2 :   if(fDigits){
     195           2 :     fDigits->Delete();
     196           4 :     delete fDigits;
     197             :   }
     198           2 :   if(fRecPoints){
     199           1 :     fRecPoints->Delete();
     200           2 :     delete fRecPoints;
     201             :   }
     202           4 :   delete [] fNMod;
     203             :   
     204           6 :   if (fITSgeom) delete fITSgeom;
     205             :  
     206           6 : }
     207             : 
     208             : //___________________________________________________________________
     209             : void AliITSDetTypeRec::SetReconstructionModel(Int_t dettype,AliITSClusterFinder *clf){
     210             : 
     211             :   //Set reconstruction model for detector type
     212             : 
     213          12 :   if(fReconstruction==0) fReconstruction = new TObjArray(fgkNdettypes);
     214           6 :   if(fReconstruction->At(dettype)!=0) delete fReconstruction->At(dettype);
     215           6 :   fReconstruction->AddAt(clf,dettype);
     216           6 : }
     217             : //______________________________________________________________________
     218             : AliITSClusterFinder* AliITSDetTypeRec::GetReconstructionModel(Int_t dettype) const{
     219             : 
     220             :   //Get reconstruction model for detector type
     221       17656 :   if(fReconstruction==0)  {
     222           0 :     Warning("GetReconstructionModel","fReconstruction is 0!");
     223           0 :     return 0;     
     224             :   }
     225        8828 :   return (AliITSClusterFinder*)fReconstruction->At(dettype);
     226        8828 : }
     227             : 
     228             : //______________________________________________________________________
     229             : void AliITSDetTypeRec::SetSegmentationModel(Int_t dettype,AliITSsegmentation *seg){
     230             :    
     231             :   //Set segmentation model for detector type
     232             :   
     233          16 :   if(fSegmentation==0) fSegmentation = new TObjArray(fgkNdettypes);
     234           6 :   if(fSegmentation->At(dettype)!=0) delete fSegmentation->At(dettype);
     235           6 :   fSegmentation->AddAt(seg,dettype);
     236             : 
     237           6 : }
     238             : //______________________________________________________________________
     239             : AliITSsegmentation* AliITSDetTypeRec::GetSegmentationModel(Int_t dettype) const {
     240             : 
     241             :   //Get segmentation model for detector type
     242             :    
     243       19868 :    if(fSegmentation==0) {
     244           0 :      Warning("GetSegmentationModel","fSegmentation is 0!");
     245           0 :      return 0; 
     246             :    } 
     247        9934 :    return (AliITSsegmentation*)fSegmentation->At(dettype);
     248             : 
     249        9934 : }
     250             : //_______________________________________________________________________
     251             : void AliITSDetTypeRec::SetCalibrationModel(Int_t iMod, AliITSCalibration *cal){
     252             : 
     253             :   //Set calibration (response) for the module iMod of type dettype
     254        2000 :   if (fCalibration==0) {
     255           0 :     fCalibration = new TObjArray(GetITSgeom()->GetIndexMax());
     256           0 :     fCalibration->SetOwner(kTRUE);
     257           0 :     fCalibration->Clear();
     258           0 :   }
     259             : 
     260        1000 :   if (fCalibration->At(iMod) != 0)
     261           0 :     delete (AliITSCalibration*) fCalibration->At(iMod);
     262        1000 :   fCalibration->AddAt(cal,iMod);
     263             : 
     264        1000 : }
     265             : //_______________________________________________________________________
     266             : void AliITSDetTypeRec::SetSPDDeadModel(Int_t iMod, AliITSCalibration *cal){
     267             : 
     268             :   //Set dead pixel info for the SPD module iMod
     269         960 :   if (fSPDDead==0) {
     270           4 :     fSPDDead = new TObjArray(fgkDefaultNModulesSPD);
     271           2 :     fSPDDead->SetOwner(kTRUE);
     272           2 :     fSPDDead->Clear();
     273           2 :   }
     274             : 
     275         480 :   if (fSPDDead->At(iMod) != 0)
     276           0 :     delete (AliITSCalibration*) fSPDDead->At(iMod);
     277         480 :   fSPDDead->AddAt(cal,iMod);
     278         480 : }
     279             : //_______________________________________________________________________
     280             : void AliITSDetTypeRec::SetSPDSparseDeadModel(Int_t iMod, AliITSCalibration *cal){
     281             : 
     282             :   //Set dead pixel info for the SPD ACTIVE module iMod
     283         960 :   if (fSPDSparseDead==0) {
     284           4 :     fSPDSparseDead = new TObjArray(fgkDefaultNModulesSPD);
     285           2 :     fSPDSparseDead->SetOwner(kTRUE);
     286           2 :     fSPDSparseDead->Clear();
     287           2 :   }
     288             : 
     289         480 :   if (fSPDSparseDead->At(iMod) != 0)
     290           0 :     delete (AliITSCalibration*) fSPDSparseDead->At(iMod);
     291         480 :   fSPDSparseDead->AddAt(cal,iMod);
     292         480 : }
     293             : //_______________________________________________________________________
     294             : AliITSCalibration* AliITSDetTypeRec::GetCalibrationModel(Int_t iMod) const {
     295             :   
     296             :   //Get calibration model for module type
     297             :   
     298       49860 :   if(fCalibration==0) {
     299           0 :     Warning("GetalibrationModel","fCalibration is 0!");
     300           0 :     return 0; 
     301             :   }  
     302             : 
     303       24930 :   if(iMod<fgkDefaultNModulesSPD+fgkDefaultNModulesSDD){
     304        5951 :     return (AliITSCalibration*)fCalibration->At(iMod);
     305             :   }else{
     306       18979 :     Int_t i=iMod-(fgkDefaultNModulesSPD+fgkDefaultNModulesSDD);
     307       18979 :     fSSDCalibration->SetModule(i);
     308       18979 :     return (AliITSCalibration*)fSSDCalibration;
     309             :   }
     310             : 
     311       24930 : }
     312             : //_______________________________________________________________________
     313             : AliITSCalibration* AliITSDetTypeRec::GetSPDDeadModel(Int_t iMod) const {
     314             :   
     315             :   //Get SPD dead for module iMod
     316             :   
     317        3980 :   if(fSPDDead==0) {
     318           0 :     AliWarning("fSPDDead is 0!");
     319           0 :     return 0; 
     320             :   }  
     321        1990 :   return (AliITSCalibration*)fSPDDead->At(iMod);
     322        1990 : }
     323             : //_______________________________________________________________________
     324             : AliITSCalibration* AliITSDetTypeRec::GetSPDSparseDeadModel(Int_t iMod) const {
     325             :   
     326             :   //Get SPD dead for module iMod
     327             :   
     328        2818 :   if(fSPDSparseDead==0) {
     329           0 :     AliWarning("fSPDSparseDead is 0!");
     330           0 :     return 0; 
     331             :   }  
     332        1409 :   return (AliITSCalibration*)fSPDSparseDead->At(iMod);
     333        1409 : }
     334             : //_______________________________________________________________________
     335             : AliITSTriggerConditions* AliITSDetTypeRec::GetTriggerConditions() const {
     336             :   //Get Pixel Trigger Conditions
     337           0 :   if (fTriggerConditions==0) {
     338           0 :     AliWarning("fTriggerConditions is 0!");
     339           0 :   }
     340           0 :   return fTriggerConditions;
     341             : }
     342             : //______________________________________________________________________
     343             : void AliITSDetTypeRec::SetTreeAddressD(TTree* const treeD){
     344             :     // Set branch address for the tree of digits.
     345             : 
     346           8 :   const char *det[4] = {"SPD","SDD","SSD","ITS"};
     347             :   TBranch *branch;
     348             :   const Char_t* digclass;
     349             :   Int_t i;
     350           4 :   char branchname[30];
     351             : 
     352           4 :   if(!treeD) return;
     353           4 :   if (fDigits == 0x0) {
     354           0 :     fDigits = new TObjArray(fgkNdettypes);
     355           0 :   }
     356             :   else {
     357           4 :     ResetDigits();
     358             :   }
     359          32 :   for (i=0; i<fgkNdettypes; i++) {
     360          12 :     digclass = GetDigitClassName(i);
     361          24 :     fDigits->AddAt(new TClonesArray(digclass,1000),i); 
     362          12 :     if (fgkNdettypes==3) snprintf(branchname,29,"%sDigits%s",det[3],det[i]);
     363             :     else  snprintf(branchname,29,"%sDigits%d",det[3],i+1);
     364          12 :     branch = treeD->GetBranch(branchname);
     365          24 :     if (branch) branch->SetAddress(&((*fDigits)[i]));
     366             :   } 
     367             : 
     368           8 : }
     369             : 
     370             : //_______________________________________________________________________
     371             : TBranch* AliITSDetTypeRec::MakeBranchInTree(TTree* const tree, 
     372             :                            const char* name, const char *classname, 
     373             :                            void* address,Int_t size,Int_t splitlevel)
     374             : { 
     375             : //
     376             : // Makes branch in given tree and diverts them to a separate file
     377             : // 
     378             : //
     379             : //
     380             :     
     381           8 :   if (tree == 0x0) {
     382           0 :     Error("MakeBranchInTree","Making Branch %s Tree is NULL",name);
     383           0 :     return 0x0;
     384             :   }
     385           4 :   TBranch *branch = tree->GetBranch(name);
     386           4 :   if (branch) {  
     387           0 :     return branch;
     388             :   }
     389           8 :   if (classname){
     390           4 :     branch = tree->Branch(name,classname,address,size,splitlevel);
     391           0 :   }
     392             :   else {
     393           4 :     branch = tree->Bronch(name, "TClonesArray", address, size, splitlevel);
     394             :   }
     395             :   
     396           4 :   return branch;
     397           4 : }
     398             : 
     399             : //____________________________________________________________________
     400             : void AliITSDetTypeRec::SetDefaults(){
     401             :   
     402             :   //Set defaults for segmentation and response
     403             : 
     404           4 :   if(!GetITSgeom()){
     405           0 :     Warning("SetDefaults","null pointer to AliITSgeomGeom !");
     406           0 :     return;
     407             :   }
     408             : 
     409             :   AliITSsegmentation* seg;
     410           2 :   if(!GetCalibration()) {AliFatal("Exit");exit(0);}  
     411             : 
     412          16 :   for(Int_t dettype=0;dettype<fgkNdettypes;dettype++){
     413           6 :     if(dettype==0){
     414           4 :       seg = new AliITSsegmentationSPD();
     415           2 :       SetSegmentationModel(dettype,seg);
     416           2 :       SetDigitClassName(dettype,"AliITSdigitSPD");
     417           2 :     }
     418           6 :     if(dettype==1){
     419           4 :       seg = new AliITSsegmentationSDD();
     420           2 :       if(fLoadOnlySPDCalib==kFALSE){
     421           2 :         AliITSCalibrationSDD* cal=(AliITSCalibrationSDD*)GetCalibrationModel(fgkDefaultNModulesSPD+1);
     422           2 :         if(cal->IsAMAt20MHz()){ 
     423           2 :           seg->SetPadSize(seg->Dpz(0),20.);
     424           2 :           seg->SetNPads(seg->Npz()/2,128);
     425           2 :         }
     426           2 :       }
     427           2 :       SetSegmentationModel(dettype,seg);
     428           2 :       SetDigitClassName(dettype,"AliITSdigitSDD");
     429           2 :     }
     430           6 :     if(dettype==2){
     431           2 :       AliITSsegmentationSSD* seg2 = new AliITSsegmentationSSD();
     432           2 :       SetSegmentationModel(dettype,seg2);
     433           2 :       SetDigitClassName(dettype,"AliITSdigitSSD");
     434           2 :     }
     435             :   }
     436           4 : }
     437             : //______________________________________________________________________
     438             : Bool_t AliITSDetTypeRec::GetCalibration() {
     439             :   // Get Default calibration if a storage is not defined.
     440             : 
     441           4 :   if(!fFirstcall){
     442           0 :     AliITSCalibration* cal = GetCalibrationModel(0);
     443           0 :     if(cal)return kTRUE;
     444           0 :   }else {
     445           2 :     fFirstcall = kFALSE;
     446             :   }
     447             : 
     448             :   //  SetRunNumber((Int_t)AliCDBManager::Instance()->GetRun());
     449             :   //  Int_t run=GetRunNumber();
     450             : 
     451           2 :   Bool_t cacheStatus = AliCDBManager::Instance()->GetCacheFlag();
     452           2 :   if (fCalibration==0) {
     453           6 :     fCalibration = new TObjArray(GetITSgeom()->GetIndexMax());
     454           2 :     fCalibration->SetOwner(!cacheStatus);
     455           2 :     fCalibration->Clear();
     456           2 :   }
     457             :     
     458           2 :   Bool_t retCode=GetCalibrationSPD(cacheStatus);
     459           2 :   if(retCode==kFALSE) return kFALSE;
     460             : 
     461           2 :   if(fLoadOnlySPDCalib==kFALSE){
     462           2 :     retCode=GetCalibrationSDD(cacheStatus);
     463           2 :     if(retCode==kFALSE) return kFALSE;
     464           2 :     retCode=GetCalibrationSSD(cacheStatus);
     465           2 :     if(retCode==kFALSE) return kFALSE;
     466             :   }
     467             : 
     468           2 :   AliInfo(Form("%i SPD, %i SDD and %i SSD in calibration database",
     469             :                fNMod[0], fNMod[1], fNMod[2]));
     470           2 :   return kTRUE;
     471           2 : }
     472             : //______________________________________________________________________
     473             : Bool_t AliITSDetTypeRec::GetCalibrationSPD(Bool_t cacheStatus) {
     474             :   // Get SPD calibration objects from OCDB
     475             :   // dead pixel are not used for local reconstruction
     476             : 
     477             :  
     478           4 :   AliCDBEntry *noisySPD = AliCDBManager::Instance()->Get("ITS/Calib/SPDNoisy");
     479           4 :   AliCDBEntry *deadSPD = AliCDBManager::Instance()->Get("ITS/Calib/SPDDead");
     480           4 :   AliCDBEntry *deadSparseSPD = AliCDBManager::Instance()->Get("ITS/Calib/SPDSparseDead");
     481           4 :   AliCDBEntry *pitCond = AliCDBManager::Instance()->Get("TRIGGER/SPD/PITConditions");
     482           2 :   if(!noisySPD || !deadSPD || !pitCond ){
     483           0 :     AliFatal("SPD Calibration object retrieval failed! ");
     484           0 :     return kFALSE;
     485             :   }
     486             : 
     487           2 :   TObjArray *calNoisySPD = (TObjArray*) noisySPD->GetObject();
     488           2 :   if (!cacheStatus) noisySPD->SetObject(NULL);
     489           2 :   noisySPD->SetOwner(kTRUE);
     490             :  
     491           2 :   TObjArray *calDeadSPD = (TObjArray*) deadSPD->GetObject();
     492           2 :   if (!cacheStatus) deadSPD->SetObject(NULL);
     493           2 :   deadSPD->SetOwner(kTRUE);
     494             : 
     495           2 :   TObjArray *calSparseDeadSPD = (TObjArray*) deadSparseSPD->GetObject();
     496           2 :   if (!cacheStatus) deadSparseSPD->SetObject(NULL);
     497           2 :   deadSparseSPD->SetOwner(kTRUE);
     498             : 
     499             :   
     500           2 :   AliITSTriggerConditions *calPitCond = (AliITSTriggerConditions*) pitCond->GetObject();
     501           2 :   if (!cacheStatus) pitCond->SetObject(NULL);
     502           2 :   pitCond->SetOwner(kTRUE);
     503             : 
     504           2 :   if(!cacheStatus){
     505           0 :     delete noisySPD;
     506           0 :     delete deadSPD;
     507           0 :     delete deadSparseSPD;
     508           0 :     delete pitCond;
     509             :   }
     510           2 :   if ((!calNoisySPD) || (!calDeadSPD) || (!calSparseDeadSPD) || (!calPitCond)){ 
     511           0 :     AliWarning("Can not get SPD calibration from calibration database !");
     512           0 :     return kFALSE;
     513             :   }
     514           2 :   fNMod[0] = calNoisySPD->GetEntries();
     515             : 
     516             :   AliITSCalibration* cal;
     517         964 :   for (Int_t i=0; i<fNMod[0]; i++) {
     518         480 :     cal = (AliITSCalibration*) calNoisySPD->At(i);
     519         480 :     SetCalibrationModel(i, cal);
     520         480 :     cal = (AliITSCalibration*) calDeadSPD->At(i);
     521         480 :     SetSPDDeadModel(i, cal);
     522         480 :     cal = (AliITSCalibration*) calSparseDeadSPD->At(i);
     523         480 :     SetSPDSparseDeadModel(i, cal);
     524             :   }
     525           2 :   fTriggerConditions = calPitCond;
     526             : 
     527             :   return kTRUE;
     528           2 : }
     529             : 
     530             : //______________________________________________________________________
     531             : Bool_t AliITSDetTypeRec::GetCalibrationSDD(Bool_t cacheStatus) {
     532             :   // Get SDD calibration objects from OCDB
     533             : 
     534           4 :   AliCDBEntry *entrySDD = AliCDBManager::Instance()->Get("ITS/Calib/CalibSDD");
     535           4 :   AliCDBEntry *entry2SDD = AliCDBManager::Instance()->Get("ITS/Calib/RespSDD");
     536           4 :   AliCDBEntry *drSpSDD = AliCDBManager::Instance()->Get("ITS/Calib/DriftSpeedSDD");
     537           4 :   AliCDBEntry *ddlMapSDD = AliCDBManager::Instance()->Get("ITS/Calib/DDLMapSDD");
     538             :   //   AliCDBEntry *mapASDD = AliCDBManager::Instance()->Get("ITS/Calib/MapsAnodeSDD");
     539           4 :   AliCDBEntry *mapTSDD = AliCDBManager::Instance()->Get("ITS/Calib/MapsTimeSDD");
     540             : 
     541           2 :   if(!entrySDD || !entry2SDD || !drSpSDD || !ddlMapSDD || !mapTSDD ){
     542           0 :     AliFatal("SDD Calibration object retrieval failed! ");
     543           0 :     return kFALSE;
     544             :   }     
     545             : 
     546             : 
     547             :     
     548           2 :   TObjArray *calSDD = (TObjArray *)entrySDD->GetObject();
     549           2 :   if(!cacheStatus)entrySDD->SetObject(NULL);
     550           2 :   entrySDD->SetOwner(kTRUE);
     551             :  
     552           2 :   AliITSresponseSDD *pSDD = (AliITSresponseSDD*)entry2SDD->GetObject();
     553           2 :   if(!cacheStatus)entry2SDD->SetObject(NULL);
     554           2 :   entry2SDD->SetOwner(kTRUE);
     555             : 
     556           2 :   TObjArray *drSp = (TObjArray *)drSpSDD->GetObject();
     557           2 :   if(!cacheStatus)drSpSDD->SetObject(NULL);
     558           2 :   drSpSDD->SetOwner(kTRUE);
     559             : 
     560           2 :   AliITSDDLModuleMapSDD *ddlsdd=(AliITSDDLModuleMapSDD*)ddlMapSDD->GetObject();
     561           2 :   if(!cacheStatus)ddlMapSDD->SetObject(NULL);
     562           2 :   ddlMapSDD->SetOwner(kTRUE);
     563             : 
     564             : //   TObjArray *mapAn = (TObjArray *)mapASDD->GetObject();
     565             : //   if(!cacheStatus)mapASDD->SetObject(NULL);
     566             : //   mapASDD->SetOwner(kTRUE);
     567             : 
     568           2 :   TObjArray *mapT = (TObjArray *)mapTSDD->GetObject();
     569           2 :   if(!cacheStatus)mapTSDD->SetObject(NULL);
     570           2 :   mapTSDD->SetOwner(kTRUE);
     571             : 
     572             : 
     573             :   // DB entries are deleted. In this way metadeta objects are deleted as well
     574           2 :   if(!cacheStatus){
     575           0 :     delete entrySDD;
     576           0 :     delete entry2SDD;
     577             :     //delete mapASDD;
     578           0 :     delete mapTSDD;
     579           0 :     delete drSpSDD;
     580           0 :     delete ddlMapSDD;
     581             :   }
     582             : 
     583           2 :   if ((!pSDD)||(!calSDD) || (!drSp) || (!ddlsdd) || (!mapT) ){
     584           0 :     AliWarning("Can not get SDD calibration from calibration database !");
     585           0 :     return kFALSE;
     586             :   }
     587             : 
     588           2 :   fNMod[1] = calSDD->GetEntries();
     589             : 
     590           2 :   fDDLMapSDD=ddlsdd;
     591           2 :   fRespSDD=pSDD;
     592             :   AliITSCalibration* cal;
     593             :   Float_t avegain=0.;
     594             :   Float_t nGdAnodes=0;
     595             :   Bool_t oldMapFormat=kFALSE;
     596           2 :   TObject* objmap=(TObject*)mapT->At(0);
     597           2 :   TString cname(objmap->ClassName());
     598           4 :   if(cname.CompareTo("AliITSMapSDD")==0){ 
     599             :     oldMapFormat=kTRUE;
     600           0 :     AliInfo("SDD Maps converted to new format");
     601             :   }
     602         100 :   for(Int_t iddl=0; iddl<AliITSDDLModuleMapSDD::GetNDDLs(); iddl++){
     603        1248 :     for(Int_t icar=0; icar<AliITSDDLModuleMapSDD::GetNModPerDDL();icar++){
     604         576 :       Int_t iMod=fDDLMapSDD->GetModuleNumber(iddl,icar);
     605         632 :       if(iMod==-1) continue;
     606         520 :       Int_t i=iMod - fgkDefaultNModulesSPD;
     607        1040 :       cal = (AliITSCalibration*) calSDD->At(i);
     608         520 :       Int_t i0=2*i;
     609         520 :       Int_t i1=1+2*i;
     610      533520 :       for(Int_t iAnode=0;iAnode< ((AliITSCalibrationSDD*)cal)->NOfAnodes(); iAnode++){
     611      532480 :         if(((AliITSCalibrationSDD*)cal)->IsBadChannel(iAnode)) continue;
     612      262280 :         avegain+= ((AliITSCalibrationSDD*)cal)->GetChannelGain(iAnode);
     613      262280 :         nGdAnodes++;
     614      262280 :       }
     615        1040 :       AliITSDriftSpeedArraySDD* arr0 = (AliITSDriftSpeedArraySDD*) drSp->At(i0);
     616        1040 :       AliITSDriftSpeedArraySDD* arr1 = (AliITSDriftSpeedArraySDD*) drSp->At(i1);
     617             : 
     618             :       AliITSCorrMapSDD* mt0 = 0;
     619             :       AliITSCorrMapSDD* mt1 = 0;
     620         520 :       if(oldMapFormat){ 
     621           0 :         AliITSMapSDD* oldmap0=(AliITSMapSDD*)mapT->At(i0);
     622           0 :         AliITSMapSDD* oldmap1=(AliITSMapSDD*)mapT->At(i1);
     623           0 :         mt0=oldmap0->ConvertToNewFormat();
     624           0 :         mt1=oldmap1->ConvertToNewFormat();
     625           0 :       }else{
     626        1040 :         mt0=(AliITSCorrMapSDD*)mapT->At(i0);
     627        1040 :         mt1=(AliITSCorrMapSDD*)mapT->At(i1);
     628             :       }
     629         520 :       cal->SetDriftSpeed(0,arr0);
     630         520 :       cal->SetDriftSpeed(1,arr1);
     631         520 :       cal->SetMapT(0,mt0);
     632         520 :       cal->SetMapT(1,mt1);
     633         520 :       SetCalibrationModel(iMod, cal);
     634         520 :     }
     635             :   }
     636           4 :   if(nGdAnodes) fAveGainSDD=avegain/nGdAnodes;
     637             :   return kTRUE;
     638           4 : }
     639             : 
     640             : 
     641             : //______________________________________________________________________
     642             : Bool_t AliITSDetTypeRec::GetCalibrationSSD(Bool_t cacheStatus) {
     643             :   // Get SSD calibration objects from OCDB
     644             :   //  AliCDBEntry *entrySSD = AliCDBManager::Instance()->Get("ITS/Calib/CalibSSD");
     645             : 
     646           4 :   AliCDBEntry *entryNoiseSSD = AliCDBManager::Instance()->Get("ITS/Calib/NoiseSSD");
     647           4 :   AliCDBEntry *entryGainSSD = AliCDBManager::Instance()->Get("ITS/Calib/GainSSD");
     648           4 :   AliCDBEntry *entryBadChannelsSSD = AliCDBManager::Instance()->Get("ITS/Calib/BadChannelsSSD");
     649             : 
     650           2 :   if(!entryNoiseSSD || !entryGainSSD || !entryBadChannelsSSD){
     651           0 :     AliFatal("SSD Calibration object retrieval failed! ");
     652           0 :     return kFALSE;
     653             :   }     
     654             : 
     655           2 :   TObject *emptyssd = 0; TString ssdobjectname;
     656             :   AliITSNoiseSSDv2 *noiseSSD = NULL; 
     657           2 :   emptyssd = (TObject *)entryNoiseSSD->GetObject();
     658           4 :   ssdobjectname = emptyssd->GetName();
     659           4 :   if(ssdobjectname=="TObjArray") {
     660           0 :     TObjArray *noiseSSDOld = (TObjArray *)entryNoiseSSD->GetObject();
     661           0 :     noiseSSD = new AliITSNoiseSSDv2(); 
     662           0 :     ReadOldSSDNoise(noiseSSDOld, noiseSSD);
     663           0 :   }
     664           4 :   else if(ssdobjectname=="AliITSNoiseSSDv2")
     665           2 :     noiseSSD = (AliITSNoiseSSDv2 *)entryNoiseSSD->GetObject();
     666           2 :   if(!cacheStatus)entryNoiseSSD->SetObject(NULL);
     667           2 :   entryNoiseSSD->SetOwner(kTRUE);
     668             : 
     669             :   AliITSGainSSDv2 *gainSSD = NULL;;
     670           2 :   emptyssd = (TObject *)entryGainSSD->GetObject();
     671           4 :   ssdobjectname = emptyssd->GetName();
     672           4 :   if(ssdobjectname=="Gain") {
     673           0 :     TObjArray *gainSSDOld = (TObjArray *)entryGainSSD->GetObject();
     674           0 :     gainSSD = new AliITSGainSSDv2();
     675           0 :     ReadOldSSDGain(gainSSDOld, gainSSD);
     676           0 :   }
     677           4 :   else if(ssdobjectname=="AliITSGainSSDv2")
     678           2 :     gainSSD = (AliITSGainSSDv2 *)entryGainSSD->GetObject();
     679           2 :   if(!cacheStatus)entryGainSSD->SetObject(NULL);
     680           2 :   entryGainSSD->SetOwner(kTRUE);
     681             : 
     682             :   AliITSBadChannelsSSDv2 *badChannelsSSD = NULL;
     683           2 :   emptyssd = (TObject *)entryBadChannelsSSD->GetObject();
     684           4 :   ssdobjectname = emptyssd->GetName();
     685           4 :   if(ssdobjectname=="TObjArray") {
     686           0 :     TObjArray *badChannelsSSDOld = (TObjArray *)entryBadChannelsSSD->GetObject();
     687           0 :     badChannelsSSD = new AliITSBadChannelsSSDv2();
     688           0 :     ReadOldSSDBadChannels(badChannelsSSDOld, badChannelsSSD);
     689           0 :   }
     690           4 :   else if(ssdobjectname=="AliITSBadChannelsSSDv2")
     691           2 :     badChannelsSSD = (AliITSBadChannelsSSDv2*)entryBadChannelsSSD->GetObject();
     692           2 :   if(!cacheStatus)entryBadChannelsSSD->SetObject(NULL);
     693           2 :   entryBadChannelsSSD->SetOwner(kTRUE);
     694             : 
     695             :   // DB entries are deleted. In this way metadeta objects are deleted as well
     696           2 :   if(!cacheStatus){
     697           0 :     delete entryNoiseSSD;
     698           0 :     delete entryGainSSD;
     699           0 :     delete entryBadChannelsSSD;
     700             :   }
     701             : 
     702           2 :   if ((!noiseSSD)|| (!gainSSD)|| (!badChannelsSSD)) {
     703           0 :     AliWarning("Can not get SSD calibration from calibration database !");
     704           0 :     return kFALSE;
     705             :   }
     706             : 
     707           2 :   fSSDCalibration->SetNoise(noiseSSD);
     708           2 :   fSSDCalibration->SetGain(gainSSD);
     709           2 :   fSSDCalibration->SetBadChannels(badChannelsSSD);
     710             :   //fSSDCalibration->FillBadChipMap();
     711             : 
     712           2 :   return kTRUE;
     713           4 : }
     714             : 
     715             : //________________________________________________________________
     716             : void AliITSDetTypeRec::SetDefaultClusterFindersV2(Bool_t rawdata, Bool_t fastSDD){
     717             : 
     718             :   //Set defaults for cluster finder V2
     719             : 
     720           8 :   if(!GetITSgeom()){
     721           0 :     Warning("SetDefaults","Null pointer to AliITSgeom !");
     722           0 :     return;
     723             :   }
     724             : 
     725             :   AliITSClusterFinder *clf; 
     726             : 
     727          64 :   for(Int_t dettype=0;dettype<fgkNdettypes;dettype++){
     728             :     //SPD
     729          24 :     if(dettype==0){
     730           8 :       if(!GetReconstructionModel(dettype)){
     731           4 :         clf = new AliITSClusterFinderV2SPD(this);
     732           2 :         clf->InitGeometry();
     733           3 :         if(!rawdata) clf->SetDigits(DigitsAddress(0));
     734           2 :         SetReconstructionModel(dettype,clf);
     735             : 
     736           2 :       }
     737             :     }
     738             :     //SDD
     739          24 :     if(dettype==1){
     740           8 :       if(!GetReconstructionModel(dettype)){
     741           2 :         if(fastSDD){
     742           4 :           clf = new AliITSClusterFinderSDDfast(this);
     743           2 :         }
     744             :         else {
     745           0 :           clf = new AliITSClusterFinderV2SDD(this);
     746             :         }
     747           2 :         clf->InitGeometry();
     748           3 :         if(!rawdata) clf->SetDigits(DigitsAddress(1));
     749           2 :         SetReconstructionModel(dettype,clf);
     750           2 :       }
     751             : 
     752             :     }
     753             : 
     754             :     //SSD
     755          24 :     if(dettype==2){
     756           8 :       if(!GetReconstructionModel(dettype)){
     757           4 :         clf = new AliITSClusterFinderV2SSD(this);
     758           2 :         clf->InitGeometry();
     759           3 :         if(!rawdata) clf->SetDigits(DigitsAddress(2));
     760           2 :         SetReconstructionModel(dettype,clf);
     761           2 :       }
     762             :     }
     763             : 
     764             :  }
     765             :    
     766          16 : }
     767             : //______________________________________________________________________
     768             : void AliITSDetTypeRec::MakeBranch(TTree* tree, Option_t* option){
     769             : 
     770             :   //Creates branches for clusters and recpoints
     771           8 :   Bool_t cR = (strstr(option,"R")!=0);
     772           4 :   Bool_t cRF = (strstr(option,"RF")!=0);
     773             :   
     774           4 :   if(cRF)cR = kFALSE;
     775             : 
     776           8 :   if(cR) MakeBranchR(tree);
     777           4 :   if(cRF) MakeBranchRF(tree);
     778             : 
     779           4 : }
     780             : 
     781             : //___________________________________________________________________
     782             : void AliITSDetTypeRec::ResetDigits(){
     783             :   // Reset number of digits and the digits array for the ITS detector.
     784             :   
     785       17592 :   if(!fDigits) return;
     786       70368 :   for(Int_t i=0;i<fgkNdettypes;i++){
     787       26388 :     ResetDigits(i);
     788             :   }
     789        8796 : }
     790             : //___________________________________________________________________
     791             : void AliITSDetTypeRec::ResetDigits(Int_t branch){
     792             :   // Reset number of digits and the digits array for this branch.
     793             :   
     794       79161 :   if(fDigits->At(branch)) ((TClonesArray*)fDigits->At(branch))->Clear();
     795             : 
     796       26388 : }
     797             : //__________________________________________________________________
     798             : void AliITSDetTypeRec::MakeBranchR(TTree *treeR, Option_t *opt){
     799             : 
     800             :   //Creates tree branches for recpoints
     801             :   // Inputs:
     802             :   //      cont char *file  File name where RecPoints branch is to be written
     803             :   //                       to. If blank it write the SDigits to the same
     804             :   //                       file in which the Hits were found.
     805             : 
     806             :   Int_t buffsz = 4000;
     807           8 :   char branchname[30];
     808             : 
     809             :   // only one branch for rec points for all detector types
     810           4 :   Bool_t oFast= (strstr(opt,"Fast")!=0);
     811             :   
     812           4 :   Char_t detname[10] = "ITS";
     813             :  
     814             :   
     815           8 :   if(oFast){
     816           4 :     snprintf(branchname,29,"%sRecPointsF",detname);
     817           0 :   } else {
     818           4 :     snprintf(branchname,29,"%sRecPoints",detname);
     819             :   }
     820             :   
     821           6 :   if(!fRecPoints)fRecPoints = new TClonesArray("AliITSRecPoint",1000);
     822           4 :   if (treeR)
     823           4 :     MakeBranchInTree(treeR,branchname,0,&fRecPoints,buffsz,99);
     824           4 : }
     825             : //______________________________________________________________________
     826             : void AliITSDetTypeRec::SetTreeAddressR(TTree* const treeR){
     827             :     // Set branch address for the Reconstructed points Trees.
     828             :     // Inputs:
     829             :     //      TTree *treeR   Tree containing the RecPoints.
     830             :     // Outputs:
     831             :     //      none.
     832             :     // Return:
     833             : 
     834           8 :    char branchname[30];
     835           4 :    Char_t namedet[10]="ITS";
     836             : 
     837           4 :    if(!treeR) return;
     838           4 :    if(fRecPoints==0x0) fRecPoints = new TClonesArray("AliITSRecPoint",1000);
     839             :    TBranch *branch;
     840           4 :    snprintf(branchname,29,"%sRecPoints",namedet);
     841           4 :    branch = treeR->GetBranch(branchname);
     842           4 :    if (branch) {
     843           4 :       branch->SetAddress(&fRecPoints);
     844           4 :     } 
     845             :     else {
     846           0 :       snprintf(branchname,29,"%sRecPointsF",namedet);
     847           0 :       branch = treeR->GetBranch(branchname);
     848           0 :       if (branch) {
     849           0 :         branch->SetAddress(&fRecPoints);
     850           0 :       }
     851             :    }
     852           8 : }
     853             : //____________________________________________________________________
     854             : void AliITSDetTypeRec::AddRecPoint(const AliITSRecPoint &r){
     855             :     // Add a reconstructed space point to the list
     856             :     // Inputs:
     857             :     //      const AliITSRecPoint &r RecPoint class to be added to the tree
     858             :     //                              of reconstructed points TreeR.
     859             :     // Outputs:
     860             :     //      none.
     861             :     // Return:
     862             :     //      none.
     863         666 :     TClonesArray &lrecp = *fRecPoints;
     864         333 :     new(lrecp[fNRecPoints++]) AliITSRecPoint(r);
     865         333 : }
     866             : 
     867             : //______________________________________________________________________
     868             : void AliITSDetTypeRec::DigitsToRecPoints(TTree *treeD,TTree *treeR,Int_t lastentry,Option_t *opt, Int_t optCluFind){
     869             :   // cluster finding and reconstruction of space points
     870             :   // the condition below will disappear when the geom class will be
     871             :   // initialized for all versions - for the moment it is only for v5 !
     872             :   // 7 is the SDD beam test version
     873             :   // Inputs:
     874             :   //      TTree *treeD     Digits tree
     875             :   //      TTree *treeR     Clusters tree
     876             :   //      Int_t lastentry  Offset for module when not all of the modules
     877             :   //                       are processed.
     878             :   //      Option_t *opt    String indicating which ITS sub-detectors should
     879             :   //                       be processed. If ="All" then all of the ITS
     880             :   //                       sub detectors are processed.
     881             : 
     882           8 :   Bool_t all = strstr(opt,"All")!=0;
     883          16 :   Bool_t det[3] = {all||(strstr(opt,"SPD")!=0),all||(strstr(opt,"SDD")!=0),all||(strstr(opt,"SSD")!=0)};
     884           8 :   if(optCluFind==0){
     885           4 :     SetDefaultClusterFindersV2();
     886           0 :     AliDebug(1,"V2 cluster finder has been selected \n");
     887             :   }else{
     888           4 :     SetDefaultClusterFindersV2(kFALSE,kTRUE);
     889          12 :     AliDebug(1,"SPD and SSD V2 Cluster Finder - SDD fast Cluster Finder \n");    
     890             :   }
     891             : 
     892           4 :   const AliITSRecoParam* recoparam = AliITSReconstructor::GetRecoParam();
     893           4 :   recoparam->PrintFastOrRecoParam(); 
     894             :   // Reset Fast-OR fired map
     895           4 :   ResetFastOrFiredMap();
     896             : 
     897           4 :   if (det[0]) { // SPD present
     898             :     // Get the FO signals for this event
     899           4 :     AliRunLoader* runLoader = AliRunLoader::Instance();
     900           4 :     AliITSLoader* itsLoader = (AliITSLoader*) runLoader->GetLoader("ITSLoader");
     901           4 :     if (!itsLoader) {
     902           0 :       AliError("ITS loader is NULL.");
     903           0 :     }
     904             :    else {
     905           4 :       fFOSignals = (AliITSFOSignalsSPD*)itsLoader->TreeD()->GetUserInfo()->FindObject("AliITSFOSignalsSPD");
     906           4 :       if(!fFOSignals) AliError("FO signals not retrieved");
     907             :      }
     908             : 
     909           4 :   }
     910             :   
     911             :   AliITSClusterFinder *rec     = 0;
     912             :   Int_t id,module,first=0, nSPD=0;
     913           4 :   Bool_t firstCall[3] = {kTRUE,kTRUE,kTRUE};
     914       17592 :   for(module=0;module<GetITSgeom()->GetIndexMax();module++) {
     915        8792 :     id = GetITSgeom()->GetModuleType(module);
     916        8792 :     if (!det[id]) continue;
     917             :     //if(det[id]) first = GetITSgeom()->GetStartDet(id); // RS the entry<->module is fixed, don't play with it
     918        8792 :     rec = (AliITSClusterFinder*)GetReconstructionModel(id);
     919        8792 :     if (firstCall[id]) { // reset clusters counter in the clusterizer
     920          12 :       rec->ResetNClusters();
     921          12 :       firstCall[id] = kFALSE;
     922          12 :     }
     923        8792 :     TClonesArray *itsDigits  = DigitsAddress(id);
     924        8792 :     if (!rec){
     925           0 :       AliFatal("The reconstruction class was not instanciated!");
     926           0 :       return;
     927             :     }
     928        8792 :     ResetDigits();  // MvL: Not sure we need this when rereading anyways
     929             :     /* 
     930             :     // RS: This is wrong, if all 3 dets are mentioned in the opt, entry 0 will be read 3 times for 3 det types
     931             :     if (all) {
     932             :       treeD->GetEvent(lastentry+module);
     933             :     }
     934             :     else {
     935             :       treeD->GetEvent(lastentry+(module-first));
     936             :     }
     937             :     */
     938        8792 :     treeD->GetEvent(lastentry+module);
     939             :     //  
     940        8792 :     Int_t ndigits = itsDigits->GetEntriesFast();
     941        8792 :     if (ndigits>0 || id==0) { // for SPD we always want to call FindRawClusters (to process FO signals)
     942        6582 :       rec->SetDetTypeRec(this);
     943        6582 :       rec->SetDigits(DigitsAddress(id));
     944             :       //        rec->SetClusters(ClustersAddress(id));
     945        6582 :       rec->FindRawClusters(module);
     946        6582 :       if (rec->GetNClusters()>recoparam->GetMaxSPDClforSPDOnly() && (det[1]||det[2])) {
     947           0 :         AliInfoF("NSPDclusters %d > threshold %d, skipping SDD,SSD clusterization",
     948             :                 rec->GetNClusters(), recoparam->GetMaxSPDClforSPDOnly());
     949           0 :         det[1]=det[2]=kFALSE;
     950           0 :       }
     951             :     } // end if
     952        8792 :     treeR->Fill();
     953        8792 :     ResetRecPoints();
     954        8792 :   }
     955             :   
     956             :    // Remove PIT in-active chips from Fast-OR fired map
     957           4 :   if (all || det[0]) { // SPD present
     958           4 :     RemoveFastOrFiredInActive();
     959             :     // here removing bits which have no associated clusters 
     960          12 :    if(recoparam->GetRemoveFastOrFromDeadMC()) RemoveFastOrFiredFromDead(GetFiredChipMap(treeR));  
     961             :   }
     962             : 
     963           4 :   AliITSRecPointContainer* rpcont = AliITSRecPointContainer::Instance();
     964           4 :   Int_t nClu[6];
     965           4 :   nClu[0]=rpcont->GetNClustersInLayer(1,treeR);
     966          48 :   for(Int_t iLay=2; iLay<=6; iLay++) nClu[iLay-1]=rpcont->GetNClustersInLayerFast(iLay);
     967           4 :   AliInfo(Form("Number of RecPoints in ITS Layers = %d %d %d %d %d %d",
     968             :                nClu[0],nClu[1],nClu[2],nClu[3],nClu[4],nClu[5]));
     969           8 : }
     970             : //______________________________________________________________________
     971             : void AliITSDetTypeRec::DigitsToRecPoints(AliRawReader* rawReader,TTree *treeR,Option_t *opt){
     972             :   // cluster finding and reconstruction of space points
     973             :   // the condition below will disappear when the geom class will be
     974             :   // initialized for all versions - for the moment it is only for v5 !
     975             :   // 7 is the SDD beam test version
     976             :   // Inputs:
     977             :   //      AliRawReader *rawReader  Pointer to the raw-data reader
     978             :   //      TTree *treeR             Clusters tree
     979             :   // Outputs:
     980             :   //      none.
     981             :   // Return:
     982             :   //      none.
     983           8 :   Bool_t all = strstr(opt,"All")!=0;
     984          16 :   Bool_t det[3] = {all||(strstr(opt,"SPD")!=0),all||(strstr(opt,"SDD")!=0),all||(strstr(opt,"SSD")!=0)};
     985             :   
     986             :   Int_t id=0;
     987           4 :   AliITSRecPointContainer* rpc = AliITSRecPointContainer::Instance();
     988           4 :   rpc->FullReset();
     989           4 :   TClonesArray* array = rpc->UncheckedGetClusters(0);
     990           4 :   TBranch *branch = treeR->Branch("ITSRecPoints",&array);
     991           4 :   DigitsToRecPoints(rawReader,opt); 
     992             :   Int_t nClusters =0 ;
     993       17592 :   for(Int_t iModule=0;iModule<GetITSgeom()->GetIndexMax();iModule++){
     994        8792 :     id = GetITSgeom()->GetModuleType(iModule);
     995        8792 :     if (!det[id]) continue;
     996        8792 :     array = rpc->UncheckedGetClusters(iModule);
     997        8792 :     if(!array){
     998           0 :       AliDebug(1,Form("data for module %d missing!",iModule));
     999             :     }
    1000        8792 :     branch->SetAddress(&array);
    1001        8792 :     treeR->Fill();
    1002        8792 :     nClusters+=array->GetEntriesFast();
    1003        8792 :   }
    1004             : 
    1005           4 :   rpc->FullReset();
    1006             : 
    1007           4 :   AliITSRecPointContainer* rpcont = AliITSRecPointContainer::Instance();
    1008           4 :   Int_t nClu[6];
    1009           4 :   nClu[0]=rpcont->GetNClustersInLayer(1,treeR);
    1010          48 :   for(Int_t iLay=2; iLay<=6; iLay++) nClu[iLay-1]=rpcont->GetNClustersInLayerFast(iLay);
    1011           4 :   AliInfo(Form("Number of RecPoints in ITS Layers = %d %d %d %d %d %d, Total = %d",
    1012             :                nClu[0],nClu[1],nClu[2],nClu[3],nClu[4],nClu[5],nClusters));
    1013           4 : }
    1014             : //______________________________________________________________________
    1015             : void AliITSDetTypeRec::DigitsToRecPoints(AliRawReader* rawReader,Option_t *opt){
    1016             :   // cluster finding and reconstruction of space points
    1017             :   // the condition below will disappear when the geom class will be
    1018             :   // initialized for all versions - for the moment it is only for v5 !
    1019             :   // 7 is the SDD beam test version
    1020             :   // Inputs:
    1021             :   //      AliRawReader *rawReader  Pointer to the raw-data reader
    1022             :   // Outputs:
    1023             :   //      none.
    1024             :   // Return:
    1025             :   //      none.
    1026           8 :   Bool_t all = strstr(opt,"All");
    1027          16 :   Bool_t det[3] = {all||(strstr(opt,"SPD")!=0),all||(strstr(opt,"SDD")!=0),all||(strstr(opt,"SSD")!=0)};
    1028             :   
    1029             :   // Reset Fast-OR fired map
    1030           4 :   ResetFastOrFiredMap();
    1031             :   
    1032             :   AliITSClusterFinder *rec     = 0;
    1033             :   Int_t id=0;
    1034           4 :   const AliITSRecoParam* recoparam = AliITSReconstructor::GetRecoParam();
    1035           4 :   recoparam->PrintFastOrRecoParam();
    1036             :  
    1037          32 :   for(id=0;id<3;id++){
    1038          12 :     if (!all && !det[id]) continue;
    1039          12 :     rec = (AliITSClusterFinder*)GetReconstructionModel(id);
    1040          12 :     if (!rec){
    1041           0 :       AliFatal("The reconstruction class was not instantiated");
    1042           0 :       return;
    1043             :     }
    1044          12 :     rec->SetDetTypeRec(this);
    1045          12 :     rec->RawdataToClusters(rawReader);  
    1046             :     // skip outer layers if NSPD > threshold
    1047          16 :     if (id==0 && rec->GetNClusters()>recoparam->GetMaxSPDClforSPDOnly()) {
    1048           0 :       AliInfoF("NSPDclusters %d > threshold %d, skipping SDD,SSD clusterization",
    1049             :                rec->GetNClusters(), recoparam->GetMaxSPDClforSPDOnly());
    1050           0 :       break;
    1051             :     }
    1052             :  } 
    1053             :    
    1054             :   // Remove PIT in-active chips from Fast-OR fired map
    1055           4 :   if (all || det[0]) { // SPD present
    1056           4 :     RemoveFastOrFiredInActive();
    1057             :     // here removing bits which have no associated clusters 
    1058           4 :     if(recoparam->GetRemoveFastOrFromDeadRaw()) RemoveFastOrFiredFromDead(GetFiredChipMap());
    1059             :    
    1060             :   }  
    1061           8 : }
    1062             : //______________________________________________________________________
    1063             : void AliITSDetTypeRec::ReadOldSSDNoise(const TObjArray *array, 
    1064             :                                        AliITSNoiseSSDv2 *noiseSSD) {
    1065             :   //Reads the old SSD calibration object and converts it to the new format
    1066             :   const Int_t fgkSSDSTRIPSPERMODULE = 1536;
    1067             :   const Int_t fgkSSDPSIDESTRIPSPERMODULE = 768;
    1068             : 
    1069           0 :   Int_t gNMod = array->GetEntries();
    1070           0 :   AliInfo("Converting old calibration object for noise...\n");
    1071             : 
    1072             :   //NOISE
    1073             :   Double_t noise = 0.0;
    1074           0 :   for (Int_t iModule = 0; iModule < gNMod; iModule++) {
    1075           0 :     AliITSNoiseSSD *noiseModule = (AliITSNoiseSSD*) (array->At(iModule));
    1076           0 :     for(Int_t iStrip = 0; iStrip < fgkSSDSTRIPSPERMODULE; iStrip++) {
    1077           0 :       noise = (iStrip < fgkSSDPSIDESTRIPSPERMODULE) ? noiseModule->GetNoiseP(iStrip) : noiseModule->GetNoiseN(1535 - iStrip);
    1078           0 :       if(iStrip < fgkSSDPSIDESTRIPSPERMODULE)
    1079           0 :         noiseSSD->AddNoiseP(iModule,iStrip,noise);
    1080           0 :       if(iStrip >= fgkSSDPSIDESTRIPSPERMODULE)
    1081           0 :         noiseSSD->AddNoiseN(iModule,1535 - iStrip,noise);
    1082             :     }//loop over strips
    1083             :   }//loop over modules      
    1084           0 : }
    1085             : 
    1086             : //______________________________________________________________________
    1087             : void AliITSDetTypeRec::ReadOldSSDBadChannels(const TObjArray *array, 
    1088             :                                              AliITSBadChannelsSSDv2 *badChannelsSSD) {
    1089             :   //Reads the old SSD calibration object and converts it to the new format
    1090           0 :   Int_t gNMod = array->GetEntries();
    1091           0 :   AliInfo("Converting old calibration object for bad channels...");
    1092           0 :   for (Int_t iModule = 0; iModule < gNMod; iModule++) {
    1093             :     //for (Int_t iModule = 0; iModule < 1; iModule++) {
    1094           0 :     AliITSBadChannelsSSD *bad = (AliITSBadChannelsSSD*) (array->At(iModule));
    1095           0 :     TArrayI arrayPSide = bad->GetBadPChannelsList();
    1096           0 :     for(Int_t iPCounter = 0; iPCounter < arrayPSide.GetSize(); iPCounter++) 
    1097           0 :       badChannelsSSD->AddBadChannelP(iModule,
    1098             :                                      iPCounter,
    1099           0 :                                      (Char_t)arrayPSide.At(iPCounter));
    1100             :         
    1101           0 :     TArrayI arrayNSide = bad->GetBadNChannelsList();
    1102           0 :     for(Int_t iNCounter = 0; iNCounter < arrayNSide.GetSize(); iNCounter++) 
    1103           0 :       badChannelsSSD->AddBadChannelN(iModule,
    1104             :                                      iNCounter,
    1105           0 :                                      (Char_t)arrayNSide.At(iNCounter));
    1106             :     
    1107           0 :   }//loop over modules      
    1108           0 : }
    1109             : 
    1110             : //______________________________________________________________________
    1111             : void AliITSDetTypeRec::ReadOldSSDGain(const TObjArray *array, 
    1112             :                                       AliITSGainSSDv2 *gainSSD) {
    1113             :   //Reads the old SSD calibration object and converts it to the new format
    1114             : 
    1115           0 :   Int_t gNMod = array->GetEntries();
    1116           0 :   AliInfo("Converting old calibration object for gain...\n");
    1117             : 
    1118             :   //GAIN
    1119           0 :   for (Int_t iModule = 0; iModule < gNMod; iModule++) {
    1120           0 :     AliITSGainSSD *gainModule = (AliITSGainSSD*) (array->At(iModule));
    1121           0 :     TArrayF arrayPSide = gainModule->GetGainP();
    1122           0 :     for(Int_t iPCounter = 0; iPCounter < arrayPSide.GetSize(); iPCounter++)
    1123           0 :       gainSSD->AddGainP(iModule,
    1124             :                         iPCounter,
    1125           0 :                         arrayPSide.At(iPCounter));
    1126           0 :     TArrayF arrayNSide = gainModule->GetGainN();
    1127           0 :     for(Int_t iNCounter = 0; iNCounter < arrayNSide.GetSize(); iNCounter++)
    1128           0 :       gainSSD->AddGainN(iModule,
    1129             :                         iNCounter,
    1130           0 :                         arrayNSide.At(iNCounter));
    1131           0 :   }//loop over modules 
    1132           0 : }
    1133             : //______________________________________________________________________
    1134             : void AliITSDetTypeRec::RemoveFastOrFiredInActive() {
    1135             :   // Removes the chips that were in-active in the pixel trigger (from fast-or fired map)
    1136             : 
    1137          16 :   if (fTriggerConditions==NULL) {
    1138           0 :     AliError("Pixel trigger conditions are missing.");
    1139           0 :     return;
    1140             :   }
    1141           8 :   Int_t eq   = -1;
    1142           8 :   Int_t hs   = -1;
    1143           8 :   Int_t chip = -1;
    1144        2400 :   while (fTriggerConditions->GetNextInActiveChip(eq,hs,chip)) {
    1145        1192 :     UInt_t chipKey = AliITSRawStreamSPD::GetOfflineChipKeyFromOnline(eq,hs,chip);
    1146        1192 :     fFastOrFiredMap.SetBitNumber(chipKey,kFALSE);
    1147             :   }
    1148          16 : }
    1149             : //______________________________________________________________________
    1150             : TBits AliITSDetTypeRec::GetFiredChipMap() const {
    1151             :   
    1152             :   //
    1153             :   // TBits of the fired chips  
    1154             :   //
    1155             :  
    1156           0 :   AliITSRecPointContainer* rpc = AliITSRecPointContainer::Instance();
    1157             : 
    1158           0 :   TBits isfiredchip(1200);
    1159             :   
    1160           0 :    AliITSsegmentationSPD *segSPD = (AliITSsegmentationSPD*)GetSegmentationModel(0);
    1161           0 :    if(!segSPD) {
    1162           0 :     AliError("no segmentation model for SPD available, the fired chip map is empty. Exiting"); 
    1163           0 :     return isfiredchip;
    1164             :    }
    1165             :    
    1166             :   
    1167           0 :   for(Int_t imod =0; imod < fgkDefaultNModulesSPD; imod++){
    1168           0 :     TClonesArray *array = rpc->UncheckedGetClusters(imod);
    1169           0 :     if(!array) continue;
    1170           0 :     Int_t nCluster = array->GetEntriesFast();
    1171             :  
    1172           0 :     while(nCluster--) {
    1173           0 :       AliITSRecPoint* cluster = (AliITSRecPoint*)array->UncheckedAt(nCluster);
    1174           0 :      if (cluster->GetLayer()>1)continue;
    1175             :      Float_t local[3]={-1,-1};
    1176           0 :      local[1]=cluster->GetDetLocalX();
    1177           0 :      local[0]=cluster->GetDetLocalZ();
    1178             :      
    1179           0 :      Int_t eq = AliITSRawStreamSPD::GetOnlineEqIdFromOffline(imod);
    1180           0 :      Int_t hs = AliITSRawStreamSPD::GetOnlineHSFromOffline(imod);
    1181           0 :      Int_t row, col;
    1182           0 :      segSPD->LocalToDet(0.5,local[0],row,col);
    1183           0 :      Int_t chip = AliITSRawStreamSPD::GetOnlineChipFromOffline(imod,col);
    1184           0 :      Int_t chipkey = AliITSRawStreamSPD::GetOfflineChipKeyFromOnline(eq,hs,chip);
    1185           0 :      isfiredchip.SetBitNumber(chipkey,kTRUE);
    1186           0 :     }
    1187             :     
    1188           0 :   } 
    1189             :  
    1190           0 :   return isfiredchip;
    1191             :   
    1192           0 : }
    1193             : //______________________________________________________________________
    1194             : TBits AliITSDetTypeRec::GetFiredChipMap(TTree *treeR) const{
    1195             :   //
    1196             :   // TBits of the fired chips  
    1197             :   //
    1198          24 :   TBits isfiredchip(1200);
    1199             :   
    1200          12 :   if(!treeR) {
    1201           0 :      AliError("no treeR. fired chip map stays empty. Exiting.");
    1202           0 :      return isfiredchip;
    1203             :    }
    1204             :    
    1205          12 :   AliITSRecPointContainer* rpcont=AliITSRecPointContainer::Instance();
    1206             :   TClonesArray *recpoints = NULL;
    1207          12 :   rpcont->FetchClusters(0,treeR);
    1208          36 :   if(!rpcont->GetStatusOK() || !rpcont->IsSPDActive()){
    1209           0 :     AliError("no clusters. fired chip map stays empty. Exiting.");
    1210           0 :      return isfiredchip;
    1211             :   }
    1212             :   
    1213          24 :    AliITSsegmentationSPD *segSPD = (AliITSsegmentationSPD*)GetSegmentationModel(0);
    1214             :       
    1215        5784 :    for(Int_t imod =0; imod < fgkDefaultNModulesSPD; imod++){
    1216        2880 :     recpoints = rpcont->UncheckedGetClusters(imod);
    1217        2880 :     Int_t nCluster = recpoints->GetEntriesFast();
    1218             :     
    1219             :     // loop over clusters
    1220        5979 :     while(nCluster--) {
    1221         219 :       AliITSRecPoint* cluster = (AliITSRecPoint*)recpoints->UncheckedAt(nCluster);
    1222         219 :       if (cluster->GetLayer()>1)continue;
    1223             :       Float_t local[3]={-1,-1};
    1224         219 :       local[1]=cluster->GetDetLocalX();
    1225         219 :       local[0]=cluster->GetDetLocalZ();
    1226             :       
    1227         219 :       Int_t eq = AliITSRawStreamSPD::GetOnlineEqIdFromOffline(imod);
    1228         219 :       Int_t hs = AliITSRawStreamSPD::GetOnlineHSFromOffline(imod);
    1229         219 :       Int_t row, col;
    1230         219 :       segSPD->LocalToDet(0.5,local[0],row,col);
    1231         219 :       Int_t chip = AliITSRawStreamSPD::GetOnlineChipFromOffline(imod,col);
    1232         219 :       Int_t chipkey = AliITSRawStreamSPD::GetOfflineChipKeyFromOnline(eq,hs,chip);
    1233         219 :       isfiredchip.SetBitNumber(chipkey,kTRUE);
    1234         219 :     }
    1235             :   }
    1236             :  
    1237             :   return isfiredchip;
    1238          24 : }
    1239             : //______________________________________________________________________
    1240             : void  AliITSDetTypeRec::RemoveFastOrFiredFromDead(TBits firedchipmap){
    1241             :   //
    1242             :   // resetting of the fast-or bit on cluster basis. 
    1243             :   // fast-or bits can be remnant from SPD ideal simulation (no dead channels)
    1244             :   //
    1245             :   
    1246        9612 :   for(Int_t chipKey=0; chipKey<1200; chipKey++){
    1247             :     // FO masked chips have been previously removed  
    1248        4800 :    if(!fFastOrFiredMap.TestBitNumber(chipKey)) continue; 
    1249          69 :    if(!firedchipmap.TestBitNumber(chipKey))  {
    1250           0 :     fFastOrFiredMap.SetBitNumber(chipKey,kFALSE);
    1251           0 :     AliDebug(2,Form("removing bit in key %i \n ",chipKey));
    1252             :   }
    1253             :  }
    1254             :    
    1255           4 : }
    1256             : //______________________________________________________________________
    1257             : void AliITSDetTypeRec::SetFastOrFiredMapOnline(UInt_t eq, UInt_t hs, UInt_t chip) {
    1258             :   // Set fast-or fired map for this chip
    1259         296 :   Int_t chipKey = AliITSRawStreamSPD::GetOfflineChipKeyFromOnline(eq,hs,chip);
    1260         148 :   return SetFastOrFiredMap(chipKey);
    1261         148 : }
    1262             : 

Generated by: LCOV version 1.11