18 double const Rcut = 445.0 /2.0;
double const Xcut = 430.0 /2.0;
19 double r = sqrt( z*z + y*y );
20 if ( r > Rcut )
return false;
21 if (fabs(x) > Xcut )
return false;
29 #define writeECAL true 30 #define killNoRecoVerts true 54 int maxNfiles = -1;
string outName, SearchDir;
bool gotOutDir =
false;
56 while ((iArg < argc) && (argv[iArg][0] ==
'-')){
57 switch (argv[iArg][1]) {
60 maxNfiles = atoi(argv[iArg+1]);
61 cout <<
"Only processing " << maxNfiles <<
" files." <<
endl;
63 cout <<
"Wait! " << maxNfiles <<
"files! That's not right!" <<
endl;
70 PmagCut = std::stof(argv[iArg+1]);
71 cout <<
"Removing tracks and vertices with tracks with P below " <<
78 SearchDir = argv[iArg+1];
86 outName = argv[iArg+1];
93 cout <<
"[-h] This message" <<
endl;
94 cout <<
"[-o name] Name for output files; TTree will be in <name>.root," <<
endl;
95 cout <<
" statistics will be in <name>.txt. Environmental" <<
endl;
96 cout <<
" variables in <name> will be expanded." <<
endl;
97 cout <<
"[-f n] Analyze n background files, max" <<
endl;
98 cout <<
"[-c m] Set Ptrk cut to Ptrk > m MeV for output." <<
endl;
99 cout <<
" The default cut is 150 MeV." <<
endl;
100 cout <<
"[-L name] Input files from directory <name> without using" <<
endl;
101 cout <<
" xrootd rather than from files in $PWD, with" <<
endl;
102 cout <<
" xrootd, which is the default." <<
endl;
108 cout <<
"Did not see -o <dir> so no output directory selected." <<
endl;
116 vector<string> fileList;
121 LookFor =
"anatree_*.root";
122 fileList =
globbing(SearchDir +LookFor);
123 nFiles = (
int)fileList.size();
124 string newAccess =
"root://fndca1.fnal.gov:1094/pnfs/fnal.gov/usr";
125 string PWD =
getenv(
"PWD"); PWD.erase(0,5); PWD +=
"/";
128 for (
int iFile=0; iFile<
nFiles; ++iFile) {
129 fileList[iFile].insert(0,newAccess);
132 LookFor =
"anatree_*.root";
133 fileList =
globbing(SearchDir +LookFor);
134 nFiles = (
int)fileList.size();
136 cout << ( nFiles = (
int)fileList.size() ) <<
" total files found.\n";
137 if (nFiles==0) exit(1);
139 if ( maxNfiles>0 && maxNfiles<nFiles) {
147 string RootOutName = outName +
".root";
149 cout <<
"Already existing " << RootOutName <<
endl;
152 outFile = TFile::Open(RootOutName.c_str(),
"NEW");
153 if (
outFile->IsZombie()) {cout <<
"Eat you brains!" <<
endl;
return 1;};
156 outTree =
new TTree(
"GArAnaTree",
"GArAnaTree");
160 time_t unixT;
struct tm* localT;
161 time(&unixT); localT = localtime(&unixT);
162 cout <<
"Starting at " << asctime(localT) <<
endl;
164 for (
int iFile=0; iFile<
nFiles; ++iFile) {
165 cout <<
"Reading file " << iFile+1 <<
": " << fileList[iFile].c_str() <<
" ";
166 inFile = TFile::Open(fileList[iFile].c_str(),
"READ");
168 cout <<
"...but that file can not be opened!" <<
endl;
172 size_t strtLoc = fileList[iFile].find(
"_") +1;
173 size_t lenLoc = fileList[iFile].find(
".root") -strtLoc;
175 string numberAsString = fileList[iFile].substr(strtLoc,lenLoc);
176 sscanf(numberAsString.c_str(),
"%d", &fileNumber);
178 TDirectory*
dir = (TDirectory*)(
inFile)->Get(
"anatree");
179 dir->GetObject(
"GArAnaTree",
inTree);
186 time(&unixT); localT = localtime(&unixT);
187 cout <<
"Stopping at " << asctime(localT) <<
endl;
191 string TextOutName = outName +
".txt";
192 #define OUTDEV TextFileOut 193 std::ofstream TextFileOut(TextOutName.c_str());
195 cout << endl <<
endl;
244 if (firstCall)
outTree->Branch(
"FileNumber",&fFileNumber,
"FileNumber/I");
248 if (firstCall)
outTree->Branch(
"Event",&fEvent,
"Event/I");
253 vector<Int_t> fNType;
254 if (firstCall)
outTree->Branch(
"NType",&fNType);
258 if (firstCall)
outTree->Branch(
"Mode",&fMode);
262 if (firstCall)
outTree->Branch(
"InterT",&fInterT);
265 vector<Float_t> fMCVertX;
266 if (firstCall)
outTree->Branch(
"MCVertX",&fMCVertX);
269 vector<Float_t> fMCVertY;
270 if (firstCall)
outTree->Branch(
"MCVertY",&fMCVertY);
273 vector<Float_t> fMCVertZ;
274 if (firstCall)
outTree->Branch(
"MCVertZ",&fMCVertZ);
277 vector<Float_t> fMCNuPx;
278 if (firstCall)
outTree->Branch(
"MCNuPx",&fMCNuPx);
281 vector<Float_t> fMCNuPy;
282 if (firstCall)
outTree->Branch(
"MCNuPy",&fMCNuPy);
285 vector<Float_t> fMCNuPz;
286 if (firstCall)
outTree->Branch(
"MCNuPz",&fMCNuPz);
289 vector<Float_t> fMC_T;
290 if (firstCall)
outTree->Branch(
"MC_T",&fMC_T);
296 if (firstCall)
outTree->Branch(
"PDG",&fPDG);
299 vector<Int_t> fPDGMother;
300 if (firstCall)
outTree->Branch(
"PDGMother",&fPDGMother);
303 vector<Float_t> fMCPStartX;
304 if (firstCall)
outTree->Branch(
"MCPStartX",&fMCPStartX);
307 vector<Float_t> fMCPStartY;
308 if (firstCall)
outTree->Branch(
"MCPStartY",&fMCPStartY);
311 vector<Float_t> fMCPStartZ;
312 if (firstCall)
outTree->Branch(
"MCPStartZ",&fMCPStartZ);
315 vector<Float_t> fMCPStartPX;
316 if (firstCall)
outTree->Branch(
"MCPStartPX",&fMCPStartPX);
319 vector<Float_t> fMCPStartPY;
320 if (firstCall)
outTree->Branch(
"MCPStartPY",&fMCPStartPY);
323 vector<Float_t> fMCPStartPZ;
324 if (firstCall)
outTree->Branch(
"MCPStartPZ",&fMCPStartPZ);
329 TrackIDNumber(
inTree,
"TrackIDNumber",&iEntry);
330 vector<gar::rec::IDNumber> fTrackIDNumber;
331 if (firstCall)
outTree->Branch(
"TrackIDNumber",&fTrackIDNumber);
334 vector<Float_t> fTrackStartX;
335 if (firstCall)
outTree->Branch(
"TrackStartX",&fTrackStartX);
338 vector<Float_t> fTrackStartY;
339 if (firstCall)
outTree->Branch(
"TrackStartY",&fTrackStartY);
342 vector<Float_t> fTrackStartZ;
343 if (firstCall)
outTree->Branch(
"TrackStartZ",&fTrackStartZ);
346 vector<Float_t> fTrackStartPX;
347 if (firstCall)
outTree->Branch(
"TrackStartPX",&fTrackStartPX);
350 vector<Float_t> fTrackStartPY;
351 if (firstCall)
outTree->Branch(
"TrackStartPY",&fTrackStartPY);
354 vector<Float_t> fTrackStartPZ;
355 if (firstCall)
outTree->Branch(
"TrackStartPZ",&fTrackStartPZ);
358 vector<Int_t> fTrackStartQ;
359 if (firstCall)
outTree->Branch(
"TrackStartQ",&fTrackStartQ);
362 vector<Float_t> fTrackEndX;
363 if (firstCall)
outTree->Branch(
"TrackEndX",&fTrackEndX);
366 vector<Float_t> fTrackEndY;
367 if (firstCall)
outTree->Branch(
"TrackEndY",&fTrackEndY);
370 vector<Float_t> fTrackEndZ;
371 if (firstCall)
outTree->Branch(
"TrackEndZ",&fTrackEndZ);
374 vector<Float_t> fTrackEndPX;
375 if (firstCall)
outTree->Branch(
"TrackEndPX",&fTrackEndPX);
378 vector<Float_t> fTrackEndPY;
379 if (firstCall)
outTree->Branch(
"TrackEndPY",&fTrackEndPY);
382 vector<Float_t> fTrackEndPZ;
383 if (firstCall)
outTree->Branch(
"TrackEndPZ",&fTrackEndPZ);
386 vector<Int_t> fTrackEndQ;
387 if (firstCall)
outTree->Branch(
"TrackEndQ",&fTrackEndQ);
392 vector<Float_t> fTrackLenF;
393 if (firstCall)
outTree->Branch(
"TrackLenF",&fTrackLenF);
396 vector<Float_t> fTrackLenB;
397 if (firstCall)
outTree->Branch(
"TrackLenB",&fTrackLenB);
400 vector<Int_t> fNTPCClustersOnTrack;
401 if (firstCall)
outTree->Branch(
"NTPCClustersOnTrack",&fNTPCClustersOnTrack);
404 vector<Float_t> fTrackAvgIonF;
405 if (firstCall)
outTree->Branch(
"TrackAvgIonF",&fTrackAvgIonF);
408 vector<Float_t> fTrackAvgIonB;
409 if (firstCall)
outTree->Branch(
"TrackAvgIonB",&fTrackAvgIonB);
414 VertIDNumber(
inTree,
"VertIDNumber",&iEntry);
415 vector<gar::rec::IDNumber> fVertIDNumber;
416 if (firstCall)
outTree->Branch(
"VertIDNumber",&fVertIDNumber);
419 vector<Float_t> fVertX;
420 if (firstCall)
outTree->Branch(
"VertX",&fVertX);
423 vector<Float_t> fVertY;
424 if (firstCall)
outTree->Branch(
"VertY",&fVertY);
427 vector<Float_t> fVertZ;
428 if (firstCall)
outTree->Branch(
"VertZ",&fVertZ);
431 vector<Int_t> fVertN;
432 if (firstCall)
outTree->Branch(
"VertN",&fVertN);
435 vector<Int_t> fVertQ;
436 if (firstCall)
outTree->Branch(
"VertQ",&fVertQ);
441 VT_VertIDNumber(
inTree,
"VT_VertIDNumber",&iEntry);
442 vector<gar::rec::IDNumber> fVT_VertIDNumber;
443 if (firstCall)
outTree->Branch(
"VT_VertIDNumber",&fVT_VertIDNumber);
446 VT_TrackIDNumber(
inTree,
"VT_TrackIDNumber",&iEntry);
447 vector<gar::rec::IDNumber> fVT_TrackIDNumber;
448 if (firstCall)
outTree->Branch(
"VT_TrackIDNumber",&fVT_TrackIDNumber);
451 VT_TrackEnd(
inTree,
"VT_TrackEnd",&iEntry);
452 vector<gar::rec::TrackEnd> fVT_TrackEnd;
453 if (firstCall)
outTree->Branch(
"VT_TrackEnd",&fVT_TrackEnd);
459 ClusterIDNumber(
inTree,
"ClusterIDNumber",&iEntry);
460 vector<gar::rec::IDNumber> fClusterIDNumber;
461 if (firstCall)
outTree->Branch(
"ClusterIDNumber",&fClusterIDNumber);
464 vector<UInt_t> fClusterNhits;
465 if (firstCall)
outTree->Branch(
"ClusterNhits",&fClusterNhits);
468 vector<Float_t> fClusterEnergy;
469 if (firstCall)
outTree->Branch(
"ClusterEnergy",&fClusterEnergy);
472 vector<Float_t> fClusterX;
473 if (firstCall)
outTree->Branch(
"ClusterX",&fClusterX);
476 vector<Float_t> fClusterY;
477 if (firstCall)
outTree->Branch(
"ClusterY",&fClusterY);
480 vector<Float_t> fClusterZ;
481 if (firstCall)
outTree->Branch(
"ClusterZ",&fClusterZ);
486 ECALAssn_ClusIDNumber(
inTree,
"ECALAssn_ClusIDNumber",&iEntry);
487 vector<gar::rec::IDNumber> fECALAssn_ClusIDNumber;
488 if (firstCall)
outTree->Branch(
"ECALAssn_ClusIDNumber",&fECALAssn_ClusIDNumber);
491 ECALAssn_TrackIDNumber(
inTree,
"ECALAssn_TrackIDNumber",&iEntry);
492 vector<gar::rec::IDNumber> fECALAssn_TrackIDNumber;
493 if (firstCall)
outTree->Branch(
"ECALAssn_TrackIDNumber",&fECALAssn_TrackIDNumber);
496 ECALAssn_TrackEnd(
inTree,
"ECALAssn_TrackEnd",&iEntry);
497 vector<gar::rec::TrackEnd> fECALAssn_TrackEnd;
498 if (firstCall)
outTree->Branch(
"ECALAssn_TrackEnd",&fECALAssn_TrackEnd);
504 Long64_t nEntry =
inTree->GetEntries();
505 cout <<
"nEntry: " << nEntry <<
"\t Run Number: " << fileNumber <<
endl;
506 for (iEntry=0; iEntry<nEntry; ++iEntry) {
514 fFileNumber = fileNumber;
578 fECALAssn_ClusIDNumber = ECALAssn_ClusIDNumber.
getDataVector();
579 fECALAssn_TrackIDNumber = ECALAssn_TrackIDNumber.
getDataVector();
586 Float_t XvertMC, YvertMC, ZvertMC;
587 int nMCVerts = MCVertX.
size();
588 for (
int iMCVert=0; iMCVert<nMCVerts; ++iMCVert) {
589 XvertMC = MCVertX.
getData(iMCVert);
590 YvertMC = MCVertY.
getData(iMCVert);
591 ZvertMC = MCVertZ.
getData(iMCVert);
594 int interType = InterT.
getData(iMCVert);
611 #ifdef killNoRecoVerts 612 if (fVertIDNumber.size()==0)
continue;
639 int nTracks = fTrackIDNumber.size();
640 for (
int iTrack=0; iTrack<nTracks; ++iTrack) {
641 Float_t Pstart =
Qadd(fTrackStartPX[iTrack],fTrackStartPY[iTrack],fTrackStartPZ[iTrack]);
642 Float_t Pend =
Qadd(fTrackEndPX[iTrack], fTrackEndPY[iTrack], fTrackEndPZ[iTrack]);
644 itTrackIDNumber = fTrackIDNumber.erase(itTrackIDNumber);
645 itTrackStartX = fTrackStartX.erase(itTrackStartX);
646 itTrackStartY = fTrackStartY.erase(itTrackStartY);
647 itTrackStartZ = fTrackStartZ.erase(itTrackStartZ);
648 itTrackStartPX = fTrackStartPX.erase(itTrackStartPX);
649 itTrackStartPY = fTrackStartPY.erase(itTrackStartPY);
650 itTrackStartPZ = fTrackStartPZ.erase(itTrackStartPZ);
651 itTrackStartQ = fTrackStartQ.erase(itTrackStartQ);
652 itTrackEndX = fTrackEndX.erase(itTrackEndX);
653 itTrackEndY = fTrackEndY.erase(itTrackEndY);
654 itTrackEndZ = fTrackEndZ.erase(itTrackEndZ);
655 itTrackEndPX = fTrackEndPX.erase(itTrackEndPX);
656 itTrackEndPY = fTrackEndPY.erase(itTrackEndPY);
657 itTrackEndPZ = fTrackEndPZ.erase(itTrackEndPZ);
658 itTrackEndQ = fTrackEndQ.erase(itTrackEndQ);
659 itTrackLenF = fTrackLenF.erase(itTrackLenF);
660 itTrackLenB = fTrackLenB.erase(itTrackLenB);
661 itNTPCClustersOnTrack = fNTPCClustersOnTrack.erase(itNTPCClustersOnTrack);
662 itTrackAvgIonF = fTrackAvgIonF.erase(itTrackAvgIonF);
663 itTrackAvgIonB = fTrackAvgIonB.erase(itTrackAvgIonB);
667 ++itTrackStartX; ++itTrackStartY; ++itTrackStartZ;
668 ++itTrackStartPX; ++itTrackStartPY; ++itTrackStartPZ; ++itTrackStartQ;
669 ++itTrackEndX; ++itTrackEndY; ++itTrackEndZ;
670 ++itTrackEndPX; ++itTrackEndPY; ++itTrackEndPZ; ++itTrackEndQ;
671 ++itTrackLenF; ++itTrackLenB; ++itNTPCClustersOnTrack;
672 ++itTrackAvgIonF; ++itTrackAvgIonB;
675 if (fTrackIDNumber.size()==0)
continue;
680 std::list<gar::rec::IDNumber> deadVertex;
681 int nAssns = fVT_VertIDNumber.size();
682 for (
int iAssn=0; iAssn<nAssns; ++iAssn) {
685 found = std::find(fTrackIDNumber.begin(),fTrackIDNumber.end(), thisIDNumber);
686 if ( found == fTrackIDNumber.end() ) {
688 deadVertex.push_back(fVT_VertIDNumber[iAssn]);
691 if (deadVertex.size()>0) {
696 deadEnd = std::unique(deadVertex.begin(),deadVertex.end());
707 int nVerts = fVertIDNumber.size();
708 for (
int iVert=0; iVert<nVerts; ++iVert) {
711 found = std::find(deadStart,deadEnd, thisIDNumber);
712 if ( found != deadEnd ) {
714 itVertIDNumber = fVertIDNumber.erase(itVertIDNumber);
715 itVertX = fVertX.erase(itVertX);
716 itVertY = fVertY.erase(itVertY);
717 itVertZ = fVertZ.erase(itVertZ);
718 itVertN = fVertN.erase(itVertN);
719 itVertQ = fVertQ.erase(itVertQ);
723 ++itVertX; ++itVertY; ++itVertZ; ++itVertN; ++itVertQ;
726 #ifdef killNoRecoVerts 727 if (fVertIDNumber.size()==0)
continue;
736 for (
int iAssn=0; iAssn<nAssns; ++iAssn) {
739 found = std::find(deadStart,deadEnd, thisIDNumber);
740 if ( found != deadEnd ) {
742 itVT_VertIDNumber = fVT_VertIDNumber.erase(itVT_VertIDNumber);
743 itVT_TrackIDNumber = fVT_TrackIDNumber.erase(itVT_TrackIDNumber);
744 itVT_TrackEnd = fVT_TrackEnd.erase(itVT_TrackEnd);
747 ++itVT_VertIDNumber; ++itVT_TrackIDNumber; ++itVT_TrackEnd;
758 nAssns = fECALAssn_ClusIDNumber.size();
759 for (
int iAssn=0; iAssn<nAssns; ++iAssn) {
762 found = std::find(fTrackIDNumber.begin(),fTrackIDNumber.end(), thisIDNumber);
763 if ( found == fTrackIDNumber.end() ) {
765 itECALAssn_ClusIDNumber = fECALAssn_ClusIDNumber.erase(itECALAssn_ClusIDNumber);
766 itECALAssn_TrackIDNumber = fECALAssn_TrackIDNumber.erase(itECALAssn_TrackIDNumber);
767 itECALAssn_TrackEnd = fECALAssn_TrackEnd.erase(itECALAssn_TrackEnd);
770 ++itECALAssn_ClusIDNumber; ++itECALAssn_TrackIDNumber; ++itECALAssn_TrackEnd;
neutral current quasi-elastic
charged current deep inelastic scatter
neutrino electron elastic scatter
int main(int argc, const char *argv[])
bool inFiducial(double x, double y, double z)
double Qadd(double const x, double const y)
vector< T > & getDataVector()
offset to account for adding in Nuance codes to this enum
charged current quasi-elastic
bool filehamna(const std::string &filename)
void TransMogrifyTree(int fileNumber, bool firstCall)
std::vector< std::string > globbing(const std::string &pat)
std::string getenv(std::string const &name)
charged current deep inelastic scatter
resonant charged current, nu p -> l- p pi+
charged current coherent pion
QTextStream & endl(QTextStream &s)