00001 #define DIFF_CUT_OFF 1.
00002
00003 #include "StHbtMaker/Reader/StHbtAssociationReader.h"
00004 #include "StHbtMaker/Infrastructure/StHbtTrackCollection.hh"
00005 #include "StHbtMaker/Infrastructure/StHbtV0Collection.hh"
00006 #include "StEventUtilities/StuRefMult.hh"
00007
00008 #include "StHbtMaker/Infrastructure/StHbtEvent.hh"
00009 #include "StHbtMaker/Base/StHbtEventCut.h"
00010 #include "StHbtMaker/Base/StHbtTrackCut.h"
00011 #include "StHbtMaker/Base/StHbtV0Cut.h"
00012 #include "StHbtMaker/Base/StHbtKinkCut.h"
00013
00014 #include "StChain.h"
00015 #include "TOrdCollection.h"
00016
00017 #include "StEventTypes.h"
00018 #include "StParticleTypes.hh"
00019 #include "SystemOfUnits.h"
00020 #include "StTpcDedxPidAlgorithm.h"
00021 #include <math.h>
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include "StAssociationMaker/StAssociationMaker.h"
00036
00037 #include "StStrangeMuDstMaker/StStrangeEvMuDst.hh"
00038 #include "StStrangeMuDstMaker/StV0MuDst.hh"
00039
00040 #include "StMcEventTypes.hh"
00041 #include "StMcEvent.hh"
00042 #include "PhysicalConstants.h"
00043 #include "SystemOfUnits.h"
00044 #include "StThreeVector.hh"
00045 #include "StThreeVectorF.hh"
00046 #include "StThreeVectorD.hh"
00047
00048 #include "StChain.h"
00049 #include "St_DataSet.h"
00050 #include "St_DataSetIter.h"
00051
00052 #include "g2t_event.h"
00053 #include "g2t_ftp_hit.h"
00054 #include "g2t_svt_hit.h"
00055 #include "g2t_tpc_hit.h"
00056 #include "g2t_track.h"
00057 #include "g2t_vertex.h"
00058
00059 #include "tables/St_g2t_event_Table.h"
00060 #include "tables/St_g2t_ftp_hit_Table.h"
00061 #include "tables/St_g2t_svt_hit_Table.h"
00062 #include "tables/St_g2t_tpc_hit_Table.h"
00063 #include "tables/St_g2t_track_Table.h"
00064 #include "tables/St_g2t_vertex_Table.h"
00065
00066
00067
00068
00069
00070
00071
00072
00073 #include "StAssociationMaker/StTrackPairInfo.hh"
00074 #include "StParticleDefinition.hh"
00075 #include "StPhysicalHelix.hh"
00076
00077
00078 #ifndef ST_NO_NAMESPACES
00079 using namespace units;
00080 #endif
00081
00082 struct vertexFlag {
00083 StMcVertex* vtx;
00084 int primaryFlag; };
00085
00086
00087 StHbtAssociationReader::StHbtAssociationReader() : mPerfectPID(true) {
00088 mDiffCurrent = new StHbt1DHisto("Diff_current", " (p_real - p_mc ) / p_real ",100,-1.,1.);
00089 mDiff = new StHbt1DHisto("Diff", " (p_real - p_mc ) / p_real ",100,-1.,1.);
00090 mDiffMean = new StHbt1DHisto("Diff_mean", " mean of (p_real - p_mc ) / p_real ",100,-1.,1.);
00091 mDiffRMS = new StHbt1DHisto("Diff_sigma", " sigma of (p_real - p_mc ) / p_real ",100,0.,1.);
00092 eventNumber=0;
00093 mEventCut=0;
00094 mTrackCut=0;
00095 mReaderStatus = 0;
00096 mV0=0;
00097 }
00098
00099 StHbtAssociationReader::~StHbtAssociationReader(){
00100 cout << " StHbtAssociationReader::~StHbtAssociationReader() " << endl;
00101 if (mEventCut) delete mEventCut;
00102 if (mTrackCut) delete mTrackCut;
00103 }
00104
00105 StHbtString StHbtAssociationReader::Report(){
00106 StHbtString temp = "\n This is the StHbtAssociationReader\n";
00107 temp += "---> EventCuts in Reader: ";
00108 if (mEventCut) {
00109 temp += mEventCut->Report();
00110 }
00111 else {
00112 temp += "NONE";
00113 }
00114 temp += "\n---> TrackCuts in Reader: ";
00115 if (mTrackCut) {
00116 temp += mTrackCut->Report();
00117 }
00118 else {
00119 temp += "NONE";
00120 }
00121 temp += "\n";
00122 return temp;
00123 }
00124
00125 StHbtEvent* StHbtAssociationReader::ReturnHbtEvent(){
00126 cout << " **************************************************************************************" << endl;
00127 cout << " StHbtAssociationReader::ReturnHbtEvent() : Seconds elapsed since last call : " << difftime( time(0), timeStamp ) << endl;
00128 cout << " **************************************************************************************" << endl;
00129 timeStamp = time(0);
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139 StEvent* rEvent = (StEvent*) StMaker::GetChain()->GetDataSet("StEvent");
00140
00141 if (!rEvent){
00142 cout << "StHbtAssociationReader - No StEvent!!! " << endl;
00143 return 0;
00144 }
00145 cout << " StEvent " << endl;
00146
00147
00148
00149 StMcEvent* mEvent = 0;
00150
00151
00152
00153
00154
00155
00156
00157 mEvent = (StMcEvent*) StMaker::GetChain()->GetDataSet("StMcEvent");
00158
00159
00160 if (!mEvent){
00161 cout << "StHbtAssociationReader - No StMcEvent!!! " << endl;
00162 return 0;
00163 }
00164 cout << " McEvent " << endl;
00165
00166
00167
00168 StAssociationMaker* assoc = 0;
00169 assoc = (StAssociationMaker*) mTheAssociationMaker;
00170
00171 if (!assoc){
00172 cout << "StHbtAssociationReader - No StAssociationMaker!!! " << endl;
00173 cout << "StHbtAssociationReader - assoc " << assoc <<endl;
00174 return 0;
00175 }
00176 rcTpcHitMapType* theHitMap = 0;
00177 theHitMap = assoc->rcTpcHitMap();
00178 if (!theHitMap){
00179 cout << "StHbtAssociationReader - No tpcHitMap!!! " << endl;
00180 cout << "StHbtAssociationReader - theHitMap " << theHitMap <<endl;
00181 return 0;
00182 }
00183 rcTrackMapType* theTrackMap = 0;
00184 theTrackMap = assoc->rcTrackMap();
00185 if (!theTrackMap){
00186 cout << "StHbtAssociationReader - No trackMap!!! " << endl;
00187 cout << "StHbtAssociationReader - theTrackMap " << theTrackMap <<endl;
00188 return 0;
00189 }
00190 rcV0MapType* theV0Map = 0;
00191 theV0Map = assoc->rcV0Map();
00192 if (!theV0Map){
00193 cout << "StHbtAssociationReader - No v0Map!!! " << endl;
00194 cout << "StHbtAssociationReader - theV0Map " << theV0Map <<endl;
00195 return 0;
00196 }
00197
00198 if ( !(rEvent->primaryVertex()) ||
00199 (mEvent->primaryVertex()->position().x() == mEvent->primaryVertex()->position().y() &&
00200 mEvent->primaryVertex()->position().y() == mEvent->primaryVertex()->position().z() ) ||
00201 isnan(rEvent->primaryVertex()->position().x())
00202 ) {
00203 cout << "StHbtAssociationReader - bad vertex !!! " << endl;
00204 return 0;
00205 }
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216 cout << " **********************" << endl;
00217 cout << " StHbtAssociationReader" << endl;
00218 cout << " **********************" << endl;
00219 unsigned long mRunNumber = mEvent->runNumber();
00220 unsigned long rRunNumber = rEvent->runId();
00221 cout << " DST run: #" << rRunNumber << endl;
00222 cout << " MC run: #" << mRunNumber << endl;
00223 unsigned long rEventNumber = 0;
00224 unsigned long mEventNumber = mEvent->eventNumber();
00225 cout << " DST event: #" << rEventNumber << endl;
00226 cout << " MC event: #" << mEventNumber << endl;
00227 int rMult = rEvent->trackNodes().size();
00228 int mMult = mEvent->tracks().size();
00229 cout << " DST mult: #" << rMult << endl;
00230 cout << " MC mult: #" << mMult << endl;
00231 if ( !rEvent->primaryVertex() ) return 0;
00232 if ( !mEvent->primaryVertex() ) return 0;
00233 StHbtThreeVector rVertexPosition = rEvent->primaryVertex()->position();
00234 StHbtThreeVector mVertexPosition = mEvent->primaryVertex()->position();
00235 cout << " DST primary Vertex #" << rVertexPosition << endl;
00236 cout << " MC primary Vertex #" << mVertexPosition << endl;
00237
00238 cout << "StHbtAssociationReader::ReturnHbtEvent - We have " << rMult << " tracks to store - we skip tracks with nhits==0" << endl;
00239
00240 double pathlength;
00241 StHbtThreeVector p;
00242 StHbtThreeVector mp;
00243
00244 mDiffCurrent->Reset();
00245
00246 float diff=0;
00247
00248 StHbtEvent* hbtEvent = new StHbtEvent;
00249
00250 hbtEvent->SetEventNumber(rEventNumber);
00251 hbtEvent->SetUncorrectedNumberOfPositivePrimaries(uncorrectedNumberOfPositivePrimaries(*rEvent));
00252 hbtEvent->SetUncorrectedNumberOfNegativePrimaries(uncorrectedNumberOfNegativePrimaries(*rEvent));
00253 hbtEvent->SetCtbMult(0);
00254 hbtEvent->SetZdcAdcEast(0);
00255 hbtEvent->SetZdcAdcWest(0);
00256 hbtEvent->SetNumberOfTpcHits(0);
00257 hbtEvent->SetNumberOfTracks(rMult);
00258 hbtEvent->SetReactionPlane(0.);
00259 hbtEvent->SetReactionPlaneSubEventDifference(0.);
00260 hbtEvent->SetPrimVertPos(rVertexPosition);
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271 StTpcDedxPidAlgorithm* PidAlgorithm = new StTpcDedxPidAlgorithm();
00272
00273 if (!PidAlgorithm) cout << " StStandardHbtEventReader::ReturnHbtEvent() - Whoa!! No PidAlgorithm!! " << endl;
00274
00275
00276 StElectron* Electron = StElectron::instance();
00277 StPionPlus* Pion = StPionPlus::instance();
00278 StKaonPlus* Kaon = StKaonPlus::instance();
00279 StProton* Proton = StProton::instance();
00280
00281 {for (rcTrackMapIter tIter=theTrackMap->begin(); tIter!=theTrackMap->end(); ++tIter){
00282
00283 const StGlobalTrack* rTrack = (*tIter).first;
00284
00285 if (!rTrack) {
00286 continue;
00287 }
00288
00289 int nhits = rTrack->detectorInfo()->numberOfPoints(kTpcId);
00290
00291 if (nhits==0) {
00292
00293 continue;
00294 }
00295
00296
00297
00298
00299 int numberOfassociatedTracks = theTrackMap->count(rTrack);
00300 if (numberOfassociatedTracks !=1) {
00301
00302
00303 continue;
00304 }
00305
00306
00307
00308 StParticleDefinition* BestGuess = (StParticleDefinition*)rTrack->pidTraits(*PidAlgorithm);
00309
00310 if (!BestGuess){
00311 continue;
00312 }
00313
00314
00315
00316
00317 const StMcTrack* mTrack = (*tIter).second->partnerMcTrack();
00318
00319
00320 int pdgCode = 0;
00321 int motherPdgCode = 0;
00322 int daughterPdgCode =0;
00323 int motherTrackId =0;
00324 if (CheckPdgIdLists()) {
00325 int check=0;
00326 if (!mTrack->particleDefinition()) {
00327 cout << " track has no particle definiton " << endl;
00328 continue;
00329 }
00330 pdgCode = mTrack->particleDefinition()->pdgEncoding();
00331
00332
00333 if (mTrack->parent()) {
00334 motherPdgCode = mTrack->parent()->pdgId();
00335 motherTrackId = mTrack->parent()->key();
00336 }
00337 if (motherPdgCode) cout << " motherPdgCode :" << motherPdgCode << endl;
00338 else cout << " mother has no pdgId "<< endl;
00339 if ( mTrack->stopVertex() == 0 ) {
00340 check += CheckPdgIdList(pdgCode,motherPdgCode,0);
00341 }
00342 else {
00343 for (unsigned int iDaughter=0; iDaughter < mTrack->stopVertex()->daughters().size()-1; iDaughter++) {
00344 daughterPdgCode = mTrack->stopVertex()->daughters()[iDaughter]->pdgId();
00345 check += CheckPdgIdList(pdgCode,motherPdgCode,daughterPdgCode);
00346 }
00347 }
00348 if ( !(check) ) {
00349 continue;
00350 }
00351 }
00352
00353
00354 int geantId = mTrack->geantId();
00355
00356
00357
00358
00359
00360
00361
00362
00363 pathlength = rTrack->geometry()->helix().pathLength( rVertexPosition );
00364
00365 p = rTrack->geometry()->momentum();
00366 mp = mTrack->momentum();
00367
00368
00369 diff = (p.mag()-mp.mag()) / p.mag();
00370
00371 if ( fabs(diff) > DIFF_CUT_OFF ) {
00372
00373 continue;
00374 }
00375
00376 mDiff->Fill(diff,1.);
00377 mDiffCurrent->Fill(diff,1.);
00378
00379
00380
00381 StHbtTrack* hbtTrack = new StHbtTrack;
00382
00383
00384
00385 hbtTrack->SetTrackId((int)(rTrack->key()+motherTrackId*::pow(2,16)));
00386
00387 hbtTrack->SetNHits(nhits);
00388
00389 if (mPerfectPID) {
00390 switch (geantId) {
00391 case 2:
00392 case 3:
00393 hbtTrack->SetNSigmaElectron(0.);
00394 hbtTrack->SetNSigmaPion(-999);
00395 hbtTrack->SetNSigmaKaon(-999.);
00396 hbtTrack->SetNSigmaProton(-999.);
00397 break;
00398 case 8:
00399 case 9:
00400 hbtTrack->SetNSigmaElectron(999.);
00401 hbtTrack->SetNSigmaPion(0.);
00402 hbtTrack->SetNSigmaKaon(-999.);
00403 hbtTrack->SetNSigmaProton(-999.);
00404 break;
00405 case 11:
00406 case 12:
00407 hbtTrack->SetNSigmaElectron(999.);
00408 hbtTrack->SetNSigmaPion(999.0);
00409 hbtTrack->SetNSigmaKaon(0.);
00410 hbtTrack->SetNSigmaProton(-999.);
00411 break;
00412 case 14:
00413 case 15:
00414 hbtTrack->SetNSigmaElectron(999.);
00415 hbtTrack->SetNSigmaPion(999.);
00416 hbtTrack->SetNSigmaKaon(999.);
00417 hbtTrack->SetNSigmaProton(0.);
00418 break;
00419 default:
00420 hbtTrack->SetNSigmaElectron(999.);
00421 hbtTrack->SetNSigmaPion(999.);
00422 hbtTrack->SetNSigmaKaon(999.);
00423 hbtTrack->SetNSigmaProton(999.);
00424 break;
00425 }
00426 }
00427 else {
00428 hbtTrack->SetNSigmaElectron(PidAlgorithm->numberOfSigma(Electron));
00429 hbtTrack->SetNSigmaPion(PidAlgorithm->numberOfSigma(Pion));
00430 hbtTrack->SetNSigmaKaon(PidAlgorithm->numberOfSigma(Kaon));
00431 hbtTrack->SetNSigmaProton(PidAlgorithm->numberOfSigma(Proton));
00432 }
00433
00434
00435
00436 hbtTrack->SetdEdx(PidAlgorithm->traits()->mean());
00437
00438 double pathlength = rTrack->geometry()->helix().pathLength(rVertexPosition);
00439
00440 StHbtThreeVector p = rTrack->geometry()->momentum();
00441
00442 hbtTrack->SetP(p);
00443
00444 StHbtThreeVector DCAxyz = rTrack->geometry()->helix().at(pathlength)-rVertexPosition;
00445
00446 hbtTrack->SetDCAxy( DCAxyz.perp() );
00447 hbtTrack->SetDCAz( DCAxyz.z() );
00448
00449 hbtTrack->SetChiSquaredXY( rTrack->fitTraits().chi2(0) );
00450 hbtTrack->SetChiSquaredZ( rTrack->fitTraits().chi2(1) );
00451
00452 StPhysicalHelixD helix = rTrack->geometry()->helix();
00453 hbtTrack->SetHelix( helix );
00454
00455 float pt = ::sqrt(p[0]*p[0]+p[1]*p[1]);
00456
00457
00458
00459 hbtTrack->SetPt(pt);
00460
00461 int charge = ( rTrack->geometry()->charge() );
00462
00463 hbtTrack->SetCharge(charge);
00464
00465 hbtTrack->SetTopologyMap( 0, rTrack->topologyMap().data(0) );
00466 hbtTrack->SetTopologyMap( 1, rTrack->topologyMap().data(1) );
00467
00468
00469
00470
00471 if (mTrackCut){
00472 if (!(mTrackCut->Pass(hbtTrack))){
00473 delete hbtTrack;
00474 continue;
00475 }
00476 }
00477
00478 hbtEvent->TrackCollection()->push_back(hbtTrack);
00479 }}
00480
00481
00482 hbtEvent->SetNumberOfGoodTracks(hbtEvent->TrackCollection()->size());
00483
00484 cout << " StHbtAssociationReader::ReturnEvent() : mean of momenta diff (accepted tracks)= " << mDiffCurrent->GetMean() << endl;
00485 cout << " StHbtAssociationReader::ReturnEvent() : rms of momenta diff (accepted tracks)= " << mDiffCurrent->GetRMS() << endl;
00486 mDiffMean->Fill(mDiffCurrent->GetMean(),1.);
00487 mDiffRMS->Fill(mDiffCurrent->GetRMS(),1.);
00488 cout << " StHbtAssociationReader::ReturnEvent() : DiffCurrent (p_real - p_mc ) / p_real " << mDiffCurrent << endl;
00489 cout << " StHbtAssociationReader::ReturnEvent() : Diff (p_real - p_mc ) / p_real " << mDiff << endl;
00490 cout << " StHbtAssociationReader::ReturnEvent() : DiffMean mean of (p_real - p_mc ) / p_real " << mDiffMean << endl;
00491 cout << " StHbtAssociationReader::ReturnEvent() : DiffSigma sigma of (p_real - p_mc ) / p_real " << mDiffRMS << endl;
00492
00493
00494
00495 StStrangeEvMuDst strangeEvMuDst(*rEvent);
00496
00497 {for (rcV0MapIter tIter=theV0Map->begin(); tIter!=theV0Map->end(); ++tIter){
00498 StV0Vertex* rV0Vertex = (StV0Vertex*) (*tIter).first;
00499 StV0MuDst v0MuDst(rV0Vertex,&strangeEvMuDst);
00500 cout << " StHbtAssociationEventReader::ReturnHbtEvent() " << theV0Map->count(rV0Vertex) << " associated V0s " << endl;
00501
00502 pair<rcV0MapIter, rcV0MapIter> boundsV0 = theV0Map->equal_range(rV0Vertex);
00503 for (rcV0MapIter v0Iter = boundsV0.first; v0Iter!= boundsV0.second; v0Iter++){
00504 }
00505 StHbtV0* hbtV0 = new StHbtV0(v0MuDst);
00506 if (mV0Cut){
00507 if (!(mV0Cut->Pass(hbtV0))) {
00508 delete hbtV0;
00509 continue;
00510 }
00511 }
00512 hbtEvent->V0Collection()->push_back(hbtV0);
00513 }}
00514
00515 cout << " StHbtAssociationReader::ReturnHbtEvent() - " << hbtEvent->V0Collection()->size();
00516 cout << " V0s pushed in collection " << endl;
00517
00518 eventNumber++;
00519 return hbtEvent;
00520 }
00521
00522 ClassImp(StHbtAssociationReader)
00523