/* This script is for timming callibration of HAND using the cosmic. Here we calculate the time difference between each bar to the toppest bar of current layer: Tl-0.5*(T_ol-T_or) Tr-0.5*(T_ol-T_or) In addition we take into account the TOF of muons. Need to adjust the Time to channel conversion. */ { gROOT->Reset(); gStyle->SetOptFit(1); int pads[6]={30, 24, 22, 12, 12, 12}; //number of bars in each layer (without veto) double xpos[7][32]={{-1.5646, -1.4526, -1.3406, -1.2286, -1.1166, -1.0046, -0.8926, -0.7806, -0.6686, -0.5566, -0.6115, -0.4995, -0.3875, -0.2755, -0.1635, -0.0515, 0.0606, 0.1726, 0.2846, 0.3966, 0.5086, 0.6206, 0.5646, 0.6766, 0.7886, 0.9006, 1.0126, 1.1246, 1.2366, 1.3486, 1.4606,1.5726}, {-1.5396, -1.4338, -1.328, -1.222, -1.1164, -1.0106, -0.9048, -0.799, -0.6932, -0.5874, -0.4816, -0.3758, -0.27, -0.1642,-0.0584, 0.0474, 0.1532, 0.259, 0.3648, 0.4706, 0.5764, 0.6822, 0.788, 0.8938, 0.9996, 1.1054, 1.2112, 1.317, 1.4228, 1.5286},{-1.5368, -1.406, -1.2752, -1.1444, -1.0136, -0.8828, -0.752, -0.6212, -0.4904, -0.3596, -0.2288, -0.0979, 0.0329, 0.1637, 0.2945, 0.4253,0.5561,0.6869,0.8177,0.9485,1.0793,1.2101,1.3409,1.4717}, {-1.4906, -1.3348, -1.179, -1.0232, -0.8674, -0.7116, -0.5683,-0.4375, -0.3067, -0.1759, -0.0576, 0.0482, 0.1665, 0.2973, 0.4281, 0.5589, 0.7022, 0.858, 1.0138, 1.1696, 1.3254, 1.4812}, {-1.4513, -1.192, -0.9328, -0.6736, -0.4143, -0.1551, 0.1042, 0.3634, 0.6226, 0.8819, 1.1411, 1.4004}, {-1.4513, -1.192, -0.9328, -0.6736, -0.4143, -0.1551, 0.1042, 0.3634, 0.6226, 0.8819, 1.1411, 1.4004}, {-1.4513, -1.192, -0.9328, -0.6736, -0.4143, -0.1551, 0.1042, 0.3634, 0.6226, 0.8819, 1.1411, 1.4004}}; double time_to_ch=2; // conversion from time to channels 1 channel = 0.5 ns double speed=0.3; // speed of light(m/ns), relativistic muons TH1 *ht=new TH1D("ht","ht",80,-40,40); TH1 *hb=new TH1D("hb","hb",80,-40,40); TH1 *hl=new TH1D("hl","hl",80,-40,40); TH1 *hr=new TH1D("hr","hr",80,-40,40); char *top,*c_top,*bottom,*c_bottom,*left,*c_left,*right,*c_right,*dummy,*cutR,*cutL; top=(char*)malloc(1000); //used to draw difference between left and right TDC of topest bar c_top=(char*)malloc(1000); // used to cut on the TDC>0 for left and right bottom=(char*)malloc(1000); //used to draw difference between left and right TDC of bottom bar c_bottom=(char*)malloc(1000); // used to cut on the TDC>0 for left and right left=(char*)malloc(1000); //used to Draw left TDC of each bar minus (Tl+Tr)/2 of topest bar c_left=(char*)malloc(1000); //used to cut on the position of top and bottom bars and relevant TDC right=(char*)malloc(1000); //used to Draw right TDC of each bar minus (Tl+Tr)/2 of topest bar c_right=(char*)malloc(1000); //used to cut on the position of top and bottom bars and relevant TDC dummy=(char*)malloc(1000); cutL=(char*)malloc(1000); //used to include all relevant cuts for left side cutR=(char*)malloc(1000); //used to include all relevant cuts for right side double x[30]; //used to create x-Axis for the graph. in order to draw tdc offset vs position double left_off[30]={0},right_off[30]={0},left_res[30]={0},right_res[30]={0},left_off_err[30]={0},right_off_err[30]={0}; //Arrays used for left/right offsets, resolutions and errors double top_off,bottom_off; //position offset of the top and bottom bars. double layerL_off[6][30]={0},layerL_res[6][30]={0},layerR_off[6][30]={0},layerR_res[6][30]={0}; //array that saves the offsets for all PMT for each layer double corection[30]={0}; //correction to the offsets due to the time of flight of muon from top bar TCanvas *c1 = new TCanvas("c1", "c1",15,49,500,300); c1.Divide(2,1); TCanvas *c2 = new TCanvas("c2", "c2",515,49,900,400); c2.Divide(2,1); TCanvas *c3 = new TCanvas("c3", "c3",515,449,700,400); c3.Divide(6,2); double min[7],max[7],time,lenght,n_chan,x1,x2,y1,y2,dx[30]={0}; //parameters used to draw line double common=1; // common stop =1 common start = 0 //==================================Run over all layers and calculate offset for each PMT===========================================// for(int i=0;i<6;i++) { //==============General Line ==========// // draw between first bar on the top to the bar at the bottom in order to visualize the time offset due to the muons time of flight. This line may differ from acctial offset! max[i]=xpos[i][pads[i]-1]; min[i]=xpos[i][0]; lenght=TMath::Abs(max[i]-min[i]); //cout<<" max "<>ht",i+1,i+1); sprintf(c_top,"NA.nd.p%d.lt[0]>0 && NA.nd.p%d.rt[0]>0",i+1,i+1); sprintf(bottom,"(NA.nd.p%d.lt[%d]-NA.nd.p%d.rt[%d])>>hb",i+1,pads[i]-1,i+1,pads[i]-1); sprintf(c_bottom,"NA.nd.p%d.lt[%d]>0 && NA.nd.p%d.rt[%d]>0",i+1,pads[i]-1,i+1,pads[i]-1); c1.cd(1); T->Draw(top,c_top); c1.Paint(); c1.Update(); c1.cd(2); T->Draw(bottom,c_bottom); c1.Paint(); c1.Update(); gets(dummy); top_off=ht->GetMean(); bottom_off=hb->GetMean(); //==========================================================================================// x[0]=0; //================================RUN over all PMTs in layer "i" and calculate offset=========================================// for(int j=0;j>hl",i+1,j,i+1,i+1); sprintf(c_left,"abs(NA.nd.p%d.lt[0]-NA.nd.p%d.rt[0]-%f)<5 && abs(NA.nd.p%d.lt[%d]-NA.nd.p%d.rt[%d]-%f)<5 && NA.nd.p%d.lt[%d]>0",i+1,i+1,top_off,i+1,pads[i]-1,i+1,pads[i]-1,bottom_off,i+1,j); sprintf(right,"NA.nd.p%d.rt[%d]-0.5*(NA.nd.p%d.lt[0]+NA.nd.p%d.rt[0])>>hr",i+1,j,i+1,i+1); sprintf(c_right,"abs(NA.nd.p%d.lt[0]-NA.nd.p%d.rt[0]-%f)<5 && abs(NA.nd.p%d.lt[%d]-NA.nd.p%d.rt[%d]-%f)<5 && NA.nd.p%d.rt[%d]>0",i+1,i+1,top_off,i+1,pads[i]-1,i+1,pads[i]-1,bottom_off,i+1,j); sprintf(cutL,"%s && %s && %s", c_left, c_top, c_bottom); c2.cd(1); T->Draw(left,cutL); hl-Fit("gaus","Q"); left_off[j]=gaus->GetParameter(1); left_off_err[j]=gaus->GetParError(1); left_res[j]=gaus->GetParameter(2); sprintf(cutR,"%s && %s && %s", c_right, c_top, c_bottom); c2.cd(2); T->Draw(right,cutR); hr->Fit("gaus","Q"); right_off[j]=gaus->GetParameter(1); right_off_err[j]=gaus->GetParError(1); right_res[j]=gaus->GetParameter(2); gets(dummy); corection[j]=(TMath::Abs(xpos[i][j]-xpos[i][0])/speed)*time_to_ch; //correction of the offset due to the muon TOF if(common==0) corection[j]=-1*corection[j]; layerL_off[i][j]=left_off[j]+corection[j]; layerL_res[i][j]=left_res[j]; layerR_off[i][j]=right_off[j]+corection[j]; layerR_res[i][j]=right_res[j]; if(j>0) x[j]=x[j-1]+1; x[j]=x[j-1]+1; }//for(j) TGraphErrors *grL=new TGraphErrors(pads[i],x,left_off,dx,left_off_err); TGraphErrors *grR=new TGraphErrors(pads[i],x,right_off,dx,right_off_err); if(common==1) TLine *l=new TLine(x1,y1,x2,-y2); else TLine *l=new TLine(x1,y1,x2,y2); c3.cd(i+1); grL->SetMarkerStyle(2); grL->SetMarkerSize(2); grL->Draw("AP"); l->Draw("same"); c3.cd(7+i); grR->SetMarkerStyle(2); grR->SetMarkerSize(2); grR->Draw("AP"); l->Draw("same"); c3.Paint(); c3.Update(); }//for(i) //===============================CHECK FOR LAYER 4 ==================================// TCanvas c4; c4.Divide(2,1); sprintf(top,"(BB.HP4.lt[0]-BB.HP4.rt[0])>>ht"); sprintf(c_top,"BB.HP4.lt[0]>0 && BB.HP4.rt[0]>0"); sprintf(bottom,"(BB.HP4.lt[11]-BB.HP4.rt[11])>>hb"); sprintf(c_bottom,"BB.HP4.lt[11]>0 && BB.HP4.rt[11]>0"); double xx[12]={0}; for(int m=0;m<12;m++) { xx[m]=xpos[5][m]; c4.cd(1); sprintf(left,"BB.HP4.lt[%d]-0.5*(BB.HP4.lt[0]+BB.HP4.rt[0])-%f>>hl",m,layerL_off[0][m]); sprintf(c_left,"abs(BB.HP4.lt[0]-BB.HP4.rt[0]-%f)<5 && abs(BB.HP4.lt[11]-BB.HP4.rt[11]-%f)<5 && BB.HP4.lt[%d]>0",top_off,bottom_off,m); sprintf(right,"BB.HP4.rt[%d]-0.5*(BB.HP4.lt[0]+BB.HP4.rt[0])-%f>>hr",m,layerR_off[0][m]); sprintf(c_right,"abs(BB.HP4.lt[0]-BB.HP4.rt[0]-%f)<5 && abs(BB.HP4.lt[11]-BB.HP4.rt[11]-%f)<5 && BB.HP4.rt[%d]>0",top_off,bottom_off,m); sprintf(cutL,"%s && %s && %s", c_left, c_top, c_bottom); T->Draw(left,cutL); hl->Fit("gaus","Q"); left_off[m]=gaus->GetParameter(1); left_off_err[j]=gaus->GetParError(1); c4.Paint(); c4.Update(); gets(dummy); sprintf(cutR,"%s && %s && %s", c_right, c_top, c_bottom); T->Draw(right,cutR); hr->Fit("gaus","Q"); right_off[m]=gaus->GetParameter(1); right_off_err[j]=gaus->GetParError(1); c4.Paint(); c4.Update(); gets(dummy); } TF1 *f=new TF1("f","[1]*x+[0]",-2,2); TGraphErrors *gL=new TGraphErrors(12,xx,left_off,dx,left_off_err); TGraphErrors *gR=new TGraphErrors(12,xx,right_off,dx,right_off_err); c4.cd(1); gL->SetMarkerStyle(3); gL->SetMarkerSize(1); gL->Draw("AP"); gL->Fit("f"); c4.cd(2); gR->SetMarkerStyle(3); gR->SetMarkerSize(1); gR->Draw("AP"); gR->Fit("f"); }