// 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[3]; TH1F *hCurrentTime[3]; TCanvas *c1 = new TCanvas("c1","Single cluster",600,600); int xaxis = 150; int line = 0; gStyle->SetOptStat(0); // FILE1 - pedestals sprintf(name, "%s/%s",dir,file1); printf("csvpedfile: %s\n",name); FILE *fcsv = fopen(name,"r"); if (fcsv == NULL) { printf("Pedfile %s not found-ignored \n",name); } else { sprintf(name,"Pedestals %s %d (average all channels) vs event",file1,date); hPedTime = new TH1F("hPedTime",name,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; 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; if (pedestal > 0) 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,100, "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("Mcmtempfile %s not found\n",name); return 1; } sprintf(name,"Temp vs Time MCM0 %s %d",file2,date); hTempTime[0] = new TH1F("hTempTime0",name,500,0.0,500.0); hTempTime[0]->SetMinimum(0); hTempTime[0]->GetXaxis()->SetTitle("Time (30 sec interval)"); hTempTime[0]->GetYaxis()->SetTitle("Temp (degrees)"); sprintf(name,"Temp vs Time MCM1 %s %d",file2,date); hTempTime[1] = new TH1F("hTempTime1",name,500,0.0,500.0); hTempTime[1]->SetMinimum(0); hTempTime[1]->GetXaxis()->SetTitle("Time (30 sec interva)"); hTempTime[1]->GetYaxis()->SetTitle("Temp (degrees)"); sprintf(name,"Temp vs Time MCM2 %s %d",file2,date); hTempTime[2] = new TH1F("hTempTime2",name,500,0.0,500.0); hTempTime[2]->SetMinimum(0); hTempTime[2]->GetXaxis()->SetTitle("Time (30 sec interva)"); hTempTime[2]->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) { if (mcm == 1) line1++; // hTempTime[mcm-1]->SetBinContent((line1-1)/2 + 1,temp); hTempTime[mcm-1]->SetBinContent(line1,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,3); c1->cd(1); sprintf(buffer,"MCM0 %d %d - %d %d",startdate,starttime,enddate,endtime); hTempTime[0]-> SetTitle(buffer); hTempTime[0]->SetAxisRange(32,42, "Y"); hTempTime[0]->SetAxisRange(0,xaxis, "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(32,42, "Y"); hTempTime[1]->SetAxisRange(0,xaxis, "X"); hTempTime[1]->Draw(); c1->cd(3); sprintf(buffer,"MCM2 %d %d - %d %d",startdate,starttime,enddate,endtime); hTempTime[2]-> SetTitle(buffer); hTempTime[2]->SetAxisRange(30,40, "Y"); hTempTime[2]->SetAxisRange(0,xaxis, "X"); hTempTime[2]->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)"); hCurrentTime[2] = new TH1F("hCurrentTime2", "Currenttime1",500,0.0,500.0); hCurrentTime[2]->SetMinimum(0); hCurrentTime[2]->GetXaxis()->SetTitle("Time (30 sec interval)"); hCurrentTime[2]->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) { if (mcm == 1) line1++; // hCurrentTime[mcm-1]->SetBinContent((line1-1)/2 + 1,c_1v5); hCurrentTime[mcm-1]->SetBinContent(line1,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,3); c1->cd(1); sprintf(buffer,"MCM0 %d %d - %d %d",startdate,starttime,enddate,endtime); hCurrentTime[0]-> SetTitle(buffer); hCurrentTime[0]->SetAxisRange(3000,3500, "Y"); hCurrentTime[0]->SetAxisRange(0,xaxis, "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(3000,3500, "Y"); hCurrentTime[1]->SetAxisRange(0,xaxis, "X"); hCurrentTime[1]->Draw(); c1->cd(3); sprintf(buffer,"MCM1 %d %d - %d %d",startdate,starttime,enddate,endtime); hCurrentTime[2]-> SetTitle(buffer); hCurrentTime[2]->SetAxisRange(3000,3500, "Y"); hCurrentTime[2]->SetAxisRange(0,xaxis, "X"); hCurrentTime[2]->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 pedfile mcmtemp readadc YYYYMMDD\n",argc); return -1; } int date = atoi(argv[5]); iret =plottime(argv[1],argv[2],argv[3],argv[4],date); return iret; }