Fork me on GitHub

Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • examples/CaloGrid.cpp

    r77e9ae1 rfed00d2  
    11//calorimeter grid
    2 #include <algorithm>
    3 #include <cassert>
    4 #include <iostream>
     2#include <set>
    53#include <map>
    6 #include <set>
    7 #include <sstream>
    84#include <utility>
    95#include <vector>
     6#include <algorithm>
     7#include <sstream>
     8#include <iostream>
     9#include <cassert>
    1010
     11#include "display/Delphes3DGeometry.h"
     12#include "classes/DelphesClasses.h"
    1113#include "ExRootAnalysis/ExRootConfReader.h"
    12 #include "classes/DelphesClasses.h"
    13 #include "display/Delphes3DGeometry.h"
    1414
    1515#include "TCanvas.h"
     16#include "TStyle.h"
     17#include "TString.h"
     18#include "TText.h"
    1619#include "TH2F.h"
    1720#include "TLine.h"
    18 #include "TString.h"
    19 #include "TStyle.h"
    20 #include "TText.h"
    2121
    2222using namespace std;
     
    2828{
    2929
    30   if(argc != 3)
    31   {
    32     cout << " Usage: ./CaloGrid [detector card] [calo name]" << endl;
    33     cout << "Example: ./CaloGrid cards/delphes_card_CMS.tcl ECal" << endl;
    34     return 0;
    35   }
     30 if(argc !=3)
     31 {
     32  cout << " Usage: ./CaloGrid [detector card] [calo name]"<<endl;
     33  cout<< "Example: ./CaloGrid cards/delphes_card_CMS.tcl ECal" <<endl;
     34  return 0;
     35 }
    3636
    3737  TString card(argv[1]);
     
    3939  ExRootConfReader *confReader = new ExRootConfReader;
    4040  confReader->ReadFile(card);
     41 
     42  std::vector<std::string> calorimeters_;
     43  std::map<std::string, std::set< std::pair<Double_t, Int_t> > > caloBinning_;
     44   
     45  std::string s(argv[2]);
     46  std::replace( s.begin(), s.end(), ',', ' ' );
     47  std::istringstream stream( s );
     48  std::string word;
     49  while (stream >> word) calorimeters_.push_back(word);
    4150
    42   std::vector<std::string> calorimeters_;
    43   std::map<std::string, std::set<std::pair<Double_t, Int_t> > > caloBinning_;
     51  caloBinning_.clear();                                                         // calo binning
    4452
    45   std::string s(argv[2]);
    46   std::replace(s.begin(), s.end(), ',', ' ');
    47   std::istringstream stream(s);
    48   std::string word;
    49   while(stream >> word) calorimeters_.push_back(word);
    50 
    51   caloBinning_.clear(); // calo binning
    52 
    53   TCanvas c("", "", 1600, 838);
    54 
    55   gPad->SetLeftMargin(0.16);
    56   gPad->SetTopMargin(0.16);
    57   gPad->SetBottomMargin(0.20);
     53  TCanvas c("","",1600,838);
     54   
     55  gPad->SetLeftMargin(0.16) ;
     56  gPad->SetTopMargin(0.16) ;
     57  gPad->SetBottomMargin(0.20) ;
    5858  gStyle->SetOptStat(0000000);
    59 
     59 
    6060  gStyle->SetTextFont(132);
    61 
     61   
    6262  TH2F h2("h2", "", 1, -6, 6, 1, 0, 6.28);
    6363
     
    7171  h2.GetYaxis()->SetLabelFont(132);
    7272
    73   h2.GetXaxis()->SetTitleOffset(1.4);
    74   h2.GetYaxis()->SetTitleOffset(1.1);
    75   h2.GetXaxis()->SetLabelOffset(0.02);
    76   h2.GetYaxis()->SetLabelOffset(0.02);
    77   h2.GetXaxis()->SetTitleSize(0.06);
    78   h2.GetYaxis()->SetTitleSize(0.06);
    79   h2.GetXaxis()->SetLabelSize(0.06);
    80   h2.GetYaxis()->SetLabelSize(0.06);
     73  h2.GetXaxis()->SetTitleOffset(1.4) ;
     74  h2.GetYaxis()->SetTitleOffset(1.1) ;
     75  h2.GetXaxis()->SetLabelOffset(0.02) ;
     76  h2.GetYaxis()->SetLabelOffset(0.02) ;
     77  h2.GetXaxis()->SetTitleSize(0.06) ;
     78  h2.GetYaxis()->SetTitleSize(0.06) ;
     79  h2.GetXaxis()->SetLabelSize(0.06) ;
     80  h2.GetYaxis()->SetLabelSize(0.06) ;
     81 
     82  h2.GetXaxis()->SetTickLength(0.0) ;
     83  h2.GetYaxis()->SetTickLength(0.0) ;
    8184
    82   h2.GetXaxis()->SetTickLength(0.0);
    83   h2.GetYaxis()->SetTickLength(0.0);
    84 
    85   h2.Draw();
    86 
    87   // fake loop just keeping it for convenience right now
    88   for(std::vector<std::string>::const_iterator calo = calorimeters_.begin(); calo != calorimeters_.end(); ++calo)
    89   {
    90 
     85 
     86  h2.Draw(); 
     87 
     88   // fake loop just keeping it for convenience right now
     89  for(std::vector<std::string>::const_iterator calo=calorimeters_.begin();calo!=calorimeters_.end(); ++calo) {
     90 
    9191    //first entry is eta bin, second is number of phi bins
    92     set<pair<Double_t, Int_t> > caloBinning;
     92    set< pair<Double_t, Int_t> > caloBinning;
    9393    ExRootConfParam paramEtaBins, paramPhiBins;
    94     ExRootConfParam param = confReader->GetParam(Form("%s::EtaPhiBins", calo->c_str()));
     94    ExRootConfParam param = confReader->GetParam(Form("%s::EtaPhiBins",calo->c_str()));
    9595    Int_t size = param.GetSize();
    96 
    97     for(int i = 0; i < size / 2; ++i)
    98     {
    99       paramEtaBins = param[i * 2];
    100       paramPhiBins = param[i * 2 + 1];
    101       assert(paramEtaBins.GetSize() == 1);
    102 
    103       caloBinning.insert(std::make_pair(paramEtaBins[0].GetDouble(), paramPhiBins.GetSize() - 1));
     96   
     97    for(int i = 0; i < size/2; ++i) {
     98      paramEtaBins = param[i*2];
     99      paramPhiBins = param[i*2+1];
     100      assert(paramEtaBins.GetSize()==1);
     101     
     102      caloBinning.insert(std::make_pair(paramEtaBins[0].GetDouble(),paramPhiBins.GetSize()-1));
    104103    }
    105104    caloBinning_[*calo] = caloBinning;
    106 
    107     TLine *liney;
    108     TLine *linex;
    109 
    110     //loop over calo binning
    111     std::set<std::pair<Double_t, Int_t> >::iterator it;
    112 
    113     Int_t n = -1;
    114     for(it = caloBinning.begin(); it != caloBinning.end(); ++it)
     105 
     106  TLine *liney;
     107  TLine *linex;
     108 
     109  //loop over calo binning
     110  std::set<std::pair<Double_t, Int_t> >::iterator it;
     111 
     112  Int_t n = -1;
     113  for (it = caloBinning.begin(); it != caloBinning.end(); ++it)
     114  {
     115    n++;
     116   
     117    if(debug)cout<<"-----------------------"<<endl;
     118    if(debug)cout<<it->first<<","<<it->second<<endl;
     119    liney = new TLine(it->first,0,it->first,6.28);
     120    liney->SetLineColor(kRed+3);
     121    liney->Draw();
     122   
     123    set<std::pair<Double_t, Int_t> >::iterator it2 = it;
     124    it2--;
     125           
     126    for(int j = 0; j <= it->second; j++)
    115127    {
    116       n++;
    117 
    118       if(debug) cout << "-----------------------" << endl;
    119       if(debug) cout << it->first << "," << it->second << endl;
    120       liney = new TLine(it->first, 0, it->first, 6.28);
    121       liney->SetLineColor(kRed + 3);
    122       liney->Draw();
    123 
    124       set<std::pair<Double_t, Int_t> >::iterator it2 = it;
    125       it2--;
    126 
    127       for(int j = 0; j <= it->second; j++)
    128       {
    129 
    130         Double_t yval0 = 0 + 6.28 * j / it->second;
    131 
    132         if(debug) cout << it2->first << "," << yval0 << "," << it->first << "," << yval0 << endl;
    133 
    134         linex = new TLine(it->first, yval0, it2->first, yval0);
    135         linex->SetLineColor(kRed + 3);
    136         linex->Draw();
    137       }
    138     }
     128     
     129      Double_t yval0 = 0 + 6.28 * j / it->second;
     130     
     131      if(debug) cout<<it2->first<<","<<yval0<<","<<it->first<<","<<yval0<<endl;
     132     
     133      linex = new TLine(it->first,yval0,it2->first,yval0);
     134      linex->SetLineColor(kRed+3);
     135      linex->Draw();
     136         
     137    }
     138   
     139 
     140  }
     141 
     142 
    139143  }
    140144
    141145  TString text = TString(s);
    142   TText *th1 = new TText(5.00, 6.45, text);
    143   th1->SetTextAlign(31);
    144   th1->SetTextFont(132);
     146  TText *th1 = new TText(5.00,6.45,text);
     147  th1->SetTextAlign(31); 
     148  th1->SetTextFont(132); 
    145149  th1->SetTextSize(0.075);
    146150  th1->Draw();
    147151
     152
    148153  TString output = TString(s);
    149   c.Print(output + ".png", "png");
    150   c.Print(output + ".pdf", "pdf");
     154  c.Print(output+".png","png");
     155  c.Print(output+".pdf","pdf");
     156 
    151157}
Note: See TracChangeset for help on using the changeset viewer.