Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 
0002 
0003 #include "TROOT.h"
0004 #include "TFile.h"
0005 #include "TDirectory.h"
0006 #include "TChain.h"
0007 #include "TObject.h"
0008 #include "TTree.h"
0009 #include "TROOT.h"
0010 #include "TFile.h"
0011 #include "TDirectory.h"
0012 #include "TChain.h"
0013 #include "TObject.h"
0014 #include "TCanvas.h"
0015 #include "TMath.h"
0016 #include "TLegend.h"
0017 #include "TGraph.h"
0018 #include "TH1.h"
0019 #include "TH2.h"
0020 #include "TH3.h"
0021 #include "TTree.h"
0022 #include "TF1.h"
0023 #include "TPaveText.h"
0024 
0025 #include<vector>
0026 
0027 #if !defined(__CINT__) && !defined(__MAKECINT__)
0028 #include "DataFormats/FWLite/interface/Handle.h"
0029 #include "DataFormats/FWLite/interface/Event.h"
0030 #include "DataFormats/FWLite/interface/ChainEvent.h"
0031 
0032 #include "CommonTools/TrackerMap/interface/TrackerMap.h"
0033 
0034 using namespace fwlite;
0035 using namespace std;
0036 using namespace edm;
0037 #endif
0038 
0039 
0040 
0041 
0042 void tkMap(string TextToPrint_="CMS Preliminary 2015"){
0043 
0044 }
0045 
0046 
0047 void MakeAsciiFileFromTree(){
0048    string inputFileTree = "../../Data_Run_251252_to_251252_PCL/Gains_Tree.root"; 
0049    string moduleName = "SiStripCalib";
0050 
0051    unsigned int  tree1_Index;
0052    unsigned int  tree1_DetId;
0053    unsigned char tree1_APVId;
0054    double        tree1_Gain;
0055    double        tree1_PrevGain;
0056 
0057    TFile* f1     = new TFile(inputFileTree.c_str());
0058 //   TTree *t1     = (TTree*)GetObjectFromPath(f1,moduleName+"/APVGain");
0059    TTree *t1     = (TTree*)f1->Get((moduleName+"/APVGain").c_str());
0060 
0061 
0062    t1->SetBranchAddress("Index"             ,&tree1_Index      );
0063    t1->SetBranchAddress("DetId"             ,&tree1_DetId      );
0064    t1->SetBranchAddress("APVId"             ,&tree1_APVId      );
0065    t1->SetBranchAddress("Gain"              ,&tree1_Gain       );
0066    t1->SetBranchAddress("PrevGain"          ,&tree1_PrevGain   );
0067 
0068 
0069 
0070    //read gain modified from a txt file
0071    std::map<unsigned int, double> gainModifiers;
0072    FILE* inFile = fopen("GainRatio.txt","r");
0073    char line[4096];
0074    while(fgets(line, 4096, inFile)!=NULL){
0075       unsigned int detId;  double modifier;
0076       sscanf(line, "%u %lf", &detId, &modifier);
0077       printf("(%i , %f) \t", detId, modifier);
0078       gainModifiers[detId] = modifier;
0079    }
0080    fclose(inFile);
0081    
0082 
0083    TrackerMap* tkmap = new TrackerMap("  ParticleGain  ");
0084 
0085    FILE* pFile = fopen("Gains_ASCII.txt","w");
0086 
0087    int PreviousId = -1;
0088    printf("Progressing Bar              :0%%       20%%       40%%       60%%       80%%       100%%\n");
0089    printf("Looping on the Tree          :");
0090    int TreeStep = t1->GetEntries()/50;if(TreeStep==0)TreeStep=1;
0091    std::vector<double> gains;
0092    for (unsigned int ientry = 0; ientry < t1->GetEntries(); ientry++) {
0093       if(ientry%TreeStep==0){printf(".");fflush(stdout);}
0094       t1->GetEntry(ientry);
0095 
0096       if((tree1_APVId==0 && PreviousId>0) || ientry==t1->GetEntries()-1){  //new module or very last APV
0097          fprintf(pFile,"%i ",PreviousId); for(unsigned int i=0;i<gains.size();i++){fprintf(pFile,"%f ", gains[i]);}   fprintf(pFile, "\n");
0098          gains.clear();
0099       }
0100       PreviousId = tree1_DetId;
0101 
0102       double modifier = 1.0;
0103       if(gainModifiers.find(tree1_DetId)!=gainModifiers.end()){modifier = gainModifiers[tree1_DetId]; }
0104       gains.push_back(tree1_Gain * modifier);
0105 
0106       if(tree1_APVId==0 and modifier!=1.000){tkmap->fill(tree1_DetId, modifier); }
0107 
0108    }printf("\n");
0109    fclose(pFile);
0110 
0111    tkmap->setTitle("Gain: Predicted/Current    (white=unmodified)");
0112    tkmap->save(true, 1.0, 1.2, "tkMap.png");
0113    tkmap->reset();    
0114 
0115 }