StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StMuMomentumShiftMaker.cxx
1 /***************************************************************************
2  *
3  * $Id: StMuMomentumShiftMaker.cxx,v 1.11 2013/07/23 11:02:59 jeromel Exp $
4  * Author: Marco van Leeuwen, LBNL
5  *
6  * This class is used to correct the momenta of tracks on MicroDst after
7  * production, in case the magnetic field that was used during production
8  * was wrong. It was used for the SL04k year-4 HalfField productions.
9  *
10  ***************************************************************************/
11 #include "StMuMomentumShiftMaker.h"
12 #include "StMuDstMaker.h"
13 #include "StMuDst.h"
14 #include "StMuEvent.h"
15 #include "StMuTrack.h"
16 #include "StEvent/StRunInfo.h"
17 #ifndef __NO_STRANGE_MUDST__
18 #include "StStrangeMuDstMaker/StKinkMuDst.hh"
19 #include "StStrangeMuDstMaker/StV0MuDst.hh"
20 #include "StStrangeMuDstMaker/StXiMuDst.hh"
21 #include "StStrangeMuDstMaker/StStrangeEvMuDst.hh"
22 #include "StMessMgr.h"
23 #endif
24 #include "TChain.h"
25 #include "THack.h"
26 #include "TFile.h"
27 
28 ClassImp(StMuMomentumShiftMaker)
29 
30 StMuMomentumShiftMaker::StMuMomentumShiftMaker() : StMaker("MomentumShiftMaker"), mMomentumScale(1), mWriteMuDst(1), mOutDir("."), mOutFile(0), mOutTree(0) { }
31 
32 StMuMomentumShiftMaker::StMuMomentumShiftMaker(const char *outDir) : StMaker("MomentumShiftMaker"), mMomentumScale(1), mWriteMuDst(1), mOutFile(0), mOutTree(0) {
33  mOutDir=outDir;
34 }
35 
36 void StMuMomentumShiftMaker::ScaleMomentum(StMuTrack *track) {
37  track->mP *= mMomentumScale;
38  track->mPt = mMomentumScale*track->pt();
39 
40  track->mHelix.mP *= mMomentumScale;
41  track->mOuterHelix.mP *= mMomentumScale;
42 }
43 #ifndef __NO_STRANGE_MUDST__
44 void StMuMomentumShiftMaker::ScaleMomentum(StKinkMuDst *kink) {
45  kink->mParentMomentum *= mMomentumScale;
46  kink->mParentPrimMomentum *= mMomentumScale;
47  kink->mDaughterMomentum *= mMomentumScale;
48  kink->mTransverseMomentum *= mMomentumScale;
49 }
50 
51 void StMuMomentumShiftMaker::ScaleMomentum(StV0MuDst *v0) {
52  v0->mMomPosX *= mMomentumScale;
53  v0->mMomPosY *= mMomentumScale;
54  v0->mMomPosZ *= mMomentumScale;
55  v0->mMomNegX *= mMomentumScale;
56  v0->mMomNegY *= mMomentumScale;
57  v0->mMomNegZ *= mMomentumScale;
58 }
59 
60 void StMuMomentumShiftMaker::ScaleMomentum(StXiMuDst *xi) {
61  xi->mMomPosX *= mMomentumScale;
62  xi->mMomPosY *= mMomentumScale;
63  xi->mMomPosZ *= mMomentumScale;
64  xi->mMomNegX *= mMomentumScale;
65  xi->mMomNegY *= mMomentumScale;
66  xi->mMomNegZ *= mMomentumScale;
67  xi->mMomBachelorX *= mMomentumScale;
68  xi->mMomBachelorY *= mMomentumScale;
69  xi->mMomBachelorZ *= mMomentumScale;
70 }
71 #endif
73 
74  StMuDstMaker *mudstMaker = (StMuDstMaker*) GetMaker("MuDst");
75  if (!mudstMaker) {
76  LOG_ERROR << "ERROR: cannot find MuDstMaker" << endm;
77  return kStErr;
78  }
79  if (mWriteMuDst) {
80  const Char_t *inBaseName= strrchr(mudstMaker->chain()->GetFile()->GetName(),'/');
81  if ( ! inBaseName ) inBaseName = (Char_t *) mudstMaker->chain()->GetFile()->GetName();
82  else inBaseName = inBaseName+1;
83 
84  if (mOutFile==0 || strstr(mOutFile->GetName(),inBaseName)==0) {
85  if (mOutFile) {
86  mOutFile->Write();
87  mOutFile->Close();
88  delete mOutFile;
89  mOutFile=0;
90  mOutTree=0;
91  }
92  mOutFile=new TFile(mOutDir+inBaseName,"RECREATE");
93  if (!mOutFile->IsOpen()) {
94  LOG_ERROR << "ERROR in StMuMomentumShiftMaker::Make: cannot open output file: " << mOutDir+inBaseName << endm;
95  delete mOutFile; mOutFile = 0;
96  }
97  }
98  }
99  StMuDst *mudst=(StMuDst*) GetInputDS("MuDst");
100 
101  StMuEvent *event=mudst->event();
102  event->eventSummary().setMagneticField(event->eventSummary().magneticField());
103  event->runInfo().setMagneticField(mMomentumScale * event->runInfo().magneticField());
104 #ifndef __NO_STRANGE_MUDST__
105  StStrangeEvMuDst *strange_event=mudst->strangeEvent();
106  strange_event->mMagneticField *= mMomentumScale;
107 #endif
108  if (mOutTree==0) {
109  mOutTree=mudstMaker->chain()->GetTree()->CloneTree(0);
110  }
111 
112  // Scale momenta of different track types
113  Int_t n_prim=mudst->numberOfPrimaryTracks();
114  for (Int_t i_prim=0; i_prim < n_prim; i_prim++) {
115  StMuTrack *track= mudst->primaryTracks(i_prim);
116  ScaleMomentum(track);
117  }
118  Int_t n_glob=mudst->numberOfGlobalTracks();
119  for (Int_t i_glob=0; i_glob < n_glob; i_glob++) {
120  StMuTrack *track= mudst->globalTracks(i_glob);
121  ScaleMomentum(track);
122  }
123  Int_t n_other=mudst->numberOfOtherTracks();
124  for (Int_t i_other=0; i_other < n_other; i_other++) {
125  StMuTrack *track= mudst->otherTracks(i_other);
126  ScaleMomentum(track);
127  }
128  /* Skip L3 tracks for now, they were reconstructed seperately
129  Int_t n_l3=mudst->numberOfL3Tracks();
130  for (Int_t i_l3=0; i_l3 < n_l3; i_l3++) {
131  StMuTrack *track= mudst->l3Tracks(i_l3);
132  ScaleMomentum(track);
133  }
134  */
135 #ifndef __NO_STRANGE_MUDST__
136  // Scale momenta of V0 et al
137  Int_t n_kink=mudst->numberOfKinks();
138  for (Int_t i_kink=0; i_kink < n_kink; i_kink++) {
139  StKinkMuDst *kink= mudst->kinks(i_kink);
140  ScaleMomentum(kink);
141  }
142  Int_t n_v0=mudst->numberOfV0s();
143  for (Int_t i_v0=0; i_v0 < n_v0; i_v0++) {
144  StV0MuDst *v0= mudst->v0s(i_v0);
145  ScaleMomentum(v0);
146  }
147  Int_t n_xi=mudst->numberOfXis();
148  for (Int_t i_xi=0; i_xi < n_xi; i_xi++) {
149  StXiMuDst *xi= mudst->xis(i_xi);
150  ScaleMomentum(xi);
151  }
152 #endif
153  if (mWriteMuDst) {
154  mOutTree->Fill(); THack::IsTreeWritable(mOutTree);
155  }
156  return kStOk;
157 }
158 
160  if (mWriteMuDst && mOutFile) {
161  mOutFile->Write();
162  mOutFile->Close();
163  }
164  return kStOk;
165 }
static TObjArray * globalTracks()
returns pointer to the global tracks list
Definition: StMuDst.h:303
Double_t pt() const
Returns pT at point of dca to primary vertex.
Definition: StMuTrack.h:256
static TClonesArray * v0s()
returns pointer to the v0 list
Definition: StMuDst.h:354
static TClonesArray * otherTracks()
returns pointer to the other tracks list (all tracks that are not flagged as primary of global) ...
Definition: StMuDst.h:305
static StStrangeEvMuDst * strangeEvent()
returns pointer to current StStrangeEvMuDst (class holding the event wise information, e.g. event number, run number)
Definition: StMuDst.h:350
static TObjArray * primaryTracks()
returns pointer to a list of tracks belonging to the selected primary vertex
Definition: StMuDst.h:301
static StMuEvent * event()
returns pointer to current StMuEvent (class holding the event wise information, e.g. event number, run number)
Definition: StMuDst.h:320
TChain * chain()
In read mode, returns pointer to the chain of .MuDst.root files that where selected.
Definition: StMuDstMaker.h:426
static TClonesArray * xis()
returns pointer to the xi list
Definition: StMuDst.h:360
static TClonesArray * kinks()
returns pointer to the kink list
Definition: StMuDst.h:366
Definition: Stypes.h:44
Definition: Stypes.h:41