Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DNeutralShower_factory.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: DNeutralShower_factory.cc
4 // Created: Tue Aug 9 14:29:24 EST 2011
5 // Creator: pmatt (on Linux ifarml6 2.6.18-128.el5 x86_64)
6 //
7 
9 #include "DEventRFBunch.h"
10 
11 inline bool DNeutralShower_SortByEnergy(const DNeutralShower* locNeutralShower1, const DNeutralShower* locNeutralShower2)
12 {
13  // truncate the shower energies: in units of MeV, ignore all digits that are 10s-place and above
14  // then sort by increasing energy: pseudo-random
15 
16  //guard against NaN: necessary since casting to int
17  bool locFirstIsNaN = (!(locNeutralShower1->dEnergy > -1.0) && !(locNeutralShower1->dEnergy < 1.0));
18  bool locSecondIsNaN = (!(locNeutralShower2->dEnergy > -1.0) && !(locNeutralShower2->dEnergy < 1.0));
19  if(locFirstIsNaN)
20  return false;
21  if(locSecondIsNaN)
22  return true;
23  double locE1 = locNeutralShower1->dEnergy - double(int(locNeutralShower1->dEnergy*100.0))/100.0;
24  double locE2 = locNeutralShower2->dEnergy - double(int(locNeutralShower2->dEnergy*100.0))/100.0;
25  return (locE1 < locE2);
26 }
27 
28 // constructor
29 
31 {
32 
33  vector< string > vars( inputVars, inputVars + sizeof( inputVars )/sizeof( char* ) );
35 
36  dResourcePool_TMatrixFSym = std::make_shared<DResourcePool<TMatrixFSym>>();
37 }
38 
39 
40 //------------------
41 // init
42 //------------------
44 {
45  dResourcePool_TMatrixFSym->Set_ControlParams(20, 20, 20);
46  return NOERROR;
47 }
48 
49 //------------------
50 // brun
51 //------------------
52 jerror_t DNeutralShower_factory::brun(jana::JEventLoop *locEventLoop, int32_t runnumber)
53 {
54 
55  DApplication* locApplication = dynamic_cast<DApplication*>(locEventLoop->GetJApplication());
56  DGeometry* locGeometry = locApplication->GetDGeometry(runnumber);
57 
58  double locTargetCenterZ;
59  locGeometry->GetTargetZ(locTargetCenterZ);
60  dTargetCenter.SetXYZ(0.0, 0.0, locTargetCenterZ);
61 
62  return NOERROR;
63 }
64 
65 //------------------
66 // evnt
67 //------------------
68 jerror_t DNeutralShower_factory::evnt(jana::JEventLoop *locEventLoop, uint64_t eventnumber)
69 {
70  const DDetectorMatches* locDetectorMatches = NULL;
71  locEventLoop->GetSingle(locDetectorMatches);
72 
73  vector<const DBCALShower*> locBCALShowers;
74  locEventLoop->Get(locBCALShowers);
75 
76  vector<const DFCALShower*> locFCALShowers;
77  locEventLoop->Get(locFCALShowers);
78 
79  vector< const DEventRFBunch* > eventRFBunches;
80  locEventLoop->Get(eventRFBunches);
81  // there should always be one and only one object or else it is a coding error
82  assert( eventRFBunches.size() == 1 );
83  double rfTime = eventRFBunches[0]->dTime; // this is the RF time at the center of the target
84 
85  // Loop over all DBCALShowers, create DNeutralShower if didn't match to any tracks
86  // The chance of an actual neutral shower matching to a bogus track is very small
87  JObject::oid_t locShowerID = 0;
88  for(size_t loc_i = 0; loc_i < locBCALShowers.size(); ++loc_i)
89  {
90  if(locDetectorMatches->Get_IsMatchedToTrack(locBCALShowers[loc_i]))
91  continue;
92 
93  // create DNeutralShower
94  DNeutralShower* locNeutralShower = new DNeutralShower();
95  locNeutralShower->dBCALFCALShower = static_cast<const JObject*>(locBCALShowers[loc_i]);
96  locNeutralShower->dDetectorSystem = SYS_BCAL;
97  locNeutralShower->dShowerID = locShowerID;
98  ++locShowerID;
99 
100  // in the BCAL set the quality variable 1 to avoid eliminating
101  // NeutralShowers in future splitoff rejection algorithms
102  locNeutralShower->dQuality = 1;
103 
104  locNeutralShower->dEnergy = locBCALShowers[loc_i]->E;
105  locNeutralShower->dSpacetimeVertex.SetXYZT(locBCALShowers[loc_i]->x, locBCALShowers[loc_i]->y, locBCALShowers[loc_i]->z, locBCALShowers[loc_i]->t);
106  auto locCovMatrix = dResourcePool_TMatrixFSym->Get_SharedResource();
107  locCovMatrix->ResizeTo(5, 5);
108  *locCovMatrix = locBCALShowers[loc_i]->ExyztCovariance;
109  locNeutralShower->dCovarianceMatrix = locCovMatrix;
110 
111  locNeutralShower->AddAssociatedObject(locBCALShowers[loc_i]);
112 
113  _data.push_back(locNeutralShower);
114  }
115 
116  // Loop over all DFCALShowers, create DNeutralShower if didn't match to any tracks
117  // The chance of an actual neutral shower matching to a bogus track is very small
118  for(size_t loc_i = 0; loc_i < locFCALShowers.size(); ++loc_i)
119  {
120  if(locDetectorMatches->Get_IsMatchedToTrack(locFCALShowers[loc_i]))
121  continue;
122 
123  // create DNeutralShower
124  DNeutralShower* locNeutralShower = new DNeutralShower();
125  locNeutralShower->dBCALFCALShower = static_cast<const JObject*>(locFCALShowers[loc_i]);
126  locNeutralShower->dDetectorSystem = SYS_FCAL;
127  locNeutralShower->dShowerID = locShowerID;
128  ++locShowerID;
129 
130  locNeutralShower->dEnergy = locFCALShowers[loc_i]->getEnergy();
131  locNeutralShower->dSpacetimeVertex.SetVect(locFCALShowers[loc_i]->getPosition());
132  locNeutralShower->dSpacetimeVertex.SetT(locFCALShowers[loc_i]->getTime());
133 
134  locNeutralShower->dQuality = getFCALQuality( locFCALShowers[loc_i], rfTime );
135 
136  auto locCovMatrix = dResourcePool_TMatrixFSym->Get_SharedResource();
137  locCovMatrix->ResizeTo(5, 5);
138  *locCovMatrix = locFCALShowers[loc_i]->ExyztCovariance;
139  locNeutralShower->dCovarianceMatrix = locCovMatrix;
140 
141  locNeutralShower->AddAssociatedObject(locFCALShowers[loc_i]);
142 
143  _data.push_back(locNeutralShower);
144  }
145 
146  sort(_data.begin(), _data.end(), DNeutralShower_SortByEnergy);
147 
148  return NOERROR;
149 }
150 
151 //------------------
152 // erun
153 //------------------
155 {
156  return NOERROR;
157 }
158 
159 //------------------
160 // fini
161 //------------------
163 {
164  return NOERROR;
165 }
166 
167 double DNeutralShower_factory::getFCALQuality( const DFCALShower* fcalShower, double rfTime ) const {
168 
169  double flightDistance = ( fcalShower->getPosition() - dTargetCenter ).Mag();
170  double flightTime = fcalShower->getTime() - rfTime;
171 
172  vector< double > mvaInputs( 8 );
173  mvaInputs[0] = fcalShower->getNumBlocks();
174  mvaInputs[1] = fcalShower->getE9E25();
175  mvaInputs[2] = fcalShower->getE1E9();
176  mvaInputs[3] = fcalShower->getSumU();
177  mvaInputs[4] = fcalShower->getSumV();
178  mvaInputs[5] = ( mvaInputs[3] - mvaInputs[4] ) / ( mvaInputs[3] + mvaInputs[4] );
179  mvaInputs[6] = flightDistance / flightTime;
180  mvaInputs[7] = fcalShower->getTime() - ( rfTime + fcalShower->getTimeTrack() );
181 
182  return dFCALClassifier->GetMvaValue( mvaInputs );
183 }
jerror_t evnt(jana::JEventLoop *locEventLoop, uint64_t eventnumber)
Called every event.
Double_t x[NCHANNELS]
Definition: st_tw_resols.C:39
double getTime() const
Definition: DFCALShower.h:161
#define y
const JObject * dBCALFCALShower
jerror_t brun(jana::JEventLoop *locEventLoop, int32_t runnumber)
Called everytime a new run number is detected.
DNeutralShower_FCALQualityMLP * dFCALClassifier
double GetMvaValue(const std::vector< double > &inputValues) const
Definition: GlueX.h:19
DetectorSystem_t dDetectorSystem
DLorentzVector dSpacetimeVertex
double getFCALQuality(const DFCALShower *fcalShower, double rfTime) const
jerror_t init(void)
Called once at program start.
DGeometry * GetDGeometry(unsigned int run_number)
Definition: GlueX.h:22
double getE9E25() const
Definition: DFCALShower.h:170
shared_ptr< TMatrixFSym > dCovarianceMatrix
double getSumU() const
Definition: DFCALShower.h:168
shared_ptr< DResourcePool< TMatrixFSym > > dResourcePool_TMatrixFSym
jerror_t fini(void)
Called after last event of last event source has been processed.
double getSumV() const
Definition: DFCALShower.h:169
double getTimeTrack() const
Definition: DFCALShower.h:167
int getNumBlocks() const
Definition: DFCALShower.h:172
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
double getE1E9() const
Definition: DFCALShower.h:171
bool DNeutralShower_SortByEnergy(const DNeutralShower *locNeutralShower1, const DNeutralShower *locNeutralShower2)
DVector3 getPosition() const
Definition: DFCALShower.h:151
bool GetTargetZ(double &z_target) const
z-location of center of target
Definition: DGeometry.cc:1933
bool Get_IsMatchedToTrack(const DBCALShower *locBCALShower) const