GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LevelScheme.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2004 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 
23 // root include's
24 
25 #ifndef ROOT_TArrow
26 #include "TArrow.h"
27 #endif
28 
29 #ifndef ROOT_TList
30 #include <TList.h>
31 #endif
32 
33 #ifndef ROOT_TObjArray
34 #include <TObjArray.h>
35 #endif
36 
37 #ifndef ROOT_TPad
38 #include <TPad.h>
39 #endif
40 
41 #ifndef ROOT_TString
42 #include <TString.h>
43 #endif
44 
45 #ifndef ROOT_TStyle
46 #include <TStyle.h>
47 #endif
48 
49 
50 // gw include's
51 #ifndef GW_ENSDF_H
52 #include "ENSDF.h"
53 #endif
54 
55 
56 #ifndef Gw_GLSPlayer
57 #include "GLSPlayer.h"
58 #endif
59 
60 #ifndef Gw_LevelScheme
61 #include "LevelScheme.h"
62 #endif
63 
64 #ifndef GW_NUCLEARLEVEL_H
65 #include "NuclearLevel.h"
66 #endif
67 
68 #ifndef GW_XGAMMALINK_H
69 #include "XGammaLink.h"
70 #endif
71 
72 using namespace Gw;
73 
75 
76 //__________________________________________________________
78  : TObject(),
79  fCLink(0x0),
80  fCLevel(0x0),
81  fCCascade(0x0),
82  fPlayer(0x0),
83  fLog("LevelScheme")
84 {
85  fLevels.SetOwner(kTRUE); fLinks.SetOwner(kTRUE);
86  fCascades.SetOwner(kTRUE); fTexts.SetOwner(kTRUE);
87  fArrows.SetOwner(kTRUE);
88 
89  fName.SetTextAlign(22);
90  fName.SetTextColor(1);
91 }
92 
93 //__________________________________________________________
94 LevelScheme::LevelScheme(const Char_t* filename, Option_t* opt)
95  : TObject(),
96  fCLink(0x0),
97  fCLevel(0x0),
98  fCCascade(0x0),
99  fLog("LevelScheme")
100 {
101  fLevels.SetOwner(kTRUE); fLinks.SetOwner(kTRUE);
102  fCascades.SetOwner(kTRUE); fTexts.SetOwner(kTRUE);
103  fArrows.SetOwner(kTRUE);
104 
105  LevelScheme::Import(filename, opt);
106  fName.SetTextAlign(22);
107  fName.SetTextColor(1);
108 }
109 
110 //__________________________________________________________
112 {
113  if ( fPlayer )
114  fPlayer->Disconnect();
115 
116  delete fPlayer;
117  map<Int_t, TBits*>::iterator im; // iterator on the map prototype
118  for (im = fCoincMap.begin() ; im != fCoincMap.end() ; ++im ) delete im->second;
119 }
120 
121 
122 //__________________________________________________________
124 {
125 
126  if (!fPlayer) {
127 
128  TString options(opt);
129  if ( options.Contains("Graphical") )
130  fPlayer = new GLSPlayer(this);
131  else {
132  fLog.SetProcessMethod("SetPlayer(Option_t* )");
133  fLog << error << "Player type not defined" << dolog;
134  return 0x0;
135  }
136  fPlayer->Connect();
137  }
138 
139  return fPlayer;
140 }
141 
142 
143 //__________________________________________________________
145 {
146  level->SetUniqueID(fLevels.GetEntries()); // for the moment
147  fLevels.Add(level);
148 }
149 
150 //__________________________________________________________
152 {
153  link->SetUniqueID(fLinks.GetEntries()); // for the moment
154  fLinks.Add(link);
155 }
156 
157 //__________________________________________________________
159 {
160  fCascades.Add(cascade);
161 }
162 
163 //__________________________________________________________
165 {
166  TBits* bitMap = 0x0;
167 
168  for (Int_t i = 0; i < fLinks.GetEntries(); ++i) {
169  Link* link1 = static_cast<Link*> ( fLinks.At(i) );
170  bitMap = new TBits(fLinks.GetEntries());
171 
172  for (Int_t j = 0; j < fLinks.GetEntries(); ++j) {
173  if (j == i) continue;
174  Link* link2 = static_cast<Link*> ( fLinks.At(j) );
175  if( link1->GetIL() == link2->GetFL() )
176  bitMap->SetBitNumber(link2->GetUniqueID(), true);
177  }
178  fCoincMap[i] = bitMap;
179  }
180 
181 }
182 
183 //__________________________________________________________
185 {
186  // this method gives the bit map for the links in coincidence above a given link
187  // WARNING: does not fully work for all cases
188 
189  fLog.SetProcessMethod("SGetBitMap(Link* l )");
190  fLog << warning << "Method not fully implemented, results not reliable for all cases" << nline;
191 
192  static Bool_t first = true;
193 
194  if (first) {
195  FillMap();
196  first = false;
197  }
198 
199  TBits* bitMap = fCoincMap[link->GetUniqueID()];
200  TBits* bitMapC = fCoincMap[link->GetUniqueID()];
201  TBits* bitMapT = 0x0;
202 
203  Link* linkC = 0x0;
204 
205  if ( !bitMapC->CountBits() ) return bitMap;
206 
207  for (UInt_t i = 0; i < bitMapC->GetNbits(); ++i) {
208  if ( bitMapC->TestBitNumber(i) ) {
209  linkC = static_cast<Link*> ( fLinks.At(i) );
210  bitMapT = GetBitMap(linkC);
211  bitMap->operator|=(*bitMapT);
212  }
213  }
214 
215  fLog << dolog;
216 
217  return bitMap;
218 }
219 
220 //__________________________________________________________
221 void LevelScheme::AddText(TLatex* text)
222 {
223  fTexts.Add(text);
224 }
225 
226 //__________________________________________________________
227 void LevelScheme::AddArrow(TArrow* arrow)
228 {
229  fArrows.Add(arrow);
230 }
231 
232 //__________________________________________________________
233 Level* LevelScheme::NewLevel(const char* /*name*/)
234 {
235  Level* lev = new Level();
236  return lev;
237 }
238 
239 //__________________________________________________________
240 Link* LevelScheme::NewLink(const char* /*name*/)
241 {
242  Link* link = new Link();
243  return link;
244 }
245 
246 //__________________________________________________________
247 Cascade* LevelScheme::NewCascade(const char* /*name*/)
248 {
249  Cascade* cas = new Cascade();
250  return cas;
251 }
252 
253 //__________________________________________________________
254 TLatex* LevelScheme::NewText(const char* msg)
255 {
256  TLatex* text = new TLatex(0., 0., msg);
257  fTexts.Add(text);
258  return text;
259 }
260 
261 //__________________________________________________________
262 TArrow* LevelScheme::NewArrow(Float_t x1, Float_t y1, Float_t x2, Float_t y2)
263 {
264  TArrow* arrow = new TArrow(x1, y1, x2, y2);
265  fArrows.Add(arrow);
266  return arrow;
267 }
268 
269 //__________________________________________________________
270 void LevelScheme::Browse(TBrowser *b)
271 {
272  if ( b ) this->Draw();
273 }
274 
275 //__________________________________________________________
276 Int_t LevelScheme::Import(const Char_t* filename, Option_t* opt)
277 {
278  // import file with dedicated readers
279  return GetPlayer()->ImportLevelScheme(filename, opt);
280 
281 }
282 
283 //__________________________________________________________
284 Int_t LevelScheme::InitENSDF(const Char_t *filename, Option_t *opt)
285 {
286  // for backward compatibility
287  return GetPlayer()->ReadENSDF(filename, opt);
288 
289 }
290 
291 //__________________________________________________________
292 Int_t LevelScheme::InitAGS(const Char_t *filename, Option_t *opt)
293 {
294  // for backward compatibility
295  return GetPlayer()->ReadAGS(filename, opt);
296 }
297 
298 
299 //__________________________________________________________
300 void LevelScheme::Draw(Option_t *opt)
301 {
302  // draw level scheme
303  TString options(opt);
304  options.ToLower();
305 
306  if (options.Contains("ground")) {
307  fName.Draw();
308  fLevels.Draw();
309  } else if (fLevels.GetEntries() == 0) {
310  GetPlayer()->Draw("new");
311  return;
312  } else {
313  GetPlayer()->Draw(opt);
314  }
315  fTexts.Draw();
316  fArrows.Draw();
317  AppendPad(opt);
318 }
319 
320 //__________________________________________________________
321 Int_t LevelScheme::DistancetoPrimitive(Int_t px, Int_t py)
322 {
323  Int_t d = fName.DistancetoPrimitive(px, py);
324  return d;
325 }
326 
327 //__________________________________________________________
328 void LevelScheme::ExecuteEvent(Int_t event, Int_t px, Int_t py)
329 {
330  fName.ExecuteEvent(event, px, py);
331 }
332 
333 //__________________________________________________________
335 {
336  TList* list = new TList();
337  list->SetOwner(false);
338 
339  for (Int_t i = 0; i < fCascades.GetEntries(); ++i) {
340  Cascade* cas = static_cast<Cascade*> ( fCascades.At(i) );
341  if (cas->FindObject(link))
342  list->Add(cas);
343  }
344 
345  return list;
346 }
347 
348 //__________________________________________________________
350 {
351  if (fCLink)
352  return FindLinkInCascade(fCLink);
353  else
354  return 0x0;
355 }
356 
357 //__________________________________________________________
358 const TList* LevelScheme::FindLink(Level* level) const
359 {
360  TIter next(&fLinks);
361 
362  TList* list = new TList();
363  list->SetOwner(false);
364 
365  Link *link = 0x0;
366  while ( (link = (Link *)next()) ){
367  if (link->GetIL() == level || link->GetFL() == level)
368  list->Add(link);
369  }
370 
371  return list;
372 }
373 
374 //__________________________________________________________
375 void LevelScheme::ls(Option_t *o) const
376 {
377  TString opt = o;
378  if ( opt.Contains("all") ) {
379  cout << "Level Scheme: " << endl;
380  cout << " " << GetName() << " (" << GetReference() << ") \n";
381  cout << "Links/Levels List: " << endl;
382  TIter iter(&fLinks); Link *link;
383  while ( (link = (Link *)iter()) ){
384  cout << " "; link->ls();
385  if ( link->GetIL() ) {
386  cout << " From "; link->GetIL()->ls(o);
387  }
388  else cout << " Not linked " << endl;
389  if ( link->GetFL() ) {
390  cout << " To "; link->GetFL()->ls(o);
391  }
392  else cout << " Not linked " << endl;
393  }
394  }
395  if ( opt.Contains("level") ) {
396  cout << "Level Scheme: " << endl;
397  cout << " " << GetName() << " (" << GetReference() << ") \n";
398  cout << "Levels List: " << endl;
399  fLevels.ls(opt);
400  }
401  if ( opt.Contains("gamma") ) {
402  cout << "Level Scheme: " << endl;
403  cout << " " << GetName() << " (" << GetReference() << ") \n";
404  cout << "Links List: " << endl;
405  fLinks.ls(opt);
406  }
407 }
408 
409 //__________________________________________________________
410 void LevelScheme::Clear(Option_t *)
411 {
412  // all collections are empty
413  fCascades.Clear(); fLinks.Clear();fLevels.Clear(); fTexts.Clear();
414  fArrows.Clear();
415  // no name, no reference
416  fName.Clear(); fReference.Clear();
417 }
418 
419 
A level Scheme.
Definition: LevelScheme.h:82
TBrowser * b
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
Compute distance to object.
virtual void ls(Option_t *option="all") const
list levels/links
virtual TList * FindCLinkInCascade() const
Find the cascades that own the currengt link.
A cascade is a list of links.
Definition: Cascade.h:51
virtual void Browse(TBrowser *b)
virtual Int_t InitAGS(const Char_t *filename, Option_t *opt="152Dy")
BETTER TO USE Import - To init this level scheme with a Radford AGS file.
interface to ENSDF Evaluated Nuclear Structure Data File
virtual void Draw(Option_t *opt="")
to draw this level scheme
LogMessage & error(LogMessage &)
Level * NewLevel(const char *name)
create new level
LogMessage & warning(LogMessage &)
virtual TList * FindLinkInCascade(Link *link) const
Find the cascades that own that link.
virtual Int_t Import(const Char_t *, Option_t *)
to init this level scheme from an existing formatted file (ENSDF, Radware ..)
BaseLSPlayer * fPlayer
Definition: LevelScheme.h:106
header file for a NuclearLevel
LogMessage & nline(LogMessage &)
virtual const char * GetName() const
Definition: LevelScheme.h:300
virtual Int_t ReadAGS(const Char_t *filename, Option_t *opt="152Dy")
for backward compatibility
virtual Int_t ImportLevelScheme(const Char_t *, Option_t *)
to init this level scheme from an existing formatted file (ENSDF, Radware ..)
Most of the methods relies on graphical approach for level scheme.
Definition: GLSPlayer.h:53
virtual void Clear(Option_t *opt="")
virtual const Char_t * GetReference() const
Definition: LevelScheme.h:301
TArrow * NewArrow(Float_t x1, Float_t y1, Float_t x2, Float_t y2)
create new arrow
virtual Int_t InitENSDF(const Char_t *, Option_t *)
BETTER TO USE Import - To init this level scheme with a ENSDF file.
LogMessage fLog
Definition: LevelScheme.h:287
Bool_t Disconnect(TCanvas *c=0x0)
Connect the Canvas to this to collect events.
LogMessage & dolog(LogMessage &)
virtual ~LevelScheme()
void AddLevel(Level *level)
level scheme player pointer
void AddText(TLatex *latex)
Add text.
Bool_t Connect(TCanvas *c=0x0)
Connect the Canvas to this to collect events.
header file for a LevelScheme
void AddLink(Link *link)
Add link.
Cascade * NewCascade(const char *name)
create new cascade
ADF::LogMessage & endl(ADF::LogMessage &log)
Link * NewLink(const char *name)
create new level
void AddCascade(Cascade *Cascade)
Add cascade.
void AddArrow(TArrow *arrow)
Add arrow.
virtual void SetProcessMethod(const char *)
To set the current method.
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
to execute an event for this level scheme
virtual TBits * GetBitMap(Link *link)
get bit map coincidence above a given link
BaseLSPlayer * GetPlayer(Option_t *opt="Graphical")
Get player.
virtual const TList * FindLink(Level *level) const
Find links attached to level.
TLatex * NewText(const char *msg)
create new text
ClassImp(LevelScheme)
virtual Int_t ReadENSDF(const Char_t *, Option_t *)
for backward compatibility
virtual void FillMap()
Fill map of coincidence.
virtual void Draw(Option_t *opt="")
to draw this level scheme
BaseLSPlayer to work on level scheme.
Definition: BaseLSPlayer.h:106
Base class describing a general level.
Definition: Level.h:53