StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFtpcDriftMapMaker.cxx
1 // $Id: StFtpcDriftMapMaker.cxx,v 1.23 2009/11/10 12:30:48 jcs Exp $
2 // $Log: StFtpcDriftMapMaker.cxx,v $
3 // Revision 1.23 2009/11/10 12:30:48 jcs
4 // replace StMagUtilities with StarMagField
5 //
6 // Revision 1.22 2007/04/28 17:56:10 perev
7 // Redundant StChain.h removed
8 //
9 // Revision 1.21 2006/08/02 13:57:57 jcs
10 // add deltaAr argument to allow user to change gas compostion (default: deltaAr=0)
11 //
12 // Revision 1.20 2005/12/12 14:43:53 jcs
13 // exit if error occurs while constructing StFtpcDbReader
14 //
15 // Revision 1.19 2003/09/30 08:58:20 jcs
16 // StMagUtilities constructer was changed; for safety's sake call with mode = 0
17 //
18 // Revision 1.18 2003/09/18 10:00:55 jcs
19 // remove obsolete version of StFtpcMagboltz2 (FORTRAN version in $CVSROOT/online/ftpc/Magboltz)
20 //
21 // Revision 1.17 2003/09/02 17:58:15 perev
22 // gcc 3.2 updates + WarnOff
23 //
24 // Revision 1.16 2002/09/24 09:50:09 jcs
25 // Remove gufld remains
26 //
27 // Revision 1.15 2002/01/22 22:09:59 jcs
28 // remove unused line of code to remove warning
29 //
30 // Revision 1.14 2001/10/29 13:00:38 jcs
31 // use new constructor in StFtpcDbReader
32 //
33 // Revision 1.13 2001/10/23 07:27:48 jcs
34 // implement new StFtpcDbReader constructor
35 //
36 // Revision 1.12 2001/10/22 09:40:18 jcs
37 // remove obsolete include StFtpcParamReader.hh
38 //
39 // Revision 1.11 2001/08/10 15:34:40 jcs
40 // correct mistake - close ftpcDriftField
41 //
42 // Revision 1.10 2001/07/12 20:43:28 jcs
43 // remove tzero from ftpcDriftField
44 //
45 // Revision 1.9 2001/07/12 18:19:31 jcs
46 // compute drift map according to FTPC cathode voltage and magnetic field
47 //
48 // Revision 1.8 2001/05/17 20:45:19 jcs
49 // change to use Jim Thomas StMagUtilities
50 //
51 // Revision 1.7 2001/04/04 17:08:52 jcs
52 // remove references to StFtpcParamReader from StFtpcDbReader
53 //
54 // Revision 1.6 2001/04/02 12:06:34 jcs
55 // get FTPC calibrations,geometry from MySQL database
56 //
57 // Revision 1.5 2001/03/19 15:53:05 jcs
58 // use ftpcDimensions from database
59 //
60 // Revision 1.4 2001/03/09 13:54:27 jcs
61 // write out cstructs with new values so that they can be added to database
62 //
63 // Revision 1.3 2001/03/07 15:12:32 jcs
64 // use MySQL database instead of params
65 //
66 // Revision 1.2 2001/01/09 22:52:22 jcs
67 // remove include St_fmg_Module.h - now obsolete
68 //
69 // Revision 1.1 2000/12/20 08:44:01 jcs
70 // Replace pam/ftpc/fmg with maker
71 //
72 //
74 // //
75 // StFtpcDriftMapMaker class //
76 // //
78 
79 #include <Stiostream.h>
80 #include <stdlib.h>
81 #include "St_db_Maker/St_db_Maker.h"
82 #include "StFtpcDriftMapMaker.h"
83 #include "StFtpcMagboltz1.hh"
84 #include "StFtpcClusterMaker/StFtpcDbReader.hh"
85 
86 #include "StMessMgr.h"
87 #include "St_DataSetIter.h"
88 #include "TH1.h"
89 #include "TH2.h"
90 
91 ClassImp(StFtpcDriftMapMaker)
92 
93 //_____________________________________________________________________________
95 }
96 //_____________________________________________________________________________
97 StFtpcDriftMapMaker::StFtpcDriftMapMaker(const StarMagField::EBField map,const Float_t factor,const Float_t deltaAr):
98  m_dimensions(0),
99  m_padrow_z(0),
100  m_efield(0),
101  m_vdrift(0),
102  m_deflection(0),
103  m_dvdriftdp(0),
104  m_ddeflectiondp(0),
105  m_gas(0),
106  m_driftfield(0)
107 {
108 // Set Date,Time for offline database access so that the latest table entries are used
109  mDbMaker = (St_db_Maker*)GetMaker("db");
110  mDbMaker->SetDateTime(20330101,0);
111 
112 // Create tables
113 
114  St_DataSet *ftpc_geometry_db = GetDataBase("Geometry/ftpc");
115  if ( !ftpc_geometry_db ){
116  *gMessMgr<<"Could not locate MySQLDb:Geometry/ftpc"<<endm;
117  exit(0);
118  }
119  St_DataSetIter dblocal_geometry(ftpc_geometry_db);
120 
121  m_dimensions = (St_ftpcDimensions *)dblocal_geometry("ftpcDimensions");
122  m_padrow_z = (St_ftpcPadrowZ *)dblocal_geometry("ftpcPadrowZ" );
123 
124  St_DataSet *ftpc_calibrations_db = GetDataBase("Calibrations/ftpc");
125  if ( !ftpc_calibrations_db ){
126  *gMessMgr<<"Could not locate MySQLDb:Calibrations/ftpc"<<endm;
127  exit(0);
128  }
129  St_DataSetIter dblocal_calibrations(ftpc_calibrations_db);
130 
131  m_gas = (St_ftpcGas *)dblocal_calibrations("ftpcGas");
132 
133 
134 
135  m_driftfield = (St_ftpcDriftField *)dblocal_calibrations("ftpcDriftField");
136  m_efield = (St_ftpcEField *)dblocal_calibrations("ftpcEField" );
137  m_vdrift = (St_ftpcVDrift *)dblocal_calibrations("ftpcVDrift" );
138  m_deflection = (St_ftpcDeflection *)dblocal_calibrations("ftpcDeflection" );
139  m_dvdriftdp = (St_ftpcdVDriftdP *)dblocal_calibrations("ftpcdVDriftdP" );
140  m_ddeflectiondp = (St_ftpcdDeflectiondP *)dblocal_calibrations("ftpcdDeflectiondP" );
141 
142  if (!m_efield || !m_vdrift || !m_deflection || !m_dvdriftdp || !m_ddeflectiondp
143  || !m_gas || !m_driftfield) {
144  cout<<"MySQLDb:Calibrations/ftpc not complete"<<endl;
145  exit(0);
146  }
147 
148  // create FTPC data base reader
149  StFtpcDbReader *dbReader = new StFtpcDbReader(m_dimensions,
150  m_padrow_z,
151  m_efield,
152  m_vdrift,
153  m_deflection,
154  m_dvdriftdp,
155  m_ddeflectiondp,
156  m_gas,
157  m_driftfield);
158  if (dbReader->returnCode != 0) {
159  cout<<"Error constructing StFtpcDbReader"<<endl;
160  return;
161  }
162 
163  ftpcEField_st *ftpcEField = m_efield->GetTable();
164  ftpcVDrift_st *ftpcVDrift = m_vdrift->GetTable();
165  ftpcDeflection_st *ftpcDeflection = m_deflection->GetTable();
166  ftpcdVDriftdP_st *ftpcdVDriftdP = m_dvdriftdp->GetTable();
167  ftpcdDeflectiondP_st *ftpcdDeflectiondP = m_ddeflectiondp->GetTable();
168  for ( Int_t iBin=0; iBin<dbReader->maximumNumberOfMagboltzBins(); iBin++)
169  {
170  ftpcEField->e[iBin] = 0.0;
171  for(Int_t iPadrow=0; iPadrow<dbReader->numberOfPadrowsPerSide(); iPadrow++) {
172  ftpcVDrift->v[iPadrow + dbReader->numberOfPadrowsPerSide()*iBin] = 0.0;
173  ftpcDeflection->psi[iPadrow + dbReader->numberOfPadrowsPerSide()*iBin] = 0.0;
174  ftpcdVDriftdP->dv_dp[iPadrow + dbReader->numberOfPadrowsPerSide()*iBin] = 0.0;
175  ftpcdDeflectiondP->dpsi_dp[iPadrow + dbReader->numberOfPadrowsPerSide()*iBin] = 0.0;
176  }
177  }
178 
179  for ( Int_t iBin=0; iBin<dbReader->numberOfMagboltzBins(); iBin++)
180  {
181  dbReader->setMagboltzEField(iBin,dbReader->minimumDriftField() + iBin*dbReader->stepSizeDriftField());
182  }
183 
184 
185 
186  StarMagField *magField = new StarMagField(map, factor, kTRUE);
187 
188 
189  // create magboltz
190  StFtpcMagboltz1 *magboltz = new StFtpcMagboltz1();
191 
192  int i, j;
193  float thisField, thisRadius;
194  float posVector[3], bVector[3];
195  float bMag, bTheta, bRadial;
196  float vDrift, psiAngle, pressure;
197  float upPressure, upDrift, upAngle, pOff;
198  float eFinal;
199 
200  eFinal=0.1;
201 
202  posVector[0]=0;
203 
204  for(i=0; i < dbReader->numberOfMagboltzBins(); i++)
205  {
206 
207  thisField = dbReader->minimumDriftField()
208  + i*dbReader->stepSizeDriftField();
209  thisRadius = dbReader->radiusTimesField() / thisField;
210 
211  posVector[1]=thisRadius;
212  for(j=0; j < dbReader->numberOfPadrowsPerSide(); j++)
213  {
214  posVector[2]=dbReader->padrowZPosition(j);
215  /* sets posVector to (0, radius, z) */
216 
217  magField->BField(posVector, bVector);
218  printf("pos %f %f %f field %f %f %f\n", posVector[0], posVector[1], posVector[2], bVector[0], bVector[1], bVector[2]);
219  bMag=::sqrt(bVector[0]*bVector[0] + bVector[1]*bVector[1] +
220  bVector[2]*bVector[2]);
221  bRadial=::sqrt(bVector[0]*bVector[0] + bVector[1]*bVector[1]);
222  bTheta=acos(bRadial/bMag)*90/acos(0.0);
223  // set sign of angle between E and B fields
224  bTheta = (factor/fabs(factor)) * bTheta;
225  pressure=760.0;
226  upPressure=760.0+dbReader->pressureOffset();
227  pOff=dbReader->pressureOffset()*1.3332;
228  /* Torr -> hPa */
229  vDrift=0;
230  psiAngle=0;
231  upDrift=0;
232  upAngle=0;
233  printf("loop %d of %d\n", i, dbReader->numberOfMagboltzBins());
234  printf("calling magboltz with field %f bMag %f bTheta %f pressure %f vDrift %f psiAngle %f\n", thisField, bMag, bTheta, pressure, vDrift, psiAngle);
235 cout<<"dbReader->percentAr() = "<<dbReader->percentAr()<<" deltaAr = "<<deltaAr<<endl;
236  float gas1=dbReader->percentAr() + deltaAr;
237  float gas2=dbReader->percentCO2() - deltaAr;;
238  float gas3=dbReader->percentNe();
239  float gas4=dbReader->percentHe();
240  float temperature=dbReader->baseTemperature();
241  cout<<"calling magboltz with "<<gas1<<"% Ar and "<<gas2<<"% CO2"<<endl;
242  magboltz->magboltz_(&thisField, &bMag, &bTheta, &pressure, &gas1, &gas2, &gas3, &gas4, &temperature, &vDrift, &psiAngle, &eFinal);
243  printf("called magboltz got field %f bMag %f bTheta %f pressure %f vDrift %f psiAngle %f\n", thisField, bMag, bTheta, pressure, vDrift, psiAngle);
244  magboltz->magboltz_(&thisField, &bMag, &bTheta, &upPressure, &gas1, &gas2, &gas3, &gas4, &temperature, &upDrift, &upAngle, &eFinal);
245  printf("changing magboltz values from %f %f %f %f\n",dbReader->magboltzVDrift(i,j), dbReader->magboltzDeflection(i,j),dbReader->magboltzdVDriftdP(i,j),dbReader->magboltzdDeflectiondP(i,j));
246  dbReader->setMagboltzEField(i,thisField);
247  dbReader->setMagboltzVDrift(i,j,vDrift);
248  dbReader->setMagboltzDeflection(i,j,psiAngle);
249  dbReader->setMagboltzdVDriftdP(i,j,(upDrift-vDrift)/pOff);
250  dbReader->setMagboltzdDeflectiondP(i,j,(upAngle-psiAngle)/pOff);
251  printf(" to %f %f %f %f\n",dbReader->magboltzVDrift(i,j), dbReader->magboltzDeflection(i,j),dbReader->magboltzdVDriftdP(i,j),dbReader->magboltzdDeflectiondP(i,j));
252 
253  }
254  }
255 
256 
257 // Write out new ftpcDeflection
258 
259  void* cstruct = m_deflection -> GetTable(); // Get pointer of table and copy to c-structure
260  Int_t nrows = m_deflection -> GetNRows(); // Get number of rows in the table
261 
262  fTableName = new char[20];
263  strcpy(fTableName,"ftpcDeflection");
264 // Create new TTable object for c-structure
265  TTable* table = TTable::New(fTableName,fTableName,cstruct,nrows);
266 
267  fOutputFileName = new char[100];
268  strcpy(fOutputFileName,"./ftpcDeflection.C");
269  ofstream ofs_Deflection(fOutputFileName); // Open a file
270  table -> SavePrimitive(ofs_Deflection,0); // Write information of c-structure from object of TTable to the file
271  ofs_Deflection.close(); // Close the file
272 
273 // Write out new ftpcVDrift
274 
275  cstruct = m_vdrift -> GetTable(); // Get pointer of table and copy to c-structure
276  nrows = m_vdrift -> GetNRows(); // Get number of rows in the table
277 
278  strcpy(fTableName,"ftpcVDrift");
279 // Create new TTable object for c-structure
280  table = TTable::New(fTableName,fTableName,cstruct,nrows);
281 
282  strcpy(fOutputFileName,"./ftpcVDrift.C");
283  ofstream ofs_VDrift(fOutputFileName); // Open a file
284  table -> SavePrimitive(ofs_VDrift,0); // Write information of c-structure from object of TTable to the file
285  ofs_VDrift.close(); // Close the file
286 
287 // Write out new ftpcdDeflectiondP
288 
289  cstruct = m_ddeflectiondp -> GetTable(); // Get pointer of table and copy to c-structure
290  nrows = m_ddeflectiondp -> GetNRows(); // Get number of rows in the table
291 
292  strcpy(fTableName,"ftpcdDeflectiondP");
293 // Create new TTable object for c-structure
294  table = TTable::New(fTableName,fTableName,cstruct,nrows);
295 
296  strcpy(fOutputFileName,"./ftpcdDeflectiondP.C");
297  ofstream ofs_dDeflectiondP(fOutputFileName); // Open a file
298  table -> SavePrimitive(ofs_dDeflectiondP,0); // Write information of c-structure from object of TTable to the file
299  ofs_dDeflectiondP.close(); // Close the file
300 
301 // Write out new ftpcdVDriftdP
302 
303  cstruct = m_dvdriftdp -> GetTable(); // Get pointer of table and copy to c-structure
304  nrows = m_dvdriftdp -> GetNRows(); // Get number of rows in the table
305 
306  strcpy(fTableName,"ftpcdVDriftdP");
307 // Create new TTable object for c-structure
308  table = TTable::New(fTableName,fTableName,cstruct,nrows);
309 
310  strcpy(fOutputFileName,"./ftpcdVDriftdP.C");
311  ofstream ofs_dVDriftdP(fOutputFileName); // Open a file
312  table -> SavePrimitive(ofs_dVDriftdP,0); // Write information of c-structure from object of TTable to the file
313  ofs_dVDriftdP.close(); // Close the file
314 
315 //-------------------------------------------------------------------
316 
317 // Write out new ftpcEField
318 
319  cstruct = m_efield -> GetTable(); // Get pointer of table and copy to c-structure
320  nrows = m_efield -> GetNRows(); // Get number of rows in the table
321 
322  fTableName = new char[20];
323  strcpy(fTableName,"ftpcEField");
324 // Create new TTable object for c-structure
325  table = TTable::New(fTableName,fTableName,cstruct,nrows);
326 
327  fOutputFileName = new char[100];
328  strcpy(fOutputFileName,"./ftpcEField.C");
329  ofstream ofs_ftpcEField(fOutputFileName); // Open a file
330  table -> SavePrimitive(ofs_ftpcEField,0); // Write information of c-structure from object of TTable to the file
331  ofs_ftpcEField.close(); // Close the file
332 
333 
334 // Write out new ftpcDriftField
335 
336  cstruct = m_driftfield -> GetTable(); // Get pointer of table and copy to c-structure
337  nrows = m_driftfield -> GetNRows(); // Get number of rows in the table
338 
339  fTableName = new char[20];
340  strcpy(fTableName,"ftpcDriftField");
341 // Create new TTable object for c-structure
342  table = TTable::New(fTableName,fTableName,cstruct,nrows);
343 
344  fOutputFileName = new char[100];
345  strcpy(fOutputFileName,"./ftpcDriftField.C");
346  ofstream ofs_ftpcDriftField(fOutputFileName); // Open a file
347  table -> SavePrimitive(ofs_ftpcDriftField,0); // Write information of c-structure from object of TTable to the file
348  ofs_ftpcDriftField.close(); // Close the file
349 
350 //-------------------------------------------------------------------
351  delete dbReader;
352  delete magboltz;
353 
354  cout <<"finished StFtpcDriftMapMaker" << endl;
355 }
356 //_____________________________________________________________________________
357 
static TTable * New(const Char_t *name, const Char_t *type, void *array, UInt_t size)
This static method creates a new TTable object if provided.
Definition: TTable.cxx:1515
Definition: TTable.h:48