CMS 3D CMS Logo

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