CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
SiStripLorentzAngleCalibration Class Reference
Inheritance diagram for SiStripLorentzAngleCalibration:
IntegratedCalibrationBase

Public Member Functions

void beginOfJob (AlignableTracker *tracker, AlignableMuon *muon, AlignableExtras *extras) override
 
void beginRun (const edm::Run &, const edm::EventSetup &) override
 Call at beginning of run: More...
 
unsigned int derivatives (std::vector< ValuesIndexPair > &outDerivInds, const TransientTrackingRecHit &hit, const TrajectoryStateOnSurface &tsos, const edm::EventSetup &setup, const EventInfo &eventInfo) const override
 
void endOfJob () override
 
double getParameter (unsigned int index) const override
 
double getParameterError (unsigned int index) const override
 
unsigned int numParameters () const override
 How many parameters does this calibration define? More...
 
bool setParameter (unsigned int index, double value) override
 
bool setParameterError (unsigned int index, double error) override
 
 SiStripLorentzAngleCalibration (const edm::ParameterSet &cfg, edm::ConsumesCollector &iC)
 Constructor. More...
 
 ~SiStripLorentzAngleCalibration () override=default
 Destructor. More...
 
- Public Member Functions inherited from IntegratedCalibrationBase
virtual std::vector< Valuesderivatives (const TrackingRecHit &hit, const TrajectoryStateOnSurface &tsos, const edm::EventSetup &setup, const EventInfo &eventInfo) const
 
virtual unsigned int derivatives (std::vector< ValuesIndexPair > &outDerivInds, const TrackingRecHit &hit, const TrajectoryStateOnSurface &tsos, const edm::EventSetup &setup, const EventInfo &eventInfo) const =0
 
virtual void endOfLoop ()
 
 IntegratedCalibrationBase (const edm::ParameterSet &cfg)
 Values and their parameter index. More...
 
const std::string & name () const
 name of this calibration More...
 
virtual void startNewLoop ()
 
virtual ~IntegratedCalibrationBase ()
 Destructor. More...
 

Private Member Functions

SiStripLorentzAngle createFromTree (const char *fileName, const char *treeName) const
 
double effectiveThickness (const GeomDet *det, int16_t mode, const edm::EventSetup &setup) const
 in non-peak mode the effective thickness is reduced... More...
 
const SiStripLorentzAnglegetLorentzAnglesInput (const align::RunNumber &=0)
 
double getParameterForDetId (unsigned int detId, edm::RunNumber_t run) const
 
void writeTree (const SiStripLorentzAngle *lorentzAngle, const std::map< unsigned int, TreeStruct > &treeInfo, const char *treeName) const
 

Private Attributes

const edm::ESGetToken< SiStripBackPlaneCorrection, SiStripBackPlaneCorrectionRcdbackPlaneCorrToken_
 
std::map< align::RunNumber, SiStripLorentzAnglecachedLorentzAngleInputs_
 
align::RunNumber currentIOV_ {0}
 
const edm::ESGetToken< SiStripLatency, SiStripLatencyRcdlatencyToken_
 
const edm::ESGetToken< SiStripLorentzAngle, SiStripLorentzAngleRcdlorentzAngleToken_
 
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecordmagFieldToken_
 
const std::vector< std::string > mergeFileNames_
 
const edm::ParameterSet moduleGroupSelCfg_
 
std::unique_ptr< TkModuleGroupSelectormoduleGroupSelector_
 
const std::string outFileName_
 
std::vector< double > parameters_
 
std::vector< double > paramUncertainties_
 
int16_t readoutMode_
 
const std::string readoutModeName_
 
const std::string recordNameDBwrite_
 
const bool saveToDB_
 
SiStripLorentzAnglesiStripLorentzAngleInput_ {nullptr}
 
edm::ESWatcher< SiStripLorentzAngleRcdwatchLorentzAngleRcd_
 

Additional Inherited Members

- Public Types inherited from IntegratedCalibrationBase
typedef AlignmentAlgorithmBase::EventInfo EventInfo
 
typedef std::pair< double, double > Values
 
typedef std::pair< Values, unsigned int > ValuesIndexPair
 x- and y-values More...
 

Detailed Description

Calibration of Lorentz angle for the strip tracker, integrated in the alignment algorithms. Note that not all algorithms support this...

Use one instance for peak and/or one instance for deco mode data.

Author
: Gero Flucke date : August 2012
Revision
1.6.2.14
Date
2013/05/31 08:37:12

(last update by

Author
flucke

)

Definition at line 53 of file SiStripLorentzAngleCalibration.cc.

Constructor & Destructor Documentation

◆ SiStripLorentzAngleCalibration()

SiStripLorentzAngleCalibration::SiStripLorentzAngleCalibration ( const edm::ParameterSet cfg,
edm::ConsumesCollector iC 
)
explicit

Constructor.

Definition at line 144 of file SiStripLorentzAngleCalibration.cc.

References Exception, kDeconvolutionMode, kPeakMode, readoutMode_, and readoutModeName_.

146  readoutModeName_(cfg.getParameter<std::string>("readoutMode")),
147  saveToDB_(cfg.getParameter<bool>("saveToDB")),
148  recordNameDBwrite_(cfg.getParameter<std::string>("recordNameDBwrite")),
149  outFileName_(cfg.getParameter<std::string>("treeFile")),
150  mergeFileNames_(cfg.getParameter<std::vector<std::string> >("mergeTreeFiles")),
151  moduleGroupSelCfg_(cfg.getParameter<edm::ParameterSet>("LorentzAngleModuleGroups")),
156  // SiStripLatency::singleReadOutMode() returns
157  // 1: all in peak, 0: all in deco, -1: mixed state
158  // (in principle one could treat even mixed state APV by APV...)
159  if (readoutModeName_ == "peak") {
161  } else if (readoutModeName_ == "deconvolution") {
163  } else {
164  throw cms::Exception("BadConfig") << "SiStripLorentzAngleCalibration:\n"
165  << "Unknown mode '" << readoutModeName_
166  << "', should be 'peak' or 'deconvolution' .\n";
167  }
168 }
IntegratedCalibrationBase(const edm::ParameterSet &cfg)
Values and their parameter index.
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > magFieldToken_
const std::vector< std::string > mergeFileNames_
const edm::ESGetToken< SiStripLorentzAngle, SiStripLorentzAngleRcd > lorentzAngleToken_
const edm::ESGetToken< SiStripLatency, SiStripLatencyRcd > latencyToken_
const edm::ESGetToken< SiStripBackPlaneCorrection, SiStripBackPlaneCorrectionRcd > backPlaneCorrToken_

◆ ~SiStripLorentzAngleCalibration()

SiStripLorentzAngleCalibration::~SiStripLorentzAngleCalibration ( )
overridedefault

Destructor.

Member Function Documentation

◆ beginOfJob()

void SiStripLorentzAngleCalibration::beginOfJob ( AlignableTracker tracker,
AlignableMuon muon,
AlignableExtras extras 
)
overridevirtual

Call at beginning of job: default implementation is dummy, to be overwritten in derived class if useful.

Reimplemented from IntegratedCalibrationBase.

Definition at line 297 of file SiStripLorentzAngleCalibration.cc.

References mergeFileNames_, moduleGroupSelCfg_, moduleGroupSelector_, IntegratedCalibrationBase::name(), numParameters(), outFileName_, parameters_, paramUncertainties_, readoutModeName_, saveToDB_, SiStripDetId::TEC, SiStripDetId::TIB, SiStripDetId::TID, and SiStripDetId::TOB.

299  {
300  //specify the sub-detectors for which the LA is determined
301  const std::vector<int> sdets = {SiStripDetId::TIB, SiStripDetId::TOB, SiStripDetId::TID, SiStripDetId::TEC};
302  moduleGroupSelector_ = std::make_unique<TkModuleGroupSelector>(aliTracker, moduleGroupSelCfg_, sdets);
303 
304  parameters_.resize(moduleGroupSelector_->getNumberOfParameters(), 0.);
305  paramUncertainties_.resize(moduleGroupSelector_->getNumberOfParameters(), 0.);
306 
307  edm::LogInfo("Alignment") << "@SUB=SiStripLorentzAngleCalibration"
308  << "Created with name " << this->name() << " for readout mode '" << readoutModeName_
309  << "',\n"
310  << this->numParameters() << " parameters to be determined."
311  << "\nsaveToDB = " << saveToDB_ << "\n outFileName = " << outFileName_
312  << "\n N(merge files) = " << mergeFileNames_.size()
313  << "\n number of IOVs = " << moduleGroupSelector_->numIovs();
314 
315  if (!mergeFileNames_.empty()) {
316  edm::LogInfo("Alignment") << "@SUB=SiStripLorentzAngleCalibration"
317  << "First file to merge: " << mergeFileNames_[0];
318  }
319 }
static constexpr auto TID
Definition: SiStripDetId.h:38
const std::vector< std::string > mergeFileNames_
static constexpr auto TOB
Definition: SiStripDetId.h:39
Log< level::Info, false > LogInfo
std::unique_ptr< TkModuleGroupSelector > moduleGroupSelector_
static constexpr auto TIB
Definition: SiStripDetId.h:37
unsigned int numParameters() const override
How many parameters does this calibration define?
const std::string & name() const
name of this calibration
static constexpr auto TEC
Definition: SiStripDetId.h:40

◆ beginRun()

void SiStripLorentzAngleCalibration::beginRun ( const edm::Run run,
const edm::EventSetup setup 
)
overridevirtual

Call at beginning of run:

Reimplemented from IntegratedCalibrationBase.

Definition at line 174 of file SiStripLorentzAngleCalibration.cc.

References cond::TimeTypeSpecs::beginValue, cachedLorentzAngleInputs_, edm::ESWatcher< T >::check(), currentIOV_, Exception, GCP_Ntuples_cfg::firstRun, SiStripLorentzAngle::getLorentzAngles(), mps_fire::i, lorentzAngleToken_, moduleGroupSelector_, writedatasetfile::run, cond::runnumber, convertSQLiteXML::runNumber, singleTopDQM_cfi::setup, siStripLorentzAngleInput_, cond::timeTypeSpecs, and watchLorentzAngleRcd_.

174  {
175  // no action needed if the LA record didn't change
176  if (!(watchLorentzAngleRcd_.check(setup)))
177  return;
178 
179  const auto runNumber = run.run();
181 
182  // avoid infinite loop due to wrap-around of unsigned variable 'i' including
183  // arrow from i to zero and a nice smiley ;)
184  for (unsigned int i = moduleGroupSelector_->numIovs(); i-- > 0;) {
185  const auto firstRunOfIOV = moduleGroupSelector_->firstRunOfIOV(i);
186  if (runNumber >= firstRunOfIOV) {
187  firstRun = firstRunOfIOV;
188  break;
189  }
190  }
191 
192  const SiStripLorentzAngle *lorentzAngleHandle = &setup.getData(lorentzAngleToken_);
193  const auto &lorentzAngleRcd = setup.get<SiStripLorentzAngleRcd>();
195  cachedLorentzAngleInputs_.emplace(firstRun, SiStripLorentzAngle(*lorentzAngleHandle));
196  } else {
197  if (lorentzAngleRcd.validityInterval().first().eventID().run() > firstRun &&
198  lorentzAngleHandle->getLorentzAngles() // only bad if non-identical values
199  != cachedLorentzAngleInputs_[firstRun].getLorentzAngles()) { // (comparing maps)
200  // Maps are containers sorted by key, but comparison problems may arise from
201  // 'floating point comparison' problems (FIXME?)
202  throw cms::Exception("BadInput") << "Trying to cache SiStripLorentzAngle payload for a run (" << runNumber
203  << ") in an IOV (" << firstRun << ") that was already cached.\n"
204  << "The following record in your input database tag has an IOV "
205  << "boundary that does not match your IOV definition:\n"
206  << " - SiStripLorentzAngleRcd '" << lorentzAngleRcd.key().name() << "' (since "
207  << lorentzAngleRcd.validityInterval().first().eventID().run() << ")\n";
208  }
209  }
210 
213 }
const TimeTypeSpecs timeTypeSpecs[]
Definition: Time.cc:16
Time_t beginValue
Definition: Time.h:41
const edm::ESGetToken< SiStripLorentzAngle, SiStripLorentzAngleRcd > lorentzAngleToken_
std::map< align::RunNumber, SiStripLorentzAngle > cachedLorentzAngleInputs_
edm::ESWatcher< SiStripLorentzAngleRcd > watchLorentzAngleRcd_
std::unique_ptr< TkModuleGroupSelector > moduleGroupSelector_
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
const std::map< unsigned int, float > & getLorentzAngles() const

◆ createFromTree()

SiStripLorentzAngle SiStripLorentzAngleCalibration::createFromTree ( const char *  fileName,
const char *  treeName 
) const
private

Definition at line 505 of file SiStripLorentzAngleCalibration.cc.

References geometryDiff::file, MillePedeFileConverter_cfg::fileName, and mps_fire::result.

Referenced by getLorentzAnglesInput().

505  {
506  // Check for file existence on your own to work around
507  // https://hypernews.cern.ch/HyperNews/CMS/get/swDevelopment/2715.html:
508  TFile *file = nullptr;
509  FILE *testFile = fopen(fileName, "r");
510  if (testFile) {
511  fclose(testFile);
512  file = TFile::Open(fileName, "READ");
513  } // else not existing, see error below
514 
515  TTree *tree = nullptr;
516  if (file)
517  file->GetObject(treeName, tree);
518 
520  if (tree) {
521  unsigned int id = 0;
522  float value = 0.;
523  tree->SetBranchAddress("detId", &id);
524  tree->SetBranchAddress("value", &value);
525 
526  const Long64_t nEntries = tree->GetEntries();
527  for (Long64_t iEntry = 0; iEntry < nEntries; ++iEntry) {
528  tree->GetEntry(iEntry);
529  result.putLorentzAngle(id, value);
530  }
531  } else { // Warning only since could be parallel job on no events.
532  edm::LogWarning("Alignment") << "@SUB=SiStripLorentzAngleCalibration::createFromTree"
533  << "Could not get TTree '" << treeName << "' from file '" << fileName
534  << (file ? "'." : "' (file does not exist).");
535  }
536 
537  delete file; // tree will vanish with file
538  return result;
539 }
Definition: value.py:1
Definition: tree.py:1
Log< level::Warning, false > LogWarning

◆ derivatives()

unsigned int SiStripLorentzAngleCalibration::derivatives ( std::vector< ValuesIndexPair > &  outDerivInds,
const TransientTrackingRecHit hit,
const TrajectoryStateOnSurface tsos,
const edm::EventSetup setup,
const EventInfo eventInfo 
) const
override

Return non-zero derivatives for x- and y-measurements with their indices by reference. Return value is their number.

Definition at line 216 of file SiStripLorentzAngleCalibration.cc.

References Calorimetry_cff::bField, TrackingRecHit::det(), l1ctLayer1_cff::dZ, effectiveThickness(), dumpTauVariables_cfi::eventInfo, kDeconvolutionMode, kPeakMode, config_102169_raw_cff::latency, latencyToken_, magFieldToken_, HLT_2023v12_cff::magneticField, ALCARECOPromptCalibProdSiPixelAli0T_cff::mode, moduleGroupSelector_, readoutMode_, readoutModeName_, and singleTopDQM_cfi::setup.

220  {
221  outDerivInds.clear();
222 
223  const SiStripLatency *latency = &setup.getData(latencyToken_);
224  const int16_t mode = latency->singleReadOutMode();
225  if (mode == readoutMode_) {
226  if (hit.det()) { // otherwise 'constraint hit' or whatever
227 
228  const int index =
229  moduleGroupSelector_->getParameterIndexFromDetId(hit.det()->geographicalId(), eventInfo.eventId().run());
230  if (index >= 0) { // otherwise not treated
231  const MagneticField *magneticField = &setup.getData(magFieldToken_);
232  const GlobalVector bField(magneticField->inTesla(hit.det()->surface().position()));
233  const LocalVector bFieldLocal(hit.det()->surface().toLocal(bField));
234  const double dZ = this->effectiveThickness(hit.det(), mode, setup);
235  // shift due to LA: dx = tan(LA) * dz/2 = mobility * B_y * dz/2,
236  // '-' since we have derivative of the residual r = hit - trk and mu is part of trk model
237  // (see GF's presentation in alignment meeting 25.10.2012,
238  // https://indico.cern.ch/conferenceDisplay.py?confId=174266#2012-10-25)
239  // Hmm! StripCPE::fillParams() defines, together with
240  // StripCPE::driftDirection(...):
241  // drift.x = -mobility * by * thickness (full drift from backside)
242  // So '-' already comes from that, not from mobility being part of
243  // track model...
244  // GM: sign convention is the same as for pixel LA, i.e. adopt it here, too
245  const double xDerivative = bFieldLocal.y() * dZ * -0.5; // parameter is mobility!
246  const double yDerivative = bFieldLocal.x() * dZ * 0.5; // parameter is mobility!
247  if (xDerivative || yDerivative) { // If field is zero, this is zero: do not return it
248  const Values derivs{xDerivative, yDerivative};
249  outDerivInds.push_back(ValuesIndexPair(derivs, index));
250  }
251  }
252  } else {
253  edm::LogWarning("Alignment") << "@SUB=SiStripLorentzAngleCalibration::derivatives1"
254  << "Hit without GeomDet, skip!";
255  }
256  } else if (mode != kDeconvolutionMode && mode != kPeakMode) {
257  // warn only if unknown/mixed mode
258  edm::LogWarning("Alignment") << "@SUB=SiStripLorentzAngleCalibration::derivatives2"
259  << "Readout mode is " << mode << ", but looking for " << readoutMode_ << " ("
260  << readoutModeName_ << ").";
261  }
262 
263  return outDerivInds.size();
264 }
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > magFieldToken_
const GeomDet * det() const
const edm::ESGetToken< SiStripLatency, SiStripLatencyRcd > latencyToken_
double effectiveThickness(const GeomDet *det, int16_t mode, const edm::EventSetup &setup) const
in non-peak mode the effective thickness is reduced...
std::pair< Values, unsigned int > ValuesIndexPair
x- and y-values
std::pair< double, double > Values
std::unique_ptr< TkModuleGroupSelector > moduleGroupSelector_
eventInfo
add run, event number and lumi section
Log< level::Warning, false > LogWarning

◆ effectiveThickness()

double SiStripLorentzAngleCalibration::effectiveThickness ( const GeomDet det,
int16_t  mode,
const edm::EventSetup setup 
) const
private

in non-peak mode the effective thickness is reduced...

Definition at line 396 of file SiStripLorentzAngleCalibration.cc.

References backPlaneCorrToken_, Surface::bounds(), l1ctLayer1_cff::dZ, GeomDet::geographicalId(), l1ctLayer2EG_cff::id, singleTopDQM_cfi::setup, GeomDet::surface(), and Bounds::thickness().

Referenced by derivatives().

398  {
399  if (!det)
400  return 0.;
401  double dZ = det->surface().bounds().thickness(); // it is a float only...
402  const SiStripDetId id(det->geographicalId());
403  const SiStripBackPlaneCorrection *backPlaneHandle = &setup.getData(backPlaneCorrToken_);
404  // FIXME: which one? DepRcd->get(handle) or Rcd->get(readoutModeName_, handle)??
405  // setup.get<SiStripBackPlaneCorrectionDepRcd>().get(backPlaneHandle); // get correct mode
406  const double bpCor = backPlaneHandle->getBackPlaneCorrection(id); // it's a float...
407  // std::cout << "bpCor " << bpCor << " in subdet " << id.subdetId() << std::endl;
408  dZ *= (1. - bpCor);
409 
410  return dZ;
411 }
virtual float thickness() const =0
const edm::ESGetToken< SiStripBackPlaneCorrection, SiStripBackPlaneCorrectionRcd > backPlaneCorrToken_
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:64
Detector identifier class for the strip tracker.
Definition: SiStripDetId.h:18
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
const Bounds & bounds() const
Definition: Surface.h:87

◆ endOfJob()

void SiStripLorentzAngleCalibration::endOfJob ( )
overridevirtual

Called at end of a the job of the AlignmentProducer. Write out determined parameters.

Implements IntegratedCalibrationBase.

Definition at line 322 of file SiStripLorentzAngleCalibration.cc.

References HltBtagPostValidation_cff::c, hcalRecHitTable_cff::detId, getLorentzAnglesInput(), getParameterError(), getParameterForDetId(), PixelMapPlotter::inputs, edm::Service< T >::isAvailable(), moduleGroupSelector_, IntegratedCalibrationBase::name(), MillePedeFileConverter_cfg::out, parameters_, paramUncertainties_, readoutModeName_, recordNameDBwrite_, saveToDB_, AlCaHLTBitMon_QueryRunRegistry::string, to_string(), cond::service::PoolDBOutputService::writeOneIOV(), and writeTree().

322  {
323  // loginfo output
324  std::ostringstream out;
325  out << "Parameter results for readout mode '" << readoutModeName_ << "'\n";
326  for (unsigned int iPar = 0; iPar < parameters_.size(); ++iPar) {
327  out << iPar << ": " << parameters_[iPar] << " +- " << paramUncertainties_[iPar] << "\n";
328  }
329  edm::LogInfo("Alignment") << "@SUB=SiStripLorentzAngleCalibration::endOfJob" << out.str();
330 
331  std::map<unsigned int, TreeStruct> treeInfo; // map of TreeStruct for each detId
332 
333  // now write 'input' tree
334  const std::string treeName{this->name() + '_' + readoutModeName_ + '_'};
335  std::vector<const SiStripLorentzAngle *> inputs{};
336  inputs.reserve(moduleGroupSelector_->numIovs());
337  for (unsigned int iIOV = 0; iIOV < moduleGroupSelector_->numIovs(); ++iIOV) {
338  const auto firstRunOfIOV = moduleGroupSelector_->firstRunOfIOV(iIOV);
339  inputs.push_back(this->getLorentzAnglesInput(firstRunOfIOV)); // never NULL
340  this->writeTree(inputs.back(),
341  treeInfo,
342  (treeName + "input_" + std::to_string(firstRunOfIOV)).c_str()); // empty treeInfo for input...
343 
344  if (inputs.back()->getLorentzAngles().empty()) {
345  edm::LogError("Alignment") << "@SUB=SiStripLorentzAngleCalibration::endOfJob"
346  << "Input Lorentz angle map is empty ('" << readoutModeName_
347  << "' mode), skip writing output!";
348  return;
349  }
350  }
351 
352  const unsigned int nonZeroParamsOrErrors = // Any determined value?
353  count_if(parameters_.begin(), parameters_.end(), [](auto c) { return c != 0.; }) +
354  count_if(paramUncertainties_.begin(), paramUncertainties_.end(), [](auto c) { return c != 0.; });
355 
356  for (unsigned int iIOV = 0; iIOV < moduleGroupSelector_->numIovs(); ++iIOV) {
357  auto firstRunOfIOV = static_cast<cond::Time_t>(moduleGroupSelector_->firstRunOfIOV(iIOV));
359  // Loop on map of values from input and add (possible) parameter results
360  for (const auto &iterIdValue : inputs[iIOV]->getLorentzAngles()) {
361  // type of 'iterIdValue' is pair<unsigned int, float>
362  const auto detId = iterIdValue.first; // key of map is DetId
363  // Some code one could use to miscalibrate wrt input:
364  // double param = 0.;
365  // const DetId id(detId);
366  // if (id.subdetId() == 3) { // TIB
367  // param = (readoutMode_ == kPeakMode ? -0.003 : -0.002);
368  // } else if (id.subdetId() == 5) { // TOB
369  // param = (readoutMode_ == kPeakMode ? 0.005 : 0.004);
370  // }
371  const double param = this->getParameterForDetId(detId, firstRunOfIOV);
372  // put result in output, i.e. sum of input and determined parameter:
373  auto value = iterIdValue.second + static_cast<float>(param);
374  output.putLorentzAngle(detId, value);
375  const int paramIndex = moduleGroupSelector_->getParameterIndexFromDetId(detId, firstRunOfIOV);
376  treeInfo[detId] = TreeStruct(param, this->getParameterError(paramIndex), paramIndex);
377  }
378 
379  if (saveToDB_ || nonZeroParamsOrErrors != 0) { // Skip writing mille jobs...
380  this->writeTree(&output, treeInfo, (treeName + Form("result_%lld", firstRunOfIOV)).c_str());
381  }
382 
383  if (saveToDB_) { // If requested, write out to DB
385  if (dbService.isAvailable()) {
386  dbService->writeOneIOV(output, firstRunOfIOV, recordNameDBwrite_);
387  } else {
388  edm::LogError("BadConfig") << "@SUB=SiStripLorentzAngleCalibration::endOfJob"
389  << "No PoolDBOutputService available, but saveToDB true!";
390  }
391  }
392  } // end loop on IOVs
393 }
void writeTree(const SiStripLorentzAngle *lorentzAngle, const std::map< unsigned int, TreeStruct > &treeInfo, const char *treeName) const
double getParameterError(unsigned int index) const override
Log< level::Error, false > LogError
static std::string to_string(const XMLCh *ch)
structure to store algorithm results in a TTree
Definition: TreeStruct.h:6
unsigned long long Time_t
Definition: Time.h:14
Hash writeOneIOV(const T &payload, Time_t time, const std::string &recordName)
Definition: value.py:1
Log< level::Info, false > LogInfo
std::unique_ptr< TkModuleGroupSelector > moduleGroupSelector_
const SiStripLorentzAngle * getLorentzAnglesInput(const align::RunNumber &=0)
bool isAvailable() const
Definition: Service.h:40
Definition: output.py:1
const std::string & name() const
name of this calibration
double getParameterForDetId(unsigned int detId, edm::RunNumber_t run) const

◆ getLorentzAnglesInput()

const SiStripLorentzAngle * SiStripLorentzAngleCalibration::getLorentzAnglesInput ( const align::RunNumber run = 0)
private

Input LorentzAngle values:

  • either from EventSetup of first call to derivatives(..)
  • or created from files of passed by configuration (i.e. from parallel processing)

Definition at line 414 of file SiStripLorentzAngleCalibration.cc.

References cachedLorentzAngleInputs_, createFromTree(), currentIOV_, SiStripLorentzAngle::getLorentzAngles(), mergeFileNames_, IntegratedCalibrationBase::name(), readoutModeName_, writedatasetfile::run, siStripLorentzAngleInput_, AlCaHLTBitMon_QueryRunRegistry::string, and to_string().

Referenced by endOfJob().

414  {
415  const auto &resolvedRun = run > 0 ? run : currentIOV_;
416  // For parallel processing in Millepede II, create SiStripLorentzAngle
417  // from info stored in files of parallel jobs and check that they are identical.
418  // If this job has run on events, still check that LA is identical to the ones
419  // from mergeFileNames_.
420  const std::string treeName{this->name() + "_" + readoutModeName_ + "_input_" + std::to_string(resolvedRun)};
421  for (const auto &iFile : mergeFileNames_) {
422  auto la = this->createFromTree(iFile.c_str(), treeName.c_str());
423  // siStripLorentzAngleInput_ could be non-null from previous file of this loop
424  // or from checkLorentzAngleInput(..) when running on data in this job as well
426  cachedLorentzAngleInputs_[resolvedRun] = la;
428  currentIOV_ = resolvedRun;
429  } else {
430  // FIXME: about comparison of maps see comments in checkLorentzAngleInput
431  if (!la.getLorentzAngles().empty() && // single job might not have got events
432  la.getLorentzAngles() != siStripLorentzAngleInput_->getLorentzAngles()) {
433  // Throw exception instead of error?
434  edm::LogError("NoInput") << "@SUB=SiStripLorentzAngleCalibration::getLorentzAnglesInput"
435  << "Different input values from tree " << treeName << " in file " << iFile << ".";
436  }
437  }
438  }
439 
440  if (!siStripLorentzAngleInput_) { // no files nor ran on events
441  // [] operator default-constructs an empty SiStripLorentzAngle object in place:
443  currentIOV_ = resolvedRun;
444  edm::LogError("NoInput") << "@SUB=SiStripLorentzAngleCalibration::getLorentzAnglesInput"
445  << "No input, create an empty one ('" << readoutModeName_ << "' mode)!";
446  } else if (siStripLorentzAngleInput_->getLorentzAngles().empty()) {
447  edm::LogError("NoInput") << "@SUB=SiStripLorentzAngleCalibration::getLorentzAnglesInput"
448  << "Empty result ('" << readoutModeName_ << "' mode)!";
449  }
450 
452 }
const std::vector< std::string > mergeFileNames_
std::map< align::RunNumber, SiStripLorentzAngle > cachedLorentzAngleInputs_
Log< level::Error, false > LogError
static std::string to_string(const XMLCh *ch)
SiStripLorentzAngle createFromTree(const char *fileName, const char *treeName) const
const std::map< unsigned int, float > & getLorentzAngles() const
const std::string & name() const
name of this calibration

◆ getParameter()

double SiStripLorentzAngleCalibration::getParameter ( unsigned int  index) const
overridevirtual

Return current value of parameter identified by index. Returns 0. if index out-of-bounds.

Implements IntegratedCalibrationBase.

Definition at line 287 of file SiStripLorentzAngleCalibration.cc.

References parameters_.

Referenced by Mixins._Parameterizable::hasParameter().

287  {
288  return (index >= parameters_.size() ? 0. : parameters_[index]);
289 }

◆ getParameterError()

double SiStripLorentzAngleCalibration::getParameterError ( unsigned int  index) const
overridevirtual

Return current value of parameter identified by index. Returns 0. if index out-of-bounds or if errors undetermined.

Implements IntegratedCalibrationBase.

Definition at line 292 of file SiStripLorentzAngleCalibration.cc.

References paramUncertainties_.

Referenced by endOfJob().

◆ getParameterForDetId()

double SiStripLorentzAngleCalibration::getParameterForDetId ( unsigned int  detId,
edm::RunNumber_t  run 
) const
private

Determined parameter value for this detId (detId not treated => 0.) and the given run.

Definition at line 455 of file SiStripLorentzAngleCalibration.cc.

References hcalRecHitTable_cff::detId, moduleGroupSelector_, parameters_, and writedatasetfile::run.

Referenced by endOfJob().

455  {
456  const int index = moduleGroupSelector_->getParameterIndexFromDetId(detId, run);
457 
458  return (index < 0 ? 0. : parameters_[index]);
459 }
std::unique_ptr< TkModuleGroupSelector > moduleGroupSelector_

◆ numParameters()

unsigned int SiStripLorentzAngleCalibration::numParameters ( ) const
overridevirtual

How many parameters does this calibration define?

Implements IntegratedCalibrationBase.

Definition at line 171 of file SiStripLorentzAngleCalibration.cc.

References parameters_.

Referenced by beginOfJob().

171 { return parameters_.size(); }

◆ setParameter()

bool SiStripLorentzAngleCalibration::setParameter ( unsigned int  index,
double  value 
)
overridevirtual

Setting the determined parameter identified by index, returns false if out-of-bounds, true otherwise.

Implements IntegratedCalibrationBase.

Definition at line 267 of file SiStripLorentzAngleCalibration.cc.

References parameters_, and relativeConstraints::value.

Referenced by coreTools.RunOnData::__call__(), trackTools.MakeAODTrackCandidates::__call__(), runJetUncertainties.RunJetUncertainties::__call__(), metTools.AddMETCollection::__call__(), cmsswVersionTools.PickRelValInputFiles::__call__(), coreTools.RemoveMCMatching::__call__(), trackTools.MakePATTrackCandidates::__call__(), trigTools.SwitchOnTrigger::__call__(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties::__call__(), trigTools.SwitchOnTriggerStandAlone::__call__(), tauTools.AddTauCollection::__call__(), trackTools.MakeTrackCandidates::__call__(), trigTools.SwitchOnTriggerMatching::__call__(), trigTools.SwitchOnTriggerMatchingStandAlone::__call__(), trigTools.SwitchOnTriggerMatchEmbedding::__call__(), jetTools.AddJetCollection::__call__(), jetTools.SwitchJetCollection::__call__(), jetTools.UpdateJetCollection::__call__(), jetTools.AddJetID::__call__(), jetTools.SetTagInfos::__call__(), and runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties::jetConfiguration().

267  {
268  if (index >= parameters_.size()) {
269  return false;
270  } else {
272  return true;
273  }
274 }

◆ setParameterError()

bool SiStripLorentzAngleCalibration::setParameterError ( unsigned int  index,
double  error 
)
overridevirtual

Setting the determined parameter uncertainty identified by index, returns false if out-of-bounds, true otherwise.

Implements IntegratedCalibrationBase.

Definition at line 277 of file SiStripLorentzAngleCalibration.cc.

References relativeConstraints::error, and paramUncertainties_.

277  {
278  if (index >= paramUncertainties_.size()) {
279  return false;
280  } else {
282  return true;
283  }
284 }

◆ writeTree()

void SiStripLorentzAngleCalibration::writeTree ( const SiStripLorentzAngle lorentzAngle,
const std::map< unsigned int, TreeStruct > &  treeInfo,
const char *  treeName 
) const
private

Definition at line 462 of file SiStripLorentzAngleCalibration.cc.

References geometryDiff::file, SiStripLorentzAngle::getLorentzAngles(), TreeStruct::LeafList(), moduleGroupSelector_, and outFileName_.

Referenced by endOfJob().

464  {
465  if (!lorentzAngle)
466  return;
467 
468  TFile *file = TFile::Open(outFileName_.c_str(), "UPDATE");
469  if (!file) {
470  edm::LogError("BadConfig") << "@SUB=SiStripLorentzAngleCalibration::writeTree"
471  << "Could not open file '" << outFileName_ << "'.";
472  return;
473  }
474 
475  TTree *tree = new TTree(treeName, treeName);
476  unsigned int id = 0;
477  float value = 0.;
478  TreeStruct treeStruct;
479  tree->Branch("detId", &id, "detId/i");
480  tree->Branch("value", &value, "value/F");
481  tree->Branch("treeStruct", &treeStruct, TreeStruct::LeafList());
482 
483  for (auto iterIdValue = lorentzAngle->getLorentzAngles().begin();
484  iterIdValue != lorentzAngle->getLorentzAngles().end();
485  ++iterIdValue) {
486  // type of (*iterIdValue) is pair<unsigned int, float>
487  id = iterIdValue->first; // key of map is DetId
488  value = iterIdValue->second;
489  // type of (*treeStructIter) is pair<unsigned int, TreeStruct>
490  auto treeStructIter = treeInfo.find(id); // find info for this id
491  if (treeStructIter != treeInfo.end()) {
492  treeStruct = treeStructIter->second; // info from input map
493  } else { // if none found, fill at least parameter index (using 1st IOV...)
494  const cond::Time_t run1of1stIov = moduleGroupSelector_->firstRunOfIOV(0);
495  const int ind = moduleGroupSelector_->getParameterIndexFromDetId(id, run1of1stIov);
496  treeStruct = TreeStruct(ind);
497  }
498  tree->Fill();
499  }
500  tree->Write();
501  delete file; // tree vanishes with the file...
502 }
Log< level::Error, false > LogError
structure to store algorithm results in a TTree
Definition: TreeStruct.h:6
unsigned long long Time_t
Definition: Time.h:14
Definition: value.py:1
std::unique_ptr< TkModuleGroupSelector > moduleGroupSelector_
static const char * LeafList()
Definition: TreeStruct.h:16
Definition: tree.py:1
const std::map< unsigned int, float > & getLorentzAngles() const

Member Data Documentation

◆ backPlaneCorrToken_

const edm::ESGetToken<SiStripBackPlaneCorrection, SiStripBackPlaneCorrectionRcd> SiStripLorentzAngleCalibration::backPlaneCorrToken_
private

Definition at line 137 of file SiStripLorentzAngleCalibration.cc.

Referenced by effectiveThickness().

◆ cachedLorentzAngleInputs_

std::map<align::RunNumber, SiStripLorentzAngle> SiStripLorentzAngleCalibration::cachedLorentzAngleInputs_
private

Definition at line 124 of file SiStripLorentzAngleCalibration.cc.

Referenced by beginRun(), and getLorentzAnglesInput().

◆ currentIOV_

align::RunNumber SiStripLorentzAngleCalibration::currentIOV_ {0}
private

Definition at line 126 of file SiStripLorentzAngleCalibration.cc.

Referenced by beginRun(), and getLorentzAnglesInput().

◆ latencyToken_

const edm::ESGetToken<SiStripLatency, SiStripLatencyRcd> SiStripLorentzAngleCalibration::latencyToken_
private

Definition at line 134 of file SiStripLorentzAngleCalibration.cc.

Referenced by derivatives().

◆ lorentzAngleToken_

const edm::ESGetToken<SiStripLorentzAngle, SiStripLorentzAngleRcd> SiStripLorentzAngleCalibration::lorentzAngleToken_
private

Definition at line 135 of file SiStripLorentzAngleCalibration.cc.

Referenced by beginRun().

◆ magFieldToken_

const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> SiStripLorentzAngleCalibration::magFieldToken_
private

Definition at line 136 of file SiStripLorentzAngleCalibration.cc.

Referenced by derivatives().

◆ mergeFileNames_

const std::vector<std::string> SiStripLorentzAngleCalibration::mergeFileNames_
private

Definition at line 120 of file SiStripLorentzAngleCalibration.cc.

Referenced by beginOfJob(), and getLorentzAnglesInput().

◆ moduleGroupSelCfg_

const edm::ParameterSet SiStripLorentzAngleCalibration::moduleGroupSelCfg_
private

Definition at line 132 of file SiStripLorentzAngleCalibration.cc.

Referenced by beginOfJob().

◆ moduleGroupSelector_

std::unique_ptr<TkModuleGroupSelector> SiStripLorentzAngleCalibration::moduleGroupSelector_
private

◆ outFileName_

const std::string SiStripLorentzAngleCalibration::outFileName_
private

Definition at line 119 of file SiStripLorentzAngleCalibration.cc.

Referenced by beginOfJob(), and writeTree().

◆ parameters_

std::vector<double> SiStripLorentzAngleCalibration::parameters_
private

◆ paramUncertainties_

std::vector<double> SiStripLorentzAngleCalibration::paramUncertainties_
private

◆ readoutMode_

int16_t SiStripLorentzAngleCalibration::readoutMode_
private

◆ readoutModeName_

const std::string SiStripLorentzAngleCalibration::readoutModeName_
private

◆ recordNameDBwrite_

const std::string SiStripLorentzAngleCalibration::recordNameDBwrite_
private

Definition at line 118 of file SiStripLorentzAngleCalibration.cc.

Referenced by endOfJob().

◆ saveToDB_

const bool SiStripLorentzAngleCalibration::saveToDB_
private

Definition at line 117 of file SiStripLorentzAngleCalibration.cc.

Referenced by beginOfJob(), and endOfJob().

◆ siStripLorentzAngleInput_

SiStripLorentzAngle* SiStripLorentzAngleCalibration::siStripLorentzAngleInput_ {nullptr}
private

Definition at line 125 of file SiStripLorentzAngleCalibration.cc.

Referenced by beginRun(), and getLorentzAnglesInput().

◆ watchLorentzAngleRcd_

edm::ESWatcher<SiStripLorentzAngleRcd> SiStripLorentzAngleCalibration::watchLorentzAngleRcd_
private

Definition at line 122 of file SiStripLorentzAngleCalibration.cc.

Referenced by beginRun().