StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StPicoDstMaker.cxx
1 //
2 // StPicoDstMaker performs the conversion from MuDst to PicoDst
3 //
4 
5 // C++ headers
6 #include <algorithm>
7 #include <unordered_map>
8 #include <string>
9 #include <vector>
10 
11 // ROOT headers
12 #include "TRegexp.h"
13 #include "TChain.h"
14 #include "TClonesArray.h"
15 #include "TTree.h"
16 #include "TBranch.h"
17 #include "TObjectSet.h"
18 
19 // STAR headers
20 #include "StChain/StChain.h"
21 #include "StChain/StChainOpt.h"
22 #include "St_base/StMessMgr.h"
23 #include "StarRoot/TAttr.h"
24 #include "StarRoot/THelixTrack.h"
25 #include "StarClassLibrary/StThreeVector.hh"
26 #include "StarClassLibrary/StThreeVectorF.hh"
27 #include "StarClassLibrary/StThreeVectorD.hh"
28 #include "StarClassLibrary/StHelix.hh"
29 #include "StarClassLibrary/StPhysicalHelix.hh"
30 #include "StarClassLibrary/PhysicalConstants.h"
31 
32 #include "StEvent/StEvent.h"
33 #include "StEvent/StBTofHeader.h"
34 #include "StEvent/StDcaGeometry.h"
35 #include "StEvent/StEmcCollection.h"
36 #include "StEvent/StEmcCluster.h"
37 #include "StEvent/StEmcDetector.h"
38 #include "StEvent/StEmcModule.h"
39 #include "StEvent/StEmcRawHit.h"
40 #include "StEvent/StTriggerData.h"
41 #include "StEvent/StEnumerations.h"
42 #include "StEvent/StL0Trigger.h"
43 
44 #include "StMuDSTMaker/COMMON/StMuDst.h"
45 #include "StMuDSTMaker/COMMON/StMuEvent.h"
46 #include "StMuDSTMaker/COMMON/StMuBTofHit.h"
47 #include "StMuDSTMaker/COMMON/StMuTrack.h"
48 #include "StMuDSTMaker/COMMON/StMuPrimaryVertex.h"
49 #include "StMuDSTMaker/COMMON/StMuMtdHit.h"
50 #include "StMuDSTMaker/COMMON/StMuMtdPidTraits.h"
51 #include "StMuDSTMaker/COMMON/StMuMtdHeader.h"
52 #include "StMuDSTMaker/COMMON/StMuEmcCollection.h"
53 #include "StMuDSTMaker/COMMON/StMuEmcPoint.h"
54 #include "StMuDSTMaker/COMMON/StMuEmcUtil.h"
55 #include "StMuDSTMaker/COMMON/StMuFmsUtil.h"
56 #include "StMuDSTMaker/COMMON/StMuEpdHit.h"
57 #include "StMuDSTMaker/COMMON/StMuETofHit.h"
58 #include "StMuDSTMaker/COMMON/StMuETofDigi.h"
59 #include "StMuDSTMaker/COMMON/StMuETofHeader.h"
60 #include "StMuDSTMaker/COMMON/StMuMcTrack.h"
61 #include "StMuDSTMaker/COMMON/StMuMcVertex.h"
62 
63 #include "StTriggerUtilities/StTriggerSimuMaker.h"
64 #include "StTriggerUtilities/Bemc/StBemcTriggerSimu.h"
65 
66 #include "StEmcUtil/geometry/StEmcGeom.h"
67 #include "StEmcUtil/others/emcDetectorName.h"
68 #include "StEmcUtil/projection/StEmcPosition.h"
69 #include "StEmcRawMaker/defines.h"
70 #include "StEmcRawMaker/StBemcTables.h"
71 
72 #include "StFmsDbMaker/StFmsDbMaker.h"
73 
74 #include "tables/St_mtdModuleToQTmap_Table.h"
75 #include "tables/St_mtdQTSlewingCorr_Table.h"
76 #include "tables/St_mtdQTSlewingCorrPart2_Table.h"
77 
78 // PicoDst headers
79 #include "StPicoEvent/StPicoEvent.h"
80 #include "StPicoEvent/StPicoTrack.h"
81 #include "StPicoEvent/StPicoEmcTrigger.h"
82 #include "StPicoEvent/StPicoMtdTrigger.h"
83 #include "StPicoEvent/StPicoBbcHit.h"
84 #include "StPicoEvent/StPicoEpdHit.h"
85 #include "StPicoEvent/StPicoBTowHit.h"
86 #include "StPicoEvent/StPicoBTofHit.h"
87 #include "StPicoEvent/StPicoMtdHit.h"
88 #include "StPicoEvent/StPicoFmsHit.h"
89 #include "StPicoEvent/StPicoBEmcPidTraits.h"
90 #include "StPicoEvent/StPicoBTofPidTraits.h"
91 #include "StPicoEvent/StPicoMtdPidTraits.h"
92 #include "StPicoEvent/StPicoTrackCovMatrix.h"
93 #include "StPicoEvent/StPicoBEmcSmdEHit.h"
94 #include "StPicoEvent/StPicoBEmcSmdPHit.h"
95 #include "StPicoEvent/StPicoETofHit.h"
96 #include "StPicoEvent/StPicoETofPidTraits.h"
97 #include "StPicoEvent/StPicoMcVertex.h"
98 #include "StPicoEvent/StPicoMcTrack.h"
99 #include "StPicoEvent/StPicoArrays.h"
100 #include "StPicoEvent/StPicoDst.h"
101 #include "StPicoDstMaker/StPicoDstMaker.h"
102 #include "TSystem.h"
103 #if defined (__TFG__VERSION__)
104 #include "StarRoot/TDirIter.h"
105 #include "StMuDSTMaker/COMMON/StMuProbPidTraits.h"
106 #include "TH1.h"
107 #include "TH2.h"
108 static Int_t _debug = 0;
109 StPicoDstMaker *StPicoDstMaker::fgPicoDstMaker = 0;
110 #endif /* __TFG__VERSION__ */
111 #include "StPicoDstMaker/StPicoUtilities.h"
112 
113 //_________________
115 StMaker(name),
116 #if !defined (__TFG__VERSION__)
117 mTpcVpdVzDiffCut(6.),
118 #endif /* !__TFG__VERSION__ */
119 mMuDst(nullptr), mPicoDst(new StPicoDst()),
120 mEmcCollection(nullptr), mEmcPosition(nullptr),
121 mEmcGeom{}, mEmcIndex{},
122 mBField(0),
123 #if !defined (__TFG__VERSION__)
124  mVtxMode(PicoVtxMode::NotSet), // This should always be ::NotSet, do not change it, see ::Init()
125 #endif /* !__TFG__VERSION__ */
126  mCovMtxMode(PicoCovMtxMode::Skip),
127  mBEmcSmdMode(PicoBEmcSmdMode::SmdSkip),
128  mInputFileName(), mOutputFileName(), mOutputFile(nullptr),
129  mChain(nullptr), mTTree(nullptr), mEventCounter(0), mSplit(99), mCompression(9), mBufferSize(65536 * 4),
130  mModuleToQT{}, mModuleToQTPos{}, mQTtoModule{}, mQTSlewBinEdge{}, mQTSlewCorr{},
131  mPicoArrays{}, mStatusArrays{},
132  mFmsFiller(*mPicoDst) {
133 
134  streamerOff();
135  createArrays();
136  std::fill_n(mStatusArrays, sizeof(mStatusArrays) / sizeof(mStatusArrays[0]), 1);
137 
138 #if defined (__TFG__VERSION__)
139  fgPicoDstMaker = this;
140 #endif /* __TFG__VERSION__ */
141 }
142 
143 //_________________
144 StPicoDstMaker::StPicoDstMaker(PicoIoMode ioMode, char const* fileName,
145  char const* name) : StPicoDstMaker(name) {
146  // Constructor that pics IO mode, filename and extension
147  StMaker::m_Mode = ioMode;
148  mInputFileName = fileName;
149 }
150 
151 //_________________
153  delete mChain;
154  delete mPicoDst;
155 
156 #if defined (__TFG__VERSION__)
157  fgPicoDstMaker = 0;
158 #endif /* __TFG__VERSION__ */
159 }
160 
161 //_________________
162 void StPicoDstMaker::clearArrays() {
163  for(Int_t i=0; i<StPicoArrays::NAllPicoArrays; i++) {
164  mPicoArrays[i]->Clear();
165  }
166 }
167 
180 //_________________
181 void StPicoDstMaker::SetStatus(char const* branchNameRegex, int enable) {
182 
183  if(strncmp(branchNameRegex, "St", 2) == 0) {
184  branchNameRegex += 2; //Ignore first "St"
185  }
186 
187  TRegexp re(branchNameRegex, 1);
188  for(Int_t i=0; i<StPicoArrays::NAllPicoArrays; i++) {
189  Ssiz_t len;
190  if(re.Index(StPicoArrays::picoArrayNames[i], &len) < 0) {
191  continue;
192  }
193  LOG_INFO << "StPicoDstMaker::SetStatus " << enable << " to "
194  << StPicoArrays::picoArrayNames[i] << endm;
195  mStatusArrays[i] = enable;
196  }
197 
198  if(StMaker::m_Mode == PicoIoMode::IoRead) {
199  setBranchAddresses(mChain);
200  }
201 }
202 
203 //_________________
204 void StPicoDstMaker::setBranchAddresses(TChain* chain) {
205  if (!chain) return;
206  chain->SetBranchStatus("*", 0);
207  TString ts;
208  for (int i = 0; i < StPicoArrays::NAllPicoArrays; ++i) {
209  if (mStatusArrays[i] == 0) continue;
210  char const* bname = StPicoArrays::picoArrayNames[i];
211  TBranch* tb = chain->GetBranch(bname);
212  if (!tb) {
213  LOG_WARN << "setBranchAddress: Branch name " << bname
214  << " does not exist!" << endm;
215  continue;
216  }
217  ts = bname;
218  ts += "*";
219  chain->SetBranchStatus(ts, 1);
220  chain->SetBranchAddress(bname, mPicoArrays + i);
221  assert(tb->GetAddress() == (char*)(mPicoArrays + i));
222  }
223  mTTree = mChain->GetTree();
224 }
225 
226 //_________________
227 void StPicoDstMaker::streamerOff() {
228  // This is to to save space on the file. No need for TObject bits for this structure.
229  // see: https://root.cern.ch/doc/master/classTClass.html#a606b0442d6fec4b1cd52f43bca73aa51
230  StPicoEvent::Class()->IgnoreTObjectStreamer();
231  StPicoTrack::Class()->IgnoreTObjectStreamer();
232  StPicoBTofHit::Class()->IgnoreTObjectStreamer();
233  StPicoBTowHit::Class()->IgnoreTObjectStreamer();
234  StPicoMtdHit::Class()->IgnoreTObjectStreamer();
235  StPicoBbcHit::Class()->IgnoreTObjectStreamer();
236  StPicoEpdHit::Class()->IgnoreTObjectStreamer();
237  StPicoFmsHit::Class()->IgnoreTObjectStreamer();
238  StPicoBEmcSmdEHit::Class()->IgnoreTObjectStreamer();
239  StPicoBEmcSmdPHit::Class()->IgnoreTObjectStreamer();
240  StPicoEmcTrigger::Class()->IgnoreTObjectStreamer();
241  StPicoMtdTrigger::Class()->IgnoreTObjectStreamer();
242  StPicoBTofPidTraits::Class()->IgnoreTObjectStreamer();
243  StPicoBEmcPidTraits::Class()->IgnoreTObjectStreamer();
244  StPicoMtdPidTraits::Class()->IgnoreTObjectStreamer();
245  StPicoTrackCovMatrix::Class()->IgnoreTObjectStreamer();
246  StPicoETofHit::Class()->IgnoreTObjectStreamer();
247  StPicoETofPidTraits::Class()->IgnoreTObjectStreamer();
248  StPicoMcVertex::Class()->IgnoreTObjectStreamer();
249  StPicoMcTrack::Class()->IgnoreTObjectStreamer();
250 }
251 
252 //_________________
253 void StPicoDstMaker::createArrays() {
254 
255  for (Int_t i = 0; i < (StPicoArrays::NAllPicoArrays); ++i) {
256  mPicoArrays[i] = new TClonesArray(StPicoArrays::picoArrayTypes[i],
258  }
259  mPicoDst->set(mPicoArrays);
260 }
261 
262 //_________________
264 
265 #if defined (__TFG__VERSION__)
266  TString file;
267  Int_t l;
268 #endif /* __TFG__VERSION__ */
269 
270  switch (StMaker::m_Mode) {
271  case PicoIoMode::IoWrite:
272 
273 #if defined (__TFG__VERSION__)
274  if (StMuDst::vtxMode() == PicoVtxMode::NotSet) {
275 #else /* ! __TFG__VERSION__ */
276  if (mVtxMode == PicoVtxMode::NotSet) {
277 #endif /* __TFG__VERSION__ */
278 
279  if (setVtxModeAttr() != kStOK) {
280  LOG_ERROR << "Pico Vertex Mode is not set ... " << endm;
281  return kStFatal;
282  }
283  } //if (mVtxMode == PicoVtxMode::NotSet)
284 
285  // To write or not to write covariance matrices into the branch
286  if (setCovMtxModeAttr() != kStOK) {
287  LOG_ERROR << "Pico covariance matrix I/O mode is not set ..." << endm;
288  return kStFatal;
289  }
290 
291  // To write or not to write BEmc Smd hits into the branch
292  if (setBEmcSmdModeAttr() != kStOk) {
293  LOG_ERROR << "Pico BEmc Smd I/O mode is not set ..." << endm;
294  return kStFatal;
295  }
296 
297 #if !defined (__TFG__VERSION__)
298 
299  if (mInputFileName.Length() == 0) {
300  // No input file
301  mOutputFileName = GetChainOpt()->GetFileOut();
302  mOutputFileName.ReplaceAll(".root", ".picoDst.root");
303  }
304  else {
305  mInputFileName = gSystem->BaseName(mInputFileName);
306  mOutputFileName = mInputFileName;
307  mOutputFileName.ReplaceAll("MuDst.root", "picoDst.root");
308 
309  if (mOutputFileName == mInputFileName) {
310  LOG_ERROR << "Input file is not a MuDst ... " << endm;
311  return kStFatal;
312  }
313  }
314 #else /* __TFG__VERSION__ */
315  if (mInputFileName.Length() == 0) mInputFileName = GetChainOpt()->GetFileOut();
316  file = gSystem->BaseName(mInputFileName);
317  l = file.Index(".");
318  if (l < 0) l = file.Length();
319  mInputFileName = mInputFileName(mInputFileName.Index("st_"), mInputFileName.Length());
320  mOutputFileName = TString(file.Data(),l);
321  mOutputFileName += ".picoDst.root";
322 #endif /* __TFG__VERSION__ */
323 
324  openWrite();
325  initEmc();
326  break;
327 
328  case PicoIoMode::IoRead:
329  openRead();
330  break;
331 
332  default:
333  LOG_ERROR << "Pico IO mode is not set ... " << endm;
334  return kStErr;
335  }
336 
337 #if defined (__TFG__VERSION__)
338 #if defined (__HIST_PV__)
339  if (GetTFile()) {
340  GetTFile()->cd();
341  hists[0] = new TH1F("dca3D","global track dca3D wrt best Vx",2000,0,200);
342  hists[1] = new TH1F("dca3DLam","global track from Lambda",2000,0,200);
343  hists[2] = new TH1F("dca3DK0s","global track from K0s",2000,0,200);
344  pVrZ = new TH2F("pVrZ","rho VS Z for primary Vertex",200,-20,20,100,0,2);
345  pVxy = new TH2F("pVxy","Y Vs X for primary Vertex",2000,-2,2,2000,-2,2);
346  }
347 #endif /* __HIST_PV__ */
348 #endif /* __TFG__VERSION__ */
349 
350  return kStOK;
351 }
352 
353 //_________________
354 Int_t StPicoDstMaker::setVtxModeAttr(){
355 
356  // Read the Tpc-Vpd cut from the input
357  Float_t cut = DAttr("TpcVpdVzDiffCut");
358 #if defined (__TFG__VERSION__)
359  if ( cut != 0.0) StMuDst::instance()->SetTpcVpdVzDiffCut(cut);
360  LOG_INFO << " StMuDst::instance()->TpcVpdVzDiffCut() = " << StMuDst::instance()->TpcVpdVzDiffCut() << endm;
361 #else
362  if ( cut != 0.0) mTpcVpdVzDiffCut = cut;
363  LOG_INFO << " mTpcVpdVzDiffCut = " << mTpcVpdVzDiffCut << endm;
364 #endif /* __TFG__VERSION__ */
365 
366  if (strcasecmp(SAttr("PicoVtxMode"), "PicoVtxDefault") == 0) {
367  setVtxMode( PicoVtxMode::Default );
368  LOG_INFO << " PicoVtxDefault is being used " << endm;
369  return kStOK;
370  }
371  else if (strcasecmp(SAttr("PicoVtxMode"), "PicoVtxVpd") == 0) {
372  setVtxMode( PicoVtxMode::Vpd );
373  LOG_INFO << " PicoVtxVpd is being used " << endm;
374  return kStOK;
375  }
376  else if (strcasecmp(SAttr("PicoVtxMode"), "PicoVtxVpdOrDefault") == 0) {
377  setVtxMode( PicoVtxMode::VpdOrDefault );
378  LOG_INFO << " PicoVtxVpdOrDefault is being used " << endm;
379  return kStOK;
380  }
381  else if (strcasecmp(SAttr("PicoVtxMode"), "PicoVtxFXT") == 0) {
382  setVtxMode( PicoVtxMode::FXT );
383  LOG_INFO << " PicoVtxFXT is being used " << endm;
384  return kStOK;
385  }
386 #if !defined (__TFG__VERSION__)
387  else if (strcasecmp(SAttr("PicoVtxMode"), "PicoVtxMtd") == 0) {
388  setVtxMode( PicoVtxMode::Mtd );
389  LOG_INFO << " PicoVtxMtd is being used " << endm;
390  return kStOK;
391  }
392 #endif /* !__TFG__VERSION__ */
393 
394  return kStErr;
395 }
396 
397 //_________________
398 Int_t StPicoDstMaker::setCovMtxModeAttr() {
399 
400  // Choose the writing method: skip - do not write; write - write
401 
402  if (strcasecmp(SAttr("PicoCovMtxMode"), "PicoCovMtxWrite") == 0) {
403  setCovMtxMode(PicoCovMtxMode::Write);
404  LOG_INFO << " PicoCovMtxWrite is being used " << endm;
405  return kStOK;
406  }
407  else if ( (strcasecmp(SAttr("PicoCovMtxMode"), "") == 0) ||
408  (strcasecmp(SAttr("PicoCovMtxMode"), "PicoCovMtxSkip") == 0) ){
409  setCovMtxMode(PicoCovMtxMode::Skip);
410  LOG_INFO << " PicoCovMtxSkip is being used " << endm;
411  return kStOK;
412  }
413  /*
414  if (strcasecmp(SAttr("PicoCovMtxMode"), "PicoCovMtxSkip") == 0) {
415  setCovMtxMode(PicoCovMtxMode::Skip);
416  LOG_INFO << " PicoCovMtxSkip is being used " << endm;
417  return kStOK;
418  }
419  else if (strcasecmp(SAttr("PicoCovMtxMode"), "PicoCovMtxWrite") == 0) {
420  setCovMtxMode(PicoCovMtxMode::Write);
421  LOG_INFO << " PicoCovMtxWrite is being used " << endm;
422  return kStOK;
423  }
424  */
425 
426  // Only if something went wrong
427  return kStErr;
428 }
429 
430 //_________________
431 Int_t StPicoDstMaker::setBEmcSmdModeAttr() {
432 
433  // Choose the writing method: skip - do not write; write - write
434  if (strcasecmp(SAttr("PicoBEmcSmdMode"), "PicoBEmcSmdWrite") == 0) {
435  setBEmcSmdMode(PicoBEmcSmdMode::SmdWrite);
436  LOG_INFO << " PicoBEmcSmdWrite is being used " << endm;
437  return kStOK;
438  }
439  else if ( (strcasecmp(SAttr("PicoBEmcSmdMode"), "") == 0) ||
440  (strcasecmp(SAttr("PicoBEmcSmdMode"), "PicoBEmcSmdSkip") == 0) ){
441  setBEmcSmdMode(PicoBEmcSmdMode::SmdSkip);
442  LOG_INFO << " PicoBEmcSmdSkip is being used " << endm;
443  return kStOK;
444  }
445  return kStErr;
446 }
447 
448 //_________________
449 Int_t StPicoDstMaker::InitRun(Int_t const runnumber) {
450 
451  if (StMaker::m_Mode == PicoIoMode::IoWrite) {
452  if (!initMtd(runnumber)) {
453  LOG_ERROR << " MTD initialization error!!! " << endm;
454  return kStErr;
455  }
456  }
457  return kStOK;
458 }
459 
460 //_________________
461 Bool_t StPicoDstMaker::initMtd(Int_t const runnumber) {
462 
463  // Oct. 1st (approx. 273rd day) is the start of a new running year
464  int year = runnumber / 1e6 + 1999;
465  if ((runnumber % 1000000) / 1000 >= 273) year += 1;
466  LOG_INFO << "Run = " << runnumber << " year = " << year << endm;
467 
468  // Obtain maps from DB
469  for (Int_t i = 0; i < 30; ++i) {
470  for (Int_t j = 0; j < 5; ++j) {
471  mModuleToQT[i][j] = -1;
472  mModuleToQTPos[i][j] = -1;
473  }
474  }
475  for (Int_t i = 0; i < 8; ++i) {
476  for (Int_t j = 0; j < 8; ++j) {
477  mQTtoModule[i][j] = -1;
478  }
479  }
480 
481  LOG_INFO << "Retrieving mtdModuleToQTmap table from database ..." << endm;
482  TDataSet* dataset = GetDataBase("Geometry/mtd/mtdModuleToQTmap");
483  if(!dataset) {
484  LOG_ERROR << "No database (mtdModuleToQTmap) was found" << endm;
485  return kStErr;
486  }
487  St_mtdModuleToQTmap* mtdModuleToQTmap = static_cast<St_mtdModuleToQTmap*>(dataset->Find("mtdModuleToQTmap"));
488  if (!mtdModuleToQTmap) {
489  LOG_ERROR << "No mtdModuleToQTmap table was found in database" << endm;
490  return kStErr;
491  }
492  mtdModuleToQTmap_st* mtdModuleToQTtable = static_cast<mtdModuleToQTmap_st*>(mtdModuleToQTmap->GetTable());
493  if(!mtdModuleToQTtable) {
494  LOG_ERROR << "No mtdModuleToQTtable was found in mtdModuleToQTmap" << endm;
495  return kStErr;
496  }
497 
498  for (Int_t i = 0; i < 30; ++i) {
499  for (Int_t j = 0; j < 5; ++j) {
500  Int_t index = i * 5 + j;
501  Int_t qt = mtdModuleToQTtable->qtBoardId[index];
502  Int_t channel = mtdModuleToQTtable->qtChannelId[index];
503  mModuleToQT[i][j] = qt;
504  if (channel < 0) {
505  mModuleToQTPos[i][j] = channel;
506  }
507  else {
508  if (channel % 8 == 1) {
509  mModuleToQTPos[i][j] = 1 + channel / 8 * 2;
510  }
511  else {
512  mModuleToQTPos[i][j] = 2 + channel / 8 * 2;
513  }
514  }
515  if (mModuleToQT[i][j] > 0 && mModuleToQTPos[i][j] > 0) {
516  mQTtoModule[mModuleToQT[i][j] - 1][mModuleToQTPos[i][j] - 1] = j + 1;
517  }
518  } //for (Int_t j = 0; j < 5; ++j)
519  } //for (Int_t i = 0; i < 30; ++i)
520 
521  // online slewing correction for QT board
522  for (int j = 0; j < 8; ++j) {
523  for (int i = 0; i < 16; ++i) {
524  for (Int_t k = 0; k < 8; ++k) {
525  mQTSlewBinEdge[j][i][k] = -1;
526  mQTSlewCorr[j][i][k] = -1;
527  } //for (Int_t k = 0; k < 8; ++k)
528  } //for (int i = 0; i < 16; ++i)
529  } //for (int j = 0; j < 8; ++j)
530 
531  LOG_INFO << "Retrieving mtdQTSlewingCorr table from database ..." << endm;
532  dataset = GetDataBase("Calibrations/mtd/mtdQTSlewingCorr");
533  St_mtdQTSlewingCorr* mtdQTSlewingCorr = dataset ? static_cast<St_mtdQTSlewingCorr*>(dataset->Find("mtdQTSlewingCorr")) : nullptr;
534  if (!mtdQTSlewingCorr) {
535  LOG_ERROR << "No mtdQTSlewingCorr table found in database" << endm;
536  return kStErr;
537  }
538  mtdQTSlewingCorr_st* mtdQTSlewingCorrtable = static_cast<mtdQTSlewingCorr_st*>(mtdQTSlewingCorr->GetTable());
539  for (int j = 0; j < 4; ++j) {
540  for (int i = 0; i < 16; ++i) {
541  for (Int_t k = 0; k < 8; ++k) {
542  Int_t index = j * 16 * 8 + i * 8 + k;
543  mQTSlewBinEdge[j][i][k] = (int) mtdQTSlewingCorrtable->slewingBinEdge[index];
544  mQTSlewCorr[j][i][k] = (int) mtdQTSlewingCorrtable->slewingCorr[index];
545  } //for (Int_t k = 0; k < 8; ++k)
546  } //for (int i = 0; i < 16; ++i)
547  } //for (int j = 0; j < 4; ++j)
548  if (year == 2016) {
549  dataset = GetDataBase("Calibrations/mtd/mtdQTSlewingCorrPart2");
550  St_mtdQTSlewingCorrPart2* mtdQTSlewingCorr2 = dataset ? static_cast<St_mtdQTSlewingCorrPart2*>(dataset->Find("mtdQTSlewingCorrPart2")) : nullptr;
551  if (!mtdQTSlewingCorr2) {
552  LOG_ERROR << "No mtdQTSlewingCorr2 table found in database for year " << year << endm;
553  return kStErr;
554  }
555  mtdQTSlewingCorrPart2_st* mtdQTSlewingCorrtable2 = static_cast<mtdQTSlewingCorrPart2_st*>(mtdQTSlewingCorr2->GetTable());
556  for (int j = 0; j < 4; ++j) {
557  for (int i = 0; i < 16; ++i) {
558  for (Int_t k = 0; k < 8; ++k) {
559  Int_t index = j * 16 * 8 + i * 8 + k;
560  mQTSlewBinEdge[j + 4][i][k] = (int) mtdQTSlewingCorrtable2->slewingBinEdge[index];
561  mQTSlewCorr[j + 4][i][k] = (int) mtdQTSlewingCorrtable2->slewingCorr[index];
562  } //for (Int_t k = 0; k < 8; ++k)
563  } //for (int i = 0; i < 16; ++i)
564  } //for (int j = 0; j < 4; ++j)
565  } // if (year == 2016)
566 
567  return kTRUE;
568 }
569 
570 //_________________
572 
573  if (StMaker::m_Mode == PicoIoMode::IoRead) {
574  closeRead();
575  }
576  else if (StMaker::m_Mode == PicoIoMode::IoWrite) {
577  closeWrite();
578  finishEmc();
579  }
580  return kStOK;
581 }
582 
583 //_________________
584 Int_t StPicoDstMaker::openRead() {
585 
586  if (!mChain) mChain = new TChain("PicoDst");
587 
588  string const dirFile = mInputFileName.Data();
589  if (dirFile.find(".list") != string::npos) {
590  ifstream inputStream(dirFile.c_str());
591 
592  if (!inputStream) {
593  LOG_ERROR << "ERROR: Cannot open list file " << dirFile << endm;
594  return kStErr;
595  }
596 
597  int nFile = 0;
598  string file;
599  size_t pos;
600  while ( getline(inputStream, file) ) {
601  // NOTE: our external formatters may pass "file NumEvents"
602  // Take only the first part
603  //cout << "DEBUG found " << file << endl;
604  pos = file.find_first_of(" ");
605  if (pos!=string::npos ) file.erase(pos,file.length()-pos);
606  //cout << "DEBUG found [" << file << "]" << endl;
607 
608  if (file.find(".picoDst.root") != string::npos) {
609  TFile* ftmp = TFile::Open(file.c_str());
610  if (ftmp && !ftmp->IsZombie() && ftmp->GetNkeys()) {
611  LOG_INFO << " Read in picoDst file " << file << endm;
612  mChain->Add(file.c_str());
613  ++nFile;
614  }
615 
616  if (ftmp) ftmp->Close();
617  }
618  } // while (getline(inputStream, file))
619 
620  LOG_INFO << " Total " << nFile << " files have been read in. " << endm;
621 
622  }
623  else if (dirFile.find(".picoDst.root") != string::npos) {
624  mChain->Add(dirFile.c_str());
625  }
626  else {
627 #if defined (__TFG__VERSION__)
628  TDirIter Dir(dirFile.c_str());
629  Char_t *name = 0;
630  Int_t NFiles = 0;
631  while ((name = (Char_t *) Dir.NextFile())) {
632  TFile* ftmp = TFile::Open(name);
633  if (ftmp && !ftmp->IsZombie() && ftmp->GetNkeys()) {
634  LOG_INFO << " Read in picoDst file " << name << endm;
635  mChain->Add(name);
636  ++NFiles;
637  }
638  if (ftmp) ftmp->Close();
639  } // while ((name = (Char_t *) Dir.NextFile()))
640  if (! NFiles) {
641 #endif /* __TFG__VERSION__ */
642  LOG_WARN << " No good input file to read ... " << endm;
643  }
644 #ifdef __TFG__VERSION__
645  }
646 #endif /* __TFG__VERSION__ */
647 
648  // Set branch addresses and pointers
649  if (mChain) {
650  setBranchAddresses(mChain);
651  mChain->SetCacheSize(50e6);
652  mChain->AddBranchToCache("*");
653  mPicoDst->set(mPicoArrays);
654  }
655  return kStOK;
656 }
657 
658 //_________________
659 void StPicoDstMaker::openWrite() {
660 
661  mOutputFile = new TFile(mOutputFileName.Data(), "RECREATE");
662  LOG_INFO << " Output file: " << mOutputFileName.Data() << " created." << endm;
663  mOutputFile->SetCompressionLevel(mCompression);
664  int bufsize = mBufferSize;
665  if (mSplit) bufsize /= 4;
666  mTTree = new TTree("PicoDst", "StPicoDst", mSplit);
667  mTTree->SetAutoSave(1000000);
668  for (int i = 0; i < StPicoArrays::NAllPicoArrays; ++i) {
669  if (mStatusArrays[i] == 0) {
670  LOG_INFO << " Branch " << StPicoArrays::picoArrayNames[i] << " status is OFF! " << endm;
671  continue;
672  }
673 
674  mTTree->Branch(StPicoArrays::picoArrayNames[i], &mPicoArrays[i], bufsize, mSplit);
675  }
676 }
677 
678 //_________________
679 void StPicoDstMaker::initEmc() {
680 
681  // Create an instance of the StEmcPosition
682  mEmcPosition = new StEmcPosition();
683  // Fill the instance
684  for (int i = 0; i < 4; ++i) {
685  mEmcGeom[i] = StEmcGeom::getEmcGeom(detname[i].Data());
686  }
687 }
688 
689 //_________________
690 void StPicoDstMaker::buildEmcIndex(StEmcCollection *emcColl) {
691 
692  // Retrieve a pointer to BEMC
693  StEmcDetector* mEmcDet = emcColl->detector(kBarrelEmcTowerId);
694  // Clean EmcIndex
695  std::fill_n(mEmcIndex, sizeof(mEmcIndex) / sizeof(mEmcIndex[0]), nullptr);
696 
697  if (!mEmcDet) return;
698 
699  // Loop over 120 modules
700  for (size_t iMod = 1; iMod <= mEmcDet->numberOfModules(); ++iMod) {
701 
702  StSPtrVecEmcRawHit& modHits = mEmcDet->module(iMod)->hits();
703 
704  // Each module has 40 towers (that should work)
705  for (size_t iHit = 0; iHit < modHits.size(); ++iHit) {
706 
707  StEmcRawHit* rawHit = modHits[iHit];
708 
709  // If no tower information is available
710  // then we skip the current tower
711  if(!rawHit) continue;
712 
713  UInt_t softId = rawHit->softId(1);
714  if (mEmcGeom[0]->checkId(softId) == 0) { // OK
715 
716  // Here we store one to one correspondence
717  // between tower id (detector, module, eta, sub)
718  // and its softId (numerical order of the tower)
719  mEmcIndex[softId - 1] = rawHit;
720  }
721  } //for (size_t iHit = 0; iHit < modHits.size(); ++iHit)
722  } //for (size_t iMod = 1; iMod <= mEmcDet->numberOfModules(); ++iMod)
723 }
724 
725 //_________________
726 void StPicoDstMaker::finishEmc() {
727  delete mEmcPosition;
728  mEmcPosition = nullptr;
729 
730  std::fill_n(mEmcGeom, 4, nullptr);
731 }
732 
733 //_________________
734 void StPicoDstMaker::Clear(char const*) {
735  if (StMaker::m_Mode == PicoIoMode::IoRead)
736  return;
737  clearArrays();
738 }
739 
740 //_________________
741 void StPicoDstMaker::closeRead() {
742  delete mChain;
743  mChain = nullptr;
744 }
745 
746 //_________________
747 void StPicoDstMaker::closeWrite() {
748  if (StMaker::m_Mode == PicoIoMode::IoWrite) {
749  if (mOutputFile) {
750  mOutputFile->Write();
751  mOutputFile->Close();
752  }
753  }
754 }
755 
756 //_________________
758 
759  int returnStarCode = kStOK;
760 
761  if (StMaker::m_Mode == PicoIoMode::IoWrite) {
762  returnStarCode = MakeWrite();
763  }
764  else if (StMaker::m_Mode == PicoIoMode::IoRead) {
765  returnStarCode = MakeRead();
766 #if defined (__TFG__VERSION__)
767  if ( !mPicoDst->IsGoodTrigger()) return kStSkip;
768 #endif /* __TFG__VERSION__ */
769  }
770 
771  return returnStarCode;
772 }
773 
774 //_________________
775 Int_t StPicoDstMaker::MakeRead() {
776 
777  if (!mChain) {
778  LOG_WARN << " No input files ... ! EXIT" << endm;
779  return kStWarn;
780  }
781 
782  int bytes = mChain->GetEntry(mEventCounter++);
783  while( bytes <= 0) {
784  if( mEventCounter >= mChain->GetEntriesFast() ) {
785  return kStEOF;
786  }
787 
788  LOG_WARN << "Encountered invalid entry or I/O error while reading event "
789  << mEventCounter << " from \"" << mChain->GetName() << "\" input tree\n";
790  bytes = mChain->GetEntry(mEventCounter++);
791  }
792 
793  fillEventHeader();
794 
795  return kStOK;
796 }
797 
798 //_________________
799 Int_t StPicoDstMaker::MakeWrite() {
800 
801 #if defined (__TFG__VERSION__)
802  mMuDst = StMuDst::instance();
803 #else /* ! __TFG__VERSION__ */
804  StMaker::WhiteBoard("muDst", &mMuDst);
805 #endif /* __TFG__VERSION__ */
806 
807  if (!mMuDst) {
808  LOG_ERROR << "No \"StMuDst\" object found in this event. It is usually created by StMuDstMaker" << endm;
809  return kStErr;
810  }
811 
812  // Retrieve pointer to StMuEvent
813  StMuEvent* muEvent = mMuDst->event();
814 
815  if (!muEvent) {
816  LOG_WARN << " No MuEvent " << endm;
817  return kStWarn;
818  }
819 
820  int const originalVertexId = mMuDst->currentVertexIndex();
821 
822 #if defined (__TFG__VERSION__)
823  if (! mMuDst->numberOfMcVertices()) { // for MC it might be no Vpd
824 #endif /* __TFG__VERSION__ */
825 
826  if (!selectVertex()) {
827 
828 #if defined (__TFG__VERSION__)
829  static Int_t count = 0;
830  count++;
831  if (count < 13) {
832 #endif /* __TFG__VERSION__ */
833 
834  LOG_INFO << "Vertex is not valid" << endm;
835 
836 #if defined (__TFG__VERSION__)
837  }
838 #endif /* __TFG__VERSION__ */
839 
840  mMuDst->setVertexIndex(originalVertexId);
841  return kStOK;
842  }
843 
844 #if defined (__TFG__VERSION__)
845  } else {
846  if (! mMuDst->primaryVertices()->At(0)) {
847  static Int_t count = 0;
848  count++;
849  if (count < 13) {
850  LOG_INFO << "Vertex is not valid" << endm;
851  }
852  return kStOK;
853  }
854  }
855 #endif /* __TFG__VERSION__ */
856 
857  mBField = muEvent->magneticField();
858 
859 #if !defined (__TFG__VERSION__)
860  // Get Emc collection
861  mEmcCollection = mMuDst->emcCollection();
862  Bool_t isFromDaq = kFALSE;
863  if ( !mEmcCollection ) {
864  isFromDaq = kTRUE;
865 // static StMuEmcUtil emcUtil;
866  // Recover StEmcCollection in case of broken/deleted pointer
867  // This usually happens during daq->picoDst converstion
868  StEvent *evt = (StEvent *)GetDataSet("StEvent");
869  if(evt) {
870  mEmcCollection = evt->emcCollection();
871  }
872 // mEmcCollection = emcUtil.getEmc( mMuDst->muEmcCollection() );
873  }
874 
875  if (mEmcCollection) {
876  // Build EmcIndex before ::fillTracks()
877  buildEmcIndex(mEmcCollection);
878  // Fill BTOW hits only if ::buildEmcIndex() has been called for this event
879  fillBTowHits();
880  }
881 #endif /* !__TFG__VERSION__ */
882 
883 
884  // Fill StPicoEvent members
885  fillMcVertices();
886  fillMcTracks();
887  fillTracks();
888  fillEvent();
889  fillEmcTrigger();
890  fillMtdTrigger();
891  fillBTofHits();
892  fillMtdHits();
893  fillEpdHits();
894  fillBbcHits();
895  fillETofHits();
896 
897  // Could be a good idea to move this call to Init() or InitRun()
898  StFmsDbMaker* fmsDbMaker = static_cast<StFmsDbMaker*>(GetMaker("fmsDb"));
899 
900  if (fmsDbMaker) {
901  StMuFmsUtil::recoverMuFmsCollection(*mMuDst, fmsDbMaker);
902  }
903 
904  mFmsFiller.fill(*mMuDst);
905 
906  if (Debug()) mPicoDst->printTracks();
907 
908  mTTree->Fill();
909  if ( isFromDaq ) {
910 // delete mEmcCollection;
911  mEmcCollection = nullptr;
912  }
913 
914  mMuDst->setVertexIndex(originalVertexId);
915 
916  return kStOK;
917 }
918 
919 //_________________
920 void StPicoDstMaker::fillEventHeader() const {
921  StPicoEvent* event=StPicoDst::event();
922  if(!event) {
923  return;
924  }
925 
927  StEvtHddr* header=GetEvtHddr();
928  header->SetRunNumber(event->runId());
929  header->SetEventNumber(event->eventId());
930  header->SetGMTime( (UInt_t) (event->time()) );
931 }
932 
933 //_________________
934 void StPicoDstMaker::fillMcVertices() {
935 
936  // Retrieve pointer to MC vertices
937  TClonesArray *mcVertices = mMuDst->mcArray(0);
938 
939  // Loop over MC vertices
940  for (Int_t iVtx=0; iVtx<mcVertices->GetEntriesFast(); iVtx++) {
941 
942  // Retrieve i-th MC vertex from MuDst
943  StMuMcVertex *mcVertex = (StMuMcVertex*)mcVertices->UncheckedAt(iVtx);
944 
945  // Obtain size of the MC vertex pico array
946  int counter = mPicoArrays[StPicoArrays::McVertex]->GetEntries();
947 
948  // Create new empty StPicoMcVertex and add it into collection
949  new((*(mPicoArrays[StPicoArrays::McVertex]))[counter]) StPicoMcVertex();
950 
951  // Return pointer to the picoMcVertex
952  StPicoMcVertex* picoMcVtx = (StPicoMcVertex*)mPicoArrays[StPicoArrays::McVertex]->At(counter);
953 
954  picoMcVtx->setId( mcVertex->Id() );
955  picoMcVtx->setNumberOfDaughters( mcVertex->NoDaughters() );
956  picoMcVtx->setIdOfParentTrack( mcVertex->IdParTrk() );
957  picoMcVtx->setIsIntermediate( mcVertex->IsIntermedate() );
958  picoMcVtx->setTime( mcVertex->Time() );
959  picoMcVtx->setPosition( mcVertex->XyzV().x(), mcVertex->XyzV().y(), mcVertex->XyzV().z() );
960 
961  } // for (Int_t iVtx=0; iVtx<mcVertices->GetEntriesFast(); iVtx++)
962 }
963 
964 //________________
965 void StPicoDstMaker::fillMcTracks() {
966 
967  // Retrieve pointer to MC tracks
968  TClonesArray *mcTracks = mMuDst->mcArray(1);
969 
970  // Loop over MC vertices
971  for (Int_t iVtx=0; iVtx<mcTracks->GetEntriesFast(); iVtx++) {
972 
973  // Retrieve i-th MC vertex from MuDst
974  StMuMcTrack *mcTrack = (StMuMcTrack*)mcTracks->UncheckedAt(iVtx);
975 
976  if ( !mcTrack ) continue;
977 
978  // Obtain size of the MC vertex pico array
979  int counter = mPicoArrays[StPicoArrays::McTrack]->GetEntries();
980 
981  // Create new empty StPicoMcVertex and add it into collection
982  new((*(mPicoArrays[StPicoArrays::McTrack]))[counter]) StPicoMcTrack();
983 
984  // Return pointer to the picoMcVertex
985  StPicoMcTrack* picoMcTrk = (StPicoMcTrack*)mPicoArrays[StPicoArrays::McTrack]->At(counter);
986 
987  picoMcTrk->setId( mcTrack->Id() );
988  picoMcTrk->setGeantId( mcTrack->GePid() );
989  picoMcTrk->setCharge( mcTrack->Charge() );
990  picoMcTrk->setP( mcTrack->Pxyz().x(),
991  mcTrack->Pxyz().y(),
992  mcTrack->Pxyz().z() );
993  picoMcTrk->setE( mcTrack->E() );
994  picoMcTrk->setIsFromShower( mcTrack->IsShower() );
995  picoMcTrk->setIdVtxStart( mcTrack->IdVx() );
996  picoMcTrk->setIdVtxStop( mcTrack->IdVxEnd() );
997  picoMcTrk->setIdVtxItrmd( mcTrack->ItrmdVertex() );
998  for (Int_t iDet=StMuMcTrack::EHIT::ktpc; iDet<StMuMcTrack::EHIT::ktot; iDet++) {
999  picoMcTrk->setNHits( iDet, mcTrack->NoHits(iDet) );
1000  }
1001 
1002  } // for (Int_t iVtx=0; iVtx<mcVertices->GetEntriesFast(); iVtx++)
1003 }
1004 
1005 //_________________
1006 void StPicoDstMaker::fillTracks() {
1007 
1008 #if defined (__TFG__VERSION__)
1009  if ( !mMuDst->primaryVertex()) return;
1010 #endif
1011 
1012  // We save primary tracks associated with the selected primary vertex only
1013  // don't use StMuTrack::primary(), it returns primary tracks associated with
1014  // all vertices
1015  std::unordered_map<unsigned int, unsigned int> index2Primary;
1016 
1017  // Retrieve number of primary tracks
1018  Int_t nPrimarys = mMuDst->numberOfPrimaryTracks();
1019 
1020  // Loop over primary trakcs
1021  for (int i = 0; i < nPrimarys; ++i) {
1022  StMuTrack* pTrk = (StMuTrack*)mMuDst->primaryTracks(i);
1023  if(!pTrk) continue;
1024 
1025 #if defined (__TFG__VERSION__)
1026  if ( !mMuDst->Accept(pTrk) ) continue;
1027 #endif /* __TFG__VERSION__ */
1028 
1029  index2Primary[pTrk->id()] = i;
1030  } // for (int i = 0; i < nPrimarys; ++i)
1031 
1032  // Retrieve number of global tracks
1033  Int_t nGlobals = mMuDst->numberOfGlobalTracks();
1034 
1035  // Loop over global tracks
1036  for (int i = 0; i < nGlobals; ++i) {
1037 
1038  // Retrieve i-th global track
1039  StMuTrack* gTrk = (StMuTrack*)mMuDst->globalTracks(i);
1040 
1041  // Check the existence and track type
1042  if( !gTrk ) continue;
1043  if( gTrk->type()!=global ) continue;
1044 
1045  // Obtain primary track that corresponds to gTrk
1046  StMuTrack const* const pTrk = index2Primary.find(gTrk->id()) != index2Primary.end() ?
1047  (StMuTrack*)mMuDst->primaryTracks(index2Primary[gTrk->id()]) : nullptr;
1048 
1049  // Check that if primary track exists, it should have a primary flag
1050  if(pTrk) {
1051  // Check track type and global2primary correspondence
1052  if (pTrk->type() != primary) continue;
1053  if (pTrk->id() != gTrk->id()) continue;
1054  }
1055 
1056  // Global track should correspondence to some covariance information
1057  if(gTrk->index2Cov() < 0) continue;
1058 
1059  // Obtain DCA information (covariance matrix)
1060  StDcaGeometry* dcaG = mMuDst->covGlobTracks(gTrk->index2Cov());
1061  if(!dcaG) {
1062  LOG_WARN << "No dca Geometry for this track !!! " << i << endm;
1063  continue;
1064  }
1065 
1066 #if defined (__TFG__VERSION__)
1067  if ( StMuDst::dca3Dmax()>0 ) {
1068  // Cut large Dca
1069  THelixTrack t = dcaG->thelix();
1070  StThreeVectorD V(mMuDst->primaryVertex()->position());
1071  Double_t dca3D = t.Dca(V.xyz());
1072 #if defined (__HIST_PV__)
1073  if (hists[0]) {
1074  hists[0]->Fill(dca3D);
1075  Int_t IdMc = gTrk->idTruth();
1076  if (IdMc) {
1077  StMuMcTrack *mcTrk = StMuDst::instance()->MCtrack(IdMc-1);
1078  assert(mcTrk);
1079  assert(IdMc == mcTrk->Id());
1080  Int_t IdVx = mcTrk->IdVx(); // parent vertex
1081  assert(IdVx);
1082  StMuMcVertex *MuVx = StMuDst::instance()->MCvertex(IdVx-1);
1083  assert(MuVx);
1084  Int_t IdParentTk = MuVx->IdParTrk();
1085  if (IdParentTk) {
1086  StMuMcTrack *mcParentTrk = StMuDst::instance()->MCtrack(IdParentTk-1);
1087  assert(mcParentTrk);
1088 #if 1
1089  Int_t pdg = mcParentTrk->Pdg();
1090  assert(pdg);
1091  if (TMath::Abs(pdg) == 3122) {
1092  hists[1]->Fill(dca3D);
1093  } else if (pdg == 310) {
1094  hists[2]->Fill(dca3D);
1095  }
1096 #else
1097  Int_t gePid = mcParentTrk->GePid();
1098  if (gePid == 18 || gePid == 26) {
1099  hists[1]->Fill(dca3D);
1100  } else if (gePid == 16) {
1101  hists[2]->Fill(dca3D);
1102  }
1103 #endif
1104  }
1105  }
1106  }
1107 #endif /* __HIST_PV__ */
1108  if (dca3D > StMuDst::dca3Dmax()) continue;
1109  }
1110 #endif /* __TFG__VERSION__ */
1111 
1112 
1113  // Obtain size of the picoTrack array
1114  int counter = mPicoArrays[StPicoArrays::Track]->GetEntries();
1115 
1116  // Create new empty StPicoTrack and add it into collection
1117  new((*(mPicoArrays[StPicoArrays::Track]))[counter]) StPicoTrack();
1118 
1119  // Return pointer to the picoTrack
1120  StPicoTrack* picoTrk = (StPicoTrack*)mPicoArrays[StPicoArrays::Track]->At(counter);
1121 
1122  // Fill basic track information here
1123  picoTrk->setId( gTrk->id() );
1124  picoTrk->setChi2( gTrk->chi2() );
1125  // Store dE/dx in KeV/cm and its error. Next lines are needed
1126  // in order to store the values obrained with the same method:
1127  // either truncated mean of fit. Starting SL14 the default was
1128  // changed from thuncated mean to fit.
1129 #if !defined (__TFG__VERSION__)
1130  static TString Production(mMuDst->event()->runInfo().productionVersion());
1131  static TString prodYear(Production.Data()+2,2);
1132  static Int_t defY = prodYear.Atoi();
1133  static StDedxMethod defaultdEdxMethod = (defY > 0 && defY < 14) ? kTruncatedMeanId : kLikelihoodFitId;
1134 #else
1135  static StDedxMethod defaultdEdxMethod = kLikelihoodFitId;
1136 #endif
1137  if (defaultdEdxMethod == kTruncatedMeanId) {
1138  picoTrk->setDedx( gTrk->probPidTraits().dEdxTruncated() );
1139  picoTrk->setDedxError( gTrk->probPidTraits().dEdxErrorTruncated() );
1140  }
1141  else {
1142  picoTrk->setDedx( gTrk->probPidTraits().dEdxFit() );
1143  picoTrk->setDedxError( gTrk->probPidTraits().dEdxErrorFit() );
1144  }
1145 
1146  picoTrk->setDndx( gTrk->probPidTraits().dNdxFit() );
1147  picoTrk->setDndxError( gTrk->probPidTraits().dNdxErrorFit() );
1148  if ( gTrk->primaryTrack() ) {
1149  picoTrk->setStatus(1);
1150  }
1151  else {
1152  picoTrk->setStatus(0);
1153  }
1154 
1155 
1156  // Fill track's hit information
1157  picoTrk->setNHitsDedx( gTrk->nHitsDedx() );
1158 
1159  Int_t flag = gTrk->flag();
1160  if (flag / 100 < 7) { // TPC tracks
1161  picoTrk->setNHitsFit( gTrk->nHitsFit(kTpcId) * gTrk->charge() );
1162  picoTrk->setNHitsMax( gTrk->nHitsPoss(kTpcId) );
1163  }
1164  else { // FTPC tracks
1165  if (gTrk->helix().momentum(mBField * kilogauss).pseudoRapidity() > 0.) {
1166  //West FTPC
1167  picoTrk->setNHitsFit( gTrk->nHitsFit(kFtpcWestId) * gTrk->charge() );
1168  picoTrk->setNHitsMax( gTrk->nHitsPoss(kFtpcWestId) );
1169  }
1170  else {
1171  // East FTPC
1172  picoTrk->setNHitsFit( gTrk->nHitsFit(kFtpcEastId) * gTrk->charge() );
1173  picoTrk->setNHitsMax( gTrk->nHitsPoss(kFtpcEastId) );
1174  }
1175  }
1176 
1177  // Fill nSigmaPID information
1178  picoTrk->setNSigmaElectron( gTrk->nSigmaElectron() );
1179  picoTrk->setNSigmaPion( gTrk->nSigmaPion() );
1180  picoTrk->setNSigmaKaon( gTrk->nSigmaKaon() );
1181  picoTrk->setNSigmaProton( gTrk->nSigmaProton() );
1182 
1183  // Fill topology map (2 words for standard && 3 words for TFG_VERSION)
1184  for(UInt_t iMap=0; iMap<StPicoTrack::eTopologyMap; iMap++) {
1185  picoTrk->setTopologyMap( iMap, gTrk->topologyMap().data(iMap) );
1186  }
1187 #if !defined (__TFG__VERSION__)
1188  // Fill iTPC topology map
1189  picoTrk->setiTpcTopologyMap( gTrk->topologyMap().data(2) );
1190 #endif
1191 
1192  // Calculate global momentum and position at point of DCA to the pVtx
1193  // at it is done in MuDst
1194  if( dcaG ) {
1195  const StThreeVectorF &pvert = mMuDst->primaryVertex()->position();
1196  Double_t vtx[3] = {pvert[0],pvert[1],pvert[2]};
1197  THelixTrack thelix = dcaG->thelix();
1198  thelix.Move(thelix.Path(vtx));
1199  const Double_t *pos = thelix.Pos();
1200  const Double_t *mom = thelix.Dir();
1201  StThreeVectorF momAtDca(mom[0], mom[1], mom[2]);
1202  momAtDca *= dcaG->momentum().mag();
1203  picoTrk->setGlobalMomentum( momAtDca[0], momAtDca[1], momAtDca[2] );
1204  picoTrk->setOrigin( pos[0], pos[1], pos[2] );
1205  }
1206  else {
1207  StPhysicalHelixD gHelix = dcaG->helix();
1208  gHelix.moveOrigin( gHelix.pathLength( mMuDst->primaryVertex()->position() ) );
1209  StThreeVectorF globMom = gHelix.momentum( mBField * kilogauss );
1210  StThreeVectorF globOrigin = gHelix.origin();
1211  picoTrk->setGlobalMomentum( globMom.x(),
1212  globMom.y(),
1213  globMom.z() );
1214  picoTrk->setOrigin( globOrigin.x(),
1215  globOrigin.y(),
1216  globOrigin.z() );
1217  }
1218 
1219  /*
1220  // Old picoDst style
1221  StPhysicalHelixD gHelix = dcaG->helix();
1222  gHelix.moveOrigin( gHelix.pathLength( mMuDst->primaryVertex()->position() ) );
1223  StThreeVectorF globMom = gHelix.momentum( mBField * kilogauss );
1224  StThreeVectorF globOrigin = gHelix.origin();
1225  picoTrk->setGlobalMomentum( globMom.x(),
1226  globMom.y(),
1227  globMom.z() );
1228  picoTrk->setOrigin( globOrigin.x(),
1229  globOrigin.y(),
1230  globOrigin.z() );
1231  */
1232 
1233  // Save primary track momentum
1234  picoTrk->setPrimaryMomentum( 0., 0., 0. ); //Should be initialized in the constructor
1235  if (pTrk) {
1236  picoTrk->setPrimaryMomentum( pTrk->momentum().x(),
1237  pTrk->momentum().y(),
1238  pTrk->momentum().z() );
1239  } //if(pTrk)
1240 
1241 
1242  // Fill Monte Carlo information (idTruth)
1243  picoTrk->setMcTruth( gTrk->idTruth(), gTrk->qaTruth() );
1244 
1245  // Fill covariance matrix. Fill it only if the flag was set up
1246  if( mCovMtxMode == PicoCovMtxMode::Write ) {
1247 
1248  // Retrieve index in the PicoTrackCovMatrix pico array
1249  Int_t cov_index = mPicoArrays[StPicoArrays::TrackCovMatrix]->GetEntries();
1250  // Create new empty instance. It must be initialized with 0 (default constructor)
1251  new((*(mPicoArrays[StPicoArrays::TrackCovMatrix]))[cov_index]) StPicoTrackCovMatrix();
1252  // Make a pointer to the new element
1253  StPicoTrackCovMatrix *covMatrix = (StPicoTrackCovMatrix*)mPicoArrays[StPicoArrays::TrackCovMatrix]->At(cov_index);
1254 
1255  if( dcaG ) {
1256  // Retrieve pointers to the covariance matrix values and errors
1257  const Float_t* parDCA = dcaG->params();
1258  const Float_t* errorMatrix = dcaG->errMatrix();
1259 
1260  // Set covariance matrix values
1261  covMatrix->setImp( parDCA[0] );
1262  covMatrix->setZ( parDCA[1] );
1263  covMatrix->setPsi( parDCA[2] );
1264  covMatrix->setPti( parDCA[3] );
1265  covMatrix->setTan( parDCA[4] );
1266  covMatrix->setCurv( parDCA[5] );
1267 
1268  Float_t SigmaArr[5];
1269  Float_t CorrArr[10];
1270  Int_t ii = 0;
1271  for(Int_t iVal=0; iVal<5; iVal++) {
1272  SigmaArr[iVal] = TMath::Sqrt( errorMatrix[ii] );
1273  for(Int_t j=0; j<iVal; j++) {
1274  Int_t ij = (ii - iVal - 1) + (j + 1);
1275  Int_t ij1 = ij - iVal;
1276  CorrArr[ij1] = errorMatrix[ij] / ( SigmaArr[iVal] * SigmaArr[j] );
1277  }
1278  ii += iVal+2;
1279  } //for(Int_t iVal = 0; iVal < 5; iVal++)
1280 
1281  // Set sigma and correlation arrays
1282  covMatrix->setSigmas( SigmaArr );
1283  covMatrix->setCorrelations( CorrArr );
1284  } //if(dcaG)
1285  } //if( mCovMtxMode == PicoCovMtxMode::Write )
1286 
1287 #if defined (__TFG__VERSION__)
1288  if (_debug) {
1289  std::cout << "StPicoDstMaker::fillTracks: MuTrack "
1290  << Form( "%4i %8.3f %8.3f %8.3f", i, gTrk->p().x(), gTrk->p().y(), gTrk->p().z() )
1291  << Form( "\te/pi/K/p\t%8.3f %8.3f %8.3f %8.3f",
1292  gTrk->nSigmaElectron(),gTrk->nSigmaPion(),
1293  gTrk->nSigmaKaon(),
1294  gTrk->nSigmaProton())
1295  << std::endl
1296  << " PicoTrack "
1297  << Form( "%4i %8.3f %8.3f %8.3f",
1298  i, picoTrk->gMom().x(), picoTrk->gMom().y(), picoTrk->gMom().z() )
1299  << Form( "\te/pi/K/p\t%8.3f %8.3f %8.3f %8.3f",
1300  picoTrk->nSigmaElectron(),
1301  picoTrk->nSigmaPion(),
1302  picoTrk->nSigmaKaon(),
1303  picoTrk->nSigmaProton()) << std::endl;
1304  }
1305 #endif /* __TFG__VERSION__ */
1306 
1307  // Fill pid traits
1308 
1309  // BEMC information
1310  if (mEmcCollection) {
1311 
1312  // Look for the BEMC-matched tower for the track
1313  // If the track is outside of the eta range of the towers, set to -1
1314  // as was done in the previous implementation. However, if the track
1315  // is not matched in phi (track extrapolated to the space between
1316  // modules). In this case, fine the closest tower instead.
1317 
1318  //get inner radius of BEMC
1319  StEmcGeom* mBemcGeom = StEmcGeom::instance("bemc");
1320  Double_t bemc_radius = mBemcGeom->Radius();
1321 
1322  // Magnetic field in Tesla
1323  Double_t mBField_tesla = mBField / 10.0;
1324 
1325  // Needed for projection of the track onto the barrel radius
1326  StThreeVectorD bemc_pos, bemc_mom;
1327 
1328  // BEMC hardware indices
1329  Int_t h_m, h_e, h_s = 0;
1330  // tower index: if no tower can be matched, assign 0
1331  picoTrk->setBEmcMatchedTowerIndex(0);
1332  Int_t tow_id = 0;
1333  Bool_t close_match = false;
1334 
1335  // Check if the track can be projected onto the current radius
1336  // if not, track can't be matched.
1337  // By JetCorr request the global track projection to BEMC is used.
1338  if ( mEmcPosition->projTrack(&bemc_pos, &bemc_mom, gTrk, mBField_tesla, bemc_radius) ) {
1339  // First, examine track eta. If it falls in two regions:
1340  // 0 < |eta| < etaMin()
1341  // etaMax() < |eta| < 1.0
1342  // then shift the eta for the projection slightly into the neighboring tower
1343  if ( fabs(bemc_pos.pseudoRapidity()) < mBemcGeom->EtaMin() ) {
1344  Double_t unsigned_eta = mBemcGeom->EtaMin() + 0.001;
1345  Double_t unsigned_theta = 2.0 * atan(exp(-1.0 * unsigned_eta));
1346  Double_t signed_theta = (bemc_pos.pseudoRapidity() >= 0 ? 1.0 : -1.0) * unsigned_theta;
1347  bemc_pos.setTheta(signed_theta);
1348  close_match = true;
1349  }
1350  else if ( fabs(bemc_pos.pseudoRapidity()) > mBemcGeom->EtaMax() &&
1351  fabs(bemc_pos.pseudoRapidity()) < 1.0 ) {
1352  Double_t unsigned_eta = mBemcGeom->EtaMax() - 0.001;
1353  Double_t unsigned_theta = 2.0 * atan(exp(-1.0 * unsigned_eta));
1354  Double_t signed_theta = (bemc_pos.pseudoRapidity() >= 0 ? 1.0 : -1.0) * unsigned_theta;
1355  bemc_pos.setTheta(signed_theta);
1356  close_match = true;
1357  }
1358  // Get the BEMC hardware location in (m, e, s) and translate to id
1359  // If StEmcGeom::getBin() != 0: track was not matched to a tower.
1360  // Its outside of the BEMC eta range (> 1.0).
1361  if ( mBemcGeom->getBin(bemc_pos.phi(),bemc_pos.pseudoRapidity(),h_m,h_e,h_s) == 0 ) {
1362  // If StEmcGeom::getId() == 0: the track was matched successfully. Otherwise,
1363  // the track was not matched to a tower at this radius, the track was projected
1364  // into the gap between modules in phi.
1365  if ( h_s != -1 ) {
1366  mBemcGeom->getId(h_m,h_e,h_s,tow_id);
1367  if (close_match) {
1368  picoTrk->setBEmcMatchedTowerIndex(-1*tow_id);
1369  }
1370  else {
1371  picoTrk->setBEmcMatchedTowerIndex(tow_id);
1372  }
1373  }
1374  // Track fell in between modules in phi. We will find which module it is closer
1375  // to by shifting phi slightly.
1376  else {
1377  // Value of the "dead space" per module in phi:
1378  // 2*pi/60 (amount of azimuth covered per module)
1379  // 2*0.0495324 (active size of module)
1380  Double_t dphi = (TMath::Pi() / 60.0) - 0.0495324;
1381 
1382  // Shift the projected phi by dphi in positive and negative directions
1383  // if we look for the projection for both of these, only one should give
1384  // a tower id, and the other should still be in the inter-tower space
1385  StThreeVectorD bemc_pos_shift_pos(bemc_pos);
1386  bemc_pos_shift_pos.setPhi(bemc_pos_shift_pos.phi() + dphi);
1387  StThreeVectorD bemc_pos_shift_neg(bemc_pos);
1388  bemc_pos_shift_neg.setPhi(bemc_pos_shift_neg.phi() - dphi);
1389 
1390  if ( mBemcGeom->getBin(bemc_pos_shift_pos.phi(),
1391  bemc_pos_shift_pos.pseudoRapidity(),
1392  h_m,h_e,h_s) == 0 && h_s != -1 ) {
1393  mBemcGeom->getId(h_m,h_e,h_s,tow_id);
1394  picoTrk->setBEmcMatchedTowerIndex(-1*tow_id);
1395  }
1396  else if ( mBemcGeom->getBin(bemc_pos_shift_neg.phi(),
1397  bemc_pos_shift_neg.pseudoRapidity(),
1398  h_m,h_e,h_s) == 0 && h_s != -1 ) {
1399  mBemcGeom->getId(h_m,h_e,h_s,tow_id);
1400  picoTrk->setBEmcMatchedTowerIndex(-1*tow_id);
1401  }
1402  } // else
1403  } // if ( mBemcGeom->getBin(bemc_pos.phi(),bemc_pos.pseudoRapidity(),h_m,h_e,h_s) == 0 )
1404  } // if ( mEmcPosition->projTrack(&bemc_pos,&bemc_mom,pTrk,mBField_tesla,bemc_radius) )
1405 
1406  Int_t id = -1;
1407  Int_t adc0;
1408  Float_t e[5];
1409  Float_t dist[4];
1410  Int_t nhit[2];
1411  Int_t ntow[3];
1412 
1413  getBEMC(gTrk, &id, &adc0, e, dist, nhit, ntow);
1414 
1415  if (id >= 0) {
1416  Int_t bemc_index = mPicoArrays[StPicoArrays::BEmcPidTraits]->GetEntries();
1417  new((*(mPicoArrays[StPicoArrays::BEmcPidTraits]))[bemc_index]) StPicoBEmcPidTraits(counter, id, adc0, e, dist, nhit, ntow);
1418  picoTrk->setBEmcPidTraitsIndex(bemc_index);
1419  }
1420  } //if (mEmcCollection)
1421 
1422  // TOF information
1423  if (gTrk->tofHit()) {
1424 
1425  // Retrieve index in the PicoBTofPidTraits pico array
1426  Int_t btof_index = mPicoArrays[StPicoArrays::BTofPidTraits]->GetEntries();
1427  // Create new empty instance
1428  new((*(mPicoArrays[StPicoArrays::BTofPidTraits]))[btof_index]) StPicoBTofPidTraits();
1429  //new((*(mPicoArrays[StPicoArrays::BTofPidTraits]))[btof_index]) StPicoBTofPidTraits(gTrk, pTrk, counter);
1430 
1431  // Return pointer to the current trait
1432  StPicoBTofPidTraits *btofPidTraits =
1433  (StPicoBTofPidTraits*)mPicoArrays[StPicoArrays::BTofPidTraits]->At(btof_index);
1434 
1435  // Fill traits information
1436 
1437  // Fill index of the corresponding pico track
1438  btofPidTraits->setTrackIndex(counter);
1439 
1440  // Retrive and store btof hit information:
1441  // cellId keeps: (tray-1)*192+(module-1)*6+(cell-1): -1 - no match
1442  StMuBTofHit *btofHit = (StMuBTofHit*)gTrk->tofHit();
1443  Int_t tray = btofHit->tray();
1444  Int_t module = btofHit->module();
1445  Int_t cell = btofHit->cell();
1446  btofPidTraits->setBTofCellId(tray, module, cell);
1447  btofPidTraits->setBTofMatchFlag( (UChar_t)(gTrk->btofPidTraits().matchFlag()) );
1448 
1449  // Time-of-flight and beta
1450  btofPidTraits->setTOF( gTrk->btofPidTraits().timeOfFlight() );
1451  btofPidTraits->setBeta( gTrk->btofPidTraits().beta() );
1452  // This was the original way (commented line below).
1453  // I think it was wrong and changed it to the line above
1454  // btofPidTraits->setBeta( ( (pTrk) ? pTrk->btofPidTraits().beta() : -999. ) );
1455 
1456  // Retrieve and store hit position
1457  StThreeVectorF pos = gTrk->btofPidTraits().position();
1458  btofPidTraits->setHitPositionXYZ( pos.x(), pos.y(), pos.z() );
1459 
1460  // Retrieve and store local Y and Z coordinates
1461  btofPidTraits->setYLocal( gTrk->btofPidTraits().yLocal() );
1462  btofPidTraits->setZLocal( gTrk->btofPidTraits().zLocal() );
1463 
1464  // Retrieve and store nsigma values for particles
1465  btofPidTraits->setNSigmaElectron( gTrk->btofPidTraits().sigmaElectron() );
1466  btofPidTraits->setNSigmaPion( gTrk->btofPidTraits().sigmaPion() );
1467  btofPidTraits->setNSigmaKaon( gTrk->btofPidTraits().sigmaKaon() );
1468  btofPidTraits->setNSigmaProton( gTrk->btofPidTraits().sigmaProton() );
1469 
1470  // Set index of the corresponding btofPidTrait to the pico track
1471  picoTrk->setBTofPidTraitsIndex(btof_index);
1472 
1473 #if defined (__TFG__VERSION__)
1474  const StMuBTofPidTraits &btofPid = gTrk->btofPidTraits();
1475  Float_t beta = (pTrk) && ! TMath::IsNaN(btofPid.beta()) ? btofPid.beta() : -999.;
1476  StThreeVectorF tofPoint = btofPid.position();
1477 
1478  double timeTof = btofPid.timeOfFlight();
1479  double lengthTof = btofPid.pathLength();
1480  if (lengthTof < 0.) {
1481  double dlDCA = 0;
1482  if (StMuDst::instance()->currentVertexIndex() >= 0) {
1483  const StThreeVectorF & dcaPoint = gTrk->dca(StMuDst::instance()->currentVertexIndex());
1484  StPhysicalHelixD innerHelix = gTrk->helix();
1485  dlDCA = fabs( innerHelix.pathLength( StThreeVector<double>(dcaPoint.x(),
1486  dcaPoint.y(), dcaPoint.z()) ) );
1487  }
1488  StPhysicalHelixD outerHelix = gTrk->outerHelix();
1489  double dlTOF = fabs( outerHelix.pathLength( StThreeVector<double>(tofPoint.x(),
1490  tofPoint.y(), еofPoint.z()) ) );
1491 
1492  double l = gTrk->length();
1493  lengthTof = l + dlDCA + dlTOF;
1494  }
1495  if (timeTof > 0. && lengthTof > 0.) {
1496  beta = lengthTof/timeTof/(1e-9*TMath::Ccgs());
1497  }
1498  btofPidTraits->setBeta( beta );
1499 #endif /* __TFG__VERSION__ */
1500  } //if (gTrk->tofHit())
1501 
1502  // ETOF information
1503  if (gTrk->etofHit()) {
1504 
1505  // Retrieve index in the PicoETofPidTraits pico array
1506  Int_t etof_index = mPicoArrays[StPicoArrays::ETofPidTraits]->GetEntries();
1507  // Create new empty instance
1508  new((*(mPicoArrays[StPicoArrays::ETofPidTraits]))[etof_index]) StPicoETofPidTraits();
1509 
1510  // Return pointer to the current trait
1511  StPicoETofPidTraits *etofPidTraits =
1512  (StPicoETofPidTraits*)mPicoArrays[StPicoArrays::ETofPidTraits]->At( etof_index );
1513 
1514  // Fill traits information:
1515 
1516  // Fill index of the corresponding pico track
1517  etofPidTraits->setTrackIndex( counter );
1518 
1519  // Hit index is properly set later in the fillETofHits() function
1520  // --> for now temporarily save the StMuTrack id that will
1521  // be used to map to the index of StPicoETofHits in the StPicoArray --
1522  etofPidTraits->setHitIndex( gTrk->id() );
1523 
1524  /*
1525  StMuETofHit* hit = (StMuETofHit*) gTrk->etofHit();
1526  LOG_INFO << "corresponding muHit: " << hit->sector()
1527  << " " << hit->zPlane() << " " << hit->counter()
1528  << " " << hit->localX() << " " << hit->localY()
1529  << " " << hit->time() << " " << hit->totalTot()
1530  << endm;
1531  */
1532 
1533  // Retrive and store etof pid traits information:
1534  // Matching information
1535  etofPidTraits->setMatchFlag( (UChar_t)(gTrk->etofPidTraits().matchFlag()) );
1536 
1537  // Time-of-flight and beta
1538  etofPidTraits->setTof( gTrk->etofPidTraits().timeOfFlight() );
1539  etofPidTraits->setBeta( gTrk->etofPidTraits().beta() );
1540 
1541  // Retrieve and store position of track crossing with etof volume
1542  StThreeVectorF pos = gTrk->etofPidTraits().position();
1543  etofPidTraits->setCrossingPos( pos.x(), pos.y(), pos.z() );
1544 
1545  // Retrieve and store local Y and Z coordinates
1546  etofPidTraits->setDeltaX( gTrk->etofPidTraits().deltaX() );
1547  etofPidTraits->setDeltaY( gTrk->etofPidTraits().deltaY() );
1548 
1549  // Set index of the corresponding etofPidTrait to the pico track
1550  picoTrk->setETofPidTraitsIndex( etof_index );
1551  } //if (gTrk->etofHit())
1552 
1553  // MTD information
1554  if (gTrk->mtdHit()) {
1555 
1556  // Retrieve the index in the MtdPidTraits array
1557  Int_t mtd_index = mPicoArrays[StPicoArrays::MtdPidTraits]->GetEntries();
1558  new((*(mPicoArrays[StPicoArrays::MtdPidTraits]))[mtd_index]) StPicoMtdPidTraits();
1559  //new((*(mPicoArrays[StPicoArrays::MtdPidTraits]))[mtd_index]) StPicoMtdPidTraits(gTrk->mtdHit(), &(gTrk->mtdPidTraits()), counter);
1560 
1561  StPicoMtdPidTraits *mtdPidTraits =
1562  (StPicoMtdPidTraits*)mPicoArrays[StPicoArrays::MtdPidTraits]->At(mtd_index);
1563 
1564  // Store index of the corresponding pico track
1565  mtdPidTraits->setTrackIndex(counter);
1566  // Store mtdPidTraits related information
1567  mtdPidTraits->setMatchFlag( (Char_t)gTrk->mtdPidTraits().matchFlag() );
1568  mtdPidTraits->setDeltaY( gTrk->mtdPidTraits().deltaY() );
1569  mtdPidTraits->setDeltaZ( gTrk->mtdPidTraits().deltaZ() );
1570  mtdPidTraits->setDeltaTimeOfFlight( gTrk->mtdPidTraits().timeOfFlight() -
1571  gTrk->mtdPidTraits().expTimeOfFlight() );
1572  mtdPidTraits->setBeta( gTrk->mtdPidTraits().pathLength() /
1573  gTrk->mtdPidTraits().expTimeOfFlight() * 1e9 / c_light );
1574  // Store mtdPidTraits hit related information as:
1575  // (backleg-1) * 60 + (module-1) * 12 + cell
1576  mtdPidTraits->setHitChannel( gTrk->mtdHit()->backleg(),
1577  gTrk->mtdHit()->module(),
1578  gTrk->mtdHit()->cell() );
1579 
1580  // Set index of the mtdPidTrait to the pico track
1581  picoTrk->setMtdPidTraitsIndex(mtd_index);
1582  } //if (gTrk->mtdHit())
1583 
1584  } //for (int i = 0; i < nGlobals; ++i)
1585 }
1586 
1587 //_________________
1588 bool StPicoDstMaker::getBEMC(const StMuTrack* t, int* id, int* adc, float* ene, float* d, int* nep, int* towid) {
1589 
1590  *id = -1;
1591  *adc = 0;
1592 
1593  std::fill(ene, ene+5, 0.);
1594  std::fill(d, d+4, 1.e9);
1595  std::fill(nep, nep+2, 0);
1596  std::fill(towid, towid+3, -1);
1597 
1598  if (!mEmcCollection) {
1599  LOG_WARN << " No Emc Collection for this event " << endm;
1600  return kFALSE;
1601  }
1602 
1603  StThreeVectorD position, momentum;
1604  StThreeVectorD positionBSMDE, momentumBSMDE;
1605  StThreeVectorD positionBSMDP, momentumBSMDP;
1606 
1607  double magneticField = mBField * kilogauss / tesla; // in Tesla
1608 
1609  bool ok = false;
1610  bool okBSMDE = false;
1611  bool okBSMDP = false;
1612 
1613  if (mEmcPosition) {
1614  ok = mEmcPosition->projTrack(&position, &momentum, t, magneticField, mEmcGeom[0]->Radius());
1615  okBSMDE = mEmcPosition->projTrack(&positionBSMDE, &momentumBSMDE, t, magneticField, mEmcGeom[2]->Radius());
1616  okBSMDP = mEmcPosition->projTrack(&positionBSMDP, &momentumBSMDP, t, magneticField, mEmcGeom[3]->Radius());
1617  }
1618 
1619  if (!ok) {
1620  LOG_WARN << " Projection failed for this track ... " << endm;
1621  return kFALSE;
1622  }
1623 
1624  if (ok && okBSMDE && okBSMDP) {
1625 
1626  Int_t mod = 0, eta = 0, sub = 0;
1627  StSPtrVecEmcPoint& bEmcPoints = mEmcCollection->barrelPoints();
1628  int index = 0;
1629  float mindist = 1.e9;
1630  mEmcGeom[0]->getBin(positionBSMDP.phi(), positionBSMDE.pseudoRapidity(), mod, eta, sub); //project on SMD plan
1631 
1632  // Loop over all BEMC measurements, aka "points"
1633  for (StSPtrVecEmcPointIterator it = bEmcPoints.begin(); it != bEmcPoints.end(); ++it, ++index) {
1634 
1635  bool associated = false;
1636  // Consider only BEMC clusters
1637  StPtrVecEmcCluster& bEmcClusters = (*it)->cluster(kBarrelEmcTowerId);
1638  if (bEmcClusters.size() == 0) continue;
1639  if (bEmcClusters[0] == NULL) continue;
1640 
1641  // Loop over all BEMC clusters
1642  for (StPtrVecEmcClusterIterator cIter = bEmcClusters.begin(); cIter != bEmcClusters.end(); ++cIter) {
1643 
1644  StPtrVecEmcRawHit& bEmcHits = (*cIter)->hit();
1645 
1646  // Loop over all hits/towers in the BEMC cluster
1647  for (StPtrVecEmcRawHitIterator hIter = bEmcHits.begin(); hIter != bEmcHits.end(); ++hIter) {
1648 
1649  // Find BEMC hit matching the track projection to BEMC
1650  if (mod == (Int_t)(*hIter)->module() && eta == (Int_t)(*hIter)->eta() && sub == (Int_t)(*hIter)->sub()) {
1651  associated = true;
1652  break;
1653  }
1654  }
1655 
1656  if (associated) {
1657 
1658  // Loop over all hits/towers in the BEMC cluster again
1659  for (StPtrVecEmcRawHitIterator hitit = bEmcHits.begin(); hitit != bEmcHits.end(); ++hitit) {
1660  // Save the highest energy among the towers in the BEMC cluster to ene[0]
1661  if ((*hitit)->energy() > ene[0]) ene[0] = (*hitit)->energy();
1662  // Save the highest ADC among the towers in the BEMC cluster to adc
1663  if ((int)(*hitit)->adc() > (*adc)) *adc = (*hitit)->adc();
1664  }
1665  } //if (associated)
1666  } //for (StPtrVecEmcClusterIterator cIter = bEmcClusters.begin(); cIter != bEmcClusters.end(); ++cIter)
1667 
1668  StPtrVecEmcCluster& smdeClusters = (*it)->cluster(kBarrelSmdEtaStripId);
1669  StPtrVecEmcCluster& smdpClusters = (*it)->cluster(kBarrelSmdPhiStripId);
1670 
1671  if (associated) {
1672  *id = index;
1673  ene[1] = ene[1] + (*it)->energy(); //use point's energy, not tower cluster's energy
1674 
1675  float deltaphi = (*it)->position().phi() - positionBSMDP.phi();
1676  if (deltaphi >= TMath::Pi()) deltaphi = deltaphi - TMath::TwoPi();
1677  if (deltaphi < -TMath::Pi()) deltaphi = deltaphi + TMath::TwoPi();
1678 
1679  float rsmdp = mEmcGeom[3]->Radius();
1680  float pointz = (*it)->position().z();
1681  float deltaz = pointz - positionBSMDE.z();
1682  if (sqrt(deltaphi * deltaphi * rsmdp * rsmdp + deltaz * deltaz) < mindist) {
1683  d[1] = deltaphi;
1684  d[0] = deltaz;
1685  if (smdeClusters.size() >= 1) nep[0] = smdeClusters[0]->nHits();
1686  if (smdpClusters.size() >= 1) nep[1] = smdpClusters[0]->nHits();
1687  mindist = sqrt(deltaphi * deltaphi * rsmdp * rsmdp + deltaz * deltaz);
1688  }
1689  }//associated
1690  } //for (StSPtrVecEmcPointIterator it = bEmcPoints.begin(); it != bEmcPoints.end(); ++it, ++index)
1691 
1692  } // end if (ok && okBSMDE && okBSMDP)
1693 
1694  // Get BEMC tower energy from matched tower + 2 nearest towers
1695  int towerId = 0;
1696  int localTowerId = -1;
1697  int localId1 = -1;
1698  int localId2 = -1;
1699  double energy1 = 0, energy2 = 0;
1700  double energyTemp = 0;
1701  double dist1 = 1000, dist2 = 1000;
1702  double distTemp = 0;
1703  Float_t etaTemp = 0, phiTemp = 0;
1704 
1705  if (mEmcGeom[0]->getId(position.phi(), position.pseudoRapidity(), towerId) == 1) return kTRUE;
1706 
1707  for (int ieta = -1; ieta < 2; ++ieta) {
1708  for (int iphi = -1; iphi < 2; ++iphi) {
1709  localTowerId++;//loops from 0 to 8
1710  int nextTowerId = mEmcPosition->getNextTowerId(towerId, ieta, iphi);
1711  if (nextTowerId < 1 || nextTowerId > 4800) continue;
1712  StEmcRawHit* emcHit = mEmcIndex[nextTowerId - 1];
1713  if (emcHit == 0) continue;
1714  if (emcHit->energy() < 0.2) continue; // don't include any noise tower
1715 
1716  if (ieta == 0 && iphi == 0) {
1717  mEmcGeom[0]->getEta(nextTowerId, etaTemp);
1718  mEmcGeom[0]->getPhi(nextTowerId, phiTemp);
1719  ene[2] = emcHit->energy();
1720  d[2] = position.pseudoRapidity() - etaTemp;
1721  d[3] = position.phi() - phiTemp;
1722  }
1723  else {
1724  energyTemp = emcHit->energy();
1725  mEmcGeom[0]->getEta(nextTowerId, etaTemp);
1726  mEmcGeom[0]->getPhi(nextTowerId, phiTemp);
1727  distTemp = sqrt((etaTemp - position.pseudoRapidity()) * (etaTemp - position.pseudoRapidity()) +
1728  (phiTemp - position.phi()) * (phiTemp - position.phi()));
1729 
1730  // In case the new tower is closer to the matched tower
1731  // than the other closest one we swap them.
1732  // i.e. previously closest tower will become the second
1733  // closest tower
1734  if (distTemp < dist1) {
1735  dist2 = dist1;
1736  dist1 = distTemp;
1737  energy2 = energy1;
1738  energy1 = energyTemp;
1739  localId2 = localId1;
1740  localId1 = localTowerId;
1741  }
1742  else if (distTemp < dist2) {
1743  dist2 = distTemp;
1744  energy2 = energyTemp;
1745  localId2 = localTowerId;
1746  }
1747  } //else
1748  } //for (int iphi = -1; iphi < 2; ++iphi)
1749  } //for (int ieta = -1; ieta < 2; ++ieta)
1750  towid[0] = towerId;
1751  ene[3] = energy1; //closest tower
1752  towid[1] = localId1;
1753  ene[4] = energy2; //2nd closest tower
1754  towid[2] = localId2;
1755 
1756  LOG_DEBUG << " ====== BEMC results ====== " << "\n"
1757  << " Energy = " << ene[0] << " " << ene[1] << " " << ene[2] << " " << ene[3] << " " << ene[4] << "\n"
1758  << " BSMD = " << nep[0] << " " << nep[1] << "\n"
1759  << " TowerId = " << towid[0] << " " << towid[1] << " " << towid[2] << endm;
1760 
1761  return kTRUE;
1762 }
1763 
1764 //_________________
1765 void StPicoDstMaker::fillEvent() {
1766 
1767  // Obtain event iterator
1768  int counter = mPicoArrays[StPicoArrays::Event]->GetEntries();
1769  // Create empty pico event
1770  new((*(mPicoArrays[StPicoArrays::Event]))[counter]) StPicoEvent();
1771 
1772  // Return pointer to the latest (just created) pico event
1773  StPicoEvent *picoEvent = (StPicoEvent*)mPicoArrays[StPicoArrays::Event]->At(counter);
1774 
1775  // Retrieve muEvent
1776  StMuEvent* ev = mMuDst->event();
1777 
1778  // Set event parameters
1779  picoEvent->setRunId( ev->runNumber() );
1780  picoEvent->setEventId( ev->eventNumber() );
1781  picoEvent->setFillId( ev->runInfo().beamFillNumber( blue ) );
1782  picoEvent->setBField( ev->magneticField() );
1783  picoEvent->setTime( ev->eventInfo().time() );
1784 
1785  // Set primary vertex information
1786  picoEvent->setPrimaryVertexPosition( ev->primaryVertexPosition().x(),
1787  ev->primaryVertexPosition().y(),
1788  ev->primaryVertexPosition().z() );
1789  picoEvent->setPrimaryVertexPositionError( ev->primaryVertexErrors().x(),
1790  ev->primaryVertexErrors().y(),
1791  ev->primaryVertexErrors().z() );
1792 
1793  if( StMuPrimaryVertex *pv = mMuDst->primaryVertex() ) {
1794  picoEvent->setPrimaryVertexRanking( pv->ranking() );
1795  picoEvent->setNumberOfBEMCMatch( pv->nBEMCMatch() );
1796  picoEvent->setNumberOfBTOFMatch( pv->nBTOFMatch() );
1797  }
1798 
1799  // Copy trigger IDs of the current event
1800  picoEvent->setTriggerIds( ev->triggerIdCollection().nominal().triggerIds() );
1801 
1802  // Save various multiplicities
1803  picoEvent->setRefMultFtpcEast( ev->refMultFtpcEast() );
1804  picoEvent->setRefMultFtpcWest( ev->refMultFtpcWest() );
1805  picoEvent->setRefMultPos( ev->refMultPos() );
1806  picoEvent->setRefMultNeg( ev->refMultNeg() );
1807 
1808  {
1809  using namespace StPicoUtilities;
1810  auto custom_refMult = StPicoUtilities::calculateRefMult(*mMuDst);
1811  picoEvent->setRefMult2NegEast( custom_refMult[RefMult2NegEast] );
1812  picoEvent->setRefMult2PosEast( custom_refMult[RefMult2PosEast] );
1813  picoEvent->setRefMult2NegWest( custom_refMult[RefMult2NegWest] );
1814  picoEvent->setRefMult2PosWest( custom_refMult[RefMult2PosWest] );
1815  picoEvent->setRefMult3NegEast( custom_refMult[RefMult3NegEast] );
1816  picoEvent->setRefMult3PosEast( custom_refMult[RefMult3PosEast] );
1817  picoEvent->setRefMult3NegWest( custom_refMult[RefMult3NegWest] );;
1818  picoEvent->setRefMult3PosWest( custom_refMult[RefMult3PosWest] );
1819  picoEvent->setRefMult4NegEast( custom_refMult[RefMult4NegEast] );
1820  picoEvent->setRefMult4PosEast( custom_refMult[RefMult4PosEast] );
1821  picoEvent->setRefMult4NegWest( custom_refMult[RefMult4NegWest] );
1822  picoEvent->setRefMult4PosWest( custom_refMult[RefMult4PosWest] );
1823  picoEvent->setRefMultHalfNegEast( custom_refMult[RefMultHalfNegEast] );
1824  picoEvent->setRefMultHalfPosEast( custom_refMult[RefMultHalfPosEast] );
1825  picoEvent->setRefMultHalfNegWest( custom_refMult[RefMultHalfNegWest] );
1826  picoEvent->setRefMultHalfPosWest( custom_refMult[RefMultHalfPosWest] );
1827  }
1828 
1829  picoEvent->setGRefMult( ev->grefmult() );
1830  picoEvent->setNumberOfGlobalTracks( mMuDst->numberOfGlobalTracks() );
1831  picoEvent->setNumberOfPrimaryTracks( mMuDst->numberOfPrimaryTracks() );
1832  picoEvent->setbTofTrayMultiplicity( ev->btofTrayMultiplicity() );
1833  picoEvent->setETofHitMultiplicity( ev->etofHitMultiplicity() );
1834  StMuETofHeader *header = mMuDst->etofHeader();
1835  if( header ) {
1836  picoEvent->setETofGoodEventFlag( header->goodEventFlagVec() );
1837  }
1838 
1839  // Save the number of etof digis that were useable in the hit building process
1840  unsigned short nUseableETofDigis = 0;
1841  for( int i=0; i<ev->etofDigiMultiplicity(); i++ ) {
1842  StMuETofDigi* digi = mMuDst->etofDigi( i );
1843  if( !digi ) continue;
1844  if( fabs( digi->calibTime() ) < 1.e-5 && digi->calibTot() < 0 ) continue;
1845  if( digi->sector() == 0 || digi->zPlane() == 0 || digi->counter() == 0 || digi->strip() == 0 ) continue;
1846  nUseableETofDigis++;
1847  }
1848  picoEvent->setETofDigiMultiplicity( nUseableETofDigis );
1849 
1850  // Store number of hits in HFT
1851  picoEvent->setNHitsHFT( 0, ev->numberOfPxlInnerHits() );
1852  picoEvent->setNHitsHFT( 1, ev->numberOfPxlOuterHits() );
1853  picoEvent->setNHitsHFT( 2, ev->numberOfIstHits() );
1854  picoEvent->setNHitsHFT( 3, ev->numberOfSsdHits() );
1855 
1856  // If TOF information is available
1857  if( StBTofHeader *header = mMuDst->btofHeader() ) {
1858  picoEvent->setNVpdHitsEast( header->numberOfVpdHits(east) );
1859  picoEvent->setNVpdHitsWest( header->numberOfVpdHits(west) );
1860  picoEvent->setNTofT0( header->nTzero() );
1861  picoEvent->setVzVpd( header->vpdVz() );
1862  picoEvent->setNTofT0Can( header->nTzeroCan() );
1863  picoEvent->setTStart( header->tStart() );
1864  picoEvent->setTCanFirst( header->tCanFirst() );
1865  picoEvent->setTCanLast( header->tCanLast() );
1866  picoEvent->setNVpdEGoodHits( header->vpdEGoodHits() );
1867  picoEvent->setNVpdWGoodHits( header->vpdWGoodHits() );
1868  picoEvent->setEarliestVpdEHit( header->earliestVpdEHit() );
1869  picoEvent->setEarliestVpdWHit( header->earliestVpdWHit() );
1870  picoEvent->setClosestVpdEHit( header->closestVpdEHit() );
1871  picoEvent->setClosestVpdWHit( header->closestVpdWHit() );
1872  picoEvent->setLatestVpdEHit( header->latestVpdEHit() );
1873  picoEvent->setLatestVpdWHit( header->latestVpdWHit() );
1874  }
1875 
1876  // ZDC and BBC background rates
1877  picoEvent->setZDCx( ev->runInfo().zdcCoincidenceRate() );
1878  picoEvent->setBBCx( ev->runInfo().bbcCoincidenceRate() );
1879  picoEvent->setBackgroundRate( ev->runInfo().backgroundRate() );
1880  picoEvent->setBbcBlueBackgroundRate( ev->runInfo().bbcBlueBackgroundRate() );
1881  picoEvent->setBbcYellowBackgroundRate( ev->runInfo().bbcYellowBackgroundRate() );
1882  picoEvent->setBbcEastRate( ev->runInfo().bbcEastRate() );
1883  picoEvent->setBbcWestRate( ev->runInfo().bbcWestRate() );
1884  picoEvent->setZdcEastRate( ev->runInfo().zdcEastRate() );
1885  picoEvent->setZdcWestRate( ev->runInfo().zdcWestRate() );
1886 
1887  // ZDC detailed information
1888  StZdcTriggerDetector &ZDC = ev->zdcTriggerDetector();
1889  picoEvent->setZdcSumAdcEast( ZDC.adcSum(east) );
1890  picoEvent->setZdcSumAdcWest( ZDC.adcSum(west) );
1891  if ( ev->triggerData() ) {
1892  picoEvent->setZdcUnAttenuatedEast( ev->triggerData()->zdcUnAttenuated(east) );
1893  picoEvent->setZdcUnAttenuatedWest( ev->triggerData()->zdcUnAttenuated(west) );
1894  }
1895 
1896  // Loop over all ZDC strips
1897  for(int iStrip=1; iStrip<9; ++iStrip) {
1898  if( ZDC.zdcSmd(east, 1, iStrip) ) {
1899  picoEvent->setZdcSmdEastHorizontal( (iStrip-1), ZDC.zdcSmd(east, 1, iStrip) );
1900  }
1901  if( ZDC.zdcSmd(east, 0, iStrip) ) {
1902  picoEvent->setZdcSmdEastVertical( (iStrip-1), ZDC.zdcSmd(east, 0, iStrip) );
1903  }
1904  if( ZDC.zdcSmd(west, 1, iStrip) ) {
1905  picoEvent->setZdcSmdWestHorizontal( (iStrip-1), ZDC.zdcSmd(west, 1, iStrip) );
1906  }
1907  if( ZDC.zdcSmd(west, 0, iStrip) ) {
1908  picoEvent->setZdcSmdWestVertical( (iStrip-1), ZDC.zdcSmd(west, 0, iStrip) );
1909  }
1910  } //for(int iStrip=1; iStrip<9; ++iStrip)
1911 
1912  // BBC detailed information
1913  StBbcTriggerDetector bbc = ev->bbcTriggerDetector();
1914 
1915  // Loop over all PMTs
1916  for(UInt_t iPMT=0; iPMT<bbc.numberOfPMTs(); ++iPMT) {
1917 
1918  UInt_t const eastWest = (iPMT<24) ? 0 : 1; // East: 0-23, West: 24-47
1919  UInt_t const pmtId = iPMT % 24; // pmtId: 0-23
1920 
1921  if( eastWest==0 ) { //East
1922  picoEvent->setBbcAdcEast( pmtId, bbc.adc(iPMT) );
1923  }
1924  else { //West
1925  picoEvent->setBbcAdcWest( pmtId, bbc.adc(iPMT) );
1926  }
1927  } //for(UInt_t iPMT=0; iPMT<bbc.numberOfPMTs(); ++iPMT)
1928 
1929  // Set bunch crossing ID
1930  picoEvent->setBunchId( ev->l0Trigger().bunchCrossingId() );
1931 }
1932 
1933 //_________________
1934 void StPicoDstMaker::fillEmcTrigger() {
1935 
1936  // Test for EMC trigger
1937  StTriggerSimuMaker* trigSimu = (StTriggerSimuMaker*)GetMaker("StarTrigSimu");
1938  if (!trigSimu) return;
1939  if (!trigSimu->bemc) return;
1940 
1941  // BEMC High Tower trigger
1942  int bht0 = trigSimu->bemc->barrelHighTowerTh(0);
1943  int bht1 = trigSimu->bemc->barrelHighTowerTh(1);
1944  int bht2 = trigSimu->bemc->barrelHighTowerTh(2);
1945  int bht3 = trigSimu->bemc->barrelHighTowerTh(3);
1946  LOG_INFO << " bht thresholds " << bht0 << " " << bht1 << " " << bht2 << " " << bht3 << endm;
1947  for (int i = 0; i < 4; ++i) {
1948  mPicoDst->event()->setHighTowerThreshold(i, trigSimu->bemc->barrelHighTowerTh(i));
1949  }
1950 
1951  if( bht0>0 || bht1>0 || bht2>0 || bht3>0 ) { // avoid saving unuseful data in case all threshold values are zeros
1952 
1953  // Loop over all towers
1954  for(Int_t towerId=1; towerId<=4800; towerId++) {
1955  Int_t status;
1956  trigSimu->bemc->getTables()->getStatus(BTOW, towerId, status);
1957  Int_t adc = trigSimu->bemc->barrelHighTowerAdc(towerId);
1958  UChar_t flag = 0;
1959  vector<unsigned short> smdEHits;
1960  vector<unsigned short> smdPHits;
1961 
1962  if (adc > bht1) {
1963  LOG_DEBUG << " id = " << towerId << " adc = " << adc << endm;
1964  flag |= 1 << 1;
1965  }
1966 
1967  if (adc > bht2) {
1968  LOG_DEBUG << " id = " << towerId << " adc = " << adc << endm;
1969  flag |= 1 << 2;
1970 
1971  // Fill BEmc Smd hits. Fill only if the flag was set up
1972  if( mBEmcSmdMode == PicoBEmcSmdMode::SmdWrite ) {
1973  StEmcDetector* smde = mEmcCollection->detector(kBarrelSmdEtaStripId);
1974  StEmcDetector* smdp = mEmcCollection->detector(kBarrelSmdPhiStripId);
1975 
1976  if (smde && smdp) {
1977  Float_t trigEta, trigPhi;
1978  mEmcGeom[0]->getEtaPhi(towerId, trigEta, trigPhi);
1979 
1980  // Length of tower side in eta/phi space
1981  float towerSideLength = 0.05;
1982  // Length of tower diagonal in eta/phi space
1983  float towerDiagonal = towerSideLength*TMath::Sqrt(2);
1984  // Maximum distance from trigger tower to include SMD hits
1985  float radius = 1.5 * towerDiagonal;
1986 
1987  // Loop over all SMD hits, but only save ones that are within some radius
1988  // of the trigger tower
1989 
1990  // Loop over eta strips
1991  for (unsigned int i=1; i<=smde->numberOfModules(); i++) {
1992 
1993  StEmcModule* module = smde->module(i);
1994  StSPtrVecEmcRawHit& aHit = module->hits();
1995 
1996  if (aHit.size() < 1) continue;
1997 
1998  for (unsigned int j=0; j<aHit.size(); j++) {
1999  Int_t id = -1;
2000  Float_t smdPhi = 0.;
2001  Float_t smdEta = 0.;
2002  mEmcGeom[2]->getId(i, aHit[j]->eta(), aHit[j]->sub(), id);
2003  mEmcGeom[2]->getEtaPhi(id, smdEta, smdPhi);
2004  // Distance from trig in eta/phi space
2005  float deltaphi = (smdPhi - trigPhi);
2006  if (deltaphi >= TMath::Pi()) {
2007  deltaphi = deltaphi - TMath::TwoPi();
2008  }
2009  if (deltaphi < -TMath::Pi()) {
2010  deltaphi = deltaphi + TMath::TwoPi();
2011  }
2012  float dr = TMath::Sqrt( (smdEta - trigEta)*(smdEta - trigEta) +
2013  deltaphi * deltaphi );
2014 
2015  if (radius >= dr) {
2016  Int_t adc = aHit[j]->adc();
2017  Int_t counterSmde = mPicoArrays[StPicoArrays::BEmcSmdEHit]->GetEntries();
2018  smdEHits.push_back( (unsigned char)counterSmde );
2019  Float_t smdEnergy = aHit[j]->energy();
2020  new( ( *(mPicoArrays[StPicoArrays::BEmcSmdEHit]) )[counterSmde]) StPicoBEmcSmdEHit(id, adc, smdEnergy);
2021  } //if (radius >= dr)
2022  } //for (int j = 0; j < aHit.size(); j++)
2023  } //for (int i = 1; i <= smde->numberOfModules(); i++)
2024 
2025  // Loop over phi strips
2026  for (unsigned int i=1; i<=smdp->numberOfModules(); i++) {
2027 
2028  StEmcModule* module = smdp->module(i);
2029  StSPtrVecEmcRawHit& aHit = module->hits();
2030 
2031  if (aHit.size() < 1) continue;
2032 
2033  for (unsigned int j=0; j<aHit.size(); j++) {
2034  Int_t id = -1;
2035  Float_t smdPhi = 0.;
2036  Float_t smdEta = 0.;
2037  mEmcGeom[3]->getId(i, aHit[j]->eta(), aHit[j]->sub(), id);
2038  mEmcGeom[3]->getEtaPhi(id, smdEta, smdPhi);
2039  // Distance from trig in eta/phi space
2040  float deltaphi = (smdPhi - trigPhi);
2041  if (deltaphi >= TMath::Pi()) {
2042  deltaphi = deltaphi - TMath::TwoPi();
2043  }
2044  if (deltaphi < -TMath::Pi()) {
2045  deltaphi = deltaphi + TMath::TwoPi();
2046  }
2047  // Distance from trig in eta/phi space
2048  float dr = TMath::Sqrt( (smdEta - trigEta)*(smdEta - trigEta) +
2049  deltaphi * deltaphi );
2050 
2051  if (radius >= dr) {
2052  int adc = aHit[j]->adc();
2053  Int_t counterSmdp = mPicoArrays[StPicoArrays::BEmcSmdPHit]->GetEntries();
2054  smdPHits.push_back( (unsigned char)counterSmdp );
2055  Float_t smdEnergy = aHit[j]->energy();
2056  new( ( *(mPicoArrays[StPicoArrays::BEmcSmdPHit]) ) [counterSmdp]) StPicoBEmcSmdPHit(id, adc, smdEnergy);
2057  }
2058  } //for (int j = 0; j < aHit.size(); j++)
2059  } //for (int i = 1; i <= smdp->numberOfModules(); i++)
2060  } //if (smde && smdp)
2061  } //if( mBEmcSmdHitMode == PicoBEmcSmdHitMode::SmdWrite )
2062 
2063  } //if (adc >bht2)
2064 
2065  if (adc > bht3) {
2066  LOG_DEBUG << " id = " << towerId << " adc = " << adc << endm;
2067  flag |= 1 << 3;
2068  }
2069 
2070  if (flag & 0xf) {
2071  Int_t counter = mPicoArrays[StPicoArrays::EmcTrigger]->GetEntries();
2072  new((*(mPicoArrays[StPicoArrays::EmcTrigger]))[counter]) StPicoEmcTrigger(flag, towerId, adc, smdEHits, smdPHits);
2073  }
2074  } //for(Int_t towerId=1; towerId<=4800; towerId++)
2075 
2076  } // end if (bht threshold check)
2077 
2078  // BEMC Jet Patch trigger threshold
2079  int const bjpth0 = trigSimu->bemc->barrelJetPatchTh(0);
2080  int const bjpth1 = trigSimu->bemc->barrelJetPatchTh(1);
2081  int const bjpth2 = trigSimu->bemc->barrelJetPatchTh(2);
2082 
2083  LOG_INFO << " bjp thresholds " << bjpth0 << " " << bjpth0 << " " << bjpth1 << " " << bjpth2 << endm;
2084 
2085  for (int i = 0; i < 3; ++i) {
2086  mPicoDst->event()->setJetPatchThreshold(i, trigSimu->bemc->barrelJetPatchTh(i));
2087  }
2088 
2089  if ( bjpth0 > 0 || bjpth1 > 0 || bjpth2 > 0 ) {
2090 
2091  // Loop over triggers
2092  for (int jp = 0; jp < 18; ++jp) {
2093  // BEMC: 12 Jet Patch + 6 overlap Jet Patches. As no EEMC information
2094  // is recorded in Pico tree, not EEMC trigger information also.
2095  int const jpAdc = trigSimu->bemc->barrelJetPatchAdc(jp);
2096 
2097  unsigned char flag = 0;
2098  if (jpAdc > bjpth0) {
2099  flag |= 1 << 4;
2100  }
2101 
2102  if (jpAdc > bjpth1) {
2103  flag |= 1 << 5;
2104  }
2105 
2106  if (jpAdc > bjpth2) {
2107  flag |= 1 << 6;
2108  }
2109 
2110  if (flag & 0x70) {
2111  int counter = mPicoArrays[StPicoArrays::EmcTrigger]->GetEntries();
2112  new((*(mPicoArrays[StPicoArrays::EmcTrigger]))[counter]) StPicoEmcTrigger(flag, jp, jpAdc);
2113  }
2114  } //for (int jp = 0; jp < 18; ++jp)
2115 
2116  }
2117 }
2118 
2119 //_________________
2120 void StPicoDstMaker::fillMtdTrigger() {
2121 
2122  // Retrieve index of the last element of the MTD trigger array
2123  int counter = mPicoArrays[StPicoArrays::MtdTrigger]->GetEntries();
2124 
2125  // Create empty MTDTrigger object and add it to pico array
2126  new((*(mPicoArrays[StPicoArrays::MtdTrigger]))[counter]) StPicoMtdTrigger();
2127 
2128  // Retrieve the last (new) MTD trigger object
2129  StPicoMtdTrigger *mtdTrigger = (StPicoMtdTrigger*)mPicoArrays[StPicoArrays::MtdTrigger]->At(counter);
2130 
2131  // Fill MTD trigger information
2132 
2133  StMuMtdHeader *muMtdHeader = mMuDst->mtdHeader();
2134  if(muMtdHeader) {
2135  mtdTrigger->setTHUBtime(0, 25 * ( muMtdHeader->triggerTime(1) & 0xfff ) );
2136  mtdTrigger->setTHUBtime(1, 25 * ( muMtdHeader->triggerTime(2) & 0xfff ) );
2137  mtdTrigger->setShouldHaveRejectEvent( muMtdHeader->shouldHaveRejectEvent() );
2138  }
2139 
2140  StTriggerData* trigger = const_cast<StTriggerData*>(mMuDst->event()->triggerData());
2141  if(!trigger) {
2142  LOG_WARN << "No trigger data bank available!" << endm;
2143  return;
2144  }
2145 
2146  // VPD TacSum
2147  mtdTrigger->setVpdTacSum(trigger->vpdEarliestTDCHighThr(east) + trigger->vpdEarliestTDCHighThr(west) );
2148 
2149  // run year
2150  const int runnumber = mMuDst->event()->runNumber();
2151  int year = runnumber / 1e6 + 1999;
2152  // Oct. 1st (approx. 273rd day) is the start of a new running year
2153  if ((runnumber % 1000000) / 1000 >= 273) year += 1;
2154 
2155  // Get QT information
2156  const int kNQTboard = 8;
2157  UShort_t mtdQTadc[kNQTboard][16], mtdQTtac[kNQTboard][16];
2158  memset(mtdQTadc, 0, sizeof(mtdQTadc));
2159  memset(mtdQTtac, 0, sizeof(mtdQTtac));
2160 
2161  for (Int_t i = 0; i < 32; i++){
2162  Int_t type = (i / 4) % 2;
2163  if(year<=2015){
2164  if (type == 1){
2165  mtdQTtac[0][i - i / 4 * 2 - 2] = trigger->mtdAtAddress(i, 0);
2166  mtdQTtac[1][i - i / 4 * 2 - 2] = trigger->mtdgemAtAddress(i, 0);
2167  mtdQTtac[2][i - i / 4 * 2 - 2] = trigger->mtd3AtAddress(i, 0);
2168  mtdQTtac[3][i - i / 4 * 2 - 2] = trigger->mtd4AtAddress(i, 0);
2169  }
2170  else{
2171  mtdQTadc[0][i - i / 4 * 2] = trigger->mtdAtAddress(i, 0);
2172  mtdQTadc[1][i - i / 4 * 2] = trigger->mtdgemAtAddress(i, 0);
2173  mtdQTadc[2][i - i / 4 * 2] = trigger->mtd3AtAddress(i, 0);
2174  mtdQTadc[3][i - i / 4 * 2] = trigger->mtd4AtAddress(i, 0);
2175  }//else
2176  }//if(year<=2015)
2177  else{
2178  for (int im = 0; im < kNQTboard; im++){
2179  if (year != 2016 && im>=4) continue;
2180  if (type == 0) mtdQTadc[im][i - i / 4 * 2] = trigger->mtdQtAtCh(im + 1, i, 0);
2181  else mtdQTtac[im][i - i / 4 * 2 - 2] = trigger->mtdQtAtCh(im + 1, i, 0);
2182  }//for (int im = 0; im < kNQTboard; im++)
2183  }//else
2184  }//for (Int_t i = 0; i < 32; i++)
2185 
2186  mtdTrigger->setQTtacSum(runnumber, mtdQTadc, mtdQTtac, mQTtoModule,
2187  mQTSlewBinEdge, mQTSlewCorr);
2188 
2189  // MT101 information
2190  UShort_t mt101Tac[kNQTboard][2], mt101Id[kNQTboard][2];
2191  for (Int_t i = 0; i < kNQTboard; i++) {
2192  int idx = 0;
2193  if(year==2016) {
2194  idx = i / 2 * 3 + i % 2 * 16;
2195  }
2196  else {
2197  idx = i * 3;
2198  }
2199  mt101Tac[i][0] = (trigger->mtdDsmAtCh(idx, 0)) + ((trigger->mtdDsmAtCh(idx + 1, 0) & 0x3) << 8);
2200  mt101Id[i][0] = (trigger->mtdDsmAtCh(idx + 1, 0) & 0xc) >> 2;
2201  mt101Tac[i][1] = (trigger->mtdDsmAtCh(idx + 1, 0) >> 4) + ((trigger->mtdDsmAtCh(idx + 2, 0) & 0x3f) << 4);
2202  mt101Id[i][1] = (trigger->mtdDsmAtCh(idx + 2, 0) & 0xc0) >> 6;
2203  } //for (Int_t i = 0; i < kNQTboard; i++)
2204  mtdTrigger->setMT101(mt101Tac, mt101Id);
2205 
2206  // TF201 information
2207  UInt_t dsmBit1 = trigger->dsmTF201Ch(0);
2208  UInt_t dsmBit2 = 0;
2209  if (year == 2016) {
2210  dsmBit2 = trigger->dsmTF201Ch(6);
2211  }
2212  mtdTrigger->setTF201TriggerBit(year, dsmBit1, dsmBit2);
2213 }
2214 
2215 //_________________
2216 void StPicoDstMaker::fillBTowHits() {
2217 
2218  // Protection from empty collection and potential crash
2219  if (!mEmcCollection) return;
2220 
2221  //Loop over 120 modules and each of them consist from 40 towers
2222  for (Int_t iTower = 0; iTower < 4800; iTower++) {
2223 
2224  StEmcRawHit* aHit = mEmcIndex[iTower];
2225 
2226  // Do not skip torwers for which information does not exist.
2227  // Set up default values for all towers and if some do not exist
2228  // then will them with aka default (see StPicoBTowHit::isBad() ) info
2229 
2230  Int_t adc = 0;
2231  Float_t energy = -2.;
2232  if (aHit) {
2233  //int softId = aHit->softId(1);
2234  adc = aHit->adc();
2235  energy = aHit->energy();
2236  }
2237 
2238  Int_t counter = mPicoArrays[StPicoArrays::BTowHit]->GetEntries();
2239  new((*(mPicoArrays[StPicoArrays::BTowHit]))[counter]) StPicoBTowHit(adc, energy);
2240  } //for (int i = 0; i < 4800; ++i)
2241 }
2242 
2243 //_________________
2244 void StPicoDstMaker::fillBTofHits() {
2245 
2246  // Loop over BTOF hits
2247  for (unsigned int i = 0; i < mMuDst->numberOfBTofHit(); ++i) {
2248 
2249  // Retrieve i-th hit
2250  StMuBTofHit* aHit = (StMuBTofHit*)mMuDst->btofHit(i);
2251  if (!aHit) continue;
2252 
2253  if (aHit->tray() > 120) continue;
2254  int cellId = (aHit->tray() - 1) * 192 + (aHit->module() - 1) * 6 + (aHit->cell() - 1);
2255 
2256  int counter = mPicoArrays[StPicoArrays::BTofHit]->GetEntries();
2257  new((*(mPicoArrays[StPicoArrays::BTofHit]))[counter]) StPicoBTofHit(cellId);
2258  }
2259 }
2260 
2261 //_________________
2262 void StPicoDstMaker::fillETofHits() {
2263 
2264  // Retrieve and fill both ETOF hit and pidTraits
2265  std::map< Int_t, Int_t > muTrackId2picoHitIndex;
2266 
2267  // Loop over ETOF hits
2268  for ( size_t i = 0; i < mMuDst->numberOfETofHit(); ++i) {
2269 
2270  // Retrieve i-th hit
2271  StMuETofHit* aHit = (StMuETofHit*)mMuDst->etofHit(i);
2272  if (!aHit) continue;
2273 
2274  unsigned int geomId = (aHit->sector() - 13) * 9 + (aHit->zPlane() - 1) * 3 + aHit->counter();
2275 
2276  // Create an instance of ETOF hit
2277  StPicoETofHit picoHit = StPicoETofHit();
2278  // Fill the current hit information
2279  picoHit.setGeomId(geomId);
2280  picoHit.setLocalX(aHit->localX());
2281  picoHit.setLocalY(aHit->localY());
2282  picoHit.setClusterSize(aHit->clusterSize());
2283  picoHit.setTime(aHit->time());
2284  picoHit.setTot(aHit->totalTot());
2285  /*
2286  LOG_INFO << "muHit sector = " << aHit->sector()
2287  << " zPlane = " << aHit->zPlane()
2288  << " counter = " << aHit->counter()
2289  << " localX = " << aHit->localX()
2290  << " localY = " << aHit->localY()
2291  << " clusterSize = " << aHit->clusterSize()
2292  << " time = " << aHit->time()
2293  << " tot = " << aHit->totalTot()
2294  << endm;
2295  picoHit.Print();
2296  */
2297  int counter = mPicoArrays[StPicoArrays::ETofHit]->GetEntries();
2298  new((*(mPicoArrays[StPicoArrays::ETofHit]))[counter]) StPicoETofHit(picoHit);
2299 
2300  if( aHit->associatedTrackId() > -1 ) muTrackId2picoHitIndex[ aHit->associatedTrackId() ] = counter;
2301  }
2302 
2303  //LOG_INFO << "size of muTrackId2picoHitIndex map: " << muTrackId2picoHitIndex.size() << endm;
2304 
2305  // Set the eTOF hit index of the eTOF PID traits to their proper values
2306  for( size_t i = 0; i < (size_t)mPicoArrays[StPicoArrays::ETofPidTraits]->GetEntriesFast(); ++i ) {
2307  StPicoETofPidTraits* etofPidTraits = (StPicoETofPidTraits*)mPicoArrays[StPicoArrays::ETofPidTraits]->At( i );
2308 
2309  int trackId = etofPidTraits->hitIndex();
2310 
2311  if( muTrackId2picoHitIndex.count( trackId ) ) {
2312  etofPidTraits->setHitIndex( muTrackId2picoHitIndex.at( trackId ) );
2313  }
2314  else {
2315  etofPidTraits->setHitIndex( -1 );
2316  }
2317  /*
2318  LOG_INFO << "muPidTrait (" << i << "): trackId = " << trackId
2319  << " hit index: " << etofPidTraits->hitIndex() << endm;
2320  if(etofPidTraits->hitIndex() > -1 ) {
2321  StPicoETofHit* picoHit = (StPicoETofHit*)mPicoArrays[StPicoArrays::ETofHit]->At( etofPidTraits->hitIndex() );
2322 
2323  if( picoHit ) {
2324  picoHit->Print();
2325  }
2326  }
2327  */
2328  }
2329 }
2330 
2331 //_________________
2332 void StPicoDstMaker::fillBbcHits() {
2333  // Retrieve pointer to StMuEvent
2334  StMuEvent* muEvent = mMuDst->event();
2335  // Retrieve trigger data
2336  const StTriggerData* trg = muEvent->triggerData();
2337  // Trigger data must exist
2338  if( trg ) {
2339  // Loop over two directions (east, west)
2340  for (int ew=-1; ew<2; ew+=2) { // note loop -1,+1
2341  StBeamDirection dir = (ew<0) ? east : west;
2342  // Loop over PMT boxes
2343  for (int pmt=1; pmt<17; pmt++) {
2344  int adc = trg->bbcADC(dir,pmt);
2345  if (adc>0) {
2346  int tdc = trg->bbcTDC5bit(dir,pmt);
2347  int tac = trg->bbcTDC(dir,pmt);
2348  bool trueval = kTRUE;
2349  int counter = mPicoArrays[StPicoArrays::BbcHit]->GetEntries();
2350  new((*(mPicoArrays[StPicoArrays::BbcHit]))[counter]) StPicoBbcHit(pmt,ew,adc,tac,tdc,trueval,trueval);
2351  } //if (adc>0)
2352  } //for (int pmt=1; pmt<17; pmt++)
2353  } //for (int ew=-1; ew<2; ew+=2)
2354  }
2355 }
2356 
2357 //_________________
2358 void StPicoDstMaker::fillEpdHits() {
2359  // Loop over EPD hits
2360  for (unsigned int i=0; i < mMuDst->numberOfEpdHit(); i++) {
2361  StMuEpdHit* aHit = mMuDst->epdHit(i);
2362  if (!aHit) continue;
2363  int counter = mPicoArrays[StPicoArrays::EpdHit]->GetEntries();
2364  new((*(mPicoArrays[StPicoArrays::EpdHit]))[counter]) StPicoEpdHit(aHit->id(), aHit->qtData(), aHit->nMIP());
2365  } //for (unsigned int i=0; i < mMuDst->numberOfEpdHit(); i++)
2366 }
2367 
2368 //_________________
2369 void StPicoDstMaker::fillMtdHits() {
2370 
2371  // Retrieve number of MTD hits from muDst
2372  Int_t nMtdHits = mMuDst->numberOfMTDHit();
2373 
2374  // Loop over MTD hits
2375  for (Int_t iHit = 0; iHit < nMtdHits; ++iHit) {
2376  // Retrieve i-th hit
2377  StMuMtdHit* hit = (StMuMtdHit*)mMuDst->mtdHit(iHit);
2378  if (!hit) continue;
2379 
2380  // Retrieve the index int the MtdHit pico array
2381  Int_t counter = mPicoArrays[StPicoArrays::MtdHit]->GetEntries();
2382  // Create new MTD hit
2383  new((*(mPicoArrays[StPicoArrays::MtdHit]))[counter]) StPicoMtdHit();
2384 
2385  // Return pointer to a new MTD hit
2386  StPicoMtdHit *mtdHit = (StPicoMtdHit*)mPicoArrays[StPicoArrays::MtdHit]->At(counter);
2387 
2388  // Fill MTD hit as: (backleg-1) * 60 + (module-1) * 12 + cell
2389  mtdHit->setHitChannel( hit->backleg(),
2390  hit->module(),
2391  hit->cell() );
2392 
2393  // Fill leading edge time
2394  mtdHit->setLeadingEdgeTime( hit->leadingEdgeTime() );
2395 
2396  // Fill trailing edge time
2397  mtdHit->setTrailingEdgeTime( hit->trailingEdgeTime() );
2398 
2399  } //for (Int_t iHit = 0; iHit < nMtdHits; ++iHit)
2400 
2401  // Retrieve number of MTD hits from picoDst
2402  unsigned int nHits = mPicoDst->numberOfMtdHits();
2403  // Retrieve number of MTD hits from picoDst associated with PidTraits
2404  unsigned int nMtdPidTraits = mPicoDst->numberOfMtdPidTraits();
2405 
2406  // Loop over MtdPidTrait and MtdHit picoArrays in order
2407  // to find MtdHit that corresponds to MtdPidTrait
2408  for (unsigned int iPidHit = 0; iPidHit < nMtdPidTraits; ++iPidHit) {
2409 
2410  // Return pointer ot i-th MtdPidTrait
2411  StPicoMtdPidTraits* pidTrait = mPicoDst->mtdPidTraits(iPidHit);
2412 
2413  // Loop over MtdHit
2414  for (unsigned int iHit = 0; iHit < nHits; ++iHit) {
2415 
2416  // Return pointer to i-th MtdHit
2417  StPicoMtdHit* hit = mPicoDst->mtdHit(iHit);
2418 
2419  // Correspondence check
2420  if (pidTrait->gChannel() == hit->gChannel()) {
2421  pidTrait->setMtdHitIndex(iHit);
2422  break;
2423  }
2424  } //for (unsigned int iHit = 0; iHit < nHits; ++iHit)
2425  } //for (unsigned int iPidHit = 0; iPidHit < nMtdPidTraits; ++iPidHit)
2426 
2427  // Check the firing hits
2428  if (mPicoDst->numberOfMtdTriggers() != 1) {
2429 
2430 #if defined (__TFG__VERSION__)
2431  static Int_t count = 0;
2432  count++;
2433  if (count < 13) {
2434  LOG_ERROR << "There are " << mPicoDst->numberOfMtdTriggers() << " MTD trigger. Check it!" << endm;
2435  }
2436 #else /* ! __TFG__VERSION__ */
2437  LOG_ERROR << "There are " << mPicoDst->numberOfMtdTriggers() << " MTD trigger. Check it!" << endm;
2438 #endif /* __TFG__VERSION__ */
2439  return;
2440  }
2441 
2442  // MTD trigger part
2443  StPicoMtdTrigger* trigger = mPicoDst->mtdTrigger(0);
2444  Int_t triggerQT[8][2];
2445  Bool_t triggerBit[8][8];
2446  Int_t pos1 = 0, pos2 = 0;
2447 
2448  for (Int_t i = 0; i < 8; ++i) {
2449  for (Int_t j = 0; j < 2; ++j) {
2450  triggerQT[i][j] = 0;
2451  } //for (Int_t j = 0; j < 2; ++j)
2452  for (Int_t j = 0; j < 8; ++j) {
2453  triggerBit[i][j] = kFALSE;
2454  } //for (Int_t j = 0; j < 8; ++j)
2455 
2456  trigger->getMaximumQTtac(i + 1, pos1, pos2);
2457  triggerQT[i][0] = pos1;
2458  triggerQT[i][1] = pos2;
2459  for (Int_t j = 0; j < 2; ++j) {
2460  if (triggerQT[i][j] > 0 && ((trigger->getTF201TriggerBit() >> (i * 2 + j)) & 0x1)) {
2461  triggerBit[i][triggerQT[i][j] - 1] = kTRUE;
2462  }
2463  } //for (Int_t j = 0; j < 2; ++j)
2464  } //for (Int_t i = 0; i < 8; ++i)
2465 
2466  vector<Int_t> triggerPos;
2467  vector<Int_t> hitIndex;
2468 
2469  // Loop over MTD hits from pico array
2470  for (unsigned int i = 0; i < nHits; ++i) {
2471  StPicoMtdHit* hit = mPicoDst->mtdHit(i);
2472  Int_t backleg = hit->backleg();
2473  Int_t module = hit->module();
2474  Int_t qt = mModuleToQT[backleg - 1][module - 1];
2475  Int_t pos = mModuleToQTPos[backleg - 1][module - 1];
2476  if (qt >= 1 && qt <= 8 && pos > 0 && triggerBit[qt - 1][pos - 1]) {
2477  triggerPos.push_back(qt * 10 + pos);
2478  hitIndex.push_back(i);
2479  }
2480  else {
2481  hit->setTriggerFlag(0);
2482  }
2483  } //for (unsigned int i = 0; i < nHits; ++i)
2484 
2485  vector<Int_t> hits;
2486 
2487  while (triggerPos.size() > 0) {
2488  hits.clear();
2489  hits.push_back(0);
2490  for (Int_t j = 1; j < (Int_t)triggerPos.size(); ++j) {
2491  if (triggerPos[j] == triggerPos[0]) {
2492  hits.push_back(j);
2493  }
2494  } //for (Int_t j = 1; j < (Int_t)triggerPos.size(); ++j)
2495 
2496  for (Int_t k = (Int_t)hits.size() - 1; k > -1; k--) {
2497  StPicoMtdHit* hit = mPicoDst->mtdHit( hitIndex[hits[k]] );
2498  hit->setTriggerFlag( (Int_t)hits.size() );
2499  triggerPos.erase(triggerPos.begin() + hits[k]);
2500  hitIndex.erase(hitIndex.begin() + hits[k]);
2501  } //for (Int_t k = (Int_t)hits.size() - 1; k > -1; k--)
2502  } //while (triggerPos.size() > 0)
2503 }
2504 
2505 #if !defined (__TFG__VERSION__)
2506 
2519 //_________________
2520 bool StPicoDstMaker::selectVertex() {
2521 
2522  // Create a NULL pointer to the MuPrimaryVertex
2523  StMuPrimaryVertex* selectedVertex = nullptr;
2524 
2525  // Switch between modes: Default and Vpd (VpdOrDefault)
2526  // Default takes the first primary vertex, meanwhile
2527  // Vpd
2528  if ( mVtxMode == PicoVtxMode::Default ) {
2529 
2530  // Choose the default vertex, i.e. the first vertex
2531  mMuDst->setVertexIndex(0);
2532  selectedVertex = mMuDst->primaryVertex();
2533  }
2534  else if ( mVtxMode == PicoVtxMode::FXT ) {
2535 
2536  // Loop over primary vertices
2537  for (unsigned int iVtx = 0; iVtx < mMuDst->numberOfPrimaryVertices(); ++iVtx) {
2538 
2539  // Return pointer to i-th primary vertex
2540  StMuPrimaryVertex* vtx = mMuDst->primaryVertex(iVtx);
2541  if (!vtx) continue;
2542 
2543  // Check TpcVz and VpdVz difference
2544  if (vtx->position().z() > 198. && vtx->position().z() < 202.) {
2545  // Reset vertex index
2546  mMuDst->setVertexIndex( iVtx );
2547  // Reset pointer to the primary vertex
2548  selectedVertex = mMuDst->primaryVertex();
2549  // Quit vertex loop
2550  break;
2551  }
2552  }
2553  }
2554  else if ( mVtxMode == PicoVtxMode::Vpd || mVtxMode == PicoVtxMode::VpdOrDefault ) {
2555 
2556  // For VpdOrDefault option one will take the first primary
2557  // vertex if no TOF or VPD information is available
2558  if( mVtxMode == PicoVtxMode::VpdOrDefault ) {
2559  mMuDst->setVertexIndex(0);
2560  selectedVertex = mMuDst->primaryVertex();
2561  }
2562 
2563  // Retrieve pointer to TOF and VPD information
2564  StBTofHeader const* mBTofHeader = mMuDst->btofHeader();
2565 
2566  if ( mBTofHeader && fabs(mBTofHeader->vpdVz()) < 200. ) {
2567 
2568  // Retrieve z-position of pVtx estimated from VPD information
2569  float vzVpd = mBTofHeader->vpdVz();
2570 
2571  // Loop over primary vertices
2572  for (unsigned int iVtx = 0; iVtx < mMuDst->numberOfPrimaryVertices(); ++iVtx) {
2573 
2574  // Return pointer to i-th primary vertex
2575  StMuPrimaryVertex* vtx = mMuDst->primaryVertex(iVtx);
2576  if (!vtx) continue;
2577 
2578  // Check TpcVz and VpdVz difference
2579  if (fabs(vzVpd - vtx->position().z()) <
2580 #if defined(__TFG__VERSION__)
2581  StMuDst::instance()->TpcVpdVzDiffCut()
2582 #else
2583  mTpcVpdVzDiffCut
2584 #endif
2585  ) {
2586  // Reset vertex index
2587  mMuDst->setVertexIndex( iVtx );
2588  // Reset pointer to the primary vertex
2589  selectedVertex = mMuDst->primaryVertex();
2590  // Quit vertex loop
2591  break;
2592  } //if (fabs(vzVpd - vtx->position().z()) < mTpcVpdVzDiffCut)
2593  } //for (unsigned int iVtx = 0; iVtx < mMuDst->numberOfPrimaryVertices(); ++iVtx)
2594  } //if (mBTofHeader && fabs(mBTofHeader->vpdVz()) < 200)
2595  } //else if (mVtxMode == PicoVtxMode::Vpd || mVtxMode == PicoVtxMode::VpdOrDefault)
2596  else if ( mVtxMode == PicoVtxMode::Mtd ) {
2597 
2598  // Set the first primary vertex as a default vertex
2599  int VtxIndex = 0;
2600 
2601  // Loop over primary vertices
2602  for(unsigned int iVtx=0; iVtx<mMuDst->numberOfPrimaryVertices(); iVtx++) {
2603 
2604  // Set pointer to i-th primary vertex
2605  mMuDst->setVertexIndex( iVtx );
2606 
2607  // Counter for primary tracks that matched MTD
2608  int nMtdMatched = 0;
2609 
2610  // Loop over primary tracks
2611  for(unsigned int iTrk=0; iTrk<mMuDst->numberOfPrimaryTracks(); iTrk++) {
2612 
2613  // Retrieve i-th primary track from that belongs
2614  // to the current primary vertex
2615  StMuTrack* pTrack = mMuDst->primaryTracks( iTrk );
2616  // Track must exist
2617  if( !pTrack ) continue;
2618 
2619  // Check if track matches MTD
2620  if( pTrack->index2MtdHit()<0 ) continue;
2621  // Increment number of tracks that matched MTD
2622  nMtdMatched++;
2623 
2624  } // for(unsigned int iTrk=0; iTrk<mMuDst->numberOfPrimaryTracks(); iTrk++)
2625 
2626  // Take the first primary vertex that has at least 2 tracks
2627  // that matched MTD
2628  if( nMtdMatched >= 2 ) {
2629  // Change vertex index
2630  VtxIndex = iVtx;
2631  // Quit vertex loop
2632  break;
2633  } // if( nMtdMatched >= 2 )
2634  } // for(unsigned int iVtx=0; iVtx<mMuDst->numberOfPrimaryVertices(); iVtx++)
2635 
2636  // Set the vertex index
2637  mMuDst->setVertexIndex(VtxIndex);
2638  // Set pointer to the primary vertex
2639  selectedVertex = mMuDst->primaryVertex();
2640  } // else if ( mVtxMode == PicoVtxMode::Mtd )
2641  else { // default case
2642  LOG_ERROR << "Pico Vtx Mode not set!" << endm;
2643  }
2644 
2645  // Retrun false if selected vertex is not valid
2646  return selectedVertex ? true : false;
2647 }
2648 
2649 #endif /* !__TFG__VERSION__ */
void setE(Float_t e)
Set energy.
Int_t m_Mode
counters
Definition: StMaker.h:81
void setEventId(Int_t id)
Set event ID.
Definition: StPicoEvent.h:251
static StMuPrimaryVertex * primaryVertex()
return pointer to current primary vertex
Definition: StMuDst.h:322
void fill(const StMuDst &muDst, const StFmsDbMaker *fmsDbMaker=nullptr)
Fill FMS info.
void setNSigmaKaon(Float_t ns)
Set nSigma(kaon)
short type() const
Returns the track type: 0=global, 1=primary, etc (see StEvent manual for type information) ...
Definition: StMuTrack.h:229
static StPicoMtdHit * mtdHit(Int_t i)
Return pointer to i-th mtd hit.
Definition: StPicoDst.h:75
double localY() const
Y-position.
Definition: StMuETofHit.h:203
void setImp(Float_t imp)
Set impact.
unsigned int zPlane() const
ZPlane.
Definition: StMuETofHit.h:194
void setBBCx(Float_t bbcCoinRate)
Set BBC coincidence rate.
Definition: StPicoEvent.h:378
virtual Int_t Finish()
Standard STAR Finish() function called from StChain.
void setPti(Float_t pti)
Set pti.
static StMuBTofHit * btofHit(int i)
returns pointer to the i-th muBTofHit
Definition: StMuDst.h:419
static TObjArray * globalTracks()
returns pointer to the global tracks list
Definition: StMuDst.h:303
StThreeVectorF primaryVertexPosition(int vtx_id=-1) const
The StMuDst is supposed to be structured in &#39;physical events&#39;. Therefore there is only 1 primary vert...
Definition: StMuEvent.cxx:221
Holds information about MTD-matched track.
unsigned short refMultNeg(int vtx_id=-1)
Reference multiplicity of negative particles as defined in StEventUtilities/StuRefMult.hh for vertex vtx_id (-1 is default index from StMuDst)
Definition: StMuEvent.cxx:184
void setStatus(Char_t k=0)
Set status of the track (0 - not fitted to any vertex, 1 - fitted to a vertex)
Definition: StPicoTrack.h:255
unsigned int sector() const
Sector.
Definition: StMuETofDigi.h:212
void setTrackIndex(const Int_t index2PicoTrack)
Set associated track index.
void setBbcYellowBackgroundRate(Float_t bbcYellowBckgRate)
Set &quot;yellow&quot;-beam background rate.
Definition: StPicoEvent.h:384
Class that converts MuDst into PicoDst.
void setIdVtxStop(Int_t id)
Set stop MC vertex index.
void setZdcSmdEastVertical(Int_t strip, Float_t zdcSmdEastVertical)
Set ZDC for the east vertical ZDC i-th strip.
Float_t nSigmaKaon() const
Return nSigma(kaon)
Definition: StPicoTrack.h:138
void setDeltaX(const Float_t &deltaX)
Set difference between track intersection and eTOF hit in local X coordinate (cm) across strips...
void setClusterSize(Int_t clusterSize)
Set cluster size of eTOF hit.
void setRefMult2NegWest(UShort_t mult)
Set negative RefMult2 west ( 0.5&lt;eta&lt;1 )
Definition: StPicoEvent.h:313
void setNumberOfPrimaryTracks(UShort_t mult)
Set number of primary tracks.
Definition: StPicoEvent.h:292
unsigned int clusterSize() const
Cluster size.
Definition: StMuETofHit.h:200
static UInt_t numberOfMtdHits()
Return number of MTD hits.
Definition: StPicoDst.h:114
void setTriggerIds(std::vector< unsigned int > ids)
Set trigger id (pass STL vector with trigger IDs)
void setRefMultPos(UShort_t mult)
Set RefMult positive (|eta|&lt;0.5)
Definition: StPicoEvent.h:307
Holds information about Monte Carlo vertex.
Float_t nSigmaPion() const
Return nSigma(pion)
Definition: StPicoTrack.h:136
double time() const
Time.
Definition: StMuETofHit.h:197
void setBackgroundRate(Float_t bckgRate)
Set background rate.
Definition: StPicoEvent.h:380
Holds information about BEMC tower.
Definition: StPicoBTowHit.h:19
void setZLocal(Float_t zLocal)
Set zLocal.
void setNSigmaProton(Float_t sigma)
Set nsigma(proton)
void setZdcUnAttenuatedEast(Float_t adc)
Set unattenuated east ZDC signal.
Definition: StPicoEvent.h:412
void setShouldHaveRejectEvent(Int_t val)
Set should have reject event (retrieve from mtdHeader)
void setBField(Double_t bField)
Set magnetic field.
Definition: StPicoEvent.h:257
void setNVpdWGoodHits(Int_t vpdWGoodHits)
Set total number of in-time VPDW hits.
Definition: StPicoEvent.h:362
virtual Int_t Init()
Standard STAR Init() function called from StChain.
void setNumberOfGlobalTracks(UShort_t mult)
Set number of global tracks reconstructed in the event.
Definition: StPicoEvent.h:336
void setBbcWestRate(Float_t bbcWestRate)
Set west BBC rate.
Definition: StPicoEvent.h:389
void setTopologyMap(Int_t id, UInt_t word)
Set topology map (2 words)
short id() const
Returns the track id(or key), is unique for a track node, i.e. global and primary tracks have the sam...
Definition: StMuTrack.h:228
void setHitChannel(Int_t backleg, Int_t module, Int_t cell)
Encode global channel number as: (backleg-1) * 60 + (module-1) * 12 + cell.
void setDedx(Float_t dEdx)
Set dE/dx of the track.
unsigned char matchFlag() const
Matching information.
UShort_t nHitsDedx() const
Return number of hits used for dEdx.
Definition: StMuTrack.h:238
static void recoverMuFmsCollection(StMuDst &muDst, const StFmsDbMaker *=nullptr)
static StMuETofHeader * etofHeader()
returns pointer to the StMuETofHeader
Definition: StMuDst.h:431
Int_t gChannel() const
Return hit channel.
void setNSigmaProton(Float_t ns)
Set nSigma(proton)
Int_t gChannel() const
Definition: StPicoMtdHit.h:37
void setBTofCellId(Int_t tray, Int_t module, Int_t cell)
Set TOF cell ID which encodes tray, module and cell IDs.
virtual Int_t Make()
Standard STAR Make() function called from StChain.
void setClosestVpdEHit(Double_t closestVpdEHit)
Set closest VPDE hit to start time.
Definition: StPicoEvent.h:368
Double_t length() const
Returns length of track (cm) from primary vertex to last measured point.
Definition: StMuTrack.cxx:416
unsigned int counter() const
Counter.
Definition: StMuETofHit.h:195
void setLocalY(Float_t localY)
Set local Y coordinate (cm) along strips w.r.t. center of eTOF counter volume.
void setFillId(Int_t id)
Set fill ID.
Definition: StPicoEvent.h:253
Short_t id() const
Definition: StMuEpdHit.h:127
void setiTpcTopologyMap(ULong64_t map)
Set iTPC topology map.
Definition: StPicoTrack.h:277
void setNumberOfDaughters(Int_t ntrk)
Set number of daughter tracks.
Class storing MTD trigger information including VPD, QT, MT101, TF201.
void setRefMult2PosWest(UShort_t mult)
Set positive RefMult2 west ( 0.5&lt;eta&lt;1 )
Definition: StPicoEvent.h:315
unsigned int sector() const
Sector.
Definition: StMuETofHit.h:193
void setDeltaZ(Float_t dz)
Set delta Z.
Holds BEMC SmdEta hit information.
void setQTtacSum(Int_t runnumber, UShort_t mtdQTadc[8][16], UShort_t mtdQTtac[8][16], const Int_t QTtoModule[8][8], const Int_t QTSlewBinEdge[8][16][8], const Int_t QTSlewCorr[8][16][8])
Set TAC sum (j2+j3) for each position in each QT board.
void setLeadingEdgeTime(std::pair< Float_t, Float_t > leadingEdgeTime)
Set leading edge time.
void setZdcSumAdcEast(Float_t zdcSumAdcEast)
Set sum of east ZDC ADC.
Definition: StPicoEvent.h:396
Double_t chi2() const
Returns chi2 of fit.
Definition: StMuTrack.h:251
static StMuETofHit * etofHit(int i)
returns pointer to the i-th StMuETofHit
Definition: StMuDst.h:429
double dEdxFit() const
returns the fitted dEdx value
void getMaximumQTtac(const Int_t qt, Int_t &pos1, Int_t &pos2)
Holds EMC trigger information.
void setRefMult2NegEast(UShort_t mult)
Set negative RefMult2 east ( -1&lt;eta&lt;-0.5 )
Definition: StPicoEvent.h:309
void setZdcUnAttenuatedWest(Float_t adc)
Set unattenuated west ZDC signal.
Definition: StPicoEvent.h:414
virtual Int_t InitRun(Int_t const runnumber)
Init run.
void setPosition(Float_t x, Float_t y, Float_t z)
Set vertex position.
unsigned int strip() const
Strip.
Definition: StMuETofDigi.h:215
void setETofDigiMultiplicity(UShort_t mult)
Set total number of digis in ETOF modules.
Definition: StPicoEvent.h:284
const StMuETofPidTraits & etofPidTraits() const
dongx
Definition: StMuTrack.h:265
void setTrailingEdgeTime(std::pair< Float_t, Float_t > trailingEdgeTime)
Set trailing edge time.
void setHitIndex(const Int_t index2Hit)
Set index of corrsponding eTOF hit.
Int_t hitIndex() const
Return index of corrsponding eTOF hit.
void setDeltaY(const Float_t &deltaY)
Set difference between track intersection and eTOF hit in local Y coordinate (cm) along strips...
unsigned short refMultFtpcWest(int vtx_id=-1)
Reference multiplicity of particles in the west FTPC as defined in StEventUtilities/StuFtpcRefMult.hh for vertex vtx_id (-1 is default index from StMuDst)
Definition: StMuEvent.cxx:208
void SetStatus(char const *branchNameRegex, int enable)
Enables or disables branches matching a simple regex pattern in reading mode.
Hold information about eTOF-matched tracks.
void setMcTruth(Int_t index, Int_t qa)
Set index of the corresonding MC track.
Definition: StPicoTrack.h:291
void setNSigmaPion(Float_t ns)
Set nSigma(pion)
void setRefMultHalfNegWest(UShort_t mult)
TPC refMultHalf neg (eta&gt;0)
Definition: StPicoEvent.h:329
void setClosestVpdWHit(Double_t closestVpdWHit)
Set closest VPDW hit to start time.
Definition: StPicoEvent.h:370
static TClonesArray * primaryVertices()
returns pointer to the primary vertex list
Definition: StMuDst.h:299
void setMtdPidTraitsIndex(Int_t index)
Set index to MTD PID traits.
Definition: StPicoTrack.h:285
void setTime(Float_t time)
Set GEANT production time (ns)
TVector3 gMom() const
Return momentum (GeV/c) of the global tracks at the point of DCA to the primary vertex.
Definition: StPicoTrack.h:64
static StPicoEvent * event()
Return pointer to current StPicoEvent (class holding the event wise information)
Definition: StPicoDst.h:63
void setRefMultFtpcEast(UShort_t mult)
Set east RefMult (-1&lt;eta&lt;0.5) estimated by FTPC.
Definition: StPicoEvent.h:301
void setBbcAdcWest(Int_t iPMT, Float_t bbcAdcWest)
Set i-th PMT of east BBC.
void setIsFromShower(Bool_t isFrom)
Set flag if track comes from shower.
void setHitPositionXYZ(Float_t x, Float_t y, Float_t z)
Set hit position (x,y,z)
void setOrigin(Double_t x, Double_t y, Double_t z)
Set origin of the track (DCA point to the primary vertex)
Definition: StPicoTrack.h:236
void setChi2(Float_t chi2)
Set chi2 of the track.
void setTime(Float_t time)
Set leading edge time (ns) of eTOF hit.
void setZdcSmdEastHorizontal(Int_t strip, Float_t zdcSmdEastHorizontal)
Set ZDC for the east horizontal ZDC i-th strip.
void setRefMultHalfNegEast(UShort_t mult)
TPC refMultHalf neg (eta&lt;0)
Definition: StPicoEvent.h:325
static const char * picoArrayNames[NAllPicoArrays]
Names of the TBranches in the TTree/File.
Definition: StPicoArrays.h:23
void setSigmas(Float_t sigmas[5])
Set 5 sigma parameters.
void setTStart(Double_t startTime)
Set event start time.
Definition: StPicoEvent.h:354
void setPrimaryVertexRanking(Float_t ranking)
Set primary vertex ranking.
Definition: StPicoEvent.h:276
void setNVpdEGoodHits(Int_t vpdEGoodHits)
Set total number of in-time VPDE hits.
Definition: StPicoEvent.h:360
unsigned char matchFlag() const
Matching information.
void setPrimaryVertexPositionError(Float_t x, Float_t y, Float_t z)
Set primary vertex position error (ex,ey,ez)
Definition: StPicoEvent.h:270
void setRunId(Int_t id)
Set run ID.
Definition: StPicoEvent.h:249
Holds information about track parameters.
Definition: StPicoTrack.h:35
unsigned int zPlane() const
ZPlane.
Definition: StMuETofDigi.h:213
void setTrackIndex(Int_t idx2PicoTrack)
Set assiciated track index.
void setMT101(UShort_t mt101Tac[8][2], UShort_t mt101Id[8][2])
Set two largest TACsum for all QT boards.
void setNTofT0Can(Int_t t0Can)
Set number of particles before T0 outlier rejection.
Definition: StPicoEvent.h:352
Int_t backleg() const
Return backleg number (1-30) of the MTD hit.
Definition: StPicoMtdHit.h:39
void setCorrelations(Float_t corr[10])
Set 10 correlation parameters.
virtual ~StPicoDstMaker()
Destructor.
void setHighTowerThreshold(const Int_t i, const Int_t th)
Set threshold for the high tower.
Definition: StPicoEvent.h:422
UInt_t getTF201TriggerBit() const
void setZdcWestRate(Float_t zdcWestRate)
Set west ZDC rate.
Definition: StPicoEvent.h:393
void setTot(Float_t tot)
Set time over threshold (ns) of eTOF hit.
void setTriggerFlag(Int_t const flag)
Definition: StPicoMtdHit.h:65
static int picoArraySizes[NAllPicoArrays]
Maximum sizes of the TClonesArrays.
Definition: StPicoArrays.h:29
void setNSigmaElectron(Float_t ns)
Set nSigma(electron)
void setCovMtxMode(const PicoCovMtxMode covMtxMode)
Set to write or not to write covariant matrix.
void setBbcAdcEast(Int_t iPMT, Float_t bbcAdcEast)
Set i-th PMT of east BBC.
void setCrossingPos(const Float_t &x, const Float_t &y, const Float_t &z)
Set global position (cm) of the track intersection with an eTOF volume.
pair< double, double > pathLength(double r) const
path length at given r (cylindrical r)
Definition: StHelix.cc:351
void setZdcSmdWestVertical(Int_t strip, Float_t zdcSmdWestVertical)
Set ZDC for the west vertical ZDC i-th strip.
StPhysicalHelixD helix() const
Returns inner helix (first measured point)
Definition: StMuTrack.cxx:407
void setTime(Int_t time)
Set time stamp.
Definition: StPicoEvent.h:261
UShort_t nHitsFit() const
Return total number of hits used in fit.
Definition: StMuTrack.h:239
void setRefMultHalfPosWest(UShort_t mult)
TPC refMultHalf pos (eta&gt;0)
Definition: StPicoEvent.h:331
double calibTime() const
calibrated time
Definition: StMuETofDigi.h:206
static StPicoMtdPidTraits * mtdPidTraits(Int_t i)
Return pointer to i-th mtd pidTraits.
Definition: StPicoDst.h:87
Int_t module() const
Return module number (1-5) of the MTD hit.
Definition: StPicoMtdHit.h:41
void setRefMultNeg(UShort_t mult)
Set RefMult negative (|eta|&lt;0.5)
Definition: StPicoEvent.h:305
static const char * picoArrayTypes[NAllPicoArrays]
Names of the classes, the TClonesArrays are arrays of this type.
Definition: StPicoArrays.h:26
void setDedxError(Float_t dEdxError)
Set dE/dx error of the track.
Definition: StPicoTrack.h:248
Float_t nSigmaElectron() const
Return nSigma(electron)
Definition: StPicoTrack.h:142
void setNHitsFit(Int_t nhits)
Set nHitsFit ( charge * nHitsFit )
Definition: StPicoTrack.h:258
short flag() const
Returns flag, (see StEvent manual for type information)
Definition: StMuTrack.h:230
Short_t charge() const
Returns charge.
Definition: StMuTrack.h:255
void setTCanFirst(Double_t tFirst)
Set time of earliest candidate particle in T0 calculation.
Definition: StPicoEvent.h:356
void setNHitsHFT(Int_t layer, UShort_t word)
Set number of hits in i-th HFT layers (PXL, PXL, IST, SSD)
static void set(TClonesArray **)
Set the pointers to the TClonesArrays.
Definition: StPicoDst.cxx:34
void setNTofT0(Int_t t0)
Set number of T0 particles in BTOF self calibration.
Definition: StPicoEvent.h:347
void setTHUBtime(Int_t thubID, UInt_t word)
Set THUB time.
Definition: Stypes.h:49
void setRefMultHalfPosEast(UShort_t mult)
TPC refMultHalf pos (eta&lt;0)
Definition: StPicoEvent.h:327
void setETofPidTraitsIndex(Int_t index)
Set index to ETOF PID traits.
Definition: StPicoTrack.h:287
void setRefMultFtpcWest(UShort_t mult)
Set west RefMult (-1&lt;eta&lt;0.5) estimated by FTPC.
Definition: StPicoEvent.h:303
void setId(Int_t id)
Set MC track ID (primary key/GEANT track ID)
const StThreeVectorF & p() const
Returns 3-momentum at dca to primary vertex.
Definition: StMuTrack.h:259
void setBunchId(Int_t id)
Set bunch crossing ID.
void setVtxMode(const PicoVtxMode vtxMode)
Set vertex selection mode.
void setNSigmaElectron(Float_t sigma)
Set nsigma(electron)
void setNHitsMax(Int_t nhits)
Set nHitsPoss.
void setVzVpd(Float_t vpdVz)
Set Vz of the primary vertex reconstructed by VPD.
Definition: StPicoEvent.h:349
Double_t nSigmaPion() const
Returns Craig&#39;s distance to the calculated dE/dx band for pions in units of sigma.
Definition: StMuTrack.h:245
double dNdxErrorFit() const
returns the fitted dNdx resolution value
Stores BTOF hit information.
Definition: StPicoBTofHit.h:18
void setBTofPidTraitsIndex(Int_t index)
Set index to BTOF PID traits.
Definition: StPicoTrack.h:283
const StMuProbPidTraits & probPidTraits() const
Returns Yuri Fisyak new pid probabilities.
Definition: StMuTrack.h:263
Main class that keeps TClonesArrays with main classes.
Definition: StPicoDst.h:40
void setRefMult2PosEast(UShort_t mult)
Set positive RefMult2 east ( -1&lt;eta&lt;-0.5 )
Definition: StPicoEvent.h:311
void setHitChannel(Int_t backleg, Int_t module, Int_t cell)
Set hit channel: (backleg-1) * 60 + (module-1) * 12 + cell.
Keep information about Barrel ElectroMagnetic Calorimeter (BEMC) matched tracks.
void setNHits(Int_t k, UChar_t n)
void setTof(const Float_t &tof)
Set time of flight.
int associatedTrackId() const
id to the track which has been matched to this hit
Definition: StMuETofHit.h:205
void setTF201TriggerBit(Int_t year, UInt_t dsmBit1, UInt_t dsmBit2)
Set trigger bit in TCU that used for online trigger.
Int_t getNextTowerId(Float_t eta, Float_t phi, Int_t nTowersdEta, Int_t nTowersdPhi) const
Return neighbor tower id&#39;s.
void setNSigmaKaon(Float_t sigma)
Set nsigma(kaon)
static TObjArray * primaryTracks()
returns pointer to a list of tracks belonging to the selected primary vertex
Definition: StMuDst.h:301
void setZ(Float_t z)
Set z.
void setTOF(Float_t tof)
Set time of flight.
Definition: Stypes.h:43
static StPicoMtdTrigger * mtdTrigger(Int_t i)
Return pointer to i-th MTD trigger data.
Definition: StPicoDst.h:69
void setZdcSmdWestHorizontal(Int_t strip, Float_t zdcSmdWestHorizontal)
Set ZDC for the west horizontal ZDC i-th strip.
void setNHitsDedx(Int_t nhits)
Set nHitsDedx.
void setBEmcPidTraitsIndex(Int_t index)
Set index to BEMC PID traits.
Definition: StPicoTrack.h:281
void setDndx(Float_t dNdx)
Set dN/dx of the track.
Definition: StPicoTrack.h:251
Double_t nSigmaElectron() const
Returns Craig&#39;s distance to the calculated dE/dx band for electrons in units of sigma.
Definition: StMuTrack.h:244
const StThreeVector< double > & origin() const
-sign(q*B);
Definition: StHelix.hh:224
void setDeltaY(Float_t dy)
Set delta Y.
static UInt_t numberOfMtdPidTraits()
Return number of MTD traits.
Definition: StPicoDst.h:126
double localX() const
X-position.
Definition: StMuETofHit.h:202
UShort_t nHitsPoss() const
Return number of possible hits on track.
Definition: StMuTrack.cxx:242
void setBeta(Float_t beta)
Set beta.
void setNSigmaPion(Float_t sigma)
Set nsigma(pion)
void setMatchFlag(Char_t flag)
Set match flag.
void setETofGoodEventFlag(bool flag, UShort_t iSector, UShort_t iModule, UShort_t iCounter, UShort_t iGet4)
Set goodEventFlag for a specific eTOF counter.
Definition: StPicoEvent.h:286
static StMuEvent * event()
returns pointer to current StMuEvent (class holding the event wise information, e.g. event number, run number)
Definition: StMuDst.h:320
float timeOfFlight() const
timing for PID
void setEarliestVpdEHit(Double_t earliestVpdEHit)
Set earliest VPDE hit compared to start time.
Definition: StPicoEvent.h:364
Holds information about Monte Carlo track parameters.
Definition: StPicoMcTrack.h:32
void setBTofMatchFlag(UChar_t flag)
Set TOF-matching flag.
const StThreeVectorF & momentum() const
Returns 3-momentum at dca to primary vertex.
Definition: StMuTrack.h:260
Holds information about the hit from MTD.
Definition: StPicoMtdHit.h:18
static StMuETofDigi * etofDigi(int i)
returns pointer to the i-th StMuEtofDigi
Definition: StMuDst.h:427
void setBbcBlueBackgroundRate(Float_t bbcBlueBckgRate)
Set &quot;blue&quot;-beam background rate.
Definition: StPicoEvent.h:382
Definition: Stypes.h:42
void setIsIntermediate(Int_t interim)
Set flag of the intermediate vertex.
Definition: Stypes.h:40
static void printTracks()
Print track info.
Definition: StPicoDst.cxx:46
float timeOfFlight() const
timing for PID
void setGlobalMomentum(Double_t px, Double_t py, Double_t pz)
Set momentum of the global track.
Definition: StPicoTrack.h:227
void setGRefMult(UShort_t mult)
Set RefMult estimated by global tracks.
Definition: StPicoEvent.h:334
void setIdOfParentTrack(Int_t id)
Set ID of the parent track.
StPicoDstMaker(char const *name="PicoDst")
Constructor.
void setEarliestVpdWHit(Double_t earliestVpdWHit)
Set earliest VPDW hit compared to start time.
Definition: StPicoEvent.h:366
void setbTofTrayMultiplicity(UShort_t mult)
Set total number of hits in TOF trays.
Definition: StPicoEvent.h:338
StThreeVectorF dca(Int_t vtx_id=-1) const
Returns 3D distance of closest approach to primary vertex.
Definition: StMuTrack.cxx:359
Float_t nSigmaProton() const
Return nSigma(proton)
Definition: StPicoTrack.h:140
PicoIoMode
Write/Read mode: 1-write, 2-read.
void setZdcSumAdcWest(Float_t zdcSumAdcWest)
Set sum of west ZDC ADC.
Definition: StPicoEvent.h:398
void setId(Int_t id)
Set track ID.
Definition: StPicoTrack.h:214
void setZDCx(Float_t zdcCoinRate)
Set ZDC coincidence rate.
Definition: StPicoEvent.h:376
void setMtdHitIndex(Int_t index)
Set MTD hit index.
double totalTot() const
Total Tot.
Definition: StMuETofHit.h:198
void setTrackIndex(Int_t index)
Set track index of the associated track.
void setPrimaryMomentum(Double_t px, Double_t py, Double_t pz)
Set momentum of the primary track.
Definition: StPicoTrack.h:218
void setBeta(Float_t beta)
Set beta.
Stores eTOF hit information.
Definition: StPicoETofHit.h:19
Holds BEMC SmdPhi hit information.
void setNVpdHitsWest(UShort_t nHits)
Set number of hits in the west VPD.
Definition: StPicoEvent.h:345
double dEdxErrorFit() const
returns the fitted dEdx resolution value
Stores global information about the event.
Definition: StPicoEvent.h:24
void setPrimaryVertexPosition(Float_t x, Float_t y, Float_t z)
Set primary vertex position (x,y,z)
Definition: StPicoEvent.h:264
void setZdcEastRate(Float_t zdcEastRate)
Set east ZDC rate.
Definition: StPicoEvent.h:391
void setLatestVpdWHit(Double_t latestVpdWHit)
Set furthest VPDW hit compared to start time.
Definition: StPicoEvent.h:374
double dEdxErrorTruncated() const
returns the truncated 70% dEdx resolution value
Float_t nMIP()
gain calibrated energy loss in tile, in units of Landau MPV for one MIP
Definition: StMuEpdHit.h:81
static StBTofHeader * btofHeader()
returns pointer to the btofHeader - dongx
Definition: StMuDst.h:423
void setNumberOfBEMCMatch(Int_t n)
Set number of BEMC-matched tracks.
Definition: StPicoEvent.h:278
const StMuTrack * primaryTrack() const
Returns pointer to associated primary track. Null pointer if no global track available.
Definition: StMuTrack.cxx:578
void setTan(Float_t tan)
Set tangent.
Int_t getBin(const Float_t phi, const Float_t eta, Int_t &m, Int_t &e, Int_t &s) const
Definition: StEmcGeom.h:321
void setBEmcMatchedTowerIndex(Int_t index)
Set index of the BEMC tower that matches the track.
Definition: StPicoTrack.h:289
Double_t nSigmaProton() const
Returns Craig&#39;s distance to the calculated dE/dx band for protons in units of sigma.
Definition: StMuTrack.h:247
static StEmcCollection * emcCollection()
returns pointer to current StEmcCollection
Definition: StMuDst.h:405
void setVpdTacSum(UShort_t tacSum)
Set VPD TAC sum.
void getStatus(Int_t det, Int_t softId, Int_t &status, const char *option="") const
Return status.
float timeOfFlight() const
timing for PID
Bool_t projTrack(StThreeVectorD *atFinal, StThreeVectorD *momentumAtFinal, const StTrack *const track, Double_t magField, Double_t radius=225.405, Int_t option=1) const
Track projection utility.
void setId(Int_t id)
Set vertex ID.
void setPsi(Float_t psi)
Set psi.
void setGeomId(Int_t geomId)
Set geometry ID of the hit.
void setBeta(const Float_t &beta)
Set beta.
float sigmaElectron() const
PID functions.
double dNdxFit() const
returns the fitted dNdx value
void setETofHitMultiplicity(UShort_t mult)
Set total number of hits in ETOF modules.
Definition: StPicoEvent.h:282
void setBbcEastRate(Float_t bbcEastRate)
Set east BBC rate.
Definition: StPicoEvent.h:387
void setIdVtxStart(Int_t id)
Set start MC vertex index.
void setCurv(Float_t curv)
Set curvature.
virtual void Clear(Option_t *option="")
Clear.
static Int_t currentVertexIndex()
Get the index number of the current primary vertex.
Definition: StMuDst.h:260
virtual void moveOrigin(double s)
move the origin along the helix to s which becomes then s=0
Definition: StHelix.cc:621
double dEdxTruncated() const
returns the truncated 70% dEdx value
Double_t nSigmaKaon() const
Returns Craig&#39;s distance to the calculated dE/dx band for kaons in units of sigma.
Definition: StMuTrack.h:246
double Move(double step)
Move along helix.
void setYLocal(Float_t yLocal)
Set yLocal.
std::vector< bool > goodEventFlagVec() const
Flag to mark if the event is good for physics analysis for each counter. A counter is considered good...
StPhysicalHelixD outerHelix() const
Returns outer helix (last measured point)
Definition: StMuTrack.cxx:412
Definition: Stypes.h:44
void setDeltaTimeOfFlight(Float_t t)
Set difference between measured and expected time of flight.
void setTCanLast(Double_t tLast)
Set time of last candidate particle in T0 calculation.
Definition: StPicoEvent.h:358
static void setVertexIndex(Int_t vtx_id)
Set the index number of the current primary vertex (used by both primaryTracks() functions and for St...
Definition: StMuDst.cxx:273
void setNVpdHitsEast(UShort_t nHits)
Set number of hits in the east VPD.
Definition: StPicoEvent.h:343
const StMuETofHit * etofHit() const
dongx
Definition: StMuTrack.h:275
double calibTot() const
Getter for calibrated Tot.
Definition: StMuETofDigi.h:210
StTrackTopologyMap topologyMap() const
Returns topology map.
Definition: StMuTrack.h:254
void setIdVtxItrmd(Int_t id)
Set first intermediate MC vertex index.
unsigned int counter() const
Counter.
Definition: StMuETofDigi.h:214
static UInt_t numberOfMtdTriggers()
Return number of MTD triggers.
Definition: StPicoDst.h:108
Int_t qtData()
Definition: StMuEpdHit.h:79
void setJetPatchThreshold(const Int_t i, const Int_t th)
Set threshold for jet patch.
Definition: StPicoEvent.h:424
void setBEmcSmdMode(const PicoBEmcSmdMode bemcSmdMode)
Set to write or not write BEmc Smd hits.
void setDndxError(Float_t dNdxError)
Set dN/dx error of the track.
Definition: StPicoTrack.h:253
void setMatchFlag(const Char_t flag)
Set match flag.
Definition: Stypes.h:41
void setGeantId(Int_t id)
Set GEANT ID (according to GPART)
unsigned short refMultPos(int vtx_id=-1)
Reference multiplicity of positive particles as defined in StEventUtilities/StuRefMult.hh for vertex vtx_id (-1 is default index from StMuDst)
Definition: StMuEvent.cxx:173
void setLatestVpdEHit(Double_t latestVpdEHit)
Set furthest VPDE hit compared to start time.
Definition: StPicoEvent.h:372
virtual TDataSet * Find(const char *path) const
Definition: TDataSet.cxx:362
void setCharge(Int_t charge)
Set particle charge.
unsigned short refMultFtpcEast(int vtx_id=-1)
Reference multiplicity of particles in the east FTPC as defined in StEventUtilities/StuFtpcRefMult.hh for vertex vtx_id (-1 is default index from StMuDst)
Definition: StMuEvent.cxx:197
void setP(Float_t px, Float_t py, Float_t pz)
Set three-momentum.
double Dca(const double point[3], double *dcaErr=0) const
DCA to given space point (with error matrix)
void setLocalX(Float_t localX)
Set local X coordinate (cm) across strips w.r.t. center of eTOF counter volume.
unsigned short matchFlag() const
matching information