67 unsigned int derivatives(std::vector<ValuesIndexPair> &outDerivInds,
71 const EventInfo &eventInfo)
const override;
110 const std::map<unsigned int, TreeStruct> &treeInfo,
111 const char *treeName)
const;
140 saveToDB_(cfg.getParameter<bool>(
"saveToDB")),
141 recordNameDBwrite_(cfg.getParameter<std::
string>(
"recordNameDBwrite")),
142 outFileName_(cfg.getParameter<std::
string>(
"treeFile")),
143 mergeFileNames_(cfg.getParameter<std::
vector<std::
string> >(
"mergeTreeFiles")),
144 lorentzAngleLabel_(cfg.getParameter<std::
string>(
"lorentzAngleLabel")),
147 moduleGroupSelCfg_(cfg.getParameter<edm::
ParameterSet>(
"LorentzAngleModuleGroups")) {}
177 if (lorentzAngleRcd.validityInterval().first().eventID().run() >
firstRun &&
183 <<
") in an IOV (" <<
firstRun <<
") that was already cached.\n"
184 <<
"The following record in your input database tag has an IOV "
185 <<
"boundary that does not match your IOV definition:\n"
186 <<
" - SiPixelLorentzAngleRcd '" << lorentzAngleRcd.key().name() <<
"' (since "
187 << lorentzAngleRcd.validityInterval().first().eventID().run() <<
")\n";
201 outDerivInds.clear();
216 const double xDerivative = bFieldLocal.y() * dZ * -0.5;
217 const double yDerivative = bFieldLocal.x() * dZ * 0.5;
218 if (xDerivative || yDerivative) {
219 const Values derivs{xDerivative, yDerivative};
224 edm::LogWarning(
"Alignment") <<
"@SUB=SiPixelLorentzAngleCalibration::derivatives2"
225 <<
"Hit without GeomDet, skip!";
228 return outDerivInds.size();
273 edm::LogInfo(
"Alignment") <<
"@SUB=SiPixelLorentzAngleCalibration"
274 <<
"Created with name " << this->
name() <<
"',\n"
281 edm::LogInfo(
"Alignment") <<
"@SUB=SiPixelLorentzAngleCalibration"
289 std::ostringstream
out;
290 out <<
"Parameter results\n";
291 for (
unsigned int iPar = 0; iPar <
parameters_.size(); ++iPar) {
294 edm::LogInfo(
"Alignment") <<
"@SUB=SiPixelLorentzAngleCalibration::endOfJob" << out.str();
296 std::map<unsigned int, TreeStruct> treeInfo;
300 std::vector<const SiPixelLorentzAngle *>
inputs{};
307 (treeName +
"input_" + std::to_string(firstRunOfIOV)).c_str());
309 if (
inputs.back()->getLorentzAngles().empty()) {
310 edm::LogError(
"Alignment") <<
"@SUB=SiPixelLorentzAngleCalibration::endOfJob"
311 <<
"Input Lorentz angle map is empty, skip writing output!";
316 const unsigned int nonZeroParamsOrErrors =
324 for (
const auto &iterIdValue :
inputs[iIOV]->getLorentzAngles()) {
326 const auto detId = iterIdValue.first;
330 auto value = iterIdValue.second +
static_cast<float>(param);
336 if (
saveToDB_ || nonZeroParamsOrErrors != 0) {
337 this->
writeTree(&
output, treeInfo, (treeName + Form(
"result_%lld", firstRunOfIOV)).c_str());
345 edm::LogError(
"BadConfig") <<
"@SUB=SiPixelLorentzAngleCalibration::endOfJob"
346 <<
"No PoolDBOutputService available, but saveToDB true!";
354 const auto &resolvedRun = run > 0 ? run :
currentIOV_;
359 const std::string treeName{this->
name() +
"_input_" + std::to_string(resolvedRun)};
370 if (!la.getLorentzAngles().empty() &&
373 edm::LogError(
"NoInput") <<
"@SUB=SiPixelLorentzAngleCalibration::getLorentzAnglesInput"
374 <<
"Different input values from tree " << treeName <<
" in file " << iFile <<
".";
383 edm::LogError(
"NoInput") <<
"@SUB=SiPixelLorentzAngleCalibration::getLorentzAnglesInput"
384 <<
"No input, create an empty one!";
386 edm::LogError(
"NoInput") <<
"@SUB=SiPixelLorentzAngleCalibration::getLorentzAnglesInput"
401 const std::map<unsigned int, TreeStruct> &treeInfo,
402 const char *treeName)
const {
408 edm::LogError(
"BadConfig") <<
"@SUB=SiPixelLorentzAngleCalibration::writeTree"
413 TTree *
tree =
new TTree(treeName, treeName);
417 tree->Branch(
"detId", &
id,
"detId/i");
418 tree->Branch(
"value", &value,
"value/F");
425 id = iterIdValue->first;
426 value = iterIdValue->second;
428 auto treeStructIter = treeInfo.find(
id);
429 if (treeStructIter != treeInfo.end()) {
430 treeStruct = treeStructIter->second;
446 TFile *
file =
nullptr;
447 FILE *testFile = fopen(fileName,
"r");
450 file = TFile::Open(fileName,
"READ");
453 TTree *
tree =
nullptr;
455 file->GetObject(treeName, tree);
461 tree->SetBranchAddress(
"detId", &
id);
462 tree->SetBranchAddress(
"value", &value);
464 const Long64_t nEntries = tree->GetEntries();
465 for (Long64_t iEntry = 0; iEntry < nEntries; ++iEntry) {
466 tree->GetEntry(iEntry);
467 result.putLorentzAngle(
id, value);
470 edm::LogWarning(
"Alignment") <<
"@SUB=SiPixelLorentzAngleCalibration::createFromTree"
471 <<
"Could not get TTree '" << treeName <<
"' from file '" << fileName
472 << (file ?
"'." :
"' (file does not exist).");
const TimeTypeSpecs timeTypeSpecs[]
bool setParameterError(unsigned int index, double error) override
const std::map< unsigned int, float > & getLorentzAngles() const
SiPixelLorentzAngleCalibration(const edm::ParameterSet &cfg, edm::ConsumesCollector &iC)
Constructor.
const edm::EventSetup & c
SiPixelLorentzAngle * siPixelLorentzAngleInput_
const std::string recordNameDBwrite_
std::vector< double > parameters_
virtual GlobalVector inTesla(const GlobalPoint &gp) const =0
Field value ad specified global point, in Tesla.
bool setParameter(unsigned int index, double value) override
const std::string outFileName_
unsigned int numParameters() const override
How many parameters does this calibration define?
const std::string & name() const
name of this calibration
void beginRun(const edm::Run &, const edm::EventSetup &) override
Call at beginning of run:
const Bounds & bounds() const
double getParameter(unsigned int index) const override
Log< level::Error, false > LogError
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > magFieldToken_
std::unique_ptr< TkModuleGroupSelector > moduleGroupSelector_
const edm::EventID eventId() const
const Plane & surface() const
The nominal surface of the GeomDet.
unsigned int derivatives(std::vector< ValuesIndexPair > &outDerivInds, const TransientTrackingRecHit &hit, const TrajectoryStateOnSurface &tsos, const edm::EventSetup &setup, const EventInfo &eventInfo) const override
SiPixelLorentzAngle createFromTree(const char *fileName, const char *treeName) const
define event information passed to algorithms
void writeTree(const SiPixelLorentzAngle *lorentzAngle, const std::map< unsigned int, TreeStruct > &treeInfo, const char *treeName) const
virtual float thickness() const =0
bool getData(T &iHolder) const
structure to store algorithm results in a TTree
edm::ESWatcher< SiPixelLorentzAngleRcd > watchLorentzAngleRcd_
std::map< align::RunNumber, SiPixelLorentzAngle > cachedLorentzAngleInputs_
unsigned long long Time_t
const std::string lorentzAngleLabel_
const GeomDet * det() const
LocalPoint toLocal(const GlobalPoint &gp) const
std::pair< Values, unsigned int > ValuesIndexPair
x- and y-values
double getParameterError(unsigned int index) const override
void beginOfJob(AlignableTracker *tracker, AlignableMuon *muon, AlignableExtras *extras) override
Call at beginning of job:
const SiPixelLorentzAngle * getLorentzAnglesInput(const align::RunNumber &=0)
Hash writeOneIOV(const T &payload, Time_t time, const std::string &recordName)
DetId geographicalId() const
The label of this GeomDet.
align::RunNumber currentIOV_
std::pair< double, double > Values
Log< level::Info, false > LogInfo
double getParameterForDetId(unsigned int detId, edm::RunNumber_t run) const
const edm::ParameterSet moduleGroupSelCfg_
~SiPixelLorentzAngleCalibration() override=default
Destructor.
static const char * LeafList()
bool check(const edm::EventSetup &iSetup)
const edm::ESGetToken< SiPixelLorentzAngle, SiPixelLorentzAngleRcd > lorentzAngleToken_
std::vector< double > paramUncertainties_
const std::vector< std::string > mergeFileNames_
#define DEFINE_EDM_PLUGIN(factory, type, name)
Log< level::Warning, false > LogWarning
Constructor of the full muon geometry.
const PositionType & position() const
cond::RealTimeType< cond::runnumber >::type RunNumber