Esempio n. 1
0
StatusCode DelphesSimulation::initialize() {
  gRandom->SetSeed(1234);
  // If required, export output directly to root file
  if (m_outRootFileName!="") {

    info()  << "Opening ROOT output file: " << m_outRootFileName << endmsg;
    m_outRootFile = new TFile(m_outRootFileName.c_str(), "RECREATE");
    if (m_outRootFile->IsZombie()) {

      error() << "Can't open " << m_outRootFileName << endmsg;
      return Error ("ERROR, can't open defined ROOT output file.");
    }
  }

  // Read Delphes configuration card (deleted by finalize())
  m_confReader = std::unique_ptr<ExRootConfReader>(new ExRootConfReader);
  m_confReader->ReadFile(m_DelphesCard.c_str());

  // Instance of Delphes (deleted by finalize())
  m_Delphes = std::unique_ptr<Delphes>(new Delphes("Delphes"));
  m_Delphes->SetConfReader(m_confReader.get());

  // Delphes needs data structure to be defined (ROOT tree) (deleted by finalize())
  m_treeWriter  = new ExRootTreeWriter( m_outRootFile, "DelphesSim");
  m_branchEvent = m_treeWriter->NewBranch("Event", HepMCEvent::Class());
  m_Delphes->SetTreeWriter(m_treeWriter);

  // Define event readers
  //
  //  HepMC reader --> reads either from a file or directly from data store (deleted by finalize())
  m_hepMCConverter = std::unique_ptr<HepMCDelphesConverter>(new HepMCDelphesConverter);

  // Create following arrays of Delphes objects --> starting objects
  m_allParticles = m_Delphes->ExportArray("allParticles");
  m_stableParticles = m_Delphes->ExportArray("stableParticles");
  m_partons = m_Delphes->ExportArray("partons");

  // Init Delphes - read in configuration & define modules to be executed
  m_Delphes->InitTask();

  // Print Delphes modules to be used
  ExRootConfParam param = m_confReader->GetParam("::ExecutionPath");
  Long_t          size  = param.GetSize();
  info()  << "Delphes simulation will use the following modules: " << endmsg;
  for( Long_t k = 0; k < size; ++k) {

    TString name = param[k].GetString();
    info()  << "-- Module: " <<  name << endmsg;
  }

  m_eventCounter     = 0;

  m_treeWriter->Clear();
  m_Delphes->Clear();

  for(auto& toolname: m_saveToolNames) {
    m_saveTools.push_back(tool<IDelphesSaveOutputTool>(toolname));
    // FIXME: check StatusCode once the m_saveTools is a ToolHandleArray
    // if (!) {
    //   error() << "Unable to retrieve the output saving tool." << endmsg;
    //   return StatusCode::FAILURE;
    // }
  }

  return StatusCode::SUCCESS;
}
Esempio n. 2
0
StatusCode DelphesSimulation::initialize() {
    inputFile = 0;
    outputFile = 0;

    // the input files is an HEPMC file
    info()  << "** Reading " << m_filename << endmsg;
    inputFile = fopen(m_filename.c_str(), "r");

    if(inputFile == NULL)
    {
        debug() << "can't open " << m_filename << endmsg;
        return Error ("ERROR, can't open hepmc input file ");
    }

    fseek(inputFile, 0L, SEEK_END);
    length = ftello(inputFile);
    fseek(inputFile, 0L, SEEK_SET);
    info() << "** length of input file " << length << endmsg;
    if(length <= 0)
    {
        fclose(inputFile);
    }
    confReader = new ExRootConfReader;
    confReader->ReadFile(m_detectorcard.c_str());


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

    if (m_debug_delphes) outputFile = TFile::Open("DelphesOutput.root", "RECREATE");

    treeWriter = new ExRootTreeWriter( outputFile , "Delphes");

    modularDelphes->SetTreeWriter(treeWriter);
    branchEvent = treeWriter->NewBranch("Event", HepMCEvent::Class());

    factory = modularDelphes->GetFactory();

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

    reader = new DelphesHepMCReader;

    modularDelphes->InitTask();
    reader->SetInputFile(inputFile);
    TString name;
    //  const ExRootConfReader::ExRootTaskMap *modules = confReader->GetModules();
    //  ExRootConfReader::ExRootTaskMap::const_iterator itModules;
    ExRootConfParam param = confReader->GetParam("::ExecutionPath");
    Long_t k, size = param.GetSize();
    for( k = 0; k < size; ++k)
    {
        name = param[k].GetString();
        info()  << "the cfg contains a delphes module with name " <<  name << endmsg;
    }


    eventCounter = 0 ;
    treeWriter->Clear();
    modularDelphes->Clear();
    reader->Clear();

    return StatusCode::SUCCESS;
}
Esempio n. 3
0
int main(int argc, char *argv[])
{

  if(argc != 3)
  {
    cout << " Usage: ./CaloGrid [detector card] [calo name]" << endl;
    cout << "Example: ./CaloGrid cards/delphes_card_CMS.tcl ECal" << endl;
    return 0;
  }

  TString card(argv[1]);

  ExRootConfReader *confReader = new ExRootConfReader;
  confReader->ReadFile(card);

  std::vector<std::string> calorimeters_;
  std::map<std::string, std::set<std::pair<Double_t, Int_t> > > caloBinning_;

  std::string s(argv[2]);
  std::replace(s.begin(), s.end(), ',', ' ');
  std::istringstream stream(s);
  std::string word;
  while(stream >> word) calorimeters_.push_back(word);

  caloBinning_.clear(); // calo binning

  TCanvas c("", "", 1600, 838);

  gPad->SetLeftMargin(0.16);
  gPad->SetTopMargin(0.16);
  gPad->SetBottomMargin(0.20);
  gStyle->SetOptStat(0000000);

  gStyle->SetTextFont(132);

  TH2F h2("h2", "", 1, -6, 6, 1, 0, 6.28);

  h2.GetXaxis()->SetTitle("#eta");
  h2.GetYaxis()->SetTitle("#phi");

  h2.GetXaxis()->SetTitleFont(132);
  h2.GetYaxis()->SetTitleFont(132);
  h2.GetZaxis()->SetTitleFont(132);
  h2.GetXaxis()->SetLabelFont(132);
  h2.GetYaxis()->SetLabelFont(132);

  h2.GetXaxis()->SetTitleOffset(1.4);
  h2.GetYaxis()->SetTitleOffset(1.1);
  h2.GetXaxis()->SetLabelOffset(0.02);
  h2.GetYaxis()->SetLabelOffset(0.02);
  h2.GetXaxis()->SetTitleSize(0.06);
  h2.GetYaxis()->SetTitleSize(0.06);
  h2.GetXaxis()->SetLabelSize(0.06);
  h2.GetYaxis()->SetLabelSize(0.06);

  h2.GetXaxis()->SetTickLength(0.0);
  h2.GetYaxis()->SetTickLength(0.0);

  h2.Draw();

  // fake loop just keeping it for convenience right now
  for(std::vector<std::string>::const_iterator calo = calorimeters_.begin(); calo != calorimeters_.end(); ++calo)
  {

    //first entry is eta bin, second is number of phi bins
    set<pair<Double_t, Int_t> > caloBinning;
    ExRootConfParam paramEtaBins, paramPhiBins;
    ExRootConfParam param = confReader->GetParam(Form("%s::EtaPhiBins", calo->c_str()));
    Int_t size = param.GetSize();

    for(int i = 0; i < size / 2; ++i)
    {
      paramEtaBins = param[i * 2];
      paramPhiBins = param[i * 2 + 1];
      assert(paramEtaBins.GetSize() == 1);

      caloBinning.insert(std::make_pair(paramEtaBins[0].GetDouble(), paramPhiBins.GetSize() - 1));
    }
    caloBinning_[*calo] = caloBinning;

    TLine *liney;
    TLine *linex;

    //loop over calo binning
    std::set<std::pair<Double_t, Int_t> >::iterator it;

    Int_t n = -1;
    for(it = caloBinning.begin(); it != caloBinning.end(); ++it)
    {
      n++;

      if(debug) cout << "-----------------------" << endl;
      if(debug) cout << it->first << "," << it->second << endl;
      liney = new TLine(it->first, 0, it->first, 6.28);
      liney->SetLineColor(kRed + 3);
      liney->Draw();

      set<std::pair<Double_t, Int_t> >::iterator it2 = it;
      it2--;

      for(int j = 0; j <= it->second; j++)
      {

        Double_t yval0 = 0 + 6.28 * j / it->second;

        if(debug) cout << it2->first << "," << yval0 << "," << it->first << "," << yval0 << endl;

        linex = new TLine(it->first, yval0, it2->first, yval0);
        linex->SetLineColor(kRed + 3);
        linex->Draw();
      }
    }
  }

  TString text = TString(s);
  TText *th1 = new TText(5.00, 6.45, text);
  th1->SetTextAlign(31);
  th1->SetTextFont(132);
  th1->SetTextSize(0.075);
  th1->Draw();

  TString output = TString(s);
  c.Print(output + ".png", "png");
  c.Print(output + ".pdf", "pdf");
}