StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StEemcGammaFilterMaker.cxx
1 // $Id: StEemcGammaFilterMaker.cxx,v 1.4 2016/05/25 21:35:26 jwebb Exp $
2 
3 // STL
4 #include <vector>
5 
6 // ROOT Libraries
7 #include "TVector3.h"
8 
9 // StEvent Libraries
10 #include "StEvent.h"
11 
12 // StEvent Libraries
13 #include "StEventTypes.h"
14 
15 // StMcEvent Libraries
16 #include "StMcEvent/StMcCalorimeterHit.hh"
17 #include "StMcEvent/StMcEmcModuleHitCollection.hh"
18 #include "StMcEvent/StMcEmcHitCollection.hh"
19 #include "StMcEvent/StMcEvent.hh"
20 #include "StMcEvent/StMcVertex.hh"
21 
22 // StEmc Libraries
23 #include "StEmcClusterCollection.h"
24 #include "StEmcPoint.h"
25 #include "StEmcUtil/geometry/StEmcGeom.h"
26 #include "StEmcUtil/projection/StEmcPosition.h"
27 #include "StEmcUtil/others/emcDetectorName.h"
28 
29 // Endcap Libraries
30 #include "StEEmcUtil/EEmcGeom/EEmcGeomSimple.h"
31 #include "StEEmcSimulatorMaker/StEEmcFastMaker.h"
32 
33 // Class Header
34 #include "StEemcGammaFilterMaker.h"
35 
36 #include "tables/St_eemcGammaFilterMakerParams_Table.h"
37 
38 ClassImp(StEemcGammaFilterMaker)
39 
40 // Constructor //
43 StEemcGammaFilterMaker::StEemcGammaFilterMaker():StMaker("eemcGammaFilterMaker.1.00")
44 {
45 
46  LOG_DEBUG << "StEemcGammaFilterMaker()" << endm;
47 
48  // Set reasonable defaults
49 
50  mMaxVertex = 120.0;
51 
52  mSeedEnergyThreshold = 3.8; //2.8; //3.4;//2.8;//2 sigma
53  mClusterEtThreshold = 5.0; //3.8; //4.5;// 4.2;
54  mEemcSamplingFraction = StEEmcFastMaker::getSamplingFraction();
55 
56 
57  mMomentum = new TVector3();
58 
60  // Calorimeter Geometry //
62 
63  //EEMC Geometry
64  mEemcGeom = new EEmcGeomSimple();
65 
66  // Zero counters
67  mTotal = 0;
68  mAccepted = 0;
69  mVertexRejected = 0;
70  mFilterRejected = 0;
71  // mFilterMode = 1;
72  // mUseDbParams = true;
73  mFilterMode = 1;
74  mUseDbParams = false;
75 
76  if(!mFilterMode)
77  {
78  LOG_INFO <<" StEemcGammaFilterMaker is running in test mode.";
79  LOG_INFO <<" set mFilterMode to 1 to run in analysis mode."<<endm;
80  }
81 
82 }
83 
85 // Destructor //
87 StEemcGammaFilterMaker::~StEemcGammaFilterMaker()
88 {
89  LOG_DEBUG << "~StEemcGammaFilterMaker()" << endm;
90 
91  // Clean up
92  delete mMomentum;
93  delete mEemcGeom;
94 
95 }
96 
98 // Maker Init //
100 Int_t StEemcGammaFilterMaker::Init()
101 {
102 
103  LOG_DEBUG << "Init()" << endm;
104 
105  // Force the BFC to listen to the filter
106  SetAttr(".Privilege", 1);
107 
108  // Display maker information
109 
110  if (this->getUseDbParams())
111  { // get parameter values from the database
112  LOG_INFO << "Getting parameters from the database" << endm;
113  TDataSet *DB = this->GetInputDB("Calibrations/emc");
114  if (DB)
115  {
116  St_eemcGammaFilterMakerParams* params = (St_eemcGammaFilterMakerParams*)DB->Find("eemcGammaFilterMakerParams");
117  if (params)
118  {
119  eemcGammaFilterMakerParams_st *p = params->GetTable();
120  if (p)
121  {
122  this->mEemcSamplingFraction = p->eemcSamplingFraction;
123  this->mSeedEnergyThreshold = p->seedEnergyThreshold;
124  this->mClusterEtThreshold = p->clusterEtThreshold;
125  this->mMaxVertex = p->maxVertexZ;
126  this->mFilterMode = p->filterMode;
127  LOG_DEBUG << "Successfully read parameters from the database table" << endm;
128  }
129  else
130  {
131  LOG_ERROR << "The database table has no entry!" << endl;
132  return kStFATAL;
133  }
134  }
135  else
136  {
137  LOG_ERROR << "Cannot find the table in the database!" << endm;
138  return kStFATAL;
139  }
140  }
141  else
142  {
143  LOG_ERROR << "Cannot read the database!" << endm;
144  return kStFATAL;
145  }
146  }//done getting db parameters
147 
148  LOG_INFO << "StEEmcDbMaker::Init() : Using gamma filter on the EEMC" << endm;
149  LOG_INFO << "StEEmcDbMaker::Init() : EEMC Sampling Fraction = " << mEemcSamplingFraction << endm;
150 
151  LOG_INFO << "StEEmcDbMaker::Init() : Seed energy threshold = " << mSeedEnergyThreshold << " GeV " << endm;
152  LOG_INFO << "StEEmcDbMaker::Init() : Cluster eT threshold = " << mClusterEtThreshold << " GeV " << endm;
153  LOG_INFO << "StEEmcDbMaker::Init() : Maximum vertex = +/- " << mMaxVertex << " cm" << endm;
154  if (!mFilterMode)
155  LOG_INFO << "StEEmcDbMaker::Init() : Running the TEST mode (accepting all events). Set mFilterMode=1 to actually reject events in BFC"<< endm;
156 
157 
158 
159  // If using the EEMC ensure that a sampling
160  // fraction has been entered by the user
161  if (mEemcSamplingFraction != StEEmcFastMaker::getSamplingFraction())
162  {
163  LOG_WARN << "StEEmcDbMaker::Init() : EEMC Sampling fraction (" << mEemcSamplingFraction << ") is different from what is in the Fast Simulator (" << StEEmcFastMaker::getSamplingFraction() <<")" << endm;
164  }
165 
166 
167  return kStOK;
168 
169 }
170 
172 // Maker Clear //
174 void StEemcGammaFilterMaker::Clear(const Option_t*)
175 {
176  LOG_DEBUG << "Clear()" << endm;
177 
178  // Clear the StEmcRawHit arrays
179 
180  double *point2 = mEemcTowerHits;
181  for(unsigned int i = 0; i < nEemcTowers; ++i)
182  {
183  *point2 = 0;
184  ++point2;
185  }
186 
187 
188 
189 }
190 
191 
192 
194 // Set maximum vertex allowed by the filter //
196 void StEemcGammaFilterMaker::setMaxVertex(double maxVertex)
197 {
198  LOG_DEBUG << "setMaxVertex()" << endm;
199  mMaxVertex = maxVertex;
200 }
201 
203 // Set filter thresholds //
205 void StEemcGammaFilterMaker::setThresholds(double seed, double cluster)
206 {
207 
208  LOG_DEBUG << "setThresholds()" << endm;
209 
210  if(seed > 0) mSeedEnergyThreshold = seed;
211  if(cluster > 0) mClusterEtThreshold = cluster;
212 
213 }
214 
216 // Set EEMC sampling fraction //
218 void StEemcGammaFilterMaker::setEEMCSamplingFraction(double f)
219 {
220  mEemcSamplingFraction = f;
221 }
222 
223 
225 // Apply filter //
228 {
229 
230  LOG_DEBUG << "Make()" << endm;
231 
232  // Acquire StEvent from the chain
233  StEvent *mEvent = static_cast<StEvent*>(GetDataSet("StEvent"));
234 
235  // Acquire StMcEvent from the chain
236  StMcEvent *mMcEvent = static_cast<StMcEvent*>(GetDataSet("StMcEvent"));
237 
238  ++mTotal;
239 
240  // Store the first event to ensure that a MuDst is created
241  // in the case of no events passing the filter
242  // if(mEvent->id() == 1)
243  // {
244  // LOG_INFO << "Make() : Storing first event without applying filter" << endm;
245  //
246  // ++mAccepted;
247  // return kStOK;
248  // }
249 
250  // Check for functional StMcEvent
251  if(!mMcEvent)
252  {
253  LOG_WARN << "Reject() : Bad StMcEvent!" << endm;
254  return kStWarn;
255  }
256 
257  // Acquire vertex information from the geant record
258  // and abort the event if the vertex is too extreme
259  double zVertex = mMcEvent->primaryVertex()->position().z();
260 
261  if(fabs(zVertex) > mMaxVertex)
262  {
263  LOG_INFO << "Reject() : Aborting Event " << mEvent->id()
264  << " due to extreme geant vertex of " << zVertex << " cm " << endm;
265 
266  ++mVertexRejected;
267  if(mFilterMode)
268  return kStSKIP;
269  else
270  return kStOK;
271 
272  }
273 
274  // Look for clusters in the chosen calorimeter
275  Int_t status = 0;
276 
277  // Pick up calorimeter information from StEvent
278  if (mEvent) {
279  StEmcCollection *emcCollection = mEvent->emcCollection();
280  status = makeEEMC(emcCollection, zVertex);
281  }
282 
283  if(status == kStSKIP)
284  {
285  ++mFilterRejected;
286  LOG_INFO << "Make() : Aborting Event " << mEvent->id() << " due to gamma filter rejection" << endm;
287  LOG_DEBUG << "Make() : Vertex = " << zVertex << " (cm)" << endm;
288  }
289 
290  if(status == kStOK)
291  {
292  ++mAccepted;
293 // LOG_INFO << "Make() : Event " << mEvent->id() << " accepted!" << endm; // Reduce noise and coverity complaint about possible NULL ptr
294  }
295 
296  if (mFilterMode==0) status = kStOK;
297  return status;
298 
299 }
300 
301 
303 // Construct crude EEMC clusters of 3x3 towers, //
304 // returning kStOK if a satisifactory cluster //
305 // is found and kStSKIP otherwise //
307 Int_t StEemcGammaFilterMaker::makeEEMC(StEmcCollection *emcCollection, double zVertex)
308 {
309 
310  LOG_DEBUG << "makeEEMC()" << endm;
311 
313  // Instantiate variables //
315 
316  unsigned int nSub = 5;
317  int eta = 0;
318  int phi = 0;
319 
320  double clusterEnergy = 0;
321  double clusterEt = 0;
322  double seedEnergy = 0;
323 
324  int neighborEta = 0;
325  int neighborPhi = 0;
326 
327  // Access EEMC information
328  StEmcDetector* eemc = emcCollection ? emcCollection->detector(kEndcapEmcTowerId) : 0;
329  if(!eemc) return kStSKIP;
330 
332  // Fill mEemcTowerHits //
333  // with hit data //
335  for(unsigned int m = 1; m < eemc->numberOfModules() + 1; ++m)
336  {
337 
338  StEmcModule *module = eemc->module(m);
339  if (module) {
340  StSPtrVecEmcRawHit &rawHits = module->hits();
341 
342  for(unsigned int l = 0 ; l < rawHits.size(); ++l)
343  {
344 
345  StEmcRawHit *tempHit = rawHits[l];
346  if (tempHit) {
347  eta = tempHit->eta() - 1;
348  phi = (m - 1) * nSub + tempHit->sub() - 1;
349  mEemcTowerHits[eta * nEemcPhiBins + phi] = tempHit->energy() / mEemcSamplingFraction;
350  }
351  }
352  }
353 
354  }
355 
357  // Search for clusters //
359 
360  for(unsigned int e = 0; e < nEemcEtaBins; ++e)
361  {
362 
363  for(unsigned int p = 0; p < nEemcPhiBins; ++p)
364  {
365 
366  clusterEnergy = 0;
367 
368  seedEnergy = mEemcTowerHits[e * nEemcPhiBins + p];
369 
370  // Start with a seed tower...
371  if(seedEnergy > mSeedEnergyThreshold)
372  {
373 
374  clusterEnergy = seedEnergy;
375 
376  // and accumulate energy from the neighboring towers
377  for(int i = -1; i < 2; ++i)
378  {
379 
380  for(int j = -1; j < 2; ++j)
381  {
382 
383  if( !i && !j )
384  {
385  LOG_DEBUG << "\t\tTower (eta, phi) = (" << e << ", " << p
386  << "), E = " << seedEnergy << " (Seed)" << endm;
387  continue;
388  }
389 
390  neighborEta = e + i;
391  if(neighborEta < 0) continue;
392  if(neighborEta > int(nEemcEtaBins - 1)) continue;
393 
394  neighborPhi = (p + j) % nEemcPhiBins;
395 // if(neighborPhi == - 1) neighborPhi = nEemcPhiBins - 1; // Cannot be < 0 after % on previous line
396  LOG_DEBUG << "\t\tTower (eta, phi) = (" << neighborEta << ", " << neighborPhi
397  << "), E = " << mEemcTowerHits[neighborEta * nEemcPhiBins + neighborPhi] << endm;
398  clusterEnergy += mEemcTowerHits[neighborEta * nEemcPhiBins + neighborPhi];
399 
400  }
401 
402  }
403 
404  // Project cluster energy into transverse plane
405  if (mMomentum && mEemcGeom) {
406  *mMomentum = mEemcGeom->getTowerCenter(p / nSub, p % nSub, e);
407  mMomentum->SetZ(mMomentum->Z() - zVertex);
408  mMomentum->SetX(mMomentum->X() * clusterEnergy / mMomentum->Mag() );
409  mMomentum->SetY(mMomentum->Y() * clusterEnergy / mMomentum->Mag() );
410  mMomentum->SetZ(mMomentum->Z() * clusterEnergy / mMomentum->Mag() );
411  clusterEt = mMomentum->Perp();
412 
413  LOG_DEBUG << "\tCluster Energy = " << clusterEnergy << " GeV" << endm;
414  LOG_DEBUG << "\tCluster eT (corrected for vertex) = " << clusterEt << " GeV" << endm;
415  LOG_DEBUG << "\tCluster eta (corrected for vertex) = " << mMomentum->Eta() << endm;
416  LOG_DEBUG << "\tCluster phi = " << mMomentum->Phi() << endm;
417  LOG_DEBUG << "" << endm;
418  }
419 
420  // Apply filter
421  if(clusterEt > mClusterEtThreshold)
422  {
423  return kStOK;
424  }
425 
426 
427  } // Seed tower check
428 
429  } // Seed tower phi loop
430 
431  } // Seed tower eta loop
432 
433  return kStSKIP;
434 
435 }
436 
438 // Display filter stats //
441 {
442  LOG_DEBUG << "::Finish()" << endm;
443 
444  LOG_INFO << "Finish() : " << GetName() << " finishing with " << endm;
445  LOG_INFO << "Finish() : \t" << mAccepted << " of " << mTotal << " events passing the filter" << endm;
446  LOG_INFO << "Finish() : \t" << mVertexRejected << " rejected for bad vertex" << endm;
447  LOG_INFO << "Finish() : \t" << mFilterRejected << " rejected for no clusters" << endm;
448 
449  return kStOK;
450 }
451 
452 // $Log: StEemcGammaFilterMaker.cxx,v $
453 // Revision 1.4 2016/05/25 21:35:26 jwebb
454 // Removed deadcode (coverity) and removed uneccessary printout.
455 //
456 // Revision 1.3 2010/08/09 21:51:22 seluzhen
457 // updated comment field
458 //
TVector3 getTowerCenter(const UInt_t sec, const UInt_t sub, const UInt_t etabin) const
Definition: Stypes.h:48
BFC level Endcap EMC gamma filter.
virtual const char * GetName() const
special overload
Definition: StMaker.cxx:237
Definition: Stypes.h:42
EEMC simple geometry.
Definition: Stypes.h:40
Event data structure to hold all information from a Monte Carlo simulation. This class is the interfa...
Definition: StMcEvent.hh:169
virtual TDataSet * Find(const char *path) const
Definition: TDataSet.cxx:362