Fork me on GitHub

source: svn/trunk/src/HEPMCConverter.cc@ 351

Last change on this file since 351 was 350, checked in by severine ovyn, 16 years ago

first test HepMC

File size: 5.2 KB
Line 
1/***********************************************************************
2** **
3** /----------------------------------------------\ **
4** | Delphes, a framework for the fast simulation | **
5** | of a generic collider experiment | **
6** \------------- arXiv:0903.2225v1 ------------/ **
7** **
8** **
9** This package uses: **
10** ------------------ **
11** FastJet algorithm: Phys. Lett. B641 (2006) [hep-ph/0512210] **
12** Hector: JINST 2:P09005 (2007) [physics.acc-ph:0707.1198v2] **
13** FROG: [hep-ex/0901.2718v1] **
14** **
15** ------------------------------------------------------------------ **
16** **
17** Main authors: **
18** ------------- **
19** **
20** Severine Ovyn Xavier Rouby **
21** severine.ovyn@uclouvain.be xavier.rouby@cern **
22** **
23** Center for Particle Physics and Phenomenology (CP3) **
24** Universite catholique de Louvain (UCL) **
25** Louvain-la-Neuve, Belgium **
26** **
27** Copyright (C) 2008-2009, **
28** All rights reserved. **
29** **
30***********************************************************************/
31
32
33#include <iostream>
34#include <fstream>
35#include "TLorentzVector.h"
36#include "BlockClasses.h"
37#include "ExRootTreeWriter.h"
38#include "ExRootTreeBranch.h"
39#include "HEPMCConverter.h"
40
41using namespace std;
42
43//------------------------------------------------------------------------------
44
45HEPMCConverter::~HEPMCConverter() {}
46
47//------------------------------------------------------------------------------
48
49HEPMCConverter::HEPMCConverter(const string& inputFileList, const string& outputFileName, const int& Nevents) : DataConverter(Nevents)
50{
51// int ierr, entryType;
52// int nevt = 0;
53
54 // export the generator-level data to the outputfile
55 ExRootTreeWriter *treeWriter = new ExRootTreeWriter(outputFileName, "GEN");
56 ExRootTreeBranch *branchGenEvent = treeWriter->NewBranch("Event", TRootGenEvent::Class());
57 ExRootTreeBranch *branchGenParticle = treeWriter->NewBranch("Particle", TRootC::GenParticle::Class());
58
59 // Open the datafile list
60 ifstream infile(inputFileList.c_str());
61 if(!infile.is_open()) {
62 cerr << left << setw(30) <<"** ERROR: Can't open "<<""
63 << left << setw(20) << inputFileList <<""
64 << right << setw(19) <<"for input **"<<""<<endl;
65 exit(1); // could not open the list : exit
66 }
67
68 string filename;
69 while(1) {
70 infile >> filename;
71 if(!infile.good()) break; // quits when the inputfile list is depleted
72
73 ifstream datafile(filename.c_str());
74 if(!datafile.good()) { // i.e. datafile could not be opened
75 cerr << left << setw(30) <<"** ERROR: Can't find file "<<""
76 << left << setw(20) << filename <<""
77 << right << setw(19) <<"for input **"<<""<<endl;
78 continue; // go to the next item in the list
79 }
80
81 // else : if the datafile was successfully opened
82 Long64_t allEntries = Nevents;
83 if(allEntries > 0) {
84 /*
85 // Loop over all objects
86 Long64_t recordNumber = 1;
87 for(Long64_t entry = 0; entry < allEntries; ++entry) {
88 ierr = StdHepXdrRead(&entryType, istr);
89 if(ierr != 0) {
90 cerr << left << setw(49) <<"** ERROR: Unexpected end of file after"<<""
91 << left << setw(10) << entry <<""
92 << right << setw(10) <<"entries **"<<""<<endl;
93 break;
94 } // if ierr !=0
95
96 // analyse only entries with standard HEPEVT common block
97 if(entryType == 1) {
98 // add empty events for missing event numbers
99 while(recordNumber < myhepevt.nevhep) {
100 treeWriter->Clear();
101 AnalyseEvent(branchGenEvent, recordNumber);
102 treeWriter->Fill();
103 ++recordNumber;
104 } // while
105 */
106 treeWriter->Clear();
107 // AnalyseEvent(branchGenEvent, myhepevt.nevhep);
108 // AnalyseParticles(branchGenParticle);
109 treeWriter->Fill();
110 //++recordNumber;
111 // } // if entryType == 1
112 // } // for entry < allEntries
113 } // if allEntries
114 datafile.close();
115 } // while : loop on the list file contents
116
117 treeWriter->Write();
118 delete treeWriter;
119}
120
Note: See TracBrowser for help on using the repository browser.