Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:01:23

0001 #include "CondCore/BeamSpotPlugins/interface/BeamSpotPayloadInspectorHelper.h"
0002 #include "CondCore/CondDB/interface/Time.h"
0003 #include "CondCore/Utilities/interface/PayloadInspector.h"
0004 #include "CondCore/Utilities/interface/PayloadInspectorModule.h"
0005 #include "CondFormats/BeamSpotObjects/interface/BeamSpotOnlineObjects.h"
0006 
0007 #include <TStyle.h>
0008 
0009 namespace {
0010 
0011   using namespace beamSpotPI;
0012 
0013   /************************************************
0014     history plots
0015   *************************************************/
0016   typedef BeamSpot_history<X, BeamSpotOnlineObjects> BeamSpotOnline_HistoryX;
0017   typedef BeamSpot_history<Y, BeamSpotOnlineObjects> BeamSpotOnline_HistoryY;
0018   typedef BeamSpot_history<Z, BeamSpotOnlineObjects> BeamSpotOnline_HistoryZ;
0019   typedef BeamSpot_history<sigmaX, BeamSpotOnlineObjects> BeamSpotOnline_HistorySigmaX;
0020   typedef BeamSpot_history<sigmaY, BeamSpotOnlineObjects> BeamSpotOnline_HistorySigmaY;
0021   typedef BeamSpot_history<sigmaZ, BeamSpotOnlineObjects> BeamSpotOnline_HistorySigmaZ;
0022   typedef BeamSpot_history<dxdz, BeamSpotOnlineObjects> BeamSpotOnline_HistorydXdZ;
0023   typedef BeamSpot_history<dydz, BeamSpotOnlineObjects> BeamSpotOnline_HistorydYdZ;
0024 
0025   /************************************************
0026     run history plots
0027   *************************************************/
0028 
0029   typedef BeamSpot_runhistory<X, BeamSpotOnlineObjects> BeamSpotOnline_RunHistoryX;
0030   typedef BeamSpot_runhistory<Y, BeamSpotOnlineObjects> BeamSpotOnline_RunHistoryY;
0031   typedef BeamSpot_runhistory<Z, BeamSpotOnlineObjects> BeamSpotOnline_RunHistoryZ;
0032   typedef BeamSpot_runhistory<sigmaX, BeamSpotOnlineObjects> BeamSpotOnline_RunHistorySigmaX;
0033   typedef BeamSpot_runhistory<sigmaY, BeamSpotOnlineObjects> BeamSpotOnline_RunHistorySigmaY;
0034   typedef BeamSpot_runhistory<sigmaZ, BeamSpotOnlineObjects> BeamSpotOnline_RunHistorySigmaZ;
0035   typedef BeamSpot_runhistory<dxdz, BeamSpotOnlineObjects> BeamSpotOnline_RunHistorydXdZ;
0036   typedef BeamSpot_runhistory<dydz, BeamSpotOnlineObjects> BeamSpotOnline_RunHistorydYdZ;
0037 
0038   /************************************************
0039     time history plots
0040   *************************************************/
0041 
0042   typedef BeamSpot_timehistory<X, BeamSpotOnlineObjects> BeamSpotOnline_TimeHistoryX;
0043   typedef BeamSpot_timehistory<Y, BeamSpotOnlineObjects> BeamSpotOnline_TimeHistoryY;
0044   typedef BeamSpot_timehistory<Z, BeamSpotOnlineObjects> BeamSpotOnline_TimeHistoryZ;
0045   typedef BeamSpot_timehistory<sigmaX, BeamSpotOnlineObjects> BeamSpotOnline_TimeHistorySigmaX;
0046   typedef BeamSpot_timehistory<sigmaY, BeamSpotOnlineObjects> BeamSpotOnline_TimeHistorySigmaY;
0047   typedef BeamSpot_timehistory<sigmaZ, BeamSpotOnlineObjects> BeamSpotOnline_TimeHistorySigmaZ;
0048   typedef BeamSpot_timehistory<dxdz, BeamSpotOnlineObjects> BeamSpotOnline_TimeHistorydXdZ;
0049   typedef BeamSpot_timehistory<dydz, BeamSpotOnlineObjects> BeamSpotOnline_TimeHistorydYdZ;
0050 
0051   /************************************************
0052     X-Y correlation plot
0053   *************************************************/
0054 
0055   typedef xyCorrelation<BeamSpotOnlineObjects> BeamSpotOnline_xy;
0056 
0057   /************************************************
0058     Display of Beam Spot parameters
0059   *************************************************/
0060 
0061   class BeamSpotOnlineParameters : public DisplayParameters<BeamSpotOnlineObjects> {
0062   public:
0063     std::shared_ptr<TH2F> fillTheExtraHistogram() const override {
0064       gStyle->SetHistMinimumZero();
0065 
0066       const auto span = parameters::startTime - parameters::lastLumi;
0067       edm::LogInfo("BeamSpotOnlineParameters") << "the span is" << span;
0068 
0069       auto h2_ExtraBSParameters =
0070           std::make_shared<TH2F>("ExtraParameters", "", 1, 0.0, 1.0, span, 0, static_cast<float>(span));
0071       h2_ExtraBSParameters->SetStats(false);
0072 
0073       //_____________________________________________________________________________
0074       std::function<int(parameters)> myIntFunctor = [this](parameters my_param) {
0075         int ret(-999);
0076         switch (my_param) {
0077           case lastLumi:
0078             return this->m_payload->lastAnalyzedLumi();
0079           case lastRun:
0080             return this->m_payload->lastAnalyzedRun();
0081           case lastFill:
0082             return this->m_payload->lastAnalyzedFill();
0083           case nTracks:
0084             return this->m_payload->numTracks();
0085           case nPVs:
0086             return this->m_payload->numPVs();
0087           case nUsedEvents:
0088             return this->m_payload->usedEvents();
0089           case maxPVs:
0090             return this->m_payload->maxPVs();
0091           default:
0092             return ret;
0093         }
0094       };
0095 
0096       //_____________________________________________________________________________
0097       std::function<float(parameters)> myFloatFunctor = [this](parameters my_param) {
0098         float ret(-999.);
0099         switch (my_param) {
0100           case meanPV:
0101             return this->m_payload->meanPV();
0102           case meanErrorPV:
0103             return this->m_payload->meanErrorPV();
0104           case rmsPV:
0105             return this->m_payload->rmsPV();
0106           case rmsErrorPV:
0107             return this->m_payload->rmsErrorPV();
0108           default:
0109             return ret;
0110         }
0111       };
0112 
0113       //_____________________________________________________________________________
0114       std::function<std::string(parameters)> myStringFunctor = [this](parameters my_param) {
0115         std::string ret("");
0116         switch (my_param) {
0117           case startTime:
0118             return this->m_payload->startTime();
0119           case endTime:
0120             return this->m_payload->endTime();
0121           case lumiRange:
0122             return this->m_payload->lumiRange();
0123           default:
0124             return ret;
0125         }
0126       };
0127 
0128       //_____________________________________________________________________________
0129       std::function<cond::Time_t(parameters)> myTimeFunctor = [this](parameters my_param) {
0130         cond::Time_t ret(1);
0131         switch (my_param) {
0132           case creationTime:
0133             return this->m_payload->creationTime();
0134           case startTimeStamp:
0135             return this->m_payload->startTimeStamp();
0136           case endTimeStamp:
0137             return this->m_payload->endTimeStamp();
0138           default:
0139             return ret;
0140         }
0141       };
0142 
0143       unsigned int yBin = span;
0144       for (int foo = parameters::lastLumi; foo != parameters::startTime; foo++) {
0145         parameters param = static_cast<parameters>(foo);
0146         std::string theLabel = this->getStringFromTypeEnum(param);
0147         h2_ExtraBSParameters->GetYaxis()->SetBinLabel(yBin, theLabel.c_str());
0148 
0149         if (foo <= parameters::maxPVs) {
0150           const auto output = try_<int, std::out_of_range>(std::bind(myIntFunctor, param), print_error);
0151           edm::LogInfo("BeamSpotOnline_PayloadInspector") << theLabel.c_str() << " : " << output << std::endl;
0152           h2_ExtraBSParameters->SetBinContent(1, yBin, output);
0153         } else if (foo <= parameters::rmsErrorPV) {
0154           const auto output = try_<float, std::out_of_range>(std::bind(myFloatFunctor, param), print_error);
0155           edm::LogInfo("BeamSpotOnline_PayloadInspector") << theLabel.c_str() << " : " << output << std::endl;
0156           h2_ExtraBSParameters->SetBinContent(1, yBin, output);
0157         } else if (foo <= parameters::endTimeStamp) {
0158           const auto output = try_<cond::Time_t, std::out_of_range>(std::bind(myTimeFunctor, param), print_error);
0159           edm::LogInfo("BeamSpotOnline_PayloadInspector") << theLabel.c_str() << " : " << output << std::endl;
0160           h2_ExtraBSParameters->SetBinContent(1, yBin, output);
0161           //} else if( foo <=parameters::lumiRange){
0162           // const auto output = try_<std::string,std::out_of_range>(std::bind(myStringFunctor, param), print_error);
0163           //edm::LogInfo("BeamSpotOnline_PayloadInspector") << theLabel.c_str() << " : " << output << std::endl;
0164           //h2_ExtraBSParameters->SetBinContent(1, yBin, output);
0165         }
0166         yBin--;
0167       }
0168 
0169       h2_ExtraBSParameters->GetYaxis()->SetLabelSize(0.05);
0170       h2_ExtraBSParameters->GetXaxis()->SetLabelSize(0.05);
0171       h2_ExtraBSParameters->GetXaxis()->SetBinLabel(1, "Value");
0172       h2_ExtraBSParameters->SetMarkerSize(2.);
0173 
0174       return h2_ExtraBSParameters;
0175     }
0176 
0177   protected:
0178     /************************************************/
0179     std::string getStringFromTypeEnum(const parameters& parameter) const override {
0180       switch (parameter) {
0181         case X:
0182           return "X [cm]";
0183         case Y:
0184           return "Y [cm]";
0185         case Z:
0186           return "Z [cm]";
0187         case sigmaX:
0188           return "#sigma_{X} [cm]";
0189         case sigmaY:
0190           return "#sigma_{Y} [cm]";
0191         case sigmaZ:
0192           return "#sigma_{Z} [cm]";
0193         case dxdz:
0194           return "#frac{dX}{dZ} [rad]";
0195         case dydz:
0196           return "#frac{dY}{dZ} [rad]";
0197         case lastLumi:
0198           return "last LS";
0199         case lastRun:
0200           return "last Run";
0201         case lastFill:
0202           return "last Fill";
0203         case nTracks:
0204           return "# tracks";
0205         case nPVs:
0206           return "# PVs";
0207         case nUsedEvents:
0208           return "# events";
0209         case maxPVs:
0210           return "max PVs";
0211         case meanPV:
0212           return "#LT # PV #GT";
0213         case meanErrorPV:
0214           return "#LT # PV #GT error";
0215         case rmsPV:
0216           return "RMS(# PV)";
0217         case rmsErrorPV:
0218           return "RMS(# PV) error";
0219         case creationTime:
0220           return "creation time";
0221         case startTimeStamp:
0222           return "start timestamp";
0223         case endTimeStamp:
0224           return "end timestamp";
0225         case startTime:
0226           return "startTime";
0227         case endTime:
0228           return "endTime";
0229         case lumiRange:
0230           return "lumiRange";
0231         default:
0232           return "should never be here";
0233       }
0234     }
0235 
0236     //slightly better error handler
0237     static void print_error(const std::exception& e) { edm::LogError("BeamSpotOnlineParameters") << e.what() << '\n'; }
0238 
0239     // method to catch exceptions
0240     template <typename T, class Except, class Func, class Response>
0241     T try_(Func f, Response r) const {
0242       try {
0243         LogDebug("BeamSpotOnlineParameters") << "I have tried" << std::endl;
0244         return f();
0245       } catch (Except& e) {
0246         LogDebug("BeamSpotOnlineParameters") << "I have caught!" << std::endl;
0247         r(e);
0248         return static_cast<T>(-999);
0249       }
0250     }
0251   };
0252 
0253   /************************************************
0254     Display of Beam Spot parameters Differences
0255   *************************************************/
0256 
0257   typedef DisplayParametersDiff<BeamSpotOnlineObjects, cond::payloadInspector::MULTI_IOV, 1>
0258       BeamSpotOnlineParametersDiffSingleTag;
0259   typedef DisplayParametersDiff<BeamSpotOnlineObjects, cond::payloadInspector::SINGLE_IOV, 2>
0260       BeamSpotOnlineParametersDiffTwoTags;
0261 
0262 }  // namespace
0263 
0264 PAYLOAD_INSPECTOR_MODULE(BeamSpotOnline) {
0265   PAYLOAD_INSPECTOR_CLASS(BeamSpotOnline_xy);
0266   PAYLOAD_INSPECTOR_CLASS(BeamSpotOnlineParameters);
0267   PAYLOAD_INSPECTOR_CLASS(BeamSpotOnlineParametersDiffSingleTag);
0268   PAYLOAD_INSPECTOR_CLASS(BeamSpotOnlineParametersDiffTwoTags);
0269   PAYLOAD_INSPECTOR_CLASS(BeamSpotOnline_HistoryX);
0270   PAYLOAD_INSPECTOR_CLASS(BeamSpotOnline_HistoryY);
0271   PAYLOAD_INSPECTOR_CLASS(BeamSpotOnline_HistoryZ);
0272   PAYLOAD_INSPECTOR_CLASS(BeamSpotOnline_HistorySigmaX);
0273   PAYLOAD_INSPECTOR_CLASS(BeamSpotOnline_HistorySigmaY);
0274   PAYLOAD_INSPECTOR_CLASS(BeamSpotOnline_HistorySigmaZ);
0275   PAYLOAD_INSPECTOR_CLASS(BeamSpotOnline_HistorydXdZ);
0276   PAYLOAD_INSPECTOR_CLASS(BeamSpotOnline_HistorydYdZ);
0277   PAYLOAD_INSPECTOR_CLASS(BeamSpotOnline_RunHistoryX);
0278   PAYLOAD_INSPECTOR_CLASS(BeamSpotOnline_RunHistoryY);
0279   PAYLOAD_INSPECTOR_CLASS(BeamSpotOnline_RunHistoryZ);
0280   PAYLOAD_INSPECTOR_CLASS(BeamSpotOnline_RunHistorySigmaX);
0281   PAYLOAD_INSPECTOR_CLASS(BeamSpotOnline_RunHistorySigmaY);
0282   PAYLOAD_INSPECTOR_CLASS(BeamSpotOnline_RunHistorySigmaZ);
0283   PAYLOAD_INSPECTOR_CLASS(BeamSpotOnline_RunHistorydXdZ);
0284   PAYLOAD_INSPECTOR_CLASS(BeamSpotOnline_RunHistorydYdZ);
0285   PAYLOAD_INSPECTOR_CLASS(BeamSpotOnline_TimeHistoryX);
0286   PAYLOAD_INSPECTOR_CLASS(BeamSpotOnline_TimeHistoryY);
0287   PAYLOAD_INSPECTOR_CLASS(BeamSpotOnline_TimeHistoryZ);
0288   PAYLOAD_INSPECTOR_CLASS(BeamSpotOnline_TimeHistorySigmaX);
0289   PAYLOAD_INSPECTOR_CLASS(BeamSpotOnline_TimeHistorySigmaY);
0290   PAYLOAD_INSPECTOR_CLASS(BeamSpotOnline_TimeHistorySigmaZ);
0291   PAYLOAD_INSPECTOR_CLASS(BeamSpotOnline_TimeHistorydXdZ);
0292   PAYLOAD_INSPECTOR_CLASS(BeamSpotOnline_TimeHistorydYdZ);
0293 }