From: <ro...@us...> - 2011-01-17 11:22:45
|
Revision: 1789 http://nsclspectcl.svn.sourceforge.net/nsclspectcl/?rev=1789&view=rev Author: ron-fox Date: 2011-01-17 11:22:39 +0000 (Mon, 17 Jan 2011) Log Message: ----------- Good compile on cbar and y2f computation. Modified Paths: -------------- branches/LLNLMadcChainSpecTcl/CMultiplicity.cpp branches/LLNLMadcChainSpecTcl/CMultiplicity.h Modified: branches/LLNLMadcChainSpecTcl/CMultiplicity.cpp =================================================================== --- branches/LLNLMadcChainSpecTcl/CMultiplicity.cpp 2011-01-17 10:29:47 UTC (rev 1788) +++ branches/LLNLMadcChainSpecTcl/CMultiplicity.cpp 2011-01-17 11:22:39 UTC (rev 1789) @@ -37,6 +37,22 @@ static const uint32_t WRAPADD(0x40000000); // Amount to add for a timestamp wrap. +/* compute factorial function used in ynf calculations */ + +static inline double +factorial(int n) +{ + if (n <= 1) { + return 1; // All the special cases for our purposes + } + double product = 1; + for (int i =2; i <= n; i++) { + product *= i; + } + return product; + +} + /*! Construction builds the tree parameters and what we can of the CTCLVariable. */ @@ -1070,3 +1086,49 @@ } return result; } +/** + ** compute the CBAR. For a given gate this is a weighted sum of the + ** multiplicities by the multiplicities dividec by the total number of events. + ** Raw data easily comes from the output of getGateMultiplicities. + ** @param gate - Number of the gate for which we want this value. + ** @return double + ** @retval cbar for the given gate. + */ +double +CMultiplicity::cbar(int gate) +{ + vector<unsigned> multiplicities = getGateMultiplicities(gate); + + double nbks = 0.0; + double numerator = 0.0; + for (int i =1; i < multiplicities.size(); i++) { + nbks += multiplicities[i]; + numerator += i*multiplicities[i]; + } + double cbar = numerator/nbks; // Really the centroid of the multiplicity distribution. + return cbar; +} + +/** + ** Calclate the y2f or the feynman variance of the multiplicity for gate n + ** @param gate - Gate number for which to calculate the y2f + ** @return double + ** @retval y2f. + */ +double +CMultiplicity::y2f(int gate) +{ + double cb = cbar(gate); + double pairs = 0.0; + if (cb == 0.0) return 0.0; // special case. + + vector<unsigned> mult = getGateMultiplicities(gate); + + + for (int i = 0; i < mult.size(); i++) { + double coef = factorial(i)/2*(factorial(i-2)); // for our purposes factorial won't be too big. + pairs += coef*mult[i]; + } + double result = (pairs - 0.5*cb*cb)/cb; + return result; +} Modified: branches/LLNLMadcChainSpecTcl/CMultiplicity.h =================================================================== --- branches/LLNLMadcChainSpecTcl/CMultiplicity.h 2011-01-17 10:29:47 UTC (rev 1788) +++ branches/LLNLMadcChainSpecTcl/CMultiplicity.h 2011-01-17 11:22:39 UTC (rev 1789) @@ -173,6 +173,8 @@ std::vector<unsigned> getMultiplicityTotals(); std::vector<unsigned> getGateMultiplicities(int gate); std::vector<unsigned> getSpecificMultiplicity(int n); + double cbar(int gate); + double y2f(int gate); // Utitities: private: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |