CMS 3D CMS Logo

SiPixelGenError.cc
Go to the documentation of this file.
1 //
2 // SiPixelGenError.cc Version 2.00
3 //
4 // Object stores Lorentz widths, bias corrections, and errors for the Generic Algorithm
5 //
6 // Created by Morris Swartz on 10/27/06.
7 // Add some debugging messages. d.k. 5/14
8 // Update for Phase 1 FPix, M.S. 1/15/17
9 //
10 
11 //#include <stdlib.h>
12 //#include <stdio.h>
13 #ifndef SI_PIXEL_TEMPLATE_STANDALONE
14 #include <math.h>
15 #else
16 #include <math.h>
17 #endif
18 #include <algorithm>
19 #include <vector>
20 //#include "boost/multi_array.hpp"
21 #include <iostream>
22 #include <iomanip>
23 #include <sstream>
24 #include <fstream>
25 #include <list>
26 
27 
28 
29 #ifndef SI_PIXEL_TEMPLATE_STANDALONE
33 #define LOGERROR(x) LogError(x)
34 #define LOGWARNING(x) LogWarning(x)
35 #define LOGINFO(x) LogInfo(x)
36 #define ENDL " "
38 using namespace edm;
39 #else
40 #include "SiPixelGenError.h"
41 #define LOGERROR(x) std::cout << x << ": "
42 #define LOGINFO(x) std::cout << x << ": "
43 #define LOGWARNING(x) std::cout << x << ": "
44 #define ENDL std::endl
45 #endif
46 
47 //****************************************************************
52 //****************************************************************
53 bool SiPixelGenError::pushfile(int filenum, std::vector< SiPixelGenErrorStore > & thePixelTemp_)
54 {
55  // Add info stored in external file numbered filenum to theGenErrorStore
56 
57  // Local variables
58  int i, j, k;
59  float costrk[3]={0,0,0};
60  const char *tempfile;
61  // char title[80]; remove this
62  char c;
63  const int code_version={1};
64 
65 
66 
67  // Create a filename for this run
68 
69  std::ostringstream tout;
70 
71  // Create different path in CMSSW than standalone
72 
73 #ifndef SI_PIXEL_TEMPLATE_STANDALONE
74  tout << "CalibTracker/SiPixelESProducers/data/generror_summary_zp"
75  << std::setw(4) << std::setfill('0') << std::right << filenum << ".out" << std::ends;
76  std::string tempf = tout.str();
77  edm::FileInPath file( tempf.c_str() );
78  tempfile = (file.fullPath()).c_str();
79 #else
80  tout << "generror_summary_zp" << std::setw(4) << std::setfill('0') << std::right << filenum << ".out" << std::ends;
81  std::string tempf = tout.str();
82  tempfile = tempf.c_str();
83 #endif
84 
85  // open the Generic file
86 
87  std::ifstream in_file(tempfile, std::ios::in);
88 
89  if(in_file.is_open()) {
90 
91  // Create a local GenError storage entry
92 
93  SiPixelGenErrorStore theCurrentTemp;
94 
95  // Read-in a header string first and print it
96 
97  for (i=0; (c=in_file.get()) != '\n'; ++i) {
98  if(i < 79) {theCurrentTemp.head.title[i] = c;}
99  }
100  if(i > 78) {i=78;}
101  theCurrentTemp.head.title[i+1] ='\0';
102  LOGINFO("SiPixelGenError") << "Loading Pixel GenError File - " << theCurrentTemp.head.title << ENDL;
103 
104  // next, the header information
105 
106  in_file >> theCurrentTemp.head.ID >> theCurrentTemp.head.templ_version >> theCurrentTemp.head.Bfield >> theCurrentTemp.head.NTy >> theCurrentTemp.head.NTyx >> theCurrentTemp.head.NTxx >> theCurrentTemp.head.Dtype >> theCurrentTemp.head.Vbias >>
107  theCurrentTemp.head.temperature >> theCurrentTemp.head.fluence >> theCurrentTemp.head.qscale >> theCurrentTemp.head.s50 >>
108  theCurrentTemp.head.lorywidth >> theCurrentTemp.head.lorxwidth >> theCurrentTemp.head.ysize >> theCurrentTemp.head.xsize >>
109  theCurrentTemp.head.zsize >> theCurrentTemp.head.ss50 >> theCurrentTemp.head.lorybias >> theCurrentTemp.head.lorxbias >>
110  theCurrentTemp.head.fbin[0] >> theCurrentTemp.head.fbin[1] >> theCurrentTemp.head.fbin[2];
111 
112  if(in_file.fail()) {LOGERROR("SiPixelGenError") << "Error reading file, no GenError load" << ENDL; return false;}
113 
114  LOGINFO("SiPixelGenError") << "GenError ID = " << theCurrentTemp.head.ID << ", GenError Version " << theCurrentTemp.head.templ_version << ", Bfield = " << theCurrentTemp.head.Bfield
115  << ", NTy = " << theCurrentTemp.head.NTy << ", NTyx = " << theCurrentTemp.head.NTyx<< ", NTxx = " << theCurrentTemp.head.NTxx << ", Dtype = " << theCurrentTemp.head.Dtype
116  << ", Bias voltage " << theCurrentTemp.head.Vbias << ", temperature "
117  << theCurrentTemp.head.temperature << ", fluence " << theCurrentTemp.head.fluence << ", Q-scaling factor " << theCurrentTemp.head.qscale
118  << ", 1/2 multi dcol threshold " << theCurrentTemp.head.s50 << ", 1/2 single dcol threshold " << theCurrentTemp.head.ss50
119  << ", y Lorentz Width " << theCurrentTemp.head.lorywidth << ", y Lorentz Bias " << theCurrentTemp.head.lorybias
120  << ", x Lorentz width " << theCurrentTemp.head.lorxwidth << ", x Lorentz Bias " << theCurrentTemp.head.lorxbias
121  << ", Q/Q_avg fractions for Qbin defs " << theCurrentTemp.head.fbin[0] << ", " << theCurrentTemp.head.fbin[1]
122  << ", " << theCurrentTemp.head.fbin[2]
123  << ", pixel x-size " << theCurrentTemp.head.xsize << ", y-size " << theCurrentTemp.head.ysize << ", zsize " << theCurrentTemp.head.zsize << ENDL;
124 
125  if(theCurrentTemp.head.templ_version < code_version) {LOGERROR("SiPixelGenError") << "code expects version " << code_version << ", no GenError load" << ENDL; return false;}
126 
127 #ifdef SI_PIXEL_TEMPLATE_USE_BOOST
128 
129  // next, layout the 1-d/2-d structures needed to store GenError info
130 
131  theCurrentTemp.enty.resize(boost::extents[theCurrentTemp.head.NTy]);
132 
133  theCurrentTemp.entx.resize(boost::extents[theCurrentTemp.head.NTyx][theCurrentTemp.head.NTxx]);
134 
135 #endif
136 
137  // next, loop over all y-angle entries
138 
139  for (i=0; i < theCurrentTemp.head.NTy; ++i) {
140 
141  in_file >> theCurrentTemp.enty[i].runnum >> costrk[0] >> costrk[1] >> costrk[2];
142 
143  if(in_file.fail()) {LOGERROR("SiPixelGenError") << "Error reading file 1, no GenError load, run # " << theCurrentTemp.enty[i].runnum << ENDL; return false;}
144 
145  // Calculate the alpha, beta, and cot(beta) for this entry
146 
147  theCurrentTemp.enty[i].cotalpha = costrk[0]/costrk[2];
148 
149  theCurrentTemp.enty[i].cotbeta = costrk[1]/costrk[2];
150 
151  in_file >> theCurrentTemp.enty[i].qavg >> theCurrentTemp.enty[i].pixmax >> theCurrentTemp.enty[i].dyone
152  >> theCurrentTemp.enty[i].syone >> theCurrentTemp.enty[i].dxone >> theCurrentTemp.enty[i].sxone;
153 
154  if(in_file.fail()) {LOGERROR("SiPixelGenError") << "Error reading file 2, no GenError load, run # " << theCurrentTemp.enty[i].runnum << ENDL; return false;}
155 
156  in_file >> theCurrentTemp.enty[i].dytwo >> theCurrentTemp.enty[i].sytwo >> theCurrentTemp.enty[i].dxtwo
157  >> theCurrentTemp.enty[i].sxtwo >> theCurrentTemp.enty[i].qmin >> theCurrentTemp.enty[i].qmin2;
158 
159  if(in_file.fail()) {LOGERROR("SiPixelGenError") << "Error reading file 3, no GenError load, run # " << theCurrentTemp.enty[i].runnum << ENDL; return false;}
160 
161  if(theCurrentTemp.enty[i].qmin <= 0.) {LOGERROR("SiPixelGenError") << "Error in GenError ID " << theCurrentTemp.head.ID << " qmin = " << theCurrentTemp.enty[i].qmin << ", run # " << theCurrentTemp.enty[i].runnum << ENDL; return false;}
162 
163 
164  for (j=0; j<4; ++j) {
165 
166  in_file >> theCurrentTemp.enty[i].yavggen[j] >> theCurrentTemp.enty[i].yrmsgen[j] >> theCurrentTemp.enty[i].xavggen[j] >> theCurrentTemp.enty[i].xrmsgen[j];
167 
168  if(in_file.fail()) {LOGERROR("SiPixelGenError") << "Error reading file 14a, no GenError load, run # " << theCurrentTemp.enty[i].runnum << ENDL; return false;}
169  }
170 
171 
172  }
173 
174  // next, loop over all barrel x-angle entries
175 
176  for (k=0; k < theCurrentTemp.head.NTyx; ++k) {
177 
178  for (i=0; i < theCurrentTemp.head.NTxx; ++i) {
179 
180  in_file >> theCurrentTemp.entx[k][i].runnum >> costrk[0] >> costrk[1] >> costrk[2];
181 
182  if(in_file.fail()) {LOGERROR("SiPixelGenError") << "Error reading file 17, no GenError load, run # " << theCurrentTemp.entx[k][i].runnum << ENDL; return false;}
183 
184  // Calculate the alpha, beta, and cot(beta) for this entry
185 
186  theCurrentTemp.entx[k][i].cotalpha = costrk[0]/costrk[2];
187 
188  theCurrentTemp.entx[k][i].cotbeta = costrk[1]/costrk[2];
189 
190  in_file >> theCurrentTemp.entx[k][i].qavg >> theCurrentTemp.entx[k][i].pixmax >> theCurrentTemp.entx[k][i].dyone
191  >> theCurrentTemp.entx[k][i].syone >> theCurrentTemp.entx[k][i].dxone >> theCurrentTemp.entx[k][i].sxone;
192 
193  if(in_file.fail()) {LOGERROR("SiPixelGenError") << "Error reading file 18, no GenError load, run # " << theCurrentTemp.entx[k][i].runnum << ENDL; return false;}
194 
195  in_file >> theCurrentTemp.entx[k][i].dytwo >> theCurrentTemp.entx[k][i].sytwo >> theCurrentTemp.entx[k][i].dxtwo
196  >> theCurrentTemp.entx[k][i].sxtwo >> theCurrentTemp.entx[k][i].qmin >> theCurrentTemp.entx[k][i].qmin2;
197  // >> theCurrentTemp.entx[k][i].mpvvav >> theCurrentTemp.entx[k][i].sigmavav >> theCurrentTemp.entx[k][i].kappavav;
198 
199  if(in_file.fail()) {LOGERROR("SiPixelGenError") << "Error reading file 19, no GenError load, run # " << theCurrentTemp.entx[k][i].runnum << ENDL; return false;}
200 
201 
202  for (j=0; j<4; ++j) {
203 
204  in_file >> theCurrentTemp.entx[k][i].yavggen[j] >> theCurrentTemp.entx[k][i].yrmsgen[j] >> theCurrentTemp.entx[k][i].xavggen[j] >> theCurrentTemp.entx[k][i].xrmsgen[j];
205 
206  if(in_file.fail()) {LOGERROR("SiPixelGenError") << "Error reading file 30a, no GenError load, run # " << theCurrentTemp.entx[k][i].runnum << ENDL; return false;}
207  }
208 
209  }
210  }
211 
212 
213  in_file.close();
214 
215  // Add this info to the store
216 
217  thePixelTemp_.push_back(theCurrentTemp);
218 
219  postInit(thePixelTemp_);
220 
221  return true;
222 
223  } else {
224 
225  // If file didn't open, report this
226 
227  LOGERROR("SiPixelGenError") << "Error opening File" << tempfile << ENDL;
228  return false;
229 
230  }
231 
232 } // TempInit
233 
234 
235 #ifndef SI_PIXEL_TEMPLATE_STANDALONE
236 
237 //****************************************************************
241 //****************************************************************
243  std::vector< SiPixelGenErrorStore > & thePixelTemp_) {
244  // Add GenError stored in external dbobject to theGenErrorStore
245 
246  // Local variables
247  int i, j, k;
248  float costrk[3]={0,0,0};
249  // const char *tempfile;
250  const int code_version={1};
251 
252  // We must create a new object because dbobject must be a const and our stream must not be
253  SiPixelGenErrorDBObject db = dbobject;
254 
255  // Create a local GenError storage entry
256  SiPixelGenErrorStore theCurrentTemp;
257 
258  // Fill the GenError storage for each GenError calibration stored in the db
259  for(int m=0; m<db.numOfTempl(); ++m) {
260 
261  // Read-in a header string first and print it
262 
264  for (i=0; i<20; ++i) {
265  temp.f = db.sVector()[db.index()];
266  theCurrentTemp.head.title[4*i] = temp.c[0];
267  theCurrentTemp.head.title[4*i+1] = temp.c[1];
268  theCurrentTemp.head.title[4*i+2] = temp.c[2];
269  theCurrentTemp.head.title[4*i+3] = temp.c[3];
270  db.incrementIndex(1);
271  }
272 
273  theCurrentTemp.head.title[79] = '\0';
274  LOGINFO("SiPixelGenError") << "Loading Pixel GenError File - "
275  << theCurrentTemp.head.title << ENDL;
276 
277  // next, the header information
278 
279  db >> theCurrentTemp.head.ID >> theCurrentTemp.head.templ_version >> theCurrentTemp.head.Bfield >> theCurrentTemp.head.NTy >> theCurrentTemp.head.NTyx >> theCurrentTemp.head.NTxx >> theCurrentTemp.head.Dtype >> theCurrentTemp.head.Vbias >>
280  theCurrentTemp.head.temperature >> theCurrentTemp.head.fluence >> theCurrentTemp.head.qscale >> theCurrentTemp.head.s50 >>
281  theCurrentTemp.head.lorywidth >> theCurrentTemp.head.lorxwidth >> theCurrentTemp.head.ysize >> theCurrentTemp.head.xsize >>
282  theCurrentTemp.head.zsize >> theCurrentTemp.head.ss50 >> theCurrentTemp.head.lorybias >> theCurrentTemp.head.lorxbias >>
283  theCurrentTemp.head.fbin[0] >> theCurrentTemp.head.fbin[1] >> theCurrentTemp.head.fbin[2];
284 
285  if(db.fail()) {LOGERROR("SiPixelGenError")
286  << "Error reading file, no GenError load" << ENDL; return false;}
287 
288  LOGINFO("SiPixelGenError") << "GenError ID = " << theCurrentTemp.head.ID << ", GenError Version " << theCurrentTemp.head.templ_version << ", Bfield = " << theCurrentTemp.head.Bfield
289  << ", NTy = " << theCurrentTemp.head.NTy << ", NTyx = " << theCurrentTemp.head.NTyx<< ", NTxx = " << theCurrentTemp.head.NTxx << ", Dtype = " << theCurrentTemp.head.Dtype
290  << ", Bias voltage " << theCurrentTemp.head.Vbias << ", temperature "
291  << theCurrentTemp.head.temperature << ", fluence " << theCurrentTemp.head.fluence << ", Q-scaling factor " << theCurrentTemp.head.qscale
292  << ", 1/2 multi dcol threshold " << theCurrentTemp.head.s50 << ", 1/2 single dcol threshold " << theCurrentTemp.head.ss50
293  << ", y Lorentz Width " << theCurrentTemp.head.lorywidth << ", y Lorentz Bias " << theCurrentTemp.head.lorybias
294  << ", x Lorentz width " << theCurrentTemp.head.lorxwidth << ", x Lorentz Bias " << theCurrentTemp.head.lorxbias
295  << ", Q/Q_avg fractions for Qbin defs " << theCurrentTemp.head.fbin[0] << ", " << theCurrentTemp.head.fbin[1]
296  << ", " << theCurrentTemp.head.fbin[2]
297  << ", pixel x-size " << theCurrentTemp.head.xsize << ", y-size " << theCurrentTemp.head.ysize << ", zsize " << theCurrentTemp.head.zsize << ENDL;
298 
299  LOGINFO("SiPixelGenError") << "Loading Pixel GenError - "
300  << theCurrentTemp.head.title << " version "
301  <<theCurrentTemp.head.templ_version <<" code v."
302  <<code_version<<ENDL;
303  if(theCurrentTemp.head.templ_version < code_version) {
304  LOGERROR("SiPixelGenError") << "code expects version " << code_version
305  << ", no GenError load" << ENDL; return false;}
306 
307 #ifdef SI_PIXEL_TEMPLATE_USE_BOOST
308 
309  // next, layout the 1-d/2-d structures needed to store GenError
310 
311  theCurrentTemp.enty.resize(boost::extents[theCurrentTemp.head.NTy]);
312 
313  theCurrentTemp.entx.resize(boost::extents[theCurrentTemp.head.NTyx][theCurrentTemp.head.NTxx]);
314 
315 #endif
316 
317  // next, loop over all barrel y-angle entries
318 
319  for (i=0; i < theCurrentTemp.head.NTy; ++i) {
320 
321  db >> theCurrentTemp.enty[i].runnum >> costrk[0] >> costrk[1] >> costrk[2];
322 
323  if(db.fail()) {LOGERROR("SiPixelGenError") << "Error reading file 1, no GenError load, run # " << theCurrentTemp.enty[i].runnum << ENDL; return false;}
324 
325  // Calculate the alpha, beta, and cot(beta) for this entry
326 
327  theCurrentTemp.enty[i].cotalpha = costrk[0]/costrk[2];
328 
329  theCurrentTemp.enty[i].cotbeta = costrk[1]/costrk[2];
330 
331  db >> theCurrentTemp.enty[i].qavg >> theCurrentTemp.enty[i].pixmax >> theCurrentTemp.enty[i].dyone
332  >> theCurrentTemp.enty[i].syone >> theCurrentTemp.enty[i].dxone >> theCurrentTemp.enty[i].sxone;
333 
334  if(db.fail()) {LOGERROR("SiPixelGenError") << "Error reading file 2, no GenError load, run # " << theCurrentTemp.enty[i].runnum << ENDL; return false;}
335 
336  db >> theCurrentTemp.enty[i].dytwo >> theCurrentTemp.enty[i].sytwo >> theCurrentTemp.enty[i].dxtwo
337  >> theCurrentTemp.enty[i].sxtwo >> theCurrentTemp.enty[i].qmin >> theCurrentTemp.enty[i].qmin2;
338 
339  for (j=0; j<4; ++j) {
340 
341  db >> theCurrentTemp.enty[i].yavggen[j] >> theCurrentTemp.enty[i].yrmsgen[j] >> theCurrentTemp.enty[i].xavggen[j] >> theCurrentTemp.enty[i].xrmsgen[j];
342 
343  if(db.fail()) {LOGERROR("SiPixelGenError") << "Error reading file 14a, no GenError load, run # " << theCurrentTemp.enty[i].runnum << ENDL; return false;}
344  }
345 
346  }
347 
348  // next, loop over all barrel x-angle entries
349 
350  for (k=0; k < theCurrentTemp.head.NTyx; ++k) {
351 
352  for (i=0; i < theCurrentTemp.head.NTxx; ++i) {
353 
354  db >> theCurrentTemp.entx[k][i].runnum >> costrk[0] >> costrk[1] >> costrk[2];
355 
356  if(db.fail()) {LOGERROR("SiPixelGenError") << "Error reading file 17, no GenError load, run # " << theCurrentTemp.entx[k][i].runnum << ENDL; return false;}
357 
358  // Calculate the alpha, beta, and cot(beta) for this entry
359 
360  theCurrentTemp.entx[k][i].cotalpha = costrk[0]/costrk[2];
361 
362  theCurrentTemp.entx[k][i].cotbeta = costrk[1]/costrk[2];
363 
364  db >> theCurrentTemp.entx[k][i].qavg >> theCurrentTemp.entx[k][i].pixmax >> theCurrentTemp.entx[k][i].dyone
365  >> theCurrentTemp.entx[k][i].syone >> theCurrentTemp.entx[k][i].dxone >> theCurrentTemp.entx[k][i].sxone;
366 
367  if(db.fail()) {LOGERROR("SiPixelGenError") << "Error reading file 18, no GenError load, run # " << theCurrentTemp.entx[k][i].runnum << ENDL; return false;}
368 
369  db >> theCurrentTemp.entx[k][i].dytwo >> theCurrentTemp.entx[k][i].sytwo >> theCurrentTemp.entx[k][i].dxtwo
370  >> theCurrentTemp.entx[k][i].sxtwo >> theCurrentTemp.entx[k][i].qmin >> theCurrentTemp.entx[k][i].qmin2;
371 
372  for (j=0; j<4; ++j) {
373 
374  db >> theCurrentTemp.entx[k][i].yavggen[j] >> theCurrentTemp.entx[k][i].yrmsgen[j] >> theCurrentTemp.entx[k][i].xavggen[j] >> theCurrentTemp.entx[k][i].xrmsgen[j];
375 
376  if(db.fail()) {LOGERROR("SiPixelGenError") << "Error reading file 30a, no GenError load, run # " << theCurrentTemp.entx[k][i].runnum << ENDL; return false;}
377  }
378 
379  }
380  }
381 
382 
383  // Add this GenError to the store
384 
385  thePixelTemp_.push_back(theCurrentTemp);
386 
387  postInit(thePixelTemp_);
388 
389  }
390  return true;
391 
392 } // TempInit
393 
394 #endif
395 
396 void SiPixelGenError::postInit(std::vector< SiPixelGenErrorStore > & thePixelTemp_) {
397 
398  for (auto & templ : thePixelTemp_) {
399  for ( auto iy=0; iy<templ.head.NTy; ++iy ) templ.cotbetaY[iy]=templ.enty[iy].cotbeta;
400  for ( auto iy=0; iy<templ.head.NTyx; ++iy ) templ.cotbetaX[iy]= templ.entx[iy][0].cotbeta;
401  for ( auto ix=0; ix<templ.head.NTxx; ++ix ) templ.cotalphaX[ix]=templ.entx[0][ix].cotalpha;
402  }
403 
404 }
405 
406 
407 
408 
409 // ************************************************************************************************************
431 // ************************************************************************************************************
432 // a simpler method just to return the LA
434  // Find the index corresponding to id
435 
436  if(id != id_current_) {
437 
438  index_id_ = -1;
439  for( int i=0; i<(int)thePixelTemp_.size(); ++i) {
440  if(id == thePixelTemp_[i].head.ID) {
441  index_id_ = i;
442  id_current_ = id;
443  //
444  lorywidth_ = thePixelTemp_[i].head.lorywidth;
445  lorxwidth_ = thePixelTemp_[i].head.lorxwidth;
446  lorybias_ = thePixelTemp_[i].head.lorybias;
447  lorxbias_ = thePixelTemp_[i].head.lorxbias;
448 
449  //for(int j=0; j<3; ++j) {fbin_[j] = thePixelTemp_[i].head.fbin[j];}
450 
451  // Pixel sizes to the private variables
452  xsize_ = thePixelTemp_[i].head.xsize;
453  ysize_ = thePixelTemp_[i].head.ysize;
454  zsize_ = thePixelTemp_[i].head.zsize;
455 
456  break;
457  }
458  }
459  }
460  return index_id_;
461 }
462 //-----------------------------------------------------------------------
463 // Full method
464 int SiPixelGenError::qbin(int id, float cotalpha, float cotbeta, float locBz, float locBx, float qclus, bool irradiationCorrections,
465  int& pixmx, float& sigmay, float& deltay, float& sigmax, float& deltax,
466  float& sy1, float& dy1, float& sy2, float& dy2, float& sx1, float& dx1,
467  float& sx2, float& dx2)
468 {
469  // Interpolate for a new set of track angles
470 
471 
472  // Find the index corresponding to id
473 
474 
475  if(id != id_current_) {
476 
477  index_id_ = -1;
478  for( int i=0; i<(int)thePixelTemp_.size(); ++i) {
479  if(id == thePixelTemp_[i].head.ID) {
480  index_id_ = i;
481  id_current_ = id;
482  lorywidth_ = thePixelTemp_[i].head.lorywidth;
483  lorxwidth_ = thePixelTemp_[i].head.lorxwidth;
484  lorybias_ = thePixelTemp_[i].head.lorybias;
485  lorxbias_ = thePixelTemp_[i].head.lorxbias;
486  for(int j=0; j<3; ++j) {fbin_[j] = thePixelTemp_[i].head.fbin[j];}
487 
488  // Pixel sizes to the private variables
489 
490  xsize_ = thePixelTemp_[i].head.xsize;
491  ysize_ = thePixelTemp_[i].head.ysize;
492  zsize_ = thePixelTemp_[i].head.zsize;
493 
494  break;
495  }
496  }
497  }
498 
499  int index = index_id_;
500 
501 #ifndef SI_PIXEL_TEMPLATE_STANDALONE
502  if(index < 0 || index >= (int)thePixelTemp_.size()) {
503  throw cms::Exception("DataCorrupt") << "SiPixelGenError::qbin can't find needed GenError ID = " << id << std::endl;
504  }
505 #else
506  assert(index >= 0 && index < (int)thePixelTemp_.size());
507 #endif
508 
509  //
510 
511 
512  auto const & templ = thePixelTemp_[index];
513 
514  // Interpolate the absolute value of cot(beta)
515 
516  auto acotb = std::abs(cotbeta);
517 
518  // qcorrect corrects the cot(alpha)=0 cluster charge for non-zero cot(alpha)
519 
520  auto cotalpha0 = thePixelTemp_[index].enty[0].cotalpha;
521  auto qcorrect=std::sqrt((1.f+cotbeta*cotbeta+cotalpha*cotalpha)/(1.f+cotbeta*cotbeta+cotalpha0*cotalpha0));
522 
523  // for some cosmics, the ususal gymnastics are incorrect
524 
525  float cota = cotalpha;
526  float cotb = acotb;
527  bool flip_y; bool flip_x;
528  // for some cosmics, the ususal gymnastics are incorrect
529  flip_x = false;
530  flip_y = false;
531  switch(thePixelTemp_[index_id_].head.Dtype) {
532  case 0:
533  if(cotbeta < 0.f) {flip_y = true;}
534  break;
535  case 1:
536  if(locBz < 0.f) {
537  cotb = cotbeta;
538  } else {
539  cotb = -cotbeta;
540  flip_y = true;
541  }
542  break;
543  case 2:
544  case 3:
545  case 4:
546  if(locBx*locBz < 0.f) {
547  cota = -cotalpha;
548  flip_x = true;
549  }
550  if(locBx > 0.f) {
551  cotb = cotbeta;
552  } else {
553  cotb = -cotbeta;
554  flip_y = true;
555  }
556  break;
557  default:
558 #ifndef SI_PIXEL_TEMPLATE_STANDALONE
559  throw cms::Exception("DataCorrupt") << "SiPixelTemplate::illegal subdetector ID = " << thePixelTemp_[index_id_].head.Dtype << std::endl;
560 #else
561  std::cout << "SiPixelTemplate::illegal subdetector ID = " << thePixelTemp_[index_id_].head.Dtype << std::endl;
562 #endif
563  }
564 
565  // Copy the charge scaling factor to the private variable
566 
567  if(flip_y) {
568  lorybias_ = -lorybias_;
569  lorywidth_ = -lorywidth_;
570  }
571  if(flip_x) {
572  lorxbias_ = -lorxbias_;
573  lorxwidth_ = -lorxwidth_;
574  }
575 
576 
577  auto qscale = thePixelTemp_[index].head.qscale;
578 
579 
580  /*
581  lorywidth = thePixelTemp_[index].head.lorywidth;
582  if(locBz > 0.f) {lorywidth = -lorywidth;}
583  lorxwidth = thePixelTemp_[index].head.lorxwidth;
584  */
585 
586 
587  auto Ny = thePixelTemp_[index].head.NTy;
588  auto Nyx = thePixelTemp_[index].head.NTyx;
589  auto Nxx = thePixelTemp_[index].head.NTxx;
590 
591 #ifndef SI_PIXEL_TEMPLATE_STANDALONE
592  if(Ny < 2 || Nyx < 1 || Nxx < 2) {
593  throw cms::Exception("DataCorrupt") << "GenError ID = " << id_current_ << "has too few entries: Ny/Nyx/Nxx = " << Ny << "/" << Nyx << "/" << Nxx << std::endl;
594  }
595 #else
596  assert(Ny > 1 && Nyx > 0 && Nxx > 1);
597 #endif
598 
599  // next, loop over all y-angle entries
600 
601  auto ilow = 0;
602  auto ihigh = 0;
603  auto yratio = 0.f;
604 
605  {
606  auto j = std::lower_bound(templ.cotbetaY,templ.cotbetaY+Ny,cotb);
607  if (j==templ.cotbetaY+Ny) { --j; yratio = 1.f; }
608  else if (j==templ.cotbetaY) { ++j; yratio = 0.f;}
609  else { yratio = (cotb - (*(j-1)) )/( (*j) - (*(j-1)) ) ; }
610 
611  ihigh = j-templ.cotbetaY;
612  ilow = ihigh-1;
613  }
614 
615 
616 
617  // Interpolate/store all y-related quantities (flip displacements when flip_y)
618 
619  auto qavg = (1.f - yratio)*thePixelTemp_[index].enty[ilow].qavg + yratio*thePixelTemp_[index].enty[ihigh].qavg;
620  qavg *= qcorrect;
621  auto qmin = (1.f - yratio)*thePixelTemp_[index].enty[ilow].qmin + yratio*thePixelTemp_[index].enty[ihigh].qmin;
622  qmin *= qcorrect;
623  auto qmin2 = (1.f - yratio)*thePixelTemp_[index].enty[ilow].qmin2 + yratio*thePixelTemp_[index].enty[ihigh].qmin2;
624  qmin2 *= qcorrect;
625 
626 
627 #ifndef SI_PIXEL_TEMPLATE_STANDALONE
628  if(qavg <= 0.f || qmin <= 0.f) {
629  throw cms::Exception("DataCorrupt") << "SiPixelGenError::qbin, qavg or qmin <= 0,"
630  << " Probably someone called the generic pixel reconstruction with an illegal trajectory state" << std::endl;
631  }
632 #else
633  assert(qavg > 0.f && qmin > 0.f);
634 #endif
635 
636  // Scale the input charge to account for differences between pixelav and CMSSW simulation or data
637 
638  auto qtotal = qscale*qclus;
639 
640  // uncertainty and final corrections depend upon total charge bin
641 
642  auto fq = qtotal/qavg;
643  int binq;
644  if(fq > fbin_[0]) {
645  binq=0;
646  } else {
647  if(fq > fbin_[1]) {
648  binq=1;
649  } else {
650  if(fq > fbin_[2]) {
651  binq=2;
652  } else {
653  binq=3;
654  }
655  }
656  }
657 
658  auto yrmsgen =(1.f - yratio)*thePixelTemp_[index].enty[ilow].yrmsgen[binq] + yratio*thePixelTemp_[index].enty[ihigh].yrmsgen[binq];
659  sy1 = (1.f - yratio)*thePixelTemp_[index].enty[ilow].syone + yratio*thePixelTemp_[index].enty[ihigh].syone;
660  sy2 = (1.f - yratio)*thePixelTemp_[index].enty[ilow].sytwo + yratio*thePixelTemp_[index].enty[ihigh].sytwo;
661 
662 
663  // next, loop over all x-angle entries, first, find relevant y-slices
664 
665  auto iylow = 0;
666  auto iyhigh = 0;
667  auto yxratio = 0.f;
668 
669 
670  {
671  auto j = std::lower_bound(templ.cotbetaX,templ.cotbetaX+Nyx,acotb);
672  if (j==templ.cotbetaX+Nyx) { --j; yxratio = 1.f; }
673  else if (j==templ.cotbetaX) { ++j; yxratio = 0.f;}
674  else { yxratio = (acotb - (*(j-1)) )/( (*j) - (*(j-1)) ) ; }
675 
676  iyhigh = j-templ.cotbetaX;
677  iylow = iyhigh -1;
678  }
679 
680 
681 
682  ilow = ihigh = 0;
683  auto xxratio = 0.f;
684 
685  {
686  auto j = std::lower_bound(templ.cotalphaX,templ.cotalphaX+Nxx,cotalpha);
687  if (j==templ.cotalphaX+Nxx) { --j; xxratio = 1.f; }
688  else if (j==templ.cotalphaX) { ++j; xxratio = 0.f;}
689  else { xxratio = (cota - (*(j-1)) )/( (*j) - (*(j-1)) ) ; }
690 
691  ihigh = j-templ.cotalphaX;
692  ilow = ihigh-1;
693  }
694 
695 
696 
697  sx1 = (1.f - xxratio)*thePixelTemp_[index].entx[0][ilow].sxone + xxratio*thePixelTemp_[index].entx[0][ihigh].sxone;
698  sx2 = (1.f - xxratio)*thePixelTemp_[index].entx[0][ilow].sxtwo + xxratio*thePixelTemp_[index].entx[0][ihigh].sxtwo;
699 
700  // pixmax is the maximum allowed pixel charge (used for truncation)
701 
702  pixmx=(1.f - yxratio)*((1.f - xxratio)*thePixelTemp_[index].entx[iylow][ilow].pixmax + xxratio*thePixelTemp_[index].entx[iylow][ihigh].pixmax)
703  +yxratio*((1.f - xxratio)*thePixelTemp_[index].entx[iyhigh][ilow].pixmax + xxratio*thePixelTemp_[index].entx[iyhigh][ihigh].pixmax);
704 
705  auto xrmsgen = (1.f - yxratio)*((1.f - xxratio)*thePixelTemp_[index].entx[iylow][ilow].xrmsgen[binq] + xxratio*thePixelTemp_[index].entx[iylow][ihigh].xrmsgen[binq])
706  +yxratio*((1.f - xxratio)*thePixelTemp_[index].entx[iyhigh][ilow].xrmsgen[binq] + xxratio*thePixelTemp_[index].entx[iyhigh][ihigh].xrmsgen[binq]);
707 
708 
709  if(irradiationCorrections) {
710  auto yavggen =(1.f - yratio)*thePixelTemp_[index].enty[ilow].yavggen[binq] + yratio*thePixelTemp_[index].enty[ihigh].yavggen[binq];
711  if(flip_y) {yavggen = -yavggen;}
712  deltay = yavggen;
713  dy1 = (1.f - yratio)*thePixelTemp_[index].enty[ilow].dyone + yratio*thePixelTemp_[index].enty[ihigh].dyone;
714  if(flip_y) {dy1 = -dy1;}
715  dy2 = (1.f - yratio)*thePixelTemp_[index].enty[ilow].dytwo + yratio*thePixelTemp_[index].enty[ihigh].dytwo;
716  if(flip_y) {dy2 = -dy2;}
717 
718  auto xavggen = (1.f - yxratio)*((1.f - xxratio)*thePixelTemp_[index].entx[iylow][ilow].xavggen[binq] + xxratio*thePixelTemp_[index].entx[iylow][ihigh].xavggen[binq])
719  +yxratio*((1.f - xxratio)*thePixelTemp_[index].entx[iyhigh][ilow].xavggen[binq] + xxratio*thePixelTemp_[index].entx[iyhigh][ihigh].xavggen[binq]);
720  if(flip_x) {xavggen = -xavggen;}
721  deltax = xavggen;
722  dx1 = (1.f - xxratio)*thePixelTemp_[index].entx[0][ilow].dxone + xxratio*thePixelTemp_[index].entx[0][ihigh].dxone;
723  if(flip_x) {dx1 = -dx1;}
724  dx2 = (1.f - xxratio)*thePixelTemp_[index].entx[0][ilow].dxtwo + xxratio*thePixelTemp_[index].entx[0][ihigh].dxtwo;
725  if(flip_x) {dx2 = -dx2;}
726  }
727 
728 
729  // Take the errors and bias from the correct charge bin
730 
731  sigmay = yrmsgen;
732 
733  sigmax = xrmsgen;
734 
735  // If the charge is too small (then flag it)
736 
737  if(qtotal < 0.95f*qmin) {binq = 5;} else {if(qtotal < 0.95f*qmin2) {binq = 4;}}
738 
739  return binq;
740 
741 } // qbin
float qavg
average cluster charge for this set of track angles (now includes threshold effects) ...
float ss50
1/2 of the single hit dcol threshold in electrons
float qmin
minimum cluster charge for valid hit (keeps 99.9% of simulated hits)
float Bfield
Bfield in Tesla.
int runnum
< Basic template entry corresponding to a single set of track angles
float yrmsgen[4]
generic algorithm: average y-rms of reconstruction binned in 4 charge bins
float dxone
mean offset/correction for one pixel x-clusters
#define LOGINFO(x)
float Vbias
detector bias potential in Volts
float xrmsgen[4]
generic algorithm: average x-rms of reconstruction binned in 4 charge bins
int NTxx
number of Template x-entries in each slice
float fbin[3]
The QBin definitions in Q_clus/Q_avg.
float syone
rms for one pixel y-clusters
float zsize
pixel size (for future use in upgraded geometry)
SiPixelGenErrorEntry enty[60]
60 Barrel y templates spanning cluster lengths from 0px to +18px [28 entries for fpix] ...
float s50
1/2 of the multihit dcol threshold in electrons
float cotalpha
cot(alpha) is proportional to cluster length in x and is basis of interpolation
float lorxbias
estimate of x-lorentz bias
float temperature
detector temperature in deg K
int qbin(int id, float cotalpha, float cotbeta, float locBz, float locBx, float qclus, bool irradiationCorrections, int &pixmx, float &sigmay, float &deltay, float &sigmax, float &deltax, float &sy1, float &dy1, float &sy2, float &dy2, float &sx1, float &dx1, float &sx2, float &dx2)
float xsize
pixel size (for future use in upgraded geometry)
static void postInit(std::vector< SiPixelGenErrorStore > &thePixelTemp_)
int templ_version
Version number of the template to ensure code compatibility.
float cotbeta
cot(beta) is proportional to cluster length in y and is basis of interpolation
T sqrt(T t)
Definition: SSEVec.h:18
std::vector< float > sVector() const
int ID
< template header structure
float sxone
rms for one pixel x-clusters
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
float fluence
radiation fluence in n_eq/cm^2
#define LOGERROR(x)
double f[11][100]
float dytwo
mean offset/correction for one double-pixel y-clusters
int NTy
number of Template y entries
float qscale
Charge scaling to match cmssw and pixelav.
float dxtwo
mean offset/correction for one double-pixel x-clusters
SiPixelGenErrorHeader head
< template storage structure
int k[5][pyjets_maxn]
float ysize
pixel size (for future use in upgraded geometry)
char title[80]
template title
float sytwo
rms for one double-pixel y-clusters
float lorywidth
estimate of y-lorentz width for optimal resolution
#define ENDL
float yavggen[4]
generic algorithm: average y-bias of reconstruction binned in 4 charge bins
float dyone
mean offset/correction for one pixel y-clusters
HLT enums.
int Dtype
detector type (0=BPix, 1=FPix)
int NTyx
number of Template y-slices of x entries
float xavggen[4]
generic algorithm: average x-bias of reconstruction binned in 4 charge bins
static bool pushfile(int filenum, std::vector< SiPixelGenErrorStore > &thePixelTemp_)
float pixmax
maximum charge for individual pixels in cluster
float sxtwo
rms for one double-pixel x-clusters
SiPixelGenErrorEntry entx[5][29]
29 Barrel x templates spanning cluster lengths from -6px (-1.125Rad) to +6px (+1.125Rad) in each of 5...
float lorybias
estimate of y-lorentz bias
float lorxwidth
estimate of x-lorentz width for optimal resolution