CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalLaserDbService.cc
Go to the documentation of this file.
1 #include <iostream>
2 
4 
6 
9 // #include "CalibCalorimetry/EcalLaserAnalyzer/interface/ME.h"
10 
11 
13 
14 using namespace std;
15 
17  :
18  mAlphas_ (0),
19  mAPDPNRatiosRef_ (0),
20  mAPDPNRatios_ (0)
21  {}
22 
23 
24 
26  return mAlphas_;
27 }
28 
30  return mAPDPNRatiosRef_;
31 }
32 
34  return mAPDPNRatios_;
35 }
36 
37 
38 float EcalLaserDbService::getLaserCorrection (DetId const & xid, edm::Timestamp const & iTime) const {
39 
40  float correctionFactor = 1.0;
41 
44  const EcalLaserAPDPNRatiosRefMap& laserRefMap = mAPDPNRatiosRef_->getMap();
45  const EcalLaserAlphaMap& laserAlphaMap = mAlphas_->getMap();
46 
49  EcalLaserAPDPNref apdpnref;
51 
52  if (xid.det()==DetId::Ecal) {
53  // std::cout << " XID is in Ecal : ";
54  } else {
55  // std::cout << " XID is NOT in Ecal : ";
56  edm::LogError("EcalLaserDbService") << " DetId is NOT in ECAL" << endl;
57  return correctionFactor;
58  }
59 
60 // int hi = -1;
61 // if (xid.subdetId()==EcalBarrel) {
62 // // std::cout << "EcalBarrel" << std::endl;
63 // // std::cout << "--> rawId() = " << xid.rawId() << " id() = " << EBDetId( xid ).hashedIndex() << std::endl;
64 // hi = EBDetId( xid ).hashedIndex();
65 // } else if (xid.subdetId()==EcalEndcap) {
66 // // std::cout << "EcalEndcap" << std::endl;
67 // hi = EEDetId( xid ).hashedIndex() + EBDetId::MAX_HASH + 1;
68 //
69 // } else {
70 // // std::cout << "NOT EcalBarrel or EcalEndCap" << std::endl;
71 // edm::LogError("EcalLaserDbService") << " DetId is NOT in ECAL Barrel or Endcap" << endl;
72 // return correctionFactor;
73 // }
74 
75  int iLM;
76  if (xid.subdetId()==EcalBarrel) {
77  EBDetId ebid( xid.rawId() );
78  iLM = MEEBGeom::lmr(ebid.ieta(), ebid.iphi());
79  } else if (xid.subdetId()==EcalEndcap) {
80  EEDetId eeid( xid.rawId() );
81  // SuperCrystal coordinates
82  MEEEGeom::SuperCrysCoord iX = (eeid.ix()-1)/5 + 1;
83  MEEEGeom::SuperCrysCoord iY = (eeid.iy()-1)/5 + 1;
84  iLM = MEEEGeom::lmr(iX, iY, eeid.zside());
85  } else {
86  edm::LogError("EcalLaserDbService") << " DetId is NOT in ECAL Barrel or Endcap" << endl;
87  return correctionFactor;
88  }
89  // std::cout << " LM num ====> " << iLM << endl;
90 
91  // get alpha, apd/pn ref, apd/pn pairs and timestamps for interpolation
92 
94  if (itratio != laserRatiosMap.end()) {
95  apdpnpair = (*itratio);
96  } else {
97  edm::LogError("EcalLaserDbService") << "error with laserRatiosMap!" << endl;
98  return correctionFactor;
99  }
100 
101  if (iLM-1< (int)laserTimeMap.size()) {
102  timestamp = laserTimeMap[iLM-1];
103  } else {
104  edm::LogError("EcalLaserDbService") << "error with laserTimeMap!" << endl;
105  return correctionFactor;
106  }
107 
108  EcalLaserAPDPNRatiosRefMap::const_iterator itref = laserRefMap.find(xid);
109  if ( itref != laserRefMap.end() ) {
110  apdpnref = (*itref);
111  } else {
112  edm::LogError("EcalLaserDbService") << "error with laserRefMap!" << endl;
113  return correctionFactor;
114  }
115 
116  EcalLaserAlphaMap::const_iterator italpha = laserAlphaMap.find(xid);
117  if ( italpha != laserAlphaMap.end() ) {
118  alpha = (*italpha);
119  } else {
120  edm::LogError("EcalLaserDbService") << "error with laserAlphaMap!" << endl;
121  return correctionFactor;
122  }
123 
124  // std::cout << " APDPN pair " << apdpnpair.p1 << " , " << apdpnpair.p2 << std::endl;
125  // std::cout << " TIME pair " << timestamp.t1.value() << " , " << timestamp.t2.value() << " iLM " << iLM << std::endl;
126  // std::cout << " LM module " << iLM << std::endl;
127  // std::cout << " APDPN ref " << apdpnref << std::endl;
128  // std::cout << " ALPHA " << alpha << std::endl;
129 
130  // should implement some default in case of error...
131 
132  // should do some quality checks first
133  // ...
134 
135  // we will need to treat time differently...
136  // is time in DB same format as in MC? probably not...
137 
138  // interpolation
139 
140  edm::TimeValue_t t = iTime.value();
141  edm::TimeValue_t t_i = 0, t_f = 0;
142  float p_i = 0, p_f = 0;
143 
144  if ( t >= timestamp.t1.value() && t < timestamp.t2.value() ) {
145  t_i = timestamp.t1.value();
146  t_f = timestamp.t2.value();
147  p_i = apdpnpair.p1;
148  p_f = apdpnpair.p2;
149  } else if ( t >= timestamp.t2.value() && t <= timestamp.t3.value() ) {
150  t_i = timestamp.t2.value();
151  t_f = timestamp.t3.value();
152  p_i = apdpnpair.p2;
153  p_f = apdpnpair.p3;
154  } else if ( t < timestamp.t1.value() ) {
155  t_i = timestamp.t1.value();
156  t_f = timestamp.t2.value();
157  p_i = apdpnpair.p1;
158  p_f = apdpnpair.p2;
159  //edm::LogWarning("EcalLaserDbService") << "The event timestamp t=" << t
160  // << " is lower than t1=" << t_i << ". Extrapolating...";
161  } else if ( t > timestamp.t3.value() ) {
162  t_i = timestamp.t2.value();
163  t_f = timestamp.t3.value();
164  p_i = apdpnpair.p2;
165  p_f = apdpnpair.p3;
166  //edm::LogWarning("EcalLaserDbService") << "The event timestamp t=" << t
167  // << " is greater than t3=" << t_f << ". Extrapolating...";
168  }
169 
170  if ( apdpnref != 0 && (t_i - t_f) != 0) {
171  float interpolatedLaserResponse = p_i/apdpnref + (t-t_i)*(p_f-p_i)/apdpnref/(t_f-t_i);
172  if ( interpolatedLaserResponse <= 0 ) {
173  edm::LogError("EcalLaserDbService") << "The interpolated laser correction is <= zero! ("
174  << interpolatedLaserResponse << "). Using 1. as correction factor.";
175  return correctionFactor;
176  } else {
177  correctionFactor = 1/pow(interpolatedLaserResponse,alpha);
178  }
179 
180  } else {
181  edm::LogError("EcalLaserDbService")
182  << "apdpnref (" << apdpnref << ") "
183  << "or t_i-t_f (" << (t_i - t_f) << " is zero!";
184  return correctionFactor;
185  }
186 
187  return correctionFactor;
188 }
189 
190 
float EcalLaserAlpha
float alpha
Definition: AMPTWrapper.h:95
const EcalLaserAPDPNRatios * getAPDPNRatios() const
const self & getMap() const
float getLaserCorrection(DetId const &xid, edm::Timestamp const &iTime) const
static int lmr(EBGlobalCoord ieta, EBGlobalCoord iphi)
Definition: MEEBGeom.cc:121
float EcalLaserAPDPNref
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
const EcalLaserAPDPNRatiosMap & getLaserMap() const
const EcalLaserAPDPNRatiosRef * mAPDPNRatiosRef_
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:39
unsigned long long TimeValue_t
Definition: Timestamp.h:27
int SuperCrysCoord
Definition: MEEEGeom.h:22
#define TYPELOOKUP_DATA_REG(_dataclass_)
Definition: typelookup.h:97
TimeValue_t value() const
Definition: Timestamp.cc:72
Definition: DetId.h:20
const EcalLaserAlphas * getAlphas() const
const EcalLaserTimeStampMap & getTimeMap() const
std::vector< EcalLaserTimeStamp > EcalLaserTimeStampMap
const EcalLaserAPDPNRatios * mAPDPNRatios_
std::vector< Item >::const_iterator const_iterator
const EcalLaserAlphas * mAlphas_
const EcalLaserAPDPNRatiosRef * getAPDPNRatiosRef() const
const_iterator find(uint32_t rawId) const
const_iterator end() const
Detector det() const
get the detector field from this detid
Definition: DetId.h:37
static int lmr(SuperCrysCoord iX, SuperCrysCoord iY, int iz)
Definition: MEEEGeom.cc:251
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40