CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/Alignment/MillePedeAlignmentAlgorithm/macros/MillePedeTrees.h

Go to the documentation of this file.
00001 // Original Author: Gero Flucke
00002 // last change    : $Date: 2011/02/11 10:49:02 $
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   TString DeformValue(UInt_t i, const TString &whichOne) const;//start,result,diff
00112   TString NumDeformValues(const TString &whichOne) const; //start,result,diff
00113 
00114   // symbols
00115   TString Dot() const { return ".";}
00116   TString Plu() const { return "+";}
00117   TString Min() const { return "-";}
00118   TString Mal() const { return "*";} // fixme? german...
00119   TString Div() const { return "/";}
00120   TString AndL() const {return "&&";} // logical and (not '&')
00121   TString OrL() const {return "||";}  // logical or (not '|')
00122   // numbers
00123   TString Int(Int_t i) const { return Form("%d", i);}
00124   TString Int(UInt_t ui) const { return Form("%u", ui);}
00125   TString Flt(Float_t f) const { return Form("%f", f);}
00126   // brackets and parentheses
00127   TString Bra() const { return "[";}
00128   TString Ket() const { return "]";}
00129   TString Bracket(UInt_t ui) const { return Bra() += Int(ui) += Ket();}
00130   TString Bracket(Int_t i) const { return Bra() += Int(i) += Ket();}
00131   TString Bracket(const char *s) const { return (Bra() += s) += Ket();}
00132   TString Paren() const { return "(";}
00133   TString Thesis() const { return ")";}
00134   TString Parenth(const char *s) const { return (Paren() += s) += Thesis();}
00135   TString Abs(const char *s) const {return Fun("TMath::Abs", s);}
00136   // functions
00137   TString Fun(const char *fun, const char *s) const { return fun + Parenth(s);}
00138   TString Sqrt(const char *s) const { return Fun("sqrt", s);}
00139 
00140   // units and names for params
00141   TString ToMumMuRad(UInt_t iParam) const { return (iParam < 3 ? "*10000" : "*1000000");}
00142   TString ToMumMuRadPede(UInt_t iParam) const;
00143   TString ToMumMuRadSurfDef(UInt_t iParam) const;
00144   TString Name(UInt_t iParam) const;
00145   TString NamePede(UInt_t iParam) const;
00146   TString NameSurfDef(UInt_t iParam) const;
00147   TString DelName(UInt_t iParam) const { return "#Delta"+Name(iParam);}
00148   TString DelNameU(UInt_t iParam) const { return DelName(iParam) += Unit(iParam);}
00149   TString Unit(UInt_t iParam) const { return (iParam < 3 
00150                                               ? " [#mum]" 
00151                                               : (iParam < kNpar ? " [#murad]" : ""));}
00152   TString UnitPede(UInt_t iParam) const;
00153   TString UnitSurfDef(UInt_t iParam) const;
00154   // units and names for position strings (r, rphi, phi, x, y, z)
00155   TString ToMumMuRad(const TString &pos) const;
00156   TString Name(const TString &pos) const;
00157   TString DelName(const TString &pos) const;// { return "#Delta"+Name(pos);}
00158   TString DelNameU(const TString &pos) const { return DelName(pos) += Unit(pos);}
00159   TString Unit(const TString &pos) const;
00160 
00161   TString DeltaPos(const TString &pos, const TString &tree /* = PosT()*/) const;// delta position to OrgPosT, depending on pos DelPhi,DelRphi,DelPos(0,..) etc.
00162   TString SelIs1D() const;
00163   TString SelIs2D() const;
00164 
00165   // tree names
00166   TString OrgPosT() const { return fOrgPos + Dot();} // nominal global positions
00167   TString MisPosT() const { return fMisPos + Dot();} // misaligned global positions
00168   TString MisRelPosT() const { return fMisRelPos + Dot();} // misaligned
00169   TString MisParT() const { return fMisPar + Dot();} // misalignment
00170   TString PosT() const { return fPos + Dot();} // aligned global positions
00171   TString RelPosT() const { return fRelPos + Dot();} // aligned
00172   TString ParT() const { return fPar + Dot();} // remaining misalignment
00173   TString MpT() const { return fMp + Dot();} // MP tree (parameter, hits,...)
00174 
00175   TTree* GetMainTree() {return fTree;} // use with care...
00176 
00177   enum {kLocX = 0, kLocY, kLocZ, kNpar = 6}; // number of parameters we have...
00178  protected:
00179 
00180  private: 
00181   MillePedeTrees();
00182   // utils
00183   TTree* CreateTree(const char *fileName, const TString &treeNameAdd);
00184 /*   TString RemoveHistName(TString &option) const; */
00185 
00186   // data members
00187   TTree   *fTree;
00188 
00189   // tree names
00190   TString fOrgPos;    // absolute original positions from xml
00191   TString fMisPos;    // absolute positions with misalignment applied
00192   TString fMisRelPos; // relative positions with misalignment applied (to abs. orig.?)
00193   TString fMisPar;    // misalignment parameters
00194   TString fPos;       // positions after alignment
00195   TString fRelPos;    // relative positions  after alignment (to abs. orig.?)
00196   TString fPar;       // remaining misalign paramters after alignment (was: alignment parameters)
00197   TString fMp;        // specials for/from MillePede
00198 
00199   // special seetings
00200   bool fUseSignedR;  // if true, Rpos will have sign of y
00201   bool fBowsParameters; //true: pede parameter names and titles to 'bows', false: rigid body
00202 };
00203 #endif