Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:02:43

0001 #include <string>
0002 #include <iostream>
0003 #include <map>
0004 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0005 #include "FWCore/Framework/interface/ESHandle.h"
0006 #include "FWCore/Framework/interface/Event.h"
0007 #include "FWCore/Framework/interface/EventSetup.h"
0008 #include "FWCore/Framework/interface/MakerMacros.h"
0009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0010 #include "CondFormats/PPSObjects/interface/CTPPSPixelGainCalibrations.h"
0011 #include "CondFormats/DataRecord/interface/CTPPSPixelGainCalibrationsRcd.h"
0012 #include "TH2D.h"
0013 #include "TFile.h"
0014 
0015 class CTPPSPixGainCalibsESAnalyzer : public edm::one::EDAnalyzer<> {
0016 public:
0017   explicit CTPPSPixGainCalibsESAnalyzer(edm::ParameterSet const& p)
0018       : m_outfilename(p.getUntrackedParameter<std::string>("outputrootfile", "output.root")),
0019         tokenCalibration_(esConsumes<CTPPSPixelGainCalibrations, CTPPSPixelGainCalibrationsRcd>()) {
0020     setReadablePlaneNames();
0021   }
0022   explicit CTPPSPixGainCalibsESAnalyzer(int i) {
0023     //std::cout<<"CTPPSPixGainCalibsESAnalyzer "<<i<<std::endl;
0024     setReadablePlaneNames();
0025   }
0026   ~CTPPSPixGainCalibsESAnalyzer() override {
0027     //std::cout<<"~CTPPSPixGainCalibsESAnalyzer "<<std::endl;
0028   }
0029   void analyze(const edm::Event& e, const edm::EventSetup& c) override;
0030   void setReadablePlaneNames();
0031 
0032 private:
0033   std::map<uint32_t, std::string> detId_readable;
0034   std::string m_outfilename;
0035 
0036   edm::ESGetToken<CTPPSPixelGainCalibrations, CTPPSPixelGainCalibrationsRcd> tokenCalibration_;
0037 };
0038 
0039 void CTPPSPixGainCalibsESAnalyzer::setReadablePlaneNames() {
0040   detId_readable[2014838784] = "Arm_0_Sec_45_St_0_Pot_3_Plane_0";
0041   detId_readable[2014904320] = "Arm_0_Sec_45_St_0_Pot_3_Plane_1";
0042   detId_readable[2014969856] = "Arm_0_Sec_45_St_0_Pot_3_Plane_2";
0043   detId_readable[2015035392] = "Arm_0_Sec_45_St_0_Pot_3_Plane_3";
0044   detId_readable[2015100928] = "Arm_0_Sec_45_St_0_Pot_3_Plane_4";
0045   detId_readable[2015166464] = "Arm_0_Sec_45_St_0_Pot_3_Plane_5";
0046   detId_readable[2023227392] = "Arm_0_Sec_45_St_2_Pot_3_Plane_0";
0047   detId_readable[2023292928] = "Arm_0_Sec_45_St_2_Pot_3_Plane_1";
0048   detId_readable[2023358464] = "Arm_0_Sec_45_St_2_Pot_3_Plane_2";
0049   detId_readable[2023424000] = "Arm_0_Sec_45_St_2_Pot_3_Plane_3";
0050   detId_readable[2023489536] = "Arm_0_Sec_45_St_2_Pot_3_Plane_4";
0051   detId_readable[2023555072] = "Arm_0_Sec_45_St_2_Pot_3_Plane_5";
0052   detId_readable[2031616000] = "Arm_1_Sec_56_St_0_Pot_3_Plane_0";
0053   detId_readable[2031681536] = "Arm_1_Sec_56_St_0_Pot_3_Plane_1";
0054   detId_readable[2031747072] = "Arm_1_Sec_56_St_0_Pot_3_Plane_2";
0055   detId_readable[2031812608] = "Arm_1_Sec_56_St_0_Pot_3_Plane_3";
0056   detId_readable[2031878144] = "Arm_1_Sec_56_St_0_Pot_3_Plane_4";
0057   detId_readable[2031943680] = "Arm_1_Sec_56_St_0_Pot_3_Plane_5";
0058   detId_readable[2040004608] = "Arm_1_Sec_56_St_2_Pot_3_Plane_0";
0059   detId_readable[2040070144] = "Arm_1_Sec_56_St_2_Pot_3_Plane_1";
0060   detId_readable[2040135680] = "Arm_1_Sec_56_St_2_Pot_3_Plane_2";
0061   detId_readable[2040201216] = "Arm_1_Sec_56_St_2_Pot_3_Plane_3";
0062   detId_readable[2040266752] = "Arm_1_Sec_56_St_2_Pot_3_Plane_4";
0063   detId_readable[2040332288] = "Arm_1_Sec_56_St_2_Pot_3_Plane_5";
0064 }
0065 
0066 void CTPPSPixGainCalibsESAnalyzer::analyze(const edm::Event& e, const edm::EventSetup& context) {
0067   edm::LogPrint("CTPPSPixGainCalibsReader") << "###CTPPSPixGainCalibsESAnalyzer::analyze";
0068   edm::LogPrint("CTPPSPixGainCalibsReader") << " I AM IN RUN NUMBER " << e.id().run();
0069   edm::LogPrint("CTPPSPixGainCalibsReader") << " ---EVENT NUMBER " << e.id().event();
0070   edm::eventsetup::EventSetupRecordKey recordKey(
0071       edm::eventsetup::EventSetupRecordKey::TypeTag::findType("CTPPSPixelGainCalibrationsRcd"));
0072   if (recordKey.type() == edm::eventsetup::EventSetupRecordKey::TypeTag()) {
0073     //record not found
0074     edm::LogPrint("CTPPSPixGainCalibsReader") << "Record \"CTPPSPixelGainCalibrationsRcd"
0075                                               << "\" does not exist ";
0076   }
0077   //this part gets the handle of the event source and the record (i.e. the Database)
0078   edm::ESHandle<CTPPSPixelGainCalibrations> calhandle = context.getHandle(tokenCalibration_);
0079   edm::LogPrint("CTPPSPixGainCalibsReader") << "got eshandle";
0080   edm::LogPrint("CTPPSPixGainCalibsReader") << "got context";
0081   const CTPPSPixelGainCalibrations* pPixelGainCalibrations = calhandle.product();
0082   edm::LogPrint("CTPPSPixGainCalibsReader") << "got CTPPSPixelGainCalibrations* ";
0083   edm::LogPrint("CTPPSPixGainCalibsReader") << "print  pointer address : ";
0084   edm::LogPrint("CTPPSPixGainCalibsReader") << pPixelGainCalibrations;
0085 
0086   TFile myfile(m_outfilename.c_str(), "RECREATE");
0087   myfile.cd();
0088 
0089   // the pPixelGainCalibrations object contains the map of detIds  to pixel gains and pedestals for current run
0090   // we get the map just to loop over the contents, but from here on it should be  as the code (reconstruction etc) needs.
0091   // Probably best to check that the key (detid) is in the list before calling the data
0092 
0093   edm::LogPrint("CTPPSPixGainCalibsReader") << "Size " << pPixelGainCalibrations->size();
0094   const CTPPSPixelGainCalibrations::CalibMap& mymap = pPixelGainCalibrations->getCalibMap();  //just to get the keys?
0095 
0096   for (CTPPSPixelGainCalibrations::CalibMap::const_iterator it = mymap.begin(); it != mymap.end(); ++it) {
0097     uint32_t detId = it->first;
0098 
0099     edm::LogPrint("CTPPSPixGainCalibsReader")
0100         << "Address of  detId = " << (&detId) << " and of it = " << (&it) << " and of it->first = " << (&(it->first));
0101 
0102     edm::LogPrint("CTPPSPixGainCalibsReader") << "Content  of pPixelGainCalibrations for key: detId= " << detId;
0103     CTPPSPixelGainCalibration mycalibs0 = pPixelGainCalibrations->getGainCalibration(detId);
0104     const CTPPSPixelGainCalibration& mycalibs = it->second;
0105 
0106     edm::LogPrint("CTPPSPixGainCalibsReader")
0107         << "Address of  mycalibs0 = " << (&mycalibs0) << " and of mycalibs = " << (&mycalibs) << " and of it->second "
0108         << (&(it->second));
0109 
0110     std::string namep("pedsFromDB_" + detId_readable[detId]);
0111     std::string nameg("gainsFromDB_" + detId_readable[detId]);
0112     std::string tlp("Pedestals for " + detId_readable[detId] + "; column; row");
0113     std::string tlg("Gains for " + detId_readable[detId] + "; column; row");
0114     TH2D mypeds(namep.c_str(), tlp.c_str(), 156, 0., 156., 160, 0., 160.);
0115     TH2D mygains(nameg.c_str(), tlg.c_str(), 156, 0., 156., 160, 0., 160.);
0116 
0117     int ncols = mycalibs.getNCols();
0118     int npix = mycalibs.getIEnd();
0119     int nrows = mycalibs.getNRows();  //should be == 160
0120     edm::LogPrint("CTPPSPixGainCalibsReader") << "Here ncols = " << ncols << " nrows =" << nrows << " npix=" << npix;
0121     for (int jrow = 0; jrow < nrows; ++jrow)
0122       for (int icol = 0; icol < ncols; ++icol) {
0123         if (mycalibs.isDead(icol + jrow * ncols)) {
0124           edm::LogPrint("CTPPSPixGainCalibsReader") << "Dead Pixel icol =" << icol << " jrow =" << jrow;
0125           continue;
0126         }
0127         if (mycalibs.isNoisy(icol + jrow * ncols)) {
0128           edm::LogPrint("CTPPSPixGainCalibsReader") << "Noisy Pixel icol =" << icol << " jrow =" << jrow;
0129           continue;
0130         }
0131         mygains.Fill(icol, jrow, mycalibs.getGain(icol, jrow));
0132         mypeds.Fill(icol, jrow, mycalibs.getPed(icol, jrow));
0133       }
0134 
0135     mypeds.Write();
0136     mygains.Write();
0137   }
0138   myfile.Write();
0139   myfile.Close();
0140 }
0141 DEFINE_FWK_MODULE(CTPPSPixGainCalibsESAnalyzer);