CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/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.6 2010/11/04 14:09:07 muzaffar 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 }
00126 
00127 // ------------ method called once each job just before starting event loop  ------------
00128 
00129 void
00130 HcalCalibrator::beginJob() {
00131 
00132   //  ESHandle<CaloGeometry> theGeometry;
00133   //  ESHandle<CaloSubdetectorGeometry> theEndcapGeometry_handle, theBarrelGeometry_handle;
00134   //  evtSetup.get<CaloGeometryRecord>().get( theGeometry );
00135 
00136 
00137   // edm::ESHandle<CaloGeometry> pG;
00138   // evtSetup.get<CaloGeometryRecord>().get(pG);     
00139   // mTheCaloGeometry = pG.product();
00140 
00141 }
00142 
00143 // ------------ method called once each job just after ending the event loop  ------------
00144 
00145 void
00146 HcalCalibrator::endJob() {
00147  
00148 
00149   if (mCalibType!="DI_JET" && mCalibType!="ISO_TRACK") {
00150     cout << "\n\nUnknown calibration type " << mCalibType << endl;
00151     cout << "Please select ISO_TRACK or DI_JET in the python file." << endl;
00152     return;
00153   }
00154 
00155   if (mCalibMethod != "L3" && mCalibMethod != "MATRIX_INV_OF_ETA_AVE" && mCalibMethod != "L3_AND_MTRX_INV") {
00156     cout << "\n\nUnknown calibration method " << mCalibMethod << endl;
00157     cout << "Supported methods for IsoTrack calibration are: L3, MATRIX_INV_OF_ETA_AVE, L3_AND_MTRX_INV" << endl;
00158     cout << "For DiJets the supported method is L3" << endl;
00159     return;
00160   }
00161 
00162   if (mCalibType=="DI_JET" && mCalibMethod!="L3") {
00163     cout << "\n\nDiJet calibration can use only the L3 method. Please change the python file." << endl;
00164     return;
00165   }
00166 
00167   if (mCalibAbsIEtaMin<1 || mCalibAbsIEtaMax>41 || mCalibAbsIEtaMin>mCalibAbsIEtaMax) {
00168     cout << "\n\nInvalid ABS(iEta) calibration range. Check calibAbsIEtaMin and calibAbsIEtaMax in the python file." << endl;
00169     return;
00170   }
00171 
00172 
00173 
00174   hcalCalib* calibrator = new hcalCalib();
00175 
00176   // set the parameters controlling the calibratoration
00177 
00178   calibrator->SetCalibType(mCalibType); 
00179   calibrator->SetCalibMethod(mCalibMethod);
00180   calibrator->SetMinTargetE(mMinTargetE);
00181   calibrator->SetMaxTargetE(mMaxTargetE);
00182   calibrator->SetMaxEtThirdJet(mMaxEtThirdJet);
00183   calibrator->SetMinDPhiDiJets(mMinDPhiDiJets);
00184   calibrator->SetSumDepthsFlag(mSumDepths);
00185   calibrator->SetSumSmallDepthsFlag(mSumSmallDepths);
00186   calibrator->SetCombinePhiFlag(mCombinePhi);
00187   calibrator->SetMinCellE(mMinCellE);
00188   calibrator->SetMinEOverP(mMinEOverP);
00189   calibrator->SetMaxEOverP(mMaxEOverP);
00190   calibrator->SetMaxTrkEmE(mMaxTrkEmE);
00191   calibrator->SetHbClusterSize(mHbClusterSize);
00192   calibrator->SetHeClusterSize(mHeClusterSize);
00193 
00194   calibrator->SetUseConeClustering(mUseConeClustering);
00195   calibrator->SetConeMaxDist(mMaxConeDist); 
00196 
00197   calibrator->SetCalibAbsIEtaMax(mCalibAbsIEtaMax);
00198   calibrator->SetCalibAbsIEtaMin(mCalibAbsIEtaMin);
00199   calibrator->SetMaxProbeJetEmFrac(mMaxProbeJetEmFrac);
00200   calibrator->SetMaxTagJetEmFrac(mMaxTagJetEmFrac);
00201   calibrator->SetMaxTagJetAbsEta(mMaxTagJetAbsEta);
00202 
00203   calibrator->SetMinTagJetEt(mMinTagJetEt);
00204 
00205   calibrator->SetMinProbeJetAbsEta(mMinProbeJetAbsEta);
00206   calibrator->SetApplyPhiSymCorFlag(mApplyPhiSymCorFlag);
00207   calibrator->SetPhiSymCorFileName(mPhiSymCorFileName);
00208   calibrator->SetOutputCorCoefFileName(mOutputCorCoefFileName);
00209 
00210   calibrator->SetHistoFileName(mHistoFileName); 
00211 
00212   calibrator->SetCaloGeometry(mTheCaloGeometry);
00213 
00214  
00215   ifstream inputFileList;  // contains list of input root files
00216 
00217   TString files = mInputFileList;
00218   inputFileList.open(files.Data());
00219 
00220   std::vector<TString> inputFiles;
00221   while (!inputFileList.eof()) {
00222     TString fileName;
00223     inputFileList >> fileName;
00224     if (!fileName.BeginsWith("#") && !fileName.Contains(" ") && fileName!="") 
00225       inputFiles.push_back(fileName);
00226   }
00227   inputFileList.close();
00228 
00229   std::cout << "\nInput files for processing:" << std::endl;
00230   for (std::vector<TString>::iterator it=inputFiles.begin(); it!=inputFiles.end(); ++it) {
00231     std::cout << "file: " <<  it->Data() << std::endl;
00232   }
00233   std::cout << std::endl;
00234 
00235 
00236   TChain* fChain = new TChain("hcalCalibTree");
00237 
00238   for (std::vector<TString>::iterator f_it=inputFiles.begin();f_it!=inputFiles.end(); ++f_it) {
00239     fChain->Add(f_it->Data());
00240   }
00241 
00242 
00243   fChain->Process(calibrator);
00244 
00245   if (fChain) delete fChain;
00246   delete calibrator;
00247 
00248   return;
00249 }
00250 
00251 
00252 //define this as a plug-in
00253 DEFINE_FWK_MODULE(HcalCalibrator);
00254 
00255 
00256