Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DTTabUtilities.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: DTTabUtilities.cc
4 // Created: Fri Apr 3 09:41:29 EDT 2015
5 // Creator: pmatt (on Linux pmattdesktop.jlab.org 2.6.32-504.12.2.el6.x86_64 x86_64)
6 //
7 
8 #include "DTTabUtilities.h"
9 
11 {
12  dTScale_CAEN = 0.0234375; // ~ 23.4375 ps/count (TOF) +/- 0.0012
13 }
14 
15 double DTTabUtilities::Convert_DigiTimeToNs_F1TDC(const JObject* locTDCDigiHit) const
16 {
17  //See if the input object is an DF1TDCHit. If so, convert it
18  const DF1TDCHit* locF1TDCHit = dynamic_cast<const DF1TDCHit*>(locTDCDigiHit);
19  if(locF1TDCHit != NULL) //it's an F1TDCHit
20  return Convert_DigiTimeToNs_F1TDC(locF1TDCHit);
21 
22  //Get the DF1TDCHit associated object
23  vector<const DF1TDCHit*> locF1TDCHits;
24  locTDCDigiHit->Get(locF1TDCHits);
25  if(locF1TDCHits.empty())
26  {
27  cout << "ERROR: INCORRECT INPUT OBJECT TO DTTabUtilities::Convert_DigiTimeToNs_F1TDC(). RETURNING NaN." << endl;
28  return std::numeric_limits<double>::quiet_NaN();
29  }
30 
31  //Convert
32  return Convert_DigiTimeToNs_F1TDC(locF1TDCHits[0]);
33 }
34 
35 double DTTabUtilities::Convert_DigiTimeToNs_F1TDC(const DF1TDCHit* locF1TDCHit) const
36 {
37  uint32_t locROCID = locF1TDCHit->rocid;
38 
39  // Get DF1TDCConfig for this ROC
40  vector<const DF1TDCConfig*> locF1TDCConfigs;
41  locF1TDCHit->Get(locF1TDCConfigs);
42 
43  // Get DCODAROCInfo for this ROC
44  map<uint32_t, const DCODAROCInfo*>::const_iterator locROCInfoIterator = dCODAROCInfoMap.find(locROCID);
45  const DCODAROCInfo* locCODAROCInfo = (locROCInfoIterator != dCODAROCInfoMap.end()) ? locROCInfoIterator->second : NULL;
46 
47  if(locCODAROCInfo == NULL) //e.g. MC
49 
50  if(locF1TDCConfigs.empty() || dHasBadOrNoF1TDCConfigInfoFlag) //e.g. Early Fall 2014 Commissioning Data (use CCDB constants)
51  return Convert_DigiTimeToNs_F1TDC_GlobalSystemClock_CCDB(locF1TDCHit, locCODAROCInfo);
52 
53  // Have all objects needed, call the main function
54  return Convert_DigiTimeToNs_F1TDC_GlobalSystemClock_ConfigInfo(locF1TDCHit, locCODAROCInfo, locF1TDCConfigs[0]);
55 }
56 
57 double DTTabUtilities::Convert_DigiTimeToNs_F1TDC_GlobalSystemClock_ConfigInfo(const DF1TDCHit* locF1TDCHit, const DCODAROCInfo* locCODAROCInfo, const DF1TDCConfig* locF1TDCConfig) const
58 {
59  //compare the digi time to the global system clock available on the crate, then convert to ns
60  //GlueX Doc 2686 Appendix A, using the global system clock
61 
62  //GlueX DOC 747
63  //48-channel-readout = F1TDCV3 (FDC) = low-resolution readout (115 ps vs 57 ps) //fewer (factor 2) TDC-ticks per ns
64  bool locIsHighResolutionReadout = (locF1TDCHit->modtype != DModuleType::F1TDC48);
65 
66  //Calculate TDC -> ns Scale Factor
67  //32.0 is TREF and should be extracted from the data-stream but it's not available
68  double locTDCToNsScaleFactor = (32.0/152.0) * double(locF1TDCConfig->REFCLKDIV) / (double(locF1TDCConfig->HSDIV)); // 32 ns / #-tdc-ticks-in-32ns
69  //(32.0/152.0) * double(128) / (232)
70  if(locIsHighResolutionReadout) //should use HIGHRES bit from the data-stream, but it's not available
71  locTDCToNsScaleFactor /= 2.0; //more TDC-ticks per ns
72 
73  //Calculate rollover window size for the F1TDCs
74  uint64_t locRolloverTimeWindowLength = (uint64_t(32))*(uint64_t(locF1TDCConfig->REFCNT + 2));
75 
76  // Transition the reference time into this F1TDC time window (get remainder)
77  uint64_t locReferenceTimeThisWindow = Calc_ROCRefTimeThisWindow(locCODAROCInfo, locRolloverTimeWindowLength);
78 
79  //compute and return the time difference
80  double locDeltaT = locTDCToNsScaleFactor*double(locF1TDCHit->time) - double(locReferenceTimeThisWindow); // in ns
81  if(locDeltaT < 0.0) // Take care of rollover
82  locDeltaT += double(locRolloverTimeWindowLength); //the time rolled over between the hit and reference times
83 
84  return locDeltaT;
85 }
86 
87 double DTTabUtilities::Convert_DigiTimeToNs_F1TDC_GlobalSystemClock_CCDB(const DF1TDCHit* locF1TDCHit, const DCODAROCInfo* locCODAROCInfo) const
88 {
89  //compare the digi time to the global system clock available on the crate, then convert to ns
90  //GlueX Doc 2686 Appendix A, using the global system clock, but the CCDB for the constants
91 
92  //GlueX DOC 747
93  //48-channel-readout = F1TDCV3 (FDC) = low-resolution readout (115 ps vs 57 ps) //fewer (factor 2) TDC-ticks per ns
94  bool locIsLowResolutionReadout = (locF1TDCHit->modtype == DModuleType::F1TDC48);
95 
96  //Calculate TDC -> ns Scale Factor
97  double locTDCToNsScaleFactor = Calc_TDCToNsScaleFactor_CCDB(locIsLowResolutionReadout);
98 
99  // Transition the reference time into this F1TDC time window (get remainder)
100  uint64_t locReferenceTimeThisWindow = Calc_ROCRefTimeThisWindow(locCODAROCInfo, dRolloverTimeWindowLength);
101 
102  //compute and return the time difference
103  double locDeltaT = locTDCToNsScaleFactor*double(locF1TDCHit->time) - double(locReferenceTimeThisWindow); // in ns
104  if(locDeltaT < 0.0) // Take care of rollover
105  locDeltaT += double(dRolloverTimeWindowLength); //the time rolled over between the hit and reference times
106 
107  return locDeltaT;
108 }
109 
111 {
112  //compare the digi time to the trigger reference signal, then convert to ns
113  //GlueX Doc 2686 Appendix A, using the trigger reference signal
114 
115  //GlueX DOC 747
116  //48-channel-readout = F1TDCV3 (FDC) = low-resolution readout (115 ps vs 57 ps) //fewer (factor 2) TDC-ticks per ns
117  bool locIsLowResolutionReadout = (locF1TDCHit->modtype == DModuleType::F1TDC48);
118 
119  //Calculate TDC -> ns Scale Factor
120  double locTDCToNsScaleFactor = Calc_TDCToNsScaleFactor_CCDB(locIsLowResolutionReadout);
121 
122  //Calc delta-t //potentially different scale factors between trigger reference & hit
123  double locDeltaT = locTDCToNsScaleFactor*double(locF1TDCHit->time) - Convert_TriggerReferenceSignal();
124 
125  // Take care of rollover
126  if(locDeltaT < 0)
127  locDeltaT += double(dRolloverTimeWindowLength);
128 
129  return locDeltaT;
130 }
131 
132 double DTTabUtilities::Calc_TDCToNsScaleFactor_CCDB(bool locIsLowResolutionReadout) const
133 {
134  double locTDCToNsScaleFactor = double(dRolloverTimeWindowLength)/double(dNumTDCTicksInRolloverTimeWindow);
135  if(locIsLowResolutionReadout)
136  locTDCToNsScaleFactor *= 2.0; //fewer TDC-ticks per ns
137  return locTDCToNsScaleFactor;
138 }
139 
140 uint64_t DTTabUtilities::Calc_ROCRefTimeThisWindow(const DCODAROCInfo* locCODAROCInfo, uint64_t locRolloverTimeWindowLength) const
141 {
142  // Transition the reference time into this F1TDC time window (get remainder)
143  // DCODAROCInfo::timestamp is the number of clock ticks of the global system clock since it was reset (at the beginning of the run)
144  uint64_t locReferenceClockTime = (uint64_t(4))*locCODAROCInfo->timestamp; // one clock tick = 4 ns
145  uint64_t locNumRollovers = locReferenceClockTime/locRolloverTimeWindowLength;
146  return (locReferenceClockTime - locNumRollovers*locRolloverTimeWindowLength);
147 }
148 
150 {
152  return locTDCToNsScaleFactor * double(dTriggerReferenceSignal);
153 }
154 
155 double DTTabUtilities::Convert_DigiTimeToNs_CAEN1290TDC(const JObject* locTDCDigiHit) const
156 {
157  //See if the input object is an DCAEN1290TDCHit. If so, convert it
158  const DCAEN1290TDCHit* locCAEN1290TDCHit = dynamic_cast<const DCAEN1290TDCHit*>(locTDCDigiHit);
159  if(locCAEN1290TDCHit != NULL) //it's an DCAEN1290TDCHit
160  return Convert_DigiTimeToNs_CAEN1290TDC(locCAEN1290TDCHit);
161 
162  //Get the DF1TDCHit associated object
163  vector<const DCAEN1290TDCHit*> locCAEN1290TDCHits;
164  locTDCDigiHit->Get(locCAEN1290TDCHits);
165  if(locCAEN1290TDCHits.empty())
166  {
167  cout << "ERROR: INCORRECT INPUT OBJECT TO DTTabUtilities::Convert_DigiTimeToNs_CAEN1290TDC(). RETURNING NaN." << endl;
168  return std::numeric_limits<double>::quiet_NaN();
169  }
170 
171  //Convert
172  return Convert_DigiTimeToNs_CAEN1290TDC(locCAEN1290TDCHits[0]);
173 }
174 
176 {
177  //compare the digi time to the trigger reference signal, then convert to ns
178  //GlueX Doc 2686
179  uint32_t locROCID = locCAEN1290TDCHit->rocid;
180 
181  // Get DCODAROCInfo for this ROC
182  map<uint32_t, const DCODAROCInfo*>::const_iterator locROCInfoIterator = dCODAROCInfoMap.find(locROCID);
183  if(locROCInfoIterator == dCODAROCInfoMap.end())
184  return std::numeric_limits<double>::quiet_NaN();
185  const DCODAROCInfo* locCODAROCInfo = locROCInfoIterator->second;
186 
187  int locSystemClockBinRemainder = locCODAROCInfo->timestamp % (uint64_t(6));
188 
189  // The number of TI-counter (4 ns) blocks to shift the CAEN time to line-up with the TI time
190  int locNum4NsBlocksToShift = dCAENTIPhaseDifference - locSystemClockBinRemainder;
191  if(locNum4NsBlocksToShift <= 0)
192  locNum4NsBlocksToShift += 6;
193 
194  return dTScale_CAEN*double(locCAEN1290TDCHit->time) + 4.0*double(locNum4NsBlocksToShift);
195 }
196 
198 {
199  // only check to see if the "bad pedestal" flag is set
200  return !( (QF>>6) & 0x01 );
201 }
202 
204 {
205  // only return true if there are no flagged errors from the flash algorithm
206  // this is probably stricter than we want...
207 
208  // check for integration errors
209  if ( (QF>>1) & 0x03 ) return false;
210  // check for timing errors
211  if ( (QF>>4) & 0x02 ) return false;
212 
213  // add other options for future convenience...
214  // if( (QF>>1) & 0x01 ) return false; // NSA beyond readout window
215  // if( (QF>>2) & 0x01 ) return false; // one or more samples were overflow
216  // if( (QF>>3) & 0x01 ) return false; // one or more samples were underflow
217  // if( (QF>>4) & 0x01 ) return false; // timing peak beyond NSA
218  // if( (QF>>5) & 0x01 ) return false; // timing peak not found
219 
220  return true;
221 }
uint64_t dNumTDCTicksInRolloverTimeWindow
double Convert_DigiTimeToNs_F1TDC(const JObject *locTDCDigiHit) const
bool CheckFADC250_NoErrors(uint32_t QF) const
uint64_t timestamp
Definition: DCODAROCInfo.h:22
bool dHasBadOrNoF1TDCConfigInfoFlag
double Convert_DigiTimeToNs_CAEN1290TDC(const JObject *locTDCDigiHit) const
int dCAENTIPhaseDifference
double Convert_TriggerReferenceSignal(void) const
uint32_t time
Definition: DF1TDCHit.h:30
bool dTriggerReferenceSignalIsLowResTDC
double Convert_DigiTimeToNs_F1TDC_GlobalSystemClock_ConfigInfo(const DF1TDCHit *locF1TDCHit, const DCODAROCInfo *locCODAROCInfo, const DF1TDCConfig *locF1TDCConfig) const
uint64_t Calc_ROCRefTimeThisWindow(const DCODAROCInfo *locCODAROCInfo, uint64_t locRolloverTimeWindowLength) const
uint16_t HSDIV
Definition: DF1TDCConfig.h:24
MODULE_TYPE modtype
Definition: DF1TDCHit.h:35
bool CheckFADC250_PedestalOK(uint32_t QF) const
double Convert_DigiTimeToNs_F1TDC_TriggerReferenceSignal(const DF1TDCHit *locF1TDCHit) const
uint16_t REFCLKDIV
Definition: DF1TDCConfig.h:26
map< uint32_t, const DCODAROCInfo * > dCODAROCInfoMap
double Convert_DigiTimeToNs_F1TDC_GlobalSystemClock_CCDB(const DF1TDCHit *locF1TDCHit, const DCODAROCInfo *locCODAROCInfo) const
uint32_t rocid
Definition: DDAQAddress.h:32
uint64_t dRolloverTimeWindowLength
uint16_t REFCNT
Definition: DF1TDCConfig.h:21
double Calc_TDCToNsScaleFactor_CCDB(bool locIsLowResolutionReadout) const
uint64_t dTriggerReferenceSignal