Commit e81776e8 authored by dauncey's avatar dauncey

New mains

parent 87bcf303
No preview for this file type
......@@ -497,7 +497,6 @@ $E=0$ & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 \cr
\end{tabular}
\end{center}
%\newpage
For the extreme values of $E$, then $E=0$ and $E=1$ both give an exact
representation as they only use the lowest range or two lowest ranges,
......@@ -568,6 +567,7 @@ Representation & Exponent & Mantissa & Value & $2\times$Rep & Appended & $2\time
\end{tabular}
\end{center}
\newpage
\section{Template fit of energy in depth}
Assume a template shape for a photon of $P_l$ per photon energy GeV
......
......@@ -12,7 +12,7 @@ public:
reset();
}
Average(unsigned n, double a, double s) {
Average(unsigned long n, double a, double s) {
_number=n;
_sum=n*a;
if(n>1) _sumOfSquares=(n-1.0)*s*s+n*a*a;
......@@ -59,7 +59,7 @@ public:
operator+=(x);
}
virtual unsigned number() const {
virtual unsigned long number() const {
return _number;
}
......@@ -88,7 +88,7 @@ public:
private:
unsigned _number;
unsigned long _number;
double _sum;
double _sumOfSquares;
};
......
......@@ -6,6 +6,7 @@
#include <cmath>
#include <cassert>
#include "Backtrace.hh"
#include "PackerBase.hh"
class PackerFloat22 : public PackerBaseUint<uint16_t> {
......@@ -24,15 +25,22 @@ public:
virtual std::string name() const {
std::ostringstream sout;
sout << "PackerFloat22E" << fExp << "M" << fMan;
sout << "PackerFloat22_" << fExp << "E" << fMan << "M";
return sout.str();
}
void pack(uint32_t d) {
uint32_t dSave(d);
assert(d<=fDataMax);
/*
std::cout << name() << "::pack() Bits in mantissa = " << fMan
<< ", exponent = " << fExp << ", total range = "
<< fBit << ", data maximum = 0x" << std::hex << fDataMax
<< std::dec << " = " << fDataMax
<< ", data = " << d << std::endl;
*/
BACKTRACE_AND_ASSERT(d<=fDataMax);
if(d<(uint32_t(1)<<fMan)) {
fDatum=d;
return;
......
......@@ -42,6 +42,10 @@ public:
}
}
TH1F* Int() {
return i;
}
protected:
bool up;
double wSum;
......
#include "Hack.hh"
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include "TH1F.h"
#include "TH2F.h"
#include "TH1D.h"
#include "TH2D.h"
#include "TFileHandler.hh"
#include "Backtrace.hh"
#include "Random.hh"
#include "TE1F.hh"
class LosingPoint {
public:
LosingPoint(int n, int m) : fN(n), fM(m) {
}
bool isWinningPoint(int n, int m) {
if(n<fN || m<fM) return false;
if(n==fN) return true;
if(m==fM) return true;
if(n-fN==m-fM) return true;
if(n-fN==2*(m-fM)) return true;
if(2*(n-fN)==m-fM) return true;
return false;
}
long int sum() const {
if(fN<=fM) return fN+fM;
return 0;
}
private:
int fN,fM;
};
int main(int argc, char* argv[]) {
TFileHandler tfh("Annoying");
unsigned bxHist(1000);
TH2F *hLose=new TH2F("Lose",";n;m",
bxHist,0,bxHist,
bxHist,0,bxHist);
TH1F *hRatio=new TH1F("Ratio",";n/s",
1000,0.0,1.0);
std::vector<LosingPoint> vLp;
vLp.push_back(LosingPoint(0,0));
hLose->SetBinContent(1,1,1);
unsigned s(1);
unsigned nX[2][2]={{0xffffffff,0},{0xffffffff,0}};
for(;s<=100;s++) {
nX[0][0]=0xffffffff;
nX[0][1]=0;
nX[1][0]=0xffffffff;
nX[1][1]=0;
unsigned nLp(vLp.size());
if((s%10)==0) std::cout << "Sum = " << s << ", number of losing points so far = " << nLp << std::endl;
for(unsigned n(0);n<=s;n++) {
unsigned m(s-n);
bool wp(false);
for(unsigned v(0);v<nLp && !wp;v++) {
wp=vLp[v].isWinningPoint(n,m);
}
if(!wp) {
//hRatio->Fill((1.0*n)/s);
vLp.push_back(LosingPoint(n,m));
hLose->SetBinContent(n+1,m+1,1);
if(n<0.35*s) {
if(nX[0][0]>n) nX[0][0]=n;
if(nX[0][1]<n) nX[0][1]=n;
} else {
if(nX[1][0]>n) nX[1][0]=n;
if(nX[1][1]<n) nX[1][1]=n;
}
}
}
}
std::cout << "Extremes = " << nX[0][0] << " to " << nX[0][1]
<< " and " << nX[1][0] << " to " << nX[1][1] << std::endl;
long int sum(0);
for(unsigned v(0);v<vLp.size();v++) {
sum+=vLp[v].sum();
}
std::cout << "Number of losing points = " << vLp.size() << ", total sum of n+m = " << sum << std::endl;
unsigned nCentre;
for(;s<=100000;s++) {
unsigned nLp(vLp.size());
if((s%500)==0) std::cout << "Sum = " << s << ", number of losing points so far = " << nLp << std::endl;
nCentre=0.3075*s;
for(unsigned n(nCentre-10);n<=nCentre+10 && n<0.35*s;n++) {
//for(unsigned n(0);n<=0.35*s;n++) {
unsigned m(s-n);
bool wp(false);
for(unsigned v(0);v<nLp && !wp;v++) {
wp=vLp[v].isWinningPoint(n,m);
}
if(!wp) {
hRatio->Fill((1.0*n)/s);
vLp.push_back(LosingPoint(n,m));
vLp.push_back(LosingPoint(m,n));
hLose->SetBinContent(n+1,m+1,1);
hLose->SetBinContent(m+1,n+1,1);
}
}
nCentre=0.4033*s;
unsigned nLo(nCentre-40);
if(nLo<0.35*s) nLo=0.35*s;
for(unsigned n(nLo);n<=nCentre+40 && n<=s/2;n++) {
//for(unsigned n(0.35*s);n<=s/2;n++) {
unsigned m(s-n);
bool wp(false);
for(unsigned v(0);v<nLp && !wp;v++) {
wp=vLp[v].isWinningPoint(n,m);
}
if(!wp) {
hRatio->Fill((1.0*n)/s);
vLp.push_back(LosingPoint(n,m));
vLp.push_back(LosingPoint(m,n));
hLose->SetBinContent(n+1,m+1,1);
hLose->SetBinContent(m+1,n+1,1);
}
}
}
sum=0;
for(unsigned v(0);v<vLp.size();v++) {
sum+=vLp[v].sum();
}
std::cout << "Number of losing points = " << vLp.size() << ", total sum of n+m = " << sum << std::endl;
return 0;
}
#include "Hack.hh"
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include "TH1F.h"
#include "TH2F.h"
#include "TH1D.h"
#include "TH2D.h"
#include "TFileHandler.hh"
#include "Backtrace.hh"
#include "Random.hh"
#include "TE1F.hh"
unsigned bitsPerModule(unsigned n) {
if(n<8) return 16+13*n;
return 16+48+7*n;
}
int main(int argc, char* argv[]) {
TFileHandler tfh("DumbBuffer");
TH1D *hBits=new TH1D("Bits",";Number of trigger cells;Bits per module",
49,0.0,49.0);
TH1D *hBitsBx=new TH1D("BitsBx",";Number of trigger cells;BX per module",
49,0.0,49.0);
TH1D *hHits=new TH1D("Hits",";Number of trigger cells;Number",
49,0.0,49.0);
TH1D *hBiocc=new TH1D("Biocc",";Buffer after filling (bits)",
100,0,500);
TH1D *hBiobx=new TH1D("Biobx",";Buffer after filling (BX)",
100,0,20);
TH1D *hBoocc=new TH1D("Boocc",";Buffer after emptying (bits)",
100,0,500);
TH1D *hBoobx=new TH1D("Boobx",";Buffer after emptying (BX)",
100,0,20);
TE1F *hBioccE=new TE1F("BioccE",";Buffer after filling (bits)",
200,0,1000);
TE1F *hBiobxE=new TE1F("BiobxE",";Buffer after filling (BX)",
200,0,40);
TE1F *hBooccE=new TE1F("BooccE",";Buffer after emptying (bits)",
200,0,1000);
TE1F *hBoobxE=new TE1F("BoobxE",";Buffer after emptying (BX)",
200,0,40);
unsigned bxHist(1000);
TH1D *hBinp=new TH1D("Binp",";BX;Buffer after filling (bits)",
bxHist,0,bxHist);
TH1D *hBout=new TH1D("Bout",";BX;Buffer after emptying (bits)",
bxHist,0,bxHist);
TH1D *hBibx=new TH1D("Bibx",";BX;Buffer after filling (BX)",
bxHist,0,bxHist);
TH1D *hBobx=new TH1D("Bobx",";BX;Buffer after emptying (BX)",
bxHist,0,bxHist);
TH1D *hLat=new TH1D("Lat",";Mean occupancy;Latency (BX)",
15,0.0,1.5);
for(unsigned n(0);n<49;n++) {
hBits->SetBinContent(n+1,bitsPerModule(n));
hBitsBx->SetBinContent(n+1,bitsPerModule(n)/32.0);
}
for(unsigned m(0);m<15;m++) {
const double meanHits(0.1*(m+0.5));
std::cout << m << " Mean number of hits = " << meanHits << " per BX" << std::endl;
unsigned nBuffer(0);
unsigned nBx(5000000);
for(unsigned bx(0);bx<nBx;bx++) {
unsigned nHits(Random::random().Poisson(meanHits));
hHits->Fill(nHits);
// Into buffer
unsigned nBits(bitsPerModule(nHits));
nBuffer+=nBits;
hBiocc->Fill(nBuffer);
hBiobx->Fill(nBuffer/32.0);
hBioccE->Fill(nBuffer);
hBiobxE->Fill(nBuffer/32.0);
if(bx<bxHist) {
hBinp->SetBinContent(bx+1,nBuffer);
hBibx->SetBinContent(bx+1,nBuffer/32.0);
}
// Out of buffer
if(nBuffer<32) nBuffer=0;
else nBuffer-=32;
hBoocc->Fill(nBuffer);
hBoobx->Fill(nBuffer/32.0);
hBooccE->Fill(nBuffer);
hBoobxE->Fill(nBuffer/32.0);
if(bx<bxHist) {
hBout->SetBinContent(bx+1,nBuffer);
hBobx->SetBinContent(bx+1,nBuffer/32.0);
}
}
unsigned nBxInt(nBx/100000);
bool done(false);
for(unsigned i(0);i<200 && !done;i++) {
if(hBiobxE->Int()->GetBinContent(i+1)<nBxInt) {
done=true;
std::cout << m << " Buffer occupancy at 10^-5 = " << 0.2*i << " BX" << std::endl;
hLat->SetBinContent(m+1,0.2*i);
}
}
if(!done) hLat->SetBinContent(m+1,0.2*200);
}
return 0;
}
#include "Hack.hh"
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include "TH1F.h"
#include "TH2F.h"
#include "TH1D.h"
#include "TH2D.h"
#include "TFileHandler.hh"
#include "Backtrace.hh"
#include "Random.hh"
#include "TE1F.hh"
/*
unsigned bitsPerModule(unsigned n) {
if(n<8) return 16+13*n;
return 16+48+7*n;
}
*/
class System {
public:
System(unsigned l, unsigned r, unsigned t, unsigned m)
: fLinks(l), fRepeat(r), fTimeMx(t), fM(m), fInput((fLinks+71)/72), fN1((fInput+fRepeat-1)/fRepeat) {
}
bool valid(bool var) const {
if(fM*fTimeMx>72) return false; // S1 FPGA input
if(fM*fN1>72) return false; // S2 FPGA input
unsigned nOverlap((72+fTimeMx-1)/fTimeMx);
if(fRepeat==1) nOverlap=0;
if(2*nOverlap>=fN1) return false;
double ratio(((fN1-2*nOverlap)*fM*fTimeMx+2*nOverlap*(fM-1)*fTimeMx)/(42.0*fN1));
if(ratio<(var?1.4:1.1)) return false;
return true;
}
unsigned latency() const {
std::cout << "r, n1, t, m = "
<< fRepeat << ", "
<< fN1 << ", "
<< fTimeMx << ", "
<< fM << ", latency = " << fTimeMx << std::endl;
return fTimeMx;
}
unsigned cost() const {
unsigned cost(1.25*(30*fN1*fRepeat+18*fTimeMx*fRepeat));
std::cout << "r, n1, t, m = "
<< fRepeat << ", "
<< fN1 << ", "
<< fTimeMx << ", "
<< fM << ", cost = "
<< cost << std::endl;
return cost;
}
private:
unsigned fLinks;
unsigned fRepeat;
unsigned fTimeMx;
unsigned fM;
unsigned fInput;
unsigned fN1;
};
int main(int argc, char* argv[]) {
bool var(true);
bool l25(false);
std::string fn("DumbTm");
if(var) fn+="Var";
else fn+="Fix";
if(l25) fn+="L25";
else fn+="L16";
TFileHandler tfh(fn);
const unsigned nL(60);
/*
std::string sL[nL]={//"3888",
"3500","3600","3700","3800","3900",
"4000","4100","4200","4300","4400",
"4500","4600","4700","4800","4900",
"5000","5100","5200","5300","5400",
"5500","5600","5700","5800","5900",
"6000"};
*/
TH2F *hCvsL[nL];
for(unsigned l(0);l<nL;l++) {
std::ostringstream sLabel;
sLabel << std::setw(4) << std::setfill('0') << 3500+50*l;
hCvsL[l]=new TH2F((std::string("CvsL")+sLabel.str()).c_str(),
";Latency (BX);Cost (kCHF)",
80,0,80,200,0,10000);
}
TH2F *hCvsK=new TH2F("CvsK",";Input links;Cost (kCHF)",
80,6000,14000,200,0,10000);
TH2F *hLvsK=new TH2F("LvsK",";Input links;Latency (BX)",
80,6000,14000,80,0,80);
TH1D *hBitsBx=new TH1D("BitsBx",";Number of trigger cells;BX per module",
49,0.0,49.0);
TH1D *hHits=new TH1D("Hits",";Number of trigger cells;Number",
49,0.0,49.0);
TH1D *hBiocc=new TH1D("Biocc",";Buffer after filling (bits)",
100,0,500);
TH1D *hBiobx=new TH1D("Biobx",";Buffer after filling (BX)",
100,0,20);
TH1D *hBoocc=new TH1D("Boocc",";Buffer after emptying (bits)",
100,0,500);
TH1D *hBoobx=new TH1D("Boobx",";Buffer after emptying (BX)",
100,0,20);
TE1F *hBioccE=new TE1F("BioccE",";Buffer after filling (bits)",
200,0,1000);
TE1F *hBiobxE=new TE1F("BiobxE",";Buffer after filling (BX)",
200,0,40);
TE1F *hBooccE=new TE1F("BooccE",";Buffer after emptying (bits)",
200,0,1000);
TE1F *hBoobxE=new TE1F("BoobxE",";Buffer after emptying (BX)",
200,0,40);
unsigned bxHist(1000);
TH1D *hBinp=new TH1D("Binp",";BX;Buffer after filling (bits)",
bxHist,0,bxHist);
TH1D *hBout=new TH1D("Bout",";BX;Buffer after emptying (bits)",
bxHist,0,bxHist);
TH1D *hBibx=new TH1D("Bibx",";BX;Buffer after filling (BX)",
bxHist,0,bxHist);
TH1D *hBobx=new TH1D("Bobx",";BX;Buffer after emptying (BX)",
bxHist,0,bxHist);
TH1D *hLat=new TH1D("Lat",";Mean occupancy;Latency (BX)",
15,0.0,1.5);
TH2F *hCvsKT[72];
TH2F *hTCvsK[72];
TH2F *hTRvsK[72];
TH2F *hTN1vsK[72];
for(unsigned t(1);t<=72;t++) {
std::ostringstream sLabel;
sLabel << std::setw(2) << std::setfill('0') << t;
hTCvsK[t-1]=new TH2F((std::string("TCvsK")+sLabel.str()).c_str(),
";Input links;Cost (kCHF)",
80,6000,14000,200,0,10000);
hTRvsK[t-1]=new TH2F((std::string("TRvsK")+sLabel.str()).c_str(),
";Input links;Regions",
80,6000,14000,100,0,100);
hTN1vsK[t-1]=new TH2F((std::string("TN1vsK")+sLabel.str()).c_str(),
";Input links;Stage 1 links/FPGA per region",
80,6000,14000,100,0,100);
}
for(unsigned l(0);l<nL;l++) {
//unsigned nLinks(l==0?3888:3500+100*l);
unsigned nLinks(3500+50*l);
unsigned nInput((nLinks+71)/72);
std::cout << std::endl << "Number of input links/endcap = " << nLinks << std::endl;
unsigned minCost(1000000);
unsigned minLatency(1000000);
for(unsigned t(1);t<=72;t++) {
if(l==0) {
std::ostringstream sLabel;
sLabel << std::setw(2) << std::setfill('0') << t;
hCvsKT[t-1]=new TH2F((std::string("CvsKT")+sLabel.str()).c_str(),
";Input links;Cost (kCHF)",
80,6000,14000,200,0,10000);
}
unsigned tmMinCost(1000000);
unsigned tmMinLatency(1000000);
unsigned tmMinRegions(1000000);
unsigned tmMinN1(1000000);
for(unsigned m(1);m<=72;m++) {
for(unsigned r(1);r<=72;r++) {
unsigned n1((nInput+r-1)/r);
System syst(nLinks,r,t,m);
// Check validity
if(m*t<=72) { // S1 FPGA output
if(m*n1<=72) { // S2 FPGA input
unsigned nOverlap((72+t-1)/t);
if(r==1) nOverlap=0;
if(2*nOverlap<n1) {
double ratio;
if(l25) ratio=((n1-2*nOverlap)*m*t+2*nOverlap*(m-1)*t)/(28.0*n1);
else ratio=((n1-2*nOverlap)*m*t+2*nOverlap*(m-1)*t)/(42.0*n1);
if(ratio>(var?1.4:1.1)) {
// Find latency, cost and overhead ratio
unsigned latency(t);
unsigned cost;
if(l25) cost=1.25*(35*n1*r+23*t*r);
else cost=1.25*(30*n1*r+18*t*r);
std::cout << "r, n1, t, m = "
<< r << ", "
<< n1 << ", "
<< t << ", "
<< m << ", latency, cost, ratio = "
<< latency << ", "
<< cost << ", "
<< ratio << std::endl;
hCvsKT[t-1]->Fill(2*nLinks,cost);
if(tmMinCost>=cost) {
std::cout << "New TM minimum cost" << std::endl;
tmMinCost=cost;
tmMinLatency=latency;
tmMinRegions=r;
tmMinN1=n1;
}
if(minCost>=cost) {
std::cout << "New minimum cost" << std::endl;
minCost=cost;
minLatency=latency;
}
hCvsL[l]->Fill(latency,cost);
}
}
}
}
}
}
hTCvsK[t-1]->Fill(2*nLinks,tmMinCost);
hTRvsK[t-1]->Fill(2*nLinks,tmMinRegions);
hTN1vsK[t-1]->Fill(2*nLinks,tmMinN1);
}
hCvsK->Fill(2*nLinks,minCost);
hLvsK->Fill(2*nLinks,minLatency);
}
return 0;
}
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment