File indexing completed on 2024-09-07 04:34:24
0001 #ifndef Alignment_APEEstimation_TrackerSectorStruct_h
0002 #define Alignment_APEEstimation_TrackerSectorStruct_h
0003
0004 #include <vector>
0005 #include <map>
0006 #include "TH1F.h"
0007 #include "TH2F.h"
0008 #include "TProfile.h"
0009 #include "TString.h"
0010 #include "CommonTools/Utils/interface/TFileDirectory.h"
0011
0012 #include "Alignment/APEEstimation/interface/EventVariables.h"
0013
0014 #include "TH1.h"
0015 #include "TH2.h"
0016 #include "TTree.h"
0017
0018
0019
0020
0021
0022
0023
0024
0025 class TrackerSectorStruct {
0026 public:
0027 inline TrackerSectorStruct();
0028
0029 inline ~TrackerSectorStruct();
0030
0031 struct CorrelationHists {
0032 CorrelationHists()
0033 : Variable(nullptr),
0034 NorResXVsVar(nullptr),
0035 ProbXVsVar(nullptr),
0036 SigmaXHitVsVar(nullptr),
0037 SigmaXTrkVsVar(nullptr),
0038 SigmaXVsVar(nullptr),
0039 PNorResXVsVar(nullptr),
0040 PProbXVsVar(nullptr),
0041 PSigmaXHitVsVar(nullptr),
0042 PSigmaXTrkVsVar(nullptr),
0043 PSigmaXVsVar(nullptr) {}
0044
0045 inline void fillCorrHists(const TString,
0046 const TrackStruct::HitParameterStruct &hitParameterStruct,
0047 double variable);
0048 inline void fillCorrHistsX(const TrackStruct::HitParameterStruct &hitParameterStruct, double variable);
0049 inline void fillCorrHistsY(const TrackStruct::HitParameterStruct &hitParameterStruct, double variable);
0050
0051 TH1F *Variable;
0052 TH2F *NorResXVsVar, *ProbXVsVar, *SigmaXHitVsVar, *SigmaXTrkVsVar, *SigmaXVsVar;
0053 TProfile *PNorResXVsVar, *PProbXVsVar, *PSigmaXHitVsVar, *PSigmaXTrkVsVar, *PSigmaXVsVar;
0054 };
0055
0056 inline void setCorrHistParams(TFileDirectory *, double, double, double);
0057 inline CorrelationHists bookCorrHists(
0058 TString, TString, TString, TString, TString, int, int, double, double, std::string = "nphtr");
0059 inline CorrelationHists bookCorrHistsX(
0060 TString, TString, TString, TString, int, int, double, double, std::string = "nphtr");
0061 inline CorrelationHists bookCorrHistsY(
0062 TString, TString, TString, TString, int, int, double, double, std::string = "nphtr");
0063
0064 inline CorrelationHists bookCorrHists(TString, TString, TString, TString, int, double, double, std::string = "nphtr");
0065 inline CorrelationHists bookCorrHistsX(TString, TString, TString, int, double, double, std::string = "nphtr");
0066 inline CorrelationHists bookCorrHistsY(TString, TString, TString, int, double, double, std::string = "nphtr");
0067
0068 TFileDirectory *directory_;
0069 double norResXMax_, sigmaXHitMax_, sigmaXMax_;
0070 std::map<std::string, CorrelationHists> m_correlationHistsX;
0071 std::map<std::string, CorrelationHists> m_correlationHistsY;
0072
0073
0074 std::string name;
0075 TH1 *Name;
0076
0077
0078 std::vector<unsigned int> v_rawId;
0079
0080 TH1 *ResX, *NorResX, *XHit, *XTrk, *SigmaX2, *ProbX;
0081 TH2 *WidthVsPhiSensX, *WidthVsWidthProjected, *WidthDiffVsMaxStrip, *WidthDiffVsSigmaXHit, *PhiSensXVsBarycentreX;
0082 TProfile *PWidthVsPhiSensX, *PWidthVsWidthProjected, *PWidthDiffVsMaxStrip, *PWidthDiffVsSigmaXHit,
0083 *PPhiSensXVsBarycentreX;
0084 std::map<std::string, std::vector<TH1 *> > m_sigmaX;
0085
0086 TH1 *ResY, *NorResY, *YHit, *YTrk, *SigmaY2, *ProbY;
0087 TH2 *PhiSensYVsBarycentreY;
0088 TProfile *PPhiSensYVsBarycentreY;
0089 std::map<std::string, std::vector<TH1 *> > m_sigmaY;
0090
0091
0092 std::map<unsigned int, std::map<std::string, TH1 *> > m_binnedHists;
0093
0094
0095 TTree *RawId;
0096 TH1 *EntriesX;
0097 TH1 *WeightX, *MeanX, *RmsX, *FitMeanX1, *ResidualWidthX1, *CorrectionX1, *FitMeanX2, *ResidualWidthX2, *CorrectionX2;
0098 TH1 *EntriesY;
0099 TH1 *WeightY, *MeanY, *RmsY, *FitMeanY1, *ResidualWidthY1, *CorrectionY1, *FitMeanY2, *ResidualWidthY2, *CorrectionY2;
0100
0101
0102 bool isPixel;
0103 };
0104
0105 TrackerSectorStruct::TrackerSectorStruct()
0106 : directory_(nullptr),
0107 norResXMax_(999.),
0108 sigmaXHitMax_(999.),
0109 sigmaXMax_(999.),
0110 name("default"),
0111 Name(nullptr),
0112 ResX(nullptr),
0113 NorResX(nullptr),
0114 XHit(nullptr),
0115 XTrk(nullptr),
0116 SigmaX2(nullptr),
0117 ProbX(nullptr),
0118 WidthVsPhiSensX(nullptr),
0119 WidthVsWidthProjected(nullptr),
0120 WidthDiffVsMaxStrip(nullptr),
0121 WidthDiffVsSigmaXHit(nullptr),
0122 PhiSensXVsBarycentreX(nullptr),
0123 PWidthVsPhiSensX(nullptr),
0124 PWidthVsWidthProjected(nullptr),
0125 PWidthDiffVsMaxStrip(nullptr),
0126 PWidthDiffVsSigmaXHit(nullptr),
0127 PPhiSensXVsBarycentreX(nullptr),
0128 ResY(nullptr),
0129 NorResY(nullptr),
0130 YHit(nullptr),
0131 YTrk(nullptr),
0132 SigmaY2(nullptr),
0133 ProbY(nullptr),
0134 PhiSensYVsBarycentreY(nullptr),
0135 PPhiSensYVsBarycentreY(nullptr),
0136 RawId(nullptr),
0137 EntriesX(nullptr),
0138 MeanX(nullptr),
0139 RmsX(nullptr),
0140 FitMeanX1(nullptr),
0141 ResidualWidthX1(nullptr),
0142 CorrectionX1(nullptr),
0143 FitMeanX2(nullptr),
0144 ResidualWidthX2(nullptr),
0145 CorrectionX2(nullptr),
0146 EntriesY(nullptr),
0147 MeanY(nullptr),
0148 RmsY(nullptr),
0149 FitMeanY1(nullptr),
0150 ResidualWidthY1(nullptr),
0151 CorrectionY1(nullptr),
0152 FitMeanY2(nullptr),
0153 ResidualWidthY2(nullptr),
0154 CorrectionY2(nullptr),
0155 isPixel(false) {}
0156
0157 TrackerSectorStruct::~TrackerSectorStruct() {}
0158
0159 void TrackerSectorStruct::setCorrHistParams(TFileDirectory *directory,
0160 double norResXMax,
0161 double sigmaXHitMax,
0162 double sigmaXMax) {
0163 directory_ = directory;
0164 norResXMax_ = norResXMax;
0165 sigmaXHitMax_ = sigmaXHitMax;
0166 sigmaXMax_ = sigmaXMax;
0167 }
0168
0169 TrackerSectorStruct::CorrelationHists TrackerSectorStruct::bookCorrHistsX(TString varName,
0170 TString varTitle,
0171 TString labelX,
0172 TString unitX,
0173 int nBinX1D,
0174 int nBinX2D,
0175 double minBinX,
0176 double maxBinX,
0177 std::string options) {
0178 return bookCorrHists("X", varName, varTitle, labelX, unitX, nBinX1D, nBinX2D, minBinX, maxBinX, options);
0179 }
0180 TrackerSectorStruct::CorrelationHists TrackerSectorStruct::bookCorrHistsY(TString varName,
0181 TString varTitle,
0182 TString labelX,
0183 TString unitX,
0184 int nBinX1D,
0185 int nBinX2D,
0186 double minBinX,
0187 double maxBinX,
0188 std::string options) {
0189 return bookCorrHists("Y", varName, varTitle, labelX, unitX, nBinX1D, nBinX2D, minBinX, maxBinX, options);
0190 }
0191 TrackerSectorStruct::CorrelationHists TrackerSectorStruct::bookCorrHists(TString xY,
0192 TString varName,
0193 TString varTitle,
0194 TString labelX,
0195 TString unitX,
0196 int nBinX1D,
0197 int nBinX2D,
0198 double minBinX,
0199 double maxBinX,
0200 std::string options) {
0201 TString xy;
0202 TString suffix;
0203 if (xY == "X") {
0204 xy = "x";
0205 suffix = "";
0206 }
0207 if (xY == "Y") {
0208 xy = "y";
0209 suffix = "_y";
0210 }
0211
0212 const std::string &o(options);
0213 CorrelationHists correlationHists;
0214
0215 if (!(o.find('n') != std::string::npos || o.find('p') != std::string::npos || o.find('h') != std::string::npos ||
0216 o.find('t') != std::string::npos || o.find('r') != std::string::npos))
0217 return correlationHists;
0218
0219 TFileDirectory *directory(directory_);
0220 double norResXMax(norResXMax_), sigmaXHitMax(sigmaXHitMax_), sigmaXMax(sigmaXMax_);
0221
0222 if (!directory)
0223 return correlationHists;
0224
0225 correlationHists.Variable = directory->make<TH1F>("h_" + varName + suffix,
0226 varTitle + " " + labelX + ";" + labelX + " " + unitX + ";# hits",
0227 nBinX1D,
0228 minBinX,
0229 maxBinX);
0230
0231 if (options.find('n') != std::string::npos)
0232 correlationHists.NorResXVsVar =
0233 directory->make<TH2F>("h2_norRes" + xY + "Vs" + varName,
0234 "r_{" + xy + "}/#sigma_{r," + xy + "} vs. " + labelX + ";" + labelX + " " + unitX +
0235 ";(" + xy + "_{trk}-" + xy + "_{hit})/#sigma_{r," + xy + "}",
0236 nBinX2D,
0237 minBinX,
0238 maxBinX,
0239 25,
0240 -norResXMax,
0241 norResXMax);
0242 if (options.find('p') != std::string::npos)
0243 correlationHists.ProbXVsVar =
0244 directory->make<TH2F>("h2_prob" + xY + "Vs" + varName,
0245 "prob_{" + xy + "} vs. " + labelX + ";" + labelX + " " + unitX + ";prob_{" + xy + "}",
0246 nBinX2D,
0247 minBinX,
0248 maxBinX,
0249 60,
0250 -0.1,
0251 1.1);
0252 if (options.find('h') != std::string::npos)
0253 correlationHists.SigmaXHitVsVar = directory->make<TH2F>(
0254 "h2_sigma" + xY + "HitVs" + varName,
0255 "#sigma_{hit," + xy + "} vs. " + labelX + ";" + labelX + " " + unitX + ";#sigma_{hit," + xy + "} [#mum]",
0256 nBinX2D,
0257 minBinX,
0258 maxBinX,
0259 50,
0260 0 * 10000.,
0261 sigmaXHitMax * 10000.);
0262 if (options.find('t') != std::string::npos)
0263 correlationHists.SigmaXTrkVsVar = directory->make<TH2F>(
0264 "h2_sigma" + xY + "TrkVs" + varName,
0265 "#sigma_{trk," + xy + "} vs. " + labelX + ";" + labelX + " " + unitX + ";#sigma_{trk," + xy + "} [#mum]",
0266 nBinX2D,
0267 minBinX,
0268 maxBinX,
0269 50,
0270 0 * 10000.,
0271 sigmaXMax * 10000.);
0272 if (options.find('r') != std::string::npos)
0273 correlationHists.SigmaXVsVar = directory->make<TH2F>(
0274 "h2_sigma" + xY + "Vs" + varName,
0275 "#sigma_{r," + xy + "} vs. " + labelX + ";" + labelX + " " + unitX + ";#sigma_{r," + xy + "} [#mum]",
0276 nBinX2D,
0277 minBinX,
0278 maxBinX,
0279 50,
0280 0 * 10000.,
0281 sigmaXMax * 10000.);
0282
0283 if (options.find('n') != std::string::npos)
0284 correlationHists.PNorResXVsVar =
0285 directory->make<TProfile>("p_norRes" + xY + "Vs" + varName,
0286 "r_{" + xy + "}/#sigma_{r," + xy + "} vs. " + labelX + ";" + labelX + " " + unitX +
0287 ";(" + xy + "_{trk}-" + xy + "_{hit})/#sigma_{r," + xy + "}",
0288 nBinX2D,
0289 minBinX,
0290 maxBinX,
0291 "s");
0292 if (options.find('p') != std::string::npos)
0293 correlationHists.PProbXVsVar = directory->make<TProfile>(
0294 "p_prob" + xY + "Vs" + varName,
0295 "prob_{" + xy + "} vs. " + labelX + ";" + labelX + " " + unitX + ";prob_{" + xy + "}",
0296 nBinX2D,
0297 minBinX,
0298 maxBinX,
0299 "s");
0300 if (options.find('h') != std::string::npos)
0301 correlationHists.PSigmaXHitVsVar = directory->make<TProfile>(
0302 "p_sigma" + xY + "HitVs" + varName,
0303 "#sigma_{hit," + xy + "} vs. " + labelX + ";" + labelX + " " + unitX + ";#sigma_{hit," + xy + "} [#mum]",
0304 nBinX2D,
0305 minBinX,
0306 maxBinX);
0307 if (options.find('t') != std::string::npos)
0308 correlationHists.PSigmaXTrkVsVar = directory->make<TProfile>(
0309 "p_sigma" + xY + "TrkVs" + varName,
0310 "#sigma_{trk," + xy + "} vs. " + labelX + ";" + labelX + " " + unitX + ";#sigma_{trk," + xy + "} [#mum]",
0311 nBinX2D,
0312 minBinX,
0313 maxBinX);
0314 if (options.find('r') != std::string::npos)
0315 correlationHists.PSigmaXVsVar = directory->make<TProfile>(
0316 "p_sigma" + xY + "Vs" + varName,
0317 "#sigma_{r," + xy + "} vs. " + labelX + ";" + labelX + " " + unitX + ";#sigma_{r," + xy + "} [#mum]",
0318 nBinX2D,
0319 minBinX,
0320 maxBinX);
0321
0322 return correlationHists;
0323 }
0324
0325 TrackerSectorStruct::CorrelationHists TrackerSectorStruct::bookCorrHistsX(
0326 TString varName, TString labelX, TString unitX, int nBinX, double minBinX, double maxBinX, std::string options) {
0327 return bookCorrHists("X", varName, labelX, unitX, nBinX, minBinX, maxBinX, options);
0328 }
0329 TrackerSectorStruct::CorrelationHists TrackerSectorStruct::bookCorrHistsY(
0330 TString varName, TString labelX, TString unitX, int nBinX, double minBinX, double maxBinX, std::string options) {
0331 return bookCorrHists("Y", varName, labelX, unitX, nBinX, minBinX, maxBinX, options);
0332 }
0333 TrackerSectorStruct::CorrelationHists TrackerSectorStruct::bookCorrHists(TString xY,
0334 TString varName,
0335 TString labelX,
0336 TString unitX,
0337 int nBinX,
0338 double minBinX,
0339 double maxBinX,
0340 std::string options) {
0341 TString xy;
0342 if (xY == "X") {
0343 xy = "x";
0344 }
0345 if (xY == "Y") {
0346 xy = "y";
0347 }
0348
0349 const std::string &o(options);
0350 CorrelationHists correlationHists;
0351
0352 if (!(o.find('n') != std::string::npos || o.find('p') != std::string::npos || o.find('h') != std::string::npos ||
0353 o.find('t') != std::string::npos || o.find('r') != std::string::npos))
0354 return correlationHists;
0355
0356 TFileDirectory *directory(directory_);
0357 double norResXMax(norResXMax_), sigmaXHitMax(sigmaXHitMax_), sigmaXMax(sigmaXMax_);
0358
0359 if (!directory)
0360 return correlationHists;
0361
0362 if (options.find('n') != std::string::npos)
0363 correlationHists.NorResXVsVar =
0364 directory->make<TH2F>("h2_norRes" + xY + "Vs" + varName,
0365 "r_{" + xy + "}/#sigma_{r," + xy + "} vs. " + labelX + ";" + labelX + " " + unitX +
0366 ";(" + xy + "_{trk}-" + xy + "_{hit})/#sigma_{r," + xy + "}",
0367 nBinX,
0368 minBinX,
0369 maxBinX,
0370 25,
0371 -norResXMax,
0372 norResXMax);
0373 if (options.find('p') != std::string::npos)
0374 correlationHists.ProbXVsVar =
0375 directory->make<TH2F>("h2_prob" + xY + "Vs" + varName,
0376 "prob_{" + xy + "} vs. " + labelX + ";" + labelX + " " + unitX + ";prob_{" + xy + "}",
0377 nBinX,
0378 minBinX,
0379 maxBinX,
0380 60,
0381 -0.1,
0382 1.1);
0383 if (options.find('h') != std::string::npos)
0384 correlationHists.SigmaXHitVsVar = directory->make<TH2F>(
0385 "h2_sigma" + xY + "HitVs" + varName,
0386 "#sigma_{hit," + xy + "} vs. " + labelX + ";" + labelX + " " + unitX + ";#sigma_{hit," + xy + "} [#mum]",
0387 nBinX,
0388 minBinX,
0389 maxBinX,
0390 50,
0391 0 * 10000.,
0392 sigmaXHitMax * 10000.);
0393 if (options.find('t') != std::string::npos)
0394 correlationHists.SigmaXTrkVsVar = directory->make<TH2F>(
0395 "h2_sigma" + xY + "TrkVs" + varName,
0396 "#sigma_{trk," + xy + "} vs. " + labelX + ";" + labelX + " " + unitX + ";#sigma_{trk," + xy + "} [#mum]",
0397 nBinX,
0398 minBinX,
0399 maxBinX,
0400 50,
0401 0 * 10000.,
0402 sigmaXMax * 10000.);
0403 if (options.find('r') != std::string::npos)
0404 correlationHists.SigmaXVsVar = directory->make<TH2F>(
0405 "h2_sigma" + xY + "Vs" + varName,
0406 "#sigma_{r," + xy + "} vs. " + labelX + ";" + labelX + " " + unitX + ";#sigma_{r," + xy + "} [#mum]",
0407 nBinX,
0408 minBinX,
0409 maxBinX,
0410 50,
0411 0 * 10000.,
0412 sigmaXMax * 10000.);
0413
0414 if (options.find('n') != std::string::npos)
0415 correlationHists.PNorResXVsVar =
0416 directory->make<TProfile>("p_norRes" + xY + "Vs" + varName,
0417 "r_{" + xy + "}/#sigma_{r," + xy + "} vs. " + labelX + ";" + labelX + " " + unitX +
0418 ";(" + xy + "_{trk}-" + xy + "_{hit})/#sigma_{r," + xy + "}",
0419 nBinX,
0420 minBinX,
0421 maxBinX,
0422 "s");
0423 if (options.find('p') != std::string::npos)
0424 correlationHists.PProbXVsVar = directory->make<TProfile>(
0425 "p_prob" + xY + "Vs" + varName,
0426 "prob_{" + xy + "} vs. " + labelX + ";" + labelX + " " + unitX + ";prob_{" + xy + "}",
0427 nBinX,
0428 minBinX,
0429 maxBinX,
0430 "s");
0431 if (options.find('h') != std::string::npos)
0432 correlationHists.PSigmaXHitVsVar = directory->make<TProfile>(
0433 "p_sigma" + xY + "HitVs" + varName,
0434 "#sigma_{hit," + xy + "} vs. " + labelX + ";" + labelX + " " + unitX + ";#sigma_{hit," + xy + "} [#mum]",
0435 nBinX,
0436 minBinX,
0437 maxBinX);
0438 if (options.find('t') != std::string::npos)
0439 correlationHists.PSigmaXTrkVsVar = directory->make<TProfile>(
0440 "p_sigma" + xY + "TrkVs" + varName,
0441 "#sigma_{trk," + xy + "} vs. " + labelX + ";" + labelX + " " + unitX + ";#sigma_{trk," + xy + "} [#mum]",
0442 nBinX,
0443 minBinX,
0444 maxBinX);
0445 if (options.find('r') != std::string::npos)
0446 correlationHists.PSigmaXVsVar = directory->make<TProfile>(
0447 "p_sigma" + xY + "Vs" + varName,
0448 "#sigma_{r," + xy + "} vs. " + labelX + ";" + labelX + " " + unitX + ";#sigma_{r," + xy + "} [#mum]",
0449 nBinX,
0450 minBinX,
0451 maxBinX);
0452
0453 return correlationHists;
0454 }
0455
0456 void TrackerSectorStruct::CorrelationHists::fillCorrHistsX(const TrackStruct::HitParameterStruct &hitParameterStruct,
0457 double variable) {
0458 return fillCorrHists("X", hitParameterStruct, variable);
0459 }
0460 void TrackerSectorStruct::CorrelationHists::fillCorrHistsY(const TrackStruct::HitParameterStruct &hitParameterStruct,
0461 double variable) {
0462 return fillCorrHists("Y", hitParameterStruct, variable);
0463 }
0464 void TrackerSectorStruct::CorrelationHists::fillCorrHists(const TString xY,
0465 const TrackStruct::HitParameterStruct &hitParameterStruct,
0466 double variable) {
0467 float norRes(999.);
0468 float prob(999.);
0469 float errHit(999.);
0470 float errTrk(999.);
0471 float err(999.);
0472 if (xY == "X") {
0473 norRes = hitParameterStruct.norResX;
0474 prob = hitParameterStruct.probX;
0475 errHit = hitParameterStruct.errXHit;
0476 errTrk = hitParameterStruct.errXTrk;
0477 err = hitParameterStruct.errX;
0478 }
0479 if (xY == "Y") {
0480 norRes = hitParameterStruct.norResY;
0481 prob = hitParameterStruct.probY;
0482 errHit = hitParameterStruct.errYHit;
0483 errTrk = hitParameterStruct.errYTrk;
0484 err = hitParameterStruct.errY;
0485 }
0486
0487 if (Variable) {
0488 Variable->Fill(variable);
0489 }
0490
0491 if (NorResXVsVar) {
0492 NorResXVsVar->Fill(variable, norRes);
0493 PNorResXVsVar->Fill(variable, norRes);
0494 }
0495 if (ProbXVsVar) {
0496 ProbXVsVar->Fill(variable, prob);
0497 PProbXVsVar->Fill(variable, prob);
0498 }
0499 if (SigmaXHitVsVar) {
0500 SigmaXHitVsVar->Fill(variable, errHit * 10000.);
0501 PSigmaXHitVsVar->Fill(variable, errHit * 10000.);
0502 }
0503 if (SigmaXTrkVsVar) {
0504 SigmaXTrkVsVar->Fill(variable, errTrk * 10000.);
0505 PSigmaXTrkVsVar->Fill(variable, errTrk * 10000.);
0506 }
0507 if (SigmaXVsVar) {
0508 SigmaXVsVar->Fill(variable, err * 10000.);
0509 PSigmaXVsVar->Fill(variable, err * 10000.);
0510 }
0511 }
0512
0513 #endif