/* * PndMvdHistogramCollector.cxx * * Created on: April 24, 2013 * Author: s.esch */ #include "PndMvdHistogramCollector.h" #include "TList.h" #include "TCollection.h" #include "TObject.h" #include PndMvdHistogramCollector::PndMvdHistogramCollector():fCountGoodFiles(0),fVerbose(0) { // TODO Auto-generated constructor stub } PndMvdHistogramCollector::~PndMvdHistogramCollector() { // TODO Auto-generated destructor stub } void PndMvdHistogramCollector::AddFile(TFile* f) { if (f!=0) { //std::cout << "zombie " << f->IsZombie() << std::endl; if (f->IsZombie()==kTRUE) { std::cout << "Root file is a ZOMBIE! I will not analyse this file... " <0) { std::cout << "File: " << f->GetName() << " added to file list with f->IsOpen(): " << f->IsOpen() << std::endl; } } } } void PndMvdHistogramCollector::AnalyzeFiles() { for (unsigned int i = 0; i < fFileList.size(); i++){ TFile* f = fFileList[i]; if (f > 0){ TList* l = f->GetListOfKeys(); TIter iter(l); TObject* ob; fCountGoodFiles++; while(ob = iter()){ if (TString(ob->GetName()).Contains("f")){ TString newName = ob->GetName(); newName.Append("_sum"); if(strcmp(f->Get(ob->GetName())->ClassName(),"TH1F")==0) { TH1F* histo = (TH1F*)(f->Get(ob->GetName())); AddHisto(histo); } else if(strcmp(f->Get(ob->GetName())->ClassName(),"TH2F")==0) { TH2F* histo = (TH2F*)(f->Get(ob->GetName())); AddHisto(histo); } else if(strcmp(f->Get(ob->GetName())->ClassName(),"TH2I")==0) { TH2I* histo = (TH2I*)(f->Get(ob->GetName())); AddHisto(histo); } else if(strcmp(f->Get(ob->GetName())->ClassName(),"TH1I")==0) { TH1I* histo = (TH1I*)(f->Get(ob->GetName())); AddHisto(histo); } else { TH1F* histo = (TH1F*)(f->Get(ob->GetName())); AddHisto(histo); } } } } //f->Close(); } if(fVerbose>0) { std::cout << "Analyzing of histogramms done " << std::endl; } } void PndMvdHistogramCollector::AddHisto(TH1F* histo) { TString mapName = histo->GetName(); mapName.Append("_sum"); if(fHistoMap1F[mapName] == 0){ TH1F* newHisto = new TH1F(*histo); newHisto->SetName(mapName); fHistoMap1F[mapName] = newHisto; } else{ fHistoMap1F[mapName]->Add(histo); } if(fVerbose>2) { std::cout << "Adding histogram: " << histo->GetName() << " with type: " << histo->ClassName() << std::endl; } } void PndMvdHistogramCollector::AddHisto(TH2F* histo) { TString mapName = histo->GetName(); mapName.Append("_sum"); if(fHistoMap2F[mapName] == 0){ TH2F* newHisto = new TH2F(*histo); newHisto->SetName(mapName); fHistoMap2F[mapName] = newHisto; } else{ fHistoMap2F[mapName]->Add(histo); } if(fVerbose>2) { std::cout << "Adding histogram: " << histo->GetName() << " with type: " << histo->ClassName() << std::endl; } } void PndMvdHistogramCollector::AddHisto(TH1I* histo) { TString mapName = histo->GetName(); mapName.Append("_sum"); if(fHistoMap1I[mapName] == 0){ TH1I* newHisto = new TH1I(*histo); newHisto->SetName(mapName); fHistoMap1I[mapName] = newHisto; } else{ fHistoMap1I[mapName]->Add(histo); } if(fVerbose>2) { std::cout << "Adding histogram: " << histo->GetName() << " with type: " << histo->ClassName() << " to List " << std::endl; } } void PndMvdHistogramCollector::AddHisto(TH2I* histo) { TString mapName = histo->GetName(); mapName.Append("_sum"); if(fHistoMap2I[mapName] == 0){ TH2I* newHisto = new TH2I(*histo); newHisto->SetName(mapName); fHistoMap2I[mapName] = newHisto; } else{ fHistoMap2I[mapName]->Add(histo); } if(fVerbose>2) { std::cout << "Adding histogram: " << histo->GetName() << " with type: " << histo->ClassName() << std::endl; } } TH1F* PndMvdHistogramCollector::GetHisto1F(int i) { std::map::iterator iter = fHistoMap1F.begin(); for (int j = 0; j < i; j++)iter++; return iter->second; } TH1F* PndMvdHistogramCollector::GetHistoByName1F(TString name) { return fHistoMap1F[name]; } TH2F* PndMvdHistogramCollector::GetHisto2F(int i) { std::map::iterator iter = fHistoMap2F.begin(); for (int j = 0; j < i; j++)iter++; return iter->second; } TH1I* PndMvdHistogramCollector::GetHistoByName1I(TString name) { return fHistoMap1I[name]; } TH2I* PndMvdHistogramCollector::GetHisto2I(int i) { std::map::iterator iter = fHistoMap2I.begin(); for (int j = 0; j < i; j++)iter++; return iter->second; } TH2F* PndMvdHistogramCollector::GetHistoByName2F(TString name) { if (fHistoMap2F.count(name)>0) return fHistoMap2F[name]; return 0; } void PndMvdHistogramCollector::SaveHistos(TString fileName) { TFile f(fileName,"RECREATE"); if(fVerbose>0) { std::cout << "Outputfile created with name: " << f.GetName() << " Status IsOpen() "<< f.IsOpen() << std::endl; } for (std::map::const_iterator iter = fHistoMap2F.begin(); iter != fHistoMap2F.end(); iter++){ if (iter->second != 0){ std::cout << "GetMapName " << iter->first << std::endl; iter->second->Write(); } } std::cout << "TH2F done " << std::endl; for (std::map::const_iterator iter = fHistoMap1F.begin(); iter != fHistoMap1F.end(); iter++){ if (iter->second != 0){ std::cout << "GetMapName " << iter->first << std::endl; iter->second->Write(); } } std::cout << "TH1F done " << std::endl; for (std::map::const_iterator iter = fHistoMap1I.begin(); iter != fHistoMap1I.end(); iter++){ if (iter->second != 0){ std::cout << "GetMapName " << iter->first << std::endl; iter->second->Write(); std::cout << "Histogram written " << iter->second->GetName() << std::endl; } } for (std::map::const_iterator iter = fHistoMap2I.begin(); iter != fHistoMap2I.end(); iter++){ if (iter->second != 0){ std::cout << "GetMapName " << iter->first << std::endl; iter->second->Write(); std::cout << "Histogram written " << iter->second->GetName() << std::endl; } } f.Close(); }