CMS 3D CMS Logo

CTPPSPixGainCalibsESAnalyzer.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <map>
12 #include "TH2D.h"
13 #include "TFile.h"
14 
16 public:
18  : m_outfilename(p.getUntrackedParameter<std::string>("outputrootfile", "output.root")),
21  }
23  //std::cout<<"CTPPSPixGainCalibsESAnalyzer "<<i<<std::endl;
25  }
27  //std::cout<<"~CTPPSPixGainCalibsESAnalyzer "<<std::endl;
28  }
29  void analyze(const edm::Event& e, const edm::EventSetup& c) override;
30  void setReadablePlaneNames();
31 
32 private:
33  std::map<uint32_t, std::string> detId_readable;
35 
37 };
38 
40  detId_readable[2014838784] = "Arm_0_Sec_45_St_0_Pot_3_Plane_0";
41  detId_readable[2014904320] = "Arm_0_Sec_45_St_0_Pot_3_Plane_1";
42  detId_readable[2014969856] = "Arm_0_Sec_45_St_0_Pot_3_Plane_2";
43  detId_readable[2015035392] = "Arm_0_Sec_45_St_0_Pot_3_Plane_3";
44  detId_readable[2015100928] = "Arm_0_Sec_45_St_0_Pot_3_Plane_4";
45  detId_readable[2015166464] = "Arm_0_Sec_45_St_0_Pot_3_Plane_5";
46  detId_readable[2023227392] = "Arm_0_Sec_45_St_2_Pot_3_Plane_0";
47  detId_readable[2023292928] = "Arm_0_Sec_45_St_2_Pot_3_Plane_1";
48  detId_readable[2023358464] = "Arm_0_Sec_45_St_2_Pot_3_Plane_2";
49  detId_readable[2023424000] = "Arm_0_Sec_45_St_2_Pot_3_Plane_3";
50  detId_readable[2023489536] = "Arm_0_Sec_45_St_2_Pot_3_Plane_4";
51  detId_readable[2023555072] = "Arm_0_Sec_45_St_2_Pot_3_Plane_5";
52  detId_readable[2031616000] = "Arm_1_Sec_56_St_0_Pot_3_Plane_0";
53  detId_readable[2031681536] = "Arm_1_Sec_56_St_0_Pot_3_Plane_1";
54  detId_readable[2031747072] = "Arm_1_Sec_56_St_0_Pot_3_Plane_2";
55  detId_readable[2031812608] = "Arm_1_Sec_56_St_0_Pot_3_Plane_3";
56  detId_readable[2031878144] = "Arm_1_Sec_56_St_0_Pot_3_Plane_4";
57  detId_readable[2031943680] = "Arm_1_Sec_56_St_0_Pot_3_Plane_5";
58  detId_readable[2040004608] = "Arm_1_Sec_56_St_2_Pot_3_Plane_0";
59  detId_readable[2040070144] = "Arm_1_Sec_56_St_2_Pot_3_Plane_1";
60  detId_readable[2040135680] = "Arm_1_Sec_56_St_2_Pot_3_Plane_2";
61  detId_readable[2040201216] = "Arm_1_Sec_56_St_2_Pot_3_Plane_3";
62  detId_readable[2040266752] = "Arm_1_Sec_56_St_2_Pot_3_Plane_4";
63  detId_readable[2040332288] = "Arm_1_Sec_56_St_2_Pot_3_Plane_5";
64 }
65 
67  edm::LogPrint("CTPPSPixGainCalibsReader") << "###CTPPSPixGainCalibsESAnalyzer::analyze";
68  edm::LogPrint("CTPPSPixGainCalibsReader") << " I AM IN RUN NUMBER " << e.id().run();
69  edm::LogPrint("CTPPSPixGainCalibsReader") << " ---EVENT NUMBER " << e.id().event();
71  edm::eventsetup::EventSetupRecordKey::TypeTag::findType("CTPPSPixelGainCalibrationsRcd"));
73  //record not found
74  edm::LogPrint("CTPPSPixGainCalibsReader") << "Record \"CTPPSPixelGainCalibrationsRcd"
75  << "\" does not exist ";
76  }
77  //this part gets the handle of the event source and the record (i.e. the Database)
79  edm::LogPrint("CTPPSPixGainCalibsReader") << "got eshandle";
80  edm::LogPrint("CTPPSPixGainCalibsReader") << "got context";
81  const CTPPSPixelGainCalibrations* pPixelGainCalibrations = calhandle.product();
82  edm::LogPrint("CTPPSPixGainCalibsReader") << "got CTPPSPixelGainCalibrations* ";
83  edm::LogPrint("CTPPSPixGainCalibsReader") << "print pointer address : ";
84  edm::LogPrint("CTPPSPixGainCalibsReader") << pPixelGainCalibrations;
85 
86  TFile myfile(m_outfilename.c_str(), "RECREATE");
87  myfile.cd();
88 
89  // the pPixelGainCalibrations object contains the map of detIds to pixel gains and pedestals for current run
90  // we get the map just to loop over the contents, but from here on it should be as the code (reconstruction etc) needs.
91  // Probably best to check that the key (detid) is in the list before calling the data
92 
93  edm::LogPrint("CTPPSPixGainCalibsReader") << "Size " << pPixelGainCalibrations->size();
94  const CTPPSPixelGainCalibrations::CalibMap& mymap = pPixelGainCalibrations->getCalibMap(); //just to get the keys?
95 
96  for (CTPPSPixelGainCalibrations::CalibMap::const_iterator it = mymap.begin(); it != mymap.end(); ++it) {
97  uint32_t detId = it->first;
98 
99  edm::LogPrint("CTPPSPixGainCalibsReader")
100  << "Address of detId = " << (&detId) << " and of it = " << (&it) << " and of it->first = " << (&(it->first));
101 
102  edm::LogPrint("CTPPSPixGainCalibsReader") << "Content of pPixelGainCalibrations for key: detId= " << detId;
103  CTPPSPixelGainCalibration mycalibs0 = pPixelGainCalibrations->getGainCalibration(detId);
104  const CTPPSPixelGainCalibration& mycalibs = it->second;
105 
106  edm::LogPrint("CTPPSPixGainCalibsReader")
107  << "Address of mycalibs0 = " << (&mycalibs0) << " and of mycalibs = " << (&mycalibs) << " and of it->second "
108  << (&(it->second));
109 
110  std::string namep("pedsFromDB_" + detId_readable[detId]);
111  std::string nameg("gainsFromDB_" + detId_readable[detId]);
112  std::string tlp("Pedestals for " + detId_readable[detId] + "; column; row");
113  std::string tlg("Gains for " + detId_readable[detId] + "; column; row");
114  TH2D mypeds(namep.c_str(), tlp.c_str(), 156, 0., 156., 160, 0., 160.);
115  TH2D mygains(nameg.c_str(), tlg.c_str(), 156, 0., 156., 160, 0., 160.);
116 
117  int ncols = mycalibs.getNCols();
118  int npix = mycalibs.getIEnd();
119  int nrows = mycalibs.getNRows(); //should be == 160
120  edm::LogPrint("CTPPSPixGainCalibsReader") << "Here ncols = " << ncols << " nrows =" << nrows << " npix=" << npix;
121  for (int jrow = 0; jrow < nrows; ++jrow)
122  for (int icol = 0; icol < ncols; ++icol) {
123  if (mycalibs.isDead(icol + jrow * ncols)) {
124  edm::LogPrint("CTPPSPixGainCalibsReader") << "Dead Pixel icol =" << icol << " jrow =" << jrow;
125  continue;
126  }
127  if (mycalibs.isNoisy(icol + jrow * ncols)) {
128  edm::LogPrint("CTPPSPixGainCalibsReader") << "Noisy Pixel icol =" << icol << " jrow =" << jrow;
129  continue;
130  }
131  mygains.Fill(icol, jrow, mycalibs.getGain(icol, jrow));
132  mypeds.Fill(icol, jrow, mycalibs.getPed(icol, jrow));
133  }
134 
135  mypeds.Write();
136  mygains.Write();
137  }
138  myfile.Write();
139  myfile.Close();
140 }
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
edm::eventsetup::heterocontainer::HCTypeTag::findType
static HCTypeTag findType(char const *iTypeName)
find a type based on the types name, if not found will return default HCTypeTag
Definition: HCTypeTag.cc:121
hgcalPlots.ncols
ncols
Definition: hgcalPlots.py:104
EDAnalyzer.h
mps_fire.i
i
Definition: mps_fire.py:428
CTPPSPixelGainCalibration::getNCols
uint32_t getNCols() const
Definition: CTPPSPixelGainCalibration.h:77
CTPPSPixGainCalibsESAnalyzer::setReadablePlaneNames
void setReadablePlaneNames()
Definition: CTPPSPixGainCalibsESAnalyzer.cc:39
MessageLogger.h
CTPPSPixelGainCalibrations::size
int size() const
Definition: CTPPSPixelGainCalibrations.h:26
ESHandle.h
CTPPSPixGainCalibsESAnalyzer::m_outfilename
std::string m_outfilename
Definition: CTPPSPixGainCalibsESAnalyzer.cc:34
edm::LogPrint
Log< level::Warning, true > LogPrint
Definition: MessageLogger.h:130
edm::one::EDAnalyzer
Definition: EDAnalyzer.h:30
CTPPSPixelGainCalibration::isDead
bool isDead(const uint32_t ipix) const
Definition: CTPPSPixelGainCalibration.h:73
CTPPSPixelGainCalibrations.h
edm::eventsetup::EventSetupRecordKey
Definition: EventSetupRecordKey.h:30
visDQMUpload.context
context
Definition: visDQMUpload.py:37
CTPPSPixelGainCalibration
Definition: CTPPSPixelGainCalibration.h:27
MakerMacros.h
CTPPSPixGainCalibsESAnalyzer::CTPPSPixGainCalibsESAnalyzer
CTPPSPixGainCalibsESAnalyzer(edm::ParameterSet const &p)
Definition: CTPPSPixGainCalibsESAnalyzer.cc:17
CTPPSPixGainCalibsESAnalyzer::~CTPPSPixGainCalibsESAnalyzer
~CTPPSPixGainCalibsESAnalyzer() override
Definition: CTPPSPixGainCalibsESAnalyzer.cc:26
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
CTPPSPixelGainCalibration::getGain
float getGain(const int &col, const int &row) const
Definition: CTPPSPixelGainCalibration.cc:136
edm::ESHandle
Definition: DTSurvey.h:22
edm::eventsetup::EventSetupRecordKey::TypeTag
heterocontainer::HCTypeTag TypeTag
Definition: EventSetupRecordKey.h:32
CTPPSPixGainCalibsESAnalyzer
Definition: CTPPSPixGainCalibsESAnalyzer.cc:15
CTPPSPixelGainCalibration::getNRows
uint32_t getNRows() const
Definition: CTPPSPixelGainCalibration.h:80
CTPPSPixelGainCalibrations::getGainCalibration
const CTPPSPixelGainCalibration & getGainCalibration(const uint32_t &detid) const
Definition: CTPPSPixelGainCalibrations.cc:52
edm::ParameterSet
Definition: ParameterSet.h:47
CTPPSPixGainCalibsESAnalyzer::analyze
void analyze(const edm::Event &e, const edm::EventSetup &c) override
Definition: CTPPSPixGainCalibsESAnalyzer.cc:66
AlCaHLTBitMon_ParallelJobs.p
def p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
Event.h
CTPPSPixelGainCalibration::getPed
float getPed(const int &col, const int &row) const
Definition: CTPPSPixelGainCalibration.cc:122
edm::eventsetup::EventSetupRecordKey::type
const TypeTag & type() const
Definition: EventSetupRecordKey.h:40
CTPPSPixelGainCalibrations
Definition: CTPPSPixelGainCalibrations.h:8
CTPPSPixelGainCalibrationsRcd
Definition: CTPPSPixelGainCalibrationsRcd.h:23
edm::EventSetup
Definition: EventSetup.h:58
CTPPSPixelGainCalibrations::CalibMap
std::map< uint32_t, CTPPSPixelGainCalibration > CalibMap
Definition: CTPPSPixelGainCalibrations.h:10
edm::ESGetToken< CTPPSPixelGainCalibrations, CTPPSPixelGainCalibrationsRcd >
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
CTPPSPixelGainCalibrationsRcd.h
CTPPSPixGainCalibsESAnalyzer::tokenCalibration_
edm::ESGetToken< CTPPSPixelGainCalibrations, CTPPSPixelGainCalibrationsRcd > tokenCalibration_
Definition: CTPPSPixGainCalibsESAnalyzer.cc:36
std
Definition: JetResolutionObject.h:76
CTPPSPixGainCalibsESAnalyzer::detId_readable
std::map< uint32_t, std::string > detId_readable
Definition: CTPPSPixGainCalibsESAnalyzer.cc:33
CTPPSPixelGainCalibrations::getCalibMap
const CalibMap & getCalibMap() const
Definition: CTPPSPixelGainCalibrations.h:22
CTPPSPixGainCalibsESAnalyzer::CTPPSPixGainCalibsESAnalyzer
CTPPSPixGainCalibsESAnalyzer(int i)
Definition: CTPPSPixGainCalibsESAnalyzer.cc:22
EventSetup.h
edm::EDConsumerBase::esConsumes
auto esConsumes()
Definition: EDConsumerBase.h:206
CTPPSPixelGainCalibration::getIEnd
uint32_t getIEnd() const
Definition: CTPPSPixelGainCalibration.h:79
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:56
edm::Event
Definition: Event.h:73
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
CTPPSPixelGainCalibration::isNoisy
bool isNoisy(const uint32_t ipix) const
Definition: CTPPSPixelGainCalibration.h:74