56 #include "TObjString.h" 64 #include <unordered_map> 95 void algoEndJob()
override;
100 std::unique_ptr<SiStripApvGain> getNewObject()
override;
107 double trajChi2OverN);
110 void getPeakOfLandau(TH1* InputHisto,
double* FitResults,
double LowRange = 0,
double HighRange = 5400);
288 return PseudoDetId1 == PseudoDetId2;
293 std::unordered_map<unsigned int, stAPVGain*>
APVsColl;
328 if (strcmp(
AlgoMode.c_str(),
"WriteOnDB") == 0)
333 tTopoToken_ = esConsumes<edm::Transition::BeginRun>();
335 gainToken_ = esConsumes<edm::Transition::BeginRun>();
367 tmp =
dqmStore_->
book2D(
"APV_PathLength",
"APV_PathLength", 72785, 0, 72784, 100, 0.2, 1.4);
384 tmp =
dqmStore_->
book2D(
"Tracks_Pt_Vs_Eta",
"Tracks_Pt_Vs_Eta", 30, 0, 3, 50, 0, 200);
387 tmp =
dqmStore_->
book2D(
"Charge_Vs_PathTIB",
"Charge_Vs_PathTIB", 100, 0.2, 1.4, 500, 0, 2000);
389 tmp =
dqmStore_->
book2D(
"Charge_Vs_PathTID",
"Charge_Vs_PathTID", 100, 0.2, 1.4, 500, 0, 2000);
391 tmp =
dqmStore_->
book2D(
"Charge_Vs_PathTOB",
"Charge_Vs_PathTOB", 100, 0.2, 1.4, 500, 0, 2000);
393 tmp =
dqmStore_->
book2D(
"Charge_Vs_PathTEC",
"Charge_Vs_PathTEC", 100, 0.2, 1.4, 500, 0, 2000);
395 tmp =
dqmStore_->
book2D(
"Charge_Vs_PathTEC1",
"Charge_Vs_PathTEC1", 100, 0.2, 1.4, 500, 0, 2000);
397 tmp =
dqmStore_->
book2D(
"Charge_Vs_PathTEC2",
"Charge_Vs_PathTEC2", 100, 0.2, 1.4, 500, 0, 2000);
428 tmp =
dqmStore_->
book2D(
"Charge_Vs_PathLength",
"Charge_Vs_PathLength", 100, 0.2, 1.4, 500, 0, 2000);
430 tmp =
dqmStore_->
book2D(
"Charge_Vs_PathLength320",
"Charge_Vs_PathLength", 100, 0.2, 1.4, 500, 0, 2000);
432 tmp =
dqmStore_->
book2D(
"Charge_Vs_PathLength500",
"Charge_Vs_PathLength", 100, 0.2, 1.4, 500, 0, 2000);
435 tmp =
dqmStore_->
book2D(
"Charge_Vs_TransversAngle",
"Charge_Vs_TransversAngle", 220, -20, 200, 500, 0, 2000);
437 tmp =
dqmStore_->
book2D(
"Charge_Vs_Alpha",
"Charge_Vs_Alpha", 220, -20, 200, 500, 0, 2000);
439 tmp =
dqmStore_->
book2D(
"Charge_Vs_Beta",
"Charge_Vs_Beta", 220, -20, 200, 500, 0, 2000);
442 tmp =
dqmStore_->
book2D(
"NStrips_Vs_TransversAngle",
"NStrips_Vs_TransversAngle", 220, -20, 200, 10, 0, 10);
444 tmp =
dqmStore_->
book2D(
"NStrips_Vs_Alpha",
"NStrips_Vs_Alpha", 220, -20, 200, 10, 0, 10);
446 tmp =
dqmStore_->
book2D(
"NStrips_Vs_Beta",
"NStrips_Vs_Beta", 220, -20, 200, 10, 0, 10);
461 if (strcmp(
AlgoMode.c_str(),
"MultiJob") != 0) {
462 tmp =
dqmStore_->
book2D(
"MPV_Vs_EtaTIB",
"MPV_Vs_EtaTIB", 50, -3.0, 3.0, 300, 0, 600);
464 tmp =
dqmStore_->
book2D(
"MPV_Vs_EtaTID",
"MPV_Vs_EtaTID", 50, -3.0, 3.0, 300, 0, 600);
466 tmp =
dqmStore_->
book2D(
"MPV_Vs_EtaTOB",
"MPV_Vs_EtaTOB", 50, -3.0, 3.0, 300, 0, 600);
468 tmp =
dqmStore_->
book2D(
"MPV_Vs_EtaTEC",
"MPV_Vs_EtaTEC", 50, -3.0, 3.0, 300, 0, 600);
470 tmp =
dqmStore_->
book2D(
"MPV_Vs_EtaTEC1",
"MPV_Vs_EtaTEC1", 50, -3.0, 3.0, 300, 0, 600);
472 tmp =
dqmStore_->
book2D(
"MPV_Vs_EtaTEC2",
"MPV_Vs_EtaTEC2", 50, -3.0, 3.0, 300, 0, 600);
475 tmp =
dqmStore_->
book2D(
"MPV_Vs_PhiTIB",
"MPV_Vs_PhiTIB", 50, -3.2, 3.2, 300, 0, 600);
477 tmp =
dqmStore_->
book2D(
"MPV_Vs_PhiTID",
"MPV_Vs_PhiTID", 50, -3.2, 3.2, 300, 0, 600);
479 tmp =
dqmStore_->
book2D(
"MPV_Vs_PhiTOB",
"MPV_Vs_PhiTOB", 50, -3.2, 3.2, 300, 0, 600);
481 tmp =
dqmStore_->
book2D(
"MPV_Vs_PhiTEC",
"MPV_Vs_PhiTEC", 50, -3.2, 3.2, 300, 0, 600);
483 tmp =
dqmStore_->
book2D(
"MPV_Vs_PhiTEC1",
"MPV_Vs_PhiTEC1", 50, -3.2, 3.2, 300, 0, 600);
485 tmp =
dqmStore_->
book2D(
"MPV_Vs_PhiTEC2",
"MPV_Vs_PhiTEC2", 50, -3.2, 3.2, 300, 0, 600);
529 tmp =
dqmStore_->
book1D(
"FWHM_Vs_PathLength320",
"FWHM_Vs_PathLength", 100, 0.2, 1.4);
531 tmp =
dqmStore_->
book1D(
"FWHM_Vs_PathLength500",
"FWHM_Vs_PathLength", 100, 0.2, 1.4);
534 tmp =
dqmStore_->
book1D(
"MPV_Vs_TransversAngle",
"MPV_Vs_TransversAngle", 220, -20, 200);
543 tmp =
dqmStore_->
book2D(
"Error_Vs_Entries",
"Error_Vs_Entries", 500, 0, 10000, 100, 0, 50);
550 tmp =
dqmStore_->
book2D(
"NoMPV_Vs_EtaPhi",
"NoMPV_Vs_EtaPhi", 50, -3.0, 3.0, 50, -3.2, 3.2);
553 tmp =
dqmStore_->
book1D(
"NumberOfEntriesByAPV",
"NumberOfEntriesByAPV", 1000, 0, 10000);
574 printf(
"\n#####################\n\nERROR --> gainHandle is not valid\n\n#####################\n\n");
580 for (
unsigned int i = 0;
i <
Det.size();
i++) {
591 unsigned int NAPV = Topo.
nstrips() / 128;
593 double Phi = DetUnit->position().basicVector().phi();
594 double Eta = DetUnit->position().basicVector().eta();
595 double R = DetUnit->position().basicVector().transverse();
596 double Thick = DetUnit->surface().bounds().thickness();
598 for (
unsigned int j = 0;
j < NAPV;
j++) {
606 APV->PreviousGain = 1;
610 APV->Thickness = Thick;
645 if (strcmp(
AlgoMode.c_str(),
"WriteOnDB") == 0 || strcmp(
AlgoMode.c_str(),
"Merge") == 0) {
646 TH1::AddDirectory(kTRUE);
648 TFile*
file =
nullptr;
650 printf(
"Loading New Input File : %s\n",
VInputFiles[
f].c_str());
652 FILE* doesFileExist = fopen(
VInputFiles[
f].c_str(),
"r");
653 if (!doesFileExist) {
654 printf(
"File %s doesn't exist\n",
VInputFiles[
f].c_str());
657 fclose(doesFileExist);
662 printf(
"### Bug With File %s\n### File will be skipped \n",
VInputFiles[
f].c_str());
693 TH1F* JobInfo_tmp = (TH1F*)
file->FindObjectAny(
"JobInfo");
694 NEvent += (
unsigned int)JobInfo_tmp->GetBinContent(JobInfo_tmp->GetXaxis()->FindBin(1));
695 unsigned int tmp_SRun = (
unsigned int)JobInfo_tmp->GetBinContent(JobInfo_tmp->GetXaxis()->FindBin(3));
696 unsigned int tmp_SEvent = (
unsigned int)JobInfo_tmp->GetBinContent(JobInfo_tmp->GetXaxis()->FindBin(4));
697 unsigned int tmp_ERun = (
unsigned int)JobInfo_tmp->GetBinContent(JobInfo_tmp->GetXaxis()->FindBin(6));
698 unsigned int tmp_EEvent = (
unsigned int)JobInfo_tmp->GetBinContent(JobInfo_tmp->GetXaxis()->FindBin(7));
703 if (tmp_SRun <
SRun) {
706 }
else if (tmp_SRun ==
SRun && tmp_SEvent <
SEvent) {
710 if (tmp_ERun >
ERun) {
713 }
else if (tmp_ERun ==
ERun && tmp_EEvent >
EEvent) {
717 printf(
"Deleting Current Input File\n");
729 if (strcmp(
AlgoMode.c_str(),
"MultiJob") != 0) {
730 TH1D* Proj =
nullptr;
731 double FitResults[5];
735 printf(
"Fitting Histograms \t %6.2f%%\n", (100.0 *
I) /
APVsColl.size());
741 Proj = (TH1D*)Proj->Clone();
747 int SecondAPVId =
APV->APVId;
748 if (SecondAPVId % 2 == 0) {
749 SecondAPVId = SecondAPVId + 1;
751 SecondAPVId = SecondAPVId - 1;
756 TH1D* Proj2 =
APV_Charge->ProjectionY(
" ", bin2, bin2,
"e");
757 if (Proj2 !=
nullptr) {
771 TH1D* Proj2 =
APV_Charge->ProjectionY(
" ", bin2, bin2,
"e");
772 if (Proj2 !=
nullptr) {
783 APV->MPV = FitResults[0];
785 if (FitResults[0] != -0.5 && FitResults[1] <
MaxMPVError) {
788 if (
APV->Thickness < 0.04)
790 if (
APV->Thickness > 0.04)
803 if (
APV->Thickness < 0.04)
805 if (
APV->Thickness > 0.04)
817 if (
APV->Thickness < 0.04)
819 if (
APV->Thickness > 0.04)
836 if (
APV->Thickness < 0.04)
838 if (
APV->Thickness > 0.04)
860 if (
APV->Thickness < 0.04)
862 if (
APV->Thickness > 0.04)
870 if (FitResults[0] != -0.5) {
889 unsigned int GOOD = 0;
890 unsigned int BAD = 0;
891 double MPVmean = 300.;
895 APV->Gain =
APV->MPV / MPVmean;
907 APV->Gain *=
APV->PreviousGain;
914 if (FitResults[0] == -0.5)
928 if (FitResults[0] == -0.5)
942 if (FitResults[0] == -0.5)
1007 if (FitResults[0] == -0.5)
1017 if (FitResults[0] == -0.5)
1027 if (FitResults[0] == -0.5)
1037 if (FitResults[0] == -0.5)
1047 if (FitResults[0] == -0.5)
1057 if (FitResults[0] == -0.5)
1067 if (FitResults[0] == -0.5)
1077 if (FitResults[0] == -0.5)
1087 if (FitResults[0] == -0.5)
1095 fprintf(Gains,
"NEvents = %i\n",
NEvent);
1096 fprintf(Gains,
"Number of APVs = %lu\n", static_cast<unsigned long>(
APVsColl.size()));
1097 fprintf(Gains,
"GoodFits = %i BadFits = %i ratio = %f\n",
GOOD,
BAD, (100.0 *
GOOD) / (
GOOD +
BAD));
1101 "%i | %i | PreviousGain = %7.5f NewGain = %7.5f\n",
1108 std::vector<int> DetIdOfBuggedAPV;
1109 fprintf(Gains,
"----------------------------------------------------------------------\n");
1112 if (
APV->MPV > 0 &&
APV->MPV < 200) {
1113 bool tmpBug =
false;
1114 for (
unsigned int b = 0;
b < DetIdOfBuggedAPV.size() && !tmpBug;
b++) {
1115 if (DetIdOfBuggedAPV[
b] ==
APV->DetId)
1119 fprintf(Gains,
"%i,\n",
APV->DetId);
1120 DetIdOfBuggedAPV.push_back(
APV->DetId);
1138 if (!gainHandle.isValid()) {
1139 printf(
"\n#####################\n\nERROR --> gainHandle is not valid\n\n#####################\n\n");
1146 if (gainHandle.isValid()) {
1148 APV->PreviousGain = *(detGainRange.first +
APV->APVId);
1151 if (
APV->PreviousGain < 0)
1152 APV->PreviousGain = 1;
1154 printf(
"GAIN HANDLE IS NOT VALID\n");
1161 if (strcmp(
AlgoMode.c_str(),
"WriteOnDB") == 0)
1195 for (Trajectory::RecHitContainer::const_iterator rechit = transRecHits.begin(); rechit != transRecHits.end();
1197 if ((*rechit)->isValid())
1198 ndof += (*rechit)->dimension();
1206 vector<TrajectoryMeasurement> measurements = traj.
measurements();
1230 for (vector<TrajectoryMeasurement>::const_iterator measurement_it = measurements.begin();
1231 measurement_it != measurements.end();
1242 if (sistripsimplehit) {
1245 }
else if (sistripmatchedhit) {
1249 }
else if (sistripsimple1dhit) {
1262 double trajChi2OverN) {
1264 double cosine = trackDirection.
z() / trackDirection.
mag();
1268 int APVId = FirstStrip / 128;
1271 bool Overlaping =
false;
1273 unsigned int NHighStrip = 0;
1278 if (FirstStrip == 0)
1280 if (FirstStrip == 128)
1282 if (FirstStrip == 256)
1284 if (FirstStrip == 384)
1286 if (FirstStrip == 512)
1288 if (FirstStrip == 640)
1291 if (FirstStrip <= 127 && FirstStrip + Ampls.size() > 127)
1293 if (FirstStrip <= 255 && FirstStrip + Ampls.size() > 255)
1295 if (FirstStrip <= 383 && FirstStrip + Ampls.size() > 383)
1297 if (FirstStrip <= 511 && FirstStrip + Ampls.size() > 511)
1299 if (FirstStrip <= 639 && FirstStrip + Ampls.size() > 639)
1302 if (FirstStrip + Ampls.size() == 127)
1304 if (FirstStrip + Ampls.size() == 255)
1306 if (FirstStrip + Ampls.size() == 383)
1308 if (FirstStrip + Ampls.size() == 511)
1310 if (FirstStrip + Ampls.size() == 639)
1312 if (FirstStrip + Ampls.size() == 767)
1326 for (
unsigned int a = 0;
a < Ampls.size();
a++) {
1328 if (Ampls[
a] >= 254)
1333 double path = (10.0 *
APV->Thickness) / fabs(cosine);
1334 double ClusterChargeOverPath = (double)
Charge /
path;
1343 if (
APV->Thickness < 0.04)
1345 if (
APV->Thickness > 0.04)
1355 if (
APV->Thickness < 0.04)
1357 if (
APV->Thickness > 0.04)
1361 double trans = atan2(trackDirection.
y(), trackDirection.
x()) * (180 / 3.14159265);
1363 acos(trackDirection.
x() /
sqrt(
pow(trackDirection.
x(), 2) +
pow(trackDirection.
z(), 2))) * (180 / 3.14159265);
1365 acos(trackDirection.
y() /
sqrt(
pow(trackDirection.
x(), 2) +
pow(trackDirection.
z(), 2))) * (180 / 3.14159265);
1387 ClusterChargeOverPath = ClusterChargeOverPath /
APV->PreviousGain;
1394 return ClusterChargeOverPath;
1398 const uint32_t detid,
1406 if (dynamic_cast<const StripGeomDetUnit*>(it) ==
nullptr && dynamic_cast<const PixelGeomDetUnit*>(it) ==
nullptr) {
1407 std::cout <<
"this detID doesn't seem to belong to the Tracker" << std::endl;
1412 const TrapezoidalPlaneBounds* trapezoidalBounds(dynamic_cast<const TrapezoidalPlaneBounds*>(&(plane.bounds())));
1413 const RectangularPlaneBounds* rectangularBounds(dynamic_cast<const RectangularPlaneBounds*>(&(plane.bounds())));
1415 double DistFromBorder = 1.0;
1419 if (trapezoidalBounds) {
1420 std::array<const float, 4>
const&
parameters = (*trapezoidalBounds).parameters();
1424 }
else if (rectangularBounds) {
1432 if (fabs(HitLocalPos.
y()) + HitLocalError.
yy() >= (
HalfLength - DistFromBorder))
1440 double adcs_err = 0.;
1441 double width = -0.5;
1442 double width_err = 0;
1443 double chi2overndf = -0.5;
1445 double nr_of_entries = InputHisto->GetEntries();
1448 FitResults[0] = adcs;
1449 FitResults[1] = adcs_err;
1450 FitResults[2] =
width;
1451 FitResults[3] = width_err;
1452 FitResults[4] = chi2overndf;
1457 TF1* MyLandau =
new TF1(
"MyLandau",
"landau", LowRange, HighRange);
1458 MyLandau->SetParameter(
"MPV", 300);
1460 InputHisto->Fit(MyLandau,
"QR WW");
1463 adcs = MyLandau->GetParameter(
"MPV");
1464 adcs_err = MyLandau->GetParError(1);
1465 width = MyLandau->GetParameter(2);
1466 width_err = MyLandau->GetParError(2);
1467 chi2overndf = MyLandau->GetChisquare() / MyLandau->GetNDF();
1478 FitResults[0] = adcs;
1479 FitResults[1] = adcs_err;
1480 FitResults[2] =
width;
1481 FitResults[3] = width_err;
1482 FitResults[4] = chi2overndf;
1488 cout <<
"START getNewObject\n";
1491 if (!(strcmp(
AlgoMode.c_str(),
"WriteOnDB") == 0 || strcmp(
AlgoMode.c_str(),
"SingleJob") == 0))
1492 return std::make_unique<SiStripApvGain>();
1494 auto obj = std::make_unique<SiStripApvGain>();
1495 std::vector<float>* theSiStripVector =
nullptr;
1496 int PreviousDetId = -1;
1499 if (
APV ==
nullptr) {
1503 if (
APV->DetId != PreviousDetId) {
1504 if (theSiStripVector !=
nullptr) {
1506 if (!
obj->put(PreviousDetId,
range))
1507 printf(
"Bug to put detId = %i\n", PreviousDetId);
1510 theSiStripVector =
new std::vector<float>;
1511 PreviousDetId =
APV->DetId;
1513 printf(
"%i | %i | PreviousGain = %7.5f NewGain = %7.5f\n",
APV->DetId,
APV->APVId,
APV->PreviousGain,
APV->Gain);
1514 if (theSiStripVector !=
nullptr) {
1515 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";
edm::ESGetToken< SiStripGain, SiStripGainRcd > gainToken_
static constexpr auto TEC
virtual int nstrips() const =0
T getParameter(std::string const &) const
void algoEndJob() override
uint16_t firstStrip() const
virtual float length() const =0
SiStripGainFromData(const edm::ParameterSet &)
TH2F * HitLocalPositionBefCut
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > tkGeomToken_
const LocalTrajectoryError & localError() const
LocalPoint localPosition() const
friend struct const_iterator
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken_
unsigned int MinNrEntries
std::vector< stAPVGain * > APVsCollOrdered
#define DEFINE_FWK_MODULE(type)
TH1F * NSatStripInCluster
bool IsFarFromBorder(TrajectoryStateOnSurface trajState, const uint32_t detid, const edm::EventSetup *iSetup)
T const * product() const
dqm::legacy::MonitorElement MonitorElement
void algoBeginRun(const edm::Run &, const edm::EventSetup &) override
bool operator()(const T &PseudoDetId1, const T &PseudoDetId2)
LocalError positionError() const
TH1F * FWHM_Vs_PathLength320
const edm::EventSetup * iSetup_
ClusterRef cluster() const
dqm::legacy::DQMStore DQMStore
TH2F * NStrips_Vs_TransversAngle
TH2F * Charge_Vs_PathTEC1
TH1F * FWHM_Vs_PathLength500
DataContainer const & measurements() const
const_iterator end() const
last iterator over the map (read only)
T getUntrackedParameter(std::string const &, T const &) const
TH1F * MPV_Vs_TransversAngle
virtual TH2F * getTH2F() const
vector< string > VInputFiles
~SiStripGainFromData() override
TH1F * FWHM_Vs_PathLength
std::unordered_map< unsigned int, stAPVGain * > APVsColl
SiStripCluster const & monoCluster() const
unsigned int tecSide(const DetId &id) const
SiStripCluster const & amplitudes() const
ConstRecHitContainer recHits() const
LocalVector localDirection() const
std::pair< ContainerIterator, ContainerIterator > Range
const std::complex< double > I
TH1F * MPV_Vs_PathLength320
TH2F * Charge_Vs_PathTEC2
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
bool getData(T &iHolder) const
static constexpr auto TOB
double MaxTrackChiOverNdf
void algoBeginJob(const edm::EventSetup &) override
TH1F * NumberOfEntriesByAPV
unsigned long long TimeValue_t
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
TH2F * Charge_Vs_PathLength500
unsigned int MinTrackHits
ConstRecHitContainer RecHitContainer
static constexpr auto TIB
const Plane & surface() const
The nominal surface of the GeomDet.
TH2F * Charge_Vs_PathLength
double ComputeChargeOverPath(const SiStripCluster *Cluster, TrajectoryStateOnSurface trajState, const edm::EventSetup *iSetup, const Track *track, double trajChi2OverN)
void algoAnalyze(const edm::Event &, const edm::EventSetup &) override
constexpr uint32_t rawId() const
get the raw id
TH2F * Charge_Vs_TransversAngle
virtual TH1F * getTH1F() const
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
std::unique_ptr< SiStripApvGain > getNewObject() override
GlobalVector globalMomentum() const
SiStripCluster const & stereoCluster() const
void getPeakOfLandau(TH1 *InputHisto, double *FitResults, double LowRange=0, double HighRange=5400)
std::string TrajToTrackLabel
DQM_DEPRECATED void save(std::string const &filename, std::string const &path="")
const_iterator begin() const
first iterator over the map (read only)
TH2F * Charge_Vs_PathLength320
TH1F * NHighStripInCluster
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
std::string TrajToTrackProducer
ClusterRef cluster() const
static constexpr auto TID
Power< A, B >::type pow(const A &a, const B &b)
const edm::Event * iEvent_
TH1F * MPV_Vs_PathLength500
const Bounds & bounds() const