空间站数据画图

要求:

image


打开ROOT文件,MakeClass生成两文件:

(ams) zpw@dell:~/Files/0520_iss$ root ISS_001223.root 
   ------------------------------------------------------------------
  | Welcome to ROOT 6.26/10                        https://root.cern |
  | (c) 1995-2021, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for linuxx8664gcc on Nov 17 2022, 16:18:00                 |
  | From tag , 16 November 2022                                      |
  | With                                                             |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q'       |
   ------------------------------------------------------------------

root [0] 
Attaching file ISS_001223.root as _file0...
(TFile *) 0x561bb71cab80
root [1] .ls
TFile**         ISS_001223.root
 TFile*         ISS_001223.root
  KEY: TTree    t1;1    ISS_001223.root
root [2] t1->MakeClass("iss")
Info in <TTreePlayer::MakeClass>: Files: iss.h and iss.C generated from TTree: t1
(int) 0
root [3] .q

image

修改 iss.h 对应部分:

Int_t iss::Cut(Long64_t entry)
{
      if (!(0.5 < q_trk && q_trk < 1.5)) return -1;
      if (!(0.5 < q_tofd && q_tofd < 3)) return -1;
      if (!(0. < rig_i && rig_i < 30)) return -1;
      if (!(beta_rich >0)) return -1;
      if (!(IsNaF == 0)) return -1;

   return 1;
}

image

修改 iss.C 对应部分:

void iss::Loop()
{
   TFile *f = new TFile("iss.root","RECREATE");
   TH1F *h = new TH1F("h","hist of pro",20., 0., 20.);

   if (fChain == 0) return;

   Long64_t nentries = fChain->GetEntriesFast();

   Long64_t nbytes = 0, nb = 0;
   for (Long64_t jentry=0; jentry<nentries;jentry++) {
      Long64_t ientry = LoadTree(jentry);
      if (ientry < 0) break;
      nb = fChain->GetEntry(jentry);   nbytes += nb;
      if (Cut(ientry) < 0) continue;
      h->Fill(nrichhit);
   }
   h->Write();
   f->Write();
   f->Close();
}

image

生成ROOT文件:

(ams) zpw@dell:~/Files/0520_iss$ root iss.C+
   ------------------------------------------------------------------
  | Welcome to ROOT 6.26/10                        https://root.cern |
  | (c) 1995-2021, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for linuxx8664gcc on Nov 17 2022, 16:18:00                 |
  | From tag , 16 November 2022                                      |
  | With                                                             |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q'       |
   ------------------------------------------------------------------

root [0] 
Processing iss.C+...
Info in <TUnixSystem::ACLiC>: creating shared library /home/zpw/Files/0520_iss/./iss_C.so
(iss) @0x55cb437a41b0
root [1] iss hello
(iss &) @0x7fd492fff000
root [2] hello.Loop()
root [3]

image

写个画图脚本Macros: plot.C

void plot()
{
    // open file
    TFile *input=new TFile("./iss.root");

    input->ls();
    auto *c1=new TCanvas();
    // Get histogram
    TH1F *hist=static_cast<TH1F*>(input->Get("h"));

    // setting/style
    gPad->SetLogy();
    gStyle->SetOptStat(0);
    // hist->SetMinimum(1e-5);
    // hist->SetMaximum(1.0);
    hist->Scale(1.0/hist->Integral());
    hist->GetYaxis()->SetRangeUser(1e-5,1.0);
    hist->SetLineColor(kBlue-4);
    // hist->SetMarkerColor(kBlue-4);
    // hist->SetMarkerStyle(2);
    // draw
    // hist->Draw("HIST P");
    hist->Draw("HIST");

    TLegend *leg_line = new TLegend(0.7, 0.8, 0.85, 0.72);
    leg_line->SetTextFont(3);
    leg_line->SetTextSize(25);
    leg_line->SetFillColor(0);
    leg_line->SetLineColor(1);

    leg_line->AddEntry(hist, "proton", "p");
    leg_line->Draw("SAME");

    c1->Print("./pro.png");
}

画出来root -q plot.C

image

**

posted @ 2023-05-20 20:19  zhaopw5  阅读(40)  评论(0编辑  收藏  举报