Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:27:17

0001 #include "FWCore/Utilities/interface/EDMException.h"
0002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0003 #include "RecoTBCalo/HcalPlotter/src/HcalQLPlotHistoMgr.h"
0004 #include "TProfile.h"
0005 
0006 //Declare Histogram Bin parameters
0007 static const int PED_BINS = 50;
0008 static const int LED_BINS = 50;
0009 static const int LASER_BINS = 70;
0010 static const int BEAM_BINS = 70;
0011 static const int OTHER_BINS = 100;
0012 static const int TIME_BINS = 75;
0013 static const int PULSE_BINS = 10;
0014 
0015 HcalQLPlotHistoMgr::HcalQLPlotHistoMgr(TDirectory* parent, const edm::ParameterSet& histoParams) {
0016   pedHistDir = parent->mkdir("PEDESTAL");
0017   ledHistDir = parent->mkdir("LED");
0018   laserHistDir = parent->mkdir("LASER");
0019   beamHistDir = parent->mkdir("BEAM");
0020   otherHistDir = parent->mkdir("OTHER");
0021   histoParams_ = histoParams;
0022 }
0023 
0024 std::string HcalQLPlotHistoMgr::nameForFlavor(HistType ht) {
0025   switch (ht) {
0026     case (ENERGY):
0027       return "Energy";
0028       break;
0029     case (TIME):
0030       return "Time";
0031       break;
0032     case (PULSE):
0033       return "Pulse";
0034       break;
0035     case (ADC):
0036       return "ADC";
0037       break;
0038     default:
0039       return "";
0040       break;
0041   }
0042 }
0043 
0044 std::string HcalQLPlotHistoMgr::nameForEvent(EventType et) {
0045   switch (et) {
0046     case (PEDESTAL):
0047       return "Pedestal";
0048       break;
0049     case (LED):
0050       return "LED";
0051       break;
0052     case (LASER):
0053       return "Laser";
0054       break;
0055     case (BEAM):
0056       return "Beam";
0057       break;
0058     default:
0059       return "Other";
0060       break;
0061   }
0062 }
0063 
0064 TH1* HcalQLPlotHistoMgr::GetAHistogram(const HcalDetId& id, const HcalElectronicsId& eid, HistType ht, EventType et) {
0065   std::string flavor = nameForFlavor(ht);
0066 
0067   char name[120];
0068 
0069   std::string subdetStr;
0070   switch (id.subdet()) {
0071     case (HcalBarrel):
0072       subdetStr = "HB";
0073       break;
0074     case (HcalEndcap):
0075       subdetStr = "HE";
0076       break;
0077     case (HcalOuter):
0078       subdetStr = "HO";
0079       break;
0080     case (HcalForward):
0081       subdetStr = "HF";
0082       break;
0083     default:
0084       subdetStr = "Other";
0085       break;
0086   }
0087 
0088   sprintf(name,
0089           "%s_%s_%d_%d_%d_eid=%d_%d_%d_%d_HTR_%d:%d%c",
0090           flavor.c_str(),
0091           subdetStr.c_str(),
0092           id.ieta(),
0093           id.iphi(),
0094           id.depth(),
0095           eid.dccid(),
0096           eid.spigot(),
0097           eid.fiberIndex(),
0098           eid.fiberChanId(),
0099           eid.readoutVMECrateId(),
0100           eid.htrSlot(),
0101           (eid.htrTopBottom() == 1) ? ('t') : ('b'));
0102 
0103   return GetAHistogramImpl(name, ht, et);
0104 }
0105 
0106 TH1* HcalQLPlotHistoMgr::GetAHistogram(const HcalCalibDetId& id,
0107                                        const HcalElectronicsId& eid,
0108                                        HistType ht,
0109                                        EventType et) {
0110   std::string flavor = nameForFlavor(ht);
0111 
0112   char name[120];
0113 
0114   std::string subdetStr;
0115   switch (id.hcalSubdet()) {
0116     case (HcalBarrel):
0117       subdetStr = "HB";
0118       break;
0119     case (HcalEndcap):
0120       subdetStr = "HE";
0121       break;
0122     case (HcalOuter):
0123       subdetStr = "HO";
0124       break;
0125     case (HcalForward):
0126       subdetStr = "HF";
0127       break;
0128     default:
0129       subdetStr = "Other";
0130       break;
0131   }
0132 
0133   std::string chanstring = id.cboxChannelString();
0134   if (chanstring.empty()) {
0135     chanstring = "Unknown";
0136     edm::LogInfo("HcalQLPlotHistoMgr::GetAHistogram") << "Unknown calibration channel " << id.cboxChannel();
0137   }
0138 
0139   sprintf(name,
0140           "%s_CALIB_%s_%d_%d_chan=%s_eid=%d_%d_%d_%d_HTR_%d:%d%c",
0141           flavor.c_str(),
0142           subdetStr.c_str(),
0143           id.ieta(),
0144           id.iphi(),
0145           chanstring.c_str(),
0146           eid.dccid(),
0147           eid.spigot(),
0148           eid.fiberIndex(),
0149           eid.fiberChanId(),
0150           eid.readoutVMECrateId(),
0151           eid.htrSlot(),
0152           (eid.htrTopBottom() == 1) ? ('t') : ('b'));
0153 
0154   return GetAHistogramImpl(name, ht, et);
0155 }
0156 
0157 TH1* HcalQLPlotHistoMgr::GetAHistogramImpl(const char* name, HistType ht, EventType et) {
0158   TDirectory* td;
0159 
0160   switch (et) {
0161     case (PEDESTAL):
0162       td = pedHistDir;
0163       break;
0164     case (LED):
0165       td = ledHistDir;
0166       break;
0167     case (LASER):
0168       td = laserHistDir;
0169       break;
0170     case (BEAM):
0171       td = beamHistDir;
0172       break;
0173     case (UNKNOWN):
0174       td = otherHistDir;
0175       break;
0176     default:
0177       td = nullptr;
0178       break;
0179   }
0180 
0181   if (td == nullptr) {
0182     printf("Unknown %d !\n", et);
0183     return nullptr;
0184   }
0185 
0186   TH1* retval = nullptr;
0187 
0188   retval = (TH1*)td->Get(name);
0189   int bins = 0;
0190   double lo = 0, hi = 0;
0191 
0192   // If the histogram doesn't exist and we are authorized,
0193   // create it!
0194   //
0195   if (retval == nullptr) {
0196     td->cd();
0197     switch (ht) {
0198       case (ENERGY): {
0199         switch (et) {
0200           case (PEDESTAL):
0201             bins = PED_BINS;
0202             try {
0203               lo = histoParams_.getParameter<double>("pedGeVlo");
0204               hi = histoParams_.getParameter<double>("pedGeVhi");
0205             } catch (std::exception& e) {  // can't find it!
0206               edm::LogError("HcalQLPlotHistoMgr::GetAHistogram") << "Parameter(s) pedGeVlo/hi not found.";
0207               throw e;
0208             }
0209             break;
0210           case (LED):
0211             bins = LED_BINS;
0212             try {
0213               lo = histoParams_.getParameter<double>("ledGeVlo");
0214               hi = histoParams_.getParameter<double>("ledGeVhi");
0215             } catch (std::exception& e) {  // can't find it!
0216               edm::LogError("HcalQLPlotHistoMgr::GetAHistogram") << "Parameter(s) ledGeVlo/hi not found.";
0217               throw e;
0218             }
0219             break;
0220           case (LASER):
0221             bins = LASER_BINS;
0222             try {
0223               lo = histoParams_.getParameter<double>("laserGeVlo");
0224               hi = histoParams_.getParameter<double>("laserGeVhi");
0225             } catch (std::exception& e) {  // can't find it!
0226               edm::LogError("HcalQLPlotHistoMgr::GetAHistogram") << "Parameter(s) laserGeVlo/hi not found.";
0227               throw e;
0228             }
0229             break;
0230           case (BEAM):
0231             bins = BEAM_BINS;
0232             try {
0233               lo = histoParams_.getParameter<double>("beamGeVlo");
0234               hi = histoParams_.getParameter<double>("beamGeVhi");
0235             } catch (std::exception& e) {  // can't find it!
0236               edm::LogError("HcalQLPlotHistoMgr::GetAHistogram") << "Parameter(s) beamGeVlo/hi not found.";
0237               throw e;
0238             }
0239             break;
0240           case (UNKNOWN):
0241             bins = OTHER_BINS;
0242             try {
0243               lo = histoParams_.getParameter<double>("otherGeVlo");
0244               hi = histoParams_.getParameter<double>("otherGeVhi");
0245             } catch (std::exception& e) {  // can't find it!
0246               edm::LogError("HcalQLPlotHistoMgr::GetAHistogram") << "Parameter(s) otherGeVlo/hi not found.";
0247               throw e;
0248             }
0249             break;
0250           default:
0251             break;
0252         };
0253       } break;
0254       case (TIME):
0255         bins = TIME_BINS;
0256         try {
0257           lo = histoParams_.getParameter<double>("timeNSlo");
0258           hi = histoParams_.getParameter<double>("timeNShi");
0259         } catch (std::exception& e) {  // can't find it!
0260           edm::LogError("HcalQLPlotHistoMgr::GetAHistogram") << "Parameter(s) timeNSlo/hi not found.";
0261           throw e;
0262         }
0263         break;
0264       case (PULSE):
0265         bins = PULSE_BINS;
0266         lo = -0.5;
0267         hi = PULSE_BINS - 0.5;
0268         break;
0269       case (ADC):
0270         bins = PED_BINS;
0271         try {
0272           lo = histoParams_.getParameter<double>("pedADClo");
0273           hi = histoParams_.getParameter<double>("pedADChi");
0274         } catch (std::exception& e) {  // can't find it!
0275           edm::LogError("HcalQLPlotHistoMgr::GetAHistogram") << "Parameter(s) pedADClo/hi not found.";
0276           throw e;
0277         }
0278         break;
0279     }
0280 
0281     if (bins > 0) {
0282       if (ht == PULSE) {
0283         retval = new TProfile(name, name, bins, lo, hi);
0284         retval->GetXaxis()->SetTitle("TimeSlice(25ns)");
0285         retval->GetYaxis()->SetTitle("fC");
0286       } else if (ht == TIME) {
0287         retval = new TH1F(name, name, bins, lo, hi);
0288         retval->GetXaxis()->SetTitle("Timing(ns)");
0289       } else if (ht == ENERGY) {
0290         retval = new TH1F(name, name, bins, lo, hi);
0291         retval->GetXaxis()->SetTitle("Energy(GeV)");
0292       } else if (ht == ADC) {
0293         retval = new TH1F(name, name, bins, lo, hi);
0294         retval->GetXaxis()->SetTitle("ADC Counts");
0295       }
0296     }
0297   }
0298 
0299   return retval;
0300 }