StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StChargedPionHelpers.cxx
1 // $Id: StChargedPionHelpers.cxx,v 1.8 2013/10/09 14:43:39 stevens4 Exp $
2 
3 #include "TLorentzVector.h"
4 
5 #include "StChargedPionHelpers.h"
6 
7 #include "StChargedPionBaseEv.h"
8 #include "StChargedPionEvent.h"
9 #include "StChargedPionJet.h"
10 #include "StChargedPionMcEvent.h"
11 #include "StChargedPionTrack.h"
12 #include "StChargedPionVertex.h"
13 
14 #include "StSpinPool/StJetSkimEvent/StJetSkimEvent.h"
15 #include "StSpinPool/StJets/StJets.h"
16 #include "StSpinPool/StJets/StJet.h"
18 #include "StMuDSTMaker/COMMON/StMuDst.h"
19 #include "StMuDSTMaker/COMMON/StMuTrack.h"
20 #include "StMuDSTMaker/COMMON/StMuPrimaryVertex.h"
21 #include "StSpinPool/StMCAsymMaker/StPythiaEvent.h"
22 
23 ClassImp(StChargedPionHelpers)
24 
26 
27 void StChargedPionHelpers::
28 translateEvent(StJetSkimEvent *skimEvent, StChargedPionBaseEv *ev) {
29  ev->setRunId(skimEvent->runId());
30  ev->setEventId(skimEvent->eventId());
31  ev->setBbcTimeBin(skimEvent->bbcTimeBin());
32  const char *baseName = strrchr(skimEvent->mudstFileName().GetString().Data(), '/');
33  baseName = baseName + 1;
34  ev->setMuDstName( baseName );
35 
36  StChargedPionEvent *data = dynamic_cast<StChargedPionEvent*>(ev);
37  if(data) {
38  data->setBx7(skimEvent->bx7());
39 
40  data->setSpinBit(skimEvent->spin4usingBx48());
41  data->setPolValid(skimEvent->isValid());
42  data->setPolLong(skimEvent->isPolLong());
43  data->setPolTrans(skimEvent->isPolTrans());
44  data->setBxingMasked(skimEvent->isMaskedUsingBx48());
45  data->setBxingOffset(skimEvent->offsetBx48minusBX7());
46 
47  for(int i=0; i<skimEvent->trigHeaders()->GetEntriesFast(); i++) {
48  StJetSkimTrigHeader *h = static_cast<StJetSkimTrigHeader*>(skimEvent->trigHeaders()->At(i));
49  data->setPrescale(h->trigId, h->prescale);
50  }
51 
52  for(int i=0; i<skimEvent->triggers()->GetEntriesFast(); i++) {
53  StJetSkimTrig *t = static_cast<StJetSkimTrig*>(skimEvent->triggers()->At(i));
54  if(t->didFire() > 0) data->addTrigger(t->trigId());
55  if(t->shouldFire() > 0) data->addSimuTrigger(t->trigId());
56 
57  map<int,int> *m;
58  m = &(t->towersAboveThreshold(0));
59  for(map<int,int>::const_iterator it=m->begin(); it!=m->end(); it++) {
60  data->addHighTower(it->first, it->second);
61  }
62  delete m;
63 
64  m = &(t->triggerPatchesAboveThreshold(0));
65  for(map<int,int>::const_iterator it=m->begin(); it!=m->end(); it++) {
66  data->addTriggerPatch(it->first, it->second);
67  }
68  delete m;
69 
70  m = &(t->jetPatchesAboveThreshold(0));
71  for(map<int,int>::const_iterator it=m->begin(); it!=m->end(); it++) {
72  data->addJetPatch(it->first, it->second);
73  }
74  delete m;
75  }
76  }
77 
78  if(skimEvent->eBbc() > 0 && skimEvent->wBbc() > 0) {
79  if(ev->runId() > 6000000 && ev->runId() < 7000000) {
80  ev->addSimuTrigger(96011);
81  }
82  else if(ev->runId() > 7000000 && ev->runId() < 8000000) {
83  ev->addSimuTrigger(117001);
84  }
85  }
86 
88  for(int i=0; i<skimEvent->vertices()->GetEntriesFast(); i++) {
89  StJetSkimVert *skv = static_cast<StJetSkimVert*>(skimEvent->vertices()->At(i));
90  v.SetX( skv->position()[0] );
91  v.SetY( skv->position()[1] );
92  v.SetZ( skv->position()[2] );
93  v.setRanking( skv->ranking() );
94  ev->addVertex(&v);
95  }
96 }
97 
98 void StChargedPionHelpers::
99 translateJet(StJet* oldJet, vector<TLorentzVector*> particles, StChargedPionJet* jet) {
100  *static_cast<TLorentzVector*>(jet) = *static_cast<TLorentzVector*>(oldJet);
101 
102  jet->setCharge(oldJet->charge);
103  jet->setNTpcTracks(oldJet->nTracks);
104  jet->setNBarrelTowers(oldJet->nBtowers);
105  jet->setNEndcapTowers(oldJet->nEtowers);
106  jet->setTpcEtSum(oldJet->tpcEtSum);
107  jet->setBarrelEtSum(oldJet->btowEtSum);
108  jet->setEndcapEtSum(oldJet->etowEtSum);
109  jet->setVertexZ(oldJet->zVertex);
110 
111  for(unsigned i=0; i<oldJet->geomTriggers().size(); i++) {
112  jet->addTrigger(oldJet->geomTriggers()[i]);
113  }
114 
115  StChargedPionJetParticle particle;
116  StThreeVectorF dca;
117  TowerToJetIndex *myTower;
118  TrackToJetIndex *myTrack;
119  for( unsigned i=0; i<particles.size(); i++ )
120  {
121  particle.SetPt ( particles[i]->Pt() );
122  particle.SetEta( particles[i]->Eta() );
123  particle.SetPhi( particles[i]->Phi() );
124  particle.SetE( particles[i]->E() );
125 
126  if ( (myTower = dynamic_cast<TowerToJetIndex *>(particles[i])) )
127  {
128  particle.setIndex( myTower->towerId() );
129  particle.setDetectorId( StDetectorId(myTower->detectorId()) );
130  particle.setCharge( 0 );
131  }
132  else if ( (myTrack = dynamic_cast<TrackToJetIndex *>(particles[i])) )
133  {
134  particle.setIndex( myTrack->trackIndex() );
135  particle.setDetectorId( myTrack->detectorId() );
136  particle.setCharge( myTrack->charge());
137  particle.setNHits( myTrack->nHits() );
138  particle.setNHitsFit( myTrack->nHitsFit() );
139  particle.setNHitsPoss( myTrack->nHitsPoss() );
140  particle.setNHitsDEdx( myTrack->nHitsDedx() );
141  particle.setNSigmaPion( myTrack->nSigmaPion() );
142 
143  dca.setY( float(myTrack->Tdcaxy()) );
144  dca.setZ( float(myTrack->Tdcaz()) );
145  particle.setGlobalDca( dca );
146  }
147  jet->addParticle(&particle);
148  }
149 }
150 
151 void StChargedPionHelpers::
152 translateJets(StJets *jets, StChargedPionBaseEv *ev) {
153  StChargedPionJet myjet;
154  StChargedPionVertex *v = ev->vertex(0);
155 
156  TClonesArray *oldJets = jets->jets();
157  for(int i=0; i<oldJets->GetEntriesFast(); i++) {
158  StJet *oldJet = static_cast<StJet*>(oldJets->At(i));
159  translateJet(oldJet, jets->particles(i), &myjet);
160  if(v) myjet.setVertexZ(v->z());
161  ev->addJet(&myjet);
162  myjet.Clear();
163  }
164 }
165 
166 void StChargedPionHelpers::
167 translateJets(StJets *jets, StChargedPionMcEvent *ev) {
168  StChargedPionMcJet myjet;
169  StChargedPionVertex *v = ev->vertex(0);
170 
171  TClonesArray *oldJets = jets->jets();
172  for(int i=0; i<oldJets->GetEntriesFast(); i++) {
173  StJet *oldJet = static_cast<StJet*>(oldJets->At(i));
174  translateJet(oldJet, jets->particles(i), &myjet);
175  if(v) myjet.setVertexZ(v->z());
176  ev->mcJets().push_back(myjet);
177  myjet.Clear();
178  }
179 }
180 
181 void StChargedPionHelpers::
182 translatePythia(const StPythiaEvent *py, StChargedPionMcEvent *ev) {
183  //remove const-ness until we have const versions of pythia->particle()
184  StPythiaEvent *pythia = const_cast<StPythiaEvent*>(py);
185 
186  ev->parton1() = StChargedPionLorentzVector(pythia->particle(0)->Px(),
187  pythia->particle(0)->Py(),
188  pythia->particle(0)->Pz(),
189  pythia->particle(0)->Energy());
190  ev->parton2() = StChargedPionLorentzVector(pythia->particle(1)->Px(),
191  pythia->particle(1)->Py(),
192  pythia->particle(1)->Pz(),
193  pythia->particle(1)->Energy());
194  ev->parton3() = StChargedPionLorentzVector(pythia->particle(2)->Px(),
195  pythia->particle(2)->Py(),
196  pythia->particle(2)->Pz(),
197  pythia->particle(2)->Energy());
198  ev->parton4() = StChargedPionLorentzVector(pythia->particle(3)->Px(),
199  pythia->particle(3)->Py(),
200  pythia->particle(3)->Pz(),
201  pythia->particle(3)->Energy());
202  ev->setProcessId(pythia->processId());
203  ev->setX1(pythia->x1());
204 }
205 
206 void StChargedPionHelpers::
207 translateMinimc(const StMiniMcEvent *mini, StChargedPionMcEvent *ev) {
208  ev->mcVertex() = StChargedPion3Vector(mini->mcVertexX(),
209  mini->mcVertexY(),
210  mini->mcVertexZ());
211 
212  TClonesArray* mcTracks = mini->tracks(MC);
213  TClonesArray* matchedPairs = mini->tracks(MATCHED);
214  TClonesArray* mergedPairs = mini->tracks(MERGED);
215  TClonesArray* splitPairs = mini->tracks(SPLIT);
216  TClonesArray* contamPairs = mini->tracks(CONTAM);
217  TClonesArray* ghostPairs = mini->tracks(GHOST);
218 
219  StTinyMcTrack *t;
220  StMiniMcPair *p;
221  for(int i=0; i<mcTracks->GetEntriesFast(); i++) {
222  t = static_cast<StTinyMcTrack*>(mcTracks->At(i));
223  if(t->ptMc() > 1.7) ev->mcTracks().push_back(*t);
224  }
225 
226  //note: the approach I used here should end up duplicating the tiny mc tracks
227  //in each of these clones arrays. Alternative would be to find the pointer to
228  //the original tiny mc track in ev->mcTracks() that has the same ID. That's
229  //likely a CPU-intensive process (but who cares?)
230 
231  //recoKey wasn't filled for the 2005 simulations, so I have to fall back to
232  //pT matching here
233 
234  for(int i=0; i<matchedPairs->GetEntriesFast(); i++) {
235  p = static_cast<StMiniMcPair*>(matchedPairs->At(i));
236  if(p->ptPr() > 2.0) {
237  ev->matchedPairs().push_back(*p);
238  }
239  }
240 
241  for(int i=0; i<mergedPairs->GetEntriesFast(); i++) {
242  p = static_cast<StMiniMcPair*>(mergedPairs->At(i));
243  if(p->ptPr() > 2.0) {
244  ev->mergedPairs().push_back(*p);
245  }
246  }
247 
248  for(int i=0; i<splitPairs->GetEntriesFast(); i++) {
249  p = static_cast<StMiniMcPair*>(splitPairs->At(i));
250  if(p->ptPr() > 2.0) {
251  ev->splitPairs().push_back(*p);
252  }
253  }
254 
255  for(int i=0; i<contamPairs->GetEntriesFast(); i++) {
256  p = static_cast<StMiniMcPair*>(contamPairs->At(i));
257  if(p->ptPr() > 2.0) {
258  ev->contamPairs().push_back(*p);
259  }
260  }
261 
262  for(int i=0; i<ghostPairs->GetEntriesFast(); i++) {
263  p = static_cast<StMiniMcPair*>(ghostPairs->At(i));
264  if(p->ptPr() > 2.0) {
265  ev->ghostPairs().push_back(*p);
266  }
267  }
268 }
269 
270 void StChargedPionHelpers::
271 translateMuDst(StChargedPionEvent *ev) {
272  translateMuDst(static_cast<StChargedPionBaseEv*>(ev));
273 
274  ev->setBx7( StMuDst::event()->l0Trigger().bunchCrossingId7bit(ev->runId()) );
275  ev->setRunInfo( StMuDst::event()->runInfo() );
276 
277  // see StDaqLib/TRG/trgStructures2005.h => L2RESULTS_OFFSET_DIJET==14
278  if(ev->runId() > 7000000)
279  ev->setL2Result( StMuDst::event()->L2Result().GetArray() + 14 );
280 }
281 
282 void StChargedPionHelpers::
283 translateMuDst(StChargedPionMcEvent *ev) {
284  translateMuDst(static_cast<StChargedPionBaseEv*>(ev));
285 }
286 
287 void StChargedPionHelpers::
288 translateMuDst(StChargedPionBaseEv *ev) {
289  //basic event info
290  ev->setRunId( StMuDst::event()->runNumber() );
291  ev->setEventId( StMuDst::event()->eventNumber() );
292  ev->setBbcTimeBin( StMuDst::event()->bbcTriggerDetector().onlineTimeDifference() );
293 
294  //vertices
296  unsigned int nVertices = StMuDst::numberOfPrimaryVertices();
297  for(unsigned int i=0; i<nVertices; ++i){
298  assert(StMuDst::primaryVertex(i));
300  vertex.SetX( muVert->position().x() );
301  vertex.SetY( muVert->position().y() );
302  vertex.SetZ( muVert->position().z() );
303  vertex.setRanking( muVert->ranking() );
304  ev->addVertex(&vertex);
305  }
306 
307  //now for the tracks
308  for(unsigned int vertex_index=0; vertex_index<nVertices; vertex_index++){
309  StMuDst::setVertexIndex(vertex_index);
310  TObjArray* primaryTracks = StMuDst::primaryTracks();
311  const StMuTrack* track;
312  const StMuTrack* global;
313  int nentries = StMuDst::numberOfPrimaryTracks();
314  assert(nentries==primaryTracks->GetEntries());
315  for(int i=0; i<nentries; i++){
316  track = StMuDst::primaryTracks(i);
317  global = track->globalTrack();
318 
319  //sanity checks
320  switch(track->bad()){
321  case(0):
322  break;
323  case(10):
324  // mBadTracks->Fill(kFlagged);
325  case(20):
326  // mBadTracks->Fill(kBadHelix);
327  case(30):
328  // mBadTracks->Fill(kBadOuterHelix);
329  continue;
330  }
331 
332  if(!global){
333  // mBadTracks->Fill(kMissingGlobal);
334  continue;
335  }
336 
337  //cuts
338  if(track->pt() < 2.) continue;
339  if(TMath::Abs(track->eta()) > 2.1) continue;
340 
341  StChargedPionTrack cpTrack;
342  translateTrack(track, &cpTrack);
343  cpTrack.setB(StMuDst::event()->eventSummary().magneticField()*kilogauss);
344  cpTrack.setVertex(StMuDst::primaryVertex()->position());
345 
346  ev->addTrack(&cpTrack);
347  }
348  }
349 }
350 
351 void StChargedPionHelpers::
352 translateTrack(const StMuTrack *mu, StChargedPionTrack *cp) {
353  cp->setId(mu->id());
354  cp->setFlag(mu->flag());
355 
356  cp->setVertexIndex(mu->vertexIndex());
357 
358  cp->setNHits(mu->nHits());
359  cp->setNHitsPoss(mu->nHitsPoss());
360  cp->setNHitsDedx(mu->nHitsDedx());
361  cp->setNHitsFit(mu->nHitsFit());
362 
363  cp->setNSigmaElectron(mu->nSigmaElectron());
364  cp->setNSigmaPion(mu->nSigmaPion());
365  cp->setNSigmaKaon(mu->nSigmaKaon());
366  cp->setNSigmaProton(mu->nSigmaProton());
367  cp->setDedx(mu->dEdx());
368 
369  cp->setChi2(mu->chi2());
370  cp->setChi2prob(mu->chi2prob());
371 
372  cp->setPtEtaPhi(mu->pt(),mu->eta(),mu->phi());
373 
374  cp->setCharge(mu->charge());
375 
376  cp->setGlobalLastPoint(mu->globalTrack()->lastPoint());
377  cp->setGlobalHelix(mu->globalTrack()->helix());
378 }
379 
380 /*****************************************************************************
381  * $Log: StChargedPionHelpers.cxx,v $
382  * Revision 1.8 2013/10/09 14:43:39 stevens4
383  * Add const to char* in 2 lines to compile on 5.34.09 and SL6.4 on rplay18
384  *
385  * Revision 1.7 2010/07/16 20:24:08 rfatemi
386  * Changes in code to preserve backward compatibility with changes in jet code. Affects info about particles in jets.
387  *
388  * Revision 1.5 2009/12/02 21:17:31 fine
389  * Fix StMuTrack interface
390  *
391  * Revision 1.4 2009/09/25 14:26:37 fine
392  * fix compilation error on SL5/64-bit machine
393  *
394  * Revision 1.3 2009/04/02 18:25:42 kocolosk
395  * fixed paths to jet codes
396  *
397  * Revision 1.2 2008/12/29 15:58:28 kocolosk
398  * removed commented code and added Id and Log as needed
399  *
400  * Revision 1.1 2008/07/17 17:06:30 kocolosk
401  * big-bang integration StChargedPionMcEvent framework
402  *
403  *****************************************************************************/
static StMuPrimaryVertex * primaryVertex()
return pointer to current primary vertex
Definition: StMuDst.h:322
Double_t chi2prob() const
Returns probability of fit.
Definition: StMuTrack.h:252
Int_t vertexIndex() const
Returns index of associated primary vertex.
Definition: StMuTrack.cxx:600
Double_t pt() const
Returns pT at point of dca to primary vertex.
Definition: StMuTrack.h:256
short id() const
Returns the track id(or key), is unique for a track node, i.e. global and primary tracks have the sam...
Definition: StMuTrack.h:228
UShort_t nHitsDedx() const
Return number of hits used for dEdx.
Definition: StMuTrack.h:238
Double_t chi2() const
Returns chi2 of fit.
Definition: StMuTrack.h:251
int nTracks
The number of tracks in this jet.
Definition: StJet.h:104
Top level class for the MiniMcTree, containing event-wise information and the McTrack, and all TrackPair collections.
TClonesArray * jets()
Access to the jets in this event.
Definition: StJets.h:42
Definition: StJets.h:24
float zVertex
position of vertex used to reconstruct jet
Definition: StJet.h:134
StPhysicalHelixD helix() const
Returns inner helix (first measured point)
Definition: StMuTrack.cxx:407
UShort_t nHitsFit() const
Return total number of hits used in fit.
Definition: StMuTrack.h:239
int nBtowers
The number of Barrel towers in this jet.
Definition: StJet.h:107
short flag() const
Returns flag, (see StEvent manual for type information)
Definition: StMuTrack.h:230
Short_t charge() const
Returns charge.
Definition: StMuTrack.h:255
float etowEtSum
The summed Et from Endcap towers.
Definition: StJet.h:119
Double_t nSigmaPion() const
Returns Craig&#39;s distance to the calculated dE/dx band for pions in units of sigma.
Definition: StMuTrack.h:245
Double_t eta() const
Returns pseudo rapidity at point of dca to primary vertex.
Definition: StMuTrack.h:257
static TObjArray * primaryTracks()
returns pointer to a list of tracks belonging to the selected primary vertex
Definition: StMuDst.h:301
void setL2Result(const void *address, bool emulated=false)
address to dijet result
Double_t nSigmaElectron() const
Returns Craig&#39;s distance to the calculated dE/dx band for electrons in units of sigma.
Definition: StMuTrack.h:244
UShort_t nHitsPoss() const
Return number of possible hits on track.
Definition: StMuTrack.cxx:242
static StMuEvent * event()
returns pointer to current StMuEvent (class holding the event wise information, e.g. event number, run number)
Definition: StMuDst.h:320
UShort_t nHits() const
Bingchu.
Definition: StMuTrack.h:237
const StThreeVectorF & lastPoint() const
Returns positions of last measured point.
Definition: StMuTrack.h:262
Double_t dEdx() const
Returns measured dE/dx value.
Definition: StMuTrack.h:248
Double_t phi() const
Returns phi at point of dca to primary vertex.
Definition: StMuTrack.h:258
Double_t nSigmaProton() const
Returns Craig&#39;s distance to the calculated dE/dx band for protons in units of sigma.
Definition: StMuTrack.h:247
int nEtowers
The number of Endcap towers in this jet.
Definition: StJet.h:110
const StMuTrack * globalTrack() const
Returns pointer to associated global track. Null pointer if no global track available.
Definition: StMuTrack.h:272
float tpcEtSum
The summed Et from tracks.
Definition: StJet.h:113
Double_t nSigmaKaon() const
Returns Craig&#39;s distance to the calculated dE/dx band for kaons in units of sigma.
Definition: StMuTrack.h:246
static void setVertexIndex(Int_t vtx_id)
Set the index number of the current primary vertex (used by both primaryTracks() functions and for St...
Definition: StMuDst.cxx:273
float btowEtSum
The summed Et from Barrel towers.
Definition: StJet.h:116
int charge
The summed coulomb charge of the tracks in this jet.
Definition: StJet.h:101
Definition: StJet.h:91