00001 #include <iostream>
00002 #include <utility>
00003 #include "IslandLength.h"
00004 #include "RegisterModule.inc"
00005 #include "TGlobalData.h"
00006 #include "TSetupData.h"
00007 #include "ModulesOptions.h"
00008 #include "definitions.h"
00009
00010
00011
00012
00013 IslandLength::IslandLength(modules::options* opts)
00014 : BaseModule("IslandLength",opts)
00015 {
00016
00017
00018
00019
00020
00021
00022 }
00023
00024
00025
00026 IslandLength::~IslandLength()
00027 {
00028 }
00029
00030
00031
00032 int IslandLength::BeforeFirstEntry(TGlobalData* data,const TSetupData *setup)
00033 {
00034
00035
00036
00037
00038
00039 if(Debug()){
00040 std::cout<<"-----IslandLength::BeforeFirstEntry(): I'm debugging!"
00041 <<std::endl;
00042 }
00043
00044 fNProcessed = 0;
00045 Book(data, setup);
00046 return 0;
00047 }
00048
00049
00050
00051 int IslandLength::ProcessEntry(TGlobalData* data,const TSetupData* setup)
00052 {
00053 ++fNProcessed;
00054
00055
00056
00057 StringPulseIslandMap& banks = data->fPulseIslandToChannelMap;
00058
00059 int entry_norm = -1;
00060 for (mapSP_iter biter = banks.begin(); biter != banks.end(); ++biter){
00061 std::string det_name = setup->GetDetectorName(biter->first);
00062 if (det_name == "muSc"){
00063 entry_norm = biter->second.size();
00064 }
00065 }
00066 for (mapSP_iter biter = banks.begin(); biter != banks.end(); ++biter){
00067 std::string bank_name = biter->first;
00068 std::string det_name = setup->GetDetectorName(bank_name);
00069 PulseIslandList& islands = biter->second;
00070
00071 TH1F* hist = fHistos.find(bank_name)->second;
00072 TH1F* histNorm = fHistosNorm.find(bank_name)->second;
00073
00074 for (PIL_iter piter = islands.begin(); piter != islands.end(); ++piter){
00075 int length = (*piter)->GetSamples().size();
00076 hist->Fill(length);
00077 if (entry_norm!=0) histNorm->Fill(length, 1./entry_norm);
00078 }
00079 }
00080
00081 return 0;
00082 }
00083
00084
00085
00086 int IslandLength::AfterLastEntry(TGlobalData* gData,const TSetupData *setup)
00087 {
00088
00089 if(Debug()){
00090 std::cout << "-----IslandLength::AfterLastEntry(): I'm debugging!"
00091 << std::endl;
00092 }
00093
00094 double run_norm = fNormHist->Integral(0,-1);
00095 for (mapSH_t::iterator it = fHistos.begin(); it != fHistos.end(); ++it){
00096 TH1F* h = it->second;
00097 TObject* obj = h->Clone((std::string(h->GetName()) + "_RunNorm").c_str());
00098 TH1* hn = static_cast<TH1*>(obj);
00099 hn->SetTitle((std::string(h->GetTitle()) + " (run normalised)").c_str());
00100 hn->Scale(1./run_norm);
00101 }
00102 for (mapSH_t::iterator it = fHistosNorm.begin(); it != fHistosNorm.end(); ++it){
00103 it->second->Scale(1./fNProcessed);
00104 }
00105
00106 return 0;
00107 }
00108
00109
00110 void IslandLength::Book(TGlobalData* data,const TSetupData* setup)
00111 {
00112
00113
00114 StringPulseIslandMap& islands = data->fPulseIslandToChannelMap;
00115 for (mapSP_iter it = islands.begin(); it != islands.end(); ++it){
00116
00117 std::string bank_name = it->first;
00118 std::string det_name = setup->GetDetectorName(bank_name);
00119 std::string hist_name = "hDQ_IslandLength_" + det_name + "" + bank_name;
00120 std::string hist_title = "Length of TPulseIslands in " + det_name;
00121 std::string axis_title = ";Length /samples;Number of Islands";
00122 TH1F* histo = new TH1F(hist_name.c_str(), (hist_title + axis_title).c_str(),
00123 500, 0, 2000);
00124 fHistos[bank_name] = histo;
00125 if (det_name == "muSc") fNormHist = histo;
00126
00127 hist_name += "_EvtNorm";
00128 hist_title += " (event normalised)";
00129 histo = new TH1F(hist_name.c_str(), (hist_title + axis_title).c_str(),
00130 500, 0, 2000);
00131 fHistosNorm[bank_name] = histo;
00132 }
00133 }
00134
00135
00136
00137
00138
00139
00140 ALCAP_REGISTER_MODULE(IslandLength);