within ROOT(similar with c++), put big data into mathematica then get
- To: mathgroup at smc.vnet.net
- Subject: [mg115663] within ROOT(similar with c++), put big data into mathematica then get
- From: junhui Liao <junhui.liaoforothers at gmail.com>
- Date: Tue, 18 Jan 2011 05:46:40 -0500 (EST)
Dear all, I want to interpolate my experimental signals by Mathematica "Sinc" function. My data is in ROOT(OO language similar with C++, actually combined C+ +). There are lots of signals(20k+), and each signal has 4k points. What I want to do is to each signal, do interpolation so I can increase it to 4k*n points(n= ~20). After reading some documents, I still not sure how to organize it. This following is get from mathematica example. ############# Original Mathematica code (Contributed by: Nasser M. Abbasi) ################# (* This is the sinc interpolation formula *) sincInterpolate[Tau_, T_, samples_] := Module[{k}, Sum[samples[[ k ]]*Sinc[Pi/T (Tau - (k - 1) T)], {k, 1, Length[samples]}] ]; (* Do the sinc interpolation sum *) xa = Table[{\[Tau], sincInterpolate[Tau, T, samples]}, {Tau, 0, maxt, sincDeltaTime} ]; ########## End of original Mathematica code ############ Following is my idea, please comment it OK or not. ########## My idea on C++ code ################## Within ROOT(C++). // There are(at least) two strategies to do my interpolation. //1st strategy, put the original data input Mathematica then get results(interpolated ) back to ROOT. SincInterpolate(double* time, double* amp, double*& time_interpolated, double*& amp_interpolated) { //link, env, arg define ..... // Put each signal's 4k points into Mathematica MLPutFunction(lp, "Tranpose", 1); MLPutFunction(lp, "List", 2); MLPutReal64List(lp,time,n+1); // n = length of input array (list). MLPutReal64List(lp, amp, n+1); MLEndPacket(lp); MLPutFunction(lp, "EvaluatePacket", 1); MLPutFunction(lp, "ToExpression",1); //*****Don't know how to code this part yet, right now :-). (* Do the sinc interpolation sum *) xa = Table[{\[Tau], sincInterpolate[Tau, T, samples]}, {Tau, 0, maxt, sincDeltaTime} ]; (* This is the sinc interpolation formula *) MLPutFunction(lp, "sincInterpolate[Tau_, T_, samples_] := Module[{k}, Sum[samples[[ k ]]*Sinc[Pi/T (Tau - (k - 1) T)], {k, 1, Length[samples]}]",3); //End of ***** MLGetReal64List(lp, time_interpolated); MLGetReal64List(lp, amp_interpolated); // 2nd strategy, make a few loops in ROOT, to each element, call mathematica function only when needed. for(i = 0; i< 4k; i++) { for(j = 0; j<J ; j ++) { // J = constant ~= 20. for(k = 0; k< 4k; k++) { amp_interpolated = amp[i]*Sinc((time[i]+T*j/J-time[k])/ T); //J = constant, Sinc is Mathematica funciton ; push_back [amp_interpolated]; } } } But in this case, the loop is huge, 4k*20*4k = 3.2e8. And there are 4k vectors and each vector with length = 4k* 20 = 8.2e4. And these data need to transfer from Mathematic to ROOT. Plus, this is only one signal, I totally have 20k+ signals. So, I worried a little bit this could be very low efficiency. Question 1, I don't know which strategy is better( in efficiency) and is there any better one than these two(like code directly in c++)? Question 2, Could you show some close source data or give some directive on how to code the mathlink part? Many thanks in advance! Junhui