DUNE / ND_CAFMaker

Code for making CAFs from ND inputs (whether 2x2+MINERvA prototype or full ND simulation)
Apache License 2.0
1 stars 11 forks source link

True trajectory information does not match direction of momentum information #64

Closed rdiurba closed 3 months ago

rdiurba commented 4 months ago

Trajectories might be broken for particles as the momentum vector commonly has a different direction than the endpoints of the trajectory particle.

An example is this file: /exp/dune/data/users/noeroy/prod/MiniRun5_1E19_RHC/MiniRun5_1E19_RHC.caf.beta1/CAF/0000000/MiniRun5_1E19_RHC.caf.0000000.CAF.root

Here is an example in the file with indices to identify it: 160 (spill),0 (truth interaction index),0 (primary index),11.3667 (dX),0 (dY),0.886803 (dZ),0.975925 (direction relative to Z according to momentum info).

Example code (assuming you are already iterating over primaries in a truth interaction in a spill:

auto end_pos=sr->mc.nu[ntrue].prim[primaries].end_pos;
auto p=sr->mc.nu[ntrue].prim[primaries].p;
double dX=abs(end_pos.x-start_pos.x);
double dY=abs(end_pos.y-start_pos.y);
double dZ=abs(end_pos.z-start_pos.z);
double length=TMath::Sqrt(dX*dX+dY*dY+dZ*dZ);
double lengthP=TMath::Sqrt(p.px*p.px+p.py*p.py+p.pz*p.pz);
if (sr->mc.nu[ntrue].iscc && abs(sr->mc.nu[ntrue].pdg)==14 && abs(pdg)==13){
std::cout<<n<<","<<ntrue<<","<<primaries<<","<<dX<<","<<dY<<","<<dZ<<","<<p.pz/lengthP<<std::endl;
sindhu-ku commented 4 months ago

Can you check this first in the downstream MLrreco and flow files? This seems to be due to the known flow bug where the coordinates are interchanged for segments and trajectories.

noeroy commented 4 months ago

I'll have a detailed look whenever I can, but is it possible that a particle scatters and keeps it's id, hence not going in a straight line and not being at the position of the projected p ? I'll have a look at the edepsim file of that trajectory to see if that could make sense.

noeroy commented 4 months ago

Alright, forget what I said earlier:

I had a look at the true particle position with the several files of the chain (edepsim, flow, mlreco, minerva and cafs).

Cafs and MLRECO positions for that trajectory match (which makes sense as CAFs true particle position is filled by MLRECO). And the three others (edepsim, flow and minerva) have the exact same coordinate (see the slides linked)

Could that be a case of MLReco filling start and end point in true_particle as the reco start and reco end ? (I remembered that there was something like that happening at some point for the vertices) @sindhu-ku ?

NDCafMaker debuging truth Position.pdf

*(btw, I think another way to check the same issue is to see if the vertex of said interaction corresponds to the start of the primary = the vertex of the interaction, which is not the case here)

sindhu-ku commented 4 months ago

It is stored correctly, but CAFmaker looks at the start_point/end_point instead of the position/end_position. I don't know if there was any historical reason for this, but I'll make sure to do a PR for this along with other ML-reco related changes before the next production.

>>> ixn = fin['truth_particles'][fin['truth_particles']['truth_interaction_id'] == 8000017]
>>> print(ixn[ixn['gen_id'] == 0]['position'])
[array([ 15.282469, -33.369576,  16.005165], dtype=float32)]
>>> print(ixn[ixn['gen_id'] == 0]['end_position'])
[[-192.72841  208.42105 1313.4749 ]]