00001 #include "IslandAmplitude.h"
00002 #include "RegisterModule.inc"
00003 #include "TGlobalData.h"
00004 #include "TSetupData.h"
00005 #include "ModulesOptions.h"
00006 #include "definitions.h"
00007 #include "TMath.h"
00008
00009 #include <iostream>
00010 #include <utility>
00011 #include <algorithm>
00012 using std::cout;
00013 using std::endl;
00014
00015
00016
00017
00019
00020 IslandAmplitude::IslandAmplitude(modules::options* opts)
00021 : BaseModule("IslandAmplitude",opts)
00022 {
00023
00024 }
00025
00027
00028 IslandAmplitude::~IslandAmplitude() { }
00029
00031
00032
00033
00034
00035 int IslandAmplitude::BeforeFirstEntry(TGlobalData* data,const TSetupData *setup)
00036 {
00037
00038 if(Debug()){
00039 cout<<"-----IslandAmplitude::BeforeFirstEntry(): I'm debugging!"<<endl;
00040
00041 }
00042
00043 fNProcessed = 0;
00044
00045 StringPulseIslandMap& islands = data->fPulseIslandToChannelMap;
00046
00047
00048
00049 for(StringPulseIslandMap::iterator mIt = islands.begin();
00050 mIt != islands.end(); ++mIt)
00051 {
00052 std::string bankname = mIt->first;
00053 std::string detname = setup->GetDetectorName(bankname);
00054 int max_adc_value = pow(2, setup->GetNBits(bankname));
00055 std::string histname = "hDQ_IslandAmplitudes_" + detname + "" + bankname;
00056 std::string histtitle = "Amplitude of Pulses in " + detname;
00057 TH1F* hDQ = new TH1F(histname.c_str(), histtitle.c_str(),
00058 max_adc_value, 0, max_adc_value);
00059 hDQ->GetXaxis()->SetTitle("Amplitude (adc)");
00060 hDQ->GetYaxis()->SetTitle("Counts");
00061 fAmpHist[bankname] = hDQ;
00062
00063 if(detname == "muSc")
00064 fAmpNorm=hDQ;
00065
00066 histname += "_EvtNorm";
00067 histtitle +=" (event normalized)";
00068 hDQ = new TH1F(histname.c_str(), histtitle.c_str(),
00069 500, 0, 2000);
00070 fAmpHistNorm[bankname] = hDQ;
00071 }
00072 TDirectory::CurrentDirectory()->cd("..");
00073
00074
00075 return 0;
00076 }
00077
00079
00080
00081
00082 int IslandAmplitude::ProcessEntry(TGlobalData* data,const TSetupData *setup)
00083 {
00084 ++fNProcessed;
00085
00086 StringPulseIslandMap& banks = data->fPulseIslandToChannelMap;
00087 int entry_norm =-1;
00088
00089 for(StringPulseIslandMap::iterator mIter = banks.begin(); mIter != banks.end(); ++mIter)
00090 {
00091 std::string detname = setup->GetDetectorName(mIter->first);
00092 if(detname == "muSc")
00093 entry_norm = mIter->second.size();
00094 }
00095
00096 for(StringPulseIslandMap::iterator mIter = banks.begin(); mIter != banks.end(); ++mIter)
00097 {
00098 std::string bankname = mIter->first;
00099 std::string detname = setup->GetDetectorName(bankname);
00100 PulseIslandList& pulses = mIter->second;
00101
00102 TH1F* hist = fAmpHist.find(bankname)->second;
00103 TH1F* histnorm = fAmpHistNorm.find(bankname)->second;
00104
00105 for(PIL_iter pIt = pulses.begin(); pIt != pulses.end(); ++pIt)
00106 {
00107
00108
00109
00110 double amp = 0;
00111 std::vector<int> samples = (*pIt)->GetSamples();
00112 std::vector<int>::iterator pos;
00113 int polarity = setup->GetTriggerPolarity(bankname);
00114 int pedestal = setup->GetPedestal(bankname);
00115
00116 if(polarity == 1)
00117 pos = std::max_element(samples.begin(), samples.end());
00118 else if(polarity == -1)
00119 pos = std::min_element(samples.begin(), samples.end());
00120
00121 amp = polarity * (*pos - pedestal);
00122
00123
00124 hist->Fill(amp);
00125 if(entry_norm != 0)
00126 histnorm->Fill(amp, 1.0/entry_norm);
00127 }
00128 }
00129
00130
00131 return 0;
00132 }
00133
00134
00136
00137
00138
00139
00140 int IslandAmplitude::AfterLastEntry(TGlobalData* gData,const TSetupData *setup){
00141
00142
00143 if(Debug()){
00144 cout<<"-----IslandAmplitude::AfterLastEntry(): I'm debugging!"<<endl;
00145 }
00146
00147 double run_norm = fAmpNorm->Integral(0,-1);
00148 for(mapSH_t::iterator it = fAmpHist.begin(); it != fAmpHist.end(); ++it)
00149 {
00150 TH1F* h = it->second;
00151 TObject* obj = h->Clone((std::string(h->GetName()) + "_RunNorm").c_str());
00152 TH1* hn = static_cast<TH1*>(obj);
00153 hn->SetTitle((std::string(h->GetTitle()) + " (run normalized)").c_str());
00154 hn->Scale(1.0/run_norm);
00155 }
00156
00157 for(mapSH_t::iterator it = fAmpHistNorm.begin(); it != fAmpHistNorm.end(); ++it)
00158 it->second->Scale(1.0/fNProcessed);
00159
00160 return 0;
00161 }
00162
00164
00165
00166
00167
00168
00169 ALCAP_REGISTER_MODULE(IslandAmplitude);