00001 #include "StMuDSTMaker/COMMON/StMuDstMaker.h"
00002 #include "StEmcSimulatorMaker/StEmcSimulatorMaker.h"
00003 #include "St_db_Maker/St_db_Maker.h"
00004
00005 #include "TList.h"
00006 #include "TTree.h"
00007
00008 #include "StGammaScheduleMaker.h"
00009
00010 ClassImp(StGammaScheduleMaker);
00011
00013
00015 StGammaScheduleMaker::StGammaScheduleMaker(const char *name): StMaker(name)
00016 {}
00017
00019
00021 void StGammaScheduleMaker::addTimestamp(int date, int time, double weight)
00022 {
00023
00024 stamp currentStamp;
00025 currentStamp.date = date;
00026 currentStamp.time = time;
00027 currentStamp.weight = weight;
00028
00029 mStamps.push_back(currentStamp);
00030
00031 }
00032
00034
00035
00037 void StGammaScheduleMaker::rearrange()
00038 {
00039
00040 StMaker *simulator = GetMakerInheritsFrom("StEmcSimulatorMaker");
00041 if(!simulator)
00042 {
00043 LOG_WARN << "rearrange() - No StEmcSimulatorMaker found in the chain!" << endm;
00044 return;
00045 }
00046
00047 TList *makerList = this->GetParentChain()->GetMakeList();
00048
00049 makerList->Remove(dynamic_cast<StMaker*>(this));
00050 makerList->AddBefore(simulator, dynamic_cast<StMaker*>(this));
00051
00052 }
00053
00055
00057 Int_t StGammaScheduleMaker::Init()
00058 {
00059
00060
00061 StMuDstMaker *muDstMaker = dynamic_cast<StMuDstMaker*>(GetMakerInheritsFrom("StMuDstMaker"));
00062 if(!muDstMaker)
00063 {
00064 LOG_WARN << "Init() - No StMuDstMaker found in the chain!" << endm;
00065 return kStWarn;
00066 }
00067
00068 mTotalEvents = muDstMaker->tree()->GetEntries();
00069 mCurrentEvent = 0;
00070 mStampIndex = 0;
00071
00072 if(mStamps.size())
00073 {
00074
00075 LOG_INFO << "Init() - Distributing status tables across " << mTotalEvents << " events" << endm;
00076
00077
00078 double totalWeight = 0;
00079
00080 vector<stamp>::iterator it;
00081
00082 for(it = mStamps.begin(); it != mStamps.end(); ++it)
00083 {
00084 totalWeight += (*it).weight;
00085 }
00086
00087
00088 double usedEvents = 0;
00089 for(it = mStamps.begin(); it != mStamps.end(); ++it)
00090 {
00091 double newEvents = ((*it).weight / totalWeight) * mTotalEvents;
00092 (*it).event = usedEvents;
00093 usedEvents += newEvents;
00094 }
00095
00096 LOG_INFO << "Init() - Using the timestamps" << endm;
00097 LOG_INFO << "Init() - \tDate\t\tTime\tWeight\tInitial Event" << endm;
00098 for(it = mStamps.begin(); it != mStamps.end(); ++it)
00099 {
00100 LOG_INFO << "Init() - \t" << it->date << "\t" << it->time << "\t" << it->weight << "\t" << it->event << endm;
00101 }
00102
00103 }
00104 else
00105 {
00106 LOG_INFO << "Init() - Using the default timestamp" << endm;
00107 }
00108
00109 return StMaker::Init();
00110
00111 }
00112
00113
00115
00117 Int_t StGammaScheduleMaker::Make()
00118 {
00119
00120
00121 St_db_Maker *database = dynamic_cast<St_db_Maker*>(GetMakerInheritsFrom("St_db_Maker"));
00122 if(!database)
00123 {
00124 LOG_WARN << "Make() - No St_db_Maker found in the chain!" << endm;
00125 return kStWarn;
00126 }
00127
00128
00129 vector<stamp>::iterator it;
00130
00131 for(it = mStamps.begin(); it != mStamps.end(); ++it)
00132 {
00133
00134
00135
00136 double diff = mCurrentEvent - it->event;
00137 if(!mCurrentEvent) diff = 0.5;
00138
00139 if(diff > 0 && diff < 1)
00140 {
00141 LOG_INFO << "Make() - Setting time stamp to Date = " << it->date << ", Time = " << it->time
00142 << " (Index " << mStampIndex + 1 << ") at event " << mCurrentEvent + 1 << endm;
00143 database->SetDateTime(it->date, it->time);
00144 ++mStampIndex;
00145 break;
00146 }
00147
00148 }
00149
00150 ++mCurrentEvent;
00151
00152 return kStOk;
00153
00154 }