File indexing completed on 2024-11-15 09:00:24
0001
0002
0003
0004 #pragma once
0005
0006 #include <stdlib.h>
0007 #include <stdio.h>
0008 #include <string>
0009 #include <iostream>
0010 #include <sstream>
0011 #include <fstream>
0012 #include <vector>
0013 #include <map>
0014 #include <set>
0015 #include <stdexcept>
0016 #include <functional>
0017 #include <fmt/format.h>
0018
0019
0020 #include <TChain.h>
0021 #include <TObjArray.h>
0022 #include <TFile.h>
0023 #include <TRegexp.h>
0024
0025
0026 #include <adage/BinSet.h>
0027
0028
0029 #include "DataModel.h"
0030 #include "Histos.h"
0031 #include "HistosDAG.h"
0032 #include "Kinematics.h"
0033 #ifndef EXCLUDE_DELPHES
0034 #include "KinematicsJets.h"
0035 #endif
0036 #include "SidisTree.h"
0037 #include "HFSTree.h"
0038 #include "ParticleTree.h"
0039 #include "Weights.h"
0040 #include "CommonConstants.h"
0041
0042 class Analysis
0043 {
0044 public:
0045 Analysis(
0046 TString configFileName_="",
0047 TString outfilePrefix_=""
0048 );
0049 ~Analysis();
0050
0051
0052 const Int_t NBINS = 50;
0053 const Int_t NBINS_FULL = 10;
0054
0055
0056 void AddBinScheme(TString varname);
0057 BinSet *BinScheme(TString varname);
0058 std::map<TString,BinSet*> GetBinSchemes() { return binSchemes; };
0059
0060
0061 void AddFinalState(TString finalStateN);
0062
0063
0064 Bool_t verbose;
0065 Bool_t writeSidisTree;
0066 Bool_t writeHFSTree;
0067 Bool_t writeParticleTree;
0068 Long64_t maxEvents;
0069
0070
0071 Bool_t useBreitJets;
0072
0073 void SetReconMethod(TString reconMethod_) { reconMethod=reconMethod_; };
0074
0075 std::map<TString,Bool_t> includeOutputSet;
0076
0077 Long64_t errorCntMax;
0078
0079
0080 int jetAlg;
0081 double jetRad, jetMin;
0082 double jetMatchDR;
0083
0084
0085
0086 void AddFileGroup(
0087 std::vector<std::string> fileNames,
0088 Long64_t totalEntries,
0089 Double_t xs,
0090 Double_t Q2min,
0091 Double_t Q2max,
0092 Double_t manualWeight
0093 );
0094
0095
0096 std::shared_ptr<HistosDAG> GetHistosDAG() { return HD; };
0097
0098
0099 Double_t GetEventQ2Weight(Double_t Q2, Int_t guess=0);
0100
0101 void CalculateEventQ2Weights();
0102
0103 Int_t GetEventQ2Idx(Double_t Q2, Int_t guess=0);
0104
0105
0106 virtual void Execute() = 0;
0107
0108 protected:
0109
0110
0111
0112
0113 void Prepare();
0114
0115
0116 void Finish();
0117
0118
0119 void ErrorPrint(std::string message);
0120
0121
0122 void FillHistosInclusive(Double_t wgt);
0123 void FillHistos1h(Double_t wgt);
0124 void FillHistosJets(Double_t wgt);
0125
0126
0127 std::unique_ptr<SidisTree> ST;
0128 std::unique_ptr<HFSTree> HFST;
0129 std::unique_ptr<ParticleTree> PT;
0130 std::shared_ptr<Kinematics> kin, kinTrue;
0131 #ifndef EXCLUDE_DELPHES
0132 std::shared_ptr<KinematicsJets> kinJet, kinJetTrue;
0133 #endif
0134 std::shared_ptr<HistosDAG> HD;
0135 std::unique_ptr<Weights> weightInclusive, weightTrack, weightJet;
0136 Double_t wInclusiveTotal, wTrackTotal, wJetTotal;
0137 Long64_t entriesTot;
0138 Long64_t errorCnt;
0139 const TString sep = "--------------------------------------------";
0140
0141
0142 std::vector<std::vector<std::string> > infiles;
0143
0144 std::vector<std::size_t> inLookup;
0145 std::vector<Double_t> Q2xsecs;
0146 std::vector<Double_t> Q2mins;
0147 std::vector<Double_t> Q2maxs;
0148 std::vector<Long64_t> Q2entries;
0149 std::vector<Double_t> Q2weights;
0150 std::vector<int> total_events = {0};
0151 TString configFileName,outfileName,outfilePrefix;
0152 TFile *outFile;
0153 Double_t eleBeamEn;
0154 Double_t ionBeamEn;
0155 Double_t crossingAngle;
0156 Double_t totalCrossSection;
0157 TString reconMethod;
0158
0159
0160 Long64_t ENT;
0161 Double_t eleP,maxEleP;
0162 Double_t elePtrue, maxElePtrue;
0163 int pid;
0164 TString finalStateID;
0165
0166 #ifndef EXCLUDE_DELPHES
0167 fastjet::PseudoJet jet;
0168 #endif
0169
0170
0171 std::map<TString,TString> availableBinSchemes;
0172 std::map<TString,BinSet*> binSchemes;
0173 std::map<TString,TString> reconMethodToTitle;
0174 std::map<TString,TString> finalStateToTitle;
0175 std::map<int,TString> PIDtoFinalState;
0176 std::set<TString> activeFinalStates;
0177
0178
0179 template<class T> bool InQ2Range(T val, T min, T max, bool ignoreZero=false) {
0180 if (ignoreZero && !(val>0)) return true;
0181 if (max>0.0) return val>=min && val<=max;
0182 else return val>=min;
0183 }
0184
0185
0186
0187 template<class O> void PrintStdVector(std::vector<O> vec, std::string name="") {
0188 if(name!="") fmt::print("{}: ",name);
0189 fmt::print("[ ");
0190 for(const auto elem : vec) fmt::print("{}, ",elem);
0191 fmt::print("]\n");
0192 }
0193 template<class O> void PrintStdVector2D(std::vector<std::vector<O>> vec, std::string name="") {
0194 if(name!="") fmt::print("{} = ",name);
0195 fmt::print("[\n");
0196 for(const auto elem : vec) PrintStdVector(elem," ");
0197 fmt::print("]\n");
0198 }
0199 template<class K, class V> void PrintStdMap(std::map<K,V> hash, std::string name="") {
0200 if(name!="") fmt::print("{} = ",name);
0201 fmt::print("{{\n");
0202 for(const auto [key,val] : hash) fmt::print(" {} => {},\n",key,val);
0203 fmt::print("}}\n");
0204 }
0205
0206 private:
0207
0208
0209 void FillHistos(std::function<void(Histos*)> fill_payload);
0210
0211 ClassDef(Analysis,1);
0212 };