CMS 3D CMS Logo

List of all members | Public Member Functions | Private Types | Private Attributes
EcalLaserDbService Class Reference

#include <EcalLaserDbService.h>

Public Member Functions

 EcalLaserDbService ()
 
const EcalLaserAlphasgetAlphas () const
 
const EcalLaserAPDPNRatiosgetAPDPNRatios () const
 
const EcalLaserAPDPNRatiosRefgetAPDPNRatiosRef () const
 
float getLaserCorrection (DetId const &xid, edm::Timestamp const &iTime) const
 
const EcalLinearCorrectionsgetLinearCorrections () const
 
void setAlphaData (const EcalLaserAlphas *fItem)
 
void setAPDPNData (const EcalLaserAPDPNRatios *fItem)
 
void setAPDPNRefData (const EcalLaserAPDPNRatiosRef *fItem)
 
void setLinearCorrectionsData (const EcalLinearCorrections *fItem)
 
void setMaxExtrapolationTimeInSec (int deltaT)
 

Private Types

typedef tbb::concurrent_unordered_set< uint32_t > ErrorMapT
 

Private Attributes

ErrorMapT channelsWithInvalidCorrection_
 
const EcalLaserAlphasmAlphas_
 
const EcalLaserAPDPNRatiosmAPDPNRatios_
 
const EcalLaserAPDPNRatiosRefmAPDPNRatiosRef_
 
unsigned long long maxExtrapolationTime_
 
const EcalLinearCorrectionsmLinearCorrections_
 

Detailed Description

Definition at line 25 of file EcalLaserDbService.h.

Member Typedef Documentation

◆ ErrorMapT

typedef tbb::concurrent_unordered_set<uint32_t> EcalLaserDbService::ErrorMapT
private

Definition at line 49 of file EcalLaserDbService.h.

Constructor & Destructor Documentation

◆ EcalLaserDbService()

EcalLaserDbService::EcalLaserDbService ( )

Definition at line 15 of file EcalLaserDbService.cc.

16  : mAlphas_(nullptr),
17  mAPDPNRatiosRef_(nullptr),
18  mAPDPNRatios_(nullptr),
19  mLinearCorrections_(nullptr),
unsigned long long maxExtrapolationTime_
const EcalLinearCorrections * mLinearCorrections_
const EcalLaserAPDPNRatiosRef * mAPDPNRatiosRef_
const EcalLaserAPDPNRatios * mAPDPNRatios_
const EcalLaserAlphas * mAlphas_

Member Function Documentation

◆ getAlphas()

const EcalLaserAlphas * EcalLaserDbService::getAlphas ( ) const

Definition at line 22 of file EcalLaserDbService.cc.

References mAlphas_.

22 { return mAlphas_; }
const EcalLaserAlphas * mAlphas_

◆ getAPDPNRatios()

const EcalLaserAPDPNRatios * EcalLaserDbService::getAPDPNRatios ( ) const

Definition at line 26 of file EcalLaserDbService.cc.

References mAPDPNRatios_.

26 { return mAPDPNRatios_; }
const EcalLaserAPDPNRatios * mAPDPNRatios_

◆ getAPDPNRatiosRef()

const EcalLaserAPDPNRatiosRef * EcalLaserDbService::getAPDPNRatiosRef ( ) const

Definition at line 24 of file EcalLaserDbService.cc.

References mAPDPNRatiosRef_.

24 { return mAPDPNRatiosRef_; }
const EcalLaserAPDPNRatiosRef * mAPDPNRatiosRef_

◆ getLaserCorrection()

float EcalLaserDbService::getLaserCorrection ( DetId const &  xid,
edm::Timestamp const &  iTime 
) const

Definition at line 30 of file EcalLaserDbService.cc.

References alpha, channelsWithInvalidCorrection_, DetId::det(), DetId::Ecal, EcalBarrel, EcalEndcap, EcalCondObjectContainer< T >::end(), f, EcalCondObjectContainer< T >::find(), dqmMemoryStats::float, EcalLaserAPDPNRatios::getLaserMap(), EcalCondObjectContainer< T >::getMap(), EcalTimeDependentCorrections::getTimeMap(), EcalLaserAPDPNRatios::getTimeMap(), EcalTimeDependentCorrections::getValueMap(), EBDetId::hashedIndex(), EEDetId::hashedIndex(), PixelPluginsPhase0_cfi::isBarrel, MEEBGeom::lmr(), MEEEGeom::lmr(), mAlphas_, mAPDPNRatios_, mAPDPNRatiosRef_, maxExtrapolationTime_, mLinearCorrections_, EcalTimeDependentCorrections::Values::p1, EcalLaserAPDPNRatios::EcalLaserAPDPNpair::p1, EcalTimeDependentCorrections::Values::p2, EcalLaserAPDPNRatios::EcalLaserAPDPNpair::p2, EcalLaserAPDPNRatios::EcalLaserAPDPNpair::p3, EcalTimeDependentCorrections::Values::p3, funct::pow(), DetId::rawId(), edm::second(), DetId::subdetId(), submitPVValidationJobs::t, EcalTimeDependentCorrections::Times::t1, EcalTimeDependentCorrections::Times::t2, EcalTimeDependentCorrections::Times::t3, cond::timestamp, groupFilesInBlocks::tt, and edm::Timestamp::value().

Referenced by EcalClusterLazyToolsBase::BasicClusterTime(), EcalHitResponse::findLaserConstant(), EcalSignalGenerator< EEDigitizerTraits >::findLaserConstant_LC(), EcalSignalGenerator< EEDigitizerTraits >::findLaserConstant_LC_prime(), EcalRecalibRecHitProducer::produce(), and EcalRecHitWorkerSimple::run().

30  {
31  float correctionFactor = 1.0;
32 
35  const EcalLaserAPDPNRatiosRefMap& laserRefMap = mAPDPNRatiosRef_->getMap();
36  const EcalLaserAlphaMap& laserAlphaMap = mAlphas_->getMap();
39 
42  EcalLaserAPDPNref apdpnref;
46 
47  if (xid.det() == DetId::Ecal) {
48  } else {
49  edm::LogError("EcalLaserDbService") << " DetId is NOT in ECAL" << endl;
50  return correctionFactor;
51  }
52 
53  int iLM;
54  int xind;
55  bool isBarrel = true;
56  if (xid.subdetId() == EcalBarrel) {
57  EBDetId ebid(xid.rawId());
58  xind = ebid.hashedIndex();
59  iLM = MEEBGeom::lmr(ebid.ieta(), ebid.iphi());
60  } else if (xid.subdetId() == EcalEndcap) {
61  isBarrel = false;
62  EEDetId eeid(xid.rawId());
63  xind = eeid.hashedIndex();
64  // SuperCrystal coordinates
65  MEEEGeom::SuperCrysCoord iX = (eeid.ix() - 1) / 5 + 1;
66  MEEEGeom::SuperCrysCoord iY = (eeid.iy() - 1) / 5 + 1;
67  iLM = MEEEGeom::lmr(iX, iY, eeid.zside());
68  } else {
69  edm::LogError("EcalLaserDbService") << " DetId is NOT in ECAL Barrel or Endcap" << endl;
70  return correctionFactor;
71  }
72  // std::cout << " LM num ====> " << iLM << endl;
73 
74  // get alpha, apd/pn ref, apd/pn pairs and timestamps for interpolation
75 
76 #ifdef VERIFY_LASER
78  if (itratio != laserRatiosMap.end()) {
79  apdpnpair = (*itratio);
80  } else {
81  edm::LogError("EcalLaserDbService") << "error with laserRatiosMap!" << endl;
82  return correctionFactor;
83  }
84 
85  if (iLM - 1 < (int)laserTimeMap.size()) {
86  timestamp = laserTimeMap[iLM - 1];
87  } else {
88  edm::LogError("EcalLaserDbService") << "error with laserTimeMap!" << endl;
89  return correctionFactor;
90  }
91 
93  if (itlin != linearValueMap.end()) {
94  linValues = (*itlin);
95  } else {
96  edm::LogError("EcalLaserDbService") << "error with linearValueMap!" << endl;
97  return correctionFactor;
98  }
99 
100  if (iLM - 1 < (int)linearTimeMap.size()) {
101  linTimes = linearTimeMap[iLM - 1];
102  } else {
103  edm::LogError("EcalLaserDbService") << "error with laserTimeMap!" << endl;
104  return correctionFactor;
105  }
106 
107  EcalLaserAPDPNRatiosRefMap::const_iterator itref = laserRefMap.find(xid);
108  if (itref != laserRefMap.end()) {
109  apdpnref = (*itref);
110  } else {
111  edm::LogError("EcalLaserDbService") << "error with laserRefMap!" << endl;
112  return correctionFactor;
113  }
114 
115  EcalLaserAlphaMap::const_iterator italpha = laserAlphaMap.find(xid);
116  if (italpha != laserAlphaMap.end()) {
117  alpha = (*italpha);
118  } else {
119  edm::LogError("EcalLaserDbService") << "error with laserAlphaMap!" << endl;
120  return correctionFactor;
121  }
122 
123 #else
124 
125  // waiting for templated lambdas
126  auto getCond = [=](EcalFloatCondObjectContainer const& cond) -> float {
127  return isBarrel ? cond.barrel(xind) : cond.endcap(xind);
128  };
129 
130  auto getPair =
132  return isBarrel ? cond.barrel(xind) : cond.endcap(xind);
133  };
134 
136  return isBarrel ? cond.barrel(xind) : cond.endcap(xind);
137  };
138 
139  apdpnpair = getPair(laserRatiosMap);
140  linValues = getLinear(linearValueMap);
141  apdpnref = getCond(laserRefMap);
142  alpha = getCond(laserAlphaMap);
143 
144  if (iLM - 1 < (int)laserTimeMap.size()) {
145  timestamp = laserTimeMap[iLM - 1];
146  } else {
147  edm::LogError("EcalLaserDbService") << "error with laserTimeMap!" << endl;
148  return correctionFactor;
149  }
150 
151  if (iLM - 1 < (int)linearTimeMap.size()) {
152  linTimes = linearTimeMap[iLM - 1];
153  } else {
154  edm::LogError("EcalLaserDbService") << "error with laserTimeMap!" << endl;
155  return correctionFactor;
156  }
157 
158 #endif
159 
160  // should implement some default in case of error...
161 
162  // should do some quality checks first
163  // ...
164 
165  // we will need to treat time differently...
166  // is time in DB same format as in MC? probably not...
167 
168  // interpolation
169 
170  edm::TimeValue_t t = iTime.value();
171  long long t_i = 0, t_f = 0;
172  float p_i = 0, p_f = 0;
173  long long lt_i = 0, lt_f = 0;
174  float lp_i = 0, lp_f = 0;
175 
176  if (t >= timestamp.t1.value() && t < timestamp.t2.value()) {
177  t_i = timestamp.t1.value();
178  t_f = timestamp.t2.value();
179  p_i = apdpnpair.p1;
180  p_f = apdpnpair.p2;
181  } else if (t >= timestamp.t2.value() && t <= timestamp.t3.value()) {
182  t_i = timestamp.t2.value();
183  t_f = timestamp.t3.value();
184  p_i = apdpnpair.p2;
185  p_f = apdpnpair.p3;
186  } else if (t < timestamp.t1.value()) {
187  t_i = timestamp.t1.value();
188  t_f = timestamp.t2.value();
189  p_i = apdpnpair.p1;
190  p_f = apdpnpair.p2;
191 
192  } else if (t > timestamp.t3.value()) {
193  t_i = timestamp.t2.value();
194  t_f = timestamp.t3.value();
195  p_i = apdpnpair.p2;
196  p_f = apdpnpair.p3;
197  }
198 
199  long long t_laser = t;
200  if (t > timestamp.t3.value() + maxExtrapolationTime_)
201  t_laser = ((long long)timestamp.t3.value()) + maxExtrapolationTime_;
202 
203  if (t >= linTimes.t1.value() && t < linTimes.t2.value()) {
204  lt_i = linTimes.t1.value();
205  lt_f = linTimes.t2.value();
206  lp_i = linValues.p1;
207  lp_f = linValues.p2;
208  } else if (t >= linTimes.t2.value() && t <= linTimes.t3.value()) {
209  lt_i = linTimes.t2.value();
210  lt_f = linTimes.t3.value();
211  lp_i = linValues.p2;
212  lp_f = linValues.p3;
213  } else if (t < linTimes.t1.value()) {
214  lt_i = linTimes.t1.value();
215  lt_f = linTimes.t2.value();
216  lp_i = linValues.p1;
217  lp_f = linValues.p2;
218 
219  } else if (t > linTimes.t3.value()) {
220  lt_i = linTimes.t2.value();
221  lt_f = linTimes.t3.value();
222  lp_i = linValues.p2;
223  lp_f = linValues.p3;
224  }
225 
226  if (apdpnref != 0 && (t_i - t_f) != 0 && (lt_i - lt_f) != 0) {
227  long long tt = t; // never subtract two unsigned!
228  float interpolatedLaserResponse =
229  p_i / apdpnref + float(t_laser - t_i) * (p_f - p_i) / (apdpnref * float(t_f - t_i));
230  float interpolatedLinearResponse =
231  lp_i / apdpnref + float(tt - lt_i) * (lp_f - lp_i) / (apdpnref * float(lt_f - lt_i)); // FIXED BY FC
232 
233  if (interpolatedLinearResponse > 2.f || interpolatedLinearResponse < 0.1f)
234  interpolatedLinearResponse = 1.f;
235  if (interpolatedLaserResponse <= 0.) {
236  // print message only if it is the first time we see < 0
237  // on this detid
238  if (channelsWithInvalidCorrection_.insert(xid.rawId()).second) {
239  edm::LogError("EcalLaserDbService") << "Interpolated Laser correction <0 for detid " << xid.rawId();
240  }
241 
242  return correctionFactor;
243 
244  } else {
245  float interpolatedTransparencyResponse = interpolatedLaserResponse / interpolatedLinearResponse;
246 
247  correctionFactor = 1.f / (std::pow(interpolatedTransparencyResponse, alpha) * interpolatedLinearResponse);
248  }
249 
250  } else {
251  edm::LogError("EcalLaserDbService") << "apdpnref (" << apdpnref << ") "
252  << "or t_i-t_f (" << (t_i - t_f) << " is zero!";
253  return correctionFactor;
254  }
255 
256  return correctionFactor;
257 }
const EcalLaserAPDPNRatiosMap & getLaserMap() const
float EcalLaserAlpha
float alpha
Definition: AMPTWrapper.h:105
const EcalValueMap & getValueMap() const
ErrorMapT channelsWithInvalidCorrection_
unsigned long long maxExtrapolationTime_
static int lmr(EBGlobalCoord ieta, EBGlobalCoord iphi)
Definition: MEEBGeom.cc:110
Log< level::Error, false > LogError
float EcalLaserAPDPNref
const EcalTimeMap & getTimeMap() const
U second(std::pair< T, U > const &p)
const EcalLinearCorrections * mLinearCorrections_
const EcalLaserAPDPNRatiosRef * mAPDPNRatiosRef_
const EcalLaserTimeStampMap & getTimeMap() const
double f[11][100]
unsigned long long TimeValue_t
Definition: Timestamp.h:28
const_iterator find(uint32_t rawId) const
int SuperCrysCoord
Definition: MEEEGeom.h:20
TimeValue_t value() const
Definition: Timestamp.h:45
std::vector< EcalLaserTimeStamp > EcalLaserTimeStampMap
const EcalLaserAPDPNRatios * mAPDPNRatios_
std::vector< Item >::const_iterator const_iterator
const EcalLaserAlphas * mAlphas_
Definition: plugin.cc:23
int hashedIndex() const
get a compact index for arrays
Definition: EBDetId.h:82
const_iterator end() const
int hashedIndex() const
Definition: EEDetId.h:183
static int lmr(SuperCrysCoord iX, SuperCrysCoord iY, int iz)
Definition: MEEEGeom.cc:254
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29

◆ getLinearCorrections()

const EcalLinearCorrections * EcalLaserDbService::getLinearCorrections ( ) const

Definition at line 28 of file EcalLaserDbService.cc.

References mLinearCorrections_.

28 { return mLinearCorrections_; }
const EcalLinearCorrections * mLinearCorrections_

◆ setAlphaData()

void EcalLaserDbService::setAlphaData ( const EcalLaserAlphas fItem)
inline

Definition at line 35 of file EcalLaserDbService.h.

References mAlphas_.

35 { mAlphas_ = fItem; }
const EcalLaserAlphas * mAlphas_

◆ setAPDPNData()

void EcalLaserDbService::setAPDPNData ( const EcalLaserAPDPNRatios fItem)
inline

Definition at line 37 of file EcalLaserDbService.h.

References mAPDPNRatios_.

37 { mAPDPNRatios_ = fItem; }
const EcalLaserAPDPNRatios * mAPDPNRatios_

◆ setAPDPNRefData()

void EcalLaserDbService::setAPDPNRefData ( const EcalLaserAPDPNRatiosRef fItem)
inline

Definition at line 36 of file EcalLaserDbService.h.

References mAPDPNRatiosRef_.

36 { mAPDPNRatiosRef_ = fItem; }
const EcalLaserAPDPNRatiosRef * mAPDPNRatiosRef_

◆ setLinearCorrectionsData()

void EcalLaserDbService::setLinearCorrectionsData ( const EcalLinearCorrections fItem)
inline

Definition at line 38 of file EcalLaserDbService.h.

References mLinearCorrections_.

38 { mLinearCorrections_ = fItem; }
const EcalLinearCorrections * mLinearCorrections_

◆ setMaxExtrapolationTimeInSec()

void EcalLaserDbService::setMaxExtrapolationTimeInSec ( int  deltaT)
inline

Definition at line 40 of file EcalLaserDbService.h.

References maxExtrapolationTime_.

40 { maxExtrapolationTime_ = ((unsigned long long)deltaT) << 32; }
unsigned long long maxExtrapolationTime_

Member Data Documentation

◆ channelsWithInvalidCorrection_

ErrorMapT EcalLaserDbService::channelsWithInvalidCorrection_
mutableprivate

Definition at line 50 of file EcalLaserDbService.h.

Referenced by getLaserCorrection().

◆ mAlphas_

const EcalLaserAlphas* EcalLaserDbService::mAlphas_
private

Definition at line 43 of file EcalLaserDbService.h.

Referenced by getAlphas(), getLaserCorrection(), and setAlphaData().

◆ mAPDPNRatios_

const EcalLaserAPDPNRatios* EcalLaserDbService::mAPDPNRatios_
private

Definition at line 45 of file EcalLaserDbService.h.

Referenced by getAPDPNRatios(), getLaserCorrection(), and setAPDPNData().

◆ mAPDPNRatiosRef_

const EcalLaserAPDPNRatiosRef* EcalLaserDbService::mAPDPNRatiosRef_
private

Definition at line 44 of file EcalLaserDbService.h.

Referenced by getAPDPNRatiosRef(), getLaserCorrection(), and setAPDPNRefData().

◆ maxExtrapolationTime_

unsigned long long EcalLaserDbService::maxExtrapolationTime_
private

Definition at line 47 of file EcalLaserDbService.h.

Referenced by getLaserCorrection(), and setMaxExtrapolationTimeInSec().

◆ mLinearCorrections_

const EcalLinearCorrections* EcalLaserDbService::mLinearCorrections_
private