// compile with: // g++ -o showmalltpcped.exe showsmalltpcped.cpp `root-config --cflags --glibs` // #include "TH1F.h" #include "TProfile.h" #include "TMath.h" #include "TF1.h" #include "TLegend.h" #include "TCanvas.h" // #include "TROOT.h" //#include "TStyle.h" #include "TTree.h" #include "TFile.h" #include "TGraphErrors.h" #include "TStyle.h" #include #include #include #include #include #include #include #include #include using namespace std; int showsmalltpcped(const char *filename = "") { TH1F* hPed; TH1F* hRms; FILE *fped; fped = fopen(filename,"r"); if (fped == NULL) { printf("File %s could not be opened\n",filename); return 1; } hPed = new TH1F("hPed", "",256,-0.5,255.5); hPed->SetMinimum(0); hPed->SetTitle("Pedestals smalltpc"); hPed->GetYaxis()->SetTitle("Pedestal"); hPed->GetXaxis()->SetTitle("Channel"); hRms = new TH1F("hRms", "",256,-0.5,255.5); hRms->SetMinimum(0); hRms->SetTitle("Pedestal rms smalltpc"); hRms->GetYaxis()->SetTitle("RMS"); hRms->GetXaxis()->SetTitle("Channel"); char buffer[512]; int line = 0; int channel,pedint; float pedfloat,pedrms,entries; while (fgets(buffer,sizeof(buffer),fped) != NULL) { sscanf(buffer,"%d,%d,%f,%f,%f",&channel,&pedint,&pedfloat,&pedrms,&entries); hPed->SetBinContent(channel+1,pedfloat); hRms->SetBinContent(channel+1,pedrms); line++; } fclose(fped); gStyle->SetOptStat(0); gStyle->SetErrorX(0); TCanvas *c1 = new TCanvas("c1","Single cluster",600,600); c1->Divide(1,2); c1->cd(1); hPed->Draw(); c1->cd(2); hRms->SetLineColor(kRed); hRms->Draw("hist"); sprintf(buffer,"%s.pdf",filename); c1->SaveAs(buffer,"pdf"); delete hPed; delete hRms; return 0; } int main (int argc, char *argv[]) { int iret = 0; printf("%s\n",argv[1]); if (argc != 2) { printf("Wrong number of arguments: argc = %d\nSyntax should be:\n./showsmalltpcped.exe filename\n",argc); return -1; } iret =showsmalltpcped(argv[1]); printf("END\n"); return iret; }