EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EicRunDigi.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file EicRunDigi.cxx
1 //
2 // AYK (ayk@bnl.gov), 2014/09/09
3 //
4 // A trivial (for now) extension of FairRunAna class;
5 //
6 
7 #include <assert.h>
8 #include <math.h>
9 
10 #include "TMath.h"
11 
12 #include <FairEventHeader.h>
13 
14 #include <EicRunDigi.h>
15 
16 // ---------------------------------------------------------------------------------------
17 
18 void EicRunDigi::ImportRealHits(const char *fileName, const char *treeName)
19 {
20  // This function can also be called from the constructor, so prefer
21  // to fall out in case of problems;
22  if (!fileName || !treeName)
23  fLogger->Fatal(MESSAGE_ORIGIN, "\033[5m\033[31m Zero input file pointer! \033[0m");
24 
25  mInputHitFileName = TString(fileName);
26 
27  // Do not mind to open the file right here; assume exact path given; distinguish
28  // betwee ROOT file and any other extension (assuming ASCII file then);
29  if (mInputHitFileName.EndsWith(".root")) {
30  mInputHitRootFile = new TFile(fileName);
31  if (!mInputHitRootFile->IsOpen())
32  fLogger->Fatal(MESSAGE_ORIGIN, "\033[5m\033[31m Failed to open '%s' ROOT input file with hits! \033[0m",
33  fileName);
34 
35  // And get access to the tree with hits; FIXME: #define, please;
36  mHitTree = (TTree*)mInputHitRootFile->Get(/*"TTracking"*/treeName);
37  if (!mHitTree)
38  fLogger->Fatal(MESSAGE_ORIGIN, "\033[5m\033[31m No '%s' tree found in the ROOT file '%s'! \033[0m",
39  treeName, fileName);
40  }
41  else {
42  mInputHitAsciiFile = fopen(fileName, "r");
43  if (!mInputHitAsciiFile)
44  fLogger->Fatal(MESSAGE_ORIGIN, "\033[5m\033[31m Failed to open '%s' ASCII input file with hits! \033[0m",
45  fileName);
46  } //if
47 } // EicRunDigi::ImportRealHits()
48 
49 // ---------------------------------------------------------------------------------------
50 
51 //
52 // NB: do not care about any efficiency here; code is only useful
53 // for test run data analysis, etc;
54 //
55 
56 int EicRunDigi::GetDetectorHits(const char *name, unsigned group, unsigned offset,
57  unsigned mdim, double local[], double sigma[])
58 {
59  // Identified component counter (see check at the end);
60  unsigned counter = 0;
61 
62  // Sanity check;
63  if (!name || !local) return -1;
64 
65  // Reset all components to 0.0 (sane default state);
66  for(unsigned iq=0; iq<mdim; iq++)
67  local[iq] = 0.0;
68 
69  // Check, that event ID has not changed since last import;
70  FairEventHeader *evHeader = GetEventHeader();
71  //printf("entry %d\n", evHeader->GetMCEntryNumber());
72  if (evHeader->GetMCEntryNumber() != mLastImportedEventID) {
73  // Import next track;
74  if (mInputHitRootFile) {
75  if (evHeader->GetMCEntryNumber() < mHitTree->GetEntries()) {
76  mHitTree->GetEntry(evHeader->GetMCEntryNumber());
77 
78  if (mVectorInputMode)
79  for(unsigned br=0; br<mBranchBuffers.size(); br++) {
81 
82  //printf("%d -> %f %f\n", buffer->mDataVector->size(),
83  // (*buffer->mDataVector)[0], (*buffer->mErrorVector)[0]);
84  for(unsigned iq=0; iq<_ARRAY_DIM_MAX_; iq++) {
85  buffer->mDataArray[iq] = (*buffer->mDataVector)[iq] + iq*0.38 + 26.60;
86  //buffer->mDataArray[iq] = (*buffer->mDataVector)[iq];// + iq*0.38;// + 26.60;
87  if (buffer->mDataVector) {
88  buffer->mErrorArray[iq] = (*buffer->mErrorVector)[iq];
89  //printf("%f\n", buffer->mErrorArray[iq]);
90  //if (buffer->mErrorArray[iq] < 0.2) buffer->mErrorArray[iq] = 0.2;
91  //if (buffer->mErrorArray[iq] > 0.1) buffer->mErrorArray[iq] = 2.0;
92  }
93  } //for iq
94  } //if .. for br
95 
96 #if _LATER_
97  for(unsigned br=0; br<mBranchBuffers.size(); br++) {
99 
100  if (buffer->mDataBranchName.EqualTo("UVAEIC")) {
101  double x = buffer->mArr[0], y = buffer->mArr[1], ra = 6.067*TMath::Pi()/180;
102 
103  if (x == _FLOAT_INVALID_ || y == _FLOAT_INVALID_)
104  buffer->mArr[0] = buffer->mArr[1] = _FLOAT_INVALID_;
105  else {
106  double qx = 2*x*tan(ra), qy = 2*y;
107 
108  double clustY1 = (qx+qy)/2;
109  double clustY0 = (qy-qx)/2;
110 
111  //buffer->mArr[0] = clustY0*0.98;
112  //buffer->mArr[1] = clustY1*0.98;
113  buffer->mArr[0] = clustY0;//*1.015;
114  buffer->mArr[1] = clustY1;//*1.015;
115  } //if
116  } //if
117  }
118 #endif
119  for(unsigned col=0; col<mDescriptors.size(); col++) {
120  ColumnOrBranchDescriptor *descriptor = mDescriptors[col];
121 
122  // Yes, check entry validity;
123  if (*descriptor->mDataPtr != _FLOAT_INVALID_) {
124  descriptor->mData = *descriptor->mDataPtr;
125  //printf("%s -> %d/%d -> %f\n", descriptor->mDetName.Data(),
126  // descriptor->mGroup, descriptor->mWhat, descriptor->mData);
127 
128  if (descriptor->mErrorPtr)
129  descriptor->mError = *descriptor->mErrorPtr;
130 
131  descriptor->mHaveFreshData = true;
132  } //if
133  } //for col
134  } //if
135  }
136  else {
137  // Read in the next line from ASCII input hit file;
138  for(unsigned col=0; col<mDescriptors.size(); col++) {
139  ColumnOrBranchDescriptor *descriptor = mDescriptors[col];
140 
141  if (fscanf(mInputHitAsciiFile, "%lf", &descriptor->mData) != 1) return -1;
142  //#if 1
143  //if (col == 8) descriptor->mData *= 1860;
144  //if (col == 8) descriptor->mData *= 10;
145  //#endif
146  descriptor->mHaveFreshData = true;
147  } //for col
148  } //if
149 
151  } //if
152 
153  //
154  // This stuff is the same for ASCII and ROOT input;
155  //
156 
157  // Loop through all column descriptors and fill out matching components
158  // of the output array; if at least one match found, return success;
159  for(unsigned col=0; col<mDescriptors.size(); col++) {
160  ColumnOrBranchDescriptor *descriptor = mDescriptors[col];
161 
162  if (descriptor->mHaveFreshData && descriptor->mDetName.EqualTo(name) &&
163  descriptor->mGroup == group &&
164  descriptor->mWhat >= offset && descriptor->mWhat < offset+mdim) {
165  unsigned index = descriptor->mWhat - offset;
166  // Convert [mm] (Aiwu's - and also Kondo's & Bob's? - format) to [cm];
167  // FIXME: make configurable later?;
168  //local[index] = 0.1 * descriptor->mData;
169  //if (sigma) sigma[index] = 0.1 * descriptor->mError;
170  local[index] = descriptor->mScale * descriptor->mData;
171  if (sigma) sigma[index] = descriptor->mScale * descriptor->mError;
172 
173  // Give data away once -> make a usage note;
174  descriptor->mHaveFreshData = false;
175 
176  // Component found -> increment counter;
177  counter++;
178  } //if
179  } //for col
180 
181  return (counter == mdim ? 0 : -1);
182 } // EicRunDigi::GetDetectorHits()
183 
184 // ---------------------------------------------------------------------------------------
185