22 #include "art_root_io/TFileService.h" 47 return first.
y < second.
y;
54 #define HolderVal 9999 69 void endJob()
override;
70 void endRun(
art::Run const&)
override;
76 void FillVars( std::vector<int> &TrackIDVec,
int &numParts,
float EDep[
MaxPart],
float DaughtEDep[MaxPart],
float DecayEDep[MaxPart],
float Start[MaxPart][4],
float End[MaxPart][4],
77 int nParents[MaxPart],
int Parent[MaxPart][
MaxParent],
int ParTrID[MaxPart][MaxParent],
int PDG[MaxPart],
int TrID[MaxPart],
int Cont[MaxPart],
int FromDecay[MaxPart],
79 bool UnAssignLoop(
int nPart,
float St[MaxPart][4],
sim::IDE thisIDE,
float NearE[MaxPart] );
80 float CalcDist(
float X1,
float Y1,
float Z1,
float X2,
float Y2,
float Z2 );
81 bool IsInTPC(
float X1,
float Y1,
float Z1 ,
float Bound[6]);
88 float ActiveBounds[6];
90 std::map<int, const simb::MCParticle*>
truthmap;
104 float TopX, TopY,
TopZ, BotX, BotY, BotZ;
110 int nMuon, nPion, nPi0, nKaon, nElec,
nProt;
142 TotalEDep = EDepNearEdge2 = EDepNearEdge5 = EDepNearEdge10 = 0;
144 for (
int i=0; i<3; i++)
145 for (
int j=0; j<2; j++)
149 for (
int pr=0; pr<
MaxPrim; ++pr) {
150 PrimPDG[pr] = PrimEn[pr] = PrimMom[pr] = 0;
153 nMuon = nPion = nPi0 = nKaon = nElec = nProt = 0;
154 for (
int i=0; i<
MaxPart; ++i) {
155 MuonPDG[i] = PionPDG[i] = Pi0PDG[i] = KaonPDG[i] = ElecPDG[i] = ProtPDG[i] = 0;
156 MuonTrID[i] = PionTrID[i] = Pi0TrID[i] = KaonTrID[i] = ElecTrID[i] = ProtTrID[i] = 0;
157 MuonCont[i] = PionCont[i] = Pi0Cont[i] = KaonCont[i] = ElecCont[i] = ProtCont[i] = -1;
158 MuonEDep[i] = PionEDep[i] = Pi0EDep[i] = KaonEDep[i] = ElecEDep[i] = ProtEDep[i] = 0;
159 nParentMuon[i] = nParentPion[i] = nParentPi0[i] = nParentKaon[i] = nParentElec[i] = nParentProt[i] = 0;
161 MuonParents[i][j] = PionParents[i][j] = Pi0Parents[i][j] = KaonParents[i][j] = ElecParents[i][j] = ProtParents[i][j] = 0;
162 MuonParTrID[i][j] = PionParTrID[i][j] = Pi0ParTrID[i][j] = KaonParTrID[i][j] = ElecParTrID[i][j] = ProtParTrID[i][j] = 0;
164 MuonDaughtersEDep[i] = PionDaughtersEDep[i] = Pi0DaughtersEDep[i] = KaonDaughtersEDep[i] = ElecDaughtersEDep[i] = ProtDaughtersEDep[i] = 0;
165 MuonDecayEDep[i] = PionDecayEDep[i] = Pi0DecayEDep[i] = KaonDecayEDep[i] = ElecDecayEDep[i] = ProtDecayEDep[i] = 0;
166 MuonNearEDep[i] = PionNearEDep[i] = Pi0NearEDep[i] = KaonNearEDep[i] = ElecNearEDep[i] = ProtNearEDep[i] = 0;
167 for (
int j=0; j<4; ++j) {
168 MuonStart[i][j] = PionStart[i][j] = Pi0Start[i][j] = KaonStart[i][j] = ElecStart[i][j] = ProtStart[i][j] =
HolderVal;
169 MuonEnd[i][j] = PionEnd[i][j] = Pi0End[i][j] = KaonEnd[i][j] = ElecEnd[i][j] = ProtEnd[i][j] =
HolderVal;
181 ActiveBounds[0] = ActiveBounds[2] = ActiveBounds[4] = DBL_MAX;
182 ActiveBounds[1] = ActiveBounds[3] = ActiveBounds[5] = -DBL_MAX;
184 TopX = TopY = TopZ = -DBL_MAX;
185 BotX = BotY = BotZ = DBL_MAX;
188 auto const* geom = lar::providerFrom<geo::Geometry>();
191 const double origin[3] = {0.};
193 TPC.LocalToWorld(origin, center);
195 double tpcDim[3] = {
TPC.HalfWidth(),
TPC.HalfHeight(), 0.5*
TPC.Length() };
196 if( center[0] - tpcDim[0] < ActiveBounds[0] ) ActiveBounds[0] = center[0] - tpcDim[0];
197 if( center[0] + tpcDim[0] > ActiveBounds[1] ) ActiveBounds[1] = center[0] + tpcDim[0];
198 if( center[1] - tpcDim[1] < ActiveBounds[2] ) ActiveBounds[2] = center[1] - tpcDim[1];
199 if( center[1] + tpcDim[1] > ActiveBounds[3] ) ActiveBounds[3] = center[1] + tpcDim[1];
200 if( center[2] - tpcDim[2] < ActiveBounds[4] ) ActiveBounds[4] = center[2] - tpcDim[2];
201 if( center[2] + tpcDim[2] > ActiveBounds[5] ) ActiveBounds[5] = center[2] + tpcDim[2];
205 ActiveBounds[0] = -723;
206 ActiveBounds[1] = 723;
207 ActiveBounds[2] = -600;
208 ActiveBounds[3] = 600;
209 ActiveBounds[4] = -1;
210 ActiveBounds[5] = 5809;
211 std::cout <<
"Active Boundaries: " 212 <<
"\n\tx: " << ActiveBounds[0] <<
" to " << ActiveBounds[1]
213 <<
"\n\ty: " << ActiveBounds[2] <<
" to " << ActiveBounds[3]
214 <<
"\n\tz: " << ActiveBounds[4] <<
" to " << ActiveBounds[5]
263 fDecayTree = tfs->make<TTree>(
"ReconstructedTree",
"analysis tree");
265 fDecayTree->Branch(
"Run" , &Run ,
"Run/I" );
266 fDecayTree->Branch(
"Event" , &
Event ,
"Event/I" );
267 fDecayTree->Branch(
"DistEdge" , &DistEdge ,
"DistEdge[3][2]/F" );
268 fDecayTree->Branch(
"TotalEDep" , &TotalEDep ,
"TotalEDep/F" );
269 fDecayTree->Branch(
"EDepNearEdge2" , &EDepNearEdge2 ,
"EDepNearEdge2/F" );
270 fDecayTree->Branch(
"EDepNearEdge5" , &EDepNearEdge5 ,
"EDepNearEdge5/F" );
271 fDecayTree->Branch(
"EDepNearEdge10", &EDepNearEdge10,
"EDepNearEdge10/F" );
274 fDecayTree->Branch(
"nPrim" , &nPrim ,
"nPrim/I" );
275 fDecayTree->Branch(
"PrimPDG" , &PrimPDG ,
"PrimPDG[nPrim]/I" );
276 fDecayTree->Branch(
"PrimEn" , &PrimEn ,
"PrimEn[nPrim]/F" );
277 fDecayTree->Branch(
"PrimMom" , &PrimMom ,
"PrimMom[nPrim]/F" );
279 fDecayTree->Branch(
"nMuon" ,&nMuon ,
"nMuon/I" );
280 fDecayTree->Branch(
"nParentMuon" ,&nParentMuon ,
"nParentMuon[nMuon]/I" );
281 fDecayTree->Branch(
"MuonParents" ,&MuonParents ,
"MuonParents[nMuon][25]/I" );
282 fDecayTree->Branch(
"MuonParTrID" ,&MuonParTrID ,
"MuonParTrID[nMuon][25]/I" );
283 fDecayTree->Branch(
"MuonPDG" ,&MuonPDG ,
"MuonPDG[nMuon]/I" );
284 fDecayTree->Branch(
"MuonTrID" ,&MuonTrID ,
"MuonTrID[nMuon]/I" );
285 fDecayTree->Branch(
"MuonCont" ,&MuonCont ,
"MuonCont[nMuon]/I" );
286 fDecayTree->Branch(
"MuonFromDecay" ,&MuonFromDecay ,
"MuonFromDecay[nMuon]/I" );
287 fDecayTree->Branch(
"MuonEDep" ,&MuonEDep ,
"MuonEDep[nMuon]/F" );
288 fDecayTree->Branch(
"MuonStart" ,&MuonStart ,
"MuonStart[nMuon][4]/F" );
289 fDecayTree->Branch(
"MuonEnd" ,&MuonEnd ,
"MuonEnd[nMuon][4]/F" );
290 fDecayTree->Branch(
"MuonDaughtersEDep",&MuonDaughtersEDep,
"MuonDaughtersEDep[nMuon]/F");
291 fDecayTree->Branch(
"MuonDecayEDep" ,&MuonDecayEDep ,
"MuonDecayEDep[nMuon]/F" );
292 fDecayTree->Branch(
"MuonNearEDep" ,&MuonNearEDep ,
"MuonNearEDep[nMuon]/F" );
294 fDecayTree->Branch(
"nPion" ,&nPion ,
"nPion/I" );
295 fDecayTree->Branch(
"nParentPion" ,&nParentPion ,
"nParentPion[nPion]/I" );
296 fDecayTree->Branch(
"PionParents" ,&PionParents ,
"PionParents[nPion][25]/I" );
297 fDecayTree->Branch(
"PionParTrID" ,&PionParTrID ,
"PionParTrID[nPion][25]/I" );
298 fDecayTree->Branch(
"PionPDG" ,&PionPDG ,
"PionPDG[nPion]/I" );
299 fDecayTree->Branch(
"PionTrID" ,&PionTrID ,
"PionTrID[nPion]/I" );
300 fDecayTree->Branch(
"PionCont" ,&PionCont ,
"PionCont[nPion]/I" );
301 fDecayTree->Branch(
"PionFromDecay" ,&PionFromDecay ,
"PionFromDecay[nPion]/I" );
302 fDecayTree->Branch(
"PionEDep" ,&PionEDep ,
"PionEDep[nPion]/F" );
303 fDecayTree->Branch(
"PionStart" ,&PionStart ,
"PionStart[nPion][4]/F" );
304 fDecayTree->Branch(
"PionEnd" ,&PionEnd ,
"PionEnd[nPion][4]/F" );
305 fDecayTree->Branch(
"PionDaughtersEDep",&PionDaughtersEDep,
"PionDaughtersEDep[nPion]/F");
306 fDecayTree->Branch(
"PionDecayEDep" ,&PionDecayEDep ,
"PionDecayEDep[nPion]/F" );
307 fDecayTree->Branch(
"PionNearEDep" ,&PionNearEDep ,
"PionNearEDep[nPion]/F" );
309 fDecayTree->Branch(
"nPi0" ,&nPi0 ,
"nPi0/I" );
310 fDecayTree->Branch(
"nParentPi0" ,&nParentPi0 ,
"nParentPi0[nPi0]/I" );
311 fDecayTree->Branch(
"Pi0Parents" ,&Pi0Parents ,
"Pi0Parents[nPi0][25]/I" );
312 fDecayTree->Branch(
"Pi0ParTrID" ,&Pi0ParTrID ,
"Pi0ParTrID[nPi0][25]/I" );
313 fDecayTree->Branch(
"Pi0PDG" ,&Pi0PDG ,
"Pi0PDG[nPi0]/I" );
314 fDecayTree->Branch(
"Pi0TrID" ,&Pi0TrID ,
"Pi0TrID[nPi0]/I" );
315 fDecayTree->Branch(
"Pi0Cont" ,&Pi0Cont ,
"Pi0Cont[nPi0]/I" );
316 fDecayTree->Branch(
"Pi0FromDecay" ,&Pi0FromDecay ,
"Pi0FromDecay[nPi0]/I" );
317 fDecayTree->Branch(
"Pi0EDep" ,&Pi0EDep ,
"Pi0EDep[nPi0]/F" );
318 fDecayTree->Branch(
"Pi0Start" ,&Pi0Start ,
"Pi0Start[nPi0][4]/F" );
319 fDecayTree->Branch(
"Pi0End" ,&Pi0End ,
"Pi0End[nPi0][4]/F" );
320 fDecayTree->Branch(
"Pi0DaughtersEDep",&Pi0DaughtersEDep,
"Pi0DaughtersEDep[nPi0]/F");
321 fDecayTree->Branch(
"Pi0DecayEDep" ,&Pi0DecayEDep ,
"Pi0DecayEDep[nPi0]/F" );
322 fDecayTree->Branch(
"Pi0NearEDep" ,&Pi0NearEDep ,
"Pi0NearEDep[nPi0]/F" );
324 fDecayTree->Branch(
"nKaon" ,&nKaon ,
"nKaon/I" );
325 fDecayTree->Branch(
"nParentKaon" ,&nParentKaon ,
"nParentKaon[nKaon]/I" );
326 fDecayTree->Branch(
"KaonParents" ,&KaonParents ,
"KaonParents[nKaon][25]/I" );
327 fDecayTree->Branch(
"KaonParTrID" ,&KaonParTrID ,
"KaonParTrID[nKaon][25]/I" );
328 fDecayTree->Branch(
"KaonPDG" ,&KaonPDG ,
"KaonPDG[nKaon]/I" );
329 fDecayTree->Branch(
"KaonTrID" ,&KaonTrID ,
"KaonTrID[nKaon]/I" );
330 fDecayTree->Branch(
"KaonCont" ,&KaonCont ,
"KaonCont[nKaon]/I" );
331 fDecayTree->Branch(
"KaonFromDecay" ,&KaonFromDecay ,
"KaonFromDecay[nKaon]/I" );
332 fDecayTree->Branch(
"KaonEDep" ,&KaonEDep ,
"KaonEDep[nKaon]/F" );
333 fDecayTree->Branch(
"KaonStart" ,&KaonStart ,
"KaonStart[nKaon][4]/F" );
334 fDecayTree->Branch(
"KaonEnd" ,&KaonEnd ,
"KaonEnd[nKaon][4]/F" );
335 fDecayTree->Branch(
"KaonDaughtersEDep",&KaonDaughtersEDep,
"KaonDaughtersEDep[nKaon]/F");
336 fDecayTree->Branch(
"KaonDecayEDep" ,&KaonDecayEDep ,
"KaonDecayEDep[nKaon]/F" );
337 fDecayTree->Branch(
"KaonNearEDep" ,&KaonNearEDep ,
"KaonNearEDep[nKaon]/F" );
339 fDecayTree->Branch(
"nElec" ,&nElec ,
"nElec/I" );
340 fDecayTree->Branch(
"nParentElec" ,&nParentElec ,
"nParentElec[nElec]/I" );
341 fDecayTree->Branch(
"ElecParents" ,&ElecParents ,
"ElecParents[nElec][25]/I" );
342 fDecayTree->Branch(
"ElecParTrID" ,&ElecParTrID ,
"ElecParTrID[nElec][25]/I" );
343 fDecayTree->Branch(
"ElecFromDecay" ,&ElecFromDecay ,
"ElecFromDecay[nElec]/I" );
344 fDecayTree->Branch(
"ElecPDG" ,&ElecPDG ,
"ElecPDG[nElec]/I" );
345 fDecayTree->Branch(
"ElecTrID" ,&ElecTrID ,
"ElecTrID[nElec]/I" );
346 fDecayTree->Branch(
"ElecCont" ,&ElecCont ,
"ElecCont[nElec]/I" );
347 fDecayTree->Branch(
"ElecEDep" ,&ElecEDep ,
"ElecEDep[nElec]/F" );
348 fDecayTree->Branch(
"ElecStart" ,&ElecStart ,
"ElecStart[nElec][4]/F" );
349 fDecayTree->Branch(
"ElecEnd" ,&ElecEnd ,
"ElecEnd[nElec][4]/F" );
350 fDecayTree->Branch(
"ElecDaughtersEDep",&ElecDaughtersEDep,
"ElecDaughtersEDep[nElec]/F");
351 fDecayTree->Branch(
"ElecDecayEDep" ,&ElecDecayEDep ,
"ElecDecayEDep[nElec]/F" );
352 fDecayTree->Branch(
"ElecNearEDep" ,&ElecNearEDep ,
"ElecNearEDep[nElec]/F" );
354 fDecayTree->Branch(
"nProt" ,&nProt ,
"nProt/I" );
355 fDecayTree->Branch(
"nParentProt" ,&nParentProt ,
"nParentProt[nProt]/I" );
356 fDecayTree->Branch(
"ProtParents" ,&ProtParents ,
"ProtParents[nProt][25]/I" );
357 fDecayTree->Branch(
"ProtParTrID" ,&ProtParTrID ,
"ProtParTrID[nProt][25]/I" );
358 fDecayTree->Branch(
"ProtFromDecay" ,&ProtFromDecay ,
"ProtFromDecay[nProt]/I" );
359 fDecayTree->Branch(
"ProtPDG" ,&ProtPDG ,
"ProtPDG[nProt]/I" );
360 fDecayTree->Branch(
"ProtTrID" ,&ProtTrID ,
"ProtTrID[nProt]/I" );
361 fDecayTree->Branch(
"ProtCont" ,&ProtCont ,
"ProtCont[nProt]/I" );
362 fDecayTree->Branch(
"ProtEDep" ,&ProtEDep ,
"ProtEDep[nProt]/F" );
363 fDecayTree->Branch(
"ProtStart" ,&ProtStart ,
"ProtStart[nProt][4]/F" );
364 fDecayTree->Branch(
"ProtEnd" ,&ProtEnd ,
"ProtEnd[nProt][4]/F" );
365 fDecayTree->Branch(
"ProtDaughtersEDep",&ProtDaughtersEDep,
"ProtDaughtersEDep[nProt]/F");
366 fDecayTree->Branch(
"ProtDecayEDep" ,&ProtDecayEDep ,
"ProtDecayEDep[nProt]/F" );
367 fDecayTree->Branch(
"ProtNearEDep" ,&ProtNearEDep ,
"ProtNearEDep[nProt]/F" );
371 std::cout <<
"\nAfter all of that Top = " << TopX <<
", " << TopY <<
", " << TopZ <<
". Bot = " << BotX <<
", " << BotY <<
", " << BotZ <<
std::endl;
381 , NearEDeps( pset.
get<
int >(
"NearEDeps" ))
401 std::cout <<
"\n\n************* New Event / Module running - Run " << Run <<
", Event " <<
Event <<
", NEvent " << NEvent <<
" *************\n\n" <<
std::endl;
404 auto const*
geo = lar::providerFrom<geo::Geometry>();
413 auto truth = evt.
getHandle<std::vector<simb::MCParticle> >(
"largeant");
415 for (
size_t i=0; i<truth->size(); i++) {
416 truthmap[truth->at(i).TrackId()]=&((*truth)[i]);
417 if (truth->at(i).Mother() == 0) {
418 PrimPDG[nPrim] = truth->at(i).PdgCode();
419 PrimEn [nPrim] = truth->at(i).E(0);
420 PrimMom[nPrim] = truth->at(i).P(0);
423 std::cout <<
"The primary particle in this event was a " << PrimPDG[nPrim-1]<<
" with Energy " << PrimEn[nPrim-1]
424 <<
", momentum " << PrimMom[nPrim-1]<<
", process " << truth->at(i).Process() <<
std::endl;
429 std::cout <<
"There were " << nPrim <<
" primary particles." <<
std::endl;
432 auto simchannels = evt.
getHandle<std::vector<sim::SimChannel> >(
"largeant");
435 std::vector<int> MuonVec, PionVec, Pi0Vec, KaonVec, ElecVec, ProtVec;
441 std::vector< sim::IDE > UnAssignVec;
444 for (
auto const& simchannel:*simchannels) {
450 for (
auto const& tdcide:simchannel.TDCIDEMap()) {
451 unsigned int tdc = tdcide.first;
452 auto const& idevec=tdcide.second;
454 std::cout <<
"TDC IDE " << tdcideIt <<
" of " << simchannel.TDCIDEMap().size() <<
", has tdc " << tdc <<
", and idevec of size " << idevec.size() <<
std::endl;
457 for (
auto const& ide:idevec) {
458 int ideTrackID = ide.trackID;
459 float ideEnergy = ide.energy;
474 int OrigPdgCode = Origpart.
PdgCode();
477 if (!(
geo->HasTPC(tpcid)) ) {
479 std::cout <<
"Outside the Active volume I found at the top!" <<
std::endl;
485 if ( DistEdge[0][0] > ( ide.x - ActiveBounds[0]) ) DistEdge[0][0] = ide.x - ActiveBounds[0];
486 if ( DistEdge[0][1] > (-ide.x + ActiveBounds[1]) ) DistEdge[0][1] = -ide.x + ActiveBounds[1];
487 if ( DistEdge[1][0] > ( ide.y - ActiveBounds[2]) ) DistEdge[1][0] = ide.y - ActiveBounds[2];
488 if ( DistEdge[1][1] > (-ide.y + ActiveBounds[3]) ) DistEdge[1][1] = -ide.y + ActiveBounds[3];
489 if ( DistEdge[2][0] > ( ide.z - ActiveBounds[4]) ) DistEdge[2][0] = ide.z - ActiveBounds[4];
490 if ( DistEdge[2][1] > (-ide.z + ActiveBounds[5]) ) DistEdge[2][1] = -ide.z + ActiveBounds[5];
493 float XEDep =
std::min( ide.x - ActiveBounds[0], -ide.x + ActiveBounds[1] );
494 float YEDep =
std::min( ide.y - ActiveBounds[2], -ide.y + ActiveBounds[3] );
495 float ZEDep =
std::min( ide.z - ActiveBounds[4], -ide.z + ActiveBounds[5] );
505 EDepNearEdge2 += ide.energy;
508 EDepNearEdge5 += ide.energy;
511 EDepNearEdge10 += ide.energy;
526 if (ide.x < BotX) BotX = ide.x;
527 if (ide.y < BotY) BotY = ide.y;
528 if (ide.z < BotZ) BotZ = ide.z;
531 TotalEDep += ideEnergy;
549 bool isDecay =
false;
550 bool WrittenOut =
false;
551 bool OrigPart =
true;
553 std::cout <<
"\nLooking at IDE " << ideIt <<
", ideTrackID is " << ideTrackID <<
", it was due to a " 554 << truthmap[
abs(ideTrackID) ]->PdgCode() <<
", process " << truthmap[
abs(ideTrackID) ]->Process()
556 while ( ideTrackID != 0 && !WrittenOut ) {
559 if ( PdgCode != OrigPdgCode || ideTrackID < 0 )
562 if ( (PdgCode == -13 || PdgCode == 13) )
563 FillVars( MuonVec, nMuon, MuonEDep, MuonDaughtersEDep, MuonDecayEDep, MuonStart, MuonEnd, nParentMuon, MuonParents, MuonParTrID, MuonPDG, MuonTrID, MuonCont, MuonFromDecay,
564 ideTrackID, tdc, ide, part, OrigPart, isDecay, WrittenOut );
566 else if ( (PdgCode == -211 || PdgCode == 211) && part.
Process() !=
"pi+Inelastic" && part.
Process() !=
"pi-Inelastic" )
567 FillVars( PionVec, nPion, PionEDep, PionDaughtersEDep, PionDecayEDep, PionStart, PionEnd, nParentPion, PionParents, PionParTrID, PionPDG, PionTrID, PionCont, PionFromDecay,
568 ideTrackID, tdc, ide, part, OrigPart, isDecay, WrittenOut);
570 else if ( PdgCode == 111 )
571 FillVars( Pi0Vec , nPi0 , Pi0EDep , Pi0DaughtersEDep , Pi0DecayEDep , Pi0Start , Pi0End , nParentPi0 , Pi0Parents , Pi0ParTrID , Pi0PDG , Pi0TrID , Pi0Cont , Pi0FromDecay ,
572 ideTrackID, tdc, ide, part, OrigPart, isDecay, WrittenOut );
574 else if ( (PdgCode == 321 || PdgCode == -321) && part.
Process() !=
"kaon+Inelastic" && part.
Process() !=
"kaon-Inelastic" )
575 FillVars( KaonVec, nKaon, KaonEDep, KaonDaughtersEDep, KaonDecayEDep, KaonStart, KaonEnd, nParentKaon, KaonParents, KaonParTrID, KaonPDG, KaonTrID, KaonCont, KaonFromDecay,
576 ideTrackID, tdc, ide, part, OrigPart, isDecay, WrittenOut );
578 else if ( (PdgCode == -11 || PdgCode == 11) ) {
581 FillVars( ElecVec, nElec, ElecEDep, ElecDaughtersEDep, ElecDecayEDep, ElecStart, ElecEnd, nParentElec, ElecParents, ElecParTrID, ElecPDG, ElecTrID, ElecCont, ElecFromDecay,
582 ideTrackID, tdc, ide, part, OrigPart, isDecay, WrittenOut );
584 }
else if ( PdgCode == 2212 )
585 FillVars( ProtVec, nProt, ProtEDep, ProtDaughtersEDep, ProtDecayEDep, ProtStart, ProtEnd, nParentProt, ProtParents, ProtParTrID, ProtPDG, ProtTrID, ProtCont, ProtFromDecay,
586 ideTrackID, tdc, ide, part, OrigPart, isDecay, WrittenOut );
589 ideTrackID = part.
Mother();
592 int ThrowIDE = ide.trackID;
593 std::cout <<
"None of the particles in this chain are interesting, so skipping. It was due to TrackID " << ThrowIDE <<
", PdGCode " << truthmap[
abs(ThrowIDE) ]->PdgCode()
594 <<
", energy " << ide.energy <<
", and pos ("<<ide.x<<
", "<<ide.y<<
", "<<ide.z<<
").\n" 595 <<
" The ide parentage was PdG (TrackID) " << truthmap[
abs(ThrowIDE) ]->PdgCode() <<
" (" << ThrowIDE <<
") ";
596 while ( ThrowIDE != 0 ) {
597 ThrowIDE = truthmap[
abs(ThrowIDE) ]->Mother();
601 std::cout <<
" <-- " << truthmap[
abs(ThrowIDE) ]->PdgCode() <<
" (" << ThrowIDE <<
") ";
604 UnAssignVec.push_back( ide );
607 PdgCode = truthmap[
abs(ideTrackID) ]->PdgCode();
610 if ( ideTrackID > 0 && part.
Process() ==
"Decay" &&
611 ( PdgCode == -13 || PdgCode == 13 || PdgCode == -211 || PdgCode == 211 ||
612 PdgCode == 321 || PdgCode == -321 || PdgCode == -11 || PdgCode == 11 ||
622 std::cout <<
"Not something interesting so moving backwards. The parent of that particle had trackID " << ideTrackID
623 <<
", was from a " << PdgCode <<
", from a decay? " << isDecay <<
std::endl;
629 std::cout <<
"Had too many of one particle type, voiding this event now...nKaon " << nKaon <<
", nElec " << nElec <<
", nMuon " << nMuon
630 <<
", nPion " << nPion <<
", nPi0 " << nPi0 <<
", nProt " << nProt <<
"....Up to now there was " << TotalEDep <<
" energy deposited." <<
std::endl;
642 std::cout <<
"\nLooked through all of my IDEs, my UnAssignVec has size " << UnAssignVec.size() <<
std::endl;
643 int StillUnassign = 0;
644 for (
auto const& ide:UnAssignVec) {
646 std::cout <<
"Going through my uninteresting particles...this IDE was due to TrackID " << ide.trackID <<
", energy " << ide.energy
647 <<
", and pos ("<<ide.x<<
", "<<ide.y<<
", "<<ide.z<<
"). " <<
std::endl;
648 int ideTrId = ide.trackID;
649 std::cout <<
" The ide parentage was PdG (TrackID) " << truthmap[
abs(ideTrId) ]->PdgCode() <<
" (" << ideTrId <<
") ";
650 while ( ideTrId != 0 ) {
651 ideTrId = truthmap[
abs(ideTrId) ]->Mother();
655 std::cout <<
" <-- " << truthmap[
abs(ideTrId) ]->PdgCode() <<
" (" << ideTrId <<
") ";
658 bool FoundDep =
false;
660 FoundDep = UnAssignLoop( nKaon, KaonStart, ide, KaonNearEDep );
661 if (FoundDep)
continue;
663 FoundDep = UnAssignLoop( nElec, ElecStart, ide, ElecNearEDep );
664 if (FoundDep)
continue;
666 FoundDep = UnAssignLoop( nMuon, MuonStart, ide, MuonNearEDep );
667 if (FoundDep)
continue;
669 FoundDep = UnAssignLoop( nPion, PionStart, ide, PionNearEDep );
670 if (FoundDep)
continue;
672 FoundDep = UnAssignLoop( nPi0, Pi0Start, ide, Pi0NearEDep );
673 if (FoundDep)
continue;
675 FoundDep = UnAssignLoop( nProt, ProtStart, ide, ProtNearEDep );
676 if (FoundDep)
continue;
678 if (
Verbosity > 1) std::cout <<
"!!!This IDE was nowhere near anything...." <<
std::endl;
681 std::cout <<
"There were still " << StillUnassign <<
" unassigned IDEs." <<
std::endl;
687 std::cout <<
"\nThere are kaons in this event!!" <<
std::endl;
688 for (
int KL=0; KL<nKaon; ++KL) {
689 std::cout <<
"Kaon " << KL <<
" had properties: PDG " << KaonPDG[KL] <<
", TrackID " << KaonTrID[KL] <<
", EDep " << KaonEDep[KL]
690 <<
", DaughtEDep " << KaonDaughtersEDep[KL] <<
", DecayEDep " << KaonDecayEDep[KL] <<
", NearEDep " << KaonNearEDep[KL] <<
std::endl;
694 std::cout <<
"There are electrons in this event!!" <<
std::endl;
695 for (
int EL=0; EL<nElec; ++EL) {
696 std::cout <<
"Elec " << EL <<
" had properties: PDG " << ElecPDG[EL] <<
", TrackID " << ElecTrID[EL] <<
", EDep " << ElecEDep[EL]
697 <<
", DaughtEDep " << ElecDaughtersEDep[EL] <<
", DecayEDep " << ElecDecayEDep[EL] <<
", NearEDep " << ElecNearEDep[EL]
698 <<
"\nStart pos " << ElecStart[EL][0] <<
", " << ElecStart[EL][1] <<
", " << ElecStart[EL][2]
699 <<
". + End pos " << ElecEnd [EL][0] <<
", " << ElecEnd [EL][1] <<
", " << ElecEnd [EL][2]
700 <<
"\nThe parents of this electron were: ";
701 for (
int zz=0; zz<nParentElec[EL]; ++zz) {
702 std::cout << ElecParents[EL][zz] <<
" ("<<ElecParTrID[EL][zz]<<
"), ";
708 std::cout <<
"There are " << nMuon <<
" muons in this event!!" <<
std::endl;
711 std::cout <<
"There are " << nPion <<
" pions in this event!!" <<
std::endl;
714 std::cout <<
"There are " << nPi0 <<
" pi0's in this event!!" <<
std::endl;
717 std::cout <<
"There are " << nProt <<
" protons in this event!!" <<
std::endl;
720 std::cout <<
"\nThere was " << EDepNearEdge2 <<
", (" << EDepNearEdge5 <<
"), [" << EDepNearEdge10 <<
"] MeV EDep within 2, (5), [10] cm of walls" <<
std::endl;
727 std::cout <<
"There were Kaons in the detector so writing out this event." <<
std::endl;
734 float DecayEDep[MaxPart],
float Start[MaxPart][4],
float End[MaxPart][4],
735 int nParents[MaxPart],
int Parent[MaxPart][
MaxParent],
int ParTrID[MaxPart][MaxParent],
736 int PDG[MaxPart],
int TrID[MaxPart],
int Cont[MaxPart],
int FromDecay[MaxPart],
738 bool OrigParticle,
bool Decay,
bool &Written ) {
739 if (numParts+1 > MaxPart-1) {
748 if ( it==TrackIDVec.end() ) {
749 TrackIDVec.push_back (
abs(ThisID) );
750 AllTrackIDs.push_back(
abs(ThisID) );
753 if ( MCPart.
Process() ==
"Decay" ) FromDecay[numParts] = 1;
754 else FromDecay[numParts] = 0;
756 bool StartIn = IsInTPC( MCPart.
Vx(0) , MCPart.
Vy(0) , MCPart.
Vz(0) , ActiveBounds );
757 bool EndIn = IsInTPC( MCPart.
EndX(), MCPart.
EndY(), MCPart.
EndZ(), ActiveBounds );
758 if(!StartIn && !EndIn ) Cont[numParts] = 0;
759 if(!StartIn && EndIn ) Cont[numParts] = 1;
760 if( StartIn && !EndIn ) Cont[numParts] = 2;
761 if( StartIn && EndIn ) Cont[numParts] = 3;
763 std::cout <<
"\nPushing back a new ideTrackID " <<
abs(ThisID) <<
", it was from a " << MCPart.
PdgCode() <<
", process " << MCPart.
Process()
764 <<
", PartDecay? " << FromDecay[numParts] <<
", deposition from a decay? " << Decay <<
"\n" 765 <<
"Starting location is " << MCPart.
Vx(0) <<
", " << MCPart.
Vy(0) <<
", " << MCPart.
Vz(0) <<
"==> InTPC? " << StartIn
766 <<
". Ending location is " << MCPart.
EndX()<<
", " << MCPart.
EndY()<<
", " << MCPart.
EndZ() <<
"==> InTPC? " << EndIn
767 <<
" =====>>> Cont? " << Cont[numParts]
770 Parent[numParts][0] = MCPart.
Mother();
772 int ParentID = Parent[numParts][0];
773 while ( ParentID > 0 && NumParent < MaxParent) {
774 int pdg = truthmap[ ParentID ]->PdgCode();
776 std::cout <<
"The particles parent was TrackID " << ParentID <<
", PdgCode " << pdg <<
", it was from process " << truthmap[ ParentID ]->Process() <<
std::endl;
778 if ( pdg == Parent[numParts][NumParent-1] ) {
780 std::cout <<
"Overwriting what was in ParentID as same particle." <<
std::endl;
781 ParTrID[numParts][NumParent-1] = ParentID;
783 Parent [numParts][NumParent] =
pdg;
784 ParTrID[numParts][NumParent] = ParentID;
787 ParentID = truthmap[ ParentID ]->Mother();
791 std::cout <<
"There were a total of " << NumParent <<
" parents of this particle. The parentage was: " <<
PDG[numParts] <<
" ("<< TrID[numParts] <<
") ";
792 for (
int aa=0; aa<NumParent; ++aa)
794 std::cout <<
" <- " << Parent[numParts][aa] <<
" ("<<ParTrID[numParts][aa] <<
") ";
797 nParents[numParts] = NumParent;
801 partNum = it - TrackIDVec.begin();
806 std::cout <<
"OrigParticle " << OrigParticle <<
", TrackID " << ThisID <<
", " << ThisIDE.
trackID 807 <<
", PDgCode " <<
PDG[numParts-1] <<
", " << MCPart.
PdgCode() <<
", decay " << Decay
810 if ( OrigParticle ) {
817 float St_Ar = CalcDist( MCPart.
Vx(0), MCPart.
Vy(0), MCPart.
Vz(0),
Start[partNum][0],
Start[partNum][1], Start[partNum][2] );
818 float St_ID = CalcDist( MCPart.
Vx(0), MCPart.
Vy(0), MCPart.
Vz(0), ThisIDE.
x , ThisIDE.
y , ThisIDE.
z );
823 Start[partNum][0] = ThisIDE.
x;
824 Start[partNum][1] = ThisIDE.
y;
825 Start[partNum][2] = ThisIDE.
z;
826 Start[partNum][3] = ThisTDC;
833 float En_Ar = CalcDist( MCPart.
EndX(), MCPart.
EndY(), MCPart.
EndZ(),
End[partNum][0],
End[partNum][1], End[partNum][2] );
834 float En_ID = CalcDist( MCPart.
EndX(), MCPart.
EndY(), MCPart.
EndZ(), ThisIDE.
x , ThisIDE.
y , ThisIDE.
z );
839 End[partNum][0] = ThisIDE.
x;
840 End[partNum][1] = ThisIDE.
y;
841 End[partNum][2] = ThisIDE.
z;
842 End[partNum][3] = ThisTDC;
846 DecayEDep[partNum] += ThisIDE.
energy;
848 DaughtEDep[partNum] += ThisIDE.
energy;
855 for (
int nP=0; nP < nPart; ++nP) {
856 float ThisDist = CalcDist( St[nP][0], St[nP][1], St[nP][2], thisIDE.
x, thisIDE.
y, thisIDE.
z );
858 std::cout <<
" Particle " << nP <<
" had initial position ("<<St[nP][0]<<
", "<<St[nP][1]<<
", "<<St[nP][2] <<
")...How close was this to the IDE in question? " << ThisDist <<
std::endl;
860 if (ThisDist < NearEDeps) {
861 NearE[nP] += thisIDE.
energy;
869 float Sq = TMath::Power( X1-X2 , 2 ) + TMath::Power( Y1-Y2 , 2 ) + TMath::Power( Z1-Z2 , 2 );
870 float Va = TMath::Power( Sq, 0.5 );
875 bool InX = ( X1 > Bound[0] && X1 < Bound[1] );
876 bool InY = ( Y1 > Bound[2] && Y1 < Bound[3] );
877 bool InZ = ( Z1 > Bound[4] && Z1 < Bound[5] );
878 bool Within = (InX && InY && InZ );
def analyze(root, level, gtrees, gbranches, doprint)
TrackID_t trackID
Geant4 supplied track ID.
float z
z position of ionization [cm]
float CalcDist(float X1, float Y1, float Z1, float X2, float Y2, float Z2)
EventNumber_t event() const
art::ServiceHandle< geo::Geometry > geom
Handle< PROD > getHandle(SelectorBase const &) const
Geometry information for a single TPC.
void Decay(const Decayer *decayer, int pdgc, double E, int ndecays)
std::string Process() const
std::vector< int > AllTrackIDs
float x
x position of ionization [cm]
art framework interface to geometry description
NeutronDecayN2Ana(fhicl::ParameterSet const &p)
int PdgCode(Resonance_t res, int Q)
(resonance id, charge) -> PDG code
bool UnAssignLoop(int nPart, float St[MaxPart][4], sim::IDE thisIDE, float NearE[MaxPart])
#define DEFINE_ART_MODULE(klass)
void endRun(art::Run const &) override
Ionization at a point of the TPC sensitive volume.
float energy
energy deposited by ionization by this track ID and time [MeV]
The data type to uniquely identify a TPC.
std::map< int, const simb::MCParticle * > truthmap
void analyze(art::Event const &e) override
float y
y position of ionization [cm]
double Vx(const int i=0) const
bool operator()(const sim::IDE &first, const sim::IDE &second)
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
virtual ~NeutronDecayN2Ana()
bool IsInTPC(float X1, float Y1, float Z1, float Bound[6])
double Vz(const int i=0) const
void FillVars(std::vector< int > &TrackIDVec, int &numParts, float EDep[MaxPart], float DaughtEDep[MaxPart], float DecayEDep[MaxPart], float Start[MaxPart][4], float End[MaxPart][4], int nParents[MaxPart], int Parent[MaxPart][MaxParent], int ParTrID[MaxPart][MaxParent], int PDG[MaxPart], int TrID[MaxPart], int Cont[MaxPart], int FromDecay[MaxPart], int ThisID, unsigned int ThisTDC, sim::IDE ThisIDE, const simb::MCParticle &MCPart, bool Decay, bool OrigParticle, bool &Written)
void beginRun(art::Run const &run) override
auto const & get(AssnsNode< L, R, D > const &r)
second_as<> second
Type of time stored in seconds, in double precision.
LArSoft geometry interface.
double Vy(const int i=0) const
constexpr Point origin()
Returns a origin position with a point of the specified type.
QTextStream & endl(QTextStream &s)
Signal from collection planes.