// Program to plot FGD temperatures. // By default plots the average busboards (BB) temperatures for each FEB and individual BB sensors // for a week. User can specify the start date, end date and a file to save plots #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 "IMidasFile.h" #include #include #include //#include "SCDatabase.h" #include "ISlowControlDatabase.hxx" #include "gscUtils.hxx" TApplication myapp("myapp",0,0,0,0); int main(int argc, char* argv[]){ // FGD electronics numbers const int NMIN = 48;// number of minicrates const int NFEB = 4; // number of FEBs const int NSENSOR = 8; // number of temperature sensors // Default times int start_time = gscUtils::GetEncodedPreviousWeek(); int end_time = gscUtils::GetEncodedCurrentTime(); bool modeSave = false; char *outFilename; TFile *outFile; std::cout << "No args: " << argc << std::endl; if(argc > 1){ switch(argc){ case 2: // mode default times but save plots modeSave = true; outFilename = argv[1]; break; case 3: // mode chosen start time start_time = gscUtils::EncodeTime(argv[1],argv[2]); break; case 4: // mode chosen start time but save plots start_time = gscUtils::EncodeTime(argv[1],argv[2]); modeSave = true; outFilename = argv[3]; break; case 5: // mode chosen start and end time start_time = gscUtils::EncodeTime(argv[1],argv[2]); end_time = gscUtils::EncodeTime(argv[3],argv[4]); break; case 6: // mode chosen start and end time but save plots start_time = gscUtils::EncodeTime(argv[1],argv[2]); end_time = gscUtils::EncodeTime(argv[3],argv[4]); modeSave = true; outFilename = argv[5]; break; } } if(modeSave) outFile = new TFile(outFilename, "RECREATE"); // Make plots of temperatures for each FEB in each crate. std::vector > feb_avg_temperatures; std::vector > > bb_ind_temperatures; for(int i = 0; i < NMIN; i++){ std::vector avg_temp; std::vector > ind_temp; for(int feb = 0; feb < NFEB; feb++){ TGraph *avg_graph = new TGraph(); avg_temp.push_back(avg_graph); std::vector ind_graph; for(int sensor = 0; sensor < NSENSOR; sensor++){ TGraph *temp = new TGraph(); ind_graph.push_back(temp); } ind_temp.push_back(ind_graph); } feb_avg_temperatures.push_back(avg_temp); bb_ind_temperatures.push_back(ind_temp); } // Make histogram of all individual temperatures in this period TH1F *histo_temps = new TH1F("all_temps","FEB Sensors individual temperatures",259,-129,129); std::cout << "Start time: " << start_time << " and end time: " << end_time << std::endl; // Loop over minicrates for(int min =0; min < NMIN; min++){ // Loop over febs for(int feb = 0; feb < NFEB; 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 < NSENSOR; tt++){ char field[100]; sprintf(field,"f%02i%01i_temp%i",min,feb,tt); std::string s(field); input_fields.push_back(s); } // get fiels of table between start and end time ordered by distance std::vector > > alltemps = ISlowControlDatabase::Get().QueryGetFieldStartEndTime(table_name,input_fields,start_time,end_time); // 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; double time_hours = time/(60.*60.); double avg_temp = 0; double denom = 0; for(int busboard = 0; busboard < NSENSOR/2; busboard++){ if(busboard == 3 && feb == 3) continue; avg_temp += temps[busboard*2] + temps[busboard*2+1]; denom += 2.0; int nnn = bb_ind_temperatures[min][feb][busboard*2]->GetN(); int mmm = bb_ind_temperatures[min][feb][busboard*2+1]->GetN(); bb_ind_temperatures[min][feb][busboard*2]->SetPoint(nnn,time_hours,temps[busboard*2]); bb_ind_temperatures[min][feb][busboard*2+1]->SetPoint(mmm,time_hours,temps[busboard*2+1]); histo_temps->Fill(temps[busboard*2]); histo_temps->Fill(temps[busboard*2+1]); } if(denom != 0) avg_temp /= denom; int nn = feb_avg_temperatures[min][feb]->GetN(); feb_avg_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_histo = new TCanvas("histo_canvas","Histogram of all FEB sensors individual temperatures"); canvas_histo->cd(); histo_temps->Draw(); TCanvas* avg_canvas[8]; for(int i = 0; i < 4;i++){ int min_start = i*6 < NMIN ? i*6 : NMIN; int min_end = i*6+6 < NMIN ? i*6+6 : NMIN; char name[100], title[100]; sprintf(name,"FEB_Avg_Temp_Side%i",i); sprintf(title,"FEB Average Busboard Temperatures - Crates %i-%i",min_start,min_end-1); std::cout << name << " " << title << std::endl; avg_canvas[i] = new TCanvas(name,title,0+i*50,0,1200,1000); avg_canvas[i]->Divide(3,2); for(int min = min_start; min < min_end; min++){ avg_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 < NFEB; feb++){ if(feb_avg_temperatures[min][feb]->GetN()==0) continue; if(feb == 0){ feb_avg_temperatures[min][feb]->Draw("AP*"); feb_avg_temperatures[min][feb]->GetXaxis()->SetTitle("Time (hours)"); char title[100]; sprintf(title,"FEB Average busboard temperature - crate %i",min); feb_avg_temperatures[min][feb]->SetTitle(title); feb_avg_temperatures[min][feb]->GetYaxis()->SetTitle("FEB Busboards Average Temperature (C)"); feb_avg_temperatures[min][feb]->GetYaxis()->SetRangeUser(16.0,40); }else feb_avg_temperatures[min][feb]->Draw("*"); feb_avg_temperatures[min][feb]->SetMarkerStyle(20); feb_avg_temperatures[min][feb]->SetMarkerColor(feb+1); char name[100]; sprintf(name,"FEB%i",feb); leg->AddEntry(feb_avg_temperatures[min][feb],name,"P"); } leg->Draw("SAME"); } if(modeSave) avg_canvas[i]->Write(); } TCanvas* ind_canvas[NMIN]; for(int min = 0; min < NMIN;min++){ //int min_start = i*6; //int min_end = i*6+6; char name[100], title[100]; sprintf(name,"BB_Sensors_Temp_Ct%i",min); sprintf(title,"FEB Busboards Individual Sensors Temperatures - Crate %i",min); std::cout << name << " " << title << std::endl; ind_canvas[min] = new TCanvas(name,title,0+min*50,0,1200,1000); ind_canvas[min]->Divide(2,2); for(int feb = 0; feb < NFEB; feb++){ ind_canvas[min]->cd(feb+1); TLegend *leg = new TLegend(0.55,0.7,0.89,0.89); // Loop over sensors for(int sens = 0 ; sens < NSENSOR; sens++){ if(bb_ind_temperatures[min][feb][sens]->GetN()==0) continue; if(sens == 0){ bb_ind_temperatures[min][feb][sens]->Draw("AP*"); bb_ind_temperatures[min][feb][sens]->GetXaxis()->SetTitle("Time (hours)"); char title[100]; sprintf(title,"Individual sensor temperature - crate %i feb %i",min,feb); bb_ind_temperatures[min][feb][sens]->SetTitle(title); bb_ind_temperatures[min][feb][sens]->GetYaxis()->SetTitle("FEB Busboards Individual Sensor Temperature (C)"); bb_ind_temperatures[min][feb][sens]->GetYaxis()->SetRangeUser(16.0,40); }else bb_ind_temperatures[min][feb][sens]->Draw("*"); bb_ind_temperatures[min][feb][sens]->SetMarkerStyle(20); bb_ind_temperatures[min][feb][sens]->SetMarkerColor(sens+1); char name[100]; sprintf(name,"Sensor%i",sens); leg->AddEntry(bb_ind_temperatures[min][feb][sens],name,"P"); } leg->Draw("SAME"); } if(modeSave) ind_canvas[min]->Write(); } if(modeSave){ canvas_histo->Write(); //histo_temps->Write(); outFile->Write(); outFile->Close(); } if(!modeSave) myapp.Run(1); }