Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
p3pi_hists/DCustomAction_CutExtraPi0.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: DCustomAction_CutExtraPi0.cc
4 // Created: Sun Jun 28 15:10:49 EDT 2015
5 // Creator: pmatt (on Darwin Pauls-MacBook-Pro-2.local 13.4.0 i386)
6 //
7 
9 
10 void DCustomAction_CutExtraPi0::Initialize(JEventLoop* locEventLoop)
11 {
12  //CREATE THE HISTOGRAMS
13  //Since we are creating histograms, the contents of gDirectory will be modified: must use JANA-wide ROOT lock
14  japp->RootWriteLock(); //ACQUIRE ROOT LOCK!!
15  {
16  // Optional: Useful utility functions.
17  locEventLoop->GetSingle(dAnalysisUtilities);
18 
19  //Required: Create a folder in the ROOT output file that will contain all of the output ROOT objects (if any) for this action.
20  //If another thread has already created the folder, it just changes to it.
22 
23  dHist_Pi0InvariantMass = GetOrCreate_Histogram<TH1I>("InvariantMass_Pi0", ";#gamma#gamma Invariant Mass (GeV/c^{2})", 600, 0.0, 0.3);
24 
25  //Return to the base directory
27  }
28  japp->RootUnLock(); //RELEASE ROOT LOCK!!
29 }
30 
31 bool DCustomAction_CutExtraPi0::Perform_Action(JEventLoop* locEventLoop, const DParticleCombo* locParticleCombo)
32 {
33  vector<const DNeutralParticle*> locUnusedNeutralParticles;
34  dAnalysisUtilities->Get_UnusedNeutralParticles(locEventLoop, locParticleCombo, locUnusedNeutralParticles);
35 
36  bool locPassesCutFlag = true;
37  vector<double> locInvariantMasses; //collect them all, then fill at once (MUCH fewer locks)
38  for(size_t loc_i = 0; loc_i < locUnusedNeutralParticles.size(); ++loc_i)
39  {
40  const DNeutralParticleHypothesis* locPhoton1 = locUnusedNeutralParticles[loc_i]->Get_Hypothesis(Gamma);
41  for(size_t loc_j = loc_i + 1; loc_j < locUnusedNeutralParticles.size(); ++loc_j)
42  {
43  const DNeutralParticleHypothesis* locPhoton2 = locUnusedNeutralParticles[loc_j]->Get_Hypothesis(Gamma);
44  DLorentzVector locP4 = locPhoton1->lorentzMomentum() + locPhoton2->lorentzMomentum();
45 
46  double locInvariantMass = locP4.M();
47  if((locInvariantMass >= dLowMassCut) && (locInvariantMass <= dHighMassCut))
48  locPassesCutFlag = false;
49 
50  //check to see if this combination has already been histogrammed (e.g. on previous combo)
51  set<const DNeutralParticleHypothesis*> locPhotonSet;
52  locPhotonSet.insert(locPhoton1);
53  locPhotonSet.insert(locPhoton2);
54  if(dPreviousSourceObjects.find(locPhotonSet) != dPreviousSourceObjects.end())
55  continue; //dupe: already histed!
56  dPreviousSourceObjects.insert(locPhotonSet);
57 
58  //save to vector to fill hist later
59  locInvariantMasses.push_back(locInvariantMass);
60  }
61  }
62 
63  //FILL HISTOGRAMS
64  //Since we are filling histograms local to this action, it will not interfere with other ROOT operations: can use action-wide ROOT lock
65  //Note, the mutex is unique to this DReaction + action_string combo: actions of same class with different hists will have a different mutex
66  Lock_Action(); //ACQUIRE ROOT LOCK!!
67  {
68  for(size_t loc_i = 0; loc_i < locInvariantMasses.size(); ++loc_i)
69  dHist_Pi0InvariantMass->Fill(locInvariantMasses[loc_i]);
70  }
71  Unlock_Action(); //RELEASE ROOT LOCK!!
72 
73  return locPassesCutFlag; //return false if you want to use this action to apply a cut (and it fails the cut!)
74 }
75 
TDirectoryFile * ChangeTo_BaseDirectory(void)
TDirectoryFile * CreateAndChangeTo_ActionDirectory(void)
TLorentzVector DLorentzVector
bool Perform_Action(JEventLoop *locEventLoop, const DParticleCombo *locParticleCombo)
JApplication * japp
void Initialize(JEventLoop *locEventLoop)
set< set< const DNeutralParticleHypothesis * > > dPreviousSourceObjects
DLorentzVector lorentzMomentum(void) const
void Get_UnusedNeutralParticles(JEventLoop *locEventLoop, const DParticleCombo *locParticleCombo, vector< const DNeutralParticle * > &locUnusedNeutralParticles) const