// compile with: // g++ -o plottime.exe plottime.cpp `root-config --cflags --glibs` // #include "TH1F.h" #include "TH2F.h" #include "TH3F.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 plottime(const char *dir,const char *file1 = "",const char *file2 = "",const char *file3 = "", int date = 0) { char buffer[1024]; char name[100]; int iEventnb; int nChan; float pedestal; TH1F *hPedTime; TH1F *hTempTime[2]; TH1F *hCurrentTime[2]; TCanvas *c1 = new TCanvas("c1","Single cluster",600,600); // FILE1 - pedestals sprintf(name, "%s/%s",dir,file1); printf("csvpedfile: %s\n",name); FILE *fcsv = fopen(name,"r"); if (fcsv == NULL) { printf("Mapfile %s not found\n",name); return 1; } gStyle->SetOptStat(0); hPedTime = new TH1F("hPedTime", "Pedestals (average all channels) vs event",500,0.0,500.0); hPedTime->SetMinimum(0); hPedTime->GetXaxis()->SetTitle("Event"); hPedTime->GetYaxis()->SetTitle("Pedestal"); float pedsum = 0.0; int oldevtnb = 0; int nbchannels = 0; int line =0; while (fgets(buffer,sizeof(buffer),fcsv) != NULL) { if (line != 0) { sscanf(buffer,"%d,%d,%f",&iEventnb,&nChan,&pedestal); if (iEventnb != oldevtnb) { if (oldevtnb != 0) { if (nbchannels != 0) { pedsum /= nbchannels; hPedTime->SetBinContent(oldevtnb,pedsum); } } pedsum = 0.0; nbchannels = 0; } pedsum += pedestal; nbchannels++; oldevtnb = iEventnb; } line++; } if (nbchannels != 0) { pedsum /= nbchannels; hPedTime->SetBinContent(iEventnb,pedsum); } sprintf(name,"%s/%s.pdf",dir,file1); printf("NAME %s\n",name); hPedTime->SetAxisRange(80,90, "Y"); hPedTime->Draw(); c1->SaveAs(name,"pdf"); fclose(fcsv); // FILE2 - mcmtemp sprintf(name, "%s/%s",dir,file2); printf("mcmtempfile: %s\n",name); fcsv = fopen(name,"r"); if (fcsv == NULL) { printf("Mapfile %s not found\n",name); return 1; } hTempTime[0] = new TH1F("hTempTime0", "Temptime0",500,0.0,500.0); hTempTime[0]->SetMinimum(0); hTempTime[0]->GetXaxis()->SetTitle("Time (30 sec interval)"); hTempTime[0]->GetYaxis()->SetTitle("Temp (degrees)"); hTempTime[1] = new TH1F("hTempTime1", "Temptime1",500,0.0,500.0); hTempTime[1]->SetMinimum(0); hTempTime[1]->GetXaxis()->SetTitle("Time (30 sec interva)"); hTempTime[1]->GetYaxis()->SetTitle("Temp (degrees)"); line = 0; int line1 = 0; int mydate,mytime,mcm,cpld,action,rdmcmtemp,settings,errorcode; float temp; int startdate,starttime; int enddate,endtime; while (fgets(buffer,sizeof(buffer),fcsv) != NULL) { if (line != 0) { sscanf(buffer,"%d,%d,%d,%d,%d,%d,%f,%d,%X",&mydate,&mytime,&mcm,&cpld,&action,&rdmcmtemp,&temp,&settings,&errorcode); if (mydate == date) { line1++; hTempTime[mcm-1]->SetBinContent((line1-1)/2 + 1,temp); if (line1 == 1) { startdate = mydate; starttime = mytime; } else { enddate = mydate; endtime = mytime; } } } line++; } sprintf(name,"%s/%s.pdf",dir,file2); printf("NAME %s\n",name); c1->Clear(); c1->Divide(1,2); c1->cd(1); sprintf(buffer,"MCM0 %d %d - %d %d",startdate,starttime,enddate,endtime); hTempTime[0]-> SetTitle(buffer); hTempTime[0]->SetAxisRange(26,36, "Y"); hTempTime[0]->SetAxisRange(0,350, "X"); hTempTime[0]->Draw(); c1->cd(2); sprintf(buffer,"MCM1 %d %d - %d %d",startdate,starttime,enddate,endtime); hTempTime[1]-> SetTitle(buffer); hTempTime[1]->SetAxisRange(26,36, "Y"); hTempTime[1]->SetAxisRange(0,350, "X"); hTempTime[1]->Draw(); c1->SaveAs(name,"pdf"); fclose(fcsv); // FILE3 - adc currents sprintf(name, "%s/%s",dir,file3); printf("adcfile: %s\n",name); fcsv = fopen(name,"r"); if (fcsv == NULL) { printf("Mapfile %s not found\n",name); return 1; } hCurrentTime[0] = new TH1F("hCurrentTime0", "Currenttime0",500,0.0,500.0); hCurrentTime[0]->SetMinimum(0); hCurrentTime[0]->GetXaxis()->SetTitle("Time (30 sec interval)"); hCurrentTime[0]->GetYaxis()->SetTitle("Current (mA)"); hCurrentTime[1] = new TH1F("hCurrentTime1", "Currenttime1",500,0.0,500.0); hCurrentTime[1]->SetMinimum(0); hCurrentTime[1]->GetXaxis()->SetTitle("Time (30 sec interval)"); hCurrentTime[1]->GetYaxis()->SetTitle("Current (mA)"); line = 0; line1 = 0; int readadc,v_1v5,c_1v5,c_1v5_adc,v_2v5,c_2v5,c_2v5_adc,v_mcm1v5,v_mcm2v5; while (fgets(buffer,sizeof(buffer),fcsv) != NULL) { if (line != 0) { sscanf(buffer,"%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%X", &mydate,&mytime,&mcm,&cpld,&action,&readadc,&v_1v5,&c_1v5,&c_1v5_adc,&v_2v5,&c_2v5,&c_2v5_adc,&v_mcm1v5,&v_mcm2v5,&settings,&errorcode); if (mydate == date) { line1++; hCurrentTime[mcm-1]->SetBinContent((line1-1)/2 + 1,c_1v5); if (line1 == 1) { startdate = mydate; starttime = mytime; } else { enddate = mydate; endtime = mytime; } } } line++; } fclose(fcsv); sprintf(name,"%s/%s.pdf",dir,file3); printf("NAME %s\n",name); c1->Clear(); c1->Divide(1,2); c1->cd(1); sprintf(buffer,"MCM0 %d %d - %d %d",startdate,starttime,enddate,endtime); hCurrentTime[0]-> SetTitle(buffer); hCurrentTime[0]->SetAxisRange(3100,3220, "Y"); hCurrentTime[0]->SetAxisRange(0,350, "X"); hCurrentTime[0]->Draw(); c1->cd(2); sprintf(buffer,"MCM1 %d %d - %d %d",startdate,starttime,enddate,endtime); hCurrentTime[1]-> SetTitle(buffer); hCurrentTime[1]->SetAxisRange(3080,3200, "Y"); hCurrentTime[1]->SetAxisRange(0,350, "X"); hCurrentTime[1]->Draw(); c1->SaveAs(name,"pdf"); fclose(fcsv); return 0; } int main (int argc, char *argv[]) { int iret = 0; // printf("%s %s\n",argv[1],argv[2]); if (argc != 6) { printf("Wrong number of arguments: argc = %d\nSyntax should be:\n./plottime.exe dir file1 file2 file3\n",argc); return -1; } int date = atoi(argv[5]); iret =plottime(argv[1],argv[2],argv[3],argv[4],date); return iret; }