00001 #ifndef ecaltimingcalibproducer_h
00002 #define ecaltimingcalibproducer_h
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #define RAWIDCRY 838904321
00034
00035
00036 #define EBCRYex 838861346
00037 #define EECRYex 872422180
00038
00039
00040 #define EBRING 1
00041 #define EEmRING 20
00042 #define EEpRING 20
00043
00044 #define SPEEDOFLIGHT 30.0 // (cm/ns)
00045
00046
00047 #include <memory>
00048 #include <iostream>
00049 #include <fstream>
00050
00051
00052 #include "FWCore/ServiceRegistry/interface/Service.h"
00053 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00054
00055
00056 #include "FWCore/Framework/interface/Frameworkfwd.h"
00057 #include "FWCore/Framework/interface/EDConsumerBase.h"
00058
00059 #include "FWCore/Framework/interface/EDProducer.h"
00060 #include "FWCore/Framework/interface/Event.h"
00061
00062 #include "FWCore/Framework/interface/MakerMacros.h"
00063 #include "FWCore/Utilities/interface/InputTag.h"
00064 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00065
00066 #include "DataFormats/Common/interface/Handle.h"
00067 #include "FWCore/Framework/interface/LooperFactory.h"
00068 #include "FWCore/Framework/interface/ESProducerLooper.h"
00069 #include "FWCore/Framework/interface/ESHandle.h"
00070 #include "FWCore/Framework/interface/ESProducts.h"
00071 #include "FWCore/Framework/interface/Event.h"
00072
00073 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00074
00075 #include "Calibration/Tools/interface/EcalRingCalibrationTools.h"
00076 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
00077 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
00078 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00079
00080
00081 #include "CondFormats/DataRecord/interface/EcalTimeCalibConstantsRcd.h"
00082 #include "CondFormats/DataRecord/interface/EcalTimeCalibErrorsRcd.h"
00083 #include "CondFormats/DataRecord/interface/EcalTimeOffsetConstantRcd.h"
00084 #include "CondTools/Ecal/interface/EcalTimeCalibConstantsXMLTranslator.h"
00085 #include "CondTools/Ecal/interface/EcalTimeCalibErrorsXMLTranslator.h"
00086 #include "CondTools/Ecal/interface/EcalTimeOffsetXMLTranslator.h"
00087 #include "CondTools/Ecal/interface/EcalCondHeader.h"
00088
00089 #include "CondFormats/EcalObjects/interface/EcalTimeCalibConstants.h"
00090 #include "CondFormats/EcalObjects/interface/EcalTimeCalibErrors.h"
00091 #include "CondFormats/EcalObjects/interface/EcalTimeOffsetConstant.h"
00092
00093 #include "EcalTiming/EcalTiming/interface/EcalTimingEvent.h"
00094 #include "EcalTiming/EcalTiming/interface/EcalCrystalTimingCalibration.h"
00095
00096 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00097 #include "DataFormats/EcalDetId/interface/EEDetId.h"
00098
00099 #include "TProfile.h"
00100 #include "TGraphErrors.h"
00101 #include "TGraph.h"
00102 #include "TH1F.h"
00103 #include "TH2F.h"
00104 #include "TFile.h"
00105 #include "TProfile2D.h"
00106
00107 #include <fstream>
00108 #include <string>
00109 #include <vector>
00110 #include <iostream>
00111 #include <map>
00112 #include <vector>
00113 #include <algorithm>
00114 #include <functional>
00115 #include <set>
00116 #include <assert.h>
00117 #include <time.h>
00118
00119 #include <TMath.h>
00120 #include <Math/VectorUtil.h>
00121
00122
00123 #include "EcalTiming/EcalTiming/interface/EcalTimeCalibrationMapFwd.h"
00124
00125 class EcalTimingCalibProducer : public edm::ESProducerLooper
00126 {
00127
00128 private:
00129 EcalTimeCalibrationMap _timeCalibMap;
00130 EventTimeMap _eventTimeMap;
00131
00132
00133 EcalCrystalTimingCalibration timeEEP;
00134 EcalCrystalTimingCalibration timeEEM;
00135 EcalCrystalTimingCalibration timeEB;
00136 EcalCrystalTimingCalibration timeEBRing;
00137 EcalCrystalTimingCalibration timeEEmRing;
00138 EcalCrystalTimingCalibration timeEEpRing;
00139 EcalCrystalTimingCalibration timeEBCRYex;
00140 EcalCrystalTimingCalibration timeEECRYex;
00141
00142 float nearEndcapTime;
00143 float farEndcapTime;
00144
00145 public:
00146 EcalTimingCalibProducer(const edm::ParameterSet&);
00147 ~EcalTimingCalibProducer();
00148
00149
00150 virtual void beginOfJob(const edm::EventSetup&);
00151 virtual void startingNewLoop(unsigned int ) ;
00152 virtual Status duringLoop(const edm::Event&, const edm::EventSetup&) ;
00153 virtual Status endOfLoop(const edm::EventSetup&, unsigned int);
00154 virtual void endOfJob();
00155 private:
00156
00157
00158
00159
00160
00161
00162 unsigned int _maxLoop;
00163 bool _isSplash;
00164 bool _makeEventPlots;
00165 edm::InputTag _ecalRecHitsEBTAG;
00166 edm::InputTag _ecalRecHitsEETAG;
00167 std::vector<int> _recHitFlags;
00168 unsigned int _recHitMin;
00169 double _minRecHitEnergy;
00170 double _minRecHitEnergyStep;
00171 unsigned int _minEntries;
00172 float _globalOffset;
00173 bool _produceNewCalib;
00174 std::string _outputDumpFileName;
00175 float _noiseRMSThreshold;
00176 float _noiseTimeThreshold;
00177 float _maxSkewnessForDump;
00178
00179
00180 void dumpCalibration(std::string filename);
00181 void dumpCorrections(std::string filename);
00182
00183
00184
00185 void FillCalibrationCorrectionHists(EcalTimeCalibrationMap::const_iterator cal_itr);
00186 void initHists(TFileDirectory dir);
00187 void initEventHists(TFileDirectory dir);
00188 void initTree(TFileDirectory dir);
00189
00190
00191 void createConstants(const edm::EventSetup& iSetup)
00192 {
00193
00194
00195 edm::ESHandle<EcalTimeCalibConstants> ecalTimeCalibConstantsHandle;
00196 iSetup.get<EcalTimeCalibConstantsRcd>().get( ecalTimeCalibConstantsHandle);
00197 _timeCalibConstants = *ecalTimeCalibConstantsHandle;
00198 #ifdef DEBUG
00199
00200 for(auto t_itr = _timeCalibConstants.begin(); t_itr != _timeCalibConstants.end() && t_itr - _timeCalibConstants.begin() < 10; ++t_itr) {
00201 std::cout << "t_itr = " << *t_itr << std::endl;
00202 }
00203 #endif
00204 produceCalibConstants(iSetup.get<EcalTimeCalibConstantsRcd>());
00205
00206
00207 edm::ESHandle<EcalTimeCalibErrors> ecalTimeCalibErrorsHandle;
00208
00209
00210
00211
00212
00213 edm::ESHandle<EcalTimeOffsetConstant> ecalTimeOffsetConstantHandle;
00214 iSetup.get<EcalTimeOffsetConstantRcd>().get( ecalTimeOffsetConstantHandle);
00215 _timeOffsetConstant = *ecalTimeOffsetConstantHandle;
00216 produceOffsetConstant(iSetup.get<EcalTimeOffsetConstantRcd>());
00217
00218 }
00219
00220 EcalTimeCalibConstants _timeCalibConstants;
00221 boost::shared_ptr<EcalTimeCalibConstants> _calibConstants;
00222 inline boost::shared_ptr<EcalTimeCalibConstants> produceCalibConstants(const EcalTimeCalibConstantsRcd& iRecord)
00223 {
00224
00225 _calibConstants = boost::shared_ptr<EcalTimeCalibConstants>( new EcalTimeCalibConstants(_timeCalibConstants) );
00226 return _calibConstants;
00227 }
00228
00229 EcalTimeCalibErrors _timeCalibErrors;
00230 boost::shared_ptr<EcalTimeCalibErrors> _calibErrors;
00231 inline boost::shared_ptr<EcalTimeCalibErrors>& produceCalibErrors(const EcalTimeCalibErrorsRcd& iRecord)
00232 {
00233 _calibErrors = boost::shared_ptr<EcalTimeCalibErrors>( new EcalTimeCalibErrors(_timeCalibErrors) );
00234 return _calibErrors;
00235 }
00236
00237 EcalTimeOffsetConstant _timeOffsetConstant;
00238 boost::shared_ptr<EcalTimeOffsetConstant> _offsetConstant;
00239 inline boost::shared_ptr<EcalTimeOffsetConstant> produceOffsetConstant(const EcalTimeOffsetConstantRcd& iRecord)
00240 {
00241 _offsetConstant = boost::shared_ptr<EcalTimeOffsetConstant>( new EcalTimeOffsetConstant(_timeOffsetConstant) );
00242 return _offsetConstant;
00243 }
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257 bool addRecHit(const EcalRecHit& recHit, EventTimeMap& eventTimeMap_);
00258
00259
00260
00261 void plotRecHit(const EcalTimingEvent& recHit);
00262
00263
00264
00265
00266 EcalTimingEvent correctGlobalOffset(const EcalTimingEvent& ev, int splashDir, float bunchCorr);
00267
00268 std::map<DetId, float> _CrysEnergyMap;
00269
00270 edm::Service<TFileService> fileService_;
00271 TFileDirectory histDir_;
00272
00273 TTree *timeEBCRYexTree, *timeEECRYexTree, *timeEEpRingTree, *timeEEmRingTree, *timeEBRingTree;
00274 TTree *_unstableEnergyTree, *_highSkewnessTree;
00275
00276
00277 TProfile2D* EneMapEEP_;
00278 TProfile2D* EneMapEEM_;
00279 TProfile2D* TimeMapEEP_;
00280 TProfile2D* TimeMapEEM_;
00281
00282 TProfile2D* EneMapEB_;
00283 TProfile2D* TimeMapEB_;
00284
00285
00286 TProfile2D* TimeErrorMapEEP_;
00287 TProfile2D* TimeErrorMapEEM_;
00288
00289 TProfile2D* TimeErrorMapEB_;
00290
00291
00292 TProfile2D * Event_EneMapEEP_;
00293 TProfile2D * Event_EneMapEEM_;
00294 TProfile2D * Event_EneMapEB_;
00295
00296 TProfile2D* Event_TimeMapEEP_;
00297 TProfile2D* Event_TimeMapEEM_;
00298 TProfile2D* Event_TimeMapEB_;
00299
00300 TProfile2D* Event_TimeMapEEP_OOT;
00301 TProfile2D* Event_TimeMapEEM_OOT;
00302 TProfile2D* Event_TimeMapEB_OOT;
00303
00304 TH1F* RechitEneEB_;
00305 TH1F* RechitTimeEB_;
00306 TH1F* RechitEneEEM_;
00307 TH1F* RechitTimeEEM_;
00308 TH1F* RechitEneEEP_;
00309 TH1F* RechitTimeEEP_;
00310
00311 TH2F* RechitEnergyTimeEB;
00312 TH2F* RechitEnergyTimeEEM;
00313 TH2F* RechitEnergyTimeEEP;
00314
00315 EcalRingCalibrationTools _ringTools;
00316 const CaloSubdetectorGeometry * endcapGeometry_;
00317 const CaloSubdetectorGeometry * barrelGeometry_;
00318
00319 std::vector<int> _noisyXtals;
00320 std::vector<TH1F*> _noisyXtalsHists;
00321 unsigned int _iter;
00322 };
00323
00324 #endif