ROOT logo
#ifndef HMDCSELFTRACKING_H
#define HMDCSELFTRACKING_H

#include "hreconstructor.h"

class TDirectory;
class TFile;
class HCategory;
class HIterator;
class HEventHeader;
class TH1F;
class TH1D;
class TH2S;
class TH3F;
class TProfile;

#define HMDCSELFTRACKING_CUTBRIDGE_NUMBER 20
#define HMDCSELFTRACKING_STARTSTRIP_NUMBER 9

class HMdcSelfTracking : public HReconstructor {
public:

protected:
  
  // some local declarations:
  
  // *** cuts ***
  
  
     enum selftrackingCut  {
	                    NO_CUT = 0,
			    TOF_BIT_CUT = 1,
			    START_CUT = 2,
			    TIME1_CUT = 3,
			    TIME2_CUT = 4,
			    TIME_ABOVE_THRESHOLD_CUT = 5,
			    MISC_6  =  6,
			    MISC_7  =  7,
			    MISC_8  =  8,
			    MISC_9  =  9,
			    MISC_10 = 10,
			    MISC_11 = 11,
			    MISC_12 = 12,
			    MISC_13 = 13,
			    MISC_14 = 14,
			    MISC_15 = 15,
			    MISC_16 = 16,
			    MISC_17 = 17,
			    MISC_18 = 18,
			    MISC_19 = 19,
			    MISC_20 = 20};
  
  enum flags  {NEIGHBOURS                 = 0,
               LEFT_CELL_HIT              = 1,
               RIGHT_CELL_HIT             = 2,
               ANALYSISLAYER2_HITS        = 1,
               ANALYSISLAYER2_DOUBLE_HITS = 2,
               RESIDUAL_CUT               = 3 };

  enum selftrackingStartStrip  {START_STRIP_1 = 1,
				START_STRIP_2 = 2,
				START_STRIP_3 = 3,
				START_STRIP_4 = 4,
				START_STRIP_5 = 5,
				START_STRIP_6 = 6,
				START_STRIP_7 = 7,
				START_STRIP_8 = 8 };

  enum rightleft {LEFT  = 1,
                  RIGHT = 2};
  Int_t setLeft[4];  // define conditions for LEFT/RIGHT correlations for different planes (I,II,III,IV)
  Int_t setRight[4]; // same
  
  Float_t A[4],B[4],C[4]; // Correlation fct parameters
  Float_t CorrWindow[4][3]; // Residual cut

  Float_t tdifmin[5]; // lower limit for cut in time-above-threshold (time1-time2)
  Float_t tdifmax[5]; // upper limit for cut in time-above-threshold (time1-time2)
  Float_t tdifcut; // cut for time1(layer3)-time1(layer4)
  Float_t tmin; // lower limit for cut in time
  Float_t tmax; // upper limit for cut in time
  Int_t cellmin; // lower limit for the cells to be used in a further analysis
  Int_t cellmax; // upper limit for the cells to be used in a further analysis
  Float_t startmin[HMDCSELFTRACKING_STARTSTRIP_NUMBER]; // array of lower limits of start time window over all start detector strips
  Float_t startmax[HMDCSELFTRACKING_STARTSTRIP_NUMBER]; // array of upper limits of start time window over all start detector strips
  Bool_t cutbridge[HMDCSELFTRACKING_CUTBRIDGE_NUMBER]; // array of cut bridges to switch of cuts 
  Bool_t cut[20]; // internal
  Int_t monitorCell;  // cell number which is taken into account for further analysis
  Int_t monitorLayer; // cell layer which is taken into account for further analysis
  // *** end cuts ***
  
  Float_t hitTime1[7][200]; // array containing time 1 per layer which fulfill the cut conditions
  Float_t hitTime2[7][200]; // array containing time 2 per layer which fulfill the cut conditions
  Float_t time1;
  Float_t time2;
  Float_t timesum;
  Float_t timediff;
  Float_t timeDiffMax;

  Int_t  setmodule, setsector;   // variables for setActiveModule(sec,mod) start counting from 1
  
  Bool_t noStart;                        // flag if starttime should not be used
  
  Bool_t noCorrSector;   // flag if CorrSector 3dim histogram should not be filled
  Bool_t noCheckCorrSector;   // flag if CorrSector is not checked

  Int_t module, sector, cell, layer;
  Int_t hitCells[7][200];              // array containing the cellnumbers per layer which fulfill the cut conditions
  Int_t nhit[7];                // hits per layer

  Int_t cell0[5][200]; // hits in 0-deg-layers, all chambers of a given sector
  Int_t ncell0[5];
  
  Bool_t relevant_data; //Boolean flag to indicate that data arrays had been filled, triggers correlation analysis
  Bool_t flag[4];  // Boolean array to trigger on flags (NEIGHBOURS = 0, LEFT_CELL_HIT = 1, RIGHT_CELL_HIT = 2, RESIDUAL_CUT = 3)
  Int_t alreadyUsedCellFlag_AnalysisLayer1[200];
  Int_t alreadyUsedCellFlag_AnalysisLayer2[200];
 // Int_t ihit;
  Int_t lhit[3];
  
  Int_t analysisLayer1;
  Int_t analysisLayer2;
  Int_t cntHitslayer1;
  Int_t cntHitslayer2;
  Int_t cntHitsWithoutNeighbours;
  Int_t cntHitsAnalysislayer2;
  Int_t cntDoubleHitsAnalysislayer2;
  Int_t eventCounter;
  
  Float_t counter[3][160];
  Double_t ctrl[11];
  
  Int_t start_strip, nstartstrip;
  Float_t start_time;
  
  HCategory     *calCatMdc;           // pointer to the MDC-CAL1 data
  HCategory     *calCatStart;         // pointer to the START-CAL1 data
  HIterator     *iterMdc;             // iterator on MDC raw data
  HIterator     *iterStart;           // iterator on START raw data
  
  HEventHeader  *evheader;            // Hades event header
  
  Char_t *fNameRoot;                  // file name of root output file
  
  // pointer to histos:
  
  TH1F *pinfo; // scaler info
  TH1D *player[7]; // hit pattern layer 1-6
  TH1D *pNhitlayer[7]; // hits per layer 1-6
  TH1D *player0[3]; // selftracking: hit pattern +/-0deg layers
  TH1F *peff; // efficiency layer 4 relative to layer 3
  
  TH1D *pTime_cut[7]; // drift time spectra for different cut levels
  TH2S *pTime0_cell[7]; // cell# vs. drifttime per layer without cuts
  TH2S *pTime0_diff; // time above threshold vs. drifttime
  TH2S *pTime_cell[7];  // cell# vs. drifttime after cuts
  TH1D *pTime_diff[2]; // time above threshold, w/[0]. w/o[1] threshold
  TH2S *pTime0diff_cell[3]; // cell# vs. time above threshold (0deg layers)
  TH2S *pTimesum_adj_cell3; // cell# vs. time sum of adjacent cells, layer 3
  TH2S *pTimesum_adj_cell4; // cell# vs. time sum of adj. cells, layer 4, cut on time diff
  TH2S *pTimesum_cell[3]; // selftracking: cell# vs. time sum of correl. cells
  TH2S *pFish[3][120];    // selftracking: time diff vs. sum of correl. cells
  TH2S *pTsum_ev[3][120]; //  selftracking: time sum vs. event#
  TProfile *pTsum_ev_prof[3][120]; //  selftracking: time sum vs. event#, profile
  
  TH2S *pStart_time_strip; // start detector: strip# vs. time
  TH1F *pStart_time[9]; // start detector: time, incl. cut1 and strip-mult=1
  TH1F *pStart_mult; // start detector:strip multiplicity
  
  TH3F *pCorrSector; // Correlations in a given sector
  TH1F *pCorrDiff[2][4]; // residuals from correlation in one sector
  
  TFile *fout; // output file pointer
  
 public:
  HMdcSelfTracking();
  HMdcSelfTracking(const Text_t* name,const Text_t* title);
  ~HMdcSelfTracking();
  Bool_t init(void);
  Bool_t finalize(void);
  Int_t execute();
  
  void setOutputRoot (const Char_t*);
  void setActiveModule (Int_t sec,Int_t mod){setsector=sec;setmodule=mod;} // only this module will be analyzed
  void setNoStart() {noStart=kTRUE;}
  void setNoCorrSector() {noCorrSector=kTRUE;}
  void setNoCheckCorrSector() {noCheckCorrSector=kTRUE;}
  
  Bool_t setCutbridge(UInt_t, Bool_t);
  Bool_t getCutbridge(UInt_t index);
  void clearCutbridges(void){for (Int_t i=0; i < HMDCSELFTRACKING_CUTBRIDGE_NUMBER; i++) setCutbridge(i,kFALSE);}// set all cutbridges to 0
  void printCutbridge(void);
  
  Bool_t setStartTimeCutWindow(UInt_t, Float_t, Float_t);
  Bool_t setStartTimeCutMax(UInt_t, Float_t);
  Bool_t setStartTimeCutMin(UInt_t, Float_t);
  Float_t getStartTimeCutMax(UInt_t);
  Float_t getStartTimeCutMin(UInt_t);
  void printStartTimeCutWindow(void);
  
  void setTimeCutWindow(Float_t min, Float_t max){setTimeCutMin(min);setTimeCutMax(max);return;} // values in ns
  void setTimeCutMax(Float_t f){tmax = f; return;} // values in ns
  void setTimeCutMin(Float_t f){tmin = f; return;} // values in ns
  Float_t getTimeCutMax(){return tmax;} // values in ns
  Float_t getTimeCutMin(){return tmin;} // values in ns
  void printTimeCutWindow(void);
  
/*   void setTimeAboveThresholdCutWindow(Float_t a, Float_t b){setTimeAboveThresholdCutMin(a);setTimeAboveThresholdCutMax(b);return;} // values in ns */
/*   void setTimeAboveThresholdCutMax(Float_t f){tdifmax = f; return;} // values in ns */
/*   void setTimeAboveThresholdCutMin(Float_t f){tdifmin = f; return;} // values in ns */
/*   Float_t getTimeAboveThresholdCutMax(){return tdifmax;} // values in ns */
/*   Float_t getTimeAboveThresholdCutMin(){return tdifmin;} // values in ns */
/*   void printTimeAboveThresholdCutWindow(void); */

  void setTimeAboveThresholdCutWindow(Int_t i, Float_t a, Float_t b){setTimeAboveThresholdCutMin(i,a);setTimeAboveThresholdCutMax(i,b);return;} // values in ns
  void setTimeAboveThresholdCutMax(Int_t i, Float_t f){tdifmax[i] = f; return;} // values in ns
  void setTimeAboveThresholdCutMin(Int_t i, Float_t f){tdifmin[i] = f; return;} // values in ns
  Float_t getTimeAboveThresholdCutMax(Int_t i){return tdifmax[i];} // values in ns
  Float_t getTimeAboveThresholdCutMin(Int_t i){return tdifmin[i];} // values in ns
  void printTimeAboveThresholdCutWindow(void);

  void setCorrelationFct(Int_t i, Float_t a, Float_t b, Float_t c){setCorrelationFctA(i,a);setCorrelationFctB(i,b);setCorrelationFctC(i,c);return;}
  void setCorrelationFctA(Int_t i, Float_t f){A[i] = f; return;} 
  void setCorrelationFctB(Int_t i, Float_t f){B[i] = f; return;} 
  void setCorrelationFctC(Int_t i, Float_t f){C[i] = f; return;} 
  Float_t getCorrelationFctA(Int_t i){return A[i];} 
  Float_t getCorrelationFctB(Int_t i){return B[i];} 
  Float_t getCorrelationFctC(Int_t i){return C[i];} 
  void printCorrelationFct(void);

  void setCorrelationWindow(Int_t i, Float_t a, Float_t b){setCorrelationWmin(i,a);setCorrelationWmax(i,b);return;}
  void setCorrelationWmin(Int_t i, Float_t f){CorrWindow[i][1] = f; return;} 
  void setCorrelationWmax(Int_t i, Float_t f){CorrWindow[i][2] = f; return;} 
  Float_t getCorrelationWmin(Int_t i){return CorrWindow[i][1];} 
  Float_t getCorrelationWmax(Int_t i){return CorrWindow[i][2];} 
  void printCorrelationWindow(void);
 
  void setAnalysisCellCutWindow(UInt_t a, UInt_t b){setAnalysisCellCutMin(a);setAnalysisCellCutMax(b);return;}
  void setAnalysisCellCutMax(UInt_t f){cellmax = f; return;}
  void setAnalysisCellCutMin(UInt_t f){cellmin = f; return;}
  UInt_t getAnalysisCellCutMax(){return cellmax;}
  UInt_t getAnalysisCellCutMin(){return cellmin;}
  void printAnalysisCellCutWindow(void);
  
  void setTimeDiffL3L4Cut(Float_t f){tdifcut = f; return;} // values in ns
  Float_t getTimeDiffL3L4Cut(){return tdifcut;} // values in ns
  void printTimeDiffL3L4Cut();

  void  setMonitor(UInt_t layer, UInt_t cellNumber){setMonitorCell(cellNumber);setMonitorLayer(layer);return;}
  void  setMonitorCell(UInt_t cell){monitorCell=(Int_t)cell;return;}
  Int_t getMonitorCell(){return monitorCell;}
  void  setMonitorLayer(UInt_t layer){monitorLayer=(Int_t)layer;return;}
  Int_t getMonitorLayer(){return monitorLayer;}

  void setTimeDiffMax(Float_t time){timeDiffMax = time;return;}
  Float_t getTimeDiffMax(){return timeDiffMax;}

protected:
  void createHist();
  void resetCounters();
  void fillControlHists();
  void fillHist  ();
  void fillAnalysisHists(Int_t);
  void checkAdjacentCellAnalysisLayer1(Int_t, Int_t);
  void checkAdjacentCellAnalysisLayer2(Int_t, Int_t);
  void findCorrelatedHits(Int_t);
  void checkCorrSector(Int_t, Int_t);
  void writeHist ();
  void setDefault ();
  void executeStart();
  void executeMdc();
  void executeCorrSector();
  void executeEventHeaderCheck();
  void executeReset();
  
 public: // This has to be placed at the end (--> root dox)
  ClassDef(HMdcSelfTracking, 0)  // class for the MDC 0deg-layer's self tracking
    };
    
#endif

 hmdcselftracking.h:1
 hmdcselftracking.h:2
 hmdcselftracking.h:3
 hmdcselftracking.h:4
 hmdcselftracking.h:5
 hmdcselftracking.h:6
 hmdcselftracking.h:7
 hmdcselftracking.h:8
 hmdcselftracking.h:9
 hmdcselftracking.h:10
 hmdcselftracking.h:11
 hmdcselftracking.h:12
 hmdcselftracking.h:13
 hmdcselftracking.h:14
 hmdcselftracking.h:15
 hmdcselftracking.h:16
 hmdcselftracking.h:17
 hmdcselftracking.h:18
 hmdcselftracking.h:19
 hmdcselftracking.h:20
 hmdcselftracking.h:21
 hmdcselftracking.h:22
 hmdcselftracking.h:23
 hmdcselftracking.h:24
 hmdcselftracking.h:25
 hmdcselftracking.h:26
 hmdcselftracking.h:27
 hmdcselftracking.h:28
 hmdcselftracking.h:29
 hmdcselftracking.h:30
 hmdcselftracking.h:31
 hmdcselftracking.h:32
 hmdcselftracking.h:33
 hmdcselftracking.h:34
 hmdcselftracking.h:35
 hmdcselftracking.h:36
 hmdcselftracking.h:37
 hmdcselftracking.h:38
 hmdcselftracking.h:39
 hmdcselftracking.h:40
 hmdcselftracking.h:41
 hmdcselftracking.h:42
 hmdcselftracking.h:43
 hmdcselftracking.h:44
 hmdcselftracking.h:45
 hmdcselftracking.h:46
 hmdcselftracking.h:47
 hmdcselftracking.h:48
 hmdcselftracking.h:49
 hmdcselftracking.h:50
 hmdcselftracking.h:51
 hmdcselftracking.h:52
 hmdcselftracking.h:53
 hmdcselftracking.h:54
 hmdcselftracking.h:55
 hmdcselftracking.h:56
 hmdcselftracking.h:57
 hmdcselftracking.h:58
 hmdcselftracking.h:59
 hmdcselftracking.h:60
 hmdcselftracking.h:61
 hmdcselftracking.h:62
 hmdcselftracking.h:63
 hmdcselftracking.h:64
 hmdcselftracking.h:65
 hmdcselftracking.h:66
 hmdcselftracking.h:67
 hmdcselftracking.h:68
 hmdcselftracking.h:69
 hmdcselftracking.h:70
 hmdcselftracking.h:71
 hmdcselftracking.h:72
 hmdcselftracking.h:73
 hmdcselftracking.h:74
 hmdcselftracking.h:75
 hmdcselftracking.h:76
 hmdcselftracking.h:77
 hmdcselftracking.h:78
 hmdcselftracking.h:79
 hmdcselftracking.h:80
 hmdcselftracking.h:81
 hmdcselftracking.h:82
 hmdcselftracking.h:83
 hmdcselftracking.h:84
 hmdcselftracking.h:85
 hmdcselftracking.h:86
 hmdcselftracking.h:87
 hmdcselftracking.h:88
 hmdcselftracking.h:89
 hmdcselftracking.h:90
 hmdcselftracking.h:91
 hmdcselftracking.h:92
 hmdcselftracking.h:93
 hmdcselftracking.h:94
 hmdcselftracking.h:95
 hmdcselftracking.h:96
 hmdcselftracking.h:97
 hmdcselftracking.h:98
 hmdcselftracking.h:99
 hmdcselftracking.h:100
 hmdcselftracking.h:101
 hmdcselftracking.h:102
 hmdcselftracking.h:103
 hmdcselftracking.h:104
 hmdcselftracking.h:105
 hmdcselftracking.h:106
 hmdcselftracking.h:107
 hmdcselftracking.h:108
 hmdcselftracking.h:109
 hmdcselftracking.h:110
 hmdcselftracking.h:111
 hmdcselftracking.h:112
 hmdcselftracking.h:113
 hmdcselftracking.h:114
 hmdcselftracking.h:115
 hmdcselftracking.h:116
 hmdcselftracking.h:117
 hmdcselftracking.h:118
 hmdcselftracking.h:119
 hmdcselftracking.h:120
 hmdcselftracking.h:121
 hmdcselftracking.h:122
 hmdcselftracking.h:123
 hmdcselftracking.h:124
 hmdcselftracking.h:125
 hmdcselftracking.h:126
 hmdcselftracking.h:127
 hmdcselftracking.h:128
 hmdcselftracking.h:129
 hmdcselftracking.h:130
 hmdcselftracking.h:131
 hmdcselftracking.h:132
 hmdcselftracking.h:133
 hmdcselftracking.h:134
 hmdcselftracking.h:135
 hmdcselftracking.h:136
 hmdcselftracking.h:137
 hmdcselftracking.h:138
 hmdcselftracking.h:139
 hmdcselftracking.h:140
 hmdcselftracking.h:141
 hmdcselftracking.h:142
 hmdcselftracking.h:143
 hmdcselftracking.h:144
 hmdcselftracking.h:145
 hmdcselftracking.h:146
 hmdcselftracking.h:147
 hmdcselftracking.h:148
 hmdcselftracking.h:149
 hmdcselftracking.h:150
 hmdcselftracking.h:151
 hmdcselftracking.h:152
 hmdcselftracking.h:153
 hmdcselftracking.h:154
 hmdcselftracking.h:155
 hmdcselftracking.h:156
 hmdcselftracking.h:157
 hmdcselftracking.h:158
 hmdcselftracking.h:159
 hmdcselftracking.h:160
 hmdcselftracking.h:161
 hmdcselftracking.h:162
 hmdcselftracking.h:163
 hmdcselftracking.h:164
 hmdcselftracking.h:165
 hmdcselftracking.h:166
 hmdcselftracking.h:167
 hmdcselftracking.h:168
 hmdcselftracking.h:169
 hmdcselftracking.h:170
 hmdcselftracking.h:171
 hmdcselftracking.h:172
 hmdcselftracking.h:173
 hmdcselftracking.h:174
 hmdcselftracking.h:175
 hmdcselftracking.h:176
 hmdcselftracking.h:177
 hmdcselftracking.h:178
 hmdcselftracking.h:179
 hmdcselftracking.h:180
 hmdcselftracking.h:181
 hmdcselftracking.h:182
 hmdcselftracking.h:183
 hmdcselftracking.h:184
 hmdcselftracking.h:185
 hmdcselftracking.h:186
 hmdcselftracking.h:187
 hmdcselftracking.h:188
 hmdcselftracking.h:189
 hmdcselftracking.h:190
 hmdcselftracking.h:191
 hmdcselftracking.h:192
 hmdcselftracking.h:193
 hmdcselftracking.h:194
 hmdcselftracking.h:195
 hmdcselftracking.h:196
 hmdcselftracking.h:197
 hmdcselftracking.h:198
 hmdcselftracking.h:199
 hmdcselftracking.h:200
 hmdcselftracking.h:201
 hmdcselftracking.h:202
 hmdcselftracking.h:203
 hmdcselftracking.h:204
 hmdcselftracking.h:205
 hmdcselftracking.h:206
 hmdcselftracking.h:207
 hmdcselftracking.h:208
 hmdcselftracking.h:209
 hmdcselftracking.h:210
 hmdcselftracking.h:211
 hmdcselftracking.h:212
 hmdcselftracking.h:213
 hmdcselftracking.h:214
 hmdcselftracking.h:215
 hmdcselftracking.h:216
 hmdcselftracking.h:217
 hmdcselftracking.h:218
 hmdcselftracking.h:219
 hmdcselftracking.h:220
 hmdcselftracking.h:221
 hmdcselftracking.h:222
 hmdcselftracking.h:223
 hmdcselftracking.h:224
 hmdcselftracking.h:225
 hmdcselftracking.h:226
 hmdcselftracking.h:227
 hmdcselftracking.h:228
 hmdcselftracking.h:229
 hmdcselftracking.h:230
 hmdcselftracking.h:231
 hmdcselftracking.h:232
 hmdcselftracking.h:233
 hmdcselftracking.h:234
 hmdcselftracking.h:235
 hmdcselftracking.h:236
 hmdcselftracking.h:237
 hmdcselftracking.h:238
 hmdcselftracking.h:239
 hmdcselftracking.h:240
 hmdcselftracking.h:241
 hmdcselftracking.h:242
 hmdcselftracking.h:243
 hmdcselftracking.h:244
 hmdcselftracking.h:245
 hmdcselftracking.h:246
 hmdcselftracking.h:247
 hmdcselftracking.h:248
 hmdcselftracking.h:249
 hmdcselftracking.h:250
 hmdcselftracking.h:251
 hmdcselftracking.h:252
 hmdcselftracking.h:253
 hmdcselftracking.h:254
 hmdcselftracking.h:255
 hmdcselftracking.h:256
 hmdcselftracking.h:257
 hmdcselftracking.h:258
 hmdcselftracking.h:259
 hmdcselftracking.h:260
 hmdcselftracking.h:261
 hmdcselftracking.h:262
 hmdcselftracking.h:263
 hmdcselftracking.h:264
 hmdcselftracking.h:265
 hmdcselftracking.h:266
 hmdcselftracking.h:267
 hmdcselftracking.h:268
 hmdcselftracking.h:269
 hmdcselftracking.h:270
 hmdcselftracking.h:271
 hmdcselftracking.h:272
 hmdcselftracking.h:273
 hmdcselftracking.h:274
 hmdcselftracking.h:275
 hmdcselftracking.h:276
 hmdcselftracking.h:277
 hmdcselftracking.h:278
 hmdcselftracking.h:279
 hmdcselftracking.h:280
 hmdcselftracking.h:281