sum_code.h
1 #include "sum.h"
2 #include "data.h"
3 
4 
5 template<unsigned int Nunmod, class Unmod, unsigned int Nsum, class Sum, bool Magn>
7  Log<Reco> odinlog(c_label(),"process");
8 
9  // create new view of input data
11 
12  TinyVector<int,Nsum+Nunmod> inshape(indata.shape());
13 
14  TinyVector<int,Nsum> sumshape;
15  for(int i=0; i<int(Nsum); i++) sumshape(i)=inshape(i);
16 
17  TinyVector<int,Nunmod> outshape;
18  for(int i=0; i<int(Nunmod); i++) outshape(i)=inshape(Nsum+i);
19 
20  ODINLOG(odinlog,normalDebug) << "indata.shape()/outshape/sumshape=" << indata.shape() << "/" << outshape << "/" << sumshape << STD_endl;
21 
22  // summed output data with same (padded) shape as input data
23  TinyVector<int,Nsum+Nunmod> outshape_padded=1;
24  for(unsigned int i=0; i<Nunmod; i++) outshape_padded(Nsum+i)=outshape(i);
25 
26 
27  // create domains for retrieving input data from the correct position
28  // initialize unmodified part with outshape
29  TinyVector<int,Nsum+Nunmod> lowin=0;
30  TinyVector<int,Nsum+Nunmod> uppin=outshape_padded-1;
31 
32  TinyVector<int,Nsum+Nunmod> lowout=0;
33  TinyVector<int,Nsum+Nunmod> uppout=outshape_padded-1;
34 
35  // output domain, the same for each dataset
36  RectDomain<Nsum+Nunmod> outdomain(lowout,uppout);
37 
38  ComplexData<Nsum+Nunmod> outdata_padded(outshape_padded); outdata_padded=STD_complex(0.0);
39 
40  for(int isum=0; isum<product(sumshape); isum++) {
41 
42  // create Nsum-dim index from linear index
43  TinyVector<int,Nsum> sumindex=index2extent(sumshape, isum);
44 
45  // set input inidices
46  for(unsigned int i=0; i<Nsum; i++) lowin(i)=uppin(i)=sumindex(i);
47 
48  // sum data
49  RectDomain<Nsum+Nunmod> indomain(lowin,uppin);
50 
51  if(Magn) outdata_padded(outdomain)+=float2real(cabs(indata(indomain)));
52  else outdata_padded(outdomain)+=indata(indomain);
53  }
54 
55  ComplexData<Nunmod> outdata(outshape);
56  outdata_padded.convert_to(outdata); // bring to output shape
57  rd.data(Rank<Nunmod>()).reference(outdata);
58 
59  ODINLOG(odinlog,normalDebug) << " outshape=" << outshape << STD_endl;
60 
61  modify_coord(rd.coord());
62 
63  if(Magn) rd.mode=RecoData::real_data;
64 
65  if(!execute_next_step(rd,controller)) return false;
66 
67  return true;
68 }
dataMode mode
Definition: tjlog.h:218
RecoCoord & coord()
ComplexData< 1 > & data(Rank< 1 >) const
Definition: odinreco/data.h:91
averagesum, cyclesum, repmagnsum, repsum: Sum up data in one or more dimensions
Definition: sum.h:36