HARPO  5.1.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HarpoTools.cxx
Go to the documentation of this file.
1 #include "MakeNiceHisto.h"
2 #include "HarpoTools.h"
3 
4 #include "TH3F.h"
5 #include "TColor.h"
6 #include "TPolyLine3D.h"
7 
8 #include <fstream>
9 #include <iostream>
10 
11 using namespace std;
12 
13 
14 TDirectory* HarpoTools::OpenSimHistFile(const char* filename, const char* dir, Int_t &run, Int_t update, Int_t verbose)
15 {
16 
17  const char* filenamefull = gSystem->ExpandPathName(filename);
18 
19  if(verbose>0)
20  cout << "Opening " << filenamefull << endl;
21  if(gSystem->AccessPathName(filenamefull)){
22  if(verbose>0)
23  cout << "file " << filenamefull << " does not exist" << endl;
24  return 0;
25  }
26  TFile* file;
27  if(update) file = new TFile(filenamefull,"update");
28  else file = TFile::Open(filenamefull);
29  if(!file){
30  if(verbose>0)
31  cout << " Could not open file " << filenamefull << endl;
32  return 0;
33  }
34  if(file->IsZombie()){
35  if(verbose>0)
36  cout << "file " << filenamefull << " is a zombie" << endl;
37  return 0;
38  }
39 // gSystem->Load("libHarpoAnalysis.so");
40  HarpoRunHeader* hdr = (HarpoRunHeader*)file->Get("fRunHeader");
41  if(run<0)
42  run = hdr->GetRun();
43  TDirectory* output = file->GetDirectory(Form("run%d/%s",run,dir));
44  if(!output){
45  if(verbose>0)
46  cout << "file " << filenamefull << " does not contain " << Form("run%d/%s",run,dir) << endl;
47  return 0;
48  }
49  //file->cd(Form("run%d/%s",run,dir));
50  //file->ls();
51 
52  return output;
53 }
54 
55 TDirectory* HarpoTools::OpenHistFile(Int_t run, const char* dir, const char* extra, Int_t update)
56 {
57 
58 
59 
60  const char* dirname = gSystem->ExpandPathName("$HARPO_ANA_DIR");
61  const char* filename = Form("%s/run%d_hist%s.root",dirname,run,extra);
62  cout << "Opening " << filename << endl;
63  if(gSystem->AccessPathName(filename)){
64  cout << "file " << filename << " does not exist" << endl;
65  return 0;
66  }
67  TFile* file;
68  if(update)
69  file = new TFile(filename,"update");
70  else
71  file = TFile::Open(filename);
72  if(!file){
73  cout << " Could not open file " << filename << endl;
74  return 0;
75  }
76  if(file->IsZombie()){
77  cout << "file " << filename << " is a zombie" << endl;
78  return 0;
79  }
80  TDirectory* output = file->GetDirectory(Form("run%d/%s",run,dir));
81  if(!output){
82  cout << "file " << filename << " does not contain " << Form("run%d/%s",run,dir) << endl;
83  return 0;
84  }
85  // file->cd(Form("run%d/%s",run,dir));
86  // file->ls();
87 
88  return output;
89 }
90 
91 
93 {
94  const char* dirname = gSystem->ExpandPathName("$HARPO_ANA_DIR");
95  const char* filename = Form("%s/run%d_hist.root",dirname,run);
96  cout << "Opening " << filename << endl;
97  if(gSystem->AccessPathName(filename)){
98  cout << "file " << filename << " does not exist" << endl;
99  return 0;
100  }
101  TFile* file = TFile::Open(filename);
102  if(!file){
103  cout << " Could not open file " << filename << endl;
104  return 0;
105  }
106  if(file->IsZombie()){
107  cout << "file " << filename << " is a zombie" << endl;
108  return 0;
109  }
110 
111 
112 
113  HarpoRunHeader* fRunHeader = (HarpoRunHeader*)file->Get("fRunHeader");
114  if(!fRunHeader){
115  cout << "No run header in file " << filename << endl;
116  return 0;
117  }
118  HarpoDetHeader *rawhdr;
119  ULong_t ndet;
120  for(ndet=0;ndet<gkNDetectors;ndet++) {
121  std::cout << "Get Det Header " << ndet << std::endl;
122  rawhdr = (HarpoDetHeader*)file->Get(Form("fDetHeader%ld",ndet));
123  if(rawhdr ==0 ) continue;
124  fRunHeader->SetDetHeader(rawhdr,ndet);
125  std::cout << "Header Class Name " << rawhdr->ClassName() << std::endl;
126  }
127  return fRunHeader;
128 }
129 
130 TTree* HarpoTools::getTree(Double_t angle, Double_t energy, Int_t pola)
131 {
132 
133  TChain* tree = new TChain("HarpoTree");
134  ifstream str;
135  str.open("listRuns.txt",std::ifstream::in);
136 
137  const char* datadir = gSystem->ExpandPathName("$HARPO_RECO_DIR");
138  cout << datadir << endl;
139 
140  while(str.good()){
141  Char_t line[256];
142  str.getline(line,256);
143  Int_t a = 0, r = 0, p = -1;
144  Float_t e = 0;
145  sscanf(line,"%d %f %d %d",&a,&e,&r,&p);
146  //cout << a << " " << e << " " << r << endl;
147  if(r<1100) continue;
148  if(a != -1000 && a != angle) continue;
149  if(p != pola) continue;
150  // cout << r << endl;
151  if(energy>0 && TMath::Abs(e-energy)>0.1) continue;
152  //cout << r << endl;
153  // Char_t name[256];
154  //sprintf(name,
155  tree->Add(Form("%s/run%d.root",datadir,r));
156  //tree->Draw("fAngleOmega","","",10);
157  }
158 
159 
160  return tree;
161 
162 
163 }
164 
165 
166 UInt_t HarpoTools::getTime(Int_t run)
167 {
168 
169 
170 
171  Bool_t found;
172  HarpoRunConfig *info;
173  info = new HarpoRunConfig;
174  //TString db = "";
175  found = info->GetRunConfig(run);
176  //std::cout << " Run " << run << " found " << found << std::endl;
177 
178  if (found) {
179  //info->print();
180  TString val,type;
181  if (info->GetVal("date",val)) {
182  std::cout << "################### DATE val " << val << std::endl;
183  Int_t year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0;
184  sscanf(val,"%d-%d-%d %d:%d:%d",&year,&month,&day,&hour,&minute,&second);
185  TDatime datime(year,month,day,hour,minute,second);
186  UInt_t outtime = datime.Convert();
187  return outtime;
188  // angle = std::atoi(val.Data());
189  }
190  }
191 
192 
193  ifstream str;
194  str.open("timeRuns.txt",std::ifstream::in);
195 
196  while(str.good()){
197  Char_t line[256];
198  str.getline(line,256);
199  Int_t year = 0, month = 0, day = 0, hour = 0, minute = 0, r = 0;
200  sscanf(line,"%d %d %d %d %d %d",&year,&month,&day,&hour,&minute,&r);
201  // Int_t year = 2014;
202  // if(month<9) year = 2015;
203  if(r == run){
204  TDatime datime(year,month,day,hour,minute,0);
205  UInt_t outtime = datime.Convert();
206  cout << run << " : " << day << "/" << month << "/" << year << " => " << outtime << endl;
207  return outtime;
208  }
209  //return ((((month-10)*31 + (day - 27))*24 + hour)*60 + minute)*60;
210  }
211 
212  return 0;
213 }
214 
215 
216 TGraph* HarpoTools::getTP(const char* filename, UInt_t timestart, UInt_t timeend, Int_t night)
217 {
218 
219  TGraph* g = new TGraph();
220  ifstream str;
221  str.open(filename,std::ifstream::in);
222  Double_t P = 0, T = 0;
223  UInt_t timeold = 0;
224  Int_t n = 0;
225  while(str.good()){
226  Char_t line[256];
227  str.getline(line,256);
228  Int_t year = 0, month = 0, day = 0, hour = 0, minute = 0;
229  Float_t p = 0;
230  Int_t test = sscanf(line,"%d/%d/%d %d:%d:%*d %f",&day,&month,&year,&hour,&minute,&p);
231  if(test != 6) continue;
232  if(night == 1 && hour>6 && hour<21) continue;
233 
234  TDatime datime(year,month,day,hour,minute,0);
235 
236  // Int_t time = (((((year-2014)*12 + month-10)*31 + (day - 27))*24 + hour)*60 + minute);
237  UInt_t time = datime.Convert();
238  if( time < timestart ) continue;
239  if( time > timeend ) continue;
240  // cout << time << " - " << timeold << " = " << time - timeold << endl;
241  if(time - timeold > 600 && n>0){
242  P /= n;
243  T /= n + 1;
244  // cout << time << " " << T << " " << P << endl;
245  g->SetPoint(g->GetN(),T,P);
246  timeold = time;
247  P = 0;
248  n = 0;
249  }
250  P += p;
251  T += time;
252  n++;
253  //g->SetPoint(g->GetN(),time*60,p);
254 
255  }
256  return g;
257 }
258 
260 {
261 
262  TGraph* g = new TGraph();
263 
264  // const char* datadir = gSystem->ExpandPathName("$HARPO_DATA_DIR");
265  // const char* filename = Form("%s/Temperature_Pressure_NewSUBARU2014.csv",datadir);
266  const char* filename = "Temperature_Pressure.csv";
267  ifstream str;
268  str.open(filename,std::ifstream::in);
269 
270  Double_t P = 0;
271  Int_t timeold = 0;
272  Int_t n = 0;
273  while(str.good()){
274  Char_t line[256];
275  str.getline(line,256);
276  Int_t year = 0, month = 0, day = 0, hour = 0, minute = 0;
277  Float_t p = 0;
278  Int_t test = sscanf(line,"%d/%d/%d %d:%d:%*f;%f;%*s",&day,&month,&year,&hour,&minute,&p);
279  if(test != 6) continue;
280  Int_t time = (((((year-2014)*12 + month-10)*31 + (day - 27))*24 + hour)*60 + minute);
281  //cout << time << " " << p << endl;
282  P += p;
283  n++;
284  if(time > timeold + 10){
285  P /= n;
286  g->SetPoint(g->GetN(),time*60,P);
287  timeold = time;
288  P = 0;
289  n = 0;
290  // cout << time*60 << " " << p << endl;
291  }
292 
293  }
294  return g;
295 }
296 
297 
299 {
300 
301  TGraph* g = new TGraph();
302 
303  // const char* datadir = gSystem->ExpandPathName("$HARPO_DATA_DIR");
304  // const char* filename = Form("%s/Temperature_Pressure_NewSUBARU2014.csv",datadir);
305  const char* filename = "Temperature_Pressure.csv";
306  cout << filename << endl;
307  ifstream str;
308  str.open(filename,std::ifstream::in);
309 
310  Double_t T = 0;
311  Int_t timeold = 0;
312  Int_t n = 0;
313  while(str.good()){
314  Char_t line[256];
315  str.getline(line,256);
316  Int_t year = 0, month = 0, day = 0, hour = 0, minute = 0;
317  Float_t t = 0;
318  Int_t test = sscanf(line,"%*d/%*d/%*d %*d:%*d:%*f;%*f;%d/%d/%d %d:%d:%*f;%f;",&day,&month,&year,&hour,&minute,&t);
319  if(test != 6){
320  //cout << line << endl;
321  //cout << test << endl;
322  continue;
323  }
324  Int_t time = (((((year-2014)*12 + month-10)*31 + (day - 27))*24 + hour)*60 + minute);
325  // cout << time << " " << t << endl;
326  T += t;
327  n++;
328  if(time > timeold + 10){
329  T /= n;
330  g->SetPoint(g->GetN(),time*60,T);
331  timeold = time;
332  T = 0;
333  n = 0;
334  //cout << year << "/" << month << "/" << day << " " << time*60 << " " << t << endl;
335  }
336 
337  }
338  return g;
339 }
340 
341 
342 
343 
344 
345 TH1F* HarpoTools::GetTruncProfile(TH2F* h, Int_t type, Double_t tl, Double_t th)
346 {
347  Double_t xmin = h->GetXaxis()->GetXmin();
348  Double_t xmax = h->GetXaxis()->GetXmax();
349  Int_t nbinsX = h->GetXaxis()->GetNbins();
350  Int_t nbinsY = h->GetYaxis()->GetNbins();
351 
352  TH1F* p = new TH1F(Form("%s_trunc",h->GetName()),"",nbinsX,xmin,xmax);
353 
354 
355  for(Int_t i = 1; i<nbinsX+1; i++){
356  TArrayD* arr = new TArrayD(20000);//nbinsY+2);
357  Int_t n = 0;
358  Double_t qtot = 0;
359  for(Int_t j = 0; j<nbinsY+2; j++){
360  Int_t N = h->GetBinContent(i,j);
361  Double_t y = h->GetYaxis()->GetBinCenter(j);
362  for(Int_t k = 0; k<N; k++){
363  if(n>=20000) break;
364  arr->AddAt(y,n++);
365  qtot += y;
366  }
367  }
368  // if(n>=20000)
369  // cout << "N = " << n << endl;
370  Double_t min = -1, max = -1, norm = -1, trunc2;
371  Double_t trunc = TruncSum(arr,tl,th,min,max,norm,trunc2);
372  delete arr;
373  if(norm==0) continue;
374  // if(max>h->GetYaxis()->GetXmax()-1000)
375  // cout << "TruncMax = " << max << ", TruncMin = " << min << endl;
376  trunc2 -= trunc*trunc/norm;
377  if(type == 1){
378  trunc /= norm;
379  trunc2 /= norm;
380  }
381  // if(trunc2/norm > 10000) continue;
382  p->SetBinContent(i,trunc);
383  p->SetBinError(i,TMath::Sqrt(trunc2/norm));
384  //p->SetBinContent(i,qtot);
385  }
386 
387  return p;
388 }
389 
390 Double_t HarpoTools::TruncSum(TArrayD* vect, Double_t tl, Double_t th, Double_t &minTrunc, Double_t &maxTrunc, Double_t &norm, Double_t &truncSum2, Double_t thr)
391 {
392  //
393  // Calculates the truncated mean mean of the non zero value in vect
394  // The truncation is done on the 100*tl% lowest and 100*(1-th) highest value
395  //
396  // debug(2,"truncated mean");
397 
398 
399  Int_t size = vect->GetSize();
400  Double_t truncMean = 0;
401  Int_t* index = new Int_t[size];
402  TMath::Sort(size,vect->GetArray(),index,kFALSE);
403  Int_t t = 0, tLow, tHigh;
404 
405 
406  while(vect->At(index[t])<thr&&t<size-1) t++;
407  tLow = TMath::FloorNint(t + (size - t)*tl);
408  tHigh = TMath::FloorNint(t + (size - t)*th);
409 
410  for(Int_t tind = tLow; tind<tHigh; tind++){
411  truncMean += vect->At(index[tind]);
412  truncSum2 += vect->At(index[tind])*vect->At(index[tind]);
413  }
414  maxTrunc = vect->At(index[tHigh]);
415  minTrunc = vect->At(index[tLow]);
416  delete[] index;
417  norm = tHigh-tLow;
418  if(tHigh-tLow) {
419  return truncMean;
420  }
421  else return 0;
422 }
423 
424 
425 Double_t HarpoTools::TruncMean(TArrayD* vect, Double_t tl, Double_t th)
426 {
427 
428 
429  Double_t min = -1, max = -1, norm = -1, trunc2 = -1;
430  Double_t trunc = TruncSum(vect,tl,th,min,max,norm,trunc2);
431 
432  if(norm>0)
433  return trunc/norm;
434  return 0;
435 
436 }
437 
438 
439 
440 
441 
442 
443 
444 
445 TCanvas* HarpoTools::drawTPRatio(UInt_t timestart,UInt_t timeend,const char* cname)
446 {
447 
448 
449  UInt_t time1, time2, time3, time4, timeCirc;
450 
451  TDatime datime1(2015,6,8,10,40,00);
452  time1 = datime1.Convert();
453  TDatime datime2(2015,6,12,11,00,00);
454  time2 = datime2.Convert();
455  TDatime datime3(2015,7,8,13,00,00);
456  time3 = datime3.Convert();
457  TDatime datime4(2015,7,16,12,00,00);
458  time4 = datime4.Convert();
459  TDatime datimeCirc(2015,7,20,11,30,00);
460  timeCirc = datimeCirc.Convert();
461  TLine* line = new TLine();
462  line->SetLineStyle(2);
463  line->SetLineColor(kGray+2);
464  TLine* lineCirc = new TLine();
465  lineCirc->SetLineStyle(3);
466  lineCirc->SetLineColor(kGreen+1);
467  TArrow* arrowCirc = new TArrow();
468  arrowCirc->SetLineColor(kGreen+1);
469 
470  TLatex* latex = new TLatex();
471  latex->SetTextFont(132);
472  latex->SetTextAlign(12);
473  latex->SetTextSize(0.1);
474 
475  TCanvas* cTP = new TCanvas(cname,cname,1600,800);
476  // cTP->Divide(1,3);
477  CanvasPartition(cTP,1,3,0.08,0.08,0.08,0.01);
478 
479  TGraph* gP = getTP("Pressure.csv", timestart, timeend, 0);
480  gP->SetMarkerColor(kBlack);
481  gP->SetMarkerStyle(1);
482 
483  cout << gP->GetN() << endl;
484 
485  TGraph* gT = getTP("Temperature.csv", timestart, timeend);
486  gT->SetMarkerColor(kGreen+1);
487  gT->SetMarkerStyle(1);
488 
489  Int_t npoints = gT->GetN();
490 
491  Int_t kT = 0, kP = 0;
492  TGraph* gRatio = new TGraph();
493  Double_t corr1 = 1.02, corr2 = 1.065, corr3 = 1.09, corr4 = 1.09, corr5 = 1.11;
494  while(kT<npoints){
495  Double_t xT, yT;
496  gT->GetPoint(kT,xT,yT);
497  Double_t xP, yP;
498  gP->GetPoint(kP,xP,yP);
499  if(xP > xT+1){
500  kT++;
501  continue;
502  }
503  if(xT > xP+1){
504  kP++;
505  continue;
506  }
507 
508  if(yP>0){
509 
510  if(xT<time1)
511  gRatio->SetPoint(gRatio->GetN(),xT,yP/(yT+273.15));
512  if(xT>time1 && xT<time2)
513  gRatio->SetPoint(gRatio->GetN(),xT,corr1*yP/(yT+273.15));
514  if(xT>time2 && xT<time3)
515  gRatio->SetPoint(gRatio->GetN(),xT,corr2*yP/(yT+273.15));
516  if(xT>time3 && xT<time4)
517  gRatio->SetPoint(gRatio->GetN(),xT,corr3*yP/(yT+273.15));
518  if(xT>time4 && xT<timeCirc)
519  gRatio->SetPoint(gRatio->GetN(),xT,corr4*yP/(yT+273.15));
520  if(xT>timeCirc)
521  gRatio->SetPoint(gRatio->GetN(),xT,corr5*yP/(yT+273.15));
522  }
523  // if(yP>0)
524  // gRatio->SetPoint(gRatio->GetN(),xT,yT/yP);
525  kT++;
526  kP++;
527  }
528 
529  Double_t Tmean = 21.8, Pmean = 2.11, Psig = 0.03;
530  Double_t Tsig = Psig*200;
531  for(Int_t i = 0; i<npoints; i++){
532  Double_t x, y;
533  gT->GetPoint(i,x,y);
534  gT->SetPoint(i,x,(y-Tmean)*Psig/Tsig + Pmean);
535  //cout << (y-23)/200. + 2.105 << endl;
536  if(i==0) cout << x << endl;
537  if(i==npoints - 1) cout << x << endl;
538  }
539 
540  TH1F* hTime = new TH1F("hTime",";time;",200,timestart,timeend);
541  hTime->GetXaxis()->SetTimeDisplay(1);
542  // TDatime dh(2014,10,27,00,00,00);
543  // hTime->GetXaxis()->SetTimeOffset(dh.Convert());
544  // hTime->GetXaxis()->SetTimeFormat("%m-%d %H:%M");
545  // hTime->GetXaxis()->SetNdivisions(011);
546  // hTime->GetXaxis()->SetTimeFormat("%m-%d %Hh");
547  hTime->GetXaxis()->SetTimeFormat("%m-%d");
548  hTime->GetXaxis()->SetNdivisions(121);
549  hTime->SetTitle(";time;P [bar]");
550  hTime->SetMaximum(4000);
551  char name[16];
552  sprintf(name,"%s_%i_%i",cTP->GetName(),0,2);
553  cTP->cd(0);
554  ((TPad*) gROOT->FindObject(name))->Draw();
555  ((TPad*) gROOT->FindObject(name))->cd();
556  SetHistStyle(hTime);
557  hTime->GetYaxis()->SetLabelSize(0.08);
558  hTime->GetYaxis()->SetTitleSize(0.1);
559  hTime->GetYaxis()->SetTitleOffset(0.35);
560  MakeNice1dHistoPad(hTime,((TPad*) gROOT->FindObject(name)),1,3);
561  // MakeNiceHisto(hTime,cTP->GetPad(1),"");
562  hTime->SetMaximum(Pmean + Psig);
563  hTime->SetMinimum(Pmean - Psig);
564  sprintf(name,"%s_%i_%i",cTP->GetName(),0,1);
565  cTP->cd(0);
566  ((TPad*) gROOT->FindObject(name))->Draw();
567  ((TPad*) gROOT->FindObject(name))->cd();
568  SetHistStyle(hTime);
569  hTime->GetYaxis()->SetLabelSize(0.08);
570  hTime->GetYaxis()->SetTitleSize(0.1);
571  hTime->GetYaxis()->SetTitleOffset(0.35);
572  MakeNice1dHistoPad(hTime,((TPad*) gROOT->FindObject(name)),1,3);
573  //MakeNiceHisto(hTime,cTP->GetPad(2),"",0);
574  hTime->GetYaxis()->SetLabelSize(0.08);
575  hTime->GetYaxis()->SetTitleSize(0.1);
576  hTime->GetYaxis()->SetTitleOffset(0.3);
577  gP->Draw("Psame");
578 
579  TGaxis *axis = new TGaxis(timeend,Pmean - Psig,
580  timeend,Pmean + Psig,
581  Tmean - Tsig, Tmean + Tsig,510,"+L");
582  axis->SetLineColor(kGreen+1);
583  axis->SetTextColor(kGreen+1);
584  axis->SetLabelColor(kGreen+1);
585  axis->SetTitle("T [C]");
586  axis->SetTitleSize(0.07);
587  axis->SetTitleOffset(0.3);
588  axis->SetTitleFont(132);
589  axis->SetLabelFont(132);
590  axis->SetLabelSize(0.06);
591  axis->Draw();
592 
593  gT->Draw("Psame");
594 
595 
596  TGraph* gPnight = getTP("Pressure.csv", timestart, timeend, 1);
597  TGraph* gTnight = getTP("Temperature.csv", timestart, timeend, 1);
598 
599  kT = 0;
600  kP = 0;
601  TGraph* gRatioNight = new TGraph();
602  gRatioNight->SetMarkerColor(kRed);
603  gRatioNight->SetMarkerStyle(6);
604  Int_t npointsNight = gTnight->GetN();
605  while(kT<npointsNight){
606  Double_t xT, yT;
607  gTnight->GetPoint(kT,xT,yT);
608  Double_t xP, yP;
609  gPnight->GetPoint(kP,xP,yP);
610  if(xP > xT+1){
611  kT++;
612  continue;
613  }
614  if(xT > xP+1){
615  kP++;
616  continue;
617  }
618  kT++;
619  kP++;
620  if(xT>time1) continue;
621 
622  if(yP>0 && yP/(yT+273.15) < 0.008 && yP/(yT+273.15) > 0.007)
623  gRatioNight->SetPoint(gRatioNight->GetN(),xT,yP/(yT+273.15));
624  // if(yP>0)
625  // gRatio->SetPoint(gRatio->GetN(),xT,yT/yP);
626  }
627 
628  TH1F* hTime2 = (TH1F*)hTime->Clone("hTime2");
629  hTime2->SetTitle(";time; P/T [bar/K]");
630  Double_t rMin = 0.00710, rMax = 0.00720;
631  hTime2->SetMaximum(rMax);
632  hTime2->SetMinimum(rMin);
633  sprintf(name,"%s_%i_%i",cTP->GetName(),0,0);
634  cTP->cd(0);
635  ((TPad*) gROOT->FindObject(name))->Draw();
636  ((TPad*) gROOT->FindObject(name))->cd();
637  SetHistStyle(hTime2);
638  hTime2->GetYaxis()->SetLabelSize(0.08);
639  hTime2->GetYaxis()->SetTitleSize(0.1);
640  hTime2->GetYaxis()->SetTitleOffset(0.35);
641  MakeNice1dHistoPad(hTime2,((TPad*) gROOT->FindObject(name)),1,3);
642  // MakeNiceHisto(hTime2,cTP->GetPad(3),"",0);
643  // hTime2->GetYaxis()->SetLabelSize(0.08);
644  // hTime2->GetYaxis()->SetTitleSize(0.1);
645  // hTime2->GetYaxis()->SetTitleOffset(0.3);
646  gRatio->Draw("Psame");
647  gRatioNight->Draw("Psame");
648 
649  // TLatex* latex = new TLatex();
650  // latex->SetTextFont(132);
651  // latex->SetTextAlign(12);
652  // latex->SetTextSize(0.07);
653 
654  Double_t ylatex1 = 0.00716;
655  latex->DrawLatex(0.5*(time1+time2)-200000,ylatex1,Form("x%.3g",corr1));
656  latex->DrawLatex(0.5*(time2+time3)-200000,ylatex1,Form("x%.3g",corr2));
657  latex->DrawLatex(0.5*(time3+time4)-200000,ylatex1,Form("x%.3g",corr3));
658  latex->DrawLatex(0.5*(time4+timeCirc)-200000,ylatex1,Form("x%.3g",corr4));
659  latex->DrawLatex(0.5*(timeCirc+timeend)-200000,ylatex1,Form("x%.3g",corr5));
660 
661  TF1* f = new TF1("f","expo",timestart, timeend);
662  //TF1* f = new TF1("f","pol1",timestart, timeend);
663  f->SetParameters(7e-3,7e-4);
664  gRatioNight->Fit(f,"0","",timestart,timeend);
665  f->SetLineColor(kRed);
666  f->SetLineWidth(1);
667  f->Draw("same");
668 
669  // TLatex* latex = new TLatex();
670  // latex->SetTextFont(132);
671  // latex->SetTextAlign(12);
672  // latex->SetTextSize(0.07);
673 
674  cTP->cd(3);
675  Double_t ylatex = rMin + 0.8*(rMax-rMin);
676  Double_t xlatex = timestart+0.05*(timeend-timestart);
677  //cout << xlatex << " " << ylatex << endl;
678  // latex->DrawLatex(xlatex,ylatex,Form("%.3g/s",f->GetParameter(1)));
679  // latex->DrawLatex(xlatex,ylatex-0.00001,Form("%.3g/s",f->GetParameter(1)*3600));
680  latex->DrawLatex(xlatex,ylatex,Form("Rate: %.3g%%/week = %.3g#muL/h = %.3g#mubar/h",f->GetParameter(1)*7*24*3600*100,f->GetParameter(1)*3600*100*1e6,f->GetParameter(1)*3600*2e6));
681 
682  cout << f->GetParameter(1)*100 << "%/s" << endl;
683  cout << f->GetParameter(1)*3600 << "%/h" << endl;
684  cout << f->GetParameter(1)*7*24*3600*100 << "%/week" << endl;
685 
686  return cTP;
687 
688 }
689 
690 
691 
692 
693 
694 void HarpoTools::updateRunData(Int_t run, const char* name, Double_t val)
695 {
696  if(run>50000){
697  std::cerr << "**** RUN NUMBER TOO HIGH (" << run << "). NOT UPDATING ****" << endl;
698  return;
699  }
700  const char* dirname = gSystem->ExpandPathName("$HARPO_ANA_DIR");
701  Char_t infilename[512], outfilename[512];
702  sprintf(infilename,"%s/RunData_bk.root",dirname);
703  sprintf(outfilename,"%s/RunData.root",dirname);
704  Char_t command[512];
705  sprintf(command,"cp %s %s",outfilename, infilename);
706 
707  if(gSystem->AccessPathName(Form("%s/RunData.root",dirname))){
708  TFile* fileout = new TFile(outfilename,"recreate");
709  TTree* tree = new TTree("RunData","Run data from analysis");
710  Double_t r, var;
711  tree->Branch("run",&r,"run/D");
712  tree->Branch(name,&var,Form("%s/D",name));
713  // for(Int_t i = 0; i<run+1; i++){
714  // r = -1000;
715  // var = -1000;
716  // if(i == run){
717  // r = run;
718  // var = val;
719  // }
720  // tree->Fill();
721  // }
722  r = run;
723  var = val;
724  tree->Fill();
725  fileout->Write();
726  fileout->Close();
727  return;
728  }
729 
730  TString namevar = TString(name);
731  cout << "Execute " << command << endl;
732  gSystem->Exec(command);
733 
734  TFile* filein = TFile::Open(infilename);
735  if(!filein) return;
736  TTree* treein = (TTree*)filein->Get("RunData");
737  if(!treein) return;
738 
739  TObjArray* listbr = treein->GetListOfBranches();
740  Int_t nbr = listbr->GetEntries();
741  Bool_t create = 1;
742  Int_t index = -1;
743  for(Int_t i = 0; i<nbr; i++){
744  TBranch* br = (TBranch*)listbr->At(i);
745  TString namebr = TString(br->GetName());
746  if(namebr == namevar){
747  //cout << "Variable " << name << " already exists" << endl;
748  create = 0;
749  index = i;
750  break;
751  }
752  }
753 
754 
755  TFile* fileout = new TFile(outfilename,"recreate");
756  TTree* tree = new TTree("RunData","Run data from analysis");
757 
758  const Int_t nvar = nbr;// + create;
759  Double_t varlistin[nvar];
760  Double_t varlistout[nvar];
761  Int_t indexrun = -1;
762  for(Int_t i = 0; i<nbr; i++){
763  TBranch* br = (TBranch*)listbr->At(i);
764  TString namebr = TString(br->GetName());
765  if(namebr == TString("run"))
766  indexrun = i;
767  tree->Branch(br->GetName(),&varlistout[i],Form("%s/D",br->GetName()));
768  treein->SetBranchAddress(br->GetName(),&varlistin[i]);
769  }
770  Double_t newvar;
771  if(create){
772  tree->Branch(name,&newvar,Form("%s/D",name));
773  }
774 
775  Int_t nEntries = treein->GetEntries();
776  // Int_t nTot = nEntries;
777  // if(run>=nEntries){
778  // nTot = run+1;
779  // }
780 
781 
782  // for(Int_t i = 0; i<nTot; i++){
783  // if(i<nEntries)
784  // treein->GetEvent(i);
785  // else{
786  // for(Int_t k = 0; k<nbr; k++)
787  // varlistin[k] = -1000;
788  // }
789 
790  // for(Int_t k = 0; k<nbr; k++){
791  // varlistout[k] = varlistin[k];
792  // }
793 
794  // newvar = -1000;
795  // if(i == run){
796  // cout << "Updating " << name << " to " << val << endl;
797  // if(index == -1) newvar = val;
798  // else varlistout[index] = val;
799  // varlistout[indexrun] = i;
800  // }
801 
802  // tree->Fill();
803  // }
804 
805  Bool_t newrun = kTRUE;
806  for(Int_t i = 0; i<nEntries; i++){
807  treein->GetEvent(i);
808  for(Int_t k = 0; k<nbr; k++){
809  varlistout[k] = varlistin[k];
810  }
811 
812  newvar = -1000;
813  if(varlistout[indexrun] == run){
814  cout << "Updating " << name << " in run " << run << " to " << val << endl;
815  if(index == -1) newvar = val;
816  else varlistout[index] = val;
817  newrun = kFALSE;
818  }
819 
820  tree->Fill();
821  }
822 
823  if(newrun){
824  cout << "Adding run " << run << endl;
825  for(Int_t k = 0; k<nbr; k++)
826  varlistout[k] = -1000;
827  if(index == -1) newvar = val;
828  else varlistout[index] = val;
829  varlistout[indexrun] = run;
830  tree->Fill();
831  }
832 
833 
834  fileout->Write();
835  fileout->Close();
836 
837  filein->Close();
838 }
839 
840 
841 
842 
843 
844 
845 void HarpoTools::updateConfData(Double_t energy, Double_t omega0, Int_t pola, Int_t sim, Int_t flag, const char* name, Double_t val)
846 {
847  const char* dirname = gSystem->ExpandPathName("$HARPO_ANA_DIR");
848  Char_t infilename[512], outfilename[512];
849  sprintf(infilename,"%s/ConfData_bk.root",dirname);
850  sprintf(outfilename,"%s/ConfData.root",dirname);
851  Char_t command[512];
852  sprintf(command,"cp %s %s",outfilename, infilename);
853 
854  if(gSystem->AccessPathName(Form("%s/ConfData.root",dirname))){
855  TFile* fileout = new TFile(outfilename,"recreate");
856  TTree* tree = new TTree("ConfData","Conf data from analysis");
857  Double_t E, Omega0, Sim, Pola, Flag, var;
858  tree->Branch("E",&E,"E/D");
859  tree->Branch("omega0",&Omega0,"omega0/D");
860  tree->Branch("sim",&Sim,"sim/D");
861  tree->Branch("pola",&Pola,"pola/D");
862  tree->Branch("flag",&Flag,"flag/D");
863  tree->Branch(name,&var,Form("%s/D",name));
864  E = energy;
865  Omega0 = omega0;
866  Sim = sim;
867  Pola = pola;
868  Flag = flag;
869  var = val;
870  tree->Fill();
871  fileout->Write();
872  fileout->Close();
873  return;
874  }
875 
876  TString namevar = TString(name);
877  //cout << "Execute " << command << endl;
878  gSystem->Exec(command);
879 
880  TFile* filein = TFile::Open(infilename);
881  if(!filein) return;
882  TTree* treein = (TTree*)filein->Get("ConfData");
883  if(!treein) return;
884 
885  TObjArray* listbr = treein->GetListOfBranches();
886  Int_t nbr = listbr->GetEntries();
887  Bool_t create = 1;
888  Int_t index = -1;
889  for(Int_t i = 0; i<nbr; i++){
890  TBranch* br = (TBranch*)listbr->At(i);
891  TString namebr = TString(br->GetName());
892  if(namebr == namevar){
893  //cout << "Variable " << name << " already exists" << endl;
894  create = 0;
895  index = i;
896  break;
897  }
898  }
899 
900 
901  TFile* fileout = new TFile(outfilename,"recreate");
902  TTree* tree = new TTree("ConfData","Run data from analysis");
903 
904  const Int_t nvar = nbr;// + create;
905  Double_t varlistin[nvar];
906  Double_t varlistout[nvar];
907  Int_t indexE = -1, indexOmega0 = -1, indexSim = -1, indexPola = -1, indexFlag = -1;
908  for(Int_t i = 0; i<nbr; i++){
909  TBranch* br = (TBranch*)listbr->At(i);
910  TString namebr = TString(br->GetName());
911  if(namebr == TString("E"))
912  indexE = i;
913  if(namebr == TString("omega0"))
914  indexOmega0 = i;
915  if(namebr == TString("sim"))
916  indexSim = i;
917  if(namebr == TString("pola"))
918  indexPola = i;
919  if(namebr == TString("flag"))
920  indexFlag = i;
921  tree->Branch(br->GetName(),&varlistout[i],Form("%s/D",br->GetName()));
922  treein->SetBranchAddress(br->GetName(),&varlistin[i]);
923  }
924  Double_t newvar;
925  if(create){
926  tree->Branch(name,&newvar,Form("%s/D",name));
927  }
928 
929  Int_t nEntries = treein->GetEntries();
930  // Int_t nTot = nEntries;
931 
932  //cout << "**** Nentries = " << nEntries << endl;
933 
934  Bool_t newconf = kTRUE;
935  for(Int_t i = 0; i<nEntries; i++){
936  treein->GetEvent(i);
937  //cout << "-------------------------------------------" << endl;
938  //cout << i << " => ";
939  for(Int_t k = 0; k<nbr; k++){
940  //cout << " " << varlistin[k];
941  varlistout[k] = varlistin[k];
942  }
943  //cout << endl;
944  //cout << "Updating " << name << " in E = " << varlistout[indexE] << "/" << energy << ", angle = " << varlistout[indexOmega0] << "/" << omega0 << ", p = " << varlistout[indexPola] << "/" << pola << ", sim = " << varlistout[indexSim] << "/" << sim << ", flag = " << varlistout[indexFlag] << "/" << flag << " ( " << i << ") to " << val << endl;
945 
946  newvar = -1000;
947  // cout << "E = " << energy << ", angle = " << angle << ", p = " << p << ", sim = " << simu << " to " << val << endl;
948  // cout << "*E = " << varlistout[indexE] << ", angle = " << varlistout[indexOmega0] << ", p = " << varlistout[indexPola] << ", sim = " << varlistout[indexSim] << " to " << val << endl;
949  if(TMath::Abs(varlistout[indexE]-energy)<0.1 && TMath::Abs(varlistout[indexOmega0]-omega0)<1 && varlistout[indexSim] == sim && varlistout[indexPola] == pola && varlistout[indexFlag] == flag){
950  cout << "Updating " << name << " in E = " << varlistout[indexE] << "/" << energy << ", angle = " << varlistout[indexOmega0] << "/" << omega0 << ", p = " << varlistout[indexPola] << "/" << pola << ", sim = " << varlistout[indexSim] << "/" << sim << ", flag = " << varlistout[indexFlag] << "/" << flag << " ( " << i << ") to " << val << endl;
951  if(index == -1) newvar = val;
952  else varlistout[index] = val;
953  newconf = kFALSE;
954  }
955 
956  tree->Fill();
957  }
958 
959  if(newconf){
960  cout << "Adding E = " << energy << ", angle = " << omega0 << ", p = " << pola << ", sim = " << sim << ", flag = " << flag << " with " << name << " = " << val << endl;
961  for(Int_t k = 0; k<nbr; k++)
962  varlistout[k] = -1000;
963  if(index == -1) newvar = val;
964  else varlistout[index] = val;
965  varlistout[indexE] = energy;
966  varlistout[indexOmega0] = omega0;
967  varlistout[indexSim] = sim;
968  varlistout[indexPola] = pola;
969  varlistout[indexFlag] = flag;
970  tree->Fill();
971  }
972 
973 
974  fileout->Write();
975  fileout->Close();
976 
977  filein->Close();
978 }
979 
980 
981 
982 
983 
984 
985 
986 Double_t HarpoTools::getRunData(Int_t run, const char* name)
987 {
988  // if(run>50000){
989  // std::cerr << "**** RUN NUMBER TOO HIGH (" << run << "). NO DATA ****" << endl;
990  // return -1000;
991  // }
992 
993  const char* dirname = gSystem->ExpandPathName("$HARPO_ANA_DIR");
994  Char_t infilename[512];
995  sprintf(infilename,"%s/RunData.root",dirname);
996  if(gSystem->AccessPathName(infilename)){
997  cout << "Could not access " << infilename << endl;
998  return -1000;
999  }
1000  TString namevar = TString(name);
1001  TFile* filein = TFile::Open(infilename);
1002  if(!filein) return -1000;
1003  TTree* treein = (TTree*)filein->Get("RunData");
1004  if(!treein) return -1000;
1005  Double_t var;
1006  treein->SetBranchAddress(name,&var);
1007  Double_t r;
1008  treein->SetBranchAddress("run",&r);
1009 
1010  Int_t nEntries = treein->GetEntries();
1011  // if(nEntries<run){
1012  // std::cerr << "**** RUN NUMBER TOO HIGH (" << run << "). NO DATA ****" << endl;
1013  // return -1000;
1014  // }
1015  for(Int_t i = 0; i<nEntries; i++){
1016  treein->GetEvent(i);
1017  // cout << r << " => " << var << endl;
1018  if(r == run) break;
1019  }
1020  filein->Close();
1021  if(r == run)
1022  return var;
1023  else
1024  return -1000;
1025 }
1026 
1027 
1028 
1029 
1030 TString HarpoTools::getVal(Int_t run, const char* name, const TString* dburl)
1031 {
1032  HarpoRunConfig* info = new HarpoRunConfig();
1033  Bool_t found;
1034  found = info->GetRunConfig(run,dburl);
1035  if(!found) return TString("");
1036  TString val,type;
1037  // if(info->GetType(name,type))
1038  // std::cout << name << " => type = " << type.Data() << std::endl;
1039  if(info->GetVal(name,val))
1040  return val;
1041  else
1042  return TString("");
1043 }
1044 
1045 
1046 Double_t HarpoTools::getDoubleVal(Int_t run, const char* name, const TString* dburl)
1047 {
1048  HarpoRunConfig* info = new HarpoRunConfig();
1049  Bool_t found;
1050  found = info->GetRunConfig(run,dburl);
1051  if(!found) return -1000;
1052  TString val,type;
1053  if (!info->GetType(name,type))
1054  return -1000;
1055  if(type.Contains("char"))
1056  return -1000;
1057  if (!info->GetVal(name,val))
1058  return -1000;
1059 
1060 
1061  Double_t output = std::atof(val.Data());
1062  if(strcmp(name,"Ephoton")==0){
1063  //cout << name << " => " << output << endl;
1064  Double_t eDB[14] = {1.7 , 2.6 , 3.8 , 4.4 , 6.3 , 11. , 16. , 18 , 25. , 32. , 37. , 49. , 50., 72.};
1065  Int_t index[14] = {0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 11 , 12 };
1066  Double_t eReal[13] = {1.74, 2.73, 3.93, 4.68, 6.76, 11.8, 16.9, 18.5, 26.6, 33.3, 38.1, 52.1, 74.3};
1067  for(Int_t i = 0; i<14; i++){
1068  if(TMath::Abs(output-eDB[i])<0.01){
1069  //cout << output << " => " << eReal[index[i]] << endl;
1070  return eReal[index[i]];
1071  }
1072  }// output = ConvertEphoton(output);
1073  }
1074  return output;
1075 }
1076 
1077 // Double_t ConvertEphoton(Double_t e)
1078 // {
1079 
1080 // Double_t eDB[13] = {1.71, 2.67, 3.83, 4.41, 6.36, 11.6, 16.7, 18 , 25.8, 32.7, 37.1, 49.3, 72.3};
1081 // Double_t eReal[13] = {1.74, 2.73, 3.93, 4.68, 6.76, 11.8, 16.9, 18.5, 26.6, 33.3, 38.1, 52.1, 74.3};
1082 
1083 // for(Int_t i = 0; i<13; i++){
1084 // if(TMath::Abs(e-eDB[i])<0.01){
1085 // cout << e << " => " << eReal[i] << endl;
1086 // return eReal[i];
1087 // }
1088 // }
1089 // return -1;
1090 
1091 // }
1092 
1093 TCanvas* HarpoTools::SaveEvent(HarpoEvent* evt, const char* savedir, HarpoRunHeader* rh, Bool_t bw)
1094 {
1095 
1096  if(bw){
1097  const Int_t Number = 2;
1098  Double_t min = 0.10, max = 0.92;
1099  Double_t Red[Number] = { max, min};
1100  Double_t Green[Number] = { max, min};
1101  Double_t Blue[Number] = { max, min};
1102  // Double_t Red[Number] = { 1, 0.9};
1103  // Double_t Green[Number] = { 1, 0};
1104  // Double_t Blue[Number] = { 0.5, 0};
1105  Double_t Length[Number] = { 0.00, 1.00 };
1106  Int_t nb=64;
1107  TColor::CreateGradientColorTable(Number,Length,Red,Green,Blue,nb);
1108  }
1109 
1110  Bool_t isSim = rh->GetSimDataFlag();
1111  cout << "SIMULATION ? " << isSim << endl;
1112 
1113  gStyle->SetOptStat(0);
1114 
1115 
1116  TH2F* fHistEvent[2];
1117  fHistEvent[0] = new TH2F("fHistEventX",";time [30ns bin]; X channel [1mm pitch]; charge [ADC ch]",512,0,512,288,0,288);
1118  fHistEvent[1] = new TH2F("fHistEventY",";time [30ns bin]; Y channel [1mm pitch]; charge [ADC ch]",512,0,512,288,0,288);
1119 
1120  TH2F* fHistEventEmpty[2];
1121  fHistEventEmpty[0] = new TH2F("fHistEventEmptyX",";time [30ns bin]; X channel [1mm pitch]; charge [ADC ch]",512,0,512,288,0,288);
1122  fHistEventEmpty[1] = new TH2F("fHistEventEmptyY",";time [30ns bin]; Y channel [1mm pitch]; charge [ADC ch]",512,0,512,288,0,288);
1123 
1124  TH1F* fHistSpectrum[2];
1125  fHistSpectrum[0] = new TH1F("fHistSpectrumX",";time [30ns bin]; X Q [ADC]",512,0,512);
1126  fHistSpectrum[1] = new TH1F("fHistSpectrumY",";time [30ns bin]; Y Q [ADC]",512,0,512);
1127 
1128  Info("DisplayMap","%p",evt);
1129 
1130  if(evt == 0) return 0;
1131 
1132  for(Int_t ndet=0;ndet<2;ndet++) {
1133  if(!gHDetSet->isExist(ndet)) continue;
1134  HarpoDccMap * m = evt->GetDccMap(ndet);
1135  if ( m == NULL ) continue;
1136  fHistEvent[ndet]->Reset();
1137  fHistSpectrum[ndet]->Reset();
1138  for(Int_t i=1;i<NADC;i++){ //Time bins
1139  // Double_t sigmaQ = 0;
1140  Double_t Qt=0;
1141  for(Int_t j=0;j<NCHAN;j++){ // Channels
1142  Double_t q = m->GetData(j,i);
1143  fHistEvent[ndet]->SetBinContent(i+1,j+1,q);
1144  if(q >= 0)
1145  Qt=Qt+q;
1146  }
1147  fHistSpectrum[ndet]->SetBinContent(i+1,Qt);
1148  }
1149  fHistEvent[ndet]->SetMinimum(1);
1150  fHistEvent[ndet]->SetMaximum(4096);
1151  }
1152 
1153 
1154  // InitEvent(evt);
1155 
1156  TLatex* latex = new TLatex();
1157  latex->SetTextFont(132);
1158  latex->SetTextAlign(12);
1159  latex->SetTextSize(0.08);
1160 
1161  // HarpoRecoEvent* reco = evt->GetRecoEvent();
1162  // TClonesArray* matchArray = reco->GetMatchingArray();
1163  // TClonesArray* trArray = reco->GetTracksArray();
1164  // Int_t nMatch = matchArray->GetEntries();
1165 
1166  TCanvas* cSave;
1167  cSave = new TCanvas("cSave","c",1200,1100);
1168 
1169  TCanvas* cSaveSp;
1170  cSaveSp = new TCanvas("cSaveSp","spectrum",1200,1100);
1171 
1172  Int_t nPlanes = 2;
1173  Double_t left = 0.15, right = 0.2, bottom = 0.09, top = 0.01;
1174  // TClonesArray* pads =
1175  CanvasPartition(cSave,1,nPlanes,left,right,bottom,top);
1176 
1177  Double_t vcorr = ((1. - bottom - top)/2. + top)/((1. - bottom - top)/2. + bottom);
1178 
1179  TLine* lineT = new TLine();
1180  lineT->SetLineStyle(10);
1181  lineT->SetLineWidth(2);
1182  lineT->SetLineColor(kGray+1);
1183  Double_t tmin = 90., tmax = 415.;
1184 
1185  char name[16];
1186  sprintf(name,"%s_%i_%i",cSave->GetName(),0,1);
1187  cSave->cd(0);
1188  ((TPad*) gROOT->FindObject(name))->Draw();
1189  ((TPad*) gROOT->FindObject(name))->cd();
1190  SetHistStyle(fHistEvent[0]);
1191  cout << "******* " << endl;
1192  cout << "******* " << fHistEvent[0]->GetYaxis()->GetTitleOffset() << endl;
1193  fHistEvent[0]->GetXaxis()->SetLabelSize(0);
1194  fHistEvent[0]->GetYaxis()->SetTitleOffset(1);
1195  fHistEvent[0]->DrawCopy("colz");
1196  lineT->DrawLine(tmin,1,tmin,288);
1197  lineT->DrawLine(tmax,1,tmax,288);
1198  sprintf(name,"%s_%i_%i",cSave->GetName(),0,0);
1199  cSave->cd(0);
1200  ((TPad*) gROOT->FindObject(name))->Draw();
1201  ((TPad*) gROOT->FindObject(name))->cd();
1202  SetHistStyle(fHistEvent[1]);
1203  fHistEvent[1]->GetYaxis()->SetTitleOffset(1);
1204  fHistEvent[1]->GetYaxis()->SetLabelSize(fHistEvent[1]->GetYaxis()->GetLabelSize()*vcorr);
1205  fHistEvent[1]->GetYaxis()->SetTitleSize(fHistEvent[1]->GetYaxis()->GetTitleSize()*vcorr);
1206  fHistEvent[1]->GetYaxis()->SetTitleOffset(fHistEvent[1]->GetYaxis()->GetTitleOffset()/vcorr);
1207  fHistEvent[1]->GetZaxis()->SetLabelSize(fHistEvent[1]->GetZaxis()->GetLabelSize()*vcorr);
1208  fHistEvent[1]->GetZaxis()->SetTitleSize(fHistEvent[1]->GetZaxis()->GetTitleSize()*vcorr);
1209  fHistEvent[1]->GetZaxis()->SetTitleOffset(fHistEvent[1]->GetZaxis()->GetTitleOffset()/vcorr);
1210  fHistEvent[1]->DrawCopy("colz");
1211  lineT->DrawLine(tmin,1,tmin,288);
1212  lineT->DrawLine(tmax,1,tmax,288);
1213 
1214  SetHistStyle(fHistEventEmpty[0]);
1215  SetHistStyle(fHistEventEmpty[1]);
1216  fHistEventEmpty[1]->GetYaxis()->SetLabelSize(fHistEventEmpty[1]->GetYaxis()->GetLabelSize()*vcorr);
1217  fHistEventEmpty[1]->GetYaxis()->SetTitleSize(fHistEventEmpty[1]->GetYaxis()->GetTitleSize()*vcorr);
1218  fHistEventEmpty[1]->GetYaxis()->SetTitleOffset(fHistEventEmpty[1]->GetYaxis()->GetTitleOffset()/vcorr);
1219 
1220 
1221  Int_t run = rh->GetRun();
1222  Int_t evtno = evt->GetHeader()->GetEvtNo();
1223 
1224  cSave->SaveAs(Form("%s/run%d_event%d_linZ.png",savedir,run,evtno));
1225  cSave->SaveAs(Form("%s/run%d_event%d_linZ.pdf",savedir,run,evtno));
1226  cSave->SaveAs(Form("%s/run%d_event%d_linZ.C",savedir,run,evtno));
1227  cSaveSp->SaveAs(Form("%s/run%d_event%d_Spectrum.pdf",savedir,run,evtno));
1228  cSaveSp->SaveAs(Form("%s/run%d_event%d_Spectrum.png",savedir,run,evtno));
1229 
1230  return cSave;
1231 }
1232 
1233 // TCanvas* HarpoTools::SaveEvent(HarpoEvent* evt, const char* savedir, HarpoRunHeader* rh)
1234 // {
1235 
1236 
1237 // Bool_t isSim = rh->GetSimDataFlag();
1238 // cout << "SIMULATION ? " << isSim << endl;
1239 
1240 // gStyle->SetOptStat(0);
1241 
1242 
1243 // TH2F* fHistEvent[2];
1244 // fHistEvent[0] = new TH2F("fHistEventX",";time [30ns bin]; X channel",512,0,512,288,0,288);
1245 // fHistEvent[1] = new TH2F("fHistEventY",";time [30ns bin]; Y channel",512,0,512,288,0,288);
1246 
1247 // TH2F* fHistEventEmpty[2];
1248 // fHistEventEmpty[0] = new TH2F("fHistEventEmptyX",";time [30ns bin]; X channel",512,0,512,288,0,288);
1249 // fHistEventEmpty[1] = new TH2F("fHistEventEmptyY",";time [30ns bin]; Y channel",512,0,512,288,0,288);
1250 
1251 // TH1F* fHistSpectrum[2];
1252 // fHistSpectrum[0] = new TH1F("fHistSpectrumX",";time [30ns bin]; X Q [ADC]",512,0,512);
1253 // fHistSpectrum[1] = new TH1F("fHistSpectrumY",";time [30ns bin]; Y Q [ADC]",512,0,512);
1254 
1255 // Info("DisplayMap","%p",evt);
1256 
1257 // if(evt == 0) return 0;
1258 
1259 // for(Int_t ndet=0;ndet<2;ndet++) {
1260 // if(!gHDetSet->isExist(ndet)) continue;
1261 // HarpoDccMap * m = evt->GetDccMap(ndet);
1262 // if ( m == NULL ) continue;
1263 // fHistEvent[ndet]->Reset();
1264 // fHistSpectrum[ndet]->Reset();
1265 // for(Int_t i=1;i<NADC;i++){ //Time bins
1266 // // Double_t sigmaQ = 0;
1267 // Double_t Qt=0;
1268 // for(Int_t j=0;j<NCHAN;j++){ // Channels
1269 // Double_t q = m->GetData(j,i);
1270 // fHistEvent[ndet]->SetBinContent(i+1,j+1,q);
1271 // if(q >= 0)
1272 // Qt=Qt+q;
1273 // }
1274 // fHistSpectrum[ndet]->SetBinContent(i+1,Qt);
1275 // }
1276 // fHistEvent[ndet]->SetMinimum(1);
1277 // fHistEvent[ndet]->SetMaximum(4096);
1278 // }
1279 
1280 
1281 // // InitEvent(evt);
1282 
1283 // TLatex* latex = new TLatex();
1284 // latex->SetTextFont(132);
1285 // latex->SetTextAlign(12);
1286 // latex->SetTextSize(0.08);
1287 
1288 // HarpoRecoEvent* reco = evt->GetRecoEvent();
1289 // TClonesArray* matchArray = reco->GetMatchingArray();
1290 // TClonesArray* trArray = reco->GetTracksArray();
1291 // Int_t nMatch = matchArray->GetEntries();
1292 
1293 // TCanvas* cSave;
1294 // cSave = new TCanvas("cSave","c",1100,1100);
1295 // // cSave->Divide(2,1);
1296 
1297 // TCanvas* cSaveLog;
1298 // cSaveLog = new TCanvas("cSaveLog","log",1100,1100);
1299 // // cSaveLog->Divide(2,1);
1300 
1301 // TCanvas* cSaveSp;
1302 // cSaveSp = new TCanvas("cSaveSp","spectrum",1100,1100);
1303 // // cSaveSp->Divide(2,1);
1304 
1305 // TCanvas* cSaveAll;
1306 // cSaveAll = new TCanvas("cSaveAll","all",1500,500);
1307 // cSaveAll->Divide(3);
1308 // TVirtualPad* cSaveAll1 = cSaveAll->GetPad(1);
1309 // cSaveAll1->SetName("cSaveAll1");
1310 // TVirtualPad* cSaveAll2 = cSaveAll->GetPad(2);
1311 // cSaveAll2->SetName("cSaveAll2");
1312 
1313 // Int_t nPlanes = 2;
1314 // Double_t left = 0.12, right = 0.12, bottom = 0.07, top = 0.01;
1315 // TClonesArray* pads = CanvasPartition(cSave,1,nPlanes,left,right,bottom,top);
1316 // TClonesArray* padsLog = CanvasPartition(cSaveLog,1,nPlanes,left,right,bottom,top);
1317 // // TClonesArray* padsSp = CanvasPartition(cSaveSp,1,nPlanes,left,right,bottom,top);
1318 // TClonesArray* padsAll1 = CanvasPartition(cSaveAll1,1,nPlanes,left,right,bottom,top);
1319 // TClonesArray* padsAll2 = CanvasPartition(cSaveAll2,1,nPlanes,left,right,bottom,top);
1320 
1321 // // Double_t vcorr = 455./545, hcorr = 1;
1322 // Double_t vcorr = ((1. - bottom - top)/2. + top)/((1. - bottom - top)/2. + bottom);
1323 // //Double_t hcorr = 1;
1324 
1325 // TLine* lineT = new TLine();
1326 // lineT->SetLineStyle(10);
1327 // lineT->SetLineWidth(2);
1328 // lineT->SetLineColor(kGray+1);
1329 // Double_t tmin = 90., tmax = 415.;
1330 
1331 // // if(fMatchingType == MATCHING_BASIC){
1332 // // for(Int_t i = 0; i<nMatch; i++){
1333 // // HarpoRecoMatching* match = (HarpoRecoMatching*)matchArray->At(i);
1334 // // TCanvas* cMatch = new TCanvas(Form("cMatch%d",i));
1335 // // ((HarpoMatching*)fMatching[fMatchingType])->DrawMatching(match,cMatch);
1336 // // Int_t iTrX1 = match->GetiMatchTrX();
1337 // // Int_t iTrX2 = match->GetiMatchTrX2();
1338 // // Int_t iTrY1 = match->GetiMatchTrY();
1339 // // Int_t iTrY2 = match->GetiMatchTrY2();
1340 // // cMatch->SaveAs(Form("%s/run%d_event%ld_match_%d-%d_%d-%d.png",savedir,fReader->GetRunHeader()->GetRun(),fReader->GetReadEvts(),iTrX1,iTrX2,iTrY1,iTrY2));
1341 // // cMatch->SaveAs(Form("%s/run%d_event%ld_match_%d-%d_%d-%d.pdf",savedir,fReader->GetRunHeader()->GetRun(),fReader->GetReadEvts(),iTrX1,iTrX2,iTrY1,iTrY2));
1342 // // }
1343 // // }
1344 
1345 // if(isSim){ // FIXME
1346 // for(Int_t plane = 0; plane<2; plane++){
1347 // for(Int_t i = 0; i<NADC-35; i++){
1348 // for(Int_t j = 0; j<NCHAN; j++){
1349 // fHistEvent[plane]->SetBinContent(NADC-i+1,j+1,fHistEvent[plane]->GetBinContent(NADC-35-i+1,j+1));
1350 // }
1351 // }
1352 // }
1353 // }
1354 
1355 // char name[16];
1356 // sprintf(name,"%s_%i_%i",cSave->GetName(),0,1);
1357 // std::cout << name << std::endl;
1358 // cSave->cd(0);
1359 // ((TPad*) gROOT->FindObject(name))->Draw();
1360 // ((TPad*) gROOT->FindObject(name))->cd();
1361 // SetHistStyle(fHistEvent[0]);
1362 // fHistEvent[0]->DrawCopy("colz");
1363 // lineT->DrawLine(tmin,1,tmin,288);
1364 // lineT->DrawLine(tmax,1,tmax,288);
1365 // sprintf(name,"%s_%i_%i",cSave->GetName(),0,0);
1366 // std::cout << name << std::endl;
1367 // cSave->cd(0);
1368 // ((TPad*) gROOT->FindObject(name))->Draw();
1369 // ((TPad*) gROOT->FindObject(name))->cd();
1370 // SetHistStyle(fHistEvent[1]);
1371 // fHistEvent[1]->GetYaxis()->SetLabelSize(fHistEvent[1]->GetYaxis()->GetLabelSize()*vcorr);
1372 // fHistEvent[1]->GetYaxis()->SetTitleSize(fHistEvent[1]->GetYaxis()->GetTitleSize()*vcorr);
1373 // fHistEvent[1]->GetYaxis()->SetTitleOffset(fHistEvent[1]->GetYaxis()->GetTitleOffset()/vcorr);
1374 // fHistEvent[1]->DrawCopy("colz");
1375 // lineT->DrawLine(tmin,1,tmin,288);
1376 // lineT->DrawLine(tmax,1,tmax,288);
1377 
1378 // sprintf(name,"%s_%i_%i",cSaveLog->GetName(),0,1);
1379 // std::cout << name << std::endl;
1380 // cSaveLog->cd(0);
1381 // ((TPad*) gROOT->FindObject(name))->Draw();
1382 // ((TPad*) gROOT->FindObject(name))->SetLogz();
1383 // ((TPad*) gROOT->FindObject(name))->cd();
1384 // //SetHistStyle(fHistEvent[0]);
1385 // fHistEvent[0]->DrawCopy("colz");
1386 // lineT->DrawLine(tmin,1,tmin,288);
1387 // lineT->DrawLine(tmax,1,tmax,288);
1388 // sprintf(name,"%s_%i_%i",cSaveLog->GetName(),0,0);
1389 // std::cout << name << std::endl;
1390 // cSaveLog->cd(0);
1391 // ((TPad*) gROOT->FindObject(name))->Draw();
1392 // ((TPad*) gROOT->FindObject(name))->SetLogz();
1393 // ((TPad*) gROOT->FindObject(name))->cd();
1394 // //SetHistStyle(fHistEvent[1]);
1395 // fHistEvent[1]->DrawCopy("colz");
1396 // lineT->DrawLine(tmin,1,tmin,288);
1397 // lineT->DrawLine(tmax,1,tmax,288);
1398 
1399 
1400 
1401 
1402 // sprintf(name,"%s_%i_%i",cSaveAll1->GetName(),0,1);
1403 // std::cout << name << std::endl;
1404 // cSaveAll1->cd(0);
1405 // ((TPad*) gROOT->FindObject(name))->Draw();
1406 // ((TPad*) gROOT->FindObject(name))->cd();
1407 // SetHistStyle(fHistEvent[0]);
1408 // fHistEvent[0]->DrawCopy("colz");
1409 // lineT->DrawLine(tmin,1,tmin,288);
1410 // lineT->DrawLine(tmax,1,tmax,288);
1411 // sprintf(name,"%s_%i_%i",cSaveAll1->GetName(),0,0);
1412 // std::cout << name << std::endl;
1413 // cSaveAll1->cd(0);
1414 // ((TPad*) gROOT->FindObject(name))->Draw();
1415 // ((TPad*) gROOT->FindObject(name))->cd();
1416 // SetHistStyle(fHistEvent[1]);
1417 // fHistEvent[1]->GetYaxis()->SetLabelSize(fHistEvent[1]->GetYaxis()->GetLabelSize()*vcorr);
1418 // fHistEvent[1]->GetYaxis()->SetTitleSize(fHistEvent[1]->GetYaxis()->GetTitleSize()*vcorr);
1419 // fHistEvent[1]->GetYaxis()->SetTitleOffset(fHistEvent[1]->GetYaxis()->GetTitleOffset()/vcorr);
1420 // fHistEvent[1]->DrawCopy("colz");
1421 // lineT->DrawLine(tmin,1,tmin,288);
1422 // lineT->DrawLine(tmax,1,tmax,288);
1423 
1424 
1425 
1426 
1427 
1428 // SetHistStyle(fHistEventEmpty[0]);
1429 // SetHistStyle(fHistEventEmpty[1]);
1430 // fHistEventEmpty[1]->GetYaxis()->SetLabelSize(fHistEventEmpty[1]->GetYaxis()->GetLabelSize()*vcorr);
1431 // fHistEventEmpty[1]->GetYaxis()->SetTitleSize(fHistEventEmpty[1]->GetYaxis()->GetTitleSize()*vcorr);
1432 // fHistEventEmpty[1]->GetYaxis()->SetTitleOffset(fHistEventEmpty[1]->GetYaxis()->GetTitleOffset()/vcorr);
1433 
1434 // Int_t nTr = trArray->GetEntries();
1435 // // if(fTrackingType==2){
1436 // // Int_t ntrX = ((HarpoKalmanTracking*)fTracking[2])->GetNtr(0);
1437 // // Int_t ntrY = ((HarpoKalmanTracking*)fTracking[2])->GetNtr(1);
1438 // // if(ntrX>ntrY) ntrY = ntrX;
1439 // // const Int_t ntr = ntrY;//fTracking2->GetNtr(plane);
1440 // // TGraph* g[2][ntr];
1441 // // TLegend* l[2];
1442 
1443 // // TClonesArray* trArrayK = reco->GetKalmanTracksArray();
1444 // // Int_t nTrK = trArrayK->GetEntries();
1445 // // TGraph* g2[2][nTrK];
1446 // // for(Int_t i = 0; i<nTrK; i++){
1447 // // g2[0][i] = new TGraph();
1448 // // g2[1][i] = new TGraph();
1449 // // }
1450 // // TClonesArray* clArray = reco->GetClustersArray();
1451 // // Int_t nCl = clArray->GetEntries();
1452 // // for(Int_t icl = 0; icl<nCl; icl++){
1453 // // HarpoRecoClusters* cluster = (HarpoRecoClusters*)clArray->At(icl);
1454 // // Int_t plane = cluster->GetPlane();
1455 // // Int_t idTr = cluster->GetIdClusterTrack();
1456 // // if(plane!=XPLANE && plane !=YPLANE) continue;
1457 // // if(idTr<0) continue;
1458 // // // Int_t idTr = fTracking2->GetId(idcluster,plane);
1459 // // //Info("DisplayTracks","plane = %d, idTr = %d (%g, %g)", plane, idTr,cluster->GetZfit(0),cluster->GetXfit(0));
1460 
1461 // // g2[plane][idTr]->SetPoint(g2[plane][idTr]->GetN(),cluster->GetZfit(0),cluster->GetXfit(0));
1462 // // }
1463 
1464 
1465 
1466 // // Int_t colorList[2][ntr];
1467 // // for(Int_t plane = 0; plane<2; plane++){
1468 // // sprintf(name,"%s_%i_%i",cSaveAll2->GetName(),0,1-plane);
1469 // // std::cout << name << std::endl;
1470 // // cSaveAll2->cd(0);
1471 // // ((TPad*) gROOT->FindObject(name))->Draw();
1472 // // ((TPad*) gROOT->FindObject(name))->cd();
1473 // // fHistEventEmpty[plane]->DrawCopy();
1474 // // lineT->DrawLine(tmin,1,tmin,288);
1475 // // lineT->DrawLine(tmax,1,tmax,288);
1476 // // l[plane] = new TLegend(0.1,0.7 + 0.01*plane,0.3,.99 + 0.01*plane);
1477 // // Int_t color = 2;
1478 // // for(Int_t itr = 0; itr<nTrK; itr++){
1479 // // HarpoRecoKalmanTracks* track = (HarpoRecoKalmanTracks*)trArrayK->At(itr);
1480 // // Int_t trId = track->GetNtrack();
1481 // // if(plane != track->GetPlane()) continue;
1482 // // if(!g2[plane][trId]) continue;
1483 // // if(g2[plane][trId]->GetN()<1) continue;
1484 // // Info("DisplayTracks","Plane %d, Tr %d => Ncl = %d",plane, trId,g2[plane][trId]->GetN());
1485 // // g2[plane][trId]->SetMarkerColor(trId+2);
1486 // // g2[plane][trId]->SetMarkerStyle(6);
1487 // // g2[plane][trId]->Draw("Psame");
1488 // // l[plane]->AddEntry(g2[plane][trId],Form("%d",trId),"P");
1489 // // }
1490 // // // for(Int_t itr = 0; itr<ntr; itr++){
1491 // // // g[plane][itr] = fTracking2->GetGraph(itr,plane);
1492 // // // if(!g[plane][itr]) continue;
1493 // // // // if(g[plane][itr] == 0) continue;
1494 // // // // cout << itr << " ===> " << g[plane][itr]->GetN() << endl;
1495 // // // if(g[plane][itr]->GetN()<1) continue;
1496 // // // g[plane][itr]->SetMarkerStyle(6);
1497 // // // g[plane][itr]->SetMarkerColor(color);
1498 // // // colorList[plane][itr] = color;
1499 // // // color++;
1500 // // // g[plane][itr]->Draw("Psame");
1501 // // // l[plane]->AddEntry(g[plane][itr],Form("%d",itr),"P");
1502 // // // }
1503 // // //l[plane]->Draw();
1504 // // }
1505 
1506 
1507 // // }
1508 
1509 
1510 
1511 // Double_t angleX[10], angleY[10];
1512 // Int_t nclX[10], nclY[10];
1513 // Int_t planeTr[10];
1514 // for(Int_t itr = 0; itr<nTr; itr++){
1515 
1516 // HarpoRecoTracks* track = (HarpoRecoTracks*)trArray->At(itr);
1517 
1518 // Int_t ndet = track->GetPlane();
1519 // // Double_t theta = track->GetMtheta();
1520 // // Double_t rho = track->GetMrho();
1521 // Double_t angX=track->GetAngleTrack();;
1522 // if(ndet==0) cout<<"angle="<<angX<<endl;
1523 // planeTr[itr] = ndet;
1524 // if(ndet==0) angleX[itr]=track->GetAngleTrack();
1525 // if(ndet==1) angleY[itr]=track->GetAngleTrack();
1526 // if(ndet==0) nclX[itr]=track->GetNclusterTrack();
1527 // if(ndet==1) nclY[itr]=track->GetNclusterTrack();
1528 // // Int_t rlambda=0;
1529 
1530 // //Int_t color = itr+2;
1531 // sprintf(name,"%s_%i_%i",cSaveAll2->GetName(),0,1-ndet);
1532 // std::cout << name << std::endl;
1533 // cSaveAll2->cd(0);
1534 // //((TPad*) gROOT->FindObject(name))->Draw();
1535 // ((TPad*) gROOT->FindObject(name))->cd();
1536 
1537 // // TF1* line = new TF1("line","pol1",0,511);
1538 // // // if(rho<0){ theta = TMath::Pi()/2 - theta; }
1539 // // // else rho = -rho;
1540 // // line->SetParameter(0,rho/TMath::Cos(theta) + 511./2.*TMath::Tan(theta) + 144);
1541 // // // line->SetParameter(1, - 1./TMath::Tan(theta));
1542 // // line->SetParameter(1, - TMath::Tan(theta));
1543 // // line->SetLineColor(color);
1544 
1545 // // line->DrawCopy("same");
1546 // // line->Delete();
1547 
1548 // // TEllipse* pStart = new TEllipse();
1549 // // pStart->SetFillColor(color);
1550 // // pStart->DrawEllipse(track->GetZstart(),track->GetXstart(),5,0,0,360,0);
1551 // // pStart->Delete();
1552 // // TEllipse* pEnd = new TEllipse();
1553 // // pEnd->SetFillColor(color);
1554 // // pEnd->SetFillStyle(3001);
1555 // // pEnd->DrawEllipse(track->GetZend(),track->GetXend(),5,0,0,360,0);
1556 // // pEnd->Delete();
1557 
1558 // // TLine* line = new TLine();
1559 // // line->SetLineColor(color);
1560 
1561 // }
1562 
1563 
1564 // TH3F* hDummy3D = new TH3F("hDummy3D",";Z;X;Y",10,0,511,10,0,288,10,0,288);
1565 // cSaveAll->cd(3);
1566 // hDummy3D->Draw();
1567 // // MakeNiceHisto(hDummy3D,cTab->GetPad(1),"lego");
1568 // const Int_t kNtrack = 100;
1569 // Int_t used[kNtrack][kNtrack];
1570 // for(Int_t i = 0; i<kNtrack; i++)
1571 // for(Int_t j = 0; j<kNtrack; j++)
1572 // used[i][j] = kBlack;
1573 // Int_t color = 2;
1574 // Double_t z0[nMatch], z1[nMatch], x0[nMatch], y0[nMatch], slopeX[nMatch], slopeY[nMatch];
1575 // for(Int_t i = 0; i<nMatch; i++){
1576 // x0[i] = -1000;
1577 // y0[i] = -1000;
1578 // slopeX[i] = -1000;
1579 // slopeY[i] = -1000;
1580 // cSaveAll->cd(3);
1581 // HarpoRecoMatching* match = (HarpoRecoMatching*)matchArray->At(i);
1582 // Int_t trX = match->GetiMatchTrX();
1583 // Int_t trY = match->GetiMatchTrY();
1584 // if(used[trX][trY] == kBlack){
1585 // used[trX][trY] = color;
1586 // color++;
1587 // }
1588 
1589 // // g->SetMarkerColor(used[trX][trY]);
1590 
1591 
1592 // for(Int_t itr = 0; itr<nTr; itr++){
1593 
1594 // HarpoRecoTracks* track = (HarpoRecoTracks*)trArray->At(itr);
1595 // Int_t trId = track->GetNtrack();
1596 // Int_t plane = track->GetPlane();
1597 
1598 // if(trId == trX && plane == XPLANE){
1599 // // x0[i] = track->GetMrho();
1600 // if(track->GetZstart()<track->GetZend()){
1601 // z0[i] = track->GetZstart();
1602 // z1[i] = track->GetZend();
1603 // }else{
1604 // z1[i] = track->GetZstart();
1605 // z0[i] = track->GetZend();
1606 // }
1607 // // slopeX[i] = track->GetMtheta();
1608 // slopeX[i] = TMath::Tan(track->GetAngleTrack());
1609 // x0[i] = track->GetXstart() - track->GetZstart()*slopeX[i];
1610 // }
1611 // if(trId == trY && plane == YPLANE){
1612 // // y0[i] = track->GetMrho();
1613 // //slopeY[i] = track->GetMtheta();
1614 // slopeY[i] = TMath::Tan(track->GetAngleTrack());
1615 // y0[i] = track->GetXstart() - track->GetZstart()*slopeY[i];
1616 // }
1617 // }
1618 // TPolyLine3D *l = new TPolyLine3D(2);
1619 // l->SetPoint(0,z0[i],x0[i] + z0[i]*slopeX[i],y0[i] + z0[i]*slopeY[i]);
1620 // l->SetPoint(1,500,x0[i] + 500*slopeX[i],y0[i]+500*slopeY[i]);
1621 // l->SetLineColor(used[trX][trY]);
1622 // l->Draw();
1623 // }
1624 
1625 
1626 // // HarpoRunHeader* rh = evt->GetRunHeader();
1627 // Double_t egamma = 0;
1628 // if(rh!=NULL) egamma = rh->GetEgamma();
1629 // if(egamma>0){
1630 // sprintf(name,"%s_%i_%i",cSave->GetName(),0,1);
1631 // cSave->cd(0);
1632 // ((TPad*) gROOT->FindObject(name))->cd();
1633 // latex->SetTextSize(0.12);
1634 // //latex->DrawLatex(20,260,Form("E_{#gamma} = %.3g MeV",egamma));
1635 // }
1636 
1637 
1638 // Int_t run = rh->GetRun();
1639 // Int_t evtno = evt->GetHeader()->GetEvtNo();
1640 
1641 // cSave->SaveAs(Form("%s/run%d_event%d_linZ.png",savedir,run,evtno));
1642 // cSave->SaveAs(Form("%s/run%d_event%d_linZ.pdf",savedir,run,evtno));
1643 // cSave->SaveAs(Form("%s/run%d_event%d_linZ.C",savedir,run,evtno));
1644 // cSaveLog->SaveAs(Form("%s/run%d_event%d_logZ.pdf",savedir,run,evtno));
1645 // cSaveSp->SaveAs(Form("%s/run%d_event%d_Spectrum.pdf",savedir,run,evtno));
1646 // cSaveSp->SaveAs(Form("%s/run%d_event%d_Spectrum.png",savedir,run,evtno));
1647 // cSaveAll->SaveAs(Form("%s/run%d_event%d_all.png",savedir,run,evtno));
1648 // cSaveAll->SaveAs(Form("%s/run%d_event%d_all.pdf",savedir,run,evtno));
1649 // cSaveAll->SaveAs(Form("%s/run%d_event%d_all.C",savedir,run,evtno));
1650 
1651 
1652 
1653 
1654 // std::ofstream textfile;
1655 // textfile.open(Form("%s/run%d_event%d_X.txt",savedir,run,evtno), std::ofstream::out);
1656 // for(Int_t i = 1; i<=fHistEvent[0]->GetXaxis()->GetNbins(); i++)
1657 // for(Int_t j = 1; j<=fHistEvent[0]->GetYaxis()->GetNbins(); j++)
1658 // if(fHistEvent[0]->GetBinContent(i,j)>0)
1659 // textfile << i << "\t" << j << endl;
1660 // textfile.close();
1661 // textfile.open(Form("%s/run%d_event%d_X_2.txt",savedir,run,evtno), std::ofstream::out);
1662 // for(Int_t i = 1; i<=fHistEvent[0]->GetXaxis()->GetNbins(); i++)
1663 // for(Int_t j = 1; j<=fHistEvent[0]->GetYaxis()->GetNbins(); j++)
1664 // if(fHistEvent[0]->GetBinContent(i,j)>0)
1665 // textfile << i << "\t" << j << "\t" << fHistEvent[0]->GetBinContent(i,j) << endl;
1666 // textfile.close();
1667 // textfile.open(Form("%s/run%d_event%d_Y.txt",savedir,run,evtno), std::ofstream::out);
1668 // for(Int_t i = 1; i<=fHistEvent[1]->GetXaxis()->GetNbins(); i++)
1669 // for(Int_t j = 1; j<=fHistEvent[1]->GetYaxis()->GetNbins(); j++)
1670 // if(fHistEvent[1]->GetBinContent(i,j)>0)
1671 // textfile << i << "\t" << j << endl;
1672 // textfile.close();
1673 // textfile.open(Form("%s/run%d_event%d_Y_2.txt",savedir,run,evtno), std::ofstream::out);
1674 // for(Int_t i = 1; i<=fHistEvent[0]->GetXaxis()->GetNbins(); i++)
1675 // for(Int_t j = 1; j<=fHistEvent[0]->GetYaxis()->GetNbins(); j++)
1676 // if(fHistEvent[1]->GetBinContent(i,j)>0)
1677 // textfile << i << "\t" << j << "\t" << fHistEvent[1]->GetBinContent(i,j) << endl;
1678 // textfile.close();
1679 
1680 // return cSave;
1681 // }
A class hold HARPO run iformation.
TH1F * GetTruncProfile(TH2F *h, Int_t type=0, Double_t tl=0., Double_t th=0.7)
Definition: HarpoTools.cxx:345
void MakeNice1dHistoPad(TH1 *hist, TVirtualPad *c1, Double_t scaleX, Double_t scaleY, const char *opt, Bool_t copy)
Bool_t GetRunConfig(Long_t nrun, const TString *dbUrl=NULL)
Query Db for given run Only this function in class interact wich DataBase. Must be called in HarpoRaw...
#define NCHAN
Definition: HarpoDccMap.h:16
TTree * getTree(Double_t angle=-1000, Double_t energy=-1, Int_t pola=100)
Definition: HarpoTools.cxx:130
Get Run Configuration info by run number. The class query MySQL databe use GetRunConfig Method Only t...
Double_t GetData(Int_t i, Int_t j)
Set/Get Data Cell.
Definition: HarpoDccMap.cxx:84
Bool_t isExist(ULong_t det)
Detecror date exist //! Number of Real Detectors.
Definition: HarpoDetSet.h:33
A class hold HARPO run iformation.
TCanvas * SaveEvent(HarpoEvent *evt, const char *dirname, HarpoRunHeader *rh, Bool_t bw=0)
Long_t GetEvtNo()
Get Event Number.
TClonesArray * CanvasPartition(TVirtualPad *C, const Int_t Nx, const Int_t Ny, Float_t lMargin, Float_t rMargin, Float_t bMargin, Float_t tMargin)
static int type
Bool_t GetSimDataFlag()
unpacked dcc data The class contains the data map for DCC or Feminos The data is stored as a 2D TMatr...
Definition: HarpoDccMap.h:29
void updateConfData(Double_t energy, Double_t angle, Int_t p, Int_t simu, Int_t flag, const char *name, Double_t val)
Definition: HarpoTools.cxx:845
TGraph * getTP(const char *filename, UInt_t timestart=0, UInt_t timeend=2000000000, Int_t night=0)
Definition: HarpoTools.cxx:216
UInt_t getTime(Int_t run)
Definition: HarpoTools.cxx:166
void updateRunData(Int_t run, const char *name, Double_t val)
Definition: HarpoTools.cxx:694
#define NADC
Definition: HarpoDccMap.h:18
void SetHistStyle(TH1 *hist)
TGraph * getTemperature()
Definition: HarpoTools.cxx:298
TDirectory * OpenSimHistFile(const char *filename, const char *dir, Int_t &run, Int_t update=0, Int_t verbose=1)
Definition: HarpoTools.cxx:14
TDirectory * OpenHistFile(Int_t run, const char *dir, const char *extra="", Int_t update=0)
Definition: HarpoTools.cxx:55
Double_t getDoubleVal(Int_t run, const char *name, const TString *dburl=NULL)
Bool_t GetVal(const TString field, TString &val)
Return value of existing field in Tstring.
Double_t TruncMean(TArrayD *vect, Double_t tl=0., Double_t th=0.7)
Definition: HarpoTools.cxx:425
Bool_t GetType(const TString field, TString &type)
Return Type of field in Tstring.
const ULong_t tmax
HarpoEventHeader * GetHeader()
Definition: HarpoEvent.cxx:80
Double_t getRunData(Int_t run, const char *name)
Definition: HarpoTools.cxx:986
A class store HARPO row event data and header. Provide access metods to the row event data...
Definition: HarpoEvent.h:29
TGraph * getPressure()
Definition: HarpoTools.cxx:259
const ULong_t gkNDetectors
Definition: HarpoDet.h:14
HarpoDccMap * GetDccMap(Long_t plane=XDCC)
Definition: HarpoEvent.cxx:108
TCanvas * drawTPRatio(UInt_t timestart, UInt_t timeend, const char *cname="cTPRatio")
Definition: HarpoTools.cxx:445
void SetDetHeader(HarpoDetHeader *hdr, UInt_t ndet=XDCC)
Double_t TruncSum(TArrayD *vect, Double_t tl, Double_t th, Double_t &minTrunc, Double_t &maxTrunc, Double_t &norm, Double_t &truncSum2, Double_t thr=10)
Definition: HarpoTools.cxx:390
TString getVal(Int_t run, const char *name, const TString *dburl=NULL)
R__EXTERN HarpoDetSet * gHDetSet
Definition: HarpoDetSet.h:71
HarpoRunHeader * getRunHeader(Int_t run)
Definition: HarpoTools.cxx:92