46 #include "StHbtCoulomb.h"
50 #include "PhysicalConstants.h"
56 StHbtCoulomb::StHbtCoulomb() {
57 mFile =
"/afs/rhic.bnl.gov/star/hbt/coul/StHbtCorrectionFiles/correctionpp.dat";
59 cout <<
" No file, dummy!" << endl;
64 cout <<
"You have 1 default Coulomb correction!" << endl;
67 StHbtCoulomb::StHbtCoulomb(
const char* readFile,
const double& radius,
const double& charge) {
70 CreateLookupTable(mRadius);
72 cout <<
"You have 1 Coulomb correction!" << endl;
75 StHbtCoulomb::~StHbtCoulomb() {
79 void StHbtCoulomb::SetRadius(
const double& radius) {
80 cout <<
" StHbtCoulomb::setRadius() " << endl;
82 CreateLookupTable(mRadius);
85 double StHbtCoulomb::GetRadius() {
89 void StHbtCoulomb::SetFile(
const char* readFile) {
90 cout <<
" StHbtCoulomb::SetFile() " << endl;
94 CreateLookupTable(mRadius);
98 void StHbtCoulomb::SetChargeProduct(
const double& charge) {
99 cout <<
" StHbtCoulomb::SetChargeProduct() " << endl;
100 if ( mZ1Z2!=charge ) {
103 mFile =
"/afs/rhic.bnl.gov/star/hbt/coul/StHbtCorrectionFiles/correctionpp.dat";
106 mFile =
"/afs/rhic.bnl.gov/star/hbt/coul/StHbtCorrectionFiles/correctionpm.dat";
108 CreateLookupTable(mRadius);
112 void StHbtCoulomb::CreateLookupTable(
const double& radius) {
113 cout <<
" StHbtCoulomb::CreateLookupTable() " << endl;
118 cout <<
" StHbtCoulomb::CreateLookupTable -> NEGATIVE RADIUS " << endl;
119 cout <<
" call StHbtCoulomb::SetRadius(r) with positive r " << endl;
120 cerr <<
" StHbtCoulomb::CreateLookupTable -> NEGATIVE RADIUS " << endl;
121 cerr <<
" call StHbtCoulomb::SetRadius(r) with positive r " << endl;
124 ifstream mystream(mFile);
126 cout <<
"Could not open file" << endl;
130 cout <<
"Input correction file opened" << endl;
133 static char tempstring[2001];
134 static float radii[2000];
135 static int NRadii = 0;
137 if (!mystream.getline(tempstring,2000)) {
138 cout <<
"Could not read radii from file" << endl;
141 for (
unsigned int ii=0; ii<strlen(tempstring); ii++) {
142 while (tempstring[ii]==
' ') ii++;
143 sscanf(&tempstring[ii++],
"%f",&radii[++NRadii]);
144 while ( tempstring[ii]!=
' ' && (ii)<strlen(tempstring) )ii++;
146 cout <<
" Read " << NRadii <<
" radii from file" << endl;
148 static double LowRadius = -1.0;
149 static double HighRadius = -1.0;
150 static int LowIndex = 0;
154 for(
int iii=1; iii<=NRadii-1; iii++) {
155 if ( radius >= radii[iii] && radius <= radii[iii+1] ) {
156 LowRadius = radii[iii];
157 HighRadius = radii[iii+1];
161 if ( (LowRadius < 0.0) || (HighRadius < 0.0) ) {
162 cout <<
"StHbtCoulomb::CreateLookupTable --> Problem interpolating radius" << endl;
163 cout <<
" Check range of radii in lookup file...." << endl;
164 cerr <<
"StHbtCoulomb::CreateLookupTable --> Problem interpolating radius" << endl;
165 cerr <<
" Check range of radii in lookup file...." << endl;
169 static double corr[100];
171 static double tempEta = 0;
173 while (mystream >> tempEta) {
174 for (
int i=1; i<=NRadii; i++) {
177 static double LowCoulomb = 0;
178 static double HighCoulomb = 0;
179 static double nCorr = 0;
180 LowCoulomb = corr[LowIndex];
181 HighCoulomb = corr[LowIndex+1];
182 nCorr = ( (radius-LowRadius)*HighCoulomb+(HighRadius-radius)*LowCoulomb )/(HighRadius-LowRadius);
183 mEta[mNLines] = tempEta;
184 mCoulomb[mNLines] = nCorr;
188 cout <<
"Lookup Table is created with " << mNLines <<
" points" << endl;
191 double StHbtCoulomb::CoulombCorrect(
const double& eta) {
194 cout <<
"StHbtCoulomb::CoulombCorrect(eta) --> Trying to correct for negative radius!" << endl;
195 cerr <<
"StHbtCoulomb::CoulombCorrect(eta) --> Trying to correct for negative radius!" << endl;
199 middle=int( (mNLines-1)/2 );
200 if (eta*mEta[middle]<0.0) {
201 cout <<
"StHbtCoulomb::CoulombCorrect(eta) --> eta: " << eta <<
" has wrong sign for data file! " << endl;
202 cerr <<
"StHbtCoulomb::CoulombCorrect(eta) --> eta: " << eta <<
" has wrong sign for data file! " << endl;
206 static double Corr = 0;
209 if ( (eta>mEta[0]) && (mEta[0]>0.0) ) {
213 if ( (eta<mEta[mNLines-1]) && (mEta[mNLines-1]<0.0) ) {
214 Corr = mCoulomb[mNLines-1];
220 static int width = 0;
224 middle = int(width/2.0);
226 if (mEta[low+middle] < eta) {
230 middle = int(width/2.0);
236 middle = int(width/2.0);
240 if ( (mEta[low] >= eta) && (eta >= mEta[low+1]) ) {
241 static double LowEta = 0;
242 static double HighEta = 0;
243 static double LowCoulomb = 0;
244 static double HighCoulomb = 0;
246 HighEta = mEta[low+1];
247 LowCoulomb = mCoulomb[low];
248 HighCoulomb = mCoulomb[low+1];
251 Corr = ( (eta-LowEta)*HighCoulomb+(HighEta-eta)*LowCoulomb )/(HighEta-LowEta);
254 cout <<
"StHbtCoulomb::CoulombCorrect(eta) --> No correction" << endl;
255 cout <<
" Check range of eta in file: Input eta " << eta << endl;
256 cerr <<
"StHbtCoulomb::CoulombCorrect(eta) --> No correction" << endl;
257 cerr <<
" Check range of eta in file: Input eta " << eta << endl;
264 double StHbtCoulomb::CoulombCorrect(
const double& eta,
265 const double& radius) {
273 cout <<
"StHbtCoulomb::CoulombCorrect(eta,r) --> input and member radii are negative!" << endl;
274 cerr <<
"StHbtCoulomb::CoulombCorrect(eta,r) --> input and member radii are negative!" << endl;
280 if (radius == mRadius) {
287 CreateLookupTable(mRadius);
292 return ( CoulombCorrect(eta) );
295 double StHbtCoulomb::CoulombCorrect(
const StHbtPair* pair) {
296 return ( CoulombCorrect( Eta(pair) ) );;
299 double StHbtCoulomb::CoulombCorrect(
const StHbtPair* pair,
const double& radius) {
300 return ( CoulombCorrect( Eta(pair),radius ) );
303 double StHbtCoulomb::Eta(
const StHbtPair* pair) {
304 static double px1,py1,pz1,px2,py2,pz2;
305 static double px1new,py1new,pz1new;
306 static double px2new,py2new,pz2new;
307 static double vx1cms,vy1cms,vz1cms;
308 static double vx2cms,vy2cms,vz2cms;
309 static double VcmsX,VcmsY,VcmsZ;
310 static double dv = 0.0;
311 static double e1,e2,e1new,e2new;
312 static double psi,theta;
313 static double beta,gamma;
314 static double VcmsXnew;
316 px1 = pair->track1()->FourMomentum().px();
317 py1 = pair->track1()->FourMomentum().py();
318 pz1 = pair->track1()->FourMomentum().pz();
319 e1 = pair->track1()->FourMomentum().e();
320 px2 = pair->track2()->FourMomentum().px();
321 py2 = pair->track2()->FourMomentum().py();
322 pz2 = pair->track2()->FourMomentum().pz();
323 e2 = pair->track2()->FourMomentum().e();
325 VcmsX = ( px1+px2 )/( e1+e2 );
326 VcmsY = ( py1+py2 )/( e1+e2 );
327 VcmsZ = ( pz1+pz2 )/( e1+e2 );
329 psi = atan(VcmsY/VcmsX);
330 VcmsXnew = VcmsX*cos(psi)+VcmsY*sin(psi);
332 theta = atan(VcmsZ/VcmsX);
333 VcmsXnew = VcmsX*cos(theta)+VcmsZ*sin(theta);
337 gamma = 1.0/::sqrt( 1.0-beta*beta );
340 px1new = px1*cos(psi)+py1*sin(psi);
341 py1new = -px1*sin(psi)+py1*cos(psi);
343 px1new = px1*cos(theta)+pz1*sin(theta);
344 pz1new = -px1*sin(theta)+pz1*cos(theta);
349 px2new = px2*cos(psi)+py2*sin(psi);
350 py2new = -px2*sin(psi)+py2*cos(psi);
352 px2new = px2*cos(theta)+pz2*sin(theta);
353 pz2new = -px2*sin(theta)+pz2*cos(theta);
359 e1new = gamma*e1 - gamma*beta*px1;
360 px1new = -gamma*beta*e1 + gamma*px1;
361 e2new = gamma*e2 - gamma*beta*px2;
362 px2new = -gamma*beta*e2 + gamma*px2;
375 dv = ::sqrt( (vx1cms-vx2cms)*(vx1cms-vx2cms) +
376 (vy1cms-vy2cms)*(vy1cms-vy2cms) +
377 (vz1cms-vz2cms)*(vz1cms-vz2cms) );
379 return ( mZ1Z2*fine_structure_const/(dv) );
382 StHbt1DHisto* StHbtCoulomb::CorrectionHistogram(
const double& mass1,
const double& mass2,
const int& nBins,
383 const double& low,
const double& high) {
384 if ( mass1!=mass2 ) {
385 cout <<
"Masses not equal ... try again. No histogram created." << endl;
389 const double reducedMass = mass1*mass2/(mass1+mass2);
393 for (
int ii=1; ii<=nBins; ii++)
395 qInv = correction->GetBinCenter(ii);
396 eta = 2.0*mZ1Z2*reducedMass*fine_structure_const/( qInv );
397 CoulombCorrect( eta );
398 correction->Fill( qInv, CoulombCorrect(eta,mRadius) );
409 correction->SetDirectory(0);
410 int nBins = correction->GetXaxis()->GetNbins();
411 const double reducedMass = 0.5*mass;
414 for (
int ii=1; ii<=nBins; ii++)
416 qInv = correction->GetBinCenter(ii);
417 eta = 2.0*mZ1Z2*reducedMass*fine_structure_const/( qInv );
418 correction->Fill( qInv, CoulombCorrect(eta,mRadius) );
424 StHbt3DHisto* StHbtCoulomb::CorrectionHistogram(
const StHbt3DHisto* histo,
const double mass) {
426 StHbt3DHisto* correction = (StHbt3DHisto*) ((StHbt3DHisto*)histo)->Clone();
428 correction->SetDirectory(0);
429 int nBinsX = correction->GetXaxis()->GetNbins();
430 int nBinsY = correction->GetYaxis()->GetNbins();
431 int nBinsZ = correction->GetZaxis()->GetNbins();
432 const double reducedMass = 0.5*mass;
436 for (
int ii=1; ii<=nBinsX; ii++) {
437 for (
int iii=1; iii<=nBinsY; iii++) {
438 for (
int iv=1; iv<=nBinsZ; iv++) {
439 binNumber = histo->GetBin(ii,iii,iv);
440 qInv = histo->GetBinContent(binNumber);
441 eta = 2.0*mZ1Z2*reducedMass*fine_structure_const/( qInv );
442 correction->SetBinContent(binNumber, CoulombCorrect(eta,mRadius) );
450 double StHbtCoulomb::CoulombCorrect(
const double& mass,
const double& charge,
451 const double& radius,
const double& qInv) {
454 const double reducedMass = 0.5*mass;
455 double eta = 2.0*mZ1Z2*reducedMass*fine_structure_const/( qInv );
456 return ( CoulombCorrect(eta,mRadius) );