Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DCustomAction_HistMass_b1_1235.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: DCustomAction_HistMass_b1_1235.cc
4 // Created: Mon Dec 2 12:18:47 EST 2013
5 // Creator: pmatt (on Darwin pmattLaptop 10.8.0 i386)
6 //
7 
9 
10 void DCustomAction_HistMass_b1_1235::Initialize(JEventLoop* locEventLoop)
11 {
12  //Optional: Create histograms and/or modify member variables.
13  //Create any histograms/trees/etc. within a ROOT lock.
14  //This is so that when running multithreaded, only one thread is writing to the ROOT file at a time.
15 
16  //CREATE THE HISTOGRAMS
17  //Since we are creating histograms, the contents of gDirectory will be modified: must use JANA-wide ROOT lock
18  japp->RootWriteLock(); //ACQUIRE ROOT LOCK!!
19  {
20  // Optional: Useful utility functions.
21  locEventLoop->GetSingle(dAnalysisUtilities);
22 
23  //Required: Create a folder in the ROOT output file that will contain all of the output ROOT objects (if any) for this action.
24  //If another thread has already created the folder, it just changes to it.
26 
27  // Optional: Create a ROOT subfolder.
28  //If another thread has already created the folder, it just changes to it.
29  // CreateAndChangeTo_Directory("MyDirName", "MyDirTitle");
30  //make sub-directory content here
31  // gDirectory->cd(".."); //return to the action directory
32 
33  // (Optional) Example: Create a histogram.
34  string locHistTitle = string(";") + ParticleName_ROOT(PiPlus) + ParticleName_ROOT(omega) + string(" Invariant Mass (GeV/c^{2});# Combos / 2 MeV/c^{2}");
35  if(gDirectory->Get("InvariantMass") == NULL) //check to see if already created by another thread
36  dMassHist = new TH1I("InvariantMass", locHistTitle.c_str(), 600, 0.6, 1.8);
37  else //already created by another thread
38  dMassHist = static_cast<TH1I*>(gDirectory->Get("InvariantMass"));
39 
40  //Return to the base directory
42  }
43  japp->RootUnLock(); //RELEASE ROOT LOCK!!
44 }
45 
46 bool DCustomAction_HistMass_b1_1235::Perform_Action(JEventLoop* locEventLoop, const DParticleCombo* locParticleCombo)
47 {
48  //Optional: check whether the user wanted to use the kinematic fit results when performing this action
49 // bool locUseKinFitResultsFlag = Get_UseKinFitResultsFlag();
50 
51  const DParticleComboStep* locParticleComboStep0 = locParticleCombo->Get_ParticleComboStep(0);
52  const DParticleComboStep* locParticleComboStep1 = locParticleCombo->Get_ParticleComboStep(1);
53  const DParticleComboStep* locParticleComboStep2 = locParticleCombo->Get_ParticleComboStep(2);
54 
55  //first get measured particle objects, and check to see if combination of particles is unique
56  const DKinematicData* locPiPlus1 = locParticleComboStep0->Get_FinalParticle_Measured(2);
57 
58  const DKinematicData* locPiPlus2 = locParticleComboStep1->Get_FinalParticle_Measured(0);
59  const DKinematicData* locPiMinus2 = locParticleComboStep1->Get_FinalParticle_Measured(1);
60 
61  const DKinematicData* locPhoton1 = locParticleComboStep2->Get_FinalParticle_Measured(0);
62  const DKinematicData* locPhoton2 = locParticleComboStep2->Get_FinalParticle_Measured(1);
63 
64  set<const DKinematicData*> locCurrentParticles;
65  locCurrentParticles.insert(locPiMinus2);
66  locCurrentParticles.insert(locPiPlus1);
67  locCurrentParticles.insert(locPiPlus2);
68  locCurrentParticles.insert(locPhoton1);
69  locCurrentParticles.insert(locPhoton2);
70 
71  for(size_t loc_i = 0; loc_i < dPastParticles.size(); ++loc_i)
72  {
73  if(locCurrentParticles != dPastParticles[loc_i])
74  continue;
75  return true; //duplicate combo of particles, don't fill histogram!
76  }
77  dPastParticles.push_back(locCurrentParticles);
78 
79  //calculate invariant mass
80  DLorentzVector locP4;
81 // if(!locUseKinFitResultsFlag || (locParticleCombo->Get_KinFitResults() == NULL)) //measured or kinfit failed to converge
82  {
83  locP4 += locPiMinus2->lorentzMomentum();
84  locP4 += locPiPlus1->lorentzMomentum() + locPiPlus2->lorentzMomentum();
85  locP4 += locPhoton1->lorentzMomentum() + locPhoton2->lorentzMomentum();
86  }
87 /* else //kinfit: get kinfit objects first
88  {
89  locPiPlus1 = locParticleComboStep0->Get_FinalParticle(2);
90  locPiPlus2 = locParticleComboStep1->Get_FinalParticle(0);
91  locPiMinus2 = locParticleComboStep1->Get_FinalParticle(1);
92  const DKinematicData* locPiZero = locParticleComboStep1->Get_FinalParticle(2);
93 
94  locP4 += locPiMinus2->lorentzMomentum();
95  locP4 += locPiPlus1->lorentzMomentum() + locPiPlus2->lorentzMomentum();
96  locP4 += locPiZero->lorentzMomentum();
97  }
98  */
99  double locInvariantMass = locP4.M();
100 
101  //FILL HISTOGRAMS
102  //Since we are filling histograms local to this action, it will not interfere with other ROOT operations: can use action-wide ROOT lock
103  //Note, the mutex is unique to this DReaction + action_string combo: actions of same class with different hists will have a different mutex
104  Lock_Action(); //ACQUIRE ROOT LOCK!!
105  {
106  // Fill any histograms here
107  dMassHist->Fill(locInvariantMass);
108  }
109  Unlock_Action(); //RELEASE ROOT LOCK!!
110 
111  return true; //return false if you want to use this action to apply a cut (and it fails the cut!)
112 }
113 
TDirectoryFile * ChangeTo_BaseDirectory(void)
const DKinematicData * Get_FinalParticle_Measured(size_t locFinalParticleIndex) const
static char * ParticleName_ROOT(Particle_t p)
Definition: particleType.h:851
char string[256]
TDirectoryFile * CreateAndChangeTo_ActionDirectory(void)
TLorentzVector DLorentzVector
JApplication * japp
bool Perform_Action(JEventLoop *locEventLoop, const DParticleCombo *locParticleCombo)
deque< set< const DKinematicData * > > dPastParticles
const DAnalysisUtilities * dAnalysisUtilities
DLorentzVector lorentzMomentum(void) const
const DParticleComboStep * Get_ParticleComboStep(size_t locStepIndex) const
void Initialize(JEventLoop *locEventLoop)