Ejemplo n.º 1
0
//______________________________________________________________________________
TChain* CreateChain(Int_t mode, Char_t* inputPath, Char_t* aodFilename = "AliAOD.root")
{
  printf("*******************************\n");
  printf("*** Getting the Chain       ***\n");
  printf("*******************************\n");
  TChain *chain = 0x0;
  if(mode==kMgridInteractive || mode==kMgridBatch){
    AliTagAnalysis *analysis = new AliTagAnalysis();
    chain = analysis->GetChainFromCollection(inputPath,"aodTree");
  }
  else{
    chain = new TChain("aodTree");
    TString inFileName(aodFilename);
    inFileName.Prepend(Form("%s/",inputPath));
    chain->Add(inFileName);
  }
  //if (chain) chain->ls();
  return chain;
}
Ejemplo n.º 2
0
int main(int argc, char** argv)
{
  setTDRStyle();
  gStyle -> SetOptFit(0000);
  
  int nFib = 64;
  int nCryst = 9;
  
  std::string inFileName(argv[1]);
  
  
  //----------
  // open file
  
  TFile* inFile = TFile::Open(Form("ntuples/tot_capture_%s.root",inFileName.c_str()));
  TTree* tree = (TTree*)( inFile->Get("tree") );
  
  
  //---------------------
  // set branch addresses
  
  std::map<int,std::vector<int>*> t_waveform;
  std::map<int,std::vector<int>*> t_crystWaveform;
  
  for(int fibIt = 0; fibIt < nFib; ++fibIt)
  {
    t_waveform[fibIt] = new std::vector<int>;
    tree -> SetBranchAddress(Form("fib%02d_waveform",fibIt),&t_waveform[fibIt]);
  }
  for(int crystIt = 0; crystIt < nCryst; ++crystIt)
  {
    t_crystWaveform[crystIt] = new std::vector<int>;
    tree -> SetBranchAddress(Form("cryst%01d_waveform",crystIt),&t_crystWaveform[crystIt]);
  }
  
  
  
  //-------------
  // define plots
  
  std::map<int,int> n_waveform_fib;
  TGraph** g_waveform_fib = new TGraph*[nFib];
  
  std::map<int,int> n_waveform_cut_fib;
  TGraph** g_waveform_cut_fib = new TGraph*[nFib];
  
  TH1F** h_ped_fib = new TH1F*[nFib];
  TH1F* h_ped_fib_all = new TH1F("h_ped_fib_all","",100,80.,120.);
  
  TH1F** h_maximum_fib = new TH1F*[nFib];
  TH1F* h_maximum_fib_all = new TH1F("h_maximum_fib_all","",1000,0.,2500.);
  
  for(int fibIt = 0; fibIt < nFib; ++fibIt)
  {
    g_waveform_fib[fibIt] = new TGraph();
    g_waveform_cut_fib[fibIt] = new TGraph();
    
    h_ped_fib[fibIt] = new TH1F(Form("h_ped_fib%02d",fibIt),"",100,80.,120.);
    h_maximum_fib[fibIt] = new TH1F(Form("h_maximum_fib%02d",fibIt),"",1000,0.,2500.);
  }
  
  TProfile2D* p_fibAveInt = new TProfile2D("p_fibAveInt","",17,-0.5,16.5,18,-0.5,17.5);
  TProfile2D* p_fibAveMax = new TProfile2D("p_fibAveMax","",17,-0.5,16.5,18,-0.5,17.5);
  TProfile2D* p_crystAveMax = new TProfile2D("p_crystAveMax","",3,-0.5,2.5,3,-0.5,2.5);
  
  TH1F* h_tot_integral = new TH1F("h_tot_integral","",1000,0.,100000.);
  TH1F* h_tot_maximum  = new TH1F("h_tot_maximum", "",1000,0.,1000.);
  
  
  //------------------
  // loop over entries
  
  for(int entry = 0; entry < tree->GetEntries(); ++entry)
  {
    std::cout << ">>> reading entry " << entry << " / " << tree->GetEntries() << "\r" << std::flush;
    tree -> GetEntry(entry);
    
    float tot_integral = 0.;
    float tot_maximum = 0.;
    
    for(int fibIt = 0; fibIt < nFib; ++fibIt)
    {
      ++n_waveform_fib[fibIt];
      AddWaveform(g_waveform_fib[fibIt],t_waveform[fibIt]);
      
      float ped, integral, maximum;
      CalculateAmplitude(t_waveform[fibIt],ped,integral,maximum);
      
      h_ped_fib[fibIt] -> Fill(ped);
      h_ped_fib_all -> Fill(ped);
      h_maximum_fib[fibIt] -> Fill(maximum);
      h_maximum_fib_all -> Fill(maximum);
      
      int x = 16-2*int(fibIt/8);
      int y = (x/2)%2 == 0 ? 16-2*(fibIt%8) : 16-2*(fibIt%8)-1;
      p_fibAveInt -> Fill(x,y,integral);
      p_fibAveMax -> Fill(x,y,maximum);
      
      if( maximum+ped > 120. )
      {
        tot_integral += integral;
        tot_maximum += maximum;
        
        ++n_waveform_cut_fib[fibIt];
        AddWaveform(g_waveform_cut_fib[fibIt],t_waveform[fibIt]);
      }
    }
    
    for(int crystIt = 0; crystIt < nCryst; ++crystIt)
    {
      float ped, integral, maximum;
      CalculateAmplitude(t_waveform[crystIt],ped,integral,maximum);
      p_crystAveMax -> Fill(crystIt%3,2-crystIt/3,maximum);
    }
    
    h_tot_integral -> Fill(tot_integral);
    h_tot_maximum -> Fill(tot_maximum);
  }
  
  
  
  TCanvas* c_waveform_fib_all = new TCanvas();
  
  int plotIt = 0;
  float min = +999999.;
  float max = -999999.;
  
  for(int fibIt = 0; fibIt < nFib; ++fibIt)
  {
    TGraph* g = g_waveform_fib[fibIt];
    if( g->GetN() == 0 ) continue;
    
    NormalizeGraph(g,n_waveform_fib[fibIt]);
    
    if( GetMinimum(g) < min ) min = GetMinimum(g);
    if( GetMaximum(g) > max ) max = GetMaximum(g);
  }
  
  for(int fibIt = 0; fibIt < nFib; ++fibIt)
  {
    TGraph* g = g_waveform_fib[fibIt];
    if( g->GetN() == 0 ) continue;
    
    TCanvas* c_waveform_fib = new TCanvas();
    
    g -> SetMinimum(min-0.05*fabs(max-min));
    g -> SetMaximum(max+0.05*fabs(max-min));
    g -> SetLineWidth(2);
    g -> SetLineColor(fibIt+1);
    g -> SetMarkerSize(0.2);
    g -> GetXaxis() -> SetTitle("sample time (ns)");
    g -> Draw("APL");
    
    c_waveform_fib -> Print(Form("/afs/cern.ch/user/a/abenagli/www/TBatFNAL/%s/plotsPerFib/waveform_fib%02d.png",inFileName.c_str(),fibIt),"png");
    
    c_waveform_fib_all -> cd();
    
    if( plotIt == 0 ) g -> Draw("APL");
    else              g -> Draw("PL,same");
    
    ++plotIt;
  }
  
  c_waveform_fib_all -> Print(Form("/afs/cern.ch/user/a/abenagli/www/TBatFNAL/%s/waveform_fib_all.png",inFileName.c_str()),"png");
  
  
  
  TCanvas* c_waveform_cut_fib_all = new TCanvas();
  
  plotIt = 0;
  min = +999999.;
  max = -999999.;
  
  for(int fibIt = 0; fibIt < nFib; ++fibIt)
  {
    TGraph* g = g_waveform_cut_fib[fibIt];
    if( g->GetN() == 0 ) continue;
    
    NormalizeGraph(g,n_waveform_cut_fib[fibIt]);
    
    if( GetMinimum(g) < min ) min = GetMinimum(g);
    if( GetMaximum(g) > max ) max = GetMaximum(g);
  }
  
  for(int fibIt = 0; fibIt < nFib; ++fibIt)
  {
    TGraph* g = g_waveform_cut_fib[fibIt];
    if( g->GetN() == 0 ) continue;
    
    //g -> SetMinimum(min-0.05*fabs(max-min));
    //g -> SetMaximum(max+0.05*fabs(max-min));
    g -> SetLineWidth(2);
    g -> SetLineColor(fibIt+1);
    g -> SetMarkerSize(0.2);
    g -> GetXaxis() -> SetTitle("sample time (ns)");
    g -> Draw("APL");
    
    c_waveform_cut_fib_all -> cd();
    
    if( plotIt == 0 ) g -> Draw("APL");
    else              g -> Draw("PL,same");
    
    ++plotIt;
  }
  
  c_waveform_cut_fib_all -> Print(Form("/afs/cern.ch/user/a/abenagli/www/TBatFNAL/%s/waveform_cut_fib_all.png",inFileName.c_str()),"png");
  
  
  
  for(int fibIt = 0; fibIt < nFib; ++fibIt)
  {
    TH1F* h = h_ped_fib[fibIt];
    
    TCanvas* c_ped_fib = new TCanvas();
    c_ped_fib -> SetLogy();
    
    h -> SetLineWidth(2);
    h -> GetXaxis() -> SetTitle("max sample");
    h -> Draw();
    h -> Fit("gaus","Q");
    
    TLatex* latex1 = new TLatex(0.60,0.90,Form("RMS = %.1f",h->GetRMS()));
    latex1 -> SetNDC();
    latex1 -> SetTextFont(42);
    latex1 -> SetTextSize(0.04);
    latex1 -> Draw("same");
    
    TLatex* latex2 = new TLatex(0.60,0.85,Form("#sigma = %.1f",h->GetFunction("gaus")->GetParameter(2)));
    latex2 -> SetNDC();
    latex2 -> SetTextFont(42);
    latex2 -> SetTextSize(0.04);
    latex2 -> Draw("same");
    
    c_ped_fib -> Print(Form("/afs/cern.ch/user/a/abenagli/www/TBatFNAL/%s/plotsPerFib/ped_fib%02d.png",inFileName.c_str(),fibIt),"png");
    
    h = h_maximum_fib[fibIt];
    
    TCanvas* c_maximum_fib = new TCanvas();
    c_maximum_fib -> SetLogy();
    
    h -> SetLineWidth(2);
    h -> GetXaxis() -> SetTitle("max sample");
    h -> Draw();
    
    c_maximum_fib -> Print(Form("/afs/cern.ch/user/a/abenagli/www/TBatFNAL/%s/plotsPerFib/maximum_fib%02d.png",inFileName.c_str(),fibIt),"png");
  }
  
  TCanvas* c_ped_fib_all = new TCanvas();
  c_ped_fib_all -> SetLogy();
  
  h_ped_fib_all -> SetLineWidth(2);
  h_ped_fib_all -> GetXaxis() -> SetTitle("pedestal");
  h_ped_fib_all -> Draw();
  h_ped_fib_all -> Fit("gaus","Q");
  
  TLatex* latex1 = new TLatex(0.60,0.90,Form("RMS = %.1f",h_ped_fib_all->GetRMS()));
  latex1 -> SetNDC();
  latex1 -> SetTextFont(42);
  latex1 -> SetTextSize(0.04);
  latex1 -> Draw("same");
  
  TLatex* latex2 = new TLatex(0.60,0.85,Form("#sigma = %.1f",h_ped_fib_all->GetFunction("gaus")->GetParameter(2)));
  latex2 -> SetNDC();
  latex2 -> SetTextFont(42);
  latex2 -> SetTextSize(0.04);
  latex2 -> Draw("same");
  c_ped_fib_all -> Print(Form("/afs/cern.ch/user/a/abenagli/www/TBatFNAL/%s/ped_fib_all.png",inFileName.c_str()),"png");
  
  TCanvas* c_maximum_fib_all = new TCanvas();
  c_maximum_fib_all -> SetLogy();
  
  h_maximum_fib_all -> SetLineWidth(2);
  h_maximum_fib_all -> GetXaxis() -> SetTitle("max sample");
  h_maximum_fib_all -> Draw();
  
  c_maximum_fib_all -> Print(Form("/afs/cern.ch/user/a/abenagli/www/TBatFNAL/%s/maximum_fib_all.png",inFileName.c_str()),"png");
  
  
  
  TCanvas* c_fibAveInt = new TCanvas();
  
  p_fibAveInt -> Draw("COLZ");
  c_fibAveInt -> Print(Form("/afs/cern.ch/user/a/abenagli/www/TBatFNAL/%s/fibAveInt.png",inFileName.c_str()),"png");
  
  TCanvas* c_fibAveMax = new TCanvas();
  
  p_fibAveMax -> Draw("COLZ");
  c_fibAveMax -> Print(Form("/afs/cern.ch/user/a/abenagli/www/TBatFNAL/%s/fibAveMax.png",inFileName.c_str()),"png");
  
  
  TCanvas* c_crystAveMax = new TCanvas();
  
  p_crystAveMax -> Draw("COLZ");
  c_crystAveMax -> Print(Form("/afs/cern.ch/user/a/abenagli/www/TBatFNAL/%s/crystAveMax.png",inFileName.c_str()),"png");
  
  
  
  TCanvas* c_tot_integral = new TCanvas();
  c_tot_integral -> SetLogy();
  
  h_tot_integral -> Draw();
  c_tot_integral -> Print(Form("/afs/cern.ch/user/a/abenagli/www/TBatFNAL/%s/tot_integral.png",inFileName.c_str()),"png");
  
  TCanvas* c_tot_maximum = new TCanvas();
  c_tot_maximum -> SetLogy();
  
  h_tot_maximum -> Draw();
  c_tot_maximum -> Print(Form("/afs/cern.ch/user/a/abenagli/www/TBatFNAL/%s/tot_maximum.png",inFileName.c_str()),"png");
}
void PhraseDictionaryFuzzyMatch::InitializeForInput(InputType const& inputSentence)
{
  char dirName[] = "/tmp/moses.XXXXXX";
  char *temp = mkdtemp(dirName);
  UTIL_THROW_IF2(temp == NULL,
		  "Couldn't create temporary directory " << dirName);

  string dirNameStr(dirName);

  string inFileName(dirNameStr + "/in");

  ofstream inFile(inFileName.c_str());

  for (size_t i = 1; i < inputSentence.GetSize() - 1; ++i) {
    inFile << inputSentence.GetWord(i);
  }
  inFile << endl;
  inFile.close();

  long translationId = inputSentence.GetTranslationId();
  string ptFileName = m_FuzzyMatchWrapper->Extract(translationId, dirNameStr);

  // populate with rules for this sentence
  PhraseDictionaryNodeMemory &rootNode = m_collection[translationId];
  FormatType format = MosesFormat;

  // data from file
  InputFileStream inStream(ptFileName);

  // copied from class LoaderStandard
  PrintUserTime("Start loading fuzzy-match phrase model");

  const StaticData &staticData = StaticData::Instance();
  const std::string& factorDelimiter = staticData.GetFactorDelimiter();


  string lineOrig;
  size_t count = 0;

  while(getline(inStream, lineOrig)) {
    const string *line;
    if (format == HieroFormat) { // reformat line
      UTIL_THROW(util::Exception, "Cannot be Hiero format");
      //line = ReformatHieroRule(lineOrig);
    } else {
      // do nothing to format of line
      line = &lineOrig;
    }

    vector<string> tokens;
    vector<float> scoreVector;

    TokenizeMultiCharSeparator(tokens, *line , "|||" );

    if (tokens.size() != 4 && tokens.size() != 5) {
      stringstream strme;
      strme << "Syntax error at " << ptFileName << ":" << count;
      UserMessage::Add(strme.str());
      abort();
    }

    const string &sourcePhraseString = tokens[0]
                                       , &targetPhraseString = tokens[1]
                                           , &scoreString        = tokens[2]
                                               , &alignString        = tokens[3];

    bool isLHSEmpty = (sourcePhraseString.find_first_not_of(" \t", 0) == string::npos);
    if (isLHSEmpty && !staticData.IsWordDeletionEnabled()) {
      TRACE_ERR( ptFileName << ":" << count << ": pt entry contains empty target, skipping\n");
      continue;
    }

    Tokenize<float>(scoreVector, scoreString);
    const size_t numScoreComponents = GetNumScoreComponents();
    if (scoreVector.size() != numScoreComponents) {
      stringstream strme;
      strme << "Size of scoreVector != number (" << scoreVector.size() << "!="
            << numScoreComponents << ") of score components on line " << count;
      UserMessage::Add(strme.str());
      abort();
    }

    UTIL_THROW_IF2(scoreVector.size() != numScoreComponents,
    		"Number of scores incorrectly specified");

    // parse source & find pt node

    // constituent labels
    Word *sourceLHS;
    Word *targetLHS;

    // source
    Phrase sourcePhrase( 0);
    sourcePhrase.CreateFromString(Input, m_input, sourcePhraseString, factorDelimiter, &sourceLHS);

    // create target phrase obj
    TargetPhrase *targetPhrase = new TargetPhrase();
    targetPhrase->CreateFromString(Output, m_output, targetPhraseString, factorDelimiter, &targetLHS);

    // rest of target phrase
    targetPhrase->SetAlignmentInfo(alignString);
    targetPhrase->SetTargetLHS(targetLHS);
    //targetPhrase->SetDebugOutput(string("New Format pt ") + line);

    // component score, for n-best output
    std::transform(scoreVector.begin(),scoreVector.end(),scoreVector.begin(),TransformScore);
    std::transform(scoreVector.begin(),scoreVector.end(),scoreVector.begin(),FloorScore);

    targetPhrase->GetScoreBreakdown().Assign(this, scoreVector);
    targetPhrase->Evaluate(sourcePhrase, GetFeaturesToApply());

    TargetPhraseCollection &phraseColl = GetOrCreateTargetPhraseCollection(rootNode, sourcePhrase, *targetPhrase, sourceLHS);
    phraseColl.Add(targetPhrase);

    count++;

    if (format == HieroFormat) { // reformat line
      delete line;
    } else {
      // do nothing
    }

  }

  // sort and prune each target phrase collection
  SortAndPrune(rootNode);

  //removedirectoryrecursively(dirName);
}
Ejemplo n.º 4
0
void AgiEngine::loadDict() {
	Common::File inFile;
	int lines = 0;

	ConfMan.registerDefault("predictive_dictionary", "pred.dic");

	uint32 time1 = _system->getMillis();
	Common::String inFileName(ConfMan.get("predictive_dictionary"));
	if (!inFile.open(inFileName))
		return;

	char *ptr;
	int size = inFile.size();

	_predictiveDictText = (char *)malloc(size + 1);
	if (!_predictiveDictText) {
		warning("Not enough memory to load the predictive dictionary");
		return;
	}
	inFile.read(_predictiveDictText, size);
	_predictiveDictText[size] = 0;
	uint32 time2 = _system->getMillis();
	debug("Time to read %s: %d bytes, %d ms", inFileName.c_str(), size, time2-time1);
	inFile.close();

	ptr = _predictiveDictText;
	lines = 1;
	while ((ptr = strchr(ptr, '\n'))) {
		lines++;
		ptr++;
	}

	_predictiveDictLine = (char **)calloc(1, sizeof(char *) * lines);
	if (_predictiveDictLine == NULL) {
		warning("Cannot allocate memory for line index buffer");
		return;
	}
	_predictiveDictLine[0] = _predictiveDictText;
	ptr = _predictiveDictText;
	int i = 1;
	while ((ptr = strchr(ptr, '\n'))) {
		*ptr = 0;
		ptr++;
#ifdef __DS__
		// Pass the line on to the DS word list
		DS::addAutoCompleteLine(_predictiveDictLine[i - 1]);
#endif
		_predictiveDictLine[i++] = ptr;
	}
	if (_predictiveDictLine[lines - 1][0] == 0)
		lines--;

	_predictiveDictLineCount = lines;
	debug("Loaded %d lines", _predictiveDictLineCount);

	// FIXME: We use binary search on _predictiveDictLine, yet we make no attempt
	// to ever sort this array (except for the DS port). That seems risky, doesn't it?

#ifdef __DS__
	// Sort the DS word completion list, to allow for a binary chop later (in the ds backend)
	DS::sortAutoCompleteWordList();
#endif

	uint32 time3 = _system->getMillis();
	debug("Time to parse pred.dic: %d, total: %d", time3-time2, time3-time1);
}
Ejemplo n.º 5
0
void dileptonMassFit(const char* pInFileName="PanchoSkim4JanAll.root",
                     // "PromtRecoV2V3V3H_DiMuonPlot_TightSTACutsAll15Dec.root",
                     // "Z0_DataMixPt50_PatDiMuonPlots_NewCutAll14Dec.root",
                     const char* pHistNameOpCh="diMuonsGlobalInvMassVsPt",//diMuonsGlobalInvMassVsPtW",
                     const char* pHistNameSameCh="diMuonsGlobalSameChargeInvMassVsPt",
                     const char* pSpectra="pt",  // pt, y, centr
                     bool doMc=false,
                     int nFitFunction = 3,
                     int getYield = 1)
{
    gROOT->Macro("setStyle.C+");

    //gROOT->Macro("/Users/eusmartass/Software/utilities/setStyle.C+");
    char szBuf[256];

    ////////  definitions of Switches   ///////////
    //  nFitFunction  = 1  RBW + Pol2
    //  nFitFunction  = 2  Gaus + Pol2
    //  nFitFunction  = 3  RBWGaus + Pol2

    //  getYield = 1  Bin counting
    //  getYield = 2  Integral
    ////////////////////////////////////////////////////////////

    // make some choices
    float MassZ0         = 91.1876;
    float WidthZ0        = 2.4952;
    float massFit_low    = 60;
    float massFit_high   = 120;   // Fit ranges
    float massDraw_low   = 30.0;  // 0.
    float massDraw_high  = 130.0; // 200/
    int nrebin           = 80;
    bool isLog           = 0;
    bool isFit           = 1; // draw ranges

    float massCount_low  = 60.0; //78.0
    float massCount_high = 120.0; //102.0

    //___________________________________________________________________________________
    // ------- Open input file
    sprintf(szBuf,"%s",pInFileName);
    TString inFileName(szBuf);
    TFile *pfInFile = new TFile(inFileName);

    // ------- get histograms:
    sprintf(szBuf,"%s",pHistNameOpCh);
    TH2D *phDimuMass_1  = (TH2D*)pfInFile->Get(szBuf)->Clone("phDimuMass_1");

    sprintf(szBuf,"%s",pHistNameSameCh);
    TH2D *phDimuMass_1S = (TH2D*)pfInFile->Get(szBuf)->Clone("phDimuMass_1S");

    phDimuMass_1->SetDirectory(0);
    phDimuMass_1S->SetDirectory(0);

    // Open pp data file

    TFile *ppFile = new TFile("Zmumu_40-200_35pb.root");
    TH1F *Zmumu  = (TH1F*)ppFile->Get("hdata");


    //___________________________________________________________________________________
    // bins definition:
    const char* Xname[] = {" ", "p_{T}^{Dimuon} (GeV/c)", "rapidity", "centrality"};
    bool doPt   = false;
    bool doY    =  false;
    bool doCent = false;

    int GenRange, nBins;
    double binEdge[10];
    char* label;
    sprintf(szBuf,"%s",pSpectra);
    TString wichSpectra(szBuf);

    if ( wichSpectra.CompareTo("pt") == 0) {
        doPt               = true;
        label              = (char*)Xname[1];
        GenRange           = 20;
        nBins              = 1;
        binEdge[0] = 0.0;
        binEdge[1]= 100.0;
        //    double binEdge[10] = {0.0, 10., 20., 100.0};
        if(doMc) {
            nBins              = 1;
            binEdge[0] = 0.0;
            binEdge[1]= 50.0;
            //	  nBins          = 7;
            // binEdge[0] =  0.0;  binEdge[1] =  2.0;  binEdge[2] =  4.0;  binEdge[3] = 8.0;
            //binEdge[4] = 12.0;  binEdge[5] = 16.0;  binEdge[6] = 22.0;  binEdge[7] = 50.0;
        }
    } else {
        if ( wichSpectra.CompareTo("y") == 0) {
            doY              = true;
            label            = (char*)Xname[2];
            nBins            = 3;
            GenRange         = 4.8;
            binEdge[0] = -2.4;
            binEdge[1] = -0.8;
            binEdge[2] =  0.8;
            binEdge[3] =  2.4;
        } else {
            if ( wichSpectra.CompareTo("cent") == 0) 	{
                doCent           = true;
                label            = (char*)Xname[3];
                nBins            = 4;
                GenRange         = 40;
                binEdge[0] = 0.;
                binEdge[1] =   4;
                binEdge[2] = 8.;
                binEdge[3] =  16;
                binEdge[4] =  40;
            } else {
                cout<<"Don't know what you want to do!!!!"<<endl;
                return;
            }
        }
    }

    double PT[10], DelPT[10], mom_err[100];
    for (Int_t ih = 0; ih < nBins; ih++)  {
        PT[ih]      = (binEdge[ih] + binEdge[ih+1])/2.0;
        DelPT[ih]   = binEdge[ih+1] - binEdge[ih];
        mom_err[ih] = DelPT[ih]/2.0;
    }

    //___________________________________________________________________________________

    double gen_pt[10];
    double egen_pt[10];

    TCanvas *pcPt_1 = new TCanvas("pcPt_1"," Z0 Yield Vs. Pt ", 40,40,600,600);

    if(doMc) {
        pcPt_1->Divide(nBins,2);

        //TH2D *genMass_1 = (TH2D*)pfInFile->Get("diMuonsGenInvMassVsPt");
        TH2D *genMass_1 = (TH2D*)pfInFile->Get("diMuonsGenInvMassVsPtW");
        TH1D *ptaxis    = (TH1D*)genMass_1->ProjectionY("ptaxis");

        for (Int_t ih = 0; ih < nBins; ih++) {
            pcPt_1->cd(ih+nBins+1);

            int bin1 = ptaxis->FindBin(binEdge[ih]+0.0000001);
            int bin2 = ptaxis->FindBin(binEdge[ih+1]+0.0000001);

            TH1D * genMassVsPt = (TH1D*)genMass_1->ProjectionX("genMassVsPt", bin1, bin2-1);
            genMassVsPt->Draw("EPL");
            pcPt_1->Update();

            TAxis *axs        = genMassVsPt->GetXaxis();
            int binlow        = axs->FindBin(massCount_low);
            int binhi         = axs->FindBin(massCount_high);

            double int_sig_gen;
            double int_sig_gen_sqr;
            for(Int_t bin = binlow; bin<=binhi; bin++) {
                //    cout << "	  int_sig += dimuonsGlobalInvMassVsPt[ih]->GetBinContent(bin);"<<int_sigpow_gen <<"+="<< "bin" << bin << " content"<<genMassVsPt->GetBinContent(bin)<<endl;
                int_sig_gen += genMassVsPt->GetBinContent(bin);
                int_sig_gen_sqr += pow(genMassVsPt->GetBinContent(bin),2);
            }


            gen_pt[ih] = int_sig_gen;//genMassVsPt->GetEntries();
            cout<<" gen entries : "<< gen_pt[ih]<<endl;
            egen_pt[ih] =int_sig_gen_sqr;

        }
    }
    else {
        if (nBins == 2)  pcPt_1->Divide(2,1);
        if (nBins == 3 || nBins == 4)  pcPt_1->Divide(2,2);
        if (nBins == 5 || nBins == 6)  pcPt_1->Divide(3,2);

    }


    //___________________________________________________________________________________
    // Fit Function
    //  const char *name_fit[] = {"  ", "RBWPol1", "GausPol1", "RBWGausPol2"};
    int nParam[]           = {0,6,6,7};
    int nFitParam          = nParam[nFitFunction];
    TF1 *RBWPOL=0;
    if(nFitFunction == 1) RBWPOL = new TF1("RBWPOL", RBWPol2,     0, 200, nFitParam);
    if(nFitFunction == 2) RBWPOL = new TF1("RBWPOL", GausPol2,    0, 200, nFitParam);
    if(nFitFunction == 3) RBWPOL = new TF1("RBWPOL", RBWGausPol2, 0, 200, nFitParam);
    TF1 *EXP               = new TF1("EXP", Exp, 0, 200, 2);

    RBWPOL->SetLineWidth(1);
    RBWPOL->SetParameter(1, MassZ0);
    RBWPOL->SetParameter(2, WidthZ0);

    RBWPOL->SetParLimits(1, 0.9*MassZ0, 1.1*MassZ0);
    RBWPOL->SetParLimits(2, 0.1*WidthZ0, 5.0*WidthZ0);

    if(nFitFunction  == 1 || nFitFunction  == 2) RBWPOL->FixParameter(5, 0);
    if(nFitFunction  == 3 || nFitFunction  == 4)  {
        RBWPOL->SetParameter(3, WidthZ0);
        RBWPOL->SetParLimits(3, 0.1, 20);
        RBWPOL->FixParameter(2, WidthZ0);

        RBWPOL->FixParameter(4, 0);   // for no bkg
        RBWPOL->FixParameter(5, 0);   // for no bkg
        RBWPOL->FixParameter(6, 0);
    }


    //___________________________________________________________________________________
    // Efficiency

    double yld_cat_1[10], cyld_cat_1[10], eyld_cat_1[10], ceyld_cat_1[10];
    double Eff_cat_1[10], errEff_cat_1[10];


    ///// Write the spectra
    sprintf(szBuf,"fileSpecta%d.root", getYield);
    //  TFile *fileSpectra = new TFile(szBuf, "recreate");


    //___________________________________________________________________________________
    // Drawing
    // Category _1
    TLegend *pLegCategory = new TLegend(.66, .74, .92, .94);
    //  pLegCategory = new TLegend(.1, .82, .50, .93);
    pLegCategory->SetBorderSize(0);
    pLegCategory->SetFillStyle(0);
    pLegCategory->SetFillColor(0);
    pLegCategory->SetTextSize(0.03);
    //  pLegCategory->AddEntry(RBWPOL," CMS Preliminary", " ");

    pLegCategory->AddEntry(RBWPOL," CMS Pb+Pb ", " ");
    pLegCategory->AddEntry(RBWPOL," #sqrt{s_{NN}} = 2.76 TeV ", " ");
    pLegCategory->AddEntry(RBWPOL," #int Ldt  = 6.6 #mub^{-1} ", " ");

    //  pLegCategory->AddEntry(RBWPOL," Global-Global ", "");
    //pLegCategory->AddEntry(RBWPOL," |y| < 2.4 ", "P");
    //pLegCategory->AddEntry(RBWPOL," Run# 150431-151027 ", "P");

    TLegend *legend_1[12];
    for(int i=0; i<12; i++) {
        if(isFit) legend_1[i] = new TLegend(.13, .66, .52, 0.94);
        if(!isFit) legend_1[i] = new TLegend(.13, .66, .52, 0.94 );
        //    legend_1[i] = new TLegend(.68, .62, .91, 0.93 );
        legend_1[i]->SetBorderSize(0);
        legend_1[i]->SetFillStyle(0);
        legend_1[i]->SetFillColor(0);
        legend_1[i]->SetTextSize(0.028);
    }

    int bin_bound[100];
    TH1D *dimuonsGlobalInvMassVsPt[10];
    TH1D *dimuonsGlobalInvMassVsPtS[10];
    TH1D *service = (TH1D*)phDimuMass_1->ProjectionY("service");

    //  cout << endl << label << "    Yield      Mass (GeV)    Width (GeV)    GauWidth    chi2/ndf " << endl << endl;
    for (Int_t ih = 0; ih < nBins; ih++)  {
        pcPt_1->cd(ih+1);
        gPad->SetTickx();
        gPad->SetTicky();

        // Project 1 D
        bin_bound[ih]   = service->FindBin(binEdge[ih]+0.0000001);
        bin_bound[ih+1] = service->FindBin(binEdge[ih+1]+0.0000001);

        sprintf(szBuf,"Z0_1_pt_%d",ih);
        dimuonsGlobalInvMassVsPt[ih]  = (TH1D*)phDimuMass_1->ProjectionX(szBuf, bin_bound[ih], bin_bound[ih+1]-1+1, "e");
        sprintf(szBuf,"Z0_1S_pt_%d",ih);
        dimuonsGlobalInvMassVsPtS[ih] = (TH1D*)phDimuMass_1S->ProjectionX(szBuf, bin_bound[ih], bin_bound[ih+1]-1+1);
        cout << "reco entries" << dimuonsGlobalInvMassVsPt[ih]->GetEntries() <<endl;
        if(doPt || doY) {
            sprintf(szBuf," %s [%.1f, %.1f]",
                    label,
                    service->GetBinLowEdge(bin_bound[ih]),
                    service->GetBinLowEdge(bin_bound[ih+1]-1) + service->GetBinWidth(bin_bound[ih+1]));
        }

        if(doCent) {
            sprintf(szBuf," %s [%.1f, %.1f] %s",
                    label,
                    2.5*service->GetBinLowEdge(bin_bound[ih]),
                    2.5*(service->GetBinLowEdge(bin_bound[ih+1]-1) + service->GetBinWidth(bin_bound[ih+1])), "%");
        }

        dimuonsGlobalInvMassVsPt[ih]->Rebin(nrebin);
        dimuonsGlobalInvMassVsPtS[ih]->Rebin(nrebin);

        // -------- Fit Function + Bkg Function
        double part[20];
        dimuonsGlobalInvMassVsPt[ih]->Fit("EXP","LEQ", "", 34, 60);
        EXP->GetParameters(part);
        if(nFitFunction  == 4) {
            RBWPOL->FixParameter(4, part[0]);
            RBWPOL->FixParameter(5, part[1]);
        }

        if(isFit) {
            //dimuonsGlobalInvMassVsPt[ih]->Fit("RBWPOL","LEQ", "", massFit_low, massFit_high);
            //TFitResultPtr r =
            dimuonsGlobalInvMassVsPt[ih]->Fit("RBWPOL","LEQS0","", massFit_low, massFit_high);
            //	if(r->IsValid()) r->Print();
            //else cout<<"Fit not valid!!!\n"<<endl;
        }

        //------  get fit parameters
        double par[20];
        RBWPOL->GetParameters(par);

        float GGphDimuMass = RBWPOL->GetParameter(1);
        float GGZ0Width    = RBWPOL->GetParameter(2);
        float GauWidth     =0;
        if(nFitFunction  == 3 || nFitFunction  == 4) GauWidth = RBWPOL->GetParameter(3);

        double chisq      = RBWPOL->GetChisquare();
        int ndf           = RBWPOL->GetNDF();
        double chisqdf    =1000;
        if(ndf!=0) chisqdf=chisq/ndf;

        // +++ set backgroudn fit
        sprintf(szBuf,"pt_1B_%d",ih);
        TF1 *bkgFit_1 = new TF1(szBuf, Pol2, massFit_low, massFit_high, 3);
        // if(nFitFunction  == 4) bkgFit_1 = new TF1(namePt_1B, Exp, massFit_low, massFit_high, 2);

        bkgFit_1->SetParameters(&par[3]);
        if(nFitFunction  == 3 || nFitFunction  == 4) bkgFit_1->SetParameters(&par[4]);

        // ----------  Integrated Yield
        //    float massCount_low =GGphDimuMass-(4.0*GGZ0Width);
        //    float massCount_high =GGphDimuMass+(4.0*GGZ0Width);

        TAxis *axs        = dimuonsGlobalInvMassVsPt[ih]->GetXaxis();
        int binlow        = axs->FindBin(massCount_low);
        int binhi         = axs->FindBin(massCount_high);
        Double_t bin_size = (1.0*dimuonsGlobalInvMassVsPt[ih]->GetNbinsX())/(axs->GetXmax() - axs->GetXmin());

        Float_t int_sig   = 0.0;
        Float_t int_sig_sqr   = 0.0;
        for(Int_t bin = binlow; bin<=binhi; bin++) {
            //	  cout << "	  int_sig += dimuonsGlobalInvMassVsPt[ih]->GetBinContent(bin);"<<int_sig <<"+="<< "bin" << bin << " content"<<dimuonsGlobalInvMassVsPt[ih]->GetBinContent(bin)<<endl;
            int_sig += dimuonsGlobalInvMassVsPt[ih]->GetBinContent(bin);
            int_sig_sqr += pow(dimuonsGlobalInvMassVsPt[ih]->GetBinContent(bin),2);
        }

        if(getYield == 2) {
            int_sig =  RBWPOL->Integral(massCount_low, massCount_high)*bin_size;
            yld_cat_1[ih]   = int_sig - bin_size*bkgFit_1->Integral(massCount_low, massCount_high);
            eyld_cat_1[ih] = TMath::Sqrt(int_sig + bin_size*bkgFit_1->Integral(massCount_low, massCount_high) );
        }

        else {
            yld_cat_1[ih]   = int_sig ;
            eyld_cat_1[ih] = int_sig_sqr;
        }
        cout << "int_sig - bin_size*bkgFit_1->Integral(massCount_low, massCount_high);" << int_sig<< "  -"<< bin_size<<"*"<<bkgFit_1->Integral(massCount_low, massCount_high)<< " with low"<< massCount_low<<" high "<< massCount_high<<endl;
        //// Printing /////
        cout <<  PT[ih] << "    " << yld_cat_1[ih] << " +- " << eyld_cat_1[ih] <<"     " << GGphDimuMass << "    " << GGZ0Width  << "    " << GauWidth <<"   "<< chisq << "/" << ndf  << endl;


        // -------------- Draw
        //    dimuonsGlobalInvMassVsPt[ih]->SetMinimum(-.05*dimuonsGlobalInvMassVsPt[ih]->GetMaximum());

        if(isLog) gPad->SetLogy(1);

        TColor *pal    = new TColor();
        Int_t kblue    = pal->GetColor(9,0,200);
        //    Int_t korange  = pal->GetColor(101, 42,  0);

        // +++ opposite charge
        dimuonsGlobalInvMassVsPt[ih]->SetMarkerStyle(21);
        dimuonsGlobalInvMassVsPt[ih]->SetMarkerColor(kblue);
        dimuonsGlobalInvMassVsPt[ih]->SetLineColor(kblue);
        dimuonsGlobalInvMassVsPt[ih]->SetMarkerSize(1.1);
        dimuonsGlobalInvMassVsPt[ih]->GetXaxis()->SetTitle("Dimuon mass (GeV/c^{2})");
        dimuonsGlobalInvMassVsPt[ih]->GetYaxis()->SetTitle("dN/dM (2 GeV/c^{2})^{-1}");

        dimuonsGlobalInvMassVsPt[ih]->GetXaxis()->SetRangeUser(massDraw_low,massDraw_high);
        //    dimuonsGlobalInvMassVsPt[ih]->Add(dimuonsGlobalInvMassVsPtS[ih], -1);

        pcPt_1->cd(ih+1);


        dimuonsGlobalInvMassVsPt[ih]->DrawCopy("EPLsame");

        // pp data

        TAxis *axs1   = Zmumu->GetXaxis();
        int ll        = axs1->FindBin(massCount_low);
        int hh        = axs1->FindBin(massCount_high);

        double scalefactor =  yld_cat_1[ih]/Zmumu->Integral(ll, hh);

        cout << Zmumu->Integral(ll, hh) << endl;

        Zmumu->Scale(scalefactor);

        Zmumu->SetFillColor(19);

        Zmumu->Draw("same");

        dimuonsGlobalInvMassVsPt[ih]->DrawCopy("EPLsame");

        //    dimuonsGlobalInvMassVsPt[ih]->Draw("B");

        // +++ same charge
        dimuonsGlobalInvMassVsPtS[ih]->SetMarkerStyle(8);
        dimuonsGlobalInvMassVsPtS[ih]->SetMarkerColor(46);
        dimuonsGlobalInvMassVsPtS[ih]->SetLineColor(46);

        dimuonsGlobalInvMassVsPtS[ih]->SetMarkerSize(1.1);
        dimuonsGlobalInvMassVsPtS[ih]->DrawCopy("EPsame");


        // background
        //    RBWPOL->SetLineColor(kblue);
        bkgFit_1->SetLineColor(46);
        bkgFit_1->SetLineWidth(1);
        //    if(isFit) bkgFit_1->Draw("same");

        // ++++ legend
        pLegCategory->Draw("same");


        //    legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih]," Global-Global", " ");

        legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih]," |#eta^{#mu}| < 2.4, p_{T}^{#mu} > 10 GeV/c ", "");
        legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih]," Unlike Sign ", "LP");
        legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPtS[ih]," Like Sign ", "LP");
        legend_1[ih]->AddEntry(Zmumu," pp Data ", "L");




        //    legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih], text, "");


        sprintf(szBuf, "N=%1.0f #pm %1.1f ", yld_cat_1[ih], sqrt(yld_cat_1[ih]) );

        legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih], szBuf, "");

        //    sprintf(label_1, "N_{Z^{0}} = 27");

        sprintf(szBuf, "mass = %1.2f #pm %1.2f GeV/c^{2}", RBWPOL->GetParameter(1), RBWPOL->GetParError(1));
        //    if(isFit) legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih],szBuf, "");

        sprintf(szBuf, "#sigma_{Gauss} = %1.2f #pm %1.2f GeV/c^{2}", RBWPOL->GetParameter(2), RBWPOL->GetParError(2));

        if(nFitFunction ==3 || nFitFunction  == 4)
            sprintf(szBuf, "#sigma_{Gauss} = %1.2f #pm %1.2f GeV/c^{2}", RBWPOL->GetParameter(3), RBWPOL->GetParError(3));

        //    if(isFit) legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih], szBuf, "");

        sprintf(szBuf, "#chi^{2}/ndf = %1.2f / %d", chisq, ndf);

        //    if(isFit) legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih], label_4, "");

        legend_1[ih]->Draw("same");

        pcPt_1->Update();
    }

    cout << endl << endl;


    TGraphErrors *Z0pt_cat_1 = new TGraphErrors(nBins, PT, yld_cat_1, mom_err, eyld_cat_1);
    Z0pt_cat_1->SetMarkerStyle(20);
    Z0pt_cat_1->SetMarkerColor(2);
    Z0pt_cat_1->GetXaxis()->SetTitle(label);
    Z0pt_cat_1->GetYaxis()->SetTitle("counts");

    TCanvas *pc2 = new TCanvas("pc2","pc2");
    Z0pt_cat_1->SetMinimum(0.0);
    Z0pt_cat_1->SetName("Z0pt_cat_1");
    Z0pt_cat_1->Draw("AP");


    TGraphErrors *Z0ptC_cat_1_gen = new TGraphErrors(nBins, PT, gen_pt, mom_err, egen_pt);
    //  Z0ptC_cat_1_gen->SetMarkerStyle(23);
    //Z0ptC_cat_1_gen->SetMarkerColor(3);
    //Z0ptC_cat_1_gen->Draw("AP");


    pLegCategory->Draw("same");

    Z0pt_cat_1->Write();
    pLegCategory->Write();


    //    gPad->Print("Pt_Z0YieldCat_1.png");
    pcPt_1->Print("Pt_Z0YieldCat_1.png");


    cout << endl << endl;




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

    // Efficiency correction
    if(doMc)  {
        ofstream fileout("correction.txt");
        cout << label << "   Eff_cat_1  " << endl;

        for (Int_t ih = 0; ih < nBins; ih++)  {
            Eff_cat_1[ih] = yld_cat_1[ih]/gen_pt[ih];

            errEff_cat_1[ih] = sqrt( (pow(Eff_cat_1[ih]/yld_cat_1[ih],2))*eyld_cat_1[ih]
                                     +(pow((1-Eff_cat_1[ih]/yld_cat_1[ih]),2))*( yld_cat_1[ih]-gen_pt[ih]/ yld_cat_1[ih]));
            //	  errEff_cat_1[ih] = sqrt( (pow(Eff_cat_1[ih]/yld_cat_1[ih],2))*eyld_cat_1[ih]
            //			   +(pow((1-Eff_cat_1[ih]/yld_cat_1[ih]),2))*event failing);


            //	fileout << PT[ih] <<"   "<< Eff_cat_1[ih] << "   " << Eff_cat_2[ih] <<"    " << Eff_cat_3[ih] << endl;
            //	cout <<"    " << PT[ih] <<"      "<< Eff_cat_1[ih] << "      " << Eff_cat_2[ih] << "      " << Eff_cat_3[ih] << endl;

            fileout << PT[ih] <<"   "<< Eff_cat_1[ih] << "   " << errEff_cat_1[ih] << endl;
            cout <<"    " << PT[ih] <<"    "<< Eff_cat_1[ih] << " +- " << errEff_cat_1[ih] << endl;
            cyld_cat_1[ih] = Eff_cat_1[ih];
            ceyld_cat_1[ih] = errEff_cat_1[ih];

        }
    }
    else {
        ifstream filein("correction.txt");
        cout <<  label << " yld_cat_1 "  << "  efficiency " <<  " corr. yld_cat_1  " << endl;
        for (Int_t ih = 0; ih < nBins; ih++)  {

            //      filein >> PT[ih] >>  Eff_cat_1[ih] >>  Eff_cat_2[ih]  >>  Eff_cat_3[ih] ;
            //      cout << "       " << PT[ih] << "      "<< yld_cat_1[ih] << "       " << yld_cat_2[ih] <<"      " <<  yld_cat_3[ih] << endl;

            filein >> PT[ih] >>  Eff_cat_1[ih]  >> errEff_cat_1[ih];
            cout << "    " << PT[ih] << "     " << yld_cat_1[ih] << "     " << Eff_cat_1[ih] << "     " << yld_cat_1[ih]/Eff_cat_1[ih] << endl;
            cyld_cat_1[ih] = yld_cat_1[ih]/Eff_cat_1[ih];
            ceyld_cat_1[ih] = eyld_cat_1[ih]/Eff_cat_1[ih];

        }
    }

    //  TF1 *EXPA = new TF1("EXPA", Exp, 0, 100, 2);

    TGraphErrors *Z0ptC_cat_1 = new TGraphErrors(nBins, PT, cyld_cat_1, mom_err, ceyld_cat_1);
    Z0ptC_cat_1->SetMarkerStyle(20);
    Z0ptC_cat_1->SetMarkerColor(2);
    Z0ptC_cat_1->GetXaxis()->SetTitle(label);
    Z0ptC_cat_1->GetYaxis()->SetTitle("Acc x Eff");
    //  if(part == 2) Z0ptC_cat_1->Fit("EXPA","LEQ", "", 7, 16);


    new TCanvas;
    Z0ptC_cat_1->SetMinimum(0.0);
    Z0ptC_cat_1->SetMaximum(0.8);
    Z0ptC_cat_1->SetName("Z0ptC_cat_1");
    Z0ptC_cat_1->Draw("AP");


    pLegCategory->Draw("same");

    cout << endl << endl;

    Z0ptC_cat_1->Write();

}