File indexing completed on 2024-04-06 12:03:27
0001 #include "TROOT.h"
0002 #include "TFile.h"
0003 #include "TCanvas.h"
0004 #include "TH1F.h"
0005 #include "TH2F.h"
0006 #include "TProfile.h"
0007 #include "TTree.h"
0008 #include "TBranch.h"
0009 #include "TTree.h"
0010 #include "TChain.h"
0011
0012 #include <iostream>
0013 #include <algorithm>
0014 #include <vector>
0015 #include <map>
0016 #include <iostream>
0017 #include <iomanip> // std::setw
0018
0019
0020
0021
0022 class RecordInfo : public TNamed {
0023 public:
0024 RecordInfo(const char* record, const char* tag) : TNamed(record, tag) {}
0025
0026 void printInfo() const { std::cout << GetName() << " " << GetTitle() << std::endl; }
0027
0028 const char* getRecord() { return this->GetName(); }
0029
0030 const char* getIOVSince() { return this->GetTitle(); }
0031 };
0032
0033 enum ModuleGeometry {
0034 UNKNOWNGEOMETRY,
0035 IB1,
0036 IB2,
0037 OB1,
0038 OB2,
0039 W1A,
0040 W2A,
0041 W3A,
0042 W1B,
0043 W2B,
0044 W3B,
0045 W4,
0046 W5,
0047 W6,
0048 W7,
0049 END_OF_GEOMETRIES
0050 };
0051
0052 enum TrackerRegion {
0053 TIB1 = 1,
0054 TIB2 = 2,
0055 TIB3 = 3,
0056 TIB4 = 4,
0057 TOB1 = 5,
0058 TOB2 = 6,
0059 TOB3 = 7,
0060 TOB4 = 8,
0061 TOB5 = 9,
0062 TOB6 = 10,
0063 TIDP1 = 11,
0064 TIDP2 = 12,
0065 TIDP3 = 13,
0066 TIDM1 = 14,
0067 TIDM2 = 15,
0068 TIDM3 = 16,
0069 TECP1 = 17,
0070 TECP2 = 18,
0071 TECP3 = 19,
0072 TECP4 = 20,
0073 TECP5 = 21,
0074 TECP6 = 22,
0075 TECP7 = 23,
0076 TECP8 = 24,
0077 TECP9 = 25,
0078 TECM1 = 26,
0079 TECM2 = 27,
0080 TECM3 = 28,
0081 TECM4 = 29,
0082 TECM5 = 30,
0083 TECM6 = 31,
0084 TECM7 = 32,
0085 TECM8 = 33,
0086 TECM9 = 34,
0087 END_OF_REGIONS = 35
0088 };
0089
0090
0091 TrackerRegion getTheRegionFromTopology(int subdet, int side, int layer)
0092
0093 {
0094 int ret(-99);
0095 switch (subdet) {
0096 case 3:
0097
0098 ret = layer;
0099 break;
0100 case 4:
0101
0102 ret = side == 1 ? 10 + std::abs(layer) : 13 + std::abs(layer);
0103 break;
0104 case 5:
0105
0106 ret = layer + 4;
0107 break;
0108 case 6:
0109
0110 ret = side == 1 ? 16 + std::abs(layer) : 25 + std::abs(layer);
0111 break;
0112 default:
0113 std::cout << "getTheRegionFromTopology(): shall never ever be here!" << std::endl;
0114 break;
0115 }
0116 return static_cast<TrackerRegion>(ret);
0117 }
0118
0119
0120 const char* regionType(int index)
0121
0122 {
0123 auto region = static_cast<std::underlying_type_t<TrackerRegion> >(index);
0124
0125 switch (region) {
0126 case TIB1:
0127 return "TIB L1";
0128 case TIB2:
0129 return "TIB L2";
0130 case TIB3:
0131 return "TIB L3";
0132 case TIB4:
0133 return "TIB L4";
0134 case TOB1:
0135 return "TOB L1";
0136 case TOB2:
0137 return "TOB L2";
0138 case TOB3:
0139 return "TOB L3";
0140 case TOB4:
0141 return "TOB L4";
0142 case TOB5:
0143 return "TOB L5";
0144 case TOB6:
0145 return "TOB L6";
0146 case TIDP1:
0147 return "TID+ D1";
0148 case TIDP2:
0149 return "TID+ D2";
0150 case TIDP3:
0151 return "TID+ D3";
0152 case TIDM1:
0153 return "TID- D1";
0154 case TIDM2:
0155 return "TID- D2";
0156 case TIDM3:
0157 return "TID- D3";
0158 case TECP1:
0159 return "TEC+ D1";
0160 case TECP2:
0161 return "TEC+ D2";
0162 case TECP3:
0163 return "TEC+ D3";
0164 case TECP4:
0165 return "TEC+ D4";
0166 case TECP5:
0167 return "TEC+ D5";
0168 case TECP6:
0169 return "TEC+ D6";
0170 case TECP7:
0171 return "TEC+ D7";
0172 case TECP8:
0173 return "TEC+ D8";
0174 case TECP9:
0175 return "TEC+ D9";
0176 case TECM1:
0177 return "TEC- D1";
0178 case TECM2:
0179 return "TEC- D2";
0180 case TECM3:
0181 return "TEC- D3";
0182 case TECM4:
0183 return "TEC- D4";
0184 case TECM5:
0185 return "TEC- D5";
0186 case TECM6:
0187 return "TEC- D6";
0188 case TECM7:
0189 return "TEC- D7";
0190 case TECM8:
0191 return "TEC- D8";
0192 case TECM9:
0193 return "TEC- D9";
0194 case END_OF_REGIONS:
0195 return "undefined";
0196 default:
0197 return "should never be here";
0198 }
0199 }
0200
0201
0202 const char* moduleType(int index)
0203
0204 {
0205 auto geometry = static_cast<std::underlying_type_t<ModuleGeometry> >(index);
0206
0207 switch (geometry) {
0208 case UNKNOWNGEOMETRY:
0209 return "unknown geometry";
0210 case IB1:
0211 return "IB1";
0212 case IB2:
0213 return "IB2";
0214 case OB1:
0215 return "OB1";
0216 case OB2:
0217 return "OB2";
0218 case W1A:
0219 return "W1A";
0220 case W2A:
0221 return "W2A";
0222 case W3A:
0223 return "W3A";
0224 case W1B:
0225 return "W1B";
0226 case W2B:
0227 return "W2B";
0228 case W3B:
0229 return "W3B";
0230 case W4:
0231 return "W4";
0232 case W5:
0233 return "W5";
0234 case W6:
0235 return "W6";
0236 case W7:
0237 return "W7";
0238 case END_OF_GEOMETRIES:
0239 return "NONE";
0240 default:
0241 return "should never be here";
0242 }
0243 }
0244
0245
0246 void readNSiStripDBTrees(TString fname)
0247
0248 {
0249 TChain* tree_ = new TChain("treeDump/StripDBTree");
0250 tree_->Add(fname);
0251
0252 uint32_t detId_, ring_, istrip_, det_type_;
0253 Int_t layer_, side_, subdetId_;
0254 float pedestal_, noise_, gsim_, g1_, g2_, lenght_;
0255 bool isTIB_, isTOB_, isTEC_, isTID_, isBad_;
0256
0257 std::map<int, TH1F*> PedestalPerLayer;
0258 std::map<int, TH1F*> idealNoiseRatioPerLayer;
0259 std::map<int, TH1F*> NoisePerLayer;
0260 std::map<int, TH1F*> g1PerLayer;
0261 std::map<int, TH2F*> noiseVsG1PerModuleGeometry;
0262 std::map<int, TProfile*> p_noiseVsG1PerModuleGeometry;
0263
0264 tree_->SetBranchAddress("detId", &detId_);
0265 tree_->SetBranchAddress("detType", &det_type_);
0266 tree_->SetBranchAddress("noise", &noise_);
0267 tree_->SetBranchAddress("pedestal", &pedestal_);
0268 tree_->SetBranchAddress("istrip", &istrip_);
0269 tree_->SetBranchAddress("gsim", &gsim_);
0270 tree_->SetBranchAddress("g1", &g1_);
0271 tree_->SetBranchAddress("g2", &g2_);
0272 tree_->SetBranchAddress("layer", &layer_);
0273 tree_->SetBranchAddress("side", &side_);
0274 tree_->SetBranchAddress("subdetId", &subdetId_);
0275 tree_->SetBranchAddress("ring", &ring_);
0276 tree_->SetBranchAddress("length", &lenght_);
0277 tree_->SetBranchAddress("isBad", &isBad_);
0278 tree_->SetBranchAddress("isTIB", &isTIB_);
0279 tree_->SetBranchAddress("isTOB", &isTOB_);
0280 tree_->SetBranchAddress("isTEC", &isTEC_);
0281 tree_->SetBranchAddress("isTID", &isTID_);
0282
0283 int nentries = tree_->GetEntries();
0284 std::cout << "Number of entries = " << nentries << std::endl;
0285
0286 tree_->LoadTree(0);
0287 TObjString* s = (TObjString*)tree_->GetTree()->GetUserInfo()->At(0);
0288
0289
0290
0291
0292
0293
0294
0295 std::vector<const char*> records = {
0296 "SiStripPedestalsRcd", "SiStripNoisesRcd", "SiStripApvGainRcd", "SiStripApvGain2Rcd", "SiStripQualityRcd"};
0297 for (const auto& rec : records) {
0298 RecordInfo* header = (RecordInfo*)tree_->GetTree()->GetUserInfo()->FindObject(rec);
0299
0300 std::cout << "printing recordInfo: " << header->getRecord() << " IOV: " << header->getIOVSince() << std::endl;
0301 }
0302
0303 TH1F* h_avgPedestal =
0304 new TH1F("h_avgPedestal_perRegion", "average Pedestal per region;;average Pedestals [ADC counts]", 34, 0., 34.);
0305 TH1F* h_avgIdealNoiseRatio =
0306 new TH1F("h_avgIdealNoise_perRegion", "average Ideal Noise per region;;averag Ideal Noise ratio", 34, 0., 34.);
0307 TH1F* h_avgNoise =
0308 new TH1F("h_avgNoise_perRegion", "average Noise per region;; average Noise [ADC counts]", 34, 0., 34.);
0309
0310 TH1F* h_Pedestal = new TH1F("h_Pedestal", "Pedestal;Pedestals [ADC counts];n. strips", 300, 0., 300.);
0311 TH1F* h_idealNoiseRatio = new TH1F("h_IdealNoise", "Ideal Noise;Ideal Noise ratio;n. strips", 500, 0., 10.);
0312 TH1F* h_Noise = new TH1F("h_Noise", "Noise;Noise [ADC counts];n. strips", 500, 0., 10.);
0313
0314 TH2F* h2_NoiseVsPedestal = new TH2F(
0315 "h2_NoiseVsPedestal", "Noise Vs Pedestal;Pedestals [ADC counts];Noise [ACD counts]", 350, 0., 350., 120, 0., 12.);
0316 TH2F* h2_NoiseVsG1 =
0317 new TH2F("h2_NoiseVsG1", "Noise vs G1 Gain;G1 gain;Noise [ACD counts]", 100, 0., 2., 200, 0., 20.);
0318
0319 TH2F* h2_NoiseVsPedestalTIB = new TH2F("h2_NoiseVsPedestalTIB",
0320 "Noise Vs Pedestal;Pedestals [ADC counts];Noise [ACD counts]",
0321 350,
0322 0.,
0323 350.,
0324 120,
0325 0.,
0326 12.);
0327 TH2F* h2_NoiseVsPedestalTOB = new TH2F("h2_NoiseVsPedestalTOB",
0328 "Noise Vs Pedestal;Pedestals [ADC counts];Noise [ACD counts]",
0329 350,
0330 0.,
0331 350.,
0332 120,
0333 0.,
0334 12.);
0335 TH2F* h2_NoiseVsPedestalTID = new TH2F("h2_NoiseVsPedestalTID",
0336 "Noise Vs Pedestal;Pedestals [ADC counts];Noise [ACD counts]",
0337 350,
0338 0.,
0339 350.,
0340 120,
0341 0.,
0342 12.);
0343 TH2F* h2_NoiseVsPedestalTEC = new TH2F("h2_NoiseVsPedestalTEC",
0344 "Noise Vs Pedestal;Pedestals [ADC counts];Noise [ACD counts]",
0345 350,
0346 0.,
0347 350.,
0348 120,
0349 0.,
0350 12.);
0351
0352 TH1F* h_g1 = new TH1F("h_g1", "g1 gain;g1 gain;n. strips", 200, 0., 2.);
0353
0354
0355 for (int region = TrackerRegion::TIB1; region != TrackerRegion::END_OF_REGIONS; region++) {
0356 auto tag = regionType(region);
0357 std::cout << "booking region: " << std::setw(3) << region << " -> " << tag << std::endl;
0358 idealNoiseRatioPerLayer[region] = new TH1F(
0359 Form("IdealNoise_%s", tag), Form("Ideal Noise %s;Ideal Noise ratio for %s;n. strips", tag, tag), 500, 0., 10.);
0360 NoisePerLayer[region] =
0361 new TH1F(Form("Noise_%s", tag), Form("Noise %s;Noise for %s [ADC counts];n. strips", tag, tag), 500, 0., 10.);
0362 g1PerLayer[region] = new TH1F(Form("g1_%s", tag), Form("g1 %s;g1 for %s;n. strips", tag, tag), 200, 0., 2.);
0363 PedestalPerLayer[region] =
0364 new TH1F(Form("pedestal_%s", tag), Form("pedestal %s;pedestal for %s;n. strips", tag, tag), 350, 0., 350.);
0365
0366 h_avgPedestal->GetXaxis()->SetBinLabel(region, tag);
0367 h_avgIdealNoiseRatio->GetXaxis()->SetBinLabel(region, tag);
0368 h_avgNoise->GetXaxis()->SetBinLabel(region, tag);
0369 }
0370
0371
0372 for (int geometry = ModuleGeometry::IB1; geometry != ModuleGeometry::END_OF_GEOMETRIES; geometry++) {
0373 auto tag = moduleType(geometry);
0374 noiseVsG1PerModuleGeometry[geometry] = new TH2F(Form("h2_NoiseVsG1_%s", tag),
0375 Form("Noise vs G1 Gain for %s;G1 gain;Noise [ACD counts]", tag),
0376 100,
0377 0.,
0378 2.,
0379 200,
0380 0.,
0381 20.);
0382 p_noiseVsG1PerModuleGeometry[geometry] = new TProfile(
0383 Form("p_NoiseVsG1_%s", tag), Form("Noise vs G1 Gain for %s;G1 gain;Noise [ACD counts]", tag), 100, 0., 2.);
0384 }
0385
0386 uint32_t cachedDetId = -1;
0387
0388 printf("Progressing Bar :0%% 20%% 40%% 60%% 80%% 100%%\n");
0389 printf("Scanning ntuple :");
0390 int TreeStep = tree_->GetEntries() / 50;
0391 if (TreeStep == 0)
0392 TreeStep = 1;
0393 for (Int_t stripNo = 0; stripNo < nentries; stripNo++) {
0394 if (stripNo % TreeStep == 0) {
0395 printf(".");
0396 fflush(stdout);
0397 }
0398 Int_t IgetStrip = tree_->GetEntry(stripNo);
0399 auto region = getTheRegionFromTopology(subdetId_, side_, layer_);
0400
0401 h2_NoiseVsPedestal->Fill(pedestal_, noise_);
0402 h2_NoiseVsG1->Fill(g1_, noise_);
0403
0404 switch (subdetId_) {
0405 case 3:
0406 h2_NoiseVsPedestalTIB->Fill(pedestal_, noise_);
0407 break;
0408 case 5:
0409 h2_NoiseVsPedestalTOB->Fill(pedestal_, noise_);
0410 break;
0411 case 4:
0412 h2_NoiseVsPedestalTID->Fill(pedestal_, noise_);
0413 break;
0414 case 6:
0415 h2_NoiseVsPedestalTEC->Fill(pedestal_, noise_);
0416 break;
0417 default:
0418 std::cout << "shall never be here!" << std::endl;
0419 }
0420
0421 h_Pedestal->Fill(pedestal_);
0422 h_idealNoiseRatio->Fill(noise_ / g1_);
0423 h_Noise->Fill(noise_);
0424 h_g1->Fill(g1_);
0425
0426 PedestalPerLayer[region]->Fill(pedestal_);
0427 idealNoiseRatioPerLayer[region]->Fill(noise_ / g1_);
0428 NoisePerLayer[region]->Fill(noise_);
0429 g1PerLayer[region]->Fill(g1_);
0430
0431 noiseVsG1PerModuleGeometry[det_type_]->Fill(g1_, noise_);
0432 p_noiseVsG1PerModuleGeometry[det_type_]->Fill(g1_, noise_);
0433
0434
0435 if (detId_ != cachedDetId) {
0436
0437
0438 cachedDetId = detId_;
0439 }
0440 }
0441 printf("\n");
0442
0443 for (int region = TrackerRegion::TIB1; region != TrackerRegion::END_OF_REGIONS; region++) {
0444 h_avgIdealNoiseRatio->SetBinContent(region, idealNoiseRatioPerLayer[region]->GetMean());
0445 h_avgNoise->SetBinContent(region, NoisePerLayer[region]->GetMean());
0446 h_avgPedestal->SetBinContent(region, PedestalPerLayer[region]->GetMean());
0447 }
0448
0449 TFile* outfile = TFile::Open(Form("idealNoise_%s.root", (s->GetString()).Data()), "RECREATE");
0450 outfile->cd();
0451 h_Pedestal->Write();
0452 h_idealNoiseRatio->Write();
0453 h_Noise->Write();
0454 h2_NoiseVsG1->Write();
0455 h2_NoiseVsPedestal->Write();
0456 h_g1->Write();
0457
0458 h_avgPedestal->Write();
0459 h_avgIdealNoiseRatio->Write();
0460 h_avgNoise->Write();
0461
0462 TDirectory* byPartition = outfile->mkdir("ByPartition");
0463 byPartition->cd();
0464 h2_NoiseVsPedestalTIB->Write();
0465 h2_NoiseVsPedestalTOB->Write();
0466 h2_NoiseVsPedestalTID->Write();
0467 h2_NoiseVsPedestalTEC->Write();
0468
0469 TDirectory* cdIdealNoise = outfile->mkdir("idealNoise");
0470 cdIdealNoise->cd();
0471 for (int region = TrackerRegion::TIB1; region != TrackerRegion::END_OF_REGIONS; region++) {
0472 auto tag = regionType(region);
0473 idealNoiseRatioPerLayer[region]->Write();
0474 }
0475
0476 outfile->cd();
0477 TDirectory* cdNoise = outfile->mkdir("Noise");
0478 cdNoise->cd();
0479 for (int region = TrackerRegion::TIB1; region != TrackerRegion::END_OF_REGIONS; region++) {
0480 auto tag = regionType(region);
0481 NoisePerLayer[region]->Write();
0482 }
0483
0484 outfile->cd();
0485 TDirectory* cdG1 = outfile->mkdir("g1");
0486 cdG1->cd();
0487 for (int region = TrackerRegion::TIB1; region != TrackerRegion::END_OF_REGIONS; region++) {
0488 auto tag = regionType(region);
0489 g1PerLayer[region]->Write();
0490 }
0491
0492 outfile->cd();
0493 TDirectory* cNoiseVsG1 = outfile->mkdir("tickmark_vs_noise");
0494 cNoiseVsG1->cd();
0495 for (int geometry = ModuleGeometry::IB1; geometry != ModuleGeometry::END_OF_GEOMETRIES; geometry++) {
0496 noiseVsG1PerModuleGeometry[geometry]->Write();
0497 p_noiseVsG1PerModuleGeometry[geometry]->Write();
0498 }
0499
0500 outfile->Close();
0501 tree_->Delete();
0502 return;
0503 }