00001 #include "eemcTimingScanPlot.h"
00002
00003 #include "TH2.h"
00004 #include "TAxis.h"
00005 #include "TROOT.h"
00006 #include "TKey.h"
00007 #include "TIterator.h"
00008 #include "TFile.h"
00009 #include "TTree.h"
00010 #include "TGraph.h"
00011 #include "TGraphErrors.h"
00012 #include "TMultiGraph.h"
00013 #include "TSystem.h"
00014 #include "TF1.h"
00015 #include "TCanvas.h"
00016 #include "TStyle.h"
00017 #include "TMath.h"
00018 #include "TLegend.h"
00019
00020 #include <iostream>
00021 #include <fstream>
00022 #include <iomanip>
00023 #include <map>
00024 #include <set>
00025 #include <string>
00026 #include "StEEmcUtil/EEfeeRaw/EEdims.h"
00027
00028 using namespace std;
00029
00030
00031 eemcTimingScanPlot::eemcTimingScanPlot() {
00032 mAxisMin=0.;
00033 mAxisMax=110.;
00034 mNormalize=false;
00035 mNormalizePreshower=false;
00036 mErrors=false;
00037 mLegend=false;
00038 mSuppressZeros=false;
00039 }
00040
00041
00042 Int_t eemcTimingScanPlot::scan(TString directory) {
00043
00045 TGraph *graphs[MaxMapmtCrates][12];
00046 TString tmpstr,runnumberstring,tmpstr2;
00047 const Int_t MxMapmtFeeCh= (MaxMapmtCrates* MaxMapmtCrateCh / 16) + 1;
00048
00049
00050 Int_t myCrateIds[MaxMapmtCrates][12];
00051 Int_t myChannelIds[MaxMapmtCrates][12];
00052
00054 Float_t channelIntegrals[MxMapmtFeeCh];
00055 Float_t channelErrors[MxMapmtFeeCh];
00056 Int_t channelIds[MxMapmtFeeCh];
00057 Int_t crateIds[MxMapmtFeeCh];
00058 Float_t tmpfloat;
00059
00061 TString flavor;
00062
00065 std::vector<std::vector<std::vector<Float_t> > > allRunsVector;
00066 std::vector<std::vector<Float_t> > channelIntegralVector;
00067 std::vector<Float_t> tmpvector;
00068 std::vector<Float_t> timingDelay;
00069
00070 std::vector<std::vector<std::vector<Int_t> > > allRunsCrateIds;
00071 std::vector<std::vector<std::vector<Int_t> > > allRunsChannelIds;
00072 std::vector<std::vector<Int_t> > crateIdsVector;
00073 std::vector<std::vector<Int_t> > channelIdsVector;
00074 std::vector<Int_t> tmpCrateIds;
00075 std::vector<Int_t> tmpChannelIds;
00076
00077
00079 if (!directory) return 0;
00080 TString dirEntry;
00081 void *dir = NULL;
00082
00084 if ((dir = gSystem->OpenDirectory(directory.Data())) != NULL) {
00085
00086
00091 const Char_t *dirEntryc;
00092 while ((dirEntryc = gSystem->GetDirEntry(dir)) != NULL) {
00093
00095 channelIntegralVector.clear();
00096 crateIdsVector.clear();
00097 channelIdsVector.clear();
00098 dirEntry = dirEntryc;
00099
00101 if(!dirEntry.Contains(".root")) continue;
00102 tmpstr2 = directory + "/" + dirEntry;
00103
00105 TFile *tf = new TFile(tmpstr2.Data());
00106
00108 if (tf && tf->IsOpen()) {
00109
00111 flavor = dirEntry(4,5);
00112
00115 TTree* ttree = dynamic_cast<TTree*>(tf->Get("ints"));
00116 ttree->SetBranchAddress("chanint",channelIntegrals);
00117 ttree->SetBranchAddress("chanerr",channelErrors);
00118 ttree->SetBranchAddress("delay",&tmpfloat);
00119 ttree->SetBranchAddress("crateIds",crateIds);
00120 ttree->SetBranchAddress("channelIds",channelIds);
00121 ttree->GetEvent(0);
00122
00123
00124
00126 for(int i=0; i<MaxMapmtCrates; i++) {
00127
00129 tmpvector.clear();
00130 tmpCrateIds.clear();
00131 tmpChannelIds.clear();
00132
00136 for(int j=0; j<12; j++) {
00137 tmpvector.push_back(channelIntegrals[i*12 + j]);
00138 tmpCrateIds.push_back(crateIds[i*12 + j]);
00139 tmpChannelIds.push_back(channelIds[i*12 + j]);
00140 }
00141 channelIntegralVector.push_back(tmpvector);
00142 crateIdsVector.push_back(tmpCrateIds);
00143 channelIdsVector.push_back(tmpChannelIds);
00144 }
00145
00146
00147 timingDelay.push_back(tmpfloat);
00148 }
00149
00151 delete tf;
00152
00155 allRunsVector.push_back(channelIntegralVector);
00156 allRunsCrateIds.push_back(crateIdsVector);
00157 allRunsChannelIds.push_back(channelIdsVector);
00158
00159 }
00160
00161 }
00162
00163
00164
00166 Int_t tmpint, sector;
00167 for(int icr=0;icr<MaxMapmtCrates;icr++) {
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187 TString tit = "";
00188 sector = -1;
00189
00190 if ( flavor.Contains("tower") ) {
00191 tit = "Crate";
00192 tit += icr+1;
00193 }
00194 else {
00195 tit = "Box";
00196 sector=icr/4-1; if ( sector==-1 ) sector = 11;
00197 tit += sector+1;
00198 tmpint = icr%4 + 1;
00199 if ( tmpint<4 ) { tit+="S"; tit += tmpint; }
00200 else tit += "P1";
00201 }
00202
00203
00204
00208 for(int ich=0;ich<12;ich++) {
00209 TGraph* gr=new TGraph(timingDelay.size());
00210 gr->SetMarkerStyle(20+ich%7);
00211 int icol=1+ich%5;
00212 gr->SetMarkerColor(icol);
00213 gr->SetLineColor(icol);
00214 if(ich==0)gr->SetName(tit);
00215 if(ich==0)gr->SetTitle(tit+"; delay(ns)");
00216 graphs[icr][ich]=(TGraph*)gr;
00217 }
00218
00219
00220 }
00221
00222
00224 Int_t numberofPoints = timingDelay.size();
00225 Float_t maxima[MaxMapmtCrates];
00226 Float_t maxCrateChan[MaxMapmtCrates][12];
00227 for(int icr=0;icr<MaxMapmtCrates;icr++) {
00228 maxima[icr] = 0;
00229 for ( Int_t jch=0; jch<12; jch++ ) maxCrateChan[icr][jch]=0.;
00230 }
00231
00234 for(Int_t i=0; i<numberofPoints; i++) {
00236 for(int icr=0;icr<MaxMapmtCrates;icr++) {
00238 for(int ich=0; ich<12; ich++) {
00239
00241 if (allRunsVector[i][icr][ich] > maxima[icr]) {
00242 maxima[icr] = allRunsVector[i][icr][ich];
00243 }
00244 if (allRunsVector[i][icr][ich] > maxCrateChan[icr][ich] ){
00245 maxCrateChan[icr][ich] = allRunsVector[i][icr][ich];
00246 }
00247
00248 }
00249 }
00250 }
00251
00252
00253
00254
00256 for(Int_t i=0; i<numberofPoints; i++) {
00258 for(int icr=0;icr<MaxMapmtCrates;icr++) {
00260 for(int ich=0; ich<12; ich++) {
00263 Float_t scale = 1.;
00264 if ( mNormalize && maxCrateChan[icr][ich] != 0. ) scale = maxima[icr]/maxCrateChan[icr][ich];
00265 TString myName=graphs[icr][ich]->GetName();
00266 if ( myName.Contains("P") && !mNormalizePreshower ) scale = 1.;
00267 if ( allRunsVector[i][icr][ich] > 0. || !mSuppressZeros )
00268 graphs[icr][ich]->SetPoint(i,timingDelay[i],scale*allRunsVector[i][icr][ich]);
00269 myCrateIds[icr][ich] = allRunsCrateIds[i][icr][ich];
00270 myChannelIds[icr][ich] = allRunsChannelIds[i][icr][ich]; }
00271
00272 }
00273 }
00274
00275
00277 for ( Int_t i = 0; i < MaxMapmtCrates; i++ ) {
00278 for ( Int_t j = 0; j < 12; j++ ) {
00279 graphs[i][j]->Sort();
00280 }
00281 }
00282
00283
00288
00289
00293 Int_t maxpg= (flavor.Contains("tower"))?1:4;
00294 Int_t maxch= (flavor.Contains("tower"))?8:12;
00295
00296
00300 for(int i=0; i<maxpg; i++) {
00301
00306 TString cname="canvas"; cname += i;
00307 TCanvas* c = new TCanvas(cname,"Crate channel plots",0,0,800,600);
00308 TPad* smallpad[12];
00309 for(int pp=0; pp<4; pp++) {
00310 for(int qq=0; qq<3; qq++) {
00311 c->cd();
00312 tmpstr = "graph";
00313 tmpstr += pp*3+qq;
00314 smallpad[pp*3+qq] = new TPad(tmpstr.Data(),tmpstr.Data(), 0.33*qq, 0.25*pp, 0.33*(qq+1), 0.25*(pp+1));
00315 smallpad[pp*3+qq]->Draw();
00316 }
00317 }
00318
00319
00323 for(int icpp=0; icpp<12 ; icpp++) {
00324
00325 smallpad[icpp]->cd();
00326 smallpad[icpp]->Clear();
00327
00330 TMultiGraph* tmg = new TMultiGraph(graphs[i*12 + icpp][0]->GetName(),graphs[i*12 + icpp][0]->GetTitle());
00331
00332 for(int pcc=0; pcc<maxch ; pcc++) {
00333 tmg->Add(graphs[i*12 + icpp][pcc]);
00334 }
00336 tmg->SetMaximum(maxima[i*12 + icpp] * 1.1);
00337 tmg->SetMinimum(0.0);
00338
00339 Float_t minX=mAxisMin;
00340 Float_t maxX=(mLegend)?mAxisMax*1.25:mAxisMax;
00341 Float_t minY=0.;
00342 Float_t maxY=1.1*maxima[i*12 + icpp];
00343
00345 TH1F *htmp = new TH1F(graphs[i*12 + icpp][0]->GetName(),graphs[i*12 + icpp][0]->GetTitle(),110,minX,maxX);
00346 htmp->SetMaximum(maxY);
00347 htmp->SetMinimum(minY);
00348 htmp->Draw();
00349
00350 tmg->Draw("LP");
00351
00353 if ( !mLegend ) continue;
00354 TString bxstr = "crate "; bxstr += myCrateIds[i*12 + icpp][1];
00355 TLegend *legend=new TLegend( 0.77 * maxX, 0.10 * maxY, 0.98 * maxX, 0.98 * maxY, bxstr, "br" );
00356 legend->SetFillColor(33);
00357 for(int pcc=0; pcc<maxch ; pcc++) {
00358 TString chstr = bxstr;
00359 chstr += ":";
00360 chstr += myChannelIds[i*12 + icpp][pcc];
00361 legend->AddEntry(graphs[i*12 + icpp][pcc],chstr,"P");
00362 }
00363 legend -> Draw();
00364
00365 }
00366
00367 tmpstr="CrateTimingScanPage";
00368 tmpstr += i;
00369 tmpstr+=".gif";
00370 c->Modified();
00371 c->Update();
00372 c->Print(tmpstr);
00373 tmpstr.ReplaceAll("gif","ps");
00374 c->Print(tmpstr);
00375 }
00376
00377 return 0;
00378 }
00379
00380
00381 ClassImp(eemcTimingScanPlot)