29 std::vector<std::pair<std::string, std::string>> hnames =
31 for (
unsigned int i = 0;
i < hnames.size();
i++) {
38 auto loc =
APVloc(thick,
id, side, plane,
s);
59 gainToken_ = esConsumes<edm::Transition::BeginRun>();
68 static constexpr
float defaultGainTick = 690. / 640.;
75 if (!gainHandle.isValid()) {
76 edm::LogError(
"SiStripGainPCLWorker") <<
"gainHandle is not valid\n";
82 for (
unsigned int a = 0;
a <
histograms.APVsCollOrdered.size();
a++) {
88 APV->isMasked = siStripQuality.IsApvBad(
APV->DetId,
APV->APVId);
90 if (gainHandle->getNumberOfTags() != 2) {
91 edm::LogError(
"SiStripGainPCLWorker") <<
"NUMBER OF GAIN TAG IS EXPECTED TO BE 2\n";
95 float newPreviousGain = gainHandle->getApvGain(
APV->APVId, gainHandle->getRange(
APV->DetId, 1), 1);
96 if (
APV->PreviousGain != 1 and newPreviousGain !=
APV->PreviousGain)
97 edm::LogWarning(
"SiStripGainPCLWorker") <<
"WARNING: ParticleGain in the global tag changed\n";
98 APV->PreviousGain = newPreviousGain;
100 float newPreviousGainTick =
101 APV->isMasked ? defaultGainTick : gainHandle->getApvGain(
APV->APVId, gainHandle->getRange(
APV->DetId, 0), 0);
102 if (
APV->PreviousGainTick != 1 and newPreviousGainTick !=
APV->PreviousGainTick) {
104 <<
"WARNING: TickMarkGain in the global tag changed\n"
106 <<
" APV->SubDet: " <<
APV->SubDet <<
" APV->APVId:" <<
APV->APVId << std::endl
107 <<
" APV->PreviousGainTick: " <<
APV->PreviousGainTick <<
" newPreviousGainTick: " << newPreviousGainTick
110 APV->PreviousGainTick = newPreviousGainTick;
123 const auto simple1d = dynamic_cast<const SiStripRecHit1D*>(
hit);
124 const auto simple = dynamic_cast<const SiStripRecHit2D*>(
hit);
125 const auto matched = dynamic_cast<const SiStripMatchedRecHit2D*>(
hit);
126 const auto pixel = dynamic_cast<const SiPixelRecHit*>(
hit);
132 clusters.emplace_back(simple->geographicalId().rawId(), simple->cluster().get(),
nullptr);
133 }
else if (simple1d) {
134 clusters.emplace_back(simple1d->geographicalId().rawId(), simple1d->cluster().get(),
nullptr);
136 clusters.emplace_back(
pixel->geographicalId().rawId(),
nullptr,
pixel->cluster().get());
143 if ((!dynamic_cast<const StripGeomDetUnit*>(gdu)) && (!dynamic_cast<const PixelGeomDetUnit*>(gdu))) {
145 <<
"DetId " << detId <<
" does not seem to belong to the tracker";
148 const auto plane = gdu->surface();
149 const auto trapBounds = dynamic_cast<const TrapezoidalPlaneBounds*>(&plane.bounds());
150 const auto rectBounds = dynamic_cast<const RectangularPlaneBounds*>(&plane.bounds());
152 static constexpr
double distFromBorder = 1.0;
153 double halfLength = 0.;
155 halfLength = trapBounds->parameters()[3];
156 }
else if (rectBounds) {
157 halfLength = .5 * gdu->surface().bounds().length();
178 unsigned int eventnumber =
iEvent.id().event();
181 edm::LogInfo(
"SiStripGainsPCLWorker") <<
"Processing run " <<
runnumber <<
" and event " << eventnumber << std::endl;
193 LogDebug(
"SiStripGainsPCLWorker") << elem.first <<
" - " << elem.second.m_string <<
" "
194 << elem.second.m_subdetectorId <<
" " << elem.second.m_subdetectorSide <<
" "
195 << elem.second.m_subdetectorPlane << std::endl;
202 std::size_t nStoredClusters{0};
203 for (
const auto&
assoc : *trajTrackAssociations) {
204 const auto traj =
assoc.key.get();
213 for (
const auto& meas : traj->measurements()) {
214 const auto& trajState = meas.updatedState();
219 auto clusters = getClusters(meas.recHit()->hit());
220 for (
const auto hitCluster :
clusters) {
223 bool overlapping =
false;
227 if (hitCluster.strip) {
228 const auto& ampls = hitCluster.strip->amplitudes();
229 firstStrip = hitCluster.strip->firstStrip();
231 charge = hitCluster.strip->charge();
232 saturation = std::any_of(ampls.begin(), ampls.end(), [](uint8_t amp) {
return amp >= 254; });
234 overlapping = (((firstStrip % 128) == 0) || ((firstStrip / 128) != ((firstStrip +
int(
nStrips)) / 128)));
235 }
else if (hitCluster.pixel) {
236 const auto& ampls = hitCluster.pixel->pixelADC();
237 const int firstRow = hitCluster.pixel->minPixelRow();
238 const int firstCol = hitCluster.pixel->minPixelCol();
239 firstStrip = ((firstRow / 80) << 3 | (firstCol / 52)) * 128;
241 for (
const auto amp : ampls) {
248 std::shared_ptr<stAPVGain>
APV =
histograms.APVsColl.at((hitCluster.det << 4) | (firstStrip / 128));
250 const auto farFromEdge = (hitCluster.strip ? isFarFromBorder(trajState, hitCluster.det, tGeom) :
true);
251 if ((
APV->SubDet > 2) &&
255 int clusterCharge = 0;
256 if (
APV->SubDet > 2) {
259 for (
const auto origCharge : hitCluster.strip->amplitudes()) {
263 stripCharge =
int(origCharge /
APV->CalibGain);
265 stripCharge =
int(origCharge * (
APV->PreviousGain /
APV->CalibGain));
269 stripCharge = origCharge;
271 stripCharge =
int(origCharge *
APV->PreviousGain);
274 if (stripCharge > 1024) {
277 }
else if (stripCharge > 254) {
281 clusterCharge += stripCharge;
289 clusterCharge =
charge / 265.0;
293 const auto path = (10. *
APV->Thickness) /
std::abs(trackDir.z() / trackDir.mag());
294 double ClusterChargeOverPath = ((double)clusterCharge) /
path;
295 if (
APV->SubDet > 2) {
297 ClusterChargeOverPath /=
APV->PreviousGain;
300 ClusterChargeOverPath *=
APV->PreviousGain;
309 histograms.Charge_Vs_Index[elepos]->Fill(
APV->Index, ClusterChargeOverPath);
312 <<
" i " << iCluster <<
" useCalibration " <<
useCalibration <<
" FirstSetOfConstants "
314 <<
" APV->DetId " <<
APV->DetId <<
" APV->Index " <<
APV->Index <<
" Charge " << clusterCharge <<
" Path "
315 <<
path <<
" ClusterChargeOverPath " << ClusterChargeOverPath << std::endl;
319 for (
const auto sCharge : hitCluster.strip->amplitudes()) {
327 int mCharge2 = mCharge1 *
APV->PreviousGain;
328 int mCharge3 = mCharge1 *
APV->PreviousGainTick;
329 int mCharge4 = mCharge1 *
APV->PreviousGain *
APV->PreviousGainTick;
331 LogDebug(
"SiStripGainsPCLWorker") <<
" full charge " << mCharge1 <<
" remove G2 " << mCharge2 <<
" remove G1 "
332 << mCharge3 <<
" remove G1*G2 " << mCharge4 << std::endl;
346 histograms.Charge_Vs_PathlengthTIB[elepos]->Fill(
path, clusterCharge);
349 histograms.Charge_Vs_PathlengthTOB[elepos]->Fill(
path, clusterCharge);
353 histograms.Charge_Vs_PathlengthTIDM[elepos]->Fill(
path, clusterCharge);
355 else if (
APV->Eta > 0) {
356 histograms.Charge_Vs_PathlengthTIDP[elepos]->Fill(
path, clusterCharge);
361 if (
APV->Thickness < 0.04) {
362 histograms.Charge_Vs_PathlengthTECM1[elepos]->Fill(
path, clusterCharge);
364 else if (
APV->Thickness > 0.04) {
365 histograms.Charge_Vs_PathlengthTECM2[elepos]->Fill(
path, clusterCharge);
367 }
else if (
APV->Eta > 0) {
368 if (
APV->Thickness < 0.04) {
369 histograms.Charge_Vs_PathlengthTECP1[elepos]->Fill(
path, clusterCharge);
371 else if (
APV->Thickness > 0.04) {
372 histograms.Charge_Vs_PathlengthTECP2[elepos]->Fill(
path, clusterCharge);
382 histograms.EventStats->Fill(2., 0., nStoredClusters);
397 auto const&
Det = bareTkGeomPtr->
dets();
399 edm::LogInfo(
"SiStripGainsPCLWorker") <<
" Resetting APV struct" << std::endl;
401 unsigned int Index = 0;
403 for (
unsigned int i = 0;
i <
Det.size();
i++) {
409 auto DetUnit = dynamic_cast<const StripGeomDetUnit*>(
Det[
i]);
414 unsigned int NAPV = Topo.
nstrips() / 128;
416 for (
unsigned int j = 0;
j < NAPV;
j++) {
417 auto APV = std::make_shared<stAPVGain>();
426 APV->FitWidthErr = -1;
430 APV->PreviousGain = 1;
431 APV->PreviousGainTick = 1;
432 APV->x = DetUnit->position().basicVector().x();
433 APV->y = DetUnit->position().basicVector().y();
434 APV->z = DetUnit->position().basicVector().z();
435 APV->Eta = DetUnit->position().basicVector().eta();
436 APV->Phi = DetUnit->position().basicVector().phi();
437 APV->R = DetUnit->position().basicVector().transverse();
438 APV->Thickness = DetUnit->surface().bounds().thickness();
440 APV->isMasked =
false;
450 for (
unsigned int i = 0;
i <
Det.size();
455 auto DetUnit = dynamic_cast<const PixelGeomDetUnit*>(
Det[
i]);
460 unsigned int NROCRow = Topo.
nrows() / (80.);
461 unsigned int NROCCol = Topo.
ncolumns() / (52.);
463 for (
unsigned int j = 0;
j < NROCRow;
j++) {
464 for (
unsigned int i = 0;
i < NROCCol;
i++) {
465 auto APV = std::make_shared<stAPVGain>();
469 APV->APVId = (
j << 3 |
i);
474 APV->FitWidthErr = -1;
477 APV->PreviousGain = 1;
478 APV->PreviousGainTick = 1;
479 APV->x = DetUnit->position().basicVector().x();
480 APV->y = DetUnit->position().basicVector().y();
481 APV->z = DetUnit->position().basicVector().z();
482 APV->Eta = DetUnit->position().basicVector().eta();
483 APV->Phi = DetUnit->position().basicVector().phi();
484 APV->R = DetUnit->position().basicVector().transverse();
485 APV->Thickness = DetUnit->surface().bounds().thickness();
486 APV->isMasked =
false;
517 edm::LogInfo(
"SiStripGainsPCLWorker") <<
"Setting " << dqm_dir <<
" in DQM and booking histograms for tag " <<
tag
525 histograms.EventStats = ibooker.
book2S(
"EventStats",
"Statistics", 3, -0.5, 2.5, 1, 0, 1);
526 histograms.EventStats->setBinLabel(1,
"events count", 1);
527 histograms.EventStats->setBinLabel(2,
"tracks count", 1);
528 histograms.EventStats->setBinLabel(3,
"clusters count", 1);
531 if (!stag.empty() && stag[0] !=
'_')
532 stag.insert(0, 1,
'_');
564 std::vector<float> binXarray;
567 binXarray.push_back((
float)
a);
570 std::array<float, 688> binYarray;
572 double p1 = 0.002113;
573 double p2 = 69.01576;
575 for (
int b = 0;
b < 687;
b++) {
582 binYarray[687] = 4000.;
592 ibooker.
book2S(cvi.c_str(), cvi.c_str(),
histograms.NStripAPVs, &binXarray[0], 687, binYarray.data()));
594 it =
histograms.Charge_Vs_PathlengthTIB.begin();
595 histograms.Charge_Vs_PathlengthTIB.insert(it + elepos,
596 ibooker.
book2S(cvpTIB.c_str(), cvpTIB.c_str(), 20, 0.3, 1.3, 250, 0, 2000));
598 it =
histograms.Charge_Vs_PathlengthTOB.begin();
599 histograms.Charge_Vs_PathlengthTOB.insert(it + elepos,
600 ibooker.
book2S(cvpTOB.c_str(), cvpTOB.c_str(), 20, 0.3, 1.3, 250, 0, 2000));
602 it =
histograms.Charge_Vs_PathlengthTIDP.begin();
604 it + elepos, ibooker.
book2S(cvpTIDP.c_str(), cvpTIDP.c_str(), 20, 0.3, 1.3, 250, 0, 2000));
606 it =
histograms.Charge_Vs_PathlengthTIDM.begin();
608 it + elepos, ibooker.
book2S(cvpTIDM.c_str(), cvpTIDM.c_str(), 20, 0.3, 1.3, 250, 0, 2000));
610 it =
histograms.Charge_Vs_PathlengthTECP1.begin();
612 it + elepos, ibooker.
book2S(cvpTECP1.c_str(), cvpTECP1.c_str(), 20, 0.3, 1.3, 250, 0, 2000));
614 it =
histograms.Charge_Vs_PathlengthTECP2.begin();
616 it + elepos, ibooker.
book2S(cvpTECP2.c_str(), cvpTECP2.c_str(), 20, 0.3, 1.3, 250, 0, 2000));
618 it =
histograms.Charge_Vs_PathlengthTECM1.begin();
620 it + elepos, ibooker.
book2S(cvpTECM1.c_str(), cvpTECM1.c_str(), 20, 0.3, 1.3, 250, 0, 2000));
622 it =
histograms.Charge_Vs_PathlengthTECM2.begin();
624 it + elepos, ibooker.
book2S(cvpTECM2.c_str(), cvpTECM2.c_str(), 20, 0.3, 1.3, 250, 0, 2000));
626 std::vector<std::pair<std::string, std::string>> hnames =
628 for (
unsigned int i = 0;
i < hnames.size();
i++) {
634 for (
unsigned int i = 0;
i < hnames.size();
i++) {
640 for (
unsigned int i = 0;
i < hnames.size();
i++) {
646 for (
unsigned int i = 0;
i < hnames.size();
i++) {