62 #include "StFcsClusterMaker.h"
64 #include "StLorentzVectorF.hh"
66 #include "StMessMgr.h"
67 #include "StEvent/StEventTypes.h"
68 #include "StEvent/StFcsHit.h"
69 #include "StEvent/StFcsCluster.h"
70 #include "StFcsDbMaker/StFcsDb.h"
71 #include "tables/St_g2t_track_Table.h"
73 #include "StMuDSTMaker/COMMON/StMuTypes.hh"
74 #include "StMuDSTMaker/COMMON/StMuDst.h"
75 #include "StMuDSTMaker/COMMON/StMuEvent.h"
85 StFcsClusterMaker::~StFcsClusterMaker() { }
91 int StFcsClusterMaker::InitRun(
int runNumber) {
93 LOG_DEBUG <<
"StFcsClusterMaker initializing run" << endm;
95 mDb =
static_cast<StFcsDb*
>(GetDataSet(
"fcsDb"));
97 LOG_ERROR <<
"StFcsClusterMaker initializing failed due to no StFcsDb" << endm;
100 return StMaker::InitRun(runNumber);
104 LOG_DEBUG <<
"StFcsClusterMaker Make!!!" << endm;
108 if (event) mFcsCollection =
event->fcsCollection();
109 if(!mFcsCollection) {
110 LOG_WARN <<
"StFcsClusterMaker did not find fcsCollection in StEvent" << endm;
114 for(
int det=0; det<=kFcsHcalSouthDetId; det++) {
116 mNeighborDistance = mNeighborDistance_Ecal;
117 mDistanceAdvantage = mDistanceAdvantage_Ecal;
118 mTowerEThreSeed = mTowerEThreSeed_Ecal;
119 mTowerEThreshold = mTowerEThreshold_Ecal;
120 mTowerEThreMoment = mTowerEThreMoment_Ecal;
121 mTowerERatio2Split = mTowerERatio2Split_Ecal;
124 mNeighborDistance = mNeighborDistance_Hcal;
125 mDistanceAdvantage = mDistanceAdvantage_Hcal;
126 mTowerEThreSeed = mTowerEThreSeed_Hcal;
127 mTowerEThreshold = mTowerEThreshold_Hcal;
128 mTowerEThreMoment = mTowerEThreMoment_Hcal;
129 mTowerERatio2Split = mTowerERatio2Split_Hcal;
133 if(GetDebug()>0) mFcsCollection->print(3);
137 int StFcsClusterMaker::makeCluster(
int det) {
138 StSPtrVecFcsHit& hits = mFcsCollection->hits(det);
139 StSPtrVecFcsCluster& clusters = mFcsCollection->clusters(det);
141 int nhit=hits.size();
142 for(
int i=0; i<nhit; i++) hits[i]->setCluster(0);
146 return b->energy() < a->energy();
150 return b->id() > a->id();
154 for(
int i=0; i<nhit; i++){
156 float e=hit->energy();
157 if(e < mTowerEThreshold && mSortById==0)
break;
158 float neighborClusterId=-1;
159 float minDistance=999.0;
160 int ncluster = clusters.size();
162 StPtrVecFcsCluster neighbor;
163 for(
int j=0; j<ncluster; j++){
165 float neighborTowerE = isNeighbor(hit,clu);
166 if(neighborTowerE>0.0) {
167 neighbor.push_back(clu);
169 if(neighborTowerE * mTowerERatio2Split > e){
170 float d = distance(hit,clu);
171 if(d * mDistanceAdvantage < minDistance){
179 if(neighborClusterId==-1) {
181 if(e >= mTowerEThreSeed){
183 cluster->setId(ncluster);
184 cluster->setDetectorId(det);
185 cluster->hits().push_back(hit);
186 hit->setCluster(cluster);
187 updateCluster(cluster);
188 mFcsCollection->addCluster(det,cluster);
189 neighbor.push_back(cluster);
198 cluster = clusters[neighborClusterId];
199 cluster->hits().push_back(hit);
200 hit->setCluster(cluster);
201 updateCluster(cluster);
204 for(
int k=0; k<nNeighbor-1; k++){
206 for(
int l=k+1; l<nNeighbor; l++){
208 clu1->addNeighbor(clu2);
209 clu2->addNeighbor(clu1);
216 int nc = clusters.size();
217 for(
int j=0; j<nc; j++){
223 int ret=clusterMomentAnalysis(clu,mTowerEThreMoment);
224 if(ret==
kStErr) ret=clusterMomentAnalysis(clu,0.0);
230 g2t_track_st* g2ttrk=0;
231 St_g2t_track* trackTable =
static_cast<St_g2t_track*
>(GetDataSet(
"g2t_track"));
233 LOG_INFO <<
"g2t_track Table not found" << endm;
235 const int nTrk = trackTable->GetNRows();
236 LOG_INFO << Form(
"g2t_track table has %d tracks",nTrk) << endm;
238 g2ttrk = trackTable->GetTable();
240 LOG_INFO <<
"g2t_track GetTable failed" << endm;
247 int nh = hits.size();
248 for(
int i=0; i<nh; i++){
253 LOG_INFO << Form(
"Det=%1d Id=%3d E=%8.3f Parent Id=%4d Pid=%4d E=%8.3f Frc=%6.3f N=%d",
254 det,hit->id(),hit->energy(),trk->id,trk->ge_pid,trk->e,frc,ntrk)<<endm;
255 const g2t_track_st* ptrk = mDb->getPrimaryG2tTrack(hit,g2ttrk,frc,ntrk);
256 LOG_INFO << Form(
"Det=%1d Id=%3d E=%8.3f Primary Id=%4d Pid=%4d E=%8.3f Frc=%6.3f N=%d",
257 det,hit->id(),hit->energy(),ptrk->id,ptrk->ge_pid,ptrk->e,frc,ntrk)<<endm;
259 int nc = clusters.size();
260 for(
int j=0; j<nc; j++){
263 LOG_INFO << Form(
"Det=%1d C#=%3d E=%8.3f Parent Id=%4d Pid=%4d E=%8.3f Frc=%6.3f N=%d",
264 det,j,clu->energy(),trk->id,trk->ge_pid,trk->e,frc,ntrk)<<endm;
265 const g2t_track_st* ptrk = mDb->getPrimaryG2tTrack(clu,g2ttrk,frc,ntrk);
266 LOG_INFO << Form(
"Det=%1d C#=%3d E=%8.3f Primary Id=%4d Pid=%4d E=%8.3f Frc=%6.3f N=%d",
267 det,j,clu->energy(),ptrk->id,ptrk->ge_pid,ptrk->e,frc,ntrk)<<endm;
278 int nhit = clu->hits().size();
280 for(
int i=0; i<nhit; i++){
284 if(ehp==0) thr=mNeighborDistance_Ecal;
285 if(ehp==1) thr=mNeighborDistance_Hcal;
286 float d = distance(hit,h);
287 float e = h->energy();
288 if(d < thr && e>ne) ne=e;
295 int det1=hit1->detectorId();
296 int det2=hit2->detectorId();
297 if(det1 != det2)
return 999.0;
303 return sqrt(dx*dx + dy*dy);
308 int det1=hit->detectorId();
309 int det2=clu->detectorId();
310 if(det1 != det2)
return 999.0;
313 float dx = x - clu->x();
314 float dy = y - clu->y();
315 return sqrt(dx*dx + dy*dy);
319 void StFcsClusterMaker::updateCluster(
StFcsCluster* clu){
320 int nhit=clu->hits().size();
321 double etot=0.0, xe=0.0, ye=0.0;
322 double wtot=0.0, xw=0.0, yw=0.0;
323 for(
int i=0; i<nhit; i++){
327 double e= hit->energy();
328 double w=log(e + 1.0 - mTowerEThreMoment);
330 etot+= e; xe += x*e; ye += y*e;
331 wtot+= w; xw += x*w; yw += y*w;
333 clu->setNTowers(nhit);
334 clu->setEnergy(etot);
348 int StFcsClusterMaker::clusterMomentAnalysis(
StFcsCluster* clu,
float ecut){
349 int nhit=clu->hits().size();
350 double wtot=0.0, xx=0.0, yy=0.0, sx=0.0, sy=0.0, sxy=0.0;
351 for(
int i=0; i<nhit; i++){
355 double e= hit->energy();
356 double w=log(e + 1.0 - ecut);
370 clu->setSigmaMin(0.0);
371 clu->setSigmaMax(0.0);
377 double sigx = sqrt(fabs(sx / wtot - std::pow(x, 2.0)));
378 double sigy = sqrt(fabs(sy / wtot - std::pow(y, 2.0)));
379 double sigxy = sxy/wtot - x*y;
380 double dsig2 = sigx*sigx - sigy*sigy;
381 double aA = sqrt(dsig2 * dsig2 + 4.0 * sigxy * sigxy) + dsig2;
382 double bB = 2.0 * sigxy;
383 if (sigxy < 1e-10 && aA < 1e-10) {
384 bB = sqrt(dsig2 * dsig2 + 4.0 * sigxy * sigxy) - dsig2;
387 double theta = atan2(bB, aA);
388 while (theta > M_PI / 2.0) {
391 while (theta < -M_PI / 2.0) {
394 clu->setTheta(theta);
395 clu->setSigmaMin(getSigma(clu, theta, ecut));
396 clu->setSigmaMax(getSigma(clu, theta - M_PI/2.0, ecut));
401 float StFcsClusterMaker::getSigma(
StFcsCluster* clu,
double theta,
float ecut){
404 TVector2 vaxis(cos(theta), sin(theta));
406 int nhit=clu->hits().size();
407 for (
int i=0; i<nhit; i++){
409 int det=hit->detectorId();
413 TVector2 v1(x - clu->x(), y - clu->y());
416 double dis = (v1.Norm(vaxis)).Mod();
418 double w = log(hit->energy() + 1.0 - ecut);
421 sigma += w * dis * dis;
424 return wtot > 0.0 ? (float)sqrt(sigma / wtot) : 0.0;
427 void StFcsClusterMaker::categorization(
StFcsCluster* cluster){
428 if(cluster->nTowers() < 5){
429 cluster->setCategory(1);
431 const double sigma=cluster->sigmaMax();
432 const double e =cluster->energy();
433 if(sigma > 1/2.5 + 0.003*e + 7.0/e){
434 cluster->setCategory(2);
435 }
else if(sigma < 1/2.1 - 0.001*e + 2.0/e){
436 cluster->setCategory(1);
438 cluster->setCategory(0);
StLorentzVectorD getLorentzVector(const StThreeVectorD &xyz, float energy, float zVertex=0.0)
Get get 4 vector assuing m=0 and taking beamline from DB.
void Clear(Option_t *option="")
User defined functions.
virtual void Clear(Option_t *option="")
User defined functions.
const g2t_track_st * getParentG2tTrack(StFcsHit *h, g2t_track_st *g2ttrk, float &fraction, int &ntrk, unsigned int order=0)
StThreeVectorD getStarXYZfromColumnRow(int det, float col, float row, float FcsZ=-1.0) const
get the STAR frame cooridnates from other way
void getLocalXYinCell(StFcsHit *hit, float &x, float &y) const
getting XY in local cell coordinate
int ecalHcalPres(int det) const
Ecal North=0, Ecal South=1, Hcal North=2, Hcal South=3, Pres=4/5.