9 #include <framework/gearbox/Const.h>
10 #include <reconstruction/modules/HitLevelInfoWriter/HitLevelInfoWriter.h>
11 #include <reconstruction/dataobjects/DedxConstants.h>
12 #include <mdst/dataobjects/PIDLikelihood.h>
22 setDescription(
"Extract dE/dx information for calibration development.");
24 addParam(
"outputBaseName", m_strOutputBaseName,
"Suffix for output file name", std::string(
"HLInfo.root"));
25 addParam(
"particleLists", m_strParticleList,
"Vector of ParticleLists to save", std::vector<std::string>());
26 addParam(
"enableHitLevel", enableHitLevel,
"True or False for Hit level variables",
false);
27 addParam(
"enableExtraVar", enableExtraVar,
"True or False for extra track/hit level variables",
false);
28 addParam(
"nodeadwire", nodeadwire,
"True or False for deadwire hit variables",
true);
37 B2INFO(
"Creating a ROOT file for the hit level information...");
40 m_dedxTracks.isRequired();
41 m_tracks.isRequired();
42 m_trackFitResults.isRequired();
43 m_eclClusters.isOptional();
44 m_klmClusters.isOptional();
47 std::map<std::string, std::string> pdgMap = {{
"pi+",
"Const::pion.getPDGCode()"}, {
"K+",
"Const::kaon.getPDGCode()"}, {
"mu+",
"Const::muon.getPDGCode()"}, {
"e+",
"Const::electron.getPDGCode()"}, {
"p+",
"Const::proton.getPDGCode()"}, {
"deuteron",
"Const::deuteron.getPDGCode()"}};
50 if (m_strParticleList.size() == 0) bookOutput(m_strOutputBaseName);
53 for (
unsigned int i = 0; i < m_strParticleList.size(); i++) {
55 std::string pdg = pdgMap[m_strParticleList[i].substr(0, m_strParticleList[i].find(
":"))];
56 std::string filename = std::string(m_strOutputBaseName +
"_PID" + pdg +
".root");
64 int nParticleList = m_strParticleList.size();
70 if (nParticleList == 0) {
71 for (
int idedx = 0; idedx < m_dedxTracks.getEntries(); idedx++) {
75 B2WARNING(
"No dedx related track...");
81 B2WARNING(
"No related track...");
87 B2WARNING(
"No related fit for this track...");
91 if (dedxTrack->
size() == 0 || dedxTrack->
size() > 200)
continue;
96 m_expID = evtMetaData->getExperiment();
97 m_runID = evtMetaData->getRun();
98 m_eventID = evtMetaData->getEvent();
109 if (klmCluster) m_klmLayers = klmCluster->
getLayers();
113 fillTrack(fitResult);
129 for (
int iList = 0; iList < nParticleList; iList++) {
132 if (!particlelist or particlelist->getListSize(
true) == 0) {
139 for (
unsigned int iPart = 0; iPart < particlelist->getListSize(
true); iPart++) {
140 Particle* part = particlelist->getParticle(iPart,
true);
142 B2WARNING(
"No particles...");
147 B2WARNING(
"No related PID likelihood...");
152 B2WARNING(
"No related track...");
157 B2WARNING(
"No related CDCDedxTrack...");
160 std::string ptype = m_strParticleList[iList].substr(0, m_strParticleList[iList].find(
":"));
162 if (ptype !=
"pi+") {
163 if (ptype ==
"K+") fitResult = track->getTrackFitResultWithClosestMass(
Const::kaon);
164 else if (ptype ==
"p+") fitResult = track->getTrackFitResultWithClosestMass(
Const::proton);
165 else if (ptype ==
"deuteron") fitResult = track->getTrackFitResultWithClosestMass(
Const::deuteron);
166 else if (ptype ==
"mu+") fitResult = track->getTrackFitResultWithClosestMass(
Const::muon);
167 else if (ptype ==
"e+") fitResult = track->getTrackFitResultWithClosestMass(
Const::electron);
170 B2WARNING(
"No related fit for this track...");
174 if (dedxTrack->
size() == 0 || dedxTrack->
size() > 200)
continue;
176 if (dedxTrack->
getCosTheta() < TMath::Cos(150.0 * TMath::DegToRad()))
continue;
177 if (dedxTrack->
getCosTheta() > TMath::Cos(17.0 * TMath::DegToRad()))
continue;
181 m_expID = evtMetaData->getExperiment();
182 m_runID = evtMetaData->getRun();
183 m_eventID = evtMetaData->getEvent();
192 if (klmCluster) m_klmLayers = klmCluster->
getLayers();
196 fillTrack(fitResult);
202 m_tree[iList]->Fill();
210 for (
unsigned int i = 0; i < m_file.size(); i++) {
211 B2INFO(
"Done writing out the hit level information...\t" << m_tree[i]->GetEntries() <<
" tracks");
224 m_p = trackMom.Mag();
225 m_pt = trackMom.Pt();
226 m_phi = trackMom.Phi();
228 m_theta = trackMom.Theta() * 180. / TMath::Pi();
229 if (m_theta > 17. && m_theta < 150.)m_inCDC = 1;
238 m_vx0 = trackPos.x();
239 m_vy0 = trackPos.y();
240 m_vz0 = trackPos.z();
242 m_d0 = fitResult->
getD0();
243 m_z0 = fitResult->
getZ0();
253 m_dr = frame.getVertex(helix.getPerigee()).Perp();
254 m_dphi = frame.getVertex(helix.getPerigee()).Phi();
255 m_dz = frame.getVertex(helix.getPerigee()).Z();
264 m_trackID = dedxTrack->
trackID();
268 m_PDG = dedxTrack->
getPDG();
275 h_nhits = dedxTrack->
size();
280 m_trunc = dedxTrack->
getDedx();
285 m_scale = m_DBScaleFactor->getScaleFactor();
286 m_runGain = m_DBRunGain->getRunGain();
287 m_cosCor = m_DBCosineCor->getMean(m_cosTheta);
289 if (m_cosTheta <= -0.850 || m_cosTheta >= 0.950) {
290 m_cosEdgeCor = m_DBCosEdgeCor->getMean(m_cosTheta);
296 m_chie = dedxTrack->
getChi(0);
297 m_chimu = dedxTrack->
getChi(1);
298 m_chipi = dedxTrack->
getChi(2);
299 m_chik = dedxTrack->
getChi(3);
300 m_chip = dedxTrack->
getChi(4);
301 m_chid = dedxTrack->
getChi(5);
318 double lout = 0, lin = 0, increment = 0;
320 for (
int il = 0; il < l_nhits; ++il) {
323 l_layer[il] = dedxTrack->
getLayer(il);
327 if (l_layer[il] > lastlayer) lout++;
328 else if (l_layer[il] < lastlayer) lin++;
331 lastlayer = l_layer[il];
334 m_ioasym = (lout - lin) / increment;
337 if (enableHitLevel) {
338 for (
int ihit = 0; ihit < h_nhits; ++ihit) {
340 if (nodeadwire && m_DBWireGains->getWireGain(h_wire[ihit]) == 0)
continue;
342 h_wire[ihit] = dedxTrack->
getWire(ihit);
344 h_path[ihit] = dedxTrack->
getPath(ihit);
345 h_dedx[ihit] = dedxTrack->
getDedx(ihit);
348 h_doca[ihit] = dedxTrack->
getDoca(ihit);
351 h_enta[ihit] = dedxTrack->
getEnta(ihit);
352 h_entaRS[ihit] = dedxTrack->
getEntaRS(ihit);
353 h_driftT[ihit] = dedxTrack->
getDriftT(ihit);
354 h_driftD[ihit] = dedxTrack->
getDriftD(ihit);
357 if (enableExtraVar) {
365 h_wireGain[ihit] = m_DBWireGains->getWireGain(h_wire[ihit]);
366 h_twodCor[ihit] = m_DB2DCell->getMean(h_layer[ihit], h_ndocaRS[ihit], h_entaRS[ihit]);
367 h_onedCor[ihit] = m_DB1DCell->getMean(h_layer[ihit], h_entaRS[ihit]);
375 for (
int il = 0; il < 200; ++il) {
376 l_nhitscombined[il] = 0;
377 l_wirelongesthit[il] = 0;
383 if (enableHitLevel) {
384 for (
int ihit = 0; ihit < 200; ++ihit) {
399 h_facnladc[ihit] = 0;
400 h_wireGain[ihit] = 0;
403 h_WeightPionHypo[ihit] = 0;
404 h_WeightKaonHypo[ihit] = 0;
405 h_WeightProtonHypo[ihit] = 0;
406 h_foundByTrackFinder[ihit] = 0;
415 m_file.push_back(
new TFile(filename.c_str(),
"RECREATE"));
416 m_tree.push_back(
new TTree(
"track",
"dE/dx information"));
418 int i = m_tree.size() - 1;
419 m_tree[i]->SetDirectory(0);
422 m_tree[i]->Branch(
"exp", &m_expID,
"exp/I");
423 m_tree[i]->Branch(
"run", &m_runID,
"run/I");
424 m_tree[i]->Branch(
"event", &m_eventID,
"event/I");
427 m_tree[i]->Branch(
"d0", &m_d0,
"d0/D");
428 m_tree[i]->Branch(
"z0", &m_z0,
"z0/D");
429 m_tree[i]->Branch(
"dz", &m_dz,
"dz/D");
430 m_tree[i]->Branch(
"dr", &m_dr,
"dr/D");
431 m_tree[i]->Branch(
"dphi", &m_dphi,
"dphi/D");
432 m_tree[i]->Branch(
"vx0", &m_vx0,
"vx0/D");
433 m_tree[i]->Branch(
"vy0", &m_vy0,
"vy0/D");
434 m_tree[i]->Branch(
"vz0", &m_vz0,
"vz0/D");
435 m_tree[i]->Branch(
"tanlambda", &m_tanlambda,
"tanlambda/D");
436 m_tree[i]->Branch(
"phi0", &m_phi0,
"phi0/D");
437 m_tree[i]->Branch(
"chi2", &m_chi2,
"chi2/D");
440 m_tree[i]->Branch(
"nCDChits", &m_nCDChits,
"nCDChits/D");
441 m_tree[i]->Branch(
"inCDC", &m_inCDC,
"inCDC/I");
442 m_tree[i]->Branch(
"track", &m_trackID,
"track/I");
443 m_tree[i]->Branch(
"length", &m_length,
"length/D");
444 m_tree[i]->Branch(
"charge", &m_charge,
"charge/I");
445 m_tree[i]->Branch(
"costh", &m_cosTheta,
"costh/D");
446 m_tree[i]->Branch(
"pF", &m_pCDC,
"pF/D");
447 m_tree[i]->Branch(
"p", &m_p,
"p/D");
448 m_tree[i]->Branch(
"pt", &m_pt,
"pt/D");
449 m_tree[i]->Branch(
"ioasym", &m_ioasym,
"ioasym/D");
450 m_tree[i]->Branch(
"phi", &m_phi,
"phi/D");
451 m_tree[i]->Branch(
"pdg", &m_PDG,
"pdg/D");
453 m_tree[i]->Branch(
"mean", &m_mean,
"mean/D");
454 m_tree[i]->Branch(
"dedx", &m_trunc,
"dedx/D");
455 m_tree[i]->Branch(
"dedxnosat", &m_truncNoSat,
"dedxnosat/D");
456 m_tree[i]->Branch(
"dedxerr", &m_error,
"dedxerr/D");
460 m_tree[i]->Branch(
"eop", &m_eop,
"eop/D");
461 m_tree[i]->Branch(
"e", &m_e,
"e/D");
462 m_tree[i]->Branch(
"e1_9", &m_e1_9,
"e1_9/D");
463 m_tree[i]->Branch(
"e9_21", &m_e9_21,
"e9_21/D");
464 m_tree[i]->Branch(
"klmLayers", &m_klmLayers,
"klmLayers/I");
467 m_tree[i]->Branch(
"scale", &m_scale,
"scale/D");
468 m_tree[i]->Branch(
"coscor", &m_cosCor,
"coscor/D");
469 m_tree[i]->Branch(
"cosedgecor", &m_cosEdgeCor,
"cosedgecor/D");
470 m_tree[i]->Branch(
"rungain", &m_runGain,
"rungain/D");
473 m_tree[i]->Branch(
"chiE", &m_chie,
"chiE/D");
474 m_tree[i]->Branch(
"chiMu", &m_chimu,
"chiMu/D");
475 m_tree[i]->Branch(
"chiPi", &m_chipi,
"chiPi/D");
476 m_tree[i]->Branch(
"chiK", &m_chik,
"chiK/D");
477 m_tree[i]->Branch(
"chiP", &m_chip,
"chiP/D");
478 m_tree[i]->Branch(
"chiD", &m_chid,
"chiD/D");
480 m_tree[i]->Branch(
"pmeanE", &m_pmeane,
"pmeanE/D");
481 m_tree[i]->Branch(
"pmeanMu", &m_pmeanmu,
"pmeanMu/D");
482 m_tree[i]->Branch(
"pmeanPi", &m_pmeanpi,
"pmeanPi/D");
483 m_tree[i]->Branch(
"pmeanK", &m_pmeank,
"pmeanK/D");
484 m_tree[i]->Branch(
"pmeanP", &m_pmeanp,
"pmeanP/D");
485 m_tree[i]->Branch(
"pmeanD", &m_pmeand,
"pmeanD/D");
487 m_tree[i]->Branch(
"presE", &m_prese,
"presE/D");
488 m_tree[i]->Branch(
"presMu", &m_presmu,
"presMu/D");
489 m_tree[i]->Branch(
"presPi", &m_prespi,
"presPi/D");
490 m_tree[i]->Branch(
"presK", &m_presk,
"presK/D");
491 m_tree[i]->Branch(
"presP", &m_presp,
"presP/D");
492 m_tree[i]->Branch(
"presD", &m_presd,
"presD/D");
495 m_tree[i]->Branch(
"lNHits", &l_nhits,
"lNHits/I");
496 m_tree[i]->Branch(
"lNHitsUsed", &l_nhitsused,
"lNHitsUsed/I");
497 m_tree[i]->Branch(
"lNHitsCombined", l_nhitscombined,
"lNHitsCombined[lNHits]/I");
498 m_tree[i]->Branch(
"lWireLongestHit", l_wirelongesthit,
"lWireLongestHit[lNHits]/I");
499 m_tree[i]->Branch(
"lLayer", l_layer,
"lLayer[lNHits]/I");
500 m_tree[i]->Branch(
"lPath", l_path,
"lPath[lNHits]/D");
501 m_tree[i]->Branch(
"lDedx", l_dedx,
"lDedx[lNHits]/D");
504 if (enableHitLevel) {
505 m_tree[i]->Branch(
"hNHits", &h_nhits,
"hNHits/I");
506 m_tree[i]->Branch(
"hLWire", h_lwire,
"hLWire[hNHits]/I");
507 m_tree[i]->Branch(
"hWire", h_wire,
"hWire[hNHits]/I");
508 m_tree[i]->Branch(
"hLayer", h_layer,
"hLayer[hNHits]/I");
509 m_tree[i]->Branch(
"hPath", h_path,
"hPath[hNHits]/D");
510 m_tree[i]->Branch(
"hDedx", h_dedx,
"hDedx[hNHits]/D");
511 m_tree[i]->Branch(
"hADCRaw", h_adcraw,
"hADCRaw[hNHits]/D");
512 m_tree[i]->Branch(
"hADCCorr", h_adccorr,
"hADCCorr[hNHits]/D");
513 m_tree[i]->Branch(
"hDoca", h_doca,
"hDoca[hNHits]/D");
514 m_tree[i]->Branch(
"hNDoca", h_ndoca,
"hNDoca[hNHits]/D");
515 m_tree[i]->Branch(
"hNDocaRS", h_ndocaRS,
"hNDocaRS[hNHits]/D");
516 m_tree[i]->Branch(
"hEnta", h_enta,
"hEnta[hNHits]/D");
517 m_tree[i]->Branch(
"hEntaRS", h_entaRS,
"hEntaRS[hNHits]/D");
518 m_tree[i]->Branch(
"hDriftT", h_driftT,
"hDriftT[hNHits]/D");
519 m_tree[i]->Branch(
"hDriftD", h_driftD,
"hDriftD[hNHits]/D");
520 m_tree[i]->Branch(
"hFacnlADC", h_facnladc,
"hFacnlADC[hNHits]/D");
521 m_tree[i]->Branch(
"hWireGain", h_wireGain,
"hWireGain[hNHits]/D");
522 m_tree[i]->Branch(
"hTwodcor", h_twodCor,
"hTwodcor[hNHits]/D");
523 m_tree[i]->Branch(
"hOnedcor", h_onedCor,
"hOnedcor[hNHits]/D");
525 if (enableExtraVar) {
526 m_tree[i]->Branch(
"hWeightPionHypo", h_WeightPionHypo,
"hWeightPionHypo[hNHits]/D");
527 m_tree[i]->Branch(
"hWeightKaonHypo", h_WeightKaonHypo,
"hWeightKaonHypo[hNHits]/D");
528 m_tree[i]->Branch(
"hWeightProtonHypo", h_WeightProtonHypo,
"hWeightProtonHypo[hNHits]/D");
529 m_tree[i]->Branch(
"hFoundByTrackFinder", h_foundByTrackFinder,
"hFoundByTrackFinder[hNHits]/I");
Debug output for CDCDedxPID module.
int getHitLayer(int i) const
Return the (global) layer number for a hit.
int getADCBaseCount(int i) const
Return the base adcCount (no non-linearity) for this hit.
int getADCCount(int i) const
Return the adcCount for this hit.
double getDedxMean() const
Get the dE/dx mean for this track.
double getDriftD(int i) const
Return the drift distance for this hit.
int getLayer(int i) const
Return the (global) layer number for a layer hit.
double getDoca(int i) const
Return the distance of closest approach to the sense wire for this hit.
double getDedx() const
Get dE/dx truncated mean for this track.
double getPath(int i) const
Return the path length through the cell for this hit.
int getWireInLayer(int i) const
Return the sensor ID for this hit: wire number in the layer.
double getPmean(int i) const
Return the PID (predicted mean) value.
int getWireLongestHit(int i) const
Return the wire number of the longest hit per layer.
double getWeightKaonHypo(int i) const
Return the max weights from KalmanFitterInfo using kaon hypothesis.
double getEntaRS(int i) const
Return rescaled enta value for cell height=width assumption.
double getLayerDedx(int i) const
Return the total dE/dx for this layer.
double getCellHalfWidth(int i) const
Return the half-width of the CDC cell.
double getPDG() const
Get the identity of the particle.
double getPreso(int i) const
Return the PID (predicted reso) value.
int getNLayerHits() const
Return the number of layer hits for this track.
int getFoundByTrackFinder(int i) const
Return the TrackFinder which added the given hit to track.
int getDriftT(int i) const
Return the drift time for this hit.
double getCosTheta() const
Return cos(theta) for this track.
int getCharge() const
Return the charge for this track.
double getWeightPionHypo(int i) const
Return the max weights from KalmanFitterInfo using pion hypothesis.
int getWire(int i) const
Return the sensor ID for this hit: wire number for CDC (0-14336)
double getDocaRS(int i) const
Return rescaled doca value for cell height=width assumption.
double getNonLADCCorrection(int i) const
Return the factor introduce for adcCount (non-linearity) correction.
double getDedxError() const
Get the error on the dE/dx truncated mean for this track.
double getWeightProtonHypo(int i) const
Return the max weights from KalmanFitterInfo using proton hypothesis.
double getEnta(int i) const
Return the entrance angle in the CDC cell for this hit.
double trackID() const
Return the track ID.
double getLayerPath(int i) const
Return the distance travelled in this layer.
double getChi(int i) const
Return the PID (chi) value.
double getLength() const
Return the total path length for this track.
int getNHitsCombined(int i) const
Return the number of hits combined per layer.
double getDedxNoSat() const
Get dE/dx truncated mean without the saturation correction for this track.
int size() const
Return the number of hits for this track.
double getNLayerHitsUsed() const
Return the number of hits used to determine the truncated mean.
double getMomentum() const
Return the track momentum valid in the CDC.
static const ChargedStable muon
muon particle
static const ChargedStable pion
charged pion particle
static const ChargedStable proton
proton particle
static const ChargedStable kaon
charged kaon particle
static const ChargedStable electron
electron particle
static const ChargedStable deuteron
deuteron particle
Class for accessing objects in the database.
bool hasHypothesis(EHypothesisBit bitmask) const
Return if specific hypothesis bit is set.
double getE1oE9() const
Return E1/E9 (shower shape variable).
double getE9oE21() const
Return E9/E21 (shower shape variable).
double getEnergy(EHypothesisBit hypothesis) const
Return Energy (GeV).
@ c_nPhotons
CR is split into n photons (N1)
Extracts dE/dx information for calibration testing.
virtual ~HitLevelInfoWriterModule()
Destructor.
virtual void initialize() override
Initialize the module.
virtual void event() override
This method is called for each event.
virtual void terminate() override
End of the event processing.
void fillTrack(const TrackFitResult *fitResult)
Fill the TTree with the information from the track fit.
void bookOutput(std::string filename)
Create the output TFiles and TTrees.
void clearEntries()
Clear the arrays before filling an event.
void fillDedx(CDCDedxTrack *dedxTrack)
Fill the TTree with the information from a CDCDedxTrack object.
unsigned short getNHits() const
Get the total Number of CDC hits in the fit.
int getLayers() const
Get number of layers with hits.
Class to collect log likelihoods from TOP, ARICH, dEdx, ECL and KLM aimed for output to mdst includes...
Class to store reconstructed particles.
static const ReferenceFrame & GetCurrent()
Get current rest frame.
FROM * getRelatedFrom(const std::string &name="", const std::string &namedRelation="") const
Get the object from which this object has a relation.
T * getRelated(const std::string &name="", const std::string &namedRelation="") const
Get the object to or from which this object has a relation.
Type-safe access to single objects in the data store.
Values of the result of a track fit with a given particle hypothesis.
short getChargeSign() const
Return track charge (1 or -1).
double getPValue() const
Getter for Chi2 Probability of the track fit.
TVector3 getMomentum() const
Getter for vector of momentum at closest approach of track in r/phi projection.
double getD0() const
Getter for d0.
double getTanLambda() const
Getter for tanLambda.
TVector3 getPosition() const
Getter for vector of position at closest approach of track in r/phi projection.
double getZ0() const
Getter for z0.
HitPatternCDC getHitPatternCDC() const
Getter for the hit pattern in the CDC;.
UncertainHelix getUncertainHelix() const
Conversion to framework Uncertain Helix (i.e., with covariance).
double getPhi0() const
Getter for phi0.
Class that bundles various TrackFitResults.
This class represents an ideal helix in perigee parameterization including the covariance matrix of t...
double passiveMoveBy(const TVector3 &by)
Moves origin of the coordinate system (passive transformation) by the given vector.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.