CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/RecoLocalCalo/EcalDeadChannelRecoveryAlgos/interface/CorrectDeadChannelsClassic.cc

Go to the documentation of this file.
00001 //
00002 // Original Author:  Georgios Daskalakis , Georgios.Daskalakis@cern.ch
00003 //         Created:  Fri Mar 30 18:15:12 CET 2007
00004 //         
00005 //
00006 //
00007 //
00008 #include "TMultiLayerPerceptron.h"
00009 #include <TTree.h>
00010 #include <TCanvas.h>
00011 #include <TGraph2D.h>
00012 #include <TSystem.h>
00013 #include <TMath.h>
00014 #include <TGraphErrors.h>
00015 #include <TProfile2D.h>
00016 #include <TProfile.h>
00017 #include <TPostScript.h>
00018 #include <TLegend.h>
00019 #include <TStyle.h>
00020 #include <TRandom.h>
00021 #include "getopt.h"
00022 #include <map>
00023 #include <iostream>
00024 #include "string.h"
00025 #include <sstream>
00026 #include <unistd.h>
00027 #include <iomanip>
00028 #include <fstream>
00029 #include <algorithm>
00030 #include <time.h>
00031 
00032 #include "PositionCorrector.cxx"
00033 #include "SplineCorrector.cxx"
00034 #include "ExponCorrector.cxx"
00035 
00036 
00037 
00038 using namespace std;
00039 
00040 double CorrectDeadChannelsClassic(double *M11x11Input, const int DCeta){
00041 
00042   //std::cout<<"Inside Correction Function ...."<< std::endl;
00043 
00044   PositionCorrector *PosCorr = new PositionCorrector();
00045   SplineCorrector *SplCorr   = new SplineCorrector();
00046   ExponCorrector *ExpCorr    = new ExponCorrector();
00047 
00048 
00049 
00050 
00051   double epsilon = 0.0000001;
00052   float NEWx,NEWy;
00053   float estimX,estimY,SUMlogFR;
00054   float SUM24;
00055   float crE[25];
00056   
00057    
00058 
00059   crE[0]=M11x11Input[40];
00060   crE[1]=M11x11Input[51];
00061   crE[2]=M11x11Input[62];
00062   crE[3]=M11x11Input[73];
00063   crE[4]=M11x11Input[84];
00064 
00065   crE[5]=M11x11Input[39];
00066   crE[6]=M11x11Input[50];
00067   crE[7]=M11x11Input[61];
00068   crE[8]=M11x11Input[72];
00069   crE[9]=M11x11Input[83];
00070 
00071   crE[10]=M11x11Input[38];
00072   crE[11]=M11x11Input[49];
00073   crE[12]=M11x11Input[60];
00074   crE[13]=M11x11Input[71];
00075   crE[14]=M11x11Input[82];
00076 
00077   crE[15]=M11x11Input[37];
00078   crE[16]=M11x11Input[48];
00079   crE[17]=M11x11Input[59];
00080   crE[18]=M11x11Input[70];
00081   crE[19]=M11x11Input[81];
00082 
00083   crE[20]=M11x11Input[36];
00084   crE[21]=M11x11Input[47];
00085   crE[22]=M11x11Input[58];
00086   crE[23]=M11x11Input[69];
00087   crE[24]=M11x11Input[80];
00088 
00089 
00090   std::cout<<"Inside Correction Function : Dead Channel ETA" << DCeta << std::endl;
00091   //revert crystal matrix because of negative eta
00092   if(DCeta<0){
00093 
00094   crE[0]=M11x11Input[36];
00095   crE[1]=M11x11Input[47];
00096   crE[2]=M11x11Input[58];
00097   crE[3]=M11x11Input[69];
00098   crE[4]=M11x11Input[80];
00099 
00100   crE[5]=M11x11Input[37];
00101   crE[6]=M11x11Input[48];
00102   crE[7]=M11x11Input[59];
00103   crE[8]=M11x11Input[70];
00104   crE[9]=M11x11Input[81];
00105 
00106   crE[10]=M11x11Input[38];
00107   crE[11]=M11x11Input[49];
00108   crE[12]=M11x11Input[60];
00109   crE[13]=M11x11Input[71];
00110   crE[14]=M11x11Input[82];
00111 
00112   crE[15]=M11x11Input[39];
00113   crE[16]=M11x11Input[50];
00114   crE[17]=M11x11Input[61];
00115   crE[18]=M11x11Input[72];
00116   crE[19]=M11x11Input[83];
00117 
00118   crE[20]=M11x11Input[40];
00119   crE[21]=M11x11Input[51];
00120   crE[22]=M11x11Input[62];
00121   crE[23]=M11x11Input[73];
00122   crE[24]=M11x11Input[84];
00123 
00124 
00125   }
00126   
00127 
00128 
00129 
00130 
00131   float SUMuu = 0.0;
00132   float SUMu  = 0.0;
00133   float SUMdd = 0.0;
00134   float SUMd  = 0.0;
00135   float SUMll = 0.0;
00136   float SUMl  = 0.0;  
00137   float SUMrr = 0.0;
00138   float SUMr  = 0.0;
00139 
00140   SUMuu  = crE[4]  + crE[9]  + crE[14] + crE[19] + crE[24];
00141   SUMu   = crE[3]  + crE[8]  + crE[13] + crE[18] + crE[23];
00142   SUMd   = crE[1]  + crE[6]  + crE[11] + crE[16] + crE[21];
00143   SUMdd  = crE[0]  + crE[5]  + crE[10] + crE[15] + crE[20];
00144   
00145   SUMll  = crE[0]  + crE[1]  + crE[2]  + crE[3]  + crE[4];
00146   SUMl   = crE[5]  + crE[6]  + crE[7]  + crE[8]  + crE[9];
00147   SUMr   = crE[15] + crE[16] + crE[17] + crE[18] + crE[19];
00148   SUMrr  = crE[20] + crE[21] + crE[22] + crE[23] + crE[24];
00149 
00150   /*
00151   std::cout<<"================================================================="<<std::endl;
00152   std::cout<<crE[4]<<setw(12)<<crE[9]<<setw(12)<<crE[14]<<setw(12)<<crE[19]<<setw(12)<<crE[24]<<std::endl;
00153   std::cout<<crE[3]<<setw(12)<<crE[8]<<setw(12)<<crE[13]<<setw(12)<<crE[18]<<setw(12)<<crE[23]<<std::endl;
00154   std::cout<<crE[2]<<setw(12)<<crE[7]<<setw(12)<<crE[12]<<setw(12)<<crE[17]<<setw(12)<<crE[22]<<std::endl;
00155   std::cout<<crE[1]<<setw(12)<<crE[6]<<setw(12)<<crE[11]<<setw(12)<<crE[16]<<setw(12)<<crE[21]<<std::endl;
00156   std::cout<<crE[0]<<setw(12)<<crE[5]<<setw(12)<<crE[10]<<setw(12)<<crE[15]<<setw(12)<<crE[20]<<std::endl;
00157   std::cout<<"================================================================="<<std::endl;
00158   */
00159 
00160 
00162 
00163   float XLOW[50],XHIG[50],YLOW[50],YHIG[50];
00164   float CentX[50],CentY[50];
00165   int NSUBS = 25;
00166   for(int ix=0; ix<5 ; ix++){
00167     for(int iy=0; iy<5 ; iy++){
00168       int isub= ix*5+iy ; 
00169       
00170       XLOW[isub]= -10.0 +float(ix)*4.0;
00171       XHIG[isub]= XLOW[isub] + 4.0;
00172       YLOW[isub]= -10.0 +float(iy)*4.0;;
00173       YHIG[isub]= YLOW[isub] + 4.0; 
00174       
00175       CentX[isub]=(XHIG[isub]+XLOW[isub])/2.0;
00176       CentY[isub]=(YHIG[isub]+YLOW[isub])/2.0;
00177     }
00178   }
00179 
00180 
00181 
00182 
00184 
00185 
00186 
00187   //First Find the position of the Dead Channel in 3x3 matrix
00188   int DeadCR = -1;
00189   for(int ix=1; ix<4 ; ix++){
00190     for(int iy=1; iy<4 ; iy++){
00191       int idx = ix*5+iy; 
00192       if(fabs(crE[idx])<epsilon && DeadCR >0){std::cout<<" Problem 2 dead channels in sum9! Can not correct ... I return 0.0"<<std::endl; return 0.0;}
00193       if(fabs(crE[idx])<epsilon && DeadCR==-1)DeadCR=idx;
00194     }
00195   }
00196 
00197 
00198   //std::cout<<" THE DEAD CHANNEL IS : "<< DeadCR <<std::endl;
00199   SUM24=0.0;
00200   for(int j=0;j<25;j++)SUM24+=crE[j];
00201   if(DeadCR == -1){std::cout<<" No Dead Channel in 3x3 !   I don't correct ... I return 0.0 ....look S25 = "<<SUM24<<std::endl; return 0.0;}
00202 
00203 
00204 
00205   // CR=12 must be the maximum in 5x5 !!!
00206   int CisMax; CisMax=-1;
00207   float MaxEin5x5; MaxEin5x5=0.0;
00208   for(int ic=0;ic<24;ic++){
00209     if(crE[ic]>MaxEin5x5){
00210       MaxEin5x5 = crE[ic];
00211       CisMax = ic ;
00212     }
00213   }
00214   if(CisMax != 12){
00215     std::cout<<"ERROR ----> Central has NOT the MAX energy in 5x5 ... I return 0.0"<<std::endl;
00216     return 0.0;
00217   }
00218   
00219 
00220 
00221   //AVOID BREM or OTHER DEPOSITIONS IN 5x5
00222   //std::cout<<" CHECK FOR BREM or UNUSUAL PATTERNS  ... " <<std::endl;
00223   //std::cout<<" SUMuu="<<SUMuu<<",SUMu="<<SUMu<<",SUMd="<<SUMd <<",SUMdd="<<SUMdd <<",SUMll="<<SUMll <<",SUMl="<<SUMl <<",SUMrr="<<SUMrr <<",SUMr="<<SUMr <<std::endl;
00224   if(DeadCR==6  && (SUMuu>SUMu || SUMrr>SUMr || SUMll>3.0*SUMr || SUMdd>3.0*SUMu)){std::cout<<"Unusual Pattern in 6 I return 0.0"<<std::endl; return 0.0;}
00225   if(DeadCR==8  && (SUMdd>SUMd || SUMrr>SUMr || SUMll>3.0*SUMr || SUMuu>3.0*SUMd)){std::cout<<"Unusual Pattern in 8 I return 0.0"<<std::endl; return 0.0;}
00226   if(DeadCR==16 && (SUMuu>SUMu || SUMll>SUMl || SUMrr>3.0*SUMl || SUMdd>3.0*SUMu)){std::cout<<"Unusual Pattern in 16 I return 0.0"<<std::endl; return 0.0;}
00227   if(DeadCR==18 && (SUMdd>SUMd || SUMll>SUMl || SUMrr>3.0*SUMl || SUMuu>3.0*SUMd)){std::cout<<"Unusual Pattern in 18 I return 0.0"<<std::endl; return 0.0;}
00228 
00229   if(DeadCR==7  && (SUMuu>SUMu || SUMdd>SUMd || SUMrr>SUMr)){std::cout<<"Unusual Pattern in 7 I return 0.0"<<std::endl; return 0.0;}
00230   if(DeadCR==17 && (SUMuu>SUMu || SUMdd>SUMd || SUMll>SUMl)){std::cout<<"Unusual Pattern in 17 I return 0.0"<<std::endl; return 0.0;}
00231   if(DeadCR==11 && (SUMll>SUMl || SUMrr>SUMr || SUMuu>SUMu)){std::cout<<"Unusual Pattern in 11 I return 0.0"<<std::endl; return 0.0;}
00232   if(DeadCR==13 && (SUMll>SUMl || SUMrr>SUMr || SUMdd>SUMd)){std::cout<<"Unusual Pattern in 13 I return 0.0"<<std::endl; return 0.0;}
00233 
00234 
00235   //std::cout<<" NO BREM OR OTHER DEPOSITIONS IN THIS PATTERN --- I continue ... " <<std::endl;
00236 
00237   SUM24=0.0;
00238   for(int j=0;j<25;j++)if(j!=DeadCR)SUM24+=crE[j];
00239   // std::cout<<" THE Enorm is : "<< SUM24 <<std::endl;
00240 
00241 
00242   //CHECK IF IT IS REALLY THE CORRECT DEAD CHANNEL
00243   // This will be included in the next version
00244 
00245 
00246 
00249    //                   Estimate X,Y
00252 
00253     NEWx=0.0; NEWy=0.0;                     
00254     
00255     
00256     estimX=0.0;
00257     estimY=0.0;
00258     SUMlogFR=0.0;
00259     for(int ix=0; ix<5 ; ix++){
00260       for(int iy=0; iy<5 ; iy++){
00261         int idx = ix*5+iy; 
00262         
00263         float xpos = 20.0*(float(ix)-2.0);
00264         float ypos = 20.0*(float(iy)-2.0);
00265         
00266         if(idx != DeadCR){
00267           
00268           // weight definition
00269           float w = crE[idx]/SUM24;
00270           
00271           if(w<0.0)w=0.0;
00272           SUMlogFR = SUMlogFR + w;
00273           
00274           estimX = estimX + xpos*w;
00275           estimY = estimY + ypos*w;
00276         }
00277         
00278       } // iy loop
00279     }// ix loop
00280     
00281     estimX = estimX/SUMlogFR;               
00282     estimY = estimY/SUMlogFR;    
00283     
00284 
00285        NEWx = PosCorr->CORRX(DeadCR,0,50,estimX);
00286        NEWy = PosCorr->CORRY(DeadCR,0,50,estimY);  
00287 
00288 
00289        //std::cout<<" FINAL X,Y calculation: DC , estimX, estimY, NEWx, NEWy : "<<DeadCR<<" "<<estimX<<" "<<estimY<<" "<< NEWx<<" "<<NEWy<<std::endl;
00290 
00291 
00292     if(DeadCR==7  && (estimX>7.0 || estimX< -2.0 || estimY>10.0 || estimY<-9.0) ){std::cout<<"DC=7  Position OUT of LIMIT I return 0.0"<<std::endl; return 0.0;}
00293     if(DeadCR==17 && (estimX>2.5 || estimX< -8.0 || estimY>10.0 || estimY<-8.0) ){std::cout<<"DC=17 Position OUT of LIMIT I return 0.0"<<std::endl; return 0.0;}
00294     if(DeadCR==11 && (estimX>8.0 || estimX<-10.0 || estimY> 9.0 || estimY<-4.0) ){std::cout<<"DC=11 Position OUT of LIMIT I return 0.0"<<std::endl; return 0.0;}
00295     if(DeadCR==13 && (estimX>8.0 || estimX<-10.0 || estimY> 4.5 || estimY<-8.0) ){std::cout<<"DC=13 Position OUT of LIMIT I return 0.0"<<std::endl; return 0.0;}
00296 
00297     if(DeadCR==12 && (estimX>18.0 || estimX<-18.0 || estimY> 17.0 || estimY<-17.0) ){std::cout<<"DC=12 Position OUT of LIMIT I return 0.0"<<std::endl; return 0.0;}
00298 
00299     if(DeadCR==6  && (estimX>8.0 || estimX< -9.0 || estimY>10.0 || estimY<-8.0) ){std::cout<<"DC=6  Position OUT of LIMIT I return 0.0"<<std::endl; return 0.0;}
00300     if(DeadCR==8  && (estimX>8.0 || estimX< -9.0 || estimY> 9.0 || estimY<-8.5) ){std::cout<<"DC=8  Position OUT of LIMIT I return 0.0"<<std::endl; return 0.0;}
00301     if(DeadCR==16 && (estimX>7.0 || estimX<-10.0 || estimY> 9.0 || estimY<-8.0) ){std::cout<<"DC=16 Position OUT of LIMIT I return 0.0"<<std::endl; return 0.0;}
00302     if(DeadCR==18 && (estimX>8.0 || estimX< -9.0 || estimY> 9.0 || estimY<-8.0) ){std::cout<<"DC=18 Position OUT of LIMIT I return 0.0"<<std::endl; return 0.0;}
00303 
00307 
00308 
00309 
00310   
00311 
00312 
00313 
00314 
00315 
00316      // INFO from SPLINE
00317      float RECOfrDcr = 0.0;
00318      RECOfrDcr = SplCorr->value(DeadCR,0,50,NEWx,NEWy);
00319 
00320 
00321 
00322     // RESOLUTIONS PER AREA
00323     for (int isub=0 ; isub<NSUBS ; isub++){
00324       if( NEWx>XLOW[isub] && NEWx<XHIG[isub] && NEWy>YLOW[isub] && NEWy<YHIG[isub] ){
00325         
00326         
00327         //TEST THE IDEA OF EXPs
00328         if(DeadCR==6  && (isub==0  || isub ==1  || isub==5)  ){
00329           RECOfrDcr = ExpCorr->value(DeadCR,0,50,isub,NEWx,NEWy);
00330         }
00331         if(DeadCR==8  && (isub==4  || isub ==3  || isub==9)  ){
00332           RECOfrDcr = ExpCorr->value(DeadCR,0,50,isub,NEWx,NEWy);
00333         }
00334         if(DeadCR==16 && (isub==15 || isub ==21 || isub==20) ){
00335           RECOfrDcr = ExpCorr->value(DeadCR,0,50,isub,NEWx,NEWy);
00336         }
00337         if(DeadCR==18 && (isub==19 || isub ==23 || isub==24) ){
00338           RECOfrDcr = ExpCorr->value(DeadCR,0,50,isub,NEWx,NEWy);
00339         }
00340         if(DeadCR==7 ||  DeadCR==11 || DeadCR==12 || DeadCR==13 || DeadCR==17 ){
00341           RECOfrDcr = ExpCorr->value(DeadCR,0,50,isub,NEWx,NEWy);
00342         }
00343         
00344         
00345       }
00346     }
00347     
00348     
00349     double ESTIMATED_ENERGY = RECOfrDcr*SUM24;
00350     std::cout<<" THE ESTIMATED RECOfrDcr is : "<< RECOfrDcr <<std::endl;
00351     std::cout<<" THE ESTIMATED ENERGY is : "<<  ESTIMATED_ENERGY <<std::endl;
00352 
00353     if(RECOfrDcr<0.0){std::cout<<"NEGATIVE RECOfrDr I Return 0.0"<<std::endl; RECOfrDcr=0.0;}
00354     if( (DeadCR==6 || DeadCR==8  || DeadCR==16 || DeadCR==18) && RECOfrDcr>0.20){std::cout<<"Fraction OUT of LIMIT I return 0.0"<<std::endl; return 0.0;}
00355     if( (DeadCR==7 || DeadCR==17 || DeadCR==11 || DeadCR==13) && RECOfrDcr>1.00){std::cout<<"Fraction OUT of LIMIT I return 0.0"<<std::endl; return 0.0;}
00356     if( DeadCR==12 && RECOfrDcr>5.00){std::cout<<"Fraction OUT of LIMIT I return 0.0"<<std::endl; return 0.0;}
00357 
00358 
00360 // Using the findings above I build the position and the energy again!
00362 
00363 
00364 
00365   // THIS IS THE FINAL ANSWER
00366   return ESTIMATED_ENERGY;
00367 }
00368 
00369 
00370