// This script reads in .dat files produced using CalibTFB_genECALTFBOffsets.exe. // It saves four canvases (Ds, Br x2 and in the future, maybe, POD ECAL) // showing mean RMM ofsets as a function of time. // It takes as input the DB-ready .dat files of the type // ECALReconRMMOffsets_database_comet_0000XXXX.dat // To run CalibOffline_ECALplotmeanRMM.exe /path/tothe/datfiles/*.dat // This will then run over all .dat files in the directory. // Please feel free to make changes/improvements. // ROOT #include "TROOT.h" #include "TBrowser.h" #include "TH2.h" #include "TH1D.h" #include "TApplication.h" #include "TMath.h" #include "TLegend.h" #include "TCanvas.h" #include "TStyle.h" #include "TPaveText.h" #include "TGraph.h" #include "TMultiGraph.h" #include "TGraphErrors.h" #include "TF1.h" #include "TFile.h" #include "TAxis.h" // C headers #include #include #include #include #include #include #include #include #include #include int main(int argc, char *argv[]){ char *files[argc-1]; for(int i=1; iSetOptStat(0); // Three different canvases for different parts of the ECAL TCanvas* DsECAL = new TCanvas("DsECAL","DsECAL");//,1000,1000); // DsECAL->Divide(1,2); TCanvas* SideBrECAL = new TCanvas("SideBrECAL","Side BrECAL");//,1000,1000); SideBrECAL->Divide(1,2); TCanvas* TBBrECAL = new TCanvas("TBBrECAL","Top and Bottom ECAL");//,1000,1000); TBBrECAL->Divide(1,2); TCanvas* PODECAL = new TCanvas("PODECAL","PODECAL");//,1000,1000); // PODECAL->Divide(1,2); // TFile to save canvases to TFile* output = new TFile("monitoringRMMmean.root", "recreate"); int gNoRMMs = 10; // Array of TGraphErrors for plotting the mean time for each RMM TGraphErrors** gRMM = new TGraphErrors*[gNoRMMs]; for(int i=0; i gRMMLegend; gRMMLegend["ds"] = new TLegend(0.75,0.66,0.87,0.84); gRMMLegend["SBrL"] = new TLegend(0.75,0.66,0.87,0.84); gRMMLegend["SBrR"] = new TLegend(0.75,0.66,0.87,0.84); gRMMLegend["TBBrL"] = new TLegend(0.75,0.66,0.87,0.84); gRMMLegend["TBBrR"] = new TLegend(0.75,0.66,0.87,0.84); gRMMLegend["POD"] = new TLegend(0.75,0.66,0.87,0.84); Double_t errortime=0; Int_t rmmCounter[gNoRMMs]; time_t gXmin=0;// begin time of first run time_t gXmax=0;// end time of last run time_t time_offset = 788940000; //offset to get X axsis right... // Scale for y-axis on histograms Double_t gYmax=30.0; Double_t gYmin=-30.0; for(int i=0; imaxTime)maxTime=unixTime; if(unixTimeSetPoint(rmmCounter[irmm], unixtime-788940000.0, 2.5*offset); gRMM[irmm]->SetPointError(rmmCounter[irmm], errortime, error); rmmCounter[irmm]++; } irmm++; } if(i==0){gXmin=unixtime-time_offset;}; if(i==gNumberFiles-1){gXmax=unixtime-time_offset;} } //end of while(infile.good()) infile.close(); }// for(i=0;i gRMMForce; gRMMForce["Ds"] = new TH2D("gRMMForceDs","Downstream ECAL",1000,gXmin,gXmax,1000,gYmin,gYmax); gRMMForce["SBrL"] = new TH2D("gRMMForceSBrL","Side Barrel ECAL (Left/South)",1000,gXmin,gXmax,1000,gYmin,gYmax); gRMMForce["SBrR"] = new TH2D("gRMMForceSBrR","Side Barrel ECAL (Right/North)",1000,gXmin,gXmax,1000,gYmin,gYmax); gRMMForce["TBBrL"] = new TH2D("gRMMForceTBBrL","Top and Bottom Barrel ECAL (Left/South)",1000,gXmin,gXmax,1000,gYmin,gYmax); gRMMForce["TBBrR"] = new TH2D("gRMMForceTBBrR","Top and Bottom Barrel ECAL (Right/North)",1000,gXmin,gXmax,1000,gYmin,gYmax); gRMMForce["POD"] = new TH2D("gRMMForcePOD","POD ECAL",1000,gXmin,gXmax,1000,gYmin,gYmax); for(int i=0; icd(); if(i==0){ gRMMForce["Ds"]->Draw(); } gRMM[i]->Draw("samePL"); char RMM[10]; sprintf(RMM,"RMM%d",i); gRMMLegend["ds"]->AddEntry(gRMM[i],RMM,"l"); } // Side BrECAL South/Left: // RMM5, RMM6 if(i==4||i==5){ SideBrECAL->cd(1); if(i==4){ gRMMForce["SBrL"]->Draw(); } gRMM[i]->Draw("samePL"); char RMM[10]; sprintf(RMM,"RMM%d",i+1); gRMMLegend["SBrL"]->AddEntry(gRMM[i],RMM,"l"); } // Side BrECAL North/Right: // RMM8, RMM9 if(i==6||i==7){ SideBrECAL->cd(2); if(i==6){ gRMMForce["SBrR"]->Draw(); } gRMM[i]->Draw("samePL"); char RMM[10]; sprintf(RMM,"RMM%d",i+2); gRMMLegend["SBrR"]->AddEntry(gRMM[i],RMM,"l"); } // Top and Bottom BrECAL South/Left: // RMM3, RMM4 if(i==2||i==3){ TBBrECAL->cd(1); if(i==2){ gRMMForce["TBBrL"]->Draw(); } gRMM[i]->Draw("samePL"); char RMM[10]; sprintf(RMM,"RMM%d",i+1); gRMMLegend["TBBrL"]->AddEntry(gRMM[i],RMM,"l"); } // Top and Bottom BrECAL North/Right: // RMM 10, RMM 11 if(i==8||i==9){ TBBrECAL->cd(2); if(i==8){ gRMMForce["TBBrR"]->Draw(); } gRMM[i]->Draw("samePL"); char RMM[10]; sprintf(RMM,"RMM%d",i+2); gRMMLegend["TBBrR"]->AddEntry(gRMM[i],RMM,"l"); } if(i>=0&&i<9){gRMM[i]->SetLineColor(i+1);} if(i>=9&&iSetLineColor(i-8);} // Draw grid lines at 2.5ns intervals for the current pad for(double y=gYmin; y<=gYmax; y=y+2.5){ TLine* grid = new TLine(gXmin, y, gXmax, y); grid->Draw("same"); grid->SetLineStyle(3); //std::cout<::iterator it = gRMMForce.begin(); it != gRMMForce.end(); ++it){ (it->second)->GetXaxis()->SetTimeDisplay(1); (it->second)->GetXaxis()->SetTimeFormat("%d/%m/%y"); (it->second)->GetXaxis()->SetTitle("Date"); (it->second)->GetYaxis()->SetTitle("RMM offset (ns)"); (it->second)->GetXaxis()->SetTitleSize(0.04); (it->second)->GetYaxis()->SetTitleSize(0.04); (it->second)->GetXaxis()->SetLabelSize(0.03); (it->second)->GetYaxis()->SetLabelSize(0.03); (it->second)->GetYaxis()->SetTitleOffset(1.); } // Draw the legend for each canvas for(std::map::iterator it = gRMMLegend.begin(); it != gRMMLegend.end(); ++it){ if((it->first)=="ds"){ DsECAL->cd(); (it->second)->SetTextSize(0.03); (it->second)->SetFillColor(0); (it->second)->SetMargin(0.2); (it->second)->Draw(); } if((it->first)=="SBrL"){ SideBrECAL->cd(1); (it->second)->SetTextSize(0.03); (it->second)->SetFillColor(0); (it->second)->SetMargin(0.2); (it->second)->Draw(); } if((it->first)=="SBrR"){ SideBrECAL->cd(2); (it->second)->SetTextSize(0.03); (it->second)->SetFillColor(0); (it->second)->SetMargin(0.2); (it->second)->Draw(); } if((it->first)=="TBBrL"){ TBBrECAL->cd(1); (it->second)->SetTextSize(0.03); (it->second)->SetFillColor(0); (it->second)->SetMargin(0.2); (it->second)->Draw(); } if((it->first)=="TBBrR"){ TBBrECAL->cd(2); (it->second)->SetTextSize(0.03); (it->second)->SetFillColor(0); (it->second)->SetMargin(0.2); (it->second)->Draw(); } if((it->first)=="POD"){ PODECAL->cd(1); (it->second)->SetTextSize(0.03); (it->second)->SetFillColor(0); (it->second)->SetMargin(0.2); (it->second)->Draw(); } } // Update canvases DsECAL->Update(); SideBrECAL->Update(); TBBrECAL->Update(); PODECAL->Update(); // Write canvases to file output->WriteTObject(DsECAL); output->WriteTObject(SideBrECAL); output->WriteTObject(TBBrECAL); output->WriteTObject(PODECAL); // Delete canvases delete DsECAL; delete SideBrECAL; delete TBBrECAL; delete PODECAL; std::cout<<"Finished running"<