Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:21:06

0001 {
0002 
0003   TFile *input_file_1 = new TFile("test35a.root");
0004   TFile *input_file_2 = new TFile("test35b.root");
0005 
0006   TCanvas *c1 = new TCanvas("c1", "test35", 200, 10, 700, 500);
0007   c1->SetGridx();
0008   c1->SetGridy();
0009   c1->SetLogx();
0010   c1->SetLogy();
0011 
0012   // histogram for energy spectra
0013   int n = 41;
0014   float bin[41];
0015   
0016   for (int i = 0; i < n; i++) {
0017     bin[i] =pow(10,(-2+0.1*i));
0018   }
0019   //
0020   TH1 *h_1 = new TH1D("unbiased","Source spectrum",40,bin);
0021   TH1 *h_2 = new TH1D("biased","Source spectrum",40,bin);
0022   input_file_1->cd();
0023   input_file_1->ls();
0024   // get the tuple t1
0025   double energy, weight;
0026   TTree *t1 = (TTree *) input_file_1->Get("MyTuple");
0027   t1->SetBranchAddress("Energy", &energy);
0028   t1->SetBranchAddress("Weight", &weight);
0029   cout <<t1->GetEntries() << endl;
0030   for (int i = 0; i < t1->GetEntries(); i++) {
0031     t1.GetEntry(i);
0032     //    cout << energy << " " << weight << endl;
0033     h_1->Fill(energy,weight);
0034   }
0035   input_file_2->cd();
0036   TTree *t2 = (TTree *) input_file_2->Get("MyTuple");
0037   t2->SetBranchAddress("Energy", &energy);
0038   t2->SetBranchAddress("Weight", &weight);
0039   cout <<t2->GetEntries() << endl;
0040   for (int i = 0; i < t1->GetEntries(); i++) {
0041     t2.GetEntry(i);
0042     h_2->Fill(energy,weight);
0043   }
0044   //  h_2->SetFillColor(kRed);
0045   h_2->SetLineStyle(kDashed);
0046   h_2->SetLineColor(kBlue);
0047   h_2->Draw();
0048   h_1->Draw("same") ;
0049   c1->Update();
0050   c1->Print("./test35.png");
0051   
0052   input_file_1->Close();
0053   input_file_2->Close();
0054 }