Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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 #include "PlotFunction.h"
0019 
0020 
0021 #include<vector>
0022 #include<tdrstyle.C>
0023 
0024 void PlotMacro_Core(string input, string moduleName, string output);
0025 TF1*  getLandau(TH1* InputHisto, double* FitResults, double LowRange=50, double HighRange=5400);
0026 TH1D* ChargeToMPV(TH2* InputHisto, string Name, bool DivideByX);
0027 
0028 int DataType = 2;
0029 
0030 void PlotMacro(){
0031    gROOT->Reset();
0032    setTDRStyle();
0033    gStyle->SetPadTopMargin   (0.05);
0034    gStyle->SetPadBottomMargin(0.10);
0035    gStyle->SetPadRightMargin (0.18);
0036    gStyle->SetPadLeftMargin  (0.13);
0037    gStyle->SetTitleSize(0.04, "XYZ");
0038    gStyle->SetTitleXOffset(1.1);
0039    gStyle->SetTitleYOffset(1.35);
0040    gStyle->SetPalette(1);
0041    gStyle->SetCanvasColor(0);
0042    gStyle->SetBarOffset(0);
0043 
0044    
0045    system("mkdir Pictures");
0046    PlotMacro_Core("file:Gains_Tree.root",      , "SiStripCalib/"          , "Pictures/Gains");
0047 }
0048 
0049 
0050 void PlotMacro_Core(string input, string moduleName, string output)
0051 {
0052    FILE* pFile;
0053    TCanvas* c1;
0054    TObject** Histos = new TObject*[10];                
0055    std::vector<string> legend;
0056 
0057    unsigned int  tree_Index;
0058    unsigned int  tree_DetId;
0059    unsigned char tree_APVId;
0060    unsigned char tree_SubDet;
0061    float         tree_x;
0062    float         tree_y;
0063    float         tree_z;
0064    float         tree_Eta;
0065    float         tree_R;
0066    float         tree_Phi;
0067    float         tree_Thickness;
0068    float         tree_FitMPV;
0069    float         tree_FitMPVErr;
0070    float         tree_FitWidth;
0071    float         tree_FitWidthErr;
0072    float         tree_FitChi2NDF;
0073    double        tree_Gain;
0074    double        tree_PrevGain;
0075    double        tree_NEntries;
0076    bool          tree_isMasked;
0077 
0078    TFile* f1     = new TFile(input.c_str());
0079    TTree *t1     = (TTree*)GetObjectFromPath(f1,moduleName+"APVGain");
0080 
0081    t1->SetBranchAddress("Index"             ,&tree_Index      );
0082    t1->SetBranchAddress("DetId"             ,&tree_DetId      );
0083    t1->SetBranchAddress("APVId"             ,&tree_APVId      );
0084    t1->SetBranchAddress("SubDet"            ,&tree_SubDet     );
0085    t1->SetBranchAddress("x"                 ,&tree_x          );
0086    t1->SetBranchAddress("y"                 ,&tree_y          );
0087    t1->SetBranchAddress("z"                 ,&tree_z          );
0088    t1->SetBranchAddress("Eta"               ,&tree_Eta        );
0089    t1->SetBranchAddress("R"                 ,&tree_R          );
0090    t1->SetBranchAddress("Phi"               ,&tree_Phi        );
0091    t1->SetBranchAddress("Thickness"         ,&tree_Thickness  );
0092    t1->SetBranchAddress("FitMPV"            ,&tree_FitMPV     );
0093    t1->SetBranchAddress("FitMPVErr"         ,&tree_FitMPVErr  );
0094    t1->SetBranchAddress("FitWidth"          ,&tree_FitWidth   );
0095    t1->SetBranchAddress("FitWidthErr"       ,&tree_FitWidthErr);
0096    t1->SetBranchAddress("FitChi2NDF"        ,&tree_FitChi2NDF );
0097    t1->SetBranchAddress("Gain"              ,&tree_Gain       );
0098    t1->SetBranchAddress("PrevGain"          ,&tree_PrevGain   );
0099    t1->SetBranchAddress("NEntries"          ,&tree_NEntries   );
0100    t1->SetBranchAddress("isMasked"          ,&tree_isMasked   );
0101 
0102 
0103    TH2D* ChargeDistrib  = (TH2D*)GetObjectFromPath(f1,moduleName+"Charge_Vs_Index");
0104    TH2D* ChargeDistribA = (TH2D*)GetObjectFromPath(f1,moduleName+"Charge_Vs_Index_Absolute");
0105 
0106    TH2D* Charge_Vs_PathlengthTIB   = (TH2D*)GetObjectFromPath(f1,moduleName+"Charge_Vs_PathlengthTIB");
0107    TH2D* Charge_Vs_PathlengthTOB   = (TH2D*)GetObjectFromPath(f1,moduleName+"Charge_Vs_PathlengthTOB");
0108    TH2D* Charge_Vs_PathlengthTIDP  = (TH2D*)GetObjectFromPath(f1,moduleName+"Charge_Vs_PathlengthTIDP");
0109    TH2D* Charge_Vs_PathlengthTIDM  = (TH2D*)GetObjectFromPath(f1,moduleName+"Charge_Vs_PathlengthTIDM");
0110    TH2D* Charge_Vs_PathlengthTID   = (TH2D*)Charge_Vs_PathlengthTIDP->Clone("Charge_Vs_PathlengthTID");
0111          Charge_Vs_PathlengthTID      ->Add(Charge_Vs_PathlengthTIDM);
0112    TH2D* Charge_Vs_PathlengthTECP1 = (TH2D*)GetObjectFromPath(f1,moduleName+"Charge_Vs_PathlengthTECP1");
0113    TH2D* Charge_Vs_PathlengthTECP2 = (TH2D*)GetObjectFromPath(f1,moduleName+"Charge_Vs_PathlengthTECP2");
0114    TH2D* Charge_Vs_PathlengthTECM1 = (TH2D*)GetObjectFromPath(f1,moduleName+"Charge_Vs_PathlengthTECM1");
0115    TH2D* Charge_Vs_PathlengthTECM2 = (TH2D*)GetObjectFromPath(f1,moduleName+"Charge_Vs_PathlengthTECM2");
0116    TH2D* Charge_Vs_PathlengthTECP  = (TH2D*)Charge_Vs_PathlengthTECP1->Clone("Charge_Vs_PathlengthTECP");
0117          Charge_Vs_PathlengthTECP     ->Add(Charge_Vs_PathlengthTECP2);
0118    TH2D* Charge_Vs_PathlengthTECM  = (TH2D*)Charge_Vs_PathlengthTECM1->Clone("Charge_Vs_PathlengthTECM");
0119          Charge_Vs_PathlengthTECM     ->Add(Charge_Vs_PathlengthTECM2);
0120    TH2D* Charge_Vs_PathlengthTEC1  = (TH2D*)Charge_Vs_PathlengthTECP1->Clone("Charge_Vs_PathlengthTEC1");
0121          Charge_Vs_PathlengthTEC1     ->Add(Charge_Vs_PathlengthTECM1);
0122    TH2D* Charge_Vs_PathlengthTEC2  = (TH2D*)Charge_Vs_PathlengthTECP2->Clone("Charge_Vs_PathlengthTEC2");
0123          Charge_Vs_PathlengthTEC2     ->Add(Charge_Vs_PathlengthTECM2); 
0124    TH2D* Charge_Vs_PathlengthTEC   = (TH2D*)Charge_Vs_PathlengthTECP ->Clone("Charge_Vs_PathlengthTEC");
0125          Charge_Vs_PathlengthTEC      ->Add(Charge_Vs_PathlengthTECM );
0126 
0127    TH2D* Charge_Vs_PathlengthThin  = (TH2D*)Charge_Vs_PathlengthTEC1->Clone("Charge_Vs_PathlengthThin");
0128          Charge_Vs_PathlengthThin     ->Add(Charge_Vs_PathlengthTIB );
0129          Charge_Vs_PathlengthThin     ->Add(Charge_Vs_PathlengthTID );
0130    TH2D* Charge_Vs_PathlengthThick = (TH2D*)Charge_Vs_PathlengthTEC2->Clone("Charge_Vs_PathlengthThin");
0131          Charge_Vs_PathlengthThick    ->Add(Charge_Vs_PathlengthTOB );
0132 
0133    TH1D* MPV_Vs_PathlengthTIB      = ChargeToMPV(Charge_Vs_PathlengthTIB  ,"MPV_Vs_PathlengthTIB"  , true);
0134    TH1D* MPV_Vs_PathlengthTID      = ChargeToMPV(Charge_Vs_PathlengthTID  ,"MPV_Vs_PathlengthTID"  , true);
0135 // TH1D* MPV_Vs_PathlengthTIDP     = ChargeToMPV(Charge_Vs_PathlengthTIDP ,"MPV_Vs_PathlengthTIDP" , true);
0136 // TH1D* MPV_Vs_PathlengthTIDM     = ChargeToMPV(Charge_Vs_PathlengthTIDM ,"MPV_Vs_PathlengthTIDM" , true);
0137 
0138 
0139 
0140    TH1D* MPV_Vs_PathlengthTOB      = ChargeToMPV(Charge_Vs_PathlengthTOB  ,"MPV_Vs_PathlengthTOB"  , true);
0141 // TH1D* MPV_Vs_PathlengthTEC      = ChargeToMPV(Charge_Vs_PathlengthTEC  ,"MPV_Vs_PathlengthTEC"  , true);
0142 // TH1D* MPV_Vs_PathlengthTECP     = ChargeToMPV(Charge_Vs_PathlengthTECP ,"MPV_Vs_PathlengthTECP" , true);
0143 // TH1D* MPV_Vs_PathlengthTECM     = ChargeToMPV(Charge_Vs_PathlengthTECM ,"MPV_Vs_PathlengthTECM" , true);
0144    TH1D* MPV_Vs_PathlengthTEC1     = ChargeToMPV(Charge_Vs_PathlengthTEC1 ,"MPV_Vs_PathlengthTEC1" , true);
0145    TH1D* MPV_Vs_PathlengthTEC2     = ChargeToMPV(Charge_Vs_PathlengthTEC2 ,"MPV_Vs_PathlengthTEC2" , true);
0146 
0147 
0148 // TH1D* MPV_Vs_PathlengthTECP1    = ChargeToMPV(Charge_Vs_PathlengthTECP1,"MPV_Vs_PathlengthTECP1", true);
0149 // TH1D* MPV_Vs_PathlengthTECP2    = ChargeToMPV(Charge_Vs_PathlengthTECP2,"MPV_Vs_PathlengthTECP2", true);
0150 // TH1D* MPV_Vs_PathlengthTECM1    = ChargeToMPV(Charge_Vs_PathlengthTECM1,"MPV_Vs_PathlengthTECM1", true);
0151 // TH1D* MPV_Vs_PathlengthTECM2    = ChargeToMPV(Charge_Vs_PathlengthTECM2,"MPV_Vs_PathlengthTECM2", true);
0152    TH1D* MPV_Vs_PathlengthThin     = ChargeToMPV(Charge_Vs_PathlengthThin ,"MPV_Vs_PathlengthThin" , true);
0153    TH1D* MPV_Vs_PathlengthThick    = ChargeToMPV(Charge_Vs_PathlengthThick,"MPV_Vs_PathlengthThick", true);
0154 
0155 
0156 
0157    TH2D* MPV_Vs_EtaTIB  = new TH2D("MPV_Vs_EtaTIB" ,"MPV_Vs_EtaTIB" , 50, -3.0, 3.0, 300, 0, 600);
0158    TH2D* MPV_Vs_EtaTID  = new TH2D("MPV_Vs_EtaTID" ,"MPV_Vs_EtaTID" , 50, -3.0, 3.0, 300, 0, 600);
0159    TH2D* MPV_Vs_EtaTOB  = new TH2D("MPV_Vs_EtaTOB" ,"MPV_Vs_EtaTOB" , 50, -3.0, 3.0, 300, 0, 600);
0160    TH2D* MPV_Vs_EtaTEC  = new TH2D("MPV_Vs_EtaTEC" ,"MPV_Vs_EtaTEC" , 50, -3.0, 3.0, 300, 0, 600);
0161    TH2D* MPV_Vs_EtaTEC1 = new TH2D("MPV_Vs_EtaTEC1","MPV_Vs_EtaTEC1", 50, -3.0, 3.0, 300, 0, 600);
0162    TH2D* MPV_Vs_EtaTEC2 = new TH2D("MPV_Vs_EtaTEC2","MPV_Vs_EtaTEC2", 50, -3.0, 3.0, 300, 0, 600);
0163 
0164    TH2D* MPV_Vs_PhiTIB  = new TH2D("MPV_Vs_PhiTIB" ,"MPV_Vs_PhiTIB" , 50, -3.4, 3.4, 300, 0, 600);
0165    TH2D* MPV_Vs_PhiTID  = new TH2D("MPV_Vs_PhiTID" ,"MPV_Vs_PhiTID" , 50, -3.4, 3.4, 300, 0, 600);
0166    TH2D* MPV_Vs_PhiTOB  = new TH2D("MPV_Vs_PhiTOB" ,"MPV_Vs_PhiTOB" , 50, -3.4, 3.4, 300, 0, 600);
0167    TH2D* MPV_Vs_PhiTEC  = new TH2D("MPV_Vs_PhiTEC" ,"MPV_Vs_PhiTEC" , 50, -3.4, 3.4, 300, 0, 600);
0168    TH2D* MPV_Vs_PhiTEC1 = new TH2D("MPV_Vs_PhiTEC1","MPV_Vs_PhiTEC1", 50, -3.4, 3.4, 300, 0, 600);
0169    TH2D* MPV_Vs_PhiTEC2 = new TH2D("MPV_Vs_PhiTEC2","MPV_Vs_PhiTEC2", 50, -3.4, 3.4, 300, 0, 600);
0170 
0171    TH2D* NoMPV          = new TH2D("NoMPV"         ,"NoMPV"         ,350, -350, 350, 240, 0, 120);
0172 
0173 
0174 
0175    TH1D* Gains          = new TH1D("Gains"         ,"Gains"         ,                300, 0, 2);
0176    TH1D* MPVs           = new TH1D("MPVs"          ,"MPVs"          ,                300, 0, 600);
0177    TH1D* MPVs320        = new TH1D("MPVs320"       ,"MPVs320"       ,                300, 0, 600);
0178    TH1D* MPVs500        = new TH1D("MPVs500"       ,"MPVs500"       ,                300, 0, 600);
0179    TH1D* MPVsTIB        = new TH1D("MPVsTIB"       ,"MPVsTIB"       ,                300, 0, 600);
0180    TH1D* MPVsTID        = new TH1D("MPVsTID"       ,"MPVsTID"       ,                300, 0, 600);
0181    TH1D* MPVsTIDP       = new TH1D("MPVsTIDP"      ,"MPVsTIDP"      ,                300, 0, 600);
0182    TH1D* MPVsTIDM       = new TH1D("MPVsTIDM"      ,"MPVsTIDM"      ,                300, 0, 600);
0183    TH1D* MPVsTOB        = new TH1D("MPVsTOB"       ,"MPVsTOB"       ,                300, 0, 600);
0184    TH1D* MPVsTEC        = new TH1D("MPVsTEC"       ,"MPVsTEC"       ,                300, 0, 600);
0185    TH1D* MPVsTECP       = new TH1D("MPVsTECP"      ,"MPVsTECP"      ,                300, 0, 600);
0186    TH1D* MPVsTECM       = new TH1D("MPVsTECM"      ,"MPVsTECM"      ,                300, 0, 600);
0187    TH1D* MPVsTEC1       = new TH1D("MPVsTEC1"      ,"MPVsTEC1"      ,                300, 0, 600);
0188    TH1D* MPVsTEC2       = new TH1D("MPVsTEC2"      ,"MPVsTEC2"      ,                300, 0, 600);
0189    TH1D* MPVsTECP1      = new TH1D("MPVsTECP1"     ,"MPVsTECP1"     ,                300, 0, 600);
0190    TH1D* MPVsTECP2      = new TH1D("MPVsTECP2"     ,"MPVsTECP2"     ,                300, 0, 600);
0191    TH1D* MPVsTECM1      = new TH1D("MPVsTECM1"     ,"MPVsTECM1"     ,                300, 0, 600);
0192    TH1D* MPVsTECM2      = new TH1D("MPVsTECM2"     ,"MPVsTECM2"     ,                300, 0, 600);
0193 
0194 
0195    TH1D* MPVError       = new TH1D("MPVError"      ,"MPVError"      ,                150, 0, 150);
0196    TH2D* MPVErrorVsMPV  = new TH2D("MPVErrorVsMPV" ,"MPVErrorVsMPV" ,300,    0, 600, 150, 0, 150);
0197    TH2D* MPVErrorVsEta  = new TH2D("MPVErrorVsEta" ,"MPVErrorVsEta" , 50, -3.0, 3.0, 150, 0, 150); 
0198    TH2D* MPVErrorVsPhi  = new TH2D("MPVErrorVsPhi" ,"MPVErrorVsPhi" , 50, -3.4, 3.4, 150, 0, 150);             
0199    TH2D* MPVErrorVsN    = new TH2D("MPVErrorVsN"   ,"MPVErrorVsN"   ,500,    0,1000, 150, 0, 150);              
0200 
0201 
0202 
0203 
0204    TH1D* ChargeTIB      = new TH1D("ChargeTIB"     ,"ChargeTIB"     ,               1000, 0,2000);
0205    TH1D* ChargeTID      = new TH1D("ChargeTID"     ,"ChargeTID"     ,               1000, 0,2000);
0206    TH1D* ChargeTIDP     = new TH1D("ChargeTIDP"    ,"ChargeTIDP"    ,               1000, 0,2000);
0207    TH1D* ChargeTIDM     = new TH1D("ChargeTIDM"    ,"ChargeTIDM"    ,               1000, 0,2000);
0208    TH1D* ChargeTOB      = new TH1D("ChargeTOB"     ,"ChargeTOB"     ,               1000, 0,2000);
0209    TH1D* ChargeTEC      = new TH1D("ChargeTEC"     ,"ChargeTEC"     ,               1000, 0,2000);
0210    TH1D* ChargeTECP     = new TH1D("ChargeTECP"    ,"ChargeTECP"    ,               1000, 0,2000);
0211    TH1D* ChargeTECM     = new TH1D("ChargeTECM"    ,"ChargeTECM"    ,               1000, 0,2000);
0212    TH1D* ChargeTEC1     = new TH1D("ChargeTEC1"    ,"ChargeTEC1"    ,               1000, 0,2000);
0213    TH1D* ChargeTEC2     = new TH1D("ChargeTEC2"    ,"ChargeTEC2"    ,               1000, 0,2000);
0214    TH1D* ChargeTECP1    = new TH1D("ChargeTECP1"   ,"ChargeTECP1"   ,               1000, 0,2000);
0215    TH1D* ChargeTECP2    = new TH1D("ChargeTECP2"   ,"ChargeTECP2"   ,               1000, 0,2000);
0216    TH1D* ChargeTECM1    = new TH1D("ChargeTECM1"   ,"ChargeTECM1"   ,               1000, 0,2000);
0217    TH1D* ChargeTECM2    = new TH1D("ChargeTECM2"   ,"ChargeTECM2"   ,               1000, 0,2000);
0218 
0219    TH1D* ChargeAbsTIB   = new TH1D("ChargeAbsTIB"  ,"ChargeAbsTIB"  ,                500, 0,2000);
0220    TH1D* ChargeAbsTID   = new TH1D("ChargeAbsTID"  ,"ChargeAbsTID"  ,                500, 0,2000);
0221    TH1D* ChargeAbsTIDP  = new TH1D("ChargeAbsTIDP" ,"ChargeAbsTIDP" ,                500, 0,2000);
0222    TH1D* ChargeAbsTIDM  = new TH1D("ChargeAbsTIDM" ,"ChargeAbsTIDM" ,                500, 0,2000);
0223    TH1D* ChargeAbsTOB   = new TH1D("ChargeAbsTOB"  ,"ChargeAbsTOB"  ,                500, 0,2000);
0224    TH1D* ChargeAbsTEC   = new TH1D("ChargeAbsTEC"  ,"ChargeAbsTEC"  ,                500, 0,2000);
0225    TH1D* ChargeAbsTECP  = new TH1D("ChargeAbsTECP" ,"ChargeAbsTECP" ,                500, 0,2000);
0226    TH1D* ChargeAbsTECM  = new TH1D("ChargeAbsTECM" ,"ChargeAbsTECM" ,                500, 0,2000);
0227    TH1D* ChargeAbsTEC1  = new TH1D("ChargeAbsTEC1" ,"ChargeAbsTEC1" ,                500, 0,2000);
0228    TH1D* ChargeAbsTEC2  = new TH1D("ChargeAbsTEC2" ,"ChargeAbsTEC2" ,                500, 0,2000);
0229    TH1D* ChargeAbsTECP1 = new TH1D("ChargeAbsTECP1","ChargeAbsTECP1",                500, 0,2000);
0230    TH1D* ChargeAbsTECP2 = new TH1D("ChargeAbsTECP2","ChargeAbsTECP2",                500, 0,2000);
0231    TH1D* ChargeAbsTECM1 = new TH1D("ChargeAbsTECM1","ChargeAbsTECM1",                500, 0,2000);
0232    TH1D* ChargeAbsTECM2 = new TH1D("ChargeAbsTECM2","ChargeAbsTECM2",                500, 0,2000);
0233 
0234    TH1D* DiffWRTPrevGainTIB      = new TH1D("DiffWRTPrevGainTIB"     ,"DiffWRTPrevGainTIB"     ,               250, 0,2);
0235    TH1D* DiffWRTPrevGainTID      = new TH1D("DiffWRTPrevGainTID"     ,"DiffWRTPrevGainTID"     ,               250, 0,2);
0236    TH1D* DiffWRTPrevGainTOB      = new TH1D("DiffWRTPrevGainTOB"     ,"DiffWRTPrevGainTOB"     ,               250, 0,2);
0237    TH1D* DiffWRTPrevGainTEC      = new TH1D("DiffWRTPrevGainTEC"     ,"DiffWRTPrevGainTEC"     ,               250, 0,2);
0238 
0239    TH2D* GainVsPrevGainTIB      = new TH2D("GainVsPrevGainTIB"     ,"GainVsPrevGainTIB"     ,               100, 0,2, 100, 0,2);
0240    TH2D* GainVsPrevGainTID      = new TH2D("GainVsPrevGainTID"     ,"GainVsPrevGainTID"     ,               100, 0,2, 100, 0,2);
0241    TH2D* GainVsPrevGainTOB      = new TH2D("GainVsPrevGainTOB"     ,"GainVsPrevGainTOB"     ,               100, 0,2, 100, 0,2);
0242    TH2D* GainVsPrevGainTEC      = new TH2D("GainVsPrevGainTEC"     ,"GainVsPrevGainTEC"     ,               100, 0,2, 100, 0,2);
0243 
0244 
0245    printf("Progressing Bar              :0%%       20%%       40%%       60%%       80%%       100%%\n");
0246    printf("Looping on the Tree          :");
0247    int TreeStep = t1->GetEntries()/50;if(TreeStep==0)TreeStep=1;
0248    for (unsigned int ientry = 0; ientry < t1->GetEntries(); ientry++) {
0249       if(ientry%TreeStep==0){printf(".");fflush(stdout);}
0250       t1->GetEntry(ientry);
0251       int bin = ChargeDistrib->GetXaxis()->FindBin(tree_Index);
0252       TH1D* Proj         = ChargeDistrib ->ProjectionY("proj" ,bin, bin);
0253       TH1D* ProjAbsolute = ChargeDistribA->ProjectionY("projA",bin, bin);
0254 
0255       if(tree_FitMPV<0                        ) NoMPV         ->Fill(tree_z ,tree_R);
0256       if(tree_FitMPV>=0){
0257 
0258       if(tree_SubDet==3                       ) MPV_Vs_EtaTIB ->Fill(tree_Eta,tree_FitMPV);
0259       if(tree_SubDet==4                       ) MPV_Vs_EtaTID ->Fill(tree_Eta,tree_FitMPV);
0260       if(tree_SubDet==5                       ) MPV_Vs_EtaTOB ->Fill(tree_Eta,tree_FitMPV);
0261       if(tree_SubDet==6                       ) MPV_Vs_EtaTEC ->Fill(tree_Eta,tree_FitMPV);
0262       if(tree_SubDet==6 && tree_Thickness<0.04) MPV_Vs_EtaTEC1->Fill(tree_Eta,tree_FitMPV);
0263       if(tree_SubDet==6 && tree_Thickness>0.04) MPV_Vs_EtaTEC2->Fill(tree_Eta,tree_FitMPV);
0264 
0265       if(tree_SubDet==3                       ) MPV_Vs_PhiTIB ->Fill(tree_Phi,tree_FitMPV);
0266       if(tree_SubDet==4                       ) MPV_Vs_PhiTID ->Fill(tree_Phi,tree_FitMPV);
0267       if(tree_SubDet==5                       ) MPV_Vs_PhiTOB ->Fill(tree_Phi,tree_FitMPV);
0268       if(tree_SubDet==6                       ) MPV_Vs_PhiTEC ->Fill(tree_Phi,tree_FitMPV);
0269       if(tree_SubDet==6 && tree_Thickness<0.04) MPV_Vs_PhiTEC1->Fill(tree_Phi,tree_FitMPV);
0270       if(tree_SubDet==6 && tree_Thickness>0.04) MPV_Vs_PhiTEC2->Fill(tree_Phi,tree_FitMPV);
0271 
0272       if(tree_FitMPV>0                        ) Gains         ->Fill(         tree_Gain  );
0273                                                 MPVs          ->Fill(         tree_FitMPV);
0274       if(                  tree_Thickness<0.04) MPVs320       ->Fill(         tree_FitMPV);
0275       if(                  tree_Thickness>0.04) MPVs500       ->Fill(         tree_FitMPV);
0276       if(tree_SubDet==3                       ) MPVsTIB       ->Fill(         tree_FitMPV);
0277       if(tree_SubDet==4                       ) MPVsTID       ->Fill(         tree_FitMPV);
0278       if(tree_SubDet==4 && tree_Eta<0         ) MPVsTIDM      ->Fill(         tree_FitMPV);
0279       if(tree_SubDet==4 && tree_Eta>0         ) MPVsTIDP      ->Fill(         tree_FitMPV);
0280       if(tree_SubDet==5                       ) MPVsTOB       ->Fill(         tree_FitMPV);
0281       if(tree_SubDet==6                       ) MPVsTEC       ->Fill(         tree_FitMPV);
0282       if(tree_SubDet==6 && tree_Thickness<0.04) MPVsTEC1      ->Fill(         tree_FitMPV);
0283       if(tree_SubDet==6 && tree_Thickness>0.04) MPVsTEC2      ->Fill(         tree_FitMPV);
0284       if(tree_SubDet==6 && tree_Eta<0         ) MPVsTECP      ->Fill(         tree_FitMPV);
0285       if(tree_SubDet==6 && tree_Eta>0         ) MPVsTECM      ->Fill(         tree_FitMPV);
0286       if(tree_SubDet==6 && tree_Thickness<0.04 && tree_Eta>0) MPVsTECP1      ->Fill(         tree_FitMPV);
0287       if(tree_SubDet==6 && tree_Thickness>0.04 && tree_Eta>0) MPVsTECP2      ->Fill(         tree_FitMPV);
0288       if(tree_SubDet==6 && tree_Thickness<0.04 && tree_Eta<0) MPVsTECM1      ->Fill(         tree_FitMPV);
0289       if(tree_SubDet==6 && tree_Thickness>0.04 && tree_Eta<0) MPVsTECM2      ->Fill(         tree_FitMPV);
0290 
0291                                                 MPVError      ->Fill(         tree_FitMPVErr);    
0292                                                 MPVErrorVsMPV ->Fill(tree_FitMPV,tree_FitMPVErr);
0293                                                 MPVErrorVsEta ->Fill(tree_Eta,tree_FitMPVErr);
0294                                                 MPVErrorVsPhi ->Fill(tree_Phi,tree_FitMPVErr);
0295                                                 MPVErrorVsN   ->Fill(tree_NEntries,tree_FitMPVErr);
0296       }
0297 
0298 
0299       if(tree_SubDet==3                       ) ChargeTIB  ->Add(Proj,1);
0300       if(tree_SubDet==4                       ) ChargeTID  ->Add(Proj,1);
0301       if(tree_SubDet==4 && tree_Eta<0         ) ChargeTIDM ->Add(Proj,1);
0302       if(tree_SubDet==4 && tree_Eta>0         ) ChargeTIDP ->Add(Proj,1);
0303       if(tree_SubDet==5                       ) ChargeTOB  ->Add(Proj,1);
0304       if(tree_SubDet==6                       ) ChargeTEC  ->Add(Proj,1);
0305       if(tree_SubDet==6 && tree_Thickness<0.04) ChargeTEC1 ->Add(Proj,1);
0306       if(tree_SubDet==6 && tree_Thickness>0.04) ChargeTEC2 ->Add(Proj,1);
0307       if(tree_SubDet==6 && tree_Eta>0         ) ChargeTECP ->Add(Proj,1);
0308       if(tree_SubDet==6 && tree_Eta<0         ) ChargeTECM ->Add(Proj,1);
0309       if(tree_SubDet==6 && tree_Eta<0 && tree_Thickness<0.04) ChargeTECM1 ->Add(Proj,1);
0310       if(tree_SubDet==6 && tree_Eta<0 && tree_Thickness>0.04) ChargeTECM2 ->Add(Proj,1);
0311       if(tree_SubDet==6 && tree_Eta>0 && tree_Thickness<0.04) ChargeTECP1 ->Add(Proj,1);
0312       if(tree_SubDet==6 && tree_Eta>0 && tree_Thickness>0.04) ChargeTECP2 ->Add(Proj,1);
0313 
0314 
0315       if(tree_SubDet==3                       ) ChargeAbsTIB  ->Add(ProjAbsolute,1);
0316       if(tree_SubDet==4                       ) ChargeAbsTID  ->Add(ProjAbsolute,1);
0317       if(tree_SubDet==4 && tree_Eta<0         ) ChargeAbsTIDM ->Add(ProjAbsolute,1);
0318       if(tree_SubDet==4 && tree_Eta>0         ) ChargeAbsTIDP ->Add(ProjAbsolute,1);
0319       if(tree_SubDet==5                       ) ChargeAbsTOB  ->Add(ProjAbsolute,1);
0320       if(tree_SubDet==6                       ) ChargeAbsTEC  ->Add(ProjAbsolute,1);
0321       if(tree_SubDet==6 && tree_Thickness<0.04) ChargeAbsTEC1 ->Add(ProjAbsolute,1);
0322       if(tree_SubDet==6 && tree_Thickness>0.04) ChargeAbsTEC2 ->Add(ProjAbsolute,1);
0323       if(tree_SubDet==6 && tree_Eta>0         ) ChargeAbsTECP ->Add(ProjAbsolute,1);
0324       if(tree_SubDet==6 && tree_Eta<0         ) ChargeAbsTECM ->Add(ProjAbsolute,1);
0325       if(tree_SubDet==6 && tree_Eta<0 && tree_Thickness<0.04) ChargeAbsTECM1 ->Add(ProjAbsolute,1);
0326       if(tree_SubDet==6 && tree_Eta<0 && tree_Thickness>0.04) ChargeAbsTECM2 ->Add(ProjAbsolute,1);
0327       if(tree_SubDet==6 && tree_Eta>0 && tree_Thickness<0.04) ChargeAbsTECP1 ->Add(ProjAbsolute,1);
0328       if(tree_SubDet==6 && tree_Eta>0 && tree_Thickness>0.04) ChargeAbsTECP2 ->Add(ProjAbsolute,1);
0329 
0330       if(tree_SubDet==3                       ) DiffWRTPrevGainTIB  ->Fill(tree_Gain/tree_PrevGain);
0331       if(tree_SubDet==4                       ) DiffWRTPrevGainTID  ->Fill(tree_Gain/tree_PrevGain);
0332       if(tree_SubDet==5                       ) DiffWRTPrevGainTOB  ->Fill(tree_Gain/tree_PrevGain);
0333       if(tree_SubDet==6                       ) DiffWRTPrevGainTEC  ->Fill(tree_Gain/tree_PrevGain);
0334 
0335       if(tree_SubDet==3                       ) GainVsPrevGainTIB  ->Fill(tree_PrevGain,tree_Gain);
0336       if(tree_SubDet==4                       ) GainVsPrevGainTID  ->Fill(tree_PrevGain,tree_Gain);
0337       if(tree_SubDet==5                       ) GainVsPrevGainTOB  ->Fill(tree_PrevGain,tree_Gain);
0338       if(tree_SubDet==6                       ) GainVsPrevGainTEC  ->Fill(tree_PrevGain,tree_Gain);
0339 
0340       delete Proj;
0341       delete ProjAbsolute;
0342    }printf("\n");
0343 
0344 
0345 
0346    // ######################################################### PRINT OUT APV INFOS #################################
0347    unsigned int CountAPV_Total    = 0;
0348    unsigned int CountAPV_NoEntry  = 0;
0349    unsigned int CountAPV_NoEntryU = 0;
0350    unsigned int CountAPV_NoGain   = 0;
0351    unsigned int CountAPV_NoGainU  = 0;
0352    unsigned int CountAPV_LowGain  = 0;
0353    unsigned int CountAPV_DiffGain = 0;
0354 
0355    pFile = fopen((output + "_LowResponseModule.txt").c_str(),"w");
0356    fprintf(pFile,"\n\nALL APVs WITH NO ENTRIES (NO RECO CLUSTER ON IT)\n--------------------------------------------\n");
0357    printf("Looping on the Tree          :");
0358    for (unsigned int ientry = 0; ientry < t1->GetEntries(); ientry++) {      
0359       if(ientry%TreeStep==0){printf(".");fflush(stdout);}
0360       t1->GetEntry(ientry);
0361       CountAPV_Total++;
0362       if(tree_NEntries==0){fprintf(pFile,"%i-%i, ",tree_DetId,tree_APVId); CountAPV_NoEntry++;}
0363    }printf("\n");
0364    fprintf(pFile,"\n--> %i / %i = %f%% APV Concerned\n",CountAPV_NoEntry,CountAPV_Total,(100.0*CountAPV_NoEntry)/CountAPV_Total);
0365 
0366    fprintf(pFile,"\n\nUNMASKED APVs WITH NO ENTRIES (NO RECO CLUSTER ON IT)\n--------------------------------------------\n");
0367    printf("Looping on the Tree          :");
0368    for (unsigned int ientry = 0; ientry < t1->GetEntries(); ientry++) {
0369       if(ientry%TreeStep==0){printf(".");fflush(stdout);}
0370       t1->GetEntry(ientry);
0371       if(tree_NEntries==0 && !tree_isMasked){fprintf(pFile,"%i-%i, ",tree_DetId,tree_APVId); CountAPV_NoEntryU++;}
0372    }printf("\n");
0373    fprintf(pFile,"\n--> %i / %i = %f%% APV Concerned\n",CountAPV_NoEntryU,CountAPV_Total,(100.0*CountAPV_NoEntryU)/CountAPV_Total);
0374 
0375    fprintf(pFile,"\n\nALL APVs WITH NO GAIN COMPUTED\n--------------------------------------------\n");
0376    printf("Looping on the Tree          :");
0377    for (unsigned int ientry = 0; ientry < t1->GetEntries(); ientry++) {
0378       if(ientry%TreeStep==0){printf(".");fflush(stdout);}
0379       t1->GetEntry(ientry);
0380       if(tree_FitMPV<0){fprintf(pFile,"%i-%i, ",tree_DetId,tree_APVId); CountAPV_NoGain++;}
0381    }printf("\n");
0382    fprintf(pFile,"\n--> %i / %i = %f%% APV Concerned\n",CountAPV_NoGain,CountAPV_Total,(100.0*CountAPV_NoGain)/CountAPV_Total);
0383 
0384    fprintf(pFile,"\n\nUNMASKED APVs WITH NO GAIN COMPUTED\n--------------------------------------------\n");
0385    printf("Looping on the Tree          :");
0386    for (unsigned int ientry = 0; ientry < t1->GetEntries(); ientry++) {
0387       if(ientry%TreeStep==0){printf(".");fflush(stdout);}
0388       t1->GetEntry(ientry);
0389       if(tree_FitMPV<0 && !tree_isMasked){fprintf(pFile,"%i-%i, ",tree_DetId,tree_APVId); CountAPV_NoGainU++;}
0390    }printf("\n");
0391    fprintf(pFile,"\n--> %i / %i = %f%% APV Concerned\n",CountAPV_NoGainU,CountAPV_Total,(100.0*CountAPV_NoGainU)/CountAPV_Total);
0392 
0393    fprintf(pFile,"\n\nUNMASKED APVs WITH LOW RESPONSE\n--------------------------------------------\n");
0394    printf("Looping on the Tree          :");
0395    for (unsigned int ientry = 0; ientry < t1->GetEntries(); ientry++) {
0396       if(ientry%TreeStep==0){printf(".");fflush(stdout);}
0397       t1->GetEntry(ientry);
0398       if(tree_FitMPV>0 && tree_FitMPV<220 && !tree_isMasked){fprintf(pFile,"%i-%i, ",tree_DetId,tree_APVId); CountAPV_LowGain++;}
0399    }printf("\n");
0400    fprintf(pFile,"\n--> %i / %i = %f%% APV Concerned\n",CountAPV_LowGain,CountAPV_Total,(100.0*CountAPV_LowGain)/CountAPV_Total);
0401 
0402    fprintf(pFile,"\n\nUNMASKED APVs WITH SIGNIFICANT CHANGE OF GAIN VALUE\n--------------------------------------------\n");
0403    printf("Looping on the Tree          :");
0404    for (unsigned int ientry = 0; ientry < t1->GetEntries(); ientry++) {
0405       if(ientry%TreeStep==0){printf(".");fflush(stdout);}
0406       t1->GetEntry(ientry);
0407       if(tree_FitMPV>0 && !tree_isMasked && (tree_Gain/tree_PrevGain<0.7 || tree_Gain/tree_PrevGain>1.3)){fprintf(pFile,"%i-%i, ",tree_DetId,tree_APVId); CountAPV_DiffGain++;}
0408    }printf("\n");
0409    fprintf(pFile,"\n--> %i / %i = %f%% APV Concerned\n",CountAPV_DiffGain,CountAPV_Total,(100.0*CountAPV_DiffGain)/CountAPV_Total);
0410    fclose(pFile);
0411 
0412 
0413 
0414    // ######################################################### PRINT DISTRIBUTION INFO #################################
0415    pFile = fopen((output + "_SubDetector_MPV.txt").c_str(),"w");
0416 
0417    double Results[5]; TF1* landau;
0418    landau = getLandau(ChargeTIB, Results, 0, 5400);
0419    c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0420    ChargeTIB->Draw();
0421    landau->SetLineWidth(3);
0422    landau->Draw("same");
0423    SaveCanvas(c1,output,"SubDetChargeTIB");
0424    fprintf(pFile,"TIB   MPV=%7.2f +- %7.2f  Chi2=%7.2f\n",Results[0],Results[1],Results[4]);
0425 
0426    landau = getLandau(ChargeTIDM, Results, 0, 5400);
0427    c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0428    ChargeTIDM->Draw();
0429    landau->SetLineWidth(3);
0430    landau->Draw("same");
0431    SaveCanvas(c1,output,"SubDetChargeTIDM");
0432    fprintf(pFile, "TIDM  MPV=%7.2f +- %7.2f  Chi2=%7.2f\n",Results[0],Results[1],Results[4]);
0433 
0434    landau = getLandau(ChargeTIDP, Results, 0, 5400);
0435    c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0436    ChargeTIDP->Draw();
0437    landau->SetLineWidth(3);
0438    landau->Draw("same");
0439    SaveCanvas(c1,output,"SubDetChargeTIDP");
0440    fprintf(pFile, "TIDP  MPV=%7.2f +- %7.2f  Chi2=%7.2f\n",Results[0],Results[1],Results[4]);
0441 
0442    landau = getLandau(ChargeTOB, Results, 0, 5400);
0443    c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0444    ChargeTOB->Draw();
0445    landau->SetLineWidth(3);
0446    landau->Draw("same");
0447    SaveCanvas(c1,output,"SubDetChargeTOB");
0448    fprintf(pFile, "TOB   MPV=%7.2f +- %7.2f  Chi2=%7.2f\n",Results[0],Results[1],Results[4]);
0449 
0450    landau = getLandau(ChargeTECP1, Results, 0, 5400);
0451    c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0452    ChargeTECP1->Draw();
0453    landau->SetLineWidth(3);
0454    landau->Draw("same");
0455    SaveCanvas(c1,output,"SubDetChargeTECP1");
0456    fprintf(pFile, "TECP1 MPV=%7.2f +- %7.2f  Chi2=%7.2f\n",Results[0],Results[1],Results[4]);
0457 
0458    landau = getLandau(ChargeTECP2, Results, 0, 5400);
0459    c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0460    ChargeTECP2->Draw();
0461    landau->SetLineWidth(3);
0462    landau->Draw("same");
0463    SaveCanvas(c1,output,"SubDetChargeTECP2");
0464    fprintf(pFile, "TECP2 MPV=%7.2f +- %7.2f  Chi2=%7.2f\n",Results[0],Results[1],Results[4]);
0465 
0466    landau = getLandau(ChargeTECM1, Results, 0, 5400);
0467    c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0468    ChargeTECM1->Draw();
0469    landau->SetLineWidth(3);
0470    landau->Draw("same");
0471    SaveCanvas(c1,output,"SubDetChargeTECM1");
0472    fprintf(pFile, "TECM1 MPV=%7.2f +- %7.2f  Chi2=%7.2f\n",Results[0],Results[1],Results[4]);
0473 
0474    landau = getLandau(ChargeTECM2, Results, 0, 5400);
0475    c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0476    ChargeTECM2->Draw();
0477    landau->SetLineWidth(3);
0478    landau->Draw("same");
0479    SaveCanvas(c1,output,"SubDetChargeTECM2");
0480    fprintf(pFile, "TECM2 MPV=%7.2f +- %7.2f  Chi2=%7.2f\n",Results[0],Results[1],Results[4]);
0481 
0482    fclose(pFile);
0483    // ######################################################### MAKE PLOTS #################################
0484 
0485 
0486    c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0487    Histos[0] = MPV_Vs_EtaTEC;                     legend.push_back("TEC");
0488    Histos[1] = MPV_Vs_EtaTIB;                     legend.push_back("TIB");
0489    Histos[2] = MPV_Vs_EtaTID;                     legend.push_back("TID");
0490    Histos[3] = MPV_Vs_EtaTOB;                     legend.push_back("TOB");
0491    DrawTH2D((TH2D**)Histos,legend, "", "module #eta", "MPV [ADC/mm]", -3.0,3.0, 0,600);
0492    DrawLegend (Histos,legend,"","P");
0493    DrawStatBox(Histos,legend,false);
0494    SaveCanvas(c1,output,"MPV_Vs_EtaSubDet");
0495    delete c1;
0496 
0497     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0498     Histos[0] = MPV_Vs_PhiTEC;                     legend.push_back("TEC");
0499     Histos[1] = MPV_Vs_PhiTIB;                     legend.push_back("TIB");
0500     Histos[2] = MPV_Vs_PhiTID;                     legend.push_back("TID");
0501     Histos[3] = MPV_Vs_PhiTOB;                     legend.push_back("TOB");
0502     DrawTH2D((TH2D**)Histos,legend, "", "module #phi", "MPV [ADC/mm]", -3.4,3.4, 0,600);
0503     DrawLegend(Histos,legend,"","P");
0504     DrawStatBox(Histos,legend,false);
0505     SaveCanvas(c1,output,"MPV_Vs_PhiSubDet");
0506     delete c1;
0507 
0508     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0509     Histos[0] = NoMPV;                             legend.push_back("NoMPV");
0510     DrawTH2D((TH2D**)Histos,legend, "", "z (cm)", "R (cms)", 0,0, 0,0);
0511     SaveCanvas(c1,output,"NoMPV", true);
0512     delete c1;
0513 
0514     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0515     ChargeDistrib->GetXaxis()->SetNdivisions(5+500);
0516     Histos[0] = ChargeDistrib;                     legend.push_back("Charge Vs Index");
0517     DrawTH2D((TH2D**)Histos,legend, "COLZ", "APV Index", "Charge [ADC/mm]", 0,0, 0,0);
0518     c1->SetLogz(true);
0519     SaveCanvas(c1,output,"Charge2D", true);
0520     delete c1;
0521 
0522     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0523     Histos[0] = Gains;                             legend.push_back("");
0524     DrawSuperposedHistos((TH1**)Histos, legend, "",  "Gain", "Number of APVs", 0.5,1.5, 0,0);
0525     DrawLegend(Histos,legend,"","L");
0526     DrawStatBox(Histos,legend,true);
0527     SaveCanvas(c1,output,"Gains");
0528 
0529     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0530     Histos[0] = MPVs320;                           legend.push_back("320 #mum");
0531     Histos[1] = MPVs500;                           legend.push_back("500 #mum");
0532     Histos[2] = MPVs;                              legend.push_back("320 + 500 #mum");
0533     DrawSuperposedHistos((TH1**)Histos, legend, "",  "MPV [ADC/mm]", "Number of APVs", 100,550, 0,0);
0534     DrawLegend(Histos,legend,"","L");
0535     DrawPreliminary(DataType);
0536     SaveCanvas(c1,output,"MPVs");
0537     c1->SetLogy(true);
0538     SaveCanvas(c1,output,"MPVsLog");
0539     DrawStatBox(Histos,legend,true);
0540     c1->SetLogy(false);
0541     SaveCanvas(c1,output,"MPVsAndStat");
0542     c1->SetLogy(true);
0543     SaveCanvas(c1,output,"MPVsLogAndStat");
0544     delete c1;
0545 
0546 
0547     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0548     MPVsTOB->GetXaxis()->SetNdivisions(5+500);
0549     Histos[0] = MPVsTIB;                           legend.push_back("TIB (320 #mum)");
0550     Histos[1] = MPVsTID;                           legend.push_back("TID (320 #mum)");
0551     Histos[2] = MPVsTOB;                           legend.push_back("TOB (500 #mum)");
0552     Histos[3] = MPVsTEC1;                          legend.push_back("TEC (320 #mum)");
0553     Histos[4] = MPVsTEC2;                          legend.push_back("TEC (500 #mum)");
0554 //    Histos[5] = MPVs;                              legend.push_back("All");
0555     DrawSuperposedHistos((TH1**)Histos, legend, "",  "MPV [ADC/mm]", "Number of APVs", 100,550, 0,0);
0556     DrawLegend(Histos,legend,"","L");
0557     DrawPreliminary(DataType);
0558     SaveCanvas(c1,output,"MPVsSubDet");
0559     c1->SetLogy(true);
0560     SaveCanvas(c1,output,"MPVsSubDetLog");
0561     DrawStatBox(Histos,legend,true);
0562     SaveCanvas(c1,output,"MPVsSubDetLogAndStat");
0563     c1->SetLogy(false);
0564     SaveCanvas(c1,output,"MPVsSubDetAndStat");
0565     delete c1;
0566 
0567 
0568 
0569     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0570     MPVsTOB->GetXaxis()->SetNdivisions(5+500);
0571     Histos[0] = MPVsTECP1;                          legend.push_back("TEC+ (320 #mum)");
0572     Histos[1] = MPVsTECP2;                          legend.push_back("TEC+ (500 #mum)");
0573     Histos[2] = MPVsTECM1;                          legend.push_back("TEC- (320 #mum)");
0574     Histos[3] = MPVsTECM2;                          legend.push_back("TEC- (500 #mum)");
0575     DrawSuperposedHistos((TH1**)Histos, legend, "",  "MPV [ADC/mm]", "Number of APVs", 100,550, 0,0);
0576     DrawLegend(Histos,legend,"#sqrt{s}=7TeV","L");
0577     DrawStatBox(Histos,legend,true);
0578     SaveCanvas(c1,output,"MPVsTEC");
0579     c1->SetLogy(true);
0580     SaveCanvas(c1,output,"MPVsTECLog");
0581     delete c1;
0582 
0583 
0584     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0585     Histos[0] = MPVError;                          legend.push_back("MPV Error");
0586     DrawSuperposedHistos((TH1**)Histos, legend, "",  "Error on MPV [ADC/mm]", "Number of APVs", 0,500, 0,0);
0587     DrawStatBox(Histos,legend,true);
0588     c1->SetLogy(true);
0589     SaveCanvas(c1,output,"Error");
0590     delete c1;
0591 
0592     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0593     Histos[0] = MPVErrorVsMPV;                     legend.push_back("Error Vs MPV");
0594     DrawTH2D((TH2D**)Histos,legend, "COLZ", "MPV [ADC/mm]", "Error on MPV [ADC/mm]", 0,0, 0,0);
0595     c1->SetLogz(true);
0596     SaveCanvas(c1,output,"Error_Vs_MPV", true);
0597     delete c1;
0598 
0599     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0600     Histos[0] = MPVErrorVsEta;                     legend.push_back("Error Vs Eta");
0601     DrawTH2D((TH2D**)Histos,legend, "COLZ", "module #eta", "Error on MPV [ADC/mm]", 0,0, 0,0);
0602     c1->SetLogz(true);
0603     SaveCanvas(c1,output,"Error_Vs_Eta", true);
0604     delete c1;
0605 
0606     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0607     Histos[0] = MPVErrorVsPhi;                     legend.push_back("Error Vs Phi");
0608     DrawTH2D((TH2D**)Histos,legend, "COLZ", "module #phi", "Error on MPV [ADC/mm]", 0,0, 0,0);
0609     c1->SetLogz(true);
0610     SaveCanvas(c1,output,"Error_Vs_Phi", true);
0611     delete c1;
0612 
0613     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0614     Histos[0] = MPVErrorVsN;                       legend.push_back("Error Vs Entries");
0615     DrawTH2D((TH2D**)Histos,legend, "COLZ", "Number of Entries", "Error on MPV [ADC/mm]", 0,0, 0,0);
0616     c1->SetLogz(true);
0617     SaveCanvas(c1,output,"Error_Vs_N", true);
0618     delete c1;
0619 
0620     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0621     Histos[0] = ChargeTEC;                         legend.push_back("TEC");
0622     Histos[1] = ChargeTIB;                         legend.push_back("TIB");
0623     Histos[2] = ChargeTID;                         legend.push_back("TID");
0624     Histos[3] = ChargeTOB;                         legend.push_back("TOB");
0625     DrawSuperposedHistos((TH1**)Histos, legend, "",  "Charge [ADC/mm]", "Number of Clusters", 0,800 , 0,0);
0626     DrawLegend(Histos,legend,"","L");
0627     DrawPreliminary(DataType);
0628     TLine* l0 = new TLine(300, 0,300,((TH1*)Histos[0])->GetMaximum()); l0->SetLineWidth(3); l0->SetLineStyle(2); l0->Draw("same");
0629     SaveCanvas(c1,output,"Charge");
0630     DrawStatBox(Histos,legend,true, 0.6, 0.7);
0631     SaveCanvas(c1,output,"ChargeAndStat");
0632     delete c1;
0633 
0634     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0635     Histos[0] = ChargeTECP;                        legend.push_back("TEC+");
0636     Histos[1] = ChargeTECM;                        legend.push_back("TEC-");
0637     DrawSuperposedHistos((TH1**)Histos, legend, "",  "Charge [ADC/mm]", "Number of Clusters", 0,800 , 0,0);
0638     DrawLegend(Histos,legend,"","L");
0639     DrawStatBox(Histos,legend,true, 0.6, 0.7);
0640     SaveCanvas(c1,output,"ChargeTECSide");
0641     delete c1;
0642 
0643     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0644     Histos[0] = ChargeTEC1;                        legend.push_back("TEC Thin");
0645     Histos[1] = ChargeTEC2;                        legend.push_back("TEC Thick");
0646     DrawSuperposedHistos((TH1**)Histos, legend, "",  "Charge [ADC/mm]", "Number of Clusters", 0,800 , 0,0);
0647     DrawLegend(Histos,legend,"","L");
0648     DrawStatBox(Histos,legend,true, 0.6, 0.7);
0649     SaveCanvas(c1,output,"ChargeTECThickness");
0650     delete c1;
0651 
0652     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0653     Histos[0] = ChargeTIDP;                        legend.push_back("TID+");
0654     Histos[1] = ChargeTIDM;                        legend.push_back("TID-");
0655     DrawSuperposedHistos((TH1**)Histos, legend, "",  "Charge [ADC/mm]", "Number of Clusters", 0,800 , 0,0);
0656     DrawLegend(Histos,legend,"","L");
0657     DrawStatBox(Histos,legend,true, 0.6, 0.7);
0658     SaveCanvas(c1,output,"ChargeTIDSide");
0659     delete c1;
0660 
0661     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0662     Histos[0] = ChargeAbsTEC;                      legend.push_back("TEC");
0663     Histos[1] = ChargeAbsTIB;                      legend.push_back("TIB");
0664     Histos[2] = ChargeAbsTID;                      legend.push_back("TID");
0665     Histos[3] = ChargeAbsTOB;                      legend.push_back("TOB");
0666     DrawSuperposedHistos((TH1**)Histos, legend, "",  "Charge [ADC]", "Number of Clusters", 0,800 , 0,0);
0667     DrawLegend(Histos,legend,"","L");
0668     DrawStatBox(Histos,legend,true, 0.6, 0.7);
0669     SaveCanvas(c1,output,"ChargeAbs");
0670     delete c1;
0671 
0672     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0673     Histos[0] = ChargeAbsTECP;                     legend.push_back("TEC+");
0674     Histos[1] = ChargeAbsTECM;                     legend.push_back("TEC-");
0675     DrawSuperposedHistos((TH1**)Histos, legend, "",  "Charge [ADC]", "Number of Clusters", 0,800 , 0,0);
0676     DrawLegend(Histos,legend,"","L");
0677     DrawStatBox(Histos,legend,true, 0.6, 0.7);
0678     SaveCanvas(c1,output,"ChargeAbsTECSide");
0679     delete c1;
0680 
0681     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0682     Histos[0] = ChargeAbsTEC1;                     legend.push_back("TEC Thin");
0683     Histos[1] = ChargeAbsTEC2;                     legend.push_back("TEC Thick");
0684     DrawSuperposedHistos((TH1**)Histos, legend, "",  "Charge [ADC]", "Number of Clusters", 0,800 , 0,0);
0685     DrawLegend(Histos,legend,"","L");
0686     DrawStatBox(Histos,legend,true, 0.6, 0.7);
0687     SaveCanvas(c1,output,"ChargeAbsTECThickness");
0688     delete c1;
0689 
0690     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0691     Histos[0] = ChargeAbsTIDP;                     legend.push_back("TID+");
0692     Histos[1] = ChargeAbsTIDM;                     legend.push_back("TID-");
0693     DrawSuperposedHistos((TH1**)Histos, legend, "",  "Charge [ADC]", "Number of Clusters", 0,800 , 0,0);
0694     DrawLegend(Histos,legend,"","L");
0695     DrawStatBox(Histos,legend,true, 0.6, 0.7);
0696     SaveCanvas(c1,output,"ChargeAbsTIDSide");
0697     delete c1;
0698 
0699 
0700     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0701     Histos[0] = MPV_Vs_PathlengthThin;             legend.push_back("320 #mum");
0702     Histos[1] = MPV_Vs_PathlengthThick;            legend.push_back("500 #mum");
0703     DrawSuperposedHistos((TH1**)Histos, legend, "HIST",  "pathlength [mm]", "MPV [ADC/mm]", 0,0 , 230,380);
0704     DrawLegend(Histos,legend,"","L");
0705     SaveCanvas(c1,output,"MPV_Vs_Path");
0706     delete c1;
0707 
0708 
0709     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0710     Histos[0] = MPV_Vs_PathlengthTIB;              legend.push_back("TIB (320 #mum)");
0711     Histos[1] = MPV_Vs_PathlengthTID;              legend.push_back("TID (320 #mum)");
0712     Histos[2] = MPV_Vs_PathlengthTOB;              legend.push_back("TOB (500 #mum)");
0713     Histos[3] = MPV_Vs_PathlengthTEC1;             legend.push_back("TEC (320 #mum)");
0714     Histos[4] = MPV_Vs_PathlengthTEC2;             legend.push_back("TEC (500 #mum)");
0715     DrawSuperposedHistos((TH1**)Histos, legend, "HIST",  "pathlength [mm]", "MPV [ADC/mm]", 0,0 , 230,380);
0716     DrawLegend(Histos,legend,"","L");
0717     SaveCanvas(c1,output,"MPV_Vs_PathSubDet");
0718     delete c1;
0719 
0720 
0721     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0722     Histos[0] = DiffWRTPrevGainTIB;                legend.push_back("TIB");
0723     Histos[1] = DiffWRTPrevGainTID;                legend.push_back("TID");
0724     Histos[2] = DiffWRTPrevGainTOB;                legend.push_back("TOB");
0725     Histos[3] = DiffWRTPrevGainTEC;                legend.push_back("TEC");
0726     DrawSuperposedHistos((TH1**)Histos, legend, "HIST",  "New Gain / Previous Gain", "Number of APV", 0.0,2.0 ,0,0);
0727     DrawLegend(Histos,legend,"","L");
0728     c1->SetLogy(true);
0729     DrawStatBox(Histos,legend,true, 0.6, 0.7);
0730     SaveCanvas(c1,output,"GainDividedPrevGain");
0731     delete c1;
0732 
0733 
0734    c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0735    Histos[0] = GainVsPrevGainTEC;                 legend.push_back("TEC");
0736    Histos[1] = GainVsPrevGainTIB;                 legend.push_back("TIB");
0737    Histos[2] = GainVsPrevGainTID;                 legend.push_back("TID");
0738    Histos[3] = GainVsPrevGainTOB;                 legend.push_back("TOB");
0739    DrawTH2D((TH2D**)Histos,legend, "", "Previous Gain", "New Gain", 0.5,1.8, 0.5,1.8);
0740    TLine diagonal(0.5,0.5,1.8,1.8);
0741    diagonal.SetLineWidth(3);
0742    diagonal.SetLineStyle(2);
0743    diagonal.Draw("same");
0744    DrawLegend (Histos,legend,"","P");
0745    DrawStatBox(Histos,legend,false);
0746    SaveCanvas(c1,output,"GainVsPrevGain");
0747    delete c1;
0748 
0749 
0750 }
0751 
0752 TF1* getLandau(TH1* InputHisto, double* FitResults, double LowRange, double HighRange)
0753 {
0754    FitResults[0]         = -0.5;  //MPV
0755    FitResults[1]         =  0;    //MPV error
0756    FitResults[2]         = -0.5;  //Width
0757    FitResults[3]         =  0;    //Width error
0758    FitResults[4]         = -0.5;  //Fit Chi2/NDF
0759 
0760    // perform fit with standard landau
0761    TF1* MyLandau = new TF1("MyLandau","landau",LowRange, HighRange);
0762    MyLandau->SetParameter(1,300);
0763    InputHisto->Fit("MyLandau","0QR WW");
0764 
0765    // MPV is parameter 1 (0=constant, 1=MPV, 2=Sigma)
0766    FitResults[0]         = MyLandau->GetParameter(1);  //MPV
0767    FitResults[1]         = MyLandau->GetParError(1);   //MPV error
0768    FitResults[2]         = MyLandau->GetParameter(2);  //Width
0769    FitResults[3]         = MyLandau->GetParError(2);   //Width error
0770    FitResults[4]         = MyLandau->GetChisquare() / MyLandau->GetNDF();  //Fit Chi2/NDF
0771 
0772    return MyLandau;
0773 }
0774 
0775 TH1D* ChargeToMPV(TH2* InputHisto, string Name,  bool DivideByX)
0776 {
0777    TH1D* toReturn = new TH1D(Name.c_str(),Name.c_str(),InputHisto->GetXaxis()->GetNbins(), InputHisto->GetXaxis()->GetXmin(), InputHisto->GetXaxis()->GetXmax() );
0778    double Results[5];
0779 
0780    for(int i=0;i<=InputHisto->GetXaxis()->GetNbins();i++){
0781       TH1D* proj   = InputHisto->ProjectionY("",i,i);
0782       if(proj->GetEntries()<50){delete proj;continue;}
0783 
0784       TF1*  landau = getLandau(proj,Results);
0785 
0786       if(DivideByX){
0787          toReturn->SetBinContent(i,Results[0] / InputHisto->GetXaxis()->GetBinCenter(i) );
0788          toReturn->SetBinError  (i,Results[1] / InputHisto->GetXaxis()->GetBinCenter(i) );
0789       }else{
0790          toReturn->SetBinContent(i,Results[0]);
0791          toReturn->SetBinError  (i,Results[1]);
0792       }
0793       delete landau;
0794      delete proj;
0795    }
0796 
0797    return toReturn;
0798 }
0799