File indexing completed on 2026-04-07 08:08:32
0001 #ifndef __AN_NEUTRAL_MESON_MICRO_DST_H__
0002 #define __AN_NEUTRAL_MESON_MICRO_DST_H__
0003
0004 #include <fun4all/SubsysReco.h>
0005 #include <cmath>
0006 #include <algorithm>
0007 #include <vector>
0008 #include <map>
0009 #include <queue>
0010 #include <Math/Vector3D.h>
0011 #include <Math/Vector4D.h>
0012 #include <globalvertex/GlobalVertexMap.h>
0013 #include "ClusterSmallInfoContainer.h"
0014
0015 #include <calobase/RawTowerGeomContainer.h>
0016
0017 #include <ffaobjects/SyncDefs.h>
0018 #include <ffaobjects/SyncObject.h>
0019
0020
0021 #include <triggeremulator/TriggerTile.h>
0022
0023
0024 class PHCompositeNode;
0025 class TFile;
0026 class TTree;
0027 class TH1;
0028 class TH1F;
0029 class TH1I;
0030 class TH2F;
0031 class LorentzVector;
0032
0033 void monitorMemoryUsage(const std::string& label="");
0034
0035 class AnNeutralMeson_micro_dst : public SubsysReco
0036 {
0037 public:
0038
0039 AnNeutralMeson_micro_dst(const std::string &name = "AnNeutralMeson_micro_dst",
0040 const int runnb = 48746,
0041 const std::string &outputfilename = "analysis_per_run/analysis_48746.root",
0042 const std::string &outputfiletreename = "analysis_per_run/diphoton_minimal_48746.root");
0043
0044
0045 virtual ~AnNeutralMeson_micro_dst();
0046
0047
0048 int Init(PHCompositeNode *);
0049
0050 int InitRun(PHCompositeNode *);
0051
0052
0053 int process_event(PHCompositeNode *);
0054
0055
0056 int End(PHCompositeNode *);
0057
0058 int FindBinBinary(float val, const float* binEdges, int nBins)
0059 {
0060 const float *it = std::upper_bound(binEdges, binEdges + nBins, val);
0061 int ibin = static_cast<int>(it - binEdges) -1;
0062 return ibin;
0063 }
0064
0065 int FindClosestValFromVector(float val, const float* binValues, int nBins)
0066 {
0067 const float *it = std::upper_bound(binValues, binValues + nBins, val);
0068 int icenter = static_cast<int>(it - binValues) - 1;
0069 int iminus = std::max(0, icenter - 1);
0070 int imaxi = std::min(nBins - 1, icenter + 1);
0071 float valminus = *(binValues + iminus);
0072 float valcenter = *(binValues + icenter);
0073 float valmaxi = *(binValues + imaxi);
0074 float diffminus = std::abs(valminus - val);
0075 float diffcenter = std::abs(valcenter - val);
0076 float diffmaxi = std::abs(valmaxi - val);
0077 std::vector<float> diffs = {diffminus, diffcenter, diffmaxi};
0078 auto pos = std::min_element(diffs.begin(), diffs.end());
0079 int ipos = int(pos - diffs.begin());
0080 if (ipos == 0) return iminus;
0081 else if (ipos == 1) return icenter;
0082 else if (ipos == 2) return imaxi;
0083 return 0;
0084 }
0085
0086
0087 bool mbd_trigger_bit();
0088
0089
0090 bool photon_trigger_bit();
0091
0092
0093 void trigger_emulator_input();
0094
0095
0096 bool trigger_efficiency_matching(const ROOT::Math::PtEtaPhiMVector& photon1,
0097 const ROOT::Math::PtEtaPhiMVector& photon2,
0098 const ROOT::Math::PtEtaPhiMVector& diphoton);
0099
0100 void event_mixing_mbd(PHCompositeNode *topNode);
0101
0102 void event_mixing_photon();
0103
0104 void set_event_mixing(bool use) { use_event_mixing = use; }
0105
0106 void set_mbd_trigger_bit_requirement(bool require) { require_mbd_trigger_bit = require; }
0107
0108 void set_photon_trigger_bit_requirement(bool require) { require_photon_trigger_bit = require; }
0109
0110 void set_photon_trigger_emulator_matching_requirement(bool require) { require_emulator_matching = require; }
0111
0112 void set_photon_trigger_efficiency_matching_requirement(bool require) { require_efficiency_matching = require; }
0113
0114 void set_photon_trigger_efficiency_threshold(float efficiency_target) {
0115 efficiency_index = FindClosestValFromVector(efficiency_target, efficiency_thresholds, nThresholds);
0116 energy_threshold_3 = array_energy_threshold_3[efficiency_index];
0117 energy_threshold_4 = array_energy_threshold_4[efficiency_index];
0118 std::cout << "efficiency_index = " << efficiency_index << std::endl;
0119 std::cout << "efficiency threshold is " << efficiency_thresholds[efficiency_index] << std::endl;
0120 std::cout << "min energies = (" << energy_threshold_3 << ", " << energy_threshold_4 << ")" << std::endl;
0121 }
0122
0123 void set_vertex_max(float vtx) { vertex_max = vtx; }
0124
0125
0126 void set_chi2cut(const std::vector<float>& chi2) { chi2_cuts = chi2; n_chi2_cuts = chi2.size(); }
0127
0128
0129 void set_ecorecut(const std::vector<float>& ecore) { ecore_cuts = ecore; n_ecore_cuts = ecore.size(); }
0130
0131
0132 void set_alphacut(float alpha) { alphaCut = alpha; }
0133
0134
0135 void set_ptcut(float pTMin = 1.0, float pTMax = 1000.0)
0136 {
0137 pTCutMin = pTMin;
0138 pTCutMax = pTMax;
0139 }
0140
0141
0142 void set_pt_threshold(float pT = 0)
0143 {
0144 pTCutThreshold = pT;
0145 }
0146
0147
0148 void set_store_qa(bool val) { store_qa = val; }
0149
0150
0151 void cluster_cuts();
0152
0153
0154 bool diphoton_cut(ROOT::Math::PtEtaPhiMVector p1,
0155 ROOT::Math::PtEtaPhiMVector p2,
0156 ROOT::Math::PtEtaPhiMVector ppair);
0157
0158
0159 bool trigger_matching(const ROOT::Math::PtEtaPhiMVector&, const ROOT::Math::PtEtaPhiMVector&, const ROOT::Math::PtEtaPhiMVector&);
0160
0161 bool startswith(const std::string&, const std::string&);
0162
0163
0164 float WrapAngleDifference(const float& phi1, const float& phi2);
0165
0166 ROOT::Math::XYZVector EnergyWeightedAverageP3(const std::vector<ROOT::Math::PtEtaPhiMVector>& v4s);
0167
0168 void set_store_tree(bool does_store_tree) { store_tree = does_store_tree; }
0169
0170 struct Cluster {
0171 ROOT::Math::PtEtaPhiMVector p4;
0172 bool isTrigger = false;
0173 };
0174
0175
0176
0177 struct EventInPool {
0178 float zvtx = 1000;
0179 float eta_lead = -10;
0180 float phi_lead = -10;
0181 std::vector<Cluster> clusters;
0182 };
0183
0184 private:
0185
0186
0187 int runnumber;
0188
0189
0190 int _eventcounter;
0191
0192
0193 std::string infilename;
0194 TFile *infile;
0195 std::string treename;
0196 TTree *microDST;
0197
0198
0199 unsigned long live_trigger;
0200 unsigned long scaled_trigger;
0201 float vertex_z;
0202 int cluster_number;
0203
0204
0205 std::string outfilename;
0206 std::string outtreename;
0207 TFile *outfile = nullptr;
0208 TFile *outfile_tree = nullptr;
0209 bool store_tree = false;
0210
0211
0212 int diphoton_bunchnumber;
0213 float diphoton_vertex_z;
0214 float diphoton_mass;
0215 float diphoton_eta;
0216 float diphoton_pt;
0217 float diphoton_xf;
0218 float diphoton_phi;
0219 TTree *output_tree;
0220
0221
0222 static constexpr int nBeams = 2;
0223 const std::string beams[nBeams] = {"yellow", "blue"};
0224 static constexpr int nParticles = 2;
0225 const std::string particle[nParticles] = {"pi0", "eta"};
0226 static constexpr int nRegions = 2;
0227 const std::string regions[nRegions] = {"peak", "side"};
0228 static constexpr int nSpins = 2;
0229 const std::string spins[nSpins] = {"up", "down"};
0230
0231
0232 static constexpr int nPtBins = 9;
0233 const float pTBins[nPtBins + 1] = {1, 2, 3, 4, 5, 6, 7, 8, 10, 20};
0234
0235
0236 static constexpr int nEtaBins = 8;
0237 const float etaBins[nEtaBins + 1] = {-2.00, -1.05, -0.86, -0.61, 0.0, 0.61, 0.86, 1.05, 2.0};
0238
0239
0240 static constexpr int nXfBins = 8;
0241 const float xfBins[nXfBins + 1] = {-0.200, -0.048, -0.035, -0.022, 0.0, 0.022, 0.035, 0.048, 0.200};
0242
0243 static constexpr int nZvtxBins = 7;
0244 const float zvtxBins[nZvtxBins + 1] = {0, 10, 30, 50, 70, 100, 150, 200};
0245
0246 static constexpr int nEtaRegions = 2;
0247
0248
0249 const std::string etaRegions[nEtaRegions] = {"low", "high"};
0250 static constexpr float Vs = 200;
0251 static constexpr int nDirections = 2;
0252
0253 const std::string directions[nDirections] = {"forward", "backward"};
0254
0255
0256 const double etaThreshold = 0.35;
0257 const float beamDirection[nBeams] = {-1, 1};
0258
0259
0260 static constexpr int nBunches = 120;
0261 int crossingshift;
0262 int beamspinpat[nBeams][nBunches];
0263
0264
0265 float band_limits[nParticles * (nRegions + 1) * 2] =
0266 {0.030, 0.070,
0267 0.080, 0.199,
0268 0.209, 0.249,
0269 0.257, 0.371,
0270 0.399,0.739,
0271 0.767, 0.880};
0272
0273
0274
0275
0276 float vertex_max = 1000;
0277
0278
0279 bool require_mbd_trigger_bit = false;
0280 bool trigger_mbd_any_vtx = false;
0281 bool trigger_mbd_vtx_10 = false;
0282 bool mbd_trigger_bit_event = false;
0283 bool require_photon_trigger_bit = false;
0284 bool trigger_mbd = false;
0285 bool trigger_mbd_photon_3 = false;
0286 bool trigger_mbd_photon_4 = false;
0287 bool photon_trigger_bit_event = false;
0288
0289
0290 int n_chi2_cuts = 0;
0291 std::vector<float> chi2_cuts;
0292 std::vector<std::string> chi2_cuts_labels;
0293 int n_ecore_cuts = 0;
0294 std::vector<float> ecore_cuts;
0295 std::vector<std::string> ecore_cuts_labels;
0296
0297
0298 float alphaCut = 1.0;
0299 float pTCutMin = 1.0;
0300 float pTCutMax = 1000.0;
0301 float pTCutThreshold = 0;
0302
0303
0304 bool require_emulator_matching = false;
0305 bool emulator_match = false;
0306 int emulator_selection = 0;
0307 std::vector<int> fired_indices;
0308 int tileNumber = 0;
0309 int adc_threshold_3 = 13;
0310 int adc_threshold_4 = 17;
0311 std::map<int, std::vector<float>> emulator_energies;
0312 std::map<int, std::vector<int>> emulator_clusters;
0313 std::map<int, int> emulator_multiplicities;
0314
0315
0316 bool require_efficiency_matching = false;
0317 bool efficiency_match = false;
0318 int efficiency_index = 6;
0319 float energy_threshold_3 = 3.5;
0320 float energy_threshold_4 = 4.3;
0321
0322
0323 static constexpr int nThresholds = 10;
0324 const float efficiency_thresholds[nThresholds] = {10, 20, 30, 40, 50, 60, 70, 80, 90, 95};
0325 const float array_energy_threshold_3[nThresholds] = {2.4, 2.7, 2.9, 3.1, 3.2, 3.4, 3.5, 3.7, 4.0, 4.3};
0326 const float array_energy_threshold_4[nThresholds] = {2.9, 3.3, 3.6, 3.7, 3.9, 4.1, 4.3, 4.5, 4.9, 5.3};
0327 static constexpr float delta_eta_threshold = 0.192;
0328 static constexpr float delta_phi_threshold = 0.192;
0329
0330
0331
0332 bool store_qa = false;
0333
0334
0335 TH1I *h_emulator_selection;
0336 TH1F *h_trigger_live;
0337 TH1F *h_trigger_scaled;
0338 const std::map<unsigned int, std::string> trigger_names{
0339 {0, "Clock"}, {3, "ZDC Coincidence"}, {10, "MBD N&S >= 1"}, {12, "MBD N&S >=1, vtx < 10"}, {17, "Jet 8 GeV + MBD NS >= 1"}, {18, "Jet 10 GeV + MBD NS >= 1"}, {19, "Jet 12 GeV + MBD NS >= 1"}, {21, "Jet 8 GeV"}, {22, "Jet 10 GeV"}, {23, "Jet 12 GeV"}, {25, "Photon 3 GeV + MBD NS >= 1"}, {26, "Photon 4 GeV + MBD NS >= 1"}, {27, "Photon 5 GeV + MBD NS >= 1"}, {29, "Photon 3 Gev"}, {30, "Photon 4 Gev"}, {31, "Photon 5 Gev"}
0340 };
0341
0342
0343 TriggerTile *emcaltiles;
0344 GlobalVertexMap *vertexmap;
0345 ClusterSmallInfoContainer *_smallclusters;
0346
0347
0348 std::vector<Cluster> good_photons;
0349 int num_photons = 0;
0350
0351
0352
0353 TH1I *h_efficiency_x_matching = nullptr;
0354 TH1I *h_efficiency_x_matching_pt[nPtBins] = {nullptr};
0355
0356
0357 TH1I *h_count_diphoton_nomatch;
0358 TH1F *h_event_zvtx;
0359 TH1F *h_triggered_event_zvtx;
0360 TH1F *h_triggered_event_photons;
0361 TH1F *h_analysis_event_zvtx;
0362 TH1F *h_photon_eta;
0363 TH1F *h_photon_phi;
0364 TH1F *h_photon_pt;
0365 TH1F *h_photon_zvtx;
0366 TH2F *h_photon_eta_phi;
0367 TH2F *h_photon_eta_pt;
0368 TH2F *h_photon_eta_zvtx;
0369 TH2F *h_photon_phi_pt;
0370 TH2F *h_photon_phi_zvtx;
0371 TH2F *h_photon_pt_zvtx;
0372 TH1F *h_selected_photon_eta;
0373 TH1F *h_selected_photon_phi;
0374 TH1F *h_selected_photon_pt;
0375 TH1F *h_selected_photon_zvtx;
0376 TH2F *h_selected_photon_eta_phi;
0377 TH2F *h_selected_photon_eta_pt;
0378 TH2F *h_selected_photon_eta_zvtx;
0379 TH2F *h_selected_photon_phi_pt;
0380 TH2F *h_selected_photon_phi_zvtx;
0381 TH2F *h_selected_photon_pt_zvtx;
0382 TH1F *h_pair_eta;
0383 TH1F *h_pair_phi;
0384 TH1F *h_pair_pt;
0385 TH1F *h_pair_zvtx;
0386 TH2F *h_pair_eta_phi;
0387 TH2F *h_pair_eta_pt;
0388 TH2F *h_pair_eta_zvtx;
0389 TH2F *h_pair_phi_pt;
0390 TH2F *h_pair_phi_zvtx;
0391 TH2F *h_pair_pt_zvtx;
0392 TH1F *h_pair_E1;
0393 TH1F *h_pair_E2;
0394 TH1F *h_pair_theta_12;
0395 TH1F *h_pair_DeltaR;
0396 TH1F *h_pair_alpha;
0397 TH2F *h_pair_alpha_pt;
0398 TH1F *h_pair_pi0_eta_pt_1;
0399 TH1F *h_pair_pi0_eta_pt_2;
0400 TH1F *h_pair_pi0_eta_pt_3;
0401 TH1F *h_pair_pi0_eta_pt_4;
0402 TH1F *h_pair_pi0_eta_pt_5;
0403 TH1F *h_pair_pi0_eta_pt_6;
0404 TH1F *h_pair_pi0_eta_pt_7;
0405 TH1F *h_pair_pi0_eta_pt_8;
0406 TH1F *h_pair_pi0_eta_pt_9;
0407 TH1F *h_pair_eta_eta_pt_1;
0408 TH1F *h_pair_eta_eta_pt_2;
0409 TH1F *h_pair_eta_eta_pt_3;
0410 TH1F *h_pair_eta_eta_pt_4;
0411 TH1F *h_pair_eta_eta_pt_5;
0412 TH1F *h_pair_eta_eta_pt_6;
0413 TH1F *h_pair_eta_eta_pt_7;
0414 TH1F *h_pair_eta_eta_pt_8;
0415 TH1F *h_pair_eta_eta_pt_9;
0416 TH1F *h_pair_pi0_xf_pt_1;
0417 TH1F *h_pair_pi0_xf_pt_2;
0418 TH1F *h_pair_pi0_xf_pt_3;
0419 TH1F *h_pair_pi0_xf_pt_4;
0420 TH1F *h_pair_pi0_xf_pt_5;
0421 TH1F *h_pair_pi0_xf_pt_6;
0422 TH1F *h_pair_pi0_xf_pt_7;
0423 TH1F *h_pair_pi0_xf_pt_8;
0424 TH1F *h_pair_pi0_xf_pt_9;
0425 TH1F *h_pair_eta_xf_pt_1;
0426 TH1F *h_pair_eta_xf_pt_2;
0427 TH1F *h_pair_eta_xf_pt_3;
0428 TH1F *h_pair_eta_xf_pt_4;
0429 TH1F *h_pair_eta_xf_pt_5;
0430 TH1F *h_pair_eta_xf_pt_6;
0431 TH1F *h_pair_eta_xf_pt_7;
0432 TH1F *h_pair_eta_xf_pt_8;
0433 TH1F *h_pair_eta_xf_pt_9;
0434 TH1F *h_meson_pi0_pt;
0435 TH1F *h_meson_pi0_E;
0436 TH1F *h_meson_eta_pt;
0437 TH1F *h_meson_eta_E;
0438
0439 TH1F *h_photon_fired;
0440 TH1F *h_photon_fired_scale;
0441
0442
0443 TH2F *h_cluster_level_cuts_total;
0444 TH2F *h_cluster_level_cuts_particle[nParticles][nRegions];
0445 TH2F *h_cluster_level_cuts_total_pt[nPtBins];
0446 TH2F *h_cluster_level_cuts_particle_pt[nParticles][nRegions][nPtBins];
0447
0448
0449 TH1F* h_average_pt[nParticles];
0450 TH1F* h_average_eta[nParticles];
0451 TH1F* h_average_xf[nParticles];
0452 TH1F* h_norm_pt[nParticles];
0453 TH1F* h_norm_eta[nParticles];
0454 TH1F* h_norm_xf[nParticles];
0455
0456
0457 TH1F *h_pair_mass;
0458 TH1F *h_pair_mass_pt[nPtBins];
0459 TH1F *h_pair_mass_zvtx[nZvtxBins];
0460 TH1F *h_pair_mass_eta[nEtaBins];
0461 TH1F *h_pair_mass_xf[nXfBins];
0462 TH1F *h_pair_mass_mixing;
0463 TH1F *h_pair_mass_mixing_pt[nPtBins];
0464
0465
0466 TH1F *h_yield_1[nBeams][nParticles][nRegions][nPtBins][nEtaRegions][nSpins];
0467 TH1F *h_yield_2[nBeams][nParticles][nRegions][nPtBins][nDirections][nSpins];
0468 TH1F *h_yield_3[nBeams][nParticles][nRegions][nPtBins][nEtaRegions][nDirections][nSpins];
0469
0470
0471 TH1F *h_yield_eta[nBeams][nParticles][nRegions][nEtaBins][nSpins];
0472
0473
0474 TH1F *h_yield_xf[nBeams][nParticles][nRegions][nXfBins][nSpins];
0475
0476 TH1F *h_multiplicity_efficiency;
0477 TH1F *h_multiplicity_emulator;
0478 TH1F *h_matching_consistency;
0479
0480
0481 RawTowerGeomContainer *towergeom;
0482 static constexpr double radius = 103;
0483
0484 int count_1 = 0;
0485 int count_2 = 0;
0486 int count_3 = 0;
0487 int count_4 = 0;
0488 int count_5 = 0;
0489 int count_yellow_pi0_peak_pt_0 = 0;
0490
0491
0492 int scaledown[64] = {0};
0493 double livetime[64] = {0};
0494 int prescale = 0;
0495
0496
0497 std::string db_name = "daq";
0498 std::string user_name = "phnxrc";
0499 std::string table_name = "gl1_scaledown";
0500
0501
0502
0503 bool use_event_mixing = false;
0504 static constexpr float dR_min = 0.034;
0505 static constexpr int nPoolZvtxBins = 10;
0506 const float poolZvtxBins[nPoolZvtxBins + 1] = {-50, -40, -30, -20, -10, 0, 10, 20, 30, 40, 50};
0507 static constexpr int nMultiplicityBins = 9;
0508 const float multiplicityBins[nMultiplicityBins + 1] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
0509 static constexpr int nPoolEtaBins = 12;
0510 const float poolEtaBins[nPoolEtaBins + 1] = {-1.2, -1.0, -0.8, -0.6, -0.4, -0.2, 0, 0.2, 0.4, 0.6, 0.8, 1.0, 1.2};
0511 static constexpr int Nmix = 10;
0512 std::deque<EventInPool> pool[nPoolZvtxBins][nMultiplicityBins][nPoolEtaBins];
0513
0514
0515 TH1F *h_current_E = nullptr;
0516 TH1F *h_current_eta = nullptr;
0517 TH1F *h_current_phi = nullptr;
0518 TH1F *h_pool_E = nullptr;
0519 TH1F *h_pool_eta = nullptr;
0520 TH1F *h_pool_phi = nullptr;
0521
0522 TH1F *h_same_delta_eta = nullptr;
0523 TH1F *h_same_delta_phi = nullptr;
0524 TH1F *h_same_delta_R = nullptr;
0525 TH1F *h_same_alpha = nullptr;
0526 TH1F *h_mixed_delta_eta = nullptr;
0527 TH1F *h_mixed_delta_phi = nullptr;
0528 TH1F *h_mixed_delta_R = nullptr;
0529 TH1F *h_mixed_alpha = nullptr;
0530
0531 SyncObject *syncobject{nullptr};
0532 };
0533
0534 #endif