CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
BSCTrigger.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: BSCTrigger
4 // Class: BSCTrigger
5 //
13 //
14 // Original Author: Muriel VANDER DONCKT *:0
15 // Created: Wed Jul 16 16:11:05 CEST 2008
16 // $Id: BSCTrigger.cc,v 1.10 2010/10/07 22:02:55 yjlee Exp $
17 //
18 //
19 
20 
21 // system include files
22 #include <memory>
23 
24 // user include files
27 
30 
36 
39 
40 
41 //
42 // class declaration
43 //
44 
45 class BSCTrigger : public edm::EDProducer {
46 public:
47  explicit BSCTrigger(const edm::ParameterSet&);
48  ~BSCTrigger();
49 
50 private:
51  virtual void beginJob() ;
52  virtual void produce(edm::Event&, const edm::EventSetup&);
53  virtual void endJob() ;
54  int getBSCNum(int id, float z);
55  bool isInner(int id);
56  bool isZplus(int id);
57  // ----------member data ---------------------------
58  std::vector<unsigned> ttBits_;
59  std::vector<std::string> names_;
60  unsigned nEvt_;
64  int theNouter_;
65  int nevt_;
67 };
68 
69 //
70 // constants, enums and typedefs
71 //
72 
73 
74 //
75 // static data member definitions
76 //
77 
78 //
79 // constructors and destructor
80 //
82 {
83  ttBits_=iConfig.getParameter< std::vector<unsigned> >("bitNumbers");
84  names_= iConfig.getParameter< std::vector<std::string> >("bitNames");
85  theCoincidence_= iConfig.getParameter<double>("coincidence");
86  theResolution_= iConfig.getParameter<double>("resolution");
87  TheHits_tag_= iConfig.getParameter<edm::InputTag>("theHits");
88  produces<L1GtTechnicalTriggerRecord>();
89  nevt_=0;
90 }
91 
92 
94 {
95 
96  // do anything here that needs to be done at desctruction time
97  // (e.g. close files, deallocate resources etc.)
98 
99 }
100 
101 
102 //
103 // member functions
104 //
105 
106 // ------------ method called to produce the data ------------
108 {
109  std::vector<L1GtTechnicalTrigger> ttVec(ttBits_.size());
110  std::vector<float>EnergyBX(32);
111  std::vector<float>EnergyBXMinusDt(32);
112  int ZMinnerBX=0, ZMouterBX=0;
113  int ZPinnerBX=0, ZPouterBX=0;
114  int ZMinnerBXMinusDt=0, ZMouterBXMinusDt=0;
115  int ZPinnerBXMinusDt=0, ZPouterBXMinusDt=0;
116  ++nevt_;
117  std::auto_ptr<L1GtTechnicalTriggerRecord> BscRecord;
118  float MipFraction=0.5;
119  float MipEnergy=0.0027;
120  float theThreshold=MipFraction*MipEnergy;
121 
123  iEvent.getByLabel(TheHits_tag_, cf);
124 
125  if (!cf.failedToGet()) {
126  for ( int c=0;c<32;++c){
127  EnergyBX[c]=0;
128  EnergyBXMinusDt[c]=0;
129  }
130  std::auto_ptr<MixCollection<PSimHit> > theBSCHitContainer( new MixCollection <PSimHit>(cf.product()));
132  float dt1,dt2;
135  if ( edm::isDebugEnabled() ) LogDebug("BSCTrig")<<" ----------------new event ---with "<<theBSCHitContainer->size()<<" hits in the BSC";
136 
137  // collect total deposited energy in BSC segments -> EnergyBX[segment id], in GeV units ---------------------------------------------------------------
138  for (itHit = theBSCHitContainer->begin(); itHit != theBSCHitContainer->end(); ++itHit) {
139  float zh=itHit->entryPoint().z()/10;
140  int id=getBSCNum(itHit->detUnitId(),zh);
141  if ( id > 31 ) continue; // the small 2 paddles further from the IP
142  float t=itHit->timeOfFlight();
143 
144  if ( edm::isDebugEnabled() ) {
145  float rh=sqrt(itHit->entryPoint().x()*itHit->entryPoint().x()+itHit->entryPoint().y()*itHit->entryPoint().y())/10;
146  LogTrace("BSCTrig")<<" BSC Num "<<id<<" z="<<zh<<" isZplus="<<isZplus(id)<<" Hit DetId="<<getBSCNum(id,zh)<<" r="<<rh<<" isInner="<<isInner(id);
147  LogTrace("BSCTrig")<<" Hit time="<<t<<" accepted range=["<<dt2<<","<<dt1<<"] from a "<<abs(itHit->particleType())<<" with energy " <<itHit->energyLoss();
148  }
149  if (fabs(t)> dt1 || fabs(t) <dt2 ) continue;
150  if (t>0) EnergyBX[id]+=itHit->energyLoss();
151  else EnergyBXMinusDt[id]+=itHit->energyLoss();
152  }
153 
154  // count number of segments hit in inner/outer and +z, -z ---------------------------------------------------------------------------------------------
155  for ( unsigned int ipad = 0 ; ipad<32; ipad++) {
156  if ( edm::isDebugEnabled() ) LogTrace("BSCTrig")<<" EnergyBX["<<ipad<<"]="<<EnergyBX[ipad];
157  // hits after the bunch crossing
158  if ( EnergyBX[ipad] > theThreshold ) {
159  if ( isZplus(ipad)) {
160  if ( isInner(ipad) ) ZPinnerBX++;
161  else ZPouterBX++;
162  } else {
163  if ( isInner(ipad) ) ZMinnerBX++;
164  else ZMouterBX++;
165  }
166  }
167  // hits before the bunch crossing
168  if ( EnergyBXMinusDt[ipad] > theThreshold ) {
169  if ( isZplus(ipad)) {
170  if ( isInner(ipad) ) ZPinnerBXMinusDt++;
171  else ZPouterBXMinusDt++;
172  } else {
173  if ( isInner(ipad) ) ZMinnerBXMinusDt++;
174  else ZMouterBXMinusDt++;
175  }
176  }
177  }
178 
179  if ( edm::isDebugEnabled() ) LogTrace("BSCTrig")<<" Zplus I="<<ZPinnerBX<<" Zminus I="<<ZMinnerBX<<" Zplus O="<<ZPouterBX<<" Zminus O="<<ZMouterBX;
180 
181  // minimum bias technical triggers that are also connected to 'external condition' triggers -----------------
182  bool bit32=false; // min bias inner >=1
183  if(ZPinnerBX >= 1 && ZMinnerBX >= 1) bit32 = true;
184 
185  bool bit33=false; // min bias inner >=2
186  if(ZPinnerBX >= 2 && ZMinnerBX >= 2) bit33 = true;
187 
188  bool bit34=false; // min bias OR
189  if(ZPinnerBX + ZMinnerBX + ZPouterBX + ZMouterBX >= 1) bit34 = true;
190 
191  bool bit35=false; // high multiplicity
192  if(ZPinnerBX == 8 && ZMinnerBX == 8) bit35 = true;
193 
194  // beam halo technical triggers ----------------------------------------------------------------
195  bool bit36=false; // beam 2 halo inner
196  if(ZPinnerBX >= 1 && ZMinnerBXMinusDt >= 1) bit36 = true;
197 
198  bool bit37=false; // beam 2 halo outer
199  if(ZPouterBX >= 1 && ZMouterBXMinusDt >= 1) bit37 = true;
200 
201  bool bit38=false; // beam 1 halo inner
202  if(ZMinnerBX >= 1 && ZPinnerBXMinusDt >= 1) bit38 = true;
203 
204  bool bit39=false; // beam 1 halo outer
205  if(ZMouterBX >= 1 && ZPouterBXMinusDt >= 1) bit39 = true;
206 
207  // minimum bias technical triggers ---------------------------------------------------------
208  bool bit40=false; // min bias all >=1
209  if(ZPinnerBX + ZPouterBX >= 1 && ZMinnerBX + ZMouterBX >= 1) bit40 = true;
210 
211  bool bit41=false; // min bias all >=2
212  if(ZPinnerBX + ZPouterBX >= 2 && ZMinnerBX + ZMouterBX >= 2) bit41 = true;
213 
214  bool bit42=false; // beam 1 splash (-z)
215  if(ZMinnerBX >= 2) bit42 = true;
216 
217  bool bit43=false; // beam 2 splash (+z)
218  if(ZPinnerBX >= 2) bit43 = true;
219 
220  for ( unsigned i=0; i< ttBits_.size();++i ){
221  bool bit = false;
222  if ( names_.at(i) == names_[0] ) bit = bit32;
223  if ( names_.at(i) == names_[1] ) bit = bit33;
224  if ( names_.at(i) == names_[2] ) bit = bit34;
225  if ( names_.at(i) == names_[3] ) bit = bit35;
226  if ( names_.at(i) == names_[4] ) bit = bit36;
227  if ( names_.at(i) == names_[5] ) bit = bit37;
228  if ( names_.at(i) == names_[6] ) bit = bit38;
229  if ( names_.at(i) == names_[7] ) bit = bit39;
230  if ( names_.at(i) == names_[8] ) bit = bit40;
231  if ( names_.at(i) == names_[9] ) bit = bit41;
232  if ( names_.at(i) == names_[10]) bit = bit42;
233  if ( names_.at(i) == names_[11]) bit = bit43;
234  ttVec.at(i)=L1GtTechnicalTrigger(names_.at(i), ttBits_.at(i), 0, bit) ;
235  if ( edm::isDebugEnabled() ) LogTrace("AnaBsc") << "bit: "<<ttBits_[i] << " VALUE:"<<bit ;
236  }
237  } else ttVec.clear();
238  std::auto_ptr<L1GtTechnicalTriggerRecord> output(new L1GtTechnicalTriggerRecord());
239  output->setGtTechnicalTrigger(ttVec);
240  iEvent.put(output);
241 }
242 // ------------ method called once each job just before starting event loop ------------
244 {
245 }
246 
247 // ------------ method called once each job just after ending the event loop ------------
249 }
250 
251 int BSCTrigger::getBSCNum( int id, float z ) {
252  int zside = 0;
253  if ( z > 0 ) zside = 1;
254  if ( edm::isDebugEnabled() ) {
255  int det = (id&24)>>3;
256  int station = id&7;
257  LogTrace("BSCTrig")<<"id="<<id<<" zside="<<zside<<" det="<<det<<" station="<<station;
258  }
259  int BSCNum;
260  if (id&16) BSCNum=32+(id&1)+(zside<<1) ; // small paddles further from IP
261  else BSCNum= (id&15)+(zside<<4); // the BSC on the HF
262  return BSCNum;
263 }
264 
265 bool BSCTrigger::isInner( int id ){
266  return ( (id&8)>>3 ) ;
267 }
268 
269 bool BSCTrigger::isZplus( int id ){
270  return ( (id&16)>>4 ) ;
271 }
272 
273 //define this as a plug-in
#define LogDebug(id)
BSCTrigger(const edm::ParameterSet &)
Definition: BSCTrigger.cc:81
T getParameter(std::string const &) const
bool isDebugEnabled()
int i
Definition: DBlmapReader.cc:9
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual void produce(edm::Event &, const edm::EventSetup &)
Definition: BSCTrigger.cc:107
#define abs(x)
Definition: mlp_lapack.h:159
bool isZplus(int id)
Definition: BSCTrigger.cc:269
virtual void endJob()
Definition: BSCTrigger.cc:248
float float float z
float theResolution_
Definition: BSCTrigger.cc:62
unsigned nEvt_
Definition: BSCTrigger.cc:60
iterator end()
std::vector< unsigned > ttBits_
Definition: BSCTrigger.cc:58
int iEvent
Definition: GenABIO.cc:243
std::vector< std::string > names_
Definition: BSCTrigger.cc:59
bool isInner(int id)
Definition: BSCTrigger.cc:265
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:94
T sqrt(T t)
Definition: SSEVec.h:48
edm::InputTag TheHits_tag_
Definition: BSCTrigger.cc:66
virtual void beginJob()
Definition: BSCTrigger.cc:243
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
#define LogTrace(id)
int theNouter_
Definition: BSCTrigger.cc:64
bool failedToGet() const
Definition: HandleBase.h:80
iterator begin()
T const * product() const
Definition: Handle.h:74
int getBSCNum(int id, float z)
Definition: BSCTrigger.cc:251
float theCoincidence_
Definition: BSCTrigger.cc:61
int theNinner_
Definition: BSCTrigger.cc:63