#include "Riostream.h" void help() { cout << "Welcome in the alignment job analysis macro !" << endl; } ////////////////////////////////////////////////////// // // SPACEPOINTS_RESIDUALS.C: // // Root macro performing residual analysis. // For monitoring purposes. // // Usage: // root [0] .L Spacepoints_Residuals.C // root [1] spacepoints(filename,HP_number) // // S.V. 14/11/06 // ////////////////////////////////////////////////////// void spacepoints(char inFile[], int config_type) { // //Initialization // gROOT->Reset(); TString inFileTString=TString(inFile); Size_t dotPosition =inFileTString.Index(".root"); TString fileTitleTString = inFileTString(0,dotPosition); char fileTitle[400]; strcpy(fileTitle, fileTitleTString.Data()); // Histogram name and readout configuration TFile *res = new TFile(inFile); if (config_type == 1) // Happy Pion I { int config[] = {26,0,0,0,0,0,0,0,0,0,0,0,29,23,31,30,0,0,0,0,28}; int softnum[] = {0,12,13,14,15,20}; } if (config_type == 2) // Happy Pion II { int config[] = {0,0,0,0,0,0,0,0,0,0,0,0,29,0,31,0,0,37,27,24,28}; int softnum[] = {12,14,17,18,19,20}; } if (config_type == 3) // Happy Pion III { int config[] = {26,0,0,0,0,0,0,0,0,0,0,0,29,23,31,30,0,27,0,0,0}; int softnum[] = {0,12,13,14,15,18}; } if (config_type == 4) // Happy Pion IV { int config[] = {0,0,0,0,0,0,0,0,0,0,0,0,29,0,31,30,0,37,27,24,0}; int softnum[] = {12,14,15,17,18,19}; } // // Initialization of histograms // char histo_title[150]; TH1F *Res_X_bef[21], *Res_X_aft[21], *Res_Y_bef[21], *Res_Y_aft[21]; double window = 0.15; // In mm int nbins = 50; // for (i=0; i<21; i++) { sprintf(histo_title,"Res_X_bef_%d",i); Res_X_bef[i] = new TH1F(histo_title,"",nbins,-window,window); sprintf(histo_title,"Res_Y_bef_%d",i); Res_Y_bef[i] = new TH1F(histo_title,"",nbins,-window,window); sprintf(histo_title,"Res_X_aft_%d",i); Res_X_aft[i] = new TH1F(histo_title,"",nbins,-window,window); sprintf(histo_title,"Res_Y_aft_%d",i); Res_Y_aft[i] = new TH1F(histo_title,"",nbins,-window,window); } // // Initialization of variables // double n_type, n_station, n_dof, n_const; double t_step, t_side, t_station, t_resX, t_resY, t_X, t_Y; double z_r[] = {-161.15, -131.15, -98.85, -71.15, -38.85, -11.15, 21.15, 48.85, 81.15, 108.85, 141.15, 168.85, 201.15, 228.85, 261.15, 288.85, 451.15, 598.85, 651.15, 698.85, 751.15}; // // Then get the result file // TTree *check = (TTree*)res->Get("trackinfo"); check->SetBranchAddress("step" ,&t_step); check->SetBranchAddress("side" ,&t_side); check->SetBranchAddress("station" ,&t_station); check->SetBranchAddress("X_clus" ,&t_X); check->SetBranchAddress("Y_clus" ,&t_Y); check->SetBranchAddress("res_X" ,&t_resX); check->SetBranchAddress("res_Y" ,&t_resY); int nentries = check->GetEntries(); for (Int_t i=0; iGetEntry(i); int nstat = -1; if (t_side == 1) // ACDC (Right half) { for (int j=0; j<21; ++j) { if (fabs(t_station -z_r[j]) <= 0.5) nstat = j; } if (nstat < 0) continue; if (t_step == 0) // Before alignment { Res_X_bef[nstat]->Fill(t_resX); Res_Y_bef[nstat]->Fill(t_resY); } if (t_step == 1) // After alignment { Res_X_aft[nstat]->Fill(t_resX); Res_Y_aft[nstat]->Fill(t_resY); } } } /* ########################################### # On passe ensuite a la partie cosmetique # ########################################### */ /////////////STAT//////// gStyle -> SetStatW(0.3); gStyle -> SetStatH(0.2); gStyle -> SetStatColor(41); gStyle -> SetStatX(0.8); gStyle -> SetStatY(0.8); gStyle -> SetStatFont(42); gStyle -> SetOptStat(0); gStyle -> SetOptFit(111); gStyle -> SetPalette(45); ///////////////////////// c1 = new TCanvas("c1","X space-points residuals",200,500,700,800); c1->SetFillColor(0); c1->SetBorderMode(0); c1->Divide(2,3); for (i=0; i<6; i++) { c1->cd(i+1); Res_X_aft[softnum[i]]->GetXaxis()->SetTitle("Mean X residual (in mm)"); Res_X_aft[softnum[i]]->GetXaxis()->SetTitleSize(0.04); Res_X_bef[softnum[i]]->SetFillColor(2); Res_X_bef[softnum[i]]->SetFillStyle(3444); Res_X_aft[softnum[i]]->SetFillColor(1); Res_X_aft[softnum[i]]->SetFillStyle(3444); Res_X_aft[softnum[i]]->Draw(); Res_X_bef[softnum[i]]->Draw("same"); leg = new TLegend(0.6,0.75,0.99,0.99); sprintf(histo_title,"M%d bef. ali.",config[softnum[i]]); leg->AddEntry(Res_X_bef[softnum[i]],histo_title,"f"); sprintf(histo_title,"M%d aft. ali.",config[softnum[i]]); leg->AddEntry(Res_X_aft[softnum[i]],histo_title,"f"); leg->Draw(); } c1->Update(); c2 = new TCanvas("c2","Y space-points residuals",200,500,700,800); c2->SetFillColor(0); c2->SetBorderMode(0); c2->Divide(2,3); for (i=0; i<6; i++) { c2->cd(i+1); Res_Y_aft[softnum[i]]->GetXaxis()->SetTitle("Mean Y residual (in mm)"); Res_Y_aft[softnum[i]]->GetXaxis()->SetTitleSize(0.04); Res_Y_bef[softnum[i]]->SetFillColor(2); Res_Y_bef[softnum[i]]->SetFillStyle(3444); Res_Y_aft[softnum[i]]->SetFillColor(1); Res_Y_aft[softnum[i]]->SetFillStyle(3444); Res_Y_aft[softnum[i]]->Draw(); Res_Y_bef[softnum[i]]->Draw("same"); leg = new TLegend(0.6,0.75,0.99,0.99); sprintf(histo_title,"M%d bef. ali.",config[softnum[i]]); leg->AddEntry(Res_Y_bef[softnum[i]],histo_title,"f"); sprintf(histo_title,"M%d aft. ali.",config[softnum[i]]); leg->AddEntry(Res_Y_aft[softnum[i]],histo_title,"f"); leg->Draw(); } c1->Print(Form("%s.ps(",fileTitle)); c2->Print(Form("%s.ps)",fileTitle)); } ////////////////////////////////////////////////////// // // COMPARE_CONSTANTS.C: // // Macros to be used in order to compare 2 alignment files // For example if you want to compare constants in air and vacuum // // Usage: // root [0] .L Spacepoints_Residuals.C // root [1] compare_constants(filename1,filename2) // // S.V. 14/11/06 // ////////////////////////////////////////////////////// void compare_constants(char inFile1[], char inFile2[]) { gROOT->Reset(); // // Few options // const int n_modules = 6; double biases_aft_1[150]; double biases_aft_2[150]; double n_type, n_station, n_dof, n_const; double m_type, m_station, m_dof, m_const; double biases_tx_1[n_modules], biases_tx_2[n_modules]; double biases_ty_1[n_modules], biases_ty_2[n_modules]; double biases_rz_1[n_modules], biases_rz_2[n_modules]; double abscissa[n_modules]; for (Int_t j=0; j<150; j++) { biases_aft_1[j] = -999.0; biases_aft_2[j] = -999.0; } // // Then loop over the result files // TFile *DATA_1 = new TFile(inFile1); TFile *DATA_2 = new TFile(inFile2); TTree *DATA1 = (TTree*)DATA_1->Get("constants"); TTree *DATA2 = (TTree*)DATA_2->Get("constants"); DATA1->SetBranchAddress("type" ,&n_type); DATA1->SetBranchAddress("station" ,&n_station); DATA1->SetBranchAddress("DOF" ,&n_dof); DATA1->SetBranchAddress("mis_value" ,&n_const); DATA2->SetBranchAddress("type" ,&m_type); DATA2->SetBranchAddress("station" ,&m_station); DATA2->SetBranchAddress("DOF" ,&m_dof); DATA2->SetBranchAddress("mis_value" ,&m_const); Int_t nentries_1 = DATA1->GetEntries(); Int_t nentries_2 = DATA2->GetEntries(); // // Get the computed misalignments // for (Int_t i=0; iGetEntry(i); // Right alignment constants if (n_type == 3 && n_const != -999) biases_aft_1[int(n_station)+21*int(n_dof)] = n_const; } for (Int_t i=0; iGetEntry(i); // Right alignment constants if (m_type == 3 && m_const != -999) biases_aft_2[int(m_station)+21*int(m_dof)] = m_const; } int i_mod1 = 0; int i_mod2 = 0; for (Int_t j=0; j<21; j++) { if (biases_aft_1[j] != -999. && i_mod1 < n_modules) { biases_tx_1[i_mod1] = biases_aft_1[j]; biases_ty_1[i_mod1] = biases_aft_1[j+21]; biases_rz_1[i_mod1] = biases_aft_1[j+105]; abscissa[i_mod1] = j; i_mod1++; } if (biases_aft_2[j] != -999. && i_mod2 < n_modules) { biases_tx_2[i_mod2] = biases_aft_2[j]; biases_ty_2[i_mod2] = biases_aft_2[j+21]; biases_rz_2[i_mod2] = biases_aft_2[j+105]; abscissa[i_mod2] = j; i_mod2++; } } TGraph *Trans_x1 = new TGraph(n_modules,abscissa,biases_tx_1); TGraph *Trans_x2 = new TGraph(n_modules,abscissa,biases_tx_2); TGraph *Trans_y1 = new TGraph(n_modules,abscissa,biases_ty_1); TGraph *Trans_y2 = new TGraph(n_modules,abscissa,biases_ty_2); TGraph *Rot_z1 = new TGraph(n_modules,abscissa,biases_rz_1); TGraph *Rot_z2 = new TGraph(n_modules,abscissa,biases_rz_2); // Then do the cosmetics /////////////STAT//////// gStyle -> SetStatW(0.2); gStyle -> SetStatH(0.2); gStyle -> SetStatColor(41); gStyle -> SetStatX(0.8); gStyle -> SetStatY(0.8); gStyle -> SetStatFont(42); gStyle -> SetOptStat(0); gStyle -> SetOptFit(0); gStyle -> SetPalette(45); ///////////////////////// TH2F *GraphTX = new TH2F("GraphTX","",200,-0.5,20.5,200,-0.05,0.05); TH2F *GraphTY = new TH2F("GraphTY","",200,-0.5,20.5,200,-0.05,0.05); TH2F *GraphRZ = new TH2F("GraphRZ","",200,-0.5,20.5,200,-0.01,0.01); c1 = new TCanvas("c1","Test",200,500,700,800); c1->SetFillColor(0); c1->SetBorderMode(0); c1->Divide(1,3); c1->cd(1); Trans_x1->SetMarkerStyle(24); Trans_x1->SetMarkerColor(1); Trans_x1->SetMarkerSize(1.5); Trans_x2->SetMarkerStyle(20); Trans_x2->SetMarkerColor(2); GraphTX->GetXaxis()->SetTitle("Module number"); GraphTX->GetXaxis()->SetTitleSize(0.05); GraphTX->GetYaxis()->SetTitle("Misalignment value (in #mum)"); GraphTX->GetYaxis()->SetTitleSize(0.05); GraphTX->GetYaxis()->SetTitleOffset(0.8); GraphTX->Draw(); Trans_x1->Draw("P"); Trans_x2->Draw("P"); leg = new TLegend(0.6,0.75,0.99,0.99); leg->AddEntry(Trans_x1,inFile1,"P"); leg->AddEntry(Trans_x2,inFile2,"P"); leg->Draw(); c1->cd(2); Trans_y1->SetMarkerStyle(24); Trans_y1->SetMarkerColor(1); Trans_y1->SetMarkerSize(1.5); Trans_y2->SetMarkerStyle(20); Trans_y2->SetMarkerColor(2); GraphTY->GetXaxis()->SetTitle("Module number"); GraphTY->GetXaxis()->SetTitleSize(0.05); GraphTY->GetYaxis()->SetTitle("Misalignment value (in #mum)"); GraphTY->GetYaxis()->SetTitleSize(0.05); GraphTY->GetYaxis()->SetTitleOffset(0.8); GraphTY->Draw(); Trans_y1->Draw("P"); Trans_y2->Draw("P"); c1->cd(3); Rot_z1->SetMarkerStyle(24); Rot_z1->SetMarkerColor(1); Rot_z1->SetMarkerSize(1.5); Rot_z2->SetMarkerStyle(20); Rot_z2->SetMarkerColor(2); GraphRZ->GetXaxis()->SetTitle("Module number"); GraphRZ->GetXaxis()->SetTitleSize(0.05); GraphRZ->GetYaxis()->SetTitle("Misalignment value (in mrad)"); GraphRZ->GetYaxis()->SetTitleSize(0.05); GraphRZ->GetYaxis()->SetTitleOffset(0.8); GraphRZ->Draw(); Rot_z1->Draw("P"); Rot_z2->Draw("P"); c1->Update(); } ////////////////////////////////////////////////////// // // CREATE_XML.C: // // Root macro creating the xml file necessary for alignment runs // // Usage: // root [0] .L Alignment_analysis.C // root [1] create_XML(filename,file_tag) // // this will create a file named 'alignment_$file_tag.xml' // // S.V. 14/11/06 // ////////////////////////////////////////////////////// void create_XML(char inFile[], char file_tag[]) { // //Initialization // gROOT->Reset(); TFile *res = new TFile(inFile); char file_name[150]; sprintf(file_name,"alignment_%s.xml",file_tag); // // Initialization of variables // double n_type, n_station, n_dof, n_const, n_pull; double biases_aft_L[150]; double biases_aft_R[150]; TTree *rest = (TTree*)res->Get("constants"); rest->SetBranchAddress("type" ,&n_type); rest->SetBranchAddress("station" ,&n_station); rest->SetBranchAddress("DOF" ,&n_dof); rest->SetBranchAddress("mis_value" ,&n_const); rest->SetBranchAddress("mis_pull" ,&n_pull); Int_t nentries = rest->GetEntries(); for (Int_t j=0; j<150; j++) { biases_aft_R[j] = 0.0; biases_aft_L[j] = 0.0; } // // Get the computed misalignments // for (Int_t i=0; iGetEntry(i); // Left alignment constants if (n_type == 2 && n_const != -999) biases_aft_L[int(n_station)+21*int(n_dof)] = n_const; // Right alignment constants if (n_type == 3 && n_const != -999) biases_aft_R[int(n_station)+21*int(n_dof)] = n_const; } // // Then create the corresponding Alignment.xml file // cout << "" << endl; cout << "...Writing " << file_name << " file in the current directory..." << endl; cout << "" << endl; char numb[2]; fileout = new ofstream(file_name); (*fileout) << "" << endl; (*fileout) << "" << endl; (*fileout) << "" << endl; (*fileout) << "" << endl; (*fileout) << "" << endl; (*fileout) << " " << endl; (*fileout) << " 0 0 0" << endl; (*fileout) << " 0 0 0" << endl; (*fileout) << " " << endl; (*fileout) << "" << endl; (*fileout) << " " << endl; (*fileout) << " 0 0 0" << endl; (*fileout) << " 0 0 0" << endl; (*fileout) << " 0 0 0" << endl; (*fileout) << " " << endl; (*fileout) << "" << endl; (*fileout) << " " << endl; (*fileout) << " 0 0 0" << endl; (*fileout) << " 0 0 0" << endl; (*fileout) << " 0 0 0" << endl; (*fileout) << " " << endl; (*fileout) << "" << endl; (*fileout) << " " << endl; (*fileout) << " 0 0 0 " << endl; (*fileout) << " 0 0 0" << endl; (*fileout) << " " << endl; (*fileout) << "" << endl; (*fileout) << " " << endl; (*fileout) << " 0 0 0" << endl; (*fileout) << " 0 0 0" << endl; (*fileout) << " " << endl; (*fileout) << "" << endl; (*fileout) << " " << endl; (*fileout) << " 0 0 0" << endl; (*fileout) << " 0 0 0" << endl; (*fileout) << " " << endl; (*fileout) << "" << endl; (*fileout) << " " << endl; (*fileout) << " 0 0 0" << endl; (*fileout) << " 0 0 0" << endl; (*fileout) << " " << endl; (*fileout) << "" << endl; for (int k=0; k<21; k++) { int sign = 1; // First left (k%2 == 0) // Take into account global to local frame change ? sign = 1 : sign = -1; (k < 5) ? sprintf(numb, "0%d",2*k) : sprintf(numb, "%d",2*k); (*fileout) << " " << endl; (*fileout) << " " << biases_aft_L[k] << " " << sign*biases_aft_L[k+21] << " " << sign*biases_aft_L[k+42] << "" << endl; (*fileout) << " " << biases_aft_L[k+63] << " " << sign*biases_aft_L[k+84] << " " << sign*biases_aft_L[k+105] << "" << endl; (*fileout) << " 0 0 0" << endl; (*fileout) << " " << endl; (*fileout) << "" << endl; (*fileout) << " " << endl; (*fileout) << " 0 0 0" << endl; (*fileout) << " 0 0 0" << endl; (*fileout) << " 0 0 0" << endl; (*fileout) << " " << endl; (*fileout) << "" << endl; (*fileout) << " " << endl; (*fileout) << " 0 0 0" << endl; (*fileout) << " 0 0 0" << endl; (*fileout) << " 0 0 0" << endl; (*fileout) << " " << endl; (*fileout) << "" << endl; // Then right... (k < 5) ? sprintf(numb, "0%d",2*k+1) : sprintf(numb, "%d",2*k+1); (*fileout) << " " << endl; (*fileout) << " " << -biases_aft_R[k] << " " << sign*biases_aft_R[k+21] << " " << -sign*biases_aft_R[k+42] << "" << endl; (*fileout) << " " << biases_aft_R[k+63] << " " << sign*biases_aft_R[k+84] << " " << -sign*biases_aft_R[k+105] << "" << endl; (*fileout) << " 0 0 0" << endl; (*fileout) << " " << endl; (*fileout) << "" << endl; (*fileout) << " " << endl; (*fileout) << " 0 0 0" << endl; (*fileout) << " 0 0 0" << endl; (*fileout) << " 0 0 0" << endl; (*fileout) << " " << endl; (*fileout) << "" << endl; (*fileout) << " " << endl; (*fileout) << " 0 0 0" << endl; (*fileout) << " 0 0 0" << endl; (*fileout) << " 0 0 0" << endl; (*fileout) << " " << endl; (*fileout) << "" << endl; } (*fileout) << "" << endl; (*fileout) << "" << endl; fileout->close(); }