CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/RecoTBCalo/HcalPlotter/src/HcalQLPlotHistoMgr.cc

Go to the documentation of this file.
00001 #include "FWCore/Utilities/interface/EDMException.h"
00002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00003 #include "RecoTBCalo/HcalPlotter/src/HcalQLPlotHistoMgr.h"
00004 #include "TProfile.h"
00005 
00006 //Declare Histogram Bin parameters
00007 static const int PED_BINS=50;
00008 static const int LED_BINS=50;
00009 static const int LASER_BINS=70;
00010 static const int BEAM_BINS=70;
00011 static const int OTHER_BINS=100;
00012 static const int TIME_BINS=75;
00013 static const int PULSE_BINS=10;
00014 
00015 HcalQLPlotHistoMgr::HcalQLPlotHistoMgr(TDirectory* parent,
00016                                        const edm::ParameterSet& histoParams) {
00017   pedHistDir=parent->mkdir("PEDESTAL");
00018   ledHistDir=parent->mkdir("LED");
00019   laserHistDir=parent->mkdir("LASER");
00020   beamHistDir=parent->mkdir("BEAM");
00021   otherHistDir=parent->mkdir("OTHER");
00022   histoParams_ = histoParams;
00023 }
00024 
00025 std::string HcalQLPlotHistoMgr::nameForFlavor(HistType ht) {
00026   switch (ht) {
00027   case(ENERGY): return "Energy"; break;
00028   case(TIME):  return "Time"; break;
00029   case(PULSE):  return "Pulse"; break;
00030   case(ADC):  return "ADC"; break;
00031   default: return ""; break;
00032   }
00033 }
00034 
00035 std::string HcalQLPlotHistoMgr::nameForEvent(EventType et) {
00036   switch(et) {
00037   case(PEDESTAL): return "Pedestal"; break;
00038   case(LED): return "LED"; break;
00039   case(LASER): return "Laser"; break;
00040   case(BEAM): return "Beam"; break;
00041   default: return "Other"; break;
00042   }     
00043 }
00044 
00045 TH1* HcalQLPlotHistoMgr::GetAHistogram(const HcalDetId& id,
00046                                        const HcalElectronicsId& eid,
00047                                        HistType ht, EventType et)
00048 {
00049   std::string flavor=nameForFlavor(ht);
00050 
00051   char name[120];
00052 
00053   std::string subdetStr;
00054   switch (id.subdet()) {
00055   case (HcalBarrel)  : subdetStr="HB"; break;
00056   case (HcalEndcap)  : subdetStr="HE"; break;
00057   case (HcalOuter)   : subdetStr="HO"; break;
00058   case (HcalForward) : subdetStr="HF"; break;
00059   default: subdetStr="Other"; break;
00060   }
00061 
00062   sprintf(name,"%s_%s_%d_%d_%d_eid=%d_%d_%d_%d_HTR_%d:%d%c",
00063           flavor.c_str(),subdetStr.c_str(),id.ieta(),id.iphi(),id.depth(),
00064           eid.dccid(),eid.spigot(), eid.fiberIndex(), eid.fiberChanId(),
00065           eid.readoutVMECrateId(), eid.htrSlot(),(eid.htrTopBottom()==1)?('t'):('b') );
00066 
00067   return GetAHistogramImpl(name,ht,et);
00068 }
00069 
00070 TH1* HcalQLPlotHistoMgr::GetAHistogram(const HcalCalibDetId& id,
00071                                        const HcalElectronicsId& eid,
00072                                        HistType ht, EventType et)
00073 {
00074   std::string flavor=nameForFlavor(ht);
00075 
00076   char name[120];
00077 
00078   std::string subdetStr;
00079   switch (id.hcalSubdet()) {
00080   case (HcalBarrel)  : subdetStr="HB"; break;
00081   case (HcalEndcap)  : subdetStr="HE"; break;
00082   case (HcalOuter)   : subdetStr="HO"; break;
00083   case (HcalForward) : subdetStr="HF"; break;
00084   default: subdetStr="Other"; break;
00085   }
00086 
00087   std::string chanstring = id.cboxChannelString();
00088   if (!chanstring.size()) {
00089     chanstring = "Unknown";
00090     edm::LogInfo("HcalQLPlotHistoMgr::GetAHistogram") << "Unknown calibration channel " << id.cboxChannel();
00091   }
00092 
00093   sprintf(name,"%s_CALIB_%s_%d_%d_chan=%s_eid=%d_%d_%d_%d_HTR_%d:%d%c",
00094           flavor.c_str(),subdetStr.c_str(),id.ieta(),id.iphi(),chanstring.c_str(),
00095           eid.dccid(),eid.spigot(), eid.fiberIndex(), eid.fiberChanId(),
00096           eid.readoutVMECrateId(), eid.htrSlot(),(eid.htrTopBottom()==1)?('t'):('b') );
00097 
00098   return GetAHistogramImpl(name,ht,et);
00099 }
00100 
00101 TH1* HcalQLPlotHistoMgr::GetAHistogramImpl(const char *name,
00102                                            HistType ht, EventType et)
00103 {
00104   TDirectory* td;
00105 
00106   switch (et) {
00107   case(PEDESTAL): td=pedHistDir; break;
00108   case(LED): td=ledHistDir; break;
00109   case(LASER): td=laserHistDir; break;
00110   case(BEAM): td=beamHistDir; break;
00111   case(UNKNOWN): td=otherHistDir; break;
00112   default: td=0; break;
00113   }
00114 
00115   if (td==0) {
00116     printf("Unknown %d !\n", et);
00117     return 0;
00118   }
00119 
00120   TH1* retval=0;
00121 
00122   retval=(TH1*)td->Get(name);
00123   int bins=0; double lo=0, hi=0;
00124 
00125   // If the histogram doesn't exist and we are authorized,
00126   // create it!
00127   //
00128   if (retval==0) {
00129     td->cd();
00130     switch (ht) {
00131     case(ENERGY): {
00132       switch (et) {
00133       case(PEDESTAL):
00134         bins=PED_BINS;
00135         try {
00136           lo=histoParams_.getParameter<double>("pedGeVlo");
00137           hi=histoParams_.getParameter<double>("pedGeVhi");
00138         } catch (std::exception& e) { // can't find it!
00139           edm::LogError("HcalQLPlotHistoMgr::GetAHistogram") << "Parameter(s) pedGeVlo/hi not found.";
00140           throw e;
00141         }
00142         break;
00143       case(LED):
00144         bins=LED_BINS;
00145         try {
00146           lo=histoParams_.getParameter<double>("ledGeVlo");
00147           hi=histoParams_.getParameter<double>("ledGeVhi");
00148         } catch (std::exception& e) { // can't find it!
00149           edm::LogError("HcalQLPlotHistoMgr::GetAHistogram") << "Parameter(s) ledGeVlo/hi not found.";
00150           throw e;
00151         }
00152         break;
00153       case(LASER):
00154         bins=LASER_BINS;
00155         try {
00156           lo=histoParams_.getParameter<double>("laserGeVlo");
00157           hi=histoParams_.getParameter<double>("laserGeVhi");
00158         } catch (std::exception& e) { // can't find it!
00159           edm::LogError("HcalQLPlotHistoMgr::GetAHistogram") << "Parameter(s) laserGeVlo/hi not found.";
00160           throw e;
00161         }
00162         break;
00163       case(BEAM):
00164         bins=BEAM_BINS;
00165         try {
00166           lo=histoParams_.getParameter<double>("beamGeVlo");
00167           hi=histoParams_.getParameter<double>("beamGeVhi");
00168         } catch (std::exception& e) { // can't find it!
00169           edm::LogError("HcalQLPlotHistoMgr::GetAHistogram") << "Parameter(s) beamGeVlo/hi not found.";
00170           throw e;
00171         }
00172         break;
00173       case(UNKNOWN):
00174         bins=OTHER_BINS;
00175         try {
00176           lo=histoParams_.getParameter<double>("otherGeVlo");
00177           hi=histoParams_.getParameter<double>("otherGeVhi");
00178         } catch (std::exception& e) { // can't find it!
00179           edm::LogError("HcalQLPlotHistoMgr::GetAHistogram") << "Parameter(s) otherGeVlo/hi not found.";
00180           throw e;
00181         }
00182         break;
00183       default: break;
00184       };
00185     }
00186       break;
00187     case(TIME):
00188       bins=TIME_BINS;
00189       try {
00190         lo=histoParams_.getParameter<double>("timeNSlo");
00191         hi=histoParams_.getParameter<double>("timeNShi");
00192       } catch (std::exception& e) { // can't find it!
00193         edm::LogError("HcalQLPlotHistoMgr::GetAHistogram") << "Parameter(s) timeNSlo/hi not found.";
00194         throw e;
00195       }
00196       break;
00197     case(PULSE):
00198       bins=PULSE_BINS;
00199       lo=-0.5;
00200       hi=PULSE_BINS-0.5;
00201       break;
00202     case(ADC):
00203       bins=PED_BINS;
00204       try {
00205         lo=histoParams_.getParameter<double>("pedADClo");
00206         hi=histoParams_.getParameter<double>("pedADChi");
00207       } catch (std::exception& e) { // can't find it!
00208         edm::LogError("HcalQLPlotHistoMgr::GetAHistogram") << "Parameter(s) pedADClo/hi not found.";
00209         throw e;
00210       }
00211       break;
00212     }
00213    
00214     if (bins>0){
00215       if (ht==PULSE){
00216         retval=new TProfile(name,name,bins,lo,hi);
00217         retval->GetXaxis()->SetTitle("TimeSlice(25ns)");
00218         retval->GetYaxis()->SetTitle("fC");
00219       }   
00220       else if (ht==TIME){
00221         retval=new TH1F(name,name,bins,lo,hi);
00222         retval->GetXaxis()->SetTitle("Timing(ns)");
00223       }
00224       else if (ht==ENERGY){
00225         retval=new TH1F(name,name,bins,lo,hi);
00226         retval->GetXaxis()->SetTitle("Energy(GeV)");
00227       }
00228       else if (ht==ADC){
00229         retval=new TH1F(name,name,bins,lo,hi);
00230         retval->GetXaxis()->SetTitle("ADC Counts");
00231       }
00232     } 
00233   }
00234 
00235   return retval;
00236 }