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 (minTracks > 0) ((StMinuitVertexFinder*) theFinder)->SetMinimumTracks(minTracks);
116 
117  } else if ( IAttr("VFppLMV")){
118  theFinder= new StppLMVVertexFinder();
119  theFinder->SetMode(0); // this mode is an internal to ppLMV option switch
120 
121  } else if ( IAttr("VFppLMV5")){
122  theFinder= new StppLMVVertexFinder();
123  theFinder->SetMode(1); // this mode is an internal to ppLMV option switch
124 
125  } else if ( (IAttr("VFPPV") || IAttr("VFPPVnoCTB")) && !IAttr("VFPPVev")) {
126  // 2 version of PPV w/ & w/o CTB
127  LOG_INFO << "StGenericVertexMaker::Init: uses PPVertex finder"<< endm;
128  LOG_INFO << "StPPVertexFinder::StPPVertexFinder is in use" << endm;
129 
130  theFinder= new StPPVertexFinder(vertexFitMode);
131 
132  if ( IAttr("VFPPVnoCTB")) theFinder->UseCTB(kFALSE);
133 
134  // Because VFstore is a local optio used by users, make sure it is checked first
135  int vfstore = IAttr("VFstore");
136  // ... while the global option would not be used if the local one is used
137  //if (vfstore == 0) vfstore = IAttr(".gopt.VFstore"); <--- this will work whenevr gopt will be amde flexible
138 
139  if (vfstore > 0) {
140  LOG_INFO << "StGenericVertexMaker::Init: Using VFStore depth = " << vfstore << endm;
141  ((StPPVertexFinder*)theFinder)->SetStoreUnqualifiedVertex(vfstore);
142  }
143  if ( IAttr("useBTOFmatchOnly") ){
144  LOG_INFO << "StGenericVertexMaker::Init: UseBTOFmatchOnly option enabled" << endm;
145  ((StPPVertexFinder*)theFinder)->UseBTOFmatchOnly();
146  useBTOF = 1;
147  }
148 
149  } else if ( IAttr("VFPPVEv") || IAttr("VFPPVEvNoBTof") ) { // 2 version of PPV w/ & w/o Btof
150  LOG_INFO << "StGenericVertexMaker::Init: uses StvPPVertex finder(StEvent based)"<< endm;
151  LOG_INFO << "StPPVertexFinder::StPPVertexFinder is in use" << endm;
152 
153  theFinder= new StEvPPV::StPPVertexFinder();
154  useBTOF = (IAttr("VFPPVEvNoBTof"))? 0:1;
155 
156  } else if ( IAttr("VFFV") || IAttr("VFMCE")) {
157  theFinder = new StFixedVertexFinder();
158  if (IAttr("VFMCE")){
159  LOG_INFO << "StGenericVertexMaker::Init: fixed vertex using MC vertex" << endm;
160  theFinder->SetMode(1);
161  } else {
162  theFinder->SetVertexPosition(0.,0.,0);
163  LOG_INFO << "StGenericVertexMaker::Init: fixed vertex 'finder' selected" << endm;
164  }
165 
166  } else {
167  LOG_INFO << "StMinuitVertexFinder::StMinuitVertexFinder is in use." << endm;
168 
169  // Later, this would NEVER make multiple possible vertex
170  // finder unlike for option 0x1 .
171  theFinder= new StMinuitVertexFinder();
172  isMinuit=kTRUE;
173 
174  }
175 
176  theFinder->UsePCT(usePCT);
177  theFinder->UseBTOF(useBTOF);
178 
179  if(isMinuit) { // this is ugly, one should abort at 'else' above, Jan
180  if (useITTF) ((StMinuitVertexFinder*)theFinder)->DoUseITTF();
181  if (useCTB) ((StMinuitVertexFinder*)theFinder)->CTBforSeed();
182  } else {
183  assert(!eval); // current implementation support only Minuit Vertex finder, JB
184  }
185 
186  if (eval)
187  mEvalNtuple = new TNtuple("results", "results", "thX:thY:thZ:thStat:goodGlob:evX:evY:evZ:evStat:nPrim:nCTB:geantX:geantY:geantZ");
188 
189  theFinder->Init();
190  return StMaker::Init();
191 }
192 
193 //_____________________________________________________________________________
194 void StGenericVertexMaker::Clear(const char* opt){
195  LOG_INFO <<" StGenericVertexMaker::Clear()"<<endm;
196  theFinder->Clear();
197 }
198 
199 
200 //_____________________________________________________________________________
201 
210 Int_t StGenericVertexMaker::InitRun(int runnumber){
211 
212  St_db_Maker *st_db_maker = static_cast<St_db_Maker*>(GetMaker("db"));
213  theFinder->InitRun(runnumber, st_db_maker);
214 
215  return StMaker::InitRun(runnumber);
216 }
217 
218 
219 //_____________________________________________________________________________
221 {
222 
223  LOG_INFO << "StGenericVertexMaker::Finish " <<GetName() <<endm;
224  LOG_INFO << " Total events: " << nEvTotal << endm;
225  LOG_INFO << " Good events: " << nEvGood << endm;
226 
227 
228  //LSB TODO Leave this for now. Should really be using STAR/ROOT I/O scheme?
229  if (eval) {
230  TFile out("MinuitVertexEval.root","RECREATE");
231  mEvalNtuple->Write();
232  out.Close();
233  }
234 
235  if(theFinder) theFinder->Finish();
236  return kStOK;
237 }
238 
239 //_____________________________________________________________________________
240 //_____________________________________________________________________________
241 //_____________________________________________________________________________
242 Bool_t StGenericVertexMaker::DoFit(){
243 
244  if (theFinder->fit(mEvent)) {
245  theFinder->printInfo();
246  } else {
247  LOG_ERROR << "StGenericVertexMaker::DoFit: vertex fit failed, no vertex." << endm;
248  return kFALSE;
249  }
250 
251  return kTRUE;
252 
253 }
254 //_____________________________________________________________________________
255 //_____________________________________________________________________________
256 //_____________________________________________________________________________
257 
258 
259 //_____________________________________________________________________________
261 {
262  nEvTotal++;
263  primV = NULL;
264 
265  if (IAttr("useMuDst")) {
266  StMuDst* muDst = 0;
267  TClonesArray* vtxArray = 0;
268  WhiteBoard("muDst",&muDst);
269  WhiteBoard("vtxArray",&vtxArray);
270  if (!(vtxArray && muDst)) {
271  LOG_ERROR << "problems for refitting MuDst" << endm;
272  return kStErr;
273  }
274  theFinder->fit(*muDst);
275  theFinder->result(*vtxArray);
276  return kStOk;
277  }
278 
279  mEvent = (StEvent*) GetInputDS("StEvent");
280  LOG_DEBUG << "StGenericVertexMaker::Make: StEvent pointer " << mEvent << endm;
281  LOG_DEBUG << "StGenericVertexMaker::Make: external find use " << externalFindUse << endm;
282 
283  if(!externalFindUse){
284  DoFit();
285  }
286 
287  if (eval)MakeEvalNtuple();
288 
289  if(!externalFindUse){
291  if (theFinder->size()>0){
292  theFinder->FillStEvent(mEvent);
293  nEvGood++;
294  }
295  }
296  return kStOK;
297 }
298 
299 //-----------------------------------------------------------------------------
300 
301 void StGenericVertexMaker::MakeEvalNtuple(){ // only for Minuit vertex finder
302 
303  // get geant vertex
304  St_DataSet *gds=GetDataSet("geant");
305  St_g2t_vertex *g2t_ver=0;
306  g2t_vertex_st *gver=0;
307  if(gds) g2t_ver=( St_g2t_vertex *)gds->Find("g2t_vertex");
308  if(g2t_ver)gver=g2t_ver->GetTable();
309 
310  double gx = -999.;
311  double gy = -999.;
312  double gz = -999.;
313 
314  if(gver) {
315  gx=gver->ge_x[0];
316  gy=gver->ge_x[1];
317  gz=gver->ge_x[2];
318  }
319 
320 
321  // G E T P R I M V E R T E X
322  primV=mEvent->primaryVertex();
323  int nCtb= ((StMinuitVertexFinder*)theFinder)->NCtbMatches();
324  int stat= ((StMinuitVertexFinder*)theFinder)->statusMin();
325 
326  if (!primV) {
327  LOG_INFO <<"primaryVertex()=NULL"<<endm;
328  // why would one access x,y,z of the vertex if it is not found, Jan ???
329  float x=999,y=999,z=999;
330  mEvalNtuple->Fill(x,y,z,stat,mEvent->summary()->numberOfGoodTracks(),-999.,-999.,-999.,-999.,-999.,nCtb,gx,gy,gz);
331  } else
332  {
333  LOG_INFO << Form("primaryVertex()= %f, %f %f, nTracks=%d\n",
334  primV->position().x(), primV->position().y(), primV->position().z(),
335  primV->numberOfDaughters()) << endm;
336 
337  mEvalNtuple->Fill(primV->position().x(), primV->position().y(), primV->position().z(),
338  stat, mEvent->summary()->numberOfGoodTracks(),
339  primV->position().x(), primV->position().y(), primV->position().z(), primV->flag(),
340  primV->numberOfDaughters(), nCtb, gx, gy, gz);
341  }
342 }
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