// Program to plot FGD temperatures for a week. // In particular, plots the average temperature for each FEB // for week. User can specify the start date of week. #include "TH1F.h" #include "TROOT.h" #include "TTree.h" #include "TFile.h" #include "TLine.h" #include "TMath.h" #include "TStyle.h" #include "TApplication.h" #include "TCanvas.h" #include "TPad.h" #include "TProfile.h" #include "TH1.h" #include "TF1.h" #include "TF2.h" #include "TH2.h" #include "TGraphErrors.h" #include "TLegend.h" #include "TColor.h" //#include "IMidasFile.h" #include #include #include //#include "SCDatabase.h" #include "ISlowControlDatabase.hxx" TApplication myapp("myapp",0,0,0,0); int main(int argc, char* argv[]){ gROOT->SetStyle("Plain"); gStyle->SetPalette(1); // T2K style definition // Adopted from BaBar collaboration // Add the following lines to the start of your rootlogon.C file TStyle *t2kStyle= new TStyle("T2K","T2K approved plots style"); // use plain black on white colors t2kStyle->SetFrameBorderMode(0); t2kStyle->SetCanvasBorderMode(0); t2kStyle->SetPadBorderMode(0); t2kStyle->SetPadColor(0); t2kStyle->SetCanvasColor(0); t2kStyle->SetStatColor(0); t2kStyle->SetFillColor(0); t2kStyle->SetLegendBorderSize(1); // set the paper & margin sizes t2kStyle->SetPaperSize(20,26); t2kStyle->SetPadTopMargin(0.05); t2kStyle->SetPadRightMargin(0.05); t2kStyle->SetPadBottomMargin(0.16); t2kStyle->SetPadLeftMargin(0.12); // use large Times-Roman fonts t2kStyle->SetTextFont(132); t2kStyle->SetTextSize(0.08); t2kStyle->SetLabelFont(132,"x"); t2kStyle->SetLabelFont(132,"y"); t2kStyle->SetLabelFont(132,"z"); t2kStyle->SetLabelSize(0.05,"x"); t2kStyle->SetTitleSize(0.06,"x"); t2kStyle->SetLabelSize(0.05,"y"); t2kStyle->SetTitleSize(0.06,"y"); t2kStyle->SetLabelSize(0.05,"z"); t2kStyle->SetTitleSize(0.06,"z"); t2kStyle->SetLabelFont(132,"t"); t2kStyle->SetTitleFont(132,"x"); t2kStyle->SetTitleFont(132,"y"); t2kStyle->SetTitleFont(132,"z"); t2kStyle->SetTitleFont(132,"t"); t2kStyle->SetTitleFillColor(0); t2kStyle->SetTitleX(0.25); t2kStyle->SetTitleFontSize(0.08); t2kStyle->SetTitleFont(132,"pad"); // use bold lines and markers t2kStyle->SetMarkerStyle(20); t2kStyle->SetHistLineWidth(1.85); t2kStyle->SetLineStyleString(2,"[12 12]"); // postscript dashes // get rid of X error bars and y error bar caps t2kStyle->SetErrorX(0.001); // do not display any of the standard histogram decorations t2kStyle->SetOptTitle(0); t2kStyle->SetOptStat(0); t2kStyle->SetOptFit(0); // put tick marks on top and RHS of plots t2kStyle->SetPadTickX(1); t2kStyle->SetPadTickY(1); // Add a greyscale palette for 2D plots int ncol=50; double dcol = 1./float(ncol); double gray = 1; TColor **theCols = new TColor*[ncol]; for (int i=0;iSetRGB(gray,gray,gray); gray -= dcol; } int ColJul[100]; for (int i=0; i<100; i++) ColJul[i]=999-i; t2kStyle->SetPalette(ncol,ColJul); // Default start time. int start_time = 1272672000; // May 1, 2010 int argOk=0; time_t checkTime; if(argc==1){ checkTime = time(NULL); argOk=1; } if(argc==3){ tm timeDecoder; char Dum[50]; strncpy(Dum,argv[1],4); strncpy(Dum+4,"\n",1); std::cout << Dum << std::endl; timeDecoder.tm_year = atoi(Dum); std::cout << atoi(Dum) << std::endl; timeDecoder.tm_year -= 1900; strncpy(Dum,argv[1]+5,2); strncpy(Dum+2,"\n",1); timeDecoder.tm_mon = atoi(Dum); timeDecoder.tm_mon--; strncpy(Dum,argv[1]+8,2); strncpy(Dum+2,"\n",1); timeDecoder.tm_mday = atoi(Dum); strncpy(Dum,argv[2],2); strncpy(Dum+2,"\n",1); timeDecoder.tm_hour = atoi(Dum); strncpy(Dum,argv[2]+3,2); strncpy(Dum+2,"\n",1); timeDecoder.tm_min = atoi(Dum); strncpy(Dum,argv[2]+6,2); strncpy(Dum+2,"\n",1); timeDecoder.tm_sec = atoi(Dum); std::cout << "Requested : " << " " << timeDecoder.tm_year << " " << timeDecoder.tm_mon << " " << timeDecoder.tm_mday << " " << timeDecoder.tm_hour << " " << timeDecoder.tm_min << " " << timeDecoder.tm_sec << std::endl; timeDecoder.tm_isdst=1; checkTime = mktime(&timeDecoder); if(checkTime!=-1) argOk=1; start_time = checkTime; } if(!argOk){ std::cout << "Usage: oaSlowControlDatabase_FgdWeeklyTemperatureCheck.exe or FgdWeeklyTemperatureCheck.exe yyyy-mm-dd hh:mm:ss" << std::endl; return 0; } // Make plots of average busboard temperatures for each FEB in each crate. std::vector > feb_temperatures; for(int i = 0; i < 48; i++){ std::vector temp; for(int feb = 0; feb < 4; feb++){ TGraph *graph = new TGraph(); temp.push_back(graph); } feb_temperatures.push_back(temp); } std::cout << "Start time: " << start_time << std::endl; // Loop over minicrates for(int min =0; min < 48; min++){ // Loop over febs for(int feb = 0; feb < 4; feb++){ struct timeval last; gettimeofday(&last,NULL); // Prepare the table name and list of required fields (ie columns); // In this case we will ask for the eight busboard temperature sensors // for each FEB. char table_name[100]; sprintf(table_name,"fgdsc_f%02i%01i",min,feb); std::vector input_fields; for(int tt = 0; tt < 8; tt++){ char field[100]; sprintf(field,"f%02i%01i_temp%i",min,feb,tt); std::string s(field); input_fields.push_back(s); } // 10000 rows ~ one week at one row/minute. std::vector > > alltemps // = ISlowControlDatabase::Get().QueryGetFieldNoCache(start_time,table_name,input_fields,10000); = ISlowControlDatabase::Get().QueryGetFieldStartEndTime(table_name, input_fields, start_time, start_time +604800 ); // Loop over all time entries for(int t = 0; t < alltemps.size(); t++){ double time = alltemps[t].first - start_time; std::vector temps = alltemps[t].second; // Calculate an average temperature for this crate. double avg_temp = 0; double denom = 0; for(int busboard = 0; busboard < 4; busboard++){ if(busboard == 3 && feb == 3) continue; if(busboard == 3 && feb == 2 && min >= 24) continue; avg_temp += temps[busboard*2] + temps[busboard*2+1]; denom += 2.0; } if(denom != 0) avg_temp /= denom; double time_hours = time/(60.*60.); int nn = feb_temperatures[min][feb]->GetN(); feb_temperatures[min][feb]->SetPoint(nn,time_hours,avg_temp); } struct timeval current; gettimeofday(¤t,NULL); double time = current.tv_sec-last.tv_sec + (current.tv_usec-last.tv_usec)/1000000.0; std::cout << "time to complete this feb " << min << "/" << feb << " is " << time << " s "<< std::endl; } } TCanvas* canvas[8]; for(int i = 0; i < 8;i++){ int min_start = i*6; int min_end = i*6+6; char name[100], title[100]; sprintf(name,"Ct%i",i); sprintf(title,"Temperature - Crates %i-%i",min_start,min_end-1); std::cout << name << " " << title << std::endl; canvas[i] = new TCanvas(name,title,0+i*50,0,1200,1000); canvas[i]->Divide(3,2); for(int min = min_start; min < min_end; min++){ canvas[i]->cd(min-min_start+1); TLegend *leg = new TLegend(0.55,0.7,0.89,0.89); // Loop over FEBs for(int feb = 0 ; feb < 4; feb++){ feb_temperatures[min][feb]->UseCurrentStyle(); if(feb_temperatures[min][feb]->GetN()==0) continue; if(feb == 0){ feb_temperatures[min][feb]->Draw("AP*"); feb_temperatures[min][feb]->GetXaxis()->SetTitle("Time (hours)"); char title[100]; sprintf(title,"Average busboard temp - crate %i",min); //feb_temperatures[min][feb]->SetTitle(title); feb_temperatures[min][feb]->GetYaxis()->SetTitle("Temperature (C)"); feb_temperatures[min][feb]->GetYaxis()->SetRangeUser(14,30); }else feb_temperatures[min][feb]->Draw("*"); feb_temperatures[min][feb]->SetMarkerStyle(20+feb); feb_temperatures[min][feb]->SetMarkerColor(feb+1); char name[100]; sprintf(name,"FEB%i",feb); leg->AddEntry(feb_temperatures[min][feb],name,"P"); } leg->Draw("SAME"); } } TCanvas* example = new TCanvas("cexample"); int min = 0; TLegend *leg = new TLegend(0.55,0.7,0.89,0.89); gStyle->SetOptStat(0); // Loop over FEBs for(int feb = 0 ; feb < 4; feb++){ feb_temperatures[min][feb]->UseCurrentStyle(); if(feb_temperatures[min][feb]->GetN()==0) continue; if(feb == 0){ feb_temperatures[min][feb]->Draw("AP*"); feb_temperatures[min][feb]->GetXaxis()->SetTitle("Time (hours)"); char title[100]; sprintf(title,"Average busboard temp - crate %i",min); feb_temperatures[min][feb]->GetYaxis()->SetTitle("Temperature (C)"); feb_temperatures[min][feb]->GetYaxis()->SetRangeUser(18,24); }else feb_temperatures[min][feb]->Draw("*"); feb_temperatures[min][feb]->SetMarkerStyle(20+feb); feb_temperatures[min][feb]->SetMarkerColor(feb+1); char name[100]; sprintf(name,"FEB%i",feb); leg->AddEntry(feb_temperatures[min][feb],name,"P"); } leg->Draw("SAME"); myapp.Run(1); }