52 tTopoToken_ = esConsumes<edm::Transition::EndRun>();
54 gainToken_ = esConsumes<edm::Transition::BeginRun>();
62 static constexpr
float defaultGainTick = 690. / 640.;
67 if (!gainHandle.isValid()) {
68 edm::LogError(
"SiStripGainPCLHarvester") <<
"gainHandle is not valid\n";
80 APV->isMasked = stripQuality.IsApvBad(
APV->DetId,
APV->APVId);
82 if (gainHandle->getNumberOfTags() != 2) {
83 edm::LogError(
"SiStripGainPCLHarvester") <<
"NUMBER OF GAIN TAG IS EXPECTED TO BE 2\n";
87 float newPreviousGain = gainHandle->getApvGain(
APV->APVId, gainHandle->getRange(
APV->DetId, 1), 1);
88 if (
APV->PreviousGain != 1 and newPreviousGain !=
APV->PreviousGain)
89 edm::LogWarning(
"SiStripGainPCLHarvester") <<
"WARNING: ParticleGain in the global tag changed\n";
90 APV->PreviousGain = newPreviousGain;
92 float newPreviousGainTick =
93 APV->isMasked ? defaultGainTick : gainHandle->getApvGain(
APV->APVId, gainHandle->getRange(
APV->DetId, 0), 0);
94 if (
APV->PreviousGainTick != 1 and newPreviousGainTick !=
APV->PreviousGainTick) {
96 <<
"WARNING: TickMarkGain in the global tag changed\n"
98 <<
" APV->SubDet: " <<
APV->SubDet <<
" APV->APVId:" <<
APV->APVId << std::endl
99 <<
" APV->PreviousGainTick: " <<
APV->PreviousGainTick <<
" newPreviousGainTick: " << newPreviousGainTick
102 APV->PreviousGainTick = newPreviousGainTick;
108 edm::LogInfo(
"SiStripGainsPCLHarvester") <<
"Starting harvesting statistics" << std::endl;
113 if (!stag.empty() && stag[0] !=
'_')
114 stag.insert(0, 1,
'_');
120 if (Charge_Vs_Index ==
nullptr) {
122 <<
"Harvesting: could not retrieve " << cvi.c_str() <<
", statistics will not be summed!" << std::endl;
125 <<
"Harvesting " << (Charge_Vs_Index)->getTH2S()->GetEntries() <<
" more clusters" << std::endl;
129 std::unique_ptr<SiStripApvGain> theAPVGains = this->
getNewObject(Charge_Vs_Index);
138 throw std::runtime_error(
"PoolDBService required.");
140 edm::LogInfo(
"SiStripGainsPCLHarvester") <<
"Will not produce payload!" << std::endl;
152 std::vector<APVGain::APVmon> new_charge_histos;
153 std::vector<std::pair<std::string, std::string>> cnames =
155 for (
unsigned int i = 0;
i < cnames.size();
i++) {
169 ibooker_.
book2DD(
"MPVvsEtaTIB",
"MPV vs Eta TIB", 50, -3.0, 3.0, MPVbin, MPVmin, MPVmax);
171 ibooker_.
book2DD(
"MPVvsEtaTID",
"MPV vs Eta TID", 50, -3.0, 3.0, MPVbin, MPVmin, MPVmax);
173 ibooker_.
book2DD(
"MPVvsEtaTOB",
"MPV vs Eta TOB", 50, -3.0, 3.0, MPVbin, MPVmin, MPVmax);
175 ibooker_.
book2DD(
"MPVvsEtaTEC",
"MPV vs Eta TEC", 50, -3.0, 3.0, MPVbin, MPVmin, MPVmax);
177 ibooker_.
book2DD(
"MPVvsEtaTEC1",
"MPV vs Eta TEC-thin", 50, -3.0, 3.0, MPVbin, MPVmin, MPVmax);
179 ibooker_.
book2DD(
"MPVvsEtaTEC2",
"MPV vs Eta TEC-thick", 50, -3.0, 3.0, MPVbin, MPVmin, MPVmax);
182 ibooker_.
book2DD(
"MPVvsPhiTIB",
"MPV vs Phi TIB", 50, -3.4, 3.4, MPVbin, MPVmin, MPVmax);
184 ibooker_.
book2DD(
"MPVvsPhiTID",
"MPV vs Phi TID", 50, -3.4, 3.4, MPVbin, MPVmin, MPVmax);
186 ibooker_.
book2DD(
"MPVvsPhiTOB",
"MPV vs Phi TOB", 50, -3.4, 3.4, MPVbin, MPVmin, MPVmax);
188 ibooker_.
book2DD(
"MPVvsPhiTEC",
"MPV vs Phi TEC", 50, -3.4, 3.4, MPVbin, MPVmin, MPVmax);
190 ibooker_.
book2DD(
"MPVvsPhiTEC1",
"MPV vs Phi TEC-thin ", 50, -3.4, 3.4, MPVbin, MPVmin, MPVmax);
192 ibooker_.
book2DD(
"MPVvsPhiTEC2",
"MPV vs Phi TEC-thick", 50, -3.4, 3.4, MPVbin, MPVmin, MPVmax);
194 MonitorElement* NoMPVfit = ibooker_.
book2DD(
"NoMPVfit",
"Modules with bad Landau Fit", 350, -350, 350, 240, 0, 120);
195 MonitorElement* NoMPVmasked = ibooker_.
book2DD(
"NoMPVmasked",
"Masked Modules", 350, -350, 350, 240, 0, 120);
210 MonitorElement* MPVsTECthick = ibooker_.
book1DD(
"MPV_TEC2",
"MPV TEC thick", MPVbin, MPVmin, MPVmax);
217 MonitorElement* MPVErrorVsMPV = ibooker_.
book2DD(
"MPVErrorVsMPV",
"MPV Error vs MPV", 300, 0, 600, 150, 0, 150);
218 MonitorElement* MPVErrorVsEta = ibooker_.
book2DD(
"MPVErrorVsEta",
"MPV Error vs Eta", 50, -3.0, 3.0, 150, 0, 150);
219 MonitorElement* MPVErrorVsPhi = ibooker_.
book2DD(
"MPVErrorVsPhi",
"MPV Error vs Phi", 50, -3.4, 3.4, 150, 0, 150);
220 MonitorElement* MPVErrorVsN = ibooker_.
book2DD(
"MPVErrorVsN",
"MPV Error vs N", 500, 0, 1000, 150, 0, 150);
222 MonitorElement* DiffWRTPrevGainTIB = ibooker_.
book1DD(
"DiffWRTPrevGainTIB",
"Diff w.r.t. PrevGain TIB", 250, 0, 2);
223 MonitorElement* DiffWRTPrevGainTID = ibooker_.
book1DD(
"DiffWRTPrevGainTID",
"Diff w.r.t. PrevGain TID", 250, 0, 2);
224 MonitorElement* DiffWRTPrevGainTOB = ibooker_.
book1DD(
"DiffWRTPrevGainTOB",
"Diff w.r.t. PrevGain TOB", 250, 0, 2);
225 MonitorElement* DiffWRTPrevGainTEC = ibooker_.
book1DD(
"DiffWRTPrevGainTEC",
"Diff w.r.t. PrevGain TEC", 250, 0, 2);
228 ibooker_.
book2DD(
"GainVsPrevGainTIB",
"Gain vs PrevGain TIB", 100, 0, 2, 100, 0, 2);
230 ibooker_.
book2DD(
"GainVsPrevGainTID",
"Gain vs PrevGain TID", 100, 0, 2, 100, 0, 2);
232 ibooker_.
book2DD(
"GainVsPrevGainTOB",
"Gain vs PrevGain TOB", 100, 0, 2, 100, 0, 2);
234 ibooker_.
book2DD(
"GainVsPrevGainTEC",
"Gain vs PrevGain TEC", 100, 0, 2, 100, 0, 2);
241 unsigned int Index =
APV->Index;
245 float Eta =
APV->Eta;
248 float Thickness =
APV->Thickness;
249 double FitMPV =
APV->FitMPV;
250 double FitMPVErr =
APV->FitMPVErr;
252 double NEntries =
APV->NEntries;
253 double PreviousGain =
APV->PreviousGain;
261 if (!Charge_Vs_Index)
263 TH2S* chvsidx = (Charge_Vs_Index)->getTH2S();
264 int bin = chvsidx->GetXaxis()->FindBin(Index);
265 TH1D* Proj = chvsidx->ProjectionY(
"proj",
bin,
bin);
266 for (
int binId = 0; binId < Proj->GetXaxis()->GetNbins(); binId++) {
267 double new_charge = Proj->GetXaxis()->GetBinCenter(binId) /
Gain;
268 if (Proj->GetBinContent(binId) != 0.) {
269 for (
unsigned int h = 0;
h < charge_histos.size();
h++) {
270 TH1D* chisto = (charge_histos[
h])->getTH1D();
271 for (
int e = 0;
e < Proj->GetBinContent(binId);
e++)
272 chisto->Fill(new_charge);
289 if (Thickness < 0.04)
290 MPVs320->
Fill(FitMPV);
291 if (Thickness > 0.04)
292 MPVs500->
Fill(FitMPV);
294 MPVError->
Fill(FitMPVErr);
295 MPVErrorVsMPV->
Fill(FitMPV, FitMPVErr);
296 MPVErrorVsEta->
Fill(Eta, FitMPVErr);
297 MPVErrorVsPhi->
Fill(
Phi, FitMPVErr);
298 MPVErrorVsN->
Fill(NEntries, FitMPVErr);
301 MPV_Vs_EtaTIB->
Fill(Eta, FitMPV);
302 MPV_Vs_PhiTIB->
Fill(
Phi, FitMPV);
303 MPVsTIB->
Fill(FitMPV);
306 MPV_Vs_EtaTID->
Fill(Eta, FitMPV);
307 MPV_Vs_PhiTID->
Fill(
Phi, FitMPV);
308 MPVsTID->
Fill(FitMPV);
310 MPVsTIDM->
Fill(FitMPV);
312 MPVsTIDP->
Fill(FitMPV);
315 MPV_Vs_EtaTOB->
Fill(Eta, FitMPV);
316 MPV_Vs_PhiTOB->
Fill(
Phi, FitMPV);
317 MPVsTOB->
Fill(FitMPV);
320 MPV_Vs_EtaTEC->
Fill(Eta, FitMPV);
321 MPV_Vs_PhiTEC->
Fill(
Phi, FitMPV);
322 MPVsTEC->
Fill(FitMPV);
324 MPVsTECM->
Fill(FitMPV);
326 MPVsTECP->
Fill(FitMPV);
327 if (Thickness < 0.04) {
328 MPV_Vs_EtaTECthin->
Fill(Eta, FitMPV);
329 MPV_Vs_PhiTECthin->
Fill(
Phi, FitMPV);
330 MPVsTECthin->
Fill(FitMPV);
332 MPVsTECP1->
Fill(FitMPV);
334 MPVsTECM1->
Fill(FitMPV);
336 if (Thickness > 0.04) {
337 MPV_Vs_EtaTECthick->
Fill(Eta, FitMPV);
338 MPV_Vs_PhiTECthick->
Fill(
Phi, FitMPV);
339 MPVsTECthick->
Fill(FitMPV);
341 MPVsTECP2->
Fill(FitMPV);
343 MPVsTECM2->
Fill(FitMPV);
348 if (
SubDet == 3 && PreviousGain != 0.)
349 DiffWRTPrevGainTIB->
Fill(
Gain / PreviousGain);
350 else if (
SubDet == 4 && PreviousGain != 0.)
351 DiffWRTPrevGainTID->
Fill(
Gain / PreviousGain);
352 else if (
SubDet == 5 && PreviousGain != 0.)
353 DiffWRTPrevGainTOB->
Fill(
Gain / PreviousGain);
354 else if (
SubDet == 6 && PreviousGain != 0.)
355 DiffWRTPrevGainTEC->
Fill(
Gain / PreviousGain);
358 GainVsPrevGainTIB->
Fill(PreviousGain,
Gain);
360 GainVsPrevGainTID->
Fill(PreviousGain,
Gain);
362 GainVsPrevGainTOB->
Fill(PreviousGain,
Gain);
364 GainVsPrevGainTEC->
Fill(PreviousGain,
Gain);
371 TH1F* Proj =
nullptr;
372 double FitResults[6];
373 double MPVmean = 300;
375 if (Charge_Vs_Index ==
nullptr) {
377 <<
"Harvesting: could not execute algoComputeMPVandGain method because " <<
m_calibrationMode
378 <<
" statistics cannot be retrieved.\n"
379 <<
"Please check if input contains " <<
m_calibrationMode <<
" data." << std::endl;
383 TH2S* chvsidx = (Charge_Vs_Index)->getTH2S();
385 printf(
"Progressing Bar :0%% 20%% 40%% 60%% 80%% 100%%\n");
386 printf(
"Fitting Charge Distribution :");
387 int TreeStep =
APVsColl.size() / 50;
390 if (
I % TreeStep == 0) {
394 std::shared_ptr<stAPVGain>
APV = it->second;
396 APV->Bin = chvsidx->GetXaxis()->FindBin(
APV->Index);
399 APV->Gain =
APV->PreviousGain;
404 Proj = (TH1F*)(chvsidx->ProjectionY(
405 "", chvsidx->GetXaxis()->FindBin(
APV->Index), chvsidx->GetXaxis()->FindBin(
APV->Index),
"e"));
411 int SecondAPVId =
APV->APVId;
412 if (SecondAPVId % 2 == 0) {
413 SecondAPVId = SecondAPVId + 1;
415 SecondAPVId = SecondAPVId - 1;
417 std::shared_ptr<stAPVGain> APV2 =
APVsColl[(
APV->DetId << 4) | SecondAPVId];
419 APV2->Bin = chvsidx->GetXaxis()->FindBin(APV2->Index);
420 TH1F* Proj2 = (TH1F*)(chvsidx->ProjectionY(
"", APV2->Bin, APV2->Bin,
"e"));
426 for (
unsigned int i = 0;
i < 16;
i++) {
430 std::shared_ptr<stAPVGain> APV2 = tmpit->second;
431 if (APV2->DetId !=
APV->DetId || APV2->APVId ==
APV->APVId)
434 APV2->Bin = chvsidx->GetXaxis()->FindBin(APV2->Index);
435 TH1F* Proj2 = (TH1F*)(chvsidx->ProjectionY(
"", APV2->Bin, APV2->Bin,
"e"));
447 APV->FitMPV = FitResults[0];
448 APV->FitMPVErr = FitResults[1];
449 APV->FitWidth = FitResults[2];
450 APV->FitWidthErr = FitResults[3];
451 APV->FitChi2 = FitResults[4];
452 APV->FitNorm = FitResults[5];
453 APV->NEntries = Proj->GetEntries();
456 APV->Gain =
APV->FitMPV / MPVmean;
460 APV->Gain =
APV->PreviousGain;
474 FitResults[0] = -0.5;
476 FitResults[2] = -0.5;
478 FitResults[4] = -0.5;
485 TF1 MyLandau(
"MyLandau",
"landau", LowRange, HighRange);
486 MyLandau.SetParameter(1, 300);
487 InputHisto->Fit(&MyLandau,
"0QR WW");
490 FitResults[0] = MyLandau.GetParameter(1);
491 FitResults[1] = MyLandau.GetParError(1);
492 FitResults[2] = MyLandau.GetParameter(2);
493 FitResults[3] = MyLandau.GetParError(2);
494 FitResults[4] = MyLandau.GetChisquare() / MyLandau.GetNDF();
495 FitResults[5] = MyLandau.GetParameter(0);
500 if (FitResults[0] <= 0)
515 auto const&
Det = newBareTkGeomPtr->dets();
517 unsigned int Index = 0;
519 for (
unsigned int i = 0;
i <
Det.size();
i++) {
525 auto DetUnit = dynamic_cast<const StripGeomDetUnit*>(
Det[
i]);
530 unsigned int NAPV = Topo.
nstrips() / 128;
532 for (
unsigned int j = 0;
j < NAPV;
j++) {
533 auto APV = std::make_shared<stAPVGain>();
542 APV->FitWidthErr = -1;
546 APV->PreviousGain = 1;
547 APV->PreviousGainTick = 1;
548 APV->x = DetUnit->position().basicVector().x();
549 APV->y = DetUnit->position().basicVector().y();
550 APV->z = DetUnit->position().basicVector().z();
551 APV->Eta = DetUnit->position().basicVector().eta();
552 APV->Phi = DetUnit->position().basicVector().phi();
553 APV->R = DetUnit->position().basicVector().transverse();
554 APV->Thickness = DetUnit->surface().bounds().thickness();
556 APV->isMasked =
false;
566 for (
unsigned int i = 0;
i <
Det.size();
571 auto DetUnit = dynamic_cast<const PixelGeomDetUnit*>(
Det[
i]);
576 unsigned int NROCRow = Topo.
nrows() / (80.);
577 unsigned int NROCCol = Topo.
ncolumns() / (52.);
579 for (
unsigned int j = 0;
j < NROCRow;
j++) {
580 for (
unsigned int i = 0;
i < NROCCol;
i++) {
581 auto APV = std::make_shared<stAPVGain>();
585 APV->APVId = (
j << 3 |
i);
590 APV->FitWidthErr = -1;
593 APV->PreviousGain = 1;
594 APV->PreviousGainTick = 1;
595 APV->x = DetUnit->position().basicVector().x();
596 APV->y = DetUnit->position().basicVector().y();
597 APV->z = DetUnit->position().basicVector().z();
598 APV->Eta = DetUnit->position().basicVector().eta();
599 APV->Phi = DetUnit->position().basicVector().phi();
600 APV->R = DetUnit->position().basicVector().transverse();
601 APV->Thickness = DetUnit->surface().bounds().thickness();
602 APV->isMasked =
false;
623 if (Charge_Vs_Index ==
nullptr) {
625 <<
"produceTagFilter -> Return false: could not retrieve the " <<
m_calibrationMode <<
" statistics.\n"
626 <<
"Please check if input contains " <<
m_calibrationMode <<
" data." << std::endl;
630 float integral = (Charge_Vs_Index)->getTH2S()->Integral();
634 <<
"produceTagFilter -> Return false: Statistics is too low : " <<
integral << std::endl;
640 <<
"produceTagFilter -> Return false: ratio of GOOD/TOTAL is too low: " << (1.0 *
GOOD) / (
GOOD +
BAD)
649 std::unique_ptr<SiStripApvGain>
obj = std::make_unique<SiStripApvGain>();
653 <<
"getNewObject -> will not produce a paylaod because produceTagFilter returned false " << std::endl;
659 std::vector<float> theSiStripVector;
660 unsigned int PreviousDetId = 0;
663 if (
APV ==
nullptr) {
667 if (
APV->SubDet <= 2)
669 if (
APV->DetId != PreviousDetId) {
670 if (!theSiStripVector.empty()) {
672 if (!
obj->put(PreviousDetId,
range))
673 printf(
"Bug to put detId = %i\n", PreviousDetId);
675 theSiStripVector.clear();
676 PreviousDetId =
APV->DetId;
678 theSiStripVector.push_back(
APV->Gain);
680 LogDebug(
"SiStripGainsPCLHarvester") <<
" DetId: " <<
APV->DetId <<
" APV: " <<
APV->APVId
681 <<
" Gain: " <<
APV->Gain << std::endl;
683 if (!theSiStripVector.empty()) {
685 if (!
obj->put(PreviousDetId,
range))
686 printf(
"Bug to put detId = %i\n", PreviousDetId);