--- quicklook/tracker/flight/macros/FTrkQLook_BASIC.cxx 2006/05/10 10:06:54 1.1 +++ quicklook/tracker/flight/macros/FTrkQLook_BASIC.cxx 2006/07/13 10:13:37 1.10 @@ -1,8 +1,8 @@ /** - * FTrkQLook_BASIC.cpp + * FTrkQLook_BASIC.cxx * * autor: D.Fedele - * version 2.0 + * version v1r06 * Parameters: * file - the data file to analyze * fromevent - first event to analyze @@ -17,37 +17,28 @@ #include #include #include +#include #include +#include // #include #include #include #include +#include +#include // - -void stringcopy(TString& s1, const TString& s2, Int_t from=0, Int_t to=0){ - if ( to == 0 ){ - Int_t t2length = s2.Length(); - s1 = ""; - to = t2length; - }; - for (Int_t i = from; i0) base=file(0,dwpos); TString out; if(outdir.Length()==0){ @@ -55,13 +46,17 @@ }else{ out = outdir; } + if(out.Last('/')+1Get("RunHeader"); @@ -70,14 +65,17 @@ TTree *tr = (TTree*)datafile->Get("Physics"); tr->SetBranchAddress("Tracker",&te); tr->SetBranchAddress("Header",&eh); - - + TTree *ctr = (TTree*)datafile->Get("CalibTrk1"); + ctr->SetBranchAddress("Header",&ceh); + + Long64_t neventC = ctr->GetEntries(); Long64_t nevent = tr->GetEntries(); Long64_t neventH = otr->GetEntries(); Int_t minevent=0; Int_t maxevent=0; printf("Number of total events: %lld\nNumber of total header events: %lld\n",nevent,neventH); + printf("Number of calibration events: %lld\n",neventC); if (nevent<=0){ datafile->Close(); @@ -113,237 +111,383 @@ // // other variables definitions stringstream oss,fromfile,isfile; - const Int_t size=nevent; - Int_t dsp=0,count=0,trk_cal_us[50]; - Double_t perc; - Double_t yd[size*12], x[size+1]; - Double_t yyd[size+1],yyb[size], xb[size]; - ULong64_t HOBT[50]; - TGraph *dataletime,*dataletime1; - - for (Int_t i=0; i<50;i++){ - HOBT[i]=0; - trk_cal_us[i]=0; + // + // information about the RunHeader + Int_t HOBT[neventH]; + Int_t trk_cal_us[neventH]; + for (Int_t vi=0; viGetEntry(ev); pH = eH->GetPscuHeader(); HOBT[ev]= pH->GetOrbitalTime(); trk_cal_us[ev]=reh->TRK_CALIB_USED; + if((HOBT[ev]0) + countnboot+=1; } - + countnboot+=2*(Int_t)nevent/MAXSTORAGE; + // printf("\ncountnboot=%d\n",countnboot); // - // information about datalength - x[0]=(Double_t)HOBT[0]; - for (Int_t ev=minevent; evGetEntry(ev); - ph = eh->GetPscuHeader(); - - x[(ev-minevent)+1]= ph->GetOrbitalTime(); - dsp=0; - for(Int_t i=0; i<12; i++){ - dsp=te->DSPnumber[i]-1; - yd[(ev-minevent)*12+dsp]= te->DATAlength[i]; - } - }; - datafile->Close(); - - - //**************************************************************************************** - //Output figure - //**************************************************************************************** - - TCanvas *DataTimeCanv=new TCanvas("Tracker_Detector_Report_","",900,1200); - DataTimeCanv->SetFillColor(10); - DataTimeCanv->Range(0,0,100,100); - fromfile<<"FTrkQLook_BASIC File: "<SetTextFont(32); - t->SetTextColor(1); - t->SetTextAlign(12); - t->SetTextSize(0.02); - t->DrawLatex(2.,98.7,fromfile.str().c_str()); - TLatex *t1=new TLatex(); - t1->SetTextFont(32); - t1->SetTextColor(1); - t1->SetTextAlign(12); - t1->SetTextSize(0.02); - t1->DrawLatex(70.,98.7,isfile.str().c_str()); - fromfile.str(""); - isfile.str(""); - + // information about calibration OBT + Int_t COBT[neventC]; + for (Int_t vi=0; viGetEntry(ev); + pH = ceh->GetPscuHeader(); + COBT[ev]= pH->GetOrbitalTime(); + } - //************************************************************************************* - //book pads and histos - //*************************************************************************************** + // + // Style options gStyle->SetLabelSize(0.06,"x"); gStyle->SetLabelSize(0.06,"y"); gStyle->SetStatFontSize(0.075); - gStyle->SetOptStat(1110); + gStyle->SetOptStat(10); gStyle->SetFillColor(10); gStyle->SetTitleFontSize(0.1); + gStyle->SetTitleFillColor(10); gStyle->SetTitleOffset(0.8,"y"); gStyle->SetTitleOffset(0.9,"x"); gStyle->SetTitleSize(0.06,"y"); gStyle->SetTitleSize(0.055,"x"); - TPad *pad[12]; //pad for histos - Double_t posy = 0.95; // up y-coord - top pads - Double_t hpad = 0; // pad height - Double_t posx1=0; // left x-coord - pad column - Double_t posx0=0; // x-coord - column division - Double_t wrel = 0; // relative x size of first sub-column - Double_t marg = 0.004; // margin among pads - - hpad = (posy-marg*11)/6; - wrel = (1-marg*4)/2; - stringstream title; - stringstream hid; - - for(Int_t n = 0; n<12; n++) { - if ( (n+1)%2==1 ) { - if(n>1) posy = posy-(marg*2+hpad); - posx1 = marg; - posx0 = posx1 + wrel; - } - else { - posx1 = posx0 + 2*marg; - posx0 = posx1 + wrel; - } + //*************************************************************************************** + // LOOP on each event + //*************************************************************************************** - /* -----------> pad for histograms */ - pad[n] = new TPad("pad"," ",posx1,posy-hpad,posx0,posy,18,0,0); - }; + if (fromevent!=0) + printf("\n Scan of events from %i to %i ... \n",minevent,maxevent-1); + else + printf("\n Scan of events from %i to %i ... \n",minevent+1,maxevent); - TLine li; - li.SetLineColor(1); - li.SetLineStyle(1); - li.SetLineWidth(1); - //********************************************************************************** - // Fill Graphs and Histos - //********************************************************************************** - stringstream calus; - TLatex *t2=new TLatex(); - t2->SetTextFont(32); - t2->SetTextColor(1); - t2->SetTextAlign(13); - t2->SetTextSize(0.08); - - for (Int_t i=0; i<12 ; i++){ - perc=0; - count=0; - yyd[0]=-10000.; - for (Int_t ev=minevent; ev1500){ - if(yyd[(ev-minevent)+1]<3075){ - yyb[count]= yyd[(ev-minevent)+1]; - xb[count]= x[(ev-minevent)+1]; - count++; - } - } + + Int_t minev=minevent,maxev=maxevent,hin=0,hfin=0,cin=0,cfin=0; + TPad *pad[12][countnboot]; + TGraph *dataletime[12][countnboot],*dataletime1[12][countnboot]; + TCanvas *DataTimeCanv[countnboot]; + for(Int_t ii=0; iiSetFillColor(10); + DataTimeCanv[ii]->Range(0,0,100,100); + + TLatex *t=new TLatex(); + t->SetTextFont(32); + t->SetTextColor(1); + t->SetTextAlign(12); + t->SetTextSize(0.02); + t->DrawLatex(2.,98.7,fromfile.str().c_str()); + TLatex *t1=new TLatex(); + t1->SetTextFont(32); + t1->SetTextColor(1); + t1->SetTextAlign(12); + t1->SetTextSize(0.02); + t1->DrawLatex(70.,98.7,isfile.str().c_str()); + fromfile.str(""); + isfile.str(""); + + fromfile<<"D = Default Calibration"; + isfile<<"O = OnLine Calibration"; + t->SetTextColor(6); + t->SetTextSize(0.018); + t->DrawLatex(70.,97.,fromfile.str().c_str()); + t->SetTextColor(3); + t->DrawLatex(70.,96.,isfile.str().c_str()); + fromfile.str(""); + isfile.str(""); + + fromfile<<"The green arrow (if present) points out the time of the online calibration"; + t->DrawLatex(7.,96.,fromfile.str().c_str()); + fromfile.str(""); + + //************************************************************************************* + //book pads and histos + //*************************************************************************************** + + + Float_t posy = 0.95; // up y-coord - top pads + Float_t hpad = 0; // pad height + Float_t posx1=0; // left x-coord - pad column + Float_t posx0=0; // x-coord - column division + Float_t wrel = 0; // relative x size of first sub-column + Float_t marg = 0.004; // margin among pads + + hpad = (posy-marg*11)/6; + wrel = (1-marg*4)/2; + stringstream title; + stringstream hid; + + for(Int_t n = 0; n<12; n++) { + if ( (n+1)%2==1 ) { + if(n>1) posy = posy-(marg*2+hpad); + posx1 = marg; + posx0 = posx1 + wrel; + } + else { + posx1 = posx0 + 2*marg; + posx0 = posx1 + wrel; + } + + /* -----------> pad for histograms */ + oss<<"pad"<SetTextFont(32); + t2->SetTextColor(1); + t2->SetTextAlign(13); + t2->SetTextSize(0.08); + + Int_t i=0; + Float_t x[MAXSTORAGE], xb[MAXSTORAGE]; + Float_t yyd[MAXSTORAGE][12],yyb[MAXSTORAGE][12]; + Int_t countbad[12]; + Float_t perc=0,xMIN=0.,xMAX=0.; + for (Int_t n=0; n<12 ; n++) + countbad[n]=0; + + // + // obtain values of the datalenght + for (Int_t ev=minev; evGetEntry(ev); + ph = eh->GetPscuHeader(); + cod = eh->GetCounter(); + + if(ev==minev){ + if(cod->Get(pctp->CalibTrk1)>0) cin=cod->Get(pctp->CalibTrk1)-1; + else cin=cod->Get(pctp->CalibTrk1); + if(cin==cfin-1) cin+=1; + + if(cod->Get(pctp->RunHeader)>0) hin=cod->Get(pctp->RunHeader)-1; + else hin=cod->Get(pctp->RunHeader); + if(hin==hfin-1) hin+=1; + } + + if(ev==maxevent-1) maxev=maxevent-1; + + if((ph->GetOrbitalTime()750){ - if(yyd[(ev-minevent)+1]<3075){ - yyb[count]= yyd[(ev-minevent)+1]; - xb[count]= x[(ev-minevent)+1]; - count++; + cfin=cod->Get(pctp->CalibTrk1); + hfin=cod->Get(pctp->RunHeader); + x[(ev-minev)]= ph->GetOrbitalTime(); + i=0; + + for (Int_t n=0; n<12 ; n++){ + yyb[countbad[n]][i]=0; + xb[countbad[n]]= 0; + + i=te->DSPnumber[n]-1; + + yyd[(ev-minev)][i]=te->DATAlength[n]; + if(i==6){ + if(yyd[(ev-minev)][i]>1500){ + if(yyd[(ev-minev)][i]<3075){ + yyb[countbad[i]][i]= yyd[(ev-minev)][i]; + xb[countbad[i]]= x[(ev-minev)]; + countbad[i]+=1; + } + } + } + else{ + if(yyd[(ev-minev)][i]>750){ + if(yyd[(ev-minev)][i]<3075){ + yyb[countbad[i]][i]= yyd[(ev-minev)][i]; + xb[countbad[i]]= x[(ev-minev)]; + countbad[i]+=1; + } + } } } } } - if((maxevent-minevent)>100) perc=(count*100)/(maxevent-minevent); - else perc=(count*10)/(maxevent-minevent); + // + // define limit for the Xaxis of the graphs + + xMAX=x[maxev-minev-1]+(x[maxev-minev-1]-x[0])/10; + if(xMAX>1000000) xMIN=x[0]-(x[maxev-minev-1]-x[0])/10; + if(xMAX<1000000 || xMIN<0) xMIN=0.; + + + // + // Draw Histos + for (Int_t i=0; i<12 ; i++){ + + Float_t y[maxev-minev],yb[maxev-minev]; + for(Int_t v=0;v1000){ + perc=(countbad[i]*100)/(maxev-minev); + if(perc>10) pad[i][ii]->SetFillColor(2); + else pad[i][ii]->SetFillColor(10); + } + else{ + if(countbad[i]>=100) pad[i][ii]->SetFillColor(2); + else pad[i][ii]->SetFillColor(10); + } + + oss<<"DSP "<cd(); + pad[i][ii]->SetFrameFillColor(10); + pad[i][ii]->Draw(); + pad[i][ii]->cd(); + dataletime[i][ii]= new TGraph((maxev-minev),x,y); + dataletime[i][ii]->SetTitle(oss.str().c_str()); + dataletime[i][ii]->GetXaxis()->SetTitle("OBT (ms)"); + dataletime[i][ii]->GetXaxis()->CenterTitle(); + dataletime[i][ii]->GetXaxis()->SetRangeUser(xMIN,xMAX); + dataletime[i][ii]->GetYaxis()->SetTitle("datalength (Word 13 bit)"); + dataletime[i][ii]->GetYaxis()->CenterTitle(); + if(i==6) dataletime[i][ii]->GetYaxis()->SetRangeUser(0,4500); + else dataletime[i][ii]->GetYaxis()->SetRangeUser(0,4000); + dataletime[i][ii]->SetMarkerStyle(21); + if((maxev-minev)<50) dataletime[i][ii]->SetMarkerSize(0.5); + else dataletime[i][ii]->SetMarkerSize(0.1); + dataletime[i][ii]->SetMarkerColor(4); + dataletime[i][ii]->Draw("ap"); + + + if((maxev-minev)>1000 && perc>10){ + dataletime1[i][ii]= new TGraph(countbad[i],xb,yb); + dataletime1[i][ii]->SetMarkerStyle(21); + if((maxev-minev)<50) dataletime1[i][ii]->SetMarkerSize(0.5); + else dataletime1[i][ii]->SetMarkerSize(0.1); + dataletime1[i][ii]->SetMarkerColor(2); + dataletime1[i][ii]->Draw("psame"); + } + else if((maxev-minev)<1000 && countbad[i]>=100){ + dataletime1[i][ii]= new TGraph(countbad[i],xb,yb); + dataletime1[i][ii]->SetMarkerStyle(21); + if((maxev-minev)<50) dataletime1[i][ii]->SetMarkerSize(0.5); + else dataletime1[i][ii]->SetMarkerSize(0.1); + dataletime1[i][ii]->SetMarkerColor(2); + dataletime1[i][ii]->Draw("psame"); + } + li.SetLineColor(1); + li.SetLineStyle(1); + li.SetLineWidth(1); + if(i!=6) li.DrawLine(xMIN,750,xMAX,750); + else li.DrawLine(xMIN,1500,xMAX,1500); + li.DrawLine(xMIN,3075,xMAX,3075); - Double_t min,max; - if((maxevent-minevent)<100){ - min=x[0]; - max=x[size]*1.0001; - } - else{ - min=x[0]; - max=x[size-1]*1.0005; - } - oss<<"DSP "<cd(); - if(perc>1) pad[i]->SetFillColor(2); - else pad[i]->SetFillColor(10); - pad[i]->SetFrameFillColor(10); - pad[i]->Draw(); - pad[i]->cd(); - dataletime= new TGraph((maxevent-minevent)+1,x,yyd); - dataletime->SetTitle(oss.str().c_str()); - dataletime->GetXaxis()->SetTitle("OBT (ms)"); - dataletime->GetXaxis()->CenterTitle(); - dataletime->GetXaxis()->SetRangeUser(min,max); - dataletime->GetYaxis()->SetTitle("datalength (Word 13 bit)"); - dataletime->GetYaxis()->CenterTitle(); - dataletime->GetYaxis()->SetRangeUser(0,3500); - dataletime->SetMarkerStyle(21); - if((maxevent-minevent)<50) dataletime->SetMarkerSize(0.5); - else dataletime->SetMarkerSize(0.3); - dataletime->SetMarkerColor(1); - dataletime->Draw("ap"); - if(perc>1){ - dataletime1= new TGraph(count,xb,yyb); - dataletime1->SetMarkerStyle(21); - if((maxevent-minevent)<50) dataletime1->SetMarkerSize(0.5); - else dataletime1->SetMarkerSize(0.3); - dataletime1->SetMarkerColor(2); - dataletime1->Draw("psame"); - } - li.SetLineColor(1); - li.SetLineStyle(1); - li.SetLineWidth(1); - if(i!=6) li.DrawLine(min,750,max,750); - else li.DrawLine(min,1500,max,1500); - li.DrawLine(min,3075,max,3075); - for(Int_t j=0;jSetTextColor(6); - t2->DrawLatex(HOBT[j],3350.,calus.str().c_str()); - calus.str(""); - } - else{ - calus<SetTextColor(3); - t2->DrawLatex(HOBT[j],3350.,calus.str().c_str()); - calus.str(""); + for(Int_t j=hin;jSetTextColor(6); + if(i==6) t2->DrawLatex(HOBT[j],4350.,calus.str().c_str()); + else t2->DrawLatex(HOBT[j],3850.,calus.str().c_str()); + calus.str(""); + } + else{ + calus<<"O"; + t2->SetTextColor(3); + if(i==6) t2->DrawLatex(HOBT[j],4350.,calus.str().c_str()); + else t2->DrawLatex(HOBT[j],3850.,calus.str().c_str()); + calus.str(""); + } + } + for(Int_t j=cin;jUpdate(); } - oss.str(""); - }; - - DataTimeCanv->Update(); - + + minev=maxev; + if(maxev==maxevent-1) { + countnboot=ii+1; + break; + } + } printf("... end of packets. \n"); + //************************************************************************* // Save output Files //************************************************************************* - stringstream out1; + stringstream nom1,nom2,nom3; + + for(Int_t fl=0;flPrint(out+nom1.str().c_str()); + nom1.str(""); + } + + if(countnboot>=2){ + if(!strcmp(outfile.Data(),"ps") || !strcmp(outfile.Data(),"pdf")){ + nom1.str(""); + nom2.str(""); + nom3.str(""); + nom1<Print(out+nom1.str().c_str(),"portrait"); + else if(fl==countnboot-1) DataTimeCanv[fl]->Print(out+nom3.str().c_str(),"portrait"); + else DataTimeCanv[fl]->Print(out+nom2.str().c_str(),"portrait"); + + } + else{ + nom1.str(""); + nom1<Print(out+nom1.str().c_str()); + } + } + } - out1<Print(out+out1.str().c_str()); - out1.str(""); + // + // Convert ps to pdf if required + if(!strcmp(outfile.Data(),"pdf") && countnboot>=2){ + stringstream com; + com<<"ps2pdf13 "< ps file converted in pdf format!\n"); + com.str(""); + com<<"rm -f "< ps file removed!\n\n"); + com.str(""); + } + datafile->Close(); gROOT->Reset(); return; }