All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
SimpleMuonDigi.cc
Go to the documentation of this file.
1 #include "SimpleMuonDigi.h"
2 #include <EVENT/LCCollection.h>
3 #include <EVENT/SimCalorimeterHit.h>
4 #include <IMPL/CalorimeterHitImpl.h>
5 #include <IMPL/LCCollectionVec.h>
6 #include <IMPL/LCFlagImpl.h>
7 #include <IMPL/LCRelationImpl.h>
8 #include <EVENT/LCParameters.h>
9 #include <UTIL/CellIDDecoder.h>
10 
11 // #include <algorithm>
12 // #include <string>
13 #include <cctype>
14 #include <cstdlib> // abs
15 
16 // STUFF needed for GEAR
17 #include <marlin/Global.h>
18 #include <gear/GEAR.h>
19 #include <gear/CalorimeterParameters.h>
20 #include <gear/LayerLayout.h>
21 
22 
23 using namespace std;
24 using namespace lcio ;
25 using namespace marlin ;
26 
27 
29 
30 
31 SimpleMuonDigi::SimpleMuonDigi() : Processor("SimpleMuonDigi") {
32 
33  _description = "Performs simple digitization of sim muon hits..." ;
34 
35  std::vector<std::string> muonCollections;
36 
37  muonCollections.push_back(std::string("yoke03_MuonBarrel"));
38  muonCollections.push_back(std::string("yoke03_MuonEndCap"));
39  muonCollections.push_back(std::string("yoke03_MuonPlug"));
40 
41 
42  registerInputCollections( LCIO::SIMCALORIMETERHIT,
43  "MUONCollections" ,
44  "Muon Collection Names" ,
46  muonCollections);
47 
48  registerOutputCollection( LCIO::CALORIMETERHIT,
49  "MUONOutputCollection" ,
50  "Muon Collection of real Hits" ,
52  std::string("MUON")) ;
53 
54  registerOutputCollection( LCIO::LCRELATION,
55  "RelationOutputCollection" ,
56  "CaloHit Relation Collection" ,
58  std::string("RelationMuonHit")) ;
59 
60  registerProcessorParameter("MuonThreshold" ,
61  "Threshold for Muon Hits in GeV" ,
63  (float)0.025);
64 
65  registerProcessorParameter("CalibrMUON" ,
66  "Calibration coefficients for MUON" ,
68  (float)120000.);
69 
70  registerProcessorParameter("MaxHitEnergyMUON",
71  "maximum hit energy for a MUON hit" ,
73  (float)2.0);
74 
75  IntVec keepBarrelLayersVec, keepEndcapLayersVec;
76 
77  registerProcessorParameter("KeepBarrelLayersVec" ,
78  "Vector of Barrel layers to be kept. Layers start at 1!",
80  keepBarrelLayersVec);
81 
82  registerProcessorParameter("KeepEndcapLayersVec" ,
83  "Vector of Endcap layers to be kept. Layers start at 1!",
85  keepEndcapLayersVec);
86 
87 
88  registerProcessorParameter("CellIDLayerString" ,
89  "name of the part of the cellID that holds the layer" ,
91  std::string("K-1")
92  );
93 
94 }
95 
97 
98  _nRun = -1;
99  _nEvt = 0;
100 
101  //fg: need to set default encoding in for reading old files...
102  CellIDDecoder<SimCalorimeterHit>::setDefaultEncoding("M:3,S-1:3,I:9,J:9,K-1:6") ;
103 
104 
105  //Get the number of Layers in the Endcap
106  int layersEndcap=0, layersBarrel=0;
107 
108  try{
109  layersBarrel = Global::GEAR->getYokeBarrelParameters().getLayerLayout().getNLayers();
110  }catch( gear::UnknownParameterException& e ){
111  streamlog_out(WARNING) << " oops - no Yoke Barrel available " << std::endl ;
112  }
113  try{
114  layersEndcap = Global::GEAR->getYokeEndcapParameters().getLayerLayout().getNLayers();
115  }catch( gear::UnknownParameterException& e ){
116  streamlog_out(WARNING) << " oops - no Yoke Endcap available " << std::endl ;
117  }
118 
119  //If the vectors are empty, we are keeping everything
120  if(_layersToKeepBarrelVec.size() > 0) {
121  //layers start at 0
122  for(int i = 0; i < layersBarrel; ++i) {
123  _useLayersBarrelVec.push_back(false);
124  for(IntVec::iterator iter = _layersToKeepBarrelVec.begin(); iter < _layersToKeepBarrelVec.end(); ++iter) {
125  if (i == *iter-1){
126  _useLayersBarrelVec[i]=true; break;
127  }
128  }
129  }
130  }
131 
132  if(_layersToKeepEndcapVec.size() > 0) {
133  //layers start at 0
134  for(int i = 0; i < layersEndcap; ++i) {
135  _useLayersEndcapVec.push_back(false);
136  for(IntVec::iterator iter = _layersToKeepEndcapVec.begin(); iter < _layersToKeepEndcapVec.end(); ++iter) {
137  if (i == *iter-1){
138  _useLayersEndcapVec[i]=true; break;
139  }
140  }
141  }
142  }
143 
144 
145 
146 }
147 
148 
149 void SimpleMuonDigi::processRunHeader( LCRunHeader* /*run*/) {
150  _nRun++ ;
151  _nEvt = 0;
152 }
153 
154 void SimpleMuonDigi::processEvent( LCEvent * evt ) {
155 
156 
157  streamlog_out( DEBUG ) << " process event : " << evt->getEventNumber()
158  << " - run " << evt->getRunNumber() << std::endl ;
159 
160 
161  LCCollectionVec *muoncol = new LCCollectionVec(LCIO::CALORIMETERHIT);
162  LCCollectionVec *relcol = new LCCollectionVec(LCIO::LCRELATION);
163 
164  LCFlagImpl flag;
165 
166  flag.setBit(LCIO::CHBIT_LONG);
167 
168  muoncol->setFlag(flag.getFlag());
169 
170  //
171  // * Reading Collections of MUON Simulated Hits *
172  //
173  string initString;
174  for (unsigned int i(0); i < _muonCollections.size(); ++i) {
175 
176  std::string colName = _muonCollections[i] ;
177 
178  //fg: need to establish the yoke subdetetcor part here
179  // use collection name as cellID does not seem to have that information
180  CHT::Layout caloLayout = layoutFromString( colName ) ;
181 
182  try{
183  LCCollection * col = evt->getCollection( _muonCollections[i].c_str() ) ;
184  initString = col->getParameters().getStringVal(LCIO::CellIDEncoding);
185  int numElements = col->getNumberOfElements();
186  CellIDDecoder<SimCalorimeterHit> idDecoder( col );
187  for (int j(0); j < numElements; ++j) {
188  SimCalorimeterHit * hit = dynamic_cast<SimCalorimeterHit*>( col->getElementAt( j ) ) ;
189  float energy = hit->getEnergy();
190  int cellid = hit->getCellID0();
191  int cellid1 = hit->getCellID1();
192  //Get The LayerNumber
193  unsigned int layer = abs( idDecoder(hit)[ _cellIDLayerString ] ) ;
194  //Check if we want to use this layer, else go to the next hit
195  if( !useLayer(caloLayout, layer) ) continue;
196  float calibr_coeff(1.);
197  calibr_coeff = _calibrCoeffMuon;
198  float hitEnergy = calibr_coeff*energy;
199  if(hitEnergy>_maxHitEnergyMuon)hitEnergy=_maxHitEnergyMuon;
200  if (hitEnergy > _thresholdMuon) {
201  CalorimeterHitImpl * calhit = new CalorimeterHitImpl();
202  calhit->setCellID0(cellid);
203  calhit->setCellID1(cellid1);
204  calhit->setEnergy(hitEnergy);
205  calhit->setPosition(hit->getPosition());
206  calhit->setType( CHT( CHT::muon, CHT::yoke, caloLayout , idDecoder(hit)[ _cellIDLayerString ] ) );
207  calhit->setRawHit(hit);
208  muoncol->addElement(calhit);
209  LCRelationImpl *rel = new LCRelationImpl(calhit,hit,1.);
210  relcol->addElement( rel );
211  }
212 
213  }
214  }
215  catch(DataNotAvailableException &e){
216  }
217  }
218  muoncol->parameters().setValue(LCIO::CellIDEncoding,initString);
219  evt->addCollection(muoncol,_outputMuonCollection.c_str());
220  evt->addCollection(relcol,_outputRelCollection.c_str());
221 
222 
223  _nEvt++;
224 
225 }
226 
227 
228 void SimpleMuonDigi::check( LCEvent * /*evt*/ ) { }
229 
231 
232 bool SimpleMuonDigi::useLayer(CHT::Layout caloLayout, unsigned int layer) {
233  switch (caloLayout){
234  case CHT::barrel:
235  if(layer > _useLayersBarrelVec.size() || _useLayersBarrelVec.size() == 0) return true;
236  return _useLayersBarrelVec[layer]; //break not needed, because of return
237  case CHT::endcap:
238  if(layer > _useLayersEndcapVec.size() || _useLayersEndcapVec.size() == 0) return true;
239  return _useLayersEndcapVec[layer]; //break not needed, because of return
240  //For all other cases, always keep the hit
241  default:
242  return true;
243  }
244 }//useLayer
bool useLayer(CHT::Layout caloLayout, unsigned int layer)
float _calibrCoeffMuon
virtual void init()
virtual void processRunHeader(LCRunHeader *run)
std::string _outputMuonCollection
virtual void check(LCEvent *evt)
float _maxHitEnergyMuon
std::vector< bool > _useLayersEndcapVec
virtual void processEvent(LCEvent *evt)
IntVec _layersToKeepEndcapVec
IntVec _layersToKeepBarrelVec
SimpleMuonDigi aSimpleMuonDigi
virtual void end()
std::string _outputRelCollection
static const float e
std::string _cellIDLayerString
std::vector< LCCollection * > LCCollectionVec
Definition: SiStripClus.h:55
std::vector< std::string > _muonCollections
std::vector< bool > _useLayersBarrelVec