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