Ejemplo n.º 1
0
TH2F* mergeBackground(TFile* fa,const char* pattern,const char * theSbtag,const char* newname,const string scenario) {
  std::cout << "mergeBackground: newname = " << newname << std::endl;
  const int nTrig=3;
  const int nfc=3;
  const int ncateg=3;
  string sfc[nfc] = { "q", "c", "b" };
  TH2F* theData[nTrig][nfc][ncateg];
  if (fa == NULL) {
    std::cout << "mergeBackground: no hfile opened" << std::endl;
    return NULL;
  }

  // no weights
  for (int iTrig=0; iTrig<nTrig; ++iTrig) {
    for (int ifc=0; ifc<nfc; ++ifc) {
      for (int icateg=0; icateg<ncateg; ++icateg) {
	//string sname( Form(Form("%sTrig%d",pattern,iTrig),sfc[ifc].c_str(),theSbtag,icateg,icateg) );
	string sname( Form("bgPredict/MassBTagPred_%s_%s_Cat%dTpat%dTrig%d",
			   sfc[ifc].c_str(),theSbtag,icateg,icateg,iTrig) );
	theData[iTrig][ifc][icateg] = (TH2F*) fa->Get( sname.c_str());
	if (theData[iTrig][ifc][icateg] == NULL) {
	  std::cout << "mergeBackground: histogram " << sname << " not found" << std::endl;
	  return 0;
	}
    //theData[ii]->Draw();
      }
    }
  }

  TH2F* mergedData = new TH2F( *theData[0][0][0] );
  mergedData->SetName( newname );
  mergedData->SetTitle( newname );
  for (int iTrig=0; iTrig<nTrig; ++iTrig) {
    for (int ifc=0; ifc<nfc; ++ifc) {
      for (int icateg=0; icateg<ncateg; ++icateg) {
	if (! ((iTrig == 0) && (ifc == 0) && (icateg == 0) )) {
	  mergedData->Add( theData[iTrig][ifc][icateg] );
	  std::cout << "mergeBackground: adding " << theData[iTrig][ifc][icateg]->GetName() << std::endl;
	}
      }
    }
  }  
  std::cout << "mergeBackground: newname(4) = " << newname << std::endl;

  // cross check total weight
  double tw = 0;
  for (int iTrig=0; iTrig<nTrig; ++iTrig) {
    for (int ifc=0; ifc<nfc; ++ifc) {
      for (int icateg=0; icateg<ncateg; ++icateg) {
	tw += theData[iTrig][ifc][icateg]->GetSumOfWeights();
      }
    }
  }
  std::cout << newname << " Sum = " << tw << "  mergedData = " << mergedData->GetSumOfWeights() << std::endl;
  std::cout << mergedData->GetName() << std::endl;
  
  // final normalization (from control region)
  double wScale = 1;
  string sb( theSbtag );
  if (scenario == "LowMass2011") {
    {
      if ( sb == "CSVT" ) {
	wScale = 1.07817;
      } else if ( sb == "TCHPT" ) {
	wScale = 0.970401;
      }
    }
  } else if (scenario == "MediumMass2011") {
    {
      if ( sb == "CSVT" ) {
	wScale = 0.9505;
      } else if ( sb == "TCHPT" ) {
	wScale = 0.874897;
      }
    }
  

   } else if (scenario == "MediumMass2012") {

	       if ( sb == "CSVT" ) 
           wScale = 0.9505;
        if ( sb == "TCHPT" ) 
          wScale = 0.874897;

}

else {
    std::cout << "merge background: bad scenario " << scenario << std::endl;
    return 0;
  }
  std::cout << "Use expected background scale factor of " << wScale << " for " << theSbtag 
	    << " scenario " << scenario << std::endl;
  mergedData->Scale( wScale );
  std::cout << newname << " After final normalization: " << mergedData->GetSumOfWeights() << std::endl;

  return mergedData;
}