CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
WriteCTPPSPixGainCalibrations Class Reference
Inheritance diagram for WriteCTPPSPixGainCalibrations:
edm::one::EDAnalyzer<> edm::one::EDAnalyzerBase edm::EDConsumerBase

Public Member Functions

 WriteCTPPSPixGainCalibrations (const edm::ParameterSet &)
 
 ~WriteCTPPSPixGainCalibrations () override
 
- Public Member Functions inherited from edm::one::EDAnalyzer<>
 EDAnalyzer ()=default
 
 EDAnalyzer (const EDAnalyzer &)=delete
 
SerialTaskQueueglobalLuminosityBlocksQueue () final
 
SerialTaskQueueglobalRunsQueue () final
 
const EDAnalyzeroperator= (const EDAnalyzer &)=delete
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
bool wantsInputProcessBlocks () const final
 
bool wantsProcessBlocks () const final
 
- Public Member Functions inherited from edm::one::EDAnalyzerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzerBase ()
 
ModuleDescription const & moduleDescription () const
 
bool wantsStreamLuminosityBlocks () const
 
bool wantsStreamRuns () const
 
 ~EDAnalyzerBase () override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
std::vector< ESProxyIndex > const & esGetTokenIndicesVector (edm::Transition iTrans) const
 
std::vector< ESRecordIndex > const & esGetTokenRecordIndicesVector (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::array< std::vector< ModuleDescription const *> *, NumBranchTypes > &modulesAll, std::vector< ModuleProcessName > &modulesInPreviousProcesses, ProductRegistry const &preg, std::map< std::string, ModuleDescription const *> const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void selectInputProcessBlocks (ProductRegistry const &productRegistry, ProcessBlockHelperBase const &processBlockHelperBase)
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 
- Static Public Member Functions inherited from edm::one::EDAnalyzerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 

Private Member Functions

void analyze (const edm::Event &, const edm::EventSetup &) override
 
void beginJob () override
 
void endJob () override
 
void fillDB ()
 
void getGainsPedsFromHistos (uint32_t detid, int rocId, int index, std::vector< double > &peds, std::vector< double > &gains, std::map< int, int > &myindxmap, int nrocs)
 
void getHistos ()
 
void setDummyFullPlane (std::vector< float > &peds, std::vector< float > &gains, int npixplane)
 

Private Attributes

std::map< uint32_t, std::vector< std::string > > detidHistoNameMap
 
std::map< uint32_t, std::vector< int > > detidROCsPresent
 
double gainhigh
 
double gainlow
 
std::string m_inputHistosFileName
 
TFile * m_inputRootFile
 
std::string m_record
 
bool m_usedummy
 
int npfitmin
 

Additional Inherited Members

- Public Types inherited from edm::one::EDAnalyzerBase
typedef EDAnalyzerBase ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< Bconsumes (edm::InputTag tag) noexcept
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<Transition Tr = Transition::Event>
constexpr auto esConsumes ()
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag)
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
void resetItemsToGetFrom (BranchType iType)
 

Detailed Description

Definition at line 26 of file WriteCTPPSPixGainCalibrations.cc.

Constructor & Destructor Documentation

◆ WriteCTPPSPixGainCalibrations()

WriteCTPPSPixGainCalibrations::WriteCTPPSPixGainCalibrations ( const edm::ParameterSet iConfig)
explicit

Definition at line 65 of file WriteCTPPSPixGainCalibrations.cc.

66  : m_record(iConfig.getUntrackedParameter<std::string>("record", "CTPPSPixelGainCalibrationsRcd")),
67  m_inputHistosFileName(iConfig.getUntrackedParameter<std::string>("inputrootfile", "inputfile.root")),
68  m_usedummy(iConfig.getUntrackedParameter<bool>("useDummyValues", true)),
69  npfitmin(iConfig.getUntrackedParameter<int>("minimumNpfit", 3)),
70  gainlow(iConfig.getUntrackedParameter<double>("gainLowLimit", 0.0)),
71  gainhigh(iConfig.getUntrackedParameter<double>("gainHighLimit", 100.0)) {}
T getUntrackedParameter(std::string const &, T const &) const

◆ ~WriteCTPPSPixGainCalibrations()

WriteCTPPSPixGainCalibrations::~WriteCTPPSPixGainCalibrations ( )
override

Definition at line 73 of file WriteCTPPSPixGainCalibrations.cc.

73  {
74  // do anything here that needs to be done at desctruction time
75  // (e.g. close files, deallocate resources etc.)
76 }

Member Function Documentation

◆ analyze()

void WriteCTPPSPixGainCalibrations::analyze ( const edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivatevirtual

Implements edm::one::EDAnalyzerBase.

Definition at line 83 of file WriteCTPPSPixGainCalibrations.cc.

83  {
84  // using namespace edm;
85 }

◆ beginJob()

void WriteCTPPSPixGainCalibrations::beginJob ( )
overrideprivatevirtual

Reimplemented from edm::one::EDAnalyzerBase.

Definition at line 88 of file WriteCTPPSPixGainCalibrations.cc.

88 {}

◆ endJob()

void WriteCTPPSPixGainCalibrations::endJob ( void  )
overrideprivatevirtual

◆ fillDB()

void WriteCTPPSPixGainCalibrations::fillDB ( )
private

Definition at line 190 of file WriteCTPPSPixGainCalibrations.cc.

References cond::service::PoolDBOutputService::currentTime(), detidROCsPresent, getGainsPedsFromHistos(), mps_fire::i, edm::Service< T >::isAvailable(), dqmdumpme::k, m_record, genParticles_cff::map, DeadROCCounter::nrocs, CTPPSPixelGainCalibration::putData(), PixelMapPlotter::rocs, setDummyFullPlane(), CTPPSPixelGainCalibrations::setGainCalibration(), and cond::service::PoolDBOutputService::writeOneIOV().

Referenced by endJob().

190  {
191  CTPPSPixelGainCalibrations gainCalibsTest;
192  CTPPSPixelGainCalibrations gainCalibsTest1;
193 
194  // std::cout<<"Here! "<<std::endl;
195 
196  for (std::map<uint32_t, std::vector<int> >::iterator it = detidROCsPresent.begin(); it != detidROCsPresent.end();
197  ++it) {
198  uint32_t tempdetid = it->first;
199  std::vector<int> rocs = it->second;
200  unsigned int nrocs = rocs.size();
201  std::map<int, int> mapIPixIndx;
202 
203  std::vector<double> gainsFromHistos;
204  std::vector<double> pedsFromHistos;
205 
206  CTPPSPixelGainCalibration tempPGCalib;
207 
208  for (unsigned int i = 0; i < nrocs; i++) {
209  getGainsPedsFromHistos(tempdetid, i, rocs[i], pedsFromHistos, gainsFromHistos, mapIPixIndx, nrocs);
210  }
211 
212  std::vector<float> orderedGains;
213  std::vector<float> orderedPeds;
214  for (unsigned int k = 0; k < nrocs * 52 * 80; k++) {
215  int indx = mapIPixIndx[k];
216  float tmpped = pedsFromHistos[indx];
217  float tmpgain = gainsFromHistos[indx];
218  orderedGains.push_back(tmpgain);
219  orderedPeds.push_back(tmpped);
220  tempPGCalib.putData(k, tmpped, tmpgain);
221  }
222 
223  if (nrocs == 0) {
224  edm::LogWarning("CTPPSPixGainsCalibrationWriter") << " plane with detID =" << tempdetid << " is empty";
225  setDummyFullPlane(orderedPeds, orderedGains, 6 * 52 * 80);
226  }
227 
228  gainCalibsTest.setGainCalibration(tempdetid, orderedPeds, orderedGains);
229  // std::cout << "Here detid = "<<tempdetid <<std::endl;
230  gainCalibsTest1.setGainCalibration(tempdetid, tempPGCalib);
231  // std::cout << "Here again"<<std::endl;
232  }
233  // std::cout<<" Here 3!"<<std::endl;
235  if (!mydbservice.isAvailable()) {
236  edm::LogError("CTPPSPixGainsCalibrationWriter") << "Db Service Unavailable";
237  return;
238  }
239  mydbservice->writeOneIOV(gainCalibsTest, mydbservice->currentTime(), m_record);
240 }
Log< level::Error, false > LogError
void setGainCalibration(const uint32_t &DetId, const CTPPSPixelGainCalibration &PixGains)
Hash writeOneIOV(const T &payload, Time_t time, const std::string &recordName)
void getGainsPedsFromHistos(uint32_t detid, int rocId, int index, std::vector< double > &peds, std::vector< double > &gains, std::map< int, int > &myindxmap, int nrocs)
void setDummyFullPlane(std::vector< float > &peds, std::vector< float > &gains, int npixplane)
bool isAvailable() const
Definition: Service.h:40
Log< level::Warning, false > LogWarning
void putData(uint32_t ipix, float ped, float gain)
std::map< uint32_t, std::vector< int > > detidROCsPresent

◆ fillDescriptions()

void WriteCTPPSPixGainCalibrations::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 97 of file WriteCTPPSPixGainCalibrations.cc.

References edm::ConfigurationDescriptions::addDefault(), and submitPVResolutionJobs::desc.

97  {
98  //The following says we do not know what parameters are allowed so do no validation
99  // Please change this to state exactly what you do use, even if it is no parameters
101  desc.setUnknown();
102  descriptions.addDefault(desc);
103 }
void addDefault(ParameterSetDescription const &psetDescription)

◆ getGainsPedsFromHistos()

void WriteCTPPSPixGainCalibrations::getGainsPedsFromHistos ( uint32_t  detid,
int  rocId,
int  index,
std::vector< double > &  peds,
std::vector< double > &  gains,
std::map< int, int > &  myindxmap,
int  nrocs 
)
private

Definition at line 251 of file WriteCTPPSPixGainCalibrations.cc.

References detidHistoNameMap, gainhigh, ecalph2::gains, m_inputRootFile, m_usedummy, hgcalPlots::ncols, npfitmin, DeadROCCounter::nrocs, AlCaHLTBitMon_QueryRunRegistry::string, and CTPPSPixelIndices::transformToModule().

Referenced by fillDB().

257  {
258  CTPPSPixelIndices modulepixels(52 * nrocs / 2, 160);
259 
260  std::string tmpslopename = detidHistoNameMap[detid][ROCindex] + "_Slope2D";
261  std::string tmpitcpname = detidHistoNameMap[detid][ROCindex] + "_Intercept2D";
262  std::string tmpchi2name = detidHistoNameMap[detid][ROCindex] + "_Chisquare2D";
263  std::string tmpnpfitsname = detidHistoNameMap[detid][ROCindex] + "_Npfits2D";
264  TH2D* tempslope = (TH2D*)m_inputRootFile->Get(tmpslopename.c_str());
265  TH2D* tempintrcpt = (TH2D*)m_inputRootFile->Get(tmpitcpname.c_str());
266  // TH2D * tempchi2 = (TH2D*) m_inputRootFile->Get(tmpchi2name.c_str());
267  TH2D* tempnpfit = (TH2D*)m_inputRootFile->Get(tmpnpfitsname.c_str());
268  int ncols = tempslope->GetNbinsX();
269  int nrows = tempslope->GetNbinsY();
270  if (nrows != 80 || ncols != 52)
271  edm::LogWarning("CTPPSPixGainsCalibrationWriter")
272  << "Something wrong ncols = " << ncols << " and nrows = " << nrows;
273 
274  for (int jrow = 0; jrow < nrows;
275  ++jrow) // when scanning through the 2d histo make sure to avoid underflow bin i or j ==0
276  for (int icol = 0; icol < ncols; ++icol) {
277  double tmpslp = tempslope->GetBinContent(icol + 1, jrow + 1);
278  double tmpgain = (tmpslp == 0.0) ? 0.0 : 1.0 / tmpslp;
279  double tmpped = tempintrcpt->GetBinContent(icol + 1, jrow + 1);
280  // check for noisy/badly calibrated pixels
281  int tmpnpfit = tempnpfit->GetBinContent(icol + 1, jrow + 1);
282  //double tmpchi2 = tempchi2 -> GetBinContent(icol+1,jrow+1);
283  if (tmpnpfit < npfitmin || tmpgain < gainlow || tmpgain > gainhigh) {
284  // std::cout << " *** Badly calibrated pixel, NPoints = "<<tmpnpfit << " setting dummy values gain = 0.5 and ped =20.0 ***" <<std::endl;
285  // std::cout << " **** bad Pixel column icol = "<<icol <<" and jrow = "<<jrow <<" Name= "<< tmpslopename <<std::endl;
286  if (m_usedummy) {
287  tmpgain = 1.0 / 2.0;
288  tmpped = 20.0;
289  }
290  // else leave as is and set noisy in mask?
291  }
292 
293  gains.push_back(tmpgain);
294  peds.push_back(tmpped);
295  int modCol = -1;
296  int modRow = -1;
297  modulepixels.transformToModule(icol, jrow, rocId, modCol, modRow);
298  int indx = gains.size() - 1;
299  int pixIndx = modCol + modRow * (52 * nrocs / 2);
300  mymap[pixIndx] = indx;
301  }
302 }
std::map< uint32_t, std::vector< std::string > > detidHistoNameMap
constexpr float gains[NGAINS]
Definition: EcalConstants.h:11
Log< level::Warning, false > LogWarning

◆ getHistos()

void WriteCTPPSPixGainCalibrations::getHistos ( )
private

Definition at line 105 of file WriteCTPPSPixGainCalibrations.cc.

References protons_cff::arm, detidHistoNameMap, detidROCsPresent, mps_fire::i, m_inputHistosFileName, m_inputRootFile, DetId::rawId(), PixelMapPlotter::roc, relativeConstraints::station, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by endJob().

105  {
106  // std::cout <<"Parsing file " <<m_inputHistosFileName << std::endl;
107  m_inputRootFile = new TFile(m_inputHistosFileName.c_str());
108  m_inputRootFile->cd();
109 
110  int sector[2] = {45, 56}; // arm 0 is sector 45 and arm 1 is sector 56
111  int nsec = 2;
112  int station[2] = {0, 2}; // for each arm
113  int nst = 2;
114  //int pot[6]={3}; // index of the pot within the 6 pot configuration (vertical top or bottom and horizontal)
115  int npt = 6;
116 
117  for (int i = 0; i < nsec; i++)
118  for (int st = 0; st < nst; st++)
119  for (int pot = 0; pot < npt; pot++) {
120  int arm = i;
121 
122  //Check which pots present
123  char temppathrp[100];
124  sprintf(temppathrp, "CTPPS/CTPPS_SEC%d/CTPPS_SEC%d_RP%d%d%d", sector[i], sector[i], arm, station[st], pot);
125  if (!m_inputRootFile->Get(temppathrp))
126  continue;
127 
128  for (int plane = 0; plane < 6; plane++) {
129  //Check which planes present
130  char temppathplane[100];
131  sprintf(temppathplane,
132  "CTPPS/CTPPS_SEC%d/CTPPS_SEC%d_RP%d%d%d/CTPPS_SEC%d_RP%d%d%d_PLN%d",
133  sector[i],
134  sector[i],
135  arm,
136  station[st],
137  pot,
138  sector[i],
139  arm,
140  station[st],
141  pot,
142  plane);
143 
144  // do not skip the missing plane, instead put dummy values
145  // if(!m_inputRootFile->Get(temppathplane)) continue;
146 
147  CTPPSPixelDetId mytempid(arm, station[st], pot, plane);
148  std::vector<std::string> histnamevec;
149  std::vector<int> listrocs;
150  for (int roc = 0; roc < 6; roc++) {
151  char temppathhistos[200];
152 
153  sprintf(
154  temppathhistos,
155  "CTPPS/CTPPS_SEC%d/CTPPS_SEC%d_RP%d%d%d/CTPPS_SEC%d_RP%d%d%d_PLN%d/CTPPS_SEC%d_RP%d%d%d_PLN%d_ROC%d",
156  sector[i],
157  sector[i],
158  arm,
159  station[st],
160  pot,
161  sector[i],
162  arm,
163  station[st],
164  pot,
165  plane,
166  sector[i],
167  arm,
168  station[st],
169  pot,
170  plane,
171  roc);
172 
173  std::string pathhistos(temppathhistos);
174  std::string pathslope = pathhistos + "_Slope2D";
175  std::string pathintercept = pathhistos + "_Intercept2D";
176  if (m_inputRootFile->Get(pathslope.c_str()) && m_inputRootFile->Get(pathintercept.c_str())) {
177  histnamevec.push_back(pathhistos);
178  listrocs.push_back(roc);
179  }
180  }
181  detidHistoNameMap[mytempid.rawId()] = histnamevec;
182  detidROCsPresent[mytempid.rawId()] = listrocs;
183  edm::LogInfo("CTPPSPixGainsCalibrationWriter")
184  << "Raw DetId = " << mytempid.rawId() << " Arm = " << arm << " Sector = " << sector[arm]
185  << " Station = " << station[st] << " Pot = " << pot << " Plane = " << plane;
186  }
187  }
188 }
std::map< uint32_t, std::vector< std::string > > detidHistoNameMap
Log< level::Info, false > LogInfo
std::map< uint32_t, std::vector< int > > detidROCsPresent

◆ setDummyFullPlane()

void WriteCTPPSPixGainCalibrations::setDummyFullPlane ( std::vector< float > &  peds,
std::vector< float > &  gains,
int  npixplane 
)
private

Definition at line 242 of file WriteCTPPSPixGainCalibrations.cc.

References ecalph2::gains, and mps_fire::i.

Referenced by fillDB().

244  {
245  for (int i = 0; i < npixplane; ++i) {
246  peds.push_back(20.);
247  gains.push_back(0.5);
248  }
249 }
constexpr float gains[NGAINS]
Definition: EcalConstants.h:11

Member Data Documentation

◆ detidHistoNameMap

std::map<uint32_t, std::vector<std::string> > WriteCTPPSPixGainCalibrations::detidHistoNameMap
private

Definition at line 54 of file WriteCTPPSPixGainCalibrations.cc.

Referenced by getGainsPedsFromHistos(), and getHistos().

◆ detidROCsPresent

std::map<uint32_t, std::vector<int> > WriteCTPPSPixGainCalibrations::detidROCsPresent
private

Definition at line 59 of file WriteCTPPSPixGainCalibrations.cc.

Referenced by fillDB(), and getHistos().

◆ gainhigh

double WriteCTPPSPixGainCalibrations::gainhigh
private

Definition at line 52 of file WriteCTPPSPixGainCalibrations.cc.

Referenced by getGainsPedsFromHistos().

◆ gainlow

double WriteCTPPSPixGainCalibrations::gainlow
private

Definition at line 52 of file WriteCTPPSPixGainCalibrations.cc.

◆ m_inputHistosFileName

std::string WriteCTPPSPixGainCalibrations::m_inputHistosFileName
private

Definition at line 49 of file WriteCTPPSPixGainCalibrations.cc.

Referenced by getHistos().

◆ m_inputRootFile

TFile* WriteCTPPSPixGainCalibrations::m_inputRootFile
private

Definition at line 53 of file WriteCTPPSPixGainCalibrations.cc.

Referenced by getGainsPedsFromHistos(), and getHistos().

◆ m_record

std::string WriteCTPPSPixGainCalibrations::m_record
private

Definition at line 48 of file WriteCTPPSPixGainCalibrations.cc.

Referenced by fillDB().

◆ m_usedummy

bool WriteCTPPSPixGainCalibrations::m_usedummy
private

Definition at line 50 of file WriteCTPPSPixGainCalibrations.cc.

Referenced by getGainsPedsFromHistos().

◆ npfitmin

int WriteCTPPSPixGainCalibrations::npfitmin
private

Definition at line 51 of file WriteCTPPSPixGainCalibrations.cc.

Referenced by getGainsPedsFromHistos().