Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-12-06 23:18:00

0001 #ifndef HcalPedestalAnalysis_H
0002 #define HcalPedestalAnalysis_H
0003 
0004 #include "FWCore/Framework/interface/Frameworkfwd.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
0007 #include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
0008 
0009 #include "CondFormats/HcalObjects/interface/AllObjects.h"
0010 
0011 #include "TH1F.h"
0012 #include "TF1.h"
0013 
0014 #include <memory>
0015 //#include <iostream>
0016 #include <fstream>
0017 #include <vector>
0018 #include <string>
0019 
0020 // User switches for HcalPedestalAnalysis to set in cfg are:
0021 //   nevtsample - number of events per sample in which data will be divided
0022 //                for stability checks (default: 0 = do not use),
0023 //   hiSaveflag - flag to save histos of charge per cap-id (default: 0),
0024 //   pedValflag - pedestal validation flag:
0025 //                0 - write out current raw constants (default)
0026 //                1 - write out validated constants
0027 
0028 class HcalDbService;
0029 class TFile;
0030 
0031 class HcalPedestalAnalysis {
0032 public:
0033   /// Constructor
0034   HcalPedestalAnalysis(const edm::ParameterSet& ps);
0035   /// Destructor
0036   ~HcalPedestalAnalysis();
0037 
0038   void setup(const std::string& m_outputFileROOT);
0039 
0040   void SampleAnalysis();
0041 
0042   void setTopology(const HcalTopology* htopo) { fTopology = htopo; }
0043 
0044   int done(const HcalPedestals* fInputPedestals,
0045            const HcalPedestalWidths* fInputWidths,
0046            HcalPedestals* fOutputPedestals,
0047            HcalPedestalWidths* fOutputWidths);
0048 
0049   void processEvent(const HBHEDigiCollection& hbhe,
0050                     const HODigiCollection& ho,
0051                     const HFDigiCollection& hf,
0052                     const HcalDbService& cond);
0053 
0054   // pedestal validation: HcalPedVal=-1 means not validated,
0055   //                                  0 everything OK,
0056   //                                  N>0 : mod(N,100000) drifts + width changes
0057   //                                        int(N/100000) missing channels
0058   static int HcalPedVal(int nstat[4],
0059                         const HcalPedestals* fRefPedestals,
0060                         const HcalPedestalWidths* fRefPedestalWidths,
0061                         HcalPedestals* fRawPedestals,
0062                         HcalPedestalWidths* fRawPedestalWidths,
0063                         HcalPedestals* fValPedestals,
0064                         HcalPedestalWidths* fValPedestalWidths);
0065 
0066 protected:
0067 private:
0068   //###
0069   //#  PEDBUNCH is used in map<HcalDetId,map<int, PEDBUNCH > > PEDTRENDS;
0070   //#  For each HcalDetId (channel) a map<int, PEDBUNCH> is associated;
0071   //#  int is cap-id (1-4);
0072   //#  PEDBUNCH is a pair - first element is the main
0073   //#  histo with the pedestal distribution and second one is another pair;
0074   //#  this pair contains map<int, std::vector<double> > as a first element;
0075   //#  int is cap-id, and vector contains some useful variables;
0076   //#  the second element is a vector of histos (pointers);
0077   //#  for the "trend" analysis the main histo (with pedestals) is reset every
0078   //#  nevt_ped events and info is put in the other part of the PEDBUNCH;
0079   //#  so at the end we have the trends for the variables in concern
0080   //#  which are written in THE vector<TH1F*>;
0081   //###
0082   typedef std::pair<TH1F*, std::pair<std::map<int, std::vector<double> >, std::vector<TH1F*> > > PEDBUNCH;
0083 
0084   void per2CapsHists(int flag,
0085                      int id,
0086                      const HcalDetId detid,
0087                      const HcalQIESample& qie1,
0088                      const HcalQIESample& qie2,
0089                      std::map<HcalDetId, std::map<int, PEDBUNCH> >& toolT,
0090                      const HcalDbService& cond);
0091 
0092   void GetPedConst(std::map<HcalDetId, std::map<int, PEDBUNCH> >& toolT, TH1F* PedMeans, TH1F* PedWidths);
0093 
0094   void Trendings(std::map<HcalDetId, std::map<int, PEDBUNCH> >& toolT, TH1F* Chi2, TH1F* CapidAverage, TH1F* CapidChi2);
0095 
0096   void AllChanHists(const HcalDetId detid,
0097                     const HcalQIESample& qie0,
0098                     const HcalQIESample& qie1,
0099                     const HcalQIESample& qie2,
0100                     const HcalQIESample& qie3,
0101                     const HcalQIESample& qie4,
0102                     const HcalQIESample& qie5,
0103                     std::map<HcalDetId, std::map<int, PEDBUNCH> >& toolT);
0104 
0105   TFile* m_file;
0106 
0107   std::string m_outputFileROOT;
0108   std::string m_outputFileMean;
0109   std::string m_outputFileWidth;
0110 
0111   int m_startTS;
0112   int m_endTS;
0113   int m_nevtsample;
0114   int m_pedsinADC;
0115   int m_hiSaveflag;
0116   int m_pedValflag;
0117   int m_AllPedsOK;
0118 
0119   const HcalQIEShape* m_shape;
0120   const HcalQIECoder* m_coder;
0121   struct {
0122     std::map<HcalDetId, std::map<int, PEDBUNCH> > PEDTRENDS;
0123     TH1F* ALLPEDS;
0124     TH1F* PEDRMS;
0125     TH1F* PEDMEAN;
0126     TH1F* CHI2;
0127     TH1F* CAPID_AVERAGE;
0128     TH1F* CAPID_CHI2;
0129   } hbHists, hfHists, hoHists;
0130   std::map<HcalDetId, std::map<int, PEDBUNCH> >::iterator _meot;
0131   const HcalPedestals* fRefPedestals;
0132   const HcalPedestalWidths* fRefPedestalWidths;
0133   HcalPedestals* fRawPedestals;
0134   HcalPedestalWidths* fRawPedestalWidths;
0135   HcalPedestals* fValPedestals;
0136   HcalPedestalWidths* fValPedestalWidths;
0137   int evt;
0138   int sample;
0139   int evt_curr;
0140   float m_stat[4];
0141   std::vector<bool> state;
0142   const HcalTopology* fTopology;
0143   // flag to make gaussian fits to charge dists
0144   static const int fitflag = 0;
0145 };
0146 
0147 #endif