3 #include "StFcsPointMaker.h"
4 #include "StLorentzVectorF.hh"
7 #include "StEvent/StEventTypes.h"
8 #include "StEvent/StFcsHit.h"
9 #include "StEvent/StFcsCluster.h"
10 #include "StEvent/StFcsPoint.h"
11 #include "StFcsDbMaker/StFcsDb.h"
13 #include "StMuDSTMaker/COMMON/StMuTypes.hh"
14 #include "StMuDSTMaker/COMMON/StMuDst.h"
15 #include "StMuDSTMaker/COMMON/StMuEvent.h"
16 #include "tables/St_vertexSeed_Table.h"
25 static const int NPMAX=60;
26 std::array<double,NPMAX> mShowerShapeParameters;
31 std::vector<float> mX;
32 std::vector<float> mY;
33 std::vector<float> mE;
39 mMinuit.SetPrintLevel(-1);
42 StFcsPointMaker::~StFcsPointMaker() { }
48 int StFcsPointMaker::InitRun(
int runNumber) {
50 LOG_DEBUG <<
"StFcsPointMaker initializing run" << endm;
51 mDb =
static_cast<StFcsDb*
>(GetDataSet(
"fcsDb"));
53 LOG_ERROR <<
"StFcsPointMaker initializing failed due to no StFcsDb" << endm;
56 return StMaker::InitRun(runNumber);
59 void StFcsPointMaker::setShowerShapeParameters(
int det){
62 double scl=mShowerShapeScale;
66 mShowerShapeParameters= { width, 1.0708, 0.167773, -0.238578, 0.535845*scl, 0.850233*scl, 2.38264*scl, 1.0, unused, unused,
67 unused, unused, unused, unused, unused, unused, unused, unused, unused, unused,
68 unused, unused, unused, unused, unused, unused, unused, unused, unused, unused,
69 unused, unused, unused, unused, unused, unused, unused, unused, unused, unused,
70 unused, unused, unused, unused, unused, unused, unused, unused, unused, unused,
71 unused, unused, unused, unused, unused, unused, unused, unused, unused, unused};
72 }
else if(mShowerShape==1){
75 double a11=0.998438;
double a12=0.222782;
double a13=-0.22122;
double b11=0.177028;
double b12=0.000473222;
double b13=0.178897;
double w1 = 0.0372556;
76 double a21=1.07711 ;
double a22=-0.0281385;
double a23=-0.0489747;
double b21=0.199964;
double b22=3.5021;
double b23=2.35246;
double w2 = 0.202699;
77 double a31=1.07901 ;
double a32=0.0650143;
double a33=-0.144025;
double b31=0.446845;
double b32=0.00544512;
double b33=1.64565;
double w3 = 0.293878;
78 double a41=0.922174;
double a42=0.0778254;
double a43=1.07474e-07;
double b41=0.593804;
double b42=0.6199;
double b43=3.49798;
double w4 = 0.236854;
79 double a51=0.999849;
double a52=0.000151185;
double a53=2.20244e-07;
double b51=0.949953;
double b52=1.84451;
double b53=3.40799;
double w5 = 0.146041;
80 double a61=0.997454;
double a62=0.00254497;
double a63=1.02127e-06;
double b61=1.43387;
double b62=2.91155;
double b63=3.4484;
double w6 = 0.0832717;
81 mShowerShapeParameters= {width, a11*w1, a12*w1, a13*w1, b11*scl, b12*scl, b13*scl, unused ,unused, unused,
82 width, a21*w2, a22*w2, a23*w2, b21*scl, b22*scl, b23*scl, unused ,unused, unused,
83 width, a31*w3, a32*w3, a33*w3, b31*scl, b32*scl, b33*scl, unused ,unused, unused,
84 width, a41*w4, a42*w4, a43*w4, b41*scl, b42*scl, b43*scl, unused ,unused, unused,
85 width, a51*w5, a52*w5, a53*w5, b51*scl, b52*scl, b53*scl, unused ,unused, unused,
86 width, a61*w6, a62*w6, a63*w6, b61*scl, b62*scl, b63*scl, unused ,unused, unused};
87 }
else if(mShowerShape==2){
90 double a1S[6]={0.0303644,0.212191,0.277429,0.0370035,0.0524404,0.00844062};
91 double a2S[6]={0.00122867,0.105355,0.10538,0.152656,0.00664331,0.0108688};
92 double b1S[6]={0.403493,0.514546,0.672826,1.82344,0.727991,1.48785};
93 double b2S[6]={0.270492,0.514593,0.672655,0.644871,4.32003,0.25};
94 mShowerShapeParameters= {width, a1S[0], a2S[0], 0.0, b1S[0]*scl, b2S[0]*scl, 0.0, unused, unused, unused,
95 width, a1S[1], a2S[1], 0.0, b1S[1]*scl, b2S[1]*scl, 0.0, unused, unused, unused,
96 width, a1S[2], a2S[2], 0.0, b1S[2]*scl, b2S[2]*scl, 0.0, unused, unused, unused,
97 width, a1S[3], a2S[3], 0.0, b1S[3]*scl, b2S[3]*scl, 0.0, unused, unused, unused,
98 width, a1S[4], a2S[4], 0.0, b1S[4]*scl, b2S[4]*scl, 0.0, unused, unused, unused,
99 width, a1S[5], a2S[5], 0.0, b1S[5]*scl, b2S[5]*scl, 0.0, unused, unused, unused};
100 }
else if(mShowerShape==3){
103 double a1L[6]={0.0275364,0.200363,0.277157,0.0391611,0.0590757,0.0101089};
104 double a2L[6]={0.000429808,0.0991777,0.104781,0.161916,0.00764026,0.012653};
105 double b1L[6]={0.515974,0.661722,0.865167,2.35237,0.932038,1.87933};
106 double b2L[6]={0.53531,0.661519,0.865226,0.828017,5.49041,0.321139};
107 mShowerShapeParameters= {width, a1L[0], a2L[0], 0.0, b1L[0]*scl, b2L[0]*scl, 0.0, unused, unused, unused,
108 width, a1L[1], a2L[1], 0.0, b1L[1]*scl, b2L[1]*scl, 0.0, unused, unused, unused,
109 width, a1L[2], a2L[2], 0.0, b1L[2]*scl, b2L[2]*scl, 0.0, unused, unused, unused,
110 width, a1L[3], a2L[3], 0.0, b1L[3]*scl, b2L[3]*scl, 0.0, unused, unused, unused,
111 width, a1L[4], a2L[4], 0.0, b1L[4]*scl, b2L[4]*scl, 0.0, unused, unused, unused,
112 width, a1L[5], a2L[5], 0.0, b1L[5]*scl, b2L[5]*scl, 0.0, unused, unused, unused};
117 double smax=mDb->getShowerMaxZ(det);
119 double z0 = off.z()/cos(a);
120 for(
int i=0; i<6; i++){
121 double z = (i+0.5)*dz/6.0;
122 mShowerShapeParameters[i*10+7]=(z0 + z)/(z0+smax);
126 for(
int i=0; i<6; i++){
127 LOG_INFO << Form(
"Shower Shape Parameters det=%1d slice=%1d : ",det,i);
128 for(
int j=0; j<10; j++) {LOG_INFO << Form(
" %10.6f",mShowerShapeParameters[i*10+j]);}
135 LOG_DEBUG <<
"StFcsPointMaker Make!!!" << endm;
139 if (event) mFcsCollection =
event->fcsCollection();
140 if(!mFcsCollection) {
141 LOG_WARN <<
"StFcsPointMaker did not find fcsCollection in StEvent" << endm;
145 for(
int det=0; det<=kFcsEcalSouthDetId; det++) {
148 if(GetDebug()>0) mFcsCollection->print(3);
152 void StFcsPointMaker::fitClusters(
int det) {
153 StSPtrVecFcsCluster& clusters = mFcsCollection->clusters(det);
154 StSPtrVecFcsPoint& points = mFcsCollection->points(det);
157 int nclu=clusters.size();
158 for(
int i=0; i<nclu; i++) clusters[i]->points().clear();
160 setShowerShapeParameters(det);
163 for(
int i=0; i<nclu; i++){
170 mE.clear(); mX.clear(); mY.clear();
171 for(
int j=0; j<mNHit; j++){
175 mE.push_back(h->energy());
182 double chi1=std::numeric_limits<double>::max();
183 double chi2=std::numeric_limits<double>::max();
184 switch(c->category()){
186 chi1 = fit1PhotonCluster(c,&point0);
187 chi2 = fit2PhotonCluster(c,&point1,&point2);
190 chi1 = fit1PhotonCluster(c,&point0);
193 chi2 = fit2PhotonCluster(c,&point1,&point2);
197 LOG_WARN <<
"Unknown cluster category=" << c->category() << endm;
200 c->setChi2Ndf1Photon(chi1);
201 c->setChi2Ndf2Photon(chi2);
205 p0->setDetectorId(det);
207 p0->setNParentClusterPhotons(1);
211 mFcsCollection->addPoint(det,p0);
215 p1->setDetectorId(det);
217 p1->setNParentClusterPhotons(2);
221 mFcsCollection->addPoint(det,p1);
224 p2->setDetectorId(det);
226 p2->setNParentClusterPhotons(2);
230 mFcsCollection->addPoint(det,p2);
237 int np = points.size();
238 for(
int i=0; i<np; i++){
249 mMinuit.SetFCN(minimizationFunctionNPhoton);
251 if(mMinuit.GetNumFixedPars() > 0) {mMinuit.mnfree(0);}
254 double e=c->energy();
255 double dx=m_PH1_Delta_X;
256 double de=m_PH1_Delta_E;
257 const std::vector<TString> names = {
"np",
"x",
"y",
"e"};
260 mMinuit.DefineParameter(0,
"np", one, zero, one, one);
261 mMinuit.DefineParameter(1,
"x", x, dx/5, x-dx, x+dx);
262 mMinuit.DefineParameter(2,
"y", y, dx/5, y-dx, y+dx);
263 mMinuit.DefineParameter(3,
"e", e, e*(1-de)/5, e/de, e*de);
266 if(m_PH1_FixEnergy==1) mMinuit.FixParameter(3);
270 double arguments[2]={1000.0,1.0};
271 mMinuit.mnexcm(
"MIGRAD", arguments, 2, err);
273 if(mMinuit.GetStatus() == 0){
274 double par[4],perr[4],g[4];
275 for(
int i=0; i<4; i++){ mMinuit.GetParameter(i, par[i], perr[i]); }
278 p->setEnergy(par[3]);
279 mMinuit.Eval(4, g, chi2, par, err);
287 mMinuit.SetFCN(minimizationFunction2Photon);
289 if(mMinuit.GetNumFixedPars() > 0) {mMinuit.mnfree(0);}
292 double smax= c->sigmaMax();
294 double d=std::max(m_PH2_StartDggFactor*smax,0.5);
297 double e=c->energy();
298 double dx=m_PH2_Delta_X;
299 double ddl=d*m_PH2_Low_Dgg;
300 double ddh=d*m_PH2_High_Dgg;
301 double dt=m_PH2_MaxTheta_F;
302 double de=m_PH2_Delta_E;
303 mMinuit.mnparm(0,
"np", 2.0, 0.0, 2.0, 2.0, err);
304 mMinuit.mnparm(1,
"x", x, dx/5, x-dx, x+dx, err);
305 mMinuit.mnparm(2,
"y", y, dx/5, y-dx, y+dx, err);
306 mMinuit.mnparm(3,
"dgg", d, d*0.05, ddl, ddh, err);
307 mMinuit.mnparm(4,
"theta", t, dt/5, t-dt, t+dt, err);
308 mMinuit.mnparm(5,
"zgg", z, 0.1, -0.99, 0.99, err);
309 mMinuit.mnparm(6,
"etot", e, e*(1-de)/5, e/de, e*de, err);
310 mMinuit.FixParameter(0);
312 if(m_PH2_FixTheta==1) mMinuit.FixParameter(4);
313 if(m_PH2_FixEnergy==1) mMinuit.FixParameter(6);
317 double arguments[2]={1000.0,1.0};
318 mMinuit.mnexcm(
"MIGRAD", arguments, 2, err);
320 if(mMinuit.GetStatus() == 0) {
321 double par[7],perr[7],g[7];
322 for(
int i=0; i<7; i++){ mMinuit.GetParameter(i, par[i], perr[i]); }
329 double x1 = x + cos(t)*d*(1.0-z)/2.0;
330 double y1 = y + sin(t)*d*(1.0-z)/2.0;
331 double e1 = e*(1.0+z)/2.0;
332 double x2 = x - cos(t)*d*(1.0+z)/2.0;
333 double y2 = y - sin(t)*d*(1.0+z)/2.0;
334 double e2 = e*(1.0-z)/2.0;
341 mMinuit.Eval(7, g, chi2, par, 1);
347 void StFcsPointMaker::minimizationFunctionNPhoton(
int& npara,
double* grad,
double& fval,
double* para,
int){
349 const int nPhotons =
static_cast<int>(para[0]);
350 for(
int i=0; i<mNHit; i++){
351 double expected = 0.0;
352 for (
int j=0; j<nPhotons; j++){
354 expected += para[k+3] * energyDepositionInTower(mX[i], mY[i], para[k+1], para[k+2]);
356 const double measured = mE[i];
357 const double deviation = measured - expected;
358 const double ratio = measured / mEtot;
359 const double err = 0.01 + 0.03 * pow(ratio, 1.0-0.001*mEtot) * pow(1.0-ratio, 1.0-0.007*mEtot)*mEtot;
360 fval += deviation * deviation / err;
363 fval = std::max(fval, 0.);
368 void StFcsPointMaker::minimizationFunction2Photon(
int& npara,
double* grad,
double& fval,
double* para,
int){
370 const double dgg = para[3];
371 const double zgg = para[5];
372 const double angle = para[4];
373 double oldPara[7] = {
375 para[1] + cos(angle) * dgg * (1 - zgg) / 2.0,
376 para[2] + sin(angle) * dgg * (1 - zgg) / 2.0,
377 para[6] * (1 + zgg) / 2.0,
378 para[1] - cos(angle) * dgg * (1 + zgg) / 2.0,
379 para[2] - sin(angle) * dgg * (1 + zgg) / 2.0,
380 para[6] * (1 - zgg) / 2.0
383 minimizationFunctionNPhoton(npara, grad, fval, oldPara, 0);
391 double StFcsPointMaker::energyDepositionInTower(
double x,
double y,
double xun,
double yun){
393 for(
int i=0; i<6; i++){
395 if(mShowerShapeParameters[istart]>0.0){
396 double xc = xun * mShowerShapeParameters[istart+7];
397 double yc = yun * mShowerShapeParameters[istart+7];
398 sum += energyDepositionInTowerSingleLayer(x-xc,y-yc,&mShowerShapeParameters[istart]);
StLorentzVectorD getLorentzVector(const StThreeVectorD &xyz, float energy, float zVertex=0.0)
Get get 4 vector assuing m=0 and taking beamline from DB.
virtual void Clear(Option_t *option="")
User defined functions.
StThreeVectorD getDetectorOffset(int det, double zdepth=-1) const
Utility functions related to DetectorPosition.
StThreeVectorD getStarXYZfromColumnRow(int det, float col, float row, float FcsZ=-1.0) const
get the STAR frame cooridnates from other way
float getZDepth(int det) const
get the Y width of the cell
float getXWidth(int det) const
get the angle of the detector
void getLocalXYinCell(StFcsHit *hit, float &x, float &y) const
getting XY in local cell coordinate
void Clear(Option_t *option="")
User defined functions.
float getDetectorAngle(int det) const
This is the vector normal to the detector plane.