00001 #ifndef mcreweight_cxx 00002 #define mcreweight_cxx 00003 #include "MCReweight/MCReweight.h" 00004 #include "MessageService/MsgService.h" 00005 #include <cassert> 00006 00007 CVSID("$Id: MCReweight.cxx,v 1.5 2005/04/13 19:17:03 cbs Exp $"); 00008 00009 MCReweight* MCReweight::fgInstance = 0; 00010 00011 //***************************************************** 00012 MCReweight::MCReweight() 00013 { 00014 fWeightCalculators.clear(); 00015 } 00016 00017 //***************************************************** 00018 MCReweight::~MCReweight() 00019 { 00020 MSG("MCReweight",Msg::kInfo) << "Closing down MCReweight object" 00021 << endl; 00022 } 00023 00024 //***************************************************** 00025 MCReweight& MCReweight::Instance() 00026 { 00027 static Cleaner cleaner; 00028 00029 //all copied from Calibrator package... 00030 if (!fgInstance) { 00031 cleaner.UseMe(); // dummy call to quiet compiler warnings 00032 fgInstance = new MCReweight(); 00033 if(!fgInstance){ 00034 MSG("MCReweight", Msg::kError) 00035 << "No MCReweight Instance - fatal." << endl; 00036 assert(fgInstance); // Kill job is there is no instance 00037 } 00038 } 00039 return *fgInstance; 00040 } 00041 00042 //***************************************************** 00043 double MCReweight::ComputeWeight(Registry *event, Registry *rwtconfig){ 00044 00045 std::vector<WeightCalculator*>::iterator beg = fWeightCalculators.begin(); 00046 std::vector<WeightCalculator*>::iterator end = fWeightCalculators.end(); 00047 double totalWeight = 1; 00048 while(beg!=end) { 00049 (*beg)->SetReweightConfig(rwtconfig); 00050 totalWeight *= (*beg)->GetWeight(event); 00051 beg++; 00052 } 00053 return totalWeight; 00054 } 00055 00056 //***************************************************** 00057 double MCReweight::ComputeWeight(MCEventInfo *event, NuParent *parent, 00058 Registry *rwtconfig){ 00059 00060 std::vector<WeightCalculator*>::iterator beg = fWeightCalculators.begin(); 00061 std::vector<WeightCalculator*>::iterator end = fWeightCalculators.end(); 00062 double totalWeight = 1; 00063 while(beg!=end) { 00064 (*beg)->SetReweightConfig(rwtconfig); 00065 totalWeight *= (*beg)->GetWeight(event,parent); 00066 beg++; 00067 } 00068 return totalWeight; 00069 } 00070 00071 //***************************************************** 00072 void MCReweight::AddWeightCalculator(WeightCalculator *wc){ 00073 00074 std::vector<WeightCalculator*>::iterator beg = fWeightCalculators.begin(); 00075 std::vector<WeightCalculator*>::iterator end = fWeightCalculators.end(); 00076 while(beg!=end){ 00077 if((*beg)->GetName()==wc->GetName()){ 00078 MSG("MCReweight", Msg::kError) 00079 << "Attempting to add " << wc->GetName() << " more than once! " 00080 << "This is not a good idea, so not doing it." 00081 << endl; 00082 return; 00083 } 00084 beg++; 00085 } 00086 wc->SetStandardConfig(&fStandardConfig); 00087 fWeightCalculators.push_back(wc); 00088 00089 } 00090 00091 //***************************************************** 00092 void MCReweight::ClearWeightCalculators(){ 00093 00094 fWeightCalculators.clear(); 00095 00096 } 00097 00098 //***************************************************** 00099 void MCReweight::ResetAllReweightConfigs() { 00100 std::vector<WeightCalculator*>::iterator beg = fWeightCalculators.begin(); 00101 std::vector<WeightCalculator*>::iterator end = fWeightCalculators.end(); 00102 while(beg!=end){ 00103 (*beg)->ReweightConfigReset(); 00104 beg++; 00105 } 00106 } 00107 00108 //***************************************************** 00109 void MCReweight::SetStandardConfig(Registry *config) { 00110 if(!config) return; 00111 fStandardConfig = *config; 00112 std::vector<WeightCalculator*>::iterator beg = fWeightCalculators.begin(); 00113 std::vector<WeightCalculator*>::iterator end = fWeightCalculators.end(); 00114 while(beg!=end){ 00115 (*beg)->SetStandardConfig(&fStandardConfig); 00116 beg++; 00117 } 00118 } 00119 00120 //***************************************************** 00121 void MCReweight::PrintReweightConfig(ostream & stream) { 00122 std::vector<WeightCalculator*>::iterator beg = fWeightCalculators.begin(); 00123 std::vector<WeightCalculator*>::iterator end = fWeightCalculators.end(); 00124 while(beg!=end){ 00125 (*beg)->PrintReweightConfig(stream); 00126 beg++; 00127 } 00128 } 00129 #endif
1.3.9.1