00001 #include "emcDSTHistogrammer.h"
00002 #include "ezdst.h"
00003 #include <iostream>
00004 #include "emcClusterContainer.h"
00005 #include "emcClusterContent.h"
00006 #include "emcTowerContainer.h"
00007 #include "emcTowerContent.h"
00008 #include "emcObjectFillerManager.h"
00009 #include <map>
00010 #include <string>
00011 #include "TH1.h"
00012 #include "TH2.h"
00013 #include "TFile.h"
00014 #include "EmcIndexer.h"
00015 #include <sstream>
00016 #include "TROOT.h"
00017 #include <cassert>
00018
00019 using namespace std;
00020
00021 namespace
00022 {
00023 typedef map<string,TH1*> MAP;
00024 static vector<MAP> histos;
00025
00026 }
00027
00028
00029 void histogram(const emcTowerContainer& tc)
00030 {
00031 for ( size_t i = 0; i < tc.size(); ++i )
00032 {
00033 emcTowerContent* t = tc.getTower(i);
00034 assert(t!=0);
00035 int towerID = t->TowerID();
00036 int iS,x,y;
00037 EmcIndexer::decodeTowerId(towerID,iS,x,y);
00038 histos[iS]["tenergy"]->Fill(t->Energy());
00039 histos[iS]["ttof"]->Fill(t->ToF());
00040 }
00041 }
00042
00043
00044 void histogram(const emcClusterContainer& cc)
00045 {
00046 for ( size_t i = 0; i < cc.size(); ++i )
00047 {
00048 emcClusterContent* c = cc.getCluster(i);
00049 assert(c!=0);
00050 int iS = EmcIndexer::sectorOfflineToOnline(c->arm(),c->sector());
00051 assert(iS>=0&&iS<8);
00052 histos[iS]["cenergy"]->Fill(c->e());
00053 histos[iS]["ctof"]->Fill(c->tof());
00054 }
00055 }
00056
00057
00058 void makeHistoMap()
00059 {
00060 for ( size_t i = 0; i < 8; ++i )
00061 {
00062 MAP m;
00063 string name;
00064 string title;
00065
00066 double emax = 25.6;
00067 int nebins = 512;
00068
00069 double tmin = -150;
00070 double tmax = 150;
00071 int ntbins = 512;
00072
00073 name = EmcIndexer::EmcSectorId(i) + string("_tenergy");
00074 title = string("Tower energies (GeV) for sector ")
00075 + EmcIndexer::EmcSectorId(i);
00076
00077 TH1* h = m["tenergy"] = new TH1F(name.c_str(),
00078 title.c_str(),
00079 nebins,0,emax);
00080
00081 name = EmcIndexer::EmcSectorId(i) + string("_cenergy");
00082 title = string("Cluster energies (GeV) for sector ")
00083 + EmcIndexer::EmcSectorId(i);
00084
00085 h = m["cenergy"] = new TH1F(name.c_str(),
00086 title.c_str(),
00087 nebins,0,emax);
00088
00089 name = EmcIndexer::EmcSectorId(i) + string("_ttof");
00090 title = string("Tower TOF (ns) for sector ")
00091 + EmcIndexer::EmcSectorId(i);
00092
00093 h = m["ttof"] = new TH1F(name.c_str(),
00094 title.c_str(),
00095 ntbins,tmin,tmax);
00096
00097 name = EmcIndexer::EmcSectorId(i) + string("_ctof");
00098 title = string("Cluster TOF (ns) for sector ")
00099 + EmcIndexer::EmcSectorId(i);
00100
00101 h = m["ctof"] = new TH1F(name.c_str(),
00102 title.c_str(),
00103 ntbins,tmin,tmax);
00104
00105 histos.push_back(m);
00106 }
00107
00108 for ( size_t i = 0; i < 8; ++i )
00109 {
00110 MAP& m = histos[i];
00111 MAP::const_iterator it;
00112 for ( it = m.begin(); it != m.end(); ++it )
00113 {
00114 it->second->SetDirectory(gROOT);
00115 }
00116 }
00117
00118 gROOT->ls();
00119 }
00120
00121
00122 int process_event(DstContent* dst)
00123 {
00124 if ( histos.empty() )
00125 {
00126 makeHistoMap();
00127 }
00128
00129 emcTowerContainer* tc = static_cast<emcTowerContainer*>
00130 (dst->getClass("emcTowerContainer"));
00131
00132 if (tc)
00133 {
00134 histogram(*tc);
00135 }
00136
00137 emcClusterContainer* cc = static_cast<emcClusterContainer*>
00138 (dst->getClass("emcClusterContainer"));
00139
00140 if (cc)
00141 {
00142 histogram(*cc);
00143 }
00144
00145 return 0;
00146 }
00147
00148
00149 void hsave(const char* filename)
00150 {
00151 TFile f(filename,"RECREATE");
00152 for ( size_t i = 0; i < histos.size(); ++i )
00153 {
00154 MAP& m = histos[i];
00155 MAP::const_iterator it;
00156 for ( it = m.begin(); it != m.end(); ++it )
00157 {
00158 it->second->Write();
00159 }
00160 }
00161 f.Close();
00162
00163
00164
00165 for ( size_t i = 0; i < histos.size(); ++i )
00166 {
00167 MAP& m = histos[i];
00168 MAP::const_iterator it;
00169 for ( it = m.begin(); it != m.end(); ++it )
00170 {
00171 it->second->Reset();
00172 }
00173 }
00174 }