CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/Calibration/HcalCalibAlgos/src/HcalCalibrator.cc

Go to the documentation of this file.
00001 // -*- C++ -*-F
00002 //---------------------------------------------------------------------------------
00003 // Package:    HcalCalibrator
00004 // Class:      HcalCalibrator
00005 // 
00019 //
00020 // Original Author:  "Anton Anastassov"
00021 //         Created:  Tue Sept 24 09:13:48 CDT 2008
00022 // $Id: HcalCalibrator.cc,v 1.7 2012/11/12 21:08:18 dlange Exp $
00023 //
00024 //
00025 //_________________________________________________________________________________
00026 
00027 
00028 
00029 // system include files
00030 #include <memory>
00031 #include <fstream>
00032 
00033 // user include files
00034 
00035 #include "Calibration/HcalCalibAlgos/interface/HcalCalibrator.h"
00036 #include "Calibration/HcalCalibAlgos/interface/hcalCalib.h"
00037 
00038 #include "FWCore/Framework/interface/Frameworkfwd.h"
00039 #include "FWCore/Framework/interface/Event.h"
00040 
00041 
00042 #include "FWCore/Framework/interface/MakerMacros.h"
00043 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00044 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00045 
00046 //--------------
00047 #include "FWCore/Framework/interface/EventSetup.h"
00048 
00049 #include "FWCore/Framework/interface/MakerMacros.h"
00050 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00051 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00052 #include "FWCore/ServiceRegistry/interface/Service.h"
00053 #include "FWCore/Framework/interface/ESHandle.h"
00054 
00055 #include "DataFormats/Common/interface/Handle.h"
00056 
00057 #include "TFile.h"
00058 
00059 
00060 
00061 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00062 
00063 
00064 
00065 
00066 using namespace edm;
00067 //using namespace reco;
00068 using namespace std;
00069 
00070 
00071 // constructor
00072 
00073 HcalCalibrator::HcalCalibrator(const edm::ParameterSet& conf) :
00074 
00075   mInputFileList(conf.getUntrackedParameter<string>("inputFileList")),
00076   //  mOutputFile(conf.getUntrackedParameter<string>("outputFile")),
00077 
00078   mCalibType(conf.getUntrackedParameter<string>("calibType")),
00079   mCalibMethod(conf.getUntrackedParameter<string>("calibMethod")),
00080   mMinTargetE(conf.getUntrackedParameter<double>("minTargetE")),
00081   mMaxTargetE(conf.getUntrackedParameter<double>("maxTargetE")),
00082   mMinCellE(conf.getUntrackedParameter<double>("minCellE")),
00083   mMinEOverP(conf.getUntrackedParameter<double>("minEOverP")),
00084   mMaxEOverP(conf.getUntrackedParameter<double>("maxEOverP")),
00085   mMaxTrkEmE(conf.getUntrackedParameter<double>("maxTrkEmE")),
00086   mMaxEtThirdJet(conf.getUntrackedParameter<double>("maxEtThirdJet")),
00087   mMinDPhiDiJets(conf.getUntrackedParameter<double>("minDPhiDiJets")),
00088   mSumDepths(conf.getUntrackedParameter<bool>("sumDepths")),
00089   mSumSmallDepths(conf.getUntrackedParameter<bool>("sumSmallDepths")),
00090   mCombinePhi (conf.getUntrackedParameter<bool>("combinePhi")),   
00091   mHbClusterSize(conf.getUntrackedParameter<int>("hbClusterSize")),
00092   mHeClusterSize(conf.getUntrackedParameter<int>("heClusterSize")), 
00093 
00094   mUseConeClustering(conf.getUntrackedParameter<bool>("useConeClustering")),
00095   mMaxConeDist(conf.getUntrackedParameter<double>("maxConeDist")),
00096 
00097   mCalibAbsIEtaMax(conf.getUntrackedParameter<int>("calibAbsIEtaMax")),
00098   mCalibAbsIEtaMin(conf.getUntrackedParameter<int>("calibAbsIEtaMin")),
00099   mMaxProbeJetEmFrac(conf.getUntrackedParameter<double>("maxProbeJetEmFrac")),
00100   mMaxTagJetEmFrac(conf.getUntrackedParameter<double>("maxTagJetEmFrac")),
00101   mMaxTagJetAbsEta(conf.getUntrackedParameter<double>("maxTagJetAbsEta")),
00102   mMinTagJetEt(conf.getUntrackedParameter<double>("minTagJetEt")),
00103   mMinProbeJetAbsEta(conf.getUntrackedParameter<double>("minProbeJetAbsEta")),
00104   mPhiSymCorFileName(conf.getUntrackedParameter<string>("phiSymCorFileName")),
00105   mApplyPhiSymCorFlag(conf.getUntrackedParameter<bool>("applyPhiSymCorFlag")),
00106   mOutputCorCoefFileName(conf.getUntrackedParameter<string>("outputCorCoefFileName")),
00107   mHistoFileName(conf.getUntrackedParameter<string>("histoFileName"))
00108 
00109 {
00110 }
00111 
00112 
00113 // destructor
00114 
00115 HcalCalibrator::~HcalCalibrator() {
00116 }
00117 
00118 // ------------ method called to for each event  ------------
00119 
00120 void
00121 HcalCalibrator::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
00122    edm::ESHandle<CaloGeometry> pG;
00123    iSetup.get<CaloGeometryRecord>().get(pG);
00124    mTheCaloGeometry = pG.product();
00125    edm::ESHandle<HcalTopology> pT;
00126    iSetup.get<IdealGeometryRecord>().get(pT);
00127    mTheHcalTopology = pT.product();
00128 }
00129 
00130 // ------------ method called once each job just before starting event loop  ------------
00131 
00132 void
00133 HcalCalibrator::beginJob() {
00134 
00135   //  ESHandle<CaloGeometry> theGeometry;
00136   //  ESHandle<CaloSubdetectorGeometry> theEndcapGeometry_handle, theBarrelGeometry_handle;
00137   //  evtSetup.get<CaloGeometryRecord>().get( theGeometry );
00138 
00139 
00140   // edm::ESHandle<CaloGeometry> pG;
00141   // evtSetup.get<CaloGeometryRecord>().get(pG);     
00142   // mTheCaloGeometry = pG.product();
00143 
00144 }
00145 
00146 // ------------ method called once each job just after ending the event loop  ------------
00147 
00148 void
00149 HcalCalibrator::endJob() {
00150  
00151 
00152   if (mCalibType!="DI_JET" && mCalibType!="ISO_TRACK") {
00153     cout << "\n\nUnknown calibration type " << mCalibType << endl;
00154     cout << "Please select ISO_TRACK or DI_JET in the python file." << endl;
00155     return;
00156   }
00157 
00158   if (mCalibMethod != "L3" && mCalibMethod != "MATRIX_INV_OF_ETA_AVE" && mCalibMethod != "L3_AND_MTRX_INV") {
00159     cout << "\n\nUnknown calibration method " << mCalibMethod << endl;
00160     cout << "Supported methods for IsoTrack calibration are: L3, MATRIX_INV_OF_ETA_AVE, L3_AND_MTRX_INV" << endl;
00161     cout << "For DiJets the supported method is L3" << endl;
00162     return;
00163   }
00164 
00165   if (mCalibType=="DI_JET" && mCalibMethod!="L3") {
00166     cout << "\n\nDiJet calibration can use only the L3 method. Please change the python file." << endl;
00167     return;
00168   }
00169 
00170   if (mCalibAbsIEtaMin<1 || mCalibAbsIEtaMax>41 || mCalibAbsIEtaMin>mCalibAbsIEtaMax) {
00171     cout << "\n\nInvalid ABS(iEta) calibration range. Check calibAbsIEtaMin and calibAbsIEtaMax in the python file." << endl;
00172     return;
00173   }
00174 
00175 
00176 
00177   hcalCalib* calibrator = new hcalCalib();
00178 
00179   // set the parameters controlling the calibratoration
00180 
00181   calibrator->SetCalibType(mCalibType); 
00182   calibrator->SetCalibMethod(mCalibMethod);
00183   calibrator->SetMinTargetE(mMinTargetE);
00184   calibrator->SetMaxTargetE(mMaxTargetE);
00185   calibrator->SetMaxEtThirdJet(mMaxEtThirdJet);
00186   calibrator->SetMinDPhiDiJets(mMinDPhiDiJets);
00187   calibrator->SetSumDepthsFlag(mSumDepths);
00188   calibrator->SetSumSmallDepthsFlag(mSumSmallDepths);
00189   calibrator->SetCombinePhiFlag(mCombinePhi);
00190   calibrator->SetMinCellE(mMinCellE);
00191   calibrator->SetMinEOverP(mMinEOverP);
00192   calibrator->SetMaxEOverP(mMaxEOverP);
00193   calibrator->SetMaxTrkEmE(mMaxTrkEmE);
00194   calibrator->SetHbClusterSize(mHbClusterSize);
00195   calibrator->SetHeClusterSize(mHeClusterSize);
00196 
00197   calibrator->SetUseConeClustering(mUseConeClustering);
00198   calibrator->SetConeMaxDist(mMaxConeDist); 
00199 
00200   calibrator->SetCalibAbsIEtaMax(mCalibAbsIEtaMax);
00201   calibrator->SetCalibAbsIEtaMin(mCalibAbsIEtaMin);
00202   calibrator->SetMaxProbeJetEmFrac(mMaxProbeJetEmFrac);
00203   calibrator->SetMaxTagJetEmFrac(mMaxTagJetEmFrac);
00204   calibrator->SetMaxTagJetAbsEta(mMaxTagJetAbsEta);
00205 
00206   calibrator->SetMinTagJetEt(mMinTagJetEt);
00207 
00208   calibrator->SetMinProbeJetAbsEta(mMinProbeJetAbsEta);
00209   calibrator->SetApplyPhiSymCorFlag(mApplyPhiSymCorFlag);
00210   calibrator->SetPhiSymCorFileName(mPhiSymCorFileName);
00211   calibrator->SetOutputCorCoefFileName(mOutputCorCoefFileName);
00212 
00213   calibrator->SetHistoFileName(mHistoFileName); 
00214 
00215   calibrator->SetCaloGeometry(mTheCaloGeometry,mTheHcalTopology);
00216 
00217  
00218   ifstream inputFileList;  // contains list of input root files
00219 
00220   TString files = mInputFileList;
00221   inputFileList.open(files.Data());
00222 
00223   std::vector<TString> inputFiles;
00224   while (!inputFileList.eof()) {
00225     TString fileName;
00226     inputFileList >> fileName;
00227     if (!fileName.BeginsWith("#") && !fileName.Contains(" ") && fileName!="") 
00228       inputFiles.push_back(fileName);
00229   }
00230   inputFileList.close();
00231 
00232   std::cout << "\nInput files for processing:" << std::endl;
00233   for (std::vector<TString>::iterator it=inputFiles.begin(); it!=inputFiles.end(); ++it) {
00234     std::cout << "file: " <<  it->Data() << std::endl;
00235   }
00236   std::cout << std::endl;
00237 
00238 
00239   TChain* fChain = new TChain("hcalCalibTree");
00240 
00241   for (std::vector<TString>::iterator f_it=inputFiles.begin();f_it!=inputFiles.end(); ++f_it) {
00242     fChain->Add(f_it->Data());
00243   }
00244 
00245 
00246   fChain->Process(calibrator);
00247 
00248   if (fChain) delete fChain;
00249   delete calibrator;
00250 
00251   return;
00252 }
00253 
00254 
00255 //define this as a plug-in
00256 DEFINE_FWK_MODULE(HcalCalibrator);
00257 
00258 
00259