Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

BinCorrelationEM.cxx

Go to the documentation of this file.
00001 #include "BinCorrelationEM.h"
00002 #include "MessageService/MsgService.h"
00003 #include <fstream>
00004 
00005 using namespace std;
00006 
00007 CVSID("$Id: BinCorrelationEM.cxx,v 1.2 2005/10/21 11:22:30 cbs Exp $");
00008 
00009 BinCorrelationEM::BinCorrelationEM(Double_t *inputs){
00010 
00011   fErrArray = NULL;
00012   fCovMat = NULL;
00013   
00014   if(inputs){
00015     fInputParams = new Double_t[6];
00016     for(Int_t i=0;i<6;i++){
00017       fInputParams[i] = inputs[i];
00018     }
00019     Init();
00020   }
00021   else fInputParams = NULL;
00022 
00023 }
00024 
00025 BinCorrelationEM::~BinCorrelationEM(){
00026   if(fErrArray) delete [] fErrArray;
00027   if(fCovMat) delete [] fCovMat;
00028   if(fInputParams) delete [] fInputParams;
00029 }
00030 
00031 void BinCorrelationEM::ReInit(Double_t *inputs){
00032 
00033   //delete old inputs
00034   Double_t CurrentEnergy = -1;
00035   if(fInputParams) {
00036     CurrentEnergy = fInputParams[0];
00037     delete [] fInputParams;
00038   }
00039   
00040   //read in new ones
00041   fInputParams = new Double_t[6];
00042   for(Int_t i=0;i<6;i++){
00043     fInputParams[i] = inputs[i];
00044   }
00045   
00046   //delete fErrArray whatever happens
00047   //only delete fCovMat if the energy has changed
00048   if(fInputParams[0]>0){
00049     Init();
00050     delete [] fErrArray;
00051     fErrArray = NULL;
00052     if(CurrentEnergy!=fInputParams[0]) {
00053       delete [] fCovMat;
00054       fCovMat = NULL;
00055     }
00056   }
00057   else MSG("FitShowerEM",Msg::kWarning)
00058     <<"Trying to ReInit with energy <=0 ... Probably everything will break..." 
00059     << endl;
00060 }
00061 
00062 void BinCorrelationEM::Init(){
00063 
00064 }
00065 
00066 Double_t BinCorrelationEM::CalcCorrelation(Double_t /*t*/, Double_t /*r*/){
00067   
00068   return 1;
00069 
00070 }
00071 
00072 Double_t *BinCorrelationEM::GetErrArray(Int_t LowBin_pl,Int_t HighBin_pl,
00073                                         Int_t LowBin_st,Int_t HighBin_st){
00074 
00075   if(fErrArray) return fErrArray;
00076   
00077   int nplane = int(HighBin_pl-LowBin_pl+1);
00078   int nstrip = int(HighBin_st-LowBin_st+1);
00079   int totstp = nplane*nstrip;
00080   
00081   fErrArray = new double[totstp*totstp];
00082 
00086 
00087   if(!fCovMat){ //if it doesn't exist, make it and fill it    
00088     MSG("FitShowerEM",Msg::kDebug) << "Setting up Correlation Matrix" << endl;
00089     
00090     fCovMat = new double[720*720];
00091     ifstream infile;
00092     char name[256];
00093     sprintf(name,"BinErrors/CovMat_%iGeV_NoXTalk.dat",int(fInputParams[0]));
00094     infile.open(name);
00095     if(!infile.is_open()) {
00096       //open default
00097       sprintf(name,"BinErrors/CovMat_3GeV_NoXTalk.dat");
00098       infile.open(name);
00099     }
00100     
00101     if(!infile.is_open()) {
00102       MSG("FitShowerEM",Msg::kDebug) 
00103         << "No txt file for correlations found - using identity matrix" << endl;
00104       for(int i=0;i<720;i++){
00105         for(int j=0;j<720;j++) {
00106           if(i==j) fCovMat[i*720+j] = 1;
00107           else fCovMat[i*720+j] = 0;
00108         }
00109       }
00110     }
00111     else {
00112       int a,b;
00113       double c;
00114       while(infile>>a>>b>>c) {
00115         if(c>1e6) fCovMat[a*720+b]=c;
00116         else fCovMat[a*720+b]=0;
00117       }
00118       infile.close();    
00119       MSG("FitShowerEM",Msg::kDebug) << "Read in file " << name << endl;
00120     }
00121   }
00122   
00123 
00124   Double_t SimVtx[3] = {11.5,11.5,0.5};
00125   //fill fErrArray
00126   for(int i=0;i<totstp;i++){
00127     int plane_i = int(LowBin_pl) + i/nstrip;
00128     int strip_i = int(LowBin_st) + i%nstrip;
00129     if(plane_i%2==0) {
00130       strip_i += int(-fInputParams[1] + SimVtx[0]);      
00131     }
00132     else {
00133       strip_i += int(-fInputParams[2] + SimVtx[1]);
00134     }
00135     plane_i += int(-fInputParams[3] + SimVtx[2]);
00136     for(int j=0;j<totstp;j++){
00137       int plane_j = int(LowBin_pl) + j/nstrip;
00138       int strip_j = int(LowBin_st) + j%nstrip;      
00139       if(plane_j%2==0) {
00140         strip_j = int(-fInputParams[1] + SimVtx[0]) + strip_j;
00141       }
00142       else {
00143         strip_j = int(-fInputParams[2] + SimVtx[1]) + strip_j;
00144       }
00145       plane_j += int(-fInputParams[3] + SimVtx[2]);
00146             
00147       if(plane_i>=0&&plane_i<30&&plane_j>=0&&plane_j<30
00148          &&strip_i>=0&&strip_i<24&&strip_j>=0&&strip_j<24){
00149         fErrArray[i*totstp+j] = fCovMat[(plane_i*24+strip_i)*720 + 
00150                                         plane_j*24+strip_j];
00151       }
00152       else { //out of defined region
00153         if(i==j) fErrArray[i*totstp+j] = 1.;  //diagonal terms
00154         else fErrArray[i*totstp+j] = 0;       //off-diagonal
00155       }
00156 
00157       MSG("FitShowerEM",Msg::kVerbose) << "Plane_i: " << plane_i 
00158                                        << " Strip_i: " << strip_i 
00159                                        << "\nPlane_j: " << plane_j 
00160                                        << " Strip_j: " << strip_j
00161                                        << "\nErrArray_ij: " 
00162                                        << fErrArray[i*totstp+j]
00163                                        << endl;
00164     }
00165   }
00166 
00167   return fErrArray;
00168 
00169 }

Generated on Mon Feb 15 11:06:26 2010 for loon by  doxygen 1.3.9.1