Code For Histograms Below

From New IAC Wiki
Jump to navigation Jump to search

int VzDiffDoubleBump() {

 TFile *file = new TFile("eg12_sol_75k_2cm_XYRaster_6cm_ZRaster_30DegRot_rec_cat.root");
 TTree *tree = (TTree*) file->Get("clas12");



 char cut[600];
 char hist_title[600];
 char file_title[600];
                                                                                                                                                                                       
 float Zmax= 0;
 float r = 0;
 c1 = new TCanvas();


 gROOT -> SetBatch(1);
 for(float Zmin = -3.0;Zmin<3.0;Zmin +=0.25)
   {
     for(float r = 0; r<1.0;r+=0.1)
       {
     Zmax = Zmin + 0.25;
 sprintf(cut,"sqrt(GenPart.x*GenPart.x + GenPart.y*GenPart.y)>%.2f && sqrt(GenPart.x*GenPart.x + GenPart.y*GenPart.y)<%.2f && GenPart.z > %.2f && GenPart.z<%.2f",r,r+0.1,Zmin,Zmax);
 sprintf(hist_title,"Vz Difference, %.2f<R<%.2f , %.2f < Z < %.2f",r,r+0.1,Zmin,Zmax);
 sprintf(file_title,"VzDiff_%.2f<R<%.2f_%.2f<Z<%.2f.png",r,r+0.1,Zmin,Zmax);
 TH1F *h1 = new TH1F("h1","h1",120,-6,6);
tree -> Project("h1","GenPart.z - Event.z",cut);
 h1->GetXaxis()->SetTitle("GenPart.x - Event.x (cm)");
 h1 -> GetYaxis() -> SetTitle("Counts");


 h1 -> GetYaxis() -> SetTitleOffset(1.5);
 h1 -> Fit("gaus");
 cout << cut << endl;
 h1 -> Draw();
 h1 -> SetTitle(hist_title);
 gStyle -> SetOptFit(1111);
 c1 -> SaveAs(file_title);


 delete h1;
                                                                                                                                                                                                
       }
                                                                                                                                                                                                 
   }
                          



 return 1;

}