9#include <tracking/trackFindingCDC/findlets/complete/AsicBackgroundLibraryCreator.h>
10#include <tracking/trackingUtilities/eventdata/hits/CDCWireHit.h>
11#include <tracking/trackingUtilities/eventdata/tracks/CDCTrack.h>
12#include <tracking/trackingUtilities/eventdata/trajectories/CDCTrajectory2D.h>
13#include <tracking/trackingUtilities/eventdata/trajectories/CDCTrajectorySZ.h>
14#include <cdc/topology/CDCWire.h>
15#include <tracking/trackingUtilities/utilities/StringManipulation.h>
16#include <framework/core/ModuleParamList.templateDetails.h>
17#include <cdc/dataobjects/CDCHit.h>
18#include <framework/logging/Logger.h>
29using namespace TrackFindingCDC;
30using namespace TrackingUtilities;
39 if (wireHit->isAxial()) {
40 recoPos2D = wireHit->reconstruct2D(trajectory2D);
42 const CDCWire& wire = wireHit->getWire();
43 const Vector2D& posOnXYPlane = wireHit->reconstruct2D(trajectory2D);
45 const double z = trajectorySZ.
mapSToZ(arcLength);
48 const double driftLength = wireHit->getRefDriftLength();
49 Vector2D disp2D = recoPosOnTrajectory - wirePos2DAtZ;
51 recoPos2D = wirePos2DAtZ + disp2D;
53 const float distanceToHit = trajectory2D.
getDist2D(recoPos2D);
54 return std::abs(distanceToHit);
63 if ((*m_channelMapFromDB).isValid()) {
64 B2DEBUG(29,
"CDC Channel map is valid");
66 B2FATAL(
"CDC Channel map is not valid");
71 auto leavesCreator = [
this](TTree & tree) {
74 tree.Branch(
"ADC", &
m_adc_sig,
"ADC_Sig/S:ADC_bg/S");
77 tree.Branch(
"Board", &
m_board,
"board/b");
78 tree.Branch(
"Channel", &
m_channel,
"channel/b");
79 tree.Branch(
"Nhit", &
m_n_hit,
"nhit/b");
81 "TDC0/S:ADC0/S:TOT0/S:TDC1/S:ADC1/S:TOT1/S:TDC2/S:ADC2/S:TOT2/S:TDC3/S:ADC3/S:TOT3/S:TDC4/S:ADC4/S:TOT4/S:TDC5/S:ADC5/S:TOT5/S:TDC6/S:ADC6/S:TOT6/S:TDC7/S:ADC7/S:TOT7/S");
96 const int isl = cm.getISuperLayer();
97 const int il = cm.getILayer();
98 const int iw = cm.getIWire();
99 const int iBoard = cm.getBoardID();
100 const int iCh = cm.getBoardChannel();
101 const WireID wireId(isl, il, iw);
108 return "Finds suitable ASICs with a single hit attached to a track and uses them to create the library";
114 std::map< std::pair<int, int>, std::vector<const CDCWireHit*>> groupedByAsic;
117 B2ASSERT(
"Channel map NOT found for the channel",
m_map.count(eWire) > 0);
118 auto board =
m_map[eWire].first;
119 auto channel =
m_map[eWire].second;
120 auto asicID = std::pair<int, int>(board, channel / 8);
121 groupedByAsic[asicID].push_back(&wireHit);
123 for (
auto& asicList : groupedByAsic) {
133 moduleParamList->
addParameter(prefixed(prefix,
"minimalHitNumberASIC"),
135 "Required number of hits per ASIC for library creation",
138 moduleParamList->
addParameter(prefixed(prefix,
"AsicLibraryFileName"),
140 "ASIC library file name",
143 moduleParamList->
addParameter(prefixed(prefix,
"maximalDistanceSignal"),
145 "maximal distance in cm from track to signal hit",
148 moduleParamList->
addParameter(prefixed(prefix,
"minimalDistanceBackground"),
150 "minimal distance in cm from track to background hit",
153 moduleParamList->
addParameter(prefixed(prefix,
"useAxialHitsOnly"),
155 "use axial layers only",
158 moduleParamList->
addParameter(prefixed(prefix,
"writeExtraVars"),
160 "Write extra variables to the library",
163 moduleParamList->
addParameter(prefixed(prefix,
"minimalHitsOnTrack"),
165 "Required number of hits on track for library creation",
169 moduleParamList->
getParameter<std::string>(
"inputTracks").setDefaultValue(
"CDCTrackVector");
170 moduleParamList->
getParameter<std::string>(
"inputWireHits").setDefaultValue(
"CDCWireHitVector");
186 if (wireHits.size() > 8) {
187 B2ERROR(
"Number of hits per asic should not exceed 8, observe too many hits." <<
LogVar(
"nHits", wireHits.size()));
196 for (
auto& hit : wireHits) {
197 if (!(*hit)->hasBackgroundFlag() && (*hit)->hasTakenFlag()) {
216 const CDCTrack* signalTrack =
nullptr;
217 for (
auto& track : tracks) {
218 for (
auto& hit : track) {
219 if (&hit.getWireHit() == signal) {
220 signalTrack = &track;
224 if (signalTrack !=
nullptr) {
229 if (signalTrack ==
nullptr) {
230 B2DEBUG(29,
"AsicBackgroundLibraryCreator::No track found for the signal hit");
239 const auto& trajectory = signalTrack->getStartTrajectory3D();
243 for (
auto& hit : wireHits) {
245 const float dist = getDist2D(trajectory, hit);
272 for (
auto& hit : wireHits) {
273 auto eWire = hit->getWireID().getEWire();
274 auto channel =
m_map[eWire].second;
275 auto asicCH = channel % 8;
276 m_asic_info[asicCH].ADC = hit->getHit()->getADCCount();
277 m_asic_info[asicCH].TDC = hit->getHit()->getTDCCount();
285 auto eWire = signal->getWireID().getEWire();
288 m_adc_sig = signal->getHit()->getADCCount();
Class representing a sense wire in the central drift chamber.
ROOT::Math::XYVector getWirePos2DAtZ(const double z) const
Gives the xy projected position of the wire at the given z coordinate.
The Module parameter list class.
double m_distance_signal_max
maximal distance from track to signal hit
Short_t m_adc_sig
ADC of the signal.
std::unique_ptr< DBArray< CDCChannelMap > > m_channelMapFromDB
Channel map retrieved from DB.
asicChannel m_asic_info[8]
all 8 channels
UShort_t m_n_hit_track
Number of hits on the track.
void selectAsic(const std::vector< const TrackingUtilities::CDCWireHit * > &wireHits, const std::vector< TrackingUtilities::CDCTrack > &tracks)
Algorithm to select suitable ASIC for library creation.
void initialize() final
Access database here, open library for writing:
void beginRun() final
Reload channel map if needed.
bool m_use_axial_hits_only
use axial layers only
size_t m_minimal_hits_on_track
min. number of hits on the track
float m_dist_bg
min. distance to non-linked hits
UChar_t m_board
signal boardID
float m_dist_signal
Distance to signal hit.
void apply(const std::vector< TrackingUtilities::CDCWireHit > &wireHits, const std::vector< TrackingUtilities::CDCTrack > &tracks) final
Main algorithm marking hit as background.
std::string m_library_name
output library name
std::map< int, std::pair< int, int > > m_map
map from ewire to board/channel ID
std::string getDescription() final
Short description of the findlet.
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) final
Expose the parameters to a module.
UChar_t m_n_hit
For debugging, store also number of channels with hits.
UChar_t m_channel
signal channelID
bool m_write_extra_vars
extra vars to the library
double m_distance_background_min
minimal distance from track to background hit
size_t m_minimal_hit_number
min. number of hits in ASIC for background check
std::unique_ptr< TrackingUtilities::Recorder > m_recorder
Recorder for the root output.
Short_t m_adc_max_bg
Max. ADC background.
void terminate() final
write out the library
Class representing a sequence of three dimensional reconstructed hits.
Particle trajectory as it is seen in xy projection represented as a circle.
double calcArcLength2D(const Vector2D &point) const
Calculate the travel distance from the start position of the trajectory.
Vector2D getClosest(const Vector2D &point) const
Calculates the closest approach on the trajectory to the given point.
double getDist2D(const Vector2D &point) const
Calculates the distance from the point to the trajectory as seen from the xy projection.
Particle full three dimensional trajectory.
CDCTrajectory2D getTrajectory2D() const
Getter for the two dimensional trajectory.
CDCTrajectorySZ getTrajectorySZ() const
Getter for the sz trajectory.
Linear trajectory in sz space.
double mapSToZ(const double s=0) const
Translates the travel distance to the z coordinate.
Class representing a hit wire in the central drift chamber.
const WireID & getWireID() const
Getter for the WireID of the wire the hit is located on.
void initialize() override
void terminate() override
virtual void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix)
Class to fill a tree from a set of variables.
A two dimensional vector which is equipped with functions for correct handling of orientation relate...
double normalizeTo(const double toLength)
Normalizes the vector to the given length.
Class to identify a wire inside the CDC.
unsigned short getEWire() const
Getter for encoded wire number.
Class to store variables with their name which were sent to the logging service.
ModuleParam< T > & getParameter(const std::string &name) const
Returns a reference to a parameter.
void addParameter(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module list.
Abstract base class for different kinds of events.