00001 //#define USE_PRINT_OUT 00002 00003 #include "PlotTAP_Energy.h" 00004 #include <iostream> 00005 #include <string> 00006 #include <sstream> 00007 #include <map> 00008 //#include <utility> 00009 //#include <algorithm> 00010 #include <cmath> 00011 00012 #include "TAnalysedPulse.h" 00013 //#include "TDetectorPulse.h" 00014 #include "RegisterModule.inc" 00015 #include "definitions.h" 00016 #include "SetupNavigator.h" 00017 //#include "debug_tools.h" 00018 00019 using std::string; 00020 using std::map; 00021 using std::vector; 00022 using std::pair; 00023 00024 extern SourceAnalPulseMap gAnalysedPulseMap; 00025 00026 PlotTAP_Energy::PlotTAP_Energy(modules::options* opts) : 00027 BaseModule("PlotTAP_Energy",opts) { 00028 } 00029 00030 PlotTAP_Energy::~PlotTAP_Energy(){ 00031 } 00032 00033 int PlotTAP_Energy::BeforeFirstEntry(TGlobalData *gData, const TSetupData *gSetup){ 00034 return 0; 00035 } 00036 00037 int PlotTAP_Energy::ProcessEntry(TGlobalData *gData, const TSetupData* gSetup){ 00038 00039 // Loop over each TAP list 00040 for (SourceAnalPulseMap::const_iterator i_det = gAnalysedPulseMap.begin(); 00041 i_det != gAnalysedPulseMap.end(); 00042 i_det++) { 00043 00044 const std::string& detname = i_det->first.str(); 00045 std::string keyname = i_det->first.str() + GetName(); 00046 00047 // Create the histogram if it's not been created yet 00048 if ( fEnergyPlots.find(keyname) == fEnergyPlots.end() ) { 00049 00050 // hEnergy 00051 std::string histname = "h" + detname + "_Energy"; 00052 std::stringstream histtitle; 00053 histtitle<<"Energy of pulses from source " << i_det->first; 00054 histtitle<<" for run "<<SetupNavigator::Instance()->GetRunNumber(); 00055 int n_bits = gSetup->GetNBits(gSetup->GetBankName(i_det->first.Channel().str())); 00056 const double max_adc_value = std::pow(2, n_bits); 00057 double gain = 1; 00058 double offset= 0; 00059 try{ 00060 gain = SetupNavigator::Instance()->GetAdcToEnergyGain( i_det->first.Channel()); 00061 offset= SetupNavigator::Instance()->GetAdcToEnergyConstant(i_det->first.Channel()); 00062 }catch( Except::InvalidDetector& e){}; 00063 TH1F* hEnergy = new TH1F(histname.c_str(), histtitle.str().c_str(), max_adc_value,0,gain*max_adc_value + offset); 00064 hEnergy->GetXaxis()->SetTitle("Energy (KeV)"); 00065 hEnergy->GetYaxis()->SetTitle("Arbitrary Units"); 00066 fEnergyPlots[keyname] = hEnergy; 00067 } 00068 00069 const AnalysedPulseList *pulses = &i_det->second; 00070 //if(Debug() && pulses->empty()) DEBUG_PREFIX<<" no pulses to fill for "<<i_det->first<<std::endl; 00071 00072 for (AnalysedPulseList::const_iterator pulseIter = pulses->begin(); pulseIter != pulses->end(); ++pulseIter) { 00073 double Energy = (*pulseIter)->GetEnergy(); 00074 fEnergyPlots[keyname]->Fill(Energy); 00075 00076 } // end loop through pulses 00077 00078 } // end loop through detectors 00079 return 0; 00080 } 00081 00082 ALCAP_REGISTER_MODULE(PlotTAP_Energy)