/** * FTrkCalibQLookExpert.cpp * * autor: D.Fedele * version 2.0 * Parameters: * file - the data file to analyze * step - select =1 in order to analyze one event at time * fromevent - first event to analyze * toevent - last event to analyze * outdir - total path of output file * outfile - extension of output file (pdf,ps,gif,jpg) * */ // #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; iGet("CalibHeader"); hotr->SetBranchAddress("Header", &eh4); totr = (TTree*)calibFile->Get("CalibTrailer"); totr->SetBranchAddress("Header", &eh3); otr1 = (TTree*)calibFile->Get("CalibTrk1"); otr1->SetBranchAddress("CalibTrk1", &trk1); otr1->SetBranchAddress("Header",&eh1); otr2 = (TTree*)calibFile->Get("CalibTrk2"); otr2->SetBranchAddress("CalibTrk2", &trk2); otr2->SetBranchAddress("Header",&eh2); if(otr1->GetEntries()==otr2->GetEntries()) nevents = otr1->GetEntries(); else{ printf("WARNING: CalibTrk1 entries is different from CalibTrk2 entries"); return;} if (nevents<=0) { calibFile->Close(); printf("No calibration packets found, exiting...\n"); return; }; printf("Number of calibration packets: %i\n",nevents); if ( fromevent > toevent && toevent ){ printf("It must be fromevent < toevent \n"); return; }; if ( fromevent > nevents || fromevent < 0 ) { printf("You can choose fromevent between 0 (all) and %i \n",nevents); return; }; if ( toevent > nevents || toevent < 0 ) { printf("You can choose toevent between 0 (all) and %i \n",nevents); return; }; if ( fromevent == 0 ) { minevent = 0; maxevent = nevents; } else { minevent = fromevent - 1; if ( toevent > 0 ){ maxevent = toevent; } else if (toevent > nevents) { maxevent = nevents; } else { maxevent = fromevent; }; }; //********************************************************************** // // LOOP OVER EVENTS // //********************************************************************** printf("\n Scan of calibration packets from %i to %i ... \n\n",minevent+1,maxevent); for (Int_t i = minevent; i < maxevent; i++){ otr1->GetEntry(i); otr2->GetEntry(i); totr->GetEntry(i); hotr->GetEntry(i); ph = eh4->GetPscuHeader(); HOBT= ph->GetOrbitalTime(); ph = eh3->GetPscuHeader(); TOBT= ph->GetOrbitalTime(); ctrk.good0[0]=trk1->good0; ctrk.good0[1]=trk2->good0; for (Int_t m = 0; m < 6; m++){ ph = eh1->GetPscuHeader(); FOBT[0]= ph->GetOrbitalTime(); ctrk.daqmode[trk1->DSPnumber[m]-1]=trk1->DAQmode[m]; ctrk.dspnum[trk1->DSPnumber[m]-1]=trk1->DSPnumber[m]; ctrk.calibnum[trk1->DSPnumber[m]-1]=trk1->calibnumber[m]; ctrk.ncalev[trk1->DSPnumber[m]-1]=trk1->ncalib_event[m]; ctrk.ped1[trk1->DSPnumber[m]-1]=trk1->ped_l1[m]; ctrk.ped2[trk1->DSPnumber[m]-1]=trk1->ped_l2[m]; ctrk.ped3[trk1->DSPnumber[m]-1]=trk1->ped_l3[m]; ctrk.sig1[trk1->DSPnumber[m]-1]=trk1->sig_l1[m]; ctrk.sig2[trk1->DSPnumber[m]-1]=trk1->sig_l2[m]; ctrk.sig3[trk1->DSPnumber[m]-1]=trk1->sig_l3[m]; ctrk.nbad1[trk1->DSPnumber[m]-1]=trk1->nbad_l1[m]; ctrk.nbad2[trk1->DSPnumber[m]-1]=trk1->nbad_l2[m]; ctrk.nbad3[trk1->DSPnumber[m]-1]=trk1->nbad_l3[m]; ctrk.calfl[trk1->DSPnumber[m]-1]=trk1->cal_flag[m]; ctrk.crc_c[trk1->DSPnumber[m]-1][0]=trk1->crc_cal[m][0]; ctrk.crc_c[trk1->DSPnumber[m]-1][1]=trk1->crc_cal[m][1]; ctrk.crc_c[trk1->DSPnumber[m]-1][2]=trk1->crc_cal[m][2]; ctrk.crc_hc[trk1->DSPnumber[m]-1]=trk1->crc_hcal[m]; for (Int_t j = 0; j < 3072; j++){ ctrk.dspped[trk1->DSPnumber[m]-1][j]=trk1->DSPped_par[m][j]; ctrk.dspsig[trk1->DSPnumber[m]-1][j]=trk1->DSPsig_par[m][j]; ctrk.dspbad[trk1->DSPnumber[m]-1][j]=trk1->DSPbad_par[m][j]; }; ph = eh2->GetPscuHeader(); FOBT[1]= ph->GetOrbitalTime(); ctrk.daqmode[trk2->DSPnumber[m]-1]=trk2->DAQmode[m]; ctrk.dspnum[trk2->DSPnumber[m]-1]=trk2->DSPnumber[m]; ctrk.calibnum[trk2->DSPnumber[m]-1]=trk2->calibnumber[m]; ctrk.ncalev[trk2->DSPnumber[m]-1]=trk2->ncalib_event[m]; ctrk.ped1[trk2->DSPnumber[m]-1]=trk2->ped_l1[m]; ctrk.ped2[trk2->DSPnumber[m]-1]=trk2->ped_l2[m]; ctrk.ped3[trk2->DSPnumber[m]-1]=trk2->ped_l3[m]; ctrk.sig1[trk2->DSPnumber[m]-1]=trk2->sig_l1[m]; ctrk.sig2[trk2->DSPnumber[m]-1]=trk2->sig_l2[m]; ctrk.sig3[trk2->DSPnumber[m]-1]=trk2->sig_l3[m]; ctrk.nbad1[trk2->DSPnumber[m]-1]=trk2->nbad_l1[m]; ctrk.nbad2[trk2->DSPnumber[m]-1]=trk2->nbad_l2[m]; ctrk.nbad3[trk2->DSPnumber[m]-1]=trk2->nbad_l3[m]; ctrk.calfl[trk2->DSPnumber[m]-1]=trk2->cal_flag[m]; ctrk.crc_c[trk1->DSPnumber[m]-1][0]=trk2->crc_cal[m][0]; ctrk.crc_c[trk1->DSPnumber[m]-1][1]=trk2->crc_cal[m][1]; ctrk.crc_c[trk1->DSPnumber[m]-1][2]=trk2->crc_cal[m][2]; ctrk.crc_hc[trk1->DSPnumber[m]-1]=trk2->crc_hcal[m]; for (Int_t j = 0; j < 3072; j++){ ctrk.dspped[trk2->DSPnumber[m]-1][j]=trk2->DSPped_par[m][j]; ctrk.dspsig[trk2->DSPnumber[m]-1][j]=trk2->DSPsig_par[m][j]; ctrk.dspbad[trk2->DSPnumber[m]-1][j]=trk2->DSPbad_par[m][j]; }; }; // // other variables definitions Int_t risposta=0; stringstream fromfile; fromfile<<"FTrkCalibQLook_EXPERT File: "<SetLabelSize(0.08,"x"); gStyle->SetLabelSize(0.08,"y"); gStyle->SetTitleFillColor(10); gStyle->SetTitleFontSize(0.1); gStyle->SetTitleOffset(0.8,"y"); gStyle->SetTitleOffset(1.,"x"); gStyle->SetTitleSize(0.06,"y"); gStyle->SetTitleSize(0.06,"x"); gStyle->SetOptStat(0); // // draw display area TLatex *tzz=new TLatex(); tzz->SetTextFont(32); tzz->SetTextColor(1); tzz->SetTextAlign(12); tzz->SetTextSize(0.019); Int_t canvasx=1200; Int_t canvasy=900; TCanvas *c1 = new TCanvas("c1","FTrkCalibQLook_EXPERT_ped",canvasx,canvasy); c1->SetFillColor(10); tzz->DrawLatex(.01,0.98,fromfile.str().c_str()); tzz->DrawLatex(.90,0.98,"PEDESTAL"); TCanvas *c2 = new TCanvas("c2","FTrkCalibQLook_EXPERT_sig",canvasx,canvasy); c2->SetFillColor(10); tzz->DrawLatex(.01,0.98,fromfile.str().c_str()); tzz->DrawLatex(.90,0.98,"SIGMA"); // draw pads TPad *trkpad1[12],*trkpad2[12]; //pad for histos TPaveText *trkpadtext[12]; //pad for header TH1F *histosig[12]; //histos of sigma TH1F *histoped[12]; //histos of pedestals TH1F *histoasig[12]; //histos of sigma TH1F *histoaped[12]; //histos of pedestals Double_t posy = 0.95; // up y-coord - top pads Double_t hpad = 0.15; // pad height Double_t posx1=0; // left x-coord - pad column Double_t posx2=0; // right x-coord - pad olumn Double_t posx0=0; // x-coord - column division Double_t wrel = 0.6; // relative x size of first sub-column Double_t marg = 0.004; // margin among pads stringstream title; stringstream hid; for(Int_t n = 0; n<12; n++){ if ( (n+1)%2 ) { if(n>1)posy = posy-(marg*2+hpad); posx1 = marg; posx2 = 0.5 - marg; posx0 = 0.5*wrel; } else { posx1 = posx1 + 0.5; posx2 = posx2 + 0.5; posx0 = posx0 + 0.5; }; /* -----------> pad for histograms */ trkpad1[n] = new TPad("pad1"," ",posx1,posy-hpad,posx0-marg,posy,18,0,0); trkpad2[n] = new TPad("pad2"," ",posx1,posy-hpad,posx0-marg,posy,18,0,0); /* -----------> pad for header dump */ trkpadtext[n] = new TPaveText((posx0+marg),(posy-hpad),posx2,posy); /* -----------> HISTOGRAMS */ /* calibration parameters */ title<<"DSP "<SetTextFont(40); trkpadtext[nn]->SetFillColor(33); if(calok==0)trkpadtext[nn]->SetFillColor(2); trkpadtext[nn]->SetTextSize(0.013); trkpadtext[nn]->SetTextAlign(13); trkpadtext[nn]->SetTextColor(1); trkpadtext[nn]->AddText(" "); message<<"DSP num --------> "<AddText(message.str().c_str()); message.str(""); message<<"DAQ mode -------> "<AddText(message.str().c_str()); message.str(""); message<<"Calibnumber ----> "<AddText(message.str().c_str()); message.str(""); message<<"ncalib_event ---> "<AddText(message.str().c_str()); message.str(""); message<<"Cal_flag -------> "<AddText(message.str().c_str()); message.str(""); message<<"crc_hcal -------> "<AddText(message.str().c_str()); message.str(""); message<<"crc_cal: l1- ";message.width(5);message<< ctrk.crc_c[n][0]; message<<" l2- ";message.width(5);message<< ctrk.crc_c[n][1]; message<<" l3- ";message.width(5);message<< ctrk.crc_c[n][2]; trkpadtext[nn]->AddText(message.str().c_str()); message.str(""); message<<": l1- "; message.width(5);message<< ctrk.ped1[n]; message<<" l2-"; message.width(5);message<< ctrk.ped2[n]; message<<" l3-"; message.width(5);message<< ctrk.ped3[n]; trkpadtext[nn]->AddText(message.str().c_str()); message.str(""); message<<": l1- "; message.width(5);message<< ctrk.sig1[n]; message<<" l2-"; message.width(5);message<< ctrk.sig2[n]; message<<" l3-"; message.width(5);message<< ctrk.sig3[n]; trkpadtext[nn]->AddText(message.str().c_str()); message.str(""); message<<"n.BAD: l1- "; message.width(5);message<AddText(message.str().c_str()); message.str(""); if(calok==0){ message.str("*** FAILED ***"); TText *t=trkpadtext[nn]->AddText(message.str().c_str()); t->SetTextSize(0.02); t->SetTextAlign(23); t->SetTextColor(5); }; /*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* * * Plot histo * *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*/ /******************************************************/ /* fill histos */ for(Int_t j = 0; j < 3072; j++){ histosig[nn]->Fill((Float_t)j,ctrk.dspsig[nn][j]); histoped[nn]->Fill((Float_t)j,ctrk.dspped[nn][j]); }; histoasig[nn]->Fill(1,ctrk.sig1[nn]); histoasig[nn]->Fill(1025,ctrk.sig2[nn]); histoasig[nn]->Fill(2049,ctrk.sig3[nn]); histoaped[nn]->Fill(1,ctrk.ped1[nn]); histoaped[nn]->Fill(1025,ctrk.ped2[nn]); histoaped[nn]->Fill(2049,ctrk.ped3[nn]); /******************************************************/ TLine li; li.SetLineColor(38); li.SetLineStyle(3); li.SetLineWidth(2); /* plot PEDESTAL */ c1->cd(); trkpadtext[nn]->Draw(); trkpad1[nn]->Draw(); trkpad1[nn]->cd(); trkpad1[nn]->SetFillColor(10); trkpad1[nn]->SetFrameFillColor(10); histoped[nn]->SetLineColor(1); histoped[nn]->SetFillColor(12); histoped[nn]->SetLineWidth(1); histoped[nn]->GetYaxis()->SetTitle("PED (ADC channels)"); histoped[nn]->GetYaxis()->CenterTitle(); if((nn+1)%2==1) histoped[nn]->GetYaxis()->SetRangeUser(2500,3200); if((nn+1)%2==0) histoped[nn]->GetYaxis()->SetRangeUser(1000,1700); histoaped[nn]->SetLineColor(5); histoaped[nn]->SetLineWidth(1); if(ctrk.good0[0]==1 && ctrk.good0[1]==1) histoped[nn]->Draw("b"); else histoped[nn]->Draw("axis"); histoaped[nn]->Draw("same"); if((nn+1)%2==1) { li.DrawLine(1024.5,2500,1024.5,3200); li.DrawLine(2048.5,2500,2048.5,3200); } if((nn+1)%2==0) { li.DrawLine(1024.5,1000,1024.5,1700); li.DrawLine(2048.5,1000,2048.5,1700); } /* plot SIGMA */ Double_t max=500.; c2->cd(); trkpadtext[nn]->Draw(); trkpad2[nn]->SetLogy(); trkpad2[nn]->Draw(); trkpad2[nn]->cd(); trkpad2[nn]->SetFillColor(10); trkpad2[nn]->SetFrameFillColor(10); histosig[nn]->SetLineColor(1); histosig[nn]->SetFillColor(12); histosig[nn]->SetLineWidth(1); histosig[nn]->SetMaximum(max); histosig[nn]->SetMinimum(0.5); histosig[nn]->GetYaxis()->SetTitle("SIG (ADC channels)"); histosig[nn]->GetYaxis()->CenterTitle(); histoasig[nn]->SetLineColor(5); histoasig[nn]->SetLineWidth(1); if(ctrk.good0[0]==1 && ctrk.good0[1]==1) histosig[nn]->Draw("b"); else histosig[nn]->Draw("axis"); histoasig[nn]->Draw("same"); li.DrawLine(1024.5,0,1024.5,max); li.DrawLine(2048.5,0,2048.5,max); };//end loop on views c1->Update();//draw pads in canvas c2->Update();//draw pads in canvas stringstream nom1; stringstream nom2; if(!strcmp(outfile.Data(),"ps")||!strcmp(outfile.Data(),"pdf")){ nom1.str(""); nom2.str(""); nom1<Print(nom1.str().c_str(),"Landscape"); c2->Print(nom2.str().c_str(),"Landscape"); if(!strcmp(outfile.Data(),"pdf")){ stringstream com; com<<"ps2pdf13 "< ps file converted in pdf format!\n"); com.str(""); com<<"rm -f "< ps file removed!\n\n"); com.str(""); } } else{ nom1.str(""); nom2.str(""); nom1<Print(nom1.str().c_str()); c2->Print(nom2.str().c_str()); } if(step==1 && i!=maxevent-1 ){ printf("\n Press 1 to continue, 2 to quit.\n"); cin>>risposta; if ( i != maxevent-1 ) { if ( risposta == 2 ) { gROOT->Reset(); printf("Exiting...\n"); return; } } } };//end loop on events gROOT->Reset(); printf("... end of packets. \n"); return; }