mEmcMIPCorrModule.C

Go to the documentation of this file.
00001 //-------------------------------------------------------------------------
00002 // 
00003 // Package: offline/packages/emc
00004 // 
00005 // Copyright (C) PHENIX collaboration, 2000 
00006 //
00007 // Implementation of class : mEmcMIPCorrModule.h
00008 //
00009 // Hisayuki Torii
00010 //-------------------------------------------------------------------------
00011 #include "mEmcMIPCorrModule.h"
00012 #include "dEmcCalibTower.h"
00013 #include "dEmcCalibTowerWrapper.h"
00014 #include "PHNode.h"
00015 #include "PHIODataNode.h"
00016 #include "PHNodeIterator.h"
00017 #include "PHDataNodeIterator.h"
00018 
00019 #include <iostream>
00020 #include <fstream>
00021 
00022 using namespace std;
00023 
00024 mEmcMIPCorrModule* mEmcMIPCorrModule::_instance = NULL;
00025 //-------------------------------------------------------------------------
00026 mEmcMIPCorrModule::mEmcMIPCorrModule()
00027 { 
00028   // default ctor
00029   fVerbose = 0 ;
00030   int isect,iz,iy;
00031   isect = 8;
00032   while( isect-- ){
00033     iz = 96;
00034     while( iz-- ){
00035       iy = 48;
00036       while( iy-- ){
00037         _corrfact[isect][iz][iy] = 1;
00038         _corrfact_err[isect][iz][iy] = 0;
00039         _corrfact_stat[isect][iz][iy] = 0;
00040       }
00041     }
00042   }
00043 }
00044 //-------------------------------------------------------------------------
00045 mEmcMIPCorrModule* mEmcMIPCorrModule::instance(char* filename)
00046 { 
00047   if(! _instance )
00048     _instance = new mEmcMIPCorrModule();
00049   _instance->readfile(filename);
00050   return _instance;
00051 }
00052 //-------------------------------------------------------------------------
00053 mEmcMIPCorrModule* mEmcMIPCorrModule::instance()
00054 { 
00055   if(! _instance )
00056     _instance = new mEmcMIPCorrModule();
00057   return _instance;
00058 }
00059 //-------------------------------------------------------------------------
00060 void mEmcMIPCorrModule::readfile(char* filename)
00061 { 
00062   int isect,ismz,ismy,iz,iy,status,towerid;
00063   float correction,error_correction;
00064   char tmpline[128];
00065   char tmpc;
00066   ifstream fin(filename);
00067   if(!fin) {
00068     cerr<<" mEmcCIPcorrModule:: Can't open file: "<<filename<<endl;
00069     return;
00070   }
00071   fin.getline(tmpline,128);
00072   sscanf(tmpline,"#Sector %d MIP Correction table",&isect);
00073   if( isect < 0 || isect > 8 ) {
00074     cerr<<" Error:: mEmcMIPCorrModule can't open the file "<<filename<<endl;
00075     return;
00076   }
00077   cout<<" mEmcMIPCorrModule read correction table of sector "<<isect<<endl;
00078   while( fin.get(tmpc) && tmpc != '\n' ); // Skip 1 line
00079   while( fin.get(tmpc) && tmpc != '\n' ); // Skip 1 line
00080 
00081   while( fin>>ismz>>ismy>>iz>>iy>>towerid>>correction>>error_correction>>status ){
00082     int itmpz = (isect>=6 ? 6*ismz+iz : 12*ismz+iz );
00083     int itmpy = (isect>=6 ? 4*ismy+iy : 12*ismy+iy );
00084     _corrfact[isect][itmpz][itmpy] = correction;
00085     _corrfact_err[isect][itmpz][itmpy] = error_correction;
00086     _corrfact_stat[isect][itmpz][itmpy] = status;
00087   }
00088   return;
00089 }
00090 //-------------------------------------------------------------------------
00091 void mEmcMIPCorrModule::print()
00092 { 
00093   int isect,ismz,ismy,iz,iy;
00094   isect = 8;
00095   while( isect-- ){
00096     ismz = (isect>=6 ? 16 : 6 );
00097     while( ismz-- ){
00098       ismy = (isect>=6 ? 12 : 3 );
00099       while( ismy-- ){
00100         iz = (isect>=6 ? 4*ismz : 12*ismz );
00101         iy = (isect>=6 ? 4*ismy : 12*ismy );
00102         cout<<" isect, iz, iy = "<<isect<<","<<iz<<","<<iy<<"   : "<<_corrfact[isect][iz][iy]<<endl;
00103       }
00104     }
00105   }
00106   return;
00107 }
00108 //-------------------------------------------------------------------------
00109 PHBoolean mEmcMIPCorrModule::event(PHCompositeNode *root) 
00110 {  
00111   int arm,sect,yrow,zrow;
00112   int irow = 0 ;
00113   
00114   if( fVerbose > 0 )
00115     cout << "mEmcMIPCorrModule >>>  Starting..." << endl;
00116   
00117   // Set up dEmcCalibTower
00118   PHNodeIterator i(root);
00119   PHIODataNode<PHTable>* dEmcCalibTowerNode = (PHIODataNode<PHTable>*)i.findFirst("PHIODataNode","dEmcCalibTower");
00120   dEmcCalibTowerWrapper * dEmcCalibTower = static_cast<dEmcCalibTowerWrapper*>(dEmcCalibTowerNode->getData());
00121 
00122   irow = dEmcCalibTower->RowCount();
00123   while( irow -- ){
00124     arm = dEmcCalibTower->get_arm(irow);
00125     sect = dEmcCalibTower->get_sector(irow);
00126     zrow = dEmcCalibTower->get_ind(0,irow);
00127     yrow = dEmcCalibTower->get_ind(1,irow);
00128     if( arm == 1 )
00129       if( sect == 0 || sect == 1 ) // PbGl E0,E1
00130         sect = sect + 6;
00131       else
00132         sect = sect + 4;           // PbSc E2,E3
00133     // Apply MIP correction
00134     if( _corrfact_stat[sect][zrow][yrow] ){
00135       dEmcCalibTower->set_ecal( irow,  dEmcCalibTower->get_ecal(irow) * _corrfact[sect][zrow][yrow] );
00136     }
00137     //
00138   }
00139 #ifdef SKIP_CLUSTER
00140   irow = dEmcClusterLocalExt->RowCount();
00141   while( irow -- ){
00142     arm = dEmcClusterLocalExt->get_arm(irow);
00143     sect = dEmcClusterLocalExt->get_sector(irow);
00144     zrow = dEmcClusterLocalExt->get_ind(0,irow);
00145     yrow = dEmcClusterLocalExt->get_ind(1,irow);
00146     if( arm == 1 )
00147       if( sect == 0 || sect == 1 ) // PbGl E0,E1
00148         sect = sect + 6;
00149       else
00150         sect = sect + 4;           // PbSc E2,E3
00151     // Apply MIP correction
00152     if( _corrfact_stat[sect][zrow][yrow] ){
00153       dEmcClusterLocalExt->set_e( irow, dEmcClusterLocalExt->get_e(irow) * _corrfact[sect][zrow][yrow] );
00154       dEmcClusterLocalExt->set_ecore( irow, dEmcClusterLocalExt->get_ecore(irow) * _corrfact[sect][zrow][yrow] );
00155       dEmcClusterLocalExt->set_ecorr( irow, dEmcClusterLocalExt->get_ecorr(irow) * _corrfact[sect][zrow][yrow] );
00156       dEmcClusterLocalExt->set_ecent( irow, dEmcClusterLocalExt->get_ecent(irow) * _corrfact[sect][zrow][yrow] );
00157     }
00158     //
00159   }
00160 #endif
00161   return true;
00162   
00163 }
00164 //-------------------------------------------------------------------------