Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:57:33

0001 #ifndef CastorPedestalAnalysis_H
0002 #define CastorPedestalAnalysis_H
0003 
0004 #include "FWCore/Framework/interface/Frameworkfwd.h"
0005 #include "FWCore/Framework/interface/Event.h"
0006 #include "FWCore/Framework/interface/MakerMacros.h"
0007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0008 #include "FWCore/ServiceRegistry/interface/Service.h"
0009 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
0010 #include "DataFormats/HcalDetId/interface/HcalCastorDetId.h"
0011 #include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
0012 
0013 #include "TH1F.h"
0014 #include "TF1.h"
0015 
0016 #include <memory>
0017 //#include <iostream>
0018 #include <fstream>
0019 #include <vector>
0020 #include <string>
0021 
0022 // User switches for CastorPedestalAnalysis to set in cfg are:
0023 //   nevtsample - number of events per sample in which data will be divided
0024 //                for stability checks (default: 0 = do not use),
0025 //   hiSaveflag - flag to save histos of charge per cap-id (default: 0),
0026 //   pedValflag - pedestal validation flag:
0027 //                0 - write out current raw constants (default)
0028 //                1 - write out validated constants
0029 
0030 class CastorPedestals;
0031 class CastorPedestalWidths;
0032 class CastorDbService;
0033 class CastorQIEShape;
0034 class CastorQIECoder;
0035 class TFile;
0036 class CastorPedestalAnalysis {
0037 public:
0038   /// Constructor
0039   CastorPedestalAnalysis(const edm::ParameterSet& ps);
0040   /// Destructor
0041   ~CastorPedestalAnalysis();
0042 
0043   void setup(const std::string& m_outputFileROOT);
0044 
0045   void SampleAnalysis();
0046 
0047   int done(const CastorPedestals* fInputPedestals,
0048            const CastorPedestalWidths* fInputWidths,
0049            CastorPedestals* fOutputPedestals,
0050            CastorPedestalWidths* fOutputWidths);
0051 
0052   void processEvent(const CastorDigiCollection& castor, const CastorDbService& cond);
0053 
0054   // pedestal validation: CastorPedVal=-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 CastorPedVal(int nstat[4],
0059                           const CastorPedestals* fRefPedestals,
0060                           const CastorPedestalWidths* fRefPedestalWidths,
0061                           CastorPedestals* fRawPedestals,
0062                           CastorPedestalWidths* fRawPedestalWidths,
0063                           CastorPedestals* fValPedestals,
0064                           CastorPedestalWidths* 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 CastorDbService& 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   std::ofstream m_logFile;
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 CastorQIEShape* m_shape;
0120   const CastorQIECoder* 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   } castorHists;
0130   std::map<HcalDetId, std::map<int, PEDBUNCH> >::iterator _meot;
0131   const CastorPedestals* fRefPedestals;
0132   const CastorPedestalWidths* fRefPedestalWidths;
0133   CastorPedestals* fRawPedestals;
0134   CastorPedestalWidths* fRawPedestalWidths;
0135   CastorPedestals* fValPedestals;
0136   CastorPedestalWidths* fValPedestalWidths;
0137   int evt;
0138   int sample;
0139   int evt_curr;
0140   float m_stat[4];
0141   std::vector<bool> state;
0142 
0143   // flag to make gaussian fits to charge dists
0144   static const int fitflag = 0;
0145 };
0146 
0147 #endif