LCFIPlus  0.6.5
LCIOStorer.h
Go to the documentation of this file.
1 // LCIOStorer.h
2 #ifndef LCIOStorer_h
3 #define LCIOStorer_h 1
4 
5 #include "lcfiplus.h"
6 #include <vector>
7 #include <string>
8 
9 #include "TObject.h"
10 
11 #include "lcio.h"
12 #include "IO/LCReader.h"
13 #include "IO/LCWriter.h"
14 #include "EVENT/LCEvent.h"
15 #include <EVENT/ReconstructedParticle.h>
16 #include "EVENT/MCParticle.h"
17 
18 using namespace std;
19 
20 namespace lcfiplus {
21 
22 class LCIOStorer : public TObject, public EventStoreObserver {
23  public:
24  LCIOStorer(const char* inputfile = NULL, const char* outputfile = NULL, bool autoread = true, bool autowrite = false, const char* outPrefix = 0);
25  virtual ~LCIOStorer();
26 
27  // in both func the obtained LCEvent is used for following operations
28  bool Next(bool autovertex = false, bool autojet = false); // file mode: move to the next event
29  void SetEvent(lcio::LCEvent* event); // non-file mode
30  void SetColorSinglets(vector<MCParticle*>& mcps, vector<MCColorSinglet*>& mccs);
31 
32  // LCIO -> lcfiplus
33  // register basic collections to EventStore
34  void InitMCPPFOCollections(const char* pfoColName, const char* mcColName, const char* mcpfoColName);
35  void InitPFOCollections(const char* pfoColName);
36 
37  // initialize misc collections
38  void InitVertexCollection(const char* lcioName, const char* flavtagName, bool readnow = true);
39  void InitJetCollection(const char* lcioName, const char* flavtagName, bool readnow = true, bool readvtx = true, const char* vtxname = 0);
40 
41  /*
42  // register every LCIO collections: used only in standalone
43  void InitVertexCollectionsAuto(lcio::LCEvent *evt);
44  void InitJetCollectionsAuto(lcio::LCEvent *evt);
45  */
46  // vertices/jets
47  void ReadVertices(const char* vtxname, vector<const Vertex*>* lcficol);
48  void ReadJets(const char* jetname, vector<const Jet*>* lcficol, const char* vtxrelname = 0);
49 
50  // lcfiplus -> LCIO
51  void WriteVertices(const char* vertexName, const char* outName = 0, const char* outRPName = 0);
52  void WriteVertices(VertexVec* pvvtx, const char* newName, const char* newRPName = 0);
53  void WriteJets(const char* jetName, const char* outName = 0, bool writeVertex = true, const char* vtxName = 0, const char* relName = 0);
54 // void ConvertJetWithFlavor(const char *jetName, const char *flavName);
55 
56  // convert PID : lcfiplus -> LCIO
57  void WritePID(lcio::LCCollection* lciocol, lcio::ReconstructedParticle* lciojet, const lcfiplus::Jet* lcfijet, const char* paramname);
58  void WriteAllPIDs(lcio::LCCollection* lciocol, lcio::ReconstructedParticle* lciojet, const lcfiplus::Jet* lcfijet);
59 
60  void WriteEvent(); // write to the outputfile
61  void AutoConvert(); // auto convert without WriteEvent()
62 
63  // helper functions for std::sort()
64  //static bool energy_sort_trk(Track *a, Track *b);
65  //static bool energy_sort_mc(MCParticle *a, MCParticle *b);
66  static bool energy_sort_pfo(lcio::ReconstructedParticle* a, lcio::ReconstructedParticle* b);
67 
68  void setReadSubdetectorEnergies(bool flag) {
69  _readSubdetectorEnergies = flag;
70  }
71  void setTrackHitOrdering(int flag) {
72  _trackHitOrdering = flag;
73  }
74  void setUpdateVertexRPDaughters(bool flag) {
75  _updateVertexRPDaughters = flag;
76  }
77  void setIgnoreLackOfVertexRP(bool flag) {
78  _ignoreLackOfVertexRP = flag;
79  }
80 
81  void setParticleIDAlgorithmName(const char* algoName) {
82  _pidAlgoName = algoName;
83  }
84 
86  return _readSubdetectorEnergies;
87  }
88  int getTrackHitOrdering()const {
89  return _trackHitOrdering;
90  }
92  return _updateVertexRPDaughters;
93  }
95  return _ignoreLackOfVertexRP;
96  }
97 
99  return _pidAlgoName.c_str();
100  }
101 
102  // callback function from EventStore
103  virtual void GetCallback(const char* name, const char* classname);
104 
105  private:
106  lcio::LCEvent* _event;
107  lcio::LCReader* _reader;
108  lcio::LCWriter* _writer;
109 
110  // collections to import
111  map<string, vector<lcfiplus::MCParticle*> *> _importMCPCols;
112  map<string, vector<lcfiplus::MCColorSinglet*> *> _importMCCSCols;
113  map<string, pair<vector<lcfiplus::Track*> *, vector<lcfiplus::Neutral*> *> >_importPFOCols;
114  map<string, pair<string,string> > _importMCPFOLinkCols; // Link, <MC, PFO>
115  map<string, vector<const lcfiplus::Vertex*> *> _importVertexCols;
116  map<string, vector<const lcfiplus::Jet*> *> _importJetCols;
117 
118  // LCIO - lcfiplus relation
119  map<lcfiplus::Track*, lcio::ReconstructedParticle*> _trackLCIORel;
120  map<lcfiplus::Neutral*, lcio::ReconstructedParticle*> _neutralLCIORel;
121  map<lcfiplus::MCParticle*, lcio::MCParticle*> _mcpLCIORel;
122  map<const lcfiplus::Vertex*, lcio::Vertex*> _vtxLCIORel;
123  map<const lcfiplus::Jet*, lcio::ReconstructedParticle*> _jetLCIORel;
124 
125  // reverse direction
126  map<lcio::ReconstructedParticle*, lcfiplus::Track*> _trackLCIORel2;
127  map<lcio::ReconstructedParticle*, lcfiplus::Neutral*> _neutralLCIORel2;
128  map<lcio::MCParticle*, lcfiplus::MCParticle*> _mcpLCIORel2;
129  map<lcio::Vertex*, const lcfiplus::Vertex*> _vtxLCIORel2;
130  map<lcio::ReconstructedParticle*, const lcfiplus::Jet*> _jetLCIORel2;
131 
132  // autosave for output
133  bool _autoread; // for vertex/jet collections: on in LcfiplusProcessor
134  bool _autowrite; // for every persistent collections: off in LcfiplusProcessor
135  string _savePrefix;
136 
137  bool _readSubdetectorEnergies;
138  int _trackHitOrdering;
139  bool _updateVertexRPDaughters;
140  bool _ignoreLackOfVertexRP;
141  string _pidAlgoName;
142 
143  ClassDef(LCIOStorer,0);
144 };
145 
146 }
147 
148 #endif
bool getReadSubdetectorEnergies() const
Definition: LCIOStorer.h:85
bool getIgnoreLackOfVertexRP() const
Definition: LCIOStorer.h:94
bool getUpdateVertexRPDaughters() const
Definition: LCIOStorer.h:91
Definition: LCIOStorer.h:22
Definition: EventStore.h:17
const char * getParticleIDAlgorithmName()
Definition: LCIOStorer.h:98
void setReadSubdetectorEnergies(bool flag)
Definition: LCIOStorer.h:68
void setIgnoreLackOfVertexRP(bool flag)
Definition: LCIOStorer.h:77
void setUpdateVertexRPDaughters(bool flag)
Definition: LCIOStorer.h:74
void setTrackHitOrdering(int flag)
Definition: LCIOStorer.h:71
Definition: lcfiplus.h:980
void setParticleIDAlgorithmName(const char *algoName)
Definition: LCIOStorer.h:81
int getTrackHitOrdering() const
Definition: LCIOStorer.h:88
const vector< const Vertex * > VertexVec
Definition: lcfiplus.h:79