Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:35:20

0001 #include "TROOT.h"
0002 #include "TFile.h"
0003 #include "TDirectory.h"
0004 #include "TChain.h"
0005 #include "TObject.h"
0006 #include "TCanvas.h"
0007 #include "TMath.h"
0008 #include "TLegend.h"
0009 #include "TGraph.h"
0010 #include "TH1.h"
0011 #include "TH2.h"
0012 #include "TH3.h"
0013 #include "TTree.h"
0014 #include "TF1.h"
0015 #include "TPaveText.h"
0016 #include "PlotFunction.h"
0017 
0018 #include<vector>
0019 #include "tdrstyle.C"
0020 
0021 #if !defined(__CINT__) && !defined(__MAKECINT__)
0022 //#include "DataFormats/FWLite/interface/Handle.h"
0023 //#include "DataFormats/FWLite/interface/Event.h"
0024 //#include "DataFormats/FWLite/interface/ChainEvent.h"
0025 
0026 #include "CommonTools/TrackerMap/interface/TrackerMap.h"
0027 
0028 //using namespace fwlite;
0029 using namespace std;
0030 //using namespace edm;
0031 #endif
0032 
0033 
0034 
0035 
0036 void PlotMacro_Core(std::string input, std::string moduleName, std::string modeName, std::string output, std::string TextToPrint);
0037 TF1*  getLandau(TH1* InputHisto, double* FitResults, double LowRange=50, double HighRange=5400);
0038 TH1D* ChargeToMPV(TH2* InputHisto, std::string Name, bool DivideByX);
0039 
0040 
0041 
0042 void PlotMacro(std::string modeName="StdBunch", std::string TextToPrint_="CMS Preliminary 2017"){
0043    system("mkdir Pictures");
0044    printf("Plotting histograms for %s calibration\n", modeName.c_str());   
0045    PlotMacro_Core("file:Gains_Tree.root"     , "SiStripCalib/"          , modeName, "Pictures/Gains"     , TextToPrint_ + "  -  Particle Gain");
0046    //PlotMacro_Core("file:Validation_Tree.root", "SiStripCalibValidation/", modeName, "Pictures/Validation", TextToPrint_ + "  -  Gain Validation");
0047 }
0048 
0049 
0050 void PlotMacro_Core(std::string input, std::string moduleName, std::string modeName, std::string output, std::string TextToPrint)
0051 {
0052    FILE* pFile;
0053    TCanvas* c1;
0054    TObject** Histos = new TObject*[10];                
0055    std::vector<std::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    float         tree_FitNorm;
0074    double        tree_Gain;
0075    double        tree_PrevGain;
0076    double        tree_PrevGainTick;
0077    double        tree_NEntries;
0078    bool          tree_isMasked;
0079 
0080    TFile* f1     = new TFile(input.c_str());
0081    TTree *t1     = (TTree*)GetObjectFromPath(f1,moduleName+"APVGain");
0082    cout<<"Mode name = "<<modeName<<endl;
0083    if(t1==0) return;
0084    t1->SetBranchAddress("Index"             ,&tree_Index      );
0085    t1->SetBranchAddress("DetId"             ,&tree_DetId      );
0086    t1->SetBranchAddress("APVId"             ,&tree_APVId      );
0087    t1->SetBranchAddress("SubDet"            ,&tree_SubDet     );
0088    t1->SetBranchAddress("x"                 ,&tree_x          );
0089    t1->SetBranchAddress("y"                 ,&tree_y          );
0090    t1->SetBranchAddress("z"                 ,&tree_z          );
0091    t1->SetBranchAddress("Eta"               ,&tree_Eta        );
0092    t1->SetBranchAddress("R"                 ,&tree_R          );
0093    t1->SetBranchAddress("Phi"               ,&tree_Phi        );
0094    t1->SetBranchAddress("Thickness"         ,&tree_Thickness  );
0095    t1->SetBranchAddress("FitMPV"            ,&tree_FitMPV     );
0096    t1->SetBranchAddress("FitMPVErr"         ,&tree_FitMPVErr  );
0097    t1->SetBranchAddress("FitWidth"          ,&tree_FitWidth   );
0098    t1->SetBranchAddress("FitWidthErr"       ,&tree_FitWidthErr);
0099    t1->SetBranchAddress("FitChi2NDF"        ,&tree_FitChi2NDF );
0100    t1->SetBranchAddress("FitNorm"           ,&tree_FitNorm    );
0101    t1->SetBranchAddress("Gain"              ,&tree_Gain       );
0102    t1->SetBranchAddress("PrevGain"          ,&tree_PrevGain   );
0103    t1->SetBranchAddress("PrevGainTick"      ,&tree_PrevGainTick);
0104    t1->SetBranchAddress("NEntries"          ,&tree_NEntries   );
0105    t1->SetBranchAddress("isMasked"          ,&tree_isMasked   );
0106    TH2D* ChargeDistrib  = (TH2D*)GetObjectFromPath(f1,moduleName+"Charge_Vs_Index_"+modeName);
0107    //TH2D* ChargeDistribA = (TH2D*)GetObjectFromPath(f1,moduleName+"Charge_Vs_Index_Absolute_"+modeName);
0108 
0109    TH2D* Charge_Vs_PathlengthTIB   = (TH2D*)GetObjectFromPath(f1,moduleName+"Charge_Vs_PathlengthTIB_"+modeName);
0110    TH2D* Charge_Vs_PathlengthTOB   = (TH2D*)GetObjectFromPath(f1,moduleName+"Charge_Vs_PathlengthTOB_"+modeName);
0111    TH2D* Charge_Vs_PathlengthTIDP  = (TH2D*)GetObjectFromPath(f1,moduleName+"Charge_Vs_PathlengthTIDP_"+modeName);
0112    TH2D* Charge_Vs_PathlengthTIDM  = (TH2D*)GetObjectFromPath(f1,moduleName+"Charge_Vs_PathlengthTIDM_"+modeName);
0113    TH2D* Charge_Vs_PathlengthTID   = (TH2D*)Charge_Vs_PathlengthTIDP->Clone("Charge_Vs_PathlengthTID");
0114          Charge_Vs_PathlengthTID      ->Add(Charge_Vs_PathlengthTIDM);
0115    TH2D* Charge_Vs_PathlengthTECP1 = (TH2D*)GetObjectFromPath(f1,moduleName+"Charge_Vs_PathlengthTECP1_"+modeName);
0116    TH2D* Charge_Vs_PathlengthTECP2 = (TH2D*)GetObjectFromPath(f1,moduleName+"Charge_Vs_PathlengthTECP2_"+modeName);
0117    TH2D* Charge_Vs_PathlengthTECM1 = (TH2D*)GetObjectFromPath(f1,moduleName+"Charge_Vs_PathlengthTECM1_"+modeName);
0118    TH2D* Charge_Vs_PathlengthTECM2 = (TH2D*)GetObjectFromPath(f1,moduleName+"Charge_Vs_PathlengthTECM2_"+modeName);
0119    TH2D* Charge_Vs_PathlengthTECP  = (TH2D*)Charge_Vs_PathlengthTECP1->Clone("Charge_Vs_PathlengthTECP");
0120          Charge_Vs_PathlengthTECP     ->Add(Charge_Vs_PathlengthTECP2);
0121    TH2D* Charge_Vs_PathlengthTECM  = (TH2D*)Charge_Vs_PathlengthTECM1->Clone("Charge_Vs_PathlengthTECM");
0122          Charge_Vs_PathlengthTECM     ->Add(Charge_Vs_PathlengthTECM2);
0123    TH2D* Charge_Vs_PathlengthTEC1  = (TH2D*)Charge_Vs_PathlengthTECP1->Clone("Charge_Vs_PathlengthTEC1");
0124          Charge_Vs_PathlengthTEC1     ->Add(Charge_Vs_PathlengthTECM1);
0125    TH2D* Charge_Vs_PathlengthTEC2  = (TH2D*)Charge_Vs_PathlengthTECP2->Clone("Charge_Vs_PathlengthTEC2");
0126          Charge_Vs_PathlengthTEC2     ->Add(Charge_Vs_PathlengthTECM2); 
0127    TH2D* Charge_Vs_PathlengthTEC   = (TH2D*)Charge_Vs_PathlengthTECP ->Clone("Charge_Vs_PathlengthTEC");
0128          Charge_Vs_PathlengthTEC      ->Add(Charge_Vs_PathlengthTECM );
0129 
0130    TH2D* Charge_Vs_PathlengthThin  = (TH2D*)Charge_Vs_PathlengthTEC1->Clone("Charge_Vs_PathlengthThin");
0131          Charge_Vs_PathlengthThin     ->Add(Charge_Vs_PathlengthTIB );
0132          Charge_Vs_PathlengthThin     ->Add(Charge_Vs_PathlengthTID );
0133    TH2D* Charge_Vs_PathlengthThick = (TH2D*)Charge_Vs_PathlengthTEC2->Clone("Charge_Vs_PathlengthThin");
0134          Charge_Vs_PathlengthThick    ->Add(Charge_Vs_PathlengthTOB );
0135 
0136    TH1D* MPV_Vs_PathlengthTIB      = ChargeToMPV(Charge_Vs_PathlengthTIB  ,"MPV_Vs_PathlengthTIB"  , true);
0137    TH1D* MPV_Vs_PathlengthTID      = ChargeToMPV(Charge_Vs_PathlengthTID  ,"MPV_Vs_PathlengthTID"  , true);
0138 // TH1D* MPV_Vs_PathlengthTIDP     = ChargeToMPV(Charge_Vs_PathlengthTIDP ,"MPV_Vs_PathlengthTIDP" , true);
0139 // TH1D* MPV_Vs_PathlengthTIDM     = ChargeToMPV(Charge_Vs_PathlengthTIDM ,"MPV_Vs_PathlengthTIDM" , true);
0140 
0141 
0142 
0143    TH1D* MPV_Vs_PathlengthTOB      = ChargeToMPV(Charge_Vs_PathlengthTOB  ,"MPV_Vs_PathlengthTOB"  , true);
0144 // TH1D* MPV_Vs_PathlengthTEC      = ChargeToMPV(Charge_Vs_PathlengthTEC  ,"MPV_Vs_PathlengthTEC"  , true);
0145 // TH1D* MPV_Vs_PathlengthTECP     = ChargeToMPV(Charge_Vs_PathlengthTECP ,"MPV_Vs_PathlengthTECP" , true);
0146 // TH1D* MPV_Vs_PathlengthTECM     = ChargeToMPV(Charge_Vs_PathlengthTECM ,"MPV_Vs_PathlengthTECM" , true);
0147    TH1D* MPV_Vs_PathlengthTEC1     = ChargeToMPV(Charge_Vs_PathlengthTEC1 ,"MPV_Vs_PathlengthTEC1" , true);
0148    TH1D* MPV_Vs_PathlengthTEC2     = ChargeToMPV(Charge_Vs_PathlengthTEC2 ,"MPV_Vs_PathlengthTEC2" , true);
0149 
0150 
0151 // TH1D* MPV_Vs_PathlengthTECP1    = ChargeToMPV(Charge_Vs_PathlengthTECP1,"MPV_Vs_PathlengthTECP1", true);
0152 // TH1D* MPV_Vs_PathlengthTECP2    = ChargeToMPV(Charge_Vs_PathlengthTECP2,"MPV_Vs_PathlengthTECP2", true);
0153 // TH1D* MPV_Vs_PathlengthTECM1    = ChargeToMPV(Charge_Vs_PathlengthTECM1,"MPV_Vs_PathlengthTECM1", true);
0154 // TH1D* MPV_Vs_PathlengthTECM2    = ChargeToMPV(Charge_Vs_PathlengthTECM2,"MPV_Vs_PathlengthTECM2", true);
0155    TH1D* MPV_Vs_PathlengthThin     = ChargeToMPV(Charge_Vs_PathlengthThin ,"MPV_Vs_PathlengthThin" , true);
0156    TH1D* MPV_Vs_PathlengthThick    = ChargeToMPV(Charge_Vs_PathlengthThick,"MPV_Vs_PathlengthThick", true);
0157 
0158 
0159 
0160    TH2D* MPV_Vs_EtaTIB  = new TH2D("MPV_Vs_EtaTIB" ,"MPV_Vs_EtaTIB" , 50, -3.0, 3.0, 300, 0, 600);
0161    TH2D* MPV_Vs_EtaTID  = new TH2D("MPV_Vs_EtaTID" ,"MPV_Vs_EtaTID" , 50, -3.0, 3.0, 300, 0, 600);
0162    TH2D* MPV_Vs_EtaTOB  = new TH2D("MPV_Vs_EtaTOB" ,"MPV_Vs_EtaTOB" , 50, -3.0, 3.0, 300, 0, 600);
0163    TH2D* MPV_Vs_EtaTEC  = new TH2D("MPV_Vs_EtaTEC" ,"MPV_Vs_EtaTEC" , 50, -3.0, 3.0, 300, 0, 600);
0164    TH2D* MPV_Vs_EtaTEC1 = new TH2D("MPV_Vs_EtaTEC1","MPV_Vs_EtaTEC1", 50, -3.0, 3.0, 300, 0, 600);
0165    TH2D* MPV_Vs_EtaTEC2 = new TH2D("MPV_Vs_EtaTEC2","MPV_Vs_EtaTEC2", 50, -3.0, 3.0, 300, 0, 600);
0166 
0167    TH2D* MPV_Vs_PhiTIB  = new TH2D("MPV_Vs_PhiTIB" ,"MPV_Vs_PhiTIB" , 50, -3.4, 3.4, 300, 0, 600);
0168    TH2D* MPV_Vs_PhiTID  = new TH2D("MPV_Vs_PhiTID" ,"MPV_Vs_PhiTID" , 50, -3.4, 3.4, 300, 0, 600);
0169    TH2D* MPV_Vs_PhiTOB  = new TH2D("MPV_Vs_PhiTOB" ,"MPV_Vs_PhiTOB" , 50, -3.4, 3.4, 300, 0, 600);
0170    TH2D* MPV_Vs_PhiTEC  = new TH2D("MPV_Vs_PhiTEC" ,"MPV_Vs_PhiTEC" , 50, -3.4, 3.4, 300, 0, 600);
0171    TH2D* MPV_Vs_PhiTEC1 = new TH2D("MPV_Vs_PhiTEC1","MPV_Vs_PhiTEC1", 50, -3.4, 3.4, 300, 0, 600);
0172    TH2D* MPV_Vs_PhiTEC2 = new TH2D("MPV_Vs_PhiTEC2","MPV_Vs_PhiTEC2", 50, -3.4, 3.4, 300, 0, 600);
0173 
0174    TH2D* NoMPV          = new TH2D("NoMPV"         ,"NoMPV"         ,350, -350, 350, 240, 0, 120);
0175 
0176 
0177 
0178    TH1D* Gains          = new TH1D("Gains"         ,"Gains"         ,                300, 0, 2);
0179    TH1D* MPVs           = new TH1D("MPVs"          ,"MPVs"          ,                300, 0, 600);
0180    TH1D* MPVs320        = new TH1D("MPVs320"       ,"MPVs320"       ,                300, 0, 600);
0181    TH1D* MPVs500        = new TH1D("MPVs500"       ,"MPVs500"       ,                300, 0, 600);
0182    TH1D* MPVsTIB        = new TH1D("MPVsTIB"       ,"MPVsTIB"       ,                300, 0, 600);
0183    TH1D* MPVsTID        = new TH1D("MPVsTID"       ,"MPVsTID"       ,                300, 0, 600);
0184    TH1D* MPVsTIDP       = new TH1D("MPVsTIDP"      ,"MPVsTIDP"      ,                300, 0, 600);
0185    TH1D* MPVsTIDM       = new TH1D("MPVsTIDM"      ,"MPVsTIDM"      ,                300, 0, 600);
0186    TH1D* MPVsTOB        = new TH1D("MPVsTOB"       ,"MPVsTOB"       ,                300, 0, 600);
0187    TH1D* MPVsTEC        = new TH1D("MPVsTEC"       ,"MPVsTEC"       ,                300, 0, 600);
0188    TH1D* MPVsTECP       = new TH1D("MPVsTECP"      ,"MPVsTECP"      ,                300, 0, 600);
0189    TH1D* MPVsTECM       = new TH1D("MPVsTECM"      ,"MPVsTECM"      ,                300, 0, 600);
0190    TH1D* MPVsTEC1       = new TH1D("MPVsTEC1"      ,"MPVsTEC1"      ,                300, 0, 600);
0191    TH1D* MPVsTEC2       = new TH1D("MPVsTEC2"      ,"MPVsTEC2"      ,                300, 0, 600);
0192    TH1D* MPVsTECP1      = new TH1D("MPVsTECP1"     ,"MPVsTECP1"     ,                300, 0, 600);
0193    TH1D* MPVsTECP2      = new TH1D("MPVsTECP2"     ,"MPVsTECP2"     ,                300, 0, 600);
0194    TH1D* MPVsTECM1      = new TH1D("MPVsTECM1"     ,"MPVsTECM1"     ,                300, 0, 600);
0195    TH1D* MPVsTECM2      = new TH1D("MPVsTECM2"     ,"MPVsTECM2"     ,                300, 0, 600);
0196 
0197 
0198    TH1D* MPVError       = new TH1D("MPVError"      ,"MPVError"      ,                150, 0, 150);
0199    TH2D* MPVErrorVsMPV  = new TH2D("MPVErrorVsMPV" ,"MPVErrorVsMPV" ,300,    0, 600, 150, 0, 150);
0200    TH2D* MPVErrorVsEta  = new TH2D("MPVErrorVsEta" ,"MPVErrorVsEta" , 50, -3.0, 3.0, 150, 0, 150); 
0201    TH2D* MPVErrorVsPhi  = new TH2D("MPVErrorVsPhi" ,"MPVErrorVsPhi" , 50, -3.4, 3.4, 150, 0, 150);             
0202    TH2D* MPVErrorVsN    = new TH2D("MPVErrorVsN"   ,"MPVErrorVsN"   ,500,    0,1000, 150, 0, 150);              
0203 
0204 
0205    TH1D* ChargeWoG1     = new TH1D("ChargeWoG1"    ,"ChargeWoG1"    ,               2000, 0,4000); 
0206    TH1D* ChargeWoG1TIB  = new TH1D("ChargeWoG1TIB" ,"ChargeWoG1TIB" ,               2000, 0,4000);
0207    TH1D* ChargeWoG1TID  = new TH1D("ChargeWoG1TID" ,"ChargeWoG1TID" ,               2000, 0,4000);
0208    TH1D* ChargeWoG1TOB  = new TH1D("ChargeWoG1TOB" ,"ChargeWoG1TOB" ,               2000, 0,4000);
0209    TH1D* ChargeWoG1TEC  = new TH1D("ChargeWoG1TEC" ,"ChargeWoG1TEC" ,               2000, 0,4000);
0210    
0211    TH1D* ChargeWoG1G2     = new TH1D("ChargeWoG1G2"    ,"ChargeWoG1G2"    ,               2000, 0,4000); 
0212    TH1D* ChargeWoG1G2TIB  = new TH1D("ChargeWoG1G2TIB" ,"ChargeWoG1G2TIB" ,               2000, 0,4000);
0213    TH1D* ChargeWoG1G2TID  = new TH1D("ChargeWoG1G2TID" ,"ChargeWoG1G2TID" ,               2000, 0,4000);
0214    TH1D* ChargeWoG1G2TOB  = new TH1D("ChargeWoG1G2TOB" ,"ChargeWoG1G2TOB" ,               2000, 0,4000);
0215    TH1D* ChargeWoG1G2TEC  = new TH1D("ChargeWoG1G2TEC" ,"ChargeWoG1G2TEC" ,               2000, 0,4000);
0216 
0217 
0218    TH1D* ChargeWoG2     = new TH1D("ChargeWoG2"    ,"ChargeWoG2"    ,               2000, 0,4000); 
0219    TH1D* ChargeWoG2TIB  = new TH1D("ChargeWoG2TIB" ,"ChargeWoG2TIB" ,               2000, 0,4000);
0220    TH1D* ChargeWoG2TID  = new TH1D("ChargeWoG2TID" ,"ChargeWoG2TID" ,               2000, 0,4000);
0221    TH1D* ChargeWoG2TOB  = new TH1D("ChargeWoG2TOB" ,"ChargeWoG2TOB" ,               2000, 0,4000);
0222    TH1D* ChargeWoG2TEC  = new TH1D("ChargeWoG2TEC" ,"ChargeWoG2TEC" ,               2000, 0,4000);
0223 
0224 
0225    TH1D* ChargePIB      = new TH1D("ChargePIB"     ,"ChargePIB"     ,               2000, 0,4000);
0226    TH1D* ChargePIE      = new TH1D("ChargePIE"     ,"ChargePIE"     ,               2000, 0,4000);
0227    TH1D* ChargeTIB      = new TH1D("ChargeTIB"     ,"ChargeTIB"     ,               2000, 0,4000);
0228    TH1D* ChargeTID      = new TH1D("ChargeTID"     ,"ChargeTID"     ,               2000, 0,4000);
0229    TH1D* ChargeTIDP     = new TH1D("ChargeTIDP"    ,"ChargeTIDP"    ,               2000, 0,4000);
0230    TH1D* ChargeTIDM     = new TH1D("ChargeTIDM"    ,"ChargeTIDM"    ,               2000, 0,4000);
0231    TH1D* ChargeTOB      = new TH1D("ChargeTOB"     ,"ChargeTOB"     ,               2000, 0,4000);
0232    TH1D* ChargeTEC      = new TH1D("ChargeTEC"     ,"ChargeTEC"     ,               2000, 0,4000);
0233    TH1D* ChargeTECP     = new TH1D("ChargeTECP"    ,"ChargeTECP"    ,               2000, 0,4000);
0234    TH1D* ChargeTECM     = new TH1D("ChargeTECM"    ,"ChargeTECM"    ,               2000, 0,4000);
0235    TH1D* ChargeTEC1     = new TH1D("ChargeTEC1"    ,"ChargeTEC1"    ,               2000, 0,4000);
0236    TH1D* ChargeTEC2     = new TH1D("ChargeTEC2"    ,"ChargeTEC2"    ,               2000, 0,4000);
0237    TH1D* ChargeTECP1    = new TH1D("ChargeTECP1"   ,"ChargeTECP1"   ,               2000, 0,4000);
0238    TH1D* ChargeTECP2    = new TH1D("ChargeTECP2"   ,"ChargeTECP2"   ,               2000, 0,4000);
0239    TH1D* ChargeTECM1    = new TH1D("ChargeTECM1"   ,"ChargeTECM1"   ,               2000, 0,4000);
0240    TH1D* ChargeTECM2    = new TH1D("ChargeTECM2"   ,"ChargeTECM2"   ,               2000, 0,4000);
0241 /*
0242    TH1D* ChargeAbsPIB   = new TH1D("ChargeAbsPIB"  ,"ChargeAbsPIB"  ,               1000, 0,4000);
0243    TH1D* ChargeAbsPIE   = new TH1D("ChargeAbsPIE"  ,"ChargeAbsPIE"  ,               1000, 0,4000);
0244    TH1D* ChargeAbsTIB   = new TH1D("ChargeAbsTIB"  ,"ChargeAbsTIB"  ,               1000, 0,4000);
0245    TH1D* ChargeAbsTID   = new TH1D("ChargeAbsTID"  ,"ChargeAbsTID"  ,               1000, 0,4000);
0246    TH1D* ChargeAbsTIDP  = new TH1D("ChargeAbsTIDP" ,"ChargeAbsTIDP" ,               1000, 0,4000);
0247    TH1D* ChargeAbsTIDM  = new TH1D("ChargeAbsTIDM" ,"ChargeAbsTIDM" ,               1000, 0,4000);
0248    TH1D* ChargeAbsTOB   = new TH1D("ChargeAbsTOB"  ,"ChargeAbsTOB"  ,               1000, 0,4000);
0249    TH1D* ChargeAbsTEC   = new TH1D("ChargeAbsTEC"  ,"ChargeAbsTEC"  ,               1000, 0,4000);
0250    TH1D* ChargeAbsTECP  = new TH1D("ChargeAbsTECP" ,"ChargeAbsTECP" ,               1000, 0,4000);
0251    TH1D* ChargeAbsTECM  = new TH1D("ChargeAbsTECM" ,"ChargeAbsTECM" ,               1000, 0,4000);
0252    TH1D* ChargeAbsTEC1  = new TH1D("ChargeAbsTEC1" ,"ChargeAbsTEC1" ,               1000, 0,4000);
0253    TH1D* ChargeAbsTEC2  = new TH1D("ChargeAbsTEC2" ,"ChargeAbsTEC2" ,               1000, 0,4000);
0254    TH1D* ChargeAbsTECP1 = new TH1D("ChargeAbsTECP1","ChargeAbsTECP1",               1000, 0,4000);
0255    TH1D* ChargeAbsTECP2 = new TH1D("ChargeAbsTECP2","ChargeAbsTECP2",               1000, 0,4000);
0256    TH1D* ChargeAbsTECM1 = new TH1D("ChargeAbsTECM1","ChargeAbsTECM1",               1000, 0,4000);
0257    TH1D* ChargeAbsTECM2 = new TH1D("ChargeAbsTECM2","ChargeAbsTECM2",               1000, 0,4000);
0258 */
0259    TH1D* DiffWRTPrevGainPIB      = new TH1D("DiffWRTPrevGainPIB"     ,"DiffWRTPrevGainPIB"     ,               250, 0,2);
0260    TH1D* DiffWRTPrevGainPIE      = new TH1D("DiffWRTPrevGainPIE"     ,"DiffWRTPrevGainPIE"     ,               250, 0,2);
0261    TH1D* DiffWRTPrevGainTIB      = new TH1D("DiffWRTPrevGainTIB"     ,"DiffWRTPrevGainTIB"     ,               250, 0,2);
0262    TH1D* DiffWRTPrevGainTID      = new TH1D("DiffWRTPrevGainTID"     ,"DiffWRTPrevGainTID"     ,               250, 0,2);
0263    TH1D* DiffWRTPrevGainTOB      = new TH1D("DiffWRTPrevGainTOB"     ,"DiffWRTPrevGainTOB"     ,               250, 0,2);
0264    TH1D* DiffWRTPrevGainTEC      = new TH1D("DiffWRTPrevGainTEC"     ,"DiffWRTPrevGainTEC"     ,               250, 0,2);
0265 
0266    TH2D* GainVsPrevGainPIB      = new TH2D("GainVsPrevGainPIB"     ,"GainVsPrevGainPIB"     ,               100, 0,2, 100, 0,2);
0267    TH2D* GainVsPrevGainPIE      = new TH2D("GainVsPrevGainPIE"     ,"GainVsPrevGainPIE"     ,               100, 0,2, 100, 0,2);
0268    TH2D* GainVsPrevGainTIB      = new TH2D("GainVsPrevGainTIB"     ,"GainVsPrevGainTIB"     ,               100, 0,2, 100, 0,2);
0269    TH2D* GainVsPrevGainTID      = new TH2D("GainVsPrevGainTID"     ,"GainVsPrevGainTID"     ,               100, 0,2, 100, 0,2);
0270    TH2D* GainVsPrevGainTOB      = new TH2D("GainVsPrevGainTOB"     ,"GainVsPrevGainTOB"     ,               100, 0,2, 100, 0,2);
0271    TH2D* GainVsPrevGainTEC      = new TH2D("GainVsPrevGainTEC"     ,"GainVsPrevGainTEC"     ,               100, 0,2, 100, 0,2);
0272    
0273    printf("Progressing Bar              :0%%       20%%       40%%       60%%       80%%       100%%\n");
0274    printf("Looping on the Tree          :");
0275    int TreeStep = t1->GetEntries()/50;if(TreeStep==0)TreeStep=1;
0276    for (unsigned int ientry = 0; ientry < t1->GetEntries(); ientry++) {
0277       if(ientry%TreeStep==0){printf(".");fflush(stdout);}
0278       t1->GetEntry(ientry);
0279 
0280       int bin = ChargeDistrib->GetXaxis()->FindBin(tree_Index);
0281       TH1D* Proj         = ChargeDistrib ->ProjectionY("proj" ,bin, bin);
0282       TH1D* ProjScaledG1     = new TH1D("projScaledG1"      ,"projScaledG1"    ,               2000, 0,4000); 
0283       TH1D* ProjScaledG1G2   = new TH1D("projScaledG1G2"    ,"projScaledG1G2"  ,               2000, 0,4000); 
0284       TH1D* ProjScaledG2     = new TH1D("projScaledG2"      ,"projScaledG2"    ,               2000, 0,4000); 
0285       //TH1D* ProjAbsolute = ChargeDistribA->ProjectionY("projA",bin, bin);
0286 
0287       if(tree_SubDet>=3 && tree_FitMPV<0      ) NoMPV         ->Fill(tree_z ,tree_R);
0288       if(tree_SubDet>=3 && tree_FitMPV>=0){
0289 
0290       if(tree_SubDet==3                       ) MPV_Vs_EtaTIB ->Fill(tree_Eta,tree_FitMPV);
0291       if(tree_SubDet==4                       ) MPV_Vs_EtaTID ->Fill(tree_Eta,tree_FitMPV);
0292       if(tree_SubDet==5                       ) MPV_Vs_EtaTOB ->Fill(tree_Eta,tree_FitMPV);
0293       if(tree_SubDet==6                       ) MPV_Vs_EtaTEC ->Fill(tree_Eta,tree_FitMPV);
0294       if(tree_SubDet==6 && tree_Thickness<0.04) MPV_Vs_EtaTEC1->Fill(tree_Eta,tree_FitMPV);
0295       if(tree_SubDet==6 && tree_Thickness>0.04) MPV_Vs_EtaTEC2->Fill(tree_Eta,tree_FitMPV);
0296 
0297       if(tree_SubDet==3                       ) MPV_Vs_PhiTIB ->Fill(tree_Phi,tree_FitMPV);
0298       if(tree_SubDet==4                       ) MPV_Vs_PhiTID ->Fill(tree_Phi,tree_FitMPV);
0299       if(tree_SubDet==5                       ) MPV_Vs_PhiTOB ->Fill(tree_Phi,tree_FitMPV);
0300       if(tree_SubDet==6                       ) MPV_Vs_PhiTEC ->Fill(tree_Phi,tree_FitMPV);
0301       if(tree_SubDet==6 && tree_Thickness<0.04) MPV_Vs_PhiTEC1->Fill(tree_Phi,tree_FitMPV);
0302       if(tree_SubDet==6 && tree_Thickness>0.04) MPV_Vs_PhiTEC2->Fill(tree_Phi,tree_FitMPV);
0303 
0304       if(tree_FitMPV>0                        ) Gains         ->Fill(         tree_Gain  );
0305                                                 MPVs          ->Fill(         tree_FitMPV);
0306       if(                  tree_Thickness<0.04) MPVs320       ->Fill(         tree_FitMPV);
0307       if(                  tree_Thickness>0.04) MPVs500       ->Fill(         tree_FitMPV);
0308       if(tree_SubDet==3                       ) MPVsTIB       ->Fill(         tree_FitMPV);
0309       if(tree_SubDet==4                       ) MPVsTID       ->Fill(         tree_FitMPV);
0310       if(tree_SubDet==4 && tree_Eta<0         ) MPVsTIDM      ->Fill(         tree_FitMPV);
0311       if(tree_SubDet==4 && tree_Eta>0         ) MPVsTIDP      ->Fill(         tree_FitMPV);
0312       if(tree_SubDet==5                       ) MPVsTOB       ->Fill(         tree_FitMPV);
0313       if(tree_SubDet==6                       ) MPVsTEC       ->Fill(         tree_FitMPV);
0314       if(tree_SubDet==6 && tree_Thickness<0.04) MPVsTEC1      ->Fill(         tree_FitMPV);
0315       if(tree_SubDet==6 && tree_Thickness>0.04) MPVsTEC2      ->Fill(         tree_FitMPV);
0316       if(tree_SubDet==6 && tree_Eta<0         ) MPVsTECP      ->Fill(         tree_FitMPV);
0317       if(tree_SubDet==6 && tree_Eta>0         ) MPVsTECM      ->Fill(         tree_FitMPV);
0318       if(tree_SubDet==6 && tree_Thickness<0.04 && tree_Eta>0) MPVsTECP1      ->Fill(         tree_FitMPV);
0319       if(tree_SubDet==6 && tree_Thickness>0.04 && tree_Eta>0) MPVsTECP2      ->Fill(         tree_FitMPV);
0320       if(tree_SubDet==6 && tree_Thickness<0.04 && tree_Eta<0) MPVsTECM1      ->Fill(         tree_FitMPV);
0321       if(tree_SubDet==6 && tree_Thickness>0.04 && tree_Eta<0) MPVsTECM2      ->Fill(         tree_FitMPV);
0322 
0323                                                 MPVError      ->Fill(         tree_FitMPVErr);    
0324                                                 MPVErrorVsMPV ->Fill(tree_FitMPV,tree_FitMPVErr);
0325                                                 MPVErrorVsEta ->Fill(tree_Eta,tree_FitMPVErr);
0326                                                 MPVErrorVsPhi ->Fill(tree_Phi,tree_FitMPVErr);
0327                                                 MPVErrorVsN   ->Fill(tree_NEntries,tree_FitMPVErr);
0328       }
0329       
0330       // Rescaling histogram...
0331       if (tree_PrevGainTick>0 && tree_PrevGain >0){
0332          for (int binId=0; binId<Proj->GetXaxis()->GetNbins(); binId++){
0333 /*            float binX = Proj->GetXaxis()->GetBinCenter(binId);
0334             ProjScaledG1->Fill(tree_PrevGainTick*binX,Proj->GetBinContent(binId));   
0335             ProjScaledG1G2->Fill(tree_PrevGainTick*tree_PrevGain*binX,Proj->GetBinContent(binId));   
0336             ProjScaledG2->Fill(tree_PrevGain*binX,Proj->GetBinContent(binId));   */
0337             ProjScaledG1->SetBinContent(tree_PrevGainTick*binId,Proj->GetBinContent(binId));   
0338             ProjScaledG1G2->SetBinContent(tree_PrevGainTick*tree_PrevGain*binId,Proj->GetBinContent(binId));   
0339             ProjScaledG2->SetBinContent(tree_PrevGain*binId,Proj->GetBinContent(binId));
0340          }
0341       }
0342       
0343       ChargeWoG1 ->Add(ProjScaledG1,1);
0344 
0345       if(tree_SubDet==1                       ) {ChargePIB  ->Add(Proj,1);} 
0346       if(tree_SubDet==2                       ) {ChargePIE  ->Add(Proj,1);}
0347       if(tree_SubDet==3                       ) {ChargeTIB  ->Add(Proj,1); ChargeWoG1TIB->Add(ProjScaledG1,1);
0348                                                 ChargeWoG1G2TIB->Add(ProjScaledG1G2,1); ChargeWoG2TIB->Add(ProjScaledG2,1);}
0349       if(tree_SubDet==4                       ) {ChargeTID  ->Add(Proj,1); ChargeWoG1TID->Add(ProjScaledG1,1);
0350                                                 ChargeWoG1G2TID->Add(ProjScaledG1G2,1); ChargeWoG2TID->Add(ProjScaledG2,1);}
0351       if(tree_SubDet==4 && tree_Eta<0         ) {ChargeTIDM ->Add(Proj,1);}
0352       if(tree_SubDet==4 && tree_Eta>0         ) {ChargeTIDP ->Add(Proj,1);}
0353       if(tree_SubDet==5                       ) {ChargeTOB  ->Add(Proj,1); ChargeWoG1TOB->Add(ProjScaledG1,1);
0354                                                 ChargeWoG1G2TOB->Add(ProjScaledG1G2,1); ChargeWoG2TOB->Add(ProjScaledG2,1);}
0355       if(tree_SubDet==6                       ) {ChargeTEC  ->Add(Proj,1); ChargeWoG1TEC->Add(ProjScaledG1,1);
0356                                                 ChargeWoG1G2TEC->Add(ProjScaledG1G2,1); ChargeWoG2TEC->Add(ProjScaledG2,1);}
0357       if(tree_SubDet==6 && tree_Thickness<0.04) {ChargeTEC1 ->Add(Proj,1);}
0358       if(tree_SubDet==6 && tree_Thickness>0.04) {ChargeTEC2 ->Add(Proj,1);}
0359       if(tree_SubDet==6 && tree_Eta>0         ) {ChargeTECP ->Add(Proj,1);}
0360       if(tree_SubDet==6 && tree_Eta<0         ) {ChargeTECM ->Add(Proj,1);}
0361       if(tree_SubDet==6 && tree_Eta<0 && tree_Thickness<0.04) ChargeTECM1 ->Add(Proj,1);
0362       if(tree_SubDet==6 && tree_Eta<0 && tree_Thickness>0.04) ChargeTECM2 ->Add(Proj,1);
0363       if(tree_SubDet==6 && tree_Eta>0 && tree_Thickness<0.04) ChargeTECP1 ->Add(Proj,1);
0364       if(tree_SubDet==6 && tree_Eta>0 && tree_Thickness>0.04) ChargeTECP2 ->Add(Proj,1);
0365 /*
0366       if(tree_SubDet==1                       ) ChargeAbsPIB  ->Add(ProjAbsolute,1);
0367       if(tree_SubDet==2                       ) ChargeAbsPIE  ->Add(ProjAbsolute,1);
0368       if(tree_SubDet==3                       ) ChargeAbsTIB  ->Add(ProjAbsolute,1);
0369       if(tree_SubDet==4                       ) ChargeAbsTID  ->Add(ProjAbsolute,1);
0370       if(tree_SubDet==4 && tree_Eta<0         ) ChargeAbsTIDM ->Add(ProjAbsolute,1);
0371       if(tree_SubDet==4 && tree_Eta>0         ) ChargeAbsTIDP ->Add(ProjAbsolute,1);
0372       if(tree_SubDet==5                       ) ChargeAbsTOB  ->Add(ProjAbsolute,1);
0373       if(tree_SubDet==6                       ) ChargeAbsTEC  ->Add(ProjAbsolute,1);
0374       if(tree_SubDet==6 && tree_Thickness<0.04) ChargeAbsTEC1 ->Add(ProjAbsolute,1);
0375       if(tree_SubDet==6 && tree_Thickness>0.04) ChargeAbsTEC2 ->Add(ProjAbsolute,1);
0376       if(tree_SubDet==6 && tree_Eta>0         ) ChargeAbsTECP ->Add(ProjAbsolute,1);
0377       if(tree_SubDet==6 && tree_Eta<0         ) ChargeAbsTECM ->Add(ProjAbsolute,1);
0378       if(tree_SubDet==6 && tree_Eta<0 && tree_Thickness<0.04) ChargeAbsTECM1 ->Add(ProjAbsolute,1);
0379       if(tree_SubDet==6 && tree_Eta<0 && tree_Thickness>0.04) ChargeAbsTECM2 ->Add(ProjAbsolute,1);
0380       if(tree_SubDet==6 && tree_Eta>0 && tree_Thickness<0.04) ChargeAbsTECP1 ->Add(ProjAbsolute,1);
0381       if(tree_SubDet==6 && tree_Eta>0 && tree_Thickness>0.04) ChargeAbsTECP2 ->Add(ProjAbsolute,1);
0382 */
0383       if(tree_SubDet==1                       ) DiffWRTPrevGainPIB  ->Fill(tree_Gain/tree_PrevGain);
0384       if(tree_SubDet==2                       ) DiffWRTPrevGainPIE  ->Fill(tree_Gain/tree_PrevGain);
0385       if(tree_SubDet==3                       ) DiffWRTPrevGainTIB  ->Fill(tree_Gain/tree_PrevGain);
0386       if(tree_SubDet==4                       ) DiffWRTPrevGainTID  ->Fill(tree_Gain/tree_PrevGain);
0387       if(tree_SubDet==5                       ) DiffWRTPrevGainTOB  ->Fill(tree_Gain/tree_PrevGain);
0388       if(tree_SubDet==6                       ) DiffWRTPrevGainTEC  ->Fill(tree_Gain/tree_PrevGain);
0389 
0390       if(tree_SubDet==1                       ) GainVsPrevGainPIB  ->Fill(tree_PrevGain,tree_Gain);
0391       if(tree_SubDet==2                       ) GainVsPrevGainPIE  ->Fill(tree_PrevGain,tree_Gain);
0392       if(tree_SubDet==3                       ) GainVsPrevGainTIB  ->Fill(tree_PrevGain,tree_Gain);
0393       if(tree_SubDet==4                       ) GainVsPrevGainTID  ->Fill(tree_PrevGain,tree_Gain);
0394       if(tree_SubDet==5                       ) GainVsPrevGainTOB  ->Fill(tree_PrevGain,tree_Gain);
0395       if(tree_SubDet==6                       ) GainVsPrevGainTEC  ->Fill(tree_PrevGain,tree_Gain);
0396 
0397 
0398 
0399 
0400       delete Proj;
0401       delete ProjScaledG1;
0402       delete ProjScaledG2;
0403       delete ProjScaledG1G2;
0404       //delete ProjAbsolute;
0405    }printf("\n");
0406 
0407 
0408 
0409    // ######################################################### PRINT OUT APV INFOS #################################
0410    unsigned int CountAPV_Total    = 0;
0411    unsigned int CountAPV_NoEntry  = 0;
0412    unsigned int CountAPV_NoEntryU = 0;
0413    unsigned int CountAPV_NoGain   = 0;
0414    unsigned int CountAPV_NoGainU  = 0;
0415    unsigned int CountAPV_LowGain  = 0;
0416    unsigned int CountAPV_HighGain = 0;
0417    unsigned int CountAPV_DiffGain = 0;
0418 
0419    TrackerMap* tkmap = new TrackerMap("  ParticleGain  ");
0420 
0421    pFile = fopen((output + "_MAP.txt").c_str(),"w");
0422    fprintf(pFile,"#maxValue = 1.5\n");
0423    fprintf(pFile,"#minValue = 0.5\n");
0424    fprintf(pFile,"#defaultColor = 1.0,1.0,1.0,0.1\n");
0425    printf("Looping on the Tree          :");
0426    double MaxGain=0;  unsigned int previousMod=0;
0427    for (unsigned int ientry = 0; ientry < t1->GetEntries(); ientry++) {
0428       if(ientry%TreeStep==0){printf(".");fflush(stdout);}     
0429       t1->GetEntry(ientry);
0430       if (tree_DetId<369120277)continue;
0431       if(previousMod>0&&tree_APVId==0){fprintf(pFile,"%i %f\n",previousMod,MaxGain); tkmap->fill(previousMod, MaxGain);  MaxGain=1;  } 
0432       previousMod = tree_DetId;
0433       if(fabs(tree_Gain-1.0)>fabs(MaxGain-1))MaxGain=tree_Gain;
0434    }printf("\n");
0435    if(previousMod>0){fprintf(pFile,"%i %f\n",previousMod,MaxGain); tkmap->fill(previousMod, MaxGain); }
0436    fclose(pFile);
0437 
0438    tkmap->setTitle(TextToPrint + " : Module Gain");
0439    tkmap->save                 (true, 0.7, 1.3, output + "_TKMap_Gain_MECH.png");
0440    tkmap->reset();    
0441 
0442 
0443    pFile = fopen((output + "_NoClusterForAll.txt").c_str(),"w");
0444    fprintf(pFile,"\n\nALL APVs WITH NO ENTRIES (NO RECO CLUSTER ON IT)\n--------------------------------------------\n");
0445    printf("Looping on the Tree          :");
0446    for (unsigned int ientry = 0; ientry < t1->GetEntries(); ientry++) {      
0447       if(ientry%TreeStep==0){printf(".");fflush(stdout);}
0448       t1->GetEntry(ientry);  if(tree_SubDet<3)continue;
0449       if (tree_DetId<369120277)continue;
0450       CountAPV_Total++;
0451       if(tree_NEntries==0){fprintf(pFile,"%i-%i\n",tree_DetId,tree_APVId);  CountAPV_NoEntry++;}
0452    }printf("\n");
0453    fprintf(pFile,"\n--> %i / %i = %f%% APV Concerned\n",CountAPV_NoEntry,CountAPV_Total,(100.0*CountAPV_NoEntry)/CountAPV_Total);
0454    fclose(pFile);
0455 
0456 
0457    pFile = fopen((output + "_NoClusterForUnmasked.txt").c_str(),"w");
0458    fprintf(pFile,"\n\nUNMASKED APVs WITHOUT ANY CLUSTER (NO RECO CLUSTER ON IT)\n--------------------------------------------\n");
0459    printf("Looping on the Tree          :");
0460    for (unsigned int ientry = 0; ientry < t1->GetEntries(); ientry++) {
0461       if(ientry%TreeStep==0){printf(".");fflush(stdout);}
0462       t1->GetEntry(ientry);   if(tree_SubDet<3)continue;
0463       if (tree_DetId<369120277)continue;
0464       if(tree_NEntries==0 && !tree_isMasked){fprintf(pFile,"%i-%i\n",tree_DetId,tree_APVId); tkmap->fill(tree_DetId, 1); CountAPV_NoEntryU++;}
0465    }printf("\n");
0466    fprintf(pFile,"\n--> %i / %i = %f%% APV Concerned\n",CountAPV_NoEntryU,CountAPV_Total,(100.0*CountAPV_NoEntryU)/CountAPV_Total);
0467    fclose(pFile);
0468 
0469    tkmap->setTitle(TextToPrint + " : #Unmasked APV without any cluster");
0470    tkmap->save                 (true, 1.0, 6.0, output + "_TKMap_NoCluster_MECH.png");
0471    tkmap->reset();    
0472 
0473 
0474    pFile = fopen((output + "_NoGainForAll.txt").c_str(),"w");
0475    fprintf(pFile,"\n\nALL APVs WITH NO GAIN COMPUTED\n--------------------------------------------\n");
0476    printf("Looping on the Tree          :");
0477    for (unsigned int ientry = 0; ientry < t1->GetEntries(); ientry++) {
0478       if(ientry%TreeStep==0){printf(".");fflush(stdout);}
0479       t1->GetEntry(ientry);   if(tree_SubDet<3)continue;
0480       if (tree_DetId<369120277)continue;
0481       if(tree_FitMPV<0){fprintf(pFile,"%i-%i\n",tree_DetId,tree_APVId); CountAPV_NoGain++;}
0482    }printf("\n");
0483    fprintf(pFile,"\n--> %i / %i = %f%% APV Concerned\n",CountAPV_NoGain,CountAPV_Total,(100.0*CountAPV_NoGain)/CountAPV_Total);
0484    fclose(pFile);
0485 
0486    pFile = fopen((output + "_NoGainForUnmasked.txt").c_str(),"w");
0487    fprintf(pFile,"\n\nUNMASKED APVs WITH NO GAIN COMPUTED\n--------------------------------------------\n");
0488    printf("Looping on the Tree          :");
0489    for (unsigned int ientry = 0; ientry < t1->GetEntries(); ientry++) {
0490       if(ientry%TreeStep==0){printf(".");fflush(stdout);}
0491       t1->GetEntry(ientry);   if(tree_SubDet<3)continue;
0492       if (tree_DetId<369120277)continue;
0493       if(tree_FitMPV<0 && !tree_isMasked){fprintf(pFile,"%i-%i\n",tree_DetId,tree_APVId);  tkmap->fill(tree_DetId, 1); CountAPV_NoGainU++;}
0494    }printf("\n");
0495    fprintf(pFile,"\n--> %i / %i = %f%% APV Concerned\n",CountAPV_NoGainU,CountAPV_Total,(100.0*CountAPV_NoGainU)/CountAPV_Total);
0496    fclose(pFile);
0497 
0498    tkmap->setTitle(TextToPrint + " : #Unmasked APV for which no gain was computed");
0499    tkmap->save                 (true, 1.0, 6.0, output + "_TKMap_NoGain_MECH.png");
0500    tkmap->reset();
0501 
0502 
0503    pFile = fopen((output + "_LowResponseForUnmasked.txt").c_str(),"w");
0504    fprintf(pFile,"\n\nUNMASKED APVs WITH LOW RESPONSE\n--------------------------------------------\n");
0505    fprintf(pFile,"  ID-APV     Fit MPV   Gain\n");
0506    printf("Looping on the Tree          :");
0507    for (unsigned int ientry = 0; ientry < t1->GetEntries(); ientry++) {
0508       if(ientry%TreeStep==0){printf(".");fflush(stdout);}
0509       t1->GetEntry(ientry);   if(tree_SubDet<3)continue;
0510       if (tree_DetId<369120277)continue;
0511       if(tree_FitMPV>0 && tree_FitMPV<220 && !tree_isMasked) {
0512           fprintf(pFile,"%i-%i   %5.1f   %4.1f\n",tree_DetId,tree_APVId,tree_FitMPV,tree_Gain); 
0513           tkmap->fill(tree_DetId, 1); 
0514           CountAPV_LowGain++;
0515       }
0516    }printf("\n");
0517    fprintf(pFile,"\n--> %i / %i = %f%% APV Concerned\n",CountAPV_LowGain,CountAPV_Total,(100.0*CountAPV_LowGain)/CountAPV_Total);
0518    fclose(pFile);
0519 
0520    tkmap->setTitle(TextToPrint + " : #Unmasked APV with a gain > 1.26");
0521    tkmap->save                 (true, 1.0, 6.0, output + "_TKMap_highGain_MECH.png");
0522    tkmap->reset();
0523 
0524 
0525    pFile = fopen((output + "_HighResponseForUnmasked.txt").c_str(),"w");
0526    fprintf(pFile,"\n\nUNMASKED APVs WITH HIGH RESPONSE\n--------------------------------------------\n");
0527    fprintf(pFile,"  ID-APV     Fit MPV   Gain\n");
0528    printf("Looping on the Tree          :");
0529    for (unsigned int ientry = 0; ientry < t1->GetEntries(); ientry++) {
0530       if(ientry%TreeStep==0){printf(".");fflush(stdout);}
0531       t1->GetEntry(ientry);   if(tree_SubDet<3)continue;
0532       if (tree_DetId<369120277)continue;
0533       if(tree_FitMPV>0 && tree_FitMPV>380 && !tree_isMasked) {
0534           fprintf(pFile,"%i-%i   %5.1f   %4.1f\n",tree_DetId,tree_APVId,tree_FitMPV,tree_Gain);
0535           tkmap->fill(tree_DetId, 1);
0536           CountAPV_HighGain++;
0537       }
0538    }printf("\n");
0539    fprintf(pFile,"\n--> %i / %i = %f%% APV Concerned\n",CountAPV_HighGain,CountAPV_Total,(100.0*CountAPV_HighGain)/CountAPV_Total);
0540    fclose(pFile);
0541 
0542 
0543    tkmap->setTitle(TextToPrint + " : #Unmasked APV with a gain<0.75");
0544    tkmap->save                 (true, 1.0, 6.0, output + "_TKMap_LowGain_MECH.png");
0545    tkmap->reset();
0546 
0547 
0548 
0549    pFile = fopen((output + "_BigGainChangeForUnmasked.txt").c_str(),"w");
0550    fprintf(pFile,"\n\nUNMASKED APVs WITH SIGNIFICANT CHANGE OF GAIN VALUE\n--------------------------------------------\n");
0551    printf("Looping on the Tree          :");
0552    for (unsigned int ientry = 0; ientry < t1->GetEntries(); ientry++) {
0553       if(ientry%TreeStep==0){printf(".");fflush(stdout);}
0554       t1->GetEntry(ientry);   if(tree_SubDet<3)continue;
0555       if (tree_DetId<369120277)continue;
0556       if(tree_FitMPV>0 && !tree_isMasked && (tree_Gain/tree_PrevGain<0.7 || tree_Gain/tree_PrevGain>1.3)){fprintf(pFile,"%i-%i\n",tree_DetId,tree_APVId); tkmap->fill(tree_DetId, 1); CountAPV_DiffGain++;}
0557    }printf("\n");
0558    fprintf(pFile,"\n--> %i / %i = %f%% APV Concerned\n",CountAPV_DiffGain,CountAPV_Total,(100.0*CountAPV_DiffGain)/CountAPV_Total);
0559    fclose(pFile);
0560 
0561    tkmap->setTitle(TextToPrint + " : #Unmasked APV with a gain variation > 30\% w.r.t GT");
0562    tkmap->save                 (true, 1.0, 6.0, output + "_TKMap_GainChange_MECH.png");
0563    tkmap->reset();
0564 
0565 
0566    // ######################################################### TrackerMAP  ONLY          #################################
0567 
0568    printf("Looping on the Tree          :");
0569    double MaxError=-1;  previousMod=0;
0570    for (unsigned int ientry = 0; ientry < t1->GetEntries(); ientry++) {
0571       if(ientry%TreeStep==0){printf(".");fflush(stdout);}     
0572       t1->GetEntry(ientry);
0573       if (tree_DetId<369120277)continue;
0574       if(previousMod>0&&tree_APVId==0&&MaxError>=0){tkmap->fill(previousMod, 100.0*MaxError);  MaxError=-1;  } 
0575       previousMod = tree_DetId;
0576       if(tree_FitMPV>0 && tree_FitMPVErr/300.0>MaxError)MaxError=tree_FitMPVErr/300.0;
0577    }printf("\n");
0578    if(previousMod>0){tkmap->fill(previousMod, 100.0*MaxError); }
0579    tkmap->setTitle(TextToPrint + " : Error on Module Gain (%)");
0580    tkmap->save                 (true, 0, 15, output + "_TKMap_GainError_MECH.png");
0581    tkmap->reset();    
0582 
0583 
0584 
0585    printf("Looping on the Tree          :");
0586    double MaxRatio=0;  previousMod=0;
0587    for (unsigned int ientry = 0; ientry < t1->GetEntries(); ientry++) {
0588       if(ientry%TreeStep==0){printf(".");fflush(stdout);}
0589       t1->GetEntry(ientry);
0590       if (tree_DetId<369120277)continue;
0591       if(previousMod>0&&tree_APVId==0&&fabs(MaxRatio)>=0){tkmap->fill(previousMod, MaxRatio);  MaxRatio=0;  }
0592       previousMod = tree_DetId;
0593       if(tree_FitMPV>0 && fabs((tree_Gain/tree_PrevGain)-1)>fabs(MaxRatio))MaxRatio=(tree_Gain/tree_PrevGain)-1;
0594    }printf("\n");
0595    if(previousMod>0){tkmap->fill(previousMod, MaxRatio); }
0596    tkmap->setTitle(TextToPrint + " :  (G2new / G2gt) - 1  per module");
0597    tkmap->save                 (true, -0.5, 0.5, output + "_TKMap_GainRatio_MECH.png");
0598    tkmap->save                 (true, -0.1, 0.1, output + "_TKMap_GainRatio_MECH_zoom.png");
0599    tkmap->reset();
0600 
0601 
0602    printf("Looping on the Tree          :");
0603    double prevEntries=-1;  previousMod=0; double nEntriesMax=-1;
0604    for (unsigned int ientry = 0; ientry < t1->GetEntries(); ientry++) {
0605       if(ientry%TreeStep==0){printf(".");fflush(stdout);}
0606       t1->GetEntry(ientry);
0607       if (tree_DetId<369120277)continue;
0608       if(previousMod>0&&tree_APVId==0&&prevEntries>0){
0609          tkmap->fill(previousMod, prevEntries); 
0610          if(prevEntries>nEntriesMax)nEntriesMax=prevEntries;
0611          prevEntries=-1;  
0612          }
0613       previousMod=tree_DetId;
0614       prevEntries+=tree_NEntries;
0615    }printf("\n");
0616    if(previousMod>0){tkmap->fill(previousMod, prevEntries+1); }
0617    tkmap->setTitle(TextToPrint + " : Number of entries");
0618    tkmap->save                 (true, 0.0, nEntriesMax, output + "_TKMap_Nentries.png");
0619    tkmap->save                 (true, 0.0, 5000, output + "_TKMap_Nentries_zoom.png");
0620    tkmap->reset();
0621    // ######################################################### PRINT DISTRIBUTION INFO #################################
0622     gROOT->Reset();
0623    setTDRStyle();
0624    gStyle->SetPadTopMargin   (0.05);
0625    gStyle->SetPadBottomMargin(0.10);
0626    gStyle->SetPadRightMargin (0.18);
0627    gStyle->SetPadLeftMargin  (0.13);
0628    gStyle->SetTitleSize(0.04, "XYZ");
0629    gStyle->SetTitleXOffset(1.1);
0630    gStyle->SetTitleYOffset(1.35);
0631    gStyle->SetPalette(1);
0632    gStyle->SetCanvasColor(0);
0633    gStyle->SetBarOffset(0);
0634   
0635    pFile = fopen((output + "_SubDetector_MPV.txt").c_str(),"w");
0636 
0637    double Results[5]; TF1* landau;
0638 
0639    landau = getLandau(ChargePIB, Results, 0, 5400);
0640    c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0641    ChargePIB->Draw();
0642    landau->SetLineWidth(3);
0643    landau->Draw("same");
0644    DrawPreliminary(TextToPrint);
0645    SaveCanvas(c1,output,"SubDetChargePIB");
0646    fprintf(pFile,"PIB   MPV=%7.2f +- %7.2f  Chi2=%7.2f\n",Results[0],Results[1],Results[4]);
0647    
0648    c1 = new TCanvas("c1","c1,",600,600);      legend.clear();
0649    Histos[0] = ChargeWoG2TEC;               legend.push_back("TEC");
0650    Histos[1] = ChargeWoG2TIB;               legend.push_back("TIB");
0651    Histos[2] = ChargeWoG2TID;               legend.push_back("TID");
0652    Histos[3] = ChargeWoG2TOB;               legend.push_back("TOB");
0653    DrawSuperposedHistos((TH1**)Histos, legend, "",  "Charge after G2 removal [ADC/mm]", "Number of Clusters", 0,800 , 0,0);
0654    TLine* l0s = new TLine(300, 0,300,((TH1*)Histos[0])->GetMaximum()); l0s->SetLineWidth(3); l0s->SetLineStyle(2); l0s->Draw("same");
0655    DrawLegend(Histos,legend,"","P");
0656    DrawPreliminary(TextToPrint);
0657    SaveCanvas(c1,output,"ChargeWithoutG2SubDet");
0658    delete l0s;
0659 
0660    c1 = new TCanvas("c1","c1,",600,600);      legend.clear();
0661    Histos[0] = ChargeWoG1G2TEC;               legend.push_back("TEC");
0662    Histos[1] = ChargeWoG1G2TIB;               legend.push_back("TIB");
0663    Histos[2] = ChargeWoG1G2TID;               legend.push_back("TID");
0664    Histos[3] = ChargeWoG1G2TOB;               legend.push_back("TOB");
0665    DrawSuperposedHistos((TH1**)Histos, legend, "",  "Charge after G1&G2 removal [ADC/mm]", "Number of Clusters", 0,800 , 0,0);
0666    l0s = new TLine(300, 0,300,((TH1*)Histos[0])->GetMaximum()); l0s->SetLineWidth(3); l0s->SetLineStyle(2); l0s->Draw("same");
0667    DrawLegend(Histos,legend,"","P");
0668    DrawPreliminary(TextToPrint);
0669    SaveCanvas(c1,output,"ChargeWithoutG1G2SubDet");
0670    delete l0s;
0671 
0672    c1 = new TCanvas("c1","c1,",600,600);      legend.clear();
0673    Histos[0] = ChargeWoG1TEC;               legend.push_back("TEC");
0674    Histos[1] = ChargeWoG1TIB;               legend.push_back("TIB");
0675    Histos[2] = ChargeWoG1TID;               legend.push_back("TID");
0676    Histos[3] = ChargeWoG1TOB;               legend.push_back("TOB");
0677    DrawSuperposedHistos((TH1**)Histos, legend, "",  "Charge after G1 removal [ADC/mm]", "Number of Clusters", 0,800 , 0,0);
0678    l0s = new TLine(300, 0,300,((TH1*)Histos[0])->GetMaximum()); l0s->SetLineWidth(3); l0s->SetLineStyle(2); l0s->Draw("same");
0679    DrawLegend(Histos,legend,"","P");
0680    DrawPreliminary(TextToPrint);
0681    SaveCanvas(c1,output,"ChargeWithoutG1SubDet");
0682    delete l0s;
0683 
0684    landau = getLandau(ChargePIE, Results, 0, 5400);
0685    c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0686    ChargePIE->Draw();
0687    landau->SetLineWidth(3);
0688    landau->Draw("same");
0689    DrawPreliminary(TextToPrint);
0690    SaveCanvas(c1,output,"SubDetChargePIE");
0691    fprintf(pFile,"PIE   MPV=%7.2f +- %7.2f  Chi2=%7.2f\n",Results[0],Results[1],Results[4]);
0692 
0693 
0694    landau = getLandau(ChargeTIB, Results, 0, 5400);
0695    c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0696    ChargeTIB->Draw();
0697    landau->SetLineWidth(3);
0698    landau->Draw("same");
0699    DrawPreliminary(TextToPrint);
0700    SaveCanvas(c1,output,"SubDetChargeTIB");
0701    fprintf(pFile,"TIB   MPV=%7.2f +- %7.2f  Chi2=%7.2f\n",Results[0],Results[1],Results[4]);
0702 
0703    landau = getLandau(ChargeTIDM, Results, 0, 5400);
0704    c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0705    ChargeTIDM->Draw();
0706    landau->SetLineWidth(3);
0707    landau->Draw("same");
0708    DrawPreliminary(TextToPrint);
0709    SaveCanvas(c1,output,"SubDetChargeTIDM");
0710    fprintf(pFile, "TIDM  MPV=%7.2f +- %7.2f  Chi2=%7.2f\n",Results[0],Results[1],Results[4]);
0711 
0712    landau = getLandau(ChargeTIDP, Results, 0, 5400);
0713    c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0714    ChargeTIDP->Draw();
0715    landau->SetLineWidth(3);
0716    landau->Draw("same");
0717    DrawPreliminary(TextToPrint);
0718    SaveCanvas(c1,output,"SubDetChargeTIDP");
0719    fprintf(pFile, "TIDP  MPV=%7.2f +- %7.2f  Chi2=%7.2f\n",Results[0],Results[1],Results[4]);
0720 
0721    landau = getLandau(ChargeTOB, Results, 0, 5400);
0722    c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0723    ChargeTOB->Draw();
0724    landau->SetLineWidth(3);
0725    landau->Draw("same");
0726    DrawPreliminary(TextToPrint);
0727    SaveCanvas(c1,output,"SubDetChargeTOB");
0728    fprintf(pFile, "TOB   MPV=%7.2f +- %7.2f  Chi2=%7.2f\n",Results[0],Results[1],Results[4]);
0729 
0730    landau = getLandau(ChargeTECP1, Results, 0, 5400);
0731    c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0732    ChargeTECP1->Draw();
0733    landau->SetLineWidth(3);
0734    landau->Draw("same");
0735    DrawPreliminary(TextToPrint);
0736    SaveCanvas(c1,output,"SubDetChargeTECP1");
0737    fprintf(pFile, "TECP1 MPV=%7.2f +- %7.2f  Chi2=%7.2f\n",Results[0],Results[1],Results[4]);
0738 
0739    landau = getLandau(ChargeTECP2, Results, 0, 5400);
0740    c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0741    ChargeTECP2->Draw();
0742    landau->SetLineWidth(3);
0743    landau->Draw("same");
0744    DrawPreliminary(TextToPrint);
0745    SaveCanvas(c1,output,"SubDetChargeTECP2");
0746    fprintf(pFile, "TECP2 MPV=%7.2f +- %7.2f  Chi2=%7.2f\n",Results[0],Results[1],Results[4]);
0747 
0748    landau = getLandau(ChargeTECM1, Results, 0, 5400);
0749    c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0750    ChargeTECM1->Draw();
0751    landau->SetLineWidth(3);
0752    landau->Draw("same");
0753    DrawPreliminary(TextToPrint);
0754    SaveCanvas(c1,output,"SubDetChargeTECM1");
0755    fprintf(pFile, "TECM1 MPV=%7.2f +- %7.2f  Chi2=%7.2f\n",Results[0],Results[1],Results[4]);
0756 
0757    landau = getLandau(ChargeTECM2, Results, 0, 5400);
0758    c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0759    ChargeTECM2->Draw();
0760    landau->SetLineWidth(3);
0761    landau->Draw("same");
0762    DrawPreliminary(TextToPrint);
0763    SaveCanvas(c1,output,"SubDetChargeTECM2");
0764    fprintf(pFile, "TECM2 MPV=%7.2f +- %7.2f  Chi2=%7.2f\n",Results[0],Results[1],Results[4]);
0765 
0766    fclose(pFile);
0767    // ######################################################### MAKE PLOTS #################################
0768 
0769 
0770    c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0771    Histos[0] = MPV_Vs_EtaTEC;                     legend.push_back("TEC");
0772    Histos[1] = MPV_Vs_EtaTIB;                     legend.push_back("TIB");
0773    Histos[2] = MPV_Vs_EtaTID;                     legend.push_back("TID");
0774    Histos[3] = MPV_Vs_EtaTOB;                     legend.push_back("TOB");
0775    DrawTH2D((TH2D**)Histos,legend, "", "module #eta", "MPV [ADC/mm]", -3.0,3.0, 0,600);
0776    DrawLegend (Histos,legend,"","P");
0777    DrawStatBox(Histos,legend,false);
0778    DrawPreliminary(TextToPrint);
0779    SaveCanvas(c1,output,"MPV_Vs_EtaSubDet");
0780    delete c1;
0781 
0782     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0783     Histos[0] = MPV_Vs_PhiTEC;                     legend.push_back("TEC");
0784     Histos[1] = MPV_Vs_PhiTIB;                     legend.push_back("TIB");
0785     Histos[2] = MPV_Vs_PhiTID;                     legend.push_back("TID");
0786     Histos[3] = MPV_Vs_PhiTOB;                     legend.push_back("TOB");
0787     DrawTH2D((TH2D**)Histos,legend, "", "module #phi", "MPV [ADC/mm]", -3.4,3.4, 0,600);
0788     DrawLegend(Histos,legend,"","P");
0789     DrawStatBox(Histos,legend,false);
0790     DrawPreliminary(TextToPrint);
0791     SaveCanvas(c1,output,"MPV_Vs_PhiSubDet");
0792     delete c1;
0793 
0794     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0795     Histos[0] = NoMPV;                             legend.push_back("NoMPV");
0796     DrawTH2D((TH2D**)Histos,legend, "", "z (cm)", "R (cms)", 0,0, 0,0);
0797     DrawPreliminary(TextToPrint);
0798     SaveCanvas(c1,output,"NoMPV", true);
0799     delete c1;
0800 
0801     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0802     ChargeDistrib->GetXaxis()->SetNdivisions(5+500);
0803     Histos[0] = ChargeDistrib;                     legend.push_back("Charge Vs Index");
0804     DrawTH2D((TH2D**)Histos,legend, "COLZ", "APV Index", "Charge [ADC/mm]", 0,0, 0,0);
0805     c1->SetLogz(true);
0806     DrawPreliminary(TextToPrint);
0807     SaveCanvas(c1,output,"Charge2D", true);
0808     delete c1;
0809 
0810     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0811     Histos[0] = Gains;                             legend.push_back("");
0812     DrawSuperposedHistos((TH1**)Histos, legend, "",  "Gain", "Number of APVs", 0.5,1.5, 0,0);
0813     DrawLegend(Histos,legend,"","L");
0814     DrawStatBox(Histos,legend,true);
0815     SaveCanvas(c1,output,"Gains");
0816 
0817     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0818     Histos[0] = MPVs320;                           legend.push_back("320 #mum");
0819     Histos[1] = MPVs500;                           legend.push_back("500 #mum");
0820     Histos[2] = MPVs;                              legend.push_back("320 + 500 #mum");
0821     DrawSuperposedHistos((TH1**)Histos, legend, "",  "MPV [ADC/mm]", "Number of APVs", 100,550, 0,0);
0822     DrawLegend(Histos,legend,"","L");
0823     DrawPreliminary(TextToPrint);
0824     SaveCanvas(c1,output,"MPVs");
0825     c1->SetLogy(true);
0826     SaveCanvas(c1,output,"MPVsLog");
0827     DrawStatBox(Histos,legend,true);
0828     c1->SetLogy(false);
0829     SaveCanvas(c1,output,"MPVsAndStat");
0830     c1->SetLogy(true);
0831     SaveCanvas(c1,output,"MPVsLogAndStat");
0832     delete c1;
0833 
0834 
0835     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0836     MPVsTOB->GetXaxis()->SetNdivisions(5+500);
0837     Histos[0] = MPVsTIB;                           legend.push_back("TIB (320 #mum)");
0838     Histos[1] = MPVsTID;                           legend.push_back("TID (320 #mum)");
0839     Histos[2] = MPVsTOB;                           legend.push_back("TOB (500 #mum)");
0840     Histos[3] = MPVsTEC1;                          legend.push_back("TEC (320 #mum)");
0841     Histos[4] = MPVsTEC2;                          legend.push_back("TEC (500 #mum)");
0842 //    Histos[5] = MPVs;                              legend.push_back("All");
0843     DrawSuperposedHistos((TH1**)Histos, legend, "",  "MPV [ADC/mm]", "Number of APVs", 100,550, 0,0);
0844     DrawLegend(Histos,legend,"","L");
0845     DrawPreliminary(TextToPrint);
0846     SaveCanvas(c1,output,"MPVsSubDet");
0847     c1->SetLogy(true);
0848     SaveCanvas(c1,output,"MPVsSubDetLog");
0849     DrawStatBox(Histos,legend,true);
0850     SaveCanvas(c1,output,"MPVsSubDetLogAndStat");
0851     c1->SetLogy(false);
0852     SaveCanvas(c1,output,"MPVsSubDetAndStat");
0853     delete c1;
0854 
0855 
0856 
0857     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0858     MPVsTOB->GetXaxis()->SetNdivisions(5+500);
0859     Histos[0] = MPVsTECP1;                          legend.push_back("TEC+ (320 #mum)");
0860     Histos[1] = MPVsTECP2;                          legend.push_back("TEC+ (500 #mum)");
0861     Histos[2] = MPVsTECM1;                          legend.push_back("TEC- (320 #mum)");
0862     Histos[3] = MPVsTECM2;                          legend.push_back("TEC- (500 #mum)");
0863     DrawSuperposedHistos((TH1**)Histos, legend, "",  "MPV [ADC/mm]", "Number of APVs", 100,550, 0,0);
0864     DrawLegend(Histos,legend,"","L");
0865     DrawStatBox(Histos,legend,true);
0866     DrawPreliminary(TextToPrint);
0867     SaveCanvas(c1,output,"MPVsTEC");
0868     c1->SetLogy(true);
0869     SaveCanvas(c1,output,"MPVsTECLog");
0870     delete c1;
0871 
0872 
0873     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0874     Histos[0] = MPVError;                          legend.push_back("MPV Error");
0875     DrawSuperposedHistos((TH1**)Histos, legend, "",  "Error on MPV [ADC/mm]", "Number of APVs", 0,500, 0,0);
0876     DrawStatBox(Histos,legend,true);
0877     c1->SetLogy(true);
0878     c1->SetLogx(true);
0879     DrawPreliminary(TextToPrint);
0880     SaveCanvas(c1,output,"Error");
0881     delete c1;
0882 
0883     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0884     Histos[0] = MPVErrorVsMPV;                     legend.push_back("Error Vs MPV");
0885     DrawTH2D((TH2D**)Histos,legend, "COLZ", "MPV [ADC/mm]", "Error on MPV [ADC/mm]", 0,0, 0,0);
0886     c1->SetLogy(false);
0887     c1->SetLogz();
0888     DrawPreliminary(TextToPrint);
0889     SaveCanvas(c1,output,"Error_Vs_MPV", true);
0890     delete c1;
0891 
0892     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0893     Histos[0] = MPVErrorVsEta;                     legend.push_back("Error Vs Eta");
0894     DrawTH2D((TH2D**)Histos,legend, "COLZ", "module #eta", "Error on MPV [ADC/mm]", 0,0, 0,0);
0895     c1->SetLogy(false);
0896     c1->SetLogz();
0897     DrawPreliminary(TextToPrint);
0898     SaveCanvas(c1,output,"Error_Vs_Eta", true);
0899     delete c1;
0900 
0901     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0902     Histos[0] = MPVErrorVsPhi;                     legend.push_back("Error Vs Phi");
0903     DrawTH2D((TH2D**)Histos,legend, "COLZ", "module #phi", "Error on MPV [ADC/mm]", 0,0, 0,0);
0904     c1->SetLogy(false);
0905     c1->SetLogz();
0906     DrawPreliminary(TextToPrint);
0907     SaveCanvas(c1,output,"Error_Vs_Phi", true);
0908     delete c1;
0909 
0910     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0911     Histos[0] = MPVErrorVsN;                       legend.push_back("Error Vs Entries");
0912     DrawTH2D((TH2D**)Histos,legend, "COLZ", "Number of Entries", "Error on MPV [ADC/mm]", 0,0, 0,0);
0913     c1->SetLogx(true);
0914     c1->SetLogy(true);
0915     c1->SetLogz(true);
0916     DrawPreliminary(TextToPrint);
0917     SaveCanvas(c1,output,"Error_Vs_N", true);
0918     delete c1;
0919 
0920 
0921     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0922     Histos[0] = ChargePIB;                         legend.push_back("PIB");
0923     Histos[1] = ChargePIE;                         legend.push_back("PIE");
0924     DrawSuperposedHistos((TH1**)Histos, legend, "",  "Charge [ADC/mm]", "Number of Clusters", 0,800 , 0,0);
0925     DrawLegend(Histos,legend,"","L");
0926     DrawPreliminary(TextToPrint);
0927     TLine* l0p = new TLine(300, 0,300,((TH1*)Histos[0])->GetMaximum()); l0p->SetLineWidth(3); l0p->SetLineStyle(2); l0p->Draw("same");
0928     SaveCanvas(c1,output,"Charge");
0929     DrawStatBox(Histos,legend,true, 0.6, 0.7);
0930     SaveCanvas(c1,output,"PixelChargeAndStat");
0931     delete c1;
0932 
0933 
0934     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0935     Histos[0] = ChargeTEC;                         legend.push_back("TEC");
0936     Histos[1] = ChargeTIB;                         legend.push_back("TIB");
0937     Histos[2] = ChargeTID;                         legend.push_back("TID");
0938     Histos[3] = ChargeTOB;                         legend.push_back("TOB");
0939     DrawSuperposedHistos((TH1**)Histos, legend, "",  "Charge [ADC/mm]", "Number of Clusters", 0,800 , 0,0);
0940     DrawLegend(Histos,legend,"","L");
0941     DrawPreliminary(TextToPrint);
0942     TLine* l0 = new TLine(300, 0,300,((TH1*)Histos[0])->GetMaximum()); l0->SetLineWidth(3); l0->SetLineStyle(2); l0->Draw("same");
0943     SaveCanvas(c1,output,"Charge");
0944     DrawStatBox(Histos,legend,true, 0.6, 0.7);
0945     SaveCanvas(c1,output,"ChargeAndStat");
0946     delete c1;
0947 
0948     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0949     Histos[0] = ChargeTECP;                        legend.push_back("TEC+");
0950     Histos[1] = ChargeTECM;                        legend.push_back("TEC-");
0951     DrawSuperposedHistos((TH1**)Histos, legend, "",  "Charge [ADC/mm]", "Number of Clusters", 0,800 , 0,0);
0952     DrawLegend(Histos,legend,"","L");
0953     DrawStatBox(Histos,legend,true, 0.6, 0.7);
0954     DrawPreliminary(TextToPrint);
0955     SaveCanvas(c1,output,"ChargeTECSide");
0956     delete c1;
0957 
0958     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0959     Histos[0] = ChargeTEC1;                        legend.push_back("TEC Thin");
0960     Histos[1] = ChargeTEC2;                        legend.push_back("TEC Thick");
0961     DrawSuperposedHistos((TH1**)Histos, legend, "",  "Charge [ADC/mm]", "Number of Clusters", 0,800 , 0,0);
0962     DrawLegend(Histos,legend,"","L");
0963     DrawStatBox(Histos,legend,true, 0.6, 0.7);
0964     DrawPreliminary(TextToPrint);
0965     SaveCanvas(c1,output,"ChargeTECThickness");
0966     delete c1;
0967 
0968     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0969     Histos[0] = ChargeTIDP;                        legend.push_back("TID+");
0970     Histos[1] = ChargeTIDM;                        legend.push_back("TID-");
0971     DrawSuperposedHistos((TH1**)Histos, legend, "",  "Charge [ADC/mm]", "Number of Clusters", 0,800 , 0,0);
0972     DrawLegend(Histos,legend,"","L");
0973     DrawStatBox(Histos,legend,true, 0.6, 0.7);
0974     DrawPreliminary(TextToPrint);
0975     SaveCanvas(c1,output,"ChargeTIDSide");
0976     delete c1;
0977 /*
0978     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0979     Histos[0] = ChargeAbsPIB;                      legend.push_back("PIB");
0980     Histos[1] = ChargeAbsPIE;                      legend.push_back("PIE");
0981     DrawSuperposedHistos((TH1**)Histos, legend, "",  "Charge [ADC]", "Number of Clusters", 0,800 , 0,0);
0982     DrawLegend(Histos,legend,"","L");
0983     DrawStatBox(Histos,legend,true, 0.6, 0.7);
0984     DrawPreliminary(TextToPrint);
0985     SaveCanvas(c1,output,"PixelChargeAbs");
0986     delete c1;
0987 
0988     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0989     Histos[0] = ChargeAbsTEC;                      legend.push_back("TEC");
0990     Histos[1] = ChargeAbsTIB;                      legend.push_back("TIB");
0991     Histos[2] = ChargeAbsTID;                      legend.push_back("TID");
0992     Histos[3] = ChargeAbsTOB;                      legend.push_back("TOB");
0993     DrawSuperposedHistos((TH1**)Histos, legend, "",  "Charge [ADC]", "Number of Clusters", 0,800 , 0,0);
0994     DrawLegend(Histos,legend,"","L");
0995     DrawStatBox(Histos,legend,true, 0.6, 0.7);
0996     DrawPreliminary(TextToPrint);
0997     SaveCanvas(c1,output,"ChargeAbs");
0998     delete c1;
0999 
1000     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
1001     Histos[0] = ChargeAbsTECP;                     legend.push_back("TEC+");
1002     Histos[1] = ChargeAbsTECM;                     legend.push_back("TEC-");
1003     DrawSuperposedHistos((TH1**)Histos, legend, "",  "Charge [ADC]", "Number of Clusters", 0,800 , 0,0);
1004     DrawLegend(Histos,legend,"","L");
1005     DrawStatBox(Histos,legend,true, 0.6, 0.7);
1006     DrawPreliminary(TextToPrint);
1007     SaveCanvas(c1,output,"ChargeAbsTECSide");
1008     delete c1;
1009 
1010     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
1011     Histos[0] = ChargeAbsTEC1;                     legend.push_back("TEC Thin");
1012     Histos[1] = ChargeAbsTEC2;                     legend.push_back("TEC Thick");
1013     DrawSuperposedHistos((TH1**)Histos, legend, "",  "Charge [ADC]", "Number of Clusters", 0,800 , 0,0);
1014     DrawLegend(Histos,legend,"","L");
1015     DrawStatBox(Histos,legend,true, 0.6, 0.7);
1016     DrawPreliminary(TextToPrint);
1017     SaveCanvas(c1,output,"ChargeAbsTECThickness");
1018     delete c1;
1019 
1020     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
1021     Histos[0] = ChargeAbsTIDP;                     legend.push_back("TID+");
1022     Histos[1] = ChargeAbsTIDM;                     legend.push_back("TID-");
1023     DrawSuperposedHistos((TH1**)Histos, legend, "",  "Charge [ADC]", "Number of Clusters", 0,800 , 0,0);
1024     DrawLegend(Histos,legend,"","L");
1025     DrawStatBox(Histos,legend,true, 0.6, 0.7);
1026     DrawPreliminary(TextToPrint);
1027     SaveCanvas(c1,output,"ChargeAbsTIDSide");
1028     delete c1;
1029 */
1030 
1031     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
1032     Histos[0] = MPV_Vs_PathlengthThin;             legend.push_back("320 #mum");
1033     Histos[1] = MPV_Vs_PathlengthThick;            legend.push_back("500 #mum");
1034     DrawSuperposedHistos((TH1**)Histos, legend, "HIST",  "pathlength [mm]", "MPV [ADC/mm]", 0,0 , 230,380);
1035     DrawLegend(Histos,legend,"","L");
1036     DrawPreliminary(TextToPrint);
1037     SaveCanvas(c1,output,"MPV_Vs_Path");
1038     delete c1;
1039 
1040 
1041     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
1042     Histos[0] = MPV_Vs_PathlengthTIB;              legend.push_back("TIB (320 #mum)");
1043     Histos[1] = MPV_Vs_PathlengthTID;              legend.push_back("TID (320 #mum)");
1044     Histos[2] = MPV_Vs_PathlengthTOB;              legend.push_back("TOB (500 #mum)");
1045     Histos[3] = MPV_Vs_PathlengthTEC1;             legend.push_back("TEC (320 #mum)");
1046     Histos[4] = MPV_Vs_PathlengthTEC2;             legend.push_back("TEC (500 #mum)");
1047     DrawSuperposedHistos((TH1**)Histos, legend, "HIST",  "pathlength [mm]", "MPV [ADC/mm]", 0,0 , 230,380);
1048     DrawLegend(Histos,legend,"","L");
1049     DrawPreliminary(TextToPrint);
1050     SaveCanvas(c1,output,"MPV_Vs_PathSubDet");
1051     delete c1;
1052 
1053 
1054     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
1055     Histos[0] = DiffWRTPrevGainPIB;                legend.push_back("PIB");
1056     Histos[1] = DiffWRTPrevGainPIE;                legend.push_back("PIE");
1057     DrawSuperposedHistos((TH1**)Histos, legend, "HIST",  "New Gain / Previous Gain", "Number of APV", 0.0,2.0 ,0,0);
1058     DrawLegend(Histos,legend,"","L");
1059     c1->SetLogy(true);
1060     DrawStatBox(Histos,legend,true, 0.6, 0.7);
1061     DrawPreliminary(TextToPrint);
1062     SaveCanvas(c1,output,"PixelGainDividedPrevGain");
1063     delete c1;
1064 
1065 
1066     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
1067     Histos[0] = DiffWRTPrevGainTIB;                legend.push_back("TIB");
1068     Histos[1] = DiffWRTPrevGainTID;                legend.push_back("TID");
1069     Histos[2] = DiffWRTPrevGainTOB;                legend.push_back("TOB");
1070     Histos[3] = DiffWRTPrevGainTEC;                legend.push_back("TEC");
1071     DrawSuperposedHistos((TH1**)Histos, legend, "HIST",  "New Gain / Previous Gain", "Number of APV", 0.0,2.0 ,0,0);
1072     DrawLegend(Histos,legend,"","L");
1073     c1->SetLogy(true);
1074     DrawStatBox(Histos,legend,true, 0.6, 0.7);
1075     DrawPreliminary(TextToPrint);
1076     SaveCanvas(c1,output,"GainDividedPrevGain");
1077     delete c1;
1078 
1079 
1080    c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
1081    Histos[0] = GainVsPrevGainPIB;                 legend.push_back("PIB");
1082    Histos[1] = GainVsPrevGainPIE;                 legend.push_back("PIE");
1083    DrawTH2D((TH2D**)Histos,legend, "", "Previous Gain", "New Gain", 0.5,1.8, 0.5,1.8);
1084    TLine diagonalP(0.5,0.5,1.8,1.8);
1085    diagonalP.SetLineWidth(3);
1086    diagonalP.SetLineStyle(2);
1087    diagonalP.Draw("same");
1088    DrawLegend (Histos,legend,"","P");
1089    DrawStatBox(Histos,legend,false);
1090    DrawPreliminary(TextToPrint);
1091    SaveCanvas(c1,output,"PixelGainVsPrevGain");
1092    delete c1;
1093 
1094 
1095    c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
1096    Histos[0] = GainVsPrevGainTEC;                 legend.push_back("TEC");
1097    Histos[1] = GainVsPrevGainTIB;                 legend.push_back("TIB");
1098    Histos[2] = GainVsPrevGainTID;                 legend.push_back("TID");
1099    Histos[3] = GainVsPrevGainTOB;                 legend.push_back("TOB");
1100    DrawTH2D((TH2D**)Histos,legend, "", "Previous Gain", "New Gain", 0.5,1.8, 0.5,1.8);
1101    TLine diagonal(0.5,0.5,1.8,1.8);
1102    diagonal.SetLineWidth(3);
1103    diagonal.SetLineStyle(2);
1104    diagonal.Draw("same");
1105    DrawLegend (Histos,legend,"","P");
1106    DrawStatBox(Histos,legend,false);
1107    DrawPreliminary(TextToPrint);
1108    SaveCanvas(c1,output,"GainVsPrevGain");
1109    delete c1;
1110 
1111 
1112 }
1113 
1114 TF1* getLandau(TH1* InputHisto, double* FitResults, double LowRange, double HighRange)
1115 {
1116    FitResults[0]         = -0.5;  //MPV
1117    FitResults[1]         =  0;    //MPV error
1118    FitResults[2]         = -0.5;  //Width
1119    FitResults[3]         =  0;    //Width error
1120    FitResults[4]         = -0.5;  //Fit Chi2/NDF
1121 
1122    // perform fit with standard landau
1123    TF1* MyLandau = new TF1("MyLandau","landau",LowRange, HighRange);
1124    MyLandau->SetParameter(1,300);
1125    InputHisto->Fit("MyLandau","0QR WW");
1126 
1127    // MPV is parameter 1 (0=constant, 1=MPV, 2=Sigma)
1128    FitResults[0]         = MyLandau->GetParameter(1);  //MPV
1129    FitResults[1]         = MyLandau->GetParError(1);   //MPV error
1130    FitResults[2]         = MyLandau->GetParameter(2);  //Width
1131    FitResults[3]         = MyLandau->GetParError(2);   //Width error
1132    FitResults[4]         = MyLandau->GetChisquare() / MyLandau->GetNDF();  //Fit Chi2/NDF
1133 
1134    return MyLandau;
1135 }
1136 
1137 TH1D* ChargeToMPV(TH2* InputHisto, std::string Name,  bool DivideByX)
1138 {
1139    TH1D* toReturn = new TH1D(Name.c_str(),Name.c_str(),InputHisto->GetXaxis()->GetNbins(), InputHisto->GetXaxis()->GetXmin(), InputHisto->GetXaxis()->GetXmax() );
1140    double Results[5];
1141 
1142    for(int i=0;i<=InputHisto->GetXaxis()->GetNbins();i++){
1143       TH1D* proj   = InputHisto->ProjectionY("",i,i);
1144       if(proj->GetEntries()<50){delete proj;continue;}
1145 
1146       TF1*  landau = getLandau(proj,Results);
1147 
1148       if(DivideByX){
1149          toReturn->SetBinContent(i,Results[0] / InputHisto->GetXaxis()->GetBinCenter(i) );
1150          toReturn->SetBinError  (i,Results[1] / InputHisto->GetXaxis()->GetBinCenter(i) );
1151       }else{
1152          toReturn->SetBinContent(i,Results[0]);
1153          toReturn->SetBinError  (i,Results[1]);
1154       }
1155       delete landau;
1156      delete proj;
1157    }
1158 
1159    return toReturn;
1160 }
1161