Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:14:41

0001 
0002 
0003 #include "TROOT.h"
0004 #include "TFile.h"
0005 #include "TDirectory.h"
0006 #include "TChain.h"
0007 #include "TObject.h"
0008 #include "TCanvas.h"
0009 #include "TMath.h"
0010 #include "TLegend.h"
0011 #include "TGraph.h"
0012 #include "TH1.h"
0013 #include "TH2.h"
0014 #include "TH3.h"
0015 #include "TTree.h"
0016 #include "TF1.h"
0017 #include "TPaveText.h"
0018 
0019 int Color [] = {2,4,1,8,6,7,3,9,5};
0020 int Marker[] = {21,22,23,20,29,3,2};
0021 int Style [] = {1,2,5,7,9,10};
0022 
0023 #include<vector>
0024 #include<tdrstyle.C>
0025 
0026 TObject* GetObjectFromPath(TDirectory* File, const char* Path);
0027 void SaveCanvas(TCanvas* c, char* path, bool OnlyPPNG=false);
0028 void DrawStatBox(TObject** Histos, std::vector<char*> legend, bool Mean               , double X=0.15, double Y=0.93, double W=0.15, double H=0.03);
0029 void DrawLegend (TObject** Histos, std::vector<char*> legend, char* Title, char* Style, double X=0.80, double Y=0.93, double W=0.20, double H=0.05);
0030 void DrawSuperposedHistos(TH1D** Histos, std::vector<char*> legend, char* Style,  char* Xlegend, char* Ylegend, double xmin, double xmax, double ymin, double ymax);
0031 void DrawTH2D   (TH2D**    Histos, std::vector<char*> legend, char* Style, char* Xlegend, char* Ylegend, double xmin, double xmax, double ymin, double ymax);
0032 
0033 TF1*  getLandau(TH1* InputHisto, double* FitResults, double LowRange=50, double HighRange=5400);
0034 TH1D* ChargeToMPV(TH2* InputHisto, char* Name, bool DivideByX);
0035 
0036 void GainPlot()
0037 {
0038    gROOT->Reset();
0039    setTDRStyle();
0040    gStyle->SetPadTopMargin   (0.05);
0041    gStyle->SetPadBottomMargin(0.10);
0042    gStyle->SetPadRightMargin (0.18);
0043    gStyle->SetPadLeftMargin  (0.13);
0044    gStyle->SetTitleSize(0.04, "XYZ");
0045    gStyle->SetTitleXOffset(1.1);
0046    gStyle->SetTitleYOffset(1.35);
0047    gStyle->SetPalette(1);
0048    gStyle->SetCanvasColor(0);
0049    gStyle->SetBarOffset(0);
0050 
0051 
0052    unsigned int  tree_Index;
0053    unsigned int  tree_DetId;
0054    unsigned char tree_APVId;
0055    unsigned char tree_SubDet;
0056    float         tree_x;
0057    float         tree_y;
0058    float         tree_z;
0059    float         tree_Eta;
0060    float         tree_R;
0061    float         tree_Phi;
0062    float         tree_Thickness;
0063    float         tree_FitMPV;
0064    float         tree_FitMPVErr;
0065    float         tree_FitWidth;
0066    float         tree_FitWidthErr;
0067    float         tree_FitChi2NDF;
0068    double        tree_Gain;
0069    double        tree_PrevGain;
0070    double        tree_NEntries;
0071 
0072    TFile* f1     = new TFile("file:../Gains_Tree.root");
0073    TTree *t1     = (TTree*)GetObjectFromPath(f1,"SiStripCalib/APVGain");
0074 
0075    t1->SetBranchAddress("Index"             ,&tree_Index      );
0076    t1->SetBranchAddress("DetId"             ,&tree_DetId      );
0077    t1->SetBranchAddress("APVId"             ,&tree_APVId      );
0078    t1->SetBranchAddress("SubDet"            ,&tree_SubDet     );
0079    t1->SetBranchAddress("x"                 ,&tree_x          );
0080    t1->SetBranchAddress("y"                 ,&tree_y          );
0081    t1->SetBranchAddress("z"                 ,&tree_z          );
0082    t1->SetBranchAddress("Eta"               ,&tree_Eta        );
0083    t1->SetBranchAddress("R"                 ,&tree_R          );
0084    t1->SetBranchAddress("Phi"               ,&tree_Phi        );
0085    t1->SetBranchAddress("Thickness"         ,&tree_Thickness  );
0086    t1->SetBranchAddress("FitMPV"            ,&tree_FitMPV     );
0087    t1->SetBranchAddress("FitMPVErr"         ,&tree_FitMPVErr  );
0088    t1->SetBranchAddress("FitWidth"          ,&tree_FitWidth   );
0089    t1->SetBranchAddress("FitWidthErr"       ,&tree_FitWidthErr);
0090    t1->SetBranchAddress("FitChi2NDF"        ,&tree_FitChi2NDF );
0091    t1->SetBranchAddress("Gain"              ,&tree_Gain       );
0092    t1->SetBranchAddress("PrevGain"          ,&tree_PrevGain   );
0093    t1->SetBranchAddress("NEntries"          ,&tree_NEntries   );
0094 
0095 
0096    TH2D* ChargeDistrib  = (TH2D*)GetObjectFromPath(f1,"SiStripCalib/Charge_Vs_Index");
0097    TH2D* ChargeDistribA = (TH2D*)GetObjectFromPath(f1,"SiStripCalib/Charge_Vs_Index_Absolute");
0098 
0099    TH2D* Charge_Vs_PathlengthTIB   = (TH2D*)GetObjectFromPath(f1,"SiStripCalib/Charge_Vs_PathlengthTIB");
0100    TH2D* Charge_Vs_PathlengthTOB   = (TH2D*)GetObjectFromPath(f1,"SiStripCalib/Charge_Vs_PathlengthTOB");
0101    TH2D* Charge_Vs_PathlengthTIDP  = (TH2D*)GetObjectFromPath(f1,"SiStripCalib/Charge_Vs_PathlengthTIDP");
0102    TH2D* Charge_Vs_PathlengthTIDM  = (TH2D*)GetObjectFromPath(f1,"SiStripCalib/Charge_Vs_PathlengthTIDM");
0103    TH2D* Charge_Vs_PathlengthTID   = (TH2D*)Charge_Vs_PathlengthTIDP->Clone("Charge_Vs_PathlengthTID");
0104          Charge_Vs_PathlengthTID      ->Add(Charge_Vs_PathlengthTIDM);
0105    TH2D* Charge_Vs_PathlengthTECP1 = (TH2D*)GetObjectFromPath(f1,"SiStripCalib/Charge_Vs_PathlengthTECP1");
0106    TH2D* Charge_Vs_PathlengthTECP2 = (TH2D*)GetObjectFromPath(f1,"SiStripCalib/Charge_Vs_PathlengthTECP2");
0107    TH2D* Charge_Vs_PathlengthTECM1 = (TH2D*)GetObjectFromPath(f1,"SiStripCalib/Charge_Vs_PathlengthTECM1");
0108    TH2D* Charge_Vs_PathlengthTECM2 = (TH2D*)GetObjectFromPath(f1,"SiStripCalib/Charge_Vs_PathlengthTECM2");
0109    TH2D* Charge_Vs_PathlengthTECP  = (TH2D*)Charge_Vs_PathlengthTECP1->Clone("Charge_Vs_PathlengthTECP");
0110          Charge_Vs_PathlengthTECP     ->Add(Charge_Vs_PathlengthTECP2);
0111    TH2D* Charge_Vs_PathlengthTECM  = (TH2D*)Charge_Vs_PathlengthTECM1->Clone("Charge_Vs_PathlengthTECM");
0112          Charge_Vs_PathlengthTECM     ->Add(Charge_Vs_PathlengthTECM2);
0113    TH2D* Charge_Vs_PathlengthTEC1  = (TH2D*)Charge_Vs_PathlengthTECP1->Clone("Charge_Vs_PathlengthTEC1");
0114          Charge_Vs_PathlengthTEC1     ->Add(Charge_Vs_PathlengthTECM1);
0115    TH2D* Charge_Vs_PathlengthTEC2  = (TH2D*)Charge_Vs_PathlengthTECP2->Clone("Charge_Vs_PathlengthTEC2");
0116          Charge_Vs_PathlengthTEC2     ->Add(Charge_Vs_PathlengthTECM2); 
0117    TH2D* Charge_Vs_PathlengthTEC   = (TH2D*)Charge_Vs_PathlengthTECP ->Clone("Charge_Vs_PathlengthTEC");
0118          Charge_Vs_PathlengthTEC      ->Add(Charge_Vs_PathlengthTECM );
0119 
0120    TH2D* Charge_Vs_PathlengthThin  = (TH2D*)Charge_Vs_PathlengthTEC1->Clone("Charge_Vs_PathlengthThin");
0121          Charge_Vs_PathlengthThin     ->Add(Charge_Vs_PathlengthTIB );
0122          Charge_Vs_PathlengthThin     ->Add(Charge_Vs_PathlengthTID );
0123    TH2D* Charge_Vs_PathlengthThick = (TH2D*)Charge_Vs_PathlengthTEC2->Clone("Charge_Vs_PathlengthThin");
0124          Charge_Vs_PathlengthThick    ->Add(Charge_Vs_PathlengthTOB );
0125 
0126 
0127 
0128    TH1D* MPV_Vs_PathlengthTIB      = ChargeToMPV(Charge_Vs_PathlengthTIB  ,"MPV_Vs_PathlengthTIB"  , true);
0129    TH1D* MPV_Vs_PathlengthTID      = ChargeToMPV(Charge_Vs_PathlengthTID  ,"MPV_Vs_PathlengthTID"  , true);
0130 // TH1D* MPV_Vs_PathlengthTIDP     = ChargeToMPV(Charge_Vs_PathlengthTIDP ,"MPV_Vs_PathlengthTIDP" , true);
0131 // TH1D* MPV_Vs_PathlengthTIDM     = ChargeToMPV(Charge_Vs_PathlengthTIDM ,"MPV_Vs_PathlengthTIDM" , true);
0132    TH1D* MPV_Vs_PathlengthTOB      = ChargeToMPV(Charge_Vs_PathlengthTOB  ,"MPV_Vs_PathlengthTOB"  , true);
0133 // TH1D* MPV_Vs_PathlengthTEC      = ChargeToMPV(Charge_Vs_PathlengthTEC  ,"MPV_Vs_PathlengthTEC"  , true);
0134 // TH1D* MPV_Vs_PathlengthTECP     = ChargeToMPV(Charge_Vs_PathlengthTECP ,"MPV_Vs_PathlengthTECP" , true);
0135 // TH1D* MPV_Vs_PathlengthTECM     = ChargeToMPV(Charge_Vs_PathlengthTECM ,"MPV_Vs_PathlengthTECM" , true);
0136    TH1D* MPV_Vs_PathlengthTEC1     = ChargeToMPV(Charge_Vs_PathlengthTEC1 ,"MPV_Vs_PathlengthTEC1" , true);
0137    TH1D* MPV_Vs_PathlengthTEC2     = ChargeToMPV(Charge_Vs_PathlengthTEC2 ,"MPV_Vs_PathlengthTEC2" , true);
0138 // TH1D* MPV_Vs_PathlengthTECP1    = ChargeToMPV(Charge_Vs_PathlengthTECP1,"MPV_Vs_PathlengthTECP1", true);
0139 // TH1D* MPV_Vs_PathlengthTECP2    = ChargeToMPV(Charge_Vs_PathlengthTECP2,"MPV_Vs_PathlengthTECP2", true);
0140 // TH1D* MPV_Vs_PathlengthTECM1    = ChargeToMPV(Charge_Vs_PathlengthTECM1,"MPV_Vs_PathlengthTECM1", true);
0141 // TH1D* MPV_Vs_PathlengthTECM2    = ChargeToMPV(Charge_Vs_PathlengthTECM2,"MPV_Vs_PathlengthTECM2", true);
0142    TH1D* MPV_Vs_PathlengthThin     = ChargeToMPV(Charge_Vs_PathlengthThin ,"MPV_Vs_PathlengthThin" , true);
0143    TH1D* MPV_Vs_PathlengthThick    = ChargeToMPV(Charge_Vs_PathlengthThick,"MPV_Vs_PathlengthThick", true);
0144 
0145    TH2D* MPV_Vs_EtaTIB  = new TH2D("MPV_Vs_EtaTIB" ,"MPV_Vs_EtaTIB" , 50, -3.0, 3.0, 300, 0, 600);
0146    TH2D* MPV_Vs_EtaTID  = new TH2D("MPV_Vs_EtaTID" ,"MPV_Vs_EtaTID" , 50, -3.0, 3.0, 300, 0, 600);
0147    TH2D* MPV_Vs_EtaTOB  = new TH2D("MPV_Vs_EtaTOB" ,"MPV_Vs_EtaTOB" , 50, -3.0, 3.0, 300, 0, 600);
0148    TH2D* MPV_Vs_EtaTEC  = new TH2D("MPV_Vs_EtaTEC" ,"MPV_Vs_EtaTEC" , 50, -3.0, 3.0, 300, 0, 600);
0149    TH2D* MPV_Vs_EtaTEC1 = new TH2D("MPV_Vs_EtaTEC1","MPV_Vs_EtaTEC1", 50, -3.0, 3.0, 300, 0, 600);
0150    TH2D* MPV_Vs_EtaTEC2 = new TH2D("MPV_Vs_EtaTEC2","MPV_Vs_EtaTEC2", 50, -3.0, 3.0, 300, 0, 600);
0151 
0152    TH2D* MPV_Vs_PhiTIB  = new TH2D("MPV_Vs_PhiTIB" ,"MPV_Vs_PhiTIB" , 50, -3.4, 3.4, 300, 0, 600);
0153    TH2D* MPV_Vs_PhiTID  = new TH2D("MPV_Vs_PhiTID" ,"MPV_Vs_PhiTID" , 50, -3.4, 3.4, 300, 0, 600);
0154    TH2D* MPV_Vs_PhiTOB  = new TH2D("MPV_Vs_PhiTOB" ,"MPV_Vs_PhiTOB" , 50, -3.4, 3.4, 300, 0, 600);
0155    TH2D* MPV_Vs_PhiTEC  = new TH2D("MPV_Vs_PhiTEC" ,"MPV_Vs_PhiTEC" , 50, -3.4, 3.4, 300, 0, 600);
0156    TH2D* MPV_Vs_PhiTEC1 = new TH2D("MPV_Vs_PhiTEC1","MPV_Vs_PhiTEC1", 50, -3.4, 3.4, 300, 0, 600);
0157    TH2D* MPV_Vs_PhiTEC2 = new TH2D("MPV_Vs_PhiTEC2","MPV_Vs_PhiTEC2", 50, -3.4, 3.4, 300, 0, 600);
0158 
0159    TH2D* NoMPV          = new TH2D("NoMPV"         ,"NoMPV"         ,350, -350, 350, 240, 0, 120);
0160 
0161    TH1D* MPVs           = new TH1D("MPVs"          ,"MPVs"          ,                300, 0, 600);
0162    TH1D* MPVs320        = new TH1D("MPVs320"       ,"MPVs320"       ,                300, 0, 600);
0163    TH1D* MPVs500        = new TH1D("MPVs500"       ,"MPVs500"       ,                300, 0, 600);
0164 
0165    TH1D* MPVError       = new TH1D("MPVError"      ,"MPVError"      ,                150, 0, 150);
0166    TH2D* MPVErrorVsMPV  = new TH2D("MPVErrorVsMPV" ,"MPVErrorVsMPV" ,300,    0, 600, 150, 0, 150);
0167    TH2D* MPVErrorVsEta  = new TH2D("MPVErrorVsEta" ,"MPVErrorVsEta" , 50, -3.0, 3.0, 150, 0, 150); 
0168    TH2D* MPVErrorVsPhi  = new TH2D("MPVErrorVsPhi" ,"MPVErrorVsPhi" , 50, -3.4, 3.4, 150, 0, 150);             
0169    TH2D* MPVErrorVsN    = new TH2D("MPVErrorVsN"   ,"MPVErrorVsN"   ,500,    0,1000, 150, 0, 150);              
0170 
0171 
0172 
0173 
0174    TH1D* ChargeTIB      = new TH1D("ChargeTIB"     ,"ChargeTIB"     ,               1000, 0,2000);
0175    TH1D* ChargeTID      = new TH1D("ChargeTID"     ,"ChargeTID"     ,               1000, 0,2000);
0176    TH1D* ChargeTIDP     = new TH1D("ChargeTIDP"    ,"ChargeTIDP"    ,               1000, 0,2000);
0177    TH1D* ChargeTIDM     = new TH1D("ChargeTIDM"    ,"ChargeTIDM"    ,               1000, 0,2000);
0178    TH1D* ChargeTOB      = new TH1D("ChargeTOB"     ,"ChargeTOB"     ,               1000, 0,2000);
0179    TH1D* ChargeTEC      = new TH1D("ChargeTEC"     ,"ChargeTEC"     ,               1000, 0,2000);
0180    TH1D* ChargeTECP     = new TH1D("ChargeTECP"    ,"ChargeTECP"    ,               1000, 0,2000);
0181    TH1D* ChargeTECM     = new TH1D("ChargeTECM"    ,"ChargeTECM"    ,               1000, 0,2000);
0182    TH1D* ChargeTEC1     = new TH1D("ChargeTEC1"    ,"ChargeTEC1"    ,               1000, 0,2000);
0183    TH1D* ChargeTEC2     = new TH1D("ChargeTEC2"    ,"ChargeTEC2"    ,               1000, 0,2000);
0184    TH1D* ChargeTECP1    = new TH1D("ChargeTECP1"   ,"ChargeTECP1"   ,               1000, 0,2000);
0185    TH1D* ChargeTECP2    = new TH1D("ChargeTECP2"   ,"ChargeTECP2"   ,               1000, 0,2000);
0186    TH1D* ChargeTECM1    = new TH1D("ChargeTECM1"   ,"ChargeTECM1"   ,               1000, 0,2000);
0187    TH1D* ChargeTECM2    = new TH1D("ChargeTECM2"   ,"ChargeTECM2"   ,               1000, 0,2000);
0188 
0189    TH1D* ChargeAbsTIB   = new TH1D("ChargeAbsTIB"  ,"ChargeAbsTIB"  ,                500, 0,2000);
0190    TH1D* ChargeAbsTID   = new TH1D("ChargeAbsTID"  ,"ChargeAbsTID"  ,                500, 0,2000);
0191    TH1D* ChargeAbsTIDP  = new TH1D("ChargeAbsTIDP" ,"ChargeAbsTIDP" ,                500, 0,2000);
0192    TH1D* ChargeAbsTIDM  = new TH1D("ChargeAbsTIDM" ,"ChargeAbsTIDM" ,                500, 0,2000);
0193    TH1D* ChargeAbsTOB   = new TH1D("ChargeAbsTOB"  ,"ChargeAbsTOB"  ,                500, 0,2000);
0194    TH1D* ChargeAbsTEC   = new TH1D("ChargeAbsTEC"  ,"ChargeAbsTEC"  ,                500, 0,2000);
0195    TH1D* ChargeAbsTECP  = new TH1D("ChargeAbsTECP" ,"ChargeAbsTECP" ,                500, 0,2000);
0196    TH1D* ChargeAbsTECM  = new TH1D("ChargeAbsTECM" ,"ChargeAbsTECM" ,                500, 0,2000);
0197    TH1D* ChargeAbsTEC1  = new TH1D("ChargeAbsTEC1" ,"ChargeAbsTEC1" ,                500, 0,2000);
0198    TH1D* ChargeAbsTEC2  = new TH1D("ChargeAbsTEC2" ,"ChargeAbsTEC2" ,                500, 0,2000);
0199    TH1D* ChargeAbsTECP1 = new TH1D("ChargeAbsTECP1","ChargeAbsTECP1",                500, 0,2000);
0200    TH1D* ChargeAbsTECP2 = new TH1D("ChargeAbsTECP2","ChargeAbsTECP2",                500, 0,2000);
0201    TH1D* ChargeAbsTECM1 = new TH1D("ChargeAbsTECM1","ChargeAbsTECM1",                500, 0,2000);
0202    TH1D* ChargeAbsTECM2 = new TH1D("ChargeAbsTECM2","ChargeAbsTECM2",                500, 0,2000);
0203 
0204 
0205 
0206    printf("Progressing Bar              :0%%       20%%       40%%       60%%       80%%       100%%\n");
0207    printf("Looping on the Tree          :");
0208    int TreeStep = t1->GetEntries()/50;if(TreeStep==0)TreeStep=1;
0209    for (unsigned int ientry = 0; ientry < t1->GetEntries(); ientry++) {
0210       if(ientry%TreeStep==0){printf(".");fflush(stdout);}
0211       t1->GetEntry(ientry);
0212       TH1D* Proj         = ChargeDistrib ->ProjectionY("proj" ,tree_Index, tree_Index);
0213       TH1D* ProjAbsolute = ChargeDistribA->ProjectionY("projA",tree_Index, tree_Index);
0214 
0215 
0216       if(tree_SubDet==3                       ) MPV_Vs_EtaTIB ->Fill(tree_Eta,tree_FitMPV);
0217       if(tree_SubDet==4                       ) MPV_Vs_EtaTID ->Fill(tree_Eta,tree_FitMPV);
0218       if(tree_SubDet==5                       ) MPV_Vs_EtaTOB ->Fill(tree_Eta,tree_FitMPV);
0219       if(tree_SubDet==6                       ) MPV_Vs_EtaTEC ->Fill(tree_Eta,tree_FitMPV);
0220       if(tree_SubDet==6 && tree_Thickness<0.04) MPV_Vs_EtaTEC1->Fill(tree_Eta,tree_FitMPV);
0221       if(tree_SubDet==6 && tree_Thickness>0.04) MPV_Vs_EtaTEC2->Fill(tree_Eta,tree_FitMPV);
0222 
0223       if(tree_SubDet==3                       ) MPV_Vs_PhiTIB ->Fill(tree_Phi,tree_FitMPV);
0224       if(tree_SubDet==4                       ) MPV_Vs_PhiTID ->Fill(tree_Phi,tree_FitMPV);
0225       if(tree_SubDet==5                       ) MPV_Vs_PhiTOB ->Fill(tree_Phi,tree_FitMPV);
0226       if(tree_SubDet==6                       ) MPV_Vs_PhiTEC ->Fill(tree_Phi,tree_FitMPV);
0227       if(tree_SubDet==6 && tree_Thickness<0.04) MPV_Vs_PhiTEC1->Fill(tree_Phi,tree_FitMPV);
0228       if(tree_SubDet==6 && tree_Thickness>0.04) MPV_Vs_PhiTEC2->Fill(tree_Phi,tree_FitMPV);
0229 
0230                                                 MPVs          ->Fill(         tree_FitMPV);
0231       if(                  tree_Thickness<0.04) MPVs320       ->Fill(         tree_FitMPV);
0232       if(                  tree_Thickness>0.04) MPVs500       ->Fill(         tree_FitMPV);
0233 
0234 
0235       if(tree_FitMPV<0                        ) NoMPV         ->Fill(tree_z ,tree_R);
0236 
0237                                                 MPVError      ->Fill(         tree_FitMPVErr);    
0238                                                 MPVErrorVsMPV ->Fill(tree_FitMPV,tree_FitMPVErr);
0239                                                 MPVErrorVsEta ->Fill(tree_Eta,tree_FitMPVErr);
0240                                                 MPVErrorVsPhi ->Fill(tree_Phi,tree_FitMPVErr);
0241                                                 MPVErrorVsN   ->Fill(tree_NEntries,tree_FitMPVErr);
0242 
0243 
0244       if(tree_SubDet==3                       ) ChargeTIB  ->Add(Proj,1);
0245       if(tree_SubDet==4                       ) ChargeTID  ->Add(Proj,1);
0246       if(tree_SubDet==4 && tree_Eta<0         ) ChargeTIDM ->Add(Proj,1);
0247       if(tree_SubDet==4 && tree_Eta>0         ) ChargeTIDP ->Add(Proj,1);
0248       if(tree_SubDet==5                       ) ChargeTOB  ->Add(Proj,1);
0249       if(tree_SubDet==6                       ) ChargeTEC  ->Add(Proj,1);
0250       if(tree_SubDet==6 && tree_Thickness<0.04) ChargeTEC1 ->Add(Proj,1);
0251       if(tree_SubDet==6 && tree_Thickness>0.04) ChargeTEC2 ->Add(Proj,1);
0252       if(tree_SubDet==6 && tree_Eta<0         ) ChargeTECP ->Add(Proj,1);
0253       if(tree_SubDet==6 && tree_Eta>0         ) ChargeTECM ->Add(Proj,1);
0254       if(tree_SubDet==6 && tree_Eta<0 && tree_Thickness<0.04) ChargeTECM1 ->Add(Proj,1);
0255       if(tree_SubDet==6 && tree_Eta<0 && tree_Thickness>0.04) ChargeTECM2 ->Add(Proj,1);
0256       if(tree_SubDet==6 && tree_Eta>0 && tree_Thickness<0.04) ChargeTECP1 ->Add(Proj,1);
0257       if(tree_SubDet==6 && tree_Eta>0 && tree_Thickness>0.04) ChargeTECP2 ->Add(Proj,1);
0258 
0259 
0260       if(tree_SubDet==3                       ) ChargeAbsTIB  ->Add(ProjAbsolute,1);
0261       if(tree_SubDet==4                       ) ChargeAbsTID  ->Add(ProjAbsolute,1);
0262       if(tree_SubDet==4 && tree_Eta<0         ) ChargeAbsTIDM ->Add(ProjAbsolute,1);
0263       if(tree_SubDet==4 && tree_Eta>0         ) ChargeAbsTIDP ->Add(ProjAbsolute,1);
0264       if(tree_SubDet==5                       ) ChargeAbsTOB  ->Add(ProjAbsolute,1);
0265       if(tree_SubDet==6                       ) ChargeAbsTEC  ->Add(ProjAbsolute,1);
0266       if(tree_SubDet==6 && tree_Thickness<0.04) ChargeAbsTEC1 ->Add(ProjAbsolute,1);
0267       if(tree_SubDet==6 && tree_Thickness>0.04) ChargeAbsTEC2 ->Add(ProjAbsolute,1);
0268       if(tree_SubDet==6 && tree_Eta<0         ) ChargeAbsTECP ->Add(ProjAbsolute,1);
0269       if(tree_SubDet==6 && tree_Eta>0         ) ChargeAbsTECM ->Add(ProjAbsolute,1);
0270       if(tree_SubDet==6 && tree_Eta<0 && tree_Thickness<0.04) ChargeAbsTECM1 ->Add(ProjAbsolute,1);
0271       if(tree_SubDet==6 && tree_Eta<0 && tree_Thickness>0.04) ChargeAbsTECM2 ->Add(ProjAbsolute,1);
0272       if(tree_SubDet==6 && tree_Eta>0 && tree_Thickness<0.04) ChargeAbsTECP1 ->Add(ProjAbsolute,1);
0273       if(tree_SubDet==6 && tree_Eta>0 && tree_Thickness>0.04) ChargeAbsTECP2 ->Add(ProjAbsolute,1);
0274 
0275 
0276 
0277       delete Proj;
0278       delete ProjAbsolute;
0279    }printf("\n");
0280 
0281    TCanvas* c1;
0282    TObject** Histos = new TObject*[10];                
0283    std::vector<char*> legend;
0284 
0285    c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0286    Histos[0] = MPV_Vs_EtaTEC;                     legend.push_back("TEC");
0287    Histos[1] = MPV_Vs_EtaTIB;                     legend.push_back("TIB");
0288    Histos[2] = MPV_Vs_EtaTID;                     legend.push_back("TID");
0289    Histos[3] = MPV_Vs_EtaTOB;                     legend.push_back("TOB");
0290    DrawTH2D((TH2D**)Histos,legend, "", "module #eta", "MPV (ADC/mm)", -3.0,3.0, 0,500);
0291    DrawLegend (Histos,legend,"","P");
0292    DrawStatBox(Histos,legend,false);
0293    SaveCanvas(c1,"Pictures/MPV_Vs_EtaSubDet");
0294    delete c1;
0295 
0296     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0297     Histos[0] = MPV_Vs_PhiTEC;                     legend.push_back("TEC");
0298     Histos[1] = MPV_Vs_PhiTIB;                     legend.push_back("TIB");
0299     Histos[2] = MPV_Vs_PhiTID;                     legend.push_back("TID");
0300     Histos[3] = MPV_Vs_PhiTOB;                     legend.push_back("TOB");
0301     DrawTH2D((TH2D**)Histos,legend, "", "module #phi", "MPV (ADC/mm)", -3.4,3.4, 0,500);
0302     DrawLegend(Histos,legend,"","P");
0303     DrawStatBox(Histos,legend,false);
0304     SaveCanvas(c1,"Pictures/MPV_Vs_PhiSubDet");
0305     delete c1;
0306 
0307     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0308     Histos[0] = NoMPV;                             legend.push_back("NoMPV");
0309     DrawTH2D((TH2D**)Histos,legend, "", "z (cm)", "R (cms)", 0,0, 0,0);
0310     SaveCanvas(c1,"Pictures/NoMPV", true);
0311     delete c1;
0312 
0313     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0314     ChargeDistrib->GetXaxis()->SetNdivisions(5+500);
0315     Histos[0] = ChargeDistrib;                     legend.push_back("Charge Vs Index");
0316     //DrawTH2D((TH2D**)Histos,legend, "COLZ", "APV Index", "Charge (ADC/mm)", 0,0, 0,0);
0317     //c1->SetLogz(true);
0318     //SaveCanvas(c1,"Pictures/Charge", true);
0319     delete c1;
0320 
0321     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0322     Histos[0] = MPVs320;                           legend.push_back("320 #mum");
0323     Histos[1] = MPVs500;                           legend.push_back("500 #mum");
0324     Histos[2] = MPVs;                              legend.push_back("320 + 500 #mum");
0325     DrawSuperposedHistos((TH1D**)Histos, legend, "",  "MPV (ADC/mm)", "#APVs", 0,500, 0,0);
0326     DrawLegend(Histos,legend,"","L");
0327     DrawStatBox(Histos,legend,true);
0328     SaveCanvas(c1,"Pictures/MPVs");
0329     delete c1;
0330 
0331 
0332     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0333     Histos[0] = MPVError;                          legend.push_back("MPV Error");
0334     DrawSuperposedHistos((TH1D**)Histos, legend, "",  "Error on MPV (ADC/mm)", "#APVs", 0,500, 0,0);
0335     DrawStatBox(Histos,legend,true);
0336     c1->SetLogy(true);
0337     SaveCanvas(c1,"Pictures/Error");
0338     delete c1;
0339 
0340     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0341     Histos[0] = MPVErrorVsMPV;                     legend.push_back("Error Vs MPV");
0342     DrawTH2D((TH2D**)Histos,legend, "COLZ", "MPV (ADC/mm)", "Error on MPV (ADC/mm)", 0,0, 0,0);
0343     c1->SetLogz(true);
0344     SaveCanvas(c1,"Pictures/Error_Vs_MPV", true);
0345     delete c1;
0346 
0347     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0348     Histos[0] = MPVErrorVsEta;                     legend.push_back("Error Vs Eta");
0349     DrawTH2D((TH2D**)Histos,legend, "COLZ", "module #eta", "Error on MPV (ADC/mm)", 0,0, 0,0);
0350     c1->SetLogz(true);
0351     SaveCanvas(c1,"Pictures/Error_Vs_Eta", true);
0352     delete c1;
0353 
0354     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0355     Histos[0] = MPVErrorVsPhi;                     legend.push_back("Error Vs Phi");
0356     DrawTH2D((TH2D**)Histos,legend, "COLZ", "module #phi", "Error on MPV (ADC/mm)", 0,0, 0,0);
0357     c1->SetLogz(true);
0358     SaveCanvas(c1,"Pictures/Error_Vs_Phi", true);
0359     delete c1;
0360 
0361     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0362     Histos[0] = MPVErrorVsN;                       legend.push_back("Error Vs Entries");
0363     DrawTH2D((TH2D**)Histos,legend, "COLZ", "Number of Entries", "Error on MPV (ADC/mm)", 0,0, 0,0);
0364     c1->SetLogz(true);
0365     SaveCanvas(c1,"Pictures/Error_Vs_N", true);
0366     delete c1;
0367 
0368     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0369     Histos[0] = ChargeTEC;                         legend.push_back("TEC");
0370     Histos[1] = ChargeTIB;                         legend.push_back("TIB");
0371     Histos[2] = ChargeTID;                         legend.push_back("TID");
0372     Histos[3] = ChargeTOB;                         legend.push_back("TOB");
0373     DrawSuperposedHistos((TH1D**)Histos, legend, "",  "Charge (ADC/mm)", "#clusters", 0,800 , 0,0);
0374     DrawLegend(Histos,legend,"","L");
0375     DrawStatBox(Histos,legend,true, 0.6, 0.7);
0376     SaveCanvas(c1,"Pictures/Charge");
0377     delete c1;
0378 
0379     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0380     Histos[0] = ChargeTECP;                        legend.push_back("TEC+");
0381     Histos[1] = ChargeTECM;                        legend.push_back("TEC-");
0382     DrawSuperposedHistos((TH1D**)Histos, legend, "",  "Charge (ADC/mm)", "#clusters", 0,800 , 0,0);
0383     DrawLegend(Histos,legend,"","L");
0384     DrawStatBox(Histos,legend,true, 0.6, 0.7);
0385     SaveCanvas(c1,"Pictures/ChargeTECSide");
0386     delete c1;
0387 
0388     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0389     Histos[0] = ChargeTEC1;                        legend.push_back("TEC Thin");
0390     Histos[1] = ChargeTEC2;                        legend.push_back("TEC Thick");
0391     DrawSuperposedHistos((TH1D**)Histos, legend, "",  "Charge (ADC/mm)", "#clusters", 0,800 , 0,0);
0392     DrawLegend(Histos,legend,"","L");
0393     DrawStatBox(Histos,legend,true, 0.6, 0.7);
0394     SaveCanvas(c1,"Pictures/ChargeTECThickness");
0395     delete c1;
0396 
0397     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0398     Histos[0] = ChargeTIDP;                        legend.push_back("TID+");
0399     Histos[1] = ChargeTIDM;                        legend.push_back("TID-");
0400     DrawSuperposedHistos((TH1D**)Histos, legend, "",  "Charge (ADC/mm)", "#clusters", 0,800 , 0,0);
0401     DrawLegend(Histos,legend,"","L");
0402     DrawStatBox(Histos,legend,true, 0.6, 0.7);
0403     SaveCanvas(c1,"Pictures/ChargeTIDSide");
0404     delete c1;
0405 
0406     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0407     Histos[0] = ChargeAbsTEC;                      legend.push_back("TEC");
0408     Histos[1] = ChargeAbsTIB;                      legend.push_back("TIB");
0409     Histos[2] = ChargeAbsTID;                      legend.push_back("TID");
0410     Histos[3] = ChargeAbsTOB;                      legend.push_back("TOB");
0411     DrawSuperposedHistos((TH1D**)Histos, legend, "",  "Charge (ADC)", "#clusters", 0,800 , 0,0);
0412     DrawLegend(Histos,legend,"","L");
0413     DrawStatBox(Histos,legend,true, 0.6, 0.7);
0414     SaveCanvas(c1,"Pictures/ChargeAbs");
0415     delete c1;
0416 
0417     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0418     Histos[0] = ChargeAbsTECP;                     legend.push_back("TEC+");
0419     Histos[1] = ChargeAbsTECM;                     legend.push_back("TEC-");
0420     DrawSuperposedHistos((TH1D**)Histos, legend, "",  "Charge (ADC)", "#clusters", 0,800 , 0,0);
0421     DrawLegend(Histos,legend,"","L");
0422     DrawStatBox(Histos,legend,true, 0.6, 0.7);
0423     SaveCanvas(c1,"Pictures/ChargeAbsTECSide");
0424     delete c1;
0425 
0426     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0427     Histos[0] = ChargeAbsTEC1;                     legend.push_back("TEC Thin");
0428     Histos[1] = ChargeAbsTEC2;                     legend.push_back("TEC Thick");
0429     DrawSuperposedHistos((TH1D**)Histos, legend, "",  "Charge (ADC)", "#clusters", 0,800 , 0,0);
0430     DrawLegend(Histos,legend,"","L");
0431     DrawStatBox(Histos,legend,true, 0.6, 0.7);
0432     SaveCanvas(c1,"Pictures/ChargeAbsTECThickness");
0433     delete c1;
0434 
0435     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0436     Histos[0] = ChargeAbsTIDP;                     legend.push_back("TID+");
0437     Histos[1] = ChargeAbsTIDM;                     legend.push_back("TID-");
0438     DrawSuperposedHistos((TH1D**)Histos, legend, "",  "Charge (ADC)", "#clusters", 0,800 , 0,0);
0439     DrawLegend(Histos,legend,"","L");
0440     DrawStatBox(Histos,legend,true, 0.6, 0.7);
0441     SaveCanvas(c1,"Pictures/ChargeAbsTIDSide");
0442     delete c1;
0443 
0444 
0445     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0446     Histos[0] = MPV_Vs_PathlengthThin;             legend.push_back("320 #mum");
0447     Histos[1] = MPV_Vs_PathlengthThick;            legend.push_back("500 #mum");
0448     DrawSuperposedHistos((TH1D**)Histos, legend, "HIST",  "pathlength (mm)", "MPV (ADC/mm)", 0,0 , 230,380);
0449     DrawLegend(Histos,legend,"","L");
0450     SaveCanvas(c1,"Pictures/MPV_Vs_Path");
0451     delete c1;
0452 
0453 
0454     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0455     Histos[0] = MPV_Vs_PathlengthTIB;              legend.push_back("TIB (320 #mum)");
0456     Histos[1] = MPV_Vs_PathlengthTID;              legend.push_back("TID (320 #mum)");
0457     Histos[2] = MPV_Vs_PathlengthTOB;              legend.push_back("TOB (500 #mum)");
0458     Histos[3] = MPV_Vs_PathlengthTEC1;             legend.push_back("TEC (320 #mum)");
0459     Histos[4] = MPV_Vs_PathlengthTEC2;             legend.push_back("TEC (500 #mum)");
0460     DrawSuperposedHistos((TH1D**)Histos, legend, "HIST",  "pathlength (mm)", "MPV (ADC/mm)", 0,0 , 230,380);
0461     DrawLegend(Histos,legend,"","L");
0462     SaveCanvas(c1,"Pictures/MPV_Vs_PathSubDet");
0463     delete c1;
0464 }
0465 
0466 
0467 
0468 TObject* GetObjectFromPath(TDirectory* File, const char* Path)
0469 {
0470    string str(Path);
0471    size_t pos = str.find("/");
0472 
0473    if(pos < 256){
0474       string firstPart = str.substr(0,pos);
0475       string endPart   = str.substr(pos+1,str.length());
0476       TDirectory* TMP = (TDirectory*)File->Get(firstPart.c_str());
0477       if(TMP!=NULL)return GetObjectFromPath(TMP,endPart.c_str());
0478 
0479       printf("BUG\n");
0480       return NULL;
0481    }else{
0482       return File->Get(Path);
0483    }
0484 
0485 }
0486 
0487 void SaveCanvas(TCanvas* c, char* path, bool OnlyPPNG){
0488    char buff[1024];
0489    sprintf(buff,"%s.png",path);  c->SaveAs(buff);   if(OnlyPPNG)return;
0490    sprintf(buff,"%s.eps",path);  c->SaveAs(buff);
0491    sprintf(buff,"%s.c"  ,path);  c->SaveAs(buff);
0492 }
0493 
0494 void DrawLegend(TObject** Histos, std::vector<char*> legend, char* Title, char* Style, double X, double Y, double W, double H)
0495 {
0496    int    N             = legend.size();
0497 
0498    if(strcmp(legend[0],"")!=0){
0499       TLegend* leg;
0500       leg = new TLegend(X,Y,X-W,Y - N*H);
0501       leg->SetFillColor(0);
0502       leg->SetBorderSize(0);
0503       if(strcmp(Title,"")!=0)leg->SetHeader(Title);
0504 
0505       for(int i=0;i<N;i++){
0506          TH2D* temp = (TH2D*)Histos[i]->Clone();
0507          temp->SetMarkerSize(1.3);
0508          leg->AddEntry(temp, legend[i] ,Style);
0509       }
0510       leg->Draw();
0511    }
0512 }
0513 
0514 
0515 void DrawStatBox(TObject** Histos, std::vector<char*> legend, bool Mean, double X, double Y, double W, double H)
0516 {
0517    int    N             = legend.size();
0518    char   buffer[255];
0519 
0520    if(Mean)H*=3;
0521    for(int i=0;i<N;i++){
0522            TPaveText* stat = new TPaveText(X,Y-(i*H), X+W, Y-(i+1)*H, "NDC");
0523        TH1* Histo = (TH1*)Histos[i];
0524            sprintf(buffer,"Entries : %i\n",(int)Histo->GetEntries());
0525            stat->AddText(buffer);
0526 
0527            if(Mean){
0528            sprintf(buffer,"Mean    : %6.2f\n",Histo->GetMean());
0529            stat->AddText(buffer);
0530 
0531            sprintf(buffer,"RMS     : %6.2f\n",Histo->GetRMS());
0532            stat->AddText(buffer);
0533            }
0534 
0535            stat->SetFillColor(0);
0536            stat->SetLineColor(Color[i]);
0537            stat->SetTextColor(Color[i]);
0538            stat->SetBorderSize(0);
0539            stat->SetMargin(0.05);
0540            stat->SetTextAlign(12);
0541            stat->Draw();
0542    }
0543 }
0544 
0545 
0546 
0547 void DrawTH2D(TH2D** Histos, std::vector<char*> legend, char* Style, char* Xlegend, char* Ylegend, double xmin, double xmax, double ymin, double ymax)
0548 {
0549    int    N             = legend.size();
0550 
0551    for(int i=0;i<N;i++){
0552         if(!Histos[i])continue;
0553         Histos[i]->SetTitle("");
0554         Histos[i]->SetStats(kFALSE);
0555         Histos[i]->GetXaxis()->SetTitle(Xlegend);
0556         Histos[i]->GetYaxis()->SetTitle(Ylegend);
0557         Histos[i]->GetYaxis()->SetTitleOffset(1.60);
0558         if(xmin!=xmax)Histos[i]->SetAxisRange(xmin,xmax,"X");
0559         if(ymin!=ymax)Histos[i]->SetAxisRange(ymin,ymax,"Y");
0560         Histos[i]->SetMarkerStyle(Marker[i]);
0561         Histos[i]->SetMarkerColor(Color[i]);
0562         Histos[i]->SetMarkerSize(0.3);
0563    }
0564 
0565    char Buffer[256];
0566    Histos[0]->Draw(Style);
0567    for(int i=1;i<N;i++){
0568         sprintf(Buffer,"%s same",Style);
0569         Histos[i]->Draw(Buffer);
0570    }
0571 }
0572 
0573 void DrawSuperposedHistos(TH1D** Histos, std::vector<char*> legend, char* Style,  char* Xlegend, char* Ylegend, double xmin, double xmax, double ymin, double ymax)
0574 {
0575    int    N             = legend.size();
0576 
0577    double HistoMax      = -1;
0578    int    HistoHeighest = -1;
0579 
0580    for(int i=0;i<N;i++){
0581         if(!Histos[i])continue;
0582         Histos[i]->SetTitle("");
0583         Histos[i]->SetStats(kFALSE);
0584         Histos[i]->GetXaxis()->SetTitle(Xlegend);
0585         Histos[i]->GetYaxis()->SetTitle(Ylegend);
0586         Histos[i]->GetYaxis()->SetTitleOffset(1.60);
0587         if(xmin!=xmax)Histos[i]->SetAxisRange(xmin,xmax,"X");
0588         if(ymin!=ymax)Histos[i]->SetAxisRange(ymin,ymax,"Y");
0589         Histos[i]->SetFillColor(0);
0590         Histos[i]->SetMarkerStyle(Marker[i]);
0591         Histos[i]->SetMarkerColor(Color[i]);
0592         Histos[i]->SetMarkerSize(0.5);
0593         Histos[i]->SetLineColor(Color[i]);
0594         Histos[i]->SetLineWidth(2);
0595 
0596         if(Histos[i]->GetMaximum() >= HistoMax){
0597        HistoMax      = Histos[i]->GetMaximum();
0598            HistoHeighest = i;
0599     }
0600 
0601    }
0602 
0603    char Buffer[256];
0604    Histos[HistoHeighest]->Draw(Style);
0605    for(int i=0;i<N;i++){        
0606         if(strcmp(Style,"")!=0){
0607            sprintf(Buffer,"same %s",Style);
0608         }else{
0609            sprintf(Buffer,"same");
0610         }
0611         Histos[i]->Draw(Buffer);
0612    }
0613 }
0614 
0615 
0616 TF1* getLandau(TH1* InputHisto, double* FitResults, double LowRange, double HighRange)
0617 {
0618    FitResults[0]         = -0.5;  //MPV
0619    FitResults[1]         =  0;    //MPV error
0620    FitResults[2]         = -0.5;  //Width
0621    FitResults[3]         =  0;    //Width error
0622    FitResults[4]         = -0.5;  //Fit Chi2/NDF
0623 
0624    // perform fit with standard landau
0625    TF1* MyLandau = new TF1("MyLandau","landau",LowRange, HighRange);
0626    MyLandau->SetParameter(1,300);
0627    InputHisto->Fit("MyLandau","0QR WW");
0628 
0629    // MPV is parameter 1 (0=constant, 1=MPV, 2=Sigma)
0630    FitResults[0]         = MyLandau->GetParameter(1);  //MPV
0631    FitResults[1]         = MyLandau->GetParError(1);   //MPV error
0632    FitResults[2]         = MyLandau->GetParameter(2);  //Width
0633    FitResults[3]         = MyLandau->GetParError(2);   //Width error
0634    FitResults[4]         = MyLandau->GetChisquare() / MyLandau->GetNDF();  //Fit Chi2/NDF
0635 
0636    return MyLandau;
0637 }
0638 
0639 TH1D* ChargeToMPV(TH2* InputHisto, char* Name,  bool DivideByX)
0640 {
0641    TH1D* toReturn = new TH1D(Name,Name,InputHisto->GetXaxis()->GetNbins(), InputHisto->GetXaxis()->GetXmin(), InputHisto->GetXaxis()->GetXmax() );
0642    double Results[4];
0643 
0644    for(int i=0;i<=InputHisto->GetXaxis()->GetNbins();i++){
0645       TH1D* proj   = InputHisto->ProjectionY("",i,i);
0646       if(proj->GetEntries()<50){delete proj;continue;}
0647 
0648       TF1*  landau = getLandau(proj,Results);
0649 
0650       if(DivideByX){
0651          toReturn->SetBinContent(i,Results[0] / InputHisto->GetXaxis()->GetBinCenter(i) );
0652          toReturn->SetBinError  (i,Results[1] / InputHisto->GetXaxis()->GetBinCenter(i) );
0653       }else{
0654          toReturn->SetBinContent(i,Results[0]);
0655          toReturn->SetBinError  (i,Results[1]);
0656       }
0657       delete landau;
0658       delete proj;
0659    }
0660    return toReturn;
0661 }
0662