00001 #include "mEmcReCalibratorModulev1.h"
00002
00003 #include "emcDataProcessorv2.h"
00004 #include "emcTowerContainer.h"
00005 #include "emcTowerContent.h"
00006 #include "emcNodeHelper.h"
00007 #include "emcBadModulesv1.h"
00008 #include "emcDataError.h"
00009 #include "EmcIndexer.h"
00010
00011 #include "PHNodeIterator.h"
00012 #include "PHDataNode.h"
00013 #include "PHCompositeNode.h"
00014 #include "PHTimeStamp.h"
00015 #include "Event.h"
00016
00017 #include <memory>
00018 #include <cassert>
00019
00020 using namespace std;
00021
00022
00023 namespace
00024 {
00025 Event* getEvent(PHCompositeNode* topNode)
00026 {
00027 PHNodeIterator it(topNode);
00028 PHDataNode<Event>* eventNode =
00029 static_cast<PHDataNode<Event>*>(it.findFirst("PHDataNode","PRDF"));
00030 if (eventNode)
00031 {
00032 return eventNode->getData();
00033 }
00034 return 0;
00035 }
00036 }
00037
00038
00039 mEmcReCalibratorModulev1::mEmcReCalibratorModulev1(int runnumber,
00040 const PHTimeStamp& ts,
00041 bool constantGains)
00042 {
00043 name = "mEmcReCalibratorModulev1";
00044 fDataProcessor = new emcDataProcessorv2(runnumber,ts);
00045 fTimeStamp = new PHTimeStamp(ts);
00046 fBadModules = new emcBadModulesv1(*fTimeStamp);
00047 fConstantGains = constantGains;
00048 fRunNumber = runnumber;
00049 }
00050
00051
00052 mEmcReCalibratorModulev1::~mEmcReCalibratorModulev1()
00053 {
00054 delete fDataProcessor;
00055 delete fTimeStamp;
00056 delete fBadModules;
00057 }
00058
00059
00060 PHBoolean
00061 mEmcReCalibratorModulev1::event(PHCompositeNode* topNode)
00062 {
00063 emcTowerContainer* tc = emcNodeHelper::getObject<emcTowerContainer>
00064 ("emcTowerContainer",topNode);
00065
00066 auto_ptr<emcTowerContainer> pbsc(tc->clone());
00067 auto_ptr<emcTowerContainer> pbgl(tc->clone());
00068 pbsc->Reset();
00069 pbgl->Reset();
00070 for ( size_t i = 0; i < tc->size(); ++i )
00071 {
00072 emcTowerContent* tin = tc->getTower(i);
00073 int towerid = tin->towerid();
00074 if ( EmcIndexer::isPbSc(towerid) )
00075 {
00076 emcTowerContent* tout = pbsc->addTower(pbsc->size(),*tin);
00077 assert(tout);
00078 }
00079 else if ( EmcIndexer::isPbGl(towerid) )
00080 {
00081 emcTowerContent* tout = pbgl->addTower(pbgl->size(),*tin);
00082 assert(tout);
00083 }
00084 }
00085 assert( pbsc->size() + pbgl->size() == tc->size() );
00086 tc->Reset();
00087
00088 bool ok = true;
00089
00090 if ( !fBadModules)
00091 {
00092 fBadModules = new emcBadModulesv1(*fTimeStamp);
00093 }
00094
00095 if (ok)
00096 {
00097 ok = fDataProcessor->toADCandTDC(pbsc.get(),pbgl.get(),*fBadModules);
00098 }
00099
00100 if (ok)
00101 {
00102 time_t thetime;
00103 thetime = fTimeStamp->getTics();
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113 ok = fDataProcessor->calibrate(pbsc.get(),pbgl.get(),thetime);
00114 }
00115
00116 if (ok)
00117 {
00118
00119 int out=0;
00120 for ( size_t i = 0; i < pbsc->size(); ++i )
00121 {
00122 emcTowerContent* tin = pbsc->getTower(i);
00123 if ( tin->ADC() > 10 &&
00124 !(tin->DataError() & emcDataError::CHANNEL_DISABLED()) )
00125 {
00126 emcTowerContent* tout = tc->addTower(out,*tin);
00127 assert(tout!=0);
00128 ++out;
00129 }
00130 }
00131
00132 for ( size_t i = 0; i < pbgl->size(); ++i )
00133 {
00134 emcTowerContent* tin = pbgl->getTower(i);
00135 if ( tin->ADC() > 10 &&
00136 !(tin->DataError() & emcDataError::CHANNEL_DISABLED()) )
00137 {
00138 emcTowerContent* tout = tc->addTower(out,*tin);
00139 assert(tout!=0);
00140 ++out;
00141 }
00142 }
00143 return true;
00144 }
00145 else
00146 {
00147 tc->Reset();
00148 return false;
00149 }
00150 }