StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StTpcHitMoverMaker.cxx
1 #include "StTpcHitMoverMaker.h"
2 #include "StTpcDb/StTpcDb.h"
3 #include "StMessMgr.h"
4 #include "StDbUtilities/StMagUtilities.h"
5 #include "StDbUtilities/StTpcCoordinateTransform.hh"
6 #include "StEventTypes.h"
7 #ifdef __CORRECT_CHARGE__
8 #include "StDetectorDbMaker/St_tss_tssparC.h"
9 #endif /* __CORRECT_CHARGE__ */
10 #include "StDetectorDbMaker/St_tpcSlewingC.h"
11 #include "StDetectorDbMaker/St_tpcPadConfigC.h"
12 #include "StDetectorDbMaker/St_tpcEffectiveGeomC.h"
13 #include "StDetectorDbMaker/St_tpcTimeBucketCorC.h"
14 #include "StDetectorDbMaker/St_spaceChargeCorC.h"
15 #include "StDetectorDbMaker/St_tpcChargeEventC.h"
16 #include "StDetectorDbMaker/St_tpcBXT0CorrEPDC.h"
17 #include "StEventUtilities/StEbyET0.h"
18 #include "TMath.h"
19 ClassImp(StTpcHitMover)
20 #define __DEBUG__
21 #ifdef __DEBUG__
22 #define PrPP(A,B) if (_debug %10 > 1) {LOG_INFO << "StTpcHitMover::" << (#A) << "\t" << (#B) << " = \t" << (B) << endm;}
23 #else
24 #define PrPP(A,B)
25 #endif
26 StTpcCoordinateTransform *StTpcHitMover::mTpcTransForm = 0;
27 Int_t StTpcHitMover::_debug = 0;
28 //________________________________________________________________________________
29 StTpcHitMover::StTpcHitMover(const Char_t *name) : StMaker(name) {
30  gMessMgr->Info("StTpcHitMover::StTpcHitMover: constructor called");
31 }
32 //________________________________________________________________________________
33 StTpcHitMover::~StTpcHitMover() {
34  FlushDB();
35 }
36 //________________________________________________________________________________
37 Int_t StTpcHitMover::Init() {
38  return StMaker::Init();
39 }
40 //________________________________________________________________________________
41 Int_t StTpcHitMover::InitRun(Int_t runnumber) {
42  FlushDB();
43  return kStOk;
44 }
45 //________________________________________________________________________________
46 void StTpcHitMover::FlushDB() {
47  SafeDelete(mTpcTransForm);
48 }
49 //________________________________________________________________________________
51  if (StMagUtilities::Instance() && StMagUtilities::Instance()->GetSpaceChargeMode() &&
52  St_spaceChargeCorR2C::instance()->IsMarked()) {
53  gMessMgr->Error() << "StTpcHitMover::Make questionable hit corrections" << endm;
54  return kStSkip;
55  }
56  static StGlobalCoordinate coorG;
57  Bool_t EmbeddingShortCut = IAttr("EmbeddingShortCut");
58  StEvent* pEvent = dynamic_cast<StEvent*> (GetInputDS("StEvent"));
59  if (! pEvent) {
60  LOG_WARN << "StTpcHitMover::Make there is no StEvent " << endm;
61  return kStWarn;
62  }
63 
64 
65 // EPD (or other trigger detector) based event-by-event correction for the hit timing
66  double mTimeBinWidth = 1./StTpcDb::instance()->Electronics()->samplingFrequency();
67  // StEbyET0 returns microsec, will need it in time buckets
68  double ebyeT0 = (IAttr("EbyET0") ? StEbyET0::Instance()->getT0(pEvent) / mTimeBinWidth : 0);
69 
70  int ew = 0;
71  int TAC = 0;
72  int maxTAC = -1;
73 
74  int doEPDT0Correction = StTpcBXT0CorrEPDC::instance()->nrows();
75 
76  if (doEPDT0Correction) {
77  StEpdCollection * epdCol = pEvent->epdCollection();
78  if (epdCol) {
79  StSPtrVecEpdHit &epdHits = epdCol->epdHits();
80  int nEpdHits = epdHits.size();
81 
82  for(int i = 0; i < nEpdHits; i++) {
83  StEpdHit * epdHit = dynamic_cast<StEpdHit*>(epdHits[i]);
84  TAC = 0;
85  if (epdHit->tile() > 9) continue; // only tiles 1 - 9 have timing info
86  if (epdHit->id() < 0) ew = -1; // tile is on the east
87  else ew = 1;
88  if (epdHit->adc() < 100) continue;
89  TAC = epdHit->tac(); // this is the timing
90  if (TAC > maxTAC) maxTAC = TAC;
91  }
92  }
93  }
94 // ======================================================
95 
96  gMessMgr->Info() << "StTpcHitMover::Make use StEvent " << endm;
97  if (! gStTpcDb) {
98  gMessMgr->Error() << "StTpcHitMover::Make TpcDb has not been instantiated " << endm;
99  return kStErr;
100  }
101  if (pEvent && StMagUtilities::Instance() && StMagUtilities::Instance()->UsingDistortion(kAbortGap)) {
102  StTriggerData* trg = pEvent->triggerData();
103  if (trg) St_tpcChargeEventC::instance()->findChargeTimes(trg->bunchCounter());
104  }
105  if (! mTpcTransForm) mTpcTransForm = new StTpcCoordinateTransform(gStTpcDb);
106  StTpcCoordinateTransform &transform = *mTpcTransForm;
107  StTpcHitCollection* TpcHitCollection = pEvent->tpcHitCollection();
108 #ifdef __CORRECT_CHARGE__
109  St_tss_tssparC *tsspar = St_tss_tssparC::instance();
110  Double_t gains[2] = {
111  tsspar->gain_in() / tsspar->wire_coupling_in() *tsspar->ave_ion_pot() *tsspar->scale(),
112  tsspar->gain_out()/ tsspar->wire_coupling_out()*tsspar->ave_ion_pot() *tsspar->scale()
113  };
114 #endif /* __CORRECT_CHARGE__ */
115  if (TpcHitCollection) {
116  UInt_t numberOfSectors = TpcHitCollection->numberOfSectors();
117  for (UInt_t i = 0; i< numberOfSectors; i++) {
118  StTpcSectorHitCollection* sectorCollection = TpcHitCollection->sector(i);
119  if (sectorCollection) {
120  Int_t sector = i + 1;
121 
122  double driftVelocity = StTpcDb::instance()->DriftVelocity(sector);
123 
124  Int_t numberOfPadrows = sectorCollection->numberOfPadrows();
125  for (int j = 0; j< numberOfPadrows; j++) {
126  Int_t row = j + 1;
127  Int_t io = 0;
128  if (row > St_tpcPadConfigC::instance()->innerPadRows(sector)) io = 1;
129  Double_t padlength = (io == 0) ?
130  St_tpcPadConfigC::instance()->innerSectorPadLength(sector) :
131  St_tpcPadConfigC::instance()->outerSectorPadLength(sector);
132  StTpcPadrowHitCollection *rowCollection = sectorCollection->padrow(j);
133  if (rowCollection) {
134  StSPtrVecTpcHit &hits = rowCollection->hits();
135  UInt_t NoHits = hits.size();
136  if (NoHits) {
137  for (UInt_t k = 0; k < NoHits; k++) {
138  StTpcHit *tpcHit = static_cast<StTpcHit *> (hits[k]);
139 #ifdef __CORRECT_CHARGE__
140  Double_t q = tpcHit->charge();
141  PrPP(Make,*tpcHit);
142  if (tpcHit->adc()) { // correct charge
143  q = gains[io] * ((Double_t) tpcHit->adc());
144  }
145 #endif /* __CORRECT_CHARGE__ */
146  if (EmbeddingShortCut && tpcHit->idTruth() && tpcHit->idTruth() < 10000 &&
147  tpcHit->qaTruth() > 95) {
148  continue; // don't move embedded hits
149  }
150  if (! tpcHit->pad() && ! tpcHit->timeBucket()) {// old style, no pad and timeBucket set
151  StTpcLocalCoordinate coorL(tpcHit->position().x(),tpcHit->position().y(),tpcHit->position().z(),i+1,j+1);
152  moveTpcHit(coorL,coorG);
153  StThreeVectorF xyzF(coorG.position().x(),coorG.position().y(),coorG.position().z());
154  tpcHit->setPosition(xyzF);
155  } else { // transoform from original pad and time bucket measurements
156  Float_t pad = tpcHit->pad();
157  Float_t time = tpcHit->timeBucket();
158  if (! StTpcDb::IsOldScheme()) {
159  if (St_tpcTimeBucketCorC::instance()->getNumRows()) {
160  Int_t io = 0;
161  if (row <= St_tpcPadConfigC::instance()->innerPadRows(sector)) io = 1;
162  Double_t noTmbks = tpcHit->maxTmbk() - tpcHit->minTmbk() + 1;
163  time += St_tpcTimeBucketCorC::instance()->CalcCorrection(io, noTmbks);
164  }
165  }
166 // THIS IS A BLOCK TO CORRECT TIMING IN FXT MODE FOR DATA
167  if (doEPDT0Correction) time += StTpcBXT0CorrEPDC::instance()->getCorrection(maxTAC, driftVelocity, mTimeBinWidth);
168  time += ebyeT0;
169 // ======================================================
170 
171  StTpcPadCoordinate padcoord(sector, row, pad, time);
173  transform(padcoord,coorS,kFALSE);
174  StTpcLocalCoordinate coorL;
175  Double_t y = coorS.position().y();
176  for (Int_t l = 0; l < 3; l++) {// center, upper and lower
177  if (l == 1) coorS.position().setY(y + padlength/2);
178  else if (l == 2) coorS.position().setY(y - padlength/2);
179  transform(coorS,coorL);
180  moveTpcHit(coorL,coorG);
181  StThreeVectorF xyzF(coorG.position().x(),coorG.position().y(),coorG.position().z());
182  if (l == 1) tpcHit->setPositionU(xyzF);
183  else if (l == 2) tpcHit->setPositionL(xyzF);
184  else tpcHit->setPosition (xyzF);
185  }
186  }
187  }
188  }
189  }
190  }
191  }
192  }
193  }
194  if (StMagUtilities::Instance()) {
195  pEvent->runInfo()->setSpaceCharge(StMagUtilities::Instance()->CurrentSpaceChargeR2());
196  pEvent->runInfo()->setSpaceChargeCorrectionMode(StMagUtilities::Instance()->GetSpaceChargeMode());
197  }
198  return kStOK;
199 }
200 //________________________________________________________________________________
201 void StTpcHitMover::moveTpcHit(StTpcLocalCoordinate &coorL,StTpcLocalCoordinate &coorLTD) {
202  coorLTD = coorL; // distortions
203  Float_t pos[3] = {(Float_t) coorLTD.position().x(), (Float_t) coorLTD.position().y(), (Float_t) coorLTD.position().z()};
204  if ( StMagUtilities::Instance() ) {
205  Float_t posMoved[3];
206  StMagUtilities::Instance()->UndoDistortion(pos,posMoved,coorL.fromSector()); // input pos[], returns posMoved[]
207  StThreeVector<double> newPos(posMoved[0],posMoved[1],posMoved[2]);
208  coorLTD.setPosition(newPos);
209  }
210 }
211 //________________________________________________________________________________
212 void StTpcHitMover::moveTpcHit(StTpcLocalCoordinate &coorL,StGlobalCoordinate &coorG) {
213  if (! mTpcTransForm) mTpcTransForm = new StTpcCoordinateTransform(gStTpcDb);
214  StTpcCoordinateTransform &transform = *mTpcTransForm;
215  static StTpcLocalCoordinate coorLTD;
216  moveTpcHit(coorL,coorLTD);
217  transform(coorLTD,coorG); PrPP(moveTpcHit,coorLTD); PrPP(moveTpcHit,coorG);
218 }
219 // $Id: StTpcHitMoverMaker.cxx,v 1.34 2021/04/02 04:09:26 genevb Exp $
220 // $Log: StTpcHitMoverMaker.cxx,v $
221 // Revision 1.34 2021/04/02 04:09:26 genevb
222 // Event-by-event T0 needs converted to time buckets
223 //
224 // Revision 1.33 2021/03/19 01:44:48 genevb
225 // Introduce Event-by-Event T0 corrections
226 //
227 // Revision 1.32 2019/11/14 23:07:48 iraklic
228 // added timebucket and drift velocity into epd-based T0 correction calculation
229 //
230 // Revision 1.30 2019/04/22 20:47:16 genevb
231 // Introducing codes for AbortGapCleaning distortion corrections
232 //
233 // Revision 1.29 2018/06/07 04:48:28 genevb
234 // Explicit include for spaceChargeCor needed
235 //
236 // Revision 1.28 2018/04/11 02:43:22 smirnovd
237 // Enable TPC/iTPC switch via St_tpcPadConfig
238 //
239 // This is accomplished by substituting St_tpcPadPlanes with St_tpcPadConfig.
240 // A sector ID is passed to St_tpcPadConfig in order to extract parameters for
241 // either TPC or iTPC
242 //
243 // Revision 1.27 2014/07/27 13:23:09 fisyak
244 // Add cast for c++11 option
245 //
246 // Revision 1.26 2014/06/27 14:45:51 fisyak
247 // Add swith between new and old schema, clean up
248 //
249 // Revision 1.25 2014/06/26 21:32:25 fisyak
250 // New Tpc Alignment, v632
251 //
252 // Revision 1.24 2014/01/28 17:10:39 genevb
253 // Fill otherwise empty SpaceCharge info in StRunInfo
254 //
255 // Revision 1.23 2014/01/08 21:14:28 fisyak
256 // Add transformations for Upper and Lower tpc hits postions (new dX calculation in dE/dx)
257 //
StTpcHitMoverMaker - implements corrections on TPC hits.
virtual Int_t Make()
int adc() const
ADC value [0,4095].
Definition: StEpdHit.h:149
Definition: Stypes.h:49
Stores information for tiles in STAR Event Plane Detector.
Definition: StEpdHit.h:43
Definition: Stypes.h:42
Definition: Stypes.h:40
int tile() const
tile on the supersector [1,31]
Definition: StEpdHit.h:148
Definition: Stypes.h:44
short id() const
Definition: StEpdHit.h:146
Definition: Stypes.h:41
int tac() const
TAC value [0,4095].
Definition: StEpdHit.h:150