00001
00002
00003 #include <cstdlib>
00004 #include <cmath>
00005 #include <iostream>
00006 #include <vector>
00007 #include <map>
00008 #include <algorithm>
00009
00010 using namespace std;
00011
00012 #include "StMCFilter/StGenParticle.h"
00013 #include "StMCFilter/StEemcGammaFilter.h"
00014
00015 #include "TLorentzVector.h"
00016
00017
00018
00019
00020
00021
00022 static StEemcGammaFilter eemcGammaFilter;
00023
00024
00026
00028
00029 const double StEemcGammaFilter::mConeRadius = 0.22;
00030
00031
00032 const double StEemcGammaFilter::mSeedThreshold = 3.8;
00033
00034
00035 const double StEemcGammaFilter::mClusterThreshold = 5.0;
00036
00037
00038 const double StEemcGammaFilter::mEtaLow = 0.95;
00039
00040
00041 const double StEemcGammaFilter::mEtaHigh =2.1;
00042
00043
00044 const double StEemcGammaFilter::mMaxVertex = 120.0;
00045
00046
00047 const double StEemcGammaFilter:: mCalDepth = 279.5;
00048
00049
00050
00051
00052 const double StEemcGammaFilter:: mHadronScale = 1.0;
00053
00054
00055
00056 const double StEemcGammaFilter:: mMinPartEnergy = 0.00001;
00057
00058
00059 bool operator>(const TLorentzVector& v1, const TLorentzVector& v2)
00060 {
00061 return v1.E() > v2.E();
00062 }
00063
00064
00066
00068
00069 StEemcGammaFilter::StEemcGammaFilter(): StMCFilter("eemcGammaFilter.1.00")
00070 {
00071
00072
00073
00074 mPrintLevel = 0;
00075
00076
00077
00078
00079 mFilterMode = 1;
00080
00081 if (!mFilterMode)
00082 cout<<"StEemcGammaFilter:: running the TEST mode (accepting all events). Set mFilterMode=1 to actually reject events"<< endl;
00083
00084 cout<<"StEemcGammaFilter::"
00085 <<" mConeRadius "<<mConeRadius
00086 <<" mSeedThreshold "<< mSeedThreshold
00087 <<" mClusterThreshold "<< mClusterThreshold
00088 <<" mEtaLow "<<mEtaLow
00089 <<" mEtaHigh "<<mEtaHigh
00090 <<" mMaxVertex "<<mMaxVertex
00091 <<endl;
00092 cout<<"StEemcGammaFilter::"
00093 <<" mCalDepth " << mCalDepth
00094 <<" mMinPartEnergy " <<mMinPartEnergy
00095 <<" mHadronScale " <<mHadronScale
00096 <<" mFilterMode " <<mFilterMode
00097 <<" mPrintLevel "<<mPrintLevel
00098 <<endl;
00099
00100
00101 }
00102
00103
00105
00107
00108 int StEemcGammaFilter::RejectGT(const StGenParticleMaster &ptl) const
00109 {
00110
00111
00112
00113 vector<TLorentzVector> seedTracksDet;
00114 vector<TLorentzVector> eventTracksDet;
00115
00116
00117
00118
00119 float zVertex = 0;
00120 int acceptFlag= 0;
00121
00122 const StGenParticle* track = 0;
00123
00124 for(int i = 0; i < ptl.Size(); ++i)
00125 {
00126
00127 track = ptl(i);
00128 if(!track) continue;
00129
00130
00131 if(track->GetStatusCode() != 1) continue;
00132
00133 int id = track->GetPdgCode();
00134
00135
00136 double p[4] = {0, 0, 0, 0};
00137 double v[3] = {0, 0, 0};
00138
00139 track->Momentum(p);
00140 track->Vertex(v);
00141 zVertex = v[2];
00142
00143 if(fabs(v[2])>mMaxVertex)
00144 {
00145 if(mPrintLevel>=1) cout<<"Rejecting event with extreme vertex of "<<v[2]<<endl;
00146 if (mFilterMode==0 || mPrintLevel>=1)
00147 if (acceptFlag==0) { cout<<"StEemcGammaFilter::RejectGT() - Reject!"<<endl; acceptFlag = -1;}
00148 if (mFilterMode) return mFilterMode;
00149 }
00150
00151
00152
00153 TLorentzVector particleV(p[0],p[1],p[2],p[3]);;
00154
00155 if(mPrintLevel>=2)
00156 {
00157 cout<<"Particle vector px py pz E Et:\n";
00158 cout<<particleV.Px()<<" "<<particleV.Py()<<" "<<particleV.Pz()
00159 <<" "<<particleV.E()<<" "<<particleV.Et()<<endl;
00160 }
00161
00162
00163
00164
00165 double scale = (mCalDepth-v[2]) / fabs(p[2]);
00166 for(unsigned int j = 0; j < 3; ++j) p[j] = p[j] * scale + v[j];
00167
00168 TVector3 positionV(p[0],p[1],p[2]);
00169
00170 positionV.SetMag(particleV.P());
00171
00172 TLorentzVector detectorV(positionV,p[3]);
00173
00174
00175 if(mPrintLevel>=2)
00176 {
00177 cout<<"Detector vector px py pz E Et:\n";
00178 cout<<detectorV.Px()<<" "<<detectorV.Py()<<" "<<detectorV.Pz()
00179 <<" "<<detectorV.E()<<" "<<detectorV.Et()<<endl;
00180 }
00181
00182
00183
00184
00185
00186
00187
00188
00189 bool hadronFlag = abs(id) != 22 && abs(id) != 111 && abs(id) != 221 && abs(id) != 11;
00190
00191
00192 hadronFlag &= id != -2212 && id != -2112;
00193
00194
00195 if(hadronFlag){
00196 particleV*=mHadronScale;
00197 detectorV*=mHadronScale;
00198 if(mPrintLevel>=2)
00199 cout<<"Particle with id "<< id<<" is a hadron - E was "<<track->Energy()<<" and is now "<<detectorV.Energy()<<endl;
00200 }
00201
00202
00203
00204
00205
00206
00207 if(particleV.E()<mMinPartEnergy){
00208 if(mPrintLevel>=1)
00209 cout<<"Throwing out track with energy "<<particleV.E()
00210 <<" from particle with id "<<id<<endl;
00211 continue;
00212 }
00213
00214
00215
00216
00217 if(detectorV.Eta() < mEtaLow || detectorV.Eta() > mEtaHigh) continue;
00218
00219
00220
00221
00222 if(particleV.Energy() > mSeedThreshold)
00223 {
00224 seedTracksDet.push_back(detectorV);
00225 if(mPrintLevel>=1)
00226 {
00227 cout<<"Seed track stored with E "<<particleV.Energy()
00228 <<" et "<<particleV.Et()
00229 <<" detector eta "<<detectorV.Eta()
00230 <<" and detector phi "<<detectorV.Phi()<<endl;
00231 cout<<"StStRoot/StMCFilter/StGenParticle Print :"<<endl;
00232 track->Print();
00233 }
00234 }
00235
00236
00237 eventTracksDet.push_back(detectorV);
00238
00239
00240 }
00241
00242
00243
00244
00245
00246
00247 if(seedTracksDet.empty()){
00248 if(mPrintLevel>=1)
00249 cout<<"Did not find any fiducial seed tracks passing the energy threshold.\n";
00250 if (mFilterMode==0 || mPrintLevel>=1)
00251 if(mPrintLevel>=1) {if (acceptFlag==0) cout<<"StEemcGammaFilter::RejectGT() - Reject!"<<endl;}
00252 acceptFlag += -10;
00253 if(mPrintLevel>=1)
00254 {
00255 cout << "StEemcGammaFilter:: max clusters: seed: " << acceptFlag << " " << zVertex << " "
00256 << 0.0 <<" "<< 0.0<<" "<<0.0<<" "<<0.0<<" "<<0.0
00257 << " :Et: "
00258 << 0.0 <<" "<< 0.0<<" "<<0.0<<" "<<0.0<<" "<<0.0<< endl;
00259 }
00260 return mFilterMode;
00261 }
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278 sort(seedTracksDet.begin(),seedTracksDet.end(),greater<TLorentzVector>());
00279
00280 TLorentzVector maxSeedCluster(0.,0.,0.,0.);
00281 TLorentzVector maxEtCluster(0.,0.,0.,0.);
00282 float maxEtClusterValue = 0;
00283 float maxSeedClusterSeedEnergy = 0;
00284 float maxEtClusterSeedEnergy = 0;
00285
00286 for(unsigned int iseed = 0; iseed<seedTracksDet.size(); iseed++)
00287 {
00288 if(mPrintLevel>=1)
00289 {
00290 cout<<"Begin looping seed track with energy "<<seedTracksDet[iseed].Energy()
00291 <<" detector eta "<<seedTracksDet[iseed].Eta()
00292 <<" and detector phi "<<seedTracksDet[iseed].Phi()<<endl;
00293 }
00294
00295 TLorentzVector clusterV(0.,0.,0.,0.);
00296
00297
00298
00299 for(unsigned int ievent = 0; ievent<eventTracksDet.size(); ievent++)
00300 {
00301
00302
00303 double dEta = seedTracksDet[iseed].Eta()-eventTracksDet[ievent].Eta();
00304 double dPhi = acos( cos( seedTracksDet[iseed].Phi() - eventTracksDet[ievent].Phi()) );
00305 double R = sqrt( dEta * dEta + dPhi * dPhi );
00306
00307
00308
00309 TLorentzVector &trackV = eventTracksDet[ievent];
00310
00311
00312 if(R <= mConeRadius) {
00313 clusterV+=trackV;
00314 if(mPrintLevel>=1)
00315 {
00316 cout<<"Track accepted with energy "<<trackV.Energy()
00317 <<" et "<<trackV.Et()
00318 <<" dEta "<<dEta
00319 <<" dPhi "<<dPhi
00320 <<" R "<<R<<endl;
00321 cout<<"EtSum now "<<clusterV.Et()<<endl;
00322 }
00323 }
00324 }
00325 if (clusterV.Et() > maxEtClusterValue )
00326 {
00327 maxEtClusterValue = clusterV.Et();
00328 maxEtCluster = clusterV;
00329 maxEtClusterSeedEnergy = seedTracksDet[iseed].Energy();
00330 }
00331 if (iseed==0)
00332 {
00333 maxSeedCluster = clusterV;
00334 maxSeedClusterSeedEnergy = seedTracksDet[iseed].Energy();
00335 }
00336
00337
00338
00339
00340 if(clusterV.Et() > mClusterThreshold)
00341 {
00342 if(mPrintLevel>=1)
00343 cout<<"Cluster accepted with et "<<clusterV.Et()
00344 <<" eta "<<clusterV.Eta()<< " and phi "<<clusterV.Phi()<<endl;
00345
00346 if (mFilterMode==0 || mPrintLevel>=1)
00347 if (acceptFlag==0)
00348 {
00349 if(mPrintLevel>=1) cout << "StEemcGammaFilter::RejectGT() - Accept!" << endl;
00350 acceptFlag= 1;
00351 }
00352 if (mFilterMode) return 0;
00353 }
00354
00355 }
00356
00357
00358
00359 if (mFilterMode==0 || mPrintLevel>=1)
00360 {if (acceptFlag==0) if(mPrintLevel>=1) cout << "StEemcGammaFilter::RejectGT() - Reject!" << endl;}
00361 if (acceptFlag==0) acceptFlag = -100;
00362 if(mPrintLevel>=1)
00363 {
00364 cout << "StEemcGammaFilter:: max clusters: seed: " << acceptFlag << " " << zVertex << " "
00365 << maxSeedClusterSeedEnergy<<" "<< maxSeedCluster.E()<<" "<<maxSeedCluster.Et()<<" "<<maxSeedCluster.Eta()<<" "<<maxSeedCluster.Phi()
00366 << " :Et: "
00367 << maxEtClusterSeedEnergy<<" "<<maxEtCluster.E()<<" "<<maxEtCluster.Et()<<" "<<maxEtCluster.Eta()<<" "<<maxEtCluster.Phi()
00368 << endl;
00369 }
00370
00371 return mFilterMode;
00372 }
00373
00374
00375
00376
00377
00378