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 
34 namespace edm
35 {
37 : flagSimTrack_(false),
38  flagSimVertex_(false),
39  flagHepMCProduct_(false),
40  flagPCaloHit_(false),
41  flagPSimHit_(false)
42 {
43 
44  //register your products
45  ParameterSet ps=iConfig.getParameter<ParameterSet>("mixObjects");
46  std::vector<std::string> names = ps.getParameterNames();
47  for (std::vector<std::string>::iterator it=names.begin();it!= names.end();++it)
48  {
50  if (!pset.exists("type")) continue; //to allow replacement by empty pset
51 
52  std::string object = pset.getParameter<std::string>("type");
53  std::vector<InputTag> tags=pset.getParameter<std::vector<InputTag> >("input");
54 
55  //SimTracks
56  if (object=="SimTrack") {
57  flagSimTrack_ = true;
58 
59  InputTag tag;
60  if (tags.size()>0) tag=tags[0];
62  branchesActivate(TypeID(typeid(std::vector<SimTrack>)).friendlyClassName(),std::string(""),tag,label);
63  produces<PCrossingFrame<SimTrack> >(label);
64  consumes<std::vector<SimTrack>>(tag);
65  LogInfo("MixingModule") <<"Add PCrossingFrame<SimTrack> "<<object<<"s with InputTag= "<<tag.encode()<<", label will be "<<label;
66 
67  }
68  //SimVertices
69  else if (object=="SimVertex") {
70  flagSimVertex_ = true;
71 
72  InputTag tag;
73  if (tags.size()>0) tag=tags[0];
75  branchesActivate(TypeID(typeid(std::vector<SimVertex>)).friendlyClassName(),std::string(""),tag,label);
76  produces<PCrossingFrame<SimVertex> >(label);
77  consumes<std::vector<SimVertex>>(tag);
78  LogInfo("MixingModule") <<"Add SimVertexContainer "<<object<<"s with InputTag= "<<tag.encode()<<", 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) tag=tags[0];
89  else if(tags.size()>1) tag=tags[ii];
91 
92  branchesActivate(TypeID(typeid(std::vector<PCaloHit>)).friendlyClassName(),subdets[ii],tag,label);
93  produces<PCrossingFrame<PCaloHit> >(label);
94  consumes<std::vector<PCaloHit>>(tag);
95  LogInfo("MixingModule") <<"Add PCrossingFrame<PCaloHit> "<<object<<"s with InputTag= "<<tag.encode()<<", label will be "<<label;
96 
97  // fill table with labels
98  labCaloHit.push_back(label);
99  }
100  }
101 
102  // PSimHit
103  else if (object=="PSimHit"){
104  flagPSimHit_ = true;
105 
106  std::vector<std::string> subdets=pset.getParameter<std::vector<std::string> >("subdets");
107  for (unsigned int ii=0;ii<subdets.size();ii++) {
108  InputTag tag;
109  if (tags.size()==1) tag=tags[0];
110 
111  else if(tags.size()>1) tag=tags[ii];
113 
114  branchesActivate(TypeID(typeid(std::vector<PSimHit>)).friendlyClassName(),subdets[ii],tag,label);
115  produces<PCrossingFrame<PSimHit> >(label);
116  consumes<std::vector<PSimHit>>(tag);
117  LogInfo("MixingModule") <<"Add PSimHitContainer "<<object<<"s with InputTag= "<<tag.encode()<<", label will be "<<label;
118 
119  // fill table with labels
120  labSimHit.push_back(label);
121  } //end for
122  }
123 
124  // HepMCProduct
125  else if (object=="HepMCProduct"){
126  flagHepMCProduct_ = true;
127 
128  InputTag tag;
129  if (tags.size()>0) tag=tags[0];
131 
132  branchesActivate(TypeID(typeid(HepMCProduct)).friendlyClassName(),std::string(""),tag,label);
133  produces<PCrossingFrame<edm::HepMCProduct> >(label);
134  consumes<HepMCProduct>(tag);
135  LogInfo("MixingModule") <<"Add HepMCProduct "<<object<<"s with InputTag= "<<tag.encode()<<", label will be "<<label;
136  }
137  else LogWarning("MixingModule") <<"You did not mix a type of object("<<object<<").";
138 
139  }//end for
140 }
141 
142 
144 }
145 
146 
147 
149 
150 
152 {
153 
154  if (flagSimTrack_){
155  bool gotTracks;
157  gotTracks = iEvent.getByLabel("mix","g4SimHits",cf_simtrack);
158 
159  if (gotTracks){
160  PCrossingFrame<SimTrack> * PCFbis = new PCrossingFrame<SimTrack>(*cf_simtrack.product());
161  std::unique_ptr<PCrossingFrame<SimTrack> > pOutTrack(PCFbis);
162  iEvent.put(std::move(pOutTrack),"g4SimHits");
163  }
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  }
180  else{
181  LogInfo("MixingModule") << " Please, check if the object <SimVertex> has been mixed by the MixingModule!";
182  }
183  }
184 
185  // PCaloHit
186  if (flagPCaloHit_){
187 
188  for (unsigned int ii=0;ii<labCaloHit.size();ii++){
189  bool gotPCaloHit;
191  gotPCaloHit=iEvent.getByLabel("mix",labCaloHit[ii],cf_calohit);
192 
193  if (gotPCaloHit){
194  PCrossingFrame<PCaloHit> * PCFPhCaloHit = new PCrossingFrame<PCaloHit>(*cf_calohit.product());
195  std::unique_ptr<PCrossingFrame<PCaloHit> > pOutHCalo(PCFPhCaloHit);
196  iEvent.put(std::move(pOutHCalo),labCaloHit[ii]);
197  }
198  else{
199  LogInfo("MixingModule") << " Please, check if the object <PCaloHit> " << labCaloHit[ii] << " has been mixed by the MixingModule!";
200  }
201  }
202 
203  }
204 
205  if (flagPSimHit_){
206 
207  for (unsigned int ii=0;ii<labSimHit.size();ii++) {
208  bool gotPSimHit;
210  gotPSimHit=iEvent.getByLabel("mix",labSimHit[ii],cf_simhit);
211 
212  if (gotPSimHit){
213  PCrossingFrame<PSimHit> * PCFSimHit = new PCrossingFrame<PSimHit>(*cf_simhit.product());
214  std::unique_ptr<PCrossingFrame<PSimHit> > pOutSimHit(PCFSimHit);
215  iEvent.put(std::move(pOutSimHit),labSimHit[ii]);
216  }
217  else{
218  LogInfo("MixingModule") << " Please, check if the object <PSimHit> " << labSimHit[ii] << " has been mixed by the MixingModule!";
219  }
220 
221  }
222  }
223 
224 
225  //HepMCProduct
226  if (flagHepMCProduct_){
227  bool gotHepMCProduct;
229  gotHepMCProduct=iEvent.getByLabel("mix","generatorSmeared",cf_hepmc);
230  if (gotHepMCProduct){
232  std::unique_ptr<PCrossingFrame<edm::HepMCProduct> > pOuthepmcpr(PCFHepMC);
233  iEvent.put(std::move(pOuthepmcpr),"generator");
234  }
235  else{
236  LogInfo("MixingModule") << " Please, check if the object <HepMCProduct> has been mixed by the MixingModule!";
237  }
238 
239  }// end if flagHepMCProduct_
240 
241 }
242 
243 
245 
246  label=tag.label()+tag.instance();
247  wantedBranches_.push_back(friendlyName + '_' +
248  tag.label() + '_' +
249  tag.instance());
250 
251  //if useCurrentProcessOnly, we have to change the input tag
254  tag = InputTag(tag.label(),tag.instance(),processName);
255  }
256 
257 }
258 
259 }//edm
T getParameter(std::string const &) const
bool useCurrentProcessOnly_
Definition: CFWriter.h:49
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
static const HistoName names[]
std::vector< std::string > labCaloHit
Definition: CFWriter.h:58
bool exists(std::string const &parameterName) const
checks if a parameter exists
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:1
bool flagSimVertex_
Definition: CFWriter.h:51
bool flagPSimHit_
Definition: CFWriter.h:54
std::string encode() const
Definition: InputTag.cc:166
virtual void produce(edm::Event &e, const edm::EventSetup &c) override
Definition: CFWriter.cc:151
int iEvent
Definition: GenABIO.cc:230
std::vector< std::string > labSimHit
Definition: CFWriter.h:57
std::string friendlyName(std::string const &iFullName)
std::vector< std::string > wantedBranches_
Definition: CFWriter.h:48
bool flagPCaloHit_
Definition: CFWriter.h:53
void beginRun(const edm::Run &run, const edm::EventSetup &es) override
Definition: CFWriter.cc:143
std::vector< std::string > getParameterNames() const
virtual void branchesActivate(const std::string &friendlyName, std::string subdet, InputTag &tag, std::string &label)
Definition: CFWriter.cc:244
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:416
def getProcessName(pdgGen, requiredNumberOfGeneratedObjects)
ii
Definition: cuy.py:588
T const * product() const
Definition: Handle.h:81
bool flagHepMCProduct_
Definition: CFWriter.h:52
std::string const & label() const
Definition: InputTag.h:36
HLT enums.
virtual ~CFWriter()
Definition: CFWriter.cc:148
bool flagSimTrack_
Definition: CFWriter.h:50
static const std::string subdets[7]
Definition: TrackUtils.cc:66
std::string const & instance() const
Definition: InputTag.h:37
def move(src, dest)
Definition: eostools.py:510
CFWriter(const edm::ParameterSet &conf)
Definition: CFWriter.cc:36
Definition: Run.h:42