ROOT logo
#ifndef ALIITSPLANEEFFSPD_H
#define ALIITSPLANEEFFSPD_H
/* Copyright(c) 2007-2009, ALICE Experiment at CERN, All rights reserved. *
 * See cxx source for full Copyright notice                               */

#include <TH1F.h>
#include <TH2I.h>
#include <TProfile.h>
#include "AliITSPlaneEff.h"

class AliCDBId;

///////////////////////////////////////////
//                                       //
// ITS Plane Efficiency class            //
//       for SPD                         //
// Origin: Giuseppe.Bruno@ba.infn.it     //
///////////////////////////////////////////

/* $Id$ */
  
class AliITSPlaneEffSPD :  public AliITSPlaneEff {
 public:
    AliITSPlaneEffSPD(); // default constructor
    virtual ~AliITSPlaneEffSPD(); // destructror
    // copy constructor
    AliITSPlaneEffSPD(const AliITSPlaneEffSPD &source);
    // ass. operator
    AliITSPlaneEffSPD& operator=(const AliITSPlaneEffSPD &s);
    // Simple way to add another class (i.e. statistics). 
    AliITSPlaneEffSPD& operator +=( const AliITSPlaneEffSPD &add);
    // Getters for average Plane efficiency (including dead/noisy)
    Double_t PlaneEff(const UInt_t mod, const UInt_t chip, Bool_t FO=kFALSE, const UInt_t BCm4=0) const;
    Double_t ErrPlaneEff(const UInt_t mod, const UInt_t chip, Bool_t FO=kFALSE, const UInt_t BCm4=0) const;
    Double_t PlaneEff(const UInt_t key) const 
        {return PlaneEff(GetModFromKey(key),GetChipFromKey(key),IsForFO(key),GetBCm4FromKey(key));};
    Double_t ErrPlaneEff(const UInt_t key) const 
        {return ErrPlaneEff(GetModFromKey(key),GetChipFromKey(key),IsForFO(key),GetBCm4FromKey(key));};
    // Getters for fFound[] and fTried[]
    Int_t GetFound(const UInt_t key) const; 
    Int_t GetTried(const UInt_t key) const; 
    // Methods to update the Plane efficiency (specific of the SPD segmentation) 
    Bool_t UpDatePlaneEff(const Bool_t Kfound, const UInt_t mod, const UInt_t chip, Bool_t FO=kFALSE, const UInt_t BCm4=0);
    Bool_t UpDatePlaneEff(const Bool_t Kfound, const UInt_t key)
        {return UpDatePlaneEff(Kfound,GetModFromKey(key),GetChipFromKey(key),IsForFO(key),GetBCm4FromKey(key));};
    //
    enum {kNModule = 240}; // The number of modules
    enum {kNModuleLy1 = 80}; // The number of modules in Inner Layer
    enum {kNChip = 5};     // The number of chips per module
    enum {kNCol = 32};     // The number of columns per chip
    enum {kNRow = 256};    // The number of rows per chip (and per module)
    enum {kNClockPhase = 4}; // The number of clock phases between LHC (40 MHz clock) and SPD (10 MHz clock), for FO studies

    virtual Double_t LivePlaneEff(UInt_t key) const;
    Double_t LivePlaneEff(const UInt_t mod, const UInt_t chip) const
       {return LivePlaneEff(GetKey(mod,chip));};
    virtual Double_t ErrLivePlaneEff(UInt_t key) const;
    Double_t ErrLivePlaneEff(const UInt_t mod, const UInt_t chip) const
       {return ErrLivePlaneEff(GetKey(mod,chip));};
    // Compute the fraction of Live area (of the CHIP for the SPD)
    virtual Double_t GetFracLive(const UInt_t key) const;
    // Compute the fraction of bad (i.e. dead and noisy) area (of the CHIP for the SPD)
    virtual Double_t GetFracBad(const UInt_t key) const;
    virtual Bool_t WriteIntoCDB() const;
    virtual Bool_t ReadFromCDB(); // this method reads Data Members (statistics) from DataBase
    Bool_t AddFromCDB(AliCDBId *cdbId);   // this method updates Data Members (statistics) from DataBase
    virtual Bool_t AddFromCDB() {AliCDBId *cdbId=0; return  AddFromCDB(cdbId);}
   // method to locate a basic block from Detector Local coordinate (to be used in tracking)
   // see file cxx for numbering convention.
   // here idet runs from 0 to 79 for layer 0 and from 0 to 159 for layer 1
    UInt_t GetKey(const UInt_t mod, const UInt_t chip, const Bool_t FO=kFALSE, const UInt_t BCm4=0) const; // unique key to locate the basic
                                                                                                           // block of the SPD for detector and FO efficiency
    UInt_t SwitchChipKeyNumbering(UInt_t key) const; //  method to switch from offline chip key numbering to online Raw Stream chip numbering 
                                                     // and viceversa. Used for Fast-Or studies.
    UInt_t GetKeyFromDetLocCoord(Int_t ilay,Int_t idet, Float_t, Float_t locz) const;
    UInt_t Nblock() const; // return the number of basic blocks
    // compute the geometrical limit of a basic block (chip) in detector local coordinate system 
    Bool_t GetBlockBoundaries(const UInt_t key,Float_t& xmn,Float_t& xmx,Float_t& zmn,Float_t& zmx) const;
  // Methods for dealing with auxiliary histograms
    // method to set on/off the creation/updates of histograms (Histos are created/destroyed)
    virtual void   SetCreateHistos(Bool_t his=kFALSE) 
         //{fHis=his; if(fHis) InitHistos(); else DeleteHistos(); return; }
         {fHis=his; if(fHis) {DeleteHistos(); InitHistos();} else DeleteHistos(); return; }
    virtual Bool_t FillHistos(UInt_t key, Bool_t found, Float_t *track, Float_t *cluster, Int_t *ctype, Float_t *angtrkmod);
    virtual Bool_t WriteHistosToFile(TString filename="PlaneEffSPDHistos.root",Option_t* option = "RECREATE");
    virtual Bool_t ReadHistosFromFile(TString filename="PlaneEffSPDHistos.root"); // histos must exist already !
                                                                                  // This method increases the
                                                                                  // statistics of histos by adding 
									          // those of the input file. 
 protected:
    virtual void Copy(TObject &obj) const;           // copy ALL data members to obj 
                                                     // both statistics ad histograms)
    Int_t GetMissingTracksForGivenEff(Double_t eff, Double_t RelErr, UInt_t im, UInt_t ic) const;
    UInt_t GetModFromKey(const UInt_t key) const;
    UInt_t GetChipFromKey(const UInt_t key) const;
    Bool_t IsForFO(const UInt_t key) const;
    UInt_t GetBCm4FromKey(const UInt_t key) const;  // return the "Bunch Crossing modulo 4" (for Fast Or studies)
    UInt_t GetChipFromCol(const UInt_t col) const;  // get the chip number (from 0 to kNChip)
    UInt_t GetColFromLocZ(Float_t zloc) const;      // get the Column from the local z
    Float_t GetLocZFromCol(const UInt_t col) const; // get the local Z from the column number,
                                                    // the latter in the range [0,kNChip*kNCol]
    Float_t GetLocXFromRow(const UInt_t row) const; // get the local X from the row number
                                                    // the latter in the range [0,kNRow]
    void GetModAndChipFromKey(const UInt_t key, UInt_t& mod, UInt_t& chip) const;
    void GetDeadAndNoisyInChip(const UInt_t key, UInt_t& dead, UInt_t& noisy) const;
// 
    Int_t fFound[kNModule*kNChip*(kNClockPhase+1)];  // if(<kNModule*kNChip) is the number of associated clusters in a given chip
    Int_t fTried[kNModule*kNChip*(kNClockPhase+1)];  // if(<kNModule*kNChip) is the number of tracks used for chip efficiency evaluation
                                                     // if(>=kNModule*kNChip) Same tale but for Fast-Or
                                                     // studies (in the 4 phase relationship between LHC and SPD clocks)
    Bool_t FillHistosStd(UInt_t key, Bool_t found, Float_t *track, Float_t *cluster, Int_t *ctype, Float_t *angtrkmod);
    Bool_t FillHistosFO(UInt_t key, Bool_t found, Float_t *track);

 private:
    enum {kNHisto = kNModule}; // The number of histograms: module by module.
    enum {kNclu = 3};          // Build specific histos of residuals up to cluster size kNclu.
                               // If you change them, then you must change implementation of
                               // the method FillHistos.

    virtual void InitHistos(); // create histos by allocating memory for them 
    virtual void DeleteHistos(); // deletete histos (memory is freed)
    virtual void CopyHistos(AliITSPlaneEffSPD& target) const; // copy only histograms to target

    TH1F **fHisResX; //! histos with residual distribution (track-cluster) along local X (r-phi)
    TH1F **fHisResZ; //! histos with residual distribution (track-cluster) along local Z
    TH2F **fHisResXZ; //! 2-d histos with residual distribution (track-cluster) along local X and Z
    TH2I **fHisClusterSize; //! histos with cluster-size distribution
    TH1F ***fHisResXclu; //! histos with residual distribution along local X (r-phi) for cluster type
    TH1F ***fHisResZclu; //! histos with residual distribution along local Z for cluster type
    TH1F ***fHisResXchip; //! histos with residual distribution along local X (r-phi) chip by chip
    TH1F ***fHisResZchip; //! histos with residual distribution along local Z chip by chip
    TProfile **fProfResXvsPhi; //! TProfile of X Residuals vs. impact Angle phi (of the track w.r.t. module)
    //TProfile **fProfResZvsPhi; //! TProfile of Z Residuals vs. impact Angle phi (of the track w.r.t. module)
    //TProfile **fProfResXvsDip; //! TProfile of X Residuals vs. impact dip Angle  (of the track w.r.t. module)
    TProfile **fProfResZvsDip; //! TProfile of Z Residuals vs. impact dip Angle  (of the track w.r.t. module)
    TProfile ***fProfResXvsPhiclu; //! TProfile of X Residuals vs. impact Angle phi (of the track w.r.t. module) for different clu. type
    TProfile ***fProfResZvsDipclu; //! TProfile of Z Residuals vs. impact dip Angle  (of the track w.r.t. module) for different clu. type
    TH1F **fHisTrackErrX; //! histos with track prediction error on Local X
    TH1F **fHisTrackErrZ; //! histos with track prediction error on Local Z
    TH1F **fHisClusErrX; //! histos with Local_X cluster error
    TH1F **fHisClusErrZ; //! histos with Local_Z cluster error
    TH1F ***fHisTrackXFOtrue; //! histos with track prediction along local X (r-phi) if FastOr bit is found
    TH1F ***fHisTrackZFOtrue; //! histos with track prediction along local Z if FastOr bit is found
    TH1F ***fHisTrackXFOfalse; //! histos with track prediction along local X (r-phi) if FastOr bit is not found
    TH1F ***fHisTrackZFOfalse; //! histos with track prediction along local Z if FastOr bit is not found
    TH2F ***fHisTrackXZFOtrue; //! histos with track prediction along local X (r-phi) and Z if FastOr bit is found
    TH2F ***fHisTrackXZFOfalse; //! histos with track prediction along local X (r-phi) and Z if FastOr bit is not found
    
    ClassDef(AliITSPlaneEffSPD,4) // SPD Plane Efficiency class
};
//
inline UInt_t AliITSPlaneEffSPD::Nblock() const {return kNModule*kNChip;}

inline Int_t AliITSPlaneEffSPD::GetFound(const UInt_t key) const {
 if(key>=kNModule*kNChip*(kNClockPhase+1)) {AliWarning("GetFound: you asked for a non existing key"); return -1;}
 if(key>=kNModule*kNChip)AliWarning("GetFound: you asked for FO efficiency studies");
 return fFound[key];
}
inline Int_t AliITSPlaneEffSPD::GetTried(const UInt_t key) const {
 if(key>=kNModule*kNChip*(kNClockPhase+1)) {AliWarning("GetTried: you asked for a non existing key"); return -1;}
 if(key>=kNModule*kNChip)AliWarning("GetTried: you asked for FO efficiency studies");
 return fTried[key];
}
//
#endif

 AliITSPlaneEffSPD.h:1
 AliITSPlaneEffSPD.h:2
 AliITSPlaneEffSPD.h:3
 AliITSPlaneEffSPD.h:4
 AliITSPlaneEffSPD.h:5
 AliITSPlaneEffSPD.h:6
 AliITSPlaneEffSPD.h:7
 AliITSPlaneEffSPD.h:8
 AliITSPlaneEffSPD.h:9
 AliITSPlaneEffSPD.h:10
 AliITSPlaneEffSPD.h:11
 AliITSPlaneEffSPD.h:12
 AliITSPlaneEffSPD.h:13
 AliITSPlaneEffSPD.h:14
 AliITSPlaneEffSPD.h:15
 AliITSPlaneEffSPD.h:16
 AliITSPlaneEffSPD.h:17
 AliITSPlaneEffSPD.h:18
 AliITSPlaneEffSPD.h:19
 AliITSPlaneEffSPD.h:20
 AliITSPlaneEffSPD.h:21
 AliITSPlaneEffSPD.h:22
 AliITSPlaneEffSPD.h:23
 AliITSPlaneEffSPD.h:24
 AliITSPlaneEffSPD.h:25
 AliITSPlaneEffSPD.h:26
 AliITSPlaneEffSPD.h:27
 AliITSPlaneEffSPD.h:28
 AliITSPlaneEffSPD.h:29
 AliITSPlaneEffSPD.h:30
 AliITSPlaneEffSPD.h:31
 AliITSPlaneEffSPD.h:32
 AliITSPlaneEffSPD.h:33
 AliITSPlaneEffSPD.h:34
 AliITSPlaneEffSPD.h:35
 AliITSPlaneEffSPD.h:36
 AliITSPlaneEffSPD.h:37
 AliITSPlaneEffSPD.h:38
 AliITSPlaneEffSPD.h:39
 AliITSPlaneEffSPD.h:40
 AliITSPlaneEffSPD.h:41
 AliITSPlaneEffSPD.h:42
 AliITSPlaneEffSPD.h:43
 AliITSPlaneEffSPD.h:44
 AliITSPlaneEffSPD.h:45
 AliITSPlaneEffSPD.h:46
 AliITSPlaneEffSPD.h:47
 AliITSPlaneEffSPD.h:48
 AliITSPlaneEffSPD.h:49
 AliITSPlaneEffSPD.h:50
 AliITSPlaneEffSPD.h:51
 AliITSPlaneEffSPD.h:52
 AliITSPlaneEffSPD.h:53
 AliITSPlaneEffSPD.h:54
 AliITSPlaneEffSPD.h:55
 AliITSPlaneEffSPD.h:56
 AliITSPlaneEffSPD.h:57
 AliITSPlaneEffSPD.h:58
 AliITSPlaneEffSPD.h:59
 AliITSPlaneEffSPD.h:60
 AliITSPlaneEffSPD.h:61
 AliITSPlaneEffSPD.h:62
 AliITSPlaneEffSPD.h:63
 AliITSPlaneEffSPD.h:64
 AliITSPlaneEffSPD.h:65
 AliITSPlaneEffSPD.h:66
 AliITSPlaneEffSPD.h:67
 AliITSPlaneEffSPD.h:68
 AliITSPlaneEffSPD.h:69
 AliITSPlaneEffSPD.h:70
 AliITSPlaneEffSPD.h:71
 AliITSPlaneEffSPD.h:72
 AliITSPlaneEffSPD.h:73
 AliITSPlaneEffSPD.h:74
 AliITSPlaneEffSPD.h:75
 AliITSPlaneEffSPD.h:76
 AliITSPlaneEffSPD.h:77
 AliITSPlaneEffSPD.h:78
 AliITSPlaneEffSPD.h:79
 AliITSPlaneEffSPD.h:80
 AliITSPlaneEffSPD.h:81
 AliITSPlaneEffSPD.h:82
 AliITSPlaneEffSPD.h:83
 AliITSPlaneEffSPD.h:84
 AliITSPlaneEffSPD.h:85
 AliITSPlaneEffSPD.h:86
 AliITSPlaneEffSPD.h:87
 AliITSPlaneEffSPD.h:88
 AliITSPlaneEffSPD.h:89
 AliITSPlaneEffSPD.h:90
 AliITSPlaneEffSPD.h:91
 AliITSPlaneEffSPD.h:92
 AliITSPlaneEffSPD.h:93
 AliITSPlaneEffSPD.h:94
 AliITSPlaneEffSPD.h:95
 AliITSPlaneEffSPD.h:96
 AliITSPlaneEffSPD.h:97
 AliITSPlaneEffSPD.h:98
 AliITSPlaneEffSPD.h:99
 AliITSPlaneEffSPD.h:100
 AliITSPlaneEffSPD.h:101
 AliITSPlaneEffSPD.h:102
 AliITSPlaneEffSPD.h:103
 AliITSPlaneEffSPD.h:104
 AliITSPlaneEffSPD.h:105
 AliITSPlaneEffSPD.h:106
 AliITSPlaneEffSPD.h:107
 AliITSPlaneEffSPD.h:108
 AliITSPlaneEffSPD.h:109
 AliITSPlaneEffSPD.h:110
 AliITSPlaneEffSPD.h:111
 AliITSPlaneEffSPD.h:112
 AliITSPlaneEffSPD.h:113
 AliITSPlaneEffSPD.h:114
 AliITSPlaneEffSPD.h:115
 AliITSPlaneEffSPD.h:116
 AliITSPlaneEffSPD.h:117
 AliITSPlaneEffSPD.h:118
 AliITSPlaneEffSPD.h:119
 AliITSPlaneEffSPD.h:120
 AliITSPlaneEffSPD.h:121
 AliITSPlaneEffSPD.h:122
 AliITSPlaneEffSPD.h:123
 AliITSPlaneEffSPD.h:124
 AliITSPlaneEffSPD.h:125
 AliITSPlaneEffSPD.h:126
 AliITSPlaneEffSPD.h:127
 AliITSPlaneEffSPD.h:128
 AliITSPlaneEffSPD.h:129
 AliITSPlaneEffSPD.h:130
 AliITSPlaneEffSPD.h:131
 AliITSPlaneEffSPD.h:132
 AliITSPlaneEffSPD.h:133
 AliITSPlaneEffSPD.h:134
 AliITSPlaneEffSPD.h:135
 AliITSPlaneEffSPD.h:136
 AliITSPlaneEffSPD.h:137
 AliITSPlaneEffSPD.h:138
 AliITSPlaneEffSPD.h:139
 AliITSPlaneEffSPD.h:140
 AliITSPlaneEffSPD.h:141
 AliITSPlaneEffSPD.h:142
 AliITSPlaneEffSPD.h:143
 AliITSPlaneEffSPD.h:144
 AliITSPlaneEffSPD.h:145
 AliITSPlaneEffSPD.h:146
 AliITSPlaneEffSPD.h:147
 AliITSPlaneEffSPD.h:148
 AliITSPlaneEffSPD.h:149
 AliITSPlaneEffSPD.h:150
 AliITSPlaneEffSPD.h:151
 AliITSPlaneEffSPD.h:152
 AliITSPlaneEffSPD.h:153
 AliITSPlaneEffSPD.h:154
 AliITSPlaneEffSPD.h:155
 AliITSPlaneEffSPD.h:156
 AliITSPlaneEffSPD.h:157
 AliITSPlaneEffSPD.h:158
 AliITSPlaneEffSPD.h:159
 AliITSPlaneEffSPD.h:160
 AliITSPlaneEffSPD.h:161
 AliITSPlaneEffSPD.h:162
 AliITSPlaneEffSPD.h:163
 AliITSPlaneEffSPD.h:164
 AliITSPlaneEffSPD.h:165
 AliITSPlaneEffSPD.h:166