|
[Rivet-svn] r3123 - in trunk: . bin data/plotinfo include/Rivet src/Coreblackhole at projects.hepforge.org blackhole at projects.hepforge.orgThu Jun 2 23:45:53 BST 2011
Author: buckley Date: Thu Jun 2 23:45:53 2011 New Revision: 3123 Log: * Adding a file-weight feature to the Run object, which will optionally rescale the weights in the provided HepMC files. This should be useful for e.g. running on multiple differently-weighted AlpGen HepMC files/streams. The new functionality is used by the rivet command via an optional weight appended to the filename with a colon delimiter, e.g. "rivet fifo1.hepmc fifo2.hepmc:2.31" Modified: trunk/ChangeLog trunk/bin/rivet trunk/data/plotinfo/MC_GENERIC.plot trunk/include/Rivet/Run.hh trunk/src/Core/Run.cc Modified: trunk/ChangeLog ============================================================================== --- trunk/ChangeLog Thu Jun 2 22:58:07 2011 (r3122) +++ trunk/ChangeLog Thu Jun 2 23:45:53 2011 (r3123) @@ -1,3 +1,12 @@ +2011-06-03 Andy Buckley <andy at insectnation.org> + + * Adding a file-weight feature to the Run object, which will + optionally rescale the weights in the provided HepMC files. This + should be useful for e.g. running on multiple differently-weighted + AlpGen HepMC files/streams. The new functionality is used by the + rivet command via an optional weight appended to the filename with + a colon delimiter, e.g. "rivet fifo1.hepmc fifo2.hepmc:2.31" + 2011-06-01 Hendrik Hoeth <hendrik.hoeth at cern.ch> * Add BeamThrust projection Modified: trunk/bin/rivet ============================================================================== --- trunk/bin/rivet Thu Jun 2 22:58:07 2011 (r3122) +++ trunk/bin/rivet Thu Jun 2 23:45:53 2011 (r3123) @@ -424,10 +424,15 @@ ## Init run based on one event hepmcfile = HEPMCFILES[0] +## Apply a file-level weight derived from the filename +hepmcfileweight = 1.0 +if ":" in hepmcfile: + hepmcfile, hepmcfileweight = hepmcfile.rsplit(":", 1) + hepmcfileweight = float(hepmcfileweight) try: if opts.EVENT_TIMEOUT or opts.RUN_TIMEOUT: signal.alarm(min_nonnull(opts.EVENT_TIMEOUT, opts.RUN_TIMEOUT)) - init_ok = run.init(hepmcfile) + init_ok = run.init(hepmcfile, hepmcfileweight) signal.alarm(0) if not init_ok: logging.error("Failed to initialise using event file '%s'... exiting" % hepmcfile) @@ -441,13 +446,21 @@ evtnum = 0 starttime = time.time() for fileidx, hepmcfile in enumerate(HEPMCFILES): + ## Apply a file-level weight derived from the filename + hepmcfileweight = 1.0 + if ":" in hepmcfile: + hepmcfile, hepmcfileweight = hepmcfile.rsplit(":", 1) + hepmcfileweight = float(hepmcfileweight) ## Open next HepMC file (NB. this doesn't apply to the first file: it was already used for the run init) if fileidx > 0: - run.openFile(hepmcfile) + run.openFile(hepmcfile, hepmcfileweight) if not run.readEvent(): logging.warning("Could not read events from '%s'" % hepmcfile) continue - logging.info("Reading events from '%s'" % hepmcfile) + msg = "Reading events from '%s'" % hepmcfile + if hepmcfileweight != 1.0: + msg += " (file weight = %e)" % hepmcfileweight + logging.info(msg) while opts.MAXEVTNUM is None or evtnum < opts.MAXEVTNUM: evtnum += 1 logNEvt(evtnum, starttime, opts.MAXEVTNUM) Modified: trunk/data/plotinfo/MC_GENERIC.plot ============================================================================== --- trunk/data/plotinfo/MC_GENERIC.plot Thu Jun 2 22:58:07 2011 (r3122) +++ trunk/data/plotinfo/MC_GENERIC.plot Thu Jun 2 23:45:53 2011 (r3123) @@ -1,16 +1,16 @@ -# BEGIN PLOT /MC_GENERIC/ECh -Title=Energy of charged particles +# BEGIN PLOT /MC_GENERIC/E$ +Title=Energy of all particles XLabel=$E$ [GeV] YLabel=$1/\sigma \; \mathrm{d}\sigma/\mathrm{d}E$ [GeV$^{-1}$] # END PLOT -# BEGIN PLOT /MC_GENERIC/E -Title=Energy of all particles +# BEGIN PLOT /MC_GENERIC/ECh +Title=Energy of charged particles XLabel=$E$ [GeV] YLabel=$1/\sigma \; \mathrm{d}\sigma/\mathrm{d}E$ [GeV$^{-1}$] # END PLOT -# BEGIN PLOT /MC_GENERIC/Eta.* +# BEGIN PLOT /MC_GENERIC/Eta XLabel=$\eta$ YLabel=$1/\sigma \; \mathrm{d}\sigma/\mathrm{d}\eta$ LogY=0 @@ -82,7 +82,7 @@ LogY=0 # END PLOT -# BEGIN PLOT /MC_GENERIC/Mult +# BEGIN PLOT /MC_GENERIC/Mult$ Title=Total multiplicity of events XLabel=$N$ YLabel=$1/\sigma \; \mathrm{d}\sigma/\mathrm{d}N$ @@ -107,62 +107,62 @@ Title=Average per-event multiplicity of \emph{all} (unphysical) particle IDs # END PLOT -# BEGIN PLOT /MC_GENERIC/PhiCh -Title=Azimuthal distribution of charged particles +# BEGIN PLOT /MC_GENERIC/Phi$ +Title=Azimuthal distribution of all particles XLabel=$\phi$ YLabel=$1/\sigma \; \mathrm{d}\sigma/\mathrm{d}\phi$ LogY=0 LegendYPos=0.5 # END PLOT -# BEGIN PLOT /MC_GENERIC/Phi -Title=Azimuthal distribution of all particles +# BEGIN PLOT /MC_GENERIC/PhiCh +Title=Azimuthal distribution of charged particles XLabel=$\phi$ YLabel=$1/\sigma \; \mathrm{d}\sigma/\mathrm{d}\phi$ LogY=0 LegendYPos=0.5 # END PLOT -# BEGIN PLOT /MC_GENERIC/PtCh -Title=Transverse momentum of charged particles +# BEGIN PLOT /MC_GENERIC/Pt$ +Title=Transverse momentum of all particles XLabel=$p_\perp$ [GeV] YLabel=$1/\sigma \; \mathrm{d}\sigma/\mathrm{d}p_\perp$ [GeV$^{-1}$] FullRange=1 # END PLOT -# BEGIN PLOT /MC_GENERIC/Pt -Title=Transverse momentum of all particles +# BEGIN PLOT /MC_GENERIC/PtCh +Title=Transverse momentum of charged particles XLabel=$p_\perp$ [GeV] YLabel=$1/\sigma \; \mathrm{d}\sigma/\mathrm{d}p_\perp$ [GeV$^{-1}$] FullRange=1 # END PLOT -# BEGIN PLOT /MC_GENERIC/RapidityCh -Title=Rapidity of charged particles +# BEGIN PLOT /MC_GENERIC/Rapidity$ +Title=Rapidity of all particles XLabel=$y$ YLabel=$1/\sigma \; \mathrm{d}\sigma/\mathrm{d}y$ LogY=0 LegendYPos=0.5 # END PLOT -# BEGIN PLOT /MC_GENERIC/RapidityChPMRatio -Title=Rapidity $+/-$ ratio of charged particles +# BEGIN PLOT /MC_GENERIC/RapidityPMRatio +Title=Rapidity $+/-$ ratio of all particles XLabel=$|y|$ YLabel=$\mathrm{d}\sigma/\mathrm{d}y_+ \; / \; \mathrm{d}\sigma/\mathrm{d}y_-$ LogY=0 LegendYPos=0.5 # END PLOT -# BEGIN PLOT /MC_GENERIC/Rapidity -Title=Rapidity of all particles +# BEGIN PLOT /MC_GENERIC/RapidityCh$ +Title=Rapidity of charged particles XLabel=$y$ YLabel=$1/\sigma \; \mathrm{d}\sigma/\mathrm{d}y$ LogY=0 LegendYPos=0.5 # END PLOT -# BEGIN PLOT /MC_GENERIC/RapidityPMRatio -Title=Rapidity $+/-$ ratio of all particles +# BEGIN PLOT /MC_GENERIC/RapidityChPMRatio +Title=Rapidity $+/-$ ratio of charged particles XLabel=$|y|$ YLabel=$\mathrm{d}\sigma/\mathrm{d}y_+ \; / \; \mathrm{d}\sigma/\mathrm{d}y_-$ LogY=0 Modified: trunk/include/Rivet/Run.hh ============================================================================== --- trunk/include/Rivet/Run.hh Thu Jun 2 22:58:07 2011 (r3122) +++ trunk/include/Rivet/Run.hh Thu Jun 2 23:45:53 2011 (r3123) @@ -47,11 +47,11 @@ /// @name File processing stages //@{ - /// Set up HepMC file readers - bool init(const std::string& evtfile); + /// Set up HepMC file readers (using the appropriate file weight for the first file) + bool init(const std::string& evtfile, double weight=1.0); - /// Open a HepMC GenEvent file - bool openFile(const std::string& evtfile); + /// Open a HepMC GenEvent file (using the appropriate file weight for the first file) + bool openFile(const std::string& evtfile, double weight=1.0); /// Read the next HepMC event bool readEvent(); @@ -70,11 +70,14 @@ /// AnalysisHandler object AnalysisHandler& _ah; - /// @name Run variables obtained from events or command line //@{ - /// Cross-section from command line + /// @brief An extra event weight scaling per event file. + /// Useful for e.g. AlpGen n-parton event file combination. + double _fileweight; + + /// Cross-section from command line. double _xs; //@} Modified: trunk/src/Core/Run.cc ============================================================================== --- trunk/src/Core/Run.cc Thu Jun 2 22:58:07 2011 (r3122) +++ trunk/src/Core/Run.cc Thu Jun 2 23:45:53 2011 (r3123) @@ -3,13 +3,14 @@ #include "Rivet/AnalysisHandler.hh" #include "HepMC/IO_GenEvent.h" #include "Rivet/Projections/Beam.hh" +#include "Rivet/Math/MathUtils.hh" #include <limits> namespace Rivet { Run::Run(AnalysisHandler& ah) - : _ah(ah), _xs(-1.0) + : _ah(ah), _fileweight(1.0), _xs(-1.0) { } @@ -38,15 +39,23 @@ /// @todo Clear rather than new the GenEvent object per-event? _evt.reset(new GenEvent()); if (_io->rdstate() != 0 || !_io->fill_next_event(_evt.get()) ) { - Log::getLog("Rivet.Run") << Log::DEBUG - << "Read failed. End of file?" << endl; + Log::getLog("Rivet.Run") << Log::DEBUG << "Read failed. End of file?" << endl; return false; } + // Rescale event weights by file-level weight, if scaling is non-trivial + if (!fuzzyEquals(_fileweight, 1.0)) { + for (size_t i = 0; i < _evt->weights().size(); ++i) { + _evt->weights()[i] *= _fileweight; + } + } return true; } - bool Run::openFile(const std::string& evtfile) { + bool Run::openFile(const std::string& evtfile, double weight) { + // Set current weight-scaling member + _fileweight = weight; + // Set up HepMC input reader objects if (evtfile == "-") { _io.reset(new HepMC::IO_GenEvent(std::cin)); @@ -63,8 +72,8 @@ } - bool Run::init(const std::string& evtfile) { - if (!openFile(evtfile)) return false; + bool Run::init(const std::string& evtfile, double weight) { + if (!openFile(evtfile, weight)) return false; // Read first event to define run conditions bool ok = readEvent();
More information about the Rivet-svn mailing list |