CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/Alignment/MillePedeAlignmentAlgorithm/macros/MillePedeTrees.h

Go to the documentation of this file.
00001 // Original Author: Gero Flucke
00002 // last change    : $Date: 2010/10/26 21:34:25 $
00003 // by             : $Author: flucke $
00004 
00005 #ifndef MILLEPEDETREES_H
00006 #define MILLEPEDETREES_H
00007 
00008 #include "TString.h"
00009 
00010 class TTree;
00011 class TGraph;
00012 class TH1;
00013 class TH2;
00014 class TProfile;
00015 
00016 class MillePedeTrees
00017 {
00018  public:
00019   explicit MillePedeTrees(const char *fileName, Int_t iter = 1, const char *treeNameAdd = "");
00020   virtual ~MillePedeTrees();
00021 
00022   TH1* Draw(const char *exp, const char *selection, const char *hDef = "", Option_t *opt = "");
00023   TH1* CreateHist(const char *exp, const char *select, const char *hDef = "", Option_t *opt = "");
00024   TH2* CreateHist2D(const char *expX, const char *expY, const char *select,
00025                     const char *hDef = "", Option_t *opt = "");
00026   TProfile* CreateHistProf(const char *expX, const char *expY, const char *select,
00027                            const char *hDef = "", Option_t *opt = "");
00028   TGraph* CreateGraph(const char *expX, const char *expY, const char *select, Option_t *option="");
00029 
00030 /*   void ScanDiffAbove(UInt_t iPar, float absDiff); */
00031 
00032   // values: absolute positions and orientations; need a 'position tree' as argument or in front
00033   TString Pos() const { return "Pos";}
00034   TString Pos(UInt_t ui) const { return Pos() += Bracket(ui);}
00035   TString XPos() const { return Pos(0);}
00036   TString YPos() const { return Pos(1);}
00037   TString ZPos() const { return Pos(2);}
00038   TString RPos2(const TString &tree) const; // x^2+y^2
00039 /*   TString RPos(const TString &tree) const { return Sqrt(RPos2(tree));} // sqrt(x^2+y^2) */
00040   TString RPos(const TString &tree) const; // sqrt(x^2+y^2) - y-sign if selected by UseSignedR()
00041   // (un)set whether RPos should be signed like y, return old setting
00042   bool SetUseSignedR(bool use = true) {bool buf = fUseSignedR; fUseSignedR = use; return buf;}//true: radius gets sign of y
00043   bool SetBowsParameters(bool use = true) {bool buf = fBowsParameters; fBowsParameters = use; return buf;}//true: bows param. for pede
00044 
00045   TString Phi(const TString &tree) const;
00046   TString OrgPos(const TString &pos) const; // pos x, y, z, r, phi,... on original position
00047 
00048   TString PhiSwaps(double swapAround, const TString &tree1, const TString &tree2) const;
00049   TString Theta(const TString &tree) const;
00050   TString Alpha(const TString &tree, bool betaMpiPpi) const;
00051   TString Beta (const TString &tree, bool betaMpiPpi) const;
00052   TString Gamma(const TString &tree, bool betaMpiPpi) const;
00053 
00054   // values: alignment parameters; need a 'parameter tree' or MpT() as argument or in front
00055   TString Par() const { return "Par";}
00056   TString Par(UInt_t ui) const { return Par() += Bracket(ui);}
00057   TString XPar() const { return Par(0);}
00058   TString YPar() const { return Par(1);}
00059   TString ZPar() const { return Par(2);}
00060   TString Alpha() const { return Par(3);}
00061   TString Beta() const { return Par(4);}
00062   TString Gamma() const { return Par(5);}
00063   TString DiffPar(const TString &t1, const TString &t2, UInt_t iPar) const {
00064     return Parenth(t1 + Par(iPar) += Min() += t2 + Par(iPar));}
00065   // values: alignment parameter errors from parameter tree (to be given as tree name)
00066   TString ParSi(const TString &tree, UInt_t ui) const;
00067   TString XParSi(const TString &tree) const  { return ParSi(tree, 0);}
00068   TString YParSi(const TString &tree) const { return ParSi(tree, 1);}
00069   TString ZParSi(const TString &tree) const { return ParSi(tree, 2);}
00070   TString AlphaSi(const TString &tree) const { return ParSi(tree, 3);}
00071   TString BetaSi(const TString &tree) const { return ParSi(tree, 4);}
00072   TString GammaSi(const TString &tree) const { return ParSi(tree, 5);}
00073 
00074   // values: Delta positions
00075   TString DelPos(UInt_t ui, const TString &tree1, const TString &tree2) const;
00076   TString DelR(const TString &tree1, const TString &tree2) const;
00077   TString DelRphi(const TString &tree1, const TString &tree2) const;
00078   // TString DelRphi_b(const TString &tree1, const TString &tree2) const; // version b
00079   TString DelPhi(const TString &tree1, const TString &tree2) const;
00080   // values: Delta positions wrt. OrgPosT()
00081   TString DelPos(UInt_t ui, const TString &tree) const { return DelPos(ui, tree, OrgPosT());}
00082   TString DelR(const TString &tree) const { return DelR(tree, OrgPosT());}
00083   TString DelRphi(const TString &tree) const { return DelRphi(tree, OrgPosT());}
00084   TString DelPhi(const TString &tree) const { return DelPhi(tree, OrgPosT());}
00085   // see also TString DeltaPos(const TString &pos, const TString &tree) const;
00086   
00087   // '25' and '0x7' DataFormats/DetId/interface/DetId.h:
00088   TString SubDetId() const { return "(" + OrgPosT() += "Id>>25)&0x7";}
00089   TString AlignableTypeId() const { return OrgPosT() += "ObjId";}
00090   TString HieraLev(const TString &tree, Int_t level) const {
00091     return Parenth(tree + "HieraLevel==" + Int(level));}
00092   TString HieraLev(Int_t level) const {return HieraLev(ParT(), level);}
00093   // values: from pede, do not add tree in front
00094   TString Valid(UInt_t iParam) const;
00095   TString Fixed(UInt_t iParam, bool isFixed = true) const;
00096   TString AnyFreePar() const;
00097   TString Label(UInt_t iParam) const;
00098   TString Cor(UInt_t iParam) const;
00099   TString Diff(UInt_t iParam) const;
00100   TString PreSi(UInt_t iParam) const;
00101   TString ParSi(UInt_t iParam) const;
00102   TString ParSiOk(UInt_t iParam) const;
00103   TString XParSi() const  { return ParSi(0);}
00104   TString YParSi() const { return ParSi(1);}
00105   TString ZParSi() const { return ParSi(2);}
00106   TString AlphaSi() const { return ParSi(3);}
00107   TString BetaSi() const { return ParSi(4);}
00108   TString GammaSi() const { return ParSi(5);}
00109   TString HitsX() const { return MpT() += "HitsX";}
00110   TString HitsY() const { return MpT() += "HitsY";}
00111 
00112   // symbols
00113   TString Dot() const { return ".";}
00114   TString Plu() const { return "+";}
00115   TString Min() const { return "-";}
00116   TString Mal() const { return "*";} // fixme? german...
00117   TString Div() const { return "/";}
00118   TString AndL() const {return "&&";} // logical and (not '&')
00119   TString OrL() const {return "||";}  // logical or (not '|')
00120   // numbers
00121   TString Int(Int_t i) const { return Form("%d", i);}
00122   TString Int(UInt_t ui) const { return Form("%u", ui);}
00123   TString Flt(Float_t f) const { return Form("%f", f);}
00124   // brackets and parentheses
00125   TString Bra() const { return "[";}
00126   TString Ket() const { return "]";}
00127   TString Bracket(UInt_t ui) const { return Bra() += Int(ui) += Ket();}
00128   TString Bracket(Int_t i) const { return Bra() += Int(i) += Ket();}
00129   TString Bracket(const char *s) const { return (Bra() += s) += Ket();}
00130   TString Paren() const { return "(";}
00131   TString Thesis() const { return ")";}
00132   TString Parenth(const char *s) const { return (Paren() += s) += Thesis();}
00133   TString Abs(const char *s) const {return Fun("TMath::Abs", s);}
00134   // functions
00135   TString Fun(const char *fun, const char *s) const { return fun + Parenth(s);}
00136   TString Sqrt(const char *s) const { return Fun("sqrt", s);}
00137 
00138   // units and names for params
00139   TString ToMumMuRad(UInt_t iParam) const { return (iParam < 3 ? "*10000" : "*1000000");}
00140   TString ToMumMuRadPede(UInt_t iParam) const;
00141   TString Name(UInt_t iParam) const;
00142   TString NamePede(UInt_t iParam) const;
00143   TString DelName(UInt_t iParam) const { return "#Delta"+Name(iParam);}
00144   TString DelNameU(UInt_t iParam) const { return DelName(iParam) += Unit(iParam);}
00145   TString Unit(UInt_t iParam) const { return (iParam < 3 
00146                                               ? " [#mum]" 
00147                                               : (iParam < kNpar ? " [#murad]" : ""));}
00148   TString UnitPede(UInt_t iParam) const;
00149   // units and names for position strings (r, rphi, phi, x, y, z)
00150   TString ToMumMuRad(const TString &pos) const;
00151   TString Name(const TString &pos) const;
00152   TString DelName(const TString &pos) const;// { return "#Delta"+Name(pos);}
00153   TString DelNameU(const TString &pos) const { return DelName(pos) += Unit(pos);}
00154   TString Unit(const TString &pos) const;
00155 
00156   TString DeltaPos(const TString &pos, const TString &tree /* = PosT()*/) const;// delta position to OrgPosT, depending on pos DelPhi,DelRphi,DelPos(0,..) etc.
00157   TString SelIs1D() const;
00158   TString SelIs2D() const;
00159 
00160   // tree names
00161   TString OrgPosT() const { return fOrgPos + Dot();} // nominal global positions
00162   TString MisPosT() const { return fMisPos + Dot();} // misaligned global positions
00163   TString MisRelPosT() const { return fMisRelPos + Dot();} // misaligned
00164   TString MisParT() const { return fMisPar + Dot();} // misalignment
00165   TString PosT() const { return fPos + Dot();} // aligned global positions
00166   TString RelPosT() const { return fRelPos + Dot();} // aligned
00167   TString ParT() const { return fPar + Dot();} // remaining misalignment
00168   TString MpT() const { return fMp + Dot();} // MP tree (parameter, hits,...)
00169 
00170   TTree* GetMainTree() {return fTree;} // use with care...
00171 
00172   enum {kLocX = 0, kLocY, kLocZ, kNpar = 6}; // number of parameters we have...
00173  protected:
00174 
00175  private: 
00176   MillePedeTrees();
00177   // utils
00178   TTree* CreateTree(const char *fileName, const TString &treeNameAdd);
00179 /*   TString RemoveHistName(TString &option) const; */
00180 
00181   // data members
00182   TTree   *fTree;
00183 
00184   // tree names
00185   TString fOrgPos;    // absolute original positions from xml
00186   TString fMisPos;    // absolute positions with misalignment applied
00187   TString fMisRelPos; // relative positions with misalignment applied (to abs. orig.?)
00188   TString fMisPar;    // misalignment parameters
00189   TString fPos;       // positions after alignment
00190   TString fRelPos;    // relative positions  after alignment (to abs. orig.?)
00191   TString fPar;       // remaining misalign paramters after alignment (was: alignment parameters)
00192   TString fMp;        // specials for/from MillePede
00193 
00194   // special seetings
00195   bool fUseSignedR;  // if true, Rpos will have sign of y
00196   bool fBowsParameters; //true: pede parameter names and titles to 'bows', false: rigid body
00197 };
00198 #endif