StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StSvtSeqAdjMaker.cxx
1  /***************************************************************************
2  *
3  * $Id: StSvtSeqAdjMaker.cxx,v 1.57 2016/04/21 01:37:04 perev Exp $
4  *
5  * Author:
6  ***************************************************************************
7  *
8  * Description: Sequence
9  **************************************************************************
10  *
11  *
12  * Revision 1.29 2001/09/26 18:42:48 Takahashi
13  * Added new bad anode list and switched ON the bad anode elimination
14  *
15  * $Log: StSvtSeqAdjMaker.cxx,v $
16  * Revision 1.57 2016/04/21 01:37:04 perev
17  * Remove dangerous delete
18  *
19  * Revision 1.56 2007/04/28 17:57:10 perev
20  * Redundant StChain.h removed
21  *
22  * Revision 1.55 2005/07/23 03:37:34 perev
23  * IdTruth + Cleanup
24  *
25  * Revision 1.54 2004/04/03 01:17:25 caines
26  * I think this time I should really have stopped valgrind complaing lets see
27  *
28  * Revision 1.53 2004/03/18 04:05:01 caines
29  * Remove from global scope variables used in debug mode as they shouldnt be there and caused erratic behaviour, also initialise some variables that valgrind was complaining about - didnt really need to as they are sent back from function which initialises them properly always but doesnt hurt
30  *
31  * Revision 1.52 2004/02/11 00:42:17 caines
32  * Put common mode back
33  *
34  * Revision 1.51 2004/01/27 02:44:16 perev
35  * LeakOff
36  *
37  * Revision 1.50 2004/01/22 17:15:21 caines
38  * Remove gain calibration files and common mode moise subtraction
39  *
40  * Revision 1.49 2003/09/18 18:16:44 caines
41  * Initialise stuff for new compiler
42  *
43  * Revision 1.48 2003/07/31 19:01:14 caines
44  * Make changes so the slow simulator can run
45  *
46  * Revision 1.47 2003/07/18 17:15:40 caines
47  * Fix Pedoffset to be 20 not 10 change variables to int from floats to avoid casting problems, fix that when pedestal goes negative we dont
48  *
49  * Revision 1.46 2003/04/14 15:56:59 munhoz
50  * changes for gain calibration file
51  *
52  * Revision 1.45 2003/01/28 20:21:17 munhoz
53  * changing from Init() to InitRun()
54  *
55  * Revision 1.44 2003/01/21 01:27:44 jeromel
56  * hfile->write(0 while NULL caused spurious crash.
57  * Took the oportunity to add GetCVS()
58  * Some maniaco-compulsive //! alignement fixes ...
59  *
60  * Revision 1.43 2002/09/26 20:46:06 caines
61  * Make sure initRun works when no svt data present and correct code to allow for the ordering init and initrun are called in
62  *
63  * Revision 1.42 2002/09/20 19:35:19 caines
64  * Change building of file name
65  *
66  * Revision 1.41 2002/09/19 16:17:48 caines
67  * Add code to do Juns gain calibration
68  *
69  * Revision 1.40 2002/05/09 16:55:08 munhoz
70  * add reading bad anodes from DB
71  *
72  * Revision 1.39 2002/04/21 20:28:01 caines
73  * Put some of the print out only if in debug mode
74  *
75  * Revision 1.37 2002/01/11 22:49:15 caines
76  * Fix sequence merging bugs-hopefully
77  *
78  * Revision 1.36 2001/12/13 03:08:11 caines
79  * Can now subtract common mode noise via black anodes 239 and 2
80  *
81  * Revision 1.35 2001/10/19 23:31:30 caines
82  * Correct problem that if anodes were missing didnt do average common mode noise calc
83  *
84  * Revision 1.32 2001/10/04 02:56:01 caines
85  * Change default pedoffset and black anodes to current values
86  *
87  * Revision 1.31 2001/10/02 22:55:57 caines
88  * Jun was coorect about B2L8D2H2
89  *
90  * Revision 1.30 2001/09/28 20:47:38 caines
91  * Fix typo in bad anode listing
92  *
93  * Revision 1.29 2001/09/28 15:36:41 caines
94  * Add in bad anode elimination
95  *
96  * Revision 1.28 2001/09/26 18:42:48 caines
97  * Fix 2 anode subtraction routines
98  *
99  * Revision 1.27 2001/09/22 00:35:54 caines
100  * Fixes now that AddData() is cleared everyevent
101  *
102  * Revision 1.26 2001/09/16 22:24:22 caines
103  * Fix for when SVT isnt in every event
104  *
105  * Revision 1.25 2001/08/28 19:02:55 caines
106  * Remove hardwired line that makes it always do common mode average (dumb!)
107  *
108  * Revision 1.24 2001/08/24 21:40:04 caines
109  * Adjust rawHybridData not SeqHybridData in Common Mode noise subtraction
110  *
111  * Revision 1.23 2001/08/24 20:57:45 caines
112  * Do common mode noise suppression from first two anodes
113  *
114  * Revision 1.22 2001/08/22 14:24:49 caines
115  * Raise m_thresh_hi to 10
116  *
117  * Revision 1.21 2001/07/25 14:47:41 caines
118  * Fix filling histogram only when debug is on
119  *
120  * Revision 1.20 2001/07/22 20:31:28 caines
121  * Better tuning for real data. Common mode noise calc and sub. Avoid overlapping seq. Fill histograms only in debug
122  *
123  * Revision 1.19 2001/05/06 22:16:35 caines
124  * Fix pointer problem for DAQ Ped files
125  *
126  * Revision 1.18 2001/04/30 22:27:40 caines
127  * Fix adjusting for ZSP data
128  *
129  * Revision 1.17 2001/04/25 19:00:17 perev
130  * HPcorrs
131  *
132  * Revision 1.16 2001/03/28 21:49:38 caines
133  * Correct bug that allowed AdjustSeq1 code to fall off end
134  *
135  * Revision 1.15 2001/03/22 20:47:10 caines
136  * Comment out some of the QA histograms
137  *
138  * Revision 1.14 2001/02/07 19:15:05 caines
139  * Change char[3] to char[4] for full SVT running
140  *
141  * Revision 1.13 2000/11/30 20:45:56 caines
142  * Dynamically calc prob values, use database
143  *
144  * Revision 1.12 2000/10/31 16:21:59 caines
145  * Set up efaults for paramters in init
146  *
147  * Revision 1.11 2000/10/02 13:48:10 caines
148  * Adjusting donw hybrid by hybrid
149  *
150  * Revision 1.10 2000/09/14 22:13:56 caines
151  * Move histogram creation to better place
152  *
153  * Revision 1.9 2000/08/28 22:11:38 caines
154  * Fixed check that data exists before using it
155  *
156  * Revision 1.8 2000/08/24 04:23:50 caines
157  * Improved histograms
158  *
159  * Revision 1.7 2000/08/21 12:57:31 caines
160  * Now opens and reads in ped using CalibMaker
161  *
162  * Revision 1.6 2000/08/09 02:05:08 caines
163  * Only add pixels in the ASIC-like sequence adjusting
164  *
165  * Revision 1.5 2000/07/16 22:32:23 caines
166  * Now also saves RAW data
167  *
168  * Revision 1.4 2000/07/13 14:50:13 caines
169  * Fixed up problem when pointer went past 128
170  *
171  * Revision 1.3 2000/07/11 18:36:15 caines
172  * Updates to save more of sequence for fitting
173  *
174  * Revision 1.2 2000/07/03 02:07:56 perev
175  * StEvent: vector<TObject*>
176  *
177  * Revision 1.1 2000/06/15 20:04:54 caines
178  * Initial versions of sequence adjusting codes
179  *
180  **************************************************************************/
181 
182 #include "TFile.h"
183 #include "TH1.h"
184 #include "TH2.h"
185 #include "StSequence.hh"
186 #include "StMCTruth.h"
187 #include "StSvtClassLibrary/StSvtData.hh"
188 #include "StSvtClassLibrary/StSvtHybridData.hh"
189 #include "StSvtClassLibrary/StSvtHybridPed.hh"
190 #include "StSvtClassLibrary/StSvtHybridCollection.hh"
191 #include "StSvtInverseProducts.hh"
192 #include "StSvtProbValues.hh"
193 #include "StSvtPedSub.h"
194 #include "StSvtClassLibrary/StSvtHybridBadAnodes.hh"
195 #include "StSvtSeqAdjMaker.h"
196 #include "StSvtCalibMaker/StSvtPedMaker.h"
197 #include "StMessMgr.h"
198 #include "StIOMaker/StIOMaker.h"
199 
200 #include "St_DataSetIter.h"
201 #include "TObjectSet.h"
202 
203 
204 
205 //___________________________________________________________________________________________
206 StSvtSeqAdjMaker::StSvtSeqAdjMaker(const char *name) : StMaker(name)
207 {
208 
209  mSvtDataSet = NULL;
210  mSvtAdjData = NULL;
211  mSvtRawData = NULL;
212  mSvtBadAnodes = NULL;
213  mHybridRawData = NULL;
214  mHybridAdjData = NULL;
215  mSvtPedSub = NULL;
216  mSvtPedColl = NULL;
217  anolist = NULL;
218  mInvProd = NULL;
219  mProbValue = NULL;
220 
221  // Set up some defaults
222 
223  mPedFile = NULL;
224  hfile = NULL;
225  mPedOffSet = 20;
226  m_thresh_lo = 3+mPedOffSet;
227  m_thresh_hi = 5+mPedOffSet;
228  m_n_seq_lo = 2;
229  m_n_seq_hi = 0;
230  m_inv_prod_lo = 0;
231 
232 }
233 
234 //____________________________________________________________________________
235 StSvtSeqAdjMaker::~StSvtSeqAdjMaker(){
236 }
237 //____________________________________________________________________________
238 Int_t StSvtSeqAdjMaker::Init(){
239 
240 
241  GetSvtRawData();
242 
243  SetSvtData();
244 
245  mInvProd = new StSvtInverseProducts();
246  mProbValue = new StSvtProbValues();
247 
248  float sigma;
249  // set probability values
250  for (int barrel = 1;barrel <= mSvtRawData->getNumberOfBarrels();barrel++) {
251  for (int ladder = 1;ladder <= mSvtRawData->getNumberOfLadders(barrel);ladder++) {
252  for (int wafer = 1;wafer <= mSvtRawData->getNumberOfWafers(barrel);wafer++) {
253  for (int hybrid = 1;hybrid <= mSvtRawData->getNumberOfHybrids();hybrid++) {
254  int index = mSvtRawData->getHybridIndex(barrel,ladder,wafer,hybrid);
255  if(index < 0) continue;
256  if (mSvtPedColl && mSvtPedColl->at(index))
257  sigma = ((StSvtHybridPed*)mSvtPedColl->at(index))->getRMS();
258  else
259  sigma = mProbValue->GetSigma();
260  mProbValue->SetProbValue(sigma);
261  mInvProd->SetProbTable(mProbValue);
262  }
263  }
264  }
265  }
266 
267  return StMaker::Init();
268 }
269 //____________________________________________________________________________
270 Int_t StSvtSeqAdjMaker::InitRun( int runnumber)
271 {
272 
273  if(GetSvtRawData() ){
274 
275  St_DataSet *dataSet = NULL;
276  dataSet = GetDataSet("StSvtConfig");
277 
278  if (!dataSet) return kStWarn;
279 
280  mSvtRawData = new StSvtData((StSvtConfig*)(dataSet->GetObject()));
281  AddData(new TObjectSet("StSvtRawData",mSvtRawData));
282  }
283 
284  mTotalNumberOfHybrids = mSvtRawData->getTotalNumberOfHybrids();
285 
286  if( hfile){
287  hfile->Write();
288  hfile->Close();
289  }
290 
291  string ioMakerFileName;
292  string FileName;
293  string DirName;
294  DirName=".";
295 
296  StIOMaker* mIOMaker = (StIOMaker*)GetMaker("inputStream");
297  cout << "************************" << mIOMaker << endl;
298  if (mIOMaker){
299  ioMakerFileName = string(mIOMaker->GetFile());
300  FileName = buildFileName( DirName+"/", baseName(ioMakerFileName),".SvtGainCal.root");
301  // cout << "Heres my name: " << FileName << endl;
302  }else
303  {
304  FileName=buildFileName( DirName+"/", "SeqAdj-Run"+GetRunNumber(),".SvtGainCal.root");
305  }
306  //hfile = new TFile(FileName.c_str(),"RECREATE","Demo ROOT file");
307  CreateHist(mTotalNumberOfHybrids);
308 
309  GetBadAnodes();
310 
311  GetSvtPedestals();
312 
313  gMessMgr->Info()<< " StSvtSeqAdjMaker-info:"<<endm;
314  gMessMgr->Info() << " PedOffSet = "<<mPedOffSet<<endm;
315  gMessMgr->Info() << " thresh_lo = "<<m_thresh_lo <<endm;
316  gMessMgr->Info() << " thresh_hi = "<<m_thresh_hi <<endm;
317  gMessMgr->Info() << " n_seq_lo = "<<m_n_seq_lo <<endm;
318  gMessMgr->Info() << " n_seq_hi = "<< m_n_seq_hi <<endm;
319  gMessMgr->Info() << " inv_prod_lo = "<<m_inv_prod_lo <<endm;
320 
321  return kStOK;
322 }
323 
324 //____________________________________________________________________________
325 
326 
327 Int_t StSvtSeqAdjMaker::GetSvtRawData()
328 {
329  St_DataSet *dataSet;
330 
331  dataSet = GetDataSet("StSvtRawData");
332  if( !dataSet) {
333  gMessMgr->Warning() << " No Svt Raw data set" << endm;
334  return kStWarn;
335  }
336 
337  mSvtRawData = (StSvtData*)(dataSet->GetObject());
338  if( !mSvtRawData) {
339  gMessMgr->Warning() << " No Svt Raw data " << endm;
340  return kStWarn;
341  }
342  return kStOK;
343 }
344 
345 //____________________________________________________________________________
346 
347 
348 Int_t StSvtSeqAdjMaker::GetSvtPedestals()
349 {
350  if (mPedFile) {
351  StSvtPedMaker* sdaq = (StSvtPedMaker*)GetMaker("SvtPed");
352 
353  if( sdaq)
354  sdaq->ReadFromFile( mPedFile);
355  }
356 
357  St_DataSet *dataSet;
358 
359  dataSet = GetDataSet("StSvtPedestal");
360 
361  // get pedestals and set pedestal subtraction ONLY if there is a pedestal data set
362  if (dataSet) {
363  mSvtPedColl = (StSvtHybridCollection*)(dataSet->GetObject());
364  mSvtPedSub = new StSvtPedSub(mSvtPedColl);
365 
366  //Set offset
367  mSvtRawData->setPedOffset(mPedOffSet);
368  }
369 
370  return kStOK;
371 }
372 
373 //__________________________________________________________________________
374 
375 
376 Int_t StSvtSeqAdjMaker::SetSvtData()
377 {
378  mSvtDataSet = new St_ObjectSet("StSvtData");
379  AddData(mSvtDataSet);
380 
381  mSvtAdjData = new StSvtData(*mSvtRawData);
382  //cout<<"mSvtAdjData = "<<mSvtAdjData<<endl;
383  mSvtDataSet->SetObject((TObject*)mSvtAdjData);
384  // assert(mSvtAdjData);
385 
386  return kStOK;
387 }
388 
389 //__________________________________________________________________________
390 
391 Int_t StSvtSeqAdjMaker::SetMinAdcLevels( int MinAdc1, int MinAbove1,
392  int MinAdc2, int MinAbove2, int PedOffset){
393 
394  m_thresh_lo = MinAdc1+PedOffset;
395  m_thresh_hi = MinAdc2+PedOffset;
396  m_n_seq_lo = MinAbove1;
397  m_n_seq_hi = MinAbove2;
398 
399  //if (PedOffset)
400  mPedOffSet = PedOffset;
401 
402  return kStOK;
403 }
404 
405 //____________________________________________________________________________
406 
407 Int_t StSvtSeqAdjMaker::SetPedestalFile(const char* pedFile)
408 {
409  if(Debug()) gMessMgr->Debug() << "opening file called " << pedFile << " "
410  << GetName() << endm;
411 
412  mPedFile = pedFile;
413 
414  return kStOK;
415 }
416 
417 
418 //____________________________________________________________________________
419 
420 Int_t StSvtSeqAdjMaker::SetLowInvProd(int LowInvProd)
421 {
422  m_inv_prod_lo = LowInvProd;
423 
424  return kStOK;
425 }
426 
427 //___________________________________________________________________________
428 
429 Int_t StSvtSeqAdjMaker::GetBadAnodes()
430 {
431 
432  St_DataSet *dataSet;
433 
434  dataSet = GetDataSet("StSvtBadAnodes");
435  if( !dataSet) {
436  gMessMgr->Warning() << " No Svt Bad Anodes data set" << endm;
437  return kStWarn;
438  }
439 
440  mSvtBadAnodes = (StSvtHybridCollection*)(dataSet->GetObject());
441  if( !mSvtBadAnodes) {
442  gMessMgr->Warning() << " No Svt Bad Anodes data " << endm;
443  return kStWarn;
444  }
445  return kStOK;
446 }
447 
448 //_____________________________________________________________________________
449 Int_t StSvtSeqAdjMaker::CreateHist(Int_t tNuOfHyb)
450 {
451  // Create Histograms
452 
453 
454  //mInvProdSeqAdj= new TH1D*[tNuOfHyb];
455  mRawAdc = new TH1F*[tNuOfHyb];
456  mAdcAfter = new TH1F*[tNuOfHyb];
457  //mTimeAn = new TH2F*[tNuOfHyb];
458 
459  char RawTitle[25], AdcAfterTitle[25], TimeAnTitle[25];
460  char Index[4];
461  char* RawTitle_cut;
462  char* AdcAf_cut;
463  char* TimeAnCh;
464  for (int barrel = 1;barrel <= mSvtRawData->getNumberOfBarrels();barrel++) {
465  for (int ladder = 1;ladder <= mSvtRawData->getNumberOfLadders(barrel);ladder++) {
466  for (int wafer = 1;wafer <= mSvtRawData->getNumberOfWafers(barrel);wafer++) {
467  for (int hybrid = 1;hybrid <= mSvtRawData->getNumberOfHybrids();hybrid++) {
468 
469  int index = mSvtRawData->getHybridIndex(barrel,ladder,wafer,hybrid);
470  if(index < 0) continue;
471 
472  sprintf(RawTitle,"RawAdcIn");
473  sprintf(AdcAfterTitle,"numOfhitsIn");
474  sprintf(TimeAnTitle,"TimeAn");
475  sprintf(Index,"%d", index);
476  RawTitle_cut = strcat(RawTitle,Index);
477  AdcAf_cut = strcat(AdcAfterTitle,Index);
478  TimeAnCh = strcat(TimeAnTitle,Index);
479 
480  mRawAdc[index] = new TH1F(RawTitle_cut,"Raw ADC for each anode",241,0,241);
481  mAdcAfter[index] = new TH1F(AdcAf_cut,"Number of hits in each anode",241,0,241);
482  //mTimeAn[index] = new TH2F(TimeAnCh,"Time vs Anode",240,0,240,128,0,128);
483  }
484  }
485  }
486  }
487  mOcupancyHisto = new TH1F("OcupancyHisto","Anode Occupancy in an event",129,0,128);
488  EventOccupancy = new TH1F("EventOccup","Event Occupancy",200,0,100000);
489 
490  return kStOK;
491 }
492 
493 //____________________________________________________________________________
494 
496 {
497 
498  int Anode;
499 
500  StSvtHybridBadAnodes* BadAnode=NULL;
501 
502  // GetBadAnodes();
503  if ( GetSvtRawData() ) return kStWarn; // Return if SVT not there
504 
505  SetSvtData();
506 
507  // copy event information to adjusted data collection
508 //VP (*mSvtAdjData) = (*mSvtRawData); // already made in SetSvtData()
509 
510  gMessMgr->Info() << "Working On Event: " << mSvtAdjData->getEventNumber() << endm;
511 
512 
513  Evt_counts=0;
514 
515  for(int Barrel = 1;Barrel <= mSvtRawData->getNumberOfBarrels();Barrel++){
516  for (int Ladder = 1;Ladder <= mSvtRawData->getNumberOfLadders(Barrel);Ladder++){
517  for (int Wafer = 1;Wafer <= mSvtRawData->getNumberOfWafers(Barrel);Wafer++){
518  for( int Hybrid = 1;Hybrid <=mSvtRawData->getNumberOfHybrids();Hybrid++){
519 
520  int index = mSvtRawData->getHybridIndex(Barrel,Ladder,Wafer,Hybrid);
521 
522  if( index < 0) continue;
523 
524  mHybridRawData = (StSvtHybridData *)mSvtRawData->at(index);
525 
526  // cout << "mHybridRawData = " << mHybridRawData << endl;
527  if( !mHybridRawData) continue;
528 
529  // subtract pedestal from raw data and save pedestal subtracted data
530  //if( mSvtPedSub){
531  // mSvtPedSub->SubtractPed(mHybridRawData, index, mPedOffSet);
532  //}
533 
534  // retrieve bad anodes
535  if (mSvtBadAnodes)
536  BadAnode = (StSvtHybridBadAnodes*)mSvtBadAnodes->at(index);
537 
538  mHybridAdjData = (StSvtHybridData *)mSvtAdjData->at(index);
539  mSvtAdjData->put_at(0,index);
540  delete mHybridAdjData;
541  mHybridAdjData = new StSvtHybridData(Barrel,Ladder,Wafer,Hybrid);
542  mHybridAdjData->setTimeZero(mHybridRawData->getTimeZero());
543  mHybridAdjData->setSCAZero(mHybridRawData->getSCAZero());
544 
545  doCommon = 1;
546  mNAnodes = FindBlackAnodes();
547 
548  if( doCommon || !mNAnodes ){
549  if (Debug()) gMessMgr->Debug() << "Doing Common mode average for index " << index << endl;
550 
551  // Zero Common Mode Noise arrays
552  for(int Timebin=0; Timebin<128; Timebin++){
553  mCommonModeNoise[Timebin]=0;
554  mCommonModeNoiseAn[Timebin]=0;
555  }
556  }
557  for( int iAnode= 0; iAnode< mHybridRawData->getAnodeList(anolist); iAnode++)
558  {
559  Anode = anolist[iAnode];
560 
561  // here anode is real anode number (1-240)
562  //if (Debug())MakeHistogramsAdc(mHybridRawData,index,Anode,1);
563  if( doCommon) CommonModeNoiseCalc(iAnode);
564  }
565 
566  if( doCommon){
567  int TimeLast, TimeAv, TimeSum, TimeAvSav;
568  TimeLast = 0;
569  TimeSum = 0;
570  TimeAv=0;
571  TimeAvSav = 0;
572  for( int TimeBin=0; TimeBin<128; TimeBin++){
573  if(mCommonModeNoiseAn[TimeBin] > 30)
574  mCommonModeNoise[TimeBin] /= mCommonModeNoiseAn[TimeBin];
575  else mCommonModeNoise[TimeBin] =0;
576 
577  if( Debug()){
578  if( index < 4 && mCommonModeNoiseAn[TimeBin] > 20){
579  if( TimeLast < TimeBin-3 && TimeSum > 0){
580 
581  TimeAv /= TimeSum;
582  TimeLast = TimeBin;
583  TimeAvSav = TimeAv;
584  TimeAv = 0;
585  TimeSum=0;
586  }
587  else{
588  TimeAv +=TimeBin;
589  TimeSum++;
590  TimeLast = TimeBin;
591  }
592  }
593  } // End of if If(Debug)
594  }
595  } // End of If(Common)
596 
597  for( int iAnode= 0; iAnode<mHybridRawData->getAnodeList(anolist); iAnode++)
598  {
599  Anode = anolist[iAnode];
600 
601  // Skip Bad anodes
602  //
603  if( BadAnode && BadAnode->isBadAnode(Anode)) continue;
604 
605  if( doCommon) CommonModeNoiseSub(iAnode);
606  else SubtractFirstAnode(iAnode);
607  //if (Debug() && !doCommon)MakeHistogramsAdc(mHybridRawData,index,Anode,1);
608  //Perform Asic like zero suppression
609  AdjustSequences1(iAnode, Anode);
610 
611  //Perform E896 type zero-suppresion (look for non-noise like signals
612  if(m_inv_prod_lo){
613  mInvProd->FindInvProducts(mHybridAdjData,iAnode,mPedOffSet);
614  // if(Debug())MakeHistogramsProb(index,Anode);
615  AdjustSequences2(iAnode, Anode);
616 
617  }
618  // Here anode is index to real anode number (1-240)
619  MakeHistogramsAdc(mHybridRawData,index,Anode,2);
620  }
621 
622 
623  mHybridAdjData->setAnodeList();
624  mSvtAdjData->put_at(mHybridAdjData,index);
625  }
626 
627  mInvProd->ResetBuffer();
628  }
629  }
630  }
631  cout << endl;
632  cout << " Event Occupancy = " << Evt_counts << endl;
633 
634  EventOccupancy->Fill((float)Evt_counts);
635  Evt_counts=0;
636 
637  return kStOK;
638 
639 }
640 
641 //_____________________________________________________________________________
642 
643 Int_t StSvtSeqAdjMaker::AdjustSequences1(int iAnode, int Anode){
644 
645  //Perform ASIC like zero suppression. Need > m_n_seq_lo pixels with a count
646  // > than m_thresh_lo and > m_n_seq_hi pixels with a count
647  // > than m_thresh_hi
648 
649  int nSeqOrig, nSeqNow, nSeqTruth, length, count1, count2;
650  int startTimeBin, status;
652  StMCTruth* SeqTruth;
653  unsigned char* adc;
654  //int ExtraBefore = 1;
655  // int ExtraAfter = 3;
656  int ExtraBefore = 0;
657  int ExtraAfter = 0;
658  int firstTimeBin;
659 
660  //Anode is the index into the anolist array
661  status= mHybridRawData->getListSequences(iAnode,nSeqOrig,Sequence);
662  status= mHybridRawData->getListTruth (iAnode,nSeqTruth,SeqTruth );
663  //status= mHybridRawData->getSequences(Anode,nSeqOrig,Sequence);
664 
665  nSeqNow = 0;
666  StSequence tempSeq1[128];
667  StMCTruth tempTru1[128];
668  for( int nSeq=0; nSeq< nSeqOrig ; nSeq++){
669 
670  adc=Sequence[nSeq].firstAdc;
671  length = Sequence[nSeq].length;
672  startTimeBin=Sequence[nSeq].startTimeBin;
673 
674  int j =0;
675  while( j<length){
676  count1=0;
677  count2=0;
678 
679  while( (int)adc[j] > m_thresh_lo && j<length){
680  count1++;
681 
682  if( (int)adc[j] > m_thresh_hi){
683  count2++;
684  }
685 
686  j++;
687  }
688 
689  if( count2 > m_n_seq_hi && count1 > m_n_seq_lo){
690 
691  firstTimeBin = startTimeBin + j - count1 - ExtraBefore;
692 
693  tempSeq1[nSeqNow].firstAdc=&adc[j- count1 - ExtraBefore];
694  tempSeq1[nSeqNow].startTimeBin = firstTimeBin;
695  tempSeq1[nSeqNow].length = 0;
696  if((startTimeBin + j - count1 - ExtraBefore) < 0){
697  tempSeq1[nSeqNow].startTimeBin=0;
698  tempSeq1[nSeqNow].firstAdc=&adc[0];
699  // Make length temp. negative to account for the fact we went
700  //past the start of the sequence get adjusted properly in a bit
701  tempSeq1[nSeqNow].length = startTimeBin + j - count1 - ExtraBefore;
702  }
703 
704  if((startTimeBin + j - count1 - ExtraBefore) < startTimeBin){
705  tempSeq1[nSeqNow].startTimeBin=startTimeBin;
706  tempSeq1[nSeqNow].firstAdc=&adc[0];
707  // Make length temp. negative to account for the fact we went
708  //past the start of the sequence get adjusted properly in a bit
709  tempSeq1[nSeqNow].length = startTimeBin + j - count1 - ExtraBefore
710  -startTimeBin;
711  }
712 
713  // Make length proper size even if it went negative
714  tempSeq1[nSeqNow].length += count1+ ExtraAfter+ ExtraBefore;
715 
716  // Check dont go past end of sequence if do adjust length correctly
717  if( tempSeq1[nSeqNow].length + tempSeq1[nSeqNow].startTimeBin > 128)
718  tempSeq1[nSeqNow].length=128-tempSeq1[nSeqNow].startTimeBin +1;
719  if ( tempSeq1[nSeqNow].startTimeBin+ tempSeq1[nSeqNow].length >
720  startTimeBin +length){
721  tempSeq1[nSeqNow].length = (startTimeBin +length) -
722  tempSeq1[nSeqNow].startTimeBin ;
723  }
724  if (SeqTruth) tempTru1[nSeqNow]=SeqTruth[nSeq];
725  nSeqNow++;
726  }
727 
728 
729  j++;
730  }
731  }
732 
733  mNumOfSeq=0;
734  if( nSeqNow > 0){
735  if (SeqTruth) SeqTruth=tempTru1;
736  mNumOfSeq = MergeSequences(tempSeq1,nSeqNow,SeqTruth);
737  }
738 
739  mHybridAdjData->setListSequences(iAnode, Anode,mNumOfSeq, tempSeq1);
740  if (SeqTruth)
741  mHybridAdjData->setListTruth (iAnode, Anode,mNumOfSeq, tempTru1);
742 
743  //if (nSeqNow)
744  // cout << "For Anode=" << Anode << " Number sequnces was=" << nSeqOrig << " Number now=" << nSeqNow << endl;
745 
746  // data << endl;
747 
748  return kStOK;
749 }
750 
751 //_____________________________________________________________________________
752 
753 Int_t StSvtSeqAdjMaker::AdjustSequences2(int iAnode, int Anode){
754 
755  //Perform E896 like zero suppression. Find pixels that have consecutive ADC
756  // counts that do not have the shape of noise
757 
758  int nSeqBefore, nSeqNow, count1, nSeqTruth;
759  int startTimeBin, length, status;
760  StSequence* Sequence;
761  StMCTruth* SeqTruth;
762  unsigned char* adc;
763  //int ExtraBefore=1;
764  //int ExtraAfter=3;
765  int ExtraBefore=0;
766  int ExtraAfter=0;
767 
768  int firstTimeBin;
769 
770  double tempBuffer = 0;
771 
772  nSeqNow = 0;
773  StSequence tempSeq1[128];
774  StMCTruth tempTru1[128];
775  status = mHybridAdjData->getListSequences(iAnode,nSeqBefore,Sequence);
776  status = mHybridRawData->getListTruth (iAnode,nSeqTruth ,SeqTruth );
777 
778  for(int Seq = 0; Seq < nSeqBefore; Seq++)
779  {
780  startTimeBin =Sequence[Seq].startTimeBin;
781  length = Sequence[Seq].length;
782  adc = Sequence[Seq].firstAdc;
783 
784  int j=0;
785  while( j < length)
786  {
787  count1 = 0;
788  tempBuffer = mInvProd->GetBuffer(startTimeBin + j);
789 
790  while(tempBuffer > m_inv_prod_lo && j < length)
791  {
792  ++count1;
793  ++j;
794  tempBuffer = mInvProd->GetBuffer(startTimeBin + j);
795  }
796  if(count1 > 0 && (tempBuffer < m_inv_prod_lo || j == length))
797  {
798  firstTimeBin = startTimeBin + j - count1 - ExtraBefore;
799 
800  tempSeq1[nSeqNow].firstAdc=&adc[j- count1 - ExtraBefore];
801  tempSeq1[nSeqNow].startTimeBin = firstTimeBin;
802  tempSeq1[nSeqNow].length = 0;
803  if((startTimeBin + j - count1 - ExtraBefore) < 0){
804  tempSeq1[nSeqNow].startTimeBin=0;
805  tempSeq1[nSeqNow].firstAdc=&adc[0];
806  // Make length temp. negative to account for the fact we went
807  //past the start of the sequence get adjusted properly in a bit
808  tempSeq1[nSeqNow].length = startTimeBin + j - count1 - ExtraBefore;
809  }
810 
811  if((startTimeBin + j - count1 - ExtraBefore) < startTimeBin){
812  tempSeq1[nSeqNow].startTimeBin=startTimeBin;
813  tempSeq1[nSeqNow].firstAdc=&adc[0];
814  // Make length temp. negative to account for the fact we went
815  //past the start of the sequence get adjusted properly in a bit
816  tempSeq1[nSeqNow].length = startTimeBin + j -
817  count1 - ExtraBefore -startTimeBin;
818  }
819 
820  // Make length proper size even if it went negative
821  tempSeq1[nSeqNow].length += count1+ ExtraAfter+ ExtraBefore;
822 
823  // Check dont go past end of sequence if do adjust length correctly
824  if( tempSeq1[nSeqNow].length + tempSeq1[nSeqNow].startTimeBin > 128)
825  tempSeq1[nSeqNow].length=128-tempSeq1[nSeqNow].startTimeBin +1;
826  if ( tempSeq1[nSeqNow].startTimeBin+ tempSeq1[nSeqNow].length >
827  startTimeBin +length){
828  tempSeq1[nSeqNow].length = (startTimeBin +length) -
829  tempSeq1[nSeqNow].startTimeBin ;
830  }
831  if(SeqTruth) tempTru1[nSeqNow] = SeqTruth[Seq];
832  nSeqNow++;
833 
834  }
835  j++;
836  }
837 
838  } // Sequence loop
839 
840 
841  if( nSeqBefore >0){
842  if (SeqTruth) SeqTruth = tempTru1;
843  mNumOfSeq = MergeSequences(tempSeq1, nSeqNow,SeqTruth);
844  mHybridAdjData->setListSequences(iAnode, Anode,mNumOfSeq, tempSeq1);
845  if (SeqTruth)
846  mHybridAdjData->setListTruth (iAnode, Anode,mNumOfSeq, tempTru1);
847  }
848  //cout << "For Anode=" << Anode << " Number of sequnces was=" << nSeqBefore << " Number now=" << nSeqNow << endl;
849 
850  return kStOK;
851 
852 }
853 //_____________________________________________________________________________
854 
855 Int_t StSvtSeqAdjMaker::MergeSequences( StSequence* seq, int nSeq, StMCTruth* tru){
856 
857  // Check and see if the end of one sequence overlaps the start of the next
858  // if it does merge sequences
859 
860  int nSeqNow = 0;
861  int EndTime;
862  StMCPivotTruth pivo(1);
863  if (tru) pivo.Add(tru[0]);
864  for( int i=1; i<nSeq; i++){
865 
866  if( (seq[nSeqNow].startTimeBin + seq[nSeqNow].length)
867  >= seq[i].startTimeBin){
868  EndTime = seq[i].startTimeBin + seq[i].length;
869  seq[nSeqNow].length = EndTime - seq[nSeqNow].startTimeBin;
870  if (tru) { pivo.Add(tru[i]); tru[nSeqNow] = pivo.Get();}
871 
872  }
873  else{
874  nSeqNow++;
875  seq[nSeqNow] = seq[i];
876  if (tru){ pivo.Reset(); pivo.Add(tru[i]);}
877  }
878 
879  }
880 
881  return nSeqNow+1;
882 }
883 //_____________________________________________________________________________
884 
885 void StSvtSeqAdjMaker::CommonModeNoiseCalc(int iAnode){
886 
887  // Calc common mode noise
888 
889  int nSeqOrig, length;
890  int startTimeBin, status;
891  StSequence* Sequence;
892  unsigned char* adc;
893 
894  //Anode is the index into the anolist array
895 
896  status= mHybridRawData->getListSequences(iAnode,nSeqOrig,Sequence);
897 
898  for( int nSeq=0; nSeq< nSeqOrig ; nSeq++){
899 
900  adc=Sequence[nSeq].firstAdc;
901  length = Sequence[nSeq].length;
902  startTimeBin=Sequence[nSeq].startTimeBin;
903 
904  int j =0;
905  while( j<length){
906 
907  mCommonModeNoise[j+startTimeBin] += (int)adc[j] - mPedOffSet;
908  mCommonModeNoiseAn[j+startTimeBin]++;
909  j++;
910 
911 
912  }
913  }
914  return;
915 }
916 //_____________________________________________________________________________
917 
918 void StSvtSeqAdjMaker::CommonModeNoiseSub(int iAnode){
919 
920  // Calc common mode noise
921 
922  int nSeqOrig, length;
923  int startTimeBin, status;
924  StSequence* Sequence;
925  unsigned char* adc;
926 
927  //Anode is the index into the anolist array
928 
929  status= mHybridRawData->getListSequences(iAnode,nSeqOrig,Sequence);
930 
931  for( int nSeq=0; nSeq< nSeqOrig ; nSeq++){
932 
933  adc=Sequence[nSeq].firstAdc;
934  length = Sequence[nSeq].length;
935  startTimeBin=Sequence[nSeq].startTimeBin;
936 
937  int j =0;
938  while( j<length){
939  if( (int) adc[j]-mCommonModeNoise[j+startTimeBin] < 0) adc[j]=0;
940  else{
941  adc[j] -=mCommonModeNoise[j+startTimeBin];
942  }
943  j++;
944  }
945  }
946  return;
947 }
948 
949 //_____________________________________________________________________________
950 
951 void StSvtSeqAdjMaker::SubtractFirstAnode(int iAnode){
952 
953  // Calc common mode noise
954 
955  int nSeq, nSeqOrig, length;
956  int startTimeBin, status, j;
957  int adcMean;
958  StSequence* Sequence;
959  unsigned char* adc;
960 
961 
962  status= mHybridRawData->getListSequences(iAnode,nSeqOrig,Sequence);
963 
964  adcMean = 0;
965  for( nSeq=0; nSeq< nSeqOrig ; nSeq++){
966 
967  adc=Sequence[nSeq].firstAdc;
968  length = Sequence[nSeq].length;
969  startTimeBin=Sequence[nSeq].startTimeBin;
970  j =0;
971  while( j<length){
972 
973  if( mNAnodes) adcMean = adcCommon[j+startTimeBin]/mNAnodes;
974 
975  //cout << "iAnode = " << iAnode << "ADC value is: " << (int) adc[j] << " for time = " << startTimeBin + j << " and ADCMean = "<< adcMean << " mNAnodes = " << mNAnodes <<endl;
976  if( (int)adc[j]- adcMean < 0) adc[j]=0;
977  else if( adcMean < 0){
978  adc[j] += (unsigned char)(-1*adcMean);
979  }
980  else{
981  adc[j] -= (unsigned char)adcMean;
982  }
983  //cout << "Final ADC= " << (int)adc[j] << endl;
984  j++;
985  }
986  }
987  return;
988 }
989 //____________________________________________________________________________
990 
991 int StSvtSeqAdjMaker::FindBlackAnodes(){
992  // Decide whether to do common mode noise from average timebucket
993  //value or via first two black anodes.Have many options andoes 1&240,
994  //1&2 or 2&239. IN some case one of the black anodes is bad so only
995  //subtract one.
996  int status, length;
997  int i, j, startTimeBin;
998  int nSequence = 0;
999  StSequence* Seq = NULL;
1000  unsigned char *adc;
1001 
1002  doCommon = 0;
1003  mNAnodes=2;
1004  int adcAv=0;
1005 
1006  status= mHybridRawData->getSequences(240,nSequence,Seq);
1007  length = 0;
1008  for(j=0; j<128; j++) adcCommon[j]=0;
1009  for( i=0; i<nSequence; i++) length += Seq[i].length;
1010  if( length < 126){
1011  // IF anode 240 isnt black try 239
1012  status= mHybridRawData->getSequences(239,nSequence,Seq);
1013  length = 0;
1014 
1015  for( i=0; i<nSequence; i++) length += Seq[i].length;
1016  if( length < 126){
1017  //if that one isnt black either try 2
1018  status= mHybridRawData->getSequences(2,nSequence,Seq);
1019  length = 0;
1020 
1021  for( i=0; i<nSequence; i++) length += Seq[i].length;
1022  if( length < 126){
1023  // If that isnt black too do common mode noise subtraction
1024  doCommon =1;
1025  }
1026  }
1027  }
1028 
1029  // If one of those anodes was black fill adc array
1030  if( !doCommon){
1031 
1032  // Fill in array of adc values of first anode
1033  for( int nSeq=0; nSeq< nSequence ; nSeq++){
1034 
1035  adc=Seq[nSeq].firstAdc;
1036  length = Seq[nSeq].length;
1037  startTimeBin=Seq[nSeq].startTimeBin;
1038  j=0;
1039  while( j<length){
1040  adcCommon[startTimeBin+j] = adc[j]-mPedOffSet;
1041  adcAv += (int) adc[j];
1042  j++;
1043  }
1044  }
1045  // If this black anode was bad dont count it in subtraction
1046  if( adcAv <100 || adcAv> 25000) {
1047  mNAnodes--;
1048  for(j=0; j<128; j++) adcCommon[j]=0;
1049  }
1050  }
1051 
1052  // now find second black anode
1053 
1054  status= mHybridRawData->getSequences(2,nSequence,Seq);
1055  length = 0;
1056 
1057  for( i=0; i<nSequence; i++) length += Seq[i].length;
1058  if( length < 126){
1059  status= mHybridRawData->getSequences(1,nSequence,Seq);
1060  length = 0;
1061 
1062  for( i=0; i<nSequence; i++) length += Seq[i].length;
1063  if( length < 126){
1064  doCommon=1;
1065  }
1066 
1067  }
1068  if( !doCommon){
1069  // Fill in array of adc values of second anode
1070  adcAv=0;
1071  for( int nSeq=0; nSeq< nSequence ; nSeq++){
1072 
1073  adc=Seq[nSeq].firstAdc;
1074  length = Seq[nSeq].length;
1075  startTimeBin=Seq[nSeq].startTimeBin;
1076  j=0;
1077  while( j<length){
1078  adcCommon[startTimeBin+j] += adc[j]-mPedOffSet;
1079  adcAv += (int) adc[j];
1080  j++;
1081  }
1082  }
1083 
1084  if( adcAv <100 || adcAv> 25000) {
1085  mNAnodes--;
1086  // If black anode is bad subtract back of wrong adc values
1087  // from average will subtract from all other anodes
1088  if( mNAnodes){
1089  for( int nSeq=0; nSeq< nSequence ; nSeq++){
1090 
1091  adc=Seq[nSeq].firstAdc;
1092  length = Seq[nSeq].length;
1093  startTimeBin=Seq[nSeq].startTimeBin;
1094  j=0;
1095  while( j<length){
1096  adcCommon[startTimeBin+j] -= adc[j]-mPedOffSet;
1097  adcAv += (int) adc[j];
1098  j++;
1099  }
1100  }
1101  }
1102  }
1103  }
1104  return mNAnodes;
1105 }
1106 
1107 //_____________________________________________________________________________
1108 void StSvtSeqAdjMaker::MakeHistogramsAdc(StSvtHybridData* hybridData, int index, int Anode, int Count){
1109 
1110  // Count is 1 for before CM-Noise subtraction and 2 for after CMN subtraction.
1111  int mSequence;
1112  int len,status;
1113  unsigned char* adc;
1114 
1115  StSequence* svtSequence;
1116  mSequence = 0;
1117  svtSequence = NULL;
1118 
1119  // Anode goes between 1-240
1120 
1121  status = hybridData->getSequences(Anode,mSequence,svtSequence);
1122 
1123  int numOfPixels=0;
1124  for(int mSeq = 0; mSeq < mSequence; mSeq++)
1125  {
1126  adc = svtSequence[mSeq].firstAdc;
1127  len = svtSequence[mSeq].length;
1128  if (len>12) continue;
1129  for(int j = 0 ; j < len; j++){
1130  mRawAdc[index]->Fill(Anode,(int)adc[j]);
1131  //mTimeAn[index]->Fill(Anode,j+svtSequence[mSeq].startTimeBin,(int)adc[j]);
1132  mAdcAfter[index]->Fill(Anode);
1133  //cout << "Index= " << index << " Anode " << Anode << " " << (int)adc[j] - mPedOffSet << " count= " << Evt_counts <<endl;
1134  if (adc[j] >0) numOfPixels++;
1135  if (adc[j] >0) Evt_counts++;
1136  }
1137  }
1138  mOcupancyHisto->Fill(numOfPixels);
1139 }
1140 
1141 //_____________________________________________________________________________
1142 Int_t StSvtSeqAdjMaker::Reset(){
1143 
1144  //delete mInvProd;
1145  //delete mProbValue;
1146 
1147  mSvtDataSet = NULL;
1148  mSvtAdjData = NULL;
1149  mSvtRawData = NULL;
1150  mHybridRawData = NULL;
1151  mHybridAdjData = NULL;
1152  mSvtPedSub = NULL;
1153  mSvtPedColl = NULL;
1154  mSvtBadAnodes = NULL;
1155  mInvProd = NULL;
1156  mProbValue = NULL;
1157 
1158  return kStOK;
1159 }
1160 //_____________________________________________________________________________
1161 string StSvtSeqAdjMaker::baseName(string s){
1162 
1163  string name(s);
1164  size_t pos;
1165  pos = name.find_last_of("/");
1166  if (pos!=string::npos ) name.erase(0, pos );
1167  pos = name.find_first_of(".");
1168  if (pos!=string::npos ) name.erase(pos,name.length()-pos );
1169  return name;
1170 }
1171 //_____________________________________________________________________________
1172 string StSvtSeqAdjMaker::buildFileName(string dir, string fileName, string extention){
1173 
1174  fileName = dir + fileName + extention;
1175  while (fileName.find("//")!=string::npos) {
1176  int pos = fileName.find("//");
1177  fileName.erase(pos,1);
1178  }
1179  return fileName;
1180 }
1181 //_____________________________________________________________________________
1183 
1184 
1185  if (Debug()) gMessMgr->Debug() << "In StSvtSeqAdjMaker::Finish() "
1186  << GetName() << endm;
1187 
1188  if ( hfile ){
1189  hfile->Write();
1190  hfile->Close();
1191  }
1192 
1193  return kStOK;
1194 }
1195 
1196 //_____________________________________________________________________________
1197 ClassImp(StSvtSeqAdjMaker)
virtual void AddData(TDataSet *data, const char *dir=".data")
User methods.
Definition: StMaker.cxx:332
virtual Int_t Make()
virtual void SetObject(TObject *obj)
The depricated method (left here for the sake of the backward compatibility)
Definition: TObjectSet.h:59
virtual TObject * GetObject() const
The depricated method (left here for the sake of the backward compatibility)
Definition: TDataSet.cxx:428
virtual const char * GetName() const
special overload
Definition: StMaker.cxx:237
Definition: Stypes.h:42
Definition: Stypes.h:40
virtual Int_t GetRunNumber() const
Returns the current RunNumber.
Definition: StMaker.cxx:1054
virtual Int_t Finish()