GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GANIL/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 #include "TBox.h"
23 #include "TCanvas.h"
24 #include "TGeoMatrix.h"
25 #include "TGToolTip.h"
26 #include "TLatex.h"
27 #include "TMath.h"
28 #include "TObjArray.h"
29 #include "TPaveText.h"
30 #include "TPolyLine.h"
31 #include "TRandom.h"
32 #include "TString.h"
33 #include "TTimer.h"
34 #include "TSystem.h"
35 #include "TH2.h"
36 #include "TH1.h"
37 #include "TPad.h"
38 #include "TPaveStats.h"
39 #include "TLegend.h"
40 #include "BashColor.h"
41 
42 #include "TVirtualPad.h"
43 //#include "AgataEventDisplay.h"
44 #include "AgataEventContainer.h"
45 #include "MetaWatchers.h"
46 #include "MetaFrame.h"
47 
48 #include "DFAgent.h"
49 #include "AgataKeyFactory.h"
50 #include "MetaWatchers.h"
51 #include "LoupeOnPad.h"
52 
53 #include "EventPSAWatchers.h"
54 #include "Hits.h"
55 #include "CrystalWatchers.h"
56 
57 using namespace ADF;
58 
62 
64 {
65  if ( !Watcher::GetFromTrigger(trigger, "event:data:psa", fFrame) )
66  return false;
67 
68  // first extract from the current configuration the definition
69  // of the data:psa frame on the data flow
70  FactoryItem i_asked, k_defined, f_defined;
71 
72  i_asked.SetItem("Agata","data:psa",Version());
73  k_defined = ConfAgent::theGlobalAgent()->GetDFAgent()->WhichKnownKey (i_asked,i_asked);
74  f_defined = ConfAgent::theGlobalAgent()->GetDFAgent()->WhichKnownFrame (i_asked,i_asked);
75 
76  Frame *f = MainFrameFactory::theMainFactory().New(k_defined,f_defined);
77  if ( f ) { // it exists
78  if ( fPSAFrame )
79  { delete fPSAFrame; fPSAFrame = 0x0; }
80 
81  fPSAFrame = f;
82  }
83  else fFrame = 0x0;
84 
85  return fFrame != 0x0;
86 }
87 
89 
91 {
92  if ( fFrame && fFrame->IsValid() ) {
93  fFrame->GetFrame()->Scan();
94  return fFrame->GetFrame()->GetNbSubFrame();
95  }
96 
97  return 0u;
98 }
99 
101 
103 {
104  // does not exist
105  if ( !(which < GetNbFramePSA()) ) {
106  if ( gDebug > 3 )
107  printf("EventPSAWatcher::GetDataPSA %d %d \n",which,GetNbFramePSA());
108  return 0x0;
109  }
110  // cannot load subframe #i in fPSAFrame
111  if ( !fFrame->GetFrame()->LinkSubFrame(which,fPSAFrame) ) {
112  if ( gDebug > 3 )
113  printf("EventPSAWatcher::GetDataPSA cannot LinkSubFrame \n");
114  return 0x0;
115  }
116  // cannot read the data
117  if( fPSAFrame->Read() == 0 ) {
118  if ( gDebug > 3 )
119  printf("EventPSAWatcher::GetDataPSA cannot Read \n");
120  return 0x0;
121  }
122  // return the data interface for that frame
123  return GetDataPointer<PSAInterface>(fPSAFrame);
124 }
125 
129 
130 HitsSpectra::HitsSpectra(const char *name, const char *title, TDirectory *sp_dir, TDirectory *tag_dir) :
131  EventPSAWatcher(name,title,sp_dir,tag_dir),
132  fVertexBuilder(0x0),
133  fTrans(0x0),
134  fSpectra(180),
135  fSpectraDoppler(180),
136  fCoreCommon(0x0),
137  fGxG(0x0),
138  fGxT(0x0),
139  fCoreCommonDoppler(0x0),
140  fGxGDoppler(0x0),
141  fDistri(0x0),
142  fPosXYZ(0x0),
143  fPosXYZ_Ta(0x0)
144 {
145  fSpectra.SetOwner(false); fSpectraDoppler.SetOwner(false);
146 
147  // Vertex used for doppler correction, last registered
148  fVertexBuilder = VertexBuilder::theCurrentVertexBuilder();
149  if ( fVertexBuilder == 0x0 )
150  std::cout << "Should not be NULL " << std::endl;
151 
153 
154  if ( gSystem->AccessPathName("CrystalPositionLookUpTable") ) { // does not exist
155  if ( gSystem->AccessPathName("CrystalPositionLookUpTable.dat") ) {
156  fLog << error << " CrystalPositionLookUpTable required " << nline;
157  }
158  else {
159  fLog << info << " Ge positions extracted from CrystalPositionLookUpTable.dat " << nline;
160  fTrans->ReadTransformations("CrystalPositionLookUpTable.dat");
161  }
162  }
163  else {
164  fLog << info << " Ge positions extracted from CrystalPositionLookUpTable.dat " << nline;
165  fTrans->ReadTransformations("CrystalPositionLookUpTable");
166  }
167 
168  for (UInt_t i = 0u; i < gNbCrys; i++ ) {
169 
170  TString tmp; TH1F *h;
171 
172  tmp = Form("Crystal_%d",i);
173  h = MakeTH1<TH1F>(tmp.Data(),"Core energy of the crystal", 4096,0,4096);
174  fSpectra.Add ( h ) ;
175 
176  tmp = Form("Crystal_track_%d",i);
177  h = MakeTH1<TH1F>(tmp.Data(),"Core energy of the crystal", 4096,0,4096);
178  fSpectraDoppler.Add ( h ) ;
179 
180  }
181  fCoreCommon = MakeTH1<TH1F>("CoreCommon","Core common spectrum",8192,0,4096);
182  fSumSpectra = MakeTH1<TH1F>("SumSpectra","Sum of all spectra",8192,0,4096);
183  fGxG = MakeTH2<TH2F>("GxG","Gamma Gamma Matrix",4096,0,4096,4096,0,4096);
184  fDistri = MakeTH1<TH1F>("CrystalDistri","Distribution of the crystal fired",180,0,180);
185  fPosXYZ = MakeTH3<TH3F>("PosXYZ","Distribution of hits in Space",100,-200,200,100,-200,200,100,-400,0);
186 
187  // fPos3D = MakeTH3<TH3F>("Pos3D","Positions of Tracked Gamma-rays ;x;y;z",200,-200,200,200,-200,200,200,-400,0);
188 
189  fPosXYZ_Ta = MakeTH3<TH3F>("PosXYZ_Ta","Distribution of hits in Space with Target hit",200,-400,400,200,-400,400,200,-400,400);
190 
191 
192 
193  fGxT = MakeTH2<TH2F>("GxT","Gamma Time Matrix",4096,0,4096,300,0,300);
194 
195  fCoreCommonDoppler = MakeTH1<TH1F>("DCoreCommon","Core common spectrum with doppler correction",8192,0,4096);
196  fGxGDoppler = MakeTH2<TH2F>("DGxG","Gamma Gamma Matrix with doppler correction",4096,0,4096,4096,0,4096);
197 
198  fFold = MakeTH1<TH1F>("Fold","Crystal Fold distributions",10,0,10);
199 }
200 
202 
204 {
205  if (fTrans) {
206  delete fTrans; fTrans = 0x0;
207  }
208 }
209 
211 {
212  Double_t e = hit->GetE(), beta = vertex->GetBeta(), gamma = vertex->GetGamma();
213 
214  Double_t px, py, pz, dx, dy, dz;
215  vertex->GetPosition (px, py, pz);
216  vertex->GetDirection(dx, dy, dz);
217 
218  // std::cout << " " << px << " " << py << " " << pz <<std::endl;
219 
220  Double_t x = hit->GetX() - px;
221  Double_t y = hit->GetY() - py;
222  Double_t z = hit->GetZ() - pz;
223 
224  Double_t dd = x*x + y*y + z*z;
225  if( !(dd == 0.0) ) {
226  Double_t cosTheta = (x*dx + y*dy + z*dz)/::sqrt(dd);
227  e = VertexInterface::DopplerCorrection(e,beta,gamma,cosTheta);
228  }
229  else e = -1.0;
230 
231  return e;
232 }
233 
235 
236 void HitsSpectra::DoCanvas(TCanvas *c, Option_t *o)
237 {
238  TString opt = o;
239 
240  c->Divide(4,4,0.001,0.001);
241 
242  int PadNbr = 1;
243  c->cd(PadNbr);
244  fDistri->DrawCopy();
245 
246  for(int i=0 ; i<fDistri->GetNbinsX() ; i++)
247  {
248  if(fDistri->GetBinContent(i+1))
249  {
250  PadNbr++;
251  c->cd(PadNbr%16);
252  if(fSpectra[i+1]) fSpectra[(int)fDistri->GetBinLowEdge(i+1)]->Draw();
253  }
254  if(PadNbr%16==0)
255  {
256  c = NewCanvas(Form("HitSpectra_%d_%d",PadNbr+1,PadNbr+16));
257  c->Divide(4,4,0.001,0.001);
258  }
259  }
260 
261 
262  TCanvas *OverImposedCore = NewCanvas("OverImposedCore");
263  OverImposedCore->cd();
264  bool FirstHist = true;
265  for(int i=0 ; i<fDistri->GetNbinsX() ; i++)
266  {
267  if(fDistri->GetBinContent(i+1) && fSpectra[i+1])
268  {
269  if(FirstHist)
270  {
271  fSpectra[(int)fDistri->GetBinLowEdge(i+1)]->Draw();
272  FirstHist = false;
273  }
274  else fSpectra[(int)fDistri->GetBinLowEdge(i+1)]->Draw("same");
275  }
276  }
277 
278 
279  TCanvas *GlobalSpectra = NewCanvas("GlobalSpectra");
280  GlobalSpectra->Divide(1,2,0.001,0.001);
281  GlobalSpectra->cd(1);
282  fCoreCommon->Draw();
283 
284  TPad *pad = new TPad("Crystal fold", "Pad for Crystal fold distribution",0.7,0.6,1,1);
285  pad->Draw();
286  pad->cd();
287  fFold->Draw();
288 
289  GlobalSpectra->cd(2);
290  fSumSpectra->Draw();
291 }
292 
294 
295 void HitsSpectra::Exec(Option_t * /*option*/)
296 {
297  // cout << "Exec Hits sectra" <<endl;
298  Double_t xLocal, yLocal, zLocal, xGlobal, yGlobal, zGlobal; TrackedHitImp<EHit,EHit> gamma; Float_t gg[150], ggdc[150];
299 
300  // be sure the frame has been set properly
301  if ( fFrame == 0x0 || !fFrame->IsValid() ) {
302  // cout << "non valid frame" << endl;
303  return;
304  }
305  // the vertex used for doppler correction
306  VertexInterface *vertex = 0x0;
307  vertex =
308  fVertexBuilder->GetVertex();
309  TH1F *h;
310  UInt_t nb_frames = GetNbFramePSA();
311 
312  fFold->Fill(nb_frames);
313 
314  double SumEnergy = 0.;
315 
316  for(UInt_t i = 0u; i <nb_frames; i++) {
317 
318  PSAInterface *data = GetDataPSA(i);
319  gg[i] = data->GetE();
320  h = (TH1F *)fSpectra.At(data->GetUID());
321  if ( h ) {
322  h->Fill(data->GetE());
323  }
324  fGxT->Fill(data->GetE(),data->GetT());
325 
326  SumEnergy += data->GetE();
327  fCoreCommon->Fill(data->GetE());
328  fDistri->Fill(data->GetUID());
329 
330  // Now look for the hit with the highest energy, taken for Doppler correction
331  // Kind of tracking in crystal
332  Int_t nHits = data->GetNbHits();
333  Double_t max_e = 0.0;
334  //test DR
335  Double_t xt,yt,zt;
336  vertex->GetPosition(xt,yt,zt);
337  fPosXYZ_Ta->Fill(xt,yt,zt);
338 
339  for (UShort_t j = 0u; j < nHits; ++j) {
340 
341  const PSAHit* pHit = (PSAHit*)data->GetHit(j);
342  //
343  pHit->GetXYZ(xLocal, yLocal, zLocal);
344  /* if ( gDebug > 3 ) {
345  std::cout << "Global " << xGlobal << " " << yGlobal << " " << zGlobal << std::endl;
346  std::cout << "Local " << xLocal << " " << yLocal << " " << zLocal << " " << pHit->GetID() << std::endl;
347  } */
348  fTrans->Local2Global(data->GetUID(), xLocal, yLocal, zLocal, xGlobal, yGlobal, zGlobal);//y,x,z
349  fPosXYZ->Fill(xGlobal, yGlobal, zGlobal);
350  fPosXYZ_Ta->Fill(xGlobal, yGlobal, zGlobal);
351 
352  if ( pHit->GetE() > max_e ) {
353  gamma.SetXYZ(xGlobal, yGlobal, zGlobal);
354  max_e = pHit->GetE();
355  }
356  } // j
357 
358  gamma.SetE(data->GetE()); h = (TH1F *)fSpectraDoppler.At(data->GetUID());
359  if ( vertex ) {
360  Double_t edc = DoDopplerCorrection(&gamma,vertex);
361  h->Fill(edc);
362  fCoreCommonDoppler->Fill(edc);
363  ggdc[i] = edc;
364  }
365  else ggdc[i] = gg[i];
366  }
367 
368  fSumSpectra->Fill(SumEnergy);
369 
370  for(UInt_t i = 0u; i <nb_frames; i++) {
371  for(UInt_t j = i+1; j <nb_frames; j++) {
372 
373  fGxG->Fill(gg[i],gg[j]); fGxG->Fill(gg[j],gg[i]); fGxGDoppler->Fill(ggdc[i],ggdc[j]); fGxGDoppler->Fill(ggdc[j],ggdc[i]);
374  }
375  }
376 
377 }
378 
382 
383 //Float_t EventPSAWatcher::fgMetric = 10.;
384 
385 //HitDisplay3D::HitDisplay3D(const char *name, const char *title, TDirectory *sp_dir, TDirectory *tag_dir):
386 // EventPSAWatcher(name,title,sp_dir,tag_dir),
387 // fMaxCycle(100),
388 // fPathFile(Gw::AgataEventDisplay::GetDefaultAgataPath())
389 //{
390 // fTrans = new AgataGeometryTransformer();
391 // fTrans->ReadTransformations("CrystalPositionLookUpTable.dat");
392 //}
393 
395 
396 //HitDisplay3D::~HitDisplay3D()
397 //{
398 // delete fTrans;
399 //}
400 
402 
403 //void HitDisplay3D::SetActive(Bool_t active)
404 //{
405 // TTask::SetActive(active);
406 // AgataEventDisplay::Instance()->Reset();
407 //}
408 
410 
411 //void HitDisplay3D::DoCanvas(TCanvas* /*c*/, Option_t* /*o*/)
412 //{
413 //}
414 
416 
417 //void HitDisplay3D::ShowEve(const Char_t* agataPathFile)
418 //{
419 // AgataEventDisplay::SetDefaultAgataPath(agataPathFile);
420 // AgataEventDisplay::Instance()->BuildDefaultGeometry();
421 // AgataEventDisplay::Instance()->ShowDisplay();
422 //}
423 
425 
426 //void HitDisplay3D::Exec(Option_t */*option*/)
427 //{
428 // // be sure the frame has been set properly
429 // if ( fFrame == 0x0 || !fFrame->IsValid() ) {
430 // return;
431 // }
432 
433 // if ( gDebug > 3 )
434 // printf("HitDisplay3D::::Exec is called %d \n",GetNbFramePSA());
435 
436 // AgataEventContainer* agataContainer = AgataEventDisplay::Instance()->GetEventContainer();
437 
438 // if (agataContainer->GetNofEvents() > fMaxCycle) {
439 // TTask::SetActive(false);
440 // return;
441 // }
442 
443 // static UInt_t evtNbOld = 0;
444 // Frame *f = GetTrigger()->GetInputFrame(0);
445 // const AgataKey* key = dynamic_cast<const AgataKey *>(f->GetKey());
446 // UInt_t evtNb = key->GetEventNumber();
447 // if (evtNb == evtNbOld)
448 // return;
449 
450 // for(UInt_t i = 0u; i < GetNbFramePSA(); i++) {
451 
452 // PSAInterface *data = GetDataPSA(i);
453 
454 // UInt_t nHits = data->GetNbHits();
455 // //cout << "Fold " << nHits << endl;
456 
457 // for (UShort_t j = 0u; j < nHits; ++j) {
458 // const PSAHit* pHit = (PSAHit*)data->GetHit(j);
459 // StdHit* hit = agataContainer->NewHit();
460 // Float_t xLocal = pHit->GetX();
461 // Float_t yLocal = pHit->GetY();
462 // Float_t zLocal = pHit->GetZ();
463 
464 // Float_t xGlobal, yGlobal, zGlobal;
465 // fTrans->Local2Global(pHit->GetID(), xLocal, yLocal, zLocal, xGlobal, yGlobal, zGlobal);
466 
467 // if ( gDebug > 3 ) {
468 // std::cout << "Global " << xGlobal << " " << yGlobal << " " << zGlobal << std::endl;
469 // std::cout << "Local " << xLocal << " " << yLocal << " " << zLocal << " " << pHit->GetE() << std::endl;
470 // }
471 // hit->SetX(xGlobal/fgMetric);
472 // hit->SetY(yGlobal/fgMetric);
473 // hit->SetZ(zGlobal/fgMetric);
474 // hit->SetE(pHit->GetE());
475 // }
476 // }
477 // agataContainer->FillHits();
478 // evtNbOld = evtNb;
479 //}
480 
484 
485 //const Double_t RateDisplay::fgkDRho = 3.;
486 //const Double_t RateDisplay::fgkRho1 = 5.;
487 //const Double_t RateDisplay::fgkRho2 = 80.;
488 //const Double_t RateDisplay::fgkDRange = 400.;
489 //const Int_t RateDisplay::fgkNofPoints = 5;
490 //const Int_t RateDisplay::fgkNofSectors = 6;
491 //const Int_t RateDisplay::fgkNofSlices = 6;
492 //const Int_t RateDisplay::fgkNofCrystals = 60;
493 //const Int_t RateDisplay::fgkNDivX = 5;
494 //const Int_t RateDisplay::fgkNDivY = 3;
495 
496 //RateDisplay::RateDisplay(const Char_t *name, const Char_t *title, TDirectory *sp_dir, TDirectory *tag_dir) :
497 // EventPSAWatcher(name,title,sp_dir,tag_dir),
498 // fSectorList(new TObjArray(fgkNofSectors*fgkNofCrystals)),
499 // fLabelList(new TObjArray(fgkNofCrystals)),
500 // fRateList(new TObjArray(fgkNofSectors*fgkNofCrystals)),
501 // fTransf(new AgataGeometryTransformer()),
502 // fCountCoreMax(1),
503 // fCountMaxAll(1),
504 // fCurrentCycle(0),
505 // fMaxCycle(200),
506 // fDepth(1),
507 // fNormByAll(true),
508 // fTimer(new TTimer()),
509 // fRefresh(3),
510 // fDepthText(new TLatex()),
511 // fBox(new TBox(0, fgkDRange, 0, fgkDRange)),
512 // fInfoTip(new TGToolTip(fBox, "", 350))
513 //{
514 
515 // // Set owner for delete
516 // fSectorList->SetOwner(true);
517 // fLabelList->SetOwner(true);
518 // fRateList->SetOwner(true);
519 
520 // // count arrays
521 // for (Int_t i = 0; i < fgkNofSlices+1; ++i) {
522 // fCountArray[i] = new TArrayI(fgkNofSectors*fgkNofCrystals);
523 // fCountArray[i]->Reset();
524 // }
525 
526 // fCountMax = new TArrayI(fgkNofCrystals);
527 // fCountMax->Reset(1);
528 
529 // // create cluster & rate display
530 // for (Int_t j = 0; j < fgkNDivY; ++j)
531 // for (Int_t i = 0; i < fgkNDivX; ++i) {
532 // AddCluster(fgkDRange*i,fgkDRange*j);
533 // }
534 
535 // AddRates();
536 
537 // // histos
538 // fHistoCntCrystal = MakeTH1<TH1I>("HistoCntCrystal","Number of counts per crystal", fgkNofCrystals, 0, fgkNofCrystals) ;
539 
540 // for (Int_t i = 0; i < fgkNofCrystals; ++i) {
541 // for (Int_t j = 0; j < fgkNofSectors; ++j) {
542 // for (Int_t k = 0; k < fgkNofSlices; ++k) {
543 // Int_t id = i*fgkNofSectors*fgkNofSlices+j*fgkNofSlices + k;
544 // fHistoCntSlice[id] = MakeTH1<TH1I>(Form("%s%d_%d_%d","fHistoCntSlice", i,j, k),
545 // "Number of counts per sector and per slice", fMaxCycle+1, 0, fMaxCycle);
546 // fHistoCntSlice[id]->SetLineStyle(k+1);
547 // fHistoCntSlice[id]->SetLineColor(j+1);
548 // fHistoCntSlice[id]->SetLineWidth(2);
549 // }
550 // }
551 // }
552 
553 // fTimer->Connect("Timeout()", "RateDisplay", this, "UpdateCanvas()");
554 //}
555 
557 
558 //RateDisplay::~RateDisplay()
559 //{
560 // delete fSectorList;
561 // delete fLabelList;
562 // delete fRateList;
563 // delete fTransf;
564 // delete fDepthText;
565 // delete fTimer;
566 // delete fInfoTip;
567 // delete fBox;
568 
569 // for (Int_t i = 0; i < fgkNofSlices+1; ++i)
570 // delete fCountArray[i];
571 //}
572 
574 
575 //Bool_t RateDisplay::SetTrigger( ADF::DFTrigger *trigger )
576 //{
577 // // trigger on event:data:psa
578 // if ( EventPSAWatcher::SetTrigger(trigger) ) {
579 
580 // // the crystal id is needed
581 // GObject *glob =
582 // GetDataPointer<PSAInterface>(fPSAFrame)->Global();
583 // fCrysID = glob->Get<UShort_t>("CrystalID");
584 // fCoreE1 = glob->Get<Float_t>("CoreE1");
585 // return true;
586 // } else return false;
587 //}
588 
590 
591 //void RateDisplay::Zero(Option_t *opt1, Option_t *opt2)
592 //{
593 // fCurrentCycle = 0;
594 // return Watcher::Zero(opt1, opt2);
595 //}
596 
598 
599 //void RateDisplay::HandleMovement(Int_t eventType, Int_t eventX, Int_t eventY, TObject* select)
600 //{
601 
602 // TVirtualPad* pad = TVirtualPad::Pad();
603 // pad->cd();
604 
605 // if (eventType == kMouseMotion) {
606 // fLastX = eventX; fLastY = eventY;
607 
608 // // to keep track of the last mouse position
609 // fLastX = eventX; fLastY = eventY;
610 // if ( select->InheritsFrom("TPolyLine") && select->GetUniqueID() != 0) {
611 // fInfoTip->SetText(Form("Counts: %d", select->GetUniqueID()));
612 // fInfoTip->Show(fLastX, fLastY);
613 // } else
614 // fInfoTip->Hide();
615 // }
616 
617 //}
618 
620 
621 //void RateDisplay::DoCanvas(TCanvas* c, Option_t* o)
622 //{
623 
624 // TString tmp(o);
625 // tmp.ToLower();
626 
627 // // rate display
628 // if (tmp.IsNull() ) {
629 
630 // if ( !c->HasConnection("ProcessedEvent(Int_t, Int_t, Int_t, TObject*)") ) {
631 // c->Connect("ProcessedEvent(Int_t, Int_t, Int_t, TObject*)",
632 // "RateDisplay",
633 // this,
634 // "HandleMovement(Int_t, Int_t, Int_t, TObject*)");
635 // }
636 
637 // gPad->Range(-fgkDRange/2, -fgkDRange/2, fgkDRange/2+(fgkNDivX-1)*fgkDRange, fgkDRange/2+(fgkNDivY-1)*fgkDRange);
638 
639 // fSectorList->Draw();
640 // fLabelList->Draw();
641 // fRateList->Draw();
642 // fDepthText->Draw();
643 
644 // gPad->SetEditable(false);
645 // }
646 
647 // // histo display
648 // if (tmp.BeginsWith("h") ) {
649 // c->SetWindowSize((int)fgkDRange*fgkNDivX,(int)fgkDRange*fgkNDivY);
650 // c->Divide(fgkNDivX, fgkNDivY*3);
651 
652 // for (Int_t i = 0; i < fgkNofCrystals; ++i) {
653 // c->cd(i+1);
654 // for (Int_t j = 0; j < fgkNofSectors; ++j) {
655 // for (Int_t k = 0; k < fgkNofSlices; ++k) {
656 // Int_t id = i*fgkNofSectors*fgkNofSlices+j*fgkNofSlices + k;
657 // if (j == 0 && k == 0)
658 // fHistoCntSlice[id]->Draw();
659 // else
660 // fHistoCntSlice[id]->Draw("SAME");
661 // }
662 // }
663 // }
664 // }
665 // SetDepth(0, false);
666 // fTimer->Start(fRefresh*1000);
667 //}
668 
670 
671 //void RateDisplay::UpdateCanvas()
672 //{
673 // static Int_t depth = 0;
674 
675 // SetDepth(depth++, false);
676 // if (depth == fgkNofSlices+1) {
677 // depth = 0;
678 // Reset();
679 // }
680 
681 // // if (gPad) { // TO BE DONE
682 // // gPad->Update();
683 // // }
684 //}
685 
687 
688 //void RateDisplay::Exec(Option_t */*option*/)
689 //{
690 // // Frame by Frame action
691 
692 // // be sure the frame has been set properly
693 // if ( fFrame == 0x0 || !fFrame->IsValid() )
694 // return;
695 
696 // if ( gDebug > 3 )
697 // printf("RateDisplay::Exec is called %d \n",GetNbFramePSA());
698 
699 
700 // Int_t tmpID = 0;
701 // Int_t tmp = 0;
702 
703 // // depth 0 for core energy
704 // for (Int_t s = 0; s < fgkNofSectors; ++s) {
705 // tmpID = fCrysID->Get()*fgkNofSectors + s;
706 // tmp = fCountArray[0]->At(tmpID)+1;
707 // if (fCoreE1->Get() > 0) {
708 // fCountArray[0]->AddAt(tmp, tmpID);
709 // if (tmp > fCountCoreMax)
710 // fCountCoreMax = tmp;
711 // }
712 // }
713 // fHistoCntCrystal->Fill(fCrysID->Get());
714 
715 // // loop on PSAFrame and extract the information you need
716 // for(UInt_t i = 0u; i < GetNbFramePSA(); ++i) {
717 // PSAInterface *data = GetDataPSA(i);
718 
719 // if ( data ) {
720 // for (Int_t j = 0; j < data->GetNbHits(); ++j) {
721 // const PSAHit* pHit = (PSAHit*)data->GetHit(j);
722 // Int_t depthID = fTransf->GetDepthId(pHit->GetZ());
723 // Int_t sectorID = fTransf->GetSectorId(pHit->GetX(), pHit->GetY());
724 
725 // tmpID = fCrysID->Get()*fgkNofSectors + sectorID;
726 // tmp = fCountArray[depthID]->At(tmpID)+1;
727 
728 // Int_t histoID = fCrysID->Get()*fgkNofSectors*fgkNofSlices + sectorID*fgkNofSlices + (depthID-1);
729 // fHistoCntSlice[histoID]->Fill(fCurrentCycle, tmp);
730 
731 // fCountArray[depthID]->AddAt(tmp, tmpID);
732 
733 // if ( tmp > fCountMax->At(fCrysID->Get()) )
734 // fCountMax->AddAt(tmp, fCrysID->Get());
735 
736 // if (tmp > fCountMaxAll)
737 // fCountMaxAll = tmp;
738 
739 
740 // if ( gDebug > 3 ) {
741 // printf("hit %d with pos (%f, %f, %f)\n", j, pHit->GetX(), pHit->GetY(), pHit->GetZ());
742 // printf("Count %d for crystal %d depth %d and sector %d max %d\n",
743 // fCountArray[depthID]->At(tmpID), fCrysID->Get(), depthID, sectorID, fCountMax->At(fCrysID->Get()));
744 // }
745 // }
746 // }
747 // }
748 //}
749 
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 
795 
796 //void RateDisplay::AddCristals(Double_t xPos, Double_t yPos)
797 //{
798 // TPolyLine* detectorLine = 0x0;
799 
800 // Double_t x[fgkNofPoints];
801 // Double_t y[fgkNofPoints];
802 
803 // Double_t offset = TMath::Pi()/6.;
804 // Double_t dPhi = TMath::Pi()/3.;
805 
806 // for (Int_t i = 0; i < fgkNofSectors; ++i) {
807 // Double_t angle = dPhi*i + offset;
808 // Double_t shiftX = fgkDRho*TMath::Cos(angle+dPhi/2.);
809 // Double_t shiftY = fgkDRho*TMath::Sin(angle+dPhi/2.);
810 
811 // x[0] = x[4] = fgkRho1*TMath::Cos(angle) + shiftX;
812 // y[0] = y[4] = fgkRho1*TMath::Sin(angle) + shiftY;
813 // x[1] = fgkRho2*TMath::Cos(angle) + shiftX;
814 // y[1] = fgkRho2*TMath::Sin(angle) + shiftY;
815 
816 // angle = dPhi*(i+1) + offset;
817 // x[2] = fgkRho2*TMath::Cos(angle) + shiftX;
818 // y[2] = fgkRho2*TMath::Sin(angle) + shiftY;
819 
820 // x[3] = fgkRho1*TMath::Cos(angle) + shiftX;
821 // y[3] = fgkRho1*TMath::Sin(angle) + shiftY;
822 
823 // for (Int_t j = 0; j < fgkNofPoints; ++j) {
824 // x[j] += xPos;
825 // y[j] += yPos;
826 // }
827 
828 // detectorLine = new TPolyLine(fgkNofPoints,x,y);
829 // detectorLine->SetLineWidth(1);
830 // detectorLine->SetLineStyle(2);
831 // fSectorList->Add(detectorLine);
832 // }
833 //}
834 
836 
837 //void RateDisplay::AddRates()
838 //{
839 // TPolyLine* rateLine = 0x0;
840 
841 // for (Int_t iCrystal = 0; iCrystal < fSectorList->GetEntries(); ++iCrystal) {
842 // Color_t col = 0;
843 // if (iCrystal/fgkNofSectors % 3 == 0)
844 // col = kRed;
845 // if (iCrystal/fgkNofSectors % 3 == 1)
846 // col = kGreen;
847 // if (iCrystal/fgkNofSectors % 3 == 2)
848 // col = kBlue;
849 
850 // rateLine = new TPolyLine(fgkNofPoints);
851 // rateLine->SetLineColor(2);
852 // rateLine->SetLineWidth(1);
853 // rateLine->SetFillColor(col);
854 // rateLine->SetOption("f");
855 // fRateList->Add(rateLine);
856 
857 // }
858 //}
859 
861 
862 //void RateDisplay::SetRefresh(Long_t r)
863 //{
864 // fRefresh = r;
865 // fTimer->Start(r*1000);
866 //}
867 
869 
870 //void RateDisplay::SetDepth(Int_t d, Bool_t stop)
871 //{
872 // if (stop)
873 // fTimer->Stop();
874 
875 // if (d > 6 || d < 0) return;
876 
877 // fDepth = d;
878 // UpdateRates();
879 //}
880 
882 
883 //void RateDisplay::UpdateRates()
884 //{
885 // TPolyLine* rateLine = 0x0;
886 // TPolyLine* detectorLine = 0x0;
887 
888 // Double_t xm;
889 // Double_t ym;
890 
891 // Double_t x[fgkNofPoints];
892 // Double_t y[fgkNofPoints];
893 
894 // for (Int_t iCrystal = 0; iCrystal < fSectorList->GetEntries()/fgkNofSectors; ++iCrystal) {
895 
896 // Int_t max = 1;
897 
898 // if (IsNormByAll()) {
899 // max = fCountMaxAll;
900 // } else {
901 // max = fCountMax->At(iCrystal);
902 // }
903 
904 // if (max == 0) continue;
905 
906 // for (Int_t iSector = 0; iSector < fgkNofSectors; ++iSector) {
907 // detectorLine = static_cast<TPolyLine*> ( fSectorList->At(iCrystal*fgkNofSectors + iSector) );
908 // rateLine = static_cast<TPolyLine*> ( fRateList->At(iCrystal*fgkNofSectors + iSector) );
909 
910 // Double_t x1 = (detectorLine->GetX()[1] + detectorLine->GetX()[2])/2.;
911 // Double_t y1 = (detectorLine->GetY()[1] + detectorLine->GetY()[2])/2.;
912 
913 // Double_t x2 = (detectorLine->GetX()[0] + detectorLine->GetX()[3])/2.;
914 // Double_t y2 = (detectorLine->GetY()[0] + detectorLine->GetY()[3])/2.;
915 
916 // xm = (x1+x2)/2.;
917 // ym = (y1+y2)/2.;
918 
919 // Double_t rateRatio = 1.;
920 
921 // if (fDepth != 0)
922 // rateRatio = (Double_t)fCountArray[fDepth]->At(iCrystal*fgkNofSectors + iSector)/max*0.85;
923 // else
924 // rateRatio = (Double_t)fCountArray[fDepth]->At(iCrystal*fgkNofSectors + iSector)/fCountCoreMax*0.85;
925 
926 // if ( gDebug > 3 ) {
927 // printf("count %d ratio %lf for sector %d and crystal %d\n",
928 // fCountArray[fDepth]->At(iCrystal*fgkNofSectors + iSector), rateRatio,
929 // iSector, iCrystal);
930 // }
931 
932 // for (Int_t j = 0; j < fgkNofPoints; ++j) {
933 // x[j] = (detectorLine->GetX()[j] - xm)* rateRatio + xm;
934 // y[j] = (detectorLine->GetY()[j] - ym)* rateRatio + ym;
935 // }
936 
937 // rateLine->SetPolyLine(fgkNofPoints, x, y, "f");
938 // rateLine->SetUniqueID(fCountArray[fDepth]->At(iCrystal*fgkNofSectors + iSector));
939 // }
940 // }
941 
942 // // show depth
943 // fDepthText->Clear();
944 // fDepthText->SetTextSize(0.04);
945 // fDepthText->SetText(-fgkDRange/2+20, -fgkDRange/2+20, Form("Depth: %d", fDepth));
946 
947 // fCurrentCycle++;
948 //}
949 
951 
952 //void RateDisplay::Reset()
953 //{
954 // // reset counters + cycle
955 // fCountMax->Reset();
956 // fCountCoreMax = 1;
957 // for (Int_t i = 0; i < fgkNofSlices+1; ++i)
958 // fCountArray[i]->Reset();
959 
960 // fCountMaxAll = 0;
961 //}
962 
966 
967 EBWatcher::EBWatcher(const char *name, const char *title, TDirectory *sp_dir, TDirectory *tag_dir) :
968  EventPSAWatcher(name,title,sp_dir,tag_dir),
969  CanvasVisu(name,title),
970  fTrans(0x0),
971  fSpectra(180),
972  fCoreCommon(0x0),
973  fGxG(0x0),
974  fGxT(0x0),
975  fDistri(0x0),
976  fPosXYZ_Ta(0x0)
977 {
978  fSpectra.SetOwner(false);
979 
981 
982  // Vertex used for doppler correction, last registered
983  fVertexBuilder = VertexBuilder::theCurrentVertexBuilder();
984  if ( fVertexBuilder == 0x0 )
985  std::cout << "Should not be NULL " << std::endl;
986 
987  if ( gSystem->AccessPathName("CrystalPositionLookUpTable") ) { // does not exist
988  if ( gSystem->AccessPathName("CrystalPositionLookUpTable.dat") ) {
989  fLog << error << " CrystalPositionLookUpTable required " << nline;
990  }
991  else {
992  fLog << info << " Ge positions extracted from CrystalPositionLookUpTable.dat " << nline;
993  fTrans->ReadTransformations("CrystalPositionLookUpTable.dat");
994  }
995  }
996  else {
997  fLog << info << " Ge positions extracted from CrystalPositionLookUpTable.dat " << nline;
998  fTrans->ReadTransformations("CrystalPositionLookUpTable");
999  }
1000 
1001  for (UInt_t i = 0u; i < gNbCrys; i++ ) {
1002 
1003  TString tmp; TH1F *h;
1004 
1005  tmp = Form("Crystal_%d",i);
1006  h = MakeTH1<TH1F>(tmp.Data(),"Core energy of the crystal", 4096,0,4096);
1007  fSpectra.Add ( h );
1008  }
1009  fCoreCommon = MakeTH1<TH1F>("CoreCommon","Core common spectrum",8192,0,4096);
1010  fSumSpectra = MakeTH1<TH1F>("SumSpectra","Sum of all core spectra",8192,0,4096);
1011  fGxG = MakeTH2<TH2F>("GxG_HG","Gamma Gamma Matrix (High gain)",4096,0,4096,4096,0,4096);
1012  fDistri = MakeTH1<TH1F>("CrystalDistri","Distribution of the crystal fired",gNbCrys,0,gNbCrys);
1013  fPosXYZ_Ta = MakeTH3<TH3F>("PosXYZ_Ta","Distribution of hits in Space with Target hit",200,-400,400,200,-400,400,200,-400,400);
1014  fGxT = MakeTH2<TH2F>("GxT_LG","Gamma Time Matrix (Low gain)",4096,0,4096,300,0,300);
1015  fFold = MakeTH1<TH1F>("Fold","Crystal Fold distributions",20,0,20);
1016 }
1017 
1019 
1021 {
1022  if (fTrans) {
1023  delete fTrans; fTrans = 0x0;
1024  }
1025 }
1026 
1028 
1030 {
1031  int PadNbr = 0;
1032 
1033  TString Name = Form("EB_CrystSpectra_%d_%d",PadNbr+1,PadNbr+16);
1034  TString Title = "Crystal of the hited crystals at the event builder level";
1035 
1036  TCanvas *c = CanvasVisu::NewCanvas(Name,Title);
1037  new LoupeOnPad(c);
1038  SetLoupe(false);
1039 
1040  c->Divide(4,4,0.001,0.001);
1041 
1042  double topmarg = 0.0679612;
1043  double rightmarg = 0.0121951;
1044  double leftmarg = 0.0983588;
1045  double bottommarg = 0.11165;
1046 
1047  c->cd(PadNbr+1);
1048  gPad->SetRightMargin(rightmarg);
1049  gPad->SetTopMargin(topmarg);
1050  gPad->SetLeftMargin(leftmarg);
1051  gPad->SetBottomMargin(bottommarg);
1052 
1053  fDistri->SetBit(TH1::kNoTitle);
1054 
1055  fDistri->GetXaxis()->SetTitle("Crystal ID");
1056  fDistri->GetXaxis()->SetLabelSize(0.05);
1057  fDistri->GetXaxis()->SetTitleSize(0.06);
1058  fDistri->GetXaxis()->SetTitleOffset(0.85);
1059 
1060  fDistri->GetYaxis()->SetTitle("Counts");
1061  fDistri->GetYaxis()->SetLabelSize(0.05);
1062  fDistri->GetYaxis()->SetTitleSize(0.06);
1063  fDistri->GetYaxis()->SetTitleOffset(0.90);
1064 
1065  fDistri->SetLineColor(GetColor(0));
1066 
1067  fDistri->Draw();
1068 
1069  gPad->Modified();
1070  gPad->Update();
1071 
1072  TPaveStats *st = (TPaveStats*)fDistri->FindObject("stats");
1073  if(st)
1074  {
1075  st->SetX2NDC(1-rightmarg);
1076  st->SetY2NDC(1-topmarg);
1077  st->SetX1NDC(0.681013);
1078  st->SetY1NDC(0.663962);
1079  }
1080 
1081  PadNbr++;
1082 
1083  for(int i=0 ; i<fDistri->GetNbinsX() ; i++)
1084  {
1085  if(fDistri->GetBinContent(i+1))
1086  {
1087  if(PadNbr%16==0)
1088  {
1089  Name = Form("EB_CrystSpectra_%d_%d",PadNbr+1,PadNbr+16);
1090  c = CanvasVisu::NewCanvas(Name,Title);
1091  new LoupeOnPad(c);
1092  SetLoupe(false);
1093  c->Divide(4,4,0.001,0.001);
1094  }
1095 
1096  c->cd(PadNbr%16+1);
1097 
1098  TH1 *h = (TH1*)fSpectra[i];
1099  if(h)
1100  {
1101  gPad->SetRightMargin(rightmarg);
1102  gPad->SetTopMargin(topmarg);
1103  gPad->SetLeftMargin(leftmarg);
1104  gPad->SetBottomMargin(bottommarg);
1105 
1106  h->SetBit(TH1::kNoTitle);
1107 
1108  h->GetXaxis()->SetTitle("Energy (keV)");
1109  h->GetXaxis()->SetLabelSize(0.05);
1110  h->GetXaxis()->SetTitleSize(0.06);
1111  h->GetXaxis()->SetTitleOffset(0.85);
1112 
1113  h->GetYaxis()->SetTitle("Counts");
1114  h->GetYaxis()->SetLabelSize(0.05);
1115  h->GetYaxis()->SetTitleSize(0.06);
1116  h->GetYaxis()->SetTitleOffset(0.90);
1117 
1118  h->SetLineColor(GetColor(0));
1119 
1120  h->Draw();
1121 
1122  gPad->Modified();
1123  gPad->Update();
1124 
1125  st = (TPaveStats*)h->FindObject("stats");
1126  if(st)
1127  {
1128  st->SetX2NDC(1-rightmarg);
1129  st->SetY2NDC(1-topmarg);
1130  st->SetX1NDC(0.681013);
1131  st->SetY1NDC(0.663962);
1132  }
1133 
1134  }
1135  PadNbr++;
1136  }
1137  }
1138 }
1139 
1141 
1143 {
1144  TString Name = "EB_SuperimposedCores";
1145  TString Title = "Superposition of the core spectra at the event builder level";
1146 
1147  TCanvas *c = CanvasVisu::NewCanvas(Name,Title);
1148 
1149  double topmarg = 0.00240964;
1150  double rightmarg = 0.00120919;
1151  double leftmarg = 0.0719468;
1152  double bottommarg = 0.0843373;
1153 
1154  c->cd();
1155  gPad->SetRightMargin(rightmarg);
1156  gPad->SetTopMargin(topmarg);
1157  gPad->SetLeftMargin(leftmarg);
1158  gPad->SetBottomMargin(bottommarg);
1159 
1160  bool FirstHist = true;
1161 
1162  int color = 0;
1163 
1164  TLegend *leg=0x0;
1165 
1166  double deltaYLeg = 0.035;
1167  int n=0;
1168 
1169  for(int i=0 ; i<fDistri->GetNbinsX() ; i++)
1170  {
1171  if(fDistri->GetBinContent(i+1) && fSpectra[i])
1172  {
1173  TH1 *h = (TH1*)fSpectra[i];
1174  h->SetTitle(Form("Crystal %d",i));
1175  h->SetLineColor(GetColor(color));
1176 
1177  if(FirstHist)
1178  {
1179  h->SetBit(TH1::kNoTitle);
1180  h->SetStats(false);
1181  h->GetXaxis()->SetTitle("Energy (keV)");
1182  h->GetXaxis()->SetLabelSize(0.04);
1183  h->GetXaxis()->SetTitleSize(0.04);
1184  h->GetXaxis()->SetTitleOffset(1.);
1185 
1186  h->GetYaxis()->SetTitle("Counts");
1187  h->GetYaxis()->SetLabelSize(0.04);
1188  h->GetYaxis()->SetTitleSize(0.04);
1189  h->GetYaxis()->SetTitleOffset(1.);
1190 
1191  h->Draw();
1192 
1193  leg = new TLegend(0.874849,1-topmarg-deltaYLeg,1-rightmarg,1-topmarg,"","NDC");
1194  leg->SetMargin(0.4);
1195  leg->AddEntry(h,h->GetTitle(),"l");
1196 
1197  n++;
1198  FirstHist = false;
1199  }
1200  else
1201  {
1202  h->Draw("same");
1203  h->SetStats(false);
1204  leg->AddEntry(h,h->GetTitle(),"l");
1205 
1206  n++;
1207  }
1208 
1209  color++;
1210  }
1211  }
1212 
1213  leg->Draw();
1214 
1215  gPad->Modified();
1216  gPad->Update();
1217 
1218  leg->SetY1NDC(leg->GetY1NDC()-n*deltaYLeg);
1219 
1220 }
1221 
1223 
1225 {
1226  TString Name = "EB_CommonVsSum";
1227  TString Title = "Core common spectra compared to sum spectra at the event builder level";
1228 
1229  TCanvas *c = CanvasVisu::NewCanvas(Name,Title);
1230 
1231  if(!OnSamePad)
1232  {
1233  c->Divide(1,2,0.001,0.001);
1234 
1235  double topmarg = 0.0657599;
1236  double rightmarg = 0.00726832;
1237  double leftmarg = 0.0490612;
1238  double bottommarg = 0.114119;
1239 
1240  TH1 *h[2] = {fCoreCommon,fSumSpectra};
1241 
1242  for(int i=0 ; i<2 ; i++)
1243  {
1244  c->cd(i+1);
1245 
1246  gPad->SetRightMargin(rightmarg);
1247  gPad->SetTopMargin(topmarg);
1248  gPad->SetLeftMargin(leftmarg);
1249  gPad->SetBottomMargin(bottommarg);
1250 
1251  TH1 *htemp = h[i];
1252 
1253  htemp->SetLineColor(GetColor(0));
1254  htemp->Draw();
1255 
1256  htemp->SetStats(false);
1257  htemp->GetXaxis()->SetTitle("Energy (keV)");
1258  htemp->GetXaxis()->SetTitleSize(0.06);
1259  htemp->GetXaxis()->SetLabelSize(0.06);
1260  htemp->GetXaxis()->SetTitleOffset(0.91);
1261 
1262  htemp->GetYaxis()->SetTitle("Counts");
1263  htemp->GetYaxis()->SetTitleSize(0.06);
1264  htemp->GetYaxis()->SetLabelSize(0.06);
1265  htemp->GetYaxis()->SetTitleOffset(0.45);
1266 
1267  gPad->Modified();
1268  gPad->Update();
1269 
1270  TPaveStats *st = (TPaveStats*)htemp->FindObject("stats");
1271  if(st)
1272  {
1273  st->SetX2NDC(1-rightmarg);
1274  st->SetY2NDC(1-topmarg);
1275  }
1276 
1277  TPaveText *txt = (TPaveText*)gPad->FindObject("title");
1278  if(txt)
1279  {
1280  double width = txt->GetY2NDC()-txt->GetY1NDC();
1281  txt->SetY2NDC(1-topmarg);
1282  txt->SetY1NDC(txt->GetY2NDC()-width);
1283  }
1284 
1285  if(i==0)
1286  {
1287  TPad *pad = new TPad("Crystal fold", "Crystal fold distribution",0.7,0.6,1-rightmarg-0.0025,1-topmarg-0.005);
1288  pad->SetRightMargin(0.00486268);
1289  pad->SetTopMargin(0.00912681);
1290  pad->SetLeftMargin(0.0736404);
1291  pad->SetBottomMargin(0.195208);
1292  pad->Draw();
1293  pad->cd();
1294  pad->SetLogy();
1295  fFold->SetLineColor(GetColor(0));
1296  fFold->SetStats(false);
1297  fFold->GetXaxis()->SetTitle("Crystal Fold");
1298  fFold->GetXaxis()->SetTitleSize(0.08);
1299  fFold->GetXaxis()->SetLabelSize(0.08);
1300 
1301  fFold->GetYaxis()->SetTitle("Counts");
1302  fFold->GetYaxis()->SetTitleSize(0.08);
1303  fFold->GetYaxis()->SetLabelSize(0.08);
1304  fFold->GetYaxis()->SetTitleOffset(0.5);
1305  fFold->Draw();
1306  }
1307  }
1308  }
1309  else
1310  {
1311  double topmarg = 0.00240964;
1312  double rightmarg = 0.00120919;
1313  double leftmarg = 0.0719468;
1314  double bottommarg = 0.0843373;
1315 
1316  c->cd();
1317 
1318  gPad->SetRightMargin(rightmarg);
1319  gPad->SetTopMargin(topmarg);
1320  gPad->SetLeftMargin(leftmarg);
1321  gPad->SetBottomMargin(bottommarg);
1322 
1323  fCoreCommon->SetBit(TH1::kNoTitle);
1324  fCoreCommon->SetLineColor(GetColor(0));
1325  fCoreCommon->SetStats(false);
1326  fCoreCommon->Draw();
1327 
1328  fCoreCommon->GetXaxis()->SetTitle("Energy (keV)");
1329  fCoreCommon->GetXaxis()->SetTitleSize(0.04);
1330  fCoreCommon->GetXaxis()->SetLabelSize(0.04);
1331  fCoreCommon->GetXaxis()->SetTitleOffset(1.);
1332 
1333  fCoreCommon->GetYaxis()->SetTitle("Counts");
1334  fCoreCommon->GetYaxis()->SetTitleSize(0.04);
1335  fCoreCommon->GetYaxis()->SetLabelSize(0.04);
1336  fCoreCommon->GetYaxis()->SetTitleOffset(1.);
1337 
1338  fSumSpectra->SetLineColor(GetColor(1));
1339  fSumSpectra->SetStats(false);
1340  fSumSpectra->Draw("same");
1341 
1342  gPad->Modified();
1343  gPad->Update();
1344 
1345  TLegend *leg = new TLegend(0.756348,0.870486,1-rightmarg,1-topmarg,"Core common VS Sum spectra","NDC");
1346  leg->AddEntry(fCoreCommon,fCoreCommon->GetTitle(),"l");
1347  leg->AddEntry(fSumSpectra,fSumSpectra->GetTitle(),"l");
1348  leg->Draw();
1349  }
1350 }
1351 
1353 
1355 {
1356  TString Name = "EB_GammaGamma";
1357  TString Title = "Gamma Gamma matrix at the event builder level";
1358 
1359  CanvasVisu::NewCanvas(Name,Title);
1360 
1361  double topmarg = 0.0156627;
1362  double rightmarg = 0.00120919;
1363  double leftmarg = 0.0719468;
1364  double bottommarg = 0.0843373;
1365 
1366  gPad->SetRightMargin(rightmarg);
1367  gPad->SetTopMargin(topmarg);
1368  gPad->SetLeftMargin(leftmarg);
1369  gPad->SetBottomMargin(bottommarg);
1370 
1371  fGxG->SetBit(TH2::kNoTitle);
1372  fGxG->GetXaxis()->SetTitle("Energy #gamma_{1} (keV)");
1373  fGxG->GetYaxis()->SetTitle("Energy #gamma_{2} (keV)");
1374  fGxG->Draw("col");
1375  gPad->SetLogz();
1376 
1377  gPad->Modified();
1378  gPad->Update();
1379 
1380  TPaveStats *st = (TPaveStats*)fGxG->FindObject("stats");
1381  if(st)
1382  {
1383  st->SetX2NDC(1-rightmarg);
1384  st->SetY2NDC(1-topmarg);
1385  }
1386 }
1387 
1389 
1391 {
1392  TString Name = "EB_GammaTime";
1393  TString Title = "Gamma Time matrix at the event builder level";
1394 
1395  CanvasVisu::NewCanvas(Name,Title);
1396 
1397  double topmarg = 0.0156627;
1398  double rightmarg = 0.00120919;
1399  double leftmarg = 0.0719468;
1400  double bottommarg = 0.0843373;
1401 
1402  gPad->SetRightMargin(rightmarg);
1403  gPad->SetTopMargin(topmarg);
1404  gPad->SetLeftMargin(leftmarg);
1405  gPad->SetBottomMargin(bottommarg);
1406 
1407  fGxT->SetBit(TH2::kNoTitle);
1408  fGxT->GetXaxis()->SetTitle("Energy low gain (keV)");
1409  fGxT->GetYaxis()->SetTitle("Time low gain (ns)");
1410  fGxT->Draw("col");
1411  gPad->SetLogz();
1412 
1413  gPad->Modified();
1414  gPad->Update();
1415 
1416  TPaveStats *st = (TPaveStats*)fGxT->FindObject("stats");
1417  if(st)
1418  {
1419  st->SetX2NDC(1-rightmarg);
1420  st->SetY2NDC(1-topmarg);
1421  }
1422 }
1423 
1425 
1427 {
1428  TString Name = "EB_3DHits";
1429  TString Title = "3D Hits for the whole array with target vertex ";
1430 
1431  CanvasVisu::NewCanvas(Name,Title);
1432 
1433  fPosXYZ_Ta->Draw();
1434 
1435 }
1436 
1438 
1439 void EBWatcher::Exec(Option_t * /*option*/)
1440 {
1441  Double_t xLocal, yLocal, zLocal, xGlobal, yGlobal, zGlobal; TrackedHitImp<EHit,EHit> gamma; Float_t gg[150];
1442 
1443  // be sure the frame has been set properly
1444  if ( fFrame == 0x0 || !fFrame->IsValid() ) {
1445  cout << "non valid frame" << endl;
1446  return;
1447  }
1448 
1449  // the vertex used for doppler correction
1450  VertexInterface *vertex = 0x0;
1451  vertex = fVertexBuilder->GetVertex();
1452  TH1F *h;
1453  UInt_t nb_frames = GetNbFramePSA();
1454 
1455  fFold->Fill(nb_frames);
1456 
1457  double SumEnergy = 0.;
1458 
1459  for(UInt_t i = 0u; i <nb_frames; i++) {
1460 
1461  PSAInterface *data = GetDataPSA(i);
1462  gg[i] = data->GetE();
1463  h = (TH1F *)fSpectra.At(data->GetUID());
1464  if ( h ) {
1465  h->Fill(data->GetE());
1466  }
1467  fGxT->Fill(data->GetE(1),data->GetT(1));
1468 
1469  SumEnergy += data->GetE();
1470  fCoreCommon->Fill(data->GetE());
1471  fDistri->Fill(data->GetUID());
1472 
1473  // Now look for the hit with the highest energy, taken for Doppler correction
1474  // Kind of tracking in crystal
1475  Int_t nHits = data->GetNbHits();
1476  Double_t max_e = 0.0;
1477  //test DR
1478  Double_t xt,yt,zt;
1479  vertex->GetPosition(xt,yt,zt);
1480  fPosXYZ_Ta->Fill(xt,yt,zt);
1481 
1482  for (UShort_t j = 0u; j < nHits; ++j) {
1483 
1484  const PSAHit* pHit = (PSAHit*)data->GetHit(j);
1485  //
1486  pHit->GetXYZ(xLocal, yLocal, zLocal);
1487  fTrans->Local2Global(data->GetUID(), xLocal, yLocal, zLocal, xGlobal, yGlobal, zGlobal);//y,x,z
1488  fPosXYZ_Ta->Fill(xGlobal, yGlobal, zGlobal);
1489 
1490  if ( pHit->GetE() > max_e ) {
1491  gamma.SetXYZ(xGlobal, yGlobal, zGlobal);
1492  max_e = pHit->GetE();
1493  }
1494  }
1495  }
1496 
1497  fSumSpectra->Fill(SumEnergy);
1498 
1499  for(UInt_t i = 0u; i <nb_frames; i++) {
1500  for(UInt_t j = i+1; j <nb_frames; j++) {
1501 
1502  fGxG->Fill(gg[i],gg[j]); fGxG->Fill(gg[j],gg[i]);
1503  }
1504  }
1505 }
1506 
1510 
1511 TimeCheckBuilder::TimeCheckBuilder(const char *name, const char *title, TDirectory *sp_dir, TDirectory *tag_dir) :
1512  EventPSAWatcher(name,title,sp_dir,tag_dir),
1513  CanvasVisu(name,title),
1514  fGoodInit(true)
1515 {
1516  ReadConfFile();
1517 
1518  fTotalHistPos = fTSWindow/fDeltaTS+1;
1519  fGraphPos = fTotalHistPos+1;
1520 
1521  if(fTSWindow%fDeltaTS != 0)
1522  {
1523  cout<<"Time stamp window is not a entire step TS factor"<<endl;
1524  fGoodInit = false;
1525  }
1526 
1527  fListOfHists = new TList();
1528 
1529  for (Int_t i = 0; i < gNbCrys; i++ )
1530  {
1531  Int_t Id = GetCrystalId(CrystalNames[i]);
1532 
1533  fLastFitResultCore[Id][0] = 100;
1534  fLastFitResultCore[Id][1] = fERef;
1535  fLastFitResultCore[Id][2] = 2;
1536  // fLastFitResult[i][3] = 0;
1537 
1538  fLastTS[Id] =0;
1539  fFirstTS[Id] =0;
1540  fTSMax[Id] = (Double_t)fDeltaTS*60;
1541 
1542 // cout<<CrystalNames[i]<<" "<<Id<<endl;
1543 
1544  fSpectra[Id] = MakeTH1<TH1F>(Form("Cry%.3d_%s",Id,CrystalNames[i].Data()),"Core energy for the crystal", 8000,0,4000);
1545 
1548  f_TS_Dist[Id] = BuildArray(Form("TS_%.3d_%s",Id,CrystalNames[i].Data()),15*24*(60/fDeltaTS),0,15*24*3600.,false);
1549 
1550  f_CoreCheck[Id] = BuildArray(Form("CoreCheck_%.3d_%s",Id,CrystalNames[i].Data()),8000,0,4000,true);
1551 
1552  fGausFuncCry[Id] = new TF1(Form("gaus_%.3d_%s",Id,CrystalNames[i].Data()),"gaus");
1553 
1554  ((TGraph*)f_CoreCheck[Id]->At(fGraphPos))->SetPoint(0,0,fERef);
1555 
1556  fCoreLines[Id] = new TLine;
1557  fCoreLines[Id]->SetLineColor(kRed);
1558  fCoreLines[Id]->SetLineStyle(2);
1559  fCoreLines[Id]->SetLineWidth(2);
1560 
1561  fLastFittedHist[Id] = 0x0;
1562  fLastFitFunction[Id] = 0x0;
1563 
1565 
1566  if(fCrystalListForSegments.Contains(CrystalNames[i]))
1567  {
1568  for (Int_t j = 0u; j < gNbSeg; j++ )
1569  {
1570  fLastFitResultSeg[Id][j][0] = 100;
1571  fLastFitResultSeg[Id][j][1] = fERef;
1572  fLastFitResultSeg[Id][j][2] = 2;
1573 
1574  f_SegCheck[Id][j] = BuildArray(Form("SegCheck_%.3d_%s_Seg_%d",Id,CrystalNames[i].Data(),j),8000,0,4000,true);
1575  fGausFuncSeg[Id][j] = new TF1(Form("gaus_%.3d_%s_Seg_%d",Id,CrystalNames[i].Data(),j),"gaus");
1576  }
1577  }
1578  }
1579 }
1580 
1581 void TimeCheckBuilder::ReadConfFile()
1582 {
1583  ifstream ConfFile("TimeChecks.conf");
1584 
1585  string Line;
1586  TString Buffer;
1587 
1588  while(ConfFile)
1589  {
1590  getline(ConfFile,Line);
1591  Buffer = Line;
1592 
1593  if(Buffer.BeginsWith("#"))
1594  continue;
1595 
1596  if(Buffer.BeginsWith("ERef="))
1597  {
1598  Buffer.ReplaceAll("ERef=","").ReplaceAll(" ","");
1599  fERef = Buffer.Atof();
1600  }
1601  if(Buffer.BeginsWith("CrystalList="))
1602  {
1603  Buffer.ReplaceAll("CrystalList=","");
1604  fCrystalList = Buffer;
1605 
1606  TObjArray *arr = Buffer.Tokenize(" ");
1607  gNbCrys = arr->GetEntries();
1608 
1609  for(int i=0 ; i<gNbCrys ; i++)
1610  CrystalNames[i] = arr->At(i)->GetName();
1611 
1612  delete arr;
1613  }
1614  if(Buffer.BeginsWith("CrystalListForSegments="))
1615  {
1616  Buffer.ReplaceAll("CrystalListForSegments=","");
1617  fCrystalListForSegments = Buffer;
1618  }
1619  if(Buffer.BeginsWith("DeltaTS="))
1620  {
1621  Buffer.ReplaceAll("DeltaTS=","").ReplaceAll(" ","");
1622  fDeltaTS = Buffer.Atoi();
1623  }
1624  if(Buffer.BeginsWith("TSWindow="))
1625  {
1626  Buffer.ReplaceAll("TSWindow=","").ReplaceAll(" ","");
1627  fTSWindow=Buffer.Atoi();
1628  }
1629  if(Buffer.BeginsWith("NToFill="))
1630  {
1631  Buffer.ReplaceAll("NToFill=","").ReplaceAll(" ","");
1632  fNToFill=Buffer.Atoi();
1633  }
1634  }
1635  ConfFile.close();
1636 
1638  cout<<endl;
1639  cout<<"Reference gamma energy to follow : "<<fERef<<"keV"<<endl;
1640  cout<<"Crystals wich are followed only at the core level : "<<endl<<fCrystalList<<endl;
1641  cout<<"Crystals wich are followed at the segment level : "<<endl<<fCrystalListForSegments<<endl;
1642  cout<<"Delta TS in min : "<<fDeltaTS<<" min"<<endl;
1643  cout<<"Total integrated window in min : "<<fTSWindow<<"min"<<endl;
1644  cout<<"Minimum number of DeltaT wich needs to contains data to analyse the total integrated window histogram : "<<fNToFill<<endl;
1645  cout<<endl;
1647 }
1648 
1649 TString TimeCheckBuilder::GetCrystalName(Int_t cry)
1650 {
1651  Int_t Ctemp = cry/3;
1652  Int_t C=Ctemp;
1653 
1654  Int_t C2 = cry%3;
1655 
1656  TString Name="";
1657 
1658  if(C2==0)
1659  Name = Form("%.2dA",C);
1660  if(C2==1)
1661  Name = Form("%.2dB",C);
1662  if(C2==2)
1663  Name = Form("%.2dC",C);
1664 
1665  return Name;
1666 }
1667 
1668 Int_t TimeCheckBuilder::GetCrystalId(TString Name)
1669 {
1670  Int_t Ctemp;
1671  Int_t C;
1672  Int_t C2;
1673 
1674  if(Name.Contains("A"))
1675  C2=0;
1676  if(Name.Contains("B"))
1677  C2=1;
1678  if(Name.Contains("C"))
1679  C2=2;
1680 
1681  Name.Remove(Name.Length()-1,1);
1682 
1683  Ctemp = Name.Atoi();
1684 
1685  C=Ctemp;
1686 
1687  C=3*C+C2;
1688 
1689  return C;
1690 }
1691 
1693 
1694 void TimeCheckBuilder::Exec(Option_t * /*option*/)
1695 {
1696  // be sure the frame has been set properly
1697  if ( fFrame == 0x0 || !fFrame->IsValid() ) {
1698  cout << "non valid frame" << endl;
1699  return;
1700  }
1701 
1702  if(fGoodInit==false)
1703  return;
1704 
1705  TH1F *h;
1706  UInt_t nb_frames = GetNbFramePSA();
1707 
1708  for(UInt_t i = 0u; i <nb_frames; i++)
1709  {
1710  PSAInterface *data = GetDataPSA(i);
1711 
1712  Int_t CryId = data->GetUID();
1713 
1714  TString Name = GetCrystalName(CryId);
1715 
1716 // cout<<CryId<<" "<<Name<<endl;
1717 
1718  if(!fCrystalList.Contains(Name))
1719  continue;
1720 
1721  h = (TH1F *)fSpectra[CryId];
1722  if ( h )
1723  h->Fill(data->GetE());
1724 
1725  fTS = ((AgataKey*) fFrame->GetFrame()->GetSubKey(i))->GetTimeStamp();
1726 
1727  if(fLastTS[CryId] == 0)
1728  {
1729  fFirstTS[CryId] = fTS;
1730  fLastTS[CryId] = fTS;
1731  continue;
1732  }
1733 
1734  Double_t TimeInSec = ((Double_t)fTS-(Double_t)fFirstTS[CryId])*1e-8;
1735 
1736  if(TimeInSec<fTSMax[CryId])
1737  {
1738  ((TH1F*)f_TS_Dist[CryId]->At(0))->Fill(TimeInSec);
1739  ((TH1F*)f_CoreCheck[CryId]->At(0))->Fill(data->GetE());
1740 
1741  if(fCrystalListForSegments.Contains(Name))
1742  {
1743  Int_t NHits = data->GetNbHits();
1744 
1745  for(int ihit=0 ; ihit<NHits ; ihit++)
1746  {
1747  PSAHit *hit = (PSAHit*)data->GetHit(ihit);
1748  Int_t SegId = hit->GetID(0);
1749  Float_t SegE = hit->GetE();
1750 
1751  ((TH1F*)f_SegCheck[CryId][SegId]->At(0))->Fill(SegE);
1752  }
1753  }
1754  }
1755  else
1756  {
1757  ReProcessHists(CryId);
1758 
1759  Int_t NFill = GetNFill(CryId);
1760 
1761  if(NFill >= fNToFill)
1762  {
1763  AnalyseGraphs(CryId);
1764  }
1765 
1766  if(NFill==0)
1767  {
1768  fTSMax[CryId] = (Double_t)TimeInSec+fDeltaTS*60;
1769  }
1770  else
1771  {
1772  fTSMax[CryId] += fDeltaTS*60;
1773  }
1774  }
1775  }
1776 }
1777 
1778 void TimeCheckBuilder::AnalyseGraphs(Int_t cry)
1779 {
1780  TH1F *X_Hist = ((TH1F*)f_TS_Dist[cry]->At(fTotalHistPos));
1781 
1782  TString CryName = GetCrystalName(cry);
1783 
1784  for(int i=0 ; i<fListOfHists->GetSize() ; i++)
1785  {
1786  TObjArray *arr = (TObjArray*)fListOfHists->At(i);
1787 
1788  if(arr->GetEntries()==fGraphPos+1)
1789  {
1790  TGraph *gr = (TGraph*)arr->At(fGraphPos);
1791 
1792  TH1F *Y_Hist = ((TH1F*)arr->At(fTotalHistPos));
1793  TString tmp = Y_Hist->GetName();
1794 
1795  if(Y_Hist->GetEntries()<1000 || !tmp.Contains(CryName))
1796  continue;
1797 
1798  TString BaseName = gr->GetName();
1799 
1800  if(BaseName.Contains("CoreCheck"))
1801  {
1802  Y_Hist->GetXaxis()->SetRangeUser(fLastFitResultCore[cry][1]-10,fLastFitResultCore[cry][1]+10);
1803 
1804  Double_t Norm = fLastFitResultCore[cry][0];
1805  Float_t Mean = Y_Hist->GetBinCenter(Y_Hist->GetMaximumBin());
1806  Float_t Sigma = fLastFitResultCore[cry][2];
1807 
1808  fGausFuncCry[cry]->SetParameters(Norm,Mean,Sigma);
1809 
1810  // cout<<Norm<<" "<<0<<" "<<TMath::Max(Y_Hist->GetMaximum(),Norm)<<endl;
1811  // cout<<Mean<<" "<<Mean-2<<" "<<Mean+2<<endl;
1812  // cout<<Sigma<<" "<<0<<" "<<5<<endl;
1813 
1814  fGausFuncCry[cry]->SetParLimits(0,0,TMath::Max(Y_Hist->GetMaximum(),Norm)*1.2);
1815  fGausFuncCry[cry]->SetParLimits(1,Mean-2,Mean+2);
1816  fGausFuncCry[cry]->SetParLimits(2,0,10);
1817 
1818  Y_Hist->Fit(fGausFuncCry[cry],"Q0","",Mean-2,Mean+2);
1819 
1820  fLastFitResultCore[cry][0] = fGausFuncCry[cry]->GetParameter(0);
1821  fLastFitResultCore[cry][1] = fGausFuncCry[cry]->GetParameter(1);
1822  fLastFitResultCore[cry][2] = fGausFuncCry[cry]->GetParameter(2);
1823 
1824  if(gr->GetN() && gr->GetX()[0]==0)
1825  gr->RemovePoint(0);
1826 
1827  gr->SetPoint(gr->GetN(), X_Hist->GetMean(), fLastFitResultCore[cry][1]);
1828 
1829  fCoreLines[cry]->SetX1(gr->GetX()[0]);
1830  fCoreLines[cry]->SetX2(gr->GetX()[gr->GetN()-1]);
1831 
1832  Double_t max = TMath::MaxElement(gr->GetN(),gr->GetY());
1833  Double_t min = TMath::MinElement(gr->GetN(),gr->GetY());
1834 
1835  gr->SetMaximum(TMath::Max(max+gr->GetRMS(2),fERef+gr->GetRMS(2)));
1836  gr->SetMinimum(TMath::Min(min-gr->GetRMS(2),fERef-gr->GetRMS(2)));
1837 
1838 
1839  if(fLastFittedHist[cry] == 0x0)
1840  {
1841  fLastFittedHist[cry] = (TH1F*)Y_Hist->Clone();
1842  fLastFitFunction[cry] = (TF1*)fGausFuncCry[cry]->Clone();
1843  }
1844  else
1845  {
1846  fLastFittedHist[cry]->Reset();
1847  fLastFittedHist[cry]->Add(Y_Hist);
1848 
1849  fLastFittedHist[cry]->GetXaxis()->SetRangeUser(fLastFitResultCore[cry][1]-5*fLastFitResultCore[cry][2],fLastFitResultCore[cry][1]+5*fLastFitResultCore[cry][2]);
1850 
1851  fLastFitFunction[cry]->SetParameters(fGausFuncCry[cry]->GetParameters());
1852  fLastFitFunction[cry]->SetRange(Mean-2,Mean+2);
1853  }
1854  }
1855  else if(BaseName.Contains("SegCheck"))
1856  {
1857  TObjArray *arr = BaseName.Tokenize("_");
1858  Int_t SegId = ((TString)arr->At(5)->GetName()).Atoi();
1859  delete arr;
1860 
1861  Y_Hist->GetXaxis()->SetRangeUser(fLastFitResultSeg[cry][SegId][1]-10,fLastFitResultSeg[cry][SegId][1]+10);
1862 
1863  Double_t Norm = fLastFitResultSeg[cry][SegId][0];
1864  Float_t Mean = Y_Hist->GetBinCenter(Y_Hist->GetMaximumBin());
1865  Float_t Sigma = fLastFitResultSeg[cry][SegId][2];
1866  // Float_t Bgd = (Y_Hist->GetBinContent(Y_Hist->FindBin(Mean-10))+Y_Hist->GetBinContent(Y_Hist->FindBin(Mean+10)))/2.;
1867 
1868  fGausFuncCry[cry]->SetParameters(Norm,Mean,Sigma/*,Bgd*/);
1869 
1870  // cout<<Norm<<" "<<0<<" "<<TMath::Max(Y_Hist->GetMaximum(),Norm)<<endl;
1871  // cout<<Mean<<" "<<Mean-2<<" "<<Mean+2<<endl;
1872  // cout<<Sigma<<" "<<0<<" "<<5<<endl;
1873 
1874  fGausFuncCry[cry]->SetParLimits(0,0,TMath::Max(Y_Hist->GetMaximum(),Norm)*1.2);
1875  fGausFuncCry[cry]->SetParLimits(1,Mean-2,Mean+2);
1876  fGausFuncCry[cry]->SetParLimits(2,0,5);
1877  // fGausFunc[cry]->SetParLimits(3,0,Y_Hist->GetMaximum());
1878 
1879  Y_Hist->Fit(fGausFuncCry[cry],"Q0","",Mean-2,Mean+3);
1880 
1881  fLastFitResultSeg[cry][SegId][0] = fGausFuncCry[cry]->GetParameter(0);
1882  fLastFitResultSeg[cry][SegId][1] = fGausFuncCry[cry]->GetParameter(1);
1883  fLastFitResultSeg[cry][SegId][2] = fGausFuncCry[cry]->GetParameter(2);
1884  // fLastFitResult[cry][3] = fGausFunc[cry]->GetParameter(3);
1885 
1886  gr->SetPoint(gr->GetN(), X_Hist->GetMean(), fLastFitResultSeg[cry][SegId][1]);
1887  }
1888  }
1889  }
1890 }
1891 
1892 Int_t TimeCheckBuilder::GetNFill(Int_t cry)
1893 {
1894  Int_t n=0;
1895  for(int i=1 ; i<fTotalHistPos ; i++)
1896  {
1897  TH1F *htemp = ((TH1F*)f_TS_Dist[cry]->At(i));
1898  if(htemp->GetEntries()>0) n++;
1899  }
1900 
1901  return n;
1902 }
1903 
1904 void TimeCheckBuilder::ReProcessHists(Int_t cry)
1905 {
1906  TString CryName = GetCrystalName(cry);
1907 
1908  for(int i=0 ; i<fListOfHists->GetSize() ; i++)
1909  {
1910  TObjArray *arr = (TObjArray*)fListOfHists->At(i);
1911 
1912  TString tmp = ((TH1F*)arr->At(fTotalHistPos))->GetName();
1913  if(!tmp.Contains(CryName))
1914  continue;
1915 
1916  ((TH1F*)arr->At(fTotalHistPos))->Reset();
1917 
1918  for(int i=fTSWindow/fDeltaTS ; i>0 ; i--)
1919  {
1920  ((TH1F*)arr->At(i))->Reset();
1921  ((TH1F*)arr->At(i))->Add(((TH1F*)arr->At(i-1)));
1922  ((TH1F*)arr->At(fTotalHistPos))->Add(((TH1F*)arr->At(i)));
1923  }
1924 
1925  ((TH1F*)arr->At(0))->Reset();
1926  }
1927 }
1928 
1929 TObjArray *TimeCheckBuilder::BuildArray(const char * BaseName,Int_t NBins, Double_t Min, Double_t Max, Bool_t MakeGraph)
1930 {
1931  TObjArray *arr = new TObjArray(2+fTotalHistPos+MakeGraph);
1932 
1933  arr->Add(new TH1F(Form("%s_PreLoad_%dmin",BaseName,fDeltaTS),Form("%s_PreLoad_%dmin",BaseName,fDeltaTS),NBins,Min,Max));
1934 
1935  for(int i=1 ; i<=fTSWindow/fDeltaTS ; i++) arr->Add(new TH1F(Form("%s_%d-%dmin",BaseName,(i-1)*fDeltaTS,i*fDeltaTS),Form("%s_%d-%dmin",BaseName,(i-1)*fDeltaTS,i*fDeltaTS),NBins,Min,Max));
1936 
1937  arr->Add(new TH1F(Form("%s_%dMin",BaseName,fTSWindow),Form("%s_%dMin",BaseName,fTSWindow),NBins,Min,Max));
1938 
1939  if(MakeGraph)
1940  {
1941  TGraph *gr = new TGraph();
1942  gr->SetNameTitle(Form("Mean_%s_vs_Time",BaseName),Form("Mean_%s_vs_Time",BaseName));
1943  gr->SetMarkerStyle(20);
1944  gr->SetMarkerColor(2);
1945  gr->GetXaxis()->SetLabelSize(0.06);
1946  gr->GetYaxis()->SetLabelSize(0.06);
1947 
1948  arr->Add(gr);
1949 
1950  TFolder *folder = GetSubFolder(fTopFolder);
1951  folder->Add((TObject *)gr);
1952  AddToPool(gr);
1953  }
1954 
1955  fListOfHists->Add(arr);
1956 
1957  return arr;
1958 }
1959 
1960 #include "TFrame.h"
1961 
1963 {
1964  int PadNbr = 0;
1965 
1966  TString Name = Form("EB_TimeCheckBuilder_%d",PadNbr+1);
1967  TString Title = "TimeCheckBuilder at the event builder level";
1968 
1969  TCanvas *c = CanvasVisu::NewCanvas(Name,Title);
1970  new LoupeOnPad(c);
1971  SetLoupe(false);
1972 
1973  Int_t Nx = 5;
1974  Int_t Ny = 4;
1975 
1976  Int_t NPads = Nx*Ny;
1977 
1978  c->Divide(Nx,Ny,0.001,0.001);
1979 
1980  double topmarg = 0.0679612;
1981  double rightmarg = 0.0121951;
1982  double leftmarg = 0.0983588;
1983  double bottommarg = 0.11165;
1984 
1985  for(int i=0 ; i<gNbCrys ; i++)
1986  {
1987  Int_t ID = GetCrystalId(CrystalNames[i]);
1988 
1989 // cout<<ID<<" "<<CrystalNames[i]<<" "<<((TGraph*)f_CoreCheck[ID]->At(fGraphPos))<<endl;
1990 
1991 // if(fFirstTS[i]>0)
1992 // {
1993  if(PadNbr%NPads==0 && PadNbr!=0)
1994  {
1995  Name = Form("EB_TimeCheckBuilder_%d",PadNbr+1);
1996  c = CanvasVisu::NewCanvas(Name,Title);
1997  new LoupeOnPad(c);
1998  SetLoupe(false);
1999  c->Divide(Nx,Ny,0.001,0.001);
2000  }
2001 
2002  c->cd(PadNbr%NPads+1);
2003 
2004  gPad->SetRightMargin(rightmarg);
2005  gPad->SetTopMargin(topmarg);
2006  gPad->SetLeftMargin(leftmarg);
2007  gPad->SetBottomMargin(bottommarg);
2008 
2009  TGraph *gr = ((TGraph*)f_CoreCheck[ID]->At(fGraphPos));
2010  gr->Draw("APL");
2011 
2012  gPad->Modified();
2013  gPad->Update();
2014 
2015  fCoreLines[ID]->SetX1(gPad->GetFrame()->GetX1());
2016  fCoreLines[ID]->SetX2(gPad->GetFrame()->GetX2());
2017  fCoreLines[ID]->SetY1(fERef);
2018  fCoreLines[ID]->SetY2(fERef);
2019  fCoreLines[ID]->Draw("same");
2020 
2021 // gPad->Modified();
2022 // gPad->Update();
2023 
2024  PadNbr++;
2025 // }
2026  }
2027 }
2028 
2030 {
2031  int PadNbr = 0;
2032 
2033  TString Name = Form("EB_TimeCheck_LastFit_%d",PadNbr+1);
2034  TString Title = "last fit of TimeCheckBuilder at the event builder level";
2035 
2036  TCanvas *c = CanvasVisu::NewCanvas(Name,Title);
2037  new LoupeOnPad(c);
2038  SetLoupe(false);
2039 
2040  Int_t Nx = 5;
2041  Int_t Ny = 4;
2042 
2043  Int_t NPads = Nx*Ny;
2044 
2045  c->Divide(Nx,Ny,0.001,0.001);
2046 
2047  double topmarg = 0.0679612;
2048  double rightmarg = 0.0121951;
2049  double leftmarg = 0.0983588;
2050  double bottommarg = 0.11165;
2051 
2052  for(int i=0 ; i<gNbCrys ; i++)
2053  {
2054  Int_t ID = GetCrystalId(CrystalNames[i]);
2055 
2056  if(fLastFittedHist[ID] == 0x0)
2057  {
2058  PadNbr++;
2059  continue;
2060  }
2061 
2062  if(PadNbr%NPads==0 && PadNbr!=0)
2063  {
2064  Name = Form("EB_TimeCheck_LastFit_%d",PadNbr+1);
2065  c = CanvasVisu::NewCanvas(Name,Title);
2066  new LoupeOnPad(c);
2067  SetLoupe(false);
2068  c->Divide(Nx,Ny,0.001,0.001);
2069  }
2070 
2071  c->cd(PadNbr%NPads+1);
2072 
2073  gPad->SetRightMargin(rightmarg);
2074  gPad->SetTopMargin(topmarg);
2075  gPad->SetLeftMargin(leftmarg);
2076  gPad->SetBottomMargin(bottommarg);
2077 
2078  fLastFittedHist[ID]->Draw("hist");
2079  fLastFitFunction[ID]->Draw("same");
2080 
2081  gPad->Modified();
2082  gPad->Update();
2083 
2084 // fCoreLines[ID]->SetX1(gPad->GetFrame()->GetX1());
2085 // fCoreLines[ID]->SetX2(gPad->GetFrame()->GetX2());
2086 // fCoreLines[ID]->SetY1(fERef);
2087 // fCoreLines[ID]->SetY2(fERef);
2088 // fCoreLines[ID]->Draw("same");
2089 
2090  PadNbr++;
2091  }
2092 }
2093 
2094 void TimeCheckBuilder::ShowSegments(const char *crystal_name)
2095 {
2096  TString CrystalName = crystal_name;
2097 
2098  if(!fCrystalListForSegments.Contains(crystal_name))
2099  {
2101  cout<<"Crystal "<<crystal_name<<" is not included in the list of crystals to check"<<endl;
2103  return;
2104  }
2105 
2106  TString Name = "TimeCheck_PSA_Spectra_" + CrystalName;
2107  TString Title = "TimeCheck of crystal " + CrystalName + "at the post psa level";
2108 
2109  Int_t CryId = GetCrystalId(CrystalName);
2110 
2111  TCanvas *c = CanvasVisu::BuildSegmentedCanvas(Name,Title);
2112 
2113  if(c == 0x0) return;
2114 
2115  c->cd();
2116 
2117  for(int i=0 ; i<CrystalInterface::kNbSegments ; i++)
2118  {
2119  PadPos HistPosition = fHistPositionList[i];
2120 
2121  TPad *pad = (TPad*)c->cd(HistPosition.PadNmbr);
2122  pad->SetFillStyle(0);
2123  pad->SetFrameFillStyle(0);
2124 
2125  TGraph *gr = (TGraph*)f_SegCheck[CryId][i]->At(fGraphPos);
2126 
2127  TPaveText *p = (TPaveText*)pad->GetListOfPrimitives()->FindObject("InfoPad");
2128 
2129  TString NameTitle = ((TString)gr->GetName()) + "_" + HistPosition.SegName;
2130 
2131  gr->SetNameTitle(NameTitle,NameTitle);
2132 
2133  gr->Draw("apl");
2134 
2135  if(p)p->Draw();
2136 
2137  pad->Modified();
2138  pad->Update();
2139  }
2140  for(int i=1 ; i<CrystalInterface::kNbCores ; i++)
2141  {
2142  PadPos HistPosition = fHistPositionList[CrystalInterface::kNbSegments+i];
2143 
2144  TPad *pad = (TPad*)c->cd(HistPosition.PadNmbr);
2145  pad->SetFillStyle(0);
2146  pad->SetFrameFillStyle(0);
2147 
2148  TGraph *gr = (TGraph*)f_CoreCheck[CryId]->At(fGraphPos);
2149 
2150  TPaveText *p = (TPaveText*)pad->GetListOfPrimitives()->FindObject("InfoPad");
2151 
2152  TString NameTitle = ((TString)gr->GetName()) + "_" + HistPosition.SegName;
2153 
2154  gr->SetNameTitle(NameTitle,NameTitle);
2155 
2156  gr->Draw("apl");
2157 
2158  if(p)p->Draw();
2159 
2160  pad->Modified();
2161  pad->Update();
2162  }
2163 
2164  new LoupeOnPad(c);
2165  SetLoupe(false);
2166 }
2167 
2168 
2171 //ClassImp(HitDisplay3D);
2172 //ClassImp(RateDisplay);
2175 
2176 
virtual const Key * GetSubKey(UInt_t) const =0
Returns one of the sub-key in case this is a composite frame.
virtual void SetLoupe(bool loupeon=true)
virtual ~EBWatcher()
******************************************************************************************/// ...
virtual Bool_t IsValid() const
true if it is a valid pointer
Definition: Frame.h:616
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 VertexInterface * GetVertex()
Get the vertex data interface.
A single value data.
Definition: Data.h:58
virtual UShort_t GetNbHits() const =0
To know the number of Hits currently on the stack.
printf("******************************************************************** \n")
virtual void Add(TTask *)
add only Watchers to the list of tasks to avoid problems.
Definition: Watchers.cpp:244
BashColor * fBashColor
Definition: CanvasVisu.h:34
virtual Frame * GetFrame() const
Definition: Frame.h:625
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
void Show3DHits()
******************************************************************************************/// ...
static MainFrameFactory & theMainFactory()
the main (global) keyfactory
Base class for a Frame.
Definition: Frame.h:73
LogMessage & error(LogMessage &)
virtual void Exec(Option_t *option="")
watch the current frame
void ShowSuperimposedCores()
******************************************************************************************/// ...
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) ...
TFolder * GetSubFolder(TFolder *topfolder, const Char_t *sub="")
for a new histogram, it returns the folder it belongs to. It creates sub and all intermediates if req...
Definition: Watchers.cpp:205
virtual Bool_t SetTrigger(ADF::DFTrigger *=0x0)
Set the trigger attached to this watcher.
TH1F * fDistri
Crystal fold.
vector< PadPos > fHistPositionList
Definition: CanvasVisu.h:44
virtual Double_t GetE(UInt_t=0u) const =0
to get the energy associated to the core
virtual Double_t GetE() const
Definition: Hits.h:67
virtual Int_t GetUID() const =0
to get the crystal ID
EBWatcher(const char *name, const char *title, TDirectory *sp_dir=0x0, TDirectory *tag_dir=0x0)
*/
Interface to AgataKey.
virtual DFAgent * GetDFAgent()=0
to get the Data Flow Agent in charge of knowing the structure of the DF
TObject * AddToPool(TObject *ob)
facility for other watchers: keep a list of all histograms (objects) for global operations ...
Definition: Watchers.cpp:446
TFolder * fTopFolder
Top folder in which ae stored all spectra.
Definition: Watchers.h:109
virtual ~HitsSpectra()
******************************************************************************************/// ...
void ShowGammaTime()
******************************************************************************************/// ...
TCanvas * NewCanvas(TString cname, TString ctitle)
Definition: CanvasVisu.C:102
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 &)
AgataGeometryTransformer * fTrans
AgataGeometryTransformer class that manage geometry transformations.
TObjArray fSpectra
Core energy for any crystal.
virtual Double_t GetE() const
Definition: Hits.h:158
header file for Hits.cpp
static ConfAgent * theGlobalAgent(std::string="Agata")
to get the global agent
Definition: ConfAgent.cpp:402
AgataGeometryTransformer * fTrans
virtual Double_t GetBeta(Double_t=0.0) const =0
get recoil velocity
TH1F * fDistri
Crystal fold.
ClassImp(EventPSAWatcher)
void ShowCoreVsSumSpectra(bool OnSamePad=false)
******************************************************************************************/// ...
TObjArray fSpectra
Core energy for any crystal.
void ShowCrystalSpectra()
******************************************************************************************/// ...
LogMessage & info(LogMessage &)
manipulator to modify the LogMessage
LogMessage fLog
Definition: Watchers.h:86
TimeCheckBuilder(const char *name, const char *title, TDirectory *sp_dir=0x0, TDirectory *tag_dir=0x0)
*/
HitsSpectra(const char *name, const char *title, TDirectory *sp_dir=0x0, TDirectory *tag_dir=0x0)
*/
Base class for version numbers.
Definition: Version.h:38
LoupOnPad, a class to Loupe on a Pad in a Canvas with many pads in it.
Definition: LoupeOnPad.h:76
header file for AgataKeyFactory.cpp
TCanvas * BuildSegmentedCanvas(TString CanvasName, TString CanvasTitle)
Definition: CanvasVisu.C:125
virtual void Exec(Option_t *option="")
watch the current frame
TH1 * fCoreCommon
Sum of all core spectra (without Doppler correction)
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 ShowSegments(const char *CrystalName)
It is a hit associated to a list of Hits.
Definition: Hits.h:256
Color_t GetColor(int i)
Definition: CanvasVisu.h:49
! Show rates (counts) per Crystal *!
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
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
*********************************** 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)
header file for MetaFrame.cpp
virtual Double_t GetZ() const
Definition: Hits.h:59
void ShowGammaGamma()
******************************************************************************************/// ...
SharedFP * fFrame
main frame i.e. event:data:psa
Concrete implementation of a tracked Hit.
Definition: Hits.h:279
*********************************** EventPSAWatcher Class **************************************/// ...
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
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...
virtual void GetXYZ(Double_t &x, Double_t &y, Double_t &z) const
Definition: Hits.h:155
virtual void SetLoupe(bool loupeon=true)
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.