File indexing completed on 2023-03-17 11:27:28
0001 #include "Validation/Geometry/interface/MaterialBudgetTree.h"
0002 #include "Validation/Geometry/interface/MaterialBudgetData.h"
0003
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005
0006 MaterialBudgetTree::MaterialBudgetTree(std::shared_ptr<MaterialBudgetData> data, const std::string &filename)
0007 : MaterialBudgetFormat(data) {
0008 fname = filename;
0009 tmpName = "tmp" + fname;
0010 book();
0011 }
0012
0013 void MaterialBudgetTree::book() {
0014 TFile *tmpFile = new TFile(tmpName.c_str(), "RECREATE");
0015
0016
0017 LogDebug("MaterialBudget") << "MaterialBudgetTree: Booking user TTree " << tmpFile->GetSize();
0018
0019 theTree = std::make_unique<TTree>("T1", "GeometryTest Tree");
0020
0021
0022 theTree->Branch("MB", &t_MB, "MB/F");
0023 theTree->Branch("IL", &t_IL, "IL/F");
0024
0025
0026 theTree->Branch("Particle ID", &t_ParticleID, "Particle_ID/I");
0027 theTree->Branch("Particle Pt", &t_ParticlePt, "Particle_Pt/F");
0028 theTree->Branch("Particle Eta", &t_ParticleEta, "Particle_Eta/F");
0029 theTree->Branch("Particle Phi", &t_ParticlePhi, "Particle_Phi/F");
0030 theTree->Branch("Particle Energy", &t_ParticleEnergy, "Particle_E/F");
0031 theTree->Branch("Particle Mass", &t_ParticleMass, "Particle_M/F");
0032
0033 if (theData->allStepsON()) {
0034 theTree->Branch("Nsteps", &t_Nsteps, "Nsteps/I");
0035 theTree->Branch("DeltaMB", t_DeltaMB, "DeltaMB[Nsteps]/F");
0036 theTree->Branch("DeltaMB_SUP", t_DeltaMB_SUP, "DeltaMB_SUP[Nsteps]/F");
0037 theTree->Branch("DeltaMB_SEN", t_DeltaMB_SEN, "DeltaMB_SEN[Nsteps]/F");
0038 theTree->Branch("DeltaMB_CAB", t_DeltaMB_CAB, "DeltaMB_CAB[Nsteps]/F");
0039 theTree->Branch("DeltaMB_COL", t_DeltaMB_COL, "DeltaMB_COL[Nsteps]/F");
0040 theTree->Branch("DeltaMB_ELE", t_DeltaMB_ELE, "DeltaMB_ELE[Nsteps]/F");
0041 theTree->Branch("DeltaMB_OTH", t_DeltaMB_OTH, "DeltaMB_OTH[Nsteps]/F");
0042 theTree->Branch("DeltaMB_AIR", t_DeltaMB_AIR, "DeltaMB_AIR[Nsteps]/F");
0043
0044 theTree->Branch("DeltaIL", t_DeltaIL, "DeltaIL[Nsteps]/F");
0045 theTree->Branch("DeltaIL_SUP", t_DeltaIL_SUP, "DeltaIL_SUP[Nsteps]/F");
0046 theTree->Branch("DeltaIL_SEN", t_DeltaIL_SEN, "DeltaIL_SEN[Nsteps]/F");
0047 theTree->Branch("DeltaIL_CAB", t_DeltaIL_CAB, "DeltaIL_CAB[Nsteps]/F");
0048 theTree->Branch("DeltaIL_COL", t_DeltaIL_COL, "DeltaIL_COL[Nsteps]/F");
0049 theTree->Branch("DeltaIL_ELE", t_DeltaIL_ELE, "DeltaIL_ELE[Nsteps]/F");
0050 theTree->Branch("DeltaIL_OTH", t_DeltaIL_OTH, "DeltaIL_OTH[Nsteps]/F");
0051 theTree->Branch("DeltaIL_AIR", t_DeltaIL_AIR, "DeltaIL_AIR[Nsteps]/F");
0052
0053 theTree->Branch("Initial X", t_InitialX, "Initial_X[Nsteps]/D");
0054 theTree->Branch("Initial Y", t_InitialY, "Initial_Y[Nsteps]/D");
0055 theTree->Branch("Initial Z", t_InitialZ, "Initial_Z[Nsteps]/D");
0056
0057 theTree->Branch("Final X", t_FinalX, "Final_X[Nsteps]/D");
0058 theTree->Branch("Final Y", t_FinalY, "Final_Y[Nsteps]/D");
0059 theTree->Branch("Final Z", t_FinalZ, "Final_Z[Nsteps]/D");
0060
0061 theTree->Branch("Volume ID", t_VolumeID, "VolumeID[Nsteps]/I");
0062 theTree->Branch("Volume Name", t_VolumeName, "VolumeName[Nsteps]/C");
0063 theTree->Branch("Volume Copy", t_VolumeCopy, "VolumeCopy[Nsteps]/I");
0064 theTree->Branch("Volume X", t_VolumeX, "VolumeX[Nsteps]/F");
0065 theTree->Branch("Volume Y", t_VolumeY, "VolumeY[Nsteps]/F");
0066 theTree->Branch("Volume Z", t_VolumeZ, "VolumeZ[Nsteps]/F");
0067 theTree->Branch("Volume X axis 1", t_VolumeXaxis1, "VolumeXaxis1[Nsteps]/F");
0068 theTree->Branch("Volume X axis 2", t_VolumeXaxis2, "VolumeXaxis2[Nsteps]/F");
0069 theTree->Branch("Volume X axis 3", t_VolumeXaxis3, "VolumeXaxis3[Nsteps]/F");
0070 theTree->Branch("Volume Y axis 1", t_VolumeYaxis1, "VolumeYaxis1[Nsteps]/F");
0071 theTree->Branch("Volume Y axis 2", t_VolumeYaxis2, "VolumeYaxis2[Nsteps]/F");
0072 theTree->Branch("Volume Y axis 3", t_VolumeYaxis3, "VolumeYaxis3[Nsteps]/F");
0073 theTree->Branch("Volume Z axis 1", t_VolumeZaxis1, "VolumeZaxis1[Nsteps]/F");
0074 theTree->Branch("Volume Z axis 2", t_VolumeZaxis2, "VolumeZaxis2[Nsteps]/F");
0075 theTree->Branch("Volume Z axis 3", t_VolumeZaxis3, "VolumeZaxis3[Nsteps]/F");
0076
0077 theTree->Branch("Material ID", t_MaterialID, "MaterialID[Nsteps]/I");
0078 theTree->Branch("Material Name", t_MaterialName, "MaterialName[Nsteps]/C");
0079 theTree->Branch("Material X0", t_MaterialX0, "MaterialX0[Nsteps]/F");
0080 theTree->Branch("Material Lambda0", t_MaterialLambda0, "MaterialLambda0[Nsteps]/F");
0081 theTree->Branch("Material Density", t_MaterialDensity, "MaterialDensity[Nsteps]/F");
0082
0083 theTree->Branch("Particle Step ID", t_ParticleStepID, "Step_ID[Nsteps]/I");
0084 theTree->Branch("Particle Step Initial Pt", t_ParticleStepInitialPt, "Step_Initial_Pt[Nsteps]/F");
0085 theTree->Branch("Particle Step Initial Eta", t_ParticleStepInitialEta, "Step_Initial_Eta[Nsteps]/F");
0086 theTree->Branch("Particle Step Initial Phi", t_ParticleStepInitialPhi, "Step_Initial_Phi[Nsteps]/F");
0087 theTree->Branch("Particle Step Initial Energy", t_ParticleStepInitialEnergy, "Step_Initial_E[Nsteps]/F");
0088 theTree->Branch("Particle Step Initial Px", t_ParticleStepInitialPx, "Step_Initial_Px[Nsteps]/F");
0089 theTree->Branch("Particle Step Initial Py", t_ParticleStepInitialPy, "Step_Initial_Py[Nsteps]/F");
0090 theTree->Branch("Particle Step Initial Pz", t_ParticleStepInitialPz, "Step_Initial_Pz[Nsteps]/F");
0091 theTree->Branch("Particle Step Initial Beta", t_ParticleStepInitialBeta, "Step_Initial_Beta[Nsteps]/F");
0092 theTree->Branch("Particle Step Initial Gamma", t_ParticleStepInitialGamma, "Step_Initial_Gamma[Nsteps]/F");
0093 theTree->Branch("Particle Step Initial Mass", t_ParticleStepInitialMass, "Step_Initial_Mass[Nsteps]/F");
0094 theTree->Branch("Particle Step Final Pt", t_ParticleStepFinalPt, "Step_Final_Pt[Nsteps]/F");
0095 theTree->Branch("Particle Step Final Eta", t_ParticleStepFinalEta, "Step_Final_Eta[Nsteps]/F");
0096 theTree->Branch("Particle Step Final Phi", t_ParticleStepFinalPhi, "Step_Final_Phi[Nsteps]/F");
0097 theTree->Branch("Particle Step Final Energy", t_ParticleStepFinalEnergy, "Step_Final_E[Nsteps]/F");
0098 theTree->Branch("Particle Step Final Px", t_ParticleStepFinalPx, "Step_Final_Px[Nsteps]/F");
0099 theTree->Branch("Particle Step Final Py", t_ParticleStepFinalPy, "Step_Final_Py[Nsteps]/F");
0100 theTree->Branch("Particle Step Final Pz", t_ParticleStepFinalPz, "Step_Final_Pz[Nsteps]/F");
0101 theTree->Branch("Particle Step Final Beta", t_ParticleStepFinalBeta, "Step_Final_Beta[Nsteps]/F");
0102 theTree->Branch("Particle Step Final Gamma", t_ParticleStepFinalGamma, "Step_Final_Gamma[Nsteps]/F");
0103 theTree->Branch("Particle Step Final Mass", t_ParticleStepFinalMass, "Step_Final_Mass[Nsteps]/F");
0104 theTree->Branch("Particle Step Pre Interaction", t_ParticleStepPreInteraction, "Step_PreInteraction[Nsteps]/I");
0105 theTree->Branch("Particle Step Post Interaction", t_ParticleStepPostInteraction, "Step_PostInteraction[Nsteps]/I");
0106 }
0107
0108 LogDebug("MaterialBudget") << "MaterialBudgetTree: Booking user TTree done";
0109 }
0110
0111 void MaterialBudgetTree::fillStartTrack() {}
0112
0113 void MaterialBudgetTree::fillPerStep() {}
0114
0115 void MaterialBudgetTree::fillEndTrack() {
0116 t_MB = theData->getTotalMB();
0117 t_IL = theData->getTotalIL();
0118
0119 t_ParticleID = theData->getID();
0120 t_ParticlePt = theData->getPt();
0121 t_ParticleEta = theData->getEta();
0122 t_ParticlePhi = theData->getPhi();
0123 t_ParticleEnergy = theData->getEnergy();
0124 t_ParticleMass = theData->getMass();
0125
0126 if (theData->allStepsON()) {
0127 t_Nsteps = theData->getNumberOfSteps();
0128
0129 if (t_Nsteps > MAXSTEPS)
0130 t_Nsteps = MAXSTEPS;
0131
0132 edm::LogInfo("MaterialBudget") << "MaterialBudgetTree: Number of Steps into the tree " << t_Nsteps;
0133
0134 for (int ii = 0; ii < t_Nsteps; ii++) {
0135 t_DeltaMB[ii] = theData->getStepDmb(ii);
0136 t_DeltaMB_SUP[ii] = theData->getSupportDmb(ii);
0137 t_DeltaMB_SEN[ii] = theData->getSensitiveDmb(ii);
0138 t_DeltaMB_CAB[ii] = theData->getCablesDmb(ii);
0139 t_DeltaMB_COL[ii] = theData->getCoolingDmb(ii);
0140 t_DeltaMB_ELE[ii] = theData->getElectronicsDmb(ii);
0141 t_DeltaMB_OTH[ii] = theData->getOtherDmb(ii);
0142 t_DeltaMB_AIR[ii] = theData->getAirDmb(ii);
0143
0144 t_DeltaIL[ii] = theData->getStepDil(ii);
0145 t_DeltaIL_SUP[ii] = theData->getSupportDil(ii);
0146 t_DeltaIL_SEN[ii] = theData->getSensitiveDil(ii);
0147 t_DeltaIL_CAB[ii] = theData->getCablesDil(ii);
0148 t_DeltaIL_COL[ii] = theData->getCoolingDil(ii);
0149 t_DeltaIL_ELE[ii] = theData->getElectronicsDil(ii);
0150 t_DeltaIL_OTH[ii] = theData->getOtherDil(ii);
0151 t_DeltaIL_AIR[ii] = theData->getAirDil(ii);
0152
0153 t_InitialX[ii] = theData->getStepInitialX(ii);
0154 t_InitialY[ii] = theData->getStepInitialY(ii);
0155 t_InitialZ[ii] = theData->getStepInitialZ(ii);
0156 t_FinalX[ii] = theData->getStepFinalX(ii);
0157 t_FinalY[ii] = theData->getStepFinalY(ii);
0158 t_FinalZ[ii] = theData->getStepFinalZ(ii);
0159
0160 t_VolumeID[ii] = theData->getStepVolumeID(ii);
0161 t_VolumeName[ii] = theData->getStepVolumeName(ii).c_str();
0162 t_VolumeCopy[ii] = theData->getStepVolumeCopy(ii);
0163 t_VolumeX[ii] = theData->getStepVolumeX(ii);
0164 t_VolumeY[ii] = theData->getStepVolumeY(ii);
0165 t_VolumeZ[ii] = theData->getStepVolumeZ(ii);
0166 t_VolumeXaxis1[ii] = theData->getStepVolumeXaxis(ii).x();
0167 t_VolumeXaxis2[ii] = theData->getStepVolumeXaxis(ii).y();
0168 t_VolumeXaxis3[ii] = theData->getStepVolumeXaxis(ii).z();
0169 t_VolumeYaxis1[ii] = theData->getStepVolumeYaxis(ii).x();
0170 t_VolumeYaxis2[ii] = theData->getStepVolumeYaxis(ii).y();
0171 t_VolumeYaxis3[ii] = theData->getStepVolumeYaxis(ii).z();
0172 t_VolumeZaxis1[ii] = theData->getStepVolumeZaxis(ii).x();
0173 t_VolumeZaxis2[ii] = theData->getStepVolumeZaxis(ii).y();
0174 t_VolumeZaxis3[ii] = theData->getStepVolumeZaxis(ii).z();
0175
0176 t_MaterialID[ii] = theData->getStepMaterialID(ii);
0177 t_MaterialName[ii] = theData->getStepMaterialName(ii).c_str();
0178 t_MaterialX0[ii] = theData->getStepMaterialX0(ii);
0179 t_MaterialLambda0[ii] = theData->getStepMaterialLambda0(ii);
0180 t_MaterialDensity[ii] = theData->getStepMaterialDensity(ii);
0181
0182 t_ParticleStepID[ii] = theData->getStepID(ii);
0183 t_ParticleStepInitialPt[ii] = theData->getStepInitialPt(ii);
0184 t_ParticleStepInitialEta[ii] = theData->getStepInitialEta(ii);
0185 t_ParticleStepInitialPhi[ii] = theData->getStepInitialPhi(ii);
0186 t_ParticleStepInitialEnergy[ii] = theData->getStepInitialEnergy(ii);
0187 t_ParticleStepInitialPx[ii] = theData->getStepInitialPx(ii);
0188 t_ParticleStepInitialPy[ii] = theData->getStepInitialPy(ii);
0189 t_ParticleStepInitialPz[ii] = theData->getStepInitialPz(ii);
0190 t_ParticleStepInitialBeta[ii] = theData->getStepInitialBeta(ii);
0191 t_ParticleStepInitialGamma[ii] = theData->getStepInitialGamma(ii);
0192 t_ParticleStepInitialMass[ii] = theData->getStepInitialMass(ii);
0193 t_ParticleStepFinalPt[ii] = theData->getStepFinalPt(ii);
0194 t_ParticleStepFinalEta[ii] = theData->getStepFinalEta(ii);
0195 t_ParticleStepFinalPhi[ii] = theData->getStepFinalPhi(ii);
0196 t_ParticleStepFinalEnergy[ii] = theData->getStepFinalEnergy(ii);
0197 t_ParticleStepFinalPx[ii] = theData->getStepFinalPx(ii);
0198 t_ParticleStepFinalPy[ii] = theData->getStepFinalPy(ii);
0199 t_ParticleStepFinalPz[ii] = theData->getStepFinalPz(ii);
0200 t_ParticleStepFinalBeta[ii] = theData->getStepFinalBeta(ii);
0201 t_ParticleStepFinalGamma[ii] = theData->getStepFinalGamma(ii);
0202 t_ParticleStepFinalMass[ii] = theData->getStepFinalMass(ii);
0203 t_ParticleStepPreInteraction[ii] = theData->getStepPreProcess(ii);
0204 t_ParticleStepPostInteraction[ii] = theData->getStepPostProcess(ii);
0205 }
0206 }
0207
0208 if (theData->getNumberOfSteps() != 0) {
0209 Int_t ssize = theTree->Fill();
0210 edm::LogInfo("MaterialBudget") << "MaterialBudgetTree: Filling Tree " << ssize << " bytes";
0211 } else {
0212 edm::LogWarning("MaterialBudget") << "MaterialBudgetTree: Event with 0 steps not recorded";
0213 }
0214 }
0215
0216 void MaterialBudgetTree::endOfRun() {
0217
0218
0219
0220 TFile *outFile = new TFile(fname.c_str(), "RECREATE");
0221 outFile->mkdir("TEST");
0222
0223 if (theTree) {
0224 TTree *t1 = theTree->CloneTree();
0225 t1->Write();
0226 edm::LogWarning("MaterialBudget") << "TTree Written " << t1;
0227 } else {
0228 edm::LogError("MaterialBudget") << "Material Budget Tree: Tree Pointer Null";
0229 }
0230
0231 delete outFile;
0232 unlink(tmpName.c_str());
0233 }