Ejemplo n.º 1
0
/* For 3DNow!, the operand byte goes at the end. Format is:
 *   0F 0F [ModRM] [SIB] [displacement] imm8_opcode
 * See AMD doc 24594, page 435.
 */
static void TestAll3DNow(const unsigned int prefix,
                         const size_t prefix_length,
                         const char* print_prefix) {
  const size_t kInstByteCount = NACL_ENUM_MAX_INSTRUCTION_BYTES;
  const size_t kIterByteCount = 3;
  InstByteArray itext;
  size_t i;
  int op, modrm, sib;

  if ((gPrefix > 0) && (gPrefix != prefix)) return;

  PrintProgress("TestAll3DNow(%s)\n", print_prefix);
  /* set up prefix */
  memcpy(itext, &prefix, prefix_length);
  /* set up filler bytes */
  for (i = prefix_length + kIterByteCount; i < kInstByteCount; i++) {
    itext[i] = (uint8_t)i;
  }

  for (op = 0; op < 256; op++) {
    if (!gEasyDiffMode) PrintProgress("%02x 00 00\n", op);
    /* Use opcode as fill byte, forcing iteration through 3DNow opcodes. */
    for (i = prefix_length + 2; i < kIterByteCount; i++) itext[i] = op;

    for (modrm = 0; modrm < 256; modrm++) {
      itext[prefix_length] = modrm;
      for (sib = 0; sib < 256; sib++) {
        itext[prefix_length + 1] = sib;
        TryOneInstruction(itext, kInstByteCount);
      }
    }
  }
}
Ejemplo n.º 2
0
void SpectralStatistics(std::vector<PointSet> &sets, int npoints, Statistics *stats) {
    // We need the full radial power spectrum, so for performance reasons, we
    // derive the radial power spectrum directly from full RDFs here
    const int nsets = (int) sets.size();
    const int nbins = 100 * sqrtf(npoints);
    Curve avgrp(nbins, 0, 0.5f * npoints);
    Curve rdf(nbins, 0, 0.5f);
    Curve rp(nbins, 0, 0.5f * npoints);
    
    if (nsets > 1) PrintProgress("Stats", 0);
    for (int i = 0; i < nsets; ++i) {
        rdf.SetZero();
        sets[i].RDF(&rdf);
        
        rp.SetZero();
        RDFtoRP(rdf, npoints, &rp);
        avgrp.Accumulate(rp);
        
        if (nsets > 1) PrintProgress("Stats", (i+1) / (float) nsets);
    }
    avgrp.Divide(sets.size());
    if (nsets > 1) std::cout << std::endl;
    
    stats->effnyquist = EffectiveNyquist(avgrp, npoints);
    stats->oscillations = OscillationsMetric(avgrp, npoints);
}
Ejemplo n.º 3
0
void ConsoleUpdater::OnProgressChange(const ProgressInfo& info)
{
	switch (info.type)
	{
	case ProgressInfo::FileDownload:
		// Download progress
		if (!_info.file.empty() && !info.file.empty() && info.file != _info.file)
		{
			// New file, finish the current download
			_info.progressFraction = 1.0f;
			PrintProgress();

			// Add a line break when a new file starts
			TraceLog::WriteLine(LOG_PROGRESS, "");

			TraceLog::WriteLine(LOG_PROGRESS, 
				(boost::format(" Downloading from Mirror %s: %s") % info.mirrorDisplayName % info.file.string()).str());
		}
		else if (_info.file.empty())
		{
			// First file
			TraceLog::WriteLine(LOG_PROGRESS, 
				(boost::format(" Downloading from Mirror %s: %s") % info.mirrorDisplayName % info.file.string()).str());
		}

		_info = info;

		// Print the new info
		PrintProgress();

		// Add a new line if we're done here
		if (info.progressFraction >= 1)
		{
			TraceLog::WriteLine(LOG_PROGRESS, "");
		}
		break;

	case ProgressInfo::FileOperation:

		_info = info;

		// Print the new info
		PrintProgress();

		// Add a new line if we're done here
		if (info.progressFraction >= 1)
		{
			TraceLog::WriteLine(LOG_PROGRESS, "");
		}
		break;
	};
}
Ejemplo n.º 4
0
void h10looper::Loop(Long64_t ntoproc /* = -1 */, Bool_t fastcount /* =kTRUE */, TEntryList *elist /* = 0 */)
{
    if (fChain == 0) return;
    if (ntoproc == -1) {
        if (fastcount) ntoproc = fChain->GetEntriesFast();
        else ntoproc = elist ? elist->GetN() : fChain->GetEntries();
    }
    std::cout << "ntoproc = " << ntoproc << std::endl;
    _ntoprocess = ntoproc;
    //Long64_t nbytes = 0, nb = 0;
    _swmain.Start();
    _swgroup.Start();
    for (Long64_t jentry_el=0; jentry_el<ntoproc; jentry_el++) {
        jentry = elist ? elist->GetEntry(jentry_el) : jentry_el;
        Long64_t ientry = LoadTree(jentry);
        if (ientry < 0) break;
        PrintProgress(jentry);
        //data->CheapPop(ientry);
        GetEntry(jentry);
        fHandlerChain->Process(data);
    }
    fHandlerChain->Finalize(data);
    Float_t ttime = _swmain.RealTime();
    Float_t percentProcessed = (Float_t)eventnum/_ntoprocess*100;
    printf("Total: (%.2f) %lld/%.2f = %i events/sec\n",percentProcessed,eventnum,ttime,(Int_t)(eventnum/ttime));
}
Ejemplo n.º 5
0
Result DownloadFile_Internal(const char *url, void *out, bool bProgress,
							 void (*write)(void* out, unsigned char* buffer, u32 readSize))
{
    httpcContext context;
    u32 fileSize = 0;
    u32 procSize = 0;
    Result ret = 0;
    Result dlret = HTTPC_RESULTCODE_DOWNLOADPENDING;
    u32 status;
    u32 bufSize = 0x100000;
    u32 readSize = 0;
    httpcOpenContext(&context, HTTPC_METHOD_GET, (char*)url, 1);

    ret = httpcBeginRequest(&context);
    if (ret != 0) goto _out;

    ret = httpcGetResponseStatusCode(&context, &status, 0);
    if (ret != 0) goto _out;

    if (status != 200)
    {
        ret = status;
        goto _out;
    }

    ret = httpcGetDownloadSizeState(&context, NULL, &fileSize);
    if (ret != 0) goto _out;

    {
        unsigned char *buffer = (unsigned char *)linearAlloc(bufSize);
        if (buffer == NULL)
        {
            printf("Error allocating download buffer\n");
            ret = -1;
            goto _out;
        }

        while (dlret == (s32)HTTPC_RESULTCODE_DOWNLOADPENDING)
        {
            memset(buffer, 0, bufSize);

            dlret = httpcDownloadData(&context, buffer, bufSize, &readSize);
            write(out, buffer, readSize);

            procSize += readSize;
            if (bProgress)
            {
            	PrintProgress(fileSize, procSize);
            }
        }
        linearFree(buffer);
    }
_out:
    httpcCloseContext(&context);

    return ret;
}
Ejemplo n.º 6
0
/* Enumerate and test all 24-bit opcode+modrm+sib patterns for a
 * particular prefix.
 */
static void TestAllWithPrefix(const unsigned int prefix,
                              const size_t prefix_length,
                              const char* print_prefix) {
  const size_t kInstByteCount = NACL_ENUM_MAX_INSTRUCTION_BYTES;
  const size_t kIterByteCount = 3;
  InstByteArray itext;
  size_t i;
  int op, modrm, sib;
  int min_op;
  int max_op;

  if ((gPrefix > 0) && (gPrefix != prefix)) return;

  PrintProgress("TestAllWithPrefix(%s)\n", print_prefix);
  /* set up prefix */
  memcpy(itext, &prefix, prefix_length);
  /* set up filler bytes */
  for (i = prefix_length + kIterByteCount; i < kInstByteCount; i++) {
    itext[i] = (uint8_t)i;
  }
  if (gOpcode < 0) {
    min_op = 0;
    max_op = 256;
  } else {
    min_op = gOpcode;
    max_op = gOpcode + 1;
  }
  for (op = min_op; op < max_op; op++) {
    itext[prefix_length] = op;
    if (!gEasyDiffMode) PrintProgress("%02x 00 00\n", op);
    for (modrm = 0; modrm < 256; modrm++) {
      itext[prefix_length + 1] = modrm;
      for (sib = 0; sib < 256; sib++) {
        itext[prefix_length + 2] = sib;
        TryOneInstruction(itext, kInstByteCount);
      }
    }
  }
}
Ejemplo n.º 7
0
int main(int argc, char **argv){
	S_LOG("main");
        logxx::GlobalLogLevel(logxx::warning);
        EncodingConverter converter;
        if (argc < 2){
                log(logxx::error) << "A path with dicom files should be specified" << logxx::endl;
                return 1;
        } else {
                std::string path(argv[1]);                
                if (path[path.length()-1] != '/')
                        path += '/';
                
                std::string csvFile = path + "out.csv";
                std::ofstream out(csvFile);
                if (out.good()){
                        Dir dir(path, true, ".dcm");
                        if (dir.Ok()) {
                                std::string fName;
                                while ((fName = dir.Read()).empty() == false) {
                                        log(logxx::debug) << "{" << fName << "}" << logxx::endl;
                                        Dicom dicom(path + fName);
                                        if (dicom.Parse(converter)){
                                                // cppcheck-suppress constStatement
                                                log(logxx::notice) << "{" << fName << "} Parsed" << logxx::endl;
                                                out << fName << "," << dicom << std::endl;

                                        } else {
                                                // cppcheck-suppress constStatement
                                                log(logxx::notice) << "{" << fName << "} Not parsed" << logxx::endl;
                                        }
                                        PrintProgress();
                                }
                                return 0;
                        } else {
                                log(logxx::error) << "Can't open path {" << path << "}" << logxx::endl;
                                return 1;
                        }
                } else {
                        log(logxx::error) << "Can't open file {" << csvFile <<  "} for writing"  << logxx::endl;
                        return 1;
                }
        }
}
Ejemplo n.º 8
0
void CClassifyGrid::Classify()
{
	CParamManager * manager = CParamManager::GetParamManager();
	CTimeMeter timer;
	timer.Start();

	fprintf_s( stderr, "==================== Classify points ====================\n" );

	Init();

	fprintf_s( stderr, "Initialize ... finished.\n" );

	fprintf_s( stderr, "Processing progress ... " );
	InitPrintProgress();

	int index;
	while ( ( index = ReadNextChunk() ) != -1 ) {

		PrintProgress(  );

		CClassifyChunk * chunk = m_vecPointer[ index ];
		chunk->BuildGridIndex();

		// check neighborhood of index chunk
		m_vecState[ chunk->m_iIndex ] = CClassifyChunk::CCS_Read;
		NotifyCCSRead( chunk->m_iX, chunk->m_iY );

		if ( manager->m_bDebugPrintOut ) {
			PrintGridState( manager->m_pDebugPrintOutFile );
		}

	}

	fprintf_s( stderr, " ... done!\n" );

	Fin();

	timer.End();
	timer.Print();

	fprintf_s( stderr, ".\n" );
}
static void PR_CALLBACK Thread(void *null)
{
    void *pd;
    PRStatus rv;
    PRUintn keys;
    char *key_string[] = {
        "Key #0", "Key #1", "Key #2", "Key #3",
        "Bogus #5", "Bogus #6", "Bogus #7", "Bogus #8"};
    
    did = should = PR_FALSE;
    for (keys = 0; keys < 8; ++keys)
    {
        pd = PR_GetThreadPrivate(key[keys]);
        MY_ASSERT(NULL == pd);
    }
    PrintProgress(__LINE__);

    did = should = PR_FALSE;
    for (keys = 0; keys < 4; ++keys)
    {
        rv = PR_SetThreadPrivate(key[keys], key_string[keys]);
        MY_ASSERT(PR_SUCCESS == rv);
    }
    PrintProgress(__LINE__);

    did = should = PR_FALSE;
    for (keys = 4; keys < 8; ++keys)
    {
        rv = PR_SetThreadPrivate(key[keys], key_string[keys]);
        MY_ASSERT(PR_FAILURE == rv);
    }
    PrintProgress(__LINE__);
    
    did = PR_FALSE; should = PR_TRUE;
    for (keys = 0; keys < 4; ++keys)
    {
        rv = PR_SetThreadPrivate(key[keys], key_string[keys]);
        MY_ASSERT(PR_SUCCESS == rv);
    }
    PrintProgress(__LINE__);

    did = PR_FALSE; should = PR_TRUE;
    for (keys = 0; keys < 4; ++keys)
    {
        rv = PR_SetThreadPrivate(key[keys], NULL);
        MY_ASSERT(PR_SUCCESS == rv);
    }
    PrintProgress(__LINE__);

    did = should = PR_FALSE;
    for (keys = 0; keys < 4; ++keys)
    {
        rv = PR_SetThreadPrivate(key[keys], NULL);
        MY_ASSERT(PR_SUCCESS == rv);
    }
    PrintProgress(__LINE__);

    did = should = PR_FALSE;
    for (keys = 8; keys < 127; ++keys)
    {
        rv = PR_SetThreadPrivate(key[keys], "EXTENSION");
        MY_ASSERT(PR_SUCCESS == rv);
    }
    PrintProgress(__LINE__);

    did = PR_FALSE; should = PR_TRUE;
    for (keys = 8; keys < 127; ++keys)
    {
        rv = PR_SetThreadPrivate(key[keys], NULL);
        MY_ASSERT(PR_SUCCESS == rv);
    }
    PrintProgress(__LINE__);

    did = should = PR_FALSE;
    for (keys = 8; keys < 127; ++keys)
    {
        rv = PR_SetThreadPrivate(key[keys], NULL);
        MY_ASSERT(PR_SUCCESS == rv);
    }

    /* put in keys and leave them there for thread exit */
    did = should = PR_FALSE;
    for (keys = 0; keys < 4; ++keys)
    {
        rv = PR_SetThreadPrivate(key[keys], key_string[keys]);
        MY_ASSERT(PR_SUCCESS == rv);
    }
    PrintProgress(__LINE__);
    did = PR_FALSE; should = PR_TRUE;

}  /* Thread */
Ejemplo n.º 10
0
//------------------------------------------------------------------------------
// Loop
//------------------------------------------------------------------------------
void AnalysisMonoH::Loop(TString analysis, TString filename, float luminosity)
{
  if (fChain == 0) return;

  Setup(analysis, filename, luminosity);


  // Define histograms
  //----------------------------------------------------------------------------
  for (int j=0; j<ncut; j++) {

    for (int k=0; k<=njetbin; k++) {

      TString sbin = (k < njetbin) ? Form("/%djet", k) : "";

      TString directory = scut[j] + sbin;

      root_output->cd();

      if (k < njetbin) gDirectory->mkdir(directory);

      root_output->cd(directory);

      for (int i=ee; i<=ll; i++) {

	TString suffix = "_" + schannel[i];

	DefineHistograms(i, j, k, suffix);

	h_fullpmet         [i][j][k] = new TH1D("h_fullpmet"        + suffix, "", 1000, 0.,  1000);
	h_trkpmet          [i][j][k] = new TH1D("h_trkpmet"         + suffix, "", 1000, 0.,  1000);
        h_deltarl1met      [i][j][k] = new TH1D("h_deltarl1met"     + suffix, "",  100, 0.,     5);
        h_deltarl2met      [i][j][k] = new TH1D("h_deltarl2met"     + suffix, "",  100, 0.,     5);
        h_deltarllmet      [i][j][k] = new TH1D("h_deltarllmet"     + suffix, "",  100, 0.,     5);
	h_deltarjet1met    [i][j][k] = new TH1D("h_deltarjet1met"   + suffix, "",  100, 0.,     5);
	h_deltarjet2met    [i][j][k] = new TH1D("h_deltarjet2met"   + suffix, "",  100, 0.,     5);
	h_deltarjj         [i][j][k] = new TH1D("h_deltarjj"        + suffix, "",  100, 0.,     5);
	h_deltarjjmet      [i][j][k] = new TH1D("h_deltarjjmet"     + suffix, "",  100, 0.,     5);
	h_deltarlep1jet1   [i][j][k] = new TH1D("h_deltarlep1jet1"  + suffix, "",  100, 0.,     5);
	h_deltarlep1jet2   [i][j][k] = new TH1D("h_deltarlep1jet2"  + suffix, "",  100, 0.,     5);
	h_deltarlep2jet1   [i][j][k] = new TH1D("h_deltarlep2jet1"  + suffix, "",  100, 0.,     5);
	h_deltarlep2jet2   [i][j][k] = new TH1D("h_deltarlep2jet2"  + suffix, "",  100, 0.,     5);
       	h_mllstar          [i][j][k] = new TH1D("h_mllstar"         + suffix, "", 3000, 0.,  3000);
       	//h_mnunu            [i][j][k] = new TH1D("h_mnunu"           + suffix, "",   10, 0.,    10);
	h_mr             [i][j][k] = new TH1D("h_mr"              + suffix, "", 2000, 0.,  2000);

	//h_met_m2l         [i][j][k] = new TH2D("h_met_m2l"        + suffix, "", 200,  0,  2000,  100,   0, 200);
	//h_met_deltaphill  [i][j][k] = new TH2D("h_met_deltaphill" + suffix, "", 200,  0,  2000,  100,   0,   5);     
      }
    }
  }

  root_output->cd();
  

  // Loop over events
  //----------------------------------------------------------------------------
  for (Long64_t jentry=0; jentry<_nentries;jentry++) {

    Long64_t ientry = LoadTree(jentry);

    if (ientry < 0) break;

    fChain->GetEntry(jentry);

    PrintProgress(jentry, _nentries);

    EventSetup();


    // Analysis
    //--------------------------------------------------------------------------
    //if (Lepton1.flavour * Lepton2.flavour > 0) continue;
    //if (Lepton1.v.Pt() < 20.) continue;
    //if (Lepton2.v.Pt() < 20.) continue;

    // Let's trust our ntuples
    //--------------------------------------------------------------------------
    if (std_vector_lepton_flavour->at(0)*std_vector_lepton_flavour->at(1) > 0) continue;
    if (std_vector_lepton_pt->at(0) < 20.) continue; 
    if (std_vector_lepton_pt->at(1) < 20.) continue; 
    if (std_vector_lepton_pt->at(2) > 10.) continue; 

    _nelectron = 0;

    if (abs(Lepton1.flavour) == ELECTRON_FLAVOUR) _nelectron++;
    if (abs(Lepton2.flavour) == ELECTRON_FLAVOUR) _nelectron++;

    if      (_nelectron == 2) _channel = ee;
    else if (_nelectron == 1) _channel = em;
    else if (_nelectron == 0) _channel = mm;
    
    _m2l  = mll;
    _pt2l = ptll;


    // Fill histograms
    //--------------------------------------------------------------------------
    bool pass = true;

    // WW cuts   
    FillLevelHistograms(MonoH_00_Has2Leptons, pass);

    pass &= (mll > 12.);
    FillLevelHistograms(MonoH_01_Mll, pass);
    
    pass &= (MET.Et() > 20.);
    FillLevelHistograms(MonoH_02_PfMet, pass);

    bool pass_zveto = (_nelectron == 1 || fabs(mll - Z_MASS) > 15.);
    FillLevelHistograms(MonoH_03_ZVeto, pass && pass_zveto);

    pass &= (mpmet > 45. || (_nelectron == 1 && mpmet > 45.));
    FillLevelHistograms(MonoH_04_MpMet, pass && pass_zveto);

    pass &= (_passdphiveto);
    FillLevelHistograms(MonoH_05_DPhiVeto, pass && pass_zveto);

    pass &= (_nelectron == 1 && ptll > 30. || _nelectron != 1 && ptll > 45.);
    FillLevelHistograms(MonoH_06_Ptll, pass && pass_zveto);

    bool passTopCR = pass && _nbjet20cmvav2l == 1;

    pass &= (_nbjet20cmvav2l == 0);
    FillLevelHistograms(MonoH_07_BVeto, pass && pass_zveto);

    if (_saveminitree && pass && pass_zveto) minitree->Fill();

    //ZH->4l Control Region
    if (AnalysisLeptons[2].v.Pt() > 0 || AnalysisLeptons[3].v.Pt() > 0 ){
      //cout<<"I passed! :)"<<endl;
      
      bool passZHCR = ( (fabs(_mll13 - Z_MASS) < 15. || fabs(_mll23 - Z_MASS) < 15. || fabs(_mll14 - Z_MASS) < 15. || fabs(_mll24 - Z_MASS) < 15. || fabs(_mll34 - Z_MASS) < 15.) && AnalysisLeptons[2].v.Pt() > 20. && AnalysisLeptons[3].v.Pt() > 20.);
      
      FillLevelHistograms(MonoH_08_ZHCR, passZHCR);
      // cout<<"Lepton 3 pT = "<<std_vector_lepton_pt->at(2)<<endl;
      // cout<<"Lepton 4 pT = "<<std_vector_lepton_pt->at(3)<<endl;
      // cout<<"-------------------------------------------"<<endl;
    }

    FillLevelHistograms(MonoH_09_TopCR, passTopCR && pass_zveto);

    //    pass &= (!_foundsoftmuon);
    //    FillLevelHistograms(MonoH_08_SoftMu, pass && pass_zveto);

    // monoH cuts                                                         
    // bool pass_monoh = (pass && pass_zveto);
    // bool pass_drll = (Lepton1.v.DeltaR(Lepton2.v) < 1.5);

    // FillLevelHistograms(MonoH_103_CR, pass_monoh && !pass_drll);

    // pass_monoh &= (_mc < 100.);
    // FillLevelHistograms(MonoH_100_Mc, pass_monoh);
   
    // pass_monoh &= pass_drll;                                                                       
    // FillLevelHistograms(MonoH_101_DRll, pass_monoh); 
  
    // pass_monoh &= (mpmet > 60.);
    // FillLevelHistograms(MonoH_102_MpMet, pass_monoh);

    // pass_monoh &= (mpmet > 100.);
    // FillLevelHistograms(MonoH_09_mpmet100, pass_monoh);

    // pass_monoh &= (mth > 200.);
    // FillLevelHistograms(MonoH_10_mth200, pass_monoh);

    // pass_monoh &= (Lepton1.v.DeltaPhi(MET) > 2.6);
    // FillLevelHistograms(MonoH_11_dphil1met, pass_monoh);

    // pass_monoh &= (Lepton2.v.DeltaPhi(MET) > 2.6);
    // FillLevelHistograms(MonoH_12_dphil2met, pass_monoh);

    // pass_monoh &= (drll < 0.8);
    // FillLevelHistograms(MonoH_13_deltarll, pass_monoh);

    // pass_monoh &= (mtw1 > 160.);
    // FillLevelHistograms(MonoH_14_mtw1, pass_monoh);

    // pass_monoh &= (mtw2 > 100.);
    // FillLevelHistograms(MonoH_15_mtw2, pass_monoh);

    // pass_monoh &= (metTtrk > 100.);
    // FillLevelHistograms(MonoH_16_trkmet, pass_monoh);

  }

  EndJob();
}
Ejemplo n.º 11
0
std::string ProgressBar::Update(double progress) {
  progress_ = progress;
  double elapsed = timer_.Toc();
  return PrintProgress(elapsed);
}
Ejemplo n.º 12
0
//------------------------------------------------------------------------------
// Loop
//------------------------------------------------------------------------------
void AnalysisControl::Loop(TString analysis, TString filename, float luminosity)
{
  if (fChain == 0) return;

  Setup(analysis, filename, luminosity);


  // Define histograms
  //----------------------------------------------------------------------------
  root_output->cd();

  for (int j=0; j<ncut; j++) {

    for (int k=0; k<=njetbin; k++) {

      TString sbin = (k < njetbin) ? Form("/%djet", k) : "";

      TString directory = scut[j] + sbin;

      root_output->cd();

      if (k < njetbin) gDirectory->mkdir(directory);

      root_output->cd(directory);

      for (int i=ee; i<=ll; i++) {

	TString suffix = "_" + schannel[i];

	DefineHistograms(i, j, k, suffix);
      }
    }
  }

  root_output->cd();


  // Loop over events
  //----------------------------------------------------------------------------
  for (Long64_t jentry=0; jentry<_nentries;jentry++) {

    Long64_t ientry = LoadTree(jentry);

    if (ientry < 0) break;

    fChain->GetEntry(jentry);

    PrintProgress(jentry, _nentries);

    EventSetup();


    // Analysis
    //--------------------------------------------------------------------------
    _nelectron = 0;

    if (abs(Lepton1.flavour) == ELECTRON_FLAVOUR) _nelectron++;
    if (abs(Lepton2.flavour) == ELECTRON_FLAVOUR) _nelectron++;

    if      (_nelectron == 2) _channel = ee;
    else if (_nelectron == 1) _channel = em;
    else if (_nelectron == 0) _channel = mm;
    
    _m2l  = mll;   // Needs l2Sel
    _pt2l = ptll;  // Needs l2Sel

    bool pass_2l = (Lepton1.flavour * Lepton2.flavour < 0);

    pass_2l &= (Lepton1.v.Pt() > 25.);
    pass_2l &= (Lepton2.v.Pt() > 20.);
    pass_2l &= (std_vector_lepton_pt->at(2) < 10.);
    pass_2l &= (_m2l > 20.);


    bool pass;


    // No cuts
    //--------------------------------------------------------------------------
    pass = true;

    FillLevelHistograms(Control_00_NoCuts, pass);


    // Has 2 tight leptons
    //--------------------------------------------------------------------------
    pass = pass_2l;

    FillLevelHistograms(Control_01_TwoLeptons, pass);

    if (_saveminitree && pass) minitree->Fill();


    // R out/in
    //--------------------------------------------------------------------------
    pass = pass_2l;

    pass &= (_nbjet30csvv2m > 0);

    FillLevelHistograms(Control_02_Routin, pass);


    // WW
    // https://github.com/latinos/PlotsConfigurations/blob/master/Configurations/ControlRegions/WW/Full2016/cuts.py
    //--------------------------------------------------------------------------
    pass =
      mll > 80                         &&
      std_vector_lepton_pt->at(0) > 25 &&
      std_vector_lepton_pt->at(1) > 13 &&
      std_vector_lepton_pt->at(2) < 10 &&
      metPfType1 > 20                  &&
      ptll > 30                        &&
      mth >= 60	                       &&
      (std_vector_jet_pt->at(0) < 20 || std_vector_jet_cmvav2->at(0) < -0.5884) &&
      (std_vector_jet_pt->at(1) < 20 || std_vector_jet_cmvav2->at(1) < -0.5884) &&
      (std_vector_jet_pt->at(2) < 20 || std_vector_jet_cmvav2->at(2) < -0.5884) &&
      (std_vector_jet_pt->at(3) < 20 || std_vector_jet_cmvav2->at(3) < -0.5884) &&
      (std_vector_jet_pt->at(4) < 20 || std_vector_jet_cmvav2->at(4) < -0.5884) &&
      (std_vector_jet_pt->at(5) < 20 || std_vector_jet_cmvav2->at(5) < -0.5884) &&
      (std_vector_jet_pt->at(6) < 20 || std_vector_jet_cmvav2->at(6) < -0.5884) &&
      (std_vector_jet_pt->at(7) < 20 || std_vector_jet_cmvav2->at(7) < -0.5884) &&
      (std_vector_jet_pt->at(8) < 20 || std_vector_jet_cmvav2->at(8) < -0.5884) &&
      (std_vector_jet_pt->at(9) < 20 || std_vector_jet_cmvav2->at(9) < -0.5884);

    FillLevelHistograms(Control_03_WW, pass);

    if (pass) EventDump();


    // Top
    //--------------------------------------------------------------------------
    pass = pass_2l;

    pass &= (_njet > 1);
    pass &= (_nbjet30csvv2m > 0);
    pass &= (_channel == em || fabs(_m2l - Z_MASS) > 15.);
    pass &= (MET.Et() > 45.);

    FillLevelHistograms(Control_04_Top, pass);
  }


  EndJob();
}
Ejemplo n.º 13
0
//------------------------------------------------------------------------------
// Loop
//------------------------------------------------------------------------------
void AnalysisFR::Loop(TString analysis, TString filename, float luminosity)
{
  if (fChain == 0) return;

  Setup(analysis, filename, luminosity);

  // Define fake rate histograms
  //----------------------------------------------------------------------------
  for (int i=0; i<ncut; i++) {
    
    TString directory = scut[i];
    
    root_output->cd();
    
    gDirectory->mkdir(directory);
    
    root_output->cd(directory);
    
    for (int j=0; j<njetet; j++) {
      
      TString muonsuffix = Form("_%.0fGeV", muonjetet[j]);
      TString elesuffix  = Form("_%.0fGeV", elejetet[j]);
      
      h_Muon_loose_pt_eta_bin[i][j] = new TH2D("h_Muon_loose_pt_eta_bin" + muonsuffix, "", nptbin, ptbins, netabin, etabins);
      h_Muon_tight_pt_eta_bin[i][j] = new TH2D("h_Muon_tight_pt_eta_bin" + muonsuffix, "", nptbin, ptbins, netabin, etabins);
      h_Ele_loose_pt_eta_bin [i][j] = new TH2D("h_Ele_loose_pt_eta_bin"  + elesuffix,  "", nptbin, ptbins, netabin, etabins);
      h_Ele_tight_pt_eta_bin [i][j] = new TH2D("h_Ele_tight_pt_eta_bin"  + elesuffix,  "", nptbin, ptbins, netabin, etabins);
      
      h_Muon_loose_pt_bin[i][j] = new TH1D("h_Muon_loose_pt_bin" + muonsuffix, "", nptbin, ptbins);
      h_Muon_tight_pt_bin[i][j] = new TH1D("h_Muon_tight_pt_bin" + muonsuffix, "", nptbin, ptbins);
      h_Ele_loose_pt_bin [i][j] = new TH1D("h_Ele_loose_pt_bin"  + elesuffix,  "", nptbin, ptbins);
      h_Ele_tight_pt_bin [i][j] = new TH1D("h_Ele_tight_pt_bin"  + elesuffix,  "", nptbin, ptbins);
      
      h_Muon_loose_eta_bin[i][j] = new TH1D("h_Muon_loose_eta_bin" + muonsuffix, "", netabin, etabins);
      h_Muon_tight_eta_bin[i][j] = new TH1D("h_Muon_tight_eta_bin" + muonsuffix, "", netabin, etabins);
      h_Ele_loose_eta_bin [i][j] = new TH1D("h_Ele_loose_eta_bin"  + elesuffix,  "", netabin, etabins);
      h_Ele_tight_eta_bin [i][j] = new TH1D("h_Ele_tight_eta_bin"  + elesuffix,  "", netabin, etabins);
	
      h_Muon_loose_pt[i][j] = new TH1D("h_Muon_loose_pt" + muonsuffix, "", 1000, 0, 200);
      h_Muon_tight_pt[i][j] = new TH1D("h_Muon_tight_pt" + muonsuffix, "", 1000, 0, 200);
      h_Ele_loose_pt [i][j] = new TH1D("h_Ele_loose_pt"  + elesuffix,  "", 1000, 0, 200);
      h_Ele_tight_pt [i][j] = new TH1D("h_Ele_tight_pt"  + elesuffix,  "", 1000, 0, 200);
      
      h_Muon_loose_mtw[i][j] = new TH1D("h_Muon_loose_mtw" + muonsuffix, "", 1000, 0, 200);
      h_Muon_tight_mtw[i][j] = new TH1D("h_Muon_tight_mtw" + muonsuffix, "", 1000, 0, 200);
      h_Ele_loose_mtw [i][j] = new TH1D("h_Ele_loose_mtw"  + elesuffix,  "", 1000, 0, 200);
      h_Ele_tight_mtw [i][j] = new TH1D("h_Ele_tight_mtw"  + elesuffix,  "", 1000, 0, 200);
	
      h_Muon_loose_m2l[i][j] = new TH1D("h_Muon_loose_m2l" + muonsuffix, "", 1000, 0, 200);
      h_Muon_tight_m2l[i][j] = new TH1D("h_Muon_tight_m2l" + muonsuffix, "", 1000, 0, 200);
      h_Ele_loose_m2l [i][j] = new TH1D("h_Ele_loose_m2l"  + elesuffix,  "", 1000, 0, 200);
      h_Ele_tight_m2l [i][j] = new TH1D("h_Ele_tight_m2l"  + elesuffix,  "", 1000, 0, 200);
      
      
      // Define effective luminosity estimation histograms
      //------------------------------------------------------------------------
      h_Muon_loose_pt_m2l[i][j] = new TH2D("h_Muon_loose_pt_m2l" + muonsuffix, "", 200, 0, 200, nptbin, ptbins);
      h_Muon_tight_pt_m2l[i][j] = new TH2D("h_Muon_tight_pt_m2l" + muonsuffix, "", 200, 0, 200, nptbin, ptbins);
      h_Ele_loose_pt_m2l [i][j] = new TH2D("h_Ele_loose_pt_m2l"  + elesuffix,  "", 200, 0, 200, nptbin, ptbins);
      h_Ele_tight_pt_m2l [i][j] = new TH2D("h_Ele_tight_pt_m2l"  + elesuffix,  "", 200, 0, 200, nptbin, ptbins);
    }
  }
  
  root_output->cd();
  
  // Loop over events
  //----------------------------------------------------------------------------
  for (Long64_t jentry=0; jentry<_nentries;jentry++) {
    
    Long64_t ientry = LoadTree(jentry);
    
    if (ientry < 0) break;
    
    fChain->GetEntry(jentry);
    
    PrintProgress(jentry, _nentries);
    
    EventSetup();
    
    _channel = (abs(Lepton1.flavour) == ELECTRON_FLAVOUR) ? e : m;
    
    _leptonPtMin  = (_channel == e) ?  13 :  10;
    _leptonEtaMax = (_channel == e) ? 2.5 : 2.4;

    if (Lepton1.v.Pt()        < _leptonPtMin)  continue;
    if (fabs(Lepton1.v.Eta()) > _leptonEtaMax) continue;


    // Get the event weight
    //--------------------------------------------------------------------------
    bool passTrigger;

    if (_ismc) {

      passTrigger = true;

      Float_t corrected_baseW = baseW; 

      if (_sample.Contains("DYJetsToLL_M-10to50")) corrected_baseW = 0.829752445221; 
      if (_sample.Contains("DYJetsToLL_M-50"))     corrected_baseW = 0.318902641535;

      _base_weight = (corrected_baseW / 1e3) * puW6p3 * GEN_weight_SM / abs(GEN_weight_SM);

      _event_weight = _base_weight;


      // Muons
      //------------------------------------------------------------------------
      if (_channel == m)
	{
	  (Lepton1.v.Pt() <= 20.) ? _event_weight *= 5.86 : _event_weight *= 163.84;
	}

      
      // Electrons
      //------------------------------------------------------------------------
      if (_channel == e)
	{
	  (Lepton1.v.Pt() <= 25.) ? _event_weight *= 8.51 : _event_weight *= 42.34;
	}

    } else {

      _event_weight = 1.0;

      passTrigger = false;


      // Muons
      //------------------------------------------------------------------------
      if (_sample.Contains("DoubleMuon") && _channel == m) {

	if (Lepton1.v.Pt() <= 20. && std_vector_trigger->at(22)) {  // HLT_Mu8_TrkIsoVVL_v*

	  passTrigger = true;

	} else if (Lepton1.v.Pt() > 20. && std_vector_trigger->at(23)) {  // HLT_Mu17_TrkIsoVVL_v*

	  passTrigger = true;
	}
      }


      // Electrons
      //------------------------------------------------------------------------
      if (_sample.Contains("DoubleEG") && _channel == e) {
	
	if (Lepton1.v.Pt() <= 25. && std_vector_trigger->at(31)) {  // HLT_Ele12_CaloIdL_TrackIdL_IsoVL_PFJet30_v*

	  passTrigger = true;
	  
	} else if (Lepton1.v.Pt() > 25. && std_vector_trigger->at(33)) {  // HLT_Ele23_CaloIdL_TrackIdL_IsoVL_PFJet30_v*

	  passTrigger = true;
	}
      }
    }


    // Get the jets and the W transverse mass
    //--------------------------------------------------------------------------
    GetAwayJets();
    GetMt(Lepton1, _mtw);


    // Preselection
    //--------------------------------------------------------------------------
    if (!passTrigger) continue;

    if (AnalysisJets.size() < 1) continue;


    // Get histograms for different jet pt thresholds
    //--------------------------------------------------------------------------
    for (int i=0; i<njetet; i++) {

      _inputJetEt = (_channel == e) ? elejetet[i] : muonjetet[i];

      if (AnalysisJets[0].v.Pt() < _inputJetEt) continue; 


      // QCD region
      //------------------------------------------------------------------------
      bool pass;
      pass = (_nlepton == 1);

      FillLevelHistograms(FR_00_QCD, i, pass);

    }
  }
  

  EndJob();
}
static PRIntn PR_CALLBACK Tpd(PRIntn argc, char **argv)
{
    void *pd;
    PRStatus rv;
    PRUintn keys;
    PRThread *thread;
    char *key_string[] = {
        "Key #0", "Key #1", "Key #2", "Key #3",
        "Bogus #5", "Bogus #6", "Bogus #7", "Bogus #8"};
    
    fout = PR_STDOUT;

    did = should = PR_FALSE;
    for (keys = 0; keys < 4; ++keys)
    {
        rv = PR_NewThreadPrivateIndex(&key[keys], Destructor);
        MY_ASSERT(PR_SUCCESS == rv);
    }
    PrintProgress(__LINE__);

    did = should = PR_FALSE;
    for (keys = 0; keys < 8; ++keys)
    {
        pd = PR_GetThreadPrivate(key[keys]);
        MY_ASSERT(NULL == pd);
    }
    PrintProgress(__LINE__);

    did = should = PR_FALSE;
    for (keys = 0; keys < 4; ++keys)
    {
        rv = PR_SetThreadPrivate(key[keys], key_string[keys]);
        MY_ASSERT(PR_SUCCESS == rv);
    }
    PrintProgress(__LINE__);

    for (keys = 4; keys < 8; ++keys)
		key[keys] = 4096;		/* set to invalid value */
    did = should = PR_FALSE;
    for (keys = 4; keys < 8; ++keys)
    {
        rv = PR_SetThreadPrivate(key[keys], key_string[keys]);
        MY_ASSERT(PR_FAILURE == rv);
    }
    PrintProgress(__LINE__);
    
    did = PR_FALSE; should = PR_TRUE;
    for (keys = 0; keys < 4; ++keys)
    {
        rv = PR_SetThreadPrivate(key[keys], key_string[keys]);
        MY_ASSERT(PR_SUCCESS == rv);
    }
    PrintProgress(__LINE__);

    did = PR_FALSE; should = PR_TRUE;
    for (keys = 0; keys < 4; ++keys)
    {
        rv = PR_SetThreadPrivate(key[keys], NULL);
        MY_ASSERT(PR_SUCCESS == rv);
    }
    PrintProgress(__LINE__);

    did = should = PR_FALSE;
    for (keys = 0; keys < 4; ++keys)
    {
        rv = PR_SetThreadPrivate(key[keys], NULL);
        MY_ASSERT(PR_SUCCESS == rv);
    }
    PrintProgress(__LINE__);

    did = should = PR_FALSE;
    for (keys = 8; keys < 127; ++keys)
    {
        rv = PR_NewThreadPrivateIndex(&key[keys], Destructor);
        MY_ASSERT(PR_SUCCESS == rv);
        rv = PR_SetThreadPrivate(key[keys], "EXTENSION");
        MY_ASSERT(PR_SUCCESS == rv);
    }
    PrintProgress(__LINE__);

    did = PR_FALSE; should = PR_TRUE;
    for (keys = 8; keys < 127; ++keys)
    {
        rv = PR_SetThreadPrivate(key[keys], NULL);
        MY_ASSERT(PR_SUCCESS == rv);
    }
    PrintProgress(__LINE__);

    did = should = PR_FALSE;
    for (keys = 8; keys < 127; ++keys)
    {
        rv = PR_SetThreadPrivate(key[keys], NULL);
        MY_ASSERT(PR_SUCCESS == rv);
    }

    thread = PR_CreateThread(
        PR_USER_THREAD, Thread, NULL, PR_PRIORITY_NORMAL,
        PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);

    (void)PR_JoinThread(thread);

    PrintProgress(__LINE__);

#if defined(WIN16)
    printf(
        "%s\n",((PR_TRUE == failed) ? "FAILED" : "PASSED"));
#else
    (void)PR_fprintf(
        fout, "%s\n",((PR_TRUE == failed) ? "FAILED" : "PASSED"));
#endif    

    return 0;

}  /* Tpd */
Ejemplo n.º 15
0
void MyThread::RootFunction()
{
    PRStatus rv;
    PRUintn keys;
    const RCThreadPrivateData *pd;
    
    MyPrivateData extension = MyPrivateData("EXTENSION");
    MyPrivateData key_string[] = {
        "Key #0", "Key #1", "Key #2", "Key #3",
        "Bogus #5", "Bogus #6", "Bogus #7", "Bogus #8"};
    
    did = should = PR_FALSE;
    for (keys = 0; keys < 8; ++keys)
    {
        pd = GetPrivateData(key[keys]);
        MY_ASSERT(NULL == pd);
    }
    PrintProgress(__LINE__);

    did = should = PR_FALSE;
    for (keys = 0; keys < 4; ++keys)
    {
        rv = SetPrivateData(keys, &key_string[keys]);
        MY_ASSERT(PR_SUCCESS == rv);
    }
    PrintProgress(__LINE__);

#if !defined(DEBUG)
    did = should = PR_FALSE;
    for (keys = 4; keys < 8; ++keys)
    {
        rv = SetPrivateData(keys, &key_string[keys]);
        MY_ASSERT(PR_FAILURE == rv);
    }
    PrintProgress(__LINE__);
#endif
    
    did = PR_FALSE; should = PR_TRUE;
    for (keys = 0; keys < 4; ++keys)
    {
        rv = SetPrivateData(key[keys], &key_string[keys]);
        MY_ASSERT(PR_SUCCESS == rv);
    }
    PrintProgress(__LINE__);

    did = PR_FALSE; should = PR_TRUE;
    for (keys = 0; keys < 4; ++keys)
    {
        rv = SetPrivateData(key[keys]);
        MY_ASSERT(PR_SUCCESS == rv);
    }
    PrintProgress(__LINE__);

    did = should = PR_FALSE;
    for (keys = 0; keys < 4; ++keys)
    {
        rv = SetPrivateData(key[keys]);
        MY_ASSERT(PR_SUCCESS == rv);
    }
    PrintProgress(__LINE__);

    did = should = PR_FALSE;
    for (keys = 8; keys < 127; ++keys)
    {
        rv = SetPrivateData(key[keys], &extension);
        MY_ASSERT(PR_SUCCESS == rv);
    }
    PrintProgress(__LINE__);

    did = PR_FALSE; should = PR_TRUE;
    for (keys = 8; keys < 127; ++keys)
    {
        rv = SetPrivateData(key[keys]);
        MY_ASSERT(PR_SUCCESS == rv);
    }
    PrintProgress(__LINE__);

    did = should = PR_FALSE;
    for (keys = 8; keys < 127; ++keys)
    {
        rv = SetPrivateData(key[keys]);
        MY_ASSERT(PR_SUCCESS == rv);
    }
}  /* MyThread::RootFunction */
Ejemplo n.º 16
0
int main(PRIntn argc, char *argv[])
{
    PRStatus rv;
    PRUintn keys;
    MyThread *thread;
    const RCThreadPrivateData *pd;
    PLOptStatus os;
    PLOptState *opt = PL_CreateOptState(argc, argv, "d");
    RCThread *primordial = RCThread::WrapPrimordialThread();
    while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
    {
        if (PL_OPT_BAD == os) continue;
        switch (opt->option)
        {
        case 'd':  /* debug mode */
            debug = PR_TRUE;
            break;
         default:
            break;
        }
    }
    PL_DestroyOptState(opt);

    fout = PR_STDOUT;

    MyPrivateData extension = MyPrivateData("EXTENSION");
    MyPrivateData key_string[] = {
        "Key #0", "Key #1", "Key #2", "Key #3",
        "Bogus #5", "Bogus #6", "Bogus #7", "Bogus #8"};
    

    did = should = PR_FALSE;
    for (keys = 0; keys < 4; ++keys)
    {
        rv = RCThread::NewPrivateIndex(&key[keys]);
        key[keys + 4] = key[keys] + 4;
        MY_ASSERT(PR_SUCCESS == rv);
    }
    PrintProgress(__LINE__);

    /* the first four should be bu null, the last four undefined and null */
    did = should = PR_FALSE;
    for (keys = 0; keys < 8; ++keys)
    {
        pd = RCThread::GetPrivateData(key[keys]);
        MY_ASSERT(NULL == pd);
    }
    PrintProgress(__LINE__);

    /* initially set private data for new keys */
    did = should = PR_FALSE;
    for (keys = 0; keys < 4; ++keys)
    {
        rv = RCThread::SetPrivateData(key[keys], &key_string[keys]);
        MY_ASSERT(PR_SUCCESS == rv);
    }
    PrintProgress(__LINE__);

    /* re-assign the private data, albeit the same content */    
    did = PR_FALSE; should = PR_TRUE;
    for (keys = 0; keys < 4; ++keys)
    {
        pd = RCThread::GetPrivateData(key[keys]);
        PR_ASSERT(NULL != pd);
        rv = RCThread::SetPrivateData(key[keys], &key_string[keys]);
        MY_ASSERT(PR_SUCCESS == rv);
    }
    PrintProgress(__LINE__);

    /* set private to <empty> */
    did = PR_FALSE; should = PR_TRUE;
    for (keys = 0; keys < 4; ++keys)
    {
        rv = RCThread::SetPrivateData(key[keys]);
        MY_ASSERT(PR_SUCCESS == rv);
    }
    PrintProgress(__LINE__);

    /* should all be null now */
    did = should = PR_FALSE;
    for (keys = 0; keys < 4; ++keys)
    {
        pd = RCThread::GetPrivateData(key[keys]);
        PR_ASSERT(NULL == pd);
    }
    PrintProgress(__LINE__);

    /* allocate another batch of keys and assign data to them */
    did = should = PR_FALSE;
    for (keys = 8; keys < 127; ++keys)
    {
        rv = RCThread::NewPrivateIndex(&key[keys]);
        MY_ASSERT(PR_SUCCESS == rv);
        rv = RCThread::SetPrivateData(key[keys], &extension);
        MY_ASSERT(PR_SUCCESS == rv);
    }
    PrintProgress(__LINE__);

    /* set all the extended slots to <empty> */
    did = PR_FALSE; should = PR_TRUE;
    for (keys = 8; keys < 127; ++keys)
    {
        rv = RCThread::SetPrivateData(key[keys]);
        MY_ASSERT(PR_SUCCESS == rv);
    }
    PrintProgress(__LINE__);

    /* set all the extended slots to <empty> again (noop) */
    did = should = PR_FALSE;
    for (keys = 8; keys < 127; ++keys)
    {
        rv = RCThread::SetPrivateData(key[keys]);
        MY_ASSERT(PR_SUCCESS == rv);
    }

    if (debug) PR_fprintf(fout, "Creating thread\n");
    thread = new MyThread();
    if (debug) PR_fprintf(fout, "Starting thread\n");
    thread->Start();
    if (debug) PR_fprintf(fout, "Joining thread\n");
    (void)thread->Join();
    if (debug) PR_fprintf(fout, "Joined thread\n");

    failed |= (PR_FAILURE == RCPrimordialThread::Cleanup());

    (void)PR_fprintf(
        fout, "%s\n",((PR_TRUE == failed) ? "FAILED" : "PASSED"));

    return (failed) ? 1 : 0;

}  /* main */
Ejemplo n.º 17
0
//------------------------------------------------------------------------------
// Loop
//------------------------------------------------------------------------------
void AnalysisPR::Loop(TString analysis, TString filename, float luminosity)
{
  if (fChain == 0) return;

  Setup(analysis, filename, luminosity);

  root_output->cd();
  

  // Define prompt rate histograms
  //----------------------------------------------------------------------------
  h_Muon_loose_pt_eta_PR = new TH2D("h_Muon_loose_pt_eta_PR", "", nptbin, ptbins, netabin, etabins);
  h_Muon_tight_pt_eta_PR = new TH2D("h_Muon_tight_pt_eta_PR", "", nptbin, ptbins, netabin, etabins);
  h_Ele_loose_pt_eta_PR  = new TH2D("h_Ele_loose_pt_eta_PR",  "", nptbin, ptbins, netabin, etabins);
  h_Ele_tight_pt_eta_PR  = new TH2D("h_Ele_tight_pt_eta_PR",  "", nptbin, ptbins, netabin, etabins);
    
  h_Muon_loose_pt_PR = new TH1D("h_Muon_loose_pt_PR", "", nptbin, ptbins);
  h_Muon_tight_pt_PR = new TH1D("h_Muon_tight_pt_PR", "", nptbin, ptbins);
  h_Ele_loose_pt_PR  = new TH1D("h_Ele_loose_pt_PR",  "", nptbin, ptbins);
  h_Ele_tight_pt_PR  = new TH1D("h_Ele_tight_pt_PR",  "", nptbin, ptbins);
    
  h_Muon_loose_eta_PR = new TH1D("h_Muon_loose_eta_PR", "", netabin, etabins);
  h_Muon_tight_eta_PR = new TH1D("h_Muon_tight_eta_PR", "", netabin, etabins);
  h_Ele_loose_eta_PR  = new TH1D("h_Ele_loose_eta_PR",  "", netabin, etabins);
  h_Ele_tight_eta_PR  = new TH1D("h_Ele_tight_eta_PR",  "", netabin, etabins);


  // Loop over events
  //----------------------------------------------------------------------------
  for (Long64_t jentry=0; jentry<_nentries;jentry++) {

    Long64_t ientry = LoadTree(jentry);

    if (ientry < 0) break;

    fChain->GetEntry(jentry);

    PrintProgress(jentry, _nentries);

    EventSetup();

    _channel = (abs(Lepton1.flavour) == ELECTRON_FLAVOUR) ? e : m;

    _leptonPtMin  = (_channel == e) ?  13 :  10;
    _leptonEtaMax = (_channel == e) ? 2.5 : 2.4;

    if (Lepton1.v.Pt()        < _leptonPtMin)  continue;
    if (fabs(Lepton1.v.Eta()) > _leptonEtaMax) continue;


    // Make Z candidate
    //--------------------------------------------------------------------------
    _Zlepton1type = Loose;
    _Zlepton2type = Loose;

    _m2l = -999;
    
    if (AnalysisLeptons.size() >= 2) { 
      
      for (int iLep1=0; iLep1<AnalysisLeptons.size(); iLep1++) {
	
	if (AnalysisLeptons[iLep1].v.Pt() < 10.) continue;
	
	for (int iLep2=iLep1+1; iLep2<AnalysisLeptons.size(); iLep2++) {
	  
	  if (AnalysisLeptons[iLep2].v.Pt() < 10.) continue;
	  
	  if ((AnalysisLeptons[iLep1].flavour + AnalysisLeptons[iLep2].flavour) != 0.) continue;
	  
	  float inv_mass = (AnalysisLeptons[iLep1].v + AnalysisLeptons[iLep2].v).M();
	  
	  if (_m2l < 0 || fabs(inv_mass - Z_MASS) < fabs(_m2l - Z_MASS)) {
	    
	    _m2l = inv_mass;

	    // Is the first Z lepton tight?
	    if (AnalysisLeptons[iLep1].type > 0.5 && AnalysisLeptons[iLep1].flavour == ELECTRON_FLAVOUR)
	      {
		_Zlepton1type  = Tight;
		_Zdecayflavour = ELECTRON_FLAVOUR;
	      }
	    else if (AnalysisLeptons[iLep1].type > 0.5 && AnalysisLeptons[iLep1].flavour == MUON_FLAVOUR)
	      {
		_Zlepton1type  = Tight;
		_Zdecayflavour = MUON_FLAVOUR;
	      }

	    
	    // Is the second Z lepton tight?
	    if (AnalysisLeptons[iLep2].type > 0.5 && AnalysisLeptons[iLep2].flavour == ELECTRON_FLAVOUR)
	      {
		_Zlepton2type = Tight;
	      }
	    else if (AnalysisLeptons[iLep2].type > 0.5 && AnalysisLeptons[iLep2].flavour == MUON_FLAVOUR)
	      {
		_Zlepton2type = Tight;
	      }
	  }
	}
      }
    }
    

    // Get the event weight
    //--------------------------------------------------------------------------
    bool passTrigger;

    if (_ismc) {

      passTrigger = true;

      _event_weight = (baseW / 1e3) * puW;

      if (GEN_weight_SM) _event_weight *= GEN_weight_SM / abs(GEN_weight_SM);


      // Muons
      //------------------------------------------------------------------------
      if (_channel == m)
	{
	  (Lepton1.v.Pt() <= 20.) ? _event_weight *= 7.339 : _event_weight *= 217.553;  // For 36/fb
	}

      
      // Electrons
      //------------------------------------------------------------------------
      if (_channel == e)
	{
	  (Lepton1.v.Pt() <= 25.) ? _event_weight *= 14.888 : _event_weight *= 63.046;
	}

    } else {

      _event_weight = 1.0;

      passTrigger = false;


      // Muons
      //------------------------------------------------------------------------
      if (_sample.Contains("DoubleMuon") && _channel == m) {

	if (Lepton1.v.Pt() <= 20. && std_vector_trigger->at(22)) {  // HLT_Mu8_TrkIsoVVL_v*

	  passTrigger = true;

	} else if (Lepton1.v.Pt() > 20. && std_vector_trigger->at(23)) {  // HLT_Mu17_TrkIsoVVL_v*

	  passTrigger = true;
	}
      }


      // Electrons
      //------------------------------------------------------------------------
      if (_sample.Contains("DoubleEG") && _channel == e) {
	
	if (Lepton1.v.Pt() <= 25. && std_vector_trigger->at(31)) {  // HLT_Ele12_CaloIdL_TrackIdL_IsoVL_PFJet30_v*

	  passTrigger = true;
	  
	} else if (Lepton1.v.Pt() > 25. && std_vector_trigger->at(33)) {  // HLT_Ele23_CaloIdL_TrackIdL_IsoVL_PFJet30_v*

	  passTrigger = true;
	}
      }
    }


    // Prompt rate from MC
    //--------------------------------------------------------------------------
    bool pass = true;

    pass &= (76. < _m2l && 106. > _m2l);
    pass &= (_mtw < 20.);
    
    if (pass && _sample.Contains("DYJetsToLL") && _Zlepton1type == Tight) {

      float Zlep2pt  = std_vector_lepton_pt->at(1);
      float Zlep2eta = fabs(std_vector_lepton_eta->at(1));
      
      if (fabs(_Zdecayflavour) == ELECTRON_FLAVOUR) {
      
	h_Ele_loose_pt_eta_PR->Fill(Zlep2pt, Zlep2eta, _event_weight);
	h_Ele_loose_pt_PR    ->Fill(Zlep2pt,  _event_weight);
	h_Ele_loose_eta_PR   ->Fill(Zlep2eta, _event_weight);
	
	if (_Zlepton2type == Tight) {
      
	  h_Ele_tight_pt_eta_PR->Fill(Zlep2pt, Zlep2eta, _event_weight);
	  h_Ele_tight_pt_PR    ->Fill(Zlep2pt,  _event_weight);
	  h_Ele_tight_eta_PR   ->Fill(Zlep2eta, _event_weight);
	}

      }	else if (fabs(_Zdecayflavour) == MUON_FLAVOUR) {

	h_Muon_loose_pt_eta_PR->Fill(Zlep2pt, Zlep2eta, _event_weight);
	h_Muon_loose_pt_PR    ->Fill(Zlep2pt,  _event_weight);
	h_Muon_loose_eta_PR   ->Fill(Zlep2eta, _event_weight);

	if (_Zlepton2type == Tight) {
	  
	  h_Muon_tight_pt_eta_PR->Fill(Zlep2pt, Zlep2eta, _event_weight);
	  h_Muon_tight_pt_PR    ->Fill(Zlep2pt,  _event_weight);
	  h_Muon_tight_eta_PR   ->Fill(Zlep2eta, _event_weight);
	}
      }
    }
  }

  EndJob();
}