2 #include <unordered_map> 46 theMonitorConfig(
cfg),
47 doTrackHitMonitoring(theMonitorConfig.fillTrackMonitoring || theMonitorConfig.fillTrackHitMonitoring),
48 defaultAlignableSpecs((
Alignable*)nullptr),
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" 101 trackPs =
cfg.getParameter<
bool>(
"UsePreSelection");
103 trackWt =
cfg.getParameter<
bool>(
"UseReweighting");
104 Scale =
cfg.getParameter<
double>(
"Weight");
108 edm::LogWarning(
"Alignment") <<
"@SUB=HIPAlignmentAlgorithm::HIPAlignmentAlgorithm" 109 <<
"Uniform eta formula is empty! Resetting to 1.";
115 SetScanDet =
cfg.getParameter<std::vector<double>>(
"setScanDet");
116 col_cut =
cfg.getParameter<
double>(
"CLAngleCut");
117 cos_cut =
cfg.getParameter<
double>(
"CSAngleCut");
119 edm::LogInfo(
"Alignment") <<
"@SUB=HIPAlignmentAlgorithm::HIPAlignmentAlgorithm" 129 edm::LogInfo(
"Alignment") <<
"@SUB=HIPAlignmentAlgorithm::initialize" 130 <<
"Initializing...";
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();
206 selector.addSelections(selectorPSet);
207 alignables =
selector.selectedAlignables();
210 std::vector<double> apeSPar = setiter->getParameter<std::vector<double>>(
"apeSPar");
211 std::vector<double> apeRPar = setiter->getParameter<std::vector<double>>(
"apeRPar");
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);
221 apeSPar.push_back(0);
223 apeSPar.push_back(1);
225 apeSPar.push_back(2);
228 <<
"APE function must be \"linear\", \"exponential\", or \"step\"." << std::endl;
248 selector.addSelections(selectorPSet);
249 alignables =
selector.selectedAlignables();
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;
518 static const unsigned int hitDim = 1;
533 coor[0] =
hit->localPosition().
x();
536 covmat[0][0] =
hit->localPositionError().xx();
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;
638 coor[0] =
hit->localPosition().
x();
639 coor[1] =
hit->localPosition().
y();
642 covmat[0][0] =
hit->localPositionError().xx();
643 covmat[1][1] =
hit->localPositionError().yy();
644 covmat[0][1] =
hit->localPositionError().xy();
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) {
748 float chi2n =
track->normalizedChi2();
749 int nhit =
track->numberOfValidHits();
753 int nhpxb =
track->hitPattern().numberOfValidPixelBarrelHits();
754 int nhpxf =
track->hitPattern().numberOfValidPixelEndcapHits();
755 int nhtib =
track->hitPattern().numberOfValidStripTIBHits();
756 int nhtob =
track->hitPattern().numberOfValidStripTOBHits();
757 int nhtid =
track->hitPattern().numberOfValidStripTIDHits();
758 int nhtec =
track->hitPattern().numberOfValidStripTECHits();
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) {
823 int subDet =
hit->geographicalId().subdetId();
827 const std::type_info&
type =
typeid(*rechit);
834 myflag = (*
eventInfo.clusterValueMap())[stripclust];
837 <<
"ERROR in <HIPAlignmentAlgorithm::run>: Dynamic cast of Strip RecHit failed! " 845 myflag = (*
eventInfo.clusterValueMap())[stripclust];
848 <<
"ERROR in <HIPAlignmentAlgorithm::run>: Dynamic cast of Strip RecHit failed! " 857 myflag = (*
eventInfo.clusterValueMap())[pixelclust];
860 <<
"ERROR in <HIPAlignmentAlgorithm::run>: Dynamic cast of Pixel RecHit failed! " 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) {
910 double sin_theta = TMath::Abs(mom_z) /
sqrt(
pow(mom_x, 2) +
pow(mom_y, 2) +
pow(mom_z, 2));
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;
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;
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' 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]));
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.";
Log< level::Info, true > LogVerbatim
TTree * theTrackMonitorTree
std::string uniEtaFormula
std::vector< int > m_nhTIB
T getParameter(std::string const &) const
const IOVSyncValue & first() const
AlignmentParameters * alignmentParameters() const
Get the AlignmentParameters.
std::vector< HIPAlignableSpecificParameters > theAlignableSpecifics
HIPAlignableSpecificParameters defaultAlignableSpecs
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
const LocalTrajectoryError & localError() const
const AlignableSurface & surface() const
Return the Surface (global position and orientation) of the object.
AlignmentParameterStore * theAlignmentParameterStore
std::vector< float > m_Eta
LocalPoint localPosition() const
std::vector< float > m_d0
bool usePixelProbXYOrProbQ
static AlignableObjectId commonObjectIdProvider(const AlignableObjectId &, const AlignableObjectId &)
TFile * theAlignablesMonitorIORootFile
void setAlignmentPositionError(const align::Alignables &alivec, double valshift, double valrot)
Set Alignment position error.
HIPAlignableSpecificParameters * findAlignableSpecs(const Alignable *ali)
void run(const edm::EventSetup &setup, const EventInfo &eventInfo) override
Run the algorithm.
TrajectoryStateOnSurface const & forwardPredictedState() const
Access to forward predicted state (from fitter or builder)
void initialize(const edm::EventSetup &setup, AlignableTracker *tracker, AlignableMuon *muon, AlignableExtras *extras, AlignmentParameterStore *store) override
Call at beginning of job.
align::StructureType m2_ObjId
bool hasFilledProb() const
const AlgebraicVector & parameters(void) const
Get alignment parameters.
void writeIterationFile(std::string filename, int iter)
const align::Alignables & alignables(void) const
get all alignables
void applyParameters(void)
Obsolete: Use AlignableNavigator::alignableDetFromDetId and alignableFromAlignableDet.
std::pair< int, int > typeAndLayer(const Alignable *ali, const TrackerTopology *tTopo) const
Obtain type and layer from Alignable.
Log< level::Error, false > LogError
LocalError positionError() const
void attachUserVariables(const align::Alignables &alivec, const std::vector< AlignmentUserVariables *> &uvarvec, int &ierr)
Attach User Variables to given alignables.
TFile * theTrackHitMonitorIORootFile
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
int numSelected(void) const
Get number of selected parameters.
ClusterRef cluster() const
static std::string to_string(const XMLCh *ch)
std::unique_ptr< AlignableNavigator > theAlignableDetAccessor
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)
DataContainer const & measurements() const
HIPUserVariables * clone(void) const override
const bool fillTrackHitMonitoring
std::vector< float > m_Pt
void bookBranches() override
std::vector< int > m_nhPXB
std::vector< float > m_wt
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.
CompositeAlignmentParameters selectParameters(const std::vector< AlignableDet *> &alignabledets) const
std::vector< int > m_nhTID
TTree * theHitMonitorTree
std::vector< float > m_Phi
LocalVector localDirection() const
HIPHitMonitorVariables hitmonitorvars
AlignmentUserVariables * userVariables(void) const
Get pointer to user variables.
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
std::string siterationfile
TrajectoryStateOnSurface const & backwardPredictedState() const
Access to backward predicted state (from smoother)
std::vector< int > m_nhTEC
AlignablePositions readAlignableAbsolutePositions(const align::Alignables &alivec, const char *filename, int iter, int &ierr) override
read Alignable current absolute positions
float probabilityXY() const
int readIterationFile(std::string filename)
std::vector< double > SetScanDet
align::StructureType objId() const
void setAlignmentPositionError(void)
TFile * theSurveyIORootFile
bool isValid(void) const
Get validity flag.
const bool fillTrackMonitoring
unsigned int m_rawQualityWord
void collectMonitorTrees(const std::vector< std::string > &filenames)
double calcAPE(double *par, int iter, int function)
Log< level::Info, false > LogInfo
std::string suvarfilecore
CLHEP::HepVector AlgebraicVector
align::ID id() const
Return the ID of Alignable, i.e. DetId of 'first' component GeomDet(Unit).
static constexpr float d0
void setTree(TTree *tree_)
std::vector< int > m_nhTOB
const PositionType & position() const
void setUserVariables(AlignmentUserVariables *auv)
Set pointer to user variables.
HIPTrackMonitorVariables trackmonitorvars
const std::string outfilecore
SiPixelRecHitQuality::QualWordType rawQualityWord() const
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
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 EventID & eventID() const
const edm::ESGetToken< TrackerTopology, IdealGeometryRecord > topoToken_
align::Alignables theAlignables
virtual void terminate()
Called at end of job (must be implemented in derived class)
std::vector< float > m2_surfDef
HIPMonitorConfig theMonitorConfig
void fillAlignablesMonitor(const edm::EventSetup &setup)
CLHEP::HepSymMatrix AlgebraicSymMatrix
std::string tname(const std::string &tableName, const std::string &schemaVersion)
void startNewLoop(void) override
Called at start of new loop.
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
eventInfo
add run, event number and lumi section
bool processHit1D(const AlignableDetOrUnitPtr &alidet, const Alignable *ali, const HIPAlignableSpecificParameters *alispecifics, const TrajectoryStateOnSurface &tsos, const TrackingRecHit *hit, double hitwt)
Log< level::Warning, false > LogWarning
std::vector< std::pair< align::Alignables, std::vector< double > > > theAPEParameters
Alignable * alignableFromAlignableDet(const AlignableDetOrUnitPtr &adet) const
Get relevant Alignable from AlignableDet.
TTree * theAlignablesMonitorTree
virtual AlignmentParameters * cloneFromSelected(const AlgebraicVector &par, const AlgebraicSymMatrix &cov) const =0
float probabilityQ() const
Constructor of the full muon geometry.
ClusterRef cluster() const
std::vector< align::StructureType > theLevels
std::vector< float > m_Chi2n
TSOS combine(const TSOS &pTsos1, const TSOS &pTsos2) const
Power< A, B >::type pow(const A &a, const B &b)
std::string className(const T &t)
ConstRecHitPointer const & recHit() const
const bool doTrackHitMonitoring
std::string theCollectorPath
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