emcRawDataProcessorv3.C

Go to the documentation of this file.
00001 #include "emcRawDataProcessorv3.h"
00002 #include "emcTowerContainer.h"
00003 #include "emcTowerContent.h"
00004 #include "emcBadModules.h"
00005 #include "emcDataError.h"
00006 #include "emcCalibrationDataHelper.h"
00007 #include <cmath>
00008 #include <cassert>
00009 #include "emcCalFEM.h"
00010 
00011 ClassImp(emcRawDataProcessorv3)
00012 
00013 using std::string;
00014 
00015 static const string ksPedestals5 = "Pedestals5";
00016 static const string ksTAC = "TAC";
00017 static const string ksHG_Pre = "HG_Pre";
00018 static const string ksHG_Post = "HG_Post";
00019 static const string ksLG_Pre = "LG_Pre";
00020 static const string ksLG_Post = "LG_Post";
00021 
00022 //_____________________________________________________________________________
00023 emcRawDataProcessorv3::emcRawDataProcessorv3(emcCalibrationDataHelper* ch)
00024   : emcRawDataProcessor()
00025 {
00026   fCH = ch;
00027 }
00028 
00029 //_____________________________________________________________________________
00030 emcRawDataProcessorv3::~emcRawDataProcessorv3()
00031 {
00032 }
00033 
00034 //_____________________________________________________________________________
00035 bool
00036 emcRawDataProcessorv3::chooseLowGainPbSc(emcTowerContent* tower, float& scale)
00037 {
00038   int lgpp = tower->LGPP();
00039 
00040   static emcDataError dataerror;
00041 
00042   static int badhighgain = 
00043     dataerror.HG_PRE_OUT() +
00044     dataerror.HG_POST_OUT();
00045 
00046   bool rv = ( ( lgpp > 192 ) ||
00047               ( tower->DataError() & badhighgain ) );
00048   // if both high gain samples are bad,
00049   // we for sure can only take the low gain...
00050   
00051   if (rv) 
00052     {
00053       const emcCalFEM* calfem = fCH->getCalibration(tower->FEM(),"HLRatios");
00054       assert(calfem!=0);
00055       scale = calfem->getValueFast(tower->Channel());
00056       if ( scale < 12.0 || scale > 18.0 ) 
00057         {
00058           scale = 15.4; 
00059         }
00060     }
00061   else 
00062     {
00063       scale = 1.0;
00064     }
00065 
00066   return rv;
00067 }
00068 
00069 //_____________________________________________________________________________
00070 bool 
00071 emcRawDataProcessorv3::chooseLowGainPbGl(emcTowerContent* t, float& scale)
00072 {
00073   bool badHighGain = ( t->HGPP() < 0 && t->LGPP() > 50 );
00074   bool goodLowGain = ( t->LGPP() >170 );
00075 
00076   bool rv = ( t->DataError() & 0x003f || 
00077               badHighGain || 
00078               t->HGPost() < 1024 || 
00079               goodLowGain );
00080   
00081   if ( rv ) 
00082     {
00083       const emcCalFEM* calfem = fCH->getCalibration(t->FEM(),"HLRatios");
00084       assert(calfem!=0);
00085       scale = calfem->getValueFast(t->Channel(),3);
00086      
00087       if ( scale < 10. || scale > 21.) 
00088         {
00089           scale = 15.33;
00090         }
00091     }
00092   else
00093     {
00094       scale = 1.0;
00095     }
00096 
00097   return rv;
00098 }
00099 
00100 //_____________________________________________________________________________
00101 int
00102 emcRawDataProcessorv3::isValid() const
00103 {
00104   return 1;
00105 }
00106 
00107 //_____________________________________________________________________________
00108 void
00109 emcRawDataProcessorv3::identify(std::ostream& out) const
00110 {
00111   out << "emcRawDataProcessorv3::identify" << std::endl;
00112 }
00113 
00114 //_____________________________________________________________________________
00115 void
00116 emcRawDataProcessorv3::Reset()
00117 {
00118 }
00119 
00120 //_____________________________________________________________________________
00121 bool
00122 emcRawDataProcessorv3::toADCandTDC(emcTowerContainer* pbsc, 
00123                                    emcTowerContainer* pbgl,
00124                                    const emcBadModules& bad)
00125 {
00126   if (pbsc)
00127     {
00128       FPTR ptr = &emcRawDataProcessorv3::chooseLowGainPbSc;
00129       for ( unsigned int i = 0; i < pbsc->size(); ++i ) 
00130         {      
00131           toADCandTDC(pbsc->getTower(i),ptr,bad);
00132         }
00133     }
00134 
00135   if (pbgl)
00136     {
00137       FPTR ptr = &emcRawDataProcessorv3::chooseLowGainPbGl;
00138       for ( unsigned int i = 0; i < pbgl->size(); ++i ) 
00139         {      
00140           toADCandTDC(pbgl->getTower(i),ptr,bad);
00141         }
00142     }
00143 
00144   return true;
00145 }
00146 
00147 //_____________________________________________________________________________
00148 void
00149 emcRawDataProcessorv3::toADCandTDC(emcTowerContent* tower, 
00150                                    FPTR function_ptr,
00151                                    const emcBadModules& bad)
00152 {
00153   emcDataError dataerror;
00154   int towerID = tower->TowerID();
00155 
00156   // Check if this module is known to be dead
00157   if ( bad.DeadmapFast(towerID) & 0x400 )
00158     {
00159       tower->Zero();
00160       tower->SetDataError(dataerror.CHANNEL_DISABLED());
00161       return;
00162     }
00163 
00164   if ( tower->isZero() )
00165     {
00166       tower->SetADCTDC(0,0,0,0);
00167       tower->SetNeighbours(bad.DeadmapFast(towerID),
00168                            bad.WarnmapFast(towerID));
00169       return;
00170     }
00171 
00172   float scale = 1.0;
00173 
00174   bool kChooseLowGain = (this->*function_ptr)(tower,scale);
00175 
00176   int lg = tower->LGPP();
00177   int hg = tower->HGPP();
00178 
00179   float fadc;
00180 
00181   const emcCalFEM* calfem = fCH->getCalibration(tower->FEM(),ksPedestals5);
00182   assert(calfem!=0);
00183 
00184   float ped = 0.0;
00185 
00186   float ped_lg_pre = 
00187     calfem->getValueFast(tower->Channel(),tower->AMUPre(),ksLG_Pre);
00188   float ped_lg_post =
00189     calfem->getValueFast(tower->Channel(),tower->AMUPost(),ksLG_Post);
00190   float ped_hg_pre =
00191     calfem->getValueFast(tower->Channel(),tower->AMUPre(),ksHG_Pre);
00192   float ped_hg_post =
00193     calfem->getValueFast(tower->Channel(),tower->AMUPost(),ksHG_Post);
00194        
00195   if (kChooseLowGain) 
00196     {
00197       ped = - ped_lg_pre + ped_lg_post;
00198       if (fabs(ped)<20) 
00199         {
00200           fadc = (lg + ped)*scale;
00201         }
00202       else
00203         {
00204           fadc = lg * scale;
00205         }
00206     }
00207   else 
00208     { 
00209       ped = - ped_hg_pre + ped_hg_post;
00210       if (fabs(ped)<20) 
00211         {
00212           fadc = hg + ped;
00213         }
00214       else
00215         {
00216           fadc = hg;      
00217         }
00218     }
00219    
00220   int tac = tower->TAC();
00221 
00222   assert ( tac>=0 && tac<4096 );
00223     
00224   float ftdc = 0.0;
00225   float tacped = calfem->getValueFast(tower->Channel(),tower->AMUTAC(),ksTAC);
00226 
00227   ftdc = tac*1.0 - ( (tacped>0) ? tacped : 
00228                      calfem->getValueFast(tower->Channel(), 0, ksTAC) ); 
00229   
00230   int adc = static_cast<int>(floor(fadc+0.5));
00231   int tdc = static_cast<int>(floor(ftdc+0.5));
00232   
00233   float fhg = hg - ped_hg_pre + ped_hg_post;
00234   float flg = lg - ped_lg_pre + ped_lg_post;
00235 
00236   tower->SetADCTDC(adc,tdc,
00237                    static_cast<int>(floor(fhg+0.5)),
00238                    static_cast<int>(floor(flg+0.5)));
00239   
00240   tower->SetNeighbours(bad.DeadmapFast(towerID),
00241                        bad.WarnmapFast(towerID));
00242 }