9#include <pxd/modules/pxdDQM/PXDDQMEfficiencyNtupleSelftrackModule.h>
11#include <pxd/dataobjects/PXDCluster.h>
12#include <tracking/dataobjects/ROIid.h>
13#include <mdst/dataobjects/Track.h>
14#include <tracking/dataobjects/RecoTrack.h>
16#include <pxd/reconstruction/PXDPixelMasker.h>
17#include <framework/gearbox/Const.h>
18#include <framework/geometry/VectorUtil.h>
20#include "TMatrixDSym.h"
21#include <Math/Vector3D.h>
46 addParam(
"ROIsName",
m_ROIsName,
"name of the list of HLT ROIs, if available in output", std::string(
""));
48 addParam(
"pCut",
m_pcut,
"Set a cut on the track fit p-value (0=no cut)",
double(0));
49 addParam(
"minSVDHits",
m_minSVDHits,
"Number of SVD hits required in a track to be considered", 0u);
50 addParam(
"momCut",
m_momCut,
"Set a cut on the track momentum in GeV/c, 0 disables",
double(0));
51 addParam(
"pTCut",
m_pTCut,
"Set a cut on the track pT in GeV/c, 0 disables",
double(0));
52 addParam(
"maskedDistance",
m_maskedDistance,
"Distance inside which no masked pixel or sensor border is allowed",
int(10));
58 auto dir = gDirectory;
79 m_file =
new TFile(
"test.root",
"recreate");
81 m_tuple =
new TNtuple(
"effcontrol",
"effcontrol",
82 "vxdid:u:v:p:pt:distu:distv:sigu:sigv:dist:inroi:clborder:cldead:matched:z0:d0:svdhits:charge:phi:costheta");
96 B2INFO(
"PXDClusters array is missing, no efficiencies");
100 B2INFO(
"RecoTrack array is missing, no efficiencies");
104 B2INFO(
"Track array is missing, no efficiencies");
110 if (!recoTrack.
size())
continue;
112 auto a_track = recoTrack[0];
114 if (!a_track->wasFitSuccessful())
continue;
116 if (a_track->getNumberOfSVDHits() <
m_minSVDHits)
continue;
118 const genfit::FitStatus* fitstatus = a_track->getTrackFitStatus();
119 if (fitstatus->getPVal() <
m_pcut)
continue;
121 genfit::MeasuredStateOnPlane trackstate;
122 trackstate = a_track->getMeasuredStateOnPlaneFromFirstHit();
123 if (trackstate.getMom().Mag() <
m_momCut)
continue;
124 if (trackstate.getMom().Pt() <
m_pTCut)
continue;
128 B2ERROR(
"expect a track fit result for mass");
133 std::vector<VxdID> sensors =
m_vxdGeometry.getListOfSensors();
134 for (
VxdID& aVxdID : sensors) {
145 ROOT::Math::XYZVector intersec_buff =
getTrackInterSec(info, *a_track, isgood, sigu, sigv);
151 double u_fit = intersec_buff.X();
152 double v_fit = intersec_buff.Y();
154 int ucell_fit = info.getUCellID(intersec_buff.X());
155 int vcell_fit = info.getVCellID(intersec_buff.Y());
157 bool closeToBoarder =
false;
159 closeToBoarder =
true;
162 bool closeToDead =
false;
167 bool fitInsideROI =
false;
171 for (
auto& roit :
m_ROIs) {
172 if (aVxdID != roit.getSensorID()) {
176 if (ucell_fit < roit.getMaxUid()
177 && ucell_fit > roit.getMinUid()
178 && vcell_fit < roit.getMaxVid()
179 && vcell_fit > roit.getMinVid()) {
192 bool matched =
false;
193 if (bestcluster >= 0) {
198 ROOT::Math::XYZVector dist_clus(u_fit - u_clus, v_fit - v_clus, 0);
199 du_clus = u_fit - u_clus;
200 dv_clus = v_fit - v_clus;
201 d_clus = dist_clus.R();
205 float fill[22] = {float((
int)aVxdID), float(u_fit), float(v_fit), float(trackstate.getMom().Mag()), float(trackstate.getMom().Pt()),
206 float(du_clus), float(dv_clus), float(sigu), float(sigv), float(d_clus),
207 float(fitInsideROI), float(closeToBoarder), float(closeToDead), float(matched),
208 float(ptr2->
getZ0()), float(ptr2->
getD0()), float(a_track->getNumberOfSVDHits()),
209 charge, float(trackstate.getMom().Phi()), float(trackstate.getMom().CosTheta())
221 bool& isgood,
double& du,
double& dv)
226 ROOT::Math::XYZVector intersec(99999999, 9999999, 0);
233 ROOT::Math::XYZVector zeroVec(0, 0, 0);
234 ROOT::Math::XYZVector uVec(1, 0, 0);
235 ROOT::Math::XYZVector vVec(0, 1, 0);
237 genfit::DetPlane* sensorPlane =
new genfit::DetPlane();
243 genfit::SharedPlanePtr sensorPlaneSptr(sensorPlane);
246 gfTrackState.extrapolateToPlane(sensorPlaneSptr);
247 }
catch (genfit::Exception& gfException) {
248 B2WARNING(
"Fitting failed: " << gfException.getExcString());
252 B2WARNING(
"Fitting failed: for some reason");
261 B2DEBUG(1,
"Fitted momentum on the plane p = " << gfTrackState.getMom().Mag());
264 double tolerance = 0.0;
265 bool inside = pxdSensorInfo.
inside(intersec.X(), intersec.Y(), tolerance, tolerance);
268 TMatrixDSym covMatrix = gfTrackState.getCov();
271 du = std::sqrt(covMatrix(3, 3));
272 dv = std::sqrt(covMatrix(4, 4));
274 if (inside) isgood =
true;
284 double mindist = 999999999999;
289 for (
int iclus = 0; iclus <
m_pxdclusters.getEntries(); iclus++) {
302 ROOT::Math::XYZVector current(u, v, 0);
305 double dist = (intersection - current).
R();
306 if (dist < mindist) {
319 if (u - checkDistance < 0 || u + checkDistance >= 250 ||
320 v - checkDistance < 0 || v + checkDistance >= 768) {
330 for (
int u_iter = u - checkDistance; u_iter <= u + checkDistance ; ++u_iter) {
331 for (
int v_iter = v - checkDistance; v_iter <= v + checkDistance ; ++v_iter) {
static const ChargedStable pion
charged pion particle
void setDescription(const std::string &description)
Sets the description of the module.
void initialize() override final
initializes the need store arrays, trees and histograms
bool isCloseToBorder(int u, int v, int checkDistance)
is it close to the border
unsigned int m_minSVDHits
Required hits in SVD strips for tracks.
StoreArray< PXDCluster > m_pxdclusters
store array of pxd clusters
double m_momCut
Cut on fitted track momentum.
int findClosestCluster(const VxdID &vxdid, ROOT::Math::XYZVector intersection)
find the closest cluster
ROOT::Math::XYZVector getTrackInterSec(const VXD::SensorInfoBase &pxdSensorInfo, const RecoTrack &aTrack, bool &isgood, double &du, double &dv)
helper functions to do some of the calculations
bool isDeadPixelClose(int u, int v, int checkDistance, const VxdID &moduleID)
is a dead pixel close
double m_pcut
pValue-Cut for tracks
void terminate() override final
terminate , save tuple to file if needed
void event() override final
main function which fills trees and histograms
std::string m_pxdClustersName
name of the store array of pxd clusters
StoreArray< Track > m_tracks
store array of tracks
std::string m_recoTracksName
name of the store array of recotracks
TFile * m_file
pointer to opened file
int m_maskedDistance
Distance inside which no dead pixel or module border is allowed.
double m_pTCut
Cut on fitted track pT.
std::string m_ROIsName
name of the store array of ROIs
StoreArray< RecoTrack > m_recoTracks
store array of reco tracks
bool m_useAlignment
if true alignment will be used!
VXD::GeoCache & m_vxdGeometry
the geometry
TNtuple * m_tuple
pointer to opened tuple
PXDDQMEfficiencyNtupleSelftrackModule()
Constructor: Sets the description, the properties and the parameters of the module.
std::string m_tracksName
name of the store array of tracks
StoreArray< ROIid > m_ROIs
store array of ROIs
static PXDPixelMasker & getInstance()
Main (and only) way to access the PXDPixelMasker.
This is the Reconstruction Event-Data Model Track.
const genfit::MeasuredStateOnPlane & getMeasuredStateOnPlaneFromFirstHit(const genfit::AbsTrackRep *representation=nullptr) const
Return genfit's MeasuredStateOnPlane for the first hit in a fit useful for extrapolation of measureme...
Class for type safe access to objects that are referred to in relations.
size_t size() const
Get number of relations.
Values of the result of a track fit with a given particle hypothesis.
double getD0() const
Getter for d0.
double getZ0() const
Getter for z0.
Base class to provide Sensor Information for PXD and SVD.
ROOT::Math::XYZVector pointToLocal(const ROOT::Math::XYZVector &global, bool reco=false) const
Convert a point from global to local coordinates.
ROOT::Math::XYZVector pointToGlobal(const ROOT::Math::XYZVector &local, bool reco=false) const
Convert a point from local to global coordinates.
bool inside(double u, double v, double uTolerance=DBL_EPSILON, double vTolerance=DBL_EPSILON) const
Check whether a given point is inside the active area.
ROOT::Math::XYZVector vectorToGlobal(const ROOT::Math::XYZVector &local, bool reco=false) const
Convert a vector from local to global coordinates.
Class to uniquely identify a any structure of the PXD and SVD.
baseType getSensorNumber() const
Get the sensor id.
baseType getLadderNumber() const
Get the ladder id.
baseType getLayerNumber() const
Get the layer id.
static constexpr auto XYZToTVector
Helper function to convert XYZVector to TVector3.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Namespace to provide code needed by both Vertex Detectors, PXD and SVD, and also testbeam telescopes.
Abstract base class for different kinds of events.