CMS 3D CMS Logo

CFWriter.cc
Go to the documentation of this file.
1 // File: CFWriter.cc
2 // Description: see CFWriter.h
3 // Author: Emilia Becheva, LLR Palaiseau
4 //
5 //--------------------------------------------
6 
8 
19 
29 
32 
33 namespace edm {
35  : flagSimTrack_(false),
36  flagSimVertex_(false),
37  flagHepMCProduct_(false),
38  flagPCaloHit_(false),
39  flagPSimHit_(false) {
40  //register your products
41  ParameterSet ps = iConfig.getParameter<ParameterSet>("mixObjects");
42  std::vector<std::string> names = ps.getParameterNames();
43  for (std::vector<std::string>::iterator it = names.begin(); it != names.end(); ++it) {
45  if (!pset.exists("type"))
46  continue; //to allow replacement by empty pset
47 
48  std::string object = pset.getParameter<std::string>("type");
49  std::vector<InputTag> tags = pset.getParameter<std::vector<InputTag>>("input");
50 
51  //SimTracks
52  if (object == "SimTrack") {
53  flagSimTrack_ = true;
54 
55  InputTag tag;
56  if (!tags.empty())
57  tag = tags[0];
59  branchesActivate(TypeID(typeid(std::vector<SimTrack>)).friendlyClassName(), std::string(""), tag, label);
60  produces<PCrossingFrame<SimTrack>>(label);
61  consumes<std::vector<SimTrack>>(tag);
62  LogInfo("MixingModule") << "Add PCrossingFrame<SimTrack> " << object << "s with InputTag= " << tag.encode()
63  << ", label will be " << label;
64 
65  }
66  //SimVertices
67  else if (object == "SimVertex") {
68  flagSimVertex_ = true;
69 
70  InputTag tag;
71  if (!tags.empty())
72  tag = tags[0];
74  branchesActivate(TypeID(typeid(std::vector<SimVertex>)).friendlyClassName(), std::string(""), tag, label);
75  produces<PCrossingFrame<SimVertex>>(label);
76  consumes<std::vector<SimVertex>>(tag);
77  LogInfo("MixingModule") << "Add SimVertexContainer " << object << "s with InputTag= " << tag.encode()
78  << ", label will be " << label;
79 
80  }
81  // PCaloHit
82  else if (object == "PCaloHit") {
83  flagPCaloHit_ = true;
84 
85  std::vector<std::string> subdets = pset.getParameter<std::vector<std::string>>("subdets");
86  for (unsigned int ii = 0; ii < subdets.size(); ii++) {
87  InputTag tag;
88  if (tags.size() == 1)
89  tag = tags[0];
90  else if (tags.size() > 1)
91  tag = tags[ii];
93 
94  branchesActivate(TypeID(typeid(std::vector<PCaloHit>)).friendlyClassName(), subdets[ii], tag, label);
95  produces<PCrossingFrame<PCaloHit>>(label);
96  consumes<std::vector<PCaloHit>>(tag);
97  LogInfo("MixingModule") << "Add PCrossingFrame<PCaloHit> " << object << "s with InputTag= " << tag.encode()
98  << ", label will be " << label;
99 
100  // fill table with labels
101  labCaloHit.push_back(label);
102  }
103  }
104 
105  // PSimHit
106  else if (object == "PSimHit") {
107  flagPSimHit_ = true;
108 
109  std::vector<std::string> subdets = pset.getParameter<std::vector<std::string>>("subdets");
110  for (unsigned int ii = 0; ii < subdets.size(); ii++) {
111  InputTag tag;
112  if (tags.size() == 1)
113  tag = tags[0];
114 
115  else if (tags.size() > 1)
116  tag = tags[ii];
118 
119  branchesActivate(TypeID(typeid(std::vector<PSimHit>)).friendlyClassName(), subdets[ii], tag, label);
120  produces<PCrossingFrame<PSimHit>>(label);
121  consumes<std::vector<PSimHit>>(tag);
122  LogInfo("MixingModule") << "Add PSimHitContainer " << object << "s with InputTag= " << tag.encode()
123  << ", label will be " << label;
124 
125  // fill table with labels
126  labSimHit.push_back(label);
127  } //end for
128  }
129 
130  // HepMCProduct
131  else if (object == "HepMCProduct") {
132  flagHepMCProduct_ = true;
133 
134  InputTag tag;
135  if (!tags.empty())
136  tag = tags[0];
138 
139  branchesActivate(TypeID(typeid(HepMCProduct)).friendlyClassName(), std::string(""), tag, label);
140  produces<PCrossingFrame<edm::HepMCProduct>>(label);
141  consumes<HepMCProduct>(tag);
142  LogInfo("MixingModule") << "Add HepMCProduct " << object << "s with InputTag= " << tag.encode()
143  << ", label will be " << label;
144  } else
145  LogWarning("MixingModule") << "You did not mix a type of object(" << object << ").";
146 
147  } //end for
148  }
149 
151 
153 
155  if (flagSimTrack_) {
156  bool gotTracks;
158  gotTracks = iEvent.getByLabel("mix", "g4SimHits", cf_simtrack);
159 
160  if (gotTracks) {
161  PCrossingFrame<SimTrack>* PCFbis = new PCrossingFrame<SimTrack>(*cf_simtrack.product());
162  std::unique_ptr<PCrossingFrame<SimTrack>> pOutTrack(PCFbis);
163  iEvent.put(std::move(pOutTrack), "g4SimHits");
164  } else {
165  LogInfo("MixingModule") << " Please, check if the object <SimTrack> has been mixed by the MixingModule!";
166  }
167  } //end if flagSimTrack_
168 
169  //SimVertex
170  if (flagSimVertex_) {
171  bool gotSimVertex;
173  gotSimVertex = iEvent.getByLabel("mix", "g4SimHits", cf_simvtx);
174 
175  if (gotSimVertex) {
176  PCrossingFrame<SimVertex>* PCFvtx = new PCrossingFrame<SimVertex>(*cf_simvtx.product());
177  std::unique_ptr<PCrossingFrame<SimVertex>> pOutVertex(PCFvtx);
178  iEvent.put(std::move(pOutVertex), "g4SimHits");
179  } else {
180  LogInfo("MixingModule") << " Please, check if the object <SimVertex> has been mixed by the MixingModule!";
181  }
182  }
183 
184  // PCaloHit
185  if (flagPCaloHit_) {
186  for (unsigned int ii = 0; ii < labCaloHit.size(); ii++) {
187  bool gotPCaloHit;
189  gotPCaloHit = iEvent.getByLabel("mix", labCaloHit[ii], cf_calohit);
190 
191  if (gotPCaloHit) {
192  PCrossingFrame<PCaloHit>* PCFPhCaloHit = new PCrossingFrame<PCaloHit>(*cf_calohit.product());
193  std::unique_ptr<PCrossingFrame<PCaloHit>> pOutHCalo(PCFPhCaloHit);
194  iEvent.put(std::move(pOutHCalo), labCaloHit[ii]);
195  } else {
196  LogInfo("MixingModule") << " Please, check if the object <PCaloHit> " << labCaloHit[ii]
197  << " has been mixed by the MixingModule!";
198  }
199  }
200  }
201 
202  if (flagPSimHit_) {
203  for (unsigned int ii = 0; ii < labSimHit.size(); ii++) {
204  bool gotPSimHit;
206  gotPSimHit = iEvent.getByLabel("mix", labSimHit[ii], cf_simhit);
207 
208  if (gotPSimHit) {
209  PCrossingFrame<PSimHit>* PCFSimHit = new PCrossingFrame<PSimHit>(*cf_simhit.product());
210  std::unique_ptr<PCrossingFrame<PSimHit>> pOutSimHit(PCFSimHit);
211  iEvent.put(std::move(pOutSimHit), labSimHit[ii]);
212  } else {
213  LogInfo("MixingModule") << " Please, check if the object <PSimHit> " << labSimHit[ii]
214  << " has been mixed by the MixingModule!";
215  }
216  }
217  }
218 
219  //HepMCProduct
220  if (flagHepMCProduct_) {
221  bool gotHepMCProduct;
223  gotHepMCProduct = iEvent.getByLabel("mix", "generatorSmeared", cf_hepmc);
224  if (gotHepMCProduct) {
226  std::unique_ptr<PCrossingFrame<edm::HepMCProduct>> pOuthepmcpr(PCFHepMC);
227  iEvent.put(std::move(pOuthepmcpr), "generator");
228  } else {
229  LogInfo("MixingModule") << " Please, check if the object <HepMCProduct> has been mixed by the MixingModule!";
230  }
231 
232  } // end if flagHepMCProduct_
233  }
234 
236  std::string subdet,
237  InputTag& tag,
238  std::string& label) {
239  label = tag.label() + tag.instance();
240  wantedBranches_.push_back(friendlyName + '_' + tag.label() + '_' + tag.instance());
241 
242  //if useCurrentProcessOnly, we have to change the input tag
245  tag = InputTag(tag.label(), tag.instance(), processName);
246  }
247  }
248 
249 } // namespace edm
bool useCurrentProcessOnly_
Definition: CFWriter.h:52
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
~CFWriter() override
Definition: CFWriter.cc:152
std::vector< std::string > labCaloHit
Definition: CFWriter.h:61
T const * product() const
Definition: Handle.h:70
bool flagSimVertex_
Definition: CFWriter.h:54
bool flagPSimHit_
Definition: CFWriter.h:57
const std::string names[nVars_]
void produce(edm::Event &e, const edm::EventSetup &c) override
Definition: CFWriter.cc:154
char const * label
int iEvent
Definition: GenABIO.cc:224
std::vector< std::string > labSimHit
Definition: CFWriter.h:60
std::string friendlyName(std::string const &iFullName)
std::vector< std::string > wantedBranches_
Definition: CFWriter.h:51
bool flagPCaloHit_
Definition: CFWriter.h:56
void beginRun(const edm::Run &run, const edm::EventSetup &es) override
Definition: CFWriter.cc:150
virtual void branchesActivate(const std::string &friendlyName, std::string subdet, InputTag &tag, std::string &label)
Definition: CFWriter.cc:235
def getProcessName(pdgGen, requiredNumberOfGeneratedObjects)
ii
Definition: cuy.py:589
Log< level::Info, false > LogInfo
bool flagHepMCProduct_
Definition: CFWriter.h:55
HLT enums.
bool flagSimTrack_
Definition: CFWriter.h:53
Log< level::Warning, false > LogWarning
static const std::string subdets[7]
Definition: TrackUtils.cc:60
std::vector< std::string > getParameterNames() const
def move(src, dest)
Definition: eostools.py:511
CFWriter(const edm::ParameterSet &conf)
Definition: CFWriter.cc:34
Definition: Run.h:45