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, bool doRemove=true)
148 {
149  TString optName = optionName;
150  optName.ToLower();
151  TObject* obj = optionTokens->FindObject(optName.Data());
152  if (obj) {
153  if (doRemove) {
154  optionTokens->Remove(obj);
155  optionTokens->Compress();
156  }
157  return true;
158  }
159  return false;
160 }
161 
162 bool findOption(const char* optionName, TObjArray* optionTokens)
163 {
164  return findAndRemoveOption(optionName,optionTokens,false);
165 }
166 
167 void genDst(unsigned int First,
168  unsigned int Last,
169  const char* options,
170  char* infile,
171  char* outfile)
172 {
173  loadLibs();
174 
175  StChain fullChain("genDst");
176 
177  StMuDstMaker muDstMaker(0, 0, "", infile, "st:MuDst.root", 1e9); // set up maker in read mode
178  // 0, 0 this means read mode
179  // dir read all files in this directory
180  // file bla.lis read all file in this list, if (file!="") dir is ignored
181  // filter apply filter to filenames, multiple filters are separated by ':'
182  // 10 maximum number of file to read
183 
184 
185  TChain& muDstChain = *muDstMaker.chain();
186  unsigned int nEntries = muDstChain.GetEntries();
187  unsigned int LastToRead = Last > 0 ? min(Last, nEntries) : nEntries;
188  gMessMgr->Info() << nEntries << " events in chain, " << LastToRead-First+1 << " will be read." << endm;
189 
190  St_db_Maker* db = new St_db_Maker("db", "StarDb", "MySQL:StarDb", "$STAR/StarDb");
191 
192  // Initialize some values and pointers
193  StMaker* processMaker = 0;
194  TFile* outFile = 0;
195  TTree* muDstTreeOut = 0;
196 
197  // Basic decisions based on options
198  TString CasedOptions = options;
199  TString Options = options;
200  Options.ToLower();
201  TString optDelim = " ,";
202  TObjArray* optionTokens = Options.Tokenize(optDelim);
203  optionTokens->SetOwner(kTRUE);
204 
205  // Determine database flavors
206  TString flavors = "ofl"; // default flavor for offline
207 
208  // FXT flavor
209  if (findOption("FXT",optionTokens))
210  flavors.Prepend("FXT+");
211 
212  // simulation flavors
213  if (findAndRemoveOption("Simu",optionTokens) && ! findAndRemoveOption("NoSimuDb",optionTokens))
214  flavors.Prepend("sim+");
215 
216  // filestream flavors
217  TObject* firstFile = muDstChain.GetListOfFiles()->At(0);
218  if (firstFile) {
219  TString firstFileName = firstFile->GetTitle();
220  firstFileName = firstFileName(firstFileName.Last('/')+1,firstFileName.Length());
221  if (firstFileName.BeginsWith("st_")) {
222  TString fileStream = firstFileName(3,firstFileName.Index('_',3)-3);
223  if (fileStream.Length()>0) flavors.Prepend(fileStream += '+');
224  }
225  }
226 
227  gMessMgr->Info() << "Using DB flavors: " << flavors << endm;
228  db->SetFlavor(flavors.Data());
229 
230  if (findAndRemoveOption("picodst",optionTokens)) {
231  // _________________________________________________________________
232  // Processing with generation of PicoDsts
233 
234  loadLibsPico();
235 
236  // Specify active branches but first disable all branches
237  muDstMaker.SetStatus("*", 0);
238  muDstMaker.SetStatus("MuEvent", 1);
239  muDstMaker.SetStatus("PrimaryVertices", 1);
240  muDstMaker.SetStatus("PrimaryTracks", 1);
241  muDstMaker.SetStatus("GlobalTracks", 1);
242  muDstMaker.SetStatus("CovGlobTrack", 1);
243  muDstMaker.SetStatus("BTof*", 1);
244  muDstMaker.SetStatus("Emc*", 1);
245  muDstMaker.SetStatus("MTD*", 1);
246  muDstMaker.SetStatus("ETof*", 1);
247  muDstMaker.SetStatus("Epd*", 1);
248  muDstMaker.SetStatus("Fms*", 1);
249  muDstMaker.SetStatus("MCAll", 1);
250 
251  // EMCs
252  StEEmcDbMaker* eemcDb = new StEEmcDbMaker;
253  StEmcADCtoEMaker* adc2e = new StEmcADCtoEMaker();
254  adc2e->saveAllStEvent(true);
255  StPreEclMaker* pre_ecl = new StPreEclMaker();
256  StEpcMaker* epc = new StEpcMaker();
257 
258  // FMS
259  StFmsDbMaker* fmsDb = new StFmsDbMaker("fmsDb");
260 
261  // Trigger simulator
262  StTriggerSimuMaker* trigSimu = new StTriggerSimuMaker;
263  trigSimu->setMC(false);
264  trigSimu->useBemc();
265  trigSimu->useEemc();
266  trigSimu->useOfflineDB();
267  trigSimu->bemc->setConfig(StBemcTriggerSimu::kOffline);
268 
269  if (findAndRemoveOption("btofmatch",optionTokens)) {
270 
271  procGeoTag(optionTokens);
272  loadLibsBTof();
273 
274  // instantiate both VPD and BTOF CalibMakers and MatchMaker and point them to the MuDST
275  StBTofMatchMaker* btofMatch = new StBTofMatchMaker();
276  btofMatch->setMuDstIn();
277  StVpdCalibMaker *vpdCalib = new StVpdCalibMaker();
278  vpdCalib->setMuDstIn();
279  StBTofCalibMaker *btofCalib = new StBTofCalibMaker();
280  btofCalib->setMuDstIn();
281 
282  if (findAndRemoveOption("btofstartless",optionTokens)) {
283  //Disable the VPD as start detector, BTOF calib maker will switch to the "start-less" algorithm.
284  vpdCalib->setUseVpdStart(kFALSE);
285  }
286 
287  if (findOption("FXT",optionTokens)) {
288  btofCalib->SetAttr("btofFXT", 1);
289  }
290 
291  }
292 
293  if (findAndRemoveOption("etofmatch",optionTokens)) {
294 
295  procGeoTag(optionTokens);
296  loadLibsETof();
297 
298  // instantiate eTOF CalibMakers, HitMaker and MatchMaker
299  StETofCalibMaker* etofCalib = new StETofCalibMaker();
300  StETofHitMaker* etofHit = new StETofHitMaker();
301  StETofMatchMaker* etofMatch = new StETofMatchMaker();
302 
303  }
304 
305  if (findAndRemoveOption("mtdmatch",optionTokens)) {
306 
307  procGeoTag(optionTokens);
308  loadLibsMtd();
309 
310  StMagFMaker* magfMk = new StMagFMaker;
311  StMtdMatchMaker* mtdMatchMaker = new StMtdMatchMaker();
312  StMtdCalibMaker* mtdCalibMaker = new StMtdCalibMaker("mtdcalib");
313 
314  }
315 
316  processMaker = (StMaker*) (new StPicoDstMaker(StPicoDstMaker::IoWrite, infile, "picoDst"));
317 
318  } else if (Options.Contains("vf")) {
319  // _________________________________________________________________
320  // Processing with new vertex-finding
321 
322  loadLibsVF();
323 
324  // Specify inactive branches but first enable all branches
325  muDstMaker.SetStatus("*",1);
326  muDstMaker.SetStatus("PrimaryTracks",0);
327  muDstMaker.SetStatus("PrimaryVertices",0);
328 
329  // Create new branch
330  TClonesArray* verticesRefitted = new TClonesArray("StMuPrimaryVertex", 1000);
331 
332  // Specify output
333  if (outfile) {
334  outFile = new TFile(outfile, "RECREATE");
335  } else {
336  // Use the same filename for output as was given by input
337  TString fileStr = infile;
338  Ssiz_t dir = fileStr.Last('/');
339  if (dir<0) {
340  gMessMgr->Error() << "No specification for output when input is in local directory!" << endm;
341  return;
342  }
343  fileStr.Remove(0,dir+1);
344  outFile = new TFile(fileStr.Data(), "RECREATE");
345  }
346  muDstTreeOut = muDstChain.CloneTree(0);
347  muDstTreeOut->Branch("PrimaryVertices", &verticesRefitted, 65536, 99);
348 
349  processMaker = (StMaker*) (new StGenericVertexMaker());
350  processMaker->ToWhiteConst("vtxArray",verticesRefitted);
351  processMaker->SetAttr("useMuDst",1);
352 
353  } else {
354 
355  gMessMgr->Info() << "No processing specified - just reading a MuDst?" << endm;
356  // User code may be inserted here
357 
358  }
359 
360  // Set additional options (except DbV) as maker attributes
361  if (processMaker) {
362  for (int tk=0; tk < optionTokens->GetEntries(); tk++) {
363  TString& Tag = ((TObjString*) (optionTokens->At(tk)))->String();
364 
365  // copy of DbV code from StBFChain.cxx
366  if (Tag.BeginsWith("dbv")) {
367  int FDate=0,FTime=0;
368  if (Tag.Length() == 11) (void) sscanf(Tag.Data(),"dbv%8d",&FDate);
369  if (Tag.Length() == 18) (void) sscanf(Tag.Data(),"dbv%8d.%6d",&FDate,&FTime);
370  if (FDate) {
371  db->SetMaxEntryTime(FDate,FTime);
372  gMessMgr->Info() << "\tSet DataBase max entry time " << FDate << "/" << FTime
373  << " for St_db_Maker(\"" << db->GetName() <<"\")" << endm;
374  }
375  continue;
376  }
377 
378  // assign attributes
379  StMaker* attrMaker = processMaker;
380  Ssiz_t delim = Tag.First(':');
381  // look for "::" to set attributes for a different maker
382  if (delim > 0 && Tag[delim+1] == ':') {
383  TString altMakerName = Tag(0,delim);
384  // GetMaker...() functions are case sensitive, so find original case
385  Ssiz_t casedMakerNameIdx = CasedOptions.Index(altMakerName,0,TString::ECaseCompare::kIgnoreCase);
386  if (casedMakerNameIdx >= 0) altMakerName = CasedOptions(casedMakerNameIdx,delim);
387  StMaker* altMaker = fullChain.GetMaker(altMakerName.Data());
388  if (!altMaker) altMaker = fullChain.GetMakerInheritsFrom(altMakerName.Data());
389  if (!altMaker) {
390  gMessMgr->Warning() << "No maker found with name or class " << altMakerName.Data() << endm;
391  continue;
392  }
393  attrMaker = altMaker;
394  Tag.Remove(0,delim+2);
395  delim = Tag.First(':');
396  }
397  if (delim < 0) {
398  attrMaker->SetAttr(Tag.Data(),1);
399  } else {
400  TString key(Tag(0,delim));
401  TString& val = Tag.Remove(0,delim+1);
402  if (val.IsDigit()) { attrMaker->SetAttr(key.Data(),val.Atoi()); }
403  else if (val.IsFloat()) { attrMaker->SetAttr(key.Data(),val.Atof()); }
404  else { attrMaker->SetAttr(key.Data(),val.Data()); }
405  }
406  }
407  processMaker->PrintAttr();
408  }
409 
410  {
411  TDatime t;
412  gMessMgr->QAInfo() << Form("Run is started at Date/Time %i/%i",t.GetDate(),t.GetTime()) << endm;
413  }
414  gMessMgr->QAInfo() << Form("Run on %s in %s",gSystem->HostName(),gSystem->WorkingDirectory()) << endm;
415  gMessMgr->QAInfo() << Form("with %s", fullChain.GetCVS()) << endm;
416 
417 
418  // Main loop over events
419  int iInit = fullChain.Init();
420  if (iInit >= kStEOF) {fullChain.FatalErr(iInit,"on init"); return;}
421  if (Last == 0) return;
422  int eventCount = 0;
423  // Skip, if any
424  if (First > 1) fullChain.Skip(First - 1);
425  for (unsigned int iEvent = First; iEvent <= LastToRead; iEvent++)
426  {
427  int iMake = fullChain.Make();
428  if (iMake) {fullChain.FatalErr(iMake,"on make"); return;}
429 
430  if (muDstTreeOut) muDstTreeOut->Fill();
431 
432  int iClear = fullChain.Clear();
433  if (iClear) {fullChain.FatalErr(iClear,"on clear"); return;}
434  eventCount++;
435  }
436  fullChain.Finish();
437 
438  //
439  // ATTENTION - please DO NOT change the format of the next 2 lines,
440  // they are used by our DataManagement parsers to detect a generation
441  // was succesful and thereafter Catalog the produced files.
442  // Thank you.
443  //
444  gMessMgr->QAInfo() << "NumberOfEvents= " << eventCount << endm;
445  gMessMgr->QAInfo() << "Run completed " << endm;
446 
447  if (outFile) {
448  outFile->Write();
449  outFile->Close();
450  delete outFile;
451  }
452 
453  delete db;
454  delete processMaker;
455  delete optionTokens;
456 }
457 
458 //__________________________________________________________
459 void genDst(unsigned int Last,
460  const char* options,
461  char* infile,
462  char* outfile)
463 {
464  genDst(1,Last,options,infile,outfile);
465 }
466 
468 //
469 // $Log: genDst.C,v $
470 // Revision 1.10 2022/05/12 07:16:56 weidenkaff
471 // Added eTOF support
472 //
473 // $Log: genDst.C,v $
474 // Revision 1.9 2020/10/10 07:16:56 genevb
475 // Specify makers to set attributes
476 //
477 // Revision 1.8 2020/08/19 15:27:33 genevb
478 // Add DB flavors
479 //
480 // Revision 1.7 2020/01/25 05:10:00 genevb
481 // Include DbV, more like BFC
482 //
483 // Revision 1.6 2019/09/18 17:54:48 genevb
484 // Acivate additional branches by default
485 //
486 // Revision 1.5 2019/03/21 18:53:34 jeromel
487 // Added ATTENTION message
488 //
489 // Revision 1.4 2019/01/15 17:24:29 genevb
490 // Added FMS
491 //
492 // Revision 1.3 2018/03/16 18:41:14 genevb
493 // Add BTof-matching
494 //
495 // Revision 1.2 2017/12/15 18:36:53 genevb
496 // Remove explicit function of StPicoDstMaker...params should be passed by attribute
497 //
498 // Revision 1.1 2017/12/05 16:47:58 genevb
499 // Introduce genDst.C for creating new Dsts from MuDsts
500 //
501 //
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