CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/CalibCalorimetry/CastorCalib/interface/CastorPedestalAnalysis.h

Go to the documentation of this file.
00001 #ifndef CastorPedestalAnalysis_H
00002 #define CastorPedestalAnalysis_H
00003 
00004 #include "FWCore/Framework/interface/Frameworkfwd.h"
00005 #include "FWCore/Framework/interface/EDAnalyzer.h"
00006 #include "FWCore/Framework/interface/Event.h"
00007 #include "FWCore/Framework/interface/MakerMacros.h"
00008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00009 #include "FWCore/ServiceRegistry/interface/Service.h"
00010 #include "FWCore/Framework/interface/ESHandle.h"
00011 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00012 #include "DataFormats/HcalDetId/interface/HcalCastorDetId.h"
00013 #include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
00014 
00015 
00016 #include "TH1F.h"
00017 #include "TF1.h"
00018 
00019 #include <memory>
00020 //#include <iostream>
00021 #include <fstream>
00022 #include <vector>
00023 #include <string>
00024 
00025 // User switches for CastorPedestalAnalysis to set in cfg are:
00026 //   nevtsample - number of events per sample in which data will be divided
00027 //                for stability checks (default: 0 = do not use),
00028 //   hiSaveflag - flag to save histos of charge per cap-id (default: 0),
00029 //   pedValflag - pedestal validation flag:
00030 //                0 - write out current raw constants (default)
00031 //                1 - write out validated constants
00032 
00033 class CastorPedestals;
00034 class CastorPedestalWidths;
00035 class CastorDbService;
00036 class CastorQIEShape;
00037 class CastorQIECoder;
00038 class TFile;
00039 class CastorPedestalAnalysis{
00040   
00041 public:
00042   
00044   CastorPedestalAnalysis(const edm::ParameterSet& ps);  
00046   ~CastorPedestalAnalysis();
00047 
00048   void setup(const std::string& m_outputFileROOT);
00049 
00050   void SampleAnalysis();
00051 
00052   int done(const CastorPedestals* fInputPedestals, 
00053             const CastorPedestalWidths* fInputWidths,
00054             CastorPedestals* fOutputPedestals, 
00055             CastorPedestalWidths* fOutputWidths);
00056 
00057   void processEvent(const CastorDigiCollection& castor,
00058                     const CastorDbService& cond);
00059 
00060 // pedestal validation: CastorPedVal=-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 CastorPedVal(int nstat[4], const CastorPedestals* fRefPedestals,
00065             const CastorPedestalWidths* fRefPedestalWidths,
00066             CastorPedestals* fRawPedestals,
00067             CastorPedestalWidths* fRawPedestalWidths,
00068             CastorPedestals* fValPedestals,
00069             CastorPedestalWidths* 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 CastorDbService& 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 CastorQIEShape* m_shape;
00114   const CastorQIECoder* 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   } castorHists;
00124   std::map<HcalDetId,std::map<int, PEDBUNCH > >::iterator _meot;
00125   const CastorPedestals* fRefPedestals;
00126   const CastorPedestalWidths* fRefPedestalWidths;
00127   CastorPedestals* fRawPedestals;
00128   CastorPedestalWidths* fRawPedestalWidths;
00129   CastorPedestals* fValPedestals;
00130   CastorPedestalWidths* 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