--- quicklook/QLflightTmtc_Header/HeaderScan.cpp 2006/06/16 10:11:54 1.1 +++ quicklook/QLflightTmtc_Header/HeaderScan.cpp 2006/07/11 14:27:33 1.4 @@ -1,5 +1,5 @@ /** -* Header Scan +* Header_Scan * Author Nagni * version 1.0 * @@ -43,10 +43,26 @@ * There is no default value, without this input the program will not run * TString outDir - the path where to save the output image (Default = ./) * TString format - the format which will be used fo rsave the produced images (Default = "jpg") +* +* +* Version 1.7 +* Date 16 June 2006 - Malvezzi +* +* Description of changes: +* Implementation of the case: numebr of events <= 0. +* Remove graph "grPcktId1"; see PacketScan for the same information. +* Fixed bugs: for a large namber of events is not possible to have vectors, so I have subsituted graphs with histograms +* or divided the graphs in more than one canvas. +* */ - +#include +#include +#include "TLatex.h" +#include "TF1.h" +#include "TPaveText.h" +#include "TMultiGraph.h" #include #include #include "TString.h" @@ -62,271 +78,258 @@ #include "EventHeader.h" #include "PscuHeader.h" - using namespace std; void HeaderScan(TString base, TString outDir, TString format) { - TList *list = new TList; - Int_t numkey; - TObject *key = new TObject; - const char *name; - TTree* tr = new TTree; - Long64_t totevents=0, totphysevents=0; - Float_t id; - Long64_t nevents=0; - + //------------------- Variables initilization -------------------------// + Long64_t nevents=0; + ULong_t lastime, firstime,obt;// offset, lastoffset, firstoffset; + double obmin=0.; + double obmax=0.; + stringstream oss, oss1, oss2, oss3, noentries; //------- load root file -------------- - TFile *file = new TFile(base.Data()); - if (!file){ printf("No such file in the directory has been found"); return; } - if (outDir == "" ) outDir = "."; - - list = file->GetListOfKeys(); - - numkey = file->GetNkeys(); - - pamela::EventHeader *eh=0; - pamela::PscuHeader *ph=0; - ///-----to know the total number f events end of physics events----////// - - for (Int_t i=0; iAt(i); - name=(key->GetName()); - //cout<Get(name); - if (tr->IsZombie()) continue; - nevents = tr->GetEntries(); - totevents+=nevents; - tr->SetBranchAddress("Header", &eh); - for (Int_t j = 0; j < nevents; j++){ - tr->GetEntry(j); - ph = eh->GetPscuHeader(); - if(ph->GetPacketId1() == 0x10) ++totphysevents; - } - - } + TTree *PhysicsTr = (TTree*)file->Get("Physics"); + TBranch *headBr = PhysicsTr->GetBranch("Header"); + + pamela::EventHeader *eh = 0; + pamela::PscuHeader *ph = 0; + + PhysicsTr->SetBranchAddress("Header", &eh); + + nevents = headBr->GetEntries(); - const Long64_t totalevents=totevents; - const Long64_t totalphysevents=totphysevents; - - ///////////////////////////////////////////////// - TString filename = ((TObjString*)base.Tokenize('/')->Last())->GetString(); filename = ((TObjString*)filename.Tokenize('.')->First())->GetString(); - stringstream oss; - oss.str(""); - oss << filename.Data(); - - Float_t obt[totalevents], pcktId[totalevents], pcktLenght[totalphysevents], pcktCounter[totalphysevents], offset[totalevents], allCounter[totalevents]; - Float_t obtphysevents=0; - - totphysevents=0; - totevents=0; - for (Int_t i=0; iAt(i); - name=(char *)(key->GetName()); - tr = (TTree*)file->Get(name); - if (tr->IsZombie()) continue; - tr->SetBranchAddress("Header", &eh); - nevents = tr->GetEntries(); - for (Int_t j = 0; j < nevents; j++){ - tr->GetEntry(j); - ph = eh->GetPscuHeader(); - obt[j+totevents]=ph->GetOrbitalTime() ; - pcktId[j+totevents]=ph->GetPacketId1(); - offset[j+totevents]=ph->GetFileOffset(); - if(pcktId[j+totevents]==16){ - pcktLenght[totphysevents]=ph->GetPacketLenght(); - pcktCounter[totphysevents]=ph->GetCounter(); - totphysevents=totphysevents+1; - } - offset[j+totevents]=ph->GetFileOffset(); - allCounter[j+totevents]= ph->GetCounter(); - } - totevents=totevents+nevents; - } - - - Float_t mintime=obt[0], maxtime=obt[0], minlen=pcktLenght[0], maxlen=pcktLenght[0], mincount=pcktCounter[0], maxcount=pcktCounter[0]; - + //----------- If nevents < = 0 ---------------------------------/ + 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); + l->SetTextColor(2); + noentries.str(""); + noentries<< "HeaderScan_QL:"; + l->DrawLatex(0.05, 0.7, noentries.str().c_str()); + 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(); + } - for (Int_t t=0; tmaxtime) maxtime=obt[t]; - } - for (Int_t t=0; t=maxlen) maxlen=pcktLenght[t]; - if(pcktCounter[t]<=mincount) mincount=pcktCounter[t]; - if(pcktCounter[t]>=maxcount) maxcount=pcktCounter[t]; + canv->Update(); + canv->SaveAs(oss.str().c_str()); + + return; } + + //-------------- to know the max and min OBT ----------------------------// + for (Int_t i = 0; i < nevents; i++){ + headBr->GetEntry(i); + ph = eh->GetPscuHeader(); + obt = ph->GetOrbitalTime(); + //if(obt <= firstime) firstime=obt; + if(obt >= lastime) lastime=obt; + } + //------------------------ First histogram -----------------------------------// + headBr->GetEntry(0); + ph = eh->GetPscuHeader(); + firstime = ph->GetOrbitalTime(); + obmin=firstime; + obmax=lastime; - Float_t nbintime = (maxtime-mintime)/1000; - Float_t nbinlen = (maxlen-minlen)/100; - Float_t nbincount = (maxcount-mincount)/100; - - - ///---------------------------TO GRAPH---------------------------------------------/// + oss1.str(""); + oss1 <<"File name= "<< filename.Data() <<". Start time= " << obmin << ", end time= "<< obmax <<" ms"<<". Physics Packet per minute"; + Int_t nbin = (lastime-firstime)/60000; + TH1F *h1 = new TH1F ("histo1", oss1.str().c_str(), nbin, obmin, obmax); + + //------------- Graph PscuCounter vs FileOffset --------------------------------- + const Int_t size = 10000; + Int_t ev=0; + Double_t PscuCounter[size], FileOffset[size], tempo[size], PcktLenght[size]; + Int_t m=0; + Int_t pag= (nevents/10000)+1; + + TMultiGraph *mg1 = new TMultiGraph(); + oss1.str(""); + oss1 << filename.Data() <<": PscuCounter vs FileOffset."; + mg1->SetTitle(oss1.str().c_str()); + + TMultiGraph *mg2 = new TMultiGraph(); + oss1.str(""); + oss1 << filename.Data() <<": OBT vs FileOffset."; + mg2->SetTitle(oss1.str().c_str()); + + TMultiGraph *mg3 = new TMultiGraph(); + oss2.str(""); + oss2 << filename.Data() <<": Lenght of Physic packets"; + mg3->SetTitle(oss2.str().c_str()); + + TMultiGraph *mg4 = new TMultiGraph(); + oss3.str(""); + oss3 << filename.Data() <<": Physics Counter"; + mg4->SetTitle(oss3.str().c_str()); + TCanvas *finalCanv1 = new TCanvas("Header_1", base, 1280, 1024); - TCanvas *finalCanv2 = new TCanvas("Header_2", base, 1280, 1024); - finalCanv1->Divide(3); + finalCanv1->Divide(1,3); finalCanv1->SetFillColor(10); - finalCanv2->Divide(2); + + TCanvas *finalCanv2 = new TCanvas("Header_2", base, 1280, 1024); + finalCanv2->Divide(1,2); finalCanv2->SetFillColor(10); - - TGraph *grPcktId1 = new TGraph(totalevents, obt, pcktId); - TGraph *grPcktLenght = new TGraph(totalevents, obt, pcktLenght); - TGraph *grPcktCounter = new TGraph(totalevents, obt, pcktCounter); - TGraph *grFileOffset = new TGraph(totalevents, offset, allCounter); - - TGaxis::SetMaxDigits(3); + /////ciclo sulle pagine//////////////////// + for (Int_t interval=0; intervalcd(1); - - stringstream oss1; - oss1.str(""); - oss1 << "OBT (ms) with t0 = " << mintime << "ms"; - - gStyle->SetTitleH(0.06); - grPcktId1->SetTitle(oss.str().c_str()); - grPcktId1->GetXaxis()->SetTitle(oss1.str().c_str()); - grPcktId1->GetXaxis()->CenterTitle(); - grPcktId1->GetXaxis()->SetLabelSize(0.03); - grPcktId1->GetYaxis()->SetTitle("Packet ID"); - grPcktId1->GetYaxis()->CenterTitle(); - grPcktId1->SetMarkerSize(4); - grPcktId1->Draw("AP"); - - - finalCanv1->cd(2); - oss1.str(""); - oss1 << "OBT (min) with t0 = " << mintime << "ms"; - - TH1F *h1 = new TH1F ("h1", oss.str().c_str(), (int)(nbintime/60), mintime, maxtime); - - for (Int_t i=0; iAt(i); - name=(char *)(key->GetName()); - tr = (TTree*)file->Get(name); - if (tr->IsZombie()) continue; - tr->SetBranchAddress("Header", &eh); - nevents = tr->GetEntries(); - for (Int_t j = 0; j < nevents; j++){ - tr->GetEntry(j); - ph = eh->GetPscuHeader(); - if((ph->GetPacketId1()) == 16){ - obtphysevents=ph->GetOrbitalTime(); - h1->Fill(obtphysevents); - } - } + for (Int_t l = 0; l < size; l++){ //ciclo su un sottogruppo + headBr->GetEntry(ev+l); + ph = eh->GetPscuHeader(); + PscuCounter[l]= ph->GetCounter(); // = PcktCounter[l] + FileOffset[l]=ph->GetFileOffset(); + tempo[l]=ph->GetOrbitalTime(); + PcktLenght[l]=ph->GetPacketLenght(); + h1->Fill(ph->GetOrbitalTime()); + m=l; + } + + TGraph *graph1= new TGraph(m, tempo, PcktLenght); + graph1->SetMarkerColor(2); + graph1->SetMarkerSize(.5); + graph1->SetMarkerStyle(21); + mg3->Add(graph1); + + TGraph *graph2= new TGraph(m, tempo, PscuCounter); + graph2->SetMarkerColor(4); + graph2->SetMarkerSize(.5); + graph2->SetMarkerStyle(21); + mg4->Add(graph2); + + TGraph *graph3= new TGraph(m, FileOffset, PscuCounter); + graph3->SetMarkerColor(3); + graph3->SetMarkerSize(.5); + graph3->SetMarkerStyle(21); + mg1->Add(graph3); + + TGraph *graph4= new TGraph(m, FileOffset, tempo); + graph4->SetMarkerColor(kBlue); + graph4->SetMarkerSize(.5); + graph4->SetMarkerStyle(21); + mg2->Add(graph4); + + ev=ev+10000; } - - h1->SetMarkerStyle(6); - h1->GetXaxis()->SetTitle(oss1.str().c_str()); + //------------ First Canvas ---------------------// + + finalCanv1->cd(1); + h1->SetStats(kFALSE); + h1->GetXaxis()->SetTitle("OBT (ms)"); h1->GetXaxis()->CenterTitle(); - h1->GetXaxis()->SetLabelSize(0.03); - h1->GetYaxis()->SetTitle("number of Physic packets"); + h1->GetXaxis()->SetLabelSize(0.04); + h1->GetYaxis()->SetTitle("Number of events "); h1->GetYaxis()->CenterTitle(); + h1->GetYaxis()->SetTitleSize(0.06); + h1->GetYaxis()->SetTitleOffset(0.8); h1->Draw(); - - finalCanv1->cd(3); - oss1.str(""); - oss1 << "OBT (ms) with t0 = " << mintime << "ms"; - - grPcktLenght->SetTitle(oss.str().c_str()); - grPcktLenght->GetXaxis()->SetTitle(oss1.str().c_str()); - grPcktLenght->GetXaxis()->CenterTitle(); - grPcktLenght->GetXaxis()->SetLabelSize(0.03); - grPcktLenght->GetYaxis()->SetTitle("Lenght of Physic packets (byte)"); - grPcktLenght->GetYaxis()->CenterTitle(); - grPcktLenght->GetYaxis()->SetLabelSize(0.03); - grPcktLenght->SetMarkerSize(4); - grPcktLenght->Draw("AP"); - - finalCanv1->cd(2); - h1->Draw(); - - finalCanv1->Update(); - - - ///---------canvas 2-----------------------------// - finalCanv2->cd(1); - - grPcktCounter->SetTitle(oss.str().c_str()); - grPcktCounter->GetXaxis()->SetTitle(oss1.str().c_str()); - grPcktCounter->GetXaxis()->SetTitleSize(0.04); - grPcktCounter->GetXaxis()->CenterTitle(); - grPcktCounter->GetXaxis()->SetLabelSize(0.03); - grPcktCounter->GetYaxis()->SetTitle("PacketCounter of Physic packets"); - grPcktCounter->GetYaxis()->SetTitleSize(0.04); - grPcktCounter->GetYaxis()->CenterTitle(); - grPcktCounter->GetYaxis()->SetLabelSize(0.03); - grPcktCounter->SetMarkerSize(4); - grPcktCounter->SetMinimum(mincount); - grPcktCounter->SetMaximum(maxcount); - grPcktCounter->Draw("AP"); - - finalCanv2->cd(2); - - grFileOffset->SetTitle(oss.str().c_str()); - grFileOffset->GetXaxis()->SetTitle("File Offset"); - grFileOffset->GetXaxis()->CenterTitle(); - grFileOffset->GetXaxis()->SetTitleSize(0.04); - grFileOffset->GetXaxis()->SetLabelSize(0.03); - grFileOffset->GetYaxis()->SetTitle("Packet counter"); - grFileOffset->GetYaxis()->CenterTitle(); - grFileOffset->GetYaxis()->SetTitleSize(0.04); - grFileOffset->GetYaxis()->SetLabelSize(0.03); - grFileOffset->SetMarkerSize(4); - grFileOffset->Draw("AP"); - + mg3->Draw("AP"); + mg3->GetXaxis()->SetTitle("OBT (ms)"); + mg3->GetXaxis()->CenterTitle(); + mg3->GetXaxis()->SetLabelSize(0.04); + mg3->GetYaxis()->SetTitle("Lenght (byte)"); + mg3->GetYaxis()->CenterTitle(); + mg3->GetYaxis()->SetLabelSize(0.04); + mg3->GetYaxis()->SetTitleSize(0.06); + mg3->GetYaxis()->SetTitleOffset(0.8); + + + finalCanv1->cd(3); + mg4->Draw("AP"); + mg4->GetXaxis()->SetTitle("OBT (ms)"); + mg4->GetXaxis()->SetTitleSize(0.05); + mg4->GetXaxis()->CenterTitle(); + mg4->GetXaxis()->SetLabelSize(0.04); + mg4->GetYaxis()->SetTitle("Counter"); + mg4->GetYaxis()->SetTitleSize(0.05); + mg4->GetYaxis()->CenterTitle(); + mg4->GetYaxis()->SetLabelSize(0.04); + mg4->GetYaxis()->SetTitleSize(0.06); + mg4->GetYaxis()->SetTitleOffset(0.8); + finalCanv1->Update(); - - //-------to save---------------------------/// oss.str(""); - oss1.str(""); - oss << outDir.Data() << filename.Data(); - oss1 << outDir.Data() << filename.Data(); - oss << "_HeaderScan_1." << format.Data(); - oss1 << "_HeaderScan_2." << format.Data(); - finalCanv1->SaveAs(oss.str().c_str()); - finalCanv2->SaveAs(oss1.str().c_str()); + + + //------------ Second Canvas ---------------------// + finalCanv2->cd(1); + mg1->Draw("AP"); + mg1->GetXaxis()->SetTitle("File Offset"); + mg1->GetXaxis()->CenterTitle(); + mg1->GetXaxis()->SetTitleSize(0.05); + mg1->GetXaxis()->SetLabelSize(0.04); + mg1->GetYaxis()->SetTitle("Counter"); + mg1->GetYaxis()->CenterTitle(); + mg1->GetYaxis()->SetTitleSize(0.05); + mg1->GetYaxis()->SetLabelSize(0.04); + + finalCanv2->cd(2); + mg2->Draw("AP"); + mg2->GetXaxis()->SetTitle("File Offset"); + mg2->GetXaxis()->CenterTitle(); + mg2->GetXaxis()->SetTitleSize(0.05); + mg2->GetXaxis()->SetLabelSize(0.04); + mg2->GetYaxis()->SetTitle("OBT"); + mg2->GetYaxis()->CenterTitle(); + mg2->GetYaxis()->SetTitleSize(0.05); + mg2->GetYaxis()->SetLabelSize(0.04); + + finalCanv2->Update(); + + oss1.str(""); + oss1 << outDir.Data() << filename.Data(); + oss1 << "_HeaderScan_2"<<"." << format.Data(); + + finalCanv2->SaveAs(oss1.str().c_str()); - file->Close(); + file->Close(); } - - int main(int argc, char* argv[]){ TString path; TString outDir = "./"; TString format = "jpg"; - if (argc < 2){ printf("You have to insert at least the file to analyze \n"); printf("Try '--help' for more information. \n"); exit(1); } - if (!strcmp(argv[1], "--help")){ printf( "Usage: HeaderScan FILE [OPTION] \n"); printf( "\t --help Print this help and exit \n"); @@ -334,12 +337,8 @@ printf( "\t -format[jpg|ps|gif] Format for output files [default 'jpg'] \n"); exit(1); } - - path=argv[1]; - - for (int i = 2; i < argc; i++){ - + for (int i = 2; i < argc; i++){ if (!strcmp(argv[i], "-outDir")){ if (++i >= argc){ printf( "-outDir needs arguments. \n"); @@ -350,8 +349,7 @@ outDir = argv[i]; continue; } - } - + } if (!strcmp(argv[i], "-format")){ if (++i >= argc){ printf( "-format needs arguments. \n"); @@ -363,10 +361,6 @@ continue; } } - - } - HeaderScan(argv[1], outDir, format); - }