52 tTopoToken_ = esConsumes<edm::Transition::BeginRun>();
54 gainToken_ = esConsumes<edm::Transition::BeginRun>();
62 static constexpr
float defaultGainTick = 690. / 640.;
68 if (!gainHandle.isValid()) {
69 edm::LogError(
"SiStripGainPCLHarvester") <<
"gainHandle is not valid\n";
81 APV->isMasked = stripQuality.IsApvBad(
APV->DetId,
APV->APVId);
83 if (gainHandle->getNumberOfTags() != 2) {
84 edm::LogError(
"SiStripGainPCLHarvester") <<
"NUMBER OF GAIN TAG IS EXPECTED TO BE 2\n";
88 float newPreviousGain = gainHandle->getApvGain(
APV->APVId, gainHandle->getRange(
APV->DetId, 1), 1);
89 if (
APV->PreviousGain != 1 and newPreviousGain !=
APV->PreviousGain)
90 edm::LogWarning(
"SiStripGainPCLHarvester") <<
"WARNING: ParticleGain in the global tag changed\n";
91 APV->PreviousGain = newPreviousGain;
93 float newPreviousGainTick =
94 APV->isMasked ? defaultGainTick : gainHandle->getApvGain(
APV->APVId, gainHandle->getRange(
APV->DetId, 0), 0);
95 if (
APV->PreviousGainTick != 1 and newPreviousGainTick !=
APV->PreviousGainTick) {
97 <<
"WARNING: TickMarkGain in the global tag changed\n"
99 <<
" APV->SubDet: " <<
APV->SubDet <<
" APV->APVId:" <<
APV->APVId << std::endl
100 <<
" APV->PreviousGainTick: " <<
APV->PreviousGainTick <<
" newPreviousGainTick: " << newPreviousGainTick
103 APV->PreviousGainTick = newPreviousGainTick;
109 edm::LogInfo(
"SiStripGainsPCLHarvester") <<
"Starting harvesting statistics" << std::endl;
114 if (!stag.empty() && stag[0] !=
'_')
115 stag.insert(0, 1,
'_');
121 if (Charge_Vs_Index ==
nullptr) {
123 <<
"Harvesting: could not retrieve " << cvi.c_str() <<
", statistics will not be summed!" << std::endl;
126 <<
"Harvesting " << (Charge_Vs_Index)->getTH2S()->GetEntries() <<
" more clusters" << std::endl;
130 std::unique_ptr<SiStripApvGain> theAPVGains = this->
getNewObject(Charge_Vs_Index);
139 throw std::runtime_error(
"PoolDBService required.");
141 edm::LogInfo(
"SiStripGainsPCLHarvester") <<
"Will not produce payload!" << std::endl;
153 std::vector<APVGain::APVmon> new_charge_histos;
154 std::vector<std::pair<std::string, std::string>> cnames =
156 for (
unsigned int i = 0;
i < cnames.size();
i++) {
170 ibooker_.
book2DD(
"MPVvsEtaTIB",
"MPV vs Eta TIB", 50, -3.0, 3.0, MPVbin, MPVmin, MPVmax);
172 ibooker_.
book2DD(
"MPVvsEtaTID",
"MPV vs Eta TID", 50, -3.0, 3.0, MPVbin, MPVmin, MPVmax);
174 ibooker_.
book2DD(
"MPVvsEtaTOB",
"MPV vs Eta TOB", 50, -3.0, 3.0, MPVbin, MPVmin, MPVmax);
176 ibooker_.
book2DD(
"MPVvsEtaTEC",
"MPV vs Eta TEC", 50, -3.0, 3.0, MPVbin, MPVmin, MPVmax);
178 ibooker_.
book2DD(
"MPVvsEtaTEC1",
"MPV vs Eta TEC-thin", 50, -3.0, 3.0, MPVbin, MPVmin, MPVmax);
180 ibooker_.
book2DD(
"MPVvsEtaTEC2",
"MPV vs Eta TEC-thick", 50, -3.0, 3.0, MPVbin, MPVmin, MPVmax);
183 ibooker_.
book2DD(
"MPVvsPhiTIB",
"MPV vs Phi TIB", 50, -3.4, 3.4, MPVbin, MPVmin, MPVmax);
185 ibooker_.
book2DD(
"MPVvsPhiTID",
"MPV vs Phi TID", 50, -3.4, 3.4, MPVbin, MPVmin, MPVmax);
187 ibooker_.
book2DD(
"MPVvsPhiTOB",
"MPV vs Phi TOB", 50, -3.4, 3.4, MPVbin, MPVmin, MPVmax);
189 ibooker_.
book2DD(
"MPVvsPhiTEC",
"MPV vs Phi TEC", 50, -3.4, 3.4, MPVbin, MPVmin, MPVmax);
191 ibooker_.
book2DD(
"MPVvsPhiTEC1",
"MPV vs Phi TEC-thin ", 50, -3.4, 3.4, MPVbin, MPVmin, MPVmax);
193 ibooker_.
book2DD(
"MPVvsPhiTEC2",
"MPV vs Phi TEC-thick", 50, -3.4, 3.4, MPVbin, MPVmin, MPVmax);
195 MonitorElement* NoMPVfit = ibooker_.
book2DD(
"NoMPVfit",
"Modules with bad Landau Fit", 350, -350, 350, 240, 0, 120);
196 MonitorElement* NoMPVmasked = ibooker_.
book2DD(
"NoMPVmasked",
"Masked Modules", 350, -350, 350, 240, 0, 120);
211 MonitorElement* MPVsTECthick = ibooker_.
book1DD(
"MPV_TEC2",
"MPV TEC thick", MPVbin, MPVmin, MPVmax);
218 MonitorElement* MPVErrorVsMPV = ibooker_.
book2DD(
"MPVErrorVsMPV",
"MPV Error vs MPV", 300, 0, 600, 150, 0, 150);
219 MonitorElement* MPVErrorVsEta = ibooker_.
book2DD(
"MPVErrorVsEta",
"MPV Error vs Eta", 50, -3.0, 3.0, 150, 0, 150);
220 MonitorElement* MPVErrorVsPhi = ibooker_.
book2DD(
"MPVErrorVsPhi",
"MPV Error vs Phi", 50, -3.4, 3.4, 150, 0, 150);
221 MonitorElement* MPVErrorVsN = ibooker_.
book2DD(
"MPVErrorVsN",
"MPV Error vs N", 500, 0, 1000, 150, 0, 150);
223 MonitorElement* DiffWRTPrevGainTIB = ibooker_.
book1DD(
"DiffWRTPrevGainTIB",
"Diff w.r.t. PrevGain TIB", 250, 0, 2);
224 MonitorElement* DiffWRTPrevGainTID = ibooker_.
book1DD(
"DiffWRTPrevGainTID",
"Diff w.r.t. PrevGain TID", 250, 0, 2);
225 MonitorElement* DiffWRTPrevGainTOB = ibooker_.
book1DD(
"DiffWRTPrevGainTOB",
"Diff w.r.t. PrevGain TOB", 250, 0, 2);
226 MonitorElement* DiffWRTPrevGainTEC = ibooker_.
book1DD(
"DiffWRTPrevGainTEC",
"Diff w.r.t. PrevGain TEC", 250, 0, 2);
229 ibooker_.
book2DD(
"GainVsPrevGainTIB",
"Gain vs PrevGain TIB", 100, 0, 2, 100, 0, 2);
231 ibooker_.
book2DD(
"GainVsPrevGainTID",
"Gain vs PrevGain TID", 100, 0, 2, 100, 0, 2);
233 ibooker_.
book2DD(
"GainVsPrevGainTOB",
"Gain vs PrevGain TOB", 100, 0, 2, 100, 0, 2);
235 ibooker_.
book2DD(
"GainVsPrevGainTEC",
"Gain vs PrevGain TEC", 100, 0, 2, 100, 0, 2);
242 unsigned int Index =
APV->Index;
246 float Eta =
APV->Eta;
249 float Thickness =
APV->Thickness;
250 double FitMPV =
APV->FitMPV;
251 double FitMPVErr =
APV->FitMPVErr;
253 double NEntries =
APV->NEntries;
254 double PreviousGain =
APV->PreviousGain;
261 TH2S* chvsidx = (Charge_Vs_Index)->getTH2S();
262 int bin = chvsidx->GetXaxis()->FindBin(Index);
263 TH1D* Proj = chvsidx->ProjectionY(
"proj",
bin,
bin);
264 for (
int binId = 0; binId < Proj->GetXaxis()->GetNbins(); binId++) {
265 double new_charge = Proj->GetXaxis()->GetBinCenter(binId) /
Gain;
266 if (Proj->GetBinContent(binId) != 0.) {
267 for (
unsigned int h = 0;
h < charge_histos.size();
h++) {
268 TH1D* chisto = (charge_histos[
h])->getTH1D();
269 for (
int e = 0;
e < Proj->GetBinContent(binId);
e++)
270 chisto->Fill(new_charge);
287 if (Thickness < 0.04)
288 MPVs320->
Fill(FitMPV);
289 if (Thickness > 0.04)
290 MPVs500->
Fill(FitMPV);
292 MPVError->
Fill(FitMPVErr);
293 MPVErrorVsMPV->
Fill(FitMPV, FitMPVErr);
294 MPVErrorVsEta->
Fill(Eta, FitMPVErr);
295 MPVErrorVsPhi->
Fill(
Phi, FitMPVErr);
296 MPVErrorVsN->
Fill(NEntries, FitMPVErr);
299 MPV_Vs_EtaTIB->
Fill(Eta, FitMPV);
300 MPV_Vs_PhiTIB->
Fill(
Phi, FitMPV);
301 MPVsTIB->
Fill(FitMPV);
304 MPV_Vs_EtaTID->
Fill(Eta, FitMPV);
305 MPV_Vs_PhiTID->
Fill(
Phi, FitMPV);
306 MPVsTID->
Fill(FitMPV);
308 MPVsTIDM->
Fill(FitMPV);
310 MPVsTIDP->
Fill(FitMPV);
313 MPV_Vs_EtaTOB->
Fill(Eta, FitMPV);
314 MPV_Vs_PhiTOB->
Fill(
Phi, FitMPV);
315 MPVsTOB->
Fill(FitMPV);
318 MPV_Vs_EtaTEC->
Fill(Eta, FitMPV);
319 MPV_Vs_PhiTEC->
Fill(
Phi, FitMPV);
320 MPVsTEC->
Fill(FitMPV);
322 MPVsTECM->
Fill(FitMPV);
324 MPVsTECP->
Fill(FitMPV);
325 if (Thickness < 0.04) {
326 MPV_Vs_EtaTECthin->
Fill(Eta, FitMPV);
327 MPV_Vs_PhiTECthin->
Fill(
Phi, FitMPV);
328 MPVsTECthin->
Fill(FitMPV);
330 MPVsTECP1->
Fill(FitMPV);
332 MPVsTECM1->
Fill(FitMPV);
334 if (Thickness > 0.04) {
335 MPV_Vs_EtaTECthick->
Fill(Eta, FitMPV);
336 MPV_Vs_PhiTECthick->
Fill(
Phi, FitMPV);
337 MPVsTECthick->
Fill(FitMPV);
339 MPVsTECP2->
Fill(FitMPV);
341 MPVsTECM2->
Fill(FitMPV);
346 if (
SubDet == 3 && PreviousGain != 0.)
347 DiffWRTPrevGainTIB->
Fill(
Gain / PreviousGain);
348 else if (
SubDet == 4 && PreviousGain != 0.)
349 DiffWRTPrevGainTID->
Fill(
Gain / PreviousGain);
350 else if (
SubDet == 5 && PreviousGain != 0.)
351 DiffWRTPrevGainTOB->
Fill(
Gain / PreviousGain);
352 else if (
SubDet == 6 && PreviousGain != 0.)
353 DiffWRTPrevGainTEC->
Fill(
Gain / PreviousGain);
356 GainVsPrevGainTIB->
Fill(PreviousGain,
Gain);
358 GainVsPrevGainTID->
Fill(PreviousGain,
Gain);
360 GainVsPrevGainTOB->
Fill(PreviousGain,
Gain);
362 GainVsPrevGainTEC->
Fill(PreviousGain,
Gain);
369 TH1F* Proj =
nullptr;
370 double FitResults[6];
371 double MPVmean = 300;
373 if (Charge_Vs_Index ==
nullptr) {
375 <<
"Harvesting: could not execute algoComputeMPVandGain method because " <<
m_calibrationMode
376 <<
" statistics cannot be retrieved.\n"
377 <<
"Please check if input contains " <<
m_calibrationMode <<
" data." << std::endl;
381 TH2S* chvsidx = (Charge_Vs_Index)->getTH2S();
383 printf(
"Progressing Bar :0%% 20%% 40%% 60%% 80%% 100%%\n");
384 printf(
"Fitting Charge Distribution :");
385 int TreeStep =
APVsColl.size() / 50;
388 if (
I % TreeStep == 0) {
392 std::shared_ptr<stAPVGain>
APV = it->second;
394 APV->Bin = chvsidx->GetXaxis()->FindBin(
APV->Index);
397 APV->Gain =
APV->PreviousGain;
402 Proj = (TH1F*)(chvsidx->ProjectionY(
403 "", chvsidx->GetXaxis()->FindBin(
APV->Index), chvsidx->GetXaxis()->FindBin(
APV->Index),
"e"));
409 int SecondAPVId =
APV->APVId;
410 if (SecondAPVId % 2 == 0) {
411 SecondAPVId = SecondAPVId + 1;
413 SecondAPVId = SecondAPVId - 1;
415 std::shared_ptr<stAPVGain> APV2 =
APVsColl[(
APV->DetId << 4) | SecondAPVId];
417 APV2->Bin = chvsidx->GetXaxis()->FindBin(APV2->Index);
418 TH1F* Proj2 = (TH1F*)(chvsidx->ProjectionY(
"", APV2->Bin, APV2->Bin,
"e"));
424 for (
unsigned int i = 0;
i < 16;
i++) {
428 std::shared_ptr<stAPVGain> APV2 = tmpit->second;
429 if (APV2->DetId !=
APV->DetId || APV2->APVId ==
APV->APVId)
432 APV2->Bin = chvsidx->GetXaxis()->FindBin(APV2->Index);
433 TH1F* Proj2 = (TH1F*)(chvsidx->ProjectionY(
"", APV2->Bin, APV2->Bin,
"e"));
445 APV->FitMPV = FitResults[0];
446 APV->FitMPVErr = FitResults[1];
447 APV->FitWidth = FitResults[2];
448 APV->FitWidthErr = FitResults[3];
449 APV->FitChi2 = FitResults[4];
450 APV->FitNorm = FitResults[5];
451 APV->NEntries = Proj->GetEntries();
454 APV->Gain =
APV->FitMPV / MPVmean;
458 APV->Gain =
APV->PreviousGain;
472 FitResults[0] = -0.5;
474 FitResults[2] = -0.5;
476 FitResults[4] = -0.5;
483 TF1 MyLandau(
"MyLandau",
"landau", LowRange, HighRange);
484 MyLandau.SetParameter(1, 300);
485 InputHisto->Fit(&MyLandau,
"0QR WW");
488 FitResults[0] = MyLandau.GetParameter(1);
489 FitResults[1] = MyLandau.GetParError(1);
490 FitResults[2] = MyLandau.GetParameter(2);
491 FitResults[3] = MyLandau.GetParError(2);
492 FitResults[4] = MyLandau.GetChisquare() / MyLandau.GetNDF();
493 FitResults[5] = MyLandau.GetParameter(0);
498 if (FitResults[0] <= 0)
513 auto const&
Det = newBareTkGeomPtr->dets();
515 unsigned int Index = 0;
517 for (
unsigned int i = 0;
i <
Det.size();
i++) {
523 auto DetUnit = dynamic_cast<const StripGeomDetUnit*>(
Det[
i]);
528 unsigned int NAPV = Topo.
nstrips() / 128;
530 for (
unsigned int j = 0;
j < NAPV;
j++) {
531 auto APV = std::make_shared<stAPVGain>();
540 APV->FitWidthErr = -1;
544 APV->PreviousGain = 1;
545 APV->PreviousGainTick = 1;
546 APV->x = DetUnit->position().basicVector().x();
547 APV->y = DetUnit->position().basicVector().y();
548 APV->z = DetUnit->position().basicVector().z();
549 APV->Eta = DetUnit->position().basicVector().eta();
550 APV->Phi = DetUnit->position().basicVector().phi();
551 APV->R = DetUnit->position().basicVector().transverse();
552 APV->Thickness = DetUnit->surface().bounds().thickness();
554 APV->isMasked =
false;
564 for (
unsigned int i = 0;
i <
Det.size();
569 auto DetUnit = dynamic_cast<const PixelGeomDetUnit*>(
Det[
i]);
574 unsigned int NROCRow = Topo.
nrows() / (80.);
575 unsigned int NROCCol = Topo.
ncolumns() / (52.);
577 for (
unsigned int j = 0;
j < NROCRow;
j++) {
578 for (
unsigned int i = 0;
i < NROCCol;
i++) {
579 auto APV = std::make_shared<stAPVGain>();
583 APV->APVId = (
j << 3 |
i);
588 APV->FitWidthErr = -1;
591 APV->PreviousGain = 1;
592 APV->PreviousGainTick = 1;
593 APV->x = DetUnit->position().basicVector().x();
594 APV->y = DetUnit->position().basicVector().y();
595 APV->z = DetUnit->position().basicVector().z();
596 APV->Eta = DetUnit->position().basicVector().eta();
597 APV->Phi = DetUnit->position().basicVector().phi();
598 APV->R = DetUnit->position().basicVector().transverse();
599 APV->Thickness = DetUnit->surface().bounds().thickness();
600 APV->isMasked =
false;
627 if (Charge_Vs_Index ==
nullptr) {
629 <<
"produceTagFilter -> Return false: could not retrieve the " <<
m_calibrationMode <<
" statistics.\n"
630 <<
"Please check if input contains " <<
m_calibrationMode <<
" data." << std::endl;
634 float integral = (Charge_Vs_Index)->getTH2S()->Integral();
638 <<
"produceTagFilter -> Return false: Statistics is too low : " <<
integral << std::endl;
644 <<
"produceTagFilter -> Return false: ratio of GOOD/TOTAL is too low: " << (1.0 *
GOOD) / (
GOOD +
BAD)
653 std::unique_ptr<SiStripApvGain>
obj = std::make_unique<SiStripApvGain>();
657 <<
"getNewObject -> will not produce a paylaod because produceTagFilter returned false " << std::endl;
663 std::vector<float> theSiStripVector;
664 unsigned int PreviousDetId = 0;
667 if (
APV ==
nullptr) {
671 if (
APV->SubDet <= 2)
673 if (
APV->DetId != PreviousDetId) {
674 if (!theSiStripVector.empty()) {
676 if (!
obj->put(PreviousDetId,
range))
677 printf(
"Bug to put detId = %i\n", PreviousDetId);
679 theSiStripVector.clear();
680 PreviousDetId =
APV->DetId;
682 theSiStripVector.push_back(
APV->Gain);
684 LogDebug(
"SiStripGainsPCLHarvester") <<
" DetId: " <<
APV->DetId <<
" APV: " <<
APV->APVId
685 <<
" Gain: " <<
APV->Gain << std::endl;
687 if (!theSiStripVector.empty()) {
689 if (!
obj->put(PreviousDetId,
range))
690 printf(
"Bug to put detId = %i\n", PreviousDetId);