emcRawDataProcessorv2.C

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