1 #include "p0dExampleAnalysis.hxx" 2 #include "FiducialVolumeDefinition.hxx" 3 #include "p0dExampleSelection.hxx" 4 #include "Parameters.hxx" 5 #include "CategoriesUtils.hxx" 6 #include "BasicUtils.hxx" 7 #include "P0DAnalysisUtils.hxx" 8 #include "P0DGeometryManager.hxx" 32 _isUsingReconDirP0D = ND::params().
GetParameterI(
"highlandIO.FlatTree.UseReconDirP0D");
35 _isUsingReconDirP0DNew = ND::params().
GetParameterI(
"highlandIO.P0DDataClasses.UseReconDirP0DNew");
38 _debug = ND::params().
GetParameterI(
"baseP0DAnalysis.Example.DebugAnalysis");
47 void p0dExampleAnalysis::DefineSelections(){
55 void p0dExampleAnalysis::DefineCorrections(){
58 baseP0DAnalysis::DefineCorrections();
62 void p0dExampleAnalysis::DefineSystematics(){
65 baseP0DAnalysis::DefineSystematics();
69 void p0dExampleAnalysis::DefineConfigurations(){
72 baseP0DAnalysis::DefineConfigurations();
76 void p0dExampleAnalysis::DefineMicroTrees(
bool addBase){
79 if (addBase) baseP0DAnalysis::DefineMicroTrees(addBase);
81 AddVarVI(output(), P0DOnlyTracksInGlobalID,
"ID for P0D only tracks in global", nP0DOnlyTracksInGlobal);
82 AddVarVI(output(), P0DTracksInGlobalID,
"ID of P0D segment in global tracks containing P0D", nP0DTracksInGlobal);
84 AddVarI(output(), nShowers,
"number of showers");
85 AddVarF(output(), Shower1EDeposit,
"EDeposit of first shower");
86 AddVarF(output(), Shower2EDeposit,
"EDeposit of second shower");
87 AddVar3VF(output(), Shower1Direction,
"Direction of first shower");
88 AddVar3VF(output(), Shower2Direction,
"Direction of second shower");
90 AddVar4VF(output(), truevertex_pos,
"position of the selected true vertex");
92 AddVarVI(output(), nClustersInVertex,
"number of P0DRecon clusters associated to each vertex", nVertices);
93 AddVarVI(output(), nHitsInVertex,
"number of P0DRecon hits associated to each vertex", nVertices);
94 AddVarMI(output(), ClusterInVertexTruePDG,
"PDG of TrueParticle associated to cluster in vertex", nVertices,-200,100);
95 output().
Add3DMatrixVar(ClusterInVertexPosition,
"ClusterInVertexPosition",
"F",
"Position of clusters in vertex", nVertices,
96 "nVertices", -200, 100, 4);
98 output().
Add3DMatrixVar(HitInVertexPosition,
"HitInVertexPosition",
"F",
"Position of hits in vertex", nVertices,
99 "nVertices", -200, 100, 4);
103 AddVarVI(output(), nTracksInParticle,
"number of P0DRecon tracks associated to each particle", nParticles);
104 AddVarVI(output(), nShowersInParticle,
"number of P0DRecon showers associated to each particle", nParticles);
105 AddVarVI(output(), nNodesInParticle,
"number of P0DRecon nodes associated to each particle", nParticles);
106 AddVarVI(output(), nHitsInParticle,
"number of P0DRecon hits associated to each particle", nParticles);
107 AddVar4MF(output(),ParticlePosition,
"number of P0DRecon tracks associated to each particle", nParticles);
109 AddVarVI(output(), nClustersInParticleInVertex,
"number of P0DRecon clusters associated to each particle", nParticlesInVertex);
110 AddVarVI(output(), nTracksInParticleInVertex,
"number of P0DRecon tracks associated to each particle", nParticlesInVertex);
111 AddVarVI(output(), nShowersInParticleInVertex,
"number of P0DRecon showers associated to each particle", nParticlesInVertex);
112 AddVarVI(output(), nNodesInParticleInVertex,
"number of P0DRecon nodes associated to each particle", nParticlesInVertex);
113 AddVarVI(output(), nHitsInParticleInVertex,
"number of P0DRecon hits associated to each particle", nParticlesInVertex);
114 AddVar4MF(output(),ParticleInVertexPosition,
"Position of particle", nParticlesInVertex);
115 AddVarVF(output(), ParticleInVertexMomentum,
"Momentum of particle (only for showers)", nParticlesInVertex);
116 AddVarVF(output(), ParticleInVertexEDeposit,
"Energy deposited (only for showers)", nParticlesInVertex);
117 AddVarVF(output(), ParticleInVertexLength,
"Length of particle (only for tracks)", nParticlesInVertex);
118 AddVarVI(output(), ParticleInVertexID,
"Unique ID of particle", nParticlesInVertex);
119 AddVarVF(output(), ParticleInVertexTrueMomentum,
"TrueMomentum of particle ", nParticlesInVertex);
120 AddVarVI(output(), ParticleInVertexTruePDG,
"TruePDG of particle", nParticlesInVertex);
121 AddVarVI(output(), ParticleInVertexLink,
"Has this P0D particle a link in global ?", nParticlesInVertex);
122 AddVarVI(output(), ParticleInVertexGlobal,
"Is this particle a global track with a P0D segment ?", nParticlesInVertex);
124 AddVarMI(output(), ClusterInParticleInVertexTruePDG,
"PDG of TrueParticle associated to cluster in a particle in a vertex", nParticlesInVertex, -200,100);
126 output().
Add3DMatrixVar(ClusterInParticleInVertexPosition,
"ClusterInParticleInVertexPosition",
"F",
"Position of clusters in particle in vertex", nParticlesInVertex,
127 "nParticlesInVertex", -100, 100, 4);
130 output().
Add3DMatrixVar(HitInParticleInVertexPosition,
"HitInParticleInVertexPosition",
"F",
"Position of hits in particle in vertex", nParticlesInVertex,
131 "nParticlesInVertex", -100, 200, 4);
133 AddVarMF(output(),HitInParticleInVertexCharge,
"Charge of hits in particle in vertex", nParticlesInVertex,-100, 200);
134 AddVarMI(output(),HitInParticleInVertexType,
"Type (X=0, Y=1) of hits in particle in vertex", nParticlesInVertex,-100, 200);
138 output().
AddMatrixVar(ClusterPosition,
"ClusterPosition",
"F",
"Position of clusters", nClusters,
139 "nClusters", -200, 4);
142 AddVarMaxSizeVI(output(), ClusterTruePDG,
"PDG of TrueParticle associated to a cluster in a particle", nClusters,200);
143 AddVarMaxSizeVI(output(), nHitsInCluster,
"number of P0DRecon hits associated to each cluster", nClusters,200);
145 AddVarVF(output(), vertexFiducial,
"Positive values imply within Fiducial Volume", nVertices);
146 AddVarVI(output(), vertexCycle,
" Vertex Cycle", nVertices);
147 AddVarVI(output(), vertexValidDim,
"Vertex Valid Dimensions", nVertices);
148 AddVar4MF(output(), vertexPosition,
"Vertex position", nVertices);
150 AddVarI(output(), nMichel,
"number of p0dreconclusters with AlgorithmName==TP0DTagMuonDecay in out-of-time bunch");
154 void p0dExampleAnalysis::DefineTruthTree(){
157 baseP0DAnalysis::DefineTruthTree();
161 void p0dExampleAnalysis::FillMicroTrees(
bool addBase){
164 if (addBase) baseP0DAnalysis::FillMicroTrees(addBase);
172 for (Int_t i=0;i<nP0D;i++){
173 if (static_cast<AnaTrack*>(p0dTracks[i])->nP0DSegments>0)
174 output().
FillVectorVar(P0DTracksInGlobalID, static_cast<AnaTrack*>(p0dTracks[i])->P0DSegments[0]->UniqueID);
177 output().IncrementCounter(nP0DTracksInGlobal);
183 if (_debug) std::cout <<
" nP0Dtracks using _event : " << nP0D << std::endl;
185 for (Int_t i=0;i<nP0DOnly;i++){
186 if (static_cast<AnaTrack*>(p0dOnlyTracks[i])->nP0DSegments>2)
187 output().
FillVectorVar(P0DOnlyTracksInGlobalID, static_cast<AnaTrack*>(p0dOnlyTracks[i])->P0DSegments[0]->UniqueID);
190 output().IncrementCounter(nP0DOnlyTracksInGlobal);
194 if (_isUsingReconDirP0DNew)
195 FillMicroTreesNative();
196 else if (_isUsingReconDirP0D)
197 FillMicroTreesLocal();
202 void p0dExampleAnalysis::FillMicroTreesLocal(){
215 std::cerr<<
"Invalid local event, did you enable UseReconDirP0D = 1 in highlandIO.parameters.dat?\n";
219 if (_debug) std::cout <<
"For the iBunch value:" <<
GetEvent().
Bunch <<
"the # of P0D Recon vertices" << localEvent->P0DReconVertices.size() << std::endl;
221 for(std::vector<AnaP0DReconVertex*>::iterator it =localEvent->P0DReconVertices.begin(); it!= localEvent->P0DReconVertices.end(); ++it ){
222 if (_debug) std::cout <<
"P0DReconVertices:AlgorithmName : " << (*it)->AlgorithmName <<
" Cycle: " << (*it)->Cycle <<
" Bunch: " << (*it)->Bunch << std::endl;
224 output().
FillVectorVar(nClustersInVertex, (Int_t)(*it)->ClustersP.size());
225 output().
FillVectorVar(nHitsInVertex, (Int_t)(*it)->Hits.size());
229 output().
FillVectorVar(vertexValidDim, (Int_t)(*it)->ValidDimensions);
232 output().IncrementCounter(nVertices);
234 for(std::vector<AnaP0DReconParticle*>::iterator it2 =(*it)->ParticlesP.begin(); it2!= (*it)->ParticlesP.end(); ++it2 ){
235 if (_debug) std::cout <<
"P0DReconParticles:AlgorithmName : " << (*it2)->AlgorithmName <<
" Cycle: " << (*it2)->Cycle <<
" Bunch: " << (*it2)->Bunch << std::endl;
237 if (!(*it2))
continue;
238 output().
FillVectorVar(nClustersInParticleInVertex, (Int_t)(*it2)->Clusters.size());
239 output().
FillVectorVar(nTracksInParticleInVertex, (Int_t)(*it2)->Tracks.size());
240 output().
FillVectorVar(nShowersInParticleInVertex, (Int_t)(*it2)->Showers.size());
241 output().
FillVectorVar(nNodesInParticleInVertex, (Int_t)(*it2)->Nodes.size());
242 output().
FillVectorVar(nHitsInParticleInVertex, (Int_t)(*it2)->Hits.size());
245 output().
FillVectorVar(ParticleInVertexMomentum, (*it2)->Momentum);
246 output().
FillVectorVar(ParticleInVertexEDeposit, (*it2)->EDeposit);
247 output().
FillVectorVar(ParticleInVertexLength, (*it2)->Length);
248 output().
FillVectorVar(ParticleInVertexID, (Int_t)(*it2)->UniqueID);
249 if ((*it2)->TrueParticle){
250 output().
FillVectorVar(ParticleInVertexTrueMomentum, (*it2)->TrueParticle->Momentum);
251 output().
FillVectorVar(ParticleInVertexTruePDG, (*it2)->TrueParticle->PDG);
255 for (Int_t i=0;i<nP0D;i++){
257 if (part->
UniqueID == (Int_t)(*it2)->UniqueID){
265 output().IncrementCounter(nParticlesInVertex);
269 for(std::vector<AnaP0DReconParticle*>::iterator it =localEvent->P0DReconParticles.begin(); it!= localEvent->P0DReconParticles.end(); ++it ){
270 if (_debug) std::cout <<
"P0DReconParticles:AlgorithmName : " << (*it)->AlgorithmName <<
" Cycle: " << (*it)->Cycle <<
" Bunch: " << (*it)->Bunch << std::endl;
272 output().
FillVectorVar(nTracksInParticle, (Int_t)(*it)->Tracks.size());
273 output().
FillVectorVar(nShowersInParticle, (Int_t)(*it)->Showers.size());
274 output().
FillVectorVar(nNodesInParticle, (Int_t)(*it)->Nodes.size());
275 output().
FillVectorVar(nHitsInParticle, (Int_t)(*it)->Hits.size());
276 output().IncrementCounter(nParticles);
279 for(std::vector<AnaP0DReconCluster*>::iterator it =localEvent->P0DReconClusters.begin(); it!= localEvent->P0DReconClusters.end(); ++it ){
280 if (_debug) std::cout <<
"P0DReconClusters:AlgorithmName : " << (*it)->AlgorithmName <<
" Cycle: " << (*it)->Cycle <<
"Bunch: " << (*it)->Bunch << std::endl;
282 output().
FillVectorVar(nHitsInCluster, (Int_t)(*it)->Hits.size());
283 output().IncrementCounter(nClusters);
290 for (std::vector<AnaBunchC*>::iterator it =
GetSpill().Bunches.begin();
297 for (std::vector<AnaP0DReconCluster*>::iterator it = p0dRecoBunch->P0DReconClusters.begin();
298 it != p0dRecoBunch->P0DReconClusters.end(); ++it) {
299 if (_debug) std::cout <<
"P0DReconCluster (*it)->AlgorithmName: " << (*it)->AlgorithmName << std::endl;
300 if (_debug) std::cout <<
"P0DReconCluster (*it)->Position: " << (*it)->Position << std::endl;
301 if ((*it)->AlgorithmName.compare(
"TP0DTagMuonDecay") == 0) nmichels += 1;
317 output().
FillVar(nMichel, nmichels);
321 void p0dExampleAnalysis::FillMicroTreesNative(){
336 std::cout <<
"-------------------------- AlternateEvents structure for event " << p0dEvent->
EventInfo.
Event 337 <<
" and bunch " << p0dEvent->
Bunch <<
" --------------------------" << std::endl;
338 std::cout <<
" - " << p0dEvent->FullName << std::endl;
339 for (UInt_t i=0;i<p0dEvent->AlternateEvents.size();i++){
340 std::cout <<
" - " << p0dEvent->AlternateEvents[i]->FullName << std::endl;
341 for (UInt_t j=0;j<p0dEvent->AlternateEvents[i]->AlternateEvents.size();j++){
342 std::cout <<
" - " << p0dEvent->AlternateEvents[i]->AlternateEvents[j]->FullName << std::endl;
343 for (UInt_t k=0;k<p0dEvent->AlternateEvents[i]->AlternateEvents[j]->AlternateEvents.size();k++){
344 std::cout <<
" - " << p0dEvent->AlternateEvents[i]->AlternateEvents[j]->AlternateEvents[k]->FullName << std::endl;
345 for (UInt_t l=0;l<p0dEvent->AlternateEvents[i]->AlternateEvents[j]->AlternateEvents[k]->AlternateEvents.size();l++){
346 std::cout <<
" - " << p0dEvent->AlternateEvents[i]->AlternateEvents[j]->AlternateEvents[k]->AlternateEvents[l]->FullName << std::endl;
351 std::cout <<
"-------------------------------------------------------------------------------------------------------------" << std::endl;
355 Int_t nPartsInVertices=0;
361 if (_debug) std::cout <<
"For the iBunch value:" <<
GetEvent().
Bunch <<
"the # of P0D Recon vertices is " <<
GetEvent().nVertices << std::endl;
367 Int_t nVerts = p0dUtils::GetAllP0DVertices(
GetEvent(),p0dVertices);
369 for(Int_t iv=0;iv<nVerts; iv++ ){
372 if (_debug) std::cout <<
"P0DReconVertices:AlgorithmName : " << p0dVertex->AlgorithmName <<
" Bunch: " << p0dVertex->
Bunch << std::endl;
375 output().
FillVectorVar(nClustersInVertex, (Int_t)p0dVertex->nClusters);
377 output().
FillVectorVar(vertexValidDim, (Int_t)p0dVertex->ValidDimensions);
382 for(Int_t ic=0;ic<p0dVertex->nClusters; ic++ ){
387 if (p0dCluster->TrueParticle)
388 output().
FillMatrixVar(ClusterInVertexTruePDG, p0dCluster->TrueParticle->
PDG, -1, ic);
391 for(Int_t ih=0;ih<p0dCluster->nHits; ih++ ){
392 if (nhits>=200)
break;
396 Float_t posArray[4]={pos[0],pos[1],pos[2],p0dHit->Time};
406 for(Int_t ip=0;ip<p0dVertex->nParticles; ip++ ){
409 if (!p0dParticle)
continue;
411 if (_debug) std::cout <<
"P0DReconParticles:AlgorithmName : " << p0dParticle->AlgorithmName << std::endl;
414 output().
FillVectorVar(nClustersInParticleInVertex, (Int_t)p0dParticle->nClusters);
418 output().
FillVectorVar(ParticleInVertexEDeposit, p0dParticle->EDeposit);
419 output().
FillVectorVar(ParticleInVertexLength, p0dParticle->Length);
429 for(Int_t ic=0;ic<p0dParticle->nClusters; ic++ ){
434 if (p0dCluster->TrueParticle)
435 output().
FillMatrixVar(ClusterInParticleInVertexTruePDG, p0dCluster->TrueParticle->
PDG, -1, ic);
439 for(Int_t ih=0;ih<p0dCluster->nHits; ih++ ){
440 if (nhits>=200)
break;
444 Float_t posArray[4]={pos[0],pos[1],pos[2],p0dHit->Time};
450 output().
FillMatrixVar( HitInParticleInVertexCharge, p0dHit->Charge, -1, nhits);
451 output().
FillMatrixVar( HitInParticleInVertexType, type, -1, nhits);
461 for (Int_t i=0;i<nP0D;i++){
473 output().IncrementCounter(nParticlesInVertex);
476 output().IncrementCounter(nVertices);
483 Int_t nParts = p0dUtils::GetAllP0DParticles(
GetEvent(), p0dParticles);
484 if (_debug && nParts != nPartsInVertices) std::cout <<
"warning: #Particles in vertices and #Particles in event differ !!!!" << std::endl;
486 for(Int_t ip=0;ip<nParts; ip++ ){
489 if (_debug) std::cout <<
"P0DReconParticles:AlgorithmName : " << p0dParticle->AlgorithmName << std::endl;
492 output().IncrementCounter(nParticles);
498 Int_t nmichels =
static_cast<AnaEvent*
>(
_event)->nDelayedClusters;
499 output().
FillVar(nMichel, nmichels);
502 for(Int_t i = 0; i< p0dEvent->nClusters;i++ ){
509 if (cluster->TrueParticle)
512 output().IncrementCounter(nClusters);
520 output().
FillVar(nShowers, p0dBox->nShowers);
522 if (p0dBox->Shower1){
523 output().
FillVar(Shower1EDeposit, p0dBox->Shower1->EDeposit);
526 if (p0dBox->Shower2){
527 output().
FillVar(Shower2EDeposit, p0dBox->Shower2->EDeposit);
538 void p0dExampleAnalysis::FillToyVarsInMicroTrees(
bool addBase){
541 if (addBase) baseP0DAnalysis::FillToyVarsInMicroTreesBase(addBase);
545 bool p0dExampleAnalysis::CheckFillTruthTree(
const AnaTrueVertex& vtx){
557 void p0dExampleAnalysis::FillTruthTree(
const AnaTrueVertex& vtx){
560 baseP0DAnalysis::FillTruthTreeBase(vtx);
564 void p0dExampleAnalysis::FillCategories(){
AnaP0DParticle * GetP0DParticle(AnaParticleB *part)
Get the P0D particle from a AnaParticleB: either a segment in a global track or the cast of the P0D-o...
Float_t PositionStart[4]
The reconstructed start position of the particle.
int GetAllTracksUsingOnlyDet(const AnaBunchB &bunch, SubDetId::SubDetEnum det, AnaTrackB *selTracks[])
bool Initialize()
[AnalysisAlgorithm_mandatory]
void SetMinAccumCutLevelToSave(Int_t level)
Set the minimum accumulated cut level to save an event into the micro-tree.
int GetParameterI(std::string)
Get parameter. Value is returned as integer.
AnaP0DBunch & GetBunch()
Get a casted AnaBunchBB to AnaBunch from the InputManager.
Float_t Position[4]
The identified position of the global vertex.
void FillVectorVar(Int_t index, Float_t var, Int_t indx=-1)
Fill a vector variable.
std::vector< AnaBunchC * > Bunches
The reconstructed objects, split into timing bunches.
AnaTrueObjectC * TrueObject
The link to the true oject that most likely generated this reconstructed object.
virtual bool Initialize()
[AnalysisAlgorithm_mandatory]
void Fill3DMatrixVarFromArray(Int_t index, const Double_t var[], Int_t indx1, Int_t indx2, UInt_t size)
Fill a 3D matrix variable from array.
int GetBarLayer(TGeometryId id)
Float_t Momentum
The initial momentum of the true particle.
AnaTrueVertexB * TrueVertex
For storing the true vertex, for analyses with no reconstructed primary vertex.
Int_t Bunch
The bunch of the global vertex, based on the Position.T()
void FillMatrixVarFromArray(Int_t index, const Double_t var[], Int_t indx1, UInt_t size)
Fill a matrix variable from array.
AnaEventInfoB EventInfo
Run, sunrun, event, time stamp, etc.
Int_t UniqueID
The UniqueID of this reconstructed object.
AnaP0DEvent & GetEvent()
Get a casted AnaEventC to AnaEvent.
Float_t Momentum
The reconstructed momentum of the particle, at the start position.
Representation of a true Monte Carlo vertex.
AnaEventC * _event
The current event.
Float_t Position[4]
The position the true interaction happened at.
Int_t PDG
The PDG code of this particle.
void FillCategories(AnaEventB *event, AnaTrack *track, const std::string &prefix, const SubDetId::SubDetEnum det=SubDetId::kFGD1, bool IsAntinu=false, bool useCATSAND=true)
Fill the track categories for color drawing.
Representation of a global track.
Int_t Bunch
The index of this bunch (0-7).
TVector3 GeomIdPosition(int geomId)
AnaParticleB ** Particles
void FillVar(Int_t index, Float_t var)
Fill a single variable.
Float_t DirectionStart[3]
The reconstructed start direction of the particle.
void AddSelection(const std::string &name, const std::string &title, SelectionBase *sel, Int_t presel=-1)
Add a user selection to the selection manager.
AnaSpill & GetSpill()
Get a casted AnaSpillC to AnaSpill from the InputManager.
Int_t Event
The ND280 event number.
void AddStandardCategories(const std::string &prefix="")
Add the standard categories only, given a prefix for their name.
void AddMatrixVar(Int_t index, const std::string &name, const std::string &type, const std::string &doc, Int_t counter_index, const std::string &counter_name, int size1=-MAXVECTORSIZE, int size2=-1)
Add a matrix variable to all trees.
int GetAllTracksUsingDet(const AnaBunchB &bunch, SubDetId::SubDetEnum det, AnaTrackB *selTracks[])
AnaTrueParticleB * GetTrueParticle() const
Return a casted version of the AnaTrueObject associated.
bool InFiducialVolume(SubDetId::SubDetEnum det, const Float_t *pos, const Float_t *FVdefmin, const Float_t *FVdefmax)
void FillMatrixVar(Int_t index, Float_t var, Int_t indx1, Int_t indx2)
Fill a matrix variable.
void FillVectorVarFromArray(Int_t index, const Double_t var[], UInt_t size)
Fill a vector variable from array.
void Add3DMatrixVar(Int_t index, const std::string &name, const std::string &type, const std::string &doc, Int_t counter_index, const std::string &counter_name, int size1=-MAXVECTORSIZE, int size2=-1, int size3=-1)
Add a 3D matrix variable to all trees.