ROOT logo
#ifndef HMDCTIMECUT_H
#define HMDCTIMECUT_H

#include "hparset.h"
#include "hmdccal1.h"
#include "hmessagemgr.h"
#include <stdio.h>
#include "TObjArray.h"

class HMdcDetector;

class HMdcTimeCutMod : public TObject {
 protected:
  Float_t cutT1L;       // Cut 1:  cutT1L<time1<cutT1R
  Float_t cutT1R;       // cutT1L>=cutT1R - no cut
  Float_t cutT2L;       // Cut 2:  cutT2L<time2<cutT2R
  Float_t cutT2R;       // cutT2L>=cutT2R - no cut
  Float_t cutLeft;      // Cut 3: cutLeft<(time2-time1)<cutRight
  Float_t cutRight;     // cutLeft>=cutRight - no cut


  // additional cut for bump in correlation t1 + tot
  // (remove times in the box t1>cutBumpT1L && t1<cutBumpT1R && tot>cutBumpTotL && tot<cutBumpTotR)
  Float_t cutBumpT1L;       // bump Cut 1:  cutBumpT1L<time1<cutBumpT1R
  Float_t cutBumpT1R;       // cutBumpT1L>=cutBumpT1R - no cut
  Float_t cutBumpTotL;      // bump Cut 2:  cutTotL<time2<cutTotR
  Float_t cutBumpTotR;      // cutBumpTotL>=cutBumpTotR - no cut



public:
  HMdcTimeCutMod() { clear(); }
  HMdcTimeCutMod(HMdcTimeCutMod &tc):TObject(tc) {fill(tc);}
  ~HMdcTimeCutMod() {}

  void setCutTime1(Float_t left,Float_t right) {
    cutT1L = left;
    cutT1R = right;
  }
  void setCutTime2(Float_t left,Float_t right) { 
    cutT2L = left;
    cutT2R = right;
  }
  void setCutTime(Float_t left,Float_t right) { 
    cutLeft = left;
    cutRight = right;
  } 
  void setCutBumpTime1(Float_t left,Float_t right) {
    cutBumpT1L = left;
    cutBumpT1R = right;
  } 
  void setCutBumpTot(Float_t left,Float_t right) {
    cutBumpTotL = left;
    cutBumpTotR = right;
  } 

  Float_t getCutTime1Left(void) { return cutT1L; }
  Float_t getCutTime1Right(void){ return cutT1R; }
  Float_t getCutTime2Left(void) { return cutT2L; }
  Float_t getCutTime2Right(void){ return cutT2R; }
  Float_t getCutTimeLeft(void)  { return cutLeft; }
  Float_t getCutTimeRight(void) { return cutRight; }
  Float_t getCutBumpTime1Left(void) { return cutBumpT1L; }
  Float_t getCutBumpTime1Right(void){ return cutBumpT1R; }
  Float_t getCutBumpTotLeft(void) { return cutBumpTotL; }
  Float_t getCutBumpTotRight(void){ return cutBumpTotR; }
  
  void fill(HMdcTimeCutMod &tc) {
    cutT1L      = tc.cutT1L;
    cutT1R      = tc.cutT1R;
    cutT2L      = tc.cutT2L;
    cutT2R      = tc.cutT2R;
    cutLeft     = tc.cutLeft;
    cutRight    = tc.cutRight;
    cutBumpT1L  = tc.cutBumpT1L;
    cutBumpT1R  = tc.cutBumpT1R;
    cutBumpTotL = tc.cutBumpTotL;
    cutBumpTotR = tc.cutBumpTotR;
  }
  void fill(Float_t cT1L,Float_t cT1R,Float_t cT2L,Float_t cT2R,
	    Float_t cLeft,Float_t cRight,
            Float_t cBumpT1L,Float_t cBumpT1R,Float_t cBumpTotL,Float_t cBumpTotR
	   ) {
    cutT1L      = cT1L;
    cutT1R      = cT1R;
    cutT2L      = cT2L;
    cutT2R      = cT2R;
    cutLeft     = cLeft;
    cutRight    = cRight;
    cutBumpT1L  = cBumpT1L;
    cutBumpT1R  = cBumpT1R;
    cutBumpTotL = cBumpTotL;
    cutBumpTotR = cBumpTotR;
  }
  Bool_t cutTime1(Float_t time1) {  // kTRUE : pass cut
    return (cutT1L < cutT1R && (time1>cutT1L && time1<=cutT1R)) || (cutT1L == cutT1R);
  }
  Bool_t cutTime2(Float_t time2) {  // kTRUE : pass cut
    return (cutT2L<cutT2R && (time2>cutT2L && time2<=cutT2R))   || (cutT2L == cutT2R);
  }
  Bool_t cutTimesDif(Float_t dTime) { // kTRUE : pass cut
    return (cutLeft<cutRight && (dTime>cutLeft && dTime<=cutRight)) || (cutLeft == cutRight);
  }
  Bool_t cutComStop(Float_t time1) { // kTRUE : pass cut
    return (cutT1L<cutT1R && time1<=cutT1R) || (cutT1L == cutT1R);
  }
  Bool_t cutBump(Float_t time1,Float_t tot) {  // kTRUE : pass cut
      return (cutBumpT1L < cutBumpT1R && !(cutBumpT1L<=time1 && cutBumpT1R>time1 && cutBumpTotL<=tot && cutBumpTotR>tot)) || (cutBumpT1L == cutBumpT1R); }

  void clear(void) {
    fill(0., 0., 0., 0., 0., 0., 0., 0., 0., 0. );
  }
  void print(void) {
      gHades->getMsg()->info(10,HMessageMgr::DET_MDC,GetName()
			     ,"time1: (%f, %f), time2: (%f, %f), tab: (%f, %f), Bump time1: (%f, %f), tab: (%f, %f)\n"
			     , cutT1L,cutT1R,cutT2L,cutT2R,cutLeft,cutRight
			     , cutBumpT1L,cutBumpT1R,cutBumpTotL,cutBumpTotR);
  }
  ClassDef(HMdcTimeCutMod,2)
};

class HMdcTimeCutSec : public TObject {
 protected:
  TObjArray fMod;
 public:
  HMdcTimeCutSec(Int_t mods=4) : fMod(mods) {
    for (Int_t i=0; i<mods; i++) fMod.AddAt(new HMdcTimeCutMod,i);
  }
  ~HMdcTimeCutSec(void) {}
  HMdcTimeCutMod& operator[](Int_t i) {
    return *( static_cast<HMdcTimeCutMod*>(fMod[i]) );
  }
  Int_t getSize() {return fMod.GetEntries();}
  ClassDef(HMdcTimeCutSec,1)
};

class HMdcTimeCut : public HParSet {
protected:
  TObjArray fSecs; // Sectors containins modules containing cuts
  Bool_t isContainer;  
  void setNameTitle();
  HMdcDetector *fMdc; 
  Bool_t isused;  // flag for used/not used
public:
  HMdcTimeCut(const Char_t* name="MdcTimeCut",
              const Char_t* title="cut on time1, time2 & time2-time1",
              const Char_t* context="MdcTimeCutProduction",
              Int_t secs=6,Int_t mods=4);
  ~HMdcTimeCut(void) {};
  void   setIsUsed(Bool_t flag)    {isused=flag;}
  Bool_t getIsUsed()             {return isused;}

  static HMdcTimeCut* getExObject();  // if HMdcTimeCut not existed = 0 
  static HMdcTimeCut* getObject();    // if HMdcTimeCut not existed it will cr.

  Bool_t cut(HMdcCal1* cal);          // if =kTRUE don't use this hit
  Bool_t cutComStop(HMdcCal1* cal);
  Bool_t cutTime1(HMdcCal1* cal);
  Bool_t cutTime1(Int_t,Int_t,Float_t);

  Bool_t cutTime2(HMdcCal1* cal);
  Bool_t cutTime2(Int_t,Int_t,Float_t);

  Bool_t cutTimesDif(HMdcCal1* cal);
  Bool_t cutTimesDif(Int_t,Int_t,Float_t,Float_t);

  Bool_t cutBump(HMdcCal1* cal);
  Bool_t cutBump(Int_t,Int_t,Float_t,Float_t);

  void setCut         (Float_t cT1L, Float_t cT1R, Float_t cT2L, Float_t cT2R, Float_t cLeft, Float_t cRight,Float_t cBumpT1L,Float_t cBumpT1R,Float_t cBumpTotL,Float_t cBumpTotR);
  void setCut         (Float_t* cT1L, Float_t* cT1R, Float_t* cT2L, Float_t* cT2R,Float_t* cLeft, Float_t* cRight,Float_t* cBumpT1L,Float_t* cBumpT1R,Float_t* cBumpTotL,Float_t* cBumpTotR);
  void setCutTime1    (Float_t cT1L, Float_t cT1R);
  void setCutTime2    (Float_t cT2L, Float_t cT2R);
  void setCutDTime21  (Float_t cLeft, Float_t cRight);
  void setCutBumpTime1(Float_t cLeft, Float_t cRight);
  void setCutBumpTot  (Float_t cLeft, Float_t cRight);
  void setCut         (Int_t mod, Float_t cT1L, Float_t cT1R, Float_t cT2L, Float_t cT2R, Float_t cLeft, Float_t cRight,Float_t cBumpT1L,Float_t cBumpT1R,Float_t cBumpTotL,Float_t cBumpTotR);
  void setCutTime1    (Int_t mod, Float_t cT1L, Float_t cT1R);
  void setCutTime2    (Int_t mod, Float_t cT2L, Float_t cT2R);
  void setCutDTime21  (Int_t mod, Float_t cLeft, Float_t cRight);
  void setCutBumpTime1(Int_t mod, Float_t cLeft, Float_t cRight);
  void setCutBumpTot  (Int_t mod, Float_t cLeft, Float_t cRight);
  void getCut         (Int_t s,Int_t mod, Float_t &cT1L, Float_t &cT1R,Float_t &cT2L, Float_t &cT2R, Float_t &cLeft, Float_t &cRight,Float_t& cBumpT1L,Float_t& cBumpT1R,Float_t& cBumpTotL,Float_t& cBumpTotR);

  Float_t  getCutT1L     (Int_t sec, Int_t mod) { return (*this)[sec][mod].getCutTime1Left();       }
  Float_t  getCutT1R     (Int_t sec, Int_t mod) { return (*this)[sec][mod].getCutTime1Right();      }
  Float_t  getCutT2L     (Int_t sec, Int_t mod) { return (*this)[sec][mod].getCutTime2Left();       }
  Float_t  getCutT2R     (Int_t sec, Int_t mod) { return (*this)[sec][mod].getCutTime2Right();      }
  Float_t  getCutDTime21L(Int_t sec, Int_t mod) { return (*this)[sec][mod].getCutTimeLeft();        }
  Float_t  getCutDTime21R(Int_t sec, Int_t mod) { return (*this)[sec][mod].getCutTimeRight();       }
  Float_t  getCutBumpT1L (Int_t sec, Int_t mod) { return (*this)[sec][mod].getCutBumpTime1Left();   }
  Float_t  getCutBumpT1R (Int_t sec, Int_t mod) { return (*this)[sec][mod].getCutBumpTime1Right();  }
  Float_t  getCutBumpTotL(Int_t sec, Int_t mod) { return (*this)[sec][mod].getCutBumpTotLeft();     }
  Float_t  getCutBumpTotR(Int_t sec, Int_t mod) { return (*this)[sec][mod].getCutBumpTotRight();    }

  Bool_t init(HParIo* input,Int_t* set);
  Int_t  write(HParIo* output) ;
  void   readline(const Char_t* buf, Int_t* set) ;
  void   putAsciiHeader(TString&);
  Bool_t writeline(Char_t*, Int_t, Int_t);

  HMdcTimeCutSec& operator[](Int_t i) {
    return *( static_cast<HMdcTimeCutSec*>(fSecs[i]) );
  }
  Int_t getSize() {return fSecs.GetEntries();}
  void clear(void);
  void printParam(void) {
      INFO_msg(10,HMessageMgr::DET_MDC,"TimeCut:\n");
      for (Int_t i=0;i<getSize();i++) {
	  HMdcTimeCutSec &sector = (*this)[i];
	  for (Int_t m=0; m<sector.getSize(); m++) {
	      HMdcTimeCutMod &mod = sector[m];
	      gHades->getMsg()->info(10,HMessageMgr::DET_MDC,GetName(),"%i %i ",i,m);
	      mod.print();
	  }
      }
  }

  ClassDef(HMdcTimeCut,1)
};

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