Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:22:32

0001 // Draw Longitudinal Shower Profile
0002 
0003 #include "TH1D.h"
0004 #include "TFile.h"
0005 #include "THStack.h"
0006 #include "TCanvas.h"
0007 #include "TString.h"
0008 #include "TLegend.h"
0009 
0010 TCanvas* cmpE()
0011 {
0012   // TString dataDir("/net/llrdata1.in2p3.fr/data/DATA/data.harpo/BH5D/");
0013   TString dataDir("./");
0014 
0015   TString dataFile[2];
0016   dataFile[0] = "gflash00.root";
0017   dataFile[1] = "gflash01.root";
0018 
0019   TFile* f[2];
0020   TH1D*  p[2];
0021   //  UInt_t col[] = { kRed, kBlue, kGreen, kViolet };
0022   UInt_t col[] = {kRed, kGreen, kBlue, kViolet};
0023   //  UInt_t mark[] = { 20, 32, 21, 22};
0024   UInt_t mark[] = {20, 21, 32, 22};
0025   //
0026   THStack* hs = new THStack("hs", "");
0027 
0028   for ( UInt_t i = 0; i < 2; i++ ) {
0029     TString tmp = dataDir + dataFile[i];
0030     f[i]        = TFile::Open(tmp);
0031     if ( ! f[i] ) return 0;
0032     p[i] = (TH1D*)(f[i])->Get("h0");
0033     // ShiftUp(p[i],0.0);
0034     // histogram
0035     p[i]->SetFillColor(col[i]);
0036     p[i]->SetLineStyle(i + 2);
0037     p[i]->SetLineColor(col[i]);
0038     p[i]->SetLineWidth(2);
0039     p[i]->SetMarkerStyle(mark[i]);
0040     p[i]->SetMarkerColor(col[i]);
0041     p[i]->SetMarkerSize(1.5);
0042     hs->Add(p[i]);
0043   }
0044   TCanvas* cst = new TCanvas("cst", "stacked hists", 10, 10, 800, 700);
0045   // gPad->SetGrid();
0046   hs->Draw("p,nostack");
0047   hs->SetTitle("Total Energy");
0048   hs->GetXaxis()->SetTitle("E/E_{tot} (%)");
0049   //  hs->GetYaxis()->SetTitle("No of events");
0050 
0051   cst->RedrawAxis();
0052   cst->Update();
0053 
0054   TLegend* legend = new TLegend(0.65, 0.84, 0.94, 0.94);
0055    legend->AddEntry(p[0],
0056      Form("full  - E %5.3f #sigma %5.3f",p[0]->GetMean(),p[0]->GetRMS()),"p");
0057   legend->AddEntry(p[1],
0058      Form("gflash - E %5.3f #sigma %5.3f",p[1]->GetMean(),p[1]->GetRMS()),"p");
0059   legend->Draw();
0060   cst->Update();
0061 
0062   // img->FromPad(c, 10, 10, 300, 200);
0063 
0064   // TImage *img = TImage::Create();
0065 
0066   // img->FromPad(cst);
0067 
0068   // img->WriteImage("hist0-640MeV-p.png");
0069 
0070   // for (UInt_t i = 0; i < 4; i++) {
0071   // f[i]->Close();
0072   // }
0073   return cst;
0074 }