Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:59:45

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 "TGraphErrors.h"
0011 #include "TH1.h"
0012 #include "TH2.h"
0013 #include "TH3.h"
0014 #include "TTree.h"
0015 #include "TF1.h"
0016 #include "TPaveText.h"
0017 #include "PlotFunction.h"
0018 
0019 #include "DataFormats/SiStripDetId/interface/SiStripDetId.h"
0020 #include "CalibTracker/StandaloneTrackerTopology/interface/StandaloneTrackerTopology.h"
0021 
0022 // IMPORTANT: to run this macro, first load the required library
0023 // with the following line, inside ROOT:
0024 // gSystem->Load("libCalibTrackerStandaloneTrackerTopology.so")
0025 
0026 
0027 TrackerTopology tTopo = StandaloneTrackerTopology::fromTrackerParametersXMLFile(std::string(gSystem->Getenv("CMSSW_RELEASE_BASE"))+"/src/Geometry/TrackerCommonData/data/trackerParameters.xml");
0028 
0029 #include<vector>
0030 #include"tdrstyle.C"
0031 
0032 std::map<unsigned int, double> RunToIntLumi;
0033 
0034 bool LoadLumiToRun();
0035 double getLumiFromRun(unsigned int run);
0036 
0037 struct stLayerData{
0038    std::map<unsigned int, double      > LayerGain;
0039    std::map<unsigned int, double      > LayerGainErr;
0040    std::map<unsigned int, unsigned int> LayerN;
0041    std::map<unsigned int, string      > LayerName;
0042 };
0043 
0044 void PlotMacro_Core(string input, string moduleName, string output);
0045 TF1*  getLandau(TH1* InputHisto, double* FitResults, double LowRange=50, double HighRange=5400);
0046 TH1D* ChargeToMPV(TH2* InputHisto, string Name, bool DivideByX);
0047 
0048 void GetAverageGain(string input, string moduleName, stLayerData& layerData );
0049 
0050 
0051 int DataType = 2;
0052 
0053 void PlotMacro(){
0054    gROOT->Reset();
0055    setTDRStyle();
0056    gStyle->SetPadTopMargin   (0.05);
0057    gStyle->SetPadBottomMargin(0.10);
0058    gStyle->SetPadRightMargin (0.18);
0059    gStyle->SetPadLeftMargin  (0.13);
0060    gStyle->SetTitleSize(0.04, "XYZ");
0061    gStyle->SetTitleXOffset(1.1);
0062    gStyle->SetTitleYOffset(1.35);
0063    gStyle->SetPalette(1);
0064    gStyle->SetCanvasColor(0);
0065    gStyle->SetBarOffset(0);
0066 
0067    std::vector<std::pair<unsigned int, unsigned int> > runRanges;
0068 //   //RUN1
0069 //   runRanges.push_back(std::make_pair(190645,191271));
0070 //   runRanges.push_back(std::make_pair(193093,194108));
0071 //   runRanges.push_back(std::make_pair(194115,194428));
0072 //   runRanges.push_back(std::make_pair(194429,194790));
0073 //   runRanges.push_back(std::make_pair(194825,195530));
0074 //   runRanges.push_back(std::make_pair(195540,195868));
0075 //   runRanges.push_back(std::make_pair(195915,199021));
0076 //   runRanges.push_back(std::make_pair(199318,199868));
0077 //   runRanges.push_back(std::make_pair(200042,200601));
0078 //   runRanges.push_back(std::make_pair(200961,201229));
0079 //   runRanges.push_back(std::make_pair(201278,202084));
0080 //   runRanges.push_back(std::make_pair(202093,203742));
0081 //   runRanges.push_back(std::make_pair(203777,204576));
0082 //   runRanges.push_back(std::make_pair(204577,205238));
0083 //   runRanges.push_back(std::make_pair(205303,205666));
0084 //   runRanges.push_back(std::make_pair(205667,206199));
0085 //   runRanges.push_back(std::make_pair(206257,206940));
0086 //   runRanges.push_back(std::make_pair(207214,207883));
0087 
0088 //   //RUN2
0089    runRanges.push_back(std::make_pair(247252,247988));
0090    runRanges.push_back(std::make_pair(247989,247990));
0091    runRanges.push_back(std::make_pair(247992,247992));
0092    runRanges.push_back(std::make_pair(248003,248025));
0093    runRanges.push_back(std::make_pair(248028,250927));
0094    runRanges.push_back(std::make_pair(251168,251168));
0095    runRanges.push_back(std::make_pair(251244,251244));
0096    runRanges.push_back(std::make_pair(251251,251251));
0097    runRanges.push_back(std::make_pair(251252,251252));
0098    runRanges.push_back(std::make_pair(251328,251612));
0099    runRanges.push_back(std::make_pair(251638,251721));
0100 
0101    std::vector<stLayerData> resultVec;
0102 
0103    system("mkdir Pictures");
0104    for(unsigned int i=0;i<runRanges.size();i++){
0105       stLayerData result;
0106 
0107       char filePath[256]; sprintf(filePath, "../../Data_Run_%06i_to_%06i_PCL/Gains_Tree.root", runRanges[i].first, runRanges[i].second);
0108       GetAverageGain(filePath, "SiStripCalib/", result);
0109       resultVec.push_back(result);
0110    }  
0111 
0112    LoadLumiToRun();
0113 
0114    std::map<string, TGraph*> graphMap;
0115    printf("%10s --> ", "Run Min");for(unsigned int i=0;i<runRanges.size();i++){printf("%06i " , runRanges[i].first );}printf("\n");
0116    printf("%10s --> ", "Run Max");for(unsigned int i=0;i<runRanges.size();i++){printf("%06i " , runRanges[i].second);}printf("\n");
0117    printf("%10s --> ", "LumiMin");for(unsigned int i=0;i<runRanges.size();i++){printf("%6.2f ", getLumiFromRun(runRanges[i].first) );}printf("\n");
0118    printf("%10s --> ", "LumiMax");for(unsigned int i=0;i<runRanges.size();i++){printf("%6.2f ", getLumiFromRun(runRanges[i].second) );}printf("\n");
0119    printf("%10s     ", "-------");for(unsigned int i=0;i<runRanges.size();i++){printf("%06s-" , "------"           );}printf("\n");
0120    for(std::map<unsigned int, string>::iterator it=resultVec[0].LayerName.begin(); it!=resultVec[0].LayerName.end();it++){
0121       TGraphErrors* graph = new TGraphErrors(runRanges.size());
0122  
0123       printf("%10s --> ", it->second.c_str());
0124       for(unsigned int i=0;i<runRanges.size();i++){
0125          graph->SetPoint     (i, getLumiFromRun(runRanges[i].first) + (getLumiFromRun(runRanges[i].second)-getLumiFromRun(runRanges[i].first))/2.0 , resultVec[i].LayerGain[it->first]);
0126          graph->SetPointError(i,                                      0.0, 0.0);//resultVec[i].LayerGainErr[it->first] / resultVec[0].LayerGain[it->first]);
0127 
0128 //         graph->SetPoint     (i, getLumiFromRun(runRanges[i].first) + (getLumiFromRun(runRanges[i].second)-getLumiFromRun(runRanges[i].first))/2.0 , resultVec[i].LayerGain[it->first] / resultVec[0].LayerGain[it->first]);
0129 //         graph->SetPointError(i,                                      (getLumiFromRun(runRanges[i].second)-getLumiFromRun(runRanges[i].first))/2.0 , 0.0);//resultVec[i].LayerGainErr[it->first] / resultVec[0].LayerGain[it->first]);
0130          printf("%6.2f ", resultVec[i].LayerGain[it->first]);
0131 //         printf("%6.2f+-%5.2f ", resultVec[i].LayerGain[it->first], resultVec[i].LayerGainErr[it->first]);
0132       }printf("\n");
0133       graphMap[it->second.c_str()] = graph;
0134    }
0135 
0136 
0137    TCanvas* c1 = new TCanvas("c1","c1,",900,600);
0138 
0139    TH1D* frame = new TH1D("frame", "frame", 1,getLumiFromRun(runRanges[0].first)-20,getLumiFromRun(runRanges[runRanges.size()-1].second)+20);
0140    frame->GetXaxis()->SetNdivisions(505);
0141    frame->SetTitle("");
0142    frame->SetStats(kFALSE);
0143 //   frame->GetXaxis()->SetTitle("Integrated Lumi (fb^{-1})");
0144      frame->GetXaxis()->SetTitle("Run Number");
0145 //   frame->GetYaxis()->SetTitle("Average Gain");
0146 //   frame->SetMaximum(1.25);
0147 //   frame->SetMinimum(0.80);
0148    frame->GetYaxis()->SetTitle("Average Gain");
0149    frame->SetMaximum(1.10);
0150    frame->SetMinimum(0.85);
0151    frame->GetYaxis()->SetTitleOffset(1.50);
0152 
0153    TLegend* leg = new TLegend(0.15,0.93,0.80, 0.75);
0154    leg->SetFillStyle(0);
0155    leg->SetBorderSize(0);
0156    leg->SetTextFont(43);
0157    leg->SetTextSize(20);
0158    leg->SetNColumns(4);
0159    int colorTIBTOB[]={kBlue, kBlue+1, kBlue+2, kBlue+3,  kRed-10, kRed-8, kRed-6, kRed-4, kRed-2, kRed};
0160    int colorTIDTEC[]={kRed-10, kRed-9, kRed-8, kRed-7, kRed-6, kRed-5, kRed-4, kRed-3, kRed-2, kBlue, kBlue+1, kBlue+2};
0161    int colorTIDTECr[]={kRed-10, kRed-9, kRed-8, kRed-7, kRed-6, kRed-4, kRed-2, kBlue, kBlue+1, kBlue+2};
0162    int L;
0163 
0164 
0165    L=0;
0166    frame->Draw("AXIS");
0167    leg->Clear();
0168    for(std::map<string, TGraph*>::iterator it=graphMap.begin(); it!=graphMap.end();it++){
0169       if(it->first.find("lTIB")==string::npos && it->first.find("lTOB")==string::npos)continue;
0170       it->second->SetLineColor(colorTIBTOB[L]);
0171       it->second->SetLineWidth(2);
0172       it->second->Draw("same L*");
0173       leg->AddEntry(it->second, it->first.c_str() ,"L");
0174       L++;
0175    }
0176    leg->Draw();
0177    c1->SaveAs("Pictures/TIBTOB.png");
0178    c1->SaveAs("Pictures/TIBTOB.C");
0179 
0180 
0181    L=0;
0182    frame->Draw("AXIS");
0183    leg->Clear();
0184    for(std::map<string, TGraph*>::iterator it=graphMap.begin(); it!=graphMap.end();it++){
0185       if(it->first.find("wTID+")==string::npos && it->first.find("wTEC+")==string::npos)continue;
0186       it->second->SetLineColor(colorTIDTEC[L]);
0187       it->second->SetLineWidth(2);
0188       it->second->Draw("same L*");
0189       leg->AddEntry(it->second, it->first.c_str() ,"L");
0190       L++;
0191    }
0192    leg->Draw();
0193    c1->SaveAs("Pictures/WheelTIDTECp.png");
0194    c1->SaveAs("Pictures/WheelTIDTECp.C");
0195 
0196    L=0;
0197    frame->Draw("AXIS");
0198    leg->Clear();
0199    for(std::map<string, TGraph*>::iterator it=graphMap.begin(); it!=graphMap.end();it++){
0200       if(it->first.find("wTID-")==string::npos && it->first.find("wTEC-")==string::npos)continue;
0201       it->second->SetLineColor(colorTIDTEC[L]);
0202       it->second->SetLineWidth(2);
0203       it->second->Draw("same L*");
0204       leg->AddEntry(it->second, it->first.c_str() ,"L");
0205       L++;
0206    }
0207    leg->Draw();
0208    c1->SaveAs("Pictures/WheelTIDTECm.png");
0209    c1->SaveAs("Pictures/WheelTIDTECm.C");
0210 
0211 
0212    L=0;
0213    frame->Draw("AXIS");
0214    leg->Clear();
0215    for(std::map<string, TGraph*>::iterator it=graphMap.begin(); it!=graphMap.end();it++){
0216       if(it->first.find("rTID+")==string::npos && it->first.find("rTEC+")==string::npos)continue;
0217       it->second->SetLineColor(colorTIDTECr[L]);
0218       it->second->SetLineWidth(2);
0219       it->second->Draw("same L*");
0220       leg->AddEntry(it->second, it->first.c_str() ,"L");
0221       L++;
0222    }
0223    leg->Draw();
0224    c1->SaveAs("Pictures/RingTIDTECp.png");
0225    c1->SaveAs("Pictures/RingTIDTECp.C");
0226  
0227    L=0;
0228    frame->Draw("AXIS"); 
0229    leg->Clear(); 
0230    for(std::map<string, TGraph*>::iterator it=graphMap.begin(); it!=graphMap.end();it++){
0231       if(it->first.find("rTID-")==string::npos && it->first.find("rTEC-")==string::npos)continue;
0232       it->second->SetLineColor(colorTIDTECr[L]);
0233       it->second->SetLineWidth(2);
0234       it->second->Draw("same L*");
0235       leg->AddEntry(it->second, it->first.c_str() ,"L");
0236       L++;
0237    }
0238    leg->Draw();
0239    c1->SaveAs("Pictures/RingTIDTECm.png");
0240    c1->SaveAs("Pictures/RingTIDTECm.C");
0241 
0242 
0243 
0244    TFile* f1     = new TFile("clusternoise_ontrack_tob_l1.root");
0245    if(!f1 || f1->IsZombie() || !f1->IsOpen() || f1->TestBit(TFile::kRecovered)){
0246       printf("clusternoise file not found\nStop the execution of the code here\n");
0247       return;
0248    }
0249    TH1D* noiseH     = (TH1D*)GetObjectFromPath(f1,"clusternoise_ontrack_tob_l1");
0250    TH1D* noiseHnew  = (TH1D*)noiseH->Clone("noiseHnew");
0251 
0252    TGraph* noiseG    = new TGraph(noiseH->GetXaxis()->GetNbins()-1);
0253    TGraph* noiseGnew = new TGraph(noiseH->GetXaxis()->GetNbins()-1);
0254 
0255    unsigned int CurrRunRange =0;
0256    for(int b=1;b<noiseH->GetXaxis()->GetNbins();b++){
0257       unsigned int run; sscanf( noiseH->GetXaxis()->GetBinLabel(b), "%d", &run);
0258       double noise = noiseH->GetBinContent(b);     
0259 
0260 //      //find current RunRange
0261 //      for(unsigned int i=0;i<runRanges.size()-1;i++){
0262 //         if(runRanges[i].first<run)CurrRunRange = i;
0263 //      }
0264 
0265      if(run<206880)CurrRunRange=15;
0266      if(run<206037)CurrRunRange=13;
0267      if(run<202914)CurrRunRange=10;
0268      if(run<201820)CurrRunRange=7;
0269      if(run<199878)CurrRunRange=5;  //or 6?
0270      if(run<198301)CurrRunRange=3;  //or 4?
0271      if(run<194552)CurrRunRange=1;  //or 1?
0272      if(run<192701)CurrRunRange=0;
0273 
0274 
0275    //Mapping
0276 //   unsigned int runs[] = {192701, 194552, 198301, 199878, 201820, 202914, 206037, 206880};
0277 //   runRanges.push_back(std::make_pair(190645,191271)); 0
0278 //   runRanges.push_back(std::make_pair(193093,194108)); 1
0279 //   runRanges.push_back(std::make_pair(194115,194428)); 2
0280 //   runRanges.push_back(std::make_pair(194429,194790)); 3
0281 //   runRanges.push_back(std::make_pair(194825,195530)); 4
0282 //   runRanges.push_back(std::make_pair(195540,195868)); 5
0283 //   runRanges.push_back(std::make_pair(195915,199021)); 6
0284 //   runRanges.push_back(std::make_pair(199318,199868)); 7
0285 //   runRanges.push_back(std::make_pair(200042,200601)); 8
0286 //   runRanges.push_back(std::make_pair(200961,201229)); 9
0287 //   runRanges.push_back(std::make_pair(201278,202084)); 10
0288 //   runRanges.push_back(std::make_pair(202093,203742)); 11
0289 //   runRanges.push_back(std::make_pair(203777,204576)); 12
0290 //   runRanges.push_back(std::make_pair(204577,205238)); 13
0291 //   runRanges.push_back(std::make_pair(205303,205666)); 14
0292 //   runRanges.push_back(std::make_pair(205667,206199)); 15
0293 //   runRanges.push_back(std::make_pair(206257,206940)); 16
0294 //   runRanges.push_back(std::make_pair(207214,207883)); 17
0295 
0296 
0297 
0298 
0299      stLayerData gainInfo = resultVec[CurrRunRange];
0300      double lTOB1Gain = gainInfo.LayerGain[5001];
0301      noiseHnew->SetBinContent(b,noise*lTOB1Gain);
0302 
0303      noiseG   ->SetPoint(b-1, run, noise);
0304      noiseGnew->SetPoint(b-1, run, noise*lTOB1Gain);
0305 
0306      //printf("%6i : %6.3f --> %6.3f\n",run, noise, noise*lTOB1Gain);
0307    }
0308 
0309 
0310    frame = new TH1D("frame", "frame", 1,190645, 208686);
0311    frame->GetXaxis()->SetNdivisions(510);
0312    frame->SetTitle("");
0313    frame->SetStats(kFALSE);
0314    frame->GetXaxis()->SetTitle("Run");
0315 //   frame->GetYaxis()->SetTitle("Average Gain"); 
0316 //   frame->SetMaximum(1.25);
0317 //   frame->SetMinimum(0.80);
0318    frame->GetYaxis()->SetTitle("TOB1 Noise (on track)");
0319    frame->SetMaximum(7);
0320    frame->SetMinimum(6);
0321    frame->GetYaxis()->SetTitleOffset(1.50);
0322    frame->Draw("AXIS");
0323 
0324 //   noiseG->Draw("A");
0325    noiseG->Draw("P");
0326    noiseGnew->SetMarkerColor(4);
0327    noiseGnew->Draw("P");
0328 //   noiseHnew->SetLineColor(4);
0329 //   noiseHnew->Draw("HIST same");
0330 
0331 
0332 
0333    unsigned int runs[] = {192701, 194552, 198301, 199878, 201820, 202914, 206037, 206880};
0334    for(unsigned int i=0;i<sizeof(runs)/sizeof(unsigned int);i++){
0335       //find the closest processed run
0336 //      int closestRun = 0;
0337 //      for(std::map<unsigned int, double>::iterator it = RunToIntLumi.begin(); it!=RunToIntLumi.end();it++){
0338 //         if(it->first>runs[i] && abs(it->first-runs[i])<abs(closestRun-runs[i]))closestRun = it->first;
0339 //      }
0340 //      printf("Draw line for run %i at %f\n",closestRun, RunToIntLumi[closestRun]);
0341 
0342       TLine* line = NULL;
0343 //      line = new TLine( RunToIntLumi[closestRun], ymin, RunToIntLumi[closestRun], ymax);
0344       line = new TLine( runs[i], 6, runs[i], 7);
0345       line->SetLineColor(1);
0346       line->SetLineWidth(2);
0347       line->SetLineStyle(2);
0348       line->Draw("same");
0349    }
0350 
0351 
0352 
0353    c1->SaveAs("Pictures/noise_tob_l1.png");   
0354 
0355 
0356 
0357 }
0358 
0359 
0360 
0361 void GetAverageGain(string input, string moduleName, stLayerData& layerData )
0362 {
0363    FILE* pFile;
0364    TCanvas* c1;
0365    TObject** Histos = new TObject*[10];                
0366    std::vector<string> legend;
0367 
0368    unsigned int  tree_Index;
0369    unsigned int  tree_DetId;
0370    unsigned char tree_APVId;
0371    unsigned char tree_SubDet;
0372    float         tree_x;
0373    float         tree_y;
0374    float         tree_z;
0375    float         tree_Eta;
0376    float         tree_R;
0377    float         tree_Phi;
0378    float         tree_Thickness;
0379    float         tree_FitMPV;
0380    float         tree_FitMPVErr;
0381    float         tree_FitWidth;
0382    float         tree_FitWidthErr;
0383    float         tree_FitChi2NDF;
0384    double        tree_Gain;
0385    double        tree_PrevGain;
0386    double        tree_NEntries;
0387    bool          tree_isMasked;
0388 
0389    TFile* f1     = new TFile(input.c_str());
0390    TTree *t1     = (TTree*)GetObjectFromPath(f1,moduleName+"APVGain");
0391 
0392    t1->SetBranchAddress("Index"             ,&tree_Index      );
0393    t1->SetBranchAddress("DetId"             ,&tree_DetId      );
0394    t1->SetBranchAddress("APVId"             ,&tree_APVId      );
0395    t1->SetBranchAddress("SubDet"            ,&tree_SubDet     );
0396    t1->SetBranchAddress("x"                 ,&tree_x          );
0397    t1->SetBranchAddress("y"                 ,&tree_y          );
0398    t1->SetBranchAddress("z"                 ,&tree_z          );
0399    t1->SetBranchAddress("Eta"               ,&tree_Eta        );
0400    t1->SetBranchAddress("R"                 ,&tree_R          );
0401    t1->SetBranchAddress("Phi"               ,&tree_Phi        );
0402    t1->SetBranchAddress("Thickness"         ,&tree_Thickness  );
0403    t1->SetBranchAddress("FitMPV"            ,&tree_FitMPV     );
0404    t1->SetBranchAddress("FitMPVErr"         ,&tree_FitMPVErr  );
0405    t1->SetBranchAddress("FitWidth"          ,&tree_FitWidth   );
0406    t1->SetBranchAddress("FitWidthErr"       ,&tree_FitWidthErr);
0407    t1->SetBranchAddress("FitChi2NDF"        ,&tree_FitChi2NDF );
0408    t1->SetBranchAddress("Gain"              ,&tree_Gain       );
0409    t1->SetBranchAddress("PrevGain"          ,&tree_PrevGain   );
0410    t1->SetBranchAddress("NEntries"          ,&tree_NEntries   );
0411    t1->SetBranchAddress("isMasked"          ,&tree_isMasked   );
0412 
0413    int TreeStep = t1->GetEntries()/50;if(TreeStep==0)TreeStep=1;
0414    for (unsigned int ientry = 0; ientry < t1->GetEntries(); ientry++) {
0415       t1->GetEntry(ientry);
0416       SiStripDetId SSdetId(tree_DetId);
0417 
0418       char LayerName[255];
0419 
0420       int LayerID=tree_SubDet*1000;      
0421       switch (tree_SubDet) {         
0422          case SiStripDetId::TIB:{
0423             LayerID += tTopo.tibLayer(tree_DetId);
0424             sprintf(LayerName,"lTIB%i",tTopo.tibLayer(tree_DetId));
0425          }break;
0426          case SiStripDetId::TID:{
0427             LayerID += tTopo.tidSide(tree_DetId)*100;
0428             LayerID += tTopo.tidRing(tree_DetId);
0429             sprintf(LayerName,"rTID%c%i",tTopo.tidSide(tree_DetId)==1?'-':'+', tTopo.tidRing(tree_DetId));
0430          }break;
0431          case SiStripDetId::TOB:{
0432             LayerID += tTopo.tobLayer(tree_DetId);
0433             sprintf(LayerName,"lTOB%i",tTopo.tobLayer(tree_DetId));
0434          }break;
0435          case SiStripDetId::TEC:{
0436             LayerID += tTopo.tecSide(tree_DetId)*100;
0437             LayerID += tTopo.tecRing(tree_DetId);
0438             sprintf(LayerName,"rTEC%c%i",tTopo.tecSide(tree_DetId)==1?'-':'+', tTopo.tecRing(tree_DetId));
0439          }break;
0440          default:
0441          break;
0442       }
0443       layerData.LayerGain[LayerID] += tree_Gain;
0444       layerData.LayerGainErr[LayerID] += tree_Gain*tree_Gain;
0445       layerData.LayerN   [LayerID] += 1;
0446       layerData.LayerName[LayerID]  = LayerName;
0447 
0448 
0449       LayerID=tree_SubDet*1000;
0450       switch (tree_SubDet) {
0451          case SiStripDetId::TID:{
0452             LayerID += (2+tTopo.tidSide(tree_DetId))*100;
0453             LayerID += tTopo.tidWheel(tree_DetId);
0454             sprintf(LayerName,"wTID%c%i",tTopo.tidSide(tree_DetId)==1?'-':'+', tTopo.tidWheel(tree_DetId));
0455          }break;
0456          case SiStripDetId::TEC:{
0457             LayerID += (2+tTopo.tecSide(tree_DetId))*100;
0458             LayerID += tTopo.tecWheel(tree_DetId);
0459             sprintf(LayerName,"wTEC%c%i",tTopo.tecSide(tree_DetId)==1?'-':'+', tTopo.tecWheel(tree_DetId));
0460          }break;
0461          default:
0462          break;
0463       }
0464       if(LayerID!=tree_SubDet*1000){
0465          layerData.LayerGain[LayerID] += tree_Gain;
0466          layerData.LayerGainErr[LayerID] += tree_Gain*tree_Gain;
0467          layerData.LayerN   [LayerID] += 1;
0468          layerData.LayerName[LayerID]  = LayerName;
0469       }
0470    }
0471 
0472    for(std::map<unsigned int, double>::iterator it=layerData.LayerGain.begin(); it!=layerData.LayerGain.end();it++){
0473       layerData.LayerGainErr[it->first] = sqrt((layerData.LayerGainErr[it->first] - (pow(layerData.LayerGain[it->first],2) / layerData.LayerN[it->first])) / (layerData.LayerN[it->first] - 1) );
0474       layerData.LayerGain[it->first] /= layerData.LayerN[it->first];
0475    }
0476 
0477 }
0478 
0479 
0480 
0481 
0482 void PlotMacro_Core(string input, string moduleName, string output)
0483 {
0484    FILE* pFile;
0485    TCanvas* c1;
0486    TObject** Histos = new TObject*[10];                
0487    std::vector<string> legend;
0488 
0489    unsigned int  tree_Index;
0490    unsigned int  tree_DetId;
0491    unsigned char tree_APVId;
0492    unsigned char tree_SubDet;
0493    float         tree_x;
0494    float         tree_y;
0495    float         tree_z;
0496    float         tree_Eta;
0497    float         tree_R;
0498    float         tree_Phi;
0499    float         tree_Thickness;
0500    float         tree_FitMPV;
0501    float         tree_FitMPVErr;
0502    float         tree_FitWidth;
0503    float         tree_FitWidthErr;
0504    float         tree_FitChi2NDF;
0505    double        tree_Gain;
0506    double        tree_PrevGain;
0507    double        tree_NEntries;
0508    bool          tree_isMasked;
0509 
0510    TFile* f1     = new TFile(input.c_str());
0511    TTree *t1     = (TTree*)GetObjectFromPath(f1,moduleName+"APVGain");
0512 
0513    t1->SetBranchAddress("Index"             ,&tree_Index      );
0514    t1->SetBranchAddress("DetId"             ,&tree_DetId      );
0515    t1->SetBranchAddress("APVId"             ,&tree_APVId      );
0516    t1->SetBranchAddress("SubDet"            ,&tree_SubDet     );
0517    t1->SetBranchAddress("x"                 ,&tree_x          );
0518    t1->SetBranchAddress("y"                 ,&tree_y          );
0519    t1->SetBranchAddress("z"                 ,&tree_z          );
0520    t1->SetBranchAddress("Eta"               ,&tree_Eta        );
0521    t1->SetBranchAddress("R"                 ,&tree_R          );
0522    t1->SetBranchAddress("Phi"               ,&tree_Phi        );
0523    t1->SetBranchAddress("Thickness"         ,&tree_Thickness  );
0524    t1->SetBranchAddress("FitMPV"            ,&tree_FitMPV     );
0525    t1->SetBranchAddress("FitMPVErr"         ,&tree_FitMPVErr  );
0526    t1->SetBranchAddress("FitWidth"          ,&tree_FitWidth   );
0527    t1->SetBranchAddress("FitWidthErr"       ,&tree_FitWidthErr);
0528    t1->SetBranchAddress("FitChi2NDF"        ,&tree_FitChi2NDF );
0529    t1->SetBranchAddress("Gain"              ,&tree_Gain       );
0530    t1->SetBranchAddress("PrevGain"          ,&tree_PrevGain   );
0531    t1->SetBranchAddress("NEntries"          ,&tree_NEntries   );
0532    t1->SetBranchAddress("isMasked"          ,&tree_isMasked   );
0533 
0534 
0535    TH2D* ChargeDistrib  = (TH2D*)GetObjectFromPath(f1,moduleName+"Charge_Vs_Index");
0536    TH2D* ChargeDistribA = (TH2D*)GetObjectFromPath(f1,moduleName+"Charge_Vs_Index_Absolute");
0537 
0538    TH2D* Charge_Vs_PathlengthTIB   = (TH2D*)GetObjectFromPath(f1,moduleName+"Charge_Vs_PathlengthTIB");
0539    TH2D* Charge_Vs_PathlengthTOB   = (TH2D*)GetObjectFromPath(f1,moduleName+"Charge_Vs_PathlengthTOB");
0540    TH2D* Charge_Vs_PathlengthTIDP  = (TH2D*)GetObjectFromPath(f1,moduleName+"Charge_Vs_PathlengthTIDP");
0541    TH2D* Charge_Vs_PathlengthTIDM  = (TH2D*)GetObjectFromPath(f1,moduleName+"Charge_Vs_PathlengthTIDM");
0542    TH2D* Charge_Vs_PathlengthTID   = (TH2D*)Charge_Vs_PathlengthTIDP->Clone("Charge_Vs_PathlengthTID");
0543          Charge_Vs_PathlengthTID      ->Add(Charge_Vs_PathlengthTIDM);
0544    TH2D* Charge_Vs_PathlengthTECP1 = (TH2D*)GetObjectFromPath(f1,moduleName+"Charge_Vs_PathlengthTECP1");
0545    TH2D* Charge_Vs_PathlengthTECP2 = (TH2D*)GetObjectFromPath(f1,moduleName+"Charge_Vs_PathlengthTECP2");
0546    TH2D* Charge_Vs_PathlengthTECM1 = (TH2D*)GetObjectFromPath(f1,moduleName+"Charge_Vs_PathlengthTECM1");
0547    TH2D* Charge_Vs_PathlengthTECM2 = (TH2D*)GetObjectFromPath(f1,moduleName+"Charge_Vs_PathlengthTECM2");
0548    TH2D* Charge_Vs_PathlengthTECP  = (TH2D*)Charge_Vs_PathlengthTECP1->Clone("Charge_Vs_PathlengthTECP");
0549          Charge_Vs_PathlengthTECP     ->Add(Charge_Vs_PathlengthTECP2);
0550    TH2D* Charge_Vs_PathlengthTECM  = (TH2D*)Charge_Vs_PathlengthTECM1->Clone("Charge_Vs_PathlengthTECM");
0551          Charge_Vs_PathlengthTECM     ->Add(Charge_Vs_PathlengthTECM2);
0552    TH2D* Charge_Vs_PathlengthTEC1  = (TH2D*)Charge_Vs_PathlengthTECP1->Clone("Charge_Vs_PathlengthTEC1");
0553          Charge_Vs_PathlengthTEC1     ->Add(Charge_Vs_PathlengthTECM1);
0554    TH2D* Charge_Vs_PathlengthTEC2  = (TH2D*)Charge_Vs_PathlengthTECP2->Clone("Charge_Vs_PathlengthTEC2");
0555          Charge_Vs_PathlengthTEC2     ->Add(Charge_Vs_PathlengthTECM2); 
0556    TH2D* Charge_Vs_PathlengthTEC   = (TH2D*)Charge_Vs_PathlengthTECP ->Clone("Charge_Vs_PathlengthTEC");
0557          Charge_Vs_PathlengthTEC      ->Add(Charge_Vs_PathlengthTECM );
0558 
0559    TH2D* Charge_Vs_PathlengthThin  = (TH2D*)Charge_Vs_PathlengthTEC1->Clone("Charge_Vs_PathlengthThin");
0560          Charge_Vs_PathlengthThin     ->Add(Charge_Vs_PathlengthTIB );
0561          Charge_Vs_PathlengthThin     ->Add(Charge_Vs_PathlengthTID );
0562    TH2D* Charge_Vs_PathlengthThick = (TH2D*)Charge_Vs_PathlengthTEC2->Clone("Charge_Vs_PathlengthThin");
0563          Charge_Vs_PathlengthThick    ->Add(Charge_Vs_PathlengthTOB );
0564 
0565    TH1D* MPV_Vs_PathlengthTIB      = ChargeToMPV(Charge_Vs_PathlengthTIB  ,"MPV_Vs_PathlengthTIB"  , true);
0566    TH1D* MPV_Vs_PathlengthTID      = ChargeToMPV(Charge_Vs_PathlengthTID  ,"MPV_Vs_PathlengthTID"  , true);
0567 // TH1D* MPV_Vs_PathlengthTIDP     = ChargeToMPV(Charge_Vs_PathlengthTIDP ,"MPV_Vs_PathlengthTIDP" , true);
0568 // TH1D* MPV_Vs_PathlengthTIDM     = ChargeToMPV(Charge_Vs_PathlengthTIDM ,"MPV_Vs_PathlengthTIDM" , true);
0569 
0570 
0571 
0572    TH1D* MPV_Vs_PathlengthTOB      = ChargeToMPV(Charge_Vs_PathlengthTOB  ,"MPV_Vs_PathlengthTOB"  , true);
0573 // TH1D* MPV_Vs_PathlengthTEC      = ChargeToMPV(Charge_Vs_PathlengthTEC  ,"MPV_Vs_PathlengthTEC"  , true);
0574 // TH1D* MPV_Vs_PathlengthTECP     = ChargeToMPV(Charge_Vs_PathlengthTECP ,"MPV_Vs_PathlengthTECP" , true);
0575 // TH1D* MPV_Vs_PathlengthTECM     = ChargeToMPV(Charge_Vs_PathlengthTECM ,"MPV_Vs_PathlengthTECM" , true);
0576    TH1D* MPV_Vs_PathlengthTEC1     = ChargeToMPV(Charge_Vs_PathlengthTEC1 ,"MPV_Vs_PathlengthTEC1" , true);
0577    TH1D* MPV_Vs_PathlengthTEC2     = ChargeToMPV(Charge_Vs_PathlengthTEC2 ,"MPV_Vs_PathlengthTEC2" , true);
0578 
0579 
0580 // TH1D* MPV_Vs_PathlengthTECP1    = ChargeToMPV(Charge_Vs_PathlengthTECP1,"MPV_Vs_PathlengthTECP1", true);
0581 // TH1D* MPV_Vs_PathlengthTECP2    = ChargeToMPV(Charge_Vs_PathlengthTECP2,"MPV_Vs_PathlengthTECP2", true);
0582 // TH1D* MPV_Vs_PathlengthTECM1    = ChargeToMPV(Charge_Vs_PathlengthTECM1,"MPV_Vs_PathlengthTECM1", true);
0583 // TH1D* MPV_Vs_PathlengthTECM2    = ChargeToMPV(Charge_Vs_PathlengthTECM2,"MPV_Vs_PathlengthTECM2", true);
0584    TH1D* MPV_Vs_PathlengthThin     = ChargeToMPV(Charge_Vs_PathlengthThin ,"MPV_Vs_PathlengthThin" , true);
0585    TH1D* MPV_Vs_PathlengthThick    = ChargeToMPV(Charge_Vs_PathlengthThick,"MPV_Vs_PathlengthThick", true);
0586 
0587 
0588 
0589    TH2D* MPV_Vs_EtaTIB  = new TH2D("MPV_Vs_EtaTIB" ,"MPV_Vs_EtaTIB" , 50, -3.0, 3.0, 300, 0, 600);
0590    TH2D* MPV_Vs_EtaTID  = new TH2D("MPV_Vs_EtaTID" ,"MPV_Vs_EtaTID" , 50, -3.0, 3.0, 300, 0, 600);
0591    TH2D* MPV_Vs_EtaTOB  = new TH2D("MPV_Vs_EtaTOB" ,"MPV_Vs_EtaTOB" , 50, -3.0, 3.0, 300, 0, 600);
0592    TH2D* MPV_Vs_EtaTEC  = new TH2D("MPV_Vs_EtaTEC" ,"MPV_Vs_EtaTEC" , 50, -3.0, 3.0, 300, 0, 600);
0593    TH2D* MPV_Vs_EtaTEC1 = new TH2D("MPV_Vs_EtaTEC1","MPV_Vs_EtaTEC1", 50, -3.0, 3.0, 300, 0, 600);
0594    TH2D* MPV_Vs_EtaTEC2 = new TH2D("MPV_Vs_EtaTEC2","MPV_Vs_EtaTEC2", 50, -3.0, 3.0, 300, 0, 600);
0595 
0596    TH2D* MPV_Vs_PhiTIB  = new TH2D("MPV_Vs_PhiTIB" ,"MPV_Vs_PhiTIB" , 50, -3.4, 3.4, 300, 0, 600);
0597    TH2D* MPV_Vs_PhiTID  = new TH2D("MPV_Vs_PhiTID" ,"MPV_Vs_PhiTID" , 50, -3.4, 3.4, 300, 0, 600);
0598    TH2D* MPV_Vs_PhiTOB  = new TH2D("MPV_Vs_PhiTOB" ,"MPV_Vs_PhiTOB" , 50, -3.4, 3.4, 300, 0, 600);
0599    TH2D* MPV_Vs_PhiTEC  = new TH2D("MPV_Vs_PhiTEC" ,"MPV_Vs_PhiTEC" , 50, -3.4, 3.4, 300, 0, 600);
0600    TH2D* MPV_Vs_PhiTEC1 = new TH2D("MPV_Vs_PhiTEC1","MPV_Vs_PhiTEC1", 50, -3.4, 3.4, 300, 0, 600);
0601    TH2D* MPV_Vs_PhiTEC2 = new TH2D("MPV_Vs_PhiTEC2","MPV_Vs_PhiTEC2", 50, -3.4, 3.4, 300, 0, 600);
0602 
0603    TH2D* NoMPV          = new TH2D("NoMPV"         ,"NoMPV"         ,350, -350, 350, 240, 0, 120);
0604 
0605 
0606 
0607    TH1D* Gains          = new TH1D("Gains"         ,"Gains"         ,                300, 0, 2);
0608    TH1D* MPVs           = new TH1D("MPVs"          ,"MPVs"          ,                300, 0, 600);
0609    TH1D* MPVs320        = new TH1D("MPVs320"       ,"MPVs320"       ,                300, 0, 600);
0610    TH1D* MPVs500        = new TH1D("MPVs500"       ,"MPVs500"       ,                300, 0, 600);
0611    TH1D* MPVsTIB        = new TH1D("MPVsTIB"       ,"MPVsTIB"       ,                300, 0, 600);
0612    TH1D* MPVsTID        = new TH1D("MPVsTID"       ,"MPVsTID"       ,                300, 0, 600);
0613    TH1D* MPVsTIDP       = new TH1D("MPVsTIDP"      ,"MPVsTIDP"      ,                300, 0, 600);
0614    TH1D* MPVsTIDM       = new TH1D("MPVsTIDM"      ,"MPVsTIDM"      ,                300, 0, 600);
0615    TH1D* MPVsTOB        = new TH1D("MPVsTOB"       ,"MPVsTOB"       ,                300, 0, 600);
0616    TH1D* MPVsTEC        = new TH1D("MPVsTEC"       ,"MPVsTEC"       ,                300, 0, 600);
0617    TH1D* MPVsTECP       = new TH1D("MPVsTECP"      ,"MPVsTECP"      ,                300, 0, 600);
0618    TH1D* MPVsTECM       = new TH1D("MPVsTECM"      ,"MPVsTECM"      ,                300, 0, 600);
0619    TH1D* MPVsTEC1       = new TH1D("MPVsTEC1"      ,"MPVsTEC1"      ,                300, 0, 600);
0620    TH1D* MPVsTEC2       = new TH1D("MPVsTEC2"      ,"MPVsTEC2"      ,                300, 0, 600);
0621    TH1D* MPVsTECP1      = new TH1D("MPVsTECP1"     ,"MPVsTECP1"     ,                300, 0, 600);
0622    TH1D* MPVsTECP2      = new TH1D("MPVsTECP2"     ,"MPVsTECP2"     ,                300, 0, 600);
0623    TH1D* MPVsTECM1      = new TH1D("MPVsTECM1"     ,"MPVsTECM1"     ,                300, 0, 600);
0624    TH1D* MPVsTECM2      = new TH1D("MPVsTECM2"     ,"MPVsTECM2"     ,                300, 0, 600);
0625 
0626 
0627    TH1D* MPVError       = new TH1D("MPVError"      ,"MPVError"      ,                150, 0, 150);
0628    TH2D* MPVErrorVsMPV  = new TH2D("MPVErrorVsMPV" ,"MPVErrorVsMPV" ,300,    0, 600, 150, 0, 150);
0629    TH2D* MPVErrorVsEta  = new TH2D("MPVErrorVsEta" ,"MPVErrorVsEta" , 50, -3.0, 3.0, 150, 0, 150); 
0630    TH2D* MPVErrorVsPhi  = new TH2D("MPVErrorVsPhi" ,"MPVErrorVsPhi" , 50, -3.4, 3.4, 150, 0, 150);             
0631    TH2D* MPVErrorVsN    = new TH2D("MPVErrorVsN"   ,"MPVErrorVsN"   ,500,    0,1000, 150, 0, 150);              
0632 
0633 
0634 
0635 
0636    TH1D* ChargeTIB      = new TH1D("ChargeTIB"     ,"ChargeTIB"     ,               1000, 0,2000);
0637    TH1D* ChargeTID      = new TH1D("ChargeTID"     ,"ChargeTID"     ,               1000, 0,2000);
0638    TH1D* ChargeTIDP     = new TH1D("ChargeTIDP"    ,"ChargeTIDP"    ,               1000, 0,2000);
0639    TH1D* ChargeTIDM     = new TH1D("ChargeTIDM"    ,"ChargeTIDM"    ,               1000, 0,2000);
0640    TH1D* ChargeTOB      = new TH1D("ChargeTOB"     ,"ChargeTOB"     ,               1000, 0,2000);
0641    TH1D* ChargeTEC      = new TH1D("ChargeTEC"     ,"ChargeTEC"     ,               1000, 0,2000);
0642    TH1D* ChargeTECP     = new TH1D("ChargeTECP"    ,"ChargeTECP"    ,               1000, 0,2000);
0643    TH1D* ChargeTECM     = new TH1D("ChargeTECM"    ,"ChargeTECM"    ,               1000, 0,2000);
0644    TH1D* ChargeTEC1     = new TH1D("ChargeTEC1"    ,"ChargeTEC1"    ,               1000, 0,2000);
0645    TH1D* ChargeTEC2     = new TH1D("ChargeTEC2"    ,"ChargeTEC2"    ,               1000, 0,2000);
0646    TH1D* ChargeTECP1    = new TH1D("ChargeTECP1"   ,"ChargeTECP1"   ,               1000, 0,2000);
0647    TH1D* ChargeTECP2    = new TH1D("ChargeTECP2"   ,"ChargeTECP2"   ,               1000, 0,2000);
0648    TH1D* ChargeTECM1    = new TH1D("ChargeTECM1"   ,"ChargeTECM1"   ,               1000, 0,2000);
0649    TH1D* ChargeTECM2    = new TH1D("ChargeTECM2"   ,"ChargeTECM2"   ,               1000, 0,2000);
0650 
0651    TH1D* ChargeAbsTIB   = new TH1D("ChargeAbsTIB"  ,"ChargeAbsTIB"  ,                500, 0,2000);
0652    TH1D* ChargeAbsTID   = new TH1D("ChargeAbsTID"  ,"ChargeAbsTID"  ,                500, 0,2000);
0653    TH1D* ChargeAbsTIDP  = new TH1D("ChargeAbsTIDP" ,"ChargeAbsTIDP" ,                500, 0,2000);
0654    TH1D* ChargeAbsTIDM  = new TH1D("ChargeAbsTIDM" ,"ChargeAbsTIDM" ,                500, 0,2000);
0655    TH1D* ChargeAbsTOB   = new TH1D("ChargeAbsTOB"  ,"ChargeAbsTOB"  ,                500, 0,2000);
0656    TH1D* ChargeAbsTEC   = new TH1D("ChargeAbsTEC"  ,"ChargeAbsTEC"  ,                500, 0,2000);
0657    TH1D* ChargeAbsTECP  = new TH1D("ChargeAbsTECP" ,"ChargeAbsTECP" ,                500, 0,2000);
0658    TH1D* ChargeAbsTECM  = new TH1D("ChargeAbsTECM" ,"ChargeAbsTECM" ,                500, 0,2000);
0659    TH1D* ChargeAbsTEC1  = new TH1D("ChargeAbsTEC1" ,"ChargeAbsTEC1" ,                500, 0,2000);
0660    TH1D* ChargeAbsTEC2  = new TH1D("ChargeAbsTEC2" ,"ChargeAbsTEC2" ,                500, 0,2000);
0661    TH1D* ChargeAbsTECP1 = new TH1D("ChargeAbsTECP1","ChargeAbsTECP1",                500, 0,2000);
0662    TH1D* ChargeAbsTECP2 = new TH1D("ChargeAbsTECP2","ChargeAbsTECP2",                500, 0,2000);
0663    TH1D* ChargeAbsTECM1 = new TH1D("ChargeAbsTECM1","ChargeAbsTECM1",                500, 0,2000);
0664    TH1D* ChargeAbsTECM2 = new TH1D("ChargeAbsTECM2","ChargeAbsTECM2",                500, 0,2000);
0665 
0666    TH1D* DiffWRTPrevGainTIB      = new TH1D("DiffWRTPrevGainTIB"     ,"DiffWRTPrevGainTIB"     ,               250, 0,2);
0667    TH1D* DiffWRTPrevGainTID      = new TH1D("DiffWRTPrevGainTID"     ,"DiffWRTPrevGainTID"     ,               250, 0,2);
0668    TH1D* DiffWRTPrevGainTOB      = new TH1D("DiffWRTPrevGainTOB"     ,"DiffWRTPrevGainTOB"     ,               250, 0,2);
0669    TH1D* DiffWRTPrevGainTEC      = new TH1D("DiffWRTPrevGainTEC"     ,"DiffWRTPrevGainTEC"     ,               250, 0,2);
0670 
0671    TH2D* GainVsPrevGainTIB      = new TH2D("GainVsPrevGainTIB"     ,"GainVsPrevGainTIB"     ,               100, 0,2, 100, 0,2);
0672    TH2D* GainVsPrevGainTID      = new TH2D("GainVsPrevGainTID"     ,"GainVsPrevGainTID"     ,               100, 0,2, 100, 0,2);
0673    TH2D* GainVsPrevGainTOB      = new TH2D("GainVsPrevGainTOB"     ,"GainVsPrevGainTOB"     ,               100, 0,2, 100, 0,2);
0674    TH2D* GainVsPrevGainTEC      = new TH2D("GainVsPrevGainTEC"     ,"GainVsPrevGainTEC"     ,               100, 0,2, 100, 0,2);
0675 
0676 
0677    printf("Progressing Bar              :0%%       20%%       40%%       60%%       80%%       100%%\n");
0678    printf("Looping on the Tree          :");
0679    int TreeStep = t1->GetEntries()/50;if(TreeStep==0)TreeStep=1;
0680    for (unsigned int ientry = 0; ientry < t1->GetEntries(); ientry++) {
0681       if(ientry%TreeStep==0){printf(".");fflush(stdout);}
0682       t1->GetEntry(ientry);
0683       int bin = ChargeDistrib->GetXaxis()->FindBin(tree_Index);
0684       TH1D* Proj         = ChargeDistrib ->ProjectionY("proj" ,bin, bin);
0685       TH1D* ProjAbsolute = ChargeDistribA->ProjectionY("projA",bin, bin);
0686 
0687       if(tree_FitMPV<0                        ) NoMPV         ->Fill(tree_z ,tree_R);
0688       if(tree_FitMPV>=0){
0689 
0690       if(tree_SubDet==3                       ) MPV_Vs_EtaTIB ->Fill(tree_Eta,tree_FitMPV);
0691       if(tree_SubDet==4                       ) MPV_Vs_EtaTID ->Fill(tree_Eta,tree_FitMPV);
0692       if(tree_SubDet==5                       ) MPV_Vs_EtaTOB ->Fill(tree_Eta,tree_FitMPV);
0693       if(tree_SubDet==6                       ) MPV_Vs_EtaTEC ->Fill(tree_Eta,tree_FitMPV);
0694       if(tree_SubDet==6 && tree_Thickness<0.04) MPV_Vs_EtaTEC1->Fill(tree_Eta,tree_FitMPV);
0695       if(tree_SubDet==6 && tree_Thickness>0.04) MPV_Vs_EtaTEC2->Fill(tree_Eta,tree_FitMPV);
0696 
0697       if(tree_SubDet==3                       ) MPV_Vs_PhiTIB ->Fill(tree_Phi,tree_FitMPV);
0698       if(tree_SubDet==4                       ) MPV_Vs_PhiTID ->Fill(tree_Phi,tree_FitMPV);
0699       if(tree_SubDet==5                       ) MPV_Vs_PhiTOB ->Fill(tree_Phi,tree_FitMPV);
0700       if(tree_SubDet==6                       ) MPV_Vs_PhiTEC ->Fill(tree_Phi,tree_FitMPV);
0701       if(tree_SubDet==6 && tree_Thickness<0.04) MPV_Vs_PhiTEC1->Fill(tree_Phi,tree_FitMPV);
0702       if(tree_SubDet==6 && tree_Thickness>0.04) MPV_Vs_PhiTEC2->Fill(tree_Phi,tree_FitMPV);
0703 
0704       if(tree_FitMPV>0                        ) Gains         ->Fill(         tree_Gain  );
0705                                                 MPVs          ->Fill(         tree_FitMPV);
0706       if(                  tree_Thickness<0.04) MPVs320       ->Fill(         tree_FitMPV);
0707       if(                  tree_Thickness>0.04) MPVs500       ->Fill(         tree_FitMPV);
0708       if(tree_SubDet==3                       ) MPVsTIB       ->Fill(         tree_FitMPV);
0709       if(tree_SubDet==4                       ) MPVsTID       ->Fill(         tree_FitMPV);
0710       if(tree_SubDet==4 && tree_Eta<0         ) MPVsTIDM      ->Fill(         tree_FitMPV);
0711       if(tree_SubDet==4 && tree_Eta>0         ) MPVsTIDP      ->Fill(         tree_FitMPV);
0712       if(tree_SubDet==5                       ) MPVsTOB       ->Fill(         tree_FitMPV);
0713       if(tree_SubDet==6                       ) MPVsTEC       ->Fill(         tree_FitMPV);
0714       if(tree_SubDet==6 && tree_Thickness<0.04) MPVsTEC1      ->Fill(         tree_FitMPV);
0715       if(tree_SubDet==6 && tree_Thickness>0.04) MPVsTEC2      ->Fill(         tree_FitMPV);
0716       if(tree_SubDet==6 && tree_Eta<0         ) MPVsTECP      ->Fill(         tree_FitMPV);
0717       if(tree_SubDet==6 && tree_Eta>0         ) MPVsTECM      ->Fill(         tree_FitMPV);
0718       if(tree_SubDet==6 && tree_Thickness<0.04 && tree_Eta>0) MPVsTECP1      ->Fill(         tree_FitMPV);
0719       if(tree_SubDet==6 && tree_Thickness>0.04 && tree_Eta>0) MPVsTECP2      ->Fill(         tree_FitMPV);
0720       if(tree_SubDet==6 && tree_Thickness<0.04 && tree_Eta<0) MPVsTECM1      ->Fill(         tree_FitMPV);
0721       if(tree_SubDet==6 && tree_Thickness>0.04 && tree_Eta<0) MPVsTECM2      ->Fill(         tree_FitMPV);
0722 
0723                                                 MPVError      ->Fill(         tree_FitMPVErr);    
0724                                                 MPVErrorVsMPV ->Fill(tree_FitMPV,tree_FitMPVErr);
0725                                                 MPVErrorVsEta ->Fill(tree_Eta,tree_FitMPVErr);
0726                                                 MPVErrorVsPhi ->Fill(tree_Phi,tree_FitMPVErr);
0727                                                 MPVErrorVsN   ->Fill(tree_NEntries,tree_FitMPVErr);
0728       }
0729 
0730 
0731       if(tree_SubDet==3                       ) ChargeTIB  ->Add(Proj,1);
0732       if(tree_SubDet==4                       ) ChargeTID  ->Add(Proj,1);
0733       if(tree_SubDet==4 && tree_Eta<0         ) ChargeTIDM ->Add(Proj,1);
0734       if(tree_SubDet==4 && tree_Eta>0         ) ChargeTIDP ->Add(Proj,1);
0735       if(tree_SubDet==5                       ) ChargeTOB  ->Add(Proj,1);
0736       if(tree_SubDet==6                       ) ChargeTEC  ->Add(Proj,1);
0737       if(tree_SubDet==6 && tree_Thickness<0.04) ChargeTEC1 ->Add(Proj,1);
0738       if(tree_SubDet==6 && tree_Thickness>0.04) ChargeTEC2 ->Add(Proj,1);
0739       if(tree_SubDet==6 && tree_Eta>0         ) ChargeTECP ->Add(Proj,1);
0740       if(tree_SubDet==6 && tree_Eta<0         ) ChargeTECM ->Add(Proj,1);
0741       if(tree_SubDet==6 && tree_Eta<0 && tree_Thickness<0.04) ChargeTECM1 ->Add(Proj,1);
0742       if(tree_SubDet==6 && tree_Eta<0 && tree_Thickness>0.04) ChargeTECM2 ->Add(Proj,1);
0743       if(tree_SubDet==6 && tree_Eta>0 && tree_Thickness<0.04) ChargeTECP1 ->Add(Proj,1);
0744       if(tree_SubDet==6 && tree_Eta>0 && tree_Thickness>0.04) ChargeTECP2 ->Add(Proj,1);
0745 
0746 
0747       if(tree_SubDet==3                       ) ChargeAbsTIB  ->Add(ProjAbsolute,1);
0748       if(tree_SubDet==4                       ) ChargeAbsTID  ->Add(ProjAbsolute,1);
0749       if(tree_SubDet==4 && tree_Eta<0         ) ChargeAbsTIDM ->Add(ProjAbsolute,1);
0750       if(tree_SubDet==4 && tree_Eta>0         ) ChargeAbsTIDP ->Add(ProjAbsolute,1);
0751       if(tree_SubDet==5                       ) ChargeAbsTOB  ->Add(ProjAbsolute,1);
0752       if(tree_SubDet==6                       ) ChargeAbsTEC  ->Add(ProjAbsolute,1);
0753       if(tree_SubDet==6 && tree_Thickness<0.04) ChargeAbsTEC1 ->Add(ProjAbsolute,1);
0754       if(tree_SubDet==6 && tree_Thickness>0.04) ChargeAbsTEC2 ->Add(ProjAbsolute,1);
0755       if(tree_SubDet==6 && tree_Eta>0         ) ChargeAbsTECP ->Add(ProjAbsolute,1);
0756       if(tree_SubDet==6 && tree_Eta<0         ) ChargeAbsTECM ->Add(ProjAbsolute,1);
0757       if(tree_SubDet==6 && tree_Eta<0 && tree_Thickness<0.04) ChargeAbsTECM1 ->Add(ProjAbsolute,1);
0758       if(tree_SubDet==6 && tree_Eta<0 && tree_Thickness>0.04) ChargeAbsTECM2 ->Add(ProjAbsolute,1);
0759       if(tree_SubDet==6 && tree_Eta>0 && tree_Thickness<0.04) ChargeAbsTECP1 ->Add(ProjAbsolute,1);
0760       if(tree_SubDet==6 && tree_Eta>0 && tree_Thickness>0.04) ChargeAbsTECP2 ->Add(ProjAbsolute,1);
0761 
0762       if(tree_SubDet==3                       ) DiffWRTPrevGainTIB  ->Fill(tree_Gain/tree_PrevGain);
0763       if(tree_SubDet==4                       ) DiffWRTPrevGainTID  ->Fill(tree_Gain/tree_PrevGain);
0764       if(tree_SubDet==5                       ) DiffWRTPrevGainTOB  ->Fill(tree_Gain/tree_PrevGain);
0765       if(tree_SubDet==6                       ) DiffWRTPrevGainTEC  ->Fill(tree_Gain/tree_PrevGain);
0766 
0767       if(tree_SubDet==3                       ) GainVsPrevGainTIB  ->Fill(tree_PrevGain,tree_Gain);
0768       if(tree_SubDet==4                       ) GainVsPrevGainTID  ->Fill(tree_PrevGain,tree_Gain);
0769       if(tree_SubDet==5                       ) GainVsPrevGainTOB  ->Fill(tree_PrevGain,tree_Gain);
0770       if(tree_SubDet==6                       ) GainVsPrevGainTEC  ->Fill(tree_PrevGain,tree_Gain);
0771 
0772       delete Proj;
0773       delete ProjAbsolute;
0774    }printf("\n");
0775 
0776 
0777 
0778    // ######################################################### PRINT OUT APV INFOS #################################
0779    unsigned int CountAPV_Total    = 0;
0780    unsigned int CountAPV_NoEntry  = 0;
0781    unsigned int CountAPV_NoEntryU = 0;
0782    unsigned int CountAPV_NoGain   = 0;
0783    unsigned int CountAPV_NoGainU  = 0;
0784    unsigned int CountAPV_LowGain  = 0;
0785    unsigned int CountAPV_DiffGain = 0;
0786 
0787    pFile = fopen((output + "_LowResponseModule.txt").c_str(),"w");
0788    fprintf(pFile,"\n\nALL APVs WITH NO ENTRIES (NO RECO CLUSTER ON IT)\n--------------------------------------------\n");
0789    printf("Looping on the Tree          :");
0790    for (unsigned int ientry = 0; ientry < t1->GetEntries(); ientry++) {      
0791       if(ientry%TreeStep==0){printf(".");fflush(stdout);}
0792       t1->GetEntry(ientry);
0793       CountAPV_Total++;
0794       if(tree_NEntries==0){fprintf(pFile,"%i-%i, ",tree_DetId,tree_APVId); CountAPV_NoEntry++;}
0795    }printf("\n");
0796    fprintf(pFile,"\n--> %i / %i = %f%% APV Concerned\n",CountAPV_NoEntry,CountAPV_Total,(100.0*CountAPV_NoEntry)/CountAPV_Total);
0797 
0798    fprintf(pFile,"\n\nUNMASKED APVs WITH NO ENTRIES (NO RECO CLUSTER ON IT)\n--------------------------------------------\n");
0799    printf("Looping on the Tree          :");
0800    for (unsigned int ientry = 0; ientry < t1->GetEntries(); ientry++) {
0801       if(ientry%TreeStep==0){printf(".");fflush(stdout);}
0802       t1->GetEntry(ientry);
0803       if(tree_NEntries==0 && !tree_isMasked){fprintf(pFile,"%i-%i, ",tree_DetId,tree_APVId); CountAPV_NoEntryU++;}
0804    }printf("\n");
0805    fprintf(pFile,"\n--> %i / %i = %f%% APV Concerned\n",CountAPV_NoEntryU,CountAPV_Total,(100.0*CountAPV_NoEntryU)/CountAPV_Total);
0806 
0807    fprintf(pFile,"\n\nALL APVs WITH NO GAIN COMPUTED\n--------------------------------------------\n");
0808    printf("Looping on the Tree          :");
0809    for (unsigned int ientry = 0; ientry < t1->GetEntries(); ientry++) {
0810       if(ientry%TreeStep==0){printf(".");fflush(stdout);}
0811       t1->GetEntry(ientry);
0812       if(tree_FitMPV<0){fprintf(pFile,"%i-%i, ",tree_DetId,tree_APVId); CountAPV_NoGain++;}
0813    }printf("\n");
0814    fprintf(pFile,"\n--> %i / %i = %f%% APV Concerned\n",CountAPV_NoGain,CountAPV_Total,(100.0*CountAPV_NoGain)/CountAPV_Total);
0815 
0816    fprintf(pFile,"\n\nUNMASKED APVs WITH NO GAIN COMPUTED\n--------------------------------------------\n");
0817    printf("Looping on the Tree          :");
0818    for (unsigned int ientry = 0; ientry < t1->GetEntries(); ientry++) {
0819       if(ientry%TreeStep==0){printf(".");fflush(stdout);}
0820       t1->GetEntry(ientry);
0821       if(tree_FitMPV<0 && !tree_isMasked){fprintf(pFile,"%i-%i, ",tree_DetId,tree_APVId); CountAPV_NoGainU++;}
0822    }printf("\n");
0823    fprintf(pFile,"\n--> %i / %i = %f%% APV Concerned\n",CountAPV_NoGainU,CountAPV_Total,(100.0*CountAPV_NoGainU)/CountAPV_Total);
0824 
0825    fprintf(pFile,"\n\nUNMASKED APVs WITH LOW RESPONSE\n--------------------------------------------\n");
0826    printf("Looping on the Tree          :");
0827    for (unsigned int ientry = 0; ientry < t1->GetEntries(); ientry++) {
0828       if(ientry%TreeStep==0){printf(".");fflush(stdout);}
0829       t1->GetEntry(ientry);
0830       if(tree_FitMPV>0 && tree_FitMPV<220 && !tree_isMasked){fprintf(pFile,"%i-%i, ",tree_DetId,tree_APVId); CountAPV_LowGain++;}
0831    }printf("\n");
0832    fprintf(pFile,"\n--> %i / %i = %f%% APV Concerned\n",CountAPV_LowGain,CountAPV_Total,(100.0*CountAPV_LowGain)/CountAPV_Total);
0833 
0834    fprintf(pFile,"\n\nUNMASKED APVs WITH SIGNIFICANT CHANGE OF GAIN VALUE\n--------------------------------------------\n");
0835    printf("Looping on the Tree          :");
0836    for (unsigned int ientry = 0; ientry < t1->GetEntries(); ientry++) {
0837       if(ientry%TreeStep==0){printf(".");fflush(stdout);}
0838       t1->GetEntry(ientry);
0839       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++;}
0840    }printf("\n");
0841    fprintf(pFile,"\n--> %i / %i = %f%% APV Concerned\n",CountAPV_DiffGain,CountAPV_Total,(100.0*CountAPV_DiffGain)/CountAPV_Total);
0842    fclose(pFile);
0843 
0844 
0845 
0846    // ######################################################### PRINT DISTRIBUTION INFO #################################
0847    pFile = fopen((output + "_SubDetector_MPV.txt").c_str(),"w");
0848 
0849    double Results[5]; TF1* landau;
0850    landau = getLandau(ChargeTIB, Results, 0, 5400);
0851    c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0852    ChargeTIB->Draw();
0853    landau->SetLineWidth(3);
0854    landau->Draw("same");
0855    SaveCanvas(c1,output,"SubDetChargeTIB");
0856    fprintf(pFile,"TIB   MPV=%7.2f +- %7.2f  Chi2=%7.2f\n",Results[0],Results[1],Results[4]);
0857 
0858    landau = getLandau(ChargeTIDM, Results, 0, 5400);
0859    c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0860    ChargeTIDM->Draw();
0861    landau->SetLineWidth(3);
0862    landau->Draw("same");
0863    SaveCanvas(c1,output,"SubDetChargeTIDM");
0864    fprintf(pFile, "TIDM  MPV=%7.2f +- %7.2f  Chi2=%7.2f\n",Results[0],Results[1],Results[4]);
0865 
0866    landau = getLandau(ChargeTIDP, Results, 0, 5400);
0867    c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0868    ChargeTIDP->Draw();
0869    landau->SetLineWidth(3);
0870    landau->Draw("same");
0871    SaveCanvas(c1,output,"SubDetChargeTIDP");
0872    fprintf(pFile, "TIDP  MPV=%7.2f +- %7.2f  Chi2=%7.2f\n",Results[0],Results[1],Results[4]);
0873 
0874    landau = getLandau(ChargeTOB, Results, 0, 5400);
0875    c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0876    ChargeTOB->Draw();
0877    landau->SetLineWidth(3);
0878    landau->Draw("same");
0879    SaveCanvas(c1,output,"SubDetChargeTOB");
0880    fprintf(pFile, "TOB   MPV=%7.2f +- %7.2f  Chi2=%7.2f\n",Results[0],Results[1],Results[4]);
0881 
0882    landau = getLandau(ChargeTECP1, Results, 0, 5400);
0883    c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0884    ChargeTECP1->Draw();
0885    landau->SetLineWidth(3);
0886    landau->Draw("same");
0887    SaveCanvas(c1,output,"SubDetChargeTECP1");
0888    fprintf(pFile, "TECP1 MPV=%7.2f +- %7.2f  Chi2=%7.2f\n",Results[0],Results[1],Results[4]);
0889 
0890    landau = getLandau(ChargeTECP2, Results, 0, 5400);
0891    c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0892    ChargeTECP2->Draw();
0893    landau->SetLineWidth(3);
0894    landau->Draw("same");
0895    SaveCanvas(c1,output,"SubDetChargeTECP2");
0896    fprintf(pFile, "TECP2 MPV=%7.2f +- %7.2f  Chi2=%7.2f\n",Results[0],Results[1],Results[4]);
0897 
0898    landau = getLandau(ChargeTECM1, Results, 0, 5400);
0899    c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0900    ChargeTECM1->Draw();
0901    landau->SetLineWidth(3);
0902    landau->Draw("same");
0903    SaveCanvas(c1,output,"SubDetChargeTECM1");
0904    fprintf(pFile, "TECM1 MPV=%7.2f +- %7.2f  Chi2=%7.2f\n",Results[0],Results[1],Results[4]);
0905 
0906    landau = getLandau(ChargeTECM2, Results, 0, 5400);
0907    c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0908    ChargeTECM2->Draw();
0909    landau->SetLineWidth(3);
0910    landau->Draw("same");
0911    SaveCanvas(c1,output,"SubDetChargeTECM2");
0912    fprintf(pFile, "TECM2 MPV=%7.2f +- %7.2f  Chi2=%7.2f\n",Results[0],Results[1],Results[4]);
0913 
0914    fclose(pFile);
0915    // ######################################################### MAKE PLOTS #################################
0916 
0917 
0918    c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0919    Histos[0] = MPV_Vs_EtaTEC;                     legend.push_back("TEC");
0920    Histos[1] = MPV_Vs_EtaTIB;                     legend.push_back("TIB");
0921    Histos[2] = MPV_Vs_EtaTID;                     legend.push_back("TID");
0922    Histos[3] = MPV_Vs_EtaTOB;                     legend.push_back("TOB");
0923    DrawTH2D((TH2D**)Histos,legend, "", "module #eta", "MPV [ADC/mm]", -3.0,3.0, 0,600);
0924    DrawLegend (Histos,legend,"","P");
0925    DrawStatBox(Histos,legend,false);
0926    SaveCanvas(c1,output,"MPV_Vs_EtaSubDet");
0927    delete c1;
0928 
0929     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0930     Histos[0] = MPV_Vs_PhiTEC;                     legend.push_back("TEC");
0931     Histos[1] = MPV_Vs_PhiTIB;                     legend.push_back("TIB");
0932     Histos[2] = MPV_Vs_PhiTID;                     legend.push_back("TID");
0933     Histos[3] = MPV_Vs_PhiTOB;                     legend.push_back("TOB");
0934     DrawTH2D((TH2D**)Histos,legend, "", "module #phi", "MPV [ADC/mm]", -3.4,3.4, 0,600);
0935     DrawLegend(Histos,legend,"","P");
0936     DrawStatBox(Histos,legend,false);
0937     SaveCanvas(c1,output,"MPV_Vs_PhiSubDet");
0938     delete c1;
0939 
0940     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0941     Histos[0] = NoMPV;                             legend.push_back("NoMPV");
0942     DrawTH2D((TH2D**)Histos,legend, "", "z (cm)", "R (cms)", 0,0, 0,0);
0943     SaveCanvas(c1,output,"NoMPV", true);
0944     delete c1;
0945 
0946     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0947     ChargeDistrib->GetXaxis()->SetNdivisions(5+500);
0948     Histos[0] = ChargeDistrib;                     legend.push_back("Charge Vs Index");
0949     DrawTH2D((TH2D**)Histos,legend, "COLZ", "APV Index", "Charge [ADC/mm]", 0,0, 0,0);
0950     c1->SetLogz(true);
0951     SaveCanvas(c1,output,"Charge2D", true);
0952     delete c1;
0953 
0954     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0955     Histos[0] = Gains;                             legend.push_back("");
0956     DrawSuperposedHistos((TH1**)Histos, legend, "",  "Gain", "Number of APVs", 0.5,1.5, 0,0);
0957     DrawLegend(Histos,legend,"","L");
0958     DrawStatBox(Histos,legend,true);
0959     SaveCanvas(c1,output,"Gains");
0960 
0961     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0962     Histos[0] = MPVs320;                           legend.push_back("320 #mum");
0963     Histos[1] = MPVs500;                           legend.push_back("500 #mum");
0964     Histos[2] = MPVs;                              legend.push_back("320 + 500 #mum");
0965     DrawSuperposedHistos((TH1**)Histos, legend, "",  "MPV [ADC/mm]", "Number of APVs", 100,550, 0,0);
0966     DrawLegend(Histos,legend,"","L");
0967     DrawPreliminary(DataType);
0968     SaveCanvas(c1,output,"MPVs");
0969     c1->SetLogy(true);
0970     SaveCanvas(c1,output,"MPVsLog");
0971     DrawStatBox(Histos,legend,true);
0972     c1->SetLogy(false);
0973     SaveCanvas(c1,output,"MPVsAndStat");
0974     c1->SetLogy(true);
0975     SaveCanvas(c1,output,"MPVsLogAndStat");
0976     delete c1;
0977 
0978 
0979     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
0980     MPVsTOB->GetXaxis()->SetNdivisions(5+500);
0981     Histos[0] = MPVsTIB;                           legend.push_back("TIB (320 #mum)");
0982     Histos[1] = MPVsTID;                           legend.push_back("TID (320 #mum)");
0983     Histos[2] = MPVsTOB;                           legend.push_back("TOB (500 #mum)");
0984     Histos[3] = MPVsTEC1;                          legend.push_back("TEC (320 #mum)");
0985     Histos[4] = MPVsTEC2;                          legend.push_back("TEC (500 #mum)");
0986 //    Histos[5] = MPVs;                              legend.push_back("All");
0987     DrawSuperposedHistos((TH1**)Histos, legend, "",  "MPV [ADC/mm]", "Number of APVs", 100,550, 0,0);
0988     DrawLegend(Histos,legend,"","L");
0989     DrawPreliminary(DataType);
0990     SaveCanvas(c1,output,"MPVsSubDet");
0991     c1->SetLogy(true);
0992     SaveCanvas(c1,output,"MPVsSubDetLog");
0993     DrawStatBox(Histos,legend,true);
0994     SaveCanvas(c1,output,"MPVsSubDetLogAndStat");
0995     c1->SetLogy(false);
0996     SaveCanvas(c1,output,"MPVsSubDetAndStat");
0997     delete c1;
0998 
0999 
1000 
1001     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
1002     MPVsTOB->GetXaxis()->SetNdivisions(5+500);
1003     Histos[0] = MPVsTECP1;                          legend.push_back("TEC+ (320 #mum)");
1004     Histos[1] = MPVsTECP2;                          legend.push_back("TEC+ (500 #mum)");
1005     Histos[2] = MPVsTECM1;                          legend.push_back("TEC- (320 #mum)");
1006     Histos[3] = MPVsTECM2;                          legend.push_back("TEC- (500 #mum)");
1007     DrawSuperposedHistos((TH1**)Histos, legend, "",  "MPV [ADC/mm]", "Number of APVs", 100,550, 0,0);
1008     DrawLegend(Histos,legend,"#sqrt{s}=7TeV","L");
1009     DrawStatBox(Histos,legend,true);
1010     SaveCanvas(c1,output,"MPVsTEC");
1011     c1->SetLogy(true);
1012     SaveCanvas(c1,output,"MPVsTECLog");
1013     delete c1;
1014 
1015 
1016     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
1017     Histos[0] = MPVError;                          legend.push_back("MPV Error");
1018     DrawSuperposedHistos((TH1**)Histos, legend, "",  "Error on MPV [ADC/mm]", "Number of APVs", 0,500, 0,0);
1019     DrawStatBox(Histos,legend,true);
1020     c1->SetLogy(true);
1021     SaveCanvas(c1,output,"Error");
1022     delete c1;
1023 
1024     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
1025     Histos[0] = MPVErrorVsMPV;                     legend.push_back("Error Vs MPV");
1026     DrawTH2D((TH2D**)Histos,legend, "COLZ", "MPV [ADC/mm]", "Error on MPV [ADC/mm]", 0,0, 0,0);
1027     c1->SetLogz(true);
1028     SaveCanvas(c1,output,"Error_Vs_MPV", true);
1029     delete c1;
1030 
1031     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
1032     Histos[0] = MPVErrorVsEta;                     legend.push_back("Error Vs Eta");
1033     DrawTH2D((TH2D**)Histos,legend, "COLZ", "module #eta", "Error on MPV [ADC/mm]", 0,0, 0,0);
1034     c1->SetLogz(true);
1035     SaveCanvas(c1,output,"Error_Vs_Eta", true);
1036     delete c1;
1037 
1038     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
1039     Histos[0] = MPVErrorVsPhi;                     legend.push_back("Error Vs Phi");
1040     DrawTH2D((TH2D**)Histos,legend, "COLZ", "module #phi", "Error on MPV [ADC/mm]", 0,0, 0,0);
1041     c1->SetLogz(true);
1042     SaveCanvas(c1,output,"Error_Vs_Phi", true);
1043     delete c1;
1044 
1045     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
1046     Histos[0] = MPVErrorVsN;                       legend.push_back("Error Vs Entries");
1047     DrawTH2D((TH2D**)Histos,legend, "COLZ", "Number of Entries", "Error on MPV [ADC/mm]", 0,0, 0,0);
1048     c1->SetLogz(true);
1049     SaveCanvas(c1,output,"Error_Vs_N", true);
1050     delete c1;
1051 
1052     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
1053     Histos[0] = ChargeTEC;                         legend.push_back("TEC");
1054     Histos[1] = ChargeTIB;                         legend.push_back("TIB");
1055     Histos[2] = ChargeTID;                         legend.push_back("TID");
1056     Histos[3] = ChargeTOB;                         legend.push_back("TOB");
1057     DrawSuperposedHistos((TH1**)Histos, legend, "",  "Charge [ADC/mm]", "Number of Clusters", 0,800 , 0,0);
1058     DrawLegend(Histos,legend,"","L");
1059     DrawPreliminary(DataType);
1060     TLine* l0 = new TLine(300, 0,300,((TH1*)Histos[0])->GetMaximum()); l0->SetLineWidth(3); l0->SetLineStyle(2); l0->Draw("same");
1061     SaveCanvas(c1,output,"Charge");
1062     DrawStatBox(Histos,legend,true, 0.6, 0.7);
1063     SaveCanvas(c1,output,"ChargeAndStat");
1064     delete c1;
1065 
1066     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
1067     Histos[0] = ChargeTECP;                        legend.push_back("TEC+");
1068     Histos[1] = ChargeTECM;                        legend.push_back("TEC-");
1069     DrawSuperposedHistos((TH1**)Histos, legend, "",  "Charge [ADC/mm]", "Number of Clusters", 0,800 , 0,0);
1070     DrawLegend(Histos,legend,"","L");
1071     DrawStatBox(Histos,legend,true, 0.6, 0.7);
1072     SaveCanvas(c1,output,"ChargeTECSide");
1073     delete c1;
1074 
1075     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
1076     Histos[0] = ChargeTEC1;                        legend.push_back("TEC Thin");
1077     Histos[1] = ChargeTEC2;                        legend.push_back("TEC Thick");
1078     DrawSuperposedHistos((TH1**)Histos, legend, "",  "Charge [ADC/mm]", "Number of Clusters", 0,800 , 0,0);
1079     DrawLegend(Histos,legend,"","L");
1080     DrawStatBox(Histos,legend,true, 0.6, 0.7);
1081     SaveCanvas(c1,output,"ChargeTECThickness");
1082     delete c1;
1083 
1084     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
1085     Histos[0] = ChargeTIDP;                        legend.push_back("TID+");
1086     Histos[1] = ChargeTIDM;                        legend.push_back("TID-");
1087     DrawSuperposedHistos((TH1**)Histos, legend, "",  "Charge [ADC/mm]", "Number of Clusters", 0,800 , 0,0);
1088     DrawLegend(Histos,legend,"","L");
1089     DrawStatBox(Histos,legend,true, 0.6, 0.7);
1090     SaveCanvas(c1,output,"ChargeTIDSide");
1091     delete c1;
1092 
1093     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
1094     Histos[0] = ChargeAbsTEC;                      legend.push_back("TEC");
1095     Histos[1] = ChargeAbsTIB;                      legend.push_back("TIB");
1096     Histos[2] = ChargeAbsTID;                      legend.push_back("TID");
1097     Histos[3] = ChargeAbsTOB;                      legend.push_back("TOB");
1098     DrawSuperposedHistos((TH1**)Histos, legend, "",  "Charge [ADC]", "Number of Clusters", 0,800 , 0,0);
1099     DrawLegend(Histos,legend,"","L");
1100     DrawStatBox(Histos,legend,true, 0.6, 0.7);
1101     SaveCanvas(c1,output,"ChargeAbs");
1102     delete c1;
1103 
1104     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
1105     Histos[0] = ChargeAbsTECP;                     legend.push_back("TEC+");
1106     Histos[1] = ChargeAbsTECM;                     legend.push_back("TEC-");
1107     DrawSuperposedHistos((TH1**)Histos, legend, "",  "Charge [ADC]", "Number of Clusters", 0,800 , 0,0);
1108     DrawLegend(Histos,legend,"","L");
1109     DrawStatBox(Histos,legend,true, 0.6, 0.7);
1110     SaveCanvas(c1,output,"ChargeAbsTECSide");
1111     delete c1;
1112 
1113     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
1114     Histos[0] = ChargeAbsTEC1;                     legend.push_back("TEC Thin");
1115     Histos[1] = ChargeAbsTEC2;                     legend.push_back("TEC Thick");
1116     DrawSuperposedHistos((TH1**)Histos, legend, "",  "Charge [ADC]", "Number of Clusters", 0,800 , 0,0);
1117     DrawLegend(Histos,legend,"","L");
1118     DrawStatBox(Histos,legend,true, 0.6, 0.7);
1119     SaveCanvas(c1,output,"ChargeAbsTECThickness");
1120     delete c1;
1121 
1122     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
1123     Histos[0] = ChargeAbsTIDP;                     legend.push_back("TID+");
1124     Histos[1] = ChargeAbsTIDM;                     legend.push_back("TID-");
1125     DrawSuperposedHistos((TH1**)Histos, legend, "",  "Charge [ADC]", "Number of Clusters", 0,800 , 0,0);
1126     DrawLegend(Histos,legend,"","L");
1127     DrawStatBox(Histos,legend,true, 0.6, 0.7);
1128     SaveCanvas(c1,output,"ChargeAbsTIDSide");
1129     delete c1;
1130 
1131 
1132     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
1133     Histos[0] = MPV_Vs_PathlengthThin;             legend.push_back("320 #mum");
1134     Histos[1] = MPV_Vs_PathlengthThick;            legend.push_back("500 #mum");
1135     DrawSuperposedHistos((TH1**)Histos, legend, "HIST",  "pathlength [mm]", "MPV [ADC/mm]", 0,0 , 230,380);
1136     DrawLegend(Histos,legend,"","L");
1137     SaveCanvas(c1,output,"MPV_Vs_Path");
1138     delete c1;
1139 
1140 
1141     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
1142     Histos[0] = MPV_Vs_PathlengthTIB;              legend.push_back("TIB (320 #mum)");
1143     Histos[1] = MPV_Vs_PathlengthTID;              legend.push_back("TID (320 #mum)");
1144     Histos[2] = MPV_Vs_PathlengthTOB;              legend.push_back("TOB (500 #mum)");
1145     Histos[3] = MPV_Vs_PathlengthTEC1;             legend.push_back("TEC (320 #mum)");
1146     Histos[4] = MPV_Vs_PathlengthTEC2;             legend.push_back("TEC (500 #mum)");
1147     DrawSuperposedHistos((TH1**)Histos, legend, "HIST",  "pathlength [mm]", "MPV [ADC/mm]", 0,0 , 230,380);
1148     DrawLegend(Histos,legend,"","L");
1149     SaveCanvas(c1,output,"MPV_Vs_PathSubDet");
1150     delete c1;
1151 
1152 
1153     c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
1154     Histos[0] = DiffWRTPrevGainTIB;                legend.push_back("TIB");
1155     Histos[1] = DiffWRTPrevGainTID;                legend.push_back("TID");
1156     Histos[2] = DiffWRTPrevGainTOB;                legend.push_back("TOB");
1157     Histos[3] = DiffWRTPrevGainTEC;                legend.push_back("TEC");
1158     DrawSuperposedHistos((TH1**)Histos, legend, "HIST",  "New Gain / Previous Gain", "Number of APV", 0.0,2.0 ,0,0);
1159     DrawLegend(Histos,legend,"","L");
1160     c1->SetLogy(true);
1161     DrawStatBox(Histos,legend,true, 0.6, 0.7);
1162     SaveCanvas(c1,output,"GainDividedPrevGain");
1163     delete c1;
1164 
1165 
1166    c1 = new TCanvas("c1","c1,",600,600);          legend.clear();
1167    Histos[0] = GainVsPrevGainTEC;                 legend.push_back("TEC");
1168    Histos[1] = GainVsPrevGainTIB;                 legend.push_back("TIB");
1169    Histos[2] = GainVsPrevGainTID;                 legend.push_back("TID");
1170    Histos[3] = GainVsPrevGainTOB;                 legend.push_back("TOB");
1171    DrawTH2D((TH2D**)Histos,legend, "", "Previous Gain", "New Gain", 0.5,1.8, 0.5,1.8);
1172    TLine diagonal(0.5,0.5,1.8,1.8);
1173    diagonal.SetLineWidth(3);
1174    diagonal.SetLineStyle(2);
1175    diagonal.Draw("same");
1176    DrawLegend (Histos,legend,"","P");
1177    DrawStatBox(Histos,legend,false);
1178    SaveCanvas(c1,output,"GainVsPrevGain");
1179    delete c1;
1180 
1181 
1182 }
1183 
1184 TF1* getLandau(TH1* InputHisto, double* FitResults, double LowRange, double HighRange)
1185 {
1186    FitResults[0]         = -0.5;  //MPV
1187    FitResults[1]         =  0;    //MPV error
1188    FitResults[2]         = -0.5;  //Width
1189    FitResults[3]         =  0;    //Width error
1190    FitResults[4]         = -0.5;  //Fit Chi2/NDF
1191 
1192    // perform fit with standard landau
1193    TF1* MyLandau = new TF1("MyLandau","landau",LowRange, HighRange);
1194    MyLandau->SetParameter(1,300);
1195    InputHisto->Fit("MyLandau","0QR WW");
1196 
1197    // MPV is parameter 1 (0=constant, 1=MPV, 2=Sigma)
1198    FitResults[0]         = MyLandau->GetParameter(1);  //MPV
1199    FitResults[1]         = MyLandau->GetParError(1);   //MPV error
1200    FitResults[2]         = MyLandau->GetParameter(2);  //Width
1201    FitResults[3]         = MyLandau->GetParError(2);   //Width error
1202    FitResults[4]         = MyLandau->GetChisquare() / MyLandau->GetNDF();  //Fit Chi2/NDF
1203 
1204    return MyLandau;
1205 }
1206 
1207 TH1D* ChargeToMPV(TH2* InputHisto, string Name,  bool DivideByX)
1208 {
1209    TH1D* toReturn = new TH1D(Name.c_str(),Name.c_str(),InputHisto->GetXaxis()->GetNbins(), InputHisto->GetXaxis()->GetXmin(), InputHisto->GetXaxis()->GetXmax() );
1210    double Results[5];
1211 
1212    for(int i=0;i<=InputHisto->GetXaxis()->GetNbins();i++){
1213       TH1D* proj   = InputHisto->ProjectionY("",i,i);
1214       if(proj->GetEntries()<50){delete proj;continue;}
1215 
1216       TF1*  landau = getLandau(proj,Results);
1217 
1218       if(DivideByX){
1219          toReturn->SetBinContent(i,Results[0] / InputHisto->GetXaxis()->GetBinCenter(i) );
1220          toReturn->SetBinError  (i,Results[1] / InputHisto->GetXaxis()->GetBinCenter(i) );
1221       }else{
1222          toReturn->SetBinContent(i,Results[0]);
1223          toReturn->SetBinError  (i,Results[1]);
1224       }
1225       delete landau;
1226      delete proj;
1227    }
1228 
1229    return toReturn;
1230 }
1231 
1232 
1233 bool LoadLumiToRun()
1234 {
1235    float TotalIntLuminosity = 0;
1236 
1237    FILE* pFile = fopen("lumi.txt","r");
1238    if(!pFile){
1239       printf("Not Found: %s\n","out.txt");
1240       return false;
1241    }
1242 
1243    unsigned int Run; float IntLumi;
1244    unsigned int DeliveredLs; double DeliveredLumi;
1245    char Line[2048], Tmp1[2048], Tmp2[2048], Tmp3[2048];
1246    while ( ! feof (pFile) ){
1247      fscanf(pFile,"%s\n",Line);
1248      //printf("%s\n",Line);
1249      for(unsigned int i=0;Line[i]!='\0';i++){if(Line[i]==',')Line[i]=' ';} 
1250      sscanf(Line,"%d:%d %s %s %s %f\n",&Run,&Tmp1, Tmp1,Tmp2,Tmp3,&IntLumi);
1251      TotalIntLuminosity+= IntLumi/1000000000.0;
1252 //     printf("%6i --> %f/fb  (%f)  (%s | %s | %s)\n",Run,IntLumi,TotalIntLuminosity, Tmp1,Tmp2,Tmp3);
1253      RunToIntLumi[Run] = TotalIntLuminosity;
1254    }
1255    fclose(pFile);
1256    return true;
1257 }
1258 
1259 double getLumiFromRun(unsigned int run){
1260    return run; //simply return the run number for now on
1261    int closestRun = 0;  int lastRun=0;
1262    for(std::map<unsigned int, double>::iterator it = RunToIntLumi.begin(); it!=RunToIntLumi.end();it++){
1263       if(it->first>run && abs(it->first-run)<abs(closestRun-run))closestRun = it->first;
1264       if(it->first>lastRun)lastRun=it->first;;
1265    }
1266    if(closestRun==0 && run>RunToIntLumi.begin()->first )closestRun=lastRun;
1267    return RunToIntLumi[closestRun];
1268 }
1269 
1270 
1271