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
 
SerialTaskQueueglobalLuminosityBlocksQueue () final
 
SerialTaskQueueglobalRunsQueue () final
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () 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
 
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::vector< ModuleDescription const * > &modules, 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
 
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)
 
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<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)
 

Detailed Description

Definition at line 27 of file WriteCTPPSPixGainCalibrations.cc.

Constructor & Destructor Documentation

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

Definition at line 63 of file WriteCTPPSPixGainCalibrations.cc.

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

Definition at line 75 of file WriteCTPPSPixGainCalibrations.cc.

76 {
77 
78  // do anything here that needs to be done at desctruction time
79  // (e.g. close files, deallocate resources etc.)
80 
81 }

Member Function Documentation

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

Definition at line 89 of file WriteCTPPSPixGainCalibrations.cc.

90 {
91  // using namespace edm;
92 
93 }
void WriteCTPPSPixGainCalibrations::beginJob ( void  )
overrideprivatevirtual

Reimplemented from edm::one::EDAnalyzerBase.

Definition at line 98 of file WriteCTPPSPixGainCalibrations.cc.

99 {
100 }
void WriteCTPPSPixGainCalibrations::endJob ( void  )
overrideprivatevirtual
void WriteCTPPSPixGainCalibrations::fillDB ( )
private

Definition at line 186 of file WriteCTPPSPixGainCalibrations.cc.

References cond::service::PoolDBOutputService::currentTime(), detidROCsPresent, getGainsPedsFromHistos(), mps_fire::i, edm::Service< T >::isAvailable(), gen::k, m_record, genParticles_cff::map, CTPPSPixelGainCalibration::putData(), setDummyFullPlane(), CTPPSPixelGainCalibrations::setGainCalibration(), and cond::service::PoolDBOutputService::writeOne().

Referenced by endJob().

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

Definition at line 113 of file WriteCTPPSPixGainCalibrations.cc.

References edm::ConfigurationDescriptions::addDefault(), and edm::ParameterSetDescription::setUnknown().

113  {
114  //The following says we do not know what parameters are allowed so do no validation
115  // Please change this to state exactly what you do use, even if it is no parameters
117  desc.setUnknown();
118  descriptions.addDefault(desc);
119 }
void addDefault(ParameterSetDescription const &psetDescription)
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 252 of file WriteCTPPSPixGainCalibrations.cc.

References DEFINE_FWK_MODULE, detidHistoNameMap, gainhigh, m_inputRootFile, m_usedummy, hgcalPlots::ncols, npfitmin, AlCaHLTBitMon_QueryRunRegistry::string, and CTPPSPixelIndices::transformToModule().

Referenced by fillDB().

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

Definition at line 123 of file WriteCTPPSPixGainCalibrations.cc.

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

Referenced by endJob().

124 {
125  // std::cout <<"Parsing file " <<m_inputHistosFileName << std::endl;
126  m_inputRootFile = new TFile(m_inputHistosFileName.c_str());
127  m_inputRootFile->cd();
128 
129 
130  int sector[2] = {45,56}; // arm 0 is sector 45 and arm 1 is sector 56
131  int nsec = 2;
132  int station[2]={0,2}; // for each arm
133  int nst = 2 ;
134  //int pot[6]={3}; // index of the pot within the 6 pot configuration (vertical top or bottom and horizontal)
135  int npt = 6;
136 
137  for(int i=0 ; i<nsec ; i++)
138  for(int st=0 ; st < nst ; st ++)
139  for(int pot = 0 ; pot < npt ; pot++){
140  int arm =i;
141 
142  //Check which pots present
143  char temppathrp[100];
144  sprintf(temppathrp,"CTPPS/CTPPS_SEC%d/CTPPS_SEC%d_RP%d%d%d",sector[i],sector[i],arm,station[st],pot);
145  if(!m_inputRootFile->Get(temppathrp))continue;
146 
147  for(int plane=0 ; plane<6 ; plane++){
148 
149  //Check which planes present
150  char temppathplane[100];
151  sprintf(temppathplane,"CTPPS/CTPPS_SEC%d/CTPPS_SEC%d_RP%d%d%d/CTPPS_SEC%d_RP%d%d%d_PLN%d",sector[i],sector[i],arm,station[st],pot,sector[i],arm,station[st],pot,plane);
152 
153  // do not skip the missing plane, instead put dummy values
154  // if(!m_inputRootFile->Get(temppathplane)) continue;
155 
156 
157  CTPPSPixelDetId mytempid(arm,station[st],pot,plane);
158  std::vector<std::string> histnamevec;
159  std::vector<int> listrocs;
160  for(int roc=0 ; roc<6 ; roc++){
161  char temppathhistos[200];
162 
163  sprintf(temppathhistos,"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",
164  sector[i],sector[i],arm,station[st],pot,sector[i],arm,station[st],pot,plane,sector[i],arm,station[st],pot,plane,roc);
165 
166  std::string pathhistos(temppathhistos);
167  std::string pathslope = pathhistos + "_Slope2D";
168  std::string pathintercept= pathhistos + "_Intercept2D";
169  if( m_inputRootFile->Get(pathslope.c_str()) && m_inputRootFile->Get(pathintercept.c_str())){
170  histnamevec.push_back(pathhistos);
171  listrocs.push_back(roc);
172  }
173  }
174  detidHistoNameMap[mytempid.rawId()] = histnamevec;
175  detidROCsPresent[mytempid.rawId()] = listrocs;
176  edm::LogInfo("CTPPSPixGainsCalibrationWriter") << "Raw DetId = "<< mytempid.rawId() <<" Arm = "<< arm << " Sector = "<< sector[arm] << " Station = "<< station[st] << " Pot = "<<pot << " Plane = "<<plane ;
177  }
178 
179  }
180 }
std::map< uint32_t, std::vector< std::string > > detidHistoNameMap
std::map< uint32_t, std::vector< int > > detidROCsPresent
void WriteCTPPSPixGainCalibrations::setDummyFullPlane ( std::vector< float > &  peds,
std::vector< float > &  gains,
int  npixplane 
)
private

Definition at line 242 of file WriteCTPPSPixGainCalibrations.cc.

References mps_fire::i.

Referenced by fillDB().

242  {
243  for (int i = 0 ; i<npixplane ; ++i){
244  peds.push_back(20.);
245  gains.push_back(0.5);
246  }
247 }

Member Data Documentation

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

Definition at line 51 of file WriteCTPPSPixGainCalibrations.cc.

Referenced by getGainsPedsFromHistos(), and getHistos().

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

Definition at line 56 of file WriteCTPPSPixGainCalibrations.cc.

Referenced by fillDB(), and getHistos().

double WriteCTPPSPixGainCalibrations::gainhigh
private

Definition at line 49 of file WriteCTPPSPixGainCalibrations.cc.

Referenced by getGainsPedsFromHistos().

double WriteCTPPSPixGainCalibrations::gainlow
private

Definition at line 49 of file WriteCTPPSPixGainCalibrations.cc.

std::string WriteCTPPSPixGainCalibrations::m_inputHistosFileName
private

Definition at line 46 of file WriteCTPPSPixGainCalibrations.cc.

Referenced by getHistos().

TFile* WriteCTPPSPixGainCalibrations::m_inputRootFile
private

Definition at line 50 of file WriteCTPPSPixGainCalibrations.cc.

Referenced by getGainsPedsFromHistos(), and getHistos().

std::string WriteCTPPSPixGainCalibrations::m_record
private

Definition at line 45 of file WriteCTPPSPixGainCalibrations.cc.

Referenced by fillDB().

bool WriteCTPPSPixGainCalibrations::m_usedummy
private

Definition at line 47 of file WriteCTPPSPixGainCalibrations.cc.

Referenced by getGainsPedsFromHistos().

int WriteCTPPSPixGainCalibrations::npfitmin
private

Definition at line 48 of file WriteCTPPSPixGainCalibrations.cc.

Referenced by getGainsPedsFromHistos().