44 #include <boost/assign/list_of.hpp>
76 virtual unsigned int derivatives(std::vector<ValuesIndexPair> &outDerivInds,
92 virtual double getParameter(
unsigned int index)
const override;
123 const std::map<unsigned int,TreeStruct>& treeInfo,
const char *treeName)
const;
148 saveToDB_(cfg.getParameter<bool>(
"saveToDB")),
149 recordNameDBwrite_(cfg.getParameter<std::
string>(
"recordNameDBwrite")),
150 outFileName_(cfg.getParameter<std::
string>(
"treeFile")),
151 mergeFileNames_(cfg.getParameter<std::vector<std::
string> >(
"mergeTreeFiles")),
152 siPixelLorentzAngleInput_(0),
153 moduleGroupSelector_(0),
154 moduleGroupSelCfg_(cfg.getParameter<edm::
ParameterSet>(
"LorentzAngleModuleGroups"))
185 outDerivInds.clear();
199 const double xDerivative = bFieldLocal.y() * dZ * -0.5;
202 const Values derivs(xDerivative, 0.);
207 edm::LogWarning(
"Alignment") <<
"@SUB=SiPixelLorentzAngleCalibration::derivatives2"
208 <<
"Hit without GeomDet, skip!";
211 return outDerivInds.size();
264 edm::LogInfo(
"Alignment") <<
"@SUB=SiPixelLorentzAngleCalibration" <<
"Created with name "
265 << this->
name() <<
"',\n" << this->
numParameters() <<
" parameters to be determined,"
272 edm::LogInfo(
"Alignment") <<
"@SUB=SiPixelLorentzAngleCalibration"
282 std::ostringstream
out;
283 out <<
"Parameter results\n";
284 for (
unsigned int iPar = 0; iPar <
parameters_.size(); ++iPar) {
287 edm::LogInfo(
"Alignment") <<
"@SUB=SiPixelLorentzAngleCalibration::endOfJob" << out.str();
289 std::map<unsigned int, TreeStruct> treeInfo;
294 this->
writeTree(input, treeInfo, (treeName +
"input").c_str());
297 edm::LogError(
"Alignment") <<
"@SUB=SiPixelLorentzAngleCalibration::endOfJob"
298 <<
"Input Lorentz angle map is empty, skip writing output!";
302 const unsigned int nonZeroParamsOrErrors =
305 std::bind2nd(std::not_equal_to<double>(), 0.));
315 const unsigned int detId = iterIdValue->first;
319 float value = iterIdValue->second + param;
325 if (
saveToDB_ || nonZeroParamsOrErrors != 0) {
326 this->
writeTree(output, treeInfo, (treeName + Form(
"result_%lld", firstRunOfIOV)).c_str());
336 edm::LogError(
"BadConfig") <<
"@SUB=SiPixelLorentzAngleCalibration::endOfJob"
337 <<
"No PoolDBOutputService available, but saveToDB true!";
357 if (lorentzAngleHandle->getLorentzAngles()
362 <<
"SiPixelLorentzAngleCalibration::checkLorentzAngleInput:\n"
363 <<
"Content of SiPixelLorentzAngle changed at run " << eventInfo.
eventId_.
run()
364 <<
", but algorithm expects constant input!\n";
393 edm::LogError(
"NoInput") <<
"@SUB=SiPixelLorentzAngleCalibration::getLorentzAnglesInput"
394 <<
"Different input values from tree " << treeName
395 <<
" in file " << *iFile <<
".";
404 edm::LogError(
"NoInput") <<
"@SUB=SiPixelLorentzAngleCalibration::getLorentzAnglesInput"
405 <<
"No input, create an empty one!";
407 edm::LogError(
"NoInput") <<
"@SUB=SiPixelLorentzAngleCalibration::getLorentzAnglesInput"
424 const std::map<unsigned int,TreeStruct> &treeInfo,
425 const char *treeName)
const
427 if (!lorentzAngle)
return;
431 edm::LogError(
"BadConfig") <<
"@SUB=SiPixelLorentzAngleCalibration::writeTree"
436 TTree *
tree =
new TTree(treeName, treeName);
440 tree->Branch(
"detId", &
id,
"detId/i");
441 tree->Branch(
"value", &value,
"value/F");
447 id = iterIdValue->first;
448 value = iterIdValue->second;
450 auto treeStructIter = treeInfo.find(
id);
451 if (treeStructIter != treeInfo.end()) {
452 treeStruct = treeStructIter->second;
472 FILE* testFile = fopen(fileName,
"r");
475 file = TFile::Open(fileName,
"READ");
479 if (file) file->GetObject(treeName, tree);
485 tree->SetBranchAddress(
"detId", &
id);
486 tree->SetBranchAddress(
"value", &value);
489 const Long64_t nEntries = tree->GetEntries();
490 for (Long64_t iEntry = 0; iEntry < nEntries; ++iEntry) {
491 tree->GetEntry(iEntry);
495 edm::LogWarning(
"Alignment") <<
"@SUB=SiPixelLorentzAngleCalibration::createFromTree"
496 <<
"Could not get TTree '" << treeName <<
"' from file '"
497 << fileName << (file ?
"'." :
"' (file does not exist).");
const std::map< unsigned int, float > & getLorentzAngles() const
virtual bool setParameterError(unsigned int index, double error) override
SiPixelLorentzAngle * siPixelLorentzAngleInput_
const std::string recordNameDBwrite_
std::vector< double > parameters_
edm::RunNumber_t firstRunOfIOV(unsigned int iovNum) const
First run of iov (0 if iovNum not treated).
TkModuleGroupSelector * moduleGroupSelector_
virtual bool setParameter(unsigned int index, double value) override
const std::string outFileName_
virtual unsigned int numParameters() const override
How many parameters does this calibration define?
const std::string & name() const
name of this calibration
const Bounds & bounds() const
bool checkLorentzAngleInput(const edm::EventSetup &setup, const EventInfo &eventInfo)
int getParameterIndexFromDetId(unsigned int detId, edm::RunNumber_t run) const
virtual double getParameter(unsigned int index) const override
const Plane & surface() const
The nominal surface of the GeomDet.
virtual unsigned int derivatives(std::vector< ValuesIndexPair > &outDerivInds, const TransientTrackingRecHit &hit, const TrajectoryStateOnSurface &tsos, const edm::EventSetup &setup, const EventInfo &eventInfo) const override
static std::string const input
void writeTree(const SiPixelLorentzAngle *lorentzAngle, const std::map< unsigned int, TreeStruct > &treeInfo, const char *treeName) const
virtual float thickness() const =0
structure to store algorithm results in a TTree
edm::ESWatcher< SiPixelLorentzAngleRcd > watchLorentzAngleRcd_
unsigned long long Time_t
SiPixelLorentzAngleCalibration(const edm::ParameterSet &cfg)
Constructor.
const GeomDet * det() const
LocalPoint toLocal(const GlobalPoint &gp) const
std::pair< Values, unsigned int > ValuesIndexPair
x- and y-values
virtual double getParameterError(unsigned int index) const override
virtual void endOfJob() override
virtual void beginOfJob(AlignableTracker *tracker, AlignableMuon *muon, AlignableExtras *extras) override
DetId geographicalId() const
The label of this GeomDet.
void writeOne(T *payload, Time_t time, const std::string &recordName, bool withlogging=false)
const edm::EventID & eventId_
bool putLorentzAngle(const uint32_t &, float &)
const SiPixelLorentzAngle * getLorentzAnglesInput()
double getParameterForDetId(unsigned int detId, edm::RunNumber_t run) const
const edm::ParameterSet moduleGroupSelCfg_
virtual ~SiPixelLorentzAngleCalibration()
Destructor.
std::pair< double, double > Values
SiPixelLorentzAngle * createFromTree(const char *fileName, const char *treeName) const
static const char * LeafList()
bool check(const edm::EventSetup &iSetup)
std::vector< double > paramUncertainties_
unsigned int getNumberOfParameters() const
unsigned int numIovs() const
Total number of IOVs.
const std::vector< std::string > mergeFileNames_
#define DEFINE_EDM_PLUGIN(factory, type, name)
Constructor of the full muon geometry.
const PositionType & position() const
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
define event information passed to algorithms