Multiple histograms

I want to create 4 different histograms on 4 different canvases.
Here is my code. Please let me know how to do that-

void clover_all(){

   // open the file
   TFile *f = TFile::Open("run_7_r0.root");
   
   if (f == 0) 
   {
      // if we cannot open the file, print an error message and return immediatly
      printf("Error: cannot open http://lcg-heppkg.web.cern.ch/lcg-heppkg/ROOT/eventdata.root!\n");
   }
   
   //direct way of opening file 
   //std::unique_ptr<TFile> myFile( TFile::Open("Co_60_labr_run.root") );
   
   
   TCanvas *c1 = new TCanvas("c1","Histogram",700,500);  
   TCanvas *c2 = new TCanvas("c2","Histogram",700,500); 
   TCanvas *c3 = new TCanvas("c3","Histogram",700,500); 
   TCanvas *c4 = new TCanvas("c4","Histogram",700,500); 
   

   TTree* t1 = (TTree*) f->Get("TreeMaster");
   
   //t1->Draw("fEXO_ECC_E_Energy:fEXO_ECC_E_Cristal>>h1(16384*2,0,16384,16384*2,0,16384)","","colz");
   //t1->Draw("fEXO_ECC_E_Energy>>cristalA(1000,4500,6500)","fEXO_ECC_E_Cristal=0 && fEXO_ECC_E_Cristal<1","colz");
   c1->cd(1);
   t1->Draw("fEXO_ECC_E_Energy>>cristalA(1000,4500,6500)","fEXO_ECC_E_Cristal>=0 && fEXO_ECC_E_Cristal<1","colz");
   c2->cd(2);
   t1->Draw("fEXO_ECC_E_Energy>>cristalB(1000,4500,6500)","fEXO_ECC_E_Cristal>=1 && fEXO_ECC_E_Cristal<2","colz");
   c3->cd(3);
   t1->Draw("fEXO_ECC_E_Energy>>cristalC(1000,4500,6500)","fEXO_ECC_E_Cristal>=2 && fEXO_ECC_E_Cristal<3","colz");
   c4->cd(4);
   t1->Draw("fEXO_ECC_E_Energy>>cristalD(1000,4500,6500)","fEXO_ECC_E_Cristal=>3 && fEXO_ECC_E_Cristal<4","colz");
   
   
   
}
void clover_all(){
   // open the file
   TFile *f = TFile::Open("run_7_r0.root");

   auto c = new TCanvas("c1","Histogram",700,500);
   c->Divide(2,2);

   TTree* t1 = (TTree*) f->Get("TreeMaster");

   c->cd(1); t1->Draw("fEXO_ECC_E_Energy>>cristalA(1000,4500,6500)","fEXO_ECC_E_Cristal==0");
   c->cd(2); t1->Draw("fEXO_ECC_E_Energy>>cristalB(1000,4500,6500)","fEXO_ECC_E_Cristal==1");
   c->cd(3); t1->Draw("fEXO_ECC_E_Energy>>cristalC(1000,4500,6500)","fEXO_ECC_E_Cristal==2");
   c->cd(4); t1->Draw("fEXO_ECC_E_Energy>>cristalD(1000,4500,6500)","fEXO_ECC_E_Cristal==3");
}

or, in 4 separated canvases:

void clover_all() {

   TFile *f = TFile::Open("run_7_r0.root");

   TTree* t1 = (TTree*) f->Get("TreeMaster");

   auto c1 = new TCanvas("c1","Histogram 1",700,500);
   t1->Draw("fEXO_ECC_E_Energy>>cristalA(1000,4500,6500)","fEXO_ECC_E_Cristal==0");
   auto c2 = new TCanvas("c2","Histogram 2",700,500);
   t1->Draw("fEXO_ECC_E_Energy>>cristalB(1000,4500,6500)","fEXO_ECC_E_Cristal==1");
   auto c3 = new TCanvas("c3","Histogram 3",700,500);
   t1->Draw("fEXO_ECC_E_Energy>>cristalC(1000,4500,6500)","fEXO_ECC_E_Cristal==2");
   auto c4 = new TCanvas("c4","Histogram 4",700,500);
   t1->Draw("fEXO_ECC_E_Energy>>cristalD(1000,4500,6500)","fEXO_ECC_E_Cristal==3");
}
1 Like

Thanks a lot couet!