Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:56:10

0001 // this class's header
0002 #include "Alignment/CommonAlignmentAlgorithm/interface/AlignmentParametersIORoot.h"
0003 
0004 #include "Alignment/CommonAlignment/interface/Alignable.h"
0005 #include "Alignment/CommonAlignment/interface/AlignmentParameters.h"
0006 #include "Alignment/CommonAlignmentParametrization/interface/AlignmentParametersFactory.h"
0007 
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 
0010 #include "TTree.h"
0011 
0012 // ----------------------------------------------------------------------------
0013 // constructor
0014 AlignmentParametersIORoot::AlignmentParametersIORoot() {
0015   treename = "AlignmentParameters";
0016   treetxt = "Alignment Parameters";
0017 }
0018 
0019 // ----------------------------------------------------------------------------
0020 void AlignmentParametersIORoot::createBranches(void) {
0021   tree->Branch("parSize", &theCovRang, "CovRang/I");
0022   tree->Branch("Id", &theId, "Id/i");
0023   tree->Branch("paramType", &theParamType, "paramType/I");
0024   tree->Branch("Par", &thePar, "Par[CovRang]/D");
0025   tree->Branch("covarSize", &theCovarRang, "CovarRang/I");
0026   tree->Branch("Cov", &theCov, "Cov[CovarRang]/D");
0027   tree->Branch("ObjId", &theObjId, "ObjId/I");
0028   tree->Branch("HieraLevel", &theHieraLevel, "HieraLevel/I");
0029 }
0030 
0031 // ----------------------------------------------------------------------------
0032 void AlignmentParametersIORoot::setBranchAddresses(void) {
0033   tree->SetBranchAddress("parSize", &theCovRang);
0034   tree->SetBranchAddress("covarSize", &theCovarRang);
0035   tree->SetBranchAddress("Id", &theId);
0036   tree->SetBranchAddress("Par", &thePar);
0037   tree->SetBranchAddress("paramType", &theParamType);
0038   tree->SetBranchAddress("Cov", &theCov);
0039   tree->SetBranchAddress("ObjId", &theObjId);
0040   tree->SetBranchAddress("HieraLevel", &theHieraLevel);
0041 }
0042 
0043 // ----------------------------------------------------------------------------
0044 int AlignmentParametersIORoot::writeOne(Alignable* ali) {
0045   const AlignmentParameters* ap = ali->alignmentParameters();
0046   const AlgebraicVector& params = ap->parameters();
0047   const AlgebraicSymMatrix& cov = ap->covariance();
0048 
0049   theCovRang = params.num_row();
0050   theCovarRang = theCovRang * (theCovRang + 1) / 2;
0051   int count = 0;
0052   for (int row = 0; row < theCovRang; row++) {
0053     thePar[row] = params[row];
0054     for (int col = 0; col < theCovRang; col++) {
0055       if (row - 1 < col) {
0056         theCov[count] = cov[row][col];
0057         count++;
0058       }
0059     }
0060   }
0061 
0062   theId = ali->id();
0063   theParamType = ap->type();
0064   theObjId = ali->alignableObjectId();
0065   theHieraLevel = ap->hierarchyLevel();
0066 
0067   tree->Fill();
0068   return 0;
0069 }
0070 
0071 // ----------------------------------------------------------------------------
0072 AlignmentParameters* AlignmentParametersIORoot::readOne(Alignable* ali, int& ierr) {
0073   if (tree->GetEntryWithIndex(ali->id(), ali->alignableObjectId()) > 0) {
0074     int covsize = theCovRang;
0075     int count = 0;
0076     AlgebraicVector par(covsize, 0);
0077     AlgebraicSymMatrix cov(covsize, 0);
0078     for (int row = 0; row < covsize; row++) {
0079       par[row] = thePar[row];
0080       for (int col = 0; col < covsize; col++) {
0081         if (row - 1 < col) {
0082           cov[row][col] = theCov[count];
0083           count++;
0084         }
0085       }
0086     }
0087 
0088     using namespace AlignmentParametersFactory;
0089     ParametersType parType = parametersType(theParamType);
0090     AlignmentParameters* alipar1;
0091     if (ali->alignmentParameters()) {
0092       const std::vector<bool>& sel = ali->alignmentParameters()->selector();
0093       alipar1 = createParameters(ali, parType, sel);
0094     } else {
0095       const std::vector<bool> sel(theCovRang, true);
0096       alipar1 = createParameters(ali, parType, sel);
0097     }
0098     AlignmentParameters* alipar = alipar1->clone(par, cov);
0099     alipar->setValid(true);
0100     ierr = 0;
0101     delete alipar1;
0102     return alipar;
0103   }
0104 
0105   ierr = -1;
0106   return (nullptr);
0107 }
0108 
0109 int AlignmentParametersIORoot::close() {
0110   if (bWrite) {
0111     int nIndices = tree->BuildIndex("Id", "ObjId");
0112     edm::LogInfo("Alignment") << "@SUB=AlignmentParametersIORoot::setBranchAddresses"
0113                               << "number of indexed entries: " << nIndices;
0114   }
0115 
0116   return closeRoot();
0117 }