source: MEMPHYS/HEAD/applications/MEMPHYS_analysis.cxx @ 168

Last change on this file since 168 was 168, checked in by barrand, 18 years ago

G.Barrand : ajout MEMPHYS_analysis

File size: 10.4 KB
Line 
1// AIDA analysis program over MEMPHYS.root file.
2
3// AIDA :
4#include <AIDA/AIDA.h>
5
6// std :
7#include <iostream>
8
9//////////////////////////////////////////////////////////////////////////////
10bool getXYZ(
11 AIDA::ITuple& aParent
12,int aColumn
13,double& aX
14,double& aY
15,double& aZ
16) 
17//////////////////////////////////////////////////////////////////////////////
18//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
19{
20  AIDA::ITupleEntry* entry = (AIDA::ITupleEntry*)aParent.getObject(aColumn);
21  if(!entry) return false;
22
23  AIDA::ITuple* tuple = dynamic_cast<AIDA::ITuple*>(entry);
24  if(!tuple) return false;
25
26  tuple->start();
27  if(!tuple->next()) return false;
28
29  aX = tuple->getDouble(0);
30  aY = tuple->getDouble(1);
31  aZ = tuple->getDouble(2);
32
33  return true;
34}
35//////////////////////////////////////////////////////////////////////////////
36//////////////////////////////////////////////////////////////////////////////
37//////////////////////////////////////////////////////////////////////////////
38bool dump_tracks(
39 AIDA::ITuple& aParent
40) 
41//////////////////////////////////////////////////////////////////////////////
42//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
43{
44  AIDA::ITupleEntry* entry = (AIDA::ITupleEntry*)aParent.getObject(8);
45  if(!entry) return false;
46
47  AIDA::ITuple* tuple = dynamic_cast<AIDA::ITuple*>(entry);
48  if(!tuple) return false;
49
50  //if(nPart!=tracks->rows()) {
51  //  std::cout << "read: nPart / tracks mismatch "
52  //              << nPart << " " << tracks->rows() << std::endl;
53  //  return false;
54  //}
55
56  tuple->start();
57  int irow = 0;
58  while(tuple->next()) {
59
60    int pId = tuple->getInt(0);
61    int parent = tuple->getInt(1);
62    float timeStart = tuple->getFloat(2);
63
64    double dx,dy,dz;
65    if(!getXYZ(*tuple,3,dx,dy,dz)) return false;
66
67    double mass = tuple->getDouble(4);
68    double pTot = tuple->getDouble(5);
69    double ETot = tuple->getDouble(6);
70
71    double px,py,pz;
72    if(!getXYZ(*tuple,7,px,py,pz)) return false;
73
74    double start_x,start_y,start_z;
75    if(!getXYZ(*tuple,8,start_x,start_y,start_z)) return false;
76
77    double stop_x,stop_y,stop_z;
78    if(!getXYZ(*tuple,9,stop_x,stop_y,stop_z)) return false;
79
80    int startVol = tuple->getInt(10);
81    int stopVol = tuple->getInt(11);
82
83    std::cout << "----> Tk{"<<irow<<"}: " 
84              << " pId " << pId
85              << " parent " << parent
86              << " creation time " << timeStart
87              << " Volumes " << startVol << " " << stopVol << "\n"
88              << " Start Pos (" << start_x
89              << "," << start_y << "," << start_z << ")\n"
90              << " Stop Pos (" << stop_x
91              << "," << stop_y << "," << stop_z << ")\n"
92              << " dx,dy,dz " << dx << " " << dy << " " << dz << "\n"
93              << " m " << mass
94              << " ETot " << ETot
95              << " pTot " << pTot
96              << " px,py,pz " << px << " " << py << " " << pz << "\n"
97              << std::endl;
98
99    irow++;
100  }
101  return true;
102}
103//////////////////////////////////////////////////////////////////////////////
104bool process_hits_times(
105 AIDA::ITuple& aParent
106,AIDA::IHistogram1D& aHisto
107) 
108//////////////////////////////////////////////////////////////////////////////
109//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
110{
111  AIDA::ITupleEntry* entry = (AIDA::ITupleEntry*)aParent.getObject(2);
112  if(!entry) return false;
113
114  AIDA::ITuple* tuple = dynamic_cast<AIDA::ITuple*>(entry);
115  if(!tuple) return false;
116
117  tuple->start();
118  while(tuple->next()) {
119
120    float time = tuple->getFloat(0);
121
122    aHisto.fill(time);
123  }
124  return true;
125}
126//////////////////////////////////////////////////////////////////////////////
127bool process_hits(
128 AIDA::ITuple& aParent
129,AIDA::IHistogram1D& aHisto
130) 
131//////////////////////////////////////////////////////////////////////////////
132//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
133{
134  AIDA::ITupleEntry* entry = (AIDA::ITupleEntry*)aParent.getObject(10);
135  if(!entry) return false;
136
137  AIDA::ITuple* tuple = dynamic_cast<AIDA::ITuple*>(entry);
138  if(!tuple) return false;
139
140  tuple->start();
141  while(tuple->next()) {
142
143    //int tubeId = tuple->getInt(0);
144    //int totalPE = tuple->getInt(1);
145
146    if(!process_hits_times(*tuple,aHisto)) return false;
147  }
148  return true;
149}
150//////////////////////////////////////////////////////////////////////////////
151bool process_digits(
152 AIDA::ITuple& aParent
153,AIDA::IHistogram2D& aHisto
154) 
155//////////////////////////////////////////////////////////////////////////////
156//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
157{
158  AIDA::ITupleEntry* entry = (AIDA::ITupleEntry*)aParent.getObject(13);
159  if(!entry) return false;
160
161  AIDA::ITuple* tuple = dynamic_cast<AIDA::ITuple*>(entry);
162  if(!tuple) return false;
163
164  tuple->start();
165  while(tuple->next()) {
166
167    //int tubeId = tuple->getInt(0);
168    double pe = tuple->getDouble(1);
169    double time = tuple->getDouble(2);
170    //printf("debug : ++++ : %g %g\n",time,pe);
171
172    aHisto.fill(time,pe);
173  }
174  return true;
175}
176//////////////////////////////////////////////////////////////////////////////
177bool plot(
178 AIDA::IAnalysisFactory& aAIDA
179,AIDA::IHistogram1D& aHisto1D
180,AIDA::IHistogram2D& aHisto2D
181) 
182//////////////////////////////////////////////////////////////////////////////
183//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
184{
185  std::string header = "MEMPHYS_analysis : ";
186
187  AIDA::IPlotterFactory* plotterFactory = 
188    aAIDA.createPlotterFactory(0,0);
189  if(!plotterFactory) {
190    std::cout << header << "can't get a PlotterFactory." << std::endl;
191    return false;
192  }
193   
194  AIDA::IPlotter* plotter = plotterFactory->create();
195  if(!plotter) {
196    std::cout << header << "can't get a plotter." << std::endl;
197    return false;
198  }
199   
200  plotter->clearRegions();
201  plotter->createRegions(1,2,0);
202
203  plotter->setCurrentRegionNumber(0);
204  plotter->currentRegion().plot(aHisto1D);
205
206  plotter->setCurrentRegionNumber(1);
207  plotter->currentRegion().plot(aHisto2D);
208
209
210  plotter->show();
211  plotter->interact();
212
213  delete plotter;
214  delete plotterFactory;
215
216  return true;
217}
218//////////////////////////////////////////////////////////////////////////////
219//////////////////////////////////////////////////////////////////////////////
220//////////////////////////////////////////////////////////////////////////////
221int main(
222 int //aArgc
223,char** //aArgv
224) 
225//////////////////////////////////////////////////////////////////////////////
226//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
227{
228  //std::string arg1 = aArgc>=2?aArgv[1]:"";
229
230  std::string program = "MEMPHYS_analysis";
231  std::string header = program + " : ";
232
233  AIDA::IAnalysisFactory* aida = AIDA_createAnalysisFactory();
234  if(!aida) {
235    std::cout << header << "AIDA not found." << std::endl;
236    return 1;
237  }
238
239  AIDA::ITreeFactory* treeFactory = aida->createTreeFactory();
240  if(!treeFactory) {
241    std::cout << header << "can't get a TreeFactory." << std::endl;
242    return 1;
243  }
244
245  ////////////////////////////////////////////////////////
246  // Create histograms in memory tree ////////////////////
247  ////////////////////////////////////////////////////////
248  AIDA::ITree* memory = treeFactory->create();
249  if(!memory) {
250    std::cout << header << "can't get memory tree." << std::endl;
251    return 1;
252  }
253  AIDA::IHistogramFactory* histogramFactory = 
254    aida->createHistogramFactory(*memory);
255  if(!histogramFactory) {
256    std::cout << header << "can't get an histogram factory." << std::endl;
257    return 1;
258  }
259 
260  AIDA::IHistogram1D* hits_times = 
261    histogramFactory->createHistogram1D("hits_times","Hits times",100,0,3000);
262  if(!hits_times) {
263    std::cout << header
264              << "can't create histogram : time." 
265              << std::endl;
266    return 1;
267  }
268
269  AIDA::IHistogram2D* digits_time_pe = 
270    histogramFactory->createHistogram2D("digits_pe_time","Digits PE time",
271                                        100,0,3000,100,0,10);
272  if(!digits_time_pe) {
273    std::cout << header
274              << "can't create histogram : digits_time_pe." 
275              << std::endl;
276    return 1;
277  }
278
279  delete histogramFactory;
280
281  ////////////////////////////////////////////////////////
282  /// Read data //////////////////////////////////////////
283  ////////////////////////////////////////////////////////
284
285  AIDA::ITree* tree = treeFactory->create("MEMPHYS.root","root",true,false);
286  if(!tree) {
287    std::cout << header << "can't open data file." << std::endl;
288    return 1;
289  }
290
291  AIDA::IManagedObject* object = tree->find("Event");
292  if(!object) {
293    std::cout << header
294              << "object Event not found in tree." 
295              << std::endl;
296    return 1;
297  }
298  AIDA::ITuple* tuple = dynamic_cast<AIDA::ITuple*>(object);
299  if(!tuple) {
300    std::cout << header << "object not an AIDA::ITuple." << std::endl;
301    return 1;
302  }
303
304  int coln = tuple->columns();
305  for(int index=0;index<coln;index++) {
306    std::cout << header
307              << " icol = " << index
308              << ", label = " << tuple->columnName(index) 
309              << ", type = " << tuple->columnType(index) 
310              << std::endl;
311  }
312
313  std::cout << header << "rows = " << tuple->rows() << std::endl;
314
315  int nentries = tuple->rows();
316  //int nentries = 100000;
317  //int nentries = 40;
318  std::cout << header
319            << "traitements de " << nentries << " entrees" 
320            << std::endl;
321
322  int irow = 0;
323  tuple->start();
324  while(tuple->next() && (irow<nentries)) {
325
326    /*
327    int eventId = tuple->getInt(0);
328    //int inputEvtId = tuple->getInt(1);
329    //int interMode = tuple->getInt(2);
330    //int vtxVol = tuple->getInt(3);
331
332    int nPart = tuple->getInt(5);
333    //int leptonIndex = tuple->getInt(6);
334    //int protonIndex = tuple->getInt(7);
335
336    int nHits = tuple->getInt(9);
337    int nDigits = tuple->getInt(11);
338    double sumPE = tuple->getDouble(12);
339
340    std::cout << ">>>>>>>>>>>>> Event{" << irow << "}: "
341              << " evt Id " << eventId
342    //        << " evt Input Id " << inputEvtId
343    //        << "\n interaction mode " << interMode
344    //        << " start in volume " << vtxVol << "\n"
345              <<" #tracks: " << nPart
346              <<" #hits: " << nHits
347              <<" #digits: " << nDigits
348              <<" sumPE " << sumPE
349              << std::endl;
350    */
351
352    //if(!dump_tracks(*tuple)) return 1;
353
354    if(!process_hits(*tuple,*hits_times)) return 1;
355    if(!process_digits(*tuple,*digits_time_pe)) return 1;
356
357    irow++;
358  }
359
360  delete treeFactory;
361  delete tree;
362
363  plot(*aida,*hits_times,*digits_time_pe);
364
365  delete aida;
366
367  return 0;
368}
Note: See TracBrowser for help on using the repository browser.