Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 
0002 
0003 #include "TROOT.h"
0004 #include "TFile.h"
0005 #include "TDirectory.h"
0006 #include "TChain.h"
0007 #include "TObject.h"
0008 #include "TCanvas.h"
0009 #include "TMath.h"
0010 #include "TLegend.h"
0011 #include "TGraph.h"
0012 #include "TH1.h"
0013 #include "TH2.h"
0014 #include "TH3.h"
0015 #include "TTree.h"
0016 #include "TF1.h"
0017 #include "TPaveText.h"
0018 #include "PlotFunction.h"
0019 
0020 
0021 #include<vector>
0022 #include<tdrstyle.C>
0023 
0024 void PlotMacro_Core(string input, string input2, string moduleName, string output);
0025 
0026 int DataType = 2;
0027 
0028 void MakeTkMap(){
0029    gROOT->Reset();
0030    setTDRStyle();
0031    gStyle->SetPadTopMargin   (0.05);
0032    gStyle->SetPadBottomMargin(0.10);
0033    gStyle->SetPadRightMargin (0.18);
0034    gStyle->SetPadLeftMargin  (0.13);
0035    gStyle->SetTitleSize(0.04, "XYZ");
0036    gStyle->SetTitleXOffset(1.1);
0037    gStyle->SetTitleYOffset(1.35);
0038    gStyle->SetPalette(1);
0039    gStyle->SetCanvasColor(0);
0040    gStyle->SetBarOffset(0);
0041 
0042    
0043    system("mkdir -p Pictures/Charge");
0044 //   PlotMacro_Core("file:../../Data_Run_247252_to_247990_PCL/Gains_Tree.root", "file:../../Data_Run_247992_to_247992_PCL/Gains_Tree.root", "SiStripCalib"          , "Checks");
0045      PlotMacro_Core("file:../../Data_Run_247992_to_247992_PCL/Gains_Tree.root", "file:../../Data_Run_247992_to_247992_PCL/Gains_Tree.root", "SiStripCalib"          , "Checks");
0046 
0047 }
0048 
0049 
0050 TF1* getPeakOfLandau(TH1* InputHisto, char* name, double LowRange=50, double HighRange=5400)
0051 { 
0052    // perform fit with standard landau
0053    TF1* MyLandau = new TF1(name,"landau",LowRange, HighRange);
0054    MyLandau->SetParameter(1,300);
0055    InputHisto->Fit(MyLandau,"0QR WW");
0056    return MyLandau;
0057 }
0058 
0059 
0060 void PlotMacro_Core(string input, string input2, string moduleName, string output)
0061 {
0062    FILE* pFile;
0063    TCanvas* c1;
0064    TObject** Histos = new TObject*[10];                
0065    std::vector<string> legend;
0066 
0067    unsigned int  tree1_Index;
0068    unsigned int  tree1_DetId;
0069    unsigned char tree1_APVId;
0070    unsigned char tree1_SubDet;
0071    float         tree1_x;
0072    float         tree1_y;
0073    float         tree1_z;
0074    float         tree1_Eta;
0075    float         tree1_R;
0076    float         tree1_Phi;
0077    float         tree1_Thickness;
0078    float         tree1_FitMPV;
0079    float         tree1_FitMPVErr;
0080    float         tree1_FitWidth;
0081    float         tree1_FitWidthErr;
0082    float         tree1_FitChi2NDF;
0083    double        tree1_Gain;
0084    double        tree1_PrevGain;
0085    double        tree1_NEntries;
0086    bool          tree1_isMasked;
0087 
0088 
0089    TFile* f1     = new TFile(input.c_str());
0090    TTree *t1     = (TTree*)GetObjectFromPath(f1,moduleName+"/APVGain");
0091    TH2D* ChargeDistrib1  = (TH2D*)GetObjectFromPath(f1,moduleName+"/Charge_Vs_Index");
0092    t1->SetBranchAddress("Index"             ,&tree1_Index      );
0093    t1->SetBranchAddress("DetId"             ,&tree1_DetId      );
0094    t1->SetBranchAddress("APVId"             ,&tree1_APVId      );
0095    t1->SetBranchAddress("SubDet"            ,&tree1_SubDet     );
0096    t1->SetBranchAddress("x"                 ,&tree1_x          );
0097    t1->SetBranchAddress("y"                 ,&tree1_y          );
0098    t1->SetBranchAddress("z"                 ,&tree1_z          );
0099    t1->SetBranchAddress("Eta"               ,&tree1_Eta        );
0100    t1->SetBranchAddress("R"                 ,&tree1_R          );
0101    t1->SetBranchAddress("Phi"               ,&tree1_Phi        );
0102    t1->SetBranchAddress("Thickness"         ,&tree1_Thickness  );
0103    t1->SetBranchAddress("FitMPV"            ,&tree1_FitMPV     );
0104    t1->SetBranchAddress("FitMPVErr"         ,&tree1_FitMPVErr  );
0105    t1->SetBranchAddress("FitWidth"          ,&tree1_FitWidth   );
0106    t1->SetBranchAddress("FitWidthErr"       ,&tree1_FitWidthErr);
0107    t1->SetBranchAddress("FitChi2NDF"        ,&tree1_FitChi2NDF );
0108    t1->SetBranchAddress("Gain"              ,&tree1_Gain       );
0109    t1->SetBranchAddress("PrevGain"          ,&tree1_PrevGain   );
0110    t1->SetBranchAddress("NEntries"          ,&tree1_NEntries   );
0111    t1->SetBranchAddress("isMasked"          ,&tree1_isMasked   );
0112 
0113    pFile = fopen("TkMap.txt","w");
0114 
0115    unsigned int PreviousId = 0;
0116    unsigned int NAPV       = 0;
0117    double       MPV1       = 0;
0118    double Min=9999, Max=-9999, Mean=0;
0119  
0120    printf("Progressing Bar              :0%%       20%%       40%%       60%%       80%%       100%%\n");
0121    printf("Looping on the Tree          :");
0122    int TreeStep = t1->GetEntries()/50;if(TreeStep==0)TreeStep=1;
0123    for (unsigned int ientry = 0; ientry < t1->GetEntries(); ientry++) {
0124       if(ientry%TreeStep==0){printf(".");fflush(stdout);}
0125       t1->GetEntry(ientry);
0126 
0127       if(tree1_APVId==0 && PreviousId>0){
0128          double Mean = MPV1/NAPV;
0129          if(Mean<Min)Min=Mean;
0130          if(Mean>Max)Max=Mean;
0131          if(NAPV>0) fprintf(pFile,"%i  %f\n",PreviousId,Mean);
0132          NAPV=0; MPV1=0;
0133       }
0134       PreviousId = tree1_DetId;
0135       if(tree1_FitMPV<=0)continue;
0136       NAPV++;
0137       MPV1+=tree1_FitMPV;
0138    }printf("\n");
0139    fclose(pFile);
0140 
0141    printf("Min=%f - Max=%f\n",Min,Max);
0142 }