CMS 3D CMS Logo

CalibrationHistosUsingDb.cc
Go to the documentation of this file.
7 #include <iostream>
8 
9 using namespace sistrip;
10 
11 // -----------------------------------------------------------------------------
14 {
15  return path.substr(0,path.find(std::string(sistrip::root_) + "/")+sizeof(sistrip::root_) );
16 }
17 
18 // -----------------------------------------------------------------------------
21  DQMStore* bei,
22  SiStripConfigDb* const db,
23  const sistrip::RunType& task )
24  : CommissioningHistograms( pset.getParameter<edm::ParameterSet>("CalibrationParameters"),
25  bei,
26  task ),
28  task ),
29  CalibrationHistograms( pset.getParameter<edm::ParameterSet>("CalibrationParameters"),
30  bei,
31  task )
32 {
34  << "[CalibrationHistosUsingDb::" << __func__ << "]"
35  << " Constructing object...";
36  // Load and dump the current ISHA/VFS values. This is used by the standalone analysis script
37  const SiStripConfigDb::DeviceDescriptionsRange & apvDescriptions = db->getDeviceDescriptions(APV25);
38  for(SiStripConfigDb::DeviceDescriptionsV::const_iterator apv = apvDescriptions.begin();apv!=apvDescriptions.end();++apv) {
39  apvDescription* desc = dynamic_cast<apvDescription*>( *apv );
40  if ( !desc ) { continue; }
41  // Retrieve device addresses from device description
42  const SiStripConfigDb::DeviceAddress& addr = db->deviceAddress(*desc);
43  std::stringstream bin;
44  bin << std::setw(1) << std::setfill('0') << addr.fecCrate_;
45  bin << "." << std::setw(2) << std::setfill('0') << addr.fecSlot_;
46  bin << "." << std::setw(1) << std::setfill('0') << addr.fecRing_;
47  bin << "." << std::setw(3) << std::setfill('0') << addr.ccuAddr_;
48  bin << "." << std::setw(2) << std::setfill('0') << addr.ccuChan_;
49  bin << "." << desc->getAddress();
50  LogTrace(mlDqmClient_) << "Present values for ISHA/VFS of APV "
51  << bin.str() << " : "
52  << static_cast<uint16_t>(desc->getIsha()) << " " << static_cast<uint16_t>(desc->getVfs());
53  }
54  // Load the histograms with the results
55  const std::string& pwd = bei->pwd();
56  std::string ishaPath = getBasePath(pwd);
57  ishaPath += "/ControlView/isha";
58  LogTrace(mlDqmClient_) << "Looking for " << ishaPath;
59  ishaHistogram_ = ExtractTObject<TH1F>().extract( bei->get(ishaPath) );
60  std::string vfsPath = getBasePath(pwd);
61  vfsPath += "/ControlView/vfs";
62  LogTrace(mlDqmClient_) << "Looking for " << vfsPath;
63  vfsHistogram_ = ExtractTObject<TH1F>().extract( bei->get(vfsPath) );
64 
65 }
66 
67 // -----------------------------------------------------------------------------
71  << "[CalibrationHistosUsingDb::" << __func__ << "]"
72  << " Destructing object...";
73 }
74 
75 // -----------------------------------------------------------------------------
78 
80  << "[CalibrationHistosUsingDb::" << __func__ << "]" << ishaHistogram_ << " " << vfsHistogram_;
81 
82  if(!ishaHistogram_ && !vfsHistogram_) return;
83 
84  if ( !db() ) {
86  << "[CalibrationHistosUsingDb::" << __func__ << "]"
87  << " NULL pointer to SiStripConfigDb interface!"
88  << " Aborting upload...";
89  return;
90  }
91 
92  // Update all APV device descriptions with new ISHA and VFS settings
94  update( devices );
95  if ( doUploadConf() ) {
97  << "[CalibrationHistosUsingDb::" << __func__ << "]"
98  << " Uploading ISHA/VFS settings to DB...";
101  << "[CalibrationHistosUsingDb::" << __func__ << "]"
102  << " Uploaded ISHA/VFS settings to DB!";
103  } else {
105  << "[CalibrationHistosUsingDb::" << __func__ << "]"
106  << " TEST only! No ISHA/VFS settings will be uploaded to DB...";
107  }
108 
110  << "[CalibrationHistosUsingDb::" << __func__ << "]"
111  << " Upload of ISHA/VFS settings to DB finished!";
112 
113 }
114 
115 // -----------------------------------------------------------------------------
118 
119  if(!ishaHistogram_ && !vfsHistogram_) return;
120 
121  // Iterate through devices and update device descriptions
122  SiStripConfigDb::DeviceDescriptionsV::const_iterator idevice;
123  for ( idevice = devices.begin(); idevice != devices.end(); idevice++ ) {
124 
125  // Check device type
126  if ( (*idevice)->getDeviceType() != APV25 ) { continue; }
127 
128  // Cast to retrieve appropriate description object
129  apvDescription* desc = dynamic_cast<apvDescription*>( *idevice );
130  if ( !desc ) { continue; }
131 
132  // Retrieve the device address from device description
133  const SiStripConfigDb::DeviceAddress& addr = db()->deviceAddress(*desc);
134 
135  // Construct the string for that address
136  std::stringstream bin;
137  bin << std::setw(1) << std::setfill('0') << addr.fecCrate_;
138  bin << "." << std::setw(2) << std::setfill('0') << addr.fecSlot_;
139  bin << "." << std::setw(1) << std::setfill('0') << addr.fecRing_;
140  bin << "." << std::setw(3) << std::setfill('0') << addr.ccuAddr_;
141  bin << "." << std::setw(2) << std::setfill('0') << addr.ccuChan_;
142  bin << "." << desc->getAddress();
143 
144  // Iterate over the histo bins and find the right one
145  for(int i = 1;i <= ishaHistogram_->GetNbinsX(); ++i) {
146  std::string label = ishaHistogram_->GetXaxis()->GetBinLabel(i);
147  if(label == bin.str()) {
148  desc->setIsha( (int)round(ishaHistogram_->GetBinContent(i)) );
149  LogDebug(mlDqmClient_) << "Setting ISHA to " << ((int)round(ishaHistogram_->GetBinContent(i))) << " for " << label;
150  }
151  }
152  for(int i = 1;i <= vfsHistogram_->GetNbinsX(); ++i) {
153  std::string label = vfsHistogram_->GetXaxis()->GetBinLabel(i);
154  if(label == bin.str()) {
155  desc->setVfs( (int)round(vfsHistogram_->GetBinContent(i)) );
156  LogDebug(mlDqmClient_) << "Setting VFS to " << ((int)round(vfsHistogram_->GetBinContent(i))) << " for " << label;
157  }
158  }
159 
160  }
161 
162 }
163 
164 // -----------------------------------------------------------------------------
167  Analysis analysis) {
168 
169  CalibrationAnalysis* anal = dynamic_cast<CalibrationAnalysis*>( analysis->second );
170  if ( !anal ) { return; }
171 
172  SiStripFecKey fec_key( anal->fecKey() );
173  SiStripFedKey fed_key( anal->fedKey() );
174 
175  std::ofstream ofile("calibrationResults.txt",ios_base::app);
176  for ( uint16_t iapv = 0; iapv < 2; ++iapv ) {
177 
178  // Create description
179  CalibrationAnalysisDescription *tmp;
180  tmp = new CalibrationAnalysisDescription(anal->amplitudeMean()[iapv],
181  anal->tailMean()[iapv],
182  anal->riseTimeMean()[iapv],
183  anal->timeConstantMean()[iapv],
184  anal->smearingMean()[iapv],
185  anal->chi2Mean()[iapv],
186  anal->deconvMode(),
187  fec_key.fecCrate(),
188  fec_key.fecSlot(),
189  fec_key.fecRing(),
190  fec_key.ccuAddr(),
191  fec_key.ccuChan(),
192  SiStripFecKey::i2cAddr( fec_key.lldChan(), !iapv ),
193  db()->dbParams().partitions().begin()->second.partitionName(),
194  db()->dbParams().partitions().begin()->second.runNumber(),
195  anal->isValid(),
196  "",
197  fed_key.fedId(),
198  fed_key.feUnit(),
199  fed_key.feChan(),
200  fed_key.fedApv(),
201  calchan_,
202  isha_,
203  vfs_ );
204 
205  // debug simplified printout in text file
206  ofile << " " << anal->amplitudeMean()[iapv]
207  << " " << anal->tailMean()[iapv]
208  << " " << anal->riseTimeMean()[iapv]
209  << " " << anal->timeConstantMean()[iapv]
210  << " " << anal->smearingMean()[iapv]
211  << " " << anal->chi2Mean()[iapv]
212  << " " << anal->deconvMode()
213  << " " << fec_key.fecCrate()
214  << " " << fec_key.fecSlot()
215  << " " << fec_key.fecRing()
216  << " " << fec_key.ccuAddr()
217  << " " << fec_key.ccuChan()
218  << " " << SiStripFecKey::i2cAddr( fec_key.lldChan(), !iapv )
219  << " " << db()->dbParams().partitions().begin()->second.partitionName()
220  << " " << db()->dbParams().partitions().begin()->second.runNumber()
221  << " " << fed_key.fedId()
222  << " " << fed_key.feUnit()
223  << " " << fed_key.feChan()
224  << " " << fed_key.fedApv()
225  << " " << calchan_
226  << " " << isha_
227  << " " << vfs_ << std::endl;
228 
229  // Add comments
230  typedef std::vector<std::string> Strings;
231  Strings errors = anal->getErrorCodes();
232  Strings::const_iterator istr = errors.begin();
233  Strings::const_iterator jstr = errors.end();
234  for ( ; istr != jstr; ++istr ) { tmp->addComments( *istr ); }
235 
236  // Store description
237  desc.push_back( tmp );
238  }
239  ofile.close();
240 
241 }
242 
#define LogDebug(id)
const VFloat & smearingMean() const
const uint32_t & fedKey() const
const VFloat & amplitudeMean() const
A container class for generic run and event-related info, information required by the commissioning a...
Definition: SiStripFedKey.h:56
const VFloat & timeConstantMean() const
virtual bool isValid() const
std::vector< std::string > Strings
Definition: MsgTools.h:18
static const char mlDqmClient_[]
const VFloat & riseTimeMean() const
const uint16_t & i2cAddr() const
sistrip classes
Utility class that identifies a position within the strip tracker control structure, down to the level of an APV25.
Definition: SiStripFecKey.h:45
const_iterator_range partitions() const
Analysis for calibration runs.
DeviceDescriptions::range DeviceDescriptionsRange
An interface class to the DeviceFactory.
const uint32_t & fecKey() const
DeviceAddress deviceAddress(const deviceDescription &)
#define LogTrace(id)
const VFloat & chi2Mean() const
bin
set the eta bin as selection string.
int extract(std::vector< int > *output, const std::string &dati)
const SiStripDbParams & dbParams() const
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
HLT enums.
void create(SiStripConfigDb::AnalysisDescriptionsV &, Analysis) override
CalibrationHistosUsingDb(const edm::ParameterSet &pset, DQMStore *, SiStripConfigDb *const, const sistrip::RunType &task=sistrip::CALIBRATION)
std::vector< AnalysisDescription * > AnalysisDescriptionsV
static const char root_[]
void update(SiStripConfigDb::DeviceDescriptionsRange &)
const VFloat & tailMean() const
Definition: errors.py:1
SiStripConfigDb *const db() const
DeviceDescriptionsRange getDeviceDescriptions(std::string partition="")
void uploadDeviceDescriptions(std::string partition="")
std::string getBasePath(const std::string &path)
const VString & getErrorCodes() const