Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DEventProcessor_coherent_peak_skim.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: DEventProcessor_coherent_peak_skim.cc
4 // Created: Tue Mar 28 10:57:49 EDT 2017
5 // Creator: pmatt (on Linux pmattdesktop.jlab.org 2.6.32-696.el6.x86_64 x86_64)
6 //
7 
9 
10 // Routine used to create our DEventProcessor
11 
12 extern "C"
13 {
14  void InitPlugin(JApplication *locApplication)
15  {
16  InitJANAPlugin(locApplication);
17  locApplication->AddProcessor(new DEventProcessor_coherent_peak_skim()); //register this plugin
18  }
19 } // "C"
20 
21 //------------------
22 // init
23 //------------------
25 {
26  // This is called once at program startup.
27 
30  dTimingCutMap[Proton][SYS_NULL] = -1.0;
34  dTimingCutMap[PiPlus][SYS_NULL] = -1.0;
50 
51  dShowerEOverPCut = 0.75;
52 
53  return NOERROR;
54 }
55 
56 //------------------
57 // brun
58 //------------------
59 jerror_t DEventProcessor_coherent_peak_skim::brun(jana::JEventLoop* locEventLoop, int32_t locRunNumber)
60 {
61  // This is called whenever the run number changes
62  vector<double> locBeamPeriodVector;
63  locEventLoop->GetCalib("PHOTON_BEAM/RF/beam_period", locBeamPeriodVector);
64  dBeamBunchPeriod = locBeamPeriodVector[0];
65 
66  dCoherentPeakRange = pair<double, double>(8.4, 9.0);
67  map<string, double> photon_beam_param;
68  if(locEventLoop->GetCalib("/ANALYSIS/beam_asymmetry/coherent_energy", photon_beam_param) == false)
69  dCoherentPeakRange = pair<double, double>(photon_beam_param["cohmin_energy"], photon_beam_param["cohedge_energy"]);
70  dCoherentPeakRange.first -= 0.2; //same as below
71  dCoherentPeakRange.second += 0.2; //in case the high-side edge is fluctuating a lot
72 
73  DApplication* locApplication = dynamic_cast<DApplication*>(locEventLoop->GetJApplication());
74  DGeometry* locGeometry = locApplication->GetDGeometry(locRunNumber);
75  locGeometry->GetTargetZ(dTargetCenterZ);
76  return NOERROR;
77 }
78 
79 //------------------
80 // evnt
81 //------------------
82 jerror_t DEventProcessor_coherent_peak_skim::evnt(jana::JEventLoop* locEventLoop, uint64_t locEventNumber)
83 {
84  // This is called for every event. Use of common resources like writing
85  // to a file or filling a histogram should be mutex protected. Using
86  // locEventLoop->Get(...) to get reconstructed objects (and thereby activating the
87  // reconstruction algorithm) should be done outside of any mutex lock
88  // since multiple threads may call this method at the same time.
89  //
90  // Here's an example:
91  //
92  // vector<const MyDataClass*> mydataclasses;
93  // locEventLoop->Get(mydataclasses);
94  //
95  // japp->RootFillLock(this);
96  // ... fill historgrams or trees ...
97  // japp->RootFillUnLock(this);
98 
99  // DOCUMENTATION:
100  // ANALYSIS library: https://halldweb1.jlab.org/wiki/index.php/GlueX_Analysis_Software
101 
102  //THE BELOW ALGORITHM IS BAD. WHY?
103  //Because junk or accidental tracks could have voted on which is the correct RF bunch
104 
105  vector<const DBeamPhoton*> locBeamPhotons;
106  locEventLoop->Get(locBeamPhotons);
107 
108  vector<const DChargedTrack*> locChargedTracks;
109  locEventLoop->Get(locChargedTracks, "PreSelect");
110 
111  const DEventRFBunch* locEventRFBunch = NULL;
112  locEventLoop->GetSingle(locEventRFBunch);
113 /*
114  bool locIsHadronicEventFlag = false;
115  for(auto locTrack : locChargedTracks)
116  {
117  //make sure at least one track isn't a lepton!! (read: e+/-. assume all muons come from pion decays)
118  auto locChargedHypo = locTrack->Get_Hypothesis(PiPlus);
119  if(locChargedHypo == nullptr)
120  locChargedHypo = locTrack->Get_Hypothesis(PiMinus);
121  if(locChargedHypo == nullptr)
122  locChargedHypo = locTrack->Get_BestFOM();
123  if(locChargedHypo == nullptr)
124  continue; //should be impossible!!
125 
126  //timing cut: is it consistent with an e+/-??
127  auto locDetector = locChargedHypo->t1_detector();
128  double locDeltaT = locChargedHypo->time() - locChargedHypo->t0();
129  if(fabs(locDeltaT) > dTimingCutMap[Electron][locDetector])
130  {
131  locIsHadronicEventFlag = true; //not an electron!!
132  break;
133  }
134 
135  //compute shower-E/p, cut
136  if(Cut_ShowerEOverP(locChargedHypo))
137  {
138  locIsHadronicEventFlag = true; //not an electron!!
139  break;
140  }
141  }
142 */
143  bool locIsTrackEventFlag = !locChargedTracks.empty();
144 
145  //see if is in coherent peak
146  bool locCoherentPeakFlag = false;
147  if(std::isnan(locEventRFBunch->dTime))
148  locCoherentPeakFlag = true;
149  for(auto& locBeamPhoton : locBeamPhotons)
150  {
151  if((locBeamPhoton->energy() < dCoherentPeakRange.first) || (locBeamPhoton->energy() > dCoherentPeakRange.second))
152  continue; //not in coherent peak
153 
154  double locBeamRFDeltaT = locBeamPhoton->time() - locEventRFBunch->dTime;
155  if(fabs(locBeamRFDeltaT) > 0.5*dBeamBunchPeriod)
156  continue;
157  locCoherentPeakFlag = true;
158  break;
159  }
160 
161  /******************************************************** OPTIONAL: SKIMS *******************************************************/
162 
163  //Optional: Save event to output REST file. Use this to create physical skims.
164  const DEventWriterREST* locEventWriterREST = NULL;
165  locEventLoop->GetSingle(locEventWriterREST);
166 // if(locIsHadronicEventFlag && locCoherentPeakFlag)
167 // locEventWriterREST->Write_RESTEvent(locEventLoop, "hadronic_coherent_peak"); //string is part of output file name
168  if(locCoherentPeakFlag && locIsTrackEventFlag)
169  locEventWriterREST->Write_RESTEvent(locEventLoop, "coherent_peak"); //string is part of output file name
170 
171  return NOERROR;
172 }
173 
175 {
176  //compute shower-E/p, cut
177  double locP = locChargedHypo->momentum().Mag();
178  double locShowerEOverP = -1.0;
179  auto locFCALShowerMatchParams = locChargedHypo->Get_FCALShowerMatchParams();
180  auto locBCALShowerMatchParams = locChargedHypo->Get_BCALShowerMatchParams();
181  if(locFCALShowerMatchParams != NULL)
182  {
183  const DFCALShower* locFCALShower = locFCALShowerMatchParams->dFCALShower;
184  locShowerEOverP = locFCALShower->getEnergy()/locP;
185  }
186  else if(locBCALShowerMatchParams != NULL)
187  {
188  const DBCALShower* locBCALShower = locBCALShowerMatchParams->dBCALShower;
189  locShowerEOverP = locBCALShower->E/locP;
190  }
191 
192  return (locShowerEOverP <= dShowerEOverPCut);
193 }
194 
195 double DEventProcessor_coherent_peak_skim::Step_TimeToNearInputTime(double locTimeToStep, double locTimeToStepTo) const
196 {
197  double locDeltaT = locTimeToStepTo - locTimeToStep;
198  int locNumBucketsToShift = (locDeltaT > 0.0) ? int(locDeltaT/dBeamBunchPeriod + 0.5) : int(locDeltaT/dBeamBunchPeriod - 0.5);
199  return (locTimeToStep + dBeamBunchPeriod*double(locNumBucketsToShift));
200 }
201 
bool Cut_ShowerEOverP(const DChargedTrackHypothesis *locChargedHypo) const
double getEnergy() const
Definition: DFCALShower.h:156
double Step_TimeToNearInputTime(double locTimeToStep, double locTimeToStepTo) const
Definition: GlueX.h:16
jerror_t evnt(jana::JEventLoop *locEventLoop, uint64_t locEventNumber)
Called every event.
jerror_t brun(jana::JEventLoop *locEventLoop, int32_t locRunNumber)
Called every time a new run number is detected.
Definition: GlueX.h:19
bool Write_RESTEvent(JEventLoop *locEventLoop, string locOutputFileNameSubString) const
InitPlugin_t InitPlugin
Definition: GlueX.h:20
DGeometry * GetDGeometry(unsigned int run_number)
Definition: GlueX.h:22
shared_ptr< const DFCALShowerMatchParams > Get_FCALShowerMatchParams(void) const
map< Particle_t, map< DetectorSystem_t, double > > dTimingCutMap
const DVector3 & momentum(void) const
jerror_t init(void)
Called once at program start.
shared_ptr< const DBCALShowerMatchParams > Get_BCALShowerMatchParams(void) const
bool GetTargetZ(double &z_target) const
z-location of center of target
Definition: DGeometry.cc:1933