CMS 3D CMS Logo

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 != nullptr) delete m_pos;
20  if (m_neg != nullptr) 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  int useRes() const { return m_pos->useRes(); };
30 
31  void fix(int parNum, bool value=true) {
32  m_pos->fix(parNum, value);
33  m_neg->fix(parNum, value);
34  };
35 
36  bool fixed(int parNum) {
37  return m_pos->fixed(parNum) && m_neg->fixed(parNum);
38  };
39 
40  void setPrintLevel(int printLevel) const {
41  m_pos->setPrintLevel(printLevel);
42  m_neg->setPrintLevel(printLevel);
43  }
44 
45  void setStrategy(int strategy) const {
46  m_pos->setStrategy(strategy);
47  m_neg->setStrategy(strategy);
48  }
49 
50  void fill(char charge, double *residual) {
51  if (!m_twoBin || charge > 0) m_pos->fill(residual);
52  else m_neg->fill(residual);
53  };
54 
55  bool fit(Alignable *ali) {
56  return (m_twoBin ? (m_pos->fit(ali) && m_neg->fit(ali)) : m_pos->fit(ali));
57  };
58  double value(int parNum) {
59  return (m_twoBin ? ((m_pos->value(parNum) + m_neg->value(parNum)) / 2.) : m_pos->value(parNum));
60  };
61  double errorerror(int parNum) {
62  return (m_twoBin ? (sqrt(pow(m_pos->errorerror(parNum), 2.) + pow(m_neg->errorerror(parNum), 2.)) / 2.) : m_pos->errorerror(parNum));
63  };
64  double antisym(int parNum) {
65  return (m_twoBin ? ((m_pos->value(parNum) - m_neg->value(parNum)) / 2.) : 0.);
66  };
67  double loglikelihood() {
69  };
70  double numsegments() {
71  return (m_twoBin ? (m_pos->numsegments() + m_neg->numsegments()) : m_pos->numsegments());
72  };
73  double sumofweights() {
75  };
76 
77  // demonstration plots
79  if (m_twoBin) {
80  std::string namePos = name + std::string("Pos");
81  std::string nameNeg = name + std::string("Neg");
82  double output = 0.;
83  output += m_pos->plot(namePos, dir, ali);
84  output += m_neg->plot(nameNeg, dir, ali);
85  return output;
86  }
87  else {
88  return m_pos->plot(name, dir, ali);
89  }
90  };
91 
92  // I/O of temporary files for collect mode
93  void write(FILE *file, int which=0) {
94  if (m_twoBin) {
95  m_pos->write(file, 2*which);
96  m_neg->write(file, 2*which + 1);
97  }
98  else {
99  m_pos->write(file, which);
100  }
101  };
102  void read(FILE *file, int which=0) {
103  if (m_twoBin) {
104  m_pos->read(file, 2*which);
105  m_neg->read(file, 2*which + 1);
106  }
107  else {
108  m_pos->read(file, which);
109  }
110  };
111 
112  double median(int which) {
113  std::vector<double> residuals;
114  for (std::vector<double*>::const_iterator r = residualsPos_begin(); r != residualsPos_end(); ++r) {
115  residuals.push_back((*r)[which]);
116  }
117  if (m_twoBin) {
118  for (std::vector<double*>::const_iterator r = residualsNeg_begin(); r != residualsNeg_end(); ++r) {
119  residuals.push_back((*r)[which]);
120  }
121  }
122  std::sort(residuals.begin(), residuals.end());
123  int length = residuals.size();
124  return residuals[length/2];
125  };
126 
127  double mean(int which, double truncate) {
128  double sum = 0.;
129  double n = 0.;
130  for (std::vector<double*>::const_iterator r = residualsPos_begin(); r != residualsPos_end(); ++r) {
131  double value = (*r)[which];
132  if (fabs(value) < truncate) {
133  sum += value;
134  n += 1.;
135  }
136  }
137  if (m_twoBin) {
138  for (std::vector<double*>::const_iterator r = residualsNeg_begin(); r != residualsNeg_end(); ++r) {
139  double value = (*r)[which];
140  if (fabs(value) < truncate) {
141  sum += value;
142  n += 1.;
143  }
144  }
145  }
146  return sum/n;
147  };
148 
149  double wmean(int which, int whichredchi2, double truncate) {
150  double sum = 0.;
151  double n = 0.;
152  for (std::vector<double*>::const_iterator r = residualsPos_begin(); r != residualsPos_end(); ++r) {
153  double value = (*r)[which];
154  if (fabs(value) < truncate) {
155  double weight = 1./(*r)[whichredchi2];
156  if (TMath::Prob(1./weight*12, 12) < 0.99) {
157  sum += weight*value;
158  n += weight;
159  }
160  }
161  }
162  if (m_twoBin) {
163  for (std::vector<double*>::const_iterator r = residualsNeg_begin(); r != residualsNeg_end(); ++r) {
164  double value = (*r)[which];
165  if (fabs(value) < truncate) {
166  double weight = 1./(*r)[whichredchi2];
167  if (TMath::Prob(1./weight*12, 12) < 0.99) {
168  sum += weight*value;
169  n += weight;
170  }
171  }
172  }
173  }
174  return sum/n;
175  };
176 
177  double stdev(int which, double truncate) {
178  double sum2 = 0.;
179  double sum = 0.;
180  double n = 0.;
181  for (std::vector<double*>::const_iterator r = residualsPos_begin(); r != residualsPos_end(); ++r) {
182  double value = (*r)[which];
183  if (fabs(value) < truncate) {
184  sum2 += value*value;
185  sum += value;
186  n += 1.;
187  }
188  }
189  if (m_twoBin) {
190  for (std::vector<double*>::const_iterator r = residualsNeg_begin(); r != residualsNeg_end(); ++r) {
191  double value = (*r)[which];
192  if (fabs(value) < truncate) {
193  sum2 += value*value;
194  sum += value;
195  n += 1.;
196  }
197  }
198  }
199  return sqrt(sum2/n - pow(sum/n, 2));
200  };
201 
202  void plotsimple(std::string name, TFileDirectory *dir, int which, double multiplier) {
203  if (m_twoBin) {
204  std::string namePos = name + std::string("Pos");
205  std::string nameNeg = name + std::string("Neg");
206  m_pos->plotsimple(namePos, dir, which, multiplier);
207  m_neg->plotsimple(nameNeg, dir, which, multiplier);
208  }
209  else {
210  m_pos->plotsimple(name, dir, which, multiplier);
211  }
212  };
213 
214  void plotweighted(std::string name, TFileDirectory *dir, int which, int whichredchi2, double multiplier) {
215  if (m_twoBin) {
216  std::string namePos = name + std::string("Pos");
217  std::string nameNeg = name + std::string("Neg");
218  m_pos->plotweighted(namePos, dir, which, whichredchi2, multiplier);
219  m_neg->plotweighted(nameNeg, dir, which, whichredchi2, multiplier);
220  }
221  else {
222  m_pos->plotweighted(name, dir, which, whichredchi2, multiplier);
223  }
224  };
225 
226  void selectPeakResiduals(double nsigma, int nvar, int *vars)
227  {
228  if (m_twoBin) {
229  m_pos->selectPeakResiduals(nsigma, nvar, vars);
230  m_neg->selectPeakResiduals(nsigma, nvar, vars);
231  }
232  else {
233  m_pos->selectPeakResiduals(nsigma, nvar, vars);
234  }
235  }
236 
238  {
239  m_pos->correctBField();
240  //if (m_twoBin) m_neg->correctBField();
241  };
242 
244  {
245  m_pos->fiducialCuts();
246  };
247 
249  {
250  if (m_twoBin) {
253  }
254  else {
256  }
257  }
258 
259  std::vector<double*>::const_iterator residualsPos_begin() const { return m_pos->residuals_begin(); };
260  std::vector<double*>::const_iterator residualsPos_end() const { return m_pos->residuals_end(); };
261  std::vector<double*>::const_iterator residualsNeg_begin() const { return m_neg->residuals_begin(); };
262  std::vector<double*>::const_iterator residualsNeg_end() const { return m_neg->residuals_end(); };
263 
264  std::vector<bool>::const_iterator residualsPos_ok_begin() const { return m_pos->selectedResidualsFlags().begin(); };
265  std::vector<bool>::const_iterator residualsPos_ok_end() const { return m_pos->selectedResidualsFlags().end(); };
266  std::vector<bool>::const_iterator residualsNeg_ok_begin() const { return m_neg->selectedResidualsFlags().begin(); };
267  std::vector<bool>::const_iterator residualsNeg_ok_end() const { return m_neg->selectedResidualsFlags().end(); };
268 
269 protected:
270  bool m_twoBin;
272 };
273 
274 #endif // Alignment_MuonAlignmentAlgorithms_MuonResidualsTwoBin_H
double value(int parNum)
double wmean(int which, int whichredchi2, double truncate)
MuonResidualsFitter * m_neg
MuonResidualsFitter * m_pos
void selectPeakResiduals(double nsigma, int nvar, int *vars)
void fill(char charge, double *residual)
std::vector< double * >::const_iterator residualsPos_end() const
void write(FILE *file, int which=0)
virtual int npar()=0
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)
std::vector< bool >::const_iterator residualsPos_ok_end() const
Definition: weight.py:1
std::vector< bool >::const_iterator residualsPos_ok_begin() const
double value(int parNum)
tuple twoBin
Definition: align_cfg.py:29
std::vector< bool >::const_iterator residualsNeg_ok_end() const
std::vector< bool >::const_iterator residualsNeg_ok_begin() const
T sqrt(T t)
Definition: SSEVec.h:18
void plotweighted(std::string name, TFileDirectory *dir, int which, int whichredchi2, double multiplier)
void fix(int parNum, bool dofix=true)
void write(FILE *file, int which=0)
double mean(int which, double truncate)
Definition: value.py:1
virtual void correctBField()=0
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)
virtual int type() const =0
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)
void fiducialCuts(double xMin=-80.0, double xMax=80.0, double yMin=-80.0, double yMax=80.0, bool fidcut1=false)
std::vector< double * >::const_iterator residuals_end() const
long numResidualsNeg() const
int useRes(int pattern=-1)
std::vector< bool > & selectedResidualsFlags()
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)
def which(cmd)
Definition: eostools.py:335
dbl *** dir
Definition: mlp_gen.cc:35
vars
Definition: DeepTauId.cc:77
std::vector< double * >::const_iterator residualsPos_begin() const
void setPrintLevel(int printLevel)
void selectPeakResiduals(double nsigma, int nvar, int *vars)
std::vector< double * >::const_iterator residuals_begin() const
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)