Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // Original Author: Gero Flucke
0002 // last change    : $Date: 2012/03/29 08:13:18 $
0003 // by             : $Author: flucke $
0004 
0005 #ifndef MILLEPEDETREES_H
0006 #define MILLEPEDETREES_H
0007 
0008 #include "TString.h"
0009 
0010 class TTree;
0011 class TGraph;
0012 class TH1;
0013 class TH2;
0014 class TProfile;
0015 
0016 class MillePedeTrees
0017 {
0018  public:
0019   explicit MillePedeTrees(const char *fileName, Int_t iter = 1, const char *treeNameAdd = "");
0020   virtual ~MillePedeTrees();
0021 
0022   TH1* Draw(const char *exp, const char *selection, const char *hDef = "", Option_t *opt = "");
0023   TH1* CreateHist(const char *exp, const char *select, const char *hDef = "", Option_t *opt = "");
0024   TH2* CreateHist2D(const char *expX, const char *expY, const char *select,
0025             const char *hDef = "", Option_t *opt = "");
0026   TProfile* CreateHistProf(const char *expX, const char *expY, const char *select,
0027                const char *hDef = "", Option_t *opt = "");
0028   TGraph* CreateGraph(const char *expX, const char *expY, const char *select, Option_t *option="");
0029 
0030 /*   void ScanDiffAbove(UInt_t iPar, float absDiff); */
0031 
0032   // values: absolute positions and orientations; need a 'position tree' as argument or in front
0033   TString Pos() const { return "Pos";}
0034   TString Pos(UInt_t ui) const { return Pos() += Bracket(ui);}
0035   TString XPos() const { return Pos(0);}
0036   TString YPos() const { return Pos(1);}
0037   TString ZPos() const { return Pos(2);}
0038   TString RPos2(const TString &tree) const; // x^2+y^2
0039 /*   TString RPos(const TString &tree) const { return Sqrt(RPos2(tree));} // sqrt(x^2+y^2) */
0040   TString RPos(const TString &tree) const; // sqrt(x^2+y^2) - y-sign if selected by UseSignedR()
0041   // (un)set whether RPos should be signed like y, return old setting
0042   bool SetUseSignedR(bool use = true) {bool buf = fUseSignedR; fUseSignedR = use; return buf;}//true: radius gets sign of y
0043   bool SetBowsParameters(bool use = true) {bool buf = fBowsParameters; fBowsParameters = use; return buf;}//true: bows param. for pede
0044   bool SetSurfDefDeltaBows(bool deltaBows) {const bool buf = fSurfDefDeltaBows; fSurfDefDeltaBows = deltaBows; return buf;} // take care: problems for false if drawing 1-sensor modules!
0045   
0046   TString Phi(const TString &tree) const;
0047   TString OrgPos(const TString &pos) const; // pos x, y, z, r, phi,... on original position
0048 
0049   TString PhiSwaps(double swapAround, const TString &tree1, const TString &tree2) const;
0050   TString Theta(const TString &tree) const;
0051   TString Alpha(const TString &tree, bool betaMpiPpi) const;
0052   TString Beta (const TString &tree, bool betaMpiPpi) const;
0053   TString Gamma(const TString &tree, bool betaMpiPpi) const;
0054 
0055   // values: alignment parameters; need a 'parameter tree' or MpT() as argument or in front
0056   TString Par() const { return "Par";}
0057   TString Par(UInt_t ui) const { return Par() += Bracket(ui);}
0058   TString XPar() const { return Par(0);}
0059   TString YPar() const { return Par(1);}
0060   TString ZPar() const { return Par(2);}
0061   TString Alpha() const { return Par(3);}
0062   TString Beta() const { return Par(4);}
0063   TString Gamma() const { return Par(5);}
0064   TString DiffPar(const TString &t1, const TString &t2, UInt_t iPar) const {
0065     return Parenth(t1 + Par(iPar) += Min() += t2 + Par(iPar));}
0066   // values: alignment parameter errors from parameter tree (to be given as tree name)
0067   TString ParSi(const TString &tree, UInt_t ui) const;
0068   TString XParSi(const TString &tree) const  { return ParSi(tree, 0);}
0069   TString YParSi(const TString &tree) const { return ParSi(tree, 1);}
0070   TString ZParSi(const TString &tree) const { return ParSi(tree, 2);}
0071   TString AlphaSi(const TString &tree) const { return ParSi(tree, 3);}
0072   TString BetaSi(const TString &tree) const { return ParSi(tree, 4);}
0073   TString GammaSi(const TString &tree) const { return ParSi(tree, 5);}
0074 
0075   // values: Delta positions
0076   TString DelPos(UInt_t ui, const TString &tree1, const TString &tree2) const;
0077   TString DelR(const TString &tree1, const TString &tree2) const;
0078   TString DelRphi(const TString &tree1, const TString &tree2) const;
0079   // TString DelRphi_b(const TString &tree1, const TString &tree2) const; // version b
0080   TString DelPhi(const TString &tree1, const TString &tree2) const;
0081   // values: Delta positions wrt. OrgPosT()
0082   TString DelPos(UInt_t ui, const TString &tree) const { return DelPos(ui, tree, OrgPosT());}
0083   TString DelR(const TString &tree) const { return DelR(tree, OrgPosT());}
0084   TString DelRphi(const TString &tree) const { return DelRphi(tree, OrgPosT());}
0085   TString DelPhi(const TString &tree) const { return DelPhi(tree, OrgPosT());}
0086   // see also TString DeltaPos(const TString &pos, const TString &tree) const;
0087   
0088   // '25' and '0x7' DataFormats/DetId/interface/DetId.h:
0089   TString SubDetId() const { return "(" + OrgPosT() += "Id>>25)&0x7";}
0090   TString AlignableTypeId() const { return OrgPosT() += "ObjId";}
0091   TString HieraLev(const TString &tree, Int_t level) const {
0092     return Parenth(tree + "HieraLevel==" + Int(level));}
0093   TString HieraLev(Int_t level) const {return HieraLev(ParT(), level);}
0094   // values: from pede, do not add tree in front
0095   TString Valid(UInt_t iParam) const;
0096   TString Fixed(UInt_t iParam, bool isFixed = true) const;
0097   TString AnyFreePar() const;
0098   TString Label(UInt_t iParam) const;
0099   TString Cor(UInt_t iParam) const;
0100   TString Diff(UInt_t iParam) const;
0101   TString PreSi(UInt_t iParam) const;
0102   TString ParSi(UInt_t iParam) const;
0103   TString ParSiOk(UInt_t iParam) const;
0104   TString XParSi() const  { return ParSi(0);}
0105   TString YParSi() const { return ParSi(1);}
0106   TString ZParSi() const { return ParSi(2);}
0107   TString AlphaSi() const { return ParSi(3);}
0108   TString BetaSi() const { return ParSi(4);}
0109   TString GammaSi() const { return ParSi(5);}
0110   TString HitsX() const { return MpT() += "HitsX";}
0111   TString HitsY() const { return MpT() += "HitsY";}
0112   TString DeformValue(UInt_t i, const TString &whichOne) const;//start,result,diff
0113   TString NumDeformValues(const TString &whichOne) const; //start,result,diff
0114 
0115   // symbols
0116   TString Dot() const { return ".";}
0117   TString Plu() const { return "+";}
0118   TString Min() const { return "-";}
0119   TString Mal() const { return "*";} // fixme? german...
0120   TString Div() const { return "/";}
0121   TString AndL() const {return "&&";} // logical and (not '&')
0122   TString OrL() const {return "||";}  // logical or (not '|')
0123   // numbers
0124   TString Int(Int_t i) const { return Form("%d", i);}
0125   TString Int(UInt_t ui) const { return Form("%u", ui);}
0126   TString Flt(Float_t f) const { return Form("%f", f);}
0127   // brackets and parentheses
0128   TString Bra() const { return "[";}
0129   TString Ket() const { return "]";}
0130   TString Bracket(UInt_t ui) const { return Bra() += Int(ui) += Ket();}
0131   TString Bracket(Int_t i) const { return Bra() += Int(i) += Ket();}
0132   TString Bracket(const char *s) const { return (Bra() += s) += Ket();}
0133   TString Paren() const { return "(";}
0134   TString Thesis() const { return ")";}
0135   TString Parenth(const char *s) const { return (Paren() += s) += Thesis();}
0136   TString Abs(const char *s) const {return Fun("TMath::Abs", s);}
0137   // functions
0138   TString Fun(const char *fun, const char *s) const { return fun + Parenth(s);}
0139   TString Sqrt(const char *s) const { return Fun("sqrt", s);}
0140 
0141   // units and names for params
0142   TString ToMumMuRad(UInt_t iParam) const { return (iParam < 3 ? "*10000" : "*1000000");}
0143   TString ToMumMuRadPede(UInt_t iParam) const;
0144   TString ToMumMuRadSurfDef(UInt_t iParam) const;
0145   TString Name(UInt_t iParam) const;
0146   TString NamePede(UInt_t iParam) const;
0147   TString NameSurfDef(UInt_t iParam) const;
0148   TString DelName(UInt_t iParam) const { return "#Delta"+Name(iParam);}
0149   TString DelNameU(UInt_t iParam) const { return DelName(iParam) += Unit(iParam);}
0150   TString Unit(UInt_t iParam) const { return (iParam < 3 
0151                           ? " [#mum]" 
0152                           : (iParam < kNpar ? " [#murad]" : ""));}
0153   TString UnitPede(UInt_t iParam) const;
0154   TString UnitSurfDef(UInt_t iParam) const;
0155   // units and names for position strings (r, rphi, phi, x, y, z)
0156   TString ToMumMuRad(const TString &pos) const;
0157   TString Name(const TString &pos) const;
0158   TString NamePos(UInt_t iPos) const; //0-2 are x, y, z
0159   TString DelName(const TString &pos) const;// { return "#Delta"+Name(pos);}
0160   TString DelNameU(const TString &pos) const { return DelName(pos) += Unit(pos);}
0161   TString Unit(const TString &pos) const;
0162 
0163   TString DeltaPos(const TString &pos, const TString &tree /* = PosT()*/) const;// delta position to OrgPosT, depending on pos DelPhi,DelRphi,DelPos(0,..) etc.
0164   TString SelIs1D() const;
0165   TString SelIs2D() const;
0166 
0167   // tree names
0168   TString OrgPosT() const { return fOrgPos + Dot();} // nominal global positions
0169   TString MisPosT() const { return fMisPos + Dot();} // misaligned global positions
0170   TString MisParT() const { return fMisPar + Dot();} // misalignment
0171   TString PosT() const { return fPos + Dot();} // aligned global positions
0172   TString ParT() const { return fPar + Dot();} // remaining misalignment
0173   TString MpT() const { return fMp + Dot();} // MP tree (parameter, hits,...)
0174 
0175   TTree* GetMainTree() {return fTree;} // use with care...
0176 
0177   enum {kLocX = 0, kLocY, kLocZ, kNpar = 6}; // number of parameters we have...
0178  protected:
0179 
0180  private: 
0181   MillePedeTrees();
0182   // utils
0183   TTree* CreateTree(const char *fileName, const TString &treeNameAdd);
0184 /*   TString RemoveHistName(TString &option) const; */
0185 
0186   // data members
0187   TTree   *fTree;
0188 
0189   // tree names
0190   TString fOrgPos;    // absolute original positions from xml/input DB
0191   TString fMisPos;    // absolute positions with misalignment applied
0192   TString fMisPar;    // misalignment parameters
0193   TString fPos;       // positions after alignment
0194   TString fPar;       // remaining misalign paramters after alignment (was: alignment parameters)
0195   TString fMp;        // specials for/from MillePede
0196 
0197   // special seetings
0198   bool fUseSignedR;  // if true, Rpos will have sign of y
0199   bool fBowsParameters; //true: pede parameter names and titles to 'bows', false: rigid body
0200   bool fSurfDefDeltaBows; // true: SurfaceDeformation values as is, otherwise bowMean+Delta and bowMean-Delta
0201 };
0202 #endif