PbScSuperModule.C

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <cstdio>
00003 #include <cstdlib>
00004 #include <cmath>
00005 
00006 using namespace std ;
00007 
00008 #include "Rtypes.h"
00009 #include "EmcStaticData.h"
00010 #include "PbScCalibrationData.h"
00011 #include "PbScSuperModule.h"
00012 
00013  
00014 //#############################################################################
00015 // E.Kistenev         6/10/99 
00016 // send comments to kistenev@bnl.gov 
00017 //#############################################################################
00018 
00019 PbScSuperModule::PbScSuperModule(int & SMNum)
00020 {
00021         SMProductionId = SMNum;
00022         NewData        = NULL;
00023 };
00024 
00025 //*************************************************************************
00026 
00027 PbScSuperModule::~PbScSuperModule()
00028 {
00029         if(NewData){
00030                 delete [] NewData;
00031         }
00032 };
00033  
00034 //*************************************************************************
00035 
00036  
00037 bool PbScSuperModule::LoadSMData() 
00038 { 
00039 //  Load calibration data into SuperModule object identified by its pointer SM 
00040   FILE  * fp; 
00041   char  filename[80]; 
00042   Float_t dummy[9]; 
00043   int SMId=SMProductionId; 
00044         EmcStaticData       * gEmcStaticData = EmcStaticData::buildEmcStaticData();
00045         PbScCalibrationData * PbScData       = gEmcStaticData->getPbScData();
00046         char * fName = PbScData->getPointerToFName(SMId-1);
00047   sprintf(filename,"%s/Cal_902/%s",getenv("EMCAL_DATA_PBSC"),fName) ;
00048   if((fp=fopen(filename,"r"))) 
00049       { 
00050                                 // cout<<"file open: "<<filename<<endl; 
00051       } 
00052     else 
00053       { 
00054                                 cout<<"file open error "<<filename<<endl; 
00055                                 return kFALSE; 
00056       } 
00057   int i,j; 
00058   for(i=0; i<144; i++){ 
00059     for(j=0; j<9; j++){ 
00060       fscanf(fp,"%e", dummy+j); 
00061     } 
00062     Data902.Tower[i].TowerId         = (int)dummy[0]; 
00063     Data902.Tower[i].PMT902          = (int)dummy[1]; 
00064     Data902.Tower[i].hv902           = dummy[2]; 
00065     Data902.Tower[i].PredictedGainQE = dummy[3]; 
00066     Data902.Tower[i].MuPeak          = dummy[4]; 
00067     Data902.Tower[i].LaserRaw        = dummy[5]; 
00068     Data902.Tower[i].LaserPhelRaw    = dummy[6]; 
00069     Data902.Tower[i].LaserPhelNorm   = dummy[7]; 
00070     Data902.Tower[i].MeasuredGain    = dummy[8];
00071   } 
00072   for(i=0; i<144; i++){ 
00073     for(j=0; j<9; j++){ 
00074       fscanf(fp,"%e", dummy+j); 
00075     } 
00076     Data902.Tower[i].ScrLightYield   = dummy[3]; 
00077     Data902.Tower[i].ScrPhelYield    = dummy[2]; 
00078     Data902.Tower[i].EstLightYield   = dummy[5]; 
00079     Data902.Tower[i].EstPhelYield    = dummy[4]; 
00080   }   
00081   for(i=0; i<144; i++){ 
00082     Data902.Tower[i].VGA             = 1.7;        //  Temporary fix
00083   }   
00084     for(j=0; j<4; j++){ 
00085       fscanf(fp,"%e", dummy+j); 
00086     } 
00087     Data902.Ref902.Hamamatsu       = dummy[0]; 
00088     Data902.Ref902.RmsHamamatsu    = dummy[1]; 
00089     Data902.Ref902.HamamatsuPed    = dummy[2]; 
00090     Data902.Ref902.RmsHamamatsuPed = dummy[3]; 
00091     for(j=0; j<6; j++){ 
00092       fscanf(fp,"%e", dummy+j); 
00093    } 
00094     Data902.Ref902.ExtSPD          = dummy[0]; 
00095     Data902.Ref902.RmsExtSPD       = dummy[1]; 
00096     Data902.Ref902.ExtSPDPed       = dummy[2]; 
00097     Data902.Ref902.RmsExtSPDPed    = dummy[3]; 
00098     Data902.Ref902.ExtSPDTP        = dummy[4]; 
00099     Data902.Ref902.RmsExtSPDTP     = dummy[5]; 
00100     for(j=0; j<6; j++){ 
00101       fscanf(fp,"%e", dummy+j); 
00102     } 
00103     Data902.Ref902.IntSPD          = dummy[0]; 
00104     Data902.Ref902.RmsIntSPD       = dummy[1]; 
00105     Data902.Ref902.IntSPDPed       = dummy[2]; 
00106     Data902.Ref902.RmsIntSPDPed    = dummy[3]; 
00107     Data902.Ref902.IntSPDTP        = dummy[4]; 
00108     Data902.Ref902.RmsIntSPDTP     = dummy[5]; 
00109   fclose(fp); 
00110         return kTRUE; 
00111 } 
00112 
00113 //*************************************************************************
00114 
00115 void PbScSuperModule::buildDataBase902(){
00116         NewData = new DB902 [144];
00117 }
00118 
00119 //*************************************************************************
00120 
00121 void PbScSuperModule::LoadDataBase902(int Twr, Float_t * Line){
00122         if(!NewData) {
00123                 //              cout<<"Build PMT DB "<<SMProductionId<<endl;
00124                 buildDataBase902();
00125         }
00126         NewData[Twr].PMTBarCode    = int(Line[2]);
00127         NewData[Twr].Replaced      = int(Line[3]);
00128         NewData[Twr].GainModFactor = Line[4];
00129         NewData[Twr].GQE1kV        = Line[6];
00130         NewData[Twr].Slope         = Line[5];
00131         for (int i = 0; i<PMTWordsPerTower; i++) NewData[Twr].Data[i] = Line[i+7];
00132 }
00133 
00134 //*************************************************************************
00135 
00136 Float_t PbScSuperModule::getNewHV(int HVGroup, Float_t ERange, 
00137                                   Float_t & HVIncrement, Float_t QRange, 
00138                                   Float_t VGACentral, Float_t VGAScale)
00139 {
00140   //  VGAScale    - Scales all VGA values to get VGA distribution centered
00141   //  at a value corresponding to minimum number of channels outside
00142   //  1-3 range limits.
00143   //  HVIncrement - Voltage is initially computed to on average deliver
00144   //  charge equal to QRange/VGACentral for ERange deposited in the counter
00145   //  If VGAScale is not equal to 1 - this voltage is incremented(decremented) 
00146   //  to modify Laser amplitudes according to 1/VGAScale ratio. This option 
00147   //  is used when actual voltage is irrelevant or basically unknown to 
00148   //  the program - probably in future - the program will first read file
00149   //  with voltages as they are tuned at initialization and will use those 
00150   //  to replace the ones computed below
00151 
00152   Float_t GERange0 = QRange/VGACentral*1.e-12/1.602e-19/ERange;
00153   //--  compute average light yield in this group of towers first
00154   Float_t avLight = 0.;
00155   int   Twr;
00156   for(Twr = HVGroup*48; Twr<(HVGroup+1)*48; Twr++){ 
00157     avLight += Data902.Tower[Twr].ScrLightYield;
00158   }
00159   avLight /= 48.;
00160   //    avSlope /= 48.;
00161   GERange0     /= avLight;
00162   //--  now compute average HV for this energy range
00163   Float_t avHV0 = 0.;
00164   Float_t avHV  = 0.;
00165   Float_t LVGAScale = log(VGAScale);
00166   for(Twr = HVGroup*48; Twr<(HVGroup+1)*48; Twr++){
00167     Float_t f1 = log(GERange0/NewData[Twr].GQE1kV)/NewData[Twr].Slope;
00168     avHV0 += exp(f1);
00169     avHV  += exp(f1-LVGAScale/NewData[Twr].Slope);
00170   }
00171   avHV0      /= 48.;
00172   avHV       /= 48.;
00173   HVIncrement = avHV-avHV0;
00174   return avHV0;
00175 }
00176 
00177 // ********************************************************************** 
00178 
00179 void  PbScSuperModule::getNewVGA(int , Float_t , Float_t * , Float_t * )
00180 {
00181 ;
00182 }
00183 
00184 // ********************************************************************** 
00185 
00186 Float_t PbScSuperModule::getNewData(int Twr, int Wrd)
00187 {
00188         if(NewData&&Twr<144&&Wrd<PMTWordsPerTower){
00189                 return NewData[Twr].Data[Wrd];
00190         } else {
00191                 //              cout<<"Request for PMTDB DATA which never been loaded: ProductionId "<<SMProductionId<<" Tower "<<Twr<<" Word "<<Wrd<<endl;
00192                 return 0;
00193         }
00194 }
00195