Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:32:41

0001 //////////////////////////////////////////////////////////
0002 // This class has been automatically generated on
0003 // Mon Aug  7 10:01:22 2006 by ROOT version 5.12/00
0004 // from TTree T1/GeometryTest Tree
0005 // found on file: matbdg_tree_TOB.root
0006 //////////////////////////////////////////////////////////
0007 
0008 #ifndef Loopers_h
0009 #define Loopers_h
0010 
0011 #include <TROOT.h>
0012 #include <TChain.h>
0013 #include <TFile.h>
0014 #include <TString.h>
0015 #include <TGaxis.h>
0016 
0017 #include <TTree.h>
0018 #include <iostream>
0019 #include <fstream>
0020 
0021 // histograms
0022 // Target
0023 TH1F* hist_loops;
0024 TH1F* hist_energy_init;
0025 TH1F* hist_energy_end;
0026 TH1F* hist_energy_beforeend;
0027 TH1F* hist_density;
0028 TH1F* hist_lambda0;
0029 TH2F* hist_density_vs_loops;
0030 TH1F* hist_pT_init;
0031 TH1F* hist_pT_end;
0032 TH1F* hist_energyLossPerTurn;
0033 TH1F* hist_trackLength;
0034 TH1F* hist_trackLengthPerTurn;
0035 TH1F* hist_lastInteraction;
0036 TH1F* hist_bx;
0037 TH1F* hist_bx_finer;
0038 TH2F* hist_energy_beforeend_vs_lastInteraction;
0039 TH2F* hist_trackLength_vs_lastInteraction;
0040 TH1F* hist_hadronicInteractions;
0041 TH2F* hist_hadronicInteractions_vs_lastInteraction;
0042 TH1F* hist_energyLossHadronicInteractions;
0043 TH2F* hist_productionEnergy_vs_secondaryParticle;
0044 TH2F* hist_bx_vs_secondaryParticle;
0045 //
0046 
0047 // logfile
0048 std::ofstream theLogFile;
0049 //
0050 
0051 const double pi = 3.14159265;
0052 const double c  = 299792458; // m/s;
0053 const double bx = 25; // ns
0054 const double Ekin_threshold = 20; // MeV
0055 
0056 class Loopers {
0057 public :
0058   TTree          *fChain;   //!pointer to the analyzed TTree or TChain
0059   Int_t           fCurrent; //!current Tree number in a TChain
0060   
0061   // Declaration of leave types
0062   Int_t           ParticleID;
0063   Int_t           Nsteps;
0064   Double_t        InitialX[10000];   //[Nsteps]
0065   Double_t        InitialY[10000];   //[Nsteps]
0066   Double_t        InitialZ[10000];   //[Nsteps]
0067   Double_t        FinalX[10000];   //[Nsteps]
0068   Double_t        FinalY[10000];   //[Nsteps]
0069   Double_t        FinalZ[10000];   //[Nsteps]
0070   Float_t         InitialE[10000];   //[Nsteps]
0071   Float_t         FinalE[10000];   //[Nsteps]
0072   Float_t         InitialM[10000];   //[Nsteps]
0073   Int_t           ParticleStepID[10000];   //[Nsteps]
0074   Int_t           ParticleStepPreInteraction[10000];   //[Nsteps]
0075   Int_t           ParticleStepPostInteraction[10000];   //[Nsteps]
0076   Float_t         MaterialDensity[10000];   //[Nsteps]
0077   Float_t         MaterialLambda0[10000];   //[Nsteps]
0078   Float_t         ParticleStepInitialPt[10000];   //[Nsteps]
0079   Float_t         ParticleStepFinalPt[10000];   //[Nsteps]
0080   
0081   // List of branches
0082   TBranch        *b_ParticleID;   //!
0083   TBranch        *b_Nsteps;   //!
0084   TBranch        *b_InitialX;   //!
0085   TBranch        *b_InitialY;   //!
0086   TBranch        *b_InitialZ;   //!
0087   TBranch        *b_FinalX;   //!
0088   TBranch        *b_FinalY;   //!
0089   TBranch        *b_FinalZ;   //!
0090   TBranch        *b_FinalE;   //!
0091   TBranch        *b_InitialE;   //!
0092   TBranch        *b_InitialM;   //!
0093   TBranch        *b_ParticleStepID;   //!
0094   TBranch        *b_ParticleStepPreInteraction;   //!
0095   TBranch        *b_ParticleStepPostInteraction;   //!
0096   TBranch        *b_MaterialDensity;   //!
0097   TBranch        *b_MaterialLambda0;   //!
0098   TBranch        *b_ParticleStepInitialPt;   //!
0099   TBranch        *b_ParticleStepFinalPt;   //!
0100   
0101   Loopers(TString fileName);
0102   virtual ~Loopers();
0103   virtual Int_t    Cut(Long64_t entry);
0104   virtual Int_t    GetEntry(Long64_t entry);
0105   virtual Long64_t LoadTree(Long64_t entry);
0106   virtual void     Init(TTree *tree);
0107   virtual void     Loop();
0108   virtual Bool_t   Notify();
0109   virtual void     Show(Long64_t entry = -1);
0110 
0111   
0112 private:
0113   //
0114   virtual void helpfulCommands();
0115   //
0116   // directory to store images
0117   TString theDirName;
0118   // decay
0119   Bool_t isDecay;
0120   Int_t actualParticleID;
0121 };
0122 
0123 #endif
0124 
0125 #ifdef Loopers_cxx
0126 Loopers::Loopers(TString fileName)
0127 {
0128   // images directory
0129   theDirName = "Images";
0130   
0131   // files
0132   cout << "*** Open file... " << endl;
0133   cout << fileName << endl;
0134   cout << "***" << endl;
0135   cout << " Output Directory... " << endl;
0136   cout << theDirName << endl;
0137   cout << "***" << endl;
0138   //
0139   theLogFile.open("Loopers.log");
0140   //
0141   
0142   // open root files
0143   TFile* theDetectorFile = new TFile(fileName);
0144   //
0145   // get tree
0146   TTree* theTree = (TTree*)theDetectorFile->Get("T1");
0147   //
0148   Init(theTree);
0149   Book();
0150   //
0151   helpfulCommands();
0152   //
0153   isDecay = false;
0154   actualParticleID = 0;
0155 }
0156 
0157 Loopers::~Loopers()
0158 {
0159   if (!fChain) return;
0160   delete fChain->GetCurrentFile();
0161 }
0162 
0163 Int_t Loopers::GetEntry(Long64_t entry)
0164 {
0165   // Read contents of entry.
0166   if (!fChain) return 0;
0167   return fChain->GetEntry(entry);
0168 }
0169 Long64_t Loopers::LoadTree(Long64_t entry)
0170 {
0171   // Set the environment to read one entry
0172   if (!fChain) return -5;
0173   Long64_t centry = fChain->LoadTree(entry);
0174   if (centry < 0) return centry;
0175   if (fChain->IsA() != TChain::Class()) return centry;
0176   TChain *chain = (TChain*)fChain;
0177   if (chain->GetTreeNumber() != fCurrent) {
0178     fCurrent = chain->GetTreeNumber();
0179     Notify();
0180   }
0181   return centry;
0182 }
0183 
0184 void Loopers::Init(TTree *tree)
0185 {
0186   // The Init() function is called when the selector needs to initialize
0187   // a new tree or chain. Typically here the branch addresses and branch
0188   // pointers of the tree will be set.
0189   // It is normaly not necessary to make changes to the generated
0190   // code, but the routine can be extended by the user if needed.
0191   // Init() will be called many times when running on PROOF
0192   // (once per file to be processed).
0193   
0194   // Set branch addresses and branch pointers
0195   if (!tree) return;
0196   fChain = tree;
0197   fCurrent = -1;
0198   fChain->SetMakeClass(1);
0199   
0200   fChain->SetBranchAddress("Particle ID", &ParticleID, &b_ParticleID);
0201   fChain->SetBranchAddress("Nsteps", &Nsteps, &b_Nsteps);
0202   fChain->SetBranchAddress("Initial X", InitialX, &b_InitialX);
0203   fChain->SetBranchAddress("Initial Y", InitialY, &b_InitialY);
0204   fChain->SetBranchAddress("Initial Z", InitialZ, &b_InitialZ);
0205   fChain->SetBranchAddress("Final X", FinalX, &b_FinalX);
0206   fChain->SetBranchAddress("Final Y", FinalY, &b_FinalY);
0207   fChain->SetBranchAddress("Final Z", FinalZ, &b_FinalZ);
0208   fChain->SetBranchAddress("Particle Step Initial Energy", InitialE, &b_InitialE);
0209   fChain->SetBranchAddress("Particle Step Final Energy", FinalE, &b_FinalE);
0210   fChain->SetBranchAddress("Particle Step Initial Mass", InitialM, &b_InitialM);
0211   fChain->SetBranchAddress("Particle Step ID", ParticleStepID, &b_ParticleStepID);
0212   fChain->SetBranchAddress("Particle Step Pre Interaction", ParticleStepPreInteraction, &b_ParticleStepPreInteraction);
0213   fChain->SetBranchAddress("Particle Step Post Interaction", ParticleStepPostInteraction, &b_ParticleStepPostInteraction);
0214   fChain->SetBranchAddress("Material Density", MaterialDensity, &b_MaterialDensity);
0215   fChain->SetBranchAddress("Material Lambda0", MaterialLambda0, &b_MaterialLambda0);
0216   fChain->SetBranchAddress("Particle Step Initial Pt", ParticleStepInitialPt, &b_ParticleStepInitialPt);
0217   fChain->SetBranchAddress("Particle Step Final Pt", ParticleStepFinalPt, &b_ParticleStepFinalPt);
0218   Notify();
0219 }
0220 
0221 Bool_t Loopers::Notify()
0222 {
0223   // The Notify() function is called when a new file is opened. This
0224   // can be either for a new TTree in a TChain or when when a new TTree
0225   // is started when using PROOF. It is normaly not necessary to make changes
0226   // to the generated code, but the routine can be extended by the
0227   // user if needed. The return value is currently not used.
0228   
0229   return kTRUE;
0230 }
0231 
0232 void Loopers::Show(Long64_t entry)
0233 {
0234   // Print contents of entry.
0235   // If entry is not specified, print current entry
0236   if (!fChain) return;
0237   fChain->Show(entry);
0238 }
0239 Int_t Loopers::Cut(Long64_t entry)
0240 {
0241   // This function may be called from Loop.
0242   // returns  1 if entry is accepted.
0243   // returns -1 otherwise.
0244   return 1;
0245 }
0246 
0247 void Loopers::Book(){
0248   hist_loops = new TH1F("hist_loops",
0249             "Number of Turns before stopping;Turns [2#pi];Events/bin",
0250             80,0,20);
0251   hist_energy_init = new TH1F("hist_energy_init",
0252                   "Energy at starting point;Energy [MeV];Events/bin",
0253                   100,0.0,1000.0);
0254   hist_energy_end = new TH1F("hist_energy_end",
0255                  "Energy at stopping point;Energy [MeV];Events/bin",
0256                  100,0.0,1000.0);
0257   hist_energy_beforeend = new TH1F("hist_energy_beforeend",
0258                    "Energy before stopping point;Energy [MeV];Events/bin",
0259                    100,0.0,1000.0);
0260   hist_density = new TH1F("hist_density",
0261               "Average Density;#bar{#rho} [g/cm^{3}];Events/bin",
0262               30,0.0,0.3);
0263   hist_lambda0 = new TH1F("hist_lambda0",
0264               "Average Nuclear Interaction Length;#bar{#\lambda_{0}} [mm];Events/bin",
0265               200,0.0,20000.0);
0266   hist_density_vs_loops = new TH2F("hist_density_vs_loops",
0267                    "Average Density vs Number of Turns;Turns [2#pi];#bar{#rho} [g/cm^{3}];Events/bin",
0268                    80,0,20,30,0.0,0.3);
0269   
0270   hist_pT_init = new TH1F("hist_pT_init",
0271               "Transverse Momentum at starting point;p_{T} [MeV/c];Events/bin",
0272               100,0.0,1000.0);
0273   hist_pT_end = new TH1F("hist_pT_end",
0274              "Transverse Momentum at stopping point;p_{T} [MeV/c];Events/bin",
0275              100,0.0,1000.0);
0276   hist_energyLossPerTurn = new TH1F("hist_energyLossPerTurn",
0277                     "Energy Loss per Turn;Energy [MeV];Events/bin",
0278                     50,0.0,500.0);
0279   hist_trackLength = new TH1F("hist_trackLength",
0280                   "Track Length;Length [mm];Events/bin",
0281                   100,0.0,100000.0);
0282   hist_trackLengthPerTurn = new TH1F("hist_trackLengthPerTurn",
0283                      "Track Length per Turn;Track Length [mm];Events/bin",
0284                      50,0.0,50000.0);
0285   hist_lastInteraction = new TH1F("hist_lastInteraction",
0286                   "Last Geant4 Process;Process Type;Events/bin",
0287                   11,-0.5,10.5);
0288   hist_bx = new TH1F("hist_bx",
0289              "Bunch Crossings [25 ns];Bunch Crossing [25 ns];Events/bin",
0290              21,-0.25,10.25);
0291   
0292   hist_bx_finer = new TH1F("hist_bx_finer",
0293                "Bunch Crossings [25 ns];Bunch Crossing [25 ns];Events/bin",
0294                100,0,10);
0295   
0296   hist_energybeforeend_vs_lastInteraction = new TH2F("hist_energybeforeend_vs_lastInteraction",
0297                              "Energy before stopping point vs Last Geant4 Process;Process Type;Energy [MeV];Events/bin",
0298                              11,-0.5,10.5,100,0.0,1000.0);
0299   hist_trackLength_vs_lastInteraction = new TH2F("hist_trackLength_vs_lastInteraction",
0300                          "Track Length vs Last Geant4 Process;Process Type;Length [mm];Events/bin",
0301                          11,-0.5,10.5,30,0.0,30000.0);
0302   hist_hadronicInteractions = new TH1F("hist_hadronicInteractions",
0303                        "Number of Hadronic Interactions;Hadronic Interactions;Events/bin",
0304                        7,-0.5,6.5);
0305   hist_hadronicInteractions_vs_lastInteraction = new TH2F("hist_hadronicInteractions_vs_lastInteraction",
0306                               "Number of Hadronic Interactions vs Last Geant4 Process;Process Type;Hadronic Interactions;Events/bin",
0307                               11,-0.5,10.5,7,-0.5,6.5);
0308   hist_energyLossHadronicInteractions = new TH1F("hist_energyLossHadronicInteractions",
0309                          "Energy Loss in Hadronic Interactions;Energy [MeV];Events/bin",
0310                          100,0.0,1000.0);
0311 
0312   hist_productionEnergy_vs_secondaryParticle = new TH2F("hist_productionEnergy_vs_secondaryParticle",
0313   "Kinetic Energy at Production vs Secondary Particle;Secondary Particle;Energy [MeV];Events/bin",
0314   4,0.5,4.5,100,0.0,1000.0);
0315   
0316   hist_bx_vs_secondaryParticle = new TH2F("hist_bx_vs_secondaryParticle",
0317                       "Bunch Crossings [25 ns] vs Secondary Particle;Secondary Particle;Bunch Crossing [25 ns];Events/bin",
0318                       4,0.5,4.5,21,-0.25,10.25);
0319 
0320 }
0321 
0322 void Loopers::MakePlots(TString suffix);
0323 
0324 void Loopers::rootStyle();
0325 
0326 #endif // #ifdef Loopers_cxx