mEmcTOFCorr4Module.C

Go to the documentation of this file.
00001 //-------------------------------------------------------------------------
00002 //
00003 // 
00004 // Package: offline/packages/emc
00005 // 
00006 // Copyright (C) PHENIX collaboration, 2000 
00007 //
00008 // Implementation of class : mEmcTOFCorr3Module
00009 //
00010 // Ken Oyama, CNS, University of Tokyo.
00011 //          Modified by Hisayuki Torii Dec 2000
00012 //          Modified for V05 production by H.Torii Aug/15/2001
00013 //          Modified for Run2V02 production by H.Torii Feb/1/2002
00014 //-------------------------------------------------------------------------
00015 #include "mEmcTOFCorr4Module.h"
00016 #include "dEmcCalibTower.h"
00017 #include "dEmcCalibTowerWrapper.h"
00018 #include "emcCalibrator.h"
00019 #include "emcRawDataCalibrator.h"
00020 #include "emcRawDataAccessor.h"
00021 #include "emcDataManager.h"
00022 #include "emcPedestals.h"
00023 #include "PdbBankManager.hh"
00024 #include "PdbApplication.hh"
00025 #include "PdbBankID.hh"
00026 #include "PdbCalBank.hh"
00027 #include "emcDBMS.h"
00028 #include "RunHeader.h"
00029 
00030 #include "PHNode.h"
00031 #include "PHIODataNode.h"
00032 #include "PHNodeIterator.h"
00033 #include "PHDataNodeIterator.h"
00034 
00035 #include <iostream>
00036 #include <fstream>
00037 #include <cassert>
00038 
00039 using namespace std;
00040 
00041 typedef PHIODataNode <RunHeader> RunHeaderNode_t;
00042 
00043 mEmcTOFCorr4Module* mEmcTOFCorr4Module::_instance = NULL;
00044 
00045 //-------------------------------------------------------------------------
00046 
00047 mEmcTOFCorr4Module::mEmcTOFCorr4Module()
00048 { 
00049 
00050   isvalid =0;  // we mark this class as unusable
00051 
00052 };
00053 
00054 //-------------------------------------------------------------------------
00055 
00056 mEmcTOFCorr4Module* mEmcTOFCorr4Module::instance()
00057 {
00058   if (! _instance )
00059     {
00060       _instance = new mEmcTOFCorr4Module();
00061     }
00062   return _instance;
00063 };
00064 
00065 //-------------------------------------------------------------------------
00066 
00067 
00068 void mEmcTOFCorr4Module::readDataFromDB(const int run_number)
00069 {
00070 
00071   int run = run_number;
00072 
00073   PdbBankManager *bankManager = PdbBankManager::instance();
00074   assert(bankManager!=0);
00075 
00076   PdbApplication *application = bankManager->getApplication();
00077   PdbBankID bankID(0);
00078 
00079   PdbCalBank *emcBank;
00080 
00081 
00082   if (application->startRead())
00083     {
00084       PdbEmcT0Sector *sector;
00085       PdbEmcT0Tower *tower;
00086 
00087       char *calibname = "calib.emc.T0_Sector";
00088 
00089       emcBank = bankManager->fetchClosestBank("PdbEmcT0SectorBank", bankID, calibname, run);
00090 
00091       if (emcBank)
00092         {
00093           sector = ( PdbEmcT0Sector*) & (emcBank->getEntry(0));
00094           delete emcBank;
00095         }
00096       else
00097         {
00098           sector = new PdbEmcT0Sector();
00099         }
00100 
00101       calibname = "calib.emc.T0_Tower";
00102       PdbCalBank *emcBank = bankManager->fetchBank("PdbEmcT0TowerBank", bankID, calibname, run_number);
00103 
00104       if (emcBank)
00105         {
00106           tower = ( PdbEmcT0Tower*) & (emcBank->getEntry(0));
00107           delete emcBank;
00108         }
00109       else
00110         {
00111           tower = new PdbEmcT0Tower();
00112         }
00113 
00114       TheTower = *tower;
00115       TheSector = *sector;
00116       isvalid = 1;         //ok, we are usable now
00117 
00118       application->commit();
00119     }
00120 }
00121 //-------------------------------------------------------------------------
00122 //
00123 // Find index in the run-by-run table and return total correction includes tower-by-tower correction.
00124 //
00125 float mEmcTOFCorr4Module::get_correction( int iarm, int isect, int iz, int iy )
00126 {
00127  
00128   return ( TheSector.getSectorT0Correction(iarm,isect) + TheTower.getTwrT0Correction(iarm, isect, iy, iz) );
00129 
00130 }
00131 
00132 //-------------------------------------------------------------------------
00133 PHBoolean mEmcTOFCorr4Module::eventFirst(PHCompositeNode *root)
00134 {
00135   cout<<" mEmcTOFCorr4Module::eventFirst() This is obsolete method.. "<<endl;
00136   return false;
00137 };
00138 //-------------------------------------------------------------------------
00139 PHBoolean mEmcTOFCorr4Module::event(PHCompositeNode *root) 
00140 {  
00141   int iarm, isect, iy, iz;
00142   float tof,tofcorr,energy;
00143 
00144   if (! isvalid) return 0;
00145 
00146   PHNodeIterator i(root);  
00147 
00148   int irun = -9999;
00149   PHTypedNodeIterator<RunHeader> runiter(root);
00150   RunHeaderNode_t *RunHeaderNode = runiter.find("RunHeader");
00151   if (RunHeaderNode)
00152     {
00153       irun = RunHeaderNode->getData()->get_RunNumber();
00154     }
00155   else
00156     {
00157       cout << PHWHERE << "RunHeader Node missing" << endl;
00158     }
00159 
00160   // === Patch dEmcCalibTower ===
00161   PHIODataNode<PHTable>* dEmcCalibTowerNode = (PHIODataNode<PHTable>*)i.findFirst("PHIODataNode","dEmcCalibTower");
00162   dEmcCalibTowerWrapper * dEmcCalibTower = static_cast<dEmcCalibTowerWrapper*>(dEmcCalibTowerNode->getData());
00163     
00164   for( size_t j = 0 ; j < dEmcCalibTower->RowCount(); j++) 
00165     {
00166       iarm = dEmcCalibTower->get_arm(j);
00167       isect = dEmcCalibTower->get_sector(j);
00168       iy   = dEmcCalibTower->get_ind(1,j);
00169       iz   = dEmcCalibTower->get_ind(0,j);
00170       tof = dEmcCalibTower->get_tof(j);
00171       energy = dEmcCalibTower->get_ecal(j);
00172       tofcorr = tof;
00173 
00174 
00175       if( iarm >= 0 && iarm < 2 && isect >= 0 && isect < 4 &&
00176           iz >= 0 && iz < 96 && iy >= 0 && iy < 48 )
00177         {
00178           tofcorr *= TheTower.getLeastCountCorrection(iarm, isect, iy, iz);
00179           
00180           tofcorr -= TheTower.getSlewingCorrection(iarm, isect, iy, iz) / energy;
00181           
00182           tofcorr += get_correction(iarm,isect,iz,iy);
00183 
00184           dEmcCalibTower->set_tof( j ,tofcorr);
00185         } 
00186       else 
00187         {
00188           cout << " mEmcTOFCorr4Module:: arm(" << iarm << "),sect(" << isect
00189                <<  "),z(" << iz << "),y(" << iy << ") index are out of range." << endl;
00190         }
00191     }
00192   
00193 
00194   return true;
00195   
00196 }
00197