CMS 3D CMS Logo

AlignmentParametersIORoot.cc

Go to the documentation of this file.
00001 // this class's header
00002 #include "Alignment/CommonAlignmentAlgorithm/interface/AlignmentParametersIORoot.h"
00003 
00004 #include "TTree.h"
00005 
00006 #include "Alignment/CommonAlignment/interface/Alignable.h" 
00007 #include "Alignment/CommonAlignmentParametrization/interface/RigidBodyAlignmentParameters.h"
00008 
00009 // ----------------------------------------------------------------------------
00010 // constructor
00011 
00012 AlignmentParametersIORoot::AlignmentParametersIORoot()
00013 {
00014   treename = "AlignmentParameters";
00015   treetxt = "Alignment Parameters";
00016 }
00017 
00018 // ----------------------------------------------------------------------------
00019 
00020 void AlignmentParametersIORoot::createBranches(void) 
00021 {
00022   tree->Branch("parSize",   &theCovRang,   "CovRang/I");
00023   tree->Branch("Id",        &theId,        "Id/i");
00024   tree->Branch("Par",       &thePar,       "Par[CovRang]/D");
00025   tree->Branch("covarSize", &theCovarRang, "CovarRang/I");
00026   tree->Branch("Cov",       &theCov,       "Cov[CovarRang]/D");
00027   tree->Branch("ObjId",     &theObjId,     "ObjId/I");
00028   tree->Branch("HieraLevel",&theHieraLevel,"HieraLevel/I");
00029 }
00030 
00031 // ----------------------------------------------------------------------------
00032 
00033 void AlignmentParametersIORoot::setBranchAddresses(void) 
00034 {
00035   tree->SetBranchAddress("parSize",   &theCovRang);
00036   tree->SetBranchAddress("covarSize", &theCovarRang);
00037   tree->SetBranchAddress("Id",        &theId);
00038   tree->SetBranchAddress("Par",       &thePar);
00039   tree->SetBranchAddress("Cov",       &theCov);
00040   tree->SetBranchAddress("ObjId",     &theObjId);
00041   tree->SetBranchAddress("HieraLevel",&theHieraLevel);
00042 }
00043 
00044 // ----------------------------------------------------------------------------
00045 
00046 int AlignmentParametersIORoot::findEntry(align::ID id, align::StructureType comp)
00047 {
00048   double noAliPar = tree->GetEntries();
00049   for (int ev = 0;ev<noAliPar;ev++) {
00050     tree->GetEntry(ev); 
00051     if ( theId==id && theObjId==comp ) return (ev);
00052   }
00053   return -1;
00054 }
00055 
00056 // ----------------------------------------------------------------------------
00057 int AlignmentParametersIORoot::writeOne(Alignable* ali)
00058 {
00059   const AlignmentParameters* ap =ali->alignmentParameters();
00060   const AlgebraicVector& params = ap->parameters();
00061   const AlgebraicSymMatrix& cov = ap->covariance();
00062 
00063   theCovRang   = params.num_row();
00064   theCovarRang = theCovRang*(theCovRang+1)/2;
00065   int count=0;
00066   for(int row=0;row<theCovRang;row++){
00067     thePar[row]=params[row];
00068     for(int col=0;col<theCovRang;col++){
00069       if(row-1<col) { theCov[count] = cov[row][col]; count++; }
00070     }
00071   }
00072 
00073   theId = ali->id();
00074   theObjId = ali->alignableObjectId();
00075   theHieraLevel = ap->hierarchyLevel();
00076 
00077   tree->Fill();
00078   return 0;
00079 }
00080 
00081 // ----------------------------------------------------------------------------
00082 
00083 AlignmentParameters* AlignmentParametersIORoot::readOne( Alignable* ali, int& ierr )
00084 {
00085   
00086   AlignmentParameters* alipar = 0;
00087   AlgebraicVector par(nParMax,0);
00088   AlgebraicSymMatrix cov(nParMax,0);
00089   const std::vector<bool> &sel = ali->alignmentParameters()->selector();
00090  
00091   int entry = findEntry( ali->id(), ali->alignableObjectId() );
00092   if( entry != -1 ) 
00093         {
00094           tree->GetEntry(entry);
00095           int covsize = theCovRang;
00096           int count=0;
00097           for(int row=0;row<covsize;row++) 
00098                 {
00099                   par[row]=thePar[row];
00100                   for(int col=0; col < covsize;col++) {
00101                         if(row-1<col) {cov[row][col]=theCov[count];count++;}
00102                   }
00103                 } 
00104           // FIXME: In future should check which kind of parameters to construct...
00105           alipar = new RigidBodyAlignmentParameters(ali,par,cov,sel);
00106           alipar->setValid(true); 
00107           ierr=0;
00108           return alipar;
00109         }
00110 
00111   ierr=-1;
00112   return(0);
00113 }

Generated on Tue Jun 9 17:23:47 2009 for CMSSW by  doxygen 1.5.4