CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
AlcaBeamMonitor.cc
Go to the documentation of this file.
1 /*
2  * \file AlcaBeamMonitor.cc
3  * \author Lorenzo Uplegger/FNAL
4  *
5  */
6 
14 //#include "DataFormats/Scalers/interface/BeamSpotOnline.h"
25 #include <numeric>
26 //#include <iostream>
27 
28 using namespace std;
29 using namespace edm;
30 using namespace reco;
31 
32 //----------------------------------------------------------------------------------------------------------------------
34  parameters_ (ps),
35  monitorName_ (parameters_.getUntrackedParameter<string>("MonitorName","YourSubsystemName")),
36  primaryVertexLabel_ (consumes<VertexCollection>(
37  parameters_.getUntrackedParameter<InputTag>("PrimaryVertexLabel"))),
38  trackLabel_ (consumes<reco::TrackCollection>(
39  parameters_.getUntrackedParameter<InputTag>("TrackLabel"))),
40  scalerLabel_ (consumes<BeamSpot>(
41  parameters_.getUntrackedParameter<InputTag>("ScalerLabel"))),
42  beamSpotLabel_ (parameters_.getUntrackedParameter<InputTag>("BeamSpotLabel")),
43  numberOfValuesToSave_ (0)
44 {
46 
47  if (monitorName_ != "" ) monitorName_ = monitorName_+"/" ;
48 
54 
56 
57 
58  varNamesV_.push_back("x");
59  varNamesV_.push_back("y");
60  varNamesV_.push_back("z");
61  varNamesV_.push_back("sigmaX");
62  varNamesV_.push_back("sigmaY");
63  varNamesV_.push_back("sigmaZ");
64 
65  histoByCategoryNames_.insert( pair<string,string>("run", "Coordinate"));
66  histoByCategoryNames_.insert( pair<string,string>("run", "PrimaryVertex fit-DataBase"));
67  histoByCategoryNames_.insert( pair<string,string>("run", "PrimaryVertex fit-BeamFit"));
68  histoByCategoryNames_.insert( pair<string,string>("run", "PrimaryVertex fit-Scalers"));
69  histoByCategoryNames_.insert( pair<string,string>("run", "PrimaryVertex-DataBase"));
70  histoByCategoryNames_.insert( pair<string,string>("run", "PrimaryVertex-BeamFit"));
71  histoByCategoryNames_.insert( pair<string,string>("run", "PrimaryVertex-Scalers"));
72 
73  histoByCategoryNames_.insert( pair<string,string>("lumi", "Lumibased BeamSpotFit"));
74  histoByCategoryNames_.insert( pair<string,string>("lumi", "Lumibased PrimaryVertex"));
75  histoByCategoryNames_.insert( pair<string,string>("lumi", "Lumibased DataBase"));
76  histoByCategoryNames_.insert( pair<string,string>("lumi", "Lumibased Scalers"));
77  histoByCategoryNames_.insert( pair<string,string>("lumi", "Lumibased PrimaryVertex-DataBase fit"));
78  histoByCategoryNames_.insert( pair<string,string>("lumi", "Lumibased PrimaryVertex-Scalers fit"));
79  histoByCategoryNames_.insert( pair<string,string>("validation", "Lumibased Scalers-DataBase fit"));
80  histoByCategoryNames_.insert( pair<string,string>("validation", "Lumibased PrimaryVertex-DataBase"));
81  histoByCategoryNames_.insert( pair<string,string>("validation", "Lumibased PrimaryVertex-Scalers"));
82 
83 
84  for(vector<string>::iterator itV=varNamesV_.begin(); itV!=varNamesV_.end(); itV++){
85  for(multimap<string,string>::iterator itM=histoByCategoryNames_.begin(); itM!=histoByCategoryNames_.end(); itM++){
86  if(itM->first=="run"){
87  histosMap_[*itV][itM->first][itM->second] = 0;
88  }
89  else{
90  positionsMap_[*itV][itM->first][itM->second] = 3*numberOfValuesToSave_;//value, error, ok
92  }
93  }
94  }
95 
96 // beamSpotsMap_["BF"] = map<LuminosityBlockNumber_t,BeamSpot>();//For each lumi the beamfitter will have a result
97 // beamSpotsMap_["PV"] = map<LuminosityBlockNumber_t,BeamSpot>();//For each lumi the PVfitter will have a result
98 // beamSpotsMap_["DB"] = map<LuminosityBlockNumber_t,BeamSpot>();//For each lumi we take the values that are stored in the database, already collapsed then
99 // beamSpotsMap_["SC"] = map<LuminosityBlockNumber_t,BeamSpot>();//For each lumi we take the beamspot value in the file that is the same as the scaler for the alca reco stream
100 // beamSpotsMap_["BF"] = 0;//For each lumi the beamfitter will have a result
101 // beamSpotsMap_["PV"] = 0;//For each lumi the PVfitter will have a result
102 // beamSpotsMap_["DB"] = 0;//For each lumi we take the values that are stored in the database, already collapsed then
103 // beamSpotsMap_["SC"] = 0;//For each lumi we take the beamspot value in the file that is the same as the scaler for the alca reco stream
104 }
105 
106 
108  if(theBeamFitter_ != 0){
109  delete theBeamFitter_;
110  }
111 
112  if(thePVFitter_ != 0){
113  delete thePVFitter_;
114  }
115 }
116 
117 
118 //----------------------------------------------------------------------------------------------------------------------
120  string name;
121  string title;
123  for(HistosContainer::iterator itM=histosMap_.begin(); itM!=histosMap_.end(); itM++){
124  for(map<string,MonitorElement*>::iterator itMM=itM->second["run"].begin(); itMM!=itM->second["run"].end(); itMM++){
125  name = string("h") + itM->first + itMM->first;
126  title = itM->first + "_{0} " + itMM->first;
127  if(itM->first == "x" || itM->first == "y"){
128  if(itMM->first == "Coordinate"){
129  itMM->second = dbe_->book1D(name,title,1001,-0.2525,0.2525);
130  }
131  else if(itMM->first == "PrimaryVertex fit-DataBase" || itMM->first == "PrimaryVertex fit-BeamFit" || itMM->first == "PrimaryVertex fit-Scalers"
132  || itMM->first == "PrimaryVertex-DataBase" || itMM->first == "PrimaryVertex-BeamFit" || itMM->first == "PrimaryVertex-Scalers"){
133  itMM->second = dbe_->book1D(name,title,1001,-0.02525,0.02525);
134  }
135  else{
136  //assert(0);
137  }
138  }
139  else if(itM->first == "z"){
140  if(itMM->first == "Coordinate"){
141  itMM->second = dbe_->book1D(name,title,101,-5.05,5.05);
142  }
143  else if(itMM->first == "PrimaryVertex fit-DataBase" || itMM->first == "PrimaryVertex fit-BeamFit" || itMM->first == "PrimaryVertex fit-Scalers"){
144  itMM->second = dbe_->book1D(name,title,101,-0.505,0.505);
145  }
146  else if(itMM->first == "PrimaryVertex-DataBase" || itMM->first == "PrimaryVertex-BeamFit" || itMM->first == "PrimaryVertex-Scalers"){
147  itMM->second = dbe_->book1D(name,title,1001,-5.005,5.005);
148  }
149  else{
150  //assert(0);
151  }
152  }
153  else if(itM->first == "sigmaX" || itM->first == "sigmaY"){
154  if(itMM->first == "Coordinate"){
155  itMM->second = dbe_->book1D(name,title,100,0,0.015);
156  }
157  else if(itMM->first == "PrimaryVertex fit-DataBase" || itMM->first == "PrimaryVertex fit-BeamFit" || itMM->first == "PrimaryVertex fit-Scalers"
158  || itMM->first == "PrimaryVertex-DataBase" || itMM->first == "PrimaryVertex-BeamFit" || itMM->first == "PrimaryVertex-Scalers"){
159  itMM->second = 0;
160  }
161  else{
162  //assert(0);
163  }
164  }
165  else if(itM->first == "sigmaZ"){
166  if(itMM->first == "Coordinate"){
167  itMM->second = dbe_->book1D(name,title,110,0,11);
168  }
169  else if(itMM->first == "PrimaryVertex fit-DataBase" || itMM->first == "PrimaryVertex fit-BeamFit" || itMM->first == "PrimaryVertex fit-Scalers"
170  || itMM->first == "PrimaryVertex-DataBase" || itMM->first == "PrimaryVertex-BeamFit" || itMM->first == "PrimaryVertex-Scalers"){
171  itMM->second = dbe_->book1D(name,title,101,-5.05,5.05);
172  }
173  else{
174  //assert(0);
175  }
176  }
177  else{
178  //assert(0);
179  }
180  if(itMM->second != 0){
181  if(itMM->first == "Coordinate"){
182  itMM->second->setAxisTitle(itM->first + "_{0} (cm)",1);
183  }
184  else if(itMM->first == "PrimaryVertex fit-DataBase" || itMM->first == "PrimaryVertex fit-BeamFit" || itMM->first == "PrimaryVertex fit-Scalers"
185  || itMM->first == "PrimaryVertex-DataBase" || itMM->first == "PrimaryVertex-BeamFit" || itMM->first == "PrimaryVertex-Scalers"){
186  itMM->second->setAxisTitle(itMM->first + " " + itM->first + "_{0} (cm)",1);
187  }
188  itMM->second->setAxisTitle("Entries",2);
189  }
190  }
191  }
192  dbe_->setCurrentFolder(monitorName_+"Service");
193  theValuesContainer_ = dbe_->bookProfile("hHistoLumiValues","Histo Lumi Values", 3*numberOfValuesToSave_, 0., 3*numberOfValuesToSave_, 100., -100., 9000., " ");
195 
196 }
197 
198 //----------------------------------------------------------------------------------------------------------------------
199 void AlcaBeamMonitor::beginRun(const edm::Run& r, const EventSetup& context) {
200  // create and cd into new folder
201  dbe_->setCurrentFolder(monitorName_+"Validation");
202  //Book histograms
203  hD0Phi0_ = dbe_->bookProfile("hD0Phi0","d_{0} vs. #phi_{0} (All Tracks)",63,-3.15,3.15,100,-0.1,0.1,"");
204  hD0Phi0_->setAxisTitle("#phi_{0} (rad)",1);
205  hD0Phi0_->setAxisTitle("d_{0} (cm)",2);
206 
208  hDxyBS_ = dbe_->book1D("hDxyBS","dxy_{0} w.r.t. Beam spot (All Tracks)",100,-0.1,0.1);
209  hDxyBS_->setAxisTitle("dxy_{0} w.r.t. Beam spot (cm)",1);
210 }
211 
212 //----------------------------------------------------------------------------------------------------------------------
214  // Always create a beamspot group for each lumi weather we have results or not! Each Beamspot will be of unknown type!
215 
216  vertices_.clear();
218  beamSpotsMap_.clear();
219 
220  //Read BeamSpot from DB
221  ESHandle<BeamSpotObjects> bsDBHandle;
222  try{
223  iSetup.get<BeamSpotObjectsRcd>().get(bsDBHandle);
224  }
225  catch( cms::Exception& exception ){
226  LogInfo("AlcaBeamMonitor")
227  << exception.what();
228  return;
229  }
230  if(bsDBHandle.isValid()) { // check the product
231  const BeamSpotObjects *spotDB = bsDBHandle.product();
232 
233  // translate from BeamSpotObjects to reco::BeamSpot
234  BeamSpot::Point apoint( spotDB->GetX(), spotDB->GetY(), spotDB->GetZ() );
235 
237  for ( int i=0; i<7; ++i ) {
238  for ( int j=0; j<7; ++j ) {
239  matrix(i,j) = spotDB->GetCovariance(i,j);
240  }
241  }
242 
243  beamSpotsMap_["DB"] = BeamSpot( apoint,
244  spotDB->GetSigmaZ(),
245  spotDB->Getdxdz(),
246  spotDB->Getdydz(),
247  spotDB->GetBeamWidthX(),
248  matrix );
249 
250  BeamSpot* aSpot = &(beamSpotsMap_["DB"]);
251 
252  aSpot->setBeamWidthY( spotDB->GetBeamWidthY() );
253  aSpot->setEmittanceX( spotDB->GetEmittanceX() );
254  aSpot->setEmittanceY( spotDB->GetEmittanceY() );
255  aSpot->setbetaStar( spotDB->GetBetaStar() );
256 
257  if ( spotDB->GetBeamType() == 2 ) {
258  aSpot->setType( reco::BeamSpot::Tracker );
259  } else{
260  aSpot->setType( reco::BeamSpot::Fake );
261  }
262  //LogInfo("AlcaBeamMonitor")
263  // << *aSpot << std::endl;
264  }
265  else {
266  LogInfo("AlcaBeamMonitor")
267  << "Database BeamSpot is not valid at lumi: " << iLumi.id().luminosityBlock();
268  }
269 }
270 
271 //----------------------------------------------------------------------------------------------------------------------
272 void AlcaBeamMonitor::analyze(const Event& iEvent, const EventSetup& iSetup ){
273 
274  //------ BeamFitter
275  theBeamFitter_->readEvent(iEvent);
276  //------ PVFitter
277  thePVFitter_->readEvent(iEvent);
278 
279  if(beamSpotsMap_.find("DB") != beamSpotsMap_.end()){
280  //------ Tracks
282  iEvent.getByToken(trackLabel_, TrackCollection);
283  const reco::TrackCollection *tracks = TrackCollection.product();
284  for ( reco::TrackCollection::const_iterator track = tracks->begin(); track != tracks->end(); ++track ) {
285  hD0Phi0_->Fill(track->phi(), -1*track->dxy(beamSpotsMap_["DB"].position()));
286  hDxyBS_->Fill(-1*track->dxy(beamSpotsMap_["DB"].position()));
287  }
288  }
289 
290  //------ Primary Vertices
291  Handle<VertexCollection > PVCollection;
292  if (iEvent.getByToken(primaryVertexLabel_, PVCollection )) {
293  vertices_.push_back(*PVCollection.product());
294  }
295 
296  if(beamSpotsMap_.find("SC") == beamSpotsMap_.end()){
297  //BeamSpot from file for this stream is = to the scalar BeamSpot
298  Handle<BeamSpot> recoBeamSpotHandle;
299  try{
300  iEvent.getByToken(scalerLabel_,recoBeamSpotHandle);
301  }
302  catch( cms::Exception& exception ){
303  LogInfo("AlcaBeamMonitor")
304  << exception.what();
305  return;
306  }
307  beamSpotsMap_["SC"] = *recoBeamSpotHandle;
308  if ( beamSpotsMap_["SC"].BeamWidthX() != 0 ) {
309  beamSpotsMap_["SC"].setType( reco::BeamSpot::Tracker );
310  } else{
311  beamSpotsMap_["SC"].setType( reco::BeamSpot::Fake );
312  }
313  }
314 }
315 
316 
317 //----------------------------------------------------------------------------------------------------------------------
321  }
326 
327  if ( thePVFitter_->runFitter() ) {
329  }
331 
332  // "PV,BF..." Value,Error
333  map<std::string,pair<double,double> > resultsMap;
334  vector<pair<double,double> > vertexResults;
336  int position = 0;
337  for(vector<string>::iterator itV=varNamesV_.begin(); itV!=varNamesV_.end(); itV++){
338  resultsMap.clear();
339  for(BeamSpotContainer::iterator itBS = beamSpotsMap_.begin(); itBS != beamSpotsMap_.end(); itBS++){
340  if(itBS->second.type() == BeamSpot::Tracker){
341  if(*itV == "x"){
342  resultsMap[itBS->first] = pair<double,double>(itBS->second.x0(),itBS->second.x0Error());
343  }
344  else if(*itV == "y"){
345  resultsMap[itBS->first] = pair<double,double>(itBS->second.y0(),itBS->second.y0Error());
346  }
347  else if(*itV == "z"){
348  resultsMap[itBS->first] = pair<double,double>(itBS->second.z0(),itBS->second.z0Error());
349  }
350  else if(*itV == "sigmaX"){
351  resultsMap[itBS->first] = pair<double,double>(itBS->second.BeamWidthX(),itBS->second.BeamWidthXError());
352  }
353  else if(*itV == "sigmaY"){
354  resultsMap[itBS->first] = pair<double,double>(itBS->second.BeamWidthY(),itBS->second.BeamWidthYError());
355  }
356  else if(*itV == "sigmaZ"){
357  resultsMap[itBS->first] = pair<double,double>(itBS->second.sigmaZ(),itBS->second.sigmaZ0Error());
358  }
359  else{
360  LogInfo("AlcaBeamMonitor")
361  << "The histosMap_ has been built with the name " << *itV << " that I can't recognize!";
362  //assert(0);
363  }
364  }
365  }
366  vertexResults.clear();
367  for(vector<VertexCollection>::iterator itPV = vertices_.begin(); itPV != vertices_.end(); itPV++){
368  if(itPV->size() != 0){
369  for(VertexCollection::const_iterator pv = itPV->begin(); pv != itPV->end(); pv++) {
370  if (pv->isFake() || pv->tracksSize()<10) continue;
371  if(*itV == "x"){
372  vertexResults.push_back(pair<double,double>(pv->x(),pv->xError()));
373  }
374  else if(*itV == "y"){
375  vertexResults.push_back(pair<double,double>(pv->y(),pv->yError()));
376  }
377  else if(*itV == "z"){
378  vertexResults.push_back(pair<double,double>(pv->z(),pv->zError()));
379  }
380  else if(*itV != "sigmaX" && *itV != "sigmaY" && *itV != "sigmaZ"){
381  LogInfo("AlcaBeamMonitor")
382  << "The histosMap_ has been built with the name " << *itV << " that I can't recognize!";
383  //assert(0);
384  }
385  }
386  }
387  }
388 /*
389  histoByCategoryNames_.insert( pair<string,string>("run", "Coordinate"));
390  histoByCategoryNames_.insert( pair<string,string>("run", "PrimaryVertex fit-DataBase"));
391  histoByCategoryNames_.insert( pair<string,string>("run", "PrimaryVertex fit-BeamFit"));
392  histoByCategoryNames_.insert( pair<string,string>("run", "PrimaryVertex fit-Scalers"));
393  histoByCategoryNames_.insert( pair<string,string>("run", "PrimaryVertex-DataBase"));
394  histoByCategoryNames_.insert( pair<string,string>("run", "PrimaryVertex-BeamFit"));
395  histoByCategoryNames_.insert( pair<string,string>("run", "PrimaryVertex-Scalers"));
396 
397  histoByCategoryNames_.insert( pair<string,string>("lumi", "Lumibased BeamSpotFit"));
398  histoByCategoryNames_.insert( pair<string,string>("lumi", "Lumibased PrimaryVertex"));
399  histoByCategoryNames_.insert( pair<string,string>("lumi", "Lumibased DataBase"));
400  histoByCategoryNames_.insert( pair<string,string>("lumi", "Lumibased Scalers"));
401  histoByCategoryNames_.insert( pair<string,string>("lumi", "Lumibased PrimaryVertex-DataBase fit"));
402  histoByCategoryNames_.insert( pair<string,string>("lumi", "Lumibased PrimaryVertex-Scalers fit"));
403  histoByCategoryNames_.insert( pair<string,string>("validation", "Lumibased Scalers-DataBase fit"));
404  histoByCategoryNames_.insert( pair<string,string>("validation", "Lumibased PrimaryVertex-DataBase"));
405  histoByCategoryNames_.insert( pair<string,string>("validation", "Lumibased PrimaryVertex-Scalers"));
406 */
407  for(multimap<string,string>::iterator itM=histoByCategoryNames_.begin(); itM!=histoByCategoryNames_.end(); itM++){
408  if(itM->first == "run" && (histo = histosMap_[*itV][itM->first][itM->second]) == 0){
409  continue;
410  }
411  else if(itM->first != "run"){
412  position = positionsMap_[*itV][itM->first][itM->second];
413  }
414  if(itM->second == "Coordinate"){
415  if(beamSpotsMap_.find("DB") != beamSpotsMap_.end()){
416  histo->Fill(resultsMap["DB"].first);
417  }
418  }
419  else if(itM->second == "PrimaryVertex fit-DataBase"){
420  if(resultsMap.find("PV") != resultsMap.end() && resultsMap.find("DB") != resultsMap.end()){
421  histo->Fill(resultsMap["PV"].first-resultsMap["DB"].first);
422  }
423  }
424  else if(itM->second == "PrimaryVertex fit-BeamFit"){
425  if(resultsMap.find("PV") != resultsMap.end() && resultsMap.find("BF") != resultsMap.end()){
426  histo->Fill(resultsMap["PV"].first-resultsMap["BF"].first);
427  }
428  }
429  else if(itM->second == "PrimaryVertex fit-Scalers"){
430  if(resultsMap.find("PV") != resultsMap.end() && resultsMap.find("SC") != resultsMap.end()){
431  histo->Fill(resultsMap["PV"].first-resultsMap["SC"].first);
432  }
433  }
434  else if(itM->second == "PrimaryVertex-DataBase"){
435  if(resultsMap.find("PV") != resultsMap.end() && resultsMap.find("DB") != resultsMap.end()){
436  for(vector<pair<double,double> >::iterator itPV=vertexResults.begin(); itPV!=vertexResults.end(); itPV++){
437  histo->Fill(itPV->first-resultsMap["DB"].first);
438  }
439  }
440  }
441  else if(itM->second == "PrimaryVertex-BeamFit"){
442  if(resultsMap.find("PV") != resultsMap.end() && resultsMap.find("BF") != resultsMap.end()){
443  for(vector<pair<double,double> >::iterator itPV=vertexResults.begin(); itPV!=vertexResults.end(); itPV++){
444  histo->Fill(itPV->first-resultsMap["BF"].first);
445  }
446  }
447  }
448  else if(itM->second == "PrimaryVertex-Scalers"){
449  if(resultsMap.find("PV") != resultsMap.end() && resultsMap.find("SC") != resultsMap.end()){
450  for(vector<pair<double,double> >::iterator itPV=vertexResults.begin(); itPV!=vertexResults.end(); itPV++){
451  histo->Fill(itPV->first-resultsMap["SC"].first);
452  }
453  }
454  }
455  else if(itM->second == "Lumibased BeamSpotFit"){
456  if(resultsMap.find("BF") != resultsMap.end()){
457  theValuesContainer_->Fill(position ,resultsMap["BF"].first);//Value
458  theValuesContainer_->Fill(position+1,resultsMap["BF"].second);//Error
459  theValuesContainer_->Fill(position+2,1);//ok
460  }
461  }
462  else if(itM->second == "Lumibased PrimaryVertex"){
463  if(resultsMap.find("PV") != resultsMap.end()){
464  theValuesContainer_->Fill(position ,resultsMap["PV"].first);//Value
465  theValuesContainer_->Fill(position+1,resultsMap["PV"].second);//Error
466  theValuesContainer_->Fill(position+2,1);//ok
467  }
468  }
469  else if(itM->second == "Lumibased DataBase"){
470  if(resultsMap.find("DB") != resultsMap.end()){
471  theValuesContainer_->Fill(position ,resultsMap["DB"].first);//Value
472  theValuesContainer_->Fill(position+1,resultsMap["DB"].second);//Error
473  theValuesContainer_->Fill(position+2,1);//ok
474  }
475  }
476  else if(itM->second == "Lumibased Scalers"){
477  if(resultsMap.find("SC") != resultsMap.end()){
478  theValuesContainer_->Fill(position ,resultsMap["SC"].first);//Value
479  theValuesContainer_->Fill(position+1,resultsMap["SC"].second);//Error
480  theValuesContainer_->Fill(position+2,1);//ok
481  }
482  }
483  else if(itM->second == "Lumibased PrimaryVertex-DataBase fit"){
484  if(resultsMap.find("PV") != resultsMap.end() && resultsMap.find("DB") != resultsMap.end()){
485  theValuesContainer_->Fill(position ,resultsMap["PV"].first-resultsMap["DB"].first);//Value
486  theValuesContainer_->Fill(position+1,std::sqrt(std::pow(resultsMap["PV"].second,2)+std::pow(resultsMap["DB"].second,2)));//Error
487  theValuesContainer_->Fill(position+2,1);//ok
488  }
489  }
490  else if(itM->second == "Lumibased PrimaryVertex-Scalers fit"){
491  if(resultsMap.find("PV") != resultsMap.end() && resultsMap.find("SC") != resultsMap.end()){
492  theValuesContainer_->Fill(position ,resultsMap["PV"].first-resultsMap["SC"].first);//Value
493  theValuesContainer_->Fill(position+1,std::sqrt(std::pow(resultsMap["PV"].second,2)+std::pow(resultsMap["SC"].second,2)));//Error
494  theValuesContainer_->Fill(position+2,1);//ok
495  }
496  }
497  else if(itM->second == "Lumibased Scalers-DataBase fit"){
498  if(resultsMap.find("SC") != resultsMap.end() && resultsMap.find("DB") != resultsMap.end()){
499  theValuesContainer_->Fill(position ,resultsMap["SC"].first-resultsMap["DB"].first);//Value
500  theValuesContainer_->Fill(position+1,std::sqrt(std::pow(resultsMap["SC"].second,2)+std::pow(resultsMap["DB"].second,2)));//Error
501  theValuesContainer_->Fill(position+2,1);//ok
502  }
503  }
504  else if(itM->second == "Lumibased PrimaryVertex-DataBase"){
505  if(resultsMap.find("DB") != resultsMap.end() && vertexResults.size() != 0){
506  for(vector<pair<double,double> >::iterator itPV=vertexResults.begin(); itPV!=vertexResults.end(); itPV++){
507  theValuesContainer_->Fill(position ,(*itPV).first-resultsMap["DB"].first);//Value
508  }
509 /*
510  double error = 0;
511  if(vertexResults.size() != 0){
512  for(vector<pair<double,double> >::iterator itPV=vertexResults.begin(); itPV!=vertexResults.end(); itPV++){
513  error += std::pow((*itPV).first-resultsMap["DB"].first-theValuesContainer_->getTProfile()->GetBinContent(position+1),2.);
514  }
515  error = std::sqrt(error)/vertexResults.size();
516  }
517 // theValuesContainer_->Fill(position+1,std::sqrt(std::pow((*itPV).second,2)+std::pow(resultsMap["DB"].second,2)));//Error
518  theValuesContainer_->Fill(position+1,error);//Error
519 */
520  theValuesContainer_->Fill(position+1,theValuesContainer_->getTProfile()->GetBinError(position+1));//Error
521  theValuesContainer_->Fill(position+2,1);//ok
522  }
523  }
524  else if(itM->second == "Lumibased PrimaryVertex-Scalers"){
525  if(resultsMap.find("SC") != resultsMap.end() && vertexResults.size() != 0){
526  for(vector<pair<double,double> >::iterator itPV=vertexResults.begin(); itPV!=vertexResults.end(); itPV++){
527  theValuesContainer_->Fill(position ,(*itPV).first-resultsMap["SC"].first);//Value
528  }
529 /*
530  double error = 0;
531  if(vertexResults.size() != 0){
532  for(vector<pair<double,double> >::iterator itPV=vertexResults.begin(); itPV!=vertexResults.end(); itPV++){
533  error += std::pow((*itPV).first-resultsMap["SC"].first-theValuesContainer_->getTProfile()->GetBinContent(position+1),2.);
534  }
535  error = std::sqrt(error)/vertexResults.size();
536  }
537 // theValuesContainer_->Fill(position+1,std::sqrt(std::pow((*itPV).second,2)+std::pow(resultsMap["SC"].second,2)));//Error
538  theValuesContainer_->Fill(position+1,error);//Error
539 */
540  theValuesContainer_->Fill(position+1,theValuesContainer_->getTProfile()->GetBinError(position+1));//Error
541  theValuesContainer_->Fill(position+2,1);//ok
542  }
543  }
544 // else if(itM->second == "Lumibased Scalers-DataBase"){
545 // if(resultsMap.find("SC") != resultsMap.end() && resultsMap.find("DB") != resultsMap.end()){
546 // itHHH->second->Fill(bin,resultsMap["SC"].first-resultsMap["DB"].first);
547 // }
548 // }
549  else{
550  LogInfo("AlcaBeamMonitor")
551  << "The histosMap_ have a histogram named " << itM->second << " that I can't recognize in this loop!";
552  //assert(0);
553 
554  }
555  }
556  }
557 }
558 
559 //----------------------------------------------------------------------------------------------------------------------
560 void AlcaBeamMonitor::endRun(const Run& iRun, const EventSetup& context){
561 }
562 
563 //----------------------------------------------------------------------------------------------------------------------
564 void AlcaBeamMonitor::endJob(const LuminosityBlock& iLumi, const EventSetup& iSetup){
565 }
566 
567 
569 
570 // Local Variables:
571 // show-trailing-whitespace: t
572 // truncate-lines: t
573 // End:
double Getdydz() const
get dydz slope, crossing angle in YZ
virtual char const * what() const
Definition: Exception.cc:141
LuminosityBlockID id() const
MonitorElement * hD0Phi0_
math::Error< dimension >::type CovarianceMatrix
Definition: BeamSpot.h:31
int i
Definition: DBlmapReader.cc:9
edm::EDGetTokenT< reco::TrackCollection > trackLabel_
MonitorElement * hDxyBS_
double GetY() const
get Y beam position
tuple BeamFitter
Input track for PrimaryVertex reconstruction, uncomment the following line to use pixelLess tracks pr...
bool runPVandTrkFitter()
Definition: BeamFitter.cc:401
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:954
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:10
double GetSigmaZ() const
get sigma Z, RMS bunch length
edm::EDGetTokenT< reco::VertexCollection > primaryVertexLabel_
void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup)
double GetBeamWidthX() const
get average transverse beam width
void resetTrkVector()
Definition: BeamFitter.h:53
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
math::XYZPoint Point
point in the space
Definition: BeamSpot.h:29
PositionContainer positionsMap_
double GetBeamWidthY() const
get average transverse beam width
void readEvent(const edm::Event &iEvent)
Definition: BeamFitter.cc:215
static int position[TOTALCHAMBERS][3]
Definition: ReadPGInfo.cc:509
double GetEmittanceX() const
get emittance
void endRun(const edm::Run &iRun, const edm::EventSetup &iSetup)
void Fill(long long x)
U second(std::pair< T, U > const &p)
std::vector< std::string > varNamesV_
int iEvent
Definition: GenABIO.cc:230
AlcaBeamMonitor(const edm::ParameterSet &)
void readEvent(const edm::Event &iEvent)
Definition: PVFitter.cc:101
void beginRun(const edm::Run &iRun, const edm::EventSetup &iSetup)
void setBeamWidthY(double v)
Definition: BeamSpot.h:109
int GetBeamType() const
get beam type
edm::EDGetTokenT< reco::BeamSpot > scalerLabel_
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
T sqrt(T t)
Definition: SSEVec.h:48
BeamSpotContainer beamSpotsMap_
BeamFitter * theBeamFitter_
virtual void endJob()
Definition: EDAnalyzer.h:68
int j
Definition: DBlmapReader.cc:9
double GetZ() const
get Z beam position
MonitorElement * bookProfile(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, const char *option="s")
Definition: DQMStore.cc:1268
void resetLSRange()
Definition: BeamFitter.h:55
double Getdxdz() const
get dxdz slope, crossing angle in XZ
bool first
Definition: L1TdeRCT.cc:75
PVFitter * thePVFitter_
std::multimap< std::string, std::string > histoByCategoryNames_
double GetX() const
get X beam position
void beginLuminosityBlock(const edm::LuminosityBlock &iLumi, const edm::EventSetup &iSetup)
tuple tracks
Definition: testEve_cfg.py:39
bool runFitter()
Definition: PVFitter.cc:334
HistosContainer histosMap_
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
LuminosityBlockNumber_t luminosityBlock() const
void resetAll()
Definition: PVFitter.h:80
double GetBetaStar() const
get beta star
T const * product() const
Definition: Handle.h:81
void endLuminosityBlock(const edm::LuminosityBlock &iLumi, const edm::EventSetup &iSetup)
std::string monitorName_
double GetCovariance(int i, int j) const
get i,j element of the full covariance matrix 7x7
void resetPVFitter()
Definition: BeamFitter.h:69
TProfile * getTProfile(void) const
double GetEmittanceY() const
get emittance
reco::BeamSpot getBeamSpot()
Definition: PVFitter.h:91
void setLumiFlag(void)
this ME is meant to be stored for each luminosity section
bool isValid() const
Definition: ESHandle.h:37
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
void Reset(void)
reset ME (ie. contents, errors, etc)
edm::ParameterSet parameters_
MonitorElement * theValuesContainer_
reco::BeamSpot getBeamSpot()
Definition: BeamFitter.h:94
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:667
Definition: Run.h:41
std::vector< reco::VertexCollection > vertices_
void resetRefTime()
Definition: BeamFitter.h:56