CMS 3D CMS Logo

Functions
CocoaUnitsTable.cc File Reference
#include "Alignment/CocoaToDDL/interface/CocoaUnitsTable.h"
#include <CLHEP/Units/SystemOfUnits.h>
#include <iomanip>
#include <cmath>

Go to the source code of this file.

Functions

std::ostream & operator<< (std::ostream &flux, CocoaBestUnit a)
 

Function Documentation

◆ operator<<()

std::ostream& operator<< ( std::ostream &  flux,
CocoaBestUnit  a 
)

Definition at line 343 of file CocoaUnitsTable.cc.

References a, funct::abs(), ALI_DBL_MAX, ALI_DBL_MIN, CocoaUnitDefinition::GetUnitsTable(), dqmiolumiharvest::j, isotrackApplyRegressor::k, WZElectronSkims53X_cff::max, and unit().

343  {
345  CocoaUnitsContainer& List = theUnitsTable[a.IndexOfCategory]->GetUnitsList();
346  ALIint len = theUnitsTable[a.IndexOfCategory]->GetSymbMxLen();
347 
348  ALIint ksup(-1), kinf(-1);
349  ALIdouble umax(0.), umin(ALI_DBL_MAX);
350  ALIdouble rsup(ALI_DBL_MAX), rinf(0.);
351 
352  //for a ThreeVector, choose the best unit for the biggest value
353  ALIdouble value = std::max(std::max(std::abs(a.Value[0]), std::abs(a.Value[1])), std::abs(a.Value[2]));
354 
355  for (size_t k = 0; k < List.size(); k++) {
356  ALIdouble unit = List[k]->GetValue();
357  if (value == ALI_DBL_MAX) {
358  if (unit > umax) {
359  umax = unit;
360  ksup = k;
361  }
362  } else if (value <= ALI_DBL_MIN) {
363  if (unit < umin) {
364  umin = unit;
365  kinf = k;
366  }
367  }
368 
369  else {
370  ALIdouble ratio = value / unit;
371  if ((ratio >= 1.) && (ratio < rsup)) {
372  rsup = ratio;
373  ksup = k;
374  }
375  if ((ratio < 1.) && (ratio > rinf)) {
376  rinf = ratio;
377  kinf = k;
378  }
379  }
380  }
381 
382  ALIint index = ksup;
383  if (index == -1)
384  index = kinf;
385  if (index == -1)
386  index = 0;
387 
388  for (ALIint j = 0; j < a.nbOfVals; j++) {
389  flux << a.Value[j] / (List[index]->GetValue()) << " ";
390  }
391 
392  std::ios::fmtflags oldform = flux.flags();
393 
394  flux.setf(std::ios::left, std::ios::adjustfield);
395  flux << std::setw(len) << List[index]->GetSymbol();
396  flux.flags(oldform);
397 
398  return flux;
399 }
std::vector< CocoaUnitDefinition * > CocoaUnitsContainer
long double ALIdouble
Definition: CocoaGlobals.h:11
const double ALI_DBL_MIN
Definition: CocoaGlobals.h:25
static CocoaUnitsTable & GetUnitsTable()
int ALIint
Definition: CocoaGlobals.h:15
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< CocoaUnitsCategory * > CocoaUnitsTable
Definition: value.py:1
Basic3DVector unit() const
double a
Definition: hdecay.h:121
const double ALI_DBL_MAX
Definition: CocoaGlobals.h:24