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  {
51  ParameterSet pset=ps.getParameter<ParameterSet>((*it));
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];
64  branchesActivate(TypeID(typeid(std::vector<SimTrack>)).friendlyClassName(),std::string(""),tag,label);
65  produces<PCrossingFrame<SimTrack> >(label);
66  consumes<std::vector<SimTrack>>(tag);
67  LogInfo("MixingModule") <<"Add PCrossingFrame<SimTrack> "<<object<<"s with InputTag= "<<tag.encode()<<", label will be "<<label;
68 
69  }
70  //SimVertices
71  else if (object=="SimVertex") {
72  flagSimVertex_ = true;
73 
74  InputTag tag;
75  if (tags.size()>0) tag=tags[0];
77  branchesActivate(TypeID(typeid(std::vector<SimVertex>)).friendlyClassName(),std::string(""),tag,label);
78  produces<PCrossingFrame<SimVertex> >(label);
79  consumes<std::vector<SimVertex>>(tag);
80  LogInfo("MixingModule") <<"Add SimVertexContainer "<<object<<"s with InputTag= "<<tag.encode()<<", label will be "<<label;
81 
82  }
83  // PCaloHit
84  else if (object=="PCaloHit"){
85  flagPCaloHit_ = true;
86 
87  std::vector<std::string> subdets=pset.getParameter<std::vector<std::string> >("subdets");
88  for (unsigned int ii=0;ii<subdets.size();ii++) {
89  InputTag tag;
90  if (tags.size()==1) tag=tags[0];
91  else if(tags.size()>1) 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()<<", label will be "<<label;
98 
99  // fill table with labels
100  labCaloHit.push_back(label);
101  }
102  }
103 
104  // PSimHit
105  else if (object=="PSimHit"){
106  flagPSimHit_ = true;
107 
108  std::vector<std::string> subdets=pset.getParameter<std::vector<std::string> >("subdets");
109  for (unsigned int ii=0;ii<subdets.size();ii++) {
110  InputTag tag;
111  if (tags.size()==1) tag=tags[0];
112 
113  else if(tags.size()>1) tag=tags[ii];
115 
116  branchesActivate(TypeID(typeid(std::vector<PSimHit>)).friendlyClassName(),subdets[ii],tag,label);
117  produces<PCrossingFrame<PSimHit> >(label);
118  consumes<std::vector<PSimHit>>(tag);
119  LogInfo("MixingModule") <<"Add PSimHitContainer "<<object<<"s with InputTag= "<<tag.encode()<<", label will be "<<label;
120 
121  // fill table with labels
122  labSimHit.push_back(label);
123  } //end for
124  }
125 
126  // HepMCProduct
127  else if (object=="HepMCProduct"){
128  flagHepMCProduct_ = true;
129 
130  InputTag tag;
131  if (tags.size()>0) tag=tags[0];
133 
134  branchesActivate(TypeID(typeid(HepMCProduct)).friendlyClassName(),std::string(""),tag,label);
135  produces<PCrossingFrame<edm::HepMCProduct> >(label);
136  consumes<HepMCProduct>(tag);
137  LogInfo("MixingModule") <<"Add HepMCProduct "<<object<<"s with InputTag= "<<tag.encode()<<", label will be "<<label;
138  }
139  else LogWarning("MixingModule") <<"You did not mix a type of object("<<object<<").";
140 
141  }//end for
142 }
143 
144 
146 }
147 
148 
149 
151 
152 
154 {
155 
156  if (flagSimTrack_){
157  bool gotTracks;
159  gotTracks = iEvent.getByLabel("mix","g4SimHits",cf_simtrack);
160 
161  if (gotTracks){
162  PCrossingFrame<SimTrack> * PCFbis = new PCrossingFrame<SimTrack>(*cf_simtrack.product());
163  std::auto_ptr<PCrossingFrame<SimTrack> > pOutTrack(PCFbis);
164  iEvent.put(pOutTrack,"g4SimHits");
165  }
166  else{
167  LogInfo("MixingModule") << " Please, check if the object <SimTrack> has been mixed by the MixingModule!";
168  }
169  }//end if flagSimTrack_
170 
171  //SimVertex
172  if (flagSimVertex_){
173  bool gotSimVertex;
175  gotSimVertex=iEvent.getByLabel("mix","g4SimHits",cf_simvtx);
176 
177  if (gotSimVertex){
178  PCrossingFrame<SimVertex> * PCFvtx = new PCrossingFrame<SimVertex>(*cf_simvtx.product());
179  std::auto_ptr<PCrossingFrame<SimVertex> > pOutVertex(PCFvtx);
180  iEvent.put(pOutVertex,"g4SimHits");
181  }
182  else{
183  LogInfo("MixingModule") << " Please, check if the object <SimVertex> has been mixed by the MixingModule!";
184  }
185  }
186 
187  // PCaloHit
188  if (flagPCaloHit_){
189 
190  for (unsigned int ii=0;ii<labCaloHit.size();ii++){
191  bool gotPCaloHit;
193  gotPCaloHit=iEvent.getByLabel("mix",labCaloHit[ii],cf_calohit);
194 
195  if (gotPCaloHit){
196  PCrossingFrame<PCaloHit> * PCFPhCaloHit = new PCrossingFrame<PCaloHit>(*cf_calohit.product());
197  std::auto_ptr<PCrossingFrame<PCaloHit> > pOutHCalo(PCFPhCaloHit);
198  iEvent.put(pOutHCalo,labCaloHit[ii]);
199  }
200  else{
201  LogInfo("MixingModule") << " Please, check if the object <PCaloHit> " << labCaloHit[ii] << " has been mixed by the MixingModule!";
202  }
203  }
204 
205  }
206 
207  if (flagPSimHit_){
208 
209  for (unsigned int ii=0;ii<labSimHit.size();ii++) {
210  bool gotPSimHit;
212  gotPSimHit=iEvent.getByLabel("mix",labSimHit[ii],cf_simhit);
213 
214  if (gotPSimHit){
215  PCrossingFrame<PSimHit> * PCFSimHit = new PCrossingFrame<PSimHit>(*cf_simhit.product());
216  std::auto_ptr<PCrossingFrame<PSimHit> > pOutSimHit(PCFSimHit);
217  iEvent.put(pOutSimHit,labSimHit[ii]);
218  }
219  else{
220  LogInfo("MixingModule") << " Please, check if the object <PSimHit> " << labSimHit[ii] << " has been mixed by the MixingModule!";
221  }
222 
223  }
224  }
225 
226 
227  //HepMCProduct
228  if (flagHepMCProduct_){
229  bool gotHepMCProduct;
231  gotHepMCProduct=iEvent.getByLabel("mix","generator",cf_hepmc);
232  if (gotHepMCProduct){
234  std::auto_ptr<PCrossingFrame<edm::HepMCProduct> > pOuthepmcpr(PCFHepMC);
235  iEvent.put(pOuthepmcpr,"generator");
236  }
237  else{
238  LogInfo("MixingModule") << " Please, check if the object <HepMCProduct> has been mixed by the MixingModule!";
239  }
240 
241  }// end if flagHepMCProduct_
242 
243 }
244 
245 
247 
248  label=tag.label()+tag.instance();
249  wantedBranches_.push_back(friendlyName + '_' +
250  tag.label() + '_' +
251  tag.instance());
252 
253  //if useCurrentProcessOnly, we have to change the input tag
256  tag = InputTag(tag.label(),tag.instance(),processName);
257  }
258 
259 }
260 
261 }//edm
T getParameter(std::string const &) const
bool useCurrentProcessOnly_
Definition: CFWriter.h:49
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
bool flagSimVertex_
Definition: CFWriter.h:51
bool flagPSimHit_
Definition: CFWriter.h:54
int ii
Definition: cuy.py:588
std::string encode() const
Definition: InputTag.cc:164
virtual void produce(edm::Event &e, const edm::EventSetup &c) override
Definition: CFWriter.cc:153
int iEvent
Definition: GenABIO.cc:230
std::vector< std::string > labSimHit
Definition: CFWriter.h:57
std::string friendlyName(std::string const &iFullName)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
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:145
std::vector< std::string > getParameterNames() const
virtual void branchesActivate(const std::string &friendlyName, std::string subdet, InputTag &tag, std::string &label)
Definition: CFWriter.cc:246
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
tuple tags
Definition: o2o.py:248
constexpr char const * subdets[11]
T const * product() const
Definition: Handle.h:81
bool flagHepMCProduct_
Definition: CFWriter.h:52
std::string const & label() const
Definition: InputTag.h:42
virtual ~CFWriter()
Definition: CFWriter.cc:150
bool flagSimTrack_
Definition: CFWriter.h:50
volatile std::atomic< bool > shutdown_flag false
std::string const & instance() const
Definition: InputTag.h:43
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
CFWriter(const edm::ParameterSet &conf)
Definition: CFWriter.cc:38
Definition: Run.h:41