EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EicRunDigi.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file EicRunDigi.h
1 //
2 // AYK (ayk@bnl.gov), 2014/09/09
3 //
4 // A trivial (for now) extension of EicRunAna class which allows one
5 // to import real data into the digitization chain and substitute MC
6 // hits preserving all the structure of simulation->digitization->reconstruction
7 // data exchange files; in fact used for FLYSUB data analysis only;
8 //
9 
10 #include <EicRunAna.h>
11 
12 #include <EicGeoParData.h>
13 
14 #ifndef _EIC_RUN_DIGI_
15 #define _EIC_RUN_DIGI_
16 
18 {
19  public:
20  ColumnOrBranchDescriptor(const char *detName, unsigned group, EicGeoParData::IDXYZ what,
21  double scale = 1.0,
22  float *dataPtr = 0, float *errorPtr = 0):
23  mDetName(detName), mGroup(group), mWhat(what), mHaveFreshData(false),
24  mData(0.0), mError(0.0), mDataPtr(dataPtr), mErrorPtr(errorPtr), mScale(scale) {};
26 
27  // Column description;
28  TString mDetName;
29  unsigned mGroup;
31 
32  // Branch entry offset (assume float[] array);
33  float *mDataPtr, *mErrorPtr;
34 
35  // Want to give data away only once; 2-d request will fail;
37  // The actual data and error values;
38  double mData, mError;
39 
40  // Scaling factor needed to convert data to [cm] (or [rad] for radial
41  // detectors);
42  double mScale;
43 };
44 
45 #define _FLOAT_INVALID_ (-919191.0)
46 // Do not mind to have it static;
47 #define _ARRAY_DIM_MAX_ 100
48 
49 class BranchBuffer {
50  public:
51  BranchBuffer(const char *dataBranchName, const char *errorBranchName = 0):
52  mDataBranchName(dataBranchName), mErrorBranchName(errorBranchName) {
53  for(unsigned iq=0; iq<_ARRAY_DIM_MAX_; iq++)
55 
56  mDataVector = new std::vector<float>;
57  mErrorVector = errorBranchName ? new std::vector<float> : 0;
58  };
60 
62  std::vector<float> *mDataVector, *mErrorVector;
64 };
65 
66 class EicRunDigi : public EicRunAna
67 {
68  public:
69  EicRunDigi(/*const char *fileName = 0, const char *treeName = 0*/): //FairRunAna(),
72  //if (fileName && treeName) ImportRealHits(fileName, treeName);
73  };
75 
76  // For now it's an ASCII file with FLYSUB hits;
77  void ImportRealHits(const char *fileName, const char *treeName);
79 
80  // FIXME: no double-counting check;
81  void SetColumnDescriptor(const char *detName, unsigned group, EicGeoParData::IDXYZ what,
82  double scale = 1.0) {
83  mDescriptors.push_back(new ColumnOrBranchDescriptor(detName, group, what, scale));
84  };
85  void SetBranchDescriptor(const char *detName, unsigned group, EicGeoParData::IDXYZ what,
86  const char *dataBranchName, const char *errorBranchName, unsigned offset,
87  double scale = 1.0) {
88  float *dataPtr = 0, *errorPtr = 0;
89 
90  // Loop through already defined branches and see whether this one exists already;
91  for(unsigned br=0; br<mBranchBuffers.size(); br++) {
93 
94  // FIXME: think on this, may not be exactly clean;
95  if (buffer->mDataBranchName.EqualTo(dataBranchName) &&
96  (!errorBranchName || buffer->mErrorBranchName.EqualTo(errorBranchName))) {
97  dataPtr = buffer->mDataArray + offset;
98  errorPtr = buffer->mErrorArray + offset;
99  break;
100  } //if
101  } //for
102 
103  // New branch -> have some work to do;
104  if (!dataPtr) {
105  BranchBuffer *buffer = new BranchBuffer(dataBranchName, errorBranchName);
106 
107  // FIXME: check branch existence; well, and float[3] size as well;
108  if (mVectorInputMode) {
109  mHitTree->SetBranchAddress(dataBranchName, &buffer->mDataVector);
110  if (errorBranchName)
111  mHitTree->SetBranchAddress(errorBranchName, &buffer->mErrorVector);
112  }
113  else {
114  mHitTree->SetBranchAddress(dataBranchName, &buffer->mDataArray);
115  if (errorBranchName)
116  mHitTree->SetBranchAddress(errorBranchName, &buffer->mErrorArray);
117  } //if
118  mBranchBuffers.push_back(buffer);
119 
120  dataPtr = buffer->mDataArray + offset;
121  if (errorBranchName) errorPtr = buffer->mErrorArray + offset;
122  } //if
123 
124  mDescriptors.push_back(new ColumnOrBranchDescriptor(detName, group, what, scale, dataPtr, errorPtr));
125  };
126 
127  // No matter ASCII (Aiwu) or ROOT (Kondo); just let the caller know whether MC hits need
128  // to be substituted or not;
129  bool HitImportMode() const { return !mInputHitFileName.IsNull(); };
130 
131  int GetDetectorHits(const char *name, unsigned group, unsigned offset,
132  unsigned mdim, double local[], double sigma[] = 0);
133 
134  private:
135  TString mInputHitFileName; // input file name
136 
138 
140  TTree *mHitTree;
142  std::vector<BranchBuffer*> mBranchBuffers;
143 
144  // Do not want to disturb FairRunAna() activity at all; just keep track
145  // on my own imported line counter and check it against FairRunAna() one;
146  // once there is a mismatch, import new record;
148 
149  std::vector<ColumnOrBranchDescriptor*> mDescriptors;
150 
151  ClassDef(EicRunDigi,5)
152 };
153 
154 #endif