9 #include <ecl/modules/eclTrackClusterMatching/ECLTrackClusterMatchingParametrizationExpertModule.h>
10 #include <framework/datastore/RelationVector.h>
11 #include <framework/gearbox/Const.h>
20 REG_MODULE(ECLTrackClusterMatchingParametrizationExpert)
43 setDescription(
"Store ExtHit related infos for track cluster matching");
44 setPropertyFlags(c_ParallelProcessingCertified);
45 addParam(
"writeToRoot", m_writeToRoot,
46 "set true if you want to save the information in a root file named by parameter 'rootFileName'",
bool(
false));
47 addParam(
"useArray", m_useArray,
48 "set true if you want to save the information event-wise using an array structure",
bool(
false));
49 addParam(
"rootFileName", m_rootFileName,
50 "fileName used for root file where info are saved. Will be ignored if parameter 'writeToRoot' is false (standard)",
51 string(
"eclTrackClusterMatchingAnalysis.root"));
54 ECLTrackClusterMatchingParametrizationExpertModule::~ECLTrackClusterMatchingParametrizationExpertModule()
58 void ECLTrackClusterMatchingParametrizationExpertModule::initialize()
61 m_tracks.isRequired();
62 m_eclClusters.isRequired();
63 m_tracks.registerRelationTo(m_eclClusters);
64 m_extHits.isRequired();
65 m_trackFitResults.isRequired();
66 m_mcParticles.isRequired();
68 m_eventMetaData.isOptional();
70 m_rootFilePtr =
new TFile(m_rootFileName.c_str(),
"RECREATE");
71 m_tree =
new TTree(
"tree",
"ECL Track Cluster Matching Analysis tree");
73 m_tree->Branch(
"expNo", &m_iExperiment,
"expNo/I");
74 m_tree->Branch(
"runNo", &m_iRun,
"runNo/I");
75 m_tree->Branch(
"evtNo", &m_iEvent,
"evtNo/I");
78 m_tree->Branch(
"trackNo",
"std::vector<int>", &m_trackNo_array);
79 m_tree->Branch(
"trackMomentum",
"std::vector<float>", &m_trackMomentum_array);
80 m_tree->Branch(
"pT",
"std::vector<float>", &m_pT_array);
81 m_tree->Branch(
"trackTheta",
"std::vector<float>", &m_trackTheta_array);
82 m_tree->Branch(
"deltaPhi",
"std::vector<float>", &m_deltaPhi_array);
83 m_tree->Branch(
"phiCluster",
"std::vector<float>", &m_phiCluster_array);
84 m_tree->Branch(
"phiHit",
"std::vector<float>", &m_phiHit_array);
85 m_tree->Branch(
"errorPhi",
"std::vector<float>", &m_errorPhi_array);
86 m_tree->Branch(
"deltaTheta",
"std::vector<float>", &m_deltaTheta_array);
87 m_tree->Branch(
"thetaCluster",
"std::vector<float>", &m_thetaCluster_array);
88 m_tree->Branch(
"thetaHit",
"std::vector<float>", &m_thetaHit_array);
89 m_tree->Branch(
"errorTheta",
"std::vector<float>", &m_errorTheta_array);
90 m_tree->Branch(
"hitStatus",
"std::vector<int>", &m_hitstatus_array);
91 m_tree->Branch(
"trueTrackPDG",
"std::vector<int>", &m_true_track_pdg_array);
92 m_tree->Branch(
"trueMatch",
"std::vector<int>", &m_true_match_array);
94 m_tree->Branch(
"trackNo", &m_trackNo,
"trackNo/I");
95 m_tree->Branch(
"trackMomentum", &m_trackMomentum,
"trackMomentum/F");
96 m_tree->Branch(
"pT", &m_pT,
"pT/F");
97 m_tree->Branch(
"trackTheta", &m_trackTheta,
"trackTheta/F");
98 m_tree->Branch(
"deltaPhi", &m_deltaPhi,
"deltaPhi/F");
99 m_tree->Branch(
"phiCluster", &m_phiCluster,
"phiCluster/F");
100 m_tree->Branch(
"phiHit", &m_phiHit,
"phiHit/F");
101 m_tree->Branch(
"errorPhi", &m_errorPhi,
"errorPhi/F");
102 m_tree->Branch(
"deltaTheta", &m_deltaTheta,
"deltaTheta/F");
103 m_tree->Branch(
"thetaCluster", &m_thetaCluster,
"thetaCluster/F");
104 m_tree->Branch(
"thetaHit", &m_thetaHit,
"thetaHit/F");
105 m_tree->Branch(
"errorTheta", &m_errorTheta,
"errorTheta/F");
106 m_tree->Branch(
"hitStatus", &m_hitstatus,
"hitStatus/I");
107 m_tree->Branch(
"trueTrackPDG", &m_true_track_pdg,
"trueTrackPDG/I");
108 m_tree->Branch(
"trueMatch", &m_true_match,
"trueMatch/I");
112 void ECLTrackClusterMatchingParametrizationExpertModule::event()
115 m_deltaPhi_array->clear();
116 m_phiCluster_array->clear();
117 m_phiHit_array->clear();
118 m_errorPhi_array->clear();
119 m_deltaTheta_array->clear();
120 m_thetaCluster_array->clear();
121 m_thetaHit_array->clear();
122 m_errorTheta_array->clear();
123 m_trackNo_array->clear();
124 m_trackMomentum_array->clear();
126 m_trackTheta_array->clear();
127 m_hitstatus_array->clear();
128 m_true_track_pdg_array->clear();
129 m_true_match_array->clear();
132 if (m_eventMetaData) {
133 m_iExperiment = m_eventMetaData->getExperiment();
134 m_iRun = m_eventMetaData->getRun();
135 m_iEvent = m_eventMetaData->getEvent();
144 for (
const Track& track : m_tracks) {
147 if (!relatedMCParticle)
continue;
148 int pdgCode = relatedMCParticle->
getPDG();
150 if (Const::chargedStableSet.find(abs(pdgCode)) != Const::invalidParticle) {
153 const TrackFitResult* fitResult = track.getTrackFitResultWithClosestMass(hypothesis);
157 double theta = TMath::ACos(fitResult->
getMomentum().CosTheta());
159 m_true_track_pdg_array->push_back(pdgCode);
160 m_trackNo_array->push_back(i);
161 m_trackMomentum_array->push_back(momentum);
162 m_pT_array->push_back(pt);
163 m_trackTheta_array->push_back(theta);
165 m_true_track_pdg = pdgCode;
167 m_trackMomentum = momentum;
169 m_trackTheta = theta;
175 for (
const auto& extHit : track.getRelationsTo<
ExtHit>()) {
176 if (!isECLHit(extHit))
continue;
178 if (eclCluster !=
nullptr) {
180 if (!eclCluster->
hasHypothesis(ECLCluster::EHypothesisBit::c_nPhotons))
continue;
181 double errorPhi = extHit.getErrorPhi();
182 double errorTheta = extHit.getErrorTheta();
183 double phiHit = extHit.getPosition().Phi();
184 double phiCluster = eclCluster->
getPhi();
185 double deltaPhi = phiHit - phiCluster;
186 if (deltaPhi > M_PI) {
187 deltaPhi = deltaPhi - 2 * M_PI;
188 }
else if (deltaPhi < -M_PI) {
189 deltaPhi = deltaPhi + 2 * M_PI;
191 double thetaHit = extHit.getPosition().Theta();
192 double thetaCluster = eclCluster->
getTheta();
193 double deltaTheta = thetaHit - thetaCluster;
196 bool found_match =
false;
197 for (
unsigned int index = 0; index < relatedMCParticles.size() && !found_match; ++index) {
198 const MCParticle* clusterRelatedMCParticle = relatedMCParticles.object(index);
199 if (clusterRelatedMCParticle == relatedMCParticle) {
204 m_errorPhi_array->push_back(errorPhi);
205 m_errorTheta_array->push_back(errorTheta);
206 m_deltaPhi_array->push_back(deltaPhi);
207 m_phiCluster_array->push_back(phiCluster);
208 m_phiHit_array->push_back(phiHit);
209 m_deltaTheta_array->push_back(deltaTheta);
210 m_thetaCluster_array->push_back(thetaCluster);
211 m_thetaHit_array->push_back(thetaHit);
212 m_hitstatus_array->push_back(hitStatus);
213 m_true_match_array->push_back(
int(found_match));
215 m_errorPhi = errorPhi;
216 m_errorTheta = errorTheta;
217 m_deltaPhi = deltaPhi;
218 m_phiCluster = phiCluster;
220 m_deltaTheta = deltaTheta;
221 m_thetaCluster = thetaCluster;
222 m_thetaHit = thetaHit;
223 m_hitstatus = hitStatus;
224 m_true_match = int(found_match);
230 if (m_useArray) m_tree->Fill();
233 void ECLTrackClusterMatchingParametrizationExpertModule::terminate()
235 if (m_rootFilePtr !=
nullptr) {
239 m_rootFilePtr->Close();
240 delete m_rootFilePtr;
244 bool ECLTrackClusterMatchingParametrizationExpertModule::isECLHit(
const ExtHit& extHit)
const
246 if ((extHit.
getDetectorID() != Const::EDetector::ECL))
return false;
248 if (extHitStatus == EXT_ECLCROSS || extHitStatus == EXT_ECLDL || extHitStatus == EXT_ECLNEAR)
return true;
Provides a type-safe way to pass members of the chargedStableSet set.
bool hasHypothesis(EHypothesisBit bitmask) const
Return if specific hypothesis bit is set.
double getPhi() const
Return Corrected Phi of Shower (radian).
double getTheta() const
Return Corrected Theta of Shower (radian).
The module saves information on ExtHits and related cluster into a file.
Store one Ext hit as a ROOT object.
ExtHitStatus getStatus() const
Get state of extrapolation at this hit.
Const::EDetector getDetectorID() const
Get detector ID of this extrapolation hit.
A Class to store the Monte Carlo particle information.
int getPDG() const
Return PDG code of particle.
RelationVector< TO > getRelationsTo(const std::string &name="", const std::string &namedRelation="") const
Get the relations that point from this object to another store array.
FROM * getRelatedFrom(const std::string &name="", const std::string &namedRelation="") const
Get the object from which this object has a relation.
Values of the result of a track fit with a given particle hypothesis.
TVector3 getMomentum() const
Getter for vector of momentum at closest approach of track in r/phi projection.
double getTransverseMomentum() const
Getter for the absolute value of the transverse momentum at the perigee.
Class that bundles various TrackFitResults.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
ExtHitStatus
Define state of extrapolation for each recorded hit.
Abstract base class for different kinds of events.