void checkTriggers()
{
  triggers.clear();

  triggers.push_back("HLT_Mu23_TrkIsoVVL_Ele8_CaloIdL_TrackIdL_IsoVL_v*");
  triggers.push_back("HLT_Mu8_TrkIsoVVL_Ele23_CaloIdL_TrackIdL_IsoVL_v*");
  triggers.push_back("HLT_Ele27_eta2p1_WPLoose_Gsf_v*");
  triggers.push_back("HLT_IsoMu22_v*");
  triggers.push_back("HLT_IsoTkMu22_v*");
  triggers.push_back("HLT_Ele23_Ele12_CaloIdL_TrackIdL_IsoVL_DZ_v*");
  triggers.push_back("HLT_Mu17_TrkIsoVVL_TkMu8_TrkIsoVVL_v*");
  triggers.push_back("HLT_Mu17_TrkIsoVVL_Mu8_TrkIsoVVL_v*");

  TFile* file = new TFile(_lxplus + "21Jun2016_Run2016B_PromptReco/l2loose__hadd__EpTCorr__l2tight/latino_Run2016B_PromptReco_MuonEG.root");

  TH1F* selectedTriggers = (TH1F*)file->Get("selectedTriggers");

  TAxis* xaxis = (TAxis*)selectedTriggers->GetXaxis();

  printf("\n Checking %d triggers\n\n", (int)triggers.size());

  for (int i=0; i<triggers.size(); i++)
    {
      for (int j=0; j<=selectedTriggers->GetNbinsX(); j++)
	{
	  TString label = (TString)xaxis->GetBinLabel(j);

	  if (label.Length() < 1) continue;

	  if (triggers[i].EqualTo(label)) printf(" found [%d] %s\n", i, label.Data());
	}
    }

  printf("\n");
}
Exemple #2
0
void printStat(const char* fl)
{
  printf("Stat for %s\n",fl);
  TFile* ff = TFile::Open(fl);
  TList* lst = (TList*)ff->Get("clist");
  if (!lst) {printf("no clist\n");return;}
  TH1* hstat = (TH1*)lst->FindObject("stat");
  if (!hstat) {printf("no hstat\n");return;}
  //
  TAxis* ax = hstat->GetXaxis();
  for (int ib=1;ib<ax->GetNbins();ib++) {
    double val = hstat->GetBinContent(ib);
    if (val) printf("%-20s\t%9d\n",ax->GetBinLabel(ib),int(val));
  }
  ff->Close();
  delete ff;
  return;
}
TH1* VariableSizeRebin(TH1* inhisto, unsigned int nbinsx,
		       double *xbins, TString axisname="x",
		       TString newhistoname="newhist")
{
  if ( nbinsx == 0 ) {
    cout << "Error! nbinsx must be non-zero." << endl; return 0; }

  if ( inhisto == 0 ) {
    cout << "Error! Input histogram pointer is null." << endl; return 0; }

  if ( axisname == "y"  &&  !inhisto->InheritsFrom("TH2") ) {
    cout << "No y-axis defined for " << inhisto->GetName() << endl; return 0; }

  if ( newhistoname == "" ) {
    cout << "Error! Output histogram name is null."<< endl; return 0; }

  double *edgeArr = new double[nbinsx+2]; // an extra bin for safety

  TAxis *axis = (axisname=="y" ? inhisto->GetYaxis() : inhisto->GetXaxis());

  unsigned int nbins = 0; // number of bins for the new histogram
  unsigned int j = 0; // dummy bin index (to be used as a pointer)

  for ( unsigned int i=0; i<=axis->GetNbins()+1; ++i ) {

    if ( j > nbinsx ) break;

    double ble = axis->GetBinLowEdge(i);

    if ( xbins[j] > ble ) continue;

    edgeArr[nbins] = ble; j++; nbins++;

    if ( xbins[j-1] < ble ) {
      cout << "Warning! Bin edge at " << xbins[j-1] << " does not align with"
	   << " input histo. Realigning at " << ble << ".\n";
      // check if the upcoming bin edges become obsolete after realigning.
      while ( j<=nbinsx && xbins[j] <= ble ) j++;
    }

  }

  // if we finished the loop normally, ie. not 'break'ing out, it must be
  // that the input histogram xrange is shorter than what the new binning
  // tried to get. So handle that.
  if ( j <= nbinsx ) {
    double xmax = axis->GetBinLowEdge(axis->GetNbins()+1);
    if ( xmax>edgeArr[nbins-1] ) {
      edgeArr[nbins]=xmax;
      cout << "Warning! Input histo reached max value of its x-range. "
	   << "Last bin to be closed at " << edgeArr[nbins] << "." << endl;
      nbins++; }
  }

  // we go out of the loop when index j overshoots. So our nbins is
  // always one more than actual number of bins. Fix that.
  nbins--;

  if ( nbinsx != nbins )
    cout << "Warning! nbinsx set to " << nbins
	 << " instead of " << nbinsx << "." << endl;

  //for ( unsigned int i=0; i<=nbins; i++ )
  //  cout << "For bin " << i+1 << "\tlowedge= " << edgeArr[i] << endl;

  // Now generate the new histogram
  TH1 *newhist = 0;

  if ( !inhisto->InheritsFrom("TH2") )
    newhist = inhisto->Rebin(nbins,newhistoname.Data(),edgeArr);

  else {

    // Copy the perpendicular axis as it is.
    TAxis *axisp = (axisname=="y" ? inhisto->GetXaxis() : inhisto->GetYaxis());
    unsigned int nbinsp = axisp->GetNbins();
    double *edgeArrp = new double[nbinsp+1];
    for ( unsigned int i=1; i<=nbinsp+1; ++i )
      edgeArrp[i] = axisp->GetBinLowEdge(i);

    if ( axisname == "y" ) {

      if ( axisp->IsVariableBinSize() )
	newhist = new TH2D(newhistoname, inhisto->GetTitle(),
			   nbinsp, edgeArrp, nbins, edgeArr);
      else
	newhist = new TH2D(newhistoname, inhisto->GetTitle(),
			   nbinsp, edgeArrp[0], edgeArrp[nbinsp+1],
			   nbins, edgeArr);

      if ( axisp->GetLabels() )
	for ( unsigned int i=1; i<=nbinsp; ++i )
	newhist->GetXaxis()->SetBinLabel(i, axisp->GetBinLabel(i));

    }
    else
      // ToDo: Have not yet implemented the above nice stuff for axisname=="x"
      newhist = new TH2D(newhistoname, inhisto->GetTitle(),
			 nbins, edgeArr, nbinsp, edgeArrp);

    newhist->GetYaxis()->SetTitle(inhisto->GetYaxis()->GetTitle());
    newhist->GetXaxis()->SetTitle(inhisto->GetXaxis()->GetTitle());
    bool sw2 = ( inhisto->GetSumw2N() != 0 );

    // Fill the new histogram from the input histogram
    j=0; // reset the dummy bin index
    for ( unsigned int i=0; i<=axis->GetNbins()+1; ++i ) {

      double ble = axis->GetBinLowEdge(i);
      if ( edgeArr[j] == ble ) j++; 

      for ( unsigned int k=0; k<=nbinsp+1; ++k ) {

	int newbin(0), oldbin(0);
	// Equivalent 1D bin number = binx + (fXaxis.GetNbins()+2)*biny
	if ( axisname == "y" ) {
	  newbin = k+j*(nbinsp+2); oldbin = k+i*(nbinsp+2); }
	else {
	  newbin = j+k*(nbins+2); oldbin = i+k*(axis->GetNbins()+2); }

	newhist->SetBinContent( newbin, newhist->GetBinContent(newbin)
				+ inhisto->GetBinContent(oldbin) );
	if ( sw2 )
	  newhist->SetBinError( newbin,
			        sqrt(pow(newhist->GetBinError(newbin),2) +
				     pow(inhisto->GetBinError(oldbin),2)) );
      }
    }

    newhist->SetEntries(inhisto->GetEntries());

  }

  //newhist->Draw();
  delete [] edgeArr;
  return newhist;
}
Exemple #4
0
void MPDummyForLowStat(const char* stfile, int thr=30, int nGen=40,Bool_t bin=kTRUE)
{
  // show degrees of freedom with low stat
  TFile* fl = TFile::Open(stfile);
  if (!fl) {printf("Failed to open %s\n",stfile); return;}
  TList* lst = (TList*)fl->Get("clist");
  if (!lst) {printf("No clist in %s\n",stfile); return;}
  TH1* hstdof = (TH1*)lst->FindObject("DOFstat");
  if (!hstdof) {printf("No DOFstat histo in %s\n",stfile); return;}
  //
  int ndof = hstdof->GetNbinsX();
  TAxis* xax = hstdof->GetXaxis();
  printf("%4s\t%-50s\t%s","cnt"," DOF ID_name","entries");
  Mille* ml = 0;
  AliAlgSteer* algSteer=0;
  AliAlgMPRecord* mpRec=0;
  //
  if (bin) ml = new Mille(Form("%s.%s",mpDummy.Data(),"mille"));
  else {
    algSteer = new AliAlgSteer();
    algSteer->SetMPDatFileName(mpDummy.Data());
    algSteer->SetMPOutType(AliAlgSteer::kMPRec);
    algSteer->InitMPRecOutput();
    mpRec = algSteer->GetMPRecord();
  }
  //
  int   labDum[1] = {0}, cnt=0;
  float locDum[1] = {0}, gloDum[1] = {kDummyDer};
  //
  for (int i=1;i<=ndof;i++) {
    if (hstdof->GetBinContent(i)>thr) continue;
    TString labS = xax->GetBinLabel(i);
    printf("%4d\t%-50s\t%7d\n",cnt++,labS.Data(),(int)hstdof->GetBinContent(i));
    int indL = labS.Index("_");
    if (indL>0) labS.Resize(indL);
    else {
      printf("Failed to extract label from %s\n",labS.Data());
      exit(1);
    }
    labDum[0] = labS.Atoi();
    if (bin) {
      for (int j=nGen;j--;) {
	ml->mille(0, locDum, 1, gloDum, labDum, kDummyRes, kDummyErr);
	ml->end();
      }
    }
    else {
      mpRec->DummyRecord(kDummyRes,kDummyErr,kDummyDer,labDum[0]);
      for (int j=nGen;j--;) algSteer->GetMPRecTree()->Fill();
    }
  }
  //
  if (bin) delete ml;
  else {
    algSteer->CloseMPRecOutput();
    delete algSteer;
  }
  //
  lst->SetOwner();
  delete lst;
  fl->Close();
  delete fl;
}