/[PAMELA software]/quicklook/QLflightTmtc_Header/HeaderScan.cpp
ViewVC logotype

Diff of /quicklook/QLflightTmtc_Header/HeaderScan.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1.1.2 by pam-rm2, Sat Jun 17 11:02:09 2006 UTC revision 1.6 by pam-rm2, Wed Aug 9 09:01:23 2006 UTC
# Line 1  Line 1 
1  /**  /**
2  * Header Scan  * Header_Scan
3  * Author  Nagni  * Author  Nagni
4  * version 1.0  * version 1.0
5  *  *
# Line 49  Line 49 
49  * Date 16 June 2006 - Malvezzi  * Date 16 June 2006 - Malvezzi
50  *  *
51  * Description of changes:  * Description of changes:
52  *                         Implementation of case: numebr of events are <= 0.  *                         Implementation of the case: numebr of events <= 0.
53  *                         Remove of the graph "grPcktId1"; see PacketScan for the same information.  *                         Remove graph "grPcktId1"; see PacketScan for the same information.
54  *             Fixed bugs: for a large namber of events is not possible to have vectors, so all graphs have been converted in histograms  *             Fixed bugs: for a large namber of events is not possible to have vectors, so I have subsituted graphs with histograms
55    *                         or divided the graphs in more than one canvas.
56    *
57    * Version 1.8
58    * Date 8 August 2006 - Malvezzi
59    *
60    * Description: changed the scale in the second and third graph of the first canvas; added a pad of text in the second canvas
61  *  *
62  */  */
63    
# Line 83  void HeaderScan(TString base, TString ou Line 89  void HeaderScan(TString base, TString ou
89  {  {
90    
91    //------------------- Variables initilization -------------------------//    //------------------- Variables initilization -------------------------//
92      Long64_t nevents=0;
93    TList *list = new TList;    ULong_t lastime, firstime, primotempo, ultimotempo, primoffset=500000000, ultimoffset=100000000;
   Int_t numkey;  
   TObject *key = new TObject;  
   const char *name;  
   //TTree* tr = new TTree;  
   //TTree* tr1 = new TTree;  
   Long64_t nevents=0; // ev=0, events=0;  
   ULong_t lastime, firstime;  
94    double obmin=0.;    double obmin=0.;
95    double obmax=0.;    double obmax=0.;
96    double obt;    stringstream oss, oss1, oss2, oss3, noentries, stringa;
   ULong_t maxoffset, minoffset;  
   Float_t  pcktLenght =0., pcktCounter=0., offset=0., allCounter=0.;  
   stringstream oss, oss1, oss2, oss3, noentries;  
97    //------- load root file --------------    //------- load root file --------------
98    TFile *file = new TFile(base.Data());    TFile *file = new TFile(base.Data());
99    if (!file){    if (!file){
100      printf("No such file in the directory has been found");      printf("No such file in the directory has been found");
101      return;      return;
102    }    }
   if (outDir == "" ) outDir = ".";  
   list = file->GetListOfKeys(); //get list of trees in the file  
   numkey = file->GetNkeys();   //get number of trees in the file  
103        
104    TTree *PhysicsTr = (TTree*)file->Get("Physics");    TTree *PhysicsTr = (TTree*)file->Get("Physics");
105    TBranch *headBr = PhysicsTr->GetBranch("Header");    TBranch *headBr = PhysicsTr->GetBranch("Header");
# Line 117  void HeaderScan(TString base, TString ou Line 110  void HeaderScan(TString base, TString ou
110    PhysicsTr->SetBranchAddress("Header", &eh);    PhysicsTr->SetBranchAddress("Header", &eh);
111    
112    nevents = headBr->GetEntries();    nevents = headBr->GetEntries();
   const Int_t sizetot = nevents;  
113    
114    TString filename = ((TObjString*)base.Tokenize('/')->Last())->GetString();    TString filename = ((TObjString*)base.Tokenize('/')->Last())->GetString();
115    filename = ((TObjString*)filename.Tokenize('.')->First())->GetString();    filename = ((TObjString*)filename.Tokenize('.')->First())->GetString();
# Line 156  void HeaderScan(TString base, TString ou Line 148  void HeaderScan(TString base, TString ou
148      return;      return;
149    }    }
150    
151      //-------------- to know the max and min OBT ----------------------------//
152    ///-------------- to know the max and min File Offset ----------------------------//     headBr->GetEntry(0);
153    /*for (Int_t i=0; i<numkey; i++){     ph = eh->GetPscuHeader();
154      key = list->At(i);     firstime = ph->GetOrbitalTime();
155      name=(key->GetName());  
156      tr = (TTree*)file->Get(name);     for (Int_t i = 0; i < nevents; i++){
157      if (tr->IsZombie()) continue;      headBr->GetEntry(i);
158      events = tr->GetEntries();      ph = eh->GetPscuHeader();
159      tr->SetBranchAddress("Header", &eh);        if((ph->GetOrbitalTime()) <= firstime) firstime=ph->GetOrbitalTime();
160      for (Int_t j = 0; j < events; j++){      if((ph->GetOrbitalTime()) >= lastime) lastime=ph->GetOrbitalTime();
161        tr->GetEntry(j);      }
162        ph = eh->GetPscuHeader();    
       ph->GetFileOffset();  
       if(ph->GetFileOffset() <= minoffset) minoffset=ph->GetFileOffset();  
       if(ph->GetFileOffset() >= maxoffset) maxoffset=ph->GetFileOffset();  
     }  
     }*/  
   //*************************** Histograms ************************************************************//  
163    //------------------------ First histogram -----------------------------------//    //------------------------ First histogram -----------------------------------//
164    headBr->GetEntry(0);    
165    ph = eh->GetPscuHeader();     obmin=firstime;
166    firstime = ph->GetOrbitalTime();     obmax=lastime;  
167    headBr->GetEntry(nevents-1);    
   ph = eh->GetPscuHeader();  
   lastime = ph->GetOrbitalTime();  
   obmin=firstime;  
   obmax=lastime;    
168    oss1.str("");    oss1.str("");
169    oss1 << filename.Data() << ": Physics Packet per minute;" <<" start @ " << firstime << ", end @ "<< lastime <<"ms";    oss1 << filename.Data() <<": Physics Packet per minute.  Start time = " << obmin << ", End time = "<< obmax <<" ms";
170    Int_t  nbin   = (lastime-firstime)/60000;    Int_t  nbin   = (lastime-firstime)/60000;
171    TH1F *h1 = new TH1F ("histo1", oss1.str().c_str(), nbin, obmin, obmax);    TH1F *h1 = new TH1F ("histo1", oss1.str().c_str(), nbin, obmin, obmax);
172    
   //------------------------ Second histogram -----------------------------------//  
173    oss2.str("");    oss2.str("");
174    oss2 << filename.Data() << ": Lenght of Physic packets;";    oss2 << filename.Data() <<": Lenght of Physic packets";
175    Int_t nint = (lastime-firstime);    Int_t  nbin2  =(lastime-firstime);
176    TH1F *PcktLenght = new TH1F ("histo2", oss2.str().c_str(), nint, obmin, obmax);    TH1F *packetLength = new TH1F ("packetLength", oss2.str().c_str(), nbin2, obmin, obmax);
177    
  //------------------------ Third histogram -----------------------------------//  
178    oss3.str("");    oss3.str("");
179    oss3 << filename.Data() << ": Physics Counter";    oss3 << filename.Data() <<": Physics Counter";
180    TH1F *PcktCounter = new TH1F ("histo3", oss3.str().c_str(), nint, obmin, obmax);    TH1F *packeCounter = new TH1F ("packeCounter", oss3.str().c_str(), nbin2, obmin, obmax);
181      //----------------------------------------------------
182      TCanvas *finalCanv1 = new TCanvas("Header_1", base, 1280, 1150);
183      finalCanv1->Divide(1,3);
184      finalCanv1->SetFillColor(10);
185      TPad *all2= new TPad ("","", 0, 0, 1, 1);
186      all2->SetFillColor(10);
187      TPad *all3= new TPad ("","", 0, 0, 1, 1);
188      all3->SetFillColor(10);
189      TPad *all4= new TPad ("","", 0, 0, 1, 1);
190      all4->SetFillColor(10);
191      //----------------------------------------------------
192      TCanvas *finalCanv2 = new TCanvas("Header_2", base, 1280, 1150);
193      finalCanv2->Divide(1,2);
194      finalCanv2->SetFillColor(10);
195    
196   //------------------------ Fourth histogram -----------------------------------//    TMultiGraph *mg1 = new TMultiGraph();
197    /*oss3.str("");    oss1.str("");
198    oss3 << filename.Data() << ": Packet Counter";    oss1 << filename.Data() <<": PscuCounter vs FileOffset.";
199    Int_t nintoffset = (maxoffset-minoffset)/10;    mg1->SetTitle(oss1.str().c_str());
   TH1F *FileOffset = new TH1F ("histo4", oss3.str().c_str(), nintoffset, minoffset, maxoffset);  
   */  
   //**************************************************************************************************//  
   //------- fill histograms ---------//  
200    
201    for (Int_t i = 0; i < nevents; i++){    TMultiGraph *mg2 = new TMultiGraph();
     headBr->GetEntry(i);  
     ph = eh->GetPscuHeader();  
     obt = ph->GetOrbitalTime();    
     pcktLenght=ph->GetPacketLenght();  
     pcktCounter=ph->GetCounter();  
     h1->Fill(obt);    
     PcktLenght->Fill(obt,pcktLenght);    
     PcktCounter->Fill(obt,pcktCounter);  
   }  
202    
203    /*for (Int_t i=0; i<numkey; i++){    TPad *all= new TPad ("","", 0, 0, 1, 1);
204      key = list->At(i);    all->SetFillColor(10);
205      name=(char *)(key->GetName());    TPad *all1= new TPad ("","", 0, 0, 1, 1);
206      tr1 = (TTree*)file->Get(name);    all1->SetFillColor(10);
207      if (tr1->IsZombie()) continue;    TPad *pad = new TPad("pad","pad", .80,.50,.90,.80);
208      tr1->SetBranchAddress("Header", &eh);    pad->SetFillColor(10);
209      ev = tr1->GetEntries();    //--------------------------------------------------------------------------
210      for (Int_t j = 0; j < ev; j++){     for (Int_t l = 0; l < nevents; l++){
211        tr1->GetEntry(j);        headBr->GetEntry(l);
212        ph = eh->GetPscuHeader();      ph = eh->GetPscuHeader();  
213        offset=ph->GetFileOffset();      h1->Fill(ph->GetOrbitalTime());
214        allCounter= ph->GetCounter();      packetLength->Fill(ph->GetOrbitalTime(),ph->GetPacketLenght());
215        FileOffset->Fill(offset,allCounter);      packeCounter->Fill(ph->GetOrbitalTime(),ph->GetCounter());
216      }     }  
217      }*/  
218      //------------ First Canvas ---------------------//
   //****************************** Canvases *******************************//  
   //TGaxis::SetMaxDigits(4);  
   //------------------- First Canvas --------------------------------//  
   TCanvas *finalCanv1 = new TCanvas("Header_1", base, 1280, 1024);  
   finalCanv1->Divide(1,3);  
   finalCanv1->SetFillColor(10);  
219    
220    finalCanv1->cd(1);    finalCanv1->cd(1);
221      all2->Draw();
222      all2->cd();
223    h1->SetStats(kFALSE);    h1->SetStats(kFALSE);
224    h1->GetXaxis()->SetTitle("OBT   (ms)");    h1->GetXaxis()->SetTitle("OBT   (ms)");
225    h1->GetXaxis()->CenterTitle();    h1->GetXaxis()->CenterTitle();
# Line 253  void HeaderScan(TString base, TString ou Line 230  void HeaderScan(TString base, TString ou
230    h1->GetYaxis()->SetTitleOffset(0.8);    h1->GetYaxis()->SetTitleOffset(0.8);
231    h1->Draw();    h1->Draw();
232        
233    
234    finalCanv1->cd(2);    finalCanv1->cd(2);
235    PcktLenght->SetStats(kFALSE);    all3->Draw();
236    PcktLenght->GetXaxis()->SetTitle("OBT    (ms)");    all3->cd();
237    PcktLenght->GetXaxis()->CenterTitle();    packetLength->SetStats(kFALSE);
238    PcktLenght->GetXaxis()->SetLabelSize(0.04);    packetLength->SetMarkerColor(2);
239    PcktLenght->GetYaxis()->SetTitle("Lenght  (byte)");    packetLength->SetMarkerSize(.5);
240    PcktLenght->GetYaxis()->CenterTitle();    packetLength->SetMarkerStyle(21);
241    PcktLenght->GetYaxis()->SetLabelSize(0.04);    packetLength->GetXaxis()->SetTitle("OBT    (ms)");
242    PcktLenght->GetYaxis()->SetTitleSize(0.06);    packetLength->GetXaxis()->CenterTitle();
243    PcktLenght->GetYaxis()->SetTitleOffset(0.8);    packetLength->GetXaxis()->SetLabelSize(0.04);
244    PcktLenght->SetMarkerColor(2);    packetLength->GetYaxis()->SetTitle("Lenght  (byte)");
245    PcktLenght->SetMarkerSize(.5);    packetLength->GetYaxis()->CenterTitle();
246    PcktLenght->SetMarkerStyle(21);    packetLength->GetYaxis()->SetLabelSize(0.04);
247    PcktLenght->Draw("9p");    packetLength->GetYaxis()->SetTitleSize(0.06);
248      packetLength->GetYaxis()->SetTitleOffset(0.8);
249      packetLength->Draw("9p");
250    
251    finalCanv1->cd(3);    finalCanv1->cd(3);
252    PcktCounter->SetStats(kFALSE);    all4->Draw();
253    PcktCounter->GetXaxis()->SetTitle("OBT    (ms)");    all4->cd();
254    PcktCounter->GetXaxis()->SetTitleSize(0.05);    packeCounter->SetStats(kFALSE);
255    PcktCounter->GetXaxis()->CenterTitle();    packeCounter->SetMarkerColor(4);
256    PcktCounter->GetXaxis()->SetLabelSize(0.04);    packeCounter->SetMarkerSize(.5);
257    PcktCounter->GetYaxis()->SetTitle("Counter");    packeCounter->SetMarkerStyle(21);
258    PcktCounter->GetYaxis()->SetTitleSize(0.05);    packeCounter->GetXaxis()->SetTitle("OBT    (ms)");
259    PcktCounter->GetYaxis()->CenterTitle();    packeCounter->GetXaxis()->SetTitleSize(0.05);
260    PcktCounter->GetYaxis()->SetLabelSize(0.04);    packeCounter->GetXaxis()->CenterTitle();
261    PcktCounter->GetYaxis()->SetTitleSize(0.06);    packeCounter->GetXaxis()->SetLabelSize(0.04);
262    PcktCounter->GetYaxis()->SetTitleOffset(0.8);    packeCounter->GetYaxis()->SetTitle("Counter");
263    PcktCounter->SetMarkerColor(4);    packeCounter->GetYaxis()->SetTitleSize(0.05);
264    PcktCounter->SetMarkerSize(.5);    packeCounter->GetYaxis()->CenterTitle();
265    PcktCounter->SetMarkerStyle(21);    packeCounter->GetYaxis()->SetLabelSize(0.04);
266    PcktCounter->Draw("9p");    packeCounter->GetYaxis()->SetTitleSize(0.06);
267    //--------- Second Canvas -----------------------------//    packeCounter->GetYaxis()->SetTitleOffset(0.8);
268    /*TCanvas *finalCanv2 = new TCanvas("Header_2", base, 1280, 1024);    Double_t min = 500000000.;
269    finalCanv2->Divide(1,2);     for (Int_t l = 0; l < nevents; l++){
270    finalCanv2->SetFillColor(10);       if((packeCounter->GetBinContent(l))<=  min && (packeCounter->GetBinContent(l))!= 0) min = packeCounter->GetBinContent(l);
271       }  
272    finalCanv2->cd(1);    packeCounter->SetMinimum(min);
273    PcktCounter->SetStats(kFALSE);    packeCounter->Draw("9p");
   PcktCounter->GetXaxis()->SetTitle("OBT    (ms)");  
   PcktCounter->GetXaxis()->SetTitleSize(0.05);  
   PcktCounter->GetXaxis()->CenterTitle();  
   PcktCounter->GetXaxis()->SetLabelSize(0.04);  
   PcktCounter->GetYaxis()->SetTitle("Counter");  
   PcktCounter->GetYaxis()->SetTitleSize(0.05);  
   PcktCounter->GetYaxis()->CenterTitle();  
   PcktCounter->GetYaxis()->SetLabelSize(0.04);  
   PcktCounter->SetMarkerColor(4);  
   PcktCounter->SetMarkerSize(.5);  
   PcktCounter->SetMarkerStyle(21);  
   PcktCounter->Draw("9p");  
     
   finalCanv2->cd(2);  
   FileOffset->SetStats(kFALSE);  
   FileOffset->GetXaxis()->SetTitle("File Offset");  
   FileOffset->GetXaxis()->CenterTitle();  
   FileOffset->GetXaxis()->SetTitleSize(0.05);  
   FileOffset->GetXaxis()->SetLabelSize(0.04);  
   FileOffset->GetYaxis()->SetTitle("Counter");  
   FileOffset->GetYaxis()->CenterTitle();  
   FileOffset->GetYaxis()->SetTitleSize(0.05);  
   FileOffset->GetYaxis()->SetLabelSize(0.04);  
   FileOffset->SetMarkerColor(3);  
   FileOffset->SetMarkerSize(.5);  
   FileOffset->SetMarkerStyle(21);  
   FileOffset->Draw("9p");*/  
274        
   //-------to save---------------------------///  
275    oss.str("");    oss.str("");
   oss1.str("");  
     
276    oss << outDir.Data() << filename.Data();    oss << outDir.Data() << filename.Data();
   oss1 << outDir.Data() << filename.Data();  
   
277    oss  << "_HeaderScan_1." << format.Data();    oss  << "_HeaderScan_1." << format.Data();
   oss1 << "_HeaderScan_2." << format.Data();  
     
278    finalCanv1->SaveAs(oss.str().c_str());    finalCanv1->SaveAs(oss.str().c_str());
   //finalCanv2->SaveAs(oss1.str().c_str());  
279        
280    file->Close();    //-------------------------------------------------
281      TList *list = new TList;
282      Int_t numkey;
283      TObject *key = new TObject;
284      const char *name;
285      TTree* tr = new TTree;
286      Long64_t nevntskey=0;
287      list = file->GetListOfKeys();
288      numkey = file->GetNkeys();
289    
290      const Int_t size1 = 10000;
291      Int_t ev1=0;
292      Double_t PscuCounter1[size1], FileOffset1[size1], tempo1[size1], salto[size1];
293      Int_t pag1=0;
294      Int_t m1=0;
295      Int_t ll=0;
296    
297      for (Int_t i=0; i<numkey; i++){
298        key = list->At(i);
299        name=(char *)(key->GetName());
300        tr = (TTree*)file->Get(name);
301        if (tr->IsZombie()) continue;
302        tr->SetBranchAddress("Header", &eh);
303        TBranch *Br = tr->GetBranch("Header");
304        nevntskey = tr->GetEntries();
305        m1=0;
306        pag1= (nevntskey/10000)+1;
307     /////ciclo sulle pagine////////////////////
308      for (Int_t interval1=0; interval1<pag1; interval1++){
309    
310       for (Int_t l = 0; l < size1; l++){     //ciclo su un sottogruppo
311        Br->GetEntry(ev1+l);
312        ph = eh->GetPscuHeader();  
313        PscuCounter1[l]= ph->GetCounter(); // = PcktCounter[l]
314        FileOffset1[l]=ph->GetFileOffset();
315        tempo1[l]=ph->GetOrbitalTime();
316        if(ph->GetFileOffset()<= primoffset){
317          primoffset =ph->GetFileOffset();
318          primotempo=ph->GetOrbitalTime();
319        }
320        if(ph->GetFileOffset()>= ultimoffset){
321          ultimoffset = ph->GetFileOffset();
322          ultimotempo = ph->GetOrbitalTime();
323        }
324        if(l>0){
325          if(tempo1[l] < tempo1[l-1]){
326            salto[ll]= ph->GetOrbitalTime();
327            ll=ll+1;
328              }
329        }
330        
331        m1=l;
332       }  
333    
334       TGraph *graph3= new TGraph(m1, FileOffset1, PscuCounter1);
335       graph3->SetMarkerColor(3);
336       graph3->SetMarkerSize(.5);
337       graph3->SetMarkerStyle(21);
338       mg1->Add(graph3);
339    
340       TGraph *graph4= new TGraph(m1, FileOffset1, tempo1);
341       graph4->SetMarkerColor(kBlue);
342       graph4->SetMarkerSize(.5);
343       graph4->SetMarkerStyle(21);
344       mg2->Add(graph4);
345    
346       ev1=ev1+10000;
347      }
348      }
349    
350      
351        TLatex *lat = new TLatex();
352        lat->SetTextAlign(12);
353        lat->SetTextSize(0.15);
354        lat->SetTextColor(kBlue);
355        
 }  
356    
357      //------------ Second Canvas ---------------------//
358       finalCanv2->cd(1);
359       all1->Draw();
360       all1->cd();
361       mg1->Draw("AP");
362       mg1->GetXaxis()->SetTitle("File Offset");
363       mg1->GetXaxis()->CenterTitle();
364       mg1->GetXaxis()->SetTitleSize(0.05);
365       mg1->GetXaxis()->SetLabelSize(0.04);
366       mg1->GetYaxis()->SetTitle("Counter");
367       mg1->GetYaxis()->CenterTitle();
368       mg1->GetYaxis()->SetTitleSize(0.05);
369       mg1->GetYaxis()->SetLabelSize(0.03);
370    
371       finalCanv2->cd(2);
372       all->Draw();
373       all->cd();
374      
375       oss3.str("");
376       oss3 << filename.Data() <<" OBT vs FileOffset.  First packet = "<<primotempo <<" ms,  Last packet = "<<ultimotempo<<" ms.";
377       mg2->SetTitle(oss3.str().c_str());
378       mg2->Draw("AP");
379       mg2->GetXaxis()->SetTitle("File Offset");
380       mg2->GetXaxis()->CenterTitle();
381       mg2->GetXaxis()->SetTitleSize(0.05);
382       mg2->GetXaxis()->SetLabelSize(0.04);
383       mg2->GetYaxis()->SetTitle("OBT");
384       mg2->GetYaxis()->CenterTitle();
385       mg2->GetYaxis()->SetTitleSize(0.05);
386       mg2->GetYaxis()->SetLabelSize(0.03);
387       double min2 = 0.8;
388       if(ll-1 > 0){
389       pad->Draw();
390       pad->cd();
391        stringa.str("");
392        stringa << "jump back at:";
393        lat->DrawLatex(0.08, min2, stringa.str().c_str());
394        for(Int_t kk=0; kk <(ll-1); kk++){
395          stringa.str("");
396          stringa << salto[kk];
397          min2=min2-0.1;
398          lat->DrawLatex(0.08, min2,stringa.str().c_str());
399          //cout<<salto[kk]<<";\n";
400        }
401      }
402    
403       finalCanv2->Update();
404    
405    
406    
407    
408    
409       oss1.str("");
410       oss1 << outDir.Data() << filename.Data();
411       oss1 << "_HeaderScan_2"<<"." << format.Data();
412    
413       finalCanv2->SaveAs(oss1.str().c_str());
414      
415       file->Close();
416      
417    }
418    
419  int main(int argc, char* argv[]){  int main(int argc, char* argv[]){
420    TString path;    TString path;
421    TString outDir     = "./";    TString outDir     = "./";

Legend:
Removed from v.1.1.1.2  
changed lines
  Added in v.1.6

  ViewVC Help
Powered by ViewVC 1.1.23