2 #include <unordered_map>
45 verbose(cfg.getParameter<bool>(
"verbosity")),
46 theMonitorConfig(cfg),
47 doTrackHitMonitoring(theMonitorConfig.fillTrackMonitoring || theMonitorConfig.fillTrackHitMonitoring),
48 defaultAlignableSpecs((
Alignable*)nullptr),
49 surveyResiduals_(cfg.getUntrackedParameter<std::
vector<std::
string>>(
"surveyResiduals")),
50 theTrackHitMonitorIORootFile(nullptr),
51 theTrackMonitorTree(nullptr),
52 theHitMonitorTree(nullptr),
53 theAlignablesMonitorIORootFile(nullptr),
54 theAlignablesMonitorTree(nullptr),
55 theSurveyIORootFile(nullptr),
56 theSurveyTree(nullptr) {
98 edm::LogInfo(
"Alignment") <<
"@SUB=HIPAlignmentAlgorithm::HIPAlignmentAlgorithm"
107 if (uniEtaFormula.empty()) {
108 edm::LogWarning(
"Alignment") <<
"@SUB=HIPAlignmentAlgorithm::HIPAlignmentAlgorithm"
109 <<
"Uniform eta formula is empty! Resetting to 1.";
112 theEtaFormula = std::make_unique<TFormula>(uniEtaFormula.c_str());
119 edm::LogInfo(
"Alignment") <<
"@SUB=HIPAlignmentAlgorithm::HIPAlignmentAlgorithm"
129 edm::LogInfo(
"Alignment") <<
"@SUB=HIPAlignmentAlgorithm::initialize"
130 <<
"Initializing...";
139 unsigned int firstrun = first1.
eventID().
run();
142 bool findMatchIOV =
false;
143 for (
unsigned int iovl = 0; iovl <
theIOVrangeSet.size(); iovl++) {
146 iovapp.append(
".root");
147 iovapp.insert(0,
"_");
157 edm::LogInfo(
"Alignment") <<
"@SUB=HIPAlignmentAlgorithm::initialize"
158 <<
"Found the IOV file matching IOV first run " << firstrun;
164 edm::LogError(
"Alignment") <<
"@SUB=HIPAlignmentAlgorithm::initialize"
165 <<
"Didn't find the IOV file matching IOV first run " << firstrun
166 <<
" from the validity interval";
169 iovapp.append(
".root");
170 iovapp.insert(0,
"_");
178 if (extras !=
nullptr)
179 edm::LogInfo(
"Alignment") <<
"@SUB=HIPAlignmentAlgorithm::initialize"
180 <<
"AlignableNavigator initialized with AlignableExtras";
195 for (std::vector<edm::ParameterSet>::const_iterator setiter =
theAPEParameterSet.begin();
203 if (alignParams.size() == 1 && alignParams[0] ==
std::string(
"selected"))
210 std::vector<double> apeSPar = setiter->getParameter<std::vector<double>>(
"apeSPar");
211 std::vector<double> apeRPar = setiter->getParameter<std::vector<double>>(
"apeRPar");
212 std::string function = setiter->getParameter<std::string>(
"function");
214 if (apeSPar.size() != 3 || apeRPar.size() != 3)
215 throw cms::Exception(
"BadConfig") <<
"apeSPar and apeRPar must have 3 values each" << std::endl;
217 for (std::vector<double>::const_iterator
i = apeRPar.begin();
i != apeRPar.end(); ++
i)
218 apeSPar.push_back(*
i);
220 if (
function == std::string(
"linear"))
221 apeSPar.push_back(0);
222 else if (
function == std::string(
"exponential"))
223 apeSPar.push_back(1);
224 else if (
function == std::string(
"step"))
225 apeSPar.push_back(2);
228 <<
"APE function must be \"linear\", \"exponential\", or \"step\"." << std::endl;
245 if (alignParams.size() == 1 && alignParams[0] ==
std::string(
"selected"))
252 double minRelParError = setiter->getParameter<
double>(
"minRelParError");
253 double maxRelParError = setiter->getParameter<
double>(
"maxRelParError");
254 int minNHits = setiter->getParameter<
int>(
"minNHits");
255 double maxHitPull = setiter->getParameter<
double>(
"maxHitPull");
256 bool applyPixelProbCut = setiter->getParameter<
bool>(
"applyPixelProbCut");
257 bool usePixelProbXYOrProbQ = setiter->getParameter<
bool>(
"usePixelProbXYOrProbQ");
258 double minPixelProbXY = setiter->getParameter<
double>(
"minPixelProbXY");
259 double maxPixelProbXY = setiter->getParameter<
double>(
"maxPixelProbXY");
260 double minPixelProbQ = setiter->getParameter<
double>(
"minPixelProbQ");
261 double maxPixelProbQ = setiter->getParameter<
double>(
"maxPixelProbQ");
262 for (
auto& ali : alignables) {
277 edm::LogInfo(
"Alignment") <<
"@SUB=HIPAlignmentAlgorithm::initialize"
278 <<
"Alignment specifics acquired for detector " << alispecs.
id() <<
" / "
279 << alispecs.
objId() <<
":\n"
282 <<
" - minNHits = " << alispecs.
minNHits <<
"\n"
283 <<
" - maxHitPull = " << alispecs.
maxHitPull <<
"\n"
298 edm::LogInfo(
"Alignment") <<
"@SUB=HIPAlignmentAlgorithm::startNewLoop"
312 int numAlignablesFromFile = theAlignablePositionsFromFile.size();
313 if (numAlignablesFromFile == 0) {
319 edm::LogWarning(
"Alignment") <<
"@SUB=HIPAlignmentAlgorithm::startNewLoop"
320 <<
"IO alignables file not found for iteration " <<
theIteration;
322 edm::LogInfo(
"Alignment") <<
"@SUB=HIPAlignmentAlgorithm::startNewLoop"
323 <<
"Alignables Read " << numAlignablesFromFile;
333 edm::LogWarning(
"Alignment") <<
"@SUB=HIPAlignmentAlgorithm::startNewLoop"
334 <<
"Iteration increased by one and is now " <<
theIteration;
338 edm::LogInfo(
"Alignment") <<
"@SUB=HIPAlignmentAlgorithm::startNewLoop"
339 <<
"Apply positions from file ...";
343 edm::LogWarning(
"Alignment") <<
"@SUB=HIPAlignmentAlgorithm::startNewLoop"
356 edm::LogInfo(
"Alignment") <<
"@SUB=HIPAlignmentAlgorithm::startNewLoop"
366 edm::LogWarning(
"Alignment") <<
"[HIPAlignmentAlgorithm] Using survey constraint";
370 for (
unsigned int i = 0;
i < nAlignable; ++
i) {
374 int nhit = uservar->
nhit;
378 int tmp_Type = tl.first;
379 int tmp_Layer = tl.second;
381 float tmpz = pos.
z();
383 (tmp_Type == 5 && tmp_Layer == 4 && fabs(tmpz) > 90)) {
401 uservar->
jtvj += invCov;
402 uservar->
jtve += invCov * sensResid;
427 <<
", step=" <<
SetScanDet.at(2) <<
", currentDet = " << ali->id();
435 if (dynamic_cast<AlignableDetUnit*>(ali) !=
nullptr) {
436 std::vector<std::pair<int, SurfaceDeformation*>> pairs;
437 ali->surfaceDeformationIdPairs(pairs);
438 edm::LogInfo(
"Alignment") <<
"@SUB=HIPAlignmentAlgorithm::terminate"
439 <<
"The alignable contains " << pairs.size() <<
" surface deformations";
441 edm::LogInfo(
"Alignment") <<
"@SUB=HIPAlignmentAlgorithm::terminate"
442 <<
"The alignable cannot contain surface deformations";
446 ali->alignmentParameters()->setValid(
true);
454 edm::LogWarning(
"Alignment") <<
"[HIPAlignmentAlgorithm::terminate] Aligned units: " << ialigned;
459 edm::LogWarning(
"Alignment") <<
"[HIPAlignmentAlgorithm] Writing aligned parameters to file: " << theAlignables.size()
518 static const unsigned int hitDim = 1;
539 covmat = covmat + ipcovmat;
543 if (covmat[0][0] != 0.)
544 xpull = (pos[0] - coor[0]) /
sqrt(fabs(covmat[0][0]));
553 int npar = derivs2D.num_row();
556 for (
int ipar = 0; ipar < npar; ipar++) {
557 for (
unsigned int idim = 0; idim < hitDim; idim++) {
558 derivs[ipar][idim] = derivs2D[ipar][idim];
566 edm::LogError(
"Alignment") <<
"@SUB=HIPAlignmentAlgorithm::processHit1D"
567 <<
"Cov. matrix inversion failed!";
571 double maxHitPullThreshold =
573 bool useThisHit = (maxHitPullThreshold < 0.);
574 useThisHit |= (fabs(xpull) < maxHitPullThreshold);
576 edm::LogInfo(
"Alignment") <<
"@SUB=HIPAlignmentAlgorithm::processHit2D"
577 <<
"Hit pull (x) " << xpull <<
" fails the cut " << maxHitPullThreshold;
585 thisjtvj.assign(jtvjtmp);
586 thisjtve = derivs * covmat * (pos - coor);
589 hitresidual[0] = (pos[0] - coor[0]);
592 hitresidualT = hitresidual.T();
594 uservar->
jtvj += hitwt * thisjtvj;
595 uservar->
jtve += hitwt * thisjtve;
600 thischi2 = hitwt * (hitresidualT * covmat * hitresidual)[0];
602 if (
verbose && (thischi2 / static_cast<float>(uservar->
nhit)) > 10.)
603 edm::LogWarning(
"Alignment") <<
"[HIPAlignmentAlgorithm::processHit1D] Added to Chi2 the number " << thischi2
604 <<
" having " << uservar->
nhit <<
" ndof"
605 <<
", X-resid " << hitresidual[0] <<
", Cov^-1 matr (covmat):"
606 <<
" [0][0] = " << covmat[0][0];
620 static const unsigned int hitDim = 2;
647 covmat = covmat + ipcovmat;
652 if (covmat[0][0] != 0.)
653 xpull = (pos[0] - coor[0]) /
sqrt(fabs(covmat[0][0]));
654 if (covmat[1][1] != 0.)
655 ypull = (pos[1] - coor[1]) /
sqrt(fabs(covmat[1][1]));
664 int npar = derivs2D.num_row();
667 for (
int ipar = 0; ipar < npar; ipar++) {
668 for (
unsigned int idim = 0; idim < hitDim; idim++) {
669 derivs[ipar][idim] = derivs2D[ipar][idim];
677 edm::LogError(
"Alignment") <<
"@SUB=HIPAlignmentAlgorithm::processHit2D"
678 <<
"Cov. matrix inversion failed!";
682 double maxHitPullThreshold =
684 bool useThisHit = (maxHitPullThreshold < 0.);
685 useThisHit |= (fabs(xpull) < maxHitPullThreshold && fabs(ypull) < maxHitPullThreshold);
687 edm::LogInfo(
"Alignment") <<
"@SUB=HIPAlignmentAlgorithm::processHit2D"
688 <<
"Hit pull (x,y) " << xpull <<
" , " << ypull <<
" fails the cut "
689 << maxHitPullThreshold;
697 thisjtvj.assign(jtvjtmp);
698 thisjtve = derivs * covmat * (pos - coor);
701 hitresidual[0] = (pos[0] - coor[0]);
702 hitresidual[1] = (pos[1] - coor[1]);
705 hitresidualT = hitresidual.T();
707 uservar->
jtvj += hitwt * thisjtvj;
708 uservar->
jtve += hitwt * thisjtve;
713 thischi2 = hitwt * (hitresidualT * covmat * hitresidual)[0];
715 if (
verbose && (thischi2 / static_cast<float>(uservar->
nhit)) > 10.)
716 edm::LogWarning(
"Alignment") <<
"[HIPAlignmentAlgorithm::processHit2D] Added to Chi2 the number " << thischi2
717 <<
" having " << uservar->
nhit <<
" ndof"
718 <<
", X-resid " << hitresidual[0] <<
", Y-resid " << hitresidual[1]
719 <<
", Cov^-1 matr (covmat):"
720 <<
" [0][0] = " << covmat[0][0] <<
" [0][1] = " << covmat[0][1]
721 <<
" [1][0] = " << covmat[1][0] <<
" [1][1] = " << covmat[1][1];
740 for (ConstTrajTrackPairCollection::const_iterator it = tracks.begin(); it != tracks.end(); ++it) {
744 float pt = track->
pt();
747 float p = track->
p();
750 float d0 = track->
d0();
751 float dz = track->
dz();
761 edm::LogInfo(
"Alignment") <<
"New track pt,eta,phi,chi2n,hits: " << pt <<
"," << eta <<
"," << phi <<
"," << chi2n
773 double r = gRandom->Rndm();
798 std::vector<const TransientTrackingRecHit*> hitvec;
799 std::vector<TrajectoryStateOnSurface> tsosvec;
802 std::vector<TrajectoryMeasurement> measurements = traj->
measurements();
803 for (std::vector<TrajectoryMeasurement>::iterator im = measurements.begin(); im != measurements.end(); ++im) {
827 const std::type_info&
type =
typeid(*rechit);
837 <<
"ERROR in <HIPAlignmentAlgorithm::run>: Dynamic cast of Strip RecHit failed! "
838 <<
"TypeId of the RecHit: " <<
className(*hit);
848 <<
"ERROR in <HIPAlignmentAlgorithm::run>: Dynamic cast of Strip RecHit failed! "
849 <<
"TypeId of the TTRH: " <<
className(*hit);
860 <<
"ERROR in <HIPAlignmentAlgorithm::run>: Dynamic cast of Pixel RecHit failed! "
861 <<
"TypeId of the TTRH: " <<
className(*hit);
871 hitvec.push_back(hit);
872 tsosvec.push_back(tsos);
884 std::vector<TrajectoryStateOnSurface>::const_iterator itsos = tsosvec.begin();
885 std::vector<const TransientTrackingRecHit*>::const_iterator ihit = hitvec.begin();
888 while (itsos != tsosvec.end()) {
890 const GeomDet* det = (*ihit)->det();
892 uint32_t nhitDim = (*ihit)->dimension();
899 if (ali !=
nullptr) {
911 double angle = TMath::ASin(sin_theta);
912 double alihitwt = ihitwt;
929 if ((*ihit)->hit() !=
nullptr) {
931 if (pixhit !=
nullptr) {
945 probXYQgood = (probXYgood || probQgood);
947 probXYQgood = (probXYgood && probQgood);
956 bool hitProcessed =
false;
959 hitProcessed =
processHit1D(alidet, ali, alispecifics, tsos, *ihit, alihitwt);
962 hitProcessed =
processHit2D(alidet, ali, alispecifics, tsos, *ihit, alihitwt);
966 <<
"ERROR in <HIPAlignmentAlgorithm::run>: Number of hit dimensions = " << nhitDim
967 <<
" is not supported!" << std::endl;
988 std::ifstream inIterFile(filename.c_str(),
std::ios::in);
990 edm::LogError(
"Alignment") <<
"[HIPAlignmentAlgorithm::readIterationFile] ERROR! "
991 <<
"Unable to open Iteration file";
995 edm::LogWarning(
"Alignment") <<
"[HIPAlignmentAlgorithm::readIterationFile] "
996 <<
"Read last iteration number from file: " <<
result;
1005 std::ofstream outIterFile((filename.c_str()),
std::ios::out);
1007 edm::LogError(
"Alignment") <<
"[HIPAlignmentAlgorithm::writeIterationFile] ERROR: Unable to write Iteration file";
1009 outIterFile << iter;
1010 edm::LogWarning(
"Alignment") <<
"[HIPAlignmentAlgorithm::writeIterationFile] writing iteration number to file: "
1013 outIterFile.close();
1021 edm::LogInfo(
"Alignment") <<
"[HIPAlignmentAlgorithm::setAlignmentPositionError] No APE applied";
1025 edm::LogInfo(
"Alignment") <<
"[HIPAlignmentAlgorithm::setAlignmentPositionError] Apply APE!";
1027 double apeSPar[3], apeRPar[3];
1029 const auto& alignables = alipars.first;
1030 const auto& pars = alipars.second;
1032 apeSPar[0] = pars[0];
1033 apeSPar[1] = pars[1];
1034 apeSPar[2] = pars[2];
1035 apeRPar[0] = pars[3];
1036 apeRPar[1] = pars[4];
1037 apeRPar[2] = pars[5];
1039 int function = pars[6];
1042 printf(
"APE: %u alignables\n", (
unsigned int)alignables.size());
1043 for (
int i = 0;
i < 21; ++
i) {
1044 double apelinstest =
calcAPE(apeSPar,
i, 0);
1045 double apeexpstest =
calcAPE(apeSPar,
i, 1);
1046 double apestepstest =
calcAPE(apeSPar,
i, 2);
1047 double apelinrtest =
calcAPE(apeRPar,
i, 0);
1048 double apeexprtest =
calcAPE(apeRPar,
i, 1);
1049 double apesteprtest =
calcAPE(apeRPar,
i, 2);
1050 printf(
"APE: iter slin sexp sstep rlin rexp rstep: %5d %12.5f %12.5f %12.5f %12.5f %12.5f %12.5f \n",
1070 double diter = (double)iter;
1072 return std::max(par[1], par[0] + ((par[1] - par[0]) / par[2]) * diter);
1073 else if (
function == 1)
1074 return std::max(0., par[0] * (
exp(-
pow(diter, par[1]) / par[2])));
1075 else if (
function == 2) {
1076 int ipar2 = (int)par[2];
1077 int step = iter / ipar2;
1078 double dstep = (double)step;
1079 return std::max(0., par[0] - par[1] * dstep);
1140 edm::LogInfo(
"Alignment") <<
"[HIPAlignmentAlgorithm::bookRoot] Survey trees booked.";
1142 edm::LogInfo(
"Alignment") <<
"[HIPAlignmentAlgorithm::bookRoot] Root trees booked.";
1175 m2_ObjId = ali->alignableObjectId();
1185 std::vector<std::pair<int, SurfaceDeformation*>> dali_id_pairs;
1188 std::vector<double> dali;
1189 if (1 == ali->surfaceDeformationIdPairs(dali_id_pairs)) {
1190 dali_obj = dali_id_pairs[0].second;
1194 for (
auto& dit : dali)
1202 edm::LogVerbatim(
"Alignment") <<
"------------------------------------------------------------------------\n"
1203 <<
" ALIGNABLE: " << setw(6) << naligned <<
'\n'
1204 <<
"hits: " << setw(4) <<
m2_Nhit <<
" type: " << setw(4) <<
m2_Type
1205 <<
" layer: " << setw(4) <<
m2_Layer <<
" id: " << setw(4) <<
m2_Id
1206 <<
" objId: " << setw(4) <<
m2_ObjId <<
'\n'
1207 << std::fixed << std::setprecision(5) <<
"x,y,z: " << setw(12) <<
m2_Xpos
1209 <<
"\nDeformations type, nDeformations: " << setw(12) <<
m2_dtype << setw(12)
1211 <<
"params: " << setw(12) << pars[0] << setw(12) << pars[1] << setw(12) << pars[2]
1212 << setw(12) << pars[3] << setw(12) << pars[4] << setw(12) << pars[5];
1224 edm::LogInfo(
"Alignment") <<
"@SUB=HIPAlignmentAlgorithm::calcParameters"
1225 <<
"Begin: Processing detector " << ali->
id();
1232 int nhit = uservar->
nhit;
1240 minHitThreshold = 1;
1241 if (setDet == 0 && nhit < minHitThreshold) {
1242 edm::LogInfo(
"Alignment") <<
"@SUB=HIPAlignmentAlgorithm::calcParameters"
1243 <<
"Skipping detector " << ali->
id() <<
" because number of hits = " << nhit
1244 <<
" <= " << minHitThreshold;
1253 int npar = jtve.num_row();
1264 edm::LogError(
"Alignment") <<
"@SUB=HIPAlignmentAlgorithm::calcParameters"
1265 <<
"Matrix inversion failed!";
1268 params = -(jtvjinv * jtve);
1271 double minRelErrThreshold =
1273 double maxRelErrThreshold =
1275 for (
int i = 0;
i < npar;
i++) {
1277 if (fabs(cov[
i][
i]) > 0.)
1278 paramerr[
i] =
sqrt(fabs(cov[i][i]));
1280 paramerr[
i] = params[
i];
1281 if (params[i] != 0.)
1282 relerr = fabs(paramerr[i] / params[i]);
1283 if ((maxRelErrThreshold >= 0. && relerr > maxRelErrThreshold) || relerr < minRelErrThreshold) {
1284 edm::LogWarning(
"Alignment") <<
"@SUB=HIPAlignmentAlgorithm::calcParameters"
1285 <<
"RelError = " << relerr <<
" > " << maxRelErrThreshold <<
" or < "
1286 << minRelErrThreshold <<
". Setting param = paramerr = 0 for component " <<
i;
1292 if (params.num_row() != 1) {
1293 edm::LogError(
"Alignment") <<
"@SUB=HIPAlignmentAlgorithm::calcParameters"
1294 <<
"For scanning, please only turn on one parameter! check common_cff_py.txt";
1301 edm::LogWarning(
"Alignment") <<
"@SUB=HIPAlignmentAlgorithm::calcParameters"
1302 <<
"Parameters = " <<
params;
1307 uservar->
alierr = paramerr;
1313 edm::LogInfo(
"Alignment") <<
"@SUB=HIPAlignmentAlgorithm::calcParameters"
1314 <<
"End: Processing detector " << ali->
id();
1321 edm::LogInfo(
"Alignment") <<
"@SUB=HIPAlignmentAlgorithm::collector"
1324 std::vector<std::string> monitorFileList;
1328 std::unordered_map<Alignable*, std::unordered_map<int, pawt_t>> ali_datatypecountpair_map;
1330 edm::LogInfo(
"Alignment") <<
"@SUB=HIPAlignmentAlgorithm::collector"
1331 <<
"Per-alignable reweighting is turned on. Iterating over the parallel jobs to sum "
1332 "number of hits per alignable for each data type.";
1335 edm::LogInfo(
"Alignment") <<
"@SUB=HIPAlignmentAlgorithm::collector"
1336 <<
"Pre-reading uservar for job " << ijob;
1341 std::vector<AlignmentUserVariables*> uvarvec =
1344 edm::LogWarning(
"Alignment") <<
"@SUB=HIPAlignmentAlgorithm::collector"
1346 <<
" is not the same as number of user variables = " << uvarvec.size()
1347 <<
". A mismatch might occur!";
1349 edm::LogError(
"Alignment") <<
"@SUB=HIPAlignmentAlgorithm::collector"
1350 <<
"Could not read user variable files for job " << ijob <<
" in iteration "
1354 std::vector<AlignmentUserVariables*>::const_iterator iuvar =
1360 if (uvar !=
nullptr) {
1362 pawt_t alijobnhits = uvar->
nhit;
1363 if (ali_datatypecountpair_map.find(ali) == ali_datatypecountpair_map.end()) {
1364 std::unordered_map<int, pawt_t> newmap;
1365 ali_datatypecountpair_map[ali] = newmap;
1366 ali_datatypecountpair_map[ali][alijobdtype] = alijobnhits;
1368 std::unordered_map<int, pawt_t>& theMap = ali_datatypecountpair_map[ali];
1369 if (theMap.find(alijobdtype) == theMap.end())
1370 theMap[alijobdtype] = alijobnhits;
1372 theMap[alijobdtype] += alijobnhits;
1382 edm::LogInfo(
"Alignment") <<
"@SUB=HIPAlignmentAlgorithm::collector"
1383 <<
"Reading uservar for job " << ijob;
1388 std::vector<AlignmentUserVariables*> uvarvec =
1391 edm::LogWarning(
"Alignment") <<
"@SUB=HIPAlignmentAlgorithm::collector"
1393 <<
" is not the same as number of user variables = " << uvarvec.size()
1394 <<
". A mismatch might occur!";
1397 edm::LogError(
"Alignment") <<
"@SUB=HIPAlignmentAlgorithm::collector"
1398 <<
"Could not read user variable files for job " << ijob <<
" in iteration "
1404 std::vector<AlignmentUserVariables*> uvarvecadd;
1405 std::vector<AlignmentUserVariables*>::const_iterator iuvarnew = uvarvec.begin();
1416 if (uvarnew !=
nullptr) {
1417 double peraliwgt = 1;
1419 int alijobdtype = uvarnew->
datatype;
1420 if (ali_datatypecountpair_map.find(ali) != ali_datatypecountpair_map.end() &&
1421 ali_datatypecountpair_map[ali].find(alijobdtype) != ali_datatypecountpair_map[ali].end()) {
1422 peraliwgt = ali_datatypecountpair_map[ali][alijobdtype];
1423 unsigned int nNonZeroTypes = 0;
1425 for (
auto it = ali_datatypecountpair_map[ali].cbegin(); it != ali_datatypecountpair_map[ali].cend(); ++it) {
1426 sumwgts += it->second;
1427 if (it->second != pawt_t(0))
1430 edm::LogInfo(
"Alignment") <<
"@SUB=HIPAlignmentAlgorithm::collector"
1431 <<
"Reweighting detector " << ali->id() <<
" / " << ali->alignableObjectId()
1432 <<
" for data type " << alijobdtype <<
" by " << sumwgts <<
"/" << peraliwgt
1433 <<
"/" << nNonZeroTypes;
1434 peraliwgt = ((nNonZeroTypes == 0 || peraliwgt == double(0))
1436 : double((
double(sumwgts)) / peraliwgt / (
double(nNonZeroTypes))));
1437 }
else if (ali_datatypecountpair_map.find(ali) != ali_datatypecountpair_map.end())
1438 edm::LogError(
"Alignment") <<
"@SUB=HIPAlignmentAlgorithm::collector"
1439 <<
"Could not find data type " << alijobdtype <<
" for detector " << ali->id()
1440 <<
" / " << ali->alignableObjectId();
1442 edm::LogError(
"Alignment") <<
"@SUB=HIPAlignmentAlgorithm::collector"
1443 <<
"Could not find detector " << ali->id() <<
" / " << ali->alignableObjectId()
1444 <<
" in the map ali_datatypecountpair_map";
1448 uvar->
jtvj = (uvarold->
jtvj) + peraliwgt * (uvarnew->
jtvj);
1449 uvar->
jtve = (uvarold->
jtve) + peraliwgt * (uvarnew->
jtve);
1456 uvarvecadd.push_back(uvar);
1465 monitorFileList.push_back(uvfile);
1479 throw cms::Exception(
"LogicError") <<
"[HIPAlignmentAlgorithm::collectMonitorTrees] Called in non-collector mode."
1482 TString theTrackMonitorTreeName = Form(
"T1_%i",
theIteration);
1483 TString theHitMonitorTreeName = Form(
"T1_hit_%i",
theIteration);
1485 std::vector<TFile*> finputlist;
1486 TList* eventtrees =
new TList;
1487 TList* hittrees =
new TList;
1489 TFile* finput = TFile::Open(
filename.c_str(),
"read");
1490 if (finput !=
nullptr) {
1494 tmptree = (TTree*)finput->Get(theTrackMonitorTreeName);
1495 if (tmptree !=
nullptr)
1496 eventtrees->Add(tmptree);
1500 tmptree = (TTree*)finput->Get(theHitMonitorTreeName);
1501 if (tmptree !=
nullptr)
1502 hittrees->Add((TTree*)finput->Get(theHitMonitorTreeName));
1504 finputlist.push_back(finput);
1509 edm::LogError(
"Alignment") <<
"@SUB=HIPAlignmentAlgorithm::collectMonitorTrees"
1510 <<
"Monitor file is already open while it is not supposed to be!";
1519 if (eventtrees->GetSize() > 0)
1521 if (hittrees->GetSize() > 0)
1527 for (TFile*& finput : finputlist)
1539 if (ali !=
nullptr) {
1543 if (it->matchAlignable(ali))
1546 edm::LogInfo(
"Alignment") <<
"[HIPAlignmentAlgorithm::findAlignableSpecs] Alignment object with id " << ali->
id()
1547 <<
" / " << ali->
alignableObjectId() <<
" could not be found. Returning default.";
ClusterRef cluster() const
void attachUserVariables(const align::Alignables &alivec, const std::vector< AlignmentUserVariables * > &uvarvec, int &ierr)
Attach User Variables to given alignables.
double p() const
momentum vector magnitude
Log< level::Info, true > LogVerbatim
align::ID id() const
Return the ID of Alignable, i.e. DetId of 'first' component GeomDet(Unit).
TTree * theTrackMonitorTree
std::string uniEtaFormula
bool hasFilledProb() const
std::vector< int > m_nhTIB
std::vector< HIPAlignableSpecificParameters > theAlignableSpecifics
HIPAlignableSpecificParameters defaultAlignableSpecs
ConstRecHitPointer const & recHit() const
double d0() const
dxy parameter in perigee convention (d0 = -dxy)
AlignmentParameterStore * theAlignmentParameterStore
std::vector< float > m_Eta
std::pair< int, int > typeAndLayer(const Alignable *ali, const TrackerTopology *tTopo) const
Obtain type and layer from Alignable.
const EventID & eventID() const
std::vector< float > m_d0
bool usePixelProbXYOrProbQ
double normalizedChi2() const
chi-squared divided by n.d.o.f. (or chi-squared * 1e6 if n.d.o.f. is zero)
static AlignableObjectId commonObjectIdProvider(const AlignableObjectId &, const AlignableObjectId &)
TSOS combine(const TSOS &pTsos1, const TSOS &pTsos2) const
TFile * theAlignablesMonitorIORootFile
void setAlignmentPositionError(const align::Alignables &alivec, double valshift, double valrot)
Set Alignment position error.
LocalVector localDirection() const
LocalPoint localPosition() const
HIPAlignableSpecificParameters * findAlignableSpecs(const Alignable *ali)
void run(const edm::EventSetup &setup, const EventInfo &eventInfo) override
Run the algorithm.
void initialize(const edm::EventSetup &setup, AlignableTracker *tracker, AlignableMuon *muon, AlignableExtras *extras, AlignmentParameterStore *store) override
Call at beginning of job.
align::StructureType m2_ObjId
double phi() const
azimuthal angle of momentum vector
void writeIterationFile(std::string filename, int iter)
void applyParameters(void)
Obsolete: Use AlignableNavigator::alignableDetFromDetId and alignableFromAlignableDet.
auto const & tracks
cannot be loose
Exp< T >::type exp(const T &t)
Log< level::Error, false > LogError
TFile * theTrackHitMonitorIORootFile
Alignable * alignableFromAlignableDet(const AlignableDetOrUnitPtr &adet) const
Get relevant Alignable from AlignableDet.
void applyAlignableAbsolutePositions(const align::Alignables &alis, const AlignablePositions &newpos, int &ierr)
apply absolute positions to alignables
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > topoToken2_
std::vector< int > m_Nhits
LocalError positionError() const
int numberOfValidStripTOBHits() const
AlignmentParameters * alignmentParameters() const
Get the AlignmentParameters.
std::unique_ptr< AlignableNavigator > theAlignableDetAccessor
const ConstTrajTrackPairCollection & trajTrackPairs() const
define event information passed to algorithms
std::vector< unsigned > theIOVrangeSet
void writeHIPUserVariables(const Alignables &alivec, const char *filename, int iter, bool validCheck, int &ierr)
bool calcParameters(Alignable *ali, int setDet, double start, double step)
HIPUserVariables * clone(void) const override
const bool fillTrackHitMonitoring
bool getData(T &iHolder) const
std::vector< float > m_Pt
const AlgebraicVector & parameters(void) const
Get alignment parameters.
void bookBranches() override
DataContainer const & measurements() const
AlignmentUserVariables * userVariables(void) const
Get pointer to user variables.
std::vector< int > m_nhPXB
void clear()
remove all selected Alignables and geometrical restrictions
std::vector< float > m_wt
double eta() const
pseudorapidity of momentum vector
int numberOfValidPixelBarrelHits() const
static constexpr int verbose
std::vector< AlignmentUserVariables * > readHIPUserVariables(const Alignables &alivec, const char *filename, int iter, int &ierr)
void setAlignmentParameters(AlignmentParameters *dap)
Set the AlignmentParameters.
CLHEP::HepMatrix AlgebraicMatrix
std::vector< edm::ParameterSet > theCutsPerComponent
void setValid(bool v)
Set validity flag.
std::vector< int > m_nhTID
TTree * theHitMonitorTree
double pt() const
track transverse momentum
printf("params %d %f %f %f\n", minT, eps, errmax, chi2max)
std::vector< float > m_Phi
HIPHitMonitorVariables hitmonitorvars
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
std::string siterationfile
std::vector< int > m_nhTEC
AlignablePositions readAlignableAbsolutePositions(const align::Alignables &alivec, const char *filename, int iter, int &ierr) override
read Alignable current absolute positions
int numberOfValidStripTIDHits() const
ClusterRef cluster() const
int readIterationFile(std::string filename)
unsigned short numberOfValidHits() const
number of valid hits found
int numberOfValidStripTECHits() const
std::vector< double > SetScanDet
const LocalTrajectoryError & localError() const
void setAlignmentPositionError(void)
TFile * theSurveyIORootFile
const bool fillTrackMonitoring
unsigned int m_rawQualityWord
const AlignableSurface & surface() const
Return the Surface (global position and orientation) of the object.
TrajectoryStateOnSurface const & forwardPredictedState() const
Access to forward predicted state (from fitter or builder)
void collectMonitorTrees(const std::vector< std::string > &filenames)
double dz() const
dz parameter (= dsz/cos(lambda)). This is the track z0 w.r.t (0,0,0) only if the refPoint is close to...
double calcAPE(double *par, int iter, int function)
Log< level::Info, false > LogInfo
const align::Alignables & selectedAlignables() const
vector of alignables selected so far
std::string suvarfilecore
int numSelected(void) const
Get number of selected parameters.
virtual TrackingRecHit const * hit() const
CLHEP::HepVector AlgebraicVector
static constexpr float d0
void setTree(TTree *tree_)
std::vector< int > m_nhTOB
void setUserVariables(AlignmentUserVariables *auv)
Set pointer to user variables.
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
HIPTrackMonitorVariables trackmonitorvars
const std::string outfilecore
virtual LocalError localPositionError() const =0
align::StructureType objId() const
ClusterRef cluster() const
CompositeAlignmentParameters selectParameters(const std::vector< AlignableDet * > &alignabledets) const
T getParameter(std::string const &) const
AlgebraicSymMatrix inverseCovariance() const
Get inverse of survey covariance wrt given structure type in constructor.
bool theApplyCutsPerComponent
std::unique_ptr< AlignableObjectId > alignableObjectId_
void writeAlignableAbsolutePositions(const align::Alignables &alivec, const char *filename, int iter, bool validCheck, int &ierr) override
write Alignable current absolute positions
void bookBranches() override
std::string smisalignedfile
int numberOfValidStripTIBHits() const
HIPAlignmentAlgorithm(const edm::ParameterSet &cfg, edm::ConsumesCollector &iC)
Constructor.
std::vector< edm::ParameterSet > theAPEParameterSet
align::StructureType m3_ObjId
std::unique_ptr< TFormula > theEtaFormula
std::vector< Alignable * > Alignables
const edm::ESGetToken< TrackerTopology, IdealGeometryRecord > topoToken_
int numberOfValidPixelEndcapHits() const
align::Alignables theAlignables
virtual void terminate()
Called at end of job (must be implemented in derived class)
AlgebraicVector sensorResidual() const
std::vector< float > m2_surfDef
const AliClusterValueMap * clusterValueMap() const
HIPMonitorConfig theMonitorConfig
float probabilityXY() const
void fillAlignablesMonitor(const edm::EventSetup &setup)
bool isValid(void) const
Get validity flag.
CLHEP::HepSymMatrix AlgebraicSymMatrix
std::string tname(const std::string &tableName, const std::string &schemaVersion)
void startNewLoop(void) override
Called at start of new loop.
unsigned int addSelections(const edm::ParameterSet &pSet)
const std::vector< std::string > surveyResiduals_
std::vector< int > m_nhPXF
std::vector< AlignableAbsData > AlignablePositions
bool processHit2D(const AlignableDetOrUnitPtr &alidet, const Alignable *ali, const HIPAlignableSpecificParameters *alispecifics, const TrajectoryStateOnSurface &tsos, const TrackingRecHit *hit, double hitwt)
std::vector< float > m_dz
DetId geographicalId() const
bool processHit1D(const AlignableDetOrUnitPtr &alidet, const Alignable *ali, const HIPAlignableSpecificParameters *alispecifics, const TrajectoryStateOnSurface &tsos, const TrackingRecHit *hit, double hitwt)
const IOVSyncValue & first() const
Log< level::Warning, false > LogWarning
std::vector< std::pair< align::Alignables, std::vector< double > > > theAPEParameters
TTree * theAlignablesMonitorTree
virtual AlignmentParameters * cloneFromSelected(const AlgebraicVector &par, const AlgebraicSymMatrix &cov) const =0
Constructor of the full muon geometry.
virtual LocalPoint localPosition() const =0
const PositionType & position() const
std::vector< align::StructureType > theLevels
SiPixelRecHitQuality::QualWordType rawQualityWord() const
std::vector< float > m_Chi2n
float probabilityQ() const
Power< A, B >::type pow(const A &a, const B &b)
const align::Alignables & alignables(void) const
get all alignables
std::string className(const T &t)
const bool doTrackHitMonitoring
TrajectoryStateOnSurface const & backwardPredictedState() const
Access to backward predicted state (from smoother)
std::string theCollectorPath
virtual AlgebraicMatrix selectedDerivatives(const TrajectoryStateOnSurface &tsos, const AlignableDetOrUnitPtr &alidet) const
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
SurfaceDeformationFactory::Type m2_dtype
std::vector< ConstTrajTrackPair > ConstTrajTrackPairCollection
std::string sparameterfile