Ejemplo n.º 1
0
int main(int argc, char ** argv) 
{
  if(argc < 4)
    {
      cout << "Usage:   " << argv[0] 
           << " fileToSplit.lhe events_per_file tag_for_splitting" << endl ;
      return -1;
    }

  std::ifstream ifs (argv[1]) ;
  LHEF::Reader reader (ifs) ;

  int eventsPerFile = atoi (argv[2]) ;

  LHEF::Writer * writer ;
  ofstream outputStream ;

  int ieve = 0 ;
  int index = 0 ;
  //PG loop over input events
  while (reader.readEvent ()) 
    {
      if (ieve == 0)
        { 
          stringstream filename ;
          filename << argv[3] << "_" << index << ".lhe" ;
          outputStream.open (filename.str ().c_str ()) ;
          cout << "opening in output : " << filename.str () << endl ;
          writer = new LHEF::Writer (outputStream) ;
          writer->headerBlock() << reader.headerBlock ;
          writer->initComments() << reader.initComments ;
          writer->heprup = reader.heprup ;
          writer->init () ;
        }

      if ( reader.outsideBlock.length() ) std::cout << reader.outsideBlock;
      writer->eventComments() << reader.eventComments;
      writer->hepeup = reader.hepeup;
      writer->writeEvent();
      ieve++ ;

      if (ieve % eventsPerFile == 0)
        {
          ieve = 0 ;
          index++ ;
          delete writer ;
          outputStream.close () ;
        }
    } //PG loop over input events

  if (ieve % eventsPerFile != 0)  delete writer ;
  return 0 ;
}
Ejemplo n.º 2
0
int main(int argc, char *argv[])
{
  char appName[] = "ExRootLHEFConverter";

  if(argc != 4)
  {
    cout << " Usage: " << appName << " input_file" << " outOnPeak_file" << " outOffPeak_file" <<endl;
    cout << " input_file - input file in LHEF format," << endl;
    cout << " outOnPeak_file - output file with m(H) <140 GeV." << endl;
    cout << " outOffPeak_file - output file with m(H) >=140 GeV." << endl;
    return 1;
  }

  gROOT->SetBatch();

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

  // Open a stream connected to an event file:
  ifstream inputFileStream(argv[1]);

  // Create the Reader object:
  LHEF::Reader *inputReader = new LHEF::Reader(inputFileStream);

  ofstream onPeakFile(argv[2]);
  ofstream offPeakFile(argv[3]);
  LHEF::Writer *onPeakWriter = new LHEF::Writer(onPeakFile);
  LHEF::Writer *offPeakWriter = new LHEF::Writer(offPeakFile);
  onPeakWriter->heprup = inputReader->heprup;
  offPeakWriter->heprup = inputReader->heprup;
  onPeakWriter->init();
  offPeakWriter->init();
  //TFile *outputFile = TFile::Open(argv[2], "RECREATE");
  //ExRootTreeWriter *treeWriter = new ExRootTreeWriter(outputFile, "LHEF");

  // generated event from LHEF
  //ExRootTreeBranch *branchEvent = treeWriter->NewBranch("Event", TRootLHEFEvent::Class());

  // generated partons from LHEF
 // ExRootTreeBranch *branchParticle = treeWriter->NewBranch("Particle", TRootLHEFParticle::Class());

  cout << "** Calculating number of events to process. Please wait..." << endl;
  Long64_t allEntries = inputReader->getNumberOfEvents();
  cout << "** Input file contains " << allEntries << " events" << endl;

  if(allEntries > 0)
  {
    ExRootProgressBar progressBar(allEntries);
    
    // Loop over all events
    Long64_t entry = 0;
    while(inputReader->readEvent())
    {
      //treeWriter->Clear();

      AnalyseEvent(inputReader, entry + 1);
      //AnalyseEvent(inputReader, branchEvent, entry + 1);
      if( AnalyseParticles(inputReader ) == 1)
      {
        offPeakWriter->hepeup = inputReader->hepeup;
        offPeakWriter->writeEvent();
      }else{
        onPeakWriter->hepeup = inputReader->hepeup;
        onPeakWriter->writeEvent();
      }
      //AnalyseParticles(inputReader, branchParticle);


      //treeWriter->Fill();

      progressBar.Update(entry);

      ++entry;
    }

    progressBar.Finish();
  }

  //treeWriter->Write();

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

  //delete treeWriter;
  //delete outputFile;
  delete inputReader;
  delete onPeakWriter;
  delete offPeakWriter;
  onPeakFile.close();
  offPeakFile.close();
  inputFileStream.close();
}
Ejemplo n.º 3
0
int main (int argc, char ** argv) 
{
  if(argc < 3)
    {
      cout << "Usage:   " << argv[0] 
           << " input.lhe output.lhe" << endl ;
      return -1;
    }

  std::ifstream ifs (argv[1]) ;
  LHEF::Reader reader (ifs) ;

  ofstream outputStream (argv[2]) ;
  LHEF::Writer writer (outputStream) ;

  writer.headerBlock () << reader.headerBlock ;
  writer.initComments () << reader.initComments ;
  writer.heprup = reader.heprup ;
  writer.init () ;

//PG mu massless in phantom
//  float k2 = 0.1056583715 * 0.1056583715 - 1.77682 * 1.77682 ; // GeV -3.14592562093
  float k2 = 0. - 1.77682 * 1.77682 ; // GeV -3.14592562093

  int count = 0 ;
  //PG loop over input events
  while (reader.readEvent ()) 
    {
      ++count ;
      if ( reader.outsideBlock.length ()) std::cout << reader.outsideBlock;

      // loop over particles in the event
      for (int iPart = 0 ; iPart < reader.hepeup.IDUP.size (); ++iPart) 
        {
           // outgoing particles          
           if (reader.hepeup.ISTUP.at (iPart) == 1)
             {
               if (abs (reader.hepeup.IDUP.at (iPart)) == 13)
                 {
                   TLorentzVector dummy
                     (
                       reader.hepeup.PUP.at (iPart).at (0), // px
                       reader.hepeup.PUP.at (iPart).at (1), // py
                       reader.hepeup.PUP.at (iPart).at (2), // pz
                       reader.hepeup.PUP.at (iPart).at (3) // E
                     ) ;
                   float p2 = dummy.Vect ().Mag2 () ;

                   float scale = sqrt (1 + k2 / p2) ;
                   if (p2 < (-1 * k2))
                     {
                       cout << "warning: p2 is smaller than the mass difference " << p2 << endl ;
                       scale = 1 ;                     
                     }
                   reader.hepeup.PUP.at (iPart).at (0) *= scale ; // px
                   reader.hepeup.PUP.at (iPart).at (1) *= scale ; // px
                   reader.hepeup.PUP.at (iPart).at (2) *= scale ; // px
    
                   if (reader.hepeup.IDUP.at (iPart) == 13) reader.hepeup.IDUP.at (iPart) = 15 ;
                   if (reader.hepeup.IDUP.at (iPart) == -13) reader.hepeup.IDUP.at (iPart) = -15 ;
                 }
               if (reader.hepeup.IDUP.at (iPart) == 14) reader.hepeup.IDUP.at (iPart) = 16 ;
               if (reader.hepeup.IDUP.at (iPart) == -14) reader.hepeup.IDUP.at (iPart) = -16 ;
             } // outgoing particles
        } // loop over particles in the event
      writer.eventComments () << reader.eventComments ;
      writer.hepeup = reader.hepeup ;
      bool written = writer.writeEvent () ;
      if (!written)
        {
          cout << "warning: event " << count << " not written" << endl ;
        }

    } //PG loop over input events

  cout << "end loop over " << count << " events" << endl ;
  return 0 ;
}