CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EBCosmicTask.cc
Go to the documentation of this file.
1 /*
2  * \file EBCosmicTask.cc
3  *
4  * $Date: 2012/04/27 13:46:01 $
5  * $Revision: 1.121 $
6  * \author G. Della Ricca
7  *
8 */
9 
10 #include <iostream>
11 #include <fstream>
12 
15 
17 
19 
24 
26 
28 
30 
31  init_ = false;
32 
34 
35  prefixME_ = ps.getUntrackedParameter<std::string>("prefixME", "");
36 
37  enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
38 
39  mergeRuns_ = ps.getUntrackedParameter<bool>("mergeRuns", false);
40 
41  EcalRawDataCollection_ = ps.getParameter<edm::InputTag>("EcalRawDataCollection");
42  EcalUncalibratedRecHitCollection_ = ps.getParameter<edm::InputTag>("EcalUncalibratedRecHitCollection");
43  EcalRecHitCollection_ = ps.getParameter<edm::InputTag>("EcalRecHitCollection");
44 
45  threshold_ = 0.12500; // typical muon energy deposit is 250 MeV
46 
47  minJitter_ = -2.0;
48  maxJitter_ = 1.5;
49 
50  for (int i = 0; i < 36; i++) {
51  meSelMap_[i] = 0;
52  meSpectrum_[0][i] = 0;
53  meSpectrum_[1][i] = 0;
54  }
55 
56 }
57 
59 
60 }
61 
63 
64  ievt_ = 0;
65 
66  if ( dqmStore_ ) {
67  dqmStore_->setCurrentFolder(prefixME_ + "/EBCosmicTask");
68  dqmStore_->rmdir(prefixME_ + "/EBCosmicTask");
69  }
70 
71 }
72 
74 
75  Numbers::initGeometry(c, false);
76 
77  if ( ! mergeRuns_ ) this->reset();
78 
79 }
80 
82 
83 }
84 
85 void EBCosmicTask::reset(void) {
86 
87  for (int i = 0; i < 36; i++) {
88  if ( meSelMap_[i] ) meSelMap_[i]->Reset();
89  if ( meSpectrum_[0][i] ) meSpectrum_[0][i]->Reset();
90  if ( meSpectrum_[1][i] ) meSpectrum_[1][i]->Reset();
91  }
92 
93 }
94 
96 
97  init_ = true;
98 
99  std::string name;
100 
101  if ( dqmStore_ ) {
102  dqmStore_->setCurrentFolder(prefixME_ + "/EBCosmicTask");
103 
104  dqmStore_->setCurrentFolder(prefixME_ + "/EBCosmicTask/Sel");
105  for (int i = 0; i < 36; i++) {
106  name = "EBCT energy sel " + Numbers::sEB(i+1);
107  meSelMap_[i] = dqmStore_->bookProfile2D(name, name, 85, 0., 85., 20, 0., 20., 4096, 0., 4096., "s");
108  meSelMap_[i]->setAxisTitle("ieta", 1);
109  meSelMap_[i]->setAxisTitle("iphi", 2);
110  meSelMap_[i]->setAxisTitle("energy (GeV)", 3);
111  }
112 
113  dqmStore_->setCurrentFolder(prefixME_ + "/EBCosmicTask/Spectrum");
114  for (int i = 0; i < 36; i++) {
115  name = "EBCT 1x1 energy spectrum " + Numbers::sEB(i+1);
116  meSpectrum_[0][i] = dqmStore_->book1D(name, name, 100, 0., 1.5);
117  meSpectrum_[0][i]->setAxisTitle("energy (GeV)", 1);
118  name = "EBCT 3x3 energy spectrum " + Numbers::sEB(i+1);
119  meSpectrum_[1][i] = dqmStore_->book1D(name, name, 100, 0., 1.5);
120  meSpectrum_[1][i]->setAxisTitle("energy (GeV)", 1);
121  }
122 
123  }
124 
125 }
126 
128 
129  if ( ! init_ ) return;
130 
131  if ( dqmStore_ ) {
132  dqmStore_->setCurrentFolder(prefixME_ + "/EBCosmicTask");
133 
134  dqmStore_->setCurrentFolder(prefixME_ + "/EBCosmicTask/Cut");
135  for (int i = 0; i < 36; i++) {
137  meCutMap_[i] = 0;
138  }
139 
140  dqmStore_->setCurrentFolder(prefixME_ + "/EBCosmicTask/Sel");
141  for (int i = 0; i < 36; i++) {
143  meSelMap_[i] = 0;
144  }
145 
146  dqmStore_->setCurrentFolder(prefixME_ + "/EBCosmicTask/Spectrum");
147  for (int i = 0; i < 36; i++) {
148  if ( meSpectrum_[0][i] ) dqmStore_->removeElement( meSpectrum_[0][i]->getName() );
149  meSpectrum_[0][i] = 0;
150  if ( meSpectrum_[1][i] ) dqmStore_->removeElement( meSpectrum_[1][i]->getName() );
151  meSpectrum_[1][i] = 0;
152  }
153 
154  }
155 
156  init_ = false;
157 
158 }
159 
161 
162  edm::LogInfo("EBCosmicTask") << "analyzed " << ievt_ << " events";
163 
164  if ( enableCleanup_ ) this->cleanup();
165 
166 }
167 
169 
170  bool isData = true;
171  bool enable = false;
172  int runType[36];
173  for (int i=0; i<36; i++) runType[i] = -1;
174 
176 
177  if ( e.getByLabel(EcalRawDataCollection_, dcchs) ) {
178 
179  for ( EcalRawDataCollection::const_iterator dcchItr = dcchs->begin(); dcchItr != dcchs->end(); ++dcchItr ) {
180 
181  if ( Numbers::subDet( *dcchItr ) != EcalBarrel ) continue;
182 
183  int ism = Numbers::iSM( *dcchItr, EcalBarrel );
184 
185  runType[ism-1] = dcchItr->getRunType();
186 
187  if ( dcchItr->getRunType() == EcalDCCHeaderBlock::COSMIC ||
188  dcchItr->getRunType() == EcalDCCHeaderBlock::MTCC ||
189  dcchItr->getRunType() == EcalDCCHeaderBlock::COSMICS_GLOBAL ||
190  dcchItr->getRunType() == EcalDCCHeaderBlock::PHYSICS_GLOBAL ||
191  dcchItr->getRunType() == EcalDCCHeaderBlock::COSMICS_LOCAL ||
192  dcchItr->getRunType() == EcalDCCHeaderBlock::PHYSICS_LOCAL ) enable = true;
193 
194  }
195 
196  } else {
197 
198  isData = false; enable = true;
199  edm::LogWarning("EBCosmicTask") << EcalRawDataCollection_ << " not available";
200 
201  }
202 
203  if ( ! enable ) return;
204 
205  if ( ! init_ ) this->setup();
206 
207  ievt_++;
208 
210 
211  if ( e.getByLabel(EcalRecHitCollection_, hits) ) {
212 
213  int nebh = hits->size();
214  LogDebug("EBCosmicTask") << "event " << ievt_ << " hits collection size " << nebh;
215 
217 
218  if ( ! e.getByLabel(EcalUncalibratedRecHitCollection_, uhits) ) {
219  edm::LogWarning("EBCosmicTask") << EcalUncalibratedRecHitCollection_ << " not available";
220  }
221 
222  for ( EcalRecHitCollection::const_iterator hitItr = hits->begin(); hitItr != hits->end(); ++hitItr ) {
223 
224  EBDetId id = hitItr->id();
225 
226  int ic = id.ic();
227  int ie = (ic-1)/20 + 1;
228  int ip = (ic-1)%20 + 1;
229 
230  int ism = Numbers::iSM( id );
231 
232  float xie = ie - 0.5;
233  float xip = ip - 0.5;
234 
235  if ( isData ) {
236 
237  if ( ! ( runType[ism-1] == EcalDCCHeaderBlock::COSMIC ||
238  runType[ism-1] == EcalDCCHeaderBlock::MTCC ||
239  runType[ism-1] == EcalDCCHeaderBlock::COSMICS_GLOBAL ||
240  runType[ism-1] == EcalDCCHeaderBlock::PHYSICS_GLOBAL ||
241  runType[ism-1] == EcalDCCHeaderBlock::COSMICS_LOCAL ||
242  runType[ism-1] == EcalDCCHeaderBlock::PHYSICS_LOCAL ) ) continue;
243 
244  }
245 
246  float xval = hitItr->energy();
247  if ( xval <= 0. ) xval = 0.0;
248 
249  // look for the seeds
250  float e3x3 = 0.;
251  bool isSeed = true;
252 
253  // evaluate 3x3 matrix around a seed
254  for(int icry=0; icry<9; ++icry) {
255  unsigned int row = icry/3;
256  unsigned int column = icry%3;
257  int icryEta = id.ieta()+column-1;
258  int icryPhi = id.iphi()+row-1;
259  if ( EBDetId::validDetId(icryEta, icryPhi) ) {
260  EBDetId id3x3 = EBDetId(icryEta, icryPhi, EBDetId::ETAPHIMODE);
261  if ( hits->find(id3x3) != hits->end() ) {
262  float neighbourEnergy = hits->find(id3x3)->energy();
263  e3x3 += neighbourEnergy;
264  if ( neighbourEnergy > xval ) isSeed = false;
265  }
266  }
267  }
268 
269  // find the jitter of the seed
270  float jitter = -999.;
271  if ( isSeed ) {
272  if ( uhits.isValid() ) {
273  if ( uhits->find(id) != uhits->end() ) {
274  jitter = uhits->find(id)->jitter();
275  }
276  }
277  }
278 
279  if ( isSeed && e3x3 >= threshold_ && jitter > minJitter_ && jitter < maxJitter_ ) {
280  if ( meSelMap_[ism-1] ) meSelMap_[ism-1]->Fill(xie, xip, e3x3);
281  }
282 
283  if ( meSpectrum_[0][ism-1] ) meSpectrum_[0][ism-1]->Fill(xval);
284 
285  if ( isSeed && xval >= threshold_ && jitter > minJitter_ && jitter < maxJitter_ ) {
286  if ( meSpectrum_[1][ism-1] ) meSpectrum_[1][ism-1]->Fill(e3x3);
287  }
288 
289  }
290 
291  } else {
292 
293  edm::LogWarning("EBCosmicTask") << EcalRecHitCollection_ << " not available";
294 
295  }
296 
297 }
298 
#define LogDebug(id)
static bool validDetId(int i, int j)
check if a valid index combination
Definition: EBDetId.cc:59
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:717
void rmdir(const std::string &fullpath)
Definition: DQMStore.cc:2530
Some &quot;id&quot; conversions.
std::string prefixME_
Definition: EBCosmicTask.h:62
static std::string sEB(const unsigned ism)
Definition: Numbers.cc:94
std::vector< T >::const_iterator const_iterator
void setup(void)
Setup.
Definition: EBCosmicTask.cc:95
double threshold_
Definition: EBCosmicTask.h:78
double minJitter_
Definition: EBCosmicTask.h:79
DQMStore * dqmStore_
Definition: EBCosmicTask.h:60
void cleanup(void)
Cleanup.
void Fill(long long x)
edm::InputTag EcalRecHitCollection_
Definition: EBCosmicTask.h:70
void endRun(const edm::Run &r, const edm::EventSetup &c)
EndRun.
Definition: EBCosmicTask.cc:81
void beginJob(void)
BeginJob.
Definition: EBCosmicTask.cc:62
edm::InputTag EcalUncalibratedRecHitCollection_
Definition: EBCosmicTask.h:69
void removeElement(const std::string &name)
Definition: DQMStore.cc:2572
EBCosmicTask(const edm::ParameterSet &ps)
Constructor.
Definition: EBCosmicTask.cc:29
void reset(void)
Reset.
Definition: EBCosmicTask.cc:85
MonitorElement * meSelMap_[36]
Definition: EBCosmicTask.h:74
std::string getName(Reflex::Type &cc)
Definition: ClassFiller.cc:18
void analyze(const edm::Event &e, const edm::EventSetup &c)
Analyze.
MonitorElement * meCutMap_[36]
Definition: EBCosmicTask.h:72
bool isValid() const
Definition: HandleBase.h:76
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
static const int ETAPHIMODE
Definition: EBDetId.h:145
int ic() const
get ECAL/crystal number inside SM
Definition: EBDetId.cc:94
void endJob(void)
EndJob.
static void initGeometry(const edm::EventSetup &setup, bool verbose=false)
Definition: Numbers.cc:50
MonitorElement * meSpectrum_[2][36]
Definition: EBCosmicTask.h:76
void beginRun(const edm::Run &r, const edm::EventSetup &c)
BeginRun.
Definition: EBCosmicTask.cc:73
bool enableCleanup_
Definition: EBCosmicTask.h:64
edm::InputTag EcalRawDataCollection_
Definition: EBCosmicTask.h:68
static unsigned iSM(const unsigned ism, const EcalSubdetector subdet)
Definition: Numbers.cc:246
static EcalSubdetector subDet(const EBDetId &id)
Definition: Numbers.cc:145
double maxJitter_
Definition: EBCosmicTask.h:80
virtual ~EBCosmicTask()
Destructor.
Definition: EBCosmicTask.cc:58
int ism(int ieta, int iphi)
Definition: EcalPyUtils.cc:56
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
void Reset(void)
reset ME (ie. contents, errors, etc)
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:429
Definition: Run.h:33
MonitorElement * bookProfile2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, int nchZ, double lowZ, double highZ, const char *option="s")
Definition: DQMStore.cc:1175