StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
VtxRecoMuDst.C
1 // $Id: VtxRecoMuDst.C,v 1.4 2017/10/03 20:55:22 genevb Exp $
3 // Author: G. Van Buren (BNL)
4 //
5 // Description:
6 // Re-run vertex-finding on a MuDst
7 //
8 // options (attributes) are space-separated or comma-separated,
9 // and values are provided after a ':'
10 //
11 // Example options:
12 // beamline, beamline1D, beamline3D (otherwise no beamline)
13 // useBTOFmatchOnly
14 // VFstore:100
15 //
16 // Example list of options:
17 // "VFPPVnoCTB,beamline1D,VFstore:100"
18 //
20 //
21 // To run this macro compiled, try something like:
22 // echo 'gROOT->LoadMacro("VtxRecoMuDst.C");loadLibs();gROOT->ProcessLine(".U VtxRecoMuDst.C");gROOT->LoadMacro("VtxRecoMuDst.C+");VtxRecoMuDst(1000,"MuDsts/st_*.MuDst.root","out.MuDst.root","VFPPVnoCTB,beamline1D,VFstore:100")' | root4star -b
23 //
25 
26 
27 #if !defined(__CINT__) || defined(__MAKECINT__)
28 #include <algorithm>
29 #include <cfloat>
30 #include <iostream>
31 #include <string>
32 
33 #include "TROOT.h"
34 #include "TSystem.h"
35 #include "TChain.h"
36 #include "TClonesArray.h"
37 #include "TFile.h"
38 #include "TTree.h"
39 #include "TString.h"
40 #include "TObjArray.h"
41 
42 #include "StChain/StChain.h"
43 #include "St_db_Maker/St_db_Maker.h"
44 #include "StMuDSTMaker/COMMON/StMuDstMaker.h"
45 #include "StGenericVertexMaker/StGenericVertexMaker.h"
46 
47 #endif
48 
49 
50 void loadLibs()
51 {
52  gROOT->Macro("$STAR/StRoot/StMuDSTMaker/COMMON/macros/loadSharedLibraries.C");
53  gSystem->Load("libMinuit");
54  gSystem->Load("StDbBroker");
55  gSystem->Load("St_db_Maker");
56  gSystem->Load("Sti");
57  gSystem->Load("StEEmcUtil");
58  gSystem->Load("StBTofUtil");
59  gSystem->Load("StGenericVertexMaker");
60 }
61 
62 int VtxRecoMuDst(unsigned int nEventsUser, char* inputFileName, char* outputFileName, const char* options="")
63 {
64  loadLibs();
65 
66  StChain fullChain("fullChain");
67 
68  StMuDstMaker muDstMaker(0, 0, "", inputFileName, "st:MuDst.root", 1e9); // set up maker in read mode
69  // 0, 0 this means read mode
70  // dir read all files in this directory
71  // file bla.lis real all file in this list, if (file!="") dir is ignored
72  // filter apply filter to filenames, multiple filters are separated by ':'
73  // 10 maximum number of file to read
74 
75  // Specify (active) branches to read but first disable all branches
76  muDstMaker.SetStatus("*",1);
77  muDstMaker.SetStatus("PrimaryTracks",0);
78  muDstMaker.SetStatus("PrimaryVertices",0);
79 
80 
81  TChain& muDstChain = *muDstMaker.chain();
82  unsigned int nEntries = muDstChain.GetEntries();
83  unsigned int nEventsToRead = nEventsUser > 0 ? min(nEventsUser, nEntries) : nEntries;
84  cout << nEntries << " events in chain, " << nEventsToRead << " will be read." << endl;
85 
86  // Create new branch
87  TClonesArray* verticesRefitted = new TClonesArray("StMuPrimaryVertex", 1000);
88  TFile* outFile = new TFile(outputFileName, "RECREATE");
89  TTree* muDstTreeOut = muDstChain.CloneTree(0);
90  muDstTreeOut->Branch("PrimaryVertices", &verticesRefitted, 65536, 99);
91 
92  St_db_Maker* st_db_maker = new St_db_Maker("db", "StarDb", "MySQL:StarDb", "$STAR/StarDb");
93 
94  StGenericVertexMaker* vertexMaker = new StGenericVertexMaker();
95  vertexMaker->ToWhiteConst("vtxArray",verticesRefitted);
96  vertexMaker->SetAttr("useMuDst",1);
97 
98  // Set additional options as maker attributes
99  TString Options = options;
100  TString optDelim = " ,";
101  TObjArray* tokens = Options.Tokenize(optDelim);
102  for (int tk=0; tk < tokens->GetEntries(); tk++) {
103  TString& tok = ((TObjString*) (tokens->At(tk)))->String();
104  Ssiz_t delim = tok.First(':');
105  if (delim < 0) {
106  vertexMaker->SetAttr(tok.Data(),1);
107  } else {
108  TString key(tok(0,delim));
109  TString& val = tok.Remove(0,delim+1);
110  if (val.IsDigit()) { vertexMaker->SetAttr(key.Data(),val.Atoi()); }
111  else if (val.IsFloat()) { vertexMaker->SetAttr(key.Data(),val.Atof()); }
112  else { vertexMaker->SetAttr(key.Data(),val.Data()); }
113  }
114  }
115  vertexMaker->PrintAttr();
116 
117 
118  // Main loop over events
119  fullChain.Init();
120  for (unsigned int iEvent = 0; iEvent < nEventsToRead; iEvent++)
121  {
122  if ( fullChain.Make() ) break;
123  muDstTreeOut->Fill();
124  fullChain.Clear();
125  }
126 
127  outFile->Write();
128  outFile->Close();
129 
130  delete st_db_maker;
131  delete vertexMaker;
132  delete outFile;
133 }
134 
136 //
137 // $Log: VtxRecoMuDst.C,v $
138 // Revision 1.4 2017/10/03 20:55:22 genevb
139 // Add StBTofUtil lib dependence
140 //
141 // Revision 1.3 2017/09/28 13:54:07 jeromel
142 // Fix from Leszek Adamczyk
143 //
144 // Revision 1.2 2017/08/24 19:38:19 genevb
145 // Correct the MuDst branches loaded - old primary tracks and vertices no longer kept
146 //
147 // Revision 1.1 2017/05/24 05:14:13 genevb
148 // Introduce new macro to re-find vertices in MuDsts
149 //
150 //
TChain * chain()
In read mode, returns pointer to the chain of .MuDst.root files that where selected.
Definition: StMuDstMaker.h:426
void SetStatus(const char *arrType, int status)