Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DEventWriterROOT.cc
Go to the documentation of this file.
1 #include "DEventWriterROOT.h"
2 
3 static bool BCAL_VERBOSE_OUTPUT = false;
4 static bool FCAL_VERBOSE_OUTPUT = false;
5 static bool DIRC_OUTPUT = true;
6 
7 void DEventWriterROOT::Initialize(JEventLoop* locEventLoop)
8 {
14  dThrownTreeInterface = NULL;
15 
16  locEventLoop->GetSingle(dAnalysisUtilities);
17 
18  auto locReactions = DAnalysis::Get_Reactions(locEventLoop);
19 
20  //CREATE & INITIALIZE ANALYSIS ACTIONS
21  for(size_t loc_i = 0; loc_i < locReactions.size(); ++loc_i)
22  {
23  if(!locReactions[loc_i]->Get_EnableTTreeOutputFlag())
24  continue;
25 
26  dCutActionMap_ThrownTopology[locReactions[loc_i]] = new DCutAction_ThrownTopology(locReactions[loc_i], true);
27  dCutActionMap_ThrownTopology[locReactions[loc_i]]->Initialize(locEventLoop);
28 
29  dCutActionMap_TrueCombo[locReactions[loc_i]] = new DCutAction_TrueCombo(locReactions[loc_i], -1.0, true);
30  dCutActionMap_TrueCombo[locReactions[loc_i]]->Initialize(locEventLoop);
31 
32  dCutActionMap_BDTSignalCombo[locReactions[loc_i]] = new DCutAction_BDTSignalCombo(locReactions[loc_i], 5.73303E-7, true, true); //+/- 5sigma
33  dCutActionMap_BDTSignalCombo[locReactions[loc_i]]->Initialize(locEventLoop);
34  }
35 
36  //CREATE TREES
37  vector<const DMCThrown*> locMCThrowns;
38  locEventLoop->Get(locMCThrowns);
39 
40  vector<const DReactionVertexInfo*> locVertexInfos;
41  locEventLoop->Get(locVertexInfos);
42 
43  //Get Target Center Z
44  DApplication* locApplication = dynamic_cast<DApplication*>(locEventLoop->GetJApplication());
45  DGeometry* locGeometry = locApplication->GetDGeometry(locEventLoop->GetJEvent().GetRunNumber());
46  dTargetCenterZ = 65.0;
47  locGeometry->GetTargetZ(dTargetCenterZ);
48 
49  //CREATE TTREES
50  for(auto& locVertexInfo : locVertexInfos)
51  {
52  auto locVertexReactions = locVertexInfo->Get_Reactions();
53  for(auto& locReaction : locVertexReactions)
54  {
55  dVertexInfoMap.emplace(locReaction, locVertexInfo);
56  if(locReaction->Get_EnableTTreeOutputFlag())
57  Create_DataTree(locReaction, locEventLoop, !locMCThrowns.empty());
58  }
59  }
60 }
61 
63 {
64  //Delete tree interface objects
65  for(auto& locMapPair : dTreeInterfaceMap)
66  delete locMapPair.second;
67  if(dThrownTreeInterface != NULL)
68  delete dThrownTreeInterface;
69 
70  for(auto& locMapPair : dTreeFillDataMap)
71  delete locMapPair.second;
72 
73  //Delete actions
74  for(auto& locMapPair : dCutActionMap_ThrownTopology)
75  delete locMapPair.second;
76  for(auto& locMapPair : dCutActionMap_TrueCombo)
77  delete locMapPair.second;
78  for(auto& locMapPair : dCutActionMap_BDTSignalCombo)
79  delete locMapPair.second;
80 }
81 
82 void DEventWriterROOT::Create_ThrownTree(JEventLoop* locEventLoop, string locOutputFileName) const
83 {
84  if(dThrownTreeInterface != nullptr)
85  return; //Already setup for this thread!
86  dThrownTreeInterface = DTreeInterface::Create_DTreeInterface("Thrown_Tree", locOutputFileName); //set up this thread
88  return; //branches already created: return
89 
90  //TTREE BRANCHES
91  DTreeBranchRegister locBranchRegister;
92 
93  //Get target PID
94  const DMCReaction* locMCReaction = NULL;
95  locEventLoop->GetSingle(locMCReaction);
96  Particle_t locTargetPID = locMCReaction->target.PID();
97 
98  //setup target info
99  Create_UserTargetInfo(locBranchRegister, locTargetPID);
100 
101  //create basic/misc. tree branches (run#, event#, etc.)
102  locBranchRegister.Register_Single<UInt_t>("RunNumber");
103  locBranchRegister.Register_Single<ULong64_t>("EventNumber");
104 
105  //Thrown Data
106  Create_Branches_Thrown(locBranchRegister, true);
107 
108  //CUSTOM
109  Create_CustomBranches_ThrownTree(locBranchRegister, locEventLoop);
110 
111  //CREATE BRANCHES
112  dThrownTreeInterface->Create_Branches(locBranchRegister);
113  dThrownTreeInterface->Set_TreeIndexBranchNames("RunNumber", "EventNumber");
114 }
115 
116 void DEventWriterROOT::Create_DataTree(const DReaction* locReaction, JEventLoop* locEventLoop, bool locIsMCDataFlag)
117 {
118  string locReactionName = locReaction->Get_ReactionName();
119  string locOutputFileName = locReaction->Get_TTreeOutputFileName();
120  string locTreeName = locReactionName + string("_Tree");
121 
122  //create fill object
123  dTreeFillDataMap[locReaction] = new DTreeFillData();
124 
125  //create tree interface
126  DTreeInterface* locTreeInterface = DTreeInterface::Create_DTreeInterface(locTreeName, locOutputFileName);
127  dTreeInterfaceMap[locReaction] = locTreeInterface;
128  if(locTreeInterface->Get_BranchesCreatedFlag())
129  return; //branches already created, then return
130 
131  //Branch register
132  DTreeBranchRegister locBranchRegister;
133 
134  //fill maps
135  TMap* locPositionToNameMap = Create_UserInfoMaps(locBranchRegister, locEventLoop, locReaction);
136 
137 /******************************************************************** Create Branches ********************************************************************/
138 
139  //create basic/misc. tree branches (run#, event#, etc.)
140  locBranchRegister.Register_Single<UInt_t>("RunNumber");
141  locBranchRegister.Register_Single<ULong64_t>("EventNumber");
142  locBranchRegister.Register_Single<UInt_t>("L1TriggerBits");
143 
144  //create X4_Production
145  locBranchRegister.Register_Single<TLorentzVector>("X4_Production");
146 
147  //create thrown branches
148  if(locIsMCDataFlag)
149  {
150  Create_Branches_Thrown(locBranchRegister, false);
151  locBranchRegister.Register_Single<Bool_t>("IsThrownTopology");
152  }
153 
154  bool locBeamUsedFlag = DAnalysis::Get_IsFirstStepBeam(locReaction);
155 
156  //create branches for final-state particle hypotheses
157  if(locBeamUsedFlag)
158  Create_Branches_Beam(locBranchRegister, locIsMCDataFlag);
159  Create_Branches_NeutralHypotheses(locBranchRegister, locIsMCDataFlag);
160  Create_Branches_ChargedHypotheses(locBranchRegister, locIsMCDataFlag);
161 
162  //create branches for combos
163  locBranchRegister.Register_Single<UChar_t>("NumUnusedTracks");
164  Create_Branches_Combo(locBranchRegister, locReaction, locIsMCDataFlag, locPositionToNameMap);
165 
166  //Custom branches
167  Create_CustomBranches_DataTree(locBranchRegister, locEventLoop, locReaction, locIsMCDataFlag);
168 
169  //Create branches
170  locTreeInterface->Create_Branches(locBranchRegister);
171  locTreeInterface->Set_TreeIndexBranchNames("RunNumber", "EventNumber");
172 }
173 
174 TMap* DEventWriterROOT::Create_UserInfoMaps(DTreeBranchRegister& locBranchRegister, JEventLoop* locEventLoop, const DReaction* locReaction) const
175 {
176  auto locReactionVertexInfo = dVertexInfoMap.find(locReaction)->second;
177 
178  //kinfit type
179  DKinFitType locKinFitType = locReaction->Get_KinFitType();
180 
181  //create & add reaction identification maps
182  TList* locUserInfo = locBranchRegister.Get_UserInfo();
183  TMap* locNameToPIDMap = new TMap();
184  locNameToPIDMap->SetName("NameToPIDMap");
185  locUserInfo->Add(locNameToPIDMap);
186 
187  TMap* locNameToPositionMap = new TMap(); //not filled for target or initial particles
188  locNameToPositionMap->SetName("NameToPositionMap");
189  locUserInfo->Add(locNameToPositionMap);
190 
191  TMap* locPositionToNameMap = new TMap(); //not filled for target or initial particles
192  locPositionToNameMap->SetName("PositionToNameMap");
193  locUserInfo->Add(locPositionToNameMap);
194 
195  TMap* locPositionToPIDMap = new TMap();
196  locPositionToPIDMap->SetName("PositionToPIDMap");
197  locUserInfo->Add(locPositionToPIDMap);
198 
199  TMap* locDecayProductMap = new TMap(); //excludes resonances!!! //excludes intermediate decays (e.g. if xi- -> pi-, lambda -> pi-, pi-, p: will be xi- -> pi-, pi-, p and no lambda decay present)
200  locDecayProductMap->SetName("DecayProductMap"); //parent name string -> tlist of decay product name strings
201  locUserInfo->Add(locDecayProductMap);
202 
203  TMap* locMiscInfoMap = new TMap();
204  locMiscInfoMap->SetName("MiscInfoMap");
205  locUserInfo->Add(locMiscInfoMap);
206 
207  TList* locParticleNameList = new TList();
208  locParticleNameList->SetName("ParticleNameList");
209  locUserInfo->Add(locParticleNameList);
210 
211  //Set some misc info
212  ostringstream locKinFitTypeStream;
213  locKinFitTypeStream << locKinFitType;
214  locMiscInfoMap->Add(new TObjString("KinFitType"), new TObjString(locKinFitTypeStream.str().c_str()));
215 
216  string ANALYSIS_VERSION_STRING = "";
217  if(gPARMS->Exists("ANALYSIS:DATAVERSIONSTRING"))
218  gPARMS->GetParameter("ANALYSIS:DATAVERSIONSTRING", ANALYSIS_VERSION_STRING);
219  if(ANALYSIS_VERSION_STRING != "")
220  locMiscInfoMap->Add(new TObjString("ANALYSIS:DATAVERSIONSTRING"), new TObjString(ANALYSIS_VERSION_STRING.c_str()));
221 
222  string HDDM_DATA_VERSION_STRING = "";
223  if(gPARMS->Exists("REST:DATAVERSIONSTRING"))
224  gPARMS->GetParameter("REST:DATAVERSIONSTRING", HDDM_DATA_VERSION_STRING);
225  if(HDDM_DATA_VERSION_STRING != "")
226  locMiscInfoMap->Add(new TObjString("REST:DATAVERSIONSTRING"), new TObjString(HDDM_DATA_VERSION_STRING.c_str()));
227 
228  string REST_JANA_CALIB_CONTEXT = "";
229  if(gPARMS->Exists("REST:JANACALIBCONTEXT"))
230  gPARMS->GetParameter("REST:JANACALIBCONTEXT", REST_JANA_CALIB_CONTEXT);
231  if(REST_JANA_CALIB_CONTEXT == "")
232  gPARMS->GetParameter("JANA_CALIB_CONTEXT", REST_JANA_CALIB_CONTEXT);
233  if(REST_JANA_CALIB_CONTEXT != "")
234  locMiscInfoMap->Add(new TObjString("REST:JANACALIBCONTEXT"), new TObjString(REST_JANA_CALIB_CONTEXT.c_str()));
235 
236 
237  if(gPARMS->Exists("ANALYSIS:BCAL_VERBOSE_ROOT_OUTPUT"))
238  gPARMS->GetParameter("ANALYSIS:BCAL_VERBOSE_ROOT_OUTPUT", BCAL_VERBOSE_OUTPUT);
239  if(gPARMS->Exists("ANALYSIS:FCAL_VERBOSE_ROOT_OUTPUT"))
240  gPARMS->GetParameter("ANALYSIS:FCAL_VERBOSE_ROOT_OUTPUT", FCAL_VERBOSE_OUTPUT);
241  if(gPARMS->Exists("ANALYSIS:DIRC_ROOT_OUTPUT"))
242  gPARMS->GetParameter("ANALYSIS:DIRC_ROOT_OUTPUT", DIRC_OUTPUT);
243 
244  if(locKinFitType != d_NoFit)
245  {
246  DKinFitUtils_GlueX locKinFitUtils(locEventLoop);
247  size_t locNumConstraints = 0, locNumUnknowns = 0;
248  string locConstraintString = locKinFitUtils.Get_ConstraintInfo(locReactionVertexInfo, locReaction, locNumConstraints, locNumUnknowns);
249  locMiscInfoMap->Add(new TObjString("KinFitConstraints"), new TObjString(locConstraintString.c_str()));
250 
251  ostringstream locKinFitInfoStream;
252  locKinFitInfoStream << locNumConstraints;
253  locMiscInfoMap->Add(new TObjString("NumKinFitConstraints"), new TObjString(locKinFitInfoStream.str().c_str()));
254 
255  locKinFitInfoStream.str("");
256  locKinFitInfoStream << locNumUnknowns;
257  locMiscInfoMap->Add(new TObjString("NumKinFitUnknowns"), new TObjString(locKinFitInfoStream.str().c_str()));
258  }
259 
260  //find the # particles of each pid
261  map<Particle_t, unsigned int> locParticleNumberMap;
262  map<Particle_t, unsigned int> locDecayingParticleNumberMap;
263  map<Particle_t, unsigned int> locTargetParticleNumberMap;
264  for(size_t loc_i = 0; loc_i < locReaction->Get_NumReactionSteps(); ++loc_i)
265  {
266  const DReactionStep* locReactionStep = locReaction->Get_ReactionStep(loc_i);
267  auto locFinalParticleIDs = locReactionStep->Get_FinalPIDs();
268 
269  auto locTargetPID = locReactionStep->Get_TargetPID();
270  if(locTargetPID != Unknown)
271  {
272  if(locTargetParticleNumberMap.find(locTargetPID) == locTargetParticleNumberMap.end())
273  locTargetParticleNumberMap[locTargetPID] = 1;
274  else
275  ++locTargetParticleNumberMap[locTargetPID];
276  }
277 
278  for(size_t loc_j = 0; loc_j < locFinalParticleIDs.size(); ++loc_j)
279  {
280  if(locReactionStep->Get_MissingParticleIndex() == int(loc_j)) //missing particle
281  continue;
282  Particle_t locPID = locFinalParticleIDs[loc_j];
283 
284  //see if decays in a future step
285  int locDecayStepIndex = DAnalysis::Get_DecayStepIndex(locReaction, loc_i, loc_j);
286  if(locDecayStepIndex >= 0) //decaying
287  {
288  if(locDecayingParticleNumberMap.find(locPID) == locDecayingParticleNumberMap.end())
289  locDecayingParticleNumberMap[locPID] = 1;
290  else
291  ++locDecayingParticleNumberMap[locPID];
292  }
293  else //detected, not decaying
294  {
295  if(locParticleNumberMap.find(locPID) == locParticleNumberMap.end())
296  locParticleNumberMap[locPID] = 1;
297  else
298  ++locParticleNumberMap[locPID];
299  }
300  }
301  }
302 
303  //Create map objects
304  map<Particle_t, unsigned int> locParticleNumberMap_Current, locDecayingParticleNumberMap_Current, locTargetParticleNumberMap_Current;
305  Particle_t locTargetPID = Unknown;
306  TObjString *locObjString_PID, *locObjString_Position, *locObjString_ParticleName;
307  map<int, string> locDecayingParticleNames; //key is step index where they decay
308  for(size_t loc_i = 0; loc_i < locReaction->Get_NumReactionSteps(); ++loc_i)
309  {
310  const DReactionStep* locReactionStep = locReaction->Get_ReactionStep(loc_i);
311 
312  //initial particle
313  {
314  ostringstream locPIDStream, locPositionStream, locParticleNameStream;
315  Particle_t locPID = locReactionStep->Get_InitialPID();
316  locPIDStream << PDGtype(locPID);
317  locObjString_PID = new TObjString(locPIDStream.str().c_str());
318 
319  locPositionStream << loc_i << "_" << -1;
320  locObjString_Position = new TObjString(locPositionStream.str().c_str());
321 
322  locPositionToPIDMap->Add(locObjString_Position, locObjString_PID);
323  if((loc_i == 0) && ((locPID == Gamma) || (locPID == Electron) || (locPID == Positron)))
324  {
325  locParticleNameStream << "ComboBeam";
326  locObjString_ParticleName = new TObjString(locParticleNameStream.str().c_str());
327  locNameToPIDMap->Add(locObjString_ParticleName, locObjString_PID);
328  locParticleNameList->AddLast(locObjString_ParticleName);
329  }
330  else //decaying particle
331  {
332  if(loc_i == 0)
333  locParticleNameStream << "Decaying" << Convert_ToBranchName(ParticleType(locPID));
334  else //name already created for final particle: use it
335  locParticleNameStream << locDecayingParticleNames[loc_i];
336  locObjString_ParticleName = new TObjString(locParticleNameStream.str().c_str());
337  if(loc_i == 0) //in first step
338  {
339  locNameToPIDMap->Add(locObjString_ParticleName, locObjString_PID);
340  locParticleNameList->AddLast(locObjString_ParticleName);
341  }
342  }
343  locPositionToNameMap->Add(locObjString_Position, locObjString_ParticleName);
344  locNameToPositionMap->Add(locObjString_ParticleName, locObjString_Position);
345  }
346 
347  //target particle
348  Particle_t locTempTargetPID = locReactionStep->Get_TargetPID();
349  if(locTempTargetPID != Unknown)
350  {
351  locTargetPID = locTempTargetPID;
352 
353  if(locTargetParticleNumberMap_Current.find(locTargetPID) == locTargetParticleNumberMap_Current.end())
354  locTargetParticleNumberMap_Current[locTargetPID] = 1;
355  else
356  ++locTargetParticleNumberMap_Current[locTargetPID];
357 
358  ostringstream locPIDStream, locPositionStream, locParticleNameStream;
359  locPIDStream << PDGtype(locTargetPID);
360  locObjString_PID = new TObjString(locPIDStream.str().c_str());
361 
362  locPositionStream << loc_i << "_" << -2;
363  locObjString_Position = new TObjString(locPositionStream.str().c_str());
364 
365  locPositionToPIDMap->Add(locObjString_Position, locObjString_PID);
366 
367  locParticleNameStream << "Target";
368  if(locTargetParticleNumberMap[locTargetPID] > 1)
369  locParticleNameStream << locTargetParticleNumberMap_Current[locTargetPID];
370  locObjString_ParticleName = new TObjString(locParticleNameStream.str().c_str());
371 
372  locNameToPositionMap->Add(locObjString_ParticleName, locObjString_Position);
373  locNameToPIDMap->Add(locObjString_ParticleName, locObjString_PID);
374  locPositionToNameMap->Add(locObjString_Position, locObjString_ParticleName);
375 
376  locParticleNameList->AddLast(locObjString_ParticleName);
377  }
378 
379  //final particles
380  auto locFinalParticleIDs = locReactionStep->Get_FinalPIDs();
381  for(size_t loc_j = 0; loc_j < locFinalParticleIDs.size(); ++loc_j)
382  {
383  ostringstream locPIDStream, locPositionStream;
384  Particle_t locPID = locFinalParticleIDs[loc_j];
385  locPIDStream << PDGtype(locPID);
386  locObjString_PID = new TObjString(locPIDStream.str().c_str());
387 
388  locPositionStream << loc_i << "_" << loc_j;
389  locObjString_Position = new TObjString(locPositionStream.str().c_str());
390 
391  if(locReactionStep->Get_MissingParticleIndex() == int(loc_j)) //missing particle
392  {
393  ostringstream locParticleNameStream;
394  locParticleNameStream << "Missing" << Convert_ToBranchName(ParticleType(locPID));
395  locObjString_ParticleName = new TObjString(locParticleNameStream.str().c_str());
396  locNameToPositionMap->Add(locObjString_ParticleName, locObjString_Position);
397  locPositionToNameMap->Add(locObjString_Position, locObjString_ParticleName);
398  locNameToPIDMap->Add(locObjString_ParticleName, locObjString_PID);
399  string locPIDName = locParticleNameStream.str() + string("__PID");
400  locMiscInfoMap->Add(new TObjString(locPIDName.c_str()), locObjString_PID);
401  ostringstream locMassStream;
402  locMassStream << ParticleMass(locPID);
403  string locMassName = locParticleNameStream.str() + string("__Mass");
404  locMiscInfoMap->Add(new TObjString(locMassName.c_str()), new TObjString(locMassStream.str().c_str()));
405  locParticleNameList->AddLast(locObjString_ParticleName);
406  continue;
407  }
408 
409  //build name
410  ostringstream locParticleNameStream;
411  //see if decays in a future step
412  int locDecayStepIndex = DAnalysis::Get_DecayStepIndex(locReaction, loc_i, loc_j);
413  if(locDecayStepIndex >= 0) //decays
414  {
415  if(locDecayingParticleNumberMap_Current.find(locPID) == locDecayingParticleNumberMap_Current.end())
416  locDecayingParticleNumberMap_Current[locPID] = 1;
417  else
418  ++locDecayingParticleNumberMap_Current[locPID];
419 
420  locParticleNameStream << "Decaying" << Convert_ToBranchName(ParticleType(locPID));
421  if(locDecayingParticleNumberMap[locPID] > 1)
422  locParticleNameStream << locDecayingParticleNumberMap_Current[locPID];
423  locDecayingParticleNames[locDecayStepIndex] = locParticleNameStream.str();
424  }
425  else
426  {
427  if(locParticleNumberMap_Current.find(locPID) == locParticleNumberMap_Current.end())
428  locParticleNumberMap_Current[locPID] = 1;
429  else
430  ++locParticleNumberMap_Current[locPID];
431 
432  locParticleNameStream << Convert_ToBranchName(ParticleType(locPID));
433  if(locParticleNumberMap[locPID] > 1)
434  locParticleNameStream << locParticleNumberMap_Current[locPID];
435  }
436 
437  locObjString_ParticleName = new TObjString(locParticleNameStream.str().c_str());
438  locParticleNameList->AddLast(locObjString_ParticleName);
439 
440  locPositionToPIDMap->Add(locObjString_Position, locObjString_PID);
441  locNameToPositionMap->Add(locObjString_ParticleName, locObjString_Position);
442  locPositionToNameMap->Add(locObjString_Position, locObjString_ParticleName);
443  locNameToPIDMap->Add(locObjString_ParticleName, locObjString_PID);
444  if(locDecayStepIndex >= 0)
445  {
446  ostringstream locMassStream;
447  locMassStream << ParticleMass(locPID);
448  string locMassName = locParticleNameStream.str() + string("__Mass");
449  locMiscInfoMap->Add(new TObjString(locMassName.c_str()), new TObjString(locMassStream.str().c_str()));
450  }
451  }
452  }
453 
454  //setup target info
455  Create_UserTargetInfo(locBranchRegister, locTargetPID);
456 
457  //fill decay product map
458  deque<size_t> locSavedSteps;
459  for(size_t loc_i = 0; loc_i < locReaction->Get_NumReactionSteps(); ++loc_i)
460  {
461  const DReactionStep* locReactionStep = locReaction->Get_ReactionStep(loc_i);
462 
463  //initial particle
464  Particle_t locPID = locReactionStep->Get_InitialPID();
465  if(loc_i == 0)
466  continue;
467  if(!IsFixedMass(locPID))
468  continue; //don't save resonance decays to the map
469 
470  //check to see if this decay has already been saved
471  bool locStepAlreadySavedFlag = false;
472  for(size_t loc_j = 0; loc_j < locSavedSteps.size(); ++loc_j)
473  {
474  if(locSavedSteps[loc_j] != loc_i)
475  continue;
476  locStepAlreadySavedFlag = true;
477  break;
478  }
479  if(locStepAlreadySavedFlag)
480  continue;
481 
482  //construct the name
483  ostringstream locParticleNameStream;
484  locParticleNameStream << locDecayingParticleNames[loc_i];
485  locObjString_ParticleName = new TObjString(locParticleNameStream.str().c_str());
486 
487  TList* locDecayProductNames = NULL;
488  Get_DecayProductNames(locReaction, loc_i, locPositionToNameMap, locDecayProductNames, locSavedSteps);
489  locDecayProductMap->Add(locObjString_ParticleName, locDecayProductNames); //parent name string -> tobjarray of decay product name strings
490  }
491 
492  return locPositionToNameMap;
493 }
494 
495 void DEventWriterROOT::Get_DecayProductNames(const DReaction* locReaction, size_t locReactionStepIndex, TMap* locPositionToNameMap, TList*& locDecayProductNames, deque<size_t>& locSavedSteps) const
496 {
497  const DReactionStep* locReactionStep = locReaction->Get_ReactionStep(locReactionStepIndex);
498 
499  if(locDecayProductNames == NULL)
500  locDecayProductNames = new TList();
501 
502  auto locFinalParticleIDs = locReactionStep->Get_FinalPIDs();
503  for(size_t loc_j = 0; loc_j < locFinalParticleIDs.size(); ++loc_j)
504  {
505  //see if decays in a future step //save and continue if doesn't decay
506  int locDecayStepIndex = DAnalysis::Get_DecayStepIndex(locReaction, locReactionStepIndex, loc_j);
507  if(locDecayStepIndex < 0)
508  {
509  ostringstream locPositionStream;
510  locPositionStream << locReactionStepIndex << "_" << loc_j;
511  locDecayProductNames->AddLast(locPositionToNameMap->GetValue(locPositionStream.str().c_str()));
512  continue;
513  }
514 
515  //add decay products
516  Get_DecayProductNames(locReaction, locDecayStepIndex, locPositionToNameMap, locDecayProductNames, locSavedSteps);
517  }
518 
519  locSavedSteps.push_back(locReactionStepIndex);
520 }
521 
522 void DEventWriterROOT::Create_UserTargetInfo(DTreeBranchRegister& locBranchRegister, Particle_t locTargetPID) const
523 {
524  TList* locUserInfo = locBranchRegister.Get_UserInfo();
525  TMap* locMiscInfoMap = (TMap*)locUserInfo->FindObject("MiscInfoMap");
526  if(locMiscInfoMap == NULL)
527  {
528  locMiscInfoMap = new TMap();
529  locMiscInfoMap->SetName("MiscInfoMap");
530  locUserInfo->Add(locMiscInfoMap);
531  }
532 
533  //PID
534  ostringstream locPIDStream;
535  locPIDStream << PDGtype(locTargetPID);
536  locMiscInfoMap->Add(new TObjString("Target__PID"), new TObjString(locPIDStream.str().c_str()));
537 
538  //Mass
539  ostringstream locMassStream;
540  locMassStream << ParticleMass(locTargetPID);
541  locMiscInfoMap->Add(new TObjString("Target__Mass"), new TObjString(locMassStream.str().c_str()));
542 
543  //X, Y
544  ostringstream locZeroStream;
545  locZeroStream << 0.0;
546  TObjString* locObjString_Zero = new TObjString(locZeroStream.str().c_str());
547  locMiscInfoMap->Add(new TObjString("Target__CenterX"), locObjString_Zero);
548  locMiscInfoMap->Add(new TObjString("Target__CenterY"), locObjString_Zero);
549 
550  //Z
551  ostringstream locPositionStream;
552  locPositionStream << dTargetCenterZ;
553  TObjString* locObjString_Position = new TObjString(locPositionStream.str().c_str());
554  locMiscInfoMap->Add(new TObjString("Target__CenterZ"), locObjString_Position);
555 }
556 
557 void DEventWriterROOT::Create_Branches_Thrown(DTreeBranchRegister& locBranchRegister, bool locIsOnlyThrownFlag) const
558 {
559  //BEAM
560  locBranchRegister.Register_Single<Int_t>(Build_BranchName("ThrownBeam", "PID"));
561  locBranchRegister.Register_Single<TLorentzVector>(Build_BranchName("ThrownBeam", "X4")); //reported at target center
562  locBranchRegister.Register_Single<TLorentzVector>(Build_BranchName("ThrownBeam", "P4"));
563  locBranchRegister.Register_Single<Float_t>(Build_BranchName("ThrownBeam", "GeneratedEnergy"));
564 
565  //EVENT-WIDE INFO
566  locBranchRegister.Register_Single<ULong64_t>("NumPIDThrown_FinalState"); //19 digits
567  locBranchRegister.Register_Single<ULong64_t>("PIDThrown_Decaying"); //19 digits
568  locBranchRegister.Register_Single<Float_t>("MCWeight");
569 
570  //PRODUCTS
571  Create_Branches_ThrownParticles(locBranchRegister, locIsOnlyThrownFlag);
572 }
573 
574 void DEventWriterROOT::Create_Branches_ThrownParticles(DTreeBranchRegister& locBranchRegister, bool locIsOnlyThrownFlag) const
575 {
576  string locParticleBranchName = "Thrown";
577 
578  string locArraySizeString = "NumThrown";
579  locBranchRegister.Register_Single<UInt_t>(locArraySizeString);
580 
581  //IDENTIFIERS
582  locBranchRegister.Register_FundamentalArray<Int_t>(Build_BranchName(locParticleBranchName, "ParentIndex"), locArraySizeString, dInitNumThrownArraySize);
583  locBranchRegister.Register_FundamentalArray<Int_t>(Build_BranchName(locParticleBranchName, "PID"), locArraySizeString, dInitNumThrownArraySize);
584  if(!locIsOnlyThrownFlag)
585  {
586  locBranchRegister.Register_FundamentalArray<Int_t>(Build_BranchName(locParticleBranchName, "MatchID"), locArraySizeString, dInitNumThrownArraySize);
587  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "MatchFOM"), locArraySizeString, dInitNumThrownArraySize);
588  }
589 
590  //KINEMATICS: THROWN //at the production vertex
591  locBranchRegister.Register_ClonesArray<TLorentzVector>(Build_BranchName(locParticleBranchName, "X4"), dInitNumThrownArraySize);
592  locBranchRegister.Register_ClonesArray<TLorentzVector>(Build_BranchName(locParticleBranchName, "P4"), dInitNumThrownArraySize);
593 }
594 
595 void DEventWriterROOT::Create_Branches_Beam(DTreeBranchRegister& locBranchRegister, bool locIsMCDataFlag) const
596 {
597  string locArraySizeString = "NumBeam";
598  locBranchRegister.Register_Single<UInt_t>(locArraySizeString);
599 
600  string locParticleBranchName = "Beam";
601 
602  //IDENTIFIER
603  locBranchRegister.Register_FundamentalArray<Int_t>(Build_BranchName(locParticleBranchName, "PID"), locArraySizeString, dInitNumBeamArraySize);
604  if(locIsMCDataFlag)
605  locBranchRegister.Register_FundamentalArray<Bool_t>(Build_BranchName(locParticleBranchName, "IsGenerator"), locArraySizeString, dInitNumBeamArraySize);
606 
607  //KINEMATICS: MEASURED //at the production vertex
608  locBranchRegister.Register_ClonesArray<TLorentzVector>(Build_BranchName(locParticleBranchName, "X4_Measured"), dInitNumThrownArraySize);
609  locBranchRegister.Register_ClonesArray<TLorentzVector>(Build_BranchName(locParticleBranchName, "P4_Measured"), dInitNumThrownArraySize);
610 }
611 
612 void DEventWriterROOT::Create_Branches_ChargedHypotheses(DTreeBranchRegister& locBranchRegister, bool locIsMCDataFlag) const
613 {
614  string locArraySizeString = "NumChargedHypos";
615  locBranchRegister.Register_Single<UInt_t>(locArraySizeString);
616 
617  string locParticleBranchName = "ChargedHypo";
618 
619  //IDENTIFIERS / MATCHING
620  locBranchRegister.Register_FundamentalArray<Int_t>(Build_BranchName(locParticleBranchName, "TrackID"), locArraySizeString, dInitNumTrackArraySize);
621  locBranchRegister.Register_FundamentalArray<Int_t>(Build_BranchName(locParticleBranchName, "PID"), locArraySizeString, dInitNumTrackArraySize);
622  if(locIsMCDataFlag)
623  locBranchRegister.Register_FundamentalArray<Int_t>(Build_BranchName(locParticleBranchName, "ThrownIndex"), locArraySizeString, dInitNumTrackArraySize);
624 
625  //KINEMATICS //at the production vertex
626  locBranchRegister.Register_ClonesArray<TLorentzVector>(Build_BranchName(locParticleBranchName, "X4_Measured"), dInitNumTrackArraySize);
627  locBranchRegister.Register_ClonesArray<TLorentzVector>(Build_BranchName(locParticleBranchName, "P4_Measured"), dInitNumTrackArraySize);
628 
629  //TRACKING INFO
630  locBranchRegister.Register_FundamentalArray<UInt_t>(Build_BranchName(locParticleBranchName, "NDF_Tracking"), locArraySizeString, dInitNumTrackArraySize);
631  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "ChiSq_Tracking"), locArraySizeString, dInitNumTrackArraySize);
632  locBranchRegister.Register_FundamentalArray<UInt_t>(Build_BranchName(locParticleBranchName, "NDF_DCdEdx"), locArraySizeString, dInitNumTrackArraySize);
633  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "ChiSq_DCdEdx"), locArraySizeString, dInitNumTrackArraySize);
634  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "dEdx_CDC"), locArraySizeString, dInitNumTrackArraySize);
635  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "dEdx_CDC_integral"), locArraySizeString, dInitNumTrackArraySize);
636  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "dEdx_FDC"), locArraySizeString, dInitNumTrackArraySize);
637 
638  //TIMING INFO
639  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "HitTime"), locArraySizeString, dInitNumTrackArraySize);
640  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "RFDeltaTVar"), locArraySizeString, dInitNumTrackArraySize);
641 
642  //PID QUALITY
643  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "Beta_Timing"), locArraySizeString, dInitNumTrackArraySize);
644  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "ChiSq_Timing"), locArraySizeString, dInitNumTrackArraySize);
645  locBranchRegister.Register_FundamentalArray<UInt_t>(Build_BranchName(locParticleBranchName, "NDF_Timing"), locArraySizeString, dInitNumTrackArraySize);
646 
647  //HIT ENERGY
648  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "dEdx_TOF"), locArraySizeString, dInitNumTrackArraySize);
649  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "dEdx_ST"), locArraySizeString, dInitNumTrackArraySize);
650  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "Energy_BCAL"), locArraySizeString, dInitNumNeutralArraySize);
651  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "Energy_BCALPreshower"), locArraySizeString, dInitNumNeutralArraySize);
652  if(BCAL_VERBOSE_OUTPUT) {
653  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "Energy_BCALLayer2"), locArraySizeString, dInitNumNeutralArraySize);
654  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "Energy_BCALLayer3"), locArraySizeString, dInitNumNeutralArraySize);
655  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "Energy_BCALLayer4"), locArraySizeString, dInitNumNeutralArraySize);
656  }
657  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "SigLong_BCAL"), locArraySizeString, dInitNumNeutralArraySize);
658  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "SigTheta_BCAL"), locArraySizeString, dInitNumNeutralArraySize);
659  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "SigTrans_BCAL"), locArraySizeString, dInitNumNeutralArraySize);
660  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "RMSTime_BCAL"), locArraySizeString, dInitNumNeutralArraySize);
661  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "Energy_FCAL"), locArraySizeString, dInitNumNeutralArraySize);
662  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "E1E9_FCAL"), locArraySizeString, dInitNumNeutralArraySize);
663  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "E9E25_FCAL"), locArraySizeString, dInitNumNeutralArraySize);
664  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "SumU_FCAL"), locArraySizeString, dInitNumNeutralArraySize);
665  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "SumV_FCAL"), locArraySizeString, dInitNumNeutralArraySize);
666 
667  //SHOWER MATCHING:
668  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "TrackBCAL_DeltaPhi"), locArraySizeString, dInitNumTrackArraySize);
669  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "TrackBCAL_DeltaZ"), locArraySizeString, dInitNumTrackArraySize);
670  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "TrackFCAL_DOCA"), locArraySizeString, dInitNumTrackArraySize);
671 
672  //DIRC:
673  if(DIRC_OUTPUT) {
674  locBranchRegister.Register_FundamentalArray<Int_t>(Build_BranchName(locParticleBranchName, "NumPhotons_DIRC"), locArraySizeString, dInitNumTrackArraySize);
675  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "ThetaC_DIRC"), locArraySizeString, dInitNumTrackArraySize);
676  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "Lele_DIRC"), locArraySizeString, dInitNumTrackArraySize);
677  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "Lpi_DIRC"), locArraySizeString, dInitNumTrackArraySize);
678  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "Lk_DIRC"), locArraySizeString, dInitNumTrackArraySize);
679  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "Lp_DIRC"), locArraySizeString, dInitNumTrackArraySize);
680  }
681 }
682 
683 void DEventWriterROOT::Create_Branches_NeutralHypotheses(DTreeBranchRegister& locBranchRegister, bool locIsMCDataFlag) const
684 {
685  string locArraySizeString = "NumNeutralHypos";
686  string locParticleBranchName = "NeutralHypo";
687  locBranchRegister.Register_Single<UInt_t>(locArraySizeString);
688 
689  //IDENTIFIERS / MATCHING
690  locBranchRegister.Register_FundamentalArray<Int_t>(Build_BranchName(locParticleBranchName, "NeutralID"), locArraySizeString, dInitNumNeutralArraySize);
691  locBranchRegister.Register_FundamentalArray<Int_t>(Build_BranchName(locParticleBranchName, "PID"), locArraySizeString, dInitNumNeutralArraySize);
692  if(locIsMCDataFlag)
693  locBranchRegister.Register_FundamentalArray<Int_t>(Build_BranchName(locParticleBranchName, "ThrownIndex"), locArraySizeString, dInitNumNeutralArraySize);
694 
695  //KINEMATICS //is combo-dependent: P4 defined by X4, X4 defined by other tracks
696  locBranchRegister.Register_ClonesArray<TLorentzVector>(Build_BranchName(locParticleBranchName, "X4_Measured"), dInitNumNeutralArraySize);
697  locBranchRegister.Register_ClonesArray<TLorentzVector>(Build_BranchName(locParticleBranchName, "P4_Measured"), dInitNumNeutralArraySize);
698 
699  //PID QUALITY
700  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "Beta_Timing"), locArraySizeString, dInitNumNeutralArraySize);
701  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "ChiSq_Timing"), locArraySizeString, dInitNumNeutralArraySize);
702  locBranchRegister.Register_FundamentalArray<UInt_t>(Build_BranchName(locParticleBranchName, "NDF_Timing"), locArraySizeString, dInitNumNeutralArraySize);
703 
704  //SHOWER INFO
705  locBranchRegister.Register_ClonesArray<TLorentzVector>(Build_BranchName(locParticleBranchName, "X4_Shower"), dInitNumNeutralArraySize);
706  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "ShowerQuality"), locArraySizeString, dInitNumNeutralArraySize);
707  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "Energy_BCAL"), locArraySizeString, dInitNumNeutralArraySize);
708  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "Energy_BCALPreshower"), locArraySizeString, dInitNumNeutralArraySize);
709  if(BCAL_VERBOSE_OUTPUT) {
710  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "Energy_BCALLayer2"), locArraySizeString, dInitNumNeutralArraySize);
711  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "Energy_BCALLayer3"), locArraySizeString, dInitNumNeutralArraySize);
712  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "Energy_BCALLayer4"), locArraySizeString, dInitNumNeutralArraySize);
713  }
714  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "SigLong_BCAL"), locArraySizeString, dInitNumNeutralArraySize);
715  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "SigTheta_BCAL"), locArraySizeString, dInitNumNeutralArraySize);
716  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "SigTrans_BCAL"), locArraySizeString, dInitNumNeutralArraySize);
717  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "RMSTime_BCAL"), locArraySizeString, dInitNumNeutralArraySize);
718  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "Energy_FCAL"), locArraySizeString, dInitNumNeutralArraySize);
719  if(FCAL_VERBOSE_OUTPUT) {
720  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "E1E9_FCAL"), locArraySizeString, dInitNumNeutralArraySize);
721  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "E9E25_FCAL"), locArraySizeString, dInitNumNeutralArraySize);
722  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "SumU_FCAL"), locArraySizeString, dInitNumNeutralArraySize);
723  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "SumV_FCAL"), locArraySizeString, dInitNumNeutralArraySize);
724  }
725 
726  //NEARBY TRACKS
727  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "TrackBCAL_DeltaPhi"), locArraySizeString, dInitNumNeutralArraySize);
728  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "TrackBCAL_DeltaZ"), locArraySizeString, dInitNumNeutralArraySize);
729  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "TrackFCAL_DOCA"), locArraySizeString, dInitNumNeutralArraySize);
730 
731  //PHOTON PID INFO
732  //Computed using DVertex (best estimate of reaction vertex using all "good" tracks)
733  //Can be used to compute timing chisq //is invalid for non-photons, so computed assuming photon PID
734  //Variance of X4_Measured.T() - RFTime, regardless of which RF bunch is chosen. //RF bunch is combo-depende
735  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "PhotonRFDeltaTVar"), locArraySizeString, dInitNumNeutralArraySize);
736 }
737 
738 void DEventWriterROOT::Create_Branches_Combo(DTreeBranchRegister& locBranchRegister, const DReaction* locReaction, bool locIsMCDataFlag, TMap* locPositionToNameMap) const
739 {
740  auto locReactionVertexInfo = dVertexInfoMap.find(locReaction)->second;
741  string locNumComboString = "NumCombos";
742  locBranchRegister.Register_Single<UInt_t>(locNumComboString);
743 
744  //kinfit type
745  DKinFitType locKinFitType = locReaction->Get_KinFitType();
746  bool locKinFitFlag = (locKinFitType != d_NoFit);
747  bool locVertexKinFitFlag = locKinFitFlag && (locKinFitType != d_P4Fit);
748 
749  //Is-cut
750  locBranchRegister.Register_FundamentalArray<Bool_t>("IsComboCut", locNumComboString, dInitNumComboArraySize);
751 
752  //create combo-dependent, particle-independent branches
753  if(locIsMCDataFlag)
754  {
755  locBranchRegister.Register_FundamentalArray<Bool_t>("IsTrueCombo", locNumComboString, dInitNumComboArraySize);
756  locBranchRegister.Register_FundamentalArray<Bool_t>("IsBDTSignalCombo", locNumComboString, dInitNumComboArraySize);
757  }
758 
759  locBranchRegister.Register_FundamentalArray<Float_t>("RFTime_Measured", locNumComboString, dInitNumComboArraySize);
760  if(locKinFitFlag)
761  {
762  locBranchRegister.Register_FundamentalArray<Float_t>("ChiSq_KinFit", locNumComboString, dInitNumComboArraySize);
763  locBranchRegister.Register_FundamentalArray<UInt_t>("NDF_KinFit", locNumComboString, dInitNumComboArraySize);
764  if((locKinFitType == d_SpacetimeFit) || (locKinFitType == d_P4AndSpacetimeFit))
765  locBranchRegister.Register_FundamentalArray<Float_t>("RFTime_KinFit", locNumComboString, dInitNumComboArraySize);
766  }
767  locBranchRegister.Register_FundamentalArray<Float_t>("Energy_UnusedShowers", locNumComboString, dInitNumComboArraySize);
768  locBranchRegister.Register_FundamentalArray<Float_t>("SumPMag_UnusedTracks", locNumComboString, dInitNumComboArraySize);
769  locBranchRegister.Register_ClonesArray<TVector3>("SumP3_UnusedTracks", dInitNumComboArraySize);
770 
771  map<Particle_t, unsigned int> locParticleNumberMap_Current;
772  for(size_t loc_i = 0; loc_i < locReaction->Get_NumReactionSteps(); ++loc_i)
773  {
774  const DReactionStep* locReactionStep = locReaction->Get_ReactionStep(loc_i);
775 
776  //initial particle
777  Particle_t locInitialPID = locReactionStep->Get_InitialPID();
778  //should check to make sure the beam particle isn't missing...
779  if((loc_i == 0) && (locReactionStep->Get_InitialPID() != Unknown))
780  Create_Branches_BeamComboParticle(locBranchRegister, locInitialPID, locKinFitType);
781  else //decaying
782  {
783  //get the branch name
784  ostringstream locPositionStream;
785  locPositionStream << loc_i << "_-1";
786  TObjString* locObjString = (TObjString*)locPositionToNameMap->GetValue(locPositionStream.str().c_str());
787  string locParticleBranchName = (const char*)(locObjString->GetString());
788 
789  if(IsFixedMass(locInitialPID) && locReactionStep->Get_KinFitConstrainInitMassFlag() && ((locKinFitType == d_P4Fit) || (locKinFitType == d_P4AndVertexFit) || (locKinFitType == d_P4AndSpacetimeFit)))
790  locBranchRegister.Register_ClonesArray<TLorentzVector>(Build_BranchName(locParticleBranchName, "P4_KinFit"), dInitNumComboArraySize);
791  if((loc_i == 0) || IsDetachedVertex(locInitialPID))
792  locBranchRegister.Register_ClonesArray<TLorentzVector>(Build_BranchName(locParticleBranchName, "X4"), dInitNumComboArraySize);
793 
794  auto locStepVertexInfo = locReactionVertexInfo->Get_StepVertexInfo(loc_i);
795  auto locParentVertexInfo = locStepVertexInfo->Get_ParentVertexInfo();
796  if(IsDetachedVertex(locInitialPID) && locVertexKinFitFlag && (locParentVertexInfo != nullptr) && locStepVertexInfo->Get_FittableVertexFlag() && locParentVertexInfo->Get_FittableVertexFlag())
797  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "PathLengthSigma"), locNumComboString, dInitNumComboArraySize);
798  }
799 
800  //final particles
801  auto locFinalParticleIDs = locReactionStep->Get_FinalPIDs();
802  for(size_t loc_j = 0; loc_j < locFinalParticleIDs.size(); ++loc_j)
803  {
804  int locDecayStepIndex = DAnalysis::Get_DecayStepIndex(locReaction, loc_i, loc_j);
805  if(locDecayStepIndex >= 0)
806  continue; //decaying particle
807 
808  //get the branch name
809  ostringstream locPositionStream;
810  locPositionStream << loc_i << "_" << loc_j;
811  TObjString* locObjString = (TObjString*)locPositionToNameMap->GetValue(locPositionStream.str().c_str());
812  string locParticleBranchName = (const char*)(locObjString->GetString());
813 
814  //missing particle
815  if(locReactionStep->Get_MissingParticleIndex() == int(loc_j))
816  {
817  // missing particle
818  if((locKinFitType == d_P4Fit) || (locKinFitType == d_P4AndVertexFit) || (locKinFitType == d_P4AndSpacetimeFit))
819  locBranchRegister.Register_ClonesArray<TLorentzVector>(Build_BranchName(locParticleBranchName, "P4_KinFit"), dInitNumComboArraySize);
820  continue;
821  }
822 
823  Particle_t locPID = locFinalParticleIDs[loc_j];
824  if(ParticleCharge(locPID) == 0)
825  Create_Branches_ComboNeutral(locBranchRegister, locParticleBranchName, locKinFitType);
826  else
827  Create_Branches_ComboTrack(locBranchRegister, locParticleBranchName, locKinFitType);
828  }
829  }
830 }
831 
833 {
834  string locParticleBranchName = "ComboBeam";
835  string locArraySizeString = "NumCombos";
836 
837  //IDENTIFIER
838  locBranchRegister.Register_FundamentalArray<Int_t>(Build_BranchName(locParticleBranchName, "BeamIndex"), locArraySizeString, dInitNumComboArraySize);
839 
840  //KINEMATICS: KINFIT //at the interaction vertex
841  if(locKinFitType != d_NoFit)
842  {
843  if(((locKinFitType != d_VertexFit) && (locKinFitType != d_SpacetimeFit)) || (ParticleCharge(locBeamPID) != 0))
844  locBranchRegister.Register_ClonesArray<TLorentzVector>(Build_BranchName(locParticleBranchName, "P4_KinFit"), dInitNumComboArraySize);
845  if(locKinFitType != d_P4Fit)
846  locBranchRegister.Register_ClonesArray<TLorentzVector>(Build_BranchName(locParticleBranchName, "X4_KinFit"), dInitNumComboArraySize);
847  }
848 }
849 
850 void DEventWriterROOT::Create_Branches_ComboTrack(DTreeBranchRegister& locBranchRegister, string locParticleBranchName, DKinFitType locKinFitType) const
851 {
852  string locArraySizeString = "NumCombos";
853 
854  //IDENTIFIER
855  locBranchRegister.Register_FundamentalArray<Int_t>(Build_BranchName(locParticleBranchName, "ChargedIndex"), locArraySizeString, dInitNumComboArraySize);
856 
857  //MEASURED PID
858  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "Beta_Timing_Measured"), locArraySizeString, dInitNumComboArraySize);
859  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "ChiSq_Timing_Measured"), locArraySizeString, dInitNumComboArraySize);
860 
861  //KINFIT PID
862  if((locKinFitType != d_NoFit) && (locKinFitType != d_SpacetimeFit) && (locKinFitType != d_P4AndSpacetimeFit))
863  {
864  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "Beta_Timing_KinFit"), locArraySizeString, dInitNumComboArraySize);
865  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "ChiSq_Timing_KinFit"), locArraySizeString, dInitNumComboArraySize);
866  }
867 
868  //KINFIT INFO //at the production vertex
869  if(locKinFitType != d_NoFit)
870  {
871  //update p4 even if vertex-only fit, because charged momentum propagated through b-field
872  locBranchRegister.Register_ClonesArray<TLorentzVector>(Build_BranchName(locParticleBranchName, "P4_KinFit"), dInitNumComboArraySize);
873  if(locKinFitType != d_P4Fit)
874  locBranchRegister.Register_ClonesArray<TLorentzVector>(Build_BranchName(locParticleBranchName, "X4_KinFit"), dInitNumComboArraySize);
875  }
876 }
877 
878 void DEventWriterROOT::Create_Branches_ComboNeutral(DTreeBranchRegister& locBranchRegister, string locParticleBranchName, DKinFitType locKinFitType) const
879 {
880  string locArraySizeString = "NumCombos";
881 
882  //IDENTIFIER
883  locBranchRegister.Register_FundamentalArray<Int_t>(Build_BranchName(locParticleBranchName, "NeutralIndex"), locArraySizeString, dInitNumComboArraySize);
884 
885  //KINEMATICS //is combo-dependent: P4 defined by X4, X4 defined by other tracks
886  locBranchRegister.Register_ClonesArray<TLorentzVector>(Build_BranchName(locParticleBranchName, "X4_Measured"), dInitNumComboArraySize);
887  locBranchRegister.Register_ClonesArray<TLorentzVector>(Build_BranchName(locParticleBranchName, "P4_Measured"), dInitNumComboArraySize);
888 
889  //MEASURED PID
890  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "Beta_Timing_Measured"), locArraySizeString, dInitNumComboArraySize);
891  if(locParticleBranchName.substr(0, 6) == "Photon")
892  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "ChiSq_Timing_Measured"), locArraySizeString, dInitNumComboArraySize);
893 
894  //KINFIT PID
895  if((locKinFitType != d_NoFit) && (locKinFitType != d_SpacetimeFit) && (locKinFitType != d_P4AndSpacetimeFit))
896  {
897  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "Beta_Timing_KinFit"), locArraySizeString, dInitNumComboArraySize);
898  if(locParticleBranchName.substr(0, 6) == "Photon")
899  locBranchRegister.Register_FundamentalArray<Float_t>(Build_BranchName(locParticleBranchName, "ChiSq_Timing_KinFit"), locArraySizeString, dInitNumComboArraySize);
900  }
901 
902  //KINFIT INFO //at the production vertex
903  if(locKinFitType != d_NoFit)
904  {
905  locBranchRegister.Register_ClonesArray<TLorentzVector>(Build_BranchName(locParticleBranchName, "P4_KinFit"), dInitNumComboArraySize);
906  if(locKinFitType != d_P4Fit)
907  locBranchRegister.Register_ClonesArray<TLorentzVector>(Build_BranchName(locParticleBranchName, "X4_KinFit"), dInitNumComboArraySize);
908  }
909 }
910 
911 void DEventWriterROOT::Fill_ThrownTree(JEventLoop* locEventLoop) const
912 {
913  vector<const DMCThrown*> locMCThrowns_FinalState;
914  locEventLoop->Get(locMCThrowns_FinalState, "FinalState");
915 
916  vector<const DMCThrown*> locMCThrowns_Decaying;
917  locEventLoop->Get(locMCThrowns_Decaying, "Decaying");
918 
919  const DMCReaction* locMCReaction = NULL;
920  locEventLoop->GetSingle(locMCReaction);
921 
922  ULong64_t locNumPIDThrown_FinalState = 0, locPIDThrown_Decaying = 0;
923  Compute_ThrownPIDInfo(locMCThrowns_FinalState, locMCThrowns_Decaying, locNumPIDThrown_FinalState, locPIDThrown_Decaying);
924 
925  vector<const DMCThrown*> locMCThrownsToSave;
926  map<const DMCThrown*, unsigned int> locThrownIndexMap;
927  Group_ThrownParticles(locMCThrowns_FinalState, locMCThrowns_Decaying, locMCThrownsToSave, locThrownIndexMap);
928 
929  vector<const DBeamPhoton*> locTaggedMCGenBeams;
930  locEventLoop->Get(locTaggedMCGenBeams, "TAGGEDMCGEN");
931 
932  vector<const DBeamPhoton*> locMCGenBeams;
933  locEventLoop->Get(locMCGenBeams, "MCGEN");
934 
935  const DBeamPhoton* locTaggedMCGenBeam = locTaggedMCGenBeams.empty() ? locMCGenBeams[0] : locTaggedMCGenBeams[0]; //if empty: will have to do.
936 
937  japp->RootWriteLock();
938 
939  //primary event info
940  dThrownTreeFillData.Fill_Single<UInt_t>("RunNumber", locEventLoop->GetJEvent().GetRunNumber());
941  dThrownTreeFillData.Fill_Single<ULong64_t>("EventNumber", locEventLoop->GetJEvent().GetEventNumber());
942 
943  //throwns
944  Fill_ThrownInfo(&dThrownTreeFillData, locMCReaction, locTaggedMCGenBeam, locMCThrownsToSave, locThrownIndexMap, locNumPIDThrown_FinalState, locPIDThrown_Decaying);
945 
946  //Custom Branches
947  Fill_CustomBranches_ThrownTree(&dThrownTreeFillData, locEventLoop, locMCReaction, locMCThrownsToSave);
948 
949  //FILL TTREE
951 
952 
953  japp->RootUnLock();
954 
955 }
956 
957 void DEventWriterROOT::Fill_DataTrees(JEventLoop* locEventLoop, string locDReactionTag) const
958 {
959  if(locDReactionTag == "Thrown")
960  {
961  cout << "WARNING: CANNOT FILL THROWN TREE WITH THIS FUNCTION." << endl;
962  return;
963  }
964 
965  vector<const DAnalysisResults*> locAnalysisResultsVector;
966  locEventLoop->Get(locAnalysisResultsVector);
967 
968  vector<const DReaction*> locReactionsWithTag;
969  locEventLoop->Get(locReactionsWithTag, locDReactionTag.c_str());
970 
971  for(size_t loc_i = 0; loc_i < locAnalysisResultsVector.size(); ++loc_i)
972  {
973  deque<const DParticleCombo*> locPassedParticleCombos;
974  locAnalysisResultsVector[loc_i]->Get_PassedParticleCombos(locPassedParticleCombos);
975  if(locPassedParticleCombos.empty())
976  continue;
977 
978  const DReaction* locReaction = locAnalysisResultsVector[loc_i]->Get_Reaction();
979  if(!locReaction->Get_EnableTTreeOutputFlag())
980  continue;
981 
982  bool locReactionFoundFlag = false;
983  for(size_t loc_j = 0; loc_j < locReactionsWithTag.size(); ++loc_j)
984  {
985  if(locReactionsWithTag[loc_j] != locReaction)
986  continue;
987  locReactionFoundFlag = true;
988  break;
989  }
990  if(!locReactionFoundFlag)
991  continue; //reaction not from this factory, continue
992 
993  Fill_DataTree(locEventLoop, locReaction, locPassedParticleCombos);
994  }
995 }
996 
997 void DEventWriterROOT::Fill_DataTree(JEventLoop* locEventLoop, const DReaction* locReaction, deque<const DParticleCombo*>& locParticleCombos) const
998 {
999  if(locReaction->Get_ReactionName() == "Thrown")
1000  {
1001  cout << "WARNING: CANNOT FILL THROWN TREE WITH THIS FUNCTION." << endl;
1002  return;
1003  }
1004 
1005  if(!locReaction->Get_EnableTTreeOutputFlag())
1006  {
1007  cout << "WARNING: ROOT TTREE OUTPUT NOT ENABLED FOR THIS DREACTION (" << locReaction->Get_ReactionName() << ")" << endl;
1008  return;
1009  }
1010 
1011  /***************************************************** GET THROWN INFO *****************************************************/
1012 
1013  vector<const DMCThrown*> locMCThrowns_FinalState;
1014  locEventLoop->Get(locMCThrowns_FinalState, "FinalState");
1015 
1016  vector<const DMCThrown*> locMCThrowns_Decaying;
1017  locEventLoop->Get(locMCThrowns_Decaying, "Decaying");
1018 
1019  vector<const DMCThrownMatching*> locMCThrownMatchingVector;
1020  locEventLoop->Get(locMCThrownMatchingVector);
1021  const DMCThrownMatching* locMCThrownMatching = locMCThrownMatchingVector.empty() ? NULL : locMCThrownMatchingVector[0];
1022 
1023  vector<const DMCReaction*> locMCReactions;
1024  locEventLoop->Get(locMCReactions);
1025  const DMCReaction* locMCReaction = locMCReactions.empty() ? NULL : locMCReactions[0];
1026 
1027  vector<const DBeamPhoton*> locTaggedMCGenBeams;
1028  locEventLoop->Get(locTaggedMCGenBeams, "TAGGEDMCGEN");
1029 
1030  vector<const DBeamPhoton*> locMCGenBeams;
1031  locEventLoop->Get(locMCGenBeams, "MCGEN");
1032 
1033  const DBeamPhoton* locTaggedMCGenBeam = nullptr;
1034 
1035  if (locTaggedMCGenBeams.empty()){
1036  if ( !locMCGenBeams.empty() ) locTaggedMCGenBeam = locMCGenBeams[0];
1037  }
1038  else locTaggedMCGenBeam = locTaggedMCGenBeams[0];
1039 
1040  //Pre-compute thrown info
1041  ULong64_t locNumPIDThrown_FinalState = 0, locPIDThrown_Decaying = 0;
1042  Compute_ThrownPIDInfo(locMCThrowns_FinalState, locMCThrowns_Decaying, locNumPIDThrown_FinalState, locPIDThrown_Decaying);
1043 
1044  //Pre-compute thrown info
1045  vector<const DMCThrown*> locMCThrownsToSave;
1046  map<const DMCThrown*, unsigned int> locThrownIndexMap;
1047  Group_ThrownParticles(locMCThrowns_FinalState, locMCThrowns_Decaying, locMCThrownsToSave, locThrownIndexMap);
1048 
1049  /****************************************************** GET PARTICLES ******************************************************/
1050 
1051  bool locSaveUnusedFlag = locReaction->Get_SaveUnusedFlag();
1052 
1053  //Get PIDs need for reaction
1054  auto locDetectedPIDs = locReaction->Get_FinalPIDs(-1, false, false, d_AllCharges, false);
1055  set<Particle_t> locReactionPIDs;
1056  for(size_t loc_j = 0; loc_j < locDetectedPIDs.size(); ++loc_j)
1057  locReactionPIDs.insert(locDetectedPIDs[loc_j]);
1058 
1059  //GET HYPOTHESES
1060  vector<const DChargedTrackHypothesis*> locChargedTrackHypotheses;
1061  vector<const DNeutralParticleHypothesis*> locNeutralParticleHypotheses;
1062  if(locSaveUnusedFlag)
1063  {
1064  locChargedTrackHypotheses = Get_ChargedHypotheses(locEventLoop);
1065  locNeutralParticleHypotheses = Get_NeutralHypotheses(locEventLoop, locReactionPIDs);
1066  }
1067  else
1068  {
1069  locChargedTrackHypotheses = Get_ChargedHypotheses_Used(locEventLoop, locReaction, locParticleCombos);
1070  locNeutralParticleHypotheses = Get_NeutralHypotheses_Used(locEventLoop, locReaction, locReactionPIDs, locParticleCombos);
1071  }
1072 
1073  //GET BEAM PHOTONS
1074  bool locBeamUsedFlag = DAnalysis::Get_IsFirstStepBeam(locReaction);
1075  vector<const DBeamPhoton*> locBeamPhotons = Get_BeamPhotons(locParticleCombos);
1076 
1077  //create map of particles to array index:
1078  //used for pointing combo particles to the appropriate measured-particle array index
1079  //for hypos, they are the preselect versions if they exist, else the combo versions (e.g. PID not in REST)
1080 
1081  //indices: beam
1082  map<pair<oid_t, Particle_t>, size_t> locObjectToArrayIndexMap; //particle_t necessary for neutral showers!
1083  for(size_t loc_i = 0; loc_i < locBeamPhotons.size(); ++loc_i)
1084  {
1085  pair<oid_t, Particle_t> locBeamPair(locBeamPhotons[loc_i]->id, locBeamPhotons[loc_i]->PID());
1086  locObjectToArrayIndexMap[locBeamPair] = loc_i;
1087  }
1088 
1089  //indices: charged
1090  for(size_t loc_i = 0; loc_i < locChargedTrackHypotheses.size(); ++loc_i)
1091  {
1092  const DTrackTimeBased* locTrackTimeBased = locChargedTrackHypotheses[loc_i]->Get_TrackTimeBased();
1093  pair<oid_t, Particle_t> locTrackPair(locTrackTimeBased->id, locTrackTimeBased->PID());
1094  locObjectToArrayIndexMap[locTrackPair] = loc_i;
1095  }
1096 
1097  //indices: neutral
1098  for(size_t loc_i = 0; loc_i < locNeutralParticleHypotheses.size(); ++loc_i)
1099  {
1100  const DNeutralShower* locNeutralShower = locNeutralParticleHypotheses[loc_i]->Get_NeutralShower();
1101  pair<oid_t, Particle_t> locShowerPair(locNeutralShower->id, locNeutralParticleHypotheses[loc_i]->PID());
1102  locObjectToArrayIndexMap[locShowerPair] = loc_i;
1103  }
1104 
1105  /**************************************************** GET MISCELLANEOUS ****************************************************/
1106 
1107  //GET DETECTOR MATCHES
1108  const DDetectorMatches* locDetectorMatches = NULL;
1109  locEventLoop->GetSingle(locDetectorMatches);
1110 
1111  //GET DVERTEX
1112  const DVertex* locVertex = NULL;
1113  locEventLoop->GetSingle(locVertex);
1114 
1115  //GET TRIGGER
1116  const DTrigger* locTrigger = NULL;
1117  locEventLoop->GetSingle(locTrigger);
1118 
1119  /************************************************* EXECUTE ANALYSIS ACTIONS ************************************************/
1120 
1121  japp->RootWriteLock();
1122 
1123  Bool_t locIsThrownTopologyFlag = kFALSE;
1124  vector<Bool_t> locIsTrueComboFlags;
1125  vector<Bool_t> locIsBDTSignalComboFlags;
1126  if(locMCReaction != NULL)
1127  {
1128  DCutAction_ThrownTopology* locThrownTopologyAction = dCutActionMap_ThrownTopology.find(locReaction)->second;
1129  locIsThrownTopologyFlag = (*locThrownTopologyAction)(locEventLoop, NULL); //combo not used/needed
1130  for(size_t loc_i = 0; loc_i < locParticleCombos.size(); ++loc_i)
1131  {
1132  DCutAction_TrueCombo* locTrueComboAction = dCutActionMap_TrueCombo.find(locReaction)->second;
1133  locIsTrueComboFlags.push_back((*locTrueComboAction)(locEventLoop, locParticleCombos[loc_i]));
1134 
1135  DCutAction_BDTSignalCombo* locBDTSignalComboAction = dCutActionMap_BDTSignalCombo.find(locReaction)->second;
1136  locIsBDTSignalComboFlags.push_back((*locBDTSignalComboAction)(locEventLoop, locParticleCombos[loc_i]));
1137  }
1138  }
1139 
1140  /***************************************************** FILL TTREE DATA *****************************************************/
1141 
1142  //Get tree fill data
1143  DTreeFillData* locTreeFillData = dTreeFillDataMap.find(locReaction)->second;
1144 
1145  //PRIMARY EVENT INFO
1146  locTreeFillData->Fill_Single<UInt_t>("RunNumber", locEventLoop->GetJEvent().GetRunNumber());
1147  locTreeFillData->Fill_Single<ULong64_t>("EventNumber", locEventLoop->GetJEvent().GetEventNumber());
1148  locTreeFillData->Fill_Single<UInt_t>("L1TriggerBits", locTrigger->Get_L1TriggerBits());
1149 
1150  //PRODUCTION X4
1151  DLorentzVector locProductionX4 = locVertex->dSpacetimeVertex;
1152  TLorentzVector locProductionTX4(locProductionX4.X(), locProductionX4.Y(), locProductionX4.Z(), locProductionX4.T());
1153  locTreeFillData->Fill_Single<TLorentzVector>("X4_Production", locProductionTX4);
1154 
1155  //THROWN INFORMATION
1156  if(locMCReaction != NULL)
1157  {
1158  Fill_ThrownInfo(locTreeFillData, locMCReaction, locTaggedMCGenBeam, locMCThrownsToSave, locThrownIndexMap, locNumPIDThrown_FinalState, locPIDThrown_Decaying, locMCThrownMatching);
1159  locTreeFillData->Fill_Single<Bool_t>("IsThrownTopology", locIsThrownTopologyFlag);
1160  }
1161 
1162  //INDEPENDENT BEAM PARTICLES
1163  if(locBeamUsedFlag)
1164  {
1165  //however, only fill with beam particles that are in the combos
1166  locTreeFillData->Fill_Single<UInt_t>("NumBeam", UInt_t(locBeamPhotons.size()));
1167  for(size_t loc_i = 0; loc_i < locBeamPhotons.size(); ++loc_i)
1168  Fill_BeamData(locTreeFillData, loc_i, locBeamPhotons[loc_i], locVertex, locMCThrownMatching);
1169  }
1170 
1171  //INDEPENDENT CHARGED TRACKS
1172  locTreeFillData->Fill_Single<UInt_t>("NumChargedHypos", UInt_t(locChargedTrackHypotheses.size()));
1173  for(size_t loc_i = 0; loc_i < locChargedTrackHypotheses.size(); ++loc_i)
1174  Fill_ChargedHypo(locTreeFillData, loc_i, locChargedTrackHypotheses[loc_i], locMCThrownMatching, locThrownIndexMap, locDetectorMatches);
1175 
1176  //INDEPENDENT NEUTRAL PARTICLES
1177  locTreeFillData->Fill_Single<UInt_t>("NumNeutralHypos", UInt_t(locNeutralParticleHypotheses.size()));
1178  for(size_t loc_i = 0; loc_i < locNeutralParticleHypotheses.size(); ++loc_i)
1179  Fill_NeutralHypo(locTreeFillData, loc_i, locNeutralParticleHypotheses[loc_i], locMCThrownMatching, locThrownIndexMap, locDetectorMatches);
1180 
1181  //UNUSED TRACKS
1182  double locSumPMag_UnusedTracks = 0.0;
1183  TVector3 locSumP3_UnusedTracks;
1184  int locNumUnusedTracks = dAnalysisUtilities->Calc_Momentum_UnusedTracks(locEventLoop, locParticleCombos[0], locSumPMag_UnusedTracks, locSumP3_UnusedTracks);
1185  locTreeFillData->Fill_Single<UChar_t>("NumUnusedTracks", locNumUnusedTracks);
1186 
1187  //COMBOS
1188  locTreeFillData->Fill_Single<UInt_t>("NumCombos", UInt_t(locParticleCombos.size()));
1189  for(size_t loc_i = 0; loc_i < locParticleCombos.size(); ++loc_i)
1190  {
1191  Fill_ComboData(locTreeFillData, locReaction, locParticleCombos[loc_i], loc_i, locObjectToArrayIndexMap);
1192 
1193  //ENERGY OF UNUSED SHOWERS (access to event loop required)
1194  double locEnergy_UnusedShowers = dAnalysisUtilities->Calc_Energy_UnusedShowers(locEventLoop, locParticleCombos[loc_i]);
1195  locTreeFillData->Fill_Array<Float_t>("Energy_UnusedShowers", locEnergy_UnusedShowers, loc_i);
1196 
1197  //MOMENTUM OF UNUSED TRACKS (access to event loop required)
1198  double locSumPMag_UnusedTracks = 0;
1199  TVector3 locSumP3_UnusedTracks;
1200  dAnalysisUtilities->Calc_Momentum_UnusedTracks(locEventLoop, locParticleCombos[loc_i], locSumPMag_UnusedTracks, locSumP3_UnusedTracks);
1201  locTreeFillData->Fill_Array<Float_t>("SumPMag_UnusedTracks", locSumPMag_UnusedTracks, loc_i);
1202  locTreeFillData->Fill_Array<TVector3>("SumP3_UnusedTracks", locSumP3_UnusedTracks, loc_i);
1203 
1204  if(locMCReaction != NULL)
1205  {
1206  locTreeFillData->Fill_Array<Bool_t>("IsTrueCombo", locIsTrueComboFlags[loc_i], loc_i);
1207  locTreeFillData->Fill_Array<Bool_t>("IsBDTSignalCombo", locIsTrueComboFlags[loc_i], loc_i);
1208  }
1209  }
1210 
1211  //CUSTOM
1212  Fill_CustomBranches_DataTree(locTreeFillData, locEventLoop, locReaction, locMCReaction, locMCThrownsToSave, locMCThrownMatching, locDetectorMatches, locBeamPhotons, locChargedTrackHypotheses, locNeutralParticleHypotheses, locParticleCombos);
1213 
1214  //FILL
1215  DTreeInterface* locTreeInterface = dTreeInterfaceMap.find(locReaction)->second;
1216  locTreeInterface->Fill(*locTreeFillData);
1217 
1218  japp->RootUnLock();
1219 
1220 }
1221 
1222 vector<const DBeamPhoton*> DEventWriterROOT::Get_BeamPhotons(const deque<const DParticleCombo*>& locParticleCombos) const
1223 {
1224  //however, only fill with beam particles that are in the combos
1225  set<const DBeamPhoton*> locBeamPhotonSet;
1226  vector<const DBeamPhoton*> locBeamPhotons;
1227  for(size_t loc_j = 0; loc_j < locParticleCombos.size(); ++loc_j)
1228  {
1229  const DParticleComboStep* locParticleComboStep = locParticleCombos[loc_j]->Get_ParticleComboStep(0);
1230  const DKinematicData* locKinematicData = locParticleComboStep->Get_InitialParticle_Measured();
1231  if(locKinematicData == NULL)
1232  continue;
1233  const DBeamPhoton* locBeamPhoton = dynamic_cast<const DBeamPhoton*>(locKinematicData);
1234  if(locBeamPhoton == NULL)
1235  continue;
1236  if(locBeamPhotonSet.find(locBeamPhoton) != locBeamPhotonSet.end())
1237  continue; //already included
1238  locBeamPhotonSet.insert(locBeamPhoton);
1239  locBeamPhotons.push_back(locBeamPhoton);
1240  }
1241 
1242  return locBeamPhotons;
1243 }
1244 
1245 vector<const DChargedTrackHypothesis*> DEventWriterROOT::Get_ChargedHypotheses(JEventLoop* locEventLoop) const
1246 {
1247  //For default/preselect, save all
1248  //For combo, of new PIDs ONLY, save one of each for each track
1249  //save the one with the same RF bunch as the common bunch
1250 
1251  vector<const DChargedTrack*> locChargedTracks;
1252  locEventLoop->Get(locChargedTracks, "Combo");
1253 
1254  vector<const DChargedTrackHypothesis*> locChargedHyposToSave;
1255  for(auto& locChargedTrack : locChargedTracks)
1256  locChargedHyposToSave.insert(locChargedHyposToSave.end(), locChargedTrack->dChargedTrackHypotheses.begin(), locChargedTrack->dChargedTrackHypotheses.end());
1257 
1258  return locChargedHyposToSave;
1259 }
1260 
1261 vector<const DChargedTrackHypothesis*> DEventWriterROOT::Get_ChargedHypotheses_Used(JEventLoop* locEventLoop, const DReaction* locReaction, const deque<const DParticleCombo*>& locParticleCombos) const
1262 {
1263  //get all hypos
1264  vector<const DChargedTrackHypothesis*> locAllHypos = Get_ChargedHypotheses(locEventLoop);
1265 
1266  //get used time-based tracks
1267  set<const DTrackTimeBased*> locUsedTimeBasedTracks;
1268  for(auto& locCombo : locParticleCombos)
1269  {
1270  auto locChargedParticles = locCombo->Get_FinalParticles_Measured(locReaction, d_Charged);
1271  for(auto& locParticle : locChargedParticles)
1272  locUsedTimeBasedTracks.insert(static_cast<const DChargedTrackHypothesis*>(locParticle)->Get_TrackTimeBased());
1273  }
1274 
1275  //loop through "all" hypos, removing those that weren't used
1276  for(auto locIterator = locAllHypos.begin(); locIterator != locAllHypos.end();)
1277  {
1278  const DTrackTimeBased* locTrackTimeBased = (*locIterator)->Get_TrackTimeBased();
1279  if(locUsedTimeBasedTracks.find(locTrackTimeBased) != locUsedTimeBasedTracks.end())
1280  ++locIterator;
1281  else
1282  locIterator = locAllHypos.erase(locIterator);
1283  }
1284 
1285  return locAllHypos;
1286 }
1287 
1288 vector<const DNeutralParticleHypothesis*> DEventWriterROOT::Get_NeutralHypotheses(JEventLoop* locEventLoop, const set<Particle_t>& locReactionPIDs) const
1289 {
1290  //For default/preselect, save all
1291  //For combo, of new PIDs ONLY, save one of each for each shower
1292  //save the one with the same RF bunch as the common bunch
1293 
1294  vector<const DNeutralParticle*> locNeutralParticles;
1295  locEventLoop->Get(locNeutralParticles, "Combo");
1296 
1297  vector<const DNeutralParticleHypothesis*> locNeutralHyposToSave;
1298  for(auto& locNeutralParticle : locNeutralParticles)
1299  locNeutralHyposToSave.insert(locNeutralHyposToSave.end(), locNeutralParticle->dNeutralParticleHypotheses.begin(), locNeutralParticle->dNeutralParticleHypotheses.end());
1300 
1301  return locNeutralHyposToSave;
1302 }
1303 
1304 vector<const DNeutralParticleHypothesis*> DEventWriterROOT::Get_NeutralHypotheses_Used(JEventLoop* locEventLoop, const DReaction* locReaction, const set<Particle_t>& locReactionPIDs, const deque<const DParticleCombo*>& locParticleCombos) const
1305 {
1306  //get all hypos
1307  vector<const DNeutralParticleHypothesis*> locAllHypos = Get_NeutralHypotheses(locEventLoop, locReactionPIDs);
1308 
1309  //get used showers
1310  set<pair<const DNeutralShower*, Particle_t> > locUsedNeutralShowers;
1311  for(auto& locCombo : locParticleCombos)
1312  {
1313  auto locNeutralParticles = locCombo->Get_FinalParticles_Measured(locReaction, d_Neutral);
1314  for(auto& locParticle : locNeutralParticles)
1315  {
1316  const DNeutralShower* locNeutralShower = static_cast<const DNeutralParticleHypothesis*>(locParticle)->Get_NeutralShower();
1317  pair<const DNeutralShower*, Particle_t> locShowerPair(locNeutralShower, locParticle->PID());
1318  locUsedNeutralShowers.insert(locShowerPair);
1319  }
1320  }
1321 
1322  //loop through "all" hypos, removing those that weren't used
1323  for(auto locIterator = locAllHypos.begin(); locIterator != locAllHypos.end();)
1324  {
1325  const DNeutralShower* locNeutralShower = (*locIterator)->Get_NeutralShower();
1326  pair<const DNeutralShower*, Particle_t> locShowerPair(locNeutralShower, (*locIterator)->PID());
1327  if(locUsedNeutralShowers.find(locShowerPair) == locUsedNeutralShowers.end())
1328  locIterator = locAllHypos.erase(locIterator);
1329  else
1330  ++locIterator;
1331  }
1332 
1333  return locAllHypos;
1334 }
1335 
1337 {
1338  int locPower = ParticleMultiplexPower(locPID);
1339  if(locPower == -1)
1340  return 0;
1341 
1342  int locIsFinalStateInt = Is_FinalStateParticle(locPID);
1343  if(locPID == Pi0)
1344  locIsFinalStateInt = 1;
1345 
1346  if(locIsFinalStateInt == 1) //decimal
1347  {
1348  ULong64_t locParticleMultiplexID = 1;
1349  for(int loc_i = 0; loc_i < locPower; ++loc_i)
1350  locParticleMultiplexID *= ULong64_t(10);
1351  return locParticleMultiplexID;
1352  }
1353  //decaying: binary
1354  return (ULong64_t(1) << ULong64_t(locPower)); //bit-shift
1355 }
1356 
1357 void DEventWriterROOT::Compute_ThrownPIDInfo(const vector<const DMCThrown*>& locMCThrowns_FinalState, const vector<const DMCThrown*>& locMCThrowns_Decaying, ULong64_t& locNumPIDThrown_FinalState, ULong64_t& locPIDThrown_Decaying) const
1358 {
1359  //THROWN PARTICLES BY PID
1360  locNumPIDThrown_FinalState = 0;
1361  for(size_t loc_i = 0; loc_i < locMCThrowns_FinalState.size(); ++loc_i) //final state
1362  {
1363  Particle_t locPID = locMCThrowns_FinalState[loc_i]->PID();
1364  ULong64_t locPIDMultiplexID = Calc_ParticleMultiplexID(locPID);
1365  if(locPIDMultiplexID == 0)
1366  continue; //unrecognized PID!!!
1367  unsigned int locCurrentNumParticles = (locNumPIDThrown_FinalState / locPIDMultiplexID) % ULong64_t(10);
1368  if(locCurrentNumParticles != 9)
1369  locNumPIDThrown_FinalState += locPIDMultiplexID;
1370  }
1371 
1372  locPIDThrown_Decaying = 0;
1373  for(size_t loc_i = 0; loc_i < locMCThrowns_Decaying.size(); ++loc_i) //decaying
1374  {
1375  Particle_t locPID = locMCThrowns_Decaying[loc_i]->PID();
1376  ULong64_t locPIDMultiplexID = Calc_ParticleMultiplexID(locPID);
1377  if(locPIDMultiplexID == 0)
1378  continue; //unrecognized PID!!!
1379  if(locPID != Pi0)
1380  locPIDThrown_Decaying |= locPIDMultiplexID; //bit-wise or
1381  else //save pi0's as final state instead of decaying
1382  {
1383  unsigned int locCurrentNumParticles = (locNumPIDThrown_FinalState / locPIDMultiplexID) % ULong64_t(10);
1384  if(locCurrentNumParticles != 9)
1385  locNumPIDThrown_FinalState += locPIDMultiplexID;
1386  }
1387  }
1388 }
1389 
1390 void DEventWriterROOT::Group_ThrownParticles(const vector<const DMCThrown*>& locMCThrowns_FinalState, const vector<const DMCThrown*>& locMCThrowns_Decaying, vector<const DMCThrown*>& locMCThrownsToSave, map<const DMCThrown*, unsigned int>& locThrownIndexMap) const
1391 {
1392  locMCThrownsToSave.clear();
1393  locMCThrownsToSave.insert(locMCThrownsToSave.end(), locMCThrowns_FinalState.begin(), locMCThrowns_FinalState.end());
1394  locMCThrownsToSave.insert(locMCThrownsToSave.end(), locMCThrowns_Decaying.begin(), locMCThrowns_Decaying.end());
1395 
1396  //create map of mcthrown to array index
1397  locThrownIndexMap.clear();
1398  for(size_t loc_i = 0; loc_i < locMCThrownsToSave.size(); ++loc_i)
1399  locThrownIndexMap[locMCThrownsToSave[loc_i]] = loc_i;
1400 }
1401 
1402 void DEventWriterROOT::Fill_ThrownInfo(DTreeFillData* locTreeFillData, const DMCReaction* locMCReaction, const DBeamPhoton* locTaggedMCGenBeam, const vector<const DMCThrown*>& locMCThrowns, const map<const DMCThrown*, unsigned int>& locThrownIndexMap, ULong64_t locNumPIDThrown_FinalState, ULong64_t locPIDThrown_Decaying, const DMCThrownMatching* locMCThrownMatching) const
1403 {
1404  //THIS MUST BE CALLED FROM WITHIN A LOCK, SO DO NOT PASS IN JEVENTLOOP! //TOO TEMPTING TO DO SOMETHING BAD
1405 
1406  //WEIGHT
1407  locTreeFillData->Fill_Single<Float_t>("MCWeight", locMCReaction->weight);
1408 
1409  //THROWN BEAM
1410  locTreeFillData->Fill_Single<Int_t>(Build_BranchName("ThrownBeam", "PID"), PDGtype(locMCReaction->beam.PID()));
1411  locTreeFillData->Fill_Single<Float_t>(Build_BranchName("ThrownBeam", "GeneratedEnergy"), locMCReaction->beam.energy());
1412 
1413  DVector3 locThrownBeamX3 = locMCReaction->beam.position();
1414  TLorentzVector locThrownBeamTX4(locThrownBeamX3.X(), locThrownBeamX3.Y(), locThrownBeamX3.Z(), locMCReaction->beam.time());
1415  locTreeFillData->Fill_Single<TLorentzVector>(Build_BranchName("ThrownBeam", "X4"), locThrownBeamTX4);
1416 
1417  DLorentzVector locThrownBeamP4 = locTaggedMCGenBeam->lorentzMomentum();
1418  TLorentzVector locThrownBeamTP4(locThrownBeamP4.Px(), locThrownBeamP4.Py(), locThrownBeamP4.Pz(), locThrownBeamP4.E());
1419  locTreeFillData->Fill_Single<TLorentzVector>(Build_BranchName("ThrownBeam", "P4"), locThrownBeamTP4);
1420 
1421  //THROWN PRODUCTS
1422  locTreeFillData->Fill_Single<UInt_t>("NumThrown", locMCThrowns.size());
1423  for(size_t loc_i = 0; loc_i < locMCThrowns.size(); ++loc_i)
1424  Fill_ThrownParticleData(locTreeFillData, loc_i, locMCThrowns[loc_i], locThrownIndexMap, locMCThrownMatching);
1425 
1426  //PID INFO
1427  locTreeFillData->Fill_Single<ULong64_t>("NumPIDThrown_FinalState", locNumPIDThrown_FinalState);
1428  locTreeFillData->Fill_Single<ULong64_t>("PIDThrown_Decaying", locPIDThrown_Decaying);
1429 }
1430 
1431 void DEventWriterROOT::Fill_ThrownParticleData(DTreeFillData* locTreeFillData, unsigned int locArrayIndex, const DMCThrown* locMCThrown, const map<const DMCThrown*, unsigned int>& locThrownIndexMap, const DMCThrownMatching* locMCThrownMatching) const
1432 {
1433  string locParticleBranchName = "Thrown";
1434 
1435  //IDENTIFIERS
1436  int locParentIndex = -1; //e.g. photoproduced
1437  map<const DMCThrown*, unsigned int>::const_iterator locIterator;
1438  for(locIterator = locThrownIndexMap.begin(); locIterator != locThrownIndexMap.end(); ++locIterator)
1439  {
1440  if(locIterator->first->myid != locMCThrown->parentid)
1441  continue;
1442  locParentIndex = locIterator->second;
1443  break;
1444  }
1445  locTreeFillData->Fill_Array<Int_t>(Build_BranchName(locParticleBranchName, "ParentIndex"), locParentIndex, locArrayIndex);
1446  locTreeFillData->Fill_Array<Int_t>(Build_BranchName(locParticleBranchName, "PID"), locMCThrown->pdgtype, locArrayIndex);
1447 
1448  //MATCHING
1449  if(locMCThrownMatching != NULL)
1450  {
1451  Int_t locMatchID = -1;
1452  double locMatchFOM = -1.0;
1453  if(ParticleCharge(locMCThrown->PID()) != 0)
1454  {
1455  const DChargedTrack* locChargedTrack = locMCThrownMatching->Get_MatchingChargedTrack(locMCThrown, locMatchFOM);
1456  if(locChargedTrack != NULL)
1457  locMatchID = locChargedTrack->candidateid;
1458  }
1459  else
1460  {
1461  //Can't use DNeutralShower JObject::id (must use dShowerID):
1462  //Matching done with default-tag showers, but pre-select showers are saved to tree: JObject::id's don't match
1463  const DNeutralShower* locNeutralShower = locMCThrownMatching->Get_MatchingNeutralShower(locMCThrown, locMatchFOM);
1464  if(locNeutralShower != NULL)
1465  locMatchID = locNeutralShower->dShowerID;
1466  }
1467  locTreeFillData->Fill_Array<Int_t>(Build_BranchName(locParticleBranchName, "MatchID"), locMatchID, locArrayIndex);
1468  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "MatchFOM"), locMatchFOM, locArrayIndex);
1469  }
1470 
1471  //KINEMATICS: THROWN //at the production vertex
1472  TLorentzVector locX4_Thrown(locMCThrown->position().X(), locMCThrown->position().Y(), locMCThrown->position().Z(), locMCThrown->time());
1473  locTreeFillData->Fill_Array<TLorentzVector>(Build_BranchName(locParticleBranchName, "X4"), locX4_Thrown, locArrayIndex);
1474  TLorentzVector locP4_Thrown(locMCThrown->momentum().X(), locMCThrown->momentum().Y(), locMCThrown->momentum().Z(), locMCThrown->energy());
1475  locTreeFillData->Fill_Array<TLorentzVector>(Build_BranchName(locParticleBranchName, "P4"), locP4_Thrown, locArrayIndex);
1476 }
1477 
1478 void DEventWriterROOT::Fill_BeamData(DTreeFillData* locTreeFillData, unsigned int locArrayIndex, const DBeamPhoton* locBeamPhoton, const DVertex* locVertex, const DMCThrownMatching* locMCThrownMatching) const
1479 {
1480  string locParticleBranchName = "Beam";
1481 
1482  //IDENTIFIER
1483  locTreeFillData->Fill_Array<Int_t>(Build_BranchName(locParticleBranchName, "PID"), PDGtype(locBeamPhoton->PID()), locArrayIndex);
1484 
1485  //MATCHING
1486  if(locMCThrownMatching != NULL)
1487  {
1488  Bool_t locIsGeneratorFlag = (locMCThrownMatching->Get_TaggedMCGENBeamPhoton() == locBeamPhoton) ? kTRUE : kFALSE;
1489  locTreeFillData->Fill_Array<Bool_t>(Build_BranchName(locParticleBranchName, "IsGenerator"), locIsGeneratorFlag, locArrayIndex);
1490  }
1491 
1492  //KINEMATICS: MEASURED
1493 
1494  //use production vertex, propagate photon time
1495  DVector3 locTargetCenter = locBeamPhoton->position();
1496  DVector3 locProductionVertex = locVertex->dSpacetimeVertex.Vect();
1497  double locDeltaPath = (locProductionVertex - locTargetCenter).Mag();
1498  bool locDownstreamFlag = ((locProductionVertex.Z() - locTargetCenter.Z()) > 0.0);
1499  double locDeltaT = locDownstreamFlag ? locDeltaPath/29.9792458 : -1.0*locDeltaPath/29.9792458;
1500  double locTime = locBeamPhoton->time() + locDeltaT;
1501 
1502  TLorentzVector locX4_Measured(locProductionVertex.X(), locProductionVertex.Y(), locProductionVertex.Z(), locTime);
1503  locTreeFillData->Fill_Array<TLorentzVector>(Build_BranchName(locParticleBranchName, "X4_Measured"), locX4_Measured, locArrayIndex);
1504 
1505  DLorentzVector locDP4 = locBeamPhoton->lorentzMomentum();
1506  TLorentzVector locP4_Measured(locDP4.Px(), locDP4.Py(), locDP4.Pz(), locDP4.E());
1507  locTreeFillData->Fill_Array<TLorentzVector>(Build_BranchName(locParticleBranchName, "P4_Measured"), locP4_Measured, locArrayIndex);
1508 }
1509 
1510 void DEventWriterROOT::Fill_ChargedHypo(DTreeFillData* locTreeFillData, unsigned int locArrayIndex, const DChargedTrackHypothesis* locChargedTrackHypothesis, const DMCThrownMatching* locMCThrownMatching, const map<const DMCThrown*, unsigned int>& locThrownIndexMap, const DDetectorMatches* locDetectorMatches) const
1511 {
1512  string locParticleBranchName = "ChargedHypo";
1513 
1514  //ASSOCIATED OBJECTS
1515  auto locTrackTimeBased = locChargedTrackHypothesis->Get_TrackTimeBased();
1516 
1517  const DBCALShower* locBCALShower = NULL;
1518  if(locChargedTrackHypothesis->Get_BCALShowerMatchParams() != NULL)
1519  locBCALShower = locChargedTrackHypothesis->Get_BCALShowerMatchParams()->dBCALShower;
1520 
1521  const DFCALShower* locFCALShower = NULL;
1522  if(locChargedTrackHypothesis->Get_FCALShowerMatchParams() != NULL)
1523  locFCALShower = locChargedTrackHypothesis->Get_FCALShowerMatchParams()->dFCALShower;
1524 
1525  //IDENTIFIERS
1526  locTreeFillData->Fill_Array<Int_t>(Build_BranchName(locParticleBranchName, "TrackID"), locTrackTimeBased->candidateid, locArrayIndex);
1527  locTreeFillData->Fill_Array<Int_t>(Build_BranchName(locParticleBranchName, "PID"), PDGtype(locChargedTrackHypothesis->PID()), locArrayIndex);
1528 
1529  //MATCHING
1530  if(locMCThrownMatching != NULL)
1531  {
1532  Int_t locThrownIndex = -1;
1533  double locMatchFOM = 0.0;
1534  const DMCThrown* locMCThrown = locMCThrownMatching->Get_MatchingMCThrown(locChargedTrackHypothesis, locMatchFOM);
1535  if(locMCThrown != NULL)
1536  locThrownIndex = locThrownIndexMap.find(locMCThrown)->second;
1537  locTreeFillData->Fill_Array<Int_t>(Build_BranchName(locParticleBranchName, "ThrownIndex"), locThrownIndex, locArrayIndex);
1538  }
1539 
1540  //KINEMATICS: MEASURED
1541  DVector3 locPosition = locChargedTrackHypothesis->position();
1542  TLorentzVector locTX4_Measured(locPosition.X(), locPosition.Y(), locPosition.Z(), locChargedTrackHypothesis->time());
1543  locTreeFillData->Fill_Array<TLorentzVector>(Build_BranchName(locParticleBranchName, "X4_Measured"), locTX4_Measured, locArrayIndex);
1544 
1545  DLorentzVector locDP4 = locChargedTrackHypothesis->lorentzMomentum();
1546  TLorentzVector locP4_Measured(locDP4.Px(), locDP4.Py(), locDP4.Pz(), locDP4.E());
1547  locTreeFillData->Fill_Array<TLorentzVector>(Build_BranchName(locParticleBranchName, "P4_Measured"), locP4_Measured, locArrayIndex);
1548 
1549  //TRACKING INFO
1550  locTreeFillData->Fill_Array<UInt_t>(Build_BranchName(locParticleBranchName, "NDF_Tracking"), locTrackTimeBased->Ndof, locArrayIndex);
1551  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "ChiSq_Tracking"), locTrackTimeBased->chisq, locArrayIndex);
1552  locTreeFillData->Fill_Array<UInt_t>(Build_BranchName(locParticleBranchName, "NDF_DCdEdx"), locChargedTrackHypothesis->Get_NDF_DCdEdx(), locArrayIndex);
1553  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "ChiSq_DCdEdx"), locChargedTrackHypothesis->Get_ChiSq_DCdEdx(), locArrayIndex);
1554  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "dEdx_CDC"), locTrackTimeBased->ddEdx_CDC_amp, locArrayIndex);
1555  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "dEdx_CDC_integral"), locTrackTimeBased->ddEdx_CDC, locArrayIndex);
1556  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "dEdx_FDC"), locTrackTimeBased->ddEdx_FDC, locArrayIndex);
1557 
1558  //HIT ENERGY
1559  double locTOFdEdx = (locChargedTrackHypothesis->Get_TOFHitMatchParams() != NULL) ? locChargedTrackHypothesis->Get_TOFHitMatchParams()->dEdx : 0.0;
1560  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "dEdx_TOF"), locTOFdEdx, locArrayIndex);
1561  double locSCdEdx = (locChargedTrackHypothesis->Get_SCHitMatchParams() != NULL) ? locChargedTrackHypothesis->Get_SCHitMatchParams()->dEdx : 0.0;
1562  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "dEdx_ST"), locSCdEdx, locArrayIndex);
1563  double locBCALEnergy = (locBCALShower != NULL) ? locBCALShower->E : 0.0;
1564  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "Energy_BCAL"), locBCALEnergy, locArrayIndex);
1565  double locBCALPreshowerEnergy = (locBCALShower != NULL) ? locBCALShower->E_preshower : 0.0;
1566  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "Energy_BCALPreshower"), locBCALPreshowerEnergy, locArrayIndex);
1567  if(BCAL_VERBOSE_OUTPUT) {
1568  double locBCALLayer2Energy = (locBCALShower != NULL) ? locBCALShower->E_L2 : 0.0;
1569  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "Energy_BCALLayer2"), locBCALLayer2Energy, locArrayIndex);
1570  double locBCALLayer3Energy = (locBCALShower != NULL) ? locBCALShower->E_L3 : 0.0;
1571  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "Energy_BCALLayer3"), locBCALLayer3Energy, locArrayIndex);
1572  double locBCALLayer4Energy = (locBCALShower != NULL) ? locBCALShower->E_L4 : 0.0;
1573  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "Energy_BCALLayer4"), locBCALLayer4Energy, locArrayIndex);
1574  }
1575 
1576  double locFCALEnergy = (locFCALShower != NULL) ? locFCALShower->getEnergy() : 0.0;
1577  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "Energy_FCAL"), locFCALEnergy, locArrayIndex);
1578 
1579  //SHOWER PROPERTIES
1580  double locSigLongBCAL = (locBCALShower != NULL) ? locBCALShower->sigLong : 0.0;
1581  double locSigThetaBCAL = (locBCALShower != NULL) ? locBCALShower->sigTheta : 0.0;
1582  double locSigTransBCAL = (locBCALShower != NULL) ? locBCALShower->sigTrans : 0.0;
1583  double locRMSTimeBCAL = (locBCALShower != NULL) ? locBCALShower->rmsTime : 0.0;
1584  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "SigLong_BCAL"), locSigLongBCAL, locArrayIndex);
1585  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "SigTheta_BCAL"), locSigThetaBCAL, locArrayIndex);
1586  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "SigTrans_BCAL"), locSigTransBCAL, locArrayIndex);
1587  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "RMSTime_BCAL"), locRMSTimeBCAL, locArrayIndex);
1588 
1589  double locE1E9FCAL = (locFCALShower != NULL) ? locFCALShower->getE1E9() : 0.0;
1590  double locE9E25FCAL = (locFCALShower != NULL) ? locFCALShower->getE9E25() : 0.0;
1591  double locSumUFCAL = (locFCALShower != NULL) ? locFCALShower->getSumU() : 0.0;
1592  double locSumVFCAL = (locFCALShower != NULL) ? locFCALShower->getSumV() : 0.0;
1593  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "E1E9_FCAL"), locE1E9FCAL, locArrayIndex);
1594  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "E9E25_FCAL"), locE9E25FCAL, locArrayIndex);
1595  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "SumU_FCAL"), locSumUFCAL, locArrayIndex);
1596  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "SumV_FCAL"), locSumVFCAL, locArrayIndex);
1597 
1598  //TIMING INFO
1599  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "HitTime"), locChargedTrackHypothesis->t1(), locArrayIndex);
1600  double locStartTimeError = locChargedTrackHypothesis->t0_err();
1601  double locRFDeltaTVariance = (*locChargedTrackHypothesis->errorMatrix())(6, 6) + locStartTimeError*locStartTimeError;
1602  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "RFDeltaTVar"), locRFDeltaTVariance, locArrayIndex);
1603 
1604  //MEASURED PID INFO
1605  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "Beta_Timing"), locChargedTrackHypothesis->measuredBeta(), locArrayIndex);
1606  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "ChiSq_Timing"), locChargedTrackHypothesis->Get_ChiSq_Timing(), locArrayIndex);
1607  locTreeFillData->Fill_Array<UInt_t>(Build_BranchName(locParticleBranchName, "NDF_Timing"), locChargedTrackHypothesis->Get_NDF_Timing(), locArrayIndex);
1608 
1609  //SHOWER MATCHING: BCAL
1610  double locTrackBCAL_DeltaPhi = 999.0, locTrackBCAL_DeltaZ = 999.0;
1611  if(locChargedTrackHypothesis->Get_BCALShowerMatchParams() != NULL)
1612  {
1613  locTrackBCAL_DeltaPhi = locChargedTrackHypothesis->Get_BCALShowerMatchParams()->dDeltaPhiToShower;
1614  locTrackBCAL_DeltaZ = locChargedTrackHypothesis->Get_BCALShowerMatchParams()->dDeltaZToShower;
1615  }
1616  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "TrackBCAL_DeltaPhi"), locTrackBCAL_DeltaPhi, locArrayIndex);
1617  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "TrackBCAL_DeltaZ"), locTrackBCAL_DeltaZ, locArrayIndex);
1618 
1619  //SHOWER MATCHING: FCAL
1620  double locDOCAToShower_FCAL = 999.0;
1621  if(locChargedTrackHypothesis->Get_FCALShowerMatchParams() != NULL)
1622  locDOCAToShower_FCAL = locChargedTrackHypothesis->Get_FCALShowerMatchParams()->dDOCAToShower;
1623  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "TrackFCAL_DOCA"), locDOCAToShower_FCAL, locArrayIndex);
1624 
1625  // DIRC
1626  if(DIRC_OUTPUT) {
1627  int locDIRCNumPhotons = (locChargedTrackHypothesis->Get_DIRCMatchParams() != NULL) ? locChargedTrackHypothesis->Get_DIRCMatchParams()->dNPhotons : 0;
1628  locTreeFillData->Fill_Array<Int_t>(Build_BranchName(locParticleBranchName, "NumPhotons_DIRC"), locDIRCNumPhotons, locArrayIndex);
1629  double locDIRCThetaC = (locChargedTrackHypothesis->Get_DIRCMatchParams() != NULL) ? locChargedTrackHypothesis->Get_DIRCMatchParams()->dThetaC : 0.0;
1630  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "ThetaC_DIRC"), locDIRCThetaC, locArrayIndex);
1631  double locDIRCLele = (locChargedTrackHypothesis->Get_DIRCMatchParams() != NULL) ? locChargedTrackHypothesis->Get_DIRCMatchParams()->dLikelihoodElectron : 0.0;
1632  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "Lele_DIRC"), locDIRCLele, locArrayIndex);
1633  double locDIRCLpi = (locChargedTrackHypothesis->Get_DIRCMatchParams() != NULL) ? locChargedTrackHypothesis->Get_DIRCMatchParams()->dLikelihoodPion : 0.0;
1634  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "Lpi_DIRC"), locDIRCLpi, locArrayIndex);
1635  double locDIRCLk = (locChargedTrackHypothesis->Get_DIRCMatchParams() != NULL) ? locChargedTrackHypothesis->Get_DIRCMatchParams()->dLikelihoodKaon : 0.0;
1636  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "Lk_DIRC"), locDIRCLk, locArrayIndex);
1637  double locDIRCLp = (locChargedTrackHypothesis->Get_DIRCMatchParams() != NULL) ? locChargedTrackHypothesis->Get_DIRCMatchParams()->dLikelihoodProton : 0.0;
1638  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "Lp_DIRC"), locDIRCLp, locArrayIndex);
1639  }
1640 }
1641 
1642 void DEventWriterROOT::Fill_NeutralHypo(DTreeFillData* locTreeFillData, unsigned int locArrayIndex, const DNeutralParticleHypothesis* locNeutralParticleHypothesis, const DMCThrownMatching* locMCThrownMatching, const map<const DMCThrown*, unsigned int>& locThrownIndexMap, const DDetectorMatches* locDetectorMatches) const
1643 {
1644  string locParticleBranchName = "NeutralHypo";
1645  const DNeutralShower* locNeutralShower = locNeutralParticleHypothesis->Get_NeutralShower();
1646 
1647  //ASSOCIATED OBJECTS
1648  const DBCALShower* locBCALShower = NULL;
1649  locNeutralShower->GetSingle(locBCALShower);
1650  const DFCALShower* locFCALShower = NULL;
1651  locNeutralShower->GetSingle(locFCALShower);
1652 
1653  //IDENTIFIERS
1654  Particle_t locPID = locNeutralParticleHypothesis->PID();
1655  locTreeFillData->Fill_Array<Int_t>(Build_BranchName(locParticleBranchName, "NeutralID"), locNeutralShower->dShowerID, locArrayIndex);
1656  locTreeFillData->Fill_Array<Int_t>(Build_BranchName(locParticleBranchName, "PID"), PDGtype(locPID), locArrayIndex);
1657 
1658  //MATCHING
1659  if(locMCThrownMatching != NULL)
1660  {
1661  Int_t locThrownIndex = -1;
1662  double locMatchFOM = 0.0;
1663  const DMCThrown* locMCThrown = locMCThrownMatching->Get_MatchingMCThrown(locNeutralParticleHypothesis, locMatchFOM);
1664  if(locMCThrown != NULL)
1665  locThrownIndex = locThrownIndexMap.find(locMCThrown)->second;
1666  locTreeFillData->Fill_Array<Int_t>(Build_BranchName(locParticleBranchName, "ThrownIndex"), locThrownIndex, locArrayIndex);
1667  }
1668 
1669  //KINEMATICS: MEASURED
1670  DVector3 locPosition = locNeutralParticleHypothesis->position();
1671  TLorentzVector locX4_Measured(locPosition.X(), locPosition.Y(), locPosition.Z(), locNeutralParticleHypothesis->time());
1672  locTreeFillData->Fill_Array<TLorentzVector>(Build_BranchName(locParticleBranchName, "X4_Measured"), locX4_Measured, locArrayIndex);
1673 
1674  DLorentzVector locDP4 = locNeutralParticleHypothesis->lorentzMomentum();
1675  TLorentzVector locP4_Measured(locDP4.Px(), locDP4.Py(), locDP4.Pz(), locDP4.E());
1676  locTreeFillData->Fill_Array<TLorentzVector>(Build_BranchName(locParticleBranchName, "P4_Measured"), locP4_Measured, locArrayIndex);
1677 
1678  //MEASURED PID INFO
1679  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "Beta_Timing"), locNeutralParticleHypothesis->measuredBeta(), locArrayIndex);
1680  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "ChiSq_Timing"), locNeutralParticleHypothesis->Get_ChiSq(), locArrayIndex);
1681  locTreeFillData->Fill_Array<UInt_t>(Build_BranchName(locParticleBranchName, "NDF_Timing"), locNeutralParticleHypothesis->Get_NDF(), locArrayIndex);
1682  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "ShowerQuality"), locNeutralShower->dQuality, locArrayIndex);
1683 
1684  //SHOWER ENERGY
1685  DetectorSystem_t locDetector = locNeutralShower->dDetectorSystem;
1686  double locBCALEnergy = (locDetector == SYS_BCAL) ? locNeutralShower->dEnergy : 0.0;
1687  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "Energy_BCAL"), locBCALEnergy, locArrayIndex);
1688  double locBCALPreshowerEnergy = (locDetector == SYS_BCAL) ? static_cast<const DBCALShower*>(locNeutralShower->dBCALFCALShower)->E_preshower : 0.0;
1689  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "Energy_BCALPreshower"), locBCALPreshowerEnergy, locArrayIndex);
1690  if(BCAL_VERBOSE_OUTPUT) {
1691  double locBCALLayer2Energy = (locBCALShower != NULL) ? locBCALShower->E_L2 : 0.0;
1692  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "Energy_BCALLayer2"), locBCALLayer2Energy, locArrayIndex);
1693  double locBCALLayer3Energy = (locBCALShower != NULL) ? locBCALShower->E_L3 : 0.0;
1694  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "Energy_BCALLayer3"), locBCALLayer3Energy, locArrayIndex);
1695  double locBCALLayer4Energy = (locBCALShower != NULL) ? locBCALShower->E_L4 : 0.0;
1696  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "Energy_BCALLayer4"), locBCALLayer4Energy, locArrayIndex);
1697  }
1698 
1699  double locFCALEnergy = (locDetector == SYS_FCAL) ? locNeutralShower->dEnergy : 0.0;
1700  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "Energy_FCAL"), locFCALEnergy, locArrayIndex);
1701 
1702  //SHOWER POSITION
1703  DLorentzVector locHitDX4 = locNeutralShower->dSpacetimeVertex;
1704  TLorentzVector locTX4_Shower(locHitDX4.X(), locHitDX4.Y(), locHitDX4.Z(), locHitDX4.T());
1705  locTreeFillData->Fill_Array<TLorentzVector>(Build_BranchName(locParticleBranchName, "X4_Shower"), locTX4_Shower, locArrayIndex);
1706 
1707  //SHOWER PROPERTIES
1708  double locSigLongBCAL = (locBCALShower != NULL) ? locBCALShower->sigLong : 0.0;
1709  double locSigThetaBCAL = (locBCALShower != NULL) ? locBCALShower->sigTheta : 0.0;
1710  double locSigTransBCAL = (locBCALShower != NULL) ? locBCALShower->sigTrans : 0.0;
1711  double locRMSTimeBCAL = (locBCALShower != NULL) ? locBCALShower->rmsTime : 0.0;
1712  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "SigLong_BCAL"), locSigLongBCAL, locArrayIndex);
1713  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "SigTheta_BCAL"), locSigThetaBCAL, locArrayIndex);
1714  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "SigTrans_BCAL"), locSigTransBCAL, locArrayIndex);
1715  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "RMSTime_BCAL"), locRMSTimeBCAL, locArrayIndex);
1716 
1717  if(FCAL_VERBOSE_OUTPUT) {
1718  double locE1E9FCAL = (locFCALShower != NULL) ? locFCALShower->getE1E9() : 0.0;
1719  double locE9E25FCAL = (locFCALShower != NULL) ? locFCALShower->getE9E25() : 0.0;
1720  double locSumUFCAL = (locFCALShower != NULL) ? locFCALShower->getSumU() : 0.0;
1721  double locSumVFCAL = (locFCALShower != NULL) ? locFCALShower->getSumV() : 0.0;
1722  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "E1E9_FCAL"), locE1E9FCAL, locArrayIndex);
1723  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "E9E25_FCAL"), locE9E25FCAL, locArrayIndex);
1724  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "SumU_FCAL"), locSumUFCAL, locArrayIndex);
1725  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "SumV_FCAL"), locSumVFCAL, locArrayIndex);
1726  }
1727 
1728  //Track DOCA to Shower - BCAL
1729  double locNearestTrackBCALDeltaPhi = 999.0, locNearestTrackBCALDeltaZ = 999.0;
1730  if(locBCALShower != NULL)
1731  {
1732  if(!locDetectorMatches->Get_DistanceToNearestTrack(locBCALShower, locNearestTrackBCALDeltaPhi, locNearestTrackBCALDeltaZ))
1733  {
1734  locNearestTrackBCALDeltaPhi = 999.0;
1735  locNearestTrackBCALDeltaZ = 999.0;
1736  }
1737  else if((locNearestTrackBCALDeltaPhi > 999.0) || (locNearestTrackBCALDeltaZ > 999.0))
1738  {
1739  locNearestTrackBCALDeltaPhi = 999.0;
1740  locNearestTrackBCALDeltaZ = 999.0;
1741  }
1742  }
1743  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "TrackBCAL_DeltaPhi"), locNearestTrackBCALDeltaPhi, locArrayIndex);
1744  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "TrackBCAL_DeltaZ"), locNearestTrackBCALDeltaZ, locArrayIndex);
1745 
1746  //Track DOCA to Shower - FCAL
1747  double locDistanceToNearestTrack_FCAL = 999.0;
1748  if(locFCALShower != NULL)
1749  {
1750  if(!locDetectorMatches->Get_DistanceToNearestTrack(locFCALShower, locDistanceToNearestTrack_FCAL))
1751  locDistanceToNearestTrack_FCAL = 999.0;
1752  if(locDistanceToNearestTrack_FCAL > 999.0)
1753  locDistanceToNearestTrack_FCAL = 999.0;
1754  }
1755  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "TrackFCAL_DOCA"), locDistanceToNearestTrack_FCAL, locArrayIndex);
1756 
1757  //PHOTON PID INFO
1758  double locStartTimeError = locNeutralParticleHypothesis->t0_err();
1759  double locPhotonRFDeltaTVar = (*locNeutralParticleHypothesis->errorMatrix())(6, 6) + locStartTimeError*locStartTimeError;
1760  if(locPID != Gamma)
1761  locPhotonRFDeltaTVar = 0.0;
1762  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "PhotonRFDeltaTVar"), locPhotonRFDeltaTVar, locArrayIndex);
1763 }
1764 
1765 void DEventWriterROOT::Fill_ComboData(DTreeFillData* locTreeFillData, const DReaction* locReaction, const DParticleCombo* locParticleCombo, unsigned int locComboIndex, const map<pair<oid_t, Particle_t>, size_t>& locObjectToArrayIndexMap) const
1766 {
1767  //MAIN CLASSES
1768  const DKinFitResults* locKinFitResults = locParticleCombo->Get_KinFitResults();
1769  const DEventRFBunch* locEventRFBunch = locParticleCombo->Get_EventRFBunch();
1770 
1771  //IS COMBO CUT
1772  locTreeFillData->Fill_Array<Bool_t>("IsComboCut", kFALSE, locComboIndex);
1773 
1774  //RF INFO
1775  double locRFTime = (locEventRFBunch != NULL) ? locEventRFBunch->dTime : numeric_limits<double>::quiet_NaN();
1776  locTreeFillData->Fill_Array<Float_t>("RFTime_Measured", locRFTime, locComboIndex);
1777 
1778  //KINFIT INFO
1779  DKinFitType locKinFitType = locReaction->Get_KinFitType();
1780  bool locKinFitFlag = (locKinFitType != d_NoFit);
1781  if(locKinFitFlag)
1782  {
1783  if(locKinFitResults != NULL)
1784  {
1785  locTreeFillData->Fill_Array<Float_t>("ChiSq_KinFit", locKinFitResults->Get_ChiSq(), locComboIndex);
1786  locTreeFillData->Fill_Array<UInt_t>("NDF_KinFit", locKinFitResults->Get_NDF(), locComboIndex);
1787  if((locKinFitType == d_SpacetimeFit) || (locKinFitType == d_P4AndSpacetimeFit))
1788  {
1789  double locRFTime_KinFit = -9.9E9; //NOT IMPLEMENTED YET
1790  locTreeFillData->Fill_Array<Float_t>("RFTime_KinFit", locRFTime_KinFit, locComboIndex);
1791  }
1792  }
1793  else
1794  {
1795  locTreeFillData->Fill_Array<Float_t>("ChiSq_KinFit", 0.0, locComboIndex);
1796  locTreeFillData->Fill_Array<UInt_t>("NDF_KinFit", 0, locComboIndex);
1797  if((locKinFitType == d_SpacetimeFit) || (locKinFitType == d_P4AndSpacetimeFit))
1798  locTreeFillData->Fill_Array<Float_t>("RFTime_KinFit", -9.9E9, locComboIndex);
1799  }
1800  }
1801 
1802  //STEP DATA
1803  for(size_t loc_i = 0; loc_i < locParticleCombo->Get_NumParticleComboSteps(); ++loc_i)
1804  Fill_ComboStepData(locTreeFillData, locReaction, locParticleCombo, loc_i, locComboIndex, locKinFitType, locObjectToArrayIndexMap);
1805 }
1806 
1807 void DEventWriterROOT::Fill_ComboStepData(DTreeFillData* locTreeFillData, const DReaction* locReaction, const DParticleCombo* locParticleCombo, unsigned int locStepIndex, unsigned int locComboIndex, DKinFitType locKinFitType, const map<pair<oid_t, Particle_t>, size_t>& locObjectToArrayIndexMap) const
1808 {
1809  auto locReactionVertexInfo = dVertexInfoMap.find(locReaction)->second;
1810  auto locReactionStep = locReaction->Get_ReactionStep(locStepIndex);
1811  const TList* locUserInfo = dTreeInterfaceMap.find(locReaction)->second->Get_UserInfo(); //No Lock! But this should be unchanging at this point anyway
1812  const TMap* locPositionToNameMap = (TMap*)locUserInfo->FindObject("PositionToNameMap");
1813 
1814  auto locParticleComboStep = locParticleCombo->Get_ParticleComboStep(locStepIndex);
1815  DLorentzVector locStepX4 = locParticleComboStep->Get_SpacetimeVertex();
1816  TLorentzVector locStepTX4(locStepX4.X(), locStepX4.Y(), locStepX4.Z(), locStepX4.T());
1817 
1818  //beam & production vertex
1819  Particle_t locInitialPID = locReactionStep->Get_InitialPID();
1820  const DKinematicData* locInitialParticle = locParticleComboStep->Get_InitialParticle();
1821  const DBeamPhoton* locBeamPhoton = dynamic_cast<const DBeamPhoton*>(locInitialParticle);
1822  if(locBeamPhoton != NULL)
1823  {
1824  const DKinematicData* locInitParticleMeasured = locParticleComboStep->Get_InitialParticle_Measured();
1825  const DBeamPhoton* locMeasuredBeamPhoton = dynamic_cast<const DBeamPhoton*>(locInitParticleMeasured);
1826 
1827  //get array index
1828  pair<oid_t, Particle_t> locBeamPair(locMeasuredBeamPhoton->id, locMeasuredBeamPhoton->PID());
1829  size_t locBeamIndex = locObjectToArrayIndexMap.find(locBeamPair)->second;
1830 
1831  Fill_ComboBeamData(locTreeFillData, locComboIndex, locBeamPhoton, locBeamIndex, locKinFitType);
1832  }
1833  else //decaying
1834  {
1835  //get the branch name
1836  ostringstream locPositionStream;
1837  locPositionStream << locStepIndex << "_-1";
1838  TObjString* locObjString = (TObjString*)locPositionToNameMap->GetValue(locPositionStream.str().c_str());
1839  string locParticleBranchName = (const char*)(locObjString->GetString());
1840 
1841  auto locP4FitFlag = ((locKinFitType == d_P4Fit) || (locKinFitType == d_P4AndVertexFit) || (locKinFitType == d_P4AndSpacetimeFit));
1842  if(IsFixedMass(locInitialPID) && locReactionStep->Get_KinFitConstrainInitMassFlag() && locP4FitFlag)
1843  {
1844  TLorentzVector locDecayP4;
1845  if(locInitialParticle == NULL)
1846  {
1847  //fit failed to converge, calc from other particles
1848  DLorentzVector locDecayDP4 = dAnalysisUtilities->Calc_FinalStateP4(locReaction, locParticleCombo, locStepIndex, false);
1849  locDecayDP4.SetE(sqrt(locDecayDP4.Vect().Mag2() + ParticleMass(locInitialPID)*ParticleMass(locInitialPID)));
1850  locDecayP4.SetPxPyPzE(locDecayDP4.Px(), locDecayDP4.Py(), locDecayDP4.Pz(), locDecayDP4.E());
1851  }
1852  else
1853  locDecayP4.SetPxPyPzE(locInitialParticle->momentum().X(), locInitialParticle->momentum().Y(), locInitialParticle->momentum().Z(), locInitialParticle->energy());
1854  locTreeFillData->Fill_Array<TLorentzVector>(Build_BranchName(locParticleBranchName, "P4_KinFit"), locDecayP4, locComboIndex);
1855  }
1856 
1857  if((locStepIndex == 0) || IsDetachedVertex(locInitialPID))
1858  locTreeFillData->Fill_Array<TLorentzVector>(Build_BranchName(locParticleBranchName, "X4"), locStepTX4, locComboIndex);
1859 
1860  auto locStepVertexInfo = locReactionVertexInfo->Get_StepVertexInfo(locStepIndex);
1861  auto locParentVertexInfo = locStepVertexInfo->Get_ParentVertexInfo();
1862  auto locVertexKinFitFlag = ((locKinFitType != d_P4Fit) && (locKinFitType != d_NoFit));
1863  if(IsDetachedVertex(locInitialPID) && locVertexKinFitFlag && (locParentVertexInfo != nullptr) && locStepVertexInfo->Get_FittableVertexFlag() && locParentVertexInfo->Get_FittableVertexFlag())
1864  {
1865  auto locKinFitParticle = locParticleComboStep->Get_InitialKinFitParticle();
1866  auto locPathLengthSigma = locKinFitParticle->Get_PathLengthUncertainty();
1867  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "PathLengthSigma"), locPathLengthSigma, locComboIndex);
1868  }
1869  }
1870 
1871  //final state particles
1872  for(size_t loc_i = 0; loc_i < locParticleComboStep->Get_NumFinalParticles(); ++loc_i)
1873  {
1874  Particle_t locPID = locReactionStep->Get_FinalPID(loc_i);
1875  const DKinematicData* locKinematicData = locParticleComboStep->Get_FinalParticle(loc_i);
1876  const DKinematicData* locKinematicData_Measured = locParticleComboStep->Get_FinalParticle_Measured(loc_i);
1877 
1878  //decaying particle
1879  if(DAnalysis::Get_DecayStepIndex(locReaction, locStepIndex, loc_i) >= 0)
1880  continue;
1881 
1882  //get the branch name
1883  ostringstream locPositionStream;
1884  locPositionStream << locStepIndex << "_" << loc_i;
1885  TObjString* locObjString = (TObjString*)locPositionToNameMap->GetValue(locPositionStream.str().c_str());
1886  string locParticleBranchName = (const char*)(locObjString->GetString());
1887 
1888  //missing particle
1889  if(locReactionStep->Get_MissingParticleIndex() == int(loc_i))
1890  {
1891  if((locKinFitType == d_P4Fit) || (locKinFitType == d_P4AndVertexFit) || (locKinFitType == d_P4AndSpacetimeFit))
1892  {
1893  TLorentzVector locMissingP4;
1894  if(locKinematicData == NULL)
1895  {
1896  //fit failed to converge, calc from other particles
1897  DLorentzVector locMissingDP4 = dAnalysisUtilities->Calc_MissingP4(locReaction, locParticleCombo, false);
1898  locMissingDP4.SetE(sqrt(locMissingDP4.Vect().Mag2() + ParticleMass(locPID)*ParticleMass(locPID)));
1899  locMissingP4.SetPxPyPzE(locMissingDP4.Px(), locMissingDP4.Py(), locMissingDP4.Pz(), locMissingDP4.E());
1900  }
1901  else
1902  locMissingP4.SetPxPyPzE(locKinematicData->momentum().X(), locKinematicData->momentum().Y(), locKinematicData->momentum().Z(), locKinematicData->energy());
1903 
1904  locTreeFillData->Fill_Array<TLorentzVector>(Build_BranchName(locParticleBranchName, "P4_KinFit"), locMissingP4, locComboIndex);
1905  }
1906  continue;
1907  }
1908 
1909  //fill the data
1910  if(ParticleCharge(locPID) == 0)
1911  {
1912  const DNeutralParticleHypothesis* locNeutralHypo = dynamic_cast<const DNeutralParticleHypothesis*>(locKinematicData);
1913  const DNeutralParticleHypothesis* locMeasuredNeutralHypo = dynamic_cast<const DNeutralParticleHypothesis*>(locKinematicData_Measured);
1914 
1915  //get array index
1916  const DNeutralShower* locNeutralShower = locNeutralHypo->Get_NeutralShower();
1917  pair<oid_t, Particle_t> locNeutralPair(locNeutralShower->id, locNeutralHypo->PID());
1918  size_t locNeutralIndex = locObjectToArrayIndexMap.find(locNeutralPair)->second;
1919 
1920  Fill_ComboNeutralData(locTreeFillData, locComboIndex, locParticleBranchName, locMeasuredNeutralHypo, locNeutralHypo, locNeutralIndex, locKinFitType);
1921  }
1922  else
1923  {
1924  const DChargedTrackHypothesis* locChargedHypo = dynamic_cast<const DChargedTrackHypothesis*>(locKinematicData);
1925  const DChargedTrackHypothesis* locMeasuredChargedHypo = dynamic_cast<const DChargedTrackHypothesis*>(locKinematicData_Measured);
1926 
1927  //get array index
1928  const DTrackTimeBased* locTrackTimeBased = locChargedHypo->Get_TrackTimeBased();
1929  pair<oid_t, Particle_t> locTrackPair(locTrackTimeBased->id, locChargedHypo->PID());
1930  size_t locChargedIndex = locObjectToArrayIndexMap.find(locTrackPair)->second;
1931 
1932  Fill_ComboChargedData(locTreeFillData, locComboIndex, locParticleBranchName, locMeasuredChargedHypo, locChargedHypo, locChargedIndex, locKinFitType);
1933  }
1934  }
1935 }
1936 
1937 void DEventWriterROOT::Fill_ComboBeamData(DTreeFillData* locTreeFillData, unsigned int locComboIndex, const DBeamPhoton* locBeamPhoton, size_t locBeamIndex, DKinFitType locKinFitType) const
1938 {
1939  string locParticleBranchName = "ComboBeam";
1940 
1941  //IDENTIFIER
1942  locTreeFillData->Fill_Array<Int_t>(Build_BranchName(locParticleBranchName, "BeamIndex"), locBeamIndex, locComboIndex);
1943 
1944  //KINEMATICS: KINFIT
1945  if(locKinFitType != d_NoFit)
1946  {
1947  if(locKinFitType != d_P4Fit)
1948  {
1949  DVector3 locPosition = locBeamPhoton->position();
1950  TLorentzVector locX4_KinFit(locPosition.X(), locPosition.Y(), locPosition.Z(), locBeamPhoton->time());
1951  locTreeFillData->Fill_Array<TLorentzVector>(Build_BranchName(locParticleBranchName, "X4_KinFit"), locX4_KinFit, locComboIndex);
1952  }
1953 
1954  //if charged, bends in b-field, update p4 when vertex changes
1955  if(((locKinFitType != d_VertexFit) && (locKinFitType != d_SpacetimeFit)) || (ParticleCharge(locBeamPhoton->PID()) != 0))
1956  {
1957  DLorentzVector locDP4 = locBeamPhoton->lorentzMomentum();
1958  TLorentzVector locP4_KinFit(locDP4.Px(), locDP4.Py(), locDP4.Pz(), locDP4.E());
1959  locTreeFillData->Fill_Array<TLorentzVector>(Build_BranchName(locParticleBranchName, "P4_KinFit"), locP4_KinFit, locComboIndex);
1960  }
1961  }
1962 }
1963 
1964 void DEventWriterROOT::Fill_ComboChargedData(DTreeFillData* locTreeFillData, unsigned int locComboIndex, string locParticleBranchName, const DChargedTrackHypothesis* locMeasuredChargedHypo, const DChargedTrackHypothesis* locChargedHypo, size_t locChargedIndex, DKinFitType locKinFitType) const
1965 {
1966  //IDENTIFIER
1967  locTreeFillData->Fill_Array<Int_t>(Build_BranchName(locParticleBranchName, "ChargedIndex"), locChargedIndex, locComboIndex);
1968 
1969  //MEASURED PID
1970  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "Beta_Timing_Measured"), locMeasuredChargedHypo->measuredBeta(), locComboIndex);
1971  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "ChiSq_Timing_Measured"), locMeasuredChargedHypo->Get_ChiSq_Timing(), locComboIndex);
1972 
1973  //KINFIT PID
1974  if((locKinFitType != d_NoFit) && (locKinFitType != d_SpacetimeFit) && (locKinFitType != d_P4AndSpacetimeFit))
1975  {
1976  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "Beta_Timing_KinFit"), locChargedHypo->measuredBeta(), locComboIndex);
1977  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "ChiSq_Timing_KinFit"), locChargedHypo->Get_ChiSq_Timing(), locComboIndex);
1978  }
1979 
1980  //KINFIT
1981  if(locKinFitType != d_NoFit)
1982  {
1983  //KINEMATICS
1984  if(locKinFitType != d_P4Fit)
1985  {
1986  DVector3 locPosition = locChargedHypo->position();
1987  TLorentzVector locX4_KinFit(locPosition.X(), locPosition.Y(), locPosition.Z(), locChargedHypo->time());
1988  locTreeFillData->Fill_Array<TLorentzVector>(Build_BranchName(locParticleBranchName, "X4_KinFit"), locX4_KinFit, locComboIndex);
1989  }
1990 
1991  //update even if vertex-only fit, because charged momentum propagated through b-field
1992  DLorentzVector locDP4 = locChargedHypo->lorentzMomentum();
1993  TLorentzVector locP4_KinFit(locDP4.Px(), locDP4.Py(), locDP4.Pz(), locDP4.E());
1994  locTreeFillData->Fill_Array<TLorentzVector>(Build_BranchName(locParticleBranchName, "P4_KinFit"), locP4_KinFit, locComboIndex);
1995  }
1996 }
1997 
1998 void DEventWriterROOT::Fill_ComboNeutralData(DTreeFillData* locTreeFillData, unsigned int locComboIndex, string locParticleBranchName, const DNeutralParticleHypothesis* locMeasuredNeutralHypo, const DNeutralParticleHypothesis* locNeutralHypo, size_t locNeutralIndex, DKinFitType locKinFitType) const
1999 {
2000  //IDENTIFIER
2001  locTreeFillData->Fill_Array<Int_t>(Build_BranchName(locParticleBranchName, "NeutralIndex"), locNeutralIndex, locComboIndex);
2002 
2003  //KINEMATICS: MEASURED
2004  DVector3 locPosition = locMeasuredNeutralHypo->position();
2005  TLorentzVector locX4_Measured(locPosition.X(), locPosition.Y(), locPosition.Z(), locMeasuredNeutralHypo->time());
2006  locTreeFillData->Fill_Array<TLorentzVector>(Build_BranchName(locParticleBranchName, "X4_Measured"), locX4_Measured, locComboIndex);
2007 
2008  DLorentzVector locDP4 = locMeasuredNeutralHypo->lorentzMomentum();
2009  TLorentzVector locP4_Measured(locDP4.Px(), locDP4.Py(), locDP4.Pz(), locDP4.E());
2010  locTreeFillData->Fill_Array<TLorentzVector>(Build_BranchName(locParticleBranchName, "P4_Measured"), locP4_Measured, locComboIndex);
2011 
2012  //MEASURED PID INFO
2013  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "Beta_Timing_Measured"), locMeasuredNeutralHypo->measuredBeta(), locComboIndex);
2014  if(locParticleBranchName.substr(0, 6) == "Photon")
2015  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "ChiSq_Timing_Measured"), locMeasuredNeutralHypo->Get_ChiSq(), locComboIndex);
2016 
2017  //KINFIT PID INFO
2018  if((locKinFitType != d_NoFit) && (locKinFitType != d_SpacetimeFit) && (locKinFitType != d_P4AndSpacetimeFit))
2019  {
2020  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "Beta_Timing_KinFit"), locNeutralHypo->measuredBeta(), locComboIndex);
2021  if(locParticleBranchName.substr(0, 6) == "Photon")
2022  locTreeFillData->Fill_Array<Float_t>(Build_BranchName(locParticleBranchName, "ChiSq_Timing_KinFit"), locNeutralHypo->Get_ChiSq(), locComboIndex);
2023  }
2024 
2025  //KINFIT
2026  if(locKinFitType != d_NoFit)
2027  {
2028  //KINEMATICS
2029  if(locKinFitType != d_P4Fit)
2030  {
2031  DVector3 locPosition = locNeutralHypo->position();
2032  TLorentzVector locX4_KinFit(locPosition.X(), locPosition.Y(), locPosition.Z(), locNeutralHypo->time());
2033  locTreeFillData->Fill_Array<TLorentzVector>(Build_BranchName(locParticleBranchName, "X4_KinFit"), locX4_KinFit, locComboIndex);
2034  }
2035 
2036  //update even if vertex-only fit, because neutral momentum defined by vertex
2037  DLorentzVector locDP4 = locNeutralHypo->lorentzMomentum();
2038  TLorentzVector locP4_KinFit(locDP4.Px(), locDP4.Py(), locDP4.Pz(), locDP4.E());
2039  locTreeFillData->Fill_Array<TLorentzVector>(Build_BranchName(locParticleBranchName, "P4_KinFit"), locP4_KinFit, locComboIndex);
2040  }
2041 }
2042 
string Get_TTreeOutputFileName(void) const
Definition: DReaction.h:107
bool Get_IsFirstStepBeam(const DReaction *locReaction)
Definition: DReaction.h:178
void Fill_ComboChargedData(DTreeFillData *locTreeFillData, unsigned int locComboIndex, string locParticleBranchName, const DChargedTrackHypothesis *locMeasuredChargedHypo, const DChargedTrackHypothesis *locChargedHypo, size_t locChargedIndex, DKinFitType locKinFitType) const
double getEnergy() const
Definition: DFCALShower.h:156
DKinematicData target
Definition: DMCReaction.h:24
void Fill_ThrownParticleData(DTreeFillData *locTreeFillData, unsigned int locArrayIndex, const DMCThrown *locMCThrown, const map< const DMCThrown *, unsigned int > &locThrownIndexMap, const DMCThrownMatching *locMCThrownMatching) const
double Get_ChiSq_Timing(void) const
int Calc_Momentum_UnusedTracks(JEventLoop *locEventLoop, const DParticleCombo *locParticleCombo, double &locSumPMag_UnusedTracks, TVector3 &locSumP3_UnusedTracks) const
vector< const DChargedTrackHypothesis * > Get_ChargedHypotheses_Used(JEventLoop *locEventLoop, const DReaction *locReaction, const deque< const DParticleCombo * > &locParticleCombos) const
bool Get_DistanceToNearestTrack(const DBCALShower *locBCALShower, double &locDistance) const
unsigned int Get_NDF(void) const
size_t Get_NumParticleComboSteps(void) const
void Create_Branches_BeamComboParticle(DTreeBranchRegister &locTreeBranchRegister, Particle_t locBeamPID, DKinFitType locKinFitType) const
DKinFitType Get_KinFitType(void) const
Definition: DReaction.h:79
void Fill_ComboStepData(DTreeFillData *locTreeFillData, const DReaction *locReaction, const DParticleCombo *locParticleCombo, unsigned int locStepIndex, unsigned int locComboIndex, DKinFitType locKinFitType, const map< pair< oid_t, Particle_t >, size_t > &locObjectToArrayIndexMap) const
unsigned int dInitNumNeutralArraySize
TVector3 DVector3
Definition: DVector3.h:14
bool Get_KinFitConstrainInitMassFlag(void) const
Definition: DReactionStep.h:97
map< const DReaction *, const DReactionVertexInfo * > dVertexInfoMap
double energy(void) const
float sigTrans
Definition: DBCALShower.h:28
uint32_t Get_L1TriggerBits(void) const
vector< const DReaction * > Get_Reactions(JEventLoop *locEventLoop)
Definition: DReaction.cc:218
void Compute_ThrownPIDInfo(const vector< const DMCThrown * > &locMCThrowns_FinalState, const vector< const DMCThrown * > &locMCThrowns_Decaying, ULong64_t &locNumPIDThrown_FinalState, ULong64_t &locPIDThrown_Decaying) const
char string[256]
virtual void Create_CustomBranches_DataTree(DTreeBranchRegister &locBranchRegister, JEventLoop *locEventLoop, const DReaction *locReaction, bool locIsMCDataFlag) const
void Register_Single(string locBranchName)
ULong64_t Calc_ParticleMultiplexID(Particle_t locPID) const
map< const DReaction *, DTreeFillData * > dTreeFillDataMap
void Fill_Array(string locBranchName, const DType &locData, size_t locArrayIndex)
const DVector3 & position(void) const
bool Get_EnableTTreeOutputFlag(void) const
Definition: DReaction.h:109
const DTrackTimeBased * Get_TrackTimeBased(void) const
void Create_Branches_NeutralHypotheses(DTreeBranchRegister &locTreeBranchRegister, bool locIsMCDataFlag) const
Particle_t Get_TargetPID(void) const
Definition: DReactionStep.h:83
bool Get_SaveUnusedFlag(void) const
Definition: DReaction.h:108
bool Create_Branches(const DTreeBranchRegister &locTreeBranchRegister)
static unsigned short int IsDetachedVertex(Particle_t p)
Definition: particleType.h:817
double Calc_Energy_UnusedShowers(JEventLoop *locEventLoop, const DParticleCombo *locParticleCombo) const
static char * ParticleType(Particle_t p)
Definition: particleType.h:142
static bool BCAL_VERBOSE_OUTPUT
const JObject * dBCALFCALShower
DetectorSystem_t
Definition: GlueX.h:15
void Fill_NeutralHypo(DTreeFillData *locTreeFillData, unsigned int locArrayIndex, const DNeutralParticleHypothesis *locPhotonHypothesis, const DMCThrownMatching *locMCThrownMatching, const map< const DMCThrown *, unsigned int > &locThrownIndexMap, const DDetectorMatches *locDetectorMatches) const
static int ParticleMultiplexPower(Particle_t locPID)
void Create_Branches_ThrownParticles(DTreeBranchRegister &locTreeBranchRegister, bool locIsOnlyThrownFlag) const
double measuredBeta(void) const
const DKinematicData * Get_InitialParticle_Measured(void) const
void Fill_DataTree(JEventLoop *locEventLoop, const DReaction *locReaction, deque< const DParticleCombo * > &locParticleCombos) const
TLorentzVector DLorentzVector
float sigLong
Definition: DBCALShower.h:27
unsigned int Get_NDF_Timing(void) const
int pdgtype
PDG particle type (not used by GEANT)
Definition: DMCThrown.h:21
const DEventRFBunch * Get_EventRFBunch(void) const
static bool DIRC_OUTPUT
static int ParticleCharge(Particle_t p)
void Fill_ComboBeamData(DTreeFillData *locTreeFillData, unsigned int locComboIndex, const DBeamPhoton *locBeamPhoton, size_t locBeamIndex, DKinFitType locKinFitType) const
void Create_DataTree(const DReaction *locReaction, JEventLoop *locEventLoop, bool locIsMCDataFlag)
const DNeutralShower * Get_NeutralShower(void) const
static int PDGtype(Particle_t p)
void Initialize(JEventLoop *locEventLoop)
double Get_ChiSq(void) const
Definition: GlueX.h:19
shared_ptr< const DTOFHitMatchParams > Get_TOFHitMatchParams(void) const
JApplication * japp
DKinematicData beam
Definition: DMCReaction.h:25
DetectorSystem_t dDetectorSystem
vector< Particle_t > Get_FinalPIDs(int locStepIndex=-1, bool locIncludeMissingFlag=true, bool locIncludeDecayingFlag=true, Charge_t locCharge=d_AllCharges, bool locIncludeDuplicatesFlag=true) const
Definition: DReaction.cc:17
map< const DReaction *, DTreeInterface * > dTreeInterfaceMap
DLorentzVector dSpacetimeVertex
float E_L4
Definition: DBCALShower.h:22
unsigned int Get_NDF_DCdEdx(void) const
double weight
Definition: DMCReaction.h:23
double time(void) const
string Get_ConstraintInfo(const DReactionVertexInfo *locReactionVertexInfo, const DReaction *locReaction, size_t &locNumConstraints, size_t &locNumUnknowns) const
const DChargedTrack * Get_MatchingChargedTrack(const DMCThrown *locInputMCThrown, double &locMatchFOM) const
DLorentzVector Calc_FinalStateP4(const DReaction *locReaction, const DParticleCombo *locParticleCombo, size_t locStepIndex, bool locUseKinFitDataFlag) const
unsigned int dInitNumThrownArraySize
void Register_ClonesArray(string locBranchName, size_t locInitialArraySize=10)
TMap * Create_UserInfoMaps(DTreeBranchRegister &locTreeBranchRegister, JEventLoop *locEventLoop, const DReaction *locReaction) const
vector< const DNeutralParticleHypothesis * > Get_NeutralHypotheses_Used(JEventLoop *locEventLoop, const DReaction *locReaction, const set< Particle_t > &locReactionPIDs, const deque< const DParticleCombo * > &locParticleCombos) const
void Fill(DTreeFillData &locTreeFillData)
Particle_t Get_InitialPID(void) const
Definition: DReactionStep.h:81
static DTreeInterface * Create_DTreeInterface(string locTreeName, string locFileName)
void Fill_ThrownInfo(DTreeFillData *locTreeFillData, const DMCReaction *locMCReaction, const DBeamPhoton *locTaggedMCGenBeam, const vector< const DMCThrown * > &locMCThrowns, const map< const DMCThrown *, unsigned int > &locThrownIndexMap, ULong64_t locNumPIDThrown_FinalState, ULong64_t locPIDThrown_Decaying, const DMCThrownMatching *locMCThrownMatching=NULL) const
void Create_Branches_ComboNeutral(DTreeBranchRegister &locTreeBranchRegister, string locParticleBranchName, DKinFitType locKinFitType) const
map< const DReaction *, DCutAction_ThrownTopology * > dCutActionMap_ThrownTopology
const DNeutralShower * Get_MatchingNeutralShower(const DMCThrown *locInputMCThrown, double &locMatchFOM) const
void Create_UserTargetInfo(DTreeBranchRegister &locTreeBranchRegister, Particle_t locTargetPID) const
void Set_TreeIndexBranchNames(string locTreeIndex_MajorBranchName, string locTreeIndex_MinorBranchName="0")
virtual void Fill_CustomBranches_ThrownTree(DTreeFillData *locTreeFillData, JEventLoop *locEventLoop, const DMCReaction *locMCReaction, const vector< const DMCThrown * > &locMCThrowns) const
vector< const DChargedTrackHypothesis * > Get_ChargedHypotheses(JEventLoop *locEventLoop) const
DLorentzVector Calc_MissingP4(const DReaction *locReaction, const DParticleCombo *locParticleCombo, bool locUseKinFitDataFlag) const
int parentid
id of parent of this particle from original generator
Definition: DMCThrown.h:23
const DBeamPhoton * Get_TaggedMCGENBeamPhoton(void) const
DGeometry * GetDGeometry(unsigned int run_number)
string Get_ReactionName(void) const
Definition: DReaction.h:75
Definition: GlueX.h:22
double getE9E25() const
Definition: DFCALShower.h:170
static unsigned short int IsFixedMass(Particle_t p)
Definition: particleType.h:743
void Fill_ChargedHypo(DTreeFillData *locTreeFillData, unsigned int locArrayIndex, const DChargedTrackHypothesis *locChargedTrackHypothesis, const DMCThrownMatching *locMCThrownMatching, const map< const DMCThrown *, unsigned int > &locThrownIndexMap, const DDetectorMatches *locDetectorMatches) const
float rmsTime
Definition: DBCALShower.h:31
vector< const DBeamPhoton * > Get_BeamPhotons(const deque< const DParticleCombo * > &locParticleCombos) const
float E_L3
Definition: DBCALShower.h:21
unsigned int dInitNumComboArraySize
double getSumU() const
Definition: DFCALShower.h:168
void Register_FundamentalArray(string locBranchName, string locArraySizeName, size_t locInitialArraySize=10)
shared_ptr< const DDIRCMatchParams > Get_DIRCMatchParams(void) const
void Fill_ComboData(DTreeFillData *locTreeFillData, const DReaction *locReaction, const DParticleCombo *locParticleCombo, unsigned int locComboIndex, const map< pair< oid_t, Particle_t >, size_t > &locObjectToArrayIndexMap) const
virtual void Fill_CustomBranches_DataTree(DTreeFillData *locTreeFillData, JEventLoop *locEventLoop, const DReaction *locReaction, const DMCReaction *locMCReaction, const vector< const DMCThrown * > &locMCThrowns, const DMCThrownMatching *locMCThrownMatching, const DDetectorMatches *locDetectorMatches, const vector< const DBeamPhoton * > &locBeamPhotons, const vector< const DChargedTrackHypothesis * > &locChargedHypos, const vector< const DNeutralParticleHypothesis * > &locNeutralHypos, const deque< const DParticleCombo * > &locParticleCombos) const
static int Is_FinalStateParticle(Particle_t locPID)
string Convert_ToBranchName(string locInputName) const
DLorentzVector Get_SpacetimeVertex(void) const
DLorentzVector dSpacetimeVertex
Definition: DVertex.h:28
void Fill_BeamData(DTreeFillData *locTreeFillData, unsigned int locArrayIndex, const DBeamPhoton *locBeamPhoton, const DVertex *locVertex, const DMCThrownMatching *locMCThrownMatching) const
int Get_MissingParticleIndex(void) const
Definition: DReactionStep.h:93
DTreeFillData dThrownTreeFillData
shared_ptr< const DSCHitMatchParams > Get_SCHitMatchParams(void) const
vector< const DNeutralParticleHypothesis * > Get_NeutralHypotheses(JEventLoop *locEventLoop, const set< Particle_t > &locReactionPIDs) const
TList * Get_UserInfo(void) const
void Create_Branches_ComboTrack(DTreeBranchRegister &locTreeBranchRegister, string locParticleBranchName, DKinFitType locKinFitType) const
const DAnalysisUtilities * dAnalysisUtilities
DLorentzVector lorentzMomentum(void) const
void Fill_DataTrees(JEventLoop *locEventLoop, string locDReactionTag) const
double getSumV() const
Definition: DFCALShower.h:169
static double ParticleMass(Particle_t p)
double sqrt(double)
shared_ptr< const DFCALShowerMatchParams > Get_FCALShowerMatchParams(void) const
virtual ~DEventWriterROOT(void)
double Get_ChiSq_DCdEdx(void) const
void Create_ThrownTree(JEventLoop *locEventLoop, string locOutputFileName) const
bool Get_BranchesCreatedFlag(void) const
static bool FCAL_VERBOSE_OUTPUT
map< const DReaction *, DCutAction_TrueCombo * > dCutActionMap_TrueCombo
const DVector3 & momentum(void) const
vector< Particle_t > Get_FinalPIDs(bool locIncludeMissingFlag=true, Charge_t locCharge=d_AllCharges, bool locIncludeDuplicatesFlag=true) const
void Create_Branches_ChargedHypotheses(DTreeBranchRegister &locTreeBranchRegister, bool locIsMCDataFlag) const
DTreeInterface * dThrownTreeInterface
void Get_DecayProductNames(const DReaction *locReaction, size_t locReactionStepIndex, TMap *locPositionToNameMap, TList *&locDecayProductNames, deque< size_t > &locSavedSteps) const
void Create_Branches_Thrown(DTreeBranchRegister &locTreeBranchRegister, bool locIsOnlyThrownFlag) const
unsigned int dInitNumTrackArraySize
const DReactionStep * Get_ReactionStep(size_t locStepIndex) const
Definition: DReaction.h:84
void Group_ThrownParticles(const vector< const DMCThrown * > &locMCThrowns_FinalState, const vector< const DMCThrown * > &locMCThrowns_Decaying, vector< const DMCThrown * > &locMCThrownsToSave, map< const DMCThrown *, unsigned int > &locThrownIndexMap) const
float sigTheta
Definition: DBCALShower.h:29
int Get_DecayStepIndex(const DReaction *locReaction, size_t locStepIndex, size_t locParticleIndex)
Definition: DReaction.cc:135
const DKinFitResults * Get_KinFitResults(void) const
float E_preshower
Definition: DBCALShower.h:19
unsigned int dInitNumBeamArraySize
shared_ptr< const DBCALShowerMatchParams > Get_BCALShowerMatchParams(void) const
map< const DReaction *, DCutAction_BDTSignalCombo * > dCutActionMap_BDTSignalCombo
shared_ptr< const TMatrixFSym > errorMatrix(void) const
void Create_Branches_Combo(DTreeBranchRegister &locTreeBranchRegister, const DReaction *locReaction, bool locIsMCDataFlag, TMap *locPositionToNameMap) const
const DParticleComboStep * Get_ParticleComboStep(size_t locStepIndex) const
size_t Get_NumReactionSteps(void) const
Definition: DReaction.h:83
unsigned int Get_NDF(void) const
double getE1E9() const
Definition: DFCALShower.h:171
bool GetTargetZ(double &z_target) const
z-location of center of target
Definition: DGeometry.cc:1933
void Fill_ThrownTree(JEventLoop *locEventLoop) const
void Create_Branches_Beam(DTreeBranchRegister &locTreeBranchRegister, bool locIsMCDataFlag) const
void Fill_ComboNeutralData(DTreeFillData *locTreeFillData, unsigned int locComboIndex, string locParticleBranchName, const DNeutralParticleHypothesis *locMeasuredNeutralHypo, const DNeutralParticleHypothesis *locNeutralHypo, size_t locNeutralIndex, DKinFitType locKinFitType) const
Particle_t PID(void) const
const DMCThrown * Get_MatchingMCThrown(const DChargedTrackHypothesis *locChargedTrackHypothesis, double &locMatchFOM) const
string Build_BranchName(string locParticleBranchName, string locVariableName) const
virtual void Create_CustomBranches_ThrownTree(DTreeBranchRegister &locBranchRegister, JEventLoop *locEventLoop) const
float E_L2
Definition: DBCALShower.h:20
Particle_t
Definition: particleType.h:12
void Fill_Single(string locBranchName, const DType &locData)