11 #include "StEvent/StEvent.h"
13 #include "StStrangeEvMuDst.hh"
14 #include "StStrangeCuts.hh"
15 #include "StMcEventTypes.hh"
16 #include "StParticleDefinition.hh"
17 #include "StMessMgr.h"
18 #include "StuJitterBug.hh"
21 #define MAXFILESIZE 1900000000
23 #define EachDoT(proc) \
24 for (Int_t i=1; i<strDstT; i++) { \
27 #define EachController(proc) EachDoT( if( cont[i]) cont[i]->proc );
30 static const char* defFileName =
"evMuDst.root";
31 static const char* defName =
"StrangeMuDst";
32 static const char* altName =
"MuDst";
33 static const char* defTitle =
"Strangeness Micro-DST";
34 static const char* trNames[3] = {defName,altName,0};
36 Int_t thisRun,thisEvent,lastRun,lastEvent,readEventNumber;
53 doT0JitterAbort = kFALSE;
57 for (Int_t i=0; i<strDstT; i++) {
63 strcpy(file,defFileName);
67 SetMode(StrangeNoFile);
79 StStrangeMuDstMaker::~StStrangeMuDstMaker() {
82 delete evClonesArray; evClonesArray = 0;
83 if (evMcArray) {
delete evMcArray; evMcArray = 0; }
85 delete cutsArray; cutsArray = 0;
86 delete cuts; cuts = 0;
87 for (
int i=0;i<strDstT;i++) {
delete cont[i]; cont[i]=0;}
91 Int_t StStrangeMuDstMaker::Init() {
93 if ( 1 == IAttr(
"DoV0" ) ) DoV0();
94 if ( 1 == IAttr(
"DoXi" ) ) DoXi();
95 if ( 1 == IAttr(
"DoKink" ) ) DoKink();
96 if ( 1 == IAttr(
"SetNoKeep" ) ) SetNoKeep();
100 if (Debug()) gMessMgr->Debug() <<
"In StStrangeMuDstMaker::Init() ... "
102 if ((GetMode() == StrangeWrite) && (OpenFile() ==
kStErr))
return kStEOF;
104 evClonesArray =
new TClonesArray(
"StStrangeEvMuDst",1);
105 if (doMc) evMcArray =
new TClonesArray(
"StStrangeEvMuDst",1);
107 cutsArray =
new TClonesArray(
"TCut",0);
108 StStrangeControllerBase::currentMaker =
this;
110 EachDoT(cont[i] = StStrangeControllerBase::Instantiate(i));
119 if (GetMode() == StrangeNoKeep) {
120 {EachDoT( cont[i]->SetBufferSize(32000) );}
122 {EachDoT(
if (bsize[i]) cont[i]->SetBufferSize(bsize[i]) );}
125 if (GetMode() == StrangeRead) {
128 gMessMgr->Error() <<
"StStrangeMuDstMaker: cannot read a dst and create "
129 <<
"a dst with one maker.\n"
130 <<
" Will read only." << endm;
137 return StMaker::Init();
140 void StStrangeMuDstMaker::InitReadDst() {
142 if (!((tree) && (muDst))) {
144 "StStrangeMuDstMaker: no appropriate tree in input file(s)!");
151 if (strcmp(tree->GetBranch(
"Event")->GetFileName(),
"")) {
152 TObjArray* listOfBranches = tree->GetListOfBranches();
153 for (
int i=0; i<listOfBranches->GetEntriesFast(); i++)
154 ((TBranch*) listOfBranches->At(i))->SetFile(muDst);
157 tree->SetBranchStatus(
"*",0);
158 tree->SetBranchStatus(
"Event.*",1);
159 tree->SetBranchAddress(
"Event",&evClonesArray);
161 tree->SetBranchStatus(
"McEvent.*",1);
162 tree->SetBranchAddress(
"McEvent",&evMcArray);
164 EachController(InitReadDst());
166 if (tree->GetBranch(
"StrangeCuts")) {
167 tree->SetBranchStatus(
"StrangeCuts.*",1);
168 tree->SetBranchAddress(
"StrangeCuts",&cutsArray);
170 TOrdCollection* ordCuts = (TOrdCollection*) muDst->Get(
"StrangeCuts");
172 cuts->Reset(ordCuts);
174 gMessMgr->Warning(
"StStrangeMuDstMaker: no StrangeCuts");
180 TObjArray *listOfBranches = tree->GetListOfBranches();
181 for( Int_t i=0; i<tree->GetNbranches(); i++) {
182 const char* n = ((TBranch*) listOfBranches->At(i))->
GetName();
183 gMessMgr->Debug() <<
"Branch " << n <<
" Status = " << tree->GetBranchStatus(n) << endm;
188 void StStrangeMuDstMaker::InitCreateDst() {
190 tree =
new TTree(defName,defTitle);
191 tree->SetDirectory(muDst);
192 EachController(InitCreateDst());
195 TBranch* branch = tree->Branch(
"StrangeCuts",&cutsArray,bsize[
evT],split);
197 branch = tree->Branch(
"Event",&evClonesArray,bsize[evT],split);
199 branch = tree->Branch(
"McEvent",&evMcArray,bsize[evT],split);
203 if (firstEvent) cuts->Init();
206 void StStrangeMuDstMaker::InitCreateSubDst() {
209 evClonesArray = dstMaker->GetEvClonesArray();
210 TBranch* branch = tree->Branch(
"Event",&evClonesArray,bsize[evT],split);
212 evMcArray = dstMaker->GetEvMcArray();
213 branch = tree->Branch(
"McEvent",&evMcArray,bsize[evT],split);
215 EachController(InitCreateSubDst());
220 if (Debug()) gMessMgr->Debug() <<
"In StStrangeMuDstMaker::Make() ... "
223 if (GetMode() == StrangeRead) {
224 return MakeReadDst();
225 }
else if (!dstMaker) {
226 return MakeCreateDst();
232 }
else if (!evClonesArray) {
238 Int_t StStrangeMuDstMaker::MakeReadDst() {
240 if (!((tree) && (muDst)))
return kStEOF;
242 if (makerEventNumber == -2) {
245 }
else if (makerEventNumber == -1) {
248 readEventNumber = makerEventNumber;
252 if (tree->GetEvent(readEventNumber) <= 0)
return kStEOF;
254 TFile* thisFile = chain->GetFile();
255 if (thisFile != lastFile) {
256 gMessMgr->Info() <<
"StStrangeMuDstMaker: Now reading from event file:\n "
257 << thisFile->GetName() << endm;
263 Bool_t badEvent = kTRUE;
265 thisRun = GetEvent()->
run();
266 thisEvent = GetEvent()->
event();
267 badEvent = (thisRun == lastRun) && (thisEvent == lastEvent);
270 if (makerEventNumber < 0 ) {
273 return MakeReadDst();
277 gMessMgr->Warning() <<
278 "StStrangeMuDstMaker: event on file has bad event info\n" <<
279 " and should be skipped!" << endm;
281 EachController(
Clear());
287 lastEvent = thisEvent;
290 if (cutsArray->GetEntriesFast()) cuts->Reset(cutsArray);
292 EachController(MakeReadDst());
297 Int_t StStrangeMuDstMaker::MakeCreateDst() {
299 if (abortEvent)
return kStOK;
303 Int_t iSize = cuts->GetSize();
304 cuts->Fill(strTypeNames[
v0T], GetDataSet(
"ev0par2"));
305 cuts->Fill(strTypeNames[
xiT], GetDataSet(
"exipar"));
306 cuts->Fill(strTypeNames[
kinkT], GetDataSet(
"tkf_tkfpar"));
307 Int_t fSize = cuts->GetSize();
308 if (!(fSize-iSize)) {
309 gMessMgr->Warning(
"StStrangeMuDstMaker: no cut parameters found.");
317 if (!event)
return kStOK;
320 cuts->UpdateArray(cutsArray);
322 if (doT0JitterAbort && t0JitterAbort(event)) {
323 gMessMgr->Warning(
"StStrangeMuDstMaker: T0 jitter; skipping event.");
327 EachController(MakeCreateDst(*event));
328 if (doMc) MakeCreateMcDst();
336 Int_t StStrangeMuDstMaker::MakeCreateMcDst() {
338 gMessMgr->Info(
"StStrangeMuDstMaker::MakeCreateMcDst(): running...");
342 gMessMgr->Error() <<
"StStrangeMuDstMaker: no StMcEvent! \n"
343 <<
" mc branch and assoc branch will not be filled. " << endm;
347 if (!GetMaker(
"StAssociationMaker")) {
348 gMessMgr->Warning() <<
"StStrangeMuDstMaker: no associated info! \n"
349 <<
" assoc branch will not be filled. " << endm;
353 StSPtrVecMcVertex& mcVertices = mcEvent->vertices();
354 for (StMcVertexIterator mcVertexIt = mcVertices.begin();
355 mcVertexIt != mcVertices.end(); mcVertexIt++) {
356 const StMcTrack* parent = (*mcVertexIt)->parent();
357 if (parent)
switch (parent->geantId()) {
364 if (doT[xiT]) cont[
xiT]->MakeCreateMcDst(*mcVertexIt);
373 if (doT[v0T] && !(doT[xiT])) cont[
v0T]->MakeCreateMcDst(*mcVertexIt);
384 if (doT[kinkT]) cont[
kinkT]->MakeCreateMcDst(*mcVertexIt);
393 if (doT[xiT] && doT[v0T]) {
394 for (StMcVertexIterator mcVertexIt = mcVertices.begin();
395 mcVertexIt != mcVertices.end(); mcVertexIt++) {
396 Bool_t notFromXi = kTRUE;
397 const StMcTrack* parent = (*mcVertexIt)->parent();
398 if (parent)
switch (parent->geantId()) {
402 const StMcTrack* parent2 = parent->parent();
403 if (parent2)
switch (parent2->geantId()) {
414 if (notFromXi) cont[
v0T]->MakeCreateMcDst(*mcVertexIt);
419 EachController(PrintNumMc());
424 Int_t StStrangeMuDstMaker::MakeCreateSubDst() {
426 if (abortEvent)
return kStOK;
428 EachController(MakeCreateSubDst());
430 cuts->Reset(dstMaker->Cuts());
431 cuts->UpdateArray(cutsArray);
439 if (Debug()) gMessMgr->Debug() <<
"In StStrangeMuDstMaker::Clear() ... "
442 for (Int_t i=0; i<subMakers.GetEntries(); i++) {
444 subMaker->ClearForReal(option);
447 ClearForReal(option);
451 void StStrangeMuDstMaker::ClearForReal(Option_t *option) {
453 if (Debug()) gMessMgr->Debug() <<
454 "In StStrangeMuDstMaker::ClearForReal() ... " <<
GetName() << endm;
460 if (evClonesArray) THack::ClearClonesArray(evClonesArray);
461 if (evMcArray) THack::ClearClonesArray(evMcArray);
463 THack::ClearClonesArray(cutsArray);
465 EachController(
Clear());
466 if (GetMode() == StrangeNoKeep) tree->Reset();
475 if (Debug()) gMessMgr->Debug() <<
"In StStrangeMuDstMaker::Finish() ... "
477 if (GetMode() == StrangeWrite) CloseFile();
485 SetMode(StrangeWrite);
489 void StStrangeMuDstMaker::SetRead(
const char* eFile,
const char* treeName) {
490 SetMode(StrangeRead);
491 if (!eFile) eFile = defFileName;
495 if (!treeName) treeName = altName;
496 else fileBlind = kTRUE;
498 if (!tree) tree = (TTree*) (chain =
new TChain(treeName,defTitle));
499 else SetTreeName(treeName);
503 Long_t nEntries = chain->GetEntriesFast();
504 if (fileBlind) chain->Add(eFile);
505 else chain->Add(eFile,0);
507 cuts->ForceUpdateArray();
514 if (fileBlind) { muDst = chain->GetFile();
return; }
518 Long_t nEnt = chain->GetEntries();
520 if (nEnt == TChain::kBigNumber) {
521 gMessMgr->Error(
"StStrangeMuDstMaker::SetRead(): bad file! Giving up.");
526 while (nEnt==nEntries) {
527 if (trNames[trial]==0) { SetTreeName(treeName);
return; }
529 if (strcmp(treeName,trNames[trial])) {
530 SetTreeName(trNames[trial]);
532 nEnt = chain->GetEntries();
537 muDst = chain->GetFile();
540 void StStrangeMuDstMaker::SetRead(
StFile* eFiles,
const char* treeName) {
541 SetMode(StrangeRead);
542 while (!(eFiles->GetNextBundle()))
543 SetRead(eFiles->GetFileName(0),treeName);
546 void StStrangeMuDstMaker::SetNoKeep() {
547 SetMode(StrangeNoKeep);
550 void StStrangeMuDstMaker::SetFile(
const char* eFile) {
551 if (eFile) strcpy(file,eFile);
554 void StStrangeMuDstMaker::SetTreeName(
const char* treeName) {
555 if ((treeName) && (strcmp(treeName,tree->GetName()))) {
556 tree->SetName(treeName);
557 TObjArray* chainElems = chain->GetListOfFiles();
558 for (Int_t i=0; i<chainElems->GetEntriesFast(); i++)
559 ((TNamed*) (chainElems->At(i)))->SetName(treeName);
563 Int_t StStrangeMuDstMaker::OpenFile() {
564 if( ! (muDst =
new TFile(file,
"RECREATE")) ) {
565 gMessMgr->Error() <<
"StStrangeMuDstMaker: Error opening event file:\n "
570 gMessMgr->Info() <<
"StStrangeMuDstMaker: Opened file for writing:\n"
572 cuts->ForceUpdateArray();
576 Int_t StStrangeMuDstMaker::CloseFile() {
586 void StStrangeMuDstMaker::CheckFile() {
588 if (muDst->GetBytesWritten() > MAXFILESIZE) {
589 gMessMgr->Warning() <<
"StStrangeMuDstMaker: File size limit "
590 << MAXFILESIZE <<
" exceeded!\n"
591 <<
" Closing file " << file << endm;
594 sprintf(buf_,
"_%d",(++outFileNum));
595 TString fixer = file;
597 TString suffix = strrchr(file,
'.');
598 size_t last_ = fixer.Last(
'_');
599 size_t len_ = fixer.Length() - last_;
600 fixer.Remove(last_,len_).Append(buf_).Append(suffix);
602 size_t lastdot = fixer.Last(
'.');
603 fixer.Insert(lastdot,buf_);
605 strcpy(file,fixer.Data());
608 if (dstMaker) InitCreateSubDst();
614 EachController(Select(-1));
618 EachController(Unselect(-1));
623 if (!(maker->subMakers.FindObject((TObject*)
this)))
624 maker->subMakers.Add(
this);
627 void StStrangeMuDstMaker::SetCorrectionFile(
char* fname) {
628 StStrangeEvMuDst::SetCorrectionFile(fname);
631 void StStrangeMuDstMaker::SetFractionFile(
char* fname) {
635 char* StStrangeMuDstMaker::GetFile() {
637 TFile* fptr = chain->GetFile();
638 if (fptr)
return const_cast<char*
> (fptr->GetName());
static void SetFractionFile(char *)
Set files to use.
virtual Int_t GetNumber() const
STAR methods.
virtual void Clear(Option_t *option="")
User defined functions.
Monte Carlo Track class All information on a simulated track is stored in this class: kinematics...
virtual void Clear(Option_t *option="")
User defined functions.
void UnselectEvent()
Unselect whole event for sub DST.
virtual const char * GetName() const
special overload
Int_t run() const
Run number.
Event data structure to hold all information from a Monte Carlo simulation. This class is the interfa...
void SelectEvent()
Select whole event for sub DST.
Int_t event() const
Event number.