1 #include "CreateMiniTree.hxx" 2 #include "InputManager.hxx" 3 #include "FlatTreeConverter.hxx" 4 #include "HighlandMiniTreeConverter.hxx" 5 #include "oaAnalysisTreeConverter.hxx" 6 #include "Parameters.hxx" 7 #include "Versioning.hxx" 8 #include "GeometryManager.hxx" 9 #include "HighlandAnalysisUtils.hxx" 14 #include "CT4POTCorrection.hxx" 15 #include "DataQualityCorrection.hxx" 16 #include "PileUpCorrection.hxx" 17 #include "TPCdEdxDataCorrection.hxx" 18 #include "TPCdEdxMCCorrection.hxx" 19 #include "TPCExpecteddEdxCorrection.hxx" 20 #include "IgnoreRightECalRuns3and4Correction.hxx" 21 #include "UseGlobalAltMomCorrection.hxx" 22 #include "FlipKinematicsCorrection.hxx" 23 #include "ToFCorrection.hxx" 24 #include "MomResolMCCorrection.hxx" 25 #include "MomRangeCorrection.hxx" 26 #include "TPCPIDPullMCCorrection.hxx" 38 CreateMiniTree::CreateMiniTree(
int argc,
char *argv[]):
SimpleLoopBase(argc, argv){
42 ND::versioning().
AddProduction(ProdId::PROD5E,
"PROD5E",
"v10r11p17",
"v10r11p18");
43 ND::versioning().
AddProduction(ProdId::PROD5F,
"PROD5F",
"v10r11p19",
"v10r11p24");
44 ND::versioning().
AddProduction(ProdId::PROD5G,
"PROD5G",
"v10r11p27",
"v10r11p28");
45 ND::versioning().
AddProduction(ProdId::PROD6PRE,
"PROD6PRE",
"v11r17",
"v11r28");
46 ND::versioning().
AddProduction(ProdId::PROD6A,
"PROD6A",
"v11r29",
"v11r30");
47 ND::versioning().
AddProduction(ProdId::PROD6BC,
"PROD6B/6C",
"v11r31",
"v11r32");
49 ND::versioning().
AddProduction(ProdId::PROD7DEVEL,
"PROD7DEVEL",
"v12",
"v13");
69 _saveGeometry = (bool)ND::params().
GetParameterI(
"highlandIO.FlatTree.SaveGeometry");
72 _saveRoo = (bool)ND::params().
GetParameterI(
"highlandIO.FlatTree.SaveRooTracker");
75 _filterRoo = (bool)ND::params().
GetParameterI(
"highlandIO.FlatTree.FilterRooTracker");
77 _saveTPCInfo = (bool)ND::params().
GetParameterI(
"highlandIO.FlatTree.SaveTPCInfo");
78 _saveFGDInfo = (bool)ND::params().
GetParameterI(
"highlandIO.FlatTree.SaveFGDInfo");
79 _saveECALInfo = (bool)ND::params().
GetParameterI(
"highlandIO.FlatTree.SaveECALInfo");
80 _saveP0DInfo = (bool)ND::params().
GetParameterI(
"highlandIO.FlatTree.SaveP0DInfo");
81 _saveSMRDInfo = (bool)ND::params().
GetParameterI(
"highlandIO.FlatTree.SaveSMRDInfo");
82 _saveTrackerInfo = (bool)ND::params().
GetParameterI(
"highlandIO.FlatTree.SaveTrackerInfo");
85 _saveReconDirFGDOnlyInfo = (bool)ND::params().
GetParameterI(
"highlandIO.FlatTree.UseReconDirFGDOnly" );
86 _saveReconDirP0DInfo = (bool)ND::params().
GetParameterI(
"highlandIO.FlatTree.UseReconDirP0D" );
87 _saveReconDirPECALInfo = (bool)ND::params().
GetParameterI(
"highlandIO.FlatTree.UseReconDirP0DECal" );
88 _saveReconDirTECALInfo = (bool)ND::params().
GetParameterI(
"highlandIO.FlatTree.UseReconDirTrackerECal");
90 _useTPC1 = (bool)ND::params().
GetParameterI(
"highlandIO.FlatTree.UseTPC1");
91 _useTPC2 = (bool)ND::params().
GetParameterI(
"highlandIO.FlatTree.UseTPC2");
92 _useTPC3 = (bool)ND::params().
GetParameterI(
"highlandIO.FlatTree.UseTPC3");
93 _useFGD1 = (bool)ND::params().
GetParameterI(
"highlandIO.FlatTree.UseFGD1");
94 _useFGD2 = (bool)ND::params().
GetParameterI(
"highlandIO.FlatTree.UseFGD2");
95 _useP0D = (bool)ND::params().
GetParameterI(
"highlandIO.FlatTree.UseP0D");
96 _useDsECal = (bool)ND::params().
GetParameterI(
"highlandIO.FlatTree.UseDsECal");
97 _useTrECal = (bool)ND::params().
GetParameterI(
"highlandIO.FlatTree.UseTrECal");
98 _useP0DECal = (bool)ND::params().
GetParameterI(
"highlandIO.FlatTree.UseP0DECal");
99 _useSMRD = (bool)ND::params().
GetParameterI(
"highlandIO.FlatTree.UseSMRD");
101 _useTPC1outOfBunch = (bool)ND::params().
GetParameterI(
"highlandIO.FlatTree.UseTPC1outOfBunch");
102 _useTPC2outOfBunch = (bool)ND::params().
GetParameterI(
"highlandIO.FlatTree.UseTPC2outOfBunch");
103 _useTPC3outOfBunch = (bool)ND::params().
GetParameterI(
"highlandIO.FlatTree.UseTPC3outOfBunch");
104 _useFGD1outOfBunch = (bool)ND::params().
GetParameterI(
"highlandIO.FlatTree.UseFGD1outOfBunch");
105 _useFGD2outOfBunch = (bool)ND::params().
GetParameterI(
"highlandIO.FlatTree.UseFGD2outOfBunch");
106 _useP0DoutOfBunch = (bool)ND::params().
GetParameterI(
"highlandIO.FlatTree.UseP0DoutOfBunch");
107 _useDsECaloutOfBunch = (bool)ND::params().
GetParameterI(
"highlandIO.FlatTree.UseDsECaloutOfBunch");
108 _useTrECaloutOfBunch = (bool)ND::params().
GetParameterI(
"highlandIO.FlatTree.UseTrECaloutOfBunch");
109 _useP0DECaloutOfBunch = (bool)ND::params().
GetParameterI(
"highlandIO.FlatTree.UseP0DECaloutOfBunch");
110 _useSMRDoutOfBunch = (bool)ND::params().
GetParameterI(
"highlandIO.FlatTree.UseSMRDoutOfBunch");
112 _saveTrueNuNC = (bool)ND::params().
GetParameterI(
"highlandIO.FlatTree.TrueVertex.NuNC");
113 _saveTrueAntiNuNC = (bool)ND::params().
GetParameterI(
"highlandIO.FlatTree.TrueVertex.AntiNuNC");
114 _saveTrueNumuCC = (bool)ND::params().
GetParameterI(
"highlandIO.FlatTree.TrueVertex.NumuCC");
115 _saveTrueAntiNumuCC = (bool)ND::params().
GetParameterI(
"highlandIO.FlatTree.TrueVertex.AntiNumuCC");
116 _saveTrueNueCC = (bool)ND::params().
GetParameterI(
"highlandIO.FlatTree.TrueVertex.NueCC");
117 _saveTrueAntiNueCC = (bool)ND::params().
GetParameterI(
"highlandIO.FlatTree.TrueVertex.AntiNueCC");
120 if (ND::params().GetParameterI(
"highlandIO.FlatTree.TrueVertex.TPC1")) _saveTrueVertexInDet.push_back(SubDetId::kTPC1);
121 if (ND::params().GetParameterI(
"highlandIO.FlatTree.TrueVertex.TPC2")) _saveTrueVertexInDet.push_back(SubDetId::kTPC2);
122 if (ND::params().GetParameterI(
"highlandIO.FlatTree.TrueVertex.TPC3")) _saveTrueVertexInDet.push_back(SubDetId::kTPC3);
123 if (ND::params().GetParameterI(
"highlandIO.FlatTree.TrueVertex.FGD1")) _saveTrueVertexInDet.push_back(SubDetId::kFGD1);
124 if (ND::params().GetParameterI(
"highlandIO.FlatTree.TrueVertex.FGD2")) _saveTrueVertexInDet.push_back(SubDetId::kFGD2);
125 if (ND::params().GetParameterI(
"highlandIO.FlatTree.TrueVertex.P0D")) _saveTrueVertexInDet.push_back(SubDetId::kP0D);
126 if (ND::params().GetParameterI(
"highlandIO.FlatTree.TrueVertex.DsECal")) _saveTrueVertexInDet.push_back(SubDetId::kDSECAL);
127 if (ND::params().GetParameterI(
"highlandIO.FlatTree.TrueVertex.TrECal")) _saveTrueVertexInDet.push_back(SubDetId::kTECAL);
128 if (ND::params().GetParameterI(
"highlandIO.FlatTree.TrueVertex.P0DECal")) _saveTrueVertexInDet.push_back(SubDetId::kPECAL);
129 if (ND::params().GetParameterI(
"highlandIO.FlatTree.TrueVertex.SMRD")) _saveTrueVertexInDet.push_back(SubDetId::kSMRD);
142 versionUtils::prod6_bunching =
false;
143 versionUtils::prod6_corrections =
false;
144 versionUtils::prod6_systematics =
false;
146 if (ND::versioning().GetProduction(input().GetSoftwareVersion()) >= ProdId::PROD6PRE){
147 versionUtils::prod6_bunching =
true;
148 versionUtils::prod6_corrections =
true;
149 versionUtils::prod6_systematics =
true;
154 versionUtils::DumpProductions();
159 #if !VERSION_HAS_OFFICIAL_POT 162 if (ND::params().GetParameterI(
"highlandIO.FlatTree.EnablePOTCorrection")) {
170 #if !VERSION_HAS_EQUIVALENT_MAIN_AND_ALT_FITS 171 if (ND::params().GetParameterI(
"highlandIO.FlatTree.EnableUseMuonAltMomCorrection")) {
177 if (ND::params().GetParameterI(
"highlandIO.FlatTree.EnableDQCorrection")) {
182 if (ND::params().GetParameterI(
"highlandIO.FlatTree.EnablePileUpCorrection")){
186 if (ND::params().GetParameterI(
"highlandIO.FlatTree.EnableTPCdEdxDataCorrection")){
190 if (ND::params().GetParameterI(
"highlandIO.FlatTree.EnableTPCdEdxMCCorrection")){
194 if (ND::params().GetParameterI(
"highlandIO.FlatTree.EnableTPCExpecteddEdxCorrection")){
199 if (ND::params().GetParameterI(
"highlandIO.FlatTree.EnableTPCPIDPullMCCorrection")){
204 if (ND::params().GetParameterI(
"highlandIO.FlatTree.EnableIgnoreRightECalCorrection")){
209 if (ND::params().GetParameterI(
"highlandIO.FlatTree.EnableFlipKinematicsCorrection")){
213 if (ND::params().GetParameterI(
"highlandIO.FlatTree.EnableToFCorrection")){
217 if (ND::params().GetParameterI(
"highlandIO.FlatTree.EnableMomResolMCCorrection")){
221 if (ND::params().GetParameterI(
"highlandIO.FlatTree.EnableMomRangeCorrection")){
226 _file->mkdir(
"geom");
241 std::string rooTreeName=
"";
242 if(input().GetChain(
"NRooTrackerVtx"))
243 rooTreeName =
"NRooTrackerVtx";
244 else if (input().GetChain(
"GRooTrackerVtx"))
245 rooTreeName =
"GRooTrackerVtx";
247 if(_saveRoo && rooTreeName!=
""){
248 if (input().InputIsOriginalTree() && _filterRoo){
251 Vtx =
new TClonesArray((
"ND::"+rooTreeName).c_str(),100);
253 GetTree(RooTrackerVtx)->Branch(
"RunID", &RunID,
"RunID/I", 32000);
254 GetTree(RooTrackerVtx)->Branch(
"EventID", &EventID,
"EventID/I", 32000);
255 GetTree(RooTrackerVtx)->Branch(
"Preselected", &Preselected,
"Preselected/B", 32000);
256 GetTree(RooTrackerVtx)->Branch(
"SubrunID", &SubrunID,
"SubrunID/I", 32000);
258 GetTree(RooTrackerVtx)->Branch(
"NVtx", &NVtx,
"NVtx/I", 32000);
259 GetTree(RooTrackerVtx)->Branch(
"Vtx",
"TClonesArray", &Vtx , 32000, 1);
262 AddTreeWithName(RooTrackerVtx, rooTreeName,input().GetChain(rooTreeName));
270 GetTree(minitree)->Branch(
"Spill",
"AnaSpill", &_spill,64000,1);
272 _POTSincePreviousSavedSpill =0;
273 _SpillsSincePreviousSavedSpill=0;
282 SetFillSingleTree(minitree);
287 GetTree(minitree)->SetBranchAddress(
"Spill",&_spill );
290 _POTSincePreviousSavedSpill += _spill->Beam->POTSincePreviousSavedSpill;
291 _SpillsSincePreviousSavedSpill += _spill->Beam->SpillsSincePreviousSavedSpill;
294 DeleteUninterestingBunches();
296 _lastSpillSaved =
false;
299 if (_spill->Bunches.size()>0 || CheckTruthFillMiniTree(*_spill)){
302 if (_saveGeometry) WriteGeometry();
306 FillRooTrackerVtxTree();
312 _lastSpillSaved=
true;
323 if (_lastSpillSaved)
return;
327 FillRooTrackerVtxTree();
337 bool CreateMiniTree::CheckTruthFillMiniTree(
const AnaSpill& spill){
341 bool ok_reac =
false;
343 const std::vector<AnaTrueVertexB*>& vertices = spill.
TrueVertices;
344 for (std::vector<AnaTrueVertexB*>::const_iterator it = vertices.begin(); it!=vertices.end(); it++) {
348 ok_reac = CheckTrueVertexReaction(vtx);
352 ok_det = CheckTrueVertexDetector(vtx.
Detector);
355 if (ok_reac && ok_det)
return true;
362 bool CreateMiniTree::CheckTrueVertexReaction(
const AnaTrueVertex& vtx){
367 if (_saveTrueNuNC && vtx.
ReacCode>=+30 && abs(vtx.
ReacCode)!=70)
return true;
368 if (_saveTrueAntiNuNC && vtx.
ReacCode<=-30 && abs(vtx.
ReacCode)!=70)
return true;
377 bool CreateMiniTree::CheckTrueVertexDetector(
unsigned long det){
380 for (
unsigned int i = 0;i<_saveTrueVertexInDet.size();i++)
387 bool CreateMiniTree::CheckReconFillMiniTreeOutOfBunch(
const AnaBunchB& bunch){
390 for (std::vector<AnaParticleB*>::const_iterator it = bunch.
Particles.begin(); it!=bunch.
Particles.end(); it++) {
392 unsigned long bitfield = (*it)->Detector;
394 if (_useTPC1outOfBunch)
396 if (_useTPC2outOfBunch)
398 if (_useTPC3outOfBunch)
400 if (_useFGD1outOfBunch)
402 if (_useFGD2outOfBunch)
404 if (_useP0DoutOfBunch)
406 if (_useDsECaloutOfBunch)
408 if (_useTrECaloutOfBunch)
410 if (_useP0DECaloutOfBunch)
412 if (_useSMRDoutOfBunch)
420 bool CreateMiniTree::CheckReconFillMiniTree(
const AnaBunchB& bunch){
423 if (bunch.
Bunch == -1)
return CheckReconFillMiniTreeOutOfBunch(bunch);
427 for (std::vector<AnaParticleB*>::const_iterator it = bunch.
Particles.begin(); it!=bunch.
Particles.end(); it++) {
429 unsigned long bitfield = (*it)->Detector;
446 if (necal>1)
return true;
451 if (necal>1)
return true;
465 void CreateMiniTree::WriteGeometry(){
469 if (_spill->GeomID != _currentGeomID){
473 ND::hgman().GeoManager()->Write();
477 _currentGeomID= _spill->GeomID;
483 void CreateMiniTree::FillMiniTree(){
487 _spill->CopyArraysIntoVectors();
490 _spill->Beam->POTSincePreviousSavedSpill = _POTSincePreviousSavedSpill;
491 _spill->Beam->SpillsSincePreviousSavedSpill = _SpillsSincePreviousSavedSpill;
495 _spill->RooVtxEntry = _rooVtxManager.GetRooVtxEntry();
501 _POTSincePreviousSavedSpill =0;
502 _SpillsSincePreviousSavedSpill=0;
506 void CreateMiniTree::FillRooTrackerVtxTree(){
511 if (_filterRoo) FilterRooTrackerVtxTree();
521 void CreateMiniTree::FilterRooTrackerVtxTree(){
525 if (!input().InputIsOriginalTree())
return;
530 if (_spill->EventInfo){
531 RunID = _spill->EventInfo->Run;
532 SubrunID = _spill->EventInfo->SubRun;
533 EventID = _spill->EventInfo->Event;
541 const std::vector<AnaTrueVertexB*>& vertices = _spill->TrueVertices;
545 for (
int roov = 0; roov < NVtx_input; roov++) {
546 if (input().GetChain(
"NRooTrackerVtx")){
547 ND::NRooTrackerVtx *lvtx = (ND::NRooTrackerVtx*) (*Vtx_input)[roov];
548 if ( ! lvtx->StdHepPdg)
continue;
550 for (std::vector<AnaTrueVertexB*>::const_iterator it = vertices.begin(); it!=vertices.end(); it++) {
553 if (vertex->
ID == lvtx->TruthVertexID){
562 ND::GRooTrackerVtx *lvtx = (ND::GRooTrackerVtx*) (*Vtx_input)[roov];
563 if ( ! lvtx->StdHepPdg)
continue;
565 for (std::vector<AnaTrueVertexB*>::const_iterator it = vertices.begin(); it!=vertices.end(); it++) {
568 if (vertex->
ID == lvtx->TruthVertexID){
580 void CreateMiniTree::DeleteUninterestingBunches(){
583 std::vector<AnaParticleB*> particlesToConsider;
586 std::vector<Int_t> bunchesToDelete;
587 for (std::vector<AnaBunchC*>::iterator it=_spill->Bunches.begin();it!=_spill->Bunches.end();it++){
590 if (!CheckReconFillMiniTree(*bunch))
591 bunchesToDelete.push_back(bunch->
Bunch);
594 for (std::vector<AnaVertexB*>::iterator it2=bunch->
Vertices.begin();it2!=bunch->
Vertices.end();it2++){
596 for (Int_t i = 0;i<vertex->nParticles;i++){
598 particlesToConsider.push_back(particle);
605 for (UInt_t i=0;i<bunchesToDelete.size();i++){
606 for (std::vector<AnaBunchC*>::iterator it=_spill->Bunches.begin();it!=_spill->Bunches.end();it++){
608 if (bunch->
Bunch == bunchesToDelete[i]){
611 for (std::vector<AnaParticleB*>::iterator it2=bunch->
Particles.begin();it2!=bunch->
Particles.end();it2++){
613 for (std::vector<AnaParticleB*>::iterator it3=particlesToConsider.begin();it3!=particlesToConsider.end();it3++){
615 if (particle2==particle3){
624 _spill->Bunches.erase(it);
632 if (_spill->OutOfBunch && !CheckReconFillMiniTreeOutOfBunch(*_spill->OutOfBunch)){
635 for (std::vector<AnaParticleB*>::iterator it2=_spill->OutOfBunch->Particles.begin();it2!=_spill->OutOfBunch->Particles.end();it2++){
637 for (std::vector<AnaParticleB*>::iterator it3=particlesToConsider.begin();it3!=particlesToConsider.end();it3++){
639 if (particle2==particle3){
648 delete _spill->OutOfBunch;
649 _spill->OutOfBunch=NULL;
Int_t NuPDG
The PDG code of the incoming neutrino.
int GetParameterI(std::string)
Get parameter. Value is returned as integer.
static bool HasPECALDetector(unsigned long BitField)
Check if a detector bit field has a P0D ECAL or not.
void AddCorrection(Int_t index, const std::string &name, CorrectionBase *corr)
void AddTreeWithName(Int_t tree_index, const std::string &tree_name, TTree *tree=NULL)
Add a tree provided its index and name.
Int_t RooVtxIndex
The index of the associated RooTrackerVtx vertex from its position in the TClonesArray.
void AddPackage(const std::string &name, const std::string &version)
Add a package.
std::vector< AnaTrueVertexB * > TrueVertices
The true MC vertices used in this spill.
Int_t GetCurrentTree() const
Retuns the current tree index.
static bool GetDetectorUsed(unsigned long BitField, SubDetId::SubDetEnum det)
Method to see if a certain subdetector or subdetector system is used.
CorrectionManager _corrections
Correction manager.
Int_t ID
The ID of the trueObj, which corresponds to the ID of the TTruthParticle that created it...
std::vector< AnaVertexB * > Vertices
std::string GetSoftwareVersionFromPath(const std::string &path)
Get The software version from the path of the package.
void FillTree()
Fill the current tree.
static bool HasSMRDDetector(unsigned long BitField)
Check if a detector bit field has a SMRD or not.
virtual bool Initialize()
Representation of a true Monte Carlo vertex.
This class defines a correction that affects the reconstructed TPC Momentum of an.
void SetCurrentTree(Int_t index)
Sets the current tree provided the index.
virtual void DefineOutputTree()
Define the tree that should be written to the output file.
Creates the appropriate AnaSpillB type. The rest of the work is done by the base converter.
bool HasTree(Int_t index)
Check the existence of a tree provided the index.
static bool HasTECALDetector(unsigned long BitField)
Check if a detector bit field has a Tracker ECAL or not.
AnaParticleB ** Particles
Representation of a global vertex.
void IncrementRooVtxEntry()
Increment by one the current entry in the RooTrackerVtx tree.
Int_t Bunch
The index of this bunch (0-7).
TFile * _file
Root input or output file.
ProdId_h GetProductionIdFromND280AnalysisTools()
Get Production Id from nd280AnalysisTools.
std::vector< AnaParticleB * > Particles
bool _versionCheck
Check version compatibility between nd280AnalysisTools compilation and oaAnalysis file...
void AddProduction(ProdId_h prodId, const std::string &prodName, const std::string &prodLowVersion, const std::string &prodHighVersion)
Add a production.
TTree * GetTree()
Returns the a tree set as current.
Representation of a reconstructed particle (track or shower).