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  * \author G. Della Ricca
5  *
6 */
7 
8 #include <iostream>
9 #include <fstream>
10 
13 
15 
17 
20 
22 
24 
26 
27  init_ = false;
28 
30 
31  prefixME_ = ps.getUntrackedParameter<std::string>("prefixME", "");
32 
33  enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
34 
35  mergeRuns_ = ps.getUntrackedParameter<bool>("mergeRuns", false);
36 
37  EcalRawDataCollection_ = consumes<EcalRawDataCollection>(ps.getParameter<edm::InputTag>("EcalRawDataCollection"));
38  EcalUncalibratedRecHitCollection_ = consumes<EcalUncalibratedRecHitCollection>(ps.getParameter<edm::InputTag>("EcalUncalibratedRecHitCollection"));
39  EcalRecHitCollection_ = consumes<EcalRecHitCollection>(ps.getParameter<edm::InputTag>("EcalRecHitCollection"));
40 
41  threshold_ = 0.12500; // typical muon energy deposit is 250 MeV
42 
43  minJitter_ = -2.0;
44  maxJitter_ = 1.5;
45 
46  for (int i = 0; i < 18; i++) {
47  meSelMap_[i] = 0;
48  meSpectrum_[0][i] = 0;
49  meSpectrum_[1][i] = 0;
50  }
51 
52 }
53 
55 
56 }
57 
59 
60  ievt_ = 0;
61 
62  if ( dqmStore_ ) {
63  dqmStore_->setCurrentFolder(prefixME_ + "/EECosmicTask");
64  dqmStore_->rmdir(prefixME_ + "/EECosmicTask");
65  }
66 
67 }
68 
70 
71  Numbers::initGeometry(c, false);
72 
73  if ( ! mergeRuns_ ) this->reset();
74 
75 }
76 
78 
79 }
80 
81 void EECosmicTask::reset(void) {
82 
83  for (int i = 0; i < 18; i++) {
84  if ( meSelMap_[i] ) meSelMap_[i]->Reset();
85  if ( meSpectrum_[0][i] ) meSpectrum_[0][i]->Reset();
86  if ( meSpectrum_[1][i] ) meSpectrum_[1][i]->Reset();
87  }
88 
89 }
90 
92 
93  init_ = true;
94 
96 
97  if ( dqmStore_ ) {
98  dqmStore_->setCurrentFolder(prefixME_ + "/EECosmicTask");
99 
100  dqmStore_->setCurrentFolder(prefixME_ + "/EECosmicTask/Sel");
101  for (int i = 0; i < 18; i++) {
102  name = "EECT energy sel " + Numbers::sEE(i+1);
103  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");
104  meSelMap_[i]->setAxisTitle("ix", 1);
105  if ( i+1 >= 1 && i+1 <= 9 ) meSelMap_[i]->setAxisTitle("101-ix", 1);
106  meSelMap_[i]->setAxisTitle("iy", 2);
107  meSelMap_[i]->setAxisTitle("energy (GeV)", 3);
108  }
109 
110  dqmStore_->setCurrentFolder(prefixME_ + "/EECosmicTask/Spectrum");
111  for (int i = 0; i < 18; i++) {
112  name = "EECT 1x1 energy spectrum " + Numbers::sEE(i+1);
113  meSpectrum_[0][i] = dqmStore_->book1D(name, name, 100, 0., 1.5);
114  meSpectrum_[0][i]->setAxisTitle("energy (GeV)", 1);
115 
116  name = "EECT 3x3 energy spectrum " + Numbers::sEE(i+1);
117  meSpectrum_[1][i] = dqmStore_->book1D(name, name, 100, 0., 1.5);
118  meSpectrum_[1][i]->setAxisTitle("energy (GeV)", 1);
119  }
120 
121  }
122 
123 }
124 
126 
127  if ( ! init_ ) return;
128 
129  if ( dqmStore_ ) {
130  dqmStore_->setCurrentFolder(prefixME_ + "/EECosmicTask");
131 
132  dqmStore_->setCurrentFolder(prefixME_ + "/EECosmicTask/Sel");
133  for (int i = 0; i < 18; i++) {
134  if ( meSelMap_[i] ) dqmStore_->removeElement( meSelMap_[i]->getName() );
135  meSelMap_[i] = 0;
136  }
137 
138  dqmStore_->setCurrentFolder(prefixME_ + "/EECosmicTask/Spectrum");
139  for (int i = 0; i < 18; i++) {
140  if ( meSpectrum_[0][i] ) dqmStore_->removeElement( meSpectrum_[0][i]->getName() );
141  meSpectrum_[0][i] = 0;
142  if ( meSpectrum_[1][i] ) dqmStore_->removeElement( meSpectrum_[1][i]->getName() );
143  meSpectrum_[1][i] = 0;
144  }
145 
146  }
147 
148  init_ = false;
149 
150 }
151 
153 
154  edm::LogInfo("EECosmicTask") << "analyzed " << ievt_ << " events";
155 
156  if ( enableCleanup_ ) this->cleanup();
157 
158 }
159 
161 
162  bool isData = true;
163  bool enable = false;
164  int runType[18];
165  for (int i=0; i<18; i++) runType[i] = -1;
166 
168 
169  if ( e.getByToken(EcalRawDataCollection_, dcchs) ) {
170 
171  for ( EcalRawDataCollection::const_iterator dcchItr = dcchs->begin(); dcchItr != dcchs->end(); ++dcchItr ) {
172 
173  if ( Numbers::subDet( *dcchItr ) != EcalEndcap ) continue;
174 
175  int ism = Numbers::iSM( *dcchItr, EcalEndcap );
176 
177  runType[ism-1] = dcchItr->getRunType();
178 
179  if ( dcchItr->getRunType() == EcalDCCHeaderBlock::COSMIC ||
180  dcchItr->getRunType() == EcalDCCHeaderBlock::MTCC ||
181  dcchItr->getRunType() == EcalDCCHeaderBlock::COSMICS_GLOBAL ||
182  dcchItr->getRunType() == EcalDCCHeaderBlock::PHYSICS_GLOBAL ||
183  dcchItr->getRunType() == EcalDCCHeaderBlock::COSMICS_LOCAL ||
184  dcchItr->getRunType() == EcalDCCHeaderBlock::PHYSICS_LOCAL ) enable = true;
185 
186  }
187 
188  } else {
189 
190  isData = false; enable = true;
191  edm::LogWarning("EECosmicTask") << "EcalRawDataCollection not available";
192 
193  }
194 
195  if ( ! enable ) return;
196 
197  if ( ! init_ ) this->setup();
198 
199  ievt_++;
200 
202 
203  if ( e.getByToken(EcalRecHitCollection_, hits) ) {
204 
205  int neeh = hits->size();
206  LogDebug("EECosmicTask") << "event " << ievt_ << " hits collection size " << neeh;
207 
209 
210  if ( ! e.getByToken(EcalUncalibratedRecHitCollection_, uhits) ) {
211  edm::LogWarning("EECosmicTask") << "EcalUncalibratedRecHitCollection not available";
212  }
213 
214  for ( EcalRecHitCollection::const_iterator hitItr = hits->begin(); hitItr != hits->end(); ++hitItr ) {
215 
216  EEDetId id = hitItr->id();
217 
218  int ix = id.ix();
219  int iy = id.iy();
220 
221  int ism = Numbers::iSM( id );
222 
223  if ( ism >= 1 && ism <= 9 ) ix = 101 - ix;
224 
225  float xix = ix - 0.5;
226  float xiy = iy - 0.5;
227 
228  int iz = 0;
229 
230  if ( ism >= 1 && ism <= 9 ) iz = -1;
231  if ( ism >= 10 && ism <= 18 ) iz = +1;
232 
233  if ( isData ) {
234 
235  if ( ! ( runType[ism-1] == EcalDCCHeaderBlock::COSMIC ||
236  runType[ism-1] == EcalDCCHeaderBlock::MTCC ||
237  runType[ism-1] == EcalDCCHeaderBlock::COSMICS_GLOBAL ||
238  runType[ism-1] == EcalDCCHeaderBlock::PHYSICS_GLOBAL ||
239  runType[ism-1] == EcalDCCHeaderBlock::COSMICS_LOCAL ||
240  runType[ism-1] == EcalDCCHeaderBlock::PHYSICS_LOCAL ) ) continue;
241 
242  }
243 
244  float xval = hitItr->energy();
245  if ( xval <= 0. ) xval = 0.0;
246 
247  // look for the seeds
248  float e3x3 = 0.;
249  bool isSeed = true;
250 
251  // evaluate 3x3 matrix around a seed
252  for(int icry=0; icry<9; ++icry) {
253  unsigned int row = icry/3;
254  unsigned int column = icry%3;
255  int icryX = id.ix()+column-1;
256  int icryY = id.iy()+row-1;
257  if ( EEDetId::validDetId(icryX, icryY, iz) ) {
258  EEDetId id3x3 = EEDetId(icryX, icryY, iz, EEDetId::XYMODE);
259  if ( hits->find(id3x3) != hits->end() ) {
260  float neighbourEnergy = hits->find(id3x3)->energy();
261  e3x3 += neighbourEnergy;
262  if ( neighbourEnergy > xval ) isSeed = false;
263  }
264  }
265  }
266 
267  // find the jitter of the seed
268  float jitter = -999.;
269  if ( isSeed ) {
270  if ( uhits.isValid() ) {
271  if ( uhits->find(id) != uhits->end() ) {
272  jitter = uhits->find(id)->jitter();
273  }
274  }
275  }
276 
277  if ( isSeed && e3x3 >= threshold_ && jitter > minJitter_ && jitter < maxJitter_ ) {
278  if ( meSelMap_[ism-1] ) meSelMap_[ism-1]->Fill(xix, xiy, e3x3);
279  }
280 
281  if ( meSpectrum_[0][ism-1] ) meSpectrum_[0][ism-1]->Fill(xval);
282 
283  if ( isSeed && xval >= threshold_ && jitter > minJitter_ && jitter < maxJitter_ ) {
284  if ( meSpectrum_[1][ism-1] ) meSpectrum_[1][ism-1]->Fill(e3x3);
285  }
286 
287  }
288 
289  } else {
290 
291  edm::LogWarning("EECosmicTask") << "EcalRecHitCollection not available";
292 
293  }
294 
295 }
296 
#define LogDebug(id)
edm::EDGetTokenT< EcalUncalibratedRecHitCollection > EcalUncalibratedRecHitCollection_
Definition: EECosmicTask.h:70
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
static std::string sEE(const unsigned ism)
Definition: Numbers.cc:223
int i
Definition: DBlmapReader.cc:9
int ix() const
Definition: EEDetId.h:76
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:872
void rmdir(const std::string &fullpath)
Definition: DQMStore.cc:2730
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
void reset(void)
Reset.
Definition: EECosmicTask.cc:81
Some &quot;id&quot; conversions.
static const int XYMODE
Definition: EEDetId.h:339
std::vector< EcalDCCHeaderBlock >::const_iterator const_iterator
bool enableCleanup_
Definition: EECosmicTask.h:65
void beginJob(void)
BeginJob.
Definition: EECosmicTask.cc:58
static int ix0EE(const unsigned ism)
Definition: Numbers.cc:770
static int iy0EE(const unsigned ism)
Definition: Numbers.cc:809
void Fill(long long x)
void endRun(const edm::Run &r, const edm::EventSetup &c)
EndRun.
Definition: EECosmicTask.cc:77
std::string prefixME_
Definition: EECosmicTask.h:63
virtual ~EECosmicTask()
Destructor.
Definition: EECosmicTask.cc:54
MonitorElement * meSelMap_[18]
Definition: EECosmicTask.h:73
void removeElement(const std::string &name)
Definition: DQMStore.cc:2772
bool isValid() const
Definition: HandleBase.h:76
double maxJitter_
Definition: EECosmicTask.h:79
void beginRun(const edm::Run &r, const edm::EventSetup &c)
BeginRun.
Definition: EECosmicTask.cc:69
void setup(void)
Setup.
Definition: EECosmicTask.cc:91
void analyze(const edm::Event &e, const edm::EventSetup &c)
Analyze.
edm::EDGetTokenT< EcalRecHitCollection > EcalRecHitCollection_
Definition: EECosmicTask.h:71
static void initGeometry(const edm::EventSetup &setup, bool verbose=false)
Definition: Numbers.cc:47
#define column(...)
Definition: DbCore.h:74
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
MonitorElement * meSpectrum_[2][18]
Definition: EECosmicTask.h:75
void cleanup(void)
Cleanup.
static unsigned iSM(const unsigned ism, const EcalSubdetector subdet)
Definition: Numbers.cc:243
double minJitter_
Definition: EECosmicTask.h:78
edm::EDGetTokenT< EcalRawDataCollection > EcalRawDataCollection_
Definition: EECosmicTask.h:69
void endJob(void)
EndJob.
EECosmicTask(const edm::ParameterSet &ps)
Constructor.
Definition: EECosmicTask.cc:25
static EcalSubdetector subDet(const EBDetId &id)
Definition: Numbers.cc:142
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:77
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:584
Definition: Run.h:41
DQMStore * dqmStore_
Definition: EECosmicTask.h:61
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:1330