FairRoot/PandaRoot
Public Member Functions | Private Member Functions | Private Attributes | List of all members
PndSdsStripCorrelator Class Reference

#include <PndSdsStripCorrelator.h>

Public Member Functions

 PndSdsStripCorrelator (int mode=0, double cut=0., double noise=0., double threshold=0.)
 
 ~PndSdsStripCorrelator ()
 
void Reset ()
 
void Setup (int mode=0, double cut=0., double noise=0., double threshold=0.)
 
void AddCluster (int moduleId, int side, int clusterIndex, double charge)
 
vector< pair< int, int > > GetCorrelationList ()
 
vector< double > GetProbList ()
 
vector< double > GetSecondProbList ()
 
vector< int > GetMultProbList ()
 

Private Member Functions

void CalcChargeDifferenceCut ()
 
void CalcLikelihoodAlgo ()
 
void CalcAll ()
 
std::vector
< PndSdsStripCorrelatorCombi
getCombinations (std::map< int, std::map< int, PndSdsStripCorrelatorCand > > matrix, int cols, int rows)
 
std::map< int, std::map< int,
PndSdsStripCorrelatorCand > > 
getSubMatrix (std::map< int, std::map< int, PndSdsStripCorrelatorCand > > matrix, int cols, int rows, int pivotCol, int pivotRow)
 

Private Attributes

map< int, map< int, vector
< pair< int, double > > > > 
fClusterList
 
vector< pair< int, int > > fCorrelationList
 
vector< double > fCorrelationProbList
 
vector< double > fSecondProbList
 
vector< int > fMultProbList
 
double fCut
 
double fNoise
 
double fThreshold
 
int fMode
 
bool fCalculated
 

Detailed Description

Definition at line 59 of file PndSdsStripCorrelator.h.

Constructor & Destructor Documentation

PndSdsStripCorrelator::PndSdsStripCorrelator ( int  mode = 0,
double  cut = 0.,
double  noise = 0.,
double  threshold = 0. 
)

Definition at line 19 of file PndSdsStripCorrelator.cxx.

19  :
20  fClusterList(),
24  fMultProbList(),
25  fCut(cut),
26  fNoise(noise),
28  fMode(mode),
29  fCalculated(false)
30 {}
vector< double > fSecondProbList
map< int, map< int, vector< pair< int, double > > > > fClusterList
vector< double > fCorrelationProbList
double cut[MAX]
Definition: autocutx.C:36
Int_t mode
Definition: autocutx.C:47
vector< pair< int, int > > fCorrelationList
double threshold
double noise
PndSdsStripCorrelator::~PndSdsStripCorrelator ( )

Definition at line 33 of file PndSdsStripCorrelator.cxx.

33 {}

Member Function Documentation

void PndSdsStripCorrelator::AddCluster ( int  moduleId,
int  side,
int  clusterIndex,
double  charge 
)

Definition at line 36 of file PndSdsStripCorrelator.cxx.

References fClusterList.

37 {
38  fClusterList[moduleId][side].push_back(make_pair(clusterIndex,charge));
39 }
map< int, map< int, vector< pair< int, double > > > > fClusterList
void PndSdsStripCorrelator::CalcAll ( )
private

Definition at line 117 of file PndSdsStripCorrelator.cxx.

References CalcChargeDifferenceCut(), and fCut.

Referenced by GetCorrelationList().

118 {
119  double oldcut = fCut;
120  fCut=0.;
122  fCut=oldcut;
123 }
void PndSdsStripCorrelator::CalcChargeDifferenceCut ( )
private

Definition at line 126 of file PndSdsStripCorrelator.cxx.

References fabs(), fClusterList, fCorrelationList, fCorrelationProbList, fCut, fSecondProbList, and map.

Referenced by CalcAll(), and GetCorrelationList().

127 {
128  double dq=0;
129  fCorrelationList.clear();
130  for (map<int,map<int,vector<pair<int,double> > > >::iterator modIt=fClusterList.begin(); modIt!=fClusterList.end(); ++modIt)
131  {
132  for (vector<pair<int,double> >::iterator topIt = modIt->second[0].begin(); topIt != modIt->second[0].end(); ++topIt)
133  {
134  for (vector<pair<int,double> >::iterator botIt = modIt->second[1].begin(); botIt != modIt->second[1].end(); ++botIt)
135  {
136  dq=fabs((*topIt).second - (*botIt).second);
137  if (dq<fCut)
138  {
139  fCorrelationList.push_back(make_pair((*topIt).first,(*botIt).first));
140  fCorrelationProbList.push_back( (dq>5e4) ? 0 : (1 - 2e-5*dq) );
141  fSecondProbList.push_back( -1 );
142  }
143  }
144  }
145  }
146 }
PndTransMap * map
Definition: sim_emc_apd.C:99
vector< double > fSecondProbList
map< int, map< int, vector< pair< int, double > > > > fClusterList
vector< double > fCorrelationProbList
vector< pair< int, int > > fCorrelationList
friend F32vec4 fabs(const F32vec4 &a)
Definition: P4_F32vec4.h:47
void PndSdsStripCorrelator::CalcLikelihoodAlgo ( )
private

Definition at line 149 of file PndSdsStripCorrelator.cxx.

References CLUSTER_MULT_CUTOFF, fabs(), fClusterList, fCorrelationList, fCorrelationProbList, fMultProbList, fSecondProbList, fThreshold, getCombinations(), map, sqrt(), and top.

Referenced by GetCorrelationList().

150 {
151  //per sensor module fill a combinations matrix, calculate likelihoods, assign b
152 
153  fCorrelationList.clear();
154  for (map<int,map<int,vector<pair<int,double> > > >::iterator modIt=fClusterList.begin(); modIt!=fClusterList.end(); ++modIt)
155  {
156  if (modIt->second[0].size()>CLUSTER_MULT_CUTOFF) continue; // skip modules with too busy events
157  if (modIt->second[1].size()>CLUSTER_MULT_CUTOFF) continue; // skip modules with too busy events
158  //fill matrix
159  std::map<int,std::map<int,PndSdsStripCorrelatorCand> > matrix;
160  double top_total=0.,wert=0.;
161  int nTop=0, nBot=0, iBot=0; //,iTop=-1,iBot=-1;
162  for (vector<pair<int,double> >::iterator topIt = modIt->second[0].begin(); topIt != modIt->second[0].end(); ++topIt)
163  {
164  for (vector<pair<int,double> >::iterator botIt = modIt->second[1].begin(); botIt != modIt->second[1].end(); ++botIt)
165  {
166  wert = (*topIt).second - (*botIt).second;
167  // wert *= wert;
168  // top_total += wert;
169  top_total += wert*wert;
170  wert = erfc(fabs(wert)/(2.*fThreshold)/sqrt(2.)); // [R.K.31.7.'12]
171  //wert = erfc(fabs(wert)/(6.*fNoise)/sqrt(2.)); // original
172  matrix[nTop][iBot]=PndSdsStripCorrelatorCand((*topIt).first,(*botIt).first,(*topIt).second,(*botIt).second,wert);
173  //printf("add to matrix: t=%i, b=%i, qt=%f, qb=%f, p=%f \n",(*topIt).first,(*botIt).first,(*topIt).second,(*botIt).second,wert);
174  iBot++;
175  }
176  if(iBot>nBot)nBot=iBot;
177  iBot=0;
178  nTop++;
179  }
180 
181  // Calculate combinations
182  std::vector<PndSdsStripCorrelatorCombi> combinations = getCombinations(matrix,nTop,nBot);
183 
184  if(combinations.size()==0) continue; //next module
185 
186  //select the lowest probability
187  double klein=-1.,ganzklein=-1.;
188  int who=-1, whoelse=-1;
189 
190  for(int like=0;like<(int)combinations.size();like++)
191  {
192  if(combinations[like].prob>klein)
193  {
194  if(combinations[like].prob>ganzklein)
195  {
196  klein=ganzklein;
197  whoelse=who;
198  ganzklein=combinations[like].prob;
199  who=like;
200  }
201  else
202  {
203  klein=combinations[like].prob;
204  whoelse=like;
205  }
206  }
207  }
208  // if(combinations[who].prob>fCut)
209  // { // index pairs for the output
210  for (int kk=0; kk<(int)combinations[who].pairlist.size(); ++kk)
211  {
212  fCorrelationList.push_back(make_pair(combinations[who].pairlist[kk].top,combinations[who].pairlist[kk].bot));
213  //printf("add correlation [%i|%i] p=%f \n",combinations[who].pairlist[kk].top,combinations[who].pairlist[kk].bot,combinations[who].prob);
214  fCorrelationProbList.push_back(combinations[who].prob);
215  if(whoelse>=0) fSecondProbList.push_back(combinations[whoelse].prob);
216  else fSecondProbList.push_back(-1.);
217  fMultProbList.push_back(combinations.size());
218  }
219  // }
220  }
221 }
PndTransMap * map
Definition: sim_emc_apd.C:99
friend F32vec4 sqrt(const F32vec4 &a)
Definition: P4_F32vec4.h:29
vector< double > fSecondProbList
map< int, map< int, vector< pair< int, double > > > > fClusterList
TGeoVolume * top
vector< double > fCorrelationProbList
vector< pair< int, int > > fCorrelationList
friend F32vec4 fabs(const F32vec4 &a)
Definition: P4_F32vec4.h:47
#define CLUSTER_MULT_CUTOFF
std::vector< PndSdsStripCorrelatorCombi > getCombinations(std::map< int, std::map< int, PndSdsStripCorrelatorCand > > matrix, int cols, int rows)
std::vector< PndSdsStripCorrelatorCombi > PndSdsStripCorrelator::getCombinations ( std::map< int, std::map< int, PndSdsStripCorrelatorCand > >  matrix,
int  cols,
int  rows 
)
private

Definition at line 226 of file PndSdsStripCorrelator.cxx.

References cols, combi, fabs(), fThreshold, getSubMatrix(), i, PndSdsStripCorrelatorCombi::pairlist, PndSdsStripCorrelatorCombi::prob, sqrt(), and top.

Referenced by CalcLikelihoodAlgo().

227 {
228  //printf("getCombinations: Matrix(%i,%i) \n",cols,rows);
229  std::vector<PndSdsStripCorrelatorCombi> combinations;
230  if (cols==1 && rows==1) {
232  combi.pairlist.push_back(PndSdsStripCorrelatorCand(matrix[0][0]));
233  combi.prob=matrix[0][0].prob;
234  combinations.push_back(combi);
235  return combinations;
236  }
237  if (cols==1) {
239  double q_t[rows];
240  double bsum=0.;
241  for (int i=0; i< rows; i++) bsum+=matrix[0][i].q_bot;
242  for (int i=0; i< rows; i++) q_t[i]=matrix[0][0].q_top - bsum + matrix[0][i].q_bot;
243  //double tot=0.; //unused?
244  //double diag=0.; //unused?
245  for (int i=0; i< rows; i++)
246  {
247  combi.pairlist.push_back(PndSdsStripCorrelatorCand(matrix[0][i].top,matrix[0][i].bot,q_t[i],matrix[0][i].q_bot,matrix[0][i].prob));
248  combi.prob*=erfc(fabs(q_t[i]-matrix[0][i].q_bot)/(2.*fThreshold*sqrt(2.)));// [R.K.31.7.'12]
249  //combi.prob*=erfc(fabs(q_t[i]-matrix[0][i].q_bot)/(6.*fNoise*sqrt(2.)));//original
250  }
251  double prob_full=combi.prob;
252  combinations.push_back(combi);
253  //double _maxprob = combi.prob; //unused?
254  //int _maxcombi = 0; //unused?
255  for (int i=0; i<rows; ++i)
256  { // Recursive call
257  std::vector<PndSdsStripCorrelatorCombi> combilist_reduced=getCombinations(getSubMatrix(matrix,1,rows,-1,i),1,rows-1);
258  for (int ii=0; ii<(int)combilist_reduced.size(); ii++)
259  {
260  combilist_reduced[ii].prob*=(1.-prob_full);
261  }
262  combinations.insert(combinations.end(),combilist_reduced.begin(),combilist_reduced.end());
263  }
264  return combinations;
265  }
266  if (rows==1) {
268  double q_b[cols];
269  double tsum=0.;
270  for (int i=0; i< cols; i++) tsum+=matrix[i][0].q_top;
271  for (int i=0; i< cols; i++) q_b[i]=matrix[0][0].q_bot - tsum + matrix[i][0].q_top;
272  //double tot=0.; //unused?
273  //double diag=0.; //unused?
274  for (int i=0; i< cols; i++)
275  {
276  combi.pairlist.push_back(PndSdsStripCorrelatorCand(matrix[i][0].top,matrix[i][0].bot,matrix[i][0].q_top,q_b[i],matrix[i][0].prob));
277  combi.prob*=erfc(fabs(matrix[i][0].q_top-q_b[i])/(2.*fThreshold*sqrt(2.)));// [R.K.31.7.'12]
278  //combi.prob*=erfc(fabs(matrix[i][0].q_top-q_b[i])/(6.*fNoise*sqrt(2.)));//original
279  }
280  double prob_full=combi.prob;
281  combinations.push_back(combi);
282  //double _maxprob = combi.prob; //unused?
283  //int _maxcombi = 0; //unused?
284  for (int i=0; i<cols; ++i)
285  { // Recursive call
286  std::vector<PndSdsStripCorrelatorCombi> combilist_reduced=getCombinations(getSubMatrix(matrix,cols,1,i,-1),cols-1,1);
287  for (int ii=0; ii<(int)combilist_reduced.size(); ii++)
288  {
289  combilist_reduced[ii].prob*=(1.-prob_full);
290  }
291  combinations.insert(combinations.end(),combilist_reduced.begin(),combilist_reduced.end());
292  }
293  return combinations;
294  }
295  // treat 2x2 matrix as separate case since the nr. of independent combinations is just half of the nr. of possible combinations
296  if (rows==2 && cols==2) {
299  combi1.prob=1.;
300  combi2.prob=1.;
301  combi1.pairlist.push_back(PndSdsStripCorrelatorCand(matrix[0][0]));
302  combi1.prob*=matrix[0][0].prob;
303  combi1.pairlist.push_back(PndSdsStripCorrelatorCand(matrix[1][1]));
304  combi1.prob*=matrix[1][1].prob;
305  combi2.pairlist.push_back(PndSdsStripCorrelatorCand(matrix[1][0]));
306  combi2.prob*=matrix[1][0].prob;
307  combi2.pairlist.push_back(PndSdsStripCorrelatorCand(matrix[0][1]));
308  combi2.prob*=matrix[0][1].prob;
309  combinations.push_back(combi1);
310  combinations.push_back(combi2);
311  return combinations;
312  }
313  for (int i=0; i<cols; i++) {
314  for (int j=0; j<rows; j++)
315  { // Recursive call
316  std::vector<PndSdsStripCorrelatorCombi> combilist=getCombinations(getSubMatrix(matrix,cols,rows,i,j),cols-1,rows-1);
317  for (int k=0; k<(int)combilist.size(); k++) {
318  combilist[k].pairlist.push_back(PndSdsStripCorrelatorCand(matrix[i][j]));
319  combilist[k].prob*=matrix[i][j].prob;
320  combinations.push_back(PndSdsStripCorrelatorCombi(combilist[k].pairlist,combilist[k].prob));
321  }
322  }
323  }
324  return combinations;
325 }
Int_t i
Definition: run_full.C:25
friend F32vec4 sqrt(const F32vec4 &a)
Definition: P4_F32vec4.h:29
TGeoVolume * top
std::map< int, std::map< int, PndSdsStripCorrelatorCand > > getSubMatrix(std::map< int, std::map< int, PndSdsStripCorrelatorCand > > matrix, int cols, int rows, int pivotCol, int pivotRow)
int cols[10]
Definition: evaltrig.C:69
TGeoCombiTrans * combi
friend F32vec4 fabs(const F32vec4 &a)
Definition: P4_F32vec4.h:47
std::vector< PndSdsStripCorrelatorCand > pairlist
std::vector< PndSdsStripCorrelatorCombi > getCombinations(std::map< int, std::map< int, PndSdsStripCorrelatorCand > > matrix, int cols, int rows)
vector< pair< int, int > > PndSdsStripCorrelator::GetCorrelationList ( )

Definition at line 63 of file PndSdsStripCorrelator.cxx.

References CalcAll(), CalcChargeDifferenceCut(), CalcLikelihoodAlgo(), fCalculated, fCorrelationList, and fMode.

64 {
65  if(!fCalculated)
66  {
67  switch (fMode) {
68  case 0:
70  break;
71  case 1:
73  break;
74  default:
75  CalcAll();
76  break;
77  }
78  fCalculated=true;
79  }
80  return fCorrelationList;
81 }
vector< pair< int, int > > fCorrelationList
vector< int > PndSdsStripCorrelator::GetMultProbList ( )

Definition at line 106 of file PndSdsStripCorrelator.cxx.

References fCalculated, fCorrelationProbList, fMultProbList, and fSecondProbList.

107 {
108  if(!fCalculated){
109  fCorrelationProbList.clear(); // empty on invalid state, just in case
110  fSecondProbList.clear(); // empty on invalid state, just in case
111  fMultProbList.clear(); // empty on invalid state, just in case
112  }
113  return fMultProbList;
114 }
vector< double > fSecondProbList
vector< double > fCorrelationProbList
vector< double > PndSdsStripCorrelator::GetProbList ( )

Definition at line 84 of file PndSdsStripCorrelator.cxx.

References fCalculated, fCorrelationProbList, fMultProbList, and fSecondProbList.

85 {
86  if(!fCalculated){
87  fCorrelationProbList.clear(); // empty on invalid state, just in case
88  fSecondProbList.clear(); // empty on invalid state, just in case
89  fMultProbList.clear(); // empty on invalid state, just in case
90  }
91  return fCorrelationProbList;
92 }
vector< double > fSecondProbList
vector< double > fCorrelationProbList
vector< double > PndSdsStripCorrelator::GetSecondProbList ( )

Definition at line 95 of file PndSdsStripCorrelator.cxx.

References fCalculated, fCorrelationProbList, fMultProbList, and fSecondProbList.

96 {
97  if(!fCalculated){
98  fCorrelationProbList.clear(); // empty on invalid state, just in case
99  fSecondProbList.clear(); // empty on invalid state, just in case
100  fMultProbList.clear(); // empty on invalid state, just in case
101  }
102  return fSecondProbList;
103 }
vector< double > fSecondProbList
vector< double > fCorrelationProbList
std::map< int, std::map< int, PndSdsStripCorrelatorCand > > PndSdsStripCorrelator::getSubMatrix ( std::map< int, std::map< int, PndSdsStripCorrelatorCand > >  matrix,
int  cols,
int  rows,
int  pivotCol,
int  pivotRow 
)
private

Definition at line 329 of file PndSdsStripCorrelator.cxx.

References cols, i, and jj.

Referenced by getCombinations().

330 {
331  std::map<int,std::map<int,PndSdsStripCorrelatorCand> > result;
332  int ii=0;
333  for (int i=0; i<cols;i++)
334  {
335  if (i==pivotCol) continue;
336  int jj=0;
337  for (int j=0; j<rows; j++)
338  {
339  result[ii][jj]=matrix[i][j];
340  if (j==pivotRow) continue;
341  jj++;
342  }
343  ii++;
344  }
345  return result;
346 }
Int_t i
Definition: run_full.C:25
int cols[10]
Definition: evaltrig.C:69
void PndSdsStripCorrelator::Reset ( )

Definition at line 42 of file PndSdsStripCorrelator.cxx.

References fCalculated, fClusterList, fCorrelationList, fCorrelationProbList, fMultProbList, and fSecondProbList.

43 {
44  fClusterList.clear();
45  fCorrelationList.clear();
46  fCorrelationProbList.clear();
47  fSecondProbList.clear();
48  fMultProbList.clear();
49  fCalculated=false;
50 }
vector< double > fSecondProbList
map< int, map< int, vector< pair< int, double > > > > fClusterList
vector< double > fCorrelationProbList
vector< pair< int, int > > fCorrelationList
void PndSdsStripCorrelator::Setup ( int  mode = 0,
double  cut = 0.,
double  noise = 0.,
double  threshold = 0. 
)

Definition at line 53 of file PndSdsStripCorrelator.cxx.

References cut, fCalculated, fCut, fMode, fNoise, fThreshold, mode, noise, and threshold.

Member Data Documentation

bool PndSdsStripCorrelator::fCalculated
private
map<int,map<int,vector<pair<int,double> > > > PndSdsStripCorrelator::fClusterList
private
vector<pair<int,int> > PndSdsStripCorrelator::fCorrelationList
private
vector<double> PndSdsStripCorrelator::fCorrelationProbList
private
double PndSdsStripCorrelator::fCut
private

Definition at line 91 of file PndSdsStripCorrelator.h.

Referenced by CalcAll(), CalcChargeDifferenceCut(), and Setup().

int PndSdsStripCorrelator::fMode
private

Definition at line 94 of file PndSdsStripCorrelator.h.

Referenced by GetCorrelationList(), and Setup().

vector<int> PndSdsStripCorrelator::fMultProbList
private
double PndSdsStripCorrelator::fNoise
private

Definition at line 92 of file PndSdsStripCorrelator.h.

Referenced by Setup().

vector<double> PndSdsStripCorrelator::fSecondProbList
private
double PndSdsStripCorrelator::fThreshold
private

Definition at line 93 of file PndSdsStripCorrelator.h.

Referenced by CalcLikelihoodAlgo(), getCombinations(), and Setup().


The documentation for this class was generated from the following files: