00001 #include "stdlib.h"
00002 #include "math.h"
00003 #include <iostream>
00004 #include <vector>
00005 #include <map>
00006
00007 #include "StMCFilter/StGenParticle.h"
00008 #include "StMCFilter/StBemcGammaFilter.h"
00009
00010
00011
00012
00013
00014
00015
00016 static StBemcGammaFilter bemcGammaFilter;
00017
00018 using namespace std;
00019
00021 bool comparePhi(kinematics A, kinematics B) { return A.phi < B.phi ? true : false; }
00022
00024
00025 StBemcGammaFilter::StBemcGammaFilter(): StMCFilter("bemcGammaFilter")
00026 {
00027
00028
00029 mConeRadius = 0.12;
00030 mSeedThreshold = 5.0;
00031 mClusterThreshold = 6.55;
00032 mEtaLow = -1.05;
00033 mEtaHigh = 1.05;
00034 mMaxVertex = 80;
00035
00036 }
00037
00041
00042 void StBemcGammaFilter::parseConfig(string attr, float val)
00043 {
00044
00045 if(attr == "ConeRadius")
00046 {
00047 cout << "StBemcGammaFilter::parseConfig() - Setting mConeRadius to " << val << endl;
00048 mConeRadius = val;
00049 }
00050 else if(attr == "SeedThreshold")
00051 {
00052 cout << "StBemcGammaFilter::parseConfig() - Setting mSeedThreshold to " << val << endl;
00053 mSeedThreshold = val;
00054 }
00055 else if(attr == "ClusterThreshold")
00056 {
00057 cout << "StBemcGammaFilter::parseConfig() - Setting mClusterThreshold to " << val << endl;
00058 mClusterThreshold = val;
00059 }
00060 else if(attr == "EtaLow")
00061 {
00062 cout << "StBemcGammaFilter::parseConfig() - Setting mEtaLow to " << val << endl;
00063 mEtaLow = val;
00064 }
00065 else if(attr == "EtaHigh")
00066 {
00067 cout << "StBemcGammaFilter::parseConfig() - Setting mEtaHigh to " << val << endl;
00068 mEtaHigh = val;
00069 }
00070 else if(attr == "MaxVertex")
00071 {
00072 cout << "StBemcGammaFilter::parseConfig() - Setting mMaxVertex to " << val << endl;
00073 mMaxVertex = val;
00074 }
00075 else
00076 {
00077 cout << "StBemcGammaFilter::parseConfig() - " << attr << " is not an existing parameter!" << endl;
00078 }
00079
00080 return;
00081
00082 }
00083
00087
00088 int StBemcGammaFilter::RejectGT(const StGenParticleMaster &ptl) const
00089 {
00090
00091
00092 const StGenParticle* track = 0;
00093
00094 double p[4] = {0, 0, 0, 0};
00095 double v[3] = {0, 0, 0};
00096
00097
00098 track = ptl(0);
00099 track->Vertex(v);
00100 if(fabs(v[2]) > mMaxVertex) return 1;
00101
00102
00103 double E = 0;
00104 double particleEt = 0;
00105 double detectorEt = 0;
00106 double detectorEta = 0;
00107 double detectorPhi = 0;
00108
00109 int id = 0;
00110 bool hadronFlag = 0;
00111
00112 double rSmd = 230.705;
00113 double rSmd2 = rSmd * rSmd;
00114
00115 double pT2 = 0;
00116 double pdotv = 0;
00117 double pcrossv = 0;
00118 double N = 0;
00119 double rho2 = 0;
00120
00121 double pi = 3.141592653589793;
00122
00123 map<double, kinematics> seedTracks;
00124 map<double, kinematics> eventTracks;
00125
00126
00127 for(int i = 0; i < ptl.Size(); ++i)
00128 {
00129
00130 track = ptl(i);
00131 if(!track) continue;
00132
00133
00134 if(track->GetStatusCode() != 1) continue;
00135
00136 id = track->GetPdgCode();
00137 E = track->Energy();
00138
00139
00140
00141
00142
00143
00144 hadronFlag = abs(id) != 22 && abs(id) != 111 && abs(id) != 221 && abs(id) != 11;
00145 hadronFlag &= id != -2212 && id != -2112;
00146
00147 if(hadronFlag) E *= 0.85;
00148
00149
00150 track->Vertex(v);
00151 track->Momentum(p);
00152
00153 pT2 = p[0] * p[0] + p[1] * p[1];
00154 particleEt = E * sqrt( pT2 / (pT2 + p[2] * p[2]) );
00155
00156
00157 pdotv = p[0] * v[0] + p[1] + v[1];
00158 pcrossv = p[0] * v[1] - p[1] * v[0];
00159 N = ( - pdotv + sqrt( pT2 * rSmd2 - pcrossv ) ) / pT2;
00160
00161 for(unsigned int j = 0; j < 3; ++j) p[j] = N * p[j] + v[j];
00162
00163 rho2 = p[0] * p[0] + p[1] * p[1];
00164
00165 detectorEt = E * sqrt( rho2 / (rho2 + p[2] * p[2] ) );
00166 detectorEta = - log( sqrt(rho2) / ( sqrt( rho2 + p[2] * p[2] ) + p[2] ) );
00167 detectorPhi = atan2(p[1], p[0]);
00168
00169
00170 if(detectorEta < mEtaLow) continue;
00171 if(detectorEta > mEtaHigh) continue;
00172
00173
00174 if(E > mSeedThreshold) seedTracks[detectorPhi] = kinematics(E, detectorEta, detectorPhi);
00175
00176
00177 eventTracks[detectorPhi] = kinematics(particleEt, detectorEta, detectorPhi);
00178
00179 }
00180
00181
00182
00183
00184 map<double, kinematics>::iterator itSeed;
00185 map<double, kinematics>::iterator itEvent;
00186
00187 double phiLeft = 0;
00188 double phiRight = 0;
00189
00190 double dEta = 0;
00191 double dPhi = 0;
00192 double R = 0;
00193
00194 double EtSum = 0;
00195
00196 itEvent = eventTracks.begin();
00197
00198 for(itSeed = seedTracks.begin(); itSeed != seedTracks.end(); ++itSeed)
00199 {
00200
00201 EtSum = 0;
00202 dPhi = 0;
00203
00204
00205 phiLeft = (itSeed->first) - mConeRadius;
00206 phiRight = (itSeed->first) + mConeRadius;
00207
00208
00209 while(itEvent != eventTracks.begin())
00210 {
00211 if(itEvent->first > phiLeft) --itEvent;
00212 else break;
00213 }
00214
00215
00216 if(phiLeft < - pi)
00217 {
00218
00219
00220 map<double, kinematics>::reverse_iterator rit = eventTracks.rbegin();
00221 if(rit->first > phiLeft + 2 * pi)
00222 {
00223
00224
00225 phiLeft = phiLeft + 2 * pi;
00226 phiRight = phiRight + 2 * pi;
00227
00228
00229 while(rit->first > phiLeft) ++rit;
00230
00231
00232
00233
00234 itEvent = (++rit).base();
00235
00236 }
00237
00238 }
00239
00240
00241 while(itEvent->first < phiLeft) ++itEvent;
00242
00243
00244 dPhi = 0;
00245
00246 while(itEvent->first < phiRight)
00247 {
00248
00249 dEta = itSeed->second.eta - itEvent->second.eta;
00250 dPhi = acos( cos( itSeed->first - itEvent->first) );
00251 R = sqrt( dEta * dEta + dPhi * dPhi );
00252
00253 if(R < mConeRadius) EtSum += itEvent->second.Et;
00254
00255
00256 ++itEvent;
00257
00258
00259 if(itEvent == eventTracks.end())
00260 {
00261
00262
00263 phiLeft = phiLeft - 2 * pi;
00264 phiRight = phiRight - 2 * pi;
00265
00266 itEvent = eventTracks.begin();
00267
00268 }
00269
00270 }
00271
00272
00273
00274 if(EtSum > mClusterThreshold) return 0;
00275
00276 }
00277
00278
00279 return 1;
00280
00281 }