StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StETofQAMaker.cxx
1 /***************************************************************************
2  *
3  * $Id: StETofQAMaker.cxx,v 1.1 2018/07/25 14:38:06 jeromel Exp $
4  *
5  * Author: Philipp Weidenkaff & Pengfei Lyu, May 2018
6  ***************************************************************************
7  *
8  * Description: StETofQAMaker - class to read the eTofCollection from
9  * StEvent build QA histograms.
10  *
11  ***************************************************************************
12  *
13  * $Log: StETofQAMaker.cxx,v $
14  * Revision 1.1 2018/07/25 14:38:06 jeromel
15  * Peer reviewed Raghav+Jerome - code from Florian Seck
16  *
17  *
18  ***************************************************************************/
19 #include <vector>
20 #include <algorithm>
21 #include <cmath>
22 
23 #include "TFile.h"
24 #include "TH2.h"
25 
26 #include "StChain/StChainOpt.h" // for renaming the histogram file
27 
28 #include "StEvent/StEvent.h"
29 
30 #include "StEvent/StETofCollection.h"
31 #include "StEvent/StETofDigi.h"
32 #include "StEvent/StETofHit.h"
33 
34 #include "StEvent/StBTofCollection.h"
35 #include "StEvent/StBTofHit.h"
36 #include "StEvent/StBTofHeader.h"
37 
38 #include "StETofQAMaker.h"
39 
40 
41 const Int_t uNbSectors = 12;
42 const Int_t uNbZPlanes = 3;
43 const Int_t uNbDetPerModule = 3;
44 const Int_t uNbStripsPerDet = 32;
45 
46 const Double_t dStripPitch = 1.0; //[cm]
47 
48 const Double_t dBTofTimeRange = 51200; //[ns]
49 
50 const Double_t dCoarseClockCycleNs = 6.25; //[ns]
51 
52 //const Double_t dETofTrigOffset = 1958; //[ns] // run 42
53 const Double_t dETofTrigOffset = -9047; //[ns] // run 44
54 
55 
56 //_____________________________________________________________
57 StETofQAMaker::StETofQAMaker( const char* name )
58 : StMaker( "etofQa", name ),
59  mEvent( 0 ),
60  mETofCollection( 0 ),
61  mBTofCollection( 0 ),
62  mTStart( 0 ),
63  mOutHistFileName( "" ),
64  mTimeOffset( 0 )
65 {
66  LOG_DEBUG << "StETofQAMaker::ctor" << endm;
67 }
68 
69 //_____________________________________________________________
70 StETofQAMaker::~StETofQAMaker()
71 { /* no op */
72 
73 }
74 
75 //_____________________________________________________________
83 {
85  StETofCollection* etofCollection = 0;
86  mEvent = dynamic_cast< StEvent* > ( GetInputDS( "StEvent" ) );
87 
88  if ( mEvent ) {
89  etofCollection = mEvent->etofCollection();
90 
93  if ( !etofCollection ) {
95  LOG_INFO << "StETofQAMaker::GetETofCollection - making new StETofCollection and giving it to StEvent" << endm;
96  etofCollection = new StETofCollection();
97  mEvent->setETofCollection( etofCollection );
98  }
99  else {
100  LOG_INFO << "StETofQAMaker::GetETofCollection - StEvent already has a StETofCollection - not making a new one" << endm;
101  }
102  }
103  else {
104  LOG_WARN << "No StEvent found by StETofQAMaker::GetETofCollection" << endm;
105  }
106 
107  return etofCollection;
108 }
109 
110 //_____________________________________________________________
118 {
120  StBTofCollection* btofCollection = 0;
121  mEvent = dynamic_cast< StEvent* > ( GetInputDS( "StEvent" ) );
122 
123  if ( mEvent ) {
124  btofCollection = mEvent->btofCollection();
125 
128  if ( !btofCollection ) {
130  LOG_INFO << "StETofQAMaker::GetBTofCollection - no BTofCollection found!" << endm;
131  btofCollection = new StBTofCollection();
132  mEvent->setBTofCollection( btofCollection );
133  }
134  else {
135  LOG_INFO << "StETofQAMaker::GetBTofCollection - StEvent already has a StBTofCollection - not making a new one" << endm;
136  }
137  }
138  else {
139  LOG_WARN << "No StEvent found by StETofQAMaker::GetBTofCollection" << endm;
140  }
141 
142  return btofCollection;
143 }
144 
145 //_____________________________________________________________
146 Int_t
147 StETofQAMaker::Init()
148 {
149  //Setting up storage
150  mStorStDigi.clear();
151  mStorStDigi.resize( uNbSectors ); //number of sectors
152  mStorStHit.clear();
153  mStorStHit.resize( uNbSectors );
154 
155  for( Int_t iSector = 0; iSector < uNbSectors; iSector++ ) {
156  mStorStDigi[ iSector ].resize( uNbZPlanes ); //number of ZPlanes
157  mStorStHit[ iSector ].resize( uNbZPlanes );
158 
159  for( Int_t iPlane = 0; iPlane < uNbZPlanes; iPlane++ ) {
160  mStorStDigi[ iSector ][ iPlane ].resize( uNbDetPerModule ); //number of Detectors
161  mStorStHit[ iSector ][ iPlane ].resize( uNbDetPerModule );
162  //detectors resized when filled
163 
164  for( Int_t iDet = 0; iDet < uNbDetPerModule; iDet++ ) {
165  mStorStDigi[ iSector ][ iPlane ][ iDet ].resize( uNbStripsPerDet ); //number of Strips
166  LOG_DEBUG << "StETofQAMaker::Init::Detectors" << endm;
167  }
168  }
169  }
170 
171  //TODO: Add Null-pointer handling for collection
172  LOG_INFO << "StETofQAMaker::Init" << endm;
173 
174  createHistos();
175 
176  return kStOk;
177 }
178 
179 
180 //_____________________________________________________________
181 Int_t
182 StETofQAMaker::InitRun( Int_t runnumber )
183 {
184  return kStOk;
185 }
186 
187 //_____________________________________________________________
188 Int_t
189 StETofQAMaker::FinishRun( Int_t runnumber )
190 {
191  return kStOk;
192 }
193 
194 //_____________________________________________________________
195 Int_t
197 {
198  writeHistos();
199 
200  return kStOk;
201 }
202 
203 //_____________________________________________________________
204 Int_t
206 {
207  LOG_INFO << "StETofQAMaker::Make(): starting..." << endm;
208 
209  //---------------------------------
210  mETofCollection = GetETofCollection();
211  LOG_INFO << "StETofQAMaker::Make() - getting the eTOF collection " << mETofCollection << endm;
212  LOG_INFO << "StETofQAMaker::Make() - nDigis = " << ( mETofCollection->etofDigis() ).size() << endm;
213  LOG_INFO << "StETofQAMaker::Make() - nHits = " << ( mETofCollection->etofHits() ).size() << endm;
214  //---------------------------------
215 
216  //---------------------------------
217  mBTofCollection = GetBTofCollection();
218  LOG_INFO << "StETofQAMaker::Make() - getting the bTOF collection " << mBTofCollection << endm;
219  LOG_INFO << "StETofQAMaker::Make() - nHits = " << ( mBTofCollection->tofHits() ).size() << endm;
220  //---------------------------------
221 
222  calcTStart();
223 
224  fillHistos();
225 
226  return kStOk;
227 }
228 
229 //_____________________________________________________________
230 void
231 StETofQAMaker::calcTStart()
232 {
233  LOG_INFO << "StETofQAMaker::calcTStart(): -- loading Vpd data from bTof header" << endm;
234 
235  if( !mBTofCollection ) return;
236 
237  StBTofHeader* bTofHeader = mBTofCollection->tofHeader();
238 
239  if( !bTofHeader ) {
240  LOG_INFO << "StETofQAMaker::calcTStart(): -- no bTof header. Skip start time calculation." << endm;
241  return;
242  }
243 
244 
245  const int nVpd = 19; // number of VPD tubes on each side of STAR
246 
247  double tSumWest = 0.;
248  double tSumEast = 0.;
249 
250  int nWest = bTofHeader->numberOfVpdHits( west );
251  int nEast = bTofHeader->numberOfVpdHits( east );
252 
253  double vpdLeTime[ 2 * nVpd ];
254 
255  // check if bTof header is filled with useful information
256  if( fabs( bTofHeader->vpdVz() - ( -9999. ) ) < 0.1 ) {
257  LOG_INFO << " no valid Vpd data in the bTOF header " << endm;
258  return;
259  }
260  else {
261  LOG_INFO << "Vpd Vertex is at: " << bTofHeader->vpdVz() << endm;
262  }
263 
264  // west side
265  for( int i=0; i< nVpd; i++ ) {
266  vpdLeTime[ i ] = bTofHeader->vpdTime( west, i+1 );
267  if( vpdLeTime[ i ] > 0. ) {
268  tSumWest += vpdLeTime[ i ];
269  LOG_INFO << " loading VPD west tubeId = " << i+1 << " time " << vpdLeTime[ i ] << endm;
270  }
271  }
272 
273  // east side
274  for( int i=0; i< nVpd; i++ ) {
275  vpdLeTime[ i + nVpd ] = bTofHeader->vpdTime( east, i+1 );
276  if( vpdLeTime[ i + nVpd ] > 0. ) {
277  tSumEast += vpdLeTime[ i + nVpd ];
278  LOG_INFO << " loading VPD east tubeId = " << i+1 << " time " << vpdLeTime[ i + nVpd ] << endm;
279  }
280  }
281 
282 
283  LOG_INFO << "StETofQAMaker::calcTStart(): -- calculating Vpd start time" << endm;
284 
285  double tSum = tSumWest + tSumEast;
286 
287  if( nWest + nEast ) {
288  mTStart = tSum / ( nWest + nEast );
289  }
290  LOG_INFO << "StETofQAMaker::calcTStart(): -- Vpd start time: " << mTStart << endm;
291 
292  return;
293 }
294 
295 //_____________________________________________________________
296 void
297 StETofQAMaker::createHistos()
298 {
299  mHistRpcCluSize.clear(); //Clustersize distribution for each strip of the detector
300  mHistRpcCluSize.resize( uNbSectors );
301 
302  mHistRpcCluPosition.clear(); //Position distribution of the clusters in the X-Y plane of the detector
303  mHistRpcCluPosition.resize( uNbSectors );
304 
305  mHistRpcCluTOff.clear(); //Time offset distribution for each strip of the detector
306  mHistRpcCluTOff.resize( uNbSectors );
307 
308  mHistRpcCluTot.clear(); //TOT distribution for each strip of the detector
309  mHistRpcCluTot.resize( uNbSectors );
310 
311  mHistRpcDigiTot.clear(); //TOT distribution on digi level
312  mHistRpcDigiTot.resize( uNbSectors );
313 
314  mHistRpcCluAvWalk.clear(); //TOT versus detector arrival time minus event timezero
315  mHistRpcCluAvWalk.resize( uNbSectors );
316 
317  mHistRpcCluMul.clear(); //Multiplicity distribution in each event on the detector
318  mHistRpcCluMul.resize( uNbSectors );
319 
320  mHistHitTrigTimeDet.clear();
321  mHistHitTrigTimeDet.resize( uNbSectors );
322 
323  mHistBTofAvTimeDiff = new TH1F(
324  Form( "Av_TDiff_ETof_BTof" ),
325  Form( "Difference between average hits times in Events between BTof and ETof; dT [ns]; Events []" ),
326  102400, -51200, 51200 );
327 
328  mHistHitTrigTimeDiff= new TH1F(
329  Form( "Hit_TDiff_ETof_Trg" ),
330  Form( "Difference between hits on ETof and the trigger token; dT [ns]; Events []" ),
331  10240, -51200, 51200 );
332 
333  mHistDigiTrigTimeDiff= new TH1F(
334  Form( "Digi_TDiff_ETof_Trg" ),
335  Form( "Difference between Digis on ETof and the trigger token; dT [ns]; Events []" ),
336  10240, -51200, 51200 );
337 
338  mHistDigiRawTrigTimeDiff= new TH1F(
339  Form( "DigiRaw_TDiff_ETof_Trg" ),
340  Form( "Raw time difference between Digis on ETof and the trigger token; dT [ns]; Events []" ),
341  10240, -51200, 51200 );
342 
343  mHistBTofETofMul = new TH2F(
344  Form( "Mul_ETof_BTof" ),
345  Form( "Multiplicity correlation between ETof and BTof; ETof Multiplicity []; BTof Multiplicity []" ),
346  51, -0.5, 50.5,
347  101, -0.5, 500.5 );
348 
349  mHistBTofAvTimeDiffvETofMul= new TH2F(
350  Form( "Av_TDiff_v_Mul_ETof" ),
351  Form( "Difference between average hits times in Events between BTof and ETof vs ETof multiplicity; dT [ns]; ETof Multiplicity []" ),
352  10240, -51200, 51200,
353  51, -0.5, 50.5 );
354 
355  mHistBTofAvTimeDiffvBTofMul= new TH2F(
356  Form( "Av_TDiff_v_Mul_BTof" ),
357  Form( "Difference between average hits times in Events between BTof and ETof vs ETof multiplicity; dT [ns]; BTof Multiplicity []" ),
358  10240, -51200, 51200,
359  101, -0.5, 500.5 );
360 
361 
362  mHistETofTimeOfFlight = new TH1F( "ETof_Time_of_Flight", "time of flight for eTof hits; Tof [ns]; # ETof hits", 1000, 300, 600 );
363  mHistBTofTimeOfFlight = new TH1F( "BTof_Time_of_Flight", "time of flight for bTof hits; Tof [ns]; # BTof hits", 1000, -150, 150 );
364 
365 
366 
367  for( Int_t iSector = 0; iSector < uNbSectors; iSector++ ) {
368  mHistRpcCluSize[ iSector ].resize( uNbZPlanes ); //number of ZPlanes
369  mHistRpcCluPosition[ iSector ].resize( uNbZPlanes );
370  mHistRpcCluTOff[ iSector ].resize( uNbZPlanes );
371  mHistRpcCluTot[ iSector ].resize( uNbZPlanes );
372  mHistRpcDigiTot[ iSector ].resize( uNbZPlanes );
373  mHistRpcCluAvWalk[ iSector ].resize( uNbZPlanes );
374  mHistRpcCluMul[ iSector ].resize( uNbZPlanes );
375  mHistHitTrigTimeDet[ iSector ].resize( uNbSectors );
376 
377  for( Int_t iPlane = 0; iPlane < uNbZPlanes; iPlane++ ) {
378  mHistRpcCluSize[ iSector ][ iPlane ].resize( uNbDetPerModule ); //number of Detectors
379  mHistRpcCluPosition[ iSector ][ iPlane ].resize( uNbDetPerModule );
380  mHistRpcCluTOff[ iSector ][ iPlane ].resize( uNbDetPerModule );
381  mHistRpcCluTot[ iSector ][ iPlane ].resize( uNbDetPerModule );
382  mHistRpcDigiTot[ iSector ][ iPlane ].resize( uNbDetPerModule );
383  mHistRpcCluAvWalk[ iSector ][ iPlane ].resize( uNbDetPerModule );
384  mHistRpcCluMul[ iSector ][ iPlane ].resize( uNbDetPerModule );
385  mHistHitTrigTimeDet[ iSector ][ iPlane ].resize( uNbSectors );
386 
387  for( Int_t iDet = 0; iDet < uNbDetPerModule; iDet++ ) {
388  Double_t tSumMax=2;
389 
390  mHistRpcCluSize[ iSector ][ iPlane ][ iDet ] = new TH2F(
391  Form( "cl_Sector%02d_ZPlane%d_Det%d_Size", iSector+13, iPlane, iDet ),
392  Form( "Cluster size of Det #%02d in ZPlane %d under Sector %02d; Strip []; size [strips]", iDet, iPlane, iSector+13 ),
393  32, 0, 32, 16, 0.5, 16.5 );
394 
395  mHistRpcCluPosition[ iSector ][ iPlane ][ iDet ] = new TH2F(
396  Form( "cl_Sector%02d_ZPlane%d_Det%d_Pos", iSector+13, iPlane, iDet ),
397  Form( "Cluster position of of Det #%02d in ZPlane %d under Sector %02d; Strip []; ypos [cm]", iDet, iPlane, iSector+13 ),
398  32, 0, 32, 100, -50, 50 );
399 
400  mHistRpcCluTOff[ iSector ][ iPlane ][ iDet ] = new TH2F(
401  Form( "cl_Sector%02d_ZPlane%d_Det%d_TOff", iSector+13, iPlane, iDet ),
402  Form( "Cluster timezero of Det #%02d in ZPlane %d under Sector %02d; Strip []; TOff [ns]", iDet, iPlane, iSector+13 ),
403  32, 0, 32, 100, -tSumMax, tSumMax );
404 
405  mHistRpcCluTot[ iSector ][ iPlane ][ iDet ] = new TH2F(
406  Form( "cl_Sector%02d_ZPlane%d_Det%d_Tot", iSector+13, iPlane, iDet ),
407  Form( "Total Cluster Tot of Det #%02d in ZPlane %d under Sector %02d; Strip []; TOT [ns]", iDet, iPlane, iSector+13 ),
408  32, 0, 32, 100, 0, 100 );
409 
410  mHistRpcDigiTot[ iSector ][ iPlane ][ iDet ] = new TH2F(
411  Form( "cl_Sector%02d_ZPlane%d_Det%d_TotDigi", iSector+13, iPlane, iDet ),
412  Form( "Total Digi Tot of Det #%02d in ZPlane %d under Sector %02d; Chan []; TOT [ns]", iDet, iPlane, iSector+13 ),
413  64, 0, 64, 50, 0, 20 );
414 
415  mHistRpcCluAvWalk[ iSector ][ iPlane ][ iDet ] = new TH2F(
416  Form( "cl_Sector%02d_ZPlane%d_Det%d_AvWalk", iSector+13, iPlane, iDet ),
417  Form( "Walk in Det #%02d in ZPlane %d under Sector %02d; cluster TOT; T-TSel", iDet, iPlane, iSector+13 ),
418  25, 0, 10, 400, -tSumMax, tSumMax );
419 
420  mHistRpcCluMul[ iSector ][ iPlane ][ iDet ] = new TH1F(
421  Form( "cl_Sector%02d_ZPlane%d_Det%d_Mul", iSector+13, iPlane, iDet ),
422  Form( "Cluster multiplicity of Det #%02d in ZPlane %d under Sector %02d; Mul []; cnts", iDet, iPlane, iSector+13 ),
423  32, 0, 32 );
424 
425  mHistHitTrigTimeDet[ iSector ][ iPlane ][ iDet ] = new TH1F(
426  Form( "Hit_TDiff_Trg_Sector%02d_ZPlane%d_Det%d_Mul", iSector+13, iPlane, iDet ),
427  Form( "Difference between hits on Det #%02d in ZPlane %d under Sector %02d and the trigger token; dT [ns]; Events []", iDet, iPlane, iSector+13 ),
428  10240, -51200, 51200 );
429 
430  LOG_DEBUG << "StETofQAMaker::Init() - createHistos: successfully created histograms for detector " << iSector+13 << iPlane << iDet << endm; //PW
431  }
432  }
433  }
434 
435  return;
436 }//::createHistos
437 
438 //_____________________________________________________________
439 void
440 StETofQAMaker::fillHistos()
441 {
442  LOG_INFO << "StETofQAMaker::fillHistos(): -- filling histograms for calibration and QA" << endm;
443 
444  mTimeOffset = 0; //reset time offset for each event
445 
446  //calculate trigger on calib time scale
447  StETofHeader* etofHeader = mETofCollection->etofHeader();
448 
449  if( !etofHeader ) {
450  LOG_WARN << "StETofQAMaker::fillHistos(): -- no eTof Header available -> skip event." << endm;
451  return;
452  }
453 
454  // skip event if it has no reset time of AFCK 0x18e6
455  if( etofHeader->rocStarTs().count( 0x18e6 ) == 0 ) {
456  LOG_WARN << "StETofQAMaker::fillHistos(): -- no reset time for AFCK 0x18e6 available -> skip event." << endm;
457  return;
458  }
459 
460  double triggerTime = etofHeader->trgGdpbFullTime() - ( etofHeader->rocStarTs().at( 0x18e6 ) * dCoarseClockCycleNs );//using the only working reset time in 2018 for now
461 
462  uint64_t iBTofOverflows = ( uint64_t ) ( triggerTime / dBTofTimeRange );
463 
464  triggerTime-= iBTofOverflows*dBTofTimeRange;
465  LOG_INFO << "corrected trigger time: "<< triggerTime <<" ns" << endm;
466 
467  double avEtofTime = 0;
468  double avBtofTime = 0;
469  StSPtrVecBTofHit bTofHits = 0;
470  Int_t nHitsInTrigWindow = 0;
471 
472  mTimeOffset = 0; //reset time offset for each event
473 
474  for( Int_t iSector = 0; iSector < uNbSectors; iSector++ ) {
475 
476  for( Int_t iPlane = 0; iPlane < uNbZPlanes; iPlane++ ) {
477 
478  for( Int_t iDet = 0; iDet < uNbDetPerModule; iDet++ ) {
479  mStorStHit[ iSector ][ iPlane ][ iDet ].clear();
480  mStorStHit[ iSector ][ iPlane ][ iDet ].resize( 0 ); //just to be sure
481 
482  for( Int_t iStrip = 0; iStrip < uNbStripsPerDet; iStrip++ ) {
483  mStorStDigi[ iSector ][ iPlane ][ iDet ][ iStrip ].clear();
484  mStorStDigi[ iSector ][ iPlane ][ iDet ][ iStrip ].resize( 0 );
485  }
486  }
487  }
488  }
489 
490 
491  //fillStorage
492  StSPtrVecETofDigi digis = mETofCollection->etofDigis();
493  Int_t nbDigis = digis.size();
494  Int_t nbDigisInStor = 0;
495 
496  StETofDigi* pDigi;
497  for( Int_t iDigiPos = 0; iDigiPos < nbDigis; iDigiPos++ ) {
498  //sort digis by logical address
499  pDigi = digis[ iDigiPos ];
500 
501  if ( pDigi->calibTime() == 0 && pDigi->calibTot() == -1 ) {
502  LOG_DEBUG << "StETofQAMaker::fillHistos(): -- digi not calibrated, most likely since it is outside the trigger window. Ignore." << endm;
503  continue;
504  }
505 
506  if( pDigi->sector() == 0 || pDigi->zPlane() == 0 || pDigi->counter() == 0 || pDigi->strip() == 0 ) {
507  LOG_WARN << "StETofQAMaker::fillHistos(): -- sector / zPlane / counter / strip was not assigned to the digi" << endm;
508  continue;
509  }
510 
511  mStorStDigi[ pDigi->sector() - 13 ]
512  [ pDigi->zPlane() - 1 ]
513  [ pDigi->counter() - 1 ]
514  [ pDigi->strip() - 1 ].push_back( pDigi );
515 
516  nbDigisInStor++;
517  }
518 
519  LOG_INFO << "storage vector is filled with " << nbDigisInStor << " digis" << endm;
520 
521 
522  StSPtrVecETofHit hits = mETofCollection->etofHits();
523  Int_t nbHits = hits.size();
524  Int_t nbHitsInStor = 0;
525 
526  StETofHit* pHit;
527  for( Int_t iHitPos = 0; iHitPos < nbHits; iHitPos++ ) {
528  pHit = hits[ iHitPos ];
529 
530  if( pHit->sector() == 0 || pHit->zPlane() == 0 || pHit->counter() == 0 ) {
531  LOG_ERROR << "StETofQAMaker::fillHistos(): -- sector / zPlane / counter was not assigned to the hit -- something is wrong!" << endm;
532  continue;
533  }
534 
535  mStorStHit[ pHit->sector() - 13 ]
536  [ pHit->zPlane() - 1 ]
537  [ pHit->counter() - 1 ].push_back( pHit );
538 
539  nbHitsInStor++;
540  }
541 
542  LOG_INFO << "storage vector is filled with "<< nbHitsInStor <<" hits" << endm;
543 
544  for( Int_t iSector = 0; iSector < uNbSectors; iSector++ ) {
545  for( Int_t iPlane = 0; iPlane < uNbZPlanes; iPlane++ ) {
546  for( Int_t iDet = 0; iDet < uNbDetPerModule; iDet++ ) {
547 
548  if( mStorStHit[ iSector ][ iPlane ][ iDet ].size() > 0 ) {
549  LOG_DEBUG << iSector + 13 << " " << iPlane + 1 << " " << iDet + 1 << " size mStorStHit: " << mStorStHit[ iSector ][ iPlane ][ iDet ].size() << endm;
550  mHistRpcCluMul[ iSector ][ iPlane ][ iDet ]->Fill( mStorStHit[ iSector ][ iPlane ][ iDet ].size() );
551 
552  for( unsigned int i = 0; i < mStorStHit[ iSector ][ iPlane ][ iDet ].size(); i++ ) {
553 
554  //added +(uNbStripsPerDet/2.0) to localX in order to recover strip number.
555  //localX has its origin at the center of the detector!
556 
557  if( mTimeOffset == 0 ) {
558  mTimeOffset = mStorStHit[iSector][iPlane][iDet].at(i)->time();
559  }
560  LOG_DEBUG << "The time offset is set to " << mTimeOffset << endm;
561 
562  mHistRpcCluSize[ iSector ][ iPlane ][ iDet ]->Fill( mStorStHit[ iSector ][ iPlane ][ iDet ].at( i )->localX() + ( uNbStripsPerDet / 2.0 ),
563  mStorStHit[ iSector ][ iPlane ][ iDet ].at( i )->clusterSize() );
564  mHistRpcCluPosition[ iSector ][ iPlane ][ iDet ]->Fill( mStorStHit[ iSector ][ iPlane ][ iDet ].at( i )->localX() + ( uNbStripsPerDet / 2.0 ),
565  mStorStHit[ iSector ][ iPlane ][ iDet ].at( i )->localY() );
566  mHistRpcCluTOff[ iSector ][ iPlane ][ iDet ]->Fill( mStorStHit[ iSector ][ iPlane ][ iDet ].at( i )->localX() + ( uNbStripsPerDet / 2.0 ),
567  mStorStHit[ iSector ][ iPlane ][ iDet ].at( i )->time() - mTimeOffset );
568  mHistRpcCluTot[ iSector ][ iPlane ][ iDet ]->Fill( mStorStHit[ iSector ][ iPlane ][ iDet ].at( i )->localX() + ( uNbStripsPerDet / 2.0 ),
569  mStorStHit[ iSector ][ iPlane ][ iDet ].at( i )->totalTot() );
570  mHistRpcCluAvWalk[ iSector ][ iPlane ][ iDet ]->Fill( mStorStHit[ iSector ][ iPlane ][ iDet ].at( i )->totalTot(),
571  mStorStHit[ iSector ][ iPlane ][ iDet ].at( i )->time() - mTimeOffset );
572 
573  mHistHitTrigTimeDiff->Fill( mStorStHit[ iSector ][ iPlane ][ iDet ].at( i )->time()-triggerTime );
574 
575  mHistHitTrigTimeDet[ iSector ][ iPlane ][ iDet ]->Fill( mStorStHit[ iSector ][ iPlane ][ iDet ].at( i )->time()-triggerTime ); //detector specific trigger plot
576 
577 
578  avEtofTime += mStorStHit[ iSector ][ iPlane ][ iDet ].at( i )->time();
579  nHitsInTrigWindow++;
580 
581  } //hit loop
582  }
583 
584  } //det loop
585  } //plane loop
586  } //sector loop
587 
588 
589  avEtofTime /= nHitsInTrigWindow;
590 
591  if( avEtofTime > 51200 ) { LOG_DEBUG << "Average ETof time out of range: "<< avEtofTime << endm; }
592 
593 
594  for( Int_t iSector = 0; iSector < uNbSectors; iSector++ ) {
595  for( Int_t iPlane = 0; iPlane < uNbZPlanes; iPlane++ ) {
596  for( Int_t iDet = 0; iDet < uNbDetPerModule; iDet++ ) {
597  for( Int_t iStrip = 0; iStrip < uNbStripsPerDet; iStrip++ ) {
598 
599  if( mStorStDigi[ iSector ][ iPlane ][ iDet ][ iStrip ].size() > 0 ) {
600  LOG_DEBUG << iSector+13 << " " << iPlane+1 << " " << iDet+1 << " " << iStrip+1 << " size mStorStDigi: " << mStorStDigi[ iSector ][ iPlane ][ iDet ][ iStrip ].size() << endm;
601 
602  for( unsigned int i=0; i<mStorStDigi[ iSector ][ iPlane ][ iDet ][ iStrip ].size(); i++ ) {
603  mHistRpcCluAvWalk[ iSector ][ iPlane ][ iDet ]->Fill( mStorStDigi[ iSector ][ iPlane ][ iDet ][ iStrip ].at( i )->calibTot(),
604  mStorStDigi[ iSector ][ iPlane ][ iDet ][ iStrip ].at( i )->calibTime() - mTimeOffset );
605  mHistRpcDigiTot[ iSector ][ iPlane ][ iDet ]->Fill( mStorStDigi[ iSector ][ iPlane ][ iDet ][ iStrip ].at( i )->strip() + 32 * ( mStorStDigi[ iSector ][ iPlane ][ iDet ][ iStrip ].at( i )->side() - 1 ) - 1,
606  mStorStDigi[ iSector ][ iPlane ][ iDet ][ iStrip ].at( i )->calibTot() );
607 
608  mHistDigiRawTrigTimeDiff->Fill( mStorStDigi[ iSector ][ iPlane ][ iDet ][ iStrip ].at( i )->rawTime() - ( etofHeader->trgGdpbFullTime() ) );
609 
610  mHistDigiTrigTimeDiff->Fill( mStorStDigi[ iSector ][ iPlane ][ iDet ][ iStrip ].at( i )->calibTime() - triggerTime );
611  //TODO: Timezero should be minus once available.
612 
613  } //digi loop
614  }
615  } //strip loop
616  } //det loop
617  } //plane loop
618  } //sector loop
619 
620 
621  if( mBTofCollection ) {
622  bTofHits = mBTofCollection->tofHits();
623 
624  if( bTofHits.size() && nbHits ) { //catch divisions by zero
625  for( UInt_t iHit = 0; iHit < bTofHits.size(); iHit++ ) {
626  avBtofTime += bTofHits[iHit]->leadingEdgeTime();
627  }
628  avBtofTime /= bTofHits.size();
629 
630  mHistBTofAvTimeDiff ->Fill( avEtofTime - avBtofTime );
631  mHistBTofAvTimeDiffvETofMul->Fill( avEtofTime - avBtofTime, nHitsInTrigWindow );
632  mHistBTofAvTimeDiffvBTofMul->Fill( avEtofTime - avBtofTime, bTofHits.size() );
633  mHistBTofETofMul ->Fill( nHitsInTrigWindow, bTofHits.size() );
634  }
635  }
636 
637 
638  // eTof hits
639  if( mETofCollection ) {
640  StSPtrVecETofHit eHits = mETofCollection->etofHits();
641  int nEHits = eHits.size();
642  for( int i = 0; i < nEHits; i++ ) {
643  if( mTStart ) {
644  float timeOfFlight = eHits[ i ]->time() - mTStart;
645  mHistETofTimeOfFlight->Fill( timeOfFlight );
646  //LOG_INFO << "eTof time of flight: " << timeOfFlight << endm;
647  }
648  }
649  }
650 
651 
652  // bTof hits
653  if( mBTofCollection ) {
654  StSPtrVecBTofHit bHits = mBTofCollection->tofHits();
655  int nBHits = bHits.size();
656  for( int i = 0; i < nBHits; i++ ) {
657  if( mTStart ) {
658  float timeOfFlight = bHits[ i ]->leadingEdgeTime() - mTStart;
659  mHistBTofTimeOfFlight->Fill( timeOfFlight );
660  //LOG_INFO << "bTof time of flight: " << timeOfFlight << endm;
661  }
662  }
663  }
664 
665 
666  return;
667 }//::fillHistos
668 
669 //_____________________________________________________________
670 void
671 StETofQAMaker::writeHistos()
672 {
673  std::string extension = ".etofQA.root";
674 
675  if( GetChainOpt()->GetFileOut() != nullptr ) {
676  TString outFile = GetChainOpt()->GetFileOut();
677 
678  mOutHistFileName = ( std::string ) outFile;
679 
680  // get rid of .root
681  size_t lastindex = mOutHistFileName.find_last_of( "." );
682  mOutHistFileName = mOutHistFileName.substr( 0, lastindex );
683 
684  // get rid of .MuDst or .event if necessary
685  lastindex = mOutHistFileName.find_last_of( "." );
686  mOutHistFileName = mOutHistFileName.substr( 0, lastindex );
687 
688  // get rid of directories
689  lastindex = mOutHistFileName.find_last_of( "/" );
690  mOutHistFileName = mOutHistFileName.substr( lastindex + 1, mOutHistFileName.length() );
691 
692  mOutHistFileName = mOutHistFileName + extension;
693  } else {
694  LOG_ERROR << "Cannot set the output filename for histograms" << endm;
695  }
696 
697  LOG_INFO << "StETofQAMaker::writeHistos -- creating file to save histograms" << endm;
698  TFile histFile( mOutHistFileName.c_str(), "RECREATE", "etofQA" );
699  histFile.cd();
700 
701  mHistBTofAvTimeDiff ->Write();
702  mHistHitTrigTimeDiff ->Write();
703  mHistDigiTrigTimeDiff ->Write();
704  mHistDigiRawTrigTimeDiff ->Write();
705  mHistBTofETofMul ->Write();
706  mHistBTofAvTimeDiffvETofMul->Write();
707  mHistBTofAvTimeDiffvBTofMul->Write();
708 
709  mHistETofTimeOfFlight ->Write();
710  mHistBTofTimeOfFlight ->Write();
711 
712  for( Int_t iSector = 0; iSector < uNbSectors; iSector++ ) {
713  for( Int_t iPlane = 0; iPlane < uNbZPlanes; iPlane++ ) {
714  for( Int_t iDet = 0; iDet < uNbDetPerModule; iDet++ ) {
715  mHistRpcCluSize[ iSector ][ iPlane ][ iDet ]->Write();
716  mHistRpcCluPosition[ iSector ][ iPlane ][ iDet ]->Write();
717  mHistRpcCluTOff[ iSector ][ iPlane ][ iDet ]->Write();
718  mHistRpcCluTot[ iSector ][ iPlane ][ iDet ]->Write();
719  mHistRpcDigiTot[ iSector ][ iPlane ][ iDet ]->Write();
720  mHistRpcCluAvWalk[ iSector ][ iPlane ][ iDet ]->Write();
721  mHistRpcCluMul[ iSector ][ iPlane ][ iDet ]->Write();
722  mHistHitTrigTimeDet[ iSector ][ iPlane ][ iDet ]->Write();
723  }
724  }
725  }
726 
727  histFile.Close();
728 
729  return;
730 }//::writeHistos
731 
732 //_____________________________________________________________
double calibTime() const
calibrated time
Definition: StETofDigi.h:206
StETofQAMaker(const char *name="etofQa")
Default constructor.
unsigned int zPlane() const
ZPlane.
Definition: StETofDigi.h:213
StBTofCollection * GetBTofCollection()
unsigned int sector() const
Sector.
Definition: StETofDigi.h:212
unsigned int strip() const
Strip.
Definition: StETofDigi.h:215
unsigned int counter() const
Counter.
Definition: StETofHit.h:191
unsigned int zPlane() const
ZPlane.
Definition: StETofHit.h:190
unsigned int sector() const
Sector.
Definition: StETofHit.h:189
unsigned int counter() const
Counter.
Definition: StETofDigi.h:214
double calibTot() const
Getter for calibrated Tot.
Definition: StETofDigi.h:210
StETofCollection * GetETofCollection()
Definition: Stypes.h:41