/
SiPixelDigitizerAlgorithm.cc
2609 lines (2270 loc) · 120 KB
/
SiPixelDigitizerAlgorithm.cc
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
//class SiPixelDigitizerAlgorithm SimTracker/SiPixelDigitizer/src/SiPixelDigitizerAlgoithm.cc
// Original Author Danek Kotlinski
// Ported in CMSSW by Michele Pioppi-INFN perugia
// Added DB capabilities by F.Blekman, Cornell University
// Created: Mon Sep 26 11:08:32 CEST 2005
// Add tof, change AddNoise to tracked. 4/06
// Change drift direction. 6/06 d.k.
// Add the statuis (non-rate dependent) inefficiency.
// -1 - no ineffciency
// 0 - static inefficency only
// 1,2 - low-lumi rate dependent inefficency added
// 10 - high-lumi inefficiency added
// Adopt the correct drift sign convetion from Morris Swartz. d.k. 8/06
// Add more complex misscalinbration, change kev/e to 3.61, diff=3.7,d.k.9/06
// Add the readout channel electronic noise. d.k. 3/07
// Lower the pixel noise from 500 to 175elec.
// Change the input threshold from noise units to electrons.
// Lower the amount of static dead pixels from 0.01 to 0.001.
// Modify to the new random number services. d.k. 5/07
// Protect against sigma=0 (delta tracks on the surface). d.k.5/07
// Change the TOF cut to lower and upper limit. d.k. 7/07
//
// July 2008: Split Lorentz Angle configuration in BPix/FPix (V. Cuplov)
// tanLorentzAngleperTesla_FPix=0.0912 and tanLorentzAngleperTesla_BPix=0.106
// Sept. 2008: Disable Pixel modules which are declared dead in the configuration python file. (V. Cuplov)
// Oct. 2008: Accessing/Reading the Lorentz angle from the DataBase instead of the cfg file. (V. Cuplov)
// Accessing dead modules from the DB. Implementation done and tested on a test.db
// Do not use this option for now. The PixelQuality Objects are not in the official DB yet.
// Feb. 2009: Split Fpix and Bpix threshold and use official numbers (V. Cuplov)
// ThresholdInElectrons_FPix = 2870 and ThresholdInElectrons_BPix = 3700
// update the electron to VCAL conversion using: VCAL_electrons = VCAL * 65.5 - 414
// Feb. 2009: Threshold gaussian smearing (V. Cuplov)
// March, 2009: changed DB access to *SimRcd objects (to de-couple the DB objects from reco chain) (F. Blekman)
// May, 2009: Pixel charge VCAL smearing. (V. Cuplov)
// November, 2009: new parameterization of the pixel response. (V. Cuplov)
// December, 2009: Fix issue with different compilers.
// October, 2010: Improvement: Removing single dead ROC (V. Cuplov)
// November, 2010: Bug fix in removing TBMB/A half-modules (V. Cuplov)
// February, 2011: Time improvement in DriftDirection() (J. Bashir Butt)
// June, 2011: Bug Fix for pixels on ROC edges in module_killing_DB() (J. Bashir Butt)
// February, 2018: Implement cluster charge reweighting (P. Schuetze, with code from A. Hazi)
#include <iostream>
#include <iomanip>
#include <gsl/gsl_sf_erf.h>
#include "CLHEP/Random/RandFlat.h"
#include "CLHEP/Random/RandGaussQ.h"
#include "CLHEP/Random/RandGeneral.h"
#include "CalibTracker/SiPixelESProducers/interface/SiPixelGainCalibrationOfflineSimService.h"
#include "CondFormats/SiPixelObjects/interface/CablingPathToDetUnit.h"
#include "CondFormats/SiPixelObjects/interface/GlobalPixel.h"
#include "CondFormats/SiPixelObjects/interface/LocalPixel.h"
#include "CondFormats/SiPixelObjects/interface/PixelFEDCabling.h"
#include "CondFormats/SiPixelObjects/interface/PixelFEDLink.h"
#include "CondFormats/SiPixelObjects/interface/PixelIndices.h"
#include "CondFormats/SiPixelObjects/interface/PixelROC.h"
#include "CondFormats/SiPixelObjects/interface/SiPixel2DTemplateDBObject.h"
#include "CondFormats/SiPixelObjects/interface/SiPixelDynamicInefficiency.h"
#include "CondFormats/SiPixelObjects/interface/SiPixelFEDChannelContainer.h"
#include "CondFormats/SiPixelObjects/interface/SiPixelFedCabling.h"
#include "CondFormats/SiPixelObjects/interface/SiPixelFedCablingMap.h"
#include "CondFormats/SiPixelObjects/interface/SiPixelFedCablingTree.h"
#include "CondFormats/SiPixelObjects/interface/SiPixelFrameReverter.h"
#include "CondFormats/SiPixelObjects/interface/SiPixelLorentzAngle.h"
#include "CondFormats/SiPixelObjects/interface/SiPixelQuality.h"
#include "CondFormats/SiPixelObjects/interface/SiPixelQualityProbabilities.h"
#include "DataFormats/DetId/interface/DetId.h"
#include "DataFormats/FEDRawData/interface/FEDNumbering.h"
#include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
#include "DataFormats/SiPixelDigi/interface/PixelDigi.h"
#include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "FWCore/Utilities/interface/Exception.h"
#include "FWCore/Utilities/interface/RandomNumberGenerator.h"
#include "Geometry/CommonDetUnit/interface/PixelGeomDetUnit.h"
#include "Geometry/Records/interface/IdealGeometryRecord.h"
#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
#include "SimDataFormats/PileupSummaryInfo/interface/PileupMixingContent.h"
#include "SimDataFormats/Track/interface/SimTrack.h"
#include "SimDataFormats/TrackerDigiSimLink/interface/PixelDigiSimLink.h"
#include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
#include "SimGeneral/NoiseGenerators/interface/GaussianTailNoiseGenerator.h"
#include "SimTracker/Common/interface/SiG4UniversalFluctuation.h"
#include "SimTracker/Common/interface/SiPixelChargeReweightingAlgorithm.h"
#include "SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizerAlgorithm.h"
using namespace edm;
using namespace sipixelobjects;
void SiPixelDigitizerAlgorithm::init(const edm::EventSetup& es) {
if (use_ineff_from_db_) { // load gain calibration service fromdb...
theSiPixelGainCalibrationService_->setESObjects(es);
}
if (use_deadmodule_DB_) {
SiPixelBadModule_ = &es.getData(SiPixelBadModuleToken_);
}
if (use_LorentzAngle_DB_) {
// Get Lorentz angle from DB record
SiPixelLorentzAngle_ = &es.getData(SiPixelLorentzAngleToken_);
}
//gets the map and geometry from the DB (to kill ROCs)
map_ = &es.getData(mapToken_);
geom_ = &es.getData(geomToken_);
if (KillBadFEDChannels) {
scenarioProbability_ = &es.getData(scenarioProbabilityToken_);
quality_map = &es.getData(PixelFEDChannelCollectionMapToken_);
SiPixelQualityProbabilities::probabilityMap m_probabilities = scenarioProbability_->getProbability_Map();
std::vector<std::string> allScenarios;
std::transform(quality_map->begin(),
quality_map->end(),
std::back_inserter(allScenarios),
[](const PixelFEDChannelCollectionMap::value_type& pair) { return pair.first; });
std::vector<std::string> allScenariosInProb;
for (auto it = m_probabilities.begin(); it != m_probabilities.end(); ++it) {
//int PUbin = it->first;
for (const auto& entry : it->second) {
auto scenario = entry.first;
auto probability = entry.second;
if (probability != 0) {
if (std::find(allScenariosInProb.begin(), allScenariosInProb.end(), scenario) == allScenariosInProb.end()) {
allScenariosInProb.push_back(scenario);
}
} // if prob!=0
} // loop on the scenarios for that PU bin
} // loop on PU bins
std::vector<std::string> notFound;
std::copy_if(allScenariosInProb.begin(),
allScenariosInProb.end(),
std::back_inserter(notFound),
[&allScenarios](const std::string& arg) {
return (std::find(allScenarios.begin(), allScenarios.end(), arg) == allScenarios.end());
});
if (!notFound.empty()) {
for (const auto& entry : notFound) {
LogError("SiPixelFEDChannelContainer")
<< "The requested scenario: " << entry << " is not found in the map!! \n";
}
throw cms::Exception("SiPixelDigitizerAlgorithm") << "Found: " << notFound.size()
<< " missing scenario(s) in SiPixelStatusScenariosRcd while "
"present in SiPixelStatusScenarioProbabilityRcd \n";
}
}
LogInfo("PixelDigitizer ") << " PixelDigitizerAlgorithm init \n";
LogInfo("PixelDigitizer ") << " PixelDigitizerAlgorithm --> UseReweighting " << UseReweighting << "\n";
LogInfo("PixelDigitizer ") << " PixelDigitizerAlgorithm --> store_SimHitEntryExitPoints_ "
<< store_SimHitEntryExitPoints_ << "\n";
LogInfo("PixelDigitizer ") << " PixelDigitizerAlgorithm --> makeDigiSimLinks_ " << makeDigiSimLinks_ << "\n";
TheNewSiPixelChargeReweightingAlgorithmClass->init(es);
int collectionIndex = 0; // I don't find what are the different collections here
int tofBin = 0;
for (int i1 = 1; i1 < 3; i1++) {
for (int i2 = 0; i2 < 2; i2++) {
if (i2 == 0) {
tofBin = PixelDigiSimLink::LowTof;
} else {
tofBin = PixelDigiSimLink::HighTof;
}
subDetTofBin theSubDetTofBin = std::make_pair(i1, tofBin);
SimHitCollMap[theSubDetTofBin] = collectionIndex;
collectionIndex++;
}
}
}
//=========================================================================
SiPixelDigitizerAlgorithm::SiPixelDigitizerAlgorithm(const edm::ParameterSet& conf, edm::ConsumesCollector iC)
: mapToken_(iC.esConsumes()),
geomToken_(iC.esConsumes()),
_signal(),
makeDigiSimLinks_(conf.getUntrackedParameter<bool>("makeDigiSimLinks", true)),
store_SimHitEntryExitPoints_(
conf.exists("store_SimHitEntryExitPoints") ? conf.getParameter<bool>("store_SimHitEntryExitPoints") : false),
use_ineff_from_db_(conf.getParameter<bool>("useDB")),
use_module_killing_(conf.getParameter<bool>("killModules")), // boolean to kill or not modules
use_deadmodule_DB_(conf.getParameter<bool>("DeadModules_DB")), // boolean to access dead modules from DB
use_LorentzAngle_DB_(conf.getParameter<bool>("LorentzAngle_DB")), // boolean to access Lorentz angle from DB
DeadModules(use_deadmodule_DB_ ? Parameters()
: conf.getParameter<Parameters>("DeadModules")), // get dead module from cfg file
TheNewSiPixelChargeReweightingAlgorithmClass(),
// Common pixel parameters
// These are parameters which are not likely to be changed
GeVperElectron(3.61E-09), // 1 electron(3.61eV, 1keV(277e, mod 9/06 d.k.
Sigma0(0.00037), // Charge diffusion constant 7->3.7
Dist300(0.0300), // normalized to 300micron Silicon
alpha2Order(conf.getParameter<bool>("Alpha2Order")), // switch on/off of E.B effect
ClusterWidth(3.), // Charge integration spread on the collection plane
// get external parameters:
// To account for upgrade geometries do not assume the number
// of layers or disks.
NumberOfBarrelLayers(conf.exists("NumPixelBarrel") ? conf.getParameter<int>("NumPixelBarrel") : 3),
NumberOfEndcapDisks(conf.exists("NumPixelEndcap") ? conf.getParameter<int>("NumPixelEndcap") : 2),
// ADC calibration 1adc count(135e.
// Corresponds to 2adc/kev, 270[e/kev]/135[e/adc](2[adc/kev]
// Be carefull, this parameter is also used in SiPixelDet.cc to
// calculate the noise in adc counts from noise in electrons.
// Both defaults should be the same.
theElectronPerADC(conf.getParameter<double>("ElectronPerAdc")),
// ADC saturation value, 255(8bit adc.
//theAdcFullScale(conf.getUntrackedParameter<int>("AdcFullScale",255)),
theAdcFullScale(conf.getParameter<int>("AdcFullScale")),
theAdcFullScLateCR(conf.getParameter<int>("AdcFullScLateCR")),
// Noise in electrons:
// Pixel cell noise, relevant for generating noisy pixels
theNoiseInElectrons(conf.getParameter<double>("NoiseInElectrons")),
// Fill readout noise, including all readout chain, relevant for smearing
//theReadoutNoise(conf.getUntrackedParameter<double>("ReadoutNoiseInElec",500.)),
theReadoutNoise(conf.getParameter<double>("ReadoutNoiseInElec")),
// Pixel threshold in units of noise:
// thePixelThreshold(conf.getParameter<double>("ThresholdInNoiseUnits")),
// Pixel threshold in electron units.
theThresholdInE_FPix(conf.getParameter<double>("ThresholdInElectrons_FPix")),
theThresholdInE_BPix(conf.getParameter<double>("ThresholdInElectrons_BPix")),
theThresholdInE_BPix_L1(conf.exists("ThresholdInElectrons_BPix_L1")
? conf.getParameter<double>("ThresholdInElectrons_BPix_L1")
: theThresholdInE_BPix),
theThresholdInE_BPix_L2(conf.exists("ThresholdInElectrons_BPix_L2")
? conf.getParameter<double>("ThresholdInElectrons_BPix_L2")
: theThresholdInE_BPix),
// Add threshold gaussian smearing:
theThresholdSmearing_FPix(conf.getParameter<double>("ThresholdSmearing_FPix")),
theThresholdSmearing_BPix(conf.getParameter<double>("ThresholdSmearing_BPix")),
theThresholdSmearing_BPix_L1(conf.exists("ThresholdSmearing_BPix_L1")
? conf.getParameter<double>("ThresholdSmearing_BPix_L1")
: theThresholdSmearing_BPix),
theThresholdSmearing_BPix_L2(conf.exists("ThresholdSmearing_BPix_L2")
? conf.getParameter<double>("ThresholdSmearing_BPix_L2")
: theThresholdSmearing_BPix),
// electrons to VCAL conversion needed in misscalibrate()
electronsPerVCAL(conf.getParameter<double>("ElectronsPerVcal")),
electronsPerVCAL_Offset(conf.getParameter<double>("ElectronsPerVcal_Offset")),
electronsPerVCAL_L1(conf.exists("ElectronsPerVcal_L1") ? conf.getParameter<double>("ElectronsPerVcal_L1")
: electronsPerVCAL),
electronsPerVCAL_L1_Offset(conf.exists("ElectronsPerVcal_L1_Offset")
? conf.getParameter<double>("ElectronsPerVcal_L1_Offset")
: electronsPerVCAL_Offset),
//theTofCut 12.5, cut in particle TOD +/- 12.5ns
//theTofCut(conf.getUntrackedParameter<double>("TofCut",12.5)),
theTofLowerCut(conf.getParameter<double>("TofLowerCut")),
theTofUpperCut(conf.getParameter<double>("TofUpperCut")),
// Get the Lorentz angle from the cfg file:
tanLorentzAnglePerTesla_FPix(use_LorentzAngle_DB_ ? 0.0
: conf.getParameter<double>("TanLorentzAnglePerTesla_FPix")),
tanLorentzAnglePerTesla_BPix(use_LorentzAngle_DB_ ? 0.0
: conf.getParameter<double>("TanLorentzAnglePerTesla_BPix")),
// signal response new parameterization: split Fpix and BPix
FPix_p0(conf.getParameter<double>("FPix_SignalResponse_p0")),
FPix_p1(conf.getParameter<double>("FPix_SignalResponse_p1")),
FPix_p2(conf.getParameter<double>("FPix_SignalResponse_p2")),
FPix_p3(conf.getParameter<double>("FPix_SignalResponse_p3")),
BPix_p0(conf.getParameter<double>("BPix_SignalResponse_p0")),
BPix_p1(conf.getParameter<double>("BPix_SignalResponse_p1")),
BPix_p2(conf.getParameter<double>("BPix_SignalResponse_p2")),
BPix_p3(conf.getParameter<double>("BPix_SignalResponse_p3")),
// Add noise
addNoise(conf.getParameter<bool>("AddNoise")),
// Smear the pixel charge with a gaussian which RMS is a function of the
// pixel charge (Danek's study)
addChargeVCALSmearing(conf.getParameter<bool>("ChargeVCALSmearing")),
// Add noisy pixels
addNoisyPixels(conf.getParameter<bool>("AddNoisyPixels")),
// Fluctuate charge in track subsegments
fluctuateCharge(conf.getUntrackedParameter<bool>("FluctuateCharge", true)),
// Control the pixel inefficiency
AddPixelInefficiency(conf.getParameter<bool>("AddPixelInefficiency")),
KillBadFEDChannels(conf.getParameter<bool>("KillBadFEDChannels")),
// Add threshold gaussian smearing:
addThresholdSmearing(conf.getParameter<bool>("AddThresholdSmearing")),
// Get the constants for the miss-calibration studies
doMissCalibrate(conf.getParameter<bool>("MissCalibrate")), // Enable miss-calibration
doMissCalInLateCR(conf.getParameter<bool>("MissCalInLateCR")), // Enable miss-calibration
theGainSmearing(conf.getParameter<double>("GainSmearing")), // sigma of the gain smearing
theOffsetSmearing(conf.getParameter<double>("OffsetSmearing")), //sigma of the offset smearing
// Add pixel radiation damage for upgrade studies
AddPixelAging(conf.getParameter<bool>("DoPixelAging")),
UseReweighting(conf.getParameter<bool>("UseReweighting")),
// delta cutoff in MeV, has to be same as in OSCAR(0.030/cmsim=1.0 MeV
//tMax(0.030), // In MeV.
//tMax(conf.getUntrackedParameter<double>("deltaProductionCut",0.030)),
tMax(conf.getParameter<double>("deltaProductionCut")),
fluctuate(fluctuateCharge ? new SiG4UniversalFluctuation() : nullptr),
theNoiser(addNoise ? new GaussianTailNoiseGenerator() : nullptr),
calmap((doMissCalibrate || doMissCalInLateCR) ? initCal() : std::map<int, CalParameters, std::less<int> >()),
theSiPixelGainCalibrationService_(use_ineff_from_db_ ? new SiPixelGainCalibrationOfflineSimService(conf, iC)
: nullptr),
pixelEfficiencies_(conf, AddPixelInefficiency, NumberOfBarrelLayers, NumberOfEndcapDisks),
pixelAging_(conf, AddPixelAging, NumberOfBarrelLayers, NumberOfEndcapDisks) {
if (use_deadmodule_DB_) {
//string to specify SiPixelQuality label
SiPixelBadModuleToken_ = iC.esConsumes(edm::ESInputTag("", conf.getParameter<std::string>("SiPixelQualityLabel")));
}
if (use_LorentzAngle_DB_) {
SiPixelLorentzAngleToken_ = iC.esConsumes();
}
if (AddPixelInefficiency && !pixelEfficiencies_.FromConfig) {
// TODO: in practice the bunchspacing is known at MixingModule
// construction time, and thus we could declare the consumption of
// the actual product. In principle, however, MixingModule is
// capable of updating (parts of) its configuration from the
// EventSetup, so if that capability is really needed we'd need to
// invent something new (similar to mayConsume in the ESProducer
// side). So for now, let's consume both payloads.
SiPixelDynamicInefficiencyToken_ = iC.esConsumes();
}
if (KillBadFEDChannels) {
scenarioProbabilityToken_ = iC.esConsumes();
PixelFEDChannelCollectionMapToken_ = iC.esConsumes();
}
LogInfo("PixelDigitizer ") << "SiPixelDigitizerAlgorithm constructed"
<< "Configuration parameters:"
<< "Threshold/Gain = "
<< "threshold in electron FPix = " << theThresholdInE_FPix
<< "threshold in electron BPix = " << theThresholdInE_BPix
<< "threshold in electron BPix Layer1 = " << theThresholdInE_BPix_L1
<< "threshold in electron BPix Layer2 = " << theThresholdInE_BPix_L2 << " "
<< theElectronPerADC << " " << theAdcFullScale << " The delta cut-off is set to " << tMax
<< " pix-inefficiency " << AddPixelInefficiency;
LogInfo("PixelDigitizer ") << " SiPixelDigitizerAlgorithm constructed with UseReweighting " << UseReweighting
<< " and store_SimHitEntryExitPoints_ " << store_SimHitEntryExitPoints_ << " \n";
TheNewSiPixelChargeReweightingAlgorithmClass = std::make_unique<SiPixelChargeReweightingAlgorithm>(conf, iC);
}
std::map<int, SiPixelDigitizerAlgorithm::CalParameters, std::less<int> > SiPixelDigitizerAlgorithm::initCal() const {
std::map<int, SiPixelDigitizerAlgorithm::CalParameters, std::less<int> > calmap;
// Prepare for the analog amplitude miss-calibration
LogDebug("PixelDigitizer ") << " miss-calibrate the pixel amplitude \n";
const bool ReadCalParameters = false;
if (ReadCalParameters) { // Read the calibration files from file
// read the calibration constants from a file (testing only)
std::ifstream in_file; // data file pointer
char filename[80] = "phCalibrationFit_C0.dat";
in_file.open(filename, std::ios::in); // in C++
if (in_file.bad()) {
LogInfo("PixelDigitizer ") << " File not found \n ";
return calmap; // signal error
}
LogInfo("PixelDigitizer ") << " file opened : " << filename << "\n";
char line[500];
for (int i = 0; i < 3; i++) {
in_file.getline(line, 500, '\n');
LogInfo("PixelDigitizer ") << line << "\n";
}
LogInfo("PixelDigitizer ") << " test map"
<< "\n";
float par0, par1, par2, par3;
int colid, rowid;
std::string name;
// Read MC tracks
for (int i = 0; i < (52 * 80); i++) { // loop over tracks
in_file >> par0 >> par1 >> par2 >> par3 >> name >> colid >> rowid;
if (in_file.bad()) { // check for errors
LogError("PixelDigitizer") << "Cannot read data file for calmap"
<< "\n";
return calmap;
}
if (in_file.eof() != 0) {
LogError("PixelDigitizer") << "calmap " << in_file.eof() << " " << in_file.gcount() << " " << in_file.fail()
<< " " << in_file.good() << " end of file "
<< "\n";
return calmap;
}
LogDebug("PixelDigitizer ") << " line " << i << " " << par0 << " " << par1 << " " << par2 << " " << par3 << " "
<< colid << " " << rowid << "\n";
CalParameters onePix;
onePix.p0 = par0;
onePix.p1 = par1;
onePix.p2 = par2;
onePix.p3 = par3;
// Convert ROC pixel index to channel
int chan = PixelIndices::pixelToChannelROC(rowid, colid);
calmap.insert(std::pair<int, CalParameters>(chan, onePix));
// Testing the index conversion, can be skipped
std::pair<int, int> p = PixelIndices::channelToPixelROC(chan);
if (rowid != p.first)
LogInfo("PixelDigitizer ") << " wrong channel row " << rowid << " " << p.first << "\n";
if (colid != p.second)
LogInfo("PixelDigitizer ") << " wrong channel col " << colid << " " << p.second << "\n";
} // pixel loop in a ROC
LogInfo("PixelDigitizer ") << " map size " << calmap.size() << " max " << calmap.max_size() << " "
<< calmap.empty() << "\n";
// LogInfo("PixelDigitizer ") << " map size " << calmap.size() << "\n";
// map<int,CalParameters,std::less<int> >::iterator ix,it;
// map<int,CalParameters,std::less<int> >::const_iterator ip;
// for (ix = calmap.begin(); ix != calmap.end(); ++ix) {
// int i = (*ix).first;
// std::pair<int,int> p = channelToPixelROC(i);
// it = calmap.find(i);
// CalParameters y = (*it).second;
// CalParameters z = (*ix).second;
// LogInfo("PixelDigitizer ") << i <<" "<<p.first<<" "<<p.second<<" "<<y.p0<<" "<<z.p0<<" "<<calmap[i].p0<<"\n";
// //int dummy=0;
// //cin>>dummy;
// }
} // end if readparameters
return calmap;
} // end initCal()
//=========================================================================
SiPixelDigitizerAlgorithm::~SiPixelDigitizerAlgorithm() {
LogDebug("PixelDigitizer") << "SiPixelDigitizerAlgorithm deleted";
}
// Read DynIneff Scale factors from Configuration
SiPixelDigitizerAlgorithm::PixelEfficiencies::PixelEfficiencies(const edm::ParameterSet& conf,
bool AddPixelInefficiency,
int NumberOfBarrelLayers,
int NumberOfEndcapDisks) {
// pixel inefficiency
// Don't use Hard coded values, read inefficiencies in from DB/python config or don't use any
int NumberOfTotLayers = NumberOfBarrelLayers + NumberOfEndcapDisks;
FPixIndex = NumberOfBarrelLayers;
if (AddPixelInefficiency) {
FromConfig = conf.exists("thePixelColEfficiency_BPix1") && conf.exists("thePixelColEfficiency_BPix2") &&
conf.exists("thePixelColEfficiency_BPix3") && conf.exists("thePixelColEfficiency_FPix1") &&
conf.exists("thePixelColEfficiency_FPix2") && conf.exists("thePixelEfficiency_BPix1") &&
conf.exists("thePixelEfficiency_BPix2") && conf.exists("thePixelEfficiency_BPix3") &&
conf.exists("thePixelEfficiency_FPix1") && conf.exists("thePixelEfficiency_FPix2") &&
conf.exists("thePixelChipEfficiency_BPix1") && conf.exists("thePixelChipEfficiency_BPix2") &&
conf.exists("thePixelChipEfficiency_BPix3") && conf.exists("thePixelChipEfficiency_FPix1") &&
conf.exists("thePixelChipEfficiency_FPix2");
if (NumberOfBarrelLayers == 3)
FromConfig = FromConfig && conf.exists("theLadderEfficiency_BPix1") && conf.exists("theLadderEfficiency_BPix2") &&
conf.exists("theLadderEfficiency_BPix3") && conf.exists("theModuleEfficiency_BPix1") &&
conf.exists("theModuleEfficiency_BPix2") && conf.exists("theModuleEfficiency_BPix3") &&
conf.exists("thePUEfficiency_BPix1") && conf.exists("thePUEfficiency_BPix2") &&
conf.exists("thePUEfficiency_BPix3") && conf.exists("theInnerEfficiency_FPix1") &&
conf.exists("theInnerEfficiency_FPix2") && conf.exists("theOuterEfficiency_FPix1") &&
conf.exists("theOuterEfficiency_FPix2") && conf.exists("thePUEfficiency_FPix_Inner") &&
conf.exists("thePUEfficiency_FPix_Outer") && conf.exists("theInstLumiScaleFactor");
if (NumberOfBarrelLayers >= 4)
FromConfig = FromConfig && conf.exists("thePixelColEfficiency_BPix4") &&
conf.exists("thePixelEfficiency_BPix4") && conf.exists("thePixelChipEfficiency_BPix4");
if (NumberOfEndcapDisks >= 3)
FromConfig = FromConfig && conf.exists("thePixelColEfficiency_FPix3") &&
conf.exists("thePixelEfficiency_FPix3") && conf.exists("thePixelChipEfficiency_FPix3");
if (FromConfig) {
LogInfo("PixelDigitizer ") << "The PixelDigitizer inefficiency configuration is read from the config file.\n";
theInstLumiScaleFactor = conf.getParameter<double>("theInstLumiScaleFactor");
int i = 0;
thePixelColEfficiency[i++] = conf.getParameter<double>("thePixelColEfficiency_BPix1");
thePixelColEfficiency[i++] = conf.getParameter<double>("thePixelColEfficiency_BPix2");
thePixelColEfficiency[i++] = conf.getParameter<double>("thePixelColEfficiency_BPix3");
if (NumberOfBarrelLayers >= 4) {
thePixelColEfficiency[i++] = conf.getParameter<double>("thePixelColEfficiency_BPix4");
}
//
i = 0;
thePixelEfficiency[i++] = conf.getParameter<double>("thePixelEfficiency_BPix1");
thePixelEfficiency[i++] = conf.getParameter<double>("thePixelEfficiency_BPix2");
thePixelEfficiency[i++] = conf.getParameter<double>("thePixelEfficiency_BPix3");
if (NumberOfBarrelLayers >= 4) {
thePixelEfficiency[i++] = conf.getParameter<double>("thePixelEfficiency_BPix4");
}
//
i = 0;
thePixelChipEfficiency[i++] = conf.getParameter<double>("thePixelChipEfficiency_BPix1");
thePixelChipEfficiency[i++] = conf.getParameter<double>("thePixelChipEfficiency_BPix2");
thePixelChipEfficiency[i++] = conf.getParameter<double>("thePixelChipEfficiency_BPix3");
if (NumberOfBarrelLayers >= 4) {
thePixelChipEfficiency[i++] = conf.getParameter<double>("thePixelChipEfficiency_BPix4");
}
//
if (NumberOfBarrelLayers == 3) {
i = 0;
theLadderEfficiency_BPix[i++] = conf.getParameter<std::vector<double> >("theLadderEfficiency_BPix1");
theLadderEfficiency_BPix[i++] = conf.getParameter<std::vector<double> >("theLadderEfficiency_BPix2");
theLadderEfficiency_BPix[i++] = conf.getParameter<std::vector<double> >("theLadderEfficiency_BPix3");
if (((theLadderEfficiency_BPix[0].size() != 20) || (theLadderEfficiency_BPix[1].size() != 32) ||
(theLadderEfficiency_BPix[2].size() != 44)) &&
(NumberOfBarrelLayers == 3))
throw cms::Exception("Configuration") << "Wrong ladder number in efficiency config!";
//
i = 0;
theModuleEfficiency_BPix[i++] = conf.getParameter<std::vector<double> >("theModuleEfficiency_BPix1");
theModuleEfficiency_BPix[i++] = conf.getParameter<std::vector<double> >("theModuleEfficiency_BPix2");
theModuleEfficiency_BPix[i++] = conf.getParameter<std::vector<double> >("theModuleEfficiency_BPix3");
if (((theModuleEfficiency_BPix[0].size() != 4) || (theModuleEfficiency_BPix[1].size() != 4) ||
(theModuleEfficiency_BPix[2].size() != 4)) &&
(NumberOfBarrelLayers == 3))
throw cms::Exception("Configuration") << "Wrong module number in efficiency config!";
//
thePUEfficiency.push_back(conf.getParameter<std::vector<double> >("thePUEfficiency_BPix1"));
thePUEfficiency.push_back(conf.getParameter<std::vector<double> >("thePUEfficiency_BPix2"));
thePUEfficiency.push_back(conf.getParameter<std::vector<double> >("thePUEfficiency_BPix3"));
if (((thePUEfficiency[0].empty()) || (thePUEfficiency[1].empty()) || (thePUEfficiency[2].empty())) &&
(NumberOfBarrelLayers == 3))
throw cms::Exception("Configuration")
<< "At least one PU efficiency (BPix) number is needed in efficiency config!";
}
// The next is needed for Phase2 Tracker studies
if (NumberOfBarrelLayers >= 5) {
if (NumberOfTotLayers > 20) {
throw cms::Exception("Configuration") << "SiPixelDigitizer was given more layers than it can handle";
}
// For Phase2 tracker layers just set the outermost BPix inefficiency to 99.9% THESE VALUES ARE HARDCODED ALSO ELSEWHERE IN THIS FILE
for (int j = 5; j <= NumberOfBarrelLayers; j++) {
thePixelColEfficiency[j - 1] = 0.999;
thePixelEfficiency[j - 1] = 0.999;
thePixelChipEfficiency[j - 1] = 0.999;
}
}
//
i = FPixIndex;
thePixelColEfficiency[i++] = conf.getParameter<double>("thePixelColEfficiency_FPix1");
thePixelColEfficiency[i++] = conf.getParameter<double>("thePixelColEfficiency_FPix2");
if (NumberOfEndcapDisks >= 3) {
thePixelColEfficiency[i++] = conf.getParameter<double>("thePixelColEfficiency_FPix3");
}
i = FPixIndex;
thePixelEfficiency[i++] = conf.getParameter<double>("thePixelEfficiency_FPix1");
thePixelEfficiency[i++] = conf.getParameter<double>("thePixelEfficiency_FPix2");
if (NumberOfEndcapDisks >= 3) {
thePixelEfficiency[i++] = conf.getParameter<double>("thePixelEfficiency_FPix3");
}
i = FPixIndex;
thePixelChipEfficiency[i++] = conf.getParameter<double>("thePixelChipEfficiency_FPix1");
thePixelChipEfficiency[i++] = conf.getParameter<double>("thePixelChipEfficiency_FPix2");
if (NumberOfEndcapDisks >= 3) {
thePixelChipEfficiency[i++] = conf.getParameter<double>("thePixelChipEfficiency_FPix3");
}
// The next is needed for Phase2 Tracker studies
if (NumberOfEndcapDisks >= 4) {
if (NumberOfTotLayers > 20) {
throw cms::Exception("Configuration") << "SiPixelDigitizer was given more layers than it can handle";
}
// For Phase2 tracker layers just set the extra FPix disk inefficiency to 99.9% THESE VALUES ARE HARDCODED ALSO ELSEWHERE IN THIS FILE
for (int j = 4 + FPixIndex; j <= NumberOfEndcapDisks + NumberOfBarrelLayers; j++) {
thePixelColEfficiency[j - 1] = 0.999;
thePixelEfficiency[j - 1] = 0.999;
thePixelChipEfficiency[j - 1] = 0.999;
}
}
//FPix Dynamic Inefficiency
if (NumberOfBarrelLayers == 3) {
i = FPixIndex;
theInnerEfficiency_FPix[i++] = conf.getParameter<double>("theInnerEfficiency_FPix1");
theInnerEfficiency_FPix[i++] = conf.getParameter<double>("theInnerEfficiency_FPix2");
i = FPixIndex;
theOuterEfficiency_FPix[i++] = conf.getParameter<double>("theOuterEfficiency_FPix1");
theOuterEfficiency_FPix[i++] = conf.getParameter<double>("theOuterEfficiency_FPix2");
thePUEfficiency.push_back(conf.getParameter<std::vector<double> >("thePUEfficiency_FPix_Inner"));
thePUEfficiency.push_back(conf.getParameter<std::vector<double> >("thePUEfficiency_FPix_Outer"));
if (((thePUEfficiency[3].empty()) || (thePUEfficiency[4].empty())) && (NumberOfEndcapDisks == 2))
throw cms::Exception("Configuration")
<< "At least one (FPix) PU efficiency number is needed in efficiency config!";
pu_scale.resize(thePUEfficiency.size());
}
} else
LogInfo("PixelDigitizer ") << "The PixelDigitizer inefficiency configuration is read from the database.\n";
}
// the first "NumberOfBarrelLayers" settings [0],[1], ... , [NumberOfBarrelLayers-1] are for the barrel pixels
// the next "NumberOfEndcapDisks" settings [NumberOfBarrelLayers],[NumberOfBarrelLayers+1], ... [NumberOfEndcapDisks+NumberOfBarrelLayers-1]
}
// Read DynIneff Scale factors from DB
void SiPixelDigitizerAlgorithm::init_DynIneffDB(const edm::EventSetup& es) {
LogDebug("PixelDigitizer ") << " In SiPixelDigitizerAlgorithm::init_DynIneffDB " << AddPixelInefficiency << " "
<< pixelEfficiencies_.FromConfig << "\n";
if (AddPixelInefficiency && !pixelEfficiencies_.FromConfig) {
SiPixelDynamicInefficiency_ = &es.getData(SiPixelDynamicInefficiencyToken_);
pixelEfficiencies_.init_from_db(geom_, SiPixelDynamicInefficiency_);
}
}
void SiPixelDigitizerAlgorithm::PixelEfficiencies::init_from_db(
const TrackerGeometry* geom, const SiPixelDynamicInefficiency* SiPixelDynamicInefficiency) {
theInstLumiScaleFactor = SiPixelDynamicInefficiency->gettheInstLumiScaleFactor();
const std::map<uint32_t, double>& PixelGeomFactorsDBIn = SiPixelDynamicInefficiency->getPixelGeomFactors();
const std::map<uint32_t, double>& ColGeomFactorsDB = SiPixelDynamicInefficiency->getColGeomFactors();
const std::map<uint32_t, double>& ChipGeomFactorsDB = SiPixelDynamicInefficiency->getChipGeomFactors();
const std::map<uint32_t, std::vector<double> >& PUFactors = SiPixelDynamicInefficiency->getPUFactors();
std::vector<uint32_t> DetIdmasks = SiPixelDynamicInefficiency->getDetIdmasks();
// Loop on all modules, initialize map for easy access
for (const auto& it_module : geom->detUnits()) {
if (dynamic_cast<PixelGeomDetUnit const*>(it_module) == nullptr)
continue;
const DetId detid = it_module->geographicalId();
uint32_t rawid = detid.rawId();
PixelGeomFactors[rawid] = 1;
ColGeomFactors[rawid] = 1;
ChipGeomFactors[rawid] = 1;
PixelGeomFactorsROCStdPixels[rawid] = std::vector<double>(16, 1);
PixelGeomFactorsROCBigPixels[rawid] = std::vector<double>(16, 1);
}
// ROC level inefficiency for phase 1 (disentangle scale factors for big and std size pixels)
std::map<uint32_t, double> PixelGeomFactorsDB;
LogDebug("PixelDigitizer ") << " Check PixelEfficiencies -- PixelGeomFactorsDBIn "
<< "\n";
if (geom->isThere(GeomDetEnumerators::P1PXB) || geom->isThere(GeomDetEnumerators::P1PXEC)) {
for (auto db_factor : PixelGeomFactorsDBIn) {
LogDebug("PixelDigitizer ") << " db_factor " << db_factor.first << " " << db_factor.second << "\n";
int shift = DetId(db_factor.first).subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel) ? BPixRocIdShift
: FPixRocIdShift;
unsigned int rocMask = rocIdMaskBits << shift;
unsigned int rocId = (((db_factor.first) & rocMask) >> shift);
if (rocId != 0) {
rocId--;
unsigned int rawid = db_factor.first & (~rocMask);
const PixelGeomDetUnit* theGeomDet = dynamic_cast<const PixelGeomDetUnit*>(geom->idToDet(rawid));
PixelTopology const* topology = &(theGeomDet->specificTopology());
const int nPixelsInROC = topology->rowsperroc() * topology->colsperroc();
const int nBigPixelsInROC = 2 * topology->rowsperroc() + topology->colsperroc() - 2;
double factor = db_factor.second;
double badFraction = 1 - factor;
double bigPixelFraction = static_cast<double>(nBigPixelsInROC) / nPixelsInROC;
double stdPixelFraction = 1. - bigPixelFraction;
double badFractionBig = std::min(bigPixelFraction, badFraction);
double badFractionStd = std::max(0., badFraction - badFractionBig);
double badFractionBigReNormalized = badFractionBig / bigPixelFraction;
double badFractionStdReNormalized = badFractionStd / stdPixelFraction;
PixelGeomFactorsROCStdPixels[rawid][rocId] *= (1. - badFractionStdReNormalized);
PixelGeomFactorsROCBigPixels[rawid][rocId] *= (1. - badFractionBigReNormalized);
} else {
PixelGeomFactorsDB[db_factor.first] = db_factor.second;
}
}
} // is Phase 1 geometry
else {
PixelGeomFactorsDB = PixelGeomFactorsDBIn;
}
LogDebug("PixelDigitizer ")
<< " Check PixelEfficiencies -- Loop on all modules and store module level geometrical scale factors "
<< "\n";
// Loop on all modules, store module level geometrical scale factors
for (const auto& it_module : geom->detUnits()) {
if (dynamic_cast<PixelGeomDetUnit const*>(it_module) == nullptr)
continue;
const DetId detid = it_module->geographicalId();
uint32_t rawid = detid.rawId();
for (auto db_factor : PixelGeomFactorsDB) {
LogDebug("PixelDigitizer ") << " db_factor PixelGeomFactorsDB " << db_factor.first << " "
<< db_factor.second << "\n";
if (matches(detid, DetId(db_factor.first), DetIdmasks))
PixelGeomFactors[rawid] *= db_factor.second;
}
for (auto db_factor : ColGeomFactorsDB) {
LogDebug("PixelDigitizer ") << " db_factor ColGeomFactorsDB " << db_factor.first << " " << db_factor.second
<< "\n";
if (matches(detid, DetId(db_factor.first), DetIdmasks))
ColGeomFactors[rawid] *= db_factor.second;
}
for (auto db_factor : ChipGeomFactorsDB) {
LogDebug("PixelDigitizer ") << " db_factor ChipGeomFactorsDB " << db_factor.first << " "
<< db_factor.second << "\n";
if (matches(detid, DetId(db_factor.first), DetIdmasks))
ChipGeomFactors[rawid] *= db_factor.second;
}
}
// piluep scale factors are calculated once per event
// therefore vector index is stored in a map for each module that matches to a db_id
size_t i = 0;
LogDebug("PixelDigitizer ") << " Check PixelEfficiencies -- PUFactors "
<< "\n";
for (const auto& factor : PUFactors) {
//
LogDebug("PixelDigitizer ") << " factor " << factor.first << " " << factor.second.size() << "\n";
for (size_t i = 0, n = factor.second.size(); i < n; i++) {
LogDebug("PixelDigitizer ") << " print factor.second for " << i << " " << factor.second[i] << "\n";
}
//
const DetId db_id = DetId(factor.first);
for (const auto& it_module : geom->detUnits()) {
if (dynamic_cast<PixelGeomDetUnit const*>(it_module) == nullptr)
continue;
const DetId detid = it_module->geographicalId();
if (!matches(detid, db_id, DetIdmasks))
continue;
if (iPU.count(detid.rawId())) {
throw cms::Exception("Database")
<< "Multiple db_ids match to same module in SiPixelDynamicInefficiency DB Object";
} else {
iPU[detid.rawId()] = i;
}
}
thePUEfficiency.push_back(factor.second);
++i;
}
pu_scale.resize(thePUEfficiency.size());
}
bool SiPixelDigitizerAlgorithm::PixelEfficiencies::matches(const DetId& detid,
const DetId& db_id,
const std::vector<uint32_t>& DetIdmasks) {
if (detid.subdetId() != db_id.subdetId())
return false;
for (size_t i = 0; i < DetIdmasks.size(); ++i) {
DetId maskid = DetId(DetIdmasks.at(i));
if (maskid.subdetId() != db_id.subdetId())
continue;
if ((detid.rawId() & maskid.rawId()) != (db_id.rawId() & maskid.rawId()) &&
(db_id.rawId() & maskid.rawId()) != DetId(db_id.det(), db_id.subdetId()).rawId())
return false;
}
return true;
}
SiPixelDigitizerAlgorithm::PixelAging::PixelAging(const edm::ParameterSet& conf,
bool AddAging,
int NumberOfBarrelLayers,
int NumberOfEndcapDisks) {
// pixel aging
// Don't use Hard coded values, read aging in from python or don't use any
if (AddAging) {
int NumberOfTotLayers = NumberOfBarrelLayers + NumberOfEndcapDisks;
FPixIndex = NumberOfBarrelLayers;
int i = 0;
thePixelPseudoRadDamage[i++] = conf.getParameter<double>("thePixelPseudoRadDamage_BPix1");
thePixelPseudoRadDamage[i++] = conf.getParameter<double>("thePixelPseudoRadDamage_BPix2");
thePixelPseudoRadDamage[i++] = conf.getParameter<double>("thePixelPseudoRadDamage_BPix3");
thePixelPseudoRadDamage[i++] = conf.getParameter<double>("thePixelPseudoRadDamage_BPix4");
// to be removed when Gaelle will have the phase2 digitizer
if (NumberOfBarrelLayers >= 5) {
if (NumberOfTotLayers > 20) {
throw cms::Exception("Configuration") << "SiPixelDigitizer was given more layers than it can handle";
}
// For Phase2 tracker layers just set the outermost BPix aging 0.
for (int j = 5; j <= NumberOfBarrelLayers; j++) {
thePixelPseudoRadDamage[j - 1] = 0.;
}
}
//
i = FPixIndex;
thePixelPseudoRadDamage[i++] = conf.getParameter<double>("thePixelPseudoRadDamage_FPix1");
thePixelPseudoRadDamage[i++] = conf.getParameter<double>("thePixelPseudoRadDamage_FPix2");
thePixelPseudoRadDamage[i++] = conf.getParameter<double>("thePixelPseudoRadDamage_FPix3");
//To be removed when Phase2 digitizer will be available
if (NumberOfEndcapDisks >= 4) {
if (NumberOfTotLayers > 20) {
throw cms::Exception("Configuration") << "SiPixelDigitizer was given more layers than it can handle";
}
// For Phase2 tracker layers just set the extra FPix disk aging to 0. BE CAREFUL THESE VALUES ARE HARDCODED ALSO ELSEWHERE IN THIS FILE
for (int j = 4 + FPixIndex; j <= NumberOfEndcapDisks + NumberOfBarrelLayers; j++) {
thePixelPseudoRadDamage[j - 1] = 0.;
}
}
}
// the first "NumberOfBarrelLayers" settings [0],[1], ... , [NumberOfBarrelLayers-1] are for the barrel pixels
// the next "NumberOfEndcapDisks" settings [NumberOfBarrelLayers],[NumberOfBarrelLayers+1], ... [NumberOfEndcapDisks+NumberOfBarrelLayers-1]
}
//=========================================================================
void SiPixelDigitizerAlgorithm::accumulateSimHits(std::vector<PSimHit>::const_iterator inputBegin,
std::vector<PSimHit>::const_iterator inputEnd,
const size_t inputBeginGlobalIndex,
const unsigned int tofBin,
const PixelGeomDetUnit* pixdet,
const GlobalVector& bfield,
const TrackerTopology* tTopo,
CLHEP::HepRandomEngine* engine) {
// produce SignalPoint's for all SimHit's in detector
// Loop over hits
uint32_t detId = pixdet->geographicalId().rawId();
size_t simHitGlobalIndex = inputBeginGlobalIndex; // This needs to stored to create the digi-sim link later
for (std::vector<PSimHit>::const_iterator ssbegin = inputBegin; ssbegin != inputEnd; ++ssbegin, ++simHitGlobalIndex) {
// skip hits not in this detector.
if ((*ssbegin).detUnitId() != detId) {
continue;
}
#ifdef TP_DEBUG
LogDebug("Pixel Digitizer") << (*ssbegin).particleType() << " " << (*ssbegin).pabs() << " "
<< (*ssbegin).energyLoss() << " " << (*ssbegin).tof() << " " << (*ssbegin).trackId()
<< " " << (*ssbegin).processType() << " " << (*ssbegin).detUnitId()
<< (*ssbegin).entryPoint() << " " << (*ssbegin).exitPoint();
#endif
std::vector<EnergyDepositUnit> ionization_points;
std::vector<SignalPoint> collection_points;
// fill collection_points for this SimHit, indpendent of topology
// Check the TOF cut
if (((*ssbegin).tof() - pixdet->surface().toGlobal((*ssbegin).localPosition()).mag() / 30.) >= theTofLowerCut &&
((*ssbegin).tof() - pixdet->surface().toGlobal((*ssbegin).localPosition()).mag() / 30.) <= theTofUpperCut) {
primary_ionization(*ssbegin, ionization_points, engine); // fills _ionization_points
drift(*ssbegin,
pixdet,
bfield,
tTopo,
ionization_points,
collection_points); // transforms _ionization_points to collection_points
// compute induced signal on readout elements and add to _signal
induce_signal(inputBegin,
inputEnd,
*ssbegin,
simHitGlobalIndex,
inputBeginGlobalIndex,
tofBin,
pixdet,
collection_points); // 1st 3 args needed only for SimHit<-->Digi link
} // end if
} // end for
}
//============================================================================
void SiPixelDigitizerAlgorithm::calculateInstlumiFactor(PileupMixingContent* puInfo) {
//Instlumi scalefactor calculating for dynamic inefficiency
if (puInfo) {
const std::vector<int>& bunchCrossing = puInfo->getMix_bunchCrossing();
const std::vector<float>& TrueInteractionList = puInfo->getMix_TrueInteractions();
//const int bunchSpacing = puInfo->getMix_bunchSpacing();
int pui = 0, p = 0;
std::vector<int>::const_iterator pu;
std::vector<int>::const_iterator pu0 = bunchCrossing.end();
for (pu = bunchCrossing.begin(); pu != bunchCrossing.end(); ++pu) {
if (*pu == 0) {
pu0 = pu;
p = pui;
}
pui++;
}
if (pu0 != bunchCrossing.end()) {
for (size_t i = 0, n = pixelEfficiencies_.thePUEfficiency.size(); i < n; i++) {
double instlumi = TrueInteractionList.at(p) * pixelEfficiencies_.theInstLumiScaleFactor;
double instlumi_pow = 1.;
pixelEfficiencies_.pu_scale[i] = 0;
for (size_t j = 0; j < pixelEfficiencies_.thePUEfficiency[i].size(); j++) {
pixelEfficiencies_.pu_scale[i] += instlumi_pow * pixelEfficiencies_.thePUEfficiency[i][j];
instlumi_pow *= instlumi;
}
}
}
} else {
for (int i = 0, n = pixelEfficiencies_.thePUEfficiency.size(); i < n; i++) {
pixelEfficiencies_.pu_scale[i] = 1.;
}
}
}
//============================================================================
void SiPixelDigitizerAlgorithm::calculateInstlumiFactor(const std::vector<PileupSummaryInfo>& ps, int bunchSpacing) {
int p = -1;
for (unsigned int i = 0; i < ps.size(); i++)
if (ps[i].getBunchCrossing() == 0)
p = i;
if (p >= 0) {
for (size_t i = 0, n = pixelEfficiencies_.thePUEfficiency.size(); i < n; i++) {
double instlumi = ps[p].getTrueNumInteractions() * pixelEfficiencies_.theInstLumiScaleFactor;
double instlumi_pow = 1.;
pixelEfficiencies_.pu_scale[i] = 0;
for (size_t j = 0; j < pixelEfficiencies_.thePUEfficiency[i].size(); j++) {
pixelEfficiencies_.pu_scale[i] += instlumi_pow * pixelEfficiencies_.thePUEfficiency[i][j];
instlumi_pow *= instlumi;
}
}
} else {
for (int i = 0, n = pixelEfficiencies_.thePUEfficiency.size(); i < n; i++) {
pixelEfficiencies_.pu_scale[i] = 1.;
}
}
}
// ========== StuckTBMs
bool SiPixelDigitizerAlgorithm::killBadFEDChannels() const { return KillBadFEDChannels; }
std::unique_ptr<PixelFEDChannelCollection> SiPixelDigitizerAlgorithm::chooseScenario(
const std::vector<PileupSummaryInfo>& ps, CLHEP::HepRandomEngine* engine) {
std::unique_ptr<PixelFEDChannelCollection> PixelFEDChannelCollection_ = nullptr;
pixelEfficiencies_.PixelFEDChannelCollection_ = nullptr;
std::vector<int> bunchCrossing;
std::vector<float> TrueInteractionList;
for (unsigned int i = 0; i < ps.size(); i++) {
bunchCrossing.push_back(ps[i].getBunchCrossing());
TrueInteractionList.push_back(ps[i].getTrueNumInteractions());
}
int pui = 0, p = 0;
std::vector<int>::const_iterator pu;
std::vector<int>::const_iterator pu0 = bunchCrossing.end();
for (pu = bunchCrossing.begin(); pu != bunchCrossing.end(); ++pu) {
if (*pu == 0) {
pu0 = pu;
p = pui;
}
pui++;
}
if (pu0 != bunchCrossing.end()) {
unsigned int PUBin = TrueInteractionList.at(p); // case delta PU=1, fix me
const auto& theProbabilitiesPerScenario = scenarioProbability_->getProbabilities(PUBin);
std::vector<double> probabilities;
probabilities.reserve(theProbabilitiesPerScenario.size());
for (auto it = theProbabilitiesPerScenario.begin(); it != theProbabilitiesPerScenario.end(); it++) {
probabilities.push_back(it->second);
}
CLHEP::RandGeneral randGeneral(*engine, &(probabilities.front()), probabilities.size());
double x = randGeneral.shoot();
unsigned int index = x * probabilities.size() - 1;
const std::string& scenario = theProbabilitiesPerScenario.at(index).first;
PixelFEDChannelCollection_ = std::make_unique<PixelFEDChannelCollection>(quality_map->at(scenario));
pixelEfficiencies_.PixelFEDChannelCollection_ =
std::make_unique<PixelFEDChannelCollection>(quality_map->at(scenario));
}
return PixelFEDChannelCollection_;
}
std::unique_ptr<PixelFEDChannelCollection> SiPixelDigitizerAlgorithm::chooseScenario(PileupMixingContent* puInfo,
CLHEP::HepRandomEngine* engine) {
//Determine scenario to use for the current event based on pileup information
std::unique_ptr<PixelFEDChannelCollection> PixelFEDChannelCollection_ = nullptr;
pixelEfficiencies_.PixelFEDChannelCollection_ = nullptr;
if (puInfo) {
const std::vector<int>& bunchCrossing = puInfo->getMix_bunchCrossing();
const std::vector<float>& TrueInteractionList = puInfo->getMix_TrueInteractions();
int pui = 0, p = 0;
std::vector<int>::const_iterator pu;
std::vector<int>::const_iterator pu0 = bunchCrossing.end();
for (pu = bunchCrossing.begin(); pu != bunchCrossing.end(); ++pu) {
if (*pu == 0) {
pu0 = pu;
p = pui;
}
pui++;
}
if (pu0 != bunchCrossing.end()) {
unsigned int PUBin = TrueInteractionList.at(p); // case delta PU=1, fix me
const auto& theProbabilitiesPerScenario = scenarioProbability_->getProbabilities(PUBin);
std::vector<double> probabilities;
probabilities.reserve(theProbabilitiesPerScenario.size());
for (auto it = theProbabilitiesPerScenario.begin(); it != theProbabilitiesPerScenario.end(); it++) {