forked from cms-sw/cmssw
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSiPixelTemplate.cc
More file actions
4167 lines (3486 loc) · 162 KB
/
Copy pathSiPixelTemplate.cc
File metadata and controls
4167 lines (3486 loc) · 162 KB
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
70
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
149
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
228
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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// SiPixelTemplate.cc Version 10.24
//
// Add goodness-of-fit info and spare entries to templates, version number in template header, more error checking
// Add correction for (Q_F-Q_L)/(Q_F+Q_L) bias
// Add cot(beta) reflection to reduce y-entries and more sophisticated x-interpolation
// Fix small index searching bug in interpolate method
// Change interpolation indexing to avoid complier complaining about possible un-initialized variables
// Replace containers with static arrays in calls to ysigma2 and xsigma2
// Add external threshold to calls to ysigma2 and xsigma2, fix parameter signal max for xsigma2
// Return to 5 pixel spanning but adjust boundaries to use only when needed
// Implement improved (faster) chi2min search that depends on pixel types
// Fill template arrays in single calls to this object
// Add qmin to the template
// Add qscale to match charge scales
// Small improvement to x-chisquare interpolation
// Enlarge SiPixelTemplateStore to accommodate larger templates and increased alpha acceptance (reduce PT threshold to ~200 MeV)
// Change output streams to conform to CMSSW info and error logging.
// Store x and y cluster sizes in fractional pixels to facilitate cluster splitting
// Add methods to return 3-d templates needed for cluster splitting
// Keep interpolated central 9 template bins in private storage and expand/shift in the getter functions (faster for speed=2/3) and easier to build 3d templates
// Store error and bias information for the simple chi^2 min position analysis (no interpolation or Q_{FB} corrections) to use in cluster splitting
// To save time, the gaussian centers and sigma are not interpolated right now (they aren't currently used). They can be restored by un-commenting lines in the interpolate method.
// Add a new method to calculate qbin for input cotbeta and cluster charge. To be used for error estimation of merged clusters in PixelCPEGeneric.
// Improve the charge estimation for larger cot(alpha) tracks
// Change interpolate method to return false boolean if track angles are outside of range
// Add template info and method for truncation information
// Change to allow template sizes to be changed at compile time
// Fix bug in track angle checking
// Accommodate Dave's new DB pushfile which overloads the old method (file input)
// Add CPEGeneric error information and expand qbin method to access useful info for PixelCPEGeneric
// Fix large cot(alpha) bug in qmin interpolation
// Add second qmin to allow a qbin=5 state
// Use interpolated chi^2 info for one-pixel clusters
// Fix DB pushfile version number checking bug.
// Remove assert from qbin method
// Replace asserts with exceptions in CMSSW
// Change calling sequence to interpolate method to handle cot(beta)<0 for FPix cosmics
// Add getter for pixelav Lorentz width estimates to qbin method
// Add check on template size to interpolate and qbin methods
// Add qbin population information, charge distribution information
//
//
// V7.00 - Decouple BPix and FPix information into separate templates
// Add methods to facilitate improved cluster splitting
// Fix small charge scaling bug (affects FPix only)
// Change y-slice used for the x-template to be closer to the actual cotalpha-cotbeta point
// (there is some weak breakdown of x-y factorization in the FPix after irradiation)
//
//
// V8.00 - Add method to calculate a simple 2D template
// Reorganize the interpolate method to extract header info only once per ID
// V8.01 - Improve simple template normalization
// V8.05 - Change qbin normalization to work better after irradiation
// V8.10 - Add Vavilov distribution interpolation
// V8.11 - Renormalize the x-templates for Guofan's cluster size calculation
// V8.12 - Technical fix to qavg issue.
// V8.13 - Fix qbin and fastsim interpolaters to avoid changing class variables
// V8.20 - Add methods to identify the central pixels in the x- and y-templates (to help align templates with clusters in radiation damaged detectors)
// Rename class variables from pxxxx (private xxxx) to xxxx_ to follow standard convention.
// Add compiler option to store the template entries in BOOST multiarrays of structs instead of simple c arrays
// (allows dynamic resizing template storage and has bounds checking but costs ~10% in execution time).
// V8.21 - Add new qbin method to use in cluster splitting
// V8.23 - Replace chi-min position errors with merged cluster chi2 probability info
// V8.25 - Incorporate VI's speed changes into the current version
// V8.26 - Modify the Vavilov lookups to work better with the FPix (offset y-templates)
// V8.30 - Change the splitting template generation and access to improve speed and eliminate triple index boost::multiarray
// V8.31 - Add correction factor: measured/true charge
// V8.31 - Fix version number bug in db object I/O (pushfile)
// V8.32 - Check for illegal qmin during loading
// V8.33 - Fix small type conversion warnings
// V8.40 - Incorporate V.I. optimizations
// V9.00 - Expand header to include multi and single dcol thresholds, LA biases, and (variable) Qbin definitions
// V9.01 - Protect against negative error squared
// V10.00 - Update to work with Phase 1 FPix. Fix some code problems introduced by other maintainers.
// V10.01 - Fix initialization style as suggested by S. Krutelyov
// V10.10 - Add class variables and methods to be used to correctly calculate the probabilities of single pixel clusters
// V10.11 - Allow subdetector ID=5 for FPix R2P2 [allows better internal labeling of templates]
// V10.12 - Enforce minimum signal size in pixel charge uncertainty calculation
// V10.13 - Update the variable size [SI_PIXEL_TEMPLATE_USE_BOOST] option so that it works with VI's enhancements
// V10.20 - Add directory path selection to the ascii pushfile method
// V10.21 - Address runtime issues in pushfile() for gcc 7.X due to using tempfile as char string + misc. cleanup [Petar]
// V10.22 - Move templateStore to the heap, fix variable name in pushfile() [Petar]
// V10.24 - Add sideload() + associated gymnastics [Petar and Oz]
// V10.25 - Restore y-residual Gaussian parameters [Morris]
// Created by Morris Swartz on 10/27/06.
//
//
#ifndef SI_PIXEL_TEMPLATE_STANDALONE
#include <cmath>
#else
#include <math.h>
#endif
#include <algorithm>
#include <vector>
#include "boost/multi_array.hpp"
#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <list>
#ifndef SI_PIXEL_TEMPLATE_STANDALONE
#include "CondFormats/SiPixelTransient/interface/SiPixelTemplate.h"
#include "CondFormats/SiPixelTransient/interface/SimplePixel.h"
#include "FWCore/Utilities/interface/FileInPath.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/Utilities/interface/isFinite.h"
#define LOGDEBUG(x) LogDebug(x)
#define LOGERROR(x) LogError(x)
#define LOGINFO(x) LogInfo(x)
#define ENDL " "
#include "FWCore/Utilities/interface/Exception.h"
using namespace edm;
#else
#include "SiPixelTemplate.h"
#include "SimplePixel.h"
#define LOGDEBUG(x) std::cout << x << ": "
#define LOGERROR(x) std::cout << x << ": "
#define LOGINFO(x) std::cout << x << ": "
#define ENDL std::endl
#endif
//****************************************************************
//! This routine initializes the global template structures from
//! an external file template_summary_zpNNNN where NNNN are four
//! digits of filenum.
//! \param filenum - an integer NNNN used in the filename template_summary_zpNNNN
//****************************************************************
bool SiPixelTemplate::pushfile(int filenum, std::vector<SiPixelTemplateStore>& pixelTemp, std::string dir) {
// Add template stored in external file numbered filenum to theTemplateStore
// Local variables
int i, j, k, l;
float qavg_avg;
char c;
const int code_version = {17};
// Create a filename for this run
std::string tempfile = std::to_string(filenum);
#ifndef SI_PIXEL_TEMPLATE_STANDALONE
// If integer filenum has less than 4 digits, prepend 0's until we have four numerical characters, e.g. "0292"
int nzeros = 4 - tempfile.length();
if (nzeros > 0)
tempfile = std::string(nzeros, '0') + tempfile;
/// Alt implementation: for (unsigned cnt=4-tempfile.length(); cnt > 0; cnt-- ){ tempfile = "0" + tempfile; }
tempfile = dir + "template_summary_zp" + tempfile + ".out";
edm::FileInPath file(tempfile); // Find the file in CMSSW
tempfile = file.fullPath(); // Put it back with the whole path.
#else
// This is the same as above, but more elegant. (Elegance not allowed in CMSSW...)
std::ostringstream tout;
tout << "template_summary_zp" << std::setw(4) << std::setfill('0') << std::right << filenum << ".out" << std::ends;
tempfile = tout.str();
#endif
// Open the template file
//
std::ifstream in_file(tempfile);
if (in_file.is_open() && in_file.good()) {
// Create a local template storage entry
// Create a local template storage entry
/// SiPixelTemplateStore theCurrentTemp; // large, don't allocate it on the stack
auto tmpPtr = std::make_unique<SiPixelTemplateStore>(); // must be allocated on the heap instead
auto& theCurrentTemp = *tmpPtr;
// Read-in a header string first and print it
for (i = 0; (c = in_file.get()) != '\n'; ++i) {
if (i < 79) {
theCurrentTemp.head.title[i] = c;
}
}
if (i > 78) {
i = 78;
}
theCurrentTemp.head.title[i + 1] = '\0';
LOGINFO("SiPixelTemplate") << "Loading Pixel Template File - " << theCurrentTemp.head.title << ENDL;
// next, the header information
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 >> theCurrentTemp.head.temperature >> theCurrentTemp.head.fluence >>
theCurrentTemp.head.qscale >> theCurrentTemp.head.s50 >> theCurrentTemp.head.lorywidth >>
theCurrentTemp.head.lorxwidth >> theCurrentTemp.head.ysize >> theCurrentTemp.head.xsize >>
theCurrentTemp.head.zsize;
if (in_file.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 0A, no template load" << ENDL;
return false;
}
if (theCurrentTemp.head.templ_version > 17) {
in_file >> theCurrentTemp.head.ss50 >> theCurrentTemp.head.lorybias >> theCurrentTemp.head.lorxbias >>
theCurrentTemp.head.fbin[0] >> theCurrentTemp.head.fbin[1] >> theCurrentTemp.head.fbin[2];
if (in_file.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 0B, no template load" << ENDL;
return false;
}
} else {
theCurrentTemp.head.ss50 = theCurrentTemp.head.s50;
theCurrentTemp.head.lorybias = theCurrentTemp.head.lorywidth / 2.f;
theCurrentTemp.head.lorxbias = theCurrentTemp.head.lorxwidth / 2.f;
theCurrentTemp.head.fbin[0] = 1.5f;
theCurrentTemp.head.fbin[1] = 1.00f;
theCurrentTemp.head.fbin[2] = 0.85f;
}
LOGINFO("SiPixelTemplate") << "Template ID = " << theCurrentTemp.head.ID << ", Template Version "
<< theCurrentTemp.head.templ_version << ", Bfield = " << theCurrentTemp.head.Bfield
<< ", NTy = " << theCurrentTemp.head.NTy << ", NTyx = " << theCurrentTemp.head.NTyx
<< ", NTxx = " << theCurrentTemp.head.NTxx << ", Dtype = " << theCurrentTemp.head.Dtype
<< ", Bias voltage " << theCurrentTemp.head.Vbias << ", temperature "
<< theCurrentTemp.head.temperature << ", fluence " << theCurrentTemp.head.fluence
<< ", Q-scaling factor " << theCurrentTemp.head.qscale << ", 1/2 multi dcol threshold "
<< theCurrentTemp.head.s50 << ", 1/2 single dcol threshold " << theCurrentTemp.head.ss50
<< ", y Lorentz Width " << theCurrentTemp.head.lorywidth << ", y Lorentz Bias "
<< theCurrentTemp.head.lorybias << ", x Lorentz width " << theCurrentTemp.head.lorxwidth
<< ", x Lorentz Bias " << theCurrentTemp.head.lorxbias
<< ", Q/Q_avg fractions for Qbin defs " << theCurrentTemp.head.fbin[0] << ", "
<< theCurrentTemp.head.fbin[1] << ", " << theCurrentTemp.head.fbin[2]
<< ", pixel x-size " << theCurrentTemp.head.xsize << ", y-size "
<< theCurrentTemp.head.ysize << ", zsize " << theCurrentTemp.head.zsize << ENDL;
if (theCurrentTemp.head.templ_version < code_version) {
LOGERROR("SiPixelTemplate") << "code expects version " << code_version << " finds "
<< theCurrentTemp.head.templ_version << ", no template load" << ENDL;
return false;
}
#ifdef SI_PIXEL_TEMPLATE_USE_BOOST
// next, layout the 1-d/2-d structures needed to store template
theCurrentTemp.cotbetaY = std::vector<float>(theCurrentTemp.head.NTy);
theCurrentTemp.cotbetaX = std::vector<float>(theCurrentTemp.head.NTyx);
theCurrentTemp.cotalphaX = std::vector<float>(theCurrentTemp.head.NTxx);
theCurrentTemp.enty.resize(boost::extents[theCurrentTemp.head.NTy]);
theCurrentTemp.entx.resize(boost::extents[theCurrentTemp.head.NTyx][theCurrentTemp.head.NTxx]);
#endif
// next, loop over all y-angle entries
for (i = 0; i < theCurrentTemp.head.NTy; ++i) {
in_file >> theCurrentTemp.enty[i].runnum >> theCurrentTemp.enty[i].costrk[0] >>
theCurrentTemp.enty[i].costrk[1] >> theCurrentTemp.enty[i].costrk[2];
if (in_file.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 1, no template load, run # " << theCurrentTemp.enty[i].runnum
<< ENDL;
return false;
}
// Calculate the alpha, beta, and cot(beta) for this entry
theCurrentTemp.enty[i].alpha =
static_cast<float>(atan2((double)theCurrentTemp.enty[i].costrk[2], (double)theCurrentTemp.enty[i].costrk[0]));
theCurrentTemp.enty[i].cotalpha = theCurrentTemp.enty[i].costrk[0] / theCurrentTemp.enty[i].costrk[2];
theCurrentTemp.enty[i].beta =
static_cast<float>(atan2((double)theCurrentTemp.enty[i].costrk[2], (double)theCurrentTemp.enty[i].costrk[1]));
theCurrentTemp.enty[i].cotbeta = theCurrentTemp.enty[i].costrk[1] / theCurrentTemp.enty[i].costrk[2];
in_file >> theCurrentTemp.enty[i].qavg >> theCurrentTemp.enty[i].pixmax >> theCurrentTemp.enty[i].symax >>
theCurrentTemp.enty[i].dyone >> theCurrentTemp.enty[i].syone >> theCurrentTemp.enty[i].sxmax >>
theCurrentTemp.enty[i].dxone >> theCurrentTemp.enty[i].sxone;
if (in_file.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 2, no template load, run # " << theCurrentTemp.enty[i].runnum
<< ENDL;
return false;
}
in_file >> theCurrentTemp.enty[i].dytwo >> theCurrentTemp.enty[i].sytwo >> theCurrentTemp.enty[i].dxtwo >>
theCurrentTemp.enty[i].sxtwo >> theCurrentTemp.enty[i].qmin >> theCurrentTemp.enty[i].clsleny >>
theCurrentTemp.enty[i].clslenx;
if (in_file.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 3, no template load, run # " << theCurrentTemp.enty[i].runnum
<< ENDL;
return false;
}
if (theCurrentTemp.enty[i].qmin <= 0.) {
LOGERROR("SiPixelTemplate") << "Error in template ID " << theCurrentTemp.head.ID
<< " qmin = " << theCurrentTemp.enty[i].qmin << ", run # "
<< theCurrentTemp.enty[i].runnum << ENDL;
return false;
}
for (j = 0; j < 2; ++j) {
in_file >> theCurrentTemp.enty[i].ypar[j][0] >> theCurrentTemp.enty[i].ypar[j][1] >>
theCurrentTemp.enty[i].ypar[j][2] >> theCurrentTemp.enty[i].ypar[j][3] >> theCurrentTemp.enty[i].ypar[j][4];
if (in_file.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 4, no template load, run # "
<< theCurrentTemp.enty[i].runnum << ENDL;
return false;
}
}
for (j = 0; j < 9; ++j) {
for (k = 0; k < TYSIZE; ++k) {
in_file >> theCurrentTemp.enty[i].ytemp[j][k];
}
if (in_file.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 5, no template load, run # "
<< theCurrentTemp.enty[i].runnum << ENDL;
return false;
}
}
for (j = 0; j < 2; ++j) {
in_file >> theCurrentTemp.enty[i].xpar[j][0] >> theCurrentTemp.enty[i].xpar[j][1] >>
theCurrentTemp.enty[i].xpar[j][2] >> theCurrentTemp.enty[i].xpar[j][3] >> theCurrentTemp.enty[i].xpar[j][4];
if (in_file.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 6, no template load, run # "
<< theCurrentTemp.enty[i].runnum << ENDL;
return false;
}
}
qavg_avg = 0.f;
for (j = 0; j < 9; ++j) {
for (k = 0; k < TXSIZE; ++k) {
in_file >> theCurrentTemp.enty[i].xtemp[j][k];
qavg_avg += theCurrentTemp.enty[i].xtemp[j][k];
}
if (in_file.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 7, no template load, run # "
<< theCurrentTemp.enty[i].runnum << ENDL;
return false;
}
}
theCurrentTemp.enty[i].qavg_avg = qavg_avg / 9.;
for (j = 0; j < 4; ++j) {
in_file >> theCurrentTemp.enty[i].yavg[j] >> theCurrentTemp.enty[i].yrms[j] >> theCurrentTemp.enty[i].ygx0[j] >>
theCurrentTemp.enty[i].ygsig[j];
if (in_file.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 8, no template load, run # "
<< theCurrentTemp.enty[i].runnum << ENDL;
return false;
}
}
for (j = 0; j < 4; ++j) {
in_file >> theCurrentTemp.enty[i].yflpar[j][0] >> theCurrentTemp.enty[i].yflpar[j][1] >>
theCurrentTemp.enty[i].yflpar[j][2] >> theCurrentTemp.enty[i].yflpar[j][3] >>
theCurrentTemp.enty[i].yflpar[j][4] >> theCurrentTemp.enty[i].yflpar[j][5];
if (in_file.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 9, no template load, run # "
<< theCurrentTemp.enty[i].runnum << ENDL;
return false;
}
}
for (j = 0; j < 4; ++j) {
in_file >> theCurrentTemp.enty[i].xavg[j] >> theCurrentTemp.enty[i].xrms[j] >> theCurrentTemp.enty[i].xgx0[j] >>
theCurrentTemp.enty[i].xgsig[j];
if (in_file.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 10, no template load, run # "
<< theCurrentTemp.enty[i].runnum << ENDL;
return false;
}
}
for (j = 0; j < 4; ++j) {
in_file >> theCurrentTemp.enty[i].xflpar[j][0] >> theCurrentTemp.enty[i].xflpar[j][1] >>
theCurrentTemp.enty[i].xflpar[j][2] >> theCurrentTemp.enty[i].xflpar[j][3] >>
theCurrentTemp.enty[i].xflpar[j][4] >> theCurrentTemp.enty[i].xflpar[j][5];
if (in_file.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 11, no template load, run # "
<< theCurrentTemp.enty[i].runnum << ENDL;
return false;
}
}
for (j = 0; j < 4; ++j) {
in_file >> theCurrentTemp.enty[i].chi2yavg[j] >> theCurrentTemp.enty[i].chi2ymin[j] >>
theCurrentTemp.enty[i].chi2xavg[j] >> theCurrentTemp.enty[i].chi2xmin[j];
if (in_file.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 12, no template load, run # "
<< theCurrentTemp.enty[i].runnum << ENDL;
return false;
}
}
for (j = 0; j < 4; ++j) {
in_file >> theCurrentTemp.enty[i].yavgc2m[j] >> theCurrentTemp.enty[i].yrmsc2m[j] >>
theCurrentTemp.enty[i].chi2yavgc2m[j] >> theCurrentTemp.enty[i].chi2yminc2m[j];
if (in_file.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 13, no template load, run # "
<< theCurrentTemp.enty[i].runnum << ENDL;
return false;
}
}
for (j = 0; j < 4; ++j) {
in_file >> theCurrentTemp.enty[i].xavgc2m[j] >> theCurrentTemp.enty[i].xrmsc2m[j] >>
theCurrentTemp.enty[i].chi2xavgc2m[j] >> theCurrentTemp.enty[i].chi2xminc2m[j];
if (in_file.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 14, no template load, run # "
<< theCurrentTemp.enty[i].runnum << ENDL;
return false;
}
}
for (j = 0; j < 4; ++j) {
in_file >> theCurrentTemp.enty[i].yavggen[j] >> theCurrentTemp.enty[i].yrmsgen[j] >>
theCurrentTemp.enty[i].ygx0gen[j] >> theCurrentTemp.enty[i].ygsiggen[j];
if (in_file.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 14a, no template load, run # "
<< theCurrentTemp.enty[i].runnum << ENDL;
return false;
}
}
for (j = 0; j < 4; ++j) {
in_file >> theCurrentTemp.enty[i].xavggen[j] >> theCurrentTemp.enty[i].xrmsgen[j] >>
theCurrentTemp.enty[i].xgx0gen[j] >> theCurrentTemp.enty[i].xgsiggen[j];
if (in_file.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 14b, no template load, run # "
<< theCurrentTemp.enty[i].runnum << ENDL;
return false;
}
}
in_file >> theCurrentTemp.enty[i].chi2yavgone >> theCurrentTemp.enty[i].chi2yminone >>
theCurrentTemp.enty[i].chi2xavgone >> theCurrentTemp.enty[i].chi2xminone >> theCurrentTemp.enty[i].qmin2 >>
theCurrentTemp.enty[i].mpvvav >> theCurrentTemp.enty[i].sigmavav >> theCurrentTemp.enty[i].kappavav >>
theCurrentTemp.enty[i].r_qMeas_qTrue >> theCurrentTemp.enty[i].spare[0];
if (in_file.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 15, no template load, run # "
<< theCurrentTemp.enty[i].runnum << ENDL;
return false;
}
in_file >> theCurrentTemp.enty[i].mpvvav2 >> theCurrentTemp.enty[i].sigmavav2 >>
theCurrentTemp.enty[i].kappavav2 >> theCurrentTemp.enty[i].qbfrac[0] >> theCurrentTemp.enty[i].qbfrac[1] >>
theCurrentTemp.enty[i].qbfrac[2] >> theCurrentTemp.enty[i].fracyone >> theCurrentTemp.enty[i].fracxone >>
theCurrentTemp.enty[i].fracytwo >> theCurrentTemp.enty[i].fracxtwo;
// theCurrentTemp.enty[i].qbfrac[3] = 1. - theCurrentTemp.enty[i].qbfrac[0] - theCurrentTemp.enty[i].qbfrac[1] - theCurrentTemp.enty[i].qbfrac[2];
if (in_file.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 16, no template load, run # "
<< theCurrentTemp.enty[i].runnum << ENDL;
return false;
}
}
// next, loop over all barrel x-angle entries
for (k = 0; k < theCurrentTemp.head.NTyx; ++k) {
for (i = 0; i < theCurrentTemp.head.NTxx; ++i) {
in_file >> theCurrentTemp.entx[k][i].runnum >> theCurrentTemp.entx[k][i].costrk[0] >>
theCurrentTemp.entx[k][i].costrk[1] >> theCurrentTemp.entx[k][i].costrk[2];
if (in_file.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 17, no template load, run # "
<< theCurrentTemp.entx[k][i].runnum << ENDL;
return false;
}
// Calculate the alpha, beta, and cot(beta) for this entry
theCurrentTemp.entx[k][i].alpha = static_cast<float>(
atan2((double)theCurrentTemp.entx[k][i].costrk[2], (double)theCurrentTemp.entx[k][i].costrk[0]));
theCurrentTemp.entx[k][i].cotalpha = theCurrentTemp.entx[k][i].costrk[0] / theCurrentTemp.entx[k][i].costrk[2];
theCurrentTemp.entx[k][i].beta = static_cast<float>(
atan2((double)theCurrentTemp.entx[k][i].costrk[2], (double)theCurrentTemp.entx[k][i].costrk[1]));
theCurrentTemp.entx[k][i].cotbeta = theCurrentTemp.entx[k][i].costrk[1] / theCurrentTemp.entx[k][i].costrk[2];
in_file >> theCurrentTemp.entx[k][i].qavg >> theCurrentTemp.entx[k][i].pixmax >>
theCurrentTemp.entx[k][i].symax >> theCurrentTemp.entx[k][i].dyone >> theCurrentTemp.entx[k][i].syone >>
theCurrentTemp.entx[k][i].sxmax >> theCurrentTemp.entx[k][i].dxone >> theCurrentTemp.entx[k][i].sxone;
if (in_file.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 18, no template load, run # "
<< theCurrentTemp.entx[k][i].runnum << ENDL;
return false;
}
in_file >> theCurrentTemp.entx[k][i].dytwo >> theCurrentTemp.entx[k][i].sytwo >>
theCurrentTemp.entx[k][i].dxtwo >> theCurrentTemp.entx[k][i].sxtwo >> theCurrentTemp.entx[k][i].qmin >>
theCurrentTemp.entx[k][i].clsleny >> theCurrentTemp.entx[k][i].clslenx;
// >> theCurrentTemp.entx[k][i].mpvvav >> theCurrentTemp.entx[k][i].sigmavav >> theCurrentTemp.entx[k][i].kappavav;
if (in_file.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 19, no template load, run # "
<< theCurrentTemp.entx[k][i].runnum << ENDL;
return false;
}
for (j = 0; j < 2; ++j) {
in_file >> theCurrentTemp.entx[k][i].ypar[j][0] >> theCurrentTemp.entx[k][i].ypar[j][1] >>
theCurrentTemp.entx[k][i].ypar[j][2] >> theCurrentTemp.entx[k][i].ypar[j][3] >>
theCurrentTemp.entx[k][i].ypar[j][4];
if (in_file.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 20, no template load, run # "
<< theCurrentTemp.entx[k][i].runnum << ENDL;
return false;
}
}
for (j = 0; j < 9; ++j) {
for (l = 0; l < TYSIZE; ++l) {
in_file >> theCurrentTemp.entx[k][i].ytemp[j][l];
}
if (in_file.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 21, no template load, run # "
<< theCurrentTemp.entx[k][i].runnum << ENDL;
return false;
}
}
for (j = 0; j < 2; ++j) {
in_file >> theCurrentTemp.entx[k][i].xpar[j][0] >> theCurrentTemp.entx[k][i].xpar[j][1] >>
theCurrentTemp.entx[k][i].xpar[j][2] >> theCurrentTemp.entx[k][i].xpar[j][3] >>
theCurrentTemp.entx[k][i].xpar[j][4];
if (in_file.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 22, no template load, run # "
<< theCurrentTemp.entx[k][i].runnum << ENDL;
return false;
}
}
qavg_avg = 0.f;
for (j = 0; j < 9; ++j) {
for (l = 0; l < TXSIZE; ++l) {
in_file >> theCurrentTemp.entx[k][i].xtemp[j][l];
qavg_avg += theCurrentTemp.entx[k][i].xtemp[j][l];
}
if (in_file.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 23, no template load, run # "
<< theCurrentTemp.entx[k][i].runnum << ENDL;
return false;
}
}
theCurrentTemp.entx[k][i].qavg_avg = qavg_avg / 9.;
for (j = 0; j < 4; ++j) {
in_file >> theCurrentTemp.entx[k][i].yavg[j] >> theCurrentTemp.entx[k][i].yrms[j] >>
theCurrentTemp.entx[k][i].ygx0[j] >> theCurrentTemp.entx[k][i].ygsig[j];
if (in_file.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 24, no template load, run # "
<< theCurrentTemp.entx[k][i].runnum << ENDL;
return false;
}
}
for (j = 0; j < 4; ++j) {
in_file >> theCurrentTemp.entx[k][i].yflpar[j][0] >> theCurrentTemp.entx[k][i].yflpar[j][1] >>
theCurrentTemp.entx[k][i].yflpar[j][2] >> theCurrentTemp.entx[k][i].yflpar[j][3] >>
theCurrentTemp.entx[k][i].yflpar[j][4] >> theCurrentTemp.entx[k][i].yflpar[j][5];
if (in_file.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 25, no template load, run # "
<< theCurrentTemp.entx[k][i].runnum << ENDL;
return false;
}
}
for (j = 0; j < 4; ++j) {
in_file >> theCurrentTemp.entx[k][i].xavg[j] >> theCurrentTemp.entx[k][i].xrms[j] >>
theCurrentTemp.entx[k][i].xgx0[j] >> theCurrentTemp.entx[k][i].xgsig[j];
if (in_file.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 26, no template load, run # "
<< theCurrentTemp.entx[k][i].runnum << ENDL;
return false;
}
}
for (j = 0; j < 4; ++j) {
in_file >> theCurrentTemp.entx[k][i].xflpar[j][0] >> theCurrentTemp.entx[k][i].xflpar[j][1] >>
theCurrentTemp.entx[k][i].xflpar[j][2] >> theCurrentTemp.entx[k][i].xflpar[j][3] >>
theCurrentTemp.entx[k][i].xflpar[j][4] >> theCurrentTemp.entx[k][i].xflpar[j][5];
if (in_file.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 27, no template load, run # "
<< theCurrentTemp.entx[k][i].runnum << ENDL;
return false;
}
}
for (j = 0; j < 4; ++j) {
in_file >> theCurrentTemp.entx[k][i].chi2yavg[j] >> theCurrentTemp.entx[k][i].chi2ymin[j] >>
theCurrentTemp.entx[k][i].chi2xavg[j] >> theCurrentTemp.entx[k][i].chi2xmin[j];
if (in_file.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 28, no template load, run # "
<< theCurrentTemp.entx[k][i].runnum << ENDL;
return false;
}
}
for (j = 0; j < 4; ++j) {
in_file >> theCurrentTemp.entx[k][i].yavgc2m[j] >> theCurrentTemp.entx[k][i].yrmsc2m[j] >>
theCurrentTemp.entx[k][i].chi2yavgc2m[j] >> theCurrentTemp.entx[k][i].chi2yminc2m[j];
if (in_file.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 29, no template load, run # "
<< theCurrentTemp.entx[k][i].runnum << ENDL;
return false;
}
}
for (j = 0; j < 4; ++j) {
in_file >> theCurrentTemp.entx[k][i].xavgc2m[j] >> theCurrentTemp.entx[k][i].xrmsc2m[j] >>
theCurrentTemp.entx[k][i].chi2xavgc2m[j] >> theCurrentTemp.entx[k][i].chi2xminc2m[j];
if (in_file.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 30, no template load, run # "
<< theCurrentTemp.entx[k][i].runnum << ENDL;
return false;
}
}
for (j = 0; j < 4; ++j) {
in_file >> theCurrentTemp.entx[k][i].yavggen[j] >> theCurrentTemp.entx[k][i].yrmsgen[j] >>
theCurrentTemp.entx[k][i].ygx0gen[j] >> theCurrentTemp.entx[k][i].ygsiggen[j];
if (in_file.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 30a, no template load, run # "
<< theCurrentTemp.entx[k][i].runnum << ENDL;
return false;
}
}
for (j = 0; j < 4; ++j) {
in_file >> theCurrentTemp.entx[k][i].xavggen[j] >> theCurrentTemp.entx[k][i].xrmsgen[j] >>
theCurrentTemp.entx[k][i].xgx0gen[j] >> theCurrentTemp.entx[k][i].xgsiggen[j];
if (in_file.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 30b, no template load, run # "
<< theCurrentTemp.entx[k][i].runnum << ENDL;
return false;
}
}
in_file >> theCurrentTemp.entx[k][i].chi2yavgone >> theCurrentTemp.entx[k][i].chi2yminone >>
theCurrentTemp.entx[k][i].chi2xavgone >> theCurrentTemp.entx[k][i].chi2xminone >>
theCurrentTemp.entx[k][i].qmin2 >> theCurrentTemp.entx[k][i].mpvvav >> theCurrentTemp.entx[k][i].sigmavav >>
theCurrentTemp.entx[k][i].kappavav >> theCurrentTemp.entx[k][i].r_qMeas_qTrue >>
theCurrentTemp.entx[k][i].spare[0];
if (in_file.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 31, no template load, run # "
<< theCurrentTemp.entx[k][i].runnum << ENDL;
return false;
}
in_file >> theCurrentTemp.entx[k][i].mpvvav2 >> theCurrentTemp.entx[k][i].sigmavav2 >>
theCurrentTemp.entx[k][i].kappavav2 >> theCurrentTemp.entx[k][i].qbfrac[0] >>
theCurrentTemp.entx[k][i].qbfrac[1] >> theCurrentTemp.entx[k][i].qbfrac[2] >>
theCurrentTemp.entx[k][i].fracyone >> theCurrentTemp.entx[k][i].fracxone >>
theCurrentTemp.entx[k][i].fracytwo >> theCurrentTemp.entx[k][i].fracxtwo;
// theCurrentTemp.entx[k][i].qbfrac[3] = 1. - theCurrentTemp.entx[k][i].qbfrac[0] - theCurrentTemp.entx[k][i].qbfrac[1] - theCurrentTemp.entx[k][i].qbfrac[2];
if (in_file.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 32, no template load, run # "
<< theCurrentTemp.entx[k][i].runnum << ENDL;
return false;
}
}
}
in_file.close();
// Add this template to the store
pixelTemp.push_back(theCurrentTemp);
postInit(pixelTemp);
return true;
} else {
// If file didn't open, report this
LOGERROR("SiPixelTemplate") << "Error opening File" << tempfile << ENDL;
return false;
}
} // TempInit
#ifndef SI_PIXEL_TEMPLATE_STANDALONE
//****************************************************************
//! This routine initializes the global template structures from an
//! external file template_summary_zpNNNN where NNNN are four digits
//! \param dbobject - db storing multiple template calibrations
//****************************************************************
bool SiPixelTemplate::pushfile(const SiPixelTemplateDBObject& dbobject, std::vector<SiPixelTemplateStore>& pixelTemp) {
// Add template stored in external dbobject to theTemplateStore
// Local variables
int i, j, k, l;
float qavg_avg;
const int code_version = {17};
// We must create a new object because dbobject must be a const and our stream must not be
auto db(dbobject.reader());
// Create a local template storage entry
/// SiPixelTemplateStore theCurrentTemp; // large, don't allocate it on the stack
auto tmpPtr = std::make_unique<SiPixelTemplateStore>(); // must be allocated on the heap instead
auto& theCurrentTemp = *tmpPtr;
// Fill the template storage for each template calibration stored in the db
for (int m = 0; m < db.numOfTempl(); ++m) {
// Read-in a header string first and print it
SiPixelTemplateDBObject::char2float temp;
for (i = 0; i < 20; ++i) {
temp.f = db.sVector()[db.index()];
theCurrentTemp.head.title[4 * i] = temp.c[0];
theCurrentTemp.head.title[4 * i + 1] = temp.c[1];
theCurrentTemp.head.title[4 * i + 2] = temp.c[2];
theCurrentTemp.head.title[4 * i + 3] = temp.c[3];
db.incrementIndex(1);
}
theCurrentTemp.head.title[79] = '\0';
LOGINFO("SiPixelTemplate") << "Loading Pixel Template File - " << theCurrentTemp.head.title << ENDL;
// next, the header information
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 >> theCurrentTemp.head.temperature >> theCurrentTemp.head.fluence >>
theCurrentTemp.head.qscale >> theCurrentTemp.head.s50 >> theCurrentTemp.head.lorywidth >>
theCurrentTemp.head.lorxwidth >> theCurrentTemp.head.ysize >> theCurrentTemp.head.xsize >>
theCurrentTemp.head.zsize;
if (db.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 0A, no template load" << ENDL;
return false;
}
LOGINFO("SiPixelTemplate") << "Loading Pixel Template File - " << theCurrentTemp.head.title
<< " code version = " << code_version << " object version "
<< theCurrentTemp.head.templ_version << ENDL;
if (theCurrentTemp.head.templ_version > 17) {
db >> theCurrentTemp.head.ss50 >> theCurrentTemp.head.lorybias >> theCurrentTemp.head.lorxbias >>
theCurrentTemp.head.fbin[0] >> theCurrentTemp.head.fbin[1] >> theCurrentTemp.head.fbin[2];
if (db.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 0B, no template load" << ENDL;
return false;
}
} else {
theCurrentTemp.head.ss50 = theCurrentTemp.head.s50;
theCurrentTemp.head.lorybias = theCurrentTemp.head.lorywidth / 2.f;
theCurrentTemp.head.lorxbias = theCurrentTemp.head.lorxwidth / 2.f;
theCurrentTemp.head.fbin[0] = 1.50f;
theCurrentTemp.head.fbin[1] = 1.00f;
theCurrentTemp.head.fbin[2] = 0.85f;
//std::cout<<" set fbin "<< theCurrentTemp.head.fbin[0]<<" "<<theCurrentTemp.head.fbin[1]<<" "
// <<theCurrentTemp.head.fbin[2]<<std::endl;
}
LOGINFO("SiPixelTemplate") << "Template ID = " << theCurrentTemp.head.ID << ", Template Version "
<< theCurrentTemp.head.templ_version << ", Bfield = " << theCurrentTemp.head.Bfield
<< ", NTy = " << theCurrentTemp.head.NTy << ", NTyx = " << theCurrentTemp.head.NTyx
<< ", NTxx = " << theCurrentTemp.head.NTxx << ", Dtype = " << theCurrentTemp.head.Dtype
<< ", Bias voltage " << theCurrentTemp.head.Vbias << ", temperature "
<< theCurrentTemp.head.temperature << ", fluence " << theCurrentTemp.head.fluence
<< ", Q-scaling factor " << theCurrentTemp.head.qscale << ", 1/2 multi dcol threshold "
<< theCurrentTemp.head.s50 << ", 1/2 single dcol threshold " << theCurrentTemp.head.ss50
<< ", y Lorentz Width " << theCurrentTemp.head.lorywidth << ", y Lorentz Bias "
<< theCurrentTemp.head.lorybias << ", x Lorentz width " << theCurrentTemp.head.lorxwidth
<< ", x Lorentz Bias " << theCurrentTemp.head.lorxbias
<< ", Q/Q_avg fractions for Qbin defs " << theCurrentTemp.head.fbin[0] << ", "
<< theCurrentTemp.head.fbin[1] << ", " << theCurrentTemp.head.fbin[2]
<< ", pixel x-size " << theCurrentTemp.head.xsize << ", y-size "
<< theCurrentTemp.head.ysize << ", zsize " << theCurrentTemp.head.zsize << ENDL;
if (theCurrentTemp.head.templ_version < code_version) {
LOGINFO("SiPixelTemplate") << "code expects version " << code_version << " finds "
<< theCurrentTemp.head.templ_version << ", load anyway " << ENDL;
//return false; // dk
}
#ifdef SI_PIXEL_TEMPLATE_USE_BOOST
// next, layout the 1-d/2-d structures needed to store template
theCurrentTemp.cotbetaY = std::vector<float>(theCurrentTemp.head.NTy);
theCurrentTemp.cotbetaX = std::vector<float>(theCurrentTemp.head.NTyx);
theCurrentTemp.cotalphaX = std::vector<float>(theCurrentTemp.head.NTxx);
theCurrentTemp.enty.resize(boost::extents[theCurrentTemp.head.NTy]);
theCurrentTemp.entx.resize(boost::extents[theCurrentTemp.head.NTyx][theCurrentTemp.head.NTxx]);
#endif
// next, loop over all barrel y-angle entries
for (i = 0; i < theCurrentTemp.head.NTy; ++i) {
db >> theCurrentTemp.enty[i].runnum >> theCurrentTemp.enty[i].costrk[0] >> theCurrentTemp.enty[i].costrk[1] >>
theCurrentTemp.enty[i].costrk[2];
if (db.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 1, no template load, run # " << theCurrentTemp.enty[i].runnum
<< ENDL;
return false;
}
// Calculate the alpha, beta, and cot(beta) for this entry
theCurrentTemp.enty[i].alpha =
static_cast<float>(atan2((double)theCurrentTemp.enty[i].costrk[2], (double)theCurrentTemp.enty[i].costrk[0]));
theCurrentTemp.enty[i].cotalpha = theCurrentTemp.enty[i].costrk[0] / theCurrentTemp.enty[i].costrk[2];
theCurrentTemp.enty[i].beta =
static_cast<float>(atan2((double)theCurrentTemp.enty[i].costrk[2], (double)theCurrentTemp.enty[i].costrk[1]));
theCurrentTemp.enty[i].cotbeta = theCurrentTemp.enty[i].costrk[1] / theCurrentTemp.enty[i].costrk[2];
db >> theCurrentTemp.enty[i].qavg >> theCurrentTemp.enty[i].pixmax >> theCurrentTemp.enty[i].symax >>
theCurrentTemp.enty[i].dyone >> theCurrentTemp.enty[i].syone >> theCurrentTemp.enty[i].sxmax >>
theCurrentTemp.enty[i].dxone >> theCurrentTemp.enty[i].sxone;
if (db.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 2, no template load, run # " << theCurrentTemp.enty[i].runnum
<< ENDL;
return false;
}
db >> theCurrentTemp.enty[i].dytwo >> theCurrentTemp.enty[i].sytwo >> theCurrentTemp.enty[i].dxtwo >>
theCurrentTemp.enty[i].sxtwo >> theCurrentTemp.enty[i].qmin >> theCurrentTemp.enty[i].clsleny >>
theCurrentTemp.enty[i].clslenx;
// >> theCurrentTemp.enty[i].mpvvav >> theCurrentTemp.enty[i].sigmavav >> theCurrentTemp.enty[i].kappavav;
if (db.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 3, no template load, run # " << theCurrentTemp.enty[i].runnum
<< ENDL;
return false;
}
if (theCurrentTemp.enty[i].qmin <= 0.) {
LOGERROR("SiPixelTemplate") << "Error in template ID " << theCurrentTemp.head.ID
<< " qmin = " << theCurrentTemp.enty[i].qmin << ", run # "
<< theCurrentTemp.enty[i].runnum << ENDL;
return false;
}
for (j = 0; j < 2; ++j) {
db >> theCurrentTemp.enty[i].ypar[j][0] >> theCurrentTemp.enty[i].ypar[j][1] >>
theCurrentTemp.enty[i].ypar[j][2] >> theCurrentTemp.enty[i].ypar[j][3] >> theCurrentTemp.enty[i].ypar[j][4];
if (db.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 4, no template load, run # "
<< theCurrentTemp.enty[i].runnum << ENDL;
return false;
}
}
for (j = 0; j < 9; ++j) {
for (k = 0; k < TYSIZE; ++k) {
db >> theCurrentTemp.enty[i].ytemp[j][k];
}
if (db.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 5, no template load, run # "
<< theCurrentTemp.enty[i].runnum << ENDL;
return false;
}
}
for (j = 0; j < 2; ++j) {
db >> theCurrentTemp.enty[i].xpar[j][0] >> theCurrentTemp.enty[i].xpar[j][1] >>
theCurrentTemp.enty[i].xpar[j][2] >> theCurrentTemp.enty[i].xpar[j][3] >> theCurrentTemp.enty[i].xpar[j][4];
if (db.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 6, no template load, run # "
<< theCurrentTemp.enty[i].runnum << ENDL;
return false;
}
}
qavg_avg = 0.f;
for (j = 0; j < 9; ++j) {
for (k = 0; k < TXSIZE; ++k) {
db >> theCurrentTemp.enty[i].xtemp[j][k];
qavg_avg += theCurrentTemp.enty[i].xtemp[j][k];
}
if (db.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 7, no template load, run # "
<< theCurrentTemp.enty[i].runnum << ENDL;
return false;
}
}
theCurrentTemp.enty[i].qavg_avg = qavg_avg / 9.;
for (j = 0; j < 4; ++j) {
db >> theCurrentTemp.enty[i].yavg[j] >> theCurrentTemp.enty[i].yrms[j] >> theCurrentTemp.enty[i].ygx0[j] >>
theCurrentTemp.enty[i].ygsig[j];
if (db.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 8, no template load, run # "
<< theCurrentTemp.enty[i].runnum << ENDL;
return false;
}
}
for (j = 0; j < 4; ++j) {
db >> theCurrentTemp.enty[i].yflpar[j][0] >> theCurrentTemp.enty[i].yflpar[j][1] >>
theCurrentTemp.enty[i].yflpar[j][2] >> theCurrentTemp.enty[i].yflpar[j][3] >>
theCurrentTemp.enty[i].yflpar[j][4] >> theCurrentTemp.enty[i].yflpar[j][5];
if (db.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 9, no template load, run # "
<< theCurrentTemp.enty[i].runnum << ENDL;
return false;
}
}
for (j = 0; j < 4; ++j) {
db >> theCurrentTemp.enty[i].xavg[j] >> theCurrentTemp.enty[i].xrms[j] >> theCurrentTemp.enty[i].xgx0[j] >>
theCurrentTemp.enty[i].xgsig[j];
if (db.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 10, no template load, run # "
<< theCurrentTemp.enty[i].runnum << ENDL;
return false;
}
}
for (j = 0; j < 4; ++j) {
db >> theCurrentTemp.enty[i].xflpar[j][0] >> theCurrentTemp.enty[i].xflpar[j][1] >>
theCurrentTemp.enty[i].xflpar[j][2] >> theCurrentTemp.enty[i].xflpar[j][3] >>
theCurrentTemp.enty[i].xflpar[j][4] >> theCurrentTemp.enty[i].xflpar[j][5];
if (db.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 11, no template load, run # "
<< theCurrentTemp.enty[i].runnum << ENDL;
return false;
}
}
for (j = 0; j < 4; ++j) {
db >> theCurrentTemp.enty[i].chi2yavg[j] >> theCurrentTemp.enty[i].chi2ymin[j] >>
theCurrentTemp.enty[i].chi2xavg[j] >> theCurrentTemp.enty[i].chi2xmin[j];
if (db.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 12, no template load, run # "
<< theCurrentTemp.enty[i].runnum << ENDL;
return false;
}
}
for (j = 0; j < 4; ++j) {
db >> theCurrentTemp.enty[i].yavgc2m[j] >> theCurrentTemp.enty[i].yrmsc2m[j] >>
theCurrentTemp.enty[i].chi2yavgc2m[j] >> theCurrentTemp.enty[i].chi2yminc2m[j];
if (db.fail()) {
LOGERROR("SiPixelTemplate") << "Error reading file 13, no template load, run # "
<< theCurrentTemp.enty[i].runnum << ENDL;
return false;
}
}
for (j = 0; j < 4; ++j) {