示例#1
0
void PlotERes(string FilterSet){


  stringstream name;
  name<<FilterSet<<"_vsEnergy";

  
  TH2F* thePlot = (TH2F*)gDirectory->Get(name.str().c_str());

  if (thePlot==NULL){
    cout<<"No plot"<<endl;
    return;
  }

  int numYBins = thePlot->GetNbinsY();

  TF1 * myFunc = new TF1("myFunc","gaus",-0.3,0.3);
  

  double * x = (double*)malloc(numYBins*sizeof(double));
  double * y = (double*)malloc(numYBins*sizeof(double));
  double * ey = (double*)malloc(numYBins*sizeof(double));
  
  for (int i=0;i<numYBins;i++){
    


    TH1D* proj=thePlot->ProjectionX("_px",i,numYBins-1);
    if (proj->GetEntries()>40){
      TFitResultPtr result = proj->Fit("myFunc","RQS");
      Int_t status = result;
      if (status==0){
	cout<<result->Value(2)*2.35*4<<endl;
	x[i]=i;
	y[i]=result->Value(2)*2.35*4;
	ey[i]=result->UpperError(2)*2.35*4;
      }
    }
  }
  
  
  TGraphErrors * graph = new TGraphErrors(numYBins,x,y,0,ey);
  graph->GetHistogram()->SetMarkerStyle(5);
  graph->Draw("AP");
}
示例#2
0
int main (int argc, char ** argv)
{

	std::string category = std::string(argv[1]);

	double xtalWidth = 0.01745329;
	double luminosity = 11.35;
	double etaringEE = 0.0325;

// Acquisition of input file
	TChain* treeDATA = new TChain("simpleNtupleEoverP/SimpleNtupleEoverP");

	treeDATA->Add("/gwteray/users/gerosa/ECALNTUPLES/22JanReReco/SingleElectron_RUN2012D_22Jan2013-v1.root");


	treeReader *fReader = new treeReader((TTree*)(treeDATA), false);
	treeDATA->SetBranchStatus("*", 0);
	treeDATA->SetBranchStatus("isW", 1);
	treeDATA->SetBranchStatus("isZ", 1);
	treeDATA->SetBranchStatus("ele1_seedZside", 1);
	treeDATA->SetBranchStatus("ele1_seedIx", 1);
	treeDATA->SetBranchStatus("ele1_seedIy", 1);
	treeDATA->SetBranchStatus("ele1_seedIphi", 1);
	treeDATA->SetBranchStatus("ele1_seedIeta", 1);
	treeDATA->SetBranchStatus("ele1_e3x3", 1);
	treeDATA->SetBranchStatus("ele1_scEta", 1);
	treeDATA->SetBranchStatus("ele1_scERaw", 1);

	treeDATA->SetBranchStatus("ele2_seedZside", 1);
	treeDATA->SetBranchStatus("ele2_seedIx", 1);
	treeDATA->SetBranchStatus("ele2_seedIy", 1);
	treeDATA->SetBranchStatus("ele2_seedIphi", 1);
	treeDATA->SetBranchStatus("ele2_seedIeta", 1);
	treeDATA->SetBranchStatus("ele2_e3x3", 1);
	treeDATA->SetBranchStatus("ele2_scEta", 1);
	treeDATA->SetBranchStatus("ele2_scERaw", 1);

// Set Single Electron Trigger Names

	std::vector<std::pair<std::string, std::pair<int, int> > > WHLTPathNames;
	SetWHLTPathNames(WHLTPathNames);

	TH2F* h_OccupancyEB = new TH2F("h_OccupancyEB", "h_OccupancyEB", 360, 1, 361, 171, -85, 86);
	TH2F* h_OccupancyEB2 = new TH2F("h_OccupancyEB2", "h_OccupancyEB", 360, 1, 361, 171, -85, 86);

	TH2F* h_OccupancyEE[2];
	h_OccupancyEE[0] = new TH2F("h_OccupancyEEM", "h_OccupancyEEP", 100, 1, 101, 100, 1, 101);
	h_OccupancyEE[1] = new TH2F("h_OccupancyEEP", "h_OccupancyEEM", 100, 1, 101, 100, 1, 101);

	TH2F* h_OccupancyEE2[2];
	h_OccupancyEE2[1] = new TH2F("h_OccupancyEEP2", "h_OccupancyEEP2", 100, 1, 101, 100, 1, 101);
	h_OccupancyEE2[0] = new TH2F("h_OccupancyEEM2", "h_OccupancyEEM2", 100, 1, 101, 100, 1, 101);


	std::cout << " DATA Entries = " << treeDATA->GetEntries() << std::endl;

	for(int entry = 0; entry < treeDATA->GetEntries(); ++entry) {

		if( entry % 100000 == 0 ) std::cout << "reading saved entry " << entry << "\r" << std::flush;
		treeDATA->GetEntry(entry);

		//if(fReader->getInt("isHLTEle27")[0] != 1 || fReader->getInt("isGood")[0] !=1 ) continue;

		bool skipEvent = true;
		bool isWHLT = false;

		// W triggers
		for(unsigned int HLTIt = 0; HLTIt < WHLTPathNames.size(); ++HLTIt) {

			if( fReader->getInt("runId")[0] < ((WHLTPathNames.at(HLTIt)).second).first )  continue;
			if( fReader->getInt("runId")[0] > ((WHLTPathNames.at(HLTIt)).second).second ) continue;

			for(unsigned int iHLTIt = 0; iHLTIt < fReader->GetString("HLT_Names")->size(); ++iHLTIt) {
				if( (fReader->GetString("HLT_Names")->at(iHLTIt) == WHLTPathNames.at(HLTIt).first) && (fReader->GetInt("HLT_Accept")->at(iHLTIt) == 1) ) isWHLT = true;
			}

			if( isWHLT == true ) skipEvent = false;
		}


		if(skipEvent == true) continue ;


		if(fReader->getInt("isW")[0] == 1 && fReader->getInt("ele1_seedZside")[0] == 0) h_OccupancyEB->Fill(fReader->getInt("ele1_seedIphi")[0], fReader->getInt("ele1_seedIeta")[0]);
		if(fReader->getInt("isW")[0] == 1 && fReader->getInt("ele1_seedZside")[0] == 1) h_OccupancyEE[1]->Fill(fReader->getInt("ele1_seedIx")[0], fReader->getInt("ele1_seedIy")[0]);
		if(fReader->getInt("isW")[0] == 1 && fReader->getInt("ele1_seedZside")[0] == -1) h_OccupancyEE[0]->Fill(fReader->getInt("ele1_seedIx")[0], fReader->getInt("ele1_seedIy")[0]);


//   if(fReader->getInt("isGood")[0] ==1 && fReader->getInt("ele1_seedZside")[0]==0 && fReader->getInt("isZ")[0] ==0)
//     h_OccupancyEB->Fill(fReader->getInt("ele1_seedIphi")[0],fReader->getInt("ele1_seedIeta")[0]);
//   if(fReader->getInt("isGood")[0] ==1 && fReader->getInt("ele1_seedZside")[0]==1 && fReader->getInt("isZ")[0] ==0)
//     h_OccupancyEE[1]->Fill(fReader->getInt("ele1_seedIx")[0],fReader->getInt("ele1_seedIy")[0]);
//   if(fReader->getInt("isGood")[0] ==1 && fReader->getInt("ele1_seedZside")[0]==-1 && fReader->getInt("isZ")[0] ==0)
//     h_OccupancyEE[0]->Fill(fReader->getInt("ele1_seedIx")[0],fReader->getInt("ele1_seedIy")[0]);

//   if(category == "Default"){
//      if(fReader->getInt("isGood")[0] ==1 && fReader->getInt("ele1_seedZside")[0]==0 && fReader->getInt("isZ")[0] ==0)
//        h_OccupancyEB2->Fill(fReader->getInt("ele1_seedIphi")[0],fReader->getInt("ele1_seedIeta")[0]);
//   }

//  if(category == "R9"){
//   if(fReader->getInt("isGood")[0] ==1 && fReader->getInt("ele1_seedZside")[0]==0 && fReader->getInt("isZ")[0] ==0 && fReader->getFloat("ele1_r9")[0]>0.94)
//    h_OccupancyEB2->Fill(fReader->getInt("ele1_seedIphi")[0],fReader->getInt("ele1_seedIeta")[0]);
//   if(fReader->getInt("isGood")[0] ==1 && fReader->getInt("ele1_seedZside")[0]==1 && fReader->getInt("isZ")[0] ==0 && fReader->getFloat("ele1_r9")[0]>0.94)
//    h_OccupancyEE2[1]->Fill(fReader->getInt("ele1_seedIx")[0],fReader->getInt("ele1_seedIy")[0]);
//   if(fReader->getInt("isGood")[0] ==1 && fReader->getInt("ele1_seedZside")[0]==-1 && fReader->getInt("isZ")[0] ==0 && fReader->getFloat("ele1_r9")[0]>0.94)
//    h_OccupancyEE2[0]->Fill(fReader->getInt("ele1_seedIx")[0],fReader->getInt("ele1_seedIy")[0]);
//  }

//  if(category == "fbrem") {
//   if(fReader->getInt("isGood")[0] ==1 && fReader->getInt("ele1_seedZside")[0]==0 && fReader->getInt("isZ")[0] ==0 && fabs(fReader->getFloat("ele1_fbrem")[0])<0.5)
//     h_OccupancyEB2->Fill(fReader->getInt("ele1_seedIphi")[0],fReader->getInt("ele1_seedIeta")[0]);
//   if(fReader->getInt("isGood")[0] ==1 && fReader->getInt("ele1_seedZside")[0]==1 && fReader->getInt("isZ")[0] ==0 && fabs(fReader->getFloat("ele1_fbrem")[0])<0.5)
//     h_OccupancyEE2[1]->Fill(fReader->getInt("ele1_seedIx")[0],fReader->getInt("ele1_seedIy")[0]);
//   if(fReader->getInt("isGood")[0] ==1 && fReader->getInt("ele1_seedZside")[0]==-1 && fReader->getInt("isZ")[0] ==0 && fabs(fReader->getFloat("ele1_fbrem")[0])<0.5)
//     h_OccupancyEE2[0]->Fill(fReader->getInt("ele1_seedIx")[0],fReader->getInt("ele1_seedIy")[0]);
//  }

//  if(category == "Pt"){
//   if(fReader->getInt("isGood")[0] ==1 && fReader->getInt("ele1_seedZside")[0]==0 && fReader->getInt("isZ")[0] ==0 && fReader->getFloat("ele1_pt")[0]>50)
//    h_OccupancyEB2->Fill(fReader->getInt("ele1_seedIphi")[0],fReader->getInt("ele1_seedIeta")[0]);
//   if(fReader->getInt("isGood")[0] ==1 && fReader->getInt("ele1_seedZside")[0]==1 && fReader->getInt("isZ")[0] ==0 && fReader->getFloat("ele1_pt")[0]>50)
//    h_OccupancyEE2[1]->Fill(fReader->getInt("ele1_seedIx")[0],fReader->getInt("ele1_seedIy")[0]);
//   if(fReader->getInt("isGood")[0] ==1 && fReader->getInt("ele1_seedZside")[0]==-1 && fReader->getInt("isZ")[0] ==0 && fReader->getFloat("ele1_pt")[0]>50)
//    h_OccupancyEE2[0]->Fill(fReader->getInt("ele1_seedIx")[0],fReader->getInt("ele1_seedIy")[0]);
//  }

		if(fReader->getInt("isW")[0] == 1 && fReader->getInt("ele1_seedZside")[0] == 1 ) {
			if(fabs(fReader->getFloat("ele1_scEta")[0]) < 1.75 && fReader->getFloat("ele1_e3x3")[0] / fReader->getFloat("ele1_scERaw")[0] > 0.8)
				h_OccupancyEE2[1]->Fill(fReader->getInt("ele1_seedIx")[0], fReader->getInt("ele1_seedIy")[0]);

			if(fabs(fReader->getFloat("ele1_scEta")[0]) >= 1.75 && fabs(fReader->getFloat("ele1_scEta")[0]) < 2. && fReader->getFloat("ele1_e3x3")[0] / fReader->getFloat("ele1_scERaw")[0] > 0.88)
				h_OccupancyEE2[1]->Fill(fReader->getInt("ele1_seedIx")[0], fReader->getInt("ele1_seedIy")[0]);

			if(fabs(fReader->getFloat("ele1_scEta")[0]) >= 2. && fabs(fReader->getFloat("ele1_scEta")[0]) < 2.15 && fReader->getFloat("ele1_e3x3")[0] / fReader->getFloat("ele1_scERaw")[0] > 0.92)
				h_OccupancyEE2[1]->Fill(fReader->getInt("ele1_seedIx")[0], fReader->getInt("ele1_seedIy")[0]);

			if(fabs(fReader->getFloat("ele1_scEta")[0]) >= 2.15 && fReader->getFloat("ele1_e3x3")[0] / fReader->getFloat("ele1_scERaw")[0] > 0.94)
				h_OccupancyEE2[1]->Fill(fReader->getInt("ele1_seedIx")[0], fReader->getInt("ele1_seedIy")[0]);
		}


//  if(category=="Default"){
//  if(fReader->getInt("isGood")[0] ==1 && fReader->getInt("ele1_seedZside")[0]==1 && fReader->getInt("isZ")[0] ==0){
//    if(fabs(fReader->getFloat("ele1_scEta")[0])<1.75 && fReader->getFloat("ele1_r9")[0]>0.8)
//          h_OccupancyEE2[1]->Fill(fReader->getInt("ele1_seedIx")[0],fReader->getInt("ele1_seedIy")[0]);

//    if(fabs(fReader->getFloat("ele1_scEta")[0])>=1.75 && fabs(fReader->getFloat("ele1_scEta")[0])<2. && fReader->getFloat("ele1_r9")[0]>0.88)
//          h_OccupancyEE2[1]->Fill(fReader->getInt("ele1_seedIx")[0],fReader->getInt("ele1_seedIy")[0]);

//    if(fabs(fReader->getFloat("ele1_scEta")[0])>=2. && fabs(fReader->getFloat("ele1_scEta")[0])<2.15 && fReader->getFloat("ele1_r9")[0]>0.92)
//          h_OccupancyEE2[1]->Fill(fReader->getInt("ele1_seedIx")[0],fReader->getInt("ele1_seedIy")[0]);

//    if(fabs(fReader->getFloat("ele1_scEta")[0])>=2.15 && fReader->getFloat("ele1_r9")[0]>0.94)
//          h_OccupancyEE2[1]->Fill(fReader->getInt("ele1_seedIx")[0],fReader->getInt("ele1_seedIy")[0]);
//  }
// }


		if(fReader->getInt("isW")[0] == 1 && fReader->getInt("ele1_seedZside")[0] == -1) {

			if(fabs(fReader->getFloat("ele1_scEta")[0]) < 1.75 && fReader->getFloat("ele1_e3x3")[0] / fReader->getFloat("ele1_scERaw")[0] > 0.8)
				h_OccupancyEE2[0]->Fill(fReader->getInt("ele1_seedIx")[0], fReader->getInt("ele1_seedIy")[0]);

			if(fabs(fReader->getFloat("ele1_scEta")[0]) >= 1.75 && fabs(fReader->getFloat("ele1_scEta")[0]) < 2. && fReader->getFloat("ele1_e3x3")[0] / fReader->getFloat("ele1_scERaw")[0] > 0.88)
				h_OccupancyEE2[0]->Fill(fReader->getInt("ele1_seedIx")[0], fReader->getInt("ele1_seedIy")[0]);

			if(fabs(fReader->getFloat("ele1_scEta")[0]) >= 2. && fabs(fReader->getFloat("ele1_scEta")[0]) < 2.15 && fReader->getFloat("ele1_e3x3")[0] / fReader->getFloat("ele1_scERaw")[0] > 0.92)
				h_OccupancyEE2[0]->Fill(fReader->getInt("ele1_seedIx")[0], fReader->getInt("ele1_seedIy")[0]);

			if(fabs(fReader->getFloat("ele1_scEta")[0]) >= 2.15 && fReader->getFloat("ele1_e3x3")[0] / fReader->getFloat("ele1_scERaw")[0] > 0.94)
				h_OccupancyEE2[0]->Fill(fReader->getInt("ele1_seedIx")[0], fReader->getInt("ele1_seedIy")[0]);
		}


//  if(category == "Default"){

//   if(fReader->getInt("isGood")[0] ==1 && fReader->getInt("ele1_seedZside")[0]==-1 && fReader->getInt("isZ")[0] ==0){

//    if(fabs(fReader->getFloat("ele1_scEta")[0])<1.75 && fReader->getFloat("ele1_r9")[0]>0.8)
//      h_OccupancyEE2[0]->Fill(fReader->getInt("ele1_seedIx")[0],fReader->getInt("ele1_seedIy")[0]);

//    if(fabs(fReader->getFloat("ele1_scEta")[0])>=1.75 && fabs(fReader->getFloat("ele1_scEta")[0])<2. && fReader->getFloat("ele1_r9")[0]>0.88)
//      h_OccupancyEE2[0]->Fill(fReader->getInt("ele1_seedIx")[0],fReader->getInt("ele1_seedIy")[0]);

//    if(fabs(fReader->getFloat("ele1_scEta")[0])>=2. && fabs(fReader->getFloat("ele1_scEta")[0])<2.15 && fReader->getFloat("ele1_r9")[0]>0.92)
//      h_OccupancyEE2[0]->Fill(fReader->getInt("ele1_seedIx")[0],fReader->getInt("ele1_seedIy")[0]);

//    if(fabs(fReader->getFloat("ele1_scEta")[0])>=2.15 && fReader->getFloat("ele1_r9")[0]>0.94)
//      h_OccupancyEE2[0]->Fill(fReader->getInt("ele1_seedIx")[0],fReader->getInt("ele1_seedIy")[0]);
//   }
//  }


		if(fReader->getInt("isZ")[0] == 1 && fReader->getInt("ele1_seedZside")[0] == 0) h_OccupancyEB->Fill(fReader->getInt("ele1_seedIphi")[0], fReader->getInt("ele1_seedIeta")[0]);
		if(fReader->getInt("isZ")[0] == 1 && fReader->getInt("ele2_seedZside")[0] == 0) h_OccupancyEB->Fill(fReader->getInt("ele2_seedIphi")[0], fReader->getInt("ele2_seedIeta")[0]);

		if(fReader->getInt("isZ")[0] == 1 && fReader->getInt("ele1_seedZside")[0] == 1) h_OccupancyEE[1]->Fill(fReader->getInt("ele1_seedIx")[0], fReader->getInt("ele1_seedIy")[0]);
		if(fReader->getInt("isZ")[0] == 1 && fReader->getInt("ele2_seedZside")[0] == 1) h_OccupancyEE[1]->Fill(fReader->getInt("ele2_seedIx")[0], fReader->getInt("ele2_seedIy")[0]);

		if(fReader->getInt("isZ")[0] == 1 && fReader->getInt("ele1_seedZside")[0] == -1) h_OccupancyEE[0]->Fill(fReader->getInt("ele1_seedIx")[0], fReader->getInt("ele1_seedIy")[0]);
		if(fReader->getInt("isZ")[0] == 1 && fReader->getInt("ele2_seedZside")[0] == -1) h_OccupancyEE[0]->Fill(fReader->getInt("ele2_seedIx")[0], fReader->getInt("ele2_seedIy")[0]);

		if(fReader->getInt("isZ")[0] == 1 && fReader->getInt("ele1_seedZside")[0] == 1) {

			if(fabs(fReader->getFloat("ele1_scEta")[0]) < 1.75 && fReader->getFloat("ele1_e3x3")[0] / fReader->getFloat("ele1_scERaw")[0] > 0.8)
				h_OccupancyEE2[1]->Fill(fReader->getInt("ele1_seedIphi")[0], fReader->getInt("ele1_seedIeta")[0]);

			if(fabs(fReader->getFloat("ele1_scEta")[0]) >= 1.75 && fabs(fReader->getFloat("ele1_scEta")[0]) < 2. && fReader->getFloat("ele1_e3x3")[0] / fReader->getFloat("ele1_scERaw")[0] > 0.88)
				h_OccupancyEE2[1]->Fill(fReader->getInt("ele1_seedIx")[0], fReader->getInt("ele1_seedIy")[0]);

			if(fabs(fReader->getFloat("ele1_scEta")[0]) >= 2. && fabs(fReader->getFloat("ele1_scEta")[0]) < 2.15 && fReader->getFloat("ele1_e3x3")[0] / fReader->getFloat("ele1_scERaw")[0] > 0.92)
				h_OccupancyEE2[1]->Fill(fReader->getInt("ele1_seedIx")[0], fReader->getInt("ele1_seedIy")[0]);

			if(fabs(fReader->getFloat("ele1_scEta")[0]) >= 2.15 && fReader->getFloat("ele1_e3x3")[0] / fReader->getFloat("ele1_scERaw")[0] > 0.94)
				h_OccupancyEE2[1]->Fill(fReader->getInt("ele1_seedIx")[0], fReader->getInt("ele1_seedIy")[0]);

		}

		if(fReader->getInt("isZ")[0] == 1 && fReader->getInt("ele2_seedZside")[0] == 1) {

			if(fabs(fReader->getFloat("ele2_scEta")[0]) < 1.75 && fReader->getFloat("ele2_e3x3")[0] / fReader->getFloat("ele2_scERaw")[0] > 0.8)
				h_OccupancyEE2[1]->Fill(fReader->getInt("ele2_seedIphi")[0], fReader->getInt("ele2_seedIeta")[0]);

			if(fabs(fReader->getFloat("ele2_scEta")[0]) >= 1.75 && fabs(fReader->getFloat("ele2_scEta")[0]) < 2. && fReader->getFloat("ele2_e3x3")[0] / fReader->getFloat("ele2_scERaw")[0] > 0.88)
				h_OccupancyEE2[1]->Fill(fReader->getInt("ele2_seedIx")[0], fReader->getInt("ele2_seedIy")[0]);

			if(fabs(fReader->getFloat("ele2_scEta")[0]) >= 2. && fabs(fReader->getFloat("ele2_scEta")[0]) < 2.15 && fReader->getFloat("ele2_e3x3")[0] / fReader->getFloat("ele2_scERaw")[0] > 0.92)
				h_OccupancyEE2[1]->Fill(fReader->getInt("ele2_seedIx")[0], fReader->getInt("ele2_seedIy")[0]);

			if(fabs(fReader->getFloat("ele2_scEta")[0]) >= 2.15 && fReader->getFloat("ele2_e3x3")[0] / fReader->getFloat("ele2_scERaw")[0] > 0.94)
				h_OccupancyEE2[1]->Fill(fReader->getInt("ele2_seedIx")[0], fReader->getInt("ele2_seedIy")[0]);

		}

		if(fReader->getInt("isZ")[0] == 1 && fReader->getInt("ele1_seedZside")[0] == -1) {

			if(fabs(fReader->getFloat("ele1_scEta")[0]) < 1.75 && fReader->getFloat("ele1_e3x3")[0] / fReader->getFloat("ele1_scERaw")[0] > 0.8)
				h_OccupancyEE2[0]->Fill(fReader->getInt("ele1_seedIphi")[0], fReader->getInt("ele1_seedIeta")[0]);

			if(fabs(fReader->getFloat("ele1_scEta")[0]) >= 1.75 && fabs(fReader->getFloat("ele1_scEta")[0]) < 2. && fReader->getFloat("ele1_e3x3")[0] / fReader->getFloat("ele1_scERaw")[0] > 0.88)
				h_OccupancyEE2[0]->Fill(fReader->getInt("ele1_seedIx")[0], fReader->getInt("ele1_seedIy")[0]);

			if(fabs(fReader->getFloat("ele1_scEta")[0]) >= 2. && fabs(fReader->getFloat("ele1_scEta")[0]) < 2.15 && fReader->getFloat("ele1_e3x3")[0] / fReader->getFloat("ele1_scERaw")[0] > 0.92)
				h_OccupancyEE2[0]->Fill(fReader->getInt("ele1_seedIx")[0], fReader->getInt("ele1_seedIy")[0]);

			if(fabs(fReader->getFloat("ele1_scEta")[0]) >= 2.15 && fReader->getFloat("ele1_e3x3")[0] / fReader->getFloat("ele1_scERaw")[0] > 0.94)
				h_OccupancyEE2[0]->Fill(fReader->getInt("ele1_seedIx")[0], fReader->getInt("ele1_seedIy")[0]);

		}

		if(fReader->getInt("isZ")[0] == 1 && fReader->getInt("ele2_seedZside")[0] == -1) {

			if(fabs(fReader->getFloat("ele2_scEta")[0]) < 1.75 && fReader->getFloat("ele2_e3x3")[0] / fReader->getFloat("ele2_scERaw")[0] > 0.8)
				h_OccupancyEE2[0]->Fill(fReader->getInt("ele2_seedIphi")[0], fReader->getInt("ele2_seedIeta")[0]);

			if(fabs(fReader->getFloat("ele2_scEta")[0]) >= 1.75 && fabs(fReader->getFloat("ele2_scEta")[0]) < 2. && fReader->getFloat("ele2_e3x3")[0] / fReader->getFloat("ele2_scERaw")[0] > 0.88)
				h_OccupancyEE2[0]->Fill(fReader->getInt("ele2_seedIx")[0], fReader->getInt("ele2_seedIy")[0]);

			if(fabs(fReader->getFloat("ele2_scEta")[0]) >= 2. && fabs(fReader->getFloat("ele2_scEta")[0]) < 2.15 && fReader->getFloat("ele2_e3x3")[0] / fReader->getFloat("ele2_scERaw")[0] > 0.92)
				h_OccupancyEE2[0]->Fill(fReader->getInt("ele2_seedIx")[0], fReader->getInt("ele2_seedIy")[0]);

			if(fabs(fReader->getFloat("ele2_scEta")[0]) >= 2.15 && fReader->getFloat("ele2_e3x3")[0] / fReader->getFloat("ele2_scERaw")[0] > 0.94)
				h_OccupancyEE2[0]->Fill(fReader->getInt("ele2_seedIx")[0], fReader->getInt("ele2_seedIy")[0]);

		}


	}

// Graph ocuppancy for single xtal

	TGraphErrors *OccupancyEB_vs_Eta = new TGraphErrors();
	TGraphErrors *OccupancyEEP_vs_Eta = new TGraphErrors();
	TGraphErrors *OccupancyEEM_vs_Eta = new TGraphErrors();

	TGraphErrors *OccupancyAll = new TGraphErrors();
	TGraphErrors *OccupancyAll2 = new TGraphErrors();


// Graph for EB
	int nPoint = 0, nPointAll = 0, nPointAll2 = 0;


	for(int iEta = 0; iEta < h_OccupancyEB->GetNbinsY() ; iEta++) {
		double sumHit = 0, nHit = 0;
		for(int iPhi = 0; iPhi < h_OccupancyEB->GetNbinsX() ; iPhi++) {
			if(h_OccupancyEB->GetBinContent(iPhi + 1, iEta + 1) == 0) continue;
			sumHit = sumHit + h_OccupancyEB->GetBinContent(iPhi + 1, iEta + 1);
			nHit++;
		}
		if(iEta < 85 && sumHit != 0 && nHit != 0 ) {
			OccupancyEB_vs_Eta->SetPoint(nPoint, -(85 - iEta)*xtalWidth, sumHit / (nHit * luminosity));
			OccupancyEB_vs_Eta->SetPointError(nPoint, 0., (sumHit / (nHit * luminosity)) / sqrt(nHit * luminosity));

			OccupancyAll->SetPoint(nPointAll, -(85 - iEta)*xtalWidth, sumHit / (nHit * luminosity));
			OccupancyAll->SetPointError(nPointAll, 0., (sumHit / (nHit * luminosity)) / sqrt(nHit * luminosity));
		}

		if(iEta < 85 && sumHit == 0 && nHit == 0 ) {
			OccupancyEB_vs_Eta->SetPoint(nPoint, -(85 - iEta)*xtalWidth, 0.);
			OccupancyEB_vs_Eta->SetPointError(nPoint, 0., 0.);
			OccupancyAll->SetPoint(nPointAll, -(85 - iEta)*xtalWidth, 0.);
			OccupancyAll->SetPointError(nPointAll, 0., 0.);
		}

		if(iEta == 85 && sumHit != 0 && nHit != 0) {
			OccupancyEB_vs_Eta->SetPoint(nPoint, 0., sumHit / (nHit * luminosity));
			OccupancyEB_vs_Eta->SetPointError(nPoint, 0., (sumHit / (nHit * luminosity)) / sqrt(nHit * luminosity));
			OccupancyAll->SetPoint(nPointAll, 0., sumHit / (nHit * luminosity));
			OccupancyAll->SetPoint(nPointAll, 0., sumHit / (nHit * luminosity));
		}

		if(iEta == 85 && sumHit == 0 && nHit == 0 ) {
			OccupancyEB_vs_Eta->SetPoint(nPoint, 0., 0.);
			OccupancyEB_vs_Eta->SetPointError(nPoint, 0., 0.);
			OccupancyAll->SetPoint(nPointAll, 0., 0.);
			OccupancyAll->SetPointError(nPointAll, 0., 0.);
		}

		if(iEta > 85 && sumHit != 0 && nHit != 0) {
			OccupancyEB_vs_Eta->SetPoint(nPoint, (iEta - 85)*xtalWidth, sumHit / (nHit * luminosity));
			OccupancyEB_vs_Eta->SetPointError(nPoint, 0., (sumHit / (nHit * luminosity)) / sqrt(nHit * luminosity));
			OccupancyAll->SetPoint(nPointAll, (iEta - 85)*xtalWidth, sumHit / (nHit * luminosity));
			OccupancyAll->SetPointError(nPointAll, 0., (sumHit / (nHit * luminosity)) / sqrt(nHit * luminosity));
		}

		if(iEta < 85 && sumHit == 0 && nHit == 0 ) {
			OccupancyEB_vs_Eta->SetPoint(nPoint, (iEta - 85)*xtalWidth, 0.);
			OccupancyEB_vs_Eta->SetPointError(nPoint, 0., 0.);
			OccupancyAll->SetPoint(nPointAll, (iEta - 85)*xtalWidth, 0.);
			OccupancyAll->SetPointError(nPointAll, 0., 0.);
		}

		nPoint++;
		nPointAll++;
		nPointAll2++;
	}

// Graph for EB
	nPoint = 0;
	nPointAll = 0;
	nPointAll2 = 0;

	for(int iEta = 0; iEta < h_OccupancyEB2->GetNbinsY() ; iEta++) {
		double sumHit = 0, nHit = 0;
		for(int iPhi = 0; iPhi < h_OccupancyEB2->GetNbinsX() ; iPhi++) {
			if(h_OccupancyEB2->GetBinContent(iPhi + 1, iEta + 1) == 0) continue;
			sumHit = sumHit + h_OccupancyEB2->GetBinContent(iPhi + 1, iEta + 1);
			nHit++;
		}
		if(iEta < 85 && sumHit != 0 && nHit != 0 ) {
			OccupancyAll2->SetPoint(nPointAll2, -(85 - iEta)*xtalWidth, sumHit / (nHit * luminosity));
			OccupancyAll2->SetPointError(nPointAll2, 0., (sumHit / (nHit * luminosity)) / sqrt(nHit * luminosity));
		}

		if(iEta < 85 && sumHit == 0 && nHit == 0 ) {
			OccupancyAll2->SetPoint(nPointAll2, -(85 - iEta)*xtalWidth, 0.);
			OccupancyAll2->SetPointError(nPointAll2, 0., 0.);
		}

		if(iEta == 85 && sumHit != 0 && nHit != 0) {
			OccupancyAll2->SetPointError(nPointAll2, 0., (sumHit / (nHit * luminosity)) / sqrt(nHit * luminosity));
			OccupancyAll2->SetPointError(nPointAll2, 0., (sumHit / (nHit * luminosity)) / sqrt(nHit * luminosity));

		}

		if(iEta == 85 && sumHit == 0 && nHit == 0 ) {
			OccupancyAll2->SetPoint(nPointAll2, 0., 0.);
			OccupancyAll2->SetPointError(nPointAll2, 0., 0.);
		}

		if(iEta > 85 && sumHit != 0 && nHit != 0) {
			OccupancyAll2->SetPoint(nPointAll2, (iEta - 85)*xtalWidth, sumHit / (nHit * luminosity));
			OccupancyAll2->SetPointError(nPointAll2, 0., (sumHit / (nHit * luminosity)) / sqrt(nHit * luminosity));

		}

		if(iEta < 85 && sumHit == 0 && nHit == 0 ) {
			OccupancyAll2->SetPoint(nPointAll2, (iEta - 85)*xtalWidth, 0.);
			OccupancyAll2->SetPointError(nPointAll2, 0., 0.);
		}

		nPoint++;
		nPointAll++;
		nPointAll2++;
	}



// Plot for EE : EEP and EEM
/// ring geometry for the endcap
	TH2F *hrings[2];
	hrings[0] = (TH2F*) h_OccupancyEE[0]->Clone("hringsEEM");
	hrings[1] = (TH2F*) h_OccupancyEE[1]->Clone("hringsEEP");
	hrings[0] ->Reset("ICMES");
	hrings[1] ->Reset("ICMES");
	hrings[0] ->ResetStats();
	hrings[1] ->ResetStats();

	FILE *fRing;
	fRing = fopen("macros/eerings.dat", "r");
	int x, y, z, ir;
	while(fscanf(fRing, "(%d,%d,%d) %d \n", &x, &y, &z, &ir) != EOF ) {
		if(z > 0) hrings[1]->Fill(x, y, ir);
		if(z < 0) hrings[0]->Fill(x, y, ir);
	}

	std::vector<double> sumHitEEM ;
	std::vector<int> nHitEEM ;
	sumHitEEM.assign(40, 0.);
	nHitEEM.assign(40, 0);
	std::vector<double> sumHitEEP ;
	std::vector<int> nHitEEP ;
	sumHitEEP.assign(40, 0.);
	nHitEEP.assign(40, 0);

	for(int k = 0; k < 2 ; k++) {
		for(int ix = 0; ix < h_OccupancyEE[k]->GetNbinsX() ; ix++) {
			for(int iy = 0; iy < h_OccupancyEE[k]->GetNbinsY() ; iy++) {
				if(h_OccupancyEE[k]->GetBinContent(ix + 1, iy + 1) == 0) continue;
				int mybin = h_OccupancyEE[k] -> FindBin(ix, iy);
				int ring  = int(hrings[k]-> GetBinContent(mybin));
				float occ = h_OccupancyEE[k]->GetBinContent(mybin);
				if(k == 0) {
					sumHitEEM.at(ring) = sumHitEEM.at(ring) + occ;
					nHitEEM.at(ring) = nHitEEM.at(ring) + 1;
				}
				if(k == 1) {
					sumHitEEP.at(ring) = sumHitEEP.at(ring) + occ;
					nHitEEP.at(ring) = nHitEEP.at(ring) + 1;
				}
			}
		}
	}

	for(int k = 0; k < 2 ; k++) {
		nPoint = 0;
		if(k == 0) {

			for(unsigned int iring = 0; iring < sumHitEEM.size() ; iring++) {
				if(sumHitEEM.at(iring) != 0 && nHitEEM.at(iring) != 0) {
					OccupancyEEM_vs_Eta->SetPoint(nPoint, -1.*(85 * xtalWidth + iring * etaringEE), sumHitEEM.at(iring) / (nHitEEM.at(iring)*luminosity));
					OccupancyEEM_vs_Eta->SetPointError(nPoint, 0., (sumHitEEM.at(iring) / (nHitEEM.at(iring)*luminosity)) / sqrt(nHitEEM.at(iring)*luminosity));
					OccupancyAll->SetPoint(nPointAll, -1.*(85 * xtalWidth + iring * etaringEE), sumHitEEM.at(iring) / (nHitEEM.at(iring)*luminosity));
					OccupancyAll->SetPointError(nPointAll, 0., (sumHitEEM.at(iring) / (nHitEEM.at(iring)*luminosity)) / sqrt(nHitEEM.at(iring)*luminosity));
					nPoint++;
					nPointAll++;
				}
				if(sumHitEEM.at(iring) == 0 || nHitEEM.at(iring) == 0) {
					OccupancyEEM_vs_Eta->SetPoint(nPoint, -1.*(85 * xtalWidth + iring * etaringEE), 0.);
					OccupancyEEM_vs_Eta->SetPointError(nPoint, 0., 0.);
					OccupancyAll->SetPoint(nPointAll, -1.*(85 * xtalWidth + iring * etaringEE), 0.);
					OccupancyAll->SetPointError(nPointAll, 0., 0.);
					nPoint++;
					nPointAll++;
				}

			}
		}

		if(k == 1) {
			for(unsigned int iring = 0; iring < sumHitEEP.size() ; iring++) {
				if(sumHitEEP.at(iring) != 0 && nHitEEP.at(iring) != 0) {
					OccupancyEEP_vs_Eta->SetPoint(nPoint, (85 * xtalWidth + iring * etaringEE), sumHitEEP.at(iring) / (nHitEEP.at(iring)*luminosity));
					OccupancyEEP_vs_Eta->SetPointError(nPoint, 0., (sumHitEEP.at(iring) / (nHitEEP.at(iring)*luminosity)) / sqrt(nHitEEP.at(iring)*luminosity));
					OccupancyAll->SetPoint(nPointAll, (85 * xtalWidth + iring * etaringEE), sumHitEEP.at(iring) / (nHitEEP.at(iring)*luminosity));
					OccupancyAll->SetPointError(nPointAll, 0., (sumHitEEP.at(iring) / (nHitEEP.at(iring)*luminosity)) / sqrt(nHitEEP.at(iring)*luminosity));
					nPoint++;
					nPointAll++;
				}

				if(sumHitEEP.at(iring) == 0 || nHitEEP.at(iring) == 0) {
					OccupancyEEP_vs_Eta->SetPoint(nPoint, (85 * xtalWidth + iring * etaringEE), 0.);
					OccupancyEEP_vs_Eta->SetPointError(nPoint, 0., 0.);
					OccupancyAll->SetPoint(nPointAll, (85 * xtalWidth + iring * etaringEE), 0.);
					OccupancyAll->SetPointError(nPointAll, 0., 0.);
					nPoint++;
					nPointAll++;
				}
			}
		}
	}


	sumHitEEM.clear() ;
	nHitEEM.clear() ;
	sumHitEEM.assign(40, 0.);
	nHitEEM.assign(40, 0);
	sumHitEEP.clear() ;
	nHitEEP.clear() ;
	sumHitEEP.assign(40, 0.);
	nHitEEP.assign(40, 0);

	for(int k = 0; k < 2 ; k++) {
		for(int ix = 0; ix < h_OccupancyEE2[k]->GetNbinsX() ; ix++) {
			for(int iy = 0; iy < h_OccupancyEE2[k]->GetNbinsY() ; iy++) {
				if(h_OccupancyEE2[k]->GetBinContent(ix + 1, iy + 1) == 0) continue;
				int mybin = h_OccupancyEE2[k] -> FindBin(ix, iy);
				int ring  = int(hrings[k]-> GetBinContent(mybin));
				float occ = h_OccupancyEE2[k]->GetBinContent(mybin);
				if(k == 0) {
					sumHitEEM.at(ring) = sumHitEEM.at(ring) + occ;
					nHitEEM.at(ring) = nHitEEM.at(ring) + 1;
				}
				if(k == 1) {
					sumHitEEP.at(ring) = sumHitEEP.at(ring) + occ;
					nHitEEP.at(ring) = nHitEEP.at(ring) + 1;
				}
			}
		}
	}

	for(int k = 0; k < 2 ; k++) {
		nPoint = 0;
		if(k == 0) {
			for(unsigned int iring = 0; iring < sumHitEEM.size() ; iring++) {
				if(sumHitEEM.at(iring) != 0 && nHitEEM.at(iring) != 0) {
					OccupancyAll2->SetPoint(nPointAll2, -1.*(85 * xtalWidth + iring * etaringEE), sumHitEEM.at(iring) / (nHitEEM.at(iring)*luminosity));
					OccupancyAll2->SetPointError(nPointAll2, 0., (sumHitEEM.at(iring) / (nHitEEM.at(iring)*luminosity)) / sqrt(nHitEEM.at(iring)*luminosity));
					nPoint++;
					nPointAll2++;
				}
				if(sumHitEEM.at(iring) == 0 || nHitEEM.at(iring) == 0) {
					OccupancyAll2->SetPoint(nPointAll2, -1.*(85 * xtalWidth + iring * etaringEE), 0.);
					OccupancyAll2->SetPointError(nPointAll2, 0., 0.);
					nPoint++;
					nPointAll2++;
				}
			}

		}
		if(k == 1) {
			for(unsigned int iring = 0; iring < sumHitEEP.size() ; iring++) {
				if(sumHitEEP.at(iring) != 0 && nHitEEP.at(iring) != 0) {
					OccupancyAll2->SetPoint(nPointAll2, (85 * xtalWidth + iring * etaringEE), sumHitEEP.at(iring) / (nHitEEP.at(iring)*luminosity));
					OccupancyAll2->SetPointError(nPointAll2, 0., (sumHitEEP.at(iring) / (nHitEEP.at(iring)*luminosity)) / sqrt(nHitEEP.at(iring)*luminosity));
					nPoint++;
					nPointAll2++;
				}
				if(sumHitEEP.at(iring) == 0 && nHitEEP.at(iring) == 0) {
					OccupancyAll2->SetPoint(nPointAll2, (85 * xtalWidth + iring * etaringEE), 0.);
					OccupancyAll2->SetPointError(nPointAll2, 0., 0.);
					nPoint++;
					nPointAll2++;
				}

			}
		}
	}

	gROOT->Reset();
	gROOT->SetStyle("Plain");

	gStyle->SetPadTickX(1);
	gStyle->SetPadTickY(1);
	gStyle->SetOptTitle(0);
	gStyle->SetOptStat(0);
	gStyle->SetFitFormat("6.3g");
	gStyle->SetPalette(1);

	gStyle->SetTextFont(42);
	gStyle->SetTextSize(0.05);
	gStyle->SetTitleFont(42, "xyz");
	gStyle->SetTitleSize(0.05);
	gStyle->SetLabelFont(42, "xyz");
	gStyle->SetLabelSize(0.05);
	gStyle->SetTitleXOffset(0.8);
	gStyle->SetTitleYOffset(1.1);
	gROOT->ForceStyle();

	TFile *th = new TFile("output/Occupancy.root", "RECREATE");
	th->cd();

// Final plots
	TCanvas *cEB = new TCanvas ("EB occupancy", "EB occupancy");
	cEB->cd();
	cEB->SetGridx();
	cEB->SetGridy();
	h_OccupancyEB->Write();
	th->Close();


// Final plots
	TCanvas *cEEp = new TCanvas ("EE+ occupancy", "EE+ occupancy");
	cEEp->cd();
	cEEp->SetGridx();
	cEEp->SetGridy();
	OccupancyEEP_vs_Eta->SetMarkerStyle(20);
	OccupancyEEP_vs_Eta->SetMarkerColor(kGreen + 2);
	OccupancyEEP_vs_Eta->GetHistogram()->GetXaxis()-> SetRangeUser(1.5, 2.5);
	OccupancyEEP_vs_Eta->GetHistogram()->GetYaxis()-> SetTitle("Single xtal Event / fb^{-1}");
	OccupancyEEP_vs_Eta->GetHistogram()->GetXaxis()-> SetTitle("#eta");
	OccupancyEEP_vs_Eta->Draw("ap");


// Final plots
	TCanvas *cEEm = new TCanvas ("EE- occupancy", "EE- occupancy");
	cEEm->cd();
	cEEm->SetGridx();
	cEEm->SetGridy();
	OccupancyEEM_vs_Eta->SetMarkerStyle(20);
	OccupancyEEM_vs_Eta->SetMarkerColor(kGreen + 2);
	OccupancyEEM_vs_Eta->GetHistogram()->GetXaxis()-> SetRangeUser(-2.5, -1.5);
	OccupancyEEM_vs_Eta->GetHistogram()->GetYaxis()-> SetTitle("Single xtal Event / fb^{-1}");
	OccupancyEEM_vs_Eta->GetHistogram()->GetXaxis()-> SetTitle("#eta");
	OccupancyEEM_vs_Eta->Draw("ap");


	TCanvas* cAll = new TCanvas("cAll", "history plot vs date", 1);
	cAll ->cd();
	cAll ->SetGridx();
	cAll ->SetGridy();
	OccupancyAll->SetMarkerStyle(20);
	OccupancyAll->SetMarkerColor(kRed + 2);
	OccupancyAll->GetHistogram()->GetXaxis()-> SetRangeUser(-2.55, 2.55);
	OccupancyAll->GetHistogram()->GetYaxis()-> SetTitle("Number of Electrons / Crystal / fb^{-1}");
	OccupancyAll->GetHistogram()->GetXaxis()-> SetTitle("#eta_{seed}");
	OccupancyAll->Draw("ap");
	OccupancyAll2->SetMarkerStyle(20);
	OccupancyAll2->SetMarkerColor(kGreen + 2);
	OccupancyAll2->Draw("psame");
	TLegend * leg = new TLegend(0.5, 0.7, 0.6, 0.87);
	leg->SetFillColor(0);
	leg->AddEntry(OccupancyAll, "Preselected Events", "LP");
	leg->AddEntry(OccupancyAll2, "Events Used For Calibration", "LP");
	leg->Draw("same");


	char latexBuffer[250];

	sprintf(latexBuffer, "CMS 2012 Preliminary");
	TLatex* latex = new TLatex(0.18, 0.92, latexBuffer);
	latex -> SetNDC();
	latex -> SetTextFont(62);
	latex -> SetTextSize(0.035);
	latex -> Draw("same");

	sprintf(latexBuffer, "#sqrt{s} = 8 TeV   L = 11.35 fb^{-1}");
	TLatex* latex2 = new TLatex(0.6, 0.92, latexBuffer);
	latex2 -> SetNDC();
	latex2 -> SetTextFont(42);
	latex2 -> SetTextSize(0.035);
	latex2 -> Draw("same");

	cAll -> Print(("EleOccupancy_W_" + category + ".C").c_str(), "cxx");

	return 0;
}
//===============================================================================
void Calibration(){

  //===============================================================================
  gStyle->SetOptTitle(0);

  //The root files with the individual plots 
  const int numberoffiles = 4;
  const int numberofchambers = 6;

  TString filename[numberoffiles];
  //mu-
  filename[0]="testcalo_mu-_50.root";
  filename[1]="testcalo_mu-_100.root";
  filename[2]="testcalo_mu-_150.root";
  filename[3]="testcalo_mu-_200.root";

  //Energy distributions we want to fit 
  TString energy[numberofchambers];
  //nosmear
  // energy[0] = "histo/6";
  // energy[1] = "histo/7";
  // energy[2] = "histo/8";
  // energy[3] = "histo/9";
  // energy[4] = "histo/10";
  // energy[5] = "histo/11";

  //smeared
  energy[0] = "histo/18";
  energy[1] = "histo/19";
  energy[2] = "histo/20";
  energy[3] = "histo/21";
  energy[4] = "histo/22";
  energy[5] = "histo/23";

  double mpshift = 0;//-0.22278298;

  TGraphErrors *grMPV[numberoffiles];
  TString mpvname[numberoffiles];
  
  TGraphErrors *grSigma[numberoffiles];
  TString sigmaname[numberoffiles];

  //For the mpv and sigma plot 
  std::vector<double> chamb;
  std::vector<double> mpv;
  std::vector<double> thesigma;
  std::vector<double> chamr;
  std::vector<double> mpvr;
  std::vector<double> thesigmaerr;
  chamb.push_back(1.);chamb.push_back(2.);chamb.push_back(3.);chamb.push_back(4.);chamb.push_back(5.);chamb.push_back(6.);
  
  //======================================================================================
  //Canvas
  TCanvas *can[numberoffiles][numberofchambers];
  TString canname;

  TCanvas *canmpv[numberoffiles];
  //======================================================================================
  //Read the files and histograms here
  TFile* files[numberoffiles];
  for (int k=0; k<numberoffiles; k++){
    files[k]= new TFile(filename[k]);
  }
  TH1F * histo[numberoffiles][numberofchambers];

  for (int i=0; i<numberoffiles; i++){
    gROOT->Reset();
    for (int k=0; k<numberofchambers; k++){
      histo[i][k]= (TH1F*) files[i]->Get(energy[k]);

      if (!histo[i][k]){std::cerr << "Could not get histogram " << energy[k] << "in file "
				    <<  files[i]->GetName() << std::endl;}
      std::cout << "=========================================================================" << std::endl;
      std::cout << files[i]->GetName() << std::endl;

      canname = filename[i] + histo[i][k]->GetName();
      can[i][k] = new TCanvas(canname, canname,800,600);
      can[i][k]->cd();

      histo[i][k]->Draw();

      TF1 *fit = 0;
      double mpc = 0;
      double minfit = 0.;
      double maxfit = 0.05;

      histo[i][k]->Fit("landau","R+","same",minfit,maxfit);
      fit = (TF1*) histo[i][k]->GetFunction("landau");

      mpc = fit->GetParameter(1) - mpshift * fit->GetParameter(2); 

      mpv.push_back(mpc);
      mpvr.push_back(fit->GetParError(1));
      chamr.push_back(0.);

      thesigma.push_back(fit->GetParameter(2));
      thesigmaerr.push_back(fit->GetParError(2));

      // if(i==0) {mpvname = "grMPV_50GeV"; sigmaname = "grSigma_50GeV";}
      // if(i==1) {mpvname = "grMPV_100GeV";sigmaname = "grSigma_100GeV";}
      // if(i==2) {mpvname = "grMPV_150GeV";sigmaname = "grSigma_150GeV";}
      // if(i==3) {mpvname = "grMPV_200GeV";sigmaname = "grSigma_200GeV";}
      mpvname[i] = "grMPV_" + filename[i]; 
      sigmaname[i] = "grSigma" + filename[i];
      
      // std::cout << "Chamber " << k << " MPV "<< mpc << std::endl;

      can[i][k]->Print(canname + ".root",".root");
      can[i][k]->Close();
  
      
    }// end of loop over histos   

    TGraphErrors *gr = new TGraphErrors(mpv.size(),&chamb[0],&mpv[0],&mpvr[0],&chamr[0]);
    gr->SetMarkerStyle(20); 
    gr->SetMarkerSize(1.0); 
    // gr->GetYaxis()->SetRangeUser(0.,100.);
    //gr->GetXaxis()->SetRangeUser(0.,300.);
    gr->SetTitle(mpvname[i]);
    gr->GetHistogram()->SetXTitle(" Chamber  ");
    gr->GetHistogram()->SetYTitle(" Landau MPV (MIPs)  ");
    gr->GetYaxis()->SetTitleOffset(1.6);
    TCanvas *c1 = new TCanvas("c1","mpv",200,10,700,500);
    gr->Draw("APL");
    c1->Update();

    c1->Print(mpvname[i]+".png",".png");
    c1->Close();

    mpv.clear();
    mpvr.clear();
    
    TGraphErrors *grs = new TGraphErrors(thesigma.size(),&chamb[0],&thesigma[0],&thesigmaerr[0],&chamr[0]);
    grs->SetMarkerStyle(20); 
    grs->SetMarkerSize(1.0); 
    // grs->GetYaxis()->SetRangeUser(0.,100.);
    //grs->GetXaxis()->SetRangeUser(0.,300.);
    grs->SetTitle(sigmaname[i]);
    grs->GetHistogram()->SetXTitle(" Chamber  ");
    grs->GetHistogram()->SetYTitle(" Sigma ");
    grs->GetYaxis()->SetTitleOffset(1.6);
    TCanvas *c2 = new TCanvas("c2","sigma",200,10,700,500);
    grs->Draw("APL");
    c2->Update();

    c2->Print(sigmaname[i]+".png",".png");
    c2->Close();

    thesigma.clear();
    thesigmaerr.clear();
    chamr.clear();


    gr->Delete();
    c1->Close();
    c1->Close();


  }// end of loop over files
  
  
  


}
示例#4
0
void t1pfmetPhiwithCorr(double pt1min, double pt2min, double METmin, double DPHImin){
gStyle->SetPadTickY(1);
gStyle->SetPadTickX(1);

int  i = 0;
  TLegend* leg = new TLegend(0.35,0.65,0.87,0.87);
  leg->SetNColumns(2);
  leg->SetBorderSize(0);
  leg->SetFillStyle(0);

  TCanvas *canvas = new TCanvas("c1n","",500,600);
  TPad *mainPad = new TPad("mainPad","",0,0.3,1,1);
  TPad *smallPad = new TPad("smallPad","",0,0.05,1,0.3);
  mainPad->SetBottomMargin(0.015);


  smallPad->SetTopMargin(0.05);
  smallPad->SetBottomMargin(0.25);

  canvas->cd();

  mainPad->Draw();
  mainPad->cd();







 
  //  gPad->SetLogy();
  TCut mggmax = "mgg<180";
  TCut mggmin = "mgg>100";
  TCut pt1Cut = Form("pt1/mgg>%lf",pt1min);
  TCut pt2Cut = Form("pt2/mgg>%lf",pt2min);
  //  TCut METCut = Form("t1pfmetCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0)>%lf",METmin);
  TCut METCut = "";
 TCut DPHICut =  Form("Delta(pt1,eta1,phi1,pt2,eta2,phi2,t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>%lf",DPHImin);
  TCut eveto1 = "eleveto1 == 1";
  TCut eveto2 = "eleveto2 == 1";
  TCut eveto = eveto1 && eveto2;
  TCut genmatch = "((genmatch1==1 && genmatch2==0)||(genmatch1==0 && genmatch2==1)||(genmatch1==0 && genmatch2==0))";  
  TCut metF = "((metF_GV==1) && (metF_HBHENoise==1) && (metF_HBHENoiseIso==1) && (metF_CSC==1) && (metF_eeBadSC==1))";  
  TCut NegWeight = "weight>0.";

  /* 
     TFile *M1 =  TFile::Open("./50ns_betaV3/NewWeightDMHtoGG_M1.root","READ");  
     TFile *M10 =  TFile::Open("./50ns_betaV3/NewWeightDMHtoGG_M10.root","READ");
     TFile *M100 =  TFile::Open("./50ns_betaV3/NewWeightDMHtoGG_M100.root","READ");  
     TFile *M1000 =  TFile::Open("./50ns_betaV3/NewWeightDMHtoGG_M1000.root","READ");
  */

  TFile *data = TFile::Open("./25ns_2246inv_v3/DoubleEG.root","READ");
  
  TFile *sig1 = TFile::Open("./25ns_2246inv_v3/2HDM_mZP600.root","READ");
  TFile *sig2 = TFile::Open("./25ns_2246inv_v3/2HDM_mZP800.root","READ");
  TFile *sig3 = TFile::Open("./25ns_2246inv_v3/2HDM_mZP1000.root","READ");
  TFile *sig4 = TFile::Open("./25ns_2246inv_v3/2HDM_mZP1200.root","READ");
  TFile *sig5 = TFile::Open("./25ns_2246inv_v3/2HDM_mZP1400.root","READ");  
  TFile *sig6 = TFile::Open("./25ns_2246inv_v3/2HDM_mZP1700.root","READ");
  TFile *sig7 = TFile::Open("./25ns_2246inv_v3/2HDM_mZP2500.root","READ");
  /*
    TFile *bkg1 =  TFile::Open("./50ns_betaV3/DiPhoton.root","READ");  
    TFile *bkg2 =  TFile::Open("./50ns_betaV3/DYJetsToLL.root","READ");  
    TFile *bkg3 =  TFile::Open("./50ns_betaV3/GJets.root","READ");  
    TFile *bkg4 =  TFile::Open("./50ns_betaV3/GluGluHToGG.root","READ");  
    TFile *bkg5 =  TFile::Open("./50ns_betaV3/QCD.root","READ");  
    TFile *bkg6 =  TFile::Open("./50ns_betaV3/VH.root","READ");  
  */

  TFile *bkg1 =  TFile::Open("./25ns_2246inv_v3/DiPhoton.root","READ");  
  TFile *bkg2 =  TFile::Open("./25ns_2246inv_v3/DYJetsToLL.root","READ");  
  TFile *bkg3 =  TFile::Open("./25ns_2246inv_v3/GJets.root","READ");  
  TFile *bkg4 =  TFile::Open("./25ns_2246inv_v3/GluGluHToGG.root","READ");  
  TFile *bkg5 =  TFile::Open("./25ns_2246inv_v3/QCD.root","READ");  
  TFile *bkg6 =  TFile::Open("./25ns_2246inv_v3/VH.root","READ");  
  TFile *bkg7 =  TFile::Open("./25ns_2246inv_v3/ttHJetToGG.root","READ");
  TFile *bkg8 =  TFile::Open("./25ns_2246inv_v3/VBFHToGG.root","READ");
  TFile *bkg9 =  TFile::Open("./25ns_2246inv_v3/TGJets.root","READ");
  TFile *bkg10 =  TFile::Open("./25ns_2246inv_v3/TTGJets.root","READ");
  TFile *bkg11 =  TFile::Open("./25ns_2246inv_v3/WGToLNuG.root","READ");
  TFile *bkg12 =  TFile::Open("./25ns_2246inv_v3/ZGTo2LG.root","READ");
  /*
    TTree *tree_M1 = (TTree*) M1->Get("DiPhotonTree");
    TTree *tree_M10 = (TTree*) M10->Get("DiPhotonTree");
    TTree *tree_M100 = (TTree*) M100->Get("DiPhotonTree");
    TTree *tree_M1000 = (TTree*) M1000->Get("DiPhotonTree");
  */

  TTree *tree_data = (TTree*) data->Get("DiPhotonTree");
  
  TTree *tree_sig1 = (TTree*) sig1->Get("DiPhotonTree");
  TTree *tree_sig2 = (TTree*) sig2->Get("DiPhotonTree");
  TTree *tree_sig3 = (TTree*) sig3->Get("DiPhotonTree");
  TTree *tree_sig4 = (TTree*) sig4->Get("DiPhotonTree");
  TTree *tree_sig5 = (TTree*) sig5->Get("DiPhotonTree");
  TTree *tree_sig6 = (TTree*) sig6->Get("DiPhotonTree");
  TTree *tree_sig7 = (TTree*) sig7->Get("DiPhotonTree");
 
  
  
  TTree *tree_bkg1 = (TTree*) bkg1->Get("DiPhotonTree");
  TTree *tree_bkg2 = (TTree*) bkg2->Get("DiPhotonTree");
  TTree *tree_bkg3 = (TTree*) bkg3->Get("DiPhotonTree");
  TTree *tree_bkg4 = (TTree*) bkg4->Get("DiPhotonTree");
  TTree *tree_bkg5 = (TTree*) bkg5->Get("DiPhotonTree");
  TTree *tree_bkg6 = (TTree*) bkg6->Get("DiPhotonTree");
  TTree *tree_bkg7 = (TTree*) bkg7->Get("DiPhotonTree");
  TTree *tree_bkg8 = (TTree*) bkg8->Get("DiPhotonTree");
  TTree *tree_bkg9 = (TTree*) bkg9->Get("DiPhotonTree");
  TTree *tree_bkg10 = (TTree*) bkg10->Get("DiPhotonTree");
  TTree *tree_bkg11 = (TTree*) bkg11->Get("DiPhotonTree");
  TTree *tree_bkg12 = (TTree*) bkg12->Get("DiPhotonTree");
  
  
  /* 
     tree_M1->Draw("(t1pfmet)>>h1(30,100,200)","weight*10"*(mggmax && mggmin && pt1Cut && pt2Cut && METCut && eveto && Cut_Jets));
     TH1F *h1 =(TH1F*)gPad->GetPrimitive("h1");
     tree_M10->Draw("(t1pfmet)>>h2(30,100,200)","weight*10"*(mggmax && mggmin && pt1Cut && pt2Cut && METCut && eveto && Cut_Jets));
     TH1F *h2 =(TH1F*)gPad->GetPrimitive("h2");
     tree_M100->Draw("(t1pfmet)>>h3(30,100,200)","weight*10"*(mggmax && mggmin && pt1Cut && pt2Cut && METCut && eveto && Cut_Jets));
     TH1F *h3 =(TH1F*)gPad->GetPrimitive("h3");
     tree_M1000->Draw("(t1pfmet)>>h4(30,100,200)","weight*10"*(mggmax && mggmin && pt1Cut && pt2Cut && METCut && eveto && Cut_Jets));
     TH1F *h4 =(TH1F*)gPad->GetPrimitive("h4");  
  */
  
  tree_data->Draw("(t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,1))>>hdata(10,-4,4)","(mgg<115||mgg>135)"*(mggmax && mggmin && pt1Cut && pt2Cut && eveto && METCut  && metF&& DPHICut ));
  TH1F *hdata =(TH1F*)gPad->GetPrimitive("hdata");

  tree_sig1->Draw("(t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>h1(10,-4,4)","weight*(mgg<115||mgg>135)"*(mggmax && mggmin && pt1Cut && pt2Cut && METCut && eveto  && DPHICut));
  TH1F *h1 =(TH1F*)gPad->GetPrimitive("h1");
  tree_sig2->Draw("(t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>h2(10,-4,4)","weight*(mgg<115||mgg>135)"*(mggmax && mggmin && pt1Cut && pt2Cut && METCut && eveto  && DPHICut));
  TH1F *h2 =(TH1F*)gPad->GetPrimitive("h2");
  tree_sig3->Draw("(t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>h3(10,-4,4)","weight*(mgg<115||mgg>135)"*(mggmax && mggmin && pt1Cut && pt2Cut && METCut && eveto  && DPHICut));
  TH1F *h3 =(TH1F*)gPad->GetPrimitive("h3");
  tree_sig4->Draw("(t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>h4(10,-4,4)","weight*(mgg<115||mgg>135)"*(mggmax && mggmin && pt1Cut && pt2Cut && METCut && eveto  && DPHICut));
  TH1F *h4 =(TH1F*)gPad->GetPrimitive("h4");
  tree_sig5->Draw("(t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>h5(10,-4,4)","weight*(mgg<115||mgg>135)"*(mggmax && mggmin && pt1Cut && pt2Cut && METCut && eveto  && DPHICut));
  TH1F *h5 =(TH1F*)gPad->GetPrimitive("h5");
  tree_sig6->Draw("(t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>h6(10,-4,4)","weight*(mgg<115||mgg>135)"*(mggmax && mggmin && pt1Cut && pt2Cut && METCut && eveto  && DPHICut));
  TH1F *h6 =(TH1F*)gPad->GetPrimitive("h6");
  tree_sig7->Draw("(t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>h7(10,-4,4)","weight*(mgg<115||mgg>135)"*(mggmax && mggmin && pt1Cut && pt2Cut && METCut && eveto  && DPHICut));
  TH1F *h7 =(TH1F*)gPad->GetPrimitive("h7");

  





  tree_bkg1->Draw("(t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>hbkg1(10,-4,4)","weight*(mgg<115||mgg>135)"*(mggmax && mggmin && pt1Cut && pt2Cut && METCut && eveto  && DPHICut));
  TH1F *hbkg1 =(TH1F*)gPad->GetPrimitive("hbkg1");
  tree_bkg2->Draw("(t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>hbkg2(10,-4,4)","weight*(mgg<115||mgg>135)"*(mggmax && mggmin && pt1Cut && pt2Cut && METCut && eveto  && DPHICut));
  TH1F *hbkg2 =(TH1F*)gPad->GetPrimitive("hbkg2");
  tree_bkg3->Draw("(t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>hbkg3(10,-4,4)","weight*(mgg<115||mgg>135)"*(mggmax && mggmin && pt1Cut && pt2Cut && METCut && eveto  && genmatch && DPHICut));
  TH1F *hbkg3 =(TH1F*)gPad->GetPrimitive("hbkg3");
     
tree_bkg4->Draw("(t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>hbkg4(10,-4,4)","weight*(mgg<115||mgg>135)"*(mggmax && mggmin && pt1Cut && pt2Cut && METCut && eveto  && DPHICut)); 
  TH1F *hbkg4 =(TH1F*)gPad->GetPrimitive("hbkg4");
  tree_bkg5->Draw("(t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>hbkg5(10,-4,4)","weight*(mgg<115||mgg>135)"*(mggmax && mggmin && pt1Cut && pt2Cut && METCut && eveto  && genmatch && DPHICut));
  TH1F *hbkg5 =(TH1F*)gPad->GetPrimitive("hbkg5");
  tree_bkg6->Draw("(t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>hbkg6(10,-4,4)","weight*(mgg<115||mgg>135)"*(mggmax && mggmin && pt1Cut && pt2Cut && METCut && eveto  && DPHICut));
  TH1F *hbkg6 =(TH1F*)gPad->GetPrimitive("hbkg6");  
  tree_bkg7->Draw("(t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>hbkg7(10,-4,4)","weight*(mgg<115||mgg>135)"*(mggmax && mggmin && pt1Cut && pt2Cut && METCut && eveto  && DPHICut));
  TH1F *hbkg7 =(TH1F*)gPad->GetPrimitive("hbkg7");  
  tree_bkg8->Draw("(t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>hbkg8(10,-4,4)","weight*(mgg<115||mgg>135)"*(mggmax && mggmin && pt1Cut && pt2Cut && METCut && eveto  && DPHICut));
  TH1F *hbkg8 =(TH1F*)gPad->GetPrimitive("hbkg8");  
  tree_bkg9->Draw("(t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>hbkg9(10,-4,4)","weight*(mgg<115||mgg>135)"*(mggmax && mggmin && pt1Cut && pt2Cut && METCut && eveto  && DPHICut)); 
  TH1F *hbkg9 =(TH1F*)gPad->GetPrimitive("hbkg9");  
  tree_bkg10->Draw("(t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>hbkg10(10,-4,4)","weight*(mgg<115||mgg>135)"*(mggmax && mggmin && pt1Cut && pt2Cut && METCut && eveto  && DPHICut));
  TH1F *hbkg10 =(TH1F*)gPad->GetPrimitive("hbkg10");  
 tree_bkg11->Draw("(t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>hbkg11(10,-4,4)","weight*(mgg<115||mgg>135)"*(mggmax && mggmin && pt1Cut && pt2Cut && METCut && eveto  && DPHICut));
  TH1F *hbkg11 =(TH1F*)gPad->GetPrimitive("hbkg11");  
 tree_bkg12->Draw("(t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>hbkg12(10,-4,4)","weight*(mgg<115||mgg>135)"*(mggmax && mggmin && pt1Cut && pt2Cut && METCut && eveto  && DPHICut));
  TH1F *hbkg12 =(TH1F*)gPad->GetPrimitive("hbkg12");  



 

  hdata->SetMarkerColor(kBlack);
  hdata->SetLineColor(kBlack);
  hdata->SetMarkerStyle(20);
  
  h1->SetLineColor(kRed+3);
  h2->SetLineColor(kRed+1);
  h3->SetLineColor(kRed);
  h4->SetLineColor(kPink+2);
  h5->SetLineColor(kPink+4);
 h6->SetLineColor(kPink+7);
 h7->SetLineColor(kMagenta+2);
 h1->SetLineWidth(2);
 h2->SetLineWidth(2);
 h3->SetLineWidth(2);
 h4->SetLineWidth(2);
 h5->SetLineWidth(2);
 h6->SetLineWidth(2);
 h7->SetLineWidth(2);


  
  
  THStack *hs=new THStack("hs","");
  hbkg7->SetFillColor(kGreen+2);
  hbkg6->SetFillColor(kGreen);
  hbkg8->SetFillColor(kYellow);
  hbkg4->SetFillColor(kOrange);
  hbkg9->SetFillColor(kOrange+7);
  hbkg10->SetFillColor(kOrange+4);
  hbkg11->SetFillColor(kCyan);
  hbkg12->SetFillColor(kCyan+1);
  hbkg5->SetFillColor(kBlue+2);
  hbkg2->SetFillColor(kBlue);  
  hbkg3->SetFillColor(kMagenta-2);
  hbkg1->SetFillColor(kViolet);

  hbkg1->SetLineColor(kBlack);
  hbkg2->SetLineColor(kBlack);
  hbkg3->SetLineColor(kBlack);
  hbkg4->SetLineColor(kBlack);
  hbkg5->SetLineColor(kBlack);
  hbkg6->SetLineColor(kBlack);
  hbkg7->SetLineColor(kBlack);
  hbkg8->SetLineColor(kBlack);
  hbkg9->SetLineColor(kBlack);
  hbkg10->SetLineColor(kBlack);
  hbkg11->SetLineColor(kBlack);
  hbkg12->SetLineColor(kBlack);

  hs->Add(hbkg7);
  hs->Add(hbkg6);
  hs->Add(hbkg8);
  hs->Add(hbkg4);
  hs->Add(hbkg9);
  hs->Add(hbkg10);
  hs->Add(hbkg11);
  hs->Add(hbkg12);
  hs->Add(hbkg2);
  hs->Add(hbkg5);
  hs->Add(hbkg3);
  hs->Add(hbkg1);
  
  TH1F *hsum = (TH1F*)hbkg1->Clone("hsum"); 
  hsum->Add(hbkg2);
  hsum->Add(hbkg3);
  hsum->Add(hbkg4);
  hsum->Add(hbkg5);
  hsum->Add(hbkg6);
  hsum->Add(hbkg7);
  hsum->Add(hbkg8);
  hsum->Add(hbkg9);
  hsum->Add(hbkg10);
  hsum->Add(hbkg11);
  hsum->Add(hbkg12);
  


  canvas->SetLeftMargin(0.12);

  // hs->SetMinimum(0.01);
  hs->SetMaximum(5700);

  hs->SetTitle("");
  hs->Draw("HIST"); 
  hsum->SetMarkerStyle(1);
  hsum->SetFillColor(kGray+3);
  hsum->SetFillStyle(3002);
  hsum->Draw("same e2");
  //  h2->Draw("same hist");
  // h3->Draw("same hist"); 
  // h4->Draw("same hist");
  // h1->Draw("same hist");
  //h5->Draw("same hist"); //only for 25ns samples
  //h7->Draw("same hist"); //only for 25ns samples
  // h6->Draw("same hist"); //only for 25ns samples
  hdata->Draw("same E1");
  

  hs->GetXaxis()->SetLabelOffset(999);
  hs->GetYaxis()->SetTitleOffset(1.5);
  hs->GetYaxis()->SetTitle("Events/0.8");  
  //int  iPos = 11;
//  CMS_lumi(canvas,true,iPos,false);
  gPad->Modified();


  leg->AddEntry(hdata,"Data","elp");
  /*leg->AddEntry(h1,"m_{#chi} = 1 GeV","l");
  leg->AddEntry(h2,"m_{#chi} = 10 GeV","l");
  leg->AddEntry(h3,"m_{#chi} = 100 GeV","l");      
  leg->AddEntry(h4,"m_{#chi} = 1000 GeV","l");*/
  //  leg->AddEntry(h1,"m_{Z'} = 600 GeV","l");
  leg->AddEntry(hbkg1,"#gamma #gamma","f");
  // leg->AddEntry(h2,"m_{Z'} = 800 GeV","l");
  leg->AddEntry(hbkg2,"Drell Yann","f");
  // leg->AddEntry(h3,"m_{Z'} = 1000 GeV","l");
  leg->AddEntry(hbkg3,"#gamma + Jets","f");
  // leg->AddEntry(h4,"m_{Z'} = 1200 GeV","l");
  leg->AddEntry(hbkg5,"QCD","f");
  // leg->AddEntry(h5,"m_{Z'} = 1400 GeV","l"); //only for 25ns samples                                                              
  leg->AddEntry(hbkg4,"ggH","f");
  //leg->AddEntry(h6,"m_{Z'} = 1700 GeV","l"); //only for 25ns samples                                                              
  leg->AddEntry(hbkg6,"VH","f");
  // leg->AddEntry(h7,"m_{Z'} = 2500 GeV","l"); //only for 25ns samples                                                              
  leg->AddEntry(hbkg7,"ttH","f");
  leg->AddEntry(hbkg8,"VBF H","f");
  leg->AddEntry(hbkg9,"t + #gamma + Jets","f");
  leg->AddEntry(hbkg10,"tt + #gamma +Jets","f");
  leg->AddEntry(hbkg11,"#gamma+W","f");
  leg->AddEntry(hbkg12,"#gamma+Z","f");
 leg->AddEntry(hsum,"Bkg uncertainty","f");
  leg->Draw("same");




  
  gStyle->SetOptStat(0);  
 

  canvas->cd();
  smallPad->Draw();
  smallPad->cd();

  TGraphErrors *gr = new TGraphErrors(0);
  double integralData=hdata->Integral();
  double integralBKG=hsum->Integral();
  double error, ratio;
  for(int w=1; w<20; w++){
    if((hdata->GetBinContent(w)!=0) && (hsum->GetBinContent(w)!=0)){

      gr->SetPoint(w, hdata->GetBinCenter(w),(hdata->GetBinContent(w))/(hsum->GetBinContent(w)));
      ratio= (hdata->GetBinContent(w))/(hsum->GetBinContent(w));
      error= (hdata->GetBinContent(w)*sqrt(hsum->GetBinContent(w))/(hsum->GetBinContent(w)*hsum->GetBinContent(w)) + sqrt(hdata->GetBinContent(w))/hsum->GetBinContent(w));
      std::cout<<"VALUE: "<<ratio<<" ERROR: "<<error<<std::endl;
      gr->SetPointError(w, hdata->GetBinWidth(w)/2,error);
    }else{
      gr->SetPoint(w, hdata->GetBinCenter(w),10);
    }
  }



  gStyle->SetPadTickY(1);
  gStyle->SetPadTickX(1);
  gr->GetHistogram()->SetMaximum(2);
  gr->GetHistogram()->SetMinimum(0.1);

  gStyle->SetTextSize(14);
  gROOT->ForceStyle();

  gr->GetXaxis()->SetLabelFont(43);
  gr->GetXaxis()->SetLabelSize(15);
  gr->GetYaxis()->SetLabelFont(43);
  gr->GetYaxis()->SetLabelSize(15);

  gr->GetXaxis()->SetLimits(-4,4);


  gPad->SetGrid();
  gStyle->SetStripDecimals(kTRUE);
  gr->SetMarkerStyle(20);
  gr->SetMarkerSize(0.7);


  gr->Draw("AZP");
  gr->GetXaxis()->SetTitle("#phi_{MET}^{corr}");
  gr->GetXaxis()->SetTitleSize(0.1);
  gr->GetYaxis()->SetTitleSize(0.1);
  gr->GetYaxis()->SetNdivisions(505);

  gr->GetXaxis()->SetTitleOffset(1);
  gr->GetYaxis()->SetTitle("Data/MC");
  gr->GetYaxis()->SetTitleOffset(0.4);
  gr->SetTitle("");
  smallPad->Update();
  TF1* line = new TF1("line","1",-4,4);
  line->SetLineColor(kRed);
  line->SetLineWidth(2);
  line->Draw("L same");
  gr->Draw("ZP SAME");


  canvas->SaveAs(Form("./25ns_2246inv_v3/plots/kinematics/metphicorr_MET%.0lf.pdf",METmin)); 
  canvas->SaveAs(Form("./25ns_2246inv_v3/plots/kinematics/metphicorr_MET%.0lf.png",METmin)); 
    
}
void HwwNoteFigs(TString filename = "../histo_tmva_new-ntuples-1_160_0.root",
                 int mass = 170, int ReBin = 4, int ysel = 0)
{
	TFile* infile = new TFile(filename.Data(),"READ");
	setTDRStyle(0);
	
	//BDTD dists
	TCanvas* c1 = new TCanvas("c1","c1",0,-200,500,500);
	
        TH1F* histoBg =  histo4->Clone();
        histoBg->Add(histo3);
        histoBg->Add(histo2);
        histoBg->Add(histo1);

    	TH1F* histo_4 =  histo4->Clone();
    	histo3->Add(histo_4);
    	TH1F* histo_3 =  histo3->Clone();
    	histo2->Add(histo_3);
    	TH1F* histo_2 =  histo2->Clone();
    	histo1->Add(histo_2);

        histo1->Rebin(ReBin);
        histo1->SetFillColor(kBlue);
        histo1->SetFillStyle(1001);
        histo1->SetLineStyle(0);
        histo1->SetLineWidth(0);

        histo2->Rebin(ReBin);
        histo2->SetFillColor(kMagenta);
        histo2->SetFillStyle(1001);
        histo2->SetLineStyle(0);
        histo2->SetLineWidth(0);

        histo3->Rebin(ReBin);
        histo3->SetFillColor(kGreen);
        histo3->SetFillStyle(1001);
        histo3->SetLineStyle(0);
        histo3->SetLineWidth(0);
        
        histo4->Rebin(ReBin);
        histo4->SetFillColor(kCyan);
        histo4->SetFillStyle(1001);
        histo4->SetLineStyle(0);
        histo4->SetLineWidth(0);

        char YTitle[300];
        sprintf(YTitle,"events / bin");
        char XTitle[300];
        sprintf(XTitle,"BDT Output");
    	histo0->SetYTitle(YTitle);
    	histo1->SetYTitle(YTitle);
    	histo2->SetYTitle(YTitle);
    	histo3->SetYTitle(YTitle);
    	histo4->SetYTitle(YTitle);

    	histo0->SetXTitle(XTitle);
    	histo1->SetXTitle(XTitle);
    	histo2->SetXTitle(XTitle);
    	histo3->SetXTitle(XTitle);
    	histo4->SetXTitle(XTitle);
    	histo1->SetTitleSize(0.05, "X");
    	histo1->GetXaxis()->SetTitleFont(62);
    	histo1->GetXaxis()->SetLabelFont(61);
    	histo1->GetYaxis()->SetLabelFont(61); 
    	histo1->GetYaxis()->SetTitleOffset(1.3);
    	histo1->SetLabelSize(0.04, "Y");
    	histo1->SetLabelSize(0.04, "X");

	int min = histoBg->FindBin(-1.5);
	int max = histoBg->FindBin(1.5);

	histoBg->GetXaxis()->SetRange(min,max);
	
	histoBg->SetMarkerStyle(20);
	histoBg->SetMarkerSize(1.0);
	histoBg->GetYaxis()->SetTitleOffset(1.40);
	
	histo0->SetMarkerStyle(21);
	histo0->SetMarkerSize(1.0);
	
	histoBg->Rebin(ReBin);
	histo0->Rebin(ReBin);

	histoBg->SetLineColor(4);
	histo0->SetLineColor(1);

	scaleHist(histoBg);
	scaleHist(histo0);
	cout << "bg events: " << histoBg->GetSumOfWeights() << endl;
	cout << "si events: " << histo0->GetSumOfWeights() << endl;

	histoBg->SetYTitle("Events");
    	histo1->SetMinimum(0.01);
	if(ysel == 0)  {
	  histo1->Draw("hist");
	}
	else          {
	  histo0->Draw("E");
	  histo1->Draw("hist,same");
    	}
	histo2->Draw("hist,same");
    	histo3->Draw("hist,same");
    	histo4->Draw("hist,same");
    	histo0->Draw("E, same");
	//histoBg->DrawCopy("hist");
	//histo0->DrawCopy("hist,same");

	TLegend* leg = new TLegend(0.63, 0.75, 0.92, 0.92);
	leg->SetFillColor(0);
	char theSLine[100];
	if(mass != 999)	sprintf(theSLine,"Signal, m_{H}=%d GeV",mass);
	else    	sprintf(theSLine,"WW");
        cout << theSLine << endl;
	leg ->AddEntry(histo0,theSLine);
    	leg ->AddEntry(histo4,"W+Jets, W#gamma","F"); 
    	leg ->AddEntry(histo3,"di-boson","F");  
    	leg ->AddEntry(histo2,"t#bar{t}, tW","F"); 
    	leg ->AddEntry(histo1,"Drell-Yan","F"); 
	leg->Draw("same");
	
        TString fileOutput1(filename.Data());
	TString theLine = "_";
	theLine = theLine + "plot.eps";
        fileOutput1.ReplaceAll(".root",theLine.Data());
        fileOutput1.ReplaceAll("../","");
        fileOutput1.ReplaceAll("rootfiles_fastsim/","");
        fileOutput1.ReplaceAll("rootfiles_fullsim/","");
	c1->SaveAs(fileOutput1.Data());
        //return;
	//--------------------------------
	TCanvas* c3 = new TCanvas("c3","c3",550,-200,500,500);
	c3->SetLogx();
	c3->SetLogy();
	gPad->SetGrid(1,1);
	TGraphErrors* gBDTD = makeGraphFromHists(histo0, histoBg);
	gBDTD->Draw("APXl");
	TH1* zBDTD = gBDTD->GetHistogram();
	zBDTD->SetXTitle("Signal Events");
	zBDTD->SetYTitle("Signal/Background");
	//zBDTD->SetYTitle("Background Events");
	//zBDTD->DrawCopy();

	TLegend* leg3 = new TLegend(0.7, 0.7, 0.9, 0.9);
	leg3->SetFillColor(0);
	leg3->AddEntry(gBDTD,theSLine,"lp");
	leg3->Draw("same");
        TString fileOutput2(filename.Data());
	theLine = "_";
	theLine = theLine + "counts.eps";
        fileOutput2.ReplaceAll(".root",theLine.Data());
        fileOutput2.ReplaceAll("../","");
        fileOutput2.ReplaceAll("rootfiles_fastsim/","");
        fileOutput2.ReplaceAll("rootfiles_fullsim/","");
	c3->SaveAs(fileOutput2.Data());
	
}
示例#6
0
文件: phi2.C 项目: camendola/macro
void phi2(double pt1min, double pt2min, double METmin){


  TLegend* leg = new TLegend(0.13,0.6,0.87,0.87);
  leg->SetNColumns(3);
  leg->SetBorderSize(0);
  leg->SetFillStyle(0);
  gStyle->SetPadTickY(1);
  gStyle->SetPadTickX(1);

  TFile *data =  TFile::Open("./25ns_2246inv_v3/DoubleEG.root","READ");
  TFile *sig1 = TFile::Open("./25ns_2246inv_v3/2HDM_mZP600.root","READ");
  TFile *sig2 = TFile::Open("./25ns_2246inv_v3/2HDM_mZP800.root","READ");
  TFile *sig3 = TFile::Open("./25ns_2246inv_v3/2HDM_mZP1000.root","READ");
  TFile *sig4 = TFile::Open("./25ns_2246inv_v3/2HDM_mZP1200.root","READ");
  TFile *sig5 = TFile::Open("./25ns_2246inv_v3/2HDM_mZP1400.root","READ");
  TFile *sig6 = TFile::Open("./25ns_2246inv_v3/2HDM_mZP1700.root","READ");
  TFile *sig7 = TFile::Open("./25ns_2246inv_v3/2HDM_mZP2500.root","READ");


  TFile *bkg1 =  TFile::Open("./25ns_2246inv_v3/DiPhoton.root","READ"); 
  TFile *bkg2 =  TFile::Open("./25ns_2246inv_v3/DYJetsToLL.root","READ");
  TFile *bkg3 =  TFile::Open("./25ns_2246inv_v3/GJets.root","READ");  
  TFile *bkg4 =  TFile::Open("./25ns_2246inv_v3/GluGluHToGG.root","READ");
  TFile *bkg5 =  TFile::Open("./25ns_2246inv_v3/QCD.root","READ");
  TFile *bkg6 =  TFile::Open("./25ns_2246inv_v3/VH.root","READ");
  TFile *bkg7 =  TFile::Open("./25ns_2246inv_v3/ttHJetToGG.root","READ");
  TFile *bkg8 =  TFile::Open("./25ns_2246inv_v3/VBFHToGG.root","READ");
  TFile *bkg9 =  TFile::Open("./25ns_2246inv_v3/TGJets.root","READ");
  TFile *bkg10 =  TFile::Open("./25ns_2246inv_v3/TTGJets.root","READ");
  TFile *bkg11 =  TFile::Open("./25ns_2246inv_v3/WGToLNuG.root","READ");
  TFile *bkg12 =  TFile::Open("./25ns_2246inv_v3/ZGTo2LG.root","READ");
 
  TTree *tree_data = (TTree*) data->Get("DiPhotonTree");

  TTree *tree_sig1 = (TTree*) sig1->Get("DiPhotonTree"); 
  TTree *tree_sig2 = (TTree*) sig2->Get("DiPhotonTree"); 
  TTree *tree_sig3 = (TTree*) sig3->Get("DiPhotonTree"); 
  TTree *tree_sig4 = (TTree*) sig4->Get("DiPhotonTree"); 
  TTree *tree_sig5 = (TTree*) sig5->Get("DiPhotonTree"); 
  TTree *tree_sig6 = (TTree*) sig6->Get("DiPhotonTree");
  TTree *tree_sig7 = (TTree*) sig7->Get("DiPhotonTree");  


  TTree *tree_bkg1 = (TTree*) bkg1->Get("DiPhotonTree");
  TTree *tree_bkg2 = (TTree*) bkg2->Get("DiPhotonTree");
  TTree *tree_bkg3 = (TTree*) bkg3->Get("DiPhotonTree");
  TTree *tree_bkg4 = (TTree*) bkg4->Get("DiPhotonTree");
  TTree *tree_bkg5 = (TTree*) bkg5->Get("DiPhotonTree");
  TTree *tree_bkg6 = (TTree*) bkg6->Get("DiPhotonTree");
  TTree *tree_bkg7 = (TTree*) bkg7->Get("DiPhotonTree");
  TTree *tree_bkg8 = (TTree*) bkg8->Get("DiPhotonTree");
  TTree *tree_bkg9 = (TTree*) bkg9->Get("DiPhotonTree");
  TTree *tree_bkg10 = (TTree*) bkg10->Get("DiPhotonTree");
  TTree *tree_bkg11 = (TTree*) bkg11->Get("DiPhotonTree");
  TTree *tree_bkg12 = (TTree*) bkg12->Get("DiPhotonTree");

  TCanvas *c1 = new TCanvas("c1","",500,600);
  TPad *mainPad = new TPad("mainPad","",0,0.3,1,1); 
  TPad *smallPad = new TPad("smallPad","",0,0.05,1,0.3);
  mainPad->SetBottomMargin(0.015);
 
  
  smallPad->SetTopMargin(0.05); 
smallPad->SetBottomMargin(0.25); 

  c1->cd();
  
  mainPad->Draw();
  mainPad->cd(); 
 
  
  
  
  
  
  
  gPad->SetLogy();  
  
  TCut mggmax = "mgg<180";
  TCut mggmin = "mgg>100";
  TCut pt1Cut = Form("pt1/mgg>%lf",pt1min);
  TCut pt2Cut = Form("pt2/mgg>%lf",pt2min);
  TCut METCut = Form("t1pfmet>%lf",METmin);
  TCut eveto1 = "eleveto1 == 1";
  TCut eveto2 = "eleveto2 == 1";
  TCut eveto = eveto1 && eveto2;
  TCut genmatch = "((genmatch1==1 && genmatch2==0)||(genmatch1==0 && genmatch2==1)||(genmatch1==0 && genmatch2==0))";  
  TCut metF = "((metF_GV==1) && (metF_HBHENoise==1) && (metF_HBHENoiseIso==1) && (metF_CSC==1) && (metF_eeBadSC==1))";  
  
  tree_data->Draw("(phi2)>>hdata(20,-4,4)",(mggmax && mggmin && metF&& METCut &&pt1Cut && pt2Cut&& eveto));
  TH1F *hdata =(TH1F*)gPad->GetPrimitive("hdata");
  
  
  tree_sig1->Draw("(phi2)>>h1(20,-4,4)","weight"*(mggmin && mggmax&& METCut &&pt1Cut && pt2Cut&& eveto));
  TH1F *h1 =(TH1F*)gPad->GetPrimitive("h1");
  tree_sig2->Draw("(phi2)>>h2(20,-4,4)","weight"*(mggmin && mggmax&& METCut &&pt1Cut && pt2Cut&& eveto));
  TH1F *h2 =(TH1F*)gPad->GetPrimitive("h2");
  tree_sig3->Draw("(phi2)>>h3(20,-4,4)","weight"*(mggmin && mggmax&& METCut &&pt1Cut && pt2Cut&& eveto));
  TH1F *h3 =(TH1F*)gPad->GetPrimitive("h3");
  tree_sig4->Draw("(phi2)>>h4(20,-4,4)","weight"*(mggmin && mggmax&& METCut &&pt1Cut && pt2Cut&& eveto));
  TH1F *h4 =(TH1F*)gPad->GetPrimitive("h4");
  tree_sig5->Draw("(phi2)>>h5(20,-4,4)","weight"*(mggmin && mggmax&& METCut &&pt1Cut && pt2Cut&& eveto));
  TH1F *h5 =(TH1F*)gPad->GetPrimitive("h5");
  tree_sig6->Draw("(phi2)>>h6(20,-4,4)","weight"*(mggmin && mggmax&& METCut &&pt1Cut && pt2Cut&& eveto));
  TH1F *h6 =(TH1F*)gPad->GetPrimitive("h6");
  tree_sig7->Draw("(phi2)>>h7(20,-4,4)","weight"*(mggmin && mggmax&& METCut &&pt1Cut && pt2Cut&& eveto));
  TH1F *h7 =(TH1F*)gPad->GetPrimitive("h7");
  
  
  tree_bkg1->Draw("(phi2)>>hbkg1(20,-4,4)","weight"*(mggmin && mggmax&& METCut &&pt1Cut && pt2Cut&& eveto));
  TH1F *hbkg1 =(TH1F*)gPad->GetPrimitive("hbkg1");
  tree_bkg2->Draw("(phi2)>>hbkg2(20,-4,4)","weight"*(mggmin && mggmax&& METCut &&pt1Cut && pt2Cut&& eveto));  
  TH1F *hbkg2 =(TH1F*)gPad->GetPrimitive("hbkg2");
  tree_bkg3->Draw("(phi2)>>hbkg3(20,-4,4)","weight"*(mggmin && mggmax && genmatch&& METCut &&pt1Cut && pt2Cut&& eveto));  
  TH1F *hbkg3 =(TH1F*)gPad->GetPrimitive("hbkg3");
  tree_bkg4->Draw("(phi2)>>hbkg4(20,-4,4)","weight"*(mggmin && mggmax&& METCut &&pt1Cut && pt2Cut&& eveto)); //weight also on BR = 0.002 if using the 50ns samples
  TH1F *hbkg4 =(TH1F*)gPad->GetPrimitive("hbkg4");
  tree_bkg5->Draw("(phi2)>>hbkg5(20,-4,4)","weight"*(mggmin && mggmax && genmatch&& METCut &&pt1Cut && pt2Cut&& eveto));
  TH1F *hbkg5 =(TH1F*)gPad->GetPrimitive("hbkg5");
  tree_bkg6->Draw("(phi2)>>hbkg6(20,-4,4)","weight"*(mggmin && mggmax&& METCut &&pt1Cut && pt2Cut&& eveto));
  TH1F *hbkg6 =(TH1F*)gPad->GetPrimitive("hbkg6");
  tree_bkg7->Draw("(phi2)>>hbkg7(20,-4,4)","weight"*(mggmin && mggmax&& METCut &&pt1Cut && pt2Cut&& eveto));
  TH1F *hbkg7 =(TH1F*)gPad->GetPrimitive("hbkg7");
  tree_bkg8->Draw("(phi2)>>hbkg8(20,-4,4)","weight"*(mggmin && mggmax&& METCut &&pt1Cut && pt2Cut&& eveto));
  TH1F *hbkg8 =(TH1F*)gPad->GetPrimitive("hbkg8");
  tree_bkg9->Draw("(phi2)>>hbkg9(20,-4,4)","weight"*(mggmin && mggmax&& METCut &&pt1Cut && pt2Cut&& eveto));
  TH1F *hbkg9 =(TH1F*)gPad->GetPrimitive("hbkg9");
  tree_bkg10->Draw("(phi2)>>hbkg10(20,-4,4)","weight"*(mggmin && mggmax&& METCut &&pt1Cut && pt2Cut&& eveto));
  TH1F *hbkg10 =(TH1F*)gPad->GetPrimitive("hbkg10");
  tree_bkg11->Draw("(phi2)>>hbkg11(20,-4,4)","weight"*(mggmin && mggmax&& METCut &&pt1Cut && pt2Cut&& eveto));
  TH1F *hbkg11 =(TH1F*)gPad->GetPrimitive("hbkg11");
  tree_bkg12->Draw("(phi2)>>hbkg12(20,-4,4)","weight"*(mggmin && mggmax&& METCut &&pt1Cut && pt2Cut&& eveto));
  TH1F *hbkg12 =(TH1F*)gPad->GetPrimitive("hbkg12");
  
  hdata->SetMarkerColor(kBlack);
  hdata->SetMarkerStyle(20);
  hdata->SetLineColor(kBlack);
  
  h1->SetLineColor(kRed+3);
  h2->SetLineColor(kRed+1);
  h3->SetLineColor(kRed);
  h4->SetLineColor(kPink+2);
  h5->SetLineColor(kPink+4);
  h6->SetLineColor(kPink+7);
  h7->SetLineColor(kMagenta+2);
 
  h1->SetLineWidth(2);
  h2->SetLineWidth(2);  
  h3->SetLineWidth(2);
  h4->SetLineWidth(2);
  h5->SetLineWidth(2);
 h6->SetLineWidth(2);
 h7->SetLineWidth(2);
  




  THStack *hs= new THStack("hs","");
  hbkg7->SetFillColor(kGreen+2);
  hbkg6->SetFillColor(kGreen);
  hbkg8->SetFillColor(kYellow);
  hbkg4->SetFillColor(kOrange);
  hbkg9->SetFillColor(kOrange+7);
  hbkg10->SetFillColor(kOrange+4);
  hbkg11->SetFillColor(kCyan);
  hbkg12->SetFillColor(kCyan+1);
  hbkg5->SetFillColor(kBlue+2);
  hbkg2->SetFillColor(kBlue);
  hbkg3->SetFillColor(kMagenta-2);
  hbkg1->SetFillColor(kViolet);

  hbkg1->SetLineColor(kBlack);
  hbkg2->SetLineColor(kBlack);
  hbkg3->SetLineColor(kBlack);
  hbkg4->SetLineColor(kBlack);
  hbkg5->SetLineColor(kBlack);
  hbkg6->SetLineColor(kBlack);
  hbkg7->SetLineColor(kBlack);
  hbkg8->SetLineColor(kBlack);
  hbkg9->SetLineColor(kBlack);
  hbkg10->SetLineColor(kBlack);
  hbkg11->SetLineColor(kBlack);
  hbkg12->SetLineColor(kBlack);

  hs->Add(hbkg7);
  hs->Add(hbkg6);
  hs->Add(hbkg8);
  hs->Add(hbkg4);
  hs->Add(hbkg9);
  hs->Add(hbkg10);
  hs->Add(hbkg11);
  hs->Add(hbkg12);
  hs->Add(hbkg2);
  hs->Add(hbkg5);
  hs->Add(hbkg3);
  hs->Add(hbkg1);






  
  TH1F *hsum = (TH1F*)hbkg1->Clone("hsum");
  hsum->Add(hbkg2);
  hsum->Add(hbkg3);
  hsum->Add(hbkg4);
  hsum->Add(hbkg5);
  hsum->Add(hbkg6);
  hsum->Add(hbkg7);
  hsum->Add(hbkg8);
  hsum->Add(hbkg9);
  hsum->Add(hbkg10);
  hsum->Add(hbkg11);
  hsum->Add(hbkg12);

  hs->SetMaximum(1000000);
  hs->SetMinimum(0.1);
  hs->SetTitle("");
  hs->Draw("HIST"); 

  hsum->SetMarkerStyle(1);
  hsum->SetFillColor(kGray+3);
  hsum->SetFillStyle(3002);
  hsum->Draw("same e2");
  h2->Draw("same hist");
  h3->Draw("same hist"); 
  h4->Draw("same hist");
  h1->Draw("same hist");
  h5->Draw("same hist"); 
 h6->Draw("same hist"); 
 h7->Draw("same hist"); 

  hdata->Draw("same E1");
  
  hs->GetXaxis()->SetLabelOffset(999);
  hs->GetYaxis()->SetTitle("Events/0.4");  
  hs->GetYaxis()->SetTitleOffset(1.2);  
  gPad->Modified();
  
  leg->AddEntry(hdata,"Data","lep");
     
  
  
  leg->AddEntry(hbkg1,"#gamma #gamma","f");
leg->AddEntry(h1,"m_{Z'} = 600 GeV","l");                                                                               

  leg->AddEntry(hbkg2,"Drell Yann","f");
 
  leg->AddEntry(hbkg3,"#gamma + Jets","f");
leg->AddEntry(h2,"m_{Z'} = 800 GeV","l");                                                                               

  leg->AddEntry(hbkg5,"QCD","f");
  
  leg->AddEntry(hbkg4,"ggH","f");
 leg->AddEntry(h3,"m_{Z'} = 1000 GeV","l");                                                                    
 
  leg->AddEntry(hbkg6,"VH","f");
 
  leg->AddEntry(hbkg7,"ttH","f");

 leg->AddEntry(h4,"m_{Z'} = 1200 GeV","l");                                                                    
  leg->AddEntry(hbkg8,"VBF H","f");
  leg->AddEntry(hbkg9,"t + #gamma + Jets","f");
leg->AddEntry(h5,"m_{Z'} = 1400 GeV","l");                                                            
leg->AddEntry(hbkg10,"tt + #gamma +Jets","f");
  leg->AddEntry(hbkg11,"#gamma+W","f");
leg->AddEntry(h6,"m_{Z'} = 1700 GeV","l");     
  leg->AddEntry(hbkg12,"#gamma+Z","f");
  leg->AddEntry(hsum,"Bkg uncertainty","f");

 leg->AddEntry(h7,"m_{Z'} = 2500 GeV","l");                            
 leg->Draw("same");
  
  c1->cd(); 
  smallPad->Draw(); 
  smallPad->cd();

  TGraphErrors *gr = new TGraphErrors(0);
  double integralData=hdata->Integral();
  double integralBKG=hsum->Integral();
  double error, ratio;
  for(int w=1; w<20; w++){
    if((hdata->GetBinContent(w)!=0) && (hsum->GetBinContent(w)!=0)){
      
      gr->SetPoint(w, hdata->GetBinCenter(w),(hdata->GetBinContent(w))/(hsum->GetBinContent(w)));
      ratio= (hdata->GetBinContent(w))/(hsum->GetBinContent(w));
      error= (hdata->GetBinContent(w)*sqrt(hsum->GetBinContent(w))/(hsum->GetBinContent(w)*hsum->GetBinContent(w)) + sqrt(hdata->GetBinContent(w))/hsum->GetBinContent(w));
      std::cout<<"VALUE: "<<ratio<<" ERROR: "<<error<<std::endl;
      gr->SetPointError(w, hdata->GetBinWidth(w)/2,error);
    }else{
      gr->SetPoint(w, hdata->GetBinCenter(w),10);
    } 
  }

  
  
  gStyle->SetPadTickY(1);
  gStyle->SetPadTickX(1);
  gr->GetHistogram()->SetMaximum(2);
  gr->GetHistogram()->SetMinimum(0.1);
  
  gStyle->SetTextSize(14);
  gROOT->ForceStyle();
  
  gr->GetXaxis()->SetLabelFont(43);
  gr->GetXaxis()->SetLabelSize(15);
  gr->GetYaxis()->SetLabelFont(43);
  gr->GetYaxis()->SetLabelSize(15);
  
  gr->GetXaxis()->SetLimits(-4,4);
  
  
  gPad->SetGrid();
  gStyle->SetStripDecimals(kTRUE);
  gr->SetMarkerStyle(20);
  gr->SetMarkerSize(0.7);
  
  
  gr->Draw("AZP");
  gr->GetXaxis()->SetTitle("#phi_{2}");
  gr->GetXaxis()->SetTitleSize(0.1);
  gr->GetYaxis()->SetTitleSize(0.1);
  gr->GetYaxis()->SetNdivisions(505);
 
  gr->GetXaxis()->SetTitleOffset(1);
  gr->GetYaxis()->SetTitle("Data/MC"); 
  gr->GetYaxis()->SetTitleOffset(0.4);
  gr->SetTitle(""); 
  smallPad->Update();
  TF1* line = new TF1("line","1",-4,4);
  line->SetLineColor(kRed);
  line->SetLineWidth(2);
  line->Draw("L same");
  gr->Draw("ZP SAME");
  

  if(pt1min==0 && pt2min == 0 && METmin == 0){
    c1->SaveAs("./25ns_2246inv_v3/plots/kinematics/phi2.png");
    c1->SaveAs("./25ns_2246inv_v3/plots/kinematics/phi2.pdf");
  }
  if(pt1min==0.65 && pt2min == 0.25){
    c1->SaveAs(Form("./25ns_2246inv_v3/plots/kinematics/phi2_optcuts_MET%.0lf.png",METmin));
    c1->SaveAs(Form("./25ns_2246inv_v3/plots/kinematics/phi2_optcuts_MET%.0lf.pdf",METmin));
  }
  


}
示例#7
0
void DeltaPhi(double pt1_cutIN,double pt2_cutIN,double MET_cutIN, double DPHI_cutIN){
  cout<<"#### DeltaPhi(MET,H) #####"<<endl;


 

  gStyle->SetPadTickY(1);
  gStyle->SetPadTickX(1);
  TLegend* leg = new TLegend(0.13,0.6,0.67,0.87);
  leg->SetNColumns(2);
  leg->SetBorderSize(0);
  leg->SetFillStyle(0);
  TLegend* leg_norm = new TLegend(0.20,0.5,0.74,0.87);
  leg_norm->SetNColumns(2);
  leg_norm->SetBorderSize(0);
leg_norm->SetFillStyle(0);


 TCanvas *c1 = new TCanvas("c1","",500,600);
 TPad *mainPad = new TPad("mainPad","",0,0.3,1,1);
 TPad *smallPad = new TPad("smallPad","",0,0.05,1,0.3);
 mainPad->SetBottomMargin(0.015);

 
 smallPad->SetTopMargin(0.05);
 smallPad->SetBottomMargin(0.25);
 
 c1->cd();
 
 mainPad->Draw();
 mainPad->cd();
 TCut mggmax = "mgg<180";
 TCut mggmin = "mgg>100";
 TCut mggblind = "((mgg<115)||(mgg>135))";
 TCut eveto1 = "eleveto1 == 1";
 TCut eveto2 = "eleveto2 == 1";
 TCut eveto = eveto1 && eveto2;
 TCut genmatch = "((genmatch1==1 && genmatch2==0)||(genmatch1==0 && genmatch2==1)||(genmatch1==0 && genmatch2==0))";  
  TCut metF = "((metF_GV==1) && (metF_HBHENoise==1) && (metF_HBHENoiseIso==1) && (metF_CSC==1) && (metF_eeBadSC==1))";  
  TCut pt1cut = Form("pt1/mgg>%lf",pt1_cutIN);
  TCut pt2cut = Form("pt2/mgg>%lf",pt2_cutIN);  
  TCut METcutD = Form("t1pfmetCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,1)>%lf",MET_cutIN);  
  TCut METcut = Form("t1pfmetCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0)>%lf",MET_cutIN);  
  TCut DPHIcut = Form("FDelta(pt1,eta1,phi1,0.,pt2,eta2,phi2,0.,t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>%lf",DPHI_cutIN);  
  TCut DPHIcutD = Form("FDelta(pt1,eta1,phi1,0.,pt2,eta2,phi2,0.,t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,1))>%lf",DPHI_cutIN);  
 
  
 

  TFile *data = TFile::Open("./25ns_2246inv_v3/DoubleEG.root","READ");  
  TFile *sig1 = TFile::Open("./25ns_2246inv_v3/2HDM_mZP600.root","READ");
  TFile *sig2 = TFile::Open("./25ns_2246inv_v3/2HDM_mZP800.root","READ");
  TFile *sig3 = TFile::Open("./25ns_2246inv_v3/2HDM_mZP1000.root","READ");
  TFile *sig4 = TFile::Open("./25ns_2246inv_v3/2HDM_mZP1200.root","READ");
  TFile *sig5 = TFile::Open("./25ns_2246inv_v3/2HDM_mZP1400.root","READ");  
  TFile *sig6 = TFile::Open("./25ns_2246inv_v3/2HDM_mZP1700.root","READ");  
  TFile *sig7 = TFile::Open("./25ns_2246inv_v3/2HDM_mZP2500.root","READ");  

 
  TFile *bkg1 =  TFile::Open("./25ns_2246inv_v3/DiPhoton.root","READ");  
  TFile *bkg2 =  TFile::Open("./25ns_2246inv_v3/DYJetsToLL.root","READ");  
  TFile *bkg3 =  TFile::Open("./25ns_2246inv_v3/GJets.root","READ");  
  TFile *bkg4 =  TFile::Open("./25ns_2246inv_v3/GluGluHToGG.root","READ");  
  TFile *bkg5 =  TFile::Open("./25ns_2246inv_v3/QCD.root","READ");  
  TFile *bkg6 =  TFile::Open("./25ns_2246inv_v3/VH.root","READ");  
  TFile *bkg7 =  TFile::Open("./25ns_2246inv_v3/ttHJetToGG.root","READ");
  TFile *bkg8 =  TFile::Open("./25ns_2246inv_v3/VBFHToGG.root","READ");
  TFile *bkg9 =  TFile::Open("./25ns_2246inv_v3/TGJets.root","READ");
  TFile *bkg10 =  TFile::Open("./25ns_2246inv_v3/TTGJets.root","READ");
  TFile *bkg11 =  TFile::Open("./25ns_2246inv_v3/WGToLNuG.root","READ");
  TFile *bkg12 =  TFile::Open("./25ns_2246inv_v3/ZGTo2LG.root","READ");

  cout<<"check1"<<endl; 

 
  TTree *tree_data = (TTree*) data->Get("DiPhotonTree");
  
  TTree *tree_sig1 = (TTree*) sig1->Get("DiPhotonTree");
  TTree *tree_sig2 = (TTree*) sig2->Get("DiPhotonTree");
  TTree *tree_sig3 = (TTree*) sig3->Get("DiPhotonTree");
  TTree *tree_sig4 = (TTree*) sig4->Get("DiPhotonTree");
  TTree *tree_sig5 = (TTree*) sig5->Get("DiPhotonTree");
  TTree *tree_sig6 = (TTree*) sig6->Get("DiPhotonTree");
  TTree *tree_sig7 = (TTree*) sig7->Get("DiPhotonTree");
  
  
  TTree *tree_bkg1 = (TTree*) bkg1->Get("DiPhotonTree");
  TTree *tree_bkg2 = (TTree*) bkg2->Get("DiPhotonTree");
  TTree *tree_bkg3 = (TTree*) bkg3->Get("DiPhotonTree");
  TTree *tree_bkg4 = (TTree*) bkg4->Get("DiPhotonTree");
  TTree *tree_bkg5 = (TTree*) bkg5->Get("DiPhotonTree");
  TTree *tree_bkg6 = (TTree*) bkg6->Get("DiPhotonTree");
  TTree *tree_bkg7 = (TTree*) bkg7->Get("DiPhotonTree");
  TTree *tree_bkg8 = (TTree*) bkg8->Get("DiPhotonTree");
  TTree *tree_bkg9 = (TTree*) bkg9->Get("DiPhotonTree");
  TTree *tree_bkg10= (TTree*) bkg10->Get("DiPhotonTree");
  TTree *tree_bkg11 = (TTree*) bkg11->Get("DiPhotonTree");
  TTree *tree_bkg12 = (TTree*) bkg12->Get("DiPhotonTree");


  cout<<"check2"<<endl; 

  
  
  tree_data->Draw("FDelta(pt1,eta1,phi1,0.,pt2,eta2,phi2,0.,t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,1))>>hdata(15,0,3.5)",(mggmax && mggmin && metF && eveto && pt1cut && pt2cut && METcutD&& DPHIcutD));
  TH1F *hdata =(TH1F*)gPad->GetPrimitive("hdata");
  hdata->SetMarkerColor(kBlack);
  hdata->SetMarkerStyle(20);
  hdata->SetLineColor(kBlack);
    
 
 
  
  tree_sig1->Draw("FDelta(pt1,eta1,phi1,0.,pt2,eta2,phi2,0.,t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>h1(15,0,3.5)","weight"*(mggmax && mggmin && eveto && pt1cut && pt2cut && METcut&& DPHIcut));
  TH1F *h1 =(TH1F*)gPad->GetPrimitive("h1");
  tree_sig2->Draw("FDelta(pt1,eta1,phi1,0.,pt2,eta2,phi2,0.,t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>h2(15,0,3.5)","weight"*(mggmax && mggmin && eveto && pt1cut && pt2cut && METcut&& DPHIcut));
  TH1F *h2 =(TH1F*)gPad->GetPrimitive("h2");
  tree_sig3->Draw("FDelta(pt1,eta1,phi1,0.,pt2,eta2,phi2,0.,t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>h3(15,0,3.5)","weight"*(mggmax && mggmin && eveto && pt1cut && pt2cut && METcut&& DPHIcut));
  TH1F *h3 =(TH1F*)gPad->GetPrimitive("h3");
  tree_sig4->Draw("FDelta(pt1,eta1,phi1,0.,pt2,eta2,phi2,0.,t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>h4(15,0,3.5)","weight"*(mggmax && mggmin && eveto && pt1cut && pt2cut && METcut&& DPHIcut));
  TH1F *h4 =(TH1F*)gPad->GetPrimitive("h4");
  tree_sig5->Draw("FDelta(pt1,eta1,phi1,0.,pt2,eta2,phi2,0.,t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>h5(15,0,3.5)","weight"*(mggmax && mggmin && eveto && pt1cut && pt2cut && METcut&& DPHIcut));
  TH1F *h5 =(TH1F*)gPad->GetPrimitive("h5");
  tree_sig6->Draw("FDelta(pt1,eta1,phi1,0.,pt2,eta2,phi2,0.,t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>h6(15,0,3.5)","weight"*(mggmax && mggmin && eveto && pt1cut && pt2cut && METcut&& DPHIcut));
  TH1F *h6 =(TH1F*)gPad->GetPrimitive("h6");
  tree_sig7->Draw("FDelta(pt1,eta1,phi1,0.,pt2,eta2,phi2,0.,t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>h7(15,0,3.5)","weight"*(mggmax && mggmin && eveto && pt1cut && pt2cut && METcut&& DPHIcut));
  TH1F *h7 =(TH1F*)gPad->GetPrimitive("h7");
 
  tree_bkg1->Draw("FDelta(pt1,eta1,phi1,0.,pt2,eta2,phi2,0.,t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>hbkg1(15,0,3.5)","weight"*(mggmax && mggmin && eveto && pt1cut && pt2cut && METcut&& DPHIcut));
  TH1F *hbkg1 =(TH1F*)gPad->GetPrimitive("hbkg1");
  tree_bkg2->Draw("FDelta(pt1,eta1,phi1,0.,pt2,eta2,phi2,0.,t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>hbkg2(15,0,3.5)","weight"*(mggmax && mggmin && eveto && pt1cut && pt2cut && METcut&& DPHIcut));  
  TH1F *hbkg2 =(TH1F*)gPad->GetPrimitive("hbkg2");
  tree_bkg3->Draw("FDelta(pt1,eta1,phi1,0.,pt2,eta2,phi2,0.,t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>hbkg3(15,0,3.5)","weight"*(mggmax && mggmin && eveto && genmatch && pt1cut && pt2cut && METcut&& DPHIcut));  
  TH1F *hbkg3 =(TH1F*)gPad->GetPrimitive("hbkg3");
  tree_bkg4->Draw("FDelta(pt1,eta1,phi1,0.,pt2,eta2,phi2,0.,t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>hbkg4(15,0,3.5)","weight"*(mggmax && mggmin && eveto && pt1cut && pt2cut && METcut&& DPHIcut)); //weight also on BR = 0.002 if using 50ns samples
  TH1F *hbkg4 =(TH1F*)gPad->GetPrimitive("hbkg4");
  tree_bkg5->Draw("FDelta(pt1,eta1,phi1,0.,pt2,eta2,phi2,0.,t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>hbkg5(15,0,3.5)","weight"*(mggmax && mggmin && eveto && genmatch && pt1cut && pt2cut && METcut&& DPHIcut));
  TH1F *hbkg5 =(TH1F*)gPad->GetPrimitive("hbkg5");
  tree_bkg6->Draw("FDelta(pt1,eta1,phi1,0.,pt2,eta2,phi2,0.,t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>hbkg6(15,0,3.5)","weight"*(mggmax && mggmin && eveto && pt1cut && pt2cut && METcut&& DPHIcut));   //weight also on BR = 0.002 if using 50ns samples
  TH1F *hbkg6 =(TH1F*)gPad->GetPrimitive("hbkg6");
  tree_bkg7->Draw("FDelta(pt1,eta1,phi1,0.,pt2,eta2,phi2,0.,t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>hbkg7(15,0,3.5)","weight"*(mggmax && mggmin && eveto && pt1cut && pt2cut && METcut&& DPHIcut));  //weight also on BR = 0.002 if using 50ns samples   
   TH1F *hbkg7 =(TH1F*)gPad->GetPrimitive("hbkg7");
    tree_bkg8->Draw("FDelta(pt1,eta1,phi1,0.,pt2,eta2,phi2,0.,t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>hbkg8(15,0,3.5)","weight"*(mggmax && mggmin && eveto && pt1cut && pt2cut && METcut&& DPHIcut));  //weight also on BR = 0.002 if using 50ns samples  
   TH1F *hbkg8 =(TH1F*)gPad->GetPrimitive("hbkg8");
   tree_bkg9->Draw("FDelta(pt1,eta1,phi1,0.,pt2,eta2,phi2,0.,t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>hbkg9(15,0,3.5)","weight"*(mggmax && mggmin && eveto && pt1cut && pt2cut && METcut&& DPHIcut));  //weight also on BR = 0.002 if using 50ns samples  
   TH1F *hbkg9 =(TH1F*)gPad->GetPrimitive("hbkg9");
   tree_bkg10->Draw("FDelta(pt1,eta1,phi1,0.,pt2,eta2,phi2,0.,t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>hbkg10(15,0,3.5)","weight"*(mggmax && mggmin && eveto && pt1cut && pt2cut && METcut&& DPHIcut));  //weight also on BR = 0.002 if using 50ns samples  
   TH1F *hbkg10 =(TH1F*)gPad->GetPrimitive("hbkg10");
   tree_bkg11->Draw("FDelta(pt1,eta1,phi1,0.,pt2,eta2,phi2,0.,t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>hbkg11(15,0,3.5)","weight"*(mggmax && mggmin && eveto && pt1cut && pt2cut && METcut&& DPHIcut));  //weight also on BR = 0.002 if using 50ns samples  
   TH1F *hbkg11 =(TH1F*)gPad->GetPrimitive("hbkg11");
   tree_bkg12->Draw("FDelta(pt1,eta1,phi1,0.,pt2,eta2,phi2,0.,t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>hbkg12(15,0,3.5)","weight*(weight>0.)"*(mggmax && mggmin && eveto && pt1cut && pt2cut && METcut&& DPHIcut));  //weight also on BR = 0.002 if using 50ns samples  
   TH1F *hbkg12 =(TH1F*)gPad->GetPrimitive("hbkg12");

 
   cout<<"check3"<<endl; 


  /*  h1->Scale(0.00009338);
  h2->Scale(0.00010348);
  h3->Scale(0.00008394);
  h4->Scale(0.00006352);
  h5->Scale(0.00004712);
  h6->Scale(0.00003020);
  h7->Scale(0.00000972);
  */


  h1->SetLineColor(kRed+3);
  h2->SetLineColor(kRed+1);
  h3->SetLineColor(kRed);
  h4->SetLineColor(kPink+2);
  h5->SetLineColor(kPink+4); //only for 15ns samples
  h6->SetLineColor(kPink+7); //only for 15ns samples
  h7->SetLineColor(kMagenta+2); //only for 15ns samples
  h1->SetLineWidth(2);
  h2->SetLineWidth(2);
  h3->SetLineWidth(2);
  h4->SetLineWidth(2);
  h5->SetLineWidth(2); //only for 15ns samples
  h6->SetLineWidth(2); //only for 15ns samples
  h7->SetLineWidth(2); //only for 15ns samples
  
  





  
  
   THStack *hs=new THStack("hs","");

   hbkg7->SetFillColor(kGreen+2);
   hbkg6->SetFillColor(kGreen);
   hbkg8->SetFillColor(kYellow);
   hbkg4->SetFillColor(kOrange);
   hbkg9->SetFillColor(kOrange+7);
   hbkg10->SetFillColor(kOrange+4);
   hbkg11->SetFillColor(kCyan);
   hbkg12->SetFillColor(kCyan+1);
   hbkg5->SetFillColor(kBlue+2);
   hbkg2->SetFillColor(kBlue);
   hbkg3->SetFillColor(kMagenta-2);
   hbkg1->SetFillColor(kViolet);


 


  hbkg1->SetLineColor(kBlack);
  hbkg2->SetLineColor(kBlack);
  hbkg3->SetLineColor(kBlack);
  hbkg4->SetLineColor(kBlack);
  hbkg5->SetLineColor(kBlack);
  hbkg6->SetLineColor(kBlack);
  hbkg7->SetLineColor(kBlack);
  hbkg8->SetLineColor(kBlack);
  hbkg9->SetLineColor(kBlack);
  hbkg10->SetLineColor(kBlack);
  hbkg11->SetLineColor(kBlack);
  hbkg12->SetLineColor(kBlack);
  

  hs->Add(hbkg7);
  hs->Add(hbkg6);
  hs->Add(hbkg8);
  hs->Add(hbkg4);
  hs->Add(hbkg9);
  hs->Add(hbkg10);
  hs->Add(hbkg11);
  hs->Add(hbkg12);
  hs->Add(hbkg2);
  hs->Add(hbkg5);
  hs->Add(hbkg3);
  hs->Add(hbkg1);


  cout<<"check4"<<endl;  

    TH1F *hsum = (TH1F*)hbkg1->Clone("hsum"); 
  hsum->Add(hbkg2);
  hsum->Add(hbkg3);
  hsum->Add(hbkg4);
  hsum->Add(hbkg9);
  hsum->Add(hbkg10);
  hsum->Add(hbkg11);
  hsum->Add(hbkg12);
  hsum->Add(hbkg5);
  hsum->Add(hbkg6);
  hsum->Add(hbkg7);
  hsum->Add(hbkg8);
  hdata->SetMaximum(5000);
  // hs->SetMinimum(0.0001);
  hdata->SetTitle("");
  hdata->Draw("e1"); 

  hsum->SetMarkerStyle(1);
  hsum->SetFillColor(kGray+3);
  hsum->SetFillStyle(3002);
  
  hs->Draw("same hist");
  hsum->Draw("same e2");
  h2->Draw("same hist");
  h3->Draw("same hist"); 
  h4->Draw("same hist");
  h1->Draw("same hist");
  h5->Draw("same hist"); //only for 15ns samples
  h6->Draw("same hist"); //only for 15ns samples
  h7->Draw("same hist"); //only for 15ns samples
  hdata->Draw("same e1");  
  

  hdata->GetXaxis()->SetLabelOffset(999);
  hdata->GetYaxis()->SetTitle("Events/0.4");
 

  hdata->GetYaxis()->SetTitleOffset(1.6);
  hdata->GetYaxis()->SetTitle("Events/0.23 GeV");  
  gPad->Modified();
  
  
  
  /*leg->AddEntry(h1,"m_{#chi} = 1 GeV","l");
    leg->AddEntry(h2,"m_{#chi} = 10 GeV","l");
    leg->AddEntry(h3,"m_{#chi} = 100 GeV","l");      
    leg->AddEntry(h4,"m_{#chi} = 1000 GeV","l");*/
 leg->AddEntry(hdata,"Data","elp");
 // leg->AddEntry(h1,"m_{Z'} = 600 GeV","l");
  leg->AddEntry(hbkg1,"#gamma #gamma","f");         
  //  leg->AddEntry(h2,"m_{Z'} = 800 GeV","l");
  leg->AddEntry(hbkg2,"Drell Yann","f");       
  // leg->AddEntry(h3,"m_{Z'} = 1000 GeV","l");      
  leg->AddEntry(hbkg3,"#gamma + Jets","f");      
  // leg->AddEntry(h4,"m_{Z'} = 1200 GeV","l");     
  leg->AddEntry(hbkg5,"QCD","f");    
  // leg->AddEntry(h5,"m_{Z'} = 1400 GeV","l"); //only for 15ns samples    
    leg->AddEntry(hbkg4,"ggH","f");      
    // leg->AddEntry(h6,"m_{Z'} = 1700 GeV","l"); //only for 15ns samples    
  leg->AddEntry(hbkg6,"VH","f");  
  // leg->AddEntry(h7,"m_{Z'} = 2500 GeV","l"); //only for 25ns samples      
  leg->AddEntry(hbkg7,"ttH","f");  
  leg->AddEntry(hbkg8,"VBF H","f");  
  leg->AddEntry(hbkg9,"t + #gamma + Jets","f");  
  leg->AddEntry(hbkg10,"tt + #gamma +Jets","f");  
  leg->AddEntry(hbkg11,"#gamma+W","f");  
  leg->AddEntry(hbkg12,"#gamma+Z","f");  
  leg->AddEntry(hsum,"Bkg uncertainty","f");
  leg->Draw("same");
  
 cout<<"check5"<<endl; 

  gStyle->SetOptStat(0);  
  
  c1->cd();
  smallPad->Draw();
  smallPad->cd();

  TGraphErrors *gr = new TGraphErrors(0);
  double integralData=hdata->Integral();
  double integralBKG=hsum->Integral();
  double error, ratio;
  for(int w=1; w<15; w++){
    if((hdata->GetBinContent(w)!=0) && (hsum->GetBinContent(w)!=0)){

      gr->SetPoint(w, hdata->GetBinCenter(w),(hdata->GetBinContent(w))/(hsum->GetBinContent(w)));
      ratio= (hdata->GetBinContent(w))/(hsum->GetBinContent(w));
      error= (hdata->GetBinContent(w)*sqrt(hsum->GetBinContent(w))/(hsum->GetBinContent(w)*hsum->GetBinContent(w)) + sqrt(hdata->GetBinContent(w))/hsum->GetBinContent(w));
      std::cout<<"VALUE: "<<ratio<<" ERROR: "<<error<<std::endl;
      gr->SetPointError(w, hdata->GetBinWidth(w)/2,error);
    }else{
      gr->SetPoint(w, hdata->GetBinCenter(w),10);
    }
  }



  gStyle->SetPadTickY(1);
  gStyle->SetPadTickX(1);
  gr->GetHistogram()->SetMaximum(2);
  gr->GetHistogram()->SetMinimum(0.1);

  gStyle->SetTextSize(14);
  gROOT->ForceStyle();

  gr->GetXaxis()->SetLabelFont(43);
  gr->GetXaxis()->SetLabelSize(15);
  gr->GetYaxis()->SetLabelFont(43);
  gr->GetYaxis()->SetLabelSize(15);

  gr->GetXaxis()->SetLimits(0,3.5);
  gPad->SetGrid();
  gStyle->SetStripDecimals(kTRUE);
  gr->SetMarkerStyle(20);
  gr->SetMarkerSize(0.7);


  gr->Draw("AZP");
  gr->GetXaxis()->SetTitle("|#Delta#phi(#gamma#gamma,E^{miss}_{T})|");
  gr->GetXaxis()->SetTitleSize(0.1);
  gr->GetYaxis()->SetTitleSize(0.1);
  gr->GetYaxis()->SetNdivisions(505);

  gr->GetXaxis()->SetTitleOffset(1);
  gr->GetYaxis()->SetTitle("Data/MC");
  gr->GetYaxis()->SetTitleOffset(0.4);
  gr->SetTitle("");
  smallPad->Update();
  TF1* line = new TF1("line","1",0,3.5);
  line->SetLineColor(kRed);
  line->SetLineWidth(2);
  line->Draw("L same");
  gr->Draw("ZP SAME");

 

TCanvas *c2 = new TCanvas("c2","",500,500);
    

  tree_sig1->Draw("FDelta(pt1,eta1,phi1,0.,pt2,eta2,phi2,0.,t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>h1_norm(15,0,3.5)","weight"*(mggmax && mggmin && eveto && pt1cut && pt2cut && METcut&& DPHIcut));
  TH1F *h1_norm =(TH1F*)gPad->GetPrimitive("h1_norm");
  tree_sig2->Draw("FDelta(pt1,eta1,phi1,0.,pt2,eta2,phi2,0.,t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>h2_norm(15,0,3.5)","weight"*(mggmax && mggmin && eveto && pt1cut && pt2cut && METcut&& DPHIcut));
  TH1F *h2_norm =(TH1F*)gPad->GetPrimitive("h2_norm");
  tree_sig3->Draw("FDelta(pt1,eta1,phi1,0.,pt2,eta2,phi2,0.,t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>h3_norm(15,0,3.5)","weight"*(mggmax && mggmin && eveto && pt1cut && pt2cut && METcut&& DPHIcut));
  TH1F *h3_norm =(TH1F*)gPad->GetPrimitive("h3_norm");
  tree_sig4->Draw("FDelta(pt1,eta1,phi1,0.,pt2,eta2,phi2,0.,t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>h4_norm(15,0,3.5)","weight"*(mggmax && mggmin && eveto && pt1cut && pt2cut && METcut&& DPHIcut));
  TH1F *h4_norm =(TH1F*)gPad->GetPrimitive("h4_norm");
  tree_sig5->Draw("FDelta(pt1,eta1,phi1,0.,pt2,eta2,phi2,0.,t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>h5_norm(15,0,3.5)","weight"*(mggmax && mggmin && eveto && pt1cut && pt2cut && METcut&& DPHIcut));
  TH1F *h5_norm =(TH1F*)gPad->GetPrimitive("h5_norm");
  tree_sig6->Draw("FDelta(pt1,eta1,phi1,0.,pt2,eta2,phi2,0.,t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>h6_norm(15,0,3.5)","weight"*(mggmax && mggmin && eveto && pt1cut && pt2cut && METcut&& DPHIcut));
  TH1F *h6_norm =(TH1F*)gPad->GetPrimitive("h6_norm");
  tree_sig7->Draw("FDelta(pt1,eta1,phi1,0.,pt2,eta2,phi2,0.,t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>h7_norm(15,0,3.5)","weight"*(mggmax && mggmin && eveto && pt1cut && pt2cut && METcut&& DPHIcut));
  TH1F *h7_norm =(TH1F*)gPad->GetPrimitive("h7_norm");
  




  tree_bkg1->Draw("FDelta(pt1,eta1,phi1,0.,pt2,eta2,phi2,0.,t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>hbkg1_norm(15,0,3.5)","weight"*(mggmax && mggmin && eveto && pt1cut && pt2cut && METcut&& DPHIcut));
  TH1F *hbkg1_norm =(TH1F*)gPad->GetPrimitive("hbkg1_norm");
  tree_bkg2->Draw("FDelta(pt1,eta1,phi1,0.,pt2,eta2,phi2,0.,t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>hbkg2_norm(15,0,3.5)","weight"*(mggmax && mggmin && eveto && pt1cut && pt2cut && METcut&& DPHIcut));  
  TH1F *hbkg2_norm =(TH1F*)gPad->GetPrimitive("hbkg2_norm");
  tree_bkg3->Draw("FDelta(pt1,eta1,phi1,0.,pt2,eta2,phi2,0.,t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>hbkg3_norm(15,0,3.5)","weight"*(mggmax && mggmin && eveto && genmatch && pt1cut && pt2cut && METcut&& DPHIcut));  
  TH1F *hbkg3_norm =(TH1F*)gPad->GetPrimitive("hbkg3_norm");
  tree_bkg4->Draw("FDelta(pt1,eta1,phi1,0.,pt2,eta2,phi2,0.,t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>hbkg4_norm(15,0,3.5)","weight"*(mggmax && mggmin && eveto && pt1cut && pt2cut && METcut&& DPHIcut)); //weight also on BR = 0.002 if using 50ns samples
  TH1F *hbkg4_norm =(TH1F*)gPad->GetPrimitive("hbkg4_norm");
  tree_bkg5->Draw("FDelta(pt1,eta1,phi1,0.,pt2,eta2,phi2,0.,t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>hbkg5_norm(15,0,3.5)","weight"*(mggmax && mggmin && eveto && genmatch && pt1cut && pt2cut && METcut&& DPHIcut));
  TH1F *hbkg5_norm =(TH1F*)gPad->GetPrimitive("hbkg5_norm");
  tree_bkg6->Draw("FDelta(pt1,eta1,phi1,0.,pt2,eta2,phi2,0.,t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>hbkg6_norm(15,0,3.5)","weight"*(mggmax && mggmin && eveto && pt1cut && pt2cut && METcut&& DPHIcut));   //weight also on BR = 0.002 if using 50ns samples
  TH1F *hbkg6_norm =(TH1F*)gPad->GetPrimitive("hbkg6_norm");
  tree_bkg7->Draw("FDelta(pt1,eta1,phi1,0.,pt2,eta2,phi2,0.,t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>hbkg7_norm(15,0,3.5)","weight"*(mggmax && mggmin && eveto && pt1cut && pt2cut && METcut&& DPHIcut));  //weight also on BR = 0.002 if using 50ns samples   
   TH1F *hbkg7_norm =(TH1F*)gPad->GetPrimitive("hbkg7_norm");
    tree_bkg8->Draw("FDelta(pt1,eta1,phi1,0.,pt2,eta2,phi2,0.,t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>hbkg8_norm(15,0,3.5)","weight"*(mggmax && mggmin && eveto && pt1cut && pt2cut && METcut&& DPHIcut));  //weight also on BR = 0.002 if using 50ns samples  
   TH1F *hbkg8_norm =(TH1F*)gPad->GetPrimitive("hbkg8_norm");
   tree_bkg9->Draw("FDelta(pt1,eta1,phi1,0.,pt2,eta2,phi2,0.,t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>hbkg9_norm(15,0,3.5)","weight"*(mggmax && mggmin && eveto && pt1cut && pt2cut && METcut&& DPHIcut));  //weight also on BR = 0.002 if using 50ns samples  
   TH1F *hbkg9_norm =(TH1F*)gPad->GetPrimitive("hbkg9_norm");
   tree_bkg10->Draw("FDelta(pt1,eta1,phi1,0.,pt2,eta2,phi2,0.,t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>hbkg10_norm(15,0,3.5)","weight"*(mggmax && mggmin && eveto && pt1cut && pt2cut && METcut&& DPHIcut));  //weight also on BR = 0.002 if using 50ns samples  
   TH1F *hbkg10_norm =(TH1F*)gPad->GetPrimitive("hbkg10_norm");
   tree_bkg11->Draw("FDelta(pt1,eta1,phi1,0.,pt2,eta2,phi2,0.,t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>hbkg11_norm(15,0,3.5)","weight"*(mggmax && mggmin && eveto && pt1cut && pt2cut && METcut&& DPHIcut));  //weight also on BR = 0.002 if using 50ns samples  
   TH1F *hbkg11_norm =(TH1F*)gPad->GetPrimitive("hbkg11_norm");
   tree_bkg12->Draw("FDelta(pt1,eta1,phi1,0.,pt2,eta2,phi2,0.,t1pfmetPhiCorr(t1pfmet,t1pfmetPhi,t1pfmetSumEt,0))>>hbkg12_norm(15,0,3.5)","weight"*(mggmax && mggmin && eveto && pt1cut && pt2cut && METcut&& DPHIcut));  //weight also on BR = 0.002 if using 50ns samples  
   TH1F *hbkg12_norm =(TH1F*)gPad->GetPrimitive("hbkg12_norm");


   for(int i = 0; i<26;i++){
     if(hbkg1_norm->GetBinContent(i) < 0.) hbkg1_norm->SetBinContent(i,0.);
     if(hbkg2_norm->GetBinContent(i) < 0.) hbkg2_norm->SetBinContent(i,0.);
     if(hbkg3_norm->GetBinContent(i) < 0.) hbkg3_norm->SetBinContent(i,0.);
     if(hbkg4_norm->GetBinContent(i) < 0.) hbkg4_norm->SetBinContent(i,0.);
     if(hbkg5_norm->GetBinContent(i) < 0.) hbkg5_norm->SetBinContent(i,0.);
     if(hbkg6_norm->GetBinContent(i) < 0.) hbkg6_norm->SetBinContent(i,0.);
     if(hbkg7_norm->GetBinContent(i) < 0.) hbkg7_norm->SetBinContent(i,0.);
     if(hbkg8_norm->GetBinContent(i) < 0.) hbkg8_norm->SetBinContent(i,0.);
     if(hbkg9_norm->GetBinContent(i) < 0.) hbkg9_norm->SetBinContent(i,0.);
     if(hbkg10_norm->GetBinContent(i) < 0.) hbkg10_norm->SetBinContent(i,0.);
     if(hbkg11_norm->GetBinContent(i) < 0.) hbkg11_norm->SetBinContent(i,0.);
     if(hbkg12_norm->GetBinContent(i) < 0.) hbkg12_norm->SetBinContent(i,0.);
   }




  double norm = 1./h1_norm->Integral();
  h1_norm->Scale(norm);
  norm = 1./h2_norm->Integral();
  h2_norm->Scale(norm);
  norm = 1./h3_norm->Integral();
  h3_norm->Scale(norm);
  norm = 1./h4_norm->Integral();
  h4_norm->Scale(norm);  
  norm = 1./h5_norm->Integral(); //only for 50ns samples
  h5_norm->Scale(norm);  //only for 50ns samples
  norm = 1./h6_norm->Integral(); //only for 50ns samples
  h6_norm->Scale(norm);  //only for 50ns samples
  norm = 1./h7_norm->Integral(); //only for 50ns samples
  h7_norm->Scale(norm);  //only for 50ns samples
  


  norm = 1./hbkg1_norm->Integral();
  hbkg1_norm->Scale(norm);  
  norm = 1./hbkg2_norm->Integral();
  hbkg2_norm->Scale(norm);  
  norm = 1./hbkg3_norm->Integral();
  hbkg3_norm->Scale(norm);  
  norm = 1./hbkg4_norm->Integral();
  hbkg4_norm->Scale(norm);  
  norm = 1./hbkg5_norm->Integral();
  hbkg5_norm->Scale(norm);  
  norm = 1./hbkg6_norm->Integral();
  hbkg6_norm->Scale(norm);  
  norm = 1./hbkg7_norm->Integral();
  hbkg7_norm->Scale(norm);  
  norm = 1./hbkg8_norm->Integral();
  hbkg8_norm->Scale(norm);  
  norm = 1./hbkg9_norm->Integral();
  hbkg9_norm->Scale(norm);  
  norm = 1./hbkg10_norm->Integral();
  hbkg10_norm->Scale(norm);  
  norm = 1./hbkg11_norm->Integral();
  hbkg11_norm->Scale(norm);  
  norm = 1./hbkg12_norm->Integral();
  hbkg12_norm->Scale(norm);  
  
  
  h1_norm->SetLineColor(kRed+3);
  h2_norm->SetLineColor(kRed+1);
  h3_norm->SetLineColor(kRed);
  h4_norm->SetLineColor(kPink+2);
  h5_norm->SetLineColor(kPink+4); //only for 25ns samples
  h6_norm->SetLineColor(kPink+7); //only for 25ns samples
  h7_norm->SetLineColor(kMagenta+2); //only for 25ns samples
  h1_norm->SetLineWidth(2);
  h2_norm->SetLineWidth(2);
  h3_norm->SetLineWidth(2);
  h4_norm->SetLineWidth(2);
  h5_norm->SetLineWidth(2); //only for 25ns samples
  h6_norm->SetLineWidth(2); //only for 25ns samples
  h7_norm->SetLineWidth(2); //only for 25ns samples



  hbkg7_norm->SetLineColor(kGreen+2);
  hbkg6_norm->SetLineColor(kGreen);
  hbkg8_norm->SetLineColor(kYellow);
  hbkg4_norm->SetLineColor(kOrange);
  hbkg9_norm->SetLineColor(kOrange+7);
  hbkg10_norm->SetLineColor(kOrange+4);
  hbkg11_norm->SetLineColor(kCyan);
  hbkg12_norm->SetLineColor(kCyan+1);
  hbkg5_norm->SetLineColor(kBlue+3);
  hbkg2_norm->SetLineColor(kBlue);
  hbkg3_norm->SetLineColor(kMagenta-2);
  hbkg1_norm->SetLineColor(kViolet);

 
 
 
  
  
  hbkg1_norm->SetFillStyle(0);
  hbkg2_norm->SetFillStyle(0);
  hbkg3_norm->SetFillStyle(0);
  hbkg4_norm->SetFillStyle(0);
  hbkg5_norm->SetFillStyle(0);
  hbkg6_norm->SetFillStyle(0);
  hbkg7_norm->SetFillStyle(0); 
  hbkg8_norm->SetFillStyle(0);
  hbkg9_norm->SetFillStyle(0);
  hbkg10_norm->SetFillStyle(0);
  hbkg11_norm->SetFillStyle(0);
  hbkg12_norm->SetFillStyle(0);
  
  
   
  h1_norm->SetTitle("");
  
  h1_norm->SetMaximum(1);  
  h1_norm->SetMinimum(0.001);  
  h1_norm->Draw("HIST"); 
  
  hbkg1_norm->Draw("same HIST");  
  hbkg2_norm->Draw("same HIST"); 
  hbkg3_norm->Draw("same HIST"); 
  hbkg5_norm->Draw("same HIST"); 
  hbkg4_norm->Draw("same HIST"); 
  hbkg6_norm->Draw("same HIST"); 
  hbkg7_norm->Draw("same HIST"); 
  hbkg8_norm->Draw("same HIST"); 
  hbkg9_norm->Draw("same HIST"); 
  hbkg10_norm->Draw("same HIST"); 
  hbkg11_norm->Draw("same HIST"); 
  hbkg12_norm->Draw("same HIST"); 
  h1_norm->Draw("same hist"); 
  h2_norm->Draw("same hist");
  h3_norm->Draw("same hist"); 
  h4_norm->Draw("same hist");
  h5_norm->Draw("same hist");
  h6_norm->Draw("same hist");
  h7_norm->Draw("same hist");
  
  h1_norm->GetXaxis()->SetTitle("|#Delta#phi(#gamma#gamma,E_{T}^{miss})|");
  h1_norm->GetYaxis()->SetTitle("Normalized events");  
  h1_norm->GetYaxis()->SetTitleOffset(1.2);  
  gPad->Modified();
  gStyle->SetOptStat(0);
  
  
  //int iPos =0;                                                                                                                 
  //  CMS_lumi(p1,true,iPos,true);                                                                                               
  // CMS_lumi(p2,true,iPos,true);   
  
  leg_norm->AddEntry(h1_norm,"m_{Z'} = 600 GeV","l");
  leg_norm->AddEntry(hbkg1_norm,"#gamma #gamma","l");      
  leg_norm->AddEntry(h2_norm,"m_{Z'} = 800 GeV","l");
  leg_norm->AddEntry(hbkg2_norm,"Drell Yann","l");      
  leg_norm->AddEntry(h3_norm,"m_{Z'} = 1000 GeV","l");      
  leg_norm->AddEntry(hbkg3_norm,"#gamma + Jets","l");      
  leg_norm->AddEntry(h4_norm,"m_{Z'} = 1200 GeV","l");    
  leg_norm->AddEntry(hbkg5_norm,"QCD","l");     
  leg_norm->AddEntry(h5_norm,"m_{Z'} = 1400 GeV","l"); //only for 25ns samples    
  leg_norm->AddEntry(hbkg4_norm,"ggH","l");      
  leg_norm->AddEntry(h6_norm,"m_{Z'} = 1700 GeV","l"); //only for 25ns samples    
  leg_norm->AddEntry(hbkg6_norm,"VH","l");   
  leg_norm->AddEntry(h7_norm,"m_{Z'} = 2500 GeV","l"); //only for 25ns samples      
  leg_norm->AddEntry(hbkg7_norm,"ttH","l");  
  leg_norm->AddEntry(hbkg8_norm,"VBF H","l");   
  leg_norm->AddEntry(hbkg9_norm,"t + #gamma + Jets","l");  
  leg_norm->AddEntry(hbkg10_norm,"tt + #gamma +Jets","l");  
  leg_norm->AddEntry(hbkg11_norm,"#gamma+W","l");  
  leg_norm->AddEntry(hbkg12_norm,"#gamma+Z","l");  
  leg_norm->Draw("same");
  
  if(pt1_cutIN==0. && pt2_cutIN == 0. && MET_cutIN == 0.){
    c1->SaveAs("./25ns_2246inv_v3/plots/kinematics/DeltaPhi_H_MET_MET0.png");
    c1->SaveAs("./25ns_2246inv_v3/plots/kinematics/DeltaPhi_H_MET_MET0.pdf");
 c2->SaveAs("./25ns_2246inv_v3/plots/kinematics/DeltaPhi_H_MET_MET0_norm.png");
    c2->SaveAs("./25ns_2246inv_v3/plots/kinematics/DeltaPhi_H_MET_MET0_norm.pdf");
  }
  
}
示例#8
0
文件: fitwitherr2.C 项目: XuQiao/HI
void fitwitherr2() {

  fetchpc3dphidz();

  float pt[50];
  float errx[50];

  for (int ipt=0; ipt<50; ipt++) {
    pt[ipt] = ipt*0.1 + 0.05;
    errx[ipt] = 0.0;
  }

  gStyle->SetOptStat(kFALSE);
  //gStyle->SetOptFit(1101);

  ofstream fout("run16dAupc3matchingsmooth.h");
  ofstream fout2("run16dAupc3matchingsmooth2.h");


  for (int iarm=0; iarm<2; iarm++) {
    for (int ich=0; ich<2; ich++) {
    for(int ivz=0; ivz<10; ivz++){
      string arm;
      string ch;
      if (iarm == 0) arm = "east";
      else if (iarm == 1) arm = "west";
      else arm = "err";

      if (ich == 0) ch = "pos";
      else if (ich == 1) ch = "neg";
      else ch = "err";
        string bbcz;
	if (ivz==0) bbcz = "-10 to -8";
        else if (ivz==1) bbcz = "-8 to -6";
	else if (ivz==2) bbcz = "-6 to -4";
	else if (ivz==3) bbcz = "-4 to -2";
	else if (ivz==4) bbcz = "-2 to 0";
	else if (ivz==5) bbcz = "0 to 2";
	else if (ivz==6) bbcz = "2 to 4";
	else if (ivz==7) bbcz = "4 to 6";
	else if (ivz==8) bbcz = "6 to 8";
	else if (ivz==9) bbcz = "8 to 10";
	else bbcz = "err";

      TCanvas *c1 = new TCanvas("c1","c1",500,500);
      c1->SetGridx();
      TGraphErrors* dphisigma = new TGraphErrors(50,pt,pc3dphisigma[iarm][ich][ivz],errx,pc3dphisigmaerr[iarm][ich][ivz]);
      dphisigma->SetTitle(Form("dphisigma_%s_%s_%s",arm,ch,bbcz));
      dphisigma->SetLineColor(1);
      dphisigma->SetMarkerStyle(20);
      dphisigma->SetMarkerSize(0.8);
      dphisigma->GetXaxis()->SetRangeUser(0.2,5.0);
      dphisigma->GetHistogram()->SetMaximum(0.01);
      dphisigma->GetHistogram()->SetMinimum(-0.01);
      dphisigma->GetXaxis()->SetTitle("p_{T}");
      dphisigma->GetYaxis()->SetTitle("dphi sigma");
      dphisigma->Draw("AP");

      TPaveText *p1 = new TPaveText(0.2,0.8,0.9,0.9,"NDC");
      p1->AddText("Fit function: a+bx+cx^{2}+dx^{3}+ex^{4}+fx^{5}+#frac{g}{#sqrt{x}}+#frac{h}{x^{2}}");
      p1->Draw("same");

      TF1 *fdphisigma = new TF1("fdphisigma","[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x+[5]*x*x*x*x*x+[6]/TMath::Sqrt(x)+[7]/x/x",0.3,5.0);
      //TF1 *fdphisigma2 = new TF1("fdphisigma2","[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x+[5]*x*x*x*x*x+[6]/TMath::Sqrt(x)+[7]/x/x",0.2,5.0);
      dphisigma->Fit("fdphisigma","Q0","",0.4,4.0);
      //double sigma_par[8];
      //fdphisigma->GetParameters(sigma_par);
      //fdphisigma->SetParameters(sigma_par);
      //dphisigma->Fit("fdphisigma2","Q0","",0.3,5.0);
      fdphisigma->Draw("same");
      fout << "fdphisigma->SetParameters(" << fdphisigma->GetParameter(0) << "," << fdphisigma->GetParameter(1) << "," << fdphisigma->GetParameter(2) << "," << fdphisigma->GetParameter(3) << "," << fdphisigma->GetParameter(4) << "," << fdphisigma->GetParameter(5) << "," << fdphisigma->GetParameter(6) << "," << fdphisigma->GetParameter(7) << ");" << endl;
      for(int ipar=0;ipar<8;ipar++){
      fout2 << "PC3_dphisigma[" << iarm <<"][" << ich << "][" << ivz <<"][" << ipar << "] = " << fdphisigma->GetParameter(ipar) << ";" << endl;
      }
      c1->Print(Form("smooth/dphisigma_%d_%d_%d.png",iarm,ich,ivz));
      delete c1;


      TCanvas *c3 = new TCanvas("c3","c3",500,500);
      c3->SetGridx();
      TGraphErrors* dphimean = new TGraphErrors(50,pt,pc3dphimean[iarm][ich][ivz],errx,pc3dphimeanerr[iarm][ich][ivz]);
      dphimean->SetTitle(Form("dphimean_%s_%s_%s",arm,ch,bbcz));
      dphimean->SetLineColor(1);
      dphimean->SetMarkerStyle(20);
      dphimean->SetMarkerSize(0.8);
      dphimean->GetXaxis()->SetRangeUser(0.2,5.0);
      dphimean->GetHistogram()->SetMaximum(0.01);
      dphimean->GetHistogram()->SetMinimum(-0.01);
      dphimean->GetXaxis()->SetTitle("p_{T}");
      dphimean->GetYaxis()->SetTitle("dphi mean");
      dphimean->Draw("AP");

      TPaveText *p3 = new TPaveText(0.2,0.8,0.9,0.9,"NDC");
      p3->AddText("Fit function: a+bx+#frac{c}{x}+#frac{d}{#sqrt{x}}+#frac{e}{x^{2}}+#frac{f}{x^{3}}+#frac{g}{x^{4}}");
      p3->Draw("same");
      TF1 *fdphimean = new TF1("fdphimean","[0]+[1]*x+[2]/x+[3]/TMath::Sqrt(x)+[4]/x/x+[5]/x/x/x+[6]/x/x/x/x",0.3,5.0);
      //TF1 *fdphimean2 = new TF1("fdphimean2","[0]+[1]*x+[2]/x+[3]/TMath::Sqrt(x)+[4]/x/x+[5]/x/x/x+[6]/x/x/x/x",0.2,5.0);
      dphimean->Fit("fdphimean","Q0","",0.4,4.0);
      double mean_par[7];
      //fdphimean->GetParameters(mean_par);
      //fdphimean2->SetParameters(mean_par);
      //dphimean->Fit("fdphimean2","Q0","",0.3,5.0);
      fdphimean->Draw("same");
      fout << "fdphimean->SetParameters(" << fdphimean->GetParameter(0) << "," << fdphimean->GetParameter(1) << "," << fdphimean->GetParameter(2) << "," << fdphimean->GetParameter(3) << "," << fdphimean->GetParameter(4) << "," << fdphimean->GetParameter(5) << "," << fdphimean->GetParameter(6) << ");" << endl;
      for(int ipar=0;ipar<7;ipar++){
      fout2 << "PC3_dphimean[" << iarm <<"][" << ich << "][" << ivz <<"][" << ipar << "] = " << fdphimean->GetParameter(ipar) << ";" << endl;
      }
      c3->Print(Form("smooth/dphimean_%d_%d_%d.png",iarm,ich,ivz));
      delete c3;

      TCanvas *c2 = new TCanvas("c2","c2",500,500);
      c2->SetGridx();
      TGraphErrors* dzsigma = new TGraphErrors(50,pt,pc3dzsigma[iarm][ich][ivz],errx,pc3dzsigmaerr[iarm][ich][ivz]);
      dzsigma->SetTitle(Form("dzsigma_%s_%s_%s",arm,ch,bbcz));
      dzsigma->SetLineColor(1);
      dzsigma->SetMarkerStyle(20);
      dzsigma->SetMarkerSize(0.8);
      dzsigma->GetXaxis()->SetRangeUser(0.2,5.0);
      dzsigma->GetHistogram()->SetMaximum(5);
      dzsigma->GetHistogram()->SetMinimum(0);
      dzsigma->GetXaxis()->SetTitle("p_{T}");
      dzsigma->GetYaxis()->SetTitle("dz sigma");
      dzsigma->Draw("AP");

      TPaveText *p2 = new TPaveText(0.2,0.8,0.9,0.9,"NDC");
      p2->AddText("Fit function: a+bx+cx^{2}+dx^{3}+ex^{4}+fx^{5}+#frac{g}{#sqrt{x}}+#frac{h}{x^{2}}");
      p2->Draw("same");

      //TF1 *fdzsigma = new TF1("fdzsigma","[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x+[5]/TMath::Sqrt(x)+[6]/x/x",0.3,5.0);
      TF1 *fdzsigma = new TF1("fdzsigma","[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x+[5]*x*x*x*x*x+[6]/TMath::Sqrt(x)+[7]/x/x",0.3,5.0);
      //TF1 *fdzsigma2 = new TF1("fdzsigma2","[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x+[5]/TMath::Sqrt(x)+[6]/x/x",0.2,5.0);
      dzsigma->Fit("fdzsigma","Q0","",0.4,4.0);
      //fdzsigma->GetParameters(sigma_par);
      //fdzsigma2->SetParameters(sigma_par);
      //dzsigma->Fit("fdzsigma2","Q0","",0.3,5.0);
      fdzsigma->Draw("same");
      fout << "fdzsigma->SetParameters(" << fdzsigma->GetParameter(0) << "," << fdzsigma->GetParameter(1) << "," << fdzsigma->GetParameter(2) << "," << fdzsigma->GetParameter(3) << "," << fdzsigma->GetParameter(4) << "," << fdzsigma->GetParameter(5) << "," << fdzsigma->GetParameter(6) << ");" << endl;
      for(int ipar=0;ipar<8;ipar++){
      fout2 << "PC3_dzsigma[" << iarm <<"][" << ich << "][" << ivz <<"][" << ipar << "] = " << fdzsigma->GetParameter(ipar) <<  ";" << endl;
      }
      c2->Print(Form("smooth/dzsigma_%d_%d_%d.png",iarm,ich,ivz));
      delete c2;





      TCanvas *c4 = new TCanvas("c4","c4",500,500);
      c4->SetGridx();
      TGraphErrors* dzmean = new TGraphErrors(50,pt,pc3dzmean[iarm][ich][ivz],errx,pc3dzmeanerr[iarm][ich][ivz]);
      dzmean->SetTitle(Form("dzmean_%s_%s_%s",arm,ch,bbcz));
      dzmean->SetLineColor(1);
      dzmean->SetMarkerStyle(20);
      dzmean->SetMarkerSize(0.8);
      dzmean->GetXaxis()->SetRangeUser(0.2,5.0);
      dzmean->GetHistogram()->SetMaximum(3);
      dzmean->GetHistogram()->SetMinimum(-2);
      dzmean->GetXaxis()->SetTitle("p_{T}");
      dzmean->GetYaxis()->SetTitle("dz mean");
      dzmean->Draw("AP");

      TPaveText *p4 = new TPaveText(0.2,0.8,0.9,0.9,"NDC");
      p4->AddText("Fit function: a+bx+#frac{c}{x}+#frac{d}{#sqrt{x}}+#frac{e}{x^{2}}+#frac{f}{x^{3}}+#frac{g}{x^{4}}");
      p4->Draw("same");

      TF1 *fdzmean = new TF1("fdzmean","[0]+[1]*x+[2]/x+[3]/TMath::Sqrt(x)+[4]/x/x+[5]/x/x/x+[6]/x/x/x/x",0.3,5.0);
      //TF1 *fdzmean2 = new TF1("fdzmean2","[0]+[1]*x+[2]/x+[3]/TMath::Sqrt(x)+[4]/x/x+[5]/x/x/x+[6]/x/x/x/x",0.2,5.0);
      dzmean->Fit("fdzmean","Q0","",0.4,4.0);
      //fdzmean->GetParameters(mean_par);
      //fdzmean2->SetParameters(mean_par);
      //dzmean->Fit("fdzmean2","Q0","",0.3,5.0);
      fdzmean->Draw("same");
      fout << "fdzmean->SetParameters(" << fdzmean->GetParameter(0) << "," << fdzmean->GetParameter(1) << "," << fdzmean->GetParameter(2) << "," << fdzmean->GetParameter(3) << "," << fdzmean->GetParameter(4) << "," << fdzmean->GetParameter(5) << "," << fdzmean->GetParameter(6) << ");" << endl;
      for(int ipar=0;ipar<7;ipar++){
      fout2 << "PC3_dzmean[" << iarm <<"][" << ich << "][" << ivz <<"][" << ipar << "] = " << fdzmean->GetParameter(ipar) <<  ";" << endl;
      }
      c4->Print(Form("smooth/dzmean_%d_%d_%d.png",iarm,ich,ivz));
      delete c4;
      }
    }
  }
  

}
//===============================================================================
void AbsorberStudy_RooFit(){

  //===============================================================================
  gStyle->SetOptTitle(0);
  
  using namespace RooFit;
  
  //The root files with the individual plots 
  const int numberoffiles = 20;
  const int numberofabsorbers = 1;

  TString filename[numberoffiles];
  //e-
  // filename[0]="Scream_50cmFeAbsorber_ele10GeV.root";
  // filename[1]="Scream_50cmFeAbsorber_ele20GeV.root";
  // filename[2]="Scream_50cmFeAbsorber_ele30GeV.root";
  // filename[3]="Scream_50cmFeAbsorber_ele40GeV.root";
  // filename[4]="Scream_50cmFeAbsorber_ele50GeV.root";
  // filename[5]="Scream_50cmFeAbsorber_ele60GeV.root";
  // filename[6]="Scream_50cmFeAbsorber_ele70GeV.root";
  // filename[7]="Scream_50cmFeAbsorber_ele80GeV.root";
  // filename[8]="Scream_50cmFeAbsorber_ele90GeV.root";
  // filename[9]="Scream_50cmFeAbsorber_ele100GeV.root";
  // filename[10]="Scream_50cmFeAbsorber_ele110GeV.root";
  // filename[11]="Scream_50cmFeAbsorber_ele120GeV.root";
  // filename[12]="Scream_50cmFeAbsorber_ele130GeV.root";
  // filename[13]="Scream_50cmFeAbsorber_ele140GeV.root";
  // filename[14]="Scream_50cmFeAbsorber_ele150GeV.root";
  // filename[15]="Scream_50cmFeAbsorber_ele160GeV.root";
  // filename[16]="Scream_50cmFeAbsorber_ele170GeV.root";
  // filename[17]="Scream_50cmFeAbsorber_ele180GeV.root";
  // filename[18]="Scream_50cmFeAbsorber_ele190GeV.root";
  // filename[19]="Scream_50cmFeAbsorber_ele200GeV.root";

  filename[0]="testcalo_e-_10.root";  
  filename[1]="testcalo_e-_20.root";  
  filename[2]="testcalo_e-_30.root";  
  filename[3]="testcalo_e-_40.root";  
  filename[4]="testcalo_e-_50.root";  
  filename[5]="testcalo_e-_60.root";  
  filename[6]="testcalo_e-_70.root";  
  filename[7]="testcalo_e-_80.root";  
  filename[8]="testcalo_e-_90.root";  
  filename[9]="testcalo_e-_100.root"; 
  filename[10]="testcalo_e-_110.root"; 
  filename[11]="testcalo_e-_120.root"; 
  filename[12]="testcalo_e-_130.root"; 
  filename[13]="testcalo_e-_140.root"; 
  filename[14]="testcalo_e-_150.root"; 
  filename[15]="testcalo_e-_160.root"; 
  filename[16]="testcalo_e-_170.root"; 
  filename[17]="testcalo_e-_180.root"; 
  filename[18]="testcalo_e-_190.root"; 
  filename[19]="testcalo_e-_200.root"; 





  //Energy distributions we want to fit 
  TString energy[numberofabsorbers];
  energy[0] = "histo/33";
 
  //For the maxv and sigma plot 
  std::vector<double> ene;
  std::vector<double> maxv;
  std::vector<double> thesigma;
  std::vector<double> eneerr;
  std::vector<double> maxvr;
  std::vector<double> thesigmaerr;
  ene.push_back(10.);ene.push_back(20.);ene.push_back(30.);ene.push_back(40.);ene.push_back(50.);ene.push_back(60.);ene.push_back(70.);ene.push_back(80.);
  ene.push_back(90.);ene.push_back(100.);ene.push_back(110.);ene.push_back(120.);ene.push_back(130.);ene.push_back(140.);ene.push_back(150.);ene.push_back(160.);
  ene.push_back(170.);ene.push_back(180.);ene.push_back(190.);ene.push_back(200.);
  
  //Useful parameters for the fitting
  double I = 0.;
  double histo_mean = 0.;
  double RMS = 0.;
  int   division = 0;
  float eneMIN = 0.;
  float eneMAX = 0.;
  float BIN_SIZE = 0.;
  float histomaximum = 0.;

  //======================================================================================
  //Canvas
  TCanvas *can[numberoffiles][numberofabsorbers];
  TString canname;

  TCanvas *canmaxv[numberoffiles];
  
  //======================================================================================
  //Read the files and histograms here
  TFile* files[numberoffiles];
  for (int k=0; k<numberoffiles; k++){
    files[k]= new TFile(filename[k]);
  }
  TH1F * histo[numberoffiles][numberofabsorbers];

  for (int i=0; i<numberoffiles; i++){
    gROOT->Reset();
    for (int k=0; k<numberofabsorbers; k++){
      histo[i][k]= (TH1F*) files[i]->Get(energy[k]);

      if (!histo[i][k]){std::cerr << "Could not get histogram " << energy[k] << "in file "
				    <<  files[i]->GetName() << std::endl;}
      std::cout << "=========================================================================" << std::endl;
      std::cout << files[i]->GetName() << std::endl;

      canname = filename[i] + histo[i][k]->GetName();
      can[i][k] = new TCanvas(canname, canname,800,600);
      can[i][k]->cd();

      histo[i][k]->Draw();
      // histo[i][k]->Scale(0.1);//This is for the 10 events I run.
      //Set the initial values for the fitting
      I = histo[i][k]->Integral();
      histo_mean = histo[i][k]->GetMean();
      RMS = histo[i][k]->GetRMS();
      division = histo[i][k]->GetNbinsX();
      eneMIN = histo[i][k]->GetBinLowEdge(1);
      eneMAX = histo[i][k]->GetBinLowEdge(division+1);
      BIN_SIZE = histo[i][k]->GetBinWidth(1);
      histomaximum = histo[i][k]->GetBinContent(histo[i][k]->GetMaximumBin());
      
      // Declare observable x
      RooRealVar x("x","x",eneMIN,eneMAX) ;
      eneMIN = histo[i][k]->GetMaximumBin() - RMS; eneMAX = histo[i][k]->GetMaximumBin() + RMS;
      // std::cout << histo[i][k]->GetMaximumBin() << std::endl;
      // eneMIN = 50; eneMAX = 200.;
      x.setRange("fitRegion1",eneMIN  ,  eneMAX );

      RooDataHist dh("dh","dh",x,Import(*histo[i][k])) ;
      
      RooPlot* frame = x.frame(Title(filename[i]), Bins(1000)) ;
      dh.plotOn(frame,MarkerColor(2),MarkerSize(0.9),MarkerStyle(21));  //this will show histogram data points on canvas 
      dh.statOn(frame);  //this will display hist stat on canvas
      
      RooRealVar mean("mean","mean",histo_mean, eneMIN, eneMAX);
      RooRealVar width("width","width",RMS, eneMIN, eneMAX);
      RooRealVar sigma("sigma","sigma",RMS, eneMIN, eneMAX);
      
       RooGaussian gauss("gauss","gauss",x,mean,sigma);
      // RooExponential expo("expo", "exponential PDF", x, lambda);
      
      // Construct landau(t,ml,sl) ;
      //RooLandau landau("lx","lx",x,mean,sigma) ;
  
      //RooBreitWigner BW1("BW1","Breit Wigner theory",x,mean,sigma);
      RooVoigtian bwandgaus("bwandgaus", "Breit Wigner convoluted with gauss",x,mean,width,sigma);
      //RooCBShape cryBall1("cryBall1","Crystal Ball resolution model", x, CBmean, CBsigma, CBalpha, CBn) ;
      //RooFFTConvPdf bwxCryBall1("bwxCryBall1", "FFT Conv CryBall and BW", x, BW1, cryBall1); 
      // RooBreitWigner gauss("gauss","gauss",x,mean,sigma);
      // RooVoigtian gauss("gauss","gauss",x,mean,width,sigma);

      // RooFitResult* filters = gauss.fitTo(dh, NumCPU(4), Range(("fitRegion"+IntToString(i)).c_str()), Save(true), SumW2Error(kTRUE), PrintLevel(-1));
       RooFitResult* filters = gauss.fitTo(dh, NumCPU(4), Range("fitRegion1"), Save(true), SumW2Error(kTRUE), PrintLevel(-1));
      //RooFitResult* filters = bwxCryBall1.fitTo(dh, NumCPU(4), Range("fitRegion1"), Save(true), SumW2Error(kTRUE), PrintLevel(-1));
      // RooFitResult* filters = BW1.fitTo(dh, NumCPU(4), Range("fitRegion1"), Save(true), SumW2Error(kTRUE), PrintLevel(-1));
      //RooFitResult* filters = bwandgaus.fitTo(dh, NumCPU(4), Range("fitRegion1"), Save(true), SumW2Error(kTRUE), PrintLevel(-1));
      // RooFitResult* filters = sum.fitTo(dh, NumCPU(4), Range("fitRegion1"), Save(true), SumW2Error(kTRUE), PrintLevel(-1));
      // RooFitResult* filters = gauss.fitTo(dh, NumCPU(4), Save(true), SumW2Error(kTRUE), PrintLevel(-1));

      //RooFitResult* filters = landau.fitTo(dh, NumCPU(4), Range("fitRegion1"), Save(true), SumW2Error(kTRUE), PrintLevel(-1));
      gauss.plotOn(frame,LineColor(4));//this will show fit overlay on canvas 
      gauss.paramOn(frame); //this will display the fit parameters on canvas
      
      filters->Print();
      
      // // Access list of final fit parameter values
      // std::cout << "final value of floating parameters" << std::endl ;
      // filters->floatParsFinal().Print("s") ;
      
      //mpc = fit->GetParameter(1) - mpshift * fit->GetParameter(2); 
      mpc = mean.getVal();

      maxv.push_back(mpc);
      maxvr.push_back( (mean.getError()) );
      eneerr.push_back(0.);

      thesigma.push_back( (sigma.getVal()) );
      thesigmaerr.push_back( (sigma.getError()) );
   
      // std::cout << "File " << filename[i] << " Eneer " << k << " MAXV "<< mpc << std::endl;

      // can[i][k]->Print(canname + ".root",".root");
      // can[i][k]->Close();
  
  	// // Draw all frames on a canvas
	// can[k] = new TCanvas(filename[i], filename[i],800,600);
	// can[k]->cd();
	// gPad->SetLeftMargin(0.15);
	// frame->GetXaxis()->SetTitle("E (GeV)");  
	// frame->GetXaxis()->SetTitleOffset(1.2);
	// frame->GetXaxis()->SetRangeUser(0.,0.05);
	// // float binsize = histo[i][k]->GetBinWidth(1); 
	// // char Bsize[50]; 
	// //sprintf(Bsize,"Events per %2.2f",binsize);
	// frame->GetYaxis()->SetTitle("Events");  
	//frame->GetYaxis()->SetTitleOffset(1.2);
	frame->Draw() ;
	// can[k]->Print(filename[i]+".pdf",".pdf");
	// can[k]->Print(histogramname[k]+".png",".png");
	// can[k]->Close();

	can[i][k]->Print(canname + ".root",".root");
	//can[i][k]->Close();


      

      
    } // end of loop over histos  
    //For the multi plot
 
  } // end of loop over files

   TFile f("maxvandsigma.root","recreate");

  TGraphErrors *grMAXV = new TGraphErrors(maxv.size(),&ene[0],&maxv[0],&maxvr[0],&eneerr[0]);
  TGraphErrors *grSigma = new TGraphErrors(thesigma.size(),&ene[0],&thesigma[0],&thesigmaerr[0],&eneerr[0]);
     
  //======================================================================================
  //For the maxv plot
  TCanvas *c1 = new TCanvas("c1","maxv",200,10,1200,968); 
  grMAXV->SetMarkerStyle(20); 
  grMAXV->SetMarkerSize(1.2); 
  grMAXV->Draw("APL");
  c1->Update();
  grMAXV->SetTitle( " Maximum energy loss for different e^{-} energies in Fe absorber " );
  grMAXV->GetHistogram()->SetXTitle(" Energy (GeV) ");
  grMAXV->GetHistogram()->SetYTitle(" Maximum energy loss location (mm) ");
  grMAXV->GetYaxis()->SetRangeUser(50.,150.);
  c1->Update();

  //c1->Print("maxv.png",".png");

  c1->Write();
  c1->Close();


  //======================================================================================
  //For the sigma plot
  TCanvas *c2 = new TCanvas("c2","sigma",200,10,1200,968); 
  grSigma->SetMarkerStyle(20); 
  grSigma->SetMarkerSize(1.2); 
  grSigma->Draw("APL");
  c2->Update();

  grSigma->SetTitle( " Sigma Value for different e^{-} energies  " );
  grSigma->GetHistogram()->SetXTitle(" Energy (GeV) ");
  grSigma->GetHistogram()->SetYTitle(" Sigma (mm) ");
  //grSigma->GetYaxis()->SetRangeUser(0.20,0.40);
  c2->Update();
  //c2->Print("sigma.png",".png");
  c2->Write();
  c2->Close();
  f.Close();


}
void plot_rcp_for_energy( string energy = "15", bool pannel = false ){

	RooPlotLib rpl;

	TH1 * master = new TH1D( "frame", "frame", 100, 0, 10 );
	master->Draw();

	if ( !pannel  ){
		gPad->SetLeftMargin( 0.15 );
		gPad->SetBottomMargin( 0.15 );
		gPad->SetRightMargin( 0.01 );
		gPad->SetTopMargin( 0.01 );
	}

	gStyle->SetTitleFontSize(0.1);

	vector<string> plcs = { "Ks0", "Lambda", "Xi" };

	if ( "19" == energy || "27" == energy || "39" == energy )
		plcs.push_back( "Omega" ); 


	TLegend * leg = new TLegend( 0.2, 0.5, 0.65, 0.85 );
	leg-> SetNColumns(2);
	leg->SetTextFont( 52 );
	leg->SetTextSize( 0.07 ); 

	int index = 0;
	for ( string plc : plcs){
		TGraphErrors * g = plot_single_rcp( energy, plc );

		rpl.style( g )
			.set( "color", colors[ index ] )
			.set( "markerstyle", markers[ index ] )
			.set( "markersize", 2 );

		rpl.style( g->GetHistogram() )
			.set( "titlesize", 0.25 );

		leg->AddEntry( g, legend_label(plc).c_str(), "pe" );


		index ++;
	}

	rpl.style( master )
		//.set( "title", energy + " GeV; p_{T} [GeV/c]; R_{CP} (0-5%) / (40-60%)" )
		.set( "title", energy_label( energy ) + " GeV; p_{T} [GeV/c]" )
		.set( "optstat", 0 )
		.set( "yr", 0.2, 4.2 )
		.set( "xr", 0.2, 5.2 )
		.set( "xls", 0.08 )
		.set( "yls", 0.08 )
		.set( "yts", 0.08 )
		.set( "xts", 0.08 );

	TLine * lUnity = new TLine( 0.2, 1, 5.2, 1 );
	rpl.style( lUnity )
		.set( "color", kBlack )
		.set( "linewidth", 4 )
		.set( "linestyle", kDashed )
		.set( "draw", "same" )
		.draw();

	if ( "39" == energy )
		leg->Draw("same");
	



}
int main(int argc, char**argv)
{

// Set style options
	gROOT->Reset();
	gROOT->SetStyle("Plain");

	gStyle->SetPadTickX(1);
	gStyle->SetPadTickY(1);
	gStyle->SetOptTitle(0);
	gStyle->SetOptStat(0);
	gStyle->SetOptFit(0);
	gStyle->SetFitFormat("6.3g");
	gStyle->SetPalette(1);

	gStyle->SetTextFont(42);
	gStyle->SetTextSize(0.05);
	gStyle->SetTitleFont(42, "xyz");
	gStyle->SetTitleSize(0.05);
	gStyle->SetLabelFont(42, "xyz");
	gStyle->SetLabelSize(0.05);
	gROOT->ForceStyle();

/// Input File MCTruth IC Map , RECO IC map, MC IC set after calibration (Usually set with miscalibration 5%)
/// and StatPrecision IC coefficient obtained from CalibrationBarrel.cpp

	if(argc != 2) {
		std::cerr << ">>>>> analysis.cpp::usage: " << argv[0] << " configFileName" << std::endl ;
		return 1;
	}

	std::string configFileName = argv[1];
	std::shared_ptr<edm::ParameterSet> parameterSet = edm::readConfig(configFileName);
	edm::ParameterSet Options = parameterSet -> getParameter<edm::ParameterSet>("Options");

	std::string inputFile = "NULL";
	if(Options.existsAs<std::string>("inputFile"))
		inputFile = Options.getParameter<std::string>("inputFile");

	std::string fileMCTruth = "NULL";
	if(Options.existsAs<std::string>("fileMCTruth"))
		fileMCTruth = Options.getParameter<std::string>("fileMCTruth");

	std::string fileMCRecoIC = "NULL";
	if(Options.existsAs<std::string>("fileMCRecoIC"))
		fileMCRecoIC = Options.getParameter<std::string>("fileMCRecoIC");

	std::string fileStatPrecision = "NULL";
	if(Options.existsAs<std::string>("fileStatPrecision"))
		fileStatPrecision = Options.getParameter<std::string>("fileStatPrecision");

	TApplication* theApp = new TApplication("Application", &argc, argv);


	TFile *f1 = TFile::Open(fileMCTruth.c_str());
	TFile *f2 = TFile::Open(fileMCRecoIC.c_str());
	TFile *f3 = TFile::Open(inputFile.c_str());
	TFile *f4 = TFile::Open(fileStatPrecision.c_str());

	if( f1 == 0 || f2 == 0 || f3 == 0 || f4 == 0) return -1;

	TH2F *hcmapMcT = (TH2F*)f1->Get("h_scale_map");
	TH2F *hcmapMcR = (TH2F*)f2->Get("h_scale_map");

	TH2F * hcmap1 = (TH2F*)hcmapMcT->Clone("hcmap1");
	hcmap1->Reset();
	TH1F * hringdiff = new TH1F("hringdiff", "difference of ring average", 100, -0.1, 0.1);

	for (int jbin = 1; jbin < hcmap1-> GetNbinsY(); jbin++) {
		for (int ibin = 1; ibin < hcmap1-> GetNbinsX() + 1; ibin++) {
			hcmap1->SetBinContent(ibin, jbin, hcmapMcT->GetBinContent(ibin, jbin) / hcmapMcR->GetBinContent(ibin, jbin));
		}
	}


	TH2F * miscalib_map = (TH2F*) f3 -> Get("h_scalib_EB");
	TH2F *hcL3 = (TH2F*)f3->Get("h_scale_map");

	TH2F *hcmap2 = (TH2F*)hcL3 ->Clone("hcmap2");
	hcmap2->Reset();

	for (int jbin = 1; jbin < hcmap2-> GetNbinsY() + 1; jbin++) {
		for (int ibin = 1; ibin < hcmap2-> GetNbinsX() + 1; ibin++) {
			hcmap2->SetBinContent(ibin, jbin, miscalib_map->GetBinContent(ibin, jbin)*hcL3->GetBinContent(ibin, jbin));
		}
	}

/// IC Histogramm in Eta ring and 2D map difference
	TH2F * h2 = new TH2F("h2", "h2", 400, 0.5, 1.5, 400, 0.5, 1.5);
	TH2F * h2diff = (TH2F*)hcmap1->Clone("h2diff");
	h2diff->Reset();
	TH1F *hdiff = new TH1F("hdiff", "hdiff", 400, -0.5, 0.5);

	char hname[100];

	TH1F *hspread[172];
	for (int jbin = 1; jbin < hcmap1-> GetNbinsY() + 1; jbin++) {
		int etaring = hcmap1-> GetYaxis()->GetBinCenter(jbin);
		sprintf(hname, "hspread_ring_ieta%02d", etaring);
		hspread[jbin - 1] = new TH1F(hname, hname, 400, -0.5, 0.5);
	}

	for (int jbin = 1; jbin < hcmap1-> GetNbinsY() + 1; jbin++) {
		float etaring = hcmap1-> GetYaxis()->GetBinCenter(jbin);
		for (int ibin = 1; ibin < hcmap1-> GetNbinsX() + 1; ibin++) {
			float c1 = hcmap1->GetBinContent(ibin, jbin);
			float c2 = hcmap2->GetBinContent(ibin, jbin);
			if (c1 != 0 && c2 != 0 ) {
				hspread[jbin - 1]->Fill( c1 - c2 );
				h2->Fill(c1, c2);
				h2diff->SetBinContent(ibin, jbin, c1 - c2);
				if (fabs(etaring) < 40) hdiff->Fill(c1 - c2);

			}
		}
	}

/// Final Plot in eta ring (stat prescision and scale)
	TGraphErrors *sigma_vs_ieta = new TGraphErrors();
	sigma_vs_ieta->SetMarkerStyle(20);
	sigma_vs_ieta->SetMarkerSize(1);
	sigma_vs_ieta->SetMarkerColor(kBlue + 2);

	TGraphErrors *rms_vs_ieta = new TGraphErrors();
	rms_vs_ieta->SetMarkerStyle(24);
	rms_vs_ieta->SetMarkerSize(1);
	rms_vs_ieta->SetMarkerColor(kBlue + 2);

	TGraphErrors *scale_vs_ieta = new TGraphErrors();
	scale_vs_ieta->SetMarkerStyle(20);
	scale_vs_ieta->SetMarkerSize(1);
	scale_vs_ieta->SetMarkerColor(kBlue + 2);

/// Gaussian Fit of spread coefficient dstribution
	TF1 *fgaus = new TF1("fgaus", "gaus", -1, 1);
	int np = 0;
	for (int i = 1; i < hcmap1-> GetNbinsY() + 1; i++) {
		float etaring = hcmap1-> GetYaxis()->GetBinCenter(i);
		if (etaring == 0.5) continue;
		if ( hspread[i - 1]->GetEntries() == 0) {
			sigma_vs_ieta-> SetPoint(np, etaring, -100);
			np++;
			continue;
		}
		hspread[i - 1]->Fit("fgaus", "Q");
		sigma_vs_ieta-> SetPoint(np, etaring, fgaus->GetParameter(2));
		sigma_vs_ieta-> SetPointError(np, 0, fgaus->GetParError(2));
		rms_vs_ieta  -> SetPoint(np, etaring, hspread[i - 1]->GetRMS());
		rms_vs_ieta  -> SetPointError(np, 0, hspread[i - 1]->GetRMSError() );
		scale_vs_ieta-> SetPoint(np, etaring, fgaus->GetParameter(1));
		scale_vs_ieta-> SetPointError(np, 0, fgaus->GetParError(1));
		if( fabs(etaring) < 20 ) {
			hringdiff->Fill( fgaus->GetParameter(1) );
		}
		np++;
	}

	/// Final Plot
	TGraphErrors* gr_stat_prec = (TGraphErrors*) f4->Get("gr_stat_prec");
	TCanvas *csigma = new TCanvas("csigma", "csigma");
	csigma->SetGridx();
	csigma->SetGridy();
	sigma_vs_ieta->GetHistogram()->GetYaxis()-> SetRangeUser(0.00, 0.2);
	sigma_vs_ieta->GetHistogram()->GetXaxis()-> SetRangeUser(-85, 85);
	sigma_vs_ieta->GetHistogram()->GetYaxis()-> SetTitle("#sigma");
	sigma_vs_ieta->GetHistogram()->GetXaxis()-> SetTitle("ieta");
	sigma_vs_ieta->Draw("ap");
	rms_vs_ieta->Draw("psame");
	gr_stat_prec->Draw("psame");


/// Residual Plot (spread - statistical precision)
	TGraphErrors* residual = new TGraphErrors();

	for(int pp = 0; pp < gr_stat_prec->GetN(); pp++) {
		double eta1, eta2, tot, stat;
		gr_stat_prec->GetPoint(pp, eta1, stat);
		sigma_vs_ieta->GetPoint(pp, eta2, tot);
		if(eta1 != eta2) {
			cout << "error different ring " << eta1 << "  " << eta2 << endl;
		}
		double res = tot * tot - stat * stat;
		if (res > 0) res = sqrt(res);
		else res = -sqrt(fabs(res));
		double errres = sqrt( pow(tot * sigma_vs_ieta->GetErrorY(pp), 2) + pow(stat * gr_stat_prec->GetErrorY(pp), 2)) / fabs(res);
		residual->SetPoint(pp, eta1, res);
		residual->SetPointError(pp, 0, errres);
	}

/// Residual spread plot
	TCanvas *cres = new TCanvas("cres", "cresidual");
	cres->SetGridx();
	cres->SetGridy();
	residual->GetHistogram()->GetYaxis()-> SetRangeUser(-0.1, 0.1);
	residual->GetHistogram()->GetXaxis()-> SetRangeUser(-85, 85);
	residual->GetHistogram()->GetYaxis()-> SetTitle("residual");
	residual->GetHistogram()->GetXaxis()-> SetTitle("ieta");
	residual ->SetMarkerStyle(20);
	residual->SetMarkerSize(1);
	residual->SetMarkerColor(kGreen + 2);
	residual->GetYaxis()->SetTitle("residual");
	residual->GetXaxis()->SetTitle("i#eta");
	residual->Draw("ap");

/// scale vs eta plot
	TCanvas *cscale = new TCanvas("cscale", "cscale");
	cscale->SetGridx();
	cscale->SetGridy();
	scale_vs_ieta->GetHistogram()->GetYaxis()-> SetRangeUser(-0.1, 0.1);
	scale_vs_ieta->GetHistogram()->GetXaxis()-> SetRangeUser(-85, 85);
	scale_vs_ieta->GetHistogram()->GetYaxis()-> SetTitle("c_{1}-c_{2}");
	scale_vs_ieta->GetHistogram()->GetXaxis()-> SetTitle("ieta");
	scale_vs_ieta->Draw("ap");

/// IC Diff map
	TCanvas *cmap2 = new TCanvas("cmap2", "cmap2", 500, 500);
	cmap2->SetGridx();
	cmap2->SetGridy();
	cmap2 -> cd();
	cmap2->SetLeftMargin(0.1);
	cmap2->SetRightMargin(0.15);
	h2->GetXaxis()->SetRangeUser(0.85, 1.15);
	h2->GetYaxis()->SetRangeUser(0.85, 1.15);
	h2->GetXaxis()->SetTitle("C_{1}");
	h2->GetYaxis()->SetTitle("C_{2}");
	h2->Draw("colz");

	TCanvas *cdiff = new TCanvas("cdiff", "cdiff", 700, 500);
	cdiff->SetGridx();
	cdiff->SetGridy();
	cdiff -> cd();
	cdiff->SetLeftMargin(0.1);
	cdiff->SetRightMargin(0.15);
	h2diff->GetZaxis()->SetRangeUser(-0.05, 0.05);
	h2diff->GetXaxis()->SetTitle("i#phi");
	h2diff->GetYaxis()->SetTitle("i#eta");
	h2diff->Draw("colz");

	theApp->Run();

	return 0;
}