Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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 MakeChargeDistribution(){
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 Pictures");
0044    PlotMacro_Core("file:../7TeVData_170249_to_170901/Gains_Tree.root", "file:../7TeVData/Gains_Tree.root", "SiStripCalib"          , "Checks");
0045 }
0046 
0047 
0048 void PlotMacro_Core(string input, string input2, string moduleName, string output)
0049 {
0050    FILE* pFile;
0051    TCanvas* c1;
0052    TObject** Histos = new TObject*[10];                
0053    std::vector<string> legend;
0054 
0055    unsigned int  tree1_Index;
0056    unsigned int  tree1_DetId;
0057    unsigned char tree1_APVId;
0058    unsigned char tree1_SubDet;
0059    float         tree1_x;
0060    float         tree1_y;
0061    float         tree1_z;
0062    float         tree1_Eta;
0063    float         tree1_R;
0064    float         tree1_Phi;
0065    float         tree1_Thickness;
0066    float         tree1_FitMPV;
0067    float         tree1_FitMPVErr;
0068    float         tree1_FitWidth;
0069    float         tree1_FitWidthErr;
0070    float         tree1_FitChi2NDF;
0071    double        tree1_Gain;
0072    double        tree1_PrevGain;
0073    double        tree1_NEntries;
0074    bool          tree1_isMasked;
0075 
0076 
0077    unsigned int  tree2_Index;
0078    unsigned int  tree2_DetId;
0079    unsigned char tree2_APVId;
0080    unsigned char tree2_SubDet;
0081    float         tree2_x;
0082    float         tree2_y;
0083    float         tree2_z;
0084    float         tree2_Eta;
0085    float         tree2_R;
0086    float         tree2_Phi;
0087    float         tree2_Thickness;
0088    float         tree2_FitMPV;
0089    float         tree2_FitMPVErr;
0090    float         tree2_FitWidth;
0091    float         tree2_FitWidthErr;
0092    float         tree2_FitChi2NDF;
0093    double        tree2_Gain;
0094    double        tree2_PrevGain;
0095    double        tree2_NEntries;
0096    bool          tree2_isMasked;
0097 
0098 
0099    TFile* f1     = new TFile(input.c_str());
0100    TTree *t1     = (TTree*)GetObjectFromPath(f1,moduleName+"/APVGain");
0101 
0102    t1->SetBranchAddress("Index"             ,&tree1_Index      );
0103    t1->SetBranchAddress("DetId"             ,&tree1_DetId      );
0104    t1->SetBranchAddress("APVId"             ,&tree1_APVId      );
0105    t1->SetBranchAddress("SubDet"            ,&tree1_SubDet     );
0106    t1->SetBranchAddress("x"                 ,&tree1_x          );
0107    t1->SetBranchAddress("y"                 ,&tree1_y          );
0108    t1->SetBranchAddress("z"                 ,&tree1_z          );
0109    t1->SetBranchAddress("Eta"               ,&tree1_Eta        );
0110    t1->SetBranchAddress("R"                 ,&tree1_R          );
0111    t1->SetBranchAddress("Phi"               ,&tree1_Phi        );
0112    t1->SetBranchAddress("Thickness"         ,&tree1_Thickness  );
0113    t1->SetBranchAddress("FitMPV"            ,&tree1_FitMPV     );
0114    t1->SetBranchAddress("FitMPVErr"         ,&tree1_FitMPVErr  );
0115    t1->SetBranchAddress("FitWidth"          ,&tree1_FitWidth   );
0116    t1->SetBranchAddress("FitWidthErr"       ,&tree1_FitWidthErr);
0117    t1->SetBranchAddress("FitChi2NDF"        ,&tree1_FitChi2NDF );
0118    t1->SetBranchAddress("Gain"              ,&tree1_Gain       );
0119    t1->SetBranchAddress("PrevGain"          ,&tree1_PrevGain   );
0120    t1->SetBranchAddress("NEntries"          ,&tree1_NEntries   );
0121    t1->SetBranchAddress("isMasked"          ,&tree1_isMasked   );
0122 
0123 
0124    TFile* f2     = new TFile(input2.c_str());
0125    TTree *t2     = (TTree*)GetObjectFromPath(f2,moduleName+"/APVGain");
0126 
0127    t2->SetBranchAddress("Index"             ,&tree2_Index      );
0128    t2->SetBranchAddress("DetId"             ,&tree2_DetId      );
0129    t2->SetBranchAddress("APVId"             ,&tree2_APVId      ); 
0130    t2->SetBranchAddress("SubDet"            ,&tree2_SubDet     );
0131    t2->SetBranchAddress("x"                 ,&tree2_x          ); 
0132    t2->SetBranchAddress("y"                 ,&tree2_y          );
0133    t2->SetBranchAddress("z"                 ,&tree2_z          );
0134    t2->SetBranchAddress("Eta"               ,&tree2_Eta        ); 
0135    t2->SetBranchAddress("R"                 ,&tree2_R          ); 
0136    t2->SetBranchAddress("Phi"               ,&tree2_Phi        );
0137    t2->SetBranchAddress("Thickness"         ,&tree2_Thickness  ); 
0138    t2->SetBranchAddress("FitMPV"            ,&tree2_FitMPV     ); 
0139    t2->SetBranchAddress("FitMPVErr"         ,&tree2_FitMPVErr  ); 
0140    t2->SetBranchAddress("FitWidth"          ,&tree2_FitWidth   );
0141    t2->SetBranchAddress("FitWidthErr"       ,&tree2_FitWidthErr);
0142    t2->SetBranchAddress("FitChi2NDF"        ,&tree2_FitChi2NDF ); 
0143    t2->SetBranchAddress("Gain"              ,&tree2_Gain       );
0144    t2->SetBranchAddress("PrevGain"          ,&tree2_PrevGain   );
0145    t2->SetBranchAddress("NEntries"          ,&tree2_NEntries   );
0146    t2->SetBranchAddress("isMasked"          ,&tree2_isMasked   ); 
0147 
0148    pFile = fopen("GainDiff.txt","w");
0149 
0150    unsigned int PreviousId = 0;
0151    unsigned int NAPV       = 0;
0152    double       MPV1       = 0;
0153    double       MPV2       = 0;
0154 
0155    double Min = 10000;
0156    double Max =-10000;
0157 
0158    printf("Progressing Bar              :0%%       20%%       40%%       60%%       80%%       100%%\n");
0159    printf("Looping on the Tree          :");
0160    int TreeStep = t1->GetEntries()/50;if(TreeStep==0)TreeStep=1;
0161    for (unsigned int ientry = 0; ientry < t1->GetEntries(); ientry++) {
0162       if(ientry%TreeStep==0){printf(".");fflush(stdout);}
0163       t1->GetEntry(ientry);
0164       t2->GetEntry(ientry);
0165 
0166       if(tree1_APVId==0 && PreviousId>0){
0167          double Mean = (MPV2-MPV1)/NAPV;
0168          if(Mean<Min)Min=Mean;
0169          if(Mean>Max)Max=Mean;
0170          if(NAPV>0) fprintf(pFile,"%i  %f\n",PreviousId,Mean);
0171          NAPV=0; MPV1=0; MPV2=0;
0172          exit(0);
0173       }
0174       PreviousId = tree1_DetId;
0175       if(tree1_FitMPV<=0 || tree2_FitMPV<=0)continue;
0176       NAPV++;
0177       MPV1+=tree1_FitMPV;
0178       MPV2+=tree2_FitMPV;
0179    }printf("\n");
0180    fclose(pFile);
0181 
0182    printf("Min=%f - Max=%f\n",Min,Max);
0183 
0184 }