StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
genDst.C
1 // $Id: genDst.C,v 1.9 2020/10/10 07:16:56 genevb Exp $
3 // Author: G. Van Buren (BNL)
4 //
5 // Description:
6 // Process a MuDst for...
7 // ...creating a PicoDst
8 // ...re-running vertex-finding to re-create MuDsts
9 //
10 // Options are space-separated or comma-separated,
11 // and case-insensitive. They can be attributed
12 // whose values are provided after a ':'.
13 //
14 // Example options for creating PicoDsts:
15 // picoDst
16 // btofMatch
17 // btofStartless
18 // mtdMatch
19 // y2017a
20 //
21 // Example lists of options:
22 // "picoDst"
23 // "DbV20200125,picoDst,mtdMatch,y2014a"
24 //
25 // Example options for vertex-finding:
26 // beamline, beamline1D, beamline3D (otherwise no beamline)
27 // useBTOFmatchOnly
28 // VFstore:100
29 //
30 // Example lists of options:
31 // "VFPPVnoCTB,beamline1D,VFstore:100"
32 // "VFPPVnoCTB,beamline3D"
33 //
35 
36 void genDst(unsigned int Last,
37  const char* options,
38  char* infile,
39  char* outfile=0);
40 
41 void genDst(unsigned int First,
42  unsigned int Last,
43  const char* options,
44  char* infile,
45  char* outfile=0);
46 
47 void loadLibs()
48 {
49  gROOT->Macro("$STAR/StRoot/StMuDSTMaker/COMMON/macros/loadSharedLibraries.C");
50  gSystem->Load("StDbBroker");
51  gSystem->Load("St_db_Maker");
52  gSystem->Load("StEEmcUtil");
53 }
54 
55 void loadLibsVF()
56 {
57  gSystem->Load("libMinuit");
58  gSystem->Load("Sti");
59  gSystem->Load("StBTofUtil");
60  gSystem->Load("StGenericVertexMaker");
61 }
62 
63 void loadLibsPico()
64 {
65 
66  // EMCs and FMS need DB+converters
67  gSystem->Load("StEmcRawMaker");
68  gSystem->Load("StEmcADCtoEMaker");
69  gSystem->Load("StPreEclMaker");
70  gSystem->Load("StEpcMaker");
71  gSystem->Load("StEEmcDbMaker");
72  gSystem->Load("StFmsUtil");
73  gSystem->Load("StFmsDbMaker");
74  gSystem->Load("StTriggerUtilities");
75 
76  // The PicoDst
77  gSystem->Load("libStPicoEvent");
78  gSystem->Load("libStPicoDstMaker");
79 }
80 
81 void loadLibsAgML()
82 {
83  // load support libraries. util will fail to load for agml 1.0, but you can ignore the error
84  gSystem->Load("libStarAgmlUtil");
85  gSystem->Load("libStarAgmlLib");
86 
87  // load geometry modules and master steering codes...
88  gSystem->Load("libGeometry");
89  gSystem->Load("libStarGeometry");
90 }
91 
92 void loadLibsMtd()
93 {
94  gSystem->Load("StDetectorDbMaker");
95  gSystem->Load("StarMagField");
96  gSystem->Load("StMagF");
97  gSystem->Load("StMtdUtil");
98  gSystem->Load("StMtdMatchMaker");
99  gSystem->Load("StMtdCalibMaker");
100 }
101 
102 void loadLibsBTof()
103 {
104  gSystem->Load("StBTofUtil");
105  gSystem->Load("StVpdCalibMaker");
106  gSystem->Load("StBTofCalibMaker");
107  gSystem->Load("StBTofMatchMaker");
108 }
109 
110 void loadLibsETof()
111 {
112  gSystem->Load("StETofUtil");
113  gSystem->Load("StETofCalibMaker");
114  gSystem->Load("StETofHitMaker");
115  gSystem->Load("StETofMatchMaker");
116 }
117 
118 void procGeoTag(TObjArray* optionTokens)
119 {
120  if (TClass::GetClass("AgBlock")) return; // arbitrarily chosen AgML class
121  loadLibsAgML();
122 
123  const char* tag = 0;
124  for (int tk=0; tk < optionTokens->GetEntries(); tk++) {
125  TString& tok = ((TObjString*) (optionTokens->At(tk)))->String();
126  if (tok.BeginsWith("y20")){
127  tag = tok.Data();
128  optionTokens->RemoveAt(tk);
129  optionTokens->Compress();
130  break;
131  }
132  }
133 
134  // Let agml know we want the ROOT geometry
135  AgModule::SetStacker( new StarTGeoStacker );
136 
137  // now pass the geometry "tag" and build. If the class StarGeometry exists, we have
138  // AgML 2.0 and can run using the new steering. Otherwise, old steering codes...
139  if (tag) {
140  if ( TClass::GetClass("StarGeometry") ) { StarGeometry::Construct( tag ); }
141  else { ( new Geometry() )->ConstructGeometry(tag); }
142  } else {
143  gMessMgr->Warning() << "No geometry tag passed! (e.g. y2017a)" << endm;
144  }
145 }
146 
147 bool findAndRemoveOption(const char* optionName, TObjArray* optionTokens)
148 {
149  TString optName = optionName;
150  optName.ToLower();
151  TObject* obj = optionTokens->FindObject(optName.Data());
152  if (obj) {
153  optionTokens->Remove(obj);
154  optionTokens->Compress();
155  return true;
156  }
157  return false;
158 }
159 
160 void genDst(unsigned int First,
161  unsigned int Last,
162  const char* options,
163  char* infile,
164  char* outfile)
165 {
166  loadLibs();
167 
168  StChain fullChain("genDst");
169 
170  StMuDstMaker muDstMaker(0, 0, "", infile, "st:MuDst.root", 1e9); // set up maker in read mode
171  // 0, 0 this means read mode
172  // dir read all files in this directory
173  // file bla.lis read all file in this list, if (file!="") dir is ignored
174  // filter apply filter to filenames, multiple filters are separated by ':'
175  // 10 maximum number of file to read
176 
177 
178  TChain& muDstChain = *muDstMaker.chain();
179  unsigned int nEntries = muDstChain.GetEntries();
180  unsigned int LastToRead = Last > 0 ? min(Last, nEntries) : nEntries;
181  gMessMgr->Info() << nEntries << " events in chain, " << LastToRead-First+1 << " will be read." << endm;
182 
183  St_db_Maker* db = new St_db_Maker("db", "StarDb", "MySQL:StarDb", "$STAR/StarDb");
184 
185  // Initialize some values and pointers
186  StMaker* processMaker = 0;
187  TFile* outFile = 0;
188  TTree* muDstTreeOut = 0;
189 
190  // Basic decisions based on options
191  TString CasedOptions = options;
192  TString Options = options;
193  Options.ToLower();
194  TString optDelim = " ,";
195  TObjArray* optionTokens = Options.Tokenize(optDelim);
196  optionTokens->SetOwner(kTRUE);
197 
198  // Determine database flavors
199  TString flavors = "ofl"; // default flavor for offline
200 
201  // simulation flavors
202  if (findAndRemoveOption("Simu",optionTokens) && ! findAndRemoveOption("NoSimuDb",optionTokens))
203  flavors.Prepend("sim+");
204 
205  // filestream flavors
206  TObject* firstFile = muDstChain.GetListOfFiles()->At(0);
207  if (firstFile) {
208  TString firstFileName = firstFile->GetTitle();
209  firstFileName = firstFileName(firstFileName.Last('/')+1,firstFileName.Length());
210  if (firstFileName.BeginsWith("st_")) {
211  TString fileStream = firstFileName(3,firstFileName.Index('_',3)-3);
212  if (fileStream.Length()>0) flavors.Prepend(fileStream += '+');
213  }
214  }
215 
216  gMessMgr->Info() << "Using DB flavors: " << flavors << endm;
217  db->SetFlavor(flavors.Data());
218 
219  if (findAndRemoveOption("picodst",optionTokens)) {
220  // _________________________________________________________________
221  // Processing with generation of PicoDsts
222 
223  loadLibsPico();
224 
225  // Specify active branches but first disable all branches
226  muDstMaker.SetStatus("*", 0);
227  muDstMaker.SetStatus("MuEvent", 1);
228  muDstMaker.SetStatus("PrimaryVertices", 1);
229  muDstMaker.SetStatus("PrimaryTracks", 1);
230  muDstMaker.SetStatus("GlobalTracks", 1);
231  muDstMaker.SetStatus("CovGlobTrack", 1);
232  muDstMaker.SetStatus("BTof*", 1);
233  muDstMaker.SetStatus("Emc*", 1);
234  muDstMaker.SetStatus("MTD*", 1);
235  muDstMaker.SetStatus("ETof*", 1);
236  muDstMaker.SetStatus("Epd*", 1);
237  muDstMaker.SetStatus("Fms*", 1);
238  muDstMaker.SetStatus("MCAll", 1);
239 
240  // EMCs
241  StEEmcDbMaker* eemcDb = new StEEmcDbMaker;
242  StEmcADCtoEMaker* adc2e = new StEmcADCtoEMaker();
243  adc2e->saveAllStEvent(true);
244  StPreEclMaker* pre_ecl = new StPreEclMaker();
245  StEpcMaker* epc = new StEpcMaker();
246 
247  // FMS
248  StFmsDbMaker* fmsDb = new StFmsDbMaker("fmsDb");
249 
250  // Trigger simulator
251  StTriggerSimuMaker* trigSimu = new StTriggerSimuMaker;
252  trigSimu->setMC(false);
253  trigSimu->useBemc();
254  trigSimu->useEemc();
255  trigSimu->useOfflineDB();
256  trigSimu->bemc->setConfig(StBemcTriggerSimu::kOffline);
257 
258  if (findAndRemoveOption("btofmatch",optionTokens)) {
259 
260  procGeoTag(optionTokens);
261  loadLibsBTof();
262 
263  // instantiate both VPD and BTOF CalibMakers and MatchMaker and point them to the MuDST
264  StBTofMatchMaker* btofMatch = new StBTofMatchMaker();
265  btofMatch->setMuDstIn();
266  StVpdCalibMaker *vpdCalib = new StVpdCalibMaker();
267  vpdCalib->setMuDstIn();
268  StBTofCalibMaker *btofCalib = new StBTofCalibMaker();
269  btofCalib->setMuDstIn();
270 
271  if (findAndRemoveOption("btofstartless",optionTokens)) {
272  //Disable the VPD as start detector, BTOF calib maker will switch to the "start-less" algorithm.
273  vpdCalib->setUseVpdStart(kFALSE);
274  }
275 
276  }
277 
278  if (findAndRemoveOption("etofmatch",optionTokens)) {
279 
280  procGeoTag(optionTokens);
281  loadLibsETof();
282 
283  // instantiate eTOF CalibMakers, HitMaker and MatchMaker
284  StETofCalibMaker* etofCalib = new StETofCalibMaker();
285  StETofHitMaker* etofHit = new StETofHitMaker();
286  StETofMatchMaker* etofMatch = new StETofMatchMaker();
287 
288  }
289 
290  if (findAndRemoveOption("mtdmatch",optionTokens)) {
291 
292  procGeoTag(optionTokens);
293  loadLibsMtd();
294 
295  StMagFMaker* magfMk = new StMagFMaker;
296  StMtdMatchMaker* mtdMatchMaker = new StMtdMatchMaker();
297  StMtdCalibMaker* mtdCalibMaker = new StMtdCalibMaker("mtdcalib");
298 
299  }
300 
301  processMaker = (StMaker*) (new StPicoDstMaker(StPicoDstMaker::IoWrite, infile, "picoDst"));
302 
303  } else if (Options.Contains("vf")) {
304  // _________________________________________________________________
305  // Processing with new vertex-finding
306 
307  loadLibsVF();
308 
309  // Specify inactive branches but first enable all branches
310  muDstMaker.SetStatus("*",1);
311  muDstMaker.SetStatus("PrimaryTracks",0);
312  muDstMaker.SetStatus("PrimaryVertices",0);
313 
314  // Create new branch
315  TClonesArray* verticesRefitted = new TClonesArray("StMuPrimaryVertex", 1000);
316 
317  // Specify output
318  if (outfile) {
319  outFile = new TFile(outfile, "RECREATE");
320  } else {
321  // Use the same filename for output as was given by input
322  TString fileStr = infile;
323  Ssiz_t dir = fileStr.Last('/');
324  if (dir<0) {
325  gMessMgr->Error() << "No specification for output when input is in local directory!" << endm;
326  return;
327  }
328  fileStr.Remove(0,dir+1);
329  outFile = new TFile(fileStr.Data(), "RECREATE");
330  }
331  muDstTreeOut = muDstChain.CloneTree(0);
332  muDstTreeOut->Branch("PrimaryVertices", &verticesRefitted, 65536, 99);
333 
334  processMaker = (StMaker*) (new StGenericVertexMaker());
335  processMaker->ToWhiteConst("vtxArray",verticesRefitted);
336  processMaker->SetAttr("useMuDst",1);
337 
338  } else {
339 
340  gMessMgr->Info() << "No processing specified - just reading a MuDst?" << endm;
341  // User code may be inserted here
342 
343  }
344 
345  // Set additional options (except DbV) as maker attributes
346  if (processMaker) {
347  for (int tk=0; tk < optionTokens->GetEntries(); tk++) {
348  TString& Tag = ((TObjString*) (optionTokens->At(tk)))->String();
349 
350  // copy of DbV code from StBFChain.cxx
351  if (Tag.BeginsWith("dbv")) {
352  int FDate=0,FTime=0;
353  if (Tag.Length() == 11) (void) sscanf(Tag.Data(),"dbv%8d",&FDate);
354  if (Tag.Length() == 18) (void) sscanf(Tag.Data(),"dbv%8d.%6d",&FDate,&FTime);
355  if (FDate) {
356  db->SetMaxEntryTime(FDate,FTime);
357  gMessMgr->Info() << "\tSet DataBase max entry time " << FDate << "/" << FTime
358  << " for St_db_Maker(\"" << db->GetName() <<"\")" << endm;
359  }
360  continue;
361  }
362 
363  // assign attributes
364  StMaker* attrMaker = processMaker;
365  Ssiz_t delim = Tag.First(':');
366  // look for "::" to set attributes for a different maker
367  if (delim > 0 && Tag[delim+1] == ':') {
368  TString altMakerName = Tag(0,delim);
369  // GetMaker...() functions are case sensitive, so find original case
370  Ssiz_t casedMakerNameIdx = CasedOptions.Index(altMakerName,0,TString::ECaseCompare::kIgnoreCase);
371  if (casedMakerNameIdx >= 0) altMakerName = CasedOptions(casedMakerNameIdx,delim);
372  StMaker* altMaker = fullChain.GetMaker(altMakerName.Data());
373  if (!altMaker) altMaker = fullChain.GetMakerInheritsFrom(altMakerName.Data());
374  if (!altMaker) {
375  gMessMgr->Warning() << "No maker found with name or class " << altMakerName.Data() << endm;
376  continue;
377  }
378  attrMaker = altMaker;
379  Tag.Remove(0,delim+2);
380  delim = Tag.First(':');
381  }
382  if (delim < 0) {
383  attrMaker->SetAttr(Tag.Data(),1);
384  } else {
385  TString key(Tag(0,delim));
386  TString& val = Tag.Remove(0,delim+1);
387  if (val.IsDigit()) { attrMaker->SetAttr(key.Data(),val.Atoi()); }
388  else if (val.IsFloat()) { attrMaker->SetAttr(key.Data(),val.Atof()); }
389  else { attrMaker->SetAttr(key.Data(),val.Data()); }
390  }
391  }
392  processMaker->PrintAttr();
393  }
394 
395  {
396  TDatime t;
397  gMessMgr->QAInfo() << Form("Run is started at Date/Time %i/%i",t.GetDate(),t.GetTime()) << endm;
398  }
399  gMessMgr->QAInfo() << Form("Run on %s in %s",gSystem->HostName(),gSystem->WorkingDirectory()) << endm;
400  gMessMgr->QAInfo() << Form("with %s", fullChain.GetCVS()) << endm;
401 
402 
403  // Main loop over events
404  int iInit = fullChain.Init();
405  if (iInit >= kStEOF) {fullChain.FatalErr(iInit,"on init"); return;}
406  if (Last == 0) return;
407  int eventCount = 0;
408  // Skip, if any
409  if (First > 1) fullChain.Skip(First - 1);
410  for (unsigned int iEvent = First; iEvent <= LastToRead; iEvent++)
411  {
412  int iMake = fullChain.Make();
413  if (iMake) {fullChain.FatalErr(iMake,"on make"); return;}
414 
415  if (muDstTreeOut) muDstTreeOut->Fill();
416 
417  int iClear = fullChain.Clear();
418  if (iClear) {fullChain.FatalErr(iClear,"on clear"); return;}
419  eventCount++;
420  }
421  fullChain.Finish();
422 
423  //
424  // ATTENTION - please DO NOT change the format of the next 2 lines,
425  // they are used by our DataManagement parsers to detect a generation
426  // was succesful and thereafter Catalog the produced files.
427  // Thank you.
428  //
429  gMessMgr->QAInfo() << "NumberOfEvents= " << eventCount << endm;
430  gMessMgr->QAInfo() << "Run completed " << endm;
431 
432  if (outFile) {
433  outFile->Write();
434  outFile->Close();
435  delete outFile;
436  }
437 
438  delete db;
439  delete processMaker;
440  delete optionTokens;
441 }
442 
443 //__________________________________________________________
444 void genDst(unsigned int Last,
445  const char* options,
446  char* infile,
447  char* outfile)
448 {
449  genDst(1,Last,options,infile,outfile);
450 }
451 
453 //
454 // $Log: genDst.C,v $
455 // Revision 1.10 2022/05/12 07:16:56 weidenkaff
456 // Added eTOF support
457 //
458 // $Log: genDst.C,v $
459 // Revision 1.9 2020/10/10 07:16:56 genevb
460 // Specify makers to set attributes
461 //
462 // Revision 1.8 2020/08/19 15:27:33 genevb
463 // Add DB flavors
464 //
465 // Revision 1.7 2020/01/25 05:10:00 genevb
466 // Include DbV, more like BFC
467 //
468 // Revision 1.6 2019/09/18 17:54:48 genevb
469 // Acivate additional branches by default
470 //
471 // Revision 1.5 2019/03/21 18:53:34 jeromel
472 // Added ATTENTION message
473 //
474 // Revision 1.4 2019/01/15 17:24:29 genevb
475 // Added FMS
476 //
477 // Revision 1.3 2018/03/16 18:41:14 genevb
478 // Add BTof-matching
479 //
480 // Revision 1.2 2017/12/15 18:36:53 genevb
481 // Remove explicit function of StPicoDstMaker...params should be passed by attribute
482 //
483 // Revision 1.1 2017/12/05 16:47:58 genevb
484 // Introduce genDst.C for creating new Dsts from MuDsts
485 //
486 //
virtual TDataSet * First() const
Return the first object in the list. Returns 0 when list is empty.
Definition: TDataSet.cxx:403
Class that converts MuDst into PicoDst.
virtual void Remove(TDataSet *set)
Remiove the &quot;set&quot; from this TDataSet.
Definition: TDataSet.cxx:641
virtual TDataSet * Last() const
Return the last object in the list. Returns 0 when list is empty.
Definition: TDataSet.cxx:437
void setUseVpdStart(const Bool_t val=kTRUE)
switch to force whether or not to use the VPD as the start time
void setMuDstIn(Bool_t muDstIn=kTRUE)
switch to read in StEvent/MuDst
void setMuDstIn(const bool val=kTRUE)
switch to read in StEvent/MuDst
Barrel TOF Match Maker.
Definition: Stypes.h:43
Muon Telescope Detector (MTD) Match Maker.
virtual const char * GetName() const
special overload
Definition: StMaker.cxx:237
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)
void saveAllStEvent(Bool_t a)
Set to kTRUE if all hits are to be saved on StEvent.
void setMuDstIn()
switch to read in StEvent/MuDst