FairRoot/PandaRoot
PndGemDigiAna.cxx
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // ----- PndGemDigiAna source file -----
3 // ----- Created 02.06.2009 by R. Karabowicz -----
4 // -------------------------------------------------------------------------
5 
6 #include "PndGemDigiAna.h"
7 
8 // FairRoot includes
9 #include "FairRootManager.h"
10 #include "FairRunAna.h"
11 #include "FairRuntimeDb.h"
12 #include "FairBaseParSet.h"
13 #include "FairTrackParam.h"
14 #include "FairRootManager.h"
15 // Pnd includes
16 #include "PndGemDigiPar.h"
17 #include "PndGemDigi.h"
18 // ROOT includes
19 #include "TClonesArray.h"
20 #include "TGeoManager.h"
21 
22 // C++ includes
23 #include <iostream>
24 #include <iomanip>
25 #include <map>
26 #include <cmath>
27 using std::cout;
28 using std::endl;
29 using std::map;
30 using std::setw;
31 
32 // ----- Default constructor ------------------------------------------
34  : FairTask("GEM Digis Ana", 1),
35  fDigiPar(NULL),
36  fGemDigiArray(NULL),
37  fNofEvents(0),
38  fHistoList(NULL),
39  fHistoArray(NULL)
40 {
41 }
42 // -------------------------------------------------------------------------
43 
44 // ----- Standard constructor ------------------------------------------
46  : FairTask("GEM Digis Ana", iVerbose) ,
47  fDigiPar(NULL),
48  fGemDigiArray(NULL),
49  fNofEvents(0),
50  fHistoList(NULL),
51  fHistoArray(NULL)
52 {
53 }
54 // -------------------------------------------------------------------------
55 
56 // ----- Standard constructor ------------------------------------------
58  : FairTask(taskName, iVerbose) ,
59  fDigiPar(NULL),
60  fGemDigiArray(NULL),
61  fNofEvents(0),
62  fHistoList(NULL),
63  fHistoArray(NULL)
64 {
65 }
66 // -------------------------------------------------------------------------
67 
68 // ----- Destructor ----------------------------------------------------
70 
71 // ----- Init -----------------------------------------------------------
72 InitStatus PndGemDigiAna::Init() {
73 
74  // Get and check FairRootManager
75  FairRootManager* ioman = FairRootManager::Instance();
76  if( !ioman ) {
77  cout << "-E- "<< GetName() <<"::Init: "
78  << "RootManager not instantised!" << endl;
79  return kERROR;
80  }
81 
82  // Get the pointer to the singleton FairRunAna object
83  FairRunAna* ana = FairRunAna::Instance();
84  if(NULL == ana) {
85  cout << "-E- "<< GetName() <<"::Init :"
86  <<" no FairRunAna object!" << endl;
87  return kERROR;
88  }
89  // Get the pointer to run-time data base
90  FairRuntimeDb* rtdb = ana->GetRuntimeDb();
91  if(NULL == rtdb) {
92  cout << "-E- "<< GetName() <<"::Init :"
93  <<" no runtime database!" << endl;
94  return kERROR;
95  }
96 
97  // Get Gem digi Array
98  fGemDigiArray = (TClonesArray*) ioman->GetObject("GEMDigi");
99  if ( !fGemDigiArray ) {
100  cout << "-E- " << GetName() << "::Init: No PndGemDigi array!" << endl;
101  return kERROR;
102  }
103 
104  // Get GEM digitisation parameter container
105  fDigiPar = (PndGemDigiPar*)(rtdb->getContainer("PndGemDetectors"));
106 
107  cout << "-I- " << fName.Data() << "::Init(). There are " << fDigiPar->GetNStations() << " GEM stations." << endl;
108  cout << "-I- " << fName.Data() << "::Init(). Initialization succesfull." << endl;
109 
110  CreateHistos();
111 
112  return kSUCCESS;
113 }
114 // -------------------------------------------------------------------------
115 
116 // ----- Private method ReInit -----------------------------------------
117 InitStatus PndGemDigiAna::ReInit() {
118 
119  return kSUCCESS;
120 }
121 // -------------------------------------------------------------------------
122 
123 // ----- Private method SetParContainers -------------------------------
125 
126  // Get run and runtime database
127  FairRunAna* run = FairRunAna::Instance();
128  if ( ! run ) Fatal("SetParContainers", "No analysis run");
129 
130  FairRuntimeDb* db = run->GetRuntimeDb();
131  if ( ! db ) Fatal("SetParContainers", "No runtime database");
132 
133  // Get GEM digitisation parameter container
134  fDigiPar = (PndGemDigiPar*)(db->getContainer("PndGemDetectors"));
135 
136  fNofEvents = 0;
137 }
138 // -------------------------------------------------------------------------
139 
140 
141 // ----- Public method Exec --------------------------------------------
142 void PndGemDigiAna::Exec(Option_t*) {
143 
144  if ( fVerbose ) {
145  cout << "IN EVENT GOT " << fGemDigiArray->GetEntries() << " hits." << endl;
146  cout << " - - - - - > " << fHistoArray->GetEntries() << " histograms" << endl;
147  }
148 
149  Int_t nofGemDigis = fGemDigiArray->GetEntries();
150 
151  PndGemDigi* gemDigi = NULL;
152 
153  for ( Int_t idigi = 0 ; idigi < nofGemDigis ; idigi++ ) {
154  gemDigi = (PndGemDigi*)fGemDigiArray->At(idigi);
155 
156  Int_t digiCode =
157  4*(gemDigi->GetStationNr()-1)+
158  2*(gemDigi->GetSensorNr()-1)+
159  gemDigi->GetSide();
160 
161  if ( digiCode < 0 || digiCode > 11 )
162  cout << "oops, wrong digiCode " << digiCode
163  << " from station " << gemDigi->GetStationNr()
164  << " sensor " << gemDigi->GetSensorNr()
165  << " side " << gemDigi->GetSide()
166  << endl;
167 
168  Double_t lastTime = ((TH1F*)fHistoArray->At(digiCode))->GetBinContent(gemDigi->GetChannelNr());
169 
170  if ( lastTime > 0. ) {
171  // cout << " DIGI on station " << gemDigi->GetStationNr()
172  // << " sensor " << gemDigi->GetSensorNr()
173  // << " side " << gemDigi->GetSide()
174  // << " channel " << gemDigi->GetChannelNr()
175  // << " came again at " << gemDigi->GetTimeStamp()
176  // << " after " << lastTime
177  // << endl;
178  ((TH1F*)fHistoArray->At(fDigiPar->GetNStations()*4+digiCode))->Fill(gemDigi->GetTimeStamp()-lastTime);
179 
180  }
181 
182  ((TH1F*)fHistoArray->At(digiCode))->SetBinContent(gemDigi->GetChannelNr(),gemDigi->GetTimeStamp());
183  }
184 
185  fNofEvents++;
186 
187 }
188 // ------------------------------------------------------------
189 
190 
191 // ----- Private method CreateHistos --------------------------------------------
193  fHistoList = new TList();
194 
195  if ( fVerbose )
196  cout << "ought to create histogram for " << fDigiPar->GetNStations() << " stations." << endl;
197 
198  Int_t nofStations = fDigiPar->GetNStations();
199  Int_t nofHists = 0;
200 
201  fHistoArray = new TClonesArray("TH1F", 5000);
202 
203  for ( Int_t istat = 0 ; istat < nofStations ; istat++ ) {
204  PndGemStation* station = (PndGemStation*)fDigiPar->GetStation(istat);
205 
206  if ( station->GetNSensors() != 2 ) {
207  std::cout << "will have problems with different numbers of sensors per station (" << station->GetNSensors() << ")" << std::endl;
208  }
209 
210  for ( Int_t isens = 0 ; isens < station->GetNSensors() ; isens++ ) {
211  PndGemSensor* sensor = (PndGemSensor*)station->GetSensor(isens);
212 
213  for ( Int_t iside = 0 ; iside < 2 ; iside++ ) {
214 
215  new ((*fHistoArray)[nofHists++]) TH1F(Form("fhLDTS_s%d_s%d_s%d",istat,isens,iside),
216  Form("Last digi time stamp, station %d, sensor %d, %s side",istat,isens,(iside?"back":"front")),
217  sensor->GetSideChannels(iside)+1,-0.5,sensor->GetSideChannels(iside)+0.5);
218  }
219  }
220  }
221 
222  for ( Int_t istat = 0 ; istat < nofStations ; istat++ ) {
223  PndGemStation* station = (PndGemStation*)fDigiPar->GetStation(istat);
224 
225  for ( Int_t isens = 0 ; isens < station->GetNSensors() ; isens++ ) {
226  //PndGemSensor* sensor = (PndGemSensor*)station->GetSensor(isens); //[R.K. 01/2017] unused variable?
227 
228  for ( Int_t iside = 0 ; iside < 2 ; iside++ ) {
229 
230  new ((*fHistoArray)[nofHists++]) TH1F(Form("fhTimeBetweenDigis_s%d_s%d_s%d",istat,isens,iside),
231  Form("Time between digis, station %d, sensor %d, %s side",istat,isens,(iside?"back":"front")),
232  100000,0,100000);
233  }
234  }
235  }
236 
237  if ( fVerbose ) {
238  cout << "HM, seems that fHistoArray is filled with histograms, and there are " << nofHists << " of them" << endl;
239  }
240 
241 }
242 // ------------------------------------------------------------
243 
244 // ----- Private method AnaHistos --------------------------------------------
246 
247  //Int_t nofStations = fDigiPar->GetNStations(); //[R.K. 01/2017] unused variable?
248 }
249 // ------------------------------------------------------------
250 
251 // ----- Private method Finish --------------------------------------------
253  cout << "-------------------- PndGemDigiAna : Summary ------------------" << endl;
254  cout << " Events: " << setw(10) << fNofEvents << endl;
255  cout << "---------------------------------------------------------------------" << endl;
256 
257  AnaHistos();
258 
259  TFile* temp = gFile;
260  FairRootManager* ioman = FairRootManager::Instance();
261  gFile = ioman->GetOutFile();
262  gDirectory = (TDirectory*)gFile;
263 
264  gDirectory->mkdir("GemDigiAna");
265  gDirectory->cd("GemDigiAna");
266  TIter next(fHistoList);
267  for ( Int_t ihist = 0 ; ihist < fHistoArray->GetEntries() ; ihist++ ) {
268  fHistoArray->At(ihist)->Write();
269  }
270  gDirectory->cd("..");
271 
272  gFile = temp;
273 }
274 // ------------------------------------------------------------
275 
276 
int fVerbose
Definition: poormantracks.C:24
TList * fHistoList
Definition: PndGemDigiAna.h:62
Int_t run
Definition: autocutx.C:47
TClonesArray * fGemDigiArray
Definition: PndGemDigiAna.h:57
Int_t GetStationNr() const
Definition: PndGemDigi.h:84
PndTransMap * map
Definition: sim_emc_apd.C:99
TGeoVolume * sensor
virtual InitStatus ReInit()
Digitization Parameter Class for GEM part.
Definition: PndGemDigiPar.h:31
Int_t GetSideChannels(Int_t si) const
Definition: PndGemSensor.h:114
PndGemSensor * GetSensor(Int_t iSensor)
Definition: PndGemStation.h:63
virtual InitStatus Init()
Int_t GetSensorNr() const
Definition: PndGemDigi.h:86
Int_t GetNSensors() const
Definition: PndGemStation.h:60
Double_t
Int_t fNofEvents
event counter
Definition: PndGemDigiAna.h:60
Double_t GetChannelNr() const
Definition: PndGemDigi.h:80
FairRuntimeDb * rtdb
Definition: hit_dirc.C:66
virtual ~PndGemDigiAna()
PndGemDigiPar * fDigiPar
Definition: PndGemDigiAna.h:51
Int_t GetNStations()
Definition: PndGemDigiPar.h:45
virtual void Finish()
analyze GEM digis
Definition: PndGemDigiAna.h:33
ClassImp(PndAnaContFact)
Int_t iVerbose
virtual void SetParContainers()
virtual void Exec(Option_t *opt)
static int next[96]
Definition: ranlxd.cxx:374
Int_t GetSide() const
Definition: PndGemDigi.h:88
TClonesArray * fHistoArray
Definition: PndGemDigiAna.h:65
PndGemStation * GetStation(Int_t iStation)