mEmcTOFCorr6Module.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 : mEmcTOFCorr6Module
00008 //
00009 // Ken Oyama, CNS, University of Tokyo.
00010 //          Modified by Hisayuki Torii Dec 2000
00011 //          Modified for V05 production by H.Torii Aug/15/2001
00012 //          Modified for Run2V02 production by H.Torii Feb/1/2002
00013 //          Modified for Run03V01 production by Peter Tarjan July/2/2003
00014 //          Modified for Run04 200 GeV Au-Au production by Peter Tarjan May/28/2004
00015 //-------------------------------------------------------------------------
00016 
00017 
00018 #include "mEmcTOFCorr6Module.h"
00019 #include "PdbBankManager.hh"
00020 #include "PdbApplication.hh"
00021 #include "PdbCalBank.hh"
00022 #include "recoConsts.h"
00023 #include "EmcIndexer.h"
00024 #include "emcDBMS.h"
00025 #include "emcTowerContainer.h"
00026 #include "emcTowerContent.h"
00027 
00028 #include "PHIODataNode.h"
00029 #include "PHNodeIterator.h"
00030 
00031 #include <iostream>
00032 using namespace std;
00033 
00034 
00035 //-------------------------------------------------------------------------
00036 
00037 mEmcTOFCorr6Module::mEmcTOFCorr6Module()
00038 { 
00039   
00040   isvalid =0;  // we mark this class as unusable
00041 
00042 };
00043 
00044 //-------------------------------------------------------------------------
00045 
00046 mEmcTOFCorr6Module* mEmcTOFCorr6Module::instance()
00047 { 
00048   static mEmcTOFCorr6Module* instance_ = new mEmcTOFCorr6Module;
00049   return instance_;
00050 };
00051 
00052 //-------------------------------------------------------------------------
00053 
00054 
00055 void mEmcTOFCorr6Module::readDataFromDB(const int run_number)
00056 {
00057   PdbBankManager *bankManager = PdbBankManager::instance();  
00058 
00059   if (!bankManager)
00060     {
00061       std::cerr << PHWHERE << " Can not get DMBS=" 
00062                 << emcDBMS::asString()
00063                 << std::endl;
00064       return;
00065     }
00066 
00067   PdbApplication *application = bankManager->getApplication();  
00068   PdbBankID bankID(0);
00069 
00070   // read in every correction even though not all of them
00071   // will be applied
00072   if (application->startRead()) 
00073     {
00074       PdbCalBank *emcBank;
00075 //      PdbEmcT0Sector *sector;
00076 //      PdbEmcT0Tower  *tower;
00077 //      PdbEmcT0Sector *sector_vd;
00078       
00079 // fetch sector corrections
00080       char *calibname = "calib.emc.T0_Sector";
00081        emcBank = bankManager->fetchBank("PdbEmcT0SectorBank", bankID, calibname, run_number);
00082   
00083       if (emcBank)
00084         {
00085           TheSector = *( (PdbEmcT0Sector *)( & emcBank->getEntry(0) ) );
00086           cout << "<I> mEmcTOFCorr6Module::readDataFromObjy(): Sector corrections read in." << endl;
00087           delete emcBank;
00088           isvalid = 1;
00089         }      
00090 
00091 // fetch tower corrections      
00092       calibname = "calib.emc.T0_Tower";     
00093       emcBank = bankManager->fetchBank("PdbEmcT0TowerBank", bankID, calibname, run_number);
00094       if(emcBank)
00095         {
00096           TheTower = *( (PdbEmcT0Tower *)( & emcBank->getEntry(0) ) );
00097           cout << "<I> mEmcTOFCorr6Module::readDataFromDB(): Tower corrections read in." << endl;
00098           delete emcBank;
00099           isvalid = 1;
00100         }
00101 
00102 // fetch global sector corrections
00103       calibname = "calib.emc.VD_T0Sector";
00104       emcBank = bankManager->fetchBank("PdbEmcT0SectorBank", bankID, calibname, run_number);
00105       if (emcBank)
00106         {
00107           TheSectorVd = *( (PdbEmcT0Sector *)( & emcBank->getEntry(0) ) );
00108           cout << "<I> mEmcTOFCorr6Module::readDataFromDB(): VD corrections read in." << endl;
00109           delete emcBank;
00110           isvalid = 1;
00111         }      
00112      
00113       application->commit();
00114     }
00115 
00116   
00117 }
00118 //-------------------------------------------------------------------------
00119 //
00120 // Find index in the run-by-run table and return total correction includes tower-by-tower correction.
00121 //
00122 float mEmcTOFCorr6Module::get_correction( int iarm, int isect, int iz, int iy )
00123 {
00124  
00125   // the sectorT0 correction are not yet determined at this point
00126 //    cout 
00127 //      << iarm << ".." << isect << ".." << iy << ".." << iz << "......" 
00128 //      << "....." << TheSectorVd.getSectorT0Correction(iarm,isect)
00129 //      << "....." << TheTower.getTwrT0Correction(iarm, isect, iy, iz)
00130 //      << endl;
00131     return ( TheSector.getSectorT0Correction(iarm,isect) +  TheTower.getTwrT0Correction(iarm, isect, iy, iz) + TheSectorVd.getSectorT0Correction(iarm,isect));
00132 }
00133 
00134 //-------------------------------------------------------------------------
00135 PHBoolean mEmcTOFCorr6Module::eventFirst(PHCompositeNode *root)
00136 {
00137   cout<<" mEmcTOFCorr6Module::eventFirst() This is obsolete method.. "<<endl;
00138   return false;
00139 };
00140 //-------------------------------------------------------------------------
00141 PHBoolean mEmcTOFCorr6Module::event(PHCompositeNode *topNode) 
00142 {  
00143   int irun;
00144   float tof,tofcorr,energy;
00145 
00146   if (! isvalid) return 0;
00147 
00148   PHNodeIterator i(topNode);  
00149   recoConsts *rc = recoConsts::instance();
00150   irun = rc->get_IntFlag("RUNNUMBER");
00151   
00152 
00153   PHIODataNode<PHObject>* emcTowerContainerNode = 
00154     (PHIODataNode<PHObject>*)i.findFirst("PHIODataNode","emcTowerContainer");
00155 
00156   if ( !emcTowerContainerNode ) 
00157     {
00158       cerr << __FILE__ << ":" << __LINE__ << " cannot find emcTowerContainer "
00159            << "node." << endl;
00160       return false;
00161     }
00162 
00163   emcTowerContainer* towers = 
00164     static_cast<emcTowerContainer*>(emcTowerContainerNode->getData());
00165   if (!towers)
00166     {
00167       cerr << __FILE__ << ":" << __LINE__ << " cannot find emcTowerContainer "
00168            << "object." << endl;
00169       return false;
00170     }
00171 
00172   if ( !towers->isValid() ) return false;
00173 
00174 
00175   for ( size_t i = 0; i < towers->size(); ++i ) 
00176     {
00177       emcTowerContent* t = towers->getTower(i);
00178       int towerID = t->TowerID();
00179       int iarm,isect,iy,iz;
00180       float corr;
00181       
00182       EmcIndexer::TowerLocation(towerID,iarm,isect,iy,iz);
00183 
00184 
00185         if( iarm >= 0 && iarm < 2 && isect >= 0 && isect < 4 &&
00186           iz >= 0 && iz < 96 && iy >= 0 && iy < 48 )
00187         {
00188           tof = t->ToF();
00189           energy = t->Energy();
00190           
00191           corr = get_correction(iarm,isect,iz,iy);
00192           tofcorr = tof - corr;
00193 
00194           // write back the modified time
00195           t->SetToF(tofcorr);
00196           
00197         }
00198         else 
00199         {
00200           cout << " mEmcTOFCorr6Module:: arm(" << iarm << "),sect(" << isect
00201                <<  "),z(" << iz << "),y(" << iy << ") index are out of range." << endl;
00202         }
00203         
00204     }
00205 
00206   return true;
00207   
00208 }