GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GANIL/EventWatchers.C
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2010 by Olivier Stezowski *
3  * Copyright (C) 2010 by Christian Finck *
4  * stezow(AT)ipnl.in2p3.fr *
5  * *
6  * This program is free software; you can redistribute it and/or modify *
7  * it under the terms of the GNU General Public License as published by *
8  * the Free Software Foundation; either version 2 of the License, or *
9  * (at your option) any later version. *
10  * *
11  * This program is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14  * GNU General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU General Public License *
17  * along with this program; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20  ***************************************************************************/
21 
22 // Watcher definition
23 #include "EventWatchers.h"
24 #include "AgataKeyFactory.h"
25 #include "PSAFrame.h"
26 
27 using namespace ADF;
28 
30 
31 
33 {
34  return Watcher::GetFromTrigger(trigger, "event:data", fFrame);
35 }
36 
38 
40 {
41  Bool_t ok = false; TString f_type; TH1F *h;
42 
43  // check if this trigger is not a zombie
44  if ( ! Watcher::SetTrigger(trigger) )
45  return ok;
46 
47  // check first that the main frame is a composite frame
48  // if yes set fFrame to it
49  if( ! GetTrigger()->GetInputFrame(0u)->IsComposite() )
50  return ok;
51  else {
52  fFrame = GetTrigger()->GetInputSharedFP(0u);
53  f_type = fFrame->GetFrame()->GetSignature().GetItemName();
54 
55  h = MakeTH1<TH1F>(Form("DiffCTS_%s",f_type.Data()),"Time between two consecutive events",1000,0, 10000000);
56  fCoinc->AddAt( h , 0 );
57  }
58 
59  // loop on the trigger and define a histogram associated to each sub frame
60  for(UInt_t which = 1u; which < GetTrigger()->GetNbInputFrame(); which++){
61 
62  Frame *f = GetTrigger()->GetInputFrame(which);
63  if ( f == 0x0 )
64  continue;
65 
66  // to get the type of frame, used to set the histogram's name
67  f_type = f->GetSignature().GetItemName();
68 
69  h = MakeTH1<TH1F>(Form("TS_%s",f_type.Data()),"TS Coinc in a composite Frame",500,0,500);
70  fCoinc->AddAt(h,which);
71  TagOn(h);
72  }
73  if ( dynamic_cast<AgataFrameTrigger *> (GetTrigger())) {
74  fPSAFrame = (dynamic_cast<AgataFrameTrigger *> (GetTrigger()))->AddUtility("data:psa",ConfAgent::theGlobalAgent());
75  }
76 
77  return true;
78 }
79 
80 TSCoinc::TSCoinc(const char *name, const char *title, TDirectory *sp_dir, TDirectory *tag_dir) :
81  EventWatcher(name,title,sp_dir,tag_dir),
82  fLastTimeStamp(0UL),
83  fCoinc( new TObjArray() ),
84  fCoincPerCrystal(0x0)
85 {
86  fCoincPerCrystal = MakeTH2<TH2F>("CoincPerCrystal","TS Coinc in a composite Frame",180,0,180,500,0,500);
87  ;
88 }
89 
90 void TSCoinc::DoCanvas(TCanvas *c, Option_t *o)
91 {
92  TString option = o;
93  if ( option == "" ) {
94  c->Divide(2,2,0.001,0.001);
95 
96  c->cd(1);
97  if ( fCoinc->At(0) )
98  fCoinc->At(0)->Draw();
99  c->cd(2);
100  Bool_t first = true;
101  for (Int_t i = 1u; i < fCoinc->GetSize() ; i++ ) {
102 
103  if ( fCoinc->At(i) == 0x0 )
104  continue;
105 
106  if ( first ) {
107  fCoinc->At(i)->Draw();
108  first = false;
109  }
110  else {
111  fCoinc->At(i)->Draw("same");
112  }
113  }
114  c->cd(3); fCoincPerCrystal->Draw();
115  }
116 }
117 
118 void TSCoinc::Exec(Option_t * /*option*/)
119 {
120  if ( fFrame == 0x0 || !fFrame->IsValid() )
121  { SetLastExecStatus(1); return; }
122 
123  // to get the main key
124  AgataKey * mainkey = dynamic_cast<AgataKey *> (fFrame->GetFrame()->GetKey());
125 
126  // difference between two "consecutive" timestamps
127  TH1F *h = dynamic_cast<TH1F*>(fCoinc->At(0));
128  if ( h )
129  h->Fill( mainkey->GetTimeStamp() - fLastTimeStamp );
130  fLastTimeStamp = mainkey->GetTimeStamp();
131 
132  // loop on subframes and compute the timestamp differences
133  for(UInt_t which = 1u; which < GetTrigger()->GetNbInputFrame(); which++){
134 
135  Frame *f = GetTrigger()->GetInputFrame(which);
136  if ( f == 0x0 )
137  continue;
138 
139  if ( !GetTrigger()->IsIndividualFired() ) // trigger may be with option ! (anti-coincidence) or | (with OR without this frame) for that frame
140  continue;
141  /* another possible, similar test if trigger is not known by the user
142  if ( !f->IsValid() ) //
143  continue;
144  */
145  AgataKey * subkey = dynamic_cast<AgataKey *> (f->GetKey()); h = dynamic_cast<TH1F*>(fCoinc->At(which));
146  if ( h == 0x0 || subkey == 0x0 )
147  continue;
148 
149  h->Fill( subkey->GetTimeStamp() - fLastTimeStamp );
150  if ( subkey->GetSignature().GetItemName().find("event:data:psa") != string::npos ) { // a composition frame of type event:data:psa
151  // f->Scan();
152  for (UInt_t i = 0u; i < f->GetNbSubFrame(); i++) {
153  f->LinkSubFrame(which,fPSAFrame->GetFrame());
154  fPSAFrame->GetFrame()->Read();
155  PSAInterface *data =
156  GetDataPointer<PSAInterface>(fPSAFrame);
157  UInt_t crysal_id = data->GetUID();
158 
159  AgataKey * subsubkey = dynamic_cast<AgataKey *> (fPSAFrame->GetFrame()->GetKey());
160  fCoincPerCrystal->Fill( crysal_id, subsubkey->GetTimeStamp() - fLastTimeStamp );
161  }
162  }
163  }
164 }
165 
166 
167 
168 
169 
170 
171 
virtual Bool_t IsValid() const
true if it is a valid pointer
Definition: Frame.h:616
virtual Key * GetKey()=0
To get the Key associated to this frame.
TSCoinc(const char *name, const char *title, TDirectory *sp_dir=0x0, TDirectory *tag_dir=0x0)
virtual Frame * GetFrame() const
Definition: Frame.h:625
Base class for a Frame.
Definition: Frame.h:73
virtual Bool_t SetTrigger(ADF::DFTrigger *=0x0)
Set the trigger attached to this watcher.
virtual UInt_t Read()
It reads the content into dedicated structures from the Frame (data part)
Definition: Frame.h:199
const FactoryItem & GetSignature() const
Definition: Key.h:115
virtual Int_t GetUID() const =0
to get the crystal ID
Interface to AgataKey.
static ConfAgent * theGlobalAgent(std::string="Agata")
to get the global agent
Definition: ConfAgent.cpp:402
virtual ULong64_t GetTimeStamp() const =0
To set the timestamp.
virtual UInt_t GetNbInputFrame() const =0
number of input frames that define this trigger
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
SharedFP * fPSAFrame
Utilities i.e. fPSA to decode PSA Frames.
header file for PSAFrame.cpp
virtual Frame * GetInputFrame(UInt_t which=0u)=0
to get back the frames that define this trigger
Base Watcher working for any event:data.
virtual void Exec(Option_t *option="")
watch the current frame
header file for AgataKeyFactory.cpp
SharedFP * fFrame
main frame i.e. event:data
To be used for Agata Data Flow.
Definition: Trigger.h:462
Gives the distribution of the different timstamps in a composite frame.
virtual Bool_t LinkSubFrame(UInt_t, Frame *)
Attach the sub-frame corresponding to the given subkey # to the Frame given in the second argument...
Definition: Frame.h:251
virtual void DoCanvas(TCanvas *c, Option_t *)
To be overwritten by real implementation if a canvas is produced.
Base class for a trigger on a data flow.
Definition: Trigger.h:155
virtual Bool_t SetTrigger(ADF::DFTrigger *=0x0)
Set the trigger attached to this watcher.
virtual ADF::DFTrigger * GetTrigger() const
To know the trigger in which the frame to be watched is embedded.
Definition: Watchers.h:360
virtual UInt_t GetNbSubFrame() const
Returns the number of sub-frames composing this frame. Scan have to be called first.
Definition: Frame.h:228
const std::string & GetItemName() const
Definition: FactoryItem.h:78
ClassImp(EventWatcher)
const FactoryItem & GetSignature() const
Signature of that frame.
Definition: Frame.h:127