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 
7 
8 
10 
11 using namespace std;
12 
14  :
15  mAlphas_ (0),
16  mAPDPNRatiosRef_ (0),
17  mAPDPNRatios_ (0)
18  {}
19 
20 
21 
23  return mAlphas_;
24 }
25 
27  return mAPDPNRatiosRef_;
28 }
29 
31  return mAPDPNRatios_;
32 }
33 
34 
35 float EcalLaserDbService::getLaserCorrection (DetId const & xid, edm::Timestamp const & iTime) const {
36 
37  float correctionFactor = 1.0;
38 
41  const EcalLaserAPDPNRatiosRefMap& laserRefMap = mAPDPNRatiosRef_->getMap();
42  const EcalLaserAlphaMap& laserAlphaMap = mAlphas_->getMap();
43 
46  EcalLaserAPDPNref apdpnref;
48 
49  if (xid.det()==DetId::Ecal) {
50  // std::cout << " XID is in Ecal : ";
51  } else {
52  // std::cout << " XID is NOT in Ecal : ";
53  edm::LogError("EcalLaserDbService") << " DetId is NOT in ECAL" << endl;
54  return correctionFactor;
55  }
56 
57 // int hi = -1;
58 // if (xid.subdetId()==EcalBarrel) {
59 // // std::cout << "EcalBarrel" << std::endl;
60 // // std::cout << "--> rawId() = " << xid.rawId() << " id() = " << EBDetId( xid ).hashedIndex() << std::endl;
61 // hi = EBDetId( xid ).hashedIndex();
62 // } else if (xid.subdetId()==EcalEndcap) {
63 // // std::cout << "EcalEndcap" << std::endl;
64 // hi = EEDetId( xid ).hashedIndex() + EBDetId::MAX_HASH + 1;
65 //
66 // } else {
67 // // std::cout << "NOT EcalBarrel or EcalEndCap" << std::endl;
68 // edm::LogError("EcalLaserDbService") << " DetId is NOT in ECAL Barrel or Endcap" << endl;
69 // return correctionFactor;
70 // }
71 
72  int iLM = getLMNumber(xid);
73  // std::cout << " LM num ====> " << iLM << endl;
74 
75  // get alpha, apd/pn ref, apd/pn pairs and timestamps for interpolation
76 
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 
92  EcalLaserAPDPNRatiosRefMap::const_iterator itref = laserRefMap.find(xid);
93  if ( itref != laserRefMap.end() ) {
94  apdpnref = (*itref);
95  } else {
96  edm::LogError("EcalLaserDbService") << "error with laserRefMap!" << endl;
97  return correctionFactor;
98  }
99 
100  EcalLaserAlphaMap::const_iterator italpha = laserAlphaMap.find(xid);
101  if ( italpha != laserAlphaMap.end() ) {
102  alpha = (*italpha);
103  } else {
104  edm::LogError("EcalLaserDbService") << "error with laserAlphaMap!" << endl;
105  return correctionFactor;
106  }
107 
108  // std::cout << " APDPN pair " << apdpnpair.p1 << " , " << apdpnpair.p2 << std::endl;
109  // std::cout << " TIME pair " << timestamp.t1.value() << " , " << timestamp.t2.value() << " iLM " << iLM << std::endl;
110  // std::cout << " LM module " << iLM << std::endl;
111  // std::cout << " APDPN ref " << apdpnref << std::endl;
112  // std::cout << " ALPHA " << alpha << std::endl;
113 
114  // should implement some default in case of error...
115 
116  // should do some quality checks first
117  // ...
118 
119  // we will need to treat time differently...
120  // is time in DB same format as in MC? probably not...
121 
122  // interpolation
123 
124  edm::TimeValue_t t = iTime.value();
125  edm::TimeValue_t t_i = 0, t_f = 0;
126  float p_i = 0, p_f = 0;
127 
128  if ( t >= timestamp.t1.value() && t < timestamp.t2.value() ) {
129  t_i = timestamp.t1.value();
130  t_f = timestamp.t2.value();
131  p_i = apdpnpair.p1;
132  p_f = apdpnpair.p2;
133  } else if ( t >= timestamp.t2.value() && t <= timestamp.t3.value() ) {
134  t_i = timestamp.t2.value();
135  t_f = timestamp.t3.value();
136  p_i = apdpnpair.p2;
137  p_f = apdpnpair.p3;
138  } else if ( t < timestamp.t1.value() ) {
139  t_i = timestamp.t1.value();
140  t_f = timestamp.t2.value();
141  p_i = apdpnpair.p1;
142  p_f = apdpnpair.p2;
143  //edm::LogWarning("EcalLaserDbService") << "The event timestamp t=" << t
144  // << " is lower than t1=" << t_i << ". Extrapolating...";
145  } else if ( t > timestamp.t3.value() ) {
146  t_i = timestamp.t2.value();
147  t_f = timestamp.t3.value();
148  p_i = apdpnpair.p2;
149  p_f = apdpnpair.p3;
150  //edm::LogWarning("EcalLaserDbService") << "The event timestamp t=" << t
151  // << " is greater than t3=" << t_f << ". Extrapolating...";
152  }
153 
154  if ( apdpnref != 0 && (t_i - t_f) != 0) {
155  float interpolatedLaserResponse = p_i/apdpnref + (t-t_i)*(p_f-p_i)/apdpnref/(t_f-t_i);
156  if ( interpolatedLaserResponse <= 0 ) {
157  edm::LogError("EcalLaserDbService") << "The interpolated laser correction is <= zero! ("
158  << interpolatedLaserResponse << "). Using 1. as correction factor.";
159  return correctionFactor;
160  } else {
161  correctionFactor = 1/pow(interpolatedLaserResponse,alpha);
162  }
163 
164  } else {
165  edm::LogError("EcalLaserDbService")
166  << "apdpnref (" << apdpnref << ") "
167  << "or t_i-t_f (" << (t_i - t_f) << " is zero!";
168  return correctionFactor;
169  }
170 
171  return correctionFactor;
172 }
173 
174 //
175 // function to map EB or EE xtal to light monitoring module readout number
176 // (should eventually port this code as a map in a more appropriate package)
177 //
178 int EcalLaserDbService::getLMNumber(DetId const & xid) const {
179 
180  int iLM = 0;
181 
182  if (xid.subdetId()==EcalBarrel) {
183 
184  EBDetId tempid(xid.rawId());
185 
186  int iSM = tempid.ism();
187  int iETA = tempid.ietaSM();
188  int iPHI = tempid.iphiSM();
189 
190  const int nSM = 36;
191  int numLM[nSM] = {37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35};
192 
193  if (iSM<=nSM) {
194  iLM = numLM[iSM-1];
195  }
196  // now assign light module within SM
197  if (iPHI>10&&iETA>5) { iLM++; }
198 
199  // std::cout << " SM , LM ---> " << iSM << " " << iLM << std::endl;
200 
201  } else if (xid.subdetId()==EcalEndcap) {
202 
203  EEDetId tempid(xid.rawId());
204 
205  int iSC = tempid.isc();
206  int iX = tempid.ix();
207  // int iY = tempid.iy();
208  int iZ = tempid.zside();
209 
210  const int nSC = 312;
211  const int nEELM = 18;
212 
213 
214  // Z+ side
215  int indexSCpos[nSC] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163,164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 308, 309, 310, 311, 312, 313, 314, 315, 316 };
216 
217  int indexDCCpos[nSC] = { 48, 48, 48, 48, 48, 48, 48, 48, 47, 48, 48, 48, 48, 48, 48, 48, 48, 47, 47, 47, 48, 48, 48, 48, 48, 48, 48, 46, 47, 47, 47, 48, 48, 48, 48,48, 46, 47, 47, 47, 47, 48, 48, 48, 48, 46, 47, 47, 47, 47, 47, 47, 48, 48, 46, 47, 47, 47, 47, 47, 47, 47, 46, 47, 47, 47, 47, 47, 47, 46, 46, 47, 47, 47, 47, 46, 46, 47, 49, 49, 49, 49, 49, 49, 49, 49, 50, 49, 49, 49, 49, 49, 49, 49, 49, 50, 50, 50, 49, 49, 49, 49, 49, 49, 49, 51, 50, 50, 50, 49, 49, 49, 49, 49, 51, 50, 50, 50, 50, 49, 49, 49, 49, 51, 50, 50, 50, 50, 50, 50, 49, 49, 51, 50, 50, 50, 50, 50, 50, 50, 51, 50, 50, 50, 50, 50, 50, 51, 51, 50, 50, 50, 50, 51, 51, 50, 53, 53, 53, 53, 53, 53, 53, 53, 52, 52, 52, 53, 53, 53, 53, 53, 53, 51, 52, 52, 52, 52, 52, 52, 53, 53, 53, 51, 51, 52, 52, 52, 52, 52, 52, 52, 51, 51, 51, 52, 52, 52, 52, 52, 52, 51, 51, 51, 52, 52, 52, 52, 52, 52,51, 51, 51, 51, 52, 52, 52, 52, 51, 51, 51, 51, 52, 52, 52, 51, 51, 51, 51, 51, 52, 51, 51, 51, 53, 53, 53, 53, 53, 53, 53, 53, 54, 54, 54,53, 53, 53, 53, 53, 53, 46, 54, 54, 54, 54, 54, 54, 53, 53, 53, 46, 46, 54, 54, 54, 54, 54, 54, 54, 46, 46, 46, 54, 54, 54, 54, 54, 54, 46, 46, 46, 54, 54, 54, 54, 54, 54, 46, 46, 46, 46, 54, 54, 54, 54, 46, 46, 46, 46, 54, 54, 54, 46, 46, 46, 46, 46, 54, 46, 46, 46 };
218 
219  // Z- side
220 
221  int indexSCneg[nSC] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 71, 72, 73,74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296,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CC[nEELM] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 46, 47, 48, 49, 50, 51, 52, 53, 54 };
226  int numLM[nEELM] = { 73, 74, 75, 76, 77, 78, 79, 80, 82, 83, 84, 85, 86, 87, 88, 89, 90, 92 };
227 
228  int tempdcc = 0;
229 
230  // assign SC to DCC
231  if (iZ>0) {
232  for (int i=0; i<nSC; i++) {
233  if (indexSCpos[i]==iSC) {
234  tempdcc = indexDCCpos[i];
235  break;
236  }
237  }
238  } else {
239  for (int i=0; i<nSC; i++) {
240  if (indexSCneg[i]==iSC) {
241  tempdcc = indexDCCneg[i];
242  break;
243  }
244  }
245  }
246 
247  // now assign LM number based on DCC
248  for (int j=0; j<nEELM; j++) {
249  if (tempdcc==numDCC[j]) {
250  iLM = numLM[j];
251  break;
252  }
253  }
254 
255  // now assign LM readout number for two exceptional cases:
256  if (tempdcc==53&&iX>50) {
257  iLM++;
258  } else if (tempdcc==8&&iX>50) {
259  iLM++;
260  }
261  } else {
262  edm::LogError("EcalLaserDbService") << " getLMNumber: DetId is not in ECAL." << endl;
263 
264  }
265 
266  return iLM;
267 
268 }
269 
270 
int i
Definition: DBlmapReader.cc:9
float EcalLaserAlpha
float alpha
Definition: AMPTWrapper.h:95
const EcalLaserAPDPNRatios * getAPDPNRatios() const
const self & getMap() const
int isc() const
Definition: EEDetId.cc:301
float getLaserCorrection(DetId const &xid, edm::Timestamp const &iTime) const
int getLMNumber(DetId const &xid) const
int ism() const
get the ECAL/SM id
Definition: EBDetId.cc:79
float EcalLaserAPDPNref
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
const EcalLaserAPDPNRatiosMap & getLaserMap() const
const EcalLaserAPDPNRatiosRef * mAPDPNRatiosRef_
int j
Definition: DBlmapReader.cc:9
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
#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
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40