StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StTpcFastSimMaker.cxx
1 /* $Id: StTpcFastSimMaker.cxx,v 1.12 2018/10/17 20:45:29 fisyak Exp $
2  $Log: StTpcFastSimMaker.cxx,v $
3  Revision 1.12 2018/10/17 20:45:29 fisyak
4  Restore update for Run XVIII dE/dx calibration removed by Gene on 08/07/2018
5 
6  Revision 1.10 2018/06/21 01:47:26 perev
7  iTPCheckIn
8 
9  Revision 1.8.10.1 2018/02/16 22:09:42 perev
10  iTPC
11 
12  Revision 1.8 2014/07/27 13:28:06 fisyak
13  Add cast for c++11 option
14 
15  Revision 1.7 2013/01/28 20:27:25 fisyak
16  Move cluters to global coordinatate system
17 
18  Revision 1.6 2012/12/12 23:53:36 fisyak
19  Clean up, extend no. of pad rows
20 
21  Revision 1.5 2012/05/07 14:54:45 fisyak
22  Add printout
23 
24  Revision 1.4 2011/01/04 21:40:22 fisyak
25  Add pile-up
26 
27  Revision 1.3 2010/08/16 21:59:46 fisyak
28  leave coordinates in TpcLocalCoordinate because StTpcHitMover expects that
29 
30  Revision 1.2 2010/05/28 16:28:44 fisyak
31  Adjust for new TpcDb interface, remove pseudo pad rows
32 
33  Revision 1.1 2009/11/10 21:15:33 fisyak
34  pams clean up
35 
36 */
37 #include "Stiostream.h"
38 #include "StTpcFastSimMaker.h"
39 #include "StHit.h"
40 #include "StEventTypes.h"
41 #include "tables/St_HitError_Table.h"
42 #include "StTpcHitCollection.h"
43 #include "StEvent.h"
44 #include "TMath.h"
45 #include "TRandom.h"
46 #include "StTpcDb/StTpcDb.h"
47 #include "tables/St_g2t_vertex_Table.h"
48 #include "tables/St_g2t_track_Table.h"
49 #include "tables/St_g2t_tpc_hit_Table.h"
50 #include "StDbUtilities/StTpcCoordinateTransform.hh"
51 #include "StDbUtilities/StMagUtilities.h"
52 #include "StTpcDb/StTpcDb.h"
53 #include "TDataSet.h"
54 #include "TDataSetIter.h"
55 #include "StDetectorDbMaker/StiTpcInnerHitErrorCalculator.h"
56 #include "StDetectorDbMaker/StiTpcOuterHitErrorCalculator.h"
57 #include "StDetectorDbMaker/St_tpcPadConfigC.h"
58 ClassImp(StTpcFastSimMaker);
59 //____________________________________________________________
61  static Int_t iBreak = 0;
62  mExB = StMagUtilities::Instance();
63  if (! gRandom) gRandom = new TRandom();
64  // Get the input data structures from StEvent
65  StEvent *rEvent = (StEvent*) GetInputDS("StEvent");
66  if (! rEvent) { LOG_WARN << "No StEvent on input, bye bye" << endm; return kStWarn; }
67  StTpcHitCollection *rCol = rEvent->tpcHitCollection();
68  if (!rCol) {
69  rCol = new StTpcHitCollection;
70  rEvent->setTpcHitCollection(rCol);
71  }
72  St_g2t_tpc_hit *g2t_tpc_hit = (St_g2t_tpc_hit *) GetDataSet("geant/g2t_tpc_hit");
73  if (! g2t_tpc_hit) {
74  LOG_WARN << "No g2t_tpc_hit on input, bye bye" << endm; return kStWarn;
75  }
76  Int_t Nhits = g2t_tpc_hit->GetNRows();
77  if (Nhits <= 0) return kStWarn;
78  St_g2t_track *g2t_track = (St_g2t_track *) GetDataSet("geant/g2t_track"); // if (!g2t_track) return kStWarn;
79  g2t_track_st *tpc_track = 0;
80  if (g2t_track) tpc_track = g2t_track->GetTable();
81  St_g2t_vertex *g2t_ver = (St_g2t_vertex *) GetDataSet("geant/g2t_vertex");// if (!g2t_ver) return kStWarn;
82  g2t_vertex_st *gver = 0;
83  if (g2t_ver) gver = g2t_ver->GetTable();
84  g2t_tpc_hit_st *tpc_hit = g2t_tpc_hit->GetTable();
85  StTpcCoordinateTransform transform(gStTpcDb);
86  for (Int_t i = 0; i < Nhits; i++) {
87  if (tpc_hit[i].volume_id > 100000) continue; // skip pseudo pad rows
88  Int_t Id = tpc_hit[i].track_p;
89  Int_t id3 = 0;
90  if (tpc_track)
91  id3 = tpc_track[Id-1].start_vertex_p;
92  Int_t sector = (tpc_hit[i].volume_id%10000)/100;
93  Int_t row = tpc_hit[i].volume_id%100;
94  StGlobalDirection dirG(tpc_hit[i].p[0],tpc_hit[i].p[1],tpc_hit[i].p[2]);
95  static StTpcLocalSectorDirection dirL;
96  transform(dirG, dirL, sector, row);
97  StGlobalCoordinate coorG(tpc_hit[i].x[0],tpc_hit[i].x[1],tpc_hit[i].x[2]);
98  static StTpcLocalCoordinate coorLT;
99  transform(coorG,coorLT,sector,row);
100  StTpcLocalCoordinate coorLTD = coorLT;
101  // ExB corrections
102  Float_t pos[3] = {(Float_t) coorLTD.position().x(),(Float_t) coorLTD.position().y(),(Float_t) coorLTD.position().z()};
103  Float_t posMoved[3];
104  if ( mExB ) {
105  mExB->DoDistortion(pos,posMoved); // input pos[], returns posMoved[]
106  StThreeVector<double> newPos(posMoved[0],posMoved[1],posMoved[2]);
107  coorLTD.setPosition(newPos);
108  }
109  static StTpcLocalSectorCoordinate coorLS;
110  transform(coorLTD,coorLS); // alignment
111  Double_t xyzL[3] = {coorLS.position().x(),coorLS.position().y(),coorLS.position().z()};
112  if (TMath::Abs(xyzL[1]-transform.yFromRow(sector,row)) > 0.1000) {
113  if (Debug()) {
114  LOG_DEBUG << "Id: " << tpc_hit[i].volume_id
115  << "\txyzL :" << xyzL[0] << "\t" << xyzL[1] << "\t" << xyzL[2]
116  << "\tdR :" << xyzL[1]-transform.yFromRow(sector,row) << endm;
117  }
118  iBreak++;
119  }
120  Double_t Z = xyzL[2];
121  Double_t eta = TMath::PiOver2() - TMath::Abs(dirL.position().phi());
122  Double_t tanl = dirL.position().z()/dirL.position().perp();
123  Double_t sigmaY2, sigmaZ2;
124  if (row <= St_tpcPadConfigC::instance()->innerPadRows(sector))
125  StiTpcInnerHitErrorCalculator::instance()->calculateError(Z,eta,tanl,sigmaY2, sigmaZ2);
126  else
127  StiTpcOuterHitErrorCalculator::instance()->calculateError(Z,eta,tanl,sigmaY2, sigmaZ2);
128  Double_t sigmaY = TMath::Sqrt(sigmaY2);
129  Double_t sigmaZ = TMath::Sqrt(sigmaZ2);
130  StThreeVectorF e(0, sigmaY, sigmaZ);
131  xyzL[0] += gRandom->Gaus(0, sigmaY);
132  xyzL[2] += gRandom->Gaus(0, sigmaZ);
133  StThreeVectorD newPosition(xyzL);
134  coorLS.setPosition(newPosition);
135  static StTpcPadCoordinate Pad;
136  transform(coorLS,Pad,kFALSE,kTRUE); // don't use T0, use Tau
137  Double_t tof = 0;
138  if (gver) tof = gver[id3-1].ge_tof;
139  tof += tpc_hit[i].tof;
140  Float_t timebkt = Pad.timeBucket() + 1.e6*gStTpcDb->Electronics()->samplingFrequency()*tof;
141  if (timebkt < 0 || timebkt > 512) continue;
142  StTpcPadCoordinate newPad(Pad.sector(),Pad.row(), Pad.pad(),timebkt );
143  Short_t pad = newPad.pad();
144  Short_t tmb = newPad.timeBucket();
145  static StGlobalCoordinate global; // StTpcHitMover will not move it because of EmbeddingShortCut flag.
146  transform(newPad,global,kFALSE); // alignment
147  UInt_t hw = 1; // detid_tpc
148  hw += sector << 4; // (row/100 << 4); // sector
149  hw += row << 9; // (row%100 << 9); // row
150  StTpcHit *tpcHit = new StTpcHit(global.position(),e, hw,TMath::Abs(tpc_hit[i].de)// hw, q
151  , 0 // c
152  , tpc_hit[i].track_p, 100 // idTruth, quality
153  , i // id
154  , pad, pad+1,tmb,tmb+1 // mnpad, mxpad, mntmbk, mxtmbk
155  , newPad.pad(), newPad.timeBucket() // mxtmbk, cl_x , cl_t
156  , 0); // Adc
157  if (Debug() > 1) tpcHit->Print();
158  rCol->addHit(tpcHit);
159  }
160  return kStOK;
161 }
Definition: tof.h:15
virtual void calculateError(Double_t _z, Double_t _eta, Double_t _tanl, Double_t &ecross, Double_t &edip, Double_t fudgeFactor=1) const
coeff[6] = 0:intrinsicY 1: driftY 2: crossY 3:intrinsicZ 4: driftZ 5: crossZ
Definition: StiChairs.cxx:7
virtual void DoDistortion(const Float_t x[], Float_t Xprime[], Int_t Sector=-1)
Main Entry Point for requests to DO the E and B field distortions (for simulations) ...
Definition: Stypes.h:42
Definition: Stypes.h:40
virtual Int_t Make()