star-travex
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
stihify.cc
Go to the documentation of this file.
1 #include <fstream>
2 #include <string>
3 
4 #include "TChain.h"
5 #include "TError.h"
6 #include "TGeoNavigator.h"
7 #include "TGeoManager.h"
8 #include "TRandom.h"
9 
10 #include "src-tools/config.h"
11 
12 #include "StiHify/StiHifyEvent.h"
15 
16 
17 
18 void loop_over_tree(StiHifyPrgOptions &prgOpts);
19 
20 
21 int main(int argc, char **argv)
22 {
23  const std::string stiTreeName = "t";
24 
25  StiHifyPrgOptions prgOpts(argc, argv, stiTreeName);
26  prgOpts.ProcessOptions();
27 
28  loop_over_tree(prgOpts);
29 
30  return EXIT_SUCCESS;
31 }
32 
33 
35 {
36  TChain *treeChain = prgOpts.GetStiTChain();
37 
38  StiHifyRootFile outRootFile(prgOpts, "recreate");
39 
40  int nTreeEvents = treeChain->GetEntries();
41  int nProcEvents = 0;
42 
43  Info("loop_over_tree", "Found tree/chain with N entries: %d", nTreeEvents);
44 
45  nTreeEvents = (prgOpts.GetMaxEventsUser() < nTreeEvents) ? prgOpts.GetMaxEventsUser() : nTreeEvents;
46 
47  Info("loop_over_tree", "Will process %d events", nTreeEvents);
48 
49  StiHifyEvent *stiHifyEvent = new StiHifyEvent();
50  treeChain->SetBranchAddress("e.", &stiHifyEvent);
51  treeChain->SetBranchStatus("e.*", false);
52  treeChain->SetBranchStatus("e.TStiEvent.fTStiKalmanTracks*", true);
53  treeChain->SetBranchStatus("e.TStiEvent.fTStiHits*", true);
54 
55  TRandom myRandom;
56 
57  Info("loop_over_tree", "Looping over tree/chain...");
58 
59  for (int iEvent = 1; iEvent <= nTreeEvents; iEvent++, nProcEvents++)
60  {
61  if ( nTreeEvents >= 10 && iEvent % int(nTreeEvents*0.1) == 0 )
62  Info("loop_over_tree", "Analyzing event %d", iEvent);
63 
64  if (myRandom.Rndm() > prgOpts.GetSparsity()) continue;
65 
66  treeChain->GetEntry(iEvent-1);
67 
68  // If requested by the user modify the event read from the input tree such
69  // that the closest within certain window hit for each track node is
70  // defined as the accepted one
71  if (prgOpts.AcceptCandidateHit())
72  stiHifyEvent->AssignClosestCandidateHit();
73 
74  outRootFile.FillHists(*stiHifyEvent);
75  }
76 
77  delete stiHifyEvent;
78 
79  outRootFile.Finalize();
80  outRootFile.Write();
81  outRootFile.Close();
82 }
void Finalize()
Create ratios for all histograms whose name starts with hActiveLayerCounts.
void loop_over_tree(StiHifyPrgOptions &prgOpts)
Definition: stihify.cc:34
void AssignClosestCandidateHit()
Loops over the internal container of tracks and calls the track method to override the accepted hits ...
void FillHists(const StiHifyEvent &event)
Processes and controls user options provided in the command line.
bool AcceptCandidateHit() const
int main(int argc, char **argv)
Definition: stihify.cc:21
void ProcessOptions()
Takes the standard command line arguments and parses them with the boost program_options utility...