Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix matchtp variables #76

Merged
merged 7 commits into from May 17, 2021
Merged

Conversation

cgsavard
Copy link

@cgsavard cgsavard commented Mar 9, 2021

PR description:
The trk_matchtp_{} variables in the standard ntuple maker had some issues. First, the trk_matchtp_z0 was incorrect. It was actually the vz, not z0. Next, trk_matchtp_d0 was not included in the collection but is an important variable to have for studying displaced tracks. Lastly, many of the calls to get the variables, such as the tp phi, were outdated although it still worked.

I made all these fixes by followiing exactly what was done in the regular tp collection to get/calculate all of the variables.

PR validation:
Here are the distributions of the trk_matchtp_z0 and trk_matchtp_d0 to show that they are calculated correctly. The rest of the matchtp variables did not change.
Screen Shot 2021-03-08 at 7 56 33 PM
Screen Shot 2021-03-08 at 7 58 49 PM

@cgsavard cgsavard requested a review from skinnari March 9, 2021 03:13
@skinnari
Copy link

skinnari commented Mar 9, 2021

hi @cgsavard - thanks for this cleanup. i am going to hold off on this a few days since we are trying to merge code from Anders to avoid further confusion with that PR.

@tomalin tomalin self-requested a review March 9, 2021 16:15
@tomalin
Copy link
Collaborator

tomalin commented Mar 9, 2021

I thought we'd fixed the d0 & z0 and their signs two years ago. But they still look weird.

  1. The eqn. for trk_d0 https://github.com/cgsavard/cmssw/blob/fix_matchtp/L1Trigger/TrackFindingTracklet/test/L1TrackNtupleMaker.cc#L868 has wrong sign compared with the usual CMS definition of d0 https://github.com/cms-sw/cmssw/blob/master/DataFormats/TrackReco/interface/TrackBase.h#L611 .
  2. If I plot tp_d0_prod vs tp_d0 , I see they are anti-correlated, so one of them is wrong. It is the sign of tp_d0_prod which looks correct compared with the usual CMS definition, and the sign of tp_d0 that looks wrong.
  3. matchtrk_d0 also appears to have wrong sign too.


float tmp_matchtp_charge = my_tp->charge();
float K = Kmagnitude * tmp_matchtp_charge;
float d = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the point of "float d = 0" if its value is always zero?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question, I'm not sure. I just followed exactly what was done in the tracking particle section of the code and this variable was there but I did not write it. I can take it out of both sections if you think it's not important?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@skinnari any objections if Claire removes "float d"?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can see, this "K" is inv(2R). I don't know either what is purpose of "d".

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have removed the d=0 variable both here and in calculating the tp_d0

@cgsavard
Copy link
Author

cgsavard commented Mar 9, 2021

  1. The eqn. for trk_d0 https://github.com/cgsavard/cmssw/blob/fix_matchtp/L1Trigger/TrackFindingTracklet/test/L1TrackNtupleMaker.cc#L868 has wrong sign compared with the usual CMS definition of d0 https://github.com/cms-sw/cmssw/blob/master/DataFormats/TrackReco/interface/TrackBase.h#L611 .
  2. If I plot tp_d0_prod vs tp_d0 , I see they are anti-correlated, so one of them is wrong. It is the sign of tp_d0_prod which looks correct compared with the usual CMS definition, and the sign of tp_d0 that looks wrong.
  3. matchtrk_d0 also appears to have wrong sign too.

I did not look into any other d0 variables, I just took what was already there to be the truth and copied it to create trk_matchtp_d0. If you would like to make these fixes in this PR then let me know and I can commit some more changes.

@tomalin tomalin requested a review from Jingyan95 April 7, 2021 15:50
float delx = -tmp_matchtp_vx;
float dely = -tmp_matchtp_vy;

float A = 0.01 * 0.5696;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This float "A" basically contains information of B filed that needs to be re
placed with a constant.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this to now depend on the magnetic field and speed of light constants in cmssw. I also redefined the K variable to r2_inv to avoid confusion with this variable in the future. I double checked to make sure that the K and r2_inv matched after the switch to using the cms constants.


float tmp_matchtp_t = tan(2.0 * atan(1.0) - 2.0 * atan(exp(-tmp_matchtp_eta)));

float delx = -tmp_matchtp_vx;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the minus signs on L1021 and L1022 might be wrong.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know enough about propagating back to know if this is wrong or not. If you can confirm that this is incorrect then I will make the change. Do you also think that the overall sign of d0 is wrong? Ian proposes that it might be incorrect.

Copy link

@Jingyan95 Jingyan95 Apr 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To your second point on whether or not the overall sign of d0 is wrong, I agree with Ian that the sign of d0 does not seem to follow the cms convention. The easiest way to see this is to plot tp_d0 vs tp_d0_prod
d0vsd0_prod_default
There seems to be a negative association between the two variables and I am pretty sure the sign of tp_d0_prod is correct.
The only way I can think of to fix this sign problem is NOT directly flipping the sign on L1163 (i.e. tmp_tp_d0). Instead, I believe the signs on L1151&L1152 (delx & dely) are incorrect. If we modify those two lines and plot tp_d0 vs tp_d0_prod again:
d0vsd0_prod_fixsign.
Let me talk to Louise to see we can reach an agreement.

@tomalin
Copy link
Collaborator

tomalin commented Apr 28, 2021

Can we please finish this PR, before we merge cms-L1TK into official CMSSW (~1 week)? I think we just need to fix the d0 signs.

  1. Does everyone agree that the signs of tmp_trk_d0 (L864) and tmp_matchtrk_d0 (L1352) need multiplying by -1, to be consistent with the usual CMS convention? (This would also make the expression used to derive it look consistent with that for tmp_tp_d0_prod at L1093).
  2. Like Jack, I believe that the sign of tmp_tp_d0_prod is correct.
  3. Jack's plot proves there is also a problem with the sign of tmp_tp_d0. I have not checked his statement that to fix this, one should not reverse the sign of tmp_tp_d0, but instead that of delx & dely (L1151). Can someone please do so?
  4. Jack's plot also shows that tmp_tp_d0 is often zero, even with tmp_tp_d0_prod is not. I assume this is because of the cuts applied at L1095-1105. Is there a good reason why we don't bother calculating tmp_tp_d0 if its Pt < 2 GeV etc.?

@Jingyan95
Copy link

Jingyan95 commented Apr 30, 2021

Can we please finish this PR, before we merge cms-L1TK into official CMSSW (~1 week)? I think we just need to fix the d0 signs.

  1. Does everyone agree that the signs of tmp_trk_d0 (L864) and tmp_matchtrk_d0 (L1352) need multiplying by -1, to be consistent with the usual CMS convention? (This would also make the expression used to derive it look consistent with that for tmp_tp_d0_prod at L1093).
  2. Like Jack, I believe that the sign of tmp_tp_d0_prod is correct.
  3. Jack's plot proves there is also a problem with the sign of tmp_tp_d0. I have not checked his statement that to fix this, one should not reverse the sign of tmp_tp_d0, but instead that of delx & dely (L1151). Can someone please do so?
  4. Jack's plot also shows that tmp_tp_d0 is often zero, even with tmp_tp_d0_prod is not. I assume this is because of the cuts applied at L1095-1105. Is there a good reason why we don't bother calculating tmp_tp_d0 if its Pt < 2 GeV etc.?

Hi Ian,

-1 I completely agree that the sign of tmp_trk_d0 and tmp_matchtrk_d0 need multiplying by -1.
-3. The fix should be either reversing the signs of delx & dely or that of tmp_tp_d0 depending on the convention of curvature. After studying this a bit further, I would like to retract my formal statement and just say reversing the sign of tmp_tp_d0 is the right way to go. I had some discussion with @skinnari about this but haven't reached an agreement with her.
-4. I am not entirely sure about the 2GeV cut. It does feel a bit odd to me though.

If finishing this PR before merging into official CMSSW is the goal, I would recommend the following ways forward regarding the 3rd bullet point:
We find a volunteer to check whether or not reversing the sign of tmp_tp_d0 is the correct.
Or we bring this up during the meeting next Friday. I am happy to prepare a couple of slides if needed.

@tomalin
Copy link
Collaborator

tomalin commented Apr 30, 2021

@cgsavard based on discussion above, please:
a) Reverse sign of sign of tmp_trk_d0 and tmp_matchtrk_d0.
b) Move the calculation of tmp_tp_d0 and tmp_tp_z0 up from its current location https://github.com/cgsavard/cmssw/blob/fix_matchtp/L1Trigger/TrackFindingTracklet/test/L1TrackNtupleMaker.cc#L1146 to new location https://github.com/cgsavard/cmssw/blob/fix_matchtp/L1Trigger/TrackFindingTracklet/test/L1TrackNtupleMaker.cc#L1132 , so they are evaluated whenever the "prod" variables are.
c) Looking at the maths above https://github.com/cgsavard/cmssw/blob/fix_matchtp/L1Trigger/TrackFindingTracklet/test/L1TrackNtupleMaker.cc#L1163 , my suspicion is that reversing the sign of (delx,dely) will give a negligibly different result to reversing the sign of tmp_tp_d0. I suggest you do the calc both ways, and add debug printout of the difference in the two results to check this. Run on displaced MC with low Pt particles, where the effect should be biggest. If both methods give almost identical results, then you can just reverse the sign of tmp_t0_d0.

@cgsavard
Copy link
Author

I made the first two changes.

c) Looking at the maths above https://github.com/cgsavard/cmssw/blob/fix_matchtp/L1Trigger/TrackFindingTracklet/test/L1TrackNtupleMaker.cc#L1163 , my suspicion is that reversing the sign of (delx,dely) will give a negligibly different result to reversing the sign of tmp_tp_d0. I suggest you do the calc both ways, and add debug printout of the difference in the two results to check this. Run on displaced MC with low Pt particles, where the effect should be biggest. If both methods give almost identical results, then you can just reverse the sign of tmp_t0_d0.

When looking at the difference in a ttbar+200PU sample, most changes are negligible but there are a few on the order of 10^-1 and 10^-2 which seem like a big enough change to look further. I could not run the displaced particle sample (https://twiki.cern.ch/twiki/bin/view/CMS/L1TrackMC#CMSSW_11_3_0) as the files failed to open and there doesn't seem to be another displaced dataset currently ready to use.

@tomalin
Copy link
Collaborator

tomalin commented May 1, 2021

@cgsavard try running on the displaced MC https://cmsweb.cern.ch/das/request?view=list&limit=50&instance=prod%2Fglobal&input=%2FRelVal*Displaced*%2FCMSSW_11_3_0_pre6*%2FGEN-SIM-DIGI-RAW . (N.B. It's D76, so you'll have to change the geometry in cfg). Checking which eqn. gives best d0 resolution might also help.

@cgsavard
Copy link
Author

cgsavard commented May 3, 2021

@tomalin The results are very similar. Here I have attached the results for the displaced SUSY sample (noPU). "tp_d0" is the current d0 calculation with a sign flip at the end, and "tp_d02" is the d0 calculation when delx and dely have a sign flip. We see in both this and with the ttbar sample that the resolution for "tp_d02" is slightly larger than for "tp_d0". For comparison, the std of the difference tp_d0-tp_d02 for the ttbar sample is 0.4442 instead of 0.8873 for the displaced SUSY sample shown here.

Since the results are very similar and the difference is small, should we select tp_d0 with the slightly smaller resolution?

dispsusy_tp_d0
dispsusy_tp_d02
dispsusy_tp_diff

@skinnari
Copy link

skinnari commented May 4, 2021

hi all, I am trying to understand this thread and am a bit confused. AFAIK the known problem is with the sign of track d0 vs TP d0? are you saying there is another problem here?

@tomalin
Copy link
Collaborator

tomalin commented May 4, 2021

hi all, I am trying to understand this thread and am a bit confused. AFAIK the known problem is with the sign of track d0 vs TP d0? are you saying there is another problem here?

Hi Louise, the signs of tmp_trk_d0 and tmp_matchtrk_d0 were wrong, which this PR has now fixed.
The sign of tmp_tp_d0 is also approximately wrong, but we're unsure if it should simply be multiplied by -1, or if instead the signs of the variables delx & dely used to calculate it should be multiplied by -1. Both alternatives give almost identical results.

@skinnari
Copy link

skinnari commented May 7, 2021

@cgsavard @Jingyan95 I am confused now when looking at the changes. I know there is a problem with the d0 sign, but I thought it was only the (-1) that needed to be removed for the TP. but it seems that you are also changing the sign of the track d0?

@Jingyan95
Copy link

Jingyan95 commented May 7, 2021

@cgsavard @Jingyan95 I am confused now when looking at the changes. I know there is a problem with the d0 sign, but I thought it was only the (-1) that needed to be removed for the TP. but it seems that you are also changing the sign of the track d0?

That's right. The signs of tmp_trk_d0 [1] and tmp_matchtrk_d0 [2] are also incorrect. Currently these two take the following form:
-Vx * sin(phi)+ Vy * cos(phi)
We think the correct form should be
Vx * sin(phi)- Vy * cos(phi)
They are off by -1. An example of the correct form can be found here [3]. An even better example would be [4]

[1] https://github.com/cms-L1TK/cmssw/blob/L1TK-dev-11_3_0_pre3/L1Trigger/TrackFindingTracklet/test/L1TrackNtupleMaker.cc#L864
[2] https://github.com/cms-L1TK/cmssw/blob/L1TK-dev-11_3_0_pre3/L1Trigger/TrackFindingTracklet/test/L1TrackNtupleMaker.cc#L1352
[3] https://github.com/cms-L1TK/cmssw/blob/L1TK-dev-11_3_0_pre3/L1Trigger/TrackFindingTracklet/test/L1TrackNtupleMaker.cc#L1093
[4] https://github.com/cms-sw/cmssw/blob/master/DataFormats/TrackReco/interface/TrackBase.h#L611]

@cgsavard
Copy link
Author

@tomalin I removed the sign flip on tp_d0. I believe that was the last thing we were waiting on, unless you can think of anything else?

@tomalin
Copy link
Collaborator

tomalin commented May 17, 2021

As a sanity check, I've verified that with the latest version of this branch, 2D plots of matchtrk_d0 vs. tp_d0 or tp_d0_prod show a line gradient of +1. (And the resolution is much better for tp_d0 than for tp_d0_prod, as one would expect).

Copy link
Collaborator

@tomalin tomalin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy

@tomalin tomalin merged commit 3489b50 into cms-L1TK:L1TK-dev-11_3_0_pre3 May 17, 2021
skinnari pushed a commit that referenced this pull request May 20, 2021
* fix matchtp variables

* remove d=0 variables

* switch values for cms constants

* change pi to constant

* change trk_d0 sign

* move tmp_tp_d0 and tmp_tp_z0 calc up

* flip tp_d0 sign
skinnari pushed a commit that referenced this pull request Jun 8, 2021
* fix matchtp variables

* remove d=0 variables

* switch values for cms constants

* change pi to constant

* change trk_d0 sign

* move tmp_tp_d0 and tmp_tp_z0 calc up

* flip tp_d0 sign
skinnari pushed a commit that referenced this pull request Jun 22, 2021
* fix matchtp variables

* remove d=0 variables

* switch values for cms constants

* change pi to constant

* change trk_d0 sign

* move tmp_tp_d0 and tmp_tp_z0 calc up

* flip tp_d0 sign
skinnari pushed a commit that referenced this pull request Jun 22, 2021
* fix matchtp variables

* remove d=0 variables

* switch values for cms constants

* change pi to constant

* change trk_d0 sign

* move tmp_tp_d0 and tmp_tp_z0 calc up

* flip tp_d0 sign
skinnari pushed a commit that referenced this pull request Jul 9, 2021
* fix matchtp variables

* remove d=0 variables

* switch values for cms constants

* change pi to constant

* change trk_d0 sign

* move tmp_tp_d0 and tmp_tp_z0 calc up

* flip tp_d0 sign
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants