File indexing completed on 2025-01-30 09:18:35
0001 Float_t sphx,sphy,sphz;
0002 TTree *tr;
0003 TH1D *hist;
0004
0005
0006
0007
0008
0009
0010
0011
0012 void FindCenter(Float_t startx, Float_t starty, Float_t startz,
0013 Float_t size,
0014 Float_t &endx, Float_t &endy, Float_t &endz,
0015 Float_t &enddist, Float_t &endrms) {
0016
0017 endrms = 1e6;
0018 enddist = 1e6;
0019
0020 Float_t currx,curry,currz;
0021 Float_t currrms;
0022
0023 int ndiv = 5;
0024 Float_t div = size/ndiv;
0025 int rc = (ndiv-1)/2;
0026
0027
0028 for(int x=0; x<ndiv; x++) {
0029 for(int y=0; y<ndiv; y++) {
0030 for(int z=0; z<ndiv; z++) {
0031
0032
0033 currx = startx + (x-rc)*div;
0034 curry = starty + (y-rc)*div;
0035 currz = startz + (z-rc)*div;
0036
0037
0038
0039
0040 hist->Reset();
0041 for(int e=0; e<tr->GetEntries(); e++) {
0042 tr->GetEntry(e);
0043 hist->Fill(
0044 TMath::Sqrt(
0045 TMath::Power(sphx-currx,2)+
0046 TMath::Power(sphy-curry,2)+
0047 TMath::Power(sphz-currz,2)
0048 )
0049 );
0050 };
0051 currrms = hist->GetStdDev();
0052
0053
0054
0055 if(currrms<endrms) {
0056 endx = currx;
0057 endy = curry;
0058 endz = currz;
0059 endrms = currrms;
0060 enddist = hist->GetMean();
0061 };
0062
0063 };};};
0064
0065
0066 printf("result: (%.2f, %.2f, %.2f) rms=%.4f dist=%.4f\n",
0067 endx,endy,endz,endrms,enddist);
0068 };
0069
0070
0071
0072 void FindSphereCenter(TString treeFile="photosensors.dat") {
0073
0074
0075 tr = new TTree();
0076 tr->ReadFile(treeFile,"x/F:y/F:z/F");
0077 tr->SetBranchAddress("x",&sphx);
0078 tr->SetBranchAddress("y",&sphy);
0079 tr->SetBranchAddress("z",&sphz);
0080
0081
0082 hist = new TH1D("hist","hist",2000,0,2000);
0083
0084 Float_t guessx,guessy,guessz;
0085 Float_t bestx,besty,bestz;
0086 Float_t size,dist,rms;
0087
0088
0089 const int NIter = 1000;
0090 Float_t initsize = 300;
0091 guessx = 0;
0092 guessy = 0;
0093 guessz = 0;
0094
0095
0096
0097
0098
0099
0100
0101
0102 for(int d=0; d<NIter; d++) {
0103 size = d>0 ? initsize/(2*d) : initsize;
0104 FindCenter(
0105 guessx,guessy,guessz,
0106 size,
0107 bestx,besty,bestz,
0108 dist,rms
0109 );
0110 guessx = bestx;
0111 guessy = besty;
0112 guessz = bestz;
0113 };
0114 };