00001 #define HBT_BFIELD 0.25*tesla
00002 #define DIFF_CUT_OFF 1.
00003
00004 #include "StHbtMaker/Reader/StHbtMcEventReader.h"
00005 #include "StChain.h"
00006
00007
00008 #include "StEventTypes.h"
00009 #include "StEventMaker/StEventMaker.h"
00010
00011 #include "StMcEventTypes.hh"
00012 #include "StMcEventMaker/StMcEventMaker.h"
00013
00014
00015
00016 #include <math.h>
00017
00018
00019 #include "SystemOfUnits.h"
00020 #include "StHbtMaker/Infrastructure/StHbtTrackCollection.hh"
00021 #include "StHbtMaker/Infrastructure/StHbtV0Collection.hh"
00022
00023 #include <Stiostream.h>
00024 #include <stdlib.h>
00025 #include <string>
00026 #include <vector>
00027
00028 #include "PhysicalConstants.h"
00029 #include "SystemOfUnits.h"
00030 #include "StThreeVector.hh"
00031 #include "phys_constants.h"
00032
00033 #include "StChain.h"
00034 #include "St_DataSet.h"
00035 #include "St_DataSetIter.h"
00036
00037 #include "g2t_event.h"
00038 #include "g2t_ftp_hit.h"
00039 #include "g2t_svt_hit.h"
00040 #include "g2t_tpc_hit.h"
00041 #include "g2t_track.h"
00042 #include "g2t_vertex.h"
00043
00044 #include "tables/St_g2t_event_Table.h"
00045 #include "tables/St_g2t_ftp_hit_Table.h"
00046 #include "tables/St_g2t_svt_hit_Table.h"
00047 #include "tables/St_g2t_tpc_hit_Table.h"
00048 #include "tables/St_g2t_track_Table.h"
00049 #include "tables/St_g2t_vertex_Table.h"
00050
00051 #include "StMcEvent.hh"
00052 #include "StMcTrack.hh"
00053 #include "StMcTpcHit.hh"
00054 #include "StMcFtpcHit.hh"
00055 #include "StMcSvtHit.hh"
00056 #include "StMcVertex.hh"
00057
00058 #include "StParticleDefinition.hh"
00059 #include "StKaonZeroShort.hh"
00060 #include "StLambda.hh"
00061 #include "StAntiLambda.hh"
00062 #include "StPhysicalHelix.hh"
00063
00064
00065
00066 #ifdef __ROOT__
00067 ClassImp(StHbtMcEventReader)
00068 #endif
00069
00070 #ifndef ST_NO_NAMESPACES
00071 using namespace units;
00072 #endif
00073
00074 #define __2POWER16__ 65536
00075
00076 struct vertexFlag {
00077 StMcVertex* vtx;
00078 int primaryFlag; };
00079
00080 double dedxMean(double mass, double momentum){
00081 double dedxMean;
00082 double tpcDedxGain = 0.174325e-06;
00083 double tpcDedxOffset = -2.71889;
00084 double tpcDedxRise = 776.626;
00085
00086 double gamma = ::sqrt(::pow(momentum/mass,2)+1.);
00087 double beta = ::sqrt(1. - 1./::pow(gamma,2));
00088 double rise = tpcDedxRise*::pow(beta*gamma,2);
00089 if ( beta > 0)
00090 dedxMean = tpcDedxGain/::pow(beta,2) * (0.5*::log(rise)-::pow(beta,2)- tpcDedxOffset);
00091 else
00092 dedxMean = 1000.;
00093 return dedxMean;
00094 }
00095
00096
00097 StHbtMcEventReader::StHbtMcEventReader(){
00098 mEventCut=0;
00099 mTrackCut=0;
00100 mV0Cut=0;
00101 mReaderStatus = 0;
00102 mV0=0;
00103
00104 mMotherMinvYPt = new StHbt3DHisto("Mother_MinvYPt","Mother_MinvYPt", 100,0.,5., 80,-2.,2., 80,0.,4.);
00105 mMotherMinvYMt = new StHbt3DHisto("Mother_MinvYMt","Mother_MinvYMt", 100,0.,5., 80,-2.,2., 80,0.,4.);
00106 mMotherMinvEtaPt = new StHbt3DHisto("Mother_MinvEtaPt","Mother_MinvEtaPt",100,0.,5., 80,-2.,2., 80,0.,4.);
00107 }
00108
00109 StHbtMcEventReader::~StHbtMcEventReader(){
00110 if (mEventCut) delete mEventCut;
00111 if (mTrackCut) delete mTrackCut;
00112 if (mV0Cut) delete mV0Cut;
00113 }
00114
00115 StHbtString StHbtMcEventReader::Report(){
00116 StHbtString temp = "\n This is the StHbtMcEventReader\n";
00117 temp += "---> EventCuts in Reader: ";
00118 if (mEventCut) {
00119 temp += mEventCut->Report();
00120 }
00121 else {
00122 temp += "NONE";
00123 }
00124 temp += "\n---> TrackCuts in Reader: ";
00125 if (mTrackCut) {
00126 temp += mTrackCut->Report();
00127 }
00128 else {
00129 temp += "NONE";
00130 }
00131 temp += "\n---> V0Cuts in Reader: ";
00132 if (mV0Cut) {
00133 temp += mV0Cut->Report();
00134 }
00135 else {
00136 temp += "NONE";
00137 }
00138 temp += "\n";
00139 return temp;
00140 }
00141
00142 StHbtEvent* StHbtMcEventReader::ReturnHbtEvent(){
00143 cout << " **************************************************************************************" << endl;
00144 cout << " StHbtMcEventReader::ReturnHbtEvent() : Seconds elapsed since last call : " << difftime( time(0), timeStamp ) << endl;
00145 cout << " **************************************************************************************" << endl;
00146 timeStamp = time(0);
00147
00148
00149
00150
00151 StMcEvent* mcEvent = 0;
00152
00153
00154
00155
00156
00157 mcEvent = (StMcEvent*) StMaker::GetChain()->GetDataSet("StMcEvent");
00158
00159 if (!mcEvent){
00160 cout << "StHbtMcEventReader - No StMcEvent!!! " << endl;
00161 return 0;
00162 }
00163
00164
00165
00166
00167
00168
00169 unsigned long EventNumber = mcEvent->eventNumber();
00170
00171 int Mult = mcEvent->tracks().size();
00172
00173
00174
00175 StHbtThreeVector VertexPosition = mcEvent->primaryVertex()->position();
00176
00177
00178 if (VertexPosition.x() == VertexPosition.y() &&
00179 VertexPosition.y() == VertexPosition.z() ){
00180 cout << "StHbtMcEventReader - bad vertex !!! " << endl;
00181 return 0;
00182 }
00183
00184
00185 StHbtEvent* hbtEvent = new StHbtEvent;
00186 hbtEvent->SetEventNumber(EventNumber);
00187 hbtEvent->SetCtbMult(0);
00188 hbtEvent->SetZdcAdcEast(0);
00189 hbtEvent->SetZdcAdcWest(0);
00190 hbtEvent->SetNumberOfTpcHits(0);
00191 hbtEvent->SetNumberOfTracks(Mult);
00192 hbtEvent->SetNumberOfGoodTracks(Mult);
00193 hbtEvent->SetReactionPlane(0.);
00194 hbtEvent->SetReactionPlaneSubEventDifference(0.);
00195 hbtEvent->SetPrimVertPos(VertexPosition);
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207 StHbtThreeVector p;
00208
00209 for (StMcTrackIterator iter=mcEvent->tracks().begin(); iter!=mcEvent->tracks().end(); iter++){
00210 StMcTrack* track = *iter;
00211
00212
00213 if (track->particleDefinition()) {
00214 if (CheckPdgIdList(mAcceptedMothers,track->particleDefinition()->pdgEncoding())) {
00215 mMotherMinvYPt->Fill(track->fourMomentum().m(),track->rapidity(),track->pt());
00216 mMotherMinvYMt->Fill(track->fourMomentum().m(),track->rapidity(),track->fourMomentum().mt());
00217 mMotherMinvEtaPt->Fill(track->fourMomentum().m(),track->pseudoRapidity(),track->pt());
00218 }
00219 }
00220
00221
00222
00223 int pdgCode = 0;
00224 int motherPdgCode = 0;
00225 int daughterPdgCode = 0;
00226 int motherTrackId = 0;
00227 if (CheckPdgIdLists()) {
00228 int check=0;
00229 if (!track->particleDefinition()) {
00230 cout << " track has no particle definiton " << endl;
00231 continue;
00232 }
00233 pdgCode = track->particleDefinition()->pdgEncoding();
00234
00235 if (track->parent()) {
00236 motherPdgCode = track->parent()->pdgId();
00237 motherTrackId = track->parent()->key();
00238 }
00239 if (motherPdgCode==333) cout << " phi 333" << endl;
00240
00241 if ( track->stopVertex() == 0 ) {
00242 check += CheckPdgIdList(pdgCode,motherPdgCode,0);
00243
00244 }
00245 else {
00246 for (unsigned int iDaughter=0; iDaughter < track->stopVertex()->daughters().size()-1; iDaughter++) {
00247 daughterPdgCode = track->stopVertex()->daughters()[iDaughter]->pdgId();
00248 check += CheckPdgIdList(pdgCode,motherPdgCode,daughterPdgCode);
00249
00250 }
00251 }
00252
00253 if ( !(check) ) {
00254 continue;
00255 }
00256 }
00257
00258 int nTpcHits = track->tpcHits().size();
00259
00260 if (nTpcHits==0) {
00261
00262 continue;
00263 }
00264
00265
00266
00267
00268
00269 StHbtTrack* hbtTrack = new StHbtTrack;
00270
00271
00272 #ifdef TheWorldIsNice
00273 hbtTrack->SetP( track->momentum() );
00274 #else
00275 StHbtThreeVector tmpP;
00276 tmpP.setX( track->momentum().x() );
00277 tmpP.setY( track->momentum().y() );
00278 tmpP.setZ( track->momentum().z() );
00279 hbtTrack->SetP( tmpP );
00280 #endif
00281
00282
00283 hbtTrack->SetTrackId(track->key()+motherTrackId*__2POWER16__);
00284
00285 hbtTrack->SetNHits( nTpcHits );
00286 hbtTrack->SetNHitsPossible(nTpcHits );
00287
00288
00289
00290
00291
00292 int geantPid = track->particleDefinition()->pdgEncoding();
00293
00294
00295 switch (geantPid) {
00296 case 11:
00297 case -11:
00298 hbtTrack->SetNSigmaElectron(0.);
00299 hbtTrack->SetNSigmaPion(-999.);
00300 hbtTrack->SetNSigmaKaon(-999.);
00301 hbtTrack->SetNSigmaProton(-999.);
00302 break;
00303 case 211:
00304 case -211:
00305 hbtTrack->SetNSigmaElectron(999.);
00306 hbtTrack->SetNSigmaPion(0.);
00307 hbtTrack->SetNSigmaKaon(-999.);
00308 hbtTrack->SetNSigmaProton(-999.);
00309 break;
00310 case 321:
00311 case -321:
00312 hbtTrack->SetNSigmaElectron(999.);
00313 hbtTrack->SetNSigmaPion(999.0);
00314 hbtTrack->SetNSigmaKaon(0.);
00315 hbtTrack->SetNSigmaProton(-999.);
00316 break;
00317 case 2212:
00318 case -2212:
00319 hbtTrack->SetNSigmaElectron(999.);
00320 hbtTrack->SetNSigmaPion(999.);
00321 hbtTrack->SetNSigmaKaon(999.);
00322 hbtTrack->SetNSigmaProton(0.);
00323 break;
00324 default:
00325 hbtTrack->SetNSigmaElectron(999.);
00326 hbtTrack->SetNSigmaPion(999.);
00327 hbtTrack->SetNSigmaKaon(999.);
00328 hbtTrack->SetNSigmaProton(999.);
00329 break;
00330 }
00331
00332
00333
00334
00335 hbtTrack->SetdEdx( dedxMean( track->particleDefinition()->mass(), track->momentum().mag() ) );
00336
00337
00338 hbtTrack->SetPt( track->momentum().perp() );
00339
00340
00341 hbtTrack->SetCharge( (int)(track->particleDefinition()->charge()) );
00342
00343
00344 #ifdef TheWorldIsNice
00345 StPhysicalHelix helix = StPhysicalHelix( hbtTrack->P(), track->startVertex()->position(), HBT_BFIELD, hbtTrack->Charge() );
00346 #else
00347 StHbtThreeVector tmpSV;
00348 tmpSV.setX( track->startVertex()->position().x() );
00349 tmpSV.setY( track->startVertex()->position().y() );
00350 tmpSV.setZ( track->startVertex()->position().z() );
00351 StPhysicalHelixD helix = StPhysicalHelixD( hbtTrack->P(), tmpSV, HBT_BFIELD, hbtTrack->Charge() );
00352 #endif
00353
00354 hbtTrack->SetHelix(helix);
00355
00356
00357 double pathlength = helix.pathLength(VertexPosition);
00358
00359 StHbtThreeVector DCAxyz = helix.at(pathlength)-VertexPosition;
00360
00361
00362 hbtTrack->SetDCAxy( DCAxyz.perp() );
00363 hbtTrack->SetDCAz( DCAxyz.z() );
00364
00365 hbtTrack->SetChiSquaredXY( 0.);
00366 hbtTrack->SetChiSquaredZ( 0.);
00367
00368
00369
00370
00371
00372 if (mTrackCut){
00373 if (!(mTrackCut->Pass(hbtTrack))){
00374 delete hbtTrack;
00375 continue;
00376 }
00377 }
00378 hbtEvent->TrackCollection()->push_back(hbtTrack);
00379 }
00380 cout << hbtEvent->TrackCollection()->size() << " tracks pushed to collection" << endl;
00381
00382
00383
00384
00385 StKaonZeroShort* k0Short = StKaonZeroShort::instance();
00386 StLambda* lambda = StLambda::instance();
00387 StAntiLambda* antiLambda = StAntiLambda::instance();
00388 for (StMcVertexIterator vIter=mcEvent->vertices().begin(); vIter!=mcEvent->vertices().end(); vIter++){
00389 StMcVertex* vertex = *vIter;
00390 StMcTrack* parent = (StMcTrack*)vertex->parent();
00391 if (parent) {
00392 if ( parent->particleDefinition() == k0Short ||
00393 parent->particleDefinition() == lambda ||
00394 parent->particleDefinition() == antiLambda &&
00395 vertex->numberOfDaughters() == 2) {
00396 #ifdef STHBTDEBUG
00397 cout << " v0 Id : " << parent->particleDefinition()->name() << endl;
00398 #endif
00399 StMcTrack* pos;
00400 StMcTrack* neg;
00401 if ( (*(vertex->daughters().begin()))->particleDefinition()->charge() > 0 ) {
00402 pos = *(vertex->daughters().begin());
00403 neg = *(vertex->daughters().end()-1);
00404 }
00405 else if ( (*(vertex->daughters().begin()))->particleDefinition()->charge() < 0 ) {
00406 neg = *(vertex->daughters().begin());
00407 pos = *(vertex->daughters().end()-1);
00408 }
00409 else continue;
00410
00411
00412 StHbtV0* hbtv0 = new StHbtV0();
00413 hbtv0->SetdecayLengthV0( abs(vertex->position()-VertexPosition) );
00414 hbtv0->SetdecayVertexV0( vertex->position() );
00415
00416 StPhysicalHelixD posHelix = StPhysicalHelixD( pos->momentum(), vertex->position(),
00417 HBT_BFIELD, pos->particleDefinition()->charge() );
00418 StPhysicalHelixD negHelix = StPhysicalHelixD( neg->momentum(), vertex->position(),
00419 HBT_BFIELD, neg->particleDefinition()->charge() );
00420 StPhysicalHelixD v0Helix = StPhysicalHelixD( pos->momentum()+neg->momentum(), vertex->position(),
00421 HBT_BFIELD, 0 );
00422
00423 double posPathLength = posHelix.pathLength( vertex->position() );
00424 double negPathLength = negHelix.pathLength( vertex->position() );
00425
00426 hbtv0->SetdcaV0Daughters( abs(posHelix.at(posPathLength)-negHelix.at(negPathLength)) );
00427
00428
00429 hbtv0->SetdcaV0ToPrimVertex( v0Helix.distance( VertexPosition ) );
00430
00431
00432 hbtv0->SetdcaPosToPrimVertex( posHelix.distance( VertexPosition ) );
00433 hbtv0->SetdcaNegToPrimVertex( negHelix.distance( VertexPosition ) );
00434
00435 hbtv0->SetmomPos( pos->momentum() );
00436 hbtv0->SetmomNeg( neg->momentum() );
00437
00438 hbtv0->SettpcHitsPos( pos->tpcHits().size() );
00439 hbtv0->SettpcHitsNeg( neg->tpcHits().size() );
00440
00441
00442
00443
00444
00445
00446 hbtv0->SetkeyPos(pos->key());
00447 hbtv0->SetkeyNeg(neg->key());
00448
00449 hbtv0->UpdateV0();
00450
00451
00452 if (mV0Cut){
00453 if (!(mV0Cut->Pass(hbtv0))){
00454 delete hbtv0;
00455 continue;
00456 }
00457 }
00458
00459 hbtEvent->V0Collection()->push_back(hbtv0);
00460 }
00461 }
00462 }
00463 cout << hbtEvent->V0Collection()->size() << " v0s pushed to collection" << endl;
00464
00465 return hbtEvent;
00466 }
00467
00468