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