CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MuonResidualsTwoBin.h
Go to the documentation of this file.
1 #ifndef Alignment_MuonAlignmentAlgorithms_MuonResidualsTwoBin_H
2 #define Alignment_MuonAlignmentAlgorithms_MuonResidualsTwoBin_H
3 
13 #include "TMath.h"
14 
16 public:
19  if (m_pos != NULL) delete m_pos;
20  if (m_neg != NULL) delete m_neg;
21  };
22 
23  int residualsModel() const { assert(m_pos->residualsModel() == m_neg->residualsModel()); return m_pos->residualsModel(); };
24  long numResidualsPos() const { return m_pos->numResiduals(); };
25  long numResidualsNeg() const { return m_neg->numResiduals(); };
26  int npar() { assert(m_pos->npar() == m_neg->npar()); return m_pos->npar(); };
27  int ndata() { assert(m_pos->ndata() == m_neg->ndata()); return m_pos->ndata(); };
28  int type() const { assert(m_pos->type() == m_neg->type()); return m_pos->type(); };
29 
30  void fix(int parNum, bool value=true) {
31  m_pos->fix(parNum, value);
32  m_neg->fix(parNum, value);
33  };
34 
35  bool fixed(int parNum) {
36  return m_pos->fixed(parNum) && m_neg->fixed(parNum);
37  };
38 
39  void setPrintLevel(int printLevel) const {
40  m_pos->setPrintLevel(printLevel);
41  m_neg->setPrintLevel(printLevel);
42  }
43 
44  void setStrategy(int strategy) const {
45  m_pos->setStrategy(strategy);
46  m_neg->setStrategy(strategy);
47  }
48 
49  void fill(char charge, double *residual) {
50  if (!m_twoBin || charge > 0) m_pos->fill(residual);
51  else m_neg->fill(residual);
52  };
53 
54  bool fit(Alignable *ali) {
55  return (m_twoBin ? (m_pos->fit(ali) && m_neg->fit(ali)) : m_pos->fit(ali));
56  };
57  double value(int parNum) {
58  return (m_twoBin ? ((m_pos->value(parNum) + m_neg->value(parNum)) / 2.) : m_pos->value(parNum));
59  };
60  double errorerror(int parNum) {
61  return (m_twoBin ? (sqrt(pow(m_pos->errorerror(parNum), 2.) + pow(m_neg->errorerror(parNum), 2.)) / 2.) : m_pos->errorerror(parNum));
62  };
63  double antisym(int parNum) {
64  return (m_twoBin ? ((m_pos->value(parNum) - m_neg->value(parNum)) / 2.) : 0.);
65  };
66  double loglikelihood() {
68  };
69  double numsegments() {
70  return (m_twoBin ? (m_pos->numsegments() + m_neg->numsegments()) : m_pos->numsegments());
71  };
72  double sumofweights() {
74  };
75 
76  // demonstration plots
77  double plot(std::string name, TFileDirectory *dir, Alignable *ali) {
78  if (m_twoBin) {
79  std::string namePos = name + std::string("Pos");
80  std::string nameNeg = name + std::string("Neg");
81  double output = 0.;
82  output += m_pos->plot(namePos, dir, ali);
83  output += m_neg->plot(nameNeg, dir, ali);
84  return output;
85  }
86  else {
87  return m_pos->plot(name, dir, ali);
88  }
89  };
90 
91  // I/O of temporary files for collect mode
92  void write(FILE *file, int which=0) {
93  if (m_twoBin) {
94  m_pos->write(file, 2*which);
95  m_neg->write(file, 2*which + 1);
96  }
97  else {
98  m_pos->write(file, which);
99  }
100  };
101  void read(FILE *file, int which=0) {
102  if (m_twoBin) {
103  m_pos->read(file, 2*which);
104  m_neg->read(file, 2*which + 1);
105  }
106  else {
107  m_pos->read(file, which);
108  }
109  };
110 
111  double median(int which) {
112  std::vector<double> residuals;
113  for (std::vector<double*>::const_iterator r = residualsPos_begin(); r != residualsPos_end(); ++r) {
114  residuals.push_back((*r)[which]);
115  }
116  if (m_twoBin) {
117  for (std::vector<double*>::const_iterator r = residualsNeg_begin(); r != residualsNeg_end(); ++r) {
118  residuals.push_back((*r)[which]);
119  }
120  }
121  std::sort(residuals.begin(), residuals.end());
122  int length = residuals.size();
123  return residuals[length/2];
124  };
125 
126  double mean(int which, double truncate) {
127  double sum = 0.;
128  double n = 0.;
129  for (std::vector<double*>::const_iterator r = residualsPos_begin(); r != residualsPos_end(); ++r) {
130  double value = (*r)[which];
131  if (fabs(value) < truncate) {
132  sum += value;
133  n += 1.;
134  }
135  }
136  if (m_twoBin) {
137  for (std::vector<double*>::const_iterator r = residualsNeg_begin(); r != residualsNeg_end(); ++r) {
138  double value = (*r)[which];
139  if (fabs(value) < truncate) {
140  sum += value;
141  n += 1.;
142  }
143  }
144  }
145  return sum/n;
146  };
147 
148  double wmean(int which, int whichredchi2, double truncate) {
149  double sum = 0.;
150  double n = 0.;
151  for (std::vector<double*>::const_iterator r = residualsPos_begin(); r != residualsPos_end(); ++r) {
152  double value = (*r)[which];
153  if (fabs(value) < truncate) {
154  double weight = 1./(*r)[whichredchi2];
155  if (TMath::Prob(1./weight*12, 12) < 0.99) {
156  sum += weight*value;
157  n += weight;
158  }
159  }
160  }
161  if (m_twoBin) {
162  for (std::vector<double*>::const_iterator r = residualsNeg_begin(); r != residualsNeg_end(); ++r) {
163  double value = (*r)[which];
164  if (fabs(value) < truncate) {
165  double weight = 1./(*r)[whichredchi2];
166  if (TMath::Prob(1./weight*12, 12) < 0.99) {
167  sum += weight*value;
168  n += weight;
169  }
170  }
171  }
172  }
173  return sum/n;
174  };
175 
176  double stdev(int which, double truncate) {
177  double sum2 = 0.;
178  double sum = 0.;
179  double n = 0.;
180  for (std::vector<double*>::const_iterator r = residualsPos_begin(); r != residualsPos_end(); ++r) {
181  double value = (*r)[which];
182  if (fabs(value) < truncate) {
183  sum2 += value*value;
184  sum += value;
185  n += 1.;
186  }
187  }
188  if (m_twoBin) {
189  for (std::vector<double*>::const_iterator r = residualsNeg_begin(); r != residualsNeg_end(); ++r) {
190  double value = (*r)[which];
191  if (fabs(value) < truncate) {
192  sum2 += value*value;
193  sum += value;
194  n += 1.;
195  }
196  }
197  }
198  return sqrt(sum2/n - pow(sum/n, 2));
199  };
200 
201  void plotsimple(std::string name, TFileDirectory *dir, int which, double multiplier) {
202  if (m_twoBin) {
203  std::string namePos = name + std::string("Pos");
204  std::string nameNeg = name + std::string("Neg");
205  m_pos->plotsimple(namePos, dir, which, multiplier);
206  m_neg->plotsimple(nameNeg, dir, which, multiplier);
207  }
208  else {
209  m_pos->plotsimple(name, dir, which, multiplier);
210  }
211  };
212 
213  void plotweighted(std::string name, TFileDirectory *dir, int which, int whichredchi2, double multiplier) {
214  if (m_twoBin) {
215  std::string namePos = name + std::string("Pos");
216  std::string nameNeg = name + std::string("Neg");
217  m_pos->plotweighted(namePos, dir, which, whichredchi2, multiplier);
218  m_neg->plotweighted(nameNeg, dir, which, whichredchi2, multiplier);
219  }
220  else {
221  m_pos->plotweighted(name, dir, which, whichredchi2, multiplier);
222  }
223  };
224 
225  std::vector<double*>::const_iterator residualsPos_begin() const { return m_pos->residuals_begin(); };
226  std::vector<double*>::const_iterator residualsPos_end() const { return m_pos->residuals_end(); };
227  std::vector<double*>::const_iterator residualsNeg_begin() const { return m_neg->residuals_begin(); };
228  std::vector<double*>::const_iterator residualsNeg_end() const { return m_neg->residuals_end(); };
229 
230 protected:
231  bool m_twoBin;
233 };
234 
235 #endif // Alignment_MuonAlignmentAlgorithms_MuonResidualsTwoBin_H
double value(int parNum)
double wmean(int which, int whichredchi2, double truncate)
MuonResidualsFitter * m_neg
MuonResidualsFitter * m_pos
void fill(char charge, double *residual)
std::vector< double * >::const_iterator residualsPos_end() const
void write(FILE *file, int which=0)
long numResiduals() const
void fix(int parNum, bool value=true)
virtual int npar()=0
list file
Definition: dbtoweb.py:253
std::vector< double * >::const_iterator residualsNeg_end() const
void read(FILE *file, int which=0)
void setPrintLevel(int printLevel) const
long numResidualsPos() const
double stdev(int which, double truncate)
virtual bool fit(Alignable *ali)=0
void fill(double *residual)
#define NULL
Definition: scimark2.h:8
double value(int parNum)
double charge(const std::vector< uint8_t > &Ampls)
bool fixed(int parNum)
T sqrt(T t)
Definition: SSEVec.h:28
void plotweighted(std::string name, TFileDirectory *dir, int which, int whichredchi2, double multiplier)
void write(FILE *file, int which=0)
double mean(int which, double truncate)
bool fit(Alignable *ali)
virtual double plot(std::string name, TFileDirectory *dir, Alignable *ali)=0
std::vector< double * >::const_iterator residualsNeg_begin() const
double antisym(int parNum)
MuonResidualsTwoBin(bool twoBin, MuonResidualsFitter *pos, MuonResidualsFitter *neg)
tuple twoBin
Definition: align_cfg.py:23
void plotsimple(std::string name, TFileDirectory *dir, int which, double multiplier)
void setStrategy(int strategy) const
virtual int ndata()=0
void setStrategy(int strategy)
virtual double sumofweights()=0
double errorerror(int parNum)
void read(FILE *file, int which=0)
std::vector< double * >::const_iterator residuals_end() const
long numResidualsNeg() const
void plotweighted(std::string name, TFileDirectory *dir, int which, int whichredchi2, double multiplier)
double errorerror(int parNum)
void plotsimple(std::string name, TFileDirectory *dir, int which, double multiplier)
dbl *** dir
Definition: mlp_gen.cc:35
std::vector< double * >::const_iterator residualsPos_begin() const
void setPrintLevel(int printLevel)
std::vector< double * >::const_iterator residuals_begin() const
virtual int type() const =0
double plot(std::string name, TFileDirectory *dir, Alignable *ali)
void fix(int parNum, bool value=true)
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
bool fixed(int parNum)
double median(int which)