StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
eemcTimingScanPlot.cxx
1 #include "eemcTimingScanPlot.h"
2 
3 #include "TH2.h"
4 #include "TAxis.h"
5 #include "TROOT.h"
6 #include "TKey.h"
7 #include "TIterator.h"
8 #include "TFile.h"
9 #include "TTree.h"
10 #include "TGraph.h"
11 #include "TGraphErrors.h"
12 #include "TMultiGraph.h"
13 #include "TSystem.h"
14 #include "TF1.h"
15 #include "TCanvas.h"
16 #include "TStyle.h"
17 #include "TMath.h"
18 #include "TLegend.h"
19 
20 #include <iostream>
21 #include <fstream>
22 #include <iomanip>
23 #include <map>
24 #include <set>
25 #include <string>
26 #include "StEEmcUtil/EEfeeRaw/EEdims.h"
27 
28 using namespace std;
29 
30 // ----------------------------------------------------------------------------
31 eemcTimingScanPlot::eemcTimingScanPlot() {
32  mAxisMin=0.;
33  mAxisMax=110.;
34  mNormalize=false;
35  mNormalizePreshower=false;
36  mErrors=false;
37  mLegend=false;
38  mSuppressZeros=false;
39 }
40 
41 // ----------------------------------------------------------------------------
42 Int_t eemcTimingScanPlot::scan(TString directory) {
43 
45  TGraph *graphs[MaxMapmtCrates][12];
46  TString tmpstr,runnumberstring,tmpstr2;
47  const Int_t MxMapmtFeeCh= (MaxMapmtCrates* MaxMapmtCrateCh / 16) + 1;
48 
49 
50  Int_t myCrateIds[MaxMapmtCrates][12];
51  Int_t myChannelIds[MaxMapmtCrates][12];
52 
54  Float_t channelIntegrals[MxMapmtFeeCh];
55  Float_t channelErrors[MxMapmtFeeCh];
56  Int_t channelIds[MxMapmtFeeCh];
57  Int_t crateIds[MxMapmtFeeCh];
58  Float_t tmpfloat;
59 
61  TString flavor;
62 
65  std::vector<std::vector<std::vector<Float_t> > > allRunsVector; //all runs
66  std::vector<std::vector<Float_t> > channelIntegralVector; //all channels
67  std::vector<Float_t> tmpvector; //channels for one crate
68  std::vector<Float_t> timingDelay;
69 
70  std::vector<std::vector<std::vector<Int_t> > > allRunsCrateIds;
71  std::vector<std::vector<std::vector<Int_t> > > allRunsChannelIds;
72  std::vector<std::vector<Int_t> > crateIdsVector;
73  std::vector<std::vector<Int_t> > channelIdsVector;
74  std::vector<Int_t> tmpCrateIds;
75  std::vector<Int_t> tmpChannelIds;
76 
77 
79  if (!directory) return 0;
80  TString dirEntry;
81  void *dir = NULL;
82 
84  if ((dir = gSystem->OpenDirectory(directory.Data())) != NULL) {
85 
86 
91  const Char_t *dirEntryc;
92  while ((dirEntryc = gSystem->GetDirEntry(dir)) != NULL) {
93 
95  channelIntegralVector.clear();
96  crateIdsVector.clear();
97  channelIdsVector.clear();
98  dirEntry = dirEntryc;
99 
101  if(!dirEntry.Contains(".root")) continue;
102  tmpstr2 = directory + "/" + dirEntry;
103 
105  TFile *tf = new TFile(tmpstr2.Data());
106 
108  if (tf && tf->IsOpen()) {
109 
111  flavor = dirEntry(4,5);
112 
115  TTree* ttree = dynamic_cast<TTree*>(tf->Get("ints"));
116  ttree->SetBranchAddress("chanint",channelIntegrals);
117  ttree->SetBranchAddress("chanerr",channelErrors);
118  ttree->SetBranchAddress("delay",&tmpfloat);
119  ttree->SetBranchAddress("crateIds",crateIds); // crate and chan IDs corresponding
120  ttree->SetBranchAddress("channelIds",channelIds); // to the specified integral
121  ttree->GetEvent(0); // only the one event here
122  //printf("%s %f %f --------\n",flavor.Data(),channelIntegrals,&tmpfloat);
123 
124 
126  for(int i=0; i<MaxMapmtCrates; i++) {
127 
129  tmpvector.clear();
130  tmpCrateIds.clear();
131  tmpChannelIds.clear();
132 
136  for(int j=0; j<12; j++) {
137  tmpvector.push_back(channelIntegrals[i*12 + j]);
138  tmpCrateIds.push_back(crateIds[i*12 + j]);
139  tmpChannelIds.push_back(channelIds[i*12 + j]);
140  }
141  channelIntegralVector.push_back(tmpvector);
142  crateIdsVector.push_back(tmpCrateIds);
143  channelIdsVector.push_back(tmpChannelIds);
144  }
145 // tmpstr = direntry(25,direntry.Length()-29);
146 // sscanf(tmpstr.Data(),"%f",&tmpfloat);
147  timingDelay.push_back(tmpfloat);
148  }
149 
151  delete tf;
152 
155  allRunsVector.push_back(channelIntegralVector);
156  allRunsCrateIds.push_back(crateIdsVector);
157  allRunsChannelIds.push_back(channelIdsVector);
158 
159  }
160 
161  }
162 
163 
164 
166  Int_t tmpint, sector;
167  for(int icr=0;icr<MaxMapmtCrates;icr++) {
168 
169 
170  /*
171  //TString tit="sec";
172  TString tit="Box";
173  sector = icr/4 - 1;
174  //if(sector == -1) sector = 12;
175  //tit+=sector;
176  if(sector == -1) sector = 11;
177  tit+=(sector+1);
178  tmpint = icr%4 + 1;
179  if(tmpint < 4) {
180  tit+="S";
181  tit+=tmpint;
182  } else {
183  tit+="P1";
184  }
185  */
186 
187  TString tit = ""; // eh heh, hey beavis!
188  sector = -1;
189 
190  if ( flavor.Contains("tower") ) {
191  tit = "Crate";
192  tit += icr+1;
193  }
194  else {
195  tit = "Box";
196  sector=icr/4-1; if ( sector==-1 ) sector = 11;
197  tit += sector+1;
198  tmpint = icr%4 + 1;
199  if ( tmpint<4 ) { tit+="S"; tit += tmpint; }
200  else tit += "P1";
201  }
202 
203 
204 
208  for(int ich=0;ich<12;ich++) {
209  TGraph* gr=new TGraph(timingDelay.size());
210  gr->SetMarkerStyle(20+ich%7);
211  int icol=1+ich%5;
212  gr->SetMarkerColor(icol);
213  gr->SetLineColor(icol);
214  if(ich==0)gr->SetName(tit);
215  if(ich==0)gr->SetTitle(tit+"; delay(ns)");
216  graphs[icr][ich]=(TGraph*)gr;
217  }
218 
219 
220  }//crates
221 
222 
224  Int_t numberofPoints = timingDelay.size();
225  Float_t maxima[MaxMapmtCrates];
226  Float_t maxCrateChan[MaxMapmtCrates][12];
227  for(int icr=0;icr<MaxMapmtCrates;icr++) {
228  maxima[icr] = 0;
229  for ( Int_t jch=0; jch<12; jch++ ) maxCrateChan[icr][jch]=0.;
230  }
231 
234  for(Int_t i=0; i<numberofPoints; i++) {
236  for(int icr=0;icr<MaxMapmtCrates;icr++) {
238  for(int ich=0; ich<12; ich++) {
239 
241  if (allRunsVector[i][icr][ich] > maxima[icr]) {
242  maxima[icr] = allRunsVector[i][icr][ich];
243  }
244  if (allRunsVector[i][icr][ich] > maxCrateChan[icr][ich] ){
245  maxCrateChan[icr][ich] = allRunsVector[i][icr][ich];
246  }
247 
248  }
249  }
250  }
251 
252 
253 
254 
256  for(Int_t i=0; i<numberofPoints; i++) {
258  for(int icr=0;icr<MaxMapmtCrates;icr++) {
260  for(int ich=0; ich<12; ich++) {
263  Float_t scale = 1.;
264  if ( mNormalize && maxCrateChan[icr][ich] != 0. ) scale = maxima[icr]/maxCrateChan[icr][ich];
265  TString myName=graphs[icr][ich]->GetName();
266  if ( myName.Contains("P") && !mNormalizePreshower ) scale = 1.;
267  if ( allRunsVector[i][icr][ich] > 0. || !mSuppressZeros )
268  graphs[icr][ich]->SetPoint(i,timingDelay[i],scale*allRunsVector[i][icr][ich]);
269  myCrateIds[icr][ich] = allRunsCrateIds[i][icr][ich];
270  myChannelIds[icr][ich] = allRunsChannelIds[i][icr][ich]; }
271 
272  }
273  }
274 
275 
277  for ( Int_t i = 0; i < MaxMapmtCrates; i++ ) {
278  for ( Int_t j = 0; j < 12; j++ ) {
279  graphs[i][j]->Sort();
280  }
281  }
282 
283 
288 
289 
293  Int_t maxpg= (flavor.Contains("tower"))?1:4;
294  Int_t maxch= (flavor.Contains("tower"))?8:12;
295 
296 
300  for(int i=0; i<maxpg; i++) {
301 
306  TString cname="canvas"; cname += i;
307  TCanvas* c = new TCanvas(cname,"Crate channel plots",0,0,800,600);
308  TPad* smallpad[12];
309  for(int pp=0; pp<4; pp++) {
310  for(int qq=0; qq<3; qq++) {
311  c->cd();
312  tmpstr = "graph";
313  tmpstr += pp*3+qq;
314  smallpad[pp*3+qq] = new TPad(tmpstr.Data(),tmpstr.Data(), 0.33*qq, 0.25*pp, 0.33*(qq+1), 0.25*(pp+1));
315  smallpad[pp*3+qq]->Draw();
316  }
317  }
318 
319 
323  for(int icpp=0; icpp<12 ; icpp++) {
324 
325  smallpad[icpp]->cd();
326  smallpad[icpp]->Clear();
327 
330  TMultiGraph* tmg = new TMultiGraph(graphs[i*12 + icpp][0]->GetName(),graphs[i*12 + icpp][0]->GetTitle());
331 
332  for(int pcc=0; pcc<maxch ; pcc++) { //channels per crate!
333  tmg->Add(graphs[i*12 + icpp][pcc]);
334  }
336  tmg->SetMaximum(maxima[i*12 + icpp] * 1.1);
337  tmg->SetMinimum(0.0);
338 
339  Float_t minX=mAxisMin;
340  Float_t maxX=(mLegend)?mAxisMax*1.25:mAxisMax;
341  Float_t minY=0.;
342  Float_t maxY=1.1*maxima[i*12 + icpp];
343 
345  TH1F *htmp = new TH1F(graphs[i*12 + icpp][0]->GetName(),graphs[i*12 + icpp][0]->GetTitle(),110,minX,maxX);
346  htmp->SetMaximum(maxY);
347  htmp->SetMinimum(minY);
348  htmp->Draw();
349 
350  tmg->Draw("LP");
351 
353  if ( !mLegend ) continue;
354  TString bxstr = "crate "; bxstr += myCrateIds[i*12 + icpp][1];
355  TLegend *legend=new TLegend( 0.77 * maxX, 0.10 * maxY, 0.98 * maxX, 0.98 * maxY, bxstr, "br" );
356  legend->SetFillColor(33);
357  for(int pcc=0; pcc<maxch ; pcc++) { //channels per crate!
358  TString chstr = bxstr;
359  chstr += ":";
360  chstr += myChannelIds[i*12 + icpp][pcc];
361  legend->AddEntry(graphs[i*12 + icpp][pcc],chstr,"P");
362  }
363  legend -> Draw();
364 
365  }
366 
367  tmpstr="CrateTimingScanPage";
368  tmpstr += i;
369  tmpstr+=".gif";
370  c->Modified();
371  c->Update();
372  c->Print(tmpstr);
373  tmpstr.ReplaceAll("gif","ps");
374  c->Print(tmpstr);
375  }
376 
377  return 0;
378 }
379 
380 
381 ClassImp(eemcTimingScanPlot)
Int_t scan(TString directory)