Example #1
0
void LHCOWriter::AnalyseJets()
{
  Jet *element;
  Track *track;
  Int_t counter;

  fItJet->Reset();
  while((element = static_cast<Jet*>(fItJet->Next())))
  {
    if(element->TauTag != 0) continue;

    Reset();

    counter = 0;
    fItTrack->Reset();
    while((track = static_cast<Track*>(fItTrack->Next())))
    {
      if(element->P4().DeltaR(track->P4()) < 0.5) ++counter;
    }

    fIntParam[1] = 4;

    fDblParam[0] = element->Eta;
    fDblParam[1] = element->Phi;
    fDblParam[2] = element->PT;
    fDblParam[3] = element->Mass;
    fDblParam[4] = counter;
    fDblParam[5] = element->BTag;
    fDblParam[6] = element->EhadOverEem;

    Write();
  }
}
Example #2
0
void LHCOWriter::AnalysePhotons()
{
  Photon *element;

  fItPhoton->Reset();
  while((element = static_cast<Photon*>(fItPhoton->Next())))
  {
    Reset();

    fIntParam[1] = 0;

    fDblParam[0] = element->Eta;
    fDblParam[1] = element->Phi;
    fDblParam[2] = element->PT;

    fDblParam[6] = element->EhadOverEem;

    Write();
  }
}
Example #3
0
void LHCOWriter::AnalyseElectrons()
{
  Electron *element;

  fItElectron->Reset();
  while((element = static_cast<Electron*>(fItElectron->Next())))
  {
    Reset();

    fIntParam[1] = 1;

    fDblParam[0] = element->Eta;
    fDblParam[1] = element->Phi;
    fDblParam[2] = element->PT;

    fDblParam[4] = element->Charge;

    fDblParam[6] = element->EhadOverEem;

    Write();
  }
}
Example #4
0
void splitws(string inFolderName, double mass, string channel) {
  cout << "Splitting workspace in " << channel << endl;

  int flatInterpCode = 4;
  int shapeInterpCode = 4;

  bool do2011 = 0;

  if (inFolderName.find("2011") != string::npos) do2011 = 1;

  bool conditionalAsimov = 0;
  bool doData = 1;
  //if (inFolderName.find("_blind_") != string::npos) {
    //conditionalAsimov = 0;
  //}
  //else {
    //conditionalAsimov = 1;
  //}

  set<string> channelNames;

  if (channel == "01j") {
    channelNames.insert("em_signalLike1_0j"+string(!do2011?"_2012":""));
    channelNames.insert("em_signalLike2_0j"+string(!do2011?"_2012":""));
    channelNames.insert("me_signalLike1_0j"+string(!do2011?"_2012":""));
    channelNames.insert("me_signalLike2_0j"+string(!do2011?"_2012":""));
    channelNames.insert("SF_AfrecSR_0j"+string(!do2011?"_2012":""));
    channelNames.insert("SF_ASR_0j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_AfrecSR_0j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_ASR_0j"+string(!do2011?"_2012":""));
    channelNames.insert("SF_CfrecZpeak_0j"+string(!do2011?"_2012":""));
    channelNames.insert("SF_CZpeak_0j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_CfrecZpeak_0j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_CZpeak_0j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_mainControl_0j"+string(!do2011?"_2012":""));

    channelNames.insert("em_signalLike1_1j"+string(!do2011?"_2012":""));
    channelNames.insert("em_signalLike2_1j"+string(!do2011?"_2012":""));
    channelNames.insert("me_signalLike1_1j"+string(!do2011?"_2012":""));
    channelNames.insert("me_signalLike2_1j"+string(!do2011?"_2012":""));
    channelNames.insert("SF_AfrecSR_1j"+string(!do2011?"_2012":""));
    channelNames.insert("SF_ASR_1j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_AfrecSR_1j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_ASR_1j"+string(!do2011?"_2012":""));
    channelNames.insert("SF_CfrecZpeak_1j"+string(!do2011?"_2012":""));
    channelNames.insert("SF_CZpeak_1j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_CfrecZpeak_1j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_CZpeak_1j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_mainControl_1j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_topbox_1j"+string(!do2011?"_2012":""));
  }
  else if (channel == "0j") {
    channelNames.insert("em_signalLike1_0j"+string(!do2011?"_2012":""));
    channelNames.insert("em_signalLike2_0j"+string(!do2011?"_2012":""));
    channelNames.insert("me_signalLike1_0j"+string(!do2011?"_2012":""));
    channelNames.insert("me_signalLike2_0j"+string(!do2011?"_2012":""));
    channelNames.insert("SF_AfrecSR_0j"+string(!do2011?"_2012":""));
    channelNames.insert("SF_ASR_0j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_AfrecSR_0j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_ASR_0j"+string(!do2011?"_2012":""));
    channelNames.insert("SF_CfrecZpeak_0j"+string(!do2011?"_2012":""));
    channelNames.insert("SF_CZpeak_0j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_CfrecZpeak_0j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_CZpeak_0j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_mainControl_0j"+string(!do2011?"_2012":""));
  }
  else if (channel == "1j") {
    channelNames.insert("em_signalLike1_1j"+string(!do2011?"_2012":""));
    channelNames.insert("em_signalLike2_1j"+string(!do2011?"_2012":""));
    channelNames.insert("me_signalLike1_1j"+string(!do2011?"_2012":""));
    channelNames.insert("me_signalLike2_1j"+string(!do2011?"_2012":""));
    channelNames.insert("SF_AfrecSR_1j"+string(!do2011?"_2012":""));
    channelNames.insert("SF_ASR_1j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_AfrecSR_1j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_ASR_1j"+string(!do2011?"_2012":""));
    channelNames.insert("SF_CfrecZpeak_1j"+string(!do2011?"_2012":""));
    channelNames.insert("SF_CZpeak_1j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_CfrecZpeak_1j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_CZpeak_1j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_mainControl_1j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_topbox_1j"+string(!do2011?"_2012":""));
  }
  else if (channel == "OF01j") {
    channelNames.insert("em_signalLike1_0j"+string(!do2011?"_2012":""));
    channelNames.insert("em_signalLike2_0j"+string(!do2011?"_2012":""));
    channelNames.insert("me_signalLike1_0j"+string(!do2011?"_2012":""));
    channelNames.insert("me_signalLike2_0j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_mainControl_0j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_sscr_0j"+string(!do2011?"_2012":""));

    channelNames.insert("em_signalLike1_1j"+string(!do2011?"_2012":""));
    channelNames.insert("em_signalLike2_1j"+string(!do2011?"_2012":""));
    channelNames.insert("me_signalLike1_1j"+string(!do2011?"_2012":""));
    channelNames.insert("me_signalLike2_1j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_mainControl_1j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_topbox_1j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_sscr_1j"+string(!do2011?"_2012":""));
  }
  else if (channel == "OF0j") {
    channelNames.insert("em_signalLike1_0j"+string(!do2011?"_2012":""));
    channelNames.insert("em_signalLike2_0j"+string(!do2011?"_2012":""));
    channelNames.insert("me_signalLike1_0j"+string(!do2011?"_2012":""));
    channelNames.insert("me_signalLike2_0j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_mainControl_0j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_sscr_0j"+string(!do2011?"_2012":""));
  }
  else if (channel == "OF1j") {
    channelNames.insert("em_signalLike1_1j"+string(!do2011?"_2012":""));
    channelNames.insert("em_signalLike2_1j"+string(!do2011?"_2012":""));
    channelNames.insert("me_signalLike1_1j"+string(!do2011?"_2012":""));
    channelNames.insert("me_signalLike2_1j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_mainControl_1j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_topbox_1j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_sscr_1j"+string(!do2011?"_2012":""));
  }
  else if (channel == "SF01j") {
    channelNames.insert("SF_AfrecSR_0j"+string(!do2011?"_2012":""));
    channelNames.insert("SF_ASR_0j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_AfrecSR_0j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_ASR_0j"+string(!do2011?"_2012":""));
    channelNames.insert("SF_CfrecZpeak_0j"+string(!do2011?"_2012":""));
    channelNames.insert("SF_CZpeak_0j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_CfrecZpeak_0j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_CZpeak_0j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_mainControl_0j"+string(!do2011?"_2012":""));

    channelNames.insert("SF_AfrecSR_1j"+string(!do2011?"_2012":""));
    channelNames.insert("SF_ASR_1j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_AfrecSR_1j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_ASR_1j"+string(!do2011?"_2012":""));
    channelNames.insert("SF_CfrecZpeak_1j"+string(!do2011?"_2012":""));
    channelNames.insert("SF_CZpeak_1j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_CfrecZpeak_1j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_CZpeak_1j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_mainControl_1j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_topbox_1j"+string(!do2011?"_2012":""));
  }
  else if (channel == "SF0j") {
    channelNames.insert("SF_AfrecSR_0j"+string(!do2011?"_2012":""));
    channelNames.insert("SF_ASR_0j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_AfrecSR_0j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_ASR_0j"+string(!do2011?"_2012":""));
    channelNames.insert("SF_CfrecZpeak_0j"+string(!do2011?"_2012":""));
    channelNames.insert("SF_CZpeak_0j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_CfrecZpeak_0j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_CZpeak_0j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_mainControl_0j"+string(!do2011?"_2012":""));
  }
  else if (channel == "SF1j") {
    channelNames.insert("SF_AfrecSR_1j"+string(!do2011?"_2012":""));
    channelNames.insert("SF_ASR_1j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_AfrecSR_1j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_ASR_1j"+string(!do2011?"_2012":""));
    channelNames.insert("SF_CfrecZpeak_1j"+string(!do2011?"_2012":""));
    channelNames.insert("SF_CZpeak_1j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_CfrecZpeak_1j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_CZpeak_1j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_mainControl_1j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_topbox_1j"+string(!do2011?"_2012":""));
  }
  else if (channel == "2j") {
    channelNames.insert("em_signalLike1_2j"+string(!do2011?"_2012":""));
    channelNames.insert("ee_signalLike1_2j"+string(!do2011?"_2012":""));
    channelNames.insert("SF_topbox_2j"+string(!do2011?"_2012":""));
  }
  else if (channel == "OF2j") {
    channelNames.insert("em_signalLike1_2j"+string(!do2011?"_2012":""));
    channelNames.insert("SF_topbox_2j"+string(!do2011?"_2012":""));
  }
  else if (channel == "SF2j") {
    channelNames.insert("ee_signalLike1_2j"+string(!do2011?"_2012":""));
    channelNames.insert("SF_topbox_2j"+string(!do2011?"_2012":""));
  }
  else if (channel == "OF") {
    channelNames.insert("em_signalLike1_0j"+string(!do2011?"_2012":""));
    channelNames.insert("em_signalLike2_0j"+string(!do2011?"_2012":""));
    channelNames.insert("me_signalLike1_0j"+string(!do2011?"_2012":""));
    channelNames.insert("me_signalLike2_0j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_mainControl_0j"+string(!do2011?"_2012":""));

    channelNames.insert("em_signalLike1_1j"+string(!do2011?"_2012":""));
    channelNames.insert("em_signalLike2_1j"+string(!do2011?"_2012":""));
    channelNames.insert("me_signalLike1_1j"+string(!do2011?"_2012":""));
    channelNames.insert("me_signalLike2_1j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_mainControl_1j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_topbox_1j"+string(!do2011?"_2012":""));

    channelNames.insert("em_signalLike1_2j"+string(!do2011?"_2012":""));
    channelNames.insert("SF_topbox_2j"+string(!do2011?"_2012":""));
  }
  else if (channel == "SF") {
    channelNames.insert("SF_AfrecSR_0j"+string(!do2011?"_2012":""));
    channelNames.insert("SF_ASR_0j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_AfrecSR_0j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_ASR_0j"+string(!do2011?"_2012":""));
    channelNames.insert("SF_CfrecZpeak_0j"+string(!do2011?"_2012":""));
    channelNames.insert("SF_CZpeak_0j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_CfrecZpeak_0j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_CZpeak_0j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_mainControl_0j"+string(!do2011?"_2012":""));

    channelNames.insert("SF_AfrecSR_1j"+string(!do2011?"_2012":""));
    channelNames.insert("SF_ASR_1j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_AfrecSR_1j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_ASR_1j"+string(!do2011?"_2012":""));
    channelNames.insert("SF_CfrecZpeak_1j"+string(!do2011?"_2012":""));
    channelNames.insert("SF_CZpeak_1j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_CfrecZpeak_1j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_CZpeak_1j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_mainControl_1j"+string(!do2011?"_2012":""));
    channelNames.insert("OF_topbox_1j"+string(!do2011?"_2012":""));

    channelNames.insert("ee_signalLike1_2j"+string(!do2011?"_2012":""));
    channelNames.insert("SF_topbox_2j"+string(!do2011?"_2012":""));
  }
  else {
    cout << "Channel " << channel << " not defined. Please check!" << endl;
    exit(1);
  }

  // bool fix = 1;
  stringstream inFileName;

  inFileName << "workspaces/" << inFolderName << "/" << mass << ".root";
  TFile f(inFileName.str().c_str());
  
  RooWorkspace* w = (RooWorkspace*)f.Get("combWS");
  if (!w) w = (RooWorkspace*)f.Get("combined");
  
  RooDataSet* data = (RooDataSet*)w->data("combData");
  if (!data) data = (RooDataSet*)w->data("obsData");
  
  ModelConfig* mc = (ModelConfig*)w->obj("ModelConfig");
  
  RooRealVar* weightVar = w->var("weightVar");
  
  RooRealVar* mu = (RooRealVar*)mc->GetParametersOfInterest()->first();
  if (!mu) mu = w->var("SigXsecOverSM");

  const RooArgSet* mc_obs = mc->GetObservables();
  const RooArgSet* mc_nuis = mc->GetNuisanceParameters();
  const RooArgSet* mc_globs = mc->GetGlobalObservables();
  const RooArgSet* mc_poi = mc->GetParametersOfInterest();

  RooArgSet nuis = *mc_nuis;
  RooArgSet antiNuis = *mc_nuis;

  RooArgSet globs = *mc_globs;
  RooArgSet antiGlobs = *mc_globs;

  RooArgSet allParams;

  RooSimultaneous* simPdf = (RooSimultaneous*)mc->GetPdf();
  RooCategory* cat = (RooCategory*)&simPdf->indexCat();

  RooArgSet nuis_tmp = nuis;
  RooArgSet fullConstraints = *simPdf->getAllConstraints(*mc_obs,nuis_tmp,false);

  vector<string> foundChannels;
  vector<string> skippedChannels;  

  cout << "Getting constraints" << endl;
  map<string, RooDataSet*> data_map;
  map<string, RooAbsPdf*> pdf_map;
  RooCategory* decCat = new RooCategory("dec_channel","dec_channel");
  // int i = 0;
  TIterator* catItr = cat->typeIterator();
  RooCatType* type;
  RooArgSet allConstraints;
  while ((type = (RooCatType*)catItr->Next())) {
    RooAbsPdf* pdf =  simPdf->getPdf(type->GetName());

    string typeName(type->GetName());
    if (channelNames.size() && channelNames.find(typeName) == channelNames.end())  {
      skippedChannels.push_back(typeName);
      continue;
    }
    cout << "On channel " << type->GetName() << endl;
    foundChannels.push_back(typeName);

    decCat->defineType(type->GetName());
    // pdf->getParameters(*data)->Print("v");

    RooArgSet nuis_tmp1 = nuis;
    RooArgSet nuis_tmp2 = nuis;
    RooArgSet* constraints = pdf->getAllConstraints(*mc_obs, nuis_tmp1, true);
    constraints->Print();
    allConstraints.add(*constraints);
  }

  catItr->Reset();

  while ((type = (RooCatType*)catItr->Next())) {
    RooAbsPdf* pdf =  simPdf->getPdf(type->GetName());

    string typeName(type->GetName());
    cout << "Considering type " << typeName << endl;
    if (channelNames.size() && channelNames.find(typeName) == channelNames.end()) continue;
    cout << "On channel " << type->GetName() << endl;

    RooArgSet nuis_tmp1 = nuis;
    RooArgSet nuis_tmp2 = nuis;
    RooArgSet* constraints = pdf->getAllConstraints(*mc_obs, nuis_tmp1, true);

    cout << "Adding pdf to map: " << typeName << " = " << pdf->GetName() << endl;
    pdf_map[typeName] = pdf;

    RooProdPdf prod("prod","prod",*constraints);

    RooArgSet* params = pdf->getParameters(*data);
    antiNuis.remove(*params);
    antiGlobs.remove(*params);

    allParams.add(*params);
    // cout << type->GetName() << endl;
  }
  // return;

  RooArgSet decNuis;
  TIterator* nuiItr = mc_nuis->createIterator();
  TIterator* parItr = allParams.createIterator();
  RooAbsArg* nui, *par;
  while ((par = (RooAbsArg*)parItr->Next())) {
    nuiItr->Reset();
    while ((nui = (RooAbsArg*)nuiItr->Next())) {
      if (par == nui) decNuis.add(*nui);
    }
  }

  RooArgSet decGlobs;
  TIterator* globItr = mc_globs->createIterator();
  parItr->Reset();
  RooAbsArg* glob;
  while ((par = (RooAbsArg*)parItr->Next())) {
    globItr->Reset();
    while ((glob = (RooAbsArg*)globItr->Next())) {
      if (par == glob) decGlobs.add(*glob);
    }
  }

  // antiNuis.Print();

  // nuis.Print();
  // globs.Print();

  // i = 0;
  TList* datalist = data->split(*cat, true);
  TIterator* dataItr = datalist->MakeIterator();
  RooAbsData* ds;
  while ((ds = (RooAbsData*)dataItr->Next())) {
    string typeName(ds->GetName());
    if (channelNames.size() && channelNames.find(typeName) == channelNames.end()) continue;

    cout << "Adding dataset to map: " << ds->GetName() << endl;
    data_map[string(ds->GetName())] = (RooDataSet*)ds;

    cout << ds->GetName() << endl;
  }

  RooSimultaneous* decPdf = new RooSimultaneous("decPdf","decPdf",pdf_map,*decCat); 
  RooArgSet decObs = *decPdf->getObservables(data);
  // decObs.add(*(RooAbsArg*)weightVar);
  decObs.add(*(RooAbsArg*)decCat);
  decObs.Print();

  nuis.remove(antiNuis);
  globs.remove(antiGlobs);
  // nuis.Print("v");

  RooDataSet* decData = new RooDataSet("obsData","obsData",RooArgSet(decObs,*(RooAbsArg*)weightVar),Index(*decCat),Import(data_map),WeightVar(*weightVar));

  decData->Print();

  RooArgSet poi(*(RooAbsArg*)mu);
  RooWorkspace decWS("combined");
  ModelConfig decMC("ModelConfig",&decWS);
  decMC.SetPdf(*decPdf);
  decMC.SetObservables(decObs);
  decMC.SetNuisanceParameters(decNuis);
  decMC.SetGlobalObservables(decGlobs);
  decMC.SetParametersOfInterest(poi);

  decMC.Print();
  decWS.import(*decPdf);
  decWS.import(decMC);
  decWS.import(*decData);
  // decWS.Print();

  ModelConfig* mcInWs = (ModelConfig*)decWS.obj("ModelConfig");
  decPdf = (RooSimultaneous*)mcInWs->GetPdf();

  // setup(mcInWs);
  // return;

  mcInWs->GetNuisanceParameters()->Print("v");
  mcInWs->GetGlobalObservables()->Print("v");
  // decData->tree()->Scan("*");

  // Make asimov data
  RooArgSet funcs = decWS.allFunctions();
  TIterator* it = funcs.createIterator();
  TObject* tempObj = 0;
  while((tempObj=it->Next()))
  {
    FlexibleInterpVar* flex = dynamic_cast<FlexibleInterpVar*>(tempObj);
    if(flex) {
      flex->setAllInterpCodes(flatInterpCode);
    }
    PiecewiseInterpolation* piece = dynamic_cast<PiecewiseInterpolation*>(tempObj);
    if(piece) {
      piece->setAllInterpCodes(shapeInterpCode);
    }
  }

  RooDataSet* dataInWs = (RooDataSet*)decWS.data("obsData");
  makeAsimovData(mcInWs, conditionalAsimov && doData, &decWS, mcInWs->GetPdf(), dataInWs, 0);
  makeAsimovData(mcInWs, conditionalAsimov && doData, &decWS, mcInWs->GetPdf(), dataInWs, 1);
  makeAsimovData(mcInWs, conditionalAsimov && doData, &decWS, mcInWs->GetPdf(), dataInWs, 2);

  system(("mkdir -vp workspaces/"+inFolderName+"_"+channel).c_str());
  stringstream outFileName;
  outFileName << "workspaces/" << inFolderName << "_" << channel << "/" << mass << ".root";
  cout << "Exporting" << endl;

  decWS.writeToFile(outFileName.str().c_str());

  cout << "\nIncluded the following channels: " << endl;
  for (int i=0;i<(int)foundChannels.size();i++) {
    cout << "-> " << foundChannels[i] << endl;
  }

  cout << "\nSkipping the following channels: " << endl;
  
  for (int i=0;i<(int)skippedChannels.size();i++) {
    cout << "-> " << skippedChannels[i] << endl;
  }

  cout << "Done" << endl;

  // decPdf->fitTo(*decData, Hesse(0), Minos(0), PrintLevel(0));
}
int main(int argc, char *argv[])
{
  // Declaration of variables
  ExRootConfReader *confReader = 0;
  Delphes *modularDelphes = 0;
  DelphesFactory *factory = 0;
  TObjArray *allParticleOutputArray = 0;
  TObjArray *stableParticleOutputArray = 0;
  TObjArray *partonOutputArray = 0;

  Int_t event;

  TObjArray *inputArray = 0;
  TIterator *inputIterator = 0;
  Candidate *candidate = 0;
  TLorentzVector momentum;

  JetDefinition *definition = 0;
  vector<PseudoJet> inputList, outputList;
  PseudoJet jet;

  gROOT->SetBatch();

  int appargc = 1;
  char appName[] = "ExternalFastJetBasic";
  char *appargv[] = {appName};
  TApplication app(appName, &appargc, appargv);

  if(argc != 2)
  {
    cout << " Usage: " << appName << " config_file" << endl;
    cout << " config_file - configuration file in Tcl format." << endl;
    return 1;
  }

  try
  {
    // Initialization
    confReader = new ExRootConfReader;
    confReader->ReadFile(argv[1]);

    modularDelphes = new Delphes("Delphes");
    modularDelphes->SetConfReader(confReader);

    factory = modularDelphes->GetFactory();

    allParticleOutputArray = modularDelphes->ExportArray("allParticles");
    stableParticleOutputArray = modularDelphes->ExportArray("stableParticles");
    partonOutputArray = modularDelphes->ExportArray("partons");

    modularDelphes->InitTask();

    
    // fastjet definition
    ClusterSequence::print_banner();
    definition = new JetDefinition(antikt_algorithm, 0.5);
    
    // Define your input candidates to fastjet (by default particle-flow objects).
    // If you want pure calorimeter towers change "EFlowMerger/eflow" into "Calorimeter/towers":
     
    inputArray = modularDelphes->ImportArray("EFlowMerger/eflow");
      
    inputIterator = inputArray->MakeIterator();

    // Event loop
    for(event = 0; event < NEVENTS; ++event)
    {
      modularDelphes->Clear();
      
      // convert EVENT input array into Delphes internal format
      ConvertInput(event, factory, allParticleOutputArray, stableParticleOutputArray, partonOutputArray);
      
      // run Delphes reconstruction
      modularDelphes->ProcessTask();

      inputList.clear();
      inputIterator->Reset();
      
      
      // pass delphes candidates to fastjet clustering  
      while((candidate = static_cast<Candidate*>(inputIterator->Next())))
      {
        momentum = candidate->Momentum;
        jet = PseudoJet(momentum.Px(), momentum.Py(), momentum.Pz(), momentum.E());
        inputList.push_back(jet);
      }
     
      // run clustering 
      ClusterSequence sequence(inputList, *definition);
      outputList.clear();
      outputList = sorted_by_pt(sequence.inclusive_jets(0.0));

      // tell the user what was done
      //  - the description of the algorithm used
      //  - show the inclusive jets as
      //      {index, rapidity, phi, pt}
      //----------------------------------------------------------
      cout << "Ran " << definition->description() << endl;

      // label the columns
      printf("%5s %15s %15s %15s\n","jet #", "rapidity", "phi", "pt");

      // print out the details for each jet
      for (unsigned int i = 0; i < outputList.size(); i++) {
        printf("%5u %15.8f %15.8f %15.8f\n",
               i, outputList[i].rap(), outputList[i].phi(),
               outputList[i].perp());
      }
    }

    // Finalization
    modularDelphes->FinishTask();
    delete modularDelphes;
    delete confReader;
    return 0;
  }
  catch(runtime_error &e)
  {
    cerr << "** ERROR: " << e.what() << endl;
    return 1;
  }
}
Example #6
0
void fit_mass(TString fileN="") {//suffix added before file extension, e.g., '.pdf'
  TString placeholder;//to add strings before using them, e.g., for saving text files
  gROOT->SetBatch(kTRUE);
  gROOT->ProcessLine(".x /afs/cern.ch/user/m/mwilkins/cmtuser/src/lhcbStyle.C");
  
  // gStyle->SetPadTickX(1);
  // gStyle->SetPadTickY(1);
  // gStyle->SetPadLeftMargin(0.15);
  // gStyle->SetTextSize(0.3);

  // //open file and get histogram
  // TFile *inHistos = new TFile("/afs/cern.ch/work/m/mwilkins/Lb2JpsiLtr/data/histos_data.root", "READ");
  // TH1F * h100 = (TH1F*)inHistos->Get("h70");
  // cout<<"data histogram gotten"<<endl;
  //unbinned
  TFile *hastree = new TFile("/afs/cern.ch/work/m/mwilkins/Lb2JpsiLtr/data/cutfile_Optimized.root", "READ");
  TTree * h100 = (TTree*)hastree->Get("mytree");
  cout<<"tree gotten"<<endl;
  TFile *SMChistos= new TFile("/afs/cern.ch/work/m/mwilkins/Lb2JpsiLtr/MC/withKScut/histos_SMCfile_fullMC.root", "READ");
  cout<<"SMC file opened"<<endl;
  TH1F *SMCh = (TH1F*)SMChistos->Get("h00");
  cout<<"SMC hist gotten"<<endl;

  RooRealVar *mass = new RooRealVar("Bs_LOKI_MASS_JpsiConstr","m(J/#psi #Lambda)",4100,6100,"MeV");
  mass->setRange("bkg1",4300,4800);
  mass->setRange("bkg2",5700,5950);
  mass->setRange("bkg3",4300,5500);
  mass->setRange("bkg4",5100,5500);
  mass->setRange("L",5350,5950);
  mass->setRange("tot",4300,5950);
  cout<<"mass declared"<<endl;
  // RooDataHist *data = new RooDataHist("data","1D",RooArgList(*mass),h100);
  //unbinned
  RooDataSet *data = new RooDataSet("data","1D",h100,*mass);
  cout<<"data declared"<<endl;

  RooDataHist *SMC = new RooDataHist("SMC","1D",RooArgList(*mass),SMCh);
  cout<<"SMC hist assigned to RooDataHist"<<endl;
  
  // Construct Pdf Model
  // /\0
  //gaussian
  RooRealVar mean1L("mean1L","/\\ gaus 1: mean",5621.103095,5525,5700);
  RooRealVar sig1L("sig1L","/\\ gaus 1: sigma",6.898126,0,100);
  RooGaussian gau1L("gau1L","#Lambda signal: gaussian 1",*mass,mean1L,sig1L);
  RooFormulaVar mean2L("mean2L","@0",mean1L);
  RooRealVar sig2L("sig2L","/\\ gaus 2: sigma",14.693117,0,100);
  RooGaussian gau2L("gau2L","#Lambda signal: gaussian 2",*mass,mean2L,sig2L);
  RooRealVar f1L("f1L","/\\ signal: fraction gaussian 1",0.748776,0,1);
  RooAddPdf sigL("sigL","#Lambda signal",RooArgList(gau1L,gau2L),RooArgList(f1L));
  // //CB
  // RooRealVar mean3L("mean3L","/\\ CB: mean",5621.001,5525,5700);
  // RooRealVar sig3L("sig3L","/\\ CB: sigma",5.161,0,100);
  // RooRealVar alphaL3("alphaL3","/\\ CB: alpha",2.077,0,1000);
  // RooRealVar nL3("nL1","/\\ CB: n",0.286,0,1000);
  // RooCBShape CBL("CBL","#Lambda signal: CB",*mass,mean3L,sig3L,alphaL3,nL3);
  // RooRealVar mean4L("mean4L","/\\ gaus: mean",5621.804,5525,5700);
  // RooRealVar sig4L("sig4L","/\\ gaus: sigma",10.819,0,100);
  // RooGaussian gauL("gauL","#Lambda signal: gaussian",*mass,mean4L,sig4L);
  // RooRealVar f1L("f1L","/\\ signal: fraction CB",0.578,0,1);
  // RooAddPdf sigL("sigL","#Lambda signal",RooArgList(CBL,gauL),RooArgList(f1L));

  // sigma0
  //using RooHistPdf from MC--no need to build pdf here
  RooHistPdf sigS = makeroohistpdf(SMC,mass,"sigS","#Sigma^{0} signal (RooHistPdf)");
  // /\*
  cout<<"Lst stuff"<<endl;
  RooRealVar meanLst1("meanLst1","/\\*(misc.): mean1",5011.031237,4900,5100);
  RooRealVar sigLst1("sigLst1","/\\*(misc.): sigma1",70.522092,0,100);
  RooRealVar meanLst2("mean5Lst2","/\\*(1405): mean2",5245.261703,5100,5350);
  RooRealVar sigLst2("sigLst2","/\\*(1405): sigma2",64.564763,0,100);
  RooRealVar alphaLst2("alphaLst2","/\\*(1405): alpha2",29.150301);
  RooRealVar nLst2("nLst2","/\\*(1405): n2",4.615817,0,50);
  RooGaussian gauLst1("gauLst1","#Lambda*(misc.), gaus",*mass,meanLst1,sigLst1);
  RooCBShape gauLst2("gauLst2","#Lambda*(1405), CB",*mass,meanLst2,sigLst2,alphaLst2,nLst2);
  // RooRealVar fLst1("fLst1","/\\* bkg: fraction gaus 1",0.743,0,1);
  // RooAddPdf bkgLst("bkgLst","#Lambda* signal",RooArgList(gauLst1,gauLst2),RooArgList(fLst1));
  
  //Poly func BKG mass
  // RooRealVar b0("b0","Background: Chebychev b0",-1.071,-10000,10000);
  RooRealVar b1("b1","Background: Chebychev b1",-1.323004,-10,-0.00000000000000000000001);
  RooRealVar b2("b2","Background: Chebychev b2",0.145494,0,10);
  RooRealVar b3("b3","Background: Chebychev b3",-0.316,-10000,10000);
  RooRealVar b4("b4","Background: Chebychev b4",0.102,-10000,10000);
  RooRealVar b5("b5","Background: Chebychev b5",0.014,-10000,10000);
  RooRealVar b6("b6","Background: Chebychev b6",-0.015,-10000,10000);
  RooRealVar b7("b7","Background: Chebychev b7",0.012,-10000,10000);
  RooArgList bList(b1,b2);
  RooChebychev bkg("bkg","Background", *mass, bList);
  // TF1 *ep = new TF1("ep","[2]*exp([0]*x+[1]*x*x)",4300,5950);
  // ep->SetParameter(0,1);
  // ep->SetParameter(1,-1);
  // ep->SetParameter(2,2000);
  // ep->SetParName(0,"a");
  // ep->SetParName(1,"b");
  // ep->SetParName(2,"c");
  // RooRealVar a("a","Background: Coefficent of x",1,-10000,10000);
  // RooRealVar b("b","Background: Coefficent of x*x",-1,-10000,10000);
  // RooRealVar c("c","Background: Coefficent of exp()",2000,-10000,10000);
  // RooTFnPdfBinding bkg("ep","ep",ep,RooArgList(*mass,a,b));
  
  //number of each shape  
  RooRealVar nbkg("nbkg","N bkg",2165.490249,0,100000000);
  RooRealVar nsigL("nsigL","N /\\",1689.637290,0,1000000000);
  RooRealVar nsigS("nsigS","N sigma",0.000002,0,10000000000);
  RooRealVar ngauLst1("ngauLst1","N /\\*(misc.)",439.812103,0,10000000000);
  RooRealVar ngauLst2("ngauLst2","N /\\*(1405)",152.061617,0,10000000000);
  RooRealVar nbkgLst("nbkgLst","N /\\*",591.828,0,1000000000);

  //add shapes and their number to a totalPdf
  RooArgList shapes;
  RooArgList yields;
  shapes.add(sigL);    yields.add(nsigL);
  shapes.add(sigS);    yields.add(nsigS);
  // shapes.add(bkgLst);  yields.add(nbkgLst);
  shapes.add(gauLst1); yields.add(ngauLst1);
  shapes.add(gauLst2); yields.add(ngauLst2);
  shapes.add(bkg);     yields.add(nbkg);
  RooAddPdf totalPdf("totalPdf","totalPdf",shapes,yields);

  //fit the totalPdf
  RooAbsReal * nll = totalPdf.createNLL(*data,Extended(kTRUE),Range("tot"));
  RooMinuit m(*nll);
  m.setVerbose(kFALSE);
  m.migrad();
  m.minos();
  m.minos();

  //display and save information
  ofstream textfile;//create text file to hold data
  placeholder = "plots/fit"+fileN+".txt";
  textfile.open(placeholder);
  TString outputtext;//for useful text

  //plot things  
  RooPlot *framex = mass->frame();
  framex->GetYaxis()->SetTitle("Events/(5 MeV)");
  data->plotOn(framex,Name("Hist"),MarkerColor(kBlack),LineColor(kBlack),DataError(RooAbsData::SumW2));
  totalPdf.plotOn(framex,Name("curvetot"),LineColor(kBlue));
  RooArgSet* totalPdfComponents = totalPdf.getComponents();
  TIterator* itertPC = totalPdfComponents->createIterator();
  RooAddPdf* vartPC = (RooAddPdf*) itertPC->Next();
  vartPC = (RooAddPdf*) itertPC->Next();//skip totalPdf
  int i=0;//color index
  TLegend *leg = new TLegend(0.2, 0.02, .4, .42);  
  leg->SetTextSize(0.06);
  leg->AddEntry(framex->findObject("curvetot"),"Total PDF","l");
  while(vartPC){//loop over compotents of totalPdf
    TString vartPCtitle = vartPC->GetTitle();
    TIterator* itercompPars;//forward declare so it persists outside the if statement
    RooRealVar* varcompPars;
    if(!(vartPCtitle.Contains(":")||vartPCtitle.Contains("@"))){//only for non-sub-shapes
      while(i==0||i==10||i==4||i==1||i==5||(i>=10&&i<=27))i++;//avoid white and blue and black and yellow and horribleness
      RooArgSet* compPars = vartPC->getParameters(data);//set of the parameters of the component the loop is on
      itercompPars = compPars->createIterator();
      varcompPars = (RooRealVar*) itercompPars->Next();
    
      while(varcompPars){//write and print mean, sig, etc. of sub-shapes
        TString vartitle = varcompPars->GetTitle();
        double varval = varcompPars->getVal();
        TString varvalstring = Form("%f",varval);
        double hi = varcompPars->getErrorHi();
        
        TString varerrorstring = "[exact]";
        if(hi!=-1){
          double lo = varcompPars->getErrorLo();
          double varerror = TMath::Max(fabs(lo),hi);
          varerrorstring = Form("%E",varerror);
        }
        
        outputtext = vartitle+" = "+varvalstring+" +/- "+varerrorstring;
        textfile<<outputtext<<endl;
        cout<<outputtext<<endl;
        
        varcompPars = (RooRealVar*) itercompPars->Next(); 
      }
      totalPdf.plotOn(framex,Name(vartPC->GetName()),LineStyle(kDashed),LineColor(i),Components(vartPC->GetName()));
      leg->AddEntry(framex->findObject(vartPC->GetName()),vartPCtitle,"l");
    
      i++;
    }
    vartPC = (RooAddPdf*) itertPC->Next();
    itercompPars->Reset();//make sure it's ready for the next vartPC
  }
  
  // Calculate chi2/ndf
  RooArgSet *floatpar = totalPdf.getParameters(data);
  int floatpars = (floatpar->selectByAttrib("Constant",kFALSE))->getSize();
  Double_t chi2 = framex->chiSquare("curvetot","Hist",floatpars);
  TString chi2string = Form("%f",chi2);
  //create text box to list important parameters on the plot
  // TPaveText* txt = new TPaveText(0.1,0.5,0.7,0.9,"NBNDC");
  // txt->SetTextSize(0.06);
  // txt->SetTextColor(kBlack);
  // txt->SetBorderSize(0);
  // txt->SetFillColor(0);
  // txt->SetFillStyle(0);
  outputtext = "#chi^{2}/N_{DoF} = "+chi2string;
  cout<<outputtext<<endl;
  textfile<<outputtext<<endl;
  // txt->AddText(outputtext);
  
  // Print stuff
  TIterator* iteryields =  yields.createIterator();
  RooRealVar* varyields = (RooRealVar*) iteryields->Next();//only inherits things from TObject unless class specified
  vector<double> Y, E;//holds yields and associated errors
  vector<TString> YS, ES;//holds strings of the corresponding yields
  int j=0;//count vector position
  int jS=0, jL=0;//these hold the position of the S and L results;initialized in case there is no nsigS or nsigL
  while(varyields){//loop over yields
    TString varname = varyields->GetName();
    TString vartitle = varyields->GetTitle();
    double varval = varyields->getVal();
    Y.push_back(varval);
    double lo = varyields->getErrorLo();
    double hi = varyields->getErrorHi();
    E.push_back(TMath::Max(fabs(lo),hi));
    YS.push_back(Form("%f",Y[j]));
    ES.push_back(Form("%f",E[j]));
    
    if(varname=="nsigS") jS=j;
    if(varname=="nsigL") jL=j;
    
    outputtext = vartitle+" = "+YS[j]+" +/- "+ES[j];
    cout<<outputtext<<endl;
    textfile<<outputtext<<endl;
    //txt->AddText(outputtext);
    
    varyields = (RooRealVar*) iteryields->Next();
    j++;
  }
  //S/L
  double result = Y[jS]/Y[jL];
  cout<<"result declared"<<endl;
  double E_result = TMath::Abs(result)*sqrt(pow(E[jS]/Y[jS],2)+pow(E[jL]/Y[jL],2));
  cout<<"E_result declared"<<endl;
  TString resultstring = Form("%E",result);
  TString E_resultstring = Form("%E",E_result);
  outputtext = "Y_{#Sigma^{0}}/Y_{#Lambda} = "+resultstring+" +/- "+E_resultstring;
  cout<<outputtext<<endl;
  textfile<<outputtext<<endl;
  //txt->AddText(outputtext);
  double resultlimit = (Y[jS]+E[jS])/(Y[jL]-E[jL]);
  outputtext = Form("%E",resultlimit);
  outputtext = "limit = "+outputtext;
  cout<<outputtext<<endl;
  textfile<<outputtext<<endl;
  //txt->AddText(outputtext);
  
  // Create canvas and pads, set style
  TCanvas *c1 = new TCanvas("c1","data fits",1200,800);
  TPad *pad1 = new TPad("pad1","pad1",0.0,0.3,1.0,1.0);
  TPad *pad2 = new TPad("pad2","pad2",0.0,0.0,1.0,0.3);
  pad1->SetBottomMargin(0);
  pad2->SetTopMargin(0);
  pad2->SetBottomMargin(0.5);
  pad2->SetBorderMode(0);
  pad1->SetBorderMode(0);
  c1->SetBorderMode(0);
  pad2->Draw();
  pad1->Draw();
  pad1->cd();
  framex->SetMinimum(1);
  framex->SetMaximum(3000);
  
  framex->addObject(leg);//add legend to frame
  //framex->addObject(txt);//add text to frame

  gPad->SetTopMargin(0.06);
  pad1->SetLogy();
  // pad1->Range(4100,0,6100,0.0005);
  pad1->Update();
  framex->Draw();

  // Pull distribution
  RooPlot *framex2 = mass->frame();
  RooHist* hpull = framex->pullHist("Hist","curvetot");
  framex2->addPlotable(hpull,"P");
  hpull->SetLineColor(kBlack);
  hpull->SetMarkerColor(kBlack);
  framex2->SetTitle(0);
  framex2->GetYaxis()->SetTitle("Pull");
  framex2->GetYaxis()->SetTitleSize(0.15);
  framex2->GetYaxis()->SetLabelSize(0.15);
  framex2->GetXaxis()->SetTitleSize(0.2);
  framex2->GetXaxis()->SetLabelSize(0.15);
  framex2->GetYaxis()->CenterTitle();
  framex2->GetYaxis()->SetTitleOffset(0.45);
  framex2->GetXaxis()->SetTitleOffset(1.1);
  framex2->GetYaxis()->SetNdivisions(505);
  framex2->GetYaxis()->SetRangeUser(-8.8,8.8);
  pad2->cd();
  framex2->Draw();

  c1->cd();

  placeholder = "plots/fit"+fileN+".eps";
  c1->Print(placeholder);
  placeholder = "plots/fit"+fileN+".C";
  c1->SaveAs(placeholder);
  textfile.close();
}
int main(int argc, char *argv[])
{
  char appName[] = "hepmc2pileup";
  stringstream message;
  FILE *inputFile = 0;
  DelphesFactory *factory = 0;
  TObjArray *stableParticleOutputArray = 0, *allParticleOutputArray = 0, *partonOutputArray = 0;
  TIterator *itParticle = 0;
  Candidate *candidate = 0;
  DelphesPileUpWriter *writer = 0;
  DelphesHepMCReader *reader = 0;
  Int_t i;
  Long64_t length, eventCounter;

  if(argc < 2)
  {
    cout << " Usage: " << appName << " output_file" << " [input_file(s)]" << endl;
    cout << " output_file - output binary pile-up file," << endl;
    cout << " input_file(s) - input file(s) in HepMC format," << endl;
    cout << " with no input_file, or when input_file is -, read standard input." << endl;
    return 1;
  }

  signal(SIGINT, SignalHandler);

  gROOT->SetBatch();

  int appargc = 1;
  char *appargv[] = {appName};
  TApplication app(appName, &appargc, appargv);

  try
  {
    writer = new DelphesPileUpWriter(argv[1]);

    factory = new DelphesFactory("ObjectFactory");
    allParticleOutputArray = factory->NewPermanentArray();
    stableParticleOutputArray = factory->NewPermanentArray();
    partonOutputArray = factory->NewPermanentArray();

    itParticle = stableParticleOutputArray->MakeIterator();

    reader = new DelphesHepMCReader;

    i = 2;
    do
    {
      if(interrupted) break;

      if(i == argc || strncmp(argv[i], "-", 2) == 0)
      {
        cout << "** Reading standard input" << endl;
        inputFile = stdin;
        length = -1;
      }
      else
      {
        cout << "** Reading " << argv[i] << endl;
        inputFile = fopen(argv[i], "r");

        if(inputFile == NULL)
        {
          message << "can't open " << argv[i];
          throw runtime_error(message.str());
        }

        fseek(inputFile, 0L, SEEK_END);
        length = ftello(inputFile);
        fseek(inputFile, 0L, SEEK_SET);

        if(length <= 0)
        {
          fclose(inputFile);
          ++i;
          continue;
        }
      }

      reader->SetInputFile(inputFile);

      ExRootProgressBar progressBar(length);

      // Loop over all objects
      eventCounter = 0;
      factory->Clear();
      reader->Clear();
      while(reader->ReadBlock(factory, allParticleOutputArray,
        stableParticleOutputArray, partonOutputArray) && !interrupted)
      {
        if(reader->EventReady())
        {
          ++eventCounter;

          itParticle->Reset();
          while((candidate = static_cast<Candidate*>(itParticle->Next())))
          {
            const TLorentzVector &position = candidate->Position;
            const TLorentzVector &momentum = candidate->Momentum;
            writer->WriteParticle(candidate->PID,
              position.X(), position.Y(), position.Z(), position.T(),
              momentum.Px(), momentum.Py(), momentum.Pz(), momentum.E());
          }

          writer->WriteEntry();

          factory->Clear();
          reader->Clear();
        }
        progressBar.Update(ftello(inputFile), eventCounter);
      }

      fseek(inputFile, 0L, SEEK_END);
      progressBar.Update(ftello(inputFile), eventCounter, kTRUE);
      progressBar.Finish();

      if(inputFile != stdin) fclose(inputFile);

      ++i;
    }
    while(i < argc);

    writer->WriteIndex();

    cout << "** Exiting..." << endl;

    delete reader;
    delete factory;
    delete writer;

    return 0;
  }
  catch(runtime_error &e)
  {
    if(writer) delete writer;
    cerr << "** ERROR: " << e.what() << endl;
    return 1;
  }
}
Example #8
0
void LHCOWriter::AnalyseMuons()
{
  Muon *element;
  Track *track;
  Tower *tower;
  Jet *jet;
  Int_t muonCounter, tauCounter, jetCounter, minIndex;
  Float_t sumPT, sumET, ratET, jetDR, minDR;

  muonCounter = 0;
  fItMuon->Reset();
  while((element = static_cast<Muon*>(fItMuon->Next())))
  {
    Reset();

    sumPT = 0.0;
    fItTrack->Reset();
    while((track = static_cast<Track*>(fItTrack->Next())))
    {
      if(element->P4().DeltaR(track->P4()) < 0.5) sumPT += track->PT;
    }

    sumET = 0.0;
    fItTower->Reset();
    while((tower = static_cast<Tower*>(fItTower->Next())))
    {
      if(element->P4().DeltaR(tower->P4()) < 0.5) sumET += tower->ET;
    }

    tauCounter = 0;
    jetCounter = 0;
    minIndex = -1;
    minDR = 1.0E9;
    fItJet->Reset();
    while((jet = static_cast<Jet*>(fItJet->Next())))
    {
      if(jet->TauTag != 0)
      {
        ++tauCounter;
        continue;
      }

      jetDR = element->P4().DeltaR(jet->P4());
      if(jetDR < minDR)
      {
        minIndex = jetCounter;
        minDR = jetDR;
      }
      ++jetCounter;
    }

    fIntParam[1] = 2;

    fDblParam[0] = element->Eta;
    fDblParam[1] = element->Phi;
    fDblParam[2] = element->PT;

    fDblParam[3] = 0.11;

    fDblParam[4] = element->Charge;

    if(minIndex >= 0)
    {
      fDblParam[5] = fIntParam[0] + fBranchMuon->GetEntriesFast() - muonCounter + tauCounter + minIndex;
    }

    ratET = sumET/element->PT;
    fDblParam[6] = Float_t(TMath::Nint(sumPT)) + (ratET < 1.0 ? ratET : 0.99);

    Write();
    ++muonCounter;
  }
}
int main(int argc, char *argv[])
{
  char appName[] = "root2pileup";
  stringstream message;
  TChain *inputChain = 0;
  ExRootTreeReader *treeReader = 0;
  TClonesArray *branchParticle = 0;
  TIterator *itParticle = 0;
  GenParticle *particle = 0;
  DelphesPileUpWriter *writer = 0;
  Long64_t entry, allEntries;
  Int_t i;

  if(argc < 3)
  {
    cout << " Usage: " << appName << " output_file" << " input_file(s)" << endl;
    cout << " output_file - output binary pile-up file," << endl;
    cout << " input_file(s) - input file(s) in ROOT format." << endl;
    return 1;
  }

  signal(SIGINT, SignalHandler);

  gROOT->SetBatch();

  int appargc = 1;
  char *appargv[] = {appName};
  TApplication app(appName, &appargc, appargv);

  try
  {
    inputChain = new TChain("Delphes");
    for(i = 2; i < argc && !interrupted; ++i)
    {
      inputChain->Add(argv[i]);
    }

    treeReader = new ExRootTreeReader(inputChain);
    branchParticle = treeReader->UseBranch("Particle");
    itParticle = branchParticle->MakeIterator();

    writer = new DelphesPileUpWriter(argv[1]);

    allEntries = treeReader->GetEntries();
    cout << "** Input file(s) contain(s) " << allEntries << " events" << endl;

    if(allEntries > 0)
    {
      ExRootProgressBar progressBar(allEntries - 1);
      // Loop over all events in the input file
      for(entry = 0; entry < allEntries && !interrupted; ++entry)
      {
        if(!treeReader->ReadEntry(entry))
        {
          cerr << "** ERROR: cannot read event " << entry << endl;
          break;
        }

        itParticle->Reset();
        while((particle = static_cast<GenParticle*>(itParticle->Next())))
        {
          writer->WriteParticle(particle->PID,
            particle->X, particle->Y, particle->Z, particle->T,
            particle->Px, particle->Py, particle->Pz, particle->E);
        }
        
        writer->WriteEntry();

        progressBar.Update(entry);
      }
      progressBar.Finish();

      writer->WriteIndex();
    }

    cout << "** Exiting..." << endl;

    delete writer;
    delete itParticle;
    delete treeReader;
    delete inputChain;
    return 0;
  }
  catch(runtime_error &e)
  {
    if(writer) delete writer;
    if(itParticle) delete itParticle;
    if(treeReader) delete treeReader;
    if(inputChain) delete inputChain;
    cerr << "** ERROR: " << e.what() << endl;
    return 1;
  }
}
Example #10
0
Int_t EventCount(TString inputlist, TString outfile, Int_t nev=-1)
{  

  HLoop* loop = new HLoop   (kTRUE    );  // kTRUE : create Hades  (needed to work with standard eventstructure)
         loop ->addMultFiles(inputlist);

//-----Inicialize-classes-we-need-to-use-----------------
  PidParticle p;
  dEdx        d;
  HMultCorr   cCorr;
//-------------------------------------------------------

//--------------------------------------------------------------------------------------------------------
#include "/u/parfenov/anaflow/EventCountVar.h"     //include all constants and variables we need          
#include "/u/parfenov/anaflow/outsigma.C"          //Declaration of the 3-sigma cuts for our pt & rapidity
TH2F*  hProtPtVsY_Eff;
TFile* foutfile       = new TFile(outfile.Data(), "recreate"); 
TFile* FileProtEff    = new TFile("EffCorrForProtPtVsY_WithWideBetaPcuts_ShieldGosia.root", "read");
       hProtPtVsY_Eff = (TH2F*) FileProtEff->Get("hProtPtVsY_EffSm");
       foutfile->cd();

#include "/u/parfenov/anaflow/EventCountHisto.h"   //include all histograms we need                       

FFlow pfy0pt[NC][NRAPI][NPTRN]; //--flow--9-bins-Yo--12-bins-in-Pt-in-3-centrality-sets--
  for (Int_t i=0; i<NC;i++){
   for(Int_t j=0; j<NRAPI; j++){
     for(Int_t k=0; k<NPTRN; k++){
       //-proton------------------------------------------
       pfy0pt[i][j][k].THDeclare("pCent",i,"Yo",j,"Pt",k);
     }
   }
  }
//--------------------------------------------------------------------------------------------------------

  if(!loop->setInput("-*,+HParticleCand,+HParticleEvtInfo,+HStart2Hit,+HStart2Cal,+HWallHit,+HRpcCluster,+HTofHit,+HWallEventPlane")) { exit(1); }
  loop->printCategories();
  
  TIterator* iterWallHit = 0;
  if (loop->getCategory("HWallHit")  ) iterWallHit   = loop->getCategory("HWallHit")->MakeIterator();
  
  HParticleEvtInfo* evtinfo;
  
  HParticleCand* pParticleCand; HCategory* candCat = (HCategory*)HCategoryManager::getCategory(catParticleCand); if(!candCat){exit(1);}
  HWallHit*      pWallHit;      HCategory* wallCat = (HCategory*)HCategoryManager::getCategory(catWallHit);      if(!wallCat){exit(1);}

  HEnergyLossCorrPar *momCorPar = new HEnergyLossCorrPar();
  momCorPar->setDefaultPar("apr12");
      
  /////////////////////////////////////////////////////////
  //-----Loop-over-events----------------------------------
  /////////////////////////////////////////////////////////
  
  loop->addMultFiles(inputlist);

  Int_t events = loop->getEntries();
  if(nev < events && nev >= 0 ) events = nev;
  
  for (Int_t i=1; i<events;i++){
    
    if (loop->nextEvent(i)<=0){
      cout << "End recieved with IF exit" << endl;
      break;
    }
    if (i%1000 == 0){
      cout << "    event " << i << endl;
    }
    
    if( loop->isNewFile(currFName) ){ 
        currFName = currFName( currFName.Last('/')+1,currFName.Length()-currFName.Last('/')-1 );
        currBeName = currFName(0, 13); //-simply-the-file-name-w/o-EBchunk--
        currFDay = currFName( 4, 3 ); //-we-cut-out-day-number-position-starting-from-4th-digit-with-length-of-3digits--
        DAY_NUM = currFDay.Atoi();
        currTime = currFName( 7, 2 ); //-we-cut-out-day-hour--position-starting-from-4th-digit-with-length-of-3digits--
        HR=currTime.Atoi();
        currTime = currFName( 9, 2 ); //-we-cut-out-day-minute-position-starting-from-4th-digit-with-length-of-3digits--
        MN=currTime.Atoi();
        currTime = currFName(11, 2 ); //-we-cut-out-day-second-position-starting-from-4th-digit-with-length-of-3digits--
        SC=currTime.Atoi();
        AbsMinute = MN + HR*60 + DAY_NUM*24*60;

        #include "/u/parfenov/anaflow/anaKaons_params_gen7_Auto_RC_RW_updated_gen108RminEqZero_11MultRecent.cc" //-for recentering---

        //--Now-we-read-multiplicity-parameters-for-this-beXXXXXXXXXX-file--------------------//
        mulVal = cCorr.getLineValuesAsVectFromCalibFile( currBeName );
        cout<<"mulVal "<< mulVal[0] <<" "<< mulVal[1] <<" "<< mulVal[2] <<" "<< mulVal[3] <<endl;
        fAverageMTS[0]=mulVal[4];  //multiplicity in tracking sector 1
        fAverageMTS[1]=mulVal[5];  //multiplicity in tracking sector 2
        fAverageMTS[2]=mulVal[6];  //...
        fAverageMTS[3]=mulVal[7];
        fAverageMTS[4]=mulVal[8];
        fAverageMTS[5]=mulVal[9];  //multiplicity in tracking sector 6
        printf("fAverageMTS[0,1,2,3,4,5]=[%6.3f,%6.3f,%6.3f,%6.3f,%6.3f,%6.3f,]\n", fAverageMTS[0], fAverageMTS[1], fAverageMTS[2], fAverageMTS[3], fAverageMTS[4], fAverageMTS[5]);
        
        //fTrkMultDay108
        if(mulVal[2]>0.0){
          //-if-correction-is-found-or-if-it-was-not-zero-defined-(in-case-of-not-working-MDCs)---
          fTrkMultScaler = fTrkMultDay108/mulVal[2];
          printf("==>Correction multiplier nTrkMult for this file is: (%f/%f)=%f\n", fTrkMultDay108, mulVal[2], fTrkMultScaler );
        }else{
          //--if-correction-entry-is-not-found-(may-be-not-created-once)------------------
          //--or-if-say-MDCs-were-not-working-and-tracking-multiplicity-was-exectly-zero--
          //-we-keep-correction-as-it-was-in-previous-file-or-if-not-defined-hence-it-would-be-exactly-one=1-or-
          printf("==>Correction multiplier nTrkMult for this file is: (%f/%f)=%f (default or old correction is used)\n", fTrkMultDay108, mulVal[2], fTrkMultScaler);
        }
    }

    HTool::printProgress(i,events,1,"Analyze pairs :");

    evtinfo = HCategoryManager::getObject(evtinfo,catParticleEvtInfo,0);
    
      //-------Get-vertex-from-combined-fit-of-fitted-inner-segments------------
      HVertex            fPrimVertReco = gHades->getCurrentEvent()->getHeader()->getVertexReco();
      vertexX = fPrimVertReco.getX();
      vertexY = fPrimVertReco.getY();
      vertexZ = fPrimVertReco.getZ();
      
      hvertexXZ->Fill(vertexZ,vertexX);
      hvertexXY->Fill(vertexY,vertexX);
      hvertexX ->Fill(vertexX);
      hvertexY ->Fill(vertexY);
      hvertexZ ->Fill(vertexZ);
      
      //------Alexandr's-vertex-cuts---------
      
      tgtChi2 = (Float_t) fPrimVertReco.getChi2();

      hTargChi2->Fill(tgtChi2);


      if( tgtChi2<2.0 || tgtChi2>40.) continue; //-skip-events-with-badly-reconstructed-target-------
      if( vertexZ<-59.|| vertexZ>0. ) continue; //-skip-events-with-primary-vertex-outside-of-target-

      hTargX_EVT->Fill(vertexX);
      hTargY_EVT->Fill(vertexY);
      hTargZ_EVT->Fill(vertexZ);

      if( (vertexX-tgtXc)*(vertexX-tgtXc)+(vertexY-tgtYc)*(vertexY-tgtYc)>R2 ) continue; //-skip-events-with-primary-vertex-far-from-target---
      hCutSteps->Fill(5.5);

      hTargXYsel->Fill(vertexX,vertexY);
      hTargXZsel->Fill(vertexZ,vertexX);
      //---------end-of-Alexandr's-vertex-cut--------------
      
      //------HWall-iteration------------------------------
      if (iterWallHit){
    iterWallHit->Reset();
    HWallHit* pWallHit;
        
    while ( (pWallHit = (HWallHit*)iterWallHit->Next()) != 0 ){
         
         cellNum    = pWallHit->getCell();
             cellTime   = pWallHit->getTime();
             cellCharge = pWallHit->getCharge();
             cellPhi    = pWallHit->getPhi();
         
         hWallHitTIME->Fill(cellNum-0.1, cellTime  );
         hWallHitCHRG->Fill(cellNum-0.1, cellCharge);
         
         if (cellCharge > d.dEdxCut(cellNum)/10. && cellTime > 16. && cellTime < 44.){
           hWallHitTIMEcut->Fill(cellNum-0.1, cellTime  );
           hWallHitCHRGcut->Fill(cellNum-0.1, cellCharge);
         }//end-cut
         
    }//------end-HWall-iteration-----------------------
      }//endif

    if( evtinfo->getSumParticleCandMult()<2 ) continue;  //getSumParticleCandMult()>1
      if(!evtinfo->isGoodEvent(
                               Particle::kGoodVertexClust|
                               Particle::kGoodVertexCand|
                               Particle::kNoPileUpSTART|
                               Particle::kGoodSTART|      
                               Particle::kGoodTRIGGER|    
                               Particle::kNoVETO|         
                               Particle::kGoodSTARTVETO|  
                               Particle::kGoodSTARTMETA
                              )) continue ; // bitwise add flags as suggested by Manuel 
                              
      Mtof = evtinfo->getSumTofMult();
      Mrpc = evtinfo->getSumRpcMult();
      Mult = Mtof+Mrpc;
      
      hmultTofRpc->Fill(Mult);                                   // Fill( name , weight )
      
      
      //---------centrality-classes--------------------------------------------------------------------(begin)--------//
      //-Centrality-selection-for-further-if-selection-statements------------------------//
      Int_t   nTrkMult = getParticleTrkMult();
      Mtr   = nTrkMult;
      Float_t nTrkMultCorr = nTrkMult*fTrkMultScaler;
      MtrC  = nTrkMultCorr; //-after-correction-to-average-day108--

      if( nTrkMultCorr>33 && nTrkMultCorr<=49 ){ FOPI_blue=kTRUE; }else{ FOPI_blue=kFALSE; }        // Berusz's estimate
      if( nTrkMultCorr>49 && nTrkMultCorr<=82 ){ FOPI_gren=kTRUE; }else{ FOPI_gren=kFALSE; }        // based on Glauber model
      if( nTrkMultCorr>82                     ){ FOPI_redd=kTRUE; }else{ FOPI_redd=kFALSE; }        // (lucky me, seems very similar to my naive guess!)--Alexandr-(c)--

      if( FOPI_blue ){ hPhiAB_blue->Fill(fabs(phiAB), wPhiRPA); }
      if( FOPI_gren ){ hPhiAB_gren->Fill(fabs(phiAB), wPhiRPA); }
      if( FOPI_redd ){ hPhiAB_redd->Fill(fabs(phiAB), wPhiRPA); }

      multCand = evtinfo->getSumSelectedParticleCandMult();

      hmultSumSPCand->Fill(multCand);
     
     //--------------------------------------------//
     //--Event plane reconstruction loop-----------//
     //--------------------------------------------// 
      multWall=0;
      cellNum=0;
      cellTime=0.0;
      cellCharge=0.0;
      wallX=0.0,wallY=0.0,wallZ=0.0;
      wallXc=0.0, wallYc=0.0; //corrected-reCentered-
      XfwSmear=0.0, YfwSmear=0.0;
      vect.Set(0.,0.);
      vsum.Set(0.,0.);
      eX  .Set(1.,0.);
      dEdxCut=0.0;
      xyRadius=0.0;
      
      QLx=0.0, QLy=0.0, NL=0; 
      QMx=0.0, QMy=0.0, NM=0;
      QNx=0.0, QNy=0.0, NN=0;

      for(Int_t n=0; n<6; n++){
         Qx[ n]    =0.0; Qy[ n]   =0.0;
         QxRec[n]  =0.0; QyRec[n] =0.0;
         Qax[n]    =0.0; Qay[n]   =0.0;
         Qbx[n]    =0.0; Qby[n]   =0.0;
         phiEP[ n] = -1000.;
         phiEPr[n] = 0.;
      }

      phiA   = -1000;
      phiB   = -1000;
      cellsVect.Reset();
      
      //-weight-for-scalar-product-method-------------------
      wgh = 1.0;  //PCpt; //1.0; //-or-could-be-also-equal-to-Pt---

      nFWhits   = 0;
      nFWspect  = 0;
      nFWunderflow = 0;
      FWdEdxA=0.0;
      FWdEdxB=0.0;

      FWdEdxL=0.0;
      FWdEdxM=0.0;
      FWdEdxN=0.0;

      choiceA = 1; //
      choiceB = 1; // Preparing for A/B subevent method

      //-------------------------------------------iteration-WallHits----(begin)--------------------------------------------------//
      for(Int_t j=0; j<(wallCat->getEntries()); j++){
        pWallHit = HCategoryManager::getObject(pWallHit,wallCat,j);

         cellNum    = pWallHit->getCell();
         cellTime   = pWallHit->getTime();
         cellCharge = pWallHit->getCharge();

         cellChargeCtime = cellTime;
         hFW_TimeCell_0->Fill(cellTime  , cellNum);
         hFW_dEdxCell_0->Fill(cellCharge, cellNum);

         if(cellNum< 144                ){ dEdxCut=Z1_cut_s; }
         if(cellNum>=144 && cellNum<=207){ dEdxCut=Z1_cut_m; }
         if(cellNum> 207                ){ dEdxCut=Z1_cut_l; }

         if(cellTime>T1_cut && cellTime<T2_cut && cellCharge>dEdxCut){
           
           nFWspect++;

           hFW_TimeCell_1->Fill(cellTime  , cellNum);
           hFW_dEdxCell_1->Fill(cellCharge, cellNum);

           pWallHit->getXYZLab(wallX,wallY,wallZ);
           hFWxyCC->Fill(wallX,wallY); //cell centers
           
           for (Int_t im=1;im<12;im++){
            if( (Mtof+Mrpc)>=Mrang[im-1] && (Mtof+Mrpc)<Mrang[im]){ wallXc = wallX - X_shM[12-im]; wallYc = wallY - Y_shM[12-im]; }
           }

           //-here-we-fill-d2N/(dxdy)-inX-band--and--y-band--for-auto-recentering-
           //-this-makes-realistic-distribution-on-FW-face------------------------
           if (cellNum<=143)                 { cellSize = 40;  }
           if (cellNum>=144 && cellNum<=207) { cellSize = 80;  }
           if (cellNum>=210 && cellNum<=301) { cellSize = 160; }
           XfwSmear = wallXc + ( Random.Rndm(1) - 0.5 )*cellSize;
           YfwSmear = wallYc + ( Random.Rndm(1) - 0.5 )*cellSize;

           
           for (Int_t im=0;im<8;im++){
            //-X-beam-center-scan---
            if( (Mtof+Mrpc)>=  Mcent[im] && (Mtof+Mrpc)< Mcent[im+1] ){ hFWxyCCsmearXscanM[im]->Fill(XfwSmear,YfwSmear); }
            //-Y-beam-center-scan---
            if( (Mtof+Mrpc)>=  Mcent[im] && (Mtof+Mrpc)< Mcent[im+1] ){ hFWxyCCsmearYscanM[im]->Fill(XfwSmear,YfwSmear); }
           }


           //-this-cut-was-forgotten-for-Feb2014-HADES-CM-report--//
           //-I-reintroduce-it-14.03.2014----(c)-Sadovsky---------//
           if(  wallXc*wallXc + wallYc*wallYc >= R0_cut*R0_cut  /*50.*50.*/ ){
             hFW_TimeCell_2->Fill(cellTime  , cellNum);
             hFW_dEdxCell_2->Fill(cellCharge, cellNum);


             //-spectators-selected--
             multWall++;

             vect.Set(wallXc, wallYc);
             vect =  vect.Unit();
             vsum += vect;

             //-Qnx-method--for-n=1,2,3,4,5------
             VectPhi_i = TMath::ATan2(YfwSmear,XfwSmear); //-Phi-of-i_th-spectator-particle---
             for(Int_t n=1; n<6; n++){//-loop-over-harmonics-(n)--
               Qx[n] = Qx[n] + wgh*cos(double(n)*VectPhi_i);
               Qy[n] = Qy[n] + wgh*sin(double(n)*VectPhi_i);
             }

             cellsVect.SetCellVect(vect, cellCharge); //-note-[vect]-is-a-unit-vector-this-is-for-further-subevent-(A/B)-split--


             hFWxyCCsmear->Fill(XfwSmear+X_shift,YfwSmear+Y_shift); //cells smeared but not shifted
             hFWxySHsmear->Fill(XfwSmear        ,YfwSmear        ); //cells smeared and shifted as a whole

             //-center-of-gravity-study-as-a-course-of-centrality-----------------------------
             for (Int_t im=0;im<8;im++){
              if( (Mtof+Mrpc)>=Mcent[im] && (Mtof+Mrpc)<Mcent[im+1]){ hFWxyCCsmearM[im]->Fill(XfwSmear,YfwSmear); }
             }
             
           }//-endif-R0_cut--//
           
        }//end-if-cells-cut---
     }//end-for-HitWall-loop---

     VectphiEP =  vsum.DeltaPhi(eX)   *rad2deg;
     VectphiEPr=  vsum.DeltaPhi(eX); //radians
     hPhiEPvect->Fill(VectphiEP);

     //-now-we-go-over-spectators-and-make-calculations-for-A/B-subevents
      NA=0;
      NB=0;
      multFWcells = cellsVect.GetNumbOfCells();

      Float_t choice;
      vectA.Set(0.,0.);
      vectB.Set(0.,0.);
      vsumA.Set(0.,0.);
      vsumB.Set(0.,0.);

      for(Int_t ic=0; ic<multFWcells; ic++){
        choice = Random.Rndm(1);
        //-this-is-(A/B)-subevents-split--(begin)-(c)-Sadovsky-----------------------------
        //-I-can-be-proud-that-my-algorithm-has-more-flat-distribution--:)-(c)-Sadovsky----
        levelA = (multFWcells/2.-choiceA+1.)/Float_t(multFWcells);
        levelB = (multFWcells/2.-choiceB+1.)/Float_t(multFWcells);
        if(choice < levelA/(levelA+levelB)){
           vectA = cellsVect.GetCellVector(ic);
           vsumA += vectA;
           choiceA++;
           NA++;
           vsumA += vectA;
           choiceA++;
           NA++;
           VectPhi_i = vectA.DeltaPhi(eX); //-Phi-of-i_th-spectator-particle-from-subevent-A--
           
           for(Int_t n=1; n<6; n++){//-loop-over-harmonics-(n)--
              Qax[n] = Qax[n] + wgh*cos(double(n)*VectPhi_i);
              Qay[n] = Qay[n] + wgh*sin(double(n)*VectPhi_i);
           }

           FWdEdxA=FWdEdxA + cellsVect.GetCellCharge(ic); //-total-Eloss-from-all-spectators---
           
        }else{

           vectB = cellsVect.GetCellVector(ic);
           vsumB += vectB;
           choiceB++;
           NB++;
           vectB = cellsVect.GetCellVector(ic);
           vsumB += vectB;
           choiceB++;
           NB++;
           VectPhi_i = vectB.DeltaPhi(eX); //-Phi-of-i_th-spectator-particle-from-subevent-B--
           
           for(Int_t n=1; n<6; n++){//-loop-over-harmonics-(n)--
              Qbx[n] = Qbx[n] + wgh*cos(double(n)*VectPhi_i);
              Qby[n] = Qby[n] + wgh*sin(double(n)*VectPhi_i);
           }

           FWdEdxB=FWdEdxB + cellsVect.GetCellCharge(ic); //-total-Eloss-from-all-spectators---
        }//-HWallHit-second-loop-for-reaction-plane-resolution--( end )---//
        //-this-is-(A/B)-subevents-split--( end )------------------------------------------
      }//-endfor-multFWcells-loop--for-A/B-method--

      //-calculating-eventplane-angles---------------
      phiA   = vsumA.DeltaPhi(eX)       *rad2deg;
      phiB   = vsumB.DeltaPhi(eX)       *rad2deg;
      phiAB  = vsumA.DeltaPhi(vsumB)    *rad2deg;
      Mfw = NA+NB;

      if (Mfw > 1){
        for (Int_t n=1;n<6;n++){
            QxRec[n]     = Qx[n] - MeanQx[n];
            QyRec[n]     = Qy[n] - MeanQy[n];
            phiEP[n ]    =  TMath::ATan2(Qy[n],Qx[n])/n       *rad2deg;
            phiEPr[n]    =  TMath::ATan2(Qy[n],Qx[n])/n               ;//radians
            phiEPrec[n]  =  TMath::ATan2(QyRec[n],QxRec[n])/n *rad2deg;
            hPhiEP[n-1]  -> Fill(phiEP[n]);
            hPhiEPrec[n-1]->Fill(phiEPrec[n]);
            hQvX  [n-1]  -> Fill(Qx[n]);
            hQvY  [n-1]  -> Fill(Qy[n]);
            hQvXrec[n-1] -> Fill(QxRec[n]);
            hQvYrec[n-1] -> Fill(QyRec[n]);
        }
        h0PhiEPvect->Fill(VectphiEP);
      }

      if(Mfw>=0){
        h0PhiEP->Fill(VectphiEP);
        h0PhiA ->Fill(phiA);
        h0PhiB ->Fill(phiB);
        h0PhiAB->Fill(phiAB);
      }
      //-extended-version-introduced-at-09.07.15--which-corresponds-to-META-mult-equivalent-to-numTracking-Glauber--//
      if(NA>0 && NB>0){
        hRPA->Fill(VectphiEP);
        for(Int_t im=0;im<11;im++){
            if( (Mtof+Mrpc)>=Mrang[im] && (Mtof+Mrpc)<Mrang[im+1] ){ hRPAy[im] ->Fill(VectphiEP); wPhiRPA = 1./fRPAy[im] ->Eval(VectphiEP); hRPAyc[im] ->Fill(VectphiEP,wPhiRPA); }
        }
        hRPA6Ywc->Fill(VectphiEP,wPhiRPA);
      }

      //-here-we-make-a-control-plot-for-pileup-events--//
      hMfwMmeta->Fill(Mtof+Mrpc, Mfw );
      hMfw     ->Fill(           Mfw );
      hMmeta   ->Fill(Mtof+Mrpc      );
      hMtof    ->Fill(           Mtof);
      hMrpc    ->Fill(           Mrpc);
      
      //-------------------------------------------iteration-WallHits----( end )--------------------------------------------------//


      ////////////////////////////////////////////
      //----getting-ready-to-loop-over-tracks---//
      ////////////////////////////////////////////
                     size = candCat->getEntries();
      Bool_t pimFlag[size];    // pi-
      Bool_t pipFlag[size];    // pi+
      Bool_t proFlag[size];    // proton
      Bool_t kapFlag[size];    // K+ meson        
      
      //note-new-event----------------------------
      for (Int_t icent=0;icent<NC;icent++){
        for (Int_t irpi=0;irpi<NRAPI;irpi++){
            for (Int_t ipt=0;ipt<NPTRN;ipt++){
                pfy0pt[icent][irpi][ipt].NewEvt();
            }
        }
      }   
      
      /////////////////////////////////////////////////////
      //--------Now-lets-try-to-get-tracks-----------------
      /////////////////////////////////////////////////////
      for(Int_t j=0;j<size;j++){
    
    pimFlag[j] = kFALSE;
    pipFlag[j] = kFALSE;
    proFlag[j] = kFALSE;
    kapFlag[j] = kFALSE;
        
    hEntries->Fill(size);
    
    pParticleCand = HCategoryManager::getObject(pParticleCand,candCat,j);
    if(!pParticleCand->isFlagBit(Particle::kIsUsed)) continue;
    
    
    sys      = pParticleCand->getSystem();           // sys == 0 - Rpc, sys == 1 - Tof
    mom      = pParticleCand->getMomentum();         //-later-shall-use: getMomentumPID()---(c)-Alexandr
    charge   = pParticleCand->getCharge();
    metaQa   = pParticleCand->getMetaMatchQuality(); 
    beta     = pParticleCand->getBeta();
    theta    = pParticleCand->getTheta();
    phi      = pParticleCand->getPhi();
    chi2     = pParticleCand->getChi2();
    sec      = pParticleCand->getSector();           // sector is the sixth part of the detector
    chi2In   = pParticleCand->getInnerSegmentChi2(); // chi2 of inner segment
    chi2Out  = pParticleCand->getOuterSegmentChi2(); // chi2 of outer segment
    mass2    = pParticleCand->getMass2();            // mass2 = mom*mom*(1-beta*beta)/(beta*beta);
    mass     = pParticleCand->getMass();             // mass  = sqrt(mass2);
    mdcdEdx  = pParticleCand->getMdcdEdx();
    tofdEdx  = pParticleCand->getTofdEdx();
    metaDx   = pParticleCand->getRkMetaDx();         
    metaDy   = pParticleCand->getRkMetaDy();         
    
    PCr              = pParticleCand->getR();
        PCz              = pParticleCand->getZ();
    
    pz       = mom*cos(theta*hpi/90.)/1000;
    pt0      = mom*sin(theta*hpi/90.)/1000;
    px       = pt0*cos(phi*hpi/90.);
    py       = pt0*sin(phi*hpi/90.);
    
    rapid    = 0.5*TMath::Log((1+beta)/(1-beta));
    eta      =    -TMath::Log(tan(theta/2));
    
    betaL    = beta*cos(theta*hpi/90.);
    rapidity = 0.5*TMath::Log((1+betaL)/(1-betaL));
    Y0       = (rapidity - Ycm)/Ycm;
    dphi     = phi - VectphiEP;
    if (dphi>180.){dphi = dphi - 360.; }
    if (dphi<-180.){dphi = dphi + 360.; }

    hPhi->Fill(phi);
    
        // apply track QA cuts
        if (metaQa>2) continue;
    if (mass2 <0) continue;
    
    hRapidity->Fill(rapidity);
    
    hM2fromM->Fill(mass);
    
    hCharge->Fill(charge);
    
     //-Tetiana's-plots-----------
           hChi2       ->Fill(chi2);
           hChi2In     ->Fill(chi2In);
           hChi2Out    ->Fill(chi2Out);
           //Fill Theta vs Phi Plots
           hthetaPhiAll->Fill(phi,theta);
           //Fill Beta vs Momentum
           hbetaMomAll ->Fill(mom*charge,beta);
           hmommassAll ->Fill(charge*mass,mom);
       
       hsys    ->Fill(sys);
       hmom    ->Fill(mom);
       hmetaQa ->Fill(metaQa);
       hsec    ->Fill(sec);
       hmdcdEdx->Fill(mdcdEdx);
       htofdEdx->Fill(tofdEdx);
       hmetaDx ->Fill(metaDx);
       hmetaDy ->Fill(metaDy);
       hPCr    ->Fill(PCr);
       hPCz    ->Fill(PCz);
       
       hpx     ->Fill(px);
       hpy     ->Fill(py);
       hpz     ->Fill(pz);
       hpt     ->Fill(pt);
       
       hdEdxMAll->Fill(mass/1000,mdcdEdx);
       
       
       //------Now-make-PID-------begin-----------
       
       pimFlag[j] = p.fPID(9, mom,beta,charge);
       pipFlag[j] = p.fPID(8, mom,beta,charge);
       kapFlag[j] = p.fPID(11,mom,beta,charge);
       proFlag[j] = p.fPID(14,mom,beta,charge);
       
       //fill-particle-numeration-integral-----------------------------------------------------
                                      hmassAll->Fill(charge*mass2/1000000);
       if (pipFlag[j] == kTRUE && mdcdEdx < 5) {
         hPIDPip ->Fill(charge*mass2/1000000); 
         pParticleCand->calc4vectorProperties(HPhysicsConstants::mass( 8));
         vector = (*pParticleCand);
         pt     = vector.Pt();
         y      = vector.Rapidity();
         hyPIDPip->Fill(y);
         hRPIDPip->Fill(rapidity);
         npip++;
      } // pi+    selection (Pip);
       if (pimFlag[j] == kTRUE && mdcdEdx < 5) {
         hPIDPim ->Fill(charge*mass2/1000000);
         pParticleCand->calc4vectorProperties(HPhysicsConstants::mass( 9));
         vector = (*pParticleCand);
         pt     = vector.Pt();
         y      = vector.Rapidity();
         hyPIDPim->Fill(y);
         hRPIDPim->Fill(rapidity);
         npim++;
      } // pi-    selection (Pim);
       if (kapFlag[j] == kTRUE && mdcdEdx < 5) { 
         hPIDKap ->Fill(charge*mass2/1000000);
         pParticleCand->calc4vectorProperties(HPhysicsConstants::mass(11));
         vector = (*pParticleCand);
         pt     = vector.Pt();
         y      = vector.Rapidity();
         hyPIDKap->Fill(y);
         hRPIDKap->Fill(rapidity);
         nkap++;
      } // K+     selection (Kap);
       if (proFlag[j] == kTRUE && mdcdEdx < 5) { 
         hPIDPro ->Fill(charge*mass2/1000000);
         pParticleCand->calc4vectorProperties(HPhysicsConstants::mass(14));
         vector = (*pParticleCand);
         pt     = vector.Pt();
         y      = vector.Rapidity();
         hyPIDPro->Fill(y);
         hRPIDPro->Fill(rapidity);
         npro++;
      } // proton selection (Pro);
       //--------------------------------------------------------------------------------------
           
       for (Int_t ipt=0; ipt<npt-1;ipt++){
        
         if (pt0>binpt[ipt] && pt0<binpt[ipt+1]){
                                    hM2Y   [ipt]->Fill(charge*mass2/1000000,rapidity);
         if (pipFlag[j] == kTRUE) { hM2YPip[ipt]->Fill(charge*mass2/1000000,rapidity); }
         if (pimFlag[j] == kTRUE) { hM2YPim[ipt]->Fill(charge*mass2/1000000,rapidity); }
         if (kapFlag[j] == kTRUE) { hM2YKap[ipt]->Fill(charge*mass2/1000000,rapidity); }
         if (proFlag[j] == kTRUE) { hM2YPro[ipt]->Fill(charge*mass2/1000000,rapidity); }
         }
         
         for (Int_t irpdt=0; irpdt<nrpdt-1;irpdt++){
           if (pt0>binpt[ipt] && pt0<binpt[ipt+1] && rapidity>binrpdt[irpdt] && rapidity<binrpdt[irpdt+1]){
         if (                                                                                                       mdcdEdx < 5) { hM2   [ipt][irpdt]->Fill( charge*mass2/1000000);}
             
         if (pipFlag[j] == kTRUE && mass2/1e6<=mass2Pip+sPip[ipt][irpdt] && mass2/1e6>=mass2Pip-sPip[ipt][irpdt] && mdcdEdx < 5) { hM2Pip[ipt][irpdt]->Fill( charge*mass2/1000000);}
         if (pimFlag[j] == kTRUE && mass2/1e6<=mass2Pim+sPim[ipt][irpdt] && mass2/1e6>=mass2Pim-sPim[ipt][irpdt] && mdcdEdx < 5) { hM2Pim[ipt][irpdt]->Fill( charge*mass2/1000000);}
         if (kapFlag[j] == kTRUE && mass2/1e6<=mass2Kap+sKap[ipt][irpdt] && mass2/1e6>=mass2Kap-sKap[ipt][irpdt] && mdcdEdx < 5) { hM2Kap[ipt][irpdt]->Fill( charge*mass2/1000000);}
         if (proFlag[j] == kTRUE && mass2/1e6<=mass2Pro+sPro[ipt][irpdt] && mass2/1e6>=mass2Pro-sPro[ipt][irpdt] && mdcdEdx < 5) { hM2P  [ipt][irpdt]->Fill( charge*mass2/1000000);} 
         
         hdEdxMass[ipt][irpdt]->Fill(charge*mass/1000,mdcdEdx);
         
           }//endif
         }//irpdt
       }//ipt

        for (Int_t ipt=0; ipt<npt-1;ipt++){
        
         if (pt0>binpt[ipt] && pt0<binpt[ipt+1] && (rapidity-Ycm)>=-Ycm && (rapidity-Ycm)<=Ycm){
          v2            = cos(2*((phi-180-VectphiEP)*hpi/90.));
          v2sum [ipt]  += v2;
          ncount[ipt]++;
          hv2phi[ipt]->Fill((phi-180-VectphiEP),v2,wgh);

          hNphi [ipt]->Fill((phi-180-VectphiEP),wgh);
         }
        }
        
        if (mass>600 && mass<1250 && NA>0 && NB>0 && charge>0 && metaQa<5 && chi2<200. && chi2In>0.1 && chi2In<12. && chi2Out>0.1 && chi2Out<12. && sec>=0 && sec<=5 && mdcdEdx>fdEdxVsMomLowLimit(mom)){

            PCp     = pParticleCand->getCorrectedMomentumPID(14);
            PCpz      = PCp*cos(theta*hpi/90.);

            PCE     = sqrt(938.272*938.272 + PCp*PCp );
            PCY     = 0.5*(log((PCE+PCpz)/(PCE-PCpz))); //corrected rapidity for protons
            PCYn    = PCY/(2.*Ycm); //normalized to projectile rapidity Y/Yproj
            PCYo    = (PCY-Ycm)/Ycm; //normalized to projectile rapidity (Y(cm)/Yproj(cm))
            PCpt    = PCp*sin(theta*hpi/90.); //corrected pt

            //---get-track-efficiency-------//
            binX     =   hProtPtVsY_Eff->GetXaxis()->FindBin((Double_t) rapidity );  //-Pt:Y-correction--
            binY     =   hProtPtVsY_Eff->GetYaxis()->FindBin((Double_t) PCpt );  //-Pt:Y-correction--
            TrackEff =   hProtPtVsY_Eff->GetBinContent(binX,binY);
            //------------------------------//
            for (Int_t n=1; n<6; n++){
                hPhiEPc[n-1]->Fill(phiEP[n],wgh*TrackEff);
            }

            CENT=-1;
            if( FOPI_redd ){ CENT=0; }
            if( FOPI_gren ){ CENT=1; }
            if( FOPI_blue ){ CENT=2; }
            RAPI=-1;
            if( PCYo>-0.9 && PCYo<-0.7 ){ RAPI=0; }
            if( PCYo>-0.7 && PCYo<-0.5 ){ RAPI=1; }
            if( PCYo>-0.5 && PCYo<-0.3 ){ RAPI=2; }
            if( PCYo>-0.3 && PCYo<-0.1 ){ RAPI=3; }
            if( PCYo>-0.1 && PCYo< 0.1 ){ RAPI=4; }
            if( PCYo> 0.1 && PCYo< 0.3 ){ RAPI=5; }
            if( PCYo> 0.3 && PCYo< 0.5 ){ RAPI=6; }
            if( PCYo> 0.5 && PCYo< 0.7 ){ RAPI=7; }
            if( PCYo> 0.7 && PCYo< 0.9 ){ RAPI=8; }
            PTRN=-1;
            if( PCpt> 200 && PCpt< 300 ){ PTRN= 0; }
            if( PCpt> 300 && PCpt< 400 ){ PTRN= 1; }
            if( PCpt> 400 && PCpt< 500 ){ PTRN= 2; }
            if( PCpt> 500 && PCpt< 600 ){ PTRN= 3; }
            if( PCpt> 600 && PCpt< 700 ){ PTRN= 4; }
            if( PCpt> 700 && PCpt< 800 ){ PTRN= 5; }
            if( PCpt> 800 && PCpt< 900 ){ PTRN= 6; }
            if( PCpt> 900 && PCpt<1000 ){ PTRN= 7; }
            if( PCpt>1000 && PCpt<1100 ){ PTRN= 8; }
            if( PCpt>1100 && PCpt<1200 ){ PTRN= 9; }
            if( PCpt>1200 && PCpt<1300 ){ PTRN=10; }
            if( PCpt>1300 && PCpt<1400 ){ PTRN=11; }
            if( PCpt>1400 && PCpt<1500 ){ PTRN=12; }
            if( PCpt>1500 && PCpt<1600 ){ PTRN=13; }
            if( PCpt>1600 && PCpt<1700 ){ PTRN=14; }
            if( PCpt>1700 && PCpt<1800 ){ PTRN=15; }
            if( PCpt>1800 && PCpt<1900 ){ PTRN=16; }
            if( PCpt>1900 && PCpt<2000 ){ PTRN=17; }
            if( CENT>=0 && RAPI>=0 && PTRN>=0 ){
                   pfy0pt[CENT][RAPI][PTRN].Fill(dphi, fabs(phiAB), VectphiEP, wgh*TrackEff);
                 }
        }
        
       
       //------Now-make-PID----------end----------
       
      }//j-----Loop-over-entries-----

  }//i-----Loop-over-events----------

  for (Int_t i=0;i<npt-1;i++){
        v2x[i] = binpt[i] + 0.5*(binpt[i+1]-binpt[i]);
        v2w[i] = hv2phi[i]->GetMean(2);
        hv2   -> Fill(v2x[i],v2w[i]);
  }

  Float_t yPID [4] = {hyPIDPim->GetMean(), hyPIDPip->GetMean(), hyPIDKap->GetMean(), hyPIDPro->GetMean()};
  Float_t ybet [4] = {hRPIDPim->GetMean(), hRPIDPip->GetMean(), hRPIDKap->GetMean(), hRPIDPro->GetMean()};
  Float_t dyPID[4] = {hyPIDPim->GetRMS() , hyPIDPip->GetRMS() , hyPIDKap->GetRMS() , hyPIDPro->GetRMS() };
  Float_t dybet[4] = {hRPIDPim->GetRMS() , hRPIDPip->GetRMS() , hRPIDKap->GetRMS() , hRPIDPro->GetRMS() };
  Float_t dy   [4];
  Float_t MeanY = 0.0;
  for (Int_t i=0;i<4;i++){
    dy[i] = 0.5*sqrt(ybet[i]*ybet[i]*dyPID[i]*dyPID[i]+yPID[i]*yPID[i]*dybet[i]*dybet[i])/(ybet[i]*ybet[i]);
    MeanY+=yPID[i]/ybet[i];
  }
  MeanY = MeanY/4;
  
  for (Int_t i=0;i<4;i++){
    hyvsPID ->Fill(i+0.5,yPID[i]/ybet[i]);
    hnormPID->Fill(i+0.5,MeanY);
  }
  
  foutfile->Write();
  foutfile->Close();
  
  return 0;
  
}
Example #11
0
void DrawChannelCompatibility(double rMin = -5,double rMax=5)
{
  gROOT->ForceStyle();
  TFile *inf = TFile::Open("higgsCombineZ.ChannelCompatibilityCheck.mH120.root");
  RooFitResult *fit_nominal   = (RooFitResult *)inf->Get("fit_nominal");
  RooFitResult *fit_alternate = (RooFitResult *)inf->Get("fit_alternate");
  RooRealVar *rFit = (RooRealVar*)fit_nominal->floatParsFinal().find("r");
  
  TString prefix = TString::Format("_ChannelCompatibilityCheck_%s_","r");

  int nChann = 0;
  TIterator *iter = fit_alternate->floatParsFinal().createIterator();
  for (RooAbsArg *a = (RooAbsArg *) iter->Next(); a != 0; a = (RooAbsArg *) iter->Next()) {
    if (TString(a->GetName()).Index(prefix) == 0) nChann++;
  }
  TH2F *frame = new TH2F("frame",";best fit #sigma/#sigma_{SM};",1,rMin,rMax,nChann,0,nChann);

  iter->Reset(); 
  int iChann = 0; 
  TGraphAsymmErrors *points = new TGraphAsymmErrors(nChann);
  float chi2(0.0);
  for (RooAbsArg *a = (RooAbsArg *) iter->Next(); a != 0; a = (RooAbsArg *) iter->Next()) {
    if (TString(a->GetName()).Index(prefix) == 0) {
      RooRealVar *ri = (RooRealVar *) a;
      TString channel = a->GetName(); 
      channel.ReplaceAll(prefix,"");
      points->SetPoint(iChann,ri->getVal(),iChann+0.5);
      cout<<channel<<" "<<ri->getVal()<<" "<<ri->getAsymErrorLo()<<" +"<<ri->getAsymErrorHi()<<endl;
      chi2 += pow((ri->getVal()-rFit->getVal())/ri->getError(),2);
      points->SetPointError(iChann,-ri->getAsymErrorLo(),ri->getAsymErrorHi(),0,0);
      //points->SetPointError(iChann,ri->getAsymErrorHi(),ri->getAsymErrorHi(),0,0);
      iChann++;
      frame->GetYaxis()->SetBinLabel(iChann, channel);
    }
  }
  cout<<"Combined fit: "<<rFit->getVal()<<" "<<rFit->getAsymErrorLo()<<" +"<<rFit->getAsymErrorHi()<<endl;
  cout<<"chi2 = "<<chi2<<endl;
  points->SetLineColor(kRed);
  points->SetLineWidth(3);
  points->SetMarkerStyle(21);

  TCanvas *can = new TCanvas("ChannelCompatibility_Z","ChannelCompatibility_Z",900,600);
  frame->GetXaxis()->SetNdivisions(505);
  frame->GetXaxis()->SetTitleSize(0.06);
  frame->GetXaxis()->SetTitleOffset(0.9);
  frame->GetXaxis()->SetLabelSize(0.05);
  frame->GetYaxis()->SetLabelSize(0.1);
  frame->Draw(); 
  //gStyle->SetOptStat(0);
  TBox globalFitBand(rFit->getVal()+rFit->getAsymErrorLo(), 0, rFit->getVal()+rFit->getAsymErrorHi(), nChann);
  //TBox globalFitBand(rFit->getVal()-rFit->getAsymErrorHi(), 0, rFit->getVal()+rFit->getAsymErrorHi(), nChann);
  globalFitBand.SetFillStyle(3013);
  globalFitBand.SetFillColor(65);
  globalFitBand.SetLineStyle(0);
  globalFitBand.DrawClone();
  TLine globalFitLine(rFit->getVal(), 0, rFit->getVal(), nChann);
  globalFitLine.SetLineWidth(4);
  globalFitLine.SetLineColor(214);
  globalFitLine.DrawClone();
  points->Draw("P SAME");
  gPad->Update();

  TLine *ln0 = new TLine(1,gPad->GetFrame()->GetY1(),1,gPad->GetFrame()->GetY2());
  ln0->SetLineColor(kBlack);
  ln0->SetLineWidth(1);
  ln0->SetLineStyle(2);
  ln0->Draw("same");
}