#include #include #include #include "TFile.h" #include "TH2F.h" #include "PDGHistos.h" bool PDGHistos::Add(TH2F *pHisto, Int_t PDGCode, string name) { if(!pHisto) { cout << "PDGHistos::Add - Error: Histogram Pointer is NULL Pointer" << endl; return false; } //TODO: Prüfe ob PDGCode schon verwaltet wird //TODO: Prüfe ob Histogram schon erstellt wurde -> entweder zufügen oder Aktion abbrechen pHisto->SetNameTitle(name.c_str(), name.c_str()); m_vpHistos.push_back(pHisto); m_PDGMap[PDGCode]=name; m_HistoMap[PDGCode]=pHisto; return true; } bool PDGHistos::Add(Int_t PDGCode, string name) { m_PDGMap[PDGCode]=name; return true; } bool PDGHistos::Add(TH2F *pHisto, Int_t PDGCode) { if(!pHisto) { cout << "PDGHistos::Add - Error: Histogram Pointer is NULL Pointer" << endl; return false; } if(m_PDGMap.find(PDGCode)==m_PDGMap.end()) { cout << "PDGHistos::Add - Error: PDGCode is unknown" << endl; return false; } string name=m_PDGMap[PDGCode]; pHisto->SetNameTitle(name.c_str(), name.c_str()); m_vpHistos.push_back(pHisto); m_HistoMap[PDGCode]=pHisto; return true; } void PDGHistos::Save(string strPathFilename) { TObjArray Histos(0); map::const_iterator cit; for(cit=m_PDGMap.begin(); cit!=m_PDGMap.end(); cit++) { ostringstream HistoName; HistoName << cit->second; //TH2F *pCurHisto=(TH2F*)gDirectory->Get(HistoName.str().c_str()); TH2F *pCurHisto=m_HistoMap[cit->first]; if(pCurHisto) { Histos.Add(pCurHisto); printf("Saving HistoName: %s\n", HistoName.str().c_str()); } } TFile f(strPathFilename.c_str(),"recreate"); Histos.Write(); f.Close(); } void PDGHistos::CreateSummary() { double von_x=0.; double bis_x=0.; double nbin_x=0.; double von_y=0.; double bis_y=0.; double nbin_y=0.; vector::iterator it; for(it=m_vpHistos.begin(); it!=m_vpHistos.end(); it++) { cout << "..." << endl; if( (*it) ) { assert(*it); TH2F *pCurHisto=*it; assert(pCurHisto); von_x=pCurHisto->GetBinLowEdge(1); bis_x=pCurHisto->GetBinLowEdge((*it)->GetNbinsX()) + (*it)->GetXaxis()->GetBinWidth((*it)->GetNbinsX()); nbin_x=pCurHisto->GetNbinsX(); von_y=pCurHisto->GetYaxis()->GetBinLowEdge(1); bis_y=pCurHisto->GetYaxis()->GetBinLowEdge((*it)->GetNbinsY()) + (*it)->GetYaxis()->GetBinWidth((*it)->GetNbinsY()); nbin_y=pCurHisto->GetNbinsY(); break; } } cout << "von_x(" << von_x << ") bis_x(" << bis_x << ") von_y(" << von_y << ") bis_y(" << bis_y << ")" << endl; TH2F *pHisto = new TH2F("summary", "Summary", nbin_x , von_x ,bis_x, nbin_y, von_y ,bis_y); assert(pHisto); for(it=m_vpHistos.begin(); it!=m_vpHistos.end(); it++) { if( (*it)) { pHisto->Add( (*it) ); } } if(Add(0, "Summary")) { Add(pHisto, 0); } } PDGHistos::~PDGHistos() { vector::iterator it; for(it=m_vpHistos.begin(); it!=m_vpHistos.end(); it++) { assert(*it); delete (*it); (*it)=NULL; } m_vpHistos.clear(); m_PDGMap.clear(); m_HistoMap.clear(); }