6 #include "TLorentzVector.h" 10 #include "TEntryList.h" 21 #include "Mint/MinimalEventList.h" 30 template <
typename T,
typename N>
73 std::string newFilename()
const;
77 , std::string ntpName =
"DalitzEventList" 78 ,
const char* cuts =
"" 79 ,
long int maxEvents = -1
86 , _maxEvents(maxEvents)
90 , _entries(1000000000)
94 for (
int i = 0; i < 5; i++) {
96 for (
int j = 0; j < 5; j++) {
99 m_input_var.push_back(row);
102 for (
int i = 0; i < 4; i++) {
104 m_mother_var.push_back(0);
105 m_slowPion_var.push_back(0);
113 _applyFiducalCuts =
false;
115 SetEventPattern(pat);
125 TFile* f = TFile::Open(_fname.c_str(),
"READ");
126 if(0 == f)
return false;
127 _oldTree = dynamic_cast<TTree*>(f->Get(_ntpName.c_str()));
128 return (0 != _oldTree);
132 bool SetDaughterBranchAddress(
const char* Px,
const char* Py,
const char* Pz,
const char* E,
const char* pdg );
133 bool SetMotherBranchAddress(
const char* Px,
const char* Py,
const char* Pz,
const char* E,
const char* pdg );
134 void AddSlowPion(
const char* Px =
"SlowPion_PX",
const char* Py=
"SlowPion_PY",
135 const char* Pz=
"SlowPion_PZ",
const char* E=
"SlowPion_E",
136 const char* pdg =
"SlowPion_ID" );
144 void ApplyFiducalCuts();
145 bool passFiducalCuts(
unsigned int entry);
146 bool passedFidCuts(
float dx,
float dy,
float dz);
148 bool AddFriend(std::string fname
149 , std::string ntpName);
151 bool getUpdatedTree();
155 void weightVarName(std::string weightName);
158 bool readit(MinimalEventList<DalitzEvent>* listPtr,
int nEvents=-1,
double scale = 1.0);
160 bool testEventPattern();
161 bool passETAcut(
unsigned int entry);
173 template <
typename T,
typename N>
178 string newFilename(_fname);
179 newFilename.insert(newFilename.find_last_of(
'.'),
"_reweighted");
182 checkFile.open( newFilename.c_str(), ios::in );
183 exists = ! checkFile.fail();
190 template <
typename T,
typename N>
192 , std::string ntpName)
194 if (fname ==
"" || ntpName ==
"")
196 std::cout <<
"No friend Specified" << std::endl;
199 TFile* f = TFile::Open(fname.c_str(),
"READ");
200 if(0 == f)
return false;
201 friendTree = dynamic_cast<TTree*>(f->Get(ntpName.c_str()));
202 _oldTree->AddFriend(friendTree);
203 return (0 != _oldTree);
215 template <
typename T,
typename N>
221 _oldTree->SetBranchStatus(
"*",1);
222 if (_cuts&&strcmp(_cuts,
"")!=0) {
223 _oldTree->Draw(
">>elist",_cuts,
"entryList");
224 elist = (TEntryList*)gDirectory->Get(
"elist");
227 std::stringstream msg;
228 msg <<
"Failed to retrieve TEntryList for cuts " << _cuts;
231 _oldTree->SetEntryList(elist);
233 Long64_t nentries = !elist?_oldTree->GetEntries():elist->GetN();
235 std::cout <<
"No entries after cuts " << _cuts << std::endl;
241 _file0 = TFile::Open(newFilename().c_str(),
"RECREATE");
242 cout <<
"opened new file " << _file0 << endl;
243 if(0 == _file0)
return false;
245 cout <<
"cd'ed to new file " << endl;
247 std::cout <<
"Cuts: " << _cuts << std::endl;
249 _tree = _oldTree->CopyTree(_cuts,
"",_entries,_firstentry);
264 template <
typename T,
typename N>
267 _applyFiducalCuts =
true;
270 template <
typename T,
typename N>
273 bool passCuts =
true;
274 if (fabs(dx) > 0.317*(dz - 2400))
278 if (fabs(dy/dz) < 0.02){
281 double beta1 = 0.01397;
282 double beta2 = 0.01605;
283 if( ( (p1 - beta1*dz) < fabs(dx) ) || ( fabs(dx) < ( p2+ beta2*dz ) ))
296 template <
typename T,
typename N>
299 _tree->GetEntry(entry);
300 bool passCuts =
true;
303 for (
int i = 0; i<4; i++)
305 float dx = m_input_var[0][i];
306 float dy = m_input_var[1][i];
307 float dz = m_input_var[2][i];
308 if (!passedFidCuts(dx,dy,dz)) passCuts =
false;
313 if (!passedFidCuts(m_slowPion_var[0],m_slowPion_var[1],m_slowPion_var[2])) passCuts =
false;
318 template <
typename T,
typename N>
322 _oldTree->SetBranchAddress(Px,&m_input_var[0][m_particle]);
323 _oldTree->SetBranchAddress(Py,&m_input_var[1][m_particle]);
324 _oldTree->SetBranchAddress(Pz,&m_input_var[2][m_particle]);
325 _oldTree->SetBranchAddress(E,&m_input_var[3][m_particle]);
326 _oldTree->SetBranchAddress(pdg,&m_pdg[m_particle]);
332 template <
typename T,
typename N>
336 _oldTree->SetBranchAddress(Px,&m_mother_var[0]);
337 _oldTree->SetBranchAddress(Py,&m_mother_var[1]);
338 _oldTree->SetBranchAddress(Pz,&m_mother_var[2]);
339 _oldTree->SetBranchAddress(E,&m_mother_var[3]);
340 _oldTree->SetBranchAddress(pdg,&m_mother_pdg);
345 template <
typename T,
typename N>
354 _tree->GetEntry(entry);
356 if (set_pat.size() == 0)
358 std::cout <<
"Could not find EventPattern Did you set it?" << std::endl;
384 TLorentzVector mother(m_mother_var[0],m_mother_var[1],m_mother_var[2],m_mother_var[3]);
387 TLorentzVector daughter1(m_input_var[0][0],m_input_var[1][0],m_input_var[2][0],m_input_var[3][0]);
388 TLorentzVector daughter2(m_input_var[0][1],m_input_var[1][1],m_input_var[2][1],m_input_var[3][1]);
389 TLorentzVector daughter3(m_input_var[0][2],m_input_var[1][2],m_input_var[2][2],m_input_var[3][2]);
390 TLorentzVector daughter4(m_input_var[0][3],m_input_var[1][3],m_input_var[2][3],m_input_var[3][3]);
392 std::vector<TLorentzVector> daughter;
393 daughter.push_back(daughter1);
394 daughter.push_back(daughter2);
395 daughter.push_back(daughter3);
396 daughter.push_back(daughter4);
402 cout <<
"PDG: " << (int)m_pdg[0] <<
" Px: " << m_input_var[0][0] << std::endl;
403 cout <<
"PDG: " << (int)m_pdg[1] <<
" Px: " << m_input_var[0][1] << std::endl;
404 cout <<
"PDG: " << (int)m_pdg[2] <<
" Px: " << m_input_var[0][2] << std::endl;
405 cout <<
"PDG: " << (int)m_pdg[3] <<
" Px: " << m_input_var[0][3] << std::endl;
406 cout <<
"Mother PDG: " << m_mother_pdg <<
" Px: " << m_mother_var[0] << std::endl;
411 vector<TLorentzVector> PArray(5);
413 TLorentzVector* pMother = &(PArray[0]);
417 pdgArray[0] = (int)m_mother_pdg;
424 std::cout <<
"PArray Px: " << PArray[0].Px() << std::endl;
425 std::cout <<
"Mother Px: " << mother.Px() << std::endl;
428 std::vector<int> passed_pat = set_pat;
429 std::vector<T> this_pat = m_pdg;
434 for (
int i = 0; i < 4; i++)
436 cout <<
"this_pat: " << (int)this_pat[i] <<
" passed pat:" << passed_pat[i];
443 for (
int j =1; j<5; j++)
445 for (
int i = 0; i < 4; i++)
451 cout <<
"Pdg: " << passed_pat[j] <<
" " << (int)this_pat[i];
455 if (passed_pat[j] == (
int)this_pat[i])
457 pdgArray[j] = (int)this_pat[i];
458 PArray[j] = daughter[i];
464 cout <<
"Pdg: " << passed_pat[j];
465 cout <<
" Px: " << PArray[j].Px() << std::endl;
474 for (
int i = 1; i < 4; i++)
476 for (
int j = i+1; j < 5; j++)
478 if( pdgArray[i] == pdgArray[j])
483 swap(PArray[i],PArray[j] );
484 swap(pdgArray[i],pdgArray[j] );
494 for(
unsigned int i = 0; i < 5; i++){
495 cout <<
" mass " << i <<
") " << PArray[i].M()
496 <<
" Px " << i <<
") " << PArray[i].Px()
497 <<
" Py " << i <<
") " << PArray[i].Py()
498 <<
" Pz " << i <<
") " << PArray[i].Pz()
499 <<
" E " << i <<
") " << PArray[i].E()
500 <<
", pdg " << pdgArray[i] << endl;
506 for(
unsigned int i = 0; i < 5; i++){
507 cout <<
" mass " << i <<
") " << PArray[i].M()
508 <<
" Px " << i <<
") " << PArray[i].Px()
509 <<
", pdg " << pdgArray[i] << endl;
513 _pMother.SetPxPyPzE(m_mother_var[0], m_mother_var[1], m_mother_var[2], m_mother_var[3]);
520 template <
typename T,
typename N>
526 template <
typename T,
typename N>
529 m_weightName = weightName;
532 template <
typename T,
typename N>
535 if(0 == listPtr)
return false;
539 if (!testEventPattern())
return false;
544 _tree->SetBranchAddress(m_weightName.c_str(),&weight);
546 std::cout <<
"Entries " << _oldTree->GetEntries() <<
" " << _tree->GetEntries() << std::endl;
547 for(
unsigned int i=0; i < _tree->GetEntries(); i++){
549 if (Rand.Rndm() < scale)
551 if (_applyFiducalCuts)
553 if (passFiducalCuts(i))
564 listPtr->
Add(*(evtPtr.
get()));
568 if (!_applyFiducalCuts)
579 listPtr->
Add(*(evtPtr.
get()));
583 std::cout <<
"Not allowed " << std::endl;
587 if(maxEvents > 0 && numEvents > maxEvents)
break;
593 template <
typename T,
typename N>
597 if ((
int)set_pat[0] != (
int)m_mother_pdg)
599 cout <<
"Mother Pattern not the same try CC" << endl;
600 cout <<
" set_pat " << set_pat[0] <<
" " << set_pat[1];
601 cout <<
" " << set_pat[2] <<
" " << set_pat[3] << std::endl;
603 cout <<
" m_mother_pdg " << m_mother_pdg <<
" " << endl;
607 set_pat = m_pat->getVectorOfInts();
609 if ((
int)set_pat[0] != (
int)m_mother_pdg)
611 cerr <<
" set_pat " << set_pat[0] << std::endl;
612 cerr <<
"Mother Pattern STILL not the same" << endl;
613 cerr <<
"Will try other entry" << endl;
615 if (set_pat[0] != m_mother_pdg)
617 cout <<
"Mother Pattern not the same try CC" << endl;
618 cout <<
" set_pat " << set_pat[0] <<
" " << set_pat[1];
619 cout <<
" " << set_pat[2] <<
" " << set_pat[3] << std::endl;
621 cout <<
" m_mother_pdg " << m_mother_pdg <<
" " << endl;
625 set_pat = m_pat->getVectorOfInts();
627 if (set_pat[0] != m_mother_pdg)
629 cerr <<
" set_pat " << set_pat[0] << std::endl;
630 cerr <<
"Mother Pattern STILL not the same" << endl;
639 template <
typename T,
typename N>
643 _oldTree->SetBranchAddress(Px,(
float*)&m_slowPion_var[0]);
644 _oldTree->SetBranchAddress(Py,(
float*)&m_slowPion_var[1]);
645 _oldTree->SetBranchAddress(Pz,(
float*)&m_slowPion_var[2]);
646 _oldTree->SetBranchAddress(E,(
float*)&m_slowPion_var[3]);
647 _oldTree->SetBranchAddress(pdg,(
int*)&m_slowPion_pdg);
652 template <
typename T,
typename N>
655 bool passETAcut =
false;
656 _tree->GetEntry(entry);
658 float dx = m_mother_var[0];
659 float dy = m_mother_var[1];
660 float dz = m_mother_var[2];
661 float P = sqrt(dx*dx+dy*dy+dz*dz);
662 float ETA = 0.5*log( (P + dz)/(P - dz) );
663 if (ETA < 5.0 && ETA > 2.0 ) passETAcut =
true;
664 if (P < 300000 ) passETAcut =
true;
virtual void setWeight(double w)
bool passFiducalCuts(unsigned int entry)
void weightVarName(std::string weightName)
bool SetDaughterBranchAddress(const char *Px, const char *Py, const char *Pz, const char *E, const char *pdg)
void useWeights(bool Weights)
bool exists(const string &fname)
std::vector< std::vector< N > > m_input_var
bool passETAcut(unsigned int entry)
virtual bool Add(const DalitzEvent &evt)
void AddSlowPion(const char *Px="SlowPion_PX", const char *Py="SlowPion_PY", const char *Pz="SlowPion_PZ", const char *E="SlowPion_E", const char *pdg="SlowPion_ID")
std::string newFilename() const
bool SetMotherBranchAddress(const char *Px, const char *Py, const char *Pz, const char *E, const char *pdg)
std::vector< N > m_slowPion_var
std::vector< int > getVectorOfInts() const
void SetFirstEntry(int firstEntry)
MINT::counted_ptr< DalitzEvent > readEntry(unsigned int entry)
bool readit(MinimalEventList< DalitzEvent > *listPtr, int nEvents=-1, double scale=1.0)
DalitzEventPattern * m_pat
bool passedFidCuts(float dx, float dy, float dz)
std::string anythingToString(const T &anything)
void print(std::ostream &os=std::cout) const
void SetEntries(int entries)
void SetEventPattern(DalitzEventPattern *pat)
ReadNTuple(DalitzEventPattern *pat, std::string fname, std::string ntpName="DalitzEventList", const char *cuts="", long int maxEvents=-1)
std::vector< N > m_mother_var
std::vector< int > set_pat
bool kinematicallyAllowed(double epsilon=1.e-9) const
bool AddFriend(std::string fname, std::string ntpName)