diff --git a/doc/ReleaseNotes.md b/doc/ReleaseNotes.md index a7e3244..799aea2 100644 --- a/doc/ReleaseNotes.md +++ b/doc/ReleaseNotes.md @@ -1,890 +1,894 @@ # Laura++ release notes +22nd June 2023 Thomas Latham +* Added functionality to properly manage Gaussian constraints in toy generation + - see https://phab.hepforge.org/T45 + 9th June 2023 Mark Whitehead * Added functionality to include n-dimensional Gaussian constraints - see https://phab.hepforge.org/T214 21st November 2022 Andy Morris * Use Minuit to automatically determine ASq max for signal in LauIsobarDynamics - see https://phab.hepforge.org/D85 28th June 2022 Thomas Latham * Improvements to Doxygen config 31st May 2022 Thomas Latham * Add examples for easily generating toy samples uniformly in any DP or SqDP * Very minor updates to related QuasiFlatSqDalitz examples 30th November 2021 Thomas Latham * Update CI config to: - Simplify changing compiler version - Disallow dev build failure in scheduled pipelines 7th September 2021 Thomas Latham * Update CI to test future ROOT versions in dev3/dev4 LCG builds 1st July 2021 Thomas Latham * Add version of QuasiFlatSqDalitz where particle masses can be supplied on command line 28th June 2021 Thomas Latham * Fix for compilation with ROOT 6.24 18th May 2021 Mark Whitehead * Add new MIPW example - see https://phab.hepforge.org/T147 26th March 2021 Thomas Latham * Fix bug in setting for linear interpolation in Lau1DHistPdf - see https://phab.hepforge.org/T142 9th March 2021 Mark Whitehead * Update particle properties to PDG 2020 - see https://phab.hepforge.org/T140 5th March 2021 Dan Johnson * Alterations to allow Blatt-Weisskopf factor for parent to be created in a model with only a K-matrix - see https://phab.hepforge.org/D52 4th February 2021 Dan Johnson * Extend the K-matrix implementation to handle non-zero spin - see https://phab.hepforge.org/T135 1st February 2021 Dan Johnson * Allow floating of parameters in the K-matrix - see https://phab.hepforge.org/T59 2nd December 2020 Thomas Latham * Fix LauFormulaPar to follow change in behaviour of TFormula - see https://phab.hepforge.org/T129 27th November 2020 Dan Johnson * Allow slope of NR exponential model to vary negative - improves fit stability in low-statistics fits - see https://phab.hepforge.org/T128 17th September 2020 Mark Whitehead * Begin updates to use inclusive language. Simultaneous fits now handled by Coordinator and Tasks - see https://phab.hepforge.org/T112 19th August 2020 Thomas Latham * Remove explicit normalisation of numerator Blatt-Weisskopf factors - See https://phab.hepforge.org/T93 22nd May 2020 Thomas Latham * Fix uninitialised variable (related to rho-omega mixing) in LauIsobarDynamics 12th December 2019 Thomas Latham & Daniel Johnson * Fix issue with generation of events for categories with small expected yield - See https://phab.hepforge.org/T76 21st November 2019 Thomas Latham * Add QuasiFlatSqDalitz example, which generates toy according to EvtGen's FLATSQDALITZ model 6th - 20th November 2019 Thomas Latham * Adopt CMake as the build system - See https://phab.hepforge.org/T33 === ## Laura++ v3r5 6th August 2019 Thomas Latham * Add some extra charmonium states to list of known resonances * Minor modifications to code for importing parameter values from file 17th May 2019 Thomas Latham * Fix licences and Doxygen in pole, nonresonant form factors, and rescattering line shapes * Add journal reference for pole line shape * Fix class names and add Doxygen to LauCalcChiSq, LauResultsExtractor, LauMergeDataFiles * Update Doxyfile from more recent Doxygen version * Make consistent the use of ClassDef and ClassImp everywhere * Add functions to return the "sanitised" names of parent and daughters 8th January 2019 Thomas Latham * Workaround for issue with splitting toy MC files when generating large number of experiments 5th December 2018 Thomas Latham * Move sources and headers for the utilities library into the main library - makes examples dir executables only (in preparation for CMake build) 22nd, 23rd July and 4th August 2018 Juan Otalora * Add pole, nonresonant form factors, and rescattering line shapes 17th April 2018 Daniel O'Hanlon * Fix bug in rho-omega mixing fit-fraction calculation: rho fit-fraction was not normalised to the total DP rate 23rd March 2018 Thomas Latham * Some fixes in LauRhoOmegaMix that propagate the following settings to the subcomponents: - spinType_ - flipHelicity_ - ignoreMomenta_ - ignoreSpin_ - ignoreBarrierScaling_ 23rd February 2018 Thomas Latham * Add section on structure of package to README file (requested by CPC technial editor) * Add copyright notice to files in test directory 21st February 2018 Thomas Latham * Improve comments in functions calculating helicity angles in LauKinematics 19th February 2018 Daniel O'Hanlon * Fix bug in LauCPFitModel introduced in code for importing parameters (25/01/18) - When parameters are asked to be randomised via useRandomInitFitPars, those parameters that were already fixed in the model, in addition to those that are fixed on import, were being freed. 19th February 2018 Daniel O'Hanlon * Bug fixes in rho/omega fit fractions calculation 25th January 2018 Daniel O'Hanlon * Add feature for importing parameters into LauCPFitModels from previous fit output files. 23rd January 2018 Daniel O'Hanlon * Calculate separate rho and omega fit-fractions for LauRhoOmegaMix, when turned on with calculateRhoOmegaFitFractions in LauIsobarDynamics. === ## Laura++ v3r4 16th January 2018 Thomas Latham * Update licence for all files to the Apache Software License Version 2.0 14th December 2017 Thomas Latham * Correct LauFlatteRes to use the exact formulae from the papers that report the default parameter values for each supported resonance - Deals correctly now with the cases where the m0 is absorbed into the couplings - Now uses the correct value of g1 for the a_0(980) (needed to be squared) - Also sets the mass values to those reported in those papers - Added printout to specify what is being done in each case * Improve the consistency between the weightEvents functions in LauSimpleFitModel and LauCPFitModel - Also remove the unecessary division by ASqMax in LauIsobarDynamics::getEventWeight 4th December 2017 Thomas Latham * Allow background yields to be specified as any LauAbsRValue (i.e. LauParameter or now also LauFormulaPar) 30th November 2017 Thomas Latham * In LauFitDataTree::readExperimentData add a check that the tree contains the branch "iExpt" and if not: - If the requested experiment is 0 then read all data in the tree (and print a warning) - Otherwise print an error message and return 29th November 2017 Thomas Latham * Improve error messages in LauCPFitModel::weightEvents === ## Laura++ v3r3 23rd November 2017 Thomas Latham * Add an example written as a python script: GenFit3pi.py * Various improvements to the other example code 23rd November 2017 Thomas Latham * Fix bug in the LauAbsResonance constructor used by the K-matrix - "resonance" charge is now set to the sum of the daughter charges 1st November 2017 Thomas Latham * Fix bug in LauFlatteRes - m_0 factor multiplying the width was, if useAdlerTerm_ is true, replaced by f_Adler rather than being multiplied by it - only affected case where using LauFlatteRes to describe K_0*(1430) === ## Laura++ v3r2 18th October 2017 Thomas Latham * Modify LauDaughters::testDPSymmetry to: - produce an ERROR message and exit if the symmetric DP does not have its daughters arranged correctly - detect also flavour-conjugate DPs and set a corresponding flag that can be retrieved via LauDaughters::gotFlavourConjugateDP - in this case if the daughters are sub-optimally arranged print a WARNING * Modify LauIsobarDynamics::calcDPNormalisationScheme so that any narrow resonance regions are symmetrised appropriately if the DP is fully-symmetric, symmetric or is flavour-conjugate (and in this last case, symmetrisation of the integration has been forced via a new boolean function) 11th October 2017 Thomas Latham * Allow the user to specify the randomiser to be used to randomise the initial values of the isobar parameters - simply use the new static function LauAbsCoeffSet::setRandomiser - if not specified it defaults to the current use of LauRandom::zeroSeedRandom 10th October 2017 Thomas Latham * Make symmetrisation of vetoes automatic in LauVetoes for symmetric DPs - but add new allowed indices (4 and 5) to allow vetoes to be applied to mMin or mMax if desired * Also apply to fully symmetric DPs * In addition implement the more efficient calculation of the amplitude in the fully symmetric case 23rd September 2017 Thomas Latham * Fix expressions for Covariant option for Blatt-Weisskopf momentum for spin > 1 * Make use of setSpinFormalism to set the formalism to Legendre for NR types (instead of kludging with ignoreMomentum) 15th September 2017 Thomas Latham * Various improvements to the examples 6th September 2017 Thomas Latham * Improve doxygen comments for event-embedding functions in fit models 5th September 2017 Thomas Latham * Improve efficiency of Covariant spin factor calculations 31st August 2017 Thomas Latham * Add further option for parent Blatt-Weisskopf momentum - Covariant (corresponding to Covariant spin factor) 8th August 2017 Thomas Latham * Implement expressions for the spin factor based on covariant tensor formalism * Make it much simpler to switch between formalism options via new functions in LauResonanceMaker: - setSpinFormalism, setBWType, setBWBachelorRestFrame - default settings are unchanged (and are equivalent to setting LauAbsResonance::Zemach_P, LauBlattWeisskopfFactor::BWPrimeBarrier, LauBlattWeisskopfFactor::ResonanceFrame, respectively) 21st July 2017 Thomas Latham * Add note to README file about compilation issue on Ubuntu 16.04 LTS 21st July 2017 Thomas Latham * Create public functions to update the kinematics based on one invariant mass and the corresponding helicity angle 20th June 2017 Daniel O'Hanlon * Terminate when asked to read a non-existent K-matrix parameter file 8th June 2017 Thomas Latham * Fix compilation error on gcc 4.9 30th May 2017 Thomas Latham * Permit different efficiency histograms to be defined in classic/square DP and force enable calculation of square DP coords (here and for background PDFs) if required 29th May 2017 Thomas Latham * Propagate information on EDM from the minimiser to the fit models and into the fit results ntuple 29th May 2017 Thomas Latham * Ensure that the kinematics will calculate the square DP co-ordinates if the integration requires them 29th May 2017 Thomas Latham * Reintegrate the RooFit-slave branch into the trunk (and delete the branch) 28th March 2017 Thomas Latham (in branch for developing RooFit-based slave) * Rename cacheFitData to verifyFitData in all fit models and RF-slave 28th March 2017 Daniel O'Hanlon * Fix bug in LauCPFitModel::weightEvents 24th March 2017 Thomas Latham (in branch for developing RooFit-based slave) * Refactor code between fit models, master, slave and fit-object classes 22nd March 2017 Thomas Latham (in branch for developing RooFit-based slave) * Make the compilation of the RF-based slave class, and its associated example binary, optional 22nd March 2017 Thomas Latham (in branch for developing RooFit-based slave) * Complete working example of RooFit-based slave - Have identified some scope for refactoring of code - Also want to make the compilation of this class, and its associated example binary, optional 15th March 2017 Mark Whitehead (in branch for developing time-dependent model) * Handle event-by-event mistag probabilities 7th March 2017 Thomas Latham * Rename the command for weighting events from "reweight" to "weight" 3rd March 2017 Daniel O'Hanlon * Implement LauCPFitModel::weightEvents based on the same function in LauSimpleFitModel 1st March 2017 Thomas Latham (in branch for developing RooFit-based slave) * Fix root-cling related errors 28th February 2017 Thomas Latham (in branch for developing RooFit-based slave) * Start work on creation of RooFit-based slave class - Will allow RooFit-based fitters to plug-in straightforwardly to the simultaneous fitting (JFit) framework 20th February 2017 Thomas Latham * Add warning messages to LauBkgndDPModel::setBkgndHisto when supplied backgroud histogram pointers are null 31st January 2017 Thomas Latham * Audit of the code to automate the creation of the integration binning scheme. - Fix one bug, some tidy-ups, and reintroduce a couple of lost features: - the use of a single square-DP grid if a narrow resonance is found in m12 - extension of region down to threshold if the narrow resonance is close to threshold 22nd January 2017 Daniel O'Hanlon * Fix bug in automated integration scheme where resonances were assumed to have been added in order of ascending mass 14th December 2016 Daniel O'Hanlon * Add several light resonances to the list in LauResonanceMaker 13th December 2016 Daniel O'Hanlon * Automate the determination of the integration scheme for an arbitrary number of narrow resonances in m13 and m23 12th December 2016 Daniel O'Hanlon * Efficiency saving from modifying the behaviour of LauIsobarDynamics::calculateAmplitudes, LauIsobarDynamics::resAmp and LauIsobarDynamics::incohResAmp in the case of symmetric DPs - Previously, there were 2N calls to LauKinematics::flipAndUpdateKinematics for N resonances, now reduced to 2 21st November 2016 John Back * Added two K-matrix examples for creating pedagogical plots (with associated data files): - B3piKMatrixPlots for K-matrix elements, propagator, and pole and SVP production terms - B3piKMatrixMassProj for pole and SVP mass projections generated over the DP 17th November 2016 John Back * Modifications of the K matrix implementation: - Changed the format of the parameter file to use keywords, with updated examples - The scattering coefficients are now symmetrised, unless "ScattSymmetry 0" is used - Allow the option to use the Adler zero suppression term for the production poles and SVPs (default = off). These are specified with the useProdAdler boolean in the LauKMatrixProdPole/SVP constructors - Added a few helper functions for obtaining coefficients and (internal) matrices - Added a method to return the Lorentz-invariant transition amplitude for plots/tests 1st November 2016 Wenbin Qian * Add calculation of so-called covariant factors for spin amplitude === ## Laura++ v3r1 9th September 2016 Thomas Latham * Modification of LauFitNtuple to check the size of the covariance matrix wrt known number of parameters and act accordingly: - If it is empty, just fill a diagonal correlation matrix and issue a warning. - If it results from a failed first stage of a two-stage fit then the correlation matrix is padded with 1s and 0s for the parameters that were fixed in the first stage. * Remove the feature that allows parameters to float in first stage of a two-stage fit but to be fixed in second. * Minor fix to LauAbsCoeffSet: the names of parameters would be mangled if they were the same as the basename, e.g. A1_A would become A1_ while A1_B would be correct. 8th September 2016 Thomas Latham * Modifications to LauResonanceInfo to allow customisation of which extra parameters are shared between charge conjugate or shared-parameter records. - Where the parameters are not shared they are independently created instead of being cloned. * Modification of LauRhoOmegaMix to take advantage of the above to have the magB and phiB parameters independent. * Addition to LauResonanceMaker of rho(770)_COPY record that is a shared record with rho(770) - this allows the above new feature to be used. * Minor unrelated improvement to information messages in LauIsobarDynamics. 25th August 2016 John Back * Modified LauRhoOmegaMix to allow either a RelBW or GS lineshape for the rho, as well as allowing the option to set the second-order denominator term to be equal to unity. Also fixed the bug where the spinTerm was not included in the rho-omega amplitude. Changed the LauAbsResonance enum from RhoOmegaMix to RhoOmegaMix_GS, RhoOmegaMix_RBW, RhoOmegaMix_GS_1 and RhoOmegaMix_RBW_1, where _1 sets the denominator term to unity and _GS or _RBW sets the appropriate rho lineshape. The omega is always a RelBW. * Added to LauAbsResonance: ignoreSpin and ignoreBarrierScaling boolean flags, which ignore either the spin terms or the barrier scaling factors for the amplitude. The latter does not turn off the resonance barrier factor for mass-dependent widths * Added to LauResonanceMaker: getResInfo(resonanceName), which retrieves the resonance information. This is used to obtain the PDG omega values for initialising LauRhoOmegaMix * Made LauRelBreitWignerRes ignore momentum-dependent terms for the resonance width if ignoreMomenta is set. This is used in the LauRhoOmegaMix for the omega lineshape where its width does not depend on momentum 23rd May 2016 John Back * Added new lineshape model for rho-omega mass mixing, LauRhoOmegaMix. 12th April 2016 Thomas Latham * Switch to integrating in square DP when narrow resonances are found in m12. - The integration grid size can be specified by the user 19th January 2016 John Back * Correct the f(m^2) factor in the denominator of the LauGounarisSakuraiRes lineshape to use Gamma_0 instead of Gamma(m) 14th January 2016 Thomas Latham * Documentation improvements 7th December 2015 Thomas Latham * Resolve bug that meant the order of resonances in LauIsobarDynamics was assumed to match with the order in which the complex coefficients are supplied to the fit model - The ordering of resonances is defined by LauIsobarDynamics: - Firstly all coherent resonances in order of addition - Followed by all incoherent resonances in order of addition - The complex coefficients are now rearranged to match that order - Printout of the model summary at the end of initialisation has been enhanced to indicate the ordering - Doxygen updated to reflect these changes 12th November 2015 Daniel Craik * Added support for Akima splines and linear interpolation to Lau1DCubicSpline * LauAbsModIndPartWave, LauModIndPartWaveRealImag and LauModIndPartWaveMagPhase updated to allow choice of spline interpolation method * LauEFKLLMRes updated to use Akima splines 10th November 2015 Thomas Latham & Daniel Craik * Add the EFKLLM form-factor model for the Kpi S-wave and an example using this lineshape * Modify LauResonanceMaker::getResonance to use a switch for greater clarity and easier checking on missing cases 4th November 2015 Daniel Craik * Add checks to LauIsobarDynamics::addResonance and LauIsobarDynamics::addIncohResonance to stop the wrong type of LauResonanceModel being used - LauAbsResonance::isIncoherentModel method added to identify incoherent models 8th September 2015 Mark Whitehead * Add the ability to modify the error of parameters via the CoeffSet - setParameterError added to LauAbsCoeffSet * Tweak the handling of initial error values passed to MINUIT (to determine initial step size) in LauMinuit 7th September 2015 Mark Whitehead * Add the ability to Gaussian constrain parameters via the CoeffSet - addGaussianConstraint added to LauAbsCoeffSet 12th June 2015 Thomas Latham * Modifications to Belle-style nonresonant models - LauBelleNR modified to use pure Legendre polynomials of cos(theta) in the spin term (i.e. to remove the q*p factors) - New form added to LauBelleSymNR (LauAbsResonance::BelleSymNRNoInter) that removes the interference term between the two DP halves - The new form also works with non-zero spin (warning added if non-zero spin specified for BelleSymNR and TaylorNR) 8th June 2015 Thomas Latham * Further work on the blinding mechanism: - New method added LauParameter::blindParameter that activates the blinding. - The rest of the framework updated to use another new method LauParameter::unblindedValue in all likelihood calculations etc. - Example GenFitNoDP updated to include lines to optionally blind the yield parameters. 29th May 2015 Daniel Craik * Added LauBlind class for blinding and unblinding a value with an offset based on a blinding string 26th May 2015 Daniel Craik * Stopped LauCPFitModel passing fixed signal/background yields or asymmetries to Minuit to avoid hitting limit of 101 fixed parameters 22nd April 2015 Daniel Craik * Updated MIPW classes to use Lau1DCubicSpline 19th April 2015 Daniel Craik * Added Lau1DCubicSpline class for 1D spline interpolation 26th March 2015 Thomas Latham * Reworked MIPW code into abstract base class and derived classes to allow different representations of the amplitude at each knot 31st December 2015 Daniel Craik * Added unbinned goodness of fit tests to examples 12th January 2015 Daniel Craik * Calculate effective masses for virtual resonances above the upper kinematic limit 10th December 2014 Daniel Craik * Added coefficient sets to extract gamma from a simultaneous fit to CP and nonCP final states, such as the B0->D_CP K pi and B0->D0bar K pi Dalitz plots, as proposed in Phys. Rev. D79, 051301 (2009) - LauPolarGammaCPCoeffSet uses the CP parameters r, delta and gamma directly - LauRealImagGammaCPCoeffSet parameterises CPV as X_CP+/- and Y_CP+/- - LauCartesianGammaCPCoeffSet parameterises CPV as X_CP, Y_CP DeltaX_CP DeltaY_CP - Fixed CP parameters are not passed to the fitter so the same coefficient sets can be used for both the CP and nonCP Dalitz plots - LauPolarGammaCPCoeffSet allows for a single gamma parameter to be shared between multiple resonances - LauAbsCoeffSet::adjustName made virtual to allow global variables such as gamma to not receive a prefix === ## Laura++ v3r0p1 19th June 2015 Thomas Latham * Factor out the JFit slave code from LauAbsFitModel into a new base class LauSimFitSlave 19th June 2015 Thomas Latham * Fix check in LauIsobarDynamics::calcDPNormalisationScheme to avoid using hardcoded number === ## Laura++ v3r0 24th October 2014 Thomas Latham * Fixed bug in floating of Blatt-Weisskopf barrier radii - The values at the pole mass were not being updated when the radii changed 21st October 2014 Daniel Craik * Fixed bug in LauIsobarDynamics where multiple incoherent amplitudes led to nonsensical fit fractions 17th October 2014 John Back * Added the ability to calculate the transition amplitude matrix T in LauKMatrixPropagator, as well as a few other minor speed-up changes and code checks. Example/PlotKMatrixTAmp.cc can be used to check the T amplitude variation, phase shift and inelasticity, for a given K matrix channel, as a function of the invariant mass squared variable s 15th October 2014 Thomas Latham * Add methods to LauIsobarDynamics to make the integration binning more tunable by the user: - setNarrowResonanceThreshold - modify the value below which a resonance is considered to be narrow (defaults to 0.02 GeV/c2) - setIntegralBinningFactor - modify the factor by which the narrow resonance width is divided to obtain the bin size (defaults to 100) * Print warning messages if the memory usage is likely to be very large 13th October 2014 Thomas Latham * Modify Makefile to allow compilation with ROOT 6 (in addition to maintaining support for ROOT 5) * Fix a few compilation errors on MacOSX 10.9 13th October 2014 Daniel Craik * Update LauModIndPartWave to allow knots at kinematic limits to be modified - Add new method setKnotAmp to modify existing knots (and the knot at the upper kinematic limit which is automatically added at initialisation) * Update doxygen for LauIsobarDynamics::addIncoherentResonance to mention that incoherent resonances must be added last 10th October 2014 Thomas Latham * Add new method to LauResonanceMaker to set whether the radius of a given Blatt-Weisskopf category should be fixed of floated * Modify the methods of LauResonanceMaker to set the radius value and whether it should be floated so that they work before and after the resonances have been created 9th October 2014 John Back * Corrected the eta-eta' and 4pi phase space factors in LauKMatrixPropagator, which is used for the K-matrix amplitude: - calcEtaEtaPRho() does not include the mass difference term m_eta - m_eta' following the recommendation in hep-ph/0204328 and from advice from M Pennington - calcFourPiRho() incorporates a better parameterisation of the double integral of Eq 4 in hep-ph/0204328 which avoids the exponential increase for small values of s (~< 0.1) - More detailed comments are provided in the above two functions to explain what is going on and the reason for the choices made 6th October 2014 Thomas Latham * Implement the mechanism for floating Blatt-Weisskopf barrier factor radius parameters 30th September 2014 Thomas Latham * Fix issue in the checks on toy MC generation validity - in the case of exceeding max iterations it was possible to enter an infinite loop - the checks now detect all three possible states: - aSqMaxSet_ is too low (generation is biased) => increase aSqMaxSet_ value - aSqMaxSet_ is too high => reduce aSqMaxSet_ value to improve efficiency - aSqMaxSet_ is high (causing low efficiency) but cannot be lowered without biasing => increase iterationsMax_ limit * Update resonance parameter in LauResonanceMaker to match PDG 2014 * Modify behaviour when TTree objects are saved into files to avoid having multiple cycle numbers present 29th September 2014 Daniel Craik * Add support for incoherent resonances in the signal model - LauIsobarDynamics updated to include incoherent terms - ABC for incoherent resonances, LauAbsIncohRes, added deriving from LauAbsResonance - LauGaussIncohRes added to implement a Gaussian incoherent resonance, deriving from LauAbsIncohRes - Small changes to various other classes to enable incoherent terms * Fixed small bug in LauMagPhaseCoeffSet which could hang if phase is exactly pi or -pi * Added charged version of the BelleNR resonances to LauResonanceMaker * Updated parameters in LauConstants to match PDG 2014 14th July 2014 Thomas Latham * Add intial support for fully-symmetric final states such as B0 -> KS KS KS - Performs the symmetrisation of the signal model - Background (and efficiency) histogram classes need some work if the user wants to provide folded histograms 8th July 2014 Daniel Craik * Add class for model-independent partial wave - Uses splines to produce a smooth amplitude from a set of magnitude and phase values at given invariant masses - The individual magnitudes and phases can be floated in the fit 16th June 2014 Thomas Latham * Allow floating of resonance parameters in simultaneous fits 13th June 2014 Thomas Latham * Fix bug in LauResonanceInfo cloning method, where the width parameter was given a clone of the mass 10th June 2014 Thomas Latham * Add new function to allow sharing of resonance parameters between components that are not charged conjugates, e.g. LASS_BW and LASS_NR 9th June 2014 Thomas Latham and Daniel Craik * Fix bug in the new integration scheme - Was not accounting for cases where several resonances share a floating parameter - Meant that the integrals and caches for that resonance were not being updated * Introduce a change in the implementation of the helicity flip for neutral parent decays - Prior to this change the helicity was flipped for any neutral resonance in the decay of a neutral particle. - Now the flip no longer occurs in flavour-specific decays (such as Bs0 -> D0bar K- pi+ or B0 -> K+ pi- pi0) since it is only required in flavour-conjugate modes (such as B0 -> KS pi+ pi-). - This does not affect any physical results but it does contribute a pi phase flip to some odd-spin resonances (for example K*(892)0 in Bs0->D0barKpi). - Therefore results are not necessarily comparable between fits run before and after this changeset. - This change will first be released in v3r0. === ## Laura++ v2r2 5th June 2014 Thomas Latham * Fix issue in asymmetric efficiency histogram errors - Fluctuation of bins was incorrectly sampling - assumed area each side of peak was the same 5th June 2014 Thomas Latham (in branch for release in v3r0) * Introduce intelligent calculation of amplitudes during recalculation of integrals and recaching of data points - Floating resonance parameters is now much more efficient * Make resonance parameters second-stage, also improves fit timing when floating them 3rd June 2014 Rafael Coutinho * Implement generation of toy MC from fit results in fitSlave 27th May 2014 Thomas Latham (in branch for release in v3r0) * Complete audit of special functions * Remove unncessary LauAbsDPDynamics base class and move all functionality into LauIsobarDynamics 20th May 2014 Daniel Craik (in branch for release in v3r0) * Add support for K*_0(1430) and a_0(980) to LauFlatteRes 16th-19th May 2014 Thomas Latham and Daniel Craik (in branch for release in v3r0) * Update all other lineshapes so that their parameters can float - The only resonance parameters that now cannot float are the Blatt-Weisskopf barrier factor radii 15th May 2014 Thomas Latham (in branch for release in v3r0) * Change the mechanism for getting floating resonance parameters into the fit - Moved from LauResonanceMaker to the resonances themselves - Lays some groundwork for improving the efficiency of recalculating the integrals - LauBelleNR and LauBelleSymNR lineshape parameters can now be floated 13th May 2014 Daniel Craik (in branch for release in v3r0) * Fix bug where illegal characters were being propagated from resonance names into TBranch names 6th May 2014 Thomas Latham (in branch for release in v3r0) * Provide accessors for mass and width parameters 5th May 2014 Louis Henry * Fix compilation problem by making LauDatabasePDG destructor virtual 4th May 2014 Thomas Latham * Provide a new argument to LauSimpleFitModel::splitSignalComponent and LauCPFitModel::splitSignalComponent to allow fluctuation of the bins on the SCF fraction histogram 29th April 2014 Thomas Latham * Fix bug in the determination of the integration scheme - Nearby narrow resonances caused problems if their "zones" overlap - These zones are now merged together 29th April 2014 Thomas Latham (in branch for release in v3r0) * Some improvments to integration scheme storage 26th April 2014 Juan Otalora (in branch for release in v3r0) * Make integation scheme fixed after first determination - is stored in a new class LauDPPartialIntegralInfo - used on subsequent re-evaluations of the integrals 23rd April 2014 Thomas Latham * Attempt to improve clarity of LauIsobarDynamics::addResonance function - the 3rd argument is now an enumeration of the various resonance models - removed the optional arguments regarding the change of mass, width & spin - the same functionality can be obtained by using the returned pointer and calling changeResonance - the resonance name now only affects the lineshape in the LauPolNR case - the BelleSymNR / TaylorNR choice is now made in the 3rd argument - similarly for the BelleNR / (newly introduced) PowerLawNR choice * Add new PowerLawNR nonresonant model (part of LauBelleNR) * All examples updated to use new interface 23rd April 2014 Thomas Latham * Address issue of setting values of resonance parameters for all models - decided to do away with need to have LauIsobarDynamics know everything - LauIsobarDynamics::addResonance now returns a pointer to LauAbsResonance - parameters can be changed through LauAbsResonance::setResonanceParameter - LauIsobarDynamics still knows about Blatt-Weisskopf factors - better to only need to set this once - Update GenFit3pi example to demonstrate mechanism 22nd April 2014 Thomas Latham * Allow Gaussian constraints to be added in simultaneous fitting - constraints will be ignored by the slaves - those added directly to fit parameters will be propogated to the master and handled there - those on combinations of parameters should be added in the master process 22nd April 2014 Mark Whitehead * Update Laura to cope with resonances of spin 4 and spin 5 - Zemach spin terms added to src/LauAbsResonance.cc - BW barrier factors added to src/LauRelBreitWignerRes.cc 19th April 2014 Daniel Craik * Add LauWeightedSumEffModel which gives an efficiency model from the weighted sum of several LauEffModel objects. * Added pABC, LauAbsEffModel, for LauEffModel and LauWeightedSumEffModel. * Various classes updated to use pointers to LauAbsEffModel instead of LauEffModel. 15th April 2014 Daniel Craik * Enable LauEfficiencyModel to contain several Lau2DAbsDP objects with the total efficiency calculated as the product. 10th April 2014 Mark Whitehead * Fix an issue with the likelihood penalty term for Gaussian constraints - Factor two missing in the denominator - New penalty term is: ( x-mean )^2 / 2*(width^2) 4th April 2014 Thomas Latham * Add storage of fit fractions that have not been efficiency corrected === ## Laura++ v2r1 1st April 2014 Thomas Latham * Fix issue in LauFitter that prevents compilation with g++ 4.8 - Missing virtual destructor - Take opportunity to audit other special functions 31st March 2014 Mark Whitehead (in branch for release in v2r1) * Added an efficiency branch to the ntuple produced for toy data samples - Both LauSimpleFitModel and LauCPFitModel updated 28th March 2014 Daniel Craik (in branch for release in v2r2) * Added support for asymmetric errors to Lau2DHistDP, Lau2DSplineDP and LauEffModel. 27th March 2014 Daniel Craik * Changed histogram classes to use seeded random number generator for fluctuation and raising or lowering of bins and updated doxygen. 20th March 2014 Mark Whitehead (in branch for release in v2r1) * Added the ability to add Gaussian contraints to LauFormulaPars of fit parameters - User supplies the information but the LauFormulaPar is constructed behind the scenes 18th March 2014 Thomas Latham * Improve behaviour of toy generation from fit results 13th March 2014 Juan Otalora (in branch for release in v3r0) * Extended ability to float mass and width to other resonance lineshapes (Flatte, LASS and G-S) 11th March 2014 Mark Whitehead (in branch for release in v2r1) * Added the functionality to make LauFormulaPars usable in fits - Added a new class LauAbsRValue which LauParameter and LauFormularPar inherit from - Many files updated to accept LauAbsRValues instead of LauParameters * Fairly major clean up of obsolete functions in LauAbsPdf - Only LauLinearPdf used any of them, this has now been updated 10th March 2014 Thomas Latham (in branch for release in v3r0) * First attempt at floating resonance parameters (work mostly from Juan) - Only works for RelBW lineshape - Can only float mass and width - Works nicely! - Still needs much work to generalise and make more efficient === ## Laura++ v2r0 8th March 2014 Thomas Latham * Some additional functionality for the CoeffSet classes: - allow the parameter values to be set (optionally setting the initial and generated values as well) - allow the parameters to be set to float or to be fixed in the fit These are needed when cloning but wanting some of the parameters to have different values and/or floating behaviour from the cloned set. * Improve the printout of the setting of the coefficient values in the fit models and the creation of resonances * Add LauFlatNR for the unform NR model - ends its rather strange special treatment * Fix bug setting resAmpInt to 0 for LauPolNR * Many other improvements to the info/warning/error printouts * Modify GenFitBelleCPKpipi example to demonstrate cloning in action * Add -Werror to compiler flags (treats warnings as errors) 5th March 2014 Thomas Latham * Some improvements to LauPolNR to speed up amplitude calculation 2nd March 2014 Thomas Latham * A number of updates to the CoeffSet classes: - allow specification of the basename just after construction (before being given to the fit model) - allow configuration of the parameter fit ranges (through static methods of base class) - more adaptable cloning of the parameters (e.g. can only clone phase but allow magnitude to float independently) - allow CP-violating parameters to be second-stage in Belle and CLEO formats * Some improvements to the Doxygen and runtime information printouts 20th February 2014 Louis Henry * Add LauPolNR - class for modelling the nonresonant contribution based on BaBar 3K model (arXiv:1201.5897) 6th February 2014 Thomas Latham * Correct helicity convention information in Doxygen for LauKinematics === ## Laura++ v1r2 5th February 2014 Thomas Latham * Add rule to the Makefile that creates a rootmap file for the library 4th February 2014 Daniel Craik * Fixed bug in Lau2DSplineDPPdf - normalisation was not being calculated * Added out-of-range warning in LauBkgndDPModel and supressed excessive warnings 3rd February 2014 Mark Whitehead (in branch for release in v2r0) * Added a new class to allow parameters to be a function of other parameters - inc/LauFormulaPar.hh - src/LauFormulaPar.cc 28th January 2014 Daniel Craik * Improved out-of-range efficiency warnings in LauEffModel and supressed excessive errors * Modified LauIsobarDynamics to allow LASS parameters to be configured for LauLASSBWRes and LauLASSNRRes 27th January 2014 Daniel Craik * Added spline interpolation to DP backgrounds - Added Lau2DSplineDPPdf which uses a spline to model a normalised PDF across a DP - Added pABC, Lau2DAbsDPPdf, for Lau2DHistDPPdf and Lau2DSplineDPPdf and moved common code in Lau2DHistDPPdf and Lau2DSplineDPPdf into ABC Lau2DAbsHistDPPdf - LauBkgndDPModel, modified to use Lau2DAbsDPPdf instead of Lau2DHistDPPdf - setBkgndSpline method added to LauBkgndDPModel to allow use of splines 22nd January 2014 Thomas Latham * Improve some error checks and corresponding warning messages in LauCPFitModel::setSignalDPParameters 16th January 2014 Thomas Latham * Add LauRealImagCPCoeffSet, which provides an (x,y), (xbar,ybar) way of parametrising the complex coefficients. * Try to improve timing in the *CoeffSet classes by making the complex coeffs into member variables. 20th December 2013 Daniel Craik * Added Lau2DCubicSpline which provides cubic spline interpolation of a histogram - Added Lau2DSplineDP which uses a spline to model variation across a DP (eg efficiency) - Added pABC, Lau2DAbsDP, for Lau2DHistDP and Lau2DSplineDP and moved common code in Lau2DHistDP and Lau2DSplineDP into ABC Lau2DAbsHistDP - LauEffModel, LauDPDepSumPdf and LauDPDepMapPdf modified to use Lau2DAbsDP instead of Lau2DHistDP - setEffSpline method added to LauEffModel and useSpline flag added to constructor for LauDPDepSumPdf to allow use of splines 18th December 2013 Mark Whitehead (in branch for release in v2r0) * Added functionality to include Gaussian constraints on floated parameters in the fit. The files updated are: - inc/LauAbsFitModel.hh - inc/LauParameter.hh - src/LauAbsFitModel.cc - src/LauParameter.cc 5th December 2013 Thomas Latham * Fix small bug in GenFitKpipi example where background asymmetry parameter had its limits the wrong way around 4th December 2013 Daniel Craik * Updated 2D chi-squared code to use adaptive binning. 3rd December 2013 Thomas Latham * Generalise the Makefile in the examples directory - results in minor changes to the names of 3 of the binaries 3rd December 2013 Thomas Latham (in branch for release in v2r0) * Have the master save an ntuple with all fitter parameters and the full correlation matrix information. 29th November 2013 Thomas Latham * Fixed bug in ResultsExtractor where the output file was not written 29th November 2013 Thomas Latham (in branch for release in v2r0) * Allow the slave ntuples to store the partial covariance matrices in the simultaneous fitting 26th November 2013 Thomas Latham (in branch for release in v2r0) * Added first version of the simultaneous fitting framework === ## Laura++ v1r1p1 22nd November 2013 Thomas Latham * Fixed bug in LauCPFitModel where values of q = -1 extra PDFs were used regardless of the event charge. === ## Laura++ v1r1 20th November 2013 Mark Whitehead * Changed convention for the barrier factors, swapping from p* to p. This seems to give more physically reasonable results. The files updated are: - src/LauGounarisSakuraiRes.cc - src/LauRelBreitWignerRes.cc 18th October 2013 Thomas Latham * Fix dependency problem in Makefile 8th October 2013 Thomas Latham * Some fixes to yield implementation * Minor bug fix in DP background histogram class 7th October 2013 Mark Whitehead * Update to accept the yields and yield asymmetries as LauParameters. All examples have been updated to reflect this change. This updated the following files: - inc/LauCPFitModel.hh - inc/LauSimpleFitModel.hh - inc/LauAbsFitModel.hh - src/LauCPFitModel.cc - src/LauSimpleFitModel.cc * Addition of the following particles to src/LauResonanceMaker.cc Ds*+-, Ds0*(2317)+-, Ds2*(2573)+-, Ds1*(2700)+- and Bs*0 === ## Laura++ v1r0 13th September 2013 Thomas Latham * Initial import of the package into HEPforge diff --git a/examples/B3piKMatrixMassProj.cc b/examples/B3piKMatrixMassProj.cc index 2bdfe96..7de6a27 100644 --- a/examples/B3piKMatrixMassProj.cc +++ b/examples/B3piKMatrixMassProj.cc @@ -1,438 +1,439 @@ /* Copyright 2016 University of Warwick Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /* Laura++ package authors: John Back Paul Harrison Thomas Latham */ // Plot the mass projections of K-matrix amplitude terms generated over the Dalitz plot so that // we can see what shapes the poles and SVP components have. Also show the rho for comparison #include using std::cout; using std::endl; #include "LauCartesianCPCoeffSet.hh" #include "LauDaughters.hh" #include "LauEffModel.hh" #include "LauIsobarDynamics.hh" #include "LauKMatrixPropagator.hh" #include "LauParameter.hh" #include "LauResonanceMaker.hh" #include "LauSimpleFitModel.hh" #include "LauVetoes.hh" #include "TGraph.h" #include "TCanvas.h" #include "TStyle.h" #include "TROOT.h" #include "TSystem.h" #include "TString.h" #include "TH1.h" #include "TH2.h" #include "TTree.h" #include "TFile.h" #include "THStack.h" #include "TLegend.h" #include #include void createHistos(const std::string& rootFileName); void plotHistos(const std::string& rootFileName); std::vector genMassHistos(Int_t index, Int_t NSignal); Bool_t useProdAdler = kFALSE; int main(const int argc, const char** argv) { int histFlag(0), prodFlag(0); if (argc > 1) { histFlag = std::atoi(argv[1]); } if (argc > 2) { prodFlag = std::atoi(argv[2]); if (prodFlag != 0) {useProdAdler = kTRUE;} } std::string rootFileName("KMatrixMassHistos.root"); if (histFlag) {createHistos(rootFileName);} plotHistos(rootFileName); } void plotHistos(const std::string& rootFileName) { cout<<"Running plotHistos for "<SetStyle("Plain"); gStyle->SetOptStat(0); theCanvas->Clear(); theCanvas->UseCurrentStyle(); TFile* rootFile = TFile::Open(rootFileName.c_str(), "read"); rootFile->cd(); // Plot rho with K-matrix poles TLegend* poleLegend = new TLegend(0.7, 0.5, 0.90, 0.90, ""); poleLegend->SetFillColor(0); poleLegend->SetTextSize(0.03); THStack* poleStack = new THStack(); TH1* rhoHist = dynamic_cast(rootFile->Get("Rho_m13")); rhoHist->SetLineColor(kBlack); rhoHist->SetLineWidth(2); rhoHist->Scale(1.0/rhoHist->Integral()); poleStack->Add(rhoHist); poleLegend->AddEntry(rhoHist, "#rho(770)", "l"); Int_t colours[5] = {kRed, kViolet, kBlue, kGreen+2, kOrange+2}; Int_t i(0), iN(5); for (i = 0; i < iN; i++) { Int_t j = i + 1; TString poleName("KMPole"); poleName += j; poleName += "_m13"; TH1* poleHist = dynamic_cast(rootFile->Get(poleName.Data())); poleHist->SetLineColor(colours[i]); poleHist->SetLineWidth(2); // Normalise histogram to unit area poleHist->Scale(1.0/poleHist->Integral()); poleStack->Add(poleHist); TString poleLabel("Pole"); poleLabel += j; poleLegend->AddEntry(poleHist, poleLabel, "l"); } poleStack->Draw("nostackc"); TAxis* poleXAxis = poleStack->GetXaxis(); poleXAxis->SetTitle("m(#pi^{+}#pi^{-}) (GeV/c^{2})"); poleXAxis->CenterTitle(kTRUE); TAxis* poleYAxis = poleStack->GetYaxis(); poleYAxis->SetTitle("Normalised intensity"); poleYAxis->CenterTitle(kTRUE); poleYAxis->SetTitleOffset(1.25); poleLegend->Draw(); theCanvas->Update(); theCanvas->Print("B3piKMatrixProjPoles.png"); theCanvas->Print("B3piKMatrixProjPoles.eps"); // Plot NR with K-matrix SVPs TLegend* SVPLegend = new TLegend(0.7, 0.5, 0.90, 0.90, ""); SVPLegend->SetFillColor(0); SVPLegend->SetTextSize(0.03); THStack* SVPStack = new THStack(); SVPStack->Add(rhoHist); SVPLegend->AddEntry(rhoHist, "rho(770)", "l"); for (i = 0; i < iN; i++) { Int_t j = i + 1; TString SVPName("KMSVP"); SVPName += j; SVPName += "_m13"; TH1* SVPHist = dynamic_cast(rootFile->Get(SVPName.Data())); SVPHist->SetLineColor(colours[i]); SVPHist->SetLineWidth(2); SVPHist->Scale(1.0/SVPHist->Integral()); SVPStack->Add(SVPHist); TString SVPLabel("SVP"); SVPLabel += j; SVPLegend->AddEntry(SVPHist, SVPLabel, "l"); } SVPStack->Draw("nostackc"); TAxis* SVPXAxis = SVPStack->GetXaxis(); SVPXAxis->SetTitle("m(#pi^{+}#pi^{-}) (GeV/c^{2})"); SVPXAxis->CenterTitle(kTRUE); TAxis* SVPYAxis = SVPStack->GetYaxis(); SVPYAxis->SetTitle("Normalised intensity"); SVPYAxis->CenterTitle(kTRUE); SVPYAxis->SetTitleOffset(1.25); SVPLegend->Draw(); theCanvas->Update(); theCanvas->Print("B3piKMatrixProjSVPs.png"); theCanvas->Print("B3piKMatrixProjSVPs.eps"); delete SVPStack; delete SVPLegend; delete poleStack; delete poleLegend; rootFile->Close(); } void createHistos(const std::string& rootFileName) { cout<<"rootFileName = "< > histMap; // Create mass/DP histograms for the different amplitude terms for (i = 0; i < iN; i++) { std::vector histVect = genMassHistos(i, NSignal); histMap[i] = histVect; } TFile* rootFile = TFile::Open(rootFileName.c_str(), "recreate"); rootFile->cd(); for (i = 0; i < iN; i++) { cout<<"Writing histograms for i = "< histVect = histMap[i]; std::vector::iterator iter; for (iter = histVect.begin(); iter != histVect.end(); ++iter) { TH1* theHist = *iter; theHist->Write(); } } rootFile->Close(); } std::vector genMassHistos(Int_t index, Int_t NSignal) { // Vector to store output mass/DP histograms std::vector histVect; // Define Dalitz plot: kinematics and resonances Bool_t squareDP = kTRUE; LauDaughters* theDaughters = new LauDaughters("B+", "pi+", "pi+", "pi-", squareDP); // Apply some vetoes to the DP LauVetoes* vetoes = new LauVetoes(); // Define the efficiency model LauEffModel* theEffModel = new LauEffModel(theDaughters, vetoes); // Create the isobar model LauResonanceMaker& resMaker = LauResonanceMaker::get(); resMaker.setDefaultBWRadius(LauBlattWeisskopfFactor::Parent, 4.0); resMaker.setDefaultBWRadius(LauBlattWeisskopfFactor::Light, 4.0); resMaker.fixBWRadius(LauBlattWeisskopfFactor::Parent, kTRUE); resMaker.fixBWRadius(LauBlattWeisskopfFactor::Light, kTRUE); // Define the "S-wave" K-matrix propagator Int_t nChannels = 5; Int_t nPoles = 5; Int_t resPairInt = 1; Int_t KMatrixIndex = 1; // for S-wave // Add one pole or SVP amplitude for the K-matrix and plot its mass projections // so that we can see the amplitude/intensity shape of the different terms Double_t aSqMaxValue = 0.3; Double_t nSigEvents = NSignal*1.0; Bool_t fixNSigEvents = kTRUE; Int_t nExpt = 1; Int_t firstExpt = 0; + Bool_t isToy = kTRUE; LauIsobarDynamics* theSigModel = new LauIsobarDynamics(theDaughters, theEffModel); theSigModel->setASqMaxValue(aSqMaxValue); TString theName("KMPole"); if (index >= 5) {theName = "KMSVP";} TString parName(""); if (index == 11) { // Simple Non-resonant cout<<"Non-resonant"<addResonance("NonReson", 0, LauAbsResonance::FlatNR); } else if (index == 10) { // Rho resonance cout<<"Using rho(770)"<addResonance("rho0(770)", 1, LauAbsResonance::GS); } else { // K-matrix amplitude theSigModel->defineKMatrixPropagator("KMSWave", "B3piKMatrixCoeff.dat", resPairInt, nChannels, nPoles, KMatrixIndex); cout<<"Implementing K matrix term number "<addKMatrixProdSVP(theName.Data(), "KMSWave", j, useProdAdler); } } // Create the fit model LauSimpleFitModel* fitModel = new LauSimpleFitModel(theSigModel); std::vector coeffSet; Bool_t fixPar = kTRUE; Bool_t fixCP = kTRUE; Bool_t doTwoStageFit = kFALSE; coeffSet.push_back(new LauCartesianCPCoeffSet(parName.Data(), 1.0, 0.0, 0.0, 0.0, fixPar, fixPar, fixCP, fixCP, doTwoStageFit, doTwoStageFit)); std::vector::iterator coeffIter; for (coeffIter = coeffSet.begin(); coeffIter != coeffSet.end(); ++coeffIter) { fitModel->setAmpCoeffSet(*coeffIter); } // Set the number of signal events and the number of experiments LauParameter* signalEvents = new LauParameter("signalEvents", nSigEvents, -2.0*nSigEvents, 2.0*nSigEvents, fixNSigEvents); fitModel->setNSigEvents(signalEvents); - fitModel->setNExpts(nExpt, firstExpt); + fitModel->setNExpts(nExpt, firstExpt, isToy); // Execute the generation/fit TString treeName(""); TString dummyName(""); TString tableFileName(""); TString dataFileName("Gen"); dataFileName += theName; dataFileName += ".root"; fitModel->run("gen", dataFileName, treeName, dummyName, tableFileName); // Create DP and mass projection plots so that we can see the K matrix // amplitude term shapes // Histogram of the invariant mass for pi+ pi- pairs: m13 & m23 TString m13Name(theName); m13Name += "_m13"; TH1D* m13Hist = new TH1D(m13Name.Data(), "", 100, 0.0, 5.5); m13Hist->SetXTitle("m(#pi^{+}#pi^{-})"); m13Hist->SetDirectory(0); histVect.push_back(m13Hist); // Histogram of the wrong sign invariant mass pi+ pi+: m12 TString m12Name(theName); m12Name += "_m12"; TH1D* m12Hist = new TH1D(m12Name.Data(), "", 100, 0.0, 5.5); m12Hist->SetXTitle("m(#pi^{+}#pi^{+})"); m12Hist->SetDirectory(0); histVect.push_back(m12Hist); // Dalitz plot 2d histogram TString DPName(theName); DPName += "_DP"; TH2D* DPHist = new TH2D(DPName.Data(), "", 100, 0.0, 14.0, 100, 0.0, 28.0); //TH2D* DPHist = new TH2D("DPHist", "", 100, 0.0, 28.0, 100, 0.0, 28.0); DPHist->SetXTitle("m^{2}(#pi^{+}#pi^{-})_{min}"); DPHist->SetYTitle("m^{2}(#pi^{+}#pi^{-})_{max}"); DPHist->SetDirectory(0); histVect.push_back(DPHist); // Simulation results file TFile* genFile = TFile::Open(dataFileName.Data(), "read"); genFile->cd(); TTree* genTree = dynamic_cast(genFile->Get("genResults")); genTree->SetBranchStatus("*", 0); genTree->SetBranchStatus("m12", 1); genTree->SetBranchStatus("m23", 1); genTree->SetBranchStatus("m13", 1); Double_t m12, m23, m13; genTree->SetBranchAddress("m12", &m12); genTree->SetBranchAddress("m23", &m23); genTree->SetBranchAddress("m13", &m13); Int_t nEntries = genTree->GetEntries(); cout<<"nEntries = "<GetEntry(k); Double_t mMin = m13; Double_t mMax = m23; if (m23 < m13) { mMin = m23; mMax = m13; } m13Hist->Fill(mMin); m13Hist->Fill(mMax); m12Hist->Fill(m12); DPHist->Fill(mMin*mMin, mMax*mMax); } // Cleanup genFile->Close(); delete signalEvents; for (coeffIter = coeffSet.begin(); coeffIter != coeffSet.end(); ++coeffIter) { delete *coeffIter; } delete fitModel; delete theSigModel; delete theEffModel; delete vetoes; delete theDaughters; // Return histograms return histVect; } diff --git a/examples/GenFit3K.cc b/examples/GenFit3K.cc index 49a7d0c..a26ebc3 100644 --- a/examples/GenFit3K.cc +++ b/examples/GenFit3K.cc @@ -1,227 +1,228 @@ /* Copyright 2014 University of Warwick Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /* Laura++ package authors: John Back Paul Harrison Thomas Latham */ #include #include #include #include "TFile.h" #include "TH2.h" #include "TString.h" #include "TTree.h" #include "LauSimpleFitModel.hh" #include "LauBkgndDPModel.hh" #include "LauDaughters.hh" #include "LauEffModel.hh" #include "LauIsobarDynamics.hh" #include "LauRealImagCoeffSet.hh" #include "LauResonanceMaker.hh" #include "LauVetoes.hh" void usage( std::ostream& out, const TString& progName ) { out<<"Usage:\n"; out< [nExpt = 1] [firstExpt = 0]"< [nExpt = 1] [firstExpt = 0] if ( argc < 2 ) { usage( std::cerr, argv[0] ); return EXIT_FAILURE; } TString command = argv[1]; command.ToLower(); Int_t iFit(0); Int_t nExpt(1); Int_t firstExpt(0); + Bool_t isToy(kTRUE); if ( command == "gen" ) { if ( argc > 2 ) { nExpt = atoi( argv[2] ); if ( argc > 3 ) { firstExpt = atoi( argv[3] ); } } } else if ( command == "fit" ) { if ( argc < 3 ) { usage( std::cerr, argv[0] ); return EXIT_FAILURE; } iFit = atoi( argv[2] ); if ( argc > 3 ) { nExpt = atoi( argv[3] ); if ( argc > 4 ) { firstExpt = atoi( argv[4] ); } } } else { usage( std::cerr, argv[0] ); return EXIT_FAILURE; } // If you want to use square DP histograms for efficiency, // backgrounds or you just want the square DP co-ordinates // stored in the toy MC ntuple then set this to kTRUE Bool_t squareDP = kFALSE; // This defines the DP => decay is B+ -> K+ K+ K- // Particle 1 = K+ // Particle 2 = K+ // Particle 3 = K- // The DP is defined in terms of m13Sq and m23Sq LauDaughters* daughters = new LauDaughters("B+", "K+", "K+", "K-", squareDP); // Define the efficiency model (defaults to unity everywhere) LauVetoes* vetoes = new LauVetoes(); LauEffModel* effModel = new LauEffModel(daughters, vetoes); // Create the isobar model // Set the spin formalism, the form and values of the Blatt-Weisskopf barrier radii and whether they are fixed or floating LauResonanceMaker& resMaker = LauResonanceMaker::get(); resMaker.setSpinFormalism( LauAbsResonance::Covariant ); resMaker.setBWBachelorRestFrame( LauBlattWeisskopfFactor::Covariant ); resMaker.setDefaultBWRadius( LauBlattWeisskopfFactor::Parent, 5.0 ); resMaker.setDefaultBWRadius( LauBlattWeisskopfFactor::Light, 4.0 ); resMaker.fixBWRadius( LauBlattWeisskopfFactor::Parent, kTRUE ); resMaker.fixBWRadius( LauBlattWeisskopfFactor::Light, kTRUE ); LauIsobarDynamics* sigModel = new LauIsobarDynamics(daughters, effModel); // Add various components to the isobar model, // modifying some resonance masses and widths // and allowing them to float in the fit LauAbsResonance* res(0); // addResonance arguments: resName, resPairAmpInt, resType res = sigModel->addResonance("phi(1020)", 1, LauAbsResonance::RelBW); // changeResonance arguments: newMass, newWidth, newSpin res->changeResonance(1.019460, 0.004247, 1); // Float the mass and width parameters res->fixMass(kFALSE); res->fixWidth(kFALSE); res = sigModel->addResonance("f'_2(1525)", 1, LauAbsResonance::RelBW); // Float the mass and width parameters res->fixMass(kFALSE); res->fixWidth(kFALSE); res = sigModel->addResonance("NonReson", 0, LauAbsResonance::FlatNR); // Set the maximum signal DP ASq value // If you do not provide a value, one will be determined automatically, // which should be close to the true maximum but is not guaranteed to // be optimal. // Any value, whether manually provided or automatically determined, // will be automatically adjusted to avoid bias or extreme inefficiency // but it is best to set this by hand once you've found the right value // through some trial and error. sigModel->setASqMaxValue(15.8); // Create the fit model LauSimpleFitModel* fitModel = new LauSimpleFitModel(sigModel); // Create the complex coefficients for the isobar model // Here we're using the form with real and imaginary parts: // c_j = x_j + i * y_j std::vector coeffset; coeffset.push_back( new LauRealImagCoeffSet("phi(1020)", 1.0, 0.0, kTRUE, kTRUE) ); coeffset.push_back( new LauRealImagCoeffSet("f'_2(1525)", 0.0, 1.0, kFALSE, kFALSE) ); coeffset.push_back( new LauRealImagCoeffSet("NonReson", 1.0, 0.0, kFALSE, kFALSE) ); for (std::vector::iterator iter=coeffset.begin(); iter!=coeffset.end(); ++iter) { fitModel->setAmpCoeffSet(*iter); } // Set the signal yield and define whether it is fixed or floated const Double_t nSigEvents = 5000.0; Bool_t fixNSigEvents = kFALSE; LauParameter * signalEvents = new LauParameter("signalEvents", nSigEvents, -1.0*nSigEvents, 2.0*nSigEvents, fixNSigEvents); fitModel->setNSigEvents(signalEvents); // Set the number of experiments to generate or fit and which // experiment to start with - fitModel->setNExpts( nExpt, firstExpt ); + fitModel->setNExpts( nExpt, firstExpt, isToy ); // Configure various fit options // Switch on/off calculation of asymmetric errors. fitModel->useAsymmFitErrors(kFALSE); // Randomise initial fit values for the signal mode fitModel->useRandomInitFitPars(kFALSE); const Bool_t haveBkgnds = ( fitModel->nBkgndClasses() > 0 ); // Switch on/off Poissonian smearing of total number of events fitModel->doPoissonSmearing(haveBkgnds); // Switch on/off Extended ML Fit option fitModel->doEMLFit(haveBkgnds); // Switch on the two-stage fit (for the resonance parameters) fitModel->twoStageFit(kTRUE); // Generate toy from the fitted parameters //TString fitToyFileName("fitToyMC_3K_"); //fitToyFileName += iFit; //fitToyFileName += ".root"; //fitModel->compareFitData(10, fitToyFileName); // Write out per-event likelihoods and sWeights //TString splotFileName("splot_3K_"); //splotFileName += iFit; //splotFileName += ".root"; //fitModel->writeSPlotData(splotFileName, "splot", kFALSE); // Set the names of the files to read/write TString dataFile("gen-3K.root"); TString treeName("genResults"); TString rootFileName(""); TString tableFileName(""); if (command == "fit") { rootFileName = "fit3K_"; rootFileName += iFit; rootFileName += "_expt_"; rootFileName += firstExpt; rootFileName += "-"; rootFileName += (firstExpt+nExpt-1); rootFileName += ".root"; tableFileName = "fit3KResults_"; tableFileName += iFit; } else { rootFileName = "dummy.root"; tableFileName = "gen3KResults"; } // Execute the generation/fit fitModel->run( command, dataFile, treeName, rootFileName, tableFileName ); return EXIT_SUCCESS; } diff --git a/examples/GenFit3KS.cc b/examples/GenFit3KS.cc index 90cf4af..842e879 100644 --- a/examples/GenFit3KS.cc +++ b/examples/GenFit3KS.cc @@ -1,200 +1,201 @@ /* Copyright 2014 University of Warwick Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /* Laura++ package authors: John Back Paul Harrison Thomas Latham */ #include #include #include #include "TFile.h" #include "TH2.h" #include "TString.h" #include "TTree.h" #include "LauSimpleFitModel.hh" #include "LauBkgndDPModel.hh" #include "LauDaughters.hh" #include "LauEffModel.hh" #include "LauIsobarDynamics.hh" #include "LauMagPhaseCoeffSet.hh" #include "LauVetoes.hh" void usage( std::ostream& out, const char* progName ) { out<<"Usage:\n"; out< [nExpt = 1] [firstExpt = 0]"< [nExpt = 1] [firstExpt = 0] if ( argc < 2 ) { usage( std::cerr, argv[0] ); return EXIT_FAILURE; } TString command = argv[1]; command.ToLower(); Int_t iFit(0); Int_t nExpt(1); Int_t firstExpt(0); + Bool_t isToy(kTRUE); if ( command == "gen" ) { if ( argc > 2 ) { nExpt = atoi( argv[2] ); if ( argc > 3 ) { firstExpt = atoi( argv[3] ); } } } else if ( command == "fit" ) { if ( argc < 3 ) { usage( std::cerr, argv[0] ); return EXIT_FAILURE; } iFit = atoi( argv[2] ); if ( argc > 3 ) { nExpt = atoi( argv[3] ); if ( argc > 4 ) { firstExpt = atoi( argv[4] ); } } } else { usage( std::cerr, argv[0] ); return EXIT_FAILURE; } // If you want to use square DP histograms for efficiency, // backgrounds or you just want the square DP co-ordinates // stored in the toy MC ntuple then set this to kTRUE Bool_t squareDP = kFALSE; // This defines the DP => decay is B0 -> KS KS KS // Particle 1 = KS // Particle 2 = KS // Particle 3 = KS // The DP is defined in terms of m13Sq and m23Sq LauDaughters* daughters = new LauDaughters("B0", "K_S0", "K_S0", "K_S0", squareDP); // Optionally apply some vetoes to the DP LauVetoes* vetoes = new LauVetoes(); // Define the efficiency model (defaults to unity everywhere) // Can optionally provide a histogram to model variation over DP LauEffModel* effModel = new LauEffModel(daughters, vetoes); // Create the isobar model LauIsobarDynamics* sigModel = new LauIsobarDynamics(daughters, effModel); //LauAbsResonance* reson(0); /*reson =*/ sigModel->addResonance("f_0(980)", 3, LauAbsResonance::Flatte); /*reson =*/ sigModel->addResonance("f_0(1710)", 3, LauAbsResonance::RelBW); /*reson =*/ sigModel->addResonance("f_2(2010)", 3, LauAbsResonance::RelBW); /*reson =*/ sigModel->addResonance("chi_c0", 3, LauAbsResonance::RelBW); // Set the maximum signal DP ASq value // If you do not provide a value, one will be determined automatically, // which should be close to the true maximum but is not guaranteed to // be optimal. // Any value, whether manually provided or automatically determined, // will be automatically adjusted to avoid bias or extreme inefficiency // but it is best to set this by hand once you've found the right value // through some trial and error. sigModel->setASqMaxValue(0.285); // Create the fit model LauSimpleFitModel* fitModel = new LauSimpleFitModel(sigModel); // Create the complex coefficients for the isobar model // Here we're using the magnitude and phase form: // c_j = a_j exp(i*delta_j) std::vector coeffset; coeffset.push_back( new LauMagPhaseCoeffSet("f_0(980)", 1.00, 0.00, kTRUE, kTRUE) ); coeffset.push_back( new LauMagPhaseCoeffSet("f_0(1710)", 0.40, 1.11, kFALSE, kFALSE) ); coeffset.push_back( new LauMagPhaseCoeffSet("f_2(2010)", 0.45, 2.50, kFALSE, kFALSE) ); coeffset.push_back( new LauMagPhaseCoeffSet("chi_c0", 0.40, 0.63, kFALSE, kFALSE) ); for (std::vector::iterator iter=coeffset.begin(); iter!=coeffset.end(); ++iter) { fitModel->setAmpCoeffSet(*iter); } // Set the signal yield and define whether it is fixed or floated LauParameter * nSigEvents = new LauParameter("nSigEvents",10000.0,-50000.0,50000.0,kFALSE); fitModel->setNSigEvents(nSigEvents); // Set the number of experiments to generate or fit and which // experiment to start with - fitModel->setNExpts( nExpt, firstExpt ); + fitModel->setNExpts( nExpt, firstExpt, isToy ); // Configure various fit options // Switch on/off calculation of asymmetric errors. fitModel->useAsymmFitErrors(kFALSE); // Randomise initial fit values for the signal mode fitModel->useRandomInitFitPars(kTRUE); const Bool_t haveBkgnds = ( fitModel->nBkgndClasses() > 0 ); // Switch on/off Poissonian smearing of total number of events fitModel->doPoissonSmearing(haveBkgnds); // Switch on/off Extended ML Fit option fitModel->doEMLFit(haveBkgnds); // Generate toy from the fitted parameters //TString fitToyFileName("fitToyMC_3KS_"); //fitToyFileName += iFit; //fitToyFileName += ".root"; //fitModel->compareFitData(100, fitToyFileName); // Write out per-event likelihoods and sWeights //TString splotFileName("splot_3KS_"); //splotFileName += iFit; //splotFileName += ".root"; //fitModel->writeSPlotData(splotFileName, "splot", kFALSE); // Set the names of the files to read/write TString dataFile("gen-3KS.root"); TString treeName("genResults"); TString rootFileName(""); TString tableFileName(""); if (command == "fit") { rootFileName = "fit3KS_"; rootFileName += iFit; rootFileName += "_expt_"; rootFileName += firstExpt; rootFileName += "-"; rootFileName += (firstExpt+nExpt-1); rootFileName += ".root"; tableFileName = "fit3KSResults_"; tableFileName += iFit; } else { rootFileName = "dummy.root"; tableFileName = "gen3KSResults"; } // Execute the generation/fit fitModel->run( command, dataFile, treeName, rootFileName, tableFileName ); return EXIT_SUCCESS; } diff --git a/examples/GenFit3pi.cc b/examples/GenFit3pi.cc index 171f049..7dbefd4 100644 --- a/examples/GenFit3pi.cc +++ b/examples/GenFit3pi.cc @@ -1,263 +1,264 @@ /* Copyright 2005 University of Warwick Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /* Laura++ package authors: John Back Paul Harrison Thomas Latham */ #include #include #include #include "TFile.h" #include "TH2.h" #include "TString.h" #include "TTree.h" #include "LauSimpleFitModel.hh" #include "LauBkgndDPModel.hh" #include "LauDaughters.hh" #include "LauEffModel.hh" #include "LauIsobarDynamics.hh" #include "LauMagPhaseCoeffSet.hh" #include "LauResonanceMaker.hh" #include "LauVetoes.hh" void usage( std::ostream& out, const TString& progName ) { out<<"Usage:\n"; out< [nExpt = 1] [firstExpt = 0]"< [nExpt = 1] [firstExpt = 0] if ( argc < 2 ) { usage( std::cerr, argv[0] ); return EXIT_FAILURE; } TString command = argv[1]; command.ToLower(); Int_t iFit(0); Int_t nExpt(1); Int_t firstExpt(0); + Bool_t isToy(kTRUE); if ( command == "gen" ) { if ( argc > 2 ) { nExpt = atoi( argv[2] ); if ( argc > 3 ) { firstExpt = atoi( argv[3] ); } } } else if ( command == "fit" ) { if ( argc < 3 ) { usage( std::cerr, argv[0] ); return EXIT_FAILURE; } iFit = atoi( argv[2] ); if ( argc > 3 ) { nExpt = atoi( argv[3] ); if ( argc > 4 ) { firstExpt = atoi( argv[4] ); } } } else { usage( std::cerr, argv[0] ); return EXIT_FAILURE; } // If you want to use square DP histograms for efficiency, // backgrounds or you just want the square DP co-ordinates // stored in the toy MC ntuple then set this to kTRUE Bool_t squareDP = kFALSE; // This defines the DP => decay is B+ -> pi+ pi+ pi- // Particle 1 = pi+ // Particle 2 = pi+ // Particle 3 = pi- // The DP is defined in terms of m13Sq and m23Sq LauDaughters* daughters = new LauDaughters("B+", "pi+", "pi+", "pi-", squareDP); // Optionally apply some vetoes to the DP // (example syntax given but commented-out) LauVetoes* vetoes = new LauVetoes(); //Double_t DMin = 1.70; //Double_t DMax = 1.925; //Double_t JpsiMin = 3.051; //Double_t JpsiMax = 3.222; //Double_t psi2SMin = 3.676; //Double_t psi2SMax = 3.866; //vetoes->addMassVeto(1, DMin, DMax); // D0 veto, m23 (and automatically m13) //vetoes->addMassVeto(1, JpsiMin, JpsiMax); // J/psi veto, m23 (and automatically m13) //vetoes->addMassVeto(1, psi2SMin, psi2SMax); // psi(2S) veto, m23 (and automatically m13) // Define the efficiency model (defaults to unity everywhere) LauEffModel* effModel = new LauEffModel(daughters, vetoes); // Can optionally provide a histogram to model variation over DP // (example syntax given but commented-out) //TFile *effHistFile = TFile::Open("histoFiles/B3piNRDPEff.root", "read"); //TH2* effHist = dynamic_cast(effHistFile->Get("effHist")); //Bool_t useInterpolation = kTRUE; //Bool_t fluctuateBins = kFALSE; //Bool_t useUpperHalf = kTRUE; //effModel->setEffHisto(effHist, useInterpolation, fluctuateBins, 0.0, 0.0, useUpperHalf, squareDP); // Create the isobar model // Set the values of the Blatt-Weisskopf barrier radii and whether they are fixed or floating LauResonanceMaker& resMaker = LauResonanceMaker::get(); resMaker.setDefaultBWRadius( LauBlattWeisskopfFactor::Parent, 5.0 ); resMaker.setDefaultBWRadius( LauBlattWeisskopfFactor::Light, 4.0 ); resMaker.fixBWRadius( LauBlattWeisskopfFactor::Parent, kTRUE ); resMaker.fixBWRadius( LauBlattWeisskopfFactor::Light, kTRUE ); LauIsobarDynamics* sigModel = new LauIsobarDynamics(daughters, effModel); // Add various components to the isobar model, // modifying some resonance parameters LauAbsResonance* reson(0); // addResonance arguments: resName, resPairAmpInt, resType reson = sigModel->addResonance("rho0(770)", 1, LauAbsResonance::GS); // resPairAmpInt = 1 => resonance mass is m23. reson = sigModel->addResonance("rho0(1450)", 1, LauAbsResonance::RelBW); reson = sigModel->addResonance("f_0(980)", 1, LauAbsResonance::Flatte); reson->setResonanceParameter("g1",0.2); reson->setResonanceParameter("g2",1.0); reson = sigModel->addResonance("f_2(1270)", 1, LauAbsResonance::RelBW); const TString nrName = "BelleNR_Swave"; reson = sigModel->addResonance(nrName, 0, LauAbsResonance::BelleSymNRNoInter); reson->setResonanceParameter("alpha", 0.2); // Set the maximum signal DP ASq value // If you do not provide a value, one will be determined automatically, // which should be close to the true maximum but is not guaranteed to // be optimal. // Any value, whether manually provided or automatically determined, // will be automatically adjusted to avoid bias or extreme inefficiency // but it is best to set this by hand once you've found the right value // through some trial and error. sigModel->setASqMaxValue(0.35); // Create the fit model LauSimpleFitModel* fitModel = new LauSimpleFitModel(sigModel); // Create the complex coefficients for the isobar model // Here we're using the magnitude and phase form: // c_j = a_j exp(i*delta_j) std::vector coeffset; coeffset.push_back( new LauMagPhaseCoeffSet("rho0(770)", 1.00, 0.00, kTRUE, kTRUE) ); coeffset.push_back( new LauMagPhaseCoeffSet("rho0(1450)", 0.37, 1.99, kFALSE, kFALSE) ); coeffset.push_back( new LauMagPhaseCoeffSet("f_0(980)", 0.27, -1.59, kFALSE, kFALSE) ); coeffset.push_back( new LauMagPhaseCoeffSet("f_2(1270)", 0.53, 1.39, kFALSE, kFALSE) ); coeffset.push_back( new LauMagPhaseCoeffSet(nrName, 0.54, -0.84, kFALSE, kFALSE) ); for (std::vector::iterator iter=coeffset.begin(); iter!=coeffset.end(); ++iter) { fitModel->setAmpCoeffSet(*iter); } // Set the signal yield and define whether it is fixed or floated const Double_t nSigEvents = 1500.0; LauParameter * signalEvents = new LauParameter("signalEvents",nSigEvents,-1.0*nSigEvents,2.0*nSigEvents,kFALSE); fitModel->setNSigEvents(signalEvents); // Set the number of experiments to generate or fit and which // experiment to start with - fitModel->setNExpts( nExpt, firstExpt ); + fitModel->setNExpts( nExpt, firstExpt, isToy ); // Set up a background model // First declare the names of the background class(es) std::vector bkgndNames(1); bkgndNames[0] = "qqbar"; fitModel->setBkgndClassNames( bkgndNames ); // Define and set the yield parameter for the background const Double_t nBkg = 1250.0; LauParameter* nBkgndEvents = new LauParameter("qqbar",nBkg,-2.0*nBkg,2.0*nBkg,kFALSE); fitModel->setNBkgndEvents( nBkgndEvents ); // Create the background DP model LauBkgndDPModel* qqbarModel = new LauBkgndDPModel(daughters, vetoes); // Load in background DP model histogram // (example syntax given but commented-out - the background will be treated as being uniform in the DP in the absence of a histogram) //TString qqFileName("histoFiles/offResDP.root"); //TFile* qqFile = TFile::Open(qqFileName.Data(), "read"); //TH2* qqDP = dynamic_cast(qqFile->Get("AllmTheta")); // m', theta' //qqbarModel->setBkgndHisto(qqDP, useInterpolation, fluctuateBins, useUpperHalf, squareDP); // Add the background DP model into the fit model fitModel->setBkgndDPModel( "qqbar", qqbarModel ); // Configure various fit options // Switch on/off calculation of asymmetric errors. fitModel->useAsymmFitErrors(kFALSE); // Randomise initial fit values for the signal mode fitModel->useRandomInitFitPars(kTRUE); const Bool_t haveBkgnds = ( fitModel->nBkgndClasses() > 0 ); // Switch on/off Poissonian smearing of total number of events fitModel->doPoissonSmearing(haveBkgnds); // Switch on/off Extended ML Fit option fitModel->doEMLFit(haveBkgnds); // Generate toy from the fitted parameters //TString fitToyFileName("fitToyMC_3pi_"); //fitToyFileName += iFit; //fitToyFileName += ".root"; //fitModel->compareFitData(100, fitToyFileName); // Write out per-event likelihoods and sWeights //TString splotFileName("splot_3pi_"); //splotFileName += iFit; //splotFileName += ".root"; //fitModel->writeSPlotData(splotFileName, "splot", kFALSE); // Set the names of the files to read/write TString dataFile("gen-3pi.root"); TString treeName("genResults"); TString rootFileName(""); TString tableFileName(""); if (command == "fit") { rootFileName = "fit3pi_"; rootFileName += iFit; rootFileName += "_expt_"; rootFileName += firstExpt; rootFileName += "-"; rootFileName += (firstExpt+nExpt-1); rootFileName += ".root"; tableFileName = "fit3piResults_"; tableFileName += iFit; } else { rootFileName = "dummy.root"; tableFileName = "gen3piResults"; } // Execute the generation/fit fitModel->run( command, dataFile, treeName, rootFileName, tableFileName ); return EXIT_SUCCESS; } diff --git a/examples/GenFitBelleCPKpipi.cc b/examples/GenFitBelleCPKpipi.cc index 22326eb..95e62d5 100644 --- a/examples/GenFitBelleCPKpipi.cc +++ b/examples/GenFitBelleCPKpipi.cc @@ -1,252 +1,253 @@ /* Copyright 2005 University of Warwick Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /* Laura++ package authors: John Back Paul Harrison Thomas Latham */ #include #include #include #include "TFile.h" #include "TH2.h" #include "TString.h" #include "TTree.h" #include "LauBkgndDPModel.hh" #include "LauCPFitModel.hh" #include "LauDaughters.hh" #include "LauEffModel.hh" #include "LauIsobarDynamics.hh" #include "LauBelleCPCoeffSet.hh" #include "LauVetoes.hh" void usage( std::ostream& out, const TString& progName ) { out<<"Usage:\n"; out< [nExpt = 1] [firstExpt = 0]"< [nExpt = 1] [firstExpt = 0] if ( argc < 2 ) { usage( std::cerr, argv[0] ); return EXIT_FAILURE; } TString command = argv[1]; command.ToLower(); Int_t iFit(0); Int_t nExpt(1); Int_t firstExpt(0); + Bool_t isToy(kTRUE); if ( command == "gen" ) { if ( argc > 2 ) { nExpt = atoi( argv[2] ); if ( argc > 3 ) { firstExpt = atoi( argv[3] ); } } } else if ( command == "fit" ) { if ( argc < 3 ) { usage( std::cerr, argv[0] ); return EXIT_FAILURE; } iFit = atoi( argv[2] ); if ( argc > 3 ) { nExpt = atoi( argv[3] ); if ( argc > 4 ) { firstExpt = atoi( argv[4] ); } } } else { usage( std::cerr, argv[0] ); return EXIT_FAILURE; } // If you want to use square DP histograms for efficiency, // backgrounds or you just want the square DP co-ordinates // stored in the toy MC ntuple then set this to kTRUE Bool_t squareDP = kFALSE; // These define the DP => decay is B+ -> K+ pi+ pi- and it's charge conjugate // The DP is defined in terms of m13Sq and m23Sq LauDaughters* negDaughters = new LauDaughters("B-", "K-", "pi-", "pi+", squareDP); LauDaughters* posDaughters = new LauDaughters("B+", "K+", "pi+", "pi-", squareDP); // Create the isobar models LauAbsResonance* res(0); LauIsobarDynamics* negSigModel = new LauIsobarDynamics(negDaughters, 0); res = negSigModel->addResonance("K*0(892)", 2, LauAbsResonance::RelBW); // resPairAmpInt = 2 => resonance mass is m13. res = negSigModel->addResonance("K*0_0(1430)", 2, LauAbsResonance::LASS_BW); res->floatResonanceParameter("a"); res->floatResonanceParameter("r"); res = negSigModel->addResonance("LASSNR0", 2, LauAbsResonance::LASS_NR); res = negSigModel->addResonance("rho0(770)", 1, LauAbsResonance::RelBW); // resPairAmpInt = 1 => resonance mass is m23. res = negSigModel->addResonance("f_0(980)", 1, LauAbsResonance::Flatte); res = negSigModel->addResonance("chi_c0", 1, LauAbsResonance::RelBW); res = negSigModel->addResonance("NonReson", 1, LauAbsResonance::BelleNR); res->setResonanceParameter("alpha", 0.50); res->floatResonanceParameter("alpha"); LauIsobarDynamics* posSigModel = new LauIsobarDynamics(posDaughters, 0); res = posSigModel->addResonance("K*0(892)", 2, LauAbsResonance::RelBW); res = posSigModel->addResonance("K*0_0(1430)", 2, LauAbsResonance::LASS_BW); res->floatResonanceParameter("a"); res->floatResonanceParameter("r"); res = posSigModel->addResonance("LASSNR0", 2, LauAbsResonance::LASS_NR); res = posSigModel->addResonance("rho0(770)", 1, LauAbsResonance::RelBW); res = posSigModel->addResonance("f_0(980)", 1, LauAbsResonance::Flatte); res = posSigModel->addResonance("chi_c0", 1, LauAbsResonance::RelBW); res = posSigModel->addResonance("NonReson", 1, LauAbsResonance::BelleNR); res->setResonanceParameter("alpha", 0.50); res->floatResonanceParameter("alpha"); // Set the file names for the integrals information (can be useful for debugging) negSigModel->setIntFileName("integ_neg.dat"); posSigModel->setIntFileName("integ_pos.dat"); // Set the maximum signal DP ASq value // If you do not provide a value, one will be determined automatically, // which should be close to the true maximum but is not guaranteed to // be optimal. // Any value, whether manually provided or automatically determined, // will be automatically adjusted to avoid bias or extreme inefficiency // but it is best to set this by hand once you've found the right value // through some trial and error. const Double_t aSqMaxValue{1.62}; negSigModel->setASqMaxValue(aSqMaxValue); posSigModel->setASqMaxValue(aSqMaxValue); // Create the fit model, giving it both isobar models LauCPFitModel* fitModel = new LauCPFitModel( negSigModel, posSigModel ); // Create the complex coefficients for the isobar model // Here we're using the "Belle" form: // The amplitude has the form a * exp(i*delta) * ( 1 +/- b * exp(i*phi) ) where // a is a CP conserving magnitude, // b is a CP violating magnitude, // delta is the strong phase // and phi is the weak phase. // The last two arguments indicate that the CP-violating parameters // should only be floated in the second-stage of the two-stage fit LauAbsCoeffSet* a0CoeffSet = new LauBelleCPCoeffSet("K*0(892)", 1.00, 0.00, 0.00, 0.00, kTRUE, kTRUE, kFALSE, kTRUE, kTRUE, kTRUE); // Here we show how to use the coefficient cloning mechanism to clone // only the CP-violating parameters. This means that the K*0_0(1430) // component will have identical CPV parameters to the K*0(892). // But the CP-conserving parameters will be independent and as such we // need to set their values and, in this case because we're cloning // from the reference amplitude, also set them to float. //LauAbsCoeffSet* a1CoeffSet = new LauBelleCPCoeffSet("K*0_0(1430)", 2.00, 3.00, 0.00, 0.00, kFALSE, kFALSE, kFALSE, kFALSE, kTRUE, kTRUE); LauAbsCoeffSet* a1CoeffSet = a0CoeffSet->createClone("K*0_0(1430)", LauAbsCoeffSet::TieCPPars); a1CoeffSet->setParameterValue("A",2.0,kTRUE); a1CoeffSet->setParameterValue("Delta",3.0,kTRUE); a1CoeffSet->floatParameter("A"); a1CoeffSet->floatParameter("Delta"); LauAbsCoeffSet* a2CoeffSet = a1CoeffSet->createClone("LASSNR0", LauAbsCoeffSet::TieCPPars); LauAbsCoeffSet* a3CoeffSet = new LauBelleCPCoeffSet("rho0(770)", 0.66, 1.00, 0.00, 0.00, kFALSE, kFALSE, kFALSE, kFALSE, kTRUE, kTRUE); LauAbsCoeffSet* a4CoeffSet = new LauBelleCPCoeffSet("f_0(980)", 1.00, -1.00, 0.00, 0.00, kFALSE, kFALSE, kFALSE, kFALSE, kTRUE, kTRUE); LauAbsCoeffSet* a5CoeffSet = new LauBelleCPCoeffSet("chi_c0", 0.33, 0.50, 0.00, 0.00, kFALSE, kFALSE, kFALSE, kFALSE, kTRUE, kTRUE); LauAbsCoeffSet* a6CoeffSet = new LauBelleCPCoeffSet("NonReson", 0.50, 1.50, 0.00, 0.00, kFALSE, kFALSE, kFALSE, kFALSE, kTRUE, kTRUE); std::vector coeffset; coeffset.push_back( a0CoeffSet ); coeffset.push_back( a1CoeffSet ); coeffset.push_back( a2CoeffSet ); coeffset.push_back( a3CoeffSet ); coeffset.push_back( a4CoeffSet ); coeffset.push_back( a5CoeffSet ); coeffset.push_back( a6CoeffSet ); for (std::vector::iterator iter=coeffset.begin(); iter!=coeffset.end(); ++iter) { fitModel->setAmpCoeffSet(*iter); } // Set the signal yield and define whether it is fixed or floated const Double_t nSigEvents = 5000.0; Bool_t fixNSigEvents = kFALSE; LauParameter * signalEvents = new LauParameter("signalEvents",nSigEvents,-1.0*nSigEvents,2.0*nSigEvents,fixNSigEvents); fitModel->setNSigEvents(signalEvents); // Set the number of experiments to generate or fit and which // experiment to start with - fitModel->setNExpts( nExpt, firstExpt ); + fitModel->setNExpts( nExpt, firstExpt, isToy ); // Configure various fit options // Switch on/off calculation of asymmetric errors. fitModel->useAsymmFitErrors(kFALSE); // Randomise initial fit values for the signal mode fitModel->useRandomInitFitPars(kTRUE); const Bool_t haveBkgnds = ( fitModel->nBkgndClasses() > 0 ); // Switch on/off Poissonian smearing of total number of events fitModel->doPoissonSmearing(haveBkgnds); // Switch on/off Extended ML Fit option fitModel->doEMLFit(haveBkgnds); // Switch on/off two-stage fit fitModel->twoStageFit(kTRUE); // Generate toy from the fitted parameters //TString fitToyFileName("fitToyMC_BelleCPKpipi_"); //fitToyFileName += iFit; //fitToyFileName += ".root"; //fitModel->compareFitData(100, fitToyFileName); // Write out per-event likelihoods and sWeights //TString splotFileName("splot_BelleCPKpipi_"); //splotFileName += iFit; //splotFileName += ".root"; //fitModel->writeSPlotData(splotFileName, "splot", kFALSE); // Set the names of the files to read/write TString dataFile("gen-BelleCPKpipi.root"); TString treeName("genResults"); TString rootFileName(""); TString tableFileName(""); if (command == "fit") { rootFileName = "fitBelleCPKpipi_"; rootFileName += iFit; rootFileName += "_expt_"; rootFileName += firstExpt; rootFileName += "-"; rootFileName += (firstExpt+nExpt-1); rootFileName += ".root"; tableFileName = "fitBelleCPKpipiResults_"; tableFileName += iFit; } else { rootFileName = "dummy.root"; tableFileName = "genBelleCPKpipiResults"; } // Execute the generation/fit fitModel->run( command, dataFile, treeName, rootFileName, tableFileName ); return EXIT_SUCCESS; } diff --git a/examples/GenFitDpipi.cc b/examples/GenFitDpipi.cc index eec4572..3d0a3eb 100644 --- a/examples/GenFitDpipi.cc +++ b/examples/GenFitDpipi.cc @@ -1,224 +1,225 @@ #include #include #include #include "TFile.h" #include "TH2.h" #include "TString.h" #include "TTree.h" #include "LauSimpleFitModel.hh" #include "LauResonanceMaker.hh" #include "LauBkgndDPModel.hh" #include "LauDaughters.hh" #include "LauEffModel.hh" #include "LauIsobarDynamics.hh" #include "LauMagPhaseCoeffSet.hh" #include "LauRealImagCoeffSet.hh" #include "LauRandom.hh" #include "LauVetoes.hh" #include "LauAbsModIndPartWave.hh" #include "LauModIndPartWaveRealImag.hh" #include "LauModIndPartWaveMagPhase.hh" void usage( std::ostream& out, const TString& progName ) { out<<"Usage:\n"; out< [nExpt = 1] [firstExpt = 0]"< [nExpt = 1] [firstExpt = 0] if ( argc < 2 ) { usage( std::cerr, argv[0] ); return EXIT_FAILURE; } TString command = argv[1]; command.ToLower(); Int_t iFit(0); Int_t nExpt(1); Int_t firstExpt(0); + Bool_t isToy(kTRUE); if ( command == "gen" ) { if ( argc > 2 ) { nExpt = atoi( argv[2] ); if ( argc > 3 ) { firstExpt = atoi( argv[3] ); } } } else if ( command == "fit" ) { if ( argc < 3 ) { usage( std::cerr, argv[0] ); return EXIT_FAILURE; } iFit = atoi( argv[2] ); if ( argc > 3 ) { nExpt = atoi( argv[3] ); if ( argc > 4 ) { firstExpt = atoi( argv[4] ); } } } else { usage( std::cerr, argv[0] ); return EXIT_FAILURE; } // If you want to use square DP histograms for efficiency, // backgrounds or you just want the square DP co-ordinates // stored in the toy MC ntuple then set this to kTRUE Bool_t squareDP = kTRUE; // This defines the DP => decay is B+ -> pi+ pi+ D- // Particle 1 = pi+ // Particle 2 = pi+ // Particle 3 = D- // The DP is defined in terms of m13Sq and m23Sq LauDaughters* daughters = new LauDaughters("B+", "pi+", "pi+", "D-", squareDP); // Optionally apply some vetoes to the DP LauVetoes* vetoes = new LauVetoes(); LauEffModel* effModel = new LauEffModel(daughters, vetoes); // Set the values of the Blatt-Weisskopf barrier radii and whether they are fixed or floating LauResonanceMaker& resMaker = LauResonanceMaker::get(); resMaker.setDefaultBWRadius( LauBlattWeisskopfFactor::Parent, 4.0 ); resMaker.setDefaultBWRadius( LauBlattWeisskopfFactor::Charm, 4.0 ); resMaker.setDefaultBWRadius( LauBlattWeisskopfFactor::Light, 4.0 ); resMaker.setDefaultBWRadius( LauBlattWeisskopfFactor::Beauty, 4.0 ); resMaker.fixBWRadius( LauBlattWeisskopfFactor::Parent, kTRUE); resMaker.fixBWRadius( LauBlattWeisskopfFactor::Charm, kTRUE); resMaker.fixBWRadius( LauBlattWeisskopfFactor::Light, kTRUE); resMaker.fixBWRadius( LauBlattWeisskopfFactor::Beauty, kTRUE); // Create the isobar model std::vector coeffset; LauIsobarDynamics* sigModel = new LauIsobarDynamics(daughters, effModel); LauAbsResonance* reson(0); reson = sigModel->addResonance("D*0", 2, LauAbsResonance::RelBW); reson = sigModel->addResonance("D*0_0", 2, LauAbsResonance::MIPW_MagPhase); LauModIndPartWaveMagPhase* mipw = dynamic_cast(reson); if (mipw==nullptr){ std::cout << "MIPW pointer is null" << std::endl; return 0; } //vector of knot masses - ignore ends as they are dealt with internally std::set knot_mass{ 2.10, 2.20, 2.30, 2.40, 2.50, 2.60, 2.70, 2.80, 2.90, 3.10, 4.10, }; mipw->defineKnots(knot_mass); mipw->floatKnotsSecondStage(kFALSE); //Set magnitude and phase for the knots (including the end points here) mipw->setKnotAmp(0, 0.12, -2.82,kFALSE,kFALSE); mipw->setKnotAmp(1, 0.58, -1.56,kFALSE,kFALSE); mipw->setKnotAmp(2, 0.73, -1.00,kFALSE,kFALSE); mipw->setKnotAmp(3, 0.68, -0.42,kFALSE,kFALSE); mipw->setKnotAmp(4, 0.5, 0.0,kTRUE,kTRUE); mipw->setKnotAmp(5, 0.23, -0.00,kFALSE,kFALSE); mipw->setKnotAmp(6, 0.23, -0.42,kFALSE,kFALSE); mipw->setKnotAmp(7, 0.15, -0.31,kFALSE,kFALSE); mipw->setKnotAmp(8, 0.17, -0.63,kFALSE,kFALSE); mipw->setKnotAmp(9, 0.20, -0.87,kFALSE,kFALSE); mipw->setKnotAmp(10, 0.14, -1.16,kFALSE,kFALSE); mipw->setKnotAmp(11, 0.08, 1.02,kFALSE,kFALSE); mipw->setKnotAmp(12, 0.0, 0.0,kTRUE, kTRUE); reson = sigModel->addResonance("D*0_2", 2, LauAbsResonance::RelBW); reson = sigModel->addResonance("D*0_1(2680)", 2, LauAbsResonance::RelBW); reson = sigModel->addResonance("B*0", 2, LauAbsResonance::RelBW); reson = sigModel->addResonance("D*0_3(2760)", 2, LauAbsResonance::RelBW); reson = sigModel->addResonance("D0(3000)", 2, LauAbsResonance::RelBW); sigModel->setASqMaxValue(1.0); // Create the fit model LauSimpleFitModel* fitModel = new LauSimpleFitModel(sigModel); coeffset.push_back( new LauMagPhaseCoeffSet("D*0", 0.55, -0.38, kFALSE, kFALSE) ); coeffset.push_back( new LauMagPhaseCoeffSet("D*0_0", 1.26, -0.28, kFALSE, kFALSE) ); // Still need a total mag/phase for the MIPW shape coeffset.push_back( new LauMagPhaseCoeffSet("D*0_2", 1.00, 0.00, kTRUE, kTRUE) ); coeffset.push_back( new LauMagPhaseCoeffSet("D*0_1(2680)", 0.48, 2.47, kFALSE, kFALSE) ); coeffset.push_back( new LauMagPhaseCoeffSet("B*0", 0.27, 0.14, kFALSE, kFALSE) ); coeffset.push_back( new LauMagPhaseCoeffSet("D*0_3(2760)", 0.17, 0.01, kFALSE, kFALSE) ); coeffset.push_back( new LauMagPhaseCoeffSet("D0(3000)", 0.08, -0.84, kFALSE, kFALSE) ); for (std::vector::iterator iter=coeffset.begin(); iter!=coeffset.end(); ++iter) { fitModel->setAmpCoeffSet(*iter); } Double_t nSig(50000); TString sigEventsName = "signalEvents"; LauParameter* nSigEvents = new LauParameter(sigEventsName,nSig,-2.0*nSig,2.0*nSig,kTRUE); fitModel->setNSigEvents(nSigEvents); // Set the number of experiments to generate or fit and which // experiment to start with - fitModel->setNExpts( nExpt, firstExpt ); + fitModel->setNExpts( nExpt, firstExpt, isToy ); // Switch on/off calculation of asymmetric errors. fitModel->useAsymmFitErrors(kFALSE); // Randomise initial fit values for the signal mode fitModel->useRandomInitFitPars(kTRUE); // Switch on/off Poissonian smearing of total number of events fitModel->doPoissonSmearing(kTRUE); // Switch on/off Extended ML Fit option fitModel->doEMLFit(kFALSE); // Switch on the two-stage fit (for the resonance parameters) fitModel->twoStageFit(kFALSE); // Generate toy from the fitted parameters //TString fitToyFileName("fitToyMC_Dpipi_"); //fitToyFileName += iFit; //fitToyFileName += ".root"; //fitModel->compareFitData(100, fitToyFileName); // Set the names of the files to read/write TString dataFile("gen-Dpipi.root"); TString treeName("genResults"); TString rootFileName(""); TString tableFileName(""); if (command == "fit") { rootFileName = "fitDpipi_"; rootFileName += iFit; rootFileName += "_expt_"; rootFileName += firstExpt; rootFileName += "-"; rootFileName += (firstExpt+nExpt-1); rootFileName += ".root"; tableFileName = "fitDpipiResults_"; tableFileName += iFit; } else { rootFileName = "dummy.root"; tableFileName = "genDpipiResults"; } // Execute the generation/fit fitModel->run( command, dataFile, treeName, rootFileName, tableFileName ); return EXIT_SUCCESS; } diff --git a/examples/GenFitDs2KKpi.cc b/examples/GenFitDs2KKpi.cc index 8be1300..b3298a0 100644 --- a/examples/GenFitDs2KKpi.cc +++ b/examples/GenFitDs2KKpi.cc @@ -1,196 +1,197 @@ /* Copyright 2017 University of Warwick Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /* Laura++ package authors: John Back Paul Harrison Thomas Latham */ #include #include #include #include "TFile.h" #include "TH2.h" #include "TString.h" #include "TTree.h" #include "LauSimpleFitModel.hh" #include "LauBkgndDPModel.hh" #include "LauDaughters.hh" #include "LauEffModel.hh" #include "LauIsobarDynamics.hh" #include "LauMagPhaseCoeffSet.hh" #include "LauVetoes.hh" void usage( std::ostream& out, const TString& progName ) { out<<"Usage:\n"; out< [nExpt = 1] [firstExpt = 0]"< [nExpt = 1] [firstExpt = 0] if ( argc < 2 ) { usage( std::cerr, argv[0] ); return EXIT_FAILURE; } TString command = argv[1]; command.ToLower(); Int_t iFit(0); Int_t nExpt(1); Int_t firstExpt(0); + Bool_t isToy(kTRUE); if ( command == "gen" ) { if ( argc > 2 ) { nExpt = atoi( argv[2] ); if ( argc > 3 ) { firstExpt = atoi( argv[3] ); } } } else if ( command == "fit" ) { if ( argc < 3 ) { usage( std::cerr, argv[0] ); return EXIT_FAILURE; } iFit = atoi( argv[2] ); if ( argc > 3 ) { nExpt = atoi( argv[3] ); if ( argc > 4 ) { firstExpt = atoi( argv[4] ); } } } else { usage( std::cerr, argv[0] ); return EXIT_FAILURE; } // If you want to use square DP histograms for efficiency, // backgrounds or you just want the square DP co-ordinates // stored in the toy MC ntuple then set this to kTRUE Bool_t squareDP = kFALSE; // This defines the DP => decay is D_s+ -> pi+ K+ K- // Particle 1 = pi+ // Particle 2 = K+ // Particle 3 = K- // The DP is defined in terms of m13Sq and m23Sq LauDaughters* daughters = new LauDaughters("D_s+", "pi+", "K+", "K-", squareDP); // Define the efficiency model (defaults to unity everywhere) LauVetoes* vetoes = new LauVetoes(); LauEffModel* effModel = new LauEffModel(daughters, vetoes); // Create the isobar model LauIsobarDynamics* sigModel = new LauIsobarDynamics(daughters, effModel); //LauAbsResonance* reson(0); /*reson =*/ sigModel->addResonance("phi(1020)", 1, LauAbsResonance::RelBW); // resPairAmpInt = 1 => resonance mass is m23. /*reson =*/ sigModel->addResonance("K*0(892)", 2, LauAbsResonance::RelBW); /*reson =*/ sigModel->addResonance("NonReson", 0, LauAbsResonance::FlatNR); // Set the maximum signal DP ASq value // If you do not provide a value, one will be determined automatically, // which should be close to the true maximum but is not guaranteed to // be optimal. // Any value, whether manually provided or automatically determined, // will be automatically adjusted to avoid bias or extreme inefficiency // but it is best to set this by hand once you've found the right value // through some trial and error. sigModel->setASqMaxValue(310.0); // Create the fit model LauSimpleFitModel* fitModel = new LauSimpleFitModel(sigModel); // Create the complex coefficients for the isobar model // Here we're using the magnitude and phase form: // c_j = a_j exp(i*delta_j) std::vector coeffset; coeffset.push_back( new LauMagPhaseCoeffSet("phi(1020)", 1.00, 0.00, kTRUE, kTRUE) ); coeffset.push_back( new LauMagPhaseCoeffSet("K*0(892)", 1.00, 0.00, kFALSE, kFALSE) ); coeffset.push_back( new LauMagPhaseCoeffSet("NonReson", 1.00, 0.00, kFALSE, kFALSE) ); for (std::vector::iterator iter=coeffset.begin(); iter!=coeffset.end(); ++iter) { fitModel->setAmpCoeffSet(*iter); } // Set the signal yield and define whether it is fixed or floated const Double_t nSigEvents = 10000.0; LauParameter * signalEvents = new LauParameter("signalEvents",nSigEvents,-1.0*nSigEvents,2.0*nSigEvents,kFALSE); fitModel->setNSigEvents(signalEvents); // Set the number of experiments to generate or fit and which // experiment to start with - fitModel->setNExpts( nExpt, firstExpt ); + fitModel->setNExpts( nExpt, firstExpt, isToy ); // Configure various fit options // Switch on/off calculation of asymmetric errors. fitModel->useAsymmFitErrors(kFALSE); // Randomise initial fit values for the signal mode fitModel->useRandomInitFitPars(kTRUE); const Bool_t haveBkgnds = ( fitModel->nBkgndClasses() > 0 ); // Switch on/off Poissonian smearing of total number of events fitModel->doPoissonSmearing(haveBkgnds); // Switch on/off Extended ML Fit option fitModel->doEMLFit(haveBkgnds); // Generate toy from the fitted parameters //TString fitToyFileName("fitToyMC_Ds2KKpi_"); //fitToyFileName += iFit; //fitToyFileName += ".root"; //fitModel->compareFitData(100, fitToyFileName); // Write out per-event likelihoods and sWeights //TString splotFileName("splot_Ds2KKpi_"); //splotFileName += iFit; //splotFileName += ".root"; //fitModel->writeSPlotData(splotFileName, "splot", kFALSE); // Set the names of the files to read/write TString dataFile("gen-Ds2KKpi.root"); TString treeName("genResults"); TString rootFileName(""); TString tableFileName(""); if (command == "fit") { rootFileName = "fitDs2KKpi_"; rootFileName += iFit; rootFileName += "_expt_"; rootFileName += firstExpt; rootFileName += "-"; rootFileName += (firstExpt+nExpt-1); rootFileName += ".root"; tableFileName = "fitDs2KKpiResults_"; tableFileName += iFit; } else { rootFileName = "dummy.root"; tableFileName = "genDs2KKpiResults"; } // Execute the generation/fit fitModel->run( command, dataFile, treeName, rootFileName, tableFileName ); return EXIT_SUCCESS; } diff --git a/examples/GenFitEFKLLM.cc b/examples/GenFitEFKLLM.cc index 2740b53..4a05e2c 100644 --- a/examples/GenFitEFKLLM.cc +++ b/examples/GenFitEFKLLM.cc @@ -1,205 +1,206 @@ /* Copyright 2015 University of Warwick Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /* Laura++ package authors: John Back Paul Harrison Thomas Latham */ #include #include #include #include "TFile.h" #include "TH2.h" #include "TString.h" #include "TTree.h" #include "LauSimpleFitModel.hh" #include "LauDaughters.hh" #include "LauEffModel.hh" #include "LauEFKLLMRes.hh" #include "LauIsobarDynamics.hh" #include "LauMagPhaseCoeffSet.hh" #include "LauVetoes.hh" void usage( std::ostream& out, const TString& progName ) { out<<"Usage:\n"; out< [nExpt = 1] [firstExpt = 0]"< [nExpt = 1] [firstExpt = 0] if ( argc < 2 ) { usage( std::cerr, argv[0] ); return EXIT_FAILURE; } TString command = argv[1]; command.ToLower(); Int_t iFit(0); Int_t nExpt(1); Int_t firstExpt(0); + Bool_t isToy(kTRUE); if ( command == "gen" ) { if ( argc > 2 ) { nExpt = atoi( argv[2] ); if ( argc > 3 ) { firstExpt = atoi( argv[3] ); } } } else if ( command == "fit" ) { if ( argc < 3 ) { usage( std::cerr, argv[0] ); return EXIT_FAILURE; } iFit = atoi( argv[2] ); if ( argc > 3 ) { nExpt = atoi( argv[3] ); if ( argc > 4 ) { firstExpt = atoi( argv[4] ); } } } else { usage( std::cerr, argv[0] ); return EXIT_FAILURE; } // If you want to use square DP histograms for efficiency, // backgrounds or you just want the square DP co-ordinates // stored in the toy MC ntuple then set this to kTRUE Bool_t squareDP = kFALSE; // This defines the DP => decay is B0 -> D0_bar K+ pi- // Particle 1 = D0_bar // Particle 2 = K+ // Particle 3 = pi- // The DP is defined in terms of m13Sq and m23Sq LauDaughters* daughters = new LauDaughters("B0", "D0_bar", "K+", "pi-", squareDP); // Define the efficiency model (defaults to unity everywhere) LauVetoes* vetoes = new LauVetoes(); LauEffModel* effModel = new LauEffModel(daughters, vetoes); // Create the isobar model LauIsobarDynamics* sigModel = new LauIsobarDynamics(daughters, effModel); LauEFKLLMRes::setupFormFactor("usfactor.dat"); // Add various components to the isobar model, // optionally allowing the masses and width to float in the fit LauAbsResonance* res(0); //addResonance arguments: resName, resPairAmpInt, resType res = sigModel->addResonance("kappa0", 1, LauAbsResonance::EFKLLM); res->setResonanceParameter("massFactor", 0.0); res = sigModel->addResonance("K*0_0(1430)", 1, LauAbsResonance::EFKLLM); res->setResonanceParameter("massFactor", -2.0); // Set the maximum signal DP ASq value // If you do not provide a value, one will be determined automatically, // which should be close to the true maximum but is not guaranteed to // be optimal. // Any value, whether manually provided or automatically determined, // will be automatically adjusted to avoid bias or extreme inefficiency // but it is best to set this by hand once you've found the right value // through some trial and error. sigModel->setASqMaxValue(14.5); // Create the fit model LauSimpleFitModel* fitModel = new LauSimpleFitModel(sigModel); // Create the complex coefficients for the isobar model // Here we're using the magnitude and phase form: // c_j = a_j exp(i*delta_j) std::vector coeffset; coeffset.push_back( new LauMagPhaseCoeffSet("kappa0", 1.0, 0.0, kTRUE, kTRUE) ); coeffset.push_back( new LauMagPhaseCoeffSet("K*0_0(1430)", 1.0, 0.0, kFALSE, kFALSE) ); for (std::vector::iterator iter=coeffset.begin(); iter!=coeffset.end(); ++iter) { fitModel->setAmpCoeffSet(*iter); } // Set the signal yield and define whether it is fixed or floated const Double_t nSigEvents = 5000.0; Bool_t fixNSigEvents = kFALSE; LauParameter * signalEvents = new LauParameter("signalEvents", nSigEvents, -1.0*nSigEvents, 2.0*nSigEvents, fixNSigEvents); fitModel->setNSigEvents(signalEvents); // Set the number of experiments to generate or fit and which // experiment to start with - fitModel->setNExpts( nExpt, firstExpt ); + fitModel->setNExpts( nExpt, firstExpt, isToy ); // Configure various fit options // Switch on/off calculation of asymmetric errors. fitModel->useAsymmFitErrors(kFALSE); // Randomise initial fit values for the signal mode fitModel->useRandomInitFitPars(kFALSE); const Bool_t haveBkgnds = ( fitModel->nBkgndClasses() > 0 ); // Switch on/off Poissonian smearing of total number of events fitModel->doPoissonSmearing(haveBkgnds); // Switch on/off Extended ML Fit option fitModel->doEMLFit(haveBkgnds); // Switch on the two-stage fit (for the resonance parameters) fitModel->twoStageFit(kTRUE); // Generate toy from the fitted parameters //TString fitToyFileName("fitToyMC_EFKLLM_"); //fitToyFileName += iFit; //fitToyFileName += ".root"; //fitModel->compareFitData(10, fitToyFileName); // Write out per-event likelihoods and sWeights //TString splotFileName("splot_EFKLLM_"); //splotFileName += iFit; //splotFileName += ".root"; //fitModel->writeSPlotData(splotFileName, "splot", kFALSE); TString dataFile("gen-EFKLLM.root"); TString treeName("genResults"); TString rootFileName(""); TString tableFileName(""); if (command == "fit") { rootFileName = "fitEFKLLM_"; rootFileName += iFit; rootFileName += "_expt_"; rootFileName += firstExpt; rootFileName += "-"; rootFileName += (firstExpt+nExpt-1); rootFileName += ".root"; tableFileName = "fitEFKLLMResults_"; tableFileName += iFit; } else { rootFileName = "dummy.root"; tableFileName = "genEFKLLMResults"; } // Execute the generation/fit fitModel->run( command, dataFile, treeName, rootFileName, tableFileName ); return EXIT_SUCCESS; } diff --git a/examples/GenFitKpipi.cc b/examples/GenFitKpipi.cc index f111e0b..ca1c840 100644 --- a/examples/GenFitKpipi.cc +++ b/examples/GenFitKpipi.cc @@ -1,583 +1,584 @@ /* Copyright 2005 University of Warwick Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /* Laura++ package authors: John Back Paul Harrison Thomas Latham */ #include #include #include #include "TFile.h" #include "TH2.h" #include "TString.h" #include "Lau1DHistPdf.hh" #include "LauArgusPdf.hh" #include "LauBkgndDPModel.hh" #include "LauCartesianCPCoeffSet.hh" #include "LauCPFitModel.hh" #include "LauDaughters.hh" #include "LauEffModel.hh" #include "LauGaussPdf.hh" #include "LauIsobarDynamics.hh" #include "LauLinearPdf.hh" #include "LauResonanceMaker.hh" #include "LauSumPdf.hh" #include "LauVetoes.hh" /* * Histogram ROOT files for this example are available at the following URL: * http://www.slac.stanford.edu/~tlatham/public/Laura++-example-histograms/histos.tar.gz *\ Please copy the "histos" directory into the working directory. */ void usage( std::ostream& out, const TString& progName ) { out<<"Usage:\n"; out< [nExpt = 1] [firstExpt = 0]"< [nExpt = 1] [firstExpt = 0] if ( argc < 2 ) { usage( std::cerr, argv[0] ); return EXIT_FAILURE; } TString command = argv[1]; command.ToLower(); Int_t iFit(0); Int_t nExpt(1); Int_t firstExpt(0); + Bool_t isToy(kTRUE); if ( command == "gen" ) { if ( argc > 2 ) { nExpt = atoi( argv[2] ); if ( argc > 3 ) { firstExpt = atoi( argv[3] ); } } } else if ( command == "fit" ) { if ( argc < 3 ) { usage( std::cerr, argv[0] ); return EXIT_FAILURE; } iFit = atoi( argv[2] ); if ( argc > 3 ) { nExpt = atoi( argv[3] ); if ( argc > 4 ) { firstExpt = atoi( argv[4] ); } } } else { usage( std::cerr, argv[0] ); return EXIT_FAILURE; } // If you want to use square DP histograms for efficiency, // backgrounds or you just want the square DP co-ordinates // stored in the toy MC ntuple then set this to kTRUE const Bool_t squareDP = kTRUE; // Set this to kFALSE if you want to remove the DP from the fit const Bool_t doDP = kTRUE; // Set this to kTRUE if you want to fix the CPV parameters const Bool_t fixCP = kFALSE; const Bool_t doTwoStageFit = !fixCP; // General histogram booleans const Bool_t useInterpolation = kTRUE; const Bool_t fluctuateBins = kFALSE; const Bool_t useUpperHalfOnly = kFALSE; // Signal and continuum yields - from Phys.Rev.D78:012004,2008 const Double_t nSigEvents = 4585.0; const Bool_t fixNSigEvents = kFALSE; const Double_t nBgEvents = 6830.0; const Bool_t fixNBgEvents = kFALSE; // Signal and continuum asymmetries // NB the signal asymmetry value here is only used if the DP is NOT // in the fit, otherwise the asymmetry is included within the // isobar model. const Double_t sigAsym = 0.028; const Bool_t fixSigAsym = kFALSE; const Double_t bgAsym = -0.028; const Bool_t fixBgAsym = kFALSE; // Define the DP (for both B+ and B- candidates) LauDaughters* negDaughters = new LauDaughters("B-", "K-", "pi-", "pi+", squareDP); LauDaughters* posDaughters = new LauDaughters("B+", "K+", "pi+", "pi-", squareDP); // Add some vetoes LauVetoes* vetoes = new LauVetoes(); const Double_t D_KpiMin = 1.756; const Double_t D_KpiMax = 1.931; const Double_t D_pipiMin = 1.660; const Double_t D_pipiMax = 1.800; const Double_t JpsiMin = 3.019; const Double_t JpsiMax = 3.179; const Double_t psi2SMin = 3.627; const Double_t psi2SMax = 3.747; vetoes->addMassVeto(2, D_KpiMin, D_KpiMax); // D0 veto, m13 vetoes->addMassVeto(1, D_pipiMin, D_pipiMax); // D0 veto, m23 vetoes->addMassVeto(1, JpsiMin, JpsiMax); // J/psi veto, m23 vetoes->addMassVeto(1, psi2SMin, psi2SMax); // psi(2S) veto, m23 // Create the efficiency models TFile* effHistoFile = TFile::Open("histos/eff/Kpipi_50x50.root", "read"); LauEffModel* negEffModel = new LauEffModel(negDaughters, vetoes); TString negEffHistoName("eff_all_neg"); TH2* negEffHisto = dynamic_cast(effHistoFile->Get(negEffHistoName)); negEffModel->setEffHisto(negEffHisto, useInterpolation, fluctuateBins, 0.0, 0.0, useUpperHalfOnly, squareDP); LauEffModel* posEffModel = new LauEffModel(posDaughters, vetoes); TString posEffHistoName("eff_all_pos"); TH2* posEffHisto = dynamic_cast(effHistoFile->Get(posEffHistoName)); posEffModel->setEffHisto(posEffHisto, useInterpolation, fluctuateBins, 0.0, 0.0, useUpperHalfOnly, squareDP); // Create the signal dynamics LauResonanceMaker& resMaker = LauResonanceMaker::get(); resMaker.setDefaultBWRadius( LauBlattWeisskopfFactor::Parent, 4.0 ); resMaker.setDefaultBWRadius( LauBlattWeisskopfFactor::Kstar, 4.0 ); resMaker.setDefaultBWRadius( LauBlattWeisskopfFactor::Light, 4.0 ); resMaker.setDefaultBWRadius( LauBlattWeisskopfFactor::Charmonium, 4.0 ); LauIsobarDynamics* negSigModel = new LauIsobarDynamics(negDaughters, negEffModel); negSigModel->setIntFileName("integ_neg.dat"); negSigModel->setASqMaxValue(0.45); LauAbsResonance* res(0); res = negSigModel->addResonance("K*0(892)", 2, LauAbsResonance::RelBW); res = negSigModel->addResonance("K*0_0(1430)", 2, LauAbsResonance::LASS); res = negSigModel->addResonance("rho0(770)", 1, LauAbsResonance::RelBW); res = negSigModel->addResonance("f_0(980)", 1, LauAbsResonance::Flatte); res->changeResonance( 0.965, -1.0, -1 ); res = negSigModel->addResonance("chi_c0", 1, LauAbsResonance::RelBW); res = negSigModel->addResonance("NonReson", 0, LauAbsResonance::FlatNR); res = negSigModel->addResonance("K*0_2(1430)", 2, LauAbsResonance::RelBW); res = negSigModel->addResonance("omega(782)", 1, LauAbsResonance::RelBW); res = negSigModel->addResonance("f_2(1270)", 1, LauAbsResonance::RelBW); res = negSigModel->addResonance("f'_0(1300)", 1, LauAbsResonance::RelBW); res->changeResonance( 1.479, 0.080, -1 ); LauIsobarDynamics* posSigModel = new LauIsobarDynamics(posDaughters, posEffModel); posSigModel->setIntFileName("integ_pos.dat"); posSigModel->setASqMaxValue(0.45); res = posSigModel->addResonance("K*0(892)", 2, LauAbsResonance::RelBW); res = posSigModel->addResonance("K*0_0(1430)", 2, LauAbsResonance::LASS); res = posSigModel->addResonance("rho0(770)", 1, LauAbsResonance::RelBW); res = posSigModel->addResonance("f_0(980)", 1, LauAbsResonance::Flatte); res->changeResonance( 0.965, -1.0, -1 ); res = posSigModel->addResonance("chi_c0", 1, LauAbsResonance::RelBW); res = posSigModel->addResonance("NonReson", 0, LauAbsResonance::FlatNR); res = posSigModel->addResonance("K*0_2(1430)", 2, LauAbsResonance::RelBW); res = posSigModel->addResonance("omega(782)", 1, LauAbsResonance::RelBW); res = posSigModel->addResonance("f_2(1270)", 1, LauAbsResonance::RelBW); res = posSigModel->addResonance("f'_0(1300)", 1, LauAbsResonance::RelBW); res->changeResonance( 1.479, 0.080, -1 ); // Create the fit model, passing it the two signal dynamics models LauCPFitModel* fitModel = new LauCPFitModel(negSigModel,posSigModel); fitModel->useDP(doDP); // Set isobar coefficients - taken from Phys.Rev.D78:012004,2008 std::vector coeffset; coeffset.push_back(new LauCartesianCPCoeffSet("K*0(892)", 1.000, 0.000, -0.017, -0.238, kTRUE, kTRUE, fixCP, fixCP, doTwoStageFit, doTwoStageFit)); coeffset.push_back(new LauCartesianCPCoeffSet("K*0_0(1430)", 1.718, -0.727, -0.154, -0.285, kFALSE, kFALSE, fixCP, fixCP, doTwoStageFit, doTwoStageFit)); coeffset.push_back(new LauCartesianCPCoeffSet("rho0(770)", 0.683, -0.025, -0.160, 0.169, kFALSE, kFALSE, fixCP, fixCP, doTwoStageFit, doTwoStageFit)); coeffset.push_back(new LauCartesianCPCoeffSet("f_0(980)", -0.220, 1.203, -0.109, 0.047, kFALSE, kFALSE, fixCP, fixCP, doTwoStageFit, doTwoStageFit)); coeffset.push_back(new LauCartesianCPCoeffSet("chi_c0", -0.263, 0.180, -0.033, -0.007, kFALSE, kFALSE, fixCP, fixCP, doTwoStageFit, doTwoStageFit)); coeffset.push_back(new LauCartesianCPCoeffSet("NonReson", -0.594, 0.068, 0.000, 0.000, kFALSE, kFALSE, kTRUE, kTRUE)); coeffset.push_back(new LauCartesianCPCoeffSet("K*0_2(1430)", -0.301, 0.424, 0.032, 0.007, kFALSE, kFALSE, fixCP, fixCP, doTwoStageFit, doTwoStageFit)); coeffset.push_back(new LauCartesianCPCoeffSet("omega(782)", -0.058, 0.100, 0.000, 0.000, kFALSE, kFALSE, kTRUE, kTRUE)); coeffset.push_back(new LauCartesianCPCoeffSet("f_2(1270)", -0.193, 0.110, -0.089, 0.125, kFALSE, kFALSE, fixCP, fixCP, doTwoStageFit, doTwoStageFit)); coeffset.push_back(new LauCartesianCPCoeffSet("f'_0(1300)", -0.290, -0.136, 0.024, 0.056, kFALSE, kFALSE, fixCP, fixCP, doTwoStageFit, doTwoStageFit)); for (std::vector::iterator iter=coeffset.begin(); iter!=coeffset.end(); ++iter) { fitModel->setAmpCoeffSet(*iter); } // Set the number of signal events and the number of experiments LauParameter * signalEvents = new LauParameter("signalEvents",nSigEvents,-1.0*nSigEvents,2.0*nSigEvents,fixNSigEvents); LauParameter * signalAsym = new LauParameter("signalAsym",sigAsym,-1.0,1.0,fixSigAsym); fitModel->setNSigEvents(signalEvents, signalAsym); - fitModel->setNExpts(nExpt, firstExpt); + fitModel->setNExpts(nExpt, firstExpt, isToy); // Set up the background configuration const Int_t nBBs(1); TString vetoCorrHistName(""); TString qqDPName = ""; std::vector BBNames(nBBs); std::vector BBDPNames(nBBs); std::vector BBMESNames(nBBs); std::vector BBDENames(nBBs); if (squareDP) { vetoCorrHistName = "correctionSqDPHisto"; qqDPName = "onres_sqDP_histo"; for (Int_t i(0); i bkgndNames( nBBs + 1 ); bkgndNames[0] = "qqbar"; for (Int_t i(0); isetBkgndClassNames( bkgndNames ); // Get the histogram for correcting the other histograms for the // effect of the vetoes on bins on a veto boundary TString vetoCorrFileName("histos/veto-correction/vetoCorrectionHisto_50.root"); TFile* vetoCorrFile = TFile::Open(vetoCorrFileName, "read"); TH2* vetoCorrHist = dynamic_cast(vetoCorrFile->Get(vetoCorrHistName)); // Load the qqbar DP histograms TString negqqFileName("histos/qqbar/qqbarBackgroundHistos_50_neg.root"); TFile* negqqFile = TFile::Open(negqqFileName, "read"); TH2* negqqDP = dynamic_cast(negqqFile->Get(qqDPName)); negqqDP->Divide(vetoCorrHist); LauBkgndDPModel* negqqbarModel= new LauBkgndDPModel(negDaughters, vetoes); negqqbarModel->setBkgndHisto( negqqDP, useInterpolation, fluctuateBins, useUpperHalfOnly, squareDP ); TString posqqFileName("histos/qqbar/qqbarBackgroundHistos_50_pos.root"); TFile* posqqFile = TFile::Open(posqqFileName, "read"); TH2* posqqDP = dynamic_cast(posqqFile->Get(qqDPName)); posqqDP->Divide(vetoCorrHist); LauBkgndDPModel* posqqbarModel= new LauBkgndDPModel(posDaughters, vetoes); posqqbarModel->setBkgndHisto( posqqDP, useInterpolation, fluctuateBins, useUpperHalfOnly, squareDP ); LauParameter* backgroundEvents = new LauParameter("qqbar",nBgEvents,-1.0*nBgEvents,2.0*nBgEvents,fixNBgEvents); LauParameter* backgroundAsym = new LauParameter("qqbar",bgAsym,-1.0,1.0,fixBgAsym); fitModel->setNBkgndEvents( backgroundEvents, backgroundAsym ); fitModel->setBkgndDPModels( "qqbar", negqqbarModel, posqqbarModel ); // Load the BBbar DP histograms TString negBBFileName("histos/BBbar/BbackgroundHistos_50_neg_categories.root"); TFile* negBBFile = TFile::Open(negBBFileName, "read"); TString posBBFileName("histos/BBbar/BbackgroundHistos_50_pos_categories.root"); TFile* posBBFile = TFile::Open(posBBFileName, "read"); std::vector negBBDP(nBBs); std::vector posBBDP(nBBs); std::vector nBBEvents(nBBs); std::vector BBAsym(nBBs); std::vector negBBModels(nBBs); std::vector posBBModels(nBBs); for (Int_t i(0); icd(); negBBDP[i] = dynamic_cast(negBBFile->Get(BBDPNames[i])); if (negBBDP[i] == 0) { std::cerr<<"Problem finding histogram \""<Integral(); negBBDP[i]->Divide(vetoCorrHist); negBBModels[i] = new LauBkgndDPModel(negDaughters, vetoes); negBBModels[i]->setBkgndHisto(negBBDP[i], useInterpolation, fluctuateBins, useUpperHalfOnly, squareDP); posBBFile->cd(); posBBDP[i] = dynamic_cast(posBBFile->Get(BBDPNames[i])); if (posBBDP[i] == 0) { std::cerr<<"Problem finding histogram \""<Integral(); posBBDP[i]->Divide(vetoCorrHist); posBBModels[i] = new LauBkgndDPModel(posDaughters, vetoes); posBBModels[i]->setBkgndHisto(posBBDP[i], useInterpolation, fluctuateBins, useUpperHalfOnly, squareDP); Double_t totalBBEvents = negBBEvents + posBBEvents; Double_t asym = ( negBBEvents - posBBEvents ) / totalBBEvents ; nBBEvents[i] = new LauParameter(BBNames[i],totalBBEvents,-2.0*totalBBEvents,2.0*totalBBEvents,kTRUE); BBAsym[i] = new LauParameter(BBNames[i],asym,-1.0,1.0,kTRUE); fitModel->setBkgndDPModels(BBNames[i], negBBModels[i], posBBModels[i] ); fitModel->setNBkgndEvents( nBBEvents[i], BBAsym[i] ); } // Signal mES and DeltaEsig PDF parameter values, shifts and scale factors Double_t mes_mean1_value = 5.279443; Double_t mes_mean2_value = 5.275484; Double_t mes_sigma1_value = 0.0023974; Double_t mes_frac_value = 0.9094; Double_t de_mean1_value = -0.00955; Double_t de_mean2_value = -0.632; Double_t de_sigma1_value = 1.0771; Double_t de_sigma2_value = 2.258; Double_t de_frac_value = 0.8069; // mES PDFs // PDFs for B+ and B- are set to be identical here but could be different in general Double_t mesMin = 5.272; Double_t mesMax = 5.286; // Signal PDF is a double Gaussian with the widths constrained to be the same LauParameter* mes_mean1_neg = new LauParameter("mes_mean1_neg", mes_mean1_value, 5.272, 5.286, kTRUE); LauParameter* mes_sigma1_neg = new LauParameter("mes_sigma1_neg", mes_sigma1_value, 0.000, 0.010, kTRUE); LauParameter* mes_mean2_neg = new LauParameter("mes_mean2_neg", mes_mean2_value, 5.272, 5.286, kTRUE); LauParameter* mes_sigma2_neg = mes_sigma1_neg->createClone(); LauParameter* mes_frac_neg = new LauParameter("mes_frac_neg", mes_frac_value, 0.000, 1.000, kTRUE); std::vector mesPars; mesPars.reserve(2); mesPars.push_back(mes_mean1_neg); mesPars.push_back(mes_sigma1_neg); LauAbsPdf* sigNegMESPdf1 = new LauGaussPdf("mES", mesPars, mesMin, mesMax); mesPars.clear(); mesPars.push_back(mes_mean2_neg); mesPars.push_back(mes_sigma2_neg); LauAbsPdf* sigNegMESPdf2 = new LauGaussPdf("mES", mesPars, mesMin, mesMax); LauAbsPdf* sigNegMESPdf = new LauSumPdf(sigNegMESPdf1, sigNegMESPdf2, mes_frac_neg); mesPars.clear(); LauParameter* mes_mean1_pos = mes_mean1_neg->createClone(); LauParameter* mes_sigma1_pos = mes_sigma1_neg->createClone(); LauParameter* mes_mean2_pos = mes_mean2_neg->createClone(); LauParameter* mes_sigma2_pos = mes_sigma1_pos->createClone(); LauParameter* mes_frac_pos = mes_frac_neg->createClone(); mesPars.push_back(mes_mean1_pos); mesPars.push_back(mes_sigma1_pos); LauAbsPdf* sigPosMESPdf1 = new LauGaussPdf("mES", mesPars, mesMin, mesMax); mesPars.clear(); mesPars.push_back(mes_mean2_pos); mesPars.push_back(mes_sigma2_pos); LauAbsPdf* sigPosMESPdf2 = new LauGaussPdf("mES", mesPars, mesMin, mesMax); LauAbsPdf* sigPosMESPdf = new LauSumPdf(sigPosMESPdf1, sigPosMESPdf2, mes_frac_pos); fitModel->setSignalPdfs(sigNegMESPdf, sigPosMESPdf); // Continuum PDF is an ARGUS function mesPars.clear(); LauParameter* mes_qqbar_m0_neg = new LauParameter("mes_qqbar_m0", 5.289); LauParameter* mes_qqbar_xi_neg = new LauParameter("mes_qqbar_xi_neg", 13.3, 0.0, 50.0, kTRUE); mesPars.push_back(mes_qqbar_m0_neg); mesPars.push_back(mes_qqbar_xi_neg); LauAbsPdf* qqbarNegMESPdf = new LauArgusPdf("mES", mesPars, mesMin, mesMax); mesPars.clear(); LauParameter* mes_qqbar_m0_pos = mes_qqbar_m0_neg->createClone(); LauParameter* mes_qqbar_xi_pos = mes_qqbar_xi_neg->createClone(); mesPars.push_back(mes_qqbar_m0_pos); mesPars.push_back(mes_qqbar_xi_pos); LauAbsPdf* qqbarPosMESPdf = new LauArgusPdf("mES", mesPars, mesMin, mesMax); fitModel->setBkgndPdfs( "qqbar", qqbarNegMESPdf, qqbarPosMESPdf ); // BB background PDFs are 1D histograms std::vector negBBMES(nBBs); std::vector posBBMES(nBBs); std::vector negBBMESPdfs(nBBs); std::vector posBBMESPdfs(nBBs); for (Int_t i(0); icd(); negBBMES[i] = dynamic_cast(negBBFile->Get(BBMESNames[i])); if (negBBMES[i] == 0) { std::cerr<<"Problem finding histogram \""<cd(); posBBMES[i] = dynamic_cast(posBBFile->Get(BBMESNames[i])); if (posBBMES[i] == 0) { std::cerr<<"Problem finding histogram \""<setBkgndPdfs( BBNames[i], negBBMESPdfs[i], posBBMESPdfs[i] ); } // deltaE significance PDFs // PDFs for B+ and B- are set to be identical here but could be different in general Double_t deMin = -4.0; Double_t deMax = 4.0; // Signal PDF is a double Gaussian LauParameter* de_sig_mean1_neg = new LauParameter("de_sig_mean1_neg", de_mean1_value, -4.0, 4.0, kTRUE); LauParameter* de_sig_sigma1_neg = new LauParameter("de_sig_sigma1_neg", de_sigma1_value, 0.0, 4.0, kTRUE); LauParameter* de_sig_mean2_neg = new LauParameter("de_sig_mean2_neg", de_mean2_value, -4.0, 4.0, kTRUE); LauParameter* de_sig_sigma2_neg = new LauParameter("de_sig_sigma2_neg", de_sigma2_value, 0.0, 4.0, kTRUE); LauParameter* de_sig_frac_neg = new LauParameter("de_sig_frac_neg", de_frac_value, 0.0, 1.0, kTRUE); std::vector dePars; dePars.reserve(2); dePars.push_back(de_sig_mean1_neg); dePars.push_back(de_sig_sigma1_neg); LauAbsPdf* sigNegDE1Pdf = new LauGaussPdf("deltaEsig", dePars, deMin, deMax); dePars.clear(); dePars.push_back(de_sig_mean2_neg); dePars.push_back(de_sig_sigma2_neg); LauAbsPdf* sigNegDE2Pdf = new LauGaussPdf("deltaEsig", dePars, deMin, deMax); LauAbsPdf* sigNegDEPdf = new LauSumPdf(sigNegDE1Pdf, sigNegDE2Pdf, de_sig_frac_neg); dePars.clear(); LauParameter* de_sig_mean1_pos = de_sig_mean1_neg->createClone(); LauParameter* de_sig_sigma1_pos = de_sig_sigma1_neg->createClone(); LauParameter* de_sig_mean2_pos = de_sig_mean2_neg->createClone(); LauParameter* de_sig_sigma2_pos = de_sig_sigma2_neg->createClone(); LauParameter* de_sig_frac_pos = de_sig_frac_neg->createClone(); dePars.push_back(de_sig_mean1_pos); dePars.push_back(de_sig_sigma1_pos); LauAbsPdf* sigPosDE1Pdf = new LauGaussPdf("deltaEsig", dePars, deMin, deMax); dePars.clear(); dePars.push_back(de_sig_mean2_pos); dePars.push_back(de_sig_sigma2_pos); LauAbsPdf* sigPosDE2Pdf = new LauGaussPdf("deltaEsig", dePars, deMin, deMax); LauAbsPdf* sigPosDEPdf = new LauSumPdf(sigPosDE1Pdf, sigPosDE2Pdf, de_sig_frac_pos); fitModel->setSignalPdfs(sigNegDEPdf, sigPosDEPdf); // Continuum PDF is a 1st order polynomial dePars.clear(); LauParameter* de_qqbar_slope_neg = new LauParameter("de_qqbar_slope_neg", -0.00241, -0.01, 0.01, kFALSE); dePars.push_back(de_qqbar_slope_neg); LauAbsPdf * qqbarNegDEPdf = new LauLinearPdf("deltaEsig", dePars, deMin, deMax); dePars.clear(); LauParameter* de_qqbar_slope_pos = de_qqbar_slope_neg->createClone(); dePars.push_back(de_qqbar_slope_pos); LauAbsPdf * qqbarPosDEPdf = new LauLinearPdf("deltaEsig", dePars, deMin, deMax); fitModel->setBkgndPdfs( "qqbar", qqbarNegDEPdf, qqbarPosDEPdf ); // BB background PDFs are 1D histograms std::vector negBBDE(nBBs); std::vector posBBDE(nBBs); std::vector negBBDEPdfs(nBBs); std::vector posBBDEPdfs(nBBs); for (Int_t i(0); icd(); negBBDE[i] = dynamic_cast(negBBFile->Get(BBDENames[i])); if (negBBDE[i] == 0) { std::cerr<<"Problem finding histogram \""<cd(); posBBDE[i] = dynamic_cast(posBBFile->Get(BBDENames[i])); if (posBBDE[i] == 0) { std::cerr<<"Problem finding histogram \""<setBkgndPdfs( BBNames[i], negBBDEPdfs[i], posBBDEPdfs[i] ); } // Configure various fit options // Do not calculate asymmetric errors. fitModel->useAsymmFitErrors(kFALSE); // Randomise initial fit values for the signal isobar parameters fitModel->useRandomInitFitPars(kTRUE); // Switch on/off Poissonian smearing of total number of events fitModel->doPoissonSmearing(kTRUE); // Switch on/off Extended ML Fit option fitModel->doEMLFit(kTRUE); // Switch on/off two-stage fitting for CPV parameters fitModel->twoStageFit(doTwoStageFit); // Generate toy from the fitted parameters //TString fitToyFileName("fitToyMC_Kpipi_"); //fitToyFileName += iFit; //fitToyFileName += ".root"; //fitModel->compareFitData(100, fitToyFileName); // Write out per-event likelihoods and sWeights //TString splotFileName("splot_Kpipi_"); //splotFileName += iFit; //splotFileName += ".root"; //fitModel->writeSPlotData(splotFileName, "splot", kFALSE); // Set the names of the files to read/write TString dataFile("gen-Kpipi.root"); TString treeName("genResults"); TString rootFileName(""); TString tableFileName(""); if (command == "fit") { rootFileName = "fitKpipi_"; rootFileName += iFit; rootFileName += "_expts"; rootFileName += firstExpt; rootFileName += "-"; rootFileName += firstExpt+nExpt-1; rootFileName += ".root"; tableFileName = "fitKpipiResults_"; tableFileName += iFit; } else { rootFileName = "dummy.root"; tableFileName = "genKpipiResults"; } // Execute the generation/fit fitModel->run(command, dataFile, treeName, rootFileName, tableFileName); return EXIT_SUCCESS; } diff --git a/examples/GenFitNoDP.cc b/examples/GenFitNoDP.cc index 389c497..83b4c4e 100644 --- a/examples/GenFitNoDP.cc +++ b/examples/GenFitNoDP.cc @@ -1,248 +1,249 @@ /* Copyright 2010 University of Warwick Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /* Laura++ package authors: John Back Paul Harrison Thomas Latham */ #include #include #include #include "TFile.h" #include "TH2.h" #include "TString.h" #include "LauSimpleFitModel.hh" #include "LauCrystalBallPdf.hh" #include "LauDaughters.hh" #include "LauEffModel.hh" #include "LauExponentialPdf.hh" #include "LauGaussPdf.hh" #include "LauIsobarDynamics.hh" #include "LauLinearPdf.hh" #include "LauRealImagCoeffSet.hh" #include "LauSumPdf.hh" #include "LauVetoes.hh" void usage( std::ostream& out, const TString& progName ) { out<<"Usage:\n"; out< [nExpt = 1] [firstExpt = 0]"< [nExpt = 1] [firstExpt = 0] if ( argc < 2 ) { usage( std::cerr, argv[0] ); return EXIT_FAILURE; } TString command = argv[1]; command.ToLower(); Int_t iFit(0); Int_t nExpt(1); Int_t firstExpt(0); + Bool_t isToy(kTRUE); if ( command == "gen" ) { if ( argc > 2 ) { nExpt = atoi( argv[2] ); if ( argc > 3 ) { firstExpt = atoi( argv[3] ); } } } else if ( command == "fit" ) { if ( argc < 3 ) { usage( std::cerr, argv[0] ); return EXIT_FAILURE; } iFit = atoi( argv[2] ); if ( argc > 3 ) { nExpt = atoi( argv[3] ); if ( argc > 4 ) { firstExpt = atoi( argv[4] ); } } } else { usage( std::cerr, argv[0] ); return EXIT_FAILURE; } // Still need to define the DP, so just make one up! LauDaughters* daughters = new LauDaughters("B+", "K+", "pi+", "pi-"); // Need a dummy vetoes object LauVetoes* vetoes = new LauVetoes(); // Need a dummy efficiency object LauEffModel* effModel = new LauEffModel(daughters, vetoes); // Create the signal dynamics object and just give it a non-resonant component LauIsobarDynamics* sigModel = new LauIsobarDynamics(daughters, effModel); sigModel->setIntFileName("integ.dat"); sigModel->addResonance("NonReson", 0, LauAbsResonance::FlatNR); // Create the fit model, passing it the signal dynamics model LauSimpleFitModel* fitModel = new LauSimpleFitModel(sigModel); fitModel->useDP(kFALSE); // Set isobar coefficients for the NR to be 1+0i (and fixed) LauAbsCoeffSet* coeffset = new LauRealImagCoeffSet("NonReson", 1.0, 0.0, kTRUE, kTRUE); fitModel->setAmpCoeffSet( coeffset ); // Set up the additional background configuration const Int_t nBkgnds(2); std::vector bkgndNames(nBkgnds); bkgndNames[0] = "Combinatorial"; bkgndNames[1] = "PartialReco"; fitModel->setBkgndClassNames( bkgndNames ); // Signal and background yields Double_t nSigEvents = 5000.0; Bool_t fixNSigEvents = kFALSE; Double_t nCombBgEvents = 7000.0; Bool_t fixNCombBgEvents = kFALSE; Double_t nPartRecoBgEvents = 3000.0; Bool_t fixNPartRecoBgEvents = kFALSE; Double_t nTotEvents = nSigEvents + nCombBgEvents + nPartRecoBgEvents; // Set the number of signal and background events and the number of experiments LauParameter* nSig = new LauParameter("signalEvents",nSigEvents,-1.0*nTotEvents,2.0*nTotEvents,fixNSigEvents); LauParameter* nCombBkg = new LauParameter("Combinatorial",nCombBgEvents,-1.0*nTotEvents,2.0*nTotEvents,fixNCombBgEvents); LauParameter* nPartBkg = new LauParameter("PartialReco",nPartRecoBgEvents,-1.0*nTotEvents,2.0*nTotEvents,fixNPartRecoBgEvents); // Optionally blind the yield parameters //nSig->blindParameter("something1",2000.0); //nCombBkg->blindParameter("something2",2000.0); //nPartBkg->blindParameter("something3",2000.0); fitModel->setNSigEvents(nSig); fitModel->setNBkgndEvents( nCombBkg ); fitModel->setNBkgndEvents( nPartBkg ); - fitModel->setNExpts(nExpt, firstExpt); + fitModel->setNExpts(nExpt, firstExpt, isToy); // Signal mB PDF parameter values Double_t sig_mb_mean1_value = 5.279; Double_t sig_mb_sigma1_value = 0.02; Double_t sig_mb_sigma2_value = 0.07; Double_t sig_mb_frac_value = 0.90; // m_B PDFs Double_t mbMin = 5.150; Double_t mbMax = 5.600; std::vector mbPars; mbPars.reserve(2); // Signal PDF is a double Gaussian with the means constrained to be the same LauParameter* sig_mb_mean1 = new LauParameter("sig_mb_mean1", sig_mb_mean1_value, 5.2, 5.3, kTRUE); LauParameter* sig_mb_sigma1 = new LauParameter("sig_mb_sigma1", sig_mb_sigma1_value, 0.0, 0.1, kTRUE); LauParameter* sig_mb_mean2 = sig_mb_mean1->createClone(); LauParameter* sig_mb_sigma2 = new LauParameter("sig_mb_sigma2", sig_mb_sigma2_value, 0.0, 0.2, kTRUE); LauParameter* sig_mb_frac = new LauParameter("sig_mb_frac", sig_mb_frac_value, 0.0, 1.0, kTRUE); mbPars.clear(); mbPars.push_back(sig_mb_mean1); mbPars.push_back(sig_mb_sigma1); LauAbsPdf* sigMBPdf1 = new LauGaussPdf("mB", mbPars, mbMin, mbMax); mbPars.clear(); mbPars.push_back(sig_mb_mean2); mbPars.push_back(sig_mb_sigma2); LauAbsPdf* sigMBPdf2 = new LauGaussPdf("mB", mbPars, mbMin, mbMax); LauAbsPdf* sigMBPdf = new LauSumPdf(sigMBPdf1, sigMBPdf2, sig_mb_frac); fitModel->setSignalPdf(sigMBPdf); // Combinatoric background PDF is linear function LauParameter* comb_mb_slope = new LauParameter("comb_mb_slope", -0.05, -1.0, 1.0, kTRUE); mbPars.clear(); mbPars.push_back(comb_mb_slope); LauAbsPdf* combMBPdf = new LauLinearPdf("mB", mbPars, mbMin, mbMax); fitModel->setBkgndPdf( bkgndNames[0], combMBPdf ); // Partially reconstructed background PDF is a crystal ball function LauParameter* pr_mb_mean = new LauParameter("pr_mb_mean", 5.200, 5.1, 5.3, kTRUE); LauParameter* pr_mb_sigma = new LauParameter("pr_mb_sigma", 0.050, 0.0, 0.2, kTRUE); LauParameter* pr_mb_alpha = new LauParameter("pr_mb_alpha", 0.100, -5.0, 5.0, kTRUE); LauParameter* pr_mb_order = new LauParameter("pr_mb_order", 4.000, 0.0, 5.0, kTRUE); mbPars.clear(); mbPars.push_back(pr_mb_mean); mbPars.push_back(pr_mb_sigma); mbPars.push_back(pr_mb_alpha); mbPars.push_back(pr_mb_order); LauAbsPdf* prbgMBPdf = new LauCrystalBallPdf("mB", mbPars, mbMin, mbMax); fitModel->setBkgndPdf( bkgndNames[1], prbgMBPdf ); // Configure various fit options // Do not calculate asymmetric errors. fitModel->useAsymmFitErrors(kTRUE); // Randomise initial fit values for the signal isobar parameters fitModel->useRandomInitFitPars(kTRUE); // Switch on/off Poissonian smearing of total number of events fitModel->doPoissonSmearing(kTRUE); // Switch on/off Extended ML Fit option fitModel->doEMLFit(kTRUE); // Switch on/off two-stage fitting for CPV parameters fitModel->twoStageFit(kFALSE); // Generate toy from the fitted parameters //TString fitToyFileName("fitToyMC_NoDP_"); //fitToyFileName += iFit; //fitToyFileName += ".root"; //fitModel->compareFitData(100, fitToyFileName); // Write out per-event likelihoods and sWeights //TString splotFileName("splot_NoDP_"); //splotFileName += iFit; //splotFileName += ".root"; //fitModel->writeSPlotData(splotFileName, "splot", kFALSE); TString dataFile("gen-NoDP.root"); TString treeName("genResults"); TString rootFileName(""); TString tableFileName(""); if (command == "fit") { rootFileName = "fitNoDP_"; rootFileName += iFit; rootFileName += "_expt_"; rootFileName += firstExpt; rootFileName += "-"; rootFileName += firstExpt+nExpt-1; rootFileName += ".root"; tableFileName = "fitNoDPResults_"; tableFileName += iFit; } else { rootFileName = "dummy.root"; tableFileName = "genNoDPResults"; } // Execute the generation/fit fitModel->run(command, dataFile, treeName, rootFileName, tableFileName); return EXIT_SUCCESS; } diff --git a/examples/GenFitNoDPMultiDim.cc b/examples/GenFitNoDPMultiDim.cc index 397ceba..d9d150a 100644 --- a/examples/GenFitNoDPMultiDim.cc +++ b/examples/GenFitNoDPMultiDim.cc @@ -1,266 +1,267 @@ /* Copyright 2010 University of Warwick Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /* Laura++ package authors: John Back Paul Harrison Thomas Latham */ #include #include #include #include "TFile.h" #include "TH2.h" #include "TString.h" #include "LauSimpleFitModel.hh" #include "LauArgusPdf.hh" #include "LauDaughters.hh" #include "LauEffModel.hh" #include "LauGaussPdf.hh" #include "LauIsobarDynamics.hh" #include "LauLinearPdf.hh" #include "LauRealImagCoeffSet.hh" #include "LauSumPdf.hh" #include "LauVetoes.hh" void usage( std::ostream& out, const TString& progName ) { out<<"Usage:\n"; out< [nExpt = 1] [firstExpt = 0]"< [nExpt = 1] [firstExpt = 0] if ( argc < 2 ) { usage( std::cerr, argv[0] ); return EXIT_FAILURE; } TString command = argv[1]; command.ToLower(); Int_t iFit(0); Int_t nExpt(1); Int_t firstExpt(0); + Bool_t isToy(kTRUE); if ( command == "gen" ) { if ( argc > 2 ) { nExpt = atoi( argv[2] ); if ( argc > 3 ) { firstExpt = atoi( argv[3] ); } } } else if ( command == "fit" ) { if ( argc < 3 ) { usage( std::cerr, argv[0] ); return EXIT_FAILURE; } iFit = atoi( argv[2] ); if ( argc > 3 ) { nExpt = atoi( argv[3] ); if ( argc > 4 ) { firstExpt = atoi( argv[4] ); } } } else { usage( std::cerr, argv[0] ); return EXIT_FAILURE; } // Still need to define the DP, so just make one up! LauDaughters* daughters = new LauDaughters("B+", "K+", "pi+", "pi-"); // Need a dummy vetoes object LauVetoes* vetoes = new LauVetoes(); // Need a dummy efficiency object LauEffModel* effModel = new LauEffModel(daughters, vetoes); // Create the signal dynamics object and just give it a non-resonant component LauIsobarDynamics* sigModel = new LauIsobarDynamics(daughters, effModel); sigModel->setIntFileName("integ.dat"); sigModel->addResonance("NonReson", 0, LauAbsResonance::FlatNR); // Create the fit model, passing it the signal dynamics model LauSimpleFitModel* fitModel = new LauSimpleFitModel(sigModel); fitModel->useDP(kFALSE); // Set isobar coefficients for the NR to be 1+0i (and fixed) LauAbsCoeffSet* coeffset = new LauRealImagCoeffSet("NonReson", 1.0, 0.0, kTRUE, kTRUE); fitModel->setAmpCoeffSet( coeffset ); // Define the background categories std::vector bkgndClasses(1); bkgndClasses[0] = "qqbar"; fitModel->setBkgndClassNames( bkgndClasses ); // Signal and background yields const Double_t nSigEvents = 5000.0; const Bool_t fixNSigEvents = kFALSE; const Double_t nCombBgEvents = 7000.0; const Bool_t fixNCombBgEvents = kFALSE; // Set the number of signal and background events and the number of experiments LauParameter* nSig = new LauParameter("signalEvents",nSigEvents,-1.0*nSigEvents,2.0*nSigEvents,fixNSigEvents); LauParameter* nBkg = new LauParameter("qqbar",nCombBgEvents,-1.0*nCombBgEvents,2.0*nCombBgEvents,fixNCombBgEvents); fitModel->setNSigEvents(nSig); fitModel->setNBkgndEvents(nBkg); - fitModel->setNExpts(nExpt, firstExpt); + fitModel->setNExpts(nExpt, firstExpt, isToy); // Signal mES PDF parameter values Double_t sig_mes_mean1_value = 5.279; Double_t sig_mes_sigma1_value = 0.002; Double_t sig_mes_sigma2_value = 0.007; Double_t sig_mes_frac_value = 0.90; // mES PDFs Double_t mesMin = 5.260; Double_t mesMax = 5.286; std::vector mesPars; mesPars.reserve(2); // Signal PDF is a double Gaussian with the means constrained to be the same LauParameter* sig_mes_mean1 = new LauParameter("sig_mes_mean1", sig_mes_mean1_value, 5.2, 5.3, kTRUE); LauParameter* sig_mes_sigma1 = new LauParameter("sig_mes_sigma1", sig_mes_sigma1_value, 0.0, 0.1, kTRUE); LauParameter* sig_mes_mean2 = sig_mes_mean1->createClone(); LauParameter* sig_mes_sigma2 = new LauParameter("sig_mes_sigma2", sig_mes_sigma2_value, 0.0, 0.2, kTRUE); LauParameter* sig_mes_frac = new LauParameter("sig_mes_frac", sig_mes_frac_value, 0.0, 1.0, kTRUE); mesPars.clear(); mesPars.push_back(sig_mes_mean1); mesPars.push_back(sig_mes_sigma1); LauAbsPdf* sigMESPdf1 = new LauGaussPdf("mES", mesPars, mesMin, mesMax); mesPars.clear(); mesPars.push_back(sig_mes_mean2); mesPars.push_back(sig_mes_sigma2); LauAbsPdf* sigMESPdf2 = new LauGaussPdf("mES", mesPars, mesMin, mesMax); LauAbsPdf* sigMESPdf = new LauSumPdf(sigMESPdf1, sigMESPdf2, sig_mes_frac); fitModel->setSignalPdf(sigMESPdf); // Combinatoric background PDF is an ARGUS function LauParameter* comb_mes_m0 = new LauParameter("comb_mes_m0", 5.289); LauParameter* comb_mes_xi = new LauParameter("comb_mes_xi", 20.0, 0.0, 50.0, kTRUE); mesPars.clear(); mesPars.push_back(comb_mes_m0); mesPars.push_back(comb_mes_xi); LauAbsPdf* combMESPdf = new LauArgusPdf("mES", mesPars, mesMin, mesMax); fitModel->setBkgndPdf( "qqbar", combMESPdf ); // Signal DeltaE PDF parameter values Double_t sig_de_mean1_value = -0.005; Double_t sig_de_sigma1_value = 0.020; Double_t sig_de_sigma2_value = 0.050; Double_t sig_de_frac_value = 0.90; // DeltaE PDFs Double_t deMin = -0.2; Double_t deMax = 0.2; std::vector dePars; dePars.reserve(2); // Signal PDF is a double Gaussian with the means constrained to be the same LauParameter* sig_de_mean1 = new LauParameter("sig_de_mean1", sig_de_mean1_value, -0.1, 0.1, kTRUE); LauParameter* sig_de_sigma1 = new LauParameter("sig_de_sigma1", sig_de_sigma1_value, 0.0, 0.2, kTRUE); LauParameter* sig_de_mean2 = sig_de_mean1->createClone(); LauParameter* sig_de_sigma2 = new LauParameter("sig_de_sigma2", sig_de_sigma2_value, 0.0, 0.2, kTRUE); LauParameter* sig_de_frac = new LauParameter("sig_de_frac", sig_de_frac_value, 0.0, 1.0, kTRUE); dePars.clear(); dePars.push_back(sig_de_mean1); dePars.push_back(sig_de_sigma1); LauAbsPdf* sigDEPdf1 = new LauGaussPdf("DeltaE", dePars, deMin, deMax); dePars.clear(); dePars.push_back(sig_de_mean2); dePars.push_back(sig_de_sigma2); LauAbsPdf* sigDEPdf2 = new LauGaussPdf("DeltaE", dePars, deMin, deMax); LauAbsPdf* sigDEPdf = new LauSumPdf(sigDEPdf1, sigDEPdf2, sig_de_frac); fitModel->setSignalPdf(sigDEPdf); // Combinatoric background PDF is a linear function LauParameter* comb_de_slope = new LauParameter("comb_de_slope", -5.0, -10.0, 10.0, kTRUE); dePars.clear(); dePars.push_back(comb_de_slope); LauAbsPdf* combDEPdf = new LauLinearPdf("DeltaE", dePars, deMin, deMax); fitModel->setBkgndPdf( "qqbar", combDEPdf ); // Configure various fit options // Do not calculate asymmetric errors. fitModel->useAsymmFitErrors(kFALSE); // Randomise initial fit values for the signal isobar parameters fitModel->useRandomInitFitPars(kTRUE); // Switch on/off Poissonian smearing of total number of events fitModel->doPoissonSmearing(kTRUE); // Switch on/off Extended ML Fit option fitModel->doEMLFit(kTRUE); // Switch on/off two-stage fitting for CPV parameters fitModel->twoStageFit(kFALSE); // Generate toy from the fitted parameters //TString fitToyFileName("fitToyMC_NoDPMultiDim_"); //fitToyFileName += iFit; //fitToyFileName += ".root"; //fitModel->compareFitData(100, fitToyFileName); // Write out per-event likelihoods and sWeights //TString splotFileName("splot_NoDPMultiDim_"); //splotFileName += iFit; //splotFileName += ".root"; //fitModel->writeSPlotData(splotFileName, "splot", kFALSE); TString dataFile("gen-NoDPMultiDim.root"); TString treeName("genResults"); TString rootFileName(""); TString tableFileName(""); if (command == "fit") { rootFileName = "fitNoDPMultiDim_"; rootFileName += iFit; rootFileName += "_expt_"; rootFileName += firstExpt; rootFileName += "-"; rootFileName += firstExpt+nExpt-1; rootFileName += ".root"; tableFileName = "fitNoDPMultiDimResults_"; tableFileName += iFit; } else { rootFileName = "dummy.root"; tableFileName = "genNoDPMultiDimResults"; } // Execute the generation/fit fitModel->run(command, dataFile, treeName, rootFileName, tableFileName); return EXIT_SUCCESS; } diff --git a/examples/KMatrixDto3pi.cc b/examples/KMatrixDto3pi.cc index d79dc01..0c5b0cc 100644 --- a/examples/KMatrixDto3pi.cc +++ b/examples/KMatrixDto3pi.cc @@ -1,183 +1,184 @@ /* Copyright 2008 University of Warwick Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /* Laura++ package authors: John Back Paul Harrison Thomas Latham */ #include using std::cout; using std::cerr; using std::endl; #include #include #include "LauDaughters.hh" #include "LauVetoes.hh" #include "LauIsobarDynamics.hh" #include "LauSimpleFitModel.hh" #include "LauAbsCoeffSet.hh" #include "LauCartesianCPCoeffSet.hh" #include "LauEffModel.hh" #include "TString.h" void usage( std::ostream& out, const TString& progName ) { out<<"Usage:\n"; out< [nExpt = 1] [firstExpt = 0]"< [nExpt = 1] [firstExpt = 0] if ( argc < 2 ) { usage( std::cerr, argv[0] ); return EXIT_FAILURE; } TString command = argv[1]; command.ToLower(); Int_t iFit(0); Int_t nExpt(1); Int_t firstExpt(0); + Bool_t isToy(kTRUE); if ( command == "gen" ) { if ( argc > 2 ) { nExpt = atoi( argv[2] ); if ( argc > 3 ) { firstExpt = atoi( argv[3] ); } } } else if ( command == "fit" ) { if ( argc < 3 ) { usage( std::cerr, argv[0] ); return EXIT_FAILURE; } iFit = atoi( argv[2] ); if ( argc > 3 ) { nExpt = atoi( argv[3] ); if ( argc > 4 ) { firstExpt = atoi( argv[4] ); } } } else { usage( std::cerr, argv[0] ); return EXIT_FAILURE; } // Generate K-matrix amplitude distribution across the DP LauDaughters* daughters = new LauDaughters("D+", "pi+", "pi+", "pi-", kFALSE); LauVetoes* vetoes = new LauVetoes(); LauEffModel* effModel = new LauEffModel(daughters, vetoes); LauIsobarDynamics* sigModel = new LauIsobarDynamics(daughters, effModel); // Define the "S-wave" K-matrix propagator Int_t nChannels = 5; Int_t nPoles = 5; Int_t resPairInt = 1; Int_t KMatrixIndex = 1; // for S-wave sigModel->defineKMatrixPropagator("KMSWave", "FOCUSD3pi.dat", resPairInt, nChannels, nPoles, KMatrixIndex); // Now define the pole and "slowly-varying part" (SVP) amplitudes for the K-matrix. // Each part will have their own complex coefficients which can (should) be fitted. sigModel->addKMatrixProdPole("KMPole1", "KMSWave", 1); sigModel->addKMatrixProdPole("KMPole2", "KMSWave", 2); sigModel->addKMatrixProdPole("KMPole3", "KMSWave", 3); //sigModel->addKMatrixProdPole("KMPole4", "KMSWave", 4); //sigModel->addKMatrixProdPole("KMPole5", "KMSWave", 5); sigModel->addKMatrixProdSVP("KMSVP1", "KMSWave", 1); sigModel->addKMatrixProdSVP("KMSVP2", "KMSWave", 2); //sigModel->addKMatrixProdSVP("KMSVP3", "KMSWave", 3); //sigModel->addKMatrixProdSVP("KMSVP4", "KMSWave", 4); //sigModel->addKMatrixProdSVP("KMSVP5", "KMSWave", 5); sigModel->addResonance("rho0(770)", 1, LauAbsResonance::RelBW); sigModel->addResonance("f_2(1270)", 1, LauAbsResonance::RelBW); sigModel->setASqMaxValue(2.1); LauSimpleFitModel* fitModel = new LauSimpleFitModel(sigModel); std::vector coeffset; coeffset.push_back(new LauCartesianCPCoeffSet("KMPole1", 0.85, -0.55, 0.0, 0.0, kFALSE, kFALSE, kTRUE, kTRUE)); coeffset.push_back(new LauCartesianCPCoeffSet("KMPole2", -1.10, -0.30, 0.0, 0.0, kFALSE, kFALSE, kTRUE, kTRUE)); coeffset.push_back(new LauCartesianCPCoeffSet("KMPole3", -0.84, 0.35, 0.0, 0.0, kFALSE, kFALSE, kTRUE, kTRUE)); //coeffset.push_back(new LauCartesianCPCoeffSet("KMPole4", -0.004, .46, 0.0, 0.0, kFALSE, kFALSE, kTRUE, kTRUE)); //coeffset.push_back(new LauCartesianCPCoeffSet("KMPole5", 0.00, 0.00, 0.0, 0.0, kFALSE, kFALSE, kTRUE, kTRUE)); coeffset.push_back(new LauCartesianCPCoeffSet("KMSVP1", 0.230, 0.352, 0.0, 0.0, kFALSE, kFALSE, kTRUE, kTRUE)); coeffset.push_back(new LauCartesianCPCoeffSet("KMSVP2", 0.330, 0.42, 0.0, 0.0, kFALSE, kFALSE, kTRUE, kTRUE)); //coeffset.push_back(new LauCartesianCPCoeffSet("KMSVP3", -0.48, 1.25, 0.0, 0.0, kFALSE, kFALSE, kTRUE, kTRUE)); //coeffset.push_back(new LauCartesianCPCoeffSet("KMSVP4", 0.30, 1.32, 0.0, 0.0, kFALSE, kFALSE, kTRUE, kTRUE)); //coeffset.push_back(new LauCartesianCPCoeffSet("KMSVP5", 0.00, 0.00, 0.0, 0.0, kFALSE, kFALSE, kTRUE, kTRUE)); coeffset.push_back(new LauCartesianCPCoeffSet("rho0(770)", 1.0, 0.00, 0.0, 0.0, kTRUE, kTRUE, kTRUE, kTRUE)); coeffset.push_back(new LauCartesianCPCoeffSet("f_2(1270)", 0.45, 0.35, 0.0, 0.0, kFALSE, kFALSE, kTRUE, kTRUE)); for (std::vector::iterator iter=coeffset.begin(); iter!=coeffset.end(); ++iter) { fitModel->setAmpCoeffSet(*iter); } Double_t nSigEvents = 20000; Bool_t fixSigEvents = kTRUE; LauParameter * nSig = new LauParameter("signalEvents",nSigEvents,-2.0*nSigEvents,2.0*nSigEvents,fixSigEvents); fitModel->setNSigEvents(nSig); - fitModel->setNExpts(nExpt, firstExpt); + fitModel->setNExpts(nExpt, firstExpt, isToy); // Do not calculate asymmetric errors fitModel->useAsymmFitErrors(kFALSE); // Randomise initial fit values for the signal mode fitModel->useRandomInitFitPars(kTRUE); // Switch off Poissonian smearing of total number of events fitModel->doPoissonSmearing(kFALSE); // Switch on Extended ML Fit option - only really use if Poisson smearing is also enabled fitModel->doEMLFit(kFALSE); // Set the names of the files to read/write TString dataFile("gen-KMatrixDto3pi.root"); TString treeName("genResults"); TString rootFileName(""); TString tableFileName(""); if (command == "fit") { rootFileName = "fitKMatrixDto3pi_"; rootFileName += iFit; rootFileName += "_expt_"; rootFileName += firstExpt; rootFileName += "-"; rootFileName += (firstExpt+nExpt-1); rootFileName += ".root"; tableFileName = "fitKMatrixDto3piResults_"; tableFileName += iFit; } else { rootFileName = "dummy.root"; tableFileName = "genKMatrixDto3piResults"; } // Execute the generation/fit fitModel->run( command, dataFile, treeName, rootFileName, tableFileName ); } diff --git a/examples/KMatrixExample.cc b/examples/KMatrixExample.cc index 0cfc2cc..434edb7 100644 --- a/examples/KMatrixExample.cc +++ b/examples/KMatrixExample.cc @@ -1,219 +1,220 @@ /* Copyright 2008 University of Warwick Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /* Laura++ package authors: John Back Paul Harrison Thomas Latham */ #include using std::cout; using std::cerr; using std::endl; #include #include #include "LauDaughters.hh" #include "LauVetoes.hh" #include "LauEffModel.hh" #include "LauIsobarDynamics.hh" #include "LauSimpleFitModel.hh" #include "LauAbsCoeffSet.hh" #include "LauRealImagCoeffSet.hh" #include "TString.h" void usage( std::ostream& out, const TString& progName ) { out<<"Usage:\n"; out< [nExpt = 1] [firstExpt = 0]"< [nExpt = 1] [firstExpt = 0] if ( argc < 2 ) { usage( std::cerr, argv[0] ); return EXIT_FAILURE; } TString command = argv[1]; command.ToLower(); Int_t iFit(0); Int_t nExpt(1); Int_t firstExpt(0); + Bool_t isToy(kTRUE); if ( command == "gen" ) { if ( argc > 2 ) { nExpt = atoi( argv[2] ); if ( argc > 3 ) { firstExpt = atoi( argv[3] ); } } } else if ( command == "fit" ) { if ( argc < 3 ) { usage( std::cerr, argv[0] ); return EXIT_FAILURE; } iFit = atoi( argv[2] ); if ( argc > 3 ) { nExpt = atoi( argv[3] ); if ( argc > 4 ) { firstExpt = atoi( argv[4] ); } } } else { usage( std::cerr, argv[0] ); return EXIT_FAILURE; } // If you want to use square DP histograms for efficiency, // backgrounds or you just want the square DP co-ordinates // stored in the toy MC ntuple then set this to kTRUE Bool_t squareDP = kFALSE; // This defines the DP => decay is B0 -> pi+ pi- K_S0 // Particle 1 = pi+ // Particle 2 = pi- // Particle 3 = K_S0 // The DP is defined in terms of m13Sq and m23Sq LauDaughters* daughters = new LauDaughters("B0", "pi+", "pi-", "K_S0", squareDP); LauVetoes* vetoes = new LauVetoes(); LauEffModel* effModel = new LauEffModel(daughters, vetoes); LauIsobarDynamics* sigModel = new LauIsobarDynamics(daughters, effModel); // Add relativistic BWs for the rho and K* resonances sigModel->addResonance("rho0(770)", 3, LauAbsResonance::RelBW); sigModel->addResonance("K*+(892)", 2, LauAbsResonance::RelBW); sigModel->addResonance("K*+_2(1430)", 2, LauAbsResonance::RelBW); // Define the pi+ pi- "S-wave" K-matrix propagator // The defineKMatrixPropagator requires four arguments // name of propagator, parameter file, mass pair index (1,2,3) for "s" variable, number of channels, number of // mass poles and the row index defining the K-matrix state (e.g. index = 1 for the first row -> S-wave). Int_t resPairInt = 3; Int_t nChannels = 5; Int_t nPoles = 5; Int_t KMatrixIndex = 1; sigModel->defineKMatrixPropagator("KM_pipi", "LauKMatrixCoeff.dat", resPairInt, nChannels, nPoles, KMatrixIndex); // Now define the pole and "slowly-varying part" (SVP) amplitudes for this K-matrix. // Each part will have their own complex coefficients which can (should) be fitted. // The addKMatrixProd functions need: name of pole/SVP, name of propagator and the index // number of the amplitude (from 1 to nPoles or nChannels) sigModel->addKMatrixProdPole("KM_pipi_Pole1", "KM_pipi", 1); sigModel->addKMatrixProdPole("KM_pipi_Pole2", "KM_pipi", 2); sigModel->addKMatrixProdPole("KM_pipi_Pole3", "KM_pipi", 3); sigModel->addKMatrixProdPole("KM_pipi_Pole4", "KM_pipi", 4); sigModel->addKMatrixProdPole("KM_pipi_Pole5", "KM_pipi", 5); sigModel->addKMatrixProdSVP("KM_pipi_SVP1", "KM_pipi", 1); sigModel->addKMatrixProdSVP("KM_pipi_SVP2", "KM_pipi", 2); sigModel->addKMatrixProdSVP("KM_pipi_SVP3", "KM_pipi", 3); sigModel->setASqMaxValue(3.1); LauSimpleFitModel* fitModel = new LauSimpleFitModel(sigModel); std::vector coeffset; // Define the coefficients for the P-wave rho and K* resonances coeffset.push_back(new LauRealImagCoeffSet("rho0(770)", 1.00, 0.00, kTRUE, kTRUE)); coeffset.push_back(new LauRealImagCoeffSet("K*+(892)", 0.97, -1.10, kFALSE, kFALSE)); coeffset.push_back(new LauRealImagCoeffSet("K*+_2(1430)", 0.38, -0.54, kFALSE, kFALSE)); // Define the coefficients for the K-matrix amplitudes defined above ("beta" and "f" production coeffs) coeffset.push_back(new LauRealImagCoeffSet("KM_pipi_Pole1", -0.18, -0.91, kFALSE, kFALSE)); coeffset.push_back(new LauRealImagCoeffSet("KM_pipi_Pole2", -1.02, -0.38, kFALSE, kFALSE)); coeffset.push_back(new LauRealImagCoeffSet("KM_pipi_Pole3", -0.37, 0.50, kFALSE, kFALSE)); coeffset.push_back(new LauRealImagCoeffSet("KM_pipi_Pole4", -0.01, 0.92, kFALSE, kFALSE)); coeffset.push_back(new LauRealImagCoeffSet("KM_pipi_Pole5", 0.01, -0.05, kFALSE, kFALSE)); coeffset.push_back(new LauRealImagCoeffSet("KM_pipi_SVP1", 0.22, 0.76, kFALSE, kFALSE)); coeffset.push_back(new LauRealImagCoeffSet("KM_pipi_SVP2", 0.89, -0.31, kFALSE, kFALSE)); coeffset.push_back(new LauRealImagCoeffSet("KM_pipi_SVP3", -0.97, 0.93, kFALSE, kFALSE)); for (std::vector::iterator iter=coeffset.begin(); iter!=coeffset.end(); ++iter) { fitModel->setAmpCoeffSet(*iter); } Double_t nSigEvents = 5000; Bool_t fixSigEvents = kTRUE; LauParameter* nSig = new LauParameter("signalEvents",nSigEvents,-1.0*nSigEvents,2.0*nSigEvents,fixSigEvents); fitModel->setNSigEvents(nSig); - fitModel->setNExpts(nExpt, firstExpt); + fitModel->setNExpts(nExpt, firstExpt, isToy); // Configure various fit options // Switch on/off calculation of asymmetric errors. fitModel->useAsymmFitErrors(kFALSE); // Randomise initial fit values for the signal mode fitModel->useRandomInitFitPars(kTRUE); const Bool_t haveBkgnds = ( fitModel->nBkgndClasses() > 0 ); // Switch on/off Poissonian smearing of total number of events fitModel->doPoissonSmearing(haveBkgnds); // Switch on/off Extended ML Fit option fitModel->doEMLFit(haveBkgnds); // Generate toy from the fitted parameters //TString fitToyFileName("fitToyMC_KMatrixExample_"); //fitToyFileName += iFit; //fitToyFileName += ".root"; //fitModel->compareFitData(100, fitToyFileName); // Write out per-event likelihoods and sWeights //TString splotFileName("splot_KMatrixExample_"); //splotFileName += iFit; //splotFileName += ".root"; //fitModel->writeSPlotData(splotFileName, "splot", kFALSE); // Set the names of the files to read/write TString dataFile("gen-KMatrixExample.root"); TString treeName("genResults"); TString rootFileName(""); TString tableFileName(""); if (command == "fit") { rootFileName = "fitKMatrixExample_"; rootFileName += iFit; rootFileName += "_expt_"; rootFileName += firstExpt; rootFileName += "-"; rootFileName += (firstExpt+nExpt-1); rootFileName += ".root"; tableFileName = "fitKMatrixExampleResults_"; tableFileName += iFit; } else { rootFileName = "dummy.root"; tableFileName = "genKMatrixExampleResults"; } // Execute the generation/fit fitModel->run( command, dataFile, treeName, rootFileName, tableFileName ); return EXIT_SUCCESS; } diff --git a/examples/SimFitTask.cc b/examples/SimFitTask.cc index 23fa4e3..5405ab1 100644 --- a/examples/SimFitTask.cc +++ b/examples/SimFitTask.cc @@ -1,255 +1,256 @@ /* Copyright 2013 University of Warwick Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /* Laura++ package authors: John Back Paul Harrison Thomas Latham */ #include #include #include #include "TFile.h" #include "TH2.h" #include "TString.h" #include "TTree.h" #include "LauSimpleFitModel.hh" #include "LauBkgndDPModel.hh" #include "LauDaughters.hh" #include "LauEffModel.hh" #include "LauIsobarDynamics.hh" #include "LauMagPhaseCoeffSet.hh" #include "LauRandom.hh" #include "LauVetoes.hh" void usage( std::ostream& out, const TString& progName ) { out<<"Usage:\n"; out< [nExpt = 1] [firstExpt = 0]\n"; out<<"or\n"; out< [hostname] [nExpt = 1] [firstExpt = 0]"< [nExpt = 1] [firstExpt = 0] // or // ./SimFitTask fit [nExpt = 1] [firstExpt = 0] if ( argc < 3 ) { usage( std::cerr, argv[0] ); return EXIT_FAILURE; } TString command = argv[1]; command.ToLower(); TString category = argv[2]; if ( category != "DD" && category != "LL" ) { usage( std::cerr, argv[0] ); return EXIT_FAILURE; } Int_t iFit(0); UInt_t port(5000); TString hostname("localhost"); Int_t nExpt(1); Int_t firstExpt(0); + Bool_t isToy(kTRUE); if ( command == "gen" ) { if ( argc > 3 ) { nExpt = atoi( argv[3] ); if ( argc > 4 ) { firstExpt = atoi( argv[4] ); } } } else if ( command == "fit" ) { if ( argc < 5 ) { usage( std::cerr, argv[0] ); return EXIT_FAILURE; } iFit = atoi( argv[3] ); port = atoi( argv[4] ); if ( argc > 5 ) { hostname = argv[5]; if ( argc > 6 ) { nExpt = atoi( argv[6] ); if ( argc > 7 ) { firstExpt = atoi( argv[7] ); } } } } else { usage( std::cerr, argv[0] ); return EXIT_FAILURE; } // If you want to use square DP histograms for efficiency, // backgrounds or you just want the square DP co-ordinates // stored in the toy MC ntuple then set this to kTRUE Bool_t squareDP = kFALSE; // This defines the DP => decay is B0 -> pi0 pi0 K_S0 // Particle 1 = pi0 // Particle 2 = pi0 // Particle 3 = KS_0 // The DP is defined in terms of m13Sq and m23Sq LauDaughters* daughters = new LauDaughters("B0", "pi0", "pi0", "K_S0", squareDP); // Optionally apply some vetoes to the DP LauVetoes* vetoes = new LauVetoes(); // Define the efficiency model (defaults to unity everywhere) // Can optionally provide a histogram to model variation over DP // (example syntax given in commented-out section) LauEffModel* effModel = new LauEffModel(daughters, vetoes); //TFile *effHistFile = TFile::Open("histoFiles/efficiency.root", "read"); //TH2* effHist = dynamic_cast(effHistFile->Get("effHist")); //Bool_t useInterpolation = kTRUE; //Bool_t fluctuateBins = kFALSE; //Bool_t useUpperHalf = kTRUE; //effModel->setEffHisto(effHist, useInterpolation, fluctuateBins, 0.0, 0.0, useUpperHalf, squareDP); // Create the isobar model LauIsobarDynamics* sigModel = new LauIsobarDynamics(daughters, effModel); LauAbsResonance* res(0); res = sigModel->addResonance("f_0(980)", 3, LauAbsResonance::Flatte); // resPairAmpInt = 3 => resonance mass is m12. res = sigModel->addResonance("f_2(1270)", 3, LauAbsResonance::RelBW); res = sigModel->addResonance("K*0(892)", 1, LauAbsResonance::RelBW); res->fixMass(kFALSE); res = sigModel->addResonance("K*0_0(1430)", 1, LauAbsResonance::LASS); // Set the maximum signal DP ASq value // If you do not provide a value, one will be determined automatically, // which should be close to the true maximum but is not guaranteed to // be optimal. // Any value, whether manually provided or automatically determined, // will be automatically adjusted to avoid bias or extreme inefficiency // but it is best to set this by hand once you've found the right value // through some trial and error. sigModel->setASqMaxValue(1.25); TString integralsFileName("integ-"); integralsFileName += category; integralsFileName += ".dat"; sigModel->setIntFileName( integralsFileName ); // Create the fit model LauSimpleFitModel* fitModel = new LauSimpleFitModel(sigModel); // Create the complex coefficients for the isobar model // Here we're using the magnitude and phase form: // c_j = a_j exp(i*delta_j) std::vector coeffset; coeffset.push_back( new LauMagPhaseCoeffSet("f_0(980)", 1.00, 0.00, kTRUE, kTRUE) ); coeffset.push_back( new LauMagPhaseCoeffSet("f_2(1270)", 0.53, 1.39, kFALSE, kFALSE) ); coeffset.push_back( new LauMagPhaseCoeffSet("K*0(892)", 0.87, 1.99, kFALSE, kFALSE) ); coeffset.push_back( new LauMagPhaseCoeffSet("K*0_0(1430)", 1.17, -1.59, kFALSE, kFALSE) ); for (std::vector::iterator iter=coeffset.begin(); iter!=coeffset.end(); ++iter) { fitModel->setAmpCoeffSet(*iter); } // Set the signal yield and define whether it is fixed or floated TString sigEventsName = "signalEvents" + category; Double_t nSig(500.0); if ( category == "DD" ) { nSig = 750.0; } LauParameter * nSigEvents = new LauParameter(sigEventsName,nSig,-2.0*nSig,2.0*nSig,kFALSE); fitModel->setNSigEvents(nSigEvents); // Set the number of experiments to generate or fit and which // experiment to start with - fitModel->setNExpts( nExpt, firstExpt ); + fitModel->setNExpts( nExpt, firstExpt, isToy ); // Optionally load in continuum background DP model histogram // (example syntax given in commented-out section) std::vector bkgndNames(1); bkgndNames[0] = "comb" + category; fitModel->setBkgndClassNames( bkgndNames ); Double_t nBkgnd = 1200.0; if ( category == "DD" ) { nBkgnd = 2500.0; } LauParameter* nBkgndEvents = new LauParameter(bkgndNames[0],nBkgnd,-2.0*nBkgnd,2.0*nBkgnd,kFALSE); fitModel->setNBkgndEvents( nBkgndEvents ); //TString bkgndFileName("histoFiles/bkgndDPs.root"); //TFile* bkgndFile = TFile::Open(bkgndFileName.Data(), "read"); //TH2* bkgndDP = dynamic_cast(bkgndFile->Get("AllmTheta")); // m', theta' LauBkgndDPModel* bkgndModel = new LauBkgndDPModel(daughters, vetoes); //bkgndModel->setBkgndHisto(bkgndDP, useInterpolation, fluctuateBins, useUpperHalf, squareDP); fitModel->setBkgndDPModel( bkgndNames[0], bkgndModel ); // Randomise initial fit values for the signal mode fitModel->useRandomInitFitPars(kTRUE); const Bool_t haveBkgnds = ( fitModel->nBkgndClasses() > 0 ); // Switch on/off Poissonian smearing of total number of events fitModel->doPoissonSmearing(haveBkgnds); // Switch on/off Extended ML Fit option fitModel->doEMLFit(haveBkgnds); // Activate two-stage fit fitModel->twoStageFit(kTRUE); // Generate toy from the fitted parameters //TString fitToyFileName("fitToyMC_"); //fitToyFileName += category; //fitToyFileName += "-Task_"; //fitToyFileName += iFit; //fitToyFileName += ".root"; //fitModel->compareFitData(100, fitToyFileName); // Write out per-event likelihoods and sWeights //TString splotFileName("splot_"); //splotFileName += category; //splotFileName += "-Task_"; //splotFileName += iFit; //splotFileName += ".root"; //fitModel->writeSPlotData(splotFileName, "splot", kFALSE); // Set the names of the files to read/write TString dataFile("gen-"); dataFile += category; dataFile += "-Task.root"; TString treeName("genResults"); TString rootFileName(""); TString tableFileName(""); if (command == "fit") { rootFileName = "fit"; rootFileName += category; rootFileName += "-Task_"; rootFileName += iFit; rootFileName += "_expt_"; rootFileName += firstExpt; rootFileName += "-"; rootFileName += (firstExpt+nExpt-1); rootFileName += ".root"; tableFileName = "fit"; tableFileName += category; tableFileName += "TaskResults_"; tableFileName += iFit; } else { rootFileName = "dummy.root"; tableFileName = "gen"; tableFileName += category; tableFileName += "TaskResults_"; } // Execute the generation/fit if ( command == "fit" ) { fitModel->runTask( dataFile, treeName, rootFileName, tableFileName, hostname, port ); } else { fitModel->run( command, dataFile, treeName, rootFileName, tableFileName ); } return EXIT_SUCCESS; } diff --git a/inc/LauAbsRValue.hh b/inc/LauAbsRValue.hh index f19d3f6..2ae4d53 100644 --- a/inc/LauAbsRValue.hh +++ b/inc/LauAbsRValue.hh @@ -1,141 +1,138 @@ /* Copyright 2014 University of Warwick Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /* Laura++ package authors: John Back Paul Harrison Thomas Latham */ /*! \file LauAbsRValue.hh \brief File containing declaration of LauAbsRValue class. */ /*! \class LauAbsRValue \brief Pure abstract base class for defining a parameter containing an R value Pure abstract base class for defining a parameter containing an R value, either a LauParameter or a LauFormulaPar */ #ifndef LAU_ABSRVALUE #define LAU_ABSRVALUE #include class LauParameter; class LauAbsRValue { public: //! Constructor LauAbsRValue() {} //! Destructor virtual ~LauAbsRValue() {} //! Copy constructor LauAbsRValue(const LauAbsRValue& /*rhs*/) {} //! Copy assignment operator LauAbsRValue& operator=(const LauAbsRValue& /*rhs*/) {return *this;} //! Return the name of the parameter /*! \return the name of the parameter */ virtual const TString& name() const =0; //! Set the parameter name /*! \param [in] newName the name of the parameter */ virtual void name(const TString& newName) =0; //! Return the value of the parameter /*! \return the value of the parameter */ virtual Double_t value() const =0; //! The unblinded value of the parameter /*! \return the unblinded value of the parameter */ virtual Double_t unblindValue() const =0; //! The value generated for the parameter /*! \return the value generated for the parameter */ virtual Double_t genValue() const =0; //! The initial value of the parameter /*! \return the initial value of the parameter given to the fitter */ virtual Double_t initValue() const =0; //! Check whether a Gaussian constraints is applied /*! \return the boolean flag true/false whether a Gaussian constraint is applied */ virtual Bool_t gaussConstraint() const =0; - //! The mean of the Gaussian constraint + //! The penalty term from the Gaussian constraint /*! - \return the mean value of the Gaussian constraint + \return the penalty term from the Gaussian constraint */ - virtual Double_t constraintMean() const =0; + virtual Double_t constraintPenalty() const =0; - //! The width of the Gaussian constraint - /*! - \return the width of the Gaussian constraint - */ - virtual Double_t constraintWidth() const =0; + //! Generate per-experiment constraint mean + virtual void generateConstraintMean() =0; //! Return the list of LauParameters on which the LauAbsRValue depends /*! \return the list of LauParameters */ virtual std::vector getPars() =0; //! Is the parameter also an L value or not /*! \return whether the parameter is also an L value */ virtual Bool_t isLValue() const =0; //! Check is the parameter is fixed or floated /*! \return the boolean flag whether the parameter is fixed */ virtual Bool_t fixed() const =0; //! The blinding state /*! \return the blinding state: kTRUE means that it is blinded, kFALSE that it is not blinded */ virtual Bool_t blind() const =0; private: ClassDef(LauAbsRValue,1) // Abstract base class for R parameters }; #endif diff --git a/inc/LauFitObject.hh b/inc/LauFitObject.hh index 8ea3fa7..c67a1ce 100644 --- a/inc/LauFitObject.hh +++ b/inc/LauFitObject.hh @@ -1,324 +1,374 @@ /* Copyright 2013 University of Warwick Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /* Laura++ package authors: John Back Paul Harrison Thomas Latham */ /*! \file LauFitObject.hh \brief File containing declaration of LauFitObject class. */ #ifndef LAU_FIT_OBJECT #define LAU_FIT_OBJECT #include #include "TMatrixD.h" #include "TObject.h" #include "TString.h" #include "TVectorD.h" #include "LauAbsFitter.hh" +#include "LauFormulaPar.hh" /*! \class LauFitObject \brief The abstract interface for the objects that control the calculation of the likelihood. */ class LauFitObject : public TObject { public: //! Destructor virtual ~LauFitObject() = default; //! Turn on or off the computation of asymmetric errors (e.g. MINOS routine in Minuit) /*! \param [in] useAsymmErrors boolean specifying whether or not the computation of asymmetric errors is enabled */ void useAsymmFitErrors(Bool_t useAsymmErrors) {useAsymmFitErrors_ = useAsymmErrors;} //! Report whether or not calculation of asymmetric errors is enabled Bool_t useAsymmFitErrors() const {return useAsymmFitErrors_;} //! Turn on or off the two stage fit /*! The two-stage fit allows certain parameters to be fixed in one stage and floated in another stage of the fit. Can be used, for example, in a CP fit where the CP-parameters are fixed to zero in the first stage (while the CP-average parameters are determined), then floated in the second. \param [in] doTwoStageFit boolean specifying whether or not the two-stage fit should be enabled */ void twoStageFit(Bool_t doTwoStageFit) {twoStageFit_ = doTwoStageFit;} //! Report whether the two-stage fit is enabled Bool_t twoStageFit() const {return twoStageFit_;} //! Mark that the fit is calculating asymmetric errors /*! This is called by the fitter interface to mark when entering and exiting the asymmetric error calculation. \param [in] inAsymErrCalc boolean marking that the fit is calculating the asymmetric errors */ virtual void withinAsymErrorCalc(const Bool_t inAsymErrCalc) {withinAsymErrorCalc_ = inAsymErrCalc;} //! Query whether the fit is calculating the asymmetric errors /*! \return kTRUE if the fit is calculating the asymmetric errors, kFALSE otherwise */ Bool_t withinAsymErrorCalc() const {return withinAsymErrorCalc_;} - //! Set the number of experiments and the first experiment + //! Set the number of experiments, the first experiment, and whether this is toy /*! + The default settings are nExperiments = 1, firstExperiment = 0, toyExpts = kFALSE, + i.e. the settings for fitting a single data sample. + As such, this function only needs to be called if generating/fitting toy samples. + \param [in] nExperiments the number of experiments \param [in] firstExperiment the number of the first experiment + \param [in] toyExpts whether this is toy - determines whether to generate per-experiment means for each Gaussian constraint, as per arXiv:1210.7141 */ - void setNExpts(UInt_t nExperiments, UInt_t firstExperiment = 0) { - nExpt_ = nExperiments; - firstExpt_ = firstExperiment; - } + void setNExpts(UInt_t nExperiments, UInt_t firstExperiment, Bool_t toyExpts); //! Obtain the total number of events in the current experiment UInt_t eventsPerExpt() const {return evtsPerExpt_;} //! Obtain the number of experiments UInt_t nExpt() const {return nExpt_;} //! Obtain the number of the first experiment UInt_t firstExpt() const {return firstExpt_;} //! Obtain the number of the current experiment UInt_t iExpt() const {return iExpt_;} + //! Obtain whether this is toy + Bool_t toyExpts() const {return toyExpts_;} + //! This function sets the parameter values from Minuit /*! This function has to be public since it is called from the global FCN. It should not be called otherwise! \param [in] par an array storing the various parameter values \param [in] npar the number of free parameters */ virtual void setParsFromMinuit(Double_t* par, Int_t npar) = 0; //! Calculate the new value of the negative log likelihood /*! This function has to be public since it is called from the global FCN. It should not be called otherwise! */ virtual Double_t getTotNegLogLikelihood() = 0; //! Store constraint information for fit parameters /*! + \deprecated Renamed to addFormulaConstraint, please switch to use this. Will be dropped in next major release. + \param [in] formula the formula to be used in the LauFormulaPar \param [in] pars a vector of LauParameter names to be used in the Formula, in the order specified by the formula - \param [in] mean the value of the mean of the Gaussian constraint - \param [in] width the value of the width of the Gaussian constraint - */ + \param [in] mean the value of the mean of the Gaussian constraint + \param [in] width the value of the width of the Gaussian constraint + */ virtual void addConstraint(const TString& formula, const std::vector& pars, const Double_t mean, const Double_t width); + //! Store constraint information for fit parameters + /*! + \param [in] formula the formula to be used in the LauFormulaPar + \param [in] pars a vector of LauParameter names to be used in the Formula, in the order specified by the formula + \param [in] mean the value of the mean of the Gaussian constraint + \param [in] width the value of the width of the Gaussian constraint + */ + virtual void addFormulaConstraint(const TString& formula, const std::vector& pars, const Double_t mean, const Double_t width); + //! Store n-dimensional constraint information for fit parameters /*! \param [in] pars a vector of LauParameter names to be used in the constraint - \param [in] means the values of the means of the Gaussian constraint - \param [in] covMat the covariance matrix of the parameters of the Gaussian constraint - */ - virtual void addNDConstraint(const std::vector& pars, const TVectorD& means, const TMatrixD& covMat); + \param [in] means the values of the means of the Gaussian constraint + \param [in] covMat the covariance matrix of the parameters of the Gaussian constraint + */ + virtual void addMultiDimConstraint(const std::vector& pars, const TVectorD& means, const TMatrixD& covMat); //! Check if parameters names for constraints have already been used elsewhere /*! \param [in] names a vector of parameter names \return kTRUE if no repetitions found, kFALSE if one or more repetitions found */ virtual Bool_t checkRepetition(const std::vector& names); protected: //! Constructor LauFitObject(); // Setup a struct to store information on constrained fit parameters /*! - \struct StoreConstraints - \brief Struct to store constraint information until the fit is run - */ - struct StoreConstraints { + \struct FormulaConstraint + \brief Struct to store formula-based constraint information + */ + struct FormulaConstraint { //! The formula to be used in the LauFormulaPar TString formula_; //! The list of LauParameter names to be used in the LauFormulaPar std::vector conPars_; //! The mean value of the Gaussian constraint to be applied Double_t mean_; //! The width of the Gaussian constraint to be applied Double_t width_; + //! The LauFormulaPar pointer + std::unique_ptr formulaPar_; }; - - // Setup a struct to store information on n-dimensional constrained fit parameters + + // Setup a class to store information on n-dimensional constrained fit parameters /*! - \struct StoreNDConstraints - \brief Struct to store n-dimensional constraint information until the fit is run - */ - struct StoreNDConstraints { - //! The list of LauParameter names to be used in the constraint - std::vector conPars_; - //! The mean value of the Gaussian constraints to be applied - TVectorD means_; - //! The inverse covariance matrix of the parameters of the Gaussian constraint to be applied - TMatrixD invCovMat_; - //! The LauParameters used in the constraints - std::vector conLauPars_; - //! The values of the LauParameters - TVectorD values_; + \class MultiDimConstraint + \brief Class to store n-dimensional constraint information + */ + class MultiDimConstraint { + public: + //! Default constructor + MultiDimConstraint() = default; + + //! Constructor + MultiDimConstraint( const std::vector& parNames, const TVectorD& means, const TMatrixD& covMat ); + + //! Get the penalty term + Double_t constraintPenalty() const; + + //! Generate per-experiment constraint means + void generateConstraintMeans(); + + //! The list of LauParameter names to be used in the constraint + std::vector conPars_; + //! The true mean values of the constraint + TVectorD trueMeans_; + //! The per-experiment mean values of the constraint + TVectorD means_; + //! The inverse covariance matrix of the parameters + TMatrixD invCovMat_; + //! The Cholesky Decomposition of the covariance matrix of the parameters + TMatrixD sqrtCovMat_; + //! The LauParameters used in the constraints + std::vector conLauPars_; }; + //! Generate per-experiment mean for each Gaussian constraint + /*! + Generates a new mean for all Gaussian constraints. + The constraints on a single fit parameter and the + formula-based constraints are provided as the argument, + while the multi-dimensional constraints are already a + member variable. + + \param [in,out] conVars the fit parameter and formula-based constraints + */ + void generateConstraintMeans( std::vector& conVars ); + //! Const access to the constraints store - const std::vector& constraintsStore() const {return storeCon_;} + const std::vector& formulaConstraints() const {return formulaConstraints_;} //! Access to the constraints store - std::vector& constraintsStore() {return storeCon_;} + std::vector& formulaConstraints() {return formulaConstraints_;} //! Const access to the ND constraints store - const std::vector& NDConstraintsStore() const {return storeNDCon_;} + const std::vector& multiDimConstraints() const {return multiDimConstraints_;} //! Access to the ND constraints store - std::vector& NDConstraintsStore() {return storeNDCon_;} + std::vector& multiDimConstraints() {return multiDimConstraints_;} //! Reset the good/bad fit counters void resetFitCounters(); //! Set the ID of the current experiment /*! \param [in] curExpt the experiment number */ void setCurrentExperiment( const UInt_t curExpt ) { iExpt_ = curExpt; } //! Indicate the start of a new fit /*! \param [in] nPars the total number of fit parameters \param [in] nFreePars the number of free fit parameters */ void startNewFit( const UInt_t nPars, const UInt_t nFreePars ); //! Set the number of events in the current experiment void eventsPerExpt(UInt_t nEvents) {evtsPerExpt_ = nEvents;} //! Access the worst log likelihood found so far Double_t worstLogLike() const {return worstLogLike_;} //! Set a new value for the worst log likelihood /*! \param [in] newWorstLogLike the new value of the worst log likelihood */ void worstLogLike( const Double_t newWorstLogLike ) {worstLogLike_ = newWorstLogLike;} //! Store fit status information /*! \param [in] status the status information of the fit \param [in] covMatrix the fit covariance matrix */ void storeFitStatus( const LauAbsFitter::FitStatus& status, const TMatrixD& covMatrix ); //! Access the total number of fit parameters UInt_t nTotParams() const {return nParams_;} //! Access the total number of fit parameters UInt_t nFreeParams() const {return nFreeParams_;} //! Access the fit status information const LauAbsFitter::FitStatus& fitStatus() const {return fitStatus_;} //! Access the current NLL value Double_t nll() const {return fitStatus_.NLL;} //! Access the current EDM value Double_t edm() const {return fitStatus_.EDM;} //! Access the fit status code Int_t statusCode() const {return fitStatus_.status;} //! Access the fit covariance matrix const TMatrixD& covarianceMatrix() const {return covMatrix_;} //! Access the number of successful fits UInt_t numberOKFits() const {return numberOKFits_;} //! Access the number of failed fits UInt_t numberBadFits() const {return numberBadFits_;} private: //! Copy constructor (not implemented) LauFitObject(const LauFitObject& rhs); //! Copy assignment operator (not implemented) LauFitObject& operator=(const LauFitObject& rhs); //! Store the constraints for fit parameters until initialisation is complete - std::vector storeCon_; + std::vector formulaConstraints_; //! Store the ND constraints for fit parameters until initialisation is complete - std::vector storeNDCon_; + std::vector multiDimConstraints_; //! Option to perform a two stage fit Bool_t twoStageFit_; //! Option to use asymmetric errors Bool_t useAsymmFitErrors_; //! The number of fit parameters UInt_t nParams_; //! The number of free fit parameters UInt_t nFreeParams_; //! Flag to indicate if the asymmetric error calculation (e.g. MINOS) is currently running Bool_t withinAsymErrorCalc_; + //! Flag to indicate whether this is toy + /*! Determines whether to generate per-experiment means for each Gaussian constraint, as per arXiv:1210.7141 */ + Bool_t toyExpts_; + //! The number of the first experiment to consider UInt_t firstExpt_; //! The number of experiments to consider UInt_t nExpt_; //! The current experiment number UInt_t iExpt_; //! The number of events in the current experiment UInt_t evtsPerExpt_; //! The status of the current fit LauAbsFitter::FitStatus fitStatus_; //! The worst log likelihood value found so far Double_t worstLogLike_; //! The fit covariance matrix TMatrixD covMatrix_; //! The number of successful fits UInt_t numberOKFits_; //! The number of fit failures UInt_t numberBadFits_; ClassDef(LauFitObject,0) }; #endif diff --git a/inc/LauFormulaPar.hh b/inc/LauFormulaPar.hh index eee8125..efcba71 100644 --- a/inc/LauFormulaPar.hh +++ b/inc/LauFormulaPar.hh @@ -1,183 +1,182 @@ /* Copyright 2014 University of Warwick Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /* Laura++ package authors: John Back Paul Harrison Thomas Latham */ /*! \file LauFormulaPar.hh \brief File containing declaration of LauFormulaPar class. */ /*! \class LauFormulaPar \brief Class for defining combinations of fit parameter objects. Allows for combinations of LauParameters to be passed to the fit models. Equations of the form [0]*2 + 3*[1] are accepted, with a vector of LauParameters to define inputs [0] and [1]. The parameter for [0] must be stored first in the vector, and so on. */ #ifndef LAU_FORMULAPAR #define LAU_FORMULAPAR #include #include #include "TString.h" #include "TFormula.h" #include "LauAbsRValue.hh" #include "LauParameter.hh" class LauFormulaPar : public LauAbsRValue { public: //! Constructor /*! \param [in] forName the name of the formula \param [in] formula the desired expression, using TFormula syntax \param [in] params a vector of LauParameters used in the formula */ LauFormulaPar(const TString& forName, const TString& formula, const std::vector& params); // Destructor virtual ~LauFormulaPar(); //! Copy constructor LauFormulaPar(const LauFormulaPar& rhs); //! Copy assignment operator LauFormulaPar& operator=(const LauFormulaPar& rhs); //! Return the value of the LauFormalaPar /*! \return the value of the formula */ Double_t value() const; //! The unblinded value of the parameter /*! \return the unblinded value of the parameter */ Double_t unblindValue() const; //! The value generated for the parameter /*! \return the value generated for the parameter */ Double_t genValue() const; //! The initial value of the parameter /*! \return the initial value of the parameter given to the fitter */ Double_t initValue() const; //! The parameter name /*! \return the name of the parameter */ inline const TString& name() const {return name_;} //! Set the parameter name /*! \param [in] newName the name of the parameter */ inline void name(const TString& newName) {name_ = newName;}; //! Get the LauParameters used in LauFormulaPar /*! \return the list of LauParameters */ std::vector getPars() {return paramVec_;} //! Boolean to say it is not an L value /*! \return kFALSE, LauFormulaPars are not L values */ inline Bool_t isLValue() const {return kFALSE;} //! Boolean to say if the LauFormulaPar is fixed /*! \return kFALSE unless all LauParameters in the formula are fixed */ Bool_t fixed() const; //! The blinding state /*! \return kTRUE if any of the LauParameters in the formula are blinded, kFALSE otherwise */ Bool_t blind() const; //! Check whether a Gaussian constraints is applied /*! \return the boolean flag true/false whether a Gaussian constraint is applied */ inline Bool_t gaussConstraint() const {return gaussConstraint_;} - //! The mean of the Gaussian constraint + //! The penalty term from the Gaussian constraint /*! - \return the mean value of the Gaussian constraint + \return the penalty term from the Gaussian constraint */ - inline Double_t constraintMean() const {return constraintMean_;} - - //! The width of the Gaussian constraint - /*! - \return the width of the Gaussian constraint - */ - inline Double_t constraintWidth() const {return constraintWidth_;} + Double_t constraintPenalty() const; //! Add a Gaussian constraint (or modify an existing one) /*! \param [in] newGaussMean the new value of the Gaussian constraint mean \param [in] newGaussWidth the new value of the Gaussian constraint width */ void addGaussianConstraint(Double_t newGaussMean, Double_t newGaussWidth); //! Remove the Gaussian constraint void removeGaussianConstraint(); + //! Generate per-experiment constraint mean + void generateConstraintMean(); + protected: private: //! The parameter name TString name_; //! The formula mutable TFormula formula_; //! Vector of LauParameters in the formula std::vector paramVec_; //! Array to hold parameter values to pass to formula Double_t* paramArray_; //! Choice to use Gaussian constraint Bool_t gaussConstraint_; + //! True mean of the Gaussian constraint + Double_t constraintTrueMean_; //! Mean value of the Gaussian constraint Double_t constraintMean_; //! Width of the Gaussian constraint Double_t constraintWidth_; ClassDef(LauFormulaPar, 0) }; #endif diff --git a/inc/LauParameter.hh b/inc/LauParameter.hh index 9254ee2..72380bc 100644 --- a/inc/LauParameter.hh +++ b/inc/LauParameter.hh @@ -1,560 +1,559 @@ /* Copyright 2006 University of Warwick Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /* Laura++ package authors: John Back Paul Harrison Thomas Latham */ /*! \file LauParameter.hh \brief File containing declaration of LauParameter class. */ /*! \class LauParameter \brief Class for defining the fit parameter objects. Holds all relevant information for the parameters for both generation and fitting step: current, initial and generated value, maximum and minimum range, error, asymmetric error, fix and float and etc. */ #ifndef LAU_PARAMETER #define LAU_PARAMETER #include #include #include #include "TObject.h" #include "TString.h" #include "LauAbsRValue.hh" #include "LauBlind.hh" class LauParameter : public TObject, public LauAbsRValue { public: //! Default constructor LauParameter(); //! Constructor for named parameter /*! \param [in] parName the parameter name */ explicit LauParameter(const TString& parName); //! Constructor for parameter value /*! \param [in] parValue the parameter value */ explicit LauParameter(Double_t parValue); //! Constructor double limit parameter /*! \param [in] parValue the parameter value \param [in] min the minimum value of the parameter \param [in] max the maximum value of the parameter */ LauParameter(Double_t parValue, Double_t min, Double_t max); //! Constructor double limit fixed parameter /*! \param [in] parValue the parameter value \param [in] min the minimum value of the parameter \param [in] max the maximum value of the parameter \param [in] parFixed boolean flag to fix or float parameter */ LauParameter(Double_t parValue, Double_t min, Double_t max, Bool_t parFixed); //! Constructor for double error and limit parameter /*! \param [in] parValue the parameter value \param [in] parError the parameter error \param [in] min the minimum value of the parameter \param [in] max the maximum value of the parameter */ LauParameter(Double_t parValue, Double_t parError, Double_t min, Double_t max); //! Constructor for parameter value and name /*! \param [in] parName the parameter name \param [in] parValue the parameter value */ LauParameter(const TString& parName, Double_t parValue); //! Constructor double limit parameter and name /*! \param [in] parName the parameter name \param [in] parValue the parameter value \param [in] min the minimum value of the parameter \param [in] max the maximum value of the parameter */ LauParameter(const TString& parName, Double_t parValue, Double_t min, Double_t max); //! Constructor double limit fixed parameter and name /*! \param [in] parName the parameter name \param [in] parValue the parameter value \param [in] min the minimum value of the parameter \param [in] max the maximum value of the parameter \param [in] parFixed boolean flag to fix (kTRUE) or float (kFALSE) the parameter */ LauParameter(const TString& parName, Double_t parValue, Double_t min, Double_t max, Bool_t parFixed); //! Constructor double error and limit parameter and name /*! \param [in] parName the parameter name \param [in] parValue the parameter value \param [in] parError the parameter error \param [in] min the minimum value of the parameter \param [in] max the maximum value of the parameter */ LauParameter(const TString& parName, Double_t parValue, Double_t parError, Double_t min, Double_t max); // Destructor virtual ~LauParameter(); //! Copy constructor /*! \param [in] rhs the parameter to be copied */ LauParameter(const LauParameter& rhs); //! Copy assignment operator /*! \param [in] rhs the parameter to be copied */ LauParameter& operator=(const LauParameter& rhs); // the simple accessor functions //! The parameter name /*! \return the name of the parameter */ inline const TString& name() const {return name_;} //! The blinding state /*! \return the blinding state: kTRUE means that it is blinded, kFALSE that it is not blinded */ inline Bool_t blind() const {return (blinder_ != 0);} //! Access the blinder object /*! \return the blinder */ inline const LauBlind* blinder() const {return blinder_;} //! The value of the parameter /*! \return the value of the parameter */ inline Double_t value() const {return value_;} //! The unblinded value of the parameter /*! \return the unblinded value of the parameter */ inline Double_t unblindValue() const {return (blinder_==0) ? value_ : blinder_->unblind(value_);} //! The error on the parameter /*! \return the error on the parameter */ inline Double_t error() const {return error_;} //! The lower error on the parameter /*! \return the lower error on the parameter */ inline Double_t negError() const {return negError_;} //! The upper error on the parameter /*! \return the upper error on the parameter */ inline Double_t posError() const {return posError_;} //! The value generated for the parameter /*! \return the value generated for the parameter */ inline Double_t genValue() const {return genValue_;} //! The initial value of the parameter /*! \return the initial value of the parameter given to the fitter */ inline Double_t initValue() const {return initValue_;} //! The minimum value allowed for the parameter /*! \return the minimum value allowed for the parameter */ inline Double_t minValue() const {return minValue_;} //! The maximum value allowed for the parameter /*! \return the maximum value allowed for the parameter */ inline Double_t maxValue() const {return maxValue_;} //! The range allowed for the parameter /*! \return the range allowed for the parameters, defined as the difference between the max and min value */ inline Double_t range() const {return this->maxValue() - this->minValue();} //! Check whether the parameter is fixed or floated /*! \return the boolean flag true/false whether the parameter is fixed */ inline Bool_t fixed() const {return fixed_;} //! Check whether the parameter should be floated only in the second stage of a two stage fit /*! \return the boolean flag true/false whether it floats only in the second stage */ inline Bool_t secondStage() const {return secondStage_;} //! Check whether a Gaussian constraints is applied /*! \return the boolean flag true/false whether a Gaussian constraint is applied */ inline Bool_t gaussConstraint() const {return gaussConstraint_;} - //! The mean of the Gaussian constraint + //! The penalty term from the Gaussian constraint /*! - \return the mean value of the Gaussian constraint + \return the penalty term from the Gaussian constraint */ - inline Double_t constraintMean() const {return constraintMean_;} - - //! The width of the Gaussian constraint - /*! - \return the width of the Gaussian constraint - */ - inline Double_t constraintWidth() const {return constraintWidth_;} + Double_t constraintPenalty() const; //! The parameter global correlation coefficient /*! \return the global correlation coefficient */ inline Double_t globalCorrelationCoeff() const {return gcc_;} //! The bias in the parameter /*! \return the bias in the parameter, defined as the difference between the value and the generated value */ inline Double_t bias() const {return bias_;} //! The pull value for the parameter /*! \return the pull value for the parameter, defined as the bias divided by the error */ inline Double_t pull() const {return pull_;} //! Boolean to say it is an L value /*! \return kTRUE, LauParameters are L values */ inline Bool_t isLValue() const {return kTRUE;} //! Get the LauParameter itself /*! \return a vector of the LauParameter */ std::vector getPars(); // the simple "setter" functions //! Set the parameter name /*! \param [in] newName the name of the parameter */ void name(const TString& newName); //! Set the value of the parameter /*! \param [in] newValue the value of the parameter */ void value(Double_t newValue); //! Set the error on the parameter /*! \param [in] newError the error on the parameter */ void error(Double_t newError); //! Set the lower error on the parameter /*! \param [in] newNegError the lower error on the parameter */ void negError(Double_t newNegError); //! Set the upper error on the parameter /*! \param [in] newPosError the upper error on the parameter */ void posError(Double_t newPosError); //! Set the error values on the parameter /*! \param [in] newError the error on the parameter \param [in] newNegError the lower error on the parameter \param [in] newPosError the upper error on the parameter */ void errors(Double_t newError, Double_t newNegError, Double_t newPosError); //! Set the value and errors on the parameter /*! \param [in] newValue the value of the parameter \param [in] newError the error on the parameter \param [in] newNegError the lower error on the parameter (default set to zero) \param [in] newPosError the upper error on the parameter (default set to zero) */ void valueAndErrors(Double_t newValue, Double_t newError, Double_t newNegError = 0.0, Double_t newPosError = 0.0); //! Set the global correlation coefficient /*! \param [in] newGCCValue the value of the coefficient */ void globalCorrelationCoeff(Double_t newGCCValue); //! Set the generated value for the parameter /*! \param [in] newGenValue the generated value for the parameter */ void genValue(Double_t newGenValue); //! Set the inital value for the parameter /*! \param [in] newInitValue the initial value for the parameter */ void initValue(Double_t newInitValue); //! Set the minimum value for the parameter /*! \param [in] newMinValue the minimum value for the parameter */ void minValue(Double_t newMinValue); //! Set the maximum value for the parameter /*! \param [in] newMaxValue the maximum value for the parameter */ void maxValue(Double_t newMaxValue); //! Set the range for the parameter /*! \param [in] newMinValue the minimum value for the parameter \param [in] newMaxValue the maximum value for the parameter */ void range(Double_t newMinValue, Double_t newMaxValue); //! Set the value and range for the parameter /*! \param [in] newValue the value of the parameter \param [in] newMinValue the minimum value for the parameter \param [in] newMaxValue the maximum value for the parameter */ void valueAndRange(Double_t newValue, Double_t newMinValue, Double_t newMaxValue); //! Fix or float the given parameter /*! \param [in] parFixed boolean flag to fix or float the parameter */ void fixed(Bool_t parFixed); //! Set parameter as second-stage or not of the fit /*! \param [in] secondStagePar boolean flag to check whether is a second-stage parameter */ void secondStage(Bool_t secondStagePar); //! Add a Gaussian constraint (or modify an existing one) /*! \param [in] newGaussMean the new value of the Gaussian constraint mean \param [in] newGaussWidth the new value of the Gaussian constraint width */ void addGaussianConstraint(Double_t newGaussMean, Double_t newGaussWidth); //! Remove the Gaussian constraint void removeGaussianConstraint(); + //! Generate per-experiment constraint mean + void generateConstraintMean(); + //! Blind the parameter /*! See LauBlind documentation for details of blinding procedure \param [in] blindingString the unique blinding string used to seed the random number generator \param [in] width the width of the Gaussian from which the offset should be sampled */ void blindParameter(const TString& blindingString, const Double_t width); // functions for the cloning mechanism //! Check whether is a clone or not /*! \return true/false whether is a clone */ inline Bool_t clone() const {return clone_;} //! Method to create a clone from the parent parameter using the copy constructor /*! \param [in] constFactor the optional constant factor by which the clone shold be multiplied \return the cloned parameter */ LauParameter* createClone(Double_t constFactor = 1.0); //! Method to create a clone from the parent parameter using the copy constructor and setting a new name /*! \param [in] newName the new name of the cloned parameter \param [in] constFactor the optional constant factor by which the clone shold be multiplied \return the cloned parameter */ LauParameter* createClone(const TString& newName, Double_t constFactor = 1.0); //! The parent parameter /*! \return the parent parameter */ inline LauParameter* parent() const {return parent_;} //! Call to update the bias and pull values void updatePull(); //! Randomise the value of the parameter (if it is floating). /*! The pre-defined parameter range is used as the randomisation range. */ void randomiseValue(); //! Randomise the value of the parameter (if it is floating). /*! Use the given range unless either of the given values are outside the range of the parameter, in which case that value will be altered to the current max or min. \param [in] minVal the minimum value for the parameter \param [in] maxVal the maximum value for the parameter */ void randomiseValue(Double_t minVal, Double_t maxVal); protected: //! Method to check whether value provided is within the range and that the minimum and maximum limits make sense /*! \param [in] val the value of the parameter \param [in] minVal the minimum value allowed \param [in] maxVal the maximum value allowed */ void checkRange(Double_t val, Double_t minVal, Double_t maxVal); //! Method to check whether value provided is whithin the range and that the minimum and maximum limits make sense inline void checkRange() { this->checkRange(this->value(),this->minValue(),this->maxValue()); } //! Mark this as a clone of the given parent /*! \param theparent the parent parameter */ inline void clone(LauParameter* theparent) { parent_ = theparent; clone_ = (parent_==0) ? kFALSE : kTRUE; } //! Method to clear the clone parameters inline void wipeClones() {clones_.clear();} //! Method to update clone values /*! \param [in] justValue boolean flag to determine whether it is necessary to update all the parameter settings or only its value. */ void updateClones(Bool_t justValue); private: //! LauFitNtuple is a friend class friend class LauFitNtuple; //! The parameter name TString name_; //! The parameter value Double_t value_; //! The error on the parameter Double_t error_; //! The lower error on the parameter Double_t negError_; //! The upper error on the parameter Double_t posError_; //! Toy generation value Double_t genValue_; //! Initial fit value Double_t initValue_; //! Minimum value for the parameter Double_t minValue_; //! Maximum value for the parameter Double_t maxValue_; //! Fix/float option for parameter Bool_t fixed_; //! Flag whether it is floated only in the second stage of the fit Bool_t secondStage_; //! Choice to use Gaussian constraint Bool_t gaussConstraint_; + //! True mean of the Gaussian constraint + Double_t constraintTrueMean_; //! Mean value of the Gaussian constraint Double_t constraintMean_; //! Width of the Gaussian constraint Double_t constraintWidth_; //! Global correlation coefficient Double_t gcc_; //! Parameter bias Double_t bias_; //! Parameter pull Double_t pull_; //! Flag whether the parameter is a clone Bool_t clone_; //! The parent parameter LauParameter* parent_; //! The clones of this parameter std::map clones_; //! The blinding engine LauBlind* blinder_; - ClassDef(LauParameter, 3) + ClassDef(LauParameter, 4) }; //! Output stream operator std::ostream& operator << (std::ostream& stream, const LauParameter& par); //! Type to define an array of parameters typedef std::vector< std::vector > LauParArray; #endif diff --git a/inc/LauSimFitCoordinator.hh b/inc/LauSimFitCoordinator.hh index 533784a..6f2bd57 100644 --- a/inc/LauSimFitCoordinator.hh +++ b/inc/LauSimFitCoordinator.hh @@ -1,235 +1,232 @@ /* Copyright 2013 University of Warwick Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /* Laura++ package authors: John Back Paul Harrison Thomas Latham */ /*! \file LauSimFitCoordinator.hh \brief File containing declaration of LauSimFitCoordinator class. */ /*! \class LauSimFitCoordinator \brief The coordinator process for simultaneous/combined fits Implementation of the JFit method described in arXiv:1409.5080 [physics.data-an]. This class acts as the interface between the task processes and the minimiser. */ #ifndef LAU_SIM_FIT_COORDINATOR #define LAU_SIM_FIT_COORDINATOR #include #include #include "TMatrixD.h" #include "TStopwatch.h" #include "TString.h" #include "LauFitObject.hh" class TMessage; class TMonitor; class TSocket; class LauAbsRValue; class LauParameter; class LauFitNtuple; class LauSimFitCoordinator : public LauFitObject { public: //! Constructor /*! \param [in] numTasks the number of tasks processes to expect connections from \param [in] port the port on which to listen for connections from the tasks */ LauSimFitCoordinator( UInt_t numTasks, UInt_t port = 9090 ); //! Destructor virtual ~LauSimFitCoordinator(); //! Run the fit /*! \param [in] fitNtupleFileName the file to which the ntuple containing the fit results should be written \param [in] nExp the number of experiments to be fitted \param [in] firstExp the ID of the first experiment to be fitted \param [in] useAsymmErrors should asymmetric errors be calculated or not \param [in] doTwoStageFit should the fit be performed in two stages or not */ void runSimFit( const TString& fitNtupleFileName, const UInt_t nExp, const UInt_t firstExp = 0, const Bool_t useAsymmErrors = kFALSE, const Bool_t doTwoStageFit = kFALSE ); //! Mark that the fit is calculating asymmetric errors /*! This function has to be public since it is called by the fitter interface to mark when entering and exiting the asymmetric error calculation. It should not be called otherwise! \param [in] inAsymErrCalc boolean marking that the fit is calculating the asymmetric errors */ virtual void withinAsymErrorCalc(const Bool_t inAsymErrCalc); // Need to unshadow the query method defined in the base class using LauFitObject::withinAsymErrorCalc; //! This function sets the parameter values from Minuit /*! This function has to be public since it is called from the global FCN. It should not be called otherwise! \param [in] par an array storing the various parameter values \param [in] npar the number of free parameters */ virtual void setParsFromMinuit(Double_t* par, Int_t npar); //! Calculate the new value of the negative log likelihood /*! This function has to be public since it is called from the global FCN. It should not be called otherwise! */ virtual Double_t getTotNegLogLikelihood(); protected: //! Print information on the parameters void printParInfo() const; //! Initialise void initialise(); //! Initialise socket connections for the tasks void initSockets(); //! Determine/update the parameter initial values from all tasks void getParametersFromTasks(); //! Determine the parameter names and initial values from all tasks void getParametersFromTasksFirstTime(); //! Update and verify the parameter initial values from all tasks void updateParametersFromTasks(); //! Check for compatibility between two same-named parameters, which should therefore be identical void checkParameter( const LauParameter* param, UInt_t index ) const; //! Add parameters to the list of Gaussian constrained parameters void addConParameters(); //! Calculate the penalty terms to the log likelihood from Gaussian constraints Double_t getLogLikelihoodPenalty(); //! Instruct the tasks to read the input data for the given experiment /*! \return success/failure of the reading operations */ Bool_t readData(); //! Instruct the tasks to perform the caching /*! \return success/failure of the caching operations */ Bool_t cacheInputData(); //! Perform the fit for the current experiment void fitExpt(); //! Instruct the tasks to update the initial fit parameter values, if required void checkInitFitParams(); //! Return the final parameters to the tasks and instruct them to perform their finalisation Bool_t finalise(); //! Instruct the tasks to write out the fit results Bool_t writeOutResults(); private: //! Copy constructor (not implemented) LauSimFitCoordinator(const LauSimFitCoordinator& rhs); //! Copy assignment operator (not implemented) LauSimFitCoordinator& operator=(const LauSimFitCoordinator& rhs); - //! Store the constraints for fit parameters until initialisation is complete - std::vector storeCon_; - //! The number of tasks const UInt_t nTasks_; //! The requested port const UInt_t reqPort_; //! The covariance sub-matrices for each task std::vector covMatrices_; //! Parallel setup monitor TMonitor* socketMonitor_; //! Sockets for each of the tasks std::vector socketTasks_; //! Messages to tasks std::vector messagesToTasks_; //! Message from tasks to the coordinator TMessage* messageFromTask_; //! Map of parameter names to index in the values vector std::map< TString, UInt_t > parIndices_; //! Reverse map of index in the values vector to parameter names std::map< UInt_t, TString > parNames_; //! Parameters std::vector params_; //! Gaussian constraints std::vector conVars_; //! Parameter values std::vector parValues_; //! Lists of indices for each task std::vector< std::vector > taskIndices_; //! Lists of indices of free parameters for each task std::vector< std::vector > taskFreeIndices_; //! Parameter values to send to the tasks std::vector vectorPar_; //! Likelihood values returned from the tasks std::vector vectorRes_; //! The fit timer TStopwatch timer_; //! The total fit timer TStopwatch cumulTimer_; //! The fit results ntuple LauFitNtuple* fitNtuple_; ClassDef(LauSimFitCoordinator,0); }; #endif diff --git a/src/LauAbsFitModel.cc b/src/LauAbsFitModel.cc index ebd25a5..8c7bca9 100644 --- a/src/LauAbsFitModel.cc +++ b/src/LauAbsFitModel.cc @@ -1,1123 +1,1108 @@ /* Copyright 2004 University of Warwick Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /* Laura++ package authors: John Back Paul Harrison Thomas Latham */ /*! \file LauAbsFitModel.cc \brief File containing implementation of LauAbsFitModel class. */ #include #include #include #include "TMessage.h" #include "TMonitor.h" -#include "TServerSocket.h" -#include "TSocket.h" #include "TSystem.h" #include "TVirtualFitter.h" #include "LauAbsFitModel.hh" #include "LauAbsFitter.hh" #include "LauAbsPdf.hh" #include "LauComplex.hh" #include "LauFitter.hh" #include "LauFitDataTree.hh" #include "LauGenNtuple.hh" #include "LauParameter.hh" #include "LauParamFixed.hh" #include "LauPrint.hh" #include "LauSPlot.hh" ClassImp(LauAbsFitModel) LauAbsFitModel::LauAbsFitModel() : fixParams_(kFALSE), compareFitData_(kFALSE), savePDF_(kFALSE), writeLatexTable_(kFALSE), writeSPlotData_(kFALSE), storeDPEff_(kFALSE), randomFit_(kFALSE), emlFit_(kFALSE), poissonSmear_(kFALSE), enableEmbedding_(kFALSE), usingDP_(kTRUE), pdfsDependOnDP_(kFALSE), inputFitData_(0), genNtuple_(0), sPlotNtuple_(0), nullString_(""), doSFit_(kFALSE), sWeightBranchName_(""), sWeightScaleFactor_(1.0), outputTableName_(""), fitToyMCFileName_("fitToyMC.root"), fitToyMCTableName_("fitToyMCTable"), fitToyMCScale_(10), fitToyMCPoissonSmear_(kFALSE), sPlotFileName_(""), sPlotTreeName_(""), sPlotVerbosity_("") { } LauAbsFitModel::~LauAbsFitModel() { delete inputFitData_; inputFitData_ = 0; delete genNtuple_; genNtuple_ = 0; delete sPlotNtuple_; sPlotNtuple_ = 0; - - // Remove the components created to apply constraints to fit parameters - for (std::vector::iterator iter = conVars_.begin(); iter != conVars_.end(); ++iter){ - if ( !(*iter)->isLValue() ){ - delete (*iter); - (*iter) = 0; - } - } } void LauAbsFitModel::run(const TString& applicationCode, const TString& dataFileName, const TString& dataTreeName, const TString& histFileName, const TString& tableFileName) { // Chose whether you want to generate or fit events in the Dalitz plot. // To generate events choose applicationCode = "gen", to fit events choose // applicationCode = "fit". TString runCode(applicationCode); runCode.ToLower(); TString histFileNameCopy(histFileName); TString tableFileNameCopy(tableFileName); TString dataFileNameCopy(dataFileName); TString dataTreeNameCopy(dataTreeName); // Initialise the fit par vectors. Each class that inherits from this one // must implement this sensibly for all vectors specified in clearFitParVectors, // i.e. specify parameter names, initial, min, max and fixed values this->initialise(); // Add variables to Gaussian constrain to a list this->addConParameters(); if (dataFileNameCopy == "") {dataFileNameCopy = "data.root";} if (dataTreeNameCopy == "") {dataTreeNameCopy = "genResults";} if (runCode.Contains("gen")) { if (histFileNameCopy == "") {histFileNameCopy = "parInfo.root";} if (tableFileNameCopy == "") {tableFileNameCopy = "genResults";} this->setGenValues(); this->generate(dataFileNameCopy, dataTreeNameCopy, histFileNameCopy, tableFileNameCopy); } else if (runCode.Contains("fit")) { if (histFileNameCopy == "") {histFileNameCopy = "parInfo.root";} if (tableFileNameCopy == "") {tableFileNameCopy = "fitResults";} this->fit(dataFileNameCopy, dataTreeNameCopy, histFileNameCopy, tableFileNameCopy); } else if (runCode.Contains("plot")) { this->savePDFPlots("plot"); } else if (runCode.Contains("weight")) { this->weightEvents(dataFileNameCopy, dataTreeNameCopy); } } void LauAbsFitModel::doSFit( const TString& sWeightBranchName, Double_t scaleFactor ) { if ( sWeightBranchName == "" ) { std::cerr << "WARNING in LauAbsFitModel::doSFit : sWeight branch name is empty string, not setting-up sFit." << std::endl; return; } doSFit_ = kTRUE; sWeightBranchName_ = sWeightBranchName; sWeightScaleFactor_ = scaleFactor; } void LauAbsFitModel::setBkgndClassNames( const std::vector& names ) { if ( !bkgndClassNames_.empty() ) { std::cerr << "WARNING in LauAbsFitModel::setBkgndClassNames : Names already stored, not changing them." << std::endl; return; } UInt_t nBkgnds = names.size(); for ( UInt_t i(0); i < nBkgnds; ++i ) { bkgndClassNames_.insert( std::make_pair( i, names[i] ) ); } this->setupBkgndVectors(); } Bool_t LauAbsFitModel::validBkgndClass( const TString& className ) const { if ( bkgndClassNames_.empty() ) { return kFALSE; } Bool_t found(kFALSE); for ( LauBkgndClassMap::const_iterator iter = bkgndClassNames_.begin(); iter != bkgndClassNames_.end(); ++iter ) { if ( iter->second == className ) { found = kTRUE; break; } } return found; } UInt_t LauAbsFitModel::bkgndClassID( const TString& className ) const { if ( ! this->validBkgndClass( className ) ) { std::cerr << "ERROR in LauAbsFitModel::bkgndClassID : Request for ID for invalid background class \"" << className << "\"." << std::endl; return (bkgndClassNames_.size() + 1); } UInt_t bgID(0); for ( LauBkgndClassMap::const_iterator iter = bkgndClassNames_.begin(); iter != bkgndClassNames_.end(); ++iter ) { if ( iter->second == className ) { bgID = iter->first; break; } } return bgID; } const TString& LauAbsFitModel::bkgndClassName( UInt_t classID ) const { LauBkgndClassMap::const_iterator iter = bkgndClassNames_.find( classID ); if ( iter == bkgndClassNames_.end() ) { std::cerr << "ERROR in LauAbsFitModel::bkgndClassName : Request for name of invalid background class ID " << classID << "." << std::endl; return nullString_; } return iter->second; } void LauAbsFitModel::clearFitParVectors() { std::cout << "INFO in LauAbsFitModel::clearFitParVectors : Clearing fit variable vectors" << std::endl; // Remove the components created to apply constraints to fit parameters for (std::vector::iterator iter = conVars_.begin(); iter != conVars_.end(); ++iter){ if ( !(*iter)->isLValue() ){ delete (*iter); (*iter) = 0; } } conVars_.clear(); fitVars_.clear(); } void LauAbsFitModel::clearExtraVarVectors() { std::cout << "INFO in LauAbsFitModel::clearExtraVarVectors : Clearing extra ntuple variable vectors" << std::endl; extraVars_.clear(); } void LauAbsFitModel::setGenValues() { // makes sure each parameter holds its genValue as its current value for (LauParameterPList::iterator iter = fitVars_.begin(); iter != fitVars_.end(); ++iter) { (*iter)->value((*iter)->genValue()); } this->propagateParUpdates(); } void LauAbsFitModel::writeSPlotData(const TString& fileName, const TString& treeName, Bool_t storeDPEfficiency, const TString& verbosity) { if (this->writeSPlotData()) { std::cerr << "ERROR in LauAbsFitModel::writeSPlotData : Already have an sPlot ntuple setup, not doing it again." << std::endl; return; } writeSPlotData_ = kTRUE; sPlotFileName_ = fileName; sPlotTreeName_ = treeName; sPlotVerbosity_ = verbosity; storeDPEff_ = storeDPEfficiency; } // TODO : histFileName isn't used here at the moment but could be used for // storing the values of the parameters used in the generation. // These could then be read and used for setting the "true" values // in a subsequent fit. void LauAbsFitModel::generate(const TString& dataFileName, const TString& dataTreeName, const TString& /*histFileName*/, const TString& tableFileNameBase) { // Create the ntuple for storing the results std::cout << "INFO in LauAbsFitModel::generate : Creating generation ntuple." << std::endl; if (genNtuple_ != 0) {delete genNtuple_; genNtuple_ = 0;} genNtuple_ = new LauGenNtuple(dataFileName,dataTreeName); // add branches for storing the experiment number and the number of // the event within the current experiment this->addGenNtupleIntegerBranch("iExpt"); this->addGenNtupleIntegerBranch("iEvtWithinExpt"); this->setupGenNtupleBranches(); // Start the cumulative timer cumulTimer_.Start(); const UInt_t firstExp = this->firstExpt(); const UInt_t nExp = this->nExpt(); Bool_t genOK(kTRUE); do { // Loop over the number of experiments for (UInt_t iExp = firstExp; iExp < (firstExp+nExp); ++iExp) { // Start the timer to see how long each experiment takes to generate timer_.Start(); // Store the experiment number in the ntuple this->setGenNtupleIntegerBranchValue("iExpt",iExp); // Do the generation for this experiment std::cout << "INFO in LauAbsFitModel::generate : Generating experiment number " << iExp << std::endl; genOK = this->genExpt(); // Stop the timer and see how long the program took so far timer_.Stop(); timer_.Print(); if (!genOK) { // delete and recreate an empty tree genNtuple_->deleteAndRecreateTree(); // then break out of the experiment loop std::cerr << "WARNING in LauAbsFitModel::generate : Problem in toy MC generation. Starting again with updated parameters..." << std::endl; break; } if (this->writeLatexTable()) { TString tableFileName(tableFileNameBase); tableFileName += "_"; tableFileName += iExp; tableFileName += ".tex"; this->writeOutTable(tableFileName); } } // Loop over number of experiments } while (!genOK); // Print out total timing info. cumulTimer_.Stop(); std::cout << "INFO in LauAbsFitModel::generate : Finished generating all experiments." << std::endl; std::cout << "INFO in LauAbsFitModel::generate : Cumulative timing:" << std::endl; cumulTimer_.Print(); // Build the event index std::cout << "INFO in LauAbsFitModel::generate : Building experiment:event index." << std::endl; // TODO - can test this return value? //Int_t nIndexEntries = genNtuple_->buildIndex("iExpt","iEvtWithinExpt"); // Write out toy MC ntuple std::cout << "INFO in LauAbsFitModel::generate : Writing data to file " << dataFileName << "." << std::endl; genNtuple_->writeOutGenResults(); } void LauAbsFitModel::addGenNtupleIntegerBranch(const TString& name) { genNtuple_->addIntegerBranch(name); } void LauAbsFitModel::addGenNtupleDoubleBranch(const TString& name) { genNtuple_->addDoubleBranch(name); } void LauAbsFitModel::setGenNtupleIntegerBranchValue(const TString& name, Int_t value) { genNtuple_->setIntegerBranchValue(name,value); } void LauAbsFitModel::setGenNtupleDoubleBranchValue(const TString& name, Double_t value) { genNtuple_->setDoubleBranchValue(name,value); } Int_t LauAbsFitModel::getGenNtupleIntegerBranchValue(const TString& name) const { return genNtuple_->getIntegerBranchValue(name); } Double_t LauAbsFitModel::getGenNtupleDoubleBranchValue(const TString& name) const { return genNtuple_->getDoubleBranchValue(name); } void LauAbsFitModel::fillGenNtupleBranches() { genNtuple_->fillBranches(); } void LauAbsFitModel::addSPlotNtupleIntegerBranch(const TString& name) { sPlotNtuple_->addIntegerBranch(name); } void LauAbsFitModel::addSPlotNtupleDoubleBranch(const TString& name) { sPlotNtuple_->addDoubleBranch(name); } void LauAbsFitModel::setSPlotNtupleIntegerBranchValue(const TString& name, Int_t value) { sPlotNtuple_->setIntegerBranchValue(name,value); } void LauAbsFitModel::setSPlotNtupleDoubleBranchValue(const TString& name, Double_t value) { sPlotNtuple_->setDoubleBranchValue(name,value); } void LauAbsFitModel::fillSPlotNtupleBranches() { sPlotNtuple_->fillBranches(); } void LauAbsFitModel::fit(const TString& dataFileName, const TString& dataTreeName, const TString& histFileName, const TString& tableFileNameBase) { // Routine to perform the total fit. const UInt_t firstExp = this->firstExpt(); const UInt_t nExp = this->nExpt(); std::cout << "INFO in LauAbsFitModel::fit : First experiment = " << firstExp << std::endl; std::cout << "INFO in LauAbsFitModel::fit : Number of experiments = " << nExp << std::endl; // Start the cumulative timer cumulTimer_.Start(); this->resetFitCounters(); // Create and setup the fit results ntuple this->setupResultsOutputs( histFileName, tableFileNameBase ); // Create and setup the sPlot ntuple if (this->writeSPlotData()) { std::cout << "INFO in LauAbsFitModel::fit : Creating sPlot ntuple." << std::endl; if (sPlotNtuple_ != 0) {delete sPlotNtuple_; sPlotNtuple_ = 0;} sPlotNtuple_ = new LauGenNtuple(sPlotFileName_,sPlotTreeName_); this->setupSPlotNtupleBranches(); } // This reads in the given dataFile and creates an input // fit data tree that stores them for all events and experiments. Bool_t dataOK = this->verifyFitData(dataFileName,dataTreeName); if (!dataOK) { std::cerr << "ERROR in LauAbsFitModel::fit : Problem caching the fit data." << std::endl; gSystem->Exit(EXIT_FAILURE); } // Loop over the number of experiments for (UInt_t iExp = firstExp; iExp < (firstExp+nExp); ++iExp) { // Start the timer to see how long each fit takes timer_.Start(); this->setCurrentExperiment( iExp ); UInt_t nEvents = this->readExperimentData(); if (nEvents < 1) { std::cerr << "WARNING in LauAbsFitModel::fit : Zero events in experiment " << iExp << ", skipping..." << std::endl; timer_.Stop(); continue; } // Now the sub-classes must implement whatever they need to do // to cache any more input fit data they need in order to // calculate the likelihoods during the fit. // They need to use the inputFitData_ tree as input. For example, // inputFitData_ contains m13Sq and m23Sq. The appropriate fit model // then caches the resonance dynamics for the signal model, as // well as the background likelihood values in the Dalitz plot this->cacheInputFitVars(); if ( this->doSFit() ) { this->cacheInputSWeights(); } + // If we're fitting toy experiments then re-generate the means of any constraints + this->generateConstraintMeans( conVars_ ); + // Do the fit for this experiment this->fitExpt(); // Write the results into the ntuple this->finaliseFitResults( outputTableName_ ); // Stop the timer and see how long the program took so far timer_.Stop(); timer_.Print(); // Store the per-event likelihood values if ( this->writeSPlotData() ) { this->storePerEvtLlhds(); } // Create a toy MC sample using the fitted parameters so that // the user can compare the fit to the data. if (compareFitData_ == kTRUE && this->statusCode() == 3) { this->createFitToyMC(fitToyMCFileName_, fitToyMCTableName_); } } // Loop over number of experiments // Print out total timing info. cumulTimer_.Stop(); std::cout << "INFO in LauAbsFitModel::fit : Cumulative timing:" << std::endl; cumulTimer_.Print(); // Print out stats on OK fits. const UInt_t nOKFits = this->numberOKFits(); const UInt_t nBadFits = this->numberBadFits(); std::cout << "INFO in LauAbsFitModel::fit : Number of OK Fits = " << nOKFits << std::endl; std::cout << "INFO in LauAbsFitModel::fit : Number of Failed Fits = " << nBadFits << std::endl; Double_t fitEff(0.0); if (nExp != 0) {fitEff = nOKFits/(1.0*nExp);} std::cout << "INFO in LauAbsFitModel::fit : Fit efficiency = " << fitEff*100.0 << "%." << std::endl; // Write out any fit results (ntuples etc...). this->writeOutAllFitResults(); if ( this->writeSPlotData() ) { this->calculateSPlotData(); } } void LauAbsFitModel::setupResultsOutputs( const TString& histFileName, const TString& tableFileName ) { this->LauSimFitTask::setupResultsOutputs( histFileName, tableFileName ); outputTableName_ = tableFileName; } Bool_t LauAbsFitModel::verifyFitData(const TString& dataFileName, const TString& dataTreeName) { // From the input data stream, store the variables into the // internal tree inputFitData_ that can be used by the sub-classes // in calculating their likelihood functions for the fit delete inputFitData_; inputFitData_ = new LauFitDataTree(dataFileName,dataTreeName); Bool_t dataOK = inputFitData_->findBranches(); if (!dataOK) { delete inputFitData_; inputFitData_ = 0; } return dataOK; } void LauAbsFitModel::cacheInputSWeights() { Bool_t hasBranch = inputFitData_->haveBranch( sWeightBranchName_ ); if ( ! hasBranch ) { std::cerr << "ERROR in LauAbsFitModel::cacheInputSWeights : Input data does not contain variable \"" << sWeightBranchName_ << "\".\n"; std::cerr << " : Turning off sFit!" << std::endl; doSFit_ = kFALSE; return; } UInt_t nEvents = this->eventsPerExpt(); sWeights_.clear(); sWeights_.reserve( nEvents ); for (UInt_t iEvt = 0; iEvt < nEvents; ++iEvt) { const LauFitData& dataValues = inputFitData_->getData(iEvt); LauFitData::const_iterator iter = dataValues.find( sWeightBranchName_ ); sWeights_.push_back( iter->second * sWeightScaleFactor_ ); } } void LauAbsFitModel::fitExpt() { // Routine to perform the actual fit for the given experiment // Update initial fit parameters if required (e.g. if using random numbers). this->checkInitFitParams(); // Initialise the fitter LauFitter::fitter().useAsymmFitErrors( this->useAsymmFitErrors() ); LauFitter::fitter().twoStageFit( this->twoStageFit() ); LauFitter::fitter().initialise( this, fitVars_ ); this->startNewFit( LauFitter::fitter().nParameters(), LauFitter::fitter().nFreeParameters() ); // Now ready for minimisation step std::cout << "\nINFO in LauAbsFitModel::fitExpt : Start minimisation...\n"; LauAbsFitter::FitStatus fitResult = LauFitter::fitter().minimise(); // If we're doing a two stage fit we can now release (i.e. float) // the 2nd stage parameters and re-fit if (this->twoStageFit()) { if ( fitResult.status != 3 ) { std::cerr << "WARNING in LauAbsFitModel:fitExpt : Not running second stage fit since first stage failed." << std::endl; LauFitter::fitter().releaseSecondStageParameters(); } else { LauFitter::fitter().releaseSecondStageParameters(); this->startNewFit( LauFitter::fitter().nParameters(), LauFitter::fitter().nFreeParameters() ); fitResult = LauFitter::fitter().minimise(); } } const TMatrixD& covMat = LauFitter::fitter().covarianceMatrix(); this->storeFitStatus( fitResult, covMat ); // Store the final fit results and errors into protected internal vectors that // all sub-classes can use within their own finalFitResults implementation // used below (e.g. putting them into an ntuple in a root file) LauFitter::fitter().updateParameters(); } void LauAbsFitModel::calculateSPlotData() { if (sPlotNtuple_ != 0) { sPlotNtuple_->addFriendTree(inputFitData_->fileName(), inputFitData_->treeName()); sPlotNtuple_->writeOutGenResults(); LauSPlot splot(sPlotNtuple_->fileName(), sPlotNtuple_->treeName(), this->firstExpt(), this->nExpt(), this->variableNames(), this->freeSpeciesNames(), this->fixdSpeciesNames(), this->twodimPDFs(), this->splitSignal(), this->scfDPSmear()); splot.runCalculations(sPlotVerbosity_); splot.writeOutResults(); } } void LauAbsFitModel::compareFitData(UInt_t toyMCScale, const TString& mcFileName, const TString& tableFileName, Bool_t poissonSmearing) { compareFitData_ = kTRUE; fitToyMCScale_ = toyMCScale; fitToyMCFileName_ = mcFileName; fitToyMCTableName_ = tableFileName; fitToyMCPoissonSmear_ = poissonSmearing; } void LauAbsFitModel::createFitToyMC(const TString& mcFileName, const TString& tableFileName) { // Create a toy MC sample so that the user can compare the fitted // result with the data. // Generate more toy MC to reduce statistical fluctuations: // - use the rescaling value fitToyMCScale_ // Store the info on the number of experiments, first expt and current expt const UInt_t oldNExpt(this->nExpt()); const UInt_t oldFirstExpt(this->firstExpt()); const UInt_t oldIExpt(this->iExpt()); + const Bool_t oldToyExpt(this->toyExpts()); // Turn off Poisson smearing if required const Bool_t poissonSmearing(this->doPoissonSmearing()); this->doPoissonSmearing(fitToyMCPoissonSmear_); // Turn off embedding, since we need toy MC, not reco'ed events const Bool_t enableEmbeddingOrig(this->enableEmbedding()); this->enableEmbedding(kFALSE); // Need to make sure that the generation of the DP co-ordinates is // switched on if any of our PDFs depend on it const Bool_t origUseDP = this->useDP(); if ( !origUseDP && this->pdfsDependOnDP() ) { this->useDP( kTRUE ); this->initialiseDPModels(); } // Construct a unique filename for this experiment TString exptString("_expt"); exptString += oldIExpt; TString fileName( mcFileName ); fileName.Insert( fileName.Last('.'), exptString ); // Generate the toy MC std::cout << "INFO in LauAbsFitModel::createFitToyMC : Generating toy MC in " << fileName << " to compare fit with data..." << std::endl; std::cout << " : Number of experiments to generate = " << fitToyMCScale_ << "." << std::endl; std::cout << " : This is to allow the toy MC to be made with reduced statistical fluctuations." << std::endl; // Set the genValue of each parameter to its current (fitted) value // but first store the original genValues for restoring later std::vector origGenValues; origGenValues.reserve(this->nTotParams()); Bool_t blind(kFALSE); for (LauParameterPList::iterator iter = fitVars_.begin(); iter != fitVars_.end(); ++iter) { origGenValues.push_back((*iter)->genValue()); (*iter)->genValue((*iter)->unblindValue()); if ( (*iter)->blind() ) { blind = kTRUE; } } if ( blind ) { std::cerr << "WARNING in LauAbsFitModel::createFitToyMC : One or more parameters are blind but the toy will be created using the unblind values - use with caution!!" << std::endl; } // If we're asked to generate more than 100 experiments then split it // up into multiple files since otherwise can run into memory issues // when building the index // TODO - this obviously depends on the number of events per experiment as well, so should do this properly UInt_t totalExpts = fitToyMCScale_; if ( totalExpts > 100 ) { UInt_t nFiles = totalExpts/100; if ( totalExpts%100 ) { nFiles += 1; } TString fileNameBase {fileName}; for ( UInt_t iFile(0); iFile < nFiles; ++iFile ) { UInt_t firstExp( iFile*100 ); // Set number of experiments and first experiment to generate UInt_t nExp = ((firstExp + 100)>totalExpts) ? totalExpts-firstExp : 100; - this->setNExpts(nExp, firstExp); + this->setNExpts(nExp, firstExp, kTRUE); // Create a unique filename and generate the events fileName = fileNameBase; TString extraname = "_file"; extraname += iFile; fileName.Insert( fileName.Last('.'), extraname ); this->generate(fileName, "genResults", "dummy.root", tableFileName); } } else { // Set number of experiments to new value - this->setNExpts(fitToyMCScale_, 0); + this->setNExpts(fitToyMCScale_, 0, kTRUE); // Generate the toy this->generate(fileName, "genResults", "dummy.root", tableFileName); } // Reset number of experiments to original value - this->setNExpts(oldNExpt, oldFirstExpt); + this->setNExpts(oldNExpt, oldFirstExpt, oldToyExpt); this->setCurrentExperiment(oldIExpt); // Restore the Poisson smearing to its former value this->doPoissonSmearing(poissonSmearing); // Restore the embedding status this->enableEmbedding(enableEmbeddingOrig); // Restore "useDP" to its former status this->useDP( origUseDP ); // Restore the original genValue to each parameter for (UInt_t i(0); inTotParams(); ++i) { fitVars_[i]->genValue(origGenValues[i]); } std::cout << "INFO in LauAbsFitModel::createFitToyMC : Finished in createFitToyMC." << std::endl; } Double_t LauAbsFitModel::getTotNegLogLikelihood() { // Calculate the total negative log-likelihood over all events. // This function assumes that the fit parameters and data tree have // already been set-up correctly. // Loop over the data points to calculate the log likelihood Double_t logLike = this->getLogLikelihood( 0, this->eventsPerExpt() ); // Include the Poisson term in the extended likelihood if required if (this->doEMLFit()) { logLike -= this->getEventSum(); } // Calculate any penalty terms from Gaussian constrained variables - const std::vector& storeNDCon = this->NDConstraintsStore(); - if ( ! conVars_.empty() || ! storeNDCon.empty() ){ + const auto& multiDimCons = this->multiDimConstraints(); + if ( ! conVars_.empty() || ! multiDimCons.empty() ){ logLike -= this->getLogLikelihoodPenalty(); } Double_t totNegLogLike = -logLike; return totNegLogLike; } Double_t LauAbsFitModel::getLogLikelihoodPenalty() { - Double_t penalty(0.0); + Double_t penalty{0.0}; for ( LauAbsRValue* par : conVars_ ) { - Double_t val = par->unblindValue(); - Double_t mean = par->constraintMean(); - Double_t width = par->constraintWidth(); - - Double_t term = ( val - mean )*( val - mean ); - penalty += term/( 2*width*width ); + penalty += par->constraintPenalty(); } - std::vector& storeNDCon = this->NDConstraintsStore(); - for ( ULong_t i = 0; iunblindValue(); - } - TVectorD diff = storeNDCon[i].values_-storeNDCon[i].means_; - penalty += 0.5*storeNDCon[i].invCovMat_.Similarity(diff); + auto& multiDimCons = this->multiDimConstraints(); + for ( auto& constraint : multiDimCons ) { + penalty += constraint.constraintPenalty(); } return penalty; } Double_t LauAbsFitModel::getLogLikelihood( UInt_t iStart, UInt_t iEnd ) { // Calculate the total negative log-likelihood over all events. // This function assumes that the fit parameters and data tree have // already been set-up correctly. // Loop over the data points to calculate the log likelihood Double_t logLike(0.0); const Double_t worstLL = this->worstLogLike(); // Loop over the number of events in this experiment Bool_t ok(kTRUE); for (UInt_t iEvt = iStart; iEvt < iEnd; ++iEvt) { Double_t likelihood = this->getTotEvtLikelihood(iEvt); if (likelihood > std::numeric_limits::min()) { // Is the likelihood zero? Double_t evtLogLike = TMath::Log(likelihood); if ( doSFit_ ) { evtLogLike *= sWeights_[iEvt]; } logLike += evtLogLike; } else { ok = kFALSE; std::cerr << "WARNING in LauAbsFitModel::getLogLikelihood : Strange likelihood value for event " << iEvt << ": " << likelihood << "\n"; this->printEventInfo(iEvt); this->printVarsInfo(); //Write the values of the floated variables for which the likelihood is zero break; } } if (!ok) { std::cerr << " : Returning worst NLL found so far to force MINUIT out of this region." << std::endl; logLike = worstLL; } else if (logLike < worstLL) { this->worstLogLike( logLike ); } return logLike; } void LauAbsFitModel::setParsFromMinuit(Double_t* par, Int_t npar) { // This function sets the internal parameters based on the values // that Minuit is using when trying to minimise the total likelihood function. // MINOS reports different numbers of free parameters depending on the // situation, so disable this check if ( ! this->withinAsymErrorCalc() ) { const UInt_t nFreePars = this->nFreeParams(); if (static_cast(npar) != nFreePars) { std::cerr << "ERROR in LauAbsFitModel::setParsFromMinuit : Unexpected number of free parameters: " << npar << ".\n"; std::cerr << " Expected: " << nFreePars << ".\n" << std::endl; gSystem->Exit(EXIT_FAILURE); } } // Despite npar being the number of free parameters // the par array actually contains all the parameters, // free and floating... // Update all the floating ones with their new values // Also check if we have any parameters on which the DP integrals depend // and whether they have changed since the last iteration Bool_t recalcNorm(kFALSE); const LauParameterPSet::const_iterator resVarsEnd = resVars_.end(); for (UInt_t i(0); inTotParams(); ++i) { if (!fitVars_[i]->fixed()) { if ( resVars_.find( fitVars_[i] ) != resVarsEnd ) { if ( fitVars_[i]->value() != par[i] ) { recalcNorm = kTRUE; } } fitVars_[i]->value(par[i]); } } // If so, then recalculate the normalisation if (recalcNorm) { this->recalculateNormalisation(); } this->propagateParUpdates(); } UInt_t LauAbsFitModel::addFitParameters(LauPdfList& pdfList) { UInt_t nParsAdded(0); for (LauPdfList::iterator pdf_iter = pdfList.begin(); pdf_iter != pdfList.end(); ++pdf_iter) { LauAbsPdf* pdf = (*pdf_iter); if ( pdf->isDPDependent() ) { this->pdfsDependOnDP( kTRUE ); } LauAbsRValuePList& pars = pdf->getParameters(); for (LauAbsRValuePList::iterator pars_iter = pars.begin(); pars_iter != pars.end(); ++pars_iter) { LauParameterPList params = (*pars_iter)->getPars(); for (LauParameterPList::iterator params_iter = params.begin(); params_iter != params.end(); ++params_iter) { if ( !(*params_iter)->clone() && ( !(*params_iter)->fixed() || ( this->twoStageFit() && (*params_iter)->secondStage() ) ) ) { fitVars_.push_back(*params_iter); ++nParsAdded; } } } } return nParsAdded; } void LauAbsFitModel::addConParameters() { - for ( LauParameterPList::const_iterator iter = fitVars_.begin(); iter != fitVars_.end(); ++iter ) { - if ( (*iter)->gaussConstraint() ) { - conVars_.push_back( *iter ); - std::cout << "INFO in LauAbsFitModel::addConParameters : Added Gaussian constraint to parameter "<< (*iter)->name() << std::endl; + // Add penalties from the constraints to fit parameters + + // First, constraints on the fit parameters themselves + for ( LauParameter* param : fitVars_ ) { + if ( param->gaussConstraint() ) { + conVars_.push_back( param ); + std::cout << "INFO in LauAbsFitModel::addConParameters : Added Gaussian constraint to parameter "<< param->name() << std::endl; } } - // Add penalties from the constraints to fit parameters - const std::vector& storeCon = this->constraintsStore(); - for ( std::vector::const_iterator iter = storeCon.begin(); iter != storeCon.end(); ++iter ) { - const std::vector& names = (*iter).conPars_; + // Second, constraints on arbitrary combinations + auto& conStore = this->formulaConstraints(); + for ( auto& constraint : conStore ) { std::vector params; - for ( std::vector::const_iterator iternames = names.begin(); iternames != names.end(); ++iternames ) { - for ( LauParameterPList::const_iterator iterfit = fitVars_.begin(); iterfit != fitVars_.end(); ++iterfit ) { - if ( (*iternames) == (*iterfit)->name() ){ - params.push_back(*iterfit); + for ( const auto& name : constraint.conPars_ ) { + for ( LauParameter* par : fitVars_ ) { + if ( par->name() == name ){ + params.push_back( par ); } } } // If the parameters are not found, skip it - if ( params.size() != (*iter).conPars_.size() ) { + if ( params.size() != constraint.conPars_.size() ) { std::cerr << "WARNING in LauAbsFitModel::addConParameters: Could not find parameters to constrain in the formula... skipping" << std::endl; continue; } - LauFormulaPar* formPar = new LauFormulaPar( (*iter).formula_, (*iter).formula_, params ); - formPar->addGaussianConstraint( (*iter).mean_, (*iter).width_ ); - conVars_.push_back(formPar); + constraint.formulaPar_ = std::make_unique( constraint.formula_, constraint.formula_, params ); + constraint.formulaPar_->addGaussianConstraint( constraint.mean_, constraint.width_ ); + + conVars_.push_back( constraint.formulaPar_.get() ); std::cout << "INFO in LauAbsFitModel::addConParameters : Added Gaussian constraint to formula\n"; - std::cout << " : Formula: " << (*iter).formula_ << std::endl; - for ( std::vector::iterator iterparam = params.begin(); iterparam != params.end(); ++iterparam ) { - std::cout << " : Parameter: " << (*iterparam)->name() << std::endl; + std::cout << " : Formula: " << constraint.formula_ << std::endl; + for ( LauParameter* param : params ) { + std::cout << " : Parameter: " << param->name() << std::endl; } } // Add n-dimensional constraints - std::vector& storeNDCon = this->NDConstraintsStore(); - for ( auto& constraint : storeNDCon ){ + auto& multiDimCons = this->multiDimConstraints(); + for ( auto& constraint : multiDimCons ){ for ( auto& parname : constraint.conPars_ ){ for ( auto& fitPar : fitVars_ ){ if ( parname == fitPar->name() ){ // Check parameters do not have a 1D Gaussian constraint applied if ( fitPar->gaussConstraint() ){ std::cerr << "ERROR in LauAbsFitModel::addConParameters: parameter in n-dimensional constraint already has a 1d constraint applied" << std::endl; gSystem->Exit(EXIT_FAILURE); } constraint.conLauPars_.push_back(fitPar); } } } if ( constraint.conLauPars_.size() != constraint.conPars_.size() ){ std::cerr << "Error in LauAbsFitModel::addConParameters : Could not match parameter names for n-dimensional constraint" << std::endl; gSystem->Exit(EXIT_FAILURE); } } } void LauAbsFitModel::updateFitParameters(LauPdfList& pdfList) { for (LauPdfList::iterator pdf_iter = pdfList.begin(); pdf_iter != pdfList.end(); ++pdf_iter) { (*pdf_iter)->updatePulls(); } } void LauAbsFitModel::printFitParameters(const LauPdfList& pdfList, std::ostream& fout) const { LauPrint print; for (LauPdfList::const_iterator pdf_iter = pdfList.begin(); pdf_iter != pdfList.end(); ++pdf_iter) { const LauAbsRValuePList& pars = (*pdf_iter)->getParameters(); for (LauAbsRValuePList::const_iterator pars_iter = pars.begin(); pars_iter != pars.end(); ++pars_iter) { LauParameterPList params = (*pars_iter)->getPars(); for (LauParameterPList::iterator params_iter = params.begin(); params_iter != params.end(); ++params_iter) { if (!(*params_iter)->clone()) { fout << (*params_iter)->name() << " & $"; print.printFormat(fout, (*params_iter)->value()); if ((*params_iter)->fixed() == kTRUE) { fout << "$ (fixed) \\\\"; } else { fout << " \\pm "; print.printFormat(fout, (*params_iter)->error()); fout << "$ \\\\" << std::endl; } } } } } } void LauAbsFitModel::cacheInfo(LauPdfList& pdfList, const LauFitDataTree& theData) { for (LauPdfList::iterator pdf_iter = pdfList.begin(); pdf_iter != pdfList.end(); ++pdf_iter) { (*pdf_iter)->cacheInfo(theData); } } Double_t LauAbsFitModel::prodPdfValue(LauPdfList& pdfList, UInt_t iEvt) { Double_t pdfVal = 1.0; for (LauPdfList::iterator pdf_iter = pdfList.begin(); pdf_iter != pdfList.end(); ++pdf_iter) { (*pdf_iter)->calcLikelihoodInfo(iEvt); pdfVal *= (*pdf_iter)->getLikelihood(); } return pdfVal; } void LauAbsFitModel::printEventInfo(UInt_t iEvt) const { const LauFitData& data = inputFitData_->getData(iEvt); std::cerr << " : Input data values for this event:" << std::endl; for (LauFitData::const_iterator iter = data.begin(); iter != data.end(); ++iter) { std::cerr << " " << iter->first << " = " << iter->second << std::endl; } } void LauAbsFitModel::printVarsInfo() const { std::cerr << " : Current values of fit parameters:" << std::endl; for (UInt_t i(0); inTotParams(); ++i) { std::cerr << " " << (fitVars_[i]->name()).Data() << " = " << fitVars_[i]->value() << std::endl; } } void LauAbsFitModel::prepareInitialParArray( TObjArray& array ) { // Update initial fit parameters if required (e.g. if using random numbers). this->checkInitFitParams(); // Store the total number of parameters and the number of free parameters UInt_t nPars = fitVars_.size(); UInt_t nFreePars = 0; // Send the fit parameters for ( LauParameterPList::iterator iter = fitVars_.begin(); iter != fitVars_.end(); ++iter ) { if ( ! (*iter)->fixed() ) { ++nFreePars; } array.Add( *iter ); } this->startNewFit( nPars, nFreePars ); } void LauAbsFitModel::finaliseExperiment( const LauAbsFitter::FitStatus& fitStat, const TObjArray* parsFromCoordinator, const TMatrixD* covMat, TObjArray& parsToCoordinator ) { // Copy the fit status information this->storeFitStatus( fitStat, *covMat ); // Now process the parameters const UInt_t nPars = this->nTotParams(); UInt_t nParsFromCoordinator = parsFromCoordinator->GetEntries(); if ( nParsFromCoordinator != nPars ) { std::cerr << "ERROR in LauAbsFitModel::finaliseExperiment : Unexpected number of parameters received from coordinator" << std::endl; std::cerr << " : Received " << nParsFromCoordinator << " when expecting " << nPars << std::endl; gSystem->Exit( EXIT_FAILURE ); } for ( UInt_t iPar(0); iPar < nParsFromCoordinator; ++iPar ) { LauParameter* parameter = dynamic_cast( (*parsFromCoordinator)[iPar] ); if ( ! parameter ) { std::cerr << "ERROR in LauAbsFitModel::finaliseExperiment : Error reading parameter from coordinator" << std::endl; gSystem->Exit( EXIT_FAILURE ); } if ( parameter->name() != fitVars_[iPar]->name() ) { std::cerr << "ERROR in LauAbsFitModel::finaliseExperiment : Error reading parameter from coordinator" << std::endl; gSystem->Exit( EXIT_FAILURE ); } *(fitVars_[iPar]) = *parameter; } // Write the results into the ntuple this->finaliseFitResults( outputTableName_ ); // Store the per-event likelihood values if ( this->writeSPlotData() ) { this->storePerEvtLlhds(); } // Create a toy MC sample using the fitted parameters so that // the user can compare the fit to the data. if (compareFitData_ == kTRUE && fitStat.status == 3) { this->createFitToyMC(fitToyMCFileName_, fitToyMCTableName_); } // Send the finalised fit parameters for ( LauParameterPList::iterator iter = fitVars_.begin(); iter != fitVars_.end(); ++iter ) { parsToCoordinator.Add( *iter ); } } UInt_t LauAbsFitModel::readExperimentData() { // retrieve the data and find out how many events have been read const UInt_t exptIndex = this->iExpt(); inputFitData_->readExperimentData( exptIndex ); const UInt_t nEvent = inputFitData_->nEvents(); this->eventsPerExpt( nEvent ); return nEvent; } void LauAbsFitModel::setParametersFromFile(const TString& fileName, const TString& treeName, const Bool_t fix) { fixParamFileName_ = fileName; fixParamTreeName_ = treeName; fixParams_ = fix; } void LauAbsFitModel::setParametersFromMap(const std::map& parameters, const Bool_t fix) { fixParamMap_ = parameters; fixParams_ = fix; } void LauAbsFitModel::setNamedParameters(const TString& fileName, const TString& treeName, const std::set& parameters, const Bool_t fix) { fixParamFileName_ = fileName; fixParamTreeName_ = treeName; fixParamNames_ = parameters; fixParams_ = fix; } void LauAbsFitModel::setParametersFileFallback(const TString& fileName, const TString& treeName, const std::map& parameters, const Bool_t fix) { fixParamFileName_ = fileName; fixParamTreeName_ = treeName; fixParamMap_ = parameters; fixParams_ = fix; } diff --git a/src/LauFitObject.cc b/src/LauFitObject.cc index 6e64ef5..0b73591 100644 --- a/src/LauFitObject.cc +++ b/src/LauFitObject.cc @@ -1,176 +1,251 @@ /* Copyright 2017 University of Warwick Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /* Laura++ package authors: John Back Paul Harrison Thomas Latham */ /*! \file LauFitObject.cc \brief File containing implementation of LauFitObject class. */ #include +#include "TDecompChol.h" #include "TMatrixD.h" +#include "TRandom.h" #include "TSystem.h" #include "TVectorD.h" #include "LauFitObject.hh" +#include "LauRandom.hh" ClassImp(LauFitObject) LauFitObject::LauFitObject() : TObject(), - storeCon_(), twoStageFit_(kFALSE), useAsymmFitErrors_(kFALSE), nParams_(0), nFreeParams_(0), withinAsymErrorCalc_(kFALSE), + toyExpts_(kFALSE), firstExpt_(0), - nExpt_(0), + nExpt_(1), iExpt_(0), evtsPerExpt_(0), fitStatus_({-1,0.0,0.0}), worstLogLike_(std::numeric_limits::max()), covMatrix_(), numberOKFits_(0), numberBadFits_(0) { } +void LauFitObject::setNExpts(UInt_t nExperiments, UInt_t firstExperiment, Bool_t toyExpts) +{ + nExpt_ = nExperiments; + firstExpt_ = firstExperiment; + toyExpts_ = toyExpts; + + if ( ! toyExpts && ( nExperiments > 1 || firstExperiment > 0 ) ) { + std::cerr << "WARNING in LauFitObject::setNExpts : toyExpts is set to kFALSE but the values of nExperiments and firstExperiment indicate otherwise, please check" << std::endl; + } else if ( toyExpts && nExperiments == 1 && firstExperiment == 0 ) { + std::cerr << "WARNING in LauFitObject::setNExpts : toyExpts is set to kTRUE but the values of nExperiments and firstExperiment perhaps indicate otherwise, please check" << std::endl; + } +} + void LauFitObject::resetFitCounters() { numberOKFits_ = 0; numberBadFits_ = 0; fitStatus_ = { -1, 0.0, 0.0 }; } void LauFitObject::startNewFit( const UInt_t nPars, const UInt_t nFreePars ) { // Reset the worst likelihood found to its catch-all value worstLogLike_ = std::numeric_limits::max(); // Store the number of fit parameters (total and floating) nParams_ = nPars; nFreeParams_ = nFreePars; } void LauFitObject::storeFitStatus( const LauAbsFitter::FitStatus& status, const TMatrixD& covMatrix ) { fitStatus_ = status; covMatrix_.Clear(); covMatrix_.ResizeTo( covMatrix.GetNrows(), covMatrix.GetNcols() ); covMatrix_.SetMatrixArray( covMatrix.GetMatrixArray() ); // Keep track of how many fits worked or failed // NB values of fitStatus_ indicate the status of the error matrix: // 0= not calculated at all // 1= approximation only, not accurate // 2= full matrix, but forced positive-definite // 3= full accurate covariance matrix if (fitStatus_.status == 3) { ++numberOKFits_; } else { ++numberBadFits_; } } void LauFitObject::addConstraint(const TString& formula, const std::vector& pars, const Double_t mean, const Double_t width) { + std::cerr << "WARNING in LauFitObject::addConstraint : This function is deprecated, please switch to addFormulaConstraint!" << std::endl; + this->addFormulaConstraint( formula, pars, mean, width ); +} + +void LauFitObject::addFormulaConstraint(const TString& formula, const std::vector& pars, const Double_t mean, const Double_t width) +{ if ( ! this->checkRepetition(pars) ){ - std::cerr << "ERROR in LauFitObject::addConstraint : Parameter(s) added to multiple constraints!" << std::endl; - gSystem->Exit( EXIT_FAILURE ); + std::cerr << "WARNING in LauFitObject::addFormulaConstraint : Parameter(s) added to multiple constraints!" << std::endl; } - StoreConstraints newCon; - newCon.formula_ = formula; - newCon.conPars_ = pars; - newCon.mean_ = mean; - newCon.width_ = width; - - storeCon_.push_back(newCon); + formulaConstraints_.emplace_back( FormulaConstraint{formula, pars, mean, width, nullptr} ); - std::cout << "INFO in LauFitObject::addConstraint : Added formula to constrain" << std::endl; + std::cout << "INFO in LauFitObject::addFormulaConstraint : Added formula constraint" << std::endl; } -void LauFitObject::addNDConstraint( const std::vector& pars, const TVectorD& means, const TMatrixD& covMat) +void LauFitObject::addMultiDimConstraint( const std::vector& pars, const TVectorD& means, const TMatrixD& covMat) { - if ( covMat.GetNcols() != covMat.GetNrows() ){ - std::cerr << "ERROR in LauFitObject::addNDConstraint : Covariance matrix is not square!" << std::endl; - gSystem->Exit( EXIT_FAILURE ); + if ( ! this->checkRepetition(pars) ){ + std::cerr << "WARNING in LauFitObject::addMultiDimConstraint : Parameter(s) added to multiple constraints!" << std::endl; } - if ( ( pars.size() != static_cast(means.GetNrows()) ) || ( pars.size() != static_cast(covMat.GetNcols()) ) ){ - std::cerr << "ERROR in LauFitObject::addNDConstraint : Different number of elements in vectors/covariance matrix!" << std::endl; - gSystem->Exit( EXIT_FAILURE ); - } + multiDimConstraints_.emplace_back( pars, means, covMat ); - if ( ! this->checkRepetition(pars) ){ - std::cerr << "ERROR in LauFitObject::addNDConstraint : Parameter(s) added to multiple constraints!" << std::endl; - gSystem->Exit( EXIT_FAILURE ); + std::cout << "INFO in LauFitObject::addMultiDimConstraint : Added multi-dimensional constraint" << std::endl; +} + +void LauFitObject::generateConstraintMeans( std::vector& conVars ) +{ + if ( ! this->toyExpts() ) { + return; } - TMatrixD invCovMat {TMatrixD::kInverted, covMat}; - // Check invertion was successful - if ( invCovMat == covMat ){ - std::cerr << "ERROR in LauFitObject::addNDConstraint : covariance matrix inversion failed, check your input!" << std::endl; - gSystem->Exit( EXIT_FAILURE ); + // For reproducibility, set a seed based on the experiment number + // First, store the current seed, so that it can be restored afterwards + const UInt_t oldSeed { LauRandom::randomFun()->GetSeed() }; + LauRandom::randomFun()->SetSeed( 827375 + this->iExpt() ); + + for ( LauAbsRValue* par : conVars ) { + par->generateConstraintMean(); } - TVectorD values(means.GetNrows()); - StoreNDConstraints newCon { pars, means, invCovMat, {}, values }; - storeNDCon_.emplace_back( newCon ); + for ( auto& constraint : multiDimConstraints_ ) { + constraint.generateConstraintMeans(); + } - std::cout << "INFO in LauFitObject::addNDConstraint : Added list of parameters to constrain" << std::endl; + // Restore the old random seed + LauRandom::randomFun()->SetSeed( oldSeed ); } Bool_t LauFitObject::checkRepetition( const std::vector& names ) { Bool_t allOK(kTRUE); - if ( storeCon_.size()==0 && storeNDCon_.size()==0 ) { + if ( formulaConstraints_.size()==0 && multiDimConstraints_.size()==0 ) { return allOK; } //Check in formula constraints - for ( auto& constraint : storeCon_ ){ + for ( auto& constraint : formulaConstraints_ ){ for ( auto& parname : constraint.conPars_ ){ for ( auto& newname : names ){ if ( parname == newname ){ std::cerr << "WARNING in LauFitObject::checkRepetition: named parameter " << newname << " already used in a constraint" << std::endl; allOK = kFALSE; } } } } //Check in ND constraints - for ( auto& constraint : storeNDCon_ ){ + for ( auto& constraint : multiDimConstraints_ ){ for ( auto& parname : constraint.conPars_ ){ for ( auto& newname : names ){ if ( parname == newname ){ std::cerr << "WARNING in LauFitObject::checkRepetition: named parameter " << newname << " already used in a constraint" << std::endl; allOK = kFALSE; } } } } return allOK; } + +LauFitObject::MultiDimConstraint::MultiDimConstraint( const std::vector& parNames, const TVectorD& means, const TMatrixD& covMat ) : + conPars_{parNames}, + trueMeans_{means}, + means_{means}, + invCovMat_{covMat.GetNrows(),covMat.GetNcols()}, + sqrtCovMat_{covMat.GetNrows(),covMat.GetNcols()} +{ + if ( covMat.GetNcols() != covMat.GetNrows() ){ + std::cerr << "ERROR in LauFitObject::MultiDimConstraint : Covariance matrix is not square!" << std::endl; + gSystem->Exit( EXIT_FAILURE ); + } + + if ( ( parNames.size() != static_cast(means.GetNrows()) ) || ( parNames.size() != static_cast(covMat.GetNrows()) ) ){ + std::cerr << "ERROR in LauFitObject::MultiDimConstraint : Different number of elements in vectors/covariance matrix!" << std::endl; + gSystem->Exit( EXIT_FAILURE ); + } + + // Check invertion of the covariance matrix was successful + TMatrixD invCovMat {TMatrixD::kInverted, covMat}; + if ( invCovMat == covMat ){ + std::cerr << "ERROR in LauFitObject::MultiDimConstraint : covariance matrix inversion failed, check your input!" << std::endl; + gSystem->Exit( EXIT_FAILURE ); + } + invCovMat_ = invCovMat; + + // Check invertion of the covariance matrix was successful + TDecompChol cholDecomp {covMat}; + if ( ! cholDecomp.Decompose() ) { + std::cerr << "ERROR in LauFitObject::MultiDimConstraint : covariance matrix decomposition failed, check your input!" << std::endl; + gSystem->Exit( EXIT_FAILURE ); + } + sqrtCovMat_ = TMatrixD{TMatrixD::kTransposed, cholDecomp.GetU()}; +} + +Double_t LauFitObject::MultiDimConstraint::constraintPenalty() const +{ + TVectorD diff{ means_.GetNrows() }; + for ( ULong_t j {0}; j < conLauPars_.size(); ++j ) { + LauParameter* param = conLauPars_[j]; + diff[j] = param->unblindValue(); + } + diff -= means_; + return 0.5 * invCovMat_.Similarity( diff ); +} + +void LauFitObject::MultiDimConstraint::generateConstraintMeans() +{ + TRandom* random = LauRandom::randomFun(); + + for ( Int_t j {0}; j < trueMeans_.GetNrows(); ++j ) { + means_[j] = random->Gaus(0.0, 1.0); + } + + means_ *= sqrtCovMat_; + means_ += trueMeans_; +} diff --git a/src/LauFormulaPar.cc b/src/LauFormulaPar.cc index 03883c7..56dd17d 100644 --- a/src/LauFormulaPar.cc +++ b/src/LauFormulaPar.cc @@ -1,197 +1,215 @@ /* Copyright 2014 University of Warwick Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /* Laura++ package authors: John Back Paul Harrison Thomas Latham */ /*! \file LauFormulaPar.cc \brief File containing implementation of LauFormulaPar class. */ #include #include #include #include #include "TRandom.h" #include "TMessage.h" #include "TSystem.h" #include "LauFormulaPar.hh" #include "LauParameter.hh" #include "LauRandom.hh" ClassImp(LauFormulaPar) LauFormulaPar::LauFormulaPar(const TString& forName, const TString& formula, const std::vector& params) : name_(forName), formula_(forName,formula), paramVec_(params), paramArray_(nullptr), gaussConstraint_(kFALSE), + constraintTrueMean_(0.0), constraintMean_(0.0), constraintWidth_(0.0) { // Check length of vector matches number of parameter in the formula Int_t nPars = paramVec_.size(); if (formula_.GetNpar() != nPars){ std::cerr<<"ERROR in LauFormulaPar::evaluate : Number of parameters in the formula is : "<Exit(EXIT_FAILURE); } if (formula_.GetNdim() != 0){ std::cerr<<"ERROR in LauFormulaPar::evaluate : Given formula of dimension: "<Exit(EXIT_FAILURE); } // Array of input parameters paramArray_ = new Double_t[nPars]; } LauFormulaPar::~LauFormulaPar() { delete[] paramArray_; } LauFormulaPar::LauFormulaPar(const LauFormulaPar& rhs) : LauAbsRValue(rhs), name_(rhs.name_), formula_(rhs.formula_), paramVec_(rhs.paramVec_), paramArray_(nullptr), gaussConstraint_(rhs.gaussConstraint_), + constraintTrueMean_(rhs.constraintTrueMean_), constraintMean_(rhs.constraintMean_), constraintWidth_(rhs.constraintWidth_) { // Check length of vector matches number of parameter in the formula Int_t nPars = paramVec_.size(); if (formula_.GetNpar() != nPars){ std::cerr<<"ERROR in LauFormulaPar::evaluate : Number of parameters in the formula is : "<Exit(EXIT_FAILURE); } if (formula_.GetNdim() != 0){ std::cerr<<"ERROR in LauFormulaPar::evaluate : Given formula of dimension: "<Exit(EXIT_FAILURE); } // Array of input parameters paramArray_ = new Double_t[nPars]; } LauFormulaPar& LauFormulaPar::operator=(const LauFormulaPar& rhs) { if ( &rhs != this ) { name_ = rhs.name_; formula_ = rhs.formula_; Int_t nOldPars = paramVec_.size(); Int_t nNewPars = rhs.paramVec_.size(); paramVec_ = rhs.paramVec_; if ( nOldPars != nNewPars ) { delete [] paramArray_; paramArray_ = new Double_t[nNewPars]; } gaussConstraint_ = rhs.gaussConstraint_; + constraintTrueMean_ = rhs.constraintTrueMean_; constraintMean_ = rhs.constraintMean_; constraintWidth_ = rhs.constraintWidth_; } return *this; } Double_t LauFormulaPar::value() const { //Assign vector values to array Int_t nPars = paramVec_.size(); for(Int_t i=0; ivalue(); } return formula_.EvalPar(nullptr,paramArray_); } Double_t LauFormulaPar::unblindValue() const { //Assign vector values to array Int_t nPars = paramVec_.size(); for(Int_t i=0; iunblindValue(); } return formula_.EvalPar(nullptr,paramArray_); } Double_t LauFormulaPar::genValue() const { //Assign vector values to array Int_t nPars = paramVec_.size(); for(Int_t i=0; igenValue(); } return formula_.EvalPar(nullptr,paramArray_); } Double_t LauFormulaPar::initValue() const { //Assign vector values to array Int_t nPars = paramVec_.size(); for(Int_t i=0; iinitValue(); } return formula_.EvalPar(nullptr,paramArray_); } Bool_t LauFormulaPar::fixed() const { for ( std::vector::const_iterator iter = paramVec_.begin(); iter != paramVec_.end(); ++iter ) { if ( !(*iter)->fixed() ) { return kFALSE; } } return kTRUE; } Bool_t LauFormulaPar::blind() const { for ( std::vector::const_iterator iter = paramVec_.begin(); iter != paramVec_.end(); ++iter ) { if ( (*iter)->blind() ) { return kTRUE; } } return kFALSE; } void LauFormulaPar::addGaussianConstraint(Double_t newGaussMean, Double_t newGaussWidth) { gaussConstraint_ = kTRUE; + constraintTrueMean_ = newGaussMean; constraintMean_ = newGaussMean; constraintWidth_ = newGaussWidth; } void LauFormulaPar::removeGaussianConstraint() { gaussConstraint_ = kFALSE; } +void LauFormulaPar::generateConstraintMean() +{ + constraintMean_ = LauRandom::randomFun()->Gaus( constraintTrueMean_, constraintWidth_ ); +} + +Double_t LauFormulaPar::constraintPenalty() const +{ + const Double_t val { this->unblindValue() }; + const Double_t diff { val - constraintMean_ }; + const Double_t term { diff * diff }; + + return term / ( 2.0 * constraintWidth_ * constraintWidth_ ); +} + diff --git a/src/LauParameter.cc b/src/LauParameter.cc index 70791ca..535e017 100644 --- a/src/LauParameter.cc +++ b/src/LauParameter.cc @@ -1,733 +1,762 @@ /* Copyright 2006 University of Warwick Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /* Laura++ package authors: John Back Paul Harrison Thomas Latham */ /*! \file LauParameter.cc \brief File containing implementation of LauParameter class. */ #include #include using std::cout; using std::cerr; using std::endl; using std::map; #include "TRandom.h" #include "LauParameter.hh" #include "LauRandom.hh" ClassImp(LauParameter) LauParameter::LauParameter() : name_(""), value_(0.0), error_(0.0), negError_(0.0), posError_(0.0), genValue_(0.0), initValue_(0.0), minValue_(0.0), maxValue_(0.0), fixed_(kTRUE), secondStage_(kFALSE), gaussConstraint_(kFALSE), + constraintTrueMean_(0.0), constraintMean_(0.0), constraintWidth_(0.0), gcc_(0.0), bias_(0.0), pull_(0.0), clone_(kFALSE), parent_(0), blinder_(0) { } LauParameter::LauParameter(const TString& parName) : name_(parName), value_(0.0), error_(0.0), negError_(0.0), posError_(0.0), genValue_(0.0), initValue_(0.0), minValue_(0.0), maxValue_(0.0), fixed_(kTRUE), secondStage_(kFALSE), gaussConstraint_(kFALSE), + constraintTrueMean_(0.0), constraintMean_(0.0), constraintWidth_(0.0), gcc_(0.0), bias_(0.0), pull_(0.0), clone_(kFALSE), parent_(0), blinder_(0) { } LauParameter::LauParameter(Double_t parValue) : name_(""), value_(parValue), error_(0.0), negError_(0.0), posError_(0.0), genValue_(parValue), initValue_(parValue), minValue_(parValue-1e-6), maxValue_(parValue+1e-6), fixed_(kTRUE), secondStage_(kFALSE), gaussConstraint_(kFALSE), + constraintTrueMean_(0.0), constraintMean_(0.0), constraintWidth_(0.0), gcc_(0.0), bias_(0.0), pull_(0.0), clone_(kFALSE), parent_(0), blinder_(0) { } LauParameter::LauParameter(const TString& parName, Double_t parValue) : name_(parName), value_(parValue), error_(0.0), negError_(0.0), posError_(0.0), genValue_(parValue), initValue_(parValue), minValue_(parValue-1e-6), maxValue_(parValue+1e-6), fixed_(kTRUE), secondStage_(kFALSE), gaussConstraint_(kFALSE), + constraintTrueMean_(0.0), constraintMean_(0.0), constraintWidth_(0.0), gcc_(0.0), bias_(0.0), pull_(0.0), clone_(kFALSE), parent_(0), blinder_(0) { } LauParameter::LauParameter(Double_t parValue, Double_t min, Double_t max) : name_(""), value_(parValue), error_(0.0), negError_(0.0), posError_(0.0), genValue_(parValue), initValue_(parValue), minValue_(min), maxValue_(max), fixed_(kTRUE), secondStage_(kFALSE), gaussConstraint_(kFALSE), + constraintTrueMean_(0.0), constraintMean_(0.0), constraintWidth_(0.0), gcc_(0.0), bias_(0.0), pull_(0.0), clone_(kFALSE), parent_(0), blinder_(0) { this->checkRange(); } LauParameter::LauParameter(Double_t parValue, Double_t parError, Double_t min, Double_t max) : name_(""), value_(parValue), error_(parError), negError_(0.0), posError_(0.0), genValue_(parValue), initValue_(parValue), minValue_(min), maxValue_(max), fixed_(kTRUE), secondStage_(kFALSE), gaussConstraint_(kFALSE), + constraintTrueMean_(0.0), constraintMean_(0.0), constraintWidth_(0.0), gcc_(0.0), bias_(0.0), pull_(0.0), clone_(kFALSE), parent_(0), blinder_(0) { this->checkRange(); } LauParameter::LauParameter(Double_t parValue, Double_t min, Double_t max, Bool_t parFixed) : name_(""), value_(parValue), error_(0.0), negError_(0.0), posError_(0.0), genValue_(parValue), initValue_(parValue), minValue_(min), maxValue_(max), fixed_(parFixed), secondStage_(kFALSE), gaussConstraint_(kFALSE), + constraintTrueMean_(0.0), constraintMean_(0.0), constraintWidth_(0.0), gcc_(0.0), bias_(0.0), pull_(0.0), clone_(kFALSE), parent_(0), blinder_(0) { this->checkRange(); } LauParameter::LauParameter(const TString& parName, Double_t parValue, Double_t min, Double_t max) : name_(parName), value_(parValue), error_(0.0), negError_(0.0), posError_(0.0), genValue_(parValue), initValue_(parValue), minValue_(min), maxValue_(max), fixed_(kTRUE), secondStage_(kFALSE), gaussConstraint_(kFALSE), + constraintTrueMean_(0.0), constraintMean_(0.0), constraintWidth_(0.0), gcc_(0.0), bias_(0.0), pull_(0.0), clone_(kFALSE), parent_(0), blinder_(0) { this->checkRange(); } LauParameter::LauParameter(const TString& parName, Double_t parValue, Double_t min, Double_t max, Bool_t parFixed) : name_(parName), value_(parValue), error_(0.0), negError_(0.0), posError_(0.0), genValue_(parValue), initValue_(parValue), minValue_(min), maxValue_(max), fixed_(parFixed), secondStage_(kFALSE), gaussConstraint_(kFALSE), + constraintTrueMean_(0.0), constraintMean_(0.0), constraintWidth_(0.0), gcc_(0.0), bias_(0.0), pull_(0.0), clone_(kFALSE), parent_(0), blinder_(0) { this->checkRange(); } LauParameter::LauParameter(const TString& parName, Double_t parValue, Double_t parError, Double_t min, Double_t max) : name_(parName), value_(parValue), error_(parError), negError_(0.0), posError_(0.0), genValue_(parValue), initValue_(parValue), minValue_(min), maxValue_(max), fixed_(kTRUE), secondStage_(kFALSE), gaussConstraint_(kFALSE), + constraintTrueMean_(0.0), constraintMean_(0.0), constraintWidth_(0.0), gcc_(0.0), bias_(0.0), pull_(0.0), clone_(kFALSE), parent_(0), blinder_(0) { this->checkRange(); } LauParameter::LauParameter(const LauParameter& rhs) : TObject(rhs), LauAbsRValue(rhs), name_(rhs.name_), value_(rhs.value_), error_(rhs.error_), negError_(rhs.negError_), posError_(rhs.posError_), genValue_(rhs.genValue_), initValue_(rhs.initValue_), minValue_(rhs.minValue_), maxValue_(rhs.maxValue_), fixed_(rhs.fixed_), secondStage_(rhs.secondStage_), gaussConstraint_(rhs.gaussConstraint_), + constraintTrueMean_(rhs.constraintTrueMean_), constraintMean_(rhs.constraintMean_), constraintWidth_(rhs.constraintWidth_), gcc_(rhs.gcc_), bias_(rhs.bias_), pull_(rhs.pull_), clone_(rhs.clone_), parent_(rhs.parent_), clones_(rhs.clones_), blinder_((rhs.blinder_==0) ? 0 : new LauBlind(*(rhs.blinder_))) { } LauParameter& LauParameter::operator=(const LauParameter& rhs) { if (&rhs != this) { TObject::operator=(rhs); LauAbsRValue::operator=(rhs); name_ = rhs.name_; value_ = rhs.value_; error_ = rhs.error_; negError_ = rhs.negError_; posError_ = rhs.posError_; genValue_ = rhs.genValue_; initValue_ = rhs.initValue_; minValue_ = rhs.minValue_; maxValue_ = rhs.maxValue_; fixed_ = rhs.fixed_; secondStage_ = rhs.secondStage_; gaussConstraint_ = rhs.gaussConstraint_; + constraintTrueMean_ = rhs.constraintTrueMean_; constraintMean_ = rhs.constraintMean_; constraintWidth_ = rhs.constraintWidth_; gcc_ = rhs.gcc_; bias_ = rhs.bias_; pull_ = rhs.pull_; clone_ = rhs.clone_; parent_ = rhs.parent_; clones_ = rhs.clones_; delete blinder_; blinder_ = (rhs.blinder_==0) ? 0 : new LauBlind(*(rhs.blinder_)); } return *this; } LauParameter::~LauParameter() { delete blinder_; } std::vector LauParameter::getPars() { std::vector list; list.push_back(this); return list; } void LauParameter::value(Double_t newValue) { if (this->clone()) { parent_->value(newValue); } else { this->checkRange(newValue,this->minValue(),this->maxValue()); this->updateClones(kTRUE); } } void LauParameter::error(Double_t newError) { if (this->clone()) { parent_->error(newError); } else { error_ = TMath::Abs(newError); this->updateClones(kFALSE); } } void LauParameter::negError(Double_t newNegError) { if (this->clone()) { parent_->negError(newNegError); } else { negError_ = TMath::Abs(newNegError); this->updateClones(kFALSE); } } void LauParameter::posError(Double_t newPosError) { if (this->clone()) { parent_->posError(newPosError); } else { posError_ = TMath::Abs(newPosError); this->updateClones(kFALSE); } } void LauParameter::errors(Double_t newError, Double_t newNegError, Double_t newPosError) { if (this->clone()) { parent_->errors(newError,newNegError,newPosError); } else { error_ = TMath::Abs(newError); negError_ = TMath::Abs(newNegError); posError_ = TMath::Abs(newPosError); this->updateClones(kFALSE); } } void LauParameter::valueAndErrors(Double_t newValue, Double_t newError, Double_t newNegError, Double_t newPosError) { if (this->clone()) { parent_->valueAndErrors(newValue,newError,newNegError,newPosError); } else { this->checkRange(newValue,this->minValue(),this->maxValue()); error_ = TMath::Abs(newError); negError_ = TMath::Abs(newNegError); posError_ = TMath::Abs(newPosError); this->updateClones(kFALSE); } } void LauParameter::globalCorrelationCoeff(Double_t newGCCValue) { if (this->clone()) { parent_->globalCorrelationCoeff(newGCCValue); } else { gcc_ = newGCCValue; this->updateClones(kFALSE); } } void LauParameter::genValue(Double_t newGenValue) { if (this->clone()) { parent_->genValue(newGenValue); } else { genValue_ = newGenValue; this->updateClones(kFALSE); } } void LauParameter::initValue(Double_t newInitValue) { if (this->clone()) { parent_->initValue(newInitValue); } else { initValue_ = newInitValue; this->updateClones(kFALSE); } } void LauParameter::minValue(Double_t newMinValue) { if (this->clone()) { parent_->minValue(newMinValue); } else { this->checkRange(this->value(),newMinValue,this->maxValue()); this->updateClones(kFALSE); } } void LauParameter::maxValue(Double_t newMaxValue) { if (this->clone()) { parent_->maxValue(newMaxValue); } else { this->checkRange(this->value(),this->minValue(),newMaxValue); this->updateClones(kFALSE); } } void LauParameter::range(Double_t newMinValue, Double_t newMaxValue) { if (this->clone()) { parent_->range(newMinValue,newMaxValue); } else { this->checkRange(this->value(),newMinValue,newMaxValue); this->updateClones(kFALSE); } } void LauParameter::valueAndRange(Double_t newValue, Double_t newMinValue, Double_t newMaxValue) { if (this->clone()) { parent_->valueAndRange(newValue,newMinValue,newMaxValue); } else { this->checkRange(newValue,newMinValue,newMaxValue); this->updateClones(kFALSE); } } void LauParameter::name(const TString& newName) { // no need to update clones here // clones are allowed to have different names name_ = newName; } void LauParameter::fixed(Bool_t parFixed) { if (this->clone()) { parent_->fixed(parFixed); } else { fixed_ = parFixed; this->updateClones(kFALSE); } } void LauParameter::secondStage(Bool_t secondStagePar) { if (this->clone()) { parent_->secondStage(secondStagePar); } else { secondStage_ = secondStagePar; this->updateClones(kFALSE); } } void LauParameter::addGaussianConstraint(Double_t newGaussMean, Double_t newGaussWidth) { if (this->clone()) { parent_->addGaussianConstraint(newGaussMean,newGaussWidth); } else { gaussConstraint_ = kTRUE; + constraintTrueMean_ = newGaussMean; constraintMean_ = newGaussMean; constraintWidth_ = newGaussWidth; this->updateClones(kFALSE); } } void LauParameter::removeGaussianConstraint() { if (this->clone()) { parent_->removeGaussianConstraint(); } else { gaussConstraint_ = kFALSE; this->updateClones(kFALSE); } } +void LauParameter::generateConstraintMean() +{ + if (this->clone()) { + parent_->generateConstraintMean(); + } else { + constraintMean_ = LauRandom::randomFun()->Gaus( constraintTrueMean_, constraintWidth_ ); + this->updateClones(kFALSE); + } +} + +Double_t LauParameter::constraintPenalty() const +{ + const Double_t val { this->unblindValue() }; + const Double_t diff { val - constraintMean_ }; + const Double_t term { diff * diff }; + + return term / ( 2.0 * constraintWidth_ * constraintWidth_ ); +} + void LauParameter::blindParameter(const TString& blindingString, const Double_t width) { if (this->clone()) { parent_->blindParameter(blindingString,width); return; } if ( blinder_ != 0 ) { std::cerr << "WARNING in LauParameter::blindParameter : blinding has already been set up for this parameter" << std::endl; return; } blinder_ = new LauBlind(blindingString,width); for (map::iterator iter = clones_.begin(); iter != clones_.end(); ++iter) { LauParameter* clonePar = iter->first; if ( clonePar->blinder_ != 0 ) { std::cerr << "WARNING in LauParameter::blindParameter : blinding has already been set up for a clone of this parameter - it will be replaced!" << std::endl; delete clonePar->blinder_; clonePar->blinder_ = 0; } clonePar->blinder_ = new LauBlind(*blinder_); } } void LauParameter::updatePull() { if (this->clone()) { parent_->updatePull(); return; } // calculate the bias bias_ = value_ - genValue_; // if we have errors calculated then calculate // the pull using the best error available if ((bias_ > 0.0) && (negError_ > 1e-10)) { pull_ = bias_ / negError_; } else if ((bias_ < 0.0) && (posError_ > 1e-10)) { pull_ = bias_ / posError_; } else if (error_ > 1e-10) { pull_ = bias_ / error_; } else { pull_ = 0.0; } this->updateClones(kFALSE); } void LauParameter::checkRange(Double_t val, Double_t minVal, Double_t maxVal) { // first check that min is less than max (or they are the same - this is allowed) if (minVal > maxVal) { cerr<<"ERROR in LauParameter::checkRange : minValue: "< maxValue_) { minValue_ = maxValue_; cerr<<" : Setting both to "< maxVal)) { if (name_ != "") { cerr<<"ERROR in LauParameter::checkRange : value: "<clone()) { LauParameter* clonePar = parent_->createClone(constFactor); clonePar->name(this->name()); return clonePar; } // clone ourselves using the copy-constructor LauParameter* clonePar = new LauParameter(*this); Double_t newValue = clonePar->value() * constFactor; clonePar->value( newValue ); clonePar->wipeClones(); clonePar->clone(this); clones_.insert( std::make_pair( clonePar, constFactor ) ); return clonePar; } LauParameter* LauParameter::createClone(const TString& newName, Double_t constFactor) { // self message to create the clone LauParameter* clonePar = this->createClone(constFactor); // set the new name clonePar->name(newName); // and return return clonePar; } void LauParameter::updateClones(Bool_t justValue) { // if we don't have any clones then there's nothing to do if ( clones_.empty() ) { return; } // we have to set the values directly rather than using member functions because otherwise we'd get into an infinite loop if (justValue) { - for (map::iterator iter = clones_.begin(); iter != clones_.end(); ++iter) { - LauParameter* clonePar = iter->first; - Double_t constFactor = iter->second; - clonePar->value_ = constFactor*this->value(); + for ( auto& [ clonePar, constFactor ] : clones_ ) { + clonePar->value_ = constFactor * value_; } } else { - for (map::iterator iter = clones_.begin(); iter != clones_.end(); ++iter) { - LauParameter* clonePar = iter->first; - Double_t constFactor = iter->second; - clonePar->value_ = constFactor*this->value(); - clonePar->error_ = constFactor*this->error(); - clonePar->negError_ = constFactor*this->negError(); - clonePar->posError_ = constFactor*this->posError(); - clonePar->genValue_ = constFactor*this->genValue(); - clonePar->initValue_ = constFactor*this->initValue(); - clonePar->minValue_ = constFactor*this->minValue(); - clonePar->maxValue_ = constFactor*this->maxValue(); - clonePar->fixed_ = this->fixed(); - clonePar->secondStage_ = this->secondStage(); - clonePar->gaussConstraint_ = this->gaussConstraint(); - clonePar->constraintMean_ = this->constraintMean(); - clonePar->constraintWidth_ = this->constraintWidth(); - clonePar->gcc_ = this->globalCorrelationCoeff(); - clonePar->bias_ = this->bias(); - clonePar->pull_ = this->pull(); + for ( auto& [ clonePar, constFactor ] : clones_ ) { + clonePar->value_ = constFactor * value_; + clonePar->error_ = constFactor * error_; + clonePar->negError_ = constFactor * negError_; + clonePar->posError_ = constFactor * posError_; + clonePar->genValue_ = constFactor * genValue_; + clonePar->initValue_ = constFactor * initValue_; + clonePar->minValue_ = constFactor * minValue_; + clonePar->maxValue_ = constFactor * maxValue_; + clonePar->fixed_ = fixed_; + clonePar->secondStage_ = secondStage_; + clonePar->gaussConstraint_ = gaussConstraint_; + clonePar->constraintTrueMean_ = constraintTrueMean_; + clonePar->constraintMean_ = constraintMean_; + clonePar->constraintWidth_ = constraintWidth_; + clonePar->gcc_ = gcc_; + clonePar->bias_ = bias_; + clonePar->pull_ = pull_; } } } void LauParameter::randomiseValue() { this->randomiseValue(this->minValue(), this->maxValue()); } void LauParameter::randomiseValue(Double_t minVal, Double_t maxVal) { // if we're fixed then do nothing if (this->fixed()) { return; } // check supplied values are sensible if (maxVal < minVal) { cerr<<"ERROR in LauParameter::randomiseValue : Supplied maximum value smaller than minimum value."< this->maxValue()) { maxVal = this->maxValue(); } if (minVal < this->minValue()) { minVal = this->minValue(); } // use the zero-seed random number generator to get values that are // uniformly distributed over the given range Double_t randNo = LauRandom::zeroSeedRandom()->Rndm(); Double_t val = randNo*(maxVal - minVal) + minVal; this->initValue(val); } // ostream operator std::ostream& operator << (std::ostream& stream, const LauParameter& par) { stream << par.value(); return stream; } diff --git a/src/LauSimFitCoordinator.cc b/src/LauSimFitCoordinator.cc index 99c153b..eddb02c 100644 --- a/src/LauSimFitCoordinator.cc +++ b/src/LauSimFitCoordinator.cc @@ -1,1082 +1,1065 @@ /* Copyright 2013 University of Warwick Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /* Laura++ package authors: John Back Paul Harrison Thomas Latham */ /*! \file LauSimFitCoordinator.cc \brief File containing implementation of LauSimFitCoordinator class. */ #include #include #include #include "TMath.h" #include "TMatrixD.h" #include "TMessage.h" #include "TMonitor.h" #include "TObjArray.h" #include "TObjString.h" #include "TServerSocket.h" #include "TSocket.h" #include "TSystem.h" #include "LauAbsFitter.hh" #include "LauFitNtuple.hh" #include "LauFitter.hh" #include "LauFormulaPar.hh" #include "LauParameter.hh" #include "LauParamFixed.hh" #include "LauSimFitCoordinator.hh" ClassImp(LauSimFitCoordinator) LauSimFitCoordinator::LauSimFitCoordinator( UInt_t numTasks, UInt_t port ) : nTasks_(numTasks), reqPort_(port), socketMonitor_(0), messageFromTask_(0), fitNtuple_(0) { messagesToTasks_.resize( nTasks_ ); for ( UInt_t iTask(0); iTask < nTasks_; ++iTask ) { messagesToTasks_[iTask] = new TMessage(); } } LauSimFitCoordinator::~LauSimFitCoordinator() { delete socketMonitor_; socketMonitor_ = 0; // Tell all tasks that they are finished and delete corresponding socket TString msgStr("Finish"); TMessage message( kMESS_STRING ); message.WriteTString(msgStr); for ( std::vector::iterator iter = socketTasks_.begin(); iter != socketTasks_.end(); ++iter ) { (*iter)->Send(message); (*iter)->Close(); delete (*iter); } socketTasks_.clear(); - // Remove the components created to apply constraints to fit parameters - for (std::vector::iterator iter = conVars_.begin(); iter != conVars_.end(); ++iter){ - if ( !(*iter)->isLValue() ){ - delete (*iter); - (*iter) = 0; - } - } - conVars_.clear(); - // Remove all fit parameters for ( std::vector::iterator iter = params_.begin(); iter != params_.end(); ++iter ) { delete *iter; } params_.clear(); for ( std::vector::iterator iter = vectorPar_.begin(); iter != vectorPar_.end(); ++iter ) { delete[] (*iter); } vectorPar_.clear(); delete messageFromTask_; messageFromTask_ = 0; for ( std::vector::iterator iter = messagesToTasks_.begin(); iter != messagesToTasks_.end(); ++iter ) { delete (*iter); } messagesToTasks_.clear(); delete fitNtuple_; } void LauSimFitCoordinator::initSockets() { if ( socketMonitor_ != 0 ) { std::cerr << "ERROR in LauSimFitCoordinator::initSockets : Sockets already initialised." << std::endl; return; } //initialise socket connection, then accept a connection and return a full-duplex communication socket. socketMonitor_ = new TMonitor(); TServerSocket *ss = new TServerSocket( reqPort_, kFALSE ); UInt_t actual_port = ss->GetLocalPort(); std::cout << "INFO in LauSimFitCoordinator::initSockets : Waiting for connection with " << nTasks_ << " tasks on port " << actual_port << std::endl; socketTasks_.resize(nTasks_); for ( UInt_t iTask(0); iTaskAccept(); std::cout << " : Added task " << iTask << std::endl; } // tell the clients to start std::cout << "INFO in LauSimFitCoordinator::initSockets : Initialising tasks" << std::endl; for ( UInt_t iTask(0); iTaskuseAsymmFitErrors()); socketTasks_[iTask]->Send(message); socketMonitor_->Add(socketTasks_[iTask]); } std::cout << " : Now start fit\n" << std::endl; ss->Close(); delete ss; } /* * OLD VERSION THAT JUST GETS THE NAMES - COULD HAVE A SERIES OF EXCHANGES TO GET THE NAMES, INIT VALUES, RANGES, ETC. INSTEAD OF PASSING PARAMETERS * THIS INCREASES THE GENERALITY OF THE CODE, I.E. THERE IS NO NEED FOR THE TASKS TO KNOW ANY LAURA++ CLASS BUT THIS ONE, BUT MAKES IT RATHER MORE DENSE * FOR THE MOMENT I WILL STICK WITH THE METHOD OF PASSING LAUPARAMETER OBJECTS AROUND AND CONSIDER GOING BACK TO THIS GENERAL METHOD ONCE EVERYTHING IS WORKING * void LauSimFitCoordinator::getParametersFromTasksFirstTime() { taskIndices_.resize( nTasks_ ); TSocket* sActive(0); for ( UInt_t iTask(0); iTaskSend(message); // Wait to receive the response and check that it has come from the task we just requested from sActive = socketMonitor_->Select(); if ( sActive != socketTasks_[iTask] ) { std::cerr << "ERROR in LauSimFitCoordinator::getParametersFromTasksFirstTime : Received message from a different task than expected!" << std::endl; gSystem->Exit(1); } // Read the object and extract the parameter names socketTasks_[iTask]->Recv( messageFromTask_ ); TObjArray * objarray = dynamic_cast( messageFromTask_->ReadObject( messageFromTask_->GetClass() ) ); if ( ! objarray ) { std::cerr << "ERROR in LauSimFitCoordinator::getParametersFromTasksFirstTime : Error reading parameter names from task" << std::endl; gSystem->Exit(1); } Int_t nPars = objarray->GetEntries(); for ( Int_t iPar(0); iPar < nPars; ++iPar ) { TObjString* objstring = dynamic_cast( (*objarray)[iPar] ); if ( ! objstring ) { std::cerr << "ERROR in LauSimFitCoordinator::getParametersFromTasksFirstTime : Error reading parameter names from task" << std::endl; gSystem->Exit(1); } TString parname = objstring->GetString(); std::map< TString, UInt_t >::iterator iter = parIndices_.find( parname ); if ( iter != parIndices_.end() ) { UInt_t index = iter->second; taskIndices_[iTask].push_back( index ); } else { UInt_t index = parIndices_.size(); parIndices_.insert( std::make_pair( parname, index ) ); parNames_.insert( std::make_pair( index, parname ) ); taskIndices_[iTask].push_back( index ); } } delete objarray; objarray = 0; delete messageFromTask_; messageFromTask_ = 0; } UInt_t nPars = parNames_.size(); parValues_.resize( nPars ); } */ void LauSimFitCoordinator::getParametersFromTasks() { if ( socketMonitor_ == 0 ) { std::cerr << "ERROR in LauSimFitCoordinator::getParametersFromTasks : Sockets not initialised." << std::endl; return; } if ( params_.empty() ) { this->getParametersFromTasksFirstTime(); // Add variables to Gaussian constrain to a list this->addConParameters(); } else { this->updateParametersFromTasks(); } } void LauSimFitCoordinator::updateParametersFromTasks() { TSocket* sActive(0); // Construct a message, requesting the list of parameter names TString msgStr = "Send Parameters"; TMessage message( kMESS_STRING ); message.WriteTString( msgStr ); for ( UInt_t iTask(0); iTaskSend(message); // Wait to receive the response and check that it has come from the task we just requested from sActive = socketMonitor_->Select(); if ( sActive != socketTasks_[iTask] ) { std::cerr << "ERROR in LauSimFitCoordinator::updateParametersFromTasks : Received message from a different task than expected!" << std::endl; gSystem->Exit(1); } // Read the object and extract the parameter names socketTasks_[iTask]->Recv( messageFromTask_ ); TObjArray * objarray = dynamic_cast( messageFromTask_->ReadObject( messageFromTask_->GetClass() ) ); if ( ! objarray ) { std::cerr << "ERROR in LauSimFitCoordinator::updateParametersFromTasks : Error reading parameter names from task" << std::endl; gSystem->Exit(1); } // We want to auto-delete the supplied parameters since we only copy their values in this case objarray->SetOwner(kTRUE); const UInt_t nPars = objarray->GetEntries(); if ( nPars != taskIndices_[iTask].size() ) { std::cerr << "ERROR in LauSimFitCoordinator::updateParametersFromTasks : Unexpected number of parameters received from task" << std::endl; gSystem->Exit(1); } for ( UInt_t iPar(0); iPar < nPars; ++iPar ) { LauParameter* parameter = dynamic_cast( (*objarray)[iPar] ); if ( ! parameter ) { std::cerr << "ERROR in LauSimFitCoordinator::updateParametersFromTasks : Error reading parameter from task" << std::endl; gSystem->Exit(1); } TString parname = parameter->name(); Double_t parvalue = parameter->initValue(); std::map< TString, UInt_t >::iterator iter = parIndices_.find( parname ); if ( iter == parIndices_.end() ) { std::cerr << "ERROR in LauSimFitCoordinator::updateParametersFromTasks : Unexpected parameter name received from task" << std::endl; gSystem->Exit(1); } const UInt_t index = iter->second; if ( taskIndices_[iTask][iPar] != index ) { std::cerr << "ERROR in LauSimFitCoordinator::updateParametersFromTasks : Unexpected parameter received from task" << std::endl; gSystem->Exit(1); } params_[index]->initValue( parvalue ); parValues_[index] = parvalue; vectorPar_[iTask][iPar] = parvalue; this->checkParameter( parameter, index ); } delete objarray; objarray = 0; delete messageFromTask_; messageFromTask_ = 0; } } void LauSimFitCoordinator::getParametersFromTasksFirstTime() { taskIndices_.resize( nTasks_ ); taskFreeIndices_.resize( nTasks_ ); vectorPar_.resize( nTasks_ ); vectorRes_.resize( nTasks_ ); TSocket* sActive(0); // Construct a message, requesting the list of parameter names TString msgStr = "Send Parameters"; TMessage message( kMESS_STRING ); message.WriteTString( msgStr ); for ( UInt_t iTask(0); iTaskSend(message); // Wait to receive the response and check that it has come from the task we just requested from sActive = socketMonitor_->Select(); if ( sActive != socketTasks_[iTask] ) { std::cerr << "ERROR in LauSimFitCoordinator::getParametersFromTasksFirstTime : Received message from a different task than expected!" << std::endl; gSystem->Exit(1); } // Read the object and extract the parameter names socketTasks_[iTask]->Recv( messageFromTask_ ); TObjArray * objarray = dynamic_cast( messageFromTask_->ReadObject( messageFromTask_->GetClass() ) ); if ( ! objarray ) { std::cerr << "ERROR in LauSimFitCoordinator::getParametersFromTasksFirstTime : Error reading parameters from task" << std::endl; gSystem->Exit(1); } const UInt_t nPars = objarray->GetEntries(); vectorPar_[iTask] = new Double_t[nPars]; for ( UInt_t iPar(0); iPar < nPars; ++iPar ) { LauParameter* parameter = dynamic_cast( (*objarray)[iPar] ); if ( ! parameter ) { std::cerr << "ERROR in LauSimFitCoordinator::getParametersFromTasksFirstTime : Error reading parameter from task" << std::endl; gSystem->Exit(1); } TString parname = parameter->name(); Double_t parvalue = parameter->initValue(); Bool_t parfixed = parameter->fixed(); std::map< TString, UInt_t >::iterator iter = parIndices_.find( parname ); if ( iter != parIndices_.end() ) { UInt_t index = iter->second; taskIndices_[iTask].push_back( index ); if ( ! parfixed ) { taskFreeIndices_[iTask].push_back( index ); } this->checkParameter( parameter, index ); } else { UInt_t index = parIndices_.size(); parIndices_.insert( std::make_pair( parname, index ) ); parNames_.insert( std::make_pair( index, parname ) ); taskIndices_[iTask].push_back( index ); if ( ! parfixed ) { taskFreeIndices_[iTask].push_back( index ); } params_.push_back( parameter ); parValues_.push_back( parvalue ); } vectorPar_[iTask][iPar] = parvalue; } delete objarray; objarray = 0; delete messageFromTask_; messageFromTask_ = 0; } } void LauSimFitCoordinator::printParInfo() const { for ( UInt_t iTask(0); iTask& indices = taskIndices_[iTask]; std::cout << "INFO in LauSimFitCoordinator::printParInfo : Task " << iTask << " has the following parameters:\n"; for ( std::vector::const_iterator iter = indices.begin(); iter != indices.end(); ++iter ) { const TString& parName = parNames_.find(*iter)->second; Double_t parValue = parValues_[*iter]; const LauParameter* par = params_[*iter]; if ( par->name() != parName || par->initValue() != parValue ) { std::cerr << "ERROR in LauSimFitCoordinator::printParInfo : Discrepancy in parameter name and value records, this is very strange!!" << std::endl; } std::cout << " : " << parName << " = " << parValue << " and has index " << *iter << "\n"; } std::cout << std::endl; } std::cout << "INFO in LauSimFitCoordinator::printParInfo : " << "There are " << params_.size() << " parameters in total" << std::endl; } void LauSimFitCoordinator::checkParameter( const LauParameter* param, UInt_t index ) const { const LauParameter* storedPar = params_[index]; TString parName = storedPar->name(); if ( param->name() != parName ) { std::cerr << "ERROR in LauSimFitCoordinator::checkParameter : Parameter name is different!! This shouldn't happen!!" << std::endl; } if ( param->initValue() != storedPar->initValue() ) { std::cerr << "WARNING in LauSimFitCoordinator::checkParameter : Initial value for parameter " << parName << " is different, will use the value first set: " << storedPar->initValue() << std::endl; } if ( param->minValue() != storedPar->minValue() ) { std::cerr << "WARNING in LauSimFitCoordinator::checkParameter : Minimum allowed value for parameter " << parName << " is different, will use the value first set: " << storedPar->minValue() << std::endl; } if ( param->maxValue() != storedPar->maxValue() ) { std::cerr << "WARNING in LauSimFitCoordinator::checkParameter : Maximum allowed value for parameter " << parName << " is different, will use the value first set: " << storedPar->maxValue() << std::endl; } if ( param->fixed() != storedPar->fixed() ) { std::cerr << "WARNING in LauSimFitCoordinator::checkParameter : Fixed/floating property of parameter " << parName << " is different, will use the value first set: " << (storedPar->fixed() ? "fixed" : "floating") << std::endl; } if ( param->secondStage() != storedPar->secondStage() ) { std::cerr << "WARNING in LauSimFitCoordinator::checkParameter : Second stage property of parameter " << parName << " is different, will use the value first set: " << (storedPar->secondStage() ? "true" : "false") << std::endl; } } void LauSimFitCoordinator::initialise() { this->initSockets(); } void LauSimFitCoordinator::runSimFit( const TString& fitNtupleFileName, const UInt_t nExp, const UInt_t firstExp, const Bool_t useAsymmErrors, const Bool_t doTwoStageFit ) { // Routine to perform the total fit. // First, initialise this->useAsymmFitErrors(useAsymmErrors); this->twoStageFit(doTwoStageFit); this->initialise(); std::cout << "INFO in LauSimFitCoordinator::runSimFit : First experiment = " << firstExp << std::endl; std::cout << "INFO in LauSimFitCoordinator::runSimFit : Number of experiments = " << nExp << std::endl; // Start the cumulative timer cumulTimer_.Start(); this->resetFitCounters(); // Create and setup the fit results ntuple std::cout << "INFO in LauSimFitCoordinator::runSimFit : Creating fit ntuple." << std::endl; if (fitNtuple_ != 0) {delete fitNtuple_; fitNtuple_ = 0;} fitNtuple_ = new LauFitNtuple(fitNtupleFileName, useAsymmErrors); // Loop over the number of experiments for (UInt_t iExp = firstExp; iExp < (firstExp+nExp); ++iExp) { // Start the timer to see how long each fit takes timer_.Start(); this->setCurrentExperiment( iExp ); // Instruct the tasks to read the data for this experiment Bool_t readOK = this->readData(); if ( ! readOK ) { std::cerr << "ERROR in LauSimFitCoordinator::runSimFit : One or more tasks reported problems with reading data for experiment " << iExp << ", skipping..." << std::endl; timer_.Stop(); continue; } // Instruct the tasks to perform the caching this->cacheInputData(); + // If we're fitting toy experiments then re-generate the means of any constraints + this->generateConstraintMeans( conVars_ ); + // Do the fit this->fitExpt(); // Stop the timer and see how long the program took so far timer_.Stop(); timer_.Print(); // Instruct the tasks to finalise the results this->finalise(); } // Print out total timing info. std::cout << "INFO in LauSimFitCoordinator::runSimFit : Cumulative timing:" << std::endl; cumulTimer_.Stop(); cumulTimer_.Print(); // Print out stats on OK fits. const UInt_t nOKFits = this->numberOKFits(); const UInt_t nBadFits = this->numberBadFits(); std::cout << "INFO in LauSimFitCoordinator::runSimFit : Number of OK Fits = " << nOKFits << std::endl; std::cout << "INFO in LauSimFitCoordinator::runSimFit : Number of Failed Fits = " << nBadFits << std::endl; Double_t fitEff(0.0); if (nExp != 0) {fitEff = nOKFits/(1.0*nExp);} std::cout << "INFO in LauSimFitCoordinator::runSimFit : Fit efficiency = " << fitEff*100.0 << "%." << std::endl; // Instruct the tasks to write out any fit results (ntuples etc...). this->writeOutResults(); } void LauSimFitCoordinator::withinAsymErrorCalc(const Bool_t inAsymErrCalc) { this->LauFitObject::withinAsymErrorCalc(inAsymErrCalc); if ( socketMonitor_ == 0 ) { std::cerr << "ERROR in LauSimFitCoordinator::withinAsymErrorCalc : Sockets not initialised." << std::endl; return; } // Construct a message, informing the tasks whether or not we are now within the asymmetric error calculation TString msgStr("Asym Error Calc"); const Bool_t asymErrorCalc( this->withinAsymErrorCalc() ); TMessage message( kMESS_STRING ); message.WriteTString( msgStr ); message.WriteBool( asymErrorCalc ); // Send the message to the tasks for ( UInt_t iTask(0); iTaskSend(message); } TSocket* sActive(0); UInt_t responsesReceived(0); while ( responsesReceived != nTasks_ ) { // Get the next queued response sActive = socketMonitor_->Select(); // Extract from the message the ID of the task and the number of events read Bool_t response(kTRUE); UInt_t iTask(0); sActive->Recv( messageFromTask_ ); messageFromTask_->ReadUInt( iTask ); messageFromTask_->ReadBool( response ); if ( response != asymErrorCalc ) { std::cerr << "WARNING in LauSimFitCoordinator::withinAsymErrorCalc : Problem informing task " << iTask << std::endl; } ++responsesReceived; } } Bool_t LauSimFitCoordinator::readData() { if ( socketMonitor_ == 0 ) { std::cerr << "ERROR in LauSimFitCoordinator::readData : Sockets not initialised." << std::endl; return kFALSE; } // Construct a message, requesting to read the data for the given experiment TString msgStr("Read Expt"); const UInt_t iExp( this->iExpt() ); TMessage message( kMESS_STRING ); message.WriteTString( msgStr ); message.WriteUInt( iExp ); // Send the message to the tasks for ( UInt_t iTask(0); iTaskSend(message); } TSocket* sActive(0); UInt_t responsesReceived(0); Bool_t ok(kTRUE); while ( responsesReceived != nTasks_ ) { // Get the next queued response sActive = socketMonitor_->Select(); // Extract from the message the ID of the task and the number of events read sActive->Recv( messageFromTask_ ); UInt_t iTask(0); UInt_t nEvents(0); messageFromTask_->ReadUInt( iTask ); messageFromTask_->ReadUInt( nEvents ); if ( nEvents <= 0 ) { std::cerr << "ERROR in LauSimFitCoordinator::readData : Task " << iTask << " reports no events found for experiment " << iExp << std::endl; ok = kFALSE; } else { std::cerr << "INFO in LauSimFitCoordinator::readData : Task " << iTask << " reports " << nEvents << " events found for experiment " << iExp << std::endl; } ++responsesReceived; } return ok; } Bool_t LauSimFitCoordinator::cacheInputData() { if ( socketMonitor_ == 0 ) { std::cerr << "ERROR in LauSimFitCoordinator::cacheInputData : Sockets not initialised." << std::endl; return kFALSE; } // Construct a message, requesting it to read the data for the given experiment TString msgStr("Cache"); TMessage message( kMESS_STRING ); message.WriteTString( msgStr ); for ( UInt_t iTask(0); iTaskSend(message); } TSocket* sActive(0); UInt_t responsesReceived(0); Bool_t allOK(kTRUE); while ( responsesReceived != nTasks_ ) { // Get the next queued response sActive = socketMonitor_->Select(); // Extract from the message the ID of the task and the success/failure flag sActive->Recv( messageFromTask_ ); UInt_t iTask(0); Bool_t ok(kTRUE); messageFromTask_->ReadUInt( iTask ); messageFromTask_->ReadBool( ok ); if ( ! ok ) { std::cerr << "ERROR in LauSimFitCoordinator::cacheInputData : Task " << iTask << " reports an error performing caching" << std::endl; allOK = kFALSE; } ++responsesReceived; } return allOK; } void LauSimFitCoordinator::checkInitFitParams() { this->getParametersFromTasks(); this->printParInfo(); } void LauSimFitCoordinator::fitExpt() { // Routine to perform the actual fit for the given experiment // Instruct the tasks to update initial fit parameters if required (e.g. if using random numbers). this->checkInitFitParams(); // Initialise the fitter LauFitter::fitter().useAsymmFitErrors( this->useAsymmFitErrors() ); LauFitter::fitter().twoStageFit( this->twoStageFit() ); LauFitter::fitter().initialise( this, params_ ); this->startNewFit( LauFitter::fitter().nParameters(), LauFitter::fitter().nFreeParameters() ); // Now ready for minimisation step std::cout << "\nINFO in LauSimFitCoordinator::fitExpt : Start minimisation...\n"; LauAbsFitter::FitStatus fitResult = LauFitter::fitter().minimise(); // If we're doing a two stage fit we can now release (i.e. float) // the 2nd stage parameters and re-fit if (this->twoStageFit()) { if ( fitResult.status != 3 ) { std::cerr << "ERROR in LauSimFitCoordinator:fitExpt : Not running second stage fit since first stage failed." << std::endl; LauFitter::fitter().releaseSecondStageParameters(); } else { LauFitter::fitter().releaseSecondStageParameters(); this->startNewFit( LauFitter::fitter().nParameters(), LauFitter::fitter().nFreeParameters() ); fitResult = LauFitter::fitter().minimise(); } } const TMatrixD& covMat = LauFitter::fitter().covarianceMatrix(); this->storeFitStatus( fitResult, covMat ); // Store the final fit results and errors into protected internal vectors that // all sub-classes can use within their own finalFitResults implementation // used below (e.g. putting them into an ntuple in a root file) LauFitter::fitter().updateParameters(); } void LauSimFitCoordinator::setParsFromMinuit(Double_t* par, Int_t npar) { // This function sets the internal parameters based on the values // that Minuit is using when trying to minimise the total likelihood function. // MINOS reports different numbers of free parameters depending on the // situation, so disable this check if ( ! this->withinAsymErrorCalc() ) { const UInt_t nFreePars = this->nFreeParams(); if (static_cast(npar) != nFreePars) { std::cerr << "ERROR in LauSimFitCoordinator::setParsFromMinuit : Unexpected number of free parameters: " << npar << ".\n"; std::cerr << " Expected: " << nFreePars << ".\n" << std::endl; gSystem->Exit(EXIT_FAILURE); } } // Despite npar being the number of free parameters // the par array actually contains all the parameters, // free and floating... // Update all the parameters with their new values. // Change the value in the array to be sent out to the tasks and the // parameters themselves (so that constraints are correctly calculated) for (UInt_t i(0); inTotParams(); ++i) { if (!params_[i]->fixed()) { parValues_[i] = par[i]; params_[i]->value(par[i]); } } } Double_t LauSimFitCoordinator::getTotNegLogLikelihood() { if ( socketMonitor_ == 0 ) { std::cerr << "ERROR in LauSimFitCoordinator::getTotNegLogLikelihood : Sockets not initialised." << std::endl; return 0.0; } // Send current values of the parameters to the tasks. for ( UInt_t iTask(0); iTask& indices = taskIndices_[iTask]; std::vector& freeIndices = taskFreeIndices_[iTask]; UInt_t nPars = indices.size(); UInt_t nFreePars = freeIndices.size(); for ( UInt_t iPar(0); iPar < nPars; ++iPar ) { vectorPar_[iTask][iPar] = parValues_[ indices[iPar] ]; } TMessage* message = messagesToTasks_[iTask]; message->Reset( kMESS_ANY ); message->WriteUInt( nPars ); message->WriteUInt( nFreePars ); message->WriteFastArray( vectorPar_[iTask], nPars ); socketTasks_[iTask]->Send(*message); } Double_t negLogLike(0.0); TSocket *sActive(0); UInt_t responsesReceived(0); Bool_t allOK(kTRUE); while ( responsesReceived != nTasks_ ) { sActive = socketMonitor_->Select(); sActive->Recv(messageFromTask_); messageFromTask_->ReadDouble( vectorRes_[responsesReceived] ); Double_t& nLL = vectorRes_[responsesReceived]; if ( nLL == 0.0 || TMath::IsNaN(nLL) || !TMath::Finite(nLL) ) { allOK = kFALSE; } negLogLike += vectorRes_[responsesReceived]; ++responsesReceived; } // Calculate any penalty terms from Gaussian constrained variables - if ( ! conVars_.empty() ){ + const auto& multiDimCons = this->multiDimConstraints(); + if ( ! conVars_.empty() || ! multiDimCons.empty() ){ negLogLike += this->getLogLikelihoodPenalty(); } const Double_t worstNegLogLike = -1.0*this->worstLogLike(); if ( ! allOK ) { std::cerr << "WARNING in LauSimFitCoordinator::getTotNegLogLikelihood : Strange NLL value returned by one or more tasks\n"; std::cerr << " : Returning worst NLL found so far to force MINUIT out of this region." << std::endl; negLogLike = worstNegLogLike; } else if ( negLogLike > worstNegLogLike ) { this->worstLogLike( -negLogLike ); } return negLogLike; } Double_t LauSimFitCoordinator::getLogLikelihoodPenalty() { - Double_t penalty(0.0); + Double_t penalty{0.0}; for ( LauAbsRValue* par : conVars_ ) { - Double_t val = par->unblindValue(); - Double_t mean = par->constraintMean(); - Double_t width = par->constraintWidth(); - - Double_t term = ( val - mean )*( val - mean ); - penalty += term/( 2*width*width ); + penalty += par->constraintPenalty(); } - std::vector& storeNDCon = this->NDConstraintsStore(); - for ( ULong_t i = 0; i& params = storeNDCon[i].conLauPars_; - - for ( ULong_t j = 0; junblindValue(); - } - TVectorD diff = storeNDCon[i].values_-storeNDCon[i].means_; - penalty += 0.5*storeNDCon[i].invCovMat_.Similarity(diff); + auto& multiDimCons = this->multiDimConstraints(); + for ( auto& constraint : multiDimCons ) { + penalty += constraint.constraintPenalty(); } return penalty; } void LauSimFitCoordinator::addConParameters() { // Add penalties from the constraints to fit parameters // First, constraints on the fit parameters themselves - for ( std::vector::const_iterator iter = params_.begin(); iter != params_.end(); ++iter ) { - if ( (*iter)->gaussConstraint() ) { - conVars_.push_back( *iter ); - std::cout << "INFO in LauSimFitCoordinator::addConParameters : Added Gaussian constraint to parameter "<< (*iter)->name() << std::endl; + for ( LauParameter* param : params_ ) { + if ( param->gaussConstraint() ) { + conVars_.push_back( param ); + std::cout << "INFO in LauSimFitCoordinator::addConParameters : Added Gaussian constraint to parameter "<< param->name() << std::endl; } } // Second, constraints on arbitrary combinations - const std::vector& storeCon = this->constraintsStore(); - for ( std::vector::const_iterator iter = storeCon.begin(); iter != storeCon.end(); ++iter ) { - const std::vector& names = (*iter).conPars_; + auto& conStore = this->formulaConstraints(); + for ( auto& constraint : conStore ) { std::vector params; - for ( std::vector::const_iterator iternames = names.begin(); iternames != names.end(); ++iternames ) { - for ( std::vector::const_iterator iterfit = params_.begin(); iterfit != params_.end(); ++iterfit ) { - if ( (*iternames) == (*iterfit)->name() ){ - params.push_back(*iterfit); + for ( const auto& name : constraint.conPars_ ) { + for ( LauParameter* par : params_ ) { + if ( par->name() == name ){ + params.push_back( par ); } } } // If the parameters are not found, skip it - if ( params.size() != (*iter).conPars_.size() ) { + if ( params.size() != constraint.conPars_.size() ) { std::cerr << "WARNING in LauSimFitCoordinator::addConParameters: Could not find parameters to constrain in the formula... skipping" << std::endl; continue; } - LauFormulaPar* formPar = new LauFormulaPar( (*iter).formula_, (*iter).formula_, params ); - formPar->addGaussianConstraint( (*iter).mean_, (*iter).width_ ); - conVars_.push_back(formPar); + constraint.formulaPar_ = std::make_unique( constraint.formula_, constraint.formula_, params ); + constraint.formulaPar_->addGaussianConstraint( constraint.mean_, constraint.width_ ); + + conVars_.push_back( constraint.formulaPar_.get() ); std::cout << "INFO in LauSimFitCoordinator::addConParameters : Added Gaussian constraint to formula\n"; - std::cout << " : Formula: " << (*iter).formula_ << std::endl; - for ( std::vector::iterator iterparam = params.begin(); iterparam != params.end(); ++iterparam ) { - std::cout << " : Parameter: " << (*iterparam)->name() << std::endl; + std::cout << " : Formula: " << constraint.formula_ << std::endl; + for ( LauParameter* param : params ) { + std::cout << " : Parameter: " << param->name() << std::endl; } } - // Add n-dimensional constraints - std::vector& storeNDCon = this->NDConstraintsStore(); - for ( auto& constraint : storeNDCon ){ + // Thirdly, add n-dimensional constraints + auto& multiDimCons = this->multiDimConstraints(); + for ( auto& constraint : multiDimCons ){ for ( auto& parname : constraint.conPars_ ){ for ( auto& fitPar : params_ ){ if ( parname == fitPar->name() ){ // Check parameters do not have a 1D Gaussian constraint applied if ( fitPar->gaussConstraint() ){ std::cerr << "ERROR in LauAbsFitModel::addConParameters: parameter in n-dimensional constraint already has a 1d constraint applied" << std::endl; gSystem->Exit(EXIT_FAILURE); } constraint.conLauPars_.push_back(fitPar); } } } if ( constraint.conLauPars_.size() != constraint.conPars_.size() ){ std::cerr << "Error in LauAbsFitModel::addConParameters : Could not match parameter names for n-dimensional constraint" << std::endl; gSystem->Exit(EXIT_FAILURE); } } } Bool_t LauSimFitCoordinator::finalise() { if ( socketMonitor_ == 0 ) { std::cerr << "ERROR in LauSimFitCoordinator::finalise : Sockets not initialised." << std::endl; return kFALSE; } // Prepare the covariance matrices const TMatrixD& covMatrix = this->covarianceMatrix(); covMatrices_.resize( nTasks_ ); LauParamFixed pred; std::map freeParIndices; UInt_t counter(0); for ( UInt_t iPar(0); iPar < this->nTotParams(); ++iPar ) { const LauParameter* par = params_[iPar]; if ( ! pred(par) ) { freeParIndices.insert( std::make_pair(iPar,counter) ); ++counter; } } for ( UInt_t iTask(0); iTask freeIndices; freeIndices.reserve( nPar ); for ( UInt_t iPar(0); iPar < nPar; ++iPar ) { UInt_t index = taskIndices_[iTask][iPar]; std::map::iterator freeIter = freeParIndices.find(index); if ( freeIter == freeParIndices.end() ) { continue; } UInt_t freeIndex = freeIter->second; freeIndices.push_back( freeIndex ); } const UInt_t nFreePars = freeIndices.size(); TMatrixD& covMat = covMatrices_[iTask]; covMat.ResizeTo( nFreePars, nFreePars ); for ( UInt_t iPar(0); iPar < nFreePars; ++iPar ) { for ( UInt_t jPar(0); jPar < nFreePars; ++jPar ) { UInt_t i = freeIndices[iPar]; UInt_t j = freeIndices[jPar]; covMat( iPar, jPar ) = covMatrix( i, j ); } } } // The array to hold the parameters TObjArray array; // Send messages to all tasks containing the final parameters and fit status, NLL for ( UInt_t iTask(0); iTask& indices = taskIndices_[iTask]; UInt_t nPars = indices.size(); for ( UInt_t iPar(0); iPar < nPars; ++iPar ) { array.Add( params_[ indices[iPar] ] ); } const Int_t status = this->statusCode(); const Double_t NLL = this->nll(); const Double_t EDM = this->edm(); TMatrixD& covMat = covMatrices_[iTask]; TMessage* message = messagesToTasks_[iTask]; message->Reset( kMESS_OBJECT ); message->WriteInt( status ); message->WriteDouble( NLL ); message->WriteDouble( EDM ); message->WriteObject( &array ); message->WriteObject( &covMat ); socketTasks_[iTask]->Send(*message); } TSocket *sActive(0); UInt_t responsesReceived(0); Bool_t allOK(kTRUE); while ( responsesReceived != nTasks_ ) { // Get the next queued response sActive = socketMonitor_->Select(); // Extract from the message the ID of the task and the number of events read sActive->Recv( messageFromTask_ ); UInt_t iTask(0); Bool_t ok(kTRUE); messageFromTask_->ReadUInt( iTask ); messageFromTask_->ReadBool( ok ); if ( ok ) { TObjArray * objarray = dynamic_cast( messageFromTask_->ReadObject( messageFromTask_->GetClass() ) ); if ( ! objarray ) { std::cerr << "ERROR in LauSimFitCoordinator::finalise : Error reading finalised parameters from task" << std::endl; allOK = kFALSE; } else { // We want to auto-delete the supplied parameters since we only copy their values in this case objarray->SetOwner(kTRUE); const UInt_t nPars = objarray->GetEntries(); if ( nPars != taskIndices_[iTask].size() ) { std::cerr << "ERROR in LauSimFitCoordinator::finalise : Unexpected number of finalised parameters received from task" << std::endl; allOK = kFALSE; } else { for ( UInt_t iPar(0); iPar < nPars; ++iPar ) { LauParameter* parameter = dynamic_cast( (*objarray)[iPar] ); if ( ! parameter ) { std::cerr << "ERROR in LauSimFitCoordinator::finalise : Error reading parameter from task" << std::endl; allOK = kFALSE; continue; } TString parname = parameter->name(); std::map< TString, UInt_t >::iterator iter = parIndices_.find( parname ); if ( iter == parIndices_.end() ) { std::cerr << "ERROR in LauSimFitCoordinator::finalise : Unexpected parameter name received from task" << std::endl; allOK = kFALSE; continue; } const UInt_t index = iter->second; if ( taskIndices_[iTask][iPar] != index ) { std::cerr << "ERROR in LauSimFitCoordinator::finalise : Unexpected parameter received from task" << std::endl; allOK = kFALSE; continue; } Double_t parvalue = parameter->value(); params_[index]->value( parvalue ); parValues_[index] = parvalue; vectorPar_[iTask][iPar] = parvalue; } } delete objarray; } } else { std::cerr << "ERROR in LauSimFitCoordinator::finalise : Task " << iTask << " reports an error performing finalisation" << std::endl; allOK = kFALSE; } ++responsesReceived; } // Fill our ntuple as well if ( fitNtuple_ != 0 ) { for ( std::vector::iterator iter = params_.begin(); iter != params_.end(); ++iter ) { if (!(*iter)->fixed()) { (*iter)->updatePull(); } } std::vector extraVars; fitNtuple_->storeParsAndErrors( params_, extraVars ); fitNtuple_->storeCorrMatrix(this->iExpt(), this->fitStatus(), this->covarianceMatrix()); fitNtuple_->updateFitNtuple(); } return allOK; } Bool_t LauSimFitCoordinator::writeOutResults() { if ( socketMonitor_ == 0 ) { std::cerr << "ERROR in LauSimFitCoordinator::writeOutResults : Sockets not initialised." << std::endl; return kFALSE; } // Construct a message, requesting to write out the fit results TString msgStr("Write Results"); TMessage message( kMESS_STRING ); message.WriteTString( msgStr ); // Send the message to the tasks for ( UInt_t iTask(0); iTaskSend(message); } TSocket *sActive(0); UInt_t responsesReceived(0); Bool_t allOK(kTRUE); while ( responsesReceived != nTasks_ ) { // Get the next queued response sActive = socketMonitor_->Select(); // Extract from the message the ID of the task and the number of events read sActive->Recv( messageFromTask_ ); UInt_t iTask(0); Bool_t ok(kTRUE); messageFromTask_->ReadUInt( iTask ); messageFromTask_->ReadBool( ok ); if ( ! ok ) { std::cerr << "ERROR in LauSimFitCoordinator::writeOutResults : Task " << iTask << " reports an error performing finalisation" << std::endl; allOK = kFALSE; } ++responsesReceived; } // Write out our ntuple as well if (fitNtuple_ != 0) { fitNtuple_->writeOutFitResults(); } return allOK; } diff --git a/src/LauSimFitTask.cc b/src/LauSimFitTask.cc index 2589a8d..cf99836 100644 --- a/src/LauSimFitTask.cc +++ b/src/LauSimFitTask.cc @@ -1,310 +1,310 @@ /* Copyright 2015 University of Warwick Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /* Laura++ package authors: John Back Paul Harrison Thomas Latham */ /*! \file LauSimFitTask.cc \brief File containing implementation of LauSimFitTask class. */ #include #include #include "TMatrixD.h" #include "TMessage.h" #include "TObjArray.h" #include "TObjString.h" #include "TSocket.h" #include "TSystem.h" #include "LauSimFitTask.hh" #include "LauFitNtuple.hh" ClassImp(LauSimFitTask) LauSimFitTask::LauSimFitTask() : socketCoordinator_(0), messageFromCoordinator_(0), taskId_(0), nTasks_(0), parValues_(0), fitNtuple_(0) { } LauSimFitTask::~LauSimFitTask() { delete socketCoordinator_; delete messageFromCoordinator_; delete[] parValues_; delete fitNtuple_; } void LauSimFitTask::runTask(const TString& dataFileName, const TString& dataTreeName, const TString& histFileName, const TString& tableFileName, const TString& addressCoordinator, const UInt_t portCoordinator) { // Establish the connection to the coordinator process this->connectToCoordinator( addressCoordinator, portCoordinator ); // Initialise the fit model this->initialise(); // NB call to addConParameters() is intentionally not included here cf. // LauAbsFitModel::run() since this has to be dealt with by the coordinator // to avoid multiple inclusions of each penalty term // Print a warning if constraints on combinations of parameters have been specified - const std::vector& storeCon = this->constraintsStore(); + const auto& storeCon = this->formulaConstraints(); if ( ! storeCon.empty() ) { std::cerr << "WARNING in LauSimFitTask::runTask : Constraints have been added but these will be ignored - they should have been added to the coordinator process" << std::endl; } // Setup saving of fit results to ntuple/LaTeX table etc. this->setupResultsOutputs( histFileName, tableFileName ); // This reads in the given dataFile and creates an input // fit data tree that stores them for all events and experiments. Bool_t dataOK = this->verifyFitData(dataFileName,dataTreeName); if (!dataOK) { std::cerr << "ERROR in LauSimFitTask::runTask : Problem caching the fit data." << std::endl; return; } // Now process the various requests from the coordinator this->processCoordinatorRequests(); std::cout << "INFO in LauSimFitTask::runTask : Fit task " << this->taskId() << " has finished successfully" << std::endl; } void LauSimFitTask::setupResultsOutputs( const TString& histFileName, const TString& /*tableFileName*/ ) { // Create and setup the fit results ntuple std::cout << "INFO in LauSimFitTask::setupResultsOutputs : Creating fit ntuple." << std::endl; if (fitNtuple_ != 0) {delete fitNtuple_; fitNtuple_ = 0;} fitNtuple_ = new LauFitNtuple(histFileName, this->useAsymmFitErrors()); } void LauSimFitTask::connectToCoordinator( const TString& addressCoordinator, const UInt_t portCoordinator ) { if ( socketCoordinator_ != 0 ) { std::cerr << "ERROR in LauSimFitTask::connectToCoordinator : coordinator socket already present" << std::endl; return; } // Open connection to coordinator socketCoordinator_ = new TSocket(addressCoordinator, portCoordinator); socketCoordinator_->Recv( messageFromCoordinator_ ); messageFromCoordinator_->ReadUInt( taskId_ ); messageFromCoordinator_->ReadUInt( nTasks_ ); Bool_t useAsymErrs(kFALSE); messageFromCoordinator_->ReadBool( useAsymErrs ); this->useAsymmFitErrors(useAsymErrs); delete messageFromCoordinator_; messageFromCoordinator_ = 0; std::cout << "INFO in LauSimFitTask::connectToCoordinator : Established connection to coordinator on port " << portCoordinator << std::endl; std::cout << " : We are task " << taskId_ << " of " << nTasks_ << std::endl; if ( useAsymErrs ) { std::cout << " : The fit will determine asymmetric errors" << std::endl; } } void LauSimFitTask::processCoordinatorRequests() { // Listen for requests from the coordinator and act accordingly TMessage messageToCoordinator(kMESS_ANY); while ( kTRUE ) { socketCoordinator_->Recv( messageFromCoordinator_ ); if ( messageFromCoordinator_->What() == kMESS_STRING ) { TString msgStr; messageFromCoordinator_->ReadTString( msgStr ); std::cout << "INFO in LauSimFitTask::processCoordinatorRequests : Received message from coordinator: " << msgStr << std::endl; if ( msgStr == "Send Parameters" ) { // Send the fit parameters TObjArray array; this->prepareInitialParArray( array ); // Create array to efficiently exchange parameter values with coordinator if ( parValues_ != 0 ) { delete[] parValues_; parValues_ = 0; } UInt_t nPar = array.GetEntries(); parValues_ = new Double_t[nPar]; messageToCoordinator.Reset( kMESS_OBJECT ); messageToCoordinator.WriteObject( &array ); socketCoordinator_->Send( messageToCoordinator ); } else if ( msgStr == "Read Expt" ) { // Read the data for this experiment UInt_t iExp(0); messageFromCoordinator_->ReadUInt( iExp ); this->setCurrentExperiment( iExp ); UInt_t nEvents = this->readExperimentData(); if ( nEvents < 1 ) { std::cerr << "WARNING in LauSimFitTask::processCoordinatorRequests : Zero events in experiment " << iExp << ", the coordinator should skip this experiment..." << std::endl; } messageToCoordinator.Reset( kMESS_ANY ); messageToCoordinator.WriteUInt( taskId_ ); messageToCoordinator.WriteUInt( nEvents ); socketCoordinator_->Send( messageToCoordinator ); } else if ( msgStr == "Cache" ) { // Perform the caching this->cacheInputFitVars(); messageToCoordinator.Reset( kMESS_ANY ); messageToCoordinator.WriteUInt( taskId_ ); messageToCoordinator.WriteBool( kTRUE ); socketCoordinator_->Send( messageToCoordinator ); } else if ( msgStr == "Asym Error Calc" ) { Bool_t asymErrorCalc(kFALSE); messageFromCoordinator_->ReadBool( asymErrorCalc ); this->withinAsymErrorCalc( asymErrorCalc ); messageToCoordinator.Reset( kMESS_ANY ); messageToCoordinator.WriteUInt( taskId_ ); messageToCoordinator.WriteBool( asymErrorCalc ); socketCoordinator_->Send( messageToCoordinator ); } else if ( msgStr == "Write Results" ) { this->writeOutAllFitResults(); messageToCoordinator.Reset( kMESS_ANY ); messageToCoordinator.WriteUInt( taskId_ ); messageToCoordinator.WriteBool( kTRUE ); socketCoordinator_->Send( messageToCoordinator ); } else if ( msgStr == "Finish" ) { std::cout << "INFO in LauSimFitTask::processCoordinatorRequests : Message from coordinator to finish" << std::endl; break; } else { std::cerr << "ERROR in LauSimFitTask::processCoordinatorRequests : Unexpected message from coordinator" << std::endl; gSystem->Exit( EXIT_FAILURE ); } } else if ( messageFromCoordinator_->What() == kMESS_OBJECT ) { std::cout << "INFO in LauSimFitTask::processCoordinatorRequests : Received message from coordinator: Finalise" << std::endl; Int_t status(0); Double_t NLL(0.0); Double_t EDM(0.0); messageFromCoordinator_->ReadInt( status ); messageFromCoordinator_->ReadDouble( NLL ); messageFromCoordinator_->ReadDouble( EDM ); TObjArray * objarray = dynamic_cast( messageFromCoordinator_->ReadObject( messageFromCoordinator_->GetClass() ) ); if ( ! objarray ) { std::cerr << "ERROR in LauSimFitTask::processCoordinatorRequests : Error reading parameters from coordinator" << std::endl; gSystem->Exit( EXIT_FAILURE ); } TMatrixD * covMat = dynamic_cast( messageFromCoordinator_->ReadObject( messageFromCoordinator_->GetClass() ) ); if ( ! covMat ) { std::cerr << "ERROR in LauSimFitTask::processCoordinatorRequests : Error reading covariance matrix from coordinator" << std::endl; gSystem->Exit( EXIT_FAILURE ); } TObjArray array; LauAbsFitter::FitStatus fitStat { status, NLL, EDM }; this->finaliseExperiment( fitStat, objarray, covMat, array ); delete objarray; objarray = 0; delete covMat; covMat = 0; // Send the finalised parameters back to the coordinator messageToCoordinator.Reset( kMESS_ANY ); messageToCoordinator.WriteUInt( taskId_ ); messageToCoordinator.WriteBool( kTRUE ); messageToCoordinator.WriteObject( &array ); socketCoordinator_->Send( messageToCoordinator ); } else if ( messageFromCoordinator_->What() == kMESS_ANY ) { UInt_t nPars(0); UInt_t nFreePars(0); messageFromCoordinator_->ReadUInt( nPars ); messageFromCoordinator_->ReadUInt( nFreePars ); if ( nPars != this->nTotParams() ) { std::cerr << "ERROR in LauSimFitTask::processCoordinatorRequests : Unexpected number of parameters received from coordinator" << std::endl; std::cerr << " : Received " << nPars << " when expecting " << this->nTotParams() << std::endl; gSystem->Exit( EXIT_FAILURE ); } messageFromCoordinator_->ReadFastArray( parValues_, nPars ); this->setParsFromMinuit( parValues_, nFreePars ); Double_t negLogLike = this->getTotNegLogLikelihood(); messageToCoordinator.Reset( kMESS_ANY ); messageToCoordinator.WriteDouble( negLogLike ); socketCoordinator_->Send( messageToCoordinator ); } else { std::cerr << "ERROR in LauSimFitTask::processCoordinatorRequests : Unexpected message type" << std::endl; gSystem->Exit( EXIT_FAILURE ); } delete messageFromCoordinator_; messageFromCoordinator_ = 0; } } void LauSimFitTask::writeOutAllFitResults() { // Write out histograms at end if (fitNtuple_ != 0) { fitNtuple_->writeOutFitResults(); } }