ROOT logo
#ifndef HMDCCOSMICSCANDIDATE_H
#define HMDCCOSMICSCANDIDATE_H

#include "hreconstructor.h"
#include "TString.h"
#include "TRandom.h"
#include "hlocation.h"
#include "hgeomvector.h"

using namespace std;
class TH1F;
class TH2F;
class TFile;
class TLine;
class HIterator;
class HCategory;
class HTofHit;
class HTofCluster;
class HMdcSizesCells;
class HMdcSizesCellsLayer;
class HMdcGetContainers;
class HGeomTransform;
class HMdcList12GroupCells;
class HMdcClus;

class HMdcCosmicsCandidate : public HReconstructor {
  protected:
    struct MetaHit {
      Int_t       sec;
      Float_t     tof;
      HGeomVector hit;
      Bool_t      isTOF;    // kTRUE - TOF detector; kFALSE - RPC detector
    };
    MetaHit            metaHits[250];
    Int_t              nMetaHits;
    Int_t              nMetaHitSec[6];
    Int_t              nSectors;
    Float_t            zTofShift;          // Shift z position of TofCluster/Hit on this value
    Float_t            zRpcShift;          // Shift z position of RpcCluster/Hit on this value
    Bool_t             isGeant;
    
    Int_t              nWiresStat[6][4];
    Int_t              numWiresAllMod;
    
    // Track candidate line:
    HGeomVector        hit1;              // Meta hit in sector coor.sys
    HGeomVector        hit2;              // Meta hit in sector coor.sys
    
    struct TrackCand {
      Int_t            metaInd1;          // Track line
      Int_t            metaInd2;
      Char_t           modList[6];
      Int_t            nMods;             // number of modules crossed by track cand.
      Int_t            nSecs;             // number of sectors crossed by track cand.
      // Track quality:
      Int_t            nModules;          // Number of fired modules
      Int_t            nLayers;           // Number of fired layers
      Int_t            nModSec[6];        // Number of fired layers in sector
      Int_t            nLaySec[6];        // Number of fired layers in sector
      Int_t            nWires;            // Number of wires
      Double_t         dCellMean;
      Int_t            nWiresTot;         // Number of fired wires in the crossed modules
      void copy(TrackCand &tc) {
        metaInd1 = tc.metaInd1;
        metaInd2 = tc.metaInd2;
        for(Int_t s=0;s<6;s++) {
          modList[s] = tc.modList[s];
          nModSec[s] = tc.nModSec[s];
          nLaySec[s] = tc.nLaySec[s];
        }
        nMods     = tc.nMods;
        nSecs     = tc.nSecs;
        nModules  = tc.nModules;
        nLayers   = tc.nLayers;
        nWires    = tc.nWires;
        dCellMean = tc.dCellMean;
        nWiresTot = tc.nWiresTot;
      }
      void init(Int_t i1,Int_t i2) {
        metaInd1  = i1;
        metaInd2  = i2;
        nMods     = 0;
        nSecs     = 0;
        nModules  = 0;
        nLayers   = 0;
        nWires    = 0;
        dCellMean = 1.e+30;
        nWiresTot = 0;
        for(Int_t s=0;s<6;s++) modList[s] = nModSec[s] = nLaySec[s] = 0;
      }
      Bool_t trackStatus(void)                 {return nModules>=2 && nLayers>=5 /*|| nWires>=5*/;}
      void   addMod(Int_t s,Int_t m,Int_t nWr) { 
        if(modList[s]==0) nSecs++;
        modList[s] |= 1<<m;
        nMods++;
        nWiresTot += nWr;
      }
      void   unsetMod(Int_t s,Int_t m)         {if(modStatus(s,m)!=0) {
                                                  modList[s] ^= (1<<m);
                                                  if(modList[s] == 0) nSecs--;} }
      Bool_t secStatus(Int_t s) const          {return modList[s] != 0;}
      Char_t segStatus(Int_t s,Int_t sg) const {return (modList[s]>>(sg*2)) & 3;}
      Char_t modStatus(Int_t s,Int_t m) const  {return (modList[s]>>m) & 1;}
      Int_t  numWiresOutTrack(void) const      {return nWiresTot-nWires;}
      Double_t selectQual(void) const          {return Double_t(nWires)/Double_t(nWiresTot);}
      Int_t  numLayersPerMod(void) const       {return nLayers/nModules;}
    };
    TrackCand          bestTrCand;
    TrackCand          currTrCand;

    // Cut parameters"
    Double_t           betaMin;
    Double_t           betaMax;
    Float_t            dCellWind[4];       // [mod] window of cell-cell_calc
    Int_t              nLayInModCut;       // numFiredLayers/numModInTrack must be >= meanNLayCutu
    Int_t              maxNWiresOutTr;     // maximal num.of wires out of track in the crossed modules
    Double_t           selQualCut;         // cut for numWiresInTrack/totalNunWiresInCrossedModules
    
    Int_t              nEventsTot;
    Int_t              nEventsSel;
    Int_t              nSelTr[9];          // index is number of MDC modules in track
                                           // nSelTr[index] - number of tracks with "index" number of MDCs
    Double_t           trackScaling[9];    // index is number of MDC modules in track
                                           // trackScaling[index] - take this fraction 
                                           // (=1.-all, =0.5-half, ...) of tracks with "index" number of MDCs
    Int_t              nSelTrSc[9];
    Int_t              nEventsSelSc;
    
    TRandom            rndm;
    
    HCategory         *pCatTof; 
    UChar_t            useTofCat;
    HCategory         *pCatRpc;
    UChar_t            useRpcCat;
    HCategory         *pCatMdcCal1;
    HLocation          locCal1;
    HCategory         *pCatMdcClus;
    HLocation          locClus;
    HMdcSizesCells*    sizes;              //! comment to fill in.
    HMdcGetContainers* pGetCont;
    Int_t              index;
    Int_t              returnFlag;
    Int_t              mdcsetup[6][4];
    Bool_t             setParContStat;
    
    // Layer size in layer coor.system. Due to symmmetry 2 points enough:
    struct LayerSize {
      Double_t             y1;             // minimal value
      Double_t             y2;             // maximal value
      Double_t             x2;             // correspond y2
      Double_t             inc;            // (x1-x2)/(y1-y2);
      HMdcSizesCellsLayer *pScLay;
    };
    LayerSize          laySize[4];         // [MDCplane][0-layer1; 1-layer6]
    
    TH1F              *hsBeta;
    TH2F              *plStat;
    TH2F              *plQualVsWrLo;
    TH1F              *hsDCell[6][4];
    TH1F              *hsDCellL[6][4][6];

    Bool_t             makeHists;
    TFile             *histFile;
    TString            histFileName;
    TString            histFileOption;

  private:
    void               printParam(void);
    Bool_t             createHists(void);
    void               initVariables(void);
    void               collectTofHits(void);
    void               collectRpcHits(void);
    Bool_t             testBeta(const MetaHit &h1,const MetaHit &h2,Bool_t mHists=kFALSE);
    HMdcClus*          fillCluster(Int_t sec,Int_t seg,HMdcList12GroupCells &listCells,HMdcClus* prevClus);
    Bool_t             fillTrack(TrackCand &bestCand);
    Bool_t             testTrack(void);
    Bool_t             isCrossMod(Int_t sec,Int_t mod);
    void               testSectors(TrackCand &trackCand,Int_t sec,Int_t part=0);
    Bool_t             calcSectors(TrackCand &trackCand);
    
  public:
    HMdcCosmicsCandidate(const Text_t *name, const Text_t *title);
    HMdcCosmicsCandidate(void);
    ~HMdcCosmicsCandidate(void);

    virtual Bool_t     init(void);
    virtual Bool_t     reinit(void);
    virtual Bool_t     finalize(void);
    virtual Int_t      execute(void);

    void               setBetaCut(Double_t min,Double_t max);
    void               setDCellWindow(Float_t wM1,Float_t wM2,Float_t wM3,Float_t wM4);
    void               setNLayPerModCut(Int_t cut)      {nLayInModCut = cut;};
    void               setSelectionCut(Int_t maxLW,Double_t qu) {maxNWiresOutTr = maxLW;
                                                                 selQualCut     = qu;}

    void               makeHistograms(Bool_t fl=kTRUE)  {makeHists = fl;}
    void               setHistFile(const Char_t* dir="./",const Char_t* fileNm="cosmCandHists",
                                   const Char_t* opt="NEW");
    void               setSkipEvent(Bool_t fl=kTRUE)    {returnFlag = fl ? kSkipEvent : 0;}
    void               scaleDownTrack(UInt_t nMdcTr,Double_t sc);
    void               scaleDownTrack(Double_t *sca);
    void               setParContainersStatic(void)     {setParContStat = kTRUE;}
    void               setZShiftForTof(Float_t sh)      {zTofShift = sh;}
    void               setZShiftForRpc(Float_t sh)      {zRpcShift = sh;}
    void               useTofHits(void)                 {useTofCat = 1;}
    void               useRpcHits(void)                 {useRpcCat = 1;}
    void               useTofClusters(void)             {useTofCat = 2;}
    void               useRpcClusters(void)             {useRpcCat = 2;}
 
  ClassDef(HMdcCosmicsCandidate,0)
};

class HCosmicCalibEvSkip : public HReconstructor {
  public:
    HCosmicCalibEvSkip(void);
    HCosmicCalibEvSkip(const Text_t *name, const Text_t *title);
    ~HCosmicCalibEvSkip(void) {}
    virtual Bool_t     init(void)     {return kTRUE;}
    virtual Bool_t     reinit(void)   {return kTRUE;}
    virtual Bool_t     finalize(void) {return kTRUE;}
    virtual Int_t      execute(void);
  
   ClassDef(HCosmicCalibEvSkip,0)
};
  
#endif
 hmdccosmicscandidate.h:1
 hmdccosmicscandidate.h:2
 hmdccosmicscandidate.h:3
 hmdccosmicscandidate.h:4
 hmdccosmicscandidate.h:5
 hmdccosmicscandidate.h:6
 hmdccosmicscandidate.h:7
 hmdccosmicscandidate.h:8
 hmdccosmicscandidate.h:9
 hmdccosmicscandidate.h:10
 hmdccosmicscandidate.h:11
 hmdccosmicscandidate.h:12
 hmdccosmicscandidate.h:13
 hmdccosmicscandidate.h:14
 hmdccosmicscandidate.h:15
 hmdccosmicscandidate.h:16
 hmdccosmicscandidate.h:17
 hmdccosmicscandidate.h:18
 hmdccosmicscandidate.h:19
 hmdccosmicscandidate.h:20
 hmdccosmicscandidate.h:21
 hmdccosmicscandidate.h:22
 hmdccosmicscandidate.h:23
 hmdccosmicscandidate.h:24
 hmdccosmicscandidate.h:25
 hmdccosmicscandidate.h:26
 hmdccosmicscandidate.h:27
 hmdccosmicscandidate.h:28
 hmdccosmicscandidate.h:29
 hmdccosmicscandidate.h:30
 hmdccosmicscandidate.h:31
 hmdccosmicscandidate.h:32
 hmdccosmicscandidate.h:33
 hmdccosmicscandidate.h:34
 hmdccosmicscandidate.h:35
 hmdccosmicscandidate.h:36
 hmdccosmicscandidate.h:37
 hmdccosmicscandidate.h:38
 hmdccosmicscandidate.h:39
 hmdccosmicscandidate.h:40
 hmdccosmicscandidate.h:41
 hmdccosmicscandidate.h:42
 hmdccosmicscandidate.h:43
 hmdccosmicscandidate.h:44
 hmdccosmicscandidate.h:45
 hmdccosmicscandidate.h:46
 hmdccosmicscandidate.h:47
 hmdccosmicscandidate.h:48
 hmdccosmicscandidate.h:49
 hmdccosmicscandidate.h:50
 hmdccosmicscandidate.h:51
 hmdccosmicscandidate.h:52
 hmdccosmicscandidate.h:53
 hmdccosmicscandidate.h:54
 hmdccosmicscandidate.h:55
 hmdccosmicscandidate.h:56
 hmdccosmicscandidate.h:57
 hmdccosmicscandidate.h:58
 hmdccosmicscandidate.h:59
 hmdccosmicscandidate.h:60
 hmdccosmicscandidate.h:61
 hmdccosmicscandidate.h:62
 hmdccosmicscandidate.h:63
 hmdccosmicscandidate.h:64
 hmdccosmicscandidate.h:65
 hmdccosmicscandidate.h:66
 hmdccosmicscandidate.h:67
 hmdccosmicscandidate.h:68
 hmdccosmicscandidate.h:69
 hmdccosmicscandidate.h:70
 hmdccosmicscandidate.h:71
 hmdccosmicscandidate.h:72
 hmdccosmicscandidate.h:73
 hmdccosmicscandidate.h:74
 hmdccosmicscandidate.h:75
 hmdccosmicscandidate.h:76
 hmdccosmicscandidate.h:77
 hmdccosmicscandidate.h:78
 hmdccosmicscandidate.h:79
 hmdccosmicscandidate.h:80
 hmdccosmicscandidate.h:81
 hmdccosmicscandidate.h:82
 hmdccosmicscandidate.h:83
 hmdccosmicscandidate.h:84
 hmdccosmicscandidate.h:85
 hmdccosmicscandidate.h:86
 hmdccosmicscandidate.h:87
 hmdccosmicscandidate.h:88
 hmdccosmicscandidate.h:89
 hmdccosmicscandidate.h:90
 hmdccosmicscandidate.h:91
 hmdccosmicscandidate.h:92
 hmdccosmicscandidate.h:93
 hmdccosmicscandidate.h:94
 hmdccosmicscandidate.h:95
 hmdccosmicscandidate.h:96
 hmdccosmicscandidate.h:97
 hmdccosmicscandidate.h:98
 hmdccosmicscandidate.h:99
 hmdccosmicscandidate.h:100
 hmdccosmicscandidate.h:101
 hmdccosmicscandidate.h:102
 hmdccosmicscandidate.h:103
 hmdccosmicscandidate.h:104
 hmdccosmicscandidate.h:105
 hmdccosmicscandidate.h:106
 hmdccosmicscandidate.h:107
 hmdccosmicscandidate.h:108
 hmdccosmicscandidate.h:109
 hmdccosmicscandidate.h:110
 hmdccosmicscandidate.h:111
 hmdccosmicscandidate.h:112
 hmdccosmicscandidate.h:113
 hmdccosmicscandidate.h:114
 hmdccosmicscandidate.h:115
 hmdccosmicscandidate.h:116
 hmdccosmicscandidate.h:117
 hmdccosmicscandidate.h:118
 hmdccosmicscandidate.h:119
 hmdccosmicscandidate.h:120
 hmdccosmicscandidate.h:121
 hmdccosmicscandidate.h:122
 hmdccosmicscandidate.h:123
 hmdccosmicscandidate.h:124
 hmdccosmicscandidate.h:125
 hmdccosmicscandidate.h:126
 hmdccosmicscandidate.h:127
 hmdccosmicscandidate.h:128
 hmdccosmicscandidate.h:129
 hmdccosmicscandidate.h:130
 hmdccosmicscandidate.h:131
 hmdccosmicscandidate.h:132
 hmdccosmicscandidate.h:133
 hmdccosmicscandidate.h:134
 hmdccosmicscandidate.h:135
 hmdccosmicscandidate.h:136
 hmdccosmicscandidate.h:137
 hmdccosmicscandidate.h:138
 hmdccosmicscandidate.h:139
 hmdccosmicscandidate.h:140
 hmdccosmicscandidate.h:141
 hmdccosmicscandidate.h:142
 hmdccosmicscandidate.h:143
 hmdccosmicscandidate.h:144
 hmdccosmicscandidate.h:145
 hmdccosmicscandidate.h:146
 hmdccosmicscandidate.h:147
 hmdccosmicscandidate.h:148
 hmdccosmicscandidate.h:149
 hmdccosmicscandidate.h:150
 hmdccosmicscandidate.h:151
 hmdccosmicscandidate.h:152
 hmdccosmicscandidate.h:153
 hmdccosmicscandidate.h:154
 hmdccosmicscandidate.h:155
 hmdccosmicscandidate.h:156
 hmdccosmicscandidate.h:157
 hmdccosmicscandidate.h:158
 hmdccosmicscandidate.h:159
 hmdccosmicscandidate.h:160
 hmdccosmicscandidate.h:161
 hmdccosmicscandidate.h:162
 hmdccosmicscandidate.h:163
 hmdccosmicscandidate.h:164
 hmdccosmicscandidate.h:165
 hmdccosmicscandidate.h:166
 hmdccosmicscandidate.h:167
 hmdccosmicscandidate.h:168
 hmdccosmicscandidate.h:169
 hmdccosmicscandidate.h:170
 hmdccosmicscandidate.h:171
 hmdccosmicscandidate.h:172
 hmdccosmicscandidate.h:173
 hmdccosmicscandidate.h:174
 hmdccosmicscandidate.h:175
 hmdccosmicscandidate.h:176
 hmdccosmicscandidate.h:177
 hmdccosmicscandidate.h:178
 hmdccosmicscandidate.h:179
 hmdccosmicscandidate.h:180
 hmdccosmicscandidate.h:181
 hmdccosmicscandidate.h:182
 hmdccosmicscandidate.h:183
 hmdccosmicscandidate.h:184
 hmdccosmicscandidate.h:185
 hmdccosmicscandidate.h:186
 hmdccosmicscandidate.h:187
 hmdccosmicscandidate.h:188
 hmdccosmicscandidate.h:189
 hmdccosmicscandidate.h:190
 hmdccosmicscandidate.h:191
 hmdccosmicscandidate.h:192
 hmdccosmicscandidate.h:193
 hmdccosmicscandidate.h:194
 hmdccosmicscandidate.h:195
 hmdccosmicscandidate.h:196
 hmdccosmicscandidate.h:197
 hmdccosmicscandidate.h:198
 hmdccosmicscandidate.h:199
 hmdccosmicscandidate.h:200
 hmdccosmicscandidate.h:201
 hmdccosmicscandidate.h:202
 hmdccosmicscandidate.h:203
 hmdccosmicscandidate.h:204
 hmdccosmicscandidate.h:205
 hmdccosmicscandidate.h:206
 hmdccosmicscandidate.h:207
 hmdccosmicscandidate.h:208
 hmdccosmicscandidate.h:209
 hmdccosmicscandidate.h:210
 hmdccosmicscandidate.h:211
 hmdccosmicscandidate.h:212
 hmdccosmicscandidate.h:213
 hmdccosmicscandidate.h:214
 hmdccosmicscandidate.h:215
 hmdccosmicscandidate.h:216
 hmdccosmicscandidate.h:217
 hmdccosmicscandidate.h:218
 hmdccosmicscandidate.h:219
 hmdccosmicscandidate.h:220
 hmdccosmicscandidate.h:221
 hmdccosmicscandidate.h:222
 hmdccosmicscandidate.h:223
 hmdccosmicscandidate.h:224
 hmdccosmicscandidate.h:225
 hmdccosmicscandidate.h:226
 hmdccosmicscandidate.h:227