void All(){
	string varname = "topness";
	//string signal = "T2tt_850_100";
	string signal = "T2tt_650_100";
	//string region = "baseline";
	//string region = "baselineSmallDM";
	string region = "baselineSmallDM300";
	//string region = "baselineSmallDM2b";
	string channel = "allChannels";
	/*
	Optimization("topness", signal, region, channel);
	Optimization("topness_m1", signal, region, channel);
	Optimization("topness_m2", signal, region, channel);
	Optimization("topness_m3", signal, region, channel);
	Optimization("topness_m4", signal, region, channel);
	Optimization("topness_m5", signal, region, channel);
	Optimization("topness_m6", signal, region, channel);
	Optimization("topness_m7", signal, region, channel);
	Optimization("topness_m8", signal, region, channel);
	Optimization("topness_m9", signal, region, channel);
	Optimization("topness_m10", signal, region, channel);
	Optimization("topness_m11", signal, region, channel);
	Optimization("topness_m12", signal, region, channel);
	Optimization("topness_m13", signal, region, channel);
*/
	OptRes res_650_ref = Optimization(varname, "T2tt_650_100", region, channel,"plots/config_def.txt/1DStack.root");
	OptRes res_850_ref = Optimization(varname, "T2tt_850_100", region, channel,"plots/config_def.txt/1DStack.root");
	Shape(varname, region, channel,"plots/config_def.txt/1DSuperimposed.root");
	//Optimization("topness", signal, region, channel,"plots/config_def.txt/pow2/1DStack.root");
	//Optimization("topness", signal, region, channel,"plots/config_def.txt/pow2/b1nonb/1DStack.root");
	/*
	OptRes res_650_comb3 = Optimization(varname, "T2tt_650_100", region, channel,"plots/config_def.txt/comb3_all/1DStack.root");
	OptRes res_850_comb3 = Optimization(varname, "T2tt_850_100", region, channel,"plots/config_def.txt/comb3_all/1DStack.root");
	OptRes res_650_comb4 = Optimization(varname, "T2tt_650_100", region, channel,"plots/config_def.txt/comb4_all/1DStack.root");
	OptRes res_850_comb4 = Optimization(varname, "T2tt_850_100", region, channel,"plots/config_def.txt/comb4_all/1DStack.root");
	OptRes res_650_comb5 = Optimization(varname, "T2tt_650_100", region, channel,"plots/config_def.txt/comb5_all/1DStack.root");
	OptRes res_850_comb5 = Optimization(varname, "T2tt_850_100", region, channel,"plots/config_def.txt/comb5_all/1DStack.root");
	OptRes res_650_comb4_b1 = Optimization(varname, "T2tt_650_100", region, channel,"plots/config_def.txt/comb4/1DStack.root");
	OptRes res_850_comb4_b1 = Optimization(varname, "T2tt_850_100", region, channel,"plots/config_def.txt/comb4/1DStack.root");
	OptRes res_650_comb3_4 = Optimization(varname, "T2tt_650_100", region, channel,"plots/config_def.txt/comb3_4/1DStack.root");
	OptRes res_850_comb3_4 = Optimization(varname, "T2tt_850_100", region, channel,"plots/config_def.txt/comb3_4/1DStack.root");
		
		TCanvas* cROC = new TCanvas();
		TLegend* leg = new TLegend(0.6,0.7,0.8,0.9);
		cROC->Divide(2);
		cROC->cd(1);
		res_650_ref.gROC->SetTitle("ROC - T2tt_650-100");
		res_650_ref.gROC->Draw("ACP");
		res_650_comb3.gROC->SetLineColor(kGreen);
		res_650_comb3.gROC->Draw("same");
		res_650_comb4.gROC->SetLineColor(kRed);
		res_650_comb4.gROC->Draw("same");
		res_650_comb5.gROC->SetLineColor(kBlue);
		res_650_comb5.gROC->Draw("same");
		res_650_comb4_b1.gROC->SetLineColor(kOrange);
		res_650_comb4_b1.gROC->Draw("same");
		res_650_comb3_4.gROC->SetLineColor(kViolet);
		res_650_comb3_4.gROC->Draw("same");
		leg->AddEntry(res_650_ref.gROC,"default","l");
		leg->AddEntry(res_650_comb3.gROC,"3 jets","l");
		leg->AddEntry(res_650_comb4.gROC,"4 jets","l");
		leg->AddEntry(res_650_comb5.gROC,"5 jets","l");
		leg->AddEntry(res_650_comb4_b1.gROC,"4 jets (nb<=1)","l");
		leg->AddEntry(res_650_comb3_4.gROC,"4 jets (nb<=1) && 3 jets (nb>=2)","l");
		leg->Draw("same");
		cROC->cd(2);
		res_850_ref.gROC->SetTitle("ROC - T2tt_850-100");
		res_850_ref.gROC->Draw("ACP");
		res_850_comb3.gROC->SetLineColor(kGreen);
		res_850_comb3.gROC->Draw("same");
		res_850_comb4.gROC->SetLineColor(kRed);
		res_850_comb4.gROC->Draw("same");
		res_850_comb5.gROC->SetLineColor(kBlue);
		res_850_comb5.gROC->Draw("same");
		res_850_comb4_b1.gROC->SetLineColor(kOrange);
		res_850_comb4_b1.gROC->Draw("same");
		res_850_comb3_4.gROC->SetLineColor(kViolet);
		res_850_comb3_4.gROC->Draw("same");
		leg->Draw("same");
		cROC->Draw();
		cROC->Print("combjets.png");
 	return 0;	
*/	
	//for(int i=12;i<13;i++){
	//for(int i=45;i<60;i++){
	for(int i=20;i<22;i++){
	//for(int i=1;i<45;i++){
	//for(int i=1;i<9;i++){
		char dir[120]; 
		sprintf(dir,"plots/config2_%d.txt/",i);
		//sprintf(dir,"plots/config2_%d.txt/comb3_4/",i);
		//sprintf(dir,"plots/config_def.txt/comb3_4/");

		
		//sprintf(dir,"plots/tp2_config_%d.txt/pow2/1b1nonb/",i);
		//sprintf(dir,"plots/tp2_config_%d.txt/pow2/loopnonb_all/",i);
		//sprintf(dir,"plots/tp2_config_%d.txt/pow2/1DStack.root",i);
		//sprintf(dir,"plots/tp2_config_%d.txt/pow2/loopnonb/1DStack.root",i);
		//sprintf(dir,"plots/tp2_config_%d.txt/pow2/loopnonb_all/1DStack.root",i);
		//sprintf(dir,"plots/tp2_config_%d.txt/pow2/comb4/1DStack.root",i);
		//sprintf(dir,"plots/config_%d.txt/pow2/1DStack.root",i);
		//sprintf(dir,"plots/config_%d.txt/pow2/1DStack.root",i);
		//sprintf(dir,"plots_before_20July/plots/config_%d.txt/",i);
		//sprintf(dir,"plots/config_%d.txt/1DStack.root",i);
		//sprintf(dir,"plots/topness2/tp2_config_%d.txt/1DStack.root",i);
		cout<<"config_"<<i<<endl;
 		string file = string(dir)+"purity.dat";
		string command;
		command = string("cat ") + file + string(" | grep purity | awk '{print $8}'");
		system(command.c_str());
		string rfile = string(dir)+"1DStack.root";
		//Optimization(varname, signal, region, channel, rfile);
		OptRes res_650_cur = Optimization(varname, "T2tt_650_100", region, channel, rfile);
		OptRes res_850_cur = Optimization(varname, "T2tt_850_100", region, channel, rfile);
		rfile = string(dir)+"1DSuperimposed.root";
		Shape(varname, region, channel, rfile);
		
		TCanvas* cROC = new TCanvas();
		TLegend* leg = new TLegend(0.6,0.9,0.6,0.9);
		cROC->Divide(2);
		cROC->cd(1);
		res_650_ref.gROC->SetTitle("ROC - T2tt_650-100");
		res_650_ref.gROC->Draw("ACP");
		res_650_cur.gROC->SetLineColor(kRed);
		res_650_cur.gROC->Draw("same");
		leg->AddEntry(res_650_ref.gROC,"default","l");
		leg->AddEntry(res_650_cur.gROC,"current","l");
		leg->Draw("same");
		cROC->cd(2);
		res_850_ref.gROC->SetTitle("ROC - T2tt_850-100");
		res_850_ref.gROC->Draw("ACP");
		res_850_cur.gROC->SetLineColor(kRed);
		res_850_cur.gROC->Draw("same");
		leg->Draw("same");
		cROC->Draw();
		string cname_out(dir);
		std::replace( cname_out.begin(), cname_out.end(), '/', '_');
		cname_out="results/"+cname_out+".png";
		cROC->Print(cname_out.c_str());
	}
}
Пример #2
0
void plot_CL_chi2_roofit(char * filename, double min, double max, double initial, double ndof_min, double ndof_max, char * plot, char * var = "chi2")
{

	//gStyle->SetOptStat(0);
	//gStyle->SetOptFit(1);
	//gStyle->SetStatFontSize(0.02);
	TFile * _file0 = TFile::Open(filename);
	TTree * t = (TTree*)_file0->Get("tuple");

	RooRealVar * chi2 = new RooRealVar(var, "#chi^{2}", min, max);
	RooRealVar * ndof = new RooRealVar("ndof", "ndof", initial, ndof_min, ndof_max);
	RooChiSquarePdf * pdf = new RooChiSquarePdf("pdf", "pdf", *chi2, *ndof);

	RooDataSet * data = new RooDataSet("data", "data", RooArgSet(*chi2), RooFit::Import(*t));

	pdf->fitTo(*data);

	char formula[30];
	sprintf(formula, "TMath::Prob(%s,ndof)", var);

	RooFormulaVar * CL_ndof_eff_formula = new RooFormulaVar("CL","CL(#chi^{2})",formula, RooArgList(*chi2, *ndof));
	RooRealVar * CL_ndof_eff = (RooRealVar*) data->addColumn(*CL_ndof_eff_formula);
	CL_ndof_eff->setRange(0, 1);
	RooUniform * uniform = new RooUniform("uniform", "uniform", *CL_ndof_eff);
	uniform->fitTo(*data);

	//RooFormulaVar * CL_ndof_min_formula = new RooFormulaVar("CL","CL(#chi^{2})","TMath::Prob(chi2,39)", RooArgList(*chi2));
	//RooRealVar * CL_ndof_min = (RooRealVar*) data->addColumn(*CL_ndof_min_formula);
	//CL_ndof_min->setRange(0, 1);

	RooPlot * frame0 = chi2->frame(RooFit::Bins(25));
	data->plotOn(frame0);
	pdf->plotOn(frame0);
	pdf->paramOn(frame0, RooFit::Format("NELU", RooFit::AutoPrecision(2)), RooFit::Layout(0.6,0.95,0.75)); 
	data->statOn(frame0, RooFit::Format("NELU", RooFit::AutoPrecision(2)), RooFit::Layout(0.6,0.95,0.95));

	RooPlot * frame1 = CL_ndof_eff->frame(RooFit::Bins(10));
	data->plotOn(frame1);
	uniform->plotOn(frame1);	

        TCanvas * c = new TCanvas("c","c",1200, 600);
        c->Divide(2,1);
        c->cd(1);
	frame0->Draw();
        c->cd(2);
	frame1->Draw();

/*
        char buf[30];
        sprintf(buf, "TMath::Prob(chi2,%f)>>h1", f1->GetParameter(0));
        cout << buf << endl;
        c->Modified();
        c->Update();

        c->cd(2);
        t->Draw("TMath::Prob(chi2,ndof-8)>>h0");
        t->Draw(buf);
        h1->Draw();
        h1->Fit("pol0");
        h0->Draw("same");
        h1->GetXaxis()->SetTitle("CL(#chi^{2})");
        h1->GetYaxis()->SetTitle("Number of toys / 0.1");
        h1->SetMinimum(0);
        h1->SetMaximum(2*t->GetEntries()/nbins);
*/
        c->SaveAs(plot);



}
Пример #3
0
void rf610_visualerror()
{
  // S e t u p   e x a m p l e   f i t 
  // ---------------------------------------

  // Create sum of two Gaussians p.d.f. with factory
  RooRealVar x("x","x",-10,10) ;
  
  RooRealVar m("m","m",0,-10,10) ;
  RooRealVar s("s","s",2,1,50) ;
  RooGaussian sig("sig","sig",x,m,s) ;

  RooRealVar m2("m2","m2",-1,-10,10) ;
  RooRealVar s2("s2","s2",6,1,50) ;
  RooGaussian bkg("bkg","bkg",x,m2,s2) ;

  RooRealVar fsig("fsig","fsig",0.33,0,1) ;
  RooAddPdf model("model","model",RooArgList(sig,bkg),fsig) ;

  // Create binned dataset
  x.setBins(25) ;  
  RooAbsData* d = model.generateBinned(x,1000) ;

  // Perform fit and save fit result
  RooFitResult* r = model.fitTo(*d,Save()) ;


  // V i s u a l i z e   f i t   e r r o r 
  // -------------------------------------

  // Make plot frame
  RooPlot* frame = x.frame(Bins(40),Title("P.d.f with visualized 1-sigma error band")) ;
  d->plotOn(frame) ;

  // Visualize 1-sigma error encoded in fit result 'r' as orange band using linear error propagation
  // This results in an error band that is by construction symmetric
  //
  // The linear error is calculated as
  // error(x) = Z* F_a(x) * Corr(a,a') F_a'(x)
  //
  // where     F_a(x) = [ f(x,a+da) - f(x,a-da) ] / 2, 
  // 
  //         with f(x) = the plotted curve 
  //              'da' = error taken from the fit result
  //        Corr(a,a') = the correlation matrix from the fit result
  //                Z = requested significance 'Z sigma band'
  //
  // The linear method is fast (required 2*N evaluations of the curve, where N is the number of parameters), 
  // but may not be accurate in the presence of strong correlations (~>0.9) and at Z>2 due to linear and 
  // Gaussian approximations made
  //
  model.plotOn(frame,VisualizeError(*r,1),FillColor(kOrange)) ;


  // Calculate error using sampling method and visualize as dashed red line. 
  //
  // In this method a number of curves is calculated with variations of the parameter values, as sampled 
  // from a multi-variate Gaussian p.d.f. that is constructed from the fit results covariance matrix. 
  // The error(x) is determined by calculating a central interval that capture N% of the variations 
  // for each valye of x, where N% is controlled by Z (i.e. Z=1 gives N=68%). The number of sampling curves 
  // is chosen to be such that at least 100 curves are expected to be outside the N% interval, and is minimally 
  // 100 (e.g. Z=1->Ncurve=356, Z=2->Ncurve=2156)) Intervals from the sampling method can be asymmetric, 
  // and may perform better in the presence of strong correlations, but may take (much) longer to calculate
  model.plotOn(frame,VisualizeError(*r,1,kFALSE),DrawOption("L"),LineWidth(2),LineColor(kRed)) ;
  
  // Perform the same type of error visualization on the background component only.
  // The VisualizeError() option can generally applied to _any_ kind of plot (components, asymmetries, efficiencies etc..)
  model.plotOn(frame,VisualizeError(*r,1),FillColor(kOrange),Components("bkg")) ;
  model.plotOn(frame,VisualizeError(*r,1,kFALSE),DrawOption("L"),LineWidth(2),LineColor(kRed),Components("bkg"),LineStyle(kDashed)) ;

  // Overlay central value
  model.plotOn(frame) ;
  model.plotOn(frame,Components("bkg"),LineStyle(kDashed)) ;
  d->plotOn(frame) ;
  frame->SetMinimum(0) ;


  // V i s u a l i z e   p a r t i a l   f i t   e r r o r 
  // ------------------------------------------------------

  // Make plot frame
  RooPlot* frame2 = x.frame(Bins(40),Title("Visualization of 2-sigma partial error from (m,m2)")) ;
  
  // Visualize partial error. For partial error visualization the covariance matrix is first reduced as follows
  //        ___                   -1
  // Vred = V22  = V11 - V12 * V22   * V21
  //
  // Where V11,V12,V21,V22 represent a block decomposition of the covariance matrix into observables that
  // are propagated (labeled by index '1') and that are not propagated (labeled by index '2'), and V22bar
  // is the Shur complement of V22, calculated as shown above  
  //
  // (Note that Vred is _not_ a simple sub-matrix of V)

  // Propagate partial error due to shape parameters (m,m2) using linear and sampling method
  model.plotOn(frame2,VisualizeError(*r,RooArgSet(m,m2),2),FillColor(kCyan)) ;
  model.plotOn(frame2,Components("bkg"),VisualizeError(*r,RooArgSet(m,m2),2),FillColor(kCyan)) ;
  
  model.plotOn(frame2) ;
  model.plotOn(frame2,Components("bkg"),LineStyle(kDashed)) ;
  frame2->SetMinimum(0) ;
 

  // Make plot frame
  RooPlot* frame3 = x.frame(Bins(40),Title("Visualization of 2-sigma partial error from (s,s2)")) ;
  
  // Propagate partial error due to yield parameter using linear and sampling method
  model.plotOn(frame3,VisualizeError(*r,RooArgSet(s,s2),2),FillColor(kGreen)) ;
  model.plotOn(frame3,Components("bkg"),VisualizeError(*r,RooArgSet(s,s2),2),FillColor(kGreen)) ;
  
  model.plotOn(frame3) ;
  model.plotOn(frame3,Components("bkg"),LineStyle(kDashed)) ;
  frame3->SetMinimum(0) ;


  // Make plot frame
  RooPlot* frame4 = x.frame(Bins(40),Title("Visualization of 2-sigma partial error from fsig")) ;
  
  // Propagate partial error due to yield parameter using linear and sampling method
  model.plotOn(frame4,VisualizeError(*r,RooArgSet(fsig),2),FillColor(kMagenta)) ;
  model.plotOn(frame4,Components("bkg"),VisualizeError(*r,RooArgSet(fsig),2),FillColor(kMagenta)) ;
  
  model.plotOn(frame4) ;
  model.plotOn(frame4,Components("bkg"),LineStyle(kDashed)) ;
  frame4->SetMinimum(0) ;


  
  TCanvas* c = new TCanvas("rf610_visualerror","rf610_visualerror",800,800) ;
  c->Divide(2,2) ;
  c->cd(1) ; gPad->SetLeftMargin(0.15) ; frame->GetYaxis()->SetTitleOffset(1.4)  ; frame->Draw() ;
  c->cd(2) ; gPad->SetLeftMargin(0.15) ; frame2->GetYaxis()->SetTitleOffset(1.6) ; frame2->Draw() ;
  c->cd(3) ; gPad->SetLeftMargin(0.15) ; frame3->GetYaxis()->SetTitleOffset(1.6) ; frame3->Draw() ;
  c->cd(4) ; gPad->SetLeftMargin(0.15) ; frame4->GetYaxis()->SetTitleOffset(1.6) ; frame4->Draw() ;
}
Пример #4
0
void CsIProj()
{
  TFile *file = new TFile("../root/NZ_55_New.root");
  TFile *gates = new TFile("../gates/zlines.root");
  TFile *gates2 = new TFile("../gates/zlines_new.root");

  ofstream ofile("CsI_55A_New.dat");
  
  TCanvas *mycan = (TCanvas*)gROOT->FindObjectAny("mycan");
  if(!mycan)
    {
      mycan = new TCanvas("mycan","mycan");
      mycan->Divide(1,2);
    }
  
  
  ostringstream outstring;
  string name;
  int p1= 30, p2=50; //+- fit limits up to 2 peaks. May be different.
  int const num_par = 5; //number of peaks times 2(pol1)+3(gaus).
  
  for(int ic =0;ic<56;ic++)
    {
      
      outstring.str("");
      outstring << "dEE/dEE_" << ic;
      name = outstring.str();
      
      mycan->cd(1);
      TH2I *hist = (TH2I*)file->Get(name.c_str());
      hist->Draw("col");  
      hist->GetXaxis()->SetRangeUser(200.,1800.); 
      hist->GetYaxis()->SetRangeUser(5.,50.); 
   
      
      if(ic <16 || ic > 31)
	TCutG *mycut = (TCutG*)gates->Get(Form("Zline_%i_2_4",ic));
      else 
	TCutG *mycut = (TCutG*)gates2->Get(Form("Zline_%i_2_4",ic));
      mycut->Draw();

      file->cd();
      outstring.str("");
      outstring << "CsI/CsIGate/ECsI_" << ic << "_Gate";
      name = outstring.str();
      gPad->SetLogz();

      mycan->cd(2);
      TH1I * proj = (TH1I*)file->Get(name.c_str());
      proj->Draw();
      proj->Rebin(4);
      proj->GetXaxis()->SetRangeUser(700.,1800.);

      mycan->Modified();
      mycan->Update();

      TMarker * mark;
      mark=(TMarker*)mycan->WaitPrimitive("TMarker"); //Get the Background limits
      int bkg_lo = mark->GetX();
      delete mark;  
      mark=(TMarker*)mycan->WaitPrimitive("TMarker");
      int bkg_hi = mark->GetX();
      delete mark;
      mark=(TMarker*)mycan->WaitPrimitive("TMarker"); // Get the 1st peak initial guess
      int peak1 = mark->GetX();
      delete mark;
      
      
      double par[num_par] = {0.};
      double out[num_par] = {0.}; 
      int peak1_lo = peak1 - p1, peak1_hi = peak1 + p1; // Peak center and limits
      
      
      TF1 *l1 = new TF1("l1", "pol1", bkg_lo, bkg_hi);
      TF1 *g1 = new TF1("g1", "gaus", peak1_lo,peak1_hi);
      
      TF1 *total = new TF1("total", "pol1(0)+gaus(2)", bkg_lo,bkg_hi);
      
      proj->Fit(l1,"R");
      proj->Fit(g1,"R+");
      
      l1->GetParameters(&par[0]);
      g1->GetParameters(&par[2]);
      
      total->SetParameters(par);
      proj->Fit(total,"R");
      total->GetParameters(out);
      
      
      ofile << ic << " " << out[3] << endl;
      
      outstring.str("");
      outstring << "55A_" << ic;
      name = outstring.str();
      total->SetName(name.c_str());
      total->Draw("same");
      mycan->Modified();
      mycan->Update();
      
      bool IsGood = 0;

      cout << "Good fit?" << endl;
      cin >> IsGood;
  

      if(IsGood)
	{
      ofile << ic << " " << out[3] << endl;
	}      
      else
	ofile << ic << " " << -1 << endl;      

   

    }
  
  
  return;
}
Пример #5
0
void StAssociator(Int_t nevents=1,
const char *MainFile="/afs/rhic.bnl.gov/star/data/samples/*.geant.root")
{

  // Dynamically link needed shared libs
  gSystem->Load("St_base");
  gSystem->Load("StChain");
  gSystem->Load("StBFChain");

  gSystem->Load("St_Tables");
  gSystem->Load("StUtilities");
  gSystem->Load("StIOMaker");
  gSystem->Load("StarClassLibrary");
  gSystem->Load("StDetectorDbMaker");


  gSystem->Load("StTpcDb");
  gSystem->Load("StEvent");
//   gSystem->Load("StEventMaker"); //not needed if event.root branch present
  gSystem->Load("StEmcUtil"); 
  gSystem->Load("StEEmcUtil");
  
  gSystem->Load("StMcEvent");
  gSystem->Load("StMcEventMaker");
  gSystem->Load("StAssociationMaker");
  gSystem->Load("StMcAnalysisMaker");
    
  chain = new StChain("StChain"); 
  chain->SetDebug();
   
  // Now we add Makers to the chain...

  StIOMaker* ioMaker = new StIOMaker("IO","r",MainFile,"bfcTree");
  ioMaker->SetDebug();
  ioMaker->SetIOMode("r");
  ioMaker->SetBranch("*",0,"0");                 //deactivate all branches
  ioMaker->SetBranch("geantBranch",0,"r"); //activate geant Branch
  ioMaker->SetBranch("eventBranch",0,"r"); //activate geant Branch
//   ioMaker->SetBranch("dstBranch",0,"r"); //activate Event Branch
//   ioMaker->SetBranch("runcoBranch",0,"r"); //activate runco Branch

  // Note, the title "events" is used in the Association Maker, so don't change it.
  // StEventMaker is not needed for event.root files
//   StEventMaker*       eventReader   = new StEventMaker("events","title");
//   eventReader->doPrintMemoryInfo = kFALSE;
  StMcEventMaker*     mcEventReader = new StMcEventMaker; // Make an instance...
  StAssociationMaker* associator    = new StAssociationMaker;

  // If you need to use L3 TRIGGER uncomment the line:
  // associator->useL3Trigger();
  //associator->SetDebug();
  // For tracks created with the Sti package (ITTF), uncomment the next line:
  //associator->useInTracker();
  // Switch to use the distance or id association.
  associator->useDistanceAssoc();
  //associator->useIdAssoc();
  // Note: useDistanceAssoc and useIdAssoc are mutually exclusive
  // and they set and unset the same flag.
  // The flag will be set by the call done at the end.
  //associator->doPrintMemoryInfo = kTRUE;
  StMcAnalysisMaker*  examples      = new StMcAnalysisMaker;

  // Define the cuts for the Associations

  StMcParameterDB* parameterDB = StMcParameterDB::instance();  
  // TPC
  parameterDB->setXCutTpc(.6); // 6 mm
  parameterDB->setYCutTpc(.6); // 6 mm
  parameterDB->setZCutTpc(.6); // 6 mm
  parameterDB->setReqCommonHitsTpc(3); // Require 3 hits in common for tracks to be associated
  // FTPC
  parameterDB->setRCutFtpc(.3); // 3 mm
  parameterDB->setPhiCutFtpc(5*(3.1415927/180.0)); // 5 degrees
  parameterDB->setReqCommonHitsFtpc(3); // Require 3 hits in common for tracks to be associated
  // SVT
  parameterDB->setXCutSvt(.08); // 800 um
  parameterDB->setYCutSvt(.08); // 800 um
  parameterDB->setZCutSvt(.08); // 800 um
  parameterDB->setReqCommonHitsSvt(1); // Require 1 hits in common for tracks to be associated
    
    
  // now execute the chain member functions

  chain->PrintInfo();
  Int_t initStat = chain->Init(); // This should call the Init() method in ALL makers
  if (initStat) chain->Fatal(initStat, "during Init()");
    
  int istat=0,iev=1;
 EventLoop: if (iev<=nevents && istat!=2) {
   chain->Clear();
   cout << "---------------------- Processing Event : " << iev << " ----------------------" << endl;
   istat = chain->Make(iev); // This should call the Make() method in ALL makers
   if (istat == 2) { cout << "Last  Event Processed. Status = " << istat << endl; }
   if (istat == 3) { cout << "Error Event Processed. Status = " << istat << endl; }
   iev++; goto EventLoop;
 } // Event Loop
  examples->mAssociationCanvas = new TCanvas("mAssociationCanvas", "Histograms",200,10,600,600);
  TCanvas* myCanvas = examples->mAssociationCanvas;
  myCanvas->Divide(2,2);
  
  myCanvas->cd(1);
  gPad->SetLogy(0);
  examples->mTrackNtuple->Draw("(p-prec)/p:commTpcHits","prec!=0");

  TList* dList = chain->GetMaker("StMcAnalysisMaker")->Histograms();
  TH2F* hitRes = dList->At(0);
  TH1F* momRes = dList->At(1);
  TH2F* coordRc = dList->At(2);
  TH2F* coordMc = dList->At(3);
    
  myCanvas->cd(2);
  gPad->SetLogy(0);
  hitRes->Draw("box");
  
  myCanvas->cd(3);
  gPad->SetLogy(0);
  momRes->Draw();
  
  myCanvas->cd(4);
  gPad->SetLogy(0);
  coordRc->SetMarkerStyle(20);
  coordRc->Draw();
    
  myCanvas->cd(4);
  gPad->SetLogy(0);
  coordMc->SetMarkerColor(2);
  coordMc->SetMarkerStyle(20);
  coordMc->Draw("same");
  
  if(iev>200) chain->Finish(); // This should call the Finish() method in ALL makers,
  // comment it out if you want to keep the objects
  // available at the command line after running
  // the macro.

  // To look at the ntuple after the macro has executed:
  // f1 = new TFile("TrackMapNtuple.root");  //This opens the file, and loads the Ntuple
  // TrackNtuple->Draw("px:pxrec")  //Once loaded, the Ntuple is available by name.
  // To look at the Histograms once the Macro has executed:
  // TList* dList = chain->GetMaker("McAnalysis")->Histograms();
  // TH2F* hitRes = dList->At(0);  //or whatever index from 0 to 3
}
Пример #6
0
void EfficiencyMaps(TString Signal, TString Analysis, TString Channel, bool entries = false) {

  int const nSRs = 12;
  TString SRname[nSRs] = {"SR1_NoJet", "SR1_NoTag", "SR1_Veto", "SR1_Tag", 
			  "SR2_NoJet", "SR2_NoTag", "SR2_Veto", "SR2_Tag", 
			  "SR3_Veto",  "SR3_Tag",   "SR3_Veto_isr", "SR3_Tag_isr"};
  TString SRtitle[nSRs] = {"SR1^{\\text{0Jet}}_{\\text{0Tag}}", "SR1_^{\\text{Jets}}_{\\text{0Tag}}", "SR1_{\\text{0Tag}}", "SR1_{\\text{Tags}}", 
			   "SR2^{\\text{0Jet}}_{\\text{0Tag}}", "SR2_^{\\text{Jets}}_{\\text{0Tag}}", "SR2_{\\text{0Tag}}", "SR2_{\\text{Tags}}", 
			   "SR3_{\\text{0Tag}}", "SR3_{\\text{Tags}}", "SR3^{\\text{ISR}}_{\\text{0Tag}}", "SR3^{\\text{ISR}}_{\\text{Tags}}"};
  bool UseSR[nSRs]; 
  if (Analysis=="_Stop") {
    UseSR[0] = 0; UseSR[1] = 0; UseSR [2] = 1; UseSR [3] = 1;
    UseSR[4] = 0; UseSR[5] = 0; UseSR [6] = 1; UseSR [7] = 1;
    UseSR[8] = 0; UseSR[9] = 0; UseSR[10] = 1; UseSR[11] = 1; 
  } else if (Analysis=="_Chargino") {
    UseSR[0] = 1; UseSR[1] = 1; UseSR [2] = 0; UseSR [3] = 0;
    UseSR[4] = 1; UseSR[5] = 1; UseSR [6] = 0; UseSR [7] = 0;
    UseSR[8] = 1; UseSR[9] = 0; UseSR[10] = 0; UseSR[11] = 0; 
  }

  int nSRsignal = 0;
  for (int sr = 0; sr<nSRs; sr++)
    if (UseSR[sr]) 
      nSRsignal++;

  TH2F *EffMap  = new TH2F("EffMap",  "", 7, 0., 140., nSRsignal, 0., nSRsignal);
  TH2F *StatMap = new TH2F("StatMap", "", 7, 0., 140., nSRsignal, 0., nSRsignal);

  EffMap->SetXTitle("M_{T2}(ll) [GeV]");
  StatMap->SetXTitle("M_{T2}(ll) [GeV]");
  
  TString Syst = entries ? "noweight" : "nominal"; 
  myfile0 = new TFile("../minitrees/rootfilesOct17/" + Syst + "/Stop/" + Signal + ".root", "read");

  int isr = 1;

  for (int sr = 0; sr<nSRs; sr++)
    if (UseSR[sr]) {

      EffMap->GetYaxis()->SetBinLabel(isr, SRtitle[sr]);
      StatMap->GetYaxis()->SetBinLabel(isr, SRtitle[sr]);

      TString HistoName = "Stop/02_" + SRname[sr] + "/h_MT2ll" + Channel; 
      TString HistoNameGen = HistoName; 
      HistoNameGen.ReplaceAll("SR1", "SR1gen");
      HistoNameGen.ReplaceAll("SR2", "SR2gen");
      HistoNameGen.ReplaceAll("SR3", "SR3gen");
      HistoNameGen.ReplaceAll("MT2ll", "MT2llgen");
      if (SRname[sr].Contains("_isr")) {
	HistoName.ReplaceAll("_isr", "");
	HistoName.ReplaceAll("MT2ll", "MT2llisr");
	HistoNameGen.ReplaceAll("_isr", "");
	HistoNameGen.ReplaceAll("MT2ll", "MT2llisr");
      }

      TH1F *ThisHisto = GetHisto(HistoName);
      TH1F *ThisHistoGen = GetHisto(HistoNameGen);

      for (int ib = 1; ib<=7; ib++) {
	
	//float XXX = ThisHisto->GetBinContent(ib);
	//float EEE = ThisHistoGen->GetBinContent(ib);
	float XXX = 35.896*(ThisHisto->GetBinContent(ib)+ThisHistoGen->GetBinContent(ib))/2.;
        float EEE = 35.896*(ThisHisto->GetBinError(ib)+ThisHistoGen->GetBinError(ib))/2.;
	float value = EEE/XXX;
	if (entries) value = ThisHisto->GetBinContent(ib);
	EffMap->SetBinContent(ib, isr, value);
	//EffMap->SetBinError(ib, isr, EEE);
	
      }	

      isr++;
      
    }
  
  gStyle->SetOptStat(0);
  //gStyle->SetPaintTextFormat("5.2f");

  TCanvas *CC = new TCanvas("CC", "", 600, 400);
  CC->Divide(1, 1); 

  EffMap->Draw("COLZtext");
  //EffMap->Draw("COLZtexte");
  
  TString channelFlag = (Channel=="_em") ? "_emu" : "_eemumu";
  TString PlotName = entries ? "SignalEntries" : "SignalStatError";
  CC->Print("../Plots/MapMySignal/" + PlotName + "Map_" + Signal + channelFlag + ".pdf");
  CC->Print("../Plots/MapMySignal/" + PlotName + "Map_" + Signal + channelFlag + ".png");

}
Пример #7
0
void pileup()
{
//  TH3D* h = (TH3D*)GetHist("/net/hisrv0001/home/davidlw/scratch1/DiHadronCorrelations/outputs_312/HIData_Minbias_2760GeV/merged/HIData_Minbias_2760GeV_PPRereco_INCLMULT_nmin-1_nmax-1_etatrg-2.4-2.4_etaass-2.4-2.4_centmin-1_centmax-1.root","multmaxvssecvszvtxsep");
  TH3D* h = (TH3D*)GetHist("/net/hisrv0001/home/davidlw/scratch1/DiHadronCorrelations/outputs_312/HydjetReco_Minbias_2760GeV/merged/HydjetReco_Minbias_2760GeV_PeripheralNew_INCLMULT_nmin-1_nmax-1_etatrg-2.4-2.4_etaass-2.4-2.4_centmin-1_centmax-1.root","multmaxvssecvszvtxsep");
//  TH3D* h = (TH3D*)GetHist("/net/hisrv0001/home/davidlw/scratch1/DiHadronCorrelations/outputs_312/PAData_Minbias_5TeV/merged/PAData_Minbias_5TeV_HM_PromptReco_INCLMULTAllPURej3Vtx_nmin-1_nmax-1_etatrg-2.4-2.4_etaass-2.4-2.4_centmin-1_centmax-1.root","multmaxvssecvszvtxsep");

  TF1* func[40];
  TGraph* xx_yy[40];
  double par0_arr[40];
  double par1_arr[40];
  double par2_arr[40];
  double dz_arr[40];
//  double binwidth=0.2;
  double binedges[16]={0.0,0.2,0.3,0.4,0.5,0.6,0.8,1.0,1.4,1.8,2.4,3.0,4.2,5.0,7.0,10.0};

  TCanvas* c16 = new TCanvas("c16","c16",800,600);
  c16->Divide(4,4);

  for(int i=0;i<15;i++)
  {
//    h->GetZaxis()->SetRange(h->GetZaxis()->FindBin(binwidth*i),h->GetZaxis()->FindBin(binwidth*i+binwidth));
    h->GetZaxis()->SetRange(h->GetZaxis()->FindBin(binedges[i]),h->GetZaxis()->FindBin(binedges[i+1]));
    h->GetYaxis()->SetRange(h->GetYaxis()->FindBin(2),h->GetYaxis()->FindBin(50));
    TH2D* h2D = (TH2D*)h->Project3DProfile(Form("yx%d",i));
    h2D->Rebin2D(10,1);
    TProfile* hprof_x = (TProfile*)h2D->ProfileX("hprof_x",-1,-1,"s");
    double xx[500];
    double yy[500];
    for(int ibin=1;ibin<=hprof_x->GetNbinsX();ibin++)
    {
      yy[ibin-1] = hprof_x->GetBinContent(ibin)+2*hprof_x->GetBinError(ibin);
      xx[ibin-1] = hprof_x->GetBinCenter(ibin);
    }
  
// Hydjet
//    TF1* func = new TF1("func","[0]+[1]*(x-[2])*(x-[2])",0,500);
//    func->SetParameters(20,-0.1,150);
  func[i] = new TF1(Form("func_%d",i),"[0]*x**[1]",0,500);
  func[i]->SetParameters(1,0.5);
  func[i]->SetParLimits(0,0,10000);
  func[i]->SetParLimits(1,0,10000);
  if(i==0) func[i]->FixParameter(0,8); //pPb
//  else if(i>11) func[i]->FixParameter(0,20); //pPb
  else func[i]->FixParameter(0,2.); //pPb

//  func->FixParameter(0,5); //PbPb

//    TF1* func = new TF1("func","[0]+[1]*x",40,500);
//    double par1 = (hprof_x->GetBinContent(6)+hprof_x->GetBinError(6)-hprof_x->GetBinContent(1)-hprof_x->GetBinError(1))/(hprof_x->GetBinCenter(6)-hprof_x->GetBinCenter(1));
//    double par0 = hprof_x->GetBinContent(6)+hprof_x->GetBinError(6)-par1*hprof_x->GetBinCenter(6);
//    func->SetParameters(par0,par1);

    xx_yy[i] = new TGraph(hprof_x->GetNbinsX(),xx,yy);
    xx_yy[i]->Fit(Form("func_%d",i),"NO","",0,300);

    c16->cd(i+1);
    xx_yy[i]->Draw("AP"); 
    func[i]->SetLineColor(kRed);
    func[i]->Draw("Lsame");   

    par2_arr[i] = func[i]->GetParameter(2);    
    par1_arr[i] = func[i]->GetParameter(1);
    par0_arr[i] = func[i]->GetParameter(0);
    dz_arr[i] = (binedges[i]+binedges[i+1])/2;
  }

  TGraph* gr_par0 = new TGraph(15,dz_arr,par0_arr);
  TGraph* gr_par1 = new TGraph(15,dz_arr,par1_arr);
  TGraph* gr_par2 = new TGraph(15,dz_arr,par2_arr);

  TCanvas* cc = new TCanvas("cc","",950,400);  
  cc->Divide(3,1);
  cc->cd(1);
  gr_par0->Draw("AP");
  TF1* func_par0 = new TF1("func_par0","[2]*exp(-x**2/[0])*x**[3]+[1]",0.0,10.0);
  func_par0->SetParameters(0.2,0,5,-1);
  func_par0->FixParameter(2,0);
  gr_par0->Fit("func_par0","NO","",0.3,4.0);
  func_par0->Draw("Lsame");
  cc->cd(2);
  gr_par1->Draw("AP");
//  TF1* func_par1 = new TF1("func_par1","[2]*exp(-x**2/[0])*x**[3]+[1]",0.,10.0);
//  func_par1->SetParameters(0.2,0,-0.0005,0);
//  TF1* func_par1 = new TF1("func_par1","[2]*exp(-x/[0])*x**[3]+[1]",0.,10.0);
  TF1* func_par1 = new TF1("func_par1","[1]*exp(-x**[2]/[0])*x**[3]",0.,10.0);
  func_par1->SetParameters(0.1,0.6,2,1);
//  func_par1->FixParameter(2,1);
//  func_par1->FixParameter(3,1);

  gr_par1->Fit("func_par1","NO","",0.3,4.0);
  func_par1->Draw("Lsame");
  cc->cd(3);
  gr_par2->Draw("AP"); 
  TF1* func_par2 = new TF1("func_par2","[2]*exp(-x**2/[0])*x**[3]+[1]",0.,10.0);
  func_par2->SetParameters(1.2,170,120,1);
  gr_par2->Fit("func_par2","NO","",0.2,2.0);
  func_par2->Draw("Lsame");

cout<<Form("par0=%.2f*exp(-x**2/%.2f)*(x**%.2f)+%.2f",func_par0->GetParameter(2),func_par0->GetParameter(0),func_par0->GetParameter(3),func_par0->GetParameter(1))<<endl;
cout<<Form("par1=%.6f*exp(-x/%.6f)*(x**%.6f)+%.2f",func_par1->GetParameter(2),func_par1->GetParameter(0),func_par1->GetParameter(3),func_par1->GetParameter(1))<<endl;
cout<<Form("par2=%.2f*exp(-x**2/%.2f)*(x**%.2f)+%.2f",func_par2->GetParameter(2),func_par2->GetParameter(0),func_par2->GetParameter(3),func_par2->GetParameter(1))<<endl;

//  TF2* func2D = new TF2("func2D","[2]*exp(-x**2/[0])*x**[3]+[1]+([6]*exp(-x**2/[7])*x**[3]+[5])*y",0,1.0,0,500);
//  TF2* func2D = new TF2("func2D","[2]*exp(-x**2/[0])*x**[3]+[1]+([6]*exp(-x/[4])*x**[7]+[5])*(y-[10]*exp(-x**2/[8])*x**[11]-[9])*(y-[10]*exp(-x**2/[8])*x**[11]-[9])",0,5.0,0,500);
//  TF2* func2D = new TF2("func2D","([2]*exp(-x**2/[0])*x**[3]+[1])*y**[4]",0,10.0,0,500);
  TF2* func2D = new TF2("func2D","[0]*y**([2]*exp(-x**[3]/[1])*x**[4])",0,10.0,0,500);
  func2D->SetParameter(0,func_par0->GetParameter(1));
  func2D->SetParameter(1,func_par1->GetParameter(0));
  func2D->SetParameter(2,func_par1->GetParameter(1));
  func2D->SetParameter(3,func_par1->GetParameter(2));
  func2D->SetParameter(4,func_par1->GetParameter(3));
/*
  func2D->SetParameter(0,func_par0->GetParameter(0));
  func2D->SetParameter(1,func_par0->GetParameter(1));
  func2D->SetParameter(2,func_par0->GetParameter(2));
  func2D->SetParameter(3,func_par0->GetParameter(3));
  func2D->SetParameter(4,func_par1->GetParameter(0));
  func2D->SetParameter(5,func_par1->GetParameter(1));
  func2D->SetParameter(6,func_par1->GetParameter(2));
  func2D->SetParameter(7,func_par1->GetParameter(3));
  func2D->SetParameter(8,func_par2->GetParameter(0));
  func2D->SetParameter(9,func_par2->GetParameter(1));
  func2D->SetParameter(10,func_par2->GetParameter(2));
  func2D->SetParameter(11,func_par2->GetParameter(3));
*/
/*
cout<<Form("%.6f, %.6f, %.6f, %.6f,",func_par0->GetParameter(0),func_par0->GetParameter(1),func_par0->GetParameter(2),func_par0->GetParameter(3))<<endl;
cout<<Form("%.6f, %.6f, %.6f, %.6f,",func_par1->GetParameter(0),func_par1->GetParameter(1),func_par1->GetParameter(2),func_par1->GetParameter(3))<<endl;
cout<<Form("%.6f, %.6f, %.6f, %.6f,",func_par2->GetParameter(0),func_par2->GetParameter(1),func_par2->GetParameter(2),func_par2->GetParameter(3))<<endl;
*/
cout<<Form("%.6f, %.6f, %.6f, %.6f, %.6f,",func2D->GetParameter(0),func2D->GetParameter(1),func2D->GetParameter(2),func2D->GetParameter(3),func2D->GetParameter(4))<<endl;
cout<<Form("%.6f, %.6f",func[0]->GetParameter(0),func[0]->GetParameter(1))<<endl;

  TH2D* h_pileup = new TH2D("distfunc",";d (cm);N_{trk}^{primary};N_{trk}^{secondary}",500,0,50.0,50,0,500);

  for(int i=1;i<=h_pileup->GetNbinsX();i++) 
    for(int j=1;j<=h_pileup->GetNbinsY();j++)
    {

//      if(h_pileup->GetYaxis()->GetBinCenter(j)<func2D->Eval(h_pileup->GetXaxis()->GetBinCenter(i),h_pileup->GetYaxis()->GetBinCenter(j))) h_pileup->SetBinContent(i,j,h_pileup->GetYaxis()->GetBinCenter(j));
//      else if(h_pileup->GetXaxis()->GetBinCenter(i)<0.2) h_pileup->SetBinContent(i,j,func2D->Eval(0.2,h_pileup->GetYaxis()->GetBinCenter(j)));
//      else h_pileup->SetBinContent(i,j,func2D->Eval(h_pileup->GetXaxis()->GetBinCenter(i),h_pileup->GetYaxis()->GetBinCenter(j)));
      if(h_pileup->GetXaxis()->GetBinCenter(i)<0.2) h_pileup->SetBinContent(i,j,func[0]->Eval(h_pileup->GetYaxis()->GetBinCenter(j)));
      else h_pileup->SetBinContent(i,j,func2D->Eval(h_pileup->GetXaxis()->GetBinCenter(i),h_pileup->GetYaxis()->GetBinCenter(j)));
    }

/*
  for(int i=1;i<=h_pileup->GetNbinsX();i++) 
    for(int j=1;j<=h_pileup->GetNbinsY();j++)
    {
      for(int k=0;k<15;k++) 
      {
        if(h_pileup->GetXaxis()->GetBinCenter(i)>binedges[k] && h_pileup->GetXaxis()->GetBinCenter(i)<binedges[k+1]) h_pileup->SetBinContent(i,j,func[k]->Eval(h_pileup->GetYaxis()->GetBinCenter(j)));
      }
    }
*/

  TCanvas* c2D = new TCanvas("c2D","",550,500);
  c2D->SetPhi(-60);
  c2D->SetTheta(50);
  h_pileup->SetAxisRange(0,3.0,"X");
  h_pileup->GetXaxis()->CenterTitle();
  h_pileup->GetYaxis()->CenterTitle();
  h_pileup->GetZaxis()->CenterTitle();
  h_pileup->Draw("surf1"); 
  SaveCanvas(c2D,"pPb/corr","pileup_distfunc_hydjet");
return;
  TFile* fout = new TFile("/net/hisrv0001/home/davidlw/scratch1/DiHadronCorrelations/efficiency/pileup_distfunc_pPb_1sigma_mode1.root","recreate");
  h_pileup->Write();
  fout->Close();
}
Пример #8
0
void Unfold2(int algo= 3,bool useSpectraFromFile=0, bool useMatrixFromFile=0, int doToy = 0, int isMC = 0,char *spectraFileName = (char*)"pbpb_spectra_akPu3PF.root",double recoJetPtCut = 60,double trackMaxPtCut = 0, int nBayesianIter = 4, int doBjets=0) // algo 2 =akpu2 ; 3 =akpu3 ; 4 =akpu4 ;1 = icpu5
{
  
  gStyle->SetErrorX(0.5);
  gStyle->SetPaintTextFormat("3.2f");
  gStyle->SetOptLogz(1);
  gStyle->SetPadRightMargin(0.13);	
  gStyle->SetOptTitle(0);

	const float pplumi=5.3e9;
        const bool SavePlot=kTRUE;

  TH1::SetDefaultSumw2();
  TH2::SetDefaultSumw2();
  
  // input files
  char *fileNamePP_data = (char*)"/net/hidsk0001/d00/scratch/maoyx/pPb/Btag/CodeMatt/NewFormatV4_bFractionMCTemplate_pppp1_SSVHEat2.0FixCL0_bin_0_40_eta_0_2.root";
  char *fileNamePbPb_data = (char*)"/net/hidsk0001/d00/scratch/maoyx/pPb/Btag/CodeMatt/AltBinningV6_bFractionMCTemplate_ppPbPb1_SSVHEat2.0FixCL0_bin_0_40_eta_0_2.root";
  char *fileNamePP_mc = NULL;
  if(doBjets) fileNamePP_mc = (char*)"/net/hidsk0001/d00/scratch/kjung/histos/ppMC_ppReco_ak3PF_BjetTrig_noIPupperCut.root";
  else fileNamePP_mc = (char*)"/net/hidsk0001/d00/scratch/kjung/histos//ppMC_ppReco_ak3PF_QCDjetTrig_noIPupperCut.root";
  char *fileNamePbPb_mc = NULL;
  if(doBjets)fileNamePbPb_mc = (char*) "/net/hisrv0001/home/mnguyen/scratch/bTaggingOutput/ntuples/PbPbBMC_pt30by3_ipHICalibCentWeight_noTrig.root";
  else fileNamePbPb_mc = (char*) "/net/hisrv0001/home/mnguyen/scratch/bTaggingOutput/ntuples/PbPbQCDMC_pt30by3_ipHICalibCentWeight_noTrig.root";

  // grab ntuples
  TFile *infPbPb_mc = new TFile(fileNamePbPb_mc);
  TFile *infPP_mc = new TFile(fileNamePP_mc);


  // Output file
  TFile *pbpb_Unfo;
  if (isMC) pbpb_Unfo = new TFile(Form("pbpb_Unfo_%s_MC.root",algoName[algo]),"RECREATE");
  else pbpb_Unfo  = new TFile(Form("pbpb_Unfo_%s_jtpt%.0f_trk%.0f.root",algoName[algo],recoJetPtCut,trackMaxPtCut),"RECREATE");
  // Histograms used by RooUnfold
  UnfoldingHistos *uhist[nbins_cent+1];
		
  // Initialize Histograms   
	
  for (int i=0;i<=nbins_cent;i++) uhist[i] = new UnfoldingHistos(i);
	
  // Initialize reweighting functions
  
  TCut dataSelection;
  TCut dataSelectionPP;
  TCut TriggerSelectionPP;
  TCut TriggerSelectionPbPb80;

  if(doBjets)dataSelection = "weight*(abs(refparton_flavorForB)==5&&abs(jteta)<2)";
  else dataSelection = "weight*(abs(jteta)<2)";
  

  if (isMC) cout<<"This is a MC closure test"<<endl;
  else cout<< "This is a data analysis"<<endl;    		     
	     	
  // Setup jet data branches, basically the jet tree branches are assigned to this object when we loop over the events
	
  JetDataPbPb *dataPbPb   = new JetDataPbPb(fileNamePbPb_mc,(char*)"nt"); // PbPb data	
  JetDataPP *dataPP = new JetDataPP(fileNamePP_mc,(char*)"nt");	// pp data
	
  TFile *fSpectra(0);		
  if (useSpectraFromFile||useMatrixFromFile){
    fSpectra = new TFile(spectraFileName,"read");
  }
  
  // Come back to the output file dir
  pbpb_Unfo->cd();

  // Get Jet spectra from data file
  cout <<"Reading data..."<<endl;

  // This doesn't seem to be relevant for the moment -Matt
  /*	

  TTree *tPbPbJet = (TTree*)infPbPb_mc->Get("nt");
  TTree *tPPJet  = (TTree*)infPP_mc->Get("nt");


  TCanvas * cInput = new TCanvas("cInput","Input",800,400);
  cInput->Divide(2,1);
		
  cout <<"Spectra..."<<endl;	
	
  for (int i=0;i<=nbins_cent;i++){
    cout <<nbins_cent<<endl;
    TCut centCut = Form("bin<%.0f&&bin>=%.0f",boundaries_cent[i+1],boundaries_cent[i]);
    if (useSpectraFromFile) {
      uhist[i]->hMeas = (TH1F*)fSpectra->Get(Form("hMeas_cent%d",i));
    } else {
      if (!isMC) {
	tPbPbJet->Project(Form("hMeas_cent%d",i),"jtptB", dataSelection&&centCut&&TriggerSelectionPbPb80);
      }   
    }
		
    if (useMatrixFromFile) {
      cout <<"Matrix"<<endl;
      uhist[i]->hMatrixFit = (TH2F*) fSpectra->Get(Form("hMatrixFit_cent%d",i));
      uhist[i]->hMeasMatch = (TH1F*)((TH2F*) fSpectra->Get(Form("hMatrixFit_cent%d",i)))->ProjectionY();
      uhist[i]->hMeasMatch->Divide(uhist[i]->hMeas);
    } else {
      uhist[i]->hMeasMatch = 0;
    }
    uhist[i]->hMeas->Draw();
  }

  if (!isMC) tPPJet->Project(Form("hMeas_cent%d",nbins_cent),"jtpt",dataSelectionPP&&TriggerSelectionPP);
  */
  cout <<"MC..."<<endl;	
  
  TH1F *hCent = new TH1F("hCent","",nbins_cent,boundaries_cent);
 
		
  // Fill PbPb MC   
  if (!useMatrixFromFile) {
    for (Long64_t jentry2=0; jentry2<dataPbPb->tJet->GetEntries();jentry2++) {
      dataPbPb->tJet->GetEntry(jentry2);
      
      // change when we switch to centrality binning
      int cBin = 0;
      
      //int cBin = hCent->FindBin(dataPbPb->bin)-1;
      /*
	if (cBin>=nbins_cent) continue;
	if (cBin==-1) continue;
      */
      
      if ( dataPbPb->refpt  < 0. ) continue;
      if ( dataPbPb->jteta  > 2. || dataPbPb->jteta < -2. ) continue;
      if ( dataPbPb->refpt<0) dataPbPb->refpt=0;
      if (doBjets && fabs(dataPbPb->refparton_flavorForB)!=5) continue;
      if (doBjets&& dataPbPb->discr_ssvHighEff<2) continue;
      if (doBjets && dataPbPb->jtptB < recoJetPtCut) continue;
      if (!doBjets && dataPbPb->jtptA < recoJetPtCut) continue;
      //if ( dataPbPb->isTrig <1) continue;
      
      if(!doBjets)if(dataPbPb->refpt < 50 && dataPbPb->jtptA>120) continue;
      if(doBjets)if(dataPbPb->refpt < 50 && dataPbPb->jtptB>120) continue;

      if (!isMC||jentry2 % 2 == 1) {
	if(doBjets)uhist[cBin]-> hMatrix->Fill(dataPbPb->refpt,dataPbPb->jtptB,dataPbPb->weight);
	else uhist[cBin]-> hMatrix->Fill(dataPbPb->refpt,dataPbPb->jtptA,dataPbPb->weight);
      }	  
      if (jentry2 % 2 == 0) {
	uhist[cBin]-> hGen->Fill(dataPbPb->refpt,dataPbPb->weight);   
	if(doBjets)uhist[cBin]-> hMeas->Fill(dataPbPb->jtptB,dataPbPb->weight);  	 
	else uhist[cBin]-> hMeas->Fill(dataPbPb->jtptA,dataPbPb->weight);  	 
	//uhist[cBin]-> hMeasJECSys->Fill(dataPbPb->jtpt*(1.+0.02/nbins_cent*(nbins_cent-i)),dataPbPb->weight); 
	// FIXME!!!!!!  i is supposed to be a loop over centrality !!!!
	if(doBjets)uhist[cBin]-> hMeasJECSys->Fill(dataPbPb->jtptB*(1.+0.02/nbins_cent*(nbins_cent-0)),dataPbPb->weight); 
	else uhist[cBin]-> hMeasJECSys->Fill(dataPbPb->jtptA*(1.+0.02/nbins_cent*(nbins_cent-0)),dataPbPb->weight); 
      }
    }

    //pp will just fill the last index of the centrality array

    // fill pp MC
    for (Long64_t jentry2=0; jentry2<dataPP->tJet->GetEntries();jentry2++) {
      dataPP->tJet->GetEntry(jentry2);
      
      if ( dataPP->refpt<0) continue;
      if ( dataPP->jteta  > 2. || dataPP->jteta < -2. ) continue;
      if ( dataPP->refpt<0) dataPP->refpt=0;
      if ( doBjets && fabs(dataPP->refparton_flavorForB)!=5) continue;
      if ( doBjets && dataPP->discr_ssvHighEff<2) continue;
      if ( dataPP->jtpt < recoJetPtCut) continue;
      
      if (!isMC||jentry2 % 2 == 1) {
	uhist[nbins_cent]-> hMatrix->Fill(dataPP->refpt,dataPP->jtpt,dataPP->weight);
      }	  
      if (jentry2 % 2 == 0) {
	uhist[nbins_cent]-> hGen->Fill(dataPP->refpt,dataPP->weight);   
	uhist[nbins_cent]-> hMeas->Fill(dataPP->jtpt,dataPP->weight); 
      }           
    }
  }

	

  cout <<"Response Matrix..."<<endl;
	
  TCanvas * cMatrix = new TCanvas("cMatrix","Matrix",800,400);
  cMatrix->Divide(2,1);

  for (int i=0;i<=nbins_cent;i++){
    cMatrix->cd(i+1);
    if (!useMatrixFromFile) {
      TF1 *f = new TF1("f","[0]*pow(x+[2],[1])");
      f->SetParameters(1e10,-8.8,40);
      for (int y=1;y<=uhist[i]->hMatrix->GetNbinsY();y++) {
	double sum=0;
	for (int x=1;x<=uhist[i]->hMatrix->GetNbinsX();x++) {
	  if (uhist[i]->hMatrix->GetBinContent(x,y)<=1*uhist[i]->hMatrix->GetBinError(x,y)) {
	    uhist[i]->hMatrix->SetBinContent(x,y,0);
	    uhist[i]->hMatrix->SetBinError(x,y,0);
	  }
	  sum+=uhist[i]->hMatrix->GetBinContent(x,y);
	}
				
	for (int x=1;x<=uhist[i]->hMatrix->GetNbinsX();x++) {	   
	  double ratio = 1;
	  uhist[i]->hMatrix->SetBinContent(x,y,uhist[i]->hMatrix->GetBinContent(x,y)*ratio);
	  uhist[i]->hMatrix->SetBinError(x,y,uhist[i]->hMatrix->GetBinError(x,y)*ratio);
	}
      }
    }
    uhist[i]->hResponse = (TH2F*)uhist[i]->hMatrix->Clone(Form("hResponse_cent%d",i));
    for (int y=1;y<=uhist[i]->hResponse->GetNbinsY();y++) {
      double sum=0;
      for (int x=1;x<=uhist[i]->hResponse->GetNbinsX();x++) {
	if (uhist[i]->hResponse->GetBinContent(x,y)<=0*uhist[i]->hResponse->GetBinError(x,y)) {
	  uhist[i]->hResponse->SetBinContent(x,y,0);
	  uhist[i]->hResponse->SetBinError(x,y,0);
	}
	sum+=uhist[i]->hResponse->GetBinContent(x,y);
      }
			
      for (int x=1;x<=uhist[i]->hResponse->GetNbinsX();x++) {  	
	if (sum==0) continue;
	double ratio = uhist[i]->hMeas->GetBinContent(y)/sum;
	if (uhist[i]->hMeas->GetBinContent(y)==0) ratio = 1e-100/sum;
      }
    }
		
    uhist[i]->hResponseNorm = (TH2F*)uhist[i]->hMatrix->Clone(Form("hResponseNorm_cent%d",i));
    for (int x=1;x<=uhist[i]->hResponseNorm->GetNbinsX();x++) {
      double sum=0;
      for (int y=1;y<=uhist[i]->hResponseNorm->GetNbinsY();y++) {
	if (uhist[i]->hResponseNorm->GetBinContent(x,y)<=0*uhist[i]->hResponseNorm->GetBinError(x,y)) {
	  uhist[i]->hResponseNorm->SetBinContent(x,y,0);
	  uhist[i]->hResponseNorm->SetBinError(x,y,0);
	}
	sum+=uhist[i]->hResponseNorm->GetBinContent(x,y);
      }
			
      for (int y=1;y<=uhist[i]->hResponseNorm->GetNbinsY();y++) {  	
	if (sum==0) continue;
	double ratio = 1./sum;
	uhist[i]->hResponseNorm->SetBinContent(x,y,uhist[i]->hResponseNorm->GetBinContent(x,y)*ratio);
	uhist[i]->hResponseNorm->SetBinError(x,y,uhist[i]->hResponseNorm->GetBinError(x,y)*ratio);
      }
    }
		
    uhist[i]->hResponse->Draw("col");
		
    if (!useMatrixFromFile) uhist[i]->hMatrixFit = uhist[i]->hMatrix;
    uhist[i]->hMatrixFit->SetName(Form("hMatrixFit_cent%d",i));
  }

   cMatrix->Update();
  if (isMC==0) {
    // Use measured histogram from Matt & Kurt's file
	   
    // PbPb file:

    TFile *infMatt = new TFile(fileNamePbPb_data);
    TH1F *hMattPbPb = NULL;
    if(doBjets) hMattPbPb = (TH1F*) infMatt->Get("hRawBData");
    else hMattPbPb = (TH1F*) infMatt->Get("hIncJetsData");
    divideBinWidth(hMattPbPb);
           
    // Need to match the binning carefully, please double check whenever you change the binning
    for (int i=1;i<=hMattPbPb->GetNbinsX();i++)
      {
	uhist[0]->hMeas->SetBinContent(i+uhist[0]->hMeas->FindBin(61)-1,hMattPbPb->GetBinContent(i));  
	uhist[0]->hMeas->SetBinError(i+uhist[0]->hMeas->FindBin(61)-1,hMattPbPb->GetBinError(i));  
      }

    // pp file:
    // The file name needs to be updated!!!!!
    TFile *infMattPP = new TFile(fileNamePP_data);
    TH1F *hMattPP = NULL;
    if(doBjets)hMattPP = (TH1F*) infMattPP->Get("hRawBData");
    else hMattPP = (TH1F*) infMattPP->Get("hIncJetsData");
    divideBinWidth(hMattPP);
	   
    // Need to match the binning carefully, please double check whenever you change the binning
    for (int i=1;i<=hMattPP->GetNbinsX();i++)
      {
	uhist[nbins_cent]->hMeas->SetBinContent(i+uhist[nbins_cent]->hMeas->FindBin(61)-1,hMattPP->GetBinContent(i));  
	uhist[nbins_cent]->hMeas->SetBinError(i+uhist[nbins_cent]->hMeas->FindBin(61)-1,hMattPP->GetBinError(i));  
      }

  }

 
  pbpb_Unfo->cd();
	
  cout << "==================================== UNFOLD ===================================" << endl;
	
  //char chmet[100]; 
	
  // ======================= Reconstructed pp and PbPb spectra =========================================================
  TCanvas * cPbPb = new TCanvas("cPbPb","Comparison",1200,600);
  cPbPb->Divide(2,1); 
  cPbPb->cd(1);
	
	
  for (int i=0;i<=nbins_cent;i++) {
    cPbPb->cd(i+1)->SetLogy();   
    // Do Bin-by-bin
    TH1F *hBinByBinCorRaw = (TH1F*)uhist[i]->hResponse->ProjectionY(); 
    TH1F *hMCGen           = (TH1F*)uhist[i]->hResponse->ProjectionX(); // gen
    hBinByBinCorRaw->Divide(hMCGen);
    TF1 *f = new TF1("f","[0]+[1]*x");
    hBinByBinCorRaw->Fit("f","LL ","",90,300);
    TH1F* hBinByBinCor = (TH1F*)hBinByBinCorRaw->Clone();//functionHist(f,hBinByBinCorRaw,Form("hBinByBinCor_cent%d",i));
    delete hBinByBinCorRaw;
    delete hMCGen;
    uhist[i]->hRecoBinByBin = (TH1F*) uhist[i]->hMeas->Clone(Form("hRecoBinByBin_cent%d",i));
    uhist[i]->hRecoBinByBin->Divide(hBinByBinCor);
		
    // Do unfolding
    //if (isMC) uhist[i]->hMeas = (TH1F*)uhist[i]->hMatrix->ProjectionY()->Clone(Form("hMeas_cent%d",i));
    prior myPrior(uhist[i]->hMatrixFit,uhist[i]->hMeas,0);
  //  myPrior.unfold(uhist[i]->hMeas,1);
    myPrior.unfold(uhist[i]->hMeas,nBayesianIter);
    TH1F *hPrior;//=(TH1F*) functionHist(fPow,uhist[i]->hMeas,Form("hPrior_cent%d",i));
    hPrior = (TH1F*)uhist[i]->hGen->Clone("hPrior");//(TH1F*)uhist[i]->hMeas->Clone(Form("hPrior_cent%d",i));
    removeZero(hPrior);
		
    bayesianUnfold myUnfoldingJECSys(uhist[i]->hMatrixFit,hPrior,0);
    myUnfoldingJECSys.unfold(uhist[i]->hMeasJECSys,nBayesianIter);
    bayesianUnfold myUnfoldingSmearSys(uhist[i]->hMatrixFit,hPrior,0);
    myUnfoldingSmearSys.unfold(uhist[i]->hMeasSmearSys,nBayesianIter);
    bayesianUnfold myUnfolding(uhist[i]->hMatrixFit,myPrior.hPrior,0);
    myUnfolding.unfold(uhist[i]->hMeas,nBayesianIter);
    cout <<"Unfolding bin "<<i<<endl;

    // Iteration Systematics
    for (int j=2;j<=40;j++)
      {
	bayesianUnfold myUnfoldingSys(uhist[i]->hMatrixFit,hPrior,0);
	myUnfoldingSys.unfold(uhist[i]->hMeas,j);
	uhist[i]->hRecoIterSys[j]  = (TH1F*) myUnfoldingSys.hPrior->Clone(Form("hRecoRAA_IterSys%d_cent%d",j,i));
      }
		
		
    uhist[i]->hReco         = (TH1F*) uhist[i]->hRecoIterSys[nBayesianIter]->Clone(Form("Unfolded_cent%i",i));
    uhist[i]->hRecoJECSys   = (TH1F*) myUnfoldingJECSys.hPrior->Clone(Form("UnfoldedJeCSys_cent%i",i));
    uhist[i]->hRecoSmearSys   = (TH1F*) myUnfoldingSmearSys.hPrior->Clone(Form("UnfoldedSmearSys_cent%i",i));
    uhist[i]->hRecoBinByBin->SetName(Form("UnfoldedBinByBin_cent%i",i));
		
    if (doToy) {
      TCanvas *cToy = new TCanvas("cToy","toy",600,600);
      cToy->cd();
      int nExp=1000;
      TH1F *hTmp[nbins_truth+1];
      TH1F *hTmp2[nbins_truth+1];
      for (int j=1;j<=nbins_truth;j++) {
	hTmp[j] = new TH1F(Form("hTmp%d",j),"",200,0,10.+uhist[i]->hReco->GetBinContent(j)*2);
	hTmp2[j] = new TH1F(Form("hTmp2%d",j),"",200,0,10.+uhist[i]->hRecoBinByBin->GetBinContent(j)*2);
      }
      for (int exp =0; exp<nExp; exp++) {
	TH1F *hToy = (TH1F*)uhist[i]->hMeas->Clone();   
	TH2F *hMatrixToy = (TH2F*)uhist[i]->hMatrixFit->Clone();
	hToy->SetName("hToy");
	if (exp%100==0) cout <<"Pseudo-experiment "<<exp<<endl;
	for (int j=1;j<=hToy->GetNbinsX();j++) {
	  double value = gRandom->Poisson(uhist[i]->hMeas->GetBinContent(j));
	  hToy->SetBinContent(j,value);
	}
				
	for (int j=1;j<=hMatrixToy->GetNbinsX();j++) {
	  for (int k=1;k<=hMatrixToy->GetNbinsY();k++) {
	    double value = gRandom->Gaus(uhist[i]->hMatrixFit->GetBinContent(j,k),uhist[i]->hMatrixFit->GetBinError(j,k));
	    hMatrixToy->SetBinContent(j,k,value);
	  }
	}

	prior myPriorToy(hMatrixToy,hToy,0.0);
	myPriorToy.unfold(hToy,1);
	bayesianUnfold myUnfoldingToy(hMatrixToy,myPriorToy.hPrior,0.0);
	myUnfoldingToy.unfold(hToy,nBayesianIter);
	TH1F *hRecoTmp = (TH1F*) myUnfoldingToy.hPrior->Clone();
				
	for (int j=1;j<=hRecoTmp->GetNbinsX();j++) {
	  hTmp[j]->Fill(hRecoTmp->GetBinContent(j));
	}
	delete hToy;
	delete hRecoTmp;
	delete hMatrixToy;
      }
      TF1 *fGaus = new TF1("fGaus","[0]*TMath::Gaus(x,[1],[2])");
      for (int j=1;j<=nbins_truth;j++)
	{
	  f->SetParameters(hTmp[j]->GetMaximum(),hTmp[j]->GetMean(),hTmp[j]->GetRMS());
				
	  if (hTmp[j]->GetMean()>0) {
	    hTmp[j]->Fit(fGaus,"LL Q ");
	    hTmp[j]->Fit(fGaus,"LL Q ");
	    uhist[i]->hReco->SetBinError(j,f->GetParameter(2));
	  }	       
	  f->SetParameters(hTmp2[j]->GetMaximum(),hTmp2[j]->GetMean(),hTmp2[j]->GetRMS());
	  if (hTmp2[j]->GetMean()>0) {
	    hTmp2[j]->Fit(fGaus,"LL Q ");
	    hTmp2[j]->Fit(fGaus,"LL Q ");
	    uhist[i]->hRecoBinByBin->SetBinError(j,f->GetParameter(2));
	  }	       
	  delete hTmp[j];
	  delete hTmp2[j];
	}
      cPbPb->cd(i+1);
    }

    uhist[i]->hMeas->SetMarkerStyle(20);
    uhist[i]->hMeas->SetMarkerColor(1);
    uhist[i]->hReco->SetMarkerStyle(24);
    uhist[i]->hReco->SetMarkerColor(2);
    uhist[i]->hReco->SetLineColor(2);
    uhist[i]->hReco->SetName(Form("hReco_cent%d",i));
    uhist[i]->hReco->Draw("");    
    makeHistTitle(uhist[i]->hReco,"","Jet p_{T} (GeV/c)","dN_{jets} / dp_{T}");
    uhist[i]->hReco->GetYaxis()->SetTitleOffset(1.3);
    uhist[i]->hReco->GetXaxis()->SetTitleOffset(1.2);
    uhist[i]->hGen->SetLineWidth(1);
    uhist[i]->hGen->SetLineColor(1);
    if(isMC)uhist[i]->hGen->Draw("hist same");
    uhist[i]->hReco->Draw("same");    
    uhist[i]->hRecoBinByBin->SetMarkerStyle(28);
    uhist[i]->hRecoBinByBin->SetMarkerColor(4);
    uhist[i]->hRecoBinByBin->SetLineColor(4);
    uhist[i]->hRecoBinByBin->Draw("same");    
    uhist[i]->hReco->SetAxisRange(60,300);
    TH1F *hReproduced = (TH1F*)myUnfolding.hReproduced->Clone(Form("hReproduced_cent%d",i));
    hReproduced->SetMarkerColor(4);
    hReproduced->SetMarkerStyle(24);
    uhist[i]->hMeas->Draw("same");    
		
    TLegend *leg = new TLegend(0.5,0.5,0.9,0.9);
    leg->SetBorderSize(0);
    leg->SetFillStyle(0);
    leg->AddEntry(uhist[i]->hMeas,"Measured","pl");
    leg->AddEntry(uhist[i]->hReco,"Bayesian unfolded","pl");
    leg->AddEntry(uhist[i]->hRecoBinByBin,"Bin-by-bin unfolded","pl");
    if(isMC)leg->AddEntry(uhist[i]->hGen,"Generator level truth","l");
    leg->Draw();
  }	     
  
  cPbPb->Update();

 // ======================= Unfolding closure in MC =========================================================
  TCanvas * cRatio = new TCanvas("cRatio","Ratio",1200,600);
    TH1F * hReco[nbins_cent+1];
    TH1F * hRecoBinByBin[nbins_cent+1];
    TH1F * hMeas[nbins_cent+1];
    TH1F * hGen[nbins_cent+1];
    TLegend *leg[nbins_cent+1];
  TLine *line = new TLine(60,1,250,1);
	line->SetLineStyle(2);
	line->SetLineWidth(2);
 
    for (int i=0;i<=nbins_cent;i++) {
        hReco[i]          = (TH1F*)uhist[i]->hReco->Clone(Form("hReco_Cen%d", i));
        hRecoBinByBin[i]          = (TH1F*)uhist[i]->hRecoBinByBin->Clone(Form("hRecoBinByBin_Cen%d", i));
        hMeas[i]          = (TH1F*)uhist[i]->hMeas->Clone(Form("hMeas_Cen%d", i));
        if(isMC) hGen[i]          = (TH1F*)uhist[i]->hGen->Clone(Form("hGen_Cen%d", i));
    }
    
  if(isMC){
    cRatio->Divide(2,1);
      for (int i=0;i<=nbins_cent;i++) {
          
          hMeas[i]->Divide(hGen[i]);
          hRecoBinByBin[i]->Divide(hGen[i]);
          hReco[i]->Divide(hGen[i]);
          cRatio->cd(i+1);

		//hRecoPP->SetAxisRange(90,300,"X");
		hReco[i]->SetAxisRange(0,2,"Y");
		hReco[i]->SetMarkerStyle(24);
		hReco[i] ->SetLineColor(2);
		hReco[i] ->SetMarkerColor(2);
		hMeas[i]->SetMarkerStyle(20);
		hMeas[i]->SetLineColor(1);
		hMeas[i]->SetMarkerColor(1);
		hRecoBinByBin[i]->SetMarkerStyle(28);
		hRecoBinByBin[i]->SetLineColor(4);
		hRecoBinByBin[i]->SetMarkerColor(4);
		
		makeHistTitle(hReco[i],"","Jet p_{T} (GeV/c)","Reco / Truth");
		hReco[i]->GetYaxis()->SetTitleOffset(1.4);
		hReco[i]->GetXaxis()->SetTitleOffset(1.2);
		hReco[i]->Draw("");
		hRecoBinByBin[i]->Draw("same");
		hMeas[i]->Draw("same");
		line->Draw();
		
		leg[i] = myLegend(0.52,0.65,0.85,0.9);
		leg[i]->AddEntry(hReco[i],"Bayesian","pl");
		leg[i]->AddEntry(hRecoBinByBin[i],"Bin-by-bin","pl");
		leg[i]->AddEntry(hMeas[i],"no unfolding","pl");
		leg[i]->Draw();
		putCMSPrel(0.2,0.83,0.06);
		drawText("Anti-k_{T} Particle Flow Jets   R = 0.3",0.2,0.23,20);
		drawText("CMS Simulation",0.6,0.4,22);
		drawText("| #eta | <2 ",0.6,0.31,22);
      }
  }
  else {
      hMeas[nbins_cent]->Scale(1./CorFac[6]/5.3e9);
      hRecoBinByBin[nbins_cent]->Scale(1./CorFac[6]/5.3e9);
      hReco[nbins_cent]->Scale(1./CorFac[6]/5.3e9);
      cRatio->cd(1);
      
      for (int i=0;i<nbins_cent;i++) {
          hMeas[i]            ->Scale(1./CorFac[i]/1.0908e9/TAA[i]);
          hRecoBinByBin[i]            ->Scale(1./CorFac[i]/1.0908e9/TAA[i]);
          hReco[i]            ->Scale(1./CorFac[i]/1.0908e9/TAA[i]);
          
          hMeas[i]->Divide(hMeas[nbins_cent]);
          hRecoBinByBin[i]->Divide(hRecoBinByBin[nbins_cent]);
          hReco[i]->Divide(hReco[nbins_cent]);
          
          hReco[i]->SetAxisRange(0,2,"Y");
          hReco[i]->SetMarkerStyle(24);
          hReco[i] ->SetLineColor(2);
          hReco[i] ->SetMarkerColor(2);
          hMeas[i]->SetMarkerStyle(20);
          hMeas[i]->SetLineColor(1);
          hMeas[i]->SetMarkerColor(1);
          hRecoBinByBin[i]->SetMarkerStyle(28);
          hRecoBinByBin[i]->SetLineColor(4);
          hRecoBinByBin[i]->SetMarkerColor(4);
         // if(i==0){
          makeHistTitle(hReco[i],"","Jet p_{T} (GeV/c)","Spectra Ratio");
          hReco[i]->GetYaxis()->SetTitleOffset(1.4);
          hReco[i]->GetXaxis()->SetTitleOffset(1.2);
          hReco[i]->Draw("");
              leg[i] = myLegend(0.52,0.65,0.85,0.9);
              leg[i]->AddEntry(hReco[i],"Bayesian","pl");
              leg[i]->AddEntry(hRecoBinByBin[i],"Bin-by-bin","pl");
              leg[i]->AddEntry(hMeas[i],"no unfolding","pl");
              leg[i]->Draw();

       //   }
       //   else {
          hReco[i]->Draw("same");
          hRecoBinByBin[i]->Draw("same");
          hMeas[i]->Draw("same");
      //    }
       } 
         line->Draw();
          
          putCMSPrel(0.2,0.83,0.06);
          drawText(Form("#intL dt = %.f #mub^{-1}",150.),0.2,0.78,22);
          drawText("Anti-k_{T} Particle Flow Jets   R = 0.3",0.2,0.73,20);
          drawText("| #eta | <2 ",0.6,0.69,22);
  
  }
    cRatio->Update();

  pbpb_Unfo->Write();

  SysData systematics;

  // Iteration systematics
  TCanvas *cIterSys = new TCanvas("cIterSys","IterSys",1200,600);
  cIterSys->Divide(2,1);
  cIterSys->cd(2);
  TH1F *hRecoIterSysPP[100];
  TH1F *hRebinPP_tmp         = rebin(uhist[nbins_cent]->hReco, (char*)"hRebinPP_tmp");
  TLegend *legBayesianIterPP = myLegend(0.4,0.7,0.9,0.9);
  legBayesianIterPP->AddEntry("","PP","");
         
  for (int j=2;j<7;j++) {
    hRecoIterSysPP[j] = rebin(uhist[nbins_cent]->hRecoIterSys[j],Form("hRecoIterSysPP_IterSys%d",j));
    hRecoIterSysPP[j]->SetLineColor(colorCode[j-2]);
    hRecoIterSysPP[j]->SetMarkerColor(colorCode[j-2]);
    hRecoIterSysPP[j]->Divide(hRebinPP_tmp);
    if (j==2){
    //  makeHistTitle(hRecoIterSysPP[j],(char*)"",(char*)"Jet p_{T} (GeV/c)",(char*)"Ratio (Unfolded / Nominal)");
      makeHistTitle(hRecoIterSysPP[j],"","Jet p_{T} (GeV/c)","Ratio (Unfolded / Nominal)");
      hRecoIterSysPP[j]->SetTitleOffset(1.3,"Y");
      hRecoIterSysPP[j]->SetTitleOffset(1.2,"X");
      hRecoIterSysPP[j]->SetAxisRange(0,2,"Y");
      hRecoIterSysPP[j]->Draw(); 
    } else {
      hRecoIterSysPP[j]->Draw("same");
    }
         
    checkMaximumSys(systematics.hSysIter[nbins_cent],hRecoIterSysPP[j],0,1.1);
    legBayesianIterPP->AddEntry(hRecoIterSysPP[j],Form("Iteration %d",j),"pl");     
  }
      
  legBayesianIterPP->Draw();
  line->Draw();
  drawEnvelope(systematics.hSysIter[nbins_cent],(char*)"hist same");


  cIterSys->cd(1);
  TH1F *hRecoIterSysPbPb[100];
  TH1F *hRebinPbPb_tmp         = rebin(uhist[0]->hReco, (char*)"hRebinPbPb_tmp");
  TLegend *legBayesianIterPbPb = myLegend(0.4,0.7,0.9,0.9);
  legBayesianIterPbPb->AddEntry("","PbPb","");
  for (int j=2;j<7;j++) {
    hRecoIterSysPbPb[j] = rebin(uhist[0]->hRecoIterSys[j],Form("hRecoIterSysPbPb_IterSys%d",j));
    hRecoIterSysPbPb[j]->SetLineColor(colorCode[j-2]);
    hRecoIterSysPbPb[j]->SetMarkerColor(colorCode[j-2]);
    hRecoIterSysPbPb[j]->Divide(hRebinPbPb_tmp);
    if (j==2){
    //  makeHistTitle(hRecoIterSysPbPb[j],(char*)"",(char*)"Jet p_{T} (GeV/c)",(char*)"Ratio (Unfolded / Nominal)");
      makeHistTitle(hRecoIterSysPbPb[j],"","Jet p_{T} (GeV/c)","Ratio (Unfolded / Nominal)");
      hRecoIterSysPbPb[j]->SetTitleOffset(1.3,"Y");
      hRecoIterSysPbPb[j]->SetTitleOffset(1.2,"X");
      hRecoIterSysPbPb[j]->SetAxisRange(0,2,"Y");
      hRecoIterSysPbPb[j]->Draw(); 
    } else {
      hRecoIterSysPbPb[j]->Draw("same");
    }
         
    checkMaximumSys(systematics.hSysIter[0],hRecoIterSysPbPb[j],0,1.1);
    legBayesianIterPbPb->AddEntry(hRecoIterSysPbPb[j],Form("Iteration %d",j),"pl");     
  }
  legBayesianIterPbPb->Draw();
  line->Draw();
  drawEnvelope(systematics.hSysIter[0],(char*)"hist same");
  
  cIterSys->Update();
  
  TString data ;
  if(isMC) data="MC";
  else data="Data";
 TString anaType ;
  if(doBjets) anaType="Bjet";
  else anaType="Inclusive";
  
  if(SavePlot){
    cMatrix->SaveAs(Form("plots/%s%s%sResponseMatrix.gif", data.Data(), anaType.Data(), algoName[algo]));
    cPbPb->SaveAs(Form("plots/%s%s%sJetSpectra.gif",  data.Data(), anaType.Data(), algoName[algo]));
    cRatio->SaveAs(Form("plots/%s%s%sJetRatio.gif",  data.Data(), anaType.Data(), algoName[algo]));
    cIterSys->SaveAs(Form("plots/%s%s%sIterationSys.gif",  data.Data(), anaType.Data(), algoName[algo]));
}
}
Пример #9
0
void Draw(const char* pairName, const char* canvasName, std::vector<CorrelationFunction> &plots, bool isIdentical)
{
	unsigned int i, k;
	int canvasNumber1 = -1, canvasNumber2 = 0;
	TLegend *hHKMlegend, *EPOSlegend;
	TCanvas *canv = new TCanvas(canvasName, canvasName, 1300, 2000);
	if(isIdentical)
		canv->Divide(2,4);
	else
		canv->Divide(2,5);

	// 
	// hHKM
	//
	hHKMlegend = new TLegend(legendX1, legendY1, legendX2, legendY2);

	k = 0;
	canv->cd(++++canvasNumber1);
	for(i = 0 ; i < plots.size(); ++i)
		if(plots[i].model.compare("hHKM") == 0)
		{
			DrawSinglePlot(plots[i].cf1D, (std::string(pairName) + std::string(" - hHKM - 1D;q_{inv} (GeV/c);C(q_{inv})")).c_str(), k);
			SetRanges(plots[i].cf1D, canvasName, "1D");
			hHKMlegend->AddEntry(plots[i].cf1D, plots[i].centrality.c_str(),"P");
		}
	if(plots.size() > 0)
	{
		hHKMlegend->Draw();
		hHKMlegend->SetFillColor(0);
	}
			
	k = 0;
	canv->cd(++++canvasNumber1);
	for(i = 0 ; i < plots.size(); ++i)
		if(plots[i].model.compare("hHKM") == 0)
		{
			DrawSinglePlot(plots[i].cfSH00, (std::string(pairName) + std::string(" - hHKM - Spherical Harmonics;k* (GeV/c);#RgothicC^{0}_{0}")).c_str(), k);
			SetRanges(plots[i].cfSH00, canvasName, "SH00");
		}

	if(!isIdentical)
	{
		k = 0;
		canv->cd(++++canvasNumber1);
		for(i = 0 ; i < plots.size(); ++i)
			if(plots[i].model.compare("hHKM") == 0)
			{
				DrawSinglePlot(plots[i].cfSH11, (std::string(pairName) + std::string(" - hHKM - Spherical Harmonics;k* (GeV/c);#RgothicC^{1}_{1}")).c_str(), k);
				SetRanges(plots[i].cfSH11, canvasName, "SH11");
			}
	}

	k = 0;
	canv->cd(++++canvasNumber1);
	for(i = 0 ; i < plots.size(); ++i)
		if(plots[i].model.compare("hHKM") == 0)
		{
			DrawSinglePlot(plots[i].cfSH20, (std::string(pairName) + std::string(" - hHKM - Spherical Harmonics;k* (GeV/c);#RgothicC^{0}_{2}")).c_str(), k);
			SetRanges(plots[i].cfSH20, canvasName, "SH20");
		}

	k = 0;
	canv->cd(++++canvasNumber1);
	for(i = 0 ; i < plots.size(); ++i)
		if(plots[i].model.compare("hHKM") == 0)
		{
			DrawSinglePlot(plots[i].cfSH22, (std::string(pairName) + std::string(" - hHKM - Spherical Harmonics;k* (GeV/c);#RgothicC^{2}_{2}")).c_str(), k);
			SetRanges(plots[i].cfSH22, canvasName, "SH22");
		}

	//
	// EPOS
	//
	EPOSlegend = new TLegend(legendX1, legendY1, legendX2, legendY2);

	k = 0;
	canv->cd(++++canvasNumber2);
	for(i = 0 ; i < plots.size(); ++i)
		if(plots[i].model.compare("EPOS") == 0)
		{
			DrawSinglePlot(plots[i].cf1D, (std::string(pairName) + std::string(" - EPOS - 1D;q_{inv} (GeV/c);C(q_{inv})")).c_str(), k);
			SetRanges(plots[i].cf1D, canvasName, "1D");
			EPOSlegend->AddEntry(plots[i].cf1D, plots[i].centrality.c_str(),"P");
		}
	if(plots.size() > 0)
	{
		EPOSlegend->Draw();
		EPOSlegend->SetFillColor(0);
	}
		
	k = 0;
	canv->cd(++++canvasNumber2);
	for(i = 0 ; i < plots.size(); ++i)
		if(plots[i].model.compare("EPOS") == 0)
		{
			DrawSinglePlot(plots[i].cfSH00, (std::string(pairName) + std::string(" - EPOS - Spherical Harmonics;k* (GeV/c);#RgothicC^{0}_{0}")).c_str(), k);
			SetRanges(plots[i].cfSH00, canvasName, "SH00");
		}

	if(!isIdentical)
	{
		k = 0;
		canv->cd(++++canvasNumber2);
		for(i = 0 ; i < plots.size(); ++i)
			if(plots[i].model.compare("EPOS") == 0)
			{
				DrawSinglePlot(plots[i].cfSH11, (std::string(pairName) + std::string(" - EPOS - Spherical Harmonics;k* (GeV/c);#RgothicC^{1}_{1}")).c_str(), k);
				SetRanges(plots[i].cfSH11, canvasName, "SH11");
			}
	}

	k = 0;
	canv->cd(++++canvasNumber2);
	for(i = 0 ; i < plots.size(); ++i)
		if(plots[i].model.compare("EPOS") == 0)
		{
			DrawSinglePlot(plots[i].cfSH20, (std::string(pairName) + std::string(" - EPOS - Spherical Harmonics;k* (GeV/c);#RgothicC^{0}_{2}")).c_str(), k);
			SetRanges(plots[i].cfSH20, canvasName, "SH20");
		}

	k = 0;
	canv->cd(++++canvasNumber2);
	for(i = 0 ; i < plots.size(); ++i)
		if(plots[i].model.compare("EPOS") == 0)
		{
			DrawSinglePlot(plots[i].cfSH22, (std::string(pairName) + std::string(" - EPOS - Spherical Harmonics;k* (GeV/c);#RgothicC^{2}_{2}")).c_str(), k);
			SetRanges(plots[i].cfSH22, canvasName, "SH22");
		}

	canv->SaveAs((std::string(canvasName)+std::string(".eps")).c_str());
	canv->SaveAs((std::string(canvasName)+std::string(".png")).c_str());
	canv->SaveAs((std::string(canvasName)+std::string(".root")).c_str());
}
Пример #10
0
void residualAlignment(TH2D* residualX, TH2D* residualY, double& offsetX,
                       double& offsetY, double& rotation,
                       double relaxation, bool display)
{
  assert(residualX && residualY && "Processors: can't perform residual alignment without histograms");

  rotation = 0;
  offsetX = 0;
  offsetY = 0;
  double angleWeights = 0;
  double fitChi2 = 0;

  for (int axis = 0; axis < 2; axis++)
  {
    TH2D* hist = 0;
    if (axis) hist = residualX;
    else      hist = residualY;

    // Project the histogram and fit with a gaussian to center the sensor
    TH1D* project = hist->ProjectionX("ResidualProjetion", 1, hist->GetNbinsY());
    project->SetDirectory(0);

    double sigma = project->GetBinWidth(1);
    double mean = 0;
    fitGaussian(project, mean, sigma, false);

    if (axis) offsetX = mean;
    else      offsetY = mean;

    delete project;

    std::vector<double> ptsX;
    std::vector<double> ptsY;
    std::vector<double> ptsErr;

    const unsigned int numSlices = hist->GetNbinsY();

    for (Int_t row = 1; row <= (int)numSlices; row++)
    {
      TH1D* slice = hist->ProjectionX("ResidualSlice", row, row);
      slice->SetDirectory(0);

      double mean = 0;
      double sigma = 0;
      double factor = 0;
      double background = 0;

      if (slice->Integral() < 1) { delete slice; continue; }
      fitGaussian(slice, mean, sigma, factor, background, false);

      const double sliceMin = slice->GetBinCenter(1);
      const double sliceMax = slice->GetBinCenter(slice->GetNbinsX());
      delete slice;

      // Quality assurance

      // Sigma is contained in the slice's range
      if (sigma > (sliceMax - sliceMin)) continue;
      // Mean is contained in the slice's range
      if (mean > sliceMax || mean < sliceMin) continue;
      // Peak is contains sufficient events
      if (factor < 100) continue;
      // Sufficient signal to noise ratio
      if (factor / background < 10) continue;

      // Get the total number of events in the gaussian 1 sigma
      Int_t sigRangeLow = hist->FindBin(mean - sigma);
      Int_t sigRangeHigh = hist->FindBin(mean + sigma);

      double sigRangeTotal = 0;
      for (Int_t bin = sigRangeLow; bin <= sigRangeHigh; bin++)
        sigRangeTotal += hist->GetBinContent(bin);

      // 2 * 1 sigma integral shoudl give ~ area under gaussian
      sigma /= sqrt(2 * sigRangeTotal);

      ptsX.push_back(hist->GetYaxis()->GetBinCenter(row));
      ptsY.push_back(mean);
      ptsErr.push_back(sigma);
    }

    if (ptsX.size() < 3) continue;

    std::vector<double> yvals = ptsY;
    std::sort(yvals.begin(), yvals.end());
    const double median = yvals[yvals.size()/2];
    double avgDeviation = 0;
    for (unsigned int i = 0; i < yvals.size(); i++)
      avgDeviation += fabs(yvals[i] - median);
    avgDeviation /= (double)yvals.size();

    std::vector<double> ptsXGood;
    std::vector<double> ptsYGood;
    std::vector<double> ptsErrGood;

    for (unsigned int i = 0; i < ptsX.size(); i++)
    {
      if (fabs(ptsY[i] - median) > 1.5*avgDeviation) continue;
      ptsXGood.push_back(ptsX[i]);
      ptsYGood.push_back(ptsY[i]);
      ptsErrGood.push_back(ptsErr[i]);
    }

    if (ptsXGood.size() < 3) continue;

    TGraphErrors* graph = new TGraphErrors(ptsXGood.size(),
                                           &(ptsXGood.at(0)),
                                           &(ptsYGood.at(0)), 0,
                                           &(ptsErrGood.at(0)));

    TF1* fitFunc = new TF1("f1", "1 ++ x");
    TF1* result = 0;

    graph->Fit(fitFunc, "Q0E").Get();
    result = graph->GetFunction(fitFunc->GetName());

    // Weight the angle by the slope uncertainty and the inverse of the chi2 normalized
    double weight = result->GetParError(1);
    const double chi2 = result->GetChisquare() / (double)result->GetNDF();
    fitChi2 += chi2;
    weight *= chi2;
    if (weight > 10 * DBL_MIN) weight = 1.0 / weight;
    else weight = 1.0;

    if (axis)
    {
      rotation -= weight * atan(result->GetParameter(1));
      offsetX = result->GetParameter(0);
    }
    else
    {
      rotation += weight * atan(result->GetParameter(1));
      offsetY = result->GetParameter(0);
    }

    angleWeights += weight;

    if (display)
    {
      TCanvas* can = new TCanvas("ResidualAlignment", "Residual Alignment", 900, 600);
      can->Divide(2);
      can->cd(1);
      hist->Draw("COLZ");
      can->cd(2);
      result->SetLineColor(46);
      result->SetLineWidth(2);
      graph->Draw("ap");
      result->Draw("SAME");
      can->Update();
      can->WaitPrimitive();
    }

    delete fitFunc;
    delete graph;
  }

  if (angleWeights > 10 * DBL_MIN)
    rotation /= angleWeights;
  std::cout << "relaxation: " << relaxation << std::endl;
  rotation *= relaxation;
  offsetX *= relaxation;
  offsetY *= relaxation;
}
//=============================================================================
// Standard constructor, initializes variables
//=============================================================================
void makeLongTracksonly2(  ) {
  gROOT->SetBatch(kTRUE);
  TString tuplelocation = "/afs/cern.ch/work/m/mwilkins/b_b-bar_cross-section/";
  TString data2011tuple = tuplelocation+"Strp20r1_SL_D0andDp_MD.root";
  TString MC2011tuple = tuplelocation+"MC_2011_Bu_D0Xmunu_cocktail_12873441_MC2011_S20r1_noPID_Tuples.root";
  TString data2015tuple = tuplelocation+"B2DMuNuX_tuples_05082015.root";
  TString MC2015tuple = tuplelocation+"MC_2015_Bu_D0Xmunu_cocktail_12873441_MC2015_S22_noPID_Tuples.root";
  TFile *f[4];
  f[0] = TFile::Open(data2011tuple);
  f[1] = TFile::Open(MC2011tuple);
  f[2] = TFile::Open(data2015tuple);
  f[3] = TFile::Open(MC2015tuple);
  cout<<"files opened"<<endl;
  
  const int nhpc = 2; //number of histograms per canvas
  const int ncanvases = 4;
  const int nstacks = ncanvases;
  THStack *hs[nstacks];
  TCanvas *c[ncanvases];
  TH1F *h[ncanvases][nhpc];
  TLegend *leg[ncanvases];
  TString outputlocation = "output/longtracksplots2/";//where the output will be saved
  TString plotfilename = "longtracksplots2.pdf";//name of file that will hold drawn plots

  TCanvas *cf = new TCanvas("cf","combined");//canvas to hold everything
  float sqnc = sqrt(ncanvases), sqncu = ceil(sqnc), sqncd = floor(sqnc);
  while(sqncu*sqncd<ncanvases) sqncu++;
  cf->Divide(sqncu,sqncd);
  TLegend *legf = new TLegend(0.84, 0.84, .99, .95);

  TString placeholder; //to avoid adding strings within functions; assign immediately before use
  TString placeholder2;
  
  cout<<"starting canvas loop..."<<endl;
  for(int ci =0; ci<ncanvases; ci++){ //loop over canvases
    //create indicators and strings:
    int year;
    if(ci<(ncanvases/2)){//2011 for 1st half canvases, 2015 for 2nd half
      year = 2011;
    }else year = 2015;
    TString yearstring = Form("%d",year);
    TString filetype;
    if(ci%2==0){//true every other canvas
      filetype = "data";
    }else filetype = "MC";
    int file_num=-1000;//assign file_num based on combinations of data and MC
    if(year==2011){
      if(filetype=="data") file_num=0;
      if(filetype=="MC") file_num=1;
    }
    if(year==2015){
      if(filetype=="data") file_num=2;
      if(filetype=="MC") file_num=3;
    }
    int B0;//these will be assigned within the histogram loop
    TString Bdecay;
    TString branch;
    TString  tracktype = "nLongTracks";
    TString cistring = Form("%d",ci);
    cout<<"loop "<<ci<<" indicators and strings created:"<<endl<<"year: "<<year<<endl;
    cout<<"file: "<<file_num<<endl;

    //create the plots
    placeholder = "c"+cistring;
    placeholder2=yearstring+filetype+tracktype;
    c[ci] = new TCanvas(placeholder,placeholder2,1200,800); //create the canvases
    c[ci]->cd();
    gStyle->SetOptStat("");
    leg[ci] = new TLegend(0.7, 0.7, .97, .93);//create legend
    placeholder = "hs"+cistring;
    hs[ci] = new THStack(placeholder,placeholder2); //create the stack to hold the histograms
    cout<<"starting histogram loop..."<<endl;
    for(int hi=0;hi<nhpc;hi++){ //loop over histograms in a canvas; B0=0 and B0=1
      if((int)floor(hi)%2 ==0){//every other histogram
        B0=0;
        Bdecay = "B^{-}->(D^{0}->K^{-} #pi^{+})#mu^{-}";
        if((filetype=="data")&&(year==2011)){
          branch="tupleb2D0Mu/tupleb2D0Mu";
        }else branch="Tuple_b2D0MuX/DecayTree";
      } else{
        B0=1;
        Bdecay = "B^{0}->(D^{-}->K^{+} #pi^{-} #pi^{-})#mu^{+}";
        if((filetype=="data")&&(year==2011)){
          branch="tupleb2DpMu/tupleb2DpMu";
        }else branch="Tuple_b2DpMuX/DecayTree";
      }
      //create convenient strings
      TString histring = Form("%d",hi);
      TString hname = "h"+cistring+histring;
      
      //create histograms
      if(tracktype=="nTracks") h[ci][hi] = new TH1F(hname,tracktype,104,0,1144);
      if(tracktype=="nLongTracks") h[ci][hi] = new TH1F(hname,tracktype,131,0,262);
      cout<<"histogram loop "<<hi<<" strings and histograms created"<<endl;

      //navigate files
      cout<<"navigating file..."<<endl;
      TTree *MyTree;
      f[file_num]->GetObject(branch,MyTree);
      //draw histograms
      cout<<"drawing histogram "<<hi<<"..."<<endl;
      h[ci][hi]->SetLineColor(hi+1);
      placeholder = tracktype+">>"+hname;
      MyTree->Draw(placeholder,"","norm");
      cout<<"stacking histogram "<<hi<<"..."<<endl;
      hs[ci]->Add(h[ci][hi]);//stack histograms
      leg[ci]->AddEntry(h[ci][hi],Bdecay,"l");//fill legend
      if(ci==0) legf->AddEntry(h[ci][hi],Bdecay,"l");//fill combined legend; all the same, so using the first one is fine
    }
    //draw stacked histograms
    cout<<"drawing stack "<<ci<<"..."<<endl;
    placeholder = yearstring+": "+filetype+": "+tracktype;
    hs[ci]->SetTitle(placeholder);
    hs[ci]->Draw("nostack");
    leg[ci]->Draw();
    cf->cd(ci+1);
    hs[ci]->Draw("nostack");//not using c[ci]->DrawClonePad(); because too many legends
    //save stuff:
    cout<<"saving files..."<<endl;
    placeholder = outputlocation+plotfilename+"(";//the closing page is added after the loop
    c[ci]->Print(placeholder);
    placeholder = outputlocation+"c"+cistring+".C";
    c[ci]->SaveAs(placeholder);
    cout<<endl;
  }
  cf->cd();
  legf->Draw();
  placeholder = outputlocation+plotfilename+")";
  cf->Print(placeholder);
  gROOT->SetBatch(kFALSE);
  cout<<"done"<<endl;
}
Пример #12
0
void higgsAna::Plot(string histoName)
{
	string temp1 = "hee_" + histoName;
	string temp2 = "hmumu_" + histoName;
	string temp3 = histoName;
	char *eeName, *mumuName, *Name;
	eeName = new char [temp1.size()+1];
	mumuName = new char [temp2.size()+1];
	Name = new char [temp3.size()];
	strcpy (eeName, temp1.c_str());
	strcpy (mumuName, temp2.c_str());
	strcpy (Name, temp3.c_str());
	

	
	isData = 1;
	leptonType = 11;
	SetFiles();
	TFile *eeDataFile = new TFile(outputFileName, "READ");
	TH1F *hee_data = (TH1F*) eeDataFile->Get(eeName);
	hee_data->SetMarkerStyle(20);
	hee_data->SetMarkerColor(1);
	hee_data->SetLineColor(1);
	hee_data->SetMarkerSize(1);
	
	leptonType = 13;
	SetFiles();
	TFile *mumuDataFile = new TFile(outputFileName, "READ");
	TH1F *hmumu_data = (TH1F*) mumuDataFile->Get(mumuName);
	hmumu_data->SetMarkerStyle(20);
	hmumu_data->SetMarkerColor(1);
	hmumu_data->SetLineColor(1);
	hmumu_data->SetMarkerSize(1);

	TCanvas *can = new TCanvas(Name, Name, 0, 0, 840, 800);
	can->Divide(2,2);
	
	can->cd(1);
	hee_data->DrawCopy("e");
	can->cd(3);
	hmumu_data->DrawCopy("e");
	can->cd(2);
	can->cd(2)->SetLogy();
	hee_data->SetMinimum(0.0009);
	hee_data->DrawCopy("e");
	can->cd(4);
	can->cd(4)->SetLogy();
	hmumu_data->SetMinimum(0.0009);
	hmumu_data->DrawCopy("e");
	

	TFile *MCFile[20];
	TH1F *hee_MC[20];
	TH1F *hmumu_MC[20];

	isData = 0;
	
	cout << endl << "SCALING" << endl;
	for (int i = 0; i < 20; i++){
		SetFiles(i+11);
		MCFile[i] = new TFile(outputFileName, "READ");
		hee_MC[i] = (TH1F*) MCFile[i]->Get(eeName);
		hee_MC[i]->Scale(eeScaling[i]);	
		hmumu_MC[i] = (TH1F*) MCFile[i]->Get(mumuName);
		hmumu_MC[i]->Scale(mumuScaling[i]);
		
		
		//cout <<" ee:  " << eeScaling[i] << "   mumu: " << mumuScaling[i] << endl;
		
	
	}

	// add histograms

	Color_t colors[20] = {kGreen-10,0,0,0,0,0,0,0,0, kRed+2, kGreen-6, kGreen+1,0,0,0,0,0, kAzure-6, kBlue-6, kBlue-10}; 	
	//Int_t colors[20] = {30,0,0,0,0,0,0,0,0, 50, 72, 8,0,0,0,0,0, 54, 51, 38}; 
	//Int_t colors[8] = {50, 66, 91, 0, 0, 59, 51, 8}; 

	// DY + WJets + Top + WW + WZ + ZZ
	// WJets + Top + WW + WZ + ZZ
	// Top + WW + WZ + ZZ
	// WW + WZ + ZZ
	// WZ + ZZ
	// ZZ
	for (int j = 0; j < 20; j++){
		if ( (j >=1 && j<=8) || (j >= 12 && j <= 16) ) continue;
		for (int i = j+1; i < 20; i++){
			hee_MC[j]->Add(hee_MC[i]);
			hmumu_MC[j]->Add(hmumu_MC[i]);
		}
		can->cd(1);
		hee_MC[j]->SetFillColor(colors[j]);
		hee_MC[j]->DrawCopy("same");
		can->cd(2);
		hee_MC[j]->SetMinimum(0.0009);
		hee_MC[j]->DrawCopy("same");
		can->cd(3);
		hmumu_MC[j]->SetFillColor(colors[j]);
		hmumu_MC[j]->DrawCopy("same");
		can->cd(4);
		hmumu_MC[j]->SetMinimum(0.0009);
		hmumu_MC[j]->DrawCopy("same");

		//cout << " ee    " << hee_MC[j]->GetName() << " " << hee_MC[j]->Integral();
		//cout << "    mumu  " << hmumu_MC[j]->GetName() << " " << hmumu_MC[j]->Integral() << endl;
	}
	for (int j = 0; j < 19; j++){
		if ( (j >=1 && j<=8) || (j >= 12 && j <= 16) ) continue;
		cout << " ee  " << hee_MC[j]->Integral() - hee_MC[j+1]->Integral();
		cout << "   mumu  " << hmumu_MC[j]->Integral() - hmumu_MC[j+1]->Integral() << endl;
	}
		cout << " ee  " << hee_MC[19]->Integral() ;
		cout << "   mumu  " << hmumu_MC[19]->Integral() << endl;
	
	
	// electrons
	can->cd(1);
	hee_data->DrawCopy("esame");
	can->cd(1)->RedrawAxis();
	
	can->cd(2);
	//for (int i = 1; i< 20; i++) {
	//	hee_MC[0]->Add(hee_MC[i]);
	//}
	//hee_MC[0]->SetMinimum(0.09);
	//hee_MC[0]->DrawCopy("same");
	hee_data->SetMinimum(0.0009);
	hee_data->DrawCopy("esame");
	can->cd(2)->RedrawAxis();
	
	// muons
	can->cd(3);
	hmumu_data->DrawCopy("esame");
	can->cd(3)->RedrawAxis();
	
	can->cd(4);
	hmumu_data->SetMinimum(0.0009);
	hmumu_data->DrawCopy("esame");
	can->cd(4)->RedrawAxis();


	can->cd(2);
	TLegend *leg = new TLegend(0.5, 0.55, 0.75, 0.8);
	leg->SetBorderSize(0);
	leg->SetFillStyle(0);
	TLegendEntry *entry=leg->AddEntry(hee_MC[0], "Z+Jets","f");
	entry->SetFillStyle(1001);
	entry->SetFillColor(kGreen-10);
	entry=leg->AddEntry(hee_MC[9], "W+Jets","f");
	entry->SetFillStyle(1001);
	entry->SetFillColor(kRed+2);
	entry=leg->AddEntry(hee_MC[10], "TTJets","f");
	entry->SetFillStyle(1001);
	entry->SetFillColor(kGreen-6);
	entry=leg->AddEntry(hee_MC[11], "Top","f");
	entry->SetFillStyle(1001);
	entry->SetFillColor(kGreen+1);
	entry=leg->AddEntry(hee_MC[17], "WZ","f");
	entry->SetFillStyle(1001);
	entry->SetFillColor(kAzure-6);
	entry=leg->AddEntry(hee_MC[18], "WW","f");
	entry->SetFillStyle(1001);
	entry->SetFillColor(kBlue-6);
	entry=leg->AddEntry(hee_MC[19], "ZZ","f");
	entry->SetFillStyle(1001);
	entry->SetFillColor(kBlue-10);
	entry=leg->AddEntry(hee_data, "data ee", "ple");
	entry->SetMarkerStyle(20);
	leg->Draw();

	can->cd(4);
	TLegend *leg2 = new TLegend(0.5, 0.55, 0.75, 0.8);
	leg2->SetBorderSize(0);
	leg2->SetFillStyle(0);
	entry=leg2->AddEntry(hee_MC[0], "Z+Jets","f");
	entry->SetFillStyle(1001);
	entry->SetFillColor(kGreen-10);
	entry=leg2->AddEntry(hee_MC[9], "W+Jets","f");
	entry->SetFillStyle(1001);
	entry->SetFillColor(kRed+2);
	entry=leg2->AddEntry(hee_MC[10], "TTJets","f");
	entry->SetFillStyle(1001);
	entry->SetFillColor(kGreen-6);
	entry=leg2->AddEntry(hee_MC[11], "Top","f");
	entry->SetFillStyle(1001);
	entry->SetFillColor(kGreen+1);
	entry=leg2->AddEntry(hee_MC[17], "WZ","f");
	entry->SetFillStyle(1001);
	entry->SetFillColor(kAzure-6);
	entry=leg2->AddEntry(hee_MC[18], "WW","f");
	entry->SetFillStyle(1001);
	entry->SetFillColor(kBlue-6);
	entry=leg2->AddEntry(hee_MC[19], "ZZ","f");
	entry->SetFillStyle(1001);
	entry->SetFillColor(kBlue-10);

	entry=leg2->AddEntry(hee_data, "data #mu #mu", "ple");
	entry->SetMarkerStyle(20);
	leg2->Draw();


	cout << hee_MC[0]->Integral() << endl;
	cout << hee_data->GetSumOfWeights() << endl << endl;
	cout << hmumu_MC[0]->Integral() << endl;
	cout << hmumu_data->GetSumOfWeights() << endl;

	
	for (int i = 0; i < 20; i++){
		MCFile[i]->Close();
	}
	eeDataFile->Close();
	mumuDataFile->Close();


}
Пример #13
0
void fitM3()
{

	// LOAD HISTOGRAMS FROM FILES
	/////////////////////////////////
	TH1F *hTTjets;
	TH1F *hWjets;
	TH1F *hM3;
	TH1F *hZjets;
	TH1F *hQCD;
	TH1F *hST_s;
	TH1F *hST_t;
	TH1F *hST_tW;

	// histograms from nonimal sample
	///////////
	
	TFile *infile0 = TFile::Open("nominal_IPsig3_Iso95/TopAnalysis_TTJets-madgraph_Fall08_all_all.root");
	//TFile *infile0 = TFile::Open("nominal_IPsig3_Iso95/TopAnalysis_TauolaTTbar.root");
	hTTjets = (TH1F*) gDirectory->Get("Mass/HadronicTop_mass_cut1");
	
	TFile *infile1 = TFile::Open("nominal_IPsig3_Iso95/TopAnalysis_WJets_madgraph_Fall08_all.root");
	hWjets = (TH1F*) gDirectory->Get("Mass/HadronicTop_mass_cut1");
	
	TFile *infile1Fast = TFile::Open("nominal_IPsig3_Iso95_Fast/TopAnalysis_Wjets_madgraph_Winter09_v2_all.root");
	hWjetsFast = (TH1F*) gDirectory->Get("Mass/HadronicTop_mass_cut1");

	TFile *infileZ = TFile::Open("nominal_IPsig3_Iso95/TopAnalysis_ZJets_madgraph_Fall08_all.root");
	hZjets = (TH1F*) gDirectory->Get("Mass/HadronicTop_mass_cut1");
	TFile *infileZFast = TFile::Open("nominal_IPsig3_Iso95_Fast/TopAnalysis_Zjets_madgraph_Winter09_v2_all.root");
	hZjetsFast = (TH1F*) gDirectory->Get("Mass/HadronicTop_mass_cut1");

	TFile *infileST_s = TFile::Open("nominal_IPsig3_Iso95/TopAnalysis_ST_s.root");
	hST_s = (TH1F*) gDirectory->Get("Mass/HadronicTop_mass_cut1");

	TFile *infileST_t = TFile::Open("nominal_IPsig3_Iso95/TopAnalysis_ST_t.root");
	hST_t = (TH1F*) gDirectory->Get("Mass/HadronicTop_mass_cut1");

	TFile *infileST_tW = TFile::Open("nominal_IPsig3_Iso95/TopAnalysis_ST_tW.root");
	hST_tW = (TH1F*) gDirectory->Get("Mass/HadronicTop_mass_cut1");

	TFile *infileQCD = TFile::Open("nominal_IPsig3_Iso95/TopAnalysis_InclusiveMuPt15_Summer08_all.root");
	hQCD = (TH1F*) gDirectory->Get("Mass/HadronicTop_mass_cut1");

	// histograms from systematic samples
	//////////
	TFile *infile0S = TFile::Open("nominal_JESUp/TopAnalysis_TTJets-madgraph_Fall08_all_all.root");
	hTTjetsS = (TH1F*) gDirectory->Get("Mass/HadronicTop_mass_cut1");
		
	TFile *infile1S = TFile::Open("nominal_JESUp/TopAnalysis_WJets_madgraph_Fall08_all.root");// from FullSim
	hWjetsS = (TH1F*) gDirectory->Get("Mass/HadronicTop_mass_cut1");

	//TFile *infile1SF = TFile::Open("nominal_JESUp_Fast/TopAnalysis_WJets_madgraph_Fall08_all.root");// from FastSim
	//TFile *infile1SF = TFile::Open("nominal_IPsig3_Iso95_Fast/TopAnalysis_Wjets_ScaleUp_madgraph_Winter09_all.root");
	TFile *infile1SF = TFile::Open("nominal_IPsig3_Iso95_Fast/TopAnalysis_WJets_Threshold20GeV_madgraph_Winter09_all.root");
	hWjetsSFast = (TH1F*) gDirectory->Get("Mass/HadronicTop_mass_cut1");

	TFile *infileZS = TFile::Open("nominal_JESUp/TopAnalysis_ZJets_madgraph_Fall08_all.root");// from FullSim
	hZjetsS = (TH1F*) gDirectory->Get("Mass/HadronicTop_mass_cut1");

	TFile *infileZSF = TFile::Open("nominal_JESUp_Fast/TopAnalysis_ZJets_madgraph_Fall08_all.root");// from FullSim
	hZjetsSFast = (TH1F*) gDirectory->Get("Mass/HadronicTop_mass_cut1");

	TFile *infileST_sS = TFile::Open("nominal_JESUp/TopAnalysis_ST_s.root");
	hST_sS = (TH1F*) gDirectory->Get("Mass/HadronicTop_mass_cut1");

	TFile *infileST_tS = TFile::Open("nominal_JESUp/TopAnalysis_ST_t.root");
	hST_tS = (TH1F*) gDirectory->Get("Mass/HadronicTop_mass_cut1");

	TFile *infileST_tWS = TFile::Open("nominal_JESUp/TopAnalysis_ST_tW.root");
	hST_tWS = (TH1F*) gDirectory->Get("Mass/HadronicTop_mass_cut1");

	TFile *infileQCDS = TFile::Open("nominal_JESUp/TopAnalysis_InclusiveMuPt15_Summer08_all.root");//
	hQCDS = (TH1F*) gDirectory->Get("Mass/HadronicTop_mass_cut1");
	
	//TFile *infileQCD_CS = TFile::Open("nominal_antiMuon/TopAnalysis_InclusiveMuPt15_Summer08_all.root");
	//hQCD_CS = (TH1F*) gDirectory->Get("Mass/HadronicTop_mass_cut1");

	// write templates to file
	//TFile *outfile = TFile::Open("templates.root","RECREATE");
	//hTTjets->Write("ttbar");
	//hWjets->Write("Wjets");
	//outfile->Close();

	// Add over/underflow bins if requested
	bool UseOverflow = true;
	bool UseUnderflow = true;
	
	if (UseOverflow) {
		int maxbin=hTTjets->GetNbinsX();
	
		hTTjets->SetBinContent(maxbin,    hTTjets->GetBinContent(maxbin+1)+hTTjets->GetBinContent(maxbin) );
		hWjets->SetBinContent(maxbin,     hWjets->GetBinContent(maxbin+1)+hWjets->GetBinContent(maxbin) );
		hWjetsFast->SetBinContent(maxbin, hWjetsFast->GetBinContent(maxbin+1)+hWjetsFast->GetBinContent(maxbin) );
		hZjets->SetBinContent(maxbin,     hZjets->GetBinContent(maxbin+1)+hZjets->GetBinContent(maxbin) );
		hZjetsFast->SetBinContent(maxbin, hZjetsFast->GetBinContent(maxbin+1)+hZjetsFast->GetBinContent(maxbin) );
		hQCD->SetBinContent(maxbin,       hQCD->GetBinContent(maxbin+1)+hQCD->GetBinContent(maxbin) );
		//hQCD_CS->SetBinContent(maxbin, hQCD_CS->GetBinContent(maxbin+1)+hQCD_CS->GetBinContent(maxbin) );
		hST_s->SetBinContent(maxbin,      hST_s->GetBinContent(maxbin+1)+hST_s->GetBinContent(maxbin) );
		hST_t->SetBinContent(maxbin,      hST_t->GetBinContent(maxbin+1)+hST_t->GetBinContent(maxbin) );
		hST_tW->SetBinContent(maxbin,     hST_tW->GetBinContent(maxbin+1)+hST_tW->GetBinContent(maxbin) );
	}
	//underflow bin
	if (UseUnderflow) {
		int maxbin=1;
		hTTjets->SetBinContent(maxbin,    hTTjets->GetBinContent(maxbin-1)+hTTjets->GetBinContent(maxbin) );
		hWjets->SetBinContent(maxbin,     hWjets->GetBinContent(maxbin-1)+hWjets->GetBinContent(maxbin) );
		hWjetsFast->SetBinContent(maxbin, hWjetsFast->GetBinContent(maxbin-1)+hWjetsFast->GetBinContent(maxbin) );
		hZjets->SetBinContent(maxbin,     hZjets->GetBinContent(maxbin-1)+hZjets->GetBinContent(maxbin) );
		hZjetsFast->SetBinContent(maxbin, hZjetsFast->GetBinContent(maxbin-1)+hZjetsFast->GetBinContent(maxbin) );
		hQCD->SetBinContent(maxbin,       hQCD->GetBinContent(maxbin-1)+hQCD->GetBinContent(maxbin) );
		//hQCD_CS->SetBinContent(maxbin, hQCD_CS->GetBinContent(maxbin-1)+hQCD_CS->GetBinContent(maxbin) );
		hST_s->SetBinContent(maxbin,      hST_s->GetBinContent(maxbin-1)+hST_s->GetBinContent(maxbin) );
		hST_t->SetBinContent(maxbin,      hST_t->GetBinContent(maxbin-1)+hST_t->GetBinContent(maxbin) );
		hST_tW->SetBinContent(maxbin,     hST_tW->GetBinContent(maxbin-1)+hST_tW->GetBinContent(maxbin) );
	}
	//syst.
	if (UseOverflow) {
		int maxbin=hTTjetsS->GetNbinsX();
		hTTjetsS->SetBinContent(maxbin,    hTTjetsS->GetBinContent(maxbin+1)+hTTjetsS->GetBinContent(maxbin) );
		hWjetsS->SetBinContent(maxbin,     hWjetsS->GetBinContent(maxbin+1)+hWjetsS->GetBinContent(maxbin) );
		hWjetsSFast->SetBinContent(maxbin, hWjetsSFast->GetBinContent(maxbin+1)+hWjetsSFast->GetBinContent(maxbin) );
		hZjetsS->SetBinContent(maxbin,     hZjetsS->GetBinContent(maxbin+1)+hZjetsS->GetBinContent(maxbin) );
		hZjetsSFast->SetBinContent(maxbin, hZjetsSFast->GetBinContent(maxbin+1)+hZjetsSFast->GetBinContent(maxbin) );
		hQCDS->SetBinContent(maxbin,       hQCDS->GetBinContent(maxbin+1)+hQCDS->GetBinContent(maxbin) );
		hST_sS->SetBinContent(maxbin,      hST_sS->GetBinContent(maxbin+1)+hST_sS->GetBinContent(maxbin) );
		hST_tS->SetBinContent(maxbin,      hST_tS->GetBinContent(maxbin+1)+hST_tS->GetBinContent(maxbin) );
		hST_tWS->SetBinContent(maxbin,     hST_tWS->GetBinContent(maxbin+1)+hST_tWS->GetBinContent(maxbin) );
	}
	if (UseUnderflow) {
		//underflow bin
		int maxbin=1;
		hTTjetsS->SetBinContent(maxbin,    hTTjetsS->GetBinContent(maxbin-1)+hTTjetsS->GetBinContent(maxbin) );
		hWjetsS->SetBinContent(maxbin,     hWjetsS->GetBinContent(maxbin-1)+hWjetsS->GetBinContent(maxbin) );
		hWjetsSFast->SetBinContent(maxbin, hWjetsSFast->GetBinContent(maxbin-1)+hWjetsSFast->GetBinContent(maxbin) );
		hZjetsS->SetBinContent(maxbin,     hZjetsS->GetBinContent(maxbin-1)+hZjetsS->GetBinContent(maxbin) );
		hZjetsSFast->SetBinContent(maxbin,     hZjetsSFast->GetBinContent(maxbin-1)+hZjetsSFast->GetBinContent(maxbin) );
		hQCDS->SetBinContent(maxbin,       hQCDS->GetBinContent(maxbin-1)+hQCDS->GetBinContent(maxbin) );
		hST_sS->SetBinContent(maxbin,      hST_sS->GetBinContent(maxbin-1)+hST_sS->GetBinContent(maxbin) );
		hST_tS->SetBinContent(maxbin,      hST_tS->GetBinContent(maxbin-1)+hST_tS->GetBinContent(maxbin) );
		hST_tWS->SetBinContent(maxbin,     hST_tWS->GetBinContent(maxbin-1)+hST_tWS->GetBinContent(maxbin) );
	}
	
	// scale histograms to 20/pb

	hTTjets->Scale(0.0081); // madgraph
	//hTTjets->Scale(0.0777);//Tauola
	hWjets->Scale(0.0883);
	//hWjetsFast->Scale(0.0091); //fastsim
	hWjetsFast->Scale(hWjets->Integral() / hWjetsFast->Integral()); // scale to FullSim
		
	hZjets->Scale(0.0731);
	hZjetsFast->Scale(hZjets->Integral()/hZjetsFast->Integral()); //scale to FullSim
	hQCD->Scale(0.4003);
	hQCD_WFast = (TH1F*) hWjetsFast->Clone("hQCD_WFast"); //take shape from Wjets
	hQCD_WFast->Scale(hQCD->Integral()/hQCD_WFast->Integral()); //scale to FullSim
	hST_t->Scale(0.003);
	hST_s->Scale(0.0027);
	hST_tW->Scale(0.0034);

	hTTjetsS->Scale(0.0081); // 
	//hTTjetsS->Scale(0.0008); // for fastsim
	hWjetsS->Scale(0.0883);
	//hWjetsS->Scale(0.0091);// from fastsim
	//hWjetsSFast->Scale(hWjetsS->Integral() / hWjetsSFast->Integral()); // scale to FullSim
	//hWjetsSFast->Scale(0.6642); // scaleUP
	//hWjetsSFast->Scale(0.8041); // scaleDown
	//hWjetsSFast->Scale(0.0605); // threshold 5gev
	hWjetsSFast->Scale(0.042); // threshold 20gev
	
	hZjetsS->Scale(0.0731);
	//hZjetsS->Scale(0.0085);// from fastsim
	hZjetsSFast->Scale(hZjetsS->Integral() / hZjetsSFast->Integral()); // scale to FullSim
	hQCDS->Scale(0.4003);
	//hQCDS_WFast = (TH1F*) hWjetsS->Clone("hQCDS_WFast");
	//hQCDS_WFast->Scale(hQCDS->Integral()/hQCDS_WFast->Integral());
	hST_tS->Scale(0.003);
	hST_sS->Scale(0.0027);
	hST_tWS->Scale(0.0034);
	
	cout << " N expected ttbar+jets events = " << hTTjets->Integral() << endl;
	cout << " N expected W+jets     events = " << hWjets->Integral()  << endl;
	cout << " N expected Z+jets     events = " << hZjets->Integral()  << endl;
	cout << " N expected ST s       events = " << hST_s->Integral()  << endl;
	cout << " N expected ST t       events = " << hST_t->Integral()  << endl;
	cout << " N expected ST tW      events = " << hST_tW->Integral()  << endl;
	cout << " N expected qcd        events = " << hQCD->Integral()  << endl;

	cout << endl;
	cout << " N expected W+jets fast = " << hWjetsFast->Integral() << endl;
	cout << " N expected z+jets fast = " << hZjetsFast->Integral() << endl;
	cout << " N expected qcd Wfast = " << hQCD_WFast->Integral() << endl;

	cout << "\n systematics: " << endl;
	cout << " N expected W+jets fast = " << hWjetsSFast->Integral() << endl;
	cout << " N expected z+jets fast = " << hZjetsS->Integral() << endl;
	cout << " N expected qcd Wfast = " << hQCDS->Integral() << endl;

	// add all three single top samples

	// for systematics
	//hST_t->Scale(2.);
	
	hST_t->Add(hST_s);
	hST_t->Add(hST_tW);
	cout << " number of ST = " << hST_t->Integral() << endl;
	// syst. uncertainty in single top
	//double tmpST = 0.6* hST_t->Integral();
	//hST_t->Scale(0.6);
	//cout << tmpST << endl;
	cout << " New number of ST = " << hST_t->Integral() << endl;
	
	hST_tS->Add(hST_sS);
	hST_tS->Add(hST_tWS);

	// dump scaled histograms in root file
	//TFile *output = TFile::Open("fitM3.root","RECREATE");
	//hTTjets->SetName("ttbar");hTTjets->Write();
	//hWjetsFast->SetName("WjetsFast");hWjetsFast->Write();
	//hST_t->SetName("ST");hST_t->Write();
	//output->Close();
	
		
	hM3 = (TH1F*) hTTjets->Clone("hM3");
	hM3->Add(hWjets);
	hM3->Add(hZjets);
	hM3->Add(hQCD);
	hM3->Add(hST_t);
	
	int Nbins = hM3->GetNbinsX();
	
	// --- Observable ---
        
	RooRealVar mass("mass","M3'(#chi^{2})",100,500,"GeV/c^{2}") ; 
	RooRealVar Ntt("Ntt","number of t#bar{t} events", hTTjets->Integral(), -100 , 1000);
    RooRealVar NW("NW","number of W+jets events", hWjetsFast->Integral(), -500 , 1000);
	RooRealVar NST("NST","number of single top events", hST_t->Integral(), -500,100);
	RooRealVar NZjets("NZjets","number of Z+jets events", hZjetsS->Integral(), -500,500);
	RooRealVar Nqcd("Nqcd","number of QCD events", hQCD_WFast->Integral(), -500,100);
	//RooRealVar Nbkg("Nbkg","number of bkg events", hWjetsFast->Integral()+hST_t->Integral()+hZjetsFast->Integral()+hQCD_WFast->Integral(), -500 , 1000);
	//RooRealVar Nbkg("Nbkg","number of W+jets events", hWjets->Integral(), -500 , 1000); // 2 templates

	RooRealVar Nbkg("Nbkg","number of bkg events", hWjetsFast->Integral()+hZjets->Integral()+hQCD_WFast->Integral(), -500 , 1000);
	//RooRealVar Nbkg("Nbkg","number of bkg events", hWjetsFast->Integral(), -500 , 1000);
	
	// for systematics
	//RooRealVar Nbkg("Nbkg","number of bkg events", hWjetsSFast->Integral()+hZjetsS->Integral()+hQCDS->Integral(), -500 , 1000);
	//RooRealVar Nbkg("Nbkg","number of bkg events", hWjetsSFast->Integral(), -500 , 1000);
	
	mass.setBins(Nbins);

	// RooFit datasets
	RooDataHist hdata_ttbar("hdata_ttbar","ttbar", mass, hTTjets);       
	//RooDataHist hdata_wjets("hdata_wjets","wjets", mass, hWjets);
	RooDataHist hdata_wjetsFast("hdata_wjetsFast","wjets_Fast", mass, hWjetsFast);
	RooDataHist hdata_ST("hdata_ST","ST", mass, hST_t);
	RooDataHist hdata_zjets("hdata_zjets","zjets", mass, hZjets);
	//RooDataHist hdata_qcd("hdata_qcd","qcd", mass, hQCD);
	RooDataHist hdata_zjetsFast("hdata_zjetsFast","zjets_Fast", mass, hZjetsFast);
	RooDataHist hdata_qcdWFast("hdata_qcdWFast","qcd WFast", mass, hQCD_WFast);
	
	RooHistPdf hpdf_ttbar("hpdf_ttbar","signal pdf", mass, hdata_ttbar, 0 );
	//RooHistPdf hpdf_wjets("hpdf_wjets","W+jets pdf", mass, hdata_wjets, 0 );
	RooHistPdf hpdf_wjetsFast("hpdf_wjetsFast","W+jets pdf", mass, hdata_wjetsFast, 0 );
	RooHistPdf hpdf_ST("hpdf_ST","ST pdf", mass, hdata_ST, 0 );
	//RooHistPdf hpdf_zjets("hpdf_zjets","Z+jets pdf", mass, hdata_zjets, 0 );
	//RooHistPdf hpdf_qcd("hpdf_qcd","qcd pdf", mass, hdata_qcd, 0 );
	RooHistPdf hpdf_zjetsFast("hpdf_zjetsFast","Z+jets pdf", mass, hdata_zjetsFast, 0 );
	RooHistPdf hpdf_qcdWFast("hpdf_qcdWFast","qcd WFast pdf", mass, hdata_qcdWFast, 0 );
	
	// for systematics
	RooDataHist hdata_ttbarS("hdata_ttbarS","ttbar", mass, hTTjetsS);       
	RooDataHist hdata_wjetsS("hdata_wjetsS","wjets", mass, hWjetsSFast);
	RooDataHist hdata_STS("hdata_STS","ST", mass, hST_tS);
	RooDataHist hdata_zjetsS("hdata_zjetsS","zjets", mass, hZjetsSFast);
	RooDataHist hdata_qcdS("hdata_qcdS","qcd", mass, hQCDS);
	//RooDataHist hdata_qcdSWFast("hdata_qcdSWFast","qcd WFast", mass, hQCDS_WFast);
		
	RooHistPdf hpdf_ttbarS("hpdf_ttbarS","signal pdf", mass, hdata_ttbarS, 0 );
	RooHistPdf hpdf_wjetsS("hpdf_wjetsS","W+jets pdf", mass, hdata_wjetsS, 0 );
	RooHistPdf hpdf_STS("hpdf_STS","ST pdf", mass, hdata_STS, 0 );
	RooHistPdf hpdf_zjetsS("hpdf_zjetsS","Z+jets pdf", mass, hdata_zjetsS, 0 );
	RooHistPdf hpdf_qcdS("hpdf_qcdS","qcd pdf", mass, hdata_qcdS, 0 );
	//RooHistPdf hpdf_qcdSWFast("hpdf_qcdSWFast","qcd WFast pdf", mass, hdata_qcdSWFast, 0 );

	//RooAddPdf hpdf_bkg("hpdf_bkg","bkg", RooArgList(hpdf_wjetsFast,hpdf_ST,hpdf_qcdWFast),
	//				   RooArgList(NW,NST,Nqcd) );
					   
	//RooAddPdf hpdf_bkg("hpdf_bkg","bkg", RooArgList(hpdf_wjetsFast,hpdf_ST,hpdf_zjetsFast,hpdf_qcdWFast),
					   //RooAddPdf hpdf_bkg("hpdf_bkg","bkg", RooArgList(hpdf_wjetsS,hpdf_STS,hpdf_zjetsS,hpdf_qcdSWFast),
					   //RooArgList(NW,NST,NZjets,Nqcd) );
// only two pdfs: ttbar + Wjets
//RooHistPdf hpdf_bkg = hpdf_wjetsFast;
	
	//RooAddPdf model_M3("modelM3","all", RooArgList(hpdf_ttbar,hpdf_wjetsFast,hpdf_ST,hpdf_zjetsFast,hpdf_qcdWFast),
	//			   RooArgList(Ntt,Nbkg,NST,NZjets,Nqcd));
	// for systematics
	RooAddPdf model_M3("modelM3","all", RooArgList(hpdf_ttbar,hpdf_wjetsFast,hpdf_ST),//RooArgList(hpdf_ttbar,hpdf_wjetsS,hpdf_ST),
					   RooArgList(Ntt,Nbkg,NST) );
	
	//RooAddPdf model_M3("modelM3","all",RooArgList(hpdf_ttbar,hpdf_bkg),
	//		   RooArgList(Ntt,Nbkg) );
	//RooArgList(Ntt,Nbkg,NST,Nqcd) );
	
	RooAddPdf model_histpdf("model", "TTjets+Wjets", RooArgList(hpdf_ttbar,hpdf_wjetsFast,hpdf_ST),
							RooArgList(Ntt, Nbkg, NST) ) ;

	// Construct another Gaussian constraint p.d.f on parameter f at n with resolution of sqrt(n)
	RooGaussian STgaussConstraint("STgaussConstraint","STgaussConstraint",NST,RooConst(hST_t->Integral()),RooConst(sqrt(hST_t->Integral() + (0.3*hST_t->Integral())*(0.3*hST_t->Integral()))) );
	//RooGaussian fconstext2("fconstext2","fconstext2",NZjets,RooConst(hZjets->Integral()),RooConst(sqrt(hZjets->Integral())) );
	
	// --- Generate a toyMC sample 
	//RooMCStudy *mcstudyM3 = new RooMCStudy(model_M3, mass, Binned(kTRUE),Silence(),Extended(),
	//								   FitOptions(Save(kTRUE),Minos(kTRUE),Extended(), ExternalConstraints(fconstext)) );

	// generate PEs
	int Nsamples = 1000;
	// PEs for ttbar
/*
	RooExtendPdf ext_hpdf_ttbar("ext_hpdf_ttbar","ext_hpdf_ttbar",hpdf_ttbar,Ntt);
	RooExtendPdf ext_hpdf_wjets("ext_hpdf_wjets","ext_hpdf_wjets",hpdf_wjetsFast,NW);
	RooExtendPdf ext_hpdf_zjets("ext_hpdf_zjets","ext_hpdf_zjets",hpdf_zjetsFast,NZjets);
	RooExtendPdf ext_hpdf_qcd("ext_hpdf_qcd","ext_hpdf_qcd",hpdf_qcdWFast,Nqcd);
	RooExtendPdf ext_hpdf_ST("ext_hpdf_ST","ext_hpdf_ST",hpdf_ST,NST);
	
	RooMCStudy *mc_ttbar = new RooMCStudy(ext_hpdf_ttbar,mass,Binned(kTRUE),Silence(kTRUE));
	mc_ttbar->generate(Nsamples,0,kFALSE,"data/toymc_ttbar_%04d.dat");
	RooMCStudy *mc_wjets = new RooMCStudy(ext_hpdf_wjets,mass,Binned(kTRUE),Silence(kTRUE));
	mc_wjets->generate(Nsamples,0,kFALSE,"data/toymc_wjets_%04d.dat");
	RooMCStudy *mc_zjets = new RooMCStudy(ext_hpdf_zjets,mass,Binned(kTRUE),Silence(kTRUE));
	mc_zjets->generate(Nsamples,0,kFALSE,"data/toymc_zjets_%04d.dat");
	RooMCStudy *mc_qcd = new RooMCStudy(ext_hpdf_qcd,mass,Binned(kTRUE),Silence(kTRUE));
	mc_qcd->generate(Nsamples,0,kFALSE,"data/toymc_qcd_%04d.dat");
	RooMCStudy *mc_ST = new RooMCStudy(ext_hpdf_ST,mass,Binned(kTRUE),Silence(kTRUE),FitOptions(ExternalConstraints(STgaussConstraint)));
	mc_ST->generate(Nsamples,0,kFALSE,"data/toymc_ST_%04d.dat");

	return;
*/	
	RooMCStudy *mcstudy = new RooMCStudy(model_M3, mass, FitModel(model_histpdf),Binned(kTRUE),Silence(kTRUE), Extended() , 
										 //FitOptions(Save(kTRUE),Minos(kTRUE),Extended()) );
										 FitOptions(Save(kTRUE),Minos(kTRUE),Extended(),ExternalConstraints(STgaussConstraint)));//RooArgList(fconstext,fconstext2)) )); //gaussian constraint
	
		
	//mcstudyM3->generate(Nsamples,0,kFALSE,"toymc.dat");
	//mcstudyM3->generateAndFit(Nsamples,0,kFALSE,"toymc.dat");
	
	//TList dataList;
	//for (int isample=0; isample<Nsamples; ++isample) dataList.Add( mcstudyM3->genData(isample));

	
	// Fit
	mcstudy->generateAndFit(Nsamples,0,kTRUE);
	//mcstudy->fit(Nsamples, "data/toymc_%04d.dat");

		
	gDirectory->Add(mcstudy) ;	
	// E x p l o r e   r e s u l t s   o f   s t u d y 
	// ------------------------------------------------

	// Make plots of the distributions of mean, the error on mean and the pull of mean
	RooPlot* frame1 = mcstudy->plotParam(Ntt,Bins(40));
	RooPlot* frame2 = mcstudy->plotError(Ntt,Bins(40)) ;
	RooPlot* frame3 = mcstudy->plotPull(Ntt,Bins(40),FitGauss(kTRUE)) ;
	RooPlot* frame1w = mcstudy->plotParam(Nbkg,Bins(40)) ;
	RooPlot* frame2w = mcstudy->plotError(Nbkg,Bins(40)) ;
	RooPlot* frame3w = mcstudy->plotPull(Nbkg,Bins(40),FitGauss(kTRUE)) ;
	RooPlot* frame1st = mcstudy->plotParam(NST,Bins(40)) ;
	RooPlot* frame2st = mcstudy->plotError(NST,Bins(40)) ;
	//RooPlot* frame3st = mcstudy->plotPull(NST,Bins(40),FitGauss(kTRUE)) ;
	
	// Plot distribution of minimized likelihood
	RooPlot* frame4 = mcstudy->plotNLL(Bins(40)) ;

	// Make some histograms from the parameter dataset
	TH1* hh_cor_ttbar_w = mcstudy->fitParDataSet().createHistogram("hh",Ntt,YVar(Nbkg)) ;

	// Access some of the saved fit results from individual toys
	//TH2* corrHist000 = mcstudy->fitResult(0)->correlationHist("c000") ;
	//TH2* corrHist127 = mcstudy->fitResult(127)->correlationHist("c127") ;
	//TH2* corrHist953 = mcstudy->fitResult(953)->correlationHist("c953") ;

	
	// Draw all plots on a canvas
	gStyle->SetPalette(1) ;
	gStyle->SetOptStat(0) ;

	TCanvas* cv = new TCanvas("cv","cv",600,600) ;
	hM3->SetFillColor(kRed);
	hWjets->SetFillColor(kGreen);
	hM3->Draw();
	hWjets->Draw("same");
	gPad->RedrawAxis();
	
	TCanvas* cva = new TCanvas("cva","cva",1800,600) ;
	cva->Divide(3);
	cva->cd(1) ;
	RooPlot *initialframe = mass.frame();
	//initial->SetMaximum(10);
	hpdf_ttbar.plotOn(initialframe,LineColor(kRed));
	hpdf_wjetsFast.plotOn(initialframe,LineColor(kGreen));
	hpdf_ST.plotOn(initialframe,LineColor(kYellow));
	initialframe->Draw();
	//initialframe->SetTitle();
	cva->cd(2);
	//retrieve data for only one PE
	
	int Npe = 10;
	RooPlot *genframe = mass.frame(Nbins);
	RooDataSet *gendata = mcstudy->genData(Npe);
	cout << " N events = " << gendata->numEntries() << endl;
	gendata->plotOn(genframe);
	//mcstudy->fitResult(Npe)->plotOn(genframe, model_histpdf);
	genframe->Draw();
	cva->cd(3);
	RooPlot *genframe2 = mass.frame(Nbins);
	mcstudy->fitResult(Npe)->Print("v");
	gendata->plotOn(genframe2);
	RooArgList arglist = mcstudy->fitResult(Npe)->floatParsFinal();

	
	//cout << "name of argument:" << arglist[2].GetName() << endl;
	//cout << "name of argument:" << arglist[1].GetName() << endl;
	//cout << "name of argument:" << arglist[0].GetName() << endl;
	
	RooAddPdf model_histpdf_fitted("modelfitted", "TTjets+Wjets", RooArgList(hpdf_ttbar,hpdf_wjetsFast,hpdf_ST),
							   RooArgList(arglist[2],arglist[1],arglist[0]) ) ;
	
	model_histpdf_fitted.plotOn(genframe2,LineColor(kRed));
	model_histpdf_fitted.plotOn(genframe2,Components(hpdf_wjetsFast),LineColor(kGreen));
	model_histpdf_fitted.plotOn(genframe2,Components(hpdf_ST),LineColor(kYellow));
	genframe2->Draw();

	TCanvas* cvb = new TCanvas("cvb","cvb",1800,600) ;
	cvb->Divide(3);
	cvb->cd(1) ; frame1->Draw();
	cvb->cd(2) ; frame2->Draw();
	cvb->cd(3) ; frame3->Draw();
	TCanvas* cvbb = new TCanvas("cvbb","cvbb",1800,600) ;
	cvbb->Divide(3);
	cvbb->cd(1) ; frame1w->Draw();
	cvbb->cd(2) ; frame2w->Draw();
	cvbb->cd(3) ; frame3w->Draw();

	TCanvas* cvbbb = new TCanvas("cvbbb","cvbbb",1200,600) ;
	cvbbb->Divide(2);
	cvbbb->cd(1) ; frame1st->Draw();
	cvbbb->cd(2) ; frame2st->Draw();
	//cvbbb->cd(3) ; frame3st->Draw();
	
	TCanvas* cvbc = new TCanvas("cvbc","cvbc",600,600) ;
	TH2 *h2 = Ntt.createHistogram("Nttbar vs NWjets",Nbkg);
	mcstudy->fitParDataSet().fillHistogram(h2,RooArgList(Ntt,Nbkg));
	h2->Draw("box");

	
	TCanvas* cvc = new TCanvas("cvc","cvc",600,600) ;	
	// Plot distribution of minimized likelihood
	RooPlot* frame4 = mcstudy->plotNLL(Bins(40)) ;
	frame4->Draw();

	//return;//debuging

	
	TCanvas* cvd = new TCanvas("cvd","cvd",600,600) ;
	TCanvas* cve = new TCanvas("cve","cve",1200,600) ;
	TCanvas* cvf = new TCanvas("cvf","cvf",600,600) ;

	TH1F *hNgen = new TH1F("hNgen","Number of observed events",30,350,650);
	hNgen->SetXTitle("Number of observed events");

	TH1F *hNttresults = new TH1F("hNttresults","number of ttbar events",50,20,600);
	TH1F *hNWresults = new TH1F("hNWresults","number of W events",50,-150,400);
	TH1F *hNSTresults = new TH1F("hNSTresults","number of ttbar events",50,5,25);
									 
	bool gotone = false;
	int Nfailed = 0;
	for ( int i=0; i< Nsamples; i++)
	{
		
		RooFitResult *r = mcstudy->fitResult(i);
		RooArgList list = r->floatParsFinal();
		RooRealVar *rrv_nt = (RooRealVar*)list.at(2);
		double nt = rrv_nt->getVal();
		//double nte= rrv_nt->getError();
		RooRealVar *rrv_nw = (RooRealVar*)list.at(1);
		double nw = rrv_nw->getVal();
		//double nwe= rrv_nw->getError();
		RooRealVar *rrv_nst = (RooRealVar*)list.at(0);
		double nst = rrv_nst->getVal();

				
		hNttresults->Fill(nt);
		hNWresults->Fill(nw);
		hNSTresults->Fill(nst);
		
		
		RooDataSet *adata = mcstudy->genData(i);
		hNgen->Fill(adata->numEntries());
		
		if ( r->numInvalidNLL() > 0 ) Nfailed++;
		
		
		/*
		if ( false ) {
			cout << " sample # " << i << endl;
			gotone = true;
			r->Print("v");
			cout << " invalidNLL = "<< r->numInvalidNLL() << endl;
			cout << " N events = " << adata->numEntries() << endl;

			
			RooAddPdf amodel("amodel", "TTjets+Wjets", RooArgList(hpdf_ttbar,hpdf_wjets,hpdf_ST),
							 RooArgList(list[2],list[1],list[0])) ;
			RooPlot *d2 = new RooPlot(Ntt,NW,0,500,-200,200);
			r->plotOn(d2,Ntt,NW,"ME12ABHV");
			cvd->cd();
			d2->Draw();
			
			RooNLLVar nll("nll","nll", amodel, *adata, Extended() );//, Extended(), PrintEvalErrors(-1) );
			RooMinuit myminuit(nll)
			myminuit.migrad();
			myminuit.hesse();
			myminuit.minos();
			//myminuit.Save()->Print("v");

			cve->Divide(2);
			RooPlot *nllframett = Ntt.frame(Bins(50),Range(100,600));//,Range(10,2000));
			nll.plotOn(nllframett);//,ShiftToZero());
						
			RooProfileLL pll_ntt("pll_ntt","pll_ntt",nll,Ntt);
			pll_ntt.plotOn(nllframett,LineColor(kRed));

			RooPlot *nllframeW = NW.frame(Bins(50),Range(0,250));//,Range(10,2000));
			nll.plotOn(nllframeW);//,ShiftToZero());
						
			RooProfileLL pll_nW("pll_nW","pll_nW",nll,NW);
			pll_nW.plotOn(nllframeW,LineColor(kRed));

			cve->cd(1);
			nllframett->SetMaximum(2);
			nllframett->Draw();
			cve->cd(2);
			nllframeW->SetMaximum(2);
			nllframeW->Draw();
			
		}
		*/
	}

	TCanvas *tmpcv = new TCanvas("tmpcv","tmpcv",700,700);
	cout << "\n ==================================" << endl;
	cout << "gaussian fit of Nttbar fitted values: " << endl;
	//hNttresults->Print("all");
	hNttresults->Fit("gaus");

	cout << "\n ==================================" << endl;
	cout << "gaussian fit of NW fitted values: " << endl;
	//hNWresults->Print("all");
	hNWresults->Fit("gaus");

	cout << "\n ==================================" << endl;
	cout << "gaussian fit of NST fitted values: " << endl;
	//hNSTresults->Print("all");
	hNSTresults->Fit("gaus");

	
	cout << "N failed fits = " << Nfailed << endl;
	
	cvf->cd();
	hNgen->Draw();
	
	// Make RooMCStudy object available on command line after
	// macro finishes
	//gDirectory->Add(mcstudy) ;
}
Пример #14
0
void EcalRecHitsPlotCompare( TString currentfile = "EcalRecHitsValidation_new.root",
                             TString referencefile = "EcalRecHitsValidation_old.root")
{

    gROOT ->Reset();
    char*  rfilename = referencefile;
    char*  sfilename = currentfile;

    int rcolor = 2;
    int scolor = 4;

    delete gROOT->GetListOfFiles()->FindObject(rfilename);
    delete gROOT->GetListOfFiles()->FindObject(sfilename);

    TText* te = new TText();
    te->SetTextSize(0.1);
    TFile * rfile = new TFile(rfilename);
    TFile * sfile = new TFile(sfilename);

    rfile->cd("DQMData/EcalRecHitsV/EcalRecHitsTask");
    gDirectory->ls();

    sfile->cd("DQMData/EcalRecHitsV/EcalRecHitsTask");
    gDirectory->ls();

    Char_t histo[200];

    gStyle->SetOptStat("n");

    gROOT->ProcessLine(".x HistoCompare.C");
    HistoCompare * myPV = new HistoCompare();

//////////////////////////////////////////////////////////////

// General class: Particle Gun
    if (1)
    {
        TH1* meGunEnergy_;
        rfile->GetObject("DQMData/EcalRecHitsV/EcalRecHitsTask/EcalRecHitsTask Gun Momentum;1",meGunEnergy_);
        meGunEnergy_;
        meGunEnergy_->SetLineColor(rcolor);

        TH1* meGunEta_;
        rfile->GetObject("DQMData/EcalRecHitsV/EcalRecHitsTask/EcalRecHitsTask Gun Eta;1",meGunEta_);
        meGunEta_;
        meGunEta_->SetLineColor(rcolor);

        TH1* meGunPhi_;
        rfile->GetObject("DQMData/EcalRecHitsV/EcalRecHitsTask/EcalRecHitsTask Gun Phi;1",meGunPhi_);
        meGunPhi_;
        meGunPhi_->SetLineColor(rcolor);

        TH1* newmeGunEnergy_;
        sfile->GetObject("DQMData/EcalRecHitsV/EcalRecHitsTask/EcalRecHitsTask Gun Momentum;1",newmeGunEnergy_);
        newmeGunEnergy_;
        newmeGunEnergy_->SetLineColor(scolor);

        TH1* newmeGunEta_;
        sfile->GetObject("DQMData/EcalRecHitsV/EcalRecHitsTask/EcalRecHitsTask Gun Eta;1",newmeGunEta_);
        newmeGunEta_;
        newmeGunEta_->SetLineColor(scolor);

        TH1* newmeGunPhi_;
        sfile->GetObject("DQMData/EcalRecHitsV/EcalRecHitsTask/EcalRecHitsTask Gun Phi;1",newmeGunPhi_);
        newmeGunPhi_;
        newmeGunPhi_->SetLineColor(scolor);


        // --------------------------------
        TCanvas * Ecal = new TCanvas("Ecal","Ecal",800,1000);
        Ecal->Divide(1,3);

        Ecal->cd(1);
        if ( meGunEnergy_ && newmeGunEnergy_ ) {
            meGunEnergy_->Draw();
            newmeGunEnergy_->Draw("same");
            myPV->PVCompute( meGunEnergy_ , newmeGunEnergy_ , te );
        }

        Ecal->cd(2);
        if ( meGunEta_ && newmeGunEta_ ) {
            meGunEta_->Draw();
            newmeGunEta_->Draw("same");
            myPV->PVCompute( meGunEta_ , newmeGunEta_ , te );
        }

        Ecal->cd(3);
        if ( meGunPhi_ && newmeGunPhi_ ) {
            meGunPhi_->Draw();
            newmeGunPhi_->Draw("same");
            myPV->PVCompute( meGunPhi_ , newmeGunPhi_ , te );
        }

        Ecal->Print("ParticleGun_compare.eps");
        delete Ecal;
    }



// General class: sim/rec hit ratios
    if (1)
    {
        TH1 *meEBRecHitSimHitRatio_;
        rfile->GetObject("DQMData/EcalRecHitsV/EcalRecHitsTask/EcalRecHitsTask Barrel RecSimHit Ratio;1",meEBRecHitSimHitRatio_);
        meEBRecHitSimHitRatio_;
        meEBRecHitSimHitRatio_->SetLineColor(rcolor);

        TH1 *meEERecHitSimHitRatio_;
        rfile->GetObject("DQMData/EcalRecHitsV/EcalRecHitsTask/EcalRecHitsTask Endcap RecSimHit Ratio;1",meEERecHitSimHitRatio_);
        meEERecHitSimHitRatio_;
        meEERecHitSimHitRatio_->SetLineColor(rcolor);

        TH1 *meESRecHitSimHitRatio_;
        rfile->GetObject("DQMData/EcalRecHitsV/EcalRecHitsTask/EcalRecHitsTask Preshower RecSimHit Ratio;1",meESRecHitSimHitRatio_);
        meESRecHitSimHitRatio_;
        meESRecHitSimHitRatio_->SetLineColor(rcolor);

        TH1 *newmeEBRecHitSimHitRatio_;
        sfile->GetObject("DQMData/EcalRecHitsV/EcalRecHitsTask/EcalRecHitsTask Barrel RecSimHit Ratio;1",newmeEBRecHitSimHitRatio_);
        newmeEBRecHitSimHitRatio_;
        newmeEBRecHitSimHitRatio_->SetLineColor(scolor);

        TH1 *newmeEERecHitSimHitRatio_;
        sfile->GetObject("DQMData/EcalRecHitsV/EcalRecHitsTask/EcalRecHitsTask Endcap RecSimHit Ratio;1",newmeEERecHitSimHitRatio_);
        newmeEERecHitSimHitRatio_;
        newmeEERecHitSimHitRatio_->SetLineColor(scolor);

        TH1 *newmeESRecHitSimHitRatio_;
        sfile->GetObject("DQMData/EcalRecHitsV/EcalRecHitsTask/EcalRecHitsTask Preshower RecSimHit Ratio;1",newmeESRecHitSimHitRatio_);
        newmeESRecHitSimHitRatio_;
        newmeESRecHitSimHitRatio_->SetLineColor(scolor);

        TH1 *meEBRecHitSimHitRatioGt35_;
        rfile->GetObject("DQMData/EcalRecHitsV/EcalRecHitsTask/EcalRecHitsTask Barrel RecSimHit Ratio gt 3p5 GeV;1",meEBRecHitSimHitRatioGt35_);
        meEBRecHitSimHitRatioGt35_;
        meEBRecHitSimHitRatioGt35_->SetLineColor(rcolor);

        TH1 *meEERecHitSimHitRatioGt35_;
        rfile->GetObject("DQMData/EcalRecHitsV/EcalRecHitsTask/EcalRecHitsTask Endcap RecSimHit Ratio gt 3p5 GeV;1",meEERecHitSimHitRatioGt35_);
        meEERecHitSimHitRatioGt35_;
        meEERecHitSimHitRatioGt35_->SetLineColor(rcolor);

        TH1 *newmeEBRecHitSimHitRatioGt35_;
        sfile->GetObject("DQMData/EcalRecHitsV/EcalRecHitsTask/EcalRecHitsTask Barrel RecSimHit Ratio gt 3p5 GeV;1",newmeEBRecHitSimHitRatioGt35_);
        newmeEBRecHitSimHitRatioGt35_;
        newmeEBRecHitSimHitRatioGt35_->SetLineColor(scolor);

        TH1 *newmeEERecHitSimHitRatioGt35_;
        sfile->GetObject("DQMData/EcalRecHitsV/EcalRecHitsTask/EcalRecHitsTask Endcap RecSimHit Ratio gt 3p5 GeV;1",newmeEERecHitSimHitRatioGt35_);
        newmeEERecHitSimHitRatioGt35_;
        newmeEERecHitSimHitRatioGt35_->SetLineColor(scolor);


        // --------------------------------
        TCanvas *BarrelSimRec = new TCanvas("BarrelSimRec","BarrelSimRec",800,800);
        if ( meEBRecHitSimHitRatio_ && newmeEBRecHitSimHitRatio_ ) {
            meEBRecHitSimHitRatio_->Draw();
            newmeEBRecHitSimHitRatio_->Draw("same");
            myPV->PVCompute( meEBRecHitSimHitRatio_ , newmeEBRecHitSimHitRatio_ , te );
        }
        BarrelSimRec->Print("Barrel_SimRecHitsRatio_compare.eps");
        delete BarrelSimRec;


        TCanvas *EndcapSimRec = new TCanvas("EndcapSimRec","EndcapSimRec",800,800);
        if ( meEERecHitSimHitRatio_ && newmeEERecHitSimHitRatio_ ) {
            meEERecHitSimHitRatio_->Draw();
            newmeEERecHitSimHitRatio_->Draw("same");
            myPV->PVCompute( meEERecHitSimHitRatio_ , newmeEERecHitSimHitRatio_ , te );
        }
        EndcapSimRec->Print("Endcap_SimRecHitsRatio_compare.eps");
        delete EndcapSimRec;


        TCanvas *PreshowerSimRec = new TCanvas("PreshowerSimRec","PreshowerSimRec",800,800);
        if ( meESRecHitSimHitRatio_ && newmeESRecHitSimHitRatio_ ) {
            meESRecHitSimHitRatio_->Draw();
            newmeESRecHitSimHitRatio_->Draw("same");
            myPV->PVCompute( meESRecHitSimHitRatio_ , newmeESRecHitSimHitRatio_ , te );
        }
        PreshowerSimRec->Print("Preshower_SimRecHitsRatio_compare.eps");
        delete PreshowerSimRec;


        TCanvas *BarrelSimRecGt35 = new TCanvas("BarrelSimRecGt35","BarrelSimRecGt35",800,800);
        if ( meEBRecHitSimHitRatioGt35_ && newmeEBRecHitSimHitRatioGt35_ ) {
            meEBRecHitSimHitRatioGt35_   ->Draw();
            newmeEBRecHitSimHitRatioGt35_->Draw("same");
            myPV->PVCompute( meEBRecHitSimHitRatioGt35_ , newmeEBRecHitSimHitRatioGt35_ , te );
        }
        BarrelSimRecGt35->Print("Barrel_SimRecHitsRatioGt35_compare.eps");
        delete BarrelSimRecGt35;


        TCanvas *EndcapSimRecGt35 = new TCanvas("EndcapSimRecGt35","EndcapSimRecGt35",800,800);
        if ( meEERecHitSimHitRatioGt35_ && newmeEERecHitSimHitRatioGt35_ ) {
            meEERecHitSimHitRatioGt35_   ->Draw();
            newmeEERecHitSimHitRatioGt35_->Draw("same");
            myPV->PVCompute( meEERecHitSimHitRatioGt35_ , newmeEERecHitSimHitRatioGt35_ , te );
        }
        EndcapSimRecGt35->Print("Endcap_SimRecHitsRatioGt35_compare.eps");
        delete EndcapSimRecGt35;
    }








// ---------------------------------------------------------------------------------
    cout << endl;
    cout << "Barrel validation" << endl;
    rfile->cd("DQMData/EcalRecHitsV/EcalBarrelRecHitsTask");
    gDirectory->ls();
    sfile->cd("DQMData/EcalRecHitsV/EcalBarrelRecHitsTask");
    gDirectory->ls();


// Barrel validation
    if (1)
    {
        TH2 *meEBUncalibRecHitsOccupancy_;
        rfile->GetObject("DQMData/EcalRecHitsV/EcalBarrelRecHitsTask/EB Occupancy;1",meEBUncalibRecHitsOccupancy_);
        meEBUncalibRecHitsOccupancy_;

        TH1 *meEBUncalibRecHitsAmplitude_;
        rfile->GetObject("DQMData/EcalRecHitsV/EcalBarrelRecHitsTask/EB Amplitude;1",meEBUncalibRecHitsAmplitude_);
        meEBUncalibRecHitsAmplitude_;
        meEBUncalibRecHitsAmplitude_->SetLineColor(rcolor);

        TH1 *meEBUncalibRecHitsPedestal_;
        rfile->GetObject("DQMData/EcalRecHitsV/EcalBarrelRecHitsTask/EB Pedestal;1",meEBUncalibRecHitsPedestal_);
        meEBUncalibRecHitsPedestal_;
        meEBUncalibRecHitsPedestal_->SetLineColor(rcolor);

        TH1 *meEBUncalibRecHitsJitter_;
        rfile->GetObject("DQMData/EcalRecHitsV/EcalBarrelRecHitsTask/EB Jitter;1",meEBUncalibRecHitsJitter_);
        meEBUncalibRecHitsJitter_;
        meEBUncalibRecHitsJitter_->SetLineColor(rcolor);

        TH1 *meEBUncalibRecHitsChi2_;
        rfile->GetObject("DQMData/EcalRecHitsV/EcalBarrelRecHitsTask/EB Chi2;1",meEBUncalibRecHitsChi2_);
        meEBUncalibRecHitsChi2_;
        meEBUncalibRecHitsChi2_->SetLineColor(rcolor);

        TH1 *meEBUncalibRecHitMaxSampleRatio_;
        rfile->GetObject("DQMData/EcalRecHitsV/EcalBarrelRecHitsTask/EB RecHit Max Sample Ratio;1",meEBUncalibRecHitMaxSampleRatio_);
        meEBUncalibRecHitMaxSampleRatio_;
        meEBUncalibRecHitMaxSampleRatio_->SetLineColor(rcolor);

        TH2 *meEBUncalibRecHitsOccupancyGt100adc_;
        rfile->GetObject("DQMData/EcalRecHitsV/EcalBarrelRecHitsTask/EB Occupancy gt 100 adc counts;1",meEBUncalibRecHitsOccupancyGt100adc_);
        meEBUncalibRecHitsOccupancyGt100adc_;

        TH1 *meEBUncalibRecHitsAmplitudeGt100adc_;
        rfile->GetObject("DQMData/EcalRecHitsV/EcalBarrelRecHitsTask/EB Amplitude gt 100 adc counts;1",meEBUncalibRecHitsAmplitudeGt100adc_);
        meEBUncalibRecHitsAmplitudeGt100adc_;
        meEBUncalibRecHitsAmplitudeGt100adc_->SetLineColor(rcolor);

        TH1 *meEBUncalibRecHitsPedestalGt100adc_;
        rfile->GetObject("DQMData/EcalRecHitsV/EcalBarrelRecHitsTask/EB Pedestal gt 100 adc counts;1",meEBUncalibRecHitsPedestalGt100adc_);
        meEBUncalibRecHitsPedestalGt100adc_;
        meEBUncalibRecHitsPedestalGt100adc_->SetLineColor(rcolor);

        TH1 *meEBUncalibRecHitsJitterGt100adc_;
        rfile->GetObject("DQMData/EcalRecHitsV/EcalBarrelRecHitsTask/EB Jitter gt 100 adc counts;1",meEBUncalibRecHitsJitterGt100adc_);
        meEBUncalibRecHitsJitterGt100adc_;
        meEBUncalibRecHitsJitterGt100adc_->SetLineColor(rcolor);

        TH1 *meEBUncalibRecHitsChi2Gt100adc_;
        rfile->GetObject("DQMData/EcalRecHitsV/EcalBarrelRecHitsTask/EB Chi2 gt 100 adc counts;1",meEBUncalibRecHitsChi2Gt100adc_);
        meEBUncalibRecHitsChi2Gt100adc_;
        meEBUncalibRecHitsChi2Gt100adc_->SetLineColor(rcolor);

        TH1 *meEBUncalibRecHitMaxSampleRatioGt100adc_;
        rfile->GetObject("DQMData/EcalRecHitsV/EcalBarrelRecHitsTask/EB RecHit Max Sample Ratio gt 100 adc counts;1",meEBUncalibRecHitMaxSampleRatioGt100adc_);
        meEBUncalibRecHitMaxSampleRatioGt100adc_;
        meEBUncalibRecHitMaxSampleRatioGt100adc_->SetLineColor(rcolor);

        TProfile2D *meEBUncalibRecHitsAmpFullMap_;
        rfile->GetObject("DQMData/EcalRecHitsV/EcalBarrelRecHitsTask/EB Amplitude Full Map;1",meEBUncalibRecHitsAmpFullMap_);
        meEBUncalibRecHitsAmpFullMap_;

        TProfile2D *meEBUncalibRecHitsPedFullMap_;
        rfile->GetObject("DQMData/EcalRecHitsV/EcalBarrelRecHitsTask/EB Pedestal Full Map;1",meEBUncalibRecHitsPedFullMap_);
        meEBUncalibRecHitsPedFullMap_;

        TH2 *newmeEBUncalibRecHitsOccupancy_;
        sfile->GetObject("DQMData/EcalRecHitsV/EcalBarrelRecHitsTask/EB Occupancy;1",newmeEBUncalibRecHitsOccupancy_);
        newmeEBUncalibRecHitsOccupancy_;

        TH1 *newmeEBUncalibRecHitsAmplitude_;
        sfile->GetObject("DQMData/EcalRecHitsV/EcalBarrelRecHitsTask/EB Amplitude;1",newmeEBUncalibRecHitsAmplitude_);
        newmeEBUncalibRecHitsAmplitude_;
        newmeEBUncalibRecHitsAmplitude_->SetLineColor(scolor);

        TH1 *newmeEBUncalibRecHitsPedestal_;
        sfile->GetObject("DQMData/EcalRecHitsV/EcalBarrelRecHitsTask/EB Pedestal;1",newmeEBUncalibRecHitsPedestal_);
        newmeEBUncalibRecHitsPedestal_;
        newmeEBUncalibRecHitsPedestal_->SetLineColor(scolor);

        TH1 *newmeEBUncalibRecHitsJitter_;
        sfile->GetObject("DQMData/EcalRecHitsV/EcalBarrelRecHitsTask/EB Jitter;1",newmeEBUncalibRecHitsJitter_);
        newmeEBUncalibRecHitsJitter_;
        newmeEBUncalibRecHitsJitter_->SetLineColor(scolor);

        TH1 *newmeEBUncalibRecHitsChi2_;
        sfile->GetObject("DQMData/EcalRecHitsV/EcalBarrelRecHitsTask/EB Chi2;1",newmeEBUncalibRecHitsChi2_);
        newmeEBUncalibRecHitsChi2_;
        newmeEBUncalibRecHitsChi2_->SetLineColor(scolor);

        TH1 *newmeEBUncalibRecHitMaxSampleRatio_;
        sfile->GetObject("DQMData/EcalRecHitsV/EcalBarrelRecHitsTask/EB RecHit Max Sample Ratio;1",newmeEBUncalibRecHitMaxSampleRatio_);
        newmeEBUncalibRecHitMaxSampleRatio_;
        newmeEBUncalibRecHitMaxSampleRatio_->SetLineColor(scolor);

        TH2 *newmeEBUncalibRecHitsOccupancyGt100adc_;
        sfile->GetObject("DQMData/EcalRecHitsV/EcalBarrelRecHitsTask/EB Occupancy gt 100 adc counts;1",newmeEBUncalibRecHitsOccupancyGt100adc_);
        newmeEBUncalibRecHitsOccupancyGt100adc_;

        TH1 *newmeEBUncalibRecHitsAmplitudeGt100adc_;
        sfile->GetObject("DQMData/EcalRecHitsV/EcalBarrelRecHitsTask/EB Amplitude gt 100 adc counts;1",newmeEBUncalibRecHitsAmplitudeGt100adc_);
        newmeEBUncalibRecHitsAmplitudeGt100adc_;
        newmeEBUncalibRecHitsAmplitudeGt100adc_->SetLineColor(scolor);

        TH1 *newmeEBUncalibRecHitsPedestalGt100adc_;
        sfile->GetObject("DQMData/EcalRecHitsV/EcalBarrelRecHitsTask/EB Pedestal gt 100 adc counts;1",newmeEBUncalibRecHitsPedestalGt100adc_);
        newmeEBUncalibRecHitsPedestalGt100adc_;
        newmeEBUncalibRecHitsPedestalGt100adc_->SetLineColor(scolor);

        TH1 *newmeEBUncalibRecHitsJitterGt100adc_;
        sfile->GetObject("DQMData/EcalRecHitsV/EcalBarrelRecHitsTask/EB Jitter gt 100 adc counts;1",newmeEBUncalibRecHitsJitterGt100adc_);
        newmeEBUncalibRecHitsJitterGt100adc_;
        newmeEBUncalibRecHitsJitterGt100adc_->SetLineColor(scolor);

        TH1 *newmeEBUncalibRecHitsChi2Gt100adc_;
        sfile->GetObject("DQMData/EcalRecHitsV/EcalBarrelRecHitsTask/EB Chi2 gt 100 adc counts;1",newmeEBUncalibRecHitsChi2Gt100adc_);
        newmeEBUncalibRecHitsChi2Gt100adc_;
        newmeEBUncalibRecHitsChi2Gt100adc_->SetLineColor(scolor);

        TH1 *newmeEBUncalibRecHitMaxSampleRatioGt100adc_;
        sfile->GetObject("DQMData/EcalRecHitsV/EcalBarrelRecHitsTask/EB RecHit Max Sample Ratio gt 100 adc counts;1",newmeEBUncalibRecHitMaxSampleRatioGt100adc_);
        newmeEBUncalibRecHitMaxSampleRatioGt100adc_;
        newmeEBUncalibRecHitMaxSampleRatioGt100adc_->SetLineColor(scolor);

        TProfile2D *newmeEBUncalibRecHitsAmpFullMap_;
        sfile->GetObject("DQMData/EcalRecHitsV/EcalBarrelRecHitsTask/EB Amplitude Full Map;1",newmeEBUncalibRecHitsAmpFullMap_);
        newmeEBUncalibRecHitsAmpFullMap_;

        TProfile2D *newmeEBUncalibRecHitsPedFullMap_;
        sfile->GetObject("DQMData/EcalRecHitsV/EcalBarrelRecHitsTask/EB Pedestal Full Map;1",newmeEBUncalibRecHitsPedFullMap_);
        newmeEBUncalibRecHitsPedFullMap_;





        // --------------------------------
        TCanvas *BarrelOccupancy = new TCanvas("BarrelOccupancy","BarrelOccupancy",1000,800);
        BarrelOccupancy->Divide(2,1);
        if ( meEBUncalibRecHitsOccupancy_ && newmeEBUncalibRecHitsOccupancy_ )
        {
            BarrelOccupancy->cd(1);
            meEBUncalibRecHitsOccupancy_   ->Draw("colz");
            BarrelOccupancy->cd(2);
            newmeEBUncalibRecHitsOccupancy_->Draw("colz");
            myPV->PVCompute( meEBUncalibRecHitsOccupancy_ , newmeEBUncalibRecHitsOccupancy_ , te );
        }
        BarrelOccupancy->Print("BarrelOccupancy_compare.eps");
        delete BarrelOccupancy;


        TCanvas *BarrelOccupancyGt100adc = new TCanvas("BarrelOccupancyGt100adc","BarrelOccupancyGt100adc",1000,800);
        BarrelOccupancyGt100adc->Divide(2,1);
        if ( meEBUncalibRecHitsOccupancyGt100adc_ && newmeEBUncalibRecHitsOccupancyGt100adc_ )
        {
            BarrelOccupancyGt100adc->cd(1);
            meEBUncalibRecHitsOccupancyGt100adc_   ->Draw("colz");
            BarrelOccupancyGt100adc->cd(2);
            newmeEBUncalibRecHitsOccupancyGt100adc_->Draw("colz");
            myPV->PVCompute( meEBUncalibRecHitsOccupancyGt100adc_ , newmeEBUncalibRecHitsOccupancyGt100adc_ , te );
        }
        BarrelOccupancyGt100adc->Print("BarrelOccupancyGt100adc_compare.eps");
        delete BarrelOccupancyGt100adc;


        TCanvas *BarrelFullMap = new TCanvas("BarrelFullMap","BarrelFullMap",1000,800);
        BarrelFullMap->Divide(2,2);
        if ( meEBUncalibRecHitsAmpFullMap_ && newmeEBUncalibRecHitsAmpFullMap_ )
        {
            BarrelFullMap->cd(1);
            meEBUncalibRecHitsAmpFullMap_   ->Draw("colz");
            BarrelFullMap->cd(2);
            newmeEBUncalibRecHitsAmpFullMap_->Draw("colz");
            myPV->PVCompute( meEBUncalibRecHitsAmpFullMap_ , newmeEBUncalibRecHitsAmpFullMap_ , te );

            BarrelFullMap->cd(3);
            meEBUncalibRecHitsPedFullMap_   ->Draw("colz");
            BarrelFullMap->cd(4);
            newmeEBUncalibRecHitsPedFullMap_->Draw("colz");
            myPV->PVCompute( meEBUncalibRecHitsPedFullMap_ , newmeEBUncalibRecHitsPedFullMap_ , te );
        }
        BarrelFullMap->Print("BarrelFullMap_compare.eps");
        delete BarrelFullMap;


        TCanvas *Barrel = new TCanvas("Barrel","Barrel",800,800);
        Barrel->Divide(3,2);
        if ( meEBUncalibRecHitsAmplitude_ && newmeEBUncalibRecHitsAmplitude_ )
        {
            Barrel->cd(1);
            gPad->SetLogy();
            meEBUncalibRecHitsAmplitude_->Draw();
            newmeEBUncalibRecHitsAmplitude_->Draw("same");
            myPV->PVCompute( meEBUncalibRecHitsAmplitude_ , newmeEBUncalibRecHitsAmplitude_ , te );
        }

        if ( meEBUncalibRecHitsPedestal_ && newmeEBUncalibRecHitsPedestal_ )
        {
            Barrel->cd(2);
            meEBUncalibRecHitsPedestal_->Draw();
            newmeEBUncalibRecHitsPedestal_->Draw("same");
            myPV->PVCompute( meEBUncalibRecHitsPedestal_ , newmeEBUncalibRecHitsPedestal_ , te );
        }

        if ( meEBUncalibRecHitsJitter_ && newmeEBUncalibRecHitsJitter_ )
        {
            Barrel->cd(3);
            meEBUncalibRecHitsJitter_->Draw();
            newmeEBUncalibRecHitsJitter_->Draw("same");
            myPV->PVCompute( meEBUncalibRecHitsJitter_ , newmeEBUncalibRecHitsJitter_ , te );
        }

        if ( meEBUncalibRecHitsChi2_ && newmeEBUncalibRecHitsChi2_ )
        {
            Barrel->cd(4);
            meEBUncalibRecHitsChi2_->Draw();
            newmeEBUncalibRecHitsChi2_->Draw("same");
            myPV->PVCompute( meEBUncalibRecHitsChi2_ , newmeEBUncalibRecHitsChi2_ , te );
        }

        if ( meEBUncalibRecHitMaxSampleRatio_ && newmeEBUncalibRecHitMaxSampleRatio_ )
        {
            Barrel->cd(5);
            meEBUncalibRecHitMaxSampleRatio_->Draw();
            newmeEBUncalibRecHitMaxSampleRatio_->Draw("same");
            myPV->PVCompute( meEBUncalibRecHitMaxSampleRatio_ , newmeEBUncalibRecHitMaxSampleRatio_ , te );
        }

        Barrel->Print("Barrel_compare.eps");
        delete Barrel;


        TCanvas *BarrelGt100adc = new TCanvas("BarrelGt100adc","BarrelGt100adc",800,800);
        BarrelGt100adc->Divide(3,2);
        if ( meEBUncalibRecHitsAmplitudeGt100adc_ && newmeEBUncalibRecHitsAmplitudeGt100adc_ )
        {
            BarrelGt100adc->cd(1);
            gPad->SetLogy();
            meEBUncalibRecHitsAmplitudeGt100adc_->Draw();
            newmeEBUncalibRecHitsAmplitudeGt100adc_->Draw("same");
            myPV->PVCompute( meEBUncalibRecHitsAmplitudeGt100adc_ , newmeEBUncalibRecHitsAmplitudeGt100adc_ , te );
        }

        if ( meEBUncalibRecHitsPedestalGt100adc_ && newmeEBUncalibRecHitsPedestalGt100adc_ )
        {
            BarrelGt100adc->cd(2);
            meEBUncalibRecHitsPedestalGt100adc_->Draw();
            newmeEBUncalibRecHitsPedestalGt100adc_->Draw("same");
            myPV->PVCompute( meEBUncalibRecHitsPedestalGt100adc_ , newmeEBUncalibRecHitsPedestalGt100adc_ , te );
        }

        if ( meEBUncalibRecHitsJitterGt100adc_ && newmeEBUncalibRecHitsJitterGt100adc_ )
        {
            BarrelGt100adc->cd(3);
            meEBUncalibRecHitsJitterGt100adc_->Draw();
            newmeEBUncalibRecHitsJitterGt100adc_->Draw("same");
            myPV->PVCompute( meEBUncalibRecHitsJitterGt100adc_ , newmeEBUncalibRecHitsJitterGt100adc_ , te );
        }

        if ( meEBUncalibRecHitsChi2Gt100adc_ && newmeEBUncalibRecHitsChi2Gt100adc_ )
        {
            BarrelGt100adc->cd(4);
            meEBUncalibRecHitsChi2Gt100adc_->Draw();
            newmeEBUncalibRecHitsChi2Gt100adc_->Draw("same");
            myPV->PVCompute( meEBUncalibRecHitsChi2Gt100adc_ , newmeEBUncalibRecHitsChi2Gt100adc_ , te );
        }

        if ( meEBUncalibRecHitMaxSampleRatioGt100adc_ && newmeEBUncalibRecHitMaxSampleRatioGt100adc_ )
        {
            BarrelGt100adc->cd(5);
            meEBUncalibRecHitMaxSampleRatioGt100adc_->Draw();
            newmeEBUncalibRecHitMaxSampleRatioGt100adc_->Draw("same");
            myPV->PVCompute( meEBUncalibRecHitMaxSampleRatioGt100adc_ , newmeEBUncalibRecHitMaxSampleRatioGt100adc_ , te );
        }

        BarrelGt100adc->Print("BarrelGt100adc_compare.eps");
        delete BarrelGt100adc;
    }





// -----------------------------------------------------------------
    cout << endl;
    cout << "Endcap validation" << endl;
    rfile->cd("DQMData/EcalRecHitsV/EcalEndcapRecHitsTask");
    gDirectory->ls();
    sfile->cd("DQMData/EcalRecHitsV/EcalEndcapRecHitsTask");
    gDirectory->ls();



// Endcap validation
    if (1)
    {
        TH2 *meEEUncalibRecHitsOccupancyPlus_;
        rfile->GetObject("DQMData/EcalRecHitsV/EcalEndcapRecHitsTask/EE+ Occupancy;1",meEEUncalibRecHitsOccupancyPlus_);
        meEEUncalibRecHitsOccupancyPlus_;

        TH2 *meEEUncalibRecHitsOccupancyMinus_;
        rfile->GetObject("DQMData/EcalRecHitsV/EcalEndcapRecHitsTask/EE- Occupancy;1",meEEUncalibRecHitsOccupancyMinus_);
        meEEUncalibRecHitsOccupancyMinus_;

        TH1 *meEEUncalibRecHitsAmplitude_;
        rfile->GetObject("DQMData/EcalRecHitsV/EcalEndcapRecHitsTask/EE Amplitude;1",meEEUncalibRecHitsAmplitude_);
        meEEUncalibRecHitsAmplitude_;
        meEEUncalibRecHitsAmplitude_->SetLineColor(rcolor);

        TH1 *meEEUncalibRecHitsPedestal_;
        rfile->GetObject("DQMData/EcalRecHitsV/EcalEndcapRecHitsTask/EE Pedestal;1",meEEUncalibRecHitsPedestal_);
        meEEUncalibRecHitsPedestal_;
        meEEUncalibRecHitsPedestal_->SetLineColor(rcolor);

        TH1 *meEEUncalibRecHitsJitter_;
        rfile->GetObject("DQMData/EcalRecHitsV/EcalEndcapRecHitsTask/EE Jitter;1",meEEUncalibRecHitsJitter_);
        meEEUncalibRecHitsJitter_;
        meEEUncalibRecHitsJitter_->SetLineColor(rcolor);

        TH1 *meEEUncalibRecHitsChi2_;
        rfile->GetObject("DQMData/EcalRecHitsV/EcalEndcapRecHitsTask/EE Chi2;1",meEEUncalibRecHitsChi2_);
        meEEUncalibRecHitsChi2_;
        meEEUncalibRecHitsChi2_->SetLineColor(rcolor);

        TH1 *meEEUncalibRecHitMaxSampleRatio_;
        rfile->GetObject("DQMData/EcalRecHitsV/EcalEndcapRecHitsTask/EE RecHit Max Sample Ratio;1",meEEUncalibRecHitMaxSampleRatio_);
        meEEUncalibRecHitMaxSampleRatio_;
        meEEUncalibRecHitMaxSampleRatio_->SetLineColor(rcolor);

        TH2 *meEEUncalibRecHitsOccupancyPlusGt60adc_;
        rfile->GetObject("DQMData/EcalRecHitsV/EcalEndcapRecHitsTask/EE+ Occupancy gt 60 adc counts;1",meEEUncalibRecHitsOccupancyPlusGt60adc_);
        meEEUncalibRecHitsOccupancyPlusGt60adc_;

        TH2 *meEEUncalibRecHitsOccupancyMinusGt60adc_;
        rfile->GetObject("DQMData/EcalRecHitsV/EcalEndcapRecHitsTask/EE- Occupancy gt 60 adc counts;1",meEEUncalibRecHitsOccupancyMinusGt60adc_);
        meEEUncalibRecHitsOccupancyMinusGt60adc_;

        TH1 *meEEUncalibRecHitsAmplitudeGt60adc_;
        rfile->GetObject("DQMData/EcalRecHitsV/EcalEndcapRecHitsTask/EE Amplitude gt 60 adc counts;1",meEEUncalibRecHitsAmplitudeGt60adc_);
        meEEUncalibRecHitsAmplitudeGt60adc_;
        meEEUncalibRecHitsAmplitudeGt60adc_->SetLineColor(rcolor);

        TH1 *meEEUncalibRecHitsPedestalGt60adc_;
        rfile->GetObject("DQMData/EcalRecHitsV/EcalEndcapRecHitsTask/EE Pedestal gt 60 adc counts;1",meEEUncalibRecHitsPedestalGt60adc_);
        meEEUncalibRecHitsPedestalGt60adc_;
        meEEUncalibRecHitsPedestalGt60adc_->SetLineColor(rcolor);

        TH1 *meEEUncalibRecHitsJitterGt60adc_;
        rfile->GetObject("DQMData/EcalRecHitsV/EcalEndcapRecHitsTask/EE Jitter gt 60 adc counts;1",meEEUncalibRecHitsJitterGt60adc_);
        meEEUncalibRecHitsJitterGt60adc_;
        meEEUncalibRecHitsJitterGt60adc_->SetLineColor(rcolor);

        TH1 *meEEUncalibRecHitsChi2Gt60adc_;
        rfile->GetObject("DQMData/EcalRecHitsV/EcalEndcapRecHitsTask/EE Chi2 gt 60 adc counts;1",meEEUncalibRecHitsChi2Gt60adc_);
        meEEUncalibRecHitsChi2Gt60adc_;
        meEEUncalibRecHitsChi2Gt60adc_->SetLineColor(rcolor);

        TH1 *meEEUncalibRecHitMaxSampleRatioGt60adc_;
        rfile->GetObject("DQMData/EcalRecHitsV/EcalEndcapRecHitsTask/EE RecHit Max Sample Ratio gt 60 adc counts;1",meEEUncalibRecHitMaxSampleRatioGt60adc_);
        meEEUncalibRecHitMaxSampleRatioGt60adc_;
        meEEUncalibRecHitMaxSampleRatioGt60adc_->SetLineColor(rcolor);

        TProfile2D *meEEUncalibRecHitsAmpFullMap_;
        rfile->GetObject("DQMData/EcalRecHitsV/EcalEndcapRecHitsTask/EE Amplitude Full Map;1",meEEUncalibRecHitsAmpFullMap_);
        meEEUncalibRecHitsAmpFullMap_;

        TProfile2D *meEEUncalibRecHitsPedFullMap_;
        rfile->GetObject("DQMData/EcalRecHitsV/EcalEndcapRecHitsTask/EE Pedestal Full Map;1",meEEUncalibRecHitsPedFullMap_);
        meEEUncalibRecHitsPedFullMap_;

        TH2 *newmeEEUncalibRecHitsOccupancyPlus_;
        sfile->GetObject("DQMData/EcalRecHitsV/EcalEndcapRecHitsTask/EE+ Occupancy;1",newmeEEUncalibRecHitsOccupancyPlus_);
        newmeEEUncalibRecHitsOccupancyPlus_;

        TH2 *newmeEEUncalibRecHitsOccupancyMinus_;
        sfile->GetObject("DQMData/EcalRecHitsV/EcalEndcapRecHitsTask/EE- Occupancy;1",newmeEEUncalibRecHitsOccupancyMinus_);
        newmeEEUncalibRecHitsOccupancyMinus_;

        TH1 *newmeEEUncalibRecHitsAmplitude_;
        sfile->GetObject("DQMData/EcalRecHitsV/EcalEndcapRecHitsTask/EE Amplitude;1",newmeEEUncalibRecHitsAmplitude_);
        newmeEEUncalibRecHitsAmplitude_;
        newmeEEUncalibRecHitsAmplitude_->SetLineColor(scolor);

        TH1 *newmeEEUncalibRecHitsPedestal_;
        sfile->GetObject("DQMData/EcalRecHitsV/EcalEndcapRecHitsTask/EE Pedestal;1",newmeEEUncalibRecHitsPedestal_);
        newmeEEUncalibRecHitsPedestal_;
        newmeEEUncalibRecHitsPedestal_->SetLineColor(scolor);

        TH1 *newmeEEUncalibRecHitsJitter_;
        sfile->GetObject("DQMData/EcalRecHitsV/EcalEndcapRecHitsTask/EE Jitter;1",newmeEEUncalibRecHitsJitter_);
        newmeEEUncalibRecHitsJitter_;
        newmeEEUncalibRecHitsJitter_->SetLineColor(scolor);

        TH1 *newmeEEUncalibRecHitsChi2_;
        sfile->GetObject("DQMData/EcalRecHitsV/EcalEndcapRecHitsTask/EE Chi2;1",newmeEEUncalibRecHitsChi2_);
        newmeEEUncalibRecHitsChi2_;
        newmeEEUncalibRecHitsChi2_->SetLineColor(scolor);

        TH1 *newmeEEUncalibRecHitMaxSampleRatio_;
        sfile->GetObject("DQMData/EcalRecHitsV/EcalEndcapRecHitsTask/EE RecHit Max Sample Ratio;1",newmeEEUncalibRecHitMaxSampleRatio_);
        newmeEEUncalibRecHitMaxSampleRatio_;
        newmeEEUncalibRecHitMaxSampleRatio_->SetLineColor(scolor);

        TH2 *newmeEEUncalibRecHitsOccupancyPlusGt60adc_;
        sfile->GetObject("DQMData/EcalRecHitsV/EcalEndcapRecHitsTask/EE+ Occupancy gt 60 adc counts;1",newmeEEUncalibRecHitsOccupancyPlusGt60adc_);
        newmeEEUncalibRecHitsOccupancyPlusGt60adc_;

        TH2 *newmeEEUncalibRecHitsOccupancyMinusGt60adc_;
        sfile->GetObject("DQMData/EcalRecHitsV/EcalEndcapRecHitsTask/EE- Occupancy gt 60 adc counts;1",newmeEEUncalibRecHitsOccupancyMinusGt60adc_);
        newmeEEUncalibRecHitsOccupancyMinusGt60adc_;

        TH1 *newmeEEUncalibRecHitsAmplitudeGt60adc_;
        sfile->GetObject("DQMData/EcalRecHitsV/EcalEndcapRecHitsTask/EE Amplitude gt 60 adc counts;1",newmeEEUncalibRecHitsAmplitudeGt60adc_);
        newmeEEUncalibRecHitsAmplitudeGt60adc_;
        newmeEEUncalibRecHitsAmplitudeGt60adc_->SetLineColor(scolor);

        TH1 *newmeEEUncalibRecHitsPedestalGt60adc_;
        sfile->GetObject("DQMData/EcalRecHitsV/EcalEndcapRecHitsTask/EE Pedestal gt 60 adc counts;1",newmeEEUncalibRecHitsPedestalGt60adc_);
        newmeEEUncalibRecHitsPedestalGt60adc_;
        newmeEEUncalibRecHitsPedestalGt60adc_->SetLineColor(scolor);

        TH1 *newmeEEUncalibRecHitsJitterGt60adc_;
        sfile->GetObject("DQMData/EcalRecHitsV/EcalEndcapRecHitsTask/EE Jitter gt 60 adc counts;1",newmeEEUncalibRecHitsJitterGt60adc_);
        newmeEEUncalibRecHitsJitterGt60adc_;
        newmeEEUncalibRecHitsJitterGt60adc_->SetLineColor(scolor);

        TH1 *newmeEEUncalibRecHitsChi2Gt60adc_;
        sfile->GetObject("DQMData/EcalRecHitsV/EcalEndcapRecHitsTask/EE Chi2 gt 60 adc counts;1",newmeEEUncalibRecHitsChi2Gt60adc_);
        newmeEEUncalibRecHitsChi2Gt60adc_;
        newmeEEUncalibRecHitsChi2Gt60adc_->SetLineColor(scolor);

        TH1 *newmeEEUncalibRecHitMaxSampleRatioGt60adc_;
        sfile->GetObject("DQMData/EcalRecHitsV/EcalEndcapRecHitsTask/EE RecHit Max Sample Ratio gt 60 adc counts;1",newmeEEUncalibRecHitMaxSampleRatioGt60adc_);
        newmeEEUncalibRecHitMaxSampleRatioGt60adc_;
        newmeEEUncalibRecHitMaxSampleRatioGt60adc_->SetLineColor(scolor);

        TProfile2D *newmeEEUncalibRecHitsAmpFullMap_;
        sfile->GetObject("DQMData/EcalRecHitsV/EcalEndcapRecHitsTask/EE Amplitude Full Map;1",newmeEEUncalibRecHitsAmpFullMap_);
        newmeEEUncalibRecHitsAmpFullMap_;

        TProfile2D *newmeEEUncalibRecHitsPedFullMap_;
        sfile->GetObject("DQMData/EcalRecHitsV/EcalEndcapRecHitsTask/EE Pedestal Full Map;1",newmeEEUncalibRecHitsPedFullMap_);
        newmeEEUncalibRecHitsPedFullMap_;



        // --------------------------------
        TCanvas *EndcapOccupancy = new TCanvas("EndcapOccupancy","EndcapOccupancy",1000,800);
        EndcapOccupancy->Divide(2,2);
        if ( meEEUncalibRecHitsOccupancyPlus_ && newmeEEUncalibRecHitsOccupancyPlus_ )
        {
            EndcapOccupancy->cd(1);
            meEEUncalibRecHitsOccupancyPlus_->Draw("colz");
            EndcapOccupancy->cd(2);
            newmeEEUncalibRecHitsOccupancyPlus_->Draw("colz");
            myPV->PVCompute( meEEUncalibRecHitsOccupancyPlus_ , newmeEEUncalibRecHitsOccupancyPlus_ , te );
        }

        if ( meEEUncalibRecHitsOccupancyMinus_ && newmeEEUncalibRecHitsOccupancyMinus_ )
        {
            EndcapOccupancy->cd(3);
            meEEUncalibRecHitsOccupancyMinus_->Draw("colz");
            EndcapOccupancy->cd(4);
            newmeEEUncalibRecHitsOccupancyMinus_->Draw("colz");
            myPV->PVCompute( meEEUncalibRecHitsOccupancyMinus_ , newmeEEUncalibRecHitsOccupancyMinus_ , te );
        }

        EndcapOccupancy->Print("EndcapOccupancy_compare.eps");
        delete EndcapOccupancy;


        TCanvas *EndcapOccupancyGt60adc = new TCanvas("EndcapOccupancyGt60adc","EndcapOccupancyGt60adc",1000,800);
        EndcapOccupancyGt60adc->Divide(2,2);
        if ( meEEUncalibRecHitsOccupancyPlusGt60adc_ && newmeEEUncalibRecHitsOccupancyPlusGt60adc_ )
        {
            EndcapOccupancyGt60adc->cd(1);
            meEEUncalibRecHitsOccupancyPlusGt60adc_->Draw("colz");
            EndcapOccupancyGt60adc->cd(2);
            newmeEEUncalibRecHitsOccupancyPlusGt60adc_->Draw("colz");
            myPV->PVCompute( meEEUncalibRecHitsOccupancyPlusGt60adc_ , newmeEEUncalibRecHitsOccupancyPlusGt60adc_ , te );
        }

        if ( meEEUncalibRecHitsOccupancyMinusGt60adc_ && newmeEEUncalibRecHitsOccupancyMinusGt60adc_ )
        {
            EndcapOccupancyGt60adc->cd(3);
            meEEUncalibRecHitsOccupancyMinusGt60adc_->Draw("colz");
            EndcapOccupancyGt60adc->cd(4);
            newmeEEUncalibRecHitsOccupancyMinusGt60adc_->Draw("colz");
            myPV->PVCompute( meEEUncalibRecHitsOccupancyMinusGt60adc_ , newmeEEUncalibRecHitsOccupancyMinusGt60adc_ , te );
        }

        EndcapOccupancyGt60adc->Print("EndcapOccupancyGt60adc_compare.eps");
        delete EndcapOccupancyGt60adc;


        TCanvas *EndcapFullMap = new TCanvas("EndcapFullMap","EndcapFullMap",1000,800);
        EndcapFullMap->Divide(2,2);
        if ( meEEUncalibRecHitsAmpFullMap_ && newmeEEUncalibRecHitsAmpFullMap_ )
        {
            EndcapFullMap->cd(1);
            meEEUncalibRecHitsAmpFullMap_   ->Draw("colz");
            EndcapFullMap->cd(2);
            newmeEEUncalibRecHitsAmpFullMap_->Draw("colz");
            myPV->PVCompute( meEEUncalibRecHitsAmpFullMap_ , newmeEEUncalibRecHitsAmpFullMap_ , te );

            EndcapFullMap->cd(3);
            meEEUncalibRecHitsPedFullMap_   ->Draw("colz");
            EndcapFullMap->cd(4);
            newmeEEUncalibRecHitsPedFullMap_->Draw("colz");
            myPV->PVCompute( meEEUncalibRecHitsPedFullMap_ , newmeEEUncalibRecHitsPedFullMap_ , te );
        }
        EndcapFullMap->Print("EndcapFullMap_compare.eps");
        delete EndcapFullMap;


        TCanvas *Endcap = new TCanvas("Endcap","Endcap",800,800);
        Endcap->Divide(2,2);
        if ( meEEUncalibRecHitsAmplitude_ && newmeEEUncalibRecHitsAmplitude_ )
        {
            Endcap->cd(1);
            gPad->SetLogy();
            meEEUncalibRecHitsAmplitude_->Draw();
            newmeEEUncalibRecHitsAmplitude_->Draw("same");
            myPV->PVCompute( meEEUncalibRecHitsAmplitude_ , newmeEEUncalibRecHitsAmplitude_ , te );
        }

        if ( meEEUncalibRecHitsPedestal_ && newmeEEUncalibRecHitsPedestal_ )
        {
            Endcap->cd(2);
            meEEUncalibRecHitsPedestal_->Draw();
            newmeEEUncalibRecHitsPedestal_->Draw("same");
            myPV->PVCompute( meEEUncalibRecHitsPedestal_ , newmeEEUncalibRecHitsPedestal_ , te );
        }

        if ( meEEUncalibRecHitsJitter_ && newmeEEUncalibRecHitsJitter_ )
        {
            Endcap->cd(3);
            meEEUncalibRecHitsJitter_->Draw();
            newmeEEUncalibRecHitsJitter_->Draw("same");
            myPV->PVCompute( meEEUncalibRecHitsJitter_ , newmeEEUncalibRecHitsJitter_ , te );
        }

        if ( meEEUncalibRecHitsChi2_ && newmeEEUncalibRecHitsChi2_ )
        {
            Endcap->cd(4);
            meEEUncalibRecHitsChi2_->Draw();
            newmeEEUncalibRecHitsChi2_->Draw("same");
            myPV->PVCompute( meEEUncalibRecHitsChi2_ , newmeEEUncalibRecHitsChi2_ , te );
        }
        Endcap->Print("Endcap_compare.eps");
        delete Endcap;


        TCanvas *EndcapGt60adc = new TCanvas("EndcapGt60adc","EndcapGt60adc",800,800);
        EndcapGt60adc->Divide(2,2);
        if ( meEEUncalibRecHitsAmplitudeGt60adc_ && newmeEEUncalibRecHitsAmplitudeGt60adc_ )
        {
            EndcapGt60adc->cd(1);
            gPad->SetLogy();
            meEEUncalibRecHitsAmplitudeGt60adc_->Draw();
            newmeEEUncalibRecHitsAmplitudeGt60adc_->Draw("same");
            myPV->PVCompute( meEEUncalibRecHitsAmplitudeGt60adc_ , newmeEEUncalibRecHitsAmplitudeGt60adc_ , te );
        }

        if ( meEEUncalibRecHitsPedestalGt60adc_ && newmeEEUncalibRecHitsPedestalGt60adc_ )
        {
            EndcapGt60adc->cd(2);
            meEEUncalibRecHitsPedestalGt60adc_->Draw();
            newmeEEUncalibRecHitsPedestalGt60adc_->Draw("same");
            myPV->PVCompute( meEEUncalibRecHitsPedestalGt60adc_ , newmeEEUncalibRecHitsPedestalGt60adc_ , te );
        }

        if ( meEEUncalibRecHitsJitterGt60adc_ && newmeEEUncalibRecHitsJitterGt60adc_ )
        {
            EndcapGt60adc->cd(3);
            meEEUncalibRecHitsJitterGt60adc_->Draw();
            newmeEEUncalibRecHitsJitterGt60adc_->Draw("same");
            myPV->PVCompute( meEEUncalibRecHitsJitterGt60adc_ , newmeEEUncalibRecHitsJitterGt60adc_ , te );
        }

        if ( meEEUncalibRecHitsChi2Gt60adc_ && newmeEEUncalibRecHitsChi2Gt60adc_ )
        {
            EndcapGt60adc->cd(4);
            meEEUncalibRecHitsChi2Gt60adc_->Draw();
            newmeEEUncalibRecHitsChi2Gt60adc_->Draw("same");
            myPV->PVCompute( meEEUncalibRecHitsChi2Gt60adc_ , newmeEEUncalibRecHitsChi2Gt60adc_ , te );
        }
        EndcapGt60adc->Print("EndcapGt60adc_compare.eps");
        delete EndcapGt60adc;
    }







// ----------------------------------------------------------------
    cout << endl;
    cout << "Preshower validation" << endl;
    rfile->cd("DQMData/EcalRecHitsV/EcalPreshowerRecHitsTask");
    gDirectory->ls();
    sfile->cd("DQMData/EcalRecHitsV/EcalPreshowerRecHitsTask");
    gDirectory->ls();


// Preshower validation
    if (1)
    {
        TH1 *meESRecHitsEnergy_;
        rfile->GetObject("DQMData/EcalRecHitsV/EcalPreshowerRecHitsTask/ES Energy;1",meESRecHitsEnergy_);
        meESRecHitsEnergy_;
        meESRecHitsEnergy_->SetLineColor(rcolor);

        TH1 *meESRecHitsEnergy_zp1st_;
        rfile->GetObject("DQMData/EcalRecHitsV/EcalPreshowerRecHitsTask/ES Energy Plane1 Side+;1",meESRecHitsEnergy_zp1st_);
        meESRecHitsEnergy_zp1st_;
        meESRecHitsEnergy_zp1st_->SetLineColor(rcolor);

        TH1 *meESRecHitsEnergy_zp2nd_;
        rfile->GetObject("DQMData/EcalRecHitsV/EcalPreshowerRecHitsTask/ES Energy Plane2 Side+;1",meESRecHitsEnergy_zp2nd_);
        meESRecHitsEnergy_zp2nd_;
        meESRecHitsEnergy_zp2nd_->SetLineColor(rcolor);

        TH1 *meESRecHitsEnergy_zm1st_;
        rfile->GetObject("DQMData/EcalRecHitsV/EcalPreshowerRecHitsTask/ES Energy Plane1 Side-;1",meESRecHitsEnergy_zm1st_);
        meESRecHitsEnergy_zm1st_;
        meESRecHitsEnergy_zm1st_->SetLineColor(rcolor);

        TH1 *meESRecHitsEnergy_zm2nd_;
        rfile->GetObject("DQMData/EcalRecHitsV/EcalPreshowerRecHitsTask/ES Energy Plane2 Side-;1",meESRecHitsEnergy_zm2nd_);
        meESRecHitsEnergy_zm2nd_;
        meESRecHitsEnergy_zm2nd_->SetLineColor(rcolor);

        TH1 *meESRecHitsMultip_;
        rfile->GetObject("DQMData/EcalRecHitsV/EcalPreshowerRecHitsTask/ES Multiplicity;1",meESRecHitsMultip_);
        meESRecHitsMultip_;
        meESRecHitsMultip_->SetLineColor(rcolor);

        TH1 *meESRecHitsMultip_zp1st_;
        rfile->GetObject("DQMData/EcalRecHitsV/EcalPreshowerRecHitsTask/ES Multiplicity Plane1 Side+;1",meESRecHitsMultip_zp1st_);
        meESRecHitsMultip_zp1st_;
        meESRecHitsMultip_zp1st_->SetLineColor(rcolor);

        TH1 *meESRecHitsMultip_zp2nd_;
        rfile->GetObject("DQMData/EcalRecHitsV/EcalPreshowerRecHitsTask/ES Multiplicity Plane2 Side+;1",meESRecHitsMultip_zp2nd_);
        meESRecHitsMultip_zp2nd_;
        meESRecHitsMultip_zp2nd_->SetLineColor(rcolor);

        TH1 *meESRecHitsMultip_zm1st_;
        rfile->GetObject("DQMData/EcalRecHitsV/EcalPreshowerRecHitsTask/ES Multiplicity Plane1 Side-;1",meESRecHitsMultip_zm1st_);
        meESRecHitsMultip_zm1st_;
        meESRecHitsMultip_zm1st_->SetLineColor(rcolor);

        TH1 *meESRecHitsMultip_zm2nd_;
        rfile->GetObject("DQMData/EcalRecHitsV/EcalPreshowerRecHitsTask/ES Multiplicity Plane1 Side-;1",meESRecHitsMultip_zm2nd_);
        meESRecHitsMultip_zm2nd_;
        meESRecHitsMultip_zm2nd_->SetLineColor(rcolor);

        TH1 *meESEERecHitsEnergy_zp_;
        rfile->GetObject("DQMData/EcalRecHitsV/EcalPreshowerRecHitsTask/Preshower EE vs ES energy Side+;1",meESEERecHitsEnergy_zp_);
        meESEERecHitsEnergy_zp_;

        TH1 *meESEERecHitsEnergy_zm_;
        rfile->GetObject("DQMData/EcalRecHitsV/EcalPreshowerRecHitsTask/Preshower EE vs ES energy Side-;1",meESEERecHitsEnergy_zm_);
        meESEERecHitsEnergy_zm_;

        TH1 *newmeESRecHitsEnergy_;
        sfile->GetObject("DQMData/EcalRecHitsV/EcalPreshowerRecHitsTask/ES Energy;1",newmeESRecHitsEnergy_);
        newmeESRecHitsEnergy_;
        newmeESRecHitsEnergy_->SetLineColor(scolor);

        TH1 *newmeESRecHitsEnergy_zp1st_;
        sfile->GetObject("DQMData/EcalRecHitsV/EcalPreshowerRecHitsTask/ES Energy Plane1 Side+;1",newmeESRecHitsEnergy_zp1st_);
        newmeESRecHitsEnergy_zp1st_;
        newmeESRecHitsEnergy_zp1st_->SetLineColor(scolor);

        TH1 *newmeESRecHitsEnergy_zp2nd_;
        sfile->GetObject("DQMData/EcalRecHitsV/EcalPreshowerRecHitsTask/ES Energy Plane2 Side+;1",newmeESRecHitsEnergy_zp2nd_);
        newmeESRecHitsEnergy_zp2nd_;
        newmeESRecHitsEnergy_zp2nd_->SetLineColor(scolor);

        TH1 *newmeESRecHitsEnergy_zm1st_;
        sfile->GetObject("DQMData/EcalRecHitsV/EcalPreshowerRecHitsTask/ES Energy Plane1 Side-;1",newmeESRecHitsEnergy_zm1st_);
        newmeESRecHitsEnergy_zm1st_;
        newmeESRecHitsEnergy_zm1st_->SetLineColor(scolor);

        TH1 *newmeESRecHitsEnergy_zm2nd_;
        sfile->GetObject("DQMData/EcalRecHitsV/EcalPreshowerRecHitsTask/ES Energy Plane2 Side-;1",newmeESRecHitsEnergy_zm2nd_);
        newmeESRecHitsEnergy_zm2nd_;
        newmeESRecHitsEnergy_zm2nd_->SetLineColor(scolor);

        TH1 *newmeESRecHitsMultip_;
        sfile->GetObject("DQMData/EcalRecHitsV/EcalPreshowerRecHitsTask/ES Multiplicity;1",newmeESRecHitsMultip_);
        newmeESRecHitsMultip_;
        newmeESRecHitsMultip_->SetLineColor(scolor);

        TH1 *newmeESRecHitsMultip_zp1st_;
        sfile->GetObject("DQMData/EcalRecHitsV/EcalPreshowerRecHitsTask/ES Multiplicity Plane1 Side+;1",newmeESRecHitsMultip_zp1st_);
        newmeESRecHitsMultip_zp1st_;
        newmeESRecHitsMultip_zp1st_->SetLineColor(scolor);

        TH1 *newmeESRecHitsMultip_zp2nd_;
        sfile->GetObject("DQMData/EcalRecHitsV/EcalPreshowerRecHitsTask/ES Multiplicity Plane2 Side+;1",newmeESRecHitsMultip_zp2nd_);
        newmeESRecHitsMultip_zp2nd_;
        newmeESRecHitsMultip_zp2nd_->SetLineColor(scolor);

        TH1 *newmeESRecHitsMultip_zm1st_;
        sfile->GetObject("DQMData/EcalRecHitsV/EcalPreshowerRecHitsTask/ES Multiplicity Plane1 Side-;1",newmeESRecHitsMultip_zm1st_);
        newmeESRecHitsMultip_zm1st_;
        newmeESRecHitsMultip_zm1st_->SetLineColor(scolor);

        TH1 *newmeESRecHitsMultip_zm2nd_;
        sfile->GetObject("DQMData/EcalRecHitsV/EcalPreshowerRecHitsTask/ES Multiplicity Plane1 Side-;1",newmeESRecHitsMultip_zm2nd_);
        newmeESRecHitsMultip_zm2nd_;
        newmeESRecHitsMultip_zm2nd_->SetLineColor(scolor);

        TH1 *newmeESEERecHitsEnergy_zp_;
        sfile->GetObject("DQMData/EcalRecHitsV/EcalPreshowerRecHitsTask/Preshower EE vs ES energy Side+;1",newmeESEERecHitsEnergy_zp_);
        newmeESEERecHitsEnergy_zp_;

        TH1 *newmeESEERecHitsEnergy_zm_;
        sfile->GetObject("DQMData/EcalRecHitsV/EcalPreshowerRecHitsTask/Preshower EE vs ES energy Side-;1",newmeESEERecHitsEnergy_zm_);
        newmeESEERecHitsEnergy_zm_;



        // ----------------------------------------------
        TCanvas *ESEnergyAll = new TCanvas("ESEnergyAll","ESEnergyAll",800,800);
        gPad->SetLogy();
        if ( meESRecHitsEnergy_ && newmeESRecHitsEnergy_ )
        {
            meESRecHitsEnergy_->Draw();
            newmeESRecHitsEnergy_->Draw("same");
            myPV->PVCompute( meESRecHitsEnergy_ , newmeESRecHitsEnergy_ , te );
        }
        ESEnergyAll->Print("PreshowerEnergyAll_compare.eps");
        delete ESEnergyAll;


        TCanvas *ESEnergy = new TCanvas("ESEnergy","ESEnergy",800,800);
        ESEnergy->Divide(2,2);
        if ( meESRecHitsEnergy_zp1st_ && newmeESRecHitsEnergy_zp1st_ )
        {
            ESEnergy->cd(1);
            gPad->SetLogy();
            meESRecHitsEnergy_zp1st   _->Draw();
            newmeESRecHitsEnergy_zp1st_->Draw("same");
        }
        if ( meESRecHitsEnergy_zp2nd_ && newmeESRecHitsEnergy_zp2nd_ )
        {
            ESEnergy->cd(2);
            gPad->SetLogy();
            meESRecHitsEnergy_zp2nd_   ->Draw();
            newmeESRecHitsEnergy_zp2nd_->Draw("same");
        }
        if ( meESRecHitsEnergy_zm1st_ && newmeESRecHitsEnergy_zm1st_ )
        {
            ESEnergy->cd(3);
            gPad->SetLogy();
            meESRecHitsEnergy_zm1st_   ->Draw();
            newmeESRecHitsEnergy_zm1st_->Draw("same");
        }
        if ( meESRecHitsEnergy_zm2nd_ && newmeESRecHitsEnergy_zm2nd_ )
        {
            ESEnergy->cd(4);
            gPad->SetLogy();
            meESRecHitsEnergy_zm2nd_   ->Draw();
            newmeESRecHitsEnergy_zm2nd_->Draw("same");
        }
        ESEnergy->Print("PreshowerEnergy_compare.eps");
        delete ESEnergy;


        TCanvas *ESMultipAll = new TCanvas("ESMultipAll","ESMultipAll",800,800);
        if ( meESRecHitsMultip_ && newmeESRecHitsMultip_ )
        {
            meESRecHitsMultip_->Draw();
            newmeESRecHitsMultip_->Draw("same");
            myPV->PVCompute( meESRecHitsMultip_ , newmeESRecHitsMultip_ , te );
        }
        ESMultipAll->Print("PreshowerMultipAll_compare.eps");
        delete ESMultipAll;



        TCanvas *ESMultip = new TCanvas("ESMultip","ESMultip",800,800);
        ESMultip->Divide(2,2);
        if ( meESRecHitsMultip_zp1st_ && newmeESRecHitsMultip_zp1st_ )
        {
            ESMultip->cd(1);
            meESRecHitsMultip_zp1st   _->Draw();
            newmeESRecHitsMultip_zp1st_->Draw("same");
        }
        if ( meESRecHitsMultip_zp2nd_ && newmeESRecHitsMultip_zp2nd_ )
        {
            ESMultip->cd(2);
            meESRecHitsMultip_zp2nd_   ->Draw();
            newmeESRecHitsMultip_zp2nd_->Draw("same");
        }
        if ( meESRecHitsMultip_zm1st_ && newmeESRecHitsMultip_zm1st_ )
        {
            ESMultip->cd(3);
            meESRecHitsMultip_zm1st_   ->Draw();
            newmeESRecHitsMultip_zm1st_->Draw("same");
        }
        if ( meESRecHitsMultip_zm2nd_ && newmeESRecHitsMultip_zm2nd_ )
        {
            ESMultip->cd(4);
            meESRecHitsMultip_zm2nd_   ->Draw();
            newmeESRecHitsMultip_zm2nd_->Draw("same");
        }
        ESMultip->Print("PreshowerMultip_compare.eps");
        delete ESMultip;



        TCanvas *ESvsEE = new TCanvas("ESvsEE","ESvsEE",800,800);
        ESvsEE->Divide(2,2);
        if ( meESEERecHitsEnergy_zp_ && newmeESEERecHitsEnergy_zp_ )
        {
            ESvsEE->cd(1);
            meESEERecHitsEnergy_zp   _->Draw();
            ESvsEE->cd(2);
            newmeESEERecHitsEnergy_zp_->Draw();
            myPV->PVCompute( meESEERecHitsEnergy_zp_ , newmeESEERecHitsEnergy_zp_ , te);
        }
        if ( meESEERecHitsEnergy_zm_ && newmeESEERecHitsEnergy_zm_ )
        {
            ESvsEE->cd(3);
            meESEERecHitsEnergy_zm   _->Draw();
            ESvsEE->cd(4);
            newmeESEERecHitsEnergy_zm_->Draw();
            myPV->PVCompute( meESEERecHitsEnergy_zm_ , newmeESEERecHitsEnergy_zm_ , te);
        }
        ESvsEE->Print("ESvsEE_compare.eps");
        delete ESvsEE;
    }


}
void FakePhotonSystematic(){
  
  TFile FMCRSSig("DsTolnu/SP1005Skim/DsReco/Final/HistosForFit.root");
  TFile FMCWSSig("DsTolnu/SP1005Skim/DsReco/FinalWS/HistosForFit.root");

  //TFile FMCRS("DsTolnu/MC/Final/HistosForFit.root");
  //TFile FMCWS("DsTolnu/MC/FinalWS/HistosForFit.root");
  TFile FMCRS("DsTolnu/SP1005Skim/DsReco/Final/HistosForFit.root");
  TFile FMCWS("DsTolnu/SP1005Skim/DsReco/FinalWS/HistosForFit.root");

  TFile FDataRS("DsTolnu/Data/Final/HistosForFit.root");
  TFile FDataWS("DsTolnu/Data/FinalWS/HistosForFit.root");

  

  TCanvas C;
  C.Clear();
  C.Print("FakePhotonSystematic.ps[");

  C.Clear();
  C.Divide(2,2);
  C.cd(1);  
//   TH1F* HMCRS=(TH1F*)FMCRS.Get("HEvtMultiplicity");
//   HMCRS->SetTitle(TString("MC RS =")+(long)HMCRS->GetMean()+"."+(long)(1000*(HMCRS->GetMean()-1.)));
//   HMCRS->Draw();
//   C.cd(2);
//   TH1F* HMCWS=(TH1F*)FMCWS.Get("HEvtMultiplicity");
//   HMCWS->SetTitle(TString("MC WS =")+(long)HMCWS->GetMean()+"."+(long)(1000*(HMCWS->GetMean()-1.)));
//   HMCWS->Draw();
  C.cd(3);  
  TH1F* HDataRS=(TH1F*)FDataRS.Get("HEvtMultiplicity");
  HDataRS->SetTitle(TString("Data RS =")+(long)HDataRS->GetMean()+"."+(long)(1000*(HDataRS->GetMean()-1.)));
  HDataRS->Draw();
  C.cd(4);
  TH1F* HDataWS=(TH1F*)FDataWS.Get("HEvtMultiplicity");
  HDataWS->SetTitle(TString("Data WS =")+(long)HDataWS->GetMean()+"."+(long)(1000*(HDataWS->GetMean()-1.)));
  HDataWS->Draw();
  C.Print("FakePhotonSystematic.ps");



  C.Clear();
  C.Divide(2,2);
  C.cd(1);  
  TH1F* HSigMCRS=(TH1F*)FMCRSSig.Get("HEvtMultiplicitySig");
  HSigMCRS->SetTitle(TString("MC Sig RS =")+(long)HSigMCRS->GetMean()+"."+(long)(1000*(HSigMCRS->GetMean()-1.)));
  HSigMCRS->Draw();
  C.cd(2);
  TH1F* HSigMCWS=(TH1F*)FMCWSSig.Get("HEvtMultiplicitySig");
  HSigMCWS->SetTitle(TString("MC Sig WS =")+(long)HSigMCWS->GetMean()+"."+(long)(1000*(HSigMCWS->GetMean()-1.)));
  HSigMCWS->Draw();
  C.cd(3);  
  TH1F* HBkgMCRS=(TH1F*)FMCRS.Get("HEvtMultiplicityBkg");
  HBkgMCRS->SetTitle(TString("MC Bkg RS =")+(long)HBkgMCRS->GetMean()+"."+(long)(1000*(HBkgMCRS->GetMean()-1.)));
  HBkgMCRS->Draw();
  C.cd(4);
  TH1F* HBkgMCWS=(TH1F*)FMCWS.Get("HEvtMultiplicityBkg");
  HBkgMCWS->SetTitle(TString("MC Bkg WS =")+(long)HBkgMCWS->GetMean()+"."+(long)(1000*(HBkgMCWS->GetMean()-1.)));
  HBkgMCWS->Draw();
  C.Print("FakePhotonSystematic.ps");
  
  C.Clear();
  THStack HMCStack("HMCStack","");
  HBkgMCRS->SetFillColor(1);HMCStack.Add(HBkgMCRS);
  HSigMCRS->SetFillColor(2);HSigMCRS->SetLineColor(2);HMCStack.Add(HSigMCRS);
  HMCStack.Draw();
  C.Print("FakePhotonSystematic.ps");

  //---------------------------------------------
  //subtract background from Data
  //---------------------------------------------
  TH1F*HDataRSBkg=(TH1F*)HDataWS->Clone("HDataRSBkg");
  TH1F*HBkgMCWSCl=(TH1F*)HBkgMCWS->Clone("HBkgMCWSCl");
  //need to fix the WS first by subtracting the signal component
  HSigMCWS->Scale(11350./HSigMCWS->Integral());//scale to number of WS signal events in Data
  HDataRSBkg->Add(HSigMCWS,-1);
  //construct correction ratio from MC to correct the WS distribution
  TH1F*HBkgMCRSCl=(TH1F*)HBkgMCRS->Clone("HBkgMCRSCl");
  HBkgMCWSCl->Scale(1./HBkgMCWSCl->Integral());
  HBkgMCRSCl->Scale(1./HBkgMCRSCl->Integral());
  TH1F*HBkgMCRatio=(TH1F*)HBkgMCRSCl->Clone("HBkgMCRatio");
  HBkgMCRatio->Divide(HBkgMCWSCl);
  C.Clear();
  delete HBkgMCRatio->FindObject("stats");
  HBkgMCRatio->SetFillColor(0);HBkgMCRatio->SetLineColor(1);
  HBkgMCRatio->SetStats(0);
  HBkgMCRatio->GetYaxis()->SetRangeUser(0,1.5);
  HBkgMCRatio->Draw("hist");
  C.Print("FakePhotonSystematic.ps");
  //correct the WS distribution
  HDataRSBkg->Multiply(HBkgMCRatio);
  C.Clear();
  HDataWS->Scale(1./HDataWS->Integral());
  HDataRSBkg->Scale(1./HDataRSBkg->Integral());
  delete HDataWS->FindObject("stats");
  HDataWS->SetTitle("");
  HDataWS->GetXaxis()->SetTitle("Reconstruction Multiplicity");
  HDataWS->Draw("p");
  HDataRSBkg->SetLineColor(0);
  HDataRSBkg->SetFillColor(4);
  HDataRSBkg->Draw("hist same");
  HDataWS->Draw("psame");
  C.Print("FakePhotonSystematic.ps");
  //scale Data WS up to Data RS bkg
  HDataRSBkg->Scale((6.9952e+05)/HDataRSBkg->Integral());//scale to number of Bkg events in data //+(106000*.06)modify bkg by initial guess on error of Signal .06 comes from a 10% increase in the fake photon yield
  C.Clear();
  HDataRS->GetYaxis()->SetRangeUser(0,HDataRS->GetMaximum()*1.3);
  HDataRS->GetXaxis()->SetTitle("Reconstruction Multiplicity");
  HDataRS->SetTitle("");
  HDataRS->Draw("pe");
  HDataRSBkg->SetFillColor(4);HDataRSBkg->SetLineColor(0);
  delete HDataRSBkg->FindObject("stats");
  HDataRSBkg->Draw("same");
  C.Print("FakePhotonSystematic.ps");

  //Perform subtraction
  TH1F*HDataRSCl=new TH1F("HDataRSCl","",HDataRS->GetXaxis()->GetNbins(),
			  HDataRS->GetXaxis()->GetXmin(),HDataRS->GetXaxis()->GetXmax());
  HDataRSCl->Add(HDataRS);
  Float_t Ntot=0,Nw=0;
  for(Int_t b=1;b<=HDataRSCl->GetXaxis()->GetNbins();b++){
    Nw+=HDataRSCl->GetBinContent(b)*HDataRSCl->GetBinCenter(b);
    Ntot+=HDataRSCl->GetBinContent(b);
  } 
  cout<<"before "<<HDataRSCl->GetMean()<<" "<<Nw/Ntot<<endl;
  delete HDataRSCl->FindObject("stats");
  HDataRSCl->Add(HDataRSBkg,-1);
  Ntot=0,Nw=0;
  for(Int_t b=1;b<=HDataRSCl->GetXaxis()->GetNbins();b++){
    Nw+=HDataRSCl->GetBinContent(b)*HDataRSCl->GetBinCenter(b);
    Ntot+=HDataRSCl->GetBinContent(b);
  } 
  cout<<"after "<<HDataRSCl->GetMean()<<" "<<Nw/Ntot<<endl;
  //compare Data signal to MC signal
  TH1F*HSigMCRSCl=(TH1F*)HSigMCRS->Clone("HSigMCRSCl");
  HSigMCRSCl->Scale(HDataRSCl->Integral()/HSigMCRSCl->Integral());
  HSigMCRSCl->SetFillColor(0);HSigMCRSCl->SetLineColor(1);
  C.Clear();  
  HDataRSCl->GetYaxis()->SetRangeUser(0,HDataRSCl->GetMaximum()*1.3);
  //HDataRSCl->SetTitle(TString("Data Sig =")+(long)(Nw/Ntot)+"."+(long)(1000*(Nw/Ntot-1.)));
  HDataRSCl->SetTitle("");
  HDataRSCl->GetXaxis()->SetTitle("Reconstruction Multiplicity");
  delete HDataRSCl->FindObject("stats");
  HDataRSCl->SetStats(0);
  HDataRSCl->Draw("pe");
  HSigMCRSCl->SetStats(0);
  HSigMCRSCl->Draw("same");
  C.Print("FakePhotonSystematic.ps");

  TH1F*HDataSigMCSigDiff=new TH1F("HDataSigMCSigDiff","",HDataRS->GetXaxis()->GetNbins(),
			  HDataRS->GetXaxis()->GetXmin(),HDataRS->GetXaxis()->GetXmax());
  HDataSigMCSigDiff->Add(HDataRSCl);
  HDataSigMCSigDiff->Add(HSigMCRSCl,-1);
  C.Clear();
  delete HDataSigMCSigDiff->FindObject("stats");
  HDataSigMCSigDiff->SetStats(0);
  HDataSigMCSigDiff->Draw("");
  C.Print("FakePhotonSystematic.ps");


  //Signal multiplicity for modified photon backgrounds
  C.Clear();
  HSigMCRSCl->SetFillColor(0);HSigMCRSCl->SetLineColor(1);
  HSigMCRSCl->GetYaxis()->SetRangeUser(0,HSigMCRSCl->GetMaximum()*1.1);
  HSigMCRSCl->GetXaxis()->SetRangeUser(.5,3.5);
  HSigMCRSCl->SetStats(0);
  HSigMCRSCl->Draw("l"); 
  TGraph GMult;
  Int_t npts=0;
  TH1F* HDiff[21];
  TH1F* HSigMCRSMod[21];
  for(Int_t m=0;m<11;m++){
    HSigMCRSMod[m]=(TH1F*)FMCRSSig.Get(TString("HEvtMultiplicitySigMod")+(long)m);    
    if(HSigMCRSMod[m]->Integral()>0){
      GMult.SetPoint(npts,1+(m-10)*.01,HSigMCRSMod[m]->GetMean()); 
      npts++;
      HSigMCRSMod[m]->Scale(HDataRSCl->Integral()/HSigMCRSMod[m]->Integral());
    }
    HSigMCRSMod[m]->SetLineColor(4);
    HSigMCRSMod[m]->SetStats(0);
    HSigMCRSMod[m]->Draw("lsame");
    HDiff[m]=(TH1F*)HSigMCRSMod[m]->Clone(TString("HEvtMultiplicitySigModCl")+(long)m);
    HDiff[m]->Add(HSigMCRSCl,-1);
  }
  HSigMCRSCl->Draw("lsame");
  HDataRSCl->SetLineColor(2);
  HDataRSCl->SetStats(0);
  HDataRSCl->Draw("lsame");
  C.Print("FakePhotonSystematic.ps");

  //fix the multiplicity on the plus side 
  GMult.SetPoint(npts,1.1,HSigMCRSMod[10]->GetMean()+(HSigMCRSMod[10]->GetMean()-HSigMCRSMod[0]->GetMean()));
    

  TH1F* HDataDiff=(TH1F*)HDataRSCl->Clone("HDataDiff");
  HDataDiff->Add(HSigMCRSCl,-1);
  TH1F* HMCDiff=(TH1F*)HSigMCRSCl->Clone("HMCDiff");
  HMCDiff->Add(HSigMCRSCl,-1);
  C.Clear();
  HMCDiff->GetYaxis()->SetRangeUser(-6000,3000);
  HMCDiff->Draw("l");
  for(Int_t m=0;m<11;m++) HDiff[m]->Draw("lsame");
  HMCDiff->Draw("lsame");
  HDataDiff->Draw("lsame");
  C.Print("FakePhotonSystematic.ps");
  
  GMult.GetXaxis()->SetTitle("Amount of Fake Photon Background");
  GMult.GetYaxis()->SetTitle("Avg. Reconstruction Multiplicity");

  C.Clear();  //just the map
  GMult.Draw("apl");
  C.Print("FakePhotonSystematic.ps");

  //no Data error
  C.Clear();
  GMult.Draw("apl");
  TLine line;
  line.SetLineColor(2);  line.SetLineWidth(2);
  line.DrawLine(.9,Nw/Ntot,1.1,Nw/Ntot);
  C.Print("FakePhotonSystematic.ps");

  //with Data error
  C.Clear();
  GMult.Draw("apl");
  TBox box;
  box.SetLineColor(0);
  box.SetFillColor(3);
  box.SetFillStyle(1001);
  box.DrawBox(.9,Nw/Ntot-(1.769-1.763),1.1,Nw/Ntot+(1.769-1.763));
  line.DrawLine(.9,Nw/Ntot,1.1,Nw/Ntot);
  GMult.Draw("plsame");
  C.Print("FakePhotonSystematic.ps");

  C.Print("FakePhotonSystematic.ps]");

}
Пример #16
0
void analysis() {
    Int_t nbins = 800;
    Int_t j;
    char name[20];
    char title[100];
    TH1F *HistoEvent[2214];
    for (Int_t z=0;z<2214;z++) {
        sprintf(name,"HistoEvent%d",z-1);
        sprintf(title,"Event%d Histo", z-1);
        HistoEvent[z] = new TH1F(name,title,nbins, -0.1, 159.9);
    }
    TH1F *NewHistoEvent[2214];
    for (Int_t z=0;z<2214;z++) {
        sprintf(name,"NewHistoEvent%d",z-1);
        sprintf(title,"Event%d Histo", z-1);
        NewHistoEvent[z] = new TH1F(name,title,nbins, -0.1, 159.9);
    }
    TH1F *NewHistoEventFFT[2214];
    for (Int_t z=0;z<2214;z++) {
        sprintf(name,"NewHistoEventFFT%d",z-1);
        sprintf(title,"Event%d Histo", z-1);
        NewHistoEventFFT[z] = new TH1F(name,title,nbins, 0, 5);
    }
    Double_t mean;
    Double_t rms;
    Double_t meansum = 0;
    Double_t count = 0;
    Double_t meanrms = 0;
	TFile f("/home/marko/H4Analysis/ntuples/analysis_4443.root"); //ntuple generated by H4Analysis tool
	TFile f1("/home/marko/H4Analysis/ntuples/analysis_3905.root");
    TFile f2("/home/marko/Desktop/TB Timing Res/NormalizedSignalNoise.root", "read");
    TH1F* BestSignal = (TH1F*) f2.Get("BetterSignal");
    TFile outputfile("myoutput.root", "recreate");
    TCanvas* TimeandFreq = new TCanvas("TimeandFreq","Time and Frequency",1500,900);
    TCanvas* Freq = new TCanvas("Freq","Frequency",800,1200);
    TCanvas* TimeSignal = new TCanvas("TimeSignal","Pure Signal",800,1200);
	TimeandFreq->Divide(2,2);
	TTree* h4 = (TTree*) f.Get("h4");
    TTree* h4_2 = (TTree*) f1.Get("h4");
    TString plot;
    TString cut;
	TH2F* WavePulse = new TH2F ("WavePulse", "Wave Pulse", nbins, -0.1, 159.9, 850, -50, 800);
    TH2F* NoisePulse = new TH2F ("NoisePulse", "Noise", nbins, -0.1, 159.9, 100, -50, 50);
    TH1F* PulseTime = new TH1F ("PulseTime", "Original Wave Pulse", nbins, -0.1, 159.9); //nanoseconds
    TH2F* TempHisto = new TH2F ("TempHisto", "Temp Histo", nbins, -0.1, 159.9, 1000, -15, 15); //nanoseconds
	h4->Draw("WF_val:WF_time>>WavePulse", "WF_ch==2 && event==1 && spill==1");
    h4_2->Draw("WF_val:WF_time>>NoisePulse","WF_ch==APD1 && amp_max[APD3]<25 && b_rms[APD3]<5. && charge_tot[APD3]<20000 &&  amp_max[APD5]<25 && b_rms[APD5]<5. &&  amp_max[APD6]<25 && b_rms[APD6]<5. &&  amp_max[APD4]<25 && b_rms[APD4]<5. && amp_max[SiPM1]<20 && amp_max[SiPM2]<20 && amp_max[APD1]<40 && amp_max[APD2]<40 && b_rms[APD1]<5. && b_rms[APD2]<5. && WF_time<160");
    for (Int_t i=0; i<nbins; i++) {
		for (Int_t k=0; k<4096; k++) {
			if (WavePulse->GetBinContent(i+1, k) != 0) {
				PulseTime->SetBinContent(i+1,k-50);
			}
		}
	}
    TH1F *NoiseTime = new TH1F ("NoiseTime", "Noise", nbins, -0.1, 159.9);
    for (Int_t i=0; i<nbins; i++) {
        for (Int_t k=0; k<4096; k++) {
            if (NoisePulse->GetBinContent(i+1, k) != 0) {
                NoiseTime->SetBinContent(i+1,k-62.9087);
            }
        }
    }
    //TH1F* NormNoiseFFT = new TH1F ("NormNoiseFFT", "Normalized Noise FFT", nbins, 0, 5);
    //TStopwatch t;
    //t.Start(); //1 hour runtime
    //for (j=10;j<20;j++) {
    //    plot = "WF_val:WF_time>>TempHisto";
    //    cut = "WF_ch==APD1 && amp_max[APD3]<25 && b_rms[APD3]<5. && charge_tot[APD3]<20000 &&  amp_max[APD5]<25 && b_rms[APD5]<5. &&  amp_max[APD6]<25 && b_rms[APD6]<5. &&  amp_max[APD4]<25 && b_rms[APD4]<5. && amp_max[SiPM1]<20 && amp_max[SiPM2]<20 && amp_max[APD1]<40 && amp_max[APD2]<40 && b_rms[APD1]<5. && b_rms[APD2]<5. && WF_time<160 && event==";
    //    cut += j;
    //    h4_2->Draw(plot, cut, "goff");
    //    if (TempHisto->GetMaximum() == 0) {
    //        delete HistoEvent[j+1];
    //        continue;
    //    }
    //    for (Int_t i=0; i<nbins; i++) {
    //        for (Int_t k=0; k<1000; k++) {
    //            if (TempHisto->GetBinContent(i+1, k) != 0) {
    //                HistoEvent[j+1]->SetBinContent(i+1,k*0.03-15);
    //            }
    //        }
    //    }
    //    mean = TempHisto->GetMean(2);
    //    rms = TempHisto->GetRMS(2);
    //    for (Int_t q=0;q<nbins;q++) {
    //        NewHistoEvent[j+1]->SetBinContent(q+1, HistoEvent[j+1]->GetBinContent(q+1)-mean);
    //    }
    //    NewHistoEvent[j+1]->Scale(1/rms);
    //    NewHistoEvent[j+1]->FFT(NewHistoEventFFT[j+1], "MAG");
    //    NormNoiseFFT->Add(NormNoiseFFT, NewHistoEventFFT[j+1]);
    //    TempHisto->Write();
    //    NewHistoEvent[j+1]->Write();
    //    NewHistoEventFFT[j+1]->Write();
    //    cout << "Event " << j << ", Mean = " << mean << ", RMS = " << rms << endl;
    //    count += 1;
    //}
    //NormNoiseFFT->Scale(1/count);
    //NormNoiseFFT->Write();
    //t.Stop();
    //t.Print();
	new TFile("/home/marko/H4Analysis/ntuples/analysis_4443.root"); // ignore this reloading of the same file, it is required or else the plots do not show up (when I tried)
    TimeandFreq->cd(1);
    PulseTime->GetXaxis()->SetTitle("Time (ns)");
    PulseTime->GetYaxis()->SetTitle("Amplitude");
    PulseTime->DrawClone(); //Wave Pulse in Time domain
    TimeandFreq->cd(2);
    TH1F* PulseFreq = new TH1F ("PulseFreq", "Pulse FFT", nbins, 0, 5);
    TH1F* PulsePhase = new TH1F ("PulsePhase", "Pulse Phase", nbins, -0.1, 799.9);
    PulseTime->FFT(PulseFreq, "MAG");
    PulseTime->FFT(PulsePhase, "PH");
    PulseFreq->SetLineColor(kRed);
    PulseFreq->GetXaxis()->SetTitle("Frequency (GHz)");
    PulseFreq->GetYaxis()->SetTitle("Amplitude");
    PulseFreq->DrawClone(); //Wave Pulse in Frequency domain
    gPad->SetLogy();
    TimeandFreq->cd(3);
    NoiseTime->GetXaxis()->SetTitle("Time (ns)");
    NoiseTime->GetYaxis()->SetTitle("Amplitude");
    NoiseTime->DrawClone(); // Noise from pedestal in Time domain
    TimeandFreq->cd(4);
    TH1F* NoiseFreq = new TH1F ("NoiseFreq", "Noise FFT", nbins, 0, 5);
    NoiseTime->FFT(NoiseFreq, "MAG");
    NoiseFreq->GetXaxis()->SetTitle("Frequency (GHz)");
    NoiseFreq->GetYaxis()->SetTitle("Amplitude");
    NoiseFreq->Draw(); // Noise from pedestal in Frequency domain
    gPad->SetLogy();
    Freq->Divide(1,3);
    Freq->cd(1);
    PulseFreq->DrawClone();
    gPad->SetLogy();
    Freq->cd(2);
    NoiseFreq->DrawClone();
    gPad->SetLogy();
    Freq->cd(3);
    PulseFreq->SetTitle("Pulse and Noise FFT Comparison");
    PulseFreq->Draw();
    NoiseFreq->Draw("same");
    gPad->SetLogy();
    TH1F* UnscaledSignalFreq = new TH1F ("UnscaledSignalFreq", "Unscaled Signal Frequency", nbins, -0.1, 799.9);
    for (Int_t l=0; l<nbins; l++) {
        UnscaledSignalFreq->SetBinContent(l+1, (PulseFreq->GetBinContent(l+1)-NoiseFreq->GetBinContent(l+1))/PulseFreq->GetBinContent(l+1));
    }
    TH1F* SignalFreq = new TH1F ("SignalFreq", "Signal Frequency", nbins, 0, 799.9);
    for (Int_t m=0; m<nbins; m++) {
        SignalFreq->SetBinContent(m+1, UnscaledSignalFreq->GetBinContent(m+1)*PulseFreq->GetBinContent(m+1));
    }
    Double_t *re_full = new Double_t[nbins];
    Double_t *im_full = new Double_t[nbins];
    for (Int_t n=0; n<nbins; n++) {
        (re_full)[n]=(SignalFreq->GetBinContent(n+1)*cos(PulsePhase->GetBinContent(n+1)));
        (im_full)[n]=(SignalFreq->GetBinContent(n+1)*sin(PulsePhase->GetBinContent(n+1)));
    }
    TVirtualFFT *invFFT = TVirtualFFT::FFT(1, &nbins, "C2R M K");
    invFFT->SetPointsComplex(re_full, im_full);
    invFFT->Transform();
    TH1 *Signal = 0;
    Signal = TH1::TransformHisto(invFFT,Signal,"Re");
    Signal->SetTitle("Recovered Signal 'S'");
    TH1F* BetterSignal = new TH1F ("BetterSignal", "Recovered Signal", nbins, -0.1, 159.9);
    for (Int_t p=0; p<nbins; p++) {
        BetterSignal->SetBinContent(p+1, Signal->GetBinContent(p+1)/nbins);
    }
    TimeSignal->Divide(1,2);
    TimeSignal->cd(1);
    PulseTime->DrawClone(); //Original Wave Pulse
    TimeSignal->cd(2);
    BetterSignal->GetXaxis()->SetTitle("Time (ns)");
    BetterSignal->GetYaxis()->SetTitle("Amplitude");
    BetterSignal->SetLineColor(kRed);
    //BetterSignal->Draw(); // Recovered Wave Pulse with decreased contribution from background noise
    BestSignal->SetLineColor(kGreen);
    BestSignal->DrawClone("same");
    PulseTime->DrawClone("same");
}
Пример #17
0
void SiStripRecHitsPlots()
{

 gROOT ->Reset();
 gStyle->SetOptStat(1111111);
 char*  rfilename = "sistriprechitshisto.root";

 delete gROOT->GetListOfFiles()->FindObject(rfilename);

 TText* te = new TText();
 TFile * rfile = new TFile(rfilename);
 Char_t histo[200];

 rfile->cd("DQMData/TrackerRecHits/Strip");
 gDirectory->ls();

 //reference files here
 // rfile->cd("")



////////////////////////////////////
//            TIB                 //
////////////////////////////////////

 rfile->cd("DQMData/TrackerRecHits/Strip/TIB");

 TCanvas * SiStrip = new TCanvas("SiStrip","SiStrip");
 SiStrip->Divide(2,3);
 SiStrip->cd(1);
 Adc_rphi_layer1tib->Draw();
 SiStrip->cd(2);
 Adc_rphi_layer2tib->Draw();
 SiStrip->cd(3);
 Adc_rphi_layer3tib->Draw();
 SiStrip->cd(4);
 Adc_rphi_layer4tib->Draw();
 SiStrip->cd(5);
 Adc_sas_layer1tib->Draw();
 SiStrip->cd(6);
 Adc_sas_layer2tib->Draw();
 
 SiStrip->Print("AdcOfTIB.eps");

 TCanvas * SiStrip = new TCanvas("SiStrip","SiStrip");
 SiStrip->Divide(2,3);
 SiStrip->cd(1);
 Nstp_rphi_layer1tib->Draw();
 SiStrip->cd(2);
 Nstp_rphi_layer2tib->Draw();
 SiStrip->cd(3);
 Nstp_rphi_layer3tib->Draw();
 SiStrip->cd(4);
 Nstp_rphi_layer4tib->Draw();
 SiStrip->cd(5);
 Nstp_sas_layer1tib->Draw();
 SiStrip->cd(6);
 Nstp_sas_layer2tib->Draw();
 
 SiStrip->Print("NstpOfTIB.eps");
   
 TCanvas * SiStrip = new TCanvas("SiStrip","SiStrip");
 SiStrip->Divide(2,3);
 SiStrip->cd(1);
 Posx_rphi_layer1tib->Draw();
 SiStrip->cd(2);
 Posx_rphi_layer2tib->Draw();
 SiStrip->cd(3);
 Posx_rphi_layer3tib->Draw();
 SiStrip->cd(4);
 Posx_rphi_layer4tib->Draw();
 SiStrip->cd(5);
 Posx_sas_layer1tib->Draw();
 SiStrip->cd(6);
 Posx_sas_layer2tib->Draw();
 
 SiStrip->Print("PosOfTIB.eps");

 TCanvas * SiStrip = new TCanvas("SiStrip","SiStrip");

 SiStrip->Divide(2,3);
 SiStrip->cd(1);
 Errx_rphi_layer1tib->Draw();
 SiStrip->cd(2);
 Errx_rphi_layer2tib->Draw();
 SiStrip->cd(3);
 Errx_rphi_layer3tib->Draw();
 SiStrip->cd(4);
 Errx_rphi_layer4tib->Draw();
 SiStrip->cd(5);
 Errx_sas_layer1tib->Draw();
 SiStrip->cd(6);
 Errx_sas_layer2tib->Draw();
 
 SiStrip->Print("ErrOfTIB.eps");

 TCanvas * SiStrip = new TCanvas("SiStrip","SiStrip");

 SiStrip->Divide(2,3);
 SiStrip->cd(1);
 Res_rphi_layer1tib->Draw();
 SiStrip->cd(2);
 Res_rphi_layer2tib->Draw();
 SiStrip->cd(3);
 Res_rphi_layer3tib->Draw();
 SiStrip->cd(4);
 Res_rphi_layer4tib->Draw();
 SiStrip->cd(5);
 Res_sas_layer1tib->Draw();
 SiStrip->cd(6);
 Res_sas_layer2tib->Draw();
 
 SiStrip->Print("ResOfTIB.eps");

 TCanvas * SiStrip = new TCanvas("SiStrip","SiStrip");
 SiStrip->Divide(2,3);
 SiStrip->cd(1);
 Pull_LF_rphi_layer1tib->Draw();
 SiStrip->cd(2);
 Pull_LF_rphi_layer2tib->Draw();
 SiStrip->cd(3);
 Pull_LF_rphi_layer3tib->Draw();
 SiStrip->cd(4);
 Pull_LF_rphi_layer4tib->Draw();
 SiStrip->cd(5);
 Pull_LF_sas_layer1tib->Draw();
 SiStrip->cd(6);
 Pull_LF_sas_layer2tib->Draw();

 SiStrip->Print("PullLFOfTIB.eps");

 TCanvas * SiStrip = new TCanvas("SiStrip","SiStrip");
 SiStrip->Divide(2,3);
 SiStrip->cd(1);
 Pull_MF_rphi_layer1tib->Draw();
 SiStrip->cd(2);
 Pull_MF_rphi_layer2tib->Draw();
 SiStrip->cd(3);
 Pull_MF_rphi_layer3tib->Draw();
 SiStrip->cd(4);
 Pull_MF_rphi_layer4tib->Draw();
 SiStrip->cd(5);
 Pull_MF_sas_layer1tib->Draw();
 SiStrip->cd(6);
 Pull_MF_sas_layer2tib->Draw();
 SiStrip->Print("PullMFOfTIB.eps");

 TCanvas * SiStrip = new TCanvas("SiStrip","SiStrip");

 SiStrip->Divide(2,3);
 SiStrip->cd(1);
 Chi2_rphi_layer1tib->Draw();
 SiStrip->cd(2);
 Chi2_rphi_layer2tib->Draw();
 SiStrip->cd(3);
 Chi2_rphi_layer3tib->Draw();
 SiStrip->cd(4);
 Chi2_rphi_layer4tib->Draw();
 SiStrip->cd(5);
 Chi2_sas_layer1tib->Draw();
 SiStrip->cd(6);
 Chi2_sas_layer2tib->Draw();
 
 SiStrip->Print("Chi2OfTIB.eps");

 TCanvas * SiStrip = new TCanvas("SiStrip","SiStrip");
 SiStrip->Divide(3,3);
 SiStrip->cd(1);
 Posx_matched_layer1tib->Draw();
 SiStrip->cd(2);
 Posy_matched_layer1tib->Draw();
 SiStrip->cd(3);
 Posx_matched_layer2tib->Draw();
 SiStrip->cd(4);
 Posy_matched_layer2tib->Draw();
 SiStrip->cd(5);
 Errx_matched_layer1tib->Draw();
 SiStrip->cd(6);
 Erry_matched_layer1tib->Draw();
 SiStrip->cd(7);
 Errx_matched_layer2tib->Draw();
 SiStrip->cd(8);
 Erry_matched_layer2tib->Draw();
   
 SiStrip->Print("MatchedOfTIB.eps");

 TCanvas * SiStrip = new TCanvas("SiStrip","SiStrip");
 SiStrip->Divide(3,2);

 SiStrip->cd(1);
 Resx_matched_layer1tib->Draw();
 SiStrip->cd(2);
 Resy_matched_layer1tib->Draw();
 SiStrip->cd(3);
 Chi2_matched_layer1tib->Draw();
 SiStrip->cd(4);
 Resx_matched_layer2tib->Draw();
 SiStrip->cd(5);
 Resy_matched_layer2tib->Draw();
 SiStrip->cd(6);
 Chi2_matched_layer2tib->Draw();

 SiStrip->Print("MatchedResOfTIB.eps");


////////////////////////////////////
//            TOB                 //
////////////////////////////////////


 rfile->cd("DQMData/TrackerRecHits/Strip/TOB");

 TCanvas * SiStrip = new TCanvas("SiStrip","SiStrip");
 SiStrip->Divide(3,3);
 SiStrip->cd(1);
 Adc_rphi_layer1tob->Draw();
 SiStrip->cd(2);
 Adc_rphi_layer2tob->Draw();
 SiStrip->cd(3);
 Adc_rphi_layer3tob->Draw();
 SiStrip->cd(4);
 Adc_rphi_layer4tob->Draw();
 SiStrip->cd(5);
 Adc_rphi_layer5tob->Draw();
 SiStrip->cd(6);
 Adc_rphi_layer6tob->Draw();
 SiStrip->cd(7);
 Adc_sas_layer1tob->Draw();
 SiStrip->cd(8);
 Adc_sas_layer2tob->Draw();
 
 SiStrip->Print("AdcOfTOB.eps");

 TCanvas * SiStrip = new TCanvas("SiStrip","SiStrip");
 SiStrip->Divide(3,3);
 SiStrip->cd(1);
 Nstp_rphi_layer1tob->Draw();
 SiStrip->cd(2);
 Nstp_rphi_layer2tob->Draw();
 SiStrip->cd(3);
 Nstp_rphi_layer3tob->Draw();
 SiStrip->cd(4);
 Nstp_rphi_layer4tob->Draw();
 SiStrip->cd(5);
 Nstp_rphi_layer5tob->Draw();
 SiStrip->cd(6);
 Nstp_rphi_layer6tob->Draw();
 SiStrip->cd(7);
 Nstp_sas_layer1tob->Draw();
 SiStrip->cd(8);
 Nstp_sas_layer2tob->Draw();
 
 SiStrip->Print("NstpOfTOB.eps");
   
 TCanvas * SiStrip = new TCanvas("SiStrip","SiStrip");
 SiStrip->Divide(3,3);
 SiStrip->cd(1);
 Posx_rphi_layer1tob->Draw();
 SiStrip->cd(2);
 Posx_rphi_layer2tob->Draw();
 SiStrip->cd(3);
 Posx_rphi_layer3tob->Draw();
 SiStrip->cd(4);
 Posx_rphi_layer4tob->Draw();
 SiStrip->cd(5);
 Posx_rphi_layer5tob->Draw();
 SiStrip->cd(6);
 Posx_rphi_layer6tob->Draw();
 SiStrip->cd(7);
 Posx_sas_layer1tob->Draw();
 SiStrip->cd(8);
 Posx_sas_layer2tob->Draw();
 
 SiStrip->Print("PosOfTOB.eps");

 TCanvas * SiStrip = new TCanvas("SiStrip","SiStrip");

 SiStrip->Divide(3,3);
 SiStrip->cd(1);
 Errx_rphi_layer1tob->Draw();
 SiStrip->cd(2);
 Errx_rphi_layer2tob->Draw();
 SiStrip->cd(3);
 Errx_rphi_layer3tob->Draw();
 SiStrip->cd(4);
 Errx_rphi_layer4tob->Draw();
 SiStrip->cd(5);
 Errx_rphi_layer5tob->Draw();
 SiStrip->cd(6);
 Errx_rphi_layer6tob->Draw();
 SiStrip->cd(7);
 Errx_sas_layer1tob->Draw();
 SiStrip->cd(8);
 Errx_sas_layer2tob->Draw();
 
 SiStrip->Print("ErrOfTOB.eps");

 TCanvas * SiStrip = new TCanvas("SiStrip","SiStrip");

 SiStrip->Divide(3,3);
 SiStrip->cd(1);
 Res_rphi_layer1tob->Draw();
 SiStrip->cd(2);
 Res_rphi_layer2tob->Draw();
 SiStrip->cd(3);
 Res_rphi_layer3tob->Draw();
 SiStrip->cd(4);
 Res_rphi_layer4tob->Draw();
 SiStrip->cd(5);
 Res_rphi_layer5tob->Draw();
 SiStrip->cd(6);
 Res_rphi_layer6tob->Draw();
 SiStrip->cd(7);
 Res_sas_layer1tob->Draw();
 SiStrip->cd(8);
 Res_sas_layer2tob->Draw();
 
 SiStrip->Print("ResOfTOB.eps");

 TCanvas * SiStrip = new TCanvas("SiStrip","SiStrip");
 SiStrip->Divide(3,3);
 SiStrip->cd(1);
 Pull_LF_rphi_layer1tob->Draw();
 SiStrip->cd(2);
 Pull_LF_rphi_layer2tob->Draw();
 SiStrip->cd(3);
 Pull_LF_rphi_layer3tob->Draw();
 SiStrip->cd(4);
 Pull_LF_rphi_layer4tob->Draw();
 SiStrip->cd(5);
 Pull_LF_rphi_layer5tob->Draw();
 SiStrip->cd(6);
 Pull_LF_rphi_layer6tob->Draw();
 SiStrip->cd(7);
 Pull_LF_sas_layer1tob->Draw();
 SiStrip->cd(8);
 Pull_LF_sas_layer2tob->Draw();
 SiStrip->Print("PullLFOfTOB.eps");

TCanvas * SiStrip = new TCanvas("SiStrip","SiStrip");
 SiStrip->Divide(3,3);
 SiStrip->cd(1);
 Pull_MF_rphi_layer1tob->Draw();
 SiStrip->cd(2);
 Pull_MF_rphi_layer2tob->Draw();
 SiStrip->cd(3);
 Pull_MF_rphi_layer3tob->Draw();
 SiStrip->cd(4);
 Pull_MF_rphi_layer4tob->Draw();
 SiStrip->cd(5);
 Pull_MF_rphi_layer5tob->Draw();
 SiStrip->cd(6);
 Pull_MF_rphi_layer6tob->Draw();
 SiStrip->cd(7);
 Pull_MF_sas_layer1tob->Draw();
 SiStrip->cd(8);
 Pull_MF_sas_layer2tob->Draw();
 SiStrip->Print("PullMFOfTOB.eps");
 TCanvas * SiStrip = new TCanvas("SiStrip","SiStrip");

 SiStrip->Divide(3,3);
 SiStrip->cd(1);
 Chi2_rphi_layer1tob->Draw();
 SiStrip->cd(2);
 Chi2_rphi_layer2tob->Draw();
 SiStrip->cd(3);
 Chi2_rphi_layer3tob->Draw();
 SiStrip->cd(4);
 Chi2_rphi_layer4tob->Draw();
 SiStrip->cd(5);
 Chi2_rphi_layer5tob->Draw();
 SiStrip->cd(6);
 Chi2_rphi_layer6tob->Draw();
 SiStrip->cd(7);
 Chi2_sas_layer1tob->Draw();
 SiStrip->cd(8);
 Chi2_sas_layer2tob->Draw();
 
 SiStrip->Print("Chi2OfTOB.eps");

 TCanvas * SiStrip = new TCanvas("SiStrip","SiStrip");
 SiStrip->Divide(3,3);
 SiStrip->cd(1);
 Posx_matched_layer1tob->Draw();
 SiStrip->cd(2);
 Posy_matched_layer1tob->Draw();
 SiStrip->cd(3);
 Posx_matched_layer2tob->Draw();
 SiStrip->cd(4);
 Posy_matched_layer2tob->Draw();
 SiStrip->cd(5);
 Errx_matched_layer1tob->Draw();
 SiStrip->cd(6);
 Erry_matched_layer1tob->Draw();
 SiStrip->cd(7);
 Errx_matched_layer2tob->Draw();
 SiStrip->cd(8);
 Erry_matched_layer2tob->Draw();
   
 SiStrip->Print("MatchedOfTOB.eps");

 TCanvas * SiStrip = new TCanvas("SiStrip","SiStrip");
 SiStrip->Divide(3,2);
 SiStrip->cd(1);
 Resx_matched_layer1tob->Draw();
 SiStrip->cd(2);
 Resy_matched_layer1tob->Draw();
 SiStrip->cd(3);
 Chi2_matched_layer1tob->Draw();
 SiStrip->cd(4);
 Resx_matched_layer2tob->Draw();
 SiStrip->cd(5);
 Resy_matched_layer2tob->Draw();
 SiStrip->cd(6);
 Chi2_matched_layer2tob->Draw();
 
 SiStrip->Print("MatchedResOfTOB.eps");

////////////////////////////////////
//            TID                 //
////////////////////////////////////

 rfile->cd("DQMData/TrackerRecHits/Strip/TID");

 TCanvas * SiStrip = new TCanvas("SiStrip","SiStrip");
 SiStrip->Divide(3,2);
 SiStrip->cd(1);
 Adc_rphi_layer1tid->Draw();
 SiStrip->cd(2);
 Adc_rphi_layer2tid->Draw();
 SiStrip->cd(3);
 Adc_rphi_layer3tid->Draw();
 SiStrip->cd(4);
 Adc_sas_layer1tid->Draw();
 SiStrip->cd(5);
 Adc_sas_layer2tid->Draw();
 
 SiStrip->Print("AdcOfTID.eps");

 TCanvas * SiStrip = new TCanvas("SiStrip","SiStrip");
 SiStrip->Divide(3,2);
 SiStrip->cd(1);
 Nstp_rphi_layer1tid->Draw();
 SiStrip->cd(2);
 Nstp_rphi_layer2tid->Draw();
 SiStrip->cd(3);
 Nstp_rphi_layer3tid->Draw();
 SiStrip->cd(4);
 Nstp_sas_layer1tid->Draw();
 SiStrip->cd(5);
 Nstp_sas_layer2tid->Draw();
 
 SiStrip->Print("NstpOfTID.eps");
   
 TCanvas * SiStrip = new TCanvas("SiStrip","SiStrip");
 SiStrip->Divide(3,2);
 SiStrip->cd(1);
 Posx_rphi_layer1tid->Draw();
 SiStrip->cd(2);
 Posx_rphi_layer2tid->Draw();
 SiStrip->cd(3);
 Posx_rphi_layer3tid->Draw();
 SiStrip->cd(4);
 Posx_sas_layer1tid->Draw();
 SiStrip->cd(5);
 Posx_sas_layer2tid->Draw();
 
 SiStrip->Print("PosOfTID.eps");

 TCanvas * SiStrip = new TCanvas("SiStrip","SiStrip");

 SiStrip->Divide(3,2);
 SiStrip->cd(1);
 Errx_rphi_layer1tid->Draw();
 SiStrip->cd(2);
 Errx_rphi_layer2tid->Draw();
 SiStrip->cd(3);
 Errx_rphi_layer3tid->Draw();
 SiStrip->cd(4);
 Errx_sas_layer1tid->Draw();
 SiStrip->cd(5);
 Errx_sas_layer2tid->Draw();
 
 SiStrip->Print("ErrOfTID.eps");

 TCanvas * SiStrip = new TCanvas("SiStrip","SiStrip");

 SiStrip->Divide(3,2);
 SiStrip->cd(1);
 Res_rphi_layer1tid->Draw();
 SiStrip->cd(2);
 Res_rphi_layer2tid->Draw();
 SiStrip->cd(3);
 Res_rphi_layer3tid->Draw();
 SiStrip->cd(4);
 Res_sas_layer1tid->Draw();
 SiStrip->cd(5);
 Res_sas_layer2tid->Draw();
 
 SiStrip->Print("ResOfTID.eps");

 TCanvas * SiStrip = new TCanvas("SiStrip","SiStrip");
 SiStrip->Divide(3,2);
 SiStrip->cd(1);
 Pull_LF_rphi_layer1tid->Draw();
 SiStrip->cd(2);
 Pull_LF_rphi_layer2tid->Draw();
 SiStrip->cd(3);
 Pull_LF_rphi_layer3tid->Draw();
 SiStrip->cd(4);
 Pull_LF_sas_layer1tid->Draw();
 SiStrip->cd(5);
 Pull_LF_sas_layer2tid->Draw();
 SiStrip->Print("PullLFOfTID.eps");

 TCanvas * SiStrip = new TCanvas("SiStrip","SiStrip");
 SiStrip->Divide(3,2);
 SiStrip->cd(1);
 Pull_MF_rphi_layer1tid->Draw();
 SiStrip->cd(2);
 Pull_MF_rphi_layer2tid->Draw();
 SiStrip->cd(3);
 Pull_MF_rphi_layer3tid->Draw();
 SiStrip->cd(4);
 Pull_MF_sas_layer1tid->Draw();
 SiStrip->cd(5);
 Pull_MF_sas_layer2tid->Draw();
 SiStrip->Print("PullMFOfTID.eps");

 TCanvas * SiStrip = new TCanvas("SiStrip","SiStrip");

 SiStrip->Divide(3,2);
 SiStrip->cd(1);
 Chi2_rphi_layer1tid->Draw();
 SiStrip->cd(2);
 Chi2_rphi_layer2tid->Draw();
 SiStrip->cd(3);
 Chi2_rphi_layer3tid->Draw();
 SiStrip->cd(4);
 Chi2_sas_layer1tid->Draw();
 SiStrip->cd(5);
 Chi2_sas_layer2tid->Draw();
 
 SiStrip->Print("Chi2OfTID.eps");

 TCanvas * SiStrip = new TCanvas("SiStrip","SiStrip");
 SiStrip->Divide(3,3);
 SiStrip->cd(1);
 Posx_matched_layer1tid->Draw();
 SiStrip->cd(2);
 Posy_matched_layer1tid->Draw();
 SiStrip->cd(3);
 Posx_matched_layer2tid->Draw();
 SiStrip->cd(4);
 Posy_matched_layer2tid->Draw();
 SiStrip->cd(5);
 Errx_matched_layer1tid->Draw();
 SiStrip->cd(6);
 Erry_matched_layer1tid->Draw();
 SiStrip->cd(7);
 Errx_matched_layer2tid->Draw();
 SiStrip->cd(8);
 Erry_matched_layer2tid->Draw();
   
 SiStrip->Print("MatchedOfTID.eps");

 TCanvas * SiStrip = new TCanvas("SiStrip","SiStrip");
 SiStrip->Divide(3,2);
 SiStrip->cd(1);
 Resx_matched_layer1tid->Draw();
 SiStrip->cd(2);
 Resy_matched_layer1tid->Draw();
 SiStrip->cd(3);
 Chi2_matched_layer1tid->Draw();
 SiStrip->cd(4);
 Resx_matched_layer2tid->Draw();
 SiStrip->cd(5);
 Resy_matched_layer2tid->Draw();
 SiStrip->cd(6);
 Chi2_matched_layer2tid->Draw();
   
 SiStrip->Print("MatchedResOfTID.eps");

////////////////////////////////////
//            TEC                 //
////////////////////////////////////


 rfile->cd("DQMData/TrackerRecHits/Strip/TEC");

 TCanvas * SiStrip = new TCanvas("SiStrip","SiStrip");
 SiStrip->Divide(3,4);
 SiStrip->cd(1);
 Adc_rphi_layer1tec->Draw();
 SiStrip->cd(2);
 Adc_rphi_layer2tec->Draw();
 SiStrip->cd(3);
 Adc_rphi_layer3tec->Draw();
 SiStrip->cd(4);
 Adc_rphi_layer4tec->Draw();
 SiStrip->cd(5);
 Adc_rphi_layer5tec->Draw();
 SiStrip->cd(6);
 Adc_rphi_layer6tec->Draw();
 SiStrip->cd(7);
 Adc_rphi_layer7tec->Draw();
 SiStrip->cd(8);
 Adc_sas_layer1tec->Draw();
 SiStrip->cd(9);
 Adc_sas_layer2tec->Draw();
 SiStrip->cd(10);
 Adc_sas_layer5tec->Draw();
 
 SiStrip->Print("AdcOfTEC.eps");

 TCanvas * SiStrip = new TCanvas("SiStrip","SiStrip");
 SiStrip->Divide(3,4);
 SiStrip->cd(1);
 Nstp_rphi_layer1tec->Draw();
 SiStrip->cd(2);
 Nstp_rphi_layer2tec->Draw();
 SiStrip->cd(3);
 Nstp_rphi_layer3tec->Draw();
 SiStrip->cd(4);
 Nstp_rphi_layer4tec->Draw();
 SiStrip->cd(5);
 Nstp_rphi_layer5tec->Draw();
 SiStrip->cd(6);
 Nstp_rphi_layer6tec->Draw();
 SiStrip->cd(7);
 Nstp_rphi_layer7tec->Draw();
 SiStrip->cd(8);
 Nstp_sas_layer1tec->Draw();
 SiStrip->cd(9);
 Nstp_sas_layer2tec->Draw();
 SiStrip->cd(10);
 Nstp_sas_layer5tec->Draw();
 
 SiStrip->Print("NstpOfTEC.eps");
   
 TCanvas * SiStrip = new TCanvas("SiStrip","SiStrip");
 
 SiStrip->Divide(3,4);
 SiStrip->cd(1);
 Posx_rphi_layer1tec->Draw();
 SiStrip->cd(2);
 Posx_rphi_layer2tec->Draw();
 SiStrip->cd(3);
 Posx_rphi_layer3tec->Draw();
 SiStrip->cd(4);
 Posx_rphi_layer4tec->Draw();
 SiStrip->cd(5);
 Posx_rphi_layer5tec->Draw();
 SiStrip->cd(6);
 Posx_rphi_layer6tec->Draw();
 SiStrip->cd(7);
 Posx_rphi_layer7tec->Draw();
 SiStrip->cd(8);
 Posx_sas_layer1tec->Draw();
 SiStrip->cd(9);
 Posx_sas_layer2tec->Draw();
 SiStrip->cd(10);
 Posx_sas_layer5tec->Draw();
 SiStrip->Print("PosOfTEC.eps");

 TCanvas * SiStrip = new TCanvas("SiStrip","SiStrip");

 SiStrip->Divide(3,4);
 SiStrip->cd(1);
 Errx_rphi_layer1tec->Draw();
 SiStrip->cd(2);
 Errx_rphi_layer2tec->Draw();
 SiStrip->cd(3);
 Errx_rphi_layer3tec->Draw();
 SiStrip->cd(4);
 Errx_rphi_layer4tec->Draw();
 SiStrip->cd(5);
 Errx_rphi_layer5tec->Draw();
 SiStrip->cd(6);
 Errx_rphi_layer6tec->Draw();
 SiStrip->cd(7);
 Errx_rphi_layer7tec->Draw();
 SiStrip->cd(8);
 Errx_sas_layer1tec->Draw();
 SiStrip->cd(9);
 Errx_sas_layer2tec->Draw();
 SiStrip->cd(10);
 Errx_sas_layer5tec->Draw();
 SiStrip->Print("ErrOfTEC.eps");


 TCanvas * SiStrip = new TCanvas("SiStrip","SiStrip");
 SiStrip->Divide(3,4);
 SiStrip->cd(1);
 Res_rphi_layer1tec->Draw();
 SiStrip->cd(2);
 Res_rphi_layer2tec->Draw();
 SiStrip->cd(3);
 Res_rphi_layer3tec->Draw();
 SiStrip->cd(4);
 Res_rphi_layer4tec->Draw();
 SiStrip->cd(5);
 Res_rphi_layer5tec->Draw();
 SiStrip->cd(6);
 Res_rphi_layer6tec->Draw();
 SiStrip->cd(7);
 Res_rphi_layer7tec->Draw();
 SiStrip->cd(8);
 Res_sas_layer1tec->Draw();
 SiStrip->cd(9);
 Res_sas_layer2tec->Draw();
 SiStrip->cd(10);
 Res_sas_layer5tec->Draw();
 
 SiStrip->Print("ResOfTEC.eps");

 TCanvas * SiStrip = new TCanvas("SiStrip","SiStrip");
 SiStrip->Divide(3,4);
 SiStrip->cd(1);
 Pull_LF_rphi_layer1tec->Draw();
 SiStrip->cd(2);
 Pull_LF_rphi_layer2tec->Draw();
 SiStrip->cd(3);
 Pull_LF_rphi_layer3tec->Draw();
 SiStrip->cd(4);
 Pull_LF_rphi_layer4tec->Draw();
 SiStrip->cd(5);
 Pull_LF_rphi_layer5tec->Draw();
 SiStrip->cd(6);
 Pull_LF_rphi_layer6tec->Draw();
 SiStrip->cd(7);
 Pull_LF_rphi_layer7tec->Draw();
 SiStrip->cd(8);
 Pull_LF_sas_layer1tec->Draw();
 SiStrip->cd(9);
 Pull_LF_sas_layer2tec->Draw();
 SiStrip->cd(10);
 Pull_LF_sas_layer5tec->Draw();
 SiStrip->Print("PullLFOfTEC.eps");

 TCanvas * SiStrip = new TCanvas("SiStrip","SiStrip");
 SiStrip->Divide(3,4);
 SiStrip->cd(1);
 Pull_MF_rphi_layer1tec->Draw();
 SiStrip->cd(2);
 Pull_MF_rphi_layer2tec->Draw();
 SiStrip->cd(3);
 Pull_MF_rphi_layer3tec->Draw();
 SiStrip->cd(4);
 Pull_MF_rphi_layer4tec->Draw();
 SiStrip->cd(5);
 Pull_MF_rphi_layer5tec->Draw();
 SiStrip->cd(6);
 Pull_MF_rphi_layer6tec->Draw();
 SiStrip->cd(7);
 Pull_MF_rphi_layer7tec->Draw();
 SiStrip->cd(8);
 Pull_MF_sas_layer1tec->Draw();
 SiStrip->cd(9);
 Pull_MF_sas_layer2tec->Draw();
 SiStrip->cd(10);
 Pull_MF_sas_layer5tec->Draw();
 SiStrip->Print("PullMFOfTEC.eps");

 TCanvas * SiStrip = new TCanvas("SiStrip","SiStrip");
 SiStrip->Divide(3,4);
 SiStrip->cd(1);
 Chi2_rphi_layer1tec->Draw();
 SiStrip->cd(2);
 Chi2_rphi_layer2tec->Draw();
 SiStrip->cd(3);
 Chi2_rphi_layer3tec->Draw();
 SiStrip->cd(4);
 Chi2_rphi_layer4tec->Draw();
 SiStrip->cd(5);
 Chi2_rphi_layer5tec->Draw();
 SiStrip->cd(6);
 Chi2_rphi_layer6tec->Draw();
 SiStrip->cd(7);
 Chi2_rphi_layer7tec->Draw();
 SiStrip->cd(8);
 Chi2_sas_layer1tec->Draw();
 SiStrip->cd(9);
 Chi2_sas_layer2tec->Draw();
 SiStrip->cd(10);
 Chi2_sas_layer5tec->Draw();
 
 SiStrip->Print("Chi2OfTEC.eps");

 TCanvas * SiStrip = new TCanvas("SiStrip","SiStrip");
 SiStrip->Divide(4,3);
 SiStrip->cd(1);
 Posx_matched_layer1tec->Draw();
 SiStrip->cd(2);
 Posy_matched_layer1tec->Draw();
 SiStrip->cd(3);
 Posx_matched_layer2tec->Draw();
 SiStrip->cd(4);
 Posy_matched_layer2tec->Draw();
 SiStrip->cd(5);
 Posx_matched_layer5tec->Draw();
 SiStrip->cd(6);
 Posy_matched_layer5tec->Draw();
 SiStrip->cd(7);
 Errx_matched_layer1tec->Draw();
 SiStrip->cd(8);
 Erry_matched_layer1tec->Draw();
 SiStrip->cd(9);
 Errx_matched_layer2tec->Draw();
 SiStrip->cd(10);
 Erry_matched_layer2tec->Draw();
 SiStrip->cd(11);
 Errx_matched_layer5tec->Draw();
 SiStrip->cd(12);
 Erry_matched_layer5tec->Draw();

 SiStrip->Print("MatchedOfTEC.eps");

 TCanvas * SiStrip = new TCanvas("SiStrip","SiStrip");
 SiStrip->Divide(3,3);
 SiStrip->cd(1);
 Resx_matched_layer1tec->Draw();
 SiStrip->cd(2);
 Resy_matched_layer1tec->Draw();
 SiStrip->cd(3);
 Chi2_matched_layer1tec->Draw();
 SiStrip->cd(4);
 Resx_matched_layer2tec->Draw();
 SiStrip->cd(5);
 Resy_matched_layer2tec->Draw();
 SiStrip->cd(6);
 Chi2_matched_layer2tec->Draw();
 SiStrip->cd(7);
 Resx_matched_layer5tec->Draw();
 SiStrip->cd(8);
 Resy_matched_layer5tec->Draw();
 SiStrip->cd(9);
 Chi2_matched_layer5tec->Draw();
   
 SiStrip->Print("MatchedResOfTEC.eps");
}
TCanvas* pMuonDist_1D( bool useHelper)
{
  // below 2 lines help when another TFile has been opened in memory
  // otherwise FindObject fails
  //TFile *ff = (TFile*)(gROOT->GetListOfFiles()->First());
  //ff->cd();


//
// upload histos from "helper file" (optional).
//
  TH1D *hMuonPt_BMF, *hMuonEta_BMF, *hMuonPhi_BMF;
  hMuonPt_BMF = hMuonEta_BMF = hMuonPhi_BMF = 0;
  if (useHelper) {
    TDirectory *dBefore = gDirectory;
    TFile file_BMF("../l1RpcHelper.root");
    hMuonPt_BMF =  (TH1D*) file_BMF.Get("hMuonPt_BMF")->Clone("hMuonPt_BMF_C");  hMuonPt_BMF->SetDirectory(0);
    hMuonEta_BMF = (TH1D*) file_BMF.Get("hMuonEta_BMF")->Clone("hMuonEta_BMF_C"); hMuonEta_BMF->SetDirectory(0);
    hMuonPhi_BMF = (TH1D*) file_BMF.Get("hMuonPhi_BMF")->Clone("hMuonPhi_BMF_C"); hMuonPhi_BMF->SetDirectory(0);

//    hMuonPt_BMF  = new TH1D(* (TH1D*) file_BMF.Get("hMuonPt_BMF"));   hMuonPt_BMF->SetDirectory(0);
//    hMuonEta_BMF = new TH1D(* (TH1D*) file_BMF.Get("hMuonEta_BMF")); hMuonEta_BMF->SetDirectory(0);
//    hMuonPhi_BMF = new TH1D(* (TH1D*) file_BMF.Get("hMuonPhi_BMF")); hMuonPhi_BMF->SetDirectory(0);

//    g_L1RpcGlobalTObjects.Add( file_BMF.Get("hMuonPt_BMF")->Clone("hMuonPt_BMF_C") );
//    g_L1RpcGlobalTObjects.Add( file_BMF.Get("hMuonEta_BMF")->Clone("hMuonEta_BMF_C") );
//    g_L1RpcGlobalTObjects.Add( file_BMF.Get("hMuonPhi_BMF")->Clone("hMuonPhi_BMF_C") );
    file_BMF.Close();
    dBefore->cd();
  }

  TCanvas * c = new TCanvas("cMuonDist_1D","Global muons distributions",1400,500);
  c->Divide(3,1);

//
// p1
//
  TVirtualPad * p1 = c->cd(1); p1->SetLogy(1); p1->SetLogx(1);
  TH1D* hMuonPt_DIS = (TH1D*) gROOT->FindObject("hMuonPt_DIS"); 
  if(hMuonPt_BMF)  hMuonPt_DIS->SetMaximum( hMuonPt_BMF->GetMaximum() * 250); 
  hMuonPt_DIS->SetXTitle("Glb.muon p_{T} [GeV/c]");
  hMuonPt_DIS->SetLineColor(2);
  hMuonPt_DIS->GetXaxis()->SetRange(3,33);
  hMuonPt_DIS->DrawCopy();

  TLegend l(0.3, 0.65, 0.93,.88);
  int nev;
  std::stringstream str; 

  if (hMuonPt_BMF) {
    nev= hMuonPt_BMF->GetEntries();
    str.str(""); str<<"all muons (ev: "<<std::setprecision(2) << scientific << (double) nev<<")"; 
    hMuonPt_BMF->SetLineColor(8);
    hMuonPt_BMF->DrawCopy("same");
    l.AddEntry(hMuonPt_BMF, str.str().c_str());
  }

  nev= hMuonPt_DIS->GetEntries();
  str.str(""); str<<"kinematic sel. (ev: "<< std::setprecision(2) << scientific << (double)nev<<")";
  l.AddEntry(hMuonPt_DIS, str.str().c_str() );

  TH1D* hMuonPt_MEN=(TH1D*)gROOT->FindObject("hMuonPt_MEN");
  if (hMuonPt_MEN) {
    hMuonPt_MEN->SetLineColor(4);
    hMuonPt_MEN->DrawCopy("same");
    nev= hMuonPt_MEN->GetEntries();
    str.str(""); str<<"trigger sel. (ev: "<< setprecision(3) << scientific  << (double) nev<<")";
    l.AddEntry(hMuonPt_MEN, str.str().c_str());
  }

  l.DrawClone("same");


//
// p2
//
  TVirtualPad * p2 = c->cd(2); p2->SetLogy(1);
  TH1D* hMuonEta_DIS=(TH1D*)gROOT->FindObject("hMuonEta_DIS");
  if(hMuonEta_BMF) hMuonEta_DIS->SetMaximum( hMuonEta_BMF->GetMaximum()); 
  TH1D* hMuonEta_MEN=(TH1D*)gROOT->FindObject("hMuonEta_MEN");
//  if(hMuonEta_MEN) hMuonEta_DIS->SetMinimum( max(1, (int)hMuonEta_MEN->GetMinimum()));
  hMuonEta_DIS->SetMinimum(1.e3);
  hMuonEta_DIS->SetLineColor(2);
  hMuonEta_DIS->SetXTitle("Glb.muon #eta");
  hMuonEta_DIS->DrawCopy();
  if (hMuonEta_BMF) {
   hMuonEta_BMF->SetLineColor(8);
   hMuonEta_BMF->DrawCopy("same");
  }
  if (hMuonEta_MEN) {
   hMuonEta_MEN->SetLineColor(4);
   hMuonEta_MEN->DrawCopy("same");
  }


//
// p3
//
  c->cd(3); 
  TH1D* hMuonPhi_DIS=(TH1D*)gROOT->FindObject("hMuonPhi_DIS");
  hMuonPhi_DIS->Scale(1./hMuonPhi_DIS->Integral());
  hMuonPhi_DIS->SetMinimum(0.);
  hMuonPhi_DIS->SetXTitle("Glb.muon #phi [rad]");
  hMuonPhi_DIS->SetYTitle("arbitrary units");
  hMuonPhi_DIS->SetLineColor(2);
  hMuonPhi_DIS->DrawCopy();
  if (hMuonPhi_BMF) {
   hMuonPhi_BMF->Scale(1./hMuonPhi_BMF->Integral());
   hMuonPhi_BMF->SetLineColor(8);
   hMuonPhi_BMF->DrawCopy("same");
  }
  TH1D* hMuonPhi_MEN=(TH1D*)gROOT->FindObject("hMuonPhi_MEN");
  if (hMuonPhi_MEN) {
   hMuonPhi_MEN->Scale(1./hMuonPhi_MEN->Integral());
   hMuonPhi_MEN->SetLineColor(4);
   hMuonPhi_MEN->DrawCopy("same");
  }

  return c;
}
Пример #19
0
void TTMnS2 () {
  
  const int nbins=400;
  
  TFile * QCD[8];     
  QCD[0] = new TFile("./root/TagMassVsTagNTrk_EXTRA_QCD_30-50_plots.root");
  QCD[1] = new TFile("./root/TagMassVsTagNTrk_EXTRA_QCD_50-80_plots.root");
  QCD[2] = new TFile("./root/TagMassVsTagNTrk_EXTRA_QCD_80-120_plots.root");
  QCD[3] = new TFile("./root/TagMassVsTagNTrk_EXTRA_QCD_120-170_plots.root");
  QCD[4] = new TFile("./root/TagMassVsTagNTrk_EXTRA_QCD_170-230_plots.root");
  QCD[5] = new TFile("./root/TagMassVsTagNTrk_EXTRA_QCD_230-300_plots.root");
  QCD[6] = new TFile("./root/TagMassVsTagNTrk_EXTRA_QCD_300-380_plots.root");
  QCD[7] = new TFile("./root/TagMassVsTagNTrk_EXTRA_QCD_380-incl_plots.root");
  double QCDxs[8] = { 155929000., 20938850., 2949713., 499656., 100995.,  23855., 6391., 2821.};
  // For extra QCD:
  double NQCD[8] = { 130000., 133096., 281096, 164000., 436000., 346000., 418000., 406000. };
  // For normal QCD:
  // double NQCD[8] = { 86000., 78000., 104000., 96000., 100000., 102000., 112000., 102000.};
  
  double Lumfactor = 100000; // 100/fb of luminosity assumed in histograms
  
  TH1D * H = dynamic_cast<TH1D*> (QCD[0]->Get("MTS2_0"));

  double minx=H->GetBinLowEdge(1);
  double maxx=nbins*H->GetBinWidth(1)+minx;
  TH1D * MT[8]; 
  TH1D * MN[8]; 
  for ( int i=0; i<8; i++ ) {
    char Ename[20];
    char Pname[20];
    sprintf ( Ename, "MTS2_%d", i );
    sprintf ( Pname, "MNS2_%d", i );
    MT[i] = new TH1D ( Ename, Ename, nbins, minx, maxx );
    MN[i] = new TH1D ( Pname, Pname, nbins, minx, maxx );
  }

  for ( int iN=0; iN<8; iN++ ) {
    char nameT[20];
    char nameN[20];
    sprintf ( nameT, "MTS2_%d", iN );
    sprintf ( nameN, "MNS2_%d", iN );
    double tot1[nbins]={0.};
    double s2_tot1[nbins]={0.};
    double tot2[nbins]={0.};
    double s2_tot2[nbins]={0.};
    for ( int i=0; i<8; i++ ) {
      MTtmp = dynamic_cast<TH1D*>(QCD[i]->Get(nameT));
      MNtmp = dynamic_cast<TH1D*>(QCD[i]->Get(nameN));
      cout << "Got histogram " << iN << endl;
      for ( int ibin=1; ibin<=nbins; ibin++ ) {
	double t1=MTtmp->GetBinContent(ibin);
	tot1[ibin-1]+=t1*QCDxs[i]/NQCD[i]*Lumfactor;
	s2_tot1[ibin-1]+=t1*pow(QCDxs[i]/NQCD[i]*Lumfactor,2);
	double t2=MNtmp->GetBinContent(ibin);
	tot2[ibin-1]+=t2*QCDxs[i]/NQCD[i]*Lumfactor;
	s2_tot2[ibin-1]+=t2*pow(QCDxs[i]/NQCD[i]*Lumfactor,2);
      }
    }
    if ( iN==7 ) {  // Fix split histogram for Nt=9 && >9
      sprintf ( nameT, "MTS2_%d", iN+1 );
      sprintf ( nameN, "MNS2_%d", iN+1);
      for ( int i=0; i<8; i++ ) {
	MTtmp = dynamic_cast<TH1D*>(QCD[i]->Get(nameT));
	MNtmp = dynamic_cast<TH1D*>(QCD[i]->Get(nameN));
	for ( int ibin=1; ibin<=nbins; ibin++ ) {
	  double t1=MTtmp->GetBinContent(ibin);
	  tot1[ibin-1]+=t1*QCDxs[i]/NQCD[i]*Lumfactor;
	  s2_tot1[ibin-1]+=t1*pow(QCDxs[i]/NQCD[i]*Lumfactor,2);
	  double t2=MNtmp->GetBinContent(ibin);
	  tot2[ibin-1]+=t2*QCDxs[i]/NQCD[i]*Lumfactor;
	  s2_tot2[ibin-1]+=t2*pow(QCDxs[i]/NQCD[i]*Lumfactor,2);
	}
      }
    }
    // Now renormalize histograms
    // --------------------------
    double i1=0.;
    double i2=0.;
    for ( int ibin=1; ibin<=nbins; ibin++ ) {
      i1+=tot1[ibin-1];
      i2+=tot2[ibin-1];
    }
    for ( int ibin=1; ibin<=nbins; ibin++ ) {
      MT[iN]->SetBinContent(ibin,tot1[ibin-1]/i1);
      MT[iN]->SetBinError(ibin,sqrt(s2_tot1[ibin-1])/i1);
      MN[iN]->SetBinContent(ibin,tot2[ibin-1]/i2);
      MN[iN]->SetBinError(ibin,sqrt(s2_tot2[ibin-1])/i2);
    }
  } // iN
  
  TCanvas * b = new TCanvas ("b", "Total Tag masses", 700, 700 );
  b->Divide(2,2);
  
  b->cd(1);
  b->GetPad(1)->SetLogy();
  MT[0]->SetMarkerStyle(20);
  MT[0]->SetMarkerSize(0.4);
  MT[0]->SetMarkerColor(kBlue);
  MT[0]->SetLineColor(kBlue);
  MT[0]->DrawCopy("PE");
  MT[1]->SetMarkerStyle(21);
  MT[1]->SetMarkerSize(0.4);
  MT[1]->SetMarkerColor(kRed);
  MT[1]->SetLineColor(kRed);
  MT[1]->DrawCopy("PESAME");
  MT[2]->SetMarkerStyle(24);
  MT[2]->SetMarkerSize(0.4);
  MT[2]->SetMarkerColor(kBlack);
  MT[2]->SetLineColor(kBlack);
  MT[2]->DrawCopy("PESAME");
  MT[3]->SetMarkerStyle(25);
  MT[3]->SetMarkerSize(0.4);
  MT[3]->SetMarkerColor(kGreen);
  MT[3]->SetLineColor(kGreen);
  MT[3]->DrawCopy("PESAME");
  b->cd(2);
  b->GetPad(2)->SetLogy();
  MT[4]->SetMarkerStyle(20);
  MT[4]->SetMarkerSize(0.4);
  MT[4]->SetMarkerColor(kBlue);
  MT[4]->SetLineColor(kBlue);
  MT[4]->DrawCopy("PE");
  MT[5]->SetMarkerStyle(21);
  MT[5]->SetMarkerSize(0.4);
  MT[5]->SetMarkerColor(kRed);
  MT[5]->SetLineColor(kRed);
  MT[5]->DrawCopy("PESAME");
  MT[6]->SetMarkerStyle(24);
  MT[6]->SetMarkerSize(0.4);
  MT[6]->SetMarkerColor(kBlack);
  MT[6]->SetLineColor(kBlack);
  MT[6]->DrawCopy("PESAME");
  MT[7]->SetMarkerStyle(25);
  MT[7]->SetMarkerSize(0.4);
  MT[7]->SetMarkerColor(kGreen);
  MT[7]->SetLineColor(kGreen);
  MT[7]->DrawCopy("PESAME");
  b->cd(3);
  b->GetPad(3)->SetLogy();
  MN[0]->SetMarkerStyle(20);
  MN[0]->SetMarkerSize(0.4);
  MN[0]->SetMarkerColor(kBlue);
  MN[0]->SetLineColor(kBlue);
  MN[0]->DrawCopy("PE");
  MN[1]->SetMarkerStyle(21);
  MN[1]->SetMarkerSize(0.4);
  MN[1]->SetMarkerColor(kRed);
  MN[1]->SetLineColor(kRed);
  MN[1]->DrawCopy("PESAME");
  MN[2]->SetMarkerStyle(24);
  MN[2]->SetMarkerSize(0.4);
  MN[2]->SetMarkerColor(kBlack);
  MN[2]->SetLineColor(kBlack);
  MN[2]->DrawCopy("PESAME");
  MN[3]->SetMarkerStyle(25);
  MN[3]->SetMarkerSize(0.4);
  MN[3]->SetMarkerColor(kGreen);
  MN[3]->SetLineColor(kGreen);
  MN[3]->DrawCopy("PESAME");
  b->cd(4);
  b->GetPad(4)->SetLogy();
  MN[4]->SetMarkerStyle(20);
  MN[4]->SetMarkerSize(0.4);
  MN[4]->SetMarkerColor(kBlue);
  MN[4]->SetLineColor(kBlue);
  MN[4]->DrawCopy("PE");
  MN[5]->SetMarkerStyle(21);
  MN[5]->SetMarkerSize(0.4);
  MN[5]->SetMarkerColor(kRed);
  MN[5]->SetLineColor(kRed);
  MN[5]->DrawCopy("PESAME");
  MN[6]->SetMarkerStyle(24);
  MN[6]->SetMarkerSize(0.4);
  MN[6]->SetMarkerColor(kBlack);
  MN[6]->SetLineColor(kBlack);
  MN[6]->DrawCopy("PESAME");
  MN[7]->SetMarkerStyle(25);
  MN[7]->SetMarkerSize(0.4);
  MN[7]->SetMarkerColor(kGreen);
  MN[7]->SetLineColor(kGreen);
  MN[7]->DrawCopy("PESAME");
  b->Print("./ps/TTMnS2.ps");
  
  // Close files
  // -----------
  TFile * File = new TFile ("TTMnS2.root","RECREATE");
  File->cd();
  for ( int i=0; i<8; i++ ) {
    MT[i]->Write();
    MN[i]->Write();
  }
  File->Close();
  
}
Пример #20
0
void rf701_efficiencyfit()
{
  // C o n s t r u c t   e f f i c i e n c y   f u n c t i o n   e ( x ) 
  // -------------------------------------------------------------------

  // Declare variables x,mean,sigma with associated name, title, initial value and allowed range
  RooRealVar x("x","x",-10,10) ;

  // Efficiency function eff(x;a,b) 
  RooRealVar a("a","a",0.4,0,1) ;
  RooRealVar b("b","b",5) ;
  RooRealVar c("c","c",-1,-10,10) ;
  RooFormulaVar effFunc("effFunc","(1-a)+a*cos((x-c)/b)",RooArgList(a,b,c,x)) ;



  // C o n s t r u c t   c o n d i t i o n a l    e f f i c i e n c y   p d f   E ( c u t | x ) 
  // ------------------------------------------------------------------------------------------

  // Acceptance state cut (1 or 0)
  RooCategory cut("cut","cutr") ;
  cut.defineType("accept",1) ;
  cut.defineType("reject",0) ;

  // Construct efficiency p.d.f eff(cut|x)
  RooEfficiency effPdf("effPdf","effPdf",effFunc,cut,"accept") ;



  // G e n e r a t e   d a t a   ( x ,   c u t )   f r o m   a   t o y   m o d e l 
  // -----------------------------------------------------------------------------

  // Construct global shape p.d.f shape(x) and product model(x,cut) = eff(cut|x)*shape(x) 
  // (These are _only_ needed to generate some toy MC here to be used later)
  RooPolynomial shapePdf("shapePdf","shapePdf",x,RooConst(-0.095)) ;
  RooProdPdf model("model","model",shapePdf,Conditional(effPdf,cut)) ;

  // Generate some toy data from model
  RooDataSet* data = model.generate(RooArgSet(x,cut),10000) ;



  // F i t   c o n d i t i o n a l   e f f i c i e n c y   p d f   t o   d a t a 
  // --------------------------------------------------------------------------

  // Fit conditional efficiency p.d.f to data
  effPdf.fitTo(*data,ConditionalObservables(x)) ;



  // P l o t   f i t t e d ,   d a t a   e f f i c i e n c y  
  // --------------------------------------------------------

  // Plot distribution of all events and accepted fraction of events on frame
  RooPlot* frame1 = x.frame(Bins(20),Title("Data (all, accepted)")) ;
  data->plotOn(frame1) ;
  data->plotOn(frame1,Cut("cut==cut::accept"),MarkerColor(kRed),LineColor(kRed)) ;

  // Plot accept/reject efficiency on data overlay fitted efficiency curve
  RooPlot* frame2 = x.frame(Bins(20),Title("Fitted efficiency")) ;
  data->plotOn(frame2,Efficiency(cut)) ; // needs ROOT version >= 5.21
  effFunc.plotOn(frame2,LineColor(kRed)) ;



  // Draw all frames on a canvas
  TCanvas* ca = new TCanvas("rf701_efficiency","rf701_efficiency",800,400) ;
  ca->Divide(2) ;
  ca->cd(1) ; gPad->SetLeftMargin(0.15) ; frame1->GetYaxis()->SetTitleOffset(1.6) ; frame1->Draw() ;
  ca->cd(2) ; gPad->SetLeftMargin(0.15) ; frame2->GetYaxis()->SetTitleOffset(1.4) ; frame2->Draw() ;
  
 
}
Пример #21
0
void tStudent()
{
   gSystem->Load("libMathCore");
   gSystem->Load("libMathMore");

  int n=100;
  double a=-5.;
  double b=5.;
  //double r  = 3; 
  TF1* pdf = new TF1("pdf", "ROOT::Math::tdistribution_pdf(x,3.0)", a,b);
  TF1* cum = new TF1("cum", "ROOT::Math::tdistribution_cdf(x,3.0)", a,b);


  TH1D* quant = new TH1D("quant", "", 9, 0, 0.9);
  

  for(int i=1; i < 10; i++)
     quant->Fill((i-0.5)/10.0, ROOT::Math::tdistribution_quantile((1.0*i)/10, 3.0 ) );

  double xx[10];
  xx[0] = -1.5;
  for(int i=1; i<9; i++)
    xx[i]= quant->GetBinContent(i);
  xx[9] = 1.5;
  TH1D* pdfq[10];
  //int nbin = n/10.0;
  for(int i=0; i < 10; i++)
  {
    int nbin = n * (xx[i+1]-xx[i])/3.0+1.0; 
    TString name = "pdf" + i; 
    pdfq[i]= new TH1D(name, "", nbin,xx[i],xx[i+1] );
    for(int j=1; j<nbin; j++)
    {
       double x= j*(xx[i+1]-xx[i])/nbin + xx[i];
       pdfq[i]->SetBinContent(j, ROOT::Math::tdistribution_pdf(x,3));

    }
 
  }

 TCanvas *Canvas = new TCanvas("DistCanvas", "Student Distribution graphs", 10, 10, 1000, 800); 
 pdf->SetTitle("Student t distribution function");
 cum->SetTitle("Cumulative for Student t");
 quant->SetTitle("10-quantiles  for Student t");
 Canvas->Divide(2, 2);
 Canvas->cd(1);
 pdf->SetLineWidth(2);
 pdf->DrawCopy();
 Canvas->cd(2);
 cum->SetLineWidth(2);
 cum->SetLineColor(kRed);
 cum->Draw();
 Canvas->cd(3);
 quant->Draw();
 quant->SetLineWidth(2);
 quant->SetLineColor(kBlue);
 quant->SetStats(0);
 Canvas->cd(4);
 pdfq[0]->SetTitle("Student t & its quantiles");
 pdf->SetTitle("");
 pdf->Draw();
 //pdfq[0]->SetAxisRange(-1.5, 0, 1.5,1.0);
 pdfq[0]->SetTitle("Student t & its quantiles");
 for(int i=0; i < 10; i++)
 {
   pdfq[i]->SetStats(0);
   pdfq[i]->SetFillColor(i+1);
   pdfq[i]->Draw("same");
 }
 Canvas->Modified();
 Canvas->cd();
}
Пример #22
0
//  -------------------------------------------------------------------------
//
//   ----- General Macro for R3B CALIFA S438 Data Display
//         Author: Hector Alvarez <*****@*****.**>
//         Last Update: 30/09/14
//         Comments:
//         MAIN DISPLAY OF S438 CALIFA CRYSTALHIT
//	
//  -------------------------------------------------------------------------
//
//   Usage: 
//      > root -l 
//      ROOT> .L plotAll.C
//      ROOT> plot("inputFile")
//     
//     where inputFile is the input file :) 
//  -------------------------------------------------------------------------
void plot(TString inputFile) {

  // CONFIGURATION
  ifstream input1;
  input1.open("./angles/petals_angels_angles.txt"); 
  Double_t polar[128]; Double_t azimuthal[128]; Int_t number=0;
  for(Int_t i=0;i<128;i++) input1 >> number >> polar[i] >> azimuthal[i]; 
  //

  gROOT->SetStyle("Default");
  //gStyle->SetOptTitle(0);
  gStyle->SetOptStat(0);
  gStyle->SetOptFit(0);

  TFile *file1 = TFile::Open(inputFile);

  //SETTINGS: reduce memory by disabling those canvas that you do not want!
  Bool_t plotMultiplicities=kTRUE; Bool_t plotEnergyvsAngle=kTRUE; Bool_t plotProtonCorr=kTRUE; Bool_t plotAddBack=kTRUE;

  //HISTOGRAMS DEFINITION FOR CRYSTALHITS
  TH1F* hMult; TH1F* hMult2; TH2F* hEnergyvsId; TH2F* hToT_EnergyvsId;
  if(plotMultiplicities) {
    hMult = new TH1F("hMult","Total CrystalHits vs crystalId",128,0,127);
    hMult2 = new TH1F("hMult2","Number of CrystalHit with max. E of the event vs crystalId",128,0,127);
    hEnergyvsId = new TH2F("hEnergyvsId","Energy vs crystalId",128,0,127,3000,-100,29900);
    hToT_EnergyvsId = new TH2F("hToT_EnergyvsId","ToT_Energy vs crystalId",128,0,127,3000,-1000,299000);
  }  
  TH2F* hP1EnergyvsPolar; TH2F* hP2EnergyvsPolar; TH2F* hP1ToT_EnergyvsPolar; TH2F* hP2ToT_EnergyvsPolar;
  if(plotEnergyvsAngle) {
    hP1EnergyvsPolar = new TH2F("hP1EnergyvsPolar","PETAL1: Energy vs polar",50,22,68,3000,-100,29900);
    hP2EnergyvsPolar = new TH2F("hP2EnergyvsPolar","PETAL2: Energy vs polar",50,22,68,3000,-100,29900);
    hP1ToT_EnergyvsPolar = new TH2F("hP1ToT_EnergyvsPolar","PETAL1: ToT_Energy vs polar",50,22,68,3000,-1000,299000);
    hP2ToT_EnergyvsPolar = new TH2F("hP2ToT_EnergyvsPolar","PETAL2: ToT_Energy vs polar",50,22,68,3000,-1000,299000);
  }
  TH2F* hToT_EnergyCorr; TH2F* hAngleCorr; TH2F* hToT_EnergyCorrLarge; TH2F* hAngleCorrLarge;
  if(plotProtonCorr) {
    hToT_EnergyCorr = new TH2F("hToT_EnergyCorr","ToT_Energy Petal1 vs ToT_Energy Petal2 (FULL COMBINATORIAL)",3000,-100,29900,3000,-100,29900);
    hEnergyCorr = new TH2F("hEnergyCorr","Energy Petal1 vs Energy Petal2 (FULL COMBINATORIAL)",3000,-100,29900,3000,-100,29900);
    hAngleCorr = new TH2F("hAngleCorr","Polar Petal1 vs polar Petal2 (FULL COMBINATORIAL)",50,22,68,50,22,68);
    hToT_EnergyCorrLarge = new TH2F("hToT_EnergyCorrLarge","ToT_Energy Petal1 vs ToT_Energy Petal2 (ONLY LARGEST ENERGY HIT)",3000,-100,29900,3000,-100,29900);
    hEnergyCorrLarge = new TH2F("hEnergyCorrLarge","Energy Petal1 vs Energy Petal2 (ONLY LARGEST ENERGY HIT)",3000,-100,29900,3000,-100,29900);
    hAngleCorrLarge = new TH2F("hAngleCorrLarge","Polar Petal1 vs polar Petal2 (ONLY LARGEST ENERGY HIT)",50,22,68,50,22,68);
  }  
  TH2F* hP1ABEnergy; TH2F* hP2ABEnergy; TH2F* hP1ABToT_Energy; TH2F* hP2ABToT_Energy;
  if(plotAddBack) {
    hP1ABEnergy= new TH2F("hP1ABEnergy","AddBack Energy in Petal1: second largest Energy vs largest Energy",3000,-100,29900,3000,-100,29900);
    hP2ABEnergy = new TH2F("hP2ABEnergy","AddBack Energy in Petal2: second largest Energy vs largest Energy",3000,-100,29900,3000,-100,29900);
    hP1ABToT_Energy = new TH2F("hP1ABToT_Energy","AddBack ToT_Energy in Petal1: second largest ToT_Energy vs largest ToT_Energy",3000,-1000,299000,3000,-1000,299000);
    hP2ABToT_Energy = new TH2F("hP2ABToT_Energy","AddBack ToT_Energy in Petal2: second largest ToT_Energy vs largest ToT_Energy",3000,-1000,299000,3000,-1000,299000);
  }

  TTree* caloTree = (TTree*)file1->Get("cbmsim");
 
  //Crystal Hits
  TClonesArray* crystalHitCA;  
  R3BCaloCrystalHit** crystalHit;
  crystalHitCA = new TClonesArray("R3BCaloCrystalHit",5);
  TBranch *branchCrystalHit = caloTree->GetBranch("CaloCrystalHit");
  if(branchCrystalHit) branchCrystalHit->SetAddress(&crystalHitCA);
  
  Int_t* crystalId; 
  Double_t* energies;
  Double_t* ToT_energies;
  Double_t maxEnergyP1=0; Double_t maxEnergyP2=0; Double_t maxToT_EnergyP1=0; Double_t maxToT_EnergyP2=0; 
  Int_t winnerEnergyP1=0; Int_t winnerEnergyP2=0; Int_t winnerToT_EnergyP1=0; Int_t winnerToT_EnergyP2=0;
  Int_t secondEnergyP1=0; Int_t secondEnergyP2=0; Int_t secondToT_EnergyP1=0; Int_t secondToT_EnergyP2=0;

  Long64_t nevents = caloTree->GetEntries();
  Int_t crystalHitsPerEvent =0;

  for(Int_t i=0;i<nevents;i++){
    if(i%100000 == 0) printf("Event:%i\n",i);
    crystalHitCA->Clear();
    caloTree->GetEvent(i);
    crystalHitsPerEvent = crystalHitCA->GetEntries(); 
    maxEnergyP1=-1; maxEnergyP2=-1; maxToT_EnergyP1=-1; maxToT_EnergyP2=-1; 
    winnerEnergyP1=-1; winnerEnergyP2=-1; winnerToT_EnergyP1=-1; winnerToT_EnergyP2=-1;
    secondEnergyP1=-1; secondEnergyP2=-1; secondToT_EnergyP1=-1; secondToT_EnergyP2=-1;

    if(crystalHitsPerEvent>0) {
      crystalHit = new R3BCaloCrystalHit*[crystalHitsPerEvent];
      crystalId = new Int_t[crystalHitsPerEvent]; 
      energies = new Double_t[crystalHitsPerEvent];
      ToT_energies = new Double_t[crystalHitsPerEvent];

      for(Int_t h=0;h<crystalHitsPerEvent;h++) {
	crystalHit[h] = (R3BCaloCrystalHit*) crystalHitCA->At(h);      
	//filling info
	if(plotMultiplicities) {
	  hMult->Fill(crystalHit[h]->GetCrystalId());
	  hMult2->Fill(crystalHit[h]->GetCrystalId()); //TO BE DONE BELOW! REMEMBER!!!
	  hEnergyvsId->Fill(crystalHit[h]->GetCrystalId(),crystalHit[h]->GetEnergy());
	  hToT_EnergyvsId->Fill(crystalHit[h]->GetCrystalId(),crystalHit[h]->GetToT_Energy());
	}
	if(plotEnergyvsAngle) {
	  if(crystalHit[h]->GetCrystalId()<64){//PETAL1
	    hP1EnergyvsPolar->Fill(polar[crystalHit[h]->GetCrystalId()],crystalHit[h]->GetEnergy());  //TO BE DONE BELOW! REMEMBER!!!
	    //hP1EnergyvsPolar->Fill(crystalHit[h]->GetCrystalId(),crystalHit[h]->GetEnergy());
	    hP1ToT_EnergyvsPolar->Fill(polar[crystalHit[h]->GetCrystalId()],crystalHit[h]->GetEnergy()); //TO BE DONE BELOW! REMEMBER!!!
	    //hP1ToT_EnergyvsPolar->Fill(crystalHit[h]->GetCrystalId(),crystalHit[h]->GetEnergy());
	  }
	  else{//PETAL2
	    hP2EnergyvsPolar->Fill(polar[crystalHit[h]->GetCrystalId()],crystalHit[h]->GetEnergy()); //TO BE DONE BELOW! REMEMBER!!!
	    //hP2EnergyvsPolar->Fill(crystalHit[h]->GetCrystalId(),crystalHit[h]->GetEnergy());
	    hP2ToT_EnergyvsPolar->Fill(polar[crystalHit[h]->GetCrystalId()],crystalHit[h]->GetEnergy()); //TO BE DONE BELOW! REMEMBER!!!
	    //hP2ToT_EnergyvsPolar->Fill(crystalHit[h]->GetCrystalId(),crystalHit[h]->GetEnergy());
	  }
	}
	
	//FILLING FOR ORDERING
	crystalId[h] = crystalHit[h]->GetCrystalId(); 
	energies[h] = crystalHit[h]->GetEnergy(); 
	ToT_energies[h] = crystalHit[h]->GetToT_Energy();
      }
      //TAKING THE LARGEST ENERGY IN EACH PETAL
      for(Int_t h=0;h<crystalHitsPerEvent;h++) {      
	if(crystalHit[h]->GetCrystalId()<64) {//PETAL1
	  if(maxEnergyP1<energies[h]){ secondEnergyP1=winnerEnergyP1; winnerEnergyP1=h; maxEnergyP1=energies[h];}  
	  if(maxToT_EnergyP1<ToT_energies[h]){ secondToT_EnergyP1=winnerToT_EnergyP1; winnerToT_EnergyP1=h; maxToT_EnergyP1=ToT_energies[h];}  
	}  
	else {//PETAL2
	  if(maxEnergyP2<energies[h]) { secondEnergyP2=winnerEnergyP2; winnerEnergyP2=h; maxEnergyP2=energies[h];} 
	  if(maxToT_EnergyP2<ToT_energies[h]){ secondToT_EnergyP2=winnerToT_EnergyP2; winnerToT_EnergyP2=h; maxToT_EnergyP2=ToT_energies[h];}   
	} 
      } 
      
      if(plotProtonCorr) {
	for(Int_t h=0;h<crystalHitsPerEvent;h++) {      
	  if(crystalHit[h]->GetCrystalId()<64) { //PETAL1
	    for(Int_t k=0;k<crystalHitsPerEvent;k++) {     
	      if(crystalHit[k]->GetCrystalId()>63) { //PETAL2
		hToT_EnergyCorr->Fill(ToT_energies[k],ToT_energies[h]); //FULL COMBINATORIAL!!
		hEnergyCorr->Fill(energies[k],energies[h]); //FULL COMBINATORIAL!!
		hAngleCorr->Fill(polar[crystalId[k]],polar[crystalId[h]]); 
	      }
	    }
	  }
	}
	if(winnerToT_EnergyP2>-1 && winnerToT_EnergyP1>-1) hToT_EnergyCorrLarge->Fill(ToT_energies[winnerToT_EnergyP2],ToT_energies[winnerToT_EnergyP1]);
	if(winnerEnergyP2>-1 && winnerEnergyP1>-1) hEnergyCorrLarge->Fill(energies[winnerEnergyP2],energies[winnerEnergyP1]);
	if(winnerToT_EnergyP2>-1 && winnerToT_EnergyP1>-1) hAngleCorrLarge->Fill(polar[crystalId[winnerToT_EnergyP2]],polar[crystalId[winnerToT_EnergyP1]]);
      }
      
      if(plotAddBack) {
	if(winnerEnergyP1>-1 && secondEnergyP1>-1) hP1ABEnergy->Fill(energies[winnerEnergyP1],energies[secondEnergyP1]);
	if(winnerToT_EnergyP1>-1 && secondToT_EnergyP1>-1) hP1ABToT_Energy->Fill(ToT_energies[winnerToT_EnergyP1],ToT_energies[secondToT_EnergyP1]);
	if(winnerEnergyP2>-1 && secondEnergyP2>-1) hP2ABEnergy->Fill(energies[winnerEnergyP2],energies[secondEnergyP2]);
	if(winnerToT_EnergyP2>-1 && secondToT_EnergyP2>-1) hP2ABToT_Energy->Fill(ToT_energies[winnerToT_EnergyP2],ToT_energies[secondToT_EnergyP2]);
      }
      
    }  
    if(crystalHitsPerEvent) delete [] crystalHit;
  }

  TCanvas* cMult;  TCanvas* cEnerg; TCanvas* cEneCorr; TCanvas* cAB;
  if(plotMultiplicities) {
    cMult= new TCanvas("cMult","Info on multiplicities and energies per crystalID",0,0,800,800);
    cMult->SetFillColor(0);    cMult->SetFrameFillColor(0);    cMult->Divide(2,2);
    cMult->cd(1);  hMult->Draw();
    cMult->cd(2);  hMult2->Draw();
    cMult->cd(3);  hEnergyvsId->Draw("COLZ");
    cMult->cd(4);  hToT_EnergyvsId->Draw("COLZ");
  }
  if(plotEnergyvsAngle) {
    cEnerg= new TCanvas("cEnerg","Info on energies per polar angle",0,0,800,800);
    cEnerg->SetFillColor(0);    cEnerg->SetFrameFillColor(0);    cEnerg->Divide(2,2);
    cEnerg->cd(1);  hP1EnergyvsPolar->Draw("COLZ");
    cEnerg->cd(2);  hP2EnergyvsPolar->Draw("COLZ");
    cEnerg->cd(3);  hP1ToT_EnergyvsPolar->Draw("COLZ");
    cEnerg->cd(4);  hP2ToT_EnergyvsPolar->Draw("COLZ");
  } 
  if(plotProtonCorr) {
    cEneCorr= new TCanvas("cEneCorr","Info on energy correlation between petals",0,0,1200,800);
    cEneCorr->SetFillColor(0);    cEneCorr->SetFrameFillColor(0);    cEneCorr->Divide(3,2);
    cEneCorr->cd(1);  hToT_EnergyCorr->Draw("COLZ");
    cEneCorr->cd(2);  hEnergyCorr->Draw("COLZ");
    cEneCorr->cd(3);  hAngleCorr->Draw("COLZ");
    cEneCorr->cd(4);  hToT_EnergyCorrLarge->Draw("COLZ");
    cEneCorr->cd(5);  hEnergyCorrLarge->Draw("COLZ");
    cEneCorr->cd(6);  hAngleCorrLarge->Draw("COLZ");
  }
  if(plotAddBack) {
    cAB= new TCanvas("cAB","Info on AddBack in each petal",0,0,800,800);
    cAB->SetFillColor(0);    cAB->SetFrameFillColor(0);    cAB->Divide(2,2);
    cAB->cd(1);  hP1ABEnergy->Draw("COLZ");
    cAB->cd(2);  hP2ABEnergy->Draw("COLZ");
    cAB->cd(3);  hP1ABToT_Energy->Draw("COLZ");
    cAB->cd(4);  hP2ABToT_Energy->Draw("COLZ");
  } 
}
Пример #23
0
RawSpectra() {
	
	gStyle->SetOptStat("nem");
	gStyle->SetStatX(.90);
	gStyle->SetStatY(.88);
	gStyle->SetStatW(.18);
	gStyle->SetStatH(.20);
	
	char fname[200];
	char pname[200];
	int eventno = 0;
	
	TChain *chain = new TChain("T");
	cout << "Enter multiple .root files. Type 'end' when finished."<< endl;
	while(true) {
		cout << "Enter .root file name, or 'end' if done adding files: " << endl;
		cin >> fname;
		if(strcmp(fname,"end")==0) break;
		chain->Add(fname);
	}
	
	cout << "chain entries: " << chain->GetEntries() << endl;
	int nentries = chain->GetEntries();
	
	float PbGThreshold = 120;
	
	TH2D *CerenkovCor = new TH2D("CerenkovCor", "Ce1 Ce2 Ped Sub Correlation", 100, .5, 600.5, 100, .5, 600.5);
	
	TH1D *PbGPedSubtracted = new TH1D("PbGPedSubtracted", "Lead Glass Pedestal Subtracted ADC", 4096, .5, 4096.5);
	TH2D *PbGEXYCor = new TH2D("PbGEXYCor", "PbG Position Energy Correlation", 8, -19.2, 19.2, 8, -19.2, 19.2);
	
	char buffer1[100];
	char buffer2[100];
	
	/****Raw Spectra Histograms****/
	TH1D* HCalRawADCSpectrum[16];
	for(int i=0; i<16; i++) {
		sprintf(buffer1, "HCalADCHist%d", i);
		sprintf(buffer2, "HCal ADC Channel %d", i);
		HCalRawADCSpectrum[i] = new TH1D(buffer1, buffer2, 4096, .5, 4096.5);
	}
	TH1D* ECalRawADCSpectrum[16];
	for(int i=0; i<16; i++) {
		sprintf(buffer1, "ECalADCHist%d", i);
		sprintf(buffer2, "ECal ADC Channel %d", i);
		ECalRawADCSpectrum[i] = new TH1D(buffer1, buffer2, 4096, .5, 4096.5);
	}
	
	TH1D* Sc1RawADCSpectrum = new TH1D("Sc1ADCHist", "Sc1 ADC", 4096, .5, 4096.5);
	TH1D* MonRawADCSpectrum = new TH1D("MonADCHist", "Mon ADC", 4096, .5, 4096.5);
	TH1D* Ce1RawADCSpectrum = new TH1D("Ce1ADCHist", "Ce1 ADC", 4096, .5, 4096.5);
	TH1D* Ce2RawADCSpectrum = new TH1D("Ce2ADCHist", "Ce2 ADC", 4096, .5, 4096.5);
	TH1D* PbGRawADCSpectrum = new TH1D("PbGADCHist", "PbG ADC", 4096, .5, 4096.5);
	
	TH1D* HodRawADCSpectrum[16];
	for(int i=0; i<16; i++) {
		sprintf(buffer1, "HodADCHist%d", i);
		sprintf(buffer2, "Hod ADC Channel %d", i);
		HodRawADCSpectrum[i] = new TH1D(buffer1, buffer2, 4096, .5, 4096.5);
	}
	
	
	TH1D* XMult = new TH1D("XMult", "Multiplicity in X direction", 9, -.5, 8.5);
	TH1D* YMult = new TH1D("YMult", "Multiplicity in Y direction", 9, -.5, 8.5);
	TH1D* BeamProfileX = new TH1D("BeamProfileX", "Beam Profile X", 8, -19.2, 19.2);
	TH1D* BeamProfileY = new TH1D("BeamProfileY", "Beam Profile Y", 8, -19.2, 19.2);
	TH2D* BeamXY = new TH2D("BeamXY", "Beam Profile XY", 8, -19.2, 19.2, 8, -19.2, 19.2);
	
	int eventindex = 0;
	int goodevents = 0;
	
	float ECalADC[16];
	float Sc1ADC;
	float MonADC;
	float Ce1ADC;
	float Ce2ADC;
	float PbGADC;
	float HodADC[16];
	
	bool HighHodHit = false;
	float xposition = 0;
	float yposition = 0;
	
	float PbGPedestalSubtracted = 0;
	float Ce1PedestalSubtracted = 0;
	float Ce2PedestalSubtracted = 0;
	
	float PbGHitsAbovePed = 0;
	float Ce1HitsAbovePed = 0;
	float Ce2HitsAbovePed = 0;
	
	chain->SetBranchAddress("ECalRawADC", ECalADC);
	chain->SetBranchAddress("HodRawADC", HodADC);
	chain->SetBranchAddress("Sc1RawADC", &Sc1ADC);
	chain->SetBranchAddress("MonRawADC", &MonADC);
	chain->SetBranchAddress("Ce1RawADC", &Ce1ADC);
	chain->SetBranchAddress("Ce2RawADC", &Ce2ADC);
	chain->SetBranchAddress("PbGRawADC", &PbGADC);
	
	for (eventindex=0; eventindex<nentries; eventindex++) {
		
		chain->GetEntry(eventindex);
		
		if(eventindex%10000==0) cout << "Processing event: " << eventindex << endl;
		
		/*Calculate Multiplicities*/
		
		
		int xmult = 0;
		int ymult = 0;
		HighHodHit = false;
		for(int i=0; i<8; i++) {
			if(HodADC[i]>=HodoscopeCutoff[i]) {
				ymult++;
			}
			if(HodADC[i]>2275) {
				HighHodHit = true;
			}
		}
		
		for(int i=0; i<8; i++) {
			if(HodADC[8+i]>=HodoscopeCutoff[8+i]) {
				xmult++;
			}
			if(HodADC[8+i]>2275) {
				HighHodHit = true;
			}
		}
		
		
		
		for(int i=0; i<8; i++) {
			if(HodADC[i]>=HodoscopeCutoff[i]) {
				for(int j=0; j<8; j++) {
					if(HodADC[8+j]>=HodoscopeCutoff[8+j]) {
						xposition = 16.8 - 4.8*j;
						yposition = -16.8 + 4.8*i;
					}
				}
			}
		}
		
		XMult->Fill(xmult);
		YMult->Fill(ymult);
		
		/****************Cuts******************/
		//if(!(xmult==1&&ymult==1)) {eventindex++;continue;} //xmult ymult both must be 1
		//if(!(Sc1ADC<1550)) {eventindex++;continue;}
		//if(HighHodHit) {eventindex++;continue;}
		//if(!(Ce1ADC>1470)) {eventindex++;continue;} // cut on cerenkov1 signal
		//if(!(Ce1ADC<1590)) {eventindex++;continue;}
	    //if(Ce2HitsAbovePed>0.0) {eventindex++;continue;} // cut on ce2
		//if(PbGHitsAbovePed > 0.0) {eventindex++; continue;} //cut on lead glass signal
		//if(xposition>5.0||xposition<-5.0||yposition>5.0||yposition<-5.0) {eventindex++;continue;} //include these positions
		//if(!(xposition>5.0||xposition<0.0||yposition>0.0||yposition<-5.0)) {eventindex++;continue;} //exclude these positions
		//if(!(yposition<10.0&&yposition>5.0&&xposition<-10.0&&xposition>-15.0)) {eventindex++;continue;}
		/*************************************/

		for(int i=0; i<16; i++) {
			ECalRawADCSpectrum[i]->Fill(ECalADC[i]);
		}
		for(int i=0; i<16; i++) {
			HodRawADCSpectrum[i]->Fill(HodADC[i]);
		}
		
		Sc1RawADCSpectrum->Fill(Sc1ADC);
		MonRawADCSpectrum->Fill(MonADC);
		Ce1RawADCSpectrum->Fill(Ce1ADC);
		Ce2RawADCSpectrum->Fill(Ce2ADC);
		PbGRawADCSpectrum->Fill(PbGADC);

		eventindex++;
		goodevents++;
	}
		
	/********************Plots*********************/
	
	/*******************************/
	/*********Raw Spectra***********/
	/*******************************/
	
	TCanvas *cECal = new TCanvas("cECal", "ECal ADC", 1100, 700);
	TCanvas *cHod = new TCanvas("cHod", "Hod ADC", 1100, 700);
	TCanvas *cSc1 = new TCanvas("cSc1", "Sc1 ADC", 700, 500);
	TCanvas *cMon = new TCanvas("cMon", "Mon ADC", 700, 500);
	TCanvas *cCe1 = new TCanvas("cCe1", "Ce1 ADC", 700, 500);
	TCanvas *cCe2 = new TCanvas("cCe2", "Ce2 ADC", 700, 500);
	TCanvas *cPbG = new TCanvas("cPbG", "PbG ADC", 700, 500);
	
	cECal->Divide(4,4);
	for(int i=0; i<16; i++) {
		cECal->cd(i+1);
		ECalRawADCSpectrum[i]->Draw();
		ECalRawADCSpectrum[i]->GetXaxis()->SetRangeUser(0,1000);
	}
	cECal->Update();
	
	cHod->Divide(4,4);
	for(int i=0; i<16; i++) {
		cHod->cd(i+1);
		HodRawADCSpectrum[i]->Draw();
		HodRawADCSpectrum[i]->GetXaxis()->SetRangeUser(0,1000);
		gPad->SetLogy();
	}
	cHod->Update();
	
	cSc1->cd();
	Sc1RawADCSpectrum->Draw();
	cSc1->Update();
	
	cMon->cd();
	MonRawADCSpectrum->Draw();
	cMon->Update();
	
	cCe1->cd();
	Ce1RawADCSpectrum->Draw();
	cCe1->Update();
	
	cCe2->cd();
	Ce2RawADCSpectrum->Draw();
	cCe2->Update();
	
	cPbG->cd();
	PbGRawADCSpectrum->Draw();
	cPbG->Update();
	
	/****************************/
	/********Hodoscope***********/
	/****************************/
	
	/*
	TCanvas *cxm = new TCanvas("cxm", "X Multiplicity", 700, 500);
	TCanvas *cym = new TCanvas("cym", "Y Multiplicity", 700, 500);
	TCanvas *cx = new TCanvas("cx", "X Beam Profile", 700, 500);
	TCanvas *cy = new TCanvas("cy", "Y Beam Profile", 700, 500);
	TCanvas *cxy = new TCanvas("cxy", "2D Beam Profile", 1000, 700);
	
	cxm->cd();
	XMult->Draw();
	gPad->SetLogy();
	cxm->Update();
	
	cym->cd();
	YMult->Draw();
	gPad->SetLogy();
	cym->Update();
	
	cx->cd();
	BeamProfileX->Draw();
	BeamProfileX->GetXaxis()->SetTitle("Position in mm East->West");
	cx->Update();
	
	cy->cd();
	BeamProfileY->Draw();
	BeamProfileY->GetXaxis()->SetTitle("Position in mm Down->Up");
	cy->Update();
	
	cxy->cd();
	BeamXY->Draw("zcol text");
	BeamXY->GetXaxis()->SetTitle("Position in mm East->West");
	BeamXY->GetYaxis()->SetTitle("Position in mm Down->Up");
	cy->Update();
	*/
	 
	/*************************/
	/***Ckov and Lead Glass***/
	/*************************/
	
	/*
	TCanvas *cCeCor = new TCanvas("cCeCor", "Cerenkov Correlation", 1000, 700);
	TCanvas *cPbGPedSub = new TCanvas("cPbGPedSub", "PbG Ped Sub", 1000, 700);
	TCanvas *cPbGEXY = new TCanvas("cPbGEXY", "PbG E-XY Cor", 1000, 700);
	
	cCeCor->cd();
	CerenkovCor->Draw("zcol");
	CerenkovCor->GetXaxis()->SetTitle("Ce1 Pedestal Subtracted ADC");
	CerenkovCor->GetYaxis()->SetTitle("Ce2 Pedestal Subtracted ADC");
	cCeCor->Update();
	
	cPbGPedSub->cd();
	PbGPedSubtracted->Draw();
	cPbGPedSub->Update();
	
	cPbGEXY->cd();
	PbGEXYCor->Draw("zcol");
	cPbGEXY->Update();
	*/
}
Пример #24
0
void PlotPedestalsvsTime(Int_t year=2011, Int_t firstRun=141820, 
		   Int_t lastRun=146900, Int_t ipedGainChain=0)
{


  TGrid::Connect("alien:",0,0,"t");
  gSystem->Exec(Form("gbbox find \"/alice/data/%d/OCDB/ZDC/Calib/Pedestals/\" \"Run*.root\" > calibAlienFiles.txt",year));
  FILE* listruns=fopen("calibAlienFiles.txt","r");
  
  const int kNchannels=24;
  TGraphErrors* graph[24];
  for(Int_t i=0; i<kNchannels; i++){
     graph[i] = new TGraphErrors(0);
     char name[50], title[50];
     sprintf(name,"graph%d",i); sprintf(title,"Pedestal ch.%d vs. run#",i);
     graph[i]->SetName("graph");  graph[i]->SetTitle("title");
  }

  Char_t filnam[200], filnamalien[200];
  Int_t iPoint=0;
  Int_t nrun, nrun2, nv, ns;

  while(!feof(listruns)){
    int st = fscanf(listruns,"%s\n",filnam);    
    Char_t directory[100];
    sprintf(directory,"/alice/data/%d",year);
    if(!strstr(filnam,directory)) continue;
    sscanf(filnam,"/alice/data/%d/OCDB/ZDC/Calib/Pedestals/Run%d_%d_v%d_s%d.root",&year,&nrun,&nrun2,&nv,&ns);
    if(nrun<firstRun) continue;
    if(nrun>lastRun) continue;
    sprintf(filnamalien,"alien://%s",filnam);
    printf("Opening file: %s\n",filnam);
    TFile *f = TFile::Open(filnamalien);  
    AliCDBEntry *entry = (AliCDBEntry*)f->Get("AliCDBEntry");
    AliZDCPedestals *calibdata = dynamic_cast<AliZDCPedestals*>  (entry->GetObject());
    
    for(int i=0; i<kNchannels; i++){
      if(ipedGainChain==0){
        graph[i]->SetPoint(iPoint, (Double_t)nrun, calibdata->GetMeanPed(i));
        graph[i]->SetPointError(iPoint, 0., calibdata->GetMeanPedWidth(i));
      }
      else{
        graph[i]->SetPoint(iPoint, (Double_t)nrun, calibdata->GetMeanPed(i+kNchannels));
        graph[i]->SetPointError(iPoint, 0., calibdata->GetMeanPedWidth(i+kNchannels));
      }
    }
    iPoint++;
    f->Close();
 }

 TFile *outfile=new TFile(Form("PedCalib%dVsTime.root",year),"recreate");
 outfile->cd();
 for(int i=0; i<kNchannels; i++) graph[i]->Write();
 outfile->Close();

 //***********************************************************
 // #### ROOT initialization
 gROOT->Reset();
 gStyle->SetCanvasColor(10);
 gStyle->SetFrameFillColor(10);
 gStyle->SetOptTitle(0);
 gStyle->SetOptStat(1111);
 gStyle->SetOptFit(0);
 gStyle->SetTitleTextColor(4);
 gStyle->SetStatTextColor(4);
 gStyle->SetStatX(0.92);
 gStyle->SetStatY(0.92);
 gStyle->SetLineColor(1);
 gStyle->SetPalette(1);
 gStyle->SetPadTopMargin(0.05);
 gStyle->SetPadRightMargin(0.05);
 gStyle->SetPadBottomMargin(0.09);
 gStyle->SetPadLeftMargin(0.09); 
 gStyle->SetTitleOffset(1.1,"Y");  
 // *************************************************************

 TCanvas *cHadPeds = new TCanvas("cHadPeds","Hadronic ZDC pedestals",0,0,1000,800);
 cHadPeds->Divide(5,4);
 for(int ic=0; ic<5; ic++){
   // *** ZNC pedestals
   cHadPeds->cd(ic+1);
   //
   TH1F *haxis1=0;
   if(ipedGainChain==0){
     if(ic==0) haxis1 = gPad->DrawFrame(firstRun-100, 80, lastRun+100, 100);
     else  haxis1 = gPad->DrawFrame(firstRun-100, 50, lastRun+100, 70);
   }
   else{
     if(ic==0) haxis1 = gPad->DrawFrame(firstRun-100, 500, lastRun+100, 800);
     else  haxis1 = gPad->DrawFrame(firstRun-100, 300, lastRun+100, 600);
   }
   haxis1->GetXaxis()->SetNoExponent();
   haxis1->SetXTitle("RUN no.");
   haxis1->SetYTitle("ZNC pedestals");
   //
   graph[ic]->SetMarkerStyle(20);
   graph[ic]->SetMarkerColor(kBlue);
   graph[ic]->Draw("P, SAME");
   // *** ZPC pedestals
   cHadPeds->cd(ic+6);
   //
   TH1F *haxis2=0;
   if(ipedGainChain==0) haxis2= gPad->DrawFrame(firstRun-100, 55, lastRun+100, 85);
   else  haxis2 = gPad->DrawFrame(firstRun-100, 400, lastRun+100, 700);
   haxis2->GetXaxis()->SetNoExponent();
   haxis2->SetXTitle("RUN no.");
   haxis2->SetYTitle("ZPC pedestals");
   //
   graph[ic+5]->SetMarkerStyle(21);
   graph[ic+5]->SetMarkerColor(kBlue+3);
   graph[ic+5]->Draw("P, SAME");
   // *** ZNA pedestals
   cHadPeds->cd(ic+11);
   //
   TH1F *haxis3=0;
   if(ipedGainChain==0) haxis3 = gPad->DrawFrame(firstRun-100, 35, lastRun+100, 85);
   else  haxis3 = gPad->DrawFrame(firstRun-100, 300, lastRun+100, 700);
   haxis3->GetXaxis()->SetNoExponent();
   haxis3->SetXTitle("RUN no.");
   haxis3->SetYTitle("ZNA pedestals");
   //
   graph[ic+12]->SetMarkerStyle(20);
   graph[ic+12]->SetMarkerColor(kRed);
   graph[ic+12]->Draw("P, SAME");
   // *** ZPA pedestals
   cHadPeds->cd(ic+16);
   //
   TH1F *haxis4=0;
   if(ipedGainChain==0) haxis4 = gPad->DrawFrame(firstRun-100, 40, lastRun+100, 80);
   else  haxis4 = gPad->DrawFrame(firstRun-100, 300, lastRun+100, 600);
   haxis4->GetXaxis()->SetNoExponent();
   haxis4->SetXTitle("RUN no.");
   haxis4->SetYTitle("ZPA pedestals");
   //
   graph[ic+17]->SetMarkerStyle(21);
   graph[ic+17]->SetMarkerColor(kRed+1);
   graph[ic+17]->Draw("P, SAME");
 }
 cHadPeds->SaveAs("ZDCPedvsTime1.gif");
 cHadPeds->SaveAs("ZDCPedvsTime1.C");

 TCanvas *cothPeds = new TCanvas("cothPeds","ZEM + Ref. pedestals",800,0,600,600);
 cothPeds->Divide(2,2);
 for(int ic=0; ic<2; ic++){
    // *** ZEM pedestals
    cothPeds->cd(ic+1);
    //
    TH1F *haxis5=0;
    if(ipedGainChain==0) haxis5 = gPad->DrawFrame(firstRun-100, 30, lastRun+20, 70);
    else  haxis5 = gPad->DrawFrame(firstRun-100, 250, lastRun+100, 550);
    haxis5->GetXaxis()->SetNoExponent();
    haxis5->SetXTitle("RUN no.");
    haxis5->SetYTitle("ZEM pedestals");
    //
    graph[ic+10]->SetMarkerStyle(22);
    graph[ic+10]->SetMarkerColor(kGreen+1);
    graph[ic+10]->Draw("P, SAME");
    // *** Ref. pedestals
    cothPeds->cd(ic+3);
    //
    TH1F *haxis6=0; 
    if(ipedGainChain==0) haxis6 = gPad->DrawFrame(firstRun-100, 50, lastRun+100, 90);
    else  haxis6 = gPad->DrawFrame(firstRun-100, 400, lastRun+100, 700);
    haxis6->GetXaxis()->SetNoExponent();
    haxis6->SetXTitle("RUN no.");
    haxis6->SetYTitle("PMRef. pedestals");
    //
    graph[ic+22]->SetMarkerStyle(23);
    graph[ic+22]->SetMarkerColor(kGreen+4);
    graph[ic+22]->Draw("P, SAME");
 }
 cothPeds->SaveAs("ZDCPedvsTime2.gif");
 cothPeds->SaveAs("ZDCPedvsTime2.C");
 
}
Пример #25
0
void eff_eta_taggability(TString filename="btagpatanalyzerpy_ttbar.root", TString data="ttbar") {

	
	TFile *f = TFile::Open(filename);
        const int dim=27; 
        TH1D* histo[dim];
        TH1D* histotag[dim];
	TH1D* eff[dim];
        std::vector< TString > quarks;
        quarks.push_back( "b" );
        quarks.push_back( "c" );
        quarks.push_back( "udsg" );

        std::vector< TString > tracks;
        tracks.push_back( "#tracks>0" );
        tracks.push_back( "#tracks>1" );
        tracks.push_back( "#tracks>2" );

        std::vector< TString > qtaggable;
        for ( size_t itrk=0; itrk < tracks.size(); ++itrk){
		for ( size_t iquark=0; iquark< quarks.size(); ++iquark){
			qtaggable.push_back( quarks[iquark]+" "+tracks[itrk]);
		}
	}

	TCanvas *cv = new TCanvas("cv","cv",700,1000);
	TLegend *legend = new TLegend(0.18,0.72,0.28,0.82);
	TPaveLabel *titlerow[3];
	titlerow[0] = new TPaveLabel(-2.50,0.60,-0.50,0.65,"p < 30");
	titlerow[1] = new TPaveLabel(-2.50,0.905,-0.5,0.92,"30< p < 50");
	titlerow[2] = new TPaveLabel(-2.50,0.938,-0.5,0.948,"p > 50");
	
        histotag[0] = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_b_taggable0_030");
        histo[0]    = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_b030");
        histotag[1] = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_c_taggable0_030");
        histo[1]    = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_c030");
        histotag[2] = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_udsg_taggable0_030");
        histo[2]    = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_udsg030");

        histotag[3] = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_b_taggable1_030");
        histo[3]    = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_b030");
        histotag[4] = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_c_taggable1_030");
        histo[4]    = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_c030");
        histotag[5] = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_udsg_taggable1_030");
        histo[5]    = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_udsg030");

        histotag[6] = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_b_taggable2_030");
        histo[6]    = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_b030");
        histotag[7] = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_c_taggable2_030");
        histo[7]    = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_c030");
        histotag[8] = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_udsg_taggable2_030");
        histo[8]    = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_udsg030");

        histotag[9] = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_b_taggable0_3050");
        histo[9]    = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_b3050");
        histotag[10] = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_c_taggable0_3050");
        histo[10]    = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_c3050");
        histotag[11] = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_udsg_taggable0_3050");
        histo[11]    = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_udsg3050");

        histotag[12] = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_b_taggable1_3050");
        histo[12]    = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_b3050");
        histotag[13] = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_c_taggable1_3050");
        histo[13]    = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_c3050");
        histotag[14] = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_udsg_taggable1_3050");
        histo[14]    = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_udsg3050");

        histotag[15] = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_b_taggable1_3050");
        histo[15]    = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_b3050");
        histotag[16] = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_c_taggable1_3050");
        histo[16]    = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_c3050");
        histotag[17] = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_udsg_taggable1_3050");
        histo[17]    = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_udsg3050");

        histotag[18] = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_b_taggable0_50");
        histo[18]    = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_b50");
        histotag[19] = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_c_taggable0_50");
        histo[19]    = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_c50");
        histotag[20] = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_udsg_taggable0_50");
        histo[20]    = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_udsg50");

        histotag[21] = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_b_taggable1_50");
        histo[21]    = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_b50");
        histotag[22] = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_c_taggable1_50");
        histo[22]    = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_c50");
        histotag[23] = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_udsg_taggable1_50");
        histo[23]    = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_udsg50");

        histotag[24] = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_b_taggable2_50");
        histo[24]    = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_b50");
        histotag[25] = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_c_taggable2_50");
        histo[25]    = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_c50");
        histotag[26] = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_udsg_taggable2_50");
        histo[26]    = (TH1D*) gDirectory->Get("BTagPATAnalyzerTC2/jet_eta_udsg50");

// Compute efficiencies
	for ( size_t i = 0; i < dim; ++i ){
                eff[i] = (TH1D*) histo[i]->Clone();
                eff[i]->SetName("Eff "+qtaggable[i%9]+" vs #eta");
                eff[i]->Divide(histotag[i],histo[i],1,1,"B");
		eff[i]->GetXaxis()->SetTitle("#eta");
		eff[i]->GetYaxis()->SetTitle("Eff");
	}


//We are ready to plot any histogram
	cv->Divide(3,3);
	for ( size_t irow= 0; irow < 3; ++irow){
  		for ( size_t icol = 0; icol < 3 ; ++icol ){
			cv->cd(1 + icol + 3*irow);
			eff[1 + 3*icol + 9*irow]->SetLineColor(2); //charm eff
			eff[2 + 3*icol + 9*irow]->SetLineColor(3); //udsg eff
			eff[3*icol+ 9*irow]->SetMinimum(0.6 + 0.45*sqrt(irow) - 0.15*irow);
			eff[3*icol + 9*irow]->Draw("PE0");
			eff[1 +3*icol + 9*irow]->Draw("Same");
			eff[2 +3*icol + 9*irow]->Draw("Same");
//		eff[irow + 3*icol]->Draw("PE0");
//                histotag[i]->SetLineColor(3);
//		histo[i]->Draw("LE0");
//		histotag[i]->Draw("Same");
		}
 		legend -> AddEntry(eff[irow],quarks[irow],"l");
		cv->Update();
		cv->cd(1 + 3*irow);
		titlerow[irow]->Draw();
	}
	cv->Update();
	cv->cd(0);
       // Draw a global picture title
	title = new TPaveLabel(0.00,0.97,0.20,1.00,"eff taggability");
        title->SetFillColor(16);
        title->Draw();
        cv->Update();
	legend ->Draw();
	cv-> Print ("BTagPAT_eff_eta_taggability0_"+data+".eps");
	cv-> Print ("BTagPAT_eff_eta_taggability0_"+data+".ps");
	cv-> Print ("BTagPAT_eff_eta_taggability0_"+data+".png");
	
}
Пример #26
0
TCanvas *plotmean(TString selecter)
{
 TCanvas *cWork = NULL; 
 if( selecter == "L" )
 {
   cWork = new TCanvas("cWork", "plots",200,10,700,500);
   cWork->Divide(2,2);
   plotmean(cWork, 1, "JP", selecter);
   plotmean(cWork, 2, "JBP", selecter);
   plotmean(cWork, 3, "CSV", selecter);
   plotmean(cWork, 4, "TCHE", selecter);
 }
 else if( selecter == "M" )
 {
   cWork = new TCanvas("cWork", "plots",200,10,700,750);
   cWork->Divide(2,3);
   plotmean(cWork, 1, "JP", selecter);
   plotmean(cWork, 2, "JBP", selecter);
   plotmean(cWork, 3, "CSV", selecter);
   plotmean(cWork, 4, "TCHE", selecter);
   plotmean(cWork, 5, "TCHP", selecter);
   plotmean(cWork, 6, "SSVHE", selecter);
 }
 else if( selecter == "T" )
 {
   cWork = new TCanvas("cWork", "plots",200,10,700,750);
   cWork->Divide(2,3);
   plotmean(cWork, 1, "JP", selecter);
   plotmean(cWork, 2, "JBP", selecter);
   plotmean(cWork, 3, "CSV", selecter);
   //plotmean(cWork, 4, "TCHE", selecter);
   plotmean(cWork, 5, "TCHP", selecter);
   plotmean(cWork, 6, "SSVHP", selecter);
 }
 else if( selecter == "TCHE" )
 {
   cWork = new TCanvas("cWork", "plots",200,10,700,500);
   cWork->Divide(1,2);
   plotmean(cWork, 1, selecter, "L");
   plotmean(cWork, 2, selecter, "M");
 }
 else if( selecter == "TCHP" )
 {
   cWork = new TCanvas("cWork", "plots",200,10,700,500);
   cWork->Divide(1,2);
   plotmean(cWork, 1, selecter, "M");
   plotmean(cWork, 2, selecter, "T");
 }
 else if( selecter == "SSVHE" )
 {
   cWork = new TCanvas("cWork", "plots",200,10,700,250);
   plotmean(cWork, 0, selecter, "M");
 }
 else if( selecter == "SSVHP" )
 {
   cWork = new TCanvas("cWork", "plots",200,10,700,250);
   plotmean(cWork, 0, selecter, "T");
 }
 else
 {
   cWork = new TCanvas("cWork", "plots",200,10,700,750);
   cWork->Divide(1,3);
   plotmean(cWork, 1, selecter, "L");
   plotmean(cWork, 2, selecter, "M");
   plotmean(cWork, 3, selecter, "T");
 }

 cWork->WaitPrimitive();
 cWork->SaveAs("MistagFunc_"+selecter+".pdf");
 return cWork;
}
Пример #27
0
void analize::Terminate()
{
   // The Terminate() function is the last function to be called during
   // a query. It always runs on the client, it can be used to present
   // the results graphically or save the results to file.
   cout << "Total events proceed: " << N0 << endl;
   cout << "Number of KK candidates: " << NKK  << endl;
   cout << "Number of uu candidates: " << Nuu  << endl;

   TCanvas * c =new TCanvas("cMrec","pions recoil mass");
   c->Divide(2,1);
   c->cd(1);
   hMrecKK->Draw("E");
   hMrecKK->SetDrawOption("E");
   char xaxis_title[1024];
   sprintf(xaxis_title,"M_{rec}(#pi^{+}#pi^{-}) - %6.1f, MeV", MJPSI_SHIFT*MSCALE);
   hMrecKK->GetXaxis()->SetTitle(xaxis_title);
   vector<double> resKK(3), resUU(3);
   if(NKK>20)
   {
     resKK  =  Fit(hMrecKK);
     cout << "Number of selected KK events: " << resKK[0] << " " << -resKK[1] << " +" << resKK[2] << endl;
   }
   c->cd(2);
   hMrecUU->Draw("E");
   hMrecUU->SetDrawOption("E");
   hMrecUU->GetXaxis()->SetTitle(xaxis_title);
   if(Nuu>20) 
   {
     resUU  =  Fit(hMrecUU);
     cout << "Number of selected #mu#mu events: " << resUU[0] << " " << -resUU[1] << " +" << resUU[2] << endl;
     double eps = resKK[0]/resUU[0];
     cout << "epsKK/epsUU = " << eps  << "  " << -sqrt( pow(resKK[1]/resKK[0],2) +  pow(resUU[1]/resUU[0],2)) << "  " <<  sqrt( pow(resKK[2]/resKK[0],2) +  pow(resUU[2]/resUU[0],2)) << endl;
   }
   else
   {
     cout << "Too small number of mu mu events: " << Nuu << endl;
   }

  TCanvas * cchi2 = new TCanvas("cchi2","pid and kinematic chi2");
  cchi2->Divide(2,2);
  cchi2->cd(1);
  hpid_chi2KK->Draw();
  cchi2->cd(2);
  hpid_chi2UU->Draw();
  cchi2->cd(3);
  hkin_chi2KK->Draw();
  cchi2->cd(4);
  hkin_chi2UU->Draw();
  file->WriteObject(c,"cMrec");
  file->WriteObject(cchi2,"cchi2");
  file->WriteObject(hMrecKK,"hMrecKK");
  file->WriteObject(hMrecUU,"hMrecUU");
  file->WriteObject(hpid_chi2KK,"hpid_chi2KK");
  file->WriteObject(hpid_chi2UU,"hpid_chi2UU");
  file->WriteObject(hkin_chi2KK,"hkin_chi2KK");
  file->WriteObject(hkin_chi2UU,"hkin_chi2UU");
  file->WriteObject(event_treeKK,"eventKK");
  file->WriteObject(mctopo_treeKK,"mctopoKK");
  file->WriteObject(event_treeUU,"eventUU");
  file->WriteObject(mctopo_treeUU,"mctopoUU");
  //event_tree->Print();
}
void makeSamePhiPlots() 
{
   gSystem->AddIncludePath("-I${EVENT_READER_DIR}");
   gSystem->AddIncludePath("-I${PLOTTER_DIR}");
   //  cout << gSystem->GetIncludePath() <<endl;
   
   gSystem->Load("libMathMore.so");
   gSystem->Load("/usr/lib64/libfftw3.so");
   gSystem->Load("libAnitaEvent.so");
   gSystem->Load("libAnitaCorrelator.so");
   TChain *deltaTTree = new TChain("deltaTTree");
   //   TFile *fp = new TFile("deltaTFile1027.root");
   //   TTree *deltaTTree = (TTree*) fp->Get("deltaTTree");
   deltaTTree->Add("deltaTFileClock*.root");
   
   AnitaGeomTool *fGeomTool = AnitaGeomTool::Instance();



   char plotCond[180];
   char plotTitle[180];
   char histName[180];
   TF1 *fitty = new TF1("fitty","gaus",-1,1);

   TH1F *histMeanDiff = new TH1F("histMeanDiff","histMeanDiff",100,-1,1);
   TH1F *histChiSq = new TH1F("histChiSq","histChiSq",100,0,3);
   TH1F *histSigma = new TH1F("histSigma","histSigma",100,0,10);
   TH1F *histConstant = new TH1F("histConstant","histConstant",100,0,100);

   ofstream Output("diffsDown.txt");

   for(int ant=0;ant<16;ant++) {
      TCanvas *can = new TCanvas();//"can","can");
      can->Divide(2,2);
      int topAnt=ant; 
      int bottomAnt=fGeomTool->getAzimuthPartner(topAnt); 
      for(int chip=0;chip<4;chip++) {
	 fitty->SetParameters(10,0,0.05);
	 //	 fitty->SetParLimits(2,0,0.1);

	 can->cd(chip+1);
	 sprintf(plotCond,"((firstAnt==%d && secondAnt==%d))  && labChip==%d && (corPeak/corRMS)>6",topAnt,bottomAnt,chip);	 
	 sprintf(plotTitle,"Ant %d -  Ant %d (Chip %d)",topAnt,bottomAnt,chip);
	 sprintf(histName,"histDt_%d_%d",ant,chip);
	 TH1F *histDt11 = new TH1F(histName,plotTitle,40,-0.5,0.5);

	 deltaTTree->Project(histName,"deltaT-deltaTExpected",plotCond);
	 //	 cout << plotCond << endl;
	 histDt11->Draw();
	 histDt11->Fit("fitty","Q");
	 Int_t numUnder= histDt11->GetBinContent(0);
	 Int_t numOver =histDt11->GetBinContent(1+histDt11->GetNbinsX());
// 	 cout << topAnt << "\t" << bottomAnt << "\t" << chip << "\t" << histDt11->GetEntries() << "\t"
// 	      << (histDt11->GetEntries()-(numOver+numUnder)) << "\t" << histDt11->GetMean() << "\t" << histDt11->GetRMS() << "\t"
// 	      << fitty->GetParameter(1) << "\t" << fitty->GetParError(1) << "\t" << fitty->GetParameter(2) << "\t"
// 	      << fitty->GetParError(2)  << "\t" << fitty->GetChisquare() << "\t" << fitty->GetNDF() << "\n";
	 histMeanDiff->Fill(fitty->GetParameter(1));
	 histChiSq->Fill(fitty->GetChisquare()/Double_t(fitty->GetNDF()));
	 histSigma->Fill(fitty->GetParameter(2));
	 histConstant->Fill(fitty->GetParameter(0));


	 Double_t constant=histDt11->GetMean();
	 Double_t error=0;
	 if(histDt11->GetEntries())
	    error=histDt11->GetRMS()/TMath::Sqrt(histDt11->GetEntries());
	 Int_t entries=(histDt11->GetEntries()-(numOver+numUnder));

	 if(TMath::Abs(fitty->GetParameter(1)-histDt11->GetMean())<0.01 || (entries>=20 && fitty->GetParError(1)<0.08)) {
	    constant=fitty->GetParameter(1);
	    error=fitty->GetParError(1);
	 }
	 else {
	    cout << topAnt << "\t" << bottomAnt << "\t" << chip << "\n";
	 }
	 Output << topAnt << "\t" << bottomAnt << "\t" << chip << "\t" << constant << "\t" << error << "\t"
		<< entries << "\n";
      }
	 
   }
   TCanvas *canSum = new TCanvas();
   canSum->Divide(2,2);
   canSum->cd(1);
   histChiSq->Draw();
   canSum->cd(2);
   histConstant->Draw();
   canSum->cd(3);
   histMeanDiff->Draw();
   canSum->cd(4);
   histSigma->Draw();    

      
}
Пример #29
0
void plotPdf_7D_VWW(double mH=125) {
    
    gROOT->ProcessLine(".L tdrstyle.C");
    setTDRStyle();
    TGaxis::SetMaxDigits(3);
    gROOT->ForceStyle();
    

    // Declaration of the PDFs to use
    gROOT->ProcessLine(".L PDFs/RooSpinOne_7D.cxx++");
    
    // W/Z mass and decay width constants
    double mV = 80.399;
    double gamV = 2.085;
    bool offshell = false;
    if ( mH < 2 * mV ) offshell = true;

    // for the pole mass and decay width of W 
    RooRealVar* mX = new RooRealVar("mX","mX", mH);
    RooRealVar* mW = new RooRealVar("mW","mW", mV);
    RooRealVar* gamW = new RooRealVar("gamW","gamW",gamV);

    //
    // Observables (7D)
    // 
    RooRealVar* wplusmass = new RooRealVar("wplusmass","m(W+)",mV,1e-09,120);
    wplusmass->setBins(50);
    RooRealVar* wminusmass = new RooRealVar("wminusmass","m(W-)",mV,1e-09,120);
    wminusmass->setBins(50);
    RooRealVar* hs = new RooRealVar("costhetastar","cos#theta*",-1,1);
    hs->setBins(20);
    RooRealVar* Phi1 = new RooRealVar("phistar1","#Phi_{1}",-TMath::Pi(),TMath::Pi());
    Phi1->setBins(20);
    RooRealVar* h1 = new RooRealVar("costheta1","cos#theta_{1}",-1,1);
    h1->setBins(20);
    RooRealVar* h2 = new RooRealVar("costheta2","cos#theta_{2}",-1,1);
    h2->setBins(20);
    RooRealVar* Phi = new RooRealVar("phi","#Phi",-TMath::Pi(),TMath::Pi());
    Phi->setBins(20);
    
    // 1-
    RooRealVar* g1ValV = new RooRealVar("g1ValV","g1ValV",1.);
    RooRealVar* g2ValV = new RooRealVar("g2ValV","g2ValV",0.);
    // Even more parameters, do not have to touch, based on W couplings
    RooRealVar* R1Val = new RooRealVar("R1Val","R1Val",-1.);
    RooRealVar* R2Val = new RooRealVar("R2Val","R2Val",-1.);
    
    // these are the acceptance terms associated with the production angles
    // the default setting is for setting no-acceptance
    RooRealVar* aParam = new RooRealVar("aParam","aParam",0);
    
    RooSpinOne_7D *myPDFV;

    if ( offshell ) 
      myPDFV = new RooSpinOne_7D("myPDF","myPDF", *mX, *wplusmass, *wminusmass, *h1, *h2, *hs, *Phi, *Phi1, 
				 *g1ValV, *g2ValV, *R1Val, *R2Val, *aParam, *mW, *gamW);
    else 
      myPDFV = new RooSpinOne_7D("myPDF","myPDF", *mX, *mW, *mW, *h1, *h2, *hs, *Phi, *Phi1, 
				*g1ValV, *g2ValV, *R1Val, *R2Val, *aParam, *mW, *gamW);
    
    // Grab input file to convert to RooDataSet
    TFile* finV = new TFile(Form("VWW_%.0f_JHU.root", mH));
    TTree* tinV = (TTree*) finV->Get("angles");
    if ( offshell ) 
      RooDataSet dataV("dataV","dataV",tinV,RooArgSet(*wplusmass, *wminusmass, *h1,*h2, *hs, *Phi, *Phi1));
    else 
      RooDataSet dataV("dataV","dataV",tinV,RooArgSet(*h1,*h2, *hs, *Phi, *Phi1));
    
    for (int i=1;i<1;i++) {
      RooArgSet* row = dataV.get(i);
      row->Print("v");
    }
    

    // 
    // 1+
    // 
    RooRealVar* g1ValA = new RooRealVar("g1ValA","g1ValA",0);
    RooRealVar* g2ValA = new RooRealVar("g2ValA","g2ValA",1);
    RooSpinOne_7D *myPDFA;
    
    if ( offshell ) 
      myPDFA = new RooSpinOne_7D("myPDF","myPDF", *mX, *wplusmass, *wminusmass, *h1, *h2, *hs, *Phi, *Phi1,
				 *g1ValA, *g2ValA, *R1Val, *R2Val, *aParam, *mW, *gamW);
    else 
      myPDFA = new RooSpinOne_7D("myPDF","myPDF", *mX, *mW, *mW, *h1, *h2, *hs, *Phi, *Phi1,
				 *g1ValA, *g2ValA, *R1Val, *R2Val, *aParam, *mW, *gamW);

    TFile* finA = new TFile(Form("AVWW_%.0f_JHU.root", mH));
    TTree* tinA = (TTree*) finA->Get("angles");
    if ( offshell ) 
      RooDataSet dataA("dataA","dataA",tinA,RooArgSet(*wplusmass, *wminusmass, *hs, *h1, *h2, *Phi, *Phi1));
     else 
       RooDataSet dataA("dataA","dataA",tinA,RooArgSet(*h1,*h2, *hs, *Phi, *Phi1));
    //
    // P L O T   . . .  
    // 

    bool drawv = true;
    bool drawa = true;
    bool drawpaper = true;

    double rescale = 1.0;
    if (drawpaper ) 
      rescale = 0.001;


    // for 1-
    TH1F* dum0 = new TH1F("dum0","dum0",1,0,1); dum0->SetLineColor(kRed); dum0->SetMarkerColor(kBlack); dum0->SetLineWidth(3);
    // for 1+
    TH1F* dum1 = new TH1F("dum1","dum1",1,0,1); dum1->SetLineColor(kBlue); dum1->SetMarkerColor(kBlack); dum1->SetMarkerStyle(24), dum1->SetLineWidth(3);
    TLegend * box3 = new TLegend(0.1,0.1,0.9,0.92);
    box3->SetFillColor(0);
    box3->SetBorderSize(0);
    if ( drawa ) 
      box3->AddEntry(dum0,"X#rightarrow WW JP = 1+","lp");
    if ( drawv )
    box3->AddEntry(dum1,"X#rightarrow WW JP = 1-","lp");

    // 
    //  h1
    // 
    RooPlot* h1frame =  h1->frame(20);
    h1frame->GetXaxis()->CenterTitle();
    h1frame->GetYaxis()->CenterTitle();
    h1frame->GetYaxis()->SetTitle(" ");

    double ymax_h1;
    TH1F *h1a = new TH1F("h1a", "h1a", 20, -1, 1);
    tinA->Project("h1a", "costheta1");
    ymax_h1 = h1a->GetMaximum();

    TH1F *h1_minus = new TH1F("h1_minus", "h1_minus", 20, -1, 1);
    tinV->Project("h1_minus", "costheta1");
    ymax_h1 = h1_minus->GetMaximum() > ymax_h1 ? h1_minus->GetMaximum() : ymax_h1;
    
    if ( drawa ) {
      dataA.plotOn(h1frame, MarkerColor(kRed),MarkerStyle(4),MarkerSize(1.5),LineWidth(0),XErrorSize(0), Rescale(rescale), DataError(RooAbsData::None));
      myPDFA->plotOn(h1frame, LineColor(kRed),LineWidth(2), Normalization(rescale));
    }
    if ( drawv ) {
      //dataV.plotOn(h1frame, MarkerColor(kBlue),MarkerStyle(27),MarkerSize(1.9),XErrorSize(0), Rescale(rescale), DataError(RooAbsData::None));
      //myPDFV->plotOn(h1frame, LineColor(kBlue),LineWidth(2), Normalization(rescale));
      // tempoary
      dataV.plotOn(h1frame, MarkerColor(kBlue),MarkerStyle(27),MarkerSize(1.9),XErrorSize(0), Rescale(rescale*.95823), DataError(RooAbsData::None));
      myPDFV->plotOn(h1frame, LineColor(kBlue),LineWidth(2), Normalization(rescale*.95823));
    }
    if ( rescale != 1.)
      h1frame->GetYaxis()->SetRangeUser(0, ymax_h1 / 1000. * 1.3);

    
    // 
    //  h2
    // 
    
    RooPlot* h2frame =  h2->frame(20);
    h2frame->GetXaxis()->CenterTitle();
    h2frame->GetYaxis()->CenterTitle();
    h2frame->GetYaxis()->SetTitle(" ");

    double ymax_h2;
    TH1F *h2a = new TH1F("h2a", "h2a", 20, -1, 1);
    tinA->Project("h2a", "costheta2");
    ymax_h2 = h2a->GetMaximum();

    TH1F *h2_minus = new TH1F("h2_minus", "h2_minus", 20, -1, 1);
    tinV->Project("h2_minus", "costheta2");
    ymax_h2 = h2_minus->GetMaximum() > ymax_h2 ? h2_minus->GetMaximum() : ymax_h2;

    if ( drawa ) {
      dataA.plotOn(h2frame, MarkerColor(kRed),MarkerStyle(4),MarkerSize(1.5),LineWidth(0),XErrorSize(0), Rescale(rescale), DataError(RooAbsData::None));
      myPDFA->plotOn(h2frame, LineColor(kRed),LineWidth(2), Normalization(rescale));
    }
    if ( drawv ) {
      // dataV.plotOn(h2frame, MarkerColor(kBlue),MarkerStyle(27),MarkerSize(1.9),XErrorSize(0), Rescale(rescale), yDataError(RooAbsData::None));
      // myPDFV->plotOn(h2frame, LineColor(kBlue),LineWidth(2), Normalization(rescale));
      dataV.plotOn(h2frame, MarkerColor(kBlue),MarkerStyle(27),MarkerSize(1.9),XErrorSize(0), Rescale(rescale*.95823), DataError(RooAbsData::None));
      myPDFV->plotOn(h2frame, LineColor(kBlue),LineWidth(2), Normalization(rescale*.95823));
    }
    if ( rescale != 1.) 
      h2frame->GetYaxis()->SetRangeUser(0, ymax_h2 / 1000. * 1.3);

    //
    // Phi
    // 
    RooPlot* Phiframe =  Phi->frame(20);
    Phiframe->GetXaxis()->CenterTitle();
    Phiframe->GetYaxis()->CenterTitle();
    Phiframe->GetYaxis()->SetTitle(" ");

    double ymax_Phi;
    TH1F *Phia = new TH1F("Phia", "Phia", 20,  -TMath::Pi(), TMath::Pi());
    tinA->Project("Phia", "phi");
    ymax_Phi = Phia->GetMaximum();

    TH1F *Phi_minus = new TH1F("Phi_minus", "Phi_minus", 20,  -TMath::Pi(), TMath::Pi());
    tinV->Project("Phi_minus", "phi");
    ymax_Phi = Phi_minus->GetMaximum() > ymax_Phi ? Phi_minus->GetMaximum() : ymax_Phi;
    
    if ( drawa ) {
      dataA.plotOn(Phiframe, MarkerColor(kRed),MarkerStyle(4),MarkerSize(1.5),LineWidth(0),XErrorSize(0), Rescale(rescale), DataError(RooAbsData::None));
      myPDFA->plotOn(Phiframe, LineColor(kRed),LineWidth(2), Normalization(rescale));
    }
    if ( drawv ) {
      //dataV.plotOn(Phiframe, MarkerColor(kBlue),MarkerStyle(27),MarkerSize(1.9),XErrorSize(0), Rescale(rescale), DataError(RooAbsData::None));
      //myPDFV->plotOn(Phiframe, LineColor(kBlue),LineWidth(2), Normalization(rescale));
      dataV.plotOn(Phiframe, MarkerColor(kBlue),MarkerStyle(27),MarkerSize(1.9),XErrorSize(0), Rescale(rescale*.95823), DataError(RooAbsData::None));
      myPDFV->plotOn(Phiframe, LineColor(kBlue),LineWidth(2), Normalization(rescale*.95823));
    }
    if ( rescale != 1. ) 
      Phiframe->GetYaxis()->SetRangeUser(0, ymax_Phi / 1000. * 1.3);
    
    // 
    //  hs 
    // 
    RooPlot* hsframe =  hs->frame(20);

    hsframe->GetXaxis()->CenterTitle();
    hsframe->GetYaxis()->CenterTitle();
    hsframe->GetYaxis()->SetTitle(" ");

    double ymax_hs;
    TH1F *hsa = new TH1F("hsa", "hsa", 20, -1, 1);
    tinA->Project("hsa", "costhetastar");
    ymax_hs = hsa->GetMaximum();

    TH1F *hs_minus = new TH1F("hs_minus", "hs_minus", 20, -1, 1);
    tinV->Project("hs_minus", "costhetastar");
    ymax_hs = hs_minus->GetMaximum() > ymax_hs ? hs_minus->GetMaximum() : ymax_hs;
    
    if ( drawa ) {
      dataA.plotOn(hsframe, MarkerColor(kRed),MarkerStyle(4),MarkerSize(1.5),LineWidth(0),XErrorSize(0), Rescale(rescale), DataError(RooAbsData::None));
      myPDFA->plotOn(hsframe, LineColor(kRed),LineWidth(2), Normalization(rescale));
    }
    if ( drawv ) {
      //dataV.plotOn(hsframe, MarkerColor(kBlue),MarkerStyle(27),MarkerSize(1.9),XErrorSize(0), Rescale(rescale), DataError(RooAbsData::None));
      //myPDFV->plotOn(hsframe, LineColor(kBlue),LineWidth(2), Normalization(rescale));
      dataV.plotOn(hsframe, MarkerColor(kBlue),MarkerStyle(27),MarkerSize(1.9),XErrorSize(0), Rescale(rescale*.95823), DataError(RooAbsData::None));
      myPDFV->plotOn(hsframe, LineColor(kBlue),LineWidth(2), Normalization(rescale*.95823));
    }
    if ( rescale != 1. ) 
      hsframe->GetYaxis()->SetRangeUser(0, ymax_hs / 1000. * 1.3);

    
    //
    // Phi1
    // 
    RooPlot* Phi1frame =  Phi1->frame(20);
 
    Phi1frame->GetXaxis()->CenterTitle();
    Phi1frame->GetYaxis()->CenterTitle();
    Phi1frame->GetYaxis()->SetTitle(" ");

    double ymax_Phi1;
    TH1F *Phi1a = new TH1F("Phi1a", "Phi1a", 20, -TMath::Pi(), TMath::Pi());
    tinA->Project("Phi1a", "phistar1");
    ymax_Phi1 = Phi1a->GetMaximum();

    TH1F *Phi1_minus = new TH1F("Phi1_minus", "Phi1_minus", 20, -TMath::Pi(), TMath::Pi());
    tinV->Project("Phi1_minus", "phistar1");
    ymax_Phi1 = Phi1_minus->GetMaximum() > ymax_Phi1 ? Phi1_minus->GetMaximum() : ymax_Phi1;
    
    if ( drawa ) {
      dataA.plotOn(Phi1frame, MarkerColor(kRed),MarkerStyle(4),MarkerSize(1.5),LineWidth(0),XErrorSize(0), Rescale(rescale), DataError(RooAbsData::None));
      myPDFA->plotOn(Phi1frame, LineColor(kRed),LineWidth(2), Normalization(rescale));
    }
    if ( drawv ) {
      // dataV.plotOn(Phi1frame, MarkerColor(kBlue),MarkerStyle(27),MarkerSize(1.9),XErrorSize(0), Rescale(rescale), DataError(RooAbsData::None));
      // myPDFV->plotOn(Phi1frame, LineColor(kBlue),LineWidth(2), Normalization(rescale));
      dataV.plotOn(Phi1frame, MarkerColor(kBlue),MarkerStyle(27),MarkerSize(1.9),XErrorSize(0), Rescale(rescale*.95823), DataError(RooAbsData::None));
      myPDFV->plotOn(Phi1frame, LineColor(kBlue),LineWidth(2), Normalization(rescale*.95823));
    }
    if ( rescale != 1. ) 
      Phi1frame->GetYaxis()->SetRangeUser(0, ymax_Phi1 / 1000. * 1.3);


    if ( offshell ) {
      RooPlot* w1frame =  wplusmass->frame(50);
      w1frame->GetXaxis()->CenterTitle();
      w1frame->GetYaxis()->CenterTitle();
      w1frame->GetYaxis()->SetTitle(" ");
      
      double ymax_w1;
      TH1F *w1a = new TH1F("w1a", "w1a", 50, 1e-09, 120);
      tinA->Project("w1a", "wplusmass");
      ymax_w1 = w1a->GetMaximum();
      
      TH1F *w1_minus = new TH1F("w1_minus", "w1_minus", 50, 1e-09, 120);
      tinV->Project("w1_minus", "wplusmass")
      ymax_w1 = w1_minus->GetMaximum() > ymax_w1 ? w1_minus->GetMaximum() : ymax_w1;
      
      if ( drawa ) {
	dataA.plotOn(w1frame, MarkerColor(kRed),MarkerStyle(4),MarkerSize(1.5),LineWidth(0),XErrorSize(0), Rescale(rescale), DataError(RooAbsData::None));
	myPDFA->plotOn(w1frame, LineColor(kRed),LineWidth(2), Normalization(rescale));
      }
      if ( drawv ) {
	// dataV.plotOn(w1frame, MarkerColor(kBlue),MarkerStyle(27),MarkerSize(1.9),XErrorSize(0), Rescale(rescale), DataError(RooAbsData::None));
	// myPDFV->plotOn(w1frame, LineColor(kBlue),LineWidth(2), Normalization(rescale));
	dataV.plotOn(w1frame, MarkerColor(kBlue),MarkerStyle(27),MarkerSize(1.9),XErrorSize(0), Rescale(rescale*.95823), DataError(RooAbsData::None));
	myPDFV->plotOn(w1frame, LineColor(kBlue),LineWidth(2), Normalization(rescale*.95823));
      }
      if ( rescale != 1. )
      w1frame->GetYaxis()->SetRangeUser(0, ymax_w1 / 1000. * 1.5);

      // 
      //  wminus
      // 
      RooPlot* w2frame =  wminusmass->frame(50);

      w2frame->GetXaxis()->CenterTitle();
      w2frame->GetYaxis()->CenterTitle();
      w2frame->GetYaxis()->SetTitle(" ");
      
      double ymax_w2;
      TH1F *w2a = new TH1F("w2a", "w2a", 50, 1e-09, 120);
      tinA->Project("w2a", "wminusmass");
      ymax_w2 = w2a->GetMaximum();
      
      TH1F *w2_minus = new TH1F("w2_minus", "w2_minus", 50, 1e-09, 120);
      tinV->Project("w2_minus", "wminusmass")
      ymax_w2 = w2_minus->GetMaximum() > ymax_w2 ? w2_minus->GetMaximum() : ymax_w2;
      
      if ( drawa ) {
	dataA.plotOn(w2frame, MarkerColor(kRed),MarkerStyle(4),MarkerSize(1.5),LineWidth(0),XErrorSize(0), Rescale(rescale), DataError(RooAbsData::None));
	myPDFA->plotOn(w2frame, LineColor(kRed),LineWidth(2), Normalization(rescale));
      }
      if ( drawv ) {
	//dataV.plotOn(w2frame, MarkerColor(kBlue),MarkerStyle(27),MarkerSize(1.9),XErrorSize(0), Rescale(rescale), DataError(RooAbsData::None));
	//myPDFV->plotOn(w2frame, LineColor(kBlue),LineWidth(2), Normalization(rescale));
	dataV.plotOn(w2frame, MarkerColor(kBlue),MarkerStyle(27),MarkerSize(1.9),XErrorSize(0), Rescale(rescale*.95823), DataError(RooAbsData::None));
	myPDFV->plotOn(w2frame, LineColor(kBlue),LineWidth(2), Normalization(rescale*.95823));
      }
      if ( rescale != 1. ) 
	w2frame->GetYaxis()->SetRangeUser(0, ymax_w2 / 1000. * 1.5);
    }
    if ( drawpaper ) {
      TCanvas* can =new TCanvas("can","can",600,600);

      if ( offshell ) {
	w1frame->GetXaxis()->SetTitle("m_{l#nu} [GeV]");
	w1frame->Draw();
	can->Print(Form("paperplots/wplusmass_%.0fGeV_spin1_2in1_ww.eps", mH));
	can->SaveAs(Form("paperplots/wplusmass_%.0fGeV_spin1_2in1_ww.C", mH));
      }
      
      can->Clear();
      hsframe->Draw();
      can->Print(Form("paperplots/costhetastar_%.0fGeV_spin1_2in1_ww.eps", mH));      
      can->SaveAs(Form("paperplots/costhetastar_%.0fGeV_spin1_2in1_ww.C", mH));      
      
      can->Clear();
      Phi1frame->Draw();
      can->Print(Form("paperplots/phistar1_%.0fGeV_spin1_2in1_ww.eps", mH));      
      can->SaveAs(Form("paperplots/phistar1_%.0fGeV_spin1_2in1_ww.C", mH));      

      can->Clear();
      h1frame->GetXaxis()->SetTitle("cos#theta_{1} or cos#theta_{2}");
      h1frame->Draw();
      can->Print(Form("paperplots/costheta1_%.0fGeV_spin1_2in1_ww.eps", mH));
      can->SaveAs(Form("paperplots/costheta1_%.0fGeV_spin1_2in1_ww.C", mH));

      can->Clear();
      Phiframe->Draw();
      can->Print(Form("paperplots/phi_%.0fGeV_spin1_2in1_ww.eps", mH));      
      can->SaveAs(Form("paperplots/phi_%.0fGeV_spin1_2in1_ww.C", mH));      


    }

    else {
      
      TCanvas* cww = new TCanvas( "cww", "cww", 1000, 600 );
      cww->Divide(4,2);
      if ( offshell ) {
	cww->cd(1);
	w1frame->Draw();
	cww->cd(2);
	w2frame->Draw();
      }
      cww->cd(3);
      hsframe->Draw();
      cww->cd(4);
      box3->Draw();
      cww->cd(5);
      Phi1frame->Draw();
      cww->cd(6);
      h1frame->Draw();
      cww->cd(7);
      h2frame->Draw();
      cww->cd(8);
      Phiframe->Draw();
      
      cww->Print(Form("epsfiles/angles_VWW%.0f_JHU_7D.eps", mH));
      cww->Print(Form("pngfiles/angles_VWW%.0f_JHU_7D.png", mH));
      delete cww;
    }

}
Пример #30
0
void Energy()
{

  /*****************************************************************/
  // Prepare the canvas
  gStyle->SetOptStat("ne"); 
  TCanvas *canvas = (TCanvas *) gROOT->GetListOfCanvases()->At(0);
  canvas->Divide(2,1,0.001,0.001,10);
  /*****************************************************************/
  
  char name[256];
  
  const unsigned int kBL_B =1;
  const unsigned int kBL_C =1;
  const unsigned int kBR_B =1;
  const unsigned int kBR_C =2;

  const unsigned int kML_B =1;
  const unsigned int kML_C =3;
  const unsigned int kMC_B =1;
  const unsigned int kMC_C =4;
  const unsigned int kMR_B =2;
  const unsigned int kMR_C =1;

  const unsigned int kTL_B =2;
  const unsigned int kTL_C =2;
  const unsigned int kTR_B =2;
  const unsigned int kTR_C =3;

  const unsigned int kSiPM_B = kTR_B;
  const unsigned int kSiPM_C = kTR_C;
  const unsigned int kR9800_B = kMC_B;
  const unsigned int kR9800_C = kMC_C;

  // SET PARAMETERS BELOW HERE 
  unsigned int icrate   = 1;
  unsigned int iboard   = kSiPM_B;
  unsigned int ichannel = kSiPM_C;
  
  int rebinParameter = 16;

  int binsLeftOfPeak = 4;
  int binsRightOfPeak = 30;
  int binsToShow = 150;

  int ipad = 1;
    gStyle->SetOptFit(1111);
  canvas->cd(ipad++);
  sprintf(name,"sis3350_defna/h1_defna_area_crate_%02d_board_%02d_channel_%d",icrate,iboard,ichannel);
  TH1D *h1 = (TH1D*)getObject(name);
  if ( !h1 )
    {
      printf("***ERROR! Cannot retrieve histogram [%s]\n",name);
    }
  else
    {
      h1->Rebin(rebinParameter);
      //      h1->GetXaxis()->SetRangeUser(4000,14000);
      h1->SetLineColor( kBlue );
      h1->SetLineWidth( 2 );
      h1->Draw();      

      
      TF1* user = new TF1("user","[0]*exp(-0.5*((x-[1])/[2])**2)+[3]",0,100000);
      

      double peak = h1->GetMaximumBin();
      printf("%f\n",h1->GetMaximum());

      double meanguess = h1->GetBinCenter(peak);
      user->SetParameters(0.025*meanguess,meanguess,0.15*meanguess,1);
      user->SetParNames("Amp","Mean","Sigma","Bkg");

      h1->Fit("user","","",h1->GetBinCenter(peak-binsLeftOfPeak),h1->GetBinCenter(peak+binsRightOfPeak));
      
      h1->GetXaxis()->SetRange(peak-binsToShow,peak+binsToShow);
      printf("Mean/Sigma = (%f/%f)=%f\n",user->GetParameter(2), user->GetParameter(1),user->GetParameter(2)/user->GetParameter(1));
    }

  TVirtualPad *pad = canvas->cd(ipad++);
  sprintf(name,"sis3350_hist_raw/h2_wf_crate_%02d_board_%02d_channel_%d",icrate,iboard,ichannel);
  TH2D *h2 = (TH2D*)getObject(name);
  if ( !h2 )
    {
      printf("***ERROR! Cannot retrieve histogram [%s]\n",name);
    }
  else
    {
      h2->Draw("ColZ");
      pad->SetLogz();
    }


 
}