Plotter IN.C

From New IAC Wiki
Jump to navigation Jump to search
include "Riostream.h"
#include "TFile.h"
#include "TTree.h"
#include "TCanvas.h"
#include <TH1.h>
#include <TH2.h>
#include <TString.h>
#include "TLatex.h"
#include <TMath.h>
#include <math.h> 
// In order to run this code as a "macro" in Root, the  main function must
// have the same name as the source file

void plotter_IN()
{
        gROOT->Reset();
        gStyle->SetStatY(0.75);
        gStyle->SetStatX(0.75);
        gStyle->SetStatW(0.1);
        gStyle->SetStatH(0.12);
        //
        // Initialize input filestream and output file pointers 
        //
        int SolenoidField=0;
        double TorusField;
        char ShieldStatus[10]="In";
        int Step_Number;
        int i;
        for(i=0;i<2;i++)                //loop over Torus Field Variables
        {
                Step_Number=i+1;
                TorusField=0.5*Step_Number-1.5;
                printf("ShieldStatus=%s\n",ShieldStatus);
                printf("Step_Number=%d\n",Step_Number);
                char root_name[200];
                char conditions[50];
                double temp;
                printf("TorusField=%.1f\n",TorusField);
                temp=TorusField;
                        printf("temp=%f\n",temp);
                temp=fmod(temp,1.0);
                        printf("Modulus=%f\n",temp);

                if(temp==0.0)
                {
                        sprintf(root_name,"/home/lds/src/CLAS/GEMC/experiments/eg12/MolrBckGrd/DV/Isotropic_study/LH2_%dSol_%dTor_11GeV_IsotropicPhi_Shield%s_v2_6_ON/LH2_%dSol_%dTor_11GeV_IsotropicPhi_Shield%s.root",SolenoidField,$
                        sprintf(conditions,"%dxSol\t %dxTor\t Shield%s",SolenoidField,TorusField,ShieldStatus);
                        
                }
                if(temp!=0.0)
                {
                        sprintf(root_name,"/home/lds/src/CLAS/GEMC/experiments/eg12/MolrBckGrd/DV/Isotropic_study/LH2_%dSol_%.1fTor_11GeV_IsotropicPhi_Shield%s_v2_6_ON/LH2_%dSol_%.1fTor_11GeV_IsotropicPhi_Shield%s.root",SolenoidFi$
                        sprintf(conditions,"%dxSol\t %.1fxTor\t Shield%s",SolenoidField,TorusField,ShieldStatus);
                }
                printf("root name=%s\n",root_name);
                TFile *file = new TFile(root_name); //load the input file
                TCanvas *c = new TCanvas; // make a canvas
                c->SetRightMargin(0.18);
                TText *xlabel = new TText();
                        xlabel-> SetNDC();
                        xlabel -> SetTextAngle(0);
                        xlabel -> SetTextSize(0.03);




        //get the histograms, plot to canvas and save to file
                TH2F *h = (TH2F*)file->Get("MolEThetaLabLUND");
                h->GetZaxis()->SetTitleOffset(1.2);
                h->Draw();
                char png_filename[200];
                sprintf(png_filename,"/home/lds/src/CLAS/GEMC/experiments/eg12/MolrBckGrd/DV/Isotropic_study/ShieldIN_gifs/%s_MolEThetaLabLUND/MolEThetaLabLUND_%d.png",ShieldStatus,Step_Number);
                printf("PNG File=%s\n",png_filename);
                        xlabel -> DrawText(0.6, 0.8,conditions);
                c->Print(png_filename);
                c->Clear();  //clear the canvas for a new histogram

                TH2F *h1 = (TH2F*)file->Get("MolEThetaLabHITS");
                h1->GetZaxis()->SetTitleOffset(1.2);
                h1->Draw();
                char png_filename1[200];
                sprintf(png_filename1,"/home/lds/src/CLAS/GEMC/experiments/eg12/MolrBckGrd/DV/Isotropic_study/ShieldIN_gifs/%s_MolEThetaLabHITS/MolEThetaLabHITS_%d.png",ShieldStatus,Step_Number);
                        xlabel -> DrawText(0.6, 0.8,conditions);
                c->Print(png_filename1);
                c->Clear();

                TH2F *h2 = (TH2F*)file->Get("MolEThetaLabLUNDWeighted");
                h2->GetZaxis()->SetTitleOffset(1.4);
                h2->Draw();
                char png_filename2[200];
                sprintf(png_filename2,"/home/lds/src/CLAS/GEMC/experiments/eg12/MolrBckGrd/DV/Isotropic_study/ShieldIN_gifs/%s_MolEThetaLabLUNDWeighted/MolEThetaLabLUNDWeighted_%d.png",ShieldStatus,Step_Number);
                        xlabel -> DrawText(0.6, 0.8,conditions);
                c->Print(png_filename2);
                c->Clear();

                TH2F *h3 = (TH2F*)file->Get("MolEThetaLabHITSWeighted");
                h3->GetZaxis()->SetTitleOffset(1.2);
                h3->Draw();
                char png_filename3[200];
                sprintf(png_filename3,"/home/lds/src/CLAS/GEMC/experiments/eg12/MolrBckGrd/DV/Isotropic_study/ShieldIN_gifs/%s_MolEThetaLabHITSWeighted/MolEThetaLabHITSWeighted_%d.png",ShieldStatus,Step_Number);
                        xlabel -> DrawText(0.6, 0.8,conditions);
                c->Print(png_filename3);
                c->Clear();

                TH1F *h4 = (TH1F*)file->Get("MolEPhiLabLUND");
                h4->GetZaxis()->SetTitleOffset(1.2);
                h4->Draw();
                char png_filename4[200];
                sprintf(png_filename4,"/home/lds/src/CLAS/GEMC/experiments/eg12/MolrBckGrd/DV/Isotropic_study/ShieldIN_gifs/%s_MolEPhiLabLUND/MolEPhiLabLUND_%d.png",ShieldStatus,Step_Number);
                        xlabel -> DrawText(0.6, 0.8,conditions);
                c->Print(png_filename4);
                c->Clear();

                TH1F *h5 = (TH1F*)file->Get("MolEPhiLabLUNDWeighted");
                h5->GetZaxis()->SetTitleOffset(1.2);
                h5->Draw();
                char png_filename5[200];
                sprintf(png_filename5,"/home/lds/src/CLAS/GEMC/experiments/eg12/MolrBckGrd/DV/Isotropic_study/ShieldIN_gifs/%s_MolEPhiLabLUNDWeighted/MolEPhiLabLUNDWeighted_%d.png",ShieldStatus,Step_Number);
                        xlabel -> DrawText(0.6, 0.8,conditions);
                c->Print(png_filename5);
                c->Clear();

                TH1F *h6 = (TH1F*)file->Get("MolEPhiLabHITS");
                h6->GetZaxis()->SetTitleOffset(1.2);
                h6->Draw();
                char png_filename6[200];
                sprintf(png_filename6,"/home/lds/src/CLAS/GEMC/experiments/eg12/MolrBckGrd/DV/Isotropic_study/ShieldIN_gifs/%s_MolEPhiLabHITS/MolEPhiLabHITS_%d.png",ShieldStatus,Step_Number);
                        xlabel -> DrawText(0.6, 0.8,conditions);
                c->Print(png_filename6);
                c->Clear();

                TH1F *h7 = (TH1F*)file->Get("MolEPhiLabHITSWeighted");
                h7->GetZaxis()->SetTitleOffset(1.2);
                h7->Draw();
                char png_filename7[200];
                sprintf(png_filename7,"/home/lds/src/CLAS/GEMC/experiments/eg12/MolrBckGrd/DV/Isotropic_study/ShieldIN_gifs/%s_MolEPhiLabHITSWeighted/MolEPhiLabHITSWeighted_%d.png",ShieldStatus,Step_Number);
                        xlabel -> DrawText(0.6, 0.8,conditions);
                c->Print(png_filename7);
                c->Clear();

                file->Close();

        }//End of loop
        return 0;
}