57 #include "TObjString.h"
65 #include <unordered_map>
96 void algoEndJob()
override;
101 std::unique_ptr<SiStripApvGain> getNewObject()
override;
108 double trajChi2OverN);
111 void getPeakOfLandau(TH1* InputHisto,
double* FitResults,
double LowRange = 0,
double HighRange = 5400);
289 return PseudoDetId1 == PseudoDetId2;
294 std::unordered_map<unsigned int, stAPVGain*>
APVsColl;
329 if (strcmp(
AlgoMode.c_str(),
"WriteOnDB") == 0)
334 tTopoToken_ = esConsumes<edm::Transition::BeginRun>();
336 gainToken_ = esConsumes<edm::Transition::BeginRun>();
368 tmp =
dqmStore_->
book2D(
"APV_PathLength",
"APV_PathLength", 72785, 0, 72784, 100, 0.2, 1.4);
385 tmp =
dqmStore_->
book2D(
"Tracks_Pt_Vs_Eta",
"Tracks_Pt_Vs_Eta", 30, 0, 3, 50, 0, 200);
388 tmp =
dqmStore_->
book2D(
"Charge_Vs_PathTIB",
"Charge_Vs_PathTIB", 100, 0.2, 1.4, 500, 0, 2000);
390 tmp =
dqmStore_->
book2D(
"Charge_Vs_PathTID",
"Charge_Vs_PathTID", 100, 0.2, 1.4, 500, 0, 2000);
392 tmp =
dqmStore_->
book2D(
"Charge_Vs_PathTOB",
"Charge_Vs_PathTOB", 100, 0.2, 1.4, 500, 0, 2000);
394 tmp =
dqmStore_->
book2D(
"Charge_Vs_PathTEC",
"Charge_Vs_PathTEC", 100, 0.2, 1.4, 500, 0, 2000);
396 tmp =
dqmStore_->
book2D(
"Charge_Vs_PathTEC1",
"Charge_Vs_PathTEC1", 100, 0.2, 1.4, 500, 0, 2000);
398 tmp =
dqmStore_->
book2D(
"Charge_Vs_PathTEC2",
"Charge_Vs_PathTEC2", 100, 0.2, 1.4, 500, 0, 2000);
429 tmp =
dqmStore_->
book2D(
"Charge_Vs_PathLength",
"Charge_Vs_PathLength", 100, 0.2, 1.4, 500, 0, 2000);
431 tmp =
dqmStore_->
book2D(
"Charge_Vs_PathLength320",
"Charge_Vs_PathLength", 100, 0.2, 1.4, 500, 0, 2000);
433 tmp =
dqmStore_->
book2D(
"Charge_Vs_PathLength500",
"Charge_Vs_PathLength", 100, 0.2, 1.4, 500, 0, 2000);
436 tmp =
dqmStore_->
book2D(
"Charge_Vs_TransversAngle",
"Charge_Vs_TransversAngle", 220, -20, 200, 500, 0, 2000);
438 tmp =
dqmStore_->
book2D(
"Charge_Vs_Alpha",
"Charge_Vs_Alpha", 220, -20, 200, 500, 0, 2000);
440 tmp =
dqmStore_->
book2D(
"Charge_Vs_Beta",
"Charge_Vs_Beta", 220, -20, 200, 500, 0, 2000);
443 tmp =
dqmStore_->
book2D(
"NStrips_Vs_TransversAngle",
"NStrips_Vs_TransversAngle", 220, -20, 200, 10, 0, 10);
445 tmp =
dqmStore_->
book2D(
"NStrips_Vs_Alpha",
"NStrips_Vs_Alpha", 220, -20, 200, 10, 0, 10);
447 tmp =
dqmStore_->
book2D(
"NStrips_Vs_Beta",
"NStrips_Vs_Beta", 220, -20, 200, 10, 0, 10);
462 if (strcmp(
AlgoMode.c_str(),
"MultiJob") != 0) {
463 tmp =
dqmStore_->
book2D(
"MPV_Vs_EtaTIB",
"MPV_Vs_EtaTIB", 50, -3.0, 3.0, 300, 0, 600);
465 tmp =
dqmStore_->
book2D(
"MPV_Vs_EtaTID",
"MPV_Vs_EtaTID", 50, -3.0, 3.0, 300, 0, 600);
467 tmp =
dqmStore_->
book2D(
"MPV_Vs_EtaTOB",
"MPV_Vs_EtaTOB", 50, -3.0, 3.0, 300, 0, 600);
469 tmp =
dqmStore_->
book2D(
"MPV_Vs_EtaTEC",
"MPV_Vs_EtaTEC", 50, -3.0, 3.0, 300, 0, 600);
471 tmp =
dqmStore_->
book2D(
"MPV_Vs_EtaTEC1",
"MPV_Vs_EtaTEC1", 50, -3.0, 3.0, 300, 0, 600);
473 tmp =
dqmStore_->
book2D(
"MPV_Vs_EtaTEC2",
"MPV_Vs_EtaTEC2", 50, -3.0, 3.0, 300, 0, 600);
476 tmp =
dqmStore_->
book2D(
"MPV_Vs_PhiTIB",
"MPV_Vs_PhiTIB", 50, -3.2, 3.2, 300, 0, 600);
478 tmp =
dqmStore_->
book2D(
"MPV_Vs_PhiTID",
"MPV_Vs_PhiTID", 50, -3.2, 3.2, 300, 0, 600);
480 tmp =
dqmStore_->
book2D(
"MPV_Vs_PhiTOB",
"MPV_Vs_PhiTOB", 50, -3.2, 3.2, 300, 0, 600);
482 tmp =
dqmStore_->
book2D(
"MPV_Vs_PhiTEC",
"MPV_Vs_PhiTEC", 50, -3.2, 3.2, 300, 0, 600);
484 tmp =
dqmStore_->
book2D(
"MPV_Vs_PhiTEC1",
"MPV_Vs_PhiTEC1", 50, -3.2, 3.2, 300, 0, 600);
486 tmp =
dqmStore_->
book2D(
"MPV_Vs_PhiTEC2",
"MPV_Vs_PhiTEC2", 50, -3.2, 3.2, 300, 0, 600);
530 tmp =
dqmStore_->
book1D(
"FWHM_Vs_PathLength320",
"FWHM_Vs_PathLength", 100, 0.2, 1.4);
532 tmp =
dqmStore_->
book1D(
"FWHM_Vs_PathLength500",
"FWHM_Vs_PathLength", 100, 0.2, 1.4);
535 tmp =
dqmStore_->
book1D(
"MPV_Vs_TransversAngle",
"MPV_Vs_TransversAngle", 220, -20, 200);
544 tmp =
dqmStore_->
book2D(
"Error_Vs_Entries",
"Error_Vs_Entries", 500, 0, 10000, 100, 0, 50);
551 tmp =
dqmStore_->
book2D(
"NoMPV_Vs_EtaPhi",
"NoMPV_Vs_EtaPhi", 50, -3.0, 3.0, 50, -3.2, 3.2);
554 tmp =
dqmStore_->
book1D(
"NumberOfEntriesByAPV",
"NumberOfEntriesByAPV", 1000, 0, 10000);
575 printf(
"\n#####################\n\nERROR --> gainHandle is not valid\n\n#####################\n\n");
581 for (
unsigned int i = 0;
i <
Det.size();
i++) {
587 auto DetUnit = dynamic_cast<StripGeomDetUnit const*>(
Det[
i]);
592 unsigned int NAPV = Topo.
nstrips() / 128;
594 double Phi = DetUnit->position().basicVector().phi();
595 double Eta = DetUnit->position().basicVector().eta();
596 double R = DetUnit->position().basicVector().transverse();
597 double Thick = DetUnit->surface().bounds().thickness();
599 for (
unsigned int j = 0;
j < NAPV;
j++) {
607 APV->PreviousGain = 1;
611 APV->Thickness = Thick;
646 if (strcmp(
AlgoMode.c_str(),
"WriteOnDB") == 0 || strcmp(
AlgoMode.c_str(),
"Merge") == 0) {
647 TH1::AddDirectory(kTRUE);
649 TFile*
file =
nullptr;
651 printf(
"Loading New Input File : %s\n",
VInputFiles[
f].c_str());
653 FILE* doesFileExist = fopen(
VInputFiles[
f].c_str(),
"r");
654 if (!doesFileExist) {
655 printf(
"File %s doesn't exist\n",
VInputFiles[
f].c_str());
658 fclose(doesFileExist);
663 printf(
"### Bug With File %s\n### File will be skipped \n",
VInputFiles[
f].c_str());
694 TH1F* JobInfo_tmp = (TH1F*)
file->FindObjectAny(
"JobInfo");
695 NEvent += (
unsigned int)JobInfo_tmp->GetBinContent(JobInfo_tmp->GetXaxis()->FindBin(1));
696 unsigned int tmp_SRun = (
unsigned int)JobInfo_tmp->GetBinContent(JobInfo_tmp->GetXaxis()->FindBin(3));
697 unsigned int tmp_SEvent = (
unsigned int)JobInfo_tmp->GetBinContent(JobInfo_tmp->GetXaxis()->FindBin(4));
698 unsigned int tmp_ERun = (
unsigned int)JobInfo_tmp->GetBinContent(JobInfo_tmp->GetXaxis()->FindBin(6));
699 unsigned int tmp_EEvent = (
unsigned int)JobInfo_tmp->GetBinContent(JobInfo_tmp->GetXaxis()->FindBin(7));
704 if (tmp_SRun <
SRun) {
707 }
else if (tmp_SRun ==
SRun && tmp_SEvent <
SEvent) {
711 if (tmp_ERun >
ERun) {
714 }
else if (tmp_ERun ==
ERun && tmp_EEvent >
EEvent) {
718 printf(
"Deleting Current Input File\n");
730 if (strcmp(
AlgoMode.c_str(),
"MultiJob") != 0) {
731 TH1D* Proj =
nullptr;
732 double FitResults[5];
736 printf(
"Fitting Histograms \t %6.2f%%\n", (100.0 *
I) /
APVsColl.size());
742 Proj = (TH1D*)Proj->Clone();
748 int SecondAPVId =
APV->APVId;
749 if (SecondAPVId % 2 == 0) {
750 SecondAPVId = SecondAPVId + 1;
752 SecondAPVId = SecondAPVId - 1;
757 TH1D* Proj2 =
APV_Charge->ProjectionY(
" ", bin2, bin2,
"e");
758 if (Proj2 !=
nullptr) {
772 TH1D* Proj2 =
APV_Charge->ProjectionY(
" ", bin2, bin2,
"e");
773 if (Proj2 !=
nullptr) {
784 APV->MPV = FitResults[0];
786 if (FitResults[0] != -0.5 && FitResults[1] <
MaxMPVError) {
789 if (
APV->Thickness < 0.04)
791 if (
APV->Thickness > 0.04)
804 if (
APV->Thickness < 0.04)
806 if (
APV->Thickness > 0.04)
818 if (
APV->Thickness < 0.04)
820 if (
APV->Thickness > 0.04)
837 if (
APV->Thickness < 0.04)
839 if (
APV->Thickness > 0.04)
861 if (
APV->Thickness < 0.04)
863 if (
APV->Thickness > 0.04)
871 if (FitResults[0] != -0.5) {
890 unsigned int GOOD = 0;
891 unsigned int BAD = 0;
892 double MPVmean =
MPVs->GetMean();
897 APV->Gain =
APV->MPV / MPVmean;
909 APV->Gain *=
APV->PreviousGain;
916 if (FitResults[0] == -0.5)
930 if (FitResults[0] == -0.5)
944 if (FitResults[0] == -0.5)
1009 if (FitResults[0] == -0.5)
1019 if (FitResults[0] == -0.5)
1029 if (FitResults[0] == -0.5)
1039 if (FitResults[0] == -0.5)
1049 if (FitResults[0] == -0.5)
1059 if (FitResults[0] == -0.5)
1069 if (FitResults[0] == -0.5)
1079 if (FitResults[0] == -0.5)
1089 if (FitResults[0] == -0.5)
1097 fprintf(Gains,
"NEvents = %i\n",
NEvent);
1098 fprintf(Gains,
"Number of APVs = %lu\n", static_cast<unsigned long>(
APVsColl.size()));
1099 fprintf(Gains,
"GoodFits = %i BadFits = %i ratio = %f\n",
GOOD,
BAD, (100.0 *
GOOD) / (
GOOD +
BAD));
1103 "%i | %i | PreviousGain = %7.5f NewGain = %7.5f\n",
1110 std::vector<int> DetIdOfBuggedAPV;
1111 fprintf(Gains,
"----------------------------------------------------------------------\n");
1114 if (
APV->MPV > 0 &&
APV->MPV < 200) {
1115 bool tmpBug =
false;
1116 for (
unsigned int b = 0;
b < DetIdOfBuggedAPV.size() && !tmpBug;
b++) {
1117 if (DetIdOfBuggedAPV[
b] ==
APV->DetId)
1121 fprintf(Gains,
"%i,\n",
APV->DetId);
1122 DetIdOfBuggedAPV.push_back(
APV->DetId);
1140 if (!gainHandle.isValid()) {
1141 printf(
"\n#####################\n\nERROR --> gainHandle is not valid\n\n#####################\n\n");
1148 if (gainHandle.isValid()) {
1150 APV->PreviousGain = *(detGainRange.first +
APV->APVId);
1153 if (
APV->PreviousGain < 0)
1154 APV->PreviousGain = 1;
1156 printf(
"GAIN HANDLE IS NOT VALID\n");
1163 if (strcmp(
AlgoMode.c_str(),
"WriteOnDB") == 0)
1197 for (Trajectory::RecHitContainer::const_iterator rechit = transRecHits.begin(); rechit != transRecHits.end();
1199 if ((*rechit)->isValid())
1200 ndof += (*rechit)->dimension();
1208 vector<TrajectoryMeasurement> measurements = traj.
measurements();
1232 for (vector<TrajectoryMeasurement>::const_iterator measurement_it = measurements.begin();
1233 measurement_it != measurements.end();
1240 const SiStripRecHit1D* sistripsimple1dhit = dynamic_cast<const SiStripRecHit1D*>(
hit);
1244 if (sistripsimplehit) {
1247 }
else if (sistripmatchedhit) {
1251 }
else if (sistripsimple1dhit) {
1264 double trajChi2OverN) {
1266 double cosine = trackDirection.
z() / trackDirection.
mag();
1270 int APVId = FirstStrip / 128;
1273 bool Overlaping =
false;
1275 unsigned int NHighStrip = 0;
1280 if (FirstStrip == 0)
1282 if (FirstStrip == 128)
1284 if (FirstStrip == 256)
1286 if (FirstStrip == 384)
1288 if (FirstStrip == 512)
1290 if (FirstStrip == 640)
1293 if (FirstStrip <= 127 && FirstStrip + Ampls.size() > 127)
1295 if (FirstStrip <= 255 && FirstStrip + Ampls.size() > 255)
1297 if (FirstStrip <= 383 && FirstStrip + Ampls.size() > 383)
1299 if (FirstStrip <= 511 && FirstStrip + Ampls.size() > 511)
1301 if (FirstStrip <= 639 && FirstStrip + Ampls.size() > 639)
1304 if (FirstStrip + Ampls.size() == 127)
1306 if (FirstStrip + Ampls.size() == 255)
1308 if (FirstStrip + Ampls.size() == 383)
1310 if (FirstStrip + Ampls.size() == 511)
1312 if (FirstStrip + Ampls.size() == 639)
1314 if (FirstStrip + Ampls.size() == 767)
1328 for (
unsigned int a = 0;
a < Ampls.size();
a++) {
1330 if (Ampls[
a] >= 254)
1335 double path = (10.0 *
APV->Thickness) / fabs(cosine);
1336 double ClusterChargeOverPath = (double)
Charge /
path;
1345 if (
APV->Thickness < 0.04)
1347 if (
APV->Thickness > 0.04)
1357 if (
APV->Thickness < 0.04)
1359 if (
APV->Thickness > 0.04)
1363 double trans = atan2(trackDirection.
y(), trackDirection.
x()) * (180 / 3.14159265);
1365 acos(trackDirection.
x() /
sqrt(
pow(trackDirection.
x(), 2) +
pow(trackDirection.
z(), 2))) * (180 / 3.14159265);
1367 acos(trackDirection.
y() /
sqrt(
pow(trackDirection.
x(), 2) +
pow(trackDirection.
z(), 2))) * (180 / 3.14159265);
1389 ClusterChargeOverPath = ClusterChargeOverPath /
APV->PreviousGain;
1396 return ClusterChargeOverPath;
1400 const uint32_t detid,
1408 if (dynamic_cast<const StripGeomDetUnit*>(it) ==
nullptr && dynamic_cast<const PixelGeomDetUnit*>(it) ==
nullptr) {
1409 std::cout <<
"this detID doesn't seem to belong to the Tracker" << std::endl;
1414 const TrapezoidalPlaneBounds* trapezoidalBounds(dynamic_cast<const TrapezoidalPlaneBounds*>(&(plane.bounds())));
1415 const RectangularPlaneBounds* rectangularBounds(dynamic_cast<const RectangularPlaneBounds*>(&(plane.bounds())));
1417 double DistFromBorder = 1.0;
1421 if (trapezoidalBounds) {
1422 std::array<const float, 4>
const&
parameters = (*trapezoidalBounds).parameters();
1426 }
else if (rectangularBounds) {
1434 if (fabs(HitLocalPos.
y()) + HitLocalError.
yy() >= (
HalfLength - DistFromBorder))
1442 double adcs_err = 0.;
1443 double width = -0.5;
1444 double width_err = 0;
1445 double chi2overndf = -0.5;
1447 double nr_of_entries = InputHisto->GetEntries();
1450 FitResults[0] = adcs;
1451 FitResults[1] = adcs_err;
1452 FitResults[2] =
width;
1453 FitResults[3] = width_err;
1454 FitResults[4] = chi2overndf;
1459 TF1* MyLandau =
new TF1(
"MyLandau",
"landau", LowRange, HighRange);
1460 MyLandau->SetParameter(
"MPV", 300);
1462 InputHisto->Fit(MyLandau,
"QR WW");
1465 adcs = MyLandau->GetParameter(
"MPV");
1466 adcs_err = MyLandau->GetParError(1);
1467 width = MyLandau->GetParameter(2);
1468 width_err = MyLandau->GetParError(2);
1469 chi2overndf = MyLandau->GetChisquare() / MyLandau->GetNDF();
1480 FitResults[0] = adcs;
1481 FitResults[1] = adcs_err;
1482 FitResults[2] =
width;
1483 FitResults[3] = width_err;
1484 FitResults[4] = chi2overndf;
1490 cout <<
"START getNewObject\n";
1493 if (!(strcmp(
AlgoMode.c_str(),
"WriteOnDB") == 0 || strcmp(
AlgoMode.c_str(),
"SingleJob") == 0))
1494 return std::make_unique<SiStripApvGain>();
1496 auto obj = std::make_unique<SiStripApvGain>();
1497 std::vector<float>* theSiStripVector =
nullptr;
1498 int PreviousDetId = -1;
1501 if (
APV ==
nullptr) {
1505 if (
APV->DetId != PreviousDetId) {
1506 if (theSiStripVector !=
nullptr) {
1508 if (!
obj->put(PreviousDetId,
range))
1509 printf(
"Bug to put detId = %i\n", PreviousDetId);
1512 theSiStripVector =
new std::vector<float>;
1513 PreviousDetId =
APV->DetId;
1515 printf(
"%i | %i | PreviousGain = %7.5f NewGain = %7.5f\n",
APV->DetId,
APV->APVId,
APV->PreviousGain,
APV->Gain);
1516 theSiStripVector->push_back(
APV->Gain);
1520 if (theSiStripVector !=
nullptr) {
1522 if (!
obj->put(PreviousDetId,
range))
1523 printf(
"Bug to put detId = %i\n", PreviousDetId);
1526 cout <<
"END getNewObject\n";