Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DCustomAction_p2k_hists.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: DCustomAction_p2k_hists.cc
4 // Created: Wed Jan 21 16:53:41 EST 2015
5 // Creator: jrsteven (on Linux ifarm1401 2.6.32-431.el6.x86_64 x86_64)
6 //
7 
9 
10 void DCustomAction_p2k_hists::Initialize(JEventLoop* locEventLoop)
11 {
12  DApplication* dapp=dynamic_cast<DApplication*>(locEventLoop->GetJApplication());
13  JCalibration *jcalib = dapp->GetJCalibration((locEventLoop->GetJEvent()).GetRunNumber());
14 
15  // Parameters for event selection to fill histograms
16  endpoint_energy = 12.;
17  map<string, double> photon_endpoint_energy;
18  if(jcalib->Get("/PHOTON_BEAM/endpoint_energy", photon_endpoint_energy) == false) {
19  endpoint_energy = photon_endpoint_energy["PHOTON_BEAM_ENDPOINT_ENERGY"];
20  }
22 
23  cohmin_energy = 0.;
24  cohedge_energy = 12.;
25  map<string, double> photon_beam_param;
26  if(jcalib->Get("/ANALYSIS/beam_asymmetry/coherent_energy", photon_beam_param) == false) {
27  cohmin_energy = photon_beam_param["cohmin_energy"];
28  cohedge_energy = photon_beam_param["cohedge_energy"];
29  }
30 
31  dEdxCut = 2.2;
32  minMM2Cut = -0.01;
33  maxMM2Cut = 0.01;
34  maxPhiMassCut = 1.05;
35 
36  //CREATE THE HISTOGRAMS
37  //Since we are creating histograms, the contents of gDirectory will be modified: must use JANA-wide ROOT lock
38  japp->RootWriteLock(); //ACQUIRE ROOT LOCK!!
39  {
40  //Required: Create a folder in the ROOT output file that will contain all of the output ROOT objects (if any) for this action.
41  //If another thread has already created the folder, it just changes to it.
43 
44  dEgamma = GetOrCreate_Histogram<TH1I>("Egamma", "TAGGER photon energy; E_{#gamma}", endpoint_energy_bins, 0., endpoint_energy);
45  dInvariantMass = GetOrCreate_Histogram<TH1I>("InvariantMass", "Invariant Mass of K^{+}K^{-};Invariant Mass of K^{+}K^{-} (GeV/c^{2}",270,0.9,1.8);
46  dMissingMassSq = GetOrCreate_Histogram<TH1I>("MissingMassSq", "Missing Mass Sq. of K^{+}K^{-};MM^{2}_{K^{+}K^{-}} (GeV/c^{2}",600,-0.6,0.6);
47  dKplus_deltaInvBeta_P = GetOrCreate_Histogram<TH2I>("Kplus_deltaInvBeta_P","K+ Inverse #Delta#beta vs p; p; 1/#beta_{exp} - 1/#beta_{meas}",200,0,10,500,-0.5,0.5);
48  dKminus_deltaInvBeta_P = GetOrCreate_Histogram<TH2I>("Kminus_deltaInvBeta_P","K- Inverse #Delta#beta vs p; p; 1/#beta_{exp} - 1/#beta_{meas}",200,0,10,500,-0.5,0.5);
49 
50  dMM2_M2k = GetOrCreate_Histogram<TH2I>("MM2_M2k", "MM^{2} off k^{+}k^{-} vs M_{k^{+}k^{-}}; M_{k^{+}k^{-}}; MM^{2}", 800, 0.0, 2.0, 200, -1., 1.);
51  dProton_dEdx_P = GetOrCreate_Histogram<TH2I>("Proton_dEdx_P","dE/dx vs p; p; dE/dx",200,0,2,500,0,5);
52  dProton_P_Theta = GetOrCreate_Histogram<TH2I>("Proton_P_Theta","p vs #theta; #theta; p (GeV/c)",180,0,180,120,0,12);
53  dDeltaE_M2k = GetOrCreate_Histogram<TH2I>("DeltaE_M2k", "#DeltaE vs M_{k^{+}k^{-}}; M_{k^{+}k^{-}}; #DeltaE (tagger - tracks)", 800, 0.0, 2.0, 200, -5., 5.);
54  dM2pi_M2k = GetOrCreate_Histogram<TH2I>("M2pi_M2k", "M_{#pi^{+}#pi^{-}} vs M_{k^{+}k^{-}}; M_{k^{+}k^{-}}; M_{#pi^{+}#pi^{-}}", 800, 0.0, 2.0, 800, 0.0, 2.0);
55 
56  dMM2_M2k_ProtonTag = GetOrCreate_Histogram<TH2I>("MM2_M2k_ProtonTag", "MM^{2} off k^{+}k^{-} vs M_{k^{+}k^{-}}; M_{k^{+}k^{-}}; MM^{2}", 800, 0.0, 2.0, 200, -1., 1.);
57  dDeltaE_M2k_ProtonTag = GetOrCreate_Histogram<TH2I>("DeltaE_M2k_ProtonTag", "#DeltaE vs M_{k^{+}k^{-}}; M_{k^{+}k^{-}}; #DeltaE (tagger - tracks)", 800, 0.0, 2.0, 200, -5., 5.);
58  dM2pi_M2k_ProtonTag = GetOrCreate_Histogram<TH2I>("M2pi_M2k_ProtonTag", "M_{#pi^{+}#pi^{-}} vs M_{k^{+}k^{-}}; M_{k^{+}k^{-}}; M_{#pi^{+}#pi^{-}}", 800, 0.0, 2.0, 800, 0.0, 2.0);
59 
60  dEgamma_M2k_ProtonTag = GetOrCreate_Histogram<TH2I>("Egamma_M2k", "TAGGER photon energy vs M_{k^{+}k^{-}}; M_{k^{+}k^{-}}; E_{#gamma}", 800, 0.0, 2.0, 400, 2., 12.);
61  dKplus_deltaInvBeta_P_ProtonTag = GetOrCreate_Histogram<TH2I>("Kplus_deltaInvBeta_P_ProtonTag","K+ Inverse #Delta#beta vs p; p; 1/#beta_{exp} - 1/#beta_{meas}",200,0,10,500,-0.5,0.5);
62  dKminus_deltaInvBeta_P_ProtonTag = GetOrCreate_Histogram<TH2I>("Kminus_deltaInvBeta_P_ProtonTag","K- Inverse #Delta#beta vs p; p; 1/#beta_{exp} - 1/#beta_{meas}",200,0,10,500,-0.5,0.5);
63 
64  dKplus_deltaInvBeta_P_PhiTag = GetOrCreate_Histogram<TH2I>("Kplus_deltaInvBeta_P_PhiTag","K+ Inverse #Delta#beta vs p; p; 1/#beta_{exp} - 1/#beta_{meas}",200,0,10,500,-0.5,0.5);
65  dKminus_deltaInvBeta_P_PhiTag = GetOrCreate_Histogram<TH2I>("Kminus_deltaInvBeta_P_PhiTag","K- Inverse #Delta#beta vs p; p; 1/#beta_{exp} - 1/#beta_{meas}",200,0,10,500,-0.5,0.5);
66  dKplus_Beta_P_PhiTag = GetOrCreate_Histogram<TH2I>("Kplus_Beta_P_PhiTag","K+ #beta vs p; p; #beta",200,0,10,500,-0.5,1.5);
67  dKminus_Beta_P_PhiTag = GetOrCreate_Histogram<TH2I>("Kminus_Beta_P_PhiTag","K- #beta vs p; p; #beta",200,0,10,500,-0.5,1.5);
68 
69  dKplus_deltaInvBeta_P_RhoTag = GetOrCreate_Histogram<TH2I>("Kplus_deltaInvBeta_P_RhoTag","K+ Inverse #Delta#beta vs p; p; 1/#beta_{exp} - 1/#beta_{meas}",200,0,10,500,-0.5,0.5);
70  dKminus_deltaInvBeta_P_RhoTag = GetOrCreate_Histogram<TH2I>("Kminus_deltaInvBeta_P_RhoTag","K- Inverse #Delta#beta vs p; p; 1/#beta_{exp} - 1/#beta_{meas}",200,0,10,500,-0.5,0.5);
71  dKplus_Beta_P_RhoTag = GetOrCreate_Histogram<TH2I>("Kplus_Beta_P_RhoTag","K+ #beta vs p; p; #beta",200,0,10,500,-0.5,1.5);
72  dKminus_Beta_P_RhoTag = GetOrCreate_Histogram<TH2I>("Kminus_Beta_P_RhoTag","K- #beta vs p; p; #beta",200,0,10,500,-0.5,1.5);
73 
74  dKplus_P_Theta_PhiTag = GetOrCreate_Histogram<TH2I>("Kplus_P_Theta_PhiTag","K+ p vs #theta; #theta; p (GeV)",180,0,180,200,0.,10.);
75  dKminus_P_Theta_PhiTag = GetOrCreate_Histogram<TH2I>("Kminus_P_Theta_PhiTag","K- p vs #theta; #theta; p (GeV)",180,0,180,200,0.,10.);
76  dKplus_P_Theta_RhoTag = GetOrCreate_Histogram<TH2I>("Kplus_P_Theta_RhoTag","K+ p vs #theta; #theta; p (GeV)",180,0,180,200,0.,10.);
77  dKminus_P_Theta_RhoTag = GetOrCreate_Histogram<TH2I>("Kminus_P_Theta_RhoTag","K- p vs #theta; #theta; p (GeV)",180,0,180,200,0.,10.);
78 
79  //Return to the base directory
81  }
82  japp->RootUnLock(); //RELEASE ROOT LOCK!!
83 }
84 
85 bool DCustomAction_p2k_hists::Perform_Action(JEventLoop* locEventLoop, const DParticleCombo* locParticleCombo)
86 {
87  // should only have one reaction step
88  const DParticleComboStep* locParticleComboStep = locParticleCombo->Get_ParticleComboStep(0);
89 
90  // get beam photon energy and final state particles
91  const DKinematicData* locBeamPhoton = Get_UseKinFitResultsFlag() ? locParticleComboStep->Get_InitialParticle() : locParticleComboStep->Get_InitialParticle_Measured();
92  auto locParticles = Get_UseKinFitResultsFlag() ? locParticleComboStep->Get_FinalParticles() : locParticleComboStep->Get_FinalParticles_Measured();
93  double locBeamPhotonEnergy = locBeamPhoton->energy();
94 
95  // get k+ and k- tracks
96  double kplus_beta = -1.;
97  double kminus_beta = -1.;
98  double kplus_deltaInvBeta = -1.;
99  double kminus_deltaInvBeta = -1.;
100  DLorentzVector kplus_PionHypothesis, kminus_PionHypothesis;
101  for(size_t loc_i = 0; loc_i < 2; ++loc_i) {
102  const DChargedTrack* locChargedTrack = static_cast<const DChargedTrack*>(locParticleComboStep->Get_FinalParticle_SourceObject(loc_i));
103  const DChargedTrackHypothesis* locChargedTrackHypothesis;
104  if(loc_i == 0) {
105  locChargedTrackHypothesis = locChargedTrack->Get_Hypothesis(KPlus);
106  if(locChargedTrackHypothesis == NULL) { cout<<"Missing K+"<<endl; continue; }
107  kplus_beta = locChargedTrackHypothesis->measuredBeta();
108  kplus_deltaInvBeta = 1.0/locChargedTrackHypothesis->lorentzMomentum().Beta() - 1.0/kplus_beta;
109 
110  const DChargedTrackHypothesis* locChargedTrackPion = locChargedTrack->Get_Hypothesis(PiPlus);
111  if(locChargedTrackPion != NULL)
112  kplus_PionHypothesis = locChargedTrackPion->lorentzMomentum();
113  //else
114 
115  kplus_PionHypothesis.SetXYZM(locParticles[0]->lorentzMomentum().X(), locParticles[0]->lorentzMomentum().Y(), locParticles[0]->lorentzMomentum().Z(), 0.13957);
116  }
117  else if(loc_i == 1){
118  locChargedTrackHypothesis = locChargedTrack->Get_Hypothesis(KMinus);
119  if(locChargedTrackHypothesis == NULL) { cout<<"Missing K-"<<endl; continue; }
120  kminus_beta = locChargedTrackHypothesis->measuredBeta();
121  kplus_deltaInvBeta = 1.0/locChargedTrackHypothesis->lorentzMomentum().Beta() - 1.0/kplus_beta;
122 
123  const DChargedTrackHypothesis* locChargedTrackPion = locChargedTrack->Get_Hypothesis(PiMinus);
124  if(locChargedTrackPion != NULL)
125  kminus_PionHypothesis = locChargedTrackPion->lorentzMomentum();
126  //else
127 
128  kminus_PionHypothesis.SetXYZM(locParticles[1]->lorentzMomentum().X(), locParticles[1]->lorentzMomentum().Y(), locParticles[1]->lorentzMomentum().Z(), 0.13957);
129  }
130  }
131 
132  // calculate 2k P4
133  DLorentzVector locP4_2k = locParticles[0]->lorentzMomentum() + locParticles[1]->lorentzMomentum();
134  DLorentzVector locP4_2pi = kplus_PionHypothesis + kminus_PionHypothesis;
135 
136  // calculate missing P4
138 
139  // reconstructed proton variables
140  double dEdx = 0.;
141  DLorentzVector locProtonP4;
142  const DChargedTrack* locChargedTrack = static_cast<const DChargedTrack*>(locParticleComboStep->Get_FinalParticle_SourceObject(2));
143  const DChargedTrackHypothesis* locChargedTrackHypothesis = locChargedTrack->Get_Hypothesis(Proton);
144  dEdx = locChargedTrackHypothesis->Get_TrackTimeBased()->dEdx()*1e6;
145  locProtonP4 = locChargedTrackHypothesis->lorentzMomentum();
146 
147  //FILL HISTOGRAMS
148  //Since we are filling histograms local to this action, it will not interfere with other ROOT operations: can use action-wide ROOT lock
149  //Note, the mutex is unique to this DReaction + action_string combo: actions of same class with different hists will have a different mutex
150  Lock_Action(); //ACQUIRE ROOT LOCK!!
151  {
152  // Fill histograms here
153  dEgamma->Fill(locBeamPhotonEnergy);
154 
155  dKplus_deltaInvBeta_P->Fill(locParticles[0]->lorentzMomentum().Vect().Mag(), kplus_deltaInvBeta);
156  dKminus_deltaInvBeta_P->Fill(locParticles[1]->lorentzMomentum().Vect().Mag(), kminus_deltaInvBeta);
157 
158  dMM2_M2k->Fill(locP4_2k.M(), locMissingP4.M2());
159  dDeltaE_M2k->Fill(locP4_2k.M(),locMissingP4.E());
160  dM2pi_M2k->Fill(locP4_2k.M(), locP4_2pi.M());
161 
162  dMissingMassSq->Fill(locMissingP4.M2());
163 
164  if(locMissingP4.M2() > minMM2Cut && locMissingP4.M2() < maxMM2Cut) {
165 
166  dProton_dEdx_P->Fill(locProtonP4.Vect().Mag(), dEdx);
167  dProton_P_Theta->Fill(locProtonP4.Vect().Theta()*180/TMath::Pi(), locProtonP4.Vect().Mag());
168 
169  // plots for proton tagged events
170  if(dEdx > dEdxCut) {
171 
172  dMM2_M2k_ProtonTag->Fill(locP4_2k.M(), locMissingP4.M2());
173  dDeltaE_M2k_ProtonTag->Fill(locP4_2k.M(),locMissingP4.E());
174  dM2pi_M2k_ProtonTag->Fill(locP4_2k.M(), locP4_2pi.M());
175 
176  dKplus_deltaInvBeta_P_ProtonTag->Fill(locParticles[0]->lorentzMomentum().Vect().Mag(), kplus_deltaInvBeta);
177  dKminus_deltaInvBeta_P_ProtonTag->Fill(locParticles[1]->lorentzMomentum().Vect().Mag(), kminus_deltaInvBeta);
178 
179  // plots vs phi mass
180  dEgamma_M2k_ProtonTag->Fill(locP4_2k.M(),locBeamPhotonEnergy);
181 
182  dInvariantMass->Fill(locP4_2k.M());
183 
184  // correlations for rho vs phi mass regions
185  if(locP4_2k.M() < maxPhiMassCut){
186  dKplus_deltaInvBeta_P_PhiTag->Fill(locParticles[0]->lorentzMomentum().Vect().Mag(), kplus_deltaInvBeta);
187  dKminus_deltaInvBeta_P_PhiTag->Fill(locParticles[1]->lorentzMomentum().Vect().Mag(), kminus_deltaInvBeta);
188 
189  dKplus_P_Theta_PhiTag->Fill(locParticles[0]->lorentzMomentum().Theta()*180./TMath::Pi(),locParticles[0]->lorentzMomentum().Vect().Mag());
190  dKminus_P_Theta_PhiTag->Fill(locParticles[1]->lorentzMomentum().Theta()*180./TMath::Pi(),locParticles[1]->lorentzMomentum().Vect().Mag());
191 
192  dKplus_Beta_P_PhiTag->Fill(locParticles[0]->lorentzMomentum().Vect().Mag(), kplus_beta);
193  dKminus_Beta_P_PhiTag->Fill(locParticles[1]->lorentzMomentum().Vect().Mag(), kminus_beta);
194  }
195  else {
196  dKplus_deltaInvBeta_P_RhoTag->Fill(locParticles[0]->lorentzMomentum().Vect().Mag(), kplus_deltaInvBeta);
197  dKminus_deltaInvBeta_P_RhoTag->Fill(locParticles[1]->lorentzMomentum().Vect().Mag(), kminus_deltaInvBeta);
198 
199  dKplus_P_Theta_RhoTag->Fill(locParticles[0]->lorentzMomentum().Theta()*180./TMath::Pi(),locParticles[0]->lorentzMomentum().Vect().Mag());
200  dKminus_P_Theta_RhoTag->Fill(locParticles[1]->lorentzMomentum().Theta()*180./TMath::Pi(),locParticles[1]->lorentzMomentum().Vect().Mag());
201 
202  dKplus_Beta_P_RhoTag->Fill(locParticles[0]->lorentzMomentum().Vect().Mag(), kplus_beta);
203  dKminus_Beta_P_RhoTag->Fill(locParticles[1]->lorentzMomentum().Vect().Mag(), kminus_beta);
204  }
205  }
206  }
207  }
208  Unlock_Action(); //RELEASE ROOT LOCK!!
209 
210  return true; //return false if you want to use this action to apply a cut (and it fails the cut!)
211 }
212 
vector< const DKinematicData * > Get_FinalParticles_Measured(void) const
TDirectoryFile * ChangeTo_BaseDirectory(void)
DApplication * dapp
const DReaction * Get_Reaction(void) const
double energy(void) const
const DTrackTimeBased * Get_TrackTimeBased(void) const
TDirectoryFile * CreateAndChangeTo_ActionDirectory(void)
double measuredBeta(void) const
const DKinematicData * Get_InitialParticle_Measured(void) const
TLorentzVector DLorentzVector
#define X(str)
Definition: hddm-c.cpp:83
const DChargedTrackHypothesis * Get_Hypothesis(Particle_t locPID) const
Definition: DChargedTrack.h:59
bool Get_UseKinFitResultsFlag(void) const
JApplication * japp
DLorentzVector Calc_MissingP4(const DReaction *locReaction, const DParticleCombo *locParticleCombo, bool locUseKinFitDataFlag) const
void Initialize(JEventLoop *locEventLoop)
vector< const DKinematicData * > Get_FinalParticles(void) const
DLorentzVector lorentzMomentum(void) const
const JObject * Get_FinalParticle_SourceObject(size_t locFinalParticleIndex) const
const DKinematicData * Get_InitialParticle(void) const
const DAnalysisUtilities * dAnalysisUtilities
double dEdx(void) const
bool Perform_Action(JEventLoop *locEventLoop, const DParticleCombo *locParticleCombo)
const DParticleComboStep * Get_ParticleComboStep(size_t locStepIndex) const