Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Fun4All_RunCorrelatorJetTreeOnCondor.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Fun4All_RunCorrelatorJetTreeOnCondor.C
1 // ----------------------------------------------------------------------------
2 // 'Fun4All_RunCorrelatorJetTreeOnCondor.C'
3 // Derek Anderson
4 // 01.06.2023
5 //
6 // Use this to run the SCorrelatorJetTree
7 // class via Condor.
8 //
9 // Derived from code by Cameron Dean and
10 // Antonio Silva (thanks!!)
11 //
12 // NOTE: jetType sets whether or not jets
13 // are full (charge + neutral) or charged
14 // jetType = 0: charged jets
15 // jetType = 1: full jets
16 // ----------------------------------------------------------------------------
17 
18 /****************************/
19 /* MDC2 Reco for MDC2 */
20 /* Cameron Dean, LANL, 2021 */
21 /* cdean@bnl.gov */
22 /****************************/
23 
24 // standard c includes
25 #include <vector>
26 #include <string>
27 #include <cstdlib>
28 #include <utility>
29 // f4a/sphenix includes
30 #include <FROG.h>
31 #include <G4_Magnet.C>
34 // tracking includes
35 #include <Trkr_QA.C>
36 #include <Trkr_Reco.C>
37 #include <Trkr_Eval.C>
38 #include <Trkr_RecoInit.C>
39 #include <Trkr_Clustering.C>
40 #include <Trkr_Diagnostics.C>
41 #include <G4_TrkrSimulation.C>
42 #include <g4eval/SvtxEvaluator.h>
44 // calo/pf includes
45 #include <caloreco/RawClusterBuilderTopo.h>
46 #include <particleflowreco/ParticleFlowReco.h>
47 // user includes
48 #include "/sphenix/user/danderson/install/include/scorrelatorjettree/SCorrelatorJetTree.h"
49 
50 // load libraries
51 R__LOAD_LIBRARY(libg4eval.so)
52 R__LOAD_LIBRARY(libfun4all.so)
53 R__LOAD_LIBRARY(libcalo_reco.so)
54 R__LOAD_LIBRARY(libparticleflow.so)
55 R__LOAD_LIBRARY(/sphenix/user/danderson/install/lib/libscorrelatorjettree.so)
56 
57 using namespace std;
58 using namespace SColdQcdCorrelatorAnalysis;
59 
60 // global constants
61 static const string SInListDefault = "test.list";
62 static const string SOutDirDefault = "/sphenix/user/danderson/eec/SCorrelatorJetTree/submit/ppJet10GeV/output";
63 static const string SRecoNameDefault = "CorrelatorJetTree";
64 static const int NEvtDefault = 10;
65 static const int VerbDefault = 0;
66 static const unsigned int NTopoClusts = 2;
67 static const unsigned int NTopoPar = 3;
68 static const unsigned int NAccept = 2;
69 
70 
71 
72 void Fun4All_RunCorrelatorJetTreeOnCondor(vector<string> sInputLists = {SInListDefault}, const int nEvents = NEvtDefault, const int verbosity = VerbDefault) {
73 
74  // track & particle flow parameters
75  const bool doTruthTableReco(false);
76  const bool runTracking(false);
77  const double nSigma(1.5);
78 
79  // topo cluster parameters
80  const double showerR(0.025);
81  const double noiseLevels[NTopoPar] = {0.0025, 0.006, 0.03};
82  const double significance[NTopoPar] = {4.0, 2.0, 0.0};
83  const double localMinE[NTopoPar] = {1.0, 2.0, 0.5};
84  const bool enableHCal[NTopoClusts] = {false, true};
85  const bool enableECal[NTopoClusts] = {true, false};
86  const bool doSplit(true);
87  const bool allowCorners(true);
88 
89  // jet tree general parameters
90  const bool isMC(true);
91  const bool isEmbed(false);
92  const bool doDebug(false);
93  const bool saveDst(true);
94  const bool doVtxCut(false);
95  const bool doQuality(true);
96  const bool requireSiSeeds(true);
97  const bool useOnlyPrimVtx(true);
98  const bool doDcaSigmaCut(false);
99  const bool checkWeirdTrks(false);
100  const bool maskTpcSectors(false);
101  const bool addTracks(true);
102  const bool addECal(false);
103  const bool addHCal(false);
104  const bool addParticleFlow(false);
105 
106  // jet tree jet parameters
107  const double jetRes = 0.4;
108  const unsigned int jetType = 0;
109  const auto jetAlgo = SCorrelatorJetTree::ALGO::ANTIKT;
110  const auto jetReco = SCorrelatorJetTree::RECOMB::PT_SCHEME;
111 
112  // event acceptance
113  const pair<double, double> vzEvtRange = {-10., 10.};
114  const pair<double, double> vrEvtRange = {0.0, 0.418};
115 
116  // particle acceptance
117  const pair<double, double> ptParRange = {0., 9999.};
118  const pair<double, double> etaParRange = {-1.1, 1.1};
119 
120  // track acceptance
121  const pair<double, double> ptTrackRange = {0.2, 100.};
122  const pair<double, double> etaTrackRange = {-1.1, 1.1};
123  const pair<double, double> qualTrackRange = {0., 10.};
124  const pair<double, double> nMvtxTrackRange = {2., 100.};
125  const pair<double, double> nInttTrackRange = {1., 100.};
126  const pair<double, double> nTpcTrackRange = {33., 100.};
127  const pair<double, double> dcaTrackRangeXY = {-0.06, 0.06};
128  const pair<double, double> dcaTrackRangeZ = {-0.20, 0.20};
129  const pair<double, double> deltaPtTrackRange = {0., 0.04};
130 
131  // for pt dependent dca cuts
132  const pair<double, double> dcaPtFitMax = {15., 15.};
133  const pair<double, double> nDcaSigmaTrack = {3., 3.};
134  const vector<double> dcaSigmaParamsXY = {-0.0095, 0.091, -0.029};
135  const vector<double> dcaSigmaParamsZ = {1.73, 26.1, -9.45};
136 
137  // particle flow acceptance
138  const pair<double, double> ptFlowRange = {0.2, 9999.};
139  const pair<double, double> etaFlowRange = {-1.1, 1.1};
140 
141  // calo acceptance
142  const pair<double, double> ptECalRange = {0.3, 9999.};
143  const pair<double, double> etaECalRange = {-1.1, 1.1};
144  const pair<double, double> ptHCalRange = {0.3, 9999.};
145  const pair<double, double> etaHCalRange = {-1.1, 1.1};
146 
147  // load libraries and create f4a server
148  gSystem -> Load("libg4dst.so");
149  gSystem -> Load("libFROG.so");
150 
151  FROG *frog = new FROG();
152  Fun4AllServer *ffaServer = Fun4AllServer::instance();
153 
154  // figure out folder revisions, file numbers, etc
155  string outDir = SOutDirDefault;
156  string recoName = SRecoNameDefault;
157  if (outDir.substr(outDir.size() - 1, 1) != "/") {
158  outDir += "/";
159  }
160  outDir += recoName + "/";
161 
162  string fileNumber = sInputLists[0];
163  size_t findLastDash = fileNumber.find_last_of("-");
164  if (findLastDash != string::npos) {
165  fileNumber.erase(0, findLastDash + 1);
166  }
167  string remove_this = ".list";
168 
169  size_t pos = fileNumber.find(remove_this);
170  if (pos != string::npos) {
171  fileNumber.erase(pos, remove_this.length());
172  }
173 
174  // create output name
175  string outputFileName = "outputData_" + recoName + "_" + fileNumber + ".root";
176  string outputRecoDir = outDir + "/inReconstruction/";
177  string makeDirectory = "mkdir -p " + outputRecoDir;
178 
179  system(makeDirectory.c_str());
180  string outputRecoFile = outputRecoDir + outputFileName;
181 
182  // add all inputs to input managers
183  for (unsigned int iMan = 0; iMan < sInputLists.size(); ++iMan) {
184  Fun4AllInputManager *inFileMan = new Fun4AllDstInputManager("DSTin_" + to_string(iMan));
185  inFileMan -> AddListFile(sInputLists[iMan]);
186  ffaServer -> registerInputManager(inFileMan);
187  }
188 
189  // run the tracking if not already done
190  if (runTracking) {
191 
192  // enable mms
193  Enable::MICROMEGAS = true;
194 
195  // initialize magnetic field
197  MagnetInit();
198  MagnetFieldInit();
199 
200  // initialize tracker cells
201  Mvtx_Cells();
202  Intt_Cells();
203  TPC_Cells();
205 
206  // initialize tracking
207  TrackingInit();
208 
209  // do tracker clustering & reconstruction
210  Mvtx_Clustering();
211  Intt_Clustering();
212  TPC_Clustering();
214  Tracking_Reco();
215  }
216 
217  // construct track/truth table
218  if (doTruthTableReco) {
220  tables -> Verbosity(verbosity);
221  if (runTracking) {
222  ffaServer -> registerSubsystem(tables);
223  }
224  }
225 
226  // if using particle flow, run pf reconstruction
227  if (addParticleFlow) {
228 
229  // build topo clusters
230  RawClusterBuilderTopo* ecalClusterBuilder = new RawClusterBuilderTopo("EcalRawClusterBuilderTopo");
231  ecalClusterBuilder -> Verbosity(verbosity);
232  ecalClusterBuilder -> set_nodename("TOPOCLUSTER_EMCAL");
233  ecalClusterBuilder -> set_enable_HCal(enableHCal[0]);
234  ecalClusterBuilder -> set_enable_EMCal(enableECal[0]);
235  ecalClusterBuilder -> set_noise(noiseLevels[0], noiseLevels[1], noiseLevels[2]);
236  ecalClusterBuilder -> set_significance(significance[0], significance[1], significance[2]);
237  ecalClusterBuilder -> allow_corner_neighbor(allowCorners);
238  ecalClusterBuilder -> set_do_split(doSplit);
239  ecalClusterBuilder -> set_minE_local_max(localMinE[0], localMinE[1], localMinE[2]);
240  ecalClusterBuilder -> set_R_shower(showerR);
241  ffaServer -> registerSubsystem(ecalClusterBuilder);
242 
243  RawClusterBuilderTopo* hcalClusterBuilder = new RawClusterBuilderTopo("HcalRawClusterBuilderTopo");
244  hcalClusterBuilder -> Verbosity(verbosity);
245  hcalClusterBuilder -> set_nodename("TOPOCLUSTER_HCAL");
246  hcalClusterBuilder -> set_enable_HCal(enableHCal[1]);
247  hcalClusterBuilder -> set_enable_EMCal(enableECal[1]);
248  hcalClusterBuilder -> set_noise(noiseLevels[0], noiseLevels[1], noiseLevels[2]);
249  hcalClusterBuilder -> set_significance(significance[0], significance[1], significance[1]);
250  hcalClusterBuilder -> allow_corner_neighbor(allowCorners);
251  hcalClusterBuilder -> set_do_split(doSplit);
252  hcalClusterBuilder -> set_minE_local_max(localMinE[0], localMinE[1], localMinE[2]);
253  hcalClusterBuilder -> set_R_shower(showerR);
254  ffaServer -> registerSubsystem(hcalClusterBuilder);
255 
256  // do particle flow
257  ParticleFlowReco *parFlowReco = new ParticleFlowReco();
258  parFlowReco -> set_energy_match_Nsigma(nSigma);
259  parFlowReco -> Verbosity(verbosity);
260  ffaServer -> registerSubsystem(parFlowReco);
261  }
262 
263  // create correlator jet tree
264  SCorrelatorJetTree *correlatorJetTree = new SCorrelatorJetTree("SCorrelatorJetTree", outputRecoFile, isMC, isEmbed, doDebug);
265  correlatorJetTree -> Verbosity(verbosity);
266  correlatorJetTree -> SetDoVertexCut(doVtxCut);
267  correlatorJetTree -> SetDoQualityPlots(doQuality);
268  correlatorJetTree -> SetAddTracks(addTracks);
269  correlatorJetTree -> SetAddFlow(addParticleFlow);
270  correlatorJetTree -> SetAddECal(addECal);
271  correlatorJetTree -> SetAddHCal(addHCal);
272  correlatorJetTree -> SetEvtVzRange(vzEvtRange);
273  correlatorJetTree -> SetEvtVrRange(vrEvtRange);
274  if (isMC) {
275  correlatorJetTree -> SetParPtRange(ptParRange);
276  correlatorJetTree -> SetParEtaRange(etaParRange);
277  }
278  if (addTracks) {
279  correlatorJetTree -> SetRequireSiSeeds(requireSiSeeds);
280  correlatorJetTree -> SetUseOnlyPrimVtx(useOnlyPrimVtx);
281  correlatorJetTree -> SetMaskTpcSectors(maskTpcSectors);
282  correlatorJetTree -> SetCheckWeirdTrks(checkWeirdTrks);
283  correlatorJetTree -> SetTrackPtRange(ptTrackRange);
284  correlatorJetTree -> SetTrackEtaRange(etaTrackRange);
285  correlatorJetTree -> SetTrackQualityRange(qualTrackRange);
286  correlatorJetTree -> SetTrackNMvtxRange(nMvtxTrackRange);
287  correlatorJetTree -> SetTrackNInttRange(nInttTrackRange);
288  correlatorJetTree -> SetTrackNTpcRange(nTpcTrackRange);
289  correlatorJetTree -> SetTrackDcaRangeXY(dcaTrackRangeXY);
290  correlatorJetTree -> SetTrackDcaRangeZ(dcaTrackRangeZ);
291  correlatorJetTree -> SetTrackDeltaPtRange(deltaPtTrackRange);
292  if (doDcaSigmaCut) {
293  correlatorJetTree -> SetTrackDcaSigmaParameters(doDcaSigmaCut, dcaPtFitMax, nDcaSigmaTrack, dcaSigmaParamsXY, dcaSigmaParamsZ);
294  }
295  }
296  if (addParticleFlow) {
297  correlatorJetTree -> SetFlowPtRange(ptFlowRange);
298  correlatorJetTree -> SetFlowEtaRange(etaFlowRange);
299  }
300  if (addECal) {
301  correlatorJetTree -> SetECalPtRange(ptECalRange);
302  correlatorJetTree -> SetECalEtaRange(etaECalRange);
303  }
304  if (addHCal) {
305  correlatorJetTree -> SetHCalPtRange(ptHCalRange);
306  correlatorJetTree -> SetHCalEtaRange(etaHCalRange);
307  }
308  correlatorJetTree -> SetJetParameters(jetRes, jetType, jetAlgo, jetReco);
309  correlatorJetTree -> SetSaveDST(saveDst);
310  ffaServer -> registerSubsystem(correlatorJetTree);
311 
312  // move output and clean up logs
313  ifstream file(outputRecoFile.c_str());
314  if (file.good()) {
315  string moveOutput = "mv " + outputRecoFile + " " + outDir;
316  system(moveOutput.c_str());
317  } else {
318  string rmOutput = "rm " + outDir + "CorrelatorJetTree_" + fileNumber + ".root";
319  string rmLog = "rm /sphenix/user/danderson/eec/submit/logs/" + fileNumber + ".*";
320  system(rmOutput.c_str());
321  system(rmLog.c_str());
322  }
323 
324  // run reconstruction & close f4a
325  ffaServer -> run(nEvents);
326  ffaServer -> End();
327  delete ffaServer;
328 
329  // announce end & exit
330  gSystem -> Exit(0);
331  return;
332 
333 }
334 
335 // end ------------------------------------------------------------------------