CMS 3D CMS Logo

Vx3DHLTAnalyzer.cc
Go to the documentation of this file.
1 /*
2  \File Vx3DHLTAnalyzer.cc
3  \Display Beam-spot monitor entirely based on pixel detector information
4  the monitoring is based on a 3D fit to the vertex cloud
5  \Author Mauro Dinardo
6  \Version $ Revision: 3.5 $
7  \Date $ Date: 2010/23/02 13:15:00 $
8 */
9 
10 
12 
15 
16 #include <Math/Minimizer.h>
17 #include <Math/Factory.h>
18 #include <Math/Functor.h>
19 
20 
21 // ### Calling namespaces ###
22 using namespace std;
23 using namespace edm;
24 using namespace reco;
25 
26 
28 {
29  debugMode = true;
30  nLumiFit = 2; // Number of integrated lumis to perform the fit
31  maxLumiIntegration = 15; // If failing fits, this is the maximum number of integrated lumis after which a reset is issued
32  nLumiXaxisRange = 5000; // Correspond to about 32h of data taking: 32h * 60min * 60s / 23s per lumi-block = 5009
33  dataFromFit = true; // The Beam Spot data can be either taken from the histograms or from the fit results
34  minNentries = 20; // Minimum number of good vertices to perform the fit
35  xRange = 0.8; // [cm]
36  xStep = 0.001; // [cm]
37  yRange = 0.8; // [cm]
38  yStep = 0.001; // [cm]
39  zRange = 30.; // [cm]
40  zStep = 0.04; // [cm]
41  VxErrCorr = 1.3;
42  minVxDoF = 10.; // Good-vertex selection cut
43  // For vertex fitter without track-weight: d.o.f. = 2*NTracks - 3
44  // For vertex fitter with track-weight: d.o.f. = sum_NTracks(2*track_weight) - 3
45  minVxWgt = 0.5; // Good-vertex selection cut
46  fileName = "BeamPixelResults.txt";
47 
48  vertexCollection = consumes<VertexCollection> (iConfig.getUntrackedParameter<InputTag>("vertexCollection", InputTag("pixelVertices")));
49  pixelHitCollection = consumes<SiPixelRecHitCollection>(iConfig.getUntrackedParameter<InputTag>("pixelHitCollection", InputTag("siPixelRecHits")));
50 
51  debugMode = iConfig.getParameter<bool>("debugMode");
52  nLumiFit = iConfig.getParameter<unsigned int>("nLumiFit");
53  maxLumiIntegration = iConfig.getParameter<unsigned int>("maxLumiIntegration");
54  nLumiXaxisRange = iConfig.getParameter<unsigned int>("nLumiXaxisRange");
55  dataFromFit = iConfig.getParameter<bool>("dataFromFit");
56  minNentries = iConfig.getParameter<unsigned int>("minNentries");
57  xRange = iConfig.getParameter<double>("xRange");
58  xStep = iConfig.getParameter<double>("xStep");
59  yRange = iConfig.getParameter<double>("yRange");
60  yStep = iConfig.getParameter<double>("yStep");
61  zRange = iConfig.getParameter<double>("zRange");
62  zStep = iConfig.getParameter<double>("zStep");
63  VxErrCorr = iConfig.getParameter<double>("VxErrCorr");
64  minVxDoF = iConfig.getParameter<double>("minVxDoF");
65  minVxWgt = iConfig.getParameter<double>("minVxWgt");
66  fileName = iConfig.getParameter<string>("fileName");
67 
68 
69  // ### Set internal variables ###
70  nParams = 9; // Number of free parameters in the fit
71  internalDebug = false;
72  considerVxCovariance = true; // Deconvolute vertex covariance matrix
73  pi = 3.141592653589793238;
74  // ##############################
75 }
76 
77 
79 {
80  reset("scratch");
81 }
82 
83 
84 void Vx3DHLTAnalyzer::analyze (const Event& iEvent, const EventSetup& iSetup)
85 {
86  Handle<VertexCollection> Vx3DCollection;
87  iEvent.getByToken(vertexCollection, Vx3DCollection);
88 
89  unsigned int i,j;
90  double det;
91  VertexType MyVertex;
92 
93  if (runNumber != iEvent.id().run())
94  {
95  reset("scratch");
96  runNumber = iEvent.id().run();
97 
98  if (debugMode == true)
99  {
100  stringstream debugFile;
101  string tmp(fileName);
102 
103  if (outputDebugFile.is_open() == true) outputDebugFile.close();
104  tmp.erase(strlen(fileName.c_str())-4,4);
105  debugFile << tmp.c_str() << "_Run" << iEvent.id().run() << ".txt";
106  outputDebugFile.open(debugFile.str().c_str(), ios::out);
107  outputDebugFile.close();
108  outputDebugFile.open(debugFile.str().c_str(), ios::app);
109  }
110 
111  beginLuminosityBlock(iEvent.getLuminosityBlock(),iSetup);
112  }
113  else if (beginTimeOfFit != 0)
114  {
115  totalHits += HitCounter(iEvent);
116 
117  if (internalDebug == true)
118  {
119  cout << "[Vx3DHLTAnalyzer]::\tI found " << totalHits << " pixel hits until now" << endl;
120  cout << "[Vx3DHLTAnalyzer]::\tIn this event there are " << Vx3DCollection->size() << " vertex cadidates" << endl;
121  }
122 
123  for (vector<Vertex>::const_iterator it3DVx = Vx3DCollection->begin(); it3DVx != Vx3DCollection->end(); it3DVx++)
124  {
125  if (internalDebug == true)
126  {
127  cout << "[Vx3DHLTAnalyzer]::\tVertex selections:" << endl;
128  cout << "[Vx3DHLTAnalyzer]::\tEvent ID = " << iEvent.id() << endl;
129  cout << "[Vx3DHLTAnalyzer]::\tVertex number = " << it3DVx - Vx3DCollection->begin() << endl;
130  cout << "[Vx3DHLTAnalyzer]::\tisValid = " << it3DVx->isValid() << endl;
131  cout << "[Vx3DHLTAnalyzer]::\tisFake = " << it3DVx->isFake() << endl;
132  cout << "[Vx3DHLTAnalyzer]::\tnodof = " << it3DVx->ndof() << endl;
133  cout << "[Vx3DHLTAnalyzer]::\ttracksSize = " << it3DVx->tracksSize() << endl;
134  }
135 
136  if ((it3DVx->isValid() == true) &&
137  (it3DVx->isFake() == false) &&
138  (it3DVx->ndof() >= minVxDoF) &&
139  (it3DVx->tracksSize() > 0) &&
140  ((it3DVx->ndof()+3.) / ((double)it3DVx->tracksSize()) >= 2.*minVxWgt))
141  {
142  for (i = 0; i < DIM; i++)
143  {
144  for (j = 0; j < DIM; j++)
145  {
146  MyVertex.Covariance[i][j] = it3DVx->covariance(i,j);
147  if (isNotFinite(MyVertex.Covariance[i][j]) == true) break;
148  }
149 
150  if (j != DIM) break;
151  }
152 
153  if (i == DIM)
154  det = std::fabs(MyVertex.Covariance[0][0])*(std::fabs(MyVertex.Covariance[1][1])*std::fabs(MyVertex.Covariance[2][2]) - MyVertex.Covariance[1][2]*MyVertex.Covariance[1][2]) -
155  MyVertex.Covariance[0][1]*(MyVertex.Covariance[0][1]*std::fabs(MyVertex.Covariance[2][2]) - MyVertex.Covariance[0][2]*MyVertex.Covariance[1][2]) +
156  MyVertex.Covariance[0][2]*(MyVertex.Covariance[0][1]*MyVertex.Covariance[1][2] - MyVertex.Covariance[0][2]*std::fabs(MyVertex.Covariance[1][1]));
157 
158  if ((i == DIM) && (det > 0.))
159  {
160  if (internalDebug == true) cout << "[Vx3DHLTAnalyzer]::\tVertex accepted !" << endl;
161 
162  MyVertex.x = it3DVx->x();
163  MyVertex.y = it3DVx->y();
164  MyVertex.z = it3DVx->z();
165  Vertices.push_back(MyVertex);
166 
167  Vx_X->Fill(it3DVx->x());
168  Vx_Y->Fill(it3DVx->y());
169  Vx_Z->Fill(it3DVx->z());
170 
171  Vx_ZX->Fill(it3DVx->z(), it3DVx->x());
172  Vx_ZY->Fill(it3DVx->z(), it3DVx->y());
173  Vx_XY->Fill(it3DVx->x(), it3DVx->y());
174 
175  Vx_X_Cum->Fill(it3DVx->x());
176  Vx_Y_Cum->Fill(it3DVx->y());
177  Vx_Z_Cum->Fill(it3DVx->z());
178 
179  Vx_ZX_Cum->Fill(it3DVx->z(), it3DVx->x());
180  Vx_ZY_Cum->Fill(it3DVx->z(), it3DVx->y());
181  Vx_XY_Cum->Fill(it3DVx->x(), it3DVx->y());
182  }
183  else if (internalDebug == true)
184  {
185  cout << "[Vx3DHLTAnalyzer]::\tVertex discarded !" << endl;
186 
187  for (i = 0; i < DIM; i++)
188  for (j = 0; j < DIM; j++)
189  cout << "(i,j) --> " << i << "," << j << " --> " << MyVertex.Covariance[i][j] << endl;
190  }
191  }
192  else if (internalDebug == true) cout << "[Vx3DHLTAnalyzer]::\tVertex discarded !" << endl;
193  }
194  }
195 }
196 
197 
199 {
200  Handle<SiPixelRecHitCollection> rechitspixel;
201  iEvent.getByToken(pixelHitCollection, rechitspixel);
202 
203  unsigned int counter = 0;
204 
205  for (SiPixelRecHitCollection::const_iterator j = rechitspixel->begin(); j != rechitspixel->end(); j++)
206  for (edmNew::DetSet<SiPixelRecHit>::const_iterator h = j->begin(); h != j->end(); h++) counter += h->cluster()->size();
207 
208  return counter;
209 }
210 
211 
212 string Vx3DHLTAnalyzer::formatTime (const time_t& t)
213 {
214  char ts[25];
215  strftime(ts, sizeof(ts), "%Y.%m.%d %H:%M:%S %Z", gmtime(&t));
216 
217  string ts_string(ts);
218 
219  return ts_string;
220 }
221 
222 
223 double Vx3DHLTAnalyzer::Gauss3DFunc (const double* par)
224 {
225  double K[DIM][DIM]; // Covariance Matrix
226  double M[DIM][DIM]; // K^-1
227  double det;
228  double sumlog = 0.;
229 
230 // par[0] = K(0,0) --> Var[X]
231 // par[1] = K(1,1) --> Var[Y]
232 // par[2] = K(2,2) --> Var[Z]
233 // par[3] = K(0,1) = K(1,0) --> Cov[X,Y]
234 // par[4] = K(1,2) = K(2,1) --> Cov[Y,Z] --> dy/dz
235 // par[5] = K(0,2) = K(2,0) --> Cov[X,Z] --> dx/dz
236 // par[6] = mean x
237 // par[7] = mean y
238 // par[8] = mean z
239 
240  counterVx = 0;
241  for (unsigned int i = 0; i < Vertices.size(); i++)
242  {
243  if ((std::sqrt((Vertices[i].x-xPos)*(Vertices[i].x-xPos) + (Vertices[i].y-yPos)*(Vertices[i].y-yPos)) <= maxTransRadius) &&
244  (std::fabs(Vertices[i].z-zPos) <= maxLongLength))
245  {
246  if (considerVxCovariance == true)
247  {
248  K[0][0] = std::fabs(par[0]) + VxErrCorr*VxErrCorr * std::fabs(Vertices[i].Covariance[0][0]);
249  K[1][1] = std::fabs(par[1]) + VxErrCorr*VxErrCorr * std::fabs(Vertices[i].Covariance[1][1]);
250  K[2][2] = std::fabs(par[2]) + VxErrCorr*VxErrCorr * std::fabs(Vertices[i].Covariance[2][2]);
251  K[0][1] = K[1][0] = par[3] + VxErrCorr*VxErrCorr * Vertices[i].Covariance[0][1];
252  K[1][2] = K[2][1] = par[4]*(std::fabs(par[2])-std::fabs(par[1])) - par[5]*par[3] + VxErrCorr*VxErrCorr * Vertices[i].Covariance[1][2];
253  K[0][2] = K[2][0] = par[5]*(std::fabs(par[2])-std::fabs(par[0])) - par[4]*par[3] + VxErrCorr*VxErrCorr * Vertices[i].Covariance[0][2];
254  }
255  else
256  {
257  K[0][0] = std::fabs(par[0]);
258  K[1][1] = std::fabs(par[1]);
259  K[2][2] = std::fabs(par[2]);
260  K[0][1] = K[1][0] = par[3];
261  K[1][2] = K[2][1] = par[4]*(std::fabs(par[2])-std::fabs(par[1])) - par[5]*par[3];
262  K[0][2] = K[2][0] = par[5]*(std::fabs(par[2])-std::fabs(par[0])) - par[4]*par[3];
263  }
264 
265  det = K[0][0]*(K[1][1]*K[2][2] - K[1][2]*K[1][2]) -
266  K[0][1]*(K[0][1]*K[2][2] - K[0][2]*K[1][2]) +
267  K[0][2]*(K[0][1]*K[1][2] - K[0][2]*K[1][1]);
268 
269  M[0][0] = (K[1][1]*K[2][2] - K[1][2]*K[1][2]) / det;
270  M[1][1] = (K[0][0]*K[2][2] - K[0][2]*K[0][2]) / det;
271  M[2][2] = (K[0][0]*K[1][1] - K[0][1]*K[0][1]) / det;
272  M[0][1] = M[1][0] = (K[0][2]*K[1][2] - K[0][1]*K[2][2]) / det;
273  M[1][2] = M[2][1] = (K[0][2]*K[0][1] - K[1][2]*K[0][0]) / det;
274  M[0][2] = M[2][0] = (K[0][1]*K[1][2] - K[0][2]*K[1][1]) / det;
275 
276  sumlog += double(DIM)*std::log(2.*pi) + std::log(std::fabs(det)) +
277  (M[0][0]*(Vertices[i].x-par[6])*(Vertices[i].x-par[6]) +
278  M[1][1]*(Vertices[i].y-par[7])*(Vertices[i].y-par[7]) +
279  M[2][2]*(Vertices[i].z-par[8])*(Vertices[i].z-par[8]) +
280  2.*M[0][1]*(Vertices[i].x-par[6])*(Vertices[i].y-par[7]) +
281  2.*M[1][2]*(Vertices[i].y-par[7])*(Vertices[i].z-par[8]) +
282  2.*M[0][2]*(Vertices[i].x-par[6])*(Vertices[i].z-par[8]));
283 
284  counterVx++;
285  }
286  }
287 
288  return sumlog;
289 }
290 
291 
292 int Vx3DHLTAnalyzer::MyFit (vector<double>* vals)
293 {
294  // ############################################
295  // # RETURN CODE: #
296  // # >0 == NO OK - fit status (MINUIT manual) #
297  // # 0 == OK #
298  // # -1 == NO OK - not finite edm #
299  // # -2 == NO OK - not enough "minNentries" #
300  // # -3 == NO OK - not finite errors #
301  // # -4 == NO OK - negative determinant #
302  // # -5 == NO OK - maxLumiIntegration reached #
303  // ############################################
304 
305  if ((vals != nullptr) && (vals->size() == nParams*2))
306  {
307  double nSigmaXY = 10.;
308  double nSigmaZ = 10.;
309  double parDistanceXY = 1e-3; // Unit: [cm]
310  double parDistanceZ = 1e-2; // Unit: [cm]
311  double parDistanceddZ = 1e-3; // Unit: [rad]
312  double parDistanceCxy = 1e-5; // Unit: [cm^2]
313  double bestEdm;
314 
315  const unsigned int trials = 4;
316  double largerDist[trials] = {0.1, 5., 10., 100.};
317 
318  double covxz,covyz,det;
319  double deltaMean;
320  int bestMovementX = 1;
321  int bestMovementY = 1;
322  int bestMovementZ = 1;
323  int goodData;
324 
325  double edm;
326 
327  vector<double>::const_iterator it = vals->begin();
328 
329  ROOT::Math::Minimizer* Gauss3D = ROOT::Math::Factory::CreateMinimizer("Minuit2","Migrad");
330  Gauss3D->SetErrorDef(1.0);
331  if (internalDebug == true) Gauss3D->SetPrintLevel(3);
332  else Gauss3D->SetPrintLevel(0);
333 
334  ROOT::Math::Functor _Gauss3DFunc(this, &Vx3DHLTAnalyzer::Gauss3DFunc, nParams);
335  Gauss3D->SetFunction(_Gauss3DFunc);
336 
337  if (internalDebug == true) cout << "[Vx3DHLTAnalyzer]::\t@@@ START FITTING @@@" << endl;
338 
339  // @@@ Fit at X-deltaMean | X | X+deltaMean @@@
340  bestEdm = 1.;
341  for (int i = 0; i < 3; i++)
342  {
343  deltaMean = (double(i)-1.)*std::sqrt(*(it+0));
344  if (internalDebug == true) cout << "[Vx3DHLTAnalyzer]::\tdeltaMean --> " << deltaMean << endl;
345 
346  Gauss3D->Clear();
347 
348  Gauss3D->SetVariable(0,"var x ", *(it+0), parDistanceXY * parDistanceXY);
349  Gauss3D->SetVariable(1,"var y ", *(it+1), parDistanceXY * parDistanceXY);
350  Gauss3D->SetVariable(2,"var z ", *(it+2), parDistanceZ * parDistanceZ);
351  Gauss3D->SetVariable(3,"cov xy", *(it+3), parDistanceCxy);
352  Gauss3D->SetVariable(4,"dydz ", *(it+4), parDistanceddZ);
353  Gauss3D->SetVariable(5,"dxdz ", *(it+5), parDistanceddZ);
354  Gauss3D->SetVariable(6,"mean x", *(it+6)+deltaMean, parDistanceXY);
355  Gauss3D->SetVariable(7,"mean y", *(it+7), parDistanceXY);
356  Gauss3D->SetVariable(8,"mean z", *(it+8), parDistanceZ);
357 
358  // Set the central positions of the centroid for vertex rejection
359  xPos = Gauss3D->X()[6];
360  yPos = Gauss3D->X()[7];
361  zPos = Gauss3D->X()[8];
362 
363  // Set dimensions of the centroid for vertex rejection
364  maxTransRadius = nSigmaXY * std::sqrt(std::fabs(Gauss3D->X()[0]) + std::fabs(Gauss3D->X()[1])) / 2.;
365  maxLongLength = nSigmaZ * std::sqrt(std::fabs(Gauss3D->X()[2]));
366 
367  Gauss3D->Minimize();
368  goodData = Gauss3D->Status();
369  edm = Gauss3D->Edm();
370 
371  if (counterVx < minNentries) goodData = -2;
372  else if (isNotFinite(edm) == true) { goodData = -1; if (internalDebug == true) cout << "[Vx3DHLTAnalyzer]::\tNot finite edm !" << endl; }
373  else for (unsigned int j = 0; j < nParams; j++)
374  if (isNotFinite(Gauss3D->Errors()[j]) == true)
375  {
376  goodData = -3;
377  if (internalDebug == true) cout << "[Vx3DHLTAnalyzer]::\tNot finite errors !" << endl;
378  break;
379  }
380  if (goodData == 0)
381  {
382  covyz = Gauss3D->X()[4]*(std::fabs(Gauss3D->X()[2])-std::fabs(Gauss3D->X()[1])) - Gauss3D->X()[5]*Gauss3D->X()[3];
383  covxz = Gauss3D->X()[5]*(std::fabs(Gauss3D->X()[2])-std::fabs(Gauss3D->X()[0])) - Gauss3D->X()[4]*Gauss3D->X()[3];
384 
385  det = std::fabs(Gauss3D->X()[0]) * (std::fabs(Gauss3D->X()[1])*std::fabs(Gauss3D->X()[2]) - covyz*covyz) -
386  Gauss3D->X()[3] * (Gauss3D->X()[3]*std::fabs(Gauss3D->X()[2]) - covxz*covyz) +
387  covxz * (Gauss3D->X()[3]*covyz - covxz*std::fabs(Gauss3D->X()[1]));
388  if (det < 0.) { goodData = -4; if (internalDebug == true) cout << "[Vx3DHLTAnalyzer]::\tNegative determinant !" << endl; }
389  }
390 
391  if ((goodData == 0) && (std::fabs(edm) < bestEdm)) { bestEdm = edm; bestMovementX = i; }
392  }
393  if (internalDebug == true) cout << "[Vx3DHLTAnalyzer]::\tFound bestMovementX --> " << bestMovementX << endl;
394 
395  // @@@ Fit at Y-deltaMean | Y | Y+deltaMean @@@
396  bestEdm = 1.;
397  for (int i = 0; i < 3; i++)
398  {
399  deltaMean = (double(i)-1.)*std::sqrt(*(it+1));
400  if (internalDebug == true)
401  {
402  cout << "[Vx3DHLTAnalyzer]::\tdeltaMean --> " << deltaMean << endl;
403  cout << "[Vx3DHLTAnalyzer]::\tdeltaMean X --> " << (double(bestMovementX)-1.)*std::sqrt(*(it+0)) << endl;
404  }
405 
406  Gauss3D->Clear();
407 
408  Gauss3D->SetVariable(0,"var x ", *(it+0), parDistanceXY * parDistanceXY);
409  Gauss3D->SetVariable(1,"var y ", *(it+1), parDistanceXY * parDistanceXY);
410  Gauss3D->SetVariable(2,"var z ", *(it+2), parDistanceZ * parDistanceZ);
411  Gauss3D->SetVariable(3,"cov xy", *(it+3), parDistanceCxy);
412  Gauss3D->SetVariable(4,"dydz ", *(it+4), parDistanceddZ);
413  Gauss3D->SetVariable(5,"dxdz ", *(it+5), parDistanceddZ);
414  Gauss3D->SetVariable(6,"mean x", *(it+6)+(double(bestMovementX)-1.)*std::sqrt(*(it+0)), parDistanceXY);
415  Gauss3D->SetVariable(7,"mean y", *(it+7)+deltaMean, parDistanceXY);
416  Gauss3D->SetVariable(8,"mean z", *(it+8), parDistanceZ);
417 
418  // Set the central positions of the centroid for vertex rejection
419  xPos = Gauss3D->X()[6];
420  yPos = Gauss3D->X()[7];
421  zPos = Gauss3D->X()[8];
422 
423  // Set dimensions of the centroid for vertex rejection
424  maxTransRadius = nSigmaXY * std::sqrt(std::fabs(Gauss3D->X()[0]) + std::fabs(Gauss3D->X()[1])) / 2.;
425  maxLongLength = nSigmaZ * std::sqrt(std::fabs(Gauss3D->X()[2]));
426 
427  Gauss3D->Minimize();
428  goodData = Gauss3D->Status();
429  edm = Gauss3D->Edm();
430 
431  if (counterVx < minNentries) goodData = -2;
432  else if (isNotFinite(edm) == true) { goodData = -1; if (internalDebug == true) cout << "[Vx3DHLTAnalyzer]::\tNot finite edm !" << endl; }
433  else for (unsigned int j = 0; j < nParams; j++)
434  if (isNotFinite(Gauss3D->Errors()[j]) == true)
435  {
436  goodData = -3;
437  if (internalDebug == true) cout << "[Vx3DHLTAnalyzer]::\tNot finite errors !" << endl;
438  break;
439  }
440  if (goodData == 0)
441  {
442  covyz = Gauss3D->X()[4]*(std::fabs(Gauss3D->X()[2])-std::fabs(Gauss3D->X()[1])) - Gauss3D->X()[5]*Gauss3D->X()[3];
443  covxz = Gauss3D->X()[5]*(std::fabs(Gauss3D->X()[2])-std::fabs(Gauss3D->X()[0])) - Gauss3D->X()[4]*Gauss3D->X()[3];
444 
445  det = std::fabs(Gauss3D->X()[0]) * (std::fabs(Gauss3D->X()[1])*std::fabs(Gauss3D->X()[2]) - covyz*covyz) -
446  Gauss3D->X()[3] * (Gauss3D->X()[3]*std::fabs(Gauss3D->X()[2]) - covxz*covyz) +
447  covxz * (Gauss3D->X()[3]*covyz - covxz*std::fabs(Gauss3D->X()[1]));
448  if (det < 0.) { goodData = -4; if (internalDebug == true) cout << "[Vx3DHLTAnalyzer]::\tNegative determinant !" << endl; }
449  }
450 
451  if ((goodData == 0) && (std::fabs(edm) < bestEdm)) { bestEdm = edm; bestMovementY = i; }
452  }
453  if (internalDebug == true) cout << "[Vx3DHLTAnalyzer]::\tFound bestMovementY --> " << bestMovementY << endl;
454 
455  // @@@ Fit at Z-deltaMean | Z | Z+deltaMean @@@
456  bestEdm = 1.;
457  for (int i = 0; i < 3; i++)
458  {
459  deltaMean = (double(i)-1.)*std::sqrt(*(it+2));
460  if (internalDebug == true)
461  {
462  cout << "[Vx3DHLTAnalyzer]::\tdeltaMean --> " << deltaMean << endl;
463  cout << "[Vx3DHLTAnalyzer]::\tdeltaMean X --> " << (double(bestMovementX)-1.)*std::sqrt(*(it+0)) << endl;
464  cout << "[Vx3DHLTAnalyzer]::\tdeltaMean Y --> " << (double(bestMovementY)-1.)*std::sqrt(*(it+1)) << endl;
465  }
466 
467  Gauss3D->Clear();
468 
469  Gauss3D->SetVariable(0,"var x ", *(it+0), parDistanceXY * parDistanceXY);
470  Gauss3D->SetVariable(1,"var y ", *(it+1), parDistanceXY * parDistanceXY);
471  Gauss3D->SetVariable(2,"var z ", *(it+2), parDistanceZ * parDistanceZ);
472  Gauss3D->SetVariable(3,"cov xy", *(it+3), parDistanceCxy);
473  Gauss3D->SetVariable(4,"dydz ", *(it+4), parDistanceddZ);
474  Gauss3D->SetVariable(5,"dxdz ", *(it+5), parDistanceddZ);
475  Gauss3D->SetVariable(6,"mean x", *(it+6)+(double(bestMovementX)-1.)*std::sqrt(*(it+0)), parDistanceXY);
476  Gauss3D->SetVariable(7,"mean y", *(it+7)+(double(bestMovementY)-1.)*std::sqrt(*(it+1)), parDistanceXY);
477  Gauss3D->SetVariable(8,"mean z", *(it+8)+deltaMean, parDistanceZ);
478 
479  // Set the central positions of the centroid for vertex rejection
480  xPos = Gauss3D->X()[6];
481  yPos = Gauss3D->X()[7];
482  zPos = Gauss3D->X()[8];
483 
484  // Set dimensions of the centroid for vertex rejection
485  maxTransRadius = nSigmaXY * std::sqrt(std::fabs(Gauss3D->X()[0]) + std::fabs(Gauss3D->X()[1])) / 2.;
486  maxLongLength = nSigmaZ * std::sqrt(std::fabs(Gauss3D->X()[2]));
487 
488  Gauss3D->Minimize();
489  goodData = Gauss3D->Status();
490  edm = Gauss3D->Edm();
491 
492  if (counterVx < minNentries) goodData = -2;
493  else if (isNotFinite(edm) == true) { goodData = -1; if (internalDebug == true) cout << "[Vx3DHLTAnalyzer]::\tNot finite edm !" << endl; }
494  else for (unsigned int j = 0; j < nParams; j++)
495  if (isNotFinite(Gauss3D->Errors()[j]) == true)
496  {
497  goodData = -3;
498  if (internalDebug == true) cout << "[Vx3DHLTAnalyzer]::\tNot finite errors !" << endl;
499  break;
500  }
501  if (goodData == 0)
502  {
503  covyz = Gauss3D->X()[4]*(std::fabs(Gauss3D->X()[2])-std::fabs(Gauss3D->X()[1])) - Gauss3D->X()[5]*Gauss3D->X()[3];
504  covxz = Gauss3D->X()[5]*(std::fabs(Gauss3D->X()[2])-std::fabs(Gauss3D->X()[0])) - Gauss3D->X()[4]*Gauss3D->X()[3];
505 
506  det = std::fabs(Gauss3D->X()[0]) * (std::fabs(Gauss3D->X()[1])*std::fabs(Gauss3D->X()[2]) - covyz*covyz) -
507  Gauss3D->X()[3] * (Gauss3D->X()[3]*std::fabs(Gauss3D->X()[2]) - covxz*covyz) +
508  covxz * (Gauss3D->X()[3]*covyz - covxz*std::fabs(Gauss3D->X()[1]));
509  if (det < 0.) { goodData = -4; if (internalDebug == true) cout << "[Vx3DHLTAnalyzer]::\tNegative determinant !" << endl; }
510  }
511 
512  if ((goodData == 0) && (std::fabs(edm) < bestEdm)) { bestEdm = edm; bestMovementZ = i; }
513  }
514  if (internalDebug == true) cout << "[Vx3DHLTAnalyzer]::\tFound bestMovementZ --> " << bestMovementZ << endl;
515 
516  Gauss3D->Clear();
517 
518  // @@@ FINAL FIT @@@
519  Gauss3D->SetVariable(0,"var x ", *(it+0), parDistanceXY * parDistanceXY);
520  Gauss3D->SetVariable(1,"var y ", *(it+1), parDistanceXY * parDistanceXY);
521  Gauss3D->SetVariable(2,"var z ", *(it+2), parDistanceZ * parDistanceZ);
522  Gauss3D->SetVariable(3,"cov xy", *(it+3), parDistanceCxy);
523  Gauss3D->SetVariable(4,"dydz ", *(it+4), parDistanceddZ);
524  Gauss3D->SetVariable(5,"dxdz ", *(it+5), parDistanceddZ);
525  Gauss3D->SetVariable(6,"mean x", *(it+6)+(double(bestMovementX)-1.)*std::sqrt(*(it+0)), parDistanceXY);
526  Gauss3D->SetVariable(7,"mean y", *(it+7)+(double(bestMovementY)-1.)*std::sqrt(*(it+1)), parDistanceXY);
527  Gauss3D->SetVariable(8,"mean z", *(it+8)+(double(bestMovementZ)-1.)*std::sqrt(*(it+2)), parDistanceZ);
528 
529  // Set the central positions of the centroid for vertex rejection
530  xPos = Gauss3D->X()[6];
531  yPos = Gauss3D->X()[7];
532  zPos = Gauss3D->X()[8];
533 
534  // Set dimensions of the centroid for vertex rejection
535  maxTransRadius = nSigmaXY * std::sqrt(std::fabs(Gauss3D->X()[0]) + std::fabs(Gauss3D->X()[1])) / 2.;
536  maxLongLength = nSigmaZ * std::sqrt(std::fabs(Gauss3D->X()[2]));
537 
538  Gauss3D->Minimize();
539  goodData = Gauss3D->Status();
540  edm = Gauss3D->Edm();
541 
542  if (counterVx < minNentries) goodData = -2;
543  else if (isNotFinite(edm) == true) { goodData = -1; if (internalDebug == true) cout << "[Vx3DHLTAnalyzer]::\tNot finite edm !" << endl; }
544  else for (unsigned int j = 0; j < nParams; j++)
545  if (isNotFinite(Gauss3D->Errors()[j]) == true)
546  {
547  goodData = -3;
548  if (internalDebug == true) cout << "[Vx3DHLTAnalyzer]::\tNot finite errors !" << endl;
549  break;
550  }
551  if (goodData == 0)
552  {
553  covyz = Gauss3D->X()[4]*(std::fabs(Gauss3D->X()[2])-std::fabs(Gauss3D->X()[1])) - Gauss3D->X()[5]*Gauss3D->X()[3];
554  covxz = Gauss3D->X()[5]*(std::fabs(Gauss3D->X()[2])-std::fabs(Gauss3D->X()[0])) - Gauss3D->X()[4]*Gauss3D->X()[3];
555 
556  det = std::fabs(Gauss3D->X()[0]) * (std::fabs(Gauss3D->X()[1])*std::fabs(Gauss3D->X()[2]) - covyz*covyz) -
557  Gauss3D->X()[3] * (Gauss3D->X()[3]*std::fabs(Gauss3D->X()[2]) - covxz*covyz) +
558  covxz * (Gauss3D->X()[3]*covyz - covxz*std::fabs(Gauss3D->X()[1]));
559  if (det < 0.) { goodData = -4; if (internalDebug == true) cout << "[Vx3DHLTAnalyzer]::\tNegative determinant !" << endl; }
560  }
561 
562  // @@@ FIT WITH DIFFERENT PARAMETER DISTANCES @@@
563  for (unsigned int i = 0; i < trials; i++)
564  {
565  if ((goodData != 0) && (goodData != -2))
566  {
567  Gauss3D->Clear();
568 
569  if (internalDebug == true) cout << "[Vx3DHLTAnalyzer]::\tFIT WITH DIFFERENT PARAMETER DISTANCES - STEP " << i+1 << endl;
570 
571  Gauss3D->SetVariable(0,"var x ", *(it+0), parDistanceXY * parDistanceXY * largerDist[i]);
572  Gauss3D->SetVariable(1,"var y ", *(it+1), parDistanceXY * parDistanceXY * largerDist[i]);
573  Gauss3D->SetVariable(2,"var z ", *(it+2), parDistanceZ * parDistanceZ * largerDist[i]);
574  Gauss3D->SetVariable(3,"cov xy", *(it+3), parDistanceCxy * largerDist[i]);
575  Gauss3D->SetVariable(4,"dydz ", *(it+4), parDistanceddZ * largerDist[i]);
576  Gauss3D->SetVariable(5,"dxdz ", *(it+5), parDistanceddZ * largerDist[i]);
577  Gauss3D->SetVariable(6,"mean x", *(it+6)+(double(bestMovementX)-1.)*std::sqrt(*(it+0)), parDistanceXY * largerDist[i]);
578  Gauss3D->SetVariable(7,"mean y", *(it+7)+(double(bestMovementY)-1.)*std::sqrt(*(it+1)), parDistanceXY * largerDist[i]);
579  Gauss3D->SetVariable(8,"mean z", *(it+8)+(double(bestMovementZ)-1.)*std::sqrt(*(it+2)), parDistanceZ * largerDist[i]);
580 
581  // Set the central positions of the centroid for vertex rejection
582  xPos = Gauss3D->X()[6];
583  yPos = Gauss3D->X()[7];
584  zPos = Gauss3D->X()[8];
585 
586  // Set dimensions of the centroid for vertex rejection
587  maxTransRadius = nSigmaXY * std::sqrt(std::fabs(Gauss3D->X()[0]) + std::fabs(Gauss3D->X()[1])) / 2.;
588  maxLongLength = nSigmaZ * std::sqrt(std::fabs(Gauss3D->X()[2]));
589 
590  Gauss3D->Minimize();
591  goodData = Gauss3D->Status();
592  edm = Gauss3D->Edm();
593 
594  if (counterVx < minNentries) goodData = -2;
595  else if (isNotFinite(edm) == true) { goodData = -1; if (internalDebug == true) cout << "[Vx3DHLTAnalyzer]::\tNot finite edm !" << endl; }
596  else for (unsigned int j = 0; j < nParams; j++)
597  if (isNotFinite(Gauss3D->Errors()[j]) == true)
598  {
599  goodData = -3;
600  if (internalDebug == true) cout << "[Vx3DHLTAnalyzer]::\tNot finite errors !" << endl;
601  break;
602  }
603  if (goodData == 0)
604  {
605  covyz = Gauss3D->X()[4]*(std::fabs(Gauss3D->X()[2])-std::fabs(Gauss3D->X()[1])) - Gauss3D->X()[5]*Gauss3D->X()[3];
606  covxz = Gauss3D->X()[5]*(std::fabs(Gauss3D->X()[2])-std::fabs(Gauss3D->X()[0])) - Gauss3D->X()[4]*Gauss3D->X()[3];
607 
608  det = std::fabs(Gauss3D->X()[0]) * (std::fabs(Gauss3D->X()[1])*std::fabs(Gauss3D->X()[2]) - covyz*covyz) -
609  Gauss3D->X()[3] * (Gauss3D->X()[3]*std::fabs(Gauss3D->X()[2]) - covxz*covyz) +
610  covxz * (Gauss3D->X()[3]*covyz - covxz*std::fabs(Gauss3D->X()[1]));
611  if (det < 0.) { goodData = -4; if (internalDebug == true) cout << "[Vx3DHLTAnalyzer]::\tNegative determinant !" << endl; }
612  }
613  } else break;
614  }
615 
616  if (goodData == 0)
617  for (unsigned int i = 0; i < nParams; i++)
618  {
619  vals->operator[](i) = Gauss3D->X()[i];
620  vals->operator[](i+nParams) = Gauss3D->Errors()[i];
621  }
622 
623  delete Gauss3D;
624  return goodData;
625  }
626 
627  return -1;
628 }
629 
630 
631 void Vx3DHLTAnalyzer::reset (string ResetType)
632 {
633  if ((debugMode == true) && (outputDebugFile.is_open() == true))
634  {
635  outputDebugFile << "Runnumber " << runNumber << endl;
636  outputDebugFile << "BeginTimeOfFit " << formatTime(beginTimeOfFit >> 32) << " " << (beginTimeOfFit >> 32) << endl;
637  outputDebugFile << "BeginLumiRange " << beginLumiOfFit << endl;
638  outputDebugFile << "EndTimeOfFit " << formatTime(endTimeOfFit >> 32) << " " << (endTimeOfFit >> 32) << endl;
639  outputDebugFile << "EndLumiRange " << endLumiOfFit << endl;
640  outputDebugFile << "LumiCounter " << lumiCounter << endl;
641  outputDebugFile << "LastLumiOfFit " << lastLumiOfFit << endl;
642  }
643 
644 
645  if (ResetType == "scratch")
646  {
647  runNumber = 0;
648  numberGoodFits = 0;
649  numberFits = 0;
650  lastLumiOfFit = 0;
651 
652  Vx_X->Reset();
653  Vx_Y->Reset();
654  Vx_Z->Reset();
655 
656  Vx_X_Fit->Reset();
657  Vx_Y_Fit->Reset();
658  Vx_Z_Fit->Reset();
659 
660  Vx_ZX->Reset();
661  Vx_ZY->Reset();
662  Vx_XY->Reset();
663 
664  Vx_X_Cum->Reset();
665  Vx_Y_Cum->Reset();
666  Vx_Z_Cum->Reset();
667 
668  Vx_ZX_Cum->Reset();
669  Vx_ZY_Cum->Reset();
670  Vx_XY_Cum->Reset();
671 
672  mXlumi->Reset();
673  mYlumi->Reset();
674  mZlumi->Reset();
675 
676  sXlumi->Reset();
677  sYlumi->Reset();
678  sZlumi->Reset();
679 
680  dxdzlumi->Reset();
681  dydzlumi->Reset();
682 
683  hitCounter->Reset();
684  goodVxCounter->Reset();
685  statusCounter->Reset();
686  fitResults->Reset();
687 
688  reportSummary->Fill(-1);
689  reportSummaryMap->getTH1()->SetBinContent(1, 1, -1);
690 
691  Vertices.clear();
692 
693  lumiCounter = 0;
694  totalHits = 0;
695  beginTimeOfFit = 0;
696  endTimeOfFit = 0;
697  beginLumiOfFit = 0;
698  endLumiOfFit = 0;
699 
700  if (internalDebug == true) cout << "[Vx3DHLTAnalyzer]::\tReset issued: scratch" << endl;
701  if ((debugMode == true) && (outputDebugFile.is_open() == true)) outputDebugFile << "Reset -scratch- issued\n" << endl;
702  }
703  else if (ResetType == "whole")
704  {
705  Vx_X->Reset();
706  Vx_Y->Reset();
707  Vx_Z->Reset();
708 
709  Vx_ZX->Reset();
710  Vx_ZY->Reset();
711  Vx_XY->Reset();
712 
713  Vertices.clear();
714 
715  lumiCounter = 0;
716  totalHits = 0;
717  beginTimeOfFit = 0;
718  endTimeOfFit = 0;
719  beginLumiOfFit = 0;
720  endLumiOfFit = 0;
721 
722  if (internalDebug == true) cout << "[Vx3DHLTAnalyzer]::\tReset issued: whole" << endl;
723  if ((debugMode == true) && (outputDebugFile.is_open() == true)) outputDebugFile << "Reset -whole- issued\n" << endl;
724  }
725  else if (ResetType == "fit")
726  {
727  Vx_X_Fit->Reset();
728  Vx_Y_Fit->Reset();
729  Vx_Z_Fit->Reset();
730 
731  if (internalDebug == true) cout << "[Vx3DHLTAnalyzer]::\tReset issued: fit" << endl;
732  if ((debugMode == true) && (outputDebugFile.is_open() == true)) outputDebugFile << "Reset -fit- issued\n" << endl;
733  }
734  else if (ResetType == "hitCounter")
735  {
736  totalHits = 0;
737 
738  if (internalDebug == true) cout << "[Vx3DHLTAnalyzer]::\tReset issued: hitCounter" << endl;
739  if ((debugMode == true) && (outputDebugFile.is_open() == true)) outputDebugFile << "Reset -hitCounter- issued\n" << endl;
740  }
741 }
742 
743 
744 void Vx3DHLTAnalyzer::writeToFile (vector<double>* vals,
745  TimeValue_t BeginTimeOfFit,
746  TimeValue_t EndTimeOfFit,
747  unsigned int BeginLumiOfFit,
748  unsigned int EndLumiOfFit,
749  int dataType)
750 {
751  stringstream BufferString;
752  BufferString.precision(5);
753 
754  outputFile.open(fileName.c_str(), ios::out);
755 
756  if ((outputFile.is_open() == true) && (vals != nullptr) && (vals->size() == (nParams-1)*2))
757  {
758  vector<double>::const_iterator it = vals->begin();
759 
760  outputFile << "Runnumber " << runNumber << endl;
761  outputFile << "BeginTimeOfFit " << formatTime(beginTimeOfFit >> 32) << " " << (beginTimeOfFit >> 32) << endl;
762  outputFile << "EndTimeOfFit " << formatTime(endTimeOfFit >> 32) << " " << (endTimeOfFit >> 32) << endl;
763  outputFile << "LumiRange " << beginLumiOfFit << " - " << endLumiOfFit << endl;
764  outputFile << "Type " << dataType << endl;
765  // 3D Vertexing with Pixel Tracks:
766  // Good data = Type 3
767  // Bad data = Type -1
768 
769  BufferString << *(it+0);
770  outputFile << "X0 " << BufferString.str().c_str() << endl;
771  BufferString.str("");
772 
773  BufferString << *(it+1);
774  outputFile << "Y0 " << BufferString.str().c_str() << endl;
775  BufferString.str("");
776 
777  BufferString << *(it+2);
778  outputFile << "Z0 " << BufferString.str().c_str() << endl;
779  BufferString.str("");
780 
781  BufferString << *(it+5);
782  outputFile << "sigmaZ0 " << BufferString.str().c_str() << endl;
783  BufferString.str("");
784 
785  BufferString << *(it+6);
786  outputFile << "dxdz " << BufferString.str().c_str() << endl;
787  BufferString.str("");
788 
789  BufferString << *(it+7);
790  outputFile << "dydz " << BufferString.str().c_str() << endl;
791  BufferString.str("");
792 
793  BufferString << *(it+3);
794  outputFile << "BeamWidthX " << BufferString.str().c_str() << endl;
795  BufferString.str("");
796 
797  BufferString << *(it+4);
798  outputFile << "BeamWidthY " << BufferString.str().c_str() << endl;
799  BufferString.str("");
800 
801  outputFile << "Cov(0,j) " << *(it+8) << " 0 0 0 0 0 0" << endl;
802  outputFile << "Cov(1,j) 0 " << *(it+9) << " 0 0 0 0 0" << endl;
803  outputFile << "Cov(2,j) 0 0 " << *(it+10) << " 0 0 0 0" << endl;
804  outputFile << "Cov(3,j) 0 0 0 " << *(it+13) << " 0 0 0" << endl;
805  outputFile << "Cov(4,j) 0 0 0 0 " << *(it+14) << " 0 0" << endl;
806  outputFile << "Cov(5,j) 0 0 0 0 0 " << *(it+15) << " 0" << endl;
807  outputFile << "Cov(6,j) 0 0 0 0 0 0 " << ((*(it+11)) + (*(it+12)) + 2.*std::sqrt((*(it+11))*(*(it+12)))) / 4. << endl;
808 
809  outputFile << "EmittanceX 0" << endl;
810  outputFile << "EmittanceY 0" << endl;
811  outputFile << "BetaStar 0" << endl;
812  outputFile << "events 0" << endl;
813  outputFile << "meanPV 0" << endl;
814  outputFile << "meanErrPV 0" << endl;
815  outputFile << "rmsPV 0" << endl;
816  outputFile << "rmsErrPV 0" << endl;
817  outputFile << "maxPV 0" << endl;
818  outputFile << "nPV " << counterVx << endl;
819  }
820  outputFile.close();
821 
822  if ((debugMode == true) && (outputDebugFile.is_open() == true) && (vals != nullptr) && (vals->size() == (nParams-1)*2))
823  {
824  vector<double>::const_iterator it = vals->begin();
825 
826  outputDebugFile << "Runnumber " << runNumber << endl;
827  outputDebugFile << "BeginTimeOfFit " << formatTime(beginTimeOfFit >> 32) << " " << (beginTimeOfFit >> 32) << endl;
828  outputDebugFile << "EndTimeOfFit " << formatTime(endTimeOfFit >> 32) << " " << (endTimeOfFit >> 32) << endl;
829  outputDebugFile << "LumiRange " << beginLumiOfFit << " - " << endLumiOfFit << endl;
830  outputDebugFile << "Type " << dataType << endl;
831  // 3D Vertexing with Pixel Tracks:
832  // Good data = Type 3
833  // Bad data = Type -1
834 
835  BufferString << *(it+0);
836  outputDebugFile << "X0 " << BufferString.str().c_str() << endl;
837  BufferString.str("");
838 
839  BufferString << *(it+1);
840  outputDebugFile << "Y0 " << BufferString.str().c_str() << endl;
841  BufferString.str("");
842 
843  BufferString << *(it+2);
844  outputDebugFile << "Z0 " << BufferString.str().c_str() << endl;
845  BufferString.str("");
846 
847  BufferString << *(it+5);
848  outputDebugFile << "sigmaZ0 " << BufferString.str().c_str() << endl;
849  BufferString.str("");
850 
851  BufferString << *(it+6);
852  outputDebugFile << "dxdz " << BufferString.str().c_str() << endl;
853  BufferString.str("");
854 
855  BufferString << *(it+7);
856  outputDebugFile << "dydz " << BufferString.str().c_str() << endl;
857  BufferString.str("");
858 
859  BufferString << *(it+3);
860  outputDebugFile << "BeamWidthX " << BufferString.str().c_str() << endl;
861  BufferString.str("");
862 
863  BufferString << *(it+4);
864  outputDebugFile << "BeamWidthY " << BufferString.str().c_str() << endl;
865  BufferString.str("");
866 
867  outputDebugFile << "Cov(0,j) " << *(it+8) << " 0 0 0 0 0 0" << endl;
868  outputDebugFile << "Cov(1,j) 0 " << *(it+9) << " 0 0 0 0 0" << endl;
869  outputDebugFile << "Cov(2,j) 0 0 " << *(it+10) << " 0 0 0 0" << endl;
870  outputDebugFile << "Cov(3,j) 0 0 0 " << *(it+13) << " 0 0 0" << endl;
871  outputDebugFile << "Cov(4,j) 0 0 0 0 " << *(it+14) << " 0 0" << endl;
872  outputDebugFile << "Cov(5,j) 0 0 0 0 0 " << *(it+15) << " 0" << endl;
873  outputDebugFile << "Cov(6,j) 0 0 0 0 0 0 " << ((*(it+11)) + (*(it+12)) + 2.*std::sqrt((*(it+11))*(*(it+12)))) / 4. << endl;
874 
875  outputDebugFile << "EmittanceX 0" << endl;
876  outputDebugFile << "EmittanceY 0" << endl;
877  outputDebugFile << "BetaStar 0" << endl;
878  outputDebugFile << "events 0" << endl;
879  outputDebugFile << "meanPV 0" << endl;
880  outputDebugFile << "meanErrPV 0" << endl;
881  outputDebugFile << "rmsPV 0" << endl;
882  outputDebugFile << "rmsErrPV 0" << endl;
883  outputDebugFile << "maxPV 0" << endl;
884  outputDebugFile << "nPV " << counterVx << endl;
885 
886  outputDebugFile << "\n" << "Used vertices: " << counterVx << "\n" << endl;
887  }
888 }
889 
890 
891 void Vx3DHLTAnalyzer::printFitParams (const vector<double>& fitResults)
892 {
893  cout << "var x --> " << fitResults[0] << " +/- " << fitResults[0+nParams] << endl;
894  cout << "var y --> " << fitResults[1] << " +/- " << fitResults[1+nParams] << endl;
895  cout << "var z --> " << fitResults[2] << " +/- " << fitResults[2+nParams] << endl;
896  cout << "cov xy --> " << fitResults[3] << " +/- " << fitResults[3+nParams] << endl;
897  cout << "dydz --> " << fitResults[4] << " +/- " << fitResults[4+nParams] << endl;
898  cout << "dxdz --> " << fitResults[5] << " +/- " << fitResults[5+nParams] << endl;
899  cout << "mean x --> " << fitResults[6] << " +/- " << fitResults[6+nParams] << endl;
900  cout << "mean y --> " << fitResults[7] << " +/- " << fitResults[7+nParams] << endl;
901  cout << "mean z --> " << fitResults[8] << " +/- " << fitResults[8+nParams] << endl;
902 }
903 
904 
906 {
907  // @@@ If statement to avoid problems with non-sequential lumisections @@@
908  if ((lumiCounter == 0) && (lumiBlock.luminosityBlock() > lastLumiOfFit))
909  {
910  beginTimeOfFit = lumiBlock.beginTime().value();
911  beginLumiOfFit = lumiBlock.luminosityBlock();
912  lumiCounter++;
913  }
914  else if ((lumiCounter != 0) && (lumiBlock.luminosityBlock() >= (beginLumiOfFit+lumiCounter))) lumiCounter++;
915  else reset("scratch");
916 }
917 
918 
919 void Vx3DHLTAnalyzer::endLuminosityBlock (const LuminosityBlock& lumiBlock, const EventSetup& iSetup)
920 {
921  stringstream histTitle;
922  double minXfit, maxXfit;
923  int goodData;
924 
925  if ((nLumiFit != 0) && (lumiCounter%nLumiFit == 0) && (beginTimeOfFit != 0) && (runNumber != 0))
926  {
927  endTimeOfFit = lumiBlock.endTime().value();
928  endLumiOfFit = lumiBlock.luminosityBlock();
929  lastLumiOfFit = endLumiOfFit;
930  vector<double> vals;
931 
932  hitCounter->getTH1()->SetBinContent(lastLumiOfFit, (double)totalHits);
933  hitCounter->getTH1()->SetBinError(lastLumiOfFit, (totalHits != 0 ? 1. : 0.)); // It's not sqrt(n) because we want to weight all entries in the same way for the fit
934 
935  if (dataFromFit == true)
936  {
937  vector<double> fitResults;
938 
939  fitResults.push_back(Vx_X->getTH1()->GetRMS()*Vx_X->getTH1()->GetRMS());
940  fitResults.push_back(Vx_Y->getTH1()->GetRMS()*Vx_Y->getTH1()->GetRMS());
941  fitResults.push_back(Vx_Z->getTH1()->GetRMS()*Vx_Z->getTH1()->GetRMS());
942  fitResults.push_back(0.0);
943  fitResults.push_back(0.0);
944  fitResults.push_back(0.0);
945  fitResults.push_back(Vx_X->getTH1()->GetMean());
946  fitResults.push_back(Vx_Y->getTH1()->GetMean());
947  fitResults.push_back(Vx_Z->getTH1()->GetMean());
948  for (unsigned int i = 0; i < nParams; i++) fitResults.push_back(0.0);
949 
950  if (internalDebug == true)
951  {
952  cout << "[Vx3DHLTAnalyzer]::\t@@@ Beam Spot parameters - prefit @@@" << endl;
953 
954  printFitParams(fitResults);
955 
956  cout << "Runnumber " << runNumber << endl;
957  cout << "BeginTimeOfFit " << formatTime(beginTimeOfFit >> 32) << " " << (beginTimeOfFit >> 32) << endl;
958  cout << "EndTimeOfFit " << formatTime(endTimeOfFit >> 32) << " " << (endTimeOfFit >> 32) << endl;
959  cout << "LumiRange " << beginLumiOfFit << " - " << endLumiOfFit << endl;
960  }
961 
962  goodData = MyFit(&fitResults);
963 
964  if (internalDebug == true)
965  {
966  cout << "[Vx3DHLTAnalyzer]::\t@@@ Beam Spot parameters - postfit @@@" << endl;
967 
968  printFitParams(fitResults);
969 
970  cout << "goodData --> " << goodData << endl;
971  cout << "Used vertices --> " << counterVx << endl;
972  }
973 
974  if (goodData == 0)
975  {
976  vals.push_back(fitResults[6]);
977  vals.push_back(fitResults[7]);
978  vals.push_back(fitResults[8]);
979  vals.push_back(std::sqrt(std::fabs(fitResults[0])));
980  vals.push_back(std::sqrt(std::fabs(fitResults[1])));
981  vals.push_back(std::sqrt(std::fabs(fitResults[2])));
982  vals.push_back(fitResults[5]);
983  vals.push_back(fitResults[4]);
984 
985  vals.push_back(std::pow(fitResults[6+nParams],2.));
986  vals.push_back(std::pow(fitResults[7+nParams],2.));
987  vals.push_back(std::pow(fitResults[8+nParams],2.));
988  vals.push_back(std::pow(std::fabs(fitResults[0+nParams]) / (2.*std::sqrt(std::fabs(fitResults[0]))),2.));
989  vals.push_back(std::pow(std::fabs(fitResults[1+nParams]) / (2.*std::sqrt(std::fabs(fitResults[1]))),2.));
990  vals.push_back(std::pow(std::fabs(fitResults[2+nParams]) / (2.*std::sqrt(std::fabs(fitResults[2]))),2.));
991  vals.push_back(std::pow(fitResults[5+nParams],2.));
992  vals.push_back(std::pow(fitResults[4+nParams],2.));
993  }
994  else for (unsigned int i = 0; i < (nParams-1)*2; i++) vals.push_back(0.0);
995 
996  fitResults.clear();
997  }
998  else
999  {
1000  counterVx = Vx_X->getTH1F()->GetEntries();
1001 
1002  if (Vx_X->getTH1F()->GetEntries() >= minNentries)
1003  {
1004  goodData = 0;
1005 
1006  vals.push_back(Vx_X->getTH1F()->GetMean());
1007  vals.push_back(Vx_Y->getTH1F()->GetMean());
1008  vals.push_back(Vx_Z->getTH1F()->GetMean());
1009  vals.push_back(Vx_X->getTH1F()->GetRMS());
1010  vals.push_back(Vx_Y->getTH1F()->GetRMS());
1011  vals.push_back(Vx_Z->getTH1F()->GetRMS());
1012  vals.push_back(0.0);
1013  vals.push_back(0.0);
1014 
1015  vals.push_back(std::pow(Vx_X->getTH1F()->GetMeanError(),2.));
1016  vals.push_back(std::pow(Vx_Y->getTH1F()->GetMeanError(),2.));
1017  vals.push_back(std::pow(Vx_Z->getTH1F()->GetMeanError(),2.));
1018  vals.push_back(std::pow(Vx_X->getTH1F()->GetRMSError(),2.));
1019  vals.push_back(std::pow(Vx_Y->getTH1F()->GetRMSError(),2.));
1020  vals.push_back(std::pow(Vx_Z->getTH1F()->GetRMSError(),2.));
1021  vals.push_back(0.0);
1022  vals.push_back(0.0);
1023  }
1024  else
1025  {
1026  goodData = -2;
1027  for (unsigned int i = 0; i < (nParams-1)*2; i++) vals.push_back(0.0);
1028  }
1029  }
1030 
1031  // vals[0] = X0
1032  // vals[1] = Y0
1033  // vals[2] = Z0
1034  // vals[3] = sigmaX0
1035  // vals[4] = sigmaY0
1036  // vals[5] = sigmaZ0
1037  // vals[6] = dxdz
1038  // vals[7] = dydz
1039 
1040  // vals[8] = err^2 X0
1041  // vals[9] = err^2 Y0
1042  // vals[10] = err^2 Z0
1043  // vals[11] = err^2 sigmaX0
1044  // vals[12] = err^2 sigmaY0
1045  // vals[13] = err^2 sigmaZ0
1046  // vals[14] = err^2 dxdz
1047  // vals[15] = err^2 dydz
1048 
1049  numberFits++;
1050  writeToFile(&vals, beginTimeOfFit, endTimeOfFit, beginLumiOfFit, endLumiOfFit, 3);
1051  if (internalDebug == true) cout << "[Vx3DHLTAnalyzer]::\tUsed vertices: " << counterVx << endl;
1052 
1053  statusCounter->getTH1()->SetBinContent(lastLumiOfFit, (double)goodData);
1054  statusCounter->getTH1()->SetBinError(lastLumiOfFit, 1e-3);
1055 
1056  // Copy vertex position histograms into to-fit histograms
1057  if (goodData == 0) reset("fit");
1058  else if (lumiCounter >= maxLumiIntegration)
1059  {
1060  reset("fit");
1061  reset("whole");
1062  }
1063 
1064  for (int i = 0; i < Vx_X_Fit->getTH1()->GetNbinsX(); i++)
1065  {
1066  Vx_X_Fit->getTH1()->SetBinContent(i+1,Vx_X_Fit->getTH1()->GetBinContent(i+1) + Vx_X->getTH1()->GetBinContent(i+1));
1067  Vx_X_Fit->getTH1()->SetBinError(i+1,sqrt(Vx_X_Fit->getTH1()->GetBinContent(i+1)));
1068  }
1069 
1070  for (int i = 0; i < Vx_Y_Fit->getTH1()->GetNbinsX(); i++)
1071  {
1072  Vx_Y_Fit->getTH1()->SetBinContent(i+1,Vx_Y_Fit->getTH1()->GetBinContent(i+1) + Vx_Y->getTH1()->GetBinContent(i+1));
1073  Vx_Y_Fit->getTH1()->SetBinError(i+1,sqrt(Vx_Y_Fit->getTH1()->GetBinContent(i+1)));
1074  }
1075 
1076  for (int i = 0; i < Vx_Z_Fit->getTH1()->GetNbinsX(); i++)
1077  {
1078  Vx_Z_Fit->getTH1()->SetBinContent(i+1,Vx_Z_Fit->getTH1()->GetBinContent(i+1) + Vx_Z->getTH1()->GetBinContent(i+1));
1079  Vx_Z_Fit->getTH1()->SetBinError(i+1,sqrt(Vx_Z_Fit->getTH1()->GetBinContent(i+1)));
1080  }
1081 
1082  // Check data quality
1083  if (goodData == 0)
1084  {
1085  numberGoodFits++;
1086 
1087  histTitle << "Ongoing: fitted lumis " << beginLumiOfFit << " - " << endLumiOfFit;
1088  reset("whole");
1089  }
1090  else
1091  {
1092  if (goodData == -2) histTitle << "Ongoing: not enough evts (" << lumiCounter << " - " << maxLumiIntegration << " lumis)";
1093  else histTitle << "Ongoing: temporary problems (" << lumiCounter << " - " << maxLumiIntegration << " lumis)";
1094 
1095  if (lumiCounter >= maxLumiIntegration)
1096  {
1097  statusCounter->getTH1()->SetBinContent(lastLumiOfFit, -5);
1098  statusCounter->getTH1()->SetBinError(lastLumiOfFit, 1e-3);
1099  }
1100  else reset("hitCounter");
1101  }
1102 
1103  reportSummary->Fill((numberFits != 0 ? ((double)numberGoodFits) / ((double)numberFits) : -1));
1104  reportSummaryMap->getTH1()->SetBinContent(1, 1, (numberFits != 0 ? ((double)numberGoodFits) / ((double)numberFits) : -1));
1105 
1106  fitResults->setAxisTitle(histTitle.str(), 1);
1107 
1108  fitResults->setBinContent(1, 9, vals[0]);
1109  fitResults->setBinContent(1, 8, vals[1]);
1110  fitResults->setBinContent(1, 7, vals[2]);
1111  fitResults->setBinContent(1, 6, vals[3]);
1112  fitResults->setBinContent(1, 5, vals[4]);
1113  fitResults->setBinContent(1, 4, vals[5]);
1114  fitResults->setBinContent(1, 3, vals[6]);
1115  fitResults->setBinContent(1, 2, vals[7]);
1116  fitResults->setBinContent(1, 1, counterVx);
1117 
1118  fitResults->setBinContent(2, 9, std::sqrt(vals[8]));
1119  fitResults->setBinContent(2, 8, std::sqrt(vals[9]));
1120  fitResults->setBinContent(2, 7, std::sqrt(vals[10]));
1121  fitResults->setBinContent(2, 6, std::sqrt(vals[11]));
1122  fitResults->setBinContent(2, 5, std::sqrt(vals[12]));
1123  fitResults->setBinContent(2, 4, std::sqrt(vals[13]));
1124  fitResults->setBinContent(2, 3, std::sqrt(vals[14]));
1125  fitResults->setBinContent(2, 2, std::sqrt(vals[15]));
1126  fitResults->setBinContent(2, 1, std::sqrt(counterVx));
1127 
1128  // Linear fit to the historical plots
1129  TF1* myLinFit = new TF1("myLinFit", "[0] + [1]*x", mXlumi->getTH1()->GetXaxis()->GetXmin(), mXlumi->getTH1()->GetXaxis()->GetXmax());
1130  myLinFit->SetLineColor(2);
1131  myLinFit->SetLineWidth(2);
1132  myLinFit->SetParName(0,"Inter.");
1133  myLinFit->SetParName(1,"Slope");
1134 
1135  mXlumi->getTH1()->SetBinContent(lastLumiOfFit, vals[0]);
1136  mXlumi->getTH1()->SetBinError(lastLumiOfFit, std::sqrt(vals[8]));
1137  myLinFit->SetParameter(0, mXlumi->getTH1()->GetMean(2));
1138  myLinFit->SetParameter(1, 0.0);
1139  mXlumi->getTH1()->Fit(myLinFit,"QR");
1140 
1141  mYlumi->getTH1()->SetBinContent(lastLumiOfFit, vals[1]);
1142  mYlumi->getTH1()->SetBinError(lastLumiOfFit, std::sqrt(vals[9]));
1143  myLinFit->SetParameter(0, mYlumi->getTH1()->GetMean(2));
1144  myLinFit->SetParameter(1, 0.0);
1145  mYlumi->getTH1()->Fit(myLinFit,"QR");
1146 
1147  mZlumi->getTH1()->SetBinContent(lastLumiOfFit, vals[2]);
1148  mZlumi->getTH1()->SetBinError(lastLumiOfFit, std::sqrt(vals[10]));
1149  myLinFit->SetParameter(0, mZlumi->getTH1()->GetMean(2));
1150  myLinFit->SetParameter(1, 0.0);
1151  mZlumi->getTH1()->Fit(myLinFit,"QR");
1152 
1153  sXlumi->getTH1()->SetBinContent(lastLumiOfFit, vals[3]);
1154  sXlumi->getTH1()->SetBinError(lastLumiOfFit, std::sqrt(vals[11]));
1155  myLinFit->SetParameter(0, sXlumi->getTH1()->GetMean(2));
1156  myLinFit->SetParameter(1, 0.0);
1157  sXlumi->getTH1()->Fit(myLinFit,"QR");
1158 
1159  sYlumi->getTH1()->SetBinContent(lastLumiOfFit, vals[4]);
1160  sYlumi->getTH1()->SetBinError(lastLumiOfFit, std::sqrt(vals[12]));
1161  myLinFit->SetParameter(0, sYlumi->getTH1()->GetMean(2));
1162  myLinFit->SetParameter(1, 0.0);
1163  sYlumi->getTH1()->Fit(myLinFit,"QR");
1164 
1165  sZlumi->getTH1()->SetBinContent(lastLumiOfFit, vals[5]);
1166  sZlumi->getTH1()->SetBinError(lastLumiOfFit, std::sqrt(vals[13]));
1167  myLinFit->SetParameter(0, sZlumi->getTH1()->GetMean(2));
1168  myLinFit->SetParameter(1, 0.0);
1169  sZlumi->getTH1()->Fit(myLinFit,"QR");
1170 
1171  dxdzlumi->getTH1()->SetBinContent(lastLumiOfFit, vals[6]);
1172  dxdzlumi->getTH1()->SetBinError(lastLumiOfFit, std::sqrt(vals[14]));
1173  myLinFit->SetParameter(0, dxdzlumi->getTH1()->GetMean(2));
1174  myLinFit->SetParameter(1, 0.0);
1175  dxdzlumi->getTH1()->Fit(myLinFit,"QR");
1176 
1177  dydzlumi->getTH1()->SetBinContent(lastLumiOfFit, vals[7]);
1178  dydzlumi->getTH1()->SetBinError(lastLumiOfFit, std::sqrt(vals[15]));
1179  myLinFit->SetParameter(0, dydzlumi->getTH1()->GetMean(2));
1180  myLinFit->SetParameter(1, 0.0);
1181  dydzlumi->getTH1()->Fit(myLinFit,"QR");
1182 
1183  myLinFit->SetParameter(0, hitCounter->getTH1()->GetMean(2));
1184  myLinFit->SetParameter(1, 0.0);
1185  hitCounter->getTH1()->Fit(myLinFit,"QR");
1186 
1187  goodVxCounter->getTH1()->SetBinContent(lastLumiOfFit, (double)counterVx);
1188  goodVxCounter->getTH1()->SetBinError(lastLumiOfFit, (counterVx != 0 ? 1. : 0.)); // It's not sqrt(n) because we want to weight all entries in the same way for the fit
1189  myLinFit->SetParameter(0, goodVxCounter->getTH1()->GetMean(2));
1190  myLinFit->SetParameter(1, 0.0);
1191  goodVxCounter->getTH1()->Fit(myLinFit,"QR");
1192 
1193  delete myLinFit;
1194  vals.clear();
1195 
1196  // Gaussian fit to 1D vertex coordinate distributions
1197  TF1* myGaussFit = new TF1("myGaussFit", "[0]*exp(-(x-[1])*(x-[1])/(2*[2]*[2]))", Vx_Z_Fit->getTH1()->GetXaxis()->GetXmin(), Vx_Z_Fit->getTH1()->GetXaxis()->GetXmax());
1198  myGaussFit->SetLineColor(2);
1199  myGaussFit->SetLineWidth(2);
1200  myGaussFit->SetParName(0,"Ampl.");
1201  myGaussFit->SetParName(1,"#mu");
1202  myGaussFit->SetParName(2,"#sigma");
1203 
1204  myGaussFit->SetParameter(0, Vx_X_Fit->getTH1()->GetMaximum());
1205  myGaussFit->SetParameter(1, Vx_X_Fit->getTH1()->GetMean());
1206  myGaussFit->SetParameter(2, Vx_X_Fit->getTH1()->GetRMS());
1207  minXfit = Vx_X_Fit->getTH1()->GetBinLowEdge(1);
1208  for (int i = 0; i < Vx_X_Fit->getTH1()->GetNbinsX(); i++)
1209  {
1210  if (Vx_X_Fit->getTH1()->GetBinContent(i+1) > 0)
1211  {
1212  minXfit = Vx_X_Fit->getTH1()->GetBinLowEdge(i+1);
1213  break;
1214  }
1215  }
1216  maxXfit = Vx_X_Fit->getTH1()->GetBinLowEdge(Vx_X_Fit->getTH1()->GetNbinsX());
1217  for (int i = Vx_X_Fit->getTH1()->GetNbinsX(); i > 0; i--)
1218  {
1219  if (Vx_X_Fit->getTH1()->GetBinContent(i) > 0)
1220  {
1221  maxXfit = Vx_X_Fit->getTH1()->GetBinLowEdge(i);
1222  break;
1223  }
1224  }
1225  myGaussFit->SetRange(minXfit - (maxXfit-minXfit)/2.,maxXfit + (maxXfit-minXfit)/2.);
1226  Vx_X_Fit->getTH1()->Fit(myGaussFit,"QR");
1227 
1228  myGaussFit->SetParameter(0, Vx_Y_Fit->getTH1()->GetMaximum());
1229  myGaussFit->SetParameter(1, Vx_Y_Fit->getTH1()->GetMean());
1230  myGaussFit->SetParameter(2, Vx_Y_Fit->getTH1()->GetRMS());
1231  minXfit = Vx_Y_Fit->getTH1()->GetBinLowEdge(1);
1232  for (int i = 0; i < Vx_Y_Fit->getTH1()->GetNbinsX(); i++)
1233  {
1234  if (Vx_Y_Fit->getTH1()->GetBinContent(i+1) > 0)
1235  {
1236  minXfit = Vx_Y_Fit->getTH1()->GetBinLowEdge(i+1);
1237  break;
1238  }
1239  }
1240  maxXfit = Vx_Y_Fit->getTH1()->GetBinLowEdge(Vx_Y_Fit->getTH1()->GetNbinsX());
1241  for (int i = Vx_Y_Fit->getTH1()->GetNbinsX(); i > 0; i--)
1242  {
1243  if (Vx_Y_Fit->getTH1()->GetBinContent(i) > 0)
1244  {
1245  maxXfit = Vx_Y_Fit->getTH1()->GetBinLowEdge(i);
1246  break;
1247  }
1248  }
1249  myGaussFit->SetRange(minXfit - (maxXfit-minXfit)/2.,maxXfit + (maxXfit-minXfit)/2.);
1250  Vx_Y_Fit->getTH1()->Fit(myGaussFit,"QR");
1251 
1252  myGaussFit->SetParameter(0, Vx_Z_Fit->getTH1()->GetMaximum());
1253  myGaussFit->SetParameter(1, Vx_Z_Fit->getTH1()->GetMean());
1254  myGaussFit->SetParameter(2, Vx_Z_Fit->getTH1()->GetRMS());
1255  minXfit = Vx_Z_Fit->getTH1()->GetBinLowEdge(1);
1256  for (int i = 0; i < Vx_Z_Fit->getTH1()->GetNbinsX(); i++)
1257  {
1258  if (Vx_Z_Fit->getTH1()->GetBinContent(i+1) > 0)
1259  {
1260  minXfit = Vx_Z_Fit->getTH1()->GetBinLowEdge(i+1);
1261  break;
1262  }
1263  }
1264  maxXfit = Vx_Z_Fit->getTH1()->GetBinLowEdge(Vx_Z_Fit->getTH1()->GetNbinsX());
1265  for (int i = Vx_Z_Fit->getTH1()->GetNbinsX(); i > 0; i--)
1266  {
1267  if (Vx_Z_Fit->getTH1()->GetBinContent(i) > 0)
1268  {
1269  maxXfit = Vx_Z_Fit->getTH1()->GetBinLowEdge(i);
1270  break;
1271  }
1272  }
1273  myGaussFit->SetRange(minXfit - (maxXfit-minXfit)/2.,maxXfit + (maxXfit-minXfit)/2.);
1274  Vx_Z_Fit->getTH1()->Fit(myGaussFit,"QR");
1275 
1276  delete myGaussFit;
1277  }
1278  else if ((nLumiFit != 0) && (lumiCounter%nLumiFit != 0) && (beginTimeOfFit != 0) && (runNumber != 0))
1279  {
1280  histTitle << "Ongoing: accumulating evts (" << lumiCounter%nLumiFit << " - " << nLumiFit << " in " << lumiCounter << " - " << maxLumiIntegration << " lumis)";
1281  fitResults->setAxisTitle(histTitle.str(), 1);
1282  if ((debugMode == true) && (outputDebugFile.is_open() == true))
1283  {
1284  outputDebugFile << "\n" << "Runnumber " << runNumber << endl;
1285  outputDebugFile << "BeginTimeOfFit " << formatTime(beginTimeOfFit >> 32) << " " << (beginTimeOfFit >> 32) << endl;
1286  outputDebugFile << "BeginLumiRange " << beginLumiOfFit << endl;
1287  outputDebugFile << histTitle.str().c_str() << "\n" << endl;
1288  }
1289  }
1290  else if ((nLumiFit == 0) || (beginTimeOfFit == 0) || (runNumber == 0))
1291  {
1292  histTitle << "Ongoing: no ongoing fits";
1293  fitResults->setAxisTitle(histTitle.str(), 1);
1294  if ((debugMode == true) && (outputDebugFile.is_open() == true)) outputDebugFile << histTitle.str().c_str() << "\n" << endl;
1295 
1296  endLumiOfFit = lumiBlock.luminosityBlock();
1297 
1298  hitCounter->getTH1()->SetBinContent(endLumiOfFit, (double)totalHits);
1299  hitCounter->getTH1()->SetBinError(endLumiOfFit, std::sqrt((double)totalHits));
1300 
1301  reset("whole");
1302  }
1303 
1304  if (internalDebug == true) cout << "[Vx3DHLTAnalyzer]::\tHistogram title: " << histTitle.str() << endl;
1305 }
1306 
1307 
1308 void Vx3DHLTAnalyzer::bookHistograms(DQMStore::IBooker & ibooker, Run const & iRun, EventSetup const & /* iSetup */)
1309 {
1310  ibooker.setCurrentFolder("BeamPixel");
1311 
1312  Vx_X = ibooker.book1D("F - vertex x", "Primary Vertex X Distribution", int(rint(xRange/xStep)), -xRange/2., xRange/2.);
1313  Vx_Y = ibooker.book1D("F - vertex y", "Primary Vertex Y Distribution", int(rint(yRange/yStep)), -yRange/2., yRange/2.);
1314  Vx_Z = ibooker.book1D("F - vertex z", "Primary Vertex Z Distribution", int(rint(zRange/zStep)), -zRange/2., zRange/2.);
1315  Vx_X->setAxisTitle("Primary Vertices X [cm]",1);
1316  Vx_X->setAxisTitle("Entries [#]",2);
1317  Vx_Y->setAxisTitle("Primary Vertices Y [cm]",1);
1318  Vx_Y->setAxisTitle("Entries [#]",2);
1319  Vx_Z->setAxisTitle("Primary Vertices Z [cm]",1);
1320  Vx_Z->setAxisTitle("Entries [#]",2);
1321 
1322  Vx_X_Fit = ibooker.book1D("G - vertex x fit", "Primary Vertex X Distribution (For Fit)", int(rint(xRange/xStep)), -xRange/2., xRange/2.);
1323  Vx_Y_Fit = ibooker.book1D("G - vertex y fit", "Primary Vertex Y Distribution (For Fit)", int(rint(yRange/yStep)), -yRange/2., yRange/2.);
1324  Vx_Z_Fit = ibooker.book1D("G - vertex z fit", "Primary Vertex Z Distribution (For Fit)", int(rint(zRange/zStep)), -zRange/2., zRange/2.);
1325  Vx_X_Fit->setAxisTitle("Primary Vertices X [cm]",1);
1326  Vx_X_Fit->setAxisTitle("Entries [#]",2);
1327  Vx_Y_Fit->setAxisTitle("Primary Vertices Y [cm]",1);
1328  Vx_Y_Fit->setAxisTitle("Entries [#]",2);
1329  Vx_Z_Fit->setAxisTitle("Primary Vertices Z [cm]",1);
1330  Vx_Z_Fit->setAxisTitle("Entries [#]",2);
1331 
1332  Vx_X_Cum = ibooker.book1D("I - vertex x cum", "Primary Vertex X Distribution (Cumulative)", int(rint(xRange/xStep)), -xRange/2., xRange/2.);
1333  Vx_Y_Cum = ibooker.book1D("I - vertex y cum", "Primary Vertex Y Distribution (Cumulative)", int(rint(yRange/yStep)), -yRange/2., yRange/2.);
1334  Vx_Z_Cum = ibooker.book1D("I - vertex z cum", "Primary Vertex Z Distribution (Cumulative)", int(rint(zRange/zStep)), -zRange/2., zRange/2.);
1335  Vx_X_Cum->setAxisTitle("Primary Vertices X [cm]",1);
1336  Vx_X_Cum->setAxisTitle("Entries [#]",2);
1337  Vx_Y_Cum->setAxisTitle("Primary Vertices Y [cm]",1);
1338  Vx_Y_Cum->setAxisTitle("Entries [#]",2);
1339  Vx_Z_Cum->setAxisTitle("Primary Vertices Z [cm]",1);
1340  Vx_Z_Cum->setAxisTitle("Entries [#]",2);
1341 
1342  mXlumi = ibooker.book1D("B - muX vs lumi", "#mu_{x} vs. Lumisection", nLumiXaxisRange, 0.5, ((double)nLumiXaxisRange)+0.5);
1343  mYlumi = ibooker.book1D("B - muY vs lumi", "#mu_{y} vs. Lumisection", nLumiXaxisRange, 0.5, ((double)nLumiXaxisRange)+0.5);
1344  mZlumi = ibooker.book1D("B - muZ vs lumi", "#mu_{z} vs. Lumisection", nLumiXaxisRange, 0.5, ((double)nLumiXaxisRange)+0.5);
1345  mXlumi->setAxisTitle("Lumisection [#]",1);
1346  mXlumi->setAxisTitle("#mu_{x} [cm]",2);
1347  mXlumi->getTH1()->SetOption("E1");
1348  mYlumi->setAxisTitle("Lumisection [#]",1);
1349  mYlumi->setAxisTitle("#mu_{y} [cm]",2);
1350  mYlumi->getTH1()->SetOption("E1");
1351  mZlumi->setAxisTitle("Lumisection [#]",1);
1352  mZlumi->setAxisTitle("#mu_{z} [cm]",2);
1353  mZlumi->getTH1()->SetOption("E1");
1354 
1355  sXlumi = ibooker.book1D("C - sigmaX vs lumi", "#sigma_{x} vs. Lumisection", nLumiXaxisRange, 0.5, ((double)nLumiXaxisRange)+0.5);
1356  sYlumi = ibooker.book1D("C - sigmaY vs lumi", "#sigma_{y} vs. Lumisection", nLumiXaxisRange, 0.5, ((double)nLumiXaxisRange)+0.5);
1357  sZlumi = ibooker.book1D("C - sigmaZ vs lumi", "#sigma_{z} vs. Lumisection", nLumiXaxisRange, 0.5, ((double)nLumiXaxisRange)+0.5);
1358  sXlumi->setAxisTitle("Lumisection [#]",1);
1359  sXlumi->setAxisTitle("#sigma_{x} [cm]",2);
1360  sXlumi->getTH1()->SetOption("E1");
1361  sYlumi->setAxisTitle("Lumisection [#]",1);
1362  sYlumi->setAxisTitle("#sigma_{y} [cm]",2);
1363  sYlumi->getTH1()->SetOption("E1");
1364  sZlumi->setAxisTitle("Lumisection [#]",1);
1365  sZlumi->setAxisTitle("#sigma_{z} [cm]",2);
1366  sZlumi->getTH1()->SetOption("E1");
1367 
1368  dxdzlumi = ibooker.book1D("D - dxdz vs lumi", "dX/dZ vs. Lumisection", nLumiXaxisRange, 0.5, ((double)nLumiXaxisRange)+0.5);
1369  dydzlumi = ibooker.book1D("D - dydz vs lumi", "dY/dZ vs. Lumisection", nLumiXaxisRange, 0.5, ((double)nLumiXaxisRange)+0.5);
1370  dxdzlumi->setAxisTitle("Lumisection [#]",1);
1371  dxdzlumi->setAxisTitle("dX/dZ [rad]",2);
1372  dxdzlumi->getTH1()->SetOption("E1");
1373  dydzlumi->setAxisTitle("Lumisection [#]",1);
1374  dydzlumi->setAxisTitle("dY/dZ [rad]",2);
1375  dydzlumi->getTH1()->SetOption("E1");
1376 
1377  Vx_ZX = ibooker.book2D("E - vertex zx", "Primary Vertex ZX Distribution", int(rint(zRange/zStep)), -zRange/2., zRange/2., int(rint(xRange/xStep)), -xRange/2., xRange/2.);
1378  Vx_ZY = ibooker.book2D("E - vertex zy", "Primary Vertex ZY Distribution", int(rint(zRange/zStep)), -zRange/2., zRange/2., int(rint(yRange/yStep)), -yRange/2., yRange/2.);
1379  Vx_XY = ibooker.book2D("E - vertex xy", "Primary Vertex XY Distribution", int(rint(xRange/xStep)), -xRange/2., xRange/2., int(rint(yRange/yStep)), -yRange/2., yRange/2.);
1380  Vx_ZX->setAxisTitle("Primary Vertices Z [cm]",1);
1381  Vx_ZX->setAxisTitle("Primary Vertices X [cm]",2);
1382  Vx_ZX->setAxisTitle("Entries [#]",3);
1383  Vx_ZY->setAxisTitle("Primary Vertices Z [cm]",1);
1384  Vx_ZY->setAxisTitle("Primary Vertices Y [cm]",2);
1385  Vx_ZY->setAxisTitle("Entries [#]",3);
1386  Vx_XY->setAxisTitle("Primary Vertices X [cm]",1);
1387  Vx_XY->setAxisTitle("Primary Vertices Y [cm]",2);
1388  Vx_XY->setAxisTitle("Entries [#]",3);
1389 
1390  Vx_ZX_Cum = ibooker.book2D("H - vertex zx cum", "Primary Vertex ZX Distribution (Cumulative)", int(rint(zRange/zStep)), -zRange/2., zRange/2., int(rint(xRange/xStep)), -xRange/2., xRange/2.);
1391  Vx_ZY_Cum = ibooker.book2D("H - vertex zy cum", "Primary Vertex ZY Distribution (Cumulative)", int(rint(zRange/zStep)), -zRange/2., zRange/2., int(rint(yRange/yStep)), -yRange/2., yRange/2.);
1392  Vx_XY_Cum = ibooker.book2D("H - vertex xy cum", "Primary Vertex XY Distribution (Cumulative)", int(rint(xRange/xStep)), -xRange/2., xRange/2., int(rint(yRange/yStep)), -yRange/2., yRange/2.);
1393  Vx_ZX_Cum->setAxisTitle("Primary Vertices Z [cm]",1);
1394  Vx_ZX_Cum->setAxisTitle("Primary Vertices X [cm]",2);
1395  Vx_ZX_Cum->setAxisTitle("Entries [#]",3);
1396  Vx_ZY_Cum->setAxisTitle("Primary Vertices Z [cm]",1);
1397  Vx_ZY_Cum->setAxisTitle("Primary Vertices Y [cm]",2);
1398  Vx_ZY_Cum->setAxisTitle("Entries [#]",3);
1399  Vx_XY_Cum->setAxisTitle("Primary Vertices X [cm]",1);
1400  Vx_XY_Cum->setAxisTitle("Primary Vertices Y [cm]",2);
1401  Vx_XY_Cum->setAxisTitle("Entries [#]",3);
1402 
1403  hitCounter = ibooker.book1D("J - pixelHits vs lumi", "# Pixel-Hits vs. Lumisection", nLumiXaxisRange, 0.5, ((double)nLumiXaxisRange)+0.5);
1404  hitCounter->setAxisTitle("Lumisection [#]",1);
1405  hitCounter->setAxisTitle("Pixel-Hits [#]",2);
1406  hitCounter->getTH1()->SetOption("E1");
1407 
1408  goodVxCounter = ibooker.book1D("K - good vertices vs lumi", "# Good vertices vs. Lumisection", nLumiXaxisRange, 0.5, ((double)nLumiXaxisRange)+0.5);
1409  goodVxCounter->setAxisTitle("Lumisection [#]",1);
1410  goodVxCounter->setAxisTitle("Good vertices [#]",2);
1411  goodVxCounter->getTH1()->SetOption("E1");
1412 
1413  statusCounter = ibooker.book1D("L - status vs lumi", "App. Status vs. Lumisection", nLumiXaxisRange, 0.5, ((double)nLumiXaxisRange)+0.5);
1414  statusCounter->setAxisTitle("Lumisection [#]",1);
1415  statusCounter->getTH1()->SetOption("E1");
1416  statusCounter->getTH1()->GetYaxis()->Set(11,-5.5,5.5);
1417  statusCounter->getTH1()->GetYaxis()->SetBinLabel(1, "Max Lumi.");
1418  statusCounter->getTH1()->GetYaxis()->SetBinLabel(2, "Neg. det.");
1419  statusCounter->getTH1()->GetYaxis()->SetBinLabel(3, "Infinite err.");
1420  statusCounter->getTH1()->GetYaxis()->SetBinLabel(4, "No vtx.");
1421  statusCounter->getTH1()->GetYaxis()->SetBinLabel(5, "Infinite EDM");
1422  statusCounter->getTH1()->GetYaxis()->SetBinLabel(6, "OK");
1423  statusCounter->getTH1()->GetYaxis()->SetBinLabel(7, "MINUIT stat.");
1424  statusCounter->getTH1()->GetYaxis()->SetBinLabel(8, "MINUIT stat.");
1425  statusCounter->getTH1()->GetYaxis()->SetBinLabel(9, "MINUIT stat.");
1426  statusCounter->getTH1()->GetYaxis()->SetBinLabel(10, "MINUIT stat.");
1427  statusCounter->getTH1()->GetYaxis()->SetBinLabel(11, "MINUIT stat.");
1428 
1429  fitResults = ibooker.book2D("A - fit results","Results of Beam Spot Fit", 2, 0., 2., 9, 0., 9.);
1430  fitResults->setAxisTitle("Ongoing: bootstrapping", 1);
1431  fitResults->setBinLabel(9, "X[cm]", 2);
1432  fitResults->setBinLabel(8, "Y[cm]", 2);
1433  fitResults->setBinLabel(7, "Z[cm]", 2);
1434  fitResults->setBinLabel(6, "#sigma_{X}[cm]", 2);
1435  fitResults->setBinLabel(5, "#sigma_{Y}[cm]", 2);
1436  fitResults->setBinLabel(4, "#sigma_{Z}[cm]", 2);
1437  fitResults->setBinLabel(3, "#frac{dX}{dZ}[rad]", 2);
1438  fitResults->setBinLabel(2, "#frac{dY}{dZ}[rad]", 2);
1439  fitResults->setBinLabel(1, "Vtx[#]", 2);
1440  fitResults->setBinLabel(1, "Value", 1);
1441  fitResults->setBinLabel(2, "Error (stat)", 1);
1442  fitResults->getTH1()->SetOption("text");
1443 
1444 
1445  ibooker.setCurrentFolder("BeamPixel/EventInfo");
1446 
1447  reportSummary = ibooker.bookFloat("reportSummary");
1448  reportSummary->Fill(-1);
1449  reportSummaryMap = ibooker.book2D("reportSummaryMap","Pixel-Vertices Beam Spot: % Good Fits", 1, 0., 1., 1, 0., 1.);
1450  reportSummaryMap->getTH1()->SetBinContent(1, 1, -1);
1451 
1452  ibooker.setCurrentFolder("BeamPixel/EventInfo/reportSummaryContents");
1453 
1454  // Convention for reportSummary and reportSummaryMap:
1455  // - -1% at the moment of creation of the histogram (i.e. white histogram)
1456  // - n% numberGoodFits / numberFits
1457 
1458 
1459  reset("scratch"); // Initialize histograms after creation
1460 }
1461 
1462 
1463 // Define this as a plug-in
RunNumber_t run() const
Definition: EventID.h:39
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
const_iterator end(bool update=false) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
int MyFit(std::vector< double > *vals)
void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) override
void endLuminosityBlock(const edm::LuminosityBlock &lumiBlock, const edm::EventSetup &iSetup) override
TH1 * getTH1() const
data_type const * const_iterator
Definition: DetSetNew.h:30
Timestamp const & beginTime() const
unsigned int HitCounter(const edm::Event &iEvent)
void beginLuminosityBlock(const edm::LuminosityBlock &lumiBlock, const edm::EventSetup &iSetup) override
double Gauss3DFunc(const double *par)
void writeToFile(std::vector< double > *vals, edm::TimeValue_t BeginTimeOfFit, edm::TimeValue_t EndTimeOfFit, unsigned int BeginLumiOfFit, unsigned int EndLumiOfFit, int dataType)
void Fill(long long x)
const Double_t pi
LuminosityBlockNumber_t luminosityBlock() const
static ELstring formatTime(const time_t t)
Definition: ELoutput.cc:100
double Covariance[3][3]
Vx3DHLTAnalyzer(const edm::ParameterSet &)
int iEvent
Definition: GenABIO.cc:230
bool isNotFinite(T x)
Definition: isFinite.h:10
std::string formatTime(const time_t &t)
T sqrt(T t)
Definition: SSEVec.h:18
Timestamp const & endTime() const
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:118
LuminosityBlock const & getLuminosityBlock() const
Definition: Event.h:100
void reset(std::string ResetType)
unsigned long long TimeValue_t
Definition: Timestamp.h:28
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:279
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:136
#define DIM
~Vx3DHLTAnalyzer() override
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
edm::EventID id() const
Definition: EventBase.h:60
fixed size matrix
HLT enums.
void printFitParams(const std::vector< double > &fitResults)
static std::atomic< unsigned int > counter
MonitorElement * bookFloat(Args &&...args)
Definition: DQMStore.h:112
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
void reset(double vett[256])
Definition: TPedValues.cc:11
TimeValue_t value() const
Definition: Timestamp.h:56
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
const_iterator begin(bool update=false) const
Definition: Run.h:43