GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GSI/TrackedWatchers.C
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2010 by Olivier Stezowski *
3  * stezow(AT)ipnl.in2p3.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
20 
21 // Watcher definition
22 #ifndef _TrackedWatchers
23 #include "TrackedWatchers.h"
24 #endif
25 
26 // #include "GenericFrame.h"
27 #include "AgataKeyFactory.h"
28 
29 #include "MetaWatchers.h"
30 #include "TVector3.h"
31 
32 #ifndef ROOT_TGeoMatrix
33 #include "TGeoMatrix.h"
34 #endif
35 
36 #ifndef Gw_AgataGeometryTransformer
38 #endif
39 
40 using namespace ADF;
41 
43 
45 {
46  Bool_t ok = Watcher::GetFromTrigger(trigger, "data:tracked", fFrame);
47  return ok;
48 }
49 
50 void TrackedWatcher::SetAgataOffset(Double_t offset)
51 {
52  fZOffset = offset;
53 }
54 
56 {
57  Double_t e = hit->GetE(), beta = vertex->GetBeta(), gamma = vertex->GetGamma();
58 
59  Double_t px, py, pz, dx, dy, dz;
60  vertex->GetPosition (px, py, pz);
61  vertex->GetDirection(dx, dy, dz);
62 
63  Double_t x = hit->GetX() - px;
64  Double_t y = hit->GetY() - py;
65  Double_t z = hit->GetZ() + fZOffset - pz;
66 
67  Double_t dd = x*x + y*y + z*z;
68  if( !(dd == 0.0) ) {
69  Double_t cosTheta = (x*dx + y*dy + z*dz)/::sqrt(dd);
70  e = VertexInterface::DopplerCorrection(e,beta,gamma,cosTheta);
71  }
72  else e = -1.0;
73 
74  return e;
75 }
76 
78 
79 Coinc2D::Coinc2D(const char *name, const char *title, TDirectory *sp_dir, TDirectory *tag_dir):
80  TrackedWatcher(name,title,sp_dir,tag_dir),
81  fVertexBuilder(0x0),
82  fTrackedEnergy(0x0),
83  fTrackedEnergyDopler(0x0),
84  fFold(0x0),
85  fGxG(0x0),
86  fGxG_DC(0x0),
87  fPos3D(0x0)
88 {
89  // Vertex used for doppler correction, last registered
90  fVertexBuilder = VertexBuilder::theCurrentVertexBuilder();
91 
92  // Now spectra
93  fTrackedEnergy = MakeTH1<TH1F>("TrackedEnergy","Tracked Energy",6000,0,6000);
94 
95  fTrackedEnergyDopler = MakeTH1<TH1F>("TrackedEnergyDopler","Tracked Energy with Doppler correction",6000,0,6000);
96  TagOn(fTrackedEnergyDopler);
97 
98  fFold = MakeTH1<TH1F>("Fold","Fold distributions",10,0,10);
99  TagOn(fFold);
100 
101  fGxG = MakeTH2<TH2F>("GxG","Gamma Gamma matrix",2000,0,1000,2000,0,1000);
102  fGxG_DC = MakeTH2<TH2F>("GxG_DC","Gamma Gamma matrix with Doppler Correction",2000,0,1000,2000,0,1000);
103 
104  fPos3D = MakeTH3<TH3F>("Pos3D","Positions of Tracked Gamma-rays ;x;y;z",200,-200,200,200,-200,200,200,-400,0);
105 }
106 
108 {
109 // no need to delete the histograms, done because they have been added to the pool
110 }
111 
112 void Coinc2D::DoCanvas(TCanvas *c, Option_t *o)
113 {
114  TString opt = o;
115 
116  if ( opt.Contains("") ) {
117  c->Divide(1,2,0.001,0.001);
118  c->cd(1);
119  fTrackedEnergy->Draw(o);
120  TPad *pad = new TPad("GxG_FOLD", "Pad for Fold distribution",0.7,0.6,1,1);
121  pad->Draw();
122  pad->cd();
123  fFold->Draw();
124  c->cd(2);
125  fTrackedEnergyDopler->Draw(o);
126  }
127 }
128 
129 void Coinc2D::Exec(Option_t */*option*/)
130 {
131 // Frame by Frame action
132  // be sure the frame has been set properly
133  if ( fFrame == 0x0 || !fFrame->IsValid() )
134  { SetLastExecStatus(1); return; }
135 // printf("... is called \n");
136 
137  if ( gDebug > 3 )
138  printf("Coinc2D::::Exec is called \n");
139 
140  // to get the data part of the frame
141  const GammaTrackedInterface *data =
142  GetCstDataPointer<GammaTrackedInterface>(fFrame);
143  VertexInterface *vertex = fVertexBuilder->GetVertex();
144  // vertex->SetDirection(0.,-1.,1.);
145  // vertex->SetPosition(0.,0.,-50.);
146  // vertex->SetBeta(0.02);
147 
148  // now fill histograms
149  UInt_t fold = data->GetNbGamma();
150 
151  fFold->Fill( fold );
152  for (UShort_t i = 0u; i < fold; i++) {
153 
154  const TrackedHit *gamma1 = data->GetGamma(i);
155 
156  fPos3D->Fill(gamma1->GetX(),gamma1->GetY(),gamma1->GetZ());
157 // cout << gamma1->GetHit(1)->GetX() << " " << gamma1->GetHit(1)->GetY() << " " << gamma1->GetHit(1)->GetZ() << endl;
158 
159  Double_t edc1 = DoDopplerCorrection(gamma1, vertex);
160  Double_t e1 = gamma1->GetE();
161 
162  fTrackedEnergy->Fill(e1);
163  if ( vertex->GetBeta() > 0.001 )
164  fTrackedEnergyDopler->Fill(edc1);
165 
166  for (UShort_t j = i+1u; j < fold; j++) {
167 
168  const TrackedHit *gamma2 = data->GetGamma(j);
169 
170  Double_t edc2 = DoDopplerCorrection(gamma2, vertex);
171  Double_t e2 = gamma2->GetE();
172 
173  fGxG->Fill(e1,e2);
174  fGxG->Fill(e2,e1);
175  if ( vertex->GetBeta() > 0.001 ) {
176  fGxG_DC->Fill(edc1,edc2);
177  fGxG_DC->Fill(edc2,edc1);
178  }
179  }
180  }
181 }
182 
183 //-------------------------------------------------------------------------------------
184 
186 
187 Float_t EveTrack::fgMetric = 10.;
188 
189 EveTrack::EveTrack(const char *name, const char *title, TDirectory *sp_dir, TDirectory *tag_dir):
190  TrackedWatcher(name, title, sp_dir, tag_dir),
191  fMaxCycle(100),
192  fPathFile(Gw::AgataEventDisplay::GetDefaultAgataPath())
193 {
194  AgataEventDisplay::Instance()->SetTrackStyle("Cone");
195 
196  fMeanRadius = MakeTH1<TH1F>("MeanRadius","Mean radius of the tracks (cm)", 500, -1, 34);
197  fFold = MakeTH1<TH1I>("Fold","Number of Tracks per event", 22, -1, 20) ;
198  fHitEnergy = MakeTH1<TH1F>("HitEnergy","Energy of hits", 1000,-1,1000.) ;
199  fTrackEnergy = MakeTH1<TH1F>("TrackEnergy","Energy of tracks", 2000,0.,2000.) ;
200 }
201 
203 {
204 
205 }
206 
207 void EveTrack::SetActive(Bool_t active)
208 {
209  TTask::SetActive(active);
210  AgataEventDisplay::Instance()->Reset();
211 }
212 
213 void EveTrack::DoCanvas(TCanvas* c, Option_t* /*o*/)
214 {
215  c->Divide(2,2,0.001,0.001);
216 
217  c->cd(1);
218  fMeanRadius->Draw();
219 
220  c->cd(2);
221  fFold->Draw();
222 
223  c->cd(3);
224  fHitEnergy->Draw();
225 
226  c->cd(4);
227  fTrackEnergy->Draw();
228 }
229 
230 void EveTrack::ShowEve(const Char_t* agataPathFile)
231 {
232  AgataEventDisplay::SetDefaultAgataPath(agataPathFile);
233  AgataEventDisplay::Instance()->BuildDefaultGeometry(false, false);
234  AgataEventDisplay::Instance()->ShowDisplay();
235 }
236 
237 void EveTrack::Exec(Option_t */*option*/)
238 {
239  // Frame by Frame action
240 
241  // be sure the frame has been set properly
242  // be sure the frame has been set properly
243  if ( fFrame == 0x0 || !fFrame->IsValid() )
244  { SetLastExecStatus(1); return; }
245 
246  if ( gDebug > 3 )
247  printf("EveTrack::::Exec is called \n");
248 
249  // to get the data part of the frame
250  const GammaTrackedInterface *data = GetCstDataPointer<GammaTrackedInterface>(fFrame);
251 
252  // now fill display container
253  UInt_t fold = data->GetNbGamma();
254 
255  if (fold == 0)
256  return;
257 
258  fFold->Fill(fold);
259 
260  AgataEventContainer* agataContainer = AgataEventDisplay::Instance()->GetEventContainer();
261 
262  if (agataContainer->GetNofEvents() > fMaxCycle) {
263  TTask::SetActive(false);
264  }
265 
266  if ( gDebug > 3 )
267  std::cout << "TrackHits " << std::endl;
268 
269  if ( gDebug > 3 )
270  std::cout << "Fold " << fold << std::endl;
271 
272  for (UShort_t i = 0u; i < fold; ++i) {
273 
274  const TrackedHit* gamma = (TrackedHit*)data->GetGamma(i);
275  TrackHit* hit = agataContainer->NewTrackHit();
276  fTrackEnergy->Fill(gamma->GetE());
277 
278  hit->SetX(gamma->GetX()/fgMetric);
279  hit->SetY(gamma->GetY()/fgMetric);
280  hit->SetZ(gamma->GetZ()/fgMetric);
281  hit->SetE(gamma->GetE());
282 
283  for (Int_t j = 0; j < gamma->GetNbHits(); ++j) {
284  Hit* gammaHit = gamma->GetHit(j);
285  StdHit* shit = hit->NewHit();
286 
287  Float_t radius = TMath::Sqrt(gammaHit->GetX()*gammaHit->GetX() + gammaHit->GetY()*gammaHit->GetY() +
288  gammaHit->GetZ()*gammaHit->GetZ());
289  fMeanRadius->Fill(radius/fgMetric);
290  fHitEnergy->Fill(gammaHit->GetE());
291  if ( gDebug > 3 ) {
292  std::cout << "TrackHit Pos " << gammaHit->GetX()/fgMetric << " " << gammaHit->GetY()/fgMetric
293  << " " << gammaHit->GetZ()/fgMetric << " " << gammaHit->GetE() << std::endl;
294  }
295 
296  shit->SetX(gammaHit->GetX()/fgMetric);
297  shit->SetY(gammaHit->GetY()/fgMetric);
298  shit->SetZ(gammaHit->GetZ()/fgMetric);
299  shit->SetE(gammaHit->GetE());
300  }
301  }
302  agataContainer->FillTracks();
303 }
304 
305 
306 
AgataEventContainer class that contains agata event to be displayed.
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 SetE(Float_t e)
virtual VertexInterface * GetVertex()
Get the vertex data interface.
virtual Double_t DoDopplerCorrection(const TrackedHit *hit, VertexInterface *vertex)
Do Doppler taking into account additionnal offset of the agat position (see SetAgataOffset) ...
printf("******************************************************************** \n")
virtual Double_t GetY() const
Definition: Hits.h:57
EveTrack(const char *name, const char *title, TDirectory *sp_dir=0x0, TDirectory *tag_dir=0x0)
StdHit * NewHit()
Add a new hit to the track (filling mode). The Stack is emptied by calling Reset. ...
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) ...
AgataEventDisplay a class to work on a specific event display.
virtual Double_t GetE() const
Definition: Hits.h:67
virtual void DoCanvas(TCanvas *c, Option_t *)
To be overwritten by real implementation if a canvas is produced.
virtual void SetZ(Float_t z)
The tracking algorithm produces a stack of TrackedHits.
Definition: TrackedFrame.h:41
TH1F * fTrackedEnergyDopler
virtual Bool_t SetTrigger(ADF::DFTrigger *=0x0)
Set the trigger attached to this watcher.
virtual TrackedHit * GetGamma(UShort_t) const =0
To get the current number of gammas in the stack.
void FillTracks(Option_t *type="Agata")
virtual void ShowEve(const Char_t *agataPathFile)
show eve event display
virtual void SetY(Float_t y)
virtual void SetX(Float_t x)
Setter position & energy.
virtual Double_t GetBeta(Double_t=0.0) const =0
get recoil velocity
virtual void SetE(Float_t e)
virtual void Exec(Option_t *option="")
watch the current frame
void SetLastExecStatus(Short_t s=0)
reset last status. 0 means no error, 0 < means error, > 0 means ok with conditions ...
Definition: Watchers.h:294
Base class for a Hit.
Definition: Hits.h:35
virtual ~Coinc2D()
******************************************************************************************/// ...
virtual void SetY(Float_t y)
virtual void SetZ(Float_t z)
ClassImp(TrackedWatcher)
virtual void DopplerCorrection(Hit *)=0
header file for AgataKeyFactory.cpp
virtual void SetX(Float_t x)
Setter position & energy.
virtual ~EveTrack()
It is a hit associated to a list of Hits.
Definition: Hits.h:256
TrackHit * NewTrackHit(Option_t *type="Agata")
add current track hit (added to current track hit list)
virtual void SetAgataOffset(Double_t offset=0.0)
set the agata offset in case it is not @ the optimal position
virtual Double_t GetX() const
Definition: Hits.h:55
TH1F * fTrackedEnergy
virtual UShort_t GetNbHits() const =0
It returns the number of hits for this tracked particle.
void TagOn(TObject *)
Add this histogram to the list of tagged histograms.
Definition: Watchers.cpp:901
virtual Double_t GetGamma(Double_t=0.0) const
Definition: MetaFrame.h:77
Base class for a trigger on a data flow.
Definition: Trigger.h:155
ADF::LogMessage & endl(ADF::LogMessage &log)
virtual void DoCanvas(TCanvas *c, Option_t *)
To be overwritten by real implementation if a canvas is produced.
virtual Double_t GetZ() const
Definition: Hits.h:59
virtual UShort_t GetNbGamma() const =0
To get the current number of gammas in the stack.
void SetActive(Bool_t active=true)
Toggle active task.
Coinc2D(const char *name, const char *title, TDirectory *sp_dir=0x0, TDirectory *tag_dir=0x0)
*/
virtual Hit * GetHit(UInt_t i=0) const =0
Get Hit number i of the track (already added with NewHit !!)
Base Watcher working for any kind of Trackek Frame (Frame interface) and.
Int_t GetNofEvents() const
get Number of events
virtual void Exec(Option_t *option="")
watch the current frame
static VertexBuilder * theCurrentVertexBuilder()
to get the current VertexWatcher (for other watchers) i.e. the last one registered.