Pretty printing a query model

12 views
Skip to first unread message

Gordon Watts

unread,
Apr 16, 2016, 7:20:57 PM4/16/16
to re-moti...@googlegroups.com

Hi,

  After my code is run, there are times I want to be able to show someone else what went into the plot (or, in this case, a trained booted decision tree).

 

  I have a “PrettyPrintQuery” method which returns a query model as a string, just using ToString. It looks like below. 😊 What I’d like to do is re-format it to look better. Indenting, multiple lines, etc. Before I set out to write my own QM Visitor and Expression Visitor to do that, I was wondering if someone else had tackled this problem already?

 

JetPt = from TrainingTree t in {from recoTree e in value(LINQToTTreeLib.QueriableTTree`1[DiVertAnalysis.recoTree]) from JetStream j in {from recoTreeJets j in [e].Jets select new JetStream() {JetInfo = new JetInfoExtra() {Jet = [j], Tracks = {from recoTreeTracks t in [e].Tracks where (([t].pT >= 2) AndAlso (DeltaR2([j].eta, [j].phi, [t].eta, [t].phi) < 0.04)) select [t]}, AllTracks = {from recoTreeTracks t in [e].Tracks where (([t].pT >= 0.2) AndAlso (DeltaR2([j].eta, [j].phi, [t].eta, [t].phi) < 0.04)) select [t]}}, Weight = (1365.28540113985 * [e].eventWeight)}} where (([j].JetInfo.Jet.pT > 40) AndAlso (Abs([j].JetInfo.Jet.eta) < 2.4)) where ([j].JetInfo.Jet.pT < 400) select new TrainingTree() {Weight = [j].Weight, CalRatio = IIF(([j].JetInfo.Jet.logRatio > 4), 3.99, IIF(([j].JetInfo.Jet.logRatio < -3), -2.99, [j].JetInfo.Jet.logRatio)), JetPt = [j].JetInfo.Jet.pT, JetEta = [j].JetInfo.Jet.eta, NTracks = {[j].JetInfo.Tracks => Count()}, SumPtOfAllTracks = {from recoTreeTracks t in [j].JetInfo.AllTracks select [t].pT => Sum()}, MaxTrackPt = IIF(({[j].JetInfo.AllTracks => Count()} > 0), {from recoTreeTracks t in [j].JetInfo.AllTracks orderby [t].pT desc select [t] => First()}.pT, 0)} => Take(142231) => Concat({from recoTree e in value(LINQToTTreeLib.QueriableTTree`1[DiVertAnalysis.recoTree]) from JetStream j in {from recoTreeJets j in [e].Jets select new JetStream() {JetInfo = new JetInfoExtra() {Jet = [j], Tracks = {from recoTreeTracks t in [e].Tracks where (([t].pT >= 2) AndAlso (DeltaR2([j].eta, [j].phi, [t].eta, [t].phi) < 0.04)) select [t]}, AllTracks = {from recoTreeTracks t in [e].Tracks where (([t].pT >= 0.2) AndAlso (DeltaR2([j].eta, [j].phi, [t].eta, [t].phi) < 0.04)) select [t]}}, Weight = (15.4512718839008 * [e].eventWeight)}} where (([j].JetInfo.Jet.pT > 40) AndAlso (Abs([j].JetInfo.Jet.eta) < 2.4)) where ([j].JetInfo.Jet.pT < 400) select new TrainingTree() {Weight = [j].Weight, CalRatio = IIF(([j].JetInfo.Jet.logRatio > 4), 3.99, IIF(([j].JetInfo.Jet.logRatio < -3), -2.99, [j].JetInfo.Jet.logRatio)), JetPt = [j].JetInfo.Jet.pT, JetEta = [j].JetInfo.Jet.eta, NTracks = {[j].JetInfo.Tracks => Count()}, SumPtOfAllTracks = {from recoTreeTracks t in [j].JetInfo.AllTracks select [t].pT => Sum()}, MaxTrackPt = IIF(({[j].JetInfo.AllTracks => Count()} > 0), {from recoTreeTracks t in [j].JetInfo.AllTracks orderby [t].pT desc select [t] => First()}.pT, 0)} => Take(211053)}) => Concat({from recoTree e in value(LINQToTTreeLib.QueriableTTree`1[DiVertAnalysis.recoTree]) from JetStream j in {from recoTreeJets j in [e].Jets select new JetStream() {JetInfo = new JetInfoExtra() {Jet = [j], Tracks = {from recoTreeTracks t in [e].Tracks where (([t].pT >= 2) AndAlso (DeltaR2([j].eta, [j].phi, [t].eta, [t].phi) < 0.04)) select [t]}, AllTracks = {from recoTreeTracks t in [e].Tracks where (([t].pT >= 0.2) AndAlso (DeltaR2([j].eta, [j].phi, [t].eta, [t].phi) < 0.04)) select [t]}}, Weight = (0.242795665783096 * [e].eventWeight)}} where (([j].JetInfo.Jet.pT > 40) AndAlso (Abs([j].JetInfo.Jet.eta) < 2.4)) where ([j].JetInfo.Jet.pT < 400) select new TrainingTree() {Weight = [j].Weight, CalRatio = IIF(([j].JetInfo.Jet.logRatio > 4), 3.99, IIF(([j].JetInfo.Jet.logRatio < -3), -2.99, [j].JetInfo.Jet.logRatio)), JetPt = [j].JetInfo.Jet.pT, JetEta = [j].JetInfo.Jet.eta, NTracks = {[j].JetInfo.Tracks => Count()}, SumPtOfAllTracks = {from recoTreeTracks t in [j].JetInfo.AllTracks select [t].pT => Sum()}, MaxTrackPt = IIF(({[j].JetInfo.AllTracks => Count()} > 0), {from recoTreeTracks t in [j].JetInfo.AllTracks orderby [t].pT desc select [t] => First()}.pT, 0)} => Take(146715)})} select [t].JetPt

 

Cheers,
Gordon

 

Michael Ketting

unread,
Apr 20, 2016, 2:46:11 AM4/20/16
to re-motion Users
Hi Gordon!

There's no code for this yet, just a very old feature request (https://www.re-motion.org/jira/browse/RMLNQ-13) no one's gotten around to. If you're interested in setting up a PR for this... :)

Best regards, Michael

PS to any one listening: Sorry for the delay on the other threads, I haven't really had much brain space left to investigate the compre complicated linq questions these past few days.

Gordon Watts

unread,
Apr 21, 2016, 3:04:25 AM4/21/16
to Michael Ketting, re-motion Users

Hi,

  I will probably end up tackling it at some point, and when I’ve got something that seems to work, I’ll come back tot his thread (or start a new one).

 

  No worries about not getting to this. At some point, just to make sure it doesn’t fall off the radar, there was the cloning of a sub-query expression issue I pointed out. The modification I made to relinq, btw, has held up. And it has had to clone some rather harry looking query models (e.g. like the one below). So I’m now pretty confident of the fix.

 

                Cheers,

                                Gordon.

 

Cheers,
Gordon.

 

From: Michael Ketting
Sent: Tuesday, April 19, 2016 11:46 PM
To: re-motion Users
Subject: [re-motion-users] Re: Pretty printing a query model

 

UnhideWhenUsed="true" QFormat="true" Name="heading 7"/>
--
You received this message because you are subscribed to the Google Groups "re-motion Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to re-motion-use...@googlegroups.com.
To post to this group, send email to re-moti...@googlegroups.com.
Visit this group at https://groups.google.com/group/re-motion-users.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages