StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StSvtDriftVelocityMaker.cxx
1 /***************************************************************************
2  *
3  * $Id: StSvtDriftVelocityMaker.cxx,v 1.6 2004/01/26 23:10:49 perev Exp $
4  *
5  * Author: Marcelo Munhoz
6  ***************************************************************************
7  *
8  * Description: SVT Drift Velocity calculation Maker
9  *
10  ***************************************************************************
11  *
12  * $Log: StSvtDriftVelocityMaker.cxx,v $
13  * Revision 1.6 2004/01/26 23:10:49 perev
14  * Leak off
15  *
16  * Revision 1.5 2003/09/02 17:59:05 perev
17  * gcc 3.2 updates + WarnOff
18  *
19  * Revision 1.4 2002/03/04 17:06:48 willson
20  * Laser spot positions recorded
21  *
22  * Revision 1.3 2002/02/06 00:10:45 willson
23  * File entries, variable names.
24  *
25  * Revision 1.2 2002/01/18 20:53:47 willson
26  * Some bug fixes by Helen
27  *
28  * Revision 1.1 2002/01/18 19:57:42 willson
29  * Drift Velocity Calculation v.1
30  *
31  *
32  **************************************************************************/
33 
34 #include <assert.h>
35 #include "StSvtDriftVelocityMaker.h"
36 
37 #include "StMessMgr.h"
38 
39 // #include "StSvtDb/StSvtDbMaker.h"
40 
41 
42 #include "StEventTypes.h"
43 #include "StEvent/StPrimaryVertex.h"
44 #include "StEvent/StEvent.h"
45 #include "StarClassLibrary/StSequence.hh"
46 #include "StSvtClassLibrary/StSvtHybridData.hh"
47 #include "StSvtClassLibrary/StSvtData.hh"
48 #include "StSvtClassLibrary/StSvtConfig.hh"
49 #include "StSvtClassLibrary/StSvtHybridPed.hh"
50 #include "StSvtClassLibrary/StSvtHybridDriftVelocity.hh"
51 #include "StSvtClassLibrary/StSvtHybridCollection.hh"
52 #include "StSvtClassLibrary/StSvtHybridPixels.hh"
53 #include "StSvtClusterMaker/StSvtAnalysedHybridClusters.hh"
54 #include "Stiostream.h"
55 #include <fstream>
56 
57 #define N_INJECTOR_LINES 4
58 
60 
61 //_____________________________________________________________________________
63 {
64  int n = (char*)&mDebug - (char*)&mSvtData + sizeof(mDebug);
65  memset(&mSvtData,0,n);
66 
67  mNumTimeBins = 128;
68  mMaximumTB = 128;
69  mMinimumTB = 0;
70  mDebug = false;
71  mFraction = 0.5;
72  mMoveForward = true;
73  mT0Guess = 0.5;
74 }
75 
76 //_____________________________________________________________________________
77 StSvtDriftVelocityMaker::~StSvtDriftVelocityMaker()
78 {
79  delete mSvtDriftVeloc; mSvtDriftVeloc=0;
80  for (int i=0;i<mNHybridDriftVelocityHisto;i++) {
81  delete mHybridDriftVelocityHisto[i];
82  delete mHybridDriftVelocity2DHisto[i];}
83  delete [] mHybridDriftVelocityHisto;
84  delete [] mHybridDriftVelocity2DHisto;
85 
86  delete mGlobalDriftVelocityHisto;
87  delete mGlobalDriftVelocity2DHisto;
88  delete mCalculatedDriftVelocity;
89  delete mLaserSpotDistL07B3_1;
90  delete mLaserSpotDistL15B3_1;
91  delete mLaserSpotDistL15B3_2;
92 
93 }
94 
95 //_____________________________________________________________________________
96 Int_t StSvtDriftVelocityMaker::Init()
97 {
98  //cout << "StSvtDriftVelocityMaker::Init" << endl;
99 
100  SetSvtRawData();
101 
102  SetSvtDriftVelocity();
103 
104  int indexHybrid;
105  StSvtHybridDriftVelocity* hybridDriftVeloc;
106  TH1D* hybridHisto;
107  TH2D* hybrid2DHisto;
108  char CharString1[100];
109  char CharString2[100];
110  mNHybridDriftVelocityHisto = mSvtRawData->getTotalNumberOfHybrids();
111  mHybridDriftVelocityHisto = new TH1D*[mNHybridDriftVelocityHisto];
112 
113  if (mDebug)
114  mHybridDriftVelocity2DHisto = new TH2D*[mNHybridDriftVelocityHisto];
115 
116  // Loop over barrels, ladders, wafers and hybrids
117  for (int barrel = 1;barrel <= mSvtRawData->getNumberOfBarrels();barrel++) {
118  for (int ladder = 1;ladder <= mSvtRawData->getNumberOfLadders(barrel);ladder++) {
119  for (int wafer = 1;wafer <= mSvtRawData->getNumberOfWafers(barrel);wafer++) {
120  for (int hybrid = 1;hybrid <= mSvtRawData->getNumberOfHybrids();hybrid++) {
121 
122  indexHybrid = mSvtRawData->getHybridIndex(barrel, ladder, wafer, hybrid);
123 
124  if (indexHybrid < 0) continue;
125 
126  hybridDriftVeloc = (StSvtHybridDriftVelocity*)mSvtRawData->at(indexHybrid);
127  if (!hybridDriftVeloc)
128  hybridDriftVeloc = new StSvtHybridDriftVelocity(barrel, ladder, wafer, hybrid);
129 
130  mSvtRawData->put_at(hybridDriftVeloc,indexHybrid);
131 
132  sprintf(CharString1, "Histo%d", indexHybrid);
133  sprintf(CharString2, "2DHisto%d", indexHybrid);
134 
135  hybridHisto = new TH1D(CharString1, CharString1, mNumTimeBins, mMinimumTB, mMaximumTB);
136  mHybridDriftVelocityHisto[indexHybrid] = hybridHisto;
137 
138  if (mDebug) {
139  hybrid2DHisto = new TH2D(CharString1, CharString1, 128, 0, 128, 240, 0, 240);
140  mHybridDriftVelocity2DHisto[indexHybrid] = hybrid2DHisto;
141  }
142 
143  } // end of loop over hybrids
144  } // end of loop over wafers
145  } // end of loop over ladders
146  } // end of loop over barrels
147 
148  if (mDebug) {
149  mGlobalDriftVelocityHisto = new TH1D("Global1", "Global1", 640, 0, 128);
150  mGlobalDriftVelocity2DHisto = new TH2D("Global2", "Global2", 640, 0, 128, 1200, 0, 240);
151  }
152 
153  mCalculatedDriftVelocity = new TH1D("Final", "Final", 432, 0, 431);
154  mLaserSpotDistL07B3_1 = new TH1D("L07B3 Laser Distribution 1", "L07B3 Laser Distribution 1", 1280, 0, 128);
155  mLaserSpotDistL15B3_1 = new TH1D("L15B3 Laser Distribution 1", "L15B3 Laser Distribution 1", 1280, 0, 128);
156  mLaserSpotDistL15B3_2 = new TH1D("L15B3 Laser Distribution 2", "L15B3 Laser Distribution 2", 1280, 0, 128);
157 
158  return StMaker::Init();
159 }
160 //______________________________________________
161 Int_t StSvtDriftVelocityMaker::SetSvtRawData()
162 {
163  St_DataSet *dataSet;
164 
165  dataSet = GetDataSet("StSvtRawData");
166  if( !dataSet) {
167  gMessMgr->Warning() << " No Svt Raw data set" << endm;
168  dataSet = new St_ObjectSet("DriftVelocity");
169  mSvtRawData = new StSvtData("FULL");
170  return kStWarn;
171  }
172 
173 
174  mSvtRawData = (StSvtData*)(dataSet->GetObject());
175  if( !mSvtRawData) {
176  gMessMgr->Warning() << " No Svt Raw data " << endm;
177  return kStWarn;
178  }
179 
180  return kStOK;
181 }
182 //_____________________________________________________________________________
183 Int_t StSvtDriftVelocityMaker::SetSvtData()
184 {
185  St_DataSet *dataSet;
186 
187  dataSet = GetDataSet("StSvtAnalResults");
188  if (dataSet) mRaw = true; else
189  mRaw = false;
190 
191  if (mRaw) {
192  mSvtData = (StSvtHybridCollection*)(dataSet->GetObject());
193  }
194 
195  return kStOK;
196 }
197 
198 //_____________________________________________________________________________
199 Int_t StSvtDriftVelocityMaker::SetSvtDriftVelocity()
200 {
201  assert(!mSvtDriftVeloc);
202  if (mSvtRawData)
203  mSvtDriftVeloc = new StSvtHybridCollection(mSvtRawData->getConfiguration());
204  else
205  mSvtDriftVeloc = new StSvtHybridCollection("FULL");
206 
207  return kStOK;
208 }
209 
210 //_____________________________________________________________________________
212 {
213  cout << "StSvtDriftVelocityMaker::Make" << endl;
214 
215  SetSvtData();
216 
217  if (mRaw)
218  FillHistogramsRaw();
219  else
220  FillHistogramsStEvent();
221 
222  cout << "Current Event Number is " << ((StSvtData*)mSvtRawData)->getEventNumber() << endl;
223  cout << "Current Run Number is " << ((StSvtData*)mSvtRawData)->getRunNumber() << endl;
224 
225 
226  //WriteToDb("2000-02-03 07:31:00");
227 
228  return kStOK;
229 }
230 
231 //_____________________________________________________________________________
232 Int_t StSvtDriftVelocityMaker::FillHistogramsRaw()
233 {
234 
235  //cout << "StSvtDriftVelocityMaker::FillHistogramsRaw" << endl;
236  StSvtAnalysedHybridClusters* hybridData;
237  //StSvtHybridDriftVelocity* hybridDriftVeloc;
238 
239  int indexHybrid, index, nHits;
240 
241  mEventCounter++; // increase counter
242 
243  // Loop over barrels, ladders, wafers and hybrids
244  for (int barrel = 1;barrel <= mSvtData->getNumberOfBarrels();barrel++) {
245  for (int ladder = 1;ladder <= mSvtData->getNumberOfLadders(barrel);ladder++) {
246  for (int wafer = 1;wafer <= mSvtData->getNumberOfWafers(barrel);wafer++) {
247  for (int hybrid = 1;hybrid <= mSvtData->getNumberOfHybrids();hybrid++) {
248 
249  indexHybrid = mSvtData->getHybridIndex(barrel, ladder, wafer, hybrid);
250  if (indexHybrid < 0) continue;
251 
252  // Get hybrid data
253  hybridData = (StSvtAnalysedHybridClusters*)(mSvtData->at(indexHybrid));
254 
255  if (!hybridData) continue;
256 
257  nHits = hybridData->numOfHits();
258  mHitCounter += nHits;
259 
260  for (index=0; index<nHits; index++) {
261 
262  if (accept(hybridData->svtHit())) {
263  mHybridDriftVelocityHisto[indexHybrid]->Fill(hybridData->WaferPosition()[index].x());
264 
265  if (indexHybrid==293) {
266  if (hybridData->WaferPosition()[index].y()>196.5 && hybridData->WaferPosition()[index].y()<200.5 && hybridData->WaferPosition()[index].x()>60)
267  mLaserSpotDistL07B3_1->Fill(hybridData->WaferPosition()[index].x());
268  }
269 
270  if (indexHybrid==416) {
271  if (hybridData->WaferPosition()[index].y()>198.5 && hybridData->WaferPosition()[index].y()<200.5 && hybridData->WaferPosition()[index].x()>60)
272  mLaserSpotDistL15B3_1->Fill(hybridData->WaferPosition()[index].x());
273  if (hybridData->WaferPosition()[index].y()>196.5 && hybridData->WaferPosition()[index].y()<198.5 && hybridData->WaferPosition()[index].x()>60)
274  mLaserSpotDistL15B3_2->Fill(hybridData->WaferPosition()[index].x());
275  }
276 
277  if (mDebug) {
278  mHybridDriftVelocity2DHisto[indexHybrid]->Fill(hybridData->WaferPosition()[index].x(), hybridData->WaferPosition()[index].y());
279  mGlobalDriftVelocityHisto->Fill(hybridData->WaferPosition()[index].x());
280  mGlobalDriftVelocity2DHisto->Fill(hybridData->WaferPosition()[index].x(), hybridData->WaferPosition()[index].y());
281  }
282 
283  }
284  }
285  } // end of loop over hybrids
286  } // end of loop over wafers
287  } // end of loop over ladders
288  } // end of loop over barrels
289 
290  return kStOK;
291 }
292 
293 
294 //_____________________________________________________________________________
295 Int_t StSvtDriftVelocityMaker::FillHistogramsStEvent()
296 {
297  //cout << "StSvtDriftVelocityMaker::FillHistogramsStEvent" << endl;
298  //StSvtHybridData* hybridData;
299  //StSvtHybridDriftVelocity* hybridDriftVeloc;
300 
301  //
302  // Get pointer to StEvent
303  //
304  StEvent* event;
305  event = (StEvent *) GetInputDS("StEvent");
306 
307  cout << "StEvent = " << event << endl;
308 
309  if (!event) return kStOK; // if no event, we're done
310 
311  StSvtConfig* fSvtConfig = new StSvtConfig();
312  fSvtConfig->setConfiguration("FULL");
313  //
314  // See if this event survives the event filter.
315  // If not we stop here right away.
316  //
317  if (!accept(event)) return kStOK;
318 
319  mEventCounter++; // increase counter
320 
321  // Get pointers to svt hit collection
322 
323  StSvtHitCollection* rSvtHitColl = event->svtHitCollection();
324 
325  cout << "Number of hits = " << rSvtHitColl->numberOfHits() << "." << endl;
326  mHitCounter += rSvtHitColl->numberOfHits();
327 
328  StSvtHit* sCurrentHit;
329 
330  for (unsigned int br=0; br<rSvtHitColl->numberOfBarrels(); br++) {
331  for (unsigned int ld=0; ld<rSvtHitColl->barrel(br)->numberOfLadders(); ld++) {
332  for (unsigned int w=0; w<rSvtHitColl->barrel(br)->ladder(ld)->numberOfWafers(); w++) {
333  StSPtrVecSvtHit& hits = rSvtHitColl->barrel(br)->ladder(ld)->wafer(w)->hits();
334  for (StSvtHitIterator i = hits.begin(); i != hits.end(); i++) {
335  sCurrentHit = (*i);
336  if( accept(sCurrentHit)) {
337  mHybridDriftVelocityHisto[sCurrentHit->index()]->Fill(sCurrentHit->timebucket());
338  if (mDebug)
339  mGlobalDriftVelocityHisto->Fill(sCurrentHit->timebucket());
340  }
341  }
342  }
343  }
344  }
345 
346  return kStOK;
347 
348 }
349 
350 
351 //_____________________________________________________________________________
352 Int_t StSvtDriftVelocityMaker::CalcDriftVelocity()
353 {
354 
355  double Aver=0, Num=0;
356  char filename[100];
357  Int_t Offset= (mMaximumTB - mMinimumTB)/10;
358  Int_t Start = Offset + mMinimumTB;
359  Int_t End = mMaximumTB - Offset;
360  Int_t i, j;
361  double DriftVelocity, TotalDriftTime;
362  ofstream file;
363 
364  sprintf(filename, "Run%d_DV.out", mSvtRawData->getRunNumber());
365 
366  file.open(filename);
367 
368  for (i=0; i<mSvtDriftVeloc->getTotalNumberOfHybrids(); i++) {
369 
370  for (j=Start; j<End; j++) {
371  Aver += mHybridDriftVelocityHisto[i]->GetBinContent(j);
372  Num++;
373  }
374 
375  Aver /= Num;
376 
377  Aver *= mFraction;
378 
379  if (mMoveForward) {
380  for (j=mMaximumTB/2; j<mMaximumTB+1; j++) {
381  if (mHybridDriftVelocityHisto[i]->GetBinContent(j) < Aver)
382  break;
383  }
384  }
385 
386  else {
387  for (j=mMaximumTB-2; j>mMaximumTB/2; j--) {
388  if (mHybridDriftVelocityHisto[i]->GetBinContent(j) > Aver)
389  break;
390  }
391  }
392 
393 
394 
395  if (mDebug)
396  cout << j << endl;
397 
398  TotalDriftTime = (j-mMinimumTB-mT0Guess)*(128.0/mNumTimeBins)*0.00000004;
399 
400  DriftVelocity = 3.0/TotalDriftTime;
401 
402  if (mDebug)
403  mCalculatedDriftVelocity->Fill(i, DriftVelocity);
404 
405  file << i << "\t" << DriftVelocity << "\t\t" << j*128.0/mNumTimeBins << "\n";
406 
407  Aver=Num=0;
408 
409  }
410 
411  file << "Laser Spot Time Bucket Positions:\n";
412 
413  file << "L07B3_1" << "\t" << mLaserSpotDistL07B3_1->GetMean() << "\n";
414  file << "L15B3_1" << "\t" << mLaserSpotDistL15B3_1->GetMean() << "\n";
415  file << "L15B3_2" << "\t" << mLaserSpotDistL15B3_2->GetMean() << "\n";
416 
417  file.close();
418 
419  return kStOK;
420 }
421 
422 //_____________________________________________________________________________
423 Int_t StSvtDriftVelocityMaker::GetInjectorLine(float peak)
424 {
425  return 0;
426 }
427 
428 //_____________________________________________________________________________
429 Int_t StSvtDriftVelocityMaker::GetInjectorLine(float* peak)
430 {
431  return 0;
432 }
433 
434 //_____________________________________________________________________________
435 Float_t StSvtDriftVelocityMaker::GetClosestToLine(float peak1, float peak2)
436 {
437  return 0;
438 }
439 
440 //_____________________________________________________________________________
441 Float_t StSvtDriftVelocityMaker::GetTimeZero(int anode)
442 {
443  return 0;
444 }
445 
446 //_____________________________________________________________________________
447 Float_t StSvtDriftVelocityMaker::GetDistanceInjectorLine(int line)
448 {
449  return 0;
450 }
451 
452 //_____________________________________________________________________________
453 Float_t StSvtDriftVelocityMaker::FitVelocity(int nInjectorsFired, float* peak, float t0)
454 {
455  return 0;
456 }
457 
458 //_____________________________________________________________________________
459 Float_t StSvtDriftVelocityMaker::CalcV1(int anode, float velocity)
460 {
461  return 0;
462 }
463 
464 //_____________________________________________________________________________
465 Float_t StSvtDriftVelocityMaker::CalcV2(int anode, float velocity)
466 {
467  return 0;
468 }
469 
470 //_____________________________________________________________________________
471 Float_t StSvtDriftVelocityMaker::CalcV3(int anode, float velocity)
472 {
473  return 0;
474 }
475 
476 //_____________________________________________________________________________
477 Int_t StSvtDriftVelocityMaker::FillAllAnodes()
478 {
479  return 0;
480 }
481 
482 //_____________________________________________________________________________
483 Int_t StSvtDriftVelocityMaker::WriteToDb(Text_t *timestamp)
484 {
485  cout << "StSvtDriftVelocityMaker::WriteToDb" << endl;
486 
487  if (!GetMaker("SvtDb")) {
488  gMessMgr->Warning() << " SVT database was not instantiated. Impossible to write! " << endm;
489  return kStWarn;
490  }
491 
492  //if (timestamp)
493  // ((StSvtDbMaker*)GetMaker("SvtDb"))->setTimeStamp(timestamp);
494 
495  //((StSvtDbMaker*)GetMaker("SvtDb"))->writeSvtDriftVelocity(mSvtDriftVeloc);
496 
497  return kStOK;
498 }
499 
500 //_____________________________________________________________________________
502 {
503  //cout << "StSvtDriftVelocityMaker::Finish" << endl;
504 
505  CalcDriftVelocity();
506 
507  Int_t indexHybrid;
508 
509  if (!mDebug) {
510  // Loop over barrels, ladders, wafers and hybrids
511  for (int barrel = 1;barrel <= mSvtDriftVeloc->getNumberOfBarrels();barrel++) {
512  for (int ladder = 1;ladder <= mSvtDriftVeloc->getNumberOfLadders(barrel);ladder++) {
513  for (int wafer = 1;wafer <= mSvtDriftVeloc->getNumberOfWafers(barrel);wafer++) {
514  for (int hybrid = 1;hybrid <= mSvtDriftVeloc->getNumberOfHybrids();hybrid++) {
515 
516  indexHybrid = mSvtDriftVeloc->getHybridIndex(barrel, ladder, wafer, hybrid);
517 
518  if (indexHybrid < 0) continue;
519 
520  delete mHybridDriftVelocityHisto[indexHybrid];
521 
522  } // end of loop over hybrids
523  } // end of loop over wafers
524  } // end of loop over ladders
525  } // end of loop over barrels
526 
527  delete [] mHybridDriftVelocityHisto;
528  }
529 
530  return kStOK;
531 }
532 
533 bool StSvtDriftVelocityMaker::accept(StEvent* event)
534 {
535  //
536  // This is a kind of very simple event filter.
537  // We select only events with a valid event vertex,
538  // i.e. event->primaryVertex() returns a non-zero pointer.
539  // and with the primary vertex under the svt
540 
541  if( !(event->primaryVertex())) return 0;
542  //cout << event->primaryVertex()->position().z() << endl;GetGlobalHisto()
543  //if( fabs(event->primaryVertex()->position().z()) < 20) return 1;
544 
545  return 1;
546 }
547 
548 bool StSvtDriftVelocityMaker::accept(StSvtHit* hit)
549 {
550  //Accept hits with flag < 4 and peak ADC>15
551 
552 
553  if( hit->flag() < 100) return 1;
554  return 0;
555 }
virtual TObject * GetObject() const
The depricated method (left here for the sake of the backward compatibility)
Definition: TDataSet.cxx:428
Definition: Stypes.h:42
Definition: Stypes.h:40