13#include <trg/cdc/dataobjects/CDCTriggerMLP.h>
14#include <framework/datastore/StoreArray.h>
15#include <framework/datastore/StoreObjPtr.h>
16#include <trg/cdc/dataobjects/CDCTriggerSegmentHit.h>
17#include <mdst/dataobjects/MCParticle.h>
18#include <tracking/dataobjects/RecoTrack.h>
19#include <trg/cdc/dataobjects/CDCTriggerMLPData.h>
20#include <trg/cdc/dataobjects/CDCTriggerTrack.h>
21#include <trg/cdc/dataobjects/CDCTriggerMLPData.h>
22#include <framework/dataobjects/EventMetaData.h>
23#include <cdc/geometry/CDCGeometryPar.h>
24#include <framework/gearbox/Unit.h>
27#include <framework/geometry/B2Vector3.h>
31namespace NeuroTrainer {
32 std::vector<float> getTrainTargets(
bool& trainonreco,
CDCTriggerTrack* twodtrack, std::string targetcollectionname)
34 std::vector<float> ret;
36 float invptTarget = 0;
37 float thetaTarget = 0;
42 twodtrack->getRelatedTo<
RecoTrack>(targetcollectionname);
44 B2DEBUG(29,
"Skipping CDCTriggerTrack without relation to RecoTrack.");
50 bool foundValidRep =
false;
51 for (
unsigned irep = 0; irep < reps.size() && !foundValidRep; ++irep) {
57 genfit::MeasuredStateOnPlane state =
59 reps[irep]->extrapolateToLine(state, TVector3(0, 0, -1000), TVector3(0, 0, 2000));
62 if (state.getMom().Dot(
B2Vector3D(twodtrack->getDirection())) < 0) {
63 state.setPosMom(state.getPos(), -state.getMom());
64 state.setChargeSign(-state.getCharge());
67 phi0Target = state.getMom().Phi();
68 invptTarget = state.getCharge() / state.getMom().Pt();
69 thetaTarget = state.getMom().Theta();
70 zTarget = state.getPos().Z();
80 twodtrack->getRelatedTo<
MCParticle>(targetcollectionname);
82 B2DEBUG(29,
"Skipping CDCTriggerTrack without relation to MCParticle.");
85 phi0Target = mcTrack->getMomentum().Phi();
86 invptTarget = mcTrack->getCharge() / mcTrack->getMomentum().Rho();
87 thetaTarget = mcTrack->getMomentum().Theta();
88 zTarget = mcTrack->getProductionVertex().Z();
91 ret.push_back(phi0Target);
92 ret.push_back(invptTarget);
93 ret.push_back(thetaTarget);
94 ret.push_back(zTarget);
95 ret.push_back(isvalid);
99 getRelevantID(
CDCTriggerMLPData& trainSet_prepare,
double cutsum,
double relevantcut)
101 std::vector<float> relevantID;
102 relevantID.assign(18, 0.);
105 for (
unsigned iSL = 0; iSL < 9; ++iSL) {
106 int nWires = cdc.nWiresInLayer(layerId);
107 layerId += (iSL > 0 ? 6 : 7);
108 B2DEBUG(28,
"SL " << iSL <<
" (" << nWires <<
" wires)");
110 unsigned maxCounter = 0;
112 unsigned counterSum = 0;
113 for (
int iTS = 0; iTS < nWires; ++iTS) {
115 B2DEBUG(28, iTS <<
" " << trainSet_prepare.
getHitCounter(iSL, iTS));
123 if (maxId > nWires / 2) maxId -= nWires;
124 relevantID[2 * iSL] = maxId;
125 relevantID[2 * iSL + 1] = maxId;
129 double cut = relevantcut * counterSum;
130 B2DEBUG(28,
"Threshold on counterSum: " << cut);
131 unsigned relevantSum = maxCounter;
132 while (counterSum - relevantSum > cut) {
133 int prev = trainSet_prepare.
getHitCounter(iSL, relevantID[2 * iSL] - 1);
134 int next = trainSet_prepare.
getHitCounter(iSL, relevantID[2 * iSL + 1] + 1);
137 (relevantID[2 * iSL + 1] - maxId) > (maxId - relevantID[2 * iSL]))) {
138 --relevantID[2 * iSL];
140 if (relevantID[2 * iSL] <= -nWires)
break;
142 ++relevantID[2 * iSL + 1];
144 if (relevantID[2 * iSL + 1] >= nWires - 1)
break;
150 B2DEBUG(28,
"Threshold on counter: " << cut);
151 while (trainSet_prepare.
getHitCounter(iSL, relevantID[2 * iSL] - 1) > cut) {
152 --relevantID[2 * iSL];
153 if (relevantID[2 * iSL] <= -nWires)
break;
155 while (trainSet_prepare.
getHitCounter(iSL, relevantID[2 * iSL + 1] + 1) > cut) {
156 ++relevantID[2 * iSL + 1];
157 if (relevantID[2 * iSL + 1] >= nWires - 1)
break;
161 relevantID[2 * iSL] -= 0.5;
162 relevantID[2 * iSL + 1] += 0.5;
163 B2DEBUG(28,
"SL " << iSL <<
": "
164 << relevantID[2 * iSL] <<
" " << relevantID[2 * iSL + 1]);
Struct for training data of a single MLP for the neuro trigger.
short getTrackCounter() const
get track counter
unsigned short getHitCounter(unsigned iSL, int iTS) const
get hit counter for super layer and track segment number is super layer.
Track created by the CDC trigger.
The Class for CDC Geometry Parameters.
static CDCGeometryPar & Instance(const CDCGeometry *=nullptr)
Static method to get a reference to the CDCGeometryPar instance.
A Class to store the Monte Carlo particle information.
This is the Reconstruction Event-Data Model Track.
const std::vector< genfit::AbsTrackRep * > & getRepresentations() const
Return a list of track representations. You are not allowed to modify or delete them!
bool wasFitSuccessful(const genfit::AbsTrackRep *representation=nullptr) const
Returns true if the last fit with the given representation was successful.
const genfit::MeasuredStateOnPlane & getMeasuredStateOnPlaneClosestTo(const ROOT::Math::XYZVector &closestPoint, const genfit::AbsTrackRep *representation=nullptr)
Return genfit's MasuredStateOnPlane, that is closest to the given point useful for extrapolation of m...
Abstract base class for different kinds of events.