Thanks for your reply!
Maybe not too small and probably not running, but an experienced eye might see something.
[code]#include “/afs/cern.ch/user/a/astamato/public/lib_thanos/c_header.h”
#include “/afs/cern.ch/user/a/astamato/public/lib_thanos/root_header.h”
/** To use ROOT6 run these commands and then execute the macro using root -b -q extrema_root_forum.C
source /afs/cern.ch/sw/lcg/external/gcc/4.8/x86_64-slc6/setup.csh
source /afs/cern.ch/sw/lcg/app/releases/ROOT/6.02.02/x86_64-slc6-gcc48-opt/root/bin/thisroot.csh
*/
void mean_Gamma_Flash(int runfirst, int runlast, int segment, int detn, int thres) {
gStyle->SetPalette(52);//Use Grayscale palette–51-59
std::vector<TH1F*> hists;//Raw signals
std::vector<TH1F*> hists_clean;//Subtracted Signals
unsigned int histogram;
unsigned char detector;
int pulses = 0;
int entries = 0;
for (int run = runfirst; run <= runlast; run++){
for (int seg = 0; seg <= segment; seg++) {
cout << "Run : " << run << endl;
cout << "Segment : " << seg << endl;
cout << "-----------------" << endl;
//Load File
TFile *f = new TFile(TString::Format("Signals_%d_%d.root",run, seg));
if (f->IsOpen()==kFALSE) continue;
TTree *tree = (TTree*)f->Get("info");
tree->SetBranchStatus("*",0);
tree->SetBranchStatus("histogram",1); tree->SetBranchAddress("histogram",&histogram);
tree->SetBranchStatus("detector",1); tree->SetBranchAddress("detector",&detector);
entries = tree->GetEntries();
TH1F *h = new TH1F("h", TString::Format("FIMG%d_%d", detn, seg), entries, 0, entries);
TH1F *hmean = new TH1F("hProf", TString::Format("FIMG%d_mean", detn), entries, 0, entries);
for (int i = 0; i <= entries; i++){
//Get histogram number that corresponds to detector detn
tree->GetEntry(i);
if (detector == detn){
h->Fill(histogram);
pulses++;
}
//Fill the raw-histogram vector --> Input to TH2F* Stack
if (h->GetBinContent(i+1) == 1){
TH1F *hIndv = (TH1F*)f->FindObjectAny(TString::Format("hist_%d;1",i));
if (hIndv){
hists.push_back(hIndv);
}
}
}
h->Delete();
}//End of loop over segments
}//End of Loop over runs
cout << "Found " << pulses << " pulses" << endl;
//Compute average
cout << "Stacking raw histograms" << endl;
TH2F *hStack = Stack(hists);//Raw Signals Stack
cout << "Stacking raw histograms with threshold in z-axis" << endl;
TH2F *hStack_Thres = StackThreshold(hStack, thres);//Raw Signals Stack with threshold in z-axis
cout << "Calculating average" << endl;
TProfile * hProf = hStack_Thres->ProfileX("hProfname");//Average histogram From cut histogram
//TProfile * hProfFull = hStack->ProfileX("hProfFullname");//Average histogram From Full histogram
//TH1F *hFreq = GetFrequent(hStack);
//TH1F *hFreqThres = GetFrequent(hThres);
//Turn off stats
hStack->SetStats(kFALSE);
hStack_Thres->SetStats(kFALSE);
//Draw the 2D hist with the average prof on top.
hProf->SetLineColor(kRed);
hProf->SetMarkerColor(kRed);
hProf->SetLineWidth(2);
cout << "Drawing raw signals stack" << endl;
TCanvas * c_stack = new TCanvas("c_stack", "c_stack", 720, 720);
hStack->Draw("COLZ");
hProf->Draw("same");
//Use a log scale in Z
gPad->SetLogz();
gPad->Update();
// Export mean gamma flash in ascii file
TString histfilename = TString::Format("mean_gamma_%d_%d_%d.txt", detn, runfirst, runlast);
SingleExportAscii(hProf,histfilename);
//cout << "Hists size = " << hists.size() << endl;
for (unsigned int j = 0; j < hists.size(); j++){
TH1F *h_buffer = (TH1F*)hists[j]->Clone("h_buffer");
for (int i = 0; i <= hists[j]->GetNbinsX(); i++){
h_buffer->SetBinContent(i+1, hists[j]->GetBinContent(i+1)-hProf->GetBinContent(i+1));
}
if (h_buffer) hists_clean.push_back(h_buffer);
}
TH2F *hStack_Clean = Stack(hists_clean);
cout << "Stacking subtracted signals" << endl;
cout << "Drawing subtracted signals stack" << endl;
TH2F *hStack_Clean_Thres = StackThreshold(hStack_Clean,10);
TProfile * hProf_Clean = hStack_Clean_Thres->ProfileX("hProfname");
TCanvas * c_clean = new TCanvas("c_clean", "c_clean", 720, 720);
hStack_Clean->Draw("COLZ");
hProf_Clean->Draw("same");
//Use a log scale in Z
gPad->SetLogz();
gPad->Update();
TH1D * hProjected = hStack_Clean_Thres->ProjectionY("hProjected", 1300, 8000, "e");
TCanvas * c_clean_projected = new TCanvas("c_clean_projected", "c_clean_projected", 720, 720);
hProjected->Draw("histo");
TFile fout(TString::Format("gflash_%d_%d_%d.root", runfirst, runlast, detn), "RECREATE");
hStack->Write();
hProf->Write();
hStack_Clean->Write();
hProf_Clean->Write();
hProjected->Write();
fout.Close();
}[/code]
In the meanwhile I will try to create a smaller one reproducing the problem.