--- quicklook/QLflightS4_ND/S4_Calibration_QL.cpp 2006/06/15 14:00:30 1.1 +++ quicklook/QLflightS4_ND/S4_Calibration_QL.cpp 2006/09/05 13:06:41 1.4 @@ -18,6 +18,9 @@ * Fixed bugs: for a large namber of events is not possible to initialize vectors, so all graphs have been converted in histograms * * Known bugs: it is no possible to choise the figure format +* +* Version 1.2 - August 2006 +* Fixed bugs: is possible to choise figure format; all calibration are drown **************/ #include @@ -54,15 +57,23 @@ //--------------- Variables initialization -----------------------------------// const Int_t channels = 4096; - Double_t calib_1; - Double_t calib_2; - Double_t calib_4; + Double_t calib_1_MEAN; + Double_t calib_2_MEAN; + Double_t calib_4_MEAN; Double_t calib_1_RMS; Double_t calib_2_RMS; Double_t calib_4_RMS; + Double_t calib_1=0, calib_2=0, calib_4=0; Double_t obt; TString status; Int_t IPM1status, IPM2status; + ULong_t lastime, firstime, obt1; + double obmin=0.; + double obmax=0.; + double limitdown=0; + double limitup=0; + + //------------------------- Open data file -------------------------------------// TFile *file =new TFile(base.Data()) ; TString filename = ((TObjString*)base.Tokenize('/')->Last())->GetString(); @@ -130,54 +141,50 @@ } //---------------Look for configuration hot or cold -----------------------// - Int_t recordstot=0; - for (Int_t i = 0; i < neventstmtc; i++){ - tmtcBr->GetEntry(i); - Long64_t tmpSizetmtc = tme->Records->GetEntries(); - recordstot=recordstot+tmpSizetmtc; - } - const Int_t lungmax=16*recordstot; - Double_t xrecordobtcc[lungmax], yccdiagacq[lungmax], xrecordobtcc_1[lungmax], yccdiagacq_1[lungmax]; - recordstot=0; - for (Int_t i = 0; i < neventstmtc; i++){ - tmtcBr->GetEntry(i); - Long64_t tmpSizetmtc = tme->Records->GetEntries(); - Int_t size_b = tmpSizetmtc; - for (Int_t j = 0; j < size_b; j++){ - tmr = (pamela::TmtcRecord*)tme->Records->At(j); - for (Int_t k =0; k <16; k++){ - yccdiagacq[16*recordstot+16*j+k] = (((tmr->TM_DIAG_AND_BILEVEL_ACQ)>>(15-k))&0x0001); - xrecordobtcc[16*recordstot+16*j+k] = tmr->TM_RECORD_OBT; + if(neventstmtc!=0){ + Int_t recordstot=0; + for (Int_t i = 0; i < neventstmtc; i++){ + tmtcBr->GetEntry(i); + Long64_t tmpSizetmtc = tme->Records->GetEntries(); + recordstot=recordstot+tmpSizetmtc; + } + const Int_t lungmax=16*recordstot; + Double_t xrecordobtcc[lungmax], yccdiagacq[lungmax], xrecordobtcc_1[lungmax], yccdiagacq_1[lungmax]; + recordstot=0; + for (Int_t i = 0; i < neventstmtc; i++){ + tmtcBr->GetEntry(i); + Long64_t tmpSizetmtc = tme->Records->GetEntries(); + Int_t size_b = tmpSizetmtc; + for (Int_t j = 0; j < size_b; j++){ + tmr = (pamela::TmtcRecord*)tme->Records->At(j); + for (Int_t k =0; k <16; k++){ + yccdiagacq[16*recordstot+16*j+k] = (((tmr->TM_DIAG_AND_BILEVEL_ACQ)>>(15-k))&0x0001); + xrecordobtcc[16*recordstot+16*j+k] = tmr->TM_RECORD_OBT; + } } + recordstot=recordstot+tmpSizetmtc; } - recordstot=recordstot+tmpSizetmtc; - } - Int_t riftime = recordstot/2; - //CC (0=IPM1=hot; 1=IPM2=cold for S4 calibration) - for (Int_t k =0; k<16; k++){ - for (Int_t i = 0; i < recordstot; i++){ - yccdiagacq_1[i]= yccdiagacq[16*i+k]; - xrecordobtcc_1[i]= xrecordobtcc[16*i+k]; + Int_t riftime = recordstot/2; + //CC (0=IPM1=hot; 1=IPM2=cold for S4 calibration) + for (Int_t k =0; k<16; k++){ + for (Int_t i = 0; i < recordstot; i++){ + yccdiagacq_1[i]= yccdiagacq[16*i+k]; + xrecordobtcc_1[i]= xrecordobtcc[16*i+k]; + } + if (k==0) IPM1status=(Int_t)yccdiagacq_1[riftime]; + if (k==1) IPM2status=(Int_t)yccdiagacq_1[riftime]; } - if (k==0) IPM1status=(Int_t)yccdiagacq_1[riftime]; - if (k==1) IPM2status=(Int_t)yccdiagacq_1[riftime]; - } - if (IPM1status==0 && IPM2status==1){ - status="CONFIGURATION: HOT"; - } - if (IPM1status==1 && IPM2status==0){ - status="CONFIGURATION: COLD"; + if (IPM1status==0 && IPM2status==1){ + status="CONFIGURATION: HOT"; + } + if (IPM1status==1 && IPM2status==0){ + status="CONFIGURATION: COLD"; + } + }else{ + status=" No info about kind of calibration (hot or cold)"; } - //------------- Create and fill histograms -------------------------------------------// - - TH1F *calibS4_1 =new TH1F("calibS4_1", "calibS4_1", channels, 0, channels); - TH1F *calibS4_2 =new TH1F("calibS4_2", "calibS4_2", channels, 0, channels); - TH1F *calibS4_4 =new TH1F("calibS4_4", "calibS4_4", channels, 0, channels); - ULong_t lastime, firstime; - double obmin=0.; - double obmax=0.; - const Int_t size = nevents; + //----------- search max and min OBT -----------------------------------------------------// headBr->GetEntry(0); ph = eh->GetPscuHeader(); firstime = ph->GetOrbitalTime(); @@ -186,12 +193,42 @@ lastime = ph->GetOrbitalTime(); obmin=firstime; obmax=lastime; + if(nevents < 2){ + for(Int_t kk = 0; kkGetEntry(kk); + ph = eh->GetPscuHeader(); + if(obmin >= ph->GetOrbitalTime())obmin=ph->GetOrbitalTime(); + if(obmax <= ph->GetOrbitalTime())obmax=ph->GetOrbitalTime(); + } + limitdown= obmin - 1000000; + limitup= obmax + 1000000; + }else{ + for(Int_t kk = 0; kkGetEntry(kk); + ph = eh->GetPscuHeader(); + //cout<<"OrbitalTime()"<GetOrbitalTime()<<"\n"; + if(obmin >= ph->GetOrbitalTime())obmin=ph->GetOrbitalTime(); + if(obmax <= ph->GetOrbitalTime())obmax=ph->GetOrbitalTime(); + } + limitdown=obmin; + limitup=obmax; + } + //------------- Create and fill histograms -------------------------------------------// + stringstream oss1; + oss1.str(""); + oss1 << "S4 Calibration: "<< filename.Data(); + TH1F *calibS4_1 =new TH1F("S4-1", oss1.str().c_str(), channels, 0, channels); + TH1F *calibS4_2 =new TH1F("S4-2", oss1.str().c_str(), channels, 0, channels); + TH1F *calibS4_4 =new TH1F("S4-3", oss1.str().c_str(), channels, 0, channels); + stringstream oss; oss.str(""); oss << "S4_Calibration_QL: "<< filename.Data(); - TH1F *cal1 =new TH1F("calibS4_1", oss.str().c_str(), size, obmin, obmax); - TH1F *cal2 =new TH1F("calibS4_2", oss.str().c_str(), size, obmin, obmax); - TH1F *cal4 =new TH1F("calibS4_4", oss.str().c_str(), size, obmin, obmax); + const Int_t size = nevents; + //cout<<"size "<GetEntry(k); @@ -204,45 +241,44 @@ switch (j) { case 0 :{ calibS4_1->Fill(s4Record->S4_DATA); + calib_1 = calib_1+s4Record->S4_DATA; break; } case 1 :{ calibS4_2->Fill(s4Record->S4_DATA); + calib_2 = calib_2+s4Record->S4_DATA; break; } case 3 :{ calibS4_4->Fill(s4Record->S4_DATA); + calib_4 = calib_4+s4Record->S4_DATA; break; } } } } - obt=ph->GetOrbitalTime(); - calib_1=calibS4_1->GetMean(1); + //obt=ph->GetOrbitalTime(); + calib_1_MEAN=calib_1/128; //calib_1_RMS=calibS4_1->GetRMS(1); - calib_2=calibS4_2->GetMean(1); + calib_2_MEAN=calib_2/128; //calib_2_RMS=calibS4_2->GetRMS(1); - calib_4=calibS4_4->GetMean(1); + calib_4_MEAN=calib_4/128; //calib_4_RMS=calibS4_4->GetRMS(1); - cal1->Fill(obt,calib_1); - cal2->Fill(obt,calib_2); - cal4->Fill(obt,calib_4); - - //cout<Fill(ph->GetOrbitalTime(),calib_1_MEAN); + cal2->Fill(ph->GetOrbitalTime(),calib_2_MEAN); + cal4->Fill(ph->GetOrbitalTime(),calib_4_MEAN); + calib_1=calib_2=calib_4=0; } //----------------- Create and draw canvas -----------------------------------------// TCanvas *finalCanv = new TCanvas("S4Calib","Calibration_QL", 1280, 1024); - finalCanv->SetFillColor(10); + finalCanv->SetFillColor(10); + finalCanv->Divide(2,2); - finalCanv->cd(); + finalCanv->cd(1); gPad->SetLogy(); - cal1->SetStats(kFALSE); cal1->SetMarkerSize(.5); cal1->SetMarkerStyle(21); @@ -278,104 +314,167 @@ cal4->Draw("9psame"); if (IPM1status==0 && IPM2status==1){ ////hot configuration TF1 *func1 = new TF1("func1", "1560"); ///valore di riferimento 1300 - func1->SetRange(obmin, obmax); + //func1->SetRange(obmin, obmax); + func1->SetRange(limitdown, limitup); func1->SetLineColor(4); - func1->SetLineStyle(4); - func1->SetLineWidth(4); + func1->SetLineStyle(1); + func1->SetLineWidth(3); func1->Draw("same"); TF1 *func2 = new TF1("func2", "1040"); ///valore di riferimento 1300 - func2->SetRange(obmin, obmax); + //func2->SetRange(obmin, obmax); + func2->SetRange(limitdown, limitup); func2->SetLineColor(4); - func2->SetLineStyle(4); - func2->SetLineWidth(4); + func2->SetLineStyle(1); + func2->SetLineWidth(3); func2->Draw("same"); TF1 *func3 = new TF1("func3", "109"); ///valore di riferimento 95 - func3->SetRange(obmin, obmax); + //func3->SetRange(obmin, obmax); + func3->SetRange(limitdown, limitup); func3->SetLineColor(6); - func3->SetLineStyle(4); - func3->SetLineWidth(4); + func3->SetLineStyle(1); + func3->SetLineWidth(3); func3->Draw("same"); TF1 *func4 = new TF1("func4", "71"); ///valore di riferimento 95 - func4->SetRange(obmin, obmax); + //func4->SetRange(obmin, obmax); + func4->SetRange(limitdown, limitup); func4->SetLineColor(6); - func4->SetLineStyle(4); - func4->SetLineWidth(4); + func4->SetLineStyle(1); + func4->SetLineWidth(3); func4->Draw("same"); TF1 *func5 = new TF1("func5", "38.4"); //valore di riferimento 32 - func5->SetRange(obmin, obmax); - func5->SetLineStyle(4); + //func5->SetRange(obmin, obmax); + func5->SetRange(limitdown, limitup); + func5->SetLineStyle(1); func5->SetLineColor(3); - func5->SetLineWidth(4); + func5->SetLineWidth(3); func5->Draw("same"); TF1 *func6 = new TF1("func6", "25.6"); //valore di riferimento 32 - func6->SetRange(obmin, obmax); - func6->SetLineStyle(4); + //func6->SetRange(obmin, obmax); + func6->SetRange(limitdown, limitup); + func6->SetLineStyle(1); func6->SetLineColor(3); - func6->SetLineWidth(4); + func6->SetLineWidth(3); func6->Draw("same"); } if (IPM1status==1 && IPM2status==0){ ////cold configuration TF1 *func1 = new TF1("func1", "2400"); - func1->SetRange(obmin, obmax); + //func1->SetRange(obmin, obmax); + func1->SetRange(limitdown, limitup); func1->SetLineColor(4); - func1->SetLineStyle(4); - func1->SetLineWidth(4); + func1->SetLineStyle(1); + func1->SetLineWidth(3); func1->Draw("same"); TF1 *func2 = new TF1("func2", "1600"); ///valore di riferimento 2000 - func2->SetRange(obmin, obmax); + //func2->SetRange(obmin, obmax); + func2->SetRange(limitdown, limitup); func2->SetLineColor(4); - func2->SetLineStyle(4); - func2->SetLineWidth(4); + func2->SetLineStyle(1); + func2->SetLineWidth(3); func2->Draw("same"); TF1 *func3 = new TF1("func3", "180"); - func3->SetRange(obmin, obmax); + //func3->SetRange(obmin, obmax); + func3->SetRange(limitdown, limitup); func3->SetLineColor(6); - func3->SetLineStyle(4); - func3->SetLineWidth(4); + func3->SetLineStyle(1); + func3->SetLineWidth(3); func3->Draw("same"); TF1 *func4 = new TF1("func4", "120"); ///valore di riferimento 150 - func4->SetRange(obmin, obmax); + //func4->SetRange(obmin, obmax); + func4->SetRange(limitdown, limitup); func4->SetLineColor(6); - func4->SetLineStyle(4); - func4->SetLineWidth(4); + func4->SetLineStyle(1); + func4->SetLineWidth(3); func4->Draw("same"); TF1 *func5 = new TF1("func5", "38.4"); - func5->SetRange(obmin, obmax); - func5->SetLineStyle(4); + //func5->SetRange(obmin, obmax); + func5->SetRange(limitdown, limitup); + func5->SetLineStyle(1); func5->SetLineColor(3); - func5->SetLineWidth(4); + func5->SetLineWidth(3); func5->Draw("same"); TF1 *func6 = new TF1("func6", "25.6"); //valore di riferimento 32 - func6->SetRange(obmin, obmax); - func6->SetLineStyle(4); + //func6->SetRange(obmin, obmax); + func6->SetRange(limitdown, limitup); + func6->SetLineStyle(1); func6->SetLineColor(3); - func6->SetLineWidth(4); + func6->SetLineWidth(3); func6->Draw("same"); } - TPad *pad = new TPad("pad","pad", .75, .93, .99, .99); + //TPad *pad = new TPad("pad","pad", .75, .93, .99, .99); + TPad *pad = new TPad("pad","pad", .58, .85, .92, .94); pad->SetFillColor(10); pad->Draw(); pad->cd(); TLatex *l = new TLatex(); l->SetTextAlign(12); - l->SetTextSize(0.35); - l->SetTextColor(8); + l->SetTextSize(0.4); + l->SetTextColor(kRed); l->DrawLatex(0.05, 0.65, status.Data()); + + finalCanv->cd(2); + gPad->SetLogy(); + gStyle->SetOptStat("nemrou"); + calibS4_1->SetLineColor(kBlack); + calibS4_1->SetFillColor(kRed); + calibS4_1->GetYaxis()->SetTitle("Number of events"); + calibS4_1->GetYaxis()->SetTitleSize(0.03); + calibS4_1->GetYaxis()->SetTitleOffset(1); + calibS4_1->GetYaxis()->CenterTitle(); + calibS4_1->GetYaxis()->SetLabelSize(0.02); + calibS4_1->GetXaxis()->CenterTitle(); + calibS4_1->GetXaxis()->SetTitleSize(0.03); + calibS4_1->GetXaxis()->SetTitleOffset(1); + calibS4_1->GetXaxis()->SetLabelSize(0.02); + calibS4_1->GetXaxis()->SetTitle("ADC (ch)"); + calibS4_1->SetAxisRange(0,200); + calibS4_1->Draw(); + + finalCanv->cd(3); + gPad->SetLogy(); + gStyle->SetOptStat("nemrou"); + calibS4_2->SetLineColor(kBlack); + calibS4_2->SetFillColor(kRed); + calibS4_2->GetYaxis()->SetTitle("Number of events"); + calibS4_2->GetYaxis()->SetTitleSize(0.03); + calibS4_2->GetYaxis()->SetTitleOffset(1); + calibS4_2->GetYaxis()->CenterTitle(); + calibS4_2->GetYaxis()->SetLabelSize(0.02); + calibS4_2->GetXaxis()->CenterTitle(); + calibS4_2->GetXaxis()->SetTitleSize(0.03); + calibS4_2->GetXaxis()->SetTitleOffset(1); + calibS4_2->GetXaxis()->SetLabelSize(0.02); + calibS4_2->GetXaxis()->SetTitle("ADC (ch)"); + calibS4_2->SetAxisRange(50,250); + calibS4_2->Draw(); + + finalCanv->cd(4); + gPad->SetLogy(); + gStyle->SetOptStat("nemrou"); + calibS4_4->SetLineColor(kBlack); + calibS4_4->SetFillColor(kRed); + calibS4_4->GetYaxis()->SetTitle("Number of events"); + calibS4_4->GetYaxis()->SetTitleSize(0.03); + calibS4_4->GetYaxis()->SetTitleOffset(1); + calibS4_4->GetYaxis()->CenterTitle(); + calibS4_4->GetYaxis()->SetLabelSize(0.02); + calibS4_4->GetXaxis()->CenterTitle(); + calibS4_4->GetXaxis()->SetTitleSize(0.03); + calibS4_4->GetXaxis()->SetTitleOffset(1); + calibS4_4->GetXaxis()->SetLabelSize(0.02); + calibS4_4->GetXaxis()->SetTitle("ADC (ch)"); + calibS4_4->SetAxisRange(500,2500); + calibS4_4->Draw(); + oss.str(""); if (outDir == "./") { oss << filename.Data() << "_S4_Calibration_QL." << format.Data(); } else { oss << outDir.Data() << filename.Data() << "_S4_Calibration_QL." << format.Data(); } - finalCanv->SaveAs(oss.str().c_str()); - - - - - + finalCanv->SaveAs(oss.str().c_str()); } int main(int argc, char* argv[]){ @@ -413,7 +512,7 @@ } } - /* if (!strcmp(argv[i], "-format")){ + if (!strcmp(argv[i], "-format")){ if (++i >= argc){ printf( "-format needs arguments. \n"); printf( "Try '--help' for more information. \n"); @@ -423,7 +522,7 @@ format = argv[i]; continue; } - }*/ + } }