6 #include "StMuDstFilterMaker.h"
8 #include "StMuDSTMaker/COMMON/StMuTypes.hh"
11 #include "StEvent/StEventTypes.h"
22 #define __COMPRESSION__ 9
23 #define __BUFFER__ 65536
25 #define __AUTOSAVE__ 1000000
40 mFile =
new TFile(fname,
"RECREATE",
"StMuDst");
41 if (mFile->IsZombie() )
throw StMuExceptionNullPointer(
"no file openend",__PRETTYF__);
42 mFile->SetCompressionLevel(__COMPRESSION__);
45 DEBUGMESSAGE2(
"now create trees and branches");
47 mTTree =
new TTree(
"MuDst",
"StMuDst",__SPLIT__);
48 if (!mTTree)
throw StMuExceptionNullPointer(
"can not create tree",__PRETTYF__);
49 #if ROOT_VERSION_CODE < ROOT_VERSION(5,26,0)
50 Long64_t MAXLONG=100000000000LL;
51 LOG_INFO <<
"Tree size MAX will be " << (float) MAXLONG/1000/1000/1000 <<
" GB " << endm;
53 mTTree->SetMaxTreeSize(MAXLONG);
56 DEBUGMESSAGE2(
"arrays");
57 for (
int i=0; i<__NARRAYS__; i++) {
59 mTTree->Branch(StMuArrays::arrayNames[i],&
mArrays[i], __BUFFER__, __SPLIT__);
61 #ifndef __NO_STRANGE_MUDST__
63 DEBUGMESSAGE2(
"strange arrays");
64 for (
int i=0; i<__NSTRANGEARRAYS__; i++) {
66 mTTree->Branch(StMuArrays::strangeArrayNames[i],&mStrangeArrays[i], __BUFFER__, __SPLIT__);
70 DEBUGMESSAGE2(
"emc arrays");
71 for (
int i=0; i<__NEMCARRAYS__; i++) {
73 mTTree->Branch(StMuArrays::emcArrayNames[i],&mEmcArrays[i], __BUFFER__, __SPLIT__);
90 StMuDstFilterMaker::~StMuDstFilterMaker() {
98 if ( !mMuDstMaker )
return 0;
100 if (mFile==0 || mCurFileName != mMuDstMaker->
chain()->GetFile()->GetName()) {
102 if (mOutDirName.size())
103 outName=mOutDirName+
'/';
104 if (mOutFileName.size()) {
105 outName+=mOutFileName;
109 const Char_t *inName = mMuDstMaker->
chain()->GetFile()->GetName();
110 const Char_t *baseName = strrchr(inName,
'/');
118 cout <<
"Opening output file " << outName << endl;
119 open(outName.c_str());
121 mCurFileName = mMuDstMaker->
chain()->GetFile()->GetName();
124 if ( !muDst )
return 0;
140 if (
filter(muDst)==
false )
return 0;
149 DEBUGMESSAGE(
"Event accepted");
165 TArrayI globals_stored(muDst->
globalTracks()->GetEntries());
166 int numberOfTracks = 0;
168 for (
int i=0; i<numberOfTracks; i++) {
170 if (
filter( track )==
true ) {
172 if (global_idx >= 0 && globals_stored[global_idx]==0) {
176 globals_stored[global_idx] = 1;
178 addType(
mArrays[muPrimary], *track );
183 for (
int i=0; i<numberOfTracks; i++) {
187 addType(
mArrays[muGlobal], *track);
200 addType( muDst->
emcArray(muEmcTow), mEmcArrays[muEmcTow], typeOfTowerData );
201 if (mEmcArrays[muEmcTow]->GetEntries()) {
209 addType( muDst->
emcArray(muEmcPrs), mEmcArrays[muEmcPrs], typeOfEmcHit );
210 addType( muDst->
emcArray(muEmcSmde), mEmcArrays[muEmcSmde], typeOfEmcHit );
211 addType( muDst->
emcArray(muEmcSmdp), mEmcArrays[muEmcSmdp], typeOfEmcHit );
214 addType( muDst->
emcArray(muEEmcPrs), mEmcArrays[muEEmcPrs], typeOfEmcHit );
215 addType( muDst->
emcArray(muEEmcSmdu), mEmcArrays[muEEmcSmdu], typeOfEmcHit );
216 addType( muDst->
emcArray(muEEmcSmdv), mEmcArrays[muEEmcSmdv], typeOfEmcHit );
221 if (
mArrays[muPrimary]->GetEntries()>0) {
222 mTTree->Fill(); THack::IsTreeWritable(mTTree);
228 int StMuDstFilterMaker::addType(TClonesArray* tcaTo , T t) {
231 counter = tcaTo->GetEntries();
232 new((*tcaTo)[counter]) T( t );
238 int StMuDstFilterMaker::addType(TClonesArray* tcaFrom, TClonesArray* tcaTo ,T *t) {
239 if (tcaFrom && tcaTo) {
240 int n = tcaFrom->GetEntries();
241 int counter = tcaTo->GetEntries();
242 for (
int i=0; i<n;i++) {
243 new((*tcaTo)[counter++]) T( *(T*)(
void*)tcaFrom->UncheckedAt(i) );
270 for (
int i=0; i<__NARRAYS__; i++) {
276 #ifndef __NO_STRANGE_MUDST__
277 for (
int i=0; i<__NSTRANGEARRAYS__; i++) {
279 mStrangeArrays[i] = 0;
280 mStrangeArrays[i]= mMuDstMaker->clonesArray(mStrangeArrays[i],StMuArrays::strangeArrayTypes[i],StMuArrays::strangeArraySizes[i],dummy);
283 for (
int i=0; i<__NEMCARRAYS__; i++) {
286 mEmcArrays[i]= mMuDstMaker->clonesArray(mEmcArrays[i],StMuArrays::emcArrayTypes[i],StMuArrays::emcArraySizes[i],dummy);
293 for (
int i=0; i<__NARRAYS__; i++) {
296 #ifndef __NO_STRANGE_MUDST__
297 for (
int i=0; i<__NSTRANGEARRAYS__; i++) {
299 mStrangeArrays[i]->Clear();
302 for (
int i=0; i<__NEMCARRAYS__; i++) {
304 mEmcArrays[i]->Clear();
316 return ( track->
p().mag()>1. ) && ( fabs(track->
eta())<1.0 );
static StMuPrimaryVertex * primaryVertex()
return pointer to current primary vertex
Int_t mFilterGlobals
If set, keep also globals that fulfill cuts, while primary does not.
static TObjArray * globalTracks()
returns pointer to the global tracks list
Int_t mDoBemc
Copy barrel data (if it passes cuts)
Int_t index2Global() const
Returns index of associated global track. If not in order can be set with StMuDst::fixTrackIndeces() ...
static const char * arrayTypes[__NALLARRAYS__]
< names of the classes, the TClonesArrays are arrays of this type
int Make()
Filters the muDst and writes the filtered version.
StMuDstFilterMaker(const char *name="muDstFilter")
Default constructor; get pointer to StMuDstMaker.
void setIndex2Global(Int_t i)
Set index of associated global track.
TClonesArray * mArrays[__NARRAYS__]
the list of TClonesArrays to copy
int Finish()
Writes and closes the output file.
void open(const Char_t *)
const StThreeVectorF & p() const
Returns 3-momentum at dca to primary vertex.
Double_t eta() const
Returns pseudo rapidity at point of dca to primary vertex.
static TObjArray * primaryTracks()
returns pointer to a list of tracks belonging to the selected primary vertex
static StMuEmcCollection * muEmcCollection()
returns pointer to current StMuEmcCollection
static StMuEvent * event()
returns pointer to current StMuEvent (class holding the event wise information, e.g. event number, run number)
TChain * chain()
In read mode, returns pointer to the chain of .MuDst.root files that where selected.
Int_t mDoEemc
Copy endcap data (if it passes cuts)
static int arraySizes[__NALLARRAYS__]
< maximum sizes of the TClonesArrays
bool filter(T *t)
specialize this function to apply filters to the individual branches
static TClonesArray * emcArray(int type)
returns pointer to the n-th TClonesArray from the emc arrays