GEMC  2.3
Geant4 Monte-Carlo Framework
BMT_hitprocess.cc
Go to the documentation of this file.
1 // gemc headers
2 #include "BMT_hitprocess.h"
3 
4 // geant4 headers
5 #include "G4FieldManager.hh"
6 #include "G4Field.hh"
7 
8 
9 static bmtConstants initializeBMTConstants(int runno)
10 {
11  // all these constants should be read from CCDB
12  bmtConstants bmtc;
13  bmtc.runNo = runno;
14 
15  // all dimensions are in mm
16  bmtc.SigmaDrift = 0.4;
17  bmtc.hDrift = 3.0;
18  bmtc.hStrip2Det = bmtc.hDrift/2.;
19  bmtc.changeFieldScale(-1); // this needs to be read from DB
20 
21  if(runno == -1)
22  {
23  cout << " > bmt pre-initizialization. " << endl;
24  return bmtc;
25  }
26 
27  // Z Detectors
28  bmtc.CRZRADIUS[2] = 205.8;
29  bmtc.CRZNSTRIPS[2] = 768;
30  bmtc.CRZSPACING[2] = 0.2;
31  bmtc.CRZWIDTH[2] = 0.328;
32  bmtc.CRZLENGTH[2] = 444.88;
33  bmtc.CRZZMIN[2] = -421.75;
34  bmtc.CRZZMAX[2] = 290.25;
35  bmtc.CRZOFFSET[2] = 252.1;
36  bmtc.CRZXPOS[2] = 10.547;
37 
38  double ZEdge1[bmtc.NREGIONS] = { 30.56*degree, 270.56*degree, 150.56*degree};
39  double ZEdge2[bmtc.NREGIONS] = {149.44*degree, 29.44*degree, 269.44*degree};
40 
41  // Assume the edge boundaries are the same for all regions until get final geometry
42  for (int i = 0; i <bmtc.NREGIONS ; ++i)
43  {
44  for (int j = 0; j <bmtc.NREGIONS ; ++j)
45  {
46  bmtc.CRZEDGE1[i][j] = ZEdge1[j];
47  bmtc.CRZEDGE2[i][j] = ZEdge2[j];
48  }
49  }
50 
51 
52  // C Detectors
53  bmtc.CRCRADIUS[2] = 220.8;
54  bmtc.CRCNSTRIPS[2] = 1152;
55  bmtc.CRCLENGTH[2] = 438.6;
56  bmtc.CRCSPACING[2] = 0.16;
57  bmtc.CRCZMIN[2] = -421.75;
58  bmtc.CRCZMAX[2] = 290.25;
59  bmtc.CRCOFFSET[2] = 252.18;
60 
61  double CEdge1[bmtc.NREGIONS] = { 30.52*degree, 270.52*degree, 150.52*degree};
62  double CEdge2[bmtc.NREGIONS] = { 149.48*degree, 29.48*degree, 269.48*degree};
63 
64  // Assume the edge boundaries are the same for all regions until get final geometry
65  for (int i = 0; i <bmtc.NREGIONS ; ++i)
66  {
67  for (int j = 0; j <bmtc.NREGIONS ; ++j)
68  {
69  bmtc.CRCEDGE1[i][j] = CEdge1[j];
70  bmtc.CRCEDGE2[i][j] = CEdge2[j];
71  }
72  }
73 
74  // pitch CRC --> for the C-detectors, the strips are in bunches of equal pitches
75  double CR4C_width[13]={0.345,0.28,0.225,0.175,0.17,0.21,0.26,0.31,0.37,0.44,0.515,0.605,0.7}; // width of the corresponding group of strips
76  double CR4C_group[13]={32,32,32,32,624,32,32,32,32,32,32,32,896}; // the number of strips with equal pitches
77  // For CR5, no existing value. picked a random value compatible with the geometry
78  double CR5C_width[1]={0.253}; // the number of strips with equal pitches & width of the corresponding group of strips
79  double CR5C_group[1]={1024};
80  // For CR6 the numbers are final and should not be changed
81  double CR6C_width[14]={0.38,0.32,0.27,0.23,0.17,0.18,0.22,0.25,0.29,0.33,0.37,0.41,0.46,0.51}; // the number of strips with equal pitches & width of the corresponding group of strips
82  double CR6C_group[14]={32,32,32,32,704,64,32,32,32,32,32,32,32,32};
83 
84  int MxGrpSize = 14; // the max number of entries in CRC_group array
85  bmtc.CRCGROUP.resize(bmtc.NREGIONS); //3 regions
86  bmtc.CRCWIDTH.resize(bmtc.NREGIONS);
87 
88  for (int i = 0; i <3 ; ++i)
89  {
90  bmtc.CRCGROUP[i].resize(MxGrpSize);
91  bmtc.CRCWIDTH[i].resize(MxGrpSize);
92  }
93 
94  for(int j =0; j<13; j++)
95  {
96  // region index 0 is CR4
97  bmtc.CRCGROUP[0][j] = CR4C_group[j];
98  bmtc.CRCWIDTH[0][j] = CR4C_width[j];
99  }
100  for(int j =0; j<1; j++)
101  {
102  // region index 1 is CR5
103  bmtc.CRCGROUP[1][j] = CR5C_group[j];
104  bmtc.CRCWIDTH[1][j] = CR5C_width[j];
105  }
106  for(int j =0; j<14; j++)
107  {
108  // region index 2 is CR6
109  bmtc.CRCGROUP[2][j] = CR6C_group[j];
110  bmtc.CRCWIDTH[2][j] = CR6C_width[j];
111  }
112 
113  return bmtc;
114 }
115 
116 map<string, double> BMT_HitProcess :: integrateDgt(MHit* aHit, int hitn)
117 {
118  map<string, double> dgtz;
119  vector<identifier> identity = aHit->GetId();
120 
121  // BMT ID:
122  // layer, type, sector, strip
123 
124  //int layer = 2*identity[0].id + identity[1].id - 2 ;
125  int layer = identity[0].id;
126  int sector = identity[2].id;
127  int strip = identity[3].id;
128  trueInfos tInfos(aHit);
129 
130  if(verbosity>4)
131  {
132  trueInfos tInfos(aHit);
133  cout << log_msg << " layer: " << layer << " sector: " << sector << " Strip: " << strip
134  << " x=" << tInfos.x << " y=" << tInfos.y << " z=" << tInfos.z << endl;
135  }
136 
137  dgtz["hitn"] = hitn;
138  dgtz["layer"] = layer;
139  dgtz["sector"] = sector;
140  dgtz["strip"] = strip;
141  dgtz["Edep"] = tInfos.eTot;
142  return dgtz;
143 }
144 
145 
146 
147 vector<identifier> BMT_HitProcess :: processID(vector<identifier> id, G4Step* aStep, detector Detector)
148 {
149  G4ThreeVector xyz = aStep->GetPostStepPoint()->GetPosition();
150 
151  // if the scale is not set, then use fieldmanager to get the value
152  // if fieldmanager is not found, the field is zero
153  if(bmtc.fieldScale == -1)
154  {
155  const double point[4] = {xyz.x(), xyz.y(), xyz.z(), 10};
156  double fieldValue[3] = {0, 0, 0};
157 
158 
159  G4FieldManager *fmanager = aStep->GetPostStepPoint()->GetPhysicalVolume()->GetLogicalVolume()->GetFieldManager();
160 
161  // if no field manager, the field is zero
162  if(fmanager)
163  {
164  fmanager->GetDetectorField()->GetFieldValue(point, fieldValue);
165  if(bmtc.runNo == -1)
166  cout << " > BMT: Field found with value " << fieldValue[2]/gauss << " gauss. Setting Lorentz angle accordingly." << endl;
167  bmtc.changeFieldScale((fieldValue[2]/gauss)/50000.0);
168  }
169  else
170  {
171  bmtc.changeFieldScale(0);
172  if(bmtc.runNo == -1)
173  cout << " > BMT: No field found. Lorentz angle set to zero." << endl;
174  }
175  }
176 
177  vector<identifier> yid = id;
178  class bmt_strip bmts;
179 
180  //int layer = 2*yid[0].id + yid[1].id - 2 ;
181  int layer = yid[0].id;
182  int sector = yid[2].id;
183 
184  double depe = aStep->GetTotalEnergyDeposit();
185  //cout << "resolMM " << layer << " " << x << " " << y << " " << z << " " << depe << " " << aStep->GetTrack()->GetTrackID() << endl;
186  vector<double> multi_hit = bmts.FindStrip(layer, sector, xyz, depe, bmtc);
187 
188  int n_multi_hits = multi_hit.size()/2;
189 
190  // closest strip
191  //yid[4].id = (int) multi_hit[0];
192  yid[3].id = (int) multi_hit[0];
193 
194  yid[0].id_sharing = multi_hit[1];
195  yid[1].id_sharing = multi_hit[1];
196  yid[2].id_sharing = multi_hit[1];
197  yid[3].id_sharing = multi_hit[1];
198  // yid[4].id_sharing = multi_hit[1];
199 
200  // additional strip
201  for(int h=1; h<n_multi_hits; h++)
202  {
203  for(int j=0; j<3; j++)
204  {
205  identifier this_id;
206  this_id.name = yid[j].name;
207  this_id.rule = yid[j].rule;
208  this_id.id = yid[j].id;
209  this_id.time = yid[j].time;
210  this_id.TimeWindow = yid[j].TimeWindow;
211  this_id.TrackId = yid[j].TrackId;
212  this_id.id_sharing = multi_hit[3];
213  yid.push_back(this_id);
214  }
215  // last id is strip
216  identifier this_id;
217  this_id.name = yid[3].name;
218  this_id.rule = yid[3].rule;
219  this_id.id = (int) multi_hit[2];
220  this_id.time = yid[3].time;
221  this_id.TimeWindow = yid[3].TimeWindow;
222  this_id.TrackId = yid[3].TrackId;
223  this_id.id_sharing = multi_hit[3];
224  yid.push_back(this_id);
225  }
226 
227  return yid;
228 }
229 
230 
231 void BMT_HitProcess::initWithRunNumber(int runno)
232 {
233  if(bmtc.runNo != runno)
234  {
235  cout << " > Initializing " << HCname << " digitization for run number " << runno << endl;
236  bmtc = initializeBMTConstants(runno);
237  bmtc.runNo = runno;
238  }
239 }
240 
241 
242 map< string, vector <int> > BMT_HitProcess :: multiDgt(MHit* aHit, int hitn)
243 {
244  map< string, vector <int> > MH;
245 
246  return MH;
247 }
248 
249 
250 
251 
252 // this static function will be loaded first thing by the executable
253 bmtConstants BMT_HitProcess::bmtc = initializeBMTConstants(-1);
254 
255 
256 
257 
258 
259 
260 
261 
double CRCRADIUS[NREGIONS]
Definition: bmt_strip.h:56
double CRCSPACING[NREGIONS]
Definition: bmt_strip.h:58
double CRCLENGTH[NREGIONS]
Definition: bmt_strip.h:59
double fieldScale
Definition: bmt_strip.h:37
double CRCEDGE2[NREGIONS][NREGIONS]
Definition: bmt_strip.h:65
double verbosity
Definition: HitProcess.h:120
map< string, vector< int > > multiDgt(MHit *, int)
vector< vector< int > > CRCGROUP
Definition: bmt_strip.h:66
double CRCEDGE1[NREGIONS][NREGIONS]
Definition: bmt_strip.h:64
double CRZWIDTH[NREGIONS]
Definition: bmt_strip.h:46
vector< identifier > GetId()
Definition: Hit.h:103
int id
manually assing ID. 0 if "ncopy" (will be set at hit processing time)
Definition: identifier.h:39
string name
Name of the detector.
Definition: identifier.h:37
double CRZRADIUS[NREGIONS]
Definition: bmt_strip.h:43
vector< identifier > processID(vector< identifier >, G4Step *, detector)
static const int NREGIONS
Definition: bmt_strip.h:40
double z
Definition: HitProcess.h:41
double CRZEDGE1[NREGIONS][NREGIONS]
Definition: bmt_strip.h:52
vector< double > FindStrip(int layer, int sector, G4ThreeVector xyz, double Edep, bmtConstants bmtc)
Definition: bmt_strip.cc:18
double eTot
Definition: HitProcess.h:40
double x
Definition: HitProcess.h:41
double TimeWindow
Time Window. If abs(steptime - time) is smaller than TimeWindow, it&#39;s the same hit.
Definition: identifier.h:41
int TrackId
If Time Window is 0, it&#39;s a "flux" detector: if it&#39;s the same track, it&#39;s the same hit...
Definition: identifier.h:42
string log_msg
Definition: HitProcess.h:121
double SigmaDrift
Definition: bmt_strip.h:33
void changeFieldScale(double newFieldScale)
Definition: bmt_strip.h:69
vector< vector< double > > CRCWIDTH
Definition: bmt_strip.h:67
double CRZXPOS[NREGIONS]
Definition: bmt_strip.h:51
double CRZZMAX[NREGIONS]
Definition: bmt_strip.h:49
Definition: Hit.h:22
double CRCZMAX[NREGIONS]
Definition: bmt_strip.h:61
double CRCOFFSET[NREGIONS]
Definition: bmt_strip.h:62
double y
Definition: HitProcess.h:41
double CRZZMIN[NREGIONS]
Definition: bmt_strip.h:48
double id_sharing
A single step can generate multiple identifiers. This variable represent the percentage sharing of th...
Definition: identifier.h:43
double time
Time of the first step.
Definition: identifier.h:40
double CRZLENGTH[NREGIONS]
Definition: bmt_strip.h:47
int CRZNSTRIPS[NREGIONS]
Definition: bmt_strip.h:44
map< string, double > integrateDgt(MHit *, int)
int CRCNSTRIPS[NREGIONS]
Definition: bmt_strip.h:57
double hStrip2Det
Definition: bmt_strip.h:35
double CRCZMIN[NREGIONS]
Definition: bmt_strip.h:60
double hDrift
Definition: bmt_strip.h:34
string rule
"manual" or "ncopy"
Definition: identifier.h:38
double CRZSPACING[NREGIONS]
Definition: bmt_strip.h:45
double CRZEDGE2[NREGIONS][NREGIONS]
Definition: bmt_strip.h:53
double CRZOFFSET[NREGIONS]
Definition: bmt_strip.h:50
string HCname
Definition: HitProcess.h:117