FACT++  1.0
void StateMachineRateControl::ProcessPatches ( const FTM::DimTriggerRates sdata)
inlineprivate

Definition at line 164 of file ratecontrol.cc.

References FTM::DimTriggerRates::fBoardRate, Tools::Form(), FTM::DimTriggerRates::fPatchRate, i, and Dim::SendCommandNB().

165  {
166 
167  // Caluclate Median and deviation
168  vector<float> medb(sdata.fBoardRate, sdata.fBoardRate+40);
169  vector<float> medp(sdata.fPatchRate, sdata.fPatchRate+160);
170 
171  sort(medb.begin(), medb.end());
172  sort(medp.begin(), medp.end());
173 
174  vector<float> devb(40);
175  for (int i=0; i<40; i++)
176  devb[i] = fabs(sdata.fBoardRate[i]-medb[i]);
177 
178  vector<float> devp(160);
179  for (int i=0; i<160; i++)
180  devp[i] = fabs(sdata.fPatchRate[i]-medp[i]);
181 
182  sort(devb.begin(), devb.end());
183  sort(devp.begin(), devp.end());
184 
185  const double mb = (medb[19]+medb[20])/2;
186  const double mp = (medp[79]+medp[80])/2;
187 
188  const double db = devb[27];
189  const double dp = devp[109];
190 
191  // If any is zero there is something wrong
192  if (mb==0 || mp==0 || db==0 || dp==0)
193  return;
194 
195  if (fVerbose)
196  Out() << Tools::Form("Boards: Med=%3.1f +- %3.1f Hz Patches: Med=%3.1f +- %3.1f Hz", mb, db, mp, dp) << endl;
197 
198  bool changed = false;
199 
200  for (int i=0; i<40; i++)
201  {
202  if (fBlock[i])
203  {
204  fBlock[i] = false;
205  continue;
206  }
207 
208  int maxi = -1;
209 
210  const float dif = fabs(sdata.fBoardRate[i]-mb)/db;
211  if (dif>3)
212  {
213  if (fVerbose)
214  Out() << "Board " << setw(3) << i << ": " << dif << " dev away from med" << endl;
215 
216  float max = sdata.fPatchRate[i*4];
217  maxi = 0;
218 
219  for (int j=1; j<4; j++)
220  if (sdata.fPatchRate[i*4+j]>max)
221  {
222  max = sdata.fPatchRate[i*4+j];
223  maxi = j;
224  }
225  }
226 
227  for (int j=0; j<4; j++)
228  {
229  // For the noise pixel correct down to median+3*deviation
230  if (maxi==j)
231  {
232  // This is the step which has to be performed to go from
233  // a NSB rate of sdata.fPatchRate[i*4+j]
234 
235 
236  const float step = (log10(sdata.fPatchRate[i*4+j])-log10(mp+3.5*dp))/0.039;
237  // * (dif-5)/dif
238  changed |= Step(i*4+j, step);
239  continue;
240  }
241 
242  // For pixels below the median correct also back to median+3*deviation
243  if (sdata.fPatchRate[i*4+j]<mp)
244  {
245  const float step = (log10(sdata.fPatchRate[i*4+j])-log10(mp+3.5*dp))/0.039;
246  changed |= Step(i*4+j, step);
247  continue;
248  }
249 
250  const float step = -1.5*(log10(mp+dp)-log10(mp))/0.039;
251  changed |= Step(i*4+j, step);
252  }
253  }
254 
255  if (changed)
256  Dim::SendCommandNB("FTM_CONTROL/SET_SELECTED_THRESHOLDS", fThresholds);
257  }
int i
Definition: db_dim_client.c:21
float fBoardRate[40]
Definition: HeadersFTM.h:589
vector< bool > fBlock
Definition: ratecontrol.cc:54
std::ostream & Out() const
Definition: MessageImp.h:73
void SendCommandNB(const std::string &command)
Definition: Dim.h:30
std::string Form(const char *fmt,...)
Definition: tools.cc:45
bool Step(int idx, float step)
Definition: ratecontrol.cc:140
vector< uint32_t > fThresholds
Definition: ratecontrol.cc:98
float fPatchRate[160]
Definition: HeadersFTM.h:590

+ Here is the call graph for this function: