Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include <vector>
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 
0019 
0020 #include "DataFormats/SiStripDetId/interface/SiStripDetId.h"
0021 
0022 void MakeMap()
0023 {
0024    double P_Min               = 1;
0025    double P_Max               = 15;
0026    int    P_NBins             = 14  ;
0027    double Path_Min            = 0.2 ;
0028    double Path_Max            = 1.6 ;
0029    int    Path_NBins          = 42  ;
0030    double Charge_Min          = 0   ;
0031    double Charge_Max          = 5000;
0032    int    Charge_NBins        = 500 ;
0033 
0034    TH3F* Charge_Vs_Path = new TH3F ("Charge_Vs_Path"     , "Charge_Vs_Path" , P_NBins, P_Min, P_Max, Path_NBins, Path_Min, Path_Max, Charge_NBins, Charge_Min, Charge_Max);
0035 
0036 
0037 
0038    ///////////////////////////////////////// MAKE MAP OF GAINS
0039    std::map<unsigned int,double> Gains;
0040    TChain* t1 = new TChain("SiStripCalib/APVGain");
0041    t1->Add("file:Gains.root");
0042 
0043    unsigned int  tree_DetId;
0044    unsigned char tree_APVId;
0045    double        tree_Gain;
0046 
0047    t1->SetBranchAddress("DetId"             ,&tree_DetId      );
0048    t1->SetBranchAddress("APVId"             ,&tree_APVId      );
0049    t1->SetBranchAddress("Gain"              ,&tree_Gain       );
0050 
0051    for (unsigned int ientry = 0; ientry < t1->GetEntries(); ientry++) {
0052        t1->GetEntry(ientry);
0053        Gains[tree_DetId<<3 | tree_APVId] = tree_Gain;
0054    }
0055    /////////////////////////////////////////
0056 
0057    vector<string> VInputFiles;
0058    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_190645.root");       //size = 1727.02MB
0059    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_190646.root");       //size = 1863.46MB
0060    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_190659.root");       //size = 2661.59MB
0061    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_190661.root");       //size = 6034.83MB
0062    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_190663.root");       //size = 1668.16MB
0063    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_190678.root");       //size = 9927.4MB
0064    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_190679.root");       //size = 913.426MB
0065    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_190688.root");       //size = 4128.89MB
0066    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_190702.root");       //size = 1996.21MB
0067    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_190703.root");       //size = 4408.31MB
0068    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_190705.root");       //size = 7187.65MB
0069    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_190706.root");       //size = 2186.41MB
0070    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_190707.root");       //size = 5083.74MB
0071    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_190708.root");       //size = 2683.04MB
0072    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_190733.root");       //size = 7182.07MB
0073    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_190736.root");       //size = 3222.12MB
0074    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_190738.root");       //size = 5912.86MB
0075    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_190782.root");       //size = 7974.95MB
0076    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_190895.root");       //size = 15331.2MB
0077    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_190906.root");       //size = 7652.26MB
0078    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_190945.root");       //size = 1562.03MB
0079 //   VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_190949.root");       //size = 8016.04MB
0080    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_191046.root");       //size = 4838.85MB
0081    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_191056.root");       //size = 97.7042MB
0082    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_191057.root");       //size = 1283.01MB
0083    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_191062.root");       //size = 10698.4MB
0084    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_191086.root");       //size = 9208.68MB
0085    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_191090.root");       //size = 2663.71MB
0086    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_191201.root");       //size = 899.183MB
0087    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_191202.root");       //size = 1975.63MB
0088    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_191226.root");       //size = 30174.2MB
0089    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_191247.root");       //size = 23016.2MB
0090 //   VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_191248.root");       //size = 1653.05MB
0091    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_191264.root");       //size = 2810.84MB
0092 //   VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_191271.root");       //size = 6688.46MB
0093    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_191276.root");       //size = 256.78MB
0094    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_191277.root");       //size = 16743.7MB
0095    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_191367.root");       //size = 56.7291MB
0096    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_191691.root");       //size = 193.001MB
0097    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_191692.root");       //size = 522.558MB
0098    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_191694.root");       //size = 849.879MB
0099 //   VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_191700.root");       //size = 12765.5MB
0100    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_191701.root");       //size = 2647.48MB
0101 //   VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_191718.root");       //size = 3851.63MB
0102    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_191720.root");       //size = 3203.27MB
0103    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_191721.root");       //size = 3108.56MB
0104    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_191726.root");       //size = 171.324MB
0105    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_191800.root");       //size = 901.921MB
0106    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_191810.root");       //size = 1926.16MB
0107    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_191811.root");       //size = 2952.6MB
0108    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_191830.root");       //size = 7499.53MB
0109    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_191833.root");       //size = 2139.62MB
0110    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_191834.root");       //size = 7184.75MB
0111    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_191837.root");       //size = 1212.49MB
0112    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_191839.root");       //size = 653.932MB
0113    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_191842.root");       //size = 264.614MB
0114    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_191845.root");       //size = 460.653MB
0115    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_191849.root");       //size = 877.692MB
0116    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_191856.root");       //size = 2393.8MB
0117    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_191857.root");       //size = 483.061MB
0118    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_191858.root");       //size = 809.952MB
0119    VInputFiles.push_back("rfio:/castor/cern.ch/user/m/mgalanti/calibrationtree/GR12//calibTree_191859.root");       //size = 2158.63MB
0120 
0121 
0122    TString EventPrefix("");
0123    TString EventSuffix("");
0124 
0125    TString TrackPrefix("track");
0126    TString TrackSuffix("");
0127 
0128    TString CalibPrefix("GainCalibration");
0129    TString CalibSuffix("");
0130  
0131 
0132    for(unsigned int i=0;i<VInputFiles.size();i++){
0133       printf("Openning file %3i/%3i --> %s\n",i+1, (int)VInputFiles.size(), (char*)(VInputFiles[i].c_str())); fflush(stdout);
0134       TChain* tree = new TChain("gainCalibrationTree/tree");
0135       tree->Add(VInputFiles[i].c_str());
0136 
0137       unsigned int                 eventnumber    = 0;    tree->SetBranchAddress(EventPrefix + "event"          + EventSuffix, &eventnumber   , NULL);
0138       unsigned int                 runnumber      = 0;    tree->SetBranchAddress(EventPrefix + "run"            + EventSuffix, &runnumber     , NULL);
0139       std::vector<bool>*           trigtech       = 0;    tree->SetBranchAddress(EventPrefix + "TrigTech"       + EventSuffix, &trigtech      , NULL); 
0140 
0141       std::vector<double>*         trackchi2ndof  = 0;    tree->SetBranchAddress(TrackPrefix + "chi2ndof"       + TrackSuffix, &trackchi2ndof , NULL);
0142       std::vector<float>*          trackp         = 0;    tree->SetBranchAddress(TrackPrefix + "momentum"       + TrackSuffix, &trackp        , NULL);
0143       std::vector<float>*          trackpt        = 0;    tree->SetBranchAddress(TrackPrefix + "pt"             + TrackSuffix, &trackpt       , NULL);
0144       std::vector<unsigned int>*   trackhitsvalid = 0;    tree->SetBranchAddress(TrackPrefix + "hitsvalid"      + TrackSuffix, &trackhitsvalid, NULL);
0145 
0146       std::vector<int>*            trackindex     = 0;    tree->SetBranchAddress(CalibPrefix + "trackindex"     + CalibSuffix, &trackindex    , NULL);
0147       std::vector<unsigned int>*   rawid          = 0;    tree->SetBranchAddress(CalibPrefix + "rawid"          + CalibSuffix, &rawid         , NULL);
0148       std::vector<unsigned short>* firststrip     = 0;    tree->SetBranchAddress(CalibPrefix + "firststrip"     + CalibSuffix, &firststrip    , NULL);
0149       std::vector<unsigned short>* nstrips        = 0;    tree->SetBranchAddress(CalibPrefix + "nstrips"        + CalibSuffix, &nstrips       , NULL);
0150       std::vector<unsigned int>*   charge         = 0;    tree->SetBranchAddress(CalibPrefix + "charge"         + CalibSuffix, &charge        , NULL);
0151       std::vector<float>*          path           = 0;    tree->SetBranchAddress(CalibPrefix + "path"           + CalibSuffix, &path          , NULL);
0152       std::vector<unsigned char>*  amplitude      = 0;    tree->SetBranchAddress(CalibPrefix + "amplitude"      + CalibSuffix, &amplitude     , NULL);
0153 
0154       int TreeStep = tree->GetEntries()/50;if(TreeStep==0)TreeStep=1;
0155       for (unsigned int ientry = 0; ientry < tree->GetEntries(); ientry++) {
0156          if(ientry%TreeStep==0){printf(".");fflush(stdout);}
0157          tree->GetEntry(ientry);
0158 
0159          int FirstAmplitude = 0;
0160          for(unsigned int c=0;c<(*path).size();c++){
0161             FirstAmplitude+=(*nstrips)[c];
0162             int t = (*trackindex)[c];
0163             if((*trackpt)[t]<5)continue;
0164             if((*trackhitsvalid)[t]<5)continue;
0165 
0166             int Charge = 0;
0167             for(unsigned int s=0;s<(*nstrips)[c];s++){
0168               int StripCharge =  (*amplitude)[FirstAmplitude-(*nstrips)[c]+s];
0169               if(StripCharge<254){
0170                  StripCharge=(int)(StripCharge/Gains[(*rawid)[c]<<3 | (*firststrip)[c]/128]);
0171                  if(StripCharge>=1024){
0172                     StripCharge = 255;
0173                  }else if(StripCharge>=254){
0174                     StripCharge = 254;
0175                  }
0176               }
0177               Charge += StripCharge;
0178             }
0179 //          printf("ChargeDifference = %i Vs %i with Gain = %f\n",(*charge)[c],Charge,Gains[(*rawid)[c]]);
0180             double ClusterChargeOverPath   =  ( (double) Charge )/(*path)[c] ;       
0181 
0182 
0183 
0184         SiStripDetId SSdetId((*rawid)[c]);
0185             //printf("ModuleGeometry = %i\n",SSdetId.moduleGeometry());
0186 
0187 
0188 
0189 
0190 //            Charge_Vs_Path->Fill((*trackp)[t],(*path)[c],ClusterChargeOverPath);
0191             Charge_Vs_Path->Fill(SSdetId.moduleGeometry(),(*path)[c],ClusterChargeOverPath);
0192          }
0193       }printf("\n");
0194    }printf("\n");
0195 
0196    TFile * out = new TFile("ProbaMap.root", "RECREATE");
0197    Charge_Vs_Path->Write();
0198    out->Write();
0199    out->Close();
0200    delete out;
0201 
0202 }
0203 
0204 
0205 
0206 
0207 
0208