00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "StMuMomentumShiftMaker.h"
00012 #include "StMuDstMaker.h"
00013 #include "StMuDst.h"
00014 #include "StMuEvent.h"
00015 #include "StMuTrack.h"
00016 #include "StEvent/StRunInfo.h"
00017 #ifndef __NO_STRANGE_MUDST__
00018 #include "StStrangeMuDstMaker/StKinkMuDst.hh"
00019 #include "StStrangeMuDstMaker/StV0MuDst.hh"
00020 #include "StStrangeMuDstMaker/StXiMuDst.hh"
00021 #include "StStrangeMuDstMaker/StStrangeEvMuDst.hh"
00022 #include "StMessMgr.h"
00023 #endif
00024 #include "TChain.h"
00025 #include "THack.h"
00026 #include "TFile.h"
00027
00028 ClassImp(StMuMomentumShiftMaker)
00029
00030 StMuMomentumShiftMaker::StMuMomentumShiftMaker() : StMaker("MomentumShiftMaker"), mMomentumScale(1), mWriteMuDst(1), mOutDir("."), mOutFile(0), mOutTree(0) { }
00031
00032 StMuMomentumShiftMaker::StMuMomentumShiftMaker(const char *outDir) : StMaker("MomentumShiftMaker"), mMomentumScale(1), mWriteMuDst(1), mOutFile(0), mOutTree(0) {
00033 mOutDir=outDir;
00034 }
00035
00036 void StMuMomentumShiftMaker::ScaleMomentum(StMuTrack *track) {
00037 track->mP *= mMomentumScale;
00038 track->mPt = mMomentumScale*track->pt();
00039
00040 track->mHelix.mP *= mMomentumScale;
00041 track->mOuterHelix.mP *= mMomentumScale;
00042 }
00043 #ifndef __NO_STRANGE_MUDST__
00044 void StMuMomentumShiftMaker::ScaleMomentum(StKinkMuDst *kink) {
00045 kink->mParentMomentum *= mMomentumScale;
00046 kink->mParentPrimMomentum *= mMomentumScale;
00047 kink->mDaughterMomentum *= mMomentumScale;
00048 kink->mTransverseMomentum *= mMomentumScale;
00049 }
00050
00051 void StMuMomentumShiftMaker::ScaleMomentum(StV0MuDst *v0) {
00052 v0->mMomPosX *= mMomentumScale;
00053 v0->mMomPosY *= mMomentumScale;
00054 v0->mMomPosZ *= mMomentumScale;
00055 v0->mMomNegX *= mMomentumScale;
00056 v0->mMomNegY *= mMomentumScale;
00057 v0->mMomNegZ *= mMomentumScale;
00058 }
00059
00060 void StMuMomentumShiftMaker::ScaleMomentum(StXiMuDst *xi) {
00061 xi->mMomPosX *= mMomentumScale;
00062 xi->mMomPosY *= mMomentumScale;
00063 xi->mMomPosZ *= mMomentumScale;
00064 xi->mMomNegX *= mMomentumScale;
00065 xi->mMomNegY *= mMomentumScale;
00066 xi->mMomNegZ *= mMomentumScale;
00067 xi->mMomBachelorX *= mMomentumScale;
00068 xi->mMomBachelorY *= mMomentumScale;
00069 xi->mMomBachelorZ *= mMomentumScale;
00070 }
00071 #endif
00072 int StMuMomentumShiftMaker::Make() {
00073
00074 StMuDstMaker *mudstMaker = (StMuDstMaker*) GetMaker("MuDst");
00075 if (!mudstMaker) {
00076 LOG_ERROR << "ERROR: cannot find MuDstMaker" << endm;
00077 return kStErr;
00078 }
00079 if (mWriteMuDst) {
00080 Char_t *inBaseName= strrchr(mudstMaker->chain()->GetFile()->GetName(),'/');
00081 if ( ! inBaseName ) inBaseName = (Char_t *) mudstMaker->chain()->GetFile()->GetName();
00082 else inBaseName = inBaseName+1;
00083
00084 if (mOutFile==0 || strstr(mOutFile->GetName(),inBaseName)==0) {
00085 if (mOutFile) {
00086 mOutFile->Write();
00087 mOutFile->Close();
00088 delete mOutFile;
00089 mOutFile=0;
00090 mOutTree=0;
00091 }
00092 mOutFile=new TFile(mOutDir+inBaseName,"RECREATE");
00093 if (!mOutFile->IsOpen()) {
00094 LOG_ERROR << "ERROR in StMuMomentumShiftMaker::Make: cannot open output file: " << mOutDir+inBaseName << endm;
00095 delete mOutFile; mOutFile = 0;
00096 }
00097 }
00098 }
00099 StMuDst *mudst=(StMuDst*) GetInputDS("MuDst");
00100
00101 StMuEvent *event=mudst->event();
00102 event->eventSummary().setMagneticField(event->eventSummary().magneticField());
00103 event->runInfo().setMagneticField(mMomentumScale * event->runInfo().magneticField());
00104 #ifndef __NO_STRANGE_MUDST__
00105 StStrangeEvMuDst *strange_event=mudst->strangeEvent();
00106 strange_event->mMagneticField *= mMomentumScale;
00107 #endif
00108 if (mOutTree==0) {
00109 mOutTree=mudstMaker->chain()->GetTree()->CloneTree(0);
00110 }
00111
00112
00113 Int_t n_prim=mudst->numberOfPrimaryTracks();
00114 for (Int_t i_prim=0; i_prim < n_prim; i_prim++) {
00115 StMuTrack *track= mudst->primaryTracks(i_prim);
00116 ScaleMomentum(track);
00117 }
00118 Int_t n_glob=mudst->numberOfGlobalTracks();
00119 for (Int_t i_glob=0; i_glob < n_glob; i_glob++) {
00120 StMuTrack *track= mudst->globalTracks(i_glob);
00121 ScaleMomentum(track);
00122 }
00123 Int_t n_other=mudst->numberOfOtherTracks();
00124 for (Int_t i_other=0; i_other < n_other; i_other++) {
00125 StMuTrack *track= mudst->otherTracks(i_other);
00126 ScaleMomentum(track);
00127 }
00128
00129
00130
00131
00132
00133
00134
00135 #ifndef __NO_STRANGE_MUDST__
00136
00137 Int_t n_kink=mudst->numberOfKinks();
00138 for (Int_t i_kink=0; i_kink < n_kink; i_kink++) {
00139 StKinkMuDst *kink= mudst->kinks(i_kink);
00140 ScaleMomentum(kink);
00141 }
00142 Int_t n_v0=mudst->numberOfV0s();
00143 for (Int_t i_v0=0; i_v0 < n_v0; i_v0++) {
00144 StV0MuDst *v0= mudst->v0s(i_v0);
00145 ScaleMomentum(v0);
00146 }
00147 Int_t n_xi=mudst->numberOfXis();
00148 for (Int_t i_xi=0; i_xi < n_xi; i_xi++) {
00149 StXiMuDst *xi= mudst->xis(i_xi);
00150 ScaleMomentum(xi);
00151 }
00152 #endif
00153 if (mWriteMuDst) {
00154 mOutTree->Fill(); THack::IsTreeWritable(mOutTree);
00155 }
00156 return kStOk;
00157 }
00158
00159 int StMuMomentumShiftMaker::Finish() {
00160 if (mWriteMuDst && mOutFile) {
00161 mOutFile->Write();
00162 mOutFile->Close();
00163 }
00164 return kStOk;
00165 }