GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GSI/EventPSAWatchers.C
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2010 by Olivier Stezowski *
3  * Copyright (C) 2010 by Christian Finck *
4  * stezow(AT)ipnl.in2p3.fr *
5  * *
6  * This program is free software; you can redistribute it and/or modify *
7  * it under the terms of the GNU General Public License as published by *
8  * the Free Software Foundation; either version 2 of the License, or *
9  * (at your option) any later version. *
10  * *
11  * This program is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14  * GNU General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU General Public License *
17  * along with this program; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20  ***************************************************************************/
21 
22 // Watcher definition
23 #ifndef _EventPSAWatchers
24 #include "EventPSAWatchers.h"
25 #endif
26 
27 #ifndef ROOT_TBox
28 #include "TBox.h"
29 #endif
30 
31 #ifndef ROOT_TCanvas
32 #include "TCanvas.h"
33 #endif
34 
35 #ifndef ROOT_TGeoMatrix
36 #include "TGeoMatrix.h"
37 #endif
38 
39 #ifndef ROOT_TGToolTip
40 #include "TGToolTip.h"
41 #endif
42 
43 #ifndef ROOT_TLatex
44 #include "TLatex.h"
45 #endif
46 
47 #ifndef ROOT_TMath
48 #include "TMath.h"
49 #endif
50 
51 #ifndef ROOT_TObjArray
52 #include "TObjArray.h"
53 #endif
54 
55 #ifndef ROOT_TPaveText
56 #include "TPaveText.h"
57 #endif
58 
59 #ifndef ROOT_TPolyLine
60 #include "TPolyLine.h"
61 #endif
62 
63 #ifndef ROOT_TRandom
64 #include "TRandom.h"
65 #endif
66 
67 #ifndef ROOT_TString
68 #include "TString.h"
69 #endif
70 
71 #include "TTimer.h"
72 #include "TSystem.h"
73 
74 #include "DFAgent.h"
75 #include "AgataKeyFactory.h"
76 #include "MetaWatchers.h"
77 
78 using namespace ADF;
79 
81 
82 //__________________________________________________________
84 {
85  if ( !Watcher::GetFromTrigger(trigger, "event:data:psa", fFrame) )
86  return false;
87 
88  // first extract from the current configuration the definition
89  // of the data:psa frame on the data flow
90  FactoryItem i_asked, k_defined, f_defined;
91 
92  i_asked.SetItem("Agata","data:psa",Version());
93  k_defined = ConfAgent::theGlobalAgent()->GetDFAgent()->WhichKnownKey (i_asked,i_asked);
94  f_defined = ConfAgent::theGlobalAgent()->GetDFAgent()->WhichKnownFrame (i_asked,i_asked);
95 
96  Frame *f = MainFrameFactory::theMainFactory().New(k_defined,f_defined);
97  if ( f ) { // it exists
98  if ( fPSAFrame )
99  { delete fPSAFrame; fPSAFrame = 0x0; }
100 
101  fPSAFrame = f;
102  }
103  else fFrame = 0x0;
104 
105  return fFrame != 0x0;
106 }
107 
108 //__________________________________________________________
110 {
111  if ( fFrame && fFrame->IsValid() ) {
112  fFrame->GetFrame()->Scan();
113  return fFrame->GetFrame()->GetNbSubFrame();
114  }
115 
116  return 0u;
117 }
118 
119 //__________________________________________________________
121 {
122  // does not exist
123  if ( !(which < GetNbFramePSA()) ) {
124  if ( gDebug > 3 )
125  printf("EventPSAWatcher::GetDataPSA %d %d \n",which,GetNbFramePSA());
126  return 0x0;
127  }
128  // cannot load subframe #i in fPSAFrame
129  if ( !fFrame->GetFrame()->LinkSubFrame(which,fPSAFrame) ) {
130  if ( gDebug > 3 )
131  printf("EventPSAWatcher::GetDataPSA cannot LinkSubFrame \n");
132  return 0x0;
133  }
134  // cannot read the data
135  if( fPSAFrame->Read() == 0 ) {
136  if ( gDebug > 3 )
137  printf("EventPSAWatcher::GetDataPSA cannot Read \n");
138  return 0x0;
139  }
140  // return the data interface for that frame
141  return GetDataPointer<PSAInterface>(fPSAFrame);
142 }
143 
144 //**********************************************************
145 
146 
147 const Float_t gMetric = 10.;
148 
150 
151 HitsSpectra::HitsSpectra(const char *name, const char *title, TDirectory *sp_dir, TDirectory *tag_dir) :
152  EventPSAWatcher(name,title,sp_dir,tag_dir),
153  fVertexBuilder(0x0),
154  fTrans(0x0),
155  fSpectra(180),
156  fSpectraDoppler(180),
157  fCoreCommon(0x0),
158  fGxG(0x0),
159  fGxT(0x0),
160  fCoreCommonDoppler(0x0),
161  fGxGDoppler(0x0),
162  fDistri(0x0),
163  fPosXYZ(0x0),
164  fPosXYZ_Ta(0x0)
165 {
166  fSpectra.SetOwner(false); fSpectraDoppler.SetOwner(false);
167 
168  // Vertex used for doppler correction, last registered
169  fVertexBuilder = VertexBuilder::theCurrentVertexBuilder();
170  if ( fVertexBuilder == 0x0 )
171  std::cout << "Should not be NULL " << std::endl;
172 
173  fTrans = new AgataGeometryTransformer();
174 
175  if ( gSystem->AccessPathName("CrystalPositionLookUpTable") ) { // does not exist
176  if ( gSystem->AccessPathName("CrystalPositionLookUpTable.dat") ) {
177  fLog << error << " CrystalPositionLookUpTable required " << nline;
178  }
179  else {
180  fLog << info << " Ge positions extracted from CrystalPositionLookUpTable.dat " << nline;
181  fTrans->ReadTransformations("CrystalPositionLookUpTable.dat");
182  }
183  }
184  else {
185  fLog << info << " Ge positions extracted from CrystalPositionLookUpTable.dat " << nline;
186  fTrans->ReadTransformations("CrystalPositionLookUpTable");
187  }
188 
189  for (UInt_t i = 0u; i < gNbCrys; i++ ) {
190 
191  TString tmp; TH1F *h;
192 
193  tmp = Form("Crystal_%d",i);
194  h = MakeTH1<TH1F>(tmp.Data(),"Core energy of the crystal", 4096,0,4096);
195  fSpectra.Add ( h ) ;
196 
197  tmp = Form("Crystal_track_%d",i);
198  h = MakeTH1<TH1F>(tmp.Data(),"Core energy of the crystal", 4096,0,4096);
199  fSpectraDoppler.Add ( h ) ;
200 
201  }
202  fCoreCommon = MakeTH1<TH1F>("CoreCommon","Core common spectrum",8192,0,4096);
203  fSumSpectra = MakeTH1<TH1F>("SumSpectra","Sum of all spectra",8192,0,4096);
204  fGxG = MakeTH2<TH2F>("GxG","Gamma Gamma Matrix",4096,0,4096,4096,0,4096);
205  fDistri = MakeTH1<TH1F>("CrystalDistri","Distribution of the crystal fired",180,0,180);
206  fPosXYZ = MakeTH3<TH3F>("PosXYZ","Distribution of hits in Space",100,-200,200,100,-200,200,100,-400,0);
207 
208  // fPos3D = MakeTH3<TH3F>("Pos3D","Positions of Tracked Gamma-rays ;x;y;z",200,-200,200,200,-200,200,200,-400,0);
209 
210  fPosXYZ_Ta = MakeTH3<TH3F>("PosXYZ_Ta","Distribution of hits in Space with Target hit",200,-400,400,200,-400,400,200,-400,400);
211 
212 
213 
214  fGxT = MakeTH2<TH2F>("GxT","Gamma Time Matrix",4096,0,4096,300,0,300);
215 
216  fCoreCommonDoppler = MakeTH1<TH1F>("DCoreCommon","Core common spectrum with doppler correction",8192,0,4096);
217  fGxGDoppler = MakeTH2<TH2F>("DGxG","Gamma Gamma Matrix with doppler correction",4096,0,4096,4096,0,4096);
218 
219  fFold = MakeTH1<TH1F>("Fold","Crystal Fold distributions",10,0,10);
220 }
221 
223 {
224  if (fTrans) {
225  delete fTrans; fTrans = 0x0;
226  }
227 }
228 
229 Double_t HitsSpectra::DoDopplerCorrection(const TrackedHit *hit, VertexInterface *vertex)
230 {
231  Double_t e = hit->GetE(), beta = vertex->GetBeta(), gamma = vertex->GetGamma();
232 
233  Double_t px, py, pz, dx, dy, dz;
234  vertex->GetPosition (px, py, pz);
235  vertex->GetDirection(dx, dy, dz);
236 
237  // std::cout << " " << px << " " << py << " " << pz <<std::endl;
238 
239  Double_t x = hit->GetX() - px;
240  Double_t y = hit->GetY() - py;
241  Double_t z = hit->GetZ() - pz;
242 
243  Double_t dd = x*x + y*y + z*z;
244  if( !(dd == 0.0) ) {
245  Double_t cosTheta = (x*dx + y*dy + z*dz)/::sqrt(dd);
246  e = VertexInterface::DopplerCorrection(e,beta,gamma,cosTheta);
247  }
248  else e = -1.0;
249 
250  return e;
251 }
252 
253 void HitsSpectra::DoCanvas(TCanvas *c, Option_t *o)
254 {
255  TString opt = o;
256 
257  c->Divide(4,4,0.001,0.001);
258 
259  int PadNbr = 1;
260  c->cd(PadNbr);
261  fDistri->DrawCopy();
262 
263  for(int i=0 ; i<fDistri->GetNbinsX() ; i++)
264  {
265  if(fDistri->GetBinContent(i+1))
266  {
267  PadNbr++;
268  c->cd(PadNbr%16);
269  if(fSpectra[i+1]) fSpectra[fDistri->GetBinLowEdge(i+1)]->Draw();
270  }
271  if(PadNbr%16==0)
272  {
273  c = NewCanvas(Form("HitSpectra_%d_%d",PadNbr+1,PadNbr+16));
274  c->Divide(4,4,0.001,0.001);
275  }
276  }
277 
278 
279  TCanvas *OverImposedCore = NewCanvas("OverImposedCore");
280  OverImposedCore->cd();
281  bool FirstHist = true;
282  for(int i=0 ; i<fDistri->GetNbinsX() ; i++)
283  {
284  if(fDistri->GetBinContent(i+1) && fSpectra[i+1])
285  {
286  if(FirstHist)
287  {
288  fSpectra[fDistri->GetBinLowEdge(i+1)]->Draw();
289  FirstHist = false;
290  }
291  else fSpectra[fDistri->GetBinLowEdge(i+1)]->Draw("same");
292  }
293  }
294 
295 
296  TCanvas *GlobalSpectra = NewCanvas("GlobalSpectra");
297  GlobalSpectra->Divide(1,2,0.001,0.001);
298  GlobalSpectra->cd(1);
299  fCoreCommon->Draw();
300 
301  TPad *pad = new TPad("Crystal fold", "Pad for Crystal fold distribution",0.7,0.6,1,1);
302  pad->Draw();
303  pad->cd();
304  fFold->Draw();
305 
306  GlobalSpectra->cd(2);
307  fSumSpectra->Draw();
308 }
309 
310 void HitsSpectra::Exec(Option_t * /*option*/)
311 {
312  // cout << "Exec Hits sectra" <<endl;
313  Double_t xLocal, yLocal, zLocal, xGlobal, yGlobal, zGlobal; TrackedHitImp<EHit,EHit> gamma; Float_t gg[150], ggdc[150];
314 
315  // be sure the frame has been set properly
316  if ( fFrame == 0x0 || !fFrame->IsValid() ) {
317  // cout << "non valid frame" << endl;
318  return;
319  }
320  // the vertex used for doppler correction
321  VertexInterface *vertex = 0x0;
322  vertex =
323  fVertexBuilder->GetVertex();
324  TH1F *h;
325  UInt_t nb_frames = GetNbFramePSA();
326 
327  fFold->Fill(nb_frames);
328 
329  double SumEnergy = 0.;
330 
331  for(UInt_t i = 0u; i <nb_frames; i++) {
332 
333  PSAInterface *data = GetDataPSA(i);
334  gg[i] = data->GetE();
335  h = (TH1F *)fSpectra.At(data->GetUID());
336  if ( h ) {
337  h->Fill(data->GetE());
338  }
339  fGxT->Fill(data->GetE(),data->GetT());
340 
341  SumEnergy += data->GetE();
342  fCoreCommon->Fill(data->GetE());
343  fDistri->Fill(data->GetUID());
344 
345  // Now look for the hit with the highest energy, taken for Doppler correction
346  // Kind of tracking in crystal
347  Int_t nHits = data->GetNbHits();
348  Double_t max_e = 0.0;
349  //test DR
350  Double_t xt,yt,zt;
351  vertex->GetPosition(xt,yt,zt);
352  fPosXYZ_Ta->Fill(xt,yt,zt);
353 
354  for (UShort_t j = 0u; j < nHits; ++j) {
355 
356  const PSAHit* pHit = (PSAHit*)data->GetHit(j);
357  //
358  pHit->GetXYZ(xLocal, yLocal, zLocal);
359  /* if ( gDebug > 3 ) {
360  std::cout << "Global " << xGlobal << " " << yGlobal << " " << zGlobal << std::endl;
361  std::cout << "Local " << xLocal << " " << yLocal << " " << zLocal << " " << pHit->GetID() << std::endl;
362  } */
363  fTrans->Local2Global(data->GetUID(), xLocal, yLocal, zLocal, xGlobal, yGlobal, zGlobal);//y,x,z
364  fPosXYZ->Fill(xGlobal, yGlobal, zGlobal);
365  fPosXYZ_Ta->Fill(xGlobal, yGlobal, zGlobal);
366 
367  if ( pHit->GetE() > max_e ) {
368  gamma.SetXYZ(xGlobal, yGlobal, zGlobal);
369  max_e = pHit->GetE();
370  }
371  } // j
372 
373  gamma.SetE(data->GetE()); h = (TH1F *)fSpectraDoppler.At(data->GetUID());
374  if ( vertex ) {
375  Double_t edc = DoDopplerCorrection(&gamma,vertex);
376  h->Fill(edc);
377  fCoreCommonDoppler->Fill(edc);
378  ggdc[i] = edc;
379  }
380  else ggdc[i] = gg[i];
381  }
382 
383  fSumSpectra->Fill(SumEnergy);
384 
385  for(UInt_t i = 0u; i <nb_frames; i++) {
386  for(UInt_t j = i+1; j <nb_frames; j++) {
387 
388  fGxG->Fill(gg[i],gg[j]); fGxG->Fill(gg[j],gg[i]); fGxGDoppler->Fill(ggdc[i],ggdc[j]); fGxGDoppler->Fill(ggdc[j],ggdc[i]);
389  }
390  }
391 
392 }
393 
394 
395 //-------------------------------------------------------------------
396 
398 
399 Float_t HitDisplay3D::fgMetric = 10.;
400 
401 HitDisplay3D::HitDisplay3D(const char *name, const char *title, TDirectory *sp_dir, TDirectory *tag_dir):
402  EventPSAWatcher(name,title,sp_dir,tag_dir),
403  fMaxCycle(100),
404  fPathFile(Gw::AgataEventDisplay::GetDefaultAgataPath())
405 {
406  fTrans = new AgataGeometryTransformer();
407  fTrans->ReadTransformations("CrystalPositionLookUpTable.dat");
408 }
409 
411 {
412  delete fTrans;
413 }
414 
415 void HitDisplay3D::SetActive(Bool_t active)
416 {
417  TTask::SetActive(active);
418  AgataEventDisplay::Instance()->Reset();
419 }
420 
421 void HitDisplay3D::DoCanvas(TCanvas* /*c*/, Option_t* /*o*/)
422 {
423 }
424 
425 void HitDisplay3D::ShowEve(const Char_t* agataPathFile)
426 {
427  AgataEventDisplay::SetDefaultAgataPath(agataPathFile);
428  AgataEventDisplay::Instance()->BuildDefaultGeometry();
429  AgataEventDisplay::Instance()->ShowDisplay();
430 }
431 
432 void HitDisplay3D::Exec(Option_t */*option*/)
433 {
434  // be sure the frame has been set properly
435  if ( fFrame == 0x0 || !fFrame->IsValid() ) {
436  return;
437  }
438 
439  if ( gDebug > 3 )
440  printf("HitDisplay3D::::Exec is called %d \n",GetNbFramePSA());
441 
442  AgataEventContainer* agataContainer = AgataEventDisplay::Instance()->GetEventContainer();
443 
444  if (agataContainer->GetNofEvents() > fMaxCycle) {
445  TTask::SetActive(false);
446  return;
447  }
448 
449  static UInt_t evtNbOld = 0;
450  Frame *f = GetTrigger()->GetInputFrame(0);
451  const AgataKey* key = dynamic_cast<const AgataKey *>(f->GetKey());
452  UInt_t evtNb = key->GetEventNumber();
453  if (evtNb == evtNbOld)
454  return;
455 
456  for(UInt_t i = 0u; i < GetNbFramePSA(); i++) {
457 
458  PSAInterface *data = GetDataPSA(i);
459 
460  UInt_t nHits = data->GetNbHits();
461  //cout << "Fold " << nHits << endl;
462 
463  for (UShort_t j = 0u; j < nHits; ++j) {
464  const PSAHit* pHit = (PSAHit*)data->GetHit(j);
465  StdHit* hit = agataContainer->NewHit();
466  Float_t xLocal = pHit->GetX();
467  Float_t yLocal = pHit->GetY();
468  Float_t zLocal = pHit->GetZ();
469 
470  Float_t xGlobal, yGlobal, zGlobal;
471  fTrans->Local2Global(pHit->GetID(), xLocal, yLocal, zLocal, xGlobal, yGlobal, zGlobal);
472 
473  if ( gDebug > 3 ) {
474  std::cout << "Global " << xGlobal << " " << yGlobal << " " << zGlobal << std::endl;
475  std::cout << "Local " << xLocal << " " << yLocal << " " << zLocal << " " << pHit->GetE() << std::endl;
476  }
477  hit->SetX(xGlobal/fgMetric);
478  hit->SetY(yGlobal/fgMetric);
479  hit->SetZ(zGlobal/fgMetric);
480  hit->SetE(pHit->GetE());
481  }
482  }
483  agataContainer->FillHits();
484  evtNbOld = evtNb;
485 }
486 
487 
488 //**********************************************************
489 
491 
492 const Double_t RateDisplay::fgkDRho = 3.;
493 const Double_t RateDisplay::fgkRho1 = 5.;
494 const Double_t RateDisplay::fgkRho2 = 80.;
495 const Double_t RateDisplay::fgkDRange = 400.;
496 const Int_t RateDisplay::fgkNofPoints = 5;
497 const Int_t RateDisplay::fgkNofSectors = 6;
498 const Int_t RateDisplay::fgkNofSlices = 6;
499 const Int_t RateDisplay::fgkNofCrystals = 60;
500 const Int_t RateDisplay::fgkNDivX = 5;
501 const Int_t RateDisplay::fgkNDivY = 3;
502 
503 //__________________________________________________________
504 RateDisplay::RateDisplay(const Char_t *name, const Char_t *title, TDirectory *sp_dir, TDirectory *tag_dir) :
505  EventPSAWatcher(name,title,sp_dir,tag_dir),
506  fSectorList(new TObjArray(fgkNofSectors*fgkNofCrystals)),
507  fLabelList(new TObjArray(fgkNofCrystals)),
508  fRateList(new TObjArray(fgkNofSectors*fgkNofCrystals)),
509  fTransf(new AgataGeometryTransformer()),
510  fCountCoreMax(1),
511  fCountMaxAll(1),
512  fCurrentCycle(0),
513  fMaxCycle(200),
514  fDepth(1),
515  fNormByAll(true),
516  fTimer(new TTimer()),
517  fRefresh(3),
518  fDepthText(new TLatex()),
519  fBox(new TBox(0, fgkDRange, 0, fgkDRange)),
520  fInfoTip(new TGToolTip(fBox, "", 350))
521 {
522 
523  // Set owner for delete
524  fSectorList->SetOwner(true);
525  fLabelList->SetOwner(true);
526  fRateList->SetOwner(true);
527 
528  // count arrays
529  for (Int_t i = 0; i < fgkNofSlices+1; ++i) {
530  fCountArray[i] = new TArrayI(fgkNofSectors*fgkNofCrystals);
531  fCountArray[i]->Reset();
532  }
533 
534  fCountMax = new TArrayI(fgkNofCrystals);
535  fCountMax->Reset(1);
536 
537  // create cluster & rate display
538  for (Int_t j = 0; j < fgkNDivY; ++j)
539  for (Int_t i = 0; i < fgkNDivX; ++i) {
540  AddCluster(fgkDRange*i,fgkDRange*j);
541  }
542 
543  AddRates();
544 
545  // histos
546  fHistoCntCrystal = MakeTH1<TH1I>("HistoCntCrystal","Number of counts per crystal", fgkNofCrystals, 0, fgkNofCrystals) ;
547 
548  for (Int_t i = 0; i < fgkNofCrystals; ++i) {
549  for (Int_t j = 0; j < fgkNofSectors; ++j) {
550  for (Int_t k = 0; k < fgkNofSlices; ++k) {
551  Int_t id = i*fgkNofSectors*fgkNofSlices+j*fgkNofSlices + k;
552  fHistoCntSlice[id] = MakeTH1<TH1I>(Form("%s%d_%d_%d","fHistoCntSlice", i,j, k),
553  "Number of counts per sector and per slice", fMaxCycle+1, 0, fMaxCycle);
554  fHistoCntSlice[id]->SetLineStyle(k+1);
555  fHistoCntSlice[id]->SetLineColor(j+1);
556  fHistoCntSlice[id]->SetLineWidth(2);
557  }
558  }
559  }
560 
561  fTimer->Connect("Timeout()", "RateDisplay", this, "UpdateCanvas()");
562 }
563 
564 //__________________________________________________________
566 {
567  delete fSectorList;
568  delete fLabelList;
569  delete fRateList;
570  delete fTransf;
571  delete fDepthText;
572  delete fTimer;
573  delete fInfoTip;
574  delete fBox;
575 
576  for (Int_t i = 0; i < fgkNofSlices+1; ++i)
577  delete fCountArray[i];
578 }
579 
580 //__________________________________________________________
582 {
583  // trigger on event:data:psa
584  if ( EventPSAWatcher::SetTrigger(trigger) ) {
585 
586  // the crystal id is needed
587  GObject *glob =
588  GetDataPointer<PSAInterface>(fPSAFrame)->Global();
589  fCrysID = glob->Get<UShort_t>("CrystalID");
590  fCoreE1 = glob->Get<Float_t>("CoreE1");
591  return true;
592  } else return false;
593 }
594 
595 //__________________________________________________________
596 void RateDisplay::Zero(Option_t *opt1, Option_t *opt2)
597 {
598  fCurrentCycle = 0;
599  return Watcher::Zero(opt1, opt2);
600 }
601 
602 //__________________________________________________________
603 void RateDisplay::HandleMovement(Int_t eventType, Int_t eventX, Int_t eventY, TObject* select)
604 {
605 
606  TVirtualPad* pad = TVirtualPad::Pad();
607  pad->cd();
608 
609  if (eventType == kMouseMotion) {
610  fLastX = eventX; fLastY = eventY;
611 
612  // to keep track of the last mouse position
613  fLastX = eventX; fLastY = eventY;
614  if ( select->InheritsFrom("TPolyLine") && select->GetUniqueID() != 0) {
615  fInfoTip->SetText(Form("Counts: %d", select->GetUniqueID()));
616  fInfoTip->Show(fLastX, fLastY);
617  } else
618  fInfoTip->Hide();
619  }
620 
621 }
622 
623 //__________________________________________________________
624 void RateDisplay::DoCanvas(TCanvas* c, Option_t* o)
625 {
626 
627  TString tmp(o);
628  tmp.ToLower();
629 
630  // rate display
631  if (tmp.IsNull() ) {
632 
633  if ( !c->HasConnection("ProcessedEvent(Int_t, Int_t, Int_t, TObject*)") ) {
634  c->Connect("ProcessedEvent(Int_t, Int_t, Int_t, TObject*)",
635  "RateDisplay",
636  this,
637  "HandleMovement(Int_t, Int_t, Int_t, TObject*)");
638  }
639 
640  gPad->Range(-fgkDRange/2, -fgkDRange/2, fgkDRange/2+(fgkNDivX-1)*fgkDRange, fgkDRange/2+(fgkNDivY-1)*fgkDRange);
641 
642  fSectorList->Draw();
643  fLabelList->Draw();
644  fRateList->Draw();
645  fDepthText->Draw();
646 
647  gPad->SetEditable(false);
648  }
649 
650  // histo display
651  if (tmp.BeginsWith("h") ) {
652  c->SetWindowSize(fgkDRange*fgkNDivX,fgkDRange*fgkNDivY);
653  c->Divide(fgkNDivX, fgkNDivY*3);
654 
655  for (Int_t i = 0; i < fgkNofCrystals; ++i) {
656  c->cd(i+1);
657  for (Int_t j = 0; j < fgkNofSectors; ++j) {
658  for (Int_t k = 0; k < fgkNofSlices; ++k) {
659  Int_t id = i*fgkNofSectors*fgkNofSlices+j*fgkNofSlices + k;
660  if (j == 0 && k == 0)
661  fHistoCntSlice[id]->Draw();
662  else
663  fHistoCntSlice[id]->Draw("SAME");
664  }
665  }
666  }
667  }
668  SetDepth(0, false);
669  fTimer->Start(fRefresh*1000);
670 }
671 
672 //__________________________________________________________
674 {
675  static Int_t depth = 0;
676 
677  SetDepth(depth++, false);
678  if (depth == fgkNofSlices+1) {
679  depth = 0;
680  Reset();
681  }
682 
683  // if (gPad) { // TO BE DONE
684  // gPad->Update();
685  // }
686 }
687 
688 //__________________________________________________________
689 void RateDisplay::Exec(Option_t */*option*/)
690 {
691  // Frame by Frame action
692 
693  // be sure the frame has been set properly
694  if ( fFrame == 0x0 || !fFrame->IsValid() )
695  return;
696 
697  if ( gDebug > 3 )
698  printf("RateDisplay::Exec is called %d \n",GetNbFramePSA());
699 
700 
701  Int_t tmpID = 0;
702  Int_t tmp = 0;
703 
704  // depth 0 for core energy
705  for (Int_t s = 0; s < fgkNofSectors; ++s) {
706  tmpID = fCrysID->Get()*fgkNofSectors + s;
707  tmp = fCountArray[0]->At(tmpID)+1;
708  if (fCoreE1->Get() > 0) {
709  fCountArray[0]->AddAt(tmp, tmpID);
710  if (tmp > fCountCoreMax)
711  fCountCoreMax = tmp;
712  }
713  }
714  fHistoCntCrystal->Fill(fCrysID->Get());
715 
716  // loop on PSAFrame and extract the information you need
717  for(UInt_t i = 0u; i < GetNbFramePSA(); ++i) {
718  PSAInterface *data = GetDataPSA(i);
719 
720  if ( data ) {
721  for (Int_t j = 0; j < data->GetNbHits(); ++j) {
722  const PSAHit* pHit = (PSAHit*)data->GetHit(j);
723  Int_t depthID = fTransf->GetDepthId(pHit->GetZ());
724  Int_t sectorID = fTransf->GetSectorId(pHit->GetX(), pHit->GetY());
725 
726  tmpID = fCrysID->Get()*fgkNofSectors + sectorID;
727  tmp = fCountArray[depthID]->At(tmpID)+1;
728 
729  Int_t histoID = fCrysID->Get()*fgkNofSectors*fgkNofSlices + sectorID*fgkNofSlices + (depthID-1);
730  fHistoCntSlice[histoID]->Fill(fCurrentCycle, tmp);
731 
732  fCountArray[depthID]->AddAt(tmp, tmpID);
733 
734  if ( tmp > fCountMax->At(fCrysID->Get()) )
735  fCountMax->AddAt(tmp, fCrysID->Get());
736 
737  if (tmp > fCountMaxAll)
738  fCountMaxAll = tmp;
739 
740 
741  if ( gDebug > 3 ) {
742  printf("hit %d with pos (%f, %f, %f)\n", j, pHit->GetX(), pHit->GetY(), pHit->GetZ());
743  printf("Count %d for crystal %d depth %d and sector %d max %d\n",
744  fCountArray[depthID]->At(tmpID), fCrysID->Get(), depthID, sectorID, fCountMax->At(fCrysID->Get()));
745  }
746  }
747  }
748  }
749 }
750 
751 //__________________________________________________________
752 void RateDisplay::AddCluster(Double_t xOffset, Double_t yOffset)
753 {
754  TPaveText* pave = 0x0;
755  Double_t xPave = 0;
756  Double_t yPave = 0;
757  Double_t dxPave = 10;
758  Double_t dyPave = 10;
759 
760  Double_t xPos = 0;
761  Double_t yPos = 2*TMath::Sin(TMath::Pi()/6)*(fgkRho2+3*fgkDRho);
762  AddCristals(xPos+xOffset,yPos+yOffset);
763 
764  xPave = xPos+xOffset-0.8*fgkRho2;
765  yPave = yPos+yOffset+fgkRho2;
766  pave = new TPaveText(xPave-dxPave,yPave-dyPave, xPave+dxPave, yPave+dyPave);
767  pave->SetOption("");
768  pave->AddText(Form("%d", (fSectorList->GetEntries()-1)/fgkNofSectors));
769  fLabelList->Add(pave);
770 
771  xPos = -TMath::Cos(TMath::Pi()/6)*(fgkRho2+3*fgkDRho);
772  yPos = -TMath::Sin(TMath::Pi()/6)*(fgkRho2+3*fgkDRho);
773  AddCristals(xPos+xOffset, yPos+yOffset);
774 
775  xPave = xPos+xOffset-0.8*fgkRho2;
776  yPave = yPos+yOffset+fgkRho2;
777  pave = new TPaveText(xPave-dxPave,yPave-dyPave, xPave+dxPave, yPave+dyPave);
778  pave->SetOption("l");
779  pave->AddText(Form("%d", (fSectorList->GetEntries()-1)/fgkNofSectors));
780  fLabelList->Add(pave);
781 
782  xPos = TMath::Cos(TMath::Pi()/6)*(fgkRho2+3*fgkDRho);
783  yPos = -TMath::Sin(TMath::Pi()/6)*(fgkRho2+3*fgkDRho);
784  AddCristals(xPos+xOffset, yPos+yOffset);
785 
786  xPave = xPos+xOffset+0.8*fgkRho2;
787  yPave = yPos+yOffset+fgkRho2;
788  pave = new TPaveText(xPave-dxPave,yPave-dyPave, xPave+dxPave, yPave+dyPave);
789  pave->SetOption("r");
790  pave->AddText(Form("%d", (fSectorList->GetEntries()-1)/fgkNofSectors));
791  fLabelList->Add(pave);
792 }
793 
794 //__________________________________________________________
795 void RateDisplay::AddCristals(Double_t xPos, Double_t yPos)
796 {
797  TPolyLine* detectorLine = 0x0;
798 
799  Double_t x[fgkNofPoints];
800  Double_t y[fgkNofPoints];
801 
802  Double_t offset = TMath::Pi()/6.;
803  Double_t dPhi = TMath::Pi()/3.;
804 
805  for (Int_t i = 0; i < fgkNofSectors; ++i) {
806  Double_t angle = dPhi*i + offset;
807  Double_t shiftX = fgkDRho*TMath::Cos(angle+dPhi/2.);
808  Double_t shiftY = fgkDRho*TMath::Sin(angle+dPhi/2.);
809 
810  x[0] = x[4] = fgkRho1*TMath::Cos(angle) + shiftX;
811  y[0] = y[4] = fgkRho1*TMath::Sin(angle) + shiftY;
812  x[1] = fgkRho2*TMath::Cos(angle) + shiftX;
813  y[1] = fgkRho2*TMath::Sin(angle) + shiftY;
814 
815  angle = dPhi*(i+1) + offset;
816  x[2] = fgkRho2*TMath::Cos(angle) + shiftX;
817  y[2] = fgkRho2*TMath::Sin(angle) + shiftY;
818 
819  x[3] = fgkRho1*TMath::Cos(angle) + shiftX;
820  y[3] = fgkRho1*TMath::Sin(angle) + shiftY;
821 
822  for (Int_t j = 0; j < fgkNofPoints; ++j) {
823  x[j] += xPos;
824  y[j] += yPos;
825  }
826 
827  detectorLine = new TPolyLine(fgkNofPoints,x,y);
828  detectorLine->SetLineWidth(1);
829  detectorLine->SetLineStyle(2);
830  fSectorList->Add(detectorLine);
831  }
832 }
833 
834 //__________________________________________________________
836 {
837  TPolyLine* rateLine = 0x0;
838 
839  for (Int_t iCrystal = 0; iCrystal < fSectorList->GetEntries(); ++iCrystal) {
840  Color_t col = 0;
841  if (iCrystal/fgkNofSectors % 3 == 0)
842  col = kRed;
843  if (iCrystal/fgkNofSectors % 3 == 1)
844  col = kGreen;
845  if (iCrystal/fgkNofSectors % 3 == 2)
846  col = kBlue;
847 
848  rateLine = new TPolyLine(fgkNofPoints);
849  rateLine->SetLineColor(2);
850  rateLine->SetLineWidth(1);
851  rateLine->SetFillColor(col);
852  rateLine->SetOption("f");
853  fRateList->Add(rateLine);
854 
855  }
856 }
857 
858 //__________________________________________________________
859 void RateDisplay::SetRefresh(Long_t r)
860 {
861  fRefresh = r;
862  fTimer->Start(r*1000);
863 }
864 
865 //__________________________________________________________
866 void RateDisplay::SetDepth(Int_t d, Bool_t stop)
867 {
868  if (stop)
869  fTimer->Stop();
870 
871  if (d > 6 || d < 0) return;
872 
873  fDepth = d;
874  UpdateRates();
875 }
876 
877 //__________________________________________________________
879 {
880  TPolyLine* rateLine = 0x0;
881  TPolyLine* detectorLine = 0x0;
882 
883  Double_t xm;
884  Double_t ym;
885 
886  Double_t x[fgkNofPoints];
887  Double_t y[fgkNofPoints];
888 
889  for (Int_t iCrystal = 0; iCrystal < fSectorList->GetEntries()/fgkNofSectors; ++iCrystal) {
890 
891  Int_t max = 1;
892 
893  if (IsNormByAll()) {
894  max = fCountMaxAll;
895  } else {
896  max = fCountMax->At(iCrystal);
897  }
898 
899  if (max == 0) continue;
900 
901  for (Int_t iSector = 0; iSector < fgkNofSectors; ++iSector) {
902  detectorLine = static_cast<TPolyLine*> ( fSectorList->At(iCrystal*fgkNofSectors + iSector) );
903  rateLine = static_cast<TPolyLine*> ( fRateList->At(iCrystal*fgkNofSectors + iSector) );
904 
905  Double_t x1 = (detectorLine->GetX()[1] + detectorLine->GetX()[2])/2.;
906  Double_t y1 = (detectorLine->GetY()[1] + detectorLine->GetY()[2])/2.;
907 
908  Double_t x2 = (detectorLine->GetX()[0] + detectorLine->GetX()[3])/2.;
909  Double_t y2 = (detectorLine->GetY()[0] + detectorLine->GetY()[3])/2.;
910 
911  xm = (x1+x2)/2.;
912  ym = (y1+y2)/2.;
913 
914  Double_t rateRatio = 1.;
915 
916  if (fDepth != 0)
917  rateRatio = (Double_t)fCountArray[fDepth]->At(iCrystal*fgkNofSectors + iSector)/max*0.85;
918  else
919  rateRatio = (Double_t)fCountArray[fDepth]->At(iCrystal*fgkNofSectors + iSector)/fCountCoreMax*0.85;
920 
921  if ( gDebug > 3 ) {
922  printf("count %d ratio %lf for sector %d and crystal %d\n",
923  fCountArray[fDepth]->At(iCrystal*fgkNofSectors + iSector), rateRatio,
924  iSector, iCrystal);
925  }
926 
927  for (Int_t j = 0; j < fgkNofPoints; ++j) {
928  x[j] = (detectorLine->GetX()[j] - xm)* rateRatio + xm;
929  y[j] = (detectorLine->GetY()[j] - ym)* rateRatio + ym;
930  }
931 
932  rateLine->SetPolyLine(fgkNofPoints, x, y, "f");
933  rateLine->SetUniqueID(fCountArray[fDepth]->At(iCrystal*fgkNofSectors + iSector));
934  }
935  }
936 
937  // show depth
938  fDepthText->Clear();
939  fDepthText->SetTextSize(0.04);
940  fDepthText->SetText(-fgkDRange/2+20, -fgkDRange/2+20, Form("Depth: %d", fDepth));
941 
942  fCurrentCycle++;
943 }
944 
945 //__________________________________________________________
947 {
948  // reset counters + cycle
949  fCountMax->Reset();
950  fCountCoreMax = 1;
951  for (Int_t i = 0; i < fgkNofSlices+1; ++i)
952  fCountArray[i]->Reset();
953 
954  fCountMaxAll = 0;
955 }
956 
957 
virtual void SetDepth(Int_t depth=1, Bool_t stop=true)
Set depth.
AgataEventContainer class that contains agata event to be displayed.
virtual void Exec(Option_t *option="")
watch the current frame
virtual Bool_t IsValid() const
true if it is a valid pointer
Definition: Frame.h:616
void SetActive(Bool_t active=true)
Toggle active task.
virtual void GetDirection(Double_t &, Double_t &, Double_t &, Double_t=0.0) const =0
get the direction of the source (last argument is used in case the position depends on time) ...
virtual void DoCanvas(TCanvas *c, Option_t *)
To be overwritten by real implementation if a canvas is produced.
virtual void DoCanvas(TCanvas *canvas, Option_t *option)
To be overwritten by real implementation if a canvas is produced.
virtual VertexInterface * GetVertex()
Get the vertex data interface.
const Float_t gMetric
virtual UShort_t GetNbHits() const =0
To know the number of Hits currently on the stack.
virtual Key * GetKey()=0
To get the Key associated to this frame.
printf("******************************************************************** \n")
UInt_t GetNbFramePSA()
number of PSA Frames extracted from the current event
virtual Double_t GetY() const
Definition: Hits.h:57
TCanvas * NewCanvas(Option_t *)
It creates a new embedded canvas.
Definition: Watchers.cpp:1057
static MainFrameFactory & theMainFactory()
the main (global) keyfactory
Base class for a Frame.
Definition: Frame.h:73
LogMessage & error(LogMessage &)
RateDisplay(const Char_t *name, const Char_t *title, TDirectory *sp_dir=0x0, TDirectory *tag_dir=0x0)
virtual Frame * New(const FactoryItem &key_item, const FactoryItem &frame_item)
just a frame
TH1 * fCoreCommon
Sum of all core spectra (without Doppler correction)
virtual void GetPosition(Double_t &, Double_t &, Double_t &, Double_t=0.0) const =0
get the position of the source (last argument is used in case the position depends on time) ...
virtual Bool_t SetTrigger(ADF::DFTrigger *=0x0)
Set the trigger attached to this watcher.
AgataEventDisplay a class to work on a specific event display.
TH1F * fDistri
Crystal fold.
virtual Double_t GetE(UInt_t=0u) const =0
to get the energy associated to the core
virtual Bool_t SetTrigger(ADF::DFTrigger *=0x0)
Set the trigger attached to this watcher.
virtual Double_t GetE() const
Definition: Hits.h:67
virtual Int_t GetUID() const =0
to get the crystal ID
virtual void SetZ(Float_t z)
Interface to AgataKey.
virtual DFAgent * GetDFAgent()=0
to get the Data Flow Agent in charge of knowing the structure of the DF
virtual ~HitsSpectra()
******************************************************************************************/// ...
virtual void Exec(Option_t *option="")
watch the current frame
virtual Double_t GetT(UInt_t=0u) const =0
to get the time associated to the core
LogMessage & nline(LogMessage &)
virtual Double_t GetX() const
Definition: Hits.h:146
void AddRates()
Add polyline rate object list.
AgataGeometryTransformer class that manage geometry transformations.
TObjArray fSpectra
Core energy for any crystal.
virtual Double_t GetE() const
Definition: Hits.h:158
static ConfAgent * theGlobalAgent(std::string="Agata")
to get the global agent
Definition: ConfAgent.cpp:402
virtual void SetY(Float_t y)
AgataGeometryTransformer * fTrans
Base class for a Global Object.
Definition: GObject.h:115
virtual Bool_t IsNormByAll()
return normalization
virtual Double_t GetBeta(Double_t=0.0) const =0
get recoil velocity
void HandleMovement(Int_t eventType, Int_t eventX, Int_t eventY, TObject *select)
Handle Movement.
void UpdateRates()
Update rates.
Frame * fPSAFrame
current PSA frame to help decoding one by one
virtual void SetE(Float_t e)
LogMessage & info(LogMessage &)
manipulator to modify the LogMessage
virtual UInt_t GetEventNumber() const =0
To get the event number encoded.
HitsSpectra(const char *name, const char *title, TDirectory *sp_dir=0x0, TDirectory *tag_dir=0x0)
*/
Base class for version numbers.
Definition: Version.h:38
void AddCristals(Double_t xPos=0, Double_t yPos=0)
Add cluster at a given position to list.
virtual ~RateDisplay()
virtual Frame * GetInputFrame(UInt_t which=0u)=0
to get back the frames that define this trigger
virtual Double_t GetZ() const
Definition: Hits.h:150
header file for AgataKeyFactory.cpp
Show rates (counts) per Crystal.
virtual void SetX(Float_t x)
Setter position & energy.
void AddCluster(Double_t xOffset=0, Double_t yOffset=0)
Add sectors for a cluster to list.
virtual void Zero(Option_t *hname="pool", Option_t *binning="")
Zero.
void UpdateCanvas()
Update canvas.
virtual Data_T Get() const
Get the data.
Definition: DataHandling.h:296
void SetItem(const Char_t *whichfactory, const Char_t *whichitem, Version itemversion, Short_t factversion=-1, void *ptr=0x0)
to change an item
Definition: FactoryItem.cpp:84
virtual void SetXYZ(Double_t x, Double_t y, Double_t z)
Definition: Hits.h:314
virtual void SetE(Double_t e)
Definition: Hits.h:321
void FillHits(Option_t *type="Agata")
Fill Event.
It is a hit associated to a list of Hits.
Definition: Hits.h:256
HitDisplay3D(const char *name, const char *type, TDirectory *sp_dir=0x0, TDirectory *tag_dir=0x0)
StdHit * NewHit(Option_t *type="Agata")
add current hit (added to current hit list)
virtual Double_t GetX() const
Definition: Hits.h:55
FactoryItem WhichKnownKey(const FactoryItem &kit, const FactoryItem &fit, PF_FactoryItemChange kch=ChangeOfVersion, PF_FactoryItemChange fch=ChangeOfVersion) const
Definition: DFAgent.cpp:353
virtual void DoCanvas(TCanvas *c, Option_t *)
To be overwritten by real implementation if a canvas is produced.
header file for DFAgent.cpp
PSAInterface * GetDataPSA(UInt_t which)
To get one by one the PSA Frames in one event (It fills fFramePSA). Read has beed called ! ...
virtual Double_t GetGamma(Double_t=0.0) const
Definition: MetaFrame.h:77
ClassImp(EventPSAWatcher)
*********************************** HitsSpectra Class **************************************/// ...
virtual Int_t GetID(Int_t which_id=0) const
get crystal/segment id. if which_id > 0, get crystal ID.
Definition: PSAFrame.h:96
virtual Double_t DoDopplerCorrection(const TrackedHit *hit, VertexInterface *vertex)
Do Doppler taking into account additionnal offset of the agata position (see SetAgataOffset) ...
Base class for a trigger on a data flow.
Definition: Trigger.h:155
Bool_t ReadTransformations(const TString fileName)
read transformations file
ADF::LogMessage & endl(ADF::LogMessage &log)
TH1 * fCoreCommonDoppler
Sum of all core spectra (with Doppler correction)
virtual void Exec(Option_t *option="")
watch the current frame
virtual Double_t GetZ() const
Definition: Hits.h:59
Int_t GetSectorId(Double_t x, Double_t y)
Get sector id from (x,y) position.
const NamedItem< Data_t > * Get(const char *name)
to get a given item (reading mode only !!)
Definition: GObject.h:174
SharedFP * fFrame
main frame i.e. event:data:psa
Concrete implementation of a tracked Hit.
Definition: Hits.h:279
Int_t GetDepthId(Double_t z)
Get sector depth from z position.
virtual ADF::DFTrigger * GetTrigger() const
To know the trigger in which the frame to be watched is embedded.
Definition: Watchers.h:360
*********************************** EventPSAWatcher Class **************************************/// ...
virtual Double_t GetY() const
Definition: Hits.h:148
virtual Hit * GetHit(UShort_t)=0
To get back a particular Hit (already on the stack !)
FactoryItem WhichKnownFrame(const FactoryItem &kit, const FactoryItem &fit, PF_FactoryItemChange kch=ChangeOfVersion, PF_FactoryItemChange fch=ChangeOfVersion) const
To get the exact definition of a key and a Frame.
Definition: DFAgent.cpp:370
virtual void ShowEve(const Char_t *agataPathFile)
show eve event display
void SetRefresh(Long_t r)
Set Refresh.
void Local2Global(Int_t detID, Double_t xl, Double_t yl, Double_t zl, Double_t &xg, Double_t &yg, Double_t &zg) const
Transform point from the local reference frame of the detection id to the global reference frame...
void Reset()
reset
virtual void GetXYZ(Double_t &x, Double_t &y, Double_t &z) const
Definition: Hits.h:155
Int_t GetNofEvents() const
get Number of events
Base class that described an item in a Factory.
Definition: FactoryItem.h:52
static VertexBuilder * theCurrentVertexBuilder()
to get the current VertexWatcher (for other watchers) i.e. the last one registered.