StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StGenericVertexMaker.cxx
1 // Revision 1.1.1.1 2001/01/31 14:00:07 balewski
3 // First release
4 //
5 //
7 // //
8 // Maker to run minuit based vertex finder //
9 //
10 // //
12 
13 #include <TNtuple.h>
14 
15 #include "StEvent/StEvent.h"
16 #include "StGenericVertexMaker/Minuit/StMinuitVertexFinder.h"
17 #include "StGenericVertexMaker/StFixedVertexFinder.h"
18 #include "StGenericVertexMaker/StGenericVertexFinder.h"
19 #include "StGenericVertexMaker/StGenericVertexMaker.h"
20 #include "StGenericVertexMaker/StiPPVertex/StPPVertexFinder.h"
21 #include "StGenericVertexMaker/StppLMVVertexFinder.h"
22 #include "StGenericVertexMaker/StvPPVertex/StPPVertexFinder.h"
23 #include "St_base/StMessMgr.h"
24 #include "St_db_Maker/St_db_Maker.h"
25 #include "tables/St_g2t_vertex_Table.h"
26 
27 // Historical Note 10/17/23. Jason Webb
28 // -------------------------------------
29 // The StvPPVertex appears to be an equivalent set of vertex
30 // finding algorithms using tracks from the StEvent data model
31 // rather than the internal data structures of the Sti tracker.
32 
33 class StMuDst;
34 class TClonesArray;
35 
36 
37 //___________________________________________________________
38 StGenericVertexMaker::StGenericVertexMaker(const char *name):StMaker(name),
39  useITTF(true),
40  useBeamline(false),
41  useCTB(false),
42  usePCT(false),
43  useBTOF(false),
44  eval(false),
45  externalFindUse(true),
46  minTracks(0),
47  mEvalNtuple(nullptr),
48  mEvent(nullptr),
49  primV(nullptr),
50  theFinder(nullptr),
51  nEvTotal(0),
52  nEvGood(0)
53 {
54 }
55 
56 //_____________________________________________________________________________
57 StGenericVertexMaker::~StGenericVertexMaker()
58 {
59  SafeDelete(theFinder);
60 }
61 
62 
79 {
80  // setup params
81  useITTF = IAttr("ITTF");
82  useBeamline = IAttr("beamLine");
83  useCTB = IAttr("CTB");
84  usePCT = IAttr("PCT");
85  useBTOF = IAttr("BTOF");
86  eval = IAttr("eval");
87  minTracks = IAttr("minTracks");
88 
89  bool isMinuit = ( IAttr("VFMinuit") || IAttr("VFMinuit2") || IAttr("VFMinuit3") );
90  bool isPPV = ( IAttr("VFPPV") || IAttr("VFPPVnoCTB") || IAttr("VFPPVEv") || IAttr("VFPPVEvNoBTof") );
91 
92  // Recognize different beamline options to be used with some vertex finders
93  StGenericVertexFinder::VertexFit_t vertexFitMode;
94 
95  if ( IAttr("beamline") && isPPV)
96  vertexFitMode = StGenericVertexFinder::VertexFit_t::BeamlineNoFit;
97  else if ( IAttr("beamline") && isMinuit )
98  vertexFitMode = StGenericVertexFinder::VertexFit_t::Beamline1D;
99  else if ( IAttr("beamline1D") )
100  vertexFitMode = StGenericVertexFinder::VertexFit_t::Beamline1D;
101  else if ( IAttr("beamline3D") )
102  vertexFitMode = StGenericVertexFinder::VertexFit_t::Beamline3D;
103  else
104  vertexFitMode = StGenericVertexFinder::VertexFit_t::NoBeamline;
105 
106 
107  if ( isMinuit ) // 3 versions of Minuit for ranking modes
108  {
109  LOG_INFO << "StMinuitVertexFinder::StMinuitVertexFinder is in use." << endm;
110 
111  theFinder= new StMinuitVertexFinder(vertexFitMode);
112 
113  if (IAttr("VFMinuit") ) ((StMinuitVertexFinder*) theFinder)->useOldBEMCRank();
114  if (IAttr("VFMinuit3") ) ((StMinuitVertexFinder*) theFinder)->lowerSplitVtxRank();
115  if (IAttr("FXT") ) ((StMinuitVertexFinder*) theFinder)->SetFXT();
116  if (minTracks > 0) ((StMinuitVertexFinder*) theFinder)->SetMinimumTracks(minTracks);
117 
118  } else if ( IAttr("VFppLMV")){
119  theFinder= new StppLMVVertexFinder();
120  theFinder->SetMode(0); // this mode is an internal to ppLMV option switch
121 
122  } else if ( IAttr("VFppLMV5")){
123  theFinder= new StppLMVVertexFinder();
124  theFinder->SetMode(1); // this mode is an internal to ppLMV option switch
125 
126  } else if ( (IAttr("VFPPV") || IAttr("VFPPVnoCTB")) && !IAttr("VFPPVev")) {
127  // 2 version of PPV w/ & w/o CTB
128  LOG_INFO << "StGenericVertexMaker::Init: uses PPVertex finder"<< endm;
129  LOG_INFO << "StPPVertexFinder::StPPVertexFinder is in use" << endm;
130 
131  theFinder= new StPPVertexFinder(vertexFitMode);
132 
133  if ( IAttr("VFPPVnoCTB")) theFinder->UseCTB(kFALSE);
134 
135  // Because VFstore is a local optio used by users, make sure it is checked first
136  int vfstore = IAttr("VFstore");
137  // ... while the global option would not be used if the local one is used
138  //if (vfstore == 0) vfstore = IAttr(".gopt.VFstore"); <--- this will work whenevr gopt will be amde flexible
139 
140  if (vfstore > 0) {
141  LOG_INFO << "StGenericVertexMaker::Init: Using VFStore depth = " << vfstore << endm;
142  ((StPPVertexFinder*)theFinder)->SetStoreUnqualifiedVertex(vfstore);
143  }
144  if ( IAttr("useBTOFmatchOnly") ){
145  LOG_INFO << "StGenericVertexMaker::Init: UseBTOFmatchOnly option enabled" << endm;
146  ((StPPVertexFinder*)theFinder)->UseBTOFmatchOnly();
147  useBTOF = 1;
148  }
149 
150  } else if ( IAttr("VFPPVEv") || IAttr("VFPPVEvNoBTof") ) { // 2 version of PPV w/ & w/o Btof
151  LOG_INFO << "StGenericVertexMaker::Init: uses StvPPVertex finder(StEvent based)"<< endm;
152  LOG_INFO << "StPPVertexFinder::StPPVertexFinder is in use" << endm;
153 
154  theFinder= new StEvPPV::StPPVertexFinder();
155  useBTOF = (IAttr("VFPPVEvNoBTof"))? 0:1;
156 
157  } else if ( IAttr("VFFV") || IAttr("VFMCE")) {
158  theFinder = new StFixedVertexFinder();
159  if (IAttr("VFMCE")){
160  LOG_INFO << "StGenericVertexMaker::Init: fixed vertex using MC vertex" << endm;
161  theFinder->SetMode(1);
162  } else {
163  theFinder->SetVertexPosition(0.,0.,0);
164  LOG_INFO << "StGenericVertexMaker::Init: fixed vertex 'finder' selected" << endm;
165  }
166 
167  } else {
168  LOG_INFO << "StMinuitVertexFinder::StMinuitVertexFinder is in use." << endm;
169 
170  // Later, this would NEVER make multiple possible vertex
171  // finder unlike for option 0x1 .
172  theFinder= new StMinuitVertexFinder();
173  isMinuit=kTRUE;
174 
175  }
176 
177  theFinder->UsePCT(usePCT);
178  theFinder->UseBTOF(useBTOF);
179 
180  if(isMinuit) { // this is ugly, one should abort at 'else' above, Jan
181  if (useITTF) ((StMinuitVertexFinder*)theFinder)->DoUseITTF();
182  if (useCTB) ((StMinuitVertexFinder*)theFinder)->CTBforSeed();
183  } else {
184  assert(!eval); // current implementation support only Minuit Vertex finder, JB
185  }
186 
187  if (eval)
188  mEvalNtuple = new TNtuple("results", "results", "thX:thY:thZ:thStat:goodGlob:evX:evY:evZ:evStat:nPrim:nCTB:geantX:geantY:geantZ");
189 
190  theFinder->Init();
191  return StMaker::Init();
192 }
193 
194 //_____________________________________________________________________________
195 void StGenericVertexMaker::Clear(const char* opt){
196  LOG_INFO <<" StGenericVertexMaker::Clear()"<<endm;
197  theFinder->Clear();
198 }
199 
200 
201 //_____________________________________________________________________________
202 
211 Int_t StGenericVertexMaker::InitRun(int runnumber){
212 
213  St_db_Maker *st_db_maker = static_cast<St_db_Maker*>(GetMaker("db"));
214  theFinder->InitRun(runnumber, st_db_maker);
215 
216  return StMaker::InitRun(runnumber);
217 }
218 
219 
220 //_____________________________________________________________________________
222 {
223 
224  LOG_INFO << "StGenericVertexMaker::Finish " <<GetName() <<endm;
225  LOG_INFO << " Total events: " << nEvTotal << endm;
226  LOG_INFO << " Good events: " << nEvGood << endm;
227 
228 
229  //LSB TODO Leave this for now. Should really be using STAR/ROOT I/O scheme?
230  if (eval) {
231  TFile out("MinuitVertexEval.root","RECREATE");
232  mEvalNtuple->Write();
233  out.Close();
234  }
235 
236  if(theFinder) theFinder->Finish();
237  return kStOK;
238 }
239 
240 //_____________________________________________________________________________
241 //_____________________________________________________________________________
242 //_____________________________________________________________________________
243 Bool_t StGenericVertexMaker::DoFit(){
244 
245  if (theFinder->fit(mEvent)) {
246  theFinder->printInfo();
247  } else {
248  LOG_ERROR << "StGenericVertexMaker::DoFit: vertex fit failed, no vertex." << endm;
249  return kFALSE;
250  }
251 
252  return kTRUE;
253 
254 }
255 //_____________________________________________________________________________
256 //_____________________________________________________________________________
257 //_____________________________________________________________________________
258 
259 
260 //_____________________________________________________________________________
262 {
263  nEvTotal++;
264  primV = NULL;
265 
266  if (IAttr("useMuDst")) {
267  StMuDst* muDst = 0;
268  TClonesArray* vtxArray = 0;
269  WhiteBoard("muDst",&muDst);
270  WhiteBoard("vtxArray",&vtxArray);
271  if (!(vtxArray && muDst)) {
272  LOG_ERROR << "problems for refitting MuDst" << endm;
273  return kStErr;
274  }
275  theFinder->fit(*muDst);
276  theFinder->result(*vtxArray);
277  return kStOk;
278  }
279 
280  mEvent = (StEvent*) GetInputDS("StEvent");
281  LOG_DEBUG << "StGenericVertexMaker::Make: StEvent pointer " << mEvent << endm;
282  LOG_DEBUG << "StGenericVertexMaker::Make: external find use " << externalFindUse << endm;
283 
284  if(!externalFindUse){
285  DoFit();
286  }
287 
288  if (eval)MakeEvalNtuple();
289 
290  if(!externalFindUse){
292  if (theFinder->size()>0){
293  theFinder->FillStEvent(mEvent);
294  nEvGood++;
295  }
296  }
297  return kStOK;
298 }
299 
300 //-----------------------------------------------------------------------------
301 
302 void StGenericVertexMaker::MakeEvalNtuple(){ // only for Minuit vertex finder
303 
304  // get geant vertex
305  St_DataSet *gds=GetDataSet("geant");
306  St_g2t_vertex *g2t_ver=0;
307  g2t_vertex_st *gver=0;
308  if(gds) g2t_ver=( St_g2t_vertex *)gds->Find("g2t_vertex");
309  if(g2t_ver)gver=g2t_ver->GetTable();
310 
311  double gx = -999.;
312  double gy = -999.;
313  double gz = -999.;
314 
315  if(gver) {
316  gx=gver->ge_x[0];
317  gy=gver->ge_x[1];
318  gz=gver->ge_x[2];
319  }
320 
321 
322  // G E T P R I M V E R T E X
323  primV=mEvent->primaryVertex();
324  int nCtb= ((StMinuitVertexFinder*)theFinder)->NCtbMatches();
325  int stat= ((StMinuitVertexFinder*)theFinder)->statusMin();
326 
327  if (!primV) {
328  LOG_INFO <<"primaryVertex()=NULL"<<endm;
329  // why would one access x,y,z of the vertex if it is not found, Jan ???
330  float x=999,y=999,z=999;
331  mEvalNtuple->Fill(x,y,z,stat,mEvent->summary()->numberOfGoodTracks(),-999.,-999.,-999.,-999.,-999.,nCtb,gx,gy,gz);
332  } else
333  {
334  LOG_INFO << Form("primaryVertex()= %f, %f %f, nTracks=%d\n",
335  primV->position().x(), primV->position().y(), primV->position().z(),
336  primV->numberOfDaughters()) << endm;
337 
338  mEvalNtuple->Fill(primV->position().x(), primV->position().y(), primV->position().z(),
339  stat, mEvent->summary()->numberOfGoodTracks(),
340  primV->position().x(), primV->position().y(), primV->position().z(), primV->flag(),
341  primV->numberOfDaughters(), nCtb, gx, gy, gz);
342  }
343 }
virtual Int_t InitRun(Int_t runumber)
StGenericVertexFinder implementation for fixing vertex.
virtual const char * GetName() const
special overload
Definition: StMaker.cxx:237
Definition: Stypes.h:40
Definition: Stypes.h:44
Definition: Stypes.h:41
virtual TDataSet * Find(const char *path) const
Definition: TDataSet.cxx:362