--- quicklook/QLflightTmtc_Header/HeaderScan.cpp 2006/08/31 14:28:32 1.8 +++ quicklook/QLflightTmtc_Header/HeaderScan.cpp 2006/09/26 10:12:11 1.10 @@ -87,23 +87,22 @@ using namespace std; -void HeaderScan(TString base, TString outDir, TString format) -{ +void HeaderScan(TString base, TString outDir, TString format){ - //------------------- Variables initilization -------------------------// Long64_t nevents=0, runnevents; ULong_t lastime, firstime, primotempo, ultimotempo, primoffset=500000000, ultimoffset; - double obmin=0., time=0.; + double obmin=0.; double obmax=0.; stringstream oss, oss1, oss2, oss3, noentries, stringa; - //------- load root file -------------- + + //-------------- Load root file, tree and branch -------------------// TFile *file = new TFile(base.Data()); if (!file){ printf("No such file in the directory has been found"); return; - } - + } + TTree *PhysicsTr = (TTree*)file->Get("Physics"); TBranch *headBr = PhysicsTr->GetBranch("Header"); @@ -111,7 +110,8 @@ pamela::PscuHeader *ph = 0; PhysicsTr->SetBranchAddress("Header", &eh); - nevents = headBr->GetEntries(); + nevents = PhysicsTr->GetEntries(); + const Int_t size = nevents; TTree *RunHeadTr = (TTree*)file->Get("RunHeader"); ///run header tree pamela::EventHeader *eH=0; @@ -121,7 +121,6 @@ RunHeadTr->SetBranchAddress("RunHeader",&reh); runnevents = RunHeadTr->GetEntries(); - TString filename = ((TObjString*)base.Tokenize('/')->Last())->GetString(); filename = ((TObjString*)filename.Tokenize('.')->First())->GetString(); @@ -129,11 +128,9 @@ if (nevents<=0) { printf("nevents = %i \n", nevents); printf(" \n"); - TCanvas *canv = new TCanvas("No entries", "No entries ", 400, 200); canv->SetFillColor(10); canv->cd(); - TLatex *l = new TLatex(); l->SetTextAlign(12); l->SetTextSize(0.15); @@ -144,61 +141,96 @@ noentries.str(""); noentries<< "No Physics entries for this files"; l->DrawLatex(0.05, 0.5, noentries.str().c_str()); - if (outDir == "./") { oss.str(""); oss << filename.Data() << "_HeaderScan_QL." << format.Data(); } else { oss.str(""); oss << outDir.Data() << filename.Data() << "_HeaderScan_QL." << format.Data(); - } - + } canv->Update(); canv->SaveAs(oss.str().c_str()); - return; } - //-------------- to know the max and min OBT ----------------------------// headBr->GetEntry(0); ph = eh->GetPscuHeader(); firstime = ph->GetOrbitalTime(); - - int iii =0; - while(iii < nevents){ - headBr->GetEntry(iii); + headBr->GetEntry(nevents); + ph = eh->GetPscuHeader(); + lastime = ph->GetOrbitalTime(); + int i =0; + while(i < nevents){ + headBr->GetEntry(i); ph = eh->GetPscuHeader(); if((ph->GetOrbitalTime()) <= firstime) firstime=ph->GetOrbitalTime(); if((ph->GetOrbitalTime()) >= lastime) lastime=ph->GetOrbitalTime(); - iii++; + i++; } //------------------------ First histogram -----------------------------------// - obmin=firstime; - obmax=lastime; - - oss1.str(""); - oss1 << filename.Data() <<": Physics Packet per minute. Start time = " << obmin << ", End time = "<< obmax <<" ms"; + obmax=lastime; Int_t nbin = (lastime-firstime)/60000; - //TH1F *h1 = new TH1F ("histo1", oss1.str().c_str(), nbin, obmin, obmax); TH1F *h1 = new TH1F ("histo1", "" , nbin, obmin, obmax); - + + //------------------- fill vectors and histogram -----------------------------// + Double_t *PscuCounter = new Double_t[size]; + Double_t *PacketLenght = new Double_t[size]; + Double_t *OBTime = new Double_t[size]; + Double_t *Eventsperminute= new Double_t[nbin]; + Double_t *Minute= new Double_t[nbin]; + Int_t max=0; + for (Int_t k = 0; k < nevents; k++){ + headBr->GetEntry(k); + ph = eh->GetPscuHeader(); + h1->Fill(ph->GetOrbitalTime()); + PscuCounter[k]= ph->GetCounter(); + PacketLenght[k]=ph->GetPacketLenght(); + OBTime[k]=ph->GetOrbitalTime(); + } + int l=0; + while(lGetBinContent(l); + Minute[l]=firstime+l*60000; + if(h1->GetBinContent(l) >= max)max =(Int_t)h1->GetBinContent(l); + l++; + } + + //----------- Graph and MultiGraph -----------------------------------------------// + TMultiGraph *rate = new TMultiGraph(); + TMultiGraph *packetLength = new TMultiGraph(); + TMultiGraph *packeCounter = new TMultiGraph(); + + oss1.str(""); + oss1 << "Physics Packet per minute. Start time = " << obmin << ", End time = "<< obmax <<" ms"; + TGraph *rate1= new TGraph(nbin, (const Double_t*)Minute, (const Double_t*)Eventsperminute); + rate1->SetMarkerColor(kBlack); + rate1->SetMarkerSize(.1); + rate1->SetMarkerStyle(21); + rate->Add(rate1); + + TGraph *packetLength1= new TGraph(nevents, (const Double_t*)OBTime, (const Double_t*)PacketLenght); oss2.str(""); - oss2 << filename.Data() <<": Lenght of Physic packets"; - Int_t nbin2 =(lastime-firstime); - //TH1F *packetLength = new TH1F ("packetLength", oss2.str().c_str(), nbin2, obmin, obmax); - TH1F *packetLength = new TH1F ("packetLength", "", nbin2, obmin, obmax); + oss2 <<"Lenght of Physic packets"; + packetLength1->SetMarkerColor(2); + packetLength1->SetMarkerSize(.3); + packetLength1->SetMarkerStyle(21); + packetLength->Add(packetLength1); + TGraph *packeCounter1= new TGraph(nevents, (const Double_t*)OBTime, (const Double_t*)PscuCounter); oss3.str(""); - oss3 << filename.Data() <<": Physics Counter vs. OBT"; - // TH1F *packeCounter = new TH1F ("packeCounter", oss3.str().c_str(), nbin2, obmin, obmax); - TH1F *packeCounter = new TH1F ("packeCounter", "", nbin2, obmin, obmax); - //---------------------------------------------------- + oss3 <<"Physics Counter vs. OBT"; + packeCounter1->SetMarkerColor(4); + packeCounter1->SetMarkerSize(.2); + packeCounter1->SetMarkerStyle(21); + packeCounter->Add(packeCounter1); + + //------------ Create and Draw Canvas ---------------------// TCanvas *finalCanv = new TCanvas("Header", base, 1200, 1600); - finalCanv->Divide(1,5); + finalCanv->Divide(1,6); finalCanv->SetFillColor(10); - + TPad *all2= new TPad ("","", 0, 0, 1, 1); all2->SetFillColor(10); TPad *all3= new TPad ("","", 0, 0, 1, 1); @@ -209,44 +241,25 @@ all->SetFillColor(10); TPad *all1= new TPad ("","", 0, 0, 1, 1); all1->SetFillColor(10); - TPad *pad = new TPad("pad","pad", .80,.50,.90,.80); - pad->SetFillColor(10); - //---------------------------------------------------- - - TMultiGraph *mg1 = new TMultiGraph(); - - - TMultiGraph *mg2 = new TMultiGraph(); - - - //-------------------------------------------------------------------------- - for (Int_t l = 0; l < nevents; l++){ - headBr->GetEntry(l); - ph = eh->GetPscuHeader(); - h1->Fill(ph->GetOrbitalTime()); - packetLength->Fill(ph->GetOrbitalTime(),ph->GetPacketLenght()); - packeCounter->Fill(ph->GetOrbitalTime(),ph->GetCounter()); - } - //------------ First Canvas ---------------------// TLine li; li.SetLineStyle(4); li.SetLineWidth(2); - + + //----------- First PAD -------------------------------// finalCanv->cd(1); all2->Draw(); all2->cd(); - - h1->SetStats(kFALSE); - h1->GetXaxis()->SetTitle("OBT (ms)"); - h1->GetXaxis()->CenterTitle(); - h1->GetXaxis()->SetLabelSize(0.04); - h1->GetYaxis()->SetTitle("Number of events "); - h1->GetYaxis()->CenterTitle(); - h1->GetYaxis()->SetLabelSize(0.06); - h1->GetYaxis()->SetTitleSize(0.06); - h1->GetYaxis()->SetTitleOffset(0.6); - h1->Draw(); + rate->Draw("ALP"); + rate->GetXaxis()->SetTitle("OBT (ms)"); + rate->GetXaxis()->SetTitleSize(0.05); + rate->GetXaxis()->CenterTitle(); + rate->GetXaxis()->SetLabelSize(0.05); + rate->GetYaxis()->SetTitle("Number of events "); + rate->GetYaxis()->CenterTitle(); + rate->GetYaxis()->SetLabelSize(0.05); + rate->GetYaxis()->SetTitleSize(0.06); + rate->GetYaxis()->SetTitleOffset(0.6); for (Int_t l = 0; l < runnevents; l++){ RunHeadTr->GetEntry(l); ph = eH->GetPscuHeader(); @@ -255,14 +268,21 @@ Int_t obt = ph->GetOrbitalTime(); if (ws==1){ li.SetLineColor(3); - li.DrawLine(obt,0,obt,h1->GetMaximum()); + li.DrawLine(obt,0,obt,max); } else if (ws==2){ li.SetLineColor(4); - li.DrawLine(obt,0,obt,h1->GetMaximum()); - } - } - + li.DrawLine(obt,0,obt,max); + } + } + + RunHeadTr->GetEntry(0); + ph = eH->GetPscuHeader(); + ULong_t TimeSync = reh->LAST_TIME_SYNC_INFO; + ULong_t ObtSync = reh->OBT_TIME_SYNC; + //cout<<"TimeSync "<LAST_TIME_SYNC_INFO<<"\n"; + //cout<<"ObtSync "<OBT_TIME_SYNC<<"\n"; + finalCanv->cd(1); stringstream ws1, ws2; ws1.str(""); @@ -283,7 +303,6 @@ pt1->SetFillColor(10); pt1->SetBorderSize(0); pt1->Draw(); - // TPaveText *pt1=0; pt1 = new TPaveText (.05,.91,.6,1); pt1->AddText(oss1.str().c_str()); pt1->SetTextColor(1); @@ -291,14 +310,13 @@ pt1->SetBorderSize(0); pt1->Draw(); + //----------- Second PAD -------------------------------// finalCanv->cd(2); all3->Draw(); all3->cd(); - packetLength->SetStats(kFALSE); - packetLength->SetMarkerColor(2); - packetLength->SetMarkerSize(.5); - packetLength->SetMarkerStyle(21); + packetLength->Draw("AP"); packetLength->GetXaxis()->SetTitle("OBT (ms)"); + packetLength->GetXaxis()->SetTitleSize(0.05); packetLength->GetXaxis()->CenterTitle(); packetLength->GetXaxis()->SetLabelSize(0.05); packetLength->GetYaxis()->SetTitle("Lenght (byte)"); @@ -306,9 +324,9 @@ packetLength->GetYaxis()->SetLabelSize(0.05); packetLength->GetYaxis()->SetTitleSize(0.06); packetLength->GetYaxis()->SetTitleOffset(0.6); - packetLength->Draw("9p"); + + finalCanv->cd(2); - //TPaveText *pt=0; pt = new TPaveText (.6,.91,.90,1); pt->AddText(oss2.str().c_str()); pt->SetTextColor(2); @@ -316,14 +334,11 @@ pt->SetBorderSize(0); pt->Draw(); + //----------- Third PAD -------------------------------// finalCanv->cd(3); all4->Draw(); all4->cd(); - packeCounter->GetTitle(); - packeCounter->SetStats(kFALSE); - packeCounter->SetMarkerColor(4); - packeCounter->SetMarkerSize(.2); - packeCounter->SetMarkerStyle(21); + packeCounter->Draw("AP"); packeCounter->GetXaxis()->SetTitle("OBT (ms)"); packeCounter->GetXaxis()->SetTitleSize(0.05); packeCounter->GetXaxis()->CenterTitle(); @@ -334,12 +349,8 @@ packeCounter->GetYaxis()->SetLabelSize(0.05); packeCounter->GetYaxis()->SetTitleSize(0.06); packeCounter->GetYaxis()->SetTitleOffset(0.6); - Double_t min = 500000000.; - for (Int_t l = 0; l < nevents; l++){ - if((packeCounter->GetBinContent(l))<= min && (packeCounter->GetBinContent(l))!= 0) min = packeCounter->GetBinContent(l); - } - packeCounter->SetMinimum(min); - packeCounter->Draw("9p"); + + finalCanv->cd(3); TPaveText *pt2=0; pt2 = new TPaveText (.6,.91,.90,1); @@ -347,10 +358,13 @@ pt2->SetTextColor(4); pt2->SetFillColor(10); pt2->SetBorderSize(0); - pt2->Draw(); - - - //------------------------------------------------- + pt2->Draw(); + + /**********************************************************************************************/ + + TMultiGraph *mg1 = new TMultiGraph(); + TMultiGraph *mg2 = new TMultiGraph(); + //---------------------- fill vectors and histogram --------------------------------------------------// TList *list = new TList; Int_t numkey; TObject *key = new TObject; @@ -359,11 +373,9 @@ Long64_t nevntskey=0; list = file->GetListOfKeys(); numkey = file->GetNkeys(); - int ll=0; - int kk=0; - - for (Int_t i=0; iAt(i); + ULong_t salto; + for (Int_t m=0; mAt(m); name=(char *)(key->GetName()); tr = (TTree*)file->Get(name); if (tr->IsZombie()) continue; @@ -376,35 +388,29 @@ Double_t *PscuCounter1 = new Double_t[size1]; Double_t *FileOffset1 = new Double_t[size1]; Double_t *tempo1 = new Double_t[size1]; - //Double_t *salto= new Double_t[100]; - //Double_t *salto1= new Double_t[100]; - - int l=0; - while(lGetEntry(l); + + int n=0; + while(nGetEntry(n); ph = eh->GetPscuHeader(); - PscuCounter1[l]= ph->GetCounter(); - FileOffset1[l]=ph->GetFileOffset(); - tempo1[l]=ph->GetOrbitalTime(); + PscuCounter1[n]= ph->GetCounter(); + FileOffset1[n]=ph->GetFileOffset(); + tempo1[n]=ph->GetOrbitalTime(); + if((m==0) && (n==0)){ + primotempo=ph->GetOrbitalTime(); + salto=ph->GetOrbitalTime(); + } + if(salto > ph->GetOrbitalTime())salto=ph->GetOrbitalTime(); if(ph->GetFileOffset()<= primoffset){ - primoffset =ph->GetFileOffset(); + primoffset=ph->GetFileOffset(); primotempo=ph->GetOrbitalTime(); } - if(ph->GetFileOffset()>= ultimoffset){ - ultimoffset = ph->GetFileOffset(); - ultimotempo = ph->GetOrbitalTime(); - } - /*if(l>0){ - if(tempo1[l] < tempo1[l-1]){ - salto1[kk] =(const Double_t*)tempo1[l-1]; - salto[ll]= ph->GetOrbitalTime(); - ll=ll+1; - kk=kk+1; - } - }*/ - l++; + if(ph->GetFileOffset()>=ultimoffset){ + ultimotempo=ph->GetOrbitalTime(); + ultimoffset=ph->GetFileOffset(); + } + n++; } - TGraph *graph3= new TGraph(nevntskey, (const Double_t*)FileOffset1, (const Double_t*)PscuCounter1); graph3->SetMarkerColor(3); graph3->SetMarkerSize(.2); @@ -418,32 +424,30 @@ mg2->Add(graph4); } } - - kk=kk-1; - ll=ll-1; TLatex *lat = new TLatex(); lat->SetTextAlign(12); lat->SetTextSize(0.15); lat->SetTextColor(kBlue); - //------------ Second Canvas ---------------------// + + //------------ Fourth PAD ---------------------// finalCanv->cd(4); all1->Draw(); all1->cd(); oss1.str(""); - oss1 << filename.Data() <<": PscuCounter vs FileOffset."; - //mg1->SetTitle(oss1.str().c_str()); + oss1 <<"PscuCounter vs FileOffset."; mg1->Draw("AP"); mg1->GetXaxis()->SetTitle("File Offset"); mg1->GetXaxis()->CenterTitle(); - mg1->GetXaxis()->SetTitleSize(0.045); + mg1->GetXaxis()->SetTitleOffset(0.8); + mg1->GetXaxis()->SetTitleSize(0.05); mg1->GetXaxis()->SetLabelSize(0.05); mg1->GetYaxis()->SetTitle("Counter"); mg1->GetYaxis()->CenterTitle(); - mg1->GetYaxis()->SetTitleSize(0.05); + mg1->GetYaxis()->SetTitleSize(0.06); mg1->GetYaxis()->SetLabelSize(0.06); - mg1->GetYaxis()->SetTitleOffset(0.7); + mg1->GetYaxis()->SetTitleOffset(0.6); finalCanv->cd(4); TPaveText *pt3=0; pt3 = new TPaveText (.60,.91,.90,1); @@ -453,52 +457,75 @@ pt3->SetBorderSize(0); pt3->Draw(); - + //------------ Fifth PAD ---------------------// finalCanv->cd(5); all->Draw(); all->cd(); - oss3.str(""); - oss3 << filename.Data() <<" OBT vs FileOffset. First packet = "<SetTitle(oss3.str().c_str()); + oss3 << "OBT vs FileOffset"; mg2->Draw("AP"); mg2->GetXaxis()->SetTitle("File Offset"); mg2->GetXaxis()->CenterTitle(); - mg2->GetXaxis()->SetTitleSize(0.045); + mg2->GetXaxis()->SetTitleSize(0.05); mg2->GetXaxis()->SetLabelSize(0.05); mg2->GetYaxis()->SetTitle("OBT"); mg2->GetYaxis()->CenterTitle(); - mg2->GetYaxis()->SetTitleSize(0.05); - mg2->GetYaxis()->SetLabelSize(0.055); + mg2->GetYaxis()->SetTitleSize(0.06); + mg2->GetYaxis()->SetLabelSize(0.05); mg2->GetYaxis()->SetTitleOffset(0.6); - /*pad->Draw(); - pad->cd(); - stringa.str(""); - stringa << "new data from "<< primotempo;//<<" to "<< salto1; - lat->DrawLatex(0.08, 0.8, stringa.str().c_str()); - double min2 = 0.8; - if(ll > 0){ - pad->Draw(); - pad->cd(); - for(Int_t k=0; k <(kk); k++){ - stringa.str(""); - stringa << "old data from "<< salto[kk]<< " to "<DrawLatex(0.08, min2,stringa.str().c_str()); - //cout<cd(5); TPaveText *pt4=0; - pt4 = new TPaveText (.38 ,.91,.92,1); + pt4 = new TPaveText (.70,.91,.90,1); pt4->AddText(oss3.str().c_str()); pt4->SetTextColor(kBlue); pt4->SetFillColor(10); pt4->SetBorderSize(0); pt4->Draw(); - // finalCanv->Draw(); + finalCanv->cd(6); + ULong_t primotempoABS=TimeSync+((primotempo/1000)-ObtSync); + ULong_t obmaxABS=TimeSync+((lastime/1000)-ObtSync); + ULong_t saltoABS=TimeSync+((salto/1000)-ObtSync); + ULong_t ultimotempoABS=TimeSync+((ultimotempo/1000)-ObtSync); + + TPaveText *pt5=0; + pt5 = new TPaveText (0,0,1,1); + stringa.str(""); + stringa << " Filename: "<AddText(0.25,0.95,stringa.str().c_str()); + t1->SetTextSize(0.1); + stringa.str(""); + stringa << " OBT (ms) ABS TIME (s)"; + TText *t2=pt5->AddText(0.32,0.75,stringa.str().c_str()); + t2->SetTextSize(0.07); + stringa.str(""); + stringa << "New data start at: "<AddText(0.25,0.60,stringa.str().c_str()); + t3->SetTextSize(0.08); + stringa.str(""); + stringa << "New data end at: "<AddText(0.25,0.50,stringa.str().c_str()); + t4->SetTextSize(0.08); + if(primotempo!=salto || lastime!=ultimotempo){ + stringa.str(""); + stringa << "Old data start at: "<AddText(0.65,0.60,stringa.str().c_str()); + t5->SetTextSize(0.08); + stringa.str(""); + stringa << "Old data end at: "<AddText(0.65,0.50,stringa.str().c_str()); + t6->SetTextSize(0.08); + stringa.str(""); + stringa << " OBT (ms) ABS TIME (s)"; + TText *t2=pt5->AddText(0.72,0.75,stringa.str().c_str()); + t2->SetTextSize(0.07); + } + pt5->SetTextColor(kBlack); + pt5->SetFillColor(10); + pt5->SetBorderSize(0); + pt5->Draw(); + finalCanv->Update(); oss1.str(""); @@ -507,8 +534,6 @@ finalCanv->SaveAs(oss1.str().c_str()); - - file->Close(); }