Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /epic-lfhcal-tbana/NewStructure/HGCROC.cc was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /**
0002  * @file HGCROC.cc
0003  * @brief Implementation of the HGCROC readout tile helpers.
0004  */
0005 
0006 #include "HGCROC.h"
0007 #include <cassert>
0008 #include <iostream>
0009 
0010 ClassImp(Hgcroc)
0011 
0012 /**
0013  * @brief Return the ADC waveform stored in this HGCROC tile.
0014  * @return ADC sample vector.
0015  */
0016 std::vector<int> Hgcroc::GetADCWaveform(void) const{
0017   return adc_waveform;
0018 }
0019 
0020 /**
0021  * @brief Check whether any ADC waveform sample exceeds the saturation threshold.
0022  * @return true if an ADC sample is saturated.
0023  */
0024 bool Hgcroc::IsSaturatedADC() const{
0025   for (int k = 0; k < (int)adc_waveform.size(); k++ ){
0026     if (adc_waveform.at(k) > 1022)
0027       return true;
0028   }
0029   return false;
0030 }
0031 
0032 /**
0033  * @brief Check whether any TOT waveform sample exceeds the saturation threshold.
0034  * @return true if a TOT sample is saturated.
0035  */
0036 bool Hgcroc::IsSaturatedTOT() const{
0037   for (int k = 0; k < (int)tot_waveform.size(); k++ ){
0038     if (tot_waveform.at(k) > 4090)
0039       return true;
0040   }
0041   return false;
0042 }
0043 
0044 /**
0045  * @brief Find the first ADC sample below a pedestal-based threshold.
0046  * @param pedSig Pedestal sigma used for thresholding.
0047  * @return Index of the first out-of-threshold sample or -1.
0048  */
0049 int Hgcroc::IsBelowPed(double pedSig) const{
0050   for (int k = 0; k < (int)adc_waveform.size(); k++ ){
0051     if ( adc_waveform.at(k) < (pedestal - pedSig))
0052       return k;
0053   }
0054   return -1;
0055 }
0056 
0057 /**
0058  * @brief Find the waveform sample index with the largest ADC value.
0059  * @return Index of the maximum ADC sample.
0060  */
0061 int Hgcroc::GetMaxSampleADC (void){
0062   Double_t maxADC = -1000;
0063   int nMaxADC   = 0;
0064   for (int k = 0; k < (int)adc_waveform.size(); k++ ){
0065     if (maxADC < adc_waveform.at(k)){
0066       maxADC  = adc_waveform.at(k);
0067       nMaxADC = k;
0068     }
0069   }
0070   return nMaxADC;
0071 }
0072 
0073 /**
0074  * @brief Return the index of the first ADC sample above threshold.
0075  * @return Index of the first suitable waveform sample.
0076  */
0077 int Hgcroc::GetFirstSampleAboveTh (void){
0078   int nFirst   = 0;
0079   for (int k = 0; k < (int)adc_waveform.size(); k++ ){
0080     if (adc_waveform.at(k) > GetPedestal() +10){
0081       nFirst = k;
0082       break;
0083     }
0084   }
0085   return nFirst;
0086 }
0087 
0088 /**
0089  * @brief Return the TOA waveform stored in this tile.
0090  * @return TOA sample vector.
0091  */
0092 std::vector<int> Hgcroc::GetTOAWaveform(void) const{
0093   return toa_waveform;
0094 }
0095 
0096 /**
0097  * @brief Return the first sample index carrying a non-zero TOA value.
0098  * @return TOA sample index.
0099  */
0100 int Hgcroc::GetFirstTOASample (void){
0101   int nSampTOA  = 0;
0102   for (int k = 0; k < (int)toa_waveform.size(); k++ ){
0103     if (toa_waveform.at(k) > 0){
0104       nSampTOA = k;
0105       break;
0106     }
0107   }
0108   return nSampTOA;
0109 }
0110 
0111 /**
0112  * @brief Return the TOT waveform stored in this tile.
0113  * @return TOT sample vector.
0114  */
0115 std::vector<int> Hgcroc::GetTOTWaveform(void) const{
0116   return tot_waveform;
0117 }
0118 
0119 /**
0120  * @brief Return the number of waveform samples.
0121  * @return Count of samples.
0122  */
0123 int Hgcroc::GetNsample(void) const{
0124   return Nsample;
0125 }
0126 
0127 /**
0128  * @brief Return the corrected TOT value.
0129  * @return TOT value.
0130  */
0131 double Hgcroc::GetCorrectedTOT(void) const{
0132   return TOT;
0133 }
0134 
0135 /**
0136  * @brief Return the first non-zero TOT sample in the waveform.
0137  * @return Raw TOT value.
0138  */
0139 double Hgcroc::GetRawTOT(void) const{
0140   double tot = 0;
0141   for (int k = 0; k < (int)tot_waveform.size(); k++ ){
0142     if (tot_waveform.at(k) > 0){
0143       tot = tot_waveform.at(k);
0144       break;
0145     }
0146   }
0147   return tot;
0148 }
0149 
0150 /**
0151  * @brief Return the maximum TOT observed in the waveform.
0152  * @return Maximum TOT value.
0153  */
0154 double Hgcroc::GetMaxTOT(void) const{
0155   double tot = 0;
0156   for (int k = 0; k < (int)tot_waveform.size(); k++ ){
0157     if (tot_waveform.at(k) > tot){
0158       tot = tot_waveform.at(k);
0159     }
0160   }
0161   return tot;
0162 }
0163 
0164 /**
0165  * @brief Return the mean ADC after subtracting the supplied pedestal.
0166  * @param pedestal Pedestal value used for subtraction.
0167  * @return Mean pedestal-subtracted ADC.
0168  */
0169 double Hgcroc::GetMeanADC(double pedestal) const{
0170   if (adc_waveform.size() == 0) return 0;
0171   double sum = 0;
0172   for (int k = 0; k < (int)adc_waveform.size(); k++ ){
0173     sum += (adc_waveform.at(k) - pedestal);
0174   }
0175   return sum / (double)adc_waveform.size();
0176 }
0177 
0178 /**
0179  * @brief Return the first non-zero TOA sample in the waveform.
0180  * @return Raw TOA value.
0181  */
0182 double Hgcroc::GetRawTOA(void) const{
0183   double toa = 0;
0184   for (int k = 0; k < (int)toa_waveform.size(); k++ ){
0185     if (toa_waveform.at(k) > 0){
0186       toa = toa_waveform.at(k);
0187       break;
0188     }
0189   }
0190   return toa;
0191 }
0192 
0193 /**
0194  * @brief Return the corrected TOA value.
0195  * @return Corrected TOA.
0196  */
0197 double Hgcroc::GetCorrectedTOA(void) const{
0198   return TOA;
0199 }
0200 
0201 /**
0202  * @brief Return the corrected first TOA sample, adjusted by an offset if needed.
0203  * @param toAOffset Offset used to align TOA sample timing.
0204  * @return Index of the corrected first TOA sample.
0205  */
0206 int Hgcroc::GetCorrectedFirstTOASample(double toAOffset) {
0207   int nSampTOA  = GetFirstTOASample();
0208   int rawTOA    = (int)GetRawTOA();
0209   // only calculate if the waveform actually had an intrinsic TOA
0210   if (rawTOA > 1 && toAOffset != -1000.){
0211     if ((rawTOA-toAOffset) < 0)
0212       nSampTOA++; 
0213   }
0214   return nSampTOA;
0215 }
0216 
0217 /**
0218  * @brief Return the pedestal value stored in the tile.
0219  * @return Pedestal value.
0220  */
0221 int Hgcroc::GetPedestal(void) const{
0222   return pedestal;
0223 }
0224 
0225 /**
0226  * @brief Set the complete ADC waveform.
0227  * @param v Vector of ADC samples.
0228  */
0229 void Hgcroc::SetADCWaveform(std::vector<int> v){
0230   adc_waveform=v;
0231 }
0232 
0233 /**
0234  * @brief Append one ADC sample to the waveform.
0235  * @param a ADC sample value.
0236  */
0237 void Hgcroc::AppendWaveformADC(int a){
0238   adc_waveform.push_back(a);
0239 }
0240 
0241 /**
0242  * @brief Reset a single ADC sample at a given index.
0243  * @param s Sample index.
0244  * @param a New ADC value.
0245  */
0246 void Hgcroc::ResetADCWaveformPoint(int s, int a){
0247   assert(0<=s && s<(int)adc_waveform.size());
0248   adc_waveform.at(s)=a;
0249 }
0250 
0251 /**
0252  * @brief Set the complete TOA waveform.
0253  * @param v Vector of TOA samples.
0254  */
0255 void Hgcroc::SetTOAWaveform(std::vector<int> v){
0256   toa_waveform=v;
0257 }
0258 
0259 /**
0260  * @brief Append one TOA sample to the waveform.
0261  * @param a TOA sample value.
0262  */
0263 void Hgcroc::AppendWaveformTOA(int a){
0264   toa_waveform.push_back(a);
0265 }
0266 
0267 /**
0268  * @brief Reset a single TOA sample at a given index.
0269  * @param s Sample index.
0270  * @param a New TOA value.
0271  */
0272 void Hgcroc::ResetTOAWaveformPoint(int s, int a){
0273   assert(0<=s && s<(int)toa_waveform.size());
0274   toa_waveform.at(s)=a;
0275 }
0276 
0277 /**
0278  * @brief Set the complete TOT waveform.
0279  * @param v Vector of TOT samples.
0280  */
0281 void Hgcroc::SetTOTWaveform(std::vector<int> v){
0282   tot_waveform=v;
0283 }
0284 
0285 /**
0286  * @brief Append one TOT sample to the waveform.
0287  * @param a TOT sample value.
0288  */
0289 void Hgcroc::AppendWaveformTOT(int a){
0290   tot_waveform.push_back(a);
0291 }
0292 
0293 /**
0294  * @brief Reset a single TOT sample at a given index.
0295  * @param s Sample index.
0296  * @param a New TOT value.
0297  */
0298 void Hgcroc::ResetTOTWaveformPoint(int s, int a){
0299   assert(0<=s && s<(int)tot_waveform.size());
0300   tot_waveform.at(s)=a;
0301 }
0302 
0303 /**
0304  * @brief Set the number of waveform samples.
0305  * @param n Sample count.
0306  */
0307 void Hgcroc::SetNsample(int n){
0308   Nsample=n;
0309 }
0310 
0311 /**
0312  * @brief Set the corrected TOT value.
0313  * @param tot Corrected TOT value.
0314  */
0315 void Hgcroc::SetCorrectedTOT(double tot){
0316   TOT=tot;
0317 }
0318 
0319 /**
0320  * @brief Correct the TOA using the supplied offset.
0321  * @param offset Timing offset for correction.
0322  * @return Sample index associated with the corrected TOA.
0323  */
0324 int Hgcroc::SetCorrectedTOA(int offset){
0325   int rawTOA    = (int)GetRawTOA();
0326   // only calculate if the waveform actually had an intrinsic TOA
0327   if (rawTOA > 1){
0328     int toacorr   = (rawTOA-offset)%1024;
0329     int nSampTOA  = (int)GetFirstTOASample();
0330     if (rawTOA-offset < 0)
0331       nSampTOA++;
0332     double toacorrf  = double((-1)*nSampTOA*1024-toacorr);
0333     TOA=toacorrf;
0334     return nSampTOA;
0335   // otherwise return default values
0336   } else {
0337     TOA = -10e5;
0338     return 0;
0339   }
0340   return 0;
0341 }
0342 
0343 /**
0344  * @brief Return a linearized version of the raw TOA value.
0345  * @return Linearized raw TOA value.
0346  */
0347 int Hgcroc::GetLinearizedRawTOA(){
0348   int rawTOA    = (int)GetRawTOA();
0349   if (rawTOA == 0)
0350     return -10e5;
0351   int nSampTOA  = (int)GetFirstTOASample();
0352   
0353   return (-1)*nSampTOA*1024-rawTOA;
0354 }
0355 
0356 /**
0357  * @brief Set the pedestal value for this tile.
0358  * @param ped Pedestal value.
0359  */
0360 void Hgcroc::SetPedestal(int ped){
0361   pedestal=ped;
0362 }
0363 
0364 /**
0365  * @brief Print waveform debug information for calibration and diagnostics.
0366  * @param pedMeanH Mean high-gain pedestal.
0367  * @param pedMeanL Mean low-gain pedestal.
0368  * @param pedSig Pedestal sigma.
0369  */
0370 void Hgcroc::PrintWaveFormDebugInfo( double pedMeanH, double pedMeanL, double pedSig){
0371     Setup* setupT = Setup::GetInstance();
0372     int layer     = setupT->GetLayer(CellID);
0373     int chInLayer = setupT->GetChannelInLayer(CellID);          
0374     int roCh      = setupT->GetROchannel(CellID);
0375     std::cout << "Cell ID:" << CellID<< "\t" << layer <<"\t" << chInLayer << "\t RO channel:\t" << roCh << "\t" << pedMeanH << "\t" << pedMeanL << "\t" << pedSig;
0376     std::cout << "\n \tADC-wave " ;
0377     for (int k = 0; k < (int)adc_waveform.size(); k++ ){
0378       std::cout << adc_waveform.at(k) << "\t" ;
0379     }
0380     std::cout << "\n \tTOT-Wave ";
0381     for (int k = 0; k < (int)tot_waveform.size(); k++ ){
0382       std::cout << tot_waveform.at(k) << "\t" ;
0383     }
0384     std::cout << "\n \tTOA-Wave ";
0385     for (int k = 0; k < (int)toa_waveform.size(); k++ ){
0386       std::cout << toa_waveform.at(k) << "\t" ;
0387     }
0388   std::cout <<"\n\t\t\t";
0389   for (int k = 0; k < (int)toa_waveform.size(); k++ )
0390     std::cout <<"\t";  
0391   std::cout << " integ: "<<GetIntegratedADC() <<"\t"<< GetRawTOT() << "\t" << GetRawTOA() << "\t nTOA = " << GetFirstTOASample() << "\t nTh = " << GetFirstSampleAboveTh() << "\t nMax = " << GetMaxSampleADC()  << std::endl;
0392 
0393 }