StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFcsDb.h
1 /***************************************************************************
2  * $Id: StFcsDb.h,v 1.3 2021/05/27 14:02:23 akio Exp $
3  * \author: akio ogawa
4  ***************************************************************************
5  *
6  * Description: FCS DB Utility
7  *
8  ***************************************************************************
9  *
10  * $Log: StFcsDb.h,v $
11  * Revision 1.3 2021/05/27 14:02:23 akio
12  * clean up Clear and fixGain/corr
13  *
14  * Revision 1.2 2021/04/09 15:11:18 akio
15  * Adding projection of Hcal local position to Ecal local position
16  *
17  * Revision 1.1 2021/03/30 13:40:07 akio
18  * FCS code after peer review and moved from $CVSROOT/offline/upgrades/akio
19  *
20  * Revision 1.22 2021/02/25 21:53:50 akio
21  * Int_t -> int
22  *
23  * Revision 1.21 2021/02/24 22:56:19 akio
24  * Modified for STAR code review (Dmitry)
25  *
26  * Revision 1.20 2021/02/23 22:18:23 akio
27  * Modified for STAr code review (Jason)
28  *
29  * Revision 1.19 2021/02/12 20:09:50 akio
30  * Adding getIdfromSCmap()
31  *
32  * Revision 1.18 2021/02/09 21:54:23 akio
33  * Using StEnumeration
34  *
35  * Revision 1.17 2021/02/05 17:23:25 akio
36  * Adding access to STAR offline DB tables.
37  * Adding getFromName/getDetFromName from David.
38  *
39  * Revision 1.16 2021/01/05 18:15:01 akio
40  * added setPedestal()
41  *
42  * Revision 1.15 2020/12/30 20:17:55 akio
43  * adding SC map access
44  *
45  * Revision 1.14 2020/09/03 19:43:20 akio
46  * Updating SC map and adding patchpanel & cable color map
47  *
48  * Revision 1.13 2020/05/29 18:53:40 akio
49  * Adding EPD as PRES maps, STAR coordinate for 4x4 trigger patch, renming map files to be used for DAQ as Tonko specifies
50  *
51  * Revision 1.12 2020/05/04 15:48:22 akio
52  * adding input file for DAQ
53  *
54  * Revision 1.11 2019/10/23 13:34:38 akio
55  * Adding getZDepth, and take out Ecal front space (for SiPM/Fee) from offsets
56  * so that x/z offsets are now pointing to actual ecal tower front & near beam corner.
57  *
58  * Revision 1.10 2019/07/10 06:13:34 akio
59  * Adding reading of gains from text files
60  *
61  * Revision 1.9 2019/07/03 16:18:49 akio
62  * correcting a comment
63  *
64  * Revision 1.8 2019/06/27 16:10:32 akio
65  * adding getLocalXYinCell
66  *
67  * Revision 1.7 2019/06/26 18:03:07 akio
68  * change default to mRun19=0 (futture full FCS)
69  *
70  * Revision 1.6 2019/06/25 16:38:59 akio
71  * Fixed y offset for run19
72  * Added setting run# and time dependent (for preshower yoffset only for now)
73  *
74  * Revision 1.5 2019/06/21 17:28:55 akio
75  * dealing with 5cm offsent when leakyHcal
76  *
77  * Revision 1.4 2019/06/07 18:16:55 akio
78  * *** empty log message ***
79  *
80  * Revision 1.3 2019/03/13 20:46:19 akio
81  * formatting
82  *
83  * Revision 1.2 2019/03/13 20:29:30 akio
84  * update for run19
85  *
86  * Revision 1.1 2018/11/14 16:50:13 akio
87  * FCS codes in offline/upgrade/akio
88  *
89  **************************************************************************/
90 
91 #ifndef STFCSDB_H
92 #define STFCSDB_H
93 
94 #ifndef StMaker_H
95 #include "StMaker.h"
96 #endif
97 #include "StEvent/StEnumerations.h"
98 #include "StThreeVectorD.hh"
99 #include "StLorentzVectorD.hh"
100 #include "tables/St_fcsDetectorPosition_Table.h"
101 #include "tables/St_fcsEcalGain_Table.h"
102 #include "tables/St_fcsHcalGain_Table.h"
103 #include "tables/St_fcsPresGain_Table.h"
104 #include "tables/St_fcsEcalGainCorr_Table.h"
105 #include "tables/St_fcsHcalGainCorr_Table.h"
106 #include "tables/St_fcsPresValley_Table.h"
107 #include "tables/St_fcsEcalGainOnline_Table.h"
108 #include "tables/St_fcsHcalGainOnline_Table.h"
109 #include "tables/St_fcsPresThreshold_Table.h"
110 #include "tables/St_vertexSeed_Table.h"
111 #include "tables/St_g2t_track_Table.h"
112 #include "tables/St_g2t_vertex_Table.h"
113 class StFcsHit;
114 class StFcsCluster;
115 class StFcsPoint;
116 using namespace std;
117 
118 class StFcsDb : public TDataSet {
119 
120 public:
121  StFcsDb(const char *name="fcsDb");
122  virtual ~StFcsDb();
123  int Init();
124  int InitRun(int runNumber);
125 
126  void setDebug(int v=1) {mDebug=v;}
127  void setDbAccess(int v=1);
128  void setRun(int run);
129  void setRun19(int v=1);
130  void setLeakyHcal(int v=1);
131  void setEtGainMode(int v=0) {mEtGainMode=v;}
132 
134  void setFcsDetectorPosition(fcsDetectorPosition_st* t);
135  void setFcsEcalGain(fcsEcalGain_st*);
136  void setFcsHcalGain(fcsHcalGain_st*);
137  void setFcsPresGain(fcsPresGain_st*);
138  void setFcsEcalGainCorr(fcsEcalGainCorr_st*);
139  void setFcsHcalGainCorr(fcsHcalGainCorr_st*);
140  void setFcsPresValley(fcsPresValley_st*);
141  void setFcsEcalGainOnline(fcsEcalGainOnline_st*);
142  void setFcsHcalGainOnline(fcsHcalGainOnline_st*);
143  void setFcsPresThreshold(fcsPresThreshold_st*);
144 
146  int maxDetectorId() const;
147  int detectorId(int eh, int ns) const;
148  int ecalHcalPres(int det) const;
149  int northSouth(int det) const;
150  int nRow(int det) const;
151  int nColumn(int det) const;
152  int maxId(int det) const;
153  int getRowNumber(int det, int id) const;
154  int getColumnNumber(int det, int id) const ;
155  int getId(int det, int row, int col) const ;
156  int getDepCh(int dep, int ch) const ;
157  void getName(int det, int id, char name[]);
158  void getName(int ehp, int ns, int dep, int ch, char name[]);
159  static void getFromName(const char name[], int& det, int& id);
160  static int getDetFromName(const std::string& detname);
161  static unsigned short getKey(unsigned short detid, unsigned short id);//This key matches the 'mDetId' in StFcsHit but without "zs" value (@[June 21, 2022](David Kapukchyan)>Move static method to StFcsHit?)
162  static void getDetIdFromKey(unsigned short key, unsigned short& detid, unsigned short& id);
163  static unsigned short getDetFromKey(unsigned short key);
164  static unsigned short getIdFromKey(unsigned short key);
165 
167 
174  StThreeVectorD getDetectorOffset(int det, double zdepth=-1) const;
175  StThreeVectorD getNormal(int det) const;
176  float getDetectorAngle(int det) const;
177  float getXWidth(int det) const;
178  float getYWidth(int det) const;
179 
180  float getZDepth(int det) const; // z depth of active detector
181  float getShowerMaxZ(int det) const; // default z[cm] from front face for where it measure x/y (shower max)
182 
184  void getLocalXYinCell(StFcsHit* hit, float &x, float &y) const;
185  void getLocalXYinCell(int det, int id, float &x, float &y) const;
186  void getLocalXYinCell(int det, int col, int row, float &x, float &y) const;
187 
189  StThreeVectorD getStarXYZ(int det,float FcsX, float FcsY, float FcsZ=-1.0, float zVertex=0.0) const;
191  float getPhi(int det,float FcsX, float FcsY, float FcsZ=-1.0) const;
193  float getEta(int det,float FcsX, float FcsY, float FcsZ=-1.0, float zVertex=0.0) const;
194 
196  StThreeVectorD getStarXYZfromColumnRow(int det,float col, float row, float FcsZ=-1.0) const; //from column/row[cell size unit]
197  StThreeVectorD getStarXYZ(int det, int col, int row, float FcsZ=-1.0) const; //from column/row [cell unit]
198  StThreeVectorD getStarXYZ(const StFcsHit* hit, float FcsZ=-1.0) const; //from StFcsHit
199  StThreeVectorD getStarXYZ(const StFcsCluster* clu, float FcsZ=-1.0) const; //from StFcsCluster
200  StThreeVectorD getStarXYZ(int det, int id, float FcsZ=-1.0) const; //center of the cell
201 
203  StThreeVectorD getStarXYZ_4x4(int det,int col, int row) const;
204 
206  StLorentzVectorD getLorentzVector(const StThreeVectorD& xyz, float energy, float zVertex=0.0);
207 
210  double getHcalProjectedToEcalX(int ns, double hcalLocalX, double zvtx=0.0);
211  double getHcalProjectedToEcalY(int ns, double hcalLocalY, double zvtx=0.0);
212  double getProjectedDistance(StFcsCluster* ecal, StFcsCluster* hcal, double zvtx=0.0);
213  double getProjectedDistance(StFcsPoint* ecal, StFcsCluster* hcal, double zvtx=0.0);
214 
216  int getZeroSuppression(int det) const;
217  float getSamplingFraction(int det) const;
218  float getGain(int det, int id) const;
219  float getGain(StFcsHit* hit) const;
220  float getGain8(int det, int id) const;
221  float getGain8(StFcsHit* hit) const;
222  float getGainCorrection(int det, int id) const;
223  float getGainCorrection(StFcsHit* hit) const;
224  float getPresValley(int det, int id) const;
225  float getPresValley(StFcsHit* hit) const;
226  float getGainOnline(int det, int id) const;
227  float getGainOnline(StFcsHit* hit) const;
228  float getPresThreshold(int det, int id) const;
229  float getPresThreshold(StFcsHit* hit) const;
230 
231  enum GAINMODE { FIXED, DB, FORCED, TXT };
232  void forceFixGain() {mGainMode=GAINMODE::FIXED;}
233  void forceFixGainCorrection() {mGainCorrMode=GAINMODE::FIXED;}
234  void forceUniformGain(float ecal, float hcal=0.0053, float pres=0.01){
235  mGainMode=GAINMODE::FORCED;
236  mForceUniformGainEcal=ecal;
237  mForceUniformGainHcal=hcal;
238  mForceUniformGainPres=pres;
239  }
240  void forceUniformGainCorrection(float ecal, float hcal=1.0, float pres=0.5){
241  mGainCorrMode=GAINMODE::FORCED;
242  mForceUniformGainCorrectionEcal=ecal;
243  mForceUniformGainCorrectionHcal=hcal;
244  mForceUniformGainCorrectionPres=pres;
245  }
246  void forceUniformGainOnline(float ecal, float hcal=1.0, float pres=0.5){
247  mGainCorrMode=GAINMODE::FORCED;
248  mForceUniformGainOnlineEcal=ecal;
249  mForceUniformGainOnlineHcal=hcal;
250  mForceUniformGainOnlinePres=pres;
251  }
252 
254  void setReadGainFromText(const char* file="fcsgain.txt") {strcpy(mGainFilename,file); mGainMode=GAINMODE::TXT;}
255  void setReadGainCorrFromText(const char* file="fcsgaincorr.txt") {strcpy(mGainCorrFilename,file); mGainCorrMode=GAINMODE::TXT;}
256 
257  //ETGain factor= 1(ET Match), 0(E Match), 0.5(halfway)
258  float getEtGain(int det, int id, float factor=1.0) const;
259  void printEtGain();
260 
262  void getDepfromId(int detectorId, int id, int &ehp, int &ns, int &crt, int &slt, int &dep, int &ch) const;
263  void getIdfromDep(int ehp, int ns, int dep, int ch, int &detectorId, int &id, int &crt, int &slt) const;
264  int getNDep(int ehp, int ns) const;
265  void getSCmap(int det, int id,
266  int &ehp, int &ns, int &scdep, int &branch, int &fee_i2c, int &sipm,
267  int &pp, int &jacket) const;
268  void getIdfromSCmap(int ehp, int ns, int scdep, int branch, int fee_i2c, int sipm,
269  int &det, int &id) const;
270 
271  void makeMap();
272  void makePPMap();
273  int jacketColor(int ehp, int ns, int dep, int ch);
274  void makeMap2019();
275  void printMap();
276  void printHeader(FILE* f, int flag, int csv);
277  void printHeader2(FILE* f);
278  void printHeader3(FILE* f);
279  void printHeader4(FILE* f, int flag);
280 
281  //EPD as PRES
282  void getIdfromEPD(int pp, int tt, int &det, int &id);
283  void getEPDfromId(int det, int id, int &pp, int &tt);
284 
286  float pedestal(int ehp, int ns, int dep, int ch);
287  void setPedestal(int ehp, int ns, int dep, int ch, float ped);
288  void readPedFromText(const char* file="fcsped.txt");
289 
290  // Tracing back from a given g2t_track_id to primary track's g2t_track_id
291  unsigned int backTraceG2tTrack(unsigned int id, g2t_track_st* g2ttrk);
292 
298  const g2t_track_st* getParentG2tTrack(StFcsHit* h, g2t_track_st* g2ttrk, float& fraction, int& ntrk, unsigned int order=0);
299  const g2t_track_st* getParentG2tTrack(StFcsCluster* c, g2t_track_st* g2ttrk, float& fraction, int& ntrk, unsigned int order=0);
300  const g2t_track_st* getPrimaryG2tTrack(StFcsHit* h, g2t_track_st* g2ttrk, float& fraction, int& ntrk, unsigned int order=0);
301  const g2t_track_st* getPrimaryG2tTrack(StFcsCluster* c, g2t_track_st* g2ttrk, float& fraction, int& ntrk, unsigned int order=0);
302 
303  StThreeVectorD projectTrackToEcal(const g2t_track_st* g2ttrk, const g2t_vertex_st* g2tvert=0) const;
304  StThreeVectorD projectTrackToHcal(const g2t_track_st* g2ttrk, const g2t_vertex_st* g2tvert=0) const;
305  StThreeVectorD projectTrackToEcalSMax(const g2t_track_st* g2ttrk, const g2t_vertex_st* g2tvert=0) const;
306  StThreeVectorD projectTrackToHcalSMax(const g2t_track_st* g2ttrk, const g2t_vertex_st* g2tvert=0) const;
307  StThreeVectorD projectTrack(int det, const g2t_track_st* g2ttrk, const g2t_vertex_st* g2tvert, double showermaxz=-1) const;
308  StThreeVectorD projectLine(int det, StThreeVectorD &linedirection, StThreeVectorD &lineorigin, double showermaxz=-1) const;
309 
320  StThreeVectorD projectLine(int det, double* linedirection, double* lineorigin, double showermaxz=-1) const;
321 
322  private:
323  int mDbAccess=1;
324  int mRun=0;
325  int mDebug=0;
326  int mRun19=0;
327  int mLeakyHcal=0;
328  int mEtGainMode=0;
329 
330  GAINMODE mGainMode = GAINMODE::DB;
331  float mForceUniformGainEcal=-1.0;
332  float mForceUniformGainHcal=-1.0;
333  float mForceUniformGainPres=-1.0;
334  char mGainFilename[256];
335  void readGainFromText();
336 
337  GAINMODE mGainCorrMode = GAINMODE::DB;
338  float mForceUniformGainCorrectionEcal=-1.0;
339  float mForceUniformGainCorrectionHcal=-1.0;
340  float mForceUniformGainCorrectionPres=-1.0;
341  char mGainCorrFilename[256];
342  void readGainCorrFromText();
343 
344  GAINMODE mGainOnlineMode = GAINMODE::DB;
345  float mForceUniformGainOnlineEcal=-1.0;
346  float mForceUniformGainOnlineHcal=-1.0;
347  float mForceUniformGainOnlinePres=-1.0;
348 
349  //DEP sorted ped/gain/corr
350  float mPed[kFcsEHP][kFcsNorthSouth][kFcsMaxDepBd][kFcsMaxDepCh];
351  float mGain[kFcsEHP][kFcsNorthSouth][kFcsMaxDepBd][kFcsMaxDepCh];
352  float mGainCorr[kFcsEHP][kFcsNorthSouth][kFcsMaxDepBd][kFcsMaxDepCh];
353  float mGainOnline[kFcsEHP][kFcsNorthSouth][kFcsMaxDepBd][kFcsMaxDepCh];
354 
355  //Beam line parameters
356  double mVx=0.0;
357  double mVy=0.0;
358  double mVdxdz=0.0;
359  double mVdydz=0.0;
360  double mThetaX=0.0;
361  double mThetaY=0.0;
362 
363  //copy of tables from DB
364  fcsDetectorPosition_st mFcsDetectorPosition;
365  fcsEcalGain_st mFcsEcalGain;
366  fcsHcalGain_st mFcsHcalGain;
367  fcsPresGain_st mFcsPresGain;
368  fcsEcalGainCorr_st mFcsEcalGainCorr;
369  fcsHcalGainCorr_st mFcsHcalGainCorr;
370  fcsPresValley_st mFcsPresValley;
371  fcsEcalGainOnline_st mFcsEcalGainOnline;
372  fcsHcalGainOnline_st mFcsHcalGainOnline;
373  fcsPresThreshold_st mFcsPresThreshold;
374 
377  const g2t_track_st* getG2tTrack(StFcsCluster* c, g2t_track_st* g2ttrk, float& fraction, int& ntrk, unsigned int order=0, int mode=0);
378 
379  virtual const Char_t *GetCVS() const {static const Char_t cvs[]="Tag " __DATE__ " " __TIME__ ; return cvs;}
380 
381  ClassDef(StFcsDb,1) //StAF chain virtual base class for Makers
382 };
383 
384 #endif
385 
386 
void forceUniformGainOnline(float ecal, float hcal=1.0, float pres=0.5)
Definition: StFcsDb.h:246
void forceFixGainCorrection()
fixed default gain
Definition: StFcsDb.h:233
void setReadGainFromText(const char *file="fcsgain.txt")
reading gain from text files
Definition: StFcsDb.h:254
void forceUniformGain(float ecal, float hcal=0.0053, float pres=0.01)
fixed default gaincorr
Definition: StFcsDb.h:234
void setEtGainMode(int v=0)
set leaky Hcal
Definition: StFcsDb.h:131
void forceUniformGainCorrection(float ecal, float hcal=1.0, float pres=0.5)
Definition: StFcsDb.h:240
GAINMODE
get the pres valley position for cut
Definition: StFcsDb.h:231
void forceFixGain()
Gain mode switch.
Definition: StFcsDb.h:232