CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
34 
35 
36 namespace edm
37 {
39 : flagSimTrack_(false),
40  flagSimVertex_(false),
41  flagHepMCProduct_(false),
42  flagPCaloHit_(false),
43  flagPSimHit_(false)
44 {
45 
46  //register your products
47  ParameterSet ps=iConfig.getParameter<ParameterSet>("mixObjects");
48  std::vector<std::string> names = ps.getParameterNames();
49  for (std::vector<std::string>::iterator it=names.begin();it!= names.end();++it)
50  {
52  if (!pset.exists("type")) continue; //to allow replacement by empty pset
53 
54  std::string object = pset.getParameter<std::string>("type");
55  std::vector<InputTag> tags=pset.getParameter<std::vector<InputTag> >("input");
56 
57  //SimTracks
58  if (object=="SimTrack") {
59  flagSimTrack_ = true;
60 
61  InputTag tag;
62  if (tags.size()>0) tag=tags[0];
63  std::string label;
64  branchesActivate(TypeID(typeid(std::vector<SimTrack>)).friendlyClassName(),std::string(""),tag,label);
65  produces<PCrossingFrame<SimTrack> >(label);
66  LogInfo("MixingModule") <<"Add PCrossingFrame<SimTrack> "<<object<<"s with InputTag= "<<tag.encode()<<", label will be "<<label;
67 
68  }
69  //SimVertices
70  else if (object=="SimVertex") {
71  flagSimVertex_ = true;
72 
73  InputTag tag;
74  if (tags.size()>0) tag=tags[0];
75  std::string label;
76  branchesActivate(TypeID(typeid(std::vector<SimVertex>)).friendlyClassName(),std::string(""),tag,label);
77  produces<PCrossingFrame<SimVertex> >(label);
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];
90  std::string label;
91 
92  branchesActivate(TypeID(typeid(std::vector<PCaloHit>)).friendlyClassName(),subdets[ii],tag,label);
93  produces<PCrossingFrame<PCaloHit> >(label);
94  LogInfo("MixingModule") <<"Add PCrossingFrame<PCaloHit> "<<object<<"s with InputTag= "<<tag.encode()<<", label will be "<<label;
95 
96  // fill table with labels
97  labCaloHit.push_back(label);
98  }
99  }
100 
101  // PSimHit
102  else if (object=="PSimHit"){
103  flagPSimHit_ = true;
104 
105  std::vector<std::string> subdets=pset.getParameter<std::vector<std::string> >("subdets");
106  for (unsigned int ii=0;ii<subdets.size();ii++) {
107  InputTag tag;
108  if (tags.size()==1) tag=tags[0];
109 
110  else if(tags.size()>1) tag=tags[ii];
111  std::string label;
112 
113  branchesActivate(TypeID(typeid(std::vector<PSimHit>)).friendlyClassName(),subdets[ii],tag,label);
114  produces<PCrossingFrame<PSimHit> >(label);
115  LogInfo("MixingModule") <<"Add PSimHitContainer "<<object<<"s with InputTag= "<<tag.encode()<<", label will be "<<label;
116 
117  // fill table with labels
118  labSimHit.push_back(label);
119  } //end for
120  }
121 
122  // HepMCProduct
123  else if (object=="HepMCProduct"){
124  flagHepMCProduct_ = true;
125 
126  InputTag tag;
127  if (tags.size()>0) tag=tags[0];
128  std::string label;
129 
130  branchesActivate(TypeID(typeid(HepMCProduct)).friendlyClassName(),std::string(""),tag,label);
131  produces<PCrossingFrame<edm::HepMCProduct> >(label);
132  LogInfo("MixingModule") <<"Add HepMCProduct "<<object<<"s with InputTag= "<<tag.encode()<<", label will be "<<label;
133  }
134  else LogWarning("MixingModule") <<"You did not mix a type of object("<<object<<").";
135 
136  }//end for
137 }
138 
139 
141 }
142 
143 
144 
146 
147 
149 {
150 
151  if (flagSimTrack_){
152  bool gotTracks;
154  gotTracks = iEvent.getByLabel("mix","g4SimHits",cf_simtrack);
155 
156  if (gotTracks){
157  PCrossingFrame<SimTrack> * PCFbis = new PCrossingFrame<SimTrack>(*cf_simtrack.product());
158  std::auto_ptr<PCrossingFrame<SimTrack> > pOutTrack(PCFbis);
159  iEvent.put(pOutTrack,"g4SimHits");
160  }
161  else{
162  LogInfo("MixingModule") << " Please, check if the object <SimTrack> has been mixed by the MixingModule!";
163  }
164  }//end if flagSimTrack_
165 
166  //SimVertex
167  if (flagSimVertex_){
168  bool gotSimVertex;
170  gotSimVertex=iEvent.getByLabel("mix","g4SimHits",cf_simvtx);
171 
172  if (gotSimVertex){
173  PCrossingFrame<SimVertex> * PCFvtx = new PCrossingFrame<SimVertex>(*cf_simvtx.product());
174  std::auto_ptr<PCrossingFrame<SimVertex> > pOutVertex(PCFvtx);
175  iEvent.put(pOutVertex,"g4SimHits");
176  }
177  else{
178  LogInfo("MixingModule") << " Please, check if the object <SimVertex> has been mixed by the MixingModule!";
179  }
180  }
181 
182  // PCaloHit
183  if (flagPCaloHit_){
184 
185  for (unsigned int ii=0;ii<labCaloHit.size();ii++){
186  bool gotPCaloHit;
188  gotPCaloHit=iEvent.getByLabel("mix",labCaloHit[ii],cf_calohit);
189 
190  if (gotPCaloHit){
191  PCrossingFrame<PCaloHit> * PCFPhCaloHit = new PCrossingFrame<PCaloHit>(*cf_calohit.product());
192  std::auto_ptr<PCrossingFrame<PCaloHit> > pOutHCalo(PCFPhCaloHit);
193  iEvent.put(pOutHCalo,labCaloHit[ii]);
194  }
195  else{
196  LogInfo("MixingModule") << " Please, check if the object <PCaloHit> " << labCaloHit[ii] << " has been mixed by the MixingModule!";
197  }
198  }
199 
200  }
201 
202  if (flagPSimHit_){
203 
204  for (unsigned int ii=0;ii<labSimHit.size();ii++) {
205  bool gotPSimHit;
207  gotPSimHit=iEvent.getByLabel("mix",labSimHit[ii],cf_simhit);
208 
209  if (gotPSimHit){
210  PCrossingFrame<PSimHit> * PCFSimHit = new PCrossingFrame<PSimHit>(*cf_simhit.product());
211  std::auto_ptr<PCrossingFrame<PSimHit> > pOutSimHit(PCFSimHit);
212  iEvent.put(pOutSimHit,labSimHit[ii]);
213  }
214  else{
215  LogInfo("MixingModule") << " Please, check if the object <PSimHit> " << labSimHit[ii] << " has been mixed by the MixingModule!";
216  }
217 
218  }
219  }
220 
221 
222  //HepMCProduct
223  if (flagHepMCProduct_){
224  bool gotHepMCProduct;
226  gotHepMCProduct=iEvent.getByLabel("mix","generator",cf_hepmc);
227  if (gotHepMCProduct){
229  std::auto_ptr<PCrossingFrame<edm::HepMCProduct> > pOuthepmcpr(PCFHepMC);
230  iEvent.put(pOuthepmcpr,"generator");
231  }
232  else{
233  LogInfo("MixingModule") << " Please, check if the object <HepMCProduct> has been mixed by the MixingModule!";
234  }
235 
236  }// end if flagHepMCProduct_
237 
238 }
239 
240 
241 void CFWriter::branchesActivate(const std::string &friendlyName, std::string subdet, InputTag &tag,std::string &label) {
242 
243  label=tag.label()+tag.instance();
244  wantedBranches_.push_back(friendlyName + '_' +
245  tag.label() + '_' +
246  tag.instance());
247 
248  //if useCurrentProcessOnly, we have to change the input tag
250  const std::string processName = edm::Service<edm::service::TriggerNamesService>()->getProcessName();
251  tag = InputTag(tag.label(),tag.instance(),processName);
252  }
253 
254 }
255 
256 }//edm
T getParameter(std::string const &) const
bool useCurrentProcessOnly_
Definition: CFWriter.h:49
const std::string & label
Definition: MVAComputer.cc:186
std::vector< std::string > labCaloHit
Definition: CFWriter.h:58
bool exists(std::string const &parameterName) const
checks if a parameter exists
bool flagSimVertex_
Definition: CFWriter.h:51
bool flagPSimHit_
Definition: CFWriter.h:54
std::string encode() const
Definition: InputTag.cc:72
int iEvent
Definition: GenABIO.cc:243
std::vector< std::string > labSimHit
Definition: CFWriter.h:57
std::string friendlyName(std::string const &iFullName)
static std::string subdets[11]
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:84
std::vector< std::string > wantedBranches_
Definition: CFWriter.h:48
bool flagPCaloHit_
Definition: CFWriter.h:53
std::vector< std::string > getParameterNames() const
virtual void branchesActivate(const std::string &friendlyName, std::string subdet, InputTag &tag, std::string &label)
Definition: CFWriter.cc:241
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
tuple tags
Definition: o2o.py:248
T const * product() const
Definition: Handle.h:74
bool flagHepMCProduct_
Definition: CFWriter.h:52
std::string const & label() const
Definition: InputTag.h:25
virtual void produce(edm::Event &e, const edm::EventSetup &c)
Definition: CFWriter.cc:148
virtual ~CFWriter()
Definition: CFWriter.cc:145
bool flagSimTrack_
Definition: CFWriter.h:50
void beginRun(const edm::Run &run, const edm::EventSetup &es)
Definition: CFWriter.cc:140
static const HistoName names[]
std::string const & instance() const
Definition: InputTag.h:26
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
CFWriter(const edm::ParameterSet &conf)
Definition: CFWriter.cc:38
Definition: Run.h:32