CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EECosmicTask.cc
Go to the documentation of this file.
1 /*
2  * \file EECosmicTask.cc
3  *
4  * $Date: 2012/04/27 13:46:14 $
5  * $Revision: 1.60 $
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 < 18; 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_ + "/EECosmicTask");
68  dqmStore_->rmdir(prefixME_ + "/EECosmicTask");
69  }
70 
71 }
72 
74 
75  Numbers::initGeometry(c, false);
76 
77  if ( ! mergeRuns_ ) this->reset();
78 
79 }
80 
82 
83 }
84 
85 void EECosmicTask::reset(void) {
86 
87  for (int i = 0; i < 18; 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_ + "/EECosmicTask");
103 
104  dqmStore_->setCurrentFolder(prefixME_ + "/EECosmicTask/Sel");
105  for (int i = 0; i < 18; i++) {
106  name = "EECT energy sel " + Numbers::sEE(i+1);
107  meSelMap_[i] = dqmStore_->bookProfile2D(name, name, 50, Numbers::ix0EE(i+1)+0., Numbers::ix0EE(i+1)+50., 50, Numbers::iy0EE(i+1)+0., Numbers::iy0EE(i+1)+50., 4096, 0., 4096., "s");
108  meSelMap_[i]->setAxisTitle("ix", 1);
109  if ( i+1 >= 1 && i+1 <= 9 ) meSelMap_[i]->setAxisTitle("101-ix", 1);
110  meSelMap_[i]->setAxisTitle("iy", 2);
111  meSelMap_[i]->setAxisTitle("energy (GeV)", 3);
112  }
113 
114  dqmStore_->setCurrentFolder(prefixME_ + "/EECosmicTask/Spectrum");
115  for (int i = 0; i < 18; i++) {
116  name = "EECT 1x1 energy spectrum " + Numbers::sEE(i+1);
117  meSpectrum_[0][i] = dqmStore_->book1D(name, name, 100, 0., 1.5);
118  meSpectrum_[0][i]->setAxisTitle("energy (GeV)", 1);
119 
120  name = "EECT 3x3 energy spectrum " + Numbers::sEE(i+1);
121  meSpectrum_[1][i] = dqmStore_->book1D(name, name, 100, 0., 1.5);
122  meSpectrum_[1][i]->setAxisTitle("energy (GeV)", 1);
123  }
124 
125  }
126 
127 }
128 
130 
131  if ( ! init_ ) return;
132 
133  if ( dqmStore_ ) {
134  dqmStore_->setCurrentFolder(prefixME_ + "/EECosmicTask");
135 
136  dqmStore_->setCurrentFolder(prefixME_ + "/EECosmicTask/Sel");
137  for (int i = 0; i < 18; i++) {
139  meSelMap_[i] = 0;
140  }
141 
142  dqmStore_->setCurrentFolder(prefixME_ + "/EECosmicTask/Spectrum");
143  for (int i = 0; i < 18; i++) {
144  if ( meSpectrum_[0][i] ) dqmStore_->removeElement( meSpectrum_[0][i]->getName() );
145  meSpectrum_[0][i] = 0;
146  if ( meSpectrum_[1][i] ) dqmStore_->removeElement( meSpectrum_[1][i]->getName() );
147  meSpectrum_[1][i] = 0;
148  }
149 
150  }
151 
152  init_ = false;
153 
154 }
155 
157 
158  edm::LogInfo("EECosmicTask") << "analyzed " << ievt_ << " events";
159 
160  if ( enableCleanup_ ) this->cleanup();
161 
162 }
163 
165 
166  bool isData = true;
167  bool enable = false;
168  int runType[18];
169  for (int i=0; i<18; i++) runType[i] = -1;
170 
172 
173  if ( e.getByLabel(EcalRawDataCollection_, dcchs) ) {
174 
175  for ( EcalRawDataCollection::const_iterator dcchItr = dcchs->begin(); dcchItr != dcchs->end(); ++dcchItr ) {
176 
177  if ( Numbers::subDet( *dcchItr ) != EcalEndcap ) continue;
178 
179  int ism = Numbers::iSM( *dcchItr, EcalEndcap );
180 
181  runType[ism-1] = dcchItr->getRunType();
182 
183  if ( dcchItr->getRunType() == EcalDCCHeaderBlock::COSMIC ||
184  dcchItr->getRunType() == EcalDCCHeaderBlock::MTCC ||
185  dcchItr->getRunType() == EcalDCCHeaderBlock::COSMICS_GLOBAL ||
186  dcchItr->getRunType() == EcalDCCHeaderBlock::PHYSICS_GLOBAL ||
187  dcchItr->getRunType() == EcalDCCHeaderBlock::COSMICS_LOCAL ||
188  dcchItr->getRunType() == EcalDCCHeaderBlock::PHYSICS_LOCAL ) enable = true;
189 
190  }
191 
192  } else {
193 
194  isData = false; enable = true;
195  edm::LogWarning("EECosmicTask") << EcalRawDataCollection_ << " not available";
196 
197  }
198 
199  if ( ! enable ) return;
200 
201  if ( ! init_ ) this->setup();
202 
203  ievt_++;
204 
206 
207  if ( e.getByLabel(EcalRecHitCollection_, hits) ) {
208 
209  int neeh = hits->size();
210  LogDebug("EECosmicTask") << "event " << ievt_ << " hits collection size " << neeh;
211 
213 
214  if ( ! e.getByLabel(EcalUncalibratedRecHitCollection_, uhits) ) {
215  edm::LogWarning("EECosmicTask") << EcalUncalibratedRecHitCollection_ << " not available";
216  }
217 
218  for ( EcalRecHitCollection::const_iterator hitItr = hits->begin(); hitItr != hits->end(); ++hitItr ) {
219 
220  EEDetId id = hitItr->id();
221 
222  int ix = id.ix();
223  int iy = id.iy();
224 
225  int ism = Numbers::iSM( id );
226 
227  if ( ism >= 1 && ism <= 9 ) ix = 101 - ix;
228 
229  float xix = ix - 0.5;
230  float xiy = iy - 0.5;
231 
232  int iz = 0;
233 
234  if ( ism >= 1 && ism <= 9 ) iz = -1;
235  if ( ism >= 10 && ism <= 18 ) iz = +1;
236 
237  if ( isData ) {
238 
239  if ( ! ( runType[ism-1] == EcalDCCHeaderBlock::COSMIC ||
240  runType[ism-1] == EcalDCCHeaderBlock::MTCC ||
241  runType[ism-1] == EcalDCCHeaderBlock::COSMICS_GLOBAL ||
242  runType[ism-1] == EcalDCCHeaderBlock::PHYSICS_GLOBAL ||
243  runType[ism-1] == EcalDCCHeaderBlock::COSMICS_LOCAL ||
244  runType[ism-1] == EcalDCCHeaderBlock::PHYSICS_LOCAL ) ) continue;
245 
246  }
247 
248  float xval = hitItr->energy();
249  if ( xval <= 0. ) xval = 0.0;
250 
251  // look for the seeds
252  float e3x3 = 0.;
253  bool isSeed = true;
254 
255  // evaluate 3x3 matrix around a seed
256  for(int icry=0; icry<9; ++icry) {
257  unsigned int row = icry/3;
258  unsigned int column = icry%3;
259  int icryX = id.ix()+column-1;
260  int icryY = id.iy()+row-1;
261  if ( EEDetId::validDetId(icryX, icryY, iz) ) {
262  EEDetId id3x3 = EEDetId(icryX, icryY, iz, EEDetId::XYMODE);
263  if ( hits->find(id3x3) != hits->end() ) {
264  float neighbourEnergy = hits->find(id3x3)->energy();
265  e3x3 += neighbourEnergy;
266  if ( neighbourEnergy > xval ) isSeed = false;
267  }
268  }
269  }
270 
271  // find the jitter of the seed
272  float jitter = -999.;
273  if ( isSeed ) {
274  if ( uhits.isValid() ) {
275  if ( uhits->find(id) != uhits->end() ) {
276  jitter = uhits->find(id)->jitter();
277  }
278  }
279  }
280 
281  if ( isSeed && e3x3 >= threshold_ && jitter > minJitter_ && jitter < maxJitter_ ) {
282  if ( meSelMap_[ism-1] ) meSelMap_[ism-1]->Fill(xix, xiy, e3x3);
283  }
284 
285  if ( meSpectrum_[0][ism-1] ) meSpectrum_[0][ism-1]->Fill(xval);
286 
287  if ( isSeed && xval >= threshold_ && jitter > minJitter_ && jitter < maxJitter_ ) {
288  if ( meSpectrum_[1][ism-1] ) meSpectrum_[1][ism-1]->Fill(e3x3);
289  }
290 
291  }
292 
293  } else {
294 
295  edm::LogWarning("EECosmicTask") << EcalRecHitCollection_ << " not available";
296 
297  }
298 
299 }
300 
#define LogDebug(id)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
static std::string sEE(const unsigned ism)
Definition: Numbers.cc:226
int i
Definition: DBlmapReader.cc:9
int ix() const
Definition: EEDetId.h:71
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
edm::InputTag EcalRawDataCollection_
Definition: EECosmicTask.h:68
void reset(void)
Reset.
Definition: EECosmicTask.cc:85
Some &quot;id&quot; conversions.
static const int XYMODE
Definition: EEDetId.h:316
std::vector< T >::const_iterator const_iterator
bool enableCleanup_
Definition: EECosmicTask.h:64
void beginJob(void)
BeginJob.
Definition: EECosmicTask.cc:62
static int ix0EE(const unsigned ism)
Definition: Numbers.cc:773
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.cc:562
static int iy0EE(const unsigned ism)
Definition: Numbers.cc:812
void Fill(long long x)
edm::InputTag EcalUncalibratedRecHitCollection_
Definition: EECosmicTask.h:69
void endRun(const edm::Run &r, const edm::EventSetup &c)
EndRun.
Definition: EECosmicTask.cc:81
std::string prefixME_
Definition: EECosmicTask.h:62
virtual ~EECosmicTask()
Destructor.
Definition: EECosmicTask.cc:58
MonitorElement * meSelMap_[18]
Definition: EECosmicTask.h:72
void removeElement(const std::string &name)
Definition: DQMStore.cc:2572
std::string getName(Reflex::Type &cc)
Definition: ClassFiller.cc:18
edm::InputTag EcalRecHitCollection_
Definition: EECosmicTask.h:70
bool isValid() const
Definition: HandleBase.h:76
double maxJitter_
Definition: EECosmicTask.h:78
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
void beginRun(const edm::Run &r, const edm::EventSetup &c)
BeginRun.
Definition: EECosmicTask.cc:73
void setup(void)
Setup.
Definition: EECosmicTask.cc:95
void analyze(const edm::Event &e, const edm::EventSetup &c)
Analyze.
static void initGeometry(const edm::EventSetup &setup, bool verbose=false)
Definition: Numbers.cc:50
MonitorElement * meSpectrum_[2][18]
Definition: EECosmicTask.h:74
void cleanup(void)
Cleanup.
static unsigned iSM(const unsigned ism, const EcalSubdetector subdet)
Definition: Numbers.cc:246
double minJitter_
Definition: EECosmicTask.h:77
void endJob(void)
EndJob.
EECosmicTask(const edm::ParameterSet &ps)
Constructor.
Definition: EECosmicTask.cc:29
static EcalSubdetector subDet(const EBDetId &id)
Definition: Numbers.cc:145
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)
double threshold_
Definition: EECosmicTask.h:76
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:429
Definition: Run.h:33
DQMStore * dqmStore_
Definition: EECosmicTask.h:60
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