StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StPeCMaker.cxx
1 // $Id: StPeCMaker.cxx,v 1.36 2018/02/26 23:30:18 smirnovd Exp $
2 // $Log: StPeCMaker.cxx,v $
3 // Revision 1.36 2018/02/26 23:30:18 smirnovd
4 // StPeCMaker: Init BTOF geometry using proper interface
5 //
6 // Revision 1.35 2016/02/24 16:50:00 ramdebbe
7 // just removed commented lines
8 //
9 // Revision 1.34 2015/07/22 18:29:51 ramdebbe
10 // added choice to skip writting the tree to output file and added summary histograms
11 //
12 // Revision 1.33 2015/02/25 01:19:38 ramdebbe
13 // added a setter to select writing Roman Pot Collection to output tree
14 //
15 // Revision 1.32 2014/06/18 17:29:49 ramdebbe
16 // ignore flag from StPeCEvent and writes all events with a summary
17 //
18 // Revision 1.31 2013/12/27 16:44:27 ramdebbe
19 // added extrapolation of tracks to TOF, geometry setup in InitRun
20 //
21 // Revision 1.30 2013/07/10 19:28:06 ramdebbe
22 // added returnValue in StEvent input mode
23 //
24 // Revision 1.29 2013/01/24 15:43:08 ramdebbe
25 // added more flags to choose input or output tracks tof etc.
26 //
27 // Revision 1.28 2012/06/13 15:45:42 ramdebbe
28 // Added flags to include TOF and Vertex branches in tree
29 //
30 // Revision 1.27 2007/04/28 17:56:34 perev
31 // Redundant StChain.h removed
32 //
33 // Revision 1.26 2004/02/07 01:40:46 meissner
34 // bug in check of un-analylized MC events, all MC events are now filled
35 //
36 // Revision 1.25 2003/11/25 01:54:30 meissner
37 // correct several bugs: eta cut for tracks, charge sorting, add counting of FTPC and TPC primary tracks, Add bbc information
38 //
39 // Revision 1.24 2002/12/19 18:09:53 yepes
40 // MuDST input added
41 //
42 // Revision 1.23 2002/06/04 17:55:02 meissner
43 // filtering: filter all UPC triggerwords
44 //
45 // Revision 1.21 2002/04/18 19:02:11 meissner
46 // Change Init to InitRun
47 //
48 // Revision 1.20 2002/03/19 22:23:44 meissner
49 // New variables: zdc unatt., Trigger word, MC tree if Geant Branch, DCA for primary pairs, all tracks for secondary pairs (Test)
50 //
51 // Revision 1.19 2002/02/11 20:20:09 akio
52 // remove SetFormat
53 //
54 // Revision 1.18 2001/08/07 19:52:35 akio
55 // added a flag to make udst can have more than 1 depth of branches.
56 //
57 // Revision 1.17 2001/04/23 21:44:33 meissner
58 // add dEdx z variable to tree, setFormat(1) for tree, use private BetheBloch (temp solution)
59 //
60 // Revision 1.16 2001/02/21 20:42:05 yepes
61 // Add ctb signals to tree
62 //
63 // Revision 1.15 2001/02/14 18:34:44 yepes
64 // bug in deleting StEvent and the of of Make
65 //
66 // Revision 1.14 2001/02/13 17:54:41 yepes
67 // still problems on differnt platforms
68 //
69 // Revision 1.13 2001/02/13 16:33:58 yepes
70 // fix problem on Sun
71 //
72 // Revision 1.12 2001/02/12 21:15:55 yepes
73 // New version of StPeCMaker, lots of changes
74 //
75 // Revision 1.9 2000/04/21 19:09:49 nystrand
76 // Update StPeCPair class, new histograms
77 //
78 // Revision 1.8 2000/03/24 22:36:24 nystrand
79 // First version with StPeCEvent
80 //
81 // Revision 1.7 2000/01/20 23:03:08 nystrand
82 // First Version of StPeCMaker with new StEvent
83 //
84 // Revision 1.6 1999/09/24 01:23:19 fisyak
85 // Reduced Include Path
86 //
87 // Revision 1.5 1999/07/15 13:57:20 perev
88 // cleanup
89 //
90 // Revision 1.4 1999/06/27 22:45:29 fisyak
91 // Merge StRootEvent and StEvent
92 //
93 // Revision 1.3 1999/05/01 00:57:02 fisyak
94 // Change Clear function to defualt
95 //
96 // Revision 1.2 1999/04/08 16:37:15 nystrand
97 // MakeBranch,SetBranch removed
98 //
99 // Revision 1.1 1999/04/06 20:47:27 akio
100 // The first version
101 //
102 // Revision 1.0 1999/03/05 11:00:00 Nystrand
103 // initial version
104 //
105 //
107 //
108 // StPeCMaker
109 //
110 // Description:
111 // Maker for Peripheral Collisions DST analysis
112 // This version uses StPeCEvent
113 //
114 // Environment:
115 // Software developed for the STAR Detector at Brookhaven National Laboratory
116 //
117 // Author List:
118 // Joakim Nystrand, LBNL
119 //
120 // History:
121 //
123 #include "StPeCMaker.h"
124 #include "StPeCEnumerations.h"
125 #include "StEventTypes.h"
126 #include "Stypes.h"
127 #include "StMessMgr.h"
128 #include "TH1.h"
129 #include "TH2.h"
130 #include <vector>
131 #ifndef ST_NO_NAMESPACES
132 using std::vector;
133 #endif
134 
135 #include "StTriggerDetectorCollection.h"
136 #include "StCtbTriggerDetector.h"
137 #include "StMwcTriggerDetector.h"
138 #include "StVpdTriggerDetector.h"
139 #include "StZdcTriggerDetector.h"
140 #include "StFtpcHitCollection.h"
141 #include "StFtpcPlaneHitCollection.h"
142 #include "StFtpcSectorHitCollection.h"
143 
144 #include "StMcEventTypes.hh"
145 #include "StMcEventMaker/StMcEventMaker.h"
146 #include "StIOMaker/StIOMaker.h"
147 
148 
149 
150 
151 
152 static const char rcsid[] = "$Id: StPeCMaker.cxx,v 1.36 2018/02/26 23:30:18 smirnovd Exp $";
153 
154 ClassImp(StPeCMaker)
155 
156 StPeCMaker::StPeCMaker(const Char_t *name) : StMaker(name), infoLevel(0), filter(0), outputPerRun(0), muDst(0)
157 {
158  treeFileName = "StPeCMaker.tree.root" ;
159  triggerChoice = "something";
160  return;
161 }
162 
163 
164 StPeCMaker::~StPeCMaker()
165 {
166  return;
167 }
168 
169 
170 Int_t StPeCMaker::Init() {
171 
172  LOG_INFO << "StPeCMake INIT: tree output file: " << treeFileName << endm;
173  infoLevel = 0;
174  LOG_INFO << "StPeCMake INIT: infoLevel: " << infoLevel << endm;
175  LOG_INFO <<"StPeCMaker INIT: readStMuDst " << readStMuDst << endm;
176  LOG_INFO <<"StPeCMaker INIT: readStEvent " << readStEvent << endm;
177  LOG_INFO <<"StPeCMaker INIT: readBoth " << readStMuDst_and_StEvent << endm;
178  LOG_INFO <<"trigger to be selected: " << triggerChoice << endm; // triggerChoice can be changed with the setter setTriggerOfInterest (const char * selectTrigger = "UPC_Main" ) see StPeCTrigger for details
179  LOG_INFO <<"choice for output: " << treeOff << endm; // if argument of setter setSuppressTreeOut is kTRUE, the TTree will not be writte in output file
180 
181  //Get the standard root format to be independent of Star IO
182  m_outfile = new TFile(treeFileName, "recreate");
183  m_outfile->SetCompressionLevel(1);
184 
185 
186  if(!treeOff)uDstTree = new TTree("uDst", "Pcol uDst", 99);
187 
188  //Instantiate StPeCEvent
189 
190  pevent = new StPeCEvent(useBemc, useTOF, useVertex, useTracks, useRP, readStMuDst, readStEvent, readStMuDst_and_StEvent);
191  pevent->setInfoLevel(infoLevel);
192  if(!pevent) LOG_INFO << "StPeCMaker Init: unable to make instance of StPeCEvent ---------- " << endm;
193  trigger = new StPeCTrigger();
194  trigger->setInfoLevel(infoLevel);
195  char test[] = "ZDC_monitor";
196 
197  geant = new StPeCGeant();
198  LOG_INFO << "StPeCMaker Init: before branch add ---------- " << endm;
199 
200  //Add branches
201  if(!treeOff) {
202  uDstTree->Branch("Trigger", "StPeCTrigger", &trigger, 64000, 99);
203  uDstTree->Branch("Geant", "StPeCGeant", &geant, 64000, 99);
204  LOG_INFO << "StPeCMaker Init: after Geant branch add ---------- " << endm;
205  uDstTree->Branch("Event", "StPeCEvent", &pevent, 64000, 99);
206  LOG_INFO << "StPeCMaker Init: after Event branch add ---------- " << endm;
207  }
208  //define 2-D histogram to display snapshots of individual events
209  //store then in another directory
210  TDirectory * saveDir = gDirectory;
211  TDirectory * snapShots = gDirectory->mkdir("snapShots");
212  snapShots->cd();
213  fSnapShots = new TList();
214  Int_t snapLimit = 0;
215  for (Int_t i=0;i<snapLimit;i++){
216 
217  fSnapShots->Add(new TH2F(Form("snapShot%d",i), Form("y z view of event %d", i) , 100, -250., 250., 100, -200., 200.));
218  }
219  hNumVtx = new TH1F("hNumVtx", "number of vertices in event" , 10, -0.5, 9.5);
220  hNumAccVtx = new TH1F("hNumAccVtx", "number of accepted vertices in event" , 10, -0.5, 9.5);
221  hNumAccWithTOF = new TH1F("hNumAccWithTOF", "number of accepted vertices with at least one TOF hit" , 10, -0.5, 9.5);
222  hNumRejecWithTOF = new TH1F("hNumRejecWithTOF", "number of rejected vertices with TOF hits" , 10, -0.5, 9.5);
223  hNumTrkRejecVtx = new TH1F("hNumTrkRejecVtx", "number of tracks in rejected vertex with TOF hits" , 100, 1., 1000.);
224  hzVertexAccTOF = new TH1F("hzVertexAccTOF", "z vertex accepted with TOF hits" , 100, -200., 200.);
225  hzVertexRejectTOF = new TH1F("hzVertexRejectTOF", "z vertex rejected with TOF hits" , 100, -200., 200.);
226 
227  fSnapShots->Add(hNumVtx);
228  fSnapShots->Add(hNumAccVtx);
229  fSnapShots->Add(hNumAccWithTOF);
230  fSnapShots->Add(hNumRejecWithTOF);
231  fSnapShots->Add(hNumTrkRejecVtx);
232  fSnapShots->Add(hzVertexAccTOF);
233  fSnapShots->Add(hzVertexRejectTOF);
234 
235  gDirectory = saveDir;
236 
237 
238 
239  LOG_INFO << "StPeCMaker leaving Init ---------- " << endm;
240  return StMaker::Init();
241 }
242 
243 
244 Int_t StPeCMaker::InitRun(Int_t runnr) {
245  treeFileName="StPeCMaker.tree.root";
246  LOG_INFO << "InitRun StPeCMaker run " << runnr<<endm;
247  // get TOF geometry to extrapolate tracks to it
248  //
249  mBTofGeom = new StBTofGeometry("btofGeometry","btofGeometry in MatchMaker"); //commenting this line stops the extrapolation
250 
251  geantU = dynamic_cast<St_geant_Maker *>(GetMaker("myGeant"));
252 
253  TVolume * mstarHall = (TVolume *)geantU->GetDataSet("HALL");
254 
255 
256  if(mBTofGeom && !mBTofGeom->IsInitDone()) {
257  LOG_INFO << " BTofGeometry initialization ... " << endm;
258  mstarHall->Print();
259  mBTofGeom->Init(this, mstarHall);
260  LOG_INFO << "starHall defined in StPeCMaker InitRun value of mBTofGeom " << mBTofGeom<<endm;
261  }
262  if ( outputPerRun ) {
263  StIOMaker* pIOMaker = (StIOMaker*)GetMaker("IO");
264  if (pIOMaker)
265  {
266  treeFileName = pIOMaker->GetFile();
267  const char* ccc = "/";
268  Ssiz_t slashPosition = treeFileName.Last(*ccc);
269 
270  if (slashPosition != -1 && slashPosition < treeFileName.Length())
271  treeFileName.Remove(0,slashPosition+1);
272  }
273 
274  //Make token replacements
275  treeFileName.ReplaceAll("dst", "tree");
276  treeFileName.ReplaceAll("event", "tree");
277  treeFileName.ReplaceAll("evtsel", "treeSel");
278 
279  LOG_INFO << "tree output file: " << treeFileName << endm;
280 
281  //Get the standard root format to be independent of Star IO
282  m_outfile = new TFile(treeFileName, "recreate");
283  m_outfile->SetCompressionLevel(1);
284  LOG_INFO << "Initrun: open and compression " << endm;
285  }
286 
287  LOG_INFO << "StPeCMaker leaving InitRun ---------- " << endm;
288 
289 
290 
291  return StMaker::InitRun(runnr);
292 }
293 
294 
296 {
297  StEvent* event = 0;
298  // Int_t flag = kStOk;
299  LOG_INFO << "StPeCMaker make: just in ---------- " << endm;
300 
301  Int_t NTracks = 0 ;
302  int tw = 0 ;
303  int ok = 0 ;
304  int returnValue = 0;
305  int gReturn = 0;
306  //
307  // 26-APR 2012 RD we comment the whole muDst part NEEDS TO BE FIXED
308  // 12-JULY2012 RD this is still in need of a fix, I return to StMuDst for triggerEfficiency studies
309  //
310  if(readStMuDst){
311  if(!muDst ) LOG_INFO << "StPeCMaker make: muDst not present " << endm;
312 
313 
314 // LOG_INFO << "StPeCMaker make: trigger selected ---------- " << triggerChoice<< endm;
315  NTracks = muDst->globalTracks()->GetEntries();
316 
317  StL0Trigger &trig = muDst->event()->l0Trigger();
318  tw = trig.triggerWord();
319 
320  returnValue = trigger->process(muDst, triggerChoice);
321 // LOG_INFO << "StPeCMaker make: trigger return ---------- " <<returnValue<< endm;
322  pevent->setTOFgeometry(mBTofGeom);
323  ok = pevent->fill(muDst);
324  //
325  // read MC information from MuDst
326  //Fill geant simulations //RD
327 // LOG_INFO << "StPeCMaker make: using muDst to fill Geant +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=---------- " << endm;
328 // gReturn = geant->fill(muDst);
329  }
330 
331  if(readStEvent){
332  LOG_INFO << "StPeCMaker make: using StEvent---------- " << endm; //to read StEvent 18-NOV-2012
333  event = (StEvent *)GetInputDS("StEvent");
334  if (!event)
335  {
336  LOG_ERROR << "There was no StEvent! Exiting..." << endm;
337  return kStOK;
338  }
339  //Process StEvent trigger simulations
340  returnValue = trigger->process(event, triggerChoice);
341 
342  StSPtrVecTrackNode& tempn = event->trackNodes();
343  NTracks = tempn.size();
344 
345  tw = event->l0Trigger()->triggerWord(); // end of StEvent 18-NOV
346  pevent->setTOFgeometry(mBTofGeom);
347  ok = pevent->fill(event);
348 
349  } //rd 9DEC09
350  if(readStMuDst_and_StEvent){
351 
352  event = (StEvent *)GetInputDS("StEvent");
353  if (!event)
354  {
355  LOG_ERROR << "There was no StEvent! Exiting..." << endm;
356  return kStOK;
357  }
358  LOG_INFO << "StPeCMaker make: using both StMuDst and StEvent ---------- " << endm;
359  NTracks = muDst->globalTracks()->GetEntries();
360 
361  StL0Trigger &trig = muDst->event()->l0Trigger();
362  tw = trig.triggerWord();
363 
364  returnValue = trigger->process(muDst, triggerChoice);
365  pevent->setTOFgeometry(mBTofGeom);
366  LOG_INFO << "StPeCMaker make: using both StMuDst and StEvent mBTofGeom after set " << mBTofGeom<<endm;
367 
368  std::vector<int> v = pevent->fill(event, muDst);
369  LOG_INFO << "StPeCMaker make: vector return "<<v.size()<<" first element "<<v.at(0)<<" second el: "<<v.at(1)<<" rejected with TOF hits "<<v.at(2)<<endm;
370 
371  hNumAccVtx->Fill(v.at(0));
372  hNumAccWithTOF->Fill(v.at(1));
373  hNumRejecWithTOF->Fill(v.at(2));
374  hNumVtx->Fill(v.at(3));
375  hNumTrkRejecVtx->Fill(v.at(4));
376  hzVertexAccTOF->Fill(v.at(5));
377  hzVertexRejectTOF->Fill(v.at(6));
378  }
379 
380 
381  LOG_INFO << "ok returnValue " <<ok<<" "<<returnValue<< endm;
382 
383 
384 // if ( !ok && returnValue>0) { // || geantBranch ) { RD 15-SEP ok=FALSE; good vertex in event returnValue>0; good trigger
385  if ( returnValue>0) { // || geantBranch ) { RD 3-JUNE2014 ignore the flag from StPeCEvent to write summary for all events
386 
387  LOG_INFO << "Fill Event to Tree!**********************" << endm;
388  if(!treeOff)uDstTree->Fill();
389  }
390 
391 
392  // //Select only 4 prong candidates
393  // //NOTE: This does not appear to do anything because the return code isn't used
394  // if (event)
395  // {
396  // if (filter == 1)
397  // flag = Cuts(event, pevent);
398  // else if (filter == 2)
399  // flag = Cuts4Prong(event, pevent);
400  // }
401 // } else { //turn off trigger
402 // LOG_INFO << "Do Not fill Event to Tree!**********************" << endm;
403 // } //turn off trigger
404 
405  //Cleanup
406  //LOG_INFO << "Before clean up!**********************" << endm;
407  pevent->clear();
408  geant->clear();
409  trigger->clear();
410 
411  //cout << "Exiting StPeCMaker::Make()" << endl;
412 
413 
414  return kStOk;
415 }
416 
417 
418 Int_t StPeCMaker::Cuts(StEvent *event, StPeCEvent *pevent)
419 {
420  StPrimaryVertex* vtx = event->primaryVertex();
421 
422 
423  cout << "Entering StPeCMaker::Cuts(StEvent *event, StPeCEvent *pevent)" << endl;
424 
425  //Get vertex info
426  if (!vtx)
427  return kStErr;
428 
429  if (vtx->position().x() < -5.)
430  return kStErr;
431  if (vtx->position().x() > 5.)
432  return kStErr;
433  if (vtx->position().y() < -5.)
434  return kStErr;
435  if (vtx->position().y() > 5.)
436  return kStErr;
437 
438  if (fabs(vtx->position().z()) > 200.)
439  return kStErr ;
440 
441  //Select interesting events
442  if (pevent->getNPriPairs() != 1)
443  return kStErr;
444 
445  StPeCPair *pair = pevent->getPriPair(0);
446  if (pair->getOpeningAngle() > 3.0)
447  return kStErr;
448  if (pair->getSumCharge())
449  return kStErr;
450 
451 
452 
453  return kStOK;
454 }
455 
456 
457 Int_t StPeCMaker::Cuts4Prong(StEvent *event, StPeCEvent *pevent)
458 {
459 
460  if (pevent->getNTot() != 4)
461  return kStErr;
462  if (fabs(pevent->getZVertex()) > 200)
463  return kStErr;
464  if (pevent->getNPriPairs() != 1)
465  return kStErr;
466  if (pevent->getNSecPairs() != 1)
467  return kStErr;
468  if (pevent->getPriPair(0)->getSumCharge())
469  return kStErr;
470  if (pevent->getSecPair(0)->getSumCharge())
471  return kStErr;
472  if (pevent->getPriPair(0)->getOpeningAngle() > 3)
473  return kStErr;
474  if (pevent->getSecPair(0)->getOpeningAngle() > 3)
475  return kStErr;
476 
477 
478 
479  return kStOK;
480 }
481 
482 
484 {
485 // cout << "Entering StPeCMaker::Finish()" << endl;
486  TDirectory * saveDir = gDirectory;
487  m_outfile->cd("snapShots");
488  fSnapShots->Write();
489  gDirectory = saveDir;
490  m_outfile->ls();
491  m_outfile->Write();
492  m_outfile->Close();
493  StMaker::Finish();
494 
495 
496 
497  return kStOK;
498 }
499 
500 
static TObjArray * globalTracks()
returns pointer to the global tracks list
Definition: StMuDst.h:303
virtual Int_t Finish()
Definition: StPeCMaker.cxx:483
virtual Int_t Make()
Definition: StPeCMaker.cxx:295
static StMuEvent * event()
returns pointer to current StMuEvent (class holding the event wise information, e.g. event number, run number)
Definition: StMuDst.h:320
Definition: Stypes.h:40
#include &quot;StEventTypes.h&quot;
Definition: StPeCEvent.h:83
virtual Int_t Finish()
Definition: StMaker.cxx:776
Definition: Stypes.h:44
Definition: Stypes.h:41