CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/CalibCalorimetry/HcalAlgos/interface/HcalPedestalAnalysis.h

Go to the documentation of this file.
00001 #ifndef HcalPedestalAnalysis_H
00002 #define HcalPedestalAnalysis_H
00003 
00004 
00005 #include "FWCore/Framework/interface/Frameworkfwd.h"
00006 #include "FWCore/Framework/interface/EDAnalyzer.h"
00007 #include "FWCore/Framework/interface/Event.h"
00008 #include "FWCore/Framework/interface/MakerMacros.h"
00009 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00010 #include "FWCore/ServiceRegistry/interface/Service.h"
00011 #include "FWCore/Framework/interface/ESHandle.h"
00012 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00013 #include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
00014 
00015 #include "CondFormats/HcalObjects/interface/AllObjects.h"
00016 
00017 #include "TH1F.h"
00018 #include "TF1.h"
00019 
00020 #include <memory>
00021 //#include <iostream>
00022 #include <fstream>
00023 #include <vector>
00024 #include <string>
00025 
00026 // User switches for HcalPedestalAnalysis to set in cfg are:
00027 //   nevtsample - number of events per sample in which data will be divided
00028 //                for stability checks (default: 0 = do not use),
00029 //   hiSaveflag - flag to save histos of charge per cap-id (default: 0),
00030 //   pedValflag - pedestal validation flag:
00031 //                0 - write out current raw constants (default)
00032 //                1 - write out validated constants
00033 
00034 class HcalDbService;
00035 class TFile;
00036 
00037 class HcalPedestalAnalysis{
00038   
00039 public:
00040   
00042   HcalPedestalAnalysis(const edm::ParameterSet& ps);  
00044   ~HcalPedestalAnalysis();
00045 
00046   void setup(const std::string& m_outputFileROOT);
00047 
00048   void SampleAnalysis();
00049 
00050   int done(const HcalPedestals* fInputPedestals, 
00051             const HcalPedestalWidths* fInputWidths,
00052             HcalPedestals* fOutputPedestals, 
00053             HcalPedestalWidths* fOutputWidths);
00054 
00055   void processEvent(const HBHEDigiCollection& hbhe,
00056                     const HODigiCollection& ho,
00057                     const HFDigiCollection& hf,
00058                     const HcalDbService& cond);
00059 
00060 // pedestal validation: HcalPedVal=-1 means not validated,
00061 //                                  0 everything OK,
00062 //                                  N>0 : mod(N,100000) drifts + width changes
00063 //                                        int(N/100000) missing channels
00064   static int HcalPedVal(int nstat[4], const HcalPedestals* fRefPedestals,
00065             const HcalPedestalWidths* fRefPedestalWidths,
00066             HcalPedestals* fRawPedestals,
00067             HcalPedestalWidths* fRawPedestalWidths,
00068             HcalPedestals* fValPedestals,
00069             HcalPedestalWidths* fValPedestalWidths);
00070 
00071 protected:
00072   
00073   
00074 private:
00075   //###
00076   //#  PEDBUNCH is used in map<HcalDetId,map<int, PEDBUNCH > > PEDTRENDS;
00077   //#  For each HcalDetId (channel) a map<int, PEDBUNCH> is associated;
00078   //#  int is cap-id (1-4);
00079   //#  PEDBUNCH is a pair - first element is the main 
00080   //#  histo with the pedestal distribution and second one is another pair;
00081   //#  this pair contains map<int, std::vector<double> > as a first element;
00082   //#  int is cap-id, and vector contains some useful variables;
00083   //#  the second element is a vector of histos (pointers);
00084   //#  for the "trend" analysis the main histo (with pedestals) is reset every 
00085   //#  nevt_ped events and info is put in the other part of the PEDBUNCH;
00086   //#  so at the end we have the trends for the variables in concern
00087   //#  which are written in THE vector<TH1F*>; 
00088   //###  
00089   typedef std::pair<TH1F*,std::pair<std::map<int, std::vector<double> >,std::vector<TH1F*> > > PEDBUNCH;
00090 
00091   void per2CapsHists(int flag, int id, const HcalDetId detid, const HcalQIESample& qie1, const HcalQIESample& qie2, std::map<HcalDetId, std::map<int,PEDBUNCH> > &toolT,const HcalDbService& cond);
00092 
00093   void GetPedConst(std::map<HcalDetId,std::map<int, PEDBUNCH > > &toolT, TH1F* PedMeans, TH1F* PedWidths);
00094 
00095   void Trendings(std::map<HcalDetId,std::map<int, PEDBUNCH > > &toolT, TH1F* Chi2, TH1F* CapidAverage, TH1F* CapidChi2);
00096 
00097   void AllChanHists(const HcalDetId detid, const HcalQIESample& qie0, const HcalQIESample& qie1, const HcalQIESample& qie2, const HcalQIESample& qie3, const HcalQIESample& qie4, const HcalQIESample& qie5, std::map<HcalDetId, std::map<int,PEDBUNCH> > &toolT);
00098 
00099   TFile* m_file;
00100 
00101   std::string m_outputFileROOT;
00102   std::string m_outputFileMean;
00103   std::string m_outputFileWidth;
00104   std::ofstream m_logFile;
00105   int m_startTS;
00106   int m_endTS;
00107   int m_nevtsample;
00108   int m_pedsinADC;
00109   int m_hiSaveflag;
00110   int m_pedValflag;
00111   int m_AllPedsOK;
00112   
00113   const HcalQIEShape* m_shape;
00114   const HcalQIECoder* m_coder;
00115   struct{
00116     std::map<HcalDetId,std::map<int, PEDBUNCH > > PEDTRENDS;
00117     TH1F* ALLPEDS;
00118     TH1F* PEDRMS;
00119     TH1F* PEDMEAN;
00120     TH1F* CHI2;
00121     TH1F* CAPID_AVERAGE;
00122     TH1F* CAPID_CHI2;
00123   } hbHists, hfHists, hoHists;
00124   std::map<HcalDetId,std::map<int, PEDBUNCH > >::iterator _meot;
00125   const HcalPedestals* fRefPedestals;
00126   const HcalPedestalWidths* fRefPedestalWidths;
00127   HcalPedestals* fRawPedestals;
00128   HcalPedestalWidths* fRawPedestalWidths;
00129   HcalPedestals* fValPedestals;
00130   HcalPedestalWidths* fValPedestalWidths;
00131   int evt;
00132   int sample;
00133   int evt_curr;
00134   float m_stat[4];
00135   std::vector<bool> state;
00136 
00137 // flag to make gaussian fits to charge dists
00138   static const int fitflag=0;
00139 };
00140 
00141 #endif