Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
soft:root [2021/02/08 03:02] Ce Zhangsoft:root [2023/05/24 09:51] (current) – [ROOT study] Ce Zhang
Line 1: Line 1:
 =====ROOT study===== =====ROOT study=====
 +==== Divide ====
 +<code>
 +hHitTime_Ratio[i] = new TH1F(*hHitTime_Num[i]); 
 +hHitTime_Ratio[i]->SetName("hFRSignal"); 
 +hHitTime_Ratio[i]->Divide(hHitTime_Den[i]);
 +</code>
 +==== Sub Canvas and Pads ====
 +<code>
 +TCanvas *c1 = new TCanvas(“c1”, “c1”, w, h);
 +c1->SetWindowSize( w+(w-c1->GetWw()), h+(h-c1->GetWh()) );
 +c1->Divide(2, 1); // … or … gPad->Divide(2, 1);
 +
 +TVirtualPad *c1_1 = c1->cd(1); // enter the first pad
 +gPad->Divide(2, 2); // … or … c1_1->Divide(2, 2);
 +// enter the 4 sub-pads and do stuff
 +c1_1->cd(1); // … or … (c1->cd(1))->cd(1);
 +(new TText(0.1, 0.5, “c1 … 1 … 1”))->Draw(); gPad->Update();
 +c1_1->cd(2); // … or … (c1->cd(1))->cd(2);
 +(new TText(0.1, 0.5, “c1 … 1 … 2”))->Draw(); gPad->Update();
 +c1_1->cd(3); // … or … (c1->cd(1))->cd(3);
 +(new TText(0.1, 0.5, “c1 … 1 … 3”))->Draw(); gPad->Update();
 +c1_1->cd(4); // … or … (c1->cd(1))->cd(4);
 +(new TText(0.1, 0.5, “c1 … 1 … 4”))->Draw(); gPad->Update();
 +</code>
 +
 +==== TF1 ====
 +<code>
 +TF1 * fit1 = new TF1("fit1","[0]*exp([1]*x)",3e-6,9e-6);
 +fit1->SetParameters(0.4,0.4e5);
 +f3->Fit(fit1,"","",3e-6,8e-6);
 +gStyle->SetOptFit(0111);
 +</code>
 +
 +[[https://root.cern.ch/root/htmldoc/guides/users-guide/FittingHistograms.html|gStyle->SetOptFit(1011);]]
 +
 +==== Time ====
 +
 +TDatime
 +
 +<code>
 +TDatime * Time = new TDatime();
 +cout<<Time->AsString()<<" "<<Time->GetDate()<<" "<<Time->GetTime()<<endl;
 +// output: Fri Jul 30 09:56:02 2021 20210730 95602
 +// ...
 +c1->SaveAs(Form("MuonTracks-%d-%d.pdf",Time->GetDate(),Time->GetTime()));
 +</code>
 +==== Get max and mim from TGraph ====
 +
 +<code>
 +TMath::MaxElement(n , g->GetY())
 +</code>
 +
 ==== Draw his from saved .root file in TCanvas ==== ==== Draw his from saved .root file in TCanvas ====
  
Line 24: Line 76:
    h1->Draw();    h1->Draw();
    ae->Draw("L");    ae->Draw("L");
 +</code>
 +
 +<code>
 +TFile *_file0 = TFile::Open("S2areaMuYield_SlineItvScan_210205_tot-Itv-4_TBEAM_0WithReflection_5_hT_reflection_5.0.root");
 +TCanvas *c1 = (TCanvas*)_file0->Get("c0_reflection_hT");
 +TH1D *aee = (TH1D*)c1->GetPrimitive("hT"); // get the name of the histogram, can be obtained by c1->ls()
 +
 </code> </code>
 ====Reset (refresh) the histogram==== ====Reset (refresh) the histogram====