Ejemplo n.º 1
0
// Print all canvases in a single PS file
void printCanvasesPS(TString name){
  TPostScript * ps = new TPostScript(name,112);
  TIter iter(gROOT->GetListOfCanvases());
  TCanvas *c;
  while( (c = (TCanvas *)iter()) )
    {
      cout << "Printing " << c->GetName() << endl;
      ps->NewPage();
      c->Draw();
    }
  cout << " File " << name << " was created" << endl;
  ps->Close();
}
Ejemplo n.º 2
0
// main file
int main(int argc, char** argv){

  gROOT->SetBatch(kTRUE);
  gROOT->SetStyle("Plain");
  gStyle->SetOptStat(0);

  TPostScript *ps = new TPostScript("histogramszee_minuit.ps");
  TFile *zeecomp = new TFile("zeecomp_minuit.root", "recreate");
  TCanvas *c1 =  new TCanvas("aaa","c1",50,10,700,800);   // these 2 crazy lines are needed
  ps->NewPage();                                          // for proper alignment of the 1st page

  TString data_file = argv[1];
  TString mc_file = argv[2];

  if(argc!=5 && argc!=6) {
    cout<<" Please run it the following way: " << endl
	<<" ./zeecomp_minuit  <full_mc_root_file_name>  <pmcs_root_file_name_after_MINUIT>  <make_chi2_option>  <compare_option>  [rows_per_page]"
	<< endl << endl;  
    cout<<" If <make_chi2_option>=1 then CHI plots will be created too."<<endl;  
    cout<<" Use <compare_option>=0  for comparing DATA with Fast-MC after MINUIT fit (PMCS)," << endl
        <<"     <compare_option>=1  for comparing Full-MC (GEANT) with Fast-MC (PMCS, after MINUIT fit)," << endl
        <<"     <compare_option>=2  for comparing Fast-MC (PMCS)  with Fast-MC (PMCS, after MINUIT fit)," << endl
        <<"     <compare_option>=3  for comparing Fast-MC (PMCS, after MINUIT fit) with Fast-MC (PMCS, after MINUIT fit)." << endl << endl;
    cout<<" For example: ./zeecomp_minuit  data.root             fastmc_minuit.root   0 0"<<endl
        <<"              ./zeecomp_minuit  fullmc.root           fastmc_minuit.root   0 1"<<endl
        <<"              ./zeecomp_minuit  fastmc.root           fastmc_minuit.root   0 2"<<endl
        <<"              ./zeecomp_minuit  fastmc_minuit1.root   fastmc_minuit2.root  0 3"<<endl << endl;
    cout<<" If <make_chi2_option>=1 then CHI plots will be created too."<<endl;  
    cout<<" For example: ./zeecomp_minuit  fullmc.root   fastmc_minuit.root  0  1"<<endl<<endl;
    return 1;
  }

  // make chi2 plot
  int chi2_option = atoi(argv[3]);
  bool make_chi2 = false;
  if(chi2_option>0) make_chi2 = true;

  //DATA/MC PLOTS
  TFile *fdata = new TFile(data_file, "OLD");// first file (index=0 in getHistogramsFromData/getHistogramsFromPMCS)
  TFile *fpmcs = new TFile(mc_file, "OLD");  // second file (index=1 in getHistogramsFromData/getHistogramsFromPMCS)
  if(!fdata || !fpmcs) {
    cout << "Can't open first and/or second file !!!" << endl;
    if(fdata) fdata->Close();
    if(fpmcs) fpmcs->Close();
    return 1;
  }

  // make compare option
  int compare_option = atoi(argv[4]);
  switch(compare_option) {
  case 0:    // 0 for data - fast MC (MINUIT part) 
    set_DATA_label("DATA");         // first file, upper label
    set_MC_label("FAST MC");        // second file, bottom label
    if(!(fdata->cd("ZCand_Hist") && fpmcs->cd("smeared"))){
      cout<<" ==> compare option = 0, Are you comparing DATA to FAST-MC ??? Aborted"<<endl;
      if(fdata) fdata->Close();
      if(fpmcs) fpmcs->Close();
      return 1;
    }
    getHistogramsFromData_MINUITonly(fdata, 0, false);// will assume the first file is REAL data
    getHistogramsFromPMCS_MINUITonly(fpmcs, 1);       // will assume the second file is PMCS (MINUIT fit)
    cout<<" Red histogram for the first file (DATA), Blue histogram for the second file (PMCS)"<<endl;
    break;
  case 1:   // 1 for full MC - fast MC (MINUIT part) 
    set_DATA_label("FULL MC");      // first file, upper label
    set_MC_label("FAST MC");        // second file, bottom label
    if(!(fdata->cd("ZCand_Hist") && fpmcs->cd("smeared"))){
      cout<<" ==> compare option = 1, Are you comparing FULL-MC to FAST-MC ??? Aborted"<<endl;
      if(fdata) fdata->Close();
      if(fpmcs) fpmcs->Close();
      return 1;
    }
    getHistogramsFromData_MINUITonly(fdata, 0, true);// will assume the first file is FULL MC
    getHistogramsFromPMCS_MINUITonly(fpmcs, 1);      // will assume the second file is PMCS (MINUIT fit)
    cout<<" Red histogram for the first file (FULL MC), Blue histogram for the second file (PMCS)"<<endl;
    break;
  case 2:   // 2 for fast MC (default) - fast MC (MINUIT part) 
    set_DATA_label("FAST MC - default");  // first file, upper label
    set_MC_label("FAST MC - MINUIT fit"); // second file, bottom label
    if(!(fdata->cd("smeared") && fpmcs->cd("smeared"))){
      cout<<" ==> compare option = 2, Are you comparing FAST-MC to FAST-MC ??? Aborted"<<endl;
      if(fdata) fdata->Close();
      if(fpmcs) fpmcs->Close();
      return 1;
    }
    getHistogramsFromPMCS(fdata, 0);            // will assume the first file is PMCS (default)
    getHistogramsFromPMCS_MINUITonly(fpmcs, 1); // will assume the second file is PMCS (MINUIT fit) 
    cout<<" Red histogram for the first file (FULL MC), Blue histogram for the second file (PMCS)"<<endl;
    break;
  case 3:   // 3 for fast MC (MINUIT part) - fast MC (MINUIT part) 
    set_DATA_label("FAST MC - MINUIT fit #1"); // first file, upper label
    set_MC_label("FAST MC - MINUIT fit #2");   // second file, bottom label
    if(!(fdata->cd("smeared") && fpmcs->cd("smeared"))){
      cout<<" ==> compare option = 3, Are you comparing FAST-MC to FAST-MC ??? Aborted"<<endl;
      if(fdata) fdata->Close();
      if(fpmcs) fpmcs->Close();
      return 1;
    }
    getHistogramsFromPMCS_MINUITonly(fdata, 0); // will assume the first file is PMCS (MINUIT fit) 
    getHistogramsFromPMCS_MINUITonly(fpmcs, 1); // will assume the second file is PMCS (MINUIT fit) 
    cout<<" Red histogram for the first file (FULL MC), Blue histogram for the second file (PMCS)"<<endl;
    break;
  default:  // UNKNOWN
    cout<<"Wrong <compare_option>="<<compare_option<<" !!!"<<endl;
    if(fdata) fdata->Close();
    if(fpmcs) fpmcs->Close();
    return 1;
  };

  // max plots/page
  int plots_per_page = 10;
  if(argc==6 && atoi(argv[5])>0) plots_per_page=atoi(argv[5]);
  
  ////////////////////////////////////////////////////////////////////////////
#define FULLRANGE {-1E30, 1E30}
  typedef struct {
    char *cname;
    vector<TH1 *> *vect;
    const double rangeX[2]; } canvas_t; canvas_t plot[]= {
    { "hEtaImbalance",     hetaimbalance,     FULLRANGE},
    { "deltaPhi_Z_Recoil", hdeltaPhi_Z_Recoil,FULLRANGE}};
  const int nplots=sizeof(plot)/sizeof(canvas_t);

  typedef struct {
    char *cname;
    int property;         // 0=MEAN, 1=RMS
    int distribution;     // 0=Eta Imbalance, 1=Xi Imbalance
    vector<TH1 *> *inputY, *inputX;
    TGraphErrors *plot1[2], *plot2[2], *plotCHI[2];  // index: 0=non-fitted
    double *chi2;                                    //        1=from gauss fit
  } canvasMeanRms_t;
  canvasMeanRms_t plotMeanRms[]= { 
    { "etaimbalance_mean_compare", 0, 0,
      hetaimbalance, h_smearUt_binno,
      { mean_etaimbalance_ge1[0], mean_etaimbalance_ge1[1] },
      { mean_etaimbalance_ge2[0], mean_etaimbalance_ge2[1] },
      { mean_etaimbalance_ge_chi[0], mean_etaimbalance_ge_chi[1] },
      chi2_mean_EtaImbalance },
    { "etaimbalance_width_compare", 1, 0,
      hetaimbalance, h_smearUt_binno,
      { width_etaimbalance_ge1[0], width_etaimbalance_ge1[1] }, 
      { width_etaimbalance_ge2[0], width_etaimbalance_ge2[1] }, 
      { width_etaimbalance_ge_chi[0], width_etaimbalance_ge_chi[1] },
      chi2_width_EtaImbalance }
  };
 const int nplotsMeanRms=sizeof(plotMeanRms)/sizeof(canvasMeanRms_t);

  typedef struct {
    char *cname;
    vector<TH1 *> *inputY, *inputX;
    TGraphErrors *plot1[2], *plot2[2], *plotCHI[2];  // index: 0=non-fitted
    double *chi2;                                    //        1=from gauss fit
  } canvasRmsDeltaPhiZRecoil_t;
  canvasRmsDeltaPhiZRecoil_t plotRmsDeltaPhiZRecoil[]= { 
    { "deltaphiimbalance_compare",
      hdeltaPhi_Z_Recoil, h_smearUt_binno,
      { deltaphimbalance_ge1[0], deltaphimbalance_ge1[1] },
      { deltaphimbalance_ge2[0], deltaphimbalance_ge2[1] },
      { deltaphimbalance_chi[0], deltaphimbalance_chi[1] },
      chi2_deltaphimbalance }
  };
  const int nplotsRmsDeltaPhiZRecoil=sizeof(plotRmsDeltaPhiZRecoil)/sizeof(canvasRmsDeltaPhiZRecoil_t);

  // too many bins for eta-imbalance and xi-imbalance
  // will rebin them here
  for(int i=0; i<hetaimbalance[0].size(); i++) {
    (hetaimbalance[0])[i]->Rebin(2);
    (hetaimbalance[1])[i]->Rebin(2);
  }
 
  for(int iplot=0; iplot<nplots; iplot++) {
    // avoid blank pages for non-existing histograms
    if((plot[iplot].vect)[0].size() && (plot[iplot].vect)[1].size()) {
      plot_util(plot[iplot].cname, (plot[iplot].vect)[0], (plot[iplot].vect)[1], make_chi2, 
		plot[iplot].rangeX[0], plot[iplot].rangeX[1], ps, plots_per_page, zeecomp);
    }
  }

  // plot::plot_util() now operates on copies of input histograms
  // and it does not scale the originals. 
  // Here we calculate: mean value of EtaImbalance (property=0, distribution=0) 
  //                    mean value of XiImbalance  (property=0, distribution=1)
  //                    rms value of EtaImbalance (property=1, distribution=0) 
  //                    rms value of XiImbalance  (property=1, distribution=1).
  for(int iplot=0; iplot<nplotsMeanRms; iplot++) {
    // avoid blank pages for non-existing histograms
    if((plotMeanRms[iplot].inputY)[0].size() && (plotMeanRms[iplot].inputY)[1].size() && (plotMeanRms[iplot].inputX)[1].size()) {
      plot_MeanSigma_pTeeBin(plotMeanRms[iplot].cname, 
			     (plotMeanRms[iplot].inputY)[0], (plotMeanRms[iplot].inputY)[1], (plotMeanRms[iplot].inputX)[0], 
			     (plotMeanRms[iplot].plot1)[0], (plotMeanRms[iplot].plot2)[0], (plotMeanRms[iplot].plotCHI)[0], // non-fitted
			     (plotMeanRms[iplot].plot1)[1], (plotMeanRms[iplot].plot2)[1], (plotMeanRms[iplot].plotCHI)[1], // fitted
			     plotMeanRms[iplot].property, plotMeanRms[iplot].distribution, make_chi2, 
			     plotMeanRms[iplot].chi2[0], // non-fitted
			     plotMeanRms[iplot].chi2[1], // fitted
			     ps, plots_per_page, zeecomp );
    }
  }

  // plot::plot_util() now operates on copies of input histograms
  // and it does not scale the originals. 
  // Here sigma of Phi(Z)-Phi(Recoil) distribution (centered at PI) from histogram 
  // |Phi(Z)-Phi(Recoil)| is calculated. A standard RMS won't work in this case.  
  for(int iplot=0; iplot<nplotsRmsDeltaPhiZRecoil; iplot++) {
    // avoid blank pages for non-existing histograms
    if((plotRmsDeltaPhiZRecoil[iplot].inputY)[0].size() && (plotRmsDeltaPhiZRecoil[iplot].inputY)[1].size() && (plotRmsDeltaPhiZRecoil[iplot].inputX)[1].size()) {
      plot_SigmaDeltaPhiZRecoil_pTeeBin
	(plotRmsDeltaPhiZRecoil[iplot].cname, 
	 (plotRmsDeltaPhiZRecoil[iplot].inputY)[0], 
	 (plotRmsDeltaPhiZRecoil[iplot].inputY)[1], (plotRmsDeltaPhiZRecoil[iplot].inputX)[0], 
	 (plotRmsDeltaPhiZRecoil[iplot].plot1)[0], (plotRmsDeltaPhiZRecoil[iplot].plot2)[0], (plotRmsDeltaPhiZRecoil[iplot].plotCHI)[0], // non-fitted
	 (plotRmsDeltaPhiZRecoil[iplot].plot1)[1], (plotRmsDeltaPhiZRecoil[iplot].plot2)[1], (plotRmsDeltaPhiZRecoil[iplot].plotCHI)[1], // fitted
	 make_chi2, 
	 plotRmsDeltaPhiZRecoil[iplot].chi2[0], // non-fitted
	 plotRmsDeltaPhiZRecoil[iplot].chi2[1], // fitted
	 ps, plots_per_page, zeecomp );
    }
  }

  ps->Close();
  zeecomp->Write("All");
  zeecomp->Close();
}
Ejemplo n.º 3
0
// main function
int main(int argc, char** argv){

  gROOT->SetBatch(kTRUE);
  gROOT->SetStyle("Plain");
  gStyle->SetOptStat(0);

  TPostScript *ps = new TPostScript("histogramsznunu.ps");
  TFile *znunucomp = new TFile("znunucomp.root", "recreate");
  TCanvas *c1 =  new TCanvas("aaa","c1",50,10,700,800);   // these 2 crazy lines are needed
  ps->NewPage();                                          // for proper alignment of the 1st page

  TString data_file = argv[1];
  TString mc_file = argv[2];

  //DATA/MC PLOTS
  TFile *fdata = new TFile(data_file, "OLD"); // first file (index=0 in getHistogramsFromFile)
  TFile *fpmcs = new TFile(mc_file, "OLD");   // second file (index=1 in getHistogramsFromFile)
  if(!fdata || !fpmcs) {
    cout << "Can't open first and/or second file !!!" << endl;
    if(fdata) fdata->Close();
    if(fpmcs) fpmcs->Close();
    return 1;
  }

  if(argc!=5 && argc!=6) {
    cout<<" Please run it the following way: "
	<<" ./znunucomp  <first_root_file_name>  <second_root_file_name>  <make_chi2_option>  <compare_option>  [rows_per_page]" 
	<< endl <<endl
	<<" If <make_chi2_option>=1 then CHI plots will be created too."<<endl
	<<" Use <compare_option>=0  for comparing Full-MC (GEANT) with Fast-MC (PMCS)," << endl
        <<"     <compare_option>=1  for comparing Full-MC (GEANT) with Full-MC (GEANT)," << endl
	<<"     <compare_option>=2  for comparing Fast-MC (PMCS) with Fast-MC (PMCS)." << endl << endl;
    return 1;
  }

  // make chi2 plot
  int chi2_option = atoi(argv[3]);
  bool make_chi2 = false;
  if(chi2_option>0) make_chi2 = true;

  // make compare option
  int compare_option = atoi(argv[4]);
  switch(compare_option) {
  case 0:   // 0 for full MC - fast MC 
    set_DATA_label("FULL MC");      // first file, upper label
    set_MC_label("FAST MC");        // second file, bottom label
    if(!(fdata->cd("ZNuNuCand_Hist") && fpmcs->cd("default"))){
      cout<<" ==> compare option = 0, Are you comparing FULL-MC to FAST-MC ??? Aborted"<<endl;
      if(fdata) fdata->Close();
      if(fpmcs) fpmcs->Close();
      return 1;
    }
    getHistogramsFromFile(fdata, 0, true); // will assume the first file is FULL MC
    getHistogramsFromFile(fpmcs, 1, false);// will assume the second file is PMCS
    cout<<" Red histogram for the first file (FULL MC), Blue histogram for the second file (PMCS)"<<endl;
    break;
  case 1:    // 1 for full MC - full MC 
    set_DATA_label("FULL MC #1");   // first file, upper label
    set_MC_label("FULL MC #2");     // second file, bottom label
    if(!(fdata->cd("ZNuNuCand_Hist") && fpmcs->cd("ZNuNuCand_Hist"))){
      cout<<" ==> compare option = 1, Are you comparing FULL-MC to FULL-MC ??? Aborted"<<endl;
      if(fdata) fdata->Close();
      if(fpmcs) fpmcs->Close();
      return 1;
    }
    getHistogramsFromFile(fdata, 0, true);// will assume the first file is FULL MC
    getHistogramsFromFile(fpmcs, 1, true);// will assume the second file is FULL MC
    cout<<" Red histogram for the first FULL MC file, Blue histogram for the second FULL MC file"<<endl;    
    break;
  case 2:    // 2 for fast MC - fast MC 
    set_DATA_label("FAST MC #1");   // first file, upper label
    set_MC_label("FAST MC #2");     // second file, bottom label
    if(!(fdata->cd("default") && fpmcs->cd("default"))){
      cout<<" ==> compare option = 2, Are you comparing FAST-MC to FAST-MC ??? Aborted"<<endl;
      if(fdata) fdata->Close();
      if(fpmcs) fpmcs->Close();
      return 1;
    }
    getHistogramsFromFile(fdata, 0, false);// will assume the first file is PMCS
    getHistogramsFromFile(fpmcs, 1, false);// will assume the second file is PMCS
    cout<<" Red histogram for the first PMCS file, Blue histogram for the second PMCS file"<<endl;
    break;
  default:  // UNKNOWN
    cout<<"Wrong <compare_option>="<<compare_option<<" !!!"<<endl;
    if(fdata) fdata->Close();
    if(fpmcs) fpmcs->Close();
    return 1;
  };

  // max plots/page
  int plots_per_page = 10;
  if(argc==6 && atoi(argv[5])>0) plots_per_page=atoi(argv[5]);

  ////////////////////////////////////////////////////////////////////////////
  typedef struct {
    char *cname;
    vector<TH1 *> *vect;
  } canvas_t;
  canvas_t plot[]= {
    {"ZNuNu_genZPt_Cuts", GenZPt_Cuts},
    {"ZNuNu_genZPt_Cuts_bin", GenZPt_Cuts_bin},
    {"ZNuNu_genZPt_Cuts_genZPtBin", GenZPt_Cuts_genZPtBin},
    {"ZNuNu_genZPhi_Cuts", GenZPhi_Cuts},
    {"ZNuNu_genZPhi_Cuts_bin", GenZPhi_Cuts_bin},
    {"ZNuNu_genZPhi_Cuts_genZPtBin", GenZPhi_Cuts_genZPtBin},
    {"ZNuNu_genVtxZ_Cuts", GenVtxZ_Cuts},
    {"ZNuNu_genVtxZ_Cuts_bin", GenVtxZ_Cuts_bin},
    {"ZNuNu_genVtxZ_Cuts_genZPtBin", GenVtxZ_Cuts_genZPtBin},
    {"ZNuNu_RecoilPt_Cuts", RecoilPt_Cuts},
    {"ZNuNu_RecoilPt_Cuts_bin", RecoilPt_Cuts_bin},
    {"ZNuNu_RecoilPt_Cuts_genZPtBin", RecoilPt_Cuts_genZPtBin},
    {"ZNuNu_RecoilPx_Cuts", RecoilPx_Cuts},
    {"ZNuNu_RecoilPx_Cuts_bin", RecoilPx_Cuts_bin},
    {"ZNuNu_RecoilPx_Cuts_genZPtBin", RecoilPx_Cuts_genZPtBin},
    {"ZNuNu_RecoilPy_Cuts", RecoilPy_Cuts},
    {"ZNuNu_RecoilPy_Cuts_bin", RecoilPy_Cuts_bin},
    {"ZNuNu_RecoilPy_Cuts_genZPtBin", RecoilPy_Cuts_genZPtBin},
    {"ZNuNu_RecoilPhi_Cuts", RecoilPhi_Cuts},
    {"ZNuNu_RecoilPhi_Cuts_bin", RecoilPhi_Cuts_bin},
    {"ZNuNu_RecoilPhi_Cuts_genZPtBin", RecoilPhi_Cuts_genZPtBin},
    {"ZNuNu_RecoilResolution_Cuts", RecoilResolution_Cuts},
    {"ZNuNu_RecoilResolution_Cuts_bin", RecoilResolution_Cuts_bin},
    {"ZNuNu_RecoilResolution_Cuts_genZPtBin", RecoilResolution_Cuts_genZPtBin},
    {"ZNuNu_DeltaPhi_genZ_Recoil_Cuts", DeltaPhi_genZ_Recoil_Cuts},
    {"ZNuNu_DeltaPhi_genZ_Recoil_Cuts_bin", DeltaPhi_genZ_Recoil_Cuts_bin},
    {"ZNuNu_DeltaPhi_genZ_Recoil_Cuts_genZPtBin", DeltaPhi_genZ_Recoil_Cuts_genZPtBin},
    {"ZNuNu_Met_Cuts", Met_Cuts},
    {"ZNuNu_Met_Cuts_bin", Met_Cuts_bin},
    {"ZNuNu_Met_Cuts_genZPtBin", Met_Cuts_genZPtBin},
    {"ZNuNu_MetPhi_Cuts", MetPhi_Cuts},
    {"ZNuNu_MetPhi_Cuts_bin", MetPhi_Cuts_bin},
    {"ZNuNu_MetPhi_Cuts_genZPtBin", MetPhi_Cuts_genZPtBin},
    {"ZNuNu_MetX_Cuts", MetX_Cuts},
    {"ZNuNu_MetX_Cuts_bin", MetX_Cuts_bin},
    {"ZNuNu_MetX_Cuts_genZPtBin", MetX_Cuts_genZPtBin},
    {"ZNuNu_MetY_Cuts", MetY_Cuts},
    {"ZNuNu_MetY_Cuts_bin", MetY_Cuts_bin},
    {"ZNuNu_MetY_Cuts_genZPtBin", MetY_Cuts_genZPtBin},
    {"ZNuNu_ScalarEt_Cuts", ScalarEt_Cuts},
    {"ZNuNu_ScalarEt_Cuts_bin", ScalarEt_Cuts_bin},
    {"ZNuNu_ScalarEt_Cuts_genZPtBin", ScalarEt_Cuts_genZPtBin},
    {"ZNuNu_RecoilResponse_V_RecoilPt_Cuts", RecoilResponse_V_Recoilt_Cuts},
    {"ZNuNu_RecoilResponse_V_genZPt_Cuts", RecoilResponse_V_genZPt_Cuts},
    {"ZNuNu_RecoilResponseProjection_V_RecoilPt_Cuts", RecoilResponseProjection_V_RecoilPt_Cuts},
    {"ZNuNu_RecoilResponseProjection_V_genZPt_Cuts", RecoilResponseProjection_V_genZPt_Cuts}
  };
  const int nplots=sizeof(plot)/sizeof(canvas_t);
  // plot::plot_util() now operates on copies of input histograms
  // and it does not scale the originals. 
  for(int iplot=0; iplot<nplots; iplot++) {
    plot_util(plot[iplot].cname, (plot[iplot].vect)[0], (plot[iplot].vect)[1], make_chi2, -1E30, 1E30, ps, plots_per_page, znunucomp );
  }
  ////////////////////////////////////////////////////////////////////////////
 
  ps->Close();
  znunucomp->Write("All");
  znunucomp->Close();
}
Ejemplo n.º 4
0
void run_alt_smooth(){
  gROOT->LoadMacro("Fitter.cpp");
  TPostScript *myps = new TPostScript("upara_eff_check022008_check.ps",111);
  // mass range
  double xmin = 50., xmax = 130.;
  
  // data
  TFile *data=new TFile("result_0221.root");
  gDirectory->cd("ZCand_Hist");
  
  const Int_t NBins = 15; //2 gev upara bins
  const Int_t NBinsX = 100; //1 gev mass bins
   
  TH2D *before = (TH2D *)gROOT->FindObject("ZCandUPara_V_Mass_NoCuts");
  TH2D *after = (TH2D *)gROOT->FindObject("ZCandUPara_V_Mass_BothWithGoodSpatialMatch_IsoHMxCut");
  
  //these x bins are mass
  int rbinpt = 4;
  before->RebinX(rbinpt);

  after->RebinX(rbinpt);
 
  //y bins are upara:
  int rbinupara = 8;
  before->RebinY(rbinupara);
  after->RebinY(rbinupara);
    
  Int_t NBins_X = before->GetNbinsX();
  Double_t Axis_XMin = before->GetXaxis()->GetXmin();
  Double_t Axis_XMax = before->GetXaxis()->GetXmax();
  
  if(NBins_X != NBinsX) {
    cout<<"NBins="<<NBinsX<<" while NBins_X="<<NBins_X<<" make sure they are the same"<<endl;
    exit;
  }
  
  Int_t NBins_Y = before->GetNbinsY();
  Double_t Axis_YMin = before->GetYaxis()->GetXmin();
  Double_t Axis_YMax = before->GetYaxis()->GetXmax();
  cout<<"Mass bin "<<NBins_Y<<" from "<<Axis_YMin<<" to "<<Axis_YMax<<endl;
  
  // 1D histogram
  TH1D *before_mass[NBins], *after_mass[NBins], *diff_mass[NBins], *bkgnd_mass[NBins];
  double variable[NBins], variable_err[NBins];
  
  char name[50];
  for (int ybin = 0; ybin <NBins_Y; ybin ++){   //include underflow, but doesnt go to upper limit. 
                                                 //not really a problem because there are few events there
                                                 //and we know the correct position anyway. 
    sprintf(name, "%s%d", "before_", ybin);
    before_mass[ybin] = new TH1D(name, name, NBins_X, Axis_XMin, Axis_XMax);
    sprintf(name, "%s%d", "after_", ybin);
    after_mass[ybin] = new TH1D(name, name, NBins_X, Axis_XMin, Axis_XMax);
    sprintf(name, "%s%d", "diff_", ybin);
    diff_mass[ybin] =  new TH1D(name, name, NBins_X, Axis_XMin, Axis_XMax);
    
    variable[ybin] = before->GetYaxis()->GetBinCenter(ybin);
    variable_err[ybin] = 1.0;
    
    for(int xbin=0; xbin < NBins_X; xbin ++) {
      
      cout<<"x,y: "<<xbin<<","<<ybin<<" before "<<before->GetBinContent(xbin, ybin)<<" after "<<after->GetBinContent(xbin, ybin)<<" diff " << (before->GetBinContent(xbin, ybin) - after->GetBinContent(xbin, ybin))<< endl;
      before_mass[ybin] -> SetBinContent(xbin, before->GetBinContent(xbin, ybin));
      after_mass[ybin] -> SetBinContent(xbin, after->GetBinContent(xbin, ybin));
      diff_mass[ybin]-> SetBinContent(xbin, (before->GetBinContent(xbin, ybin) - after->GetBinContent(xbin, ybin)) );
    }
   before_mass[ybin]->Draw();
  }
  
  // signal
  TFile *mc = new TFile("signal.root");
  gDirectory->cd("smeared");

  TH2D *sig2 = (TH2D *)gROOT->FindObject("smeared_hZcandMass_V_UPara_CCCC");
  sig2->RebinY(rbinupara);  //here x is the mass, y is upara
  //sig2->RebinX(rbinpt);  //here x is the mass, y is upara
  
  Int_t NBins_X = sig2->GetNbinsX();
  Double_t Axis_XMin = sig2->GetXaxis()->GetXmin();
  Double_t Axis_XMax = sig2->GetXaxis()->GetXmax();
   
  Int_t NBins_Y = sig2->GetNbinsY();
  Double_t Axis_YMin = sig2->GetYaxis()->GetXmin();
  Double_t Axis_YMax = sig2->GetYaxis()->GetXmax();
  cout<<"upara bin "<<NBins_Y<<" from "<<Axis_YMin<<" to "<<Axis_YMax<<endl;
  
  if(NBins_Y != NBins) {
    cout<<"NBins="<<NBins<<" while NBins_Y="<<NBins_Y<<" make sure they are the same"<<endl;
    exit;
  }
   
  cout<<"NBinsx="<<NBinsX<<" while NBins_X="<<NBins_X<<" make sure they are the same"<<endl;
  NBins_X = NBinsX;
  Axis_XMin = 50.;

  // 1D histogram
  TH1D *Sig_All[NBins];
  double variable[NBins], variable_err[NBins];
  TH1D *QCDBkg_All[NBins];
  
  //now for the bkg histogram:
  TFile *data=new TFile("result_bkg.root");
  gDirectory->cd("ZCand_Hist");
  TH2D *bkgnd = (TH2D *)gROOT->FindObject("ZCandUPara_V_Mass_0");
  bkgnd->RebinX(rbinupara); //upara is x
  bkgnd->RebinY(4); //mass is y. great
  //bkgnd->Draw("colz");

  char name[50];
  for (int ybin = 0; ybin < NBins_Y; ybin ++){
    sprintf(name, "%s%d", "sig_", ybin);
    Sig_All[ybin] = new TH1D(name, name, NBins_X, Axis_XMin, Axis_XMax); //note range
    //now is consistent with wmass analysis
    
    // variable[ybin] = sig2->GetYaxis()->GetBinCenter(ybin);
    //variable_err[ybin] = 0.;
    
    for(int xbin=50; xbin < 150; xbin ++) { //now is consistent with wmass analysis
      Sig_All[ybin] -> SetBinContent(xbin-50, sig2->GetBinContent(xbin,ybin)); //note order
    }  //pmcs ranges is from 0 to 150 instead of 50 to 150
    // Sig_All[ybin] -> Draw();

    sprintf(name, "%s%d", "bkgnd_", ybin);
    QCDBkg_All[ybin] = new TH1D(name, name, NBins_X, Axis_XMin, Axis_XMax);
    sprintf(name, "%s%d", "bkgnd_orig_", ybin);
    bkgnd_mass[ybin] = new TH1D(name, name, NBins_X, Axis_XMin, Axis_XMax);
    
    for(int xbin=0; xbin < NBins_X; xbin ++) {
      bkgnd_mass[ybin] -> SetBinContent((xbin), bkgnd->GetBinContent(ybin, xbin)); //note order
    }
    bkgnd_mass[ybin]->Sumw2();
    // bkgnd_mass[ybin]->Draw("pe");
    //TF1 *func = new TF1("func","[0] + [1]*x + [2]*x*x + [3]*x*x*x + [4]*x*x*x*x + [5]*x*x*x*x*x", Axis_YMin, Axis_YMax);
    //func -> SetParameters(-28900.202091,1544.3,-31.665,0.3172,0.00000305);
    TF1 *func = new TF1("func","landau", Axis_XMin, Axis_XMax);
    if (bkgnd_mass[ybin]->Integral()>10){
      bkgnd_mass[ybin]->Fit(func,"QN");//QN
    } else {
      cout<< " not enough events for bkgnd determination "<<endl;
      func -> SetParameters(3.93055e+02,5.64712e+01,3.26891e+00); 
      //this is for the bins < 25 GeV (for now) the parameters are from the 25-26 gev bin. 
    }
    //bkgnd_mass[xbin]->Draw();
    //QCDBkg_All[xbin] = (TH1D *)Sig_All[xbin]->Clone();
    
    for(int i=1; i<=QCDBkg_All[ybin]->GetNbinsX(); i++) {
      double center = QCDBkg_All[ybin]->GetBinCenter(i);
      
      QCDBkg_All[ybin] -> SetBinContent(i, 0);
      QCDBkg_All[ybin] -> SetBinError(i, 0);
      
      if(center>xmin && center<xmax) {
	double bin_min = QCDBkg_All[ybin]->GetBinLowEdge(i);
	double bin_max = bin_min + QCDBkg_All[ybin]->GetBinWidth(i);
	
	double integral = func->Integral(bin_min, bin_max);
	QCDBkg_All[ybin] -> SetBinContent(i, integral);
	QCDBkg_All[ybin] -> SetBinError(i, TMath::Sqrt(integral));
      }
    } // for all bins
    
    QCDBkg_All[ybin]->Sumw2();
    //  QCDBkg_All[ybin]->Draw();
     //Sig_All[ybin]->Draw();  
  }
  //bkgnd->Draw("colz");
  //TH1D *Sig_All = (TH1D *)gROOT->FindObject("smeared_hZcandMass_CCCC");
  
  //
  // fitter
  //
  Fitter fitter;
  double data_entry_before[NBins], mc_entry_before[NBins], mc_entry_diff[NBins], bkg_entry_before[NBins], mc_error_before[NBins], mc_error_diff[NBins];
  double data_entry_after[NBins], mc_entry_after[NBins], bkg_entry_after[NBins], mc_error_after[NBins];
  double eff[NBins], eff_err[NBins], deff[NBins], deff_err[NBins] ,reff[NBins], reff_err[NBins];
  double chisq1[NBins], chisq2[NBins];
  
  TCanvas *ctemp;
  int npad = 1;
  cout<< " nbins upara now "<<NBins<<endl;
  for(int i=0; i<NBins; i++) {  
    int cbin = 2;
    /*before_mass[i]->Rebin(cbin);
    after_mass[i]->Rebin(cbin);
    diff_mass[i]->Rebin(cbin);
    Sig_All[i]->Rebin(cbin);
    QCDBkg_All[i]->Rebin(cbin);
    */

    if (!(i%2)) {
      myps->NewPage();
      ctemp = new TCanvas("ctemp","ctemp",600,800);
      ctemp->Divide(2,2); 
      npad = 1;
      cout<<"NEWPAGE!!!"<<endl;
    }
    cout<<"=================================Starting number "<<i<<" =============================="<<endl;
    ctemp->cd(npad); 
    // before becomes diff 
    double sb = Sig_All[i]->Integral();
    double bb = QCDBkg_All[i]->Integral();
    cout<<diff_mass[i]->Integral()<<" "<< Sig_All[i]->Integral()<<" "<<QCDBkg_All[i]->Integral()<<endl;
    if(diff_mass[i]->Integral()>1. && Sig_All[i]->Integral()>2. && QCDBkg_All[i]->Integral()>1.) {
      cout<<"b mass "<<diff_mass[i]->Integral()<<endl;
      fitter.Update(diff_mass[i], Sig_All[i], QCDBkg_All[i], xmin, xmax);
      fitter.FitMass();
      fitter.Compare(ctemp);
      fitter.GetDataSignalBkg(data_entry_before[i], mc_entry_before[i], bkg_entry_before[i], mc_error_before[i], chisq1[i]);
    } else {
      diff_mass[i]->SetTitle("no fit");
      diff_mass[i]->Draw("pe");
      //Sig_All[i]->Scale(diff_mass[i]->Integral()/Sig_All[i]->Integral());
      Sig_All[i]->SetLineColor(kRed);
      Sig_All[i]->SetTitle("no fit");
      Sig_All[i]->Draw("hist && same");
      data_entry_before[i]=0.;
      mc_entry_before[i]=0.;
      bkg_entry_before[i]=0.;
      mc_error_before[i]=0.;
      
    }
    npad++;
    ctemp->cd(npad);
    if (Sig_All[i]->Integral()>0){
      Sig_All[i]->Scale(sb/Sig_All[i]->Integral());
    }
    if(QCDBkg_All[i]->Integral()>0){
      QCDBkg_All[i]->Scale(bb/QCDBkg_All[i]->Integral());
    }
    cout<<"---------------------------------------------------------------------------------here i am"<<endl;
    cout<<after_mass[i]->Integral()<<" "<< Sig_All[i]->Integral()<<" "<<QCDBkg_All[i]->Integral()<<endl;
    if(after_mass[i]->Integral()>1. && Sig_All[i]->Integral()>2. && QCDBkg_All[i]->Integral()>1.) {
      cout<<"---------------------------------------------------------------------------------here i am 2"<<endl;
      fitter.Update(after_mass[i], Sig_All[i], QCDBkg_All[i], xmin, xmax);
      fitter.FitMass();
      //ctemp->cd(npad);
      fitter.Compare(ctemp);
      fitter.GetDataSignalBkg(data_entry_after[i], mc_entry_after[i], bkg_entry_after[i], mc_error_after[i], chisq2[i]);
    } else {
      cout<<"-----------------------------------------------------------------------------------here i am 3"<<endl;
      after_mass[i]->SetTitle("no fit");
      after_mass[i]->Draw("pe");
      //Sig_All[i]->Scale(after_mass[i]->Integral()/Sig_All[i]->Integral());
      Sig_All[i]->SetLineColor(kRed);
      Sig_All[i]->SetTitle("no fit");
      Sig_All[i]->Draw("hist && same");
      data_entry_after[i]=0.;
      mc_entry_after[i]=0.;
      bkg_entry_after[i]=0.;
      mc_error_after[i]=0.;
      
    }
    npad++;

  } // for each histogram

  // plot efficiency

 myps->NewPage();
  TCanvas *eff_canvas = new TCanvas("eff","eff",600,600);


  eff_canvas->Divide(1,1);
    eff_canvas->cd(1);

  cout<<"double cccc_mc_entry_after["<<NBins<<"]={";
  for(int i=0; i<NBins; i++) {
    cout<<mc_entry_after[i]<<",";
  }
  cout<<"}"<<endl;
  cout<<"double cccc_mc_error_after["<<NBins<<"]={";
  for(int i=0; i<NBins; i++) {
    cout<<mc_error_after[i]<<",";
  }
  cout<<"}"<<endl;
  cout<<"double cccc_mc_entry_before["<<NBins<<"]={";
  for(int i=0; i<NBins; i++) {
    cout<<mc_entry_before[i]<<",";
  }
  cout<<"}"<<endl;
  cout<<"double cccc_mc_error_before["<<NBins<<"]={";
  for(int i=0; i<NBins; i++) {
    cout<<mc_error_before[i]<<",";
  }
  cout<<"}"<<endl;
  cout<<"double variable[NBins]={";
  for(int i=0; i<NBins; i++) {
    cout<<variable[i]<<",";
  }
  cout<<"}"<<endl;
  
  for(int i=0; i<NBins; i++) {
    if(mc_entry_before[i]>1.&&  mc_entry_after[i]>1.) {  // at least >one entry
      
      eff[i] = mc_entry_after[i]/(mc_entry_before[i] + mc_entry_after[i]);
      eff_err[i] = sqrt(mc_entry_before[i]*mc_entry_before[i]*mc_error_after[i]*mc_error_after[i]+ mc_entry_after[i]*mc_entry_after[i]*mc_error_before[i]*mc_error_before[i])/(mc_entry_before[i]+mc_entry_after[i])/(mc_entry_before[i]+mc_entry_after[i]);
      cout<<"what "<<i << " b "<<mc_entry_before[i]<<" a "<<mc_entry_after[i]<<" eff i "<<eff[i]<<" err i "<<eff_err[i] << " be "<<mc_error_before[i]<<" ae "<<mc_error_after[i]<<endl;    
      
    } else {
      eff[i] = 0;
      eff_err[i] = 0.05;
    }
  }
  
  TF1 *afunc = new TF1("afunc",fitf,-15,15,3);
  afunc->SetParameters(-1.0,0.010,0.74);
  
  //  TF1 *efffit2 = new TF1("efffit2","0.5 * [2] * (1. + TMath::Erf((x-[0])/(sqrt(2)*[1])))*(1. + TMath::Erf((x-[4])/(sqrt(2)*[3])))",15,55 );
  //  efffit2->SetParameters(23.,2.0,0.4,2.0,20.);
  TGraphErrors *ge = new TGraphErrors(NBins, variable, eff, variable_err, eff_err);
  ge->GetYaxis()->SetRangeUser(0.4,0.9);
  ge->SetMarkerColor(kRed);
  ge->SetMarkerSize(2);
  ge->SetLineColor(kRed);
  ge->GetXaxis()->SetTitle("Electron U_{||} [GeV]");
  ge->GetYaxis()->SetTitle("Efficiency");
  ge->GetYaxis()->SetTitleOffset(1.4);
  ge->SetTitle("Z->ee Candidates, U_{||} Eff."); 
  
  ge->Fit("afunc","R");
  
  TF1 *apol1 = new TF1("apol1","[0] + [1]*x", -20. ,0.);
  ge -> Draw("AP");
  //  ge->Fit("apol1","R");
  // apol1->Draw("same");
  TF1 *bpol1 = new TF1("bpol1","[0] + [1]*x", 0. ,20.);
  // ge->Fit("bpol1","R");
  //bpol1->Draw("same");
  

  // eff_canvas->Update();
  
  // eff_canvas->cd(2);
  eff_canvas->SaveAs("upara_out_new.eps");


  for(int i=0; i<NBins; i++) {
    if(data_entry_before[i]>1. && data_entry_after[i]>1.) {// at least one entry
      cout<<"what 2 "<<data_entry_before[i]<<" "<<data_entry_after[i]<< " "<<i<<endl;
      deff[i] = data_entry_after[i]/(data_entry_before[i]+data_entry_after[i]);
      deff_err[i] = sqrt(data_entry_before[i]*data_entry_before[i]*mc_error_after[i]*mc_error_after[i]
			 + data_entry_after[i]*data_entry_after[i]*mc_error_before[i]*mc_error_before[i])
	/(data_entry_before[i]+data_entry_after[i])/(data_entry_before[i]+data_entry_after[i]);
      //for this you really should have plain binominal errors (no background subtraction here)
    } else {
      deff[i] = 0;
      deff_err[i] = 0.05;
    }
  }
  
  
  TGraphErrors *de = new TGraphErrors(NBins, variable, deff, variable_err, deff_err);
  de->GetYaxis()->SetRangeUser(0.4,0.9);
  de->SetMarkerColor(kBlue);
  de->SetMarkerSize(2);
  de->SetLineColor(kBlue);
  //de->Fit("efffit2","RME");
  //de -> Draw("SAME");
  
  //eff_canvas->Update();
  
  //now get full MC "answer":
  /*
  TFile *data=new TFile("/rooms/porcelain/tandeen/WMASS/output/FULL/Zee/UPARAEFF/result_MCzee_upara_1.root");
  gDirectory->cd("ZCand_Hist");
  TH1D *before2 = (TH1D *)gROOT->FindObject("ZCandUPara_NoCuts");
  TH1D *after2 = (TH1D *)gROOT->FindObject("ZCandUPara_BothWithGoodSpatialMatch_IsoHMxCut");  
  before2->Rebin(8);
  after2->Rebin(8);
  
  TGraphAsymmErrors *effb = new TGraphAsymmErrors();
  effb->BayesDivide(after2,before2,""); //"debug"
  // effb->Fit("pol1","","",0,15);
  
  effb->Draw("same");
  effb->Fit("pol1","","",-20,0);
  double thep0 = pol1->GetParameter(0);
  double thep1 = pol1->GetParameter(1);
  cout<<"p0 "<<thep0<<" p1 "<<thep0<<endl;
  effb->Fit("pol1","","",0,20);
  //TF1 *cpol1 = new TF1("cpol1","[0] + [1]*x", -20. ,0.);
  //cout<<"cpol"<<endl;
  //effb->Fit("cpol1","R");
  //cpol1->Draw("same");
  TF1 *dpol1 = new TF1("dpol1","[0] + [1]*x", -20. , 0.);
  dpol1->SetParameters(thep0,thep1);
  //cout<<"dpol"<<endl;
  //effb->Fit("dpol1","R");
  dpol1->Draw("same");

  //effb->SetTitle(ZCandUPara_BothWithGoodSpatialMatch_IsoHMxCut->GetTitle());
  //effb->GetXaxis()->SetTitle("trk deteta");
  */
  /*
  eff_canvas->cd(3);
  
  for(int i=0; i<NBins; i++) {
    if(eff[i]>0. && deff[i]>0.) {// at least one entry
      reff[i] = eff[i]/deff[i]; 
      //reff_err[i] = sqrt(data_entry_before[i]*data_entry_before[i]*mc_error_after[i]*mc_error_after[i]+ data_entry_after[i]*data_entry_after[i]*mc_error_before[i]*mc_error_before[i])/(data_entry_before[i]+data_entry_after[i])/(data_entry_before[i]+data_entry_after[i]);
    } else {
      reff[i] = 1.0;
      //reff_err[i] = 0.1;
    }
  }

  TGraphErrors *erat = new TGraphErrors(NBins, variable, reff, variable_err, eff_err);
  erat->GetXaxis()->SetRangeUser(10,70);
  erat->SetMarkerColor(kRed);
  erat->SetMarkerSize(2);
  erat->SetLineColor(kRed);
  erat -> Draw("AP");
  */


  eff_canvas->Update();

  myps->NewPage();
  TCanvas *chi_canvas = new TCanvas("eff","eff",600,800);
  

  chi_canvas->Divide(1,2);
  chi_canvas->cd(1);
  
  TGraph *chi1 = new TGraph(NBins, variable, chisq1);
  // de->GetYaxis()->SetRangeUser(0.4,0.9);
  //de->SetMarkerColor(kBlue);
  //de->SetMarkerSize(2);
  //de->SetLineColor(kBlue);
  //de->Fit("efffit2","RME");
  chi1-> Draw("A*");
   

  chi_canvas->cd(2);

  TGraph *chi2 = new TGraphErrors(NBins, variable, chisq2);
  //de->GetYaxis()->SetRangeUser(0.4,0.9);
  
  //de->SetMarkerColor(kBlue);
  //de->SetMarkerSize(2);
  //de->SetLineColor(kBlue);
  //de->Fit("efffit2","RME");
  chi2 -> Draw("A*");
  
  chi_canvas->Update();


  myps->Close();
}
Ejemplo n.º 5
0
void NoiseAnalyzer()
{

  // the input file
  TFile *f1 = new TFile("DTNoiseCalib.root");
  
  // the output files
  TPostScript *ps = new TPostScript("DTNoise.ps", 112);
  ofstream summaryOutput("summaryNoise.txt");
  ofstream detailedOutput("detailedNoise.txt");

  TCanvas* c = new TCanvas("prova", "prova");
  TLegend *leg=new TLegend(0.2,0.75,0.9,0.88);


   for(int W=-2; W<=2; W++){
     std::stringstream wheel; wheel << W;
     for(int Sec=1; Sec<=14; Sec++){
       std::stringstream sector; sector << Sec;
       for(int St=1; St<=4; St++){
	 double counterSomehowNoisyCells=0;
	 double counterNoisyCells=0;
	 bool StationHasData=false;
	 std::stringstream station; station << St;
	 for(int SL=1; SL<=3; SL++){
	   leg->Clear();
	   bool SLhasData=false;
	   bool pageWritten=false;
	   std::stringstream superlayer; superlayer << SL;
	   TString newHistoName="AverageNoise_W"+wheel.str()+"_St"+station.str()+"_Sec"+sector.str()+"_SL"+superlayer.str();
	   for(int L=1; L<=4; L++){
	     std::stringstream layer; layer << L;
	     
	     // find the histo
	     TString histoName="DigiOccupancy_W"+wheel.str()+"_St"+station.str()+"_Sec"+sector.str()+"_SL"+superlayer.str()+"_L"+layer.str();
	     TH1F* h =((TH1F*) f1->Get(histoName));
	     if(h){
	       StationHasData=true;
	       SLhasData=true;
	       //overimpose the plot per SL
	       c->cd();
	       TString legend= "layer_"+layer.str();
	       if(L==1){
		 h->SetTitle(newHistoName);
		 h->SetLineColor(L);
		 h->SetLineWidth(2);
		 h->Draw();
		 leg->AddEntry(h,legend,"L");
	       }
	       else{
		 h->SetLineColor(L);
		 h->SetLineWidth(2);
		 h->Draw("same");
		 leg->AddEntry(h,legend,"L");
	       }
	       //count the numeber of noisy/someHow noisy cells
	       int numBin = h->GetXaxis()->GetNbins();
	       for (int bin=1; bin<=numBin; bin++){
		 if(h->GetBinContent(bin)>100 && h->GetBinContent(bin)<500){
		   counterSomehowNoisyCells++;
		   detailedOutput<<"somehowNoisyCell: W"<<W<<" St"<<St<<" Sec"<<Sec<<" SL"<<SL<<" L"<<L<<" wire"<<bin<<endl;
		 }
		  if(h->GetBinContent(bin)>500){
		    counterNoisyCells++;
		    detailedOutput<<"noisyCell: W"<<W<<" St"<<St<<" Sec"<<Sec<<" SL"<<SL<<" L"<<L<<" wire"<<bin<<endl;
		  }
	       } 
	     }

	    } // loop on layer
	    if(SLhasData && !(pageWritten)){
	      pageWritten=true;
	      leg->Draw("same");
	      gPad->SetLogy();
	      c->Update();
	    }

	 } // loop on SL
	 if(StationHasData){
	   summaryOutput<<" ------------ "<<endl;
	   summaryOutput<<"MB"<<St<<"_W"<<W<<"_Sec"<<Sec<<endl;
	   summaryOutput<<"# of somehow noisy cells: "<<counterSomehowNoisyCells<<endl;
	   summaryOutput<<"# of noisy cells: "<<counterNoisyCells<<endl;
	 }

       } // loop on stations
     } // loop on sectors
   } // loop on wheels

   ps->Close();
}
Ejemplo n.º 6
0
void getY0()
{
  gROOT->Reset();
  gROOT->LoadMacro("fitfun.C");   // fit function for localY, local Z

  const Int_t N = 120;

  //histograms to check the par2 and par3 distributions
  TH1D *hPar2 = new TH1D("Par2","",500,0., 5.);
  TH1D *hPar3 = new TH1D("Par3","",500,0., 1.);

  TFile *fin = new TFile("align.root");
  TH2D *yLocal2D = (TH2D *)fin->Get("yLocal_all");
  yLocal2D->RebinY(5);
  TH1D *yLocal[N];
  for(int i=0;i<N;i++) {
    char hisname[100];
    sprintf(hisname,"Tray_%d",i+1);
    yLocal[i] = yLocal2D->ProjectionY(hisname,i+1,i+1);
    yLocal[i]->Sumw2();
  }

  TF1 *fitfun = new TF1("fitfun",fitfun,-5.,5.,5);

  double t[N];
  double y0[N], ye[N];

  gStyle->SetOptStat(101);
  gStyle->SetOptFit(100);
  gStyle->SetTextSize(0.06);
  gStyle->SetTextFont(42);
  TCanvas *c1 = new TCanvas("c1","c1",0,0,800,600);
  c1->SetFillColor(10);
  c1->SetBorderMode(0);
  c1->SetBorderSize(2);
  c1->Divide(4,3);

  TPostScript *ps = new TPostScript("fig/yLocalFit.ps",112);

  for(int i=0;i<N;i++) {
    t[i] = i+1;  // tray number

    if(i%12==0) ps->NewPage();   // 12 trays per page
    c1->cd(i%12+1);

    double par[5], err[5];
    fitfun->SetParameters(0., yLocal[i]->GetBinContent(50), 0.1, 1., 0.);
    fitfun->SetLineWidth(2);
    yLocal[i]->Draw("e");
    double entries = yLocal[i]->Integral(1,100);
    if(entries>10) {
      fitfun->SetParLimits(2, 1.55, 1.7);
      fitfun->SetParLimits(3, 0.1, 0.3);
      yLocal[i]->Fit("fitfun","R");
      fitfun->GetParameters(&par[0]);
      err[0] = fitfun->GetParError(0);
    } else {
      par[0] = 0.;
      err[0] = 0.;
    }

    hPar2->Fill(par[2]);
    hPar3->Fill(par[3]);

    char text[100];
    sprintf(text, "Y0 = %5.3f #pm %5.3f", par[0], err[0]);

    TLatex *tex = new TLatex(-3, par[1]/3., text);
    tex->SetTextSize(0.07);
    tex->SetTextFont(12);
    tex->Draw("same");

    y0[i] = par[0];
    ye[i] = err[0];
    
    c1->Update();
  }

  ps->NewPage();

  gStyle->SetOptStat(0);
  gStyle->SetOptFit(0);
  gStyle->SetEndErrorSize(0.01);
   
  TCanvas *c1 = new TCanvas("c1","c1",0,0,800,600);
  c1->SetFillColor(10);
  c1->SetBorderMode(0);
  c1->SetBorderSize(2);
  c1->SetLeftMargin(0.14);
  c1->SetBottomMargin(0.15);
  c1->SetTopMargin(0.02);
  c1->SetRightMargin(0.04);
  c1->Draw();

  double x1 = 0.5;
  double x2 = 120.5;
  double y1 = -2.;
  double y2 = 2.;
  TH1D *h0 = new TH1D("h0","",1, x1, x2);
  h0->SetMinimum(y1);
  h0->SetMaximum(y2);
   h0->GetXaxis()->SetNdivisions(208);
   h0->GetXaxis()->CenterTitle();
   h0->GetXaxis()->SetTitle("Tray #");
   h0->GetXaxis()->SetTitleOffset(1.0);
   h0->GetXaxis()->SetTitleSize(0.07);
   h0->GetXaxis()->SetLabelOffset(0.01);
   h0->GetXaxis()->SetLabelSize(0.05);
   h0->GetXaxis()->SetLabelFont(42);
   h0->GetXaxis()->SetTitleFont(42);
   h0->GetYaxis()->SetNdivisions(210);
   h0->GetYaxis()->SetTitle("yLocal Offset");
   h0->GetYaxis()->SetTitleOffset(1.0);
   h0->GetYaxis()->SetTitleSize(0.07);
   h0->GetYaxis()->SetLabelOffset(0.01);
   h0->GetYaxis()->SetLabelSize(0.045);
   h0->GetYaxis()->SetLabelFont(42);
   h0->GetYaxis()->SetTitleFont(42);
   h0->Draw();

   TLine *l1 = new TLine(x1,y1,x2,y1);
   l1->SetLineWidth(3);
   l1->Draw("same");
   TLine *l2 = new TLine(x1,y2,x2,y2);
   l2->SetLineWidth(3);
   l2->Draw("same");
   TLine *l3 = new TLine(x1,y1,x1,y2);
   l3->SetLineWidth(3);
   l3->Draw("same");
   TLine *l4 = new TLine(x2,y1,x2,y2);
   l4->SetLineWidth(3);
   l4->Draw("same");

   TGraphErrors *gr = new TGraphErrors(N, t, y0, 0, ye);
   gr->SetMarkerStyle(20);
   gr->SetMarkerSize(1.5);
   gr->SetLineWidth(2);
   gr->Draw("p");

   c1->Update();

  ps->Close();

  ofstream outData;
  outData.open("yOffset.dat");
  for(int i=0;i<N;i++) {
    outData << setw(15) << y0[i] << setw(15) << ye[i] << endl;
  }
  outData.close();

  TFile  *fout = new TFile("yFitPar.root","recreate");
  hPar2->Write();
  hPar3->Write();
  fout->Close();
}
Ejemplo n.º 7
0
void getX0()
{
  gROOT->Reset();
  gROOT->LoadMacro("fitfun.C");   // fit function for localY, local Z

  const Int_t N = 120;
  const Int_t M = 7; // number of module angle groups

  //histograms to check the par2 and par3 distributions
  TH1D *hPar2 = new TH1D("Par2","",500,0., 5.);
  TH1D *hPar3 = new TH1D("Par3","",500,0., 1.);

  Double_t a[M] = {0., 16., 20., 22., 26., 30., 32.};

  TH2D *zLocal2D[M];
  TH1D *zLocal[N][M];

  TFile *fin = new TFile("align.root");
  for(int j=0;j<M;j++) {
    char inhis[100];
    sprintf(inhis,"zLocal_%d",j);
    zLocal2D[j] = (TH2D *)fin->Get(inhis);
    zLocal2D[j]->RebinY(5);
    for(int i=0;i<N;i++) {
      char hisname[100];
      sprintf(hisname,"Tray_%d_A_%d",i+1,j);
      zLocal[i][j] = zLocal2D[j]->ProjectionY(hisname,i+1,i+1);
      zLocal[i][j]->Sumw2();
    }
  }

  TF1 *fitfun = new TF1("fitfun",fitfun,-6.,6.,5);

  double t[N];
  double z0[N][M], ze[N][M];

  gStyle->SetOptStat(101);
  gStyle->SetOptFit(100);
  gStyle->SetTextSize(0.06);
  gStyle->SetTextFont(42);
  TCanvas *c1 = new TCanvas("c1","c1",0,0,800,600);
  c1->SetFillColor(10);
  c1->SetBorderMode(0);
  c1->SetBorderSize(2);
  c1->Divide(4,3);

  TPostScript *ps = new TPostScript("fig/xLocalFit.ps",112);

  for(int j=0;j<M;j++) {
    for(int i=0;i<N;i++) {
      t[i] = i+1;  // tray number

      if(i%12==0) ps->NewPage();   // 12 trays per page
      c1->cd(i%12+1);

      double par[5], err[5];
      fitfun->SetParameters(0., zLocal[i][j]->GetBinContent(50), 0.1, 1., 0.);
      fitfun->SetLineWidth(2);
      zLocal[i][j]->Draw("e");
      double entries = zLocal[i][j]->Integral(1,100);
      if(entries>10) {
	fitfun->SetParLimits(0, -3., 3.);
	fitfun->SetParLimits(2, 2.9, 3.1);
	fitfun->SetParLimits(3, 0.01, 0.16);
	zLocal[i][j]->Fit("fitfun","R");
	fitfun->GetParameters(&par[0]);
	err[0] = fitfun->GetParError(0);
      } else {
	par[0] = 0.;
	err[0] = 0.;
      }

      hPar2->Fill(par[2]);
      hPar3->Fill(par[3]);
      
      char text[100];
      sprintf(text, "Z0 = %5.3f #pm %5.3f", par[0], err[0]);
      
      TLatex *tex = new TLatex(-3, par[1]/3., text);
      tex->SetTextSize(0.07);
      tex->SetTextFont(12);
      tex->Draw("same");
      
      z0[i][j] = par[0];
      ze[i][j] = err[0];
      
      c1->Update();
    }
  }

  gStyle->SetOptStat(0);
  gStyle->SetOptFit(0);
  gStyle->SetEndErrorSize(0.01);
 
  TF1 *fitangle = new TF1("fitangle","[0]*sin(x*3.14159/180.)+[1]",-10.,40.);
  
  double z00[N], ze0[N];  // angle=0 modules zOffset
  double z0F[N], zeF[N];  // angle=0 modules zOffset after fitangle fit
  double x0[N], xe[N];
  for(int i=0;i<N;i++) {

    if(i%12==0) ps->NewPage();   // 12 trays per page
    c1->cd(i%12+1);

    z00[i] = z0[i][0];
    ze0[i] = ze[i][0];

    double x1 = -10.;
    double x2 = 50.;
    double y1 = -2.5;
    double y2 = 1.5;
    char title[100];
    sprintf(title,"Tray_%d",i+1);
    TH1D *h0 = new TH1D("h0",title,1, x1, x2);
    h0->SetMinimum(y1);
    h0->SetMaximum(y2);
    h0->GetXaxis()->SetNdivisions(208);
    h0->GetXaxis()->CenterTitle();
    h0->GetXaxis()->SetTitle("Module Angle (deg)");
    h0->GetXaxis()->SetTitleOffset(1.0);
    h0->GetXaxis()->SetTitleSize(0.07);
    h0->GetXaxis()->SetLabelOffset(0.01);
    h0->GetXaxis()->SetLabelSize(0.045);
    h0->GetXaxis()->SetLabelFont(42);
    h0->GetXaxis()->SetTitleFont(42);
    h0->GetYaxis()->SetNdivisions(210);
    h0->GetYaxis()->SetTitle("zLocal Offset");
    h0->GetYaxis()->SetTitleOffset(1.0);
    h0->GetYaxis()->SetTitleSize(0.07);
    h0->GetYaxis()->SetLabelOffset(0.01);
    h0->GetYaxis()->SetLabelSize(0.045);
    h0->GetYaxis()->SetLabelFont(42);
    h0->GetYaxis()->SetTitleFont(42);
    h0->Draw();
    
    TGraphErrors *gr = new TGraphErrors(M, a, z0[i], 0, ze[i]);
    gr->SetMarkerStyle(24);
    gr->SetMarkerSize(1.5);
    gr->SetLineWidth(2);
    gr->Draw("p");
    
    fitangle->SetParameters(-0.5, 0.0);
    gr->Fit("fitangle","R");

    x0[i] = fitangle->GetParameter(0);
    z0F[i] = fitangle->GetParameter(1);
    xe[i] = fitangle->GetParError(0);
    zeF[i] = fitangle->GetParError(1);

    c1->Update();
  }

  ps->NewPage();

  gStyle->SetOptStat(0);
  gStyle->SetOptFit(0);
  gStyle->SetEndErrorSize(0.01);
   
  TCanvas *c1 = new TCanvas("c1","c1",0,0,800,600);
  c1->SetFillColor(10);
  c1->SetBorderMode(0);
  c1->SetBorderSize(2);
  c1->SetLeftMargin(0.14);
  c1->SetBottomMargin(0.15);
  c1->SetTopMargin(0.02);
  c1->SetRightMargin(0.04);
  c1->Draw();

  double x1 = 0.5;
  double x2 = 120.5;
  double y1 = -3.;
  double y2 = 1.;
  TH1D *h0 = new TH1D("h0","",1, x1, x2);
  h0->SetMinimum(y1);
  h0->SetMaximum(y2);
   h0->GetXaxis()->SetNdivisions(208);
   h0->GetXaxis()->CenterTitle();
   h0->GetXaxis()->SetTitle("Tray #");
   h0->GetXaxis()->SetTitleOffset(1.0);
   h0->GetXaxis()->SetTitleSize(0.07);
   h0->GetXaxis()->SetLabelOffset(0.01);
   h0->GetXaxis()->SetLabelSize(0.05);
   h0->GetXaxis()->SetLabelFont(42);
   h0->GetXaxis()->SetTitleFont(42);
   h0->GetYaxis()->SetNdivisions(210);
   h0->GetYaxis()->SetTitle("zLocal Offset");
   h0->GetYaxis()->SetTitleOffset(1.0);
   h0->GetYaxis()->SetTitleSize(0.07);
   h0->GetYaxis()->SetLabelOffset(0.01);
   h0->GetYaxis()->SetLabelSize(0.045);
   h0->GetYaxis()->SetLabelFont(42);
   h0->GetYaxis()->SetTitleFont(42);
   h0->Draw();

   TLine *l1 = new TLine(x1,y1,x2,y1);
   l1->SetLineWidth(3);
   l1->Draw("same");
   TLine *l2 = new TLine(x1,y2,x2,y2);
   l2->SetLineWidth(3);
   l2->Draw("same");
   TLine *l3 = new TLine(x1,y1,x1,y2);
   l3->SetLineWidth(3);
   l3->Draw("same");
   TLine *l4 = new TLine(x2,y1,x2,y2);
   l4->SetLineWidth(3);
   l4->Draw("same");

   TGraphErrors *gr = new TGraphErrors(N, t, z00, 0, ze0);
   gr->SetMarkerStyle(20);
   gr->SetMarkerSize(1.5);
   gr->SetLineWidth(2);
   gr->Draw("p");

   TGraphErrors *gr = new TGraphErrors(N, t, z0F, 0, zeF);
   gr->SetMarkerStyle(24);
   gr->SetMarkerSize(1.5);
   gr->SetLineWidth(2);
   gr->Draw("p");

   c1->Update();
  
  ps->NewPage();

  gStyle->SetOptStat(0);
  gStyle->SetOptFit(0);
  gStyle->SetEndErrorSize(0.01);
   
  TCanvas *c1 = new TCanvas("c1","c1",0,0,800,600);
  c1->SetFillColor(10);
  c1->SetBorderMode(0);
  c1->SetBorderSize(2);
  c1->SetLeftMargin(0.14);
  c1->SetBottomMargin(0.15);
  c1->SetTopMargin(0.02);
  c1->SetRightMargin(0.04);
  c1->Draw();

  double x1 = 0.5;
  double x2 = 120.5;
  double y1 = -2.;
  double y2 = 3.;
  TH1D *h0 = new TH1D("h0","",1, x1, x2);
  h0->SetMinimum(y1);
  h0->SetMaximum(y2);
   h0->GetXaxis()->SetNdivisions(208);
   h0->GetXaxis()->CenterTitle();
   h0->GetXaxis()->SetTitle("Tray #");
   h0->GetXaxis()->SetTitleOffset(1.0);
   h0->GetXaxis()->SetTitleSize(0.07);
   h0->GetXaxis()->SetLabelOffset(0.01);
   h0->GetXaxis()->SetLabelSize(0.05);
   h0->GetXaxis()->SetLabelFont(42);
   h0->GetXaxis()->SetTitleFont(42);
   h0->GetYaxis()->SetNdivisions(210);
   h0->GetYaxis()->SetTitle("xLocal Offset");
   h0->GetYaxis()->SetTitleOffset(1.0);
   h0->GetYaxis()->SetTitleSize(0.07);
   h0->GetYaxis()->SetLabelOffset(0.01);
   h0->GetYaxis()->SetLabelSize(0.045);
   h0->GetYaxis()->SetLabelFont(42);
   h0->GetYaxis()->SetTitleFont(42);
   h0->Draw();

   TLine *l1 = new TLine(x1,y1,x2,y1);
   l1->SetLineWidth(3);
   l1->Draw("same");
   TLine *l2 = new TLine(x1,y2,x2,y2);
   l2->SetLineWidth(3);
   l2->Draw("same");
   TLine *l3 = new TLine(x1,y1,x1,y2);
   l3->SetLineWidth(3);
   l3->Draw("same");
   TLine *l4 = new TLine(x2,y1,x2,y2);
   l4->SetLineWidth(3);
   l4->Draw("same");

   TGraphErrors *gr = new TGraphErrors(N, t, x0, 0, xe);
   gr->SetMarkerStyle(20);
   gr->SetMarkerSize(1.5);
   gr->SetLineWidth(2);
   gr->Draw("p");

   c1->Update();

  ps->Close();
    
  ofstream outData;
  outData.open("xOffset.dat");
  for(int i=0;i<N;i++) {
    outData << setw(15) << z00[i] << setw(15) << ze0[i] << setw(15) << x0[i] << setw(15) << xe[i] << endl;
  }
  outData.close();

  TFile  *fout = new TFile("xFitPar.root","recreate");
  hPar2->Write();
  hPar3->Write();
  fout->Close();
}
Ejemplo n.º 8
0
checkFieldMap()
{

  // Choose field map
  TString fieldName = "field_v12b";
  TString psFile = "check." + fieldName + ".ps";
  Double_t fzref1 =   0.;        // Origin plane
  Double_t fzref2 = 170.;        // RICH entrance
  Double_t fzref3 = 180.;        // RICH PM
  // ---> Regions of interest for the field
  Double_t fxmin =  -200.;    // along x axis
  Double_t fxmax =   200.;
  Double_t fymin =  -200.;    // along y axis
  Double_t fymax =   200.;
  Double_t fzmin =  -300.;    // along z axis
  Double_t fzmax =   300.;
  // ---> Target location
  Double_t targX = 0.;
  Double_t targY = 0.;
  Double_t targZ = 0.;

    // -------  Get magnetic field  -----------------------------------------
  CbmFieldMap* field = NULL;
  if ( fieldName == "field_v12b" ) 
    field = new CbmFieldMapSym3(fieldName.Data());
  else if ( fieldName == "field_v12a" )
    field = new CbmFieldMapSym2(fieldName.Data());
  else {
    cout << "=====> ERROR: Field map " << fieldName << " unknown!" << endl;
    exit;
  }
  field->Init();
  field->Print();
  Int_t type = field->GetType();
  if ( type >=1 && type <= 3) 
    const char* mapFile = field->GetFileName();
  // ----------------------------------------------------------------------



  // -------  Create graphs and histograms  -------------------------------
  Int_t fnx = TMath::Nint( (fxmax-fxmin) * 3. );
  Int_t fny = TMath::Nint( (fymax-fymin) * 3. );
  Int_t fnz = TMath::Nint( (fzmax-fzmin) * 3. );
  Int_t fmx = TMath::Nint( (fxmax-fxmin) * 3. / 10. );
  Int_t fmy = TMath::Nint( (fymax-fymin) * 3. / 10. );
  TGraph hBy1(fnz+1);
  TGraph hBy2(fnz+1);
  TGraph hBt1(fnz+1);
  TGraph hBt2(fnz+1);
  TH2F hB1("hB1", "B at z_{target}", 
	   fmx, fxmin, fxmax, fmy, fymin, fymax);
  TH2F hB2("hB1", "B at RICH entrance", 
	   fmx, fxmin, fxmax, fmy, fymin, fymax);
  TH2F hB3("hB2", "B at RICH PM",       
	   fmx, fxmin, fxmax, fmy, fymin, fymax);
  // ----------------------------------------------------------------------



  // -------  Get field and fill graphs and histograms  -------------------
  cout << endl;
  cout << "=====>  Filling histograms..." << endl;
  Double_t x, y, z;  Double_t bx, by, bz, bt, b;
  Double_t fdx = (fxmax-fxmin) / Double_t(fnx);
  Double_t fdy = (fymax-fymin) / Double_t(fny);
  Double_t fdz = (fzmax-fzmin) / Double_t(fnz);


  // ---> Loop over z axis (x=y=0)
  cout << "                           ... z axis 1" << endl;
  x = y = 0.;
  for (Int_t iz=0; iz<=fnz; iz++) {
    z = fzmin + Double_t(iz) * fdz;
    bx = field->GetBx(x,y,z) / 10.;
    by = field->GetBy(x,y,z) / 10.;
    bz = field->GetBz(x,y,z) / 10.;
    bt = TMath::Sqrt(bx*bx + bz*bz);
    hBy1.SetPoint(iz, z, by);
    hBt1.SetPoint(iz, z, bt);
  }

  // ---> Loop over z axis (x=y=20)
  cout << "                           ... z axis 2" << endl;
  x = y = 20.;
  for (Int_t iz=0; iz<=fnz; iz++) {
    z = fzmin + Double_t(iz) * fdz;
    bx = field->GetBx(x,y,z) / 10.;
    by = field->GetBy(x,y,z) / 10.;
    bz = field->GetBz(x,y,z) / 10.;
    bt = TMath::Sqrt(bx*bx + bz*bz);
    hBy2.SetPoint(iz, z, by);
    hBt2.SetPoint(iz, z, bt);
  }

  // ---> Double loop over z (target) plane
  cout << "                           ... target plane" << endl;
  fdx = (fxmax-fxmin) / Double_t(fmx);
  fdy = (fymax-fymin) / Double_t(fmy);
  z = fzref1;
  for (Int_t ix=0; ix<fmx; ix++) {
    x = fxmin + (Double_t(ix)+0.5) * fdx;
    for (Int_t iy=0; iy<fmy; iy++) {
      y = fymin + (Double_t(iy)+0.5) * fdy;
      bx = field->GetBx(x,y,z) / 10.;
      by = field->GetBy(x,y,z) / 10.;
      bz = field->GetBz(x,y,z) / 10.;
      b = TMath::Sqrt(bx*bx + by*by + bz*bz);
      hB1.SetBinContent(ix, iy, b);
    }
  }

  // ---> Double loop over z (RICH entrance) plane
  cout << "                           ... RICH entrance plane" << endl;
  fdx = (fxmax-fxmin) / Double_t(fmx);
  fdy = (fymax-fymin) / Double_t(fmy);
  z = fzref2;
  for (Int_t ix=0; ix<fmx; ix++) {
    x = fxmin + (Double_t(ix)+0.5) * fdx;
    for (Int_t iy=0; iy<fmy; iy++) {
      y = fymin + (Double_t(iy)+0.5) * fdy;
      bx = field->GetBx(x,y,z) / 10.;
      by = field->GetBy(x,y,z) / 10.;
      bz = field->GetBz(x,y,z) / 10.;
      b = TMath::Sqrt(bx*bx + by*by + bz*bz);
      hB2.SetBinContent(ix, iy, b);
    }
  }

  // ---> Double loop over z (RICH PM) plane
  cout << "                           ... RICH PM plane" << endl;
  fdx = (fxmax-fxmin) / Double_t(fmx);
  fdy = (fymax-fymin) / Double_t(fmy);
  z = fzref3;
  for (Int_t ix=0; ix<fmx; ix++) {
    x = fxmin + (Double_t(ix)+0.5) * fdx;
    for (Int_t iy=0; iy<fmy; iy++) {
      y = fymin + (Double_t(iy)+0.5) * fdy;
      bx = field->GetBx(x,y,z) / 10.;
      by = field->GetBy(x,y,z) / 10.;
      bz = field->GetBz(x,y,z) / 10.;
      b = TMath::Sqrt(bx*bx + by*by + bz*bz);
      hB3.SetBinContent(ix, iy, b);
    }
  }
  // ----------------------------------------------------------------------



  // --------   Calculate field integral along z axis   -------------------
  Double_t zint1 = -400.;
  Double_t zint2 =  400.;
  Int_t nz = Int_t(zint2-zint1);
  Double_t bint = 0;
  z = zint1 - 1.;
  for (Int_t iz=0; iz<=nz; iz++) {
    z += 1;
    by = field->GetBy(targX, targY, z) / 10.;
    bint += by * 0.01;
  }
  // ----------------------------------------------------------------------



  // -------  Draw graphs and histogram   ---------------------------------
  cout << endl << "=====>  Drawing..." << endl;
  gROOT->SetStyle("Plain");
  gStyle->SetOptStat(0000);
  gStyle->SetPalette(1,0);
  gStyle->SetTitleW(0.5);
  gStyle->SetTitleAlign(13);
  gStyle->SetTitleBorderSize(0.);
  gStyle->SetTitleOffset(2.,"y");
  gStyle->SetOptDate(2);
  gStyle->GetAttDate()->SetTextSize(0.02);

  TPostScript* ps = new TPostScript(psFile, -111);
  ps->Range(20,30);

  TCanvas* c1 = new TCanvas("c1", "canvas", 768, 1152);
  TPad* master = new TPad("master","", 0.10, 0.05, 0.95, 0.95);
  master->Draw();
  master->cd();

  TPad* padinf = new TPad("padinf", "", 0.12, 0.80, 0.88, 0.90);
  TPad* pad1   = new TPad("pad1",   "", 0.05, 0.60, 0.48, 0.78);
  TPad* pad2   = new TPad("pad2",   "", 0.52, 0.60, 0.95, 0.78);
  TPad* pad3   = new TPad("pad3",   "", 0.05, 0.41, 0.48, 0.59);
  TPad* pad4   = new TPad("pad4",   "", 0.52, 0.41, 0.95, 0.59);
  TPad* pad5   = new TPad("pad5",   "", 0.30, 0.22, 0.70, 0.40);
  TPad* pad6   = new TPad("pad6",   "", 0.10, 0.02, 0.47, 0.20);
  TPad* pad7   = new TPad("pad7",   "", 0.53, 0.02, 0.90, 0.20);

  padinf->Draw();
  pad1->Draw();
  pad2->Draw();
  pad3->Draw();
  pad4->Draw();
  pad5->Draw();
  pad6->Draw();
  pad7->Draw();

  Double_t max, min;

  pad1->cd();
  gPad->SetFillColor(10);
  gPad->SetLeftMargin(0.15);
  hBy1.SetLineColor(4);
  hBy1.SetLineWidth(2);
  hBy1.SetTitle("x = y = 0");
  hBy1.GetXaxis()->SetTitle("z [cm]");
  hBy1.GetYaxis()->SetTitle("B_{y} [T]");
  hBy1.Draw("AC");
  max = hBy1.GetHistogram()->GetMaximum();
  min = hBy1.GetHistogram()->GetMinimum();
  TLine l1(targZ, min, targZ, max);
  l1.Draw();

  pad2->cd();
  gPad->SetFillColor(10);
  gPad->SetLeftMargin(0.15);
  hBy2.SetLineColor(4);
  hBy2.SetLineWidth(2);
  hBy2.SetTitle("x = y = 20 cm");
  hBy2.GetXaxis()->SetTitle("z [cm]");
  hBy2.GetYaxis()->SetTitle("B_{y} [T]");
  hBy2.Draw("AC");
  max = hBy2.GetHistogram()->GetMaximum();
  min = hBy2.GetHistogram()->GetMinimum();
  TLine l2(targZ, min, targZ, max);
  l2.Draw();

  pad3->cd();
  gPad->SetFillColor(10);
  gPad->SetLeftMargin(0.15);
  hBt1.SetLineColor(2);
  hBt1.SetLineWidth(2);
  hBt1.SetTitle("x = y = 0");
  hBt1.GetXaxis()->SetTitle("z [cm]");
  hBt1.GetYaxis()->SetTitle("B_{xz} [T]");
  hBt1.Draw("AC");
  max = hBt1.GetHistogram()->GetMaximum();
  min = hBt1.GetHistogram()->GetMinimum();
  TLine l3(targZ, min, targZ, max);
  l3.Draw();

  pad4->cd();
  gPad->SetFillColor(10);
  gPad->SetLeftMargin(0.15);
  hBt2.SetLineColor(2);
  hBt2.SetLineWidth(2);
  hBt2.SetTitle("x = y = 20 cm");
  hBt2.GetXaxis()->SetTitle("z [cm]");
  hBt2.GetYaxis()->SetTitle("B_{xz} [T]");
  hBt2.Draw("AC");
  max = hBt2.GetHistogram()->GetMaximum();
  min = hBt2.GetHistogram()->GetMinimum();
  TLine l4(targZ, min, targZ, max);
  l4.Draw();

  pad5->cd();
  gPad->SetLeftMargin(0.15);
  gPad->SetFillColor(10);
  hB1.UseCurrentStyle();
  hB1.GetXaxis()->SetTitle("x [cm]");
  hB1.GetYaxis()->SetTitle("y [cm]");
  char t[100];
  sprintf(t,"B [T] at z= 0",fzref1);
  hB1.SetTitle(t);
  hB1.Draw("COLZ");

  pad6->cd();
  gPad->SetFillColor(10);
  gPad->SetLeftMargin(0.15);
  hB2.UseCurrentStyle();
  hB2.GetXaxis()->SetTitle("x [cm]");
  hB2.GetYaxis()->SetTitle("y [cm]");
  char t[100];
  sprintf(t,"B [T] at RICH entrance (z=%8.2f cm)",fzref2);
  hB2->SetTitle(t);
  hB2.Draw("COLZ");

  pad7->cd();
  gPad->SetFillColor(10);
  gPad->SetLeftMargin(0.15);
  hB3.UseCurrentStyle();
  hB3.GetXaxis()->SetTitle("x [cm]");
  hB3.GetYaxis()->SetTitle("y [cm]");
  sprintf(t,"B [T] at RICH PM plane (z=%8.2f cm)",fzref3);
  hB3.SetTitle(t);
  hB3.Draw("COLZ");


  TString fieldType = "";
  if      ( type == 0 ) fieldType = "Constant field";
  else if ( type == 1 ) fieldType = "Field map";
  else if ( type == 2 ) fieldType = "Field Map Sym2";
  else if ( type == 3 ) fieldType = "Field Map Sym3";


  char t1[300];
  padinf->cd();
  TPaveText info(0.1,0.1,0.9,0.9);
  info.SetFillColor(10);
  info.SetBorderSize(0);
  info.SetTextAlign(2);
  sprintf(t1,"Field name: %s, type: %s",field->GetName(),fieldType.Data());
  info.AddText(0.05, 0.9, t1);
  Double_t bx = field->GetBx(0.,0.,0.) / 10.;
  Double_t by = field->GetBy(0.,0.,0.) / 10.;
  Double_t bz = field->GetBz(0.,0.,0.) / 10.;
  sprintf(t1,"Field at origin is (%7.4f, %7.4f, %7.4f) T",bx,by,bz);
  cout << t1 << endl;
  info.AddText(0.05, 0.7, t1);
  if ( type >= 1 && type <=3 ) {
    sprintf(t1, "Map file: %s",mapFile);
    cout << t1 << endl;
    info.AddText(0.05, 0.5, t1);
    Double_t xp = field->GetPositionX();
    Double_t yp = field->GetPositionY();
    Double_t zp = field->GetPositionZ();
    sprintf(t1,"Centre position (%.2f, %.2f, %.2f) cm",xp,yp,zp);
    info->AddText(0.05, 0.3, t1);
    Double_t scale = field->GetScale();
    sprintf(t1,"Scaling factor %.2f, Field integral along z = %.4f Tm",
	    scale,bint);
    info->AddText(0.05, 0.1, t1);
  }
  info.Draw();

  master->cd();
  sprintf(t1,"Field check for %s", field->GetName());
  TPaveLabel label(0.20, 0.92, 0.88, 0.97, t1);
  label->Draw();
  
  /*
  c1->cd();
  const char* wrkdir = getenv("VMCWORKDIR");
  TString logo = TString(wrkdir) + "/input/cbmlogo.gif";
  TImage* cbm = TImage::Open(logo);
  TPad* padimg = new TPad("padimg", "", 0.05, 0.80, 0.20, 0.95);
  padimg->Draw();
  padimg->cd();
  cbm->Draw();
  */
  


  ps->Close();
  
}