Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
groot.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file groot.C
1 #include "groot.h"
2 
3 //Important padplane headers
4 #include "ATrace.h"
5 #include "ABlob.h"
6 #include "ATrack.h"
7 #include "AZigzag.h"
8 
9 #include "Event.h"
10 #include "Quiver.h"
11 #include "TFile.h"
12 #include "TH1.h"
13 
14 #include <iostream>
15 #include <fstream>
16 #include <string>
17 #include <cstdlib> // Used to read $MYCALIB environment variable...
18 
19 #include <boost/algorithm/string.hpp>
20 
21 using namespace std;
22 using namespace boost;
24 
26 {
27  cout << "I am GROOT!";
28  cout << endl;
29 
30  // There are 4 readouts from the DRS4
31  for(int i=0; i<4; i++)
32  {
33  theTraces.push_back(new ATrace());
34  }
35 
36  // Used for neighboring cuts...
37  for (int i=0; i<Nsrs; i++)
38  {
39  ZigzagMap[i]=0;
40  ZWaveMap[i]=0;
41  }
42 
43  // Radius by Angle matrix of all the pads
44  for (int i=0; i<Nr; i++)
45  {
46  for (int j=0; j<Nphi; j++)
47  {
48  ZigzagMap2[i][j]=0;
49  }
50  }
51 
52  // Used to understand APV25 decoder order...
53  for (int i = 0; i < CHhybrid; i++)
54  {
55  int channel = 32 * ( i % 4 ) + 8 * ( i >> 2) - 31 * ( i >> 4);
56  demapper[channel]=i;
57  remapper[i]=channel;
58  }
59 
60  CreateZigzags(); // This makes the set of zigzags that form the TPC module.
61  FindNeighbors(); // Find trackers neighboring channels.
62  ClearTheDetector(); // Just to be sure that hexes are "born clear".
63 
65 }
66 
67 
69 {
70  for( unsigned int i=0; i<theTraces.size(); i++ ) { delete theTraces[i]; }
71 
72  for( unsigned int i=0; i< theTracks.size(); i++ ) { delete theTracks[i]; }
73 
74  for( unsigned int i=0; i< theZigzags.size(); i++ ) { delete theZigzags[i]; }
75 
76  for( unsigned int i=0; i<Nr; i++ )
77  {
78  for ( unsigned int j=0; i< theBlobs[i].size(); j++ ) { delete (theBlobs[i])[j]; }
79 
80  theBlobs[i].clear();
81  }
82 }
83 
84 
86 {
87  cout << "I am groot!" << endl;
88 
89  cout << "TRACES -------------------------------------------------------" << endl;
90  for (unsigned int i=0; i< theTraces.size(); i++)
91  {
92  cout << " Trace " << i;
93  cout << " Maximum: " << theTraces[i]->FindMaximum(1) << " " <<endl;
94  }
95 
96  cout << "ZIGZAGS -------------------------------------------------------" << endl;
97  int totalHit=0;
98  for (unsigned int i=0; i< theZigzags.size(); i++)
99  {
100  /*
101  if ( theZigzags[i]->IsHit() )
102  {
103  cout << "Zigzag " << i << " " << endl;
104  theZigzags[i]->Report();
105 
106  int j;
107  if (i%64 == 0) cin >> j;
108 
109  totalHit++;
110  }
111  cout << "Total Pads Hit: " << totalHit << endl;
112  */
113  }
114 
115  cout << " BLOBS --------------------------------------------------------------" << endl;
116  for(int i=0; i<Nr; i++)
117  {
118  cout << "*** ROW: " << i+1 << endl;
119  for (int j=0; j<theBlobs[i].size(); j++)
120  {
121  theBlobs[i][j]->Report();
122  }
123  }
124 }
125 
126 
128 {
129  // clear the voltage vector in each trace.
130  for (int i=0; i<4; i++)
131  {
132  theTraces[i]->voltage.clear();
133  }
134 
135  // AZigzag static variables...
136  for (int i=0; i<Nsrs; i++)
137  {
138  AZigzag::Raw[i].clear();
139  AZigzag::Cal[i].clear();
140  }
141 
142  // destroy all the old blobs...
143  for(unsigned int i=0; i<Nr; i++)
144  {
145  for ( unsigned int j=0; j< theBlobs[i].size(); j++ )
146  {
147  delete (theBlobs[i])[j];
148  }
149  theBlobs[i].clear();
150  }
151 
152  // destroy all the old tracks...
153  for ( unsigned int i=0; i< theTracks.size(); i++ )
154  {
155  delete theTracks[i];
156  }
157  theTracks.clear();
158 }
159 
160 
162 {
163  cout << "waveform neighbors" << endl;
164  // Determine the waveform neighbors...
165  for (int j=0; j<Nhybrid; j++)
166  {
167  for (int k=0; k<CHhybrid; k++)
168  {
169  int i = CHhybrid*j + k;
170  if (ZWaveMap[i] !=0)
171  {
172  if (k>0) ZWaveMap[i]->PreWaveform = ZWaveMap[i-1];
173  if (k<CHhybrid-1) ZWaveMap[i]->PostWaveform = ZWaveMap[i+1];
174  }
175  }
176  }
177 
178  cout << "logical neighbors" << endl;
179  // Determine the logical neighbors...
180  for (int j=0; j<Nr; j++)
181  {
182  for (int k=0; k<Nphi; k++)
183  {
184  if (ZigzagMap2[j][k] !=0)
185  {
186  if (k>0) ZigzagMap2[j][k]->PreLogical = ZigzagMap2[j][k-1];
187  if (k<Nphi-1) ZigzagMap2[j][k]->PostLogical = ZigzagMap2[j][k+1];
188  }
189  }
190  }
191 }
192 
193 
195 {
196  cout << "Filling the Zigzag Maps..." << endl;
197 
198  string dir( getenv("MYCALIB") );
199  string file("PadMap.txt");
200  string result = dir + file;
201  cout << "Looking for PadMap.txt in " << result << endl;
202  ifstream fin(result.c_str());
203 
204  if (!fin.is_open())
205  {
206  cout << "Groot could not open the file PadMap.txt." << endl;
207  cout << "Please initialize the variable $MYCALIB in your .login." << endl;
208  cout << "Then move the PadMap.txt file from the groot source to there." << endl;
209  cout << "Only after that will you be allowed to continue analysis." << endl;
210  return;
211  }
212  cout << "FOUND!" << endl;
213 
214  string line;
215  while (!fin.eof())
216  {
217  fin >> line;
218 
219  vector<string> items;
220  boost::split(items, line, [](char c){return c == ',';});
221 
222  Padplane_NameToConnector[items[0]] = items[1];
223  Padplane_NameToSamPin[items[0]] = items[2];
224  }
225  fin.close();
226 
227  //map<string, string>::iterator it1;
228  // for (it1 = Padplane_NameToConnector.begin(); it1 != Padplane_NameToConnector.end(); it1++)
229  // {
230  // cout << " " << it1->first;
231  // cout << " " << it1->second;
232  // cout << endl;
233  // }
234 
235  dir = getenv("MYCALIB");
236  file = "PanSamMap.txt";
237  result = dir + file;
238  cout << "Looking for PadMap.txt in " << result << endl;
239  fin.open(result.c_str());
240 
241  if (!fin.is_open())
242  {
243  cout << "You could not open the file PanSamMap.txt." << endl;
244  cout << "Please initialize the variable $MYCALIB in your .login." << endl;
245  cout << "Then move the PanSamMap.txt file from the groot source to there." << endl;
246  cout << "Only after that will you be allowed to continue analysis." << endl;
247  return;
248  }
249  cout << "FOUND!" << endl;
250 
251  while (!fin.eof())
252  {
253  fin >> line;
254 
255  vector<string> items;
256  boost::split(items, line, [](char c){return c == ',';});
257 
258  PanSam_SamPinToPanPin[items[0]] = atoi(items[1].c_str());
259  }
260  fin.close();
261 
262  //map<string, int>::iterator it2;
263  //for (it2 = PanSam_SamPinToPanPin.begin(); it2 != PanSam_SamPinToPanPin.end(); it2++)
264  // {
265  // cout << " " << it2->first;
266  // cout << " " << it2->second;
267  // cout << endl;
268  // }
269 }
270 
271 
272 int groot::PanPinToChannel(int PanPin)
273 {
274  if (PanPin%2 == 0)
275  {
276  return 132-PanPin-2; // the -2 makes channel instead of pin
277  }
278  else
279  {
280  return 130-PanPin-2; // the -2 makes channel instead of pin
281  }
282 }
283 
284 
285 int groot::ConnectorToHybrid(string Conn)
286 {
287  // FIrst get rid of the U$ business..
288  string ConnNumber = Conn.substr(2);
289  int Number = atoi(ConnNumber.c_str());
290 
291  int hybrid;
292  if (Number%2 == 0)
293  {
294  hybrid = Number-2;
295  }
296  else
297  {
298  hybrid = Number;
299  }
300 
301  //cout << " " << Conn;
302  //cout << " " << ConnNumber;
303  //cout << " " << Number;
304  //cout << " " << hybrid;
305  //cout << endl;
306 
307  return hybrid;
308 }
309 
310 
312 {
313  FillZigzagMaps();
314 
315  string dir( getenv("MYCALIB") );
316  string file("OUTPUT_trim.XML");
317  string result = dir + file;
318  cout << "Looking for OUTPUT_trim.XML in " << result << endl;
319  ifstream fin(result.c_str());
320 
321  if (!fin.is_open())
322  {
323  cout << "You could not open the file OUTPUT_trim.XML." << endl;
324  cout << "Please initialize the variable $MYCALIB in your .login." << endl;
325  cout << "Then move the OUTPUT_trim.XML file from the groot source to there." << endl;
326  cout << "Only after that will you be allowed to continue analysis." << endl;
327  return;
328  }
329  cout << "FOUND!" << endl;
330 
331  double tmp;
332  CheveronPad_t thispad;
333 
334  for(;;)
335  {
336  fin >> tmp;
337  if(!fin.good()) break;
338  if(tmp==99999) // begin of polygon detected
339  {
340  fin >> thispad.fName;
341  fin >> thispad.fPolyWidth;
342  fin >> thispad.fPolyLayer;
343  for(;;)
344  {
345  fin >> tmp;
346  if(tmp==999999) break;
347  thispad.fX.push_back(tmp);
348  double x = tmp;
349  fin >> tmp;
350  thispad.fY.push_back(tmp);
351  double y = tmp;
352  double R = TMath::Sqrt(x*x+y*y);
353  double Phi = TMath::Pi()+TMath::ATan2(-y,-x);
354  thispad.r.push_back( R );
355  thispad.phi.push_back( Phi );
356  }
357  //cout << thispad.fName.Data();
358  //cout << " size of points " << thispad.fX.size() << endl;
359  fin >> tmp; thispad.fVia.push_back( tmp ); //0
360  fin >> tmp; thispad.fVia.push_back( tmp ); //
361  fin >> tmp; thispad.fVia.push_back( tmp ); //2
362  fin >> tmp; thispad.fVia.push_back( tmp ); //
363  fin >> tmp; thispad.fVia.push_back( tmp ); //4
364  fin >> tmp; thispad.fVia.push_back( tmp ); //
365  fin >> tmp; thispad.fVia.push_back( tmp ); //6
366  fin >> tmp; thispad.fVia.push_back( tmp ); //
367 
368  fin >> tmp; thispad.fWire.push_back( tmp ); //0
369  fin >> tmp; thispad.fWire.push_back( tmp ); //
370  fin >> tmp; thispad.fWire.push_back( tmp ); //2
371  fin >> tmp; thispad.fWire.push_back( tmp ); //
372  fin >> tmp; thispad.fWire.push_back( tmp ); //4
373  fin >> tmp; thispad.fWire.push_back( tmp ); //
374 
375  int hybrid = ConnectorToHybrid(Padplane_NameToConnector[thispad.fName]);
376  int channel = PanPinToChannel(PanSam_SamPinToPanPin[Padplane_NameToSamPin[thispad.fName]]);
377  int index = CHhybrid*hybrid + channel;
378 
379  // Because some runs did not use all known hybrids...
380  if (hybrid >= Nhybrid) continue;
381 
382  // OK, looks like this is a valid hybrid.
383  // Make the hybrid and set it up (mostly)...
384  AZigzag* thisZigzag = new AZigzag(thispad);
385  thisZigzag->SetMyID(index);
386  thisZigzag->MyHybrid = hybrid;
387  thisZigzag->MyChannel= channel;
388  thisZigzag->MyWaveIndex = demapper[channel];
389  theZigzags.push_back( thisZigzag );
390 
391  // Now setup the utility arrays for the Mapping of neighbors...
392  vector<string> items;
393  split(items, thispad.fName, [](char c){return c == '.';});
394  int ir = atoi(items[1].c_str());
395  int iphi = atoi(items[2].c_str());
396  thisZigzag->iR = ir;
397  thisZigzag->iPhi = iphi;
398  ZigzagMap [index] = thisZigzag;
399  ZigzagMap2[ir][iphi] = thisZigzag;
400  ZWaveMap[hybrid*128+demapper[channel]] = thisZigzag;
401 
402  // Print out some stuff...
403  // cout << " " << thispad.fName;
404  // cout << " " << Padplane_NameToConnector[thispad.fName];
405  // cout << " " << ConnectorToHybrid(Padplane_NameToConnector[thispad.fName]);
406  // cout << " " << Padplane_NameToSamPin[thispad.fName];
407  // cout << " " << PanSam_SamPinToPanPin[Padplane_NameToSamPin[thispad.fName]];
408  // cout << " " << PanPinToChannel(PanSam_SamPinToPanPin[Padplane_NameToSamPin[thispad.fName]]);
409  // cout << " ind " << index;
410  // cout << " ir " << ir;
411  // cout << " ip " << iphi;
412  // cout << " hyb+de " << hybrid*128+demapper[channel] ;
413  // cout << " " << index;
414  // cout << endl;
415  }
416  thispad.fX.clear();
417  thispad.fY.clear();
418  thispad.fVia.clear();
419  thispad.fWire.clear();
420  thispad.r.clear();
421  thispad.phi.clear();
422  }
423 fin.close();
424 }
425 
427 {
428  TFile *theFile = new TFile(filename.c_str(),"RECREATE");
429 
430  for (int i=0; i<theHistograms.size(); i++)
431  {
432  theHistograms[i]->Write();
433  }
434 
435  theFile->Close();
436 }
437 
439 {
440  // zero out any and all old data...
441  for (int i=0; i<Nr; i++)
442  {
443  for (int j=0; j<10; j++)
444  {
445  AccessBlobs[i][j] = 0;
446  }
447  }
448 
449  // Fill em up...
450  for (int i=0; i<Nr; i++)
451  {
452  BlobCount[i] = theBlobs[i].size();
453  int MAX = (( theBlobs[i].size() < 10) ? theBlobs[i].size() : 10);
454  for (int j=0; j<MAX; j++)
455  {
456  AccessBlobs[i][j] = theBlobs[i][j];
457  }
458  }
459 
460 }