38 if(mcpList.empty())
return;
40 if(mcpListIndex.size() != (*
evt.
allHits).size())
return;
92 for(
auto& tj : slc.tjs) {
93 if(tj.AlgMod[
kKilled])
continue;
94 if(tj.mcpListIndex != 0)
continue;
95 auto& mcp = mcpList[tj.mcpListIndex];
96 int pdg = abs(mcp->PdgCode());
97 short TMeV = 1000 * (mcpList[0]->E() - mcpList[0]->Mass());
101 myprt<<
"ntp "<<pdg<<
" "<<TMeV;
102 myprt<<
" "<<tj.MCSMom;
103 myprt<<
" "<<tj.PDGCode;
104 myprt<<
" "<<std::fixed<<std::setprecision(1);
106 myprt<<
" "<<std::fixed<<std::setprecision(2);
108 myprt<<
" "<<std::setprecision(3)<<tj.ChgRMS;
110 myprt<<
" "<<tj.EffPur;
127 unsigned int tpc = tpcid.TPC;
128 unsigned int cstat = tpcid.Cryostat;
131 std::vector<std::vector<unsigned int>> mcpHits(mcpList.size());
132 bool hitsInTPC =
false;
133 for(
unsigned int iht = 0; iht < (*
evt.
allHits).size(); ++iht) {
134 if(mcpListIndex[iht] > mcpList.size() - 1)
continue;
136 if(
hit.WireID().Cryostat != cstat)
continue;
137 if(
hit.WireID().TPC != tpc)
continue;
138 mcpHits[mcpListIndex[iht]].push_back(iht);
143 if(!hitsInTPC)
continue;
145 std::vector<std::pair<unsigned short, unsigned short>> tjLocs;
147 std::vector<std::vector<unsigned int>> tjHits;
149 std::vector<std::pair<unsigned short, unsigned short>> pfpLocs;
150 std::vector<std::vector<unsigned int>> pfpHits;
151 for(
unsigned short isl = 0; isl <
slices.size(); ++isl) {
153 for(
auto& tj : slc.tjs) {
154 if(tj.AlgMod[
kKilled])
continue;
156 tj.mcpListIndex = UINT_MAX;
158 tjLocs.push_back(std::make_pair(isl, (
unsigned short)(tj.ID-1)));
161 for(
auto& pfp : slc.pfps) {
162 if(pfp.ID <= 0)
continue;
163 if(pfp.TPCID != tpcid)
continue;
165 if(pfp.PDGCode == 14 || pfp.PDGCode == 12)
continue;
166 pfp.mcpListIndex = UINT_MAX;
168 pfpLocs.push_back(std::make_pair(isl, (
unsigned short)(pfp.ID-1)));
169 std::vector<unsigned int>
tmp;
170 for(
auto tjid : pfp.TjIDs) {
171 auto& tj = slc.tjs[tjid - 1];
173 tmp.insert(tmp.end(), thits.begin(), thits.end());
175 pfpHits.push_back(tmp);
180 for(
unsigned int imcp = 0; imcp < mcpList.size(); ++imcp) {
181 if(mcpHits[imcp].empty())
continue;
184 auto& mcp = mcpList[imcp];
186 if(pdgIndex > 4)
continue;
187 std::string particleName =
"Other";
188 int pdg = abs(mcp->PdgCode());
189 if(pdg == 11) particleName =
"Electron";
190 if(pdg == 22) particleName =
"Photon";
191 if(pdg == 13) particleName =
"Muon";
192 if(pdg == 211) particleName =
"Pion";
193 if(pdg == 321) particleName =
"Kaon";
194 if(pdg == 2212) particleName =
"Proton";
195 if(particleName ==
"Other") particleName =
"PDG_" +
std::to_string(pdg);
196 float TMeV = 1000 * (mcp->E() - mcp->Mass());
199 for(
unsigned short plane = 0; plane < nplanes; ++plane) {
201 std::vector<unsigned int> mcpPlnHits;
202 for(
auto iht : mcpHits[imcp]) {
204 if(
hit.WireID().Plane == plane) mcpPlnHits.push_back(iht);
207 if(mcpPlnHits.size() < 2)
continue;
209 TSums[pdgIndex] += TMeV;
212 unsigned short mtjLoc = USHRT_MAX;
214 for(
unsigned short iit = 0; iit < tjLocs.size(); ++iit) {
216 if(tjHits[iit].empty())
continue;
219 if(shared.empty())
continue;
220 float eff = (float)shared.size() / (float)mcpPlnHits.size();
221 float pur = (float)shared.size() / (float)tjHits[iit].size();
222 float ep = eff * pur;
228 if(mtjLoc == USHRT_MAX) {
232 myprt<<particleName<<
" BadEP TMeV "<<(int)TMeV<<
" No matched trajectory to imcp "<<imcp;
233 myprt<<
" nTrue hits "<<mcpPlnHits.size();
239 auto& tj =
slices[tjLocs[mtjLoc].first].tjs[tjLocs[mtjLoc].second];
240 if(maxEP > tj.EffPur) {
242 tj.mcpListIndex = imcp;
243 EPTSums[pdgIndex] += TMeV * tj.EffPur;
249 myprt<<particleName<<
" BadEP: "<<std::fixed<<std::setprecision(2)<<tj.EffPur;
250 myprt<<
" imcp "<<imcp;
251 myprt<<
" TMeV "<<(int)TMeV<<
" MCP hits "<<mcpPlnHits.size();
261 bool longMCP = (pdgIndex > 0 && pdgIndex < 5 && (float)mcpHits[imcp].size() >= 2 *
tcc.
matchTruth[3]);
263 unsigned short mpfpLoc = USHRT_MAX;
264 for(
unsigned short iit = 0; iit < pfpLocs.size(); ++iit) {
266 if(pfpHits[iit].empty())
continue;
269 if(shared.empty())
continue;
270 float eff = (float)shared.size() / (float)mcpHits[imcp].size();
271 float pur = (float)shared.size() / (float)pfpHits[iit].size();
272 float ep = eff * pur;
278 if(mpfpLoc == USHRT_MAX) {
282 myprt<<
"BadPFP: MCParticle "<<imcp<<
" w PDGCode "<<mcp->PdgCode()<<
" T "<<(int)TMeV<<
" not reconstructed.";
287 auto& pfp =
slices[pfpLocs[mpfpLoc].first].pfps[pfpLocs[mpfpLoc].second];
288 if(maxEP > pfp.EffPur) {
290 pfp.mcpListIndex = imcp;
300 short TMeV = 1000 * (mcpList[0]->E() - mcpList[0]->Mass());
301 std::cout<<
"Study3: Find Tjs matched to primary w PDGCode "<<mcpList[0]->PdgCode()<<
". T = "<<TMeV<<
"\n";
302 std::array<bool, 3> inPln {{
false}};
304 for(
auto& tj : slc.tjs) {
305 if(tj.AlgMod[
kKilled])
continue;
306 if(tj.mcpListIndex != 0)
continue;
309 std::cout<<
"T"<<tj.UID<<
" start ";
310 auto& tp = tj.Pts[tj.EndPt[0]];
312 std::cout<<
" PDGCode "<<tj.PDGCode;
313 std::cout<<
" len "<<tj.EndPt[1] - tj.EndPt[0] + 1;
314 std::cout<<
" MCSMom "<<tj.MCSMom;
315 std::cout<<
" ChgRMS "<<std::fixed<<std::setprecision(2)<<tj.ChgRMS;
316 std::cout<<
" BraggPeak? "<<tj.StopFlag[1][
kBragg];
349 if(!slc.pfps.empty()) {
350 auto& pfp = slc.pfps[0];
351 std::cout<<
"P"<<pfp.UID<<
" PDGCode "<<pfp.PDGCode<<
" dtrs";
352 for(
auto dtruid : pfp.DtrUIDs) std::cout<<
" P"<<dtruid;
356 for(
unsigned short plane = 0; plane < 3; ++plane)
if(!inPln[plane]) std::cout<<
"No match in plane "<<plane<<
"\n";
369 myprt<<
"Evt "<<eventNum;
372 for(
unsigned short pdgIndex = 0; pdgIndex <
TSums.size(); ++pdgIndex) {
373 if(
TSums[pdgIndex] == 0)
continue;
374 if(pdgIndex == 0) myprt<<
" El";
375 if(pdgIndex == 1) myprt<<
" Mu";
376 if(pdgIndex == 2) myprt<<
" Pi";
377 if(pdgIndex == 3) myprt<<
" K";
378 if(pdgIndex == 4) myprt<<
" P";
380 myprt<<
" "<<std::fixed<<std::setprecision(2)<<ave;
383 sum +=
TSums[pdgIndex];
387 if(sum > 0) myprt<<
" MuPiKP "<<std::fixed<<std::setprecision(2)<<sumt / sum;
390 float longGood = 1 - (float)nBadEP / (
float)
nLongInPln;
391 myprt<<
" longGood "<<std::fixed<<std::setprecision(2)<<longGood;
396 myprt<<
" MCP cnt "<<(int)
MCP_Cnt<<
" PFP "<<std::fixed<<std::setprecision(2)<<ep;
400 myprt<<
" PrimPFP "<<std::fixed<<std::setprecision(2)<<ep;
404 myprt<<
" longGood "<<std::fixed<<std::setprecision(2)<<longGood;
409 myprt<<
" NuVx correct "<<std::fixed<<std::setprecision(2)<<frac;
419 if(mcpHits.empty())
return false;
420 if(nDimensions < 2 || nDimensions > 3)
return false;
421 unsigned short tpc = inTPCID.
TPC;
422 unsigned short cstat = inTPCID.
Cryostat;
424 std::vector<unsigned short> cntInPln(nplanes);
425 for(
auto iht : mcpHits) {
428 if(
hit.WireID().TPC != tpc)
continue;
429 if(
hit.WireID().Cryostat != cstat)
continue;
430 ++cntInPln[
hit.WireID().Plane];
432 unsigned short nPlnOK = 0;
434 for(
unsigned short plane = 0; plane < nplanes; ++plane) if(cntInPln[plane] > 1) ++nPlnOK;
435 return (nPlnOK >= 2);
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
unsigned short nLongInPln
const std::vector< std::string > AlgBitNames
std::vector< unsigned int > PutTrajHitsInVector(Trajectory const &tj, HitStatus_t hitRequest)
call study functions to develop cuts, etc
CryostatID_t Cryostat
Index of cryostat.
float TrajPointSeparation(TrajPoint &tp1, TrajPoint &tp2)
std::vector< float > matchTruth
Match to MC truth.
unsigned int eventsProcessed
IteratorBox< TPC_id_iterator,&GeometryCore::begin_TPC_id,&GeometryCore::end_TPC_id > IterateTPCIDs() const
Enables ranged-for loops on all TPC IDs of the detector.
std::vector< T > SetIntersection(const std::vector< T > &set1, const std::vector< T > &set2)
void MatchAndSum(std::vector< simb::MCParticle * > const &mcpList, std::vector< unsigned int > const &mcpListIndex)
bool CanReconstruct(std::vector< unsigned int > mcpHits, unsigned short nDimensions, const geo::TPCID &inTPCID)
unsigned int Nplanes(unsigned int tpc=0, unsigned int cstat=0) const
Returns the total number of wire planes in the specified TPC.
void MatchTruth(std::vector< simb::MCParticle * > const &mcpList, std::vector< unsigned int > const &mcpListIndex)
std::array< float, 5 > TSums
std::array< float, 5 > EPTSums
std::array< short, 5 > EPCnts
const geo::GeometryCore * geom
The data type to uniquely identify a TPC.
PlaneID_t Plane
Index of the plane within its TPC.
unsigned short nGoodLongMCP
std::vector< TCSlice > slices
Detector simulation of raw signals on wires.
std::bitset< 16 > modes
number of points to find AveChg
float ElectronLikelihood(TCSlice &slc, Trajectory &tj, float &asym)
std::string to_string(Flag_t< Storage > const flag)
Convert a flag into a stream (shows its index).
call study functions to develop cuts, etc
geo::PlaneID DecodeCTP(CTP_t CTP)
unsigned short PDGCodeIndex(int PDGCode)
std::vector< recob::Hit > const * allHits
std::string PrintPos(TCSlice &slc, const TrajPoint &tp)
TPCID_t TPC
Index of the TPC within its cryostat.
void PrintResults(int eventNum) const
std::array< unsigned short, 3 > TruVxCounts